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

📄 k8d3x16ux.c.bak

📁 ARM AT9260的一段初始代码,主要是用来测试SDRAM
💻 BAK
字号:
/*   K8D3X16UBC program driver for at91sam9260  ver1.00
                张驿风
              2007年6月7日
*/
#include "type.h"
extern void AT91F_DBGU_Printk(	char *buffer);
#define printf(x) AT91F_DBGU_Printk(x);

#define ERROR  -1
#define OK      1
#define NULL    0

u32 alllength,startper;

extern void sendhexstr8(unsigned char Temp);
extern void sendhexstr16(unsigned int  Temp);

#define FLASH_START_ADDR          0x10000000
#define FLASH_CHIP_HWORD_SIZE     0x100000    //This flash has 1M Hwords
#define FLASH_SECTOR_HWORD_SIZE   0x8000      //The size of each sector of this flash is 32k hwords (1hword = 2 bytes)

#define FLASH_ADDR_UNLOCK1        0x0555
#define FLASH_ADDR_UNLOCK2        0x02aa
#define FLASH_DATA_UNLOCK1        0xaaaa
#define FLASH_DATA_UNLOCK2        0x5555
#define FLASH_SETUP_WRITE         0xa0a0
#define FLASH_SETUP_ERASE         0x8080
#define FLASH_CHIP_ERASE          0x1010
#define FLASH_SECTOR_ERASE        0x3030
void delay(void){
    UINT32 i, temp;
    for (i = 0; i < 100000; i++) {
        temp = i;
    }
}
void del(void){
    int i;
    for(i=0;i<100;i++) delay();
}
int check_busy(volatile UINT16 *addr,unsigned int time){
    UINT16 status;
    unsigned int count;
    count = 0;
    while(1){
        status = *((volatile UINT16 *)0x10000000);
        status = *addr;
        sendhexstr16(status);
        printf("  ");
        if((0x100 & status) == 0x100)break;
        count += 1;
        if(count >= time){
              printf("*");
              return -1;
        }
         delay();
    }
    //printf(".");
    return 0;
}


/**********************************************************************************************/
/* NAME :    flashWrite                                                                       */
/* FUNCTION: write data to flash                                                              */
/**********************************************************************************************/
int flashWrite(UINT16 *base,UINT16 *flashAddr, UINT8 *buffer, ULONG length){
    int cLength;
    //unsigned int status;
    unsigned short *gBuffer;
    UINT16 *p;
    p = flashAddr;
    gBuffer = (unsigned short *) buffer;
    cLength = 0;
    while(1){
    	  //*(volatile UINT16 *)(0x10000000) = 0x60;*/
    	  //*(volatile UINT16 *)(0x10000000) = 0xD0;
    	   
    	  
        *((volatile UINT16 *)0x10000000 + 0x555) = 0xAA;   
        *((volatile UINT16 *)0x10000000 + 0x2AA) = 0x55;
        *((volatile UINT16 *)0x10000000 + 0x555) = 0xA0;
        //*p = *gBuffer;
        *p = 0x55AA               ;
        delay();

        //check_busy(p,20000);
        //printf(".");
        p += 1;
        cLength += 1;
        gBuffer += 1;
        if(cLength >= (length/2)) break;
        
    }	
    return OK;
}
    
/**********************************************************************************************/
/* NAME :    flashSectorErase                                                                 */
/* FUNCTION: erase a sector                                                                   */
/* PARAMETER:Base : flash chip start address will be write erase sector commmand              */
/*           *pSector : will be erase sector number                                           */
/**********************************************************************************************/
int flashSectorErase(UINT16* Base ,UINT16 *pSector){
   // int i;
    unsigned int status;
    volatile UINT16 *flashPtr = pSector;
    
    *((volatile UINT16 *)0x10000000 + 0x555) = 0xAA;
    *((volatile UINT16 *)0x10000000 + 0x2AA) = 0x55;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0x80;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0xAA;
    *((volatile UINT16 *)0x10000000 + 0x2AA) = 0x55;
    *(volatile UINT16 *)flashPtr = 0x30;	
    
    while(1){
         status = *((volatile UINT16 *)0x10000000);
         //check_busy((UINT16*) 0x10000000,0x1000);
    }
    return OK;
} 
void reset_flash(void){
	    UINT16 val;
      *((volatile UINT16 *)0x10000000) = 0xF0;
      delay();
      val = *((volatile UINT16 *)0x10000000);
}
UINT32 ReadId(void){
	  UINT32  uTemp;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0xAA;
	  *((volatile UINT16 *)0x10000000 + 0x2AA) = 0x55;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0x90;

	  uTemp = *((volatile UINT16 *)0x10000000 + 0x00);
    uTemp = uTemp<<16;
    uTemp += *((volatile UINT16 *)0x10000000 + 0x01);
        
    reset_flash();
	  return uTemp;
	    
}
/**********************************************************************************************/
/* NAME :    flashChipErase                                                                   */
/* FUNCTION: erase a flash chip                                                               */ 
/* PARAMETER:no                                                                               */
/**********************************************************************************************/
int flashChipErase(void){
    *((volatile UINT16 *)0x10000000 + 0x555) = 0xAA;	
    *((volatile UINT16 *)0x10000000 + 0x2AA) = 0x55;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0x80;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0xAA;
    *((volatile UINT16 *)0x10000000 + 0x2AA) = 0x55;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0x10;
    check_busy((volatile UINT16 *)0x10000000,20000000);
    return OK;
}

void flash_unlock_seq(void){
    *((volatile UINT16 *)0x10000000 + 0xAAA) = 0xAA;	
    *((volatile UINT16 *)0x10000000 + 0x555) = 0x55;
}

void enter_secode(void){
    *((volatile UINT16 *)0x10000000 + 0x555) = 0xAA;	
    *((volatile UINT16 *)0x10000000 + 0x2AA) = 0x55;
    *((volatile UINT16 *)0x10000000 + 0x555) = 0x88;
  
}
	

⌨️ 快捷键说明

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