aboutsummaryrefslogtreecommitdiffstats
path: root/wirish
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2010-09-05 18:34:44 -0400
committerbnewbold <bnewbold@robocracy.org>2010-09-05 22:58:36 -0400
commitb6e3624a705b36b15e7f4c0637d133c7dab059bd (patch)
tree700df3f574cb1ea64faf719de4bd6607a1addc6e /wirish
parent16b4c1fce5b1023cfb8210f9c12f09c71d4a755d (diff)
downloadlibrambutan-b6e3624a705b36b15e7f4c0637d133c7dab059bd.tar.gz
librambutan-b6e3624a705b36b15e7f4c0637d133c7dab059bd.zip
timer refactor (c, not c++)
also removed an old ASSERT()
Diffstat (limited to 'wirish')
-rw-r--r--wirish/HardwareTimer.cpp47
-rw-r--r--wirish/HardwareTimer.h10
-rw-r--r--wirish/comm/HardwareSPI.cpp4
-rw-r--r--wirish/comm/HardwareSerial.cpp4
-rw-r--r--wirish/wirish.c12
5 files changed, 19 insertions, 58 deletions
diff --git a/wirish/HardwareTimer.cpp b/wirish/HardwareTimer.cpp
index f55e6b0..99863c1 100644
--- a/wirish/HardwareTimer.cpp
+++ b/wirish/HardwareTimer.cpp
@@ -32,8 +32,10 @@
#include "HardwareTimer.h"
HardwareTimer::HardwareTimer(uint8 timerNum) {
- ASSERT(timerNum <= NR_TIMERS);
+ ASSERT(timerNum <= NR_TIMERS && timerNum != 6 && timerNum != 7);
+
this->timerNum = timerNum;
+
// Need to remember over flow for bounds checking
this->overflow = 0xFFFF;
}
@@ -104,7 +106,6 @@ void HardwareTimer::setCompare2(uint16 val) {
timer_set_compare_value(this->timerNum,2,val);
}
void HardwareTimer::setCompare3(uint16 val) {
- ASSERT(this->timerNum);
if(val > this->overflow)
val = this->overflow;
timer_set_compare_value(this->timerNum,3,val);
@@ -138,43 +139,13 @@ void HardwareTimer::detachCompare3Interrupt(void) {
void HardwareTimer::detachCompare4Interrupt(void) {
timer_detach_interrupt(this->timerNum,4);
}
-#if NR_TIMERS >= 8
-void HardwareTimer::setChannel5Mode(uint8 mode) {
- timer_set_mode(this->timerNum,5,mode);
-}
-void HardwareTimer::setChannel8Mode(uint8 mode) {
- timer_set_mode(this->timerNum,8,mode);
-}
-void HardwareTimer::setCompare5(uint16 val) {
- if(val > this->overflow)
- val = this->overflow;
- timer_set_compare_value(this->timerNum,5,val);
-}
-void HardwareTimer::setCompare8(uint16 val) {
- if(val > this->overflow)
- val = this->overflow;
- timer_set_compare_value(this->timerNum,8,val);
-}
-void HardwareTimer::attachCompare5Interrupt(voidFuncPtr handler) {
- timer_attach_interrupt(this->timerNum,5,handler);
-}
-void HardwareTimer::attachCompare8Interrupt(voidFuncPtr handler) {
- timer_attach_interrupt(this->timerNum,8,handler);
-}
-void HardwareTimer::detachCompare5Interrupt(void) {
- timer_detach_interrupt(this->timerNum,5);
-}
-void HardwareTimer::detachCompare8Interrupt(void) {
- timer_detach_interrupt(this->timerNum,8);
-}
-#endif
-HardwareTimer Timer1(1);
-HardwareTimer Timer2(2);
-HardwareTimer Timer3(3);
-HardwareTimer Timer4(4);
+HardwareTimer Timer1(TIMER1);
+HardwareTimer Timer2(TIMER2);
+HardwareTimer Timer3(TIMER3);
+HardwareTimer Timer4(TIMER4);
#if NR_TIMERS >= 8
-HardwareTimer Timer5(5); // High-density devices only
-HardwareTimer Timer8(8); // High-density devices only
+HardwareTimer Timer5(TIMER5); // High-density devices only
+HardwareTimer Timer8(TIMER8); // High-density devices only
#endif
diff --git a/wirish/HardwareTimer.h b/wirish/HardwareTimer.h
index 3f986e4..aa48718 100644
--- a/wirish/HardwareTimer.h
+++ b/wirish/HardwareTimer.h
@@ -62,16 +62,6 @@ class HardwareTimer {
void detachCompare2Interrupt(void);
void detachCompare3Interrupt(void);
void detachCompare4Interrupt(void);
- #if NR_TIMERS >= 8
- void setChannel5Mode(uint8 mode);
- void setChannel8Mode(uint8 mode);
- void setCompare5(uint16 val); // truncates to overflow
- void setCompare8(uint16 val); // truncates to overflow
- void attachCompare5Interrupt(voidFuncPtr handler);
- void attachCompare8Interrupt(voidFuncPtr handler);
- void detachCompare5Interrupt(void);
- void detachCompare8Interrupt(void);
- #endif
};
extern HardwareTimer Timer1;
diff --git a/wirish/comm/HardwareSPI.cpp b/wirish/comm/HardwareSPI.cpp
index eadcdd7..5f42db7 100644
--- a/wirish/comm/HardwareSPI.cpp
+++ b/wirish/comm/HardwareSPI.cpp
@@ -95,8 +95,8 @@ void HardwareSPI::begin(SPIFrequency freq, uint32 endianness, uint32 mode) {
}
/* Turn off PWM on shared pins */
- timer_set_mode(3, 2, TIMER_DISABLED);
- timer_set_mode(3, 1, TIMER_DISABLED);
+ timer_set_mode(TIMER3, 2, TIMER_DISABLED);
+ timer_set_mode(TIMER3, 1, TIMER_DISABLED);
}
endianness = (endianness == LSBFIRST) ? SPI_LSBFIRST : SPI_MSBFIRST;
diff --git a/wirish/comm/HardwareSerial.cpp b/wirish/comm/HardwareSerial.cpp
index 6399ad5..902b160 100644
--- a/wirish/comm/HardwareSerial.cpp
+++ b/wirish/comm/HardwareSerial.cpp
@@ -34,8 +34,8 @@
#include "gpio.h"
#include "timers.h"
-HardwareSerial Serial1(USART1, 4500000UL, GPIOA_BASE, 9, 10, 1, 2);
-HardwareSerial Serial2(USART2, 2250000UL, GPIOA_BASE, 2, 3, 2, 3);
+HardwareSerial Serial1(USART1, 4500000UL, GPIOA_BASE, 9, 10, TIMER1, 2);
+HardwareSerial Serial2(USART2, 2250000UL, GPIOA_BASE, 2, 3, TIMER2, 3);
HardwareSerial Serial3(USART3, 2250000UL, GPIOB_BASE, 10, 11, 0, 0);
// TODO: High density device ports
diff --git a/wirish/wirish.c b/wirish/wirish.c
index 9f3b19e..5407131 100644
--- a/wirish/wirish.c
+++ b/wirish/wirish.c
@@ -66,13 +66,13 @@ void init(void) {
systick_init(MAPLE_RELOAD_VAL);
gpio_init();
adc_init();
- timer_init(1, 1);
- timer_init(2, 1);
- timer_init(3, 1);
- timer_init(4, 1);
+ timer_init(TIMER1, 1);
+ timer_init(TIMER2, 1);
+ timer_init(TIMER3, 1);
+ timer_init(TIMER4, 1);
#if NR_TIMERS >= 8
- timer_init(5, 1);
- timer_init(8, 1);
+ timer_init(TIMER5, 1);
+ timer_init(TIMER8, 1);
#endif
setupUSB();
}