init_timer(&timer1);
timer1.function = test_time;
timer1.data = ;
timer1.expires = jiffies + msecs_to_jiffies();
add_timer(&timer1);
sd_test(mmc);
printk("count = %d \n",count);

sd_test()函数写在probe函数中,但要等待sd初始化完毕才行,需要在上电时就插入SD卡,而不要等待系统起来之后。另外,如果mmc_rescan函数使用的工作队列实现的,那么它与probe就属于两个线程,会造成在执行sd_test时,sd卡还没初始化好,所以测试时不要用工作队列,直接调用就可以了。

void test_time(void)
{
count++;
mod_timer(&timer1,jiffies+msecs_to_jiffies(1));
}

计数方式,没1/HZ时间计数一次,HZ跟系统相关,我的是250HZ,精确度是0.004S,msecs_to_jiffies(x),x是指tick数,间断时间由tick数*精确度。系统的计数器是超时计数,使用mod_timer函数重启计数,并赋值新的值。

void sd_test(struct mmc_host *mmc)
{
struct sepmmc_host *host = mmc_priv(mmc);
reset_hardware(host);
disable_any_int(host);
clear_any_pending_int(host); sepmmc_start_command(host);
init_completion(&host->cmd_complete_request);
enable_command_done_int(host);
wait_for_completion(&host->cmd_complete_request);
printk("command transfer over\n"); init_completion(&host->data_complete_request);
enable_data_transfer_over_int(host);
wait_for_completion(&host->data_complete_request);
printk("data transfer over\n");
// dma_free_coherent(NULL, 0x2000, p ,bus_addr);
// if (!mrq->data->error && mrq->stop) {
// init_completion(&host->cmd_complete_request);
// enable_command_done_int(host);
// wait_for_completion(&host->cmd_complete_request);
// } host->mrq = NULL;
if(host->cmd)
kfree(host->cmd);
host->cmd = NULL;
host->data = NULL; // mmc_request_done(mmc, mrq);
printk("------sd_test out------\n");
}
void sepmmc_start_command(struct sepmmc_host *host)
{
struct mmc_command *cmd;
unsigned int cmd_reg=0;
dma_test(host->mmc);
cmd = (struct mmc_command *)kmalloc(sizeof(struct mmc_command),GFP_KERNEL);
printk("sepmmc_start_command into\n");
cmd->opcode = 18;
cmd->arg = 0;
cmd->flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
cmd_reg |= cmd->opcode;
if(cmd->flags & MMC_RSP_PRESENT)
cmd_reg |= SDIO_CMD_RESP_EXPE(1);
if(cmd->flags & MMC_RSP_136)
cmd_reg |= SDIO_CMD_LONG_RESP(1);
if(cmd->flags & MMC_RSP_CRC)
cmd_reg |= SDIO_CMD_CHK_RESP_CRC(1); cmd_reg |= SDIO_CMD_HAVE_DAT_TRAN(1);
cmd_reg |= SDIO_CMD_WAIT_DAT(1);
cmd_reg |= SDIO_CMD_START;
host->cmd = cmd;
writel(0,SDIO1_CMDARG_V);
// writel(cmd_reg,SDIO1_CMD_V);
writel(0x80002352,SDIO1_CMD_V);
printk("sepmmc_start_command over\n");
}
void dma_test(struct mmc_host *mmc)
{
struct sepmmc_host *host = mmc_priv(mmc);
//struct sepmmc_dma_descriptor *descriptor_test[1];
struct mmc_data *data;
//dma_addr_t DESCRIPTOR_BASE_TEST[1];
dma_addr_t bus_addr;
int i = 0;
char *p ;
printk("------sd_test into------\n"); writel(512,SDIO1_BLKSIZ_V); //block size 512
writel(0x800000,SDIO1_BYTCNT_V);//8M
data = (struct mmc_data*)kmalloc(sizeof(struct mmc_data),GFP_KERNEL);
data->blksz = 512;
data->blocks = 0x4000;
data->flags = MMC_DATA_READ;
data->stop = NULL;
host->data = data; for(i = 0;i < 1024;i++)
{
descriptor_test[i]=dma_alloc_coherent(NULL, sizeof(struct sepmmc_dma_descriptor),&DESCRIPTOR_BASE_TEST[i], GFP_KERNEL);
if(!descriptor_test[i])
printk("descriptor malloc err\n");
}
// p=dma_alloc_coherent(NULL,0x2000,&bus_addr,GFP_KERNEL);
// if(!p)
// printk("p malloc err\n");
// descriptor_test[0]->des0 = 0x8000003c;
// descriptor_test[0]->des1 = 0x2000;
// descriptor_test[0]->des2 = bus_addr;
// descriptor_test[0]->des3 = 0; for(i=0;i<1024;i++)
{
if(i == 0)
descriptor_test[i]->des0 = 0x80000018;
else if(i == 1023)
descriptor_test[i]->des0 = 0x80000034;
else
descriptor_test[i]->des0 = 0x80000010;
} p=dma_alloc_coherent(NULL,0x2000,&bus_addr,GFP_KERNEL);
if(!p)
printk("p malloc err\n"); for(i = 0;i<1024;i++)
{
descriptor_test[i]->des1 = 0x2000;
descriptor_test[i]->des2 = bus_addr;
} for(i = 0;i<1024;i++)
{
if(i < 1023)
descriptor_test[i]->des3 = DESCRIPTOR_BASE_TEST[i+1];
else
descriptor_test[i]->des3 = 0;
} writel(DESCRIPTOR_BASE_TEST[0],SDIO1_DBADDR_V);
writel(0x82,SDIO1_BMOD_V);
printk("dma init over\n");
}

这边配置要注意,自己创建cmd 和 data函数,比如不需要stop命令,就使用data->stop = NULL;这些在中断处理函数中要用,主要的错误就出现在中断处理函数中。

我使用的是内部DMA,与一般的外部DMA不一样,代码差距较大。

最新文章

  1. 【编码】_C#中编码名称(Name)与页面标识(CodePage)的关系_编码gb2312的获取
  2. wget cooikes 下载
  3. IE9 不F12打开控制台,代码不执行。打开后正常
  4. Android 图标添加消息提醒
  5. Drools规则加载变量冲突问题分析
  6. Chrome 快捷键使用
  7. div居中鼠标悬浮显示下拉列表
  8. 关于arguments.callee.caller.arguments[0]获得event的一些问题
  9. ORACLE 根据 sql_id 查询绑定变量的传入值
  10. &lt;抽象工厂&gt;比&lt;工厂方法&gt;多了啥
  11. JAVA同步锁机制 wait() notify() notifyAll()
  12. L2-025 分而治之(并查集)
  13. Spring标签之Bean @Scope
  14. 雅礼 noip2018 模拟赛day3 T2
  15. 弱引用(WeakReference)
  16. servlet中web.xml配置详解
  17. http与https之间的区别
  18. zookeeper报错: org.I0Itec.zkclient.exception.ZkMarshallingError: java.io.EOFException
  19. 2019.01.19 bzoj5457: 城市(线段树合并)
  20. 微信小程序 js结构

热门文章

  1. Int 1的实现过程 (一)
  2. ZooKeeper系列(四)
  3. shellinabox的安装使用
  4. Java基础(十四)--装箱、拆箱详解
  5. Vue之x-template(1)
  6. zabbix4.2学习笔记--zabbix安装
  7. C++11新特性之final override标识符
  8. bzoj1174 Toponyms
  9. mybatis传多个参数(不使用@param注解情况下),3.4.2版本之后出现#{0}-#{n}参数绑定异常
  10. Runlevel in Linux