Exemplo n.º 1
0
void _psp_time_to_ticks
   (
      TIME_STRUCT_PTR     time_ptr,
      PSP_TICK_STRUCT_PTR tick_ptr
   )
{ /* Body */
   PSP_TICK_STRUCT tick1;
   PSP_TICK_STRUCT tick2;

   _psp_seconds_to_ticks(time_ptr->SECONDS, &tick1);
   _psp_msecs_to_ticks(time_ptr->MILLISECONDS, &tick2);

   _psp_add_ticks(&tick1, &tick2, tick_ptr);

} /* Endbody */
Exemplo n.º 2
0
boolean _psp_ticks_to_xdate
   (
      /*  [IN]  pointer to tick structure  */
      PSP_TICK_STRUCT_PTR  tick_ptr,

      /*  [OUT]  pointer to a xdate structure  */
      MQX_XDATE_STRUCT_PTR xdate_ptr
   )
{ /* Body */
   PSP_TICK_STRUCT        tmp_ticks1;
   PSP_TICK_STRUCT        tmp_ticks2;
   uint_64                seconds;
   uint_64                leftover_ticks;
   KERNEL_DATA_STRUCT_PTR kernel_data;
   uint_32                days,years;
   uint_32                tps, tmp;
   boolean                over_flow;
   uint_16                leap;


   _GET_KERNEL_DATA(kernel_data);

   tps = kernel_data->TICKS_PER_SECOND;

   /* Convert ticks to seconds */
   seconds        = tick_ptr->TICKS[0] / tps;
   leftover_ticks = tick_ptr->TICKS[0] % tps;
      
   /* Convert to minutes */
   tmp = seconds / SECS_IN_MINUTE;
   xdate_ptr->SEC = seconds % SECS_IN_MINUTE;

   /* Convert to hours */
   xdate_ptr->MIN = tmp % MINUTES_IN_HOUR;
   tmp /= MINUTES_IN_HOUR;

   /* Convert to days */
   xdate_ptr->HOUR = tmp % HOURS_IN_DAY;
   days = tmp / HOURS_IN_DAY;


   /* Make an educated quess where to start in table */
   years = days / 366;
   if (years > 511) {
      /* This is out of range of the xdate structure */
      return FALSE;
   } /* Endif */

   xdate_ptr->YEAR = (uint_16)years;
   while (days >= _time_days_before_year_internal[xdate_ptr->YEAR + 1]) {
      xdate_ptr->YEAR++;
   } /* Endwhile */

   /* Jan 1, 1970 was a Thursday */
   xdate_ptr->WDAY  = (uint_16)((days + 3 + 1) % 7);

   /* Calculate the number of days since the beginning of the year */
   days -= _time_days_before_year_internal[xdate_ptr->YEAR];

   xdate_ptr->YEAR += (uint_16)1970;
   xdate_ptr->YDAY  = (uint_16)days;

   /*
   ** Find out if we are in a leap year.
   **
   ** if (the year is a century year not divisible by 400
   ** then it is not a leap year, otherwise if year divisible by
   ** four then it is a leap year
   */

   if ((xdate_ptr->YEAR % (uint_16)100) == (uint_16)0) {

      if ((xdate_ptr->YEAR % (uint_16)400) == (uint_16)0) {
         leap = (uint_16)LEAP_YEAR;
      } else {
         leap = (uint_16)NON_LEAP_YEAR;
      } /* Endif */
         
   } else {

      if ((xdate_ptr->YEAR % (uint_16)4) == (uint_16)0) {
         leap = (uint_16)LEAP_YEAR;
      } else {
         leap = (uint_16)NON_LEAP_YEAR;
      } /* Endif */

   } /* Endif */

   /* calculate the month */
   xdate_ptr->MONTH = days/31;
   while (days >= _time_days_before_month_internal[leap][xdate_ptr->MONTH]) {
      xdate_ptr->MONTH++;
   } /* Endwhile */
   days -= _time_days_before_month_internal[leap][xdate_ptr->MONTH - 1];

   /* calculate the day */
   xdate_ptr->MDAY = (uint_16)(days);

   /* first day is 1*/
   xdate_ptr->MDAY++;

   /* 
   ** Calculate ms, us, ns and ps from remaining ticks
   */
   tmp_ticks1.TICKS[0]    = leftover_ticks;
   tmp_ticks1.HW_TICKS[0] = tick_ptr->HW_TICKS[0];

   /* Calculate milliseconds */
   tmp = _psp_ticks_to_milliseconds_truncate(&tmp_ticks1, &over_flow);
   xdate_ptr->MSEC = (uint_16)tmp;

   _psp_msecs_to_ticks(tmp, &tmp_ticks2);
   PSP_SUB_TICKS(&tmp_ticks1, &tmp_ticks2, &tmp_ticks1);

   if ((tmp_ticks1.TICKS[0] == 0) && (tmp_ticks2.HW_TICKS[0] == 0)) {
      xdate_ptr->USEC = xdate_ptr->NSEC = xdate_ptr->PSEC = 0;
      return TRUE;
   } /* Endif */

   /* Calculate microseconds */
   tmp = _psp_ticks_to_microseconds_truncate(&tmp_ticks1, &over_flow);
   xdate_ptr->USEC = (uint_16)tmp;

   _psp_usecs_to_ticks(tmp, &tmp_ticks2);
   PSP_SUB_TICKS(&tmp_ticks1, &tmp_ticks2, &tmp_ticks1);

   if ((tmp_ticks1.TICKS[0] == 0) && (tmp_ticks2.HW_TICKS[0] == 0)) {
      xdate_ptr->NSEC = xdate_ptr->PSEC = 0;
      return TRUE;
   } /* Endif */

   /* Calculate nanoseconds */
   tmp = _psp_ticks_to_nanoseconds_truncate(&tmp_ticks1, &over_flow);
   xdate_ptr->NSEC = (uint_16)tmp;

   _psp_nsecs_to_ticks(tmp, &tmp_ticks2);
   PSP_SUB_TICKS(&tmp_ticks1, &tmp_ticks2, &tmp_ticks1);

   if ((tmp_ticks1.TICKS[0] == 0) && (tmp_ticks2.HW_TICKS[0] == 0)) {
      xdate_ptr->PSEC = 0;
      return TRUE;
   } /* Endif */

   /* Calculate picoseconds */
   tmp = _psp_ticks_to_picoseconds_truncate(&tmp_ticks1, &over_flow);
   xdate_ptr->PSEC = (uint_16)tmp;

   return TRUE;

} /* Endbody */