소스 검색

Implement the mecanism of SysTick interruptions

Implement busyWaitUntil and improve busyWaitDuring
DricomDragon 5 년 전
부모
커밋
4ca46a9c67
2개의 변경된 파일23개의 추가작업 그리고 4개의 파일을 삭제
  1. 17 4
      prog/sources/time.cpp
  2. 6 0
      prog/sources/time.h

+ 17 - 4
prog/sources/time.cpp

@@ -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;
 }

+ 6 - 0
prog/sources/time.h

@@ -6,3 +6,9 @@ void busyWaitDuring_initMode (INIT_MODE_ const uint32_t inDelayMS);
 
 void busyWaitDuring (USER_MODE_ const uint32_t inDelayMS);
 
+void busyWaitUntil (USER_MODE_ const uint32_t inDeadLineMS);
+
+// Prevent default SysTick interruption code generation
+//$interrupt-section SysTick
+
+void systickInterruptServiceRoutine (SECTION_MODE) asm ("interrupt.section.SysTick");