diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-01 03:26:19 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-01 03:27:05 -0400 |
commit | 73f2cefbdf6d8f255bc5284c64d315f38ee45616 (patch) | |
tree | 921a46ea5a1de17131b1cba3e6a42de52d870961 /wirish | |
parent | 5befb0826a1ff77994c55f42cd73ccf0905a5ce0 (diff) | |
download | librambutan-73f2cefbdf6d8f255bc5284c64d315f38ee45616.tar.gz librambutan-73f2cefbdf6d8f255bc5284c64d315f38ee45616.zip |
Bring back HardwareTimer.
Untested, but the timers work on F2 (see exampes/test-timers.cpp), so
I'm hoping this is mostly OK. Note that there's an issue with TIMER2
and TIMER5 on F2: these timers have 32-bit counters, and the
HardwareTimer methods are all based on uint16 (like on F1).
I'm sorely tempted to keep this as-is; exposing the extra bits is just
extra documentation, and the HardwareTimer interface is already way
too complicated. The interface should still _work_; it just hides the
fact that you're missing out on the extra bits for some of the timers.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'wirish')
-rw-r--r-- | wirish/HardwareTimer.cpp | 123 | ||||
-rw-r--r-- | wirish/include/wirish/HardwareTimer.h | 2 | ||||
-rw-r--r-- | wirish/rules.mk | 2 |
3 files changed, 104 insertions, 23 deletions
diff --git a/wirish/HardwareTimer.cpp b/wirish/HardwareTimer.cpp index 52257bf..ca8ea63 100644 --- a/wirish/HardwareTimer.cpp +++ b/wirish/HardwareTimer.cpp @@ -30,33 +30,114 @@ // TODO [0.1.0] Remove deprecated pieces -#ifdef STM32_MEDIUM_DENSITY -#define NR_TIMERS 4 -#elif defined(STM32_HIGH_DENSITY) -#define NR_TIMERS 8 +#define MAX_RELOAD ((1 << 16) - 1) + +/* + * Big ugly table of timers available on the MCU. Needed by the + * HardwareTimer constructor. Sigh; maybe predefined instances weren't + * such a bad idea. Oh well, at least the HardwareTimer interface is + * officially unstable since v0.0.12; we can always get rid of this + * later. + */ + +#define MAX_NR_TIMERS 17 // No STM32 I've ever heard of has higher than TIMER17 + +static timer_dev *devs[MAX_NR_TIMERS] = { +#if STM32_HAVE_TIMER(1) + TIMER1, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(2) + TIMER2, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(3) + TIMER3, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(4) + TIMER4, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(5) + TIMER5, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(6) + TIMER6, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(7) + TIMER7, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(8) + TIMER8, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(9) + TIMER9, #else -#error "Unsupported density" + NULL, #endif +#if STM32_HAVE_TIMER(10) + TIMER10, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(11) + TIMER11, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(12) + TIMER12, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(13) + TIMER13, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(14) + TIMER14, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(15) + TIMER15, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(16) + TIMER16, +#else + NULL, +#endif +#if STM32_HAVE_TIMER(17) + TIMER17, +#else + NULL, +#endif +}; -#define MAX_RELOAD ((1 << 16) - 1) +/* + * HardwareTimer routines + */ HardwareTimer::HardwareTimer(uint8 timerNum) { - if (timerNum > NR_TIMERS) { - ASSERT(0); - } - timer_dev *devs[] = { - TIMER1, - TIMER2, - TIMER3, - TIMER4, -#ifdef STM32_HIGH_DENSITY - TIMER5, - TIMER6, - TIMER7, - TIMER8, -#endif - }; + ASSERT(timerNum <= MAX_NR_TIMERS); this->dev = devs[timerNum - 1]; + ASSERT(this->dev != NULL); } void HardwareTimer::pause(void) { diff --git a/wirish/include/wirish/HardwareTimer.h b/wirish/include/wirish/HardwareTimer.h index bdcca5d..d322033 100644 --- a/wirish/include/wirish/HardwareTimer.h +++ b/wirish/include/wirish/HardwareTimer.h @@ -313,7 +313,7 @@ extern HardwareTimer Timer3; * Pre-instantiated timer. */ extern HardwareTimer Timer4; -#ifdef STM32_HIGH_DENSITY +#if (STM32_MCU_SERIES == STM32_SERIES_F1) && defined(STM32_HIGH_DENSITY) /** * @brief Deprecated. * diff --git a/wirish/rules.mk b/wirish/rules.mk index deb3906..54c9180 100644 --- a/wirish/rules.mk +++ b/wirish/rules.mk @@ -23,6 +23,7 @@ cSRCS_$(d) := start_c.c cppSRCS_$(d) := boards.cpp cppSRCS_$(d) += cxxabi-compat.cpp cppSRCS_$(d) += HardwareSerial.cpp +cppSRCS_$(d) += HardwareTimer.cpp cppSRCS_$(d) += Print.cpp cppSRCS_$(d) += wirish_analog.cpp cppSRCS_$(d) += wirish_digital.cpp @@ -34,7 +35,6 @@ cppSRCS_$(d) += $(MCU_SERIES)/wirish_digital.cpp cppSRCS_$(d) += $(WIRISH_BOARD_PATH)/board.cpp # TODO: revise these appropriately F2 and put them back in: # HardwareSPI.cpp -# HardwareTimer.cpp # usb_serial.cpp # pwm.cpp # ext_interrupts.cpp |