summaryrefslogtreecommitdiff
path: root/tinyusb/osal/osal_none.h
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-02-01 12:00:34 +0700
committerhathach <[email protected]>2013-02-01 12:25:02 +0700
commitaab92b40d2e904e8ad85386e4a4f3b59e84eb844 (patch)
treef8099f4075a1e7612b6522d1c8902d56aa13b3f7 /tinyusb/osal/osal_none.h
parent9e3785e7e1bd5bac3c8e24477edbde12cc09dd4b (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/osal_none.h')
-rw-r--r--tinyusb/osal/osal_none.h20
1 files changed, 15 insertions, 5 deletions
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)
//--------------------------------------------------------------------+