aboutsummaryrefslogtreecommitdiffstats
path: root/libmaple/systick.c
diff options
context:
space:
mode:
authorPerry Hung <iperry@alum.mit.edu>2010-08-04 08:52:30 -0400
committerPerry Hung <iperry@alum.mit.edu>2010-08-04 08:52:30 -0400
commitd2494611156c4ba477a1bbd1b07ba0cfc14b29e4 (patch)
tree48782014152efa392ac0689c4098e089da52c82c /libmaple/systick.c
parent2b7a1b40c96525cd4c6324f6e9d53845fb07a55f (diff)
downloadlibrambutan-d2494611156c4ba477a1bbd1b07ba0cfc14b29e4.tar.gz
librambutan-d2494611156c4ba477a1bbd1b07ba0cfc14b29e4.zip
Cleaned up wirish/time, some interrupt handling refactoring:
Fixed millis(), it was just wrong, before. Added micros(), not extensively tested. New implementation of delayMicroseconds(). Should be more consistent now. Added a handful of nvic routines to enable/disable interrupts. Cleaned up systick
Diffstat (limited to 'libmaple/systick.c')
-rw-r--r--libmaple/systick.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/libmaple/systick.c b/libmaple/systick.c
index a333528..8b0d92a 100644
--- a/libmaple/systick.c
+++ b/libmaple/systick.c
@@ -31,23 +31,25 @@
#include "libmaple.h"
#include "systick.h"
-#define MILLIS_INC 1
+#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 = 0;
-void systick_init(void) {
+void systick_init(uint32 reload_val) {
/* Set the reload counter to tick every 1ms */
- REG_SET_MASK(SYSTICK_RELOAD, MAPLE_RELOAD_VAL);
-// SYSTICK_RELOAD = MAPLE_RELOAD_VAL;
+ __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()*/
- REG_SET(SYSTICK_CSR, SYSTICK_SRC_HCLK |
+ __write(SYSTICK_CSR, SYSTICK_SRC_HCLK |
SYSTICK_ENABLE |
SYSTICK_TICKINT);
-// SYSTICK_CSR = SYSTICK_SRC_HCLK |
-// SYSTICK_ENABLE |
-// SYSTICK_TICKINT;
}
void SysTickHandler(void) {