-
Notifications
You must be signed in to change notification settings - Fork 308
Deryugin edited this page Oct 29, 2019
·
1 revision
MMC devices are presented as a regular block devices, so they can be accessed via devfs (/dev/mmcX
). Generally there's no specific API if you just work with MMC/SD card as a data storage.
MMC and SD specifications allows to use a lot of common code for various storage devices, so you don't need to implement whole set of block device read()
/write()
/ioctl()
functions.
It's recommended to place new MMC/SD drivers into src/drivers/mmc/host/
directory (check out existing drivers for examples).
The general idea is following:
- You need to implement
struct host_ops
with.request
handler, which should send command and transfer data correctly.
Example (assume we implement driver for foobar
MMC controller):
src/drivers/mmc/host/foobar/foobar.c
static void foobar_mmc_request(struct mmc_host *host, struct mmc_request *req) {
int cmd_idx = req->cmd.opcode;
int cmd_arg = req->cmd.arg;
int flags = req->cmd.flags;
/* cmd_idx, cmd_arg and flags correspond to MMC/SD specification */
bool do_read = flags & MMC_DATA_READ;
bool do_write = flags & MMC_DATA_WRITE;
uintptr_t data_transfer_addr = req->data.addr;
/* Do something meaningful ... */
}
const struct mmc_host_ops foobar_mmc_ops = {
.request = foobar_mmc_request,
};
- Register MMC device in system if it is present.
src/drivers/mmc/host/foobar/foobar.c
#include <drivers/mmc/mmc_core.h>
#include <drivers/mmc/mmc_host.h>
#include <framework/mod/options.h>
EMBOX_UNIT_INIT(pl181_init); /* Tells the system to run this function on boot */
static int pl181_init(void) {
/* First you need to figure out
* if device is present */
bool is_present = ...;
if (is_present) {
struct mmc_host *mmc = mmc_host_alloc();
mmc->ops = &foobar_mmc_ops;
/* This function will reset card and read
* identification registers */
mmc_sw_reset(mmc);
}
return 0;
}
- Embox on QEMU emulator
- ARM
- AARCH64
- x86
- MIPS
- RISC-V
- PowerPC
- DLX (Microblaze)
- SPARC
- Porting to a new architecture
- Audio
- FPGA
- FS
- Graphics
- NET
- USB
- iec61850
- C Plus Plus
- GY 30 I2C light sensor on STM32
- STM32FLASHER
- Emdocker
- Emdocker on MAC
- Xen port workflow
- Troubleshooting
- QEMU with GRUB2 and Syslinux
- LKL subsystem
- Beremiz
- 4diac Forte