2015-06-04 11:50:03 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 INRIA
|
|
|
|
* 2015 Kaspar Schleiser <kaspar@schleiser.de>
|
2016-07-11 06:33:55 +02:00
|
|
|
* 2016 Eistec AB
|
2018-07-05 14:04:17 +02:00
|
|
|
* 2018 Freie Universität Berlin
|
2015-06-04 11:50:03 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-07-05 14:04:17 +02:00
|
|
|
* @ingroup sys
|
2015-06-04 11:50:03 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
2018-07-05 14:04:17 +02:00
|
|
|
* @brief STDIO over UART implementation
|
2015-06-04 11:50:03 +02:00
|
|
|
*
|
2018-07-05 14:04:17 +02:00
|
|
|
* This file implements a UART callback and the STDIO read/write functions
|
2015-06-04 11:50:03 +02:00
|
|
|
*
|
|
|
|
* @author Oliver Hahm <oliver.hahm@inria.fr>
|
2015-09-27 18:58:30 +02:00
|
|
|
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
|
2015-06-04 11:50:03 +02:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2016-07-11 06:33:55 +02:00
|
|
|
* @author Joakim Nohlgård <joakim.nohlgard@eistec.se>
|
2018-07-05 14:04:17 +02:00
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2015-06-04 11:50:03 +02:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2017-11-09 10:03:06 +01:00
|
|
|
#include <errno.h>
|
|
|
|
|
2018-07-05 14:04:17 +02:00
|
|
|
#include "stdio_uart.h"
|
2015-06-04 11:50:03 +02:00
|
|
|
|
|
|
|
#include "board.h"
|
2015-06-04 13:42:37 +02:00
|
|
|
#include "periph/uart.h"
|
2016-12-07 20:33:23 +01:00
|
|
|
#include "isrpipe.h"
|
2015-06-04 11:50:03 +02:00
|
|
|
|
2016-07-11 06:33:55 +02:00
|
|
|
#if MODULE_VFS
|
|
|
|
#include "vfs.h"
|
|
|
|
#endif
|
|
|
|
|
2015-06-04 11:50:03 +02:00
|
|
|
#define ENABLE_DEBUG 0
|
|
|
|
#include "debug.h"
|
|
|
|
|
2017-11-09 10:03:06 +01:00
|
|
|
#ifdef MODULE_STDIO_UART_RX
|
2019-06-05 18:04:17 +02:00
|
|
|
static uint8_t _rx_buf_mem[STDIO_UART_RX_BUFSIZE];
|
2018-07-05 14:04:17 +02:00
|
|
|
isrpipe_t stdio_uart_isrpipe = ISRPIPE_INIT(_rx_buf_mem);
|
2017-11-09 10:03:06 +01:00
|
|
|
#endif
|
2015-06-04 11:50:03 +02:00
|
|
|
|
2018-07-05 14:04:17 +02:00
|
|
|
void stdio_init(void)
|
2015-06-04 11:50:03 +02:00
|
|
|
{
|
2017-11-09 10:03:06 +01:00
|
|
|
uart_rx_cb_t cb;
|
|
|
|
void *arg;
|
|
|
|
|
|
|
|
#ifdef MODULE_STDIO_UART_RX
|
|
|
|
cb = (uart_rx_cb_t) isrpipe_write_one;
|
|
|
|
arg = &stdio_uart_isrpipe;
|
|
|
|
#else
|
|
|
|
cb = NULL;
|
|
|
|
arg = NULL;
|
|
|
|
#endif
|
|
|
|
|
2019-06-06 13:34:34 +02:00
|
|
|
uart_init(STDIO_UART_DEV, STDIO_UART_BAUDRATE, cb, arg);
|
|
|
|
|
2016-07-11 06:33:55 +02:00
|
|
|
#if MODULE_VFS
|
2018-08-16 18:09:27 +02:00
|
|
|
vfs_bind_stdio();
|
2016-07-11 06:33:55 +02:00
|
|
|
#endif
|
2015-06-04 11:50:03 +02:00
|
|
|
}
|
|
|
|
|
2021-12-25 13:09:45 +01:00
|
|
|
#if IS_USED(MODULE_STDIO_AVAILABLE)
|
|
|
|
int stdio_available(void)
|
|
|
|
{
|
|
|
|
return tsrb_avail(&stdio_uart_isrpipe.tsrb);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-07-05 14:04:17 +02:00
|
|
|
ssize_t stdio_read(void* buffer, size_t count)
|
2015-06-04 11:50:03 +02:00
|
|
|
{
|
2017-11-09 10:03:06 +01:00
|
|
|
#ifdef MODULE_STDIO_UART_RX
|
2019-06-05 18:04:17 +02:00
|
|
|
return (ssize_t)isrpipe_read(&stdio_uart_isrpipe, buffer, count);
|
2017-11-09 10:03:06 +01:00
|
|
|
#else
|
|
|
|
(void)buffer;
|
|
|
|
(void)count;
|
|
|
|
return -ENOTSUP;
|
|
|
|
#endif
|
2015-06-04 11:50:03 +02:00
|
|
|
}
|
|
|
|
|
2018-07-05 14:04:17 +02:00
|
|
|
ssize_t stdio_write(const void* buffer, size_t len)
|
2015-06-04 11:50:03 +02:00
|
|
|
{
|
2019-06-06 13:34:34 +02:00
|
|
|
uart_write(STDIO_UART_DEV, (const uint8_t *)buffer, len);
|
2015-06-04 11:50:03 +02:00
|
|
|
return len;
|
|
|
|
}
|