00001
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include "conf_usb.h"
00051
00052
00053 #if USB_HOST_FEATURE == ENABLED
00054
00055 #include "board.h"
00056 #ifdef FREERTOS_USED
00057 #include "FreeRTOS.h"
00058 #include "task.h"
00059 #endif
00060 #include "conf_usb.h"
00061 #include "usb_drv.h"
00062 #include "usb_host_enum.h"
00063 #include "usb_host_task.h"
00064 #include "host_mem.h"
00065 #include "ctrl_access.h"
00066 #include "navigation.h"
00067 #include "host_mass_storage_task.h"
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078 static const char log_ms_dev_connected[] = "Mass-storage device connected\n";
00079
00080 static U16 sof_cnt;
00081
00082 volatile Bool ms_new_device_connected;
00083 volatile Bool ms_connected;
00084
00085
00089 void host_mass_storage_task_init(void)
00090 {
00091 sof_cnt = 0;
00092 ms_new_device_connected = FALSE;
00093 ms_connected = FALSE;
00094
00095 #ifdef FREERTOS_USED
00096 xTaskCreate(host_mass_storage_task,
00097 configTSK_USB_HMS_NAME,
00098 configTSK_USB_HMS_STACK_SIZE,
00099 NULL,
00100 configTSK_USB_HMS_PRIORITY,
00101 NULL);
00102 #endif // FREERTOS_USED
00103 }
00104
00105
00109 #ifdef FREERTOS_USED
00110 void host_mass_storage_task(void *pvParameters)
00111 #else
00112 void host_mass_storage_task(void)
00113 #endif
00114 {
00115 U8 i;
00116 U8 max_lun;
00117 U32 capacity;
00118
00119 #ifdef FREERTOS_USED
00120 portTickType xLastWakeTime;
00121
00122 xLastWakeTime = xTaskGetTickCount();
00123 while (TRUE)
00124 {
00125 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HMS_PERIOD);
00126
00127 #endif // FREERTOS_USED
00128
00129
00130 if (Is_host_ready())
00131 {
00132 #if BOARD == EVK1100
00133
00134 LED_Display_Field(LED_MONO0_GREEN |
00135 LED_MONO1_GREEN |
00136 LED_MONO2_GREEN |
00137 LED_MONO3_GREEN,
00138 sof_cnt >> 5);
00139 #elif BOARD == EVK1101 || BOARD == UC3C_EK || BOARD == EVK1104 || BOARD == EVK1105 || BOARD == UC3C_EK
00140
00141 LED_Display_Field(LED0 |
00142 LED1,
00143 sof_cnt >> 5);
00144 #else
00145 #error The display of the SOFs must be defined here.
00146 #endif
00147
00148
00149 if (ms_new_device_connected)
00150 {
00151 ms_new_device_connected = FALSE;
00152
00153
00154 for (i = 0; i < Get_nb_supported_interface(); i++)
00155 {
00156
00157 if (Get_class(i) == MS_CLASS)
00158 {
00159 ms_connected = TRUE;
00160 LOG_STR(log_ms_dev_connected);
00161
00162
00163 if (Is_ep_in(i, 0))
00164 {
00165 g_pipe_ms_in = Get_ep_pipe(i, 0);
00166 g_pipe_ms_out = Get_ep_pipe(i, 1);
00167 }
00168 else
00169 {
00170 g_pipe_ms_in = Get_ep_pipe(i, 1);
00171 g_pipe_ms_out = Get_ep_pipe(i, 0);
00172 }
00173
00174
00175 max_lun = host_get_lun();
00176
00177
00178 for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++)
00179 {
00180 host_ms_inquiry();
00181 host_read_capacity(host_selected_lun, &capacity);
00182 host_ms_request_sense();
00183 for (i = 0; i < 3; i++)
00184 {
00185 if (host_test_unit_ready(host_selected_lun) == CTRL_GOOD)
00186 {
00187 host_read_capacity(host_selected_lun, &capacity);
00188 break;
00189 }
00190 }
00191 }
00192 break;
00193 }
00194 }
00195 }
00196 }
00197 #ifdef FREERTOS_USED
00198 }
00199 #endif
00200 }
00201
00202
00210 void host_sof_action(void)
00211 {
00212 sof_cnt++;
00213 }
00214
00215
00216 #endif // USB_HOST_FEATURE == ENABLED