|
@@ -1,5 +1,7 @@
|
|
|
#include "all-headers.h"
|
|
|
|
|
|
+static volatile uint32_t gUptime;
|
|
|
+
|
|
|
static void startSystick (BOOT_MODE) {
|
|
|
SYST_RVR = CPU_MHZ * 1000 - 1 ; // Underflow every ms
|
|
|
SYST_CVR = 0 ;
|
|
@@ -8,6 +10,12 @@ static void startSystick (BOOT_MODE) {
|
|
|
|
|
|
MACRO_BOOT_ROUTINE (startSystick);
|
|
|
|
|
|
+static void activateSystickInterrupt (INIT_MODE) {
|
|
|
+ SYST_CSR |= SYST_CSR_TICKINT;
|
|
|
+}
|
|
|
+
|
|
|
+MACRO_INIT_ROUTINE (activateSystickInterrupt);
|
|
|
+
|
|
|
void busyWaitDuring_initMode (INIT_MODE_ const uint32_t inDelayMS) {
|
|
|
const uint32_t COUNTFLAG_MASK = 1 << 16 ;
|
|
|
for (uint32_t i=0 ; i<inDelayMS ; i++) {
|
|
@@ -16,8 +24,13 @@ void busyWaitDuring_initMode (INIT_MODE_ const uint32_t inDelayMS) {
|
|
|
}
|
|
|
|
|
|
void busyWaitDuring (USER_MODE_ const uint32_t inDelayMS) {
|
|
|
- const uint32_t COUNTFLAG_MASK = 1 << 16 ;
|
|
|
- for (uint32_t i = 0; i < inDelayMS; i++) {
|
|
|
- while ((SYST_CSR & COUNTFLAG_MASK) == 0) {} // Busy wait, polling COUNTFLAG
|
|
|
- }
|
|
|
+ busyWaitUntil(MODE_ gUptime + inDelayMS);
|
|
|
+}
|
|
|
+
|
|
|
+void busyWaitUntil (USER_MODE_ const uint32_t inDeadLineMS) {
|
|
|
+ while (inDeadLineMS > gUptime) {}
|
|
|
+}
|
|
|
+
|
|
|
+void systickInterruptServiceRoutine (SECTION_MODE) {
|
|
|
+ gUptime += 1;
|
|
|
}
|