vr1.1
Dependencies: FreescaleIAP mbed-rtos mbed
Fork of CDMS_RTOS_v1_1 by
Diff: SDCard.cpp
- Revision:
- 11:d6dc9074075b
- Parent:
- 8:607ae92fa6af
- Child:
- 12:cb3ee1ac3638
--- a/SDCard.cpp Sat Jul 04 10:48:18 2015 +0000 +++ b/SDCard.cpp Mon Jul 06 06:25:14 2015 +0000 @@ -6,16 +6,38 @@ SPI spi_SD(PTD6, PTD7, PTD5); // mosi, miso, sclk DigitalOut cs_SD(D2); -int count_bro; -int cdv; -uint64_t sectors; - int *FCTN_INIT_SD() { + all_flags = all_flags|SDCARD_INIT_STATUS; int sd_response[2] = {initialise_card(),disk_initialize()}; return sd_response; } +int FCTN_RD_SD(uint8_t *buffer, uint64_t block_number) { + // set read address for single block (CMD17) + if (cmd(17, block_number * cdv) != 0) { + return 1; + } + + // receive the data + read(buffer, 512); + printf("Written Successfully to SDCard\r\n"); + return 0; +} + +int FCTN_WR_SD(const uint8_t *buffer, uint64_t block_number) +{ + // set write address for single block (CMD24) + if (cmd(24, block_number * cdv) != 0) { + return 1; + } + + // send the data block + write(buffer, 512); + printf("Written Successfully to SDCard\r\n"); + return 0; +} + int initialise_card() { // Set to 100kHz for initialisation, and clock card with cs_SD = 1 @@ -36,8 +58,7 @@ if (r == R1_IDLE_STATE) { printf("Entering v2 bro\r\n"); - return initialise_card_v2(); - + return initialise_card_v2(); } else { @@ -46,23 +67,6 @@ } } -int initialise_card_v1() { - for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { - cmd(55, 0); - if (cmd(41, 0) == 0) { - printf("Yuppie v1 successful\r\n"); - cdv = 512; - debug_if(SD_DBG, "\r\n\rInit: SEDCARD_V1\r\n\r"); - - return SDCARD_V1; - } - } - - debug("Timeout waiting for v1.x card\r\n"); - return SDCARD_FAIL; -} - - int initialise_card_v2() { for (int i = 0; i < SD_COMMAND_TIMEOUT; i++) { wait_ms(50); @@ -81,6 +85,25 @@ debug("Timeout waiting for v2.x card\r\n"); return SDCARD_FAIL; } + +int disk_initialize() { + int i = initialise_card(); + debug_if(SD_DBG, "init card = %d\r\n", i); + sectors = sd_sectors(); + + // Set block length to 512 (CMD16) + if (cmd(16, 512) != 0) { + debug("Set 512-byte block timed out\r\n"); + return 1; + } + else + { + printf("Hey,block init succesful\r\n"); + } + + spi_SD.frequency(1000000); // Set to 1MHz for data transfer + return 0; +} int cmd(int cmd, int arg) { cs_SD = 0; @@ -277,39 +300,6 @@ return bits; } -int disk_initialize() { - int i = initialise_card(); - debug_if(SD_DBG, "init card = %d\r\n", i); - sectors = sd_sectors(); - - // Set block length to 512 (CMD16) - if (cmd(16, 512) != 0) { - debug("Set 512-byte block timed out\r\n"); - return 1; - } - else - { - printf("Hey,block init succesful\r\n"); - } - - spi_SD.frequency(1000000); // Set to 1MHz for data transfer - return 0; -} - -int FCTN_WR_SD(const uint8_t *buffer, uint64_t block_number) - -{ - // set write address for single block (CMD24) - if (cmd(24, block_number * cdv) != 0) { - return 1; - } - - // send the data block - write(buffer, 512); - printf("Written Successfully bro \r\n"); - return 0; -} - int write(const uint8_t*buffer, uint32_t length) { cs_SD = 0; @@ -338,15 +328,4 @@ cs_SD = 1; spi_SD.write(0xFF); return 0; -} - -int FCTN_RD_SD(uint8_t *buffer, uint64_t block_number) { - // set read address for single block (CMD17) - if (cmd(17, block_number * cdv) != 0) { - return 1; - } - - // receive the data - read(buffer, 512); - return 0; } \ No newline at end of file