atsam: Move irq handler code above irq setup

Only code movement.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-08-22 09:12:24 -04:00
parent 6338f6a5f0
commit fc879456db
3 changed files with 65 additions and 65 deletions

View File

@ -179,29 +179,6 @@ handle_end_reset(void)
UOTGHS->UOTGHS_DEVICR = UOTGHS_DEVICR_EORSTC;
}
void
usbserial_init(void)
{
// Setup USB clock
enable_pclock(ID_UOTGHS);
PMC->CKGR_UCKR = CKGR_UCKR_UPLLCOUNT(3) | CKGR_UCKR_UPLLEN;
while (!(PMC->PMC_SR & PMC_SR_LOCKU))
;
PMC->PMC_USB = PMC_USB_USBS | PMC_USB_USBDIV(0);
PMC->PMC_SCER = PMC_SCER_UOTGCLK;
// Enable USB
UOTGHS->UOTGHS_CTRL = (UOTGHS_CTRL_UIMOD | UOTGHS_CTRL_OTGPADE
| UOTGHS_CTRL_USBE);
UOTGHS->UOTGHS_DEVCTRL = UOTGHS_DEVCTRL_SPDCONF_FORCED_FS;
// Enable interrupts
NVIC_SetPriority(UOTGHS_IRQn, 1);
NVIC_EnableIRQ(UOTGHS_IRQn);
UOTGHS->UOTGHS_DEVIER = UOTGHS_DEVIER_EORSTES;
}
DECL_INIT(usbserial_init);
void __visible
UOTGHS_Handler(void)
{
@ -227,3 +204,26 @@ UOTGHS_Handler(void)
if (s & (UOTGHS_DEVISR_PEP_0 << USB_CDC_EP_BULK_IN))
usb_notify_bulk_in();
}
void
usbserial_init(void)
{
// Setup USB clock
enable_pclock(ID_UOTGHS);
PMC->CKGR_UCKR = CKGR_UCKR_UPLLCOUNT(3) | CKGR_UCKR_UPLLEN;
while (!(PMC->PMC_SR & PMC_SR_LOCKU))
;
PMC->PMC_USB = PMC_USB_USBS | PMC_USB_USBDIV(0);
PMC->PMC_SCER = PMC_SCER_UOTGCLK;
// Enable USB
UOTGHS->UOTGHS_CTRL = (UOTGHS_CTRL_UIMOD | UOTGHS_CTRL_OTGPADE
| UOTGHS_CTRL_USBE);
UOTGHS->UOTGHS_DEVCTRL = UOTGHS_DEVCTRL_SPDCONF_FORCED_FS;
// Enable interrupts
NVIC_SetPriority(UOTGHS_IRQn, 1);
NVIC_EnableIRQ(UOTGHS_IRQn);
UOTGHS->UOTGHS_DEVIER = UOTGHS_DEVIER_EORSTES;
}
DECL_INIT(usbserial_init);

View File

@ -160,26 +160,6 @@ usb_set_configure(void)
UDP->UDP_GLB_STAT |= UDP_GLB_STAT_CONFG;
}
DECL_CONSTANT_STR("RESERVE_PINS_USB", "PB10,PB11");
void
usbserial_init(void)
{
// Enable clocks
enable_pclock(ID_UDP);
PMC->PMC_USB = PMC_USB_USBDIV(5 - 1); // PLLA=240Mhz; divide by 5 for 48Mhz
PMC->PMC_SCER = PMC_SCER_UDP;
// Enable USB pullup
UDP->UDP_TXVC = UDP_TXVC_PUON | UDP_TXVC_TXVDIS;
// Enable interrupts
UDP->UDP_ICR = 0xffffffff;
NVIC_SetPriority(UDP_IRQn, 1);
NVIC_EnableIRQ(UDP_IRQn);
}
DECL_INIT(usbserial_init);
// Configure endpoint 0 after usb reset completes
static void
handle_end_reset(void)
@ -216,3 +196,23 @@ UDP_Handler(void)
if (s & (1<<USB_CDC_EP_BULK_IN))
usb_notify_bulk_in();
}
DECL_CONSTANT_STR("RESERVE_PINS_USB", "PB10,PB11");
void
usbserial_init(void)
{
// Enable clocks
enable_pclock(ID_UDP);
PMC->PMC_USB = PMC_USB_USBDIV(5 - 1); // PLLA=240Mhz; divide by 5 for 48Mhz
PMC->PMC_SCER = PMC_SCER_UDP;
// Enable USB pullup
UDP->UDP_TXVC = UDP_TXVC_PUON | UDP_TXVC_TXVDIS;
// Enable interrupts
UDP->UDP_ICR = 0xffffffff;
NVIC_SetPriority(UDP_IRQn, 1);
NVIC_EnableIRQ(UDP_IRQn);
}
DECL_INIT(usbserial_init);

View File

@ -34,6 +34,28 @@ static const uint32_t tx_pin = GPIO('A', 10);
DECL_CONSTANT_STR("RESERVE_PINS_serial", "PA9,PA10");
#endif
void __visible
Serial_IRQ_Handler(void)
{
uint32_t status = Port->UART_SR;
if (status & UART_SR_RXRDY)
serial_rx_byte(Port->UART_RHR);
if (status & UART_SR_TXRDY) {
uint8_t data;
int ret = serial_get_tx_byte(&data);
if (ret)
Port->UART_IDR = UART_IDR_TXRDY;
else
Port->UART_THR = data;
}
}
void
serial_enable_tx_irq(void)
{
Port->UART_IER = UART_IDR_TXRDY;
}
void
serial_init(void)
{
@ -57,25 +79,3 @@ serial_init(void)
Port->UART_CR = UART_CR_RXEN | UART_CR_TXEN;
}
DECL_INIT(serial_init);
void __visible
Serial_IRQ_Handler(void)
{
uint32_t status = Port->UART_SR;
if (status & UART_SR_RXRDY)
serial_rx_byte(Port->UART_RHR);
if (status & UART_SR_TXRDY) {
uint8_t data;
int ret = serial_get_tx_byte(&data);
if (ret)
Port->UART_IDR = UART_IDR_TXRDY;
else
Port->UART_THR = data;
}
}
void
serial_enable_tx_irq(void)
{
Port->UART_IER = UART_IDR_TXRDY;
}