Subversion Repositories HomeAutomation

Rev

Rev 786 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  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.  *
  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
  9.  * or free-running mode. Timer events can be defined by polling or callbacks.
  10.  *
  11.  * @author  Andreas Fritiofson
  12.  * @date    2007-07-13
  13.  */
  14.  
  15. /**@{*/
  16.  
  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. /**
  31.  * @brief Definition for timer type TimerTypeOneShot
  32.  *
  33.  * When passed as the type argument to timerSetTimeout, the
  34.  * timer will trigger only once and then disable itself.
  35.  */
  36. #define TimerTypeOneShot        0
  37.  
  38. /**
  39.  * @brief Definition for timer type TimerTypeFreeRunning
  40.  *
  41.  * When passed as the type argument to timerSetTimeout,
  42.  * the timer will reload itself at every expiration and trigger periodically.
  43.  */
  44. #define TimerTypeFreeRunning    1
  45.  
  46.  
  47. /*-----------------------------------------------------------------------------
  48.  * Public Types
  49.  *---------------------------------------------------------------------------*/
  50.  
  51. /**
  52.  * @brief Type of the callback function pointer
  53.  */
  54. typedef void (*timerCallback_t)(uint8_t);
  55.  
  56. /*-----------------------------------------------------------------------------
  57.  * Public Function Prototypes
  58.  *---------------------------------------------------------------------------*/
  59.  
  60. /**
  61.  * @brief Initialize timer engine
  62.  *
  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.  */
  66. void Timer_Init(void);
  67.  
  68. /**
  69.  * @brief Get current timer value
  70.  *
  71.  * @retval
  72.  *      The current time in ticks. The tick count wraps around after 2^32
  73.  *      ticks without any notification.
  74.  */
  75. uint32_t Timer_GetTicks(void);
  76.  
  77. /**
  78.  * @brief Initializes a software timer and starts it.
  79.  *
  80.  * @param timer
  81.  *      The timer (0<=timer<TIMER_NUM_TIMERS).
  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.  */
  95. void Timer_SetTimeout(uint8_t timer, uint16_t timeout, uint8_t type, timerCallback_t callback);
  96.  
  97. /**
  98.  * @brief Check if timer expired.
  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
  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).
  107.  * @retval
  108.  *      Non-zero if timer has expired since the previous check.
  109.  */
  110. uint8_t Timer_Expired(uint8_t timer);
  111.  
  112. /**@}*/
  113. #endif /*TIMER_H_*/
  114.