void host_mouse_hid_task(void) #endif { uint8_t i; #ifdef FREERTOS_USED portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); while (true) { vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HHID_MOUSE_PERIOD); #endif // FREERTOS_USED // First, check the host controller is in full operating mode with the // B-device attached and enumerated if (Is_host_ready()) { // New device connection (executed only once after device connection) if (mouse_hid_new_device_connected) { mouse_hid_new_device_connected = false; // For all supported interfaces for (i = 0; i < Get_nb_supported_interface(); i++) { if(Get_class(i)==HID_CLASS && Get_protocol(i)==MOUSE_PROTOCOL) { host_hid_set_idle(HID_IDLE_DURATION_INDEFINITE, HID_REPORT_ID_ALL, i); host_hid_get_report(HID_REPORT_DESCRIPTOR, 0, i); pipe_mouse_in = Get_ep_pipe(i, 0); Host_enable_continuous_in_mode(pipe_mouse_in); Host_unfreeze_pipe(pipe_mouse_in); mouse_hid_connected=true; break; } } } if( Is_host_mouse_hid_configured() ) { if((Is_host_in_received(pipe_mouse_in)) && (Is_host_stall(pipe_mouse_in)==false) ) { Host_reset_pipe_fifo_access(pipe_mouse_in); usb_report[0]= usb_report[1]= usb_report[2]= usb_report[3]=0; host_read_p_rxpacket(pipe_mouse_in, (void*)usb_report, 4, NULL); Host_ack_in_received(pipe_mouse_in); Host_free_in(pipe_mouse_in); new_x = usb_report[1]; new_y = usb_report[2]; mouse_x += new_x; mouse_y += new_y; if( mouse_x<MOUSE_X_MIN ) mouse_x=MOUSE_X_MIN; else if( mouse_x>MOUSE_X_MAX ) mouse_x=MOUSE_X_MAX; if( mouse_y<MOUSE_Y_MIN ) mouse_y=MOUSE_Y_MIN; else if( mouse_y>MOUSE_Y_MAX ) mouse_y=MOUSE_Y_MAX; mouse_b0=usb_report[0] & 1; mouse_b1=usb_report[0] & 2; mouse_b2=usb_report[0] & 4; disp_led_mouse(); disp_ascii_mouse(); } if(Is_host_nak_received(pipe_mouse_in)) { Host_ack_nak_received(pipe_mouse_in); LED_Off(LED_HOST_MOUSE_B0 ); LED_Off(LED_HOST_MOUSE_B1 ); LED_Off(LED_HOST_MOUSE_B2 ); LED_Off(LED_HOST_MOUSE_B3 ); } } } #ifdef FREERTOS_USED } #endif }
void host_mass_storage_task(void) #endif { uint8_t i; uint8_t max_lun; uint32_t capacity; extern volatile uint8_t device_state; uint32_t total_capacity; uint8_t status = CTRL_GOOD; #ifdef FREERTOS_USED portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); while (true) { vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HMS_PERIOD); #endif // FREERTOS_USED // First, check the host controller is in full operating mode with the // B-device attached and enumerated if (Is_host_ready()) { // New device connection (executed only once after device connection) if (ms_new_device_connected) { // For all supported interfaces for (i = 0; i < Get_nb_supported_interface(); i++) { // If mass-storage class if (Get_class(i) == MS_CLASS) { total_capacity = 0; // Get correct physical pipes associated with IN/OUT endpoints if (Is_ep_in(i, 0)) { // Yes, associate it with the IN pipe g_pipe_ms_in = Get_ep_pipe(i, 0); g_pipe_ms_out = Get_ep_pipe(i, 1); } else { // No, invert... g_pipe_ms_in = Get_ep_pipe(i, 1); g_pipe_ms_out = Get_ep_pipe(i, 0); } ms_new_device_connected = false; ms_connected = true; // Get the number of LUNs in the connected mass-storage device max_lun = host_get_lun(); // Initialize all USB drives for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++) { uint32_t retry; if ((status = host_ms_inquiry()) != CTRL_GOOD) break; if ((status = host_ms_request_sense()) != CTRL_GOOD) break; for (retry = 0; retry < 3; retry++) { if ((status = host_test_unit_ready(host_selected_lun)) == CTRL_GOOD) { if ((status = host_read_capacity(host_selected_lun, &capacity)) == CTRL_GOOD) total_capacity += capacity; break; } } } // If busy then restart if (status == CTRL_BUSY || status == CTRL_NO_PRESENT) { ms_connected = false; ms_new_device_connected = true; return; } // If failed then report device not supported if (status == CTRL_FAIL) { device_state = DEVICE_ERROR; Host_device_class_not_supported_action(); ms_connected = false; return; } #ifdef AI_MAXIMAL_CAPACITY_SUPPORTED_MB if (total_capacity > (AI_MAXIMAL_CAPACITY_SUPPORTED_MB*2*1024)) { device_state = DEVICE_ERROR; Host_device_class_not_supported_action(); ms_connected = false; return; } #endif LOG_STR(log_ms_dev_connected); // Notify the Audio Interface of the new connection ai_usb_ms_new_connection(); break; } } } } #ifdef FREERTOS_USED } #endif }
void host_template_task(void) #endif { #if USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE Status_t sta; U16 nb; #endif U8 i; #ifdef FREERTOS_USED portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); while (true) { vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HTP_PERIOD); #endif // FREERTOS_USED // First, check the host controller is in full operating mode with the // B-device attached and enumerated if (Is_host_ready()) { // Put here the code to execute in host mode #if BOARD == EVK1100 // For example, display Start-of-Frame counter on LEDs LED_Display_Field(LED_MONO0_GREEN | LED_MONO1_GREEN | LED_MONO2_GREEN | LED_MONO3_GREEN, sof_cnt >> 5); #elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105 // For example, display Start-of-Frame counter on LEDs LED_Display_Field(LED0 | LED1, sof_cnt >> 5); #else #error The display of the SOFs must be defined here. #endif // New device connection (executed only once after device connection) if (tpl_new_device_connected) { tpl_new_device_connected = false; #if USB_HOST_PIPE_INTERRUPT_TRANSFER == ENABLE // No more pipe interrupt transfer pending busy = false; #endif // For all supported interfaces for (i = 0; i < Get_nb_supported_interface(); i++) { // If vendor-specific class if (Get_class(i) == VENDOR_CLASS) { // Get correct physical pipes associated with IN/OUT endpoints if (Is_ep_in(i, 0)) { // Yes, associate it with the IN pipe pipe_in = Get_ep_pipe(i, 0); pipe_out = Get_ep_pipe(i, 1); } else { // No, invert... pipe_in = Get_ep_pipe(i, 1); pipe_out = Get_ep_pipe(i, 0); } break; } } } #if USB_HOST_PIPE_INTERRUPT_TRANSFER == DISABLE // The sample task sends 64 bytes through OUT pipe LED_On(LED_APPLI_0); sta = host_send_data(pipe_out, sizeof(buf), buf); LED_Off(LED_APPLI_0); // And receives 64 bytes from IN pipe nb = sizeof(buf); LED_On(LED_APPLI_1); sta = host_get_data(pipe_in, &nb, buf); LED_Off(LED_APPLI_1); #else // Similar applicative task under interrupt mode... if (!busy) { busy = true; LED_On(LED_APPLI_0); host_send_data_interrupt(pipe_out, sizeof(buf), buf, host_send_data_callback); LED_Off(LED_APPLI_0); } #endif // Here is an example of an applicative request to go to USB suspend ... if (false/* applicative conditions */) { host_set_feature_remote_wakeup(); Host_request_suspend(); } } // Here an applicative example of resume request... if (Is_host_suspended()/* && applicative conditions */) { Host_request_resume(); } #ifdef FREERTOS_USED } #endif }
void host_keyboard_hid_task(void) #endif { uint8_t i; uint8_t max_lun; uint32_t capacity; #ifdef FREERTOS_USED portTickType xLastWakeTime; xLastWakeTime = xTaskGetTickCount(); while (true) { vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HHID_KBD_PERIOD); #endif // FREERTOS_USED // First, check the host controller is in full operating mode with the // B-device attached and enumerated if (Is_host_ready()) { // Display Start-of-Frame counter on LEDs LED_Display_Field(LED_MONO0_GREEN | LED_MONO1_GREEN | LED_MONO2_GREEN | LED_MONO3_GREEN, sof_cnt >> 5); // New device connection (executed only once after device connection) if (ms_new_device_connected) { ms_new_device_connected = false; // For all supported interfaces for (i = 0; i < Get_nb_supported_interface(); i++) { // If mass-storage class if (Get_class(i) == MS_CLASS) { ms_connected = true; LOG_STR(log_ms_dev_connected); // Get correct physical pipes associated with IN/OUT endpoints if (Is_ep_in(i, 0)) { // Yes, associate it with the IN pipe g_pipe_ms_in = Get_ep_pipe(i, 0); g_pipe_ms_out = Get_ep_pipe(i, 1); } else { // No, invert... g_pipe_ms_in = Get_ep_pipe(i, 1); g_pipe_ms_out = Get_ep_pipe(i, 0); } // Get the number of LUNs in the connected mass-storage device max_lun = host_get_lun(); // Initialize all USB drives for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++) { host_ms_inquiry(); host_read_capacity(host_selected_lun, &capacity); host_ms_request_sense(); for (i = 0; i < 3; i++) { if (host_test_unit_ready(host_selected_lun) == CTRL_GOOD) { host_read_capacity(host_selected_lun, &capacity); break; } } } break; } } } } #ifdef FREERTOS_USED } #endif }