瀏覽代碼

Call systick wait

DricomDragon 5 年之前
父節點
當前提交
aa1b615650
共有 2 個文件被更改,包括 20 次插入13 次删除
  1. 19 12
      prog/sources/setup-loop.cpp
  2. 1 1
      prog/sources/time.cpp

+ 19 - 12
prog/sources/setup-loop.cpp

@@ -3,20 +3,27 @@
 // Led L2 is connected to PORTD:7 (active high)
 
 void setup (void) {
-// Configure PTD7 as digital port (input or output)
-  PORTD_PCR (7) = PORT_PCR_MUX (1) ;
-// Configure PTD7 as digital output port (output level is low --> led is off)
-  GPIOD_PDDR |= (1 << 7) ;
+	// Configure PTD7 as digital port (input or output)
+	PORTD_PCR (7) = PORT_PCR_MUX (1) ;
+
+	// Configure PTD7 as digital output port (output level is low --> led is off)
+	GPIOD_PDDR |= (1 << 7) ;
+
+	// Init clock
+	startSystick();
 }
 
 void loop (void) {
-// Drive PTD7 high --> led is on
-  GPIOD_PSOR = 1 << 7 ;
-// Wait...
-  for (volatile uint32_t i=0 ; i< 10 * 2000 * 1000 ; i++) {}
-// Drive PTD7 low --> led is off
-  GPIOD_PCOR = 1 << 7 ;
-// Wait...
-  for (volatile uint32_t i=0 ; i< 10 * 500 * 1000 ; i++) {}
+	// Drive PTD7 high --> led is on
+	GPIOD_PSOR = 1 << 7 ;
+
+	// Wait...
+	busyWaitDuring(500);
+
+	// Drive PTD7 low --> led is off
+	GPIOD_PCOR = 1 << 7 ;
+
+	// Wait...
+	busyWaitDuring(500);
 }
 

+ 1 - 1
prog/sources/time.cpp

@@ -6,7 +6,7 @@ void startSystick (void) {
 	SYST_CSR = SYST_CSR_CLKSOURCE | SYST_CSR_ENABLE ;
 }
 
-oid busyWaitDuring (const uint32_t inDelayMS) {
+void 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