Atmel Software Framework

host_mem.h File Reference
#include "conf_access.h"
#include "ctrl_access.h"

Macros

#define HOST_SECTOR_SIZE   512
 
#define MS_GET_MAX_LUN   0xFE
 

Functions

uint8_t host_get_lun (void)
 This function returns the number of LUNs of the connected mass-storage device. More...
 
Ctrl_status host_ms_inquiry (void)
 This function sends an SCSI INQUIRY command (0x12) to the device. More...
 
uint8_t host_ms_request_sense (void)
 This function sends an SCSI REQUEST SENSE command (0x03) to the device. More...
 
Ctrl_status host_read_10_extram (uint32_t addr, void *ram, uint8_t nb_sector)
 This function transfers 1 data sector from memory to RAM sector = 512 bytes. More...
 
Ctrl_status host_read_10_ram (uint32_t addr, void *ram)
 This function transfers 1 data sector from memory to RAM sector = 512 bytes. More...
 
Ctrl_status host_read_capacity (uint8_t lun, uint32_t *u32_nb_sector)
 This function returns the address of the last valid sector in the lun. More...
 
uint8_t host_read_sector_size (uint8_t lun)
 This function returns the physical sector size of the lun. More...
 
bool host_removal (void)
 This function informs about the memory type. More...
 
Ctrl_status host_test_unit_ready (uint8_t lun)
 This function tests memory state, and starts memory initialization. More...
 
bool host_wr_protect (uint8_t lun)
 This function returns the write-protected mode Only used by memory removal with a HARDWARE-SPECIFIC write-protected detection. More...
 
Ctrl_status host_write_10_extram (uint32_t addr, const void *ram, uint8_t nb_sector)
 This function transfers 1 data sector from RAM to memory sector = 512 bytes. More...
 
Ctrl_status host_write_10_ram (uint32_t addr, const void *ram)
 This function transfers 1 data sector from RAM to memory sector = 512 bytes. More...
 

Variables

uint8_t g_pipe_ms_in
 
uint8_t g_pipe_ms_out
 
uint8_t host_selected_lun
 

#define HOST_SECTOR_SIZE   512
#define MS_GET_MAX_LUN   0xFE

uint8_t host_get_lun ( void  )

This function returns the number of LUNs of the connected mass-storage device.

Returns
uint8_t: Number of logical units of the device

References data_stage, host_ms_get_max_lun, and Is_host_ms_configured.

Referenced by host_mass_storage_task().

Ctrl_status host_ms_inquiry ( void  )

This function sends an SCSI INQUIRY command (0x12) to the device.

Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References buf_cmd, COMMAND_PASSED, CTRL_FAIL, CTRL_GOOD, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, host_get_data(), host_read_10_ram_stop(), host_selected_lun, host_send_data(), Is_host_ms_configured, PIPE_GOOD, SBC_CMD_DIR_IN, SBC_CMD_INQUIRY, and status.

Referenced by host_mass_storage_task().

Ctrl_status host_read_10_extram ( uint32_t  addr,
void *  ram,
uint8_t  nb_sector 
)

This function transfers 1 data sector from memory to RAM sector = 512 bytes.

Parameters
addrSector address to start read
ramAddress of RAM buffer
nb_sectornumber of sector
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References buf_cmd, COMMAND_PASSED, CTRL_FAIL, CTRL_GOOD, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u32_read_addr, g_u8_sector_size, host_get_data(), host_ms_stall_management(), host_read_10_ram(), host_read_10_ram_stop(), HOST_SECTOR_SIZE, host_selected_lun, host_send_data(), Is_host_ms_configured, LSB0W, LSB1W, LSB2W, LSB3W, MSB0W, MSB1W, MSB2W, MSB3W, PIPE_STALL, SBC_CMD_DIR_IN, SBC_CMD_READ_10, and status.

Referenced by ushell_cmd_perform_extaccess().

Ctrl_status host_read_10_ram ( uint32_t  addr,
void *  ram 
)

This function transfers 1 data sector from memory to RAM sector = 512 bytes.

Parameters
addrSector address to start read
ramAddress of RAM buffer
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References buf_cmd, CTRL_FAIL, CTRL_GOOD, 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_get_data(), host_ms_stall_management(), host_read_10_ram_stop(), host_read_capacity(), HOST_SECTOR_SIZE, host_selected_lun, host_send_data(), Is_host_ms_configured, LSB0W, LSB1W, LSB2W, LSB3W, MSB0W, MSB1W, MSB2W, MSB3W, NULL, PIPE_STALL, SBC_CMD_DIR_IN, SBC_CMD_READ_10, and status.

Referenced by host_read_10_extram().

Ctrl_status host_read_capacity ( uint8_t  lun,
uint32_t *  u32_nb_sector 
)

This function returns the address of the last valid sector in the lun.

Parameters
lunLogical Unit Number
u32_nb_sectorPointer to number of sectors (sector = 512 bytes)
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References buf_cmd, COMMAND_PASSED, CTRL_FAIL, CTRL_GOOD, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u8_sector_size, host_get_data(), host_ms_stall_management(), host_read_10_ram_stop(), host_selected_lun, host_send_data(), Host_set_device_ready, Is_host_ms_configured, PIPE_GOOD, PIPE_STALL, SBC_CMD_DIR_IN, SBC_CMD_READ_CAPACITY_10, sbc_format_scsi_to_mcu_data, and status.

Referenced by host_mass_storage_task(), and host_read_10_ram().

uint8_t host_read_sector_size ( uint8_t  lun)

This function returns the physical sector size of the lun.

Parameters
lunLogical Unit Number
Returns
uint8_t: Number of 512-byte blocks per sector

References g_u8_sector_size.

bool host_removal ( void  )

This function informs about the memory type.

Returns
true if the memory is removable

References Is_host_ms_configured.

Ctrl_status host_test_unit_ready ( uint8_t  lun)

This function tests memory state, and starts memory initialization.

Parameters
lunLogical Unit Number
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References buf_cmd, COMMAND_PASSED, CTRL_BUSY, CTRL_FAIL, CTRL_GOOD, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, host_get_data(), host_ms_request_sense(), host_ms_stall_management(), host_read_10_ram_stop(), host_selected_lun, host_send_data(), Host_set_device_ready, Is_host_ms_configured, PIPE_GOOD, PIPE_STALL, SBC_CMD_DIR_OUT, SBC_CMD_TEST_UNIT_READY, and status.

Referenced by host_mass_storage_task().

bool host_wr_protect ( uint8_t  lun)

This function returns the write-protected mode Only used by memory removal with a HARDWARE-SPECIFIC write-protected detection.

Warning
The customer must unplug the memory to change this write-protected mode.
Parameters
lunLogical Unit Number
Returns
true if the memory is protected

References buf_cmd, COMMAND_PASSED, CTRL_FAIL, CTRL_GOOD, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u8_sector_size, host_get_data(), host_ms_stall_management(), host_read_10_ram_stop(), host_selected_lun, host_send_data(), Is_host_ms_configured, PIPE_GOOD, PIPE_STALL, SBC_CMD_DIR_IN, SBC_CMD_MODE_SENSE_6, and status.

Ctrl_status host_write_10_extram ( uint32_t  addr,
const void *  ram,
uint8_t  nb_sector 
)

This function transfers 1 data sector from RAM to memory sector = 512 bytes.

Parameters
addrSector address to start write
ramAddress of RAM buffer
nb_sectorNumber of sector
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References buf_cmd, COMMAND_PASSED, CTRL_FAIL, CTRL_GOOD, g_b_read_run, g_pipe_ms_in, g_pipe_ms_out, g_u8_sector_size, host_get_data(), host_ms_stall_management(), host_read_10_ram_stop(), HOST_SECTOR_SIZE, host_selected_lun, host_send_data(), Is_host_ms_configured, LSB0W, LSB1W, LSB2W, LSB3W, MSB0W, MSB1W, MSB2W, MSB3W, PIPE_STALL, SBC_CMD_DIR_OUT, SBC_CMD_WRITE_10, and status.

Referenced by host_write_10_ram(), and ushell_cmd_perform_extaccess().

Ctrl_status host_write_10_ram ( uint32_t  addr,
const void *  ram 
)

This function transfers 1 data sector from RAM to memory sector = 512 bytes.

Parameters
addrSector address to start write
ramAddress of RAM buffer
Returns
Ctrl_status It is ready -> CTRL_GOOD Memory unplug -> CTRL_NO_PRESENT Not initialized or changed -> CTRL_BUSY An error occurred -> CTRL_FAIL

References host_write_10_extram().