mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
refractor cdc serial host app.
fix RTOS cdc_serial_app_task executing forever
This commit is contained in:
parent
064d0cf5a9
commit
1d28b2bd10
@ -181,6 +181,7 @@
|
||||
<option id="gnu.c.link.option.paths.916077707" name="Library search path (-L)" superClass="gnu.c.link.option.paths"/>
|
||||
<option id="com.crt.advproject.link.gcc.hdrlib.1015545513" name="Use C library" superClass="com.crt.advproject.link.gcc.hdrlib" value="com.crt.advproject.gcc.link.hdrlib.codered.nohost" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.link.fpu.834301167" name="Floating point" superClass="com.crt.advproject.link.fpu" value="com.crt.advproject.link.fpu.fpv4" valueType="enumerated"/>
|
||||
<option id="com.crt.advproject.link.gcc.multicore.slave.589644699" superClass="com.crt.advproject.link.gcc.multicore.slave"/>
|
||||
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.388300407" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
|
||||
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
|
||||
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
|
||||
@ -208,10 +209,7 @@
|
||||
<projectStorage><?xml version="1.0" encoding="UTF-8"?>
|
||||
<TargetConfig>
|
||||
<Properties property_0="" property_2="LPC18x7_43x7_2x512_BootA.cfx" property_3="NXP" property_4="LPC4357" property_count="5" version="60000"/>
|
||||
<infoList vendor="NXP">
|
||||
<info chip="LPC4357" flash_driver="LPC18x7_43x7_2x512_BootA.cfx" match_id="0x0" name="LPC4357" resetscript="LPC18LPC43InternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp">
|
||||
<chip>
|
||||
<name>LPC4357</name>
|
||||
<infoList vendor="NXP"><info chip="LPC4357" flash_driver="LPC18x7_43x7_2x512_BootA.cfx" match_id="0x0" name="LPC4357" resetscript="LPC18LPC43InternalFLASHBootResetscript.scp" stub="crt_emu_lpc18_43_nxp"><chip><name>LPC4357</name>
|
||||
<family>LPC43xx</family>
|
||||
<vendor>NXP (formerly Philips)</vendor>
|
||||
<reset board="None" core="Real" sys="Real"/>
|
||||
@ -286,8 +284,7 @@
|
||||
<peripheralInstance derived_from="SPI" determined="infoFile" id="SPI" location="0x40100000"/>
|
||||
<peripheralInstance derived_from="SGPIO" determined="infoFile" id="SGPIO" location="0x40101000"/>
|
||||
</chip>
|
||||
<processor>
|
||||
<name gcc_name="cortex-m4">Cortex-M4</name>
|
||||
<processor><name gcc_name="cortex-m4">Cortex-M4</name>
|
||||
<family>Cortex-M</family>
|
||||
</processor>
|
||||
<link href="nxp_lpc43xx_peripheral.xme" show="embed" type="simple"/>
|
||||
|
@ -50,13 +50,15 @@
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
//--------------------------------------------------------------------+
|
||||
OSAL_TASK_DEF(cdc_serial_app_task, 128, CDC_SERIAL_APP_TASK_PRIO);
|
||||
OSAL_QUEUE_DEF(queue_def, QUEUE_SERIAL_DEPTH, uint8_t);
|
||||
OSAL_SEM_DEF(serial_semaphore);
|
||||
|
||||
static osal_queue_handle_t queue_hdl;
|
||||
static osal_semaphore_handle_t sem_hdl;
|
||||
|
||||
static uint8_t serial_in_buffer[32] TUSB_CFG_ATTR_USBRAM;
|
||||
static uint8_t serial_out_buffer[32] TUSB_CFG_ATTR_USBRAM;
|
||||
|
||||
static uint8_t received_bytes; // set by transfer complete callback
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// tinyusb Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
@ -64,7 +66,12 @@ void tusbh_cdc_mounted_cb(uint8_t dev_addr)
|
||||
{ // application set-up
|
||||
printf("\na CDC device is mounted\n");
|
||||
|
||||
osal_queue_flush(queue_hdl);
|
||||
memclr_(serial_in_buffer, sizeof(serial_in_buffer));
|
||||
memclr_(serial_out_buffer, sizeof(serial_out_buffer));
|
||||
received_bytes = 0;
|
||||
|
||||
osal_semaphore_reset(sem_hdl);
|
||||
tusbh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // schedule first transfer
|
||||
}
|
||||
|
||||
void tusbh_cdc_unmounted_cb(uint8_t dev_addr)
|
||||
@ -79,13 +86,13 @@ void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_
|
||||
switch(event)
|
||||
{
|
||||
case TUSB_EVENT_XFER_COMPLETE:
|
||||
for(uint32_t i=0; i<xferred_bytes; i++)
|
||||
{
|
||||
osal_queue_send(queue_hdl, serial_in_buffer+i);
|
||||
}
|
||||
received_bytes = xferred_bytes;
|
||||
osal_semaphore_post(sem_hdl); // notify main task
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_ERROR: break; // ignore
|
||||
case TUSB_EVENT_XFER_ERROR:
|
||||
xferred_bytes = 0; // ignore
|
||||
break;
|
||||
|
||||
case TUSB_EVENT_XFER_STALLED:
|
||||
default :
|
||||
@ -102,10 +109,8 @@ void tusbh_cdc_xfer_isr(uint8_t dev_addr, tusb_event_t event, cdc_pipeid_t pipe_
|
||||
//--------------------------------------------------------------------+
|
||||
void cdc_serial_app_init(void)
|
||||
{
|
||||
memclr_(serial_in_buffer, sizeof(serial_in_buffer));
|
||||
|
||||
queue_hdl = osal_queue_create( OSAL_QUEUE_REF(queue_def) );
|
||||
ASSERT_PTR( queue_hdl, VOID_RETURN);
|
||||
sem_hdl = osal_semaphore_create( OSAL_SEM_REF(serial_semaphore) );
|
||||
ASSERT_PTR( sem_hdl, VOID_RETURN);
|
||||
|
||||
ASSERT( TUSB_ERROR_NONE == osal_task_create(OSAL_TASK_REF(cdc_serial_app_task)), VOID_RETURN);
|
||||
}
|
||||
@ -113,9 +118,11 @@ void cdc_serial_app_init(void)
|
||||
//------------- main task -------------//
|
||||
OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||
{
|
||||
static uint8_t dev_addr;
|
||||
|
||||
OSAL_TASK_LOOP_BEGIN
|
||||
|
||||
for(uint8_t dev_addr=0; dev_addr< TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
||||
for(dev_addr=1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
||||
{
|
||||
if ( tusbh_cdc_serial_is_mounted(dev_addr) )
|
||||
{
|
||||
@ -133,14 +140,14 @@ OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||
|
||||
//------------- print out received characters -------------//
|
||||
tusb_error_t error;
|
||||
do{
|
||||
uint8_t ch_rx = 0;
|
||||
osal_queue_receive(queue_hdl, &ch_rx, OSAL_TIMEOUT_NOTIMEOUT, &error); // instant return
|
||||
if (error == TUSB_ERROR_NONE && ch_rx) printf("%c", ch_rx);
|
||||
}while (error == TUSB_ERROR_NONE);
|
||||
osal_semaphore_wait(sem_hdl, 100, &error);
|
||||
|
||||
if ( !tusbh_cdc_is_busy(dev_addr, CDC_PIPE_DATA_IN) )
|
||||
if ( TUSB_ERROR_NONE == error)
|
||||
{
|
||||
for(uint8_t i=0; i<received_bytes; i++)
|
||||
{
|
||||
printf("%c", serial_in_buffer[i]);
|
||||
}
|
||||
tusbh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true);
|
||||
}
|
||||
|
||||
@ -148,6 +155,11 @@ OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||
}
|
||||
}
|
||||
|
||||
if (dev_addr > TUSB_CFG_HOST_DEVICE_MAX)
|
||||
{ // there is no CDC device connected
|
||||
osal_task_delay(1000);
|
||||
}
|
||||
|
||||
OSAL_TASK_LOOP_END
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user