Merge pull request #3164 from kaspar030/remove_uart0

sys: remove uart0
dev/timer
Hauke Petersen 8 years ago
commit 7701aed546

@ -205,10 +205,6 @@ ifneq (,$(filter newlib,$(USEMODULE)))
USEMODULE += uart_stdio
endif
ifneq (,$(filter uart0,$(USEMODULE)))
USEMODULE += posix
endif
ifneq (,$(filter posix,$(USEMODULE)))
USEMODULE += timex
USEMODULE += vtimer

@ -34,8 +34,8 @@ extern "C" {
* @{
*/
#define STDIO UART_0
#define STDIO_BAUDRATE 115200
#define STDIO_RX_BUFSIZE UART0_BUFSIZE
#define STDIO_BAUDRATE (115200U)
#define STDIO_RX_BUFSIZE (64U)
/** @} */
/**

@ -1,22 +0,0 @@
/*
* Copyright 2014 Kaspar Schleiser <kaspar@schleiser.de>
*
* 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.
*/
#ifndef UART0_H_
#define UART0_H_
#ifdef __cplusplus
extern "C" {
#endif
extern kernel_pid_t uart0_handler_pid;
#ifdef __cplusplus
}
#endif
#endif /* UART0_H */

@ -1,325 +0,0 @@
/**
* Native uart0 implementation
*
* Copyright (C) 2014 Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
*
* 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.
*
* @ingroup native_board
* @{
* @file
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
* @}
*/
#include <err.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include "cpu.h"
#include "board_uart0.h"
#include "thread.h"
#include "native_internal.h"
#include "board_internal.h"
#define ENABLE_DEBUG (0)
#include "debug.h"
int _native_uart_sock;
int _native_uart_conn;
int _native_replay_enabled;
FILE *_native_replay_buffer;
fd_set _native_uart_rfds;
/* uart API */
int uart0_puts(char *astring, int length)
{
int nwritten, offset;
nwritten = 0;
offset = 0;
while (
(length - offset > 0) && (
(nwritten = _native_write(
STDOUT_FILENO,
astring+offset,
length-offset)
) > 0)
) {
offset += nwritten;
}
if (nwritten == -1) {
err(EXIT_FAILURE, "uart0_puts: write");
}
else if ((length > 0) && (nwritten == 0)) {
/* XXX: handle properly */
errx(EXIT_FAILURE, "uart0_puts: Could not write to stdout. I don't know what to do now.");
}
return length;
}
/* internal */
void *get_in_addr(struct sockaddr *sa)
{
if (sa->sa_family == AF_INET) {
return &(((struct sockaddr_in*)sa)->sin_addr);
}
return &(((struct sockaddr_in6*)sa)->sin6_addr);
}
#ifndef UART_TCPPORT
#define UART_TCPPORT "4711"
#endif
int init_tcp_socket(char *tcpport)
{
struct addrinfo hints, *info, *p;
int i, s = -1;
if (tcpport == NULL) {
tcpport = UART_TCPPORT;
}
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
hints.ai_flags = AI_PASSIVE;
if ((i = real_getaddrinfo(NULL, tcpport, &hints, &info)) != 0) {
errx(EXIT_FAILURE,
"init_uart_socket: getaddrinfo: %s", real_gai_strerror(i));
}
for (p = info; p != NULL; p = p->ai_next) {
if ((s = real_socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
warn("init_uart_socket: socket");
continue;
}
i = 1;
if (real_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(int)) == -1) {
err(EXIT_FAILURE, "init_uart_socket: setsockopt");
}
if (real_bind(s, p->ai_addr, p->ai_addrlen) == -1) {
real_close(s);
warn("init_uart_socket: bind");
continue;
}
break;
}
if (p == NULL) {
errx(EXIT_FAILURE, "init_uart_socket: failed to bind\n");
}
real_freeaddrinfo(info);
if (real_listen(s, 1) == -1) {
err(EXIT_FAILURE, "init_uart_socket: listen");
}
return s;
}
int init_unix_socket(void)
{
int s;
struct sockaddr_un sa;
if ((s = real_socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
err(EXIT_FAILURE, "init_unix_socket: socket");
}
sa.sun_family = AF_UNIX;
if (_native_unix_socket_path != NULL) {
snprintf(sa.sun_path, sizeof(sa.sun_path), "%s", _native_unix_socket_path);
}
else {
snprintf(sa.sun_path, sizeof(sa.sun_path), "/tmp/riot.tty.%d", _native_pid);
}
real_unlink(sa.sun_path); /* remove stale socket */
if (real_bind(s, (struct sockaddr *)&sa, SUN_LEN(&sa)) == -1) {
err(EXIT_FAILURE, "init_unix_socket: bind");
}
if (real_listen(s, 5) == -1) {
err(EXIT_FAILURE, "init_unix_socket: listen");
}
return s;
}
void handle_uart_in(void)
{
char buf[42];
int nread;
DEBUG("handle_uart_in\n");
nread = _native_read(STDIN_FILENO, buf, sizeof(buf));
if (nread == -1) {
err(EXIT_FAILURE, "handle_uart_in(): read()");
}
else if (nread == 0) {
/* end of file / socket closed */
if (_native_uart_conn != 0) {
if (_native_null_out_file != -1) {
if (real_dup2(_native_null_out_file, STDOUT_FILENO) == -1) {
err(EXIT_FAILURE, "handle_uart_in: dup2(STDOUT_FILENO)");
}
}
if (real_dup2(_native_null_in_pipe[0], STDIN_FILENO) == -1) {
err(EXIT_FAILURE, "handle_uart_in: dup2(STDIN_FILENO)");
}
_native_uart_conn = 0;
warnx("closed stdio");
}
else {
errx(EXIT_FAILURE, "handle_uart_in: unhandled situation!");
}
}
for (int pos = 0; pos < nread; pos++) {
uart0_handle_incoming(buf[pos]);
}
uart0_notify_thread();
thread_yield();
}
void handle_uart_sock(void)
{
int s;
socklen_t t;
struct sockaddr remote;
t = sizeof(remote);
_native_syscall_enter();
if ((s = real_accept(_native_uart_sock, &remote, &t)) == -1) {
err(EXIT_FAILURE, "handle_uart_sock: accept");
}
else {
warnx("handle_uart_sock: successfully accepted socket");
}
if (real_dup2(s, STDOUT_FILENO) == -1) {
err(EXIT_FAILURE, "handle_uart_sock: dup2()");
}
if (real_dup2(s, STDIN_FILENO) == -1) {
err(EXIT_FAILURE, "handle_uart_sock: dup2()");
}
/* play back log from last position */
if (_native_replay_enabled) {
warnx("handle_uart_sock: replaying buffer");
size_t nread;
char buf[200];
while ((nread = real_fread(buf, 1, sizeof(buf), _native_replay_buffer)) != 0) {
int nwritten;
int pos = 0;
while ((nwritten = real_write(STDOUT_FILENO, &buf[pos], nread)) != -1) {
nread -= nwritten;
pos += nwritten;
if (nread == 0) {
break;
}
}
if (nwritten == -1) {
err(EXIT_FAILURE, "handle_uart_sock: write");
}
}
if (real_feof(_native_replay_buffer) != 0) {
real_clearerr(_native_replay_buffer);
}
else if (real_ferror(_native_replay_buffer) != 0) {
err(EXIT_FAILURE, "handle_uart_sock(): fread()");
}
}
_native_syscall_leave();
_native_uart_conn = s;
}
#ifdef MODULE_UART0
void _native_handle_uart0_input(void)
{
if (FD_ISSET(STDIN_FILENO, &_native_rfds)) {
handle_uart_in();
}
else if ((_native_uart_sock != -1) && (FD_ISSET(_native_uart_sock, &_native_rfds))) {
handle_uart_sock();
}
else {
DEBUG("_native_handle_uart0_input - nothing to do\n");
}
}
int _native_set_uart_fds(void)
{
DEBUG("_native_set_uart_fds\n");
FD_SET(STDIN_FILENO, &_native_rfds);
if (_native_uart_sock == -1) {
return (STDIN_FILENO);
}
else {
FD_SET(_native_uart_sock, &_native_rfds);
return ((STDIN_FILENO > _native_uart_sock) ? STDIN_FILENO : _native_uart_sock);
}
}
#endif
void _native_init_uart0(char *stdiotype, char *ioparam, int replay)
{
_native_replay_enabled = replay;
if (_native_replay_enabled) {
char stdout_logname[255];
snprintf(stdout_logname, sizeof(stdout_logname), "/tmp/riot.stdout.%d", _native_pid);
if ((_native_replay_buffer = real_fopen(stdout_logname, "r+")) == NULL) {
err(EXIT_FAILURE, "_native_init_uart0: fdopen(_native_null_out_file)");
}
}
if (strcmp(stdiotype, "tcp") == 0) {
_native_uart_sock = init_tcp_socket(ioparam);
}
else if (strcmp(stdiotype, "unix") == 0) {
_native_uart_sock = init_unix_socket();
}
else if (strcmp(stdiotype, "stdio") == 0) {
_native_uart_sock = -1;
_native_uart_conn = 1;
}
else if (strcmp(stdiotype, "null") == 0) {
_native_uart_sock = -1;
_native_uart_conn = 0;
}
else {
errx(EXIT_FAILURE, "_native_init_uart0: unknown stdio type");
}
puts("RIOT native uart0 initialized.");
}

@ -13,19 +13,6 @@
extern "C" {
#endif
#ifdef MODULE_UART0
#include <sys/select.h>
void _native_handle_uart0_input(void);
/**
* @brief: initialize uart0
*
* @param stdiotype: "stdio", "tcp", "udp" io redirection
* @param ioparam: a string containing a port number if stdiotype is tcp
*/
void _native_init_uart0(char *stdiotype, char *ioparam, int replay);
int _native_set_uart_fds(void);
#endif /* MODULE_UART0 */
extern int _native_null_out_file;
extern int _native_null_in_pipe[2];
void board_init(void);

@ -31,8 +31,6 @@ extern "C" {
#define THREAD_EXTRA_STACKSIZE_PRINTF_FLOAT (8192)
#define THREAD_STACKSIZE_MINIMUM (8192)
#define UART0_BUFSIZE (16)
#define F_CPU (1000000) /* This value is unused in x86 */
#ifdef __cplusplus

@ -27,18 +27,6 @@ uint32_t get_system_speed(void);
void cpu_clock_scale(uint32_t source, uint32_t target, uint32_t *prescale);
void arm_reset(void);
void stdio_flush(void);
/**
* @brief Writes an array of characters to the UART0 device
*
* @param[in] astring The string to write
* @param[in] length Length of the string
*
* @returns Always @p length
*/
int uart0_puts(char *astring, int length);
#ifdef __cplusplus
}

@ -40,17 +40,6 @@ extern "C" {
#define THREAD_STACKSIZE_IDLE (128)
/** @} */
/**
* @name UART0 buffer size definition for compatibility reasons
*
* TODO: remove once the remodeling of the uart0 driver is done
* @{
*/
#ifndef UART0_BUFSIZE
#define UART0_BUFSIZE (128)
#endif
/** @} */
#ifdef __cplusplus
}
#endif

@ -62,17 +62,6 @@ extern "C" {
#endif
/** @} */
/**
* @brief UART0 buffer size definition for compatibility reasons
*
* @todo remove once the remodeling of the uart0 driver is done
* @{
*/
#ifndef UART0_BUFSIZE
#define UART0_BUFSIZE (128)
#endif
/** @} */
/**
* @brief Deprecated interrupt control function for backward compatibility
* @{

@ -63,17 +63,6 @@ extern "C" {
#define CC_CONF_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
/** @} */
/**
* @name UART0 buffer size definition for compatibility reasons
*
* TODO: remove once the remodeling of the uart0 driver is done
* @{
*/
#ifndef UART0_BUFSIZE
#define UART0_BUFSIZE (128)
#endif
/** @} */
#ifdef __cplusplus
}
#endif

@ -27,10 +27,6 @@ extern "C" {
#define THREAD_STACKSIZE_IDLE (96)
#define MSP430_ISR_STACK_SIZE (256)
#ifndef UART0_BUFSIZE
#define UART0_BUFSIZE (32)
#endif
#ifndef GNRC_PKTBUF_SIZE
#define GNRC_PKTBUF_SIZE (2560) /* TODO: Make this value
* overall MTU dependent */

@ -75,75 +75,6 @@ Usage:
./bin/native/default.elf -d
Use UART redirection if you want to use a shell or get stderr/stdout
output with/from a daemonized process.
UART Redirection
================
You can redirect the processes' stdin/stdout/stderr by specifying
one or more options from below.
UNIX socket
-----------
To redirect stdio to a UNIX socket run:
./bin/native/default.elf -u -d
RIOT pid: 18663
Attach this UNIX socket:
nc -U /tmp/riot.tty.18663
TCP socket
----------
To redirect stdio to a TCP socket:
./bin/native/default.elf -t 4711 -d
RIOT pid: 18663
Attach this TCP socket:
nc localhost 4711
Stop the process:
kill 18663
File for stderr
---------------
To redirect stderr to a file:
./bin/native/default.elf -d -e
RIOT pid: 18663
Read from it:
tail -f /tmp/riot.stderr.18663
File for stdout
---------------
To redirect stdout to a file:
./bin/native/default.elf -d -o
RIOT pid: 18663
Read from it:
tail -f /tmp/riot.stdout.18663
Notes
-----
The stdout redirection only writes to file while no socket connection
is established.
Socket redirection is only available when the UART module has been
compiled in.
Compile Time Options
====================

@ -50,18 +50,6 @@ extern "C" {
#endif /* OS */
/** @} */
/**
* @brief UART0 buffer size definition for compatibility reasons
*
* TODO: remove once the remodeling of the uart0 driver is done
* @{
*/
#ifdef UART0_BUFSIZE
#undef UART0_BUFSIZE
#endif
#define UART0_BUFSIZE (128)
/** @} */
/**
* @brief Native internal Ethernet protocol number
*/

@ -155,11 +155,6 @@ extern unsigned _native_rng_seed;
extern int _native_rng_mode; /**< 0 = /dev/random, 1 = random(3) */
extern const char *_native_unix_socket_path;
#ifdef MODULE_UART0
#include <sys/select.h>
extern fd_set _native_rfds;
#endif
ssize_t _native_read(int fd, void *buf, size_t count);
ssize_t _native_write(int fd, const void *buf, size_t count);
ssize_t _native_writev(int fildes, const struct iovec *iov, int iovcnt);

@ -19,10 +19,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifdef MODULE_UART0
#include <sys/select.h>
#include <errno.h>
#endif
#include <err.h>
#include "lpm.h"
@ -30,9 +26,6 @@
#include "cpu.h"
#include "native_internal.h"
#ifdef MODULE_UART0
#include "board_internal.h"
#endif
static enum lpm_mode native_lpm;
@ -45,45 +38,9 @@ void lpm_init(void)
void _native_lpm_sleep(void)
{
#ifdef MODULE_UART0
int nfds;
/* set fds */
FD_ZERO(&_native_rfds);
nfds = _native_set_uart_fds();
nfds++;
_native_in_syscall++; // no switching here
nfds = real_select(nfds, &_native_rfds, NULL, NULL, NULL);
int _errno = errno;
_native_in_syscall--;
DEBUG("_native_lpm_sleep: returned: %i\n", nfds);
if (nfds != -1) {
/* uart ready, handle input */
/* TODO: switch to ISR context */
_native_handle_uart0_input();
}
else if ((_errno == EAGAIN) || (_errno == EWOULDBLOCK)) {
/* would block / resource unavailable .. it appears a
* contended socket can show this behavior sometimes */
_native_in_syscall++;
warn("_native_lpm_sleep: select()");
_native_in_syscall--;
return;
}
else if (_errno != EINTR) {
/* select failed for reason other than signal */
err(EXIT_FAILURE, "lpm_set(): select()");
}
/* otherwise select was interrupted because of a signal, continue below */
#else
_native_in_syscall++; // no switching here
real_pause();
_native_in_syscall--;
#endif
if (_native_sigpend > 0) {
DEBUG("\n\n\t\treturn from syscall, calling native_irq_handler\n\n");

@ -62,18 +62,11 @@ extern netdev2_tap_t netdev2_tap;
ucontext_t end_context;
char __end_stack[SIGSTKSZ];
#ifdef MODULE_UART0
fd_set _native_rfds;
#endif
int reboot_arch(int mode)
{
(void) mode;
printf("\n\n\t\t!! REBOOT !!\n\n");
#ifdef MODULE_UART0
/* TODO: close stdio fds */
#endif
#ifdef MODULE_NETDEV2_TAP
netdev2_tap_cleanup(&netdev2_tap);

@ -200,10 +200,6 @@ void usage_exit(void)
real_printf(" <tap interface>");
#endif
#ifdef MODULE_UART0
real_printf(" [-t <port>|-u [path]] [-r]");
#endif
real_printf(" [-i <id>] [-d] [-e|-E] [-o]\n");
real_printf(" help: %s -h\n", _progname);
@ -211,14 +207,6 @@ void usage_exit(void)
real_printf("\nOptions:\n\
-h help\n");
#ifdef MODULE_UART0
real_printf("\
-t <port> redirect stdio to TCP socket listening on <port>\n\
-u <path> redirect stdio to UNIX socket (<path> if given,\n\
/tmp/riot.tty.PID otherwise)\n\
-r replay missed output when (re-)attaching to socket\n\
(implies -o)\n");
#endif
real_printf("\
-i <id> specify instance id (set by config module)\n\
-s <seed> specify srandom(3) seed (/dev/random is used instead of\n\
@ -251,10 +239,6 @@ __attribute__((constructor)) static void startup(int argc, char **argv)
char *stderrtype = "stdio";
char *stdouttype = "stdio";
char *stdiotype = "stdio";
#ifdef MODULE_UART0
char *ioparam = NULL;
int replay = 0;
#endif
#if defined(MODULE_NETDEV2_TAP)
if (
@ -313,41 +297,6 @@ __attribute__((constructor)) static void startup(int argc, char **argv)
else if (strcmp("-o", arg) == 0) {
stdouttype = "file";
}
#ifdef MODULE_UART0
else if (strcmp("-r", arg) == 0) {
stdouttype = "file";
replay = 1;
}
else if (strcmp("-t", arg) == 0) {
stdiotype = "tcp";
if (argp + 1 < argc) {
ioparam = argv[++argp];
}
else {
usage_exit();
}
if (strcmp(stdouttype, "stdio") == 0) {
stdouttype = "null";
}
if (strcmp(stderrtype, "stdio") == 0) {
stderrtype = "null";
}
}
else if (strcmp("-u", arg) == 0) {
stdiotype = "unix";
if (strcmp(stdouttype, "stdio") == 0) {
stdouttype = "null";
}
if (strcmp(stderrtype, "stdio") == 0) {
stderrtype = "null";
}
/* parse optional path */
if ((argp + 1 < argc) && (argv[argp + 1][0] != '-')) {
_native_unix_socket_path = argv[++argp];
}
}
#endif
else {
usage_exit();
}
@ -361,10 +310,6 @@ __attribute__((constructor)) static void startup(int argc, char **argv)
_native_log_stdout(stdouttype);
_native_null_in(stdiotype);
#ifdef MODULE_UART0
_native_init_uart0(stdiotype, ioparam, replay);
#endif
native_cpu_init();
native_interrupt_init();
#ifdef MODULE_NETDEV2_TAP

@ -33,7 +33,6 @@
#include "x86_uart.h"
#include <cpu.h>
#include <board_uart0.h>
#include <inttypes.h>
#include <stdint.h>
@ -98,39 +97,6 @@ ssize_t x86_uart_read(char *buf, size_t len)
return read;
}
#ifdef MODULE_UART0
static void com_handler(uint8_t irq_num)
{
(void) irq_num; /* == UART_IRQ */
switch (inb(UART_PORT + IIR) & IIR_INT_MASK) {
case IIR_INT_BR: {
while (is_input_empty()) {
asm volatile ("pause");
}
do {
uint8_t c = inb(UART_PORT + RBR);
uart0_handle_incoming(c);
} while (!is_input_empty());
uart0_notify_thread();
break;
}
case IIR_INT_TH:
case IIR_INT_LS:
case IIR_INT_TO:
default:
break;
}
}
#endif /* ifdef MODULE_UART0 */
void x86_init_uart(void)
{
#ifdef MODULE_UART0
x86_pic_set_handler(UART_IRQ, com_handler);
x86_pic_enable_irq(UART_IRQ);
outb(UART_PORT + IER, IER_RECV); /* Enable receive interrupt */
puts("UART initialized");
#endif
}

1
dist/Makefile vendored

@ -33,7 +33,6 @@ QUIET ?= 1
# Modules to include:
#USEMODULE += shell
#USEMODULE += uart0
#USEMODULE += posix
#USEMODULE += vtimer

@ -14,10 +14,6 @@ shell commands. These are included via the `shell_commands` module.
Additionally, the `ps` module which provides the `ps` shell command is
included.
Finally, in order for the shell to receive input, the `uart0` module
is used.
Usage
=====
@ -71,7 +67,6 @@ Running the `ps` command on an msba2:
2014-05-09 17:38:33,394 - INFO # pid | name | state Q | pri | stack ( used) location
2014-05-09 17:38:33,401 - INFO # 0 | idle | pending Q | 31 | 160 ( 148) 0x40000014
2014-05-09 17:38:33,407 - INFO # 1 | main | running Q | 15 | 2560 ( 848) 0x400000b4
2014-05-09 17:38:33,414 - INFO # 2 | uart0 | bl rx _ | 14 | 512 ( 296) 0x40000ce0
2014-05-09 17:38:33,431 - INFO # | SUM | | | 4256
```

@ -36,10 +36,6 @@
#include "ltc4150.h"
#endif
#ifdef MODULE_UART0
#include "board_uart0.h"
#endif
#ifdef MODULE_MCI
#include "diskio.h"
#endif
@ -102,12 +98,6 @@ void auto_init(void)
DEBUG("Auto init vtimer module.\n");
vtimer_init();
#endif
#ifndef MODULE_UART_STDIO
#ifdef MODULE_UART0
DEBUG("Auto init uart0 module.\n");
board_uart0_init();
#endif
#endif
#ifdef MODULE_XTIMER
DEBUG("Auto init xtimer module.\n");
xtimer_init();

@ -1,131 +0,0 @@
/**
* Character device messaging loop.
*
* Copyright (C) 2013, INRIA.
*
* 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.
*
* @ingroup chardev
* @{
* @file
* @brief Runs an infinite loop in a separate thread to handle access to character devices such as uart.
* @author Kaspar Schleiser <kaspar@schleiser.de>
* @}
*/
#include <stdio.h>
#include <errno.h>
#include "irq.h"
#include "msg.h"
#include "ringbuffer.h"
#include "posix_io.h"
/* increase stack size in uart0 when setting this to 1 */
#define ENABLE_DEBUG (0)
#include "debug.h"
static int min(int a, int b)
{
if (b > a) {
return a;
}
else {
return b;
}
}
void chardev_loop(ringbuffer_t *rb)
{
msg_t m;
kernel_pid_t reader_pid = KERNEL_PID_UNDEF;
struct posix_iop_t *r = NULL;
puts("UART0 thread started.");
while (1) {
msg_receive(&m);
if (!msg_sent_by_int(&m)) {
DEBUG("Receiving message from another thread: ");
switch(m.type) {
case OPEN:
DEBUG("OPEN\n");
if (reader_pid == KERNEL_PID_UNDEF) {
reader_pid = m.sender_pid;
/* no error */
m.content.value = 0;
}
else {
m.content.value = -EBUSY;
}
msg_reply(&m, &m);
break;
case READ:
DEBUG("READ\n");
if (m.sender_pid != reader_pid) {
m.content.value = -EINVAL;
r = NULL;
msg_reply(&m, &m);
}
else {
r = (struct posix_iop_t *)(void*)m.content.ptr;
}
break;
case CLOSE:
DEBUG("CLOSE\n");
if (m.sender_pid == reader_pid) {
DEBUG("uart0_thread: closing file from %" PRIkernel_pid "\n", reader_pid);
reader_pid = KERNEL_PID_UNDEF;
r = NULL;
m.content.value = 0;
}
else {
m.content.value = -EINVAL;
}
msg_reply(&m, &m);
break;
default:
DEBUG("UNKNOWN\n");
m.content.value = -EINVAL;
msg_reply(&m, &m);
}
}
if (rb->avail && (r != NULL)) {
DEBUG("Data is available\n");
unsigned state = disableIRQ();
int nbytes = min(r->nbytes, rb->avail);
DEBUG("uart0_thread [%i]: sending %i bytes received from %" PRIkernel_pid " to pid %" PRIkernel_pid "\n", thread_getpid(), nbytes, m.sender_pid, reader_pid);
ringbuffer_get(rb, r->buffer, nbytes);
r->nbytes = nbytes;
m.sender_pid = reader_pid;
m.type = OPEN;
m.content.ptr = (char *)r;
msg_reply(&m, &m);
r = NULL;
restoreIRQ(state);
}
}
}
void *chardev_thread_entry(void *rb_)
{
ringbuffer_t *rb = rb_;
chardev_loop(rb);
return NULL;
}

@ -1,74 +0,0 @@
/*
* Copyright (C) 2010 Freie Universität Berlin
*
* 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.
*/
/**
* @defgroup sys_uart0 UART0
* @ingroup sys
* @brief UART0 interface abstraction
* @{
*
* @file
* @brief Interface definitions for the UART0 abstraction
*/
#ifndef __BOARD_UART0_H
#define __BOARD_UART0_H
#include "kernel_types.h"
#include "cpu.h" /* To give user access to UART0_BUFSIZE */
#include "cpu_conf.h" /* Some CPUs define this in cpu_conf.h... */
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Process identifier for the UART0 module.
*/
extern kernel_pid_t uart0_handler_pid;
/**
* @brief Initialize and starts the UART0 handler.
*/
void board_uart0_init(void);
/**
* @brief To be called from the uart interrupt handler for every incoming
* character.
*
* @param[in] c The received character.
*/
void uart0_handle_incoming(int c);
/**
* @brief Notify the chardev thread that new characters are available in the
* ringbuffer.
*/
void uart0_notify_thread(void);
/**
* @brief Reads one character from the ringbuffer.
*
* @returns The first available character from the ringbuffer.
*/
int uart0_readc(void);
/**
* @brief Wrapper to putchar.
*
* @param[in] c The character to put on the UART.
*/
int uart0_putc(int c);
#ifdef __cplusplus
}
#endif
/** @} */
#endif /* __BOARD_UART0_H */

@ -1,39 +0,0 @@
/*
* Copyright (C) 2010 Kaspar Schleiser
*
* 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.
*/
/**
* @defgroup sys_chardevthread Chardev Thread
* @ingroup sys
* @brief Chardev thread
* @{
*
* @file
* @brief Handles I/O from a char devices
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*/
#ifndef __CHARDEV_THREAD_H
#define __CHARDEV_THREAD_H
#include "ringbuffer.h"
#ifdef __cplusplus
extern "C" {
#endif
void chardev_loop(ringbuffer_t *rb);
void *chardev_thread_entry(void *rb_);
#ifdef __cplusplus
}
#endif
#endif /* __CHARDEV_THREAD_H */
/** @} */

@ -21,9 +21,6 @@
#include <string.h>
#include "posix_io.h"
#ifdef MODULE_UART0
#include "board_uart0.h"
#endif
#include "unistd.h"
#include "fd.h"
@ -40,19 +37,6 @@ int fd_init(void)
{
memset(fd_table, 0, sizeof(fd_t) * FD_MAX);
#ifdef MODULE_UART0
posix_open(uart0_handler_pid, 0);
fd_t fd = {
.internal_active = 1,
.internal_fd = (int)uart0_handler_pid,
.read = (ssize_t ( *)(int, void *, size_t))posix_read,
.write = (ssize_t ( *)(int, const void *, size_t))posix_write,
.close = posix_close
};
memcpy(&fd_table[STDIN_FILENO], &fd, sizeof(fd_t));
memcpy(&fd_table[STDOUT_FILENO], &fd, sizeof(fd_t));
memcpy(&fd_table[STDERR_FILENO], &fd, sizeof(fd_t));
#endif
return FD_MAX;
}

@ -1 +0,0 @@
include $(RIOTBASE)/Makefile.base

@ -1,103 +0,0 @@
/*
* Copyright (C) 2013 INRIA
*
* 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.
*/
/**
* @ingroup sys
* @{
*
* @file
* @brief UART implementation
*
* @author Oliver Hahm <oliver.hahm@inria.fr>
* @author Ludwig Ortmann <ludwig.ortmann@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#include "kernel_types.h"
#include "board_uart0.h"
kernel_pid_t uart0_handler_pid = KERNEL_PID_UNDEF;
#ifdef MODULE_UART_STDIO
#include "uart_stdio.h"
void board_uart0_init(void){}
int uart0_readc(void)
{
char c = 0;
uart_stdio_read(&c, 1);
return c;
}
#else
#include "cpu_conf.h"
#include "chardev_thread.h"
#include "ringbuffer.h"
#include "thread.h"
#include "msg.h"
#include "posix_io.h"
#include "irq.h"
#ifndef UART0_BUFSIZE
#define UART0_BUFSIZE (128)
#endif
/* increase when ENABLE_DEBUG in chardev_thread is set to 1! */
#define UART0_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
ringbuffer_t uart0_ringbuffer;
static char buffer[UART0_BUFSIZE];
static char uart0_thread_stack[UART0_STACKSIZE];
void board_uart0_init(void)
{
ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE);
kernel_pid_t pid = thread_create(
uart0_thread_stack,
sizeof(uart0_thread_stack),
THREAD_PRIORITY_MAIN - 1,
CREATE_STACKTEST | CREATE_SLEEPING,
chardev_thread_entry,
&uart0_ringbuffer,
"uart0"
);
uart0_handler_pid = pid;
thread_wakeup(pid);
puts("uart0_init() [OK]");
}
void uart0_handle_incoming(int c)
{
ringbuffer_add_one(&uart0_ringbuffer, c);
}
void uart0_notify_thread(void)
{
msg_t m;
m.type = 0;
msg_send_int(&m, uart0_handler_pid);
}
int uart0_readc(void)
{
char c = 0;
posix_read(uart0_handler_pid, &c, 1);
return c;
}
#endif
int uart0_putc(int c)
{
return putchar(c);
}

@ -34,12 +34,21 @@
#include "periph/uart.h"
#include "board.h"
#include "periph/uart.h"
#define ENABLE_DEBUG 0
#include "debug.h"
#ifndef STDIO
#define STDIO (0)
#endif
#ifndef STDIO_BAUDRATE
#define STDIO_BAUDRATE (115200)
#endif
#ifndef STDIO_RX_BUFSIZE
#define STDIO_RX_BUFSIZE (64)
#define STDIO_RX_BUFSIZE (64)
#endif
/**

Loading…
Cancel
Save