Browse Source

Import functions from course

DricomDragon 5 years ago
parent
commit
508f28ef23
1 changed files with 14 additions and 0 deletions
  1. 14 0
      prog/sources/time.cpp

+ 14 - 0
prog/sources/time.cpp

@@ -0,0 +1,14 @@
+#include "all-headers.h"
+
+void startSystick (void) {
+	SYST_RVR = CPU_MHZ * 1000 - 1 ; // Underflow every ms
+	SYST_CVR = 0 ;
+	SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_ENABLE ;
+}
+
+oid busyWaitDuring (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
+	}
+}