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

📄 test_main.c.bak

📁 It is driver source code for IDE harddisk and used to learn IDE interface and file system.
💻 BAK
📖 第 1 页 / 共 3 页
字号:
  while ((ReadBYTE(1,7) & 0xC0)!=0x40); // Wait for DRDY & NOT BUSY 
 
  // Return the error register...
  return ReadBYTE(1, 1);
}

unsigned char ReadSector(unsigned char Drive, 
                unsigned char Head, unsigned int Track, unsigned char Sector) 
{
  unsigned int i;
  // Prepare parameters...
  WriteBYTE(1,6, 0xA0+(Drive ? 0x10:00)+Head); // CHS mode/Drive/Head
  WriteBYTE(1,5, Track>>8);  // MSB of track
  WriteBYTE(1,4, Track);     // LSB of track
  WriteBYTE(1,3, Sector);    // sector
  WriteBYTE(1,2, 0x01);      // 1 sector
  // Issue read sector command...
  WriteBYTE(1,7, 0x20);      // Read sector(s) command
  while ((ReadBYTE(1,7) & 0x08)!=0x08); // Wait for DRQ or timeout

   for (i=0; i<256;i++) Uart_Printf("%x ", (*(volatile U16 *)0x4000002));
   return ReadBYTE(1, 1);
}



unsigned char WriteSector(unsigned char Drive, unsigned char Head, unsigned int Track, unsigned char Sector) 
{
  unsigned int i;

  while ((ReadBYTE(1,7) & 0x80)==0x80);

  // Prepare parameters...
  WriteBYTE(1,6, 0xA0+(Drive ? 0x10:00)+Head); // CHS mode/Drive/Head
  WriteBYTE(1,5, Track>>8);  // MSB of track
  WriteBYTE(1,4, Track);     // LSB of track
  WriteBYTE(1,3, Sector);    // sector
  WriteBYTE(1,2, 0x01);      // 1 sector

  while ((ReadBYTE(1,7) & 0x10)!=0x10 );
  // Issue write sector command...
  WriteBYTE(1,7, 0x30);      // Write sector(s) command

  while ((ReadBYTE(1,7) & 0x08)!=0x08 ) ;
 
  // write sector data...
  for (i=0; i<256; i++)  (*(volatile U16 *)0x4000002) = 0x4444;
  while ((ReadBYTE(1,7) & 0xC0)!=0xC0 ); // Wait for DRDY and NOT BUSY
 
  // Return the error register...
  return ReadBYTE(1, 1);
}

typedef struct 
{
  U8 Heads; 
  unsigned int Tracks;
  unsigned int SectorsPerTrack;
  U8 Model[41];
} tdefDriveInfo;

U8 IdentifyDrive(unsigned char DriveNo, tdefDriveInfo *DriveInfo) 
{
  unsigned int i; 
  U16 tv;
  U16 Buffer[256];

  WriteBYTE(1, 6, 0xA0 + (DriveNo ? 0x10:0x00)); // Select drive
  WriteBYTE(1, 1, 0);  
  WriteBYTE(1, 2, 1);  
  WriteBYTE(1, 3, 1);  
  WriteBYTE(1, 4, 0);  
  WriteBYTE(1, 5, 0);  
  WriteBYTE(1, 7, 0xEC);  

  
  while ((ReadBYTE(1,7) & 0x08)!=0x08); 

  // Two bytes at a time
  for (i=0; i<512; i+=2)   Buffer[i] = (*(volatile U16 *)0x4000002);

  // Extract drive info
  DriveInfo->Heads           = Buffer[6];
  DriveInfo->Tracks          = Buffer[2];
  DriveInfo->SectorsPerTrack = Buffer[12];

  // Swap bytes, because of 16 bit transfer...
  for (i=0; i<40; i+=2) 
  {
    tv = Buffer[54+i];
    DriveInfo->Model[i] = tv / 256;
    DriveInfo->Model[i+1] = tv % 256;
  }

  // Terminate string...
  DriveInfo->Model[40]='\0';

  Uart_Printf("Model         = %s\n\r", DriveInfo->Model);
  Uart_Printf("Heads         = %u\n\r", DriveInfo->Heads);
  Uart_Printf("Tracks        = %u\n\r", DriveInfo->Tracks);
  Uart_Printf("Sectors/Track = %u\n\r", DriveInfo->SectorsPerTrack);
  Uart_Printf("Model Size    = %uMB\n\r", DriveInfo->Heads * DriveInfo->Tracks * DriveInfo->SectorsPerTrack * 512 / 1024 / 1024);

  // Return the error register...
  return ReadBYTE(1, 1);
}


void WakeIDE()
{
  WriteBYTE(1, 6, 0xA0);
  while ((ReadBYTE(1,7) & 0xC0)!=0x40) ;  
}

void IdeTest()
{
  int i; 
  int a,b,c;
  U32 size;
  tdefDriveInfo DriveInfo;
  Uart_Printf("\n\rIDE Test...\n\r");
  Uart_Printf("Waiting for Initial DRDY & NOT BUSY from drive\n\r"); 
  WakeIDE();
  Uart_Printf("Spinning drive up (Going to IDLE mode)\n\r");
  Uart_Printf("SetMode=0x%0.2x\n\r", SetMode(0, 1, 1));
  Uart_Printf("Drive is ready!\n\r");

//  i = ReadSector(0, 0, 0, 1);

   size = 16 * 1010 * 51;

    for (a=1;a<16;a++)
   {
     for (b=1;b<1010;b++)
     {
       for (c=1;c<52;c++) 
        {
          WriteSector(0,a-1,b-1,c);
//          ReadSector(0, a-1, b-1, c);

//          Delay(2000);
        }
         Uart_Printf("%x ", b);
     
     }

//
}

         
//  WriteSector(0,0,0,1);

//  Uart_Printf("ReadSector=0x%0.2x\n\r", i);
  IdentifyDrive(0, &DriveInfo);


  Delay(10000);   
}

int Main()
{
	rSYSCFG=CACHECFG;   // Using 8KB Cache//
	rINTCON=0x5;    //Non-vectored,IRQ enable,FIQ disable 
	rINTMOD=0x0;    //All=IRQ mode
	Port_Init();
	Lcd_DispOFF();
	Lcd_PowerUp();
	Led_Display(0x00);
	Delay(10000);
	Led_Display(0x07);
	Delay(5000);
	Led_Display(0x0);
         //-------------------------------------------------------------------------------
 	// Init LCD Contorl
	ClearVideoBuffer();
	rLCDCON1=(0)|(1<<5)|(0x3<<8)|(0x3<<10)|(10<<12);
	rLCDCON2=(LINEVAL)|(HOZVAL<<10)|(10<<21);  
	rLCDSADDR1= (0x00<<27) | ((0x0c000000>>22)<<21 ) | M5D(0x0c000000>>1);
	rLCDSADDR2= M5D( (((U32)0x0c000000+(LCD_XSIZE*LCD_YSIZE/8))>>1) ) | (13<<21);
	rLCDSADDR3= (LCD_XSIZE/16);
	rLCDCON1=(1)|(1<<5)|(0x3<<8)|(0x3<<10)|(10<<12);
	Intro();
	Lcd_DispON();
	//-------------------------------------------------------------------------------
 	Delay(50000);
	ClearIntro();
	Led_Display(0x00);
	Delay(10000);
	Led_Display(0x07);
	Delay(5000);
	Led_Display(0x0);

	mPosX = 154;
 	mPosY = 110;
	DrawMousePointer(mPosX, mPosY);

	Uart_Init(115200); 
	Uart_Printf("\n\rMOA Starting....");		

	//	KeyboardInitial();

    IdeTest();
/*	
 	ToMouse(0xFF);
 	if (ReadMouse() == 0xAA) ToMouse(0xFF);
 	if (ReadMouse() == 0xAA) ToMouse(0xFF);
 	ToMouse(0xF4);	
	ToMouse(0xEE);
*/
	while (1)
	{

//            mPosX = ReadMouse();
//           if (mPosX != 0)
//                Uart_Printf("\n\r %x", mPosX);

//		ProcessMouse();  
		ProcessKeyboard();

	};
	return 0;
}


void Port_Init(void)
{
    rPCONA=0x1ff;	

//    rPDATB=0x3ff;
//    rPCONB=0x3ff;
	rPDATB = 0x04f;
	rPCONB = 0x7cf;    

    rPDATC=0xffff;	//All I/O Is High
    rPCONC=0x0f05f555;	
    rPUPC=0x30c0;	//PULL UP RESISTOR should be enabled to I/O

    rPDATD=0xff;
    rPCOND=0xaaaa;	
    rPUPD=0xff;

    rPDATE=0x1ff;  	//All I/O Is High
    rPCONE=0x20428;	//All NC is INPUT	
    rPUPE=0x06;	//PE8 do not have programmable pull-up resistor.  

     rPDATF=0x1ff;	//All I/O Is High
    rPCONF=0x20900a;//All NC is INPUT
    rPUPF=0x163;

    rPDATG=0xff;
    rPCONG=0xC3FF;		
    rPUPG=0x0;		//should be enabled  
    
    rSPUCR=0x7; 	//D15-D0 pull-up disable
    
    rEXTINT=0x0;	//All EXTINT0-7 Low level interrupt
    rNCACHBE0=(((Non_Cache_End)>>12)<<16)|((Non_Cache_Start)>>12); 
}

⌨️ 快捷键说明

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