static void spin(int);
+// Since SysTick is only 24-bits, we'll need to divide it by 4 to produce a
+// 2Hz value from the 80MHz system clock.
+// Yes, I know I can just run the system clock slower, but this is more fun.
+static const int initial_systick_count = 3;
+static int systick_count;
+
__attribute__((isr))
void main_isr() {
// Power on the PLL, set to 16MHz XTAL
GPIO_PORTF_DEN_R = 0xE;
// Set RGB pins to 1
- *(GPIO_PORTF_DATA_BITS_R + 0xE) = 0x2;
+ *(GPIO_PORTF_DATA_BITS_R + 0xE) = 0xF;
+
+ // Initialize our SysTick prescaler
+ systick_count = initial_systick_count;
+
+ // Initialize the SysTick module
+ NVIC_ST_RELOAD_R = 10000000; // produce 8Hz from 80MHz clock
+ NVIC_ST_CURRENT_R = 0;
+ NVIC_ST_CTRL_R |= 0x7;
// infinite loop
for (;;) {
- *(GPIO_PORTF_DATA_BITS_R + 0xC) ^= 0xC;
+ asm("wfi");
- spin(1000000);
+ // flip the green LED on every WFI, as an experiment to see if the
+ // CPU is really sleeping.
+ // Answer: it is.
+ // *(GPIO_PORTF_DATA_BITS_R + 0x8) ^= 0xFF;
}
}
asm("");
}
}
+
+__attribute__((isr))
+void systick_isr() {
+ if (systick_count) {
+ systick_count--;
+ return;
+ }
+
+ systick_count = initial_systick_count;
+ *(GPIO_PORTF_DATA_BITS_R + 0xE) ^= 0xF;
+}