Use LED to display the bits received from UART
authorMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 18:10:11 +0000 (10:10 -0800)
committerMatt Mullins <mmullins@mmlx.us>
Sun, 23 Dec 2012 18:18:48 +0000 (10:18 -0800)
main.c

diff --git a/main.c b/main.c
index 4cfd891..0aed93b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -9,8 +9,13 @@ static void spin(int);
 static const int initial_systick_count = 3;
 static int systick_count;
 
+static int bit_count, blink_char;
+
 __attribute__((isr))
 void main_isr() {
+       // Initialization, since we don't blank out BSS
+       bit_count = 0;
+
        // Power on the PLL, set to 16MHz XTAL
        SYSCTL_RCC_R &= ~(SYSCTL_RCC_PWRDN | SYSCTL_RCC_XTAL_M);
        SYSCTL_RCC_R |= SYSCTL_RCC_XTAL_16MHZ;
@@ -64,6 +69,12 @@ void main_isr() {
        NVIC_ST_CURRENT_R = 0;
        NVIC_ST_CTRL_R |= 0x7;
 
+       // Enable GPIO output for PF[3:1]
+       SYSCTL_RCGCGPIO_R |= 0x20;
+       GPIO_PORTF_DIR_R = 0xE;
+       GPIO_PORTF_DR2R_R = 0xE;
+       GPIO_PORTF_DEN_R = 0xE;
+
        // infinite loop
        for (;;) { 
                asm("wfi");
@@ -82,8 +93,12 @@ __attribute__((isr))
 void uart0_isr() {
        // Receive data, increment by 1 and send it back through the UART
        int data = UART0_DR_R & 0xFF;
+       blink_char = data;
+
        data = (data + 1) & 0xFF;
        UART0_DR_R = data;
+
+       bit_count = 8;
 }
 
 __attribute__((isr))
@@ -98,4 +113,21 @@ void systick_isr() {
 
        // Send a character out the UART for simple testing
        UART0_DR_R = 'F';
+
+       // If we're displaying bits via the LED, bit_count keeps track of how many
+       // bits are remaining to display
+       if (bit_count) {
+               if (blink_char & 0x80) {
+                       // display blue for a '1' bit
+                       *(GPIO_PORTF_DATA_BITS_R + 0xE) = 0x4;
+               } else {
+                       // display red for a '0' bit
+                       *(GPIO_PORTF_DATA_BITS_R + 0xE) = 0x2;
+               }
+               bit_count--;
+               blink_char <<= 1;
+       } else {
+               // or if we're done, blank the LED
+               *(GPIO_PORTF_DATA_BITS_R + 0xE) = 0;
+       }
 }