From 6198c924e4c30a678effb2fe706cb0ae2d1f5cc5 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 13:59:57 +0100 Subject: [PATCH 1/3] * decreased timing for sht11 (as fix for hwtimer_wait issue) --- drivers/include/sht11.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/include/sht11.h b/drivers/include/sht11.h index 71e7e8bac1..d929a2ecb5 100644 --- a/drivers/include/sht11.h +++ b/drivers/include/sht11.h @@ -51,7 +51,7 @@ and the mailinglist (subscription via web site) #define SHT11_RESET (0x1E) //000 1111 0 /* time to wait after toggling the data line */ -#define SHT11_DATA_WAIT (HWTIMER_TICKS(5)) +#define SHT11_DATA_WAIT (HWTIMER_TICKS(1)) /* time to wait after toggling the clock line */ #define SHT11_CLK_WAIT (HWTIMER_TICKS(1)) From 3b1cbf9cb898c578c06898d81a062deceb8fb556 Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 14:12:05 +0100 Subject: [PATCH 2/3] * added board_uart0 to auto_init --- sys/auto_init.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sys/auto_init.c b/sys/auto_init.c index d872c0354f..17fdeb34de 100644 --- a/sys/auto_init.c +++ b/sys/auto_init.c @@ -1,5 +1,6 @@ #include #include +#include #include #define ENABLE_DEBUG @@ -16,6 +17,10 @@ void auto_init(void) { DEBUG("Auto init swtimer module.\n"); swtimer_init(); #endif +#ifdef MODULE_UART0 + DEBUG("Auto init uart0 module.\n"); + board_uart0_init(); +#endif #ifdef MODULE_SHT11 DEBUG("Auto init SHT11 module.\n"); sht11_init(); From e335ccfb433ae1de73dc7d3abe86a4f980c4556d Mon Sep 17 00:00:00 2001 From: Oliver Hahm Date: Thu, 4 Nov 2010 16:21:39 +0100 Subject: [PATCH 3/3] * fixed wrong return value for thread_wakeup * changed hwtimer_wait to use thread_sleep instead of mutexes --- core/hwtimer.c | 71 ++++++++++++++++++++++++++---------------- core/include/hwtimer.h | 2 +- core/include/tcb.h | 2 +- core/thread.c | 2 +- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/core/hwtimer.c b/core/hwtimer.c index e056a3dd60..e19c8a2a8f 100644 --- a/core/hwtimer.c +++ b/core/hwtimer.c @@ -23,7 +23,7 @@ #include #include -#include +#include /*---------------------------------------------------------------------------*/ @@ -33,8 +33,14 @@ typedef struct hwtimer_t { uint8_t checksum; } hwtimer_t; +typedef struct hwtimer_wait_t { + unsigned int pid; /**< pid of waiting thread */ + uint8_t state; /**state = 0; + while (!(thread_wakeup((*((hwtimer_wait_t*)hwt)).pid))) { + hwtimer_set(HWTIMER_WAIT_BACKOFF, hwtimer_wakeup, (void*) &hwt); + } } void hwtimer_spin(unsigned long ticks) @@ -109,7 +121,8 @@ void hwtimer_init_comp(uint32_t fcpu) { available_timers = 0; hwtimer_arch_init(multiplexer, fcpu); for (i = 0; i < HWTIMER_QUEUESIZE; i++) { - queue[i] = 0xff; // init queue as empty + /* init queue as empty */ + queue[i] = 0xff; } for (i = 0; i < HWTIMER_QUEUESIZE; i++) { enqueue(i); @@ -119,7 +132,7 @@ void hwtimer_init_comp(uint32_t fcpu) { /*---------------------------------------------------------------------------*/ int hwtimer_active(void) { - return queue_items != HWTIMER_QUEUESIZE; + return (queue_items != HWTIMER_QUEUESIZE); } /*---------------------------------------------------------------------------*/ @@ -133,34 +146,37 @@ unsigned long hwtimer_now(void) void hwtimer_wait(unsigned long ticks) { - mutex_t mutex; - if (ticks <= 4 || inISR()) { + if (ticks <= 6 || inISR()) { hwtimer_spin(ticks); return; } - mutex_init(&mutex); - mutex_lock(&mutex); - // -2 is to adjust the real value - int res = hwtimer_set(ticks-2, hwtimer_releasemutex, &mutex); + hwtimer_wait_t hwt; + hwt.pid = active_thread->pid; + hwt.state = 1; + /* -2 is to adjust the real value */ + int res = hwtimer_set(ticks-2, hwtimer_wakeup, (void*) &hwt); if (res == -1) { - mutex_unlock(&mutex, true); hwtimer_spin(ticks); return; } - mutex_lock(&mutex); + while (hwt.state) { + thread_sleep(); + } } /*---------------------------------------------------------------------------*/ static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr, bool absolute) { - if (! inISR() ) dINT(); -// hwtimer_arch_disable_interrupt(); + if (!inISR()) { + dINT(); + } int x = dequeue(); if (x == Q_FULL) { + if (! inISR()) { + eINT(); + } printf("[KT] no timers left\n"); -// hwtimer_arch_enable_interrupt(); - if (! inISR()) eINT(); return -1; } @@ -168,13 +184,16 @@ static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr timer[x].data = ptr; timer[x].checksum = ++timer_id; - if (absolute) + if (absolute) { hwtimer_arch_set_absolute(offset, x); - else + } + else { hwtimer_arch_set(offset, x); + } - //hwtimer_arch_enable_interrupt(); - if (! inISR()) eINT(); + if (!inISR()) { + eINT(); + } return (timer[x].checksum << 8) + x; } diff --git a/core/include/hwtimer.h b/core/include/hwtimer.h index 39f2c0f189..b2d8d2666e 100644 --- a/core/include/hwtimer.h +++ b/core/include/hwtimer.h @@ -30,7 +30,7 @@ #define __HWTIMER_H #include -#include "hwtimer_cpu.h" +#include /** * @def HWTIMER_SPEED diff --git a/core/include/tcb.h b/core/include/tcb.h index 66ef085e3f..34d7c14477 100644 --- a/core/include/tcb.h +++ b/core/include/tcb.h @@ -34,7 +34,7 @@ typedef struct tcb { char* sp; - unsigned int status; + uint8_t status; uint16_t pid; uint16_t priority; diff --git a/core/thread.c b/core/thread.c index 8afbcb8446..59aaabccec 100644 --- a/core/thread.c +++ b/core/thread.c @@ -62,7 +62,7 @@ int thread_wakeup(int pid) { } else { sched_context_switch_request = 1; } - return 0; + return 1; } else { DEBUG("thread_wakeup: Thread is not sleeping!\n"); if (!isr) eINT();