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 "nav_utils.h"
00068 #include "host_keyboard_hid_task.h"
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079 static const char log_ms_dev_connected[] = "Mass-storage device connected\n";
00080
00081 static UNICODE ms_str_unicode[MAX_FILE_PATH_LENGTH];
00082 static U16 sof_cnt;
00083
00084 volatile Bool ms_new_device_connected;
00085 volatile Bool ms_connected;
00086
00087
00091 void host_keyboard_hid_task_init(void)
00092 {
00093 sof_cnt = 0;
00094 ms_new_device_connected = FALSE;
00095 ms_connected = FALSE;
00096
00097 #ifdef FREERTOS_USED
00098 xTaskCreate(host_keyboard_hid_task,
00099 configTSK_USB_HHID_KBD_NAME,
00100 configTSK_USB_HHID_KBD_STACK_SIZE,
00101 NULL,
00102 configTSK_USB_HHID_KBD_PRIORITY,
00103 NULL);
00104 #endif // FREERTOS_USED
00105 }
00106
00107
00111 #ifdef FREERTOS_USED
00112 void host_keyboard_hid_task(void *pvParameters)
00113 #else
00114 void host_keyboard_hid_task(void)
00115 #endif
00116 {
00117 U8 i;
00118 U8 max_lun;
00119 U32 capacity;
00120
00121 #ifdef FREERTOS_USED
00122 portTickType xLastWakeTime;
00123
00124 xLastWakeTime = xTaskGetTickCount();
00125 while (TRUE)
00126 {
00127 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HHID_KBD_PERIOD);
00128
00129 #endif // FREERTOS_USED
00130
00131
00132 if (Is_host_ready())
00133 {
00134
00135 LED_Display_Field(LED_MONO0_GREEN |
00136 LED_MONO1_GREEN |
00137 LED_MONO2_GREEN |
00138 LED_MONO3_GREEN,
00139 sof_cnt >> 5);
00140
00141
00142 if (ms_new_device_connected)
00143 {
00144 ms_new_device_connected = FALSE;
00145
00146
00147 for (i = 0; i < Get_nb_supported_interface(); i++)
00148 {
00149
00150 if (Get_class(i) == MS_CLASS)
00151 {
00152 ms_connected = TRUE;
00153 LOG_STR(log_ms_dev_connected);
00154
00155
00156 if (Is_ep_in(i, 0))
00157 {
00158 g_pipe_ms_in = Get_ep_pipe(i, 0);
00159 g_pipe_ms_out = Get_ep_pipe(i, 1);
00160 }
00161 else
00162 {
00163 g_pipe_ms_in = Get_ep_pipe(i, 1);
00164 g_pipe_ms_out = Get_ep_pipe(i, 0);
00165 }
00166
00167
00168 max_lun = host_get_lun();
00169
00170
00171 for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++)
00172 {
00173 host_ms_inquiry();
00174 host_read_capacity(host_selected_lun, &capacity);
00175 host_ms_request_sense();
00176 for (i = 0; i < 3; i++)
00177 {
00178 if (host_test_unit_ready(host_selected_lun) == CTRL_GOOD)
00179 {
00180 host_read_capacity(host_selected_lun, &capacity);
00181 break;
00182 }
00183 }
00184 }
00185 break;
00186 }
00187 }
00188 }
00189 }
00190 #ifdef FREERTOS_USED
00191 }
00192 #endif
00193 }
00194
00195
00203 void host_sof_action(void)
00204 {
00205 sof_cnt++;
00206 }
00207
00208
00221 Bool host_mass_storage_task_sync_dir(Fs_index *dst_fs_idx, const char *dst_dir, Fs_index *src_fs_idx, const char *src_dir)
00222 {
00223 U8 nb_file;
00224 U8 i;
00225 U32 free_space;
00226 U16 file_size;
00227
00228
00229
00230 if (!Is_host_ready()) return FALSE;
00231
00232
00233 nav_gotoindex(src_fs_idx);
00234 if (!goto_code_name(src_dir)) return FALSE;
00235 nav_dir_cd();
00236 *src_fs_idx = nav_getindex();
00237 nav_filelist_first(FS_FILE);
00238 nb_file = nav_filelist_nb(FS_FILE);
00239
00240
00241 nav_gotoindex(dst_fs_idx);
00242 if (!goto_code_name(dst_dir))
00243 {
00244 str_code_to_unicode_ram(dst_dir, ms_str_unicode);
00245 nav_dir_make(ms_str_unicode);
00246 if (!goto_code_name(dst_dir)) return FALSE;
00247 }
00248 nav_dir_cd();
00249 *dst_fs_idx = nav_getindex();
00250
00251
00252 free_space = nav_partition_space();
00253 nav_gotoindex(src_fs_idx);
00254 nav_filelist_first(FS_FILE);
00255
00256
00257 for (i = 0; i < nb_file; i++)
00258 {
00259
00260 nav_file_name(ms_str_unicode, MAX_FILE_PATH_LENGTH, FS_NAME_GET);
00261 file_size = nav_file_lgtsector();
00262 if (file_size > free_space) return FALSE;
00263
00264 free_space -= file_size;
00265
00266 nav_file_copy();
00267
00268 *src_fs_idx = nav_getindex();
00269
00270
00271 nav_gotoindex(dst_fs_idx);
00272 if (goto_unicode_name(ms_str_unicode))
00273 {
00274 nav_file_del();
00275 }
00276
00277
00278 nav_file_paste_start(ms_str_unicode);
00279
00280 nav_gotoindex(src_fs_idx);
00281
00282 while (nav_file_paste_state(FALSE) == COPY_BUSY);
00283
00284
00285 nav_gotoindex(src_fs_idx);
00286 nav_filelist_set(0, FS_FIND_NEXT);
00287 }
00288
00289 return TRUE;
00290 }
00291
00292
00302 Bool host_mass_storage_task_sync_drives(U8 sync_direction)
00303 {
00304 Fs_index local_index;
00305 Fs_index sav_local_index;
00306 Fs_index usb_index;
00307 Fs_index sav_usb_index;
00308
00309
00310
00311 if (!Is_host_ready()) return FALSE;
00312
00313 nav_reset();
00314
00315
00316 nav_drive_set(LUN_ID_AT45DBX_MEM);
00317 if (!nav_partition_mount()) return FALSE;
00318 local_index = nav_getindex();
00319 sav_local_index = nav_getindex();
00320
00321
00322 nav_drive_set(LUN_ID_MEM_USB);
00323 if (!nav_partition_mount()) return FALSE;
00324 usb_index = nav_getindex();
00325 sav_usb_index = nav_getindex();
00326
00327
00328 if (sync_direction & DEVICE_TO_HOST)
00329 {
00330 if (!host_mass_storage_task_sync_dir(&local_index, DIR_LOCAL_IN_NAME, &usb_index, DIR_USB_OUT_NAME))
00331 return FALSE;
00332 }
00333
00334
00335 nav_gotoindex(&sav_local_index);
00336 local_index = nav_getindex();
00337 nav_gotoindex(&sav_usb_index);
00338 usb_index = nav_getindex();
00339 nav_gotoindex(&local_index);
00340
00341
00342 if (sync_direction & HOST_TO_DEVICE)
00343 {
00344 if (!host_mass_storage_task_sync_dir(&usb_index, DIR_USB_IN_NAME, &local_index, DIR_LOCAL_OUT_NAME))
00345 return FALSE;
00346 }
00347
00348 return TRUE;
00349 }
00350
00351
00352 #endif // USB_HOST_FEATURE == ENABLED