_time_ticks_to_xdate

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

_time_ticks_to_xdate

Jump to solution
1,527 Views
madifazio
Contributor III

Hi, 

I have some troubles with _time_ticks_to_xdate function.

 

The following code can be used as demostration 

MQX_TICK_STRUCT stTime;MQX_XDATE_STRUCT xdate0;MQX_XDATE_STRUCT xdate1; xdate0.YEAR = 1970;xdate0.MONTH = 1;xdate0.MDAY = 1;xdate0.HOUR = 0;xdate0.MIN = 0;xdate0.SEC = 0;xdate0.MSEC = 1;xdate0.USEC = 800;xdate0.NSEC = 0;xdate0.PSEC = 0; _time_xdate_to_ticks(&xdate0,&stTime);_time_ticks_to_xdate(&stTime,&xdate1);

 After the conversion, xdate0 is diferent from xdate1

 

I see that USEC > 500 (also NSEC > 500) result in adding one to the milliseconds and random numbers in the minors fields (nsec, psec)

 

Here is the numeric result of the code above

Resultados :
Campo  Xdate0     Xdate1
Año:       1970         1970
Mes:      1                1
Dia:        1                1
Hor:        0                0
Min:        0                0
Seg:       0                0
msg:      1                2
usg:       800            6784
nsg:       0                 35336
psg:       0                 18052

Any help would be apreciated

I suspect same isue in psp functions

_psp_ticks_to_milliseconds,

_psp_ticks_to_microseconds,

_psp_ticks_to_nanoseconds and

_psp_ticks_to_picoseconds

 

Regards

0 Kudos
Reply
1 Solution
1,152 Views
madifazio
Contributor III

Hi Martin

Thanks for reply

 

 

I wrap the _time_ticks_to_xdate mqx function with this one:

 

/*FUNCTION*------------------------------------------------------------** Function Name   : _time_ticks_to_xdateQueAnda* Returned Value  : boolean* Comments        : converts ticks into a date and time from*                   Jan.1 1970* Funciona teniendo en cuenta que hay 10000 HT por ms*END*------------------------------------------------------------------*/boolean _time_ticks_to_xdateQueAnda   (      /*  [IN]  pointer to tick structure  */      MQX_TICK_STRUCT_PTR  tick_ptr,      /*  [OUT]  pointer to a xdate structure  */      MQX_XDATE_STRUCT_PTR xdate_ptr   ){ /* Body */ boolean res; uint_32 temp; // dejar solo los milisegundos en la estructura de ticks temp = tick_ptr->HW_TICKS % 10000;  // restar los usec de la estructura de ticks tick_ptr->HW_TICKS -= temp;  // convertir a xdate res = _time_ticks_to_xdate(tick_ptr,xdate_ptr);  // volver a poner los usec en la estructura de tics tick_ptr->HW_TICKS += temp;   // agregar usec, nsec y psec a xdate. xdate_ptr->USEC = (uint_16)(temp / 10);  xdate_ptr->NSEC = (uint_16)((temp % 10) * 100);  xdate_ptr->PSEC = 0;  return res;} /* Endbody */

 I have 10000 HWTICKS per ms, so this function works for me.

I extract usec, nsec and psec from MQX_TICK_STRUCT, convert it to XDATE, then restore the extracted part and then complete the (now well converted) XDATE with usec, nsec and psec derived from the extracted part.

 

 

 

View solution in original post

0 Kudos
Reply
2 Replies
1,152 Views
c0170
Senior Contributor III

Hi madifazio,

 

i have not tried to run the program you included yet because i do not have MQX 3.6 intstalled.

I remember there was a bug in those functions  even in MQX 3.7 and they should  be fixed in MQX 3.8 .

 

Regards,

MartinK

0 Kudos
Reply
1,153 Views
madifazio
Contributor III

Hi Martin

Thanks for reply

 

 

I wrap the _time_ticks_to_xdate mqx function with this one:

 

/*FUNCTION*------------------------------------------------------------** Function Name   : _time_ticks_to_xdateQueAnda* Returned Value  : boolean* Comments        : converts ticks into a date and time from*                   Jan.1 1970* Funciona teniendo en cuenta que hay 10000 HT por ms*END*------------------------------------------------------------------*/boolean _time_ticks_to_xdateQueAnda   (      /*  [IN]  pointer to tick structure  */      MQX_TICK_STRUCT_PTR  tick_ptr,      /*  [OUT]  pointer to a xdate structure  */      MQX_XDATE_STRUCT_PTR xdate_ptr   ){ /* Body */ boolean res; uint_32 temp; // dejar solo los milisegundos en la estructura de ticks temp = tick_ptr->HW_TICKS % 10000;  // restar los usec de la estructura de ticks tick_ptr->HW_TICKS -= temp;  // convertir a xdate res = _time_ticks_to_xdate(tick_ptr,xdate_ptr);  // volver a poner los usec en la estructura de tics tick_ptr->HW_TICKS += temp;   // agregar usec, nsec y psec a xdate. xdate_ptr->USEC = (uint_16)(temp / 10);  xdate_ptr->NSEC = (uint_16)((temp % 10) * 100);  xdate_ptr->PSEC = 0;  return res;} /* Endbody */

 I have 10000 HWTICKS per ms, so this function works for me.

I extract usec, nsec and psec from MQX_TICK_STRUCT, convert it to XDATE, then restore the extracted part and then complete the (now well converted) XDATE with usec, nsec and psec derived from the extracted part.

 

 

 

0 Kudos
Reply