From 34b2dc31e5bcd294672cfe4f6adfa00ea682c073 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 10 Apr 2013 12:52:19 +0200 Subject: [PATCH 1/5] adapted native Makefiles to core restructuring --- native/Makefile.dep | 6 ++++++ native/Makefile.include | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 native/Makefile.dep diff --git a/native/Makefile.dep b/native/Makefile.dep new file mode 100644 index 0000000000..de1d7e692c --- /dev/null +++ b/native/Makefile.dep @@ -0,0 +1,6 @@ +ifneq (,$(findstring cc110x_ng,$(USEMODULE))) + ifeq (,$(findstring cc110x_spi,$(USEMODULE))) + USEMODULE += cc110x_spi + endif +endif + diff --git a/native/Makefile.include b/native/Makefile.include index a14da50af5..e7bf1c65bd 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -19,3 +19,5 @@ LINKFLAGS = -lrt -m32 ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 endif + +include $(RIOTBOARD)/$(BOARD)/Makefile.dep From cbe8feb3ddd64b9d496ae05db4d43fca114ed8e4 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Mon, 15 Apr 2013 20:11:15 +0200 Subject: [PATCH 2/5] make native ltc4150 posix rt independent --- native/native-ltc4150.c | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/native/native-ltc4150.c b/native/native-ltc4150.c index 99b4d0a3e5..e84501ef2c 100644 --- a/native/native-ltc4150.c +++ b/native/native-ltc4150.c @@ -26,11 +26,25 @@ #include "cpu.h" #include "cpu-conf.h" +#include "hwtimer.h" #define native_ltc4150_startup_delay 10 -static timer_t native_ltc4150_timer; -static struct itimerspec native_ltc4150_timer_time; +static int _int_enabled; + +/** + * 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 @@ -38,7 +52,7 @@ static struct itimerspec native_ltc4150_timer_time; void ltc4150_disable_int(void) { 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) { 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(); - /* 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."); } /** @} */ From a860087f502958589a8fec8f12d9f6fca80ef1fd Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 14 May 2013 17:42:08 +0200 Subject: [PATCH 3/5] native board uart0 import --- native/board_init.c | 3 +++ native/include/board.h | 5 +++++ native/native-uart0.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 native/native-uart0.c diff --git a/native/board_init.c b/native/board_init.c index d6f4c4ba31..52e63878fc 100644 --- a/native/board_init.c +++ b/native/board_init.c @@ -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."); diff --git a/native/include/board.h b/native/include/board.h index 457289a566..69e40eb383 100644 --- a/native/include/board.h +++ b/native/include/board.h @@ -22,3 +22,8 @@ void LED_RED_OFF(void); void LED_RED_ON(void); void LED_RED_TOGGLE(void); +#ifdef MODULE_UART0 +#include +extern fd_set _native_uart_rfds; +extern void _native_handle_uart0_input(void); +#endif diff --git a/native/native-uart0.c b/native/native-uart0.c new file mode 100644 index 0000000000..c73b5ee6ea --- /dev/null +++ b/native/native-uart0.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#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."); +} From 63971962d1ecae0d00f4b33428935975638050ea Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 15 May 2013 10:44:57 +0200 Subject: [PATCH 4/5] lose superflouse -lrt CFLAG --- native/Makefile.include | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/native/Makefile.include b/native/Makefile.include index e7bf1c65bd..d360b2248f 100644 --- a/native/Makefile.include +++ b/native/Makefile.include @@ -14,7 +14,7 @@ export OBJCOPY = $(PREFIX)objcopy FLASHER = lpc2k_pgm TERM = pyterm.py -LINKFLAGS = -lrt -m32 +LINKFLAGS = -m32 ifeq ($(strip $(PORT)),) export PORT = /dev/ttyUSB0 From c660c56bbdda016a74bb66b35228b1501c0e6a60 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 15 May 2013 16:04:48 +0200 Subject: [PATCH 5/5] native board putchar implementation --- native/native-uart0.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/native/native-uart0.c b/native/native-uart0.c index c73b5ee6ea..e13447bb0e 100644 --- a/native/native-uart0.c +++ b/native/native-uart0.c @@ -1,3 +1,8 @@ +/* + * TODO: + * make stdin/stdout customizable. + */ + #include #include #include @@ -42,3 +47,8 @@ void _native_init_uart0() FD_SET(0, &_native_uart_rfds); puts("RIOT native uart0 initialized."); } + +int putchar(int c) { + write(1, &c, 1); + return 0; +}