#include "conf/conf_access.h"
#include "modules/control_access/ctrl_status.h"
Go to the source code of this file.
Defines | |
#define | MMCSD_REMOVED 0 |
#define | MMCSD_INSERTED 1 |
#define | MMCSD_REMOVING 2 |
Functions | |
void | mmc_sd_spi_init (void) |
Low-level functions (basic management). | |
void | mmc_sd_mem_init (void) |
Ctrl_status | mmc_sd_test_unit_ready (void) |
Ctrl_status | mmc_sd_read_capacity (U32 _MEM_TYPE_SLOW_ *u32_nb_sector) |
Bool | mmc_sd_wr_protect (void) |
Bool | mmc_sd_removal (void) |
Ctrl_status | mmc_sd_read_10 (U32 addr, U16 nb_sector) |
Ctrl_status | mmc_sd_write_10 (U32 addr, U16 nb_sector) |
This fonction initialise the memory for a write operation. | |
Ctrl_status | mmc_ram_2_mmc (U32 addr, U8 *ram) |
This fonction initialise the memory for a write operation from ram buffer to MMC/SD (1 sector). | |
Ctrl_status | mmc_mmc_2_ram (U32 addr, U8 *ram) |
This fonction read 1 sector from MMC/SD to ram buffer. |
Definition in file mmc_sd_mem.h.
#define MMCSD_REMOVED 0 |
#define MMCSD_INSERTED 1 |
#define MMCSD_REMOVING 2 |
void mmc_sd_spi_init | ( | void | ) |
Low-level functions (basic management).
This function initializes the SPI communication link between the MMC_SD and the MMC_SD driver.
none |
Definition at line 88 of file mmc_sd.c.
References Spi_disable_ss, Spi_enable, Spi_init_bus, SPI_MODE_0, SPI_RATE_0, Spi_select_master, Spi_set_mode, and Spi_set_rate.
00089 { 00090 Spi_select_master(); 00091 Spi_set_mode(SPI_MODE_0); 00092 Spi_init_bus(); 00093 Spi_set_rate(SPI_RATE_0); // SCK freq == fosc/2. 00094 Spi_disable_ss(); 00095 Spi_enable(); 00096 }
void mmc_sd_mem_init | ( | void | ) |
This function initializes the hw/sw ressources required to drive the MMC_SD.
none |
Definition at line 82 of file mmc_sd_mem.c.
References mmc_sd_init().
00083 { 00084 mmc_sd_init(); // Init the SPI bus and the MMC/SD card 00085 }
Ctrl_status mmc_sd_test_unit_ready | ( | void | ) |
This function tests the state of the MMC_SD memory and sends it to the Host. For a PC, this device is seen as a removable media Before indicating any modification of the status of the media (GOOD->NO_PRESENT or vice-versa), the function must return the BUSY data to make the PC accepting the change
none |
Definition at line 103 of file mmc_sd_mem.c.
References CTRL_BUSY, CTRL_GOOD, CTRL_NO_PRESENT, FALSE, mmc_sd_init_done, mmc_sd_mem_check(), mmc_sd_mem_init(), mmc_sd_presence_status, MMCSD_INSERTED, MMCSD_REMOVED, MMCSD_REMOVING, OK, Sdmmc_access_signal_off, and Sdmmc_access_signal_on.
00104 { 00105 Sdmmc_access_signal_on(); 00106 if (mmc_sd_init_done == FALSE) 00107 { 00108 mmc_sd_mem_init(); 00109 } 00110 switch (mmc_sd_presence_status) 00111 { 00112 case MMCSD_REMOVED: 00113 mmc_sd_init_done = FALSE; 00114 if (OK == mmc_sd_mem_check()) 00115 { 00116 mmc_sd_presence_status = MMCSD_INSERTED; 00117 Sdmmc_access_signal_off(); 00118 return CTRL_BUSY; 00119 } 00120 Sdmmc_access_signal_off(); 00121 return CTRL_NO_PRESENT; 00122 00123 case MMCSD_INSERTED: 00124 if (OK != mmc_sd_mem_check()) 00125 { 00126 mmc_sd_presence_status = MMCSD_REMOVING; 00127 mmc_sd_init_done = FALSE; 00128 Sdmmc_access_signal_off(); 00129 return CTRL_BUSY; 00130 } 00131 Sdmmc_access_signal_off(); 00132 return CTRL_GOOD; 00133 00134 case MMCSD_REMOVING: 00135 mmc_sd_presence_status = MMCSD_REMOVED; 00136 Sdmmc_access_signal_off(); 00137 return CTRL_NO_PRESENT; 00138 00139 default: 00140 mmc_sd_presence_status = MMCSD_REMOVED; 00141 Sdmmc_access_signal_off(); 00142 return CTRL_BUSY; 00143 } 00144 00145 Sdmmc_access_signal_off(); 00146 return CTRL_BUSY; 00147 /* 00148 if (OK==mmc_sd_mem_check()) 00149 { 00150 if (mmc_sd_status_changed == FALSE) 00151 { 00152 mmc_sd_status_changed = TRUE; 00153 return CTRL_BUSY; // BUSY token must be returned to indicate a status change ! 00154 } 00155 else 00156 return CTRL_GOOD; // the 2nd time the host will ask for unit_ready, we can answer GOOD if we have returned BUSY first ! 00157 } 00158 else 00159 { 00160 if (mmc_sd_status_changed == TRUE) 00161 { 00162 mmc_sd_status_changed = FALSE; 00163 return CTRL_BUSY; // BUSY token must be returned to indicate a status change ! 00164 } 00165 else 00166 return CTRL_NO_PRESENT; 00167 } 00168 */ 00169 }
Ctrl_status mmc_sd_read_capacity | ( | U32 _MEM_TYPE_SLOW_ * | u32_nb_sector | ) |
This function gives the address of the last valid sector.
*u32_nb_sector | number of sector (sector = 512B). OUT |
Definition at line 183 of file mmc_sd_mem.c.
References CTRL_GOOD, CTRL_NO_PRESENT, FALSE, mmc_sd_init_done, mmc_sd_last_block_address, mmc_sd_mem_init(), Sdmmc_access_signal_off, Sdmmc_access_signal_on, and TRUE.
00184 { 00185 // mmc_sd_check_presence(); // ommited because creates interferences with "mmc_sd_test_unit_ready()" function 00186 Sdmmc_access_signal_on(); 00187 if (mmc_sd_init_done == FALSE) 00188 { 00189 mmc_sd_mem_init(); 00190 } 00191 if (mmc_sd_init_done == TRUE) 00192 { 00193 *u32_nb_sector = mmc_sd_last_block_address; 00194 Sdmmc_access_signal_off(); 00195 return CTRL_GOOD; 00196 } 00197 else 00198 { 00199 Sdmmc_access_signal_off(); 00200 return CTRL_NO_PRESENT; 00201 } 00202 }
Bool mmc_sd_wr_protect | ( | void | ) |
This function returns the write protected status of the memory.
Only used by memory removal with a HARDWARE SPECIFIC write protected detection !!! The customer must unplug the memory to change this write protected status, which cannot be for a MMC_SD.
Definition at line 216 of file mmc_sd_mem.c.
References FALSE.
00217 { 00218 return FALSE; 00219 }
Bool mmc_sd_removal | ( | void | ) |
This function tells if the memory has been removed or not.
none |
Definition at line 231 of file mmc_sd_mem.c.
References FALSE.
00232 { 00233 return FALSE; 00234 // return ((OK == mmc_sd_check_presence()) ? FALSE : TRUE); 00235 }
Ctrl_status mmc_sd_read_10 | ( | U32 | addr, | |
U16 | nb_sector | |||
) |
This function performs a read operation of n sectors from a given address on. (sector = 512B)
DATA FLOW is: MMC_SD => USB
addr | Sector address to start the read from | |
nb_sector | Number of sectors to transfer |
Definition at line 257 of file mmc_sd_mem.c.
References CTRL_GOOD, CTRL_NO_PRESENT, FALSE, mmc_sd_init_done, mmc_sd_mem_init(), mmc_sd_read_close(), mmc_sd_read_open(), mmc_sd_read_sector(), OK, Sdmmc_access_signal_off, Sdmmc_access_signal_on, and TRUE.
00258 { 00259 bit status; 00260 if (mmc_sd_init_done == FALSE) 00261 { 00262 mmc_sd_mem_init(); 00263 } 00264 if (mmc_sd_init_done == TRUE) 00265 { 00266 Sdmmc_access_signal_on(); 00267 mmc_sd_read_open(addr); 00268 status = mmc_sd_read_sector(nb_sector); 00269 mmc_sd_read_close(); 00270 Sdmmc_access_signal_off(); 00271 if (status == OK) 00272 return CTRL_GOOD; 00273 else 00274 return CTRL_NO_PRESENT; 00275 } 00276 else 00277 return CTRL_NO_PRESENT; 00278 }
Ctrl_status mmc_sd_write_10 | ( | U32 | addr, | |
U16 | nb_sector | |||
) |
This fonction initialise the memory for a write operation.
DATA FLOW is: USB => MMC_SD
(sector = 512B)
addr | Sector address to start write | |
nb_sector | Number of sectors to transfer |
Definition at line 294 of file mmc_sd_mem.c.
References CTRL_GOOD, CTRL_NO_PRESENT, FALSE, mmc_sd_init_done, mmc_sd_mem_init(), mmc_sd_write_close(), mmc_sd_write_open(), mmc_sd_write_sector(), OK, Sdmmc_access_signal_off, Sdmmc_access_signal_on, and TRUE.
00295 { 00296 bit status; 00297 if (mmc_sd_init_done == FALSE) 00298 { 00299 mmc_sd_mem_init(); 00300 } 00301 if (mmc_sd_init_done == TRUE) 00302 { 00303 Sdmmc_access_signal_on(); 00304 mmc_sd_write_open(addr); 00305 status = mmc_sd_write_sector(nb_sector); 00306 mmc_sd_write_close(); 00307 Sdmmc_access_signal_off(); 00308 if (status == OK) 00309 return CTRL_GOOD; 00310 else 00311 return CTRL_NO_PRESENT; 00312 } 00313 else 00314 return CTRL_NO_PRESENT; 00315 }
Ctrl_status mmc_ram_2_mmc | ( | U32 | addr, | |
U8 * | ram | |||
) |
This fonction initialise the memory for a write operation from ram buffer to MMC/SD (1 sector).
DATA FLOW is: RAM => MMC
(sector = 512B)
addr | Sector address to write | |
ram | Ram buffer pointer |
Definition at line 333 of file mmc_sd_mem.c.
References CTRL_GOOD, CTRL_NO_PRESENT, FALSE, KO, mmc_sd_check_presence(), mmc_sd_init_done, mmc_sd_mem_init(), mmc_sd_write_close(), mmc_sd_write_open(), mmc_sd_write_sector_from_ram(), Sdmmc_access_signal_off, Sdmmc_access_signal_on, and TRUE.
00334 { 00335 #if (MMC_SD_RAM == ENABLE) 00336 Sdmmc_access_signal_on(); 00337 mmc_sd_check_presence(); 00338 if (mmc_sd_init_done == FALSE) 00339 { 00340 mmc_sd_mem_init(); 00341 } 00342 00343 if (mmc_sd_init_done == TRUE) 00344 { 00345 mmc_sd_write_open(addr); 00346 if (KO == mmc_sd_write_sector_from_ram(ram)) 00347 { 00348 mmc_sd_write_close(); 00349 Sdmmc_access_signal_off(); 00350 return CTRL_NO_PRESENT; 00351 } 00352 mmc_sd_write_close(); 00353 Sdmmc_access_signal_off(); 00354 return CTRL_GOOD; 00355 } 00356 Sdmmc_access_signal_off(); 00357 #endif // (MMC_SD_RAM == ENABLE) 00358 return CTRL_NO_PRESENT; 00359 }
Ctrl_status mmc_mmc_2_ram | ( | U32 | addr, | |
U8 * | ram | |||
) |
This fonction read 1 sector from MMC/SD to ram buffer.
DATA FLOW is: MMC => RAM
(sector = 512B)
addr | Sector address to read | |
ram | Ram buffer pointer |
Definition at line 373 of file mmc_sd_mem.c.
References CTRL_GOOD, CTRL_NO_PRESENT, FALSE, KO, mmc_sd_check_presence(), mmc_sd_init_done, mmc_sd_mem_init(), mmc_sd_read_close(), mmc_sd_read_open(), mmc_sd_read_sector_to_ram(), mmc_sd_write_close(), Sdmmc_access_signal_off, Sdmmc_access_signal_on, and TRUE.
00374 { 00375 #if (MMC_SD_RAM == ENABLE) 00376 Sdmmc_access_signal_on(); 00377 mmc_sd_check_presence(); 00378 if (mmc_sd_init_done == FALSE) 00379 { 00380 mmc_sd_mem_init(); 00381 } 00382 00383 if (mmc_sd_init_done == TRUE) 00384 { 00385 mmc_sd_read_open(addr); 00386 if (KO == mmc_sd_read_sector_to_ram(ram)) 00387 { 00388 mmc_sd_write_close(); 00389 Sdmmc_access_signal_off(); 00390 return CTRL_NO_PRESENT; 00391 } 00392 mmc_sd_read_close(); 00393 Sdmmc_access_signal_off(); 00394 return CTRL_GOOD; 00395 } 00396 Sdmmc_access_signal_off(); 00397 #endif // (MMC_SD_RAM == ENABLE) 00398 return CTRL_NO_PRESENT; 00399 }