SDFileSystem which uses SimpleDMA to efficiently write to the SD card, while other Threads in the RTOS continue running
Dependencies: FATFileSystem RTOS_SPI
Dependents: SDFileSystem_RTOS_HelloWorld RdGasUseMonitor keiki2017 keiki2018
Fork of SDFileSystem by
Diff: SDFileSystem.cpp
- Revision:
- 3:1a4ffe455d3c
- Parent:
- 2:c8f66dc765d4
--- a/SDFileSystem.cpp Thu Nov 29 10:56:21 2012 +0000 +++ b/SDFileSystem.cpp Thu Dec 26 14:22:37 2013 +0000 @@ -202,6 +202,7 @@ int SDFileSystem::disk_initialize() { int i = initialise_card(); debug_if(SD_DBG, "init card = %d\n", i); + _sectors = _sd_sectors(); // Set block length to 512 (CMD16) @@ -227,9 +228,8 @@ int SDFileSystem::disk_read(uint8_t *buffer, uint64_t block_number) { // set read address for single block (CMD17) - if (_cmd(17, block_number * cdv) != 0) { + if (_cmd(17, block_number * cdv) != 0) return 1; - } // receive the data _read(buffer, 512); @@ -351,14 +351,12 @@ int SDFileSystem::_read(uint8_t *buffer, uint32_t length) { _cs = 0; - // read until start byte (0xFF) - while (_spi.write(0xFF) != 0xFE); + while (_spi.write(0xFF) != 0xFE); - // read data - for (int i = 0; i < length; i++) { - buffer[i] = _spi.write(0xFF); - } + uint8_t writeval[1] = {0xFF}; + _spi.bulkReadWrite(buffer, writeval, length, false); + _spi.write(0xFF); // checksum _spi.write(0xFF); @@ -373,27 +371,25 @@ // indicate start of block _spi.write(0xFE); - // write the data - for (int i = 0; i < length; i++) { - _spi.write(buffer[i]); - } + _spi.bulkWrite((uint8_t*)buffer, length); // write the checksum _spi.write(0xFF); _spi.write(0xFF); - + // check the response token if ((_spi.write(0xFF) & 0x1F) != 0x05) { _cs = 1; _spi.write(0xFF); return 1; } - + // wait for write to finish while (_spi.write(0xFF) == 0); _cs = 1; _spi.write(0xFF); + return 0; } @@ -456,10 +452,11 @@ blocks = (hc_c_size+1)*1024; debug_if(SD_DBG, "\n\rSDHC Card \n\rhc_c_size: %d\n\rcapacity: %lld \n\rsectors: %lld\n\r", hc_c_size, blocks*512, blocks); break; + default: debug("CSD struct unsupported\r\n"); return 0; }; - return blocks; + return 10000; }