APM:Libraries
Macros | Functions
sd.h File Reference
#include "../diskio.h"
#include <hal.h>
#include <timer.h>
#include <string.h>
#include "../integer.h"
Include dependency graph for sd.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define FAT_SECTOR_SIZE   512
 
#define CT_MMC   0x01 /* MMC ver 3 */
 
#define CT_SD1   0x02 /* SD ver 1 */
 
#define CT_SD2   0x04 /* SD ver 2 */
 
#define CT_SDC   (CT_SD1|CT_SD2) /* SD */
 
#define CT_BLOCK   0x08 /* Block addressing */
 
#define MMCSD_R1_OUTOFRANGE   ((uint32_t)1 << 31) /* Bad argument */
 
#define MMCSD_R1_ADDRESSERROR   ((uint32_t)1 << 30) /* Bad address */
 
#define MMCSD_R1_BLOCKLENERROR   ((uint32_t)1 << 29) /* Bad block length */
 
#define MMCSD_R1_ERASESEQERROR   ((uint32_t)1 << 28) /* Erase cmd error */
 
#define MMCSD_R1_ERASEPARAM   ((uint32_t)1 << 27) /* Bad write blocks */
 
#define MMCSD_R1_WPVIOLATION   ((uint32_t)1 << 26) /* Erase access failure */
 
#define MMCSD_R1_CARDISLOCKED   ((uint32_t)1 << 25) /* Card is locked */
 
#define MMCSD_R1_LOCKUNLOCKFAILED   ((uint32_t)1 << 24) /* Password error */
 
#define MMCSD_R1_COMCRCERROR   ((uint32_t)1 << 23) /* CRC error */
 
#define MMCSD_R1_ILLEGALCOMMAND   ((uint32_t)1 << 22) /* Bad command */
 
#define MMCSD_R1_CARDECCFAILED   ((uint32_t)1 << 21) /* Failed to correct data */
 
#define MMCSD_R1_CCERROR   ((uint32_t)1 << 20) /* Card controller error */
 
#define MMCSD_R1_ERROR   ((uint32_t)1 << 19) /* General error */
 
#define MMCSD_R1_UNDERRUN   ((uint32_t)1 << 18) /* Underrun (MMC only) */
 
#define MMCSD_R1_OVERRRUN   ((uint32_t)1 << 17) /* Overrun (MMC only) */
 
#define MMCSD_R1_CIDCSDOVERWRITE   ((uint32_t)1 << 16) /* CID/CSD error */
 
#define MMCSD_R1_WPERASESKIP   ((uint32_t)1 << 15) /* Not all erased */
 
#define MMCSD_R1_CARDECCDISABLED   ((uint32_t)1 << 14) /* Internal ECC not used */
 
#define MMCSD_R1_ERASERESET   ((uint32_t)1 << 13) /* Reset sequence cleared */
 
#define MMCSD_R1_STATE_SHIFT   (9) /* Current card state */
 
#define MMCSD_R1_STATE_MASK   ((uint32_t)15 << MMCSD_R1_STATE_SHIFT)
 
#define MMCSD_R1_STATE_IDLE   ((uint32_t)0 << MMCSD_R1_STATE_SHIFT) /* 0=Idle state */
 
#define MMCSD_R1_STATE_READY   ((uint32_t)1 << MMCSD_R1_STATE_SHIFT) /* 1=Ready state */
 
#define MMCSD_R1_STATE_IDENT   ((uint32_t)2 << MMCSD_R1_STATE_SHIFT) /* 2=Identification state */
 
#define MMCSD_R1_STATE_STBY   ((uint32_t)3 << MMCSD_R1_STATE_SHIFT) /* 3=Standby state */
 
#define MMCSD_R1_STATE_TRAN   ((uint32_t)4 << MMCSD_R1_STATE_SHIFT) /* 4=Transfer state */
 
#define MMCSD_R1_STATE_DATA   ((uint32_t)5 << MMCSD_R1_STATE_SHIFT) /* 5=Sending data state */
 
#define MMCSD_R1_STATE_RCV   ((uint32_t)6 << MMCSD_R1_STATE_SHIFT) /* 6=Receiving data state */
 
#define MMCSD_R1_STATE_PRG   ((uint32_t)7 << MMCSD_R1_STATE_SHIFT) /* 7=Programming state */
 
#define MMCSD_R1_STATE_DIS   ((uint32_t)8 << MMCSD_R1_STATE_SHIFT) /* 8=Disconnect state */
 
#define MMCSD_R1_READYFORDATA   ((uint32_t)1 << 8) /* Buffer empty */
 
#define MMCSD_R1_APPCMD   ((uint32_t)1 << 5) /* Next CMD is ACMD */
 
#define MMCSD_R1_AKESEQERROR   ((uint32_t)1 << 3) /* Authentication error */
 
#define MMCSD_R1_ERRORMASK   ((uint32_t)0xfdffe008) /* Error mask */
 

Functions

void sd_timerproc ()
 
DSTATUS sd_initialize ()
 
DSTATUS sd_status ()
 
DRESULT sd_read (uint8_t *buff, uint32_t sector, uint16_t count)
 
DRESULT sd_write (const uint8_t *buff, uint32_t sector, uint16_t count)
 
DRESULT sd_ioctl (uint8_t cmd, void *buff)
 
uint8_t sd_get_type ()
 
uint8_t sd_get_state ()
 
uint8_t sd_getSectorCount (uint32_t *ptr)
 

Macro Definition Documentation

◆ CT_BLOCK

#define CT_BLOCK   0x08 /* Block addressing */

Definition at line 45 of file sd.h.

◆ CT_MMC

#define CT_MMC   0x01 /* MMC ver 3 */

Definition at line 41 of file sd.h.

◆ CT_SD1

#define CT_SD1   0x02 /* SD ver 1 */

Definition at line 42 of file sd.h.

◆ CT_SD2

#define CT_SD2   0x04 /* SD ver 2 */

Definition at line 43 of file sd.h.

◆ CT_SDC

#define CT_SDC   (CT_SD1|CT_SD2) /* SD */

Definition at line 44 of file sd.h.

◆ FAT_SECTOR_SIZE

#define FAT_SECTOR_SIZE   512

Definition at line 14 of file sd.h.

◆ MMCSD_R1_ADDRESSERROR

#define MMCSD_R1_ADDRESSERROR   ((uint32_t)1 << 30) /* Bad address */

Definition at line 49 of file sd.h.

◆ MMCSD_R1_AKESEQERROR

#define MMCSD_R1_AKESEQERROR   ((uint32_t)1 << 3) /* Authentication error */

Definition at line 82 of file sd.h.

◆ MMCSD_R1_APPCMD

#define MMCSD_R1_APPCMD   ((uint32_t)1 << 5) /* Next CMD is ACMD */

Definition at line 81 of file sd.h.

◆ MMCSD_R1_BLOCKLENERROR

#define MMCSD_R1_BLOCKLENERROR   ((uint32_t)1 << 29) /* Bad block length */

Definition at line 50 of file sd.h.

◆ MMCSD_R1_CARDECCDISABLED

#define MMCSD_R1_CARDECCDISABLED   ((uint32_t)1 << 14) /* Internal ECC not used */

Definition at line 65 of file sd.h.

◆ MMCSD_R1_CARDECCFAILED

#define MMCSD_R1_CARDECCFAILED   ((uint32_t)1 << 21) /* Failed to correct data */

Definition at line 58 of file sd.h.

◆ MMCSD_R1_CARDISLOCKED

#define MMCSD_R1_CARDISLOCKED   ((uint32_t)1 << 25) /* Card is locked */

Definition at line 54 of file sd.h.

◆ MMCSD_R1_CCERROR

#define MMCSD_R1_CCERROR   ((uint32_t)1 << 20) /* Card controller error */

Definition at line 59 of file sd.h.

◆ MMCSD_R1_CIDCSDOVERWRITE

#define MMCSD_R1_CIDCSDOVERWRITE   ((uint32_t)1 << 16) /* CID/CSD error */

Definition at line 63 of file sd.h.

◆ MMCSD_R1_COMCRCERROR

#define MMCSD_R1_COMCRCERROR   ((uint32_t)1 << 23) /* CRC error */

Definition at line 56 of file sd.h.

◆ MMCSD_R1_ERASEPARAM

#define MMCSD_R1_ERASEPARAM   ((uint32_t)1 << 27) /* Bad write blocks */

Definition at line 52 of file sd.h.

◆ MMCSD_R1_ERASERESET

#define MMCSD_R1_ERASERESET   ((uint32_t)1 << 13) /* Reset sequence cleared */

Definition at line 66 of file sd.h.

◆ MMCSD_R1_ERASESEQERROR

#define MMCSD_R1_ERASESEQERROR   ((uint32_t)1 << 28) /* Erase cmd error */

Definition at line 51 of file sd.h.

◆ MMCSD_R1_ERROR

#define MMCSD_R1_ERROR   ((uint32_t)1 << 19) /* General error */

Definition at line 60 of file sd.h.

◆ MMCSD_R1_ERRORMASK

#define MMCSD_R1_ERRORMASK   ((uint32_t)0xfdffe008) /* Error mask */

Definition at line 83 of file sd.h.

◆ MMCSD_R1_ILLEGALCOMMAND

#define MMCSD_R1_ILLEGALCOMMAND   ((uint32_t)1 << 22) /* Bad command */

Definition at line 57 of file sd.h.

◆ MMCSD_R1_LOCKUNLOCKFAILED

#define MMCSD_R1_LOCKUNLOCKFAILED   ((uint32_t)1 << 24) /* Password error */

Definition at line 55 of file sd.h.

◆ MMCSD_R1_OUTOFRANGE

#define MMCSD_R1_OUTOFRANGE   ((uint32_t)1 << 31) /* Bad argument */

Definition at line 48 of file sd.h.

◆ MMCSD_R1_OVERRRUN

#define MMCSD_R1_OVERRRUN   ((uint32_t)1 << 17) /* Overrun (MMC only) */

Definition at line 62 of file sd.h.

◆ MMCSD_R1_READYFORDATA

#define MMCSD_R1_READYFORDATA   ((uint32_t)1 << 8) /* Buffer empty */

Definition at line 80 of file sd.h.

◆ MMCSD_R1_STATE_DATA

#define MMCSD_R1_STATE_DATA   ((uint32_t)5 << MMCSD_R1_STATE_SHIFT) /* 5=Sending data state */

Definition at line 76 of file sd.h.

◆ MMCSD_R1_STATE_DIS

#define MMCSD_R1_STATE_DIS   ((uint32_t)8 << MMCSD_R1_STATE_SHIFT) /* 8=Disconnect state */

Definition at line 79 of file sd.h.

◆ MMCSD_R1_STATE_IDENT

#define MMCSD_R1_STATE_IDENT   ((uint32_t)2 << MMCSD_R1_STATE_SHIFT) /* 2=Identification state */

Definition at line 72 of file sd.h.

◆ MMCSD_R1_STATE_IDLE

#define MMCSD_R1_STATE_IDLE   ((uint32_t)0 << MMCSD_R1_STATE_SHIFT) /* 0=Idle state */

Definition at line 70 of file sd.h.

◆ MMCSD_R1_STATE_MASK

#define MMCSD_R1_STATE_MASK   ((uint32_t)15 << MMCSD_R1_STATE_SHIFT)

Definition at line 68 of file sd.h.

◆ MMCSD_R1_STATE_PRG

#define MMCSD_R1_STATE_PRG   ((uint32_t)7 << MMCSD_R1_STATE_SHIFT) /* 7=Programming state */

Definition at line 78 of file sd.h.

◆ MMCSD_R1_STATE_RCV

#define MMCSD_R1_STATE_RCV   ((uint32_t)6 << MMCSD_R1_STATE_SHIFT) /* 6=Receiving data state */

Definition at line 77 of file sd.h.

◆ MMCSD_R1_STATE_READY

#define MMCSD_R1_STATE_READY   ((uint32_t)1 << MMCSD_R1_STATE_SHIFT) /* 1=Ready state */

Definition at line 71 of file sd.h.

◆ MMCSD_R1_STATE_SHIFT

#define MMCSD_R1_STATE_SHIFT   (9) /* Current card state */

Definition at line 67 of file sd.h.

◆ MMCSD_R1_STATE_STBY

#define MMCSD_R1_STATE_STBY   ((uint32_t)3 << MMCSD_R1_STATE_SHIFT) /* 3=Standby state */

Definition at line 74 of file sd.h.

◆ MMCSD_R1_STATE_TRAN

#define MMCSD_R1_STATE_TRAN   ((uint32_t)4 << MMCSD_R1_STATE_SHIFT) /* 4=Transfer state */

Definition at line 75 of file sd.h.

◆ MMCSD_R1_UNDERRUN

#define MMCSD_R1_UNDERRUN   ((uint32_t)1 << 18) /* Underrun (MMC only) */

Definition at line 61 of file sd.h.

◆ MMCSD_R1_WPERASESKIP

#define MMCSD_R1_WPERASESKIP   ((uint32_t)1 << 15) /* Not all erased */

Definition at line 64 of file sd.h.

◆ MMCSD_R1_WPVIOLATION

#define MMCSD_R1_WPVIOLATION   ((uint32_t)1 << 26) /* Erase access failure */

Definition at line 53 of file sd.h.

Function Documentation

◆ sd_get_state()

uint8_t sd_get_state ( )

◆ sd_get_type()

uint8_t sd_get_type ( )

◆ sd_getSectorCount()

uint8_t sd_getSectorCount ( uint32_t *  ptr)

◆ sd_initialize()

DSTATUS sd_initialize ( )

Referenced by disk_initialize().

Here is the caller graph for this function:

◆ sd_ioctl()

DRESULT sd_ioctl ( uint8_t  cmd,
void *  buff 
)

Referenced by disk_ioctl().

Here is the caller graph for this function:

◆ sd_read()

DRESULT sd_read ( uint8_t *  buff,
uint32_t  sector,
uint16_t  count 
)

Referenced by disk_read().

Here is the caller graph for this function:

◆ sd_status()

DSTATUS sd_status ( )

Referenced by disk_status().

Here is the caller graph for this function:

◆ sd_timerproc()

void sd_timerproc ( )

◆ sd_write()

DRESULT sd_write ( const uint8_t *  buff,
uint32_t  sector,
uint16_t  count 
)

Referenced by disk_write().

Here is the caller graph for this function: