Skip to content

Commit

Permalink
cpu/uart: make use of named return values
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Oct 28, 2016
1 parent 3145490 commit 2eebf36
Show file tree
Hide file tree
Showing 21 changed files with 79 additions and 77 deletions.
4 changes: 2 additions & 2 deletions cpu/atmega_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
{
/* make sure the given device is valid */
if (uart >= UART_NUMOF) {
return -1;
return UART_NODEV;
}

/* register interrupt context */
Expand All @@ -132,7 +132,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
/* enable RX and TX and the RX interrupt */
dev[uart]->CSRB = ((1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0));

return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
11 changes: 6 additions & 5 deletions cpu/cc2538/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
{
/* initialize basic functionality */
int res = init_base(uart, baudrate);

if (res != 0) {
if (res != UART_OK) {
return res;
}

Expand All @@ -183,9 +182,11 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
NVIC_EnableIRQ(UART1_IRQn);
break;
#endif
default:
return UART_NODEV;
}

return 0;
return UART_OK;
}

static int init_base(uart_t uart, uint32_t baudrate)
Expand Down Expand Up @@ -240,7 +241,7 @@ static int init_base(uart_t uart, uint32_t baudrate)

default:
(void)u;
return -1;
return UART_NODEV;
}

#if UART_0_EN || UART_1_EN
Expand Down Expand Up @@ -313,7 +314,7 @@ static int init_base(uart_t uart, uint32_t baudrate)
/* UART Enable */
u->cc2538_uart_ctl.CTLbits.UARTEN = 1;

return 0;
return UART_OK;
#endif /* UART_0_EN || UART_1_EN */
}

Expand Down
4 changes: 2 additions & 2 deletions cpu/cc26x0/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
{
/* make sure the uart device is valid */
if (uart != 0) {
return -1;
return UART_NODEV;
}

/* enable clocks: serial power domain and UART */
Expand Down Expand Up @@ -89,7 +89,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
/* start the UART */
UART->CTL = ENABLE_MASK;

return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
4 changes: 2 additions & 2 deletions cpu/ezr32wg/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)

/* check if device is valid and get base register address */
if (dev >= UART_NUMOF) {
return -1;
return UART_NODEV;
}
uart = _uart(dev);

Expand Down Expand Up @@ -77,7 +77,7 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
uart->IEN |= USART_IEN_RXDATAV;
/* enable receiver and transmitter */
uart->CMD = USART_CMD_TXEN | USART_CMD_RXEN;
return 0;
return UART_OK;
}

void uart_write(uart_t dev, const uint8_t *data, size_t len)
Expand Down
12 changes: 5 additions & 7 deletions cpu/kinetis_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
{
/* do basic initialization */
int res = init_base(uart, baudrate);

if (res < 0) {
if (res != UART_OK) {
return res;
}

Expand Down Expand Up @@ -88,11 +87,10 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
#endif

default:
return -2;
break;
return UART_NODEV;
}

return 0;
return UART_OK;
}

static int init_base(uart_t uart, uint32_t baudrate)
Expand Down Expand Up @@ -134,7 +132,7 @@ static int init_base(uart_t uart, uint32_t baudrate)
#endif

default:
return -1;
return UART_NODEV;
}

/* configure RX and TX pins, set pin to use alternative function mode */
Expand Down Expand Up @@ -179,7 +177,7 @@ static int init_base(uart_t uart, uint32_t baudrate)

/* enable transmitter and receiver */
dev->C2 |= UART_C2_TE_MASK | UART_C2_RE_MASK;
return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
10 changes: 6 additions & 4 deletions cpu/lm4f120/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
assert(uart == 0);
/* Check to make sure the UART peripheral is present */
if(!ROM_SysCtlPeripheralPresent(SYSCTL_PERIPH_UART0)){
return -1;
return UART_NODEV;
}

int res = init_base(uart, baudrate);
if(res < 0){
if(res != UART_OK){
return res;
}

Expand Down Expand Up @@ -76,7 +76,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
break;
#endif
}
return 0;
return UART_OK;
}

static int init_base(uart_t uart, uint32_t baudrate)
Expand All @@ -99,8 +99,10 @@ static int init_base(uart_t uart, uint32_t baudrate)
ROM_UARTEnable(UART0_BASE);
break;
#endif
default:
return UART_NODEV;
}
return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
10 changes: 5 additions & 5 deletions cpu/lpc11u34/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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)
{
int res = init_base(uart, baudrate);
if (res < 0) {
if (res != UART_OK) {
return res;
}

Expand All @@ -55,7 +55,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
#endif
}

return 0;
return UART_OK;
}

static int init_base(uart_t uart, uint32_t baudrate)
Expand All @@ -65,7 +65,7 @@ static int init_base(uart_t uart, uint32_t baudrate)
case UART_0:
/* this implementation only supports 115200 baud */
if (baudrate != 115200) {
return -2;
return UART_NOBAUD;
}

/* select and configure the pin for RX */
Expand All @@ -91,10 +91,10 @@ static int init_base(uart_t uart, uint32_t baudrate)
break;
#endif
default:
return -1;
return UART_NODEV;
}

return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
12 changes: 6 additions & 6 deletions cpu/lpc1768/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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)
{
int res = init_base(uart, baudrate);
if (res < 0) {
if (res != UART_OK) {
return res;
}

Expand Down Expand Up @@ -64,7 +64,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
#endif
}

return 0;
return UART_OK;
}

static int init_base(uart_t uart, uint32_t baudrate)
Expand All @@ -74,7 +74,7 @@ static int init_base(uart_t uart, uint32_t baudrate)
case UART_0:
/* this implementation only supports 115200 baud */
if (baudrate != 115200) {
return -2;
return UART_NOBAUD;
}

/* power on UART device and select peripheral clock */
Expand Down Expand Up @@ -105,7 +105,7 @@ static int init_base(uart_t uart, uint32_t baudrate)
case UART_1:
/* this implementation only supports 115200 baud */
if (baudrate != 115200) {
return -2;
return UART_NOBAUD;
}

/* power on UART device and select peripheral clock */
Expand Down Expand Up @@ -133,10 +133,10 @@ static int init_base(uart_t uart, uint32_t baudrate)
break;
#endif
default:
return -1;
return UART_NODEV;
}

return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
4 changes: 2 additions & 2 deletions cpu/lpc2387/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
(void) baudrate;
/* for now, we only support one UART device and only the RX interrupt */
if (dev != 0) {
return -1;
return UART_NODEV;
}

/* save interrupt context */
Expand All @@ -66,7 +66,7 @@ int uart_init(uart_t dev, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
/* install and enable the IRQ handler */
install_irq(UART0_INT, UART0_IRQHandler, 6);
U0IER |= BIT0; /* enable only RX irq */
return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
11 changes: 6 additions & 5 deletions cpu/msp430fxyz/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ 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)
{
if (init_base(uart, baudrate) < 0) {
return -1;
int res = init_base(uart, baudrate);
if (res != UART_OK) {
return res;
}

/* save interrupt context */
Expand All @@ -50,13 +51,13 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
UART_IF &= ~(UART_IE_RX_BIT);
UART_IF |= (UART_IE_TX_BIT);
UART_IE |= (UART_IE_RX_BIT);
return 0;
return UART_OK;
}

static int init_base(uart_t uart, uint32_t baudrate)
{
if (uart != 0) {
return -1;
return UART_NODEV;
}

/* get the default UART for now -> TODO: enable for multiple devices */
Expand Down Expand Up @@ -85,7 +86,7 @@ static int init_base(uart_t uart, uint32_t baudrate)
uart_poweron(uart);
/* and finally release the software reset bit */
dev->CTL &= ~(USART_CTL_SWRST);
return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
8 changes: 4 additions & 4 deletions cpu/native/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ static void io_signal_handler(int fd, void *arg)
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
{
if (uart >= UART_NUMOF) {
return -1;
return UART_NODEV;
}

struct termios termios;
Expand Down Expand Up @@ -133,7 +133,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
case 115200: speed = B115200; break;
case 230400: speed = B230400 ; break;
default:
return -1;
return UART_NOBAUD;
break;
}

Expand All @@ -143,7 +143,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
tty_fds[uart] = real_open(tty_device_filenames[uart], O_RDWR | O_NONBLOCK);

if (tty_fds[uart] < 0) {
return -3;
return UART_INTERR;
}

tcsetattr(tty_fds[uart], TCSANOW, &termios);
Expand All @@ -154,7 +154,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
native_async_read_setup();
native_async_read_add_handler(tty_fds[uart], NULL, io_signal_handler);

return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
6 changes: 3 additions & 3 deletions cpu/nrf5x_common/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static uart_isr_ctx_t uart_config;
int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
{
if (uart != 0) {
return -1;
return UART_NODEV;
}

/* remember callback addresses and argument */
Expand Down Expand Up @@ -122,7 +122,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
NRF_UART0->BAUDRATE = UART_BAUDRATE_BAUDRATE_Baud921600;
break;
default:
return -2;
return UART_NOBAUD;
}

/* enable the UART device */
Expand All @@ -133,7 +133,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
/* enable global and receiving interrupt */
NVIC_EnableIRQ(UART_IRQN);
NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Msk;
return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
4 changes: 2 additions & 2 deletions cpu/sam3/periph/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)

/* make sure given device is valid */
if (uart >= UART_NUMOF) {
return -1;
return UART_NODEV;
}

/* get base register */
Expand Down Expand Up @@ -71,7 +71,7 @@ int uart_init(uart_t uart, uint32_t baudrate, uart_rx_cb_t rx_cb, void *arg)
NVIC_EnableIRQ(uart_config[uart].irqn);
dev->UART_IER = UART_IER_RXRDY;

return 0;
return UART_OK;
}

void uart_write(uart_t uart, const uint8_t *data, size_t len)
Expand Down
Loading

0 comments on commit 2eebf36

Please sign in to comment.