Subversion Repositories HomeAutomation

Rev

Rev 544 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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