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

📄 复件 (2) main.c

📁 ADS下测试ARM平台的SDRAM的读写程序
💻 C
字号:
/**************************************
File Name: CF.c
Author: siukit
Date: 5/22/2007
***************************************/
#include "c:/mylib.h"


#define LBA0      (*(volatile unsigned short*)0x10000802)
#define LBA8      (*(volatile unsigned short*)0x10000804)
#define CMDReg    (*(volatile unsigned short*)0x10000806)
#define DataReg   (*(volatile unsigned short*)0x10000808)
#define	StatReg	  0x1000080E
/*
#define LBA0      (*(volatile unsigned short*)0x10001004)
#define LBA8      (*(volatile unsigned short*)0x10001008)
#define CMDReg    (*(volatile unsigned short*)0x1000100c)
#define DataReg   (*(volatile unsigned short*)0x10001010)
#define	StatReg	  0x1000101C
*/
#define CLKDIVN   (*(volatile unsigned *)0x4C000014)
#define MPLLCON   (*(volatile unsigned *)0x4C000004)
#define UPLLCON   (*(volatile unsigned *)0x4C000008)

#define INTMSK (*(volatile unsigned *)0x4a000008)
#define TCFG0  (*(volatile unsigned *)0x51000000)
#define TCFG1  (*(volatile unsigned *)0x51000004)
#define TCON   (*(volatile unsigned *)0x51000008)
#define TCNTB0 (*(volatile unsigned *)0x5100000C)
#define TCMPB0 (*(volatile unsigned *)0x51000010)
#define TCNTO0 (*(volatile unsigned *)0x51000014)
#define GPBCON (*(volatile unsigned *)0x56000010)
#define BWSCON (*(volatile unsigned *)0x48000000)
#define BANKCON2 (*(volatile unsigned *)0x4800000C)


 
#define UINT16 unsigned short

#define Freq_125M  19
#define Freq_1M     24
#define Freq_0625M 39
#define Freq_05M   49


void CF_Write(unsigned short cmd,unsigned short lba8,unsigned short lba0,unsigned short * buf)
{
  unsigned short sector_count,i,j;
  putstr("\nIn CF_Write()\n");
  sector_count=lba0&0xff;
  for(;*(volatile unsigned char *)StatReg!=0x50;);  //CF卡是否准备好 
  LBA0=lba0;
  LBA8=lba8;
  CMDReg=cmd;                                    //读,选择LBA方式
  for(i=0;i<sector_count;i++)
     {
       for(;*(volatile unsigned char *)StatReg!=0x58;);  //CF卡是否准备好传输数据
       for(j=0;j<256;j++)
          {
             DataReg=*(buf+i*256+j);
          }
       putstr("Write sector end!\n");
     }	
for(;*(volatile unsigned char *)StatReg!=0x50;);  //操作是否结束
putstr("Write Done!\n");
}


void CF_Read(unsigned short cmd,unsigned short lba8,unsigned short lba0,unsigned short * buf)
{
  unsigned short sector_count,i,j;
  putstr("\nIn CF_Read()\n");
  sector_count=lba0&0xff;
  for(;*(volatile unsigned char *)StatReg!=0x50;);  //CF卡是否准备好 
  LBA0=lba0;
  LBA8=lba8;
  CMDReg=cmd;                                    //读,选择LBA方式
  for(i=0;i<sector_count;i++)
     {
       for(;*(volatile unsigned char *)StatReg!=0x58;);  //CF卡是否准备好传输数据
       for(j=0;j<256;j++)
          {
             *(buf+i*256+j)=DataReg;
          }
       putstr("Read one sector end!\n");
     }	
for(;*(volatile unsigned char *)StatReg!=0x50;);  //操作是否结束
putstr("Read Done!\n");
}

int Main()
{
 int i;
 unsigned short data[512];
 UART_Init();
 for(i=0;i<512;i++) data[i]=i;
  printf("\nBWSCON=0x%x\n",BWSCON);
  printf("BANKCON2=0x%x\n",BANKCON2);
 
 // CF_Write(0x30E0,0x0,0x202,data);
  for(i=0;i<512;i++) data[i]=0;
  putstr("Data[256] before read:\n");
  for(i=0;i<512;i++)
   {
     if(i%16==0) printf("\n");
     printf("0x%x ",data[i]);
   } 
  CF_Read(0x20E0,0x0,0x302,data);
  for(i=0;i<512;i++)
   {
     if(i%16==0) printf("\n");
     if(i==256) putstr("one sector end!\n");
     printf("0x%4x  ",data[i]);
   }    
 return 0;
}








⌨️ 快捷键说明

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