1 | void FlashRead(XQspiPs *QspiPtr, u32 Address, u32 ByteCount, u8 Command,
|
2 | u8 *WriteBfrPtr, u8 *ReadBfrPtr)
|
3 | {
|
4 | u32 RealAddr;
|
5 | u32 RealByteCnt;
|
6 | u32 BankSel;
|
7 | u32 BufferIndex;
|
8 | u32 TotalByteCnt;
|
9 | u8 ShiftSize;
|
10 |
|
11 | /*
|
12 | * Retain the actual byte count
|
13 | */
|
14 | TotalByteCnt = ByteCount;
|
15 |
|
16 | while(((signed long)(ByteCount)) > 0) {
|
17 |
|
18 | /*
|
19 | * Translate address based on type of connection
|
20 | * If stacked assert the slave select based on address
|
21 | */
|
22 | RealAddr = GetRealAddr(QspiPtr, Address);
|
23 |
|
24 | /*
|
25 | * Select bank
|
26 | */
|
27 | if(Flash_Config_Table[FCTIndex].FlashDeviceSize > SIXTEENMB) {
|
28 | BankSel = RealAddr/SIXTEENMB;
|
29 | SendBankSelect(QspiPtr, WriteBfrPtr, BankSel);
|
30 | }
|
31 |
|
32 | /*
|
33 | * If data to be read spans beyond the current bank, then
|
34 | * calculate RealByteCnt in current bank. Else
|
35 | * RealByteCnt is the same as ByteCount
|
36 | */
|
37 | if((Address & BANKMASK) != ((Address+ByteCount) & BANKMASK)) {
|
38 | RealByteCnt = (Address & BANKMASK) + SIXTEENMB - Address;
|
39 | }else {
|
40 | RealByteCnt = ByteCount;
|
41 | }
|
42 |
|
43 |
|
44 | /*
|
45 | * Setup the write command with the specified address and data for the
|
46 | * Flash
|
47 | */
|
48 | WriteBfrPtr[COMMAND_OFFSET] = Command;
|
49 | WriteBfrPtr[ADDRESS_1_OFFSET] = (u8)((RealAddr & 0xFF0000) >> 16);
|
50 | WriteBfrPtr[ADDRESS_2_OFFSET] = (u8)((RealAddr & 0xFF00) >> 8);
|
51 | WriteBfrPtr[ADDRESS_3_OFFSET] = (u8)(RealAddr & 0xFF);
|
52 |
|
53 | if ((Command == FAST_READ_CMD) || (Command == DUAL_READ_CMD) ||
|
54 | (Command == QUAD_READ_CMD)) {
|
55 | RealByteCnt += DUMMY_SIZE;
|
56 | }
|
57 | /*
|
58 | * Send the read command to the Flash to read the specified number
|
59 | * of bytes from the Flash, send the read command and address and
|
60 | * receive the specified number of bytes of data in the data buffer
|
61 | */
|
62 | XQspiPs_PolledTransfer(QspiPtr, WriteBfrPtr,
|
63 | &(ReadBfrPtr[TotalByteCnt - ByteCount]),
|
64 | RealByteCnt + OVERHEAD_SIZE);
|
65 |
|
66 | /*
|
67 | * To discard the first 5 dummy bytes, shift the data in read buffer
|
68 | */
|
69 | if((Command == FAST_READ_CMD) || (Command == DUAL_READ_CMD) ||
|
70 | (Command == QUAD_READ_CMD)){
|
71 | ShiftSize = OVERHEAD_SIZE + DUMMY_SIZE;
|
72 | }else{
|
73 | ShiftSize = OVERHEAD_SIZE;
|
74 | }
|
75 |
|
76 | for(BufferIndex = (TotalByteCnt - ByteCount);
|
77 | BufferIndex < (TotalByteCnt - ByteCount) + RealByteCnt;
|
78 | BufferIndex++) {
|
79 | ReadBfrPtr[BufferIndex] = ReadBfrPtr[BufferIndex + ShiftSize];
|
80 | }
|
81 |
|
82 | /*
|
83 | * Increase address to next bank
|
84 | */
|
85 | Address = (Address & BANKMASK) + SIXTEENMB;
|
86 | /*
|
87 | * Decrease byte count by bytes already read.
|
88 | */
|
89 | if ((Command == FAST_READ_CMD) || (Command == DUAL_READ_CMD) ||
|
90 | (Command == QUAD_READ_CMD)) {
|
91 | ByteCount = ByteCount - (RealByteCnt - DUMMY_SIZE);
|
92 | }else {
|
93 | ByteCount = ByteCount - RealByteCnt;
|
94 | }
|
95 |
|
96 | }
|
97 |
|
98 | }
|