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
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
Solved! Go to Solution.
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.
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
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.