This file manages the accesses to the remote USB device memories.
Definition in file host_mem.h.
#include "conf_access.h"
#include "ctrl_access.h"
Go to the source code of this file.
Defines | |
#define | HOST_SECTOR_SIZE 512 |
#define | MS_GET_MAX_LUN 0xFE |
Functions | |
U8 | host_get_lun (void) |
This fonction returns the number of LUNs of the connected mass-storage device. | |
Ctrl_status | host_ms_inquiry (void) |
This function sends an SCSI INQUIRY command (0x12) to the device. | |
U8 | host_ms_request_sense (void) |
This function sends an SCSI REQUEST SENSE command (0x03) to the device. | |
Ctrl_status | host_read_10_extram (U32 addr, void *ram, U8 nb_sector) |
This function tranfers 1 data sector from memory to RAM sector = 512 bytes. | |
Ctrl_status | host_read_10_ram (U32 addr, void *ram) |
This function tranfers 1 data sector from memory to RAM sector = 512 bytes. | |
Ctrl_status | host_read_capacity (U8 lun, U32 *u32_nb_sector) |
This function returns the address of the last valid sector in the lun. | |
U8 | host_read_sector_size (U8 lun) |
This function returns the physical sector size of the lun. | |
Bool | host_removal (void) |
This function informs about the memory type. | |
Ctrl_status | host_test_unit_ready (U8 lun) |
This function tests memory state, and starts memory initialization. | |
Bool | host_wr_protect (U8 lun) |
This function returns the write-protected mode Only used by memory removal with a HARDWARE-SPECIFIC write-protected detection. | |
Ctrl_status | host_write_10_extram (U32 addr, const void *ram, U8 nb_sector) |
This function tranfers 1 data sector from RAM to memory sector = 512 bytes. | |
Ctrl_status | host_write_10_ram (U32 addr, const void *ram) |
This function tranfers 1 data sector from RAM to memory sector = 512 bytes. | |
Variables | |
U8 | g_pipe_ms_in |
U8 | g_pipe_ms_out |
U8 | host_selected_lun |
#define HOST_SECTOR_SIZE 512 |
Definition at line 66 of file host_mem.h.
Referenced by host_read_10_extram(), host_read_10_ram(), host_read_10_ram_stop(), and host_write_10_extram().
#define MS_GET_MAX_LUN 0xFE |
Definition at line 64 of file host_mem.h.
U8 host_get_lun | ( | void | ) |
This fonction returns the number of LUNs of the connected mass-storage device.
Definition at line 267 of file host_mem.c.
References Is_host_ms_configured.
Referenced by host_mass_storage_task().
00268 { 00269 if (!Is_host_ms_configured()) return 0; 00270 00271 data_stage[0] = 0; 00272 host_ms_get_max_lun(); 00273 00274 return data_stage[0] + 1; 00275 }
Ctrl_status host_ms_inquiry | ( | void | ) |
This function sends an SCSI INQUIRY command (0x12) to the device.
Definition at line 111 of file host_mem.c.
References buf_cmd, COMMAND_PASSED, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, host_read_10_ram_stop(), host_selected_lun, Is_host_ms_configured, SBC_CMD_DIR_IN, and SBC_CMD_INQUIRY.
Referenced by host_mass_storage_task().
00112 { 00113 Ctrl_status status; 00114 U16 nb; 00115 00116 if (!Is_host_ms_configured()) return CTRL_FAIL; 00117 00118 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status; 00119 00120 buf_cmd[0] = 'U'; // 0 - 0x55 00121 buf_cmd[1] = 'S'; // 1 - 0x53 00122 buf_cmd[2] = 'B'; // 2 - 0x42 00123 buf_cmd[3] = 'C'; // 3 - 0x43 00124 buf_cmd[4] = 0x64; // 4 - LSB0W(dCBWTag) 00125 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00126 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00127 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00128 buf_cmd[8] = 0x24; // 8 - LSB0W(dCBWDataTransferLength) 00129 buf_cmd[9] = 0x00; // 9 - LSB1W(dCBWDataTransferLength) 00130 buf_cmd[10] = 0x00; // 10 - LSB2W(dCBWDataTransferLength) 00131 buf_cmd[11] = 0x00; // 11 - LSB3W(dCBWDataTransferLength) 00132 buf_cmd[12] = SBC_CMD_DIR_IN; // 12 - bmCBWFlags 00133 buf_cmd[13] = host_selected_lun; // 13 - bCBWLUN 00134 buf_cmd[14] = 0x06; // 14 - bCBWCBLength 00135 buf_cmd[15] = SBC_CMD_INQUIRY; // 15 - CBWCB0 - Operation Code (0x12) 00136 buf_cmd[16] = 0x00; // 16 - CBWCB1 - Obsolete, EVPD 00137 buf_cmd[17] = 0x00; // 17 - CBWCB2 - Page Code 00138 buf_cmd[18] = 0x00; // 18 - CBWCB3 - MSB(Allocation Length) 00139 buf_cmd[19] = 0x24; // 19 - CBWCB4 - LSB(Allocation Length) 00140 buf_cmd[20] = 0x00; // 20 - CBWCW5 - Control 00141 buf_cmd[21] = 0x00; // 21 00142 buf_cmd[22] = 0x00; // 22 00143 buf_cmd[23] = 0x00; // 23 00144 buf_cmd[24] = 0x00; // 24 00145 buf_cmd[25] = 0x00; // 25 00146 buf_cmd[26] = 0x00; // 26 00147 buf_cmd[27] = 0x00; // 27 00148 buf_cmd[28] = 0x00; // 28 00149 buf_cmd[29] = 0x00; // 29 00150 buf_cmd[30] = 0x00; // 30 00151 00152 // Send command 00153 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD) 00154 return CTRL_FAIL; 00155 00156 // Transfer data 00157 nb = sizeof(buf_cmd); 00158 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD) 00159 return CTRL_FAIL; 00160 00161 // Get CSW 00162 nb = sizeof(buf_cmd); 00163 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD) 00164 return CTRL_FAIL; 00165 00166 return (buf_cmd[12] == COMMAND_PASSED) ? CTRL_GOOD : CTRL_FAIL; 00167 }
U8 host_ms_request_sense | ( | void | ) |
This function sends an SCSI REQUEST SENSE command (0x03) to the device.
Definition at line 172 of file host_mem.c.
References buf_cmd, COMMAND_PASSED, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, host_ms_stall_management(), host_read_10_ram_stop(), host_selected_lun, Is_host_ms_configured, SBC_ASC_MEDIUM_NOT_PRESENT, SBC_ASC_NOT_READY_TO_READY_CHANGE, SBC_CMD_DIR_IN, SBC_CMD_REQUEST_SENSE, SBC_SENSE_KEY_DATA_PROTECT, SBC_SENSE_KEY_HARDWARE_ERROR, SBC_SENSE_KEY_MEDIUM_ERROR, SBC_SENSE_KEY_NO_SENSE, SBC_SENSE_KEY_NOT_READY, and SBC_SENSE_KEY_UNIT_ATTENTION.
Referenced by host_mass_storage_task(), host_ms_stall_management(), and host_test_unit_ready().
00173 { 00174 volatile U32 delay; 00175 U16 nb; 00176 U8 sense_key, sense_key_add; 00177 Status_t status; 00178 00179 if (!Is_host_ms_configured()) return SBC_SENSE_KEY_NO_SENSE; 00180 00181 if (g_b_read_run && host_read_10_ram_stop() != CTRL_GOOD) return SBC_SENSE_KEY_MEDIUM_ERROR; 00182 00183 buf_cmd[0] = 'U'; // 0 - 0x55 00184 buf_cmd[1] = 'S'; // 1 - 0x53 00185 buf_cmd[2] = 'B'; // 2 - 0x42 00186 buf_cmd[3] = 'C'; // 3 - 0x43 00187 buf_cmd[4] = 0x65; // 4 - LSB0W(dCBWTag) 00188 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00189 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00190 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00191 buf_cmd[8] = 0x12; // 8 - LSB0W(dCBWDataTransferLength) 00192 buf_cmd[9] = 0x00; // 9 - LSB1W(dCBWDataTransferLength) 00193 buf_cmd[10] = 0x00; // 10 - LSB2W(dCBWDataTransferLength) 00194 buf_cmd[11] = 0x00; // 11 - LSB3W(dCBWDataTransferLength) 00195 buf_cmd[12] = SBC_CMD_DIR_IN; // 12 - bmCBWFlags 00196 buf_cmd[13] = host_selected_lun; // 13 - bCBWLUN 00197 buf_cmd[14] = 0x06; // 14 - bCBWCBLength 00198 buf_cmd[15] = SBC_CMD_REQUEST_SENSE; // 15 - CBWCB0 - Operation Code (0x03) 00199 buf_cmd[16] = 0x00; // 16 - CBWCB1 - DESC 00200 buf_cmd[17] = 0x00; // 17 - CBWCB2 - Reserved 00201 buf_cmd[18] = 0x00; // 18 - CBWCB3 - Reserved 00202 buf_cmd[19] = 0x12; // 19 - CBWCB4 - Allocation Length 00203 buf_cmd[20] = 0x00; // 20 - CBWCW5 - Control 00204 buf_cmd[21] = 0x00; // 21 00205 buf_cmd[22] = 0x00; // 22 00206 buf_cmd[23] = 0x00; // 23 00207 buf_cmd[24] = 0x00; // 24 00208 buf_cmd[25] = 0x00; // 25 00209 buf_cmd[26] = 0x00; // 26 00210 buf_cmd[27] = 0x00; // 27 00211 buf_cmd[28] = 0x00; // 28 00212 buf_cmd[29] = 0x00; // 29 00213 buf_cmd[30] = 0x00; // 30 00214 00215 // Send command 00216 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD) 00217 return CTRL_FAIL; 00218 00219 // Transfer data 00220 for (delay = 100000; delay; delay--); 00221 nb = sizeof(buf_cmd); 00222 status = host_get_data(g_pipe_ms_in, &nb, buf_cmd); 00223 if (status == PIPE_STALL) 00224 { 00225 host_ms_stall_management(g_pipe_ms_in); 00226 return CTRL_FAIL; 00227 } 00228 else if (status != PIPE_GOOD) 00229 return SBC_SENSE_KEY_NO_SENSE; 00230 00231 sense_key = buf_cmd[2] & 0x0F; 00232 sense_key_add = buf_cmd[12]; 00233 00234 // Get CSW 00235 nb = sizeof(buf_cmd); 00236 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD) 00237 return CTRL_FAIL; 00238 00239 if (buf_cmd[12] != COMMAND_PASSED) return SBC_SENSE_KEY_NO_SENSE; 00240 00241 switch (sense_key) 00242 { 00243 case SBC_SENSE_KEY_NOT_READY: 00244 if (sense_key_add == SBC_ASC_MEDIUM_NOT_PRESENT) 00245 return CTRL_NO_PRESENT; 00246 break; 00247 case SBC_SENSE_KEY_UNIT_ATTENTION: 00248 if (sense_key_add == SBC_ASC_NOT_READY_TO_READY_CHANGE) 00249 return CTRL_BUSY; 00250 if (sense_key_add == SBC_ASC_MEDIUM_NOT_PRESENT) 00251 return CTRL_NO_PRESENT; 00252 break; 00253 case SBC_SENSE_KEY_HARDWARE_ERROR: 00254 case SBC_SENSE_KEY_DATA_PROTECT: 00255 break; 00256 default: 00257 sense_key = SBC_SENSE_KEY_NO_SENSE; 00258 break; 00259 } 00260 00261 return sense_key; 00262 }
Ctrl_status host_read_10_extram | ( | U32 | addr, | |
void * | ram, | |||
U8 | nb_sector | |||
) |
This function tranfers 1 data sector from memory to RAM sector = 512 bytes.
addr | Sector address to start read | |
ram | Address of RAM buffer | |
nb_sector | number of sector |
Definition at line 656 of file host_mem.c.
References buf_cmd, COMMAND_PASSED, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u32_read_addr, g_u8_sector_size, host_ms_stall_management(), host_read_10_ram(), host_read_10_ram_stop(), HOST_SECTOR_SIZE, host_selected_lun, Is_host_ms_configured, SBC_CMD_DIR_IN, and SBC_CMD_READ_10.
Referenced by ushell_cmd_perform_extaccess().
00657 { 00658 Ctrl_status status; 00659 U16 nb; 00660 U32 u32_host_ms_sector; 00661 00662 if (!Is_host_ms_configured()) return CTRL_FAIL; 00663 00664 if ( g_u8_sector_size != 1) { 00665 // For U-Disk with large block then use standard routine 00666 while( nb_sector != 0 ) { 00667 status = host_read_10_ram(addr, ram); 00668 if (status != CTRL_GOOD) return status; 00669 nb_sector--; 00670 addr++; 00671 ram = (U8*)ram + HOST_SECTOR_SIZE; 00672 } 00673 return CTRL_GOOD; 00674 } 00675 00676 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status; 00677 00678 00679 // Compute the number of bytes per physical sector 00680 u32_host_ms_sector = (U32)nb_sector * HOST_SECTOR_SIZE; 00681 00682 // Save current position and remaining sectors 00683 g_u32_read_addr = addr; 00684 00685 buf_cmd[0] = 'U'; // 0 - 0x55 00686 buf_cmd[1] = 'S'; // 1 - 0x53 00687 buf_cmd[2] = 'B'; // 2 - 0x42 00688 buf_cmd[3] = 'C'; // 3 - 0x43 00689 buf_cmd[4] = 0x66; // 4 - LSB0W(dCBWTag) 00690 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00691 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00692 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00693 buf_cmd[8] = LSB0W(u32_host_ms_sector); // 8 - LSB0W(dCBWDataTransferLength) 00694 buf_cmd[9] = LSB1W(u32_host_ms_sector); // 9 - LSB1W(dCBWDataTransferLength) 00695 buf_cmd[10] = LSB2W(u32_host_ms_sector); // 10 - LSB2W(dCBWDataTransferLength) 00696 buf_cmd[11] = LSB3W(u32_host_ms_sector); // 11 - LSB3W(dCBWDataTransferLength) 00697 buf_cmd[12] = SBC_CMD_DIR_IN; // 12 - bmCBWFlags 00698 buf_cmd[13] = host_selected_lun; // 13 - bCBWLUN 00699 buf_cmd[14] = 0x0A; // 14 - bCBWCBLength 00700 buf_cmd[15] = SBC_CMD_READ_10; // 15 - CBWCB0 - Operation Code (0x28) 00701 buf_cmd[16] = 0x00; // 16 - CBWCB1 - RDPROTECT, DPO, FUA, Obsolete 00702 buf_cmd[17] = MSB0W(addr); // 17 - CBWCB2 - MSB0W(Logical Block Address) 00703 buf_cmd[18] = MSB1W(addr); // 18 - CBWCB3 - MSB1W(Logical Block Address) 00704 buf_cmd[19] = MSB2W(addr); // 19 - CBWCB4 - MSB2W(Logical Block Address) 00705 buf_cmd[20] = MSB3W(addr); // 20 - CBWCW5 - MSB3W(Logical Block Address) 00706 buf_cmd[21] = 0x00; // 21 - CBWCW6 - Reserved 00707 buf_cmd[22] = 0x00; // 22 - CBWCW7 - MSB(Transfer Length) 00708 buf_cmd[23] = nb_sector; // 23 - CBWCW8 - LSB(Transfer Length) 00709 buf_cmd[24] = 0x00; // 24 - CBWCW9 - Control 00710 buf_cmd[25] = 0x00; // 25 00711 buf_cmd[26] = 0x00; // 26 00712 buf_cmd[27] = 0x00; // 27 00713 buf_cmd[28] = 0x00; // 28 00714 buf_cmd[29] = 0x00; // 29 00715 buf_cmd[30] = 0x00; // 30 00716 00717 // Send command 00718 host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd); 00719 00720 // Transfer data 00721 nb = HOST_SECTOR_SIZE; 00722 while( nb_sector != 0 ) { 00723 if (host_get_data(g_pipe_ms_in, &nb, ram) == PIPE_STALL) 00724 { 00725 host_ms_stall_management(g_pipe_ms_in); 00726 return CTRL_FAIL; 00727 } 00728 nb_sector--; 00729 ram = (U8*)ram + HOST_SECTOR_SIZE; 00730 } 00731 00732 // Get CSW 00733 nb = sizeof(buf_cmd); 00734 host_get_data(g_pipe_ms_in, &nb, buf_cmd); 00735 00736 return (buf_cmd[12] == COMMAND_PASSED) ? CTRL_GOOD : CTRL_FAIL; 00737 }
Ctrl_status host_read_10_ram | ( | U32 | addr, | |
void * | ram | |||
) |
This function tranfers 1 data sector from memory to RAM sector = 512 bytes.
addr | Sector address to start read | |
ram | Address of RAM buffer |
Definition at line 550 of file host_mem.c.
References buf_cmd, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u16_read_sector, g_u32_read_addr, g_u8_sector_size, host_ms_stall_management(), host_read_10_ram_stop(), host_read_capacity(), HOST_SECTOR_SIZE, host_selected_lun, Is_host_ms_configured, SBC_CMD_DIR_IN, and SBC_CMD_READ_10.
Referenced by host_read_10_extram().
00551 { 00552 Ctrl_status status; 00553 U16 nb; 00554 U16 u16_nb_byte_ignore_at_beg; 00555 U32 u32_host_ms_address; 00556 U32 u32_host_ms_sector; 00557 00558 if (!Is_host_ms_configured()) return CTRL_FAIL; 00559 00560 // It is next read 00561 if (!g_b_read_run || addr != g_u32_read_addr) 00562 { 00563 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status; 00564 00565 // Check read capacity OK 00566 if( 0 == g_u8_sector_size ) 00567 { 00568 // Update g_u8_sector_size 00569 if( CTRL_GOOD != host_read_capacity( host_selected_lun, &u32_host_ms_sector)) 00570 return CTRL_FAIL; 00571 } 00572 00573 // Compute the address in physical sector units 00574 u32_host_ms_address = addr / g_u8_sector_size; 00575 00576 // Compute the number of bytes to ignore from the beginning of the physical sector 00577 u16_nb_byte_ignore_at_beg = (addr % g_u8_sector_size) * HOST_SECTOR_SIZE; 00578 00579 // Compute the number of bytes per physical sector 00580 u32_host_ms_sector = g_u8_sector_size * HOST_SECTOR_SIZE; 00581 00582 // Save current position and remaining sectors 00583 g_u32_read_addr = addr; 00584 g_u16_read_sector = (u32_host_ms_address + 1) * g_u8_sector_size - addr; 00585 00586 buf_cmd[0] = 'U'; // 0 - 0x55 00587 buf_cmd[1] = 'S'; // 1 - 0x53 00588 buf_cmd[2] = 'B'; // 2 - 0x42 00589 buf_cmd[3] = 'C'; // 3 - 0x43 00590 buf_cmd[4] = 0x66; // 4 - LSB0W(dCBWTag) 00591 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00592 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00593 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00594 buf_cmd[8] = LSB0W(u32_host_ms_sector); // 8 - LSB0W(dCBWDataTransferLength) 00595 buf_cmd[9] = LSB1W(u32_host_ms_sector); // 9 - LSB1W(dCBWDataTransferLength) 00596 buf_cmd[10] = LSB2W(u32_host_ms_sector); // 10 - LSB2W(dCBWDataTransferLength) 00597 buf_cmd[11] = LSB3W(u32_host_ms_sector); // 11 - LSB3W(dCBWDataTransferLength) 00598 buf_cmd[12] = SBC_CMD_DIR_IN; // 12 - bmCBWFlags 00599 buf_cmd[13] = host_selected_lun; // 13 - bCBWLUN 00600 buf_cmd[14] = 0x0A; // 14 - bCBWCBLength 00601 buf_cmd[15] = SBC_CMD_READ_10; // 15 - CBWCB0 - Operation Code (0x28) 00602 buf_cmd[16] = 0x00; // 16 - CBWCB1 - RDPROTECT, DPO, FUA, Obsolete 00603 buf_cmd[17] = MSB0W(u32_host_ms_address); // 17 - CBWCB2 - MSB0W(Logical Block Address) 00604 buf_cmd[18] = MSB1W(u32_host_ms_address); // 18 - CBWCB3 - MSB1W(Logical Block Address) 00605 buf_cmd[19] = MSB2W(u32_host_ms_address); // 19 - CBWCB4 - MSB2W(Logical Block Address) 00606 buf_cmd[20] = MSB3W(u32_host_ms_address); // 20 - CBWCW5 - MSB3W(Logical Block Address) 00607 buf_cmd[21] = 0x00; // 21 - CBWCW6 - Reserved 00608 buf_cmd[22] = 0x00; // 22 - CBWCW7 - MSB(Transfer Length) 00609 buf_cmd[23] = 0x01; // 23 - CBWCW8 - LSB(Transfer Length) 00610 buf_cmd[24] = 0x00; // 24 - CBWCW9 - Control 00611 buf_cmd[25] = 0x00; // 25 00612 buf_cmd[26] = 0x00; // 26 00613 buf_cmd[27] = 0x00; // 27 00614 buf_cmd[28] = 0x00; // 28 00615 buf_cmd[29] = 0x00; // 29 00616 buf_cmd[30] = 0x00; // 30 00617 00618 // Send command 00619 host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd); 00620 00621 // Ignore data at beginning of physical sector (in case physical sector != 512 bytes) 00622 if (host_get_data(g_pipe_ms_in, &u16_nb_byte_ignore_at_beg, NULL) == PIPE_STALL) 00623 { 00624 host_ms_stall_management(g_pipe_ms_in); 00625 return CTRL_FAIL; 00626 } 00627 00628 g_b_read_run = TRUE; 00629 } 00630 00631 // Transfer data 00632 nb = HOST_SECTOR_SIZE; 00633 if (host_get_data(g_pipe_ms_in, &nb, ram) == PIPE_STALL) 00634 { 00635 host_ms_stall_management(g_pipe_ms_in); 00636 return CTRL_FAIL; 00637 } 00638 00639 g_u32_read_addr++; 00640 if (!--g_u16_read_sector) return host_read_10_ram_stop(); 00641 00642 return CTRL_GOOD; 00643 }
Ctrl_status host_read_capacity | ( | U8 | lun, | |
U32 * | u32_nb_sector | |||
) |
This function returns the address of the last valid sector in the lun.
lun | Logical Unit Number | |
u32_nb_sector | Pointer to number of sectors (sector = 512 bytes) |
Definition at line 365 of file host_mem.c.
References buf_cmd, COMMAND_PASSED, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u8_sector_size, host_ms_stall_management(), host_read_10_ram_stop(), host_selected_lun, Is_host_ms_configured, SBC_CMD_DIR_IN, SBC_CMD_READ_CAPACITY_10, and sbc_format_scsi_to_mcu_data.
Referenced by host_mass_storage_task(), and host_read_10_ram().
00366 { 00367 Ctrl_status status; 00368 U16 nb; 00369 Status_t get_data_status; 00370 00371 host_selected_lun = lun; 00372 g_u8_sector_size = 0; 00373 00374 if (!Is_host_ms_configured()) return CTRL_FAIL; 00375 00376 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status; 00377 00378 buf_cmd[0] = 'U'; // 0 - 0x55 00379 buf_cmd[1] = 'S'; // 1 - 0x53 00380 buf_cmd[2] = 'B'; // 2 - 0x42 00381 buf_cmd[3] = 'C'; // 3 - 0x43 00382 buf_cmd[4] = 0x61; // 4 - LSB0W(dCBWTag) 00383 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00384 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00385 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00386 buf_cmd[8] = 0x08; // 8 - LSB0W(dCBWDataTransferLength) 00387 buf_cmd[9] = 0x00; // 9 - LSB1W(dCBWDataTransferLength) 00388 buf_cmd[10] = 0x00; // 10 - LSB2W(dCBWDataTransferLength) 00389 buf_cmd[11] = 0x00; // 11 - LSB3W(dCBWDataTransferLength) 00390 buf_cmd[12] = SBC_CMD_DIR_IN; // 12 - bmCBWFlags 00391 buf_cmd[13] = lun; // 13 - bCBWLUN 00392 buf_cmd[14] = 0x0A; // 14 - bCBWCBLength 00393 buf_cmd[15] = SBC_CMD_READ_CAPACITY_10; // 15 - CBWCB0 - Operation Code (0x25) 00394 buf_cmd[16] = 0x00; // 16 - CBWCB1 - Obsolete 00395 buf_cmd[17] = 0x00; // 17 - CBWCB2 - MSB0W(Logical Block Address) 00396 buf_cmd[18] = 0x00; // 18 - CBWCB3 - MSB1W(Logical Block Address) 00397 buf_cmd[19] = 0x00; // 19 - CBWCB4 - MSB2W(Logical Block Address) 00398 buf_cmd[20] = 0x00; // 20 - CBWCW5 - MSB3W(Logical Block Address) 00399 buf_cmd[21] = 0x00; // 21 - CBWCW6 - Reserved 00400 buf_cmd[22] = 0x00; // 22 - CBWCW7 - Reserved 00401 buf_cmd[23] = 0x00; // 23 - CBWCW8 - PMI 00402 buf_cmd[24] = 0x00; // 24 - CBWCW9 - Control 00403 buf_cmd[25] = 0x00; // 25 00404 buf_cmd[26] = 0x00; // 26 00405 buf_cmd[27] = 0x00; // 27 00406 buf_cmd[28] = 0x00; // 28 00407 buf_cmd[29] = 0x00; // 29 00408 buf_cmd[30] = 0x00; // 30 00409 00410 // Send command 00411 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD) 00412 return CTRL_FAIL; 00413 00414 // Transfer data 00415 nb = sizeof(buf_cmd); 00416 get_data_status = host_get_data(g_pipe_ms_in, &nb, buf_cmd); 00417 if (get_data_status == PIPE_STALL) 00418 { 00419 host_ms_stall_management(g_pipe_ms_in); 00420 return CTRL_FAIL; 00421 } 00422 else if (get_data_status != PIPE_GOOD) 00423 return CTRL_FAIL; 00424 00425 *u32_nb_sector = sbc_format_scsi_to_mcu_data(32, *(U32 *)(buf_cmd + 0)); 00426 g_u8_sector_size = sbc_format_scsi_to_mcu_data(32, *(U32 *)(buf_cmd + 4)) >> 9; 00427 00428 // Get CSW 00429 nb = sizeof(buf_cmd); 00430 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD) 00431 return CTRL_FAIL; 00432 00433 if (buf_cmd[12] != COMMAND_PASSED) 00434 return CTRL_FAIL; 00435 00436 Host_set_device_ready(); 00437 00438 return CTRL_GOOD; 00439 }
U8 host_read_sector_size | ( | U8 | lun | ) |
This function returns the physical sector size of the lun.
lun | Logical Unit Number |
Definition at line 445 of file host_mem.c.
References g_u8_sector_size.
00446 { 00447 return g_u8_sector_size; 00448 }
Bool host_removal | ( | void | ) |
This function informs about the memory type.
Definition at line 531 of file host_mem.c.
References Is_host_ms_configured.
00532 { 00533 return Is_host_ms_configured(); 00534 }
Ctrl_status host_test_unit_ready | ( | U8 | lun | ) |
This function tests memory state, and starts memory initialization.
lun | Logical Unit Number |
Definition at line 285 of file host_mem.c.
References buf_cmd, COMMAND_PASSED, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, host_ms_request_sense(), host_ms_stall_management(), host_read_10_ram_stop(), host_selected_lun, Is_host_ms_configured, SBC_CMD_DIR_OUT, and SBC_CMD_TEST_UNIT_READY.
Referenced by host_mass_storage_task().
00286 { 00287 Ctrl_status status; 00288 U16 nb; 00289 Status_t get_data_status; 00290 00291 host_selected_lun = lun; 00292 00293 if (!Is_host_ms_configured()) return CTRL_FAIL; 00294 00295 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status; 00296 00297 buf_cmd[0] = 'U'; // 0 - 0x55 00298 buf_cmd[1] = 'S'; // 1 - 0x53 00299 buf_cmd[2] = 'B'; // 2 - 0x42 00300 buf_cmd[3] = 'C'; // 3 - 0x43 00301 buf_cmd[4] = 0x60; // 4 - LSB0W(dCBWTag) 00302 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00303 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00304 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00305 buf_cmd[8] = 0x00; // 8 - LSB0W(dCBWDataTransferLength) 00306 buf_cmd[9] = 0x00; // 9 - LSB1W(dCBWDataTransferLength) 00307 buf_cmd[10] = 0x00; // 10 - LSB2W(dCBWDataTransferLength) 00308 buf_cmd[11] = 0x00; // 11 - LSB3W(dCBWDataTransferLength) 00309 buf_cmd[12] = SBC_CMD_DIR_OUT; // 12 - bmCBWFlags 00310 buf_cmd[13] = host_selected_lun; // 13 - bCBWLUN 00311 buf_cmd[14] = 0x06; // 14 - bCBWCBLength 00312 buf_cmd[15] = SBC_CMD_TEST_UNIT_READY; // 15 - CBWCB0 - Operation Code (0x00) 00313 buf_cmd[16] = 0x00; // 16 - CBWCB1 - Reserved 00314 buf_cmd[17] = 0x00; // 17 - CBWCB2 - Reserved 00315 buf_cmd[18] = 0x00; // 18 - CBWCB3 - Reserved 00316 buf_cmd[19] = 0x00; // 19 - CBWCB4 - Reserved 00317 buf_cmd[20] = 0x00; // 20 - CBWCW5 - Control 00318 buf_cmd[21] = 0x00; // 21 00319 buf_cmd[22] = 0x00; // 22 00320 buf_cmd[23] = 0x00; // 23 00321 buf_cmd[24] = 0x00; // 24 00322 buf_cmd[25] = 0x00; // 25 00323 buf_cmd[26] = 0x00; // 26 00324 buf_cmd[27] = 0x00; // 27 00325 buf_cmd[28] = 0x00; // 28 00326 buf_cmd[29] = 0x00; // 29 00327 buf_cmd[30] = 0x00; // 30 00328 00329 // Send command 00330 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD) 00331 return CTRL_FAIL; 00332 00333 // Get CSW 00334 nb = sizeof(buf_cmd); 00335 get_data_status = host_get_data(g_pipe_ms_in, &nb, buf_cmd); 00336 if (get_data_status == PIPE_STALL) 00337 { 00338 host_ms_stall_management(g_pipe_ms_in); 00339 return CTRL_FAIL; 00340 } 00341 else if (get_data_status != PIPE_GOOD) 00342 return CTRL_FAIL; 00343 00344 if (buf_cmd[12] != COMMAND_PASSED) 00345 { 00346 if (host_ms_request_sense() == CTRL_BUSY) 00347 return CTRL_BUSY; 00348 return CTRL_FAIL; 00349 } 00350 00351 Host_set_device_ready(); 00352 00353 return CTRL_GOOD; 00354 }
Bool host_wr_protect | ( | U8 | lun | ) |
This function returns the write-protected mode Only used by memory removal with a HARDWARE-SPECIFIC write-protected detection.
lun | Logical Unit Number |
Definition at line 456 of file host_mem.c.
References buf_cmd, COMMAND_PASSED, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u8_sector_size, host_ms_stall_management(), host_read_10_ram_stop(), host_selected_lun, Is_host_ms_configured, SBC_CMD_DIR_IN, and SBC_CMD_MODE_SENSE_6.
00457 { 00458 U16 nb; 00459 Bool write_protect; 00460 Status_t status; 00461 00462 host_selected_lun = lun; 00463 00464 if (!Is_host_ms_configured() || 00465 g_u8_sector_size != 1 || // LUN not supported in write mode, because sector size != 512 bytes 00466 (g_b_read_run && host_read_10_ram_stop() != CTRL_GOOD)) 00467 return TRUE; 00468 00469 buf_cmd[0] = 'U'; // 0 - 0x55 00470 buf_cmd[1] = 'S'; // 1 - 0x53 00471 buf_cmd[2] = 'B'; // 2 - 0x42 00472 buf_cmd[3] = 'C'; // 3 - 0x43 00473 buf_cmd[4] = 0x63; // 4 - LSB0W(dCBWTag) 00474 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00475 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00476 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00477 buf_cmd[8] = 0x0C; // 8 - LSB0W(dCBWDataTransferLength) 00478 buf_cmd[9] = 0x00; // 9 - LSB1W(dCBWDataTransferLength) 00479 buf_cmd[10] = 0x00; // 10 - LSB2W(dCBWDataTransferLength) 00480 buf_cmd[11] = 0x00; // 11 - LSB3W(dCBWDataTransferLength) 00481 buf_cmd[12] = SBC_CMD_DIR_IN; // 12 - bmCBWFlags 00482 buf_cmd[13] = host_selected_lun; // 13 - bCBWLUN 00483 buf_cmd[14] = 0x06; // 14 - bCBWCBLength 00484 buf_cmd[15] = SBC_CMD_MODE_SENSE_6; // 15 - CBWCB0 - Operation Code (0x1A) 00485 buf_cmd[16] = 0x00; // 16 - CBWCB1 - DBD 00486 buf_cmd[17] = 0x3F; // 17 - CBWCB2 - PC, Page Code 00487 buf_cmd[18] = 0x00; // 18 - CBWCB3 - Subpage Code 00488 buf_cmd[19] = 0x0C; // 19 - CBWCB4 - Allocation Length 00489 buf_cmd[20] = 0x00; // 20 - CBWCW5 - Control 00490 buf_cmd[21] = 0x00; // 21 00491 buf_cmd[22] = 0x00; // 22 00492 buf_cmd[23] = 0x00; // 23 00493 buf_cmd[24] = 0x00; // 24 00494 buf_cmd[25] = 0x00; // 25 00495 buf_cmd[26] = 0x00; // 26 00496 buf_cmd[27] = 0x00; // 27 00497 buf_cmd[28] = 0x00; // 28 00498 buf_cmd[29] = 0x00; // 29 00499 buf_cmd[30] = 0x00; // 30 00500 00501 // Send command 00502 if (host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd) != PIPE_GOOD) 00503 return CTRL_FAIL; 00504 00505 // Transfer data 00506 nb = sizeof(buf_cmd); 00507 if (host_get_data(g_pipe_ms_in, &nb, buf_cmd) != PIPE_GOOD) 00508 return CTRL_FAIL; 00509 00510 write_protect = buf_cmd[2] >> 7; 00511 00512 // Get CSW 00513 nb = sizeof(buf_cmd); 00514 status = host_get_data(g_pipe_ms_in, &nb, buf_cmd); 00515 if (status == PIPE_STALL) 00516 { 00517 host_ms_stall_management(g_pipe_ms_in); 00518 return FALSE; 00519 } 00520 else if (status != PIPE_GOOD) 00521 return FALSE; 00522 00523 if (buf_cmd[12] != COMMAND_PASSED) return FALSE; 00524 00525 return write_protect; 00526 }
Ctrl_status host_write_10_extram | ( | U32 | addr, | |
const void * | ram, | |||
U8 | nb_sector | |||
) |
This function tranfers 1 data sector from RAM to memory sector = 512 bytes.
addr | Sector address to start write | |
ram | Address of RAM buffer | |
nb_sector | Number of sector |
Definition at line 793 of file host_mem.c.
References buf_cmd, COMMAND_PASSED, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u8_sector_size, host_ms_stall_management(), host_read_10_ram_stop(), HOST_SECTOR_SIZE, host_selected_lun, Is_host_ms_configured, SBC_CMD_DIR_OUT, and SBC_CMD_WRITE_10.
Referenced by host_write_10_ram(), and ushell_cmd_perform_extaccess().
00794 { 00795 Ctrl_status status; 00796 U16 nb; 00797 U32 dCBWDataTransferLength; 00798 00799 if (!Is_host_ms_configured() || 00800 g_u8_sector_size != 1) // LUN not supported in write mode, because sector size != 512 bytes 00801 return CTRL_FAIL; 00802 00803 if (g_b_read_run && (status = host_read_10_ram_stop()) != CTRL_GOOD) return status; 00804 00805 dCBWDataTransferLength = (U32)nb_sector * HOST_SECTOR_SIZE; 00806 00807 buf_cmd[0] = 'U'; // 0 - 0x55 00808 buf_cmd[1] = 'S'; // 1 - 0x53 00809 buf_cmd[2] = 'B'; // 2 - 0x42 00810 buf_cmd[3] = 'C'; // 3 - 0x43 00811 buf_cmd[4] = 0x66; // 4 - LSB0W(dCBWTag) 00812 buf_cmd[5] = 0x00; // 5 - LSB1W(dCBWTag) 00813 buf_cmd[6] = 0x00; // 6 - LSB2W(dCBWTag) 00814 buf_cmd[7] = 0x00; // 7 - LSB3W(dCBWTag) 00815 buf_cmd[8] = LSB0W(dCBWDataTransferLength); // 8 - LSB0W(dCBWDataTransferLength) 00816 buf_cmd[9] = LSB1W(dCBWDataTransferLength); // 9 - LSB1W(dCBWDataTransferLength) 00817 buf_cmd[10] = LSB2W(dCBWDataTransferLength); // 10 - LSB2W(dCBWDataTransferLength) 00818 buf_cmd[11] = LSB3W(dCBWDataTransferLength); // 11 - LSB3W(dCBWDataTransferLength) 00819 buf_cmd[12] = SBC_CMD_DIR_OUT; // 12 - bmCBWFlags 00820 buf_cmd[13] = host_selected_lun; // 13 - bCBWLUN 00821 buf_cmd[14] = 0x0A; // 14 - bCBWCBLength 00822 buf_cmd[15] = SBC_CMD_WRITE_10; // 15 - CBWCB0 - Operation Code (0x2A) 00823 buf_cmd[16] = 0x00; // 16 - CBWCB1 - WRPROTECT, DPO, FUA, Obsolete 00824 buf_cmd[17] = MSB0W(addr); // 17 - CBWCB2 - MSB0W(Logical Block Address) 00825 buf_cmd[18] = MSB1W(addr); // 18 - CBWCB3 - MSB1W(Logical Block Address) 00826 buf_cmd[19] = MSB2W(addr); // 19 - CBWCB4 - MSB2W(Logical Block Address) 00827 buf_cmd[20] = MSB3W(addr); // 20 - CBWCW5 - MSB3W(Logical Block Address) 00828 buf_cmd[21] = 0x00; // 21 - CBWCW6 - Reserved 00829 buf_cmd[22] = 0x00; // 22 - CBWCW7 - MSB(Transfer Length) 00830 buf_cmd[23] = nb_sector; // 23 - CBWCW8 - LSB(Transfer Length) 00831 buf_cmd[24] = 0x00; // 24 - CBWCW9 - Control 00832 buf_cmd[25] = 0x00; // 25 00833 buf_cmd[26] = 0x00; // 26 00834 buf_cmd[27] = 0x00; // 27 00835 buf_cmd[28] = 0x00; // 28 00836 buf_cmd[29] = 0x00; // 29 00837 buf_cmd[30] = 0x00; // 30 00838 00839 // Send command 00840 host_send_data(g_pipe_ms_out, sizeof(buf_cmd), buf_cmd); 00841 00842 // Transfer data 00843 while( nb_sector!= 0 ) 00844 { 00845 if (host_send_data(g_pipe_ms_out, HOST_SECTOR_SIZE, ram) == PIPE_STALL) 00846 { 00847 host_ms_stall_management(g_pipe_ms_out); 00848 return CTRL_FAIL; 00849 } 00850 nb_sector--; 00851 ram = (U8*)ram + HOST_SECTOR_SIZE; 00852 } 00853 00854 // Get CSW 00855 nb = sizeof(buf_cmd); 00856 host_get_data(g_pipe_ms_in, &nb, buf_cmd); 00857 00858 return (buf_cmd[12] == COMMAND_PASSED) ? CTRL_GOOD : CTRL_FAIL; 00859 }
Ctrl_status host_write_10_ram | ( | U32 | addr, | |
const void * | ram | |||
) |
This function tranfers 1 data sector from RAM to memory sector = 512 bytes.
addr | Sector address to start write | |
ram | Address of RAM buffer |
Definition at line 778 of file host_mem.c.
References host_write_10_extram().
00779 { 00780 return host_write_10_extram(addr, ram, 1); 00781 }
U8 g_pipe_ms_in |
Definition at line 74 of file host_mem.c.
Referenced by host_mass_storage_task(), host_ms_inquiry(), host_ms_request_sense(), host_ms_stall_management(), host_read_10_extram(), host_read_10_ram(), host_read_10_ram_stop(), host_read_capacity(), host_test_unit_ready(), host_wr_protect(), and host_write_10_extram().
Definition at line 75 of file host_mem.c.
Referenced by host_mass_storage_task(), host_ms_inquiry(), host_ms_request_sense(), host_read_10_extram(), host_read_10_ram(), host_read_capacity(), host_test_unit_ready(), host_wr_protect(), and host_write_10_extram().
Definition at line 72 of file host_mem.c.
Referenced by host_mass_storage_task(), host_ms_inquiry(), host_ms_request_sense(), host_read_10_extram(), host_read_10_ram(), host_read_capacity(), host_test_unit_ready(), host_wr_protect(), and host_write_10_extram().