Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/device/usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,10 +803,8 @@ void tud_task_ext(uint32_t timeout_ms, bool in_isr) {
break;
}

#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO
// return if there is no more events, for application to run other background
if (osal_queue_empty(_usbd_q)) { return; }
#endif
// allow to exit tud_task() if there is no event in the next run
timeout_ms = 0;
}
}

Expand Down
13 changes: 11 additions & 2 deletions src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ bool usbh_defer_func_ms_async(uint32_t ms, tusb_defer_func_t func, uintptr_t par
TU_LOG_USBH("USBH schedule function after %u ms\r\n", (unsigned int)ms);
_usbh_data.call_after.func = func;
_usbh_data.call_after.arg = param;
_usbh_data.call_after.at_ms = tusb_time_millis_api() + ms;
// add one to ensure we wait at least 'ms' milliseconds
_usbh_data.call_after.at_ms = tusb_time_millis_api() + ms + 1;
return true;
}

Expand Down Expand Up @@ -610,11 +611,19 @@ bool tuh_task_event_ready(void) {
}

#if CFG_TUH_HUB
if (!osal_queue_empty(_usbh_daq)) {
if (_usbh_data.enumerating_daddr == TUSB_INDEX_INVALID_8 &&
!osal_queue_empty(_usbh_daq)) {
return true;
}
#endif

if (_usbh_data.call_after.func) {
int32_t remain_ms = (int32_t)(_usbh_data.call_after.at_ms - tusb_time_millis_api());
if (remain_ms <= 0) {
return true;
}
}

return false;
}

Expand Down
27 changes: 23 additions & 4 deletions src/osal/osal_mynewt.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,24 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
return os_mutex_release(mutex_hdl) == OS_OK;
}

TU_ATTR_ALWAYS_INLINE static inline os_time_t _osal_ms2tick(uint32_t msec) {
if (msec == OSAL_TIMEOUT_WAIT_FOREVER) {
return OS_TIMEOUT_NEVER;
}
if (msec == 0) {
return 0;
}

os_time_t ticks = os_time_ms_to_ticks32(msec);

// If 1 tick > 1 ms, still wait at least 1 tick for non-zero timeout.
if (ticks == 0) {
ticks = 1;
}

return ticks;
}

//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+
Expand Down Expand Up @@ -161,10 +179,11 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_delete(osal_queue_t qhdl) {
}

TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec) {
(void) msec; // os_eventq_get() does not take timeout, always behave as msec = WAIT_FOREVER

struct os_event* ev;
ev = os_eventq_get(&qhdl->evq);
struct os_eventq* evq = &qhdl->evq;
struct os_event* ev = os_eventq_poll(&evq, 1, _osal_ms2tick(msec));
if (!ev) {
return false;
}

memcpy(data, ev->ev_arg, qhdl->item_sz); // copy message
os_memblock_put(&qhdl->mpool, ev->ev_arg); // put back mem block
Expand Down
4 changes: 0 additions & 4 deletions src/tusb_option.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,6 @@
#define CFG_TUSB_OS OPT_OS_NONE
#endif

#ifndef CFG_TUSB_OS_HAS_SCHEDULER
#define CFG_TUSB_OS_HAS_SCHEDULER (CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO)
#endif

#ifndef CFG_TUSB_OS_INC_PATH
#ifndef CFG_TUSB_OS_INC_PATH_DEFAULT
#define CFG_TUSB_OS_INC_PATH_DEFAULT
Expand Down
Loading