aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/timers.c
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-04-19 23:28:34 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-04-19 23:31:32 -0400
commit0e2ccd30c4bac030bc33ed248564a640a63ea3c5 (patch)
tree4a6598b5c5a90f953cb6e6665a2dbcc1523ff329 /libmaple/timers.c
parenta7b3786810ee93c81b65a431c04fd2f5d75354d2 (diff)
downloadlibrambutan-0e2ccd30c4bac030bc33ed248564a640a63ea3c5.tar.gz
librambutan-0e2ccd30c4bac030bc33ed248564a640a63ea3c5.zip
Aded two timer function to set max reload value and prescaler
Diffstat (limited to 'libmaple/timers.c')
-rw-r--r--libmaple/timers.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/libmaple/timers.c b/libmaple/timers.c
index 903f970..b13cc3a 100644
--- a/libmaple/timers.c
+++ b/libmaple/timers.c
@@ -142,6 +142,49 @@ void timer_init(uint8 timer_num, uint16 prescale) {
timer->CR1 |= 1; // Enable timer
}
+void timers_set_prescaler(uint32 timer_num, uint16 prescale) {
+ Timer *timer;
+ ASSERT(timer_num > 0 && timer_num <= 4);
+
+ switch(timer_num) {
+ case 1:
+ timer = (Timer*)TIMER1_BASE;
+ break;
+ case 2:
+ timer = (Timer*)TIMER2_BASE;
+ break;
+ case 3:
+ timer = (Timer*)TIMER3_BASE;
+ break;
+ case 4:
+ timer = (Timer*)TIMER4_BASE;
+ break;
+ }
+ timer->PSC = prescale;
+}
+
+void timers_set_reload(uint32 timer_num, uint16 max_reload) {
+ Timer *timer;
+ ASSERT(timer_num > 0 && timer_num <= 4);
+
+ switch(timer_num) {
+ case 1:
+ timer = (Timer*)TIMER1_BASE;
+ break;
+ case 2:
+ timer = (Timer*)TIMER2_BASE;
+ break;
+ case 3:
+ timer = (Timer*)TIMER3_BASE;
+ break;
+ case 4:
+ timer = (Timer*)TIMER4_BASE;
+ break;
+ }
+ timer->ARR = max_reload;
+}
+
+
void timers_disable(void) {
Timer *timer;
int i;