lpc176x: Move irq handler code above irq setup
Only code movement. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
44f862388f
commit
6409eda058
|
@ -36,6 +36,22 @@ static struct {
|
|||
|
||||
enum { ADC_DONE=0x0100 };
|
||||
|
||||
// ADC hardware irq handler
|
||||
void __visible
|
||||
ADC_IRQHandler(void)
|
||||
{
|
||||
uint32_t pos = adc_status.pos, chan = adc_status.chan & 0xff;
|
||||
uint32_t result = (&LPC_ADC->ADDR0)[chan];
|
||||
if (pos >= ARRAY_SIZE(adc_status.samples))
|
||||
// All samples complete
|
||||
return;
|
||||
if (pos >= ARRAY_SIZE(adc_status.samples) - 2)
|
||||
// Turn off burst mode
|
||||
LPC_ADC->ADCR = adc_status.adcr | (1 << chan);
|
||||
adc_status.samples[pos++] = (result >> 4) & 0x0fff;
|
||||
adc_status.pos = pos;
|
||||
}
|
||||
|
||||
struct gpio_adc
|
||||
gpio_adc_setup(uint8_t pin)
|
||||
{
|
||||
|
@ -64,22 +80,6 @@ gpio_adc_setup(uint8_t pin)
|
|||
return (struct gpio_adc){ .chan = chan };
|
||||
}
|
||||
|
||||
// ADC hardware irq handler
|
||||
void __visible
|
||||
ADC_IRQHandler(void)
|
||||
{
|
||||
uint32_t pos = adc_status.pos, chan = adc_status.chan & 0xff;
|
||||
uint32_t result = (&LPC_ADC->ADDR0)[chan];
|
||||
if (pos >= ARRAY_SIZE(adc_status.samples))
|
||||
// All samples complete
|
||||
return;
|
||||
if (pos >= ARRAY_SIZE(adc_status.samples) - 2)
|
||||
// Turn off burst mode
|
||||
LPC_ADC->ADCR = adc_status.adcr | (1 << chan);
|
||||
adc_status.samples[pos++] = (result >> 4) & 0x0fff;
|
||||
adc_status.pos = pos;
|
||||
}
|
||||
|
||||
// Try to sample a value. Returns zero if sample ready, otherwise
|
||||
// returns the number of clock ticks the caller should wait before
|
||||
// retrying this function.
|
||||
|
|
|
@ -12,35 +12,6 @@
|
|||
#include "internal.h" // gpio_peripheral
|
||||
#include "sched.h" // DECL_INIT
|
||||
|
||||
DECL_CONSTANT_STR("RESERVE_PINS_serial", "P0.3,P0.2");
|
||||
|
||||
void
|
||||
serial_init(void)
|
||||
{
|
||||
// Setup baud
|
||||
LPC_UART0->LCR = (1<<7); // set DLAB bit
|
||||
enable_pclock(PCLK_UART0);
|
||||
uint32_t pclk = SystemCoreClock;
|
||||
uint32_t div = pclk / (CONFIG_SERIAL_BAUD * 16);
|
||||
LPC_UART0->DLL = div & 0xff;
|
||||
LPC_UART0->DLM = (div >> 8) & 0xff;
|
||||
LPC_UART0->FDR = 0x10;
|
||||
LPC_UART0->LCR = 3; // 8N1 ; clear DLAB bit
|
||||
|
||||
// Enable fifo
|
||||
LPC_UART0->FCR = 0x01;
|
||||
|
||||
// Setup pins
|
||||
gpio_peripheral(GPIO(0, 3), 1, 0);
|
||||
gpio_peripheral(GPIO(0, 2), 1, 0);
|
||||
|
||||
// Enable receive irq
|
||||
NVIC_SetPriority(UART0_IRQn, 0);
|
||||
NVIC_EnableIRQ(UART0_IRQn);
|
||||
LPC_UART0->IER = 0x01;
|
||||
}
|
||||
DECL_INIT(serial_init);
|
||||
|
||||
// Write tx bytes to the serial port
|
||||
static void
|
||||
kick_tx(void)
|
||||
|
@ -81,3 +52,32 @@ serial_enable_tx_irq(void)
|
|||
irq_restore(flag);
|
||||
}
|
||||
}
|
||||
|
||||
DECL_CONSTANT_STR("RESERVE_PINS_serial", "P0.3,P0.2");
|
||||
|
||||
void
|
||||
serial_init(void)
|
||||
{
|
||||
// Setup baud
|
||||
LPC_UART0->LCR = (1<<7); // set DLAB bit
|
||||
enable_pclock(PCLK_UART0);
|
||||
uint32_t pclk = SystemCoreClock;
|
||||
uint32_t div = pclk / (CONFIG_SERIAL_BAUD * 16);
|
||||
LPC_UART0->DLL = div & 0xff;
|
||||
LPC_UART0->DLM = (div >> 8) & 0xff;
|
||||
LPC_UART0->FDR = 0x10;
|
||||
LPC_UART0->LCR = 3; // 8N1 ; clear DLAB bit
|
||||
|
||||
// Enable fifo
|
||||
LPC_UART0->FCR = 0x01;
|
||||
|
||||
// Setup pins
|
||||
gpio_peripheral(GPIO(0, 3), 1, 0);
|
||||
gpio_peripheral(GPIO(0, 2), 1, 0);
|
||||
|
||||
// Enable receive irq
|
||||
NVIC_SetPriority(UART0_IRQn, 0);
|
||||
NVIC_EnableIRQ(UART0_IRQn);
|
||||
LPC_UART0->IER = 0x01;
|
||||
}
|
||||
DECL_INIT(serial_init);
|
||||
|
|
|
@ -260,6 +260,41 @@ usb_request_bootloader(void)
|
|||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************
|
||||
* Setup and interrupts
|
||||
****************************************************************/
|
||||
|
||||
void __visible
|
||||
USB_IRQHandler(void)
|
||||
{
|
||||
uint32_t udis = LPC_USB->USBDevIntSt;
|
||||
if (udis & DEV_STAT) {
|
||||
LPC_USB->USBDevIntClr = DEV_STAT;
|
||||
// XXX - should handle reset and other states
|
||||
}
|
||||
if (udis & EP_SLOW) {
|
||||
uint32_t ueis = LPC_USB->USBEpIntSt;
|
||||
if (ueis & (1<<EP0OUT)) {
|
||||
sie_select_and_clear(EP0OUT);
|
||||
usb_notify_ep0();
|
||||
}
|
||||
if (ueis & (1<<EP0IN)) {
|
||||
sie_select_and_clear(EP0IN);
|
||||
usb_notify_ep0();
|
||||
}
|
||||
if (ueis & (1<<EP2OUT)) {
|
||||
sie_select_and_clear(EP2OUT);
|
||||
usb_notify_bulk_out();
|
||||
}
|
||||
if (ueis & (1<<EP5IN)) {
|
||||
sie_select_and_clear(EP5IN);
|
||||
usb_notify_bulk_in();
|
||||
}
|
||||
LPC_USB->USBDevIntClr = EP_SLOW;
|
||||
}
|
||||
}
|
||||
|
||||
DECL_CONSTANT_STR("RESERVE_PINS_USB", "P0.30,P0.29,P2.9");
|
||||
|
||||
void
|
||||
|
@ -295,33 +330,3 @@ usbserial_shutdown(void)
|
|||
usb_irq_enable();
|
||||
}
|
||||
DECL_SHUTDOWN(usbserial_shutdown);
|
||||
|
||||
void __visible
|
||||
USB_IRQHandler(void)
|
||||
{
|
||||
uint32_t udis = LPC_USB->USBDevIntSt;
|
||||
if (udis & DEV_STAT) {
|
||||
LPC_USB->USBDevIntClr = DEV_STAT;
|
||||
// XXX - should handle reset and other states
|
||||
}
|
||||
if (udis & EP_SLOW) {
|
||||
uint32_t ueis = LPC_USB->USBEpIntSt;
|
||||
if (ueis & (1<<EP0OUT)) {
|
||||
sie_select_and_clear(EP0OUT);
|
||||
usb_notify_ep0();
|
||||
}
|
||||
if (ueis & (1<<EP0IN)) {
|
||||
sie_select_and_clear(EP0IN);
|
||||
usb_notify_ep0();
|
||||
}
|
||||
if (ueis & (1<<EP2OUT)) {
|
||||
sie_select_and_clear(EP2OUT);
|
||||
usb_notify_bulk_out();
|
||||
}
|
||||
if (ueis & (1<<EP5IN)) {
|
||||
sie_select_and_clear(EP5IN);
|
||||
usb_notify_bulk_in();
|
||||
}
|
||||
LPC_USB->USBDevIntClr = EP_SLOW;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue