complete osal queue, semaphore static API
This commit is contained in:
parent
d6794074e1
commit
61cc8666fc
|
@ -46,6 +46,16 @@
|
||||||
#include "usbd.h"
|
#include "usbd.h"
|
||||||
#include "device/usbd_pvt.h"
|
#include "device/usbd_pvt.h"
|
||||||
|
|
||||||
|
#define USBD_TASK_QUEUE_DEPTH 16
|
||||||
|
|
||||||
|
#ifndef CFG_TUD_TASK_STACKSIZE
|
||||||
|
#define CFG_TUD_TASK_STACKSIZE 150
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef CFG_TUD_TASK_PRIO
|
||||||
|
#define CFG_TUD_TASK_PRIO 0
|
||||||
|
#endif
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// MACRO CONSTANT TYPEDEF
|
// MACRO CONSTANT TYPEDEF
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -73,7 +83,7 @@ typedef struct {
|
||||||
}usbd_device_info_t;
|
}usbd_device_info_t;
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// INTERNAL VARIABLE
|
// Class & Device Driver
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t usbd_enum_buffer[CFG_TUD_ENUM_BUFFER_SIZE];
|
CFG_TUSB_ATTR_USBRAM CFG_TUSB_MEM_ALIGN uint8_t usbd_enum_buffer[CFG_TUD_ENUM_BUFFER_SIZE];
|
||||||
|
|
||||||
|
@ -129,34 +139,10 @@ enum { USBD_CLASS_DRIVER_COUNT = sizeof(usbd_class_drivers) / sizeof(usbd_class_
|
||||||
// .bDeviceClass =
|
// .bDeviceClass =
|
||||||
//};
|
//};
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
// INTERNAL FUNCTION
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number);
|
|
||||||
static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer);
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// APPLICATION API
|
// DCD Event
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
bool tud_n_mounted(uint8_t rhport)
|
|
||||||
{
|
|
||||||
return usbd_devices[rhport].state == TUSB_DEVICE_STATE_CONFIGURED;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool tud_n_set_descriptors(uint8_t rhport, tud_desc_init_t const* desc_cfg)
|
|
||||||
{
|
|
||||||
_usbd_descs[rhport] = *desc_cfg;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
// IMPLEMENTATION
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
|
|
||||||
//------------- OSAL Task -------------//
|
|
||||||
enum { USBD_TASK_QUEUE_DEPTH = 16 };
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
USBD_EVENTID_SETUP_RECEIVED = 1,
|
USBD_EVENTID_SETUP_RECEIVED = 1,
|
||||||
|
@ -183,18 +169,34 @@ typedef struct ATTR_ALIGNED(4)
|
||||||
|
|
||||||
VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct");
|
VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct");
|
||||||
|
|
||||||
#ifndef CFG_TUD_TASK_STACKSIZE
|
/*------------- event queue -------------*/
|
||||||
#define CFG_TUD_TASK_STACKSIZE 150
|
OSAL_QUEUE_DEF(_usbd_qdef, USBD_TASK_QUEUE_DEPTH, usbd_task_event_t);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef CFG_TUD_TASK_PRIO
|
|
||||||
#define CFG_TUD_TASK_PRIO 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static osal_queue_t _usbd_q;
|
static osal_queue_t _usbd_q;
|
||||||
|
|
||||||
|
/*------------- control transfer semaphore -------------*/
|
||||||
|
static osal_semaphore_def_t _usbd_sem_def;
|
||||||
/*static*/ osal_semaphore_t _usbd_ctrl_sem;
|
/*static*/ osal_semaphore_t _usbd_ctrl_sem;
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// INTERNAL FUNCTION
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
static tusb_error_t proc_set_config_req(uint8_t rhport, uint8_t config_number);
|
||||||
|
static uint16_t get_descriptor(uint8_t rhport, tusb_control_request_t const * const p_request, uint8_t const ** pp_buffer);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// APPLICATION API
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
bool tud_n_mounted(uint8_t rhport)
|
||||||
|
{
|
||||||
|
return usbd_devices[rhport].state == TUSB_DEVICE_STATE_CONFIGURED;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tud_n_set_descriptors(uint8_t rhport, tud_desc_init_t const* desc_cfg)
|
||||||
|
{
|
||||||
|
_usbd_descs[rhport] = *desc_cfg;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -212,10 +214,10 @@ tusb_error_t usbd_init (void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//------------- Task init -------------//
|
//------------- Task init -------------//
|
||||||
_usbd_q = osal_queue_create(USBD_TASK_QUEUE_DEPTH, sizeof(usbd_task_event_t));
|
_usbd_q = osal_queue_create(&_usbd_qdef);
|
||||||
VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
|
VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
|
||||||
|
|
||||||
_usbd_ctrl_sem = osal_semaphore_create(1, 0);
|
_usbd_ctrl_sem = osal_semaphore_create(&_usbd_sem_def);
|
||||||
VERIFY(_usbd_q, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
|
VERIFY(_usbd_q, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
|
||||||
|
|
||||||
osal_task_create(usbd_task, "usbd", CFG_TUD_TASK_STACKSIZE, NULL, CFG_TUD_TASK_PRIO);
|
osal_task_create(usbd_task, "usbd", CFG_TUD_TASK_STACKSIZE, NULL, CFG_TUD_TASK_PRIO);
|
||||||
|
@ -509,7 +511,7 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event)
|
||||||
case USBD_BUS_EVENT_RESET :
|
case USBD_BUS_EVENT_RESET :
|
||||||
memclr_(&usbd_devices[rhport], sizeof(usbd_device_info_t));
|
memclr_(&usbd_devices[rhport], sizeof(usbd_device_info_t));
|
||||||
osal_queue_flush(_usbd_q);
|
osal_queue_flush(_usbd_q);
|
||||||
osal_semaphore_reset(_usbd_ctrl_sem);
|
osal_semaphore_reset_isr(_usbd_ctrl_sem);
|
||||||
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++)
|
||||||
{
|
{
|
||||||
if ( usbd_class_drivers[i].close ) usbd_class_drivers[i].close( rhport );
|
if ( usbd_class_drivers[i].close ) usbd_class_drivers[i].close( rhport );
|
||||||
|
|
|
@ -83,11 +83,15 @@ static inline void osal_task_delay(uint32_t msec)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// QUEUE API
|
// QUEUE API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
#define OSAL_QUEUE_DEF(_name, _depth, _type) \
|
||||||
|
uint8_t _name##_##buf[_depth*sizeof(_type)];\
|
||||||
|
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };\
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
uint16_t queue_sz;
|
uint16_t depth;
|
||||||
uint16_t item_sz;
|
uint16_t item_sz;
|
||||||
void* pool;
|
void* buf;
|
||||||
|
|
||||||
StaticQueue_t sq;
|
StaticQueue_t sq;
|
||||||
}osal_queue_def_t;
|
}osal_queue_def_t;
|
||||||
|
@ -96,7 +100,7 @@ typedef QueueHandle_t osal_queue_t;
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
return xQueueCreateStatic(qdef->queue_sz, qdef->item_sz, qdef->pool, &qdef->sq);
|
return xQueueCreateStatic(qdef->depth, qdef->item_sz, qdef->buf, &qdef->sq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error)
|
static inline void osal_queue_receive (osal_queue_t const queue_hdl, void *p_data, uint32_t msec, tusb_error_t *p_error)
|
||||||
|
|
Loading…
Reference in New Issue