_time_set doesnt save time

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

_time_set doesnt save time

Jump to solution
1,032 Views
kdavis
Contributor III

I am using a MCF54418 with MQX 3.8.1, when I am updating the time using _time_set() then read immediately after using time_get() the times do not match, the get time is still the time from up (usually a few seconds) where as I tried setting the seconds to 1356048000. Can anyone possibly shed some light on this? Thank you in advance.

Tags (2)
0 Kudos
1 Solution
772 Views
kdavis
Contributor III

I found the issue, it actually was due to something a coworker commited, for some reason they removed the add_ticks part to get_time, so it only ever returned the time from the start. Not sure why they did that yet, but that is what happened, thanks for your help!

View solution in original post

0 Kudos
7 Replies
772 Views
c0170
Senior Contributor III

Hello Kevin davis,

can you share some code, project or at least code snippet, just to be sure I test the same scenario which you have been having problems. It makes an entire process faster. Thank you.

Regards,

MartinK

0 Kudos
772 Views
kdavis
Contributor III

Oh sure thing, sorry I prolly should have thought of it. This first part is from my main,

TIME_STRUCT mqx_time;

mqx_time.SECONDS = 1356048000;

_time_set(&mqx_time);

_time_get(&mqx_time);

printf("seconds = %i",mqx_time.SECONDS);

This always prints 0 for seconds. when it should be printing what I set it to right above, 1356048000. I traced it as far into the PSP as I can understand, and I see some values change in the kernel, but I don't necessarily know how to tell if its doing that correctly.

0 Kudos
772 Views
PhilH
Contributor II

I notice you are not looking at the return values.  I suspect the "_time_set()" at line 3 is failing.  I see 2 errors in your code.  1) you are using an uninitialized value from the stack.  2) incorrect value for printf format string

The code should look like:

  1. TIME_STRUCT mqx_time;
  2. mqx_time.SECONDS = 1356048000
  3. mqx_time.MILLISECONDS = 0;
  4. _time_set(&mqx_time); 
  5. _time_get(&mqx_time); 
  6. printf("seconds = %u",mqx_time.SECONDS); 

0 Kudos
772 Views
kdavis
Contributor III

You are correct about those other errors, and I have changed those with no impact, however mqh.h defines the functions as follows

extern void                 _time_get(TIME_STRUCT_PTR);

extern void                 _time_set(TIME_STRUCT_PTR);

0 Kudos
772 Views
c0170
Senior Contributor III

Hello Kevin Davis,

I tested this on K60 because I do not have currently MCF board available, and it worked as expected. This is basic functionality which must work out of box, there was one bug in _psp_ticks_to_time but that does not have any impact on your result.

Check locals in your debugger if there's really 0 in TIME_STRUCT :smileywink:

Regards,

MartinK

0 Kudos
772 Views
kdavis
Contributor III

I know, thats why its so strange, and it was working the other day, could I have changed something in the BSP to disable the time functions or something along those lines?

Also here is the value of the time struct after get

mqx_time0x440089e80x440089e8
SECONDS00x440089e8
MILLISECONDS250x440089ec
0 Kudos
773 Views
kdavis
Contributor III

I found the issue, it actually was due to something a coworker commited, for some reason they removed the add_ticks part to get_time, so it only ever returned the time from the start. Not sure why they did that yet, but that is what happened, thanks for your help!

0 Kudos