Download STLite/OS20 Real-Time Kernel Reference Manual
Transcript
8.3 Reading the current time For ST20 variants with power-down capability, the clocks pause when the ST20 is in power-down mode. Low priority High priority Interval between ticks 64 µsec 1 µsec Ticks per second 15625 1000000 Approximate full timer cycle 76.35 hours 1.193 hours Table 8.1 Summary of clock intervals for parts operating at 40Mhz 8.3 Reading the current time The value of a timer (or clock) is read using time_now which returns the value of the timer for the current priority. #include <ostime.h> clock_t time_now (void); The time at which counting starts will be no later than the call to kernel_start. 8.4 Time arithmetic Arithmetic on timer values should always be performed using special modulo operators. These routines perform no overflow checking and so allow for timer values ‘wrapping round’ to the most negative integer on the next tick after the most positive integer. clock_t time_plus(const clock_t time1, const clock_t time2); clock_t time_minus(const clock_t time1, const clock_t time2); int time_after(const clock_t time1, const clock_t time2); time_plus adds two timer values together and returns the sum allowing for any wrap-around. For example, if a number of ticks is added to the current time using time_plus then the result is the time after that many ticks. time_after subtracts the second value from the first and returns the difference allowing for any wrap-around. For example, if one time is subtracted from another using time_after then the result will be the number of ticks between the two times. If the result is positive then the first time is after the second. If the result is negative then the first time is before the second. time_after determines whether the first time is after the second time. One time is considered to be after another if the one is not more than half a full timer cycle later than the other. Half a full cycle is 231 ticks. The function returns the integer value 1 if the first time is after the second, and otherwise it returns zero. Some of these concepts are shown in Figure 8.1. 138