From 58db263cc835be0abb972654c2d7369718c88b37 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 6 Nov 2014 16:04:14 -0800 Subject: altos/lpc: Declare SPI send parameters as const This matches STM Signed-off-by: Keith Packard --- src/lpc/ao_arch_funcs.h | 4 ++-- src/lpc/ao_spi_lpc.c | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_arch_funcs.h b/src/lpc/ao_arch_funcs.h index 21a7a8e5..ff8a184d 100644 --- a/src/lpc/ao_arch_funcs.h +++ b/src/lpc/ao_arch_funcs.h @@ -201,7 +201,7 @@ void ao_spi_put(uint8_t spi_index); void -ao_spi_send(void *block, uint16_t len, uint8_t spi_index); +ao_spi_send(const void *block, uint16_t len, uint8_t spi_index); void ao_spi_send_fixed(uint8_t value, uint16_t len, uint8_t spi_index); @@ -210,7 +210,7 @@ void ao_spi_recv(void *block, uint16_t len, uint8_t spi_index); void -ao_spi_duplex(void *out, void *in, uint16_t len, uint8_t spi_index); +ao_spi_duplex(const void *out, void *in, uint16_t len, uint8_t spi_index); extern uint16_t ao_spi_speed[LPC_NUM_SPI]; diff --git a/src/lpc/ao_spi_lpc.c b/src/lpc/ao_spi_lpc.c index e72b8286..bc8f9c69 100644 --- a/src/lpc/ao_spi_lpc.c +++ b/src/lpc/ao_spi_lpc.c @@ -43,9 +43,9 @@ static struct lpc_ssp * const ao_lpc_ssp[LPC_NUM_SPI] = { &lpc_ssp0, &lpc_ssp1 } } while (0) void -ao_spi_send(void *block, uint16_t len, uint8_t id) +ao_spi_send(const void *block, uint16_t len, uint8_t id) { - uint8_t *b = block; + const uint8_t *b = block; struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; spi_loop(len, *b++, (void)); @@ -69,9 +69,9 @@ ao_spi_recv(void *block, uint16_t len, uint8_t id) } void -ao_spi_duplex(void *out, void *in, uint16_t len, uint8_t id) +ao_spi_duplex(const void *out, void *in, uint16_t len, uint8_t id) { - uint8_t *o = out; + const uint8_t *o = out; uint8_t *i = in; struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; -- cgit v1.2.3 From 6a082d9b5ed169b9d4153885f3535987e5ae5d84 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 6 Nov 2014 16:04:56 -0800 Subject: altos/lpc: Disable JTAG when using pins for GPIO JTAG is enabled by default, making those pins not support GPIO unless specifically configured. Signed-off-by: Keith Packard --- src/lpc/ao_arch_funcs.h | 12 ++++++++++++ src/lpc/ao_led_lpc.c | 11 ++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_arch_funcs.h b/src/lpc/ao_arch_funcs.h index ff8a184d..69f2cbfb 100644 --- a/src/lpc/ao_arch_funcs.h +++ b/src/lpc/ao_arch_funcs.h @@ -30,8 +30,19 @@ #define ao_gpio_get(port, bit, pin) (lpc_gpio.byte[lpc_all_bit(port,bit)]) +#define PORT0_JTAG_REGS ((1 << 11) | (1 << 12) | (1 << 14)) + +static inline void lpc_set_gpio(int port, int bit) { + if (port == 0 && (1 << bit) & (PORT0_JTAG_REGS)) { + vuint32_t *_ioconf = &lpc_ioconf.pio0_0 + ((port)*24+(bit)); + + *_ioconf = (*_ioconf & ~LPC_IOCONF_FUNC_MASK) | LPC_IOCONF_FUNC_PIO0_11; + } +} + #define ao_enable_output(port,bit,pin,v) do { \ ao_enable_port(port); \ + lpc_set_gpio(port,bit); \ ao_gpio_set(port, bit, pin, v); \ lpc_gpio.dir[port] |= (1 << bit); \ } while (0) @@ -52,6 +63,7 @@ #define ao_enable_input(port,bit,mode) do { \ ao_enable_port(port); \ + lpc_set_gpio(port,bit); \ lpc_gpio.dir[port] &= ~(1 << bit); \ ao_gpio_set_mode(port,bit,mode); \ } while (0) diff --git a/src/lpc/ao_led_lpc.c b/src/lpc/ao_led_lpc.c index d983437c..a0b293b9 100644 --- a/src/lpc/ao_led_lpc.c +++ b/src/lpc/ao_led_lpc.c @@ -59,6 +59,15 @@ void ao_led_init(AO_PORT_TYPE enable) { ao_led_enable = enable; - lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_GPIO); + ao_enable_port(LED_PORT); + if (LED_PORT == 0) { + if (enable & (1 << 11)) + lpc_ioconf.pio0_11 = LPC_IOCONF_FUNC_PIO0_11 | (1 << LPC_IOCONF_ADMODE); + if (enable & (1 << 12)) + lpc_ioconf.pio0_12 = LPC_IOCONF_FUNC_PIO0_12 | (1 << LPC_IOCONF_ADMODE); + if (enable & (1 << 14)) + lpc_ioconf.pio0_14 = LPC_IOCONF_FUNC_PIO0_14 | (1 << LPC_IOCONF_ADMODE); + } lpc_gpio.dir[LED_PORT] |= enable; + ao_led_off(enable); } -- cgit v1.2.3 From 2a053d3d157e00b6a6406f4f78ddb8e298b6c4b7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 22 Dec 2014 17:27:09 -0800 Subject: altos/lpc: Switch LPC SPI driver to interrupt-driven This improves performance for SPI transfers, while allowing other tasks to get work done during longer SPI transfers. Signed-off-by: Keith Packard --- src/lpc/ao_arch.h | 3 + src/lpc/ao_arch_funcs.h | 2 - src/lpc/ao_spi_lpc.c | 143 +++++++++++++++++++++++++++++++++++++----------- 3 files changed, 115 insertions(+), 33 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_arch.h b/src/lpc/ao_arch.h index 5fbb8dfa..42faf06f 100644 --- a/src/lpc/ao_arch.h +++ b/src/lpc/ao_arch.h @@ -130,12 +130,15 @@ ao_serial_init(void); /* SPI definitions */ #define AO_SPI_SPEED_12MHz 4 +#define AO_SPI_SPEED_8MHz 6 #define AO_SPI_SPEED_6MHz 8 #define AO_SPI_SPEED_4MHz 12 #define AO_SPI_SPEED_2MHz 24 #define AO_SPI_SPEED_1MHz 48 #define AO_SPI_SPEED_500kHz 96 #define AO_SPI_SPEED_250kHz 192 +#define AO_SPI_SPEED_125kHz 384 +#define AO_SPI_SPEED_62500Hz 768 #define AO_SPI_SPEED_FAST AO_SPI_SPEED_12MHz diff --git a/src/lpc/ao_arch_funcs.h b/src/lpc/ao_arch_funcs.h index 69f2cbfb..fbe641d8 100644 --- a/src/lpc/ao_arch_funcs.h +++ b/src/lpc/ao_arch_funcs.h @@ -224,8 +224,6 @@ ao_spi_recv(void *block, uint16_t len, uint8_t spi_index); void ao_spi_duplex(const void *out, void *in, uint16_t len, uint8_t spi_index); -extern uint16_t ao_spi_speed[LPC_NUM_SPI]; - void ao_spi_init(void); diff --git a/src/lpc/ao_spi_lpc.c b/src/lpc/ao_spi_lpc.c index bc8f9c69..5a358919 100644 --- a/src/lpc/ao_spi_lpc.c +++ b/src/lpc/ao_spi_lpc.c @@ -19,63 +19,130 @@ static uint8_t ao_spi_mutex[LPC_NUM_SPI]; +struct ao_lpc_ssp_state { + int tx_count; + const uint8_t *tx; + int tx_inc; + int rx_count; + uint8_t *rx; + int rx_inc; +}; + +static struct ao_lpc_ssp_state ao_lpc_ssp_state[LPC_NUM_SPI]; + static struct lpc_ssp * const ao_lpc_ssp[LPC_NUM_SPI] = { &lpc_ssp0, &lpc_ssp1 }; -#define tx_busy(lpc_ssp) (lpc_ssp->sr & ((1 << LPC_SSP_SR_BSY) | (1 << LPC_SSP_SR_TNF))) != (1 << LPC_SSP_SR_TNF) -#define rx_busy(lpc_ssp) (lpc_ssp->sr & ((1 << LPC_SSP_SR_BSY) | (1 << LPC_SSP_SR_RNE))) != (1 << LPC_SSP_SR_RNE) - -#define spi_loop(len, put, get) do { \ - while (len--) { \ - /* Wait for space in the fifo */ \ - while (tx_busy(lpc_ssp)) \ - ; \ - \ - /* send a byte */ \ - lpc_ssp->dr = put; \ - \ - /* Wait for byte to appear in the fifo */ \ - while (rx_busy(lpc_ssp)) \ - ; \ - \ - /* recv a byte */ \ - get lpc_ssp->dr; \ - } \ - } while (0) +static inline void +ao_lpc_ssp_recv(struct lpc_ssp *lpc_ssp, struct ao_lpc_ssp_state *state) +{ + while ((lpc_ssp->sr & (1 << LPC_SSP_SR_RNE)) && + state->rx_count) + { + /* RX ready, read a byte */ + *state->rx = lpc_ssp->dr; + state->rx += state->rx_inc; + state->rx_count--; + } +} + +static void +ao_lpc_ssp_isr(struct lpc_ssp *lpc_ssp, struct ao_lpc_ssp_state *state) +{ + ao_lpc_ssp_recv(lpc_ssp, state); + while ((lpc_ssp->sr & (1 << LPC_SSP_SR_TNF)) && + state->tx_count) + { + /* TX ready, write a byte */ + lpc_ssp->dr = *state->tx; + state->tx += state->tx_inc; + state->tx_count--; + ao_lpc_ssp_recv(lpc_ssp, state); + } + if (!state->rx_count) { + lpc_ssp->imsc &= ~(1 << LPC_SSP_IMSC_TXIM); + ao_wakeup(state); + } +} + +void +lpc_ssp0_isr(void) +{ + ao_lpc_ssp_isr(&lpc_ssp0, &ao_lpc_ssp_state[0]); +} + +void +lpc_ssp1_isr(void) +{ + ao_lpc_ssp_isr(&lpc_ssp1, &ao_lpc_ssp_state[1]); +} + +static void +ao_spi_run(struct lpc_ssp *lpc_ssp, struct ao_lpc_ssp_state *state) +{ + ao_arch_block_interrupts(); + lpc_ssp->imsc = (1 << LPC_SSP_IMSC_TXIM); + while (state->rx_count) + ao_sleep(state); + ao_arch_release_interrupts(); +} + +static uint8_t ao_spi_tx_dummy = 0xff; +static uint8_t ao_spi_rx_dummy; void ao_spi_send(const void *block, uint16_t len, uint8_t id) { - const uint8_t *b = block; struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; + struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - spi_loop(len, *b++, (void)); + state->tx_count = state->rx_count = len; + state->tx = block; + state->tx_inc = 1; + state->rx = &ao_spi_rx_dummy; + state->rx_inc = 0; + ao_spi_run(lpc_ssp, state); } void ao_spi_send_fixed(uint8_t value, uint16_t len, uint8_t id) { struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; + struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - spi_loop(len, value, (void)); + state->tx_count = state->rx_count = len; + state->tx = &value; + state->tx_inc = 0; + state->rx = &ao_spi_rx_dummy; + state->rx_inc = 0; + ao_spi_run(lpc_ssp, state); } void ao_spi_recv(void *block, uint16_t len, uint8_t id) { - uint8_t *b = block; struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; + struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - spi_loop(len, 0xff, *b++ =); + state->tx_count = state->rx_count = len; + state->tx = &ao_spi_tx_dummy; + state->tx_inc = 0; + state->rx = block; + state->rx_inc = 1; + ao_spi_run(lpc_ssp, state); } void ao_spi_duplex(const void *out, void *in, uint16_t len, uint8_t id) { - const uint8_t *o = out; - uint8_t *i = in; struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; + struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - spi_loop(len, *o++, *i++ =); + state->tx_count = state->rx_count = len; + state->tx = out; + state->tx_inc = 1; + state->rx = in; + state->rx_inc = 1; + ao_spi_run(lpc_ssp, state); } void @@ -84,7 +151,7 @@ ao_spi_get(uint8_t id, uint32_t speed) struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; ao_mutex_get(&ao_spi_mutex[id]); - + /* Set the clock prescale */ lpc_ssp->cpsr = speed; } @@ -101,6 +168,11 @@ ao_spi_channel_init(uint8_t id) struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; uint8_t d; + /* Clear interrupt registers */ + lpc_ssp->imsc = 0; + lpc_ssp->ris = 0; + lpc_ssp->mis = 0; + lpc_ssp->cr0 = ((LPC_SSP_CR0_DSS_8 << LPC_SSP_CR0_DSS) | (LPC_SSP_CR0_FRF_SPI << LPC_SSP_CR0_FRF) | (0 << LPC_SSP_CR0_CPOL) | @@ -151,7 +223,11 @@ ao_spi_init(void) lpc_scb.presetctrl &= ~(1 << LPC_SCB_PRESETCTRL_SSP0_RST_N); lpc_scb.presetctrl |= (1 << LPC_SCB_PRESETCTRL_SSP0_RST_N); ao_spi_channel_init(0); -#endif + + /* Configure NVIC */ + lpc_nvic_set_enable(LPC_ISR_SSP0_POS); + lpc_nvic_set_priority(LPC_ISR_SSP0_POS, 0); +#endif #if HAS_SPI_1 @@ -190,7 +266,7 @@ ao_spi_init(void) #ifndef HAS_MOSI1 #error "No pin specified for MOSI1" #endif - + /* Enable the device */ lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_SSP1); @@ -201,5 +277,10 @@ ao_spi_init(void) lpc_scb.presetctrl &= ~(1 << LPC_SCB_PRESETCTRL_SSP1_RST_N); lpc_scb.presetctrl |= (1 << LPC_SCB_PRESETCTRL_SSP1_RST_N); ao_spi_channel_init(1); + + /* Configure NVIC */ + lpc_nvic_set_enable(LPC_ISR_SSP1_POS); + lpc_nvic_set_priority(LPC_ISR_SSP1_POS, 0); + #endif /* HAS_SPI_1 */ } -- cgit v1.2.3 From e05e0c6b71a1df65f188e00622e9632eb27510fd Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 16 Jan 2015 22:09:26 +1300 Subject: Set version to 1.5.9.1 --- configure.ac | 2 +- icon/application-vnd.altusmetrum.micropeak.svg | 1 - src/kernel/ao_config.c | 7 +- src/lpc/ao_arch.h | 2 + src/lpc/ao_arch_funcs.h | 6 + src/lpc/ao_usb_lpc.c | 76 +++++++--- src/usbtrng/ao_pins.h | 2 + src/usbtrng/ao_usbtrng.c | 195 ++++++++++++++++++++++++- 8 files changed, 264 insertions(+), 27 deletions(-) delete mode 120000 icon/application-vnd.altusmetrum.micropeak.svg (limited to 'src/lpc') diff --git a/configure.ac b/configure.ac index a38ef092..2c7b19c5 100644 --- a/configure.ac +++ b/configure.ac @@ -18,7 +18,7 @@ dnl dnl Process this file with autoconf to create configure. AC_PREREQ(2.57) -AC_INIT([altos], 1.5.9.0) +AC_INIT([altos], 1.5.9.1) AC_CONFIG_SRCDIR([src/kernel/ao.h]) AM_INIT_AUTOMAKE([foreign dist-bzip2]) AM_MAINTAINER_MODE diff --git a/icon/application-vnd.altusmetrum.micropeak.svg b/icon/application-vnd.altusmetrum.micropeak.svg deleted file mode 120000 index 6efd3200..00000000 --- a/icon/application-vnd.altusmetrum.micropeak.svg +++ /dev/null @@ -1 +0,0 @@ -altusmetrum-micropeak.svg \ No newline at end of file diff --git a/src/kernel/ao_config.c b/src/kernel/ao_config.c index 8dab7c42..83a8cd77 100644 --- a/src/kernel/ao_config.c +++ b/src/kernel/ao_config.c @@ -388,6 +388,7 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant uint16_t i; int32_t accel_total; uint8_t cal_data_ring; + int16_t min = 32767, max = -32768; #if HAS_GYRO int32_t accel_along_total = 0; int32_t accel_across_total = 0; @@ -405,7 +406,10 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant while (i) { ao_sleep(DATA_TO_XDATA(&ao_sample_data)); while (i && cal_data_ring != ao_sample_data) { - accel_total += (int32_t) ao_data_accel(&ao_data_ring[cal_data_ring]); + int16_t v = ao_data_accel(&ao_data_ring[cal_data_ring]); + accel_total += (int32_t) v; + if (v < min) min = v; + if (v > max) max = v; #if HAS_GYRO accel_along_total += (int32_t) ao_data_along(&ao_data_ring[cal_data_ring]); accel_across_total += (int32_t) ao_data_across(&ao_data_ring[cal_data_ring]); @@ -420,6 +424,7 @@ ao_config_accel_calibrate_auto(char *orientation) __reentrant accel_cal_across = accel_across_total >> ACCEL_CALIBRATE_SHIFT; accel_cal_through = accel_through_total >> ACCEL_CALIBRATE_SHIFT; #endif + printf ("total %d min %d max %d\n", accel_total, min, max); return accel_total >> ACCEL_CALIBRATE_SHIFT; } diff --git a/src/lpc/ao_arch.h b/src/lpc/ao_arch.h index 42faf06f..1b4c61f2 100644 --- a/src/lpc/ao_arch.h +++ b/src/lpc/ao_arch.h @@ -124,6 +124,8 @@ ao_adc_init(void); #define AO_USB_OUT_EP 2 #define AO_USB_IN_EP 3 +extern uint8_t ao_usb_out_avail; + void ao_serial_init(void); diff --git a/src/lpc/ao_arch_funcs.h b/src/lpc/ao_arch_funcs.h index fbe641d8..b963d3ab 100644 --- a/src/lpc/ao_arch_funcs.h +++ b/src/lpc/ao_arch_funcs.h @@ -249,4 +249,10 @@ static inline void ao_arch_start_scheduler(void) { asm("isb"); } +void * +ao_usb_alloc(uint16_t len); + +void +ao_usb_write(void *block, int len); + #endif /* _AO_ARCH_FUNCS_H_ */ diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index 12f5d8e6..499de9e9 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -80,14 +80,12 @@ static uint8_t *ao_usb_ep0_setup_buffer; static uint8_t *ao_usb_ep0_rx_buffer; /* Pointer to bulk data tx/rx buffers in USB memory */ -static uint8_t *ao_usb_in_tx_buffer; -static uint8_t *ao_usb_out_rx_buffer; - -/* Our data buffers */ -static uint8_t ao_usb_tx_buffer[AO_USB_IN_SIZE]; +static uint8_t *ao_usb_in_tx_buffer[2]; +static uint8_t ao_usb_in_tx_cur; static uint8_t ao_usb_tx_count; -static uint8_t ao_usb_rx_buffer[AO_USB_OUT_SIZE]; +static uint8_t *ao_usb_out_rx_buffer[2]; +static uint8_t ao_usb_out_rx_cur; static uint8_t ao_usb_rx_count, ao_usb_rx_pos; extern struct lpc_usb_endpoint lpc_usb_endpoint; @@ -108,7 +106,7 @@ static uint8_t ao_usb_in_pending; /* Marks when an OUT packet has been received by the hardware * but not pulled to the shadow buffer. */ -static uint8_t ao_usb_out_avail; +uint8_t ao_usb_out_avail; uint8_t ao_usb_running; static uint8_t ao_usb_configuration; @@ -362,12 +360,16 @@ ao_usb_set_configuration(void) /* Set up the INT end point */ ao_usb_enable_epn(AO_USB_INT_EP, 0, NULL, 0, NULL); - + /* Set up the OUT end point */ - ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE, &ao_usb_out_rx_buffer, 0, NULL); + ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE * 2, &ao_usb_out_rx_buffer[0], 0, NULL); + ao_usb_out_rx_buffer[1] = ao_usb_out_rx_buffer[0] + AO_USB_OUT_SIZE; + ao_usb_out_rx_cur = 0; /* Set up the IN end point */ - ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE, &ao_usb_in_tx_buffer); + ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE * 2, &ao_usb_in_tx_buffer[0]); + ao_usb_in_tx_buffer[1] = ao_usb_in_tx_buffer[0] + AO_USB_IN_SIZE; + ao_usb_in_tx_cur = 0; ao_usb_running = 1; } @@ -716,8 +718,8 @@ _ao_usb_in_send(void) ao_usb_in_pending = 1; if (ao_usb_tx_count != AO_USB_IN_SIZE) ao_usb_in_flushed = 1; - memcpy(ao_usb_in_tx_buffer, ao_usb_tx_buffer, ao_usb_tx_count); - ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), ao_usb_in_tx_buffer, ao_usb_tx_count); + ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), ao_usb_in_tx_buffer[ao_usb_in_tx_cur], ao_usb_tx_count); + ao_usb_in_tx_cur = 1 - ao_usb_in_tx_cur; ao_usb_tx_count = 0; _tx_dbg0("in_send end"); } @@ -769,10 +771,12 @@ ao_usb_putchar(char c) ao_arch_block_interrupts(); _ao_usb_in_wait(); + ao_arch_release_interrupts(); ao_usb_in_flushed = 0; - ao_usb_tx_buffer[ao_usb_tx_count++] = (uint8_t) c; + ao_usb_in_tx_buffer[ao_usb_in_tx_cur][ao_usb_tx_count++] = (uint8_t) c; + ao_arch_block_interrupts(); /* Send the packet when full */ if (ao_usb_tx_count == AO_USB_IN_SIZE) { _tx_dbg0("putchar full"); @@ -782,6 +786,43 @@ ao_usb_putchar(char c) ao_arch_release_interrupts(); } +void * +ao_usb_alloc(uint16_t len) +{ + return ao_usb_alloc_sram(len); +} + +void +ao_usb_write(void *block, int len) +{ + uint8_t *b = block; + int this_time; + + if (!ao_usb_running) + return; + + if (!ao_usb_in_flushed) + ao_usb_flush(); + + while (len) { + ao_usb_in_flushed = 0; + this_time = AO_USB_IN_SIZE; + if (this_time > len) + this_time = len; + b += this_time; + len -= this_time; + + ao_arch_block_interrupts(); + while (ao_usb_in_pending) + ao_sleep(&ao_usb_in_pending); + ao_usb_in_pending = 1; + if (this_time != AO_USB_IN_SIZE) + ao_usb_in_flushed = 1; + ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), b, this_time); + ao_arch_release_interrupts(); + } +} + static void _ao_usb_out_recv(void) { @@ -792,13 +833,12 @@ _ao_usb_out_recv(void) _rx_dbg1("out_recv count", ao_usb_rx_count); debug ("recv %d\n", ao_usb_rx_count); - debug_data("Fill OUT len %d:", ao_usb_rx_count); - memcpy(ao_usb_rx_buffer, ao_usb_out_rx_buffer, ao_usb_rx_count); - debug_data("\n"); + debug_data("Fill OUT len %d\n", ao_usb_rx_count); ao_usb_rx_pos = 0; + ao_usb_rx_out_cur = 1 - ao_usb_rx_out_cur; /* ACK the packet */ - ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer, AO_USB_OUT_SIZE); + ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer[1-ao_usb_rx_out_cur], AO_USB_OUT_SIZE); } int @@ -823,7 +863,7 @@ _ao_usb_pollchar(void) } /* Pull a character out of the fifo */ - c = ao_usb_rx_buffer[ao_usb_rx_pos++]; + c = ao_usb_rx_buffer[ao_usb_rx_out_cur][ao_usb_rx_pos++]; return c; } diff --git a/src/usbtrng/ao_pins.h b/src/usbtrng/ao_pins.h index b1fa6eb9..0f2b1ea6 100644 --- a/src/usbtrng/ao_pins.h +++ b/src/usbtrng/ao_pins.h @@ -71,3 +71,5 @@ */ #define HAS_SCK1 0 #define HAS_MOSI1 0 + +#define AO_ADC_6 1 diff --git a/src/usbtrng/ao_usbtrng.c b/src/usbtrng/ao_usbtrng.c index 6b4d20fe..66e12337 100644 --- a/src/usbtrng/ao_usbtrng.c +++ b/src/usbtrng/ao_usbtrng.c @@ -18,7 +18,53 @@ #include #define AO_TRNG_SPI_BUS 1 -#define AO_TRNG_SPI_SPEED AO_SPI_SPEED_250kHz + +static uint32_t spi_speed = AO_SPI_SPEED_4MHz; + +#define AO_TRNG_SPI_BUF 1024 + +#if 0 + +static uint8_t *spi_buf; +static uint8_t *spi_head, *spi_tail; +static uint8_t spi_wakeup; + +static void +ao_trng_run(void) +{ + int this_time; + uint8_t *end; + + if (!spi_buf) + spi_buf = ao_usb_alloc(AO_TRNG_SPI_BUF); + flush(); + ao_spi_get(AO_TRNG_SPI_BUS, spi_speed); + spi_tail = spi_buf; + spi_head = spi_buf; + ao_spi_recv_ring_start(spi_buf, AO_TRNG_SPI_BUF, &spi_head, &spi_tail, &spi_wakeup, AO_TRNG_SPI_BUS); + while (!ao_usb_out_avail) { + ao_arch_block_interrupts(); + while (spi_head == spi_tail) { + spi_wakeup = 0; + ao_sleep(&spi_wakeup); + } + ao_arch_release_interrupts(); + if (spi_tail > spi_head) + end = spi_buf + AO_TRNG_SPI_BUF; + else + end = spi_head; + this_time = end - spi_tail; + if (this_time > 64) + this_time = 64; + ao_usb_write(spi_tail, this_time); + spi_tail += this_time; + if (spi_tail == spi_buf + AO_TRNG_SPI_BUF) + spi_tail = spi_buf; + } + ao_spi_put(AO_TRNG_SPI_BUS); + getchar(); +} + static void ao_trng_test(void) @@ -26,16 +72,153 @@ ao_trng_test(void) static uint8_t random[32]; uint8_t i; - ao_spi_get(AO_TRNG_SPI_BUS, AO_TRNG_SPI_SPEED); + ao_spi_get(AO_TRNG_SPI_BUS, spi_speed); ao_spi_recv(random, sizeof (random), AO_TRNG_SPI_BUS); ao_spi_put(AO_TRNG_SPI_BUS); for (i = 0; i < sizeof (random); i++) printf (" %02x", random[i]); printf ("\n"); } +#endif + +#define ADC_RING_SIZE 512 + +static uint8_t *adc_ring; +static uint16_t adc_head, adc_tail; +static uint16_t adc_wake; + +void lpc_adc_isr(void) +{ + uint16_t avail; + uint16_t this, next; + + this = adc_head; + next = (this + 1) & (ADC_RING_SIZE - 1); + if (next == adc_tail) { + lpc_adc.inten = 0; + return; + } + adc_ring[this] = lpc_adc.dr[6] >> 8; + adc_head = next; + + /* If there are enough entries, wake up any waiters + */ + avail = (next - adc_tail) & (ADC_RING_SIZE - 1); + if (avail >= adc_wake) { + adc_wake = 0; + ao_wakeup(&adc_wake); + } +} + +#define AO_ADC_CLKDIV (AO_LPC_SYSCLK / 450000) + +static void +ao_trng_adc_init(void) +{ + adc_ring = ao_usb_alloc(ADC_RING_SIZE); + + lpc_scb.sysahbclkctrl |= (1 << LPC_SCB_SYSAHBCLKCTRL_ADC); + lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_ADC_PD); + + /* Enable interrupt when AO_ADC_6 is complete */ + lpc_adc.inten = 0; + + lpc_nvic_set_enable(LPC_ISR_ADC_POS); + lpc_nvic_set_priority(LPC_ISR_ADC_POS, AO_LPC_NVIC_CLOCK_PRIORITY); + +#if AO_ADC_0 + ao_enable_analog(0, 11, 0); +#endif +#if AO_ADC_1 + ao_enable_analog(0, 12, 1); +#endif +#if AO_ADC_2 + ao_enable_analog(0, 13, 2); +#endif +#if AO_ADC_3 + ao_enable_analog(0, 14, 3); +#endif +#if AO_ADC_4 + ao_enable_analog(0, 15, 4); +#endif +#if AO_ADC_5 + ao_enable_analog(0, 16, 5); +#endif +#if AO_ADC_6 + ao_enable_analog(0, 22, 6); +#endif +#if AO_ADC_7 + ao_enable_analog(0, 23, 7); +#endif + + lpc_adc.cr = ((1 << (LPC_ADC_CR_SEL + 6)) | + (AO_ADC_CLKDIV << LPC_ADC_CR_CLKDIV) | + (1 << LPC_ADC_CR_BURST) | + (LPC_ADC_CR_CLKS_9 << LPC_ADC_CR_CLKS)); +} + +static void +ao_trng_adc_dump(void) +{ + int i; + + while (((adc_head - adc_tail) & (ADC_RING_SIZE - 1)) < 16) { + lpc_adc.inten = (1 << (LPC_ADC_INTEN_ADINTEN + 6)); + adc_wake = 16; + ao_sleep(&adc_wake); + } + printf("adc_head %d tail %d\n", adc_head, adc_tail); + + for (i = 0; i < 16; i++) { + printf(" %4d", adc_ring[adc_tail]); + adc_tail = (adc_tail + 1) & (ADC_RING_SIZE - 1); + } + printf("\n"); + lpc_adc.inten = 0; +} + +static void +ao_trng_run(void) +{ + uint16_t this_time; + flush(); + + while (!ao_usb_out_avail) { + ao_arch_block_interrupts(); + while (((adc_head - adc_tail) & (ADC_RING_SIZE - 1)) < 64) { + lpc_adc.inten = (1 << (LPC_ADC_INTEN_ADINTEN + 6)); + adc_wake = 64; + ao_sleep(&adc_wake); + } + ao_arch_release_interrupts(); + + this_time = ADC_RING_SIZE - adc_tail; + if (this_time > 64) + this_time = 64; + ao_usb_write(&adc_ring[adc_tail], this_time); + adc_tail = (adc_tail + this_time) & (ADC_RING_SIZE - 1); + } + lpc_adc.inten = 0; +} + +static void +ao_trng_speed(void) +{ + ao_cmd_decimal(); + + if (ao_cmd_lex_u32 == 0 || ao_cmd_status != ao_cmd_success) { + ao_cmd_status = ao_cmd_success; + printf ("Current spi speed %d\n", spi_speed); + } else { + spi_speed = ao_cmd_lex_u32; + } +} static const struct ao_cmds ao_trng_cmds[] = { - { ao_trng_test, "R\0Dump some random numbers" }, +// { ao_trng_test, "R\0Dump some random numbers" }, + { ao_trng_run, "s\0Send random bits until char" }, + { ao_trng_speed, "S \0Set SPI speed (48MHz/speed)" }, + { ao_trng_adc_dump, "a\0Dump ADC data" }, { 0, NULL } }; @@ -46,15 +229,15 @@ main(void) ao_task_init(); ao_timer_init(); - ao_spi_init(); +// ao_spi_init(); ao_usb_init(); + ao_trng_adc_init(); + ao_serial_init(); ao_led_init(LEDS_AVAILABLE); - ao_led_on(AO_LED_GREEN); - ao_cmd_init(); ao_cmd_register(ao_trng_cmds); -- cgit v1.2.3 From 41a0604ad1ea1a03e2db7d41731dbadf466b45db Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 22 Jan 2015 21:31:45 -0800 Subject: altos/lpc: Fix double-buffered USB changes These got merged when we were down in Auckland, but before they'd been finished. Transmitting worked fine, but receiving was mis-configuring the OUT buffer size in the hardware. Signed-off-by: Keith Packard --- src/lpc/ao_usb_lpc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index 499de9e9..af304b8a 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -273,7 +273,7 @@ static uint8_t * ao_usb_enable_ep(vuint32_t *ep, uint16_t nbytes, uint16_t set_nbytes) { uint8_t *addr = ao_usb_alloc_sram(nbytes); - + ao_usb_set_ep(ep, addr, set_nbytes); return addr; } @@ -292,11 +292,11 @@ ao_usb_disable_ep(vuint32_t *ep) } static void -ao_usb_enable_epn(uint8_t n, uint16_t out_bytes, uint8_t **out_addr, uint16_t in_bytes, uint8_t **in_addr) +ao_usb_enable_epn(uint8_t n, uint16_t out_bytes, uint16_t out_set_bytes, uint8_t **out_addr, uint16_t in_bytes, uint8_t **in_addr) { uint8_t *addr; - addr = ao_usb_enable_ep(ao_usb_epn_out(n), out_bytes, out_bytes); + addr = ao_usb_enable_ep(ao_usb_epn_out(n), out_bytes, out_set_bytes); if (out_addr) *out_addr = addr; ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].out[1]); @@ -359,15 +359,15 @@ ao_usb_set_configuration(void) debug ("ao_usb_set_configuration\n"); /* Set up the INT end point */ - ao_usb_enable_epn(AO_USB_INT_EP, 0, NULL, 0, NULL); + ao_usb_enable_epn(AO_USB_INT_EP, 0, 0, NULL, 0, NULL); /* Set up the OUT end point */ - ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE * 2, &ao_usb_out_rx_buffer[0], 0, NULL); + ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE * 2, AO_USB_OUT_SIZE, &ao_usb_out_rx_buffer[0], 0, NULL); ao_usb_out_rx_buffer[1] = ao_usb_out_rx_buffer[0] + AO_USB_OUT_SIZE; ao_usb_out_rx_cur = 0; /* Set up the IN end point */ - ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE * 2, &ao_usb_in_tx_buffer[0]); + ao_usb_enable_epn(AO_USB_IN_EP, 0, 0, NULL, AO_USB_IN_SIZE * 2, &ao_usb_in_tx_buffer[0]); ao_usb_in_tx_buffer[1] = ao_usb_in_tx_buffer[0] + AO_USB_IN_SIZE; ao_usb_in_tx_cur = 0; @@ -771,12 +771,10 @@ ao_usb_putchar(char c) ao_arch_block_interrupts(); _ao_usb_in_wait(); - ao_arch_release_interrupts(); ao_usb_in_flushed = 0; ao_usb_in_tx_buffer[ao_usb_in_tx_cur][ao_usb_tx_count++] = (uint8_t) c; - ao_arch_block_interrupts(); /* Send the packet when full */ if (ao_usb_tx_count == AO_USB_IN_SIZE) { _tx_dbg0("putchar full"); @@ -786,6 +784,7 @@ ao_usb_putchar(char c) ao_arch_release_interrupts(); } +#if HAS_AO_USB_WRITE void * ao_usb_alloc(uint16_t len) { @@ -809,8 +808,6 @@ ao_usb_write(void *block, int len) this_time = AO_USB_IN_SIZE; if (this_time > len) this_time = len; - b += this_time; - len -= this_time; ao_arch_block_interrupts(); while (ao_usb_in_pending) @@ -820,8 +817,11 @@ ao_usb_write(void *block, int len) ao_usb_in_flushed = 1; ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), b, this_time); ao_arch_release_interrupts(); + b += this_time; + len -= this_time; } } +#endif static void _ao_usb_out_recv(void) @@ -835,10 +835,10 @@ _ao_usb_out_recv(void) debug ("recv %d\n", ao_usb_rx_count); debug_data("Fill OUT len %d\n", ao_usb_rx_count); ao_usb_rx_pos = 0; - ao_usb_rx_out_cur = 1 - ao_usb_rx_out_cur; + ao_usb_out_rx_cur = 1 - ao_usb_out_rx_cur; /* ACK the packet */ - ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer[1-ao_usb_rx_out_cur], AO_USB_OUT_SIZE); + ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer[1-ao_usb_out_rx_cur], AO_USB_OUT_SIZE); } int @@ -863,7 +863,7 @@ _ao_usb_pollchar(void) } /* Pull a character out of the fifo */ - c = ao_usb_rx_buffer[ao_usb_rx_out_cur][ao_usb_rx_pos++]; + c = ao_usb_out_rx_buffer[ao_usb_out_rx_cur][ao_usb_rx_pos++]; return c; } @@ -937,7 +937,7 @@ ao_usb_enable(void) /* Enable USB PHY */ lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPAD_PD); - + /* Turn on USB PLL */ lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPLL_PD); -- cgit v1.2.3 From ef69872c824668146a3876f1f3d0d2e51d3e4c8d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Feb 2015 14:54:27 -0800 Subject: Revert "altos/lpc: Fix double-buffered USB changes" This reverts commit 41a0604ad1ea1a03e2db7d41731dbadf466b45db. --- src/lpc/ao_usb_lpc.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index af304b8a..499de9e9 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -273,7 +273,7 @@ static uint8_t * ao_usb_enable_ep(vuint32_t *ep, uint16_t nbytes, uint16_t set_nbytes) { uint8_t *addr = ao_usb_alloc_sram(nbytes); - + ao_usb_set_ep(ep, addr, set_nbytes); return addr; } @@ -292,11 +292,11 @@ ao_usb_disable_ep(vuint32_t *ep) } static void -ao_usb_enable_epn(uint8_t n, uint16_t out_bytes, uint16_t out_set_bytes, uint8_t **out_addr, uint16_t in_bytes, uint8_t **in_addr) +ao_usb_enable_epn(uint8_t n, uint16_t out_bytes, uint8_t **out_addr, uint16_t in_bytes, uint8_t **in_addr) { uint8_t *addr; - addr = ao_usb_enable_ep(ao_usb_epn_out(n), out_bytes, out_set_bytes); + addr = ao_usb_enable_ep(ao_usb_epn_out(n), out_bytes, out_bytes); if (out_addr) *out_addr = addr; ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].out[1]); @@ -359,15 +359,15 @@ ao_usb_set_configuration(void) debug ("ao_usb_set_configuration\n"); /* Set up the INT end point */ - ao_usb_enable_epn(AO_USB_INT_EP, 0, 0, NULL, 0, NULL); + ao_usb_enable_epn(AO_USB_INT_EP, 0, NULL, 0, NULL); /* Set up the OUT end point */ - ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE * 2, AO_USB_OUT_SIZE, &ao_usb_out_rx_buffer[0], 0, NULL); + ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE * 2, &ao_usb_out_rx_buffer[0], 0, NULL); ao_usb_out_rx_buffer[1] = ao_usb_out_rx_buffer[0] + AO_USB_OUT_SIZE; ao_usb_out_rx_cur = 0; /* Set up the IN end point */ - ao_usb_enable_epn(AO_USB_IN_EP, 0, 0, NULL, AO_USB_IN_SIZE * 2, &ao_usb_in_tx_buffer[0]); + ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE * 2, &ao_usb_in_tx_buffer[0]); ao_usb_in_tx_buffer[1] = ao_usb_in_tx_buffer[0] + AO_USB_IN_SIZE; ao_usb_in_tx_cur = 0; @@ -771,10 +771,12 @@ ao_usb_putchar(char c) ao_arch_block_interrupts(); _ao_usb_in_wait(); + ao_arch_release_interrupts(); ao_usb_in_flushed = 0; ao_usb_in_tx_buffer[ao_usb_in_tx_cur][ao_usb_tx_count++] = (uint8_t) c; + ao_arch_block_interrupts(); /* Send the packet when full */ if (ao_usb_tx_count == AO_USB_IN_SIZE) { _tx_dbg0("putchar full"); @@ -784,7 +786,6 @@ ao_usb_putchar(char c) ao_arch_release_interrupts(); } -#if HAS_AO_USB_WRITE void * ao_usb_alloc(uint16_t len) { @@ -808,6 +809,8 @@ ao_usb_write(void *block, int len) this_time = AO_USB_IN_SIZE; if (this_time > len) this_time = len; + b += this_time; + len -= this_time; ao_arch_block_interrupts(); while (ao_usb_in_pending) @@ -817,11 +820,8 @@ ao_usb_write(void *block, int len) ao_usb_in_flushed = 1; ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), b, this_time); ao_arch_release_interrupts(); - b += this_time; - len -= this_time; } } -#endif static void _ao_usb_out_recv(void) @@ -835,10 +835,10 @@ _ao_usb_out_recv(void) debug ("recv %d\n", ao_usb_rx_count); debug_data("Fill OUT len %d\n", ao_usb_rx_count); ao_usb_rx_pos = 0; - ao_usb_out_rx_cur = 1 - ao_usb_out_rx_cur; + ao_usb_rx_out_cur = 1 - ao_usb_rx_out_cur; /* ACK the packet */ - ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer[1-ao_usb_out_rx_cur], AO_USB_OUT_SIZE); + ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer[1-ao_usb_rx_out_cur], AO_USB_OUT_SIZE); } int @@ -863,7 +863,7 @@ _ao_usb_pollchar(void) } /* Pull a character out of the fifo */ - c = ao_usb_out_rx_buffer[ao_usb_out_rx_cur][ao_usb_rx_pos++]; + c = ao_usb_rx_buffer[ao_usb_rx_out_cur][ao_usb_rx_pos++]; return c; } @@ -937,7 +937,7 @@ ao_usb_enable(void) /* Enable USB PHY */ lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPAD_PD); - + /* Turn on USB PLL */ lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPLL_PD); -- cgit v1.2.3 From 5bf39f674b3d5ee98b55f42562a5ba1a9328ff07 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Feb 2015 14:56:13 -0800 Subject: Revert LPC usb performance improvements There's something screwy going on, sticking garbage in the input buffer at boot time Signed-off-by: Keith Packard --- src/lpc/ao_arch.h | 2 -- src/lpc/ao_arch_funcs.h | 6 ---- src/lpc/ao_usb_lpc.c | 76 ++++++++++++------------------------------------- 3 files changed, 18 insertions(+), 66 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_arch.h b/src/lpc/ao_arch.h index 1b4c61f2..42faf06f 100644 --- a/src/lpc/ao_arch.h +++ b/src/lpc/ao_arch.h @@ -124,8 +124,6 @@ ao_adc_init(void); #define AO_USB_OUT_EP 2 #define AO_USB_IN_EP 3 -extern uint8_t ao_usb_out_avail; - void ao_serial_init(void); diff --git a/src/lpc/ao_arch_funcs.h b/src/lpc/ao_arch_funcs.h index b963d3ab..fbe641d8 100644 --- a/src/lpc/ao_arch_funcs.h +++ b/src/lpc/ao_arch_funcs.h @@ -249,10 +249,4 @@ static inline void ao_arch_start_scheduler(void) { asm("isb"); } -void * -ao_usb_alloc(uint16_t len); - -void -ao_usb_write(void *block, int len); - #endif /* _AO_ARCH_FUNCS_H_ */ diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index 499de9e9..12f5d8e6 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -80,12 +80,14 @@ static uint8_t *ao_usb_ep0_setup_buffer; static uint8_t *ao_usb_ep0_rx_buffer; /* Pointer to bulk data tx/rx buffers in USB memory */ -static uint8_t *ao_usb_in_tx_buffer[2]; -static uint8_t ao_usb_in_tx_cur; +static uint8_t *ao_usb_in_tx_buffer; +static uint8_t *ao_usb_out_rx_buffer; + +/* Our data buffers */ +static uint8_t ao_usb_tx_buffer[AO_USB_IN_SIZE]; static uint8_t ao_usb_tx_count; -static uint8_t *ao_usb_out_rx_buffer[2]; -static uint8_t ao_usb_out_rx_cur; +static uint8_t ao_usb_rx_buffer[AO_USB_OUT_SIZE]; static uint8_t ao_usb_rx_count, ao_usb_rx_pos; extern struct lpc_usb_endpoint lpc_usb_endpoint; @@ -106,7 +108,7 @@ static uint8_t ao_usb_in_pending; /* Marks when an OUT packet has been received by the hardware * but not pulled to the shadow buffer. */ -uint8_t ao_usb_out_avail; +static uint8_t ao_usb_out_avail; uint8_t ao_usb_running; static uint8_t ao_usb_configuration; @@ -360,16 +362,12 @@ ao_usb_set_configuration(void) /* Set up the INT end point */ ao_usb_enable_epn(AO_USB_INT_EP, 0, NULL, 0, NULL); - + /* Set up the OUT end point */ - ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE * 2, &ao_usb_out_rx_buffer[0], 0, NULL); - ao_usb_out_rx_buffer[1] = ao_usb_out_rx_buffer[0] + AO_USB_OUT_SIZE; - ao_usb_out_rx_cur = 0; + ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE, &ao_usb_out_rx_buffer, 0, NULL); /* Set up the IN end point */ - ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE * 2, &ao_usb_in_tx_buffer[0]); - ao_usb_in_tx_buffer[1] = ao_usb_in_tx_buffer[0] + AO_USB_IN_SIZE; - ao_usb_in_tx_cur = 0; + ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE, &ao_usb_in_tx_buffer); ao_usb_running = 1; } @@ -718,8 +716,8 @@ _ao_usb_in_send(void) ao_usb_in_pending = 1; if (ao_usb_tx_count != AO_USB_IN_SIZE) ao_usb_in_flushed = 1; - ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), ao_usb_in_tx_buffer[ao_usb_in_tx_cur], ao_usb_tx_count); - ao_usb_in_tx_cur = 1 - ao_usb_in_tx_cur; + memcpy(ao_usb_in_tx_buffer, ao_usb_tx_buffer, ao_usb_tx_count); + ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), ao_usb_in_tx_buffer, ao_usb_tx_count); ao_usb_tx_count = 0; _tx_dbg0("in_send end"); } @@ -771,12 +769,10 @@ ao_usb_putchar(char c) ao_arch_block_interrupts(); _ao_usb_in_wait(); - ao_arch_release_interrupts(); ao_usb_in_flushed = 0; - ao_usb_in_tx_buffer[ao_usb_in_tx_cur][ao_usb_tx_count++] = (uint8_t) c; + ao_usb_tx_buffer[ao_usb_tx_count++] = (uint8_t) c; - ao_arch_block_interrupts(); /* Send the packet when full */ if (ao_usb_tx_count == AO_USB_IN_SIZE) { _tx_dbg0("putchar full"); @@ -786,43 +782,6 @@ ao_usb_putchar(char c) ao_arch_release_interrupts(); } -void * -ao_usb_alloc(uint16_t len) -{ - return ao_usb_alloc_sram(len); -} - -void -ao_usb_write(void *block, int len) -{ - uint8_t *b = block; - int this_time; - - if (!ao_usb_running) - return; - - if (!ao_usb_in_flushed) - ao_usb_flush(); - - while (len) { - ao_usb_in_flushed = 0; - this_time = AO_USB_IN_SIZE; - if (this_time > len) - this_time = len; - b += this_time; - len -= this_time; - - ao_arch_block_interrupts(); - while (ao_usb_in_pending) - ao_sleep(&ao_usb_in_pending); - ao_usb_in_pending = 1; - if (this_time != AO_USB_IN_SIZE) - ao_usb_in_flushed = 1; - ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), b, this_time); - ao_arch_release_interrupts(); - } -} - static void _ao_usb_out_recv(void) { @@ -833,12 +792,13 @@ _ao_usb_out_recv(void) _rx_dbg1("out_recv count", ao_usb_rx_count); debug ("recv %d\n", ao_usb_rx_count); - debug_data("Fill OUT len %d\n", ao_usb_rx_count); + debug_data("Fill OUT len %d:", ao_usb_rx_count); + memcpy(ao_usb_rx_buffer, ao_usb_out_rx_buffer, ao_usb_rx_count); + debug_data("\n"); ao_usb_rx_pos = 0; - ao_usb_rx_out_cur = 1 - ao_usb_rx_out_cur; /* ACK the packet */ - ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer[1-ao_usb_rx_out_cur], AO_USB_OUT_SIZE); + ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer, AO_USB_OUT_SIZE); } int @@ -863,7 +823,7 @@ _ao_usb_pollchar(void) } /* Pull a character out of the fifo */ - c = ao_usb_rx_buffer[ao_usb_rx_out_cur][ao_usb_rx_pos++]; + c = ao_usb_rx_buffer[ao_usb_rx_pos++]; return c; } -- cgit v1.2.3 From 0671b3c8c24c9f33be77a10315c4669f33c516d7 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 5 Feb 2015 16:08:44 -0800 Subject: altos/lpc: Clean up USB endpoint access functions The USB device endpoints can have two pointers in them, but we use only the first. Fix the access functions to take an index as to which we want so that we can disable the other address registers with them instead of requiring open-coded access. Signed-off-by: Keith Packard --- src/lpc/ao_usb_lpc.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index 12f5d8e6..78fbac39 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -234,15 +234,15 @@ ao_usb_ep0_in(void) } static inline vuint32_t * -ao_usb_epn_out(uint8_t n) +ao_usb_epn_out(uint8_t n, uint8_t i) { - return &lpc_usb_endpoint.epn[n-1].out[0]; + return &lpc_usb_endpoint.epn[n-1].out[i]; } static inline vuint32_t * -ao_usb_epn_in(uint8_t n) +ao_usb_epn_in(uint8_t n, uint8_t i) { - return &lpc_usb_endpoint.epn[n-1].in[0]; + return &lpc_usb_endpoint.epn[n-1].in[i]; } #if UNUSED @@ -256,26 +256,26 @@ ao_usb_set_epn_in(uint8_t n, uint8_t *addr, uint16_t nbytes) static void ao_usb_set_epn_out(uint8_t n, uint8_t *addr, uint16_t nbytes) { - ao_usb_set_ep(ao_usb_epn_out(n), addr, nbytes); + ao_usb_set_ep(ao_usb_epn_out(n, 0), addr, nbytes); } static inline uint16_t ao_usb_epn_out_count(uint8_t n) { - return ao_usb_ep_count(ao_usb_epn_out(n)); + return ao_usb_ep_count(ao_usb_epn_out(n, 0)); } static inline uint16_t ao_usb_epn_in_count(uint8_t n) { - return ao_usb_ep_count(ao_usb_epn_in(n)); + return ao_usb_ep_count(ao_usb_epn_in(n, 0)); } static uint8_t * ao_usb_enable_ep(vuint32_t *ep, uint16_t nbytes, uint16_t set_nbytes) { uint8_t *addr = ao_usb_alloc_sram(nbytes); - + ao_usb_set_ep(ep, addr, set_nbytes); return addr; } @@ -298,24 +298,24 @@ ao_usb_enable_epn(uint8_t n, uint16_t out_bytes, uint8_t **out_addr, uint16_t in { uint8_t *addr; - addr = ao_usb_enable_ep(ao_usb_epn_out(n), out_bytes, out_bytes); + addr = ao_usb_enable_ep(ao_usb_epn_out(n, 0), out_bytes, out_bytes); if (out_addr) *out_addr = addr; - ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].out[1]); + ao_usb_disable_ep(ao_usb_epn_out(n, 1)); - addr = ao_usb_enable_ep(ao_usb_epn_in(n), in_bytes, 0); + addr = ao_usb_enable_ep(ao_usb_epn_in(n, 0), in_bytes, 0); if (in_addr) *in_addr = addr; - ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].in[1]); + ao_usb_disable_ep(ao_usb_epn_in(n, 1)); } static void ao_usb_disable_epn(uint8_t n) { - ao_usb_disable_ep(ao_usb_epn_out(n)); - ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].out[1]); - ao_usb_disable_ep(ao_usb_epn_in(n)); - ao_usb_disable_ep(&lpc_usb_endpoint.epn[n-1].in[1]); + ao_usb_disable_ep(ao_usb_epn_out(n, 0)); + ao_usb_disable_ep(ao_usb_epn_out(n, 1)); + ao_usb_disable_ep(ao_usb_epn_in(n, 0)); + ao_usb_disable_ep(ao_usb_epn_in(n, 1)); } static void @@ -717,7 +717,7 @@ _ao_usb_in_send(void) if (ao_usb_tx_count != AO_USB_IN_SIZE) ao_usb_in_flushed = 1; memcpy(ao_usb_in_tx_buffer, ao_usb_tx_buffer, ao_usb_tx_count); - ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP), ao_usb_in_tx_buffer, ao_usb_tx_count); + ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP, 0), ao_usb_in_tx_buffer, ao_usb_tx_count); ao_usb_tx_count = 0; _tx_dbg0("in_send end"); } @@ -897,7 +897,7 @@ ao_usb_enable(void) /* Enable USB PHY */ lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPAD_PD); - + /* Turn on USB PLL */ lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_USBPLL_PD); @@ -1044,7 +1044,7 @@ static void _dbg(int line, char *msg, uint32_t value) dbg[dbg_i].primask = primask; #if TX_DBG dbg[dbg_i].in_count = in_count; - dbg[dbg_i].in_ep = *ao_usb_epn_in(AO_USB_IN_EP); + dbg[dbg_i].in_ep = *ao_usb_epn_in(AO_USB_IN_EP, 0); dbg[dbg_i].in_pending = ao_usb_in_pending; dbg[dbg_i].tx_count = ao_usb_tx_count; dbg[dbg_i].in_flushed = ao_usb_in_flushed; @@ -1053,7 +1053,7 @@ static void _dbg(int line, char *msg, uint32_t value) dbg[dbg_i].rx_count = ao_usb_rx_count; dbg[dbg_i].rx_pos = ao_usb_rx_pos; dbg[dbg_i].out_avail = ao_usb_out_avail; - dbg[dbg_i].out_ep = *ao_usb_epn_out(AO_USB_OUT_EP); + dbg[dbg_i].out_ep = *ao_usb_epn_out(AO_USB_OUT_EP, 0); #endif if (++dbg_i == NUM_USB_DBG) dbg_i = 0; -- cgit v1.2.3 From 9fac8b639d2142c90eb95771cda1f6559e987db2 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Fri, 16 Jan 2015 22:09:26 +1300 Subject: altos/lpc: Double buffer USB data transfers This allocates twice the space in the USB memory so that transactions can be double buffered without using separate CPU memory. Signed-off-by: Keith Packard Conflicts: src/lpc/ao_usb_lpc.c --- src/lpc/ao_usb_lpc.c | 57 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 24 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_usb_lpc.c b/src/lpc/ao_usb_lpc.c index 78fbac39..0dfaece4 100644 --- a/src/lpc/ao_usb_lpc.c +++ b/src/lpc/ao_usb_lpc.c @@ -80,14 +80,12 @@ static uint8_t *ao_usb_ep0_setup_buffer; static uint8_t *ao_usb_ep0_rx_buffer; /* Pointer to bulk data tx/rx buffers in USB memory */ -static uint8_t *ao_usb_in_tx_buffer; -static uint8_t *ao_usb_out_rx_buffer; - -/* Our data buffers */ -static uint8_t ao_usb_tx_buffer[AO_USB_IN_SIZE]; +static uint8_t *ao_usb_in_tx_buffer[2]; +static uint8_t ao_usb_in_tx_cur; static uint8_t ao_usb_tx_count; -static uint8_t ao_usb_rx_buffer[AO_USB_OUT_SIZE]; +static uint8_t *ao_usb_out_rx_buffer[2]; +static uint8_t ao_usb_out_rx_cur; static uint8_t ao_usb_rx_count, ao_usb_rx_pos; extern struct lpc_usb_endpoint lpc_usb_endpoint; @@ -294,18 +292,24 @@ ao_usb_disable_ep(vuint32_t *ep) } static void -ao_usb_enable_epn(uint8_t n, uint16_t out_bytes, uint8_t **out_addr, uint16_t in_bytes, uint8_t **in_addr) +ao_usb_enable_epn(uint8_t n, + uint16_t out_bytes, uint8_t *out_addrs[2], + uint16_t in_bytes, uint8_t *in_addrs[2]) { uint8_t *addr; - addr = ao_usb_enable_ep(ao_usb_epn_out(n, 0), out_bytes, out_bytes); - if (out_addr) - *out_addr = addr; + addr = ao_usb_enable_ep(ao_usb_epn_out(n, 0), out_bytes * 2, out_bytes); + if (out_addrs) { + out_addrs[0] = addr; + out_addrs[1] = addr + out_bytes; + } ao_usb_disable_ep(ao_usb_epn_out(n, 1)); - addr = ao_usb_enable_ep(ao_usb_epn_in(n, 0), in_bytes, 0); - if (in_addr) - *in_addr = addr; + addr = ao_usb_enable_ep(ao_usb_epn_in(n, 0), in_bytes * 2, 0); + if (in_addrs) { + in_addrs[0] = addr; + in_addrs[1] = addr + in_bytes; + } ao_usb_disable_ep(ao_usb_epn_in(n, 1)); } @@ -362,12 +366,18 @@ ao_usb_set_configuration(void) /* Set up the INT end point */ ao_usb_enable_epn(AO_USB_INT_EP, 0, NULL, 0, NULL); - + /* Set up the OUT end point */ - ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE, &ao_usb_out_rx_buffer, 0, NULL); + ao_usb_enable_epn(AO_USB_OUT_EP, AO_USB_OUT_SIZE, ao_usb_out_rx_buffer, 0, NULL); + + /* Set the current RX pointer to the *other* buffer so that when buffer 0 gets + * data, we'll switch to it and pull bytes from there + */ + ao_usb_out_rx_cur = 1; /* Set up the IN end point */ - ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE, &ao_usb_in_tx_buffer); + ao_usb_enable_epn(AO_USB_IN_EP, 0, NULL, AO_USB_IN_SIZE, ao_usb_in_tx_buffer); + ao_usb_in_tx_cur = 0; ao_usb_running = 1; } @@ -716,8 +726,8 @@ _ao_usb_in_send(void) ao_usb_in_pending = 1; if (ao_usb_tx_count != AO_USB_IN_SIZE) ao_usb_in_flushed = 1; - memcpy(ao_usb_in_tx_buffer, ao_usb_tx_buffer, ao_usb_tx_count); - ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP, 0), ao_usb_in_tx_buffer, ao_usb_tx_count); + ao_usb_set_ep(ao_usb_epn_in(AO_USB_IN_EP, 0), ao_usb_in_tx_buffer[ao_usb_in_tx_cur], ao_usb_tx_count); + ao_usb_in_tx_cur = 1 - ao_usb_in_tx_cur; ao_usb_tx_count = 0; _tx_dbg0("in_send end"); } @@ -771,7 +781,7 @@ ao_usb_putchar(char c) _ao_usb_in_wait(); ao_usb_in_flushed = 0; - ao_usb_tx_buffer[ao_usb_tx_count++] = (uint8_t) c; + ao_usb_in_tx_buffer[ao_usb_in_tx_cur][ao_usb_tx_count++] = (uint8_t) c; /* Send the packet when full */ if (ao_usb_tx_count == AO_USB_IN_SIZE) { @@ -792,13 +802,12 @@ _ao_usb_out_recv(void) _rx_dbg1("out_recv count", ao_usb_rx_count); debug ("recv %d\n", ao_usb_rx_count); - debug_data("Fill OUT len %d:", ao_usb_rx_count); - memcpy(ao_usb_rx_buffer, ao_usb_out_rx_buffer, ao_usb_rx_count); - debug_data("\n"); + debug_data("Fill OUT len %d\n", ao_usb_rx_count); ao_usb_rx_pos = 0; + ao_usb_out_rx_cur = 1 - ao_usb_out_rx_cur; /* ACK the packet */ - ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer, AO_USB_OUT_SIZE); + ao_usb_set_epn_out(AO_USB_OUT_EP, ao_usb_out_rx_buffer[1-ao_usb_out_rx_cur], AO_USB_OUT_SIZE); } int @@ -823,7 +832,7 @@ _ao_usb_pollchar(void) } /* Pull a character out of the fifo */ - c = ao_usb_rx_buffer[ao_usb_rx_pos++]; + c = ao_usb_out_rx_buffer[ao_usb_out_rx_cur][ao_usb_rx_pos++]; return c; } -- cgit v1.2.3 From f9f235bce84df3a6c0261e9d256aac544f87f70f Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 7 Feb 2015 01:05:57 -0800 Subject: altos/lpc: Give up on interrupt-driven SPI driver There are just too many limitations in when interrupts are delivered to make them useful. Instead, just drive the SPI directly with the CPU. At higher spi speeds (6Mhz or more), it's probably faster to do it this way anyways. Signed-off-by: Keith Packard --- src/lpc/ao_spi_lpc.c | 133 ++++++++++----------------------------------------- 1 file changed, 25 insertions(+), 108 deletions(-) (limited to 'src/lpc') diff --git a/src/lpc/ao_spi_lpc.c b/src/lpc/ao_spi_lpc.c index 5a358919..f091c89c 100644 --- a/src/lpc/ao_spi_lpc.c +++ b/src/lpc/ao_spi_lpc.c @@ -19,130 +19,56 @@ static uint8_t ao_spi_mutex[LPC_NUM_SPI]; -struct ao_lpc_ssp_state { - int tx_count; - const uint8_t *tx; - int tx_inc; - int rx_count; - uint8_t *rx; - int rx_inc; -}; - -static struct ao_lpc_ssp_state ao_lpc_ssp_state[LPC_NUM_SPI]; - static struct lpc_ssp * const ao_lpc_ssp[LPC_NUM_SPI] = { &lpc_ssp0, &lpc_ssp1 }; -static inline void -ao_lpc_ssp_recv(struct lpc_ssp *lpc_ssp, struct ao_lpc_ssp_state *state) -{ - while ((lpc_ssp->sr & (1 << LPC_SSP_SR_RNE)) && - state->rx_count) - { - /* RX ready, read a byte */ - *state->rx = lpc_ssp->dr; - state->rx += state->rx_inc; - state->rx_count--; - } -} - -static void -ao_lpc_ssp_isr(struct lpc_ssp *lpc_ssp, struct ao_lpc_ssp_state *state) -{ - ao_lpc_ssp_recv(lpc_ssp, state); - while ((lpc_ssp->sr & (1 << LPC_SSP_SR_TNF)) && - state->tx_count) - { - /* TX ready, write a byte */ - lpc_ssp->dr = *state->tx; - state->tx += state->tx_inc; - state->tx_count--; - ao_lpc_ssp_recv(lpc_ssp, state); - } - if (!state->rx_count) { - lpc_ssp->imsc &= ~(1 << LPC_SSP_IMSC_TXIM); - ao_wakeup(state); - } -} - -void -lpc_ssp0_isr(void) -{ - ao_lpc_ssp_isr(&lpc_ssp0, &ao_lpc_ssp_state[0]); -} - -void -lpc_ssp1_isr(void) -{ - ao_lpc_ssp_isr(&lpc_ssp1, &ao_lpc_ssp_state[1]); -} - -static void -ao_spi_run(struct lpc_ssp *lpc_ssp, struct ao_lpc_ssp_state *state) -{ - ao_arch_block_interrupts(); - lpc_ssp->imsc = (1 << LPC_SSP_IMSC_TXIM); - while (state->rx_count) - ao_sleep(state); - ao_arch_release_interrupts(); -} - -static uint8_t ao_spi_tx_dummy = 0xff; -static uint8_t ao_spi_rx_dummy; +#define spi_loop(len, put, get) do { \ + while (len--) { \ + /* send a byte */ \ + lpc_ssp->dr = put; \ + /* wait for the received byte to appear */ \ + while ((lpc_ssp->sr & (1 << LPC_SSP_SR_RNE)) == 0) \ + ; \ + /* receive a byte */ \ + get lpc_ssp->dr; \ + } \ + /* Wait for the SSP to go idle (it already should be) */ \ + while (lpc_ssp->sr & (1 << LPC_SSP_SR_BSY)); \ + } while (0) void ao_spi_send(const void *block, uint16_t len, uint8_t id) { struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; - struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - - state->tx_count = state->rx_count = len; - state->tx = block; - state->tx_inc = 1; - state->rx = &ao_spi_rx_dummy; - state->rx_inc = 0; - ao_spi_run(lpc_ssp, state); + const uint8_t *o = block; + + spi_loop(len, *o++, (void)); } void ao_spi_send_fixed(uint8_t value, uint16_t len, uint8_t id) { struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; - struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - - state->tx_count = state->rx_count = len; - state->tx = &value; - state->tx_inc = 0; - state->rx = &ao_spi_rx_dummy; - state->rx_inc = 0; - ao_spi_run(lpc_ssp, state); + + spi_loop(len, value, (void)); } void ao_spi_recv(void *block, uint16_t len, uint8_t id) { struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; - struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - - state->tx_count = state->rx_count = len; - state->tx = &ao_spi_tx_dummy; - state->tx_inc = 0; - state->rx = block; - state->rx_inc = 1; - ao_spi_run(lpc_ssp, state); + uint8_t *i = block; + + spi_loop(len, 0xff, *i++ =); } void ao_spi_duplex(const void *out, void *in, uint16_t len, uint8_t id) { struct lpc_ssp *lpc_ssp = ao_lpc_ssp[id]; - struct ao_lpc_ssp_state *state = &ao_lpc_ssp_state[id]; - - state->tx_count = state->rx_count = len; - state->tx = out; - state->tx_inc = 1; - state->rx = in; - state->rx_inc = 1; - ao_spi_run(lpc_ssp, state); + const uint8_t *o = out; + uint8_t *i = in; + + spi_loop(len, *o++, *i++ =); } void @@ -223,10 +149,6 @@ ao_spi_init(void) lpc_scb.presetctrl &= ~(1 << LPC_SCB_PRESETCTRL_SSP0_RST_N); lpc_scb.presetctrl |= (1 << LPC_SCB_PRESETCTRL_SSP0_RST_N); ao_spi_channel_init(0); - - /* Configure NVIC */ - lpc_nvic_set_enable(LPC_ISR_SSP0_POS); - lpc_nvic_set_priority(LPC_ISR_SSP0_POS, 0); #endif #if HAS_SPI_1 @@ -277,10 +199,5 @@ ao_spi_init(void) lpc_scb.presetctrl &= ~(1 << LPC_SCB_PRESETCTRL_SSP1_RST_N); lpc_scb.presetctrl |= (1 << LPC_SCB_PRESETCTRL_SSP1_RST_N); ao_spi_channel_init(1); - - /* Configure NVIC */ - lpc_nvic_set_enable(LPC_ISR_SSP1_POS); - lpc_nvic_set_priority(LPC_ISR_SSP1_POS, 0); - #endif /* HAS_SPI_1 */ } -- cgit v1.2.3