linux tf 卡驱动理解
mmc 驱动框架

梳理tf卡读取异常重启逻辑问题进展:
a. 查找代码发现,在mmc_blk_issue_rw_rq函数中可以找到数据读取数据异常时的处理机制,其中部分代码如下:
static int mmc_blk_issue_rw_rq(struct mmc_queue *mq, struct request *rqc)
{
...
mmc_start_req(card->host, areq, (int *) &status);//读取数据
switch (status) {
case MMC_BLK_DATA_ERR://读取数据错误
case MMC_BLK_CMD_ERR://执行命令错误
case MMC_BLK_ABORT:// 异常退出
mmc_blk_reset(); //执行复位函数
}
...
}
执行复位函数的逻辑,其中部分代码
mmc_blk_reset
|--->mmc_hw_reset
|--->host->bus_ops->reset
|--->mmc_reset //复位函数
|--->mmc_flush_cache(host->card); //清除cache
|--->mmc_power_cycle(host, card->ocr); //执行io断电复位操作
|--->mmc_set_ios
|---> host->ops->set_ios
|--->_SetPower
|--->Hal_CARD_PowerOn/Hal_CARD_PowerOff
|--->mmc_init_card(host, card->ocr, card);//重新初始化tf卡
复位函数主要体现在mmc_reset 函数中。在文件sstar/sdmmc/ms_sdmmc_lnx.c 中st_mmc_ops,并未实现hw_reset函数,因此mmc_reset,主要内容为:
1、执行mmc_flush_cache,清除cache
2、mmc_power_cycle, 执行io断电复位操作,具体逻辑如下
void mmc_power_cycle(struct mmc_host *host, u32 ocr)
{
mmc_power_off(host);
/* Wait at least 1 ms according to SD spec */
mmc_delay(1);
mmc_power_up(host, ocr);
}
3、执行mmc_init_card,重新初始化tf卡
b. 目前分析代码,初步得出结果为:
1、tf卡io复位调用的时机:
操作tf卡读取数据或执行命令时,最终会调用函数mmc_blk_issue_rw_rq,返回值为MMC_BLK_DATA_ERR, MMC_BLK_CMD_ERR, MMC_BLK_ABORT,都会触发复位动作。
2、tf卡io复位主要做了些操作:
清除cache;执行io断电复位;重新初始化tf卡
参考文章:
https://blog.csdn.net/u013836909/category_11430485.html
https://www.cnblogs.com/yanghong-hnu/p/4671343.html
https://blog.csdn.net/u013836909/article/details/12282330
https://blog.csdn.net/h_8410435/article/details/105427499