浏览代码

Import functions from course

DricomDragon 5 年之前
父节点
当前提交
508f28ef23
共有 1 个文件被更改,包括 14 次插入0 次删除
  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
+	}
+}