add timeout to queue_receive and update test code for it
This commit is contained in:
		| @@ -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 { | ||||
|   | ||||
| @@ -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; | ||||
| } | ||||
|   | ||||
| @@ -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;\ | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach