| Description | The function WriteBlock writes data blocks to a SD/MMC Memory Card. The parameter bl specifies the starting block to where data are written. The parameter buf is a pointer to the buffer that holds the data to be written. The parameter cnt specifies the number of blocks to be written. The function is part of the MCI Driver. The prototype is defined in the file File_Config.h. Developers must customize the function. To write data to a SD Memory Card, the following function sequence is called: - SetDma - sets the DMA to send data.
This can be used if DMA must be set prior to sending an SD command. - Command - sends a command WRITE_BLOCK or WRITE_MULT_BLOCK to SD Memory Card.
- WriteBlock - writes a block of data to 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
};
/* Write a cnt number of 512 byte blocks to Flash Card. */
static BOOL WriteBlock (U32 bl, U8 *buf, U32 cnt) {
U32 i,j;
for (j = 0; j < cnt; buf += 512, j++) {
MCI_DATA_TMR = DATA_WR_TOUT_VALUE; /* Set MCI Transfer registers */
MCI_DATA_LEN = 512;
DmaStart (DMA_WRITE, buf); /* Transfer data to Peripheral */
MCI_DATA_CTRL = 0x99;
for (i = DMA_TOUT; i; i--) {
if (GPDMA_RAW_INT_TCSTAT & 0x01) { /* Data transfer finished */
break;
}
}
if (i == 0) { /* DMA Data Transfer timeout */
return (__FALSE);
}
if (cnt == 1) {
break;
}
/* Wait to send data. */
while (MCI_STATUS != (MCI_DATA_END | MCI_DATA_BLK_END)) {
if (MCI_STATUS & (MCI_DATA_CRC_FAIL | MCI_DATA_TIMEOUT)) {
return (__FALSE); /* Timeout error */
}
}
for (i = WAIT_2SD_CLK(__CPUCLK); i; i--); /* Wait 2 SD clocks */
}
return (__TRUE);
}
|