machine: make UART objects pointer receivers

This means that machine.UART0, machine.UART1, etc are of type
*machine.UART, not machine.UART. This makes them easier to pass around
and avoids surprises when they are passed around by value while they
should be passed around by reference.

There is a small code size impact in some cases, but it is relatively
minor.
This commit is contained in:
Ayke van Laethem
2021-05-13 12:32:12 +02:00
committed by Ron Evans
parent 7c949ad386
commit aa5b8d0df7
46 changed files with 246 additions and 179 deletions
+5 -4
View File
@@ -56,17 +56,18 @@ type UART struct {
}
var (
UART0 = UART{Bus: sifive.UART0, Buffer: NewRingBuffer()}
UART0 = &_UART0
_UART0 = UART{Bus: sifive.UART0, Buffer: NewRingBuffer()}
)
func (uart UART) Configure(config UARTConfig) {
func (uart *UART) Configure(config UARTConfig) {
// Assuming a 16Mhz Crystal (which is Y1 on the HiFive1), the divisor for a
// 115200 baud rate is 138.
sifive.UART0.DIV.Set(138)
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 := interrupt.New(sifive.IRQ_UART0, _UART0.handleInterrupt)
intr.SetPriority(5)
intr.Enable()
}
@@ -83,7 +84,7 @@ func (uart *UART) handleInterrupt(interrupt.Interrupt) {
uart.Receive(c)
}
func (uart UART) WriteByte(c byte) {
func (uart *UART) WriteByte(c byte) {
for sifive.UART0.TXDATA.Get()&sifive.UART_TXDATA_FULL != 0 {
}