Send two chars per second through UART for testing
authorMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 17:33:21 +0000 (09:33 -0800)
committerMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 18:18:48 +0000 (10:18 -0800)
isr_table.c
main.c
main.h

index 367f480..e0d0f9b 100644 (file)
@@ -19,7 +19,7 @@ void (*reset_vectors[])() = {
        infinite_loop_isr,
        infinite_loop_isr,
        infinite_loop_isr,
-       infinite_loop_isr,
+       systick_isr,
        infinite_loop_isr,
        infinite_loop_isr,
        infinite_loop_isr,
diff --git a/main.c b/main.c
index 807e879..3588743 100644 (file)
--- a/main.c
+++ b/main.c
@@ -55,6 +55,14 @@ void main_isr() {
        // Go!
        UART0_CTL_R |= UART_CTL_UARTEN;
 
+       // 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 (;;) { 
                asm("wfi");
@@ -76,3 +84,17 @@ void uart0_isr() {
        data = (data + 1) & 0xFF;
        UART0_DR_R = data;
 }
+
+__attribute__((isr))
+void systick_isr() {
+       // Divide the SysTick timer by (initial_systick_count+1) since the
+       // system clock is running pretty fast
+       if (systick_count) {
+               systick_count--;
+               return;
+       }
+       systick_count = initial_systick_count;
+
+       // Send a character out the UART for simple testing
+       UART0_DR_R = 'F';
+}
diff --git a/main.h b/main.h
index 63863fa..0e92f19 100644 (file)
--- a/main.h
+++ b/main.h
@@ -3,5 +3,6 @@
 
 extern void main_isr();
 extern void uart0_isr();
+extern void systick_isr();
 
 #endif