#include "config.h"#include "conf_sdmmc.h"#include "mmc_sd_mem.h"#include "mmc_sd.h"
Go to the source code of this file.
Functions | |
| 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. | |
Variables | |
| xdata U32 | MMC_SD_DISK_SIZE |
| volatile U32 | mmc_sd_last_address |
| bit | mmc_sd_init_done |
| U8 | mmc_sd_presence_status = 0 |
| bit | mmc_sd_init_done |
Definition in file mmc_sd_mem.c.
| void mmc_sd_mem_init | ( | void | ) |
This function initializes the hw/sw ressources required to drive the MMC_SD.
| none |
Definition at line 79 of file mmc_sd_mem.c.
Referenced by mmc_mmc_2_ram(), mmc_ram_2_mmc(), mmc_sd_read_10(), mmc_sd_read_capacity(), and mmc_sd_write_10().
00080 { 00081 mmc_sd_init(); // Init the SPI bus and the MMC/SD card 00082 }
| 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 100 of file mmc_sd_mem.c.
00101 { 00102 Sdmmc_access_signal_on(); 00103 switch (mmc_sd_presence_status) 00104 { 00105 case MMCSD_REMOVED: 00106 mmc_sd_init_done = FALSE; 00107 if (OK == mmc_sd_mem_check()) 00108 { 00109 mmc_sd_presence_status = MMCSD_INSERTED; 00110 Sdmmc_access_signal_off(); 00111 return CTRL_BUSY; 00112 } 00113 Sdmmc_access_signal_off(); 00114 return CTRL_NO_PRESENT; 00115 00116 case MMCSD_INSERTED: 00117 if (OK != mmc_sd_mem_check()) 00118 { 00119 mmc_sd_presence_status = MMCSD_REMOVING; 00120 mmc_sd_init_done = FALSE; 00121 Sdmmc_access_signal_off(); 00122 return CTRL_BUSY; 00123 } 00124 Sdmmc_access_signal_off(); 00125 return CTRL_GOOD; 00126 00127 case MMCSD_REMOVING: 00128 mmc_sd_presence_status = MMCSD_REMOVED; 00129 Sdmmc_access_signal_off(); 00130 return CTRL_NO_PRESENT; 00131 00132 default: 00133 mmc_sd_presence_status = MMCSD_REMOVED; 00134 Sdmmc_access_signal_off(); 00135 return CTRL_BUSY; 00136 } 00137 00138 Sdmmc_access_signal_off(); 00139 return CTRL_BUSY; 00140 /* 00141 if (OK==mmc_sd_mem_check()) 00142 { 00143 if (mmc_sd_status_changed == FALSE) 00144 { 00145 mmc_sd_status_changed = TRUE; 00146 return CTRL_BUSY; // BUSY token must be returned to indicate a status change ! 00147 } 00148 else 00149 return CTRL_GOOD; // the 2nd time the host will ask for unit_ready, we can answer GOOD if we have returned BUSY first ! 00150 } 00151 else 00152 { 00153 if (mmc_sd_status_changed == TRUE) 00154 { 00155 mmc_sd_status_changed = FALSE; 00156 return CTRL_BUSY; // BUSY token must be returned to indicate a status change ! 00157 } 00158 else 00159 return CTRL_NO_PRESENT; 00160 } 00161 */ 00162 }
| 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 176 of file mmc_sd_mem.c.
00177 { 00178 // mmc_sd_check_presence(); // ommited because creates interferences with "mmc_sd_test_unit_ready()" function 00179 Sdmmc_access_signal_on(); 00180 if (mmc_sd_init_done == FALSE) 00181 { 00182 mmc_sd_mem_init(); 00183 } 00184 if (mmc_sd_init_done == TRUE) 00185 { 00186 *u32_nb_sector = mmc_sd_last_block_address; 00187 Sdmmc_access_signal_off(); 00188 return CTRL_GOOD; 00189 } 00190 else 00191 { 00192 Sdmmc_access_signal_off(); 00193 return CTRL_NO_PRESENT; 00194 } 00195 }
| 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 209 of file mmc_sd_mem.c.
00210 { 00211 return FALSE; 00212 }
| Bool mmc_sd_removal | ( | void | ) |
This function tells if the memory has been removed or not.
| none |
Definition at line 224 of file mmc_sd_mem.c.
00225 { 00226 return FALSE; 00227 // return ((OK == mmc_sd_check_presence()) ? FALSE : TRUE); 00228 }
| 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 250 of file mmc_sd_mem.c.
00251 { 00252 bit status; 00253 if (mmc_sd_init_done == FALSE) 00254 { 00255 mmc_sd_mem_init(); 00256 } 00257 if (mmc_sd_init_done == TRUE) 00258 { 00259 Sdmmc_access_signal_on(); 00260 mmc_sd_read_open(addr); 00261 status = mmc_sd_read_sector(nb_sector); 00262 mmc_sd_read_close(); 00263 Sdmmc_access_signal_off(); 00264 if (status == OK) 00265 return CTRL_GOOD; 00266 else 00267 return CTRL_NO_PRESENT; 00268 } 00269 else 00270 return CTRL_NO_PRESENT; 00271 }
| 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 287 of file mmc_sd_mem.c.
00288 { 00289 bit status; 00290 if (mmc_sd_init_done == FALSE) 00291 { 00292 mmc_sd_mem_init(); 00293 } 00294 if (mmc_sd_init_done == TRUE) 00295 { 00296 Sdmmc_access_signal_on(); 00297 mmc_sd_write_open(addr); 00298 status = mmc_sd_write_sector(nb_sector); 00299 mmc_sd_write_close(); 00300 Sdmmc_access_signal_off(); 00301 if (status == OK) 00302 return CTRL_GOOD; 00303 else 00304 return CTRL_NO_PRESENT; 00305 } 00306 else 00307 return CTRL_NO_PRESENT; 00308 }
| 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 326 of file mmc_sd_mem.c.
00327 { 00328 #if (MMC_SD_RAM == ENABLE) 00329 Sdmmc_access_signal_on(); 00330 mmc_sd_check_presence(); 00331 if (mmc_sd_init_done == FALSE) 00332 { 00333 mmc_sd_mem_init(); 00334 } 00335 00336 if (mmc_sd_init_done == TRUE) 00337 { 00338 mmc_sd_write_open(addr); 00339 if (KO == mmc_sd_write_sector_from_ram(ram)) 00340 { 00341 mmc_sd_write_close(); 00342 Sdmmc_access_signal_off(); 00343 return CTRL_NO_PRESENT; 00344 } 00345 mmc_sd_write_close(); 00346 Sdmmc_access_signal_off(); 00347 return CTRL_GOOD; 00348 } 00349 Sdmmc_access_signal_off(); 00350 #endif // (MMC_SD_RAM == ENABLE) 00351 return CTRL_NO_PRESENT; 00352 }
| 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 366 of file mmc_sd_mem.c.
00367 { 00368 #if (MMC_SD_RAM == ENABLE) 00369 Sdmmc_access_signal_on(); 00370 mmc_sd_check_presence(); 00371 if (mmc_sd_init_done == FALSE) 00372 { 00373 mmc_sd_mem_init(); 00374 } 00375 00376 if (mmc_sd_init_done == TRUE) 00377 { 00378 mmc_sd_read_open(addr); 00379 if (KO == mmc_sd_read_sector_to_ram(ram)) 00380 { 00381 mmc_sd_write_close(); 00382 Sdmmc_access_signal_off(); 00383 return CTRL_NO_PRESENT; 00384 } 00385 mmc_sd_read_close(); 00386 Sdmmc_access_signal_off(); 00387 return CTRL_GOOD; 00388 } 00389 Sdmmc_access_signal_off(); 00390 #endif // (MMC_SD_RAM == ENABLE) 00391 return CTRL_NO_PRESENT; 00392 }
| xdata U32 MMC_SD_DISK_SIZE |
| volatile U32 mmc_sd_last_address |
| bit mmc_sd_init_done |
| bit mmc_sd_init_done |
1.5.3