diff options
Diffstat (limited to 'src/lib/systick.h')
-rw-r--r-- | src/lib/systick.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/lib/systick.h b/src/lib/systick.h new file mode 100644 index 0000000..42d33d0 --- /dev/null +++ b/src/lib/systick.h @@ -0,0 +1,37 @@ +#ifndef _SYSTICK_H_ +#define _SYSTICK_H_ +#include <inttypes.h> +#include "util.h" + +/* To the ARM technical manual... there's nearly nothing on the systick + * timer in the stm32 manual */ + +#define SYSTICK_CSR *(volatile int*)0xE000E010 // Control and status register +#define SYSTICK_RELOAD *(volatile int*)0xE000E014 // Reload value register +#define SYSTICK_CNT *(volatile int*)0xE000E018 // Current value register +#define SYSTICK_CALIB *(volatile int*)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 + +/* We use the systick timer to tick once + * every millisecond */ +#define MAPLE_RELOAD_VAL 72000 + +#ifdef __cplusplus +extern "C"{ +#endif + +void systick_init(void); + +static inline uint32_t systick_get_count(void) { + return (uint32_t)SYSTICK_CNT; +} + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif + |