diff options
author | Perry Hung <iperry@alum.mit.edu> | 2010-04-19 23:28:34 -0400 |
---|---|---|
committer | Perry Hung <iperry@alum.mit.edu> | 2010-04-19 23:31:32 -0400 |
commit | 0e2ccd30c4bac030bc33ed248564a640a63ea3c5 (patch) | |
tree | 4a6598b5c5a90f953cb6e6665a2dbcc1523ff329 /libmaple | |
parent | a7b3786810ee93c81b65a431c04fd2f5d75354d2 (diff) | |
download | librambutan-0e2ccd30c4bac030bc33ed248564a640a63ea3c5.tar.gz librambutan-0e2ccd30c4bac030bc33ed248564a640a63ea3c5.zip |
Aded two timer function to set max reload value and prescaler
Diffstat (limited to 'libmaple')
-rw-r--r-- | libmaple/timers.c | 43 | ||||
-rw-r--r-- | libmaple/timers.h | 3 |
2 files changed, 46 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; diff --git a/libmaple/timers.h b/libmaple/timers.h index bcc7f2f..1ee89a0 100644 --- a/libmaple/timers.h +++ b/libmaple/timers.h @@ -122,6 +122,8 @@ typedef volatile uint32* TimerCCR; void timer_init(uint8, uint16); void timers_disable(void); void timers_disable_channel(uint8, uint8); +void timers_set_prescaler(uint32 timer_num, uint16 prescale); +void timers_set_reload(uint32 timer_num, uint16 max_reload); /* Turn on PWM with duty_cycle on the specified channel in timer. * This function takes in a pointer to the corresponding CCR @@ -140,6 +142,7 @@ static inline void timer_pwm_write_ccr(TimerCCR CCR, uint16 duty_cycle) { *CCR = duty_cycle; } + #ifdef __cplusplus } // extern "C" #endif |