From d2494611156c4ba477a1bbd1b07ba0cfc14b29e4 Mon Sep 17 00:00:00 2001 From: Perry Hung Date: Wed, 4 Aug 2010 08:52:30 -0400 Subject: 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 --- libmaple/systick.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'libmaple/systick.c') 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) { -- cgit v1.2.3