1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

drivers/at: make at_dev_init() return uart initialize status

in case there's an error uart_init() returns an error value,
this value indicates the reason for the error thus we should
return it from at_dev_init() so the user will be able to identify
whether the init succeded or failed.
This commit is contained in:
Ran Berant 2019-01-20 00:16:53 +02:00
parent f91f62155d
commit 59416fc6ce
3 changed files with 16 additions and 7 deletions

View File

@ -31,10 +31,9 @@ int at_dev_init(at_dev_t *dev, uart_t uart, uint32_t baudrate, char *buf, size_t
{
dev->uart = uart;
isrpipe_init(&dev->isrpipe, buf, bufsize);
uart_init(uart, baudrate, _isrpipe_write_one_wrapper,
&dev->isrpipe);
return 0;
return uart_init(uart, baudrate, _isrpipe_write_one_wrapper,
&dev->isrpipe);
}
int at_expect_bytes(at_dev_t *dev, const char *bytes, uint32_t timeout)

View File

@ -124,8 +124,8 @@ typedef struct {
* @param[in] buf input buffer
* @param[in] bufsize size of @p buf
*
* @returns 0 on success
* @returns <0 otherwise
* @returns success code UART_OK on success
* @returns error code UART_NODEV or UART_NOBAUD otherwise
*/
int at_dev_init(at_dev_t *dev, uart_t uart, uint32_t baudrate, char *buf, size_t bufsize);

View File

@ -47,9 +47,19 @@ static int init(int argc, char **argv)
uint8_t uart = atoi(argv[1]);
uint32_t baudrate = atoi(argv[2]);
at_dev_init(&at_dev, UART_DEV(uart), baudrate, buf, sizeof(buf));
int res = at_dev_init(&at_dev, UART_DEV(uart), baudrate, buf, sizeof(buf));
return 0;
/* check the UART initialization return value and respond as needed */
if (res == UART_NODEV) {
puts("Invalid UART device given!");
return 1;
}
else if (res == UART_NOBAUD) {
puts("Baudrate is not applicable!");
return 1;
}
return res;
}
static int send(int argc, char **argv)