machine: switch to modern interrupt registration method

This saves about 112 bytes in flash and 288 bytes in RAM when the UART
is not used.
Этот коммит содержится в:
Ayke van Laethem 2020-04-04 16:31:20 +02:00 коммит произвёл Ron Evans
родитель dd0fb1dd9a
коммит 012c4a02c9

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

@ -639,7 +639,7 @@ type UART struct {
Buffer *RingBuffer Buffer *RingBuffer
Bus *sam.SERCOM_USART_INT_Type Bus *sam.SERCOM_USART_INT_Type
SERCOM uint8 SERCOM uint8
IRQVal uint32 // RXC interrupt Interrupt interrupt.Interrupt // RXC interrupt
} }
var ( var (
@ -651,7 +651,6 @@ var (
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: sam.SERCOM3_USART_INT, Bus: sam.SERCOM3_USART_INT,
SERCOM: 3, SERCOM: 3,
IRQVal: sam.IRQ_SERCOM3_2, // RXC interrupt
} }
// The second hardware serial port on the SAMD51. Uses the SERCOM0 interface. // The second hardware serial port on the SAMD51. Uses the SERCOM0 interface.
@ -659,10 +658,15 @@ var (
Buffer: NewRingBuffer(), Buffer: NewRingBuffer(),
Bus: sam.SERCOM0_USART_INT, Bus: sam.SERCOM0_USART_INT,
SERCOM: 0, SERCOM: 0,
IRQVal: sam.IRQ_SERCOM0_2, // RXC interrupt
} }
) )
func init() {
// Register RXC interrupts.
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, UART1.handleInterrupt)
UART2.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, UART2.handleInterrupt)
}
const ( const (
sampleRate16X = 16 sampleRate16X = 16
lsbFirst = 1 lsbFirst = 1
@ -766,7 +770,7 @@ func (uart UART) Configure(config UARTConfig) error {
// > position in the INTFLAG register of respective peripheral. // > position in the INTFLAG register of respective peripheral.
// Therefore, if we only need to listen to the RXC interrupt source (in bit // Therefore, if we only need to listen to the RXC interrupt source (in bit
// position 2), we only need interrupt source 2 for this SERCOM device. // position 2), we only need interrupt source 2 for this SERCOM device.
arm.EnableIRQ(uart.IRQVal) uart.Interrupt.Enable()
return nil return nil
} }
@ -794,18 +798,10 @@ func (uart UART) WriteByte(c byte) error {
return nil return nil
} }
//go:export SERCOM3_2_IRQHandler func (uart *UART) handleInterrupt(interrupt.Interrupt) {
func handleSERCOM3_2() {
// should reset IRQ // should reset IRQ
UART1.Receive(byte((UART1.Bus.DATA.Get() & 0xFF))) uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
UART1.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC) uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
}
//go:export SERCOM0_2_IRQHandler
func handleSERCOM0_2() {
// should reset IRQ
UART2.Receive(byte((UART2.Bus.DATA.Get() & 0xFF)))
UART2.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
} }
// I2C on the SAMD51. // I2C on the SAMD51.