| Summary |
#include <file_config.h>
U32 DeviceCtrl (
U32 code, /* Device control code */
void *p); /* Pointer to parameters */
|
| Description | The function DeviceCtrl sends a control code directly to device driver, causing the corresponding device to perform the corresponding operation. The parameter code specifies the control code for the driver. The parameter p is a generic pointer. It is used to pass additional parameters to the driver when needed. The following control codes are currently supported:
| Control code | Function |
|---|
| DC_CHKMEDIA | Checks the Media Detect and Write Protect status of a removable media. For example, SD/MMC Memory Card, USB Flash dongle. | | DC_FORMAT | Low level formats the device. This is only needed for NAND device low level FTL formatting. |
The function is part of the FAT Driver. The prototype is defined in the file File_Config.h. Developers must customize the function. |
| Return Value | For control code DC_CHKMEDIA the DeviceCtrl function returns: - M_INSERTED
Media is inserted in the socket. - M_PROTECTED
Media is read-only. Lock slider on SD Card is in position 'Locked'. - M_NOCHKMEDIA
Media Check function is not supported.
For control code DC_FORMAT the DeviceCtrl function returns:
- __TRUE
Low level formatting successful. - __FALSE
Low level formatting failed.
|
| See Also | fat.Init, fat.ReadInfo, fat.ReadSect, fat.UnInit, fat.WriteSect |
| Example |
/* USB-MSC Device Driver Control Block */
FAT_DRV usb0_drv = {
Init,
UnInit,
ReadSector,
WriteSector,
ReadInfo,
DeviceCtrl
};
static U32 DeviceCtrl (U32 code, void *p) {
/* Device Control system call. */
if (code != DC_CHKMEDIA) {
return (0);
}
/* Read Device Detected status. */
if (media_ok == __FALSE) {
/* Allow to initialize the media first. */
return (M_INSERTED);
}
/* Allow USB Host to detect and enumerate the device. */
usbh_engine();
if (usbh_msc_status () == __TRUE) {
return (M_INSERTED);
}
return (0);
}
|