diff options
| author | hathach <[email protected]> | 2013-02-01 12:39:39 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-02-01 12:39:39 +0700 |
| commit | c24d461d19634f4b592697e698fa31c59a7128c3 (patch) | |
| tree | 27177e0a9166729c8f70c798568559279908754d /tinyusb/osal | |
| parent | aab92b40d2e904e8ad85386e4a4f3b59e84eb844 (diff) | |
add timeout to queue_receive and update test code for it
Diffstat (limited to 'tinyusb/osal')
| -rw-r--r-- | tinyusb/osal/osal_common.h | 4 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.c | 2 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 12 |
3 files changed, 11 insertions, 7 deletions
diff --git a/tinyusb/osal/osal_common.h b/tinyusb/osal/osal_common.h index 24428e614..f641f970c 100644 --- a/tinyusb/osal/osal_common.h +++ b/tinyusb/osal/osal_common.h @@ -61,8 +61,8 @@ enum { OSAL_TIMEOUT_NOTIMEOUT = 0, // for use within ISR, return immediately - OSAL_TIMEOUT_WAIT_FOREVER = 1, - OSAL_TIMEOUT_NORMAL = 10 // default is 10 msec + OSAL_TIMEOUT_NORMAL = 10, // default is 10 msec + OSAL_TIMEOUT_WAIT_FOREVER = 0xFFFF0000 }; typedef enum { diff --git a/tinyusb/osal/osal_none.c b/tinyusb/osal/osal_none.c index 4a66f0dc3..b30f7ecda 100644 --- a/tinyusb/osal/osal_none.c +++ b/tinyusb/osal/osal_none.c @@ -54,7 +54,7 @@ static volatile uint32_t osal_tick_current = 0; //--------------------------------------------------------------------+ // IMPLEMENTATION //--------------------------------------------------------------------+ -volatile uint32_t osal_tick_get(void) +uint32_t osal_tick_get(void) { return osal_tick_current; } diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index 6aab4e594..56277d90c 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -175,12 +175,16 @@ static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, return TUSB_ERROR_NONE; } -#define osal_queue_receive(queue_hdl, p_data, msec) \ +#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \ do {\ + timeout = osal_tick_get();\ state = __LINE__; case __LINE__:\ - if( queue_hdl-> count == 0 ) \ - return;\ - else{\ + if( queue_hdl-> count == 0 ) {\ + if ( timeout + osal_tick_from_msec(msec) < osal_tick_get() ) /* time out */ \ + *(p_error) = TUSB_ERROR_OSAL_TIMEOUT;\ + else\ + return;\ + } else{\ /*TODO mutex lock hal_interrupt_disable */\ *p_data = queue_hdl->buffer[queue_hdl->rd_idx];\ queue_hdl->rd_idx = (queue_hdl->rd_idx + 1) % queue_hdl->depth;\ |
