⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sd_card.c

📁 The source code example of ARM9 development board from Artila (M-501 starter kit). The source code c
💻 C
字号:
/* *	Description:  *		example for SD Card. *	 *		What is shown in this example: *		1. How to mount SD Card *		2. How to write a file to SD Card *		3. How to umount SD Card */#include <stdio.h>#include <fcntl.h>#include <errno.h>#include <sys/mount.h>#include <unistd.h>const char buf[] = "MATRIX SD Card Example\n";int main(void){	int	ret, fd;	char	filename[128];	/*mount SD device*/	ret = mount("/dev/mmc0", "/mnt/mmc", "vfat", MS_SYNCHRONOUS, NULL);	if (ret == -1) {		printf("no device found\r\n");		return;	} else {		printf("found /dev/mmc0\r\n");	}	sprintf(filename, "/dev/mmc0/tmpfile");		/*create file on SD Card*/	fd = open(filename, O_CREAT|O_WRONLY|O_TRUNC);	if (fd == -1) {		printf("create file failed. errno: %d\r\n", errno);			} else {		/*write file to SD Card*/		ret = write(fd, buf, sizeof(buf));		if (ret == -1) {			printf("write file failed. errno: %d\r\n", errno);		} else {			printf("write tmpfile to SD Card ok\r\n");		}	}	close(fd);	/*umount SD Card*/		while (1) {		ret = umount("/mnt/mmc");		if (ret != 0) {			if (errno == EBUSY) { 				sleep(1);				continue;			}			}		printf("umount /mnt/mmc\r\n");		break;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -