static bool ai_sd_mmc_nav_drive_set(uint8_t n, ai_async_status_t *status) { extern void ai_usb_ms_init_drive(void); bool s; *status = CMD_DONE; // Notify the audio interface layer that a new connection is performed ai_usb_ms_new_connection(); ai_usb_ms_init_drive(); s = nav_drive_set(LUN_ID_2); if (!s) { *status = CMD_ERROR; return false; } return true; }
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 }