mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-24 14:03:55 +01:00
stm32f3: be UART0 aware
This commit is contained in:
parent
aefa818338
commit
fc3864756f
@ -37,28 +37,42 @@
|
||||
#include "irq.h"
|
||||
#include "periph/uart.h"
|
||||
|
||||
#ifdef MODULE_UART0
|
||||
#include "board_uart0.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief manage the heap
|
||||
*/
|
||||
extern uint32_t _end; /* address of last used memory cell */
|
||||
caddr_t heap_top = (caddr_t)&_end + 4;
|
||||
|
||||
#ifndef MODULE_UART0
|
||||
/**
|
||||
* @brief use mutex for waiting on incoming UART chars
|
||||
*/
|
||||
static mutex_t uart_rx_mutex;
|
||||
static char rx_buf_mem[STDIO_BUFSIZE];
|
||||
static ringbuffer_t rx_buf;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Receive a new character from the UART and put it into the receive buffer
|
||||
*/
|
||||
void rx_cb(void *arg, char data)
|
||||
{
|
||||
#ifndef MODULE_UART0
|
||||
(void)arg;
|
||||
|
||||
ringbuffer_add_one(&rx_buf, data);
|
||||
mutex_unlock(&uart_rx_mutex);
|
||||
#else
|
||||
if (uart0_handler_pid) {
|
||||
uart0_handle_incoming(data);
|
||||
|
||||
uart0_notify_thread();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,10 +80,11 @@ void rx_cb(void *arg, char data)
|
||||
*/
|
||||
void _init(void)
|
||||
{
|
||||
#ifndef MODULE_UART0
|
||||
mutex_init(&uart_rx_mutex);
|
||||
ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_BUFSIZE);
|
||||
uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0);
|
||||
}
|
||||
#endif
|
||||
uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0);}
|
||||
|
||||
/**
|
||||
* @brief Free resources on NewLib de-initialization, not used for RIOT
|
||||
@ -174,10 +189,15 @@ int _open_r(struct _reent *r, const char *name, int mode)
|
||||
*/
|
||||
int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
|
||||
{
|
||||
#ifndef MODULE_UART0
|
||||
while (rx_buf.avail == 0) {
|
||||
mutex_lock(&uart_rx_mutex);
|
||||
}
|
||||
return ringbuffer_get(&rx_buf, (char*)buffer, rx_buf.avail);
|
||||
#else
|
||||
r->_errno = ENODEV;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user