Revision 83
timer_config.c | ||
---|---|---|
21 | 21 |
#include <xc.h> |
22 | 22 |
#include "timer_config.h" |
23 | 23 |
|
24 |
/** |
|
25 |
* \brief This function enables timer passed by argument. |
|
26 |
* |
|
27 |
* \param timer number of the timer to turn on. |
|
28 |
* |
|
29 |
* \return 0 on success |
|
30 |
* \return -1 (minus one) if has invalid argument |
|
31 |
*/ |
|
24 |
|
|
32 | 25 |
int timer_enable(int timer) |
33 | 26 |
{ |
34 | 27 |
if(timer < 2 || timer > 5) |
... | ... | |
51 | 44 |
return 0; |
52 | 45 |
} |
53 | 46 |
|
54 |
/** |
|
55 |
* \brief This function disables timer passed by argument. |
|
56 |
* |
|
57 |
* \param timer number of the timer to turn off. |
|
58 |
*/ |
|
59 | 47 |
|
48 |
|
|
60 | 49 |
int timer_disable(int timer) |
61 | 50 |
{ |
62 | 51 |
if(timer < 2 || timer > 5) |
... | ... | |
79 | 68 |
return 0; |
80 | 69 |
} |
81 | 70 |
|
82 |
/** |
|
83 |
* \brief Set frequency of the timer passed by argument. |
|
84 |
* The frequency needs to be between a minimum frequency (MIN_FREQ) and Peripheral Bus Clock Frequency(PBCLK). |
|
85 |
* |
|
86 |
* \param timer number of the timer |
|
87 |
* \param freq frequency of the timer |
|
88 |
* |
|
89 |
* \return 0 on success |
|
90 |
* \return -1 (minus one) if has invalid argument |
|
91 |
*/ |
|
92 | 71 |
int set_timer_freq(int timer,unsigned int freq) |
93 | 72 |
{ |
94 | 73 |
const unsigned int prescaler_values[] = {1, 2, 4, 8, 16, 32, 64, 256}; |
... | ... | |
133 | 112 |
return 0; |
134 | 113 |
} |
135 | 114 |
|
136 |
/** |
|
137 |
* \brief Read flag status of the timer |
|
138 |
* |
|
139 |
* \param timer number of the timer |
|
140 |
* |
|
141 |
* \return <tt> 0 (zero)</tt>, timer has not finished yet |
|
142 |
* \return <tt> 1 (one)</tt>, timer has finished |
|
143 |
* \return <tt> -1 (minus one)</tt>, number of the timer is invalid |
|
144 |
*/ |
|
115 |
|
|
145 | 116 |
int read_timer_IntFlag(int timer) |
146 | 117 |
{ |
147 | 118 |
if(timer < 2 || timer > 5) |
... | ... | |
161 | 132 |
return 0; |
162 | 133 |
} |
163 | 134 |
|
164 |
/** |
|
165 |
* \brief Reset flag of the timer |
|
166 |
* |
|
167 |
* \param timer number of the timer |
|
168 |
* \return <tt> -1 (minus one)</tt>, some argument is invalid |
|
169 |
*/ |
|
135 |
|
|
170 | 136 |
int reset_timer_IntFlag(int timer) |
171 | 137 |
{ |
172 | 138 |
if(timer < 2 || timer > 5) |
... | ... | |
189 | 155 |
return 0; |
190 | 156 |
} |
191 | 157 |
|
192 |
/** |
|
193 |
* \brief Set interrupt of a specificic timer passed by argument. |
|
194 |
* The user must determine the priority of interrupt service routine between 0(zero) and 7(seven). |
|
195 |
* |
|
196 |
* \param enable enable/disable interrupt of the timer |
|
197 |
* \param priority set the priority of the interrupt service routine |
|
198 |
* \param timer number of the timer |
|
199 |
* |
|
200 |
* \return <tt>0 (zero)</tt>, on success |
|
201 |
* \return <tt> -1 (minus one) </tt>, some argument is invalid |
|
202 |
*/ |
|
203 | 158 |
int set_timer_Int(int timer, int enable, int priority) |
204 | 159 |
{ |
205 | 160 |
if(priority < 0 || priority > 7 || enable < 0 || enable > 1 || timer < 1 || timer > 5) |
... | ... | |
231 | 186 |
return 0; |
232 | 187 |
} |
233 | 188 |
|
234 |
/** |
|
235 |
* \brief Set all Interrupts. |
|
236 |
* This function allows the microcontroller to run all types of interrupts. |
|
237 |
* |
|
238 |
* \param enable enable/disable interrupt of the timer |
|
239 |
* |
|
240 |
* \return <tt> 0 (zero)</tt>, on success |
|
241 |
* \return <tt> -1 (minus one) </tt>, some argument is invalid |
|
242 |
*/ |
|
243 | 189 |
int set_ALL_Int(int enable){ |
244 | 190 |
|
245 | 191 |
if(enable < 0 || enable > 1) |
Also available in: Unified diff