From 4be9764f80dcab26648e31dd698d95269c2e6cc7 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Mon, 16 Dec 2013 11:16:08 +0100 Subject: [PATCH 1/5] removed useless code --- boards/native/drivers/native-ltc4150.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/boards/native/drivers/native-ltc4150.c b/boards/native/drivers/native-ltc4150.c index cd3639ffba..8944ffbcf9 100644 --- a/boards/native/drivers/native-ltc4150.c +++ b/boards/native/drivers/native-ltc4150.c @@ -28,7 +28,6 @@ #include "cpu-conf.h" #include "hwtimer.h" -#define native_ltc4150_startup_delay 10 #define LTC_TIMER_INTERVAL (10 * 1000UL) // 10 ms static int _int_enabled; @@ -78,8 +77,6 @@ void ltc4150_enable_int(void) void ltc4150_sync_blocking(void) { DEBUG("ltc4150_sync_blocking()\n"); - - for (int i = native_ltc4150_startup_delay; i > 0; i--); } /** From a38928e5c3d856b0dfdfa1b08b2ffa1c6a2ad5fe Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Mon, 16 Dec 2013 11:18:47 +0100 Subject: [PATCH 2/5] rename variables to match the guidelines (use module prefix) --- boards/native/drivers/native-ltc4150.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/boards/native/drivers/native-ltc4150.c b/boards/native/drivers/native-ltc4150.c index 8944ffbcf9..871109e2d9 100644 --- a/boards/native/drivers/native-ltc4150.c +++ b/boards/native/drivers/native-ltc4150.c @@ -30,19 +30,19 @@ #define LTC_TIMER_INTERVAL (10 * 1000UL) // 10 ms -static int _int_enabled; -static int hwtimer_id; +static int _native_ltc_int_enabled; +static int _native_ltc_hwtimer_id; /** * native ltc4150 hwtimer - interrupt handler proxy */ -static void _int_handler() +static void _native_ltc_int_handler() { DEBUG("ltc4150 _int_handler()\n"); ltc4150_interrupt(); - if (_int_enabled == 1) { - hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _int_handler, NULL); - if (hwtimer_id == -1) { + if (_native_ltc_int_enabled == 1) { + _native_ltc_hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _native_ltc_int_handler, NULL); + if (_native_ltc_hwtimer_id == -1) { errx(1, "_int_handler: hwtimer_set"); } } @@ -54,8 +54,8 @@ static void _int_handler() void ltc4150_disable_int(void) { DEBUG("ltc4150_disable_int()\n"); - _int_enabled = 0; - hwtimer_remove(hwtimer_id); + _native_ltc_int_enabled = 0; + hwtimer_remove(_native_ltc_hwtimer_id); } /** @@ -64,9 +64,9 @@ void ltc4150_disable_int(void) void ltc4150_enable_int(void) { DEBUG("ltc4150_enable_int()\n"); - _int_enabled = 1; - hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _int_handler, NULL); - if (hwtimer_id == -1) { + _native_ltc_int_enabled = 1; + _native_ltc_hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _native_ltc_int_handler, NULL); + if (_native_ltc_hwtimer_id == -1) { errx(1, "ltc4150_enable_int: hwtimer_set"); } } From 6aec050fc482ce2b2af26302c1a8dbe7c34acd45 Mon Sep 17 00:00:00 2001 From: Christian Mehlis Date: Mon, 16 Dec 2013 11:20:00 +0100 Subject: [PATCH 3/5] initialize id and only remove a valid timer --- boards/native/drivers/native-ltc4150.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/boards/native/drivers/native-ltc4150.c b/boards/native/drivers/native-ltc4150.c index 871109e2d9..b1860b242b 100644 --- a/boards/native/drivers/native-ltc4150.c +++ b/boards/native/drivers/native-ltc4150.c @@ -55,7 +55,10 @@ void ltc4150_disable_int(void) { DEBUG("ltc4150_disable_int()\n"); _native_ltc_int_enabled = 0; - hwtimer_remove(_native_ltc_hwtimer_id); + if (_native_ltc_hwtimer_id != -1) { + hwtimer_remove(_native_ltc_hwtimer_id); + _native_ltc_hwtimer_id = -1; + } } /** @@ -84,6 +87,7 @@ void ltc4150_sync_blocking(void) */ void ltc4150_arch_init(void) { + _native_ltc_hwtimer_id = -1; ltc4150_disable_int(); puts("Native LTC4150 initialized."); From 579c1edb04eb01444cc021258f62da13ccd910a3 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Tue, 17 Dec 2013 17:23:41 +0100 Subject: [PATCH 4/5] clean up native ltc --- boards/native/drivers/native-ltc4150.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/boards/native/drivers/native-ltc4150.c b/boards/native/drivers/native-ltc4150.c index b1860b242b..d82c686022 100644 --- a/boards/native/drivers/native-ltc4150.c +++ b/boards/native/drivers/native-ltc4150.c @@ -22,29 +22,36 @@ #include #include "ltc4150_arch.h" -#include "debug.h" #include "cpu.h" #include "cpu-conf.h" #include "hwtimer.h" +#define ENABLE_DEBUG (0) +#include "debug.h" + #define LTC_TIMER_INTERVAL (10 * 1000UL) // 10 ms -static int _native_ltc_int_enabled; -static int _native_ltc_hwtimer_id; +static int _native_ltc_hwtimer_id = -1; /** * native ltc4150 hwtimer - interrupt handler proxy */ static void _native_ltc_int_handler() { - DEBUG("ltc4150 _int_handler()\n"); - ltc4150_interrupt(); - if (_native_ltc_int_enabled == 1) { + DEBUG("_native_ltc_int_handler()\n"); + if (_native_ltc_hwtimer_id != -1) { + ltc4150_interrupt(); _native_ltc_hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _native_ltc_int_handler, NULL); if (_native_ltc_hwtimer_id == -1) { errx(1, "_int_handler: hwtimer_set"); } + else { + DEBUG("_native_ltc_int_handler: _native_ltc_hwtimer_id is %d\n", _native_ltc_hwtimer_id); + } + } + else { + DEBUG("_native_ltc_int_handler was called although no hwtimer is set\n"); } } @@ -54,7 +61,6 @@ static void _native_ltc_int_handler() void ltc4150_disable_int(void) { DEBUG("ltc4150_disable_int()\n"); - _native_ltc_int_enabled = 0; if (_native_ltc_hwtimer_id != -1) { hwtimer_remove(_native_ltc_hwtimer_id); _native_ltc_hwtimer_id = -1; @@ -67,11 +73,13 @@ void ltc4150_disable_int(void) void ltc4150_enable_int(void) { DEBUG("ltc4150_enable_int()\n"); - _native_ltc_int_enabled = 1; _native_ltc_hwtimer_id = hwtimer_set(LTC_TIMER_INTERVAL, _native_ltc_int_handler, NULL); if (_native_ltc_hwtimer_id == -1) { errx(1, "ltc4150_enable_int: hwtimer_set"); } + else { + DEBUG("ltc4150_enable_int: _native_ltc_hwtimer_id is %d\n", _native_ltc_hwtimer_id); + } } /** @@ -87,7 +95,6 @@ void ltc4150_sync_blocking(void) */ void ltc4150_arch_init(void) { - _native_ltc_hwtimer_id = -1; ltc4150_disable_int(); puts("Native LTC4150 initialized."); From 77e8cbb1129075b78280e8569b78cb66e8e7c0d8 Mon Sep 17 00:00:00 2001 From: Ludwig Ortmann Date: Wed, 18 Dec 2013 20:36:42 +0100 Subject: [PATCH 5/5] remove ltc disable race --- boards/native/drivers/native-ltc4150.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/boards/native/drivers/native-ltc4150.c b/boards/native/drivers/native-ltc4150.c index d82c686022..e269a6bab6 100644 --- a/boards/native/drivers/native-ltc4150.c +++ b/boards/native/drivers/native-ltc4150.c @@ -26,6 +26,7 @@ #include "cpu.h" #include "cpu-conf.h" #include "hwtimer.h" +#include "irq.h" #define ENABLE_DEBUG (0) #include "debug.h" @@ -60,11 +61,13 @@ static void _native_ltc_int_handler() */ void ltc4150_disable_int(void) { + unsigned state = disableIRQ(); DEBUG("ltc4150_disable_int()\n"); if (_native_ltc_hwtimer_id != -1) { hwtimer_remove(_native_ltc_hwtimer_id); _native_ltc_hwtimer_id = -1; } + restoreIRQ(state); } /**