2014-02-03 23:19:11 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 INRIA
|
|
|
|
*
|
2014-07-31 19:45:27 +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.
|
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>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2010-10-01 15:24:43 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-12-19 16:48:31 +01:00
|
|
|
#include "cpu-conf.h"
|
2013-10-26 22:11:29 +02:00
|
|
|
#include "chardev_thread.h"
|
|
|
|
#include "ringbuffer.h"
|
|
|
|
#include "thread.h"
|
|
|
|
#include "msg.h"
|
|
|
|
#include "posix_io.h"
|
|
|
|
#include "irq.h"
|
|
|
|
|
|
|
|
#include "board_uart0.h"
|
2010-10-01 15:24:43 +02:00
|
|
|
|
2013-12-19 16:48:31 +01:00
|
|
|
#ifndef UART0_BUFSIZE
|
|
|
|
#define UART0_BUFSIZE (128)
|
|
|
|
#endif
|
|
|
|
|
2014-02-24 22:40:02 +01:00
|
|
|
/* increase when ENABLE_DEBUG in chardev_thread is set to 1! */
|
2014-03-08 16:27:06 +01:00
|
|
|
#define UART0_STACKSIZE (KERNEL_CONF_STACKSIZE_DEFAULT)
|
2010-10-01 15:24:43 +02:00
|
|
|
|
2011-03-08 11:17:57 +01:00
|
|
|
ringbuffer_t uart0_ringbuffer;
|
2010-10-01 15:24:43 +02:00
|
|
|
int uart0_handler_pid;
|
|
|
|
|
|
|
|
static char buffer[UART0_BUFSIZE];
|
|
|
|
|
2010-11-05 19:33:45 +01:00
|
|
|
static char uart0_thread_stack[UART0_STACKSIZE];
|
2010-10-25 15:40:01 +02:00
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
void board_uart0_init(void)
|
|
|
|
{
|
2010-10-01 15:24:43 +02:00
|
|
|
ringbuffer_init(&uart0_ringbuffer, buffer, UART0_BUFSIZE);
|
2013-10-23 22:46:18 +02:00
|
|
|
int pid = thread_create(
|
2013-12-19 16:49:09 +01:00
|
|
|
uart0_thread_stack,
|
|
|
|
sizeof(uart0_thread_stack),
|
|
|
|
PRIORITY_MAIN - 1,
|
|
|
|
CREATE_STACKTEST | CREATE_SLEEPING,
|
2014-03-04 20:20:01 +01:00
|
|
|
chardev_thread_entry,
|
|
|
|
&uart0_ringbuffer,
|
2013-12-19 16:49:09 +01:00
|
|
|
"uart0"
|
|
|
|
);
|
2010-10-01 15:24:43 +02:00
|
|
|
uart0_handler_pid = pid;
|
2013-10-26 22:12:01 +02:00
|
|
|
thread_wakeup(pid);
|
2010-10-01 15:24:43 +02:00
|
|
|
puts("uart0_init() [OK]");
|
|
|
|
}
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
void uart0_handle_incoming(int c)
|
|
|
|
{
|
2014-05-03 16:39:39 +02:00
|
|
|
ringbuffer_add_one(&uart0_ringbuffer, c);
|
2010-10-01 15:24:43 +02:00
|
|
|
}
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
void uart0_notify_thread(void)
|
|
|
|
{
|
2011-03-08 10:54:40 +01:00
|
|
|
msg_t m;
|
2010-10-01 15:24:43 +02:00
|
|
|
m.type = 0;
|
|
|
|
msg_send_int(&m, uart0_handler_pid);
|
|
|
|
}
|
2010-11-18 17:33:25 +01:00
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
int uart0_readc(void)
|
|
|
|
{
|
2010-11-18 17:33:25 +01:00
|
|
|
char c = 0;
|
|
|
|
posix_read(uart0_handler_pid, &c, 1);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
2013-06-22 05:11:53 +02:00
|
|
|
void uart0_putc(int c)
|
|
|
|
{
|
2010-11-18 17:33:25 +01:00
|
|
|
putchar(c);
|
|
|
|
}
|