要深入理解它,必须要阅读FATFS的源码。
移植FATFS,最主要的工作是在diskio.c文件里重写几个函数,例如:
#define SD_CARD 0 //SD卡卷标为0
#define EX_FLASH 1 //外部flash卷标为1
然后,先挂载SD,还是先FLASH没有区别
把fs和pdrv(物理驱动号)绑定是靠f_mount的第二个参数path
比如,在f_mkfs函数里能找到这一句:
vol = get_ldnumber(&path);
我们看看get_ldnumber函数怎么写的:
for (tt = *path; (UINT)*tt >= (_USE_LFN ? ' ' : '!') && *tt != ':'; tt++) ; /* Find ':' in the path */
if (*tt == ':') { /* If a ':' is exist in the path name */
tp = *path;
i = *tp++ - '0'; //关键是这句,简单地把PATH字符串第一个字符减去'0'
if (i < 10 && tp == tt) { /* Is there a numeric drive id? */
if (i < _VOLUMES) { /* If a drive id is found get the value and strip it */
vol = (int)i;
*path = ++tt;
}
}
...
return vol;
现在可以知道了,它们绑定是把path字符串的第一个字符简单地转换为数值。
各位看官可能要问了,难道FATFS的盘符必须用"0:"?难道不能像电脑上一样用"A:"?
可以的,同样在get_ldnumber函数里,可以看到有个宏_STR_VOLUME_ID。详细内容请查阅这个宏。