void MainTask(void) { USB_Init(); USB_EnableIAD(); _AddCDC(); _AddHID(); USB_Start(); BSP_SetLED(0); OS_CREATETASK(&_HIDTCB, "HIDTask", _HIDTask, 200, _aHIDStack); while (1) { char ac[64]; int NumBytesReceived; // // Wait for configuration // while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) { BSP_ToggleLED(0); USB_OS_Delay(50); } BSP_SetLED(0); NumBytesReceived = USB_CDC_Receive(&ac[0], sizeof(ac)); if (NumBytesReceived > 0) { USB_CDC_Write(&ac[0], NumBytesReceived); } } }
/**************************************************************************** * Name : USBInterfaceReceiveTask * * * * Inputs : None * * Outputs : None * * Returns : None * * * * Description : This is a Receive Task which handles all the USB data * * Receive. * * 1. When USB is not ready it goes into teh delayed state * * 2. When USB is ready it blocks to receive data over USB. * * 3. Task unblocks when data is received or error on USB * * occurred. When data is received it calls the virtual * * driver functions to pass the entire received packet to * * the application. * * * ***************************************************************************** */ void USBInterfaceReceiveTask(void) { GF_UINT8 num_bytes_received; GF_UINT8 indx; /* Set the Initial interface layer state to Receive */ usb_int_state = RX_READY; while (1) { while ((USB_GetState() & (USB_STAT_CONFIGURED | USB_STAT_SUSPENDED)) != USB_STAT_CONFIGURED) { ///\Todo 20150723 -> Change from 50ms to 150ms dur to larger Objcet USB_OS_Delay(150); } num_bytes_received = 0; /* Blocking call to receive bytes on USB */ num_bytes_received = USB_CDC_Receive(usb_rxd_buf, GENI_TGM_MAX_SIZE); while (usb_int_state != RX_READY) { USB_OS_Delay(10); } /* If any bytes is received then process it.*/ if (num_bytes_received > 0) { for (indx = 0; indx < num_bytes_received; indx++) { SaveRxByte(USB_CH_NO, usb_rxd_buf[indx]); } } } }