Subversion Repositories HomeAutomation

Rev

Rev 544 | Go to most recent revision | 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 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.
  37.  */
  38. #define TimerTypeOneShot        0
  39. #define TimerTypeFreeRunning    1
  40.  
  41.  
  42. /*-----------------------------------------------------------------------------
  43.  * Public Types
  44.  *---------------------------------------------------------------------------*/
  45.  
  46. /**
  47.  * @brief Type of the callback function pointer
  48.  */
  49. typedef void (*timerCallback_t)(uint8_t);
  50.  
  51. /*-----------------------------------------------------------------------------
  52.  * Public Function Prototypes
  53.  *---------------------------------------------------------------------------*/
  54.  
  55. /**
  56.  * @brief Initialize timer engine
  57.  *
  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.  */
  61. void Timer_Init(void);
  62.  
  63. /**
  64.  * @brief Get current timer value
  65.  *
  66.  * @retval
  67.  *      The current time in ticks. The tick count wraps around after 2^32
  68.  *      ticks without any notification.
  69.  */
  70. uint32_t Timer_GetTicks(void);
  71.  
  72. /**
  73.  * @brief Initializes a software timer and starts it.
  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.  */
  90. void Timer_SetTimeout(uint8_t timer, uint16_t timeout, uint8_t type, timerCallback_t callback);
  91.  
  92. /**
  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
  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.  */
  105. uint8_t Timer_Expired(uint8_t timer);
  106.  
  107. /**@}*/
  108. #endif /*TIMER_H_*/
  109.