Fix MIT license language to make its intent clearer.
[pub/lufa.git] / Demos / Device / LowLevel / MassStorage / Lib / DataflashManager.c
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 *
33 * Functions to manage the physical dataflash media, including reading and writing of
34 * blocks of data. These functions are called by the SCSI layer when data must be stored
35 * or retrieved to/from the physical storage media. If a different media is used (such
36 * as a SD card or EEPROM), functions similar to these will need to be generated.
37 */
38
39 #define INCLUDE_FROM_DATAFLASHMANAGER_C
40 #include "DataflashManager.h"
41
42 /** Writes blocks (OS blocks, not Dataflash pages) to the storage medium, the board dataflash IC(s), from
43 * the pre-selected data OUT endpoint. This routine reads in OS sized blocks from the endpoint and writes
44 * them to the dataflash in Dataflash page sized blocks.
45 *
46 * \param[in] BlockAddress Data block starting address for the write sequence
47 * \param[in] TotalBlocks Number of blocks of data to write
48 */
49 void DataflashManager_WriteBlocks(const uint32_t BlockAddress, uint16_t TotalBlocks)
50 {
51 uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE);
52 uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE);
53 uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4);
54 bool UsingSecondBuffer = false;
55
56 /* Select the correct starting Dataflash IC for the block requested */
57 Dataflash_SelectChipFromPage(CurrDFPage);
58
59 #if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE)
60 /* Copy selected dataflash's current page contents to the dataflash buffer */
61 Dataflash_SendByte(DF_CMD_MAINMEMTOBUFF1);
62 Dataflash_SendAddressBytes(CurrDFPage, 0);
63 Dataflash_WaitWhileBusy();
64 #endif
65
66 /* Send the dataflash buffer write command */
67 Dataflash_SendByte(DF_CMD_BUFF1WRITE);
68 Dataflash_SendAddressBytes(0, CurrDFPageByte);
69
70 /* Wait until endpoint is ready before continuing */
71 if (Endpoint_WaitUntilReady())
72 return;
73
74 while (TotalBlocks)
75 {
76 uint8_t BytesInBlockDiv16 = 0;
77
78 /* Write an endpoint packet sized data block to the dataflash */
79 while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4))
80 {
81 /* Check if the endpoint is currently empty */
82 if (!(Endpoint_IsReadWriteAllowed()))
83 {
84 /* Clear the current endpoint bank */
85 Endpoint_ClearOUT();
86
87 /* Wait until the host has sent another packet */
88 if (Endpoint_WaitUntilReady())
89 return;
90 }
91
92 /* Check if end of dataflash page reached */
93 if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4))
94 {
95 /* Write the dataflash buffer contents back to the dataflash page */
96 Dataflash_WaitWhileBusy();
97 Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE);
98 Dataflash_SendAddressBytes(CurrDFPage, 0);
99
100 /* Reset the dataflash buffer counter, increment the page counter */
101 CurrDFPageByteDiv16 = 0;
102 CurrDFPage++;
103
104 /* Once all the dataflash ICs have had their first buffers filled, switch buffers to maintain throughput */
105 if (Dataflash_GetSelectedChip() == DATAFLASH_CHIP_MASK(DATAFLASH_TOTALCHIPS))
106 UsingSecondBuffer = !(UsingSecondBuffer);
107
108 /* Select the next dataflash chip based on the new dataflash page index */
109 Dataflash_SelectChipFromPage(CurrDFPage);
110
111 #if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE)
112 /* If less than one dataflash page remaining, copy over the existing page to preserve trailing data */
113 if ((TotalBlocks * (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) < (DATAFLASH_PAGE_SIZE >> 4))
114 {
115 /* Copy selected dataflash's current page contents to the dataflash buffer */
116 Dataflash_WaitWhileBusy();
117 Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_MAINMEMTOBUFF2 : DF_CMD_MAINMEMTOBUFF1);
118 Dataflash_SendAddressBytes(CurrDFPage, 0);
119 Dataflash_WaitWhileBusy();
120 }
121 #endif
122
123 /* Send the dataflash buffer write command */
124 Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2WRITE : DF_CMD_BUFF1WRITE);
125 Dataflash_SendAddressBytes(0, 0);
126 }
127
128 /* Write one 16-byte chunk of data to the dataflash */
129 Dataflash_SendByte(Endpoint_Read_Byte());
130 Dataflash_SendByte(Endpoint_Read_Byte());
131 Dataflash_SendByte(Endpoint_Read_Byte());
132 Dataflash_SendByte(Endpoint_Read_Byte());
133 Dataflash_SendByte(Endpoint_Read_Byte());
134 Dataflash_SendByte(Endpoint_Read_Byte());
135 Dataflash_SendByte(Endpoint_Read_Byte());
136 Dataflash_SendByte(Endpoint_Read_Byte());
137 Dataflash_SendByte(Endpoint_Read_Byte());
138 Dataflash_SendByte(Endpoint_Read_Byte());
139 Dataflash_SendByte(Endpoint_Read_Byte());
140 Dataflash_SendByte(Endpoint_Read_Byte());
141 Dataflash_SendByte(Endpoint_Read_Byte());
142 Dataflash_SendByte(Endpoint_Read_Byte());
143 Dataflash_SendByte(Endpoint_Read_Byte());
144 Dataflash_SendByte(Endpoint_Read_Byte());
145
146 /* Increment the dataflash page 16 byte block counter */
147 CurrDFPageByteDiv16++;
148
149 /* Increment the block 16 byte block counter */
150 BytesInBlockDiv16++;
151
152 /* Check if the current command is being aborted by the host */
153 if (IsMassStoreReset)
154 return;
155 }
156
157 /* Decrement the blocks remaining counter and reset the sub block counter */
158 TotalBlocks--;
159 }
160
161 /* Write the dataflash buffer contents back to the dataflash page */
162 Dataflash_WaitWhileBusy();
163 Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE);
164 Dataflash_SendAddressBytes(CurrDFPage, 0x00);
165 Dataflash_WaitWhileBusy();
166
167 /* If the endpoint is empty, clear it ready for the next packet from the host */
168 if (!(Endpoint_IsReadWriteAllowed()))
169 Endpoint_ClearOUT();
170
171 /* Deselect all dataflash chips */
172 Dataflash_DeselectChip();
173 }
174
175 /** Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board dataflash IC(s), into
176 * the pre-selected data IN endpoint. This routine reads in Dataflash page sized blocks from the Dataflash
177 * and writes them in OS sized blocks to the endpoint.
178 *
179 * \param[in] BlockAddress Data block starting address for the read sequence
180 * \param[in] TotalBlocks Number of blocks of data to read
181 */
182 void DataflashManager_ReadBlocks(const uint32_t BlockAddress, uint16_t TotalBlocks)
183 {
184 uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE);
185 uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE);
186 uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4);
187
188 /* Select the correct starting Dataflash IC for the block requested */
189 Dataflash_SelectChipFromPage(CurrDFPage);
190
191 /* Send the dataflash main memory page read command */
192 Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD);
193 Dataflash_SendAddressBytes(CurrDFPage, CurrDFPageByte);
194 Dataflash_SendByte(0x00);
195 Dataflash_SendByte(0x00);
196 Dataflash_SendByte(0x00);
197 Dataflash_SendByte(0x00);
198
199 /* Wait until endpoint is ready before continuing */
200 if (Endpoint_WaitUntilReady())
201 return;
202
203 while (TotalBlocks)
204 {
205 uint8_t BytesInBlockDiv16 = 0;
206
207 /* Write an endpoint packet sized data block to the dataflash */
208 while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4))
209 {
210 /* Check if the endpoint is currently full */
211 if (!(Endpoint_IsReadWriteAllowed()))
212 {
213 /* Clear the endpoint bank to send its contents to the host */
214 Endpoint_ClearIN();
215
216 /* Wait until the endpoint is ready for more data */
217 if (Endpoint_WaitUntilReady())
218 return;
219 }
220
221 /* Check if end of dataflash page reached */
222 if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4))
223 {
224 /* Reset the dataflash buffer counter, increment the page counter */
225 CurrDFPageByteDiv16 = 0;
226 CurrDFPage++;
227
228 /* Select the next dataflash chip based on the new dataflash page index */
229 Dataflash_SelectChipFromPage(CurrDFPage);
230
231 /* Send the dataflash main memory page read command */
232 Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD);
233 Dataflash_SendAddressBytes(CurrDFPage, 0);
234 Dataflash_SendByte(0x00);
235 Dataflash_SendByte(0x00);
236 Dataflash_SendByte(0x00);
237 Dataflash_SendByte(0x00);
238 }
239
240 /* Read one 16-byte chunk of data from the dataflash */
241 Endpoint_Write_Byte(Dataflash_ReceiveByte());
242 Endpoint_Write_Byte(Dataflash_ReceiveByte());
243 Endpoint_Write_Byte(Dataflash_ReceiveByte());
244 Endpoint_Write_Byte(Dataflash_ReceiveByte());
245 Endpoint_Write_Byte(Dataflash_ReceiveByte());
246 Endpoint_Write_Byte(Dataflash_ReceiveByte());
247 Endpoint_Write_Byte(Dataflash_ReceiveByte());
248 Endpoint_Write_Byte(Dataflash_ReceiveByte());
249 Endpoint_Write_Byte(Dataflash_ReceiveByte());
250 Endpoint_Write_Byte(Dataflash_ReceiveByte());
251 Endpoint_Write_Byte(Dataflash_ReceiveByte());
252 Endpoint_Write_Byte(Dataflash_ReceiveByte());
253 Endpoint_Write_Byte(Dataflash_ReceiveByte());
254 Endpoint_Write_Byte(Dataflash_ReceiveByte());
255 Endpoint_Write_Byte(Dataflash_ReceiveByte());
256 Endpoint_Write_Byte(Dataflash_ReceiveByte());
257
258 /* Increment the dataflash page 16 byte block counter */
259 CurrDFPageByteDiv16++;
260
261 /* Increment the block 16 byte block counter */
262 BytesInBlockDiv16++;
263
264 /* Check if the current command is being aborted by the host */
265 if (IsMassStoreReset)
266 return;
267 }
268
269 /* Decrement the blocks remaining counter */
270 TotalBlocks--;
271 }
272
273 /* If the endpoint is full, send its contents to the host */
274 if (!(Endpoint_IsReadWriteAllowed()))
275 Endpoint_ClearIN();
276
277 /* Deselect all dataflash chips */
278 Dataflash_DeselectChip();
279 }
280
281 /** Writes blocks (OS blocks, not Dataflash pages) to the storage medium, the board dataflash IC(s), from
282 * the a given RAM buffer. This routine reads in OS sized blocks from the buffer and writes them to the
283 * dataflash in Dataflash page sized blocks. This can be linked to FAT libraries to write files to the
284 * dataflash.
285 *
286 * \param[in] BlockAddress Data block starting address for the write sequence
287 * \param[in] TotalBlocks Number of blocks of data to write
288 * \param[in] BufferPtr Pointer to the data source RAM buffer
289 */
290 void DataflashManager_WriteBlocks_RAM(const uint32_t BlockAddress, uint16_t TotalBlocks, uint8_t* BufferPtr)
291 {
292 uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE);
293 uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE);
294 uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4);
295 bool UsingSecondBuffer = false;
296
297 /* Select the correct starting Dataflash IC for the block requested */
298 Dataflash_SelectChipFromPage(CurrDFPage);
299
300 #if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE)
301 /* Copy selected dataflash's current page contents to the dataflash buffer */
302 Dataflash_SendByte(DF_CMD_MAINMEMTOBUFF1);
303 Dataflash_SendAddressBytes(CurrDFPage, 0);
304 Dataflash_WaitWhileBusy();
305 #endif
306
307 /* Send the dataflash buffer write command */
308 Dataflash_SendByte(DF_CMD_BUFF1WRITE);
309 Dataflash_SendAddressBytes(0, CurrDFPageByte);
310
311 while (TotalBlocks)
312 {
313 uint8_t BytesInBlockDiv16 = 0;
314
315 /* Write an endpoint packet sized data block to the dataflash */
316 while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4))
317 {
318 /* Check if end of dataflash page reached */
319 if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4))
320 {
321 /* Write the dataflash buffer contents back to the dataflash page */
322 Dataflash_WaitWhileBusy();
323 Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE);
324 Dataflash_SendAddressBytes(CurrDFPage, 0);
325
326 /* Reset the dataflash buffer counter, increment the page counter */
327 CurrDFPageByteDiv16 = 0;
328 CurrDFPage++;
329
330 /* Once all the dataflash ICs have had their first buffers filled, switch buffers to maintain throughput */
331 if (Dataflash_GetSelectedChip() == DATAFLASH_CHIP_MASK(DATAFLASH_TOTALCHIPS))
332 UsingSecondBuffer = !(UsingSecondBuffer);
333
334 /* Select the next dataflash chip based on the new dataflash page index */
335 Dataflash_SelectChipFromPage(CurrDFPage);
336
337 #if (DATAFLASH_PAGE_SIZE > VIRTUAL_MEMORY_BLOCK_SIZE)
338 /* If less than one dataflash page remaining, copy over the existing page to preserve trailing data */
339 if ((TotalBlocks * (VIRTUAL_MEMORY_BLOCK_SIZE >> 4)) < (DATAFLASH_PAGE_SIZE >> 4))
340 {
341 /* Copy selected dataflash's current page contents to the dataflash buffer */
342 Dataflash_WaitWhileBusy();
343 Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_MAINMEMTOBUFF2 : DF_CMD_MAINMEMTOBUFF1);
344 Dataflash_SendAddressBytes(CurrDFPage, 0);
345 Dataflash_WaitWhileBusy();
346 }
347 #endif
348
349 /* Send the dataflash buffer write command */
350 Dataflash_ToggleSelectedChipCS();
351 Dataflash_SendByte(DF_CMD_BUFF1WRITE);
352 Dataflash_SendAddressBytes(0, 0);
353 }
354
355 /* Write one 16-byte chunk of data to the dataflash */
356 for (uint8_t ByteNum = 0; ByteNum < 16; ByteNum++)
357 Dataflash_SendByte(*(BufferPtr++));
358
359 /* Increment the dataflash page 16 byte block counter */
360 CurrDFPageByteDiv16++;
361
362 /* Increment the block 16 byte block counter */
363 BytesInBlockDiv16++;
364 }
365
366 /* Decrement the blocks remaining counter and reset the sub block counter */
367 TotalBlocks--;
368 }
369
370 /* Write the dataflash buffer contents back to the dataflash page */
371 Dataflash_WaitWhileBusy();
372 Dataflash_SendByte(UsingSecondBuffer ? DF_CMD_BUFF2TOMAINMEMWITHERASE : DF_CMD_BUFF1TOMAINMEMWITHERASE);
373 Dataflash_SendAddressBytes(CurrDFPage, 0x00);
374 Dataflash_WaitWhileBusy();
375
376 /* Deselect all dataflash chips */
377 Dataflash_DeselectChip();
378 }
379
380 /** Reads blocks (OS blocks, not Dataflash pages) from the storage medium, the board dataflash IC(s), into
381 * the a preallocated RAM buffer. This routine reads in Dataflash page sized blocks from the Dataflash
382 * and writes them in OS sized blocks to the given buffer. This can be linked to FAT libraries to read
383 * the files stored on the dataflash.
384 *
385 * \param[in] BlockAddress Data block starting address for the read sequence
386 * \param[in] TotalBlocks Number of blocks of data to read
387 * \param[out] BufferPtr Pointer to the data destination RAM buffer
388 */
389 void DataflashManager_ReadBlocks_RAM(const uint32_t BlockAddress, uint16_t TotalBlocks, uint8_t* BufferPtr)
390 {
391 uint16_t CurrDFPage = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) / DATAFLASH_PAGE_SIZE);
392 uint16_t CurrDFPageByte = ((BlockAddress * VIRTUAL_MEMORY_BLOCK_SIZE) % DATAFLASH_PAGE_SIZE);
393 uint8_t CurrDFPageByteDiv16 = (CurrDFPageByte >> 4);
394
395 /* Select the correct starting Dataflash IC for the block requested */
396 Dataflash_SelectChipFromPage(CurrDFPage);
397
398 /* Send the dataflash main memory page read command */
399 Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD);
400 Dataflash_SendAddressBytes(CurrDFPage, CurrDFPageByte);
401 Dataflash_SendByte(0x00);
402 Dataflash_SendByte(0x00);
403 Dataflash_SendByte(0x00);
404 Dataflash_SendByte(0x00);
405
406 while (TotalBlocks)
407 {
408 uint8_t BytesInBlockDiv16 = 0;
409
410 /* Write an endpoint packet sized data block to the dataflash */
411 while (BytesInBlockDiv16 < (VIRTUAL_MEMORY_BLOCK_SIZE >> 4))
412 {
413 /* Check if end of dataflash page reached */
414 if (CurrDFPageByteDiv16 == (DATAFLASH_PAGE_SIZE >> 4))
415 {
416 /* Reset the dataflash buffer counter, increment the page counter */
417 CurrDFPageByteDiv16 = 0;
418 CurrDFPage++;
419
420 /* Select the next dataflash chip based on the new dataflash page index */
421 Dataflash_SelectChipFromPage(CurrDFPage);
422
423 /* Send the dataflash main memory page read command */
424 Dataflash_SendByte(DF_CMD_MAINMEMPAGEREAD);
425 Dataflash_SendAddressBytes(CurrDFPage, 0);
426 Dataflash_SendByte(0x00);
427 Dataflash_SendByte(0x00);
428 Dataflash_SendByte(0x00);
429 Dataflash_SendByte(0x00);
430 }
431
432 /* Read one 16-byte chunk of data from the dataflash */
433 for (uint8_t ByteNum = 0; ByteNum < 16; ByteNum++)
434 *(BufferPtr++) = Dataflash_ReceiveByte();
435
436 /* Increment the dataflash page 16 byte block counter */
437 CurrDFPageByteDiv16++;
438
439 /* Increment the block 16 byte block counter */
440 BytesInBlockDiv16++;
441 }
442
443 /* Decrement the blocks remaining counter */
444 TotalBlocks--;
445 }
446
447 /* Deselect all dataflash chips */
448 Dataflash_DeselectChip();
449 }
450
451 /** Disables the dataflash memory write protection bits on the board Dataflash ICs, if enabled. */
452 void DataflashManager_ResetDataflashProtections(void)
453 {
454 /* Select first dataflash chip, send the read status register command */
455 Dataflash_SelectChip(DATAFLASH_CHIP1);
456 Dataflash_SendByte(DF_CMD_GETSTATUS);
457
458 /* Check if sector protection is enabled */
459 if (Dataflash_ReceiveByte() & DF_STATUS_SECTORPROTECTION_ON)
460 {
461 Dataflash_ToggleSelectedChipCS();
462
463 /* Send the commands to disable sector protection */
464 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[0]);
465 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[1]);
466 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[2]);
467 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[3]);
468 }
469
470 /* Select second dataflash chip (if present on selected board), send read status register command */
471 #if (DATAFLASH_TOTALCHIPS == 2)
472 Dataflash_SelectChip(DATAFLASH_CHIP2);
473 Dataflash_SendByte(DF_CMD_GETSTATUS);
474
475 /* Check if sector protection is enabled */
476 if (Dataflash_ReceiveByte() & DF_STATUS_SECTORPROTECTION_ON)
477 {
478 Dataflash_ToggleSelectedChipCS();
479
480 /* Send the commands to disable sector protection */
481 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[0]);
482 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[1]);
483 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[2]);
484 Dataflash_SendByte(DF_CMD_SECTORPROTECTIONOFF[3]);
485 }
486 #endif
487
488 /* Deselect current dataflash chip */
489 Dataflash_DeselectChip();
490 }
491
492 /** Performs a simple test on the attached Dataflash IC(s) to ensure that they are working.
493 *
494 * \return Boolean true if all media chips are working, false otherwise
495 */
496 bool DataflashManager_CheckDataflashOperation(void)
497 {
498 uint8_t ReturnByte;
499
500 /* Test first Dataflash IC is present and responding to commands */
501 Dataflash_SelectChip(DATAFLASH_CHIP1);
502 Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);
503 ReturnByte = Dataflash_ReceiveByte();
504 Dataflash_DeselectChip();
505
506 /* If returned data is invalid, fail the command */
507 if (ReturnByte != DF_MANUFACTURER_ATMEL)
508 return false;
509
510 #if (DATAFLASH_TOTALCHIPS == 2)
511 /* Test second Dataflash IC is present and responding to commands */
512 Dataflash_SelectChip(DATAFLASH_CHIP2);
513 Dataflash_SendByte(DF_CMD_READMANUFACTURERDEVICEINFO);
514 ReturnByte = Dataflash_ReceiveByte();
515 Dataflash_DeselectChip();
516
517 /* If returned data is invalid, fail the command */
518 if (ReturnByte != DF_MANUFACTURER_ATMEL)
519 return false;
520 #endif
521
522 return true;
523 }