| Description | The function ReadBlock reads data from a SD/MMC Memory Card to a buffer. The parameter bl specifies the starting block from where the data are read. The parameter buf is a pointer to the buffer that stores the data. The parameter cnt specifies the number of block to be read. The function is part of the MCI Driver. The prototype is defined in the file File_Config.h. Developers must customize the function. The following sequences are sent to read data from an SD Memory Card: - SetDma - sets the DMA to receive data.
This can be used if DMA must be set prior to sending an SD command. If this function does not exist (a NULL pointer in the MCI Driver control block), then it is not called. - Command - sends a command READ_BLOCK or READ_MULT_BLOCK to SD Memory Card.
- ReadBlock - reads a block of data from SD memory Card, or simply waits for the DMA transfer to finish.
|
| Example |
/* MCI Device Driver Control Block */
MCI_DRV mci0_drv = {
Init,
UnInit,
Delay,
BusMode,
BusWidth,
BusSpeed,
Command,
ReadBlock,
WriteBlock,
NULL,
CheckMedia
};
/* Read one or more 512 byte blocks from Flash Card. */
static BOOL ReadBlock (U32 bl, U8 *buf, U32 cnt) {
U32 i;
MCI_DATA_TMR = DATA_RD_TOUT_VALUE; /* Set MCI Transfer registers. */
MCI_DATA_LEN = cnt * 512;
DmaStart (DMA_READ, buf); /* Start DMA Peripheral to Memory transfer. */
MCI_DATA_CTRL = 0x9B;
for (i = DMA_TOUT; i; i--) {
if (GPDMA_RAW_INT_TCSTAT & 0x01) { /* Data transfer finished. */
return (__TRUE);
}
}
return (__FALSE); /* DMA Transfer timeout. */
}
|