This file manages the USB host keyboard HID task.
Definition in file host_keyboard_hid_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_keyboard_hid_task (void) |
This function manages the host keyboard HID task. | |
void | host_keyboard_hid_task_init (void) |
This function initializes the host keyboard HID 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) |
Synchronize the contents of two directories (limited to files). | |
Bool | host_mass_storage_task_sync_drives (U8 sync_direction) |
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_keyboard_hid_task.h.
Referenced by host_mass_storage_task_sync_drives().
#define DIR_LOCAL_IN_NAME "IN" |
Definition at line 77 of file host_keyboard_hid_task.h.
Referenced by host_mass_storage_task_sync_drives().
#define DIR_LOCAL_OUT_NAME "OUT" |
Definition at line 76 of file host_keyboard_hid_task.h.
Referenced by host_mass_storage_task_sync_drives().
#define DIR_USB_IN_NAME "IN" |
Definition at line 80 of file host_keyboard_hid_task.h.
Referenced by host_mass_storage_task_sync_drives().
#define DIR_USB_OUT_NAME "OUT" |
Definition at line 79 of file host_keyboard_hid_task.h.
Referenced by host_mass_storage_task_sync_drives().
#define FULL_SYNC (DEVICE_TO_HOST | HOST_TO_DEVICE) |
Definition at line 74 of file host_keyboard_hid_task.h.
#define HOST_TO_DEVICE 0x02 |
Definition at line 73 of file host_keyboard_hid_task.h.
Referenced by host_mass_storage_task_sync_drives().
#define Is_host_ms_configured | ( | ) | (ms_connected && !Is_host_suspended()) |
Definition at line 67 of file host_keyboard_hid_task.h.
void host_keyboard_hid_task | ( | void | ) |
This function manages the host keyboard HID task.
Definition at line 114 of file host_keyboard_hid_task.c.
References log_ms_dev_connected, LOG_STR, ms_connected, ms_new_device_connected, and sof_cnt.
Referenced by host_keyboard_hid_task_init().
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 // First, check the host controller is in full operating mode with the 00131 // B-device attached and enumerated 00132 if (Is_host_ready()) 00133 { 00134 // Display Start-of-Frame counter on LEDs 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 // New device connection (executed only once after device connection) 00142 if (ms_new_device_connected) 00143 { 00144 ms_new_device_connected = FALSE; 00145 00146 // For all supported interfaces 00147 for (i = 0; i < Get_nb_supported_interface(); i++) 00148 { 00149 // If mass-storage class 00150 if (Get_class(i) == MS_CLASS) 00151 { 00152 ms_connected = TRUE; 00153 LOG_STR(log_ms_dev_connected); 00154 00155 // Get correct physical pipes associated with IN/OUT endpoints 00156 if (Is_ep_in(i, 0)) 00157 { // Yes, associate it with the IN pipe 00158 g_pipe_ms_in = Get_ep_pipe(i, 0); 00159 g_pipe_ms_out = Get_ep_pipe(i, 1); 00160 } 00161 else 00162 { // No, invert... 00163 g_pipe_ms_in = Get_ep_pipe(i, 1); 00164 g_pipe_ms_out = Get_ep_pipe(i, 0); 00165 } 00166 00167 // Get the number of LUNs in the connected mass-storage device 00168 max_lun = host_get_lun(); 00169 00170 // Initialize all USB drives 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 }
void host_keyboard_hid_task_init | ( | void | ) |
This function initializes the host keyboard HID task.
Definition at line 91 of file host_keyboard_hid_task.c.
References host_keyboard_hid_task(), ms_connected, ms_new_device_connected, and sof_cnt.
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 }
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 | |||
) |
Synchronize the contents of two directories (limited to files).
dst_fs_idx | Fs_index *: File system index for destination navigation path | |
dst_dir | const char *: Pointer to destination directory name | |
src_fs_idx | Fs_index *: File system index for source navigation path | |
src_dir | const char *: Pointer to source directory name |
Definition at line 221 of file host_keyboard_hid_task.c.
References ms_str_unicode.
Referenced by host_mass_storage_task_sync_drives().
00222 { 00223 U8 nb_file; 00224 U8 i; 00225 U32 free_space; 00226 U16 file_size; 00227 00228 // First, check the host controller is in full operating mode with the 00229 // B-device attached and enumerated 00230 if (!Is_host_ready()) return FALSE; 00231 00232 // Go to source navigation 00233 nav_gotoindex(src_fs_idx); 00234 if (!goto_code_name(src_dir)) return FALSE; // Check that source directory exists 00235 nav_dir_cd(); // Source directory exists, so go to it 00236 *src_fs_idx = nav_getindex(); // Save navigation position 00237 nav_filelist_first(FS_FILE); // Go to first file 00238 nb_file = nav_filelist_nb(FS_FILE); // Get the number of files in this directory 00239 00240 // Go to destination navigation 00241 nav_gotoindex(dst_fs_idx); 00242 if (!goto_code_name(dst_dir)) // Destination directory does not exist, so create it 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; // Check that destination directory has been created 00247 } 00248 nav_dir_cd(); 00249 *dst_fs_idx = nav_getindex(); 00250 00251 // Get available free space 00252 free_space = nav_partition_space(); 00253 nav_gotoindex(src_fs_idx); 00254 nav_filelist_first(FS_FILE); 00255 00256 // For all files in directory 00257 for (i = 0; i < nb_file; i++) 00258 { 00259 // Get source name to be used as destination name 00260 nav_file_name(ms_str_unicode, MAX_FILE_PATH_LENGTH, FS_NAME_GET); 00261 file_size = nav_file_lgtsector(); // Get file size 00262 if (file_size > free_space) return FALSE; // Check that there is enough free space left 00263 // Update free space (to save time, do no call nav_partition_space() again) 00264 free_space -= file_size; 00265 // Mark source 00266 nav_file_copy(); 00267 // Save current source position 00268 *src_fs_idx = nav_getindex(); 00269 00270 // Go to destination navigation 00271 nav_gotoindex(dst_fs_idx); 00272 if (goto_unicode_name(ms_str_unicode)) // If file already exists 00273 { 00274 nav_file_del(); // Delete it 00275 } 00276 00277 // Paste 00278 nav_file_paste_start(ms_str_unicode); 00279 // Restore previous navigation position 00280 nav_gotoindex(src_fs_idx); 00281 // Copy 00282 while (nav_file_paste_state(FALSE) == COPY_BUSY); 00283 00284 // Restore previous navigation position 00285 nav_gotoindex(src_fs_idx); 00286 nav_filelist_set(0, FS_FIND_NEXT); 00287 } 00288 00289 return TRUE; 00290 }
Bool host_mass_storage_task_sync_drives | ( | U8 | sync_direction | ) |
Synchronize the contents of two drives (limited to files).
sync_direction | U8: DEVICE_TO_HOST, HOST_TO_DEVICE or FULL_SYNC |
Definition at line 302 of file host_keyboard_hid_task.c.
References DEVICE_TO_HOST, DIR_LOCAL_IN_NAME, DIR_LOCAL_OUT_NAME, DIR_USB_IN_NAME, DIR_USB_OUT_NAME, host_mass_storage_task_sync_dir(), and HOST_TO_DEVICE.
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 // First, check the host controller is in full operating mode with the 00310 // B-device attached and enumerated 00311 if (!Is_host_ready()) return FALSE; 00312 00313 nav_reset(); 00314 00315 // Try to mount local drive 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 // Try to mount first USB device drive 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 // First synchronization: USB/OUT -> Local/IN 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 // Restore positions 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 // Second synchronization: Local/OUT -> USB/IN 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 }
volatile Bool ms_connected |
Definition at line 85 of file host_keyboard_hid_task.c.