Merge pull request #414 from hathach/add-queue-is-empty

added tud_task_event_ready()
This commit is contained in:
Ha Thach 2020-05-20 15:31:09 +07:00 committed by GitHub
commit dc5445e2f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 41 additions and 12 deletions

View File

@ -339,6 +339,14 @@ static void usbd_reset(uint8_t rhport)
} }
} }
bool tud_task_event_ready(void)
{
// Skip if stack is not initialized
if ( !tusb_inited() ) return false;
return !osal_queue_empty(_usbd_q);
}
/* USB Device Driver task /* USB Device Driver task
* This top level thread manages all device controller event and delegates events to class-specific drivers. * This top level thread manages all device controller event and delegates events to class-specific drivers.
* This should be called periodically within the mainloop or rtos thread. * This should be called periodically within the mainloop or rtos thread.

View File

@ -47,6 +47,9 @@ bool tud_init (void);
// Task function should be called in main/rtos loop // Task function should be called in main/rtos loop
void tud_task (void); void tud_task (void);
// Check if there is pending events need proccessing by tud_task()
bool tud_task_event_ready(void);
// Interrupt handler, name alias to DCD // Interrupt handler, name alias to DCD
#define tud_int_handler dcd_int_handler #define tud_int_handler dcd_int_handler

View File

@ -78,8 +78,9 @@ static inline bool osal_mutex_unlock(osal_mutex_t mutex_hdl);
//------------- Queue -------------// //------------- Queue -------------//
static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef); static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef);
static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data); static inline bool osal_queue_receive(osal_queue_t qhdl, void* data);
static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr); static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr);
static inline bool osal_queue_empty(osal_queue_t qhdl);
#if 0 // TODO remove subtask related macros later #if 0 // TODO remove subtask related macros later
// Sub Task // Sub Task

View File

@ -118,14 +118,19 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq); return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
} }
static inline bool osal_queue_receive(osal_queue_t const queue_hdl, void* data) static inline bool osal_queue_receive(osal_queue_t qhdl, void* data)
{ {
return xQueueReceive(queue_hdl, data, portMAX_DELAY); return xQueueReceive(qhdl, data, portMAX_DELAY);
} }
static inline bool osal_queue_send(osal_queue_t const queue_hdl, void const * data, bool in_isr) static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr)
{ {
return in_isr ? xQueueSendToBackFromISR(queue_hdl, data, NULL) : xQueueSendToBack(queue_hdl, data, OSAL_TIMEOUT_WAIT_FOREVER); return in_isr ? xQueueSendToBackFromISR(qhdl, data, NULL) : xQueueSendToBack(qhdl, data, OSAL_TIMEOUT_WAIT_FOREVER);
}
static inline bool osal_queue_empty(osal_queue_t qhdl)
{
return uxQueueMessagesWaiting(qhdl) == 0;
} }
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -125,7 +125,7 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
return (osal_queue_t) qdef; return (osal_queue_t) qdef;
} }
static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data) static inline bool osal_queue_receive(osal_queue_t qhdl, void* data)
{ {
struct os_event* ev; struct os_event* ev;
ev = os_eventq_get(&qhdl->evq); ev = os_eventq_get(&qhdl->evq);
@ -137,7 +137,7 @@ static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
return true; return true;
} }
static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr) static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr)
{ {
(void) in_isr; (void) in_isr;
@ -161,6 +161,12 @@ static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, b
return true; return true;
} }
static inline bool osal_queue_empty(osal_queue_t qhdl)
{
return STAILQ_EMPTY(&qhdl->evq.evq_list);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -142,7 +142,7 @@ typedef osal_queue_def_t* osal_queue_t;
}\ }\
} }
// lock queue by disable usb isr // lock queue by disable USB interrupt
static inline void _osal_q_lock(osal_queue_t qhdl) static inline void _osal_q_lock(osal_queue_t qhdl)
{ {
(void) qhdl; (void) qhdl;
@ -176,8 +176,7 @@ static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
return (osal_queue_t) qdef; return (osal_queue_t) qdef;
} }
// non blocking static inline bool osal_queue_receive(osal_queue_t qhdl, void* data)
static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
{ {
_osal_q_lock(qhdl); _osal_q_lock(qhdl);
bool success = tu_fifo_read(&qhdl->ff, data); bool success = tu_fifo_read(&qhdl->ff, data);
@ -186,7 +185,7 @@ static inline bool osal_queue_receive(osal_queue_t const qhdl, void* data)
return success; return success;
} }
static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, bool in_isr) static inline bool osal_queue_send(osal_queue_t qhdl, void const * data, bool in_isr)
{ {
if (!in_isr) { if (!in_isr) {
_osal_q_lock(qhdl); _osal_q_lock(qhdl);
@ -203,6 +202,13 @@ static inline bool osal_queue_send(osal_queue_t const qhdl, void const * data, b
return success; return success;
} }
static inline bool osal_queue_empty(osal_queue_t qhdl)
{
// Skip queue lock/unlock since this function is primarily called
// with interrupt disabled before going into low power mode
return tu_fifo_empty(&qhdl->ff);
}
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif