?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 32

Line No. Rev Author Line
1 32 kaklik /******************************************************************************
2  
3 Microchip Memory Disk Drive File System
4  
5 *****************************************************************************
6 FileName: CF- Bit transaction.c
7 Dependencies: GenericTypeDefs.h
8 FSIO.h
9 FSDefs.h
10 CF- Bit transaction.h
11 string.h
12 Processor: PIC18/PIC24/dsPIC30/dsPIC33
13 Compiler: C18/C30
14 Company: Microchip Technology, Inc.
15  
16 Software License Agreement
17  
18 The software supplied herewith by Microchip Technology Incorporated
19 (the “Company”) for its PICmicro® Microcontroller is intended and
20 supplied to you, the Company’s customer, for use solely and
21 exclusively on Microchip PICmicro Microcontroller products. The
22 software is owned by the Company and/or its supplier, and is
23 protected under applicable copyright laws. All rights are reserved.
24 Any use in violation of the foregoing restrictions may subject the
25 user to criminal sanctions under applicable laws, as well as to
26 civil liability for the breach of the terms and conditions of this
27 license.
28  
29 THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
30 WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
31 TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
32 PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
33 IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
34 CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
35  
36 Change History:
37 Rev Description
38 ------- --------------------------------
39 No change since 1.2.4
40  
41 *****************************************************************************/
42  
43  
44 #include "CF- Bit transaction.h" // compact flash interface
45 #include "GenericTypeDefs.h"
46 #include "FSIO.h"
47 #include "FSDefs.h"
48 #include "string.h"
49  
50  
51  
52 /* Prototypes */
53  
54  
55 static MEDIA_INFORMATION mediaInformation;
56  
57 /******************************************************************************
58 * Function: void MDD_CFBT_InitIO(void)
59 *
60 * PreCondition: None
61 *
62 * Input: void
63 *
64 * Output: void
65 *
66 * Side Effects: None
67 *
68 * Overview: None
69 *
70 * Note: None
71 *****************************************************************************/
72  
73 void MDD_CFBT_InitIO( void)
74 {
75 CF_CE = 1;
76 CF_CEDIR = OUTPUT;
77 CF_OE = 1;
78 CF_OEDIR = OUTPUT;
79 CF_WE = 1;
80 CF_WEDIR = OUTPUT;
81 CF_BT_RDY = 0;
82 CF_BT_READYDIR = INPUT;
83 CF_BT_CD1 = 0;
84 CF_BT_CD1DIR = INPUT;
85 CF_BT_RST = 0;
86 CF_BT_RESETDIR = OUTPUT;
87  
88 #ifdef __18CXX
89 ADDDIR = 0x00;
90 #endif
91  
92 #ifdef __C30__
93 ADRTRIS0 = 0; // AD0-3
94 ADRTRIS1 = 0;
95 ADRTRIS2 = 0;
96 ADRTRIS3 = 0;
97 #endif
98  
99 MDD_CFBT_DATABinput; // D0-7 input
100  
101 } // CFinit
102  
103  
104 /******************************************************************************
105 * Function: BYTE MDD_CFBT_MediaDetect(void)
106 *
107 * PreCondition: None
108 *
109 * Input: void
110 *
111 * Output: TRUE - Card present
112 * FALSE - Card absent
113 *
114 * Side Effects: None
115 *
116 * Overview: Determines if a card is inserted
117 *
118 * Note: None
119 *****************************************************************************/
120  
121 BYTE MDD_CFBT_MediaDetect( void)
122 {
123 return (CF_BT_CD1 == 0) ? TRUE : FALSE ; // test for CD1 pull down
124 } //CFDetect
125  
126  
127 /******************************************************************************
128 * Function: BYTE MDD_CFBT_WriteProtectState(void)
129 *
130 * PreCondition: None
131 *
132 * Input: void
133 *
134 * Output: 0
135 *
136 * Side Effects: None
137 *
138 * Overview: Added for compatibility- no write protect feature
139 *
140 * Note: None
141 *****************************************************************************/
142  
143 BYTE MDD_CFBT_WriteProtectState (void)
144 {
145 return 0;
146 }
147  
148  
149  
150 /******************************************************************************
151 * Function: BYTE MDD_CFBT_CFwait(void)
152 *
153 * PreCondition: None
154 *
155 * Input: void
156 *
157 * Output: None
158 *
159 * Side Effects: None
160 *
161 * Overview: Wait until the card is ready
162 *
163 * Note: None
164 *****************************************************************************/
165  
166 void MDD_CFBT_CFwait(void)
167 {
168 while(CF_BT_RDY == 0);
169 }
170  
171  
172 /******************************************************************************
173 * Function: BYTE MDD_CFBT_CFread(void)
174 *
175 * PreCondition: None
176 *
177 * Input: BYTE add - address to read from
178 *
179 * Output: BYTE - the byte read
180 *
181 * Side Effects: None
182 *
183 * Overview: Reads a byte from the CF card
184 *
185 * Note: None
186 *****************************************************************************/
187  
188 BYTE MDD_CFBT_CFread( BYTE add)
189 // add : register address
190 {
191 char d;
192  
193 MDD_CFBT_CFwait();
194 MDD_CFBT_DATABinput; // make the databus input
195  
196 #ifdef __C30__
197 ADDR0 = (BYTE)(add & 0x01) == 0x01; // publish the register address
198 ADDR1 = (BYTE)(add & 0x02) == 0x02;
199 ADDR2 = (BYTE)(add & 0x04) == 0x04;
200 ADDR3 = (BYTE)(add & 0x08) == 0x08;
201 #endif
202  
203 #ifdef __18CXX
204 ADDBL = (add | 0x30);
205 #endif
206  
207 CF_CE = 0; // select the CF card
208 Nop();
209 CF_OE = 0; // output enable
210 Nop();
211 d = MDD_CFBT_DATABIN; // get the data
212 Nop();
213 CF_OE = 1;
214 CF_CE = 1;
215 return d;
216 } // CFread
217  
218  
219 /******************************************************************************
220 * Function: BYTE MDD_CFBT_MediaInitialize(void)
221 *
222 * PreCondition: None
223 *
224 * Input: void
225 *
226 * Output: MEDIA_NO_ERROR - The media initialized successfully
227 *
228 * Side Effects: None
229 *
230 * Overview: Return a MEDIA_INFORMATION structure to FSIO.c
231 *
232 * Note: None
233 *****************************************************************************/
234  
235 MEDIA_INFORMATION * MDD_CFBT_MediaInitialize (void)
236 {
237 mediaInformation.errorCode = MEDIA_NO_ERROR;
238 mediaInformation.validityFlags.value = 0;
239 return &mediaInformation;
240 }
241  
242 /******************************************************************************
243 * Function: BYTE MDD_CFBT_CFwrite(void)
244 *
245 * PreCondition: None
246 *
247 * Input: BYTE add - the address to write to
248 * BYTE d - the byte to write
249 *
250 * Output: None
251 *
252 * Side Effects: None
253 *
254 * Overview: Writes a byte to the CF card
255 *
256 * Note: None
257 *****************************************************************************/
258  
259 void MDD_CFBT_CFwrite( BYTE add, BYTE d)
260 // add : CF register
261 // d : data
262 {
263 MDD_CFBT_CFwait();
264 CF_OE = 1; // make sure the output is disabled first
265 MDD_CFBT_DATABoutput; // make the bus output
266  
267 #ifdef __C30__
268 ADDR0 = (add & 0x01) == 0x01; // publish the register address
269 ADDR1 = (add & 0x02) == 0x02;
270 ADDR2 = (add & 0x04) == 0x04;
271 ADDR3 = (add & 0x08) == 0x08;
272 #endif
273  
274 #ifdef __18CXX
275 ADDBL = (add | 0x30);
276 #endif
277  
278 MDD_CFBT_DATABOUT = d; // publish the data
279 CF_CE = 0; // select the CF card
280 Nop();
281 Nop();
282 CF_WE = 0; // strobe write
283 Nop();
284 Nop();
285 CF_WE = 1;
286 CF_CE = 1;
287 } // CFwrite
288  
289  
290  
291  
292 /******************************************************************************
293 * Function: BYTE MDD_CFBT_SectorRead(DWORD sector_addr, BYTE *buffer)
294 *
295 * PreCondition: None
296 *
297 * Input: sector_addr - Sector address, each sector contains 512-byte
298 * buffer - Buffer where data will be stored, see
299 * 'ram_acs.h' for 'block' definition.
300 * 'Block' is dependent on whether internal or
301 * external memory is used
302 *
303 * Output: TRUE - Sector read
304 * FALSE - Sector could not be read
305 *
306 * Side Effects: None
307 *
308 * Overview: SectorRead reads 512 bytes of data from the card starting
309 * at the sector address specified by sector_addr and stores
310 * them in the location pointed to by 'buffer'.
311 *
312 * Note: None
313 *****************************************************************************/
314  
315  
316 BYTE MDD_CFBT_SectorRead(DWORD sector_addr, BYTE * buffer)
317 {
318 BYTE test;
319 WORD i = 0;
320  
321 MDD_CFBT_CFwrite( R_COUNT, 1);
322 MDD_CFBT_CFwrite( R_SECT, sector_addr);
323 MDD_CFBT_CFwrite( R_CYLO, sector_addr>>8);
324 MDD_CFBT_CFwrite( R_CYHI, sector_addr>>16);
325 MDD_CFBT_CFwrite( R_DRIVE, ((BYTE)(sector_addr>>24) & 0xf)|0xe0); // always select card #0
326 MDD_CFBT_CFwrite( R_CMD, C_SECTOR_READ);
327  
328 while ((test = MDD_CFBT_CFread( R_STATUS)) != S_READY)
329 {
330 // If error flag is set . . .
331 if (MDD_CFBT_CFread (R_STATUS) & 0x01)
332 {
333 return FALSE;
334 }
335 }
336  
337 #ifdef __C30__
338 ADDR0 = (R_DATA & 0x01) == 0x01; // publish the register address
339 ADDR1 = (R_DATA & 0x02) == 0x02;
340 ADDR2 = (R_DATA & 0x04) == 0x04;
341 ADDR3 = (R_DATA & 0x08) == 0x08;
342 #endif
343  
344 #ifdef __18CXX
345 ADDBL = (R_DATA | 0x30);
346 #endif
347  
348 MDD_CFBT_DATABinput; // make the databus input
349 CF_CE = 0; // CF selected
350  
351 if (buffer != NULL)
352 {
353 while (i < 512)
354 {
355 CF_OE = 0;
356 Nop();
357 buffer[i++] = MDD_CFBT_DATABIN;
358 CF_OE = 1;
359 }
360 }
361 else
362 {
363  
364 }
365  
366 CF_CE = 1; // CF deselected when done
367  
368 return TRUE;
369 } // read_sector
370  
371  
372 /******************************************************************************
373 * Function: BYTE MDD_CFBT_SectorWrite(DWORD sector_addr, BYTE *buffer, BYTE allowWriteToZero)
374 *
375 * PreCondition: None
376 *
377 * Input: sector_addr - Sector address, each sector contains 512 bytes
378 * buffer - Buffer where data will be read from
379 * allowWriteToZero - allows write to the MBR sector
380 *
381 * Output: TRUE - Sector written
382 * FALSE - Sector could not be written
383 *
384 * Side Effects: None
385 *
386 * Overview: SectorWrite sends 512 bytes of data from the location
387 * pointed to by 'buffer' to the card starting
388 * at the sector address specified by sector_addr.
389 *
390 * Note: None
391 *****************************************************************************/
392  
393 BYTE MDD_CFBT_SectorWrite( DWORD sector_addr, BYTE * buffer, BYTE allowWriteToZero)
394 // lda sector lda
395 // buf 512 byte block
396 {
397 WORD i;
398  
399 if (sector_addr == 0 && allowWriteToZero == FALSE)
400 return FALSE;
401  
402 MDD_CFBT_CFwrite( R_COUNT, 1);
403 MDD_CFBT_CFwrite( R_SECT, sector_addr);
404 MDD_CFBT_CFwrite( R_CYLO, sector_addr>>8);
405 MDD_CFBT_CFwrite( R_CYHI, sector_addr>>16);
406 MDD_CFBT_CFwrite( R_DRIVE, ((BYTE)(sector_addr>>24) & 0xf)|0xe0); // always select card #0
407  
408 MDD_CFBT_CFwrite( R_CMD, C_SECTOR_WRITE);
409  
410 while (MDD_CFBT_CFread( R_STATUS) != S_READY)
411 {
412 if (MDD_CFBT_CFread( R_STATUS) == S_ERROR)
413 {
414 return FALSE;
415 }
416 }
417  
418 #ifdef __C30__
419 ADDR0 = (R_DATA & 0x01) == 0x01; // publish the register address
420 ADDR1 = (R_DATA & 0x02) == 0x02;
421 ADDR2 = (R_DATA & 0x04) == 0x04;
422 ADDR3 = (R_DATA & 0x08) == 0x08;
423 #endif
424  
425 #ifdef __18CXX
426 ADDBL = (R_DATA| 0x30);
427 #endif
428  
429 MDD_CFBT_DATABoutput; // make the databus output
430 CF_CE = 0; // CF selected
431 for ( i=0; i<512; i++)
432 {
433 MDD_CFBT_DATABOUT = RAMread( buffer, 0); // read data
434 CF_WE = 0; // WE enable
435 CF_WE = 1; // WE disable
436 buffer++;
437 }
438 CF_CE = 1; // CF deselected when done
439  
440 return TRUE;
441 } // write_sector
442  
443  
444 /******************************************************************************
445 * Function: void MDD_CFBT_ShutdownMedia(void)
446 *
447 * PreCondition: None
448 *
449 * Input: None
450 *
451 * Output: None
452 *
453 * Side Effects: None
454 *
455 * Overview: Unmounts the card
456 *
457 * Note: None
458 *****************************************************************************/
459  
460  
461 void MDD_CFBT_ShutdownMedia (DISK * dsk)
462 {
463 dsk->mount = FALSE;
464 return;
465 }
466  
467  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3