Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 786 | arune | 1 | /** |
| 2 | * @defgroup timer Timer Library |
||
| 3 | * @code #include <drivers/timer/timer.h> @endcode |
||
| 4 | * |
||
| 5 | * @brief Functions for simple and advanced timer usage. |
||
| 6 | * |
||
| 537 | andfri | 7 | * Timer software module. Utilizes a hardware timer to provide a number of |
| 8 | * software timers to the application. Each timer can be set to either one-shot |
||
| 786 | arune | 9 | * or free-running mode. Timer events can be defined by polling or callbacks. |
| 10 | * |
||
| 537 | andfri | 11 | * @author Andreas Fritiofson |
| 12 | * @date 2007-07-13 |
||
| 13 | */ |
||
| 14 | |||
| 786 | arune | 15 | /**@{*/ |
| 16 | |||
| 537 | andfri | 17 | #ifndef TIMER_H_ |
| 18 | #define TIMER_H_ |
||
| 19 | |||
| 20 | |||
| 21 | /*----------------------------------------------------------------------------- |
||
| 22 | * Includes |
||
| 23 | *---------------------------------------------------------------------------*/ |
||
| 24 | #include <inttypes.h> |
||
| 25 | |||
| 26 | /*----------------------------------------------------------------------------- |
||
| 27 | * Defines |
||
| 28 | *---------------------------------------------------------------------------*/ |
||
| 29 | |||
| 30 | /** |
||
| 786 | arune | 31 | * @brief Definitions for timer types |
| 32 | * |
||
| 33 | * TimerTypeOneShot: When passed as the type argument to timerSetTimeout, the |
||
| 34 | * timer will trigger only once and then disable itself. |
||
| 35 | * TimerTypeFreeRunning: When passed as the type argument to timerSetTimeout, |
||
| 36 | * the timer will reload itself at every expiration and trigger periodically. |
||
| 537 | andfri | 37 | */ |
| 38 | #define TimerTypeOneShot 0 |
||
| 39 | #define TimerTypeFreeRunning 1 |
||
| 40 | |||
| 786 | arune | 41 | |
| 537 | andfri | 42 | /*----------------------------------------------------------------------------- |
| 43 | * Public Types |
||
| 44 | *---------------------------------------------------------------------------*/ |
||
| 45 | |||
| 46 | /** |
||
| 786 | arune | 47 | * @brief Type of the callback function pointer |
| 537 | andfri | 48 | */ |
| 49 | typedef void (*timerCallback_t)(uint8_t); |
||
| 50 | |||
| 51 | /*----------------------------------------------------------------------------- |
||
| 52 | * Public Function Prototypes |
||
| 53 | *---------------------------------------------------------------------------*/ |
||
| 54 | |||
| 55 | /** |
||
| 786 | arune | 56 | * @brief Initialize timer engine |
| 57 | * |
||
| 537 | andfri | 58 | * Initializes the timer engine. The hardware timer interrupt source will be |
| 59 | * enabled, but global interrupts need to be enabled by the application. |
||
| 60 | */ |
||
| 544 | andfri | 61 | void Timer_Init(void); |
| 537 | andfri | 62 | |
| 63 | /** |
||
| 786 | arune | 64 | * @brief Get current timer value |
| 537 | andfri | 65 | * |
| 786 | arune | 66 | * @retval |
| 537 | andfri | 67 | * The current time in ticks. The tick count wraps around after 2^32 |
| 68 | * ticks without any notification. |
||
| 69 | */ |
||
| 544 | andfri | 70 | uint32_t Timer_GetTicks(void); |
| 537 | andfri | 71 | |
| 72 | /** |
||
| 786 | arune | 73 | * @brief Initializes a software timer and starts it. |
| 537 | andfri | 74 | * |
| 75 | * @param timer |
||
| 76 | * The timer. |
||
| 77 | * @param timeout |
||
| 78 | * The timeout in ticks. Passing zero disables a running timer. A timeout |
||
| 79 | * value of X ticks gives an actual timeout of between (X-1) and X ticks, |
||
| 80 | * not including the time it takes for the application to check the |
||
| 81 | * expiration status of the timer. |
||
| 82 | * @param type |
||
| 83 | * TimerTypeOneShot or TimerTypeFreeRunning. |
||
| 84 | * @param callback |
||
| 85 | * Pointer to optional callback function on the form |
||
| 86 | * void callback(uint8_t timer). The callback function is called with the |
||
| 87 | * timer number as the argument whenever the timer expires. It is called |
||
| 88 | * from the interrupt handler and must be very short. Null if not used. |
||
| 89 | */ |
||
| 544 | andfri | 90 | void Timer_SetTimeout(uint8_t timer, uint16_t timeout, uint8_t type, timerCallback_t callback); |
| 537 | andfri | 91 | |
| 92 | /** |
||
| 786 | arune | 93 | * @brief Timer expired. |
| 94 | * |
||
| 95 | * Checks if a timer has expired, should be used for polling a timer event if callback |
||
| 96 | * is not used. The timer will only signal its expiration at |
||
| 537 | andfri | 97 | * the first call to this function after a timeout period, even if multiple |
| 98 | * timeout periods have elapsed since the previous call. |
||
| 99 | * |
||
| 100 | * @param timer |
||
| 101 | * The timer (0<=timer<TIMER_NUM_TIMERS). |
||
| 102 | * @return |
||
| 103 | * Non-zero if timer has expired since the previous check. |
||
| 104 | */ |
||
| 544 | andfri | 105 | uint8_t Timer_Expired(uint8_t timer); |
| 537 | andfri | 106 | |
| 786 | arune | 107 | /**@}*/ |
| 537 | andfri | 108 | #endif /*TIMER_H_*/ |