![]() |
RTOS_MSPM0
1.1
ECE445M starter code
|
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... | |
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.
| void CS_Init | ( | void | ) |
Configure SDC chip select.
Enable SDC chip select, so it is an output
| none |
| DRESULT disk_ioctl | ( | BYTE | drv, |
| BYTE | cmd, | ||
| void * | buff | ||
| ) |
Disk input/output.
General purpose function for all disk I/O
| drv | (only drive 0 is supported) |
| cmd | disk command |
| buff | pointer to RAM input/output data |
| void disk_timerproc | ( | void | ) |
This should be called every 10 ms.
This implements timeout functions
| none |
| 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 | 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 |
| drive | number (only drive 0 is supported) |
| 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 | 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 |
| drv | (only drive 0 is supported) |
| buff | pointer to an empty RAM buffer |
| sector | sector number of SD card to read: 0,1,2,... |
| count | number of sectors to read |
| 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 | 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 |
| buff | pointer to an empty RAM buffer |
| sector | sector number of SD card to read: 0,1,2,... |
| DSTATUS eDisk_Status | ( | BYTE | drive | ) |
Check the status of the SD card.
Checks the status of the secure digital care.
| 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 |
| drive | number (only drive 0 is supported) |
| 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 | 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 |
| drv | (only drive 0 is supported) |
| buff | pointer to RAM buffer with data |
| sector | sector number of SD card to write: 0,1,2,... |
| count | number of sectors to write |
| 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 | 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 |
| buff | pointer to RAM buffer with 512 bytes of data |
| sector | sector number of SD card to write: 0,1,2,... |