C:/EDK_Projects/Spartan3E/TestApp_MicroSD/src/microsd.h File Reference

#include "xspi_l.h"
#include "microsd.h"

Go to the source code of this file.

Defines

#define Microsd_GetResponse(SDPtr)   Microsd_GetRespToken(SDPtr, NULL, 0)
#define Microsd_ReadSector(SDPtr, addrBySector, dataBuff)   Microsd_ReadBlock(SDPtr, (addrBySector)*SECTOR_SIZE, dataBuff, SECTOR_SIZE)

Functions

Xuint8 Microsd_crc7 (Xuint8 *MessBuff)
Xuint16 Microsd_crc16 (Xuint8 *MessBuff, unsigned int len)
Xuint8 Microsd_GetRespToken (Microsd *SDPtr, Xuint8 *RecvBuff, unsigned int NumBytes)
void Microsd_Initialize (Microsd *SDPtr, Xuint32 BaseAddr)
void Microsd_FlushRxFifo (Microsd *SDPtr)
Xuint8 Microsd_ReadBlock (Microsd *SDPtr, Xuint32 addr, Xuint8 data[], int len)
Xuint8 Microsd_SendCmd (Microsd *SDPtr, Xuint8 cmd_idx, Xuint32 arg)
Xuint8 Microsd_SetSpiMode (Microsd *SDPtr)
void Microsd_SpiTransfer (Microsd *SDPtr, Xuint8 SendBuff[], Xuint8 RecvBuff[], unsigned int NumBytes)


Detailed Description

The implementation of the SPI component's basic functionality to communicate with the microSD card. Only low level SPI functions are used in this file.

Definition in file microsd.h.


Define Documentation

#define Microsd_GetResponse ( SDPtr   )     Microsd_GetRespToken(SDPtr, NULL, 0)

Send microSD card idle signal (0xFF) to get a response. This function terminates if the card does not responde after 1000 tries. See the function Microsd_GetRespToken() for more detail.

Definition at line 70 of file microsd.h.

Referenced by Microsd_SendCmd(), Microsd_SetSpiMode(), and Microsd_WriteBlock().

#define Microsd_ReadSector ( SDPtr,
addrBySector,
dataBuff   )     Microsd_ReadBlock(SDPtr, (addrBySector)*SECTOR_SIZE, dataBuff, SECTOR_SIZE)

Read a sector from the SD card. The address provided should be by sector instead of by byte. The length of the data is always SECTOR_SIZE (as defined in fat16.h). See the function Microsd_ReadBlock() for more detail.

Definition at line 81 of file microsd.h.

Referenced by Fat16_InitializeLoadBoot(), Fat16_SDLoadRootDir(), and Fat16_SDWriteFile().


Function Documentation

Xuint16 Microsd_crc16 ( Xuint8 *  MessBuff,
unsigned int  len 
)

This function calculates the CRC for a given message. The remainder is the 16-bit CRC.

Parameters:
MessBuff is the message to be sent to the microSD card.
len is the length of the message in bytes.
Returns:
A 16-bit CRC for the given message.

Definition at line 76 of file microsd.c.

Referenced by Microsd_ReadBlock(), and Microsd_WriteBlock().

Xuint8 Microsd_crc7 ( Xuint8 *  MessBuff  ) 

This function calculates the CRC for a given 6-byte message. The remainder is 7-bits padded with an extra zero on the right.

Parameters:
MessBuff is the 6-byte message to be sent to the microSD card.
Returns:
A 7-bit CRC for the given message (padded zero on LSB).

Definition at line 33 of file microsd.c.

Referenced by Microsd_SendCmd().

void Microsd_FlushRxFifo ( Microsd *  InstPtr  ) 

This function empties out the response FIFO of the SPI module. This function should be used whenever another function needs to assume that the response FIFO is empty.

Parameters:
SDPtr is the pointer to the Microsd object.

Definition at line 167 of file microsd.c.

Referenced by Microsd_ReadBlock(), Microsd_SendCmd(), Microsd_SetSpiMode(), and Microsd_WriteBlock().

Xuint8 Microsd_GetRespToken ( Microsd *  SDPtr,
Xuint8 *  RecvBuff,
unsigned int  NumBytes 
)

Send microSD card idle signal (0xFF) to get a response. This function terminates, returning 0xFF, if the card does not responde after 1000 tries. The function stores the number of bytes given by NumBytes. The response token is stored into the buffer RecvBuff, NOT including the first byte. The first byte is instead returned.

Parameters:
SDPtr is the pointer to the Microsd object.
RecvBuff will hold the response token.
NumBytes is the length of the response in bytes.
Returns:
The first byte of the response token (usually of R1 format). If the function times-out, the value 0xFF is returned.

Definition at line 120 of file microsd.c.

References Microsd_SpiTransfer().

Referenced by Microsd_ReadBlock(), and Microsd_SetSpiMode().

void Microsd_Initialize ( Microsd *  SDPtr,
Xuint32  BaseAddr 
)

Initialized the Microsd object, set status to default (0x00).

Parameters:
SDPtr is the pointer to the Microsd object to be initialized.
BaseAddr is the SPI address that the card to connected to.

Definition at line 150 of file microsd.c.

Xuint8 Microsd_ReadBlock ( Microsd *  SDPtr,
Xuint32  addr,
Xuint8  data[],
int  len 
)

Read a block of data from the SD card, located by the address parameter. The data block is stored into the array data[].

Parameters:
SDPtr is the pointer the the Microsd object to communicate with.
addr is the address (by bytes) of the data block to be stored.
data is the array to store the data block.
len is the number of bytes for the data block.
Returns:
Something for debugging.

Definition at line 194 of file microsd.c.

References Microsd_crc16(), Microsd_FlushRxFifo(), Microsd_GetRespToken(), Microsd_SendCmd(), and Microsd_SpiTransfer().

Referenced by Fat16_SDReadFile().

Xuint8 Microsd_SendCmd ( Microsd *  SDPtr,
Xuint8  cmd_idx,
Xuint32  arg 
)

Send a command to the SD card through the SPI bus.

Parameters:
SDPtr is the pointer the the Microsd object to communicate with.
cmd_idx is the 6-bit command index.
arg is the 32-bit argument for the command.
Returns:
First byte of the response from the slave.

Definition at line 249 of file microsd.c.

References Microsd_crc7(), Microsd_FlushRxFifo(), Microsd_GetResponse, and Microsd_SpiTransfer().

Referenced by Microsd_ReadBlock(), and Microsd_WriteBlock().

Xuint8 Microsd_SetSpiMode ( Microsd *  SDPtr  ) 

Set the microSD card to SPI mode. This consists of a series of commands sent to the microSD card through the SPI bus. Verification of responses from the card will be examined to ensure that the card will be ready in SPI mode. Since many of the commands are constants, they are hard coded.

Parameters:
SDPtr is the pointer to the Microsd object to be initialized.
Returns:
Returns the status of the microSD card.

Definition at line 284 of file microsd.c.

References Microsd_FlushRxFifo(), Microsd_GetResponse, Microsd_GetRespToken(), and Microsd_SpiTransfer().

void Microsd_SpiTransfer ( Microsd *  SDPtr,
Xuint8  SendBuff[],
Xuint8  RecvBuff[],
unsigned int  NumBytes 
)

Transfer data through the SPI bus. For Every byte sent, a byte is recieved.

Parameters:
SDPtr is the pointer the the Microsd object to communicate with.
SendBuff is the buffer that holds the data to be sent to the slave.
RecvBuff is the buffer that will hold the data sent from the slave.
NumBytes is the number of bytes that will be snet and recieved.

Definition at line 372 of file microsd.c.

Referenced by Microsd_GetRespToken(), Microsd_ReadBlock(), Microsd_SendCmd(), Microsd_SetSpiMode(), and Microsd_WriteBlock().


Generated on Tue Sep 16 17:38:45 2008 for TestApp_MicroSD by  doxygen 1.5.6