📄 main.c
字号:
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h" // 03.11.27 junon
#include "mmu.h" // 03.11.27 junon
#include "MemoryTest.h"
#include "Nand.h"
#if USE_MAIN
#include <stdio.h>
#endif
#include "Userlib.h"
#include "HPI16.h"
#define DOWNLOAD_ADDRESS 0x30000000
void (*run)(void)=(void (*)(void))(DOWNLOAD_ADDRESS);
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Clk0_Enable(int clock_sel);
void Clk1_Enable(int clock_sel);
void Clk0_Disable(void);
void Clk1_Disable(void);
void copy_files(U32 startblock,U32 num,U32 targetaddr);
void Test_Nand_Read(void);
void Test_Erase_Read(void);
void Test_Nand_write(void);
void NF8_Block_Erase(U32 block);
void NF8_Page_Write(U32 block,U32 page,U32 data);
extern void Calc_Clock(int print_msg);
extern U32 Mdiv, Pdiv, Sdiv, Fclk, Hclk, Pclk, Hdivn, Pdivn, Hclk_Ratio, Pclk_Ratio, Ref_Cnt;
//static int NF8_IsBadBlock(U32 block)
extern void HPI_ISR_function(void);
void Test_Nand_write(void)
{
U32 block;
U32 page;
U32 data = 0x55;
U32 startblock;
U32 endblock;
U32 bad_block = 0;
Uart_Printf("Nand write start");
Uart_Printf("Please enter the start block,don't less than 10\n");
startblock = Uart_GetIntNum();
Uart_Printf("Please enter the end block:\n");
endblock = Uart_GetIntNum();
for(block=startblock;block<endblock;block++)
{
if(IsBadBlock(block)==OK)
{
NF8_Block_Erase(block);
for(page = 0;page<32;page++)
{
if(data == 0x55) data = 0xaa;
if(data == 0xaa) data = 0x55;
NF8_Page_Write(block,page,data);
//err_count += NF8_Page_Read(block,page); //读一个page
}
}
else {
bad_block++;
Uart_Printf("Block %d is bad block\n",block);
}
}
}
void Test_Nand_Read(void)
{
U32 block,page;
int err_count =0;
int bad_block = 0;
int temp;
int datacount = 0;
Uart_Printf("Nand Flash test start\n");
for(block=0;block<4096;block++)
{ Uart_Printf(" B:%4d ",block);
//if(IsBadBlock(block)==OK)
// {
for(page = 0;page<32;page++)
{ // Uart_Printf("\n");
//Uart_Printf("Page:%d\n",page);
temp = NF8_Page_Read(block,page);
if(temp == 1) Uart_Printf("*"); //wu shu ju
else Uart_Printf("D");
//Uart_Printf("\n");
}
// }
// else {
// bad_block++;
// Uart_Printf("Block %d is bad block\n",block);
// }
//if(datacount>0) Uart_Printf("%4d ",block);
//if(block %40 ==29) Uart_Printf("\n");
if(block%3 ==2)Uart_Printf("\n");
}
Uart_Printf("\n");
Uart_Printf("ERROR:%d\n",err_count);
Uart_Printf("Bad Block:%d\n",bad_block);
Uart_Printf("END\n");
}
/*
void Test_Nand_Read(void)
{
U32 block,page;
int err_count =0;
int bad_block = 0;
int temp;
int datacount = 0;
Uart_Printf("Nand Flash test start\n");
for(block=0;block<4095;block++)
{ //Uart_Printf(" B:%4d ",block);
//if(IsBadBlock(block)==OK)
// {
for(page = 0;page<32;page++)
{
temp = NF8_Page_Read(block,page);
if(temp == 0) datacount++;
}
// }
// else {
// bad_block++;
// Uart_Printf("Block %d is bad block\n",block);
// }
if(datacount>0) Uart_Printf("%4d ",block);
if(block %40 ==29) Uart_Printf("\n");
//if(block%3 ==2)Uart_Printf("\n");
}
Uart_Printf("\n");
Uart_Printf("ERROR:%d\n",err_count);
Uart_Printf("Bad Block:%d\n",bad_block);
Uart_Printf("END\n");
}
*/
void Test_Erase_Read(void)
{
U32 startblock,endblock;
U32 block;
U32 bad_block = 0;
Uart_Printf("Nand erase start");
Uart_Printf("Please enter the start block,don't less than 10\n");
startblock = Uart_GetIntNum();
Uart_Printf("Please enter the end block:\n");
endblock = Uart_GetIntNum();
for(block=startblock;block<endblock;block++)
{
NF8_Block_Erase(block);
/*
if(IsBadBlock(block)==OK)
{
NF8_Block_Erase(block);
}
else {
bad_block++;
Uart_Printf("Block %d is bad block\n",block);*/
}
// }
//Uart_Printf("ERROR:%d\n",err_count);
Uart_Printf("Bad Block:%d\n",bad_block);
Uart_Printf("END\n");
}
void xmain(void)
{
int i,j, voltage=120;
unsigned int mpll_val;
int count = 10;
long HPI_count=0xfff;
int mode ;
// GPIO port init.
Port_Init();
rGPJDAT = (0<<12)|(0<<11);
rGPJDAT = (0<<12)|(0<<11)|(1<<8);
Led_Display(0xf);
// MMU init. I/D cache on.
MMU_Init();
Led_Display(0x1);
Led_Display(0x2);
Calc_Clock(0);
UPDATE_REFRESH(Hclk);
// ISR init
Isr_Init();
Uart_Init(0, 115200);
Uart_Select(0);
Uart_TxEmpty(0);
// timer setting for delay 100us unit.
//Check whether or not the POWER_OFF wake-up.
Delay(0); //calibrate Delay()
//Turn on LCD.
//PWR_Lcd_Tft_16Bit_240320_On();
//Check_SleepWakeUp(); //It's needed only for sleep mode test.
//Save the wasted power consumption on GPIO.
//rIISPSR=(2<<5)|(2<<0); //IIS_LRCK=44.1Khz @384fs,PCLK=50Mhz.
// Set I/O strength control.
rDSC0 = (0<<31)|(0x3<<8)|(0xff<<0);//////////////////////////////////////////////////////////
//rDSC0 = (0<<31)|(0x0<<8)|(0x00<<0);
// nEN_DSC [31] : 0:I/O drive strength enable, 1:Disable
// DSC_ADR [9:8] : Addr drive strength, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_DATA [7:0] : DATA drive strength, 0:12mA, 1:10mA, 2:8mA, 3:6mA
rDSC1 = (0x3<<28)|(0x3<<26)|(0xfffff<<0);////////////////////////////////////////////
//rDSC1 = (0x0<<28)|(0x0<<26)|(0x00000<<0);
// DSC_SCK1 [29:28] : SCLK1, 0:16mA, 1:12mA, 2:8mA, 3:6mA
// DSC_SCK0 [27:26] : SCLK0, 0:16mA, 1:12mA, 2:8mA, 3:6mA
// DSC_SCKE [25:24] : SCLKE, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_SDR [23:22] : nRAS/nCAS, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_NFC [21:20] : Nand flash(nFCE,nFRE,nFWE,CLE,ALE), 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_BE [19:18] : nBE[3:0], 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_WOE [17:16] : nBE[3:0], 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS7 [15:14] : nGCS7, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS6 [13:12] : nGCS6, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS5 [11:10] : nGCS5, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS4 [9:8] : nGCS4, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS3 [7:6] : nGCS3, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS2 [5:4] : nGCS2, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS1 [3:2] : nGCS1, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_CS0 [1:0] : nGCS0, 0:10mA, 1:8mA, 2:6mA, 3:4mA
#if 0
Delay(0);
voltage=110;
Max1718_Set(voltage); // set proper voltage after clock changed.
Delay(1);
#if FIN==12000000 //When 12MHz.
ChangeUPllValue(56,2,2); // 48MHz
for(i=0; i<7; i++);
ChangeClockDivider(13,12);
ChangeMPllValue(68,1,1); //2440x
#else // else xtal_in=16.9344MHz.
ChangeUPllValue(60,4,2); // 48MHz
for(i=0; i<7; i++);
ChangeClockDivider(13,12);
//ChangeMPllValue(118,2,2); //265Mhz
ChangeMPllValue(97,1,2); //295Mhz
//ChangeMPllValue(110,3,1); //398Mhz
//ChangeMPllValue(120,2,1); //531Mhz
#endif
#endif
Uart_Printf("uDSC0/1:%x,%x\n", rDSC0, rDSC1);
/////////////////////////////////////// start testprogram /////////////////////////////////////
Uart_Printf("\n\n+---------------------------------------------+\n");
Uart_Printf( "| S3C2440A BootLoader ver 1.0 May 2009. |\n");
Uart_Printf( "+---------------------------------------------+\n");
Uart_Printf("[CPU ID=%xh]\n", rGSTATUS1);
Uart_Printf("[Core voltage: %4.2fV]\n", (float)voltage/100);
Uart_Printf("[XTAL in = %6.4f]\n", (float)FIN/MEGA);
Uart_Printf("[Fclk:Hclk:Pclk]=[%4.1f:%4.1f:%4.1f]Mhz\n", (float)Fclk/MEGA, (float)Hclk/MEGA, (float)Pclk/MEGA);
Uart_Printf("[Uclk=%4.1fMhz]\n", (float)UCLK/MEGA);
Uart_Printf("\n");
//Uart_Printf("[rPRIORITY=0x%x]\n", rPRIORITY);
//rCLKCON = (rCLKCON&0xf) |(0x0<<16)|(0x2<<12)|(0x4<<8)|(0x0<<4); // for test
//Uart_Printf("[CLKCON=%x]\n", rCLKCON);
Uart_Printf("[rSTATUS2=0x%x]\n", rGSTATUS2);
Uart_Printf("[rSTATUS3=0x%x]\n", rGSTATUS3);
Uart_Printf("[rSTATUS4=0x%x]\n", rGSTATUS4);
Uart_Printf("[rSRCPND=0x%x]\n", rSRCPND);
Uart_Printf("[rINTPND=0x%x]\n", rINTPND);
// CLKOUT0/1 select.
//Uart_Printf("CLKOUT0:MPLL in, CLKOUT1:RTC clock.\n");
Clk0_Enable(2); // 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0///////////LZY 2007.10.16屏蔽了 CLKOUT0/1。
Clk1_Enable(3); // 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1///////////LZY 2007.10.16
//Clk0_Disable();
//Clk1_Disable();
Uart_Printf("\n\n");
Uart_Printf("Please enter U to start USB\n");
for(j=0;j<10;j++)
{
Uart_Printf("*");
// Delay(8000000);
if(rUTRSTAT0 & 0x1) //UART
{
i=RdURXH0();
if((i=='U')||(i=='u'))
{ //
// Uart_Printf("\nDownload USB Tansmit image\n");
Uart_Printf("Download USB Tansmit image......");
Uart_Printf("Copy files complete!\n");
// Run_USBMON();
}
}
}
Uart_Printf("\n");
//Test_Nand_Read();
//copy_files(8,2,DOWNLOAD_ADDRESS);
//run();
/*-----------------TEST FJ 2009030-----------------------*/
while(1)
{
Uart_Printf("*************S3C2440A Hardware Test****************\n\n\n");
Uart_Printf("1.SD Test\n");
Uart_Printf("2.Nand Test\n");
Uart_Printf("3.Copy Test\n");
Uart_Printf("4.Nand Read Test\n");
Uart_Printf("5.Nand erase Test\n");
Uart_Printf("6.Nand Write Test\n");
Uart_Printf("Press -1 to exit!\n");
Uart_Printf("Select test mode:");
mode = Uart_GetIntNum();
Uart_Printf("\n\n\n");
switch(mode)
{
case 1:SD_Test(); break; //SD
case 2:Test_Nand(); break;
case 3:Copy_Test(); break;
case 4:Test_Nand_Read(); break;
case 5:Test_Erase_Read(); break;
case 6:Test_Nand_write(); break;
default:break;
}
Uart_Printf("\n\n\n");
//NF_Test(); //NF
//DSP_Test(); //DSP
//Copy_Test();
//NF_WR_Test ();
}
/* ---------------------------------------------------------*/
Uart_Printf("\n\n");
/// while(HPI_count--)
//{
//HPI_ISR_function();//10.18.2007 LZY
//HPI16_Test();
//}
}
/////////////////////////////////////
//===================================================================
void Isr_Init(void)
{
pISR_UNDEF = (unsigned)HaltUndef;
pISR_SWI = (unsigned)HaltSwi;
pISR_PABORT = (unsigned)HaltPabort;
pISR_DABORT = (unsigned)HaltDabort;
rINTMOD = 0x0; //All=IRQ mode
// rINTCON=0x5; //Non-vectored,IRQ enable,FIQ disable
rINTMSK = BIT_ALLMSK; //All interrupt is masked.
rINTSUBMSK = BIT_SUB_ALLMSK; //All sub-interrupt is masked. <- April 01, 2002 SOP
// rINTSUBMSK = ~(BIT_SUB_RXD0); //Enable Rx0 Default value=0x7ff
// rINTMSK = ~(BIT_UART0); //Enable UART0 Default value=0xffffffff
// pISR_UART0=(unsigned)RxInt; //pISR_FIQ,pISR_IRQ must be initialized
}
//===================================================================
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception.\n");
while(1);
}
//===================================================================
void HaltSwi(void)
{
#if !SEMIHOSTING
Uart_Printf("SWI exception!!!\n");
while(1);
#endif
}
//===================================================================
void HaltPabort(void)
{
Uart_Printf("Pabort exception.\n");
while(1);
}
//===================================================================
void HaltDabort(void)
{
Uart_Printf("Dabort exception.\n");
while(1);
}
void Clk0_Enable(int clock_sel)
{ // 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
rMISCCR = rMISCCR&~(7<<4) | (clock_sel<<4);
rGPHCON = rGPHCON&~(3<<18) | (2<<18);
}
void Clk1_Enable(int clock_sel)
{ // 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1
rMISCCR = rMISCCR&~(7<<8) | (clock_sel<<8);
rGPHCON = rGPHCON&~(3<<20) | (2<<20);
}
void Clk0_Disable(void)
{
rGPHCON = rGPHCON&~(3<<18); // GPH9 Input
}
void Clk1_Disable(void)
{
rGPHCON = rGPHCON&~(3<<20); // GPH10 Input
}
void copy_files(U32 startblock,U32 num,U32 targetaddr)
{
U32 block;
U32 page = 0;
U32 i,j;
U32 *copypt;
U32 *buffer;
copypt = (U32 *)targetaddr;
block = startblock;
for(i=0;i<num;)
{
if(IsBadBlock(block)==OK)
{ for(page = 0;page<32;page++)
{
buffer = (U32 *)COPY_BUFFER_ADDR;
NF8_Page_Read(block,page); //读一个page
for(j=0;j<128;j++) //写一个page 1 page= 512 byte = 128 word
{
(*(volatile U32 *)(copypt)) = (*(volatile U32 *)(buffer));
copypt++;
buffer++;
}
}
block++;
i++;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -