DolphinV4 API  1.6.1.0
TIME functions
Collaboration diagram for TIME functions:

Functions

void time_getTime (uint32 *pu32Time)
RETURN_TYPE time_getTimeOut (TIMER_TYPE *pu8timer)
void time_setTimerCount (TIMER_TYPE *pu8timer, uint32 u32timeToCount)
void time_wait (uint32 u32Delay)

Detailed Description

The TIME module uses a HW system timer that generates a system tick at a fixed rate of one tick per millisecond. Using this system tick a system scheduler is implemented. Each millisecond the execution of the application is interrupted and the schedule takes over the CPU. The schedule executes and one of the SYSTEM-TASKS.

For more information make sure to read scheduler_page
Because most of the radio routines are called from the schedule when linking TIME module the radio module will be also linked to your application.

The TIME module offers the application the possibility to build it's own SW timers with the precission of 1ms. Using the wait function the application can stop it's execution for a certain ammount of time. The system timer is based on 32bit counter.

Note:
It may happen that the application receives less than half time slice of the CPU when several interrupts like Radio, UART, are executed one after another.
The system timer is based on a 32bit counter therfore the counter will overflow once every 49 days.
Some critical functions (like the FLASH write functions in the mem module) needs to disable all the interrupts inclusive the interrupt from the system timer. When the functions execution time is longer than 1ms it may happen that a system tick is lost. Use these functions rarely or calculate with a system tick loss!
If you need timing with higher resolution as 1ms use the functions from the timer1 module.


Function Documentation

void time_getTime ( uint32 *  pu32Time)

Gets the sytem timer counter.

 \param[out]    pu32Time     System timer, this counter is incremented by interrupt routine every 1ms. /n
                           Pointer needs to point to allocated memory, because in function value changes not address.
 \return
Note:
This function is allowed to be used in an interrupt callback function ONLY if it is ensured that it is not used at the same time from the main program!
See also:
time_wait, time_setTimerCount, time_getTimeOut
RETURN_TYPE time_getTimeOut ( TIMER_TYPE pu8timer)

Indicates if a time-out happened in a SW timer

Parameters:
[out]*pu8timerPointer to the timer structure.
Returns:
OK No time-out or timer disabled
TIME_OUT Time-out
Note:
Function returns TIME_OUT again, when it was previously called with the same TIMER_TYPE and there was TIME_OUT. When this TIMER_TYPE is started again using time_setTimerCount, then the timer is reset. Function returns OK, when time out is still not reached. Also when timer was disabled while time out was not reached, even when in the meantime time out would have been reached.

Example 1:
This piece of code shows the standard way to implement a time-out

TIMER_TYPE myTimer_1;
time_setTimerCount(&myTimer_1, 10); //start a count of 10ms, controlled via myTimer_1
while(time_getTimeOut(&myTimer_1) == 0); //wait for the time-out before going further.

Example 2:
This will NOT work

time_setTimerCount(&myTimer_1, 10); //start a count of 10ms, controlled via myTimer_1
while(myTimer_1.timeOut == 0); //good idea, but...

...the overflow flag is only set if the time_getTimeOut is called
and a time-out happens. Since that function is not called, the flag is never set
and the program waits in the loop until WDT reset.

Example 3:
This implementation of the time-out would also work

TIMER_TYPE myTimer_1;
time_setTimerCount(&myTimer_1, 10); //start a count of 10ms, controlled via myTimer_1
do{
time_getTimeOut(&myTimer_1);
}while(time_getTimeOut(myTimer_1.timeOut == 0); //wait for the time-out before going further.
See also:
time_getTime, time_setTimerCount, time_wait
void time_setTimerCount ( TIMER_TYPE pu8timer,
uint32  u32timeToCount 
)

Initialises a SW timer for a time measurement

Parameters:
[in]*pu8timerPointer to the timer structure. See TIMER_TYPE
[in]u32timeToCountTime to measure in ms.
Returns:
void
See also:
time_getTime, time_wait, time_getTimeOut
void time_wait ( uint32  u32Delay)

Performs a dummy loop for the indicated amount of ms. If the system timer is not running i.e. the isr_timer0Init was not called the delay is realised with standby mode waking up by short term timer.

Parameters:
[in]u32DelayAmount of ms to wait.
Returns:
-
See also:
time_getTime, time_setTimerCount, time_getTimeOut
Note:
Watchdog is not cleared inside this function! This has to be handled by the application.
If system timer is not running on the XTAL the system runs on CRCO oscillator. time_wait can have then at worst case cca. 42.5% error.
If the scheduler is not running (no isr_timer0) the time_wait enters the chip in standby and uses the short term timer interrupt to get out from the standby. Please notice, that while standby mode the CPU clock is stopped and no UART function is given. So wakeup by UART receiving is not possible.