commit
7701aed546
@ -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.");
|
||||
}
|
@ -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 */
|
||||
/** @} */
|
@ -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);
|
||||
}
|
Loading…
Reference in New Issue