cpu/lpc2387: adapted UART driver

This commit is contained in:
Hauke Petersen 2015-10-20 16:27:05 +02:00
parent 68670f038f
commit fe249b9006

View File

@ -31,14 +31,11 @@
/* for now, we only support one UART device... */ /* for now, we only support one UART device... */
static uart_rx_cb_t _rx_cb; static uart_rx_cb_t _rx_cb;
static uart_tx_cb_t _tx_cb;
static void * _cb_arg; static void * _cb_arg;
void UART0_IRQHandler(void) __attribute__((interrupt("IRQ"))); void UART0_IRQHandler(void) __attribute__((interrupt("IRQ")));
int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
int uart_init(uart_t dev, uint32_t baudrate,
uart_rx_cb_t rx_cb, uart_tx_cb_t tx_cb, void *arg)
{ {
/* for now, we only support one UART device and only the RX interrupt */ /* for now, we only support one UART device and only the RX interrupt */
if (dev != 0) { if (dev != 0) {
@ -47,7 +44,6 @@ int uart_init(uart_t dev, uint32_t baudrate,
/* save interrupt context */ /* save interrupt context */
_rx_cb = rx_cb; _rx_cb = rx_cb;
_tx_cb = tx_cb;
_cb_arg = arg; _cb_arg = arg;
/* power on the UART device */ /* power on the UART device */
@ -73,39 +69,17 @@ int uart_init(uart_t dev, uint32_t baudrate,
return 0; return 0;
} }
void uart_tx_begin(uart_t uart) void uart_write(uart_t uart, const uint8_t *data, size_t len)
{ {
(void)uart; for (size_t i = 0; i < len; i++) {
while (!(U0LSR & BIT5));
/* enable THRE interrupt */ U0THR = data[i];
U0IER |= BIT1; }
}
int uart_write(uart_t uart, char c)
{
(void)uart;
U0THR = (char)c;
return 1;
}
int uart_write_blocking(uart_t dev, char c)
{
while (!(U0LSR & BIT5));
U0THR = (char)c;
return 1;
} }
void UART0_IRQHandler(void) void UART0_IRQHandler(void)
{ {
switch (U0IIR & UIIR_ID_MASK) { switch (U0IIR & UIIR_ID_MASK) {
case UIIR_THRE_INT: /* Transmit Holding Register Empty */
if (_tx_cb(_cb_arg) == 0) {
U0IER &= ~BIT1; /* clear TX interrupt */
}
break;
case UIIR_CTI_INT: /* Character Timeout Indicator */ case UIIR_CTI_INT: /* Character Timeout Indicator */
case UIIR_RDA_INT: /* Receive Data Available */ case UIIR_RDA_INT: /* Receive Data Available */
do { do {