Explorar o código

Import data race buggy main loop

Main loop imported from ECN lab slide 137
DricomDragon %!s(int64=5) %!d(string=hai) anos
pai
achega
254006fa14
Modificáronse 1 ficheiros con 32 adicións e 46 borrados
  1. 32 46
      prog/sources/setup-loop.cpp

+ 32 - 46
prog/sources/setup-loop.cpp

@@ -1,55 +1,41 @@
 #include "all-headers.h"
 
-// Bit operation references
-const uint32_t bufferEmpty(0);
-const uint32_t bufferFull(~ bufferEmpty);
-
-// Button variables
-uint32_t antiBlinkBuffer[5];
-bool buttonReleased[5];
-bool actionDone[5];
-DigitalPort LED[5];
-DigitalPort BUTTON[5];
-
-// Counter
-uint32_t counter(0);
-
-void setup (USER_MODE) {
-	// Start
-	digitalWrite(L0_LED, true);
-
-	// Init buttons and LEDs
-	BUTTON[0] = P0_PUSH_BUTTON;
-	BUTTON[1] = P1_PUSH_BUTTON;
-	BUTTON[2] = P2_PUSH_BUTTON;
-	BUTTON[3] = P3_PUSH_BUTTON;
-	BUTTON[4] = P4_PUSH_BUTTON;
-
-	LED[0] = L0_LED;
-	LED[1] = L1_LED;
-	LED[2] = L2_LED;
-	LED[3] = L3_LED;
-	LED[4] = L4_LED;
-
-	for (unsigned int i(0); i < 5; i++) {
-		antiBlinkBuffer[i] = 0;
-		buttonReleased[i] = digitalRead(BUTTON[i]);
-		actionDone[i] = false;
+static volatile uint32_t gCount1 = 0 ;
+static volatile uint32_t gCount2 = 0 ;
+static volatile uint32_t gCount3 = 0 ;
+static volatile uint32_t gCount4 = 0 ;
+static volatile bool gPerformCount = true ;
+
+static void rtISR (SECTION_MODE_ const uint32_t inUptime) {
+	if (gPerformCount) {
+		gCount1 += 1 ;
+		gCount2 += 1 ;
+		gCount3 += 1 ;
+		gCount4 += 1 ;
 	}
+}
 
-	// Init LCD
-	printString(MODE_ "Wake up in ");
-	printUnsigned(MODE_ millis(MODE));
-	printString(MODE_ "ms");
+MACRO_REAL_TIME_ISR (rtISR) ;
 
-	gotoLineColumn(MODE_ 1, 0);
+void setup (USER_MODE) {
 }
 
 void loop (USER_MODE) {
-	busyWaitUntil(MODE_ counter * 1000);
-	counter++;
-
-	gotoLineColumn(MODE_ 1, 0);
-	printString(MODE_ "Date:");
-	printUnsigned(MODE_ millis(MODE));
+	if (gPerformCount) {
+		gCount1 += 1 ;
+		gCount2 += 1 ;
+		gCount3 += 1 ;
+		gCount4 += 1 ;
+		if (5000 <= millis (MODE)) {
+			gPerformCount = false ;
+			gotoLineColumn (MODE_ 0, 0) ;
+			printUnsigned (MODE_ gCount1) ;
+			gotoLineColumn (MODE_ 1, 0) ;
+			printUnsigned (MODE_ gCount2) ;
+			gotoLineColumn (MODE_ 2, 0) ;
+			printUnsigned (MODE_ gCount3) ;
+			gotoLineColumn (MODE_ 3, 0) ;
+			printUnsigned (MODE_ gCount4) ;
+		}
+	}
 }