#include "config.h"#include "conf_usb.h"#include "storage_task.h"#include "lib_mcu/usb/usb_drv.h"#include "usb_descriptors.h"#include "modules/usb/device_chap9/usb_standard_request.h"#include "usb_specific_request.h"#include "modules/scsi_decoder/scsi_decoder.h"#include "modules/control_access/ctrl_access.h"
Go to the source code of this file.
Functions | |
| void | usb_mass_storage_cbw (void) |
| void | usb_mass_storage_csw (void) |
| void | storage_task_init (void) |
| void | storage_task (void) |
| void | sof_action () |
| This function increments the cpt_sof counter each times the USB Start Of Frame interrupt subroutine is executed (1ms) Usefull to manage time delays. | |
Variables | |
| volatile U8 | cpt_sof |
| U8 | usb_configuration_nb |
| Bool | g_b_df_protected |
| bit | ms_data_direction |
| static _MEM_TYPE_SLOW_ U8 | dCBWTag [4] |
| _MEM_TYPE_SLOW_ U8 | g_scsi_status |
| _MEM_TYPE_FAST_ U32 | g_scsi_data_remaining |
| bit | ms_multiple_drive |
| _MEM_TYPE_SLOW_ U8 | g_scsi_command [16] |
| U8 | endpoint_status [MAX_EP_NB] |
| _MEM_TYPE_SLOW_ U8 | usb_LUN |
Definition in file storage_task.c.
| void usb_mass_storage_cbw | ( | void | ) |
USB Command Block Wrapper (CBW) management This function decodes the CBW command and stores the SCSI command
| none |
check if dCBWSignature is correct
'U'
'S'
'B'
'C'
Store CBW Tag to be repeated in CSW
if (bmCBWFlags.bit7 == 1) {direction = IN}
Definition at line 152 of file storage_task.c.
References dCBWTag, endpoint_status, EP_MS_IN, EP_MS_OUT, FALSE, g_scsi_command, g_scsi_data_remaining, get_cur_lun(), Is_usb_ms_data_direction_in, LSB0, LSB1, LSB2, LSB3, ms_multiple_drive, MSK_EP_DIR, scsi_decode_command(), TRUE, Usb_ack_receive_out, Usb_enable_stall_handshake, usb_LUN, Usb_read_byte, Usb_select_endpoint, Usb_set_ms_data_direction_in, and Usb_set_ms_data_direction_out.
Referenced by storage_task().
00153 { 00154 bit cbw_error; 00155 U8 c; 00156 U8 dummy; 00157 00158 cbw_error = FALSE; 00159 Usb_select_endpoint(EP_MS_OUT); 00160 if (0x55 != Usb_read_byte()) 00161 { cbw_error = TRUE; } 00162 if (0x53 != Usb_read_byte()) 00163 { cbw_error = TRUE; } 00164 if (0x42 != Usb_read_byte()) 00165 { cbw_error = TRUE; } 00166 if (0x43 != Usb_read_byte()) 00167 { cbw_error = TRUE; } 00168 if (cbw_error) 00169 { 00170 Usb_ack_receive_out(); 00171 Usb_select_endpoint(EP_MS_IN); 00172 Usb_enable_stall_handshake(); 00173 endpoint_status[(EP_MS_IN & MSK_EP_DIR)] = 0x01; 00174 return; 00175 } 00176 00177 dCBWTag[0] = Usb_read_byte(); 00178 dCBWTag[1] = Usb_read_byte(); 00179 dCBWTag[2] = Usb_read_byte(); 00180 dCBWTag[3] = Usb_read_byte(); 00181 00182 LSB0(g_scsi_data_remaining) = Usb_read_byte(); 00183 LSB1(g_scsi_data_remaining) = Usb_read_byte(); 00184 LSB2(g_scsi_data_remaining) = Usb_read_byte(); 00185 LSB3(g_scsi_data_remaining) = Usb_read_byte(); 00186 00187 if (Usb_read_byte() != 0x00) 00188 { 00189 Usb_set_ms_data_direction_in(); 00190 } 00191 else 00192 { 00193 Usb_set_ms_data_direction_out(); 00194 } 00195 00196 usb_LUN = Usb_read_byte(); 00197 00198 if (!ms_multiple_drive) 00199 { 00200 usb_LUN = get_cur_lun(); 00201 } 00202 00203 dummy = Usb_read_byte(); // dummy CBWCBLength read 00204 00205 00206 for (c=0; c<16; c++) // store scsi_command 00207 { 00208 g_scsi_command[c] = Usb_read_byte(); 00209 } 00210 Usb_ack_receive_out(); 00211 00212 if (Is_usb_ms_data_direction_in()) 00213 { 00214 Usb_select_endpoint(EP_MS_IN); 00215 } 00216 00217 if (TRUE != scsi_decode_command()) 00218 { 00219 U8 ep; 00220 Usb_enable_stall_handshake(); 00221 if (Is_usb_ms_data_direction_in()) 00222 { 00223 ep = (EP_MS_IN & MSK_EP_DIR); 00224 }else{ 00225 ep = (EP_MS_OUT & MSK_EP_DIR); 00226 } 00227 endpoint_status[ep] = 0x01; 00228 } 00229 }
| void usb_mass_storage_csw | ( | void | ) |
USB Command Status Wrapper (CSW) management This function sends the status in relation with the last CBW
| none |
write CSW Signature
'U'
'S'
'B'
'S' write stored CBW Tag
write data residue value
write command status
0 -> PASS, 1 -> FAIL
Definition at line 240 of file storage_task.c.
References dCBWTag, EP_CONTROL, EP_MS_IN, EP_MS_OUT, g_scsi_data_remaining, g_scsi_status, Is_usb_endpoint_enabled, Is_usb_endpoint_stall_requested, Is_usb_receive_setup, Is_usb_vbus_low, Is_usb_write_enabled, LSB0, LSB1, LSB2, LSB3, usb_process_request(), Usb_select_endpoint, Usb_send_in, and Usb_write_byte.
Referenced by storage_task().
00241 { 00242 Usb_select_endpoint(EP_MS_IN); 00243 while (Is_usb_endpoint_stall_requested()) 00244 { 00245 if(Is_usb_vbus_low()) return; 00246 Usb_select_endpoint(EP_CONTROL); 00247 if (Is_usb_receive_setup()) { usb_process_request(); } 00248 Usb_select_endpoint(EP_MS_IN); 00249 } 00250 00251 Usb_select_endpoint(EP_MS_OUT); 00252 while (Is_usb_endpoint_stall_requested()) 00253 { 00254 if(Is_usb_vbus_low()) return; 00255 Usb_select_endpoint(EP_CONTROL); 00256 if (Is_usb_receive_setup()) { usb_process_request(); } 00257 Usb_select_endpoint(EP_MS_OUT); 00258 } 00259 00260 00261 Usb_select_endpoint(EP_MS_IN); 00262 while(!Is_usb_write_enabled()) 00263 { 00264 if(Is_usb_vbus_low()) return; 00265 if(!Is_usb_endpoint_enabled()) return; // USB Reset 00266 } 00268 Usb_write_byte(0x55); 00269 Usb_write_byte(0x53); 00270 Usb_write_byte(0x42); 00271 Usb_write_byte(0x53); 00272 00273 Usb_write_byte(dCBWTag[0]); 00274 Usb_write_byte(dCBWTag[1]); 00275 Usb_write_byte(dCBWTag[2]); 00276 Usb_write_byte(dCBWTag[3]); 00278 Usb_write_byte( LSB0(g_scsi_data_remaining) ); 00279 Usb_write_byte( LSB1(g_scsi_data_remaining) ); 00280 Usb_write_byte( LSB2(g_scsi_data_remaining) ); 00281 Usb_write_byte( LSB3(g_scsi_data_remaining) ); 00282 00284 Usb_write_byte(g_scsi_status); 00285 00286 Usb_send_in(); 00287 }
| void storage_task_init | ( | void | ) |
This function initializes the hardware/software ressources required for storage task.
| none |
Definition at line 91 of file storage_task.c.
References df_mem_init(), Joy_init, Leds_init, and Usb_enable_sof_interrupt.
00092 { 00093 Leds_init(); 00094 Joy_init(); 00095 Usb_enable_sof_interrupt(); 00096 df_mem_init(); // Init the hw/sw ressources required to drive the DF. 00097 }
| void storage_task | ( | void | ) |
Entry point of the mass storage task management This function links the mass storage SCSI commands and the USB bus.
| none |
Definition at line 108 of file storage_task.c.
References EP_MS_OUT, FALSE, g_b_df_protected, Is_device_enumerated, Is_joy_down, Is_joy_up, Is_usb_receive_out, TRUE, usb_mass_storage_cbw(), usb_mass_storage_csw(), and Usb_select_endpoint.
00109 { 00110 if(Is_joy_up()) 00111 { 00112 // Look Write Protection DataFlash 00113 g_b_df_protected = TRUE; 00114 } 00115 if(Is_joy_down()) 00116 { 00117 // UnLook Write Protection DataFlash 00118 g_b_df_protected = FALSE; 00119 } 00120 00121 if (Is_device_enumerated()) 00122 { 00123 Usb_select_endpoint(EP_MS_OUT); 00124 if (Is_usb_receive_out()) 00125 { 00126 usb_mass_storage_cbw(); 00127 usb_mass_storage_csw(); 00128 } 00129 } 00130 }
Definition at line 100 of file usb_standard_request.c.
Referenced by usb_device_task(), usb_general_interrupt(), usb_get_configuration(), and usb_set_configuration().
Definition at line 53 of file df_mem.c.
Referenced by df_test_unit_ready(), df_wr_protect(), df_write_10(), and storage_task().
Definition at line 66 of file storage_task.c.
Definition at line 67 of file storage_task.c.
Referenced by usb_mass_storage_cbw(), and usb_mass_storage_csw().
| _MEM_TYPE_SLOW_ U8 g_scsi_status |
| _MEM_TYPE_FAST_ U32 g_scsi_data_remaining |
Definition at line 61 of file scsi_decoder.c.
Referenced by sbc_read_10(), sbc_write_10(), usb_mass_storage_cbw(), and usb_mass_storage_csw().
Definition at line 63 of file usb_specific_request.c.
Referenced by usb_mass_storage_cbw(), and usb_user_read_request().
| _MEM_TYPE_SLOW_ U8 g_scsi_command[16] |
Definition at line 59 of file scsi_decoder.c.
Referenced by sbc_inquiry(), sbc_mode_sense(), sbc_read_10(), sbc_request_sense(), sbc_write_10(), scsi_decode_command(), and usb_mass_storage_cbw().
| U8 endpoint_status[MAX_EP_NB] |
Definition at line 98 of file usb_standard_request.c.
Referenced by usb_clear_feature(), usb_get_status(), usb_mass_storage_cbw(), usb_process_request(), and usb_set_feature().
Definition at line 76 of file storage_task.c.
Referenced by sbc_header_mode_sense(), sbc_read_10(), sbc_read_capacity(), sbc_test_unit_ready(), sbc_write_10(), and usb_mass_storage_cbw().
1.5.3