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

88 lines
1.8 KiB
C
Raw Normal View History

2014-02-03 23:19:11 +01:00
/*
* 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.
2014-02-03 23:19:11 +01:00
*/
/**
* @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 "cpu_conf.h"
#include "chardev_thread.h"
#include "ringbuffer.h"
#include "thread.h"
#include "msg.h"
#include "posix_io.h"
#include "irq.h"
#include "board_uart0.h"
2013-12-19 16:48:31 +01:00
#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)
2011-03-08 11:17:57 +01:00
ringbuffer_t uart0_ringbuffer;
2014-08-06 09:44:31 +02:00
kernel_pid_t uart0_handler_pid = KERNEL_PID_UNDEF;
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(
2013-12-19 16:49:09 +01:00
uart0_thread_stack,
sizeof(uart0_thread_stack),
THREAD_PRIORITY_MAIN - 1,
2013-12-19 16:49:09 +01:00
CREATE_STACKTEST | CREATE_SLEEPING,
chardev_thread_entry,
&uart0_ringbuffer,
2013-12-19 16:49:09 +01:00
"uart0"
);
uart0_handler_pid = pid;
2013-10-26 22:12:01 +02:00
thread_wakeup(pid);
puts("uart0_init() [OK]");
}
void uart0_handle_incoming(int c)
{
ringbuffer_add_one(&uart0_ringbuffer, c);
}
void uart0_notify_thread(void)
{
2011-03-08 10:54:40 +01:00
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;
}
int uart0_putc(int c)
{
return putchar(c);
}