diff options
| author | hathach <[email protected]> | 2013-02-01 12:00:34 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-02-01 12:25:02 +0700 |
| commit | aab92b40d2e904e8ad85386e4a4f3b59e84eb844 (patch) | |
| tree | f8099f4075a1e7612b6522d1c8902d56aa13b3f7 /tinyusb/osal | |
| parent | 9e3785e7e1bd5bac3c8e24477edbde12cc09dd4b (diff) | |
change osal_timeout_t to uint32_t
implement osal_tick_get & osal_tick_tock for osal_none
implement timeout for osal_semaphore_wait
Diffstat (limited to 'tinyusb/osal')
| -rw-r--r-- | tinyusb/osal/osal.h | 6 | ||||
| -rw-r--r-- | tinyusb/osal/osal_common.h | 10 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.c | 25 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 20 |
4 files changed, 49 insertions, 12 deletions
diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index 0c99e497f..298a54f3e 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -74,8 +74,6 @@ #include "osal_common.h" -typedef uint32_t osal_timeout_t; - //------------- Tick -------------// uint32_t osal_tick_get(void); @@ -94,7 +92,7 @@ tusb_error_t osal_task_create(osal_task_t *task); typedef uint32_t osal_semaphore_t; typedef void* osal_semaphore_handle_t; osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const sem); -void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, osal_timeout_t msec, tusb_error_t *p_error); +void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error); tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl); //------------- Queue -------------// @@ -105,7 +103,7 @@ typedef void* osal_queue_handle_t; osal_queue_t name osal_queue_handle_t osal_queue_create (osal_queue_t *p_queue); -void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, osal_timeout_t msec, tusb_error_t *p_error); +void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error); tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, uint32_t data); #endif diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h index 62a21ae74..24428e614 100644 --- a/tinyusb/osal/osal_common.h +++ b/tinyusb/osal/osal_common.h @@ -56,13 +56,13 @@ #endif #include "common/common.h" - //typedef void (*pfTask)( void * ); enum { OSAL_TIMEOUT_NOTIMEOUT = 0, // for use within ISR, return immediately - OSAL_TIMEOUT_WAIT_FOREVER = 1 + OSAL_TIMEOUT_WAIT_FOREVER = 1, + OSAL_TIMEOUT_NORMAL = 10 // default is 10 msec }; typedef enum { @@ -71,6 +71,12 @@ typedef enum { OSAL_PRIO_HIGH }osal_prio_t; +static inline uint32_t osal_tick_from_msec(uint32_t msec) ATTR_CONST ATTR_ALWAYS_INLINE; +static inline uint32_t osal_tick_from_msec(uint32_t msec) +{ + return (msec * TUSB_CFG_OS_TICKS_PER_SECOND)/1000; +} + #ifdef __cplusplus } #endif diff --git a/tinyusb/osal/osal_none.c b/tinyusb/osal/osal_none.c index d32b00225..4a66f0dc3 100644 --- a/tinyusb/osal/osal_none.c +++ b/tinyusb/osal/osal_none.c @@ -35,10 +35,33 @@ * This file is part of the tiny usb stack. */ -#include "osal_none.h" +#include "tusb_option.h" #if TUSB_CFG_OS == TUSB_OS_NONE +#define _TINY_USB_SOURCE_FILE_ + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include "osal_none.h" + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ +static volatile uint32_t osal_tick_current = 0; + +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ +volatile uint32_t osal_tick_get(void) +{ + return osal_tick_current; +} +void osal_tick_tock(void) +{ + osal_tick_current++; +} #endif diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index 84373b6de..6aab4e594 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -57,7 +57,11 @@ #include "osal_common.h" -typedef uint32_t osal_timeout_t; +//--------------------------------------------------------------------+ +// TICK API +//--------------------------------------------------------------------+ +void osal_tick_tock(void); +uint32_t osal_tick_get(void); //--------------------------------------------------------------------+ // TASK API @@ -76,6 +80,7 @@ typedef uint32_t osal_timeout_t; //#define osal_task_create(code, name, stack_depth, parameters, prio) #define OSAL_TASK_LOOP \ + static uint32_t timeout = 0;\ static uint16_t state = 0;\ switch(state)\ @@ -85,6 +90,7 @@ typedef uint32_t osal_timeout_t; #define OSAL_TASK_LOOP_END \ default:\ state = 0; + //--------------------------------------------------------------------+ // Semaphore API //--------------------------------------------------------------------+ @@ -108,11 +114,15 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se #define osal_semaphore_wait(sem_hdl, msec, p_error) \ do {\ + timeout = osal_tick_get();\ state = __LINE__; case __LINE__:\ - if( (*sem_hdl) == 0 ) \ - return;\ - else\ - (*sem_hdl)--; /*TODO mutex hal_interrupt_disable consideration*/\ + if( *(sem_hdl) == 0 ) {\ + if ( timeout + osal_tick_from_msec(msec) < osal_tick_get() ) /* time out */ \ + *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ + else\ + return;\ + } else\ + (*(sem_hdl))--; /*TODO mutex hal_interrupt_disable consideration*/\ }while(0) //--------------------------------------------------------------------+ |
