enhance serial host app
This commit is contained in:
parent
1d28b2bd10
commit
a98bae0d19
|
@ -118,15 +118,14 @@ void cdc_serial_app_init(void)
|
||||||
//------------- main task -------------//
|
//------------- main task -------------//
|
||||||
OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||||
{
|
{
|
||||||
static uint8_t dev_addr;
|
// This task can be separated into 2 Task : sending & receiving.
|
||||||
|
|
||||||
OSAL_TASK_LOOP_BEGIN
|
OSAL_TASK_LOOP_BEGIN
|
||||||
|
|
||||||
for(dev_addr=1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
//------------- send characters got from uart terminal to the first CDC device -------------//
|
||||||
|
for(uint8_t dev_addr=1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
||||||
{
|
{
|
||||||
if ( tusbh_cdc_serial_is_mounted(dev_addr) )
|
if ( tusbh_cdc_serial_is_mounted(dev_addr) )
|
||||||
{
|
{
|
||||||
//------------- send characters got from uart terminal -------------//
|
|
||||||
int ch_tx = getchar();
|
int ch_tx = getchar();
|
||||||
if ( ch_tx > 0 )
|
if ( ch_tx > 0 )
|
||||||
{ // USB is much faster than serial, here we assume usb is always complete. There could be some characters missing
|
{ // USB is much faster than serial, here we assume usb is always complete. There could be some characters missing
|
||||||
|
@ -137,10 +136,13 @@ OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||||
tusbh_cdc_send(dev_addr, serial_out_buffer, 1, false); // no need for interrupt on serial out pipe
|
tusbh_cdc_send(dev_addr, serial_out_buffer, 1, false); // no need for interrupt on serial out pipe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break; // demo app only communicate with the first CDC-capable device
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//------------- print out received characters -------------//
|
//------------- print out received characters -------------//
|
||||||
tusb_error_t error;
|
tusb_error_t error;
|
||||||
osal_semaphore_wait(sem_hdl, 100, &error);
|
osal_semaphore_wait(sem_hdl, 100, &error); // timeout to allow getchar from uart terminal can be executed
|
||||||
|
|
||||||
if ( TUSB_ERROR_NONE == error)
|
if ( TUSB_ERROR_NONE == error)
|
||||||
{
|
{
|
||||||
|
@ -148,16 +150,16 @@ OSAL_TASK_FUNCTION( cdc_serial_app_task ) (void* p_task_para)
|
||||||
{
|
{
|
||||||
printf("%c", serial_in_buffer[i]);
|
printf("%c", serial_in_buffer[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(uint8_t dev_addr=1; dev_addr <= TUSB_CFG_HOST_DEVICE_MAX; dev_addr++)
|
||||||
|
{
|
||||||
|
if ( tusbh_cdc_serial_is_mounted(dev_addr) )
|
||||||
|
{
|
||||||
tusbh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true);
|
tusbh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true);
|
||||||
}
|
|
||||||
|
|
||||||
break; // demo app only communicate with the first CDC-capable device
|
break; // demo app only communicate with the first CDC-capable device
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev_addr > TUSB_CFG_HOST_DEVICE_MAX)
|
|
||||||
{ // there is no CDC device connected
|
|
||||||
osal_task_delay(1000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OSAL_TASK_LOOP_END
|
OSAL_TASK_LOOP_END
|
||||||
|
|
Loading…
Reference in New Issue