Rev 786 | Details | Compare with Previous | 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 | /** |
||
| 787 | arune | 31 | * @brief Definition for timer type TimerTypeOneShot |
| 786 | arune | 32 | * |
| 787 | arune | 33 | * When passed as the type argument to timerSetTimeout, the |
| 786 | arune | 34 | * timer will trigger only once and then disable itself. |
| 787 | arune | 35 | */ |
| 36 | #define TimerTypeOneShot 0 |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @brief Definition for timer type TimerTypeFreeRunning |
||
| 40 | * |
||
| 41 | * When passed as the type argument to timerSetTimeout, |
||
| 786 | arune | 42 | * the timer will reload itself at every expiration and trigger periodically. |
| 537 | andfri | 43 | */ |
| 44 | #define TimerTypeFreeRunning 1 |
||
| 45 | |||
| 786 | arune | 46 | |
| 537 | andfri | 47 | /*----------------------------------------------------------------------------- |
| 48 | * Public Types |
||
| 49 | *---------------------------------------------------------------------------*/ |
||
| 50 | |||
| 51 | /** |
||
| 786 | arune | 52 | * @brief Type of the callback function pointer |
| 537 | andfri | 53 | */ |
| 54 | typedef void (*timerCallback_t)(uint8_t); |
||
| 55 | |||
| 56 | /*----------------------------------------------------------------------------- |
||
| 57 | * Public Function Prototypes |
||
| 58 | *---------------------------------------------------------------------------*/ |
||
| 59 | |||
| 60 | /** |
||
| 786 | arune | 61 | * @brief Initialize timer engine |
| 62 | * |
||
| 537 | andfri | 63 | * Initializes the timer engine. The hardware timer interrupt source will be |
| 64 | * enabled, but global interrupts need to be enabled by the application. |
||
| 65 | */ |
||
| 544 | andfri | 66 | void Timer_Init(void); |
| 537 | andfri | 67 | |
| 68 | /** |
||
| 786 | arune | 69 | * @brief Get current timer value |
| 537 | andfri | 70 | * |
| 786 | arune | 71 | * @retval |
| 537 | andfri | 72 | * The current time in ticks. The tick count wraps around after 2^32 |
| 73 | * ticks without any notification. |
||
| 74 | */ |
||
| 544 | andfri | 75 | uint32_t Timer_GetTicks(void); |
| 537 | andfri | 76 | |
| 77 | /** |
||
| 786 | arune | 78 | * @brief Initializes a software timer and starts it. |
| 537 | andfri | 79 | * |
| 80 | * @param timer |
||
| 787 | arune | 81 | * The timer (0<=timer<TIMER_NUM_TIMERS). |
| 537 | andfri | 82 | * @param timeout |
| 83 | * The timeout in ticks. Passing zero disables a running timer. A timeout |
||
| 84 | * value of X ticks gives an actual timeout of between (X-1) and X ticks, |
||
| 85 | * not including the time it takes for the application to check the |
||
| 86 | * expiration status of the timer. |
||
| 87 | * @param type |
||
| 88 | * TimerTypeOneShot or TimerTypeFreeRunning. |
||
| 89 | * @param callback |
||
| 90 | * Pointer to optional callback function on the form |
||
| 91 | * void callback(uint8_t timer). The callback function is called with the |
||
| 92 | * timer number as the argument whenever the timer expires. It is called |
||
| 93 | * from the interrupt handler and must be very short. Null if not used. |
||
| 94 | */ |
||
| 544 | andfri | 95 | void Timer_SetTimeout(uint8_t timer, uint16_t timeout, uint8_t type, timerCallback_t callback); |
| 537 | andfri | 96 | |
| 97 | /** |
||
| 787 | arune | 98 | * @brief Check if timer expired. |
| 786 | arune | 99 | * |
| 100 | * Checks if a timer has expired, should be used for polling a timer event if callback |
||
| 101 | * is not used. The timer will only signal its expiration at |
||
| 537 | andfri | 102 | * the first call to this function after a timeout period, even if multiple |
| 103 | * timeout periods have elapsed since the previous call. |
||
| 104 | * |
||
| 105 | * @param timer |
||
| 106 | * The timer (0<=timer<TIMER_NUM_TIMERS). |
||
| 787 | arune | 107 | * @retval |
| 537 | andfri | 108 | * Non-zero if timer has expired since the previous check. |
| 109 | */ |
||
| 544 | andfri | 110 | uint8_t Timer_Expired(uint8_t timer); |
| 537 | andfri | 111 | |
| 786 | arune | 112 | /**@}*/ |
| 537 | andfri | 113 | #endif /*TIMER_H_*/ |