/****************************************************************************** * * @name Virtual_Com_App * * @brief * * @param None * * @return None * *****************************************************************************/ void Virtual_Com_App(void) { /* User Code */ if ((0 != g_recv_size) && (0xFFFFFFFF != g_recv_size)) { int32_t i; /* Copy Buffer to Send Buff */ for (i = 0; i < g_recv_size; i++) { //USB_PRINTF("Copied: %c\n", g_curr_recv_buf[i]); g_curr_send_buf[g_send_size++] = g_curr_recv_buf[i]; } g_recv_size = 0; } if (g_send_size) { uint8_t error; uint32_t size = g_send_size; g_send_size = 0; error = USB_Class_CDC_Send_Data(g_app_handle, DIC_BULK_IN_ENDPOINT, g_curr_send_buf, size); if (error != USB_OK) { /* Failure to send Data Handling code here */ } } #if USBCFG_DEV_KEEP_ALIVE_MODE #if (OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_SDK) if( (waitfordatareceive)) { if(comopen == 1) { OS_Time_delay(30); comopen = 0; } USB_PRINTF("Enter lowpower\r\n"); usb_hal_khci_disable_interrupts((uint32_t)USB0, INTR_TOKDNE); POWER_SYS_SetMode(kDemoVlps, kPowerManagerPolicyAgreement); waitfordatareceive = 0; usb_hal_khci_enable_interrupts((uint32_t)USB0,INTR_TOKDNE); USB_PRINTF("Exit lowpower\r\n"); } #endif #endif return; }
/***************************************************************************** * * @name TestApp_Init * * @brief This function is the entry for Audio generator * * @param None * * @return None ** *****************************************************************************/ void Audio_TestApp_Init(void) { #if (OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_MQX) wav_buff = OS_Mem_alloc_uncached_align(AUDIO_ENDPOINT_PACKET_SIZE, 32); if(wav_buff == NULL) { printf("OS_Mem_alloc_uncached_align fail in audio composite example \r\n"); return ; } #endif while(TRUE) { while(!start_app) { OS_Time_delay(1); ; } start_app = FALSE; printf("USB_Prepare_Data \r\n"); USB_Prepare_Data(); USB_Class_Audio_Send_Data(g_audio_handle, AUDIO_ENDPOINT, wav_buff, AUDIO_ENDPOINT_PACKET_SIZE); } }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : main (Main_Task if using MQX) * Returned Value : none * Comments : * Execution starts here * *END*--------------------------------------------------------------------*/ void keyboard_task(uint32_t param) { usb_status status = USB_OK; static unsigned char *buffer; if(keyboard_inited == 0) { g_hid_com = (hid_command_t*) OS_Mem_alloc_zero(sizeof(hid_command_t)); buffer = (unsigned char *)OS_Mem_alloc_uncached(HID_KEYBOARD_BUFFER_SIZE); if (buffer == NULL) { printf("\nMemory allocation failed. STATUS: %x", status); //fflush(stdout); return; } keyboard_inited = 1; } if (OS_Event_check_bit(usb_keyboard_event, USB_Keyboard_Event_CTRL)) { OS_Event_clear(usb_keyboard_event, USB_Keyboard_Event_CTRL); switch (g_kbd_hid_device.dev_state) { case USB_DEVICE_CONFIGURED: status = usb_host_open_dev_interface(host_handle, g_kbd_hid_device.dev_handle, g_kbd_hid_device.intf_handle, (void *) & g_kbd_hid_device.class_handle); if(status != USB_OK) { printf("\nError in _usb_hostdev_select_interface: %x", status); //fflush(stdout); return; } break; case USB_DEVICE_IDLE: break; case USB_DEVICE_INTERFACED: g_hid_com->class_ptr = g_kbd_hid_device.class_handle; g_hid_com->callback_fn = usb_host_hid_keyboard_recv_callback; g_hid_com->callback_param = 0; OS_Event_clear(usb_keyboard_event, USB_Keyboard_Event_DATA); status = usb_class_hid_recv_data(g_hid_com, (unsigned char *) buffer, HID_KEYBOARD_BUFFER_SIZE); if(status != USB_OK) { printf("\nError in _usb_host_recv_data: %x", status); //fflush(stdout); } break; } } if (OS_Event_check_bit(usb_keyboard_event, USB_Keyboard_Event_DATA)) { if (g_kbd_hid_device.dev_state == USB_DEVICE_INTERFACED) { process_kbd_buffer((unsigned char *)buffer); OS_Event_clear(usb_keyboard_event, USB_Keyboard_Event_DATA); g_hid_com->class_ptr = g_kbd_hid_device.class_handle; g_hid_com->callback_fn = usb_host_hid_keyboard_recv_callback; g_hid_com->callback_param = 0; //printf("\nClass handle %x", g_kbd_hid_device.class_handle); OS_Event_clear(usb_keyboard_event, USB_Keyboard_Event_DATA); status = usb_class_hid_recv_data(g_hid_com, (unsigned char *) buffer, HID_KEYBOARD_BUFFER_SIZE); if(status != USB_OK) { printf("\nError in _usb_host_recv_data: %x", status); } } } #if (OS_ADAPTER_ACTIVE_OS == OS_ADAPTER_MQX) OS_Time_delay(1); #endif }