/*********************************************************************
** Module Name: SD CARD **
** Author: CTH **
** Version: 1.0 **
** CreateDate: 2009-8-10 **
** Description: **
** Remark: **
** Revision History: 2009-8-10 **
** Email: ahong007@yeah.net ** **
**********************************************************************/
/*********************************************************************
** 实验目的:使用SD卡功能对SD卡进行读写,注意SD卡必须是标准SD卡 **
** 实验说明:SD卡插入卡座,注意不要把SD卡锁住。本实验仅仅是对SD **
** 卡进行数组级别的读写而不是文件系统的读写,如需要文件系统 **
** 请与大道科技或者与红尘联系。 **
**********************************************************************/
#include <csl_mmc.h>
#include <stdio.h>
#include <csl_pll.h>
#include "mysd.h"
void SdRead(Uint32 addr,Uint16* data);
void SdWrite(Uint32 addr,Uint16* data);
Uint16 data[256];
Uint16 fill[256];
ioport unsigned int * fckctl=(unsigned int *)0x4c00; /* 00 */
ioport unsigned int * ctl=(unsigned int *)0x4c01; /* 00 */
ioport unsigned int * clk=(unsigned int *)0x4c02; /* 00 */
ioport unsigned int * st0=(unsigned int *)0x4c03; /* 00 */
ioport unsigned int * st1=(unsigned int *)0x4c04; /* 00 */
ioport unsigned int * im=(unsigned int *)0x4c05; /* 00 */
ioport unsigned int * tor=(unsigned int *)0x4c06; /* 00 */
ioport unsigned int * tod=(unsigned int *)0x4c07; /* 00 */
ioport unsigned int * blen=(unsigned int *)0x4c08; /* 00 */
ioport unsigned int * nblk=(unsigned int *)0x4c09; /* 00 */
ioport unsigned int * nblc=(unsigned int *)0x4c0a; /* 00 */
ioport unsigned int * ddr=(unsigned int *)0x4c0b; /* 00 */
ioport unsigned int * dxr=(unsigned int *)0x4c0c; /* 00 */
ioport unsigned int * cmd=(unsigned int *)0x4c0d; /* 00 */
ioport unsigned int * argl=(unsigned int *)0x4c0e; /* 00 */
ioport unsigned int * argh=(unsigned int *)0x4c0f; /* 00 */
ioport unsigned int * rsp0=(unsigned int *)0x4c10; /* 00 */
ioport unsigned int * rsp1=(unsigned int *)0x4c11; /* 00 */
ioport unsigned int * rsp2=(unsigned int *)0x4c12; /* 00 */
ioport unsigned int * rsp3=(unsigned int *)0x4c13; /* 00 */
ioport unsigned int * rsp4=(unsigned int *)0x4c14; /* 00 */
ioport unsigned int * rsp5=(unsigned int *)0x4c15; /* 00 */
ioport unsigned int * rsp6=(unsigned int *)0x4c16; /* 00 */
ioport unsigned int * rsp7=(unsigned int *)0x4c17; /* 00 */
ioport unsigned int * drsp=(unsigned int *)0x4c18; /* 00 */
ioport unsigned int * etok=(unsigned int *)0x4c19; /* 00 */
ioport unsigned int * cidx=(unsigned int *)0x4c1a; /* 00 */
ioport unsigned int * EBSR=(unsigned int *)0x6C00; /* 00 */
void main()
{
int i=0;
CSL_init();
for(i=0;i<256;i++)
fill[i]=i;
SdWrite(0x000000,fill);
SdRead(0x000000,data);
for(;;);
}
void SdWrite(Uint32 addr,Uint16* data)
{
mmc1 = MMC_open(MMC_DEV1);
MMC_setupNative(mmc1,&Init);
MMC_sendGoIdle(mmc1);
for (count=0;count<4016;count++)
asm(" NOP");
cardtype = MMC_sendOpCond(mmc1,0x00100000);
asm(" NOP");
if(cardtype==SD_CARD)
{
cid = &cardid;
SD_sendAllCID(mmc1,cid); // get the CID structure for all cards.
asm(" NOP");
card = &cardalloc;
rca = SD_sendRca(mmc1,card);
asm(" NOP");
}
/* Select the card to transfer data to/from. This step puts the card into the *
* transfer state where it is ready to read/write data */
retVal = MMC_selectCard(mmc1,card);
asm(" NOP");
/*Setting the SD bus width to 4 bits...*/
/*retVal = SD_setWidth(mmc1, 0x4);*/
MMC_write(mmc1,addr,data,512);
for (count = 0; count <= 6000; ++count)
asm(" NOP");
/*
for (count = 0; count <= 25000; ++count)
asm(" NOP");
for (count = 0; count <= 25000; ++count)
asm(" NOP");
for (count = 0; count <= 25000; ++count)
asm(" NOP");
*/
MMC_close(mmc1);
}
void SdRead(Uint32 addr,Uint16* data)
{
mmc1 = MMC_open(MMC_DEV1);
MMC_setupNative(mmc1,&Init);
MMC_sendGoIdle(mmc1);
for (count=0;count<4016;count++)
asm(" NOP");
cardtype = MMC_sendOpCond(mmc1,0x00100000);
asm(" NOP");
if(cardtype==SD_CARD)
{
cid = &cardid;
SD_sendAllCID(mmc1,cid); // get the CID structure for all cards.
asm(" NOP");
card = &cardalloc;
rca = SD_sendRca(mmc1,card);
asm(" NOP");
}
/* Select the card to transfer data to/from. This step puts the card into the *
* transfer state where it is ready to read/write data */
retVal = MMC_selectCard(mmc1,card);
asm(" NOP");
/*Setting the SD bus width to 4 bits...*/
/*retVal = SD_setWidth(mmc1, 0x4);*/
MMC_read(mmc1,addr,data,512);
for (count = 0; count <= 6000; ++count)
asm(" NOP");
/*
for (count = 0; count <= 25000; ++count)
asm(" NOP");
for (count = 0; count <= 25000; ++count)
asm(" NOP");
for (count = 0; count <= 25000; ++count)
asm(" NOP");
*/
MMC_close(mmc1);
}
exam_SDreadwrite.zip_SD卡
版权申诉
78 浏览量
2022-09-19
20:43:09
上传
评论
收藏 816KB ZIP 举报
JonSco
- 粉丝: 76
- 资源: 1万+
最新资源
- 单片机课程设计 -现代交通信号灯设计
- 分布式锁与信号量Web-master-demo
- 基于麻雀优化算法改进BP神经网络的回归分析(代码完整,数据齐全)
- 毕业设计-咖啡网站商城javaweb
- tensorflow-gpu-1.9.0-cp27-cp27m-win-amd64.whl
- tensorflow-gpu-1.10.0-cp27-cp27m-win-amd64.whl
- YOLOV5TORCH04
- 拿下期末javaweb课设
- tensorflow-gpu-1.10.0-cp27-cp27m-win-amd64.whl
- .4.【技能3】根据特殊的几何条件求坐标 (1)【课程出自拼多多店铺:北大网课资料店】
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈