@@ -212,28 +212,12 @@ static usbh_dev0_t _dev0;
212212// TODO: hub can has its own simpler struct to save memory
213213CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices [TOTAL_DEVICES ];
214214
215- // Mutex for claiming endpoint, only needed when using with preempted RTOS
216- #if TUSB_OPT_MUTEX
217- static osal_mutex_def_t _usbh_mutexdef ;
218- static osal_mutex_t _usbh_mutex ;
219-
220- TU_ATTR_ALWAYS_INLINE static inline void usbh_lock (void )
221- {
222- osal_mutex_lock (_usbh_mutex , OSAL_TIMEOUT_WAIT_FOREVER );
223- }
224-
225- TU_ATTR_ALWAYS_INLINE static inline void usbh_unlock (void )
226- {
227- osal_mutex_unlock (_usbh_mutex );
228- }
229-
215+ // Mutex for claiming endpoint
216+ #if OSAL_MUTEX_REQUIRED
217+ static osal_mutex_def_t _usbh_mutexdef ;
218+ static osal_mutex_t _usbh_mutex ;
230219#else
231-
232- #define _usbh_mutex NULL
233-
234- #define usbh_lock ()
235- #define usbh_unlock ()
236-
220+ #define _usbh_mutex NULL
237221#endif
238222
239223// Event queue
@@ -277,8 +261,6 @@ static bool usbh_control_xfer_cb (uint8_t daddr, uint8_t ep_addr, xfer_result_t
277261// TODO rework time-related function later
278262void osal_task_delay (uint32_t msec )
279263{
280- (void ) msec ;
281-
282264 const uint32_t start = hcd_frame_number (_usbh_controller );
283265 while ( ( hcd_frame_number (_usbh_controller ) - start ) < msec ) {}
284266}
@@ -352,8 +334,8 @@ bool tuh_init(uint8_t controller_id)
352334 _usbh_q = osal_queue_create ( & _usbh_qdef );
353335 TU_ASSERT (_usbh_q != NULL );
354336
355- #if TUSB_OPT_MUTEX
356- // Mutex
337+ #if OSAL_MUTEX_REQUIRED
338+ // Init mutex
357339 _usbh_mutex = osal_mutex_create (& _usbh_mutexdef );
358340 TU_ASSERT (_usbh_mutex );
359341#endif
@@ -537,8 +519,7 @@ bool tuh_control_xfer (tuh_xfer_t* xfer)
537519
538520 uint8_t const daddr = xfer -> daddr ;
539521
540- // TODO probably better to use semaphore as resource management than mutex
541- usbh_lock ();
522+ (void ) osal_mutex_lock (_usbh_mutex , OSAL_TIMEOUT_WAIT_FOREVER );
542523
543524 bool const is_idle = (_ctrl_xfer .stage == CONTROL_STAGE_IDLE );
544525 if (is_idle )
@@ -553,7 +534,7 @@ bool tuh_control_xfer (tuh_xfer_t* xfer)
553534 _ctrl_xfer .user_data = xfer -> user_data ;
554535 }
555536
556- usbh_unlock ( );
537+ ( void ) osal_mutex_unlock ( _usbh_mutex );
557538
558539 TU_VERIFY (is_idle );
559540 const uint8_t rhport = usbh_get_rhport (daddr );
@@ -597,9 +578,9 @@ bool tuh_control_xfer (tuh_xfer_t* xfer)
597578
598579TU_ATTR_ALWAYS_INLINE static inline void _set_control_xfer_stage (uint8_t stage )
599580{
600- usbh_lock ( );
581+ ( void ) osal_mutex_lock ( _usbh_mutex , OSAL_TIMEOUT_WAIT_FOREVER );
601582 _ctrl_xfer .stage = stage ;
602- usbh_unlock ( );
583+ ( void ) osal_mutex_unlock ( _usbh_mutex );
603584}
604585
605586static void _xfer_complete (uint8_t daddr , xfer_result_t result )
0 commit comments