machine/fe310: implement UART receive interrupts

This makes the echo example work on the HiFive1 rev B board.
Этот коммит содержится в:
Ayke van Laethem 2020-01-10 16:58:35 +01:00 коммит произвёл Ron Evans
родитель 415c60551e
коммит 94fec09b31

Просмотреть файл

@ -4,6 +4,7 @@ package machine
import ( import (
"device/sifive" "device/sifive"
"runtime/interrupt"
) )
func CPUFrequency() uint32 { func CPUFrequency() uint32 {
@ -65,6 +66,23 @@ func (uart UART) Configure(config UARTConfig) {
// 115200 baud rate is 138. // 115200 baud rate is 138.
sifive.UART0.DIV.Set(138) sifive.UART0.DIV.Set(138)
sifive.UART0.TXCTRL.Set(sifive.UART_TXCTRL_ENABLE) sifive.UART0.TXCTRL.Set(sifive.UART_TXCTRL_ENABLE)
sifive.UART0.RXCTRL.Set(sifive.UART_RXCTRL_ENABLE)
sifive.UART0.IE.Set(sifive.UART_IE_RXWM) // enable the receive interrupt (only)
intr := interrupt.New(sifive.IRQ_UART0, UART0.handleInterrupt)
intr.SetPriority(5)
intr.Enable()
}
func (uart *UART) handleInterrupt(interrupt.Interrupt) {
rxdata := uart.Bus.RXDATA.Get()
c := byte(rxdata)
if uint32(c) != rxdata {
// The rxdata has other bits set than just the low 8 bits. This probably
// means that the 'empty' flag is set, which indicates there is no data
// to be read and the byte is garbage. Ignore this byte.
return
}
uart.Receive(c)
} }
func (uart UART) WriteByte(c byte) { func (uart UART) WriteByte(c byte) {