mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-28 16:20:26 +00:00
refractor usbd_task as wrapper for body task
IAR device_freertos works well except for CDC with typing many characters (like Keil)
This commit is contained in:
parent
df352651d0
commit
124dffd2cd
5856
demos/device/device_freertos/device_freertos.ewp
Normal file
5856
demos/device/device_freertos/device_freertos.ewp
Normal file
File diff suppressed because it is too large
Load Diff
34
demos/device/device_freertos/device_freertos.eww
Normal file
34
demos/device/device_freertos/device_freertos.eww
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||||
|
|
||||||
|
<workspace>
|
||||||
|
<project>
|
||||||
|
<path>$WS_DIR$\device_freertos.ewp</path>
|
||||||
|
</project>
|
||||||
|
<batchBuild>
|
||||||
|
<batchDefinition>
|
||||||
|
<name>all</name>
|
||||||
|
<member>
|
||||||
|
<project>device_freertos</project>
|
||||||
|
<configuration>Board EA4357</configuration>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<project>device_freertos</project>
|
||||||
|
<configuration>Board LPCXpresso1347</configuration>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<project>device_freertos</project>
|
||||||
|
<configuration>Board LPCXpresso1769</configuration>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<project>device_freertos</project>
|
||||||
|
<configuration>Board NGX4330</configuration>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<project>device_freertos</project>
|
||||||
|
<configuration>Board rf1ghznode</configuration>
|
||||||
|
</member>
|
||||||
|
</batchDefinition>
|
||||||
|
</batchBuild>
|
||||||
|
</workspace>
|
||||||
|
|
||||||
|
|
@ -5562,37 +5562,40 @@
|
|||||||
</file>
|
</file>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<name>bsp</name>
|
<name>boards</name>
|
||||||
<group>
|
<file>
|
||||||
<name>boards</name>
|
<name>$PROJ_DIR$\..\..\..\boards\board.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\board.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\embedded_artists\ea4357\board_ea4357.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\embedded_artists\ea4357\board_ea4357.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\microbuilder\board_lpc4357usb.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\microbuilder\board_lpc4357usb.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\lpcxpresso\board_lpcxpresso11u14.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\lpcxpresso\board_lpcxpresso11u14.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\lpcxpresso\board_lpcxpresso1347.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\lpcxpresso\board_lpcxpresso1347.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\lpcxpresso\board_lpcxpresso1769.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\lpcxpresso\board_lpcxpresso1769.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\ngx\board_ngx4330.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\ngx\board_ngx4330.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\microbuilder\board_rf1ghznode.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\embedded_artists\oem_base_board\pca9532.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\embedded_artists\oem_base_board\pca9532.c</name>
|
||||||
<file>
|
</file>
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\printf_retarget.c</name>
|
<file>
|
||||||
</file>
|
<name>$PROJ_DIR$\..\..\..\boards\printf_retarget.c</name>
|
||||||
</group>
|
</file>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<name>mcu</name>
|
||||||
<group>
|
<group>
|
||||||
<name>lpc11uxx</name>
|
<name>lpc11uxx</name>
|
||||||
<excluded>
|
<excluded>
|
||||||
@ -5694,9 +5697,6 @@
|
|||||||
<name>$PROJ_DIR$\..\..\..\mcu\lpc43xx\CMSIS_LPC43xx_DriverLib\src\system_LPC43xx.c</name>
|
<name>$PROJ_DIR$\..\..\..\mcu\lpc43xx\CMSIS_LPC43xx_DriverLib\src\system_LPC43xx.c</name>
|
||||||
</file>
|
</file>
|
||||||
</group>
|
</group>
|
||||||
<file>
|
|
||||||
<name>$PROJ_DIR$\..\..\..\boards\microbuilder\board_rf1ghznode.c</name>
|
|
||||||
</file>
|
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<name>tinyusb</name>
|
<name>tinyusb</name>
|
||||||
|
@ -145,6 +145,87 @@ OSAL_SEM_DEF(usbd_control_xfer_semaphore_def);
|
|||||||
static osal_queue_handle_t usbd_queue_hdl;
|
static osal_queue_handle_t usbd_queue_hdl;
|
||||||
/*static*/ osal_semaphore_handle_t usbd_control_xfer_sem_hdl; // TODO may need to change to static with wrapper function
|
/*static*/ osal_semaphore_handle_t usbd_control_xfer_sem_hdl; // TODO may need to change to static with wrapper function
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// IMPLEMENTATION
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
tusb_error_t usbd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * const p_request);
|
||||||
|
static tusb_error_t usbd_body_subtask(void);
|
||||||
|
|
||||||
|
tusb_error_t usbd_init (void)
|
||||||
|
{
|
||||||
|
ASSERT_STATUS ( dcd_init() );
|
||||||
|
|
||||||
|
//------------- Task init -------------//
|
||||||
|
usbd_queue_hdl = osal_queue_create( OSAL_QUEUE_REF(usbd_queue_def) );
|
||||||
|
ASSERT_PTR(usbd_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED);
|
||||||
|
|
||||||
|
usbd_control_xfer_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(usbd_control_xfer_semaphore_def) );
|
||||||
|
ASSERT_PTR(usbd_queue_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
|
||||||
|
|
||||||
|
ASSERT_STATUS( osal_task_create( OSAL_TASK_REF(usbd_task) ));
|
||||||
|
|
||||||
|
//------------- Descriptor Check -------------//
|
||||||
|
ASSERT(tusbd_descriptor_pointers.p_device != NULL && tusbd_descriptor_pointers.p_configuration != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||||
|
|
||||||
|
//------------- class init -------------//
|
||||||
|
for (uint8_t class_code = TUSB_CLASS_AUDIO; class_code < USBD_CLASS_DRIVER_COUNT; class_code++)
|
||||||
|
{
|
||||||
|
if ( usbd_class_drivers[class_code].init )
|
||||||
|
{
|
||||||
|
usbd_class_drivers[class_code].init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return TUSB_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// To enable the TASK_ASSERT style (quick return on false condition) in a real RTOS, a task must act as a wrapper
|
||||||
|
// and is used mainly to call subtasks. Within a subtask return statement can be called freely, the task with
|
||||||
|
// forever loop cannot have any return at all.
|
||||||
|
OSAL_TASK_FUNCTION(usbd_task, p_task_para)
|
||||||
|
{
|
||||||
|
(void) p_task_para; // suppress compiler warnings
|
||||||
|
|
||||||
|
OSAL_TASK_LOOP_BEGIN
|
||||||
|
usbd_body_subtask();
|
||||||
|
OSAL_TASK_LOOP_END
|
||||||
|
}
|
||||||
|
|
||||||
|
static tusb_error_t usbd_body_subtask(void)
|
||||||
|
{
|
||||||
|
OSAL_VAR usbd_task_event_t event;
|
||||||
|
|
||||||
|
OSAL_SUBTASK_BEGIN
|
||||||
|
|
||||||
|
tusb_error_t error;
|
||||||
|
error = TUSB_ERROR_NONE;
|
||||||
|
|
||||||
|
osal_queue_receive(usbd_queue_hdl, &event, OSAL_TIMEOUT_WAIT_FOREVER, &error);
|
||||||
|
SUBTASK_ASSERT_STATUS(error);
|
||||||
|
|
||||||
|
if ( USBD_EVENTID_SETUP_RECEIVED == event.event_id )
|
||||||
|
{
|
||||||
|
OSAL_SUBTASK_INVOKED_AND_WAIT( usbd_control_request_subtask(event.coreid, &event.setup_received), error );
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
uint8_t class_index;
|
||||||
|
class_index = std_class_code_to_index( event.xfer_done.edpt_hdl.class_code );
|
||||||
|
|
||||||
|
if (usbd_class_drivers[class_index].xfer_cb)
|
||||||
|
{
|
||||||
|
usbd_class_drivers[class_index].xfer_cb( event.xfer_done.edpt_hdl, (tusb_event_t) event.sub_event_id, event.xfer_done.xferred_byte);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
hal_debugger_breakpoint(); // something wrong, no one claims the isr's source
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
OSAL_SUBTASK_END
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// CONTROL REQUEST
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
tusb_error_t usbd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * const p_request)
|
tusb_error_t usbd_control_request_subtask(uint8_t coreid, tusb_control_request_t const * const p_request)
|
||||||
{
|
{
|
||||||
OSAL_SUBTASK_BEGIN
|
OSAL_SUBTASK_BEGIN
|
||||||
@ -223,71 +304,6 @@ tusb_error_t usbd_control_request_subtask(uint8_t coreid, tusb_control_request_t
|
|||||||
OSAL_SUBTASK_END
|
OSAL_SUBTASK_END
|
||||||
}
|
}
|
||||||
|
|
||||||
// To enable the TASK_ASSERT style (quick return on false condition) in a real RTOS, a task must act as a wrapper
|
|
||||||
// and is used mainly to call subtasks. Within a subtask return statement can be called freely, the task with
|
|
||||||
// forever loop cannot have any return at all.
|
|
||||||
OSAL_TASK_FUNCTION(usbd_task, p_task_para)
|
|
||||||
{
|
|
||||||
OSAL_TASK_LOOP_BEGIN
|
|
||||||
|
|
||||||
OSAL_VAR usbd_task_event_t event;
|
|
||||||
tusb_error_t error;
|
|
||||||
error = TUSB_ERROR_NONE;
|
|
||||||
|
|
||||||
osal_queue_receive(usbd_queue_hdl, &event, OSAL_TIMEOUT_WAIT_FOREVER, &error);
|
|
||||||
SUBTASK_ASSERT_STATUS(error);
|
|
||||||
|
|
||||||
if ( USBD_EVENTID_SETUP_RECEIVED == event.event_id )
|
|
||||||
{
|
|
||||||
OSAL_SUBTASK_INVOKED_AND_WAIT( usbd_control_request_subtask(event.coreid, &event.setup_received), error );
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
uint8_t class_index;
|
|
||||||
class_index = std_class_code_to_index( event.xfer_done.edpt_hdl.class_code );
|
|
||||||
|
|
||||||
if (usbd_class_drivers[class_index].xfer_cb)
|
|
||||||
{
|
|
||||||
usbd_class_drivers[class_index].xfer_cb( event.xfer_done.edpt_hdl, (tusb_event_t) event.sub_event_id, event.xfer_done.xferred_byte);
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
hal_debugger_breakpoint(); // something wrong, no one claims the isr's source
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
OSAL_TASK_LOOP_END
|
|
||||||
}
|
|
||||||
|
|
||||||
tusb_error_t usbd_init (void)
|
|
||||||
{
|
|
||||||
ASSERT_STATUS ( dcd_init() );
|
|
||||||
|
|
||||||
//------------- Task init -------------//
|
|
||||||
usbd_queue_hdl = osal_queue_create( OSAL_QUEUE_REF(usbd_queue_def) );
|
|
||||||
ASSERT_PTR(usbd_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED);
|
|
||||||
|
|
||||||
usbd_control_xfer_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(usbd_control_xfer_semaphore_def) );
|
|
||||||
ASSERT_PTR(usbd_queue_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
|
|
||||||
|
|
||||||
ASSERT_STATUS( osal_task_create( OSAL_TASK_REF(usbd_task) ));
|
|
||||||
|
|
||||||
//------------- Descriptor Check -------------//
|
|
||||||
ASSERT(tusbd_descriptor_pointers.p_device != NULL && tusbd_descriptor_pointers.p_configuration != NULL, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
|
||||||
|
|
||||||
//------------- class init -------------//
|
|
||||||
for (uint8_t class_code = TUSB_CLASS_AUDIO; class_code < USBD_CLASS_DRIVER_COUNT; class_code++)
|
|
||||||
{
|
|
||||||
if ( usbd_class_drivers[class_code].init )
|
|
||||||
{
|
|
||||||
usbd_class_drivers[class_code].init();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return TUSB_ERROR_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
// CONTROL REQUEST
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
// TODO Host (windows) can get HID report descriptor before set configured
|
// TODO Host (windows) can get HID report descriptor before set configured
|
||||||
// may need to open interface before set configured
|
// may need to open interface before set configured
|
||||||
static tusb_error_t usbd_set_configure_received(uint8_t coreid, uint8_t config_number)
|
static tusb_error_t usbd_set_configure_received(uint8_t coreid, uint8_t config_number)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user