aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorchrysn2012-04-27 15:21:59 +0200
committerchrysn2012-04-27 15:21:59 +0200
commitc9b074a120baea1af4fa15fd678a3f1635fe4daa (patch)
treea3113ff6afe0e7ec197f5906df00f6b3a306f32f /include
parent286af7f26e756cf47eac75f441f17012cedce44b (diff)
sys tick cmsis interface for blink example
Diffstat (limited to 'include')
-rw-r--r--include/libopencmsis/core_cm3.h41
1 files changed, 40 insertions, 1 deletions
diff --git a/include/libopencmsis/core_cm3.h b/include/libopencmsis/core_cm3.h
index f27d781..708fd48 100644
--- a/include/libopencmsis/core_cm3.h
+++ b/include/libopencmsis/core_cm3.h
@@ -96,7 +96,41 @@ typedef struct
/* required for the blink example */
-#define SysTick_Config(x) 0
+/* if if (SysTick_Config(CMU_ClockFreqGet(cmuClock_CORE) / 1000)) while (1) ;
+ * configures the sys ticks to 1ms, then the argument to SysTick_Config
+ * describes how many cycles to wait between two systicks.
+ *
+ * the endless loop part looks like an "if it returns an error condition,
+ * rather loop here than continue"; every other solution would involve things
+ * that are dark magic to my understanding.
+ *
+ * implementation more or less copypasted from lib/stm32/systick.c, FIXME until
+ * the generic cm3 functionality is moved out from stm32 and can be used here
+ * easily (systick_set_reload, systick_interrupt_enable, systick_counter_enable
+ * and systick_set_clocksource).
+ * */
+#define SYS_TICK_BASE (SCS_BASE + 0x0010)
+#define MMIO32(addr) (*(volatile uint32_t *)(addr))
+#define STK_LOAD MMIO32(SYS_TICK_BASE + 0x04)
+#define STK_CTRL MMIO32(SYS_TICK_BASE + 0x00)
+#define STK_CTRL_TICKINT (1 << 1)
+#define STK_CTRL_ENABLE (1 << 0)
+
+#define STK_CTRL_CLKSOURCE_LSB 2
+#define STK_CTRL_CLKSOURCE_AHB 1
+static inline uint32_t SysTick_Config(uint32_t n_ticks)
+{
+ if (n_ticks & ~0x00FFFFFF) return 1;
+ STK_LOAD = n_ticks;
+
+ STK_CTRL |= (STK_CTRL_CLKSOURCE_AHB << STK_CTRL_CLKSOURCE_LSB);
+
+ STK_CTRL |= STK_CTRL_TICKINT;
+
+ STK_CTRL |= STK_CTRL_ENABLE;
+
+ return 0;
+}
/* stubs for efm32tg stk trace.c */
typedef struct
@@ -106,4 +140,9 @@ typedef struct
} ITM_TypeDef;
#define ITM ((ITM_TypeDef *) 0)
+/* blink.h expects the isr for systicks to be named SysTick_Handler. with this,
+ * its Systick_Handler function gets renamed to the weak symbol exported by
+ * vector.c */
+#define SysTick_Handler sys_tick_handler
+
#endif