00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #include "conf_access.h"
00049
00050
00051 #if AT45DBX_MEM == ENABLE
00052
00053 #include "conf_at45dbx.h"
00054 #include "at45dbx.h"
00055 #include "at45dbx_mem.h"
00056
00057
00058
00059
00061 #define AT45DBX_MEM_TEST_CHANGE_STATE ENABLED
00062
00063
00064 #if (ACCESS_USB == ENABLED || ACCESS_MEM_TO_RAM == ENABLED) && AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED
00065
00067 static volatile Bool s_b_data_modify = FALSE;
00068
00069 #endif
00070
00071
00074
00075
00076
00077 Ctrl_status at45dbx_test_unit_ready(void)
00078 {
00079 return (at45dbx_mem_check() == OK) ? CTRL_GOOD : CTRL_NO_PRESENT;
00080 }
00081
00082
00083 Ctrl_status at45dbx_read_capacity(U32 *u32_nb_sector)
00084 {
00085 *u32_nb_sector = (AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) - 1;
00086
00087 return CTRL_GOOD;
00088 }
00089
00090
00091 Bool at45dbx_wr_protect(void)
00092 {
00093 return FALSE;
00094 }
00095
00096
00097 Bool at45dbx_removal(void)
00098 {
00099 return FALSE;
00100 }
00101
00102
00104
00105
00106 #if ACCESS_USB == ENABLED
00107
00108 #include "usb_drv.h"
00109 #include "scsi_decoder.h"
00110
00111
00114
00115
00116
00117 Ctrl_status at45dbx_usb_read_10(U32 addr, U16 nb_sector)
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 }
00127
00128
00129 void at45dbx_read_multiple_sector_callback(const void *psector)
00130 {
00131 U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
00132
00133
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;
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 }
00148
00149
00150 Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector)
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 }
00164
00165
00166 void at45dbx_write_multiple_sector_callback(void *psector)
00167 {
00168 U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
00169
00170
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;
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 }
00185
00186
00188
00189 #endif // ACCESS_USB == ENABLED
00190
00191
00192 #if ACCESS_MEM_TO_RAM == ENABLED
00193
00196
00197
00198
00199 Ctrl_status at45dbx_df_2_ram(U32 addr, void *ram)
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 }
00209
00210
00211 Ctrl_status at45dbx_ram_2_df(U32 addr, const void *ram)
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 }
00225
00226
00228
00229 #endif // ACCESS_MEM_TO_RAM == ENABLED
00230
00231
00232 #endif // AT45DBX_MEM == ENABLE