|
|
|
@ -27,9 +27,6 @@
|
|
|
|
|
#include "periph/uart.h"
|
|
|
|
|
#include "periph_conf.h"
|
|
|
|
|
|
|
|
|
|
/* guard file in case no UART device was specified */
|
|
|
|
|
#if UART_NUMOF
|
|
|
|
|
|
|
|
|
|
#undef BIT
|
|
|
|
|
#define BIT(n) ( 1 << (n) )
|
|
|
|
|
|
|
|
|
@ -68,19 +65,10 @@ enum {
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Each UART device has to store two callbacks.
|
|
|
|
|
*/
|
|
|
|
|
typedef struct {
|
|
|
|
|
uart_rx_cb_t rx_cb;
|
|
|
|
|
uart_tx_cb_t tx_cb;
|
|
|
|
|
void *arg;
|
|
|
|
|
} uart_conf_t;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Allocate memory to store the callback functions.
|
|
|
|
|
*/
|
|
|
|
|
static uart_conf_t uart_config[UART_NUMOF];
|
|
|
|
|
static uart_isr_ctx_t uart_config[UART_NUMOF];
|
|
|
|
|
|
|
|
|
|
cc2538_uart_t * const UART0 = (cc2538_uart_t *)0x4000c000;
|
|
|
|
|
cc2538_uart_t * const UART1 = (cc2538_uart_t *)0x4000d000;
|
|
|
|
@ -161,10 +149,12 @@ void UART_1_ISR(void)
|
|
|
|
|
}
|
|
|
|
|
#endif /* UART_1_EN */
|
|
|
|
|
|
|
|
|
|
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, uart_tx_cb_t tx_cb, void *arg)
|
|
|
|
|
static int init_base(uart_t uart, uint32_t baudrate);
|
|
|
|
|
|
|
|
|
|
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
|
|
|
|
|
{
|
|
|
|
|
/* initialize basic functionality */
|
|
|
|
|
int res = uart_init_blocking(uart, baudrate);
|
|
|
|
|
int res = init_base(uart, baudrate);
|
|
|
|
|
|
|
|
|
|
if (res != 0) {
|
|
|
|
|
return res;
|
|
|
|
@ -172,7 +162,6 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, uart_tx_cb_t t
|
|
|
|
|
|
|
|
|
|
/* register callbacks */
|
|
|
|
|
uart_config[uart].rx_cb = rx_cb;
|
|
|
|
|
uart_config[uart].tx_cb = tx_cb;
|
|
|
|
|
uart_config[uart].arg = arg;
|
|
|
|
|
|
|
|
|
|
/* configure interrupts and enable RX interrupt */
|
|
|
|
@ -194,9 +183,9 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, uart_tx_cb_t t
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int uart_init_blocking(uart_t uart, uint32_t baudrate)
|
|
|
|
|
static int init_base(uart_t uart, uint32_t baudrate)
|
|
|
|
|
{
|
|
|
|
|
cc2538_uart_t *u;
|
|
|
|
|
cc2538_uart_t *u = NULL;
|
|
|
|
|
|
|
|
|
|
switch (uart) {
|
|
|
|
|
#if UART_0_EN
|
|
|
|
@ -326,17 +315,7 @@ int uart_init_blocking(uart_t uart, uint32_t baudrate)
|
|
|
|
|
#endif /* UART_0_EN || UART_1_EN */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uart_tx_begin(uart_t uart)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uart_tx_end(uart_t uart)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int uart_write(uart_t uart, char data)
|
|
|
|
|
void uart_write(uart_t uart, const uint8_t *data, size_t len)
|
|
|
|
|
{
|
|
|
|
|
cc2538_uart_t *u;
|
|
|
|
|
|
|
|
|
@ -351,73 +330,15 @@ int uart_write(uart_t uart, char data)
|
|
|
|
|
u = UART_1_DEV;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (u->FRbits.TXFF) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u->DR = data;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int uart_read_blocking(uart_t uart, char *data)
|
|
|
|
|
{
|
|
|
|
|
cc2538_uart_t *u;
|
|
|
|
|
|
|
|
|
|
switch (uart) {
|
|
|
|
|
#if UART_0_EN
|
|
|
|
|
case UART_0:
|
|
|
|
|
u = UART_0_DEV;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
#if UART_1_EN
|
|
|
|
|
case UART_1:
|
|
|
|
|
u = UART_1_DEV;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (u->FRbits.RXFE);
|
|
|
|
|
|
|
|
|
|
*data = u->DR;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int uart_write_blocking(uart_t uart, char data)
|
|
|
|
|
{
|
|
|
|
|
cc2538_uart_t *u;
|
|
|
|
|
|
|
|
|
|
switch (uart) {
|
|
|
|
|
#if UART_0_EN
|
|
|
|
|
case UART_0:
|
|
|
|
|
u = UART_0_DEV;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
#if UART_1_EN
|
|
|
|
|
case UART_1:
|
|
|
|
|
u = UART_1_DEV;
|
|
|
|
|
break;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Block if the TX FIFO is full */
|
|
|
|
|
while (u->FRbits.TXFF);
|
|
|
|
|
|
|
|
|
|
u->DR = data;
|
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
|
while (u->FRbits.TXFF);
|
|
|
|
|
u->DR = data[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uart_poweron(uart_t uart)
|
|
|
|
@ -429,5 +350,3 @@ void uart_poweroff(uart_t uart)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* UART_NUMOF */
|
|
|
|
|