aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/systick.c
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2011-04-01 03:15:27 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2011-04-05 14:13:35 -0400
commitb835b9864d7fa17de8eeaaafbb1b17f2252e68a5 (patch)
treeb35bd53503883d74f44f69847d09eec20a7ea26f /libmaple/systick.c
parent6229da7a3ec40fb7d87c0c4edd38bc32da36ef13 (diff)
downloadlibrambutan-b835b9864d7fa17de8eeaaafbb1b17f2252e68a5.tar.gz
librambutan-b835b9864d7fa17de8eeaaafbb1b17f2252e68a5.zip
SysTick refactor.
For the changelog: * util.h is free of __read(), __write(), etc. macros. * systick_resume() was renamed systick_enable().
Diffstat (limited to 'libmaple/systick.c')
-rw-r--r--libmaple/systick.c54
1 files changed, 28 insertions, 26 deletions
diff --git a/libmaple/systick.c b/libmaple/systick.c
index b9a52c1..c04f4f3 100644
--- a/libmaple/systick.c
+++ b/libmaple/systick.c
@@ -26,44 +26,46 @@
* @brief System timer interrupt handler and initialization routines
*/
-#include "libmaple.h"
#include "systick.h"
-#define SYSTICK_RELOAD 0xE000E014 // Reload value register
-#define SYSTICK_CNT 0xE000E018 // Current value register
-#define SYSTICK_CALIB 0xE000E01C // Calibration value register
-
-#define SYSTICK_SRC_HCLK BIT(2) // Use core clock
-#define SYSTICK_TICKINT BIT(1) // Interrupt on systick countdown
-#define SYSTICK_ENABLE BIT(0) // Turn on the counter
-
volatile uint32 systick_timer_millis;
+/**
+ * @brief Initialize and enable SysTick.
+ *
+ * Clocks the system timer with the core clock, turns it on, and
+ * enables interrupts.
+ *
+ * @param reload_val Appropriate reload counter to tick every 1 ms.
+ */
void systick_init(uint32 reload_val) {
- /* Set the reload counter to tick every 1ms */
- __write(SYSTICK_RELOAD, reload_val);
-
- /* Clock the system timer with the core clock and turn it on,
- * interrrupt every 1ms to keep track of millis() */
- __write(SYSTICK_CSR, SYSTICK_SRC_HCLK |
- SYSTICK_ENABLE |
- SYSTICK_TICKINT);
+ SYSTICK_BASE->RVR = reload_val;
+ systick_enable();
}
+/**
+ * Clock the system timer with the core clock, but don't turn it
+ * on or enable interrupt.
+ */
void systick_disable() {
- /* clock the system timer with the core clock, but don't turn it
- on or enable interrupt. */
- __write(SYSTICK_CSR, SYSTICK_SRC_HCLK);
+ SYSTICK_BASE->CSR = SYSTICK_CSR_CLKSOURCE_CORE;
}
-void systick_resume() {
- /* re-enable init registers without changing reload val */
- __write(SYSTICK_CSR, SYSTICK_SRC_HCLK |
- SYSTICK_ENABLE |
- SYSTICK_TICKINT);
+/**
+ * Clock the system timer with the core clock and turn it on;
+ * interrupt every 1 ms, for systick_timer_millis.
+ */
+void systick_enable() {
+ /* re-enables init registers without changing reload val */
+ SYSTICK_BASE->CSR = (SYSTICK_CSR_CLKSOURCE_CORE |
+ SYSTICK_CSR_ENABLE |
+ SYSTICK_CSR_TICKINT_PEND);
}
-/** SysTick interrupt handler. Bumps up the tick counter. */
+/*
+ * SysTick ISR
+ */
+
void __exc_systick(void) {
systick_timer_millis++;
}