]> rtime.felk.cvut.cz Git - fpga/virtex2/uart.git/blob - software/main.c
Software modification to work whit HW UART
[fpga/virtex2/uart.git] / software / main.c
1 /**
2 This is a sample application for openMSP430 softcore MCU with external HW UART
3 peripheral <git@rtime.felk.cvut.cz:fpga/uart> and quadcount peripheral.
4
5 First of all "Hello world" is printed and then application works like echo and
6 also prints quadrature count whenever its value is changed (only whole turns
7 are reported).
8
9 Baudrate is set to 115200.
10 */
11
12 #include "hardware.h"
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include "uart.h"
16
17
18 /**
19 QuadCounter value
20 */
21 inline uint32_t qcount() {
22   uint32_t result = 0;
23
24   result |= QCNTL;
25   result |= ((uint32_t)QCNTH << 16);
26
27   return result;
28 }
29
30 /**
31 Handling of QuadCounter IRQ
32 */
33 interrupt(QCNT_VECTOR) qcount_isr() {
34   printf("[QCount = 0x%08lX]\n", qcount() >> 2);
35 }
36
37
38 /**
39 Print bits of byte in format b'xxxxxxxx'
40 */
41 void print_byte_flags(char flags) {
42   int i;
43
44   putchar('b');
45   putchar('\'');
46
47   for (i = 8;  i != 0;  i--) {
48     if ((flags & 0x80) != 0) {
49       putchar('1');
50     } else {
51       putchar('0');
52     }
53
54     flags = flags << 1;
55   }
56
57   putchar('\'');
58   putchar('\n');
59 }
60
61
62 /**
63 Delay function.
64 */
65 void delay(unsigned long int a, unsigned long int b) {
66   unsigned long int i;
67
68   while (a--) {
69     i = b;
70     while (i--) {
71       nop();
72       nop();
73     }
74   }
75 }
76
77
78 /**
79 Main function with init and an endless loop.
80 */
81 int main(void) {
82
83     //UBAUD = 0x04E1;                     //24.00MHz - 9600 baud
84     UBAUD = 0x0067;                     //24.00MHz - 115200 baud
85
86     eint();                             //enable interrupts
87
88
89     puts("Hello world\n");
90
91     for (;;) {  
92       putchar(getchar());
93     }
94
95 }
96