File tree 1 file changed +22
-4
lines changed 1 file changed +22
-4
lines changed Original file line number Diff line number Diff line change 1
1
#include <generated/csr.h>
2
2
#include <time.h>
3
3
4
+ #define UART_EV_TX 0x1
5
+ #define UART_EV_RX 0x2
6
+
4
7
void isr (void ) {
5
8
asm("nop" );
6
9
}
7
10
8
11
9
12
int main (void ) {
10
13
uint32_t x = 0 ;
14
+ uint32_t buf = 0 ;
11
15
while (1 ) {
12
- uart_rxtx_write ('a' );
13
- leds_out_write (x );
14
- if (x == 0x02 ) {
16
+
17
+ // Wait for an incoming byte
18
+ while (uart_rxempty_read ()) {
19
+ // Prevent the while loop from being optimized out
20
+ asm("nop" );
21
+ }
22
+
23
+ // Read an incoming byte
24
+ buf = uart_rxtx_read ();
25
+ // Tell the UART that we read a byte out of the FIFO
26
+ // and that it can give us another.
27
+ uart_ev_pending_write (UART_EV_RX );
28
+ // Mirror the bytes back
29
+ uart_rxtx_write (buf );
30
+
31
+ // Write new LED output and toggle
32
+ leds_out_write (x | (buf << 2 ));
33
+ if (x == 2 ) {
15
34
x = 0x00000001 ;
16
35
} else {
17
36
x = 0x00000002 ;
18
37
}
19
- msleep (80 );
20
38
}
21
39
}
You can’t perform that action at this time.
0 commit comments