File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ package machine
4
4
5
5
import (
6
6
"device/sifive"
7
+ "runtime/interrupt"
7
8
)
8
9
9
10
func CPUFrequency () uint32 {
@@ -65,6 +66,23 @@ func (uart UART) Configure(config UARTConfig) {
65
66
// 115200 baud rate is 138.
66
67
sifive .UART0 .DIV .Set (138 )
67
68
sifive .UART0 .TXCTRL .Set (sifive .UART_TXCTRL_ENABLE )
69
+ sifive .UART0 .RXCTRL .Set (sifive .UART_RXCTRL_ENABLE )
70
+ sifive .UART0 .IE .Set (sifive .UART_IE_RXWM ) // enable the receive interrupt (only)
71
+ intr := interrupt .New (sifive .IRQ_UART0 , UART0 .handleInterrupt )
72
+ intr .SetPriority (5 )
73
+ intr .Enable ()
74
+ }
75
+
76
+ func (uart * UART ) handleInterrupt (interrupt.Interrupt ) {
77
+ rxdata := uart .Bus .RXDATA .Get ()
78
+ c := byte (rxdata )
79
+ if uint32 (c ) != rxdata {
80
+ // The rxdata has other bits set than just the low 8 bits. This probably
81
+ // means that the 'empty' flag is set, which indicates there is no data
82
+ // to be read and the byte is garbage. Ignore this byte.
83
+ return
84
+ }
85
+ uart .Receive (c )
68
86
}
69
87
70
88
func (uart UART ) WriteByte (c byte ) {
You can’t perform that action at this time.
0 commit comments