working version
Dependencies: mbed mbed-rtos SimpleDMA FreescaleIAP eeprom
Fork of CDMS_CODE_FM_28JAN2017 by
Diff: cdms_sd.h
- Revision:
- 207:28a07943dded
- Parent:
- 206:fba4aeebf004
diff -r fba4aeebf004 -r 28a07943dded cdms_sd.h --- a/cdms_sd.h Thu Jun 30 14:00:33 2016 +0000 +++ b/cdms_sd.h Sat Jul 02 10:48:30 2016 +0000 @@ -1,4 +1,3 @@ -#include "cdms_rtc.h" //SPI spi(PTE1, PTE3, PTE2); // MOSI,MISO, CLOCK microcontroller(in order) //DigitalOut cs_sd(PTE22); @@ -42,6 +41,7 @@ int disk_write(const uint8_t *, uint64_t); int disk_read(uint8_t *, uint64_t); int disk_erase(int,int); +int disk_read_statusbits(uint8_t *); void FCTN_SD_MNG(); int INCREMENT_SD_LIB(uint8_t); @@ -61,7 +61,6 @@ #define SDCARD_V1 1 #define SDCARD_V2 2 #define SDCARD_V2HC 3 -DigitalOut SD_SW_EN_DS (PIN97); int cdv; uint64_t sd_sectors(); @@ -131,6 +130,7 @@ { fsc=(uint32_t)(buffer[0]<<24)+(uint32_t)(buffer[1]<<16)+(uint32_t)(buffer[2]<<8)+(uint32_t)buffer[3]; start_fsc=(uint32_t)(buffer[4]<<24)+(uint32_t)(buffer[5]<<16)+(uint32_t)(buffer[6]<<8)+(uint32_t)buffer[7]; + fsc++; buffer[0]=(uint8_t) (fsc>>24 & 0xFF); buffer[1]=(uint8_t) (fsc>>16 & 0xFF); buffer[2]=(uint8_t) (fsc>>8 & 0xFF); @@ -143,12 +143,20 @@ buffer[6]=(uint8_t) (start_fsc>>8 & 0xFF); buffer[7]=(uint8_t) (start_fsc & 0xFF); } - return disk_write(buffer,SD_MNG_SECT); + + i = disk_write(buffer,SD_MNG_SECT); + if(i == 0) + { + FSC_CURRENT[1] = fsc; + FSC_LAST[1] = start_fsc; + return i; + } } if(sid==0x02) { fsc=(uint32_t)(buffer[8]<<24)+(uint32_t)(buffer[9]<<16)+(uint32_t)(buffer[10]<<8)+(uint32_t)buffer[11]; start_fsc=(uint32_t)(buffer[12]<<24)+(uint32_t)(buffer[13]<<16)+(uint32_t)(buffer[14]<<8)+(uint32_t)buffer[15]; + fsc++; buffer[8]=(uint8_t) (fsc>>24 & 0xFF); buffer[9]=(uint8_t) (fsc>>16 & 0xFF); buffer[10]=(uint8_t) (fsc>>8 & 0xFF); @@ -161,12 +169,19 @@ buffer[14]=(uint8_t) (start_fsc>>8 & 0xFF); buffer[15]=(uint8_t) (start_fsc & 0xFF); } - return disk_write(buffer,SD_MNG_SECT); + i = disk_write(buffer,SD_MNG_SECT); + if(i == 0) + { + FSC_CURRENT[2] = fsc; + FSC_LAST[2] = start_fsc; + return i; + } } if(sid==0x03) { fsc=(uint32_t)(buffer[16]<<24)+(uint32_t)(buffer[17]<<16)+(uint32_t)(buffer[18]<<8)+(uint32_t)buffer[19]; start_fsc=(uint32_t)(buffer[20]<<24)+(uint32_t)(buffer[21]<<16)+(uint32_t)(buffer[22]<<8)+(uint32_t)buffer[23]; + fsc++; buffer[16]=(uint8_t) (fsc>>24 & 0xFF); buffer[17]=(uint8_t) (fsc>>16 & 0xFF); buffer[18]=(uint8_t) (fsc>>8 & 0xFF); @@ -179,12 +194,19 @@ buffer[22]=(uint8_t) (start_fsc>>8 & 0xFF); buffer[23]=(uint8_t) (start_fsc & 0xFF); } - return disk_write(buffer,SD_MNG_SECT); + i = disk_write(buffer,SD_MNG_SECT); + if(i == 0) + { + FSC_CURRENT[3] = fsc; + FSC_LAST[3] = start_fsc; + return i; + } } if(sid==0x04) { fsc=(uint32_t)(buffer[24]<<24)+(uint32_t)(buffer[25]<<16)+(uint32_t)(buffer[26]<<8)+(uint32_t)buffer[27]; start_fsc=(uint32_t)(buffer[28]<<24)+(uint32_t)(buffer[29]<<16)+(uint32_t)(buffer[30]<<8)+(uint32_t)buffer[31]; + fsc++; buffer[24]=(uint8_t) (fsc>>24 & 0xFF); buffer[25]=(uint8_t) (fsc>>16 & 0xFF); buffer[26]=(uint8_t) (fsc>>8 & 0xFF); @@ -197,12 +219,19 @@ buffer[30]=(uint8_t) (start_fsc>>8 & 0xFF); buffer[31]=(uint8_t) (start_fsc & 0xFF); } - return disk_write(buffer,SD_MNG_SECT); + i = disk_write(buffer,SD_MNG_SECT); + if(i == 0) + { + FSC_CURRENT[4] = fsc; + FSC_LAST[4] = start_fsc; + return i; + } } if(sid==0x05) { fsc=(uint32_t)(buffer[32]<<24)+(uint32_t)(buffer[33]<<16)+(uint32_t)(buffer[34]<<8)+(uint32_t)buffer[35]; start_fsc=(uint32_t)(buffer[36]<<24)+(uint32_t)(buffer[37]<<16)+(uint32_t)(buffer[38]<<8)+(uint32_t)buffer[39]; + fsc++; buffer[32]=(uint8_t) (fsc>>24 & 0xFF); buffer[33]=(uint8_t) (fsc>>16 & 0xFF); buffer[34]=(uint8_t) (fsc>>8 & 0xFF); @@ -215,7 +244,13 @@ buffer[38]=(uint8_t) (start_fsc>>8 & 0xFF); buffer[39]=(uint8_t) (start_fsc & 0xFF); } - return disk_write(buffer,SD_MNG_SECT); + i = disk_write(buffer,SD_MNG_SECT); + if(i == 0) + { + FSC_CURRENT[5] = fsc; + FSC_LAST[5] = start_fsc; + return i; + } } return -1; } @@ -653,6 +688,7 @@ { // set read address for single block (CMD17) if (cmd(17, block_number * cdv) != 0) { + SD_RD_ERROR = 1; return 1; } @@ -695,4 +731,15 @@ } return 0; //normal return +} + +int disk_read_statusbits(uint8_t *buffer) +{ + if (cmd(17, 0) != 0) { + SD_RD_ERROR = 1; + return -1; + } + + // receive the data + return read(buffer,64); } \ No newline at end of file