mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-14 04:18:56 +00:00
enhance usbd: add usbd_defer_func()
This commit is contained in:
parent
af268ce951
commit
e3591ac682
@ -161,23 +161,30 @@ typedef enum
|
||||
USBD_EVT_XFER_DONE,
|
||||
USBD_EVT_SOF,
|
||||
|
||||
|
||||
USBD_EVT_FUNC_CALL
|
||||
}usbd_eventid_t;
|
||||
|
||||
typedef struct ATTR_ALIGNED(4)
|
||||
{
|
||||
uint8_t rhport;
|
||||
uint8_t event_id;
|
||||
uint8_t sub_event_id;
|
||||
uint8_t reserved;
|
||||
|
||||
union {
|
||||
// USBD_EVT_SETUP_RECEIVED
|
||||
tusb_control_request_t setup_received;
|
||||
|
||||
struct { // USBD_EVENTID_XFER_DONE
|
||||
// USBD_EVT_XFER_DONE
|
||||
struct {
|
||||
uint8_t ep_addr;
|
||||
uint8_t result;
|
||||
uint32_t xferred_byte;
|
||||
}xfer_done;
|
||||
|
||||
// USBD_EVT_FUNC_CALL
|
||||
struct {
|
||||
void (*func)(void*);
|
||||
void* param;
|
||||
}func_call;
|
||||
};
|
||||
} usbd_task_event_t;
|
||||
|
||||
@ -287,7 +294,7 @@ static tusb_error_t usbd_main_st(void)
|
||||
{
|
||||
if ( usbd_class_drivers[i].xfer_cb )
|
||||
{
|
||||
usbd_class_drivers[i].xfer_cb( event.rhport, event.xfer_done.ep_addr, (tusb_event_t) event.sub_event_id, event.xfer_done.xferred_byte);
|
||||
usbd_class_drivers[i].xfer_cb( event.rhport, event.xfer_done.ep_addr, (tusb_event_t) event.xfer_done.result, event.xfer_done.xferred_byte);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -582,24 +589,24 @@ void dcd_xfer_complete(uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes,
|
||||
if (xferred_bytes) osal_semaphore_post_isr( _usbd_ctrl_sem );
|
||||
}else
|
||||
{
|
||||
usbd_task_event_t task_event =
|
||||
usbd_task_event_t event =
|
||||
{
|
||||
.rhport = rhport,
|
||||
.event_id = USBD_EVT_XFER_DONE,
|
||||
.sub_event_id = succeeded ? TUSB_EVENT_XFER_COMPLETE : TUSB_EVENT_XFER_ERROR
|
||||
};
|
||||
|
||||
task_event.xfer_done.ep_addr = ep_addr;
|
||||
task_event.xfer_done.xferred_byte = xferred_bytes;
|
||||
event.xfer_done.ep_addr = ep_addr;
|
||||
event.xfer_done.xferred_byte = xferred_bytes;
|
||||
event.xfer_done.result = succeeded ? TUSB_EVENT_XFER_COMPLETE : TUSB_EVENT_XFER_ERROR;
|
||||
|
||||
osal_queue_send_isr(_usbd_q, &task_event);
|
||||
osal_queue_send_isr(_usbd_q, &event);
|
||||
}
|
||||
|
||||
TU_ASSERT(succeeded, );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// HELPER
|
||||
// Helper
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
|
||||
{
|
||||
@ -623,4 +630,25 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void usbd_defer_func(void (*func)(void*), void* param, bool isr )
|
||||
{
|
||||
usbd_task_event_t event =
|
||||
{
|
||||
.rhport = 0,
|
||||
.event_id = USBD_EVT_FUNC_CALL,
|
||||
};
|
||||
|
||||
event.func_call.func = func;
|
||||
event.func_call.param = param;
|
||||
|
||||
if ( isr )
|
||||
{
|
||||
osal_queue_send_isr(_usbd_q, &event);
|
||||
}else
|
||||
{
|
||||
osal_queue_send(_usbd_q, &event);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -36,6 +36,7 @@
|
||||
#ifndef USBD_PVT_H_
|
||||
#define USBD_PVT_H_
|
||||
|
||||
#include "osal/osal.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -45,17 +46,17 @@
|
||||
extern osal_semaphore_t _usbd_ctrl_sem;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL API
|
||||
// INTERNAL API for stack management
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_error_t usbd_init(void);
|
||||
void usbd_task( void* param);
|
||||
tusb_error_t usbd_init (void);
|
||||
void usbd_task (void* param);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Endpoint helper
|
||||
*------------------------------------------------------------------*/
|
||||
// helper to parse an pair of In and Out endpoint descriptors. They must be consecutive
|
||||
tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in);
|
||||
|
||||
// Carry out Data and Status stage of control transfer
|
||||
//tusb_error_t usbd_control_xfer_st(uint8_t rhport, tusb_dir_t dir, uint8_t * buffer, uint16_t length);
|
||||
|
||||
// Carry out Data and Status stage of control transfer
|
||||
// Must be call in a subtask (_st) function
|
||||
#define usbd_control_xfer_st(_rhport, _dir, _buffer, _len) \
|
||||
@ -72,6 +73,10 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_d
|
||||
}while(0)
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Other Helpers
|
||||
*------------------------------------------------------------------*/
|
||||
void usbd_defer_func( void (*func)(void*), void* param, bool isr );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -146,6 +146,8 @@ static inline bool osal_queue_send_isr(osal_queue_t const queue_hdl, void const
|
||||
return fifo_write( (fifo_t*) queue_hdl, data);
|
||||
}
|
||||
|
||||
#define osal_queue_send osal_queue_send_isr
|
||||
|
||||
static inline void osal_queue_flush(osal_queue_t const queue_hdl)
|
||||
{
|
||||
queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user