00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00013 00014 /* Copyright (c) 2007, Atmel Corporation All rights reserved. 00015 * 00016 * Redistribution and use in source and binary forms, with or without 00017 * modification, are permitted provided that the following conditions are met: 00018 * 00019 * 1. Redistributions of source code must retain the above copyright notice, 00020 * this list of conditions and the following disclaimer. 00021 * 00022 * 2. Redistributions in binary form must reproduce the above copyright notice, 00023 * this list of conditions and the following disclaimer in the documentation 00024 * and/or other materials provided with the distribution. 00025 * 00026 * 3. The name of ATMEL may not be used to endorse or promote products derived 00027 * from this software without specific prior written permission. 00028 * 00029 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED 00030 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00031 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND 00032 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00033 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00034 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00035 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00036 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00037 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00038 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00039 */ 00040 00041 //_____ I N C L U D E S ___________________________________________________ 00042 00043 #include "config.h" // system configuration 00044 #include "conf_sdmmc.h" 00045 #include "mmc_sd_mem.h" 00046 #include "mmc_sd.h" 00047 00048 //_____ M A C R O S ________________________________________________________ 00049 00050 00051 //_____ P R I V A T E D E C L A R A T I O N _____________________________ 00052 00053 00054 //_____ D E F I N I T I O N ________________________________________________ 00055 00056 00057 //extern xdata U32 mmc_sd_mem_size; 00058 extern xdata U32 MMC_SD_DISK_SIZE; 00059 extern volatile U32 mmc_sd_last_address; 00060 extern bit mmc_sd_init_done; 00061 00062 U8 mmc_sd_presence_status = 0; 00063 extern bit mmc_sd_init_done; 00064 00065 00066 00067 //_____ D E C L A R A T I O N ______________________________________________ 00068 00079 void mmc_sd_mem_init(void) 00080 { 00081 mmc_sd_init(); // Init the SPI bus and the MMC/SD card 00082 } 00083 00084 00100 Ctrl_status mmc_sd_test_unit_ready(void) 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 } 00163 00164 00176 Ctrl_status mmc_sd_read_capacity( U32 _MEM_TYPE_SLOW_ *u32_nb_sector ) 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 } 00196 00197 00209 Bool mmc_sd_wr_protect(void) 00210 { 00211 return FALSE; 00212 } 00213 00214 00224 Bool mmc_sd_removal(void) 00225 { 00226 return FALSE; 00227 // return ((OK == mmc_sd_check_presence()) ? FALSE : TRUE); 00228 } 00229 00230 00231 00232 //------------ STANDARD FUNCTIONS to read/write the memory -------------------- 00233 00250 Ctrl_status mmc_sd_read_10( U32 addr , U16 nb_sector ) 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 } 00272 00273 00287 Ctrl_status mmc_sd_write_10( U32 addr , U16 nb_sector ) 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 } 00309 00310 00311 //------------ Standard functions for read/write 1 sector to 1 sector ram buffer ----------------- 00312 00326 Ctrl_status mmc_ram_2_mmc(U32 addr, U8 *ram) 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 } 00353 00366 Ctrl_status mmc_mmc_2_ram( U32 addr, U8 *ram) 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 } 00393 00394
1.5.3