RTOS_MSPM0  1.1
ECE445M starter code
Macros | Typedefs | Enumerations | Functions
eDisk.h File Reference

low-level SDC driver More...

Go to the source code of this file.

Macros

#define _USE_WRITE   1
 set to 1 to enable disk write
 
#define _USE_IOCTL   1
 set to 1 to enable ioctl()
 
#define STA_NOINIT   0x01 /* Drive not initialized */
 Disk Status Bits (DSTATUS)
 
#define STA_NODISK   0x02 /* No medium in the drive */
 
#define STA_PROTECT   0x04 /* Write protected */
 
#define CTRL_SYNC   0 /* Complete pending write process (needed at _FS_READONLY == 0) */
 
#define GET_SECTOR_COUNT   1 /* Get media size (needed at _USE_MKFS == 1) */
 
#define GET_SECTOR_SIZE   2 /* Get sector size (needed at _MAX_SS != _MIN_SS) */
 
#define GET_BLOCK_SIZE   3 /* Get erase block size (needed at _USE_MKFS == 1) */
 
#define CTRL_TRIM   4 /* Inform device that the data on the block of sectors is no longer used (needed at _USE_TRIM == 1) */
 
#define CTRL_FORMAT   5 /* Create physical format on the media */
 
#define CTRL_POWER_IDLE   6 /* Put the device idle state */
 
#define CTRL_POWER_OFF   7 /* Put the device off state */
 
#define CTRL_LOCK   8 /* Lock media removal */
 
#define CTRL_UNLOCK   9 /* Unlock media removal */
 
#define CTRL_EJECT   10 /* Eject media */
 
#define MMC_GET_TYPE   50 /* Get card type */
 
#define MMC_GET_CSD   51 /* Get CSD */
 
#define MMC_GET_CID   52 /* Get CID */
 
#define MMC_GET_OCR   53 /* Get OCR */
 
#define MMC_GET_SDSTAT   54 /* Get SD status */
 
#define ATA_GET_REV   60 /* Get F/W revision */
 
#define ATA_GET_MODEL   61 /* Get model name */
 
#define ATA_GET_SN   62 /* Get serial number */
 
#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 _DISKIO
 

Typedefs

typedef signed int INT
 
typedef unsigned int UINT
 
typedef signed char CHAR
 
typedef unsigned char UCHAR
 
typedef unsigned char BYTE
 
typedef signed short SHORT
 
typedef unsigned short USHORT
 
typedef unsigned short WORD
 
typedef signed long LONG
 
typedef unsigned long ULONG
 
typedef unsigned long DWORD
 
typedef BYTE DSTATUS
 Status of Disk Functions.
 

Enumerations

enum  BOOL { FALSE = 0 , TRUE }
 Boolean type.
 
enum  DRESULT {
  RES_OK = 0 , RES_ERROR , RES_WRPRT , RES_NOTRDY ,
  RES_PARERR
}
 

Functions

DSTATUS eDisk_Init (BYTE drive)
 Initialize the interface between microcontroller and the SD card. More...
 
DSTATUS eDisk_Status (BYTE drive)
 Check the status of the SD card. More...
 
DRESULT eDisk_Read (BYTE drv, BYTE *buff, DWORD sector, UINT count)
 Read bytes from SD card. More...
 
DRESULT eDisk_ReadBlock (BYTE *buff, DWORD sector)
 Read 512-byte block from SD card. More...
 
DRESULT eDisk_Write (BYTE drv, const BYTE *buff, DWORD sector, UINT count)
 Write bytes to SD card. More...
 
DRESULT eDisk_WriteBlock (const BYTE *buff, DWORD sector)
 Write 512-byte block from SD card. More...
 
void CS_Init (void)
 Configure SDC chip select. More...
 
void disk_timerproc (void)
 This should be called every 10 ms. More...
 
DRESULT disk_ioctl (BYTE drv, BYTE cmd, void *buff)
 Disk input/output. More...
 

Detailed Description

low-level SDC driver

This version of the driver has been configured to operate on the ST7735R, so that both the SDC card and the LCD use the same SSI port, but have different chip selects.

Version
V1.0
Author
Valvano
Warning
AS-IS
Note
For more information see http://users.ece.utexas.edu/~valvano/
Date
December 29, 2026

Function Documentation

◆ CS_Init()

void CS_Init ( void  )

Configure SDC chip select.

Enable SDC chip select, so it is an output

Parameters
none
Returns
none

◆ disk_ioctl()

DRESULT disk_ioctl ( BYTE  drv,
BYTE  cmd,
void *  buff 
)

Disk input/output.

General purpose function for all disk I/O

Parameters
drv(only drive 0 is supported)
cmddisk command
buffpointer to RAM input/output data
Returns
result (0 means OK)

◆ disk_timerproc()

void disk_timerproc ( void  )

This should be called every 10 ms.

This implements timeout functions

Parameters
none
Returns
none

◆ eDisk_Init()

DSTATUS eDisk_Init ( BYTE  drive)

Initialize the interface between microcontroller and the SD card.

Turn on PLL. Since this program initializes the disk, it must run with the disk periodic task operating.

Return parameter
Return Value Meaning
RES_OK 0x00 Successful
STA_NOINIT 0x01 Drive not initialized
STA_NODISK 0x02 No medium in the drive
STA_PROTECT 0x04 Write protected
Parameters
drivenumber (only drive 0 is supported)
Returns
status (0 means OK)

◆ eDisk_Read()

DRESULT eDisk_Read ( BYTE  drv,
BYTE *  buff,
DWORD  sector,
UINT  count 
)

Read bytes from SD card.

Read data from the SD card (write to RAM)

Return parameter
Return Value Meaning
RES_OK 0x00 Successful
RES_ERROR 0x01 R/W Error
RES_WRPRT 0x02 Write Protected
RES_NOTRDY 0x03 Not Ready
RES_PARERR 0x04 Invalid Parameter
Parameters
drv(only drive 0 is supported)
buffpointer to an empty RAM buffer
sectorsector number of SD card to read: 0,1,2,...
countnumber of sectors to read
Returns
result (0 means OK)

◆ eDisk_ReadBlock()

DRESULT eDisk_ReadBlock ( BYTE *  buff,
DWORD  sector 
)

Read 512-byte block from SD card.

Read one block from the SD card (write to RAM)

Return parameter
Return Value Meaning
RES_OK 0x00 Successful
RES_ERROR 0x01 R/W Error
RES_WRPRT 0x02 Write Protected
RES_NOTRDY 0x03 Not Ready
RES_PARERR 0x04 Invalid Parameter
Parameters
buffpointer to an empty RAM buffer
sectorsector number of SD card to read: 0,1,2,...
Returns
result (0 means OK)

◆ eDisk_Status()

DSTATUS eDisk_Status ( BYTE  drive)

Check the status of the SD card.

Checks the status of the secure digital care.

Return parameter
Return Value Meaning
RES_OK 0x00 Successful
STA_NOINIT 0x01 Drive not initialized
STA_NODISK 0x02 No medium in the drive
STA_PROTECT 0x04 Write protected
Parameters
drivenumber (only drive 0 is supported)
Returns
status (0 means OK)

◆ eDisk_Write()

DRESULT eDisk_Write ( BYTE  drv,
const BYTE *  buff,
DWORD  sector,
UINT  count 
)

Write bytes to SD card.

write data to the SD card (read to RAM)

Return parameter
Return Value Meaning
RES_OK 0x00 Successful
RES_ERROR 0x01 R/W Error
RES_WRPRT 0x02 Write Protected
RES_NOTRDY 0x03 Not Ready
RES_PARERR 0x04 Invalid Parameter
Parameters
drv(only drive 0 is supported)
buffpointer to RAM buffer with data
sectorsector number of SD card to write: 0,1,2,...
countnumber of sectors to write
Returns
result (0 means OK)

◆ eDisk_WriteBlock()

DRESULT eDisk_WriteBlock ( const BYTE *  buff,
DWORD  sector 
)

Write 512-byte block from SD card.

Write one block to the SD card (read to RAM)

Return parameter
Return Value Meaning
RES_OK 0x00 Successful
RES_ERROR 0x01 R/W Error
RES_WRPRT 0x02 Write Protected
RES_NOTRDY 0x03 Not Ready
RES_PARERR 0x04 Invalid Parameter
Parameters
buffpointer to RAM buffer with 512 bytes of data
sectorsector number of SD card to write: 0,1,2,...
Returns
result (0 means OK)