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

📄 l2_flash.c

📁 台湾凌阳方案300万数码相机源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if(XBYTE[0x2413]!=0x3F) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2413] = 0x00;               
    if(XBYTE[0x2413]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2413] = tmp0;

    //0x2414
    tmp0 = XBYTE[0x2414];
    XBYTE[0x2414] = 0xFF;
    if(XBYTE[0x2414]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2414] = 0x00;               
    if(XBYTE[0x2414]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2414] = tmp0;

    //0x2415
    tmp0 = XBYTE[0x2415];
    XBYTE[0x2415] = 0xFF;
    if(XBYTE[0x2415]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2415] = 0x00;               
    if(XBYTE[0x2415]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2415] = tmp0;

    //0x2416
    tmp0 = XBYTE[0x2416];
    XBYTE[0x2416] = 0xFF;
    if(XBYTE[0x2416]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2416] = 0x00;               
    if(XBYTE[0x2416]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2416] = tmp0;

    //0x2417
    tmp0 = XBYTE[0x2417];
    XBYTE[0x2417] = 0xFF;
    if(XBYTE[0x2417]!=0x3F) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2417] = 0x00;               
    if(XBYTE[0x2417]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2417] = tmp0;

    //0x2421
    tmp0 = XBYTE[0x2421];
    XBYTE[0x2421] = 0xFF;
    if(XBYTE[0x2421]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2421] = 0x00;               
    if(XBYTE[0x2421]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2421] = tmp0;

    //0x2422
    tmp0 = XBYTE[0x2422];
    XBYTE[0x2422] = 0xFF;
    if(XBYTE[0x2422]!=0x01) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2422] = 0x00;               
    if(XBYTE[0x2422]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2422] = tmp0;

    //0x2423
    tmp0 = XBYTE[0x2423];
    XBYTE[0x2423] = 0xFF;
    if(XBYTE[0x2423]!=0x0F) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2423] = 0x00;               
    if(XBYTE[0x2423]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2423] = tmp0;

    //0x2432
    tmp0 = XBYTE[0x2432];
    XBYTE[0x2432] = 0xFF;
    if(XBYTE[0x2432]!=0x07) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2432] = 0x00;               
    if(XBYTE[0x2432]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2432] = tmp0;

    //0x2433
    tmp0 = XBYTE[0x2433];
    XBYTE[0x2433] = 0xFF;
    if(XBYTE[0x2433]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2433] = 0x00;               
    if(XBYTE[0x2433]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2433] = tmp0;

    //0x2434
    tmp0 = XBYTE[0x2434];
    XBYTE[0x2434] = 0xFF;
    if(XBYTE[0x2434]!=0x0F) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2434] = 0x00;               
    if(XBYTE[0x2434]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2434] = tmp0;

    //0x2435
    tmp0 = XBYTE[0x2435];
    XBYTE[0x2435] = 0xFF;
    if(XBYTE[0x2435]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2435] = 0x00;               
    if(XBYTE[0x2435]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2435] = tmp0;

    //0x2436
    tmp0 = XBYTE[0x2436];
    XBYTE[0x2436] = 0xFF;
    if(XBYTE[0x2436]!=0x03) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2436] = 0x00;               
    if(XBYTE[0x2436]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2436] = tmp0;

    //0x2439
    tmp0 = XBYTE[0x2439];
    XBYTE[0x2439] = 0xFF;
    if(XBYTE[0x2439]!=0x01) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2439] = 0x00;               
    if(XBYTE[0x2439]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2439] = tmp0;

    //0x243A
    tmp0 = XBYTE[0x243A];
    XBYTE[0x243A] = 0xFF;
    if(XBYTE[0x243A]!=0x01) error = 1;  //test 0 to 1 toggle
    XBYTE[0x243A] = 0x00;               
    if(XBYTE[0x243A]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x243A] = tmp0;

    //0x2446
    tmp0 = XBYTE[0x2446];
    XBYTE[0x2446] = 0xFF;
    if(XBYTE[0x2446]!=0x03) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2446] = 0x00;               
    if(XBYTE[0x2446]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2446] = tmp0;

    //0x2447
    tmp0 = XBYTE[0x2447];
    XBYTE[0x2447] = 0xFF;
    if(XBYTE[0x2447]!=0x0F) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2447] = 0x00;               
    if(XBYTE[0x2447]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2447] = tmp0;

    //0x2448
    tmp0 = XBYTE[0x2448];
    XBYTE[0x2448] = 0xFF;
    if(XBYTE[0x2448]!=0x01) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2448] = 0x00;               
    if(XBYTE[0x2448]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2448] = tmp0;

    //0x2451
    tmp0 = XBYTE[0x2451];
    XBYTE[0x2451] = 0xFF;
    if(XBYTE[0x2451]!=0x7F) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2451] = 0x00;               
    if(XBYTE[0x2451]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2451] = tmp0;

    //0x2455
    tmp0 = XBYTE[0x2455];
    XBYTE[0x2455] = 0xFF;
    if(XBYTE[0x2455]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2455] = 0x00;               
    if(XBYTE[0x2455]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2455] = tmp0;

    //0x2456
    tmp0 = XBYTE[0x2456];
    XBYTE[0x2456] = 0xFF;
    if(XBYTE[0x2456]!=0x03) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2456] = 0x00;               
    if(XBYTE[0x2456]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2456] = tmp0;

    //0x2457
    tmp0 = XBYTE[0x2457];
    XBYTE[0x2457] = 0xFF;
    if(XBYTE[0x2457]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2457] = 0x00;               
    if(XBYTE[0x2457]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2457] = tmp0;

    //0x2458
    tmp0 = XBYTE[0x2458];
    XBYTE[0x2458] = 0xFF;
    if(XBYTE[0x2458]!=0xFF) error = 1;  //test 0 to 1 toggle
    XBYTE[0x2458] = 0x00;               
    if(XBYTE[0x2458]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x2458] = tmp0;

    //0x24A2
    tmp0 = XBYTE[0x24A2];
    XBYTE[0x24A2] = 0xFF;
    if(XBYTE[0x24A2]!=0x01) error = 1;  //test 0 to 1 toggle
    XBYTE[0x24A2] = 0x00;               
    if(XBYTE[0x24A2]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x24A2] = tmp0;

    //0x24A3
    tmp0 = XBYTE[0x24A3];
    XBYTE[0x24A3] = 0xFF;
    if(XBYTE[0x24A3]!=0x03) error = 1;  //test 0 to 1 toggle
    XBYTE[0x24A3] = 0x00;               
    if(XBYTE[0x24A3]!=0x00) error = 1;  //test 1 to 0 toggle
    XBYTE[0x24A3] = tmp0;
	}

if((TestLevel ==0)||(TestLevel == 2))   // test fmgpio interrupt
  {  
        tmp0 = EA;
		tmp1 = EX0;
      	EA = 0;    //disable interrupt
        EX0 = 0;   //disable interrupt    
		tmp2 = XBYTE[0x2400];
		tmp3 = XBYTE[0x2401];
		tmp4 = XBYTE[0x2405];
        tmp5 = XBYTE[0x2410];

   	    XBYTE[0x2400] = 0x00;
		XBYTE[0x2401] = 0x00;
		XBYTE[0x2418] = 0x00;  // clear fmgpio interrupt
		XBYTE[0x2405] = 0xff;
		XBYTE[0x2410] = 0xff;
		XBYTE[0x2401] = 0xff;
        if(XBYTE[0x2C04]!=0x09) error = 1;
//		if(XBYTE[0x2
		P1 = XBYTE[0x2C04];

		XBYTE[0x2400] = tmp2;
		XBYTE[0x2401] = tmp3;
		XBYTE[0x2405] = tmp4;
        XBYTE[0x2410] = tmp5;

        while(1);

        EA = tmp0;
		EX0 = tmp1;
  }

if((TestLevel ==0)||(TestLevel == 3))
  {  
// NAND test ///////////////////////////////////////////////////////////////////////
 switch(L2K_FMactType)
  {
  case 1:
        if(L2K_FMPageSize == 0)      { blocksize = (ULONG)L2K_FMSize<<12; pagesize = 256;}
	    else if(L2K_FMPageSize == 1) { blocksize = (ULONG)L2K_FMSize<<11; pagesize = 512;}
        else                         { blocksize = (ULONG)L2K_FMSize<<10; pagesize =1024;}

        L2_FlashMode(1,L2K_FMinactType,1);
        L2_NANDInit(1,1);

		// READ ID command 
		L1_ReadNandID(&MarkerID,&DeviceID);
		//PRINT_L2("        L2_TestFlash: MarkerID = %x, DeviceID = %x\n",(USHORT)MarkerID,(USHORT)DeviceID);
        // READ ID command 

		// Erase  
        Addr = 0;
        if(L2K_FMPageSize == 0)      Addr = Addr >> 8;
 	    else if(L2K_FMPageSize == 1) Addr = Addr >> 9;
		else if(L2K_FMPageSize == 2) Addr = Addr >> 10;
		else                         return 0x01;
        for(block=0;block<blocksize;block+=16)
		   {
		   P1 = block;
		   if(L2K_FMSize < 16)
            L1_EraseNandBlock(2,Addr,&Status);
           else
            L1_EraseNandBlock(3,Addr,&Status);
           if(Status != 0xC0) return 0x02;
		   Addr += 16;
		   }
		//PRINT_L2("        L2_TestFlash: Erase Nand Type Flash Success\n");
		// Erase whole flash


        // PREPARE Data in CPU 4K SRAM   
        for(tmp = 0x1C00; tmp<(0x1C00+pagesize) ; tmp++)  
           XBYTE[tmp] = tmp;
        // PREPARE Data in CPU 4K SRAM

        Addr = 0;
        error = 0;
        for(block=0;block<blocksize;block++)
		   {
           P1 = block;
           L2_SetSRAMDMA(0x0C00);
           if(L1_DMAWrNAND(1,8,Addr,1,pagesize)!=0) error = 1;
           tmp = 0x0C00+pagesize;
           L2_SetSRAMDMA(tmp);
           if(L1_DMARdNAND(1,8,Addr,1,pagesize)!=0) error = 1;

           for(tmp = 0x1C00; tmp< (0x1C00+pagesize); tmp++)
             if(XBYTE[tmp+pagesize] != XBYTE[tmp]) error = 1;
           Addr += pagesize;
           }
        //PRINT_L2("        L2_TestFlash: Nand Type Flash data error = %x\n",(USHORT)error);

        break;
 case 2: 
        if(L2K_FMPageSize == 0)      { blocksize = (ULONG)L2K_FMSize<<12; pagesize = 256;}
	    else if(L2K_FMPageSize == 1) { blocksize = (ULONG)L2K_FMSize<<11; pagesize = 512;}
        else                         { blocksize = (ULONG)L2K_FMSize<<10; pagesize =1024;}

        L2_FlashMode(2,L2K_FMinactType,1);
        L2_NANDInit(1,1);


    	// READ ID command 
		L1_ReadNandID(&MarkerID,&DeviceID);
		//PRINT_L2("        L2_TestFlash: MarkerID = %x, DeviceID = %x\n",(USHORT)MarkerID,(USHORT)DeviceID);
        // READ ID command

		// Erase  
        Addr = 0;
        if(L2K_FMPageSize == 0)      Addr = Addr >> 8;
 	    else if(L2K_FMPageSize == 1) Addr = Addr >> 9;
		else if(L2K_FMPageSize == 2) Addr = Addr >> 10;
		else                         return 0x01;
        for(block=0;block<blocksize;block+=16)
		   {
		   P1 = block;
		   if(L2K_FMSize < 16)
            L1_EraseNandBlock(2,Addr,&Status);
           else
            L1_EraseNandBlock(3,Addr,&Status);
           if(Status != 0xC0) return 0x02;
		   Addr += 16;
		   }
		//PRINT_L2("        L2_TestFlash: Erase Nand Type Flash Success\n");
		// Erase whole flash

        // PREPARE Data in CPU 4K SRAM
        for(tmp = 0x1C00; tmp<(0x1C00+pagesize) ; tmp++)  
           XBYTE[tmp] = tmp;
        // PREPARE Data in CPU 4K SRAM

        Addr = 0;
        error = 0;

		//PRINT_L2("hi\n");
        for(block=0;block<blocksize;block++)
		   {
           P1 = block;
           L2_SetSRAMDMA(0x0C00);
           if(L1_DMAWrNAND(1,32,Addr,1,pagesize)!=0) error = 1;
           tmp = 0x0C00+pagesize;
           L2_SetSRAMDMA(tmp);
           if(L1_DMARdNAND(1,32,Addr,1,pagesize)!=0) error = 1;
           for(tmp = 0x1C00; tmp< (0x1C00+pagesize); tmp++)
             if(XBYTE[tmp+pagesize] != XBYTE[tmp]) error = 1;
           Addr += pagesize;

           //PRINT_L2("block = %lx, error =%bx\n",block,error);

           }
        //PRINT_L2("        L2_TestFlash: Nand Type Flash data error = %x\n",(USHORT)error);

        break;
 case 3: 
         #if (CFAIDE)
         L2_FlashMode(3,L2K_FMinactType,1);              // CF 512 bytes/block
   	     L2_CFInit(1,0x09,0x09);
         L2_CFReset(1);                                  // reset CF card
         L2_CardDetect(&Detect);
         //PRINT_L2("        L2_TestFlash: CF inserted? = 8'h%x (1 for inserted,0 for not inserted)\n",(USHORT)Detect);

         if(L2K_FMPageSize == 0)      { blocksize = (ULONG)L2K_FMSize<<12; pagesize = 256;}
	     else if(L2K_FMPageSize == 1) { blocksize = (ULONG)L2K_FMSize<<11; pagesize = 512;}
         else                         { blocksize = (ULONG)L2K_FMSize<<10; pagesize =1024;}

         //PRINT_L2("        L2_TestFlash: block size = 32'h%lx \n",blocksize);

		 Addr = 0;
		 error = 0;

         // PREPARE Data in CPU 4K SRAM
         for(tmp = 0x1C00; tmp<(0x1C00+pagesize) ; tmp++)  
            XBYTE[tmp] = tmp;
         // PREPARE Data in CPU 4K SRAM

		 for (block = 0 ; block < blocksize ; block++)
		    {
			SecNum = (UCHAR)(Addr&0x000000ff);
            CylLow = (UCHAR)(Addr&0x0000ff00>>8);
            CylHigh = (UCHAR)(Addr&0x00ff0000>>16);
		    HS = (UCHAR)(Addr&0x0f000000>>24);
			P1 = block;

            L2_SetSRAMDMA(0x0C00);
		    L1_DMAWrCFIDE(1,HS,CylHigh,CylLow,SecNum,1,pagesize);
            tmp = 0x0C00+pagesize;
            L2_SetSRAMDMA(tmp);
            L1_DMARdCFIDE(1,HS,CylHigh,CylLow,SecNum,1,pagesize);
     
            for(tmp = 0x1C00; tmp< (0x1C00+pagesize); tmp++)
              if(XBYTE[tmp+pagesize] != XBYTE[tmp]) {error = 1; return 0x02;}
			Addr += pagesize;
		    }


         //PRINT_L2("        L2_TestFlash: CF IDE mode data error = 8'h%x\n",(USHORT)error);
         #endif
        break;
 case 4: 
         #if (CFAMEM)
         L2_FlashMode(4,L2K_FMinactType,1);              // CF 512 bytes/sector 
	     L2_CFInit(0,0x09,0x09);
	     L2_CFReset(0);                                  // reset CF card
	     L2_CardDetect(&Detect);
         //PRINT_L2("        L2_TestFlash: CF inserted? = 8'h%x (1 for inserted,0 for not inserted)\n",(USHORT)Detect);


         if(L2K_FMPageSize == 0)      { blocksize = (ULONG)L2K_FMSize<<12; pagesize = 256;}
	     else if(L2K_FMPageSize == 1) { blocksize = (ULONG)L2K_FMSize<<11; pagesize = 512;}
         else                         { blocksize = (ULONG)L2K_FMSize<<10; pagesize =1024;}


         //PRINT_L2("        L2_TestFlash: block size = 32'h%lx \n",blocksize);

         // PREPARE Data in CPU 4K SRAM
         for(tmp = 0x1C00; tmp<(0x1C00+pagesize) ; tmp++)  
            XBYTE[tmp] = tmp;
         // PREPARE Data in CPU 4K SRAM
         
		 Addr = 0;
		 error = 0;
		 for (block = 0 ; block < blocksize ; block++)
		    {
			SecNum = (UCHAR)(Addr&0x000000ff);
            CylLow = (UCHAR)(Addr&0x0000ff00>>8);
            CylHigh = (UCHAR)(Addr&0x00ff0000>>16);
		    HS = (UCHAR)(Addr&0x0f000000>>24);
			P1 = block;

            L2_SetSRAMDMA(0x0C00);
		    L1_DMAWrCFMEM(1,HS,CylHigh,CylLow,SecNum,1,pagesize);
			tmp = 0x0C00+pagesize;
            L2_SetSRAMDMA(tmp);
            L1_DMARdCFMEM(1,HS,CylHigh,CylLow,SecNum,1,pagesize);

            error = 0;
            for(tmp = 0x1C00; tmp< (0x1C00+pagesize); tmp++)
              if(XBYTE[tmp+pagesize] != XBYTE[tmp]) {error = 1; return 0x02;}
			Addr += pagesize;
			}

         //PRINT_L2("        L2_TestFlash: CF memory mode data error = 8'h%x\n",(USHORT)error);
 
         #endif
        break;
 case 5: 
        break;
 case 6: 
        break;
 case 7: 
        break;
 case 8: 
        break;
default: return 0x01; break;
  }
 }

  return 0x00;
}

#endif



⌨️ 快捷键说明

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