Definition in file at45dbx_mem.c.
#include "conf_access.h"
#include "conf_at45dbx.h"
#include "at45dbx.h"
#include "at45dbx_mem.h"
#include "usb_drv.h"
#include "scsi_decoder.h"
Go to the source code of this file.
Defines | |
#define | AT45DBX_MEM_TEST_CHANGE_STATE ENABLED |
Whether to detect write accesses to the memory. | |
Functions | |
MEM <-> RAM Interface | |
Ctrl_status | at45dbx_df_2_ram (U32 addr, void *ram) |
Copies 1 data sector from the memory to RAM. | |
Ctrl_status | at45dbx_ram_2_df (U32 addr, const void *ram) |
Copies 1 data sector from RAM to the memory. | |
Control Interface | |
Ctrl_status | at45dbx_read_capacity (U32 *u32_nb_sector) |
Returns the address of the last valid sector in the memory. | |
Bool | at45dbx_removal (void) |
Tells whether the memory is removable. | |
Ctrl_status | at45dbx_test_unit_ready (void) |
Tests the memory state and initializes the memory if required. | |
Bool | at45dbx_wr_protect (void) |
Returns the write-protection state of the memory. | |
MEM <-> USB Interface | |
void | at45dbx_read_multiple_sector_callback (const void *psector) |
Callback function invoked after each sector read during at45dbx_read_multiple_sector. | |
Ctrl_status | at45dbx_usb_read_10 (U32 addr, U16 nb_sector) |
Tranfers data from the memory to USB. | |
Ctrl_status | at45dbx_usb_write_10 (U32 addr, U16 nb_sector) |
Tranfers data from USB to the memory. | |
void | at45dbx_write_multiple_sector_callback (void *psector) |
Callback function invoked before each sector write during at45dbx_write_multiple_sector. | |
Variables | |
static volatile Bool | s_b_data_modify = FALSE |
Memory data modified flag. |
#define AT45DBX_MEM_TEST_CHANGE_STATE ENABLED |
Ctrl_status at45dbx_df_2_ram | ( | U32 | addr, | |
void * | ram | |||
) |
Copies 1 data sector from the memory to RAM.
addr | Address of first memory sector to read. | |
ram | Pointer to RAM buffer to write. |
Definition at line 199 of file at45dbx_mem.c.
References AT45DBX_MEM_CNT, AT45DBX_MEM_SIZE, at45dbx_read_close(), at45dbx_read_open(), at45dbx_read_sector_2_ram(), AT45DBX_SECTOR_BITS, CTRL_FAIL, and CTRL_GOOD.
00200 { 00201 if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL; 00202 00203 at45dbx_read_open(addr); 00204 at45dbx_read_sector_2_ram(ram); 00205 at45dbx_read_close(); 00206 00207 return CTRL_GOOD; 00208 }
Ctrl_status at45dbx_ram_2_df | ( | U32 | addr, | |
const void * | ram | |||
) |
Copies 1 data sector from RAM to the memory.
addr | Address of first memory sector to write. | |
ram | Pointer to RAM buffer to read. |
Definition at line 211 of file at45dbx_mem.c.
References AT45DBX_MEM_CNT, AT45DBX_MEM_SIZE, AT45DBX_SECTOR_BITS, at45dbx_write_close(), at45dbx_write_open(), at45dbx_write_sector_from_ram(), CTRL_FAIL, CTRL_GOOD, and s_b_data_modify.
00212 { 00213 if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL; 00214 00215 #if AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED 00216 s_b_data_modify = TRUE; 00217 #endif 00218 00219 at45dbx_write_open(addr); 00220 at45dbx_write_sector_from_ram(ram); 00221 at45dbx_write_close(); 00222 00223 return CTRL_GOOD; 00224 }
Ctrl_status at45dbx_read_capacity | ( | U32 * | u32_nb_sector | ) |
Returns the address of the last valid sector in the memory.
u32_nb_sector | Pointer to the address of the last valid sector. |
Definition at line 83 of file at45dbx_mem.c.
References AT45DBX_MEM_CNT, AT45DBX_MEM_SIZE, AT45DBX_SECTOR_BITS, and CTRL_GOOD.
00084 { 00085 *u32_nb_sector = (AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) - 1; 00086 00087 return CTRL_GOOD; 00088 }
void at45dbx_read_multiple_sector_callback | ( | const void * | psector | ) |
Callback function invoked after each sector read during at45dbx_read_multiple_sector.
psector | Pointer to read sector. |
Definition at line 129 of file at45dbx_mem.c.
References AT45DBX_SECTOR_SIZE.
00130 { 00131 U16 data_to_transfer = AT45DBX_SECTOR_SIZE; 00132 00133 // Transfer read sector to the USB interface. 00134 while (data_to_transfer) 00135 { 00136 while (!Is_usb_in_ready(g_scsi_ep_ms_in)) 00137 { 00138 if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_in)) 00139 return; // USB Reset 00140 } 00141 00142 Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in); 00143 data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector, 00144 data_to_transfer, &psector); 00145 Usb_ack_in_ready_send(g_scsi_ep_ms_in); 00146 } 00147 }
Bool at45dbx_removal | ( | void | ) |
Tells whether the memory is removable.
TRUE
if the memory is removable, else FALSE
. Definition at line 97 of file at45dbx_mem.c.
Ctrl_status at45dbx_test_unit_ready | ( | void | ) |
Tests the memory state and initializes the memory if required.
The TEST UNIT READY SCSI primary command allows an application client to poll a LUN until it is ready without having to allocate memory for returned data.
This command may be used to check the media status of LUNs with removable media.
Definition at line 77 of file at45dbx_mem.c.
References at45dbx_mem_check(), CTRL_GOOD, and CTRL_NO_PRESENT.
00078 { 00079 return (at45dbx_mem_check() == OK) ? CTRL_GOOD : CTRL_NO_PRESENT; 00080 }
Ctrl_status at45dbx_usb_read_10 | ( | U32 | addr, | |
U16 | nb_sector | |||
) |
Tranfers data from the memory to USB.
addr | Address of first memory sector to read. | |
nb_sector | Number of sectors to transfer. |
Definition at line 117 of file at45dbx_mem.c.
References AT45DBX_MEM_CNT, AT45DBX_MEM_SIZE, at45dbx_read_close(), at45dbx_read_multiple_sector(), at45dbx_read_open(), AT45DBX_SECTOR_BITS, CTRL_FAIL, and CTRL_GOOD.
00118 { 00119 if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL; 00120 00121 at45dbx_read_open(addr); 00122 at45dbx_read_multiple_sector(nb_sector); 00123 at45dbx_read_close(); 00124 00125 return CTRL_GOOD; 00126 }
Ctrl_status at45dbx_usb_write_10 | ( | U32 | addr, | |
U16 | nb_sector | |||
) |
Tranfers data from USB to the memory.
addr | Address of first memory sector to write. | |
nb_sector | Number of sectors to transfer. |
Definition at line 150 of file at45dbx_mem.c.
References AT45DBX_MEM_CNT, AT45DBX_MEM_SIZE, AT45DBX_SECTOR_BITS, at45dbx_write_close(), at45dbx_write_multiple_sector(), at45dbx_write_open(), CTRL_FAIL, CTRL_GOOD, and s_b_data_modify.
00151 { 00152 if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL; 00153 00154 #if AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED 00155 if (nb_sector) s_b_data_modify = TRUE; 00156 #endif 00157 00158 at45dbx_write_open(addr); 00159 at45dbx_write_multiple_sector(nb_sector); 00160 at45dbx_write_close(); 00161 00162 return CTRL_GOOD; 00163 }
Bool at45dbx_wr_protect | ( | void | ) |
Returns the write-protection state of the memory.
TRUE
if the memory is write-protected, else FALSE
.Definition at line 91 of file at45dbx_mem.c.
void at45dbx_write_multiple_sector_callback | ( | void * | psector | ) |
Callback function invoked before each sector write during at45dbx_write_multiple_sector.
psector | Pointer to sector to write. |
Definition at line 166 of file at45dbx_mem.c.
References AT45DBX_SECTOR_SIZE.
00167 { 00168 U16 data_to_transfer = AT45DBX_SECTOR_SIZE; 00169 00170 // Transfer sector to write from the USB interface. 00171 while (data_to_transfer) 00172 { 00173 while (!Is_usb_out_received(g_scsi_ep_ms_out)) 00174 { 00175 if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_out)) 00176 return; // USB Reset 00177 } 00178 00179 Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_out); 00180 data_to_transfer = usb_read_ep_rxpacket(g_scsi_ep_ms_out, psector, 00181 data_to_transfer, &psector); 00182 Usb_ack_out_received_free(g_scsi_ep_ms_out); 00183 } 00184 }
volatile Bool s_b_data_modify = FALSE [static] |
Memory data modified flag.
Definition at line 67 of file at45dbx_mem.c.
Referenced by at45dbx_ram_2_df(), and at45dbx_usb_write_10().