63,6 → 63,8 |
#include "main.h" |
#include "crc16.h" |
|
|
|
//________________________________________________________________________________________________________________________________________ |
// Module name: sdc.c |
// Compiler used: avr-gcc 3.4.5 |
133,6 → 135,7 |
#define DATA_RESPONSE_WRITE_ERR 0x1D |
|
volatile SDCardInfo_t SDCardInfo; |
u8 SDCardWriteRetryCounterMax; |
|
|
//________________________________________________________________________________________________________________________________________ |
170,7 → 173,7 |
u32 timestamp = 0; |
|
SSC_ClearRxFifo(); |
SSC_Enable(); // enable chipselect. |
SSC_Enable(); // enable chipselect. SSC_Disable |
timestamp = SetDelay(timeout); |
do |
{ |
288,6 → 291,7 |
else */ |
result = SD_SUCCESS; |
end: |
SSC_Disable(); // disable CS |
if(result != SD_SUCCESS) |
{ |
sprintf(text,"Error %02X reading data from sd card (R1=%02X).\r\n", result, rsp); |
379,6 → 383,8 |
u32 timeout = 0; |
u8 rsp[6]; // SD-SPI response buffer |
SD_Result_t result = SD_ERROR_UNKNOWN; |
|
//SDCardWriteRetryCounterMax = 0; |
|
if(SD_SWITCH) // init only if the SD-Switch is indicating a card in the slot |
{ |
607,7 → 613,8 |
SDCardInfo.Valid = 1; |
// jump point for error condition before |
end: |
SSC_Disable(); |
//SSC_Disable(); |
; |
} |
else |
{ |
654,12 → 661,18 |
|
SD_Result_t SDC_PutSector(u32 addr, const u8 *Buffer) |
{ |
u8 rsp; |
u8 retryCounter = 0; |
u8 rsp; |
u16 a, crc16; |
u16 timeout = 0; |
SD_Result_t result = SD_ERROR_UNKNOWN; |
SD_Result_t result; |
|
addr = addr << 9; // convert sectoradress to byteadress |
|
while(retryCounter < 10) |
{ |
result = SD_ERROR_UNKNOWN; |
|
rsp = SDC_SendCMDR1(CMD_WRITE_SINGLE_BLOCK, addr); |
if (rsp != R1_NO_ERR) |
{ |
738,12 → 751,21 |
goto end; |
} |
end: |
//SSC_Disable(); // disable CS |
if(result != SD_SUCCESS) |
{ |
sprintf(text,"Error %02X writing data to sd card (R=%02X).\r\n", result, rsp); |
UART1_PutString(text); |
retryCounter++; |
} |
else break; // Success -> end retry loop |
|
} |
if (retryCounter > SDCardWriteRetryCounterMax) |
{ SDCardWriteRetryCounterMax = retryCounter; |
DebugOut.Analog[18] = SDCardWriteRetryCounterMax; |
} |
|
|
return(result); |
} |
|