實驗目的:

  熟悉NAND FLASH的讀寫

  學習FLASH基本原理,理解對NAND FLASH的讀寫的過程。

#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"


extern U32 srcAddress;
extern U32 targetBlock; // Block number (0 ~ 4095)
extern U32 targetSize; // Total byte size
extern void InputTargetBlock(void);
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Lcd_Off(void);
void WaitDownload(void);
int Menu(void);


extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
int consoleNum;

void Main(void)
{

#if ADS10
__rt_lib_init(); //for ADS 1.0
#endif

ChangeClockDivider(1,1); // 1:2:4
//ChangeMPllValue(82,2,1); //FCLK=135.0Mhz
ChangeMPllValue(82,1,1); //FCLK=180.0Mhz
//ChangeMPllValue(161,3,1); //FCLK=202.8Mhz

Port_Init();

rGPHCON = rGPHCON&~(0xf<<18)|(0x5<<18);
MMU_Init();
Isr_Init();
if(*pMagicNum!=0x12345678)
consoleNum=0;
else
consoleNum=1;

Uart_Init(0,115200);
Uart_Select(consoleNum);
Delay(0); //calibrate Delay()
Led_Display(0x6);

Uart_Printf("Press Any Key to program nand flash\n");
Uart_Getch();

K9S1208_Program();


while(1)
K9S1208_PrintBlock();


}

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
rINTMSK=BIT_ALLMSK; // All interrupt is masked.


}


void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception!!!\n");
while(1);
}

void HaltSwi(void)
{
Uart_Printf("SWI exception!!!\n");
while(1);
}

void HaltPabort(void)
{
Uart_Printf("Pabort exception!!!\n");
while(1);
}

void HaltDabort(void)
{
Uart_Printf("Dabort exception!!!\n");
while(1);
}