/*----------------------------------------------------------------------------------- * Blocks the thread until a message arrives in the mailbox, but does * not block the thread longer than "timeout" milliseconds (similar to * the sys_arch_sem_wait() function). The "msg" argument is a result * parameter that is set by the function (i.e., by doing "*msg = * ptr"). The "msg" parameter maybe NULL to indicate that the message * should be dropped. * * The return values are the same as for the sys_arch_sem_wait() function: * Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a * timeout. * * Note that a function with a similar name, sys_mbox_fetch(), is * implemented by lwIP. */ u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, /*@null@*/ /*@out@*/ void **msg, u32_t timeout) { void *dummyptr; void ** tmp_ptr; portTickType start_time, end_time, elapsed_time; e_mailbox_t* embox = (e_mailbox_t*)(*mbox); // assuming 1 tick is 1ms which is the case for now. start_time = OS_GetTime32(); /* inherited this code from freeRTOS and LWIP must be calling it in this way..*/ if ( msg == NULL ) { tmp_ptr = &dummyptr; } else { tmp_ptr = msg; } if ( timeout != 0 ) { // Return values 0 means success,1 means timeout if (0 == OS_GetMailTimed(&embox->mbox, tmp_ptr, timeout)) { end_time = OS_GetTime32(); elapsed_time = end_time - start_time; if ( elapsed_time == 0 ) { elapsed_time = (portTickType) 1; } return ( elapsed_time ); } else /* timed out blocking for message */ { if ( msg != NULL ) { *msg = NULL; } return SYS_ARCH_TIMEOUT; } } else /* block forever for a message. */ { OS_GetMail(&embox->mbox, &(*tmp_ptr)); end_time = OS_GetTime32(); elapsed_time = end_time - start_time; if ( elapsed_time == 0 ) { elapsed_time = (portTickType) 1; } return ( elapsed_time ); /* return time blocked TBD test */ } }
/********************************************************************* * * _ShowStamp * * Function description * */ static void _ShowStamp(void) { #if SHOW_TIME { I32 Time; char ac[20]; char * sBuffer = &ac[0]; Time = OS_GetTime32(); sBuffer = _WriteUnsigned(sBuffer, Time / 1000, 0); *sBuffer++ = ':'; sBuffer = _WriteUnsigned(sBuffer, Time % 1000, 3); *sBuffer++ = ' '; *sBuffer++ = 0; _puts(ac); } #endif #if SHOW_TASK { const char * s; s = OS_GetTaskName(NULL); if (s) { _puts(s); _puts(" - "); } } #endif }
systime_t osGetSystemTime(void) { systime_t time; //Get current tick count time = OS_GetTime32(); //Convert system ticks to milliseconds return OS_SYSTICKS_TO_MS(time); }
/********************************************************************* * * OS_GetTime_Cycles() * * This routine is required for task-info via OSView or high * resolution time maesurement functions. * It returns the system time in timer clock cycles. */ OS_U32 OS_GetTime_Cycles(void) { unsigned int t_cnt; OS_U32 time ; t_cnt = PIT_PIIR; /* Read current timer value */ time = OS_GetTime32(); /* Read current OS time */ if (t_cnt & 0xFFF00000) { /* Timer Interrupt pending ? */ time += (t_cnt >> 20); /* Adjust result */ t_cnt &= 0x000FFFFF; }
/*----------------------------------------------------------------------------------- * Blocks the thread while waiting for the semaphore to be * signaled. If the "timeout" argument is non-zero, the thread should * only be blocked for the specified time (measured in * milliseconds). * * If the timeout argument is non-zero, the return value is the number of * milliseconds spent waiting for the semaphore to be signaled. If the * semaphore wasn't signaled within the specified time, the return value is * SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore * (i.e., it was already signaled), the function may return zero. * * Notice that lwIP implements a function with a similar name, * sys_sem_wait(), that uses the sys_arch_sem_wait() function. */ u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) { portTickType start_time, end_time, elapsed_time; start_time = OS_GetTime32(); if ( timeout != 0 ) { if (0 == OS_WaitCSemaTimed(*sem, timeout)) { end_time = OS_GetTime32(); elapsed_time = end_time - start_time; if ( elapsed_time == 0 ) { elapsed_time = (portTickType) 1; } return ( elapsed_time ); /* return time blocked TBD test */ } else { return SYS_ARCH_TIMEOUT; } } else /* must block without a timeout */ { OS_WaitCSema(*sem); } end_time = OS_GetTime32(); elapsed_time = end_time - start_time; if ( elapsed_time == 0 ) { elapsed_time = (portTickType) 1; } return ( elapsed_time ); /* return time blocked */ }
/********************************************************************* * * OS_GetTime_Cycles() * * This routine is required for task-info via OSView or high * resolution time measurement functions. * It returns the system time in timer clock cycles. */ OS_U32 OS_GetTime_Cycles(void) { OS_U32 Time; OS_U32 Cnt; Time = OS_GetTime32(); Cnt = (OS_PCLK_TIMER/1000u) - SysTick->VAL; // // Check if timer interrupt pending ... // if (SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) { Cnt = (OS_PCLK_TIMER/1000u) - SysTick->VAL; // Interrupt pending, re-read timer and adjust result Time++; } return ((OS_PCLK_TIMER/1000u) * Time) + Cnt; }
/********************************************************************* * * HPTask */ static void HPTask(void) { int Cnt; int TestTime; while(1) { Cnt = 0; OS_Delay(1); // Sync to tick TestTime = OS_GetTime32() + 1000; while ((TestTime - OS_GetTime()) >= 0) { _CalcPrimes(sizeof(aIsPrime)); Cnt++; } _PrintResult(Cnt); } }
/** @memo Retrieves the elapsed seconds since the application started. @doc Retrieves the elapsed seconds since the application started. Can be used as a second timer by storing the first call and periodically checking against successive calls until the timeout period has been reached. @return The elapsed seconds. There is no error return. */ unsigned long rtp_get_system_sec (void) { return ((unsigned long) (OS_GetTime32() / TICKS_PER_SEC)); }
/** @memo Retrieves the elapsed milliseconds since the application started. @doc Retrieves the elapsed milliseconds since the application started. Can be used as a millisecond timer by storing the first call and periodically checking against successive calls until the timeout period has been reached. @return The elapsed milliseconds. There is no error return. */ unsigned long rtp_get_system_msec (void) { return((unsigned long) OS_GetTime32()); }
/********************************************************************* * * IP_OS_GetTime32() * * Function description * Return the current system time in ms. * The value will wrap around after app. 49.7 days. This is taken into * account by the stack. */ U32 IP_OS_GetTime32(void) { return OS_GetTime32(); }