-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtimer.h
More file actions
177 lines (146 loc) · 4.36 KB
/
Copy pathtimer.h
File metadata and controls
177 lines (146 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* ----------------------------------------------------------------------------
*
* "THE ANY BEVERAGE-WARE LICENSE" (Revision 42 - based on beer-ware license):
* <dev@layer128.net> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a be(ve)er(age) in return. (I don't
* like beer much.)
*
* Matthias Kleemann
*
* ----------------------------------------------------------------------------
*
* \file timer.h
*
* Note: It is assumed to use an ATmega8 here.
*
* \todo make timer functions inline, if possible/necessary
*
* \date Created: 28.11.2011 18:15:59
* \author Matthias Kleemann
**/
#ifndef TIMER_H_
#define TIMER_H_
#include "config/timer_config.h"
// check prescaler settings - if not set, the timer is assumed off
#ifndef TIMER0_PRESCALER
//! default: TIMER 0 off
#define TIMER0_PRESCALER 0
#endif
#ifndef TIMER1_PRESCALER
//! default: TIMER 1 off
#define TIMER1_PRESCALER 0
#endif
#ifndef TIMER2_PRESCALER
//! default: TIMER 2 off
#define TIMER2_PRESCALER 0
#endif
#ifndef TIMER1_COMPARE_VALUE
//! default: check available compare value setup and set to 16bit MAX
#define TIMER1_COMPARE_VALUE 0xFFFF
#endif
#ifndef TIMER2_COMPARE_VALUE
//! default: check available compare value setup and set to 8bit MAX
#define TIMER2_COMPARE_VALUE 0xFF
#endif
//! clear all prescaler bits to stop TIMER0 - just in case
#define TIMER0_STOP (1 << CS02) | (1 << CS01) | (1 << CS00)
//! clear all prescaler bits to stop TIMER1 - just in case
#define TIMER1_STOP (1 << CS12) | (1 << CS11) | (1 << CS10)
//! clear all prescaler bits to stop TIMER2 - just in case
#define TIMER2_STOP (1 << CS22) | (1 << CS21) | (1 << CS20)
/***************************************************************************/
/* TYPEDEFINITION */
/***************************************************************************/
/**
* @brief mode of timer initialization
*
* Define mode of timer (interrupt) behaviour. Four modes are available:
* - overflow
* - output compare (CTC)
* - phase correct PWM
* - fast PWM
*
* Note: Currently no output pin for PWM is set.
*/
typedef enum
{
//! overflow
TimerOverflow = 0,
//! output compare (CTC)
TimerCompare = 1,
//! phase correct PWM
TimerPwm = 2,
//! fast PWM
TimerFastPwm = 3
} eTimerMode;
/***************************************************************************/
/* TIMER 0 */
/***************************************************************************/
/**
* @brief initializes Timer0 and stops
*
* There is no argument yet, since mode of Timer0 is overflow only at
* ATmega8. This has to be adapted, if using another AVR.
*/
void initTimer0(void);
/**
* @brief start Timer0
*/
void startTimer0(void);
/**
* @brief stop Timer0
*/
void stopTimer0(void);
/***************************************************************************/
/* TIMER 1 */
/***************************************************************************/
/**
* @brief initializes Timer1
* @param mode of Timer1 (overflow, compare, pwm, ...)
*/
void initTimer1(eTimerMode mode);
/**
* @brief start Timer1
*/
void startTimer1(void);
/**
* @brief stop Timer1
*/
void stopTimer1(void);
/**
* @brief restart Timer1 (set counter register to 0)
*/
void restartTimer1(void);
/**
* @brief set timer counter register to value
* @param value of timer counter
*/
void setTimer1Count(uint16_t value);
/***************************************************************************/
/* TIMER 2 */
/***************************************************************************/
/**
* @brief initializes Timer2
* @param mode of Timer2 (overflow, compare, pwm, ...)
*/
void initTimer2(eTimerMode mode);
/**
* @brief start Timer2
*/
void startTimer2(void);
/**
* @brief stop Timer2
*/
void stopTimer2(void);
/**
* @brief restart Timer2, e.g. in compare mode
*/
void restartTimer2(void);
/**
* @brief set timer counter register to value
* @param value of timer counter
*/
void setTimer2Count(uint8_t value);
#endif /* TIMER_H_ */