Rev 380 | Rev 399 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 380 | Rev 384 | ||
---|---|---|---|
Line 61... | Line 61... | ||
61 | #include "ssc.h" |
61 | #include "ssc.h" |
62 | #include "timer1.h" |
62 | #include "timer1.h" |
63 | #include "main.h" |
63 | #include "main.h" |
64 | #include "crc16.h" |
64 | #include "crc16.h" |
Line -... | Line 65... | ||
- | 65 | ||
- | 66 | ||
65 | 67 | ||
66 | //________________________________________________________________________________________________________________________________________ |
68 | //________________________________________________________________________________________________________________________________________ |
67 | // Module name: sdc.c |
69 | // Module name: sdc.c |
68 | // Compiler used: avr-gcc 3.4.5 |
70 | // Compiler used: avr-gcc 3.4.5 |
69 | // Last Modifikation: 08.06.2008 |
71 | // Last Modifikation: 08.06.2008 |
Line 131... | Line 133... | ||
131 | #define DATA_RESPONSE_OK 0x05 |
133 | #define DATA_RESPONSE_OK 0x05 |
132 | #define DATA_RESPONSE_CRC_ERR 0x0B |
134 | #define DATA_RESPONSE_CRC_ERR 0x0B |
133 | #define DATA_RESPONSE_WRITE_ERR 0x1D |
135 | #define DATA_RESPONSE_WRITE_ERR 0x1D |
Line 134... | Line 136... | ||
134 | 136 | ||
- | 137 | volatile SDCardInfo_t SDCardInfo; |
|
Line 135... | Line 138... | ||
135 | volatile SDCardInfo_t SDCardInfo; |
138 | u8 SDCardWriteRetryCounterMax; |
136 | 139 | ||
137 | 140 | ||
Line 168... | Line 171... | ||
168 | { |
171 | { |
169 | u8 rsp = 0; |
172 | u8 rsp = 0; |
170 | u32 timestamp = 0; |
173 | u32 timestamp = 0; |
Line 171... | Line 174... | ||
171 | 174 | ||
172 | SSC_ClearRxFifo(); |
175 | SSC_ClearRxFifo(); |
173 | SSC_Enable(); // enable chipselect. |
176 | SSC_Enable(); // enable chipselect. SSC_Disable |
174 | timestamp = SetDelay(timeout); |
177 | timestamp = SetDelay(timeout); |
175 | do |
178 | do |
176 | { |
179 | { |
177 | rsp = SSC_GetChar(); |
180 | rsp = SSC_GetChar(); |
Line 286... | Line 289... | ||
286 | crc16 = (crc16<<8)|SSC_GetChar(); // lowbyte last |
289 | crc16 = (crc16<<8)|SSC_GetChar(); // lowbyte last |
287 | /* if(crc16 != CRC16(Buffer, len)) result = SD_ERROR_CRC_DATA; |
290 | /* if(crc16 != CRC16(Buffer, len)) result = SD_ERROR_CRC_DATA; |
288 | else */ |
291 | else */ |
289 | result = SD_SUCCESS; |
292 | result = SD_SUCCESS; |
290 | end: |
293 | end: |
- | 294 | SSC_Disable(); // disable CS |
|
291 | if(result != SD_SUCCESS) |
295 | if(result != SD_SUCCESS) |
292 | { |
296 | { |
293 | sprintf(text,"Error %02X reading data from sd card (R1=%02X).\r\n", result, rsp); |
297 | sprintf(text,"Error %02X reading data from sd card (R1=%02X).\r\n", result, rsp); |
294 | UART1_PutString(text); |
298 | UART1_PutString(text); |
295 | } |
299 | } |
Line 377... | Line 381... | ||
377 | SD_Result_t SDC_Init(void) |
381 | SD_Result_t SDC_Init(void) |
378 | { |
382 | { |
379 | u32 timeout = 0; |
383 | u32 timeout = 0; |
380 | u8 rsp[6]; // SD-SPI response buffer |
384 | u8 rsp[6]; // SD-SPI response buffer |
381 | SD_Result_t result = SD_ERROR_UNKNOWN; |
385 | SD_Result_t result = SD_ERROR_UNKNOWN; |
- | 386 | ||
- | 387 | //SDCardWriteRetryCounterMax = 0; |
|
Line 382... | Line 388... | ||
382 | 388 | ||
383 | if(SD_SWITCH) // init only if the SD-Switch is indicating a card in the slot |
389 | if(SD_SWITCH) // init only if the SD-Switch is indicating a card in the slot |
384 | { |
390 | { |
385 | UART1_PutString("\r\n SSC init..."); |
391 | UART1_PutString("\r\n SSC init..."); |
Line 605... | Line 611... | ||
605 | 611 | ||
606 | SDC_PrintCID((u8 *)&SDCardInfo.CID); |
612 | SDC_PrintCID((u8 *)&SDCardInfo.CID); |
607 | SDCardInfo.Valid = 1; |
613 | SDCardInfo.Valid = 1; |
608 | // jump point for error condition before |
614 | // jump point for error condition before |
609 | end: |
615 | end: |
- | 616 | //SSC_Disable(); |
|
610 | SSC_Disable(); |
617 | ; |
611 | } |
618 | } |
612 | else |
619 | else |
613 | { |
620 | { |
614 | SSC_Deinit(); |
621 | SSC_Deinit(); |
Line 652... | Line 659... | ||
652 | // Returnvalue: SD_Result_t |
659 | // Returnvalue: SD_Result_t |
653 | //________________________________________________________________________________________________________________________________________ |
660 | //________________________________________________________________________________________________________________________________________ |
Line 654... | Line 661... | ||
654 | 661 | ||
655 | SD_Result_t SDC_PutSector(u32 addr, const u8 *Buffer) |
662 | SD_Result_t SDC_PutSector(u32 addr, const u8 *Buffer) |
- | 663 | { |
|
656 | { |
664 | u8 retryCounter = 0; |
657 | u8 rsp; |
665 | u8 rsp; |
658 | u16 a, crc16; |
666 | u16 a, crc16; |
659 | u16 timeout = 0; |
667 | u16 timeout = 0; |
Line 660... | Line 668... | ||
660 | SD_Result_t result = SD_ERROR_UNKNOWN; |
668 | SD_Result_t result; |
- | 669 | ||
- | 670 | addr = addr << 9; // convert sectoradress to byteadress |
|
- | 671 | ||
- | 672 | while(retryCounter < 10) |
|
- | 673 | { |
|
661 | 674 | result = SD_ERROR_UNKNOWN; |
|
662 | addr = addr << 9; // convert sectoradress to byteadress |
675 | |
663 | rsp = SDC_SendCMDR1(CMD_WRITE_SINGLE_BLOCK, addr); |
676 | rsp = SDC_SendCMDR1(CMD_WRITE_SINGLE_BLOCK, addr); |
664 | if (rsp != R1_NO_ERR) |
677 | if (rsp != R1_NO_ERR) |
665 | { |
678 | { |
Line 736... | Line 749... | ||
736 | result = SD_ERROR_WRITE_DATA; |
749 | result = SD_ERROR_WRITE_DATA; |
737 | SSC_GetChar(); |
750 | SSC_GetChar(); |
738 | goto end; |
751 | goto end; |
739 | } |
752 | } |
740 | end: |
753 | end: |
- | 754 | //SSC_Disable(); // disable CS |
|
741 | if(result != SD_SUCCESS) |
755 | if(result != SD_SUCCESS) |
742 | { |
756 | { |
743 | sprintf(text,"Error %02X writing data to sd card (R=%02X).\r\n", result, rsp); |
757 | sprintf(text,"Error %02X writing data to sd card (R=%02X).\r\n", result, rsp); |
744 | UART1_PutString(text); |
758 | UART1_PutString(text); |
- | 759 | retryCounter++; |
|
- | 760 | } |
|
- | 761 | else break; // Success -> end retry loop |
|
- | 762 | ||
- | 763 | } |
|
- | 764 | if (retryCounter > SDCardWriteRetryCounterMax) |
|
- | 765 | { SDCardWriteRetryCounterMax = retryCounter; |
|
- | 766 | DebugOut.Analog[18] = SDCardWriteRetryCounterMax; |
|
745 | } |
767 | } |
746 | 768 | ||
747 | return(result); |
769 | return(result); |
748 | } |
770 | } |
Line 749... | Line 771... | ||
749 | 771 |