weAut_01 / weAutSys    R 2.2.1
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines
Defines | Functions
Driver adaption to SMC
+ + fatFS -- ChaN's FAT filesystem implementation + +

Overview

The functions in this architecture specific module mainly implement the glue code between ChaN's file system adaption and weAutSys' driver and handling functions for small memory cards (SMCs).

Defines

#define _USE_IOCTL   1
 enable disk_ioctl function
#define _USE_WRITE   1
 enable disk_write function
#define CT_BLOCK   0x08
 Card type flag: block addressing.
#define CT_MMC   0x01
 Card type flag: MMC version 3.
#define CT_SD1   0x02
 Card type flag: SD version 1.
#define CT_SD2   0x04
 Card type flag: SD version 2.
#define CT_SDC
 Card type mask: SD.
#define CTRL_ERASE_SECTOR   4
 Generic command: force erased a block of sectors (for only _USE_ERASE)
#define CTRL_POWER   5
 Generic command: get/set power status.
#define DRESULT
 Results of disk (media driver) functions.
#define GET_BLOCK_SIZE   3
 Generic command: get erase block size (for only f_mkfs())
#define GET_SECTOR_COUNT   1
 Generic command: get media size (for only f_mkfs())
#define GET_SECTOR_SIZE   2
 Generic command: get sector size.
#define MMC_GET_CID   12
 Specific ioctl command: get CID.
#define MMC_GET_CSD   11
 Specific ioctl command: get CSD.
#define MMC_GET_OCR   13
 Specific ioctl command: get OCR.
#define MMC_GET_SDSTAT   14
 Specific ioctl command: get SMC status.
#define MMC_GET_TYPE   10
 Specific ioctl command: get card type.
#define RES_ERROR   1
 Any (hard) error occurred.
#define RES_NOTRDY   3
 The drive has not been initialised.
#define RES_PARERR   3
 Invalid function argument.
#define STA_NODISK   0x02
 No medium in the drive / slot.
#define STA_NOINIT   0x01
 Drive not initialized.
#define STA_PROTECT   0x04
 Medium is write protected by hardware switch.

Functions

uint8_t disk_initialize (uint8_t drv)
 Initialise the SMC drive.
DRESULT disk_ioctl (uint8_t drv, uint8_t ctrl, uint8_t *buff)
 Special control functions.
DRESULT disk_read (uint8_t drv, uint8_t *buff, uint32_t sector)
 Read a sector.
uint8_t disk_status (uint8_t drv)
 Get drive status.
DRESULT disk_write (uint8_t drv, const uint8_t *buff, uint32_t sector)
 Write a sector.

Define Documentation

#define DRESULT

Results of disk (media driver) functions.

Hint: The values assigned here for (Grande) FAT FS are not the same as with Petit FatFs. Remark 2: Not any usage of the (three) media access functions within this fatFS version really uses those values: Some just compare to 0 (RES_OK) and some do not care at all. Hence we (this weAutSys port, A.W.) change it to uint8_t and "0 = false = no error = ".

#define STA_NOINIT   0x01

Drive not initialized.

This status (mask) bit indicates that the disk drive has not been initialised. The type of the (inserted) SMC is not determined yet .

See also:
STA_NODISK
disk_status()
#define STA_NODISK   0x02

No medium in the drive / slot.

This status (mask) bit indicates no medium being inserted in the drive respectively in the small memory card (SMC / MMC) connector.

See also:
STA_NOINIT
disk_status()
smcInsertSwitch()
smcInsPow()
#define STA_PROTECT   0x04

Medium is write protected by hardware switch.

Small memory cards (SMCs) do not have a write protect slider and the MMC-slot built in weAut_01 accordingly has no WP-switch. Hence this feature is not implemented and this status won't occur.

See also:
STA_NOINIT
STA_NODISK

Function Documentation

uint8_t disk_initialize ( uint8_t  drv)

Initialise the SMC drive.

This function is used in fatFS to initialise the drive. Legal return values are STA_NOINIT, STA_NODISK, STA_PROTECT and 0 for OK. STA_PROTECT cannot occur with SMCs as there is no hardware write protect mechanism.

With weAutSys this function just checks the initialisation, hence doing (in effect) same as disk_status(). The reason is weAutSys doing the SMC initialisation and other time consuming SMC actions in a background (Protothread) thread .

Parameters:
drvthe number of the physical drive to initialise (must be 0 in this implementation)
Returns:
0: success, STA_NOINIT | STA_NODISK
uint8_t disk_status ( uint8_t  drv)

Get drive status.

This function just informs about the drive status without actually accessing the device.

Parameters:
drvthe physical drive number to check (must be 0 in this implementation)
Returns:
0: success, STA_NOINIT | STA_NODISK
See also:
disk_initialize()
DRESULT disk_read ( uint8_t  drv,
uint8_t *  buff,
uint32_t  sector 
)

Read a sector.

This function reads a sector into the buffer buff supplied. As the process takes 2 ms on SMCs with 5MHz SPI clock frequency multiple sectors are disallowed. This function basically delegates to readDataBlock(sector, buff). Hence the sector number sector is just that cause weAutSys's readDataBlock() takes care of address transformations required for some low capacity SMCs.

Instead of doing block operations by this functions it is preferable to let weAutSys handle that in the respective background thread. That would then be done more compatibly with real time (process automation) tasks.

The same restrictions and recommendations apply to disk_write().

Parameters:
drvthe physical drive number to initialise (must be 0 in this implementation)
buffPointer to the read buffer (NULL not allowed)
sectorSector number (LBA)
DRESULT disk_write ( uint8_t  drv,
const uint8_t *  buff,
uint32_t  sector 
)

Write a sector.

In the sense described with disk_read() this function basically delegates to writeDataBlock(sector, buff).

Parameters:
drvthe physical drive number to initialise (must be 0 in this implementation)
buffpointer to the write buffer (NULL: not allowed)
sectorSector number (LBA)
DRESULT disk_ioctl ( uint8_t  drv,
uint8_t  ctrl,
uint8_t *  buff 
)

Special control functions.

Depending on the device and implementation this function allows to get (/put) certain information from the device:
CTRL_POWER : no effect on weAut_01 module
GET_SECTOR_COUNT : get number of sectors on the disk (uint32_t)
GET_SECTOR_SIZE : get R/W sector size (uint16_t; this implementation will always return 512)
GET_BLOCK_SIZE : get the erase block size in unit of sectors (uint16_t)
MMC_GET_TYPE : get card type flags (1 byte)
MMC_GET_CSD : receive CSD as a data block (16 bytes)
MMC_GET_CID :   receive CID as a data block (16 bytes)
MMC_GET_OCR : receive OCR as an R3 (4 bytes)
MMC_GET_SDSTAT : receive SD status as a data block (64 bytes)

Hint: This function is not implemented if _USE_IOCTL is undefined or 0.

Parameters:
drvthe physical drive number to initialise (must be 0 in this implementation)
ctrlcontrol code
buffbuffer to send/receive control data