cpu/cc2538: adapted UART driver
This commit is contained in:
parent
1125f5feb3
commit
a58d577cb1
@ -27,9 +27,6 @@
|
|||||||
#include "periph/uart.h"
|
#include "periph/uart.h"
|
||||||
#include "periph_conf.h"
|
#include "periph_conf.h"
|
||||||
|
|
||||||
/* guard file in case no UART device was specified */
|
|
||||||
#if UART_NUMOF
|
|
||||||
|
|
||||||
#undef BIT
|
#undef BIT
|
||||||
#define BIT(n) ( 1 << (n) )
|
#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.
|
* @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 UART0 = (cc2538_uart_t *)0x4000c000;
|
||||||
cc2538_uart_t * const UART1 = (cc2538_uart_t *)0x4000d000;
|
cc2538_uart_t * const UART1 = (cc2538_uart_t *)0x4000d000;
|
||||||
@ -161,10 +149,12 @@ void UART_1_ISR(void)
|
|||||||
}
|
}
|
||||||
#endif /* UART_1_EN */
|
#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 */
|
/* initialize basic functionality */
|
||||||
int res = uart_init_blocking(uart, baudrate);
|
int res = init_base(uart, baudrate);
|
||||||
|
|
||||||
if (res != 0) {
|
if (res != 0) {
|
||||||
return res;
|
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 */
|
/* register callbacks */
|
||||||
uart_config[uart].rx_cb = rx_cb;
|
uart_config[uart].rx_cb = rx_cb;
|
||||||
uart_config[uart].tx_cb = tx_cb;
|
|
||||||
uart_config[uart].arg = arg;
|
uart_config[uart].arg = arg;
|
||||||
|
|
||||||
/* configure interrupts and enable RX interrupt */
|
/* 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;
|
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) {
|
switch (uart) {
|
||||||
#if UART_0_EN
|
#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 */
|
#endif /* UART_0_EN || UART_1_EN */
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart_tx_begin(uart_t uart)
|
void uart_write(uart_t uart, const uint8_t *data, size_t len)
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void uart_tx_end(uart_t uart)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
int uart_write(uart_t uart, char data)
|
|
||||||
{
|
{
|
||||||
cc2538_uart_t *u;
|
cc2538_uart_t *u;
|
||||||
|
|
||||||
@ -351,73 +330,15 @@ int uart_write(uart_t uart, char data)
|
|||||||
u = UART_1_DEV;
|
u = UART_1_DEV;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return -1;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Block if the TX FIFO is full */
|
/* Block if the TX FIFO is full */
|
||||||
|
for (size_t i = 0; i < len; i++) {
|
||||||
while (u->FRbits.TXFF);
|
while (u->FRbits.TXFF);
|
||||||
|
u->DR = data[i];
|
||||||
u->DR = data;
|
}
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart_poweron(uart_t uart)
|
void uart_poweron(uart_t uart)
|
||||||
@ -429,5 +350,3 @@ void uart_poweroff(uart_t uart)
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* UART_NUMOF */
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user