sd.c File Reference
#include "sd.h"
#include "disk_defines.h"
#include "lpc_sys.h"
Include dependency graph for sd.c:

Macros

#define CMD0   (0x40+0) /* GO_IDLE_STATE */
 
#define CMD1   (0x40+1) /* SEND_OP_COND (MMC) */
 
#define ACMD41   (0xC0+41) /* SEND_OP_COND (SDC) */
 
#define CMD8   (0x40+8) /* SEND_IF_COND */
 
#define CMD9   (0x40+9) /* SEND_CSD */
 
#define CMD10   (0x40+10) /* SEND_CID */
 
#define CMD12   (0x40+12) /* STOP_TRANSMISSION */
 
#define ACMD13   (0xC0+13) /* SD_STATUS (SDC) */
 
#define CMD16   (0x40+16) /* SET_BLOCKLEN */
 
#define CMD17   (0x40+17) /* READ_SINGLE_BLOCK */
 
#define CMD18   (0x40+18) /* READ_MULTIPLE_BLOCK */
 
#define CMD23   (0x40+23) /* SET_BLOCK_COUNT (MMC) */
 
#define ACMD23   (0xC0+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */
 
#define CMD24   (0x40+24) /* WRITE_BLOCK */
 
#define CMD25   (0x40+25) /* WRITE_MULTIPLE_BLOCK */
 
#define CMD55   (0x40+55) /* APP_CMD */
 
#define CMD58   (0x40+58) /* READ_OCR */
 
#define MMC_GET_TYPE   10
 
#define MMC_GET_CSD   11
 
#define MMC_GET_CID   12
 
#define MMC_GET_OCR   13
 
#define MMC_GET_SDSTAT   14
 
#define ATA_GET_REV   20
 
#define ATA_GET_MODEL   21
 
#define ATA_GET_SN   22
 
#define CT_MMC   0x01
 
#define CT_SD1   0x02
 
#define CT_SD2   0x04
 
#define CT_SDC   (CT_SD1|CT_SD2)
 
#define CT_BLOCK   0x08
 
#define DEBUG_SD_CARD   0
 
#define OPTIMIZE_SSP_SPI_WRITE   1
 
#define OPTIMIZE_SSP_SPI_READ   1
 

Functions

BYTE wait_ready (void)
 
void power_on (void)
 
void power_off (void)
 
int rcvr_datablock (BYTE *buff, UINT btr)
 
int xmit_datablock (const BYTE *buff, BYTE token)
 
BYTE send_cmd (BYTE cmd, DWORD arg)
 
DSTATUS sd_initialize ()
 Initializes the SD Card for SPI Mode, called automatically by disk_initialize() More...
 
DSTATUS sd_status ()
 Returns status of card (if its been initialized or not) More...
 
DRESULT sd_read (BYTE *buff, DWORD sector, BYTE count)
 Reads a sector from the SD Card. More...
 
DRESULT sd_write (const BYTE *buff, DWORD sector, BYTE count)
 Writes a sector to the SD-Card. More...
 
DRESULT sd_ioctl (BYTE ctrl, void *buff)
 Low level function used by FAT File System Layer. More...
 
void sd_update_card_status (void)
 Timeout function MUST BE CALLED AT 100Hz (every 10ms) More...
 

Macro Definition Documentation

#define ACMD13   (0xC0+13) /* SD_STATUS (SDC) */
#define ACMD23   (0xC0+23) /* SET_WR_BLK_ERASE_COUNT (SDC) */
#define ACMD41   (0xC0+41) /* SEND_OP_COND (SDC) */
#define ATA_GET_MODEL   21
#define ATA_GET_REV   20
#define ATA_GET_SN   22
#define CMD0   (0x40+0) /* GO_IDLE_STATE */
#define CMD1   (0x40+1) /* SEND_OP_COND (MMC) */
#define CMD10   (0x40+10) /* SEND_CID */
#define CMD12   (0x40+12) /* STOP_TRANSMISSION */
#define CMD16   (0x40+16) /* SET_BLOCKLEN */
#define CMD17   (0x40+17) /* READ_SINGLE_BLOCK */
#define CMD18   (0x40+18) /* READ_MULTIPLE_BLOCK */
#define CMD23   (0x40+23) /* SET_BLOCK_COUNT (MMC) */
#define CMD24   (0x40+24) /* WRITE_BLOCK */
#define CMD25   (0x40+25) /* WRITE_MULTIPLE_BLOCK */
#define CMD55   (0x40+55) /* APP_CMD */
#define CMD58   (0x40+58) /* READ_OCR */
#define CMD8   (0x40+8) /* SEND_IF_COND */
#define CMD9   (0x40+9) /* SEND_CSD */
#define CT_BLOCK   0x08
#define CT_MMC   0x01
#define CT_SD1   0x02
#define CT_SD2   0x04
#define CT_SDC   (CT_SD1|CT_SD2)
#define DEBUG_SD_CARD   0
#define MMC_GET_CID   12
#define MMC_GET_CSD   11
#define MMC_GET_OCR   13
#define MMC_GET_SDSTAT   14
#define MMC_GET_TYPE   10
#define OPTIMIZE_SSP_SPI_READ   1
#define OPTIMIZE_SSP_SPI_WRITE   1

Function Documentation

void power_off ( void  )
void power_on ( void  )
int rcvr_datablock ( BYTE buff,
UINT  btr 
)

If it's worth doing DMA, then do it:

DSTATUS sd_initialize ( )

Initializes the SD Card for SPI Mode, called automatically by disk_initialize()

DRESULT sd_ioctl ( BYTE  ctrl,
void *  buff 
)

Low level function used by FAT File System Layer.

DRESULT sd_read ( BYTE buff,
DWORD  sector,
BYTE  count 
)

Reads a sector from the SD Card.

DSTATUS sd_status ( )

Returns status of card (if its been initialized or not)

void sd_update_card_status ( void  )

Timeout function MUST BE CALLED AT 100Hz (every 10ms)

DRESULT sd_write ( const BYTE buff,
DWORD  sector,
BYTE  count 
)

Writes a sector to the SD-Card.

BYTE send_cmd ( BYTE  cmd,
DWORD  arg 
)
BYTE wait_ready ( void  )
int xmit_datablock ( const BYTE buff,
BYTE  token 
)