aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Otto2010-04-13 22:26:07 +0200
committerThomas Otto2010-04-13 22:26:07 +0200
commit905b5112b69b83acac1a6f896d363da4d2e7c648 (patch)
tree2eaad7340fdfc345fa4f30e2275bce8d31015c6d
parent37e71e3e5c526baf0bf001a6cac9141072e9a911 (diff)
Some improvements to systick.h+c.
-rw-r--r--include/libopenstm32/systick.h20
-rw-r--r--lib/systick.c44
2 files changed, 60 insertions, 4 deletions
diff --git a/include/libopenstm32/systick.h b/include/libopenstm32/systick.h
index a4e426c..a45f744 100644
--- a/include/libopenstm32/systick.h
+++ b/include/libopenstm32/systick.h
@@ -26,16 +26,16 @@
/* --- SYSTICK registers --------------------------------------------------- */
/* Control and status register (STK_CTRL) */
-#define STK_CTRL MMIO32(SYSTICK_BASE + 0x00)
+#define STK_CTRL MMIO32(SYS_TICK_BASE + 0x00)
/* reload value register (STK_LOAD) */
-#define STK_LOAD MMIO32(SYSTICK_BASE + 0x04)
+#define STK_LOAD MMIO32(SYS_TICK_BASE + 0x04)
/* current value register (STK_VAL) */
-#define STK_VAL MMIO32(SYSTICK_BASE + 0x08)
+#define STK_VAL MMIO32(SYS_TICK_BASE + 0x08)
/* calibration value register (STK_CALIB) */
-#define STK_CALIB MMIO32(SYSTICK_BASE + 0x0C)
+#define STK_CALIB MMIO32(SYS_TICK_BASE + 0x0C)
/* --- STK_CTRL values ----------------------------------------------------- */
/* Bits [31:17] Reserved, must be kept cleared. */
@@ -44,6 +44,9 @@
/* Bits [15:3] Reserved, must be kept cleared. */
/* CLKSOURCE: Clock source selection */
#define STK_CTRL_CLKSOURCE (1 << 2)
+#define STK_CTRL_CLKSOURCE_LSB 2
+#define STK_CTRL_CLKSOURCE_AHB_DIV8 0
+#define STK_CTRL_CLKSOURCE_AHB 1
/* TICKINT: SysTick exception request enable */
#define STK_CTRL_TICKINT (1 << 1)
/* ENABLE: Counter enable */
@@ -67,4 +70,13 @@
/* --- Function Prototypes ------------------------------------------------- */
+void systick_set_reload(u32 value);
+u32 systick_get_value(void);
+void systick_set_clocksource(u8 clocksource);
+void systick_interrupt_enable(void);
+void systick_interrupt_disable(void);
+void systick_counter_enable(void);
+void systick_counter_disable(void);
+u8 systick_get_countflag(void);
+
#endif
diff --git a/lib/systick.c b/lib/systick.c
index 3298ee6..9b298d5 100644
--- a/lib/systick.c
+++ b/lib/systick.c
@@ -19,4 +19,48 @@
#include <libopenstm32/systick.h>
+void systick_set_reload(u32 value)
+{
+ STK_LOAD = (value & 0x00FFFFFF);
+}
+
+u32 systick_get_value(void)
+{
+ return STK_VAL;
+}
+
+void systick_set_clocksource(u8 clocksource)
+{
+ if (clocksource < 2)
+ STK_CTRL |= (clocksource << STK_CTRL_CLKSOURCE_LSB);
+}
+
+void systick_interrupt_enable(void)
+{
+ STK_CTRL |= STK_CTRL_TICKINT;
+}
+
+void systick_interrupt_disable(void)
+{
+ STK_CTRL &= ~STK_CTRL_TICKINT;
+}
+
+void systick_counter_enable(void)
+{
+ STK_CTRL |= STK_CTRL_ENABLE;
+}
+
+void systick_counter_disable(void)
+{
+ STK_CTRL &= ~STK_CTRL_ENABLE;
+}
+
+u8 systick_get_countflag(void)
+{
+ if (STK_CTRL & STK_CTRL_COUNTFLAG)
+ return 1;
+ else
+ return 0;
+}
+