//! This function initializes the memory for a write operation //! from ram buffer to SD/MMC (1 sector) //! //! DATA FLOW is: RAM => SD/MMC //! //! (sector = 512B) //! @param addr Sector address to write //! @param ram Ram buffer pointer //! //! @return Ctrl_status //! It is ready -> CTRL_GOOD //! An error occurs -> CTRL_FAIL //! Ctrl_status sd_mmc_spi_ram_2_mem(uint32_t addr, const void *ram) { Sd_mmc_spi_access_signal_on(); sd_mmc_spi_check_presence(); if (!sd_mmc_spi_init_done) { sd_mmc_spi_mem_init(); } if (sd_mmc_spi_init_done) { sd_mmc_spi_write_open(addr); if (!sd_mmc_spi_write_sector_from_ram(ram)) { sd_mmc_spi_write_close(); Sd_mmc_spi_access_signal_off(); return CTRL_NO_PRESENT; } sd_mmc_spi_write_close(); Sd_mmc_spi_access_signal_off(); return CTRL_GOOD; } Sd_mmc_spi_access_signal_off(); return CTRL_NO_PRESENT; }
Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) { if (!sd_mmc_spi_init_done) { sd_mmc_spi_mem_init(); } if (!sd_mmc_spi_init_done) return CTRL_NO_PRESENT; Sd_mmc_spi_access_signal_on(); if( !sd_mmc_spi_read_open(addr) ) goto sd_mmc_spi_usb_read_10_fail; if( !sd_mmc_spi_read_multiple_sector(nb_sector) ) goto sd_mmc_spi_usb_read_10_fail; if( !sd_mmc_spi_read_close() ) goto sd_mmc_spi_usb_read_10_fail; Sd_mmc_spi_access_signal_off(); return CTRL_GOOD; sd_mmc_spi_usb_read_10_fail: Sd_mmc_spi_access_signal_off(); return CTRL_FAIL; }
Ctrl_status sd_mmc_spi_mem_2_ram(uint32_t addr, void *ram) { Sd_mmc_spi_access_signal_on(); sd_mmc_spi_check_presence(); if (!sd_mmc_spi_init_done) { sd_mmc_spi_mem_init(); } if (!sd_mmc_spi_init_done) return CTRL_NO_PRESENT; if( !sd_mmc_spi_read_open(addr) ) goto sd_mmc_spi_mem_2_ram_fail; if( !sd_mmc_spi_read_sector_to_ram(ram)) goto sd_mmc_spi_mem_2_ram_fail; if( !sd_mmc_spi_read_close() ) goto sd_mmc_spi_mem_2_ram_fail; Sd_mmc_spi_access_signal_off(); return CTRL_GOOD; sd_mmc_spi_mem_2_ram_fail: Sd_mmc_spi_access_signal_off(); return CTRL_FAIL; }
Ctrl_status sd_mmc_spi_mem_2_ram(U32 addr, void *ram) { Sd_mmc_spi_access_signal_on(); sd_mmc_spi_check_presence(); if (sd_mmc_spi_init_done == FALSE) { sd_mmc_spi_mem_init(); } if (sd_mmc_spi_init_done == TRUE) { sd_mmc_spi_read_open(addr); if (KO == sd_mmc_spi_read_sector_to_ram(ram)) { sd_mmc_spi_write_close(); Sd_mmc_spi_access_signal_off(); return CTRL_NO_PRESENT; } sd_mmc_spi_read_close(); Sd_mmc_spi_access_signal_off(); return CTRL_GOOD; } Sd_mmc_spi_access_signal_off(); return CTRL_NO_PRESENT; }
Ctrl_status sd_mmc_spi_read_capacity(uint32_t *nb_sector) { // sd_mmc_spi_check_presence(); // omitted because creates interferences with "sd_mmc_spi_test_unit_ready()" function Sd_mmc_spi_access_signal_on(); if (!sd_mmc_spi_init_done) { sd_mmc_spi_mem_init(); } if (sd_mmc_spi_init_done) { *nb_sector = sd_mmc_spi_last_block_address+1; Sd_mmc_spi_access_signal_off(); return CTRL_GOOD; } else { Sd_mmc_spi_access_signal_off(); return CTRL_NO_PRESENT; } }
Ctrl_status sd_mmc_spi_read_capacity(U32 *u32_nb_sector) { // sd_mmc_spi_check_presence(); // ommited because creates interferences with "sd_mmc_spi_test_unit_ready()" function Sd_mmc_spi_access_signal_on(); if (sd_mmc_spi_init_done == FALSE) { sd_mmc_spi_mem_init(); } if (sd_mmc_spi_init_done == TRUE) { *u32_nb_sector = capacity; Sd_mmc_spi_access_signal_off(); return CTRL_GOOD; } else { Sd_mmc_spi_access_signal_off(); return CTRL_NO_PRESENT; } }
Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) { bool status; if (!sd_mmc_spi_init_done) { sd_mmc_spi_mem_init(); } if (sd_mmc_spi_init_done) { Sd_mmc_spi_access_signal_on(); sd_mmc_spi_write_open(addr); status = sd_mmc_spi_write_multiple_sector(nb_sector); sd_mmc_spi_write_close(); Sd_mmc_spi_access_signal_off(); if (status) return CTRL_GOOD; else return CTRL_NO_PRESENT; } else return CTRL_NO_PRESENT; }
Ctrl_status sd_mmc_spi_usb_write_10(U32 addr, U16 nb_sector) { Bool status; if (sd_mmc_spi_init_done == FALSE) { sd_mmc_spi_mem_init(); } if (sd_mmc_spi_init_done == TRUE) { Sd_mmc_spi_access_signal_on(); sd_mmc_spi_write_open(addr); status = sd_mmc_spi_write_multiple_sector(nb_sector); sd_mmc_spi_write_close(); Sd_mmc_spi_access_signal_off(); if (status == OK) return CTRL_GOOD; else return CTRL_NO_PRESENT; } else return CTRL_NO_PRESENT; }