mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 07:21:18 +01:00
native board uart0 import
This commit is contained in:
parent
c5f8eee291
commit
d3b806ea41
@ -21,6 +21,9 @@
|
||||
*/
|
||||
void board_init()
|
||||
{
|
||||
#ifdef MODULE_UART0
|
||||
_native_init_uart0();
|
||||
#endif
|
||||
LED_GREEN_OFF();
|
||||
LED_RED_ON();
|
||||
puts("RIOT native board initialized.");
|
||||
|
||||
@ -22,3 +22,8 @@ void LED_RED_OFF(void);
|
||||
void LED_RED_ON(void);
|
||||
void LED_RED_TOGGLE(void);
|
||||
|
||||
#ifdef MODULE_UART0
|
||||
#include <sys/select.h>
|
||||
extern fd_set _native_uart_rfds;
|
||||
extern void _native_handle_uart0_input(void);
|
||||
#endif
|
||||
|
||||
44
native/native-uart0.c
Normal file
44
native/native-uart0.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "debug.h"
|
||||
#include "board_uart0.h"
|
||||
|
||||
fd_set _native_uart_rfds;
|
||||
|
||||
static inline int uart0_puts(char *astring, int length)
|
||||
{
|
||||
return puts(astring);
|
||||
}
|
||||
|
||||
void _native_handle_uart0_input()
|
||||
{
|
||||
char buf[42];
|
||||
int nread;
|
||||
|
||||
_native_in_syscall = 0;
|
||||
_native_in_isr = 1;
|
||||
|
||||
nread = read(0, buf, sizeof(buf));
|
||||
if (nread == -1) {
|
||||
err(1, "_native_handle_uart0_input(): read()");
|
||||
}
|
||||
for(int pos = 0; pos < nread; pos++) {
|
||||
uart0_handle_incoming(buf[pos]);
|
||||
}
|
||||
uart0_notify_thread();
|
||||
|
||||
_native_in_isr = 0;
|
||||
cpu_switch_context_exit();
|
||||
}
|
||||
|
||||
void _native_init_uart0()
|
||||
{
|
||||
/* Watch stdin (fd 0) to see when it has input. */
|
||||
FD_ZERO(&_native_uart_rfds);
|
||||
FD_SET(0, &_native_uart_rfds);
|
||||
puts("RIOT native uart0 initialized.");
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user