This file manages the USB host mass-storage task.
Definition in file host_mass_storage_task.h.
#include "conf_usb.h"
#include "usb_host_task.h"
#include "fs_com.h"
Go to the source code of this file.
Defines | |
#define | DEVICE_TO_HOST 0x01 |
#define | DIR_LOCAL_IN_NAME "IN" |
#define | DIR_LOCAL_OUT_NAME "OUT" |
#define | DIR_USB_IN_NAME "IN" |
#define | DIR_USB_OUT_NAME "OUT" |
#define | FULL_SYNC (DEVICE_TO_HOST | HOST_TO_DEVICE) |
#define | HOST_TO_DEVICE 0x02 |
#define | Is_host_ms_configured() (ms_connected && !Is_host_suspended()) |
Functions | |
void | host_mass_storage_task (void *pvParameters) |
This function manages the host mass-storage task. | |
void | host_mass_storage_task_init (void) |
This function initializes the host mass-storage task. | |
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, Bool bDeleteSrc) |
Bool | host_mass_storage_task_sync_drives (signed short FsNavId, U8 sync_direction, const char *pcdir_name, Bool bDeleteSrc) |
Synchronize the contents of two drives (limited to files). | |
void | host_sof_action (void) |
host_sof_action | |
Variables | |
volatile Bool | ms_connected |
#define DEVICE_TO_HOST 0x01 |
Definition at line 72 of file host_mass_storage_task.h.
Referenced by e_usbsys_cp_cfg_to_local(), e_usbsys_cp_web_to_local(), and host_mass_storage_task_sync_drives().
#define DIR_LOCAL_IN_NAME "IN" |
Definition at line 77 of file host_mass_storage_task.h.
#define DIR_LOCAL_OUT_NAME "OUT" |
Definition at line 76 of file host_mass_storage_task.h.
#define DIR_USB_IN_NAME "IN" |
Definition at line 80 of file host_mass_storage_task.h.
#define DIR_USB_OUT_NAME "OUT" |
Definition at line 79 of file host_mass_storage_task.h.
#define FULL_SYNC (DEVICE_TO_HOST | HOST_TO_DEVICE) |
Definition at line 74 of file host_mass_storage_task.h.
#define HOST_TO_DEVICE 0x02 |
Definition at line 73 of file host_mass_storage_task.h.
Referenced by e_usbsys_cp_logs_to_key(), e_usbsys_mv_logs_to_key(), host_mass_storage_task_copy_tree(), and host_mass_storage_task_sync_drives().
#define Is_host_ms_configured | ( | ) | (ms_connected && !Is_host_suspended()) |
Definition at line 67 of file host_mass_storage_task.h.
void host_mass_storage_task | ( | void * | pvParameters | ) |
This function manages the host mass-storage task.
pvParameters | Input. Unused. |
Definition at line 109 of file host_mass_storage_task.c.
References configTSK_USB_HMS_PERIOD, log_ms_dev_connected, LOG_STR, ms_connected, and ms_new_device_connected.
Referenced by host_mass_storage_task_init().
00110 { 00111 U8 i; 00112 U8 max_lun; 00113 U32 capacity; 00114 00115 portTickType xLastWakeTime; 00116 00117 xLastWakeTime = xTaskGetTickCount(); 00118 while (TRUE) 00119 { 00120 vTaskDelayUntil(&xLastWakeTime, configTSK_USB_HMS_PERIOD); 00121 00122 // First, check the host controller is in full operating mode with the 00123 // B-device attached and enumerated 00124 if (Is_host_ready()) 00125 { 00126 // Display Start-of-Frame counter on LEDs 00127 // LED_Display_Field(0x7E, sof_cnt >> 5); 00128 00129 // New device connection (executed only once after device connection) 00130 if (ms_new_device_connected) 00131 { 00132 ms_new_device_connected = FALSE; 00133 00134 // For all supported interfaces 00135 for (i = 0; i < Get_nb_supported_interface(); i++) 00136 { 00137 // If mass-storage class 00138 if (Get_class(i) == MS_CLASS) 00139 { 00140 ms_connected = TRUE; 00141 LOG_STR(log_ms_dev_connected); 00142 00143 // Get correct physical pipes associated with IN/OUT endpoints 00144 if (Is_ep_in(i, 0)) 00145 { // Yes, associate it with the IN pipe 00146 g_pipe_ms_in = Get_ep_pipe(i, 0); 00147 g_pipe_ms_out = Get_ep_pipe(i, 1); 00148 } 00149 else 00150 { // No, invert... 00151 g_pipe_ms_in = Get_ep_pipe(i, 1); 00152 g_pipe_ms_out = Get_ep_pipe(i, 0); 00153 } 00154 00155 // Get the number of LUNs in the connected mass-storage device 00156 max_lun = host_get_lun(); 00157 00158 // Initialize all USB drives 00159 for (host_selected_lun = 0; host_selected_lun < max_lun; host_selected_lun++) 00160 { 00161 host_ms_inquiry(); 00162 host_read_capacity(host_selected_lun, &capacity); 00163 host_ms_request_sense(); 00164 // while (host_test_unit_ready(host_selected_lun) != CTRL_GOOD); 00165 for( i=0; i<3; i++) 00166 { 00167 if( host_test_unit_ready(host_selected_lun) == CTRL_GOOD ) 00168 { 00169 host_read_capacity(host_selected_lun, &capacity); 00170 break; 00171 } 00172 } 00173 } 00174 break; 00175 } 00176 } 00177 } 00178 } 00179 } 00180 }
void host_mass_storage_task_init | ( | void | ) |
This function initializes the host mass-storage task.
Definition at line 89 of file host_mass_storage_task.c.
References configTSK_USB_HMS_NAME, configTSK_USB_HMS_PRIORITY, configTSK_USB_HMS_STACK_SIZE, host_mass_storage_task(), ms_connected, ms_new_device_connected, and sof_cnt.
Referenced by b_usbsys_start().
00090 { 00091 sof_cnt = 0; 00092 ms_new_device_connected = FALSE; 00093 ms_connected = FALSE; 00094 00095 xTaskCreate(host_mass_storage_task, 00096 configTSK_USB_HMS_NAME, 00097 configTSK_USB_HMS_STACK_SIZE, 00098 NULL, 00099 configTSK_USB_HMS_PRIORITY, 00100 NULL); 00101 }
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, | |||
Bool | bDeleteSrc | |||
) |
Bool host_mass_storage_task_sync_drives | ( | signed short | FsNavId, | |
U8 | sync_direction, | |||
const char * | pcdir_name, | |||
Bool | bDeleteSrc | |||
) |
Synchronize the contents of two drives (limited to files).
FsNavId | signed short: the file system navigator id to use. | |
sync_direction | U8: DEVICE_TO_HOST, HOST_TO_DEVICE or FULL_SYNC | |
pcdir_name | const char *: directory name to consider. | |
bDeleteSrc | Bool: if TRUE delete the src directory content. |
Definition at line 368 of file host_mass_storage_task.c.
References DEVICE_TO_HOST, host_mass_storage_task_copy_tree(), and HOST_TO_DEVICE.
Referenced by prv_e_usbsys_sync_cp_ukey().
00370 { 00371 // First, check the host controller is in full operating mode with the 00372 // B-device attached and enumerated 00373 if (!Is_host_ready()) return FALSE; 00374 00375 fsaccess_take_mutex(); // Take the fs resource. 00376 00377 // First synchronization: USB/OUT -> Local/IN 00378 if (sync_direction & DEVICE_TO_HOST) 00379 { 00380 if( FALSE == host_mass_storage_task_copy_tree( pcdir_name, DEVICE_TO_HOST, bDeleteSrc ) ) 00381 { 00382 00383 fsaccess_give_mutex(); // Release the fs resource. 00384 return FALSE; 00385 } 00386 } 00387 00388 // Second synchronization: Local/pcdir_name -> USB/pcdir_name 00389 if (sync_direction & HOST_TO_DEVICE) 00390 { 00391 if( FALSE == host_mass_storage_task_copy_tree( pcdir_name, HOST_TO_DEVICE, bDeleteSrc ) ) 00392 { 00393 fsaccess_give_mutex(); // Release the fs resource. 00394 return FALSE; 00395 } 00396 } 00397 00398 fsaccess_give_mutex(); // Release the fs resource. 00399 return TRUE; 00400 }