mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #5 from LudwigOrtmann/master
OSX support, uart0 support for native
This commit is contained in:
commit
39f01d2626
6
native/Makefile.dep
Normal file
6
native/Makefile.dep
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
ifneq (,$(findstring cc110x_ng,$(USEMODULE)))
|
||||||
|
ifeq (,$(findstring cc110x_spi,$(USEMODULE)))
|
||||||
|
USEMODULE += cc110x_spi
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
@ -14,8 +14,10 @@ export OBJCOPY = $(PREFIX)objcopy
|
|||||||
FLASHER = lpc2k_pgm
|
FLASHER = lpc2k_pgm
|
||||||
TERM = pyterm.py
|
TERM = pyterm.py
|
||||||
|
|
||||||
LINKFLAGS = -lrt -m32
|
LINKFLAGS = -m32
|
||||||
|
|
||||||
ifeq ($(strip $(PORT)),)
|
ifeq ($(strip $(PORT)),)
|
||||||
export PORT = /dev/ttyUSB0
|
export PORT = /dev/ttyUSB0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
include $(RIOTBOARD)/$(BOARD)/Makefile.dep
|
||||||
|
@ -21,6 +21,9 @@
|
|||||||
*/
|
*/
|
||||||
void board_init()
|
void board_init()
|
||||||
{
|
{
|
||||||
|
#ifdef MODULE_UART0
|
||||||
|
_native_init_uart0();
|
||||||
|
#endif
|
||||||
LED_GREEN_OFF();
|
LED_GREEN_OFF();
|
||||||
LED_RED_ON();
|
LED_RED_ON();
|
||||||
puts("RIOT native board initialized.");
|
puts("RIOT native board initialized.");
|
||||||
|
@ -22,3 +22,8 @@ void LED_RED_OFF(void);
|
|||||||
void LED_RED_ON(void);
|
void LED_RED_ON(void);
|
||||||
void LED_RED_TOGGLE(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
|
||||||
|
@ -26,11 +26,25 @@
|
|||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "cpu-conf.h"
|
#include "cpu-conf.h"
|
||||||
|
#include "hwtimer.h"
|
||||||
|
|
||||||
#define native_ltc4150_startup_delay 10
|
#define native_ltc4150_startup_delay 10
|
||||||
|
|
||||||
static timer_t native_ltc4150_timer;
|
static int _int_enabled;
|
||||||
static struct itimerspec native_ltc4150_timer_time;
|
|
||||||
|
/**
|
||||||
|
* native ltc4150 hwtimer - interrupt handler proxy
|
||||||
|
*/
|
||||||
|
static void _int_handler()
|
||||||
|
{
|
||||||
|
DEBUG("ltc4150 _int_handler()\n");
|
||||||
|
ltc4150_interrupt();
|
||||||
|
if (_int_enabled == 1) {
|
||||||
|
if (hwtimer_set(100000, _int_handler, NULL) == -1) {
|
||||||
|
errx(1, "_int_handler: hwtimer_set");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* unregister signal handler
|
* unregister signal handler
|
||||||
@ -38,7 +52,7 @@ static struct itimerspec native_ltc4150_timer_time;
|
|||||||
void ltc4150_disable_int(void)
|
void ltc4150_disable_int(void)
|
||||||
{
|
{
|
||||||
DEBUG("ltc4150_disable_int()\n");
|
DEBUG("ltc4150_disable_int()\n");
|
||||||
unregister_interrupt(_SIG_LTC4150);
|
_int_enabled = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +61,10 @@ void ltc4150_disable_int(void)
|
|||||||
void ltc4150_enable_int(void)
|
void ltc4150_enable_int(void)
|
||||||
{
|
{
|
||||||
DEBUG("ltc4150_enable_int()\n");
|
DEBUG("ltc4150_enable_int()\n");
|
||||||
register_interrupt(_SIG_LTC4150, ltc4150_interrupt);
|
_int_enabled = 1;
|
||||||
|
if (hwtimer_set(100000, _int_handler, NULL) == -1) {
|
||||||
|
errx(1, "ltc4150_enable_int: hwtimer_set");
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,25 +85,6 @@ void ltc4150_arch_init(void)
|
|||||||
|
|
||||||
ltc4150_disable_int();
|
ltc4150_disable_int();
|
||||||
|
|
||||||
/* create timer */
|
|
||||||
sev.sigev_notify = SIGEV_SIGNAL;
|
|
||||||
sev.sigev_signo = _SIG_LTC4150;
|
|
||||||
sev.sigev_value.sival_ptr = &native_ltc4150_timer;
|
|
||||||
|
|
||||||
if (timer_create(CLOCK_MONOTONIC, &sev, &native_ltc4150_timer) == -1) {
|
|
||||||
err(1, "ltc4150_arch_init(): timer_create");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* set timer */
|
|
||||||
native_ltc4150_timer_time.it_value.tv_sec = 0;
|
|
||||||
native_ltc4150_timer_time.it_value.tv_nsec = 100000000;
|
|
||||||
native_ltc4150_timer_time.it_interval.tv_sec = 0;
|
|
||||||
native_ltc4150_timer_time.it_interval.tv_nsec = 100000000;
|
|
||||||
|
|
||||||
if (timer_settime(native_ltc4150_timer, 0, &native_ltc4150_timer_time, NULL) == -1) {
|
|
||||||
err(1, "ltc4150_arch_init: timer_settime");
|
|
||||||
}
|
|
||||||
|
|
||||||
puts("Native LTC4150 initialized.");
|
puts("Native LTC4150 initialized.");
|
||||||
}
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
54
native/native-uart0.c
Normal file
54
native/native-uart0.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* TODO:
|
||||||
|
* make stdin/stdout customizable.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
int putchar(int c) {
|
||||||
|
write(1, &c, 1);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user