Rev 23 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 23 | Rev 171 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
5 | // + Copyright (c) 2008 Ingo Busker, Holger Buss |
6 | // + Nur für den privaten Gebrauch |
6 | // + Nur für den privaten Gebrauch / NON-COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
7 | // + FOR NON COMMERCIAL USE ONLY |
8 | // + www.MikroKopter.com |
8 | // + www.MikroKopter.com |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
10 | // + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation), |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
11 | // + dass eine Nutzung (auch auszugsweise) nur für den privaten (nicht-kommerziellen) Gebrauch zulässig ist. |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
12 | // + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
13 | // + bzgl. der Nutzungsbedingungen aufzunehmen. |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
14 | // + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen, |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
15 | // + Verkauf von Luftbildaufnahmen, usw. |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
16 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
17 | // + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht, |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
18 | // + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
19 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
20 | // + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
21 | // + auf anderen Webseiten oder sonstigen Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de" |
22 | // + eindeutig als Ursprung verlinkt werden |
22 | // + eindeutig als Ursprung verlinkt werden |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
23 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
24 | // + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion |
25 | // + Benutzung auf eigene Gefahr |
25 | // + Benutzung auf eigene Gefahr |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
26 | // + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
28 | // + Die PORTIERUNG der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
28 | // + Die Portierung oder Nutzung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur |
29 | // + mit unserer Zustimmung zulässig |
29 | // + mit unserer Zustimmung zulässig |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
30 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
31 | // + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
33 | // + Redistributions of source code (with or without modifications) must retain the above copyright notice, |
34 | // + this list of conditions and the following disclaimer. |
34 | // + this list of conditions and the following disclaimer. |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
35 | // + * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived |
36 | // + from this software without specific prior written permission. |
36 | // + from this software without specific prior written permission. |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
37 | // + * The use of this project (hardware, software, binary files, sources and documentation) is only permitted |
38 | // + for non-commercial use (directly or indirectly) |
38 | // + for non-commercial use (directly or indirectly) |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
39 | // + Commercial use (for excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted |
40 | // + with our written permission |
40 | // + with our written permission |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
41 | // + * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be |
42 | // + clearly linked as origin |
42 | // + clearly linked as origin |
43 | // + * PORTING this software (or part of it) to systems (other than hardware from www.mikrokopter.de) is NOT allowed |
43 | // + * porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
44 | // |
44 | // |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
45 | // + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
46 | // + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
47 | // + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
48 | // + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
49 | // + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
50 | // + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
51 | // + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
52 | // + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
53 | // + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
54 | // + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
55 | // + POSSIBILITY OF SUCH DAMAGE. |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
57 | #include "main.h" |
57 | #include "main.h" |
58 | 58 | ||
59 | 59 | ||
60 | //________________________________________________________________________________________________________________________________________ |
60 | //________________________________________________________________________________________________________________________________________ |
61 | // Module name: mmc.c |
61 | // Module name: mmc.c |
62 | // Compiler used: avr-gcc 3.4.5 |
62 | // Compiler used: avr-gcc 3.4.5 |
63 | // Last Modifikation: 24.07.2007 |
63 | // Last Modifikation: 24.07.2007 |
64 | // Version: 1.05 |
64 | // Version: 1.05 |
65 | // Authors: Stephan Busker |
65 | // Authors: Stephan Busker |
66 | // Description: Source files for connecting to an sdcard using the SSC |
66 | // Description: Source files for connecting to an sdcard using the SSC |
67 | // |
67 | // |
68 | //........................................................................................................................................ |
68 | //........................................................................................................................................ |
69 | // Functions: u8 SDC_init(void); |
69 | // Functions: u8 SDC_init(void); |
70 | // u8 SDC_PutCommand (u8 *CMD); |
70 | // u8 SDC_PutCommand (u8 *CMD); |
71 | // u8 SDC_PutSector(u32 addr,u8 *Buffer); |
71 | // u8 SDC_PutSector(u32 addr,u8 *Buffer); |
72 | // u8 SDC_GetSector(u32 addr,u8 *Buffer); |
72 | // u8 SDC_GetSector(u32 addr,u8 *Buffer); |
73 | // void SDC_GetBlock(u8 *CMD,u8 *Buffer,u16 Bytes); |
73 | // void SDC_GetBlock(u8 *CMD,u8 *Buffer,u16 Bytes); |
74 | // |
74 | // |
75 | ////........................................................................................................................................ |
75 | ////........................................................................................................................................ |
76 | // ext. functions: extern void SSC_Init(void); |
76 | // ext. functions: extern void SSC_Init(void); |
77 | // extern u8 SSC_GetChar (void); |
77 | // extern u8 SSC_GetChar (void); |
78 | // extern void SSC_PutChar (u8); |
78 | // extern void SSC_PutChar (u8); |
79 | // extern void SSC_Enable(void); |
79 | // extern void SSC_Enable(void); |
80 | // extern void SSC_Disable(void); |
80 | // extern void SSC_Disable(void); |
81 | //........................................................................................................................................ |
81 | //........................................................................................................................................ |
82 | // |
82 | // |
83 | // URL: www.Mikro-Control.de |
83 | // URL: www.Mikro-Control.de |
84 | // mailto: stephan.busker@mikro-control.de |
84 | // mailto: stephan.busker@mikro-control.de |
85 | //________________________________________________________________________________________________________________________________________ |
85 | //________________________________________________________________________________________________________________________________________ |
86 | 86 | ||
87 | 87 | ||
88 | 88 | ||
89 | 89 | ||
90 | //________________________________________________________________________________________________________________________________________ |
90 | //________________________________________________________________________________________________________________________________________ |
91 | // Funtion: SDC_Init(void); |
91 | // Funtion: SDC_Init(void); |
92 | // |
92 | // |
93 | // Description: This function initialises the SDCard to spi-mode. |
93 | // Description: This function initialises the SDCard to spi-mode. |
94 | // |
94 | // |
95 | // |
95 | // |
96 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
96 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
97 | //________________________________________________________________________________________________________________________________________ |
97 | //________________________________________________________________________________________________________________________________________ |
98 | 98 | ||
99 | u8 SDC_Init(void) |
99 | u8 SDC_Init(void) |
100 | { |
100 | { |
101 | u16 Timeout = 0; |
101 | u16 Timeout = 0; |
102 | u8 CMD[] = {0x40,0x00,0x00,0x00,0x00,0x95}; |
102 | u8 CMD[] = {0x40,0x00,0x00,0x00,0x00,0x95}; |
103 | 103 | ||
104 | u8 b; |
104 | u8 b; |
105 | 105 | ||
106 | SSC_Init(); // Initialise SSC to transmit data to the sdcard. |
106 | SSC_Init(); // Initialise SSC to transmit data to the sdcard. |
107 | SerialPutString("Init SD..."); |
107 | SerialPutString("Init SD..."); |
108 | // Delay_ms(10); |
108 | // Delay_ms(10); |
109 | 109 | ||
110 | for (b = 0;b<0x0f;b++) // sending 74Clocks brings the sdcard into spimode. |
110 | for (b = 0;b<0x0f;b++) // sending 74Clocks brings the sdcard into spimode. |
111 | { |
111 | { |
112 | SSC_PutChar(0xff); |
112 | SSC_PutChar(0xff); |
113 | } |
113 | } |
114 | 114 | ||
115 | SerialPutString("reset..."); |
115 | SerialPutString("reset..."); |
116 | while(SDC_PutCommand (CMD) !=1) // Sending CMD0 (Reset) to the sdcard. |
116 | while(SDC_PutCommand (CMD) !=1) // Sending CMD0 (Reset) to the sdcard. |
117 | { |
117 | { |
118 | if (Timeout++ > 200) |
118 | if (Timeout++ > 200) |
119 | { |
119 | { |
120 | 120 | ||
121 | return(1); |
121 | return(1); |
122 | } |
122 | } |
123 | } |
123 | } |
124 | SerialPutString("ok."); |
124 | SerialPutString("ok."); |
125 | Timeout = 0; |
125 | Timeout = 0; |
126 | CMD[0] = 0x41; |
126 | CMD[0] = 0x41; |
127 | CMD[5] = 0xFF; |
127 | CMD[5] = 0xFF; |
128 | while( SDC_PutCommand (CMD) !=0) // Sending CMD1 to the sdcard. |
128 | while( SDC_PutCommand (CMD) !=0) // Sending CMD1 to the sdcard. |
129 | { |
129 | { |
130 | if (Timeout++ > 100) |
130 | if (Timeout++ > 100) |
131 | { |
131 | { |
132 | return(2); |
132 | return(2); |
133 | } |
133 | } |
134 | } |
134 | } |
135 | 135 | ||
136 | SSC_Disable(); // disable sdcard. |
136 | SSC_Disable(); // disable sdcard. |
137 | return(0); |
137 | return(0); |
138 | } |
138 | } |
139 | 139 | ||
140 | 140 | ||
141 | 141 | ||
142 | 142 | ||
143 | //________________________________________________________________________________________________________________________________________ |
143 | //________________________________________________________________________________________________________________________________________ |
144 | // Funtion: SDC_PutCommand(* CMD); |
144 | // Funtion: SDC_PutCommand(* CMD); |
145 | // |
145 | // |
146 | // Description: This function initialises the SDCard to spi-mode. |
146 | // Description: This function initialises the SDCard to spi-mode. |
147 | // |
147 | // |
148 | // |
148 | // |
149 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
149 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
150 | //________________________________________________________________________________________________________________________________________ |
150 | //________________________________________________________________________________________________________________________________________ |
151 | 151 | ||
152 | u8 SDC_PutCommand (u8 *CMD) |
152 | u8 SDC_PutCommand (u8 *CMD) |
153 | { |
153 | { |
154 | u8 tmp = 0xff; |
154 | u8 tmp = 0xff; |
155 | u16 Timeout = 0; |
155 | u16 Timeout = 0; |
156 | u16 a; |
156 | u16 a; |
157 | SSC_ClearRxFifo(); |
157 | SSC_ClearRxFifo(); |
158 | SSC_Disable(); // disable chipselect |
158 | SSC_Disable(); // disable chipselect |
159 | SSC_PutChar(0xFF); // Send 8 Clocks to the sdcard while card is not selected. |
159 | SSC_PutChar(0xFF); // Send 8 Clocks to the sdcard while card is not selected. |
160 | SSC_Enable(); // enable chipselect. |
160 | SSC_Enable(); // enable chipselect. |
161 | 161 | ||
162 | // if (*CMD == 0x41) Delay_ms(10); // if command is CMD0 generate a short delay. |
162 | // if (*CMD == 0x41) Delay_ms(10); // if command is CMD0 generate a short delay. |
163 | 163 | ||
164 | for (a = 0;a<0x06;a++) // send the command sequence to the sdcard (6 bytes) |
164 | for (a = 0;a<0x06;a++) // send the command sequence to the sdcard (6 bytes) |
165 | { |
165 | { |
166 | 166 | ||
167 | SSC_PutChar(*CMD++); |
167 | SSC_PutChar(*CMD++); |
168 | } |
168 | } |
169 | 169 | ||
170 | SSC_ClearRxFifo(); |
170 | SSC_ClearRxFifo(); |
171 | while (tmp == 0xff) // Wait for response from sdcard. |
171 | while (tmp == 0xff) // Wait for response from sdcard. |
172 | { |
172 | { |
173 | tmp = SSC_GetChar(); |
173 | tmp = SSC_GetChar(); |
174 | if (Timeout++ > 200) |
174 | if (Timeout++ > 200) |
175 | { |
175 | { |
176 | break; // or timeout. |
176 | break; // or timeout. |
177 | } |
177 | } |
178 | } |
178 | } |
179 | 179 | ||
180 | return(tmp); |
180 | return(tmp); |
181 | } |
181 | } |
182 | 182 | ||
183 | 183 | ||
184 | 184 | ||
185 | 185 | ||
186 | //________________________________________________________________________________________________________________________________________ |
186 | //________________________________________________________________________________________________________________________________________ |
187 | // Funtion: SDC_PutSector(void); |
187 | // Funtion: SDC_PutSector(void); |
188 | // |
188 | // |
189 | // Description: This function writes one sector of data to the SSC |
189 | // Description: This function writes one sector of data to the SSC |
190 | // |
190 | // |
191 | // |
191 | // |
192 | // Returnvalue: none |
192 | // Returnvalue: none |
193 | //________________________________________________________________________________________________________________________________________ |
193 | //________________________________________________________________________________________________________________________________________ |
194 | 194 | ||
195 | u8 SDC_PutSector(u32 addr,u8 *Buffer) |
195 | u8 SDC_PutSector(u32 addr,u8 *Buffer) |
196 | { |
196 | { |
197 | u8 tmp; |
197 | u8 tmp; |
198 | u8 CMD[] = {0x58,0x00,0x00,0x00,0x00,0xFF}; |
198 | u8 CMD[] = {0x58,0x00,0x00,0x00,0x00,0xFF}; |
199 | u16 a; |
199 | u16 a; |
200 | addr = addr << 9; // convert sectoradress to byteadress |
200 | addr = addr << 9; // convert sectoradress to byteadress |
201 | 201 | ||
202 | CMD[1] = ((addr & 0xFF000000) >>24 ); |
202 | CMD[1] = ((addr & 0xFF000000) >>24 ); |
203 | CMD[2] = ((addr & 0x00FF0000) >>16 ); |
203 | CMD[2] = ((addr & 0x00FF0000) >>16 ); |
204 | CMD[3] = ((addr & 0x0000FF00) >>8 ); |
204 | CMD[3] = ((addr & 0x0000FF00) >>8 ); |
205 | 205 | ||
206 | tmp = SDC_PutCommand (CMD); // send command to sdcard. |
206 | tmp = SDC_PutCommand (CMD); // send command to sdcard. |
207 | if (tmp != 0) |
207 | if (tmp != 0) |
208 | { |
208 | { |
209 | return(tmp); |
209 | return(tmp); |
210 | } |
210 | } |
211 | SSC_ClearRxFifo(); |
211 | SSC_ClearRxFifo(); |
212 | for (a=0;a<100;a++) // wait until sdcard is ready |
212 | for (a=0;a<100;a++) // wait until sdcard is ready |
213 | { |
213 | { |
214 | SSC_GetChar(); |
214 | SSC_GetChar(); |
215 | } |
215 | } |
216 | 216 | ||
217 | SSC_PutChar(0xFE); // send start of header to the SSC |
217 | SSC_PutChar(0xFE); // send start of header to the SSC |
218 | 218 | ||
219 | for (a=0;a<512;a++) // transmitt one sector (normaly 512bytes) of data to the sdcard. |
219 | for (a=0;a<512;a++) // transmitt one sector (normaly 512bytes) of data to the sdcard. |
220 | { |
220 | { |
221 | SSC_PutChar(*Buffer++); |
221 | SSC_PutChar(*Buffer++); |
222 | } |
222 | } |
223 | 223 | ||
224 | SSC_PutChar(0xFF); // write two bytes of crc to the sdcard (not used in spi-mode) |
224 | SSC_PutChar(0xFF); // write two bytes of crc to the sdcard (not used in spi-mode) |
225 | SSC_PutChar(0xFF); |
225 | SSC_PutChar(0xFF); |
226 | SSC_ClearRxFifo(); |
226 | SSC_ClearRxFifo(); |
227 | while (SSC_GetChar() != 0xff){}; // wait untile the sdcard is ready. |
227 | while (SSC_GetChar() != 0xff){}; // wait untile the sdcard is ready. |
228 | 228 | ||
229 | SSC_Disable(); // disable sdcard. |
229 | SSC_Disable(); // disable sdcard. |
230 | 230 | ||
231 | return(0); |
231 | return(0); |
232 | } |
232 | } |
233 | 233 | ||
234 | 234 | ||
235 | 235 | ||
236 | //________________________________________________________________________________________________________________________________________ |
236 | //________________________________________________________________________________________________________________________________________ |
237 | // Funtion: SDC_GetSector(u32 addr,u8 *Buffer); |
237 | // Funtion: SDC_GetSector(u32 addr,u8 *Buffer); |
238 | // |
238 | // |
239 | // Description: This function reads one sector of data from the SSC |
239 | // Description: This function reads one sector of data from the SSC |
240 | // |
240 | // |
241 | // |
241 | // |
242 | // Returnvalue: none |
242 | // Returnvalue: none |
243 | //________________________________________________________________________________________________________________________________________ |
243 | //________________________________________________________________________________________________________________________________________ |
244 | 244 | ||
245 | u8 SDC_GetSector(u32 addr,u8 *Buffer) |
245 | u8 SDC_GetSector(u32 addr,u8 *Buffer) |
246 | { |
246 | { |
247 | u8 CMD[] = {0x51,0x00,0x00,0x00,0x00,0xFF}; |
247 | u8 CMD[] = {0x51,0x00,0x00,0x00,0x00,0xFF}; |
248 | 248 | ||
249 | addr = addr << 9; // convert sectoradress to byteadress. |
249 | addr = addr << 9; // convert sectoradress to byteadress. |
250 | 250 | ||
251 | CMD[1] = ((addr & 0xFF000000) >>24 ); |
251 | CMD[1] = ((addr & 0xFF000000) >>24 ); |
252 | CMD[2] = ((addr & 0x00FF0000) >>16 ); |
252 | CMD[2] = ((addr & 0x00FF0000) >>16 ); |
253 | CMD[3] = ((addr & 0x0000FF00) >>8 ); |
253 | CMD[3] = ((addr & 0x0000FF00) >>8 ); |
254 | 254 | ||
255 | // sprintf(text,"\n\rGetSector: (%lu)", (u32)addr ); SerialPutString(text); |
255 | // sprintf(text,"\n\rGetSector: (%lu)", (u32)addr ); SerialPutString(text); |
256 | 256 | ||
257 | SDC_GetBlock(CMD,Buffer,512); // read specified sector from sdcard. |
257 | SDC_GetBlock(CMD,Buffer,512); // read specified sector from sdcard. |
258 | 258 | ||
259 | return(0); |
259 | return(0); |
260 | } |
260 | } |
261 | 261 | ||
262 | 262 | ||
263 | 263 | ||
264 | //________________________________________________________________________________________________________________________________________ |
264 | //________________________________________________________________________________________________________________________________________ |
265 | // Funtion: SDC_GetBlock(void); |
265 | // Funtion: SDC_GetBlock(void); |
266 | // |
266 | // |
267 | // Description: This function reads one block of data of int bytes from the SSC. |
267 | // Description: This function reads one block of data of int bytes from the SSC. |
268 | // |
268 | // |
269 | // |
269 | // |
270 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
270 | // Returnvalue: the function returns 0 if the initialisation was successfull otherwise the function returns an errorcode. |
271 | //________________________________________________________________________________________________________________________________________ |
271 | //________________________________________________________________________________________________________________________________________ |
272 | 272 | ||
273 | void SDC_GetBlock(u8 *CMD,u8 *Buffer,u16 Bytes) |
273 | void SDC_GetBlock(u8 *CMD,u8 *Buffer,u16 Bytes) |
274 | { |
274 | { |
275 | if (SDC_PutCommand (CMD) != 0) // Send command to the sdcard. |
275 | if (SDC_PutCommand (CMD) != 0) // Send command to the sdcard. |
276 | { |
276 | { |
277 | return; |
277 | return; |
278 | } |
278 | } |
279 | SSC_ClearRxFifo(); |
279 | SSC_ClearRxFifo(); |
280 | // SerialPutString("\n\rWait."); |
280 | // SerialPutString("\n\rWait."); |
281 | while (SSC_GetChar() != 0xfe){}; // wait until the sdcard is ready to transmitt data. |
281 | while (SSC_GetChar() != 0xfe){}; // wait until the sdcard is ready to transmitt data. |
282 | // SerialPutString("Ok."); |
282 | // SerialPutString("Ok."); |
283 | u16 a; |
283 | u16 a; |
284 | for (a=0;a<Bytes;a++) // read the block from the SSC (normaly 512Bytes) |
284 | for (a=0;a<Bytes;a++) // read the block from the SSC (normaly 512Bytes) |
285 | { |
285 | { |
286 | *Buffer++ = SSC_GetChar(); |
286 | *Buffer++ = SSC_GetChar(); |
287 | } |
287 | } |
288 | 288 | ||
289 | SSC_GetChar(); // Read two bytes CRC- checksum (not used in spi-mode) |
289 | SSC_GetChar(); // Read two bytes CRC- checksum (not used in spi-mode) |
290 | SSC_GetChar(); |
290 | SSC_GetChar(); |
291 | SSC_Disable(); // disable sdcard. |
291 | SSC_Disable(); // disable sdcard. |
292 | } |
292 | } |
293 | 293 | ||
294 | 294 | ||
295 | 295 | ||
296 | 296 |