]> rtime.felk.cvut.cz Git - fpga/virtex2/uart.git/blobdiff - software/main.c
Software modification to work whit HW UART
[fpga/virtex2/uart.git] / software / main.c
index bf98951974bc10d20af9a79ed132be1a8d24b067..1f2c2efef5cddbb93f570766afd8b1124f4b7954 100644 (file)
@@ -1,25 +1,29 @@
-/*
-see README.txt for details.
+/**
+This is a sample application for openMSP430 softcore MCU with external HW UART
+peripheral <git@rtime.felk.cvut.cz:fpga/uart> and quadcount peripheral.
 
-original by: chris <cliechti@gmx.net>
+First of all "Hello world" is printed and then application works like echo and
+also prints quadrature count whenever its value is changed (only whole turns
+are reported).
 
-modified by: Vladimir Burian <buriavl2@fel.cvut.cz>
+Baudrate is set to 115200.
 */
+
 #include "hardware.h"
 #include <stdlib.h>
 #include <stdio.h>
-#include "swuart.h"
-#include "fll.h"
+#include "uart.h"
+
 
 /**
 QuadCounter value
 */
 inline uint32_t qcount() {
   uint32_t result = 0;
-  
+
   result |= QCNTL;
   result |= ((uint32_t)QCNTH << 16);
-  
+
   return result;
 }
 
@@ -31,100 +35,62 @@ interrupt(QCNT_VECTOR) qcount_isr() {
 }
 
 
+/**
+Print bits of byte in format b'xxxxxxxx'
+*/
+void print_byte_flags(char flags) {
+  int i;
+
+  putchar('b');
+  putchar('\'');
+
+  for (i = 8;  i != 0;  i--) {
+    if ((flags & 0x80) != 0) {
+      putchar('1');
+    } else {
+      putchar('0');
+    }
+
+    flags = flags << 1;
+  }
+
+  putchar('\'');
+  putchar('\n');
+}
+
+
 /**
 Delay function.
 */
-void delay(unsigned int d) {
-   while(d--) {
+void delay(unsigned long int a, unsigned long int b) {
+  unsigned long int i;
+
+  while (a--) {
+    i = b;
+    while (i--) {
       nop();
       nop();
-   }
+    }
+  }
 }
 
+
 /**
-Main function with init an an endless loop that is synced with the
-interrupts trough the lowpower mode.
+Main function with init and an endless loop.
 */
 int main(void) {
-    int reading = 0;
-    int pos = 0;
-    char buf[40];
-    int led = 0;
-    
-    WDTCTL = WDTCTL_INIT;               //Init watchdog timer
-
-    P1OUT  = P1OUT_INIT;                //Init output data of port1
-    P1SEL  = P1SEL_INIT;                //Select port or module -function on port1
-    P1DIR  = P1DIR_INIT;                //Init port direction register of port1
-    P1IES  = P1IES_INIT;                //init port interrupts
-    P1IE   = P1IE_INIT;
-
-    P2OUT  = P2OUT_INIT;                //Init output data of port2
-    P2SEL  = P2SEL_INIT;                //Select port or module -function on port2
-    P2DIR  = P2DIR_INIT;                //Init port direction register of port2
-    P2IES  = P2IES_INIT;                //init port interrupts
-    P2IE   = P2IE_INIT;
-
-    P3DIR  = 0xff;
-    P3OUT  = 0xff;                      //light LED during init
-    delay(65535);                       //Wait for watch crystal startup
-    delay(65535);
-//  fllInit();                          //Init FLL to desired frequency using the 32k768 cystal as reference.
-    P3OUT  = 0x00;                      //switch off LED
-    
-    TACTL  = TACTL_AFTER_FLL;           //setup timer (still stopped)
-    CCTL0  = CCIE|CAP|CM_2|CCIS_1|SCS;  //select P2.2 with UART signal
-    CCTL1  = 0;                         //
-    CCTL2  = 0;                         //
-    TACTL |= MC1;                       //start timer
-    
+
+    //UBAUD = 0x04E1;                     //24.00MHz - 9600 baud
+    UBAUD = 0x0067;                     //24.00MHz - 115200 baud
+
     eint();                             //enable interrupts
-    
-    printf("\r\n====== openMSP430 in action ======\r\n");   //say hello
-    printf("\r\nSimple Line Editor Ready\r\n");   //say hello
-    
-    printf("\n[QCount = 0x%08lX]\n", qcount());
-    
-    while (1) {                         //main loop, never ends...
-        printf("> ");                   //show prompt
-        reading = 1;
-        while (reading) {               //loop and read characters
-            LPM0;                       //sync, wakeup by irq
-
-           led++;                      // Some lighting...
-           if (led==9) {
-             led = 0;
-           }
-           P3OUT = (0x01 << led);
-
-            switch (rxdata) {
-                //process RETURN key
-                case '\r':
-                //case '\n':
-                    printf("\r\n");     //finish line
-                    buf[pos++] = 0;     //to use printf...
-                    printf(":%s\r\n", buf);
-                    reading = 0;        //exit read loop
-                    pos = 0;            //reset buffer
-                    break;
-                //backspace
-                case '\b':
-                    if (pos > 0) {      //is there a char to delete?
-                        pos--;          //remove it in buffer
-                        putchar('\b');  //go back
-                        putchar(' ');   //erase on screen
-                        putchar('\b');  //go back
-                    }
-                    break;
-                //other characters
-                default:
-                    //only store characters if buffer has space
-                    if (pos < sizeof(buf)) {
-                        putchar(rxdata);     //echo
-                        buf[pos++] = rxdata; //store
-                    }
-            }
-        }
+
+
+    puts("Hello world\n");
+
+    for (;;) {  
+      putchar(getchar());
     }
+
 }