]> rtime.felk.cvut.cz Git - fpga/virtex2/uart.git/blobdiff - software/main.c
Omsp_quadcount periphery changed.
[fpga/virtex2/uart.git] / software / main.c
index 1f2c2efef5cddbb93f570766afd8b1124f4b7954..44235055e74a8799ed2a92b3cdc8c3ba8782534c 100644 (file)
@@ -3,8 +3,10 @@ This is a sample application for openMSP430 softcore MCU with external HW UART
 peripheral <git@rtime.felk.cvut.cz:fpga/uart> and quadcount peripheral.
 
 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).
+also prints quadrature count whenever its value is changed.
+
+AB error of quadrature counter peripheral is handled by irq routine which prints
+message "IRQ: QCounter AB error!".
 
 Baudrate is set to 115200.
 */
@@ -31,7 +33,8 @@ inline uint32_t qcount() {
 Handling of QuadCounter IRQ
 */
 interrupt(QCNT_VECTOR) qcount_isr() {
-  printf("[QCount = 0x%08lX]\n", qcount() >> 2);
+  puts("IRQ: QCounter AB error!");
+  qcount();
 }
 
 
@@ -79,6 +82,8 @@ void delay(unsigned long int a, unsigned long int b) {
 Main function with init and an endless loop.
 */
 int main(void) {
+    uint32_t qcnt = qcount();
+    uint32_t qcnt_new;
 
     //UBAUD = 0x04E1;                     //24.00MHz - 9600 baud
     UBAUD = 0x0067;                     //24.00MHz - 115200 baud
@@ -88,8 +93,16 @@ int main(void) {
 
     puts("Hello world\n");
 
-    for (;;) {  
-      putchar(getchar());
+    for (;;) {
+      while (!isRxEmpty()) {
+        putchar(URX);
+      }
+
+      qcnt_new = qcount();
+      if (qcnt != qcnt_new) {
+        printf("[QCount = 0x%08lX]\n", qcnt_new);
+        qcnt = qcnt_new;
+      }
     }
 
 }