📄 u2440mon.c
字号:
/****************************************************************
NAME: u2440mon.c
DESC: u2440mon entry point,menu,download
HISTORY:
Mar.25.2002:purnnamu: S3C2400X profile.c is ported for S3C2410X.
Mar.27.2002:purnnamu: DMA is enabled.
Apr.01.2002:purnnamu: isDownloadReady flag is added.
Apr.10.2002:purnnamu: - Selecting menu is available in the waiting loop.
So, isDownloadReady flag gets not needed
- UART ch.1 can be selected for the console.
Aug.20.2002:purnnamu: revision number change 0.2 -> R1.1
Sep.03.2002:purnnamu: To remove the power noise in the USB signal, the unused CLKOUT0,1 is disabled.
****************************************************************/
#define GLOBAL_CLK 1//hzh
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "2440slib.h"
#include "mmu.h"
#include "profile.h"
#include "memtest.h"
#include "usbmain.h"
#include "usbout.h"
#include "usblib.h"
#include "2440usb.h"
#include "norflash.h"
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Lcd_Off(void);
void WaitDownload(void);
void Menu(void);
void ClearMemory(void);
void Clk0_Enable(int clock_sel);
void Clk1_Enable(int clock_sel);
void Clk0_Disable(void);
void Clk1_Disable(void);
//#define DOWNLOAD_ADDRESS _RAM_STARTADDRESS
volatile U32 downloadAddress;
void (*restart)(void)=(void (*)(void))0x0;
//void (*run)(void); //don't use gloable variable, hzh!!!
volatile unsigned char *downPt;
volatile U32 downloadFileSize;
volatile U16 checkSum;
volatile unsigned int err=0;
volatile U32 totalDmaCount;
volatile int isUsbdSetConfiguration;
int download_run=0;
U32 tempDownloadAddress;
//int menuUsed=1;//始终显示菜单,feipeng
int menuUsed=0;//按键触发显示菜单,feipeng
extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
int consoleNum;
/*************************************************************/
#include "bootpara.h"
void LcdDisplay(void);
int write_24c02(U8 *pBuf);
int read_24c02(U8 *pBuf);
int find_camera(void);
void Led_Test(void);
void comdownload(void);
U32 GetFlashID(void);
int SectorProg(U32 begin, U16 *data, U32 size);
int RelocateNKBIN(U32 img_src, U32 *pStart, U32 *pLength, U32 *pLaunch);
void NandErase(void);
void NandWrite(void);
void NandLoadRun(void);
#define printf Uart_Printf
#define DM9000_BASE 0x20000300
#define DM9000_DATA_OFFSET 4
void mdelay(int ms)
{
U32 val = (PCLK>>3)/1000-1;
rTCFG0 &= ~(0xff<<8);
rTCFG0 |= 3<<8; //prescaler = 3+1
rTCFG1 &= ~(0xf<<12);
rTCFG1 |= 0<<12; //mux = 1/2
/* while(ms--) {
rTCNTB3 = val;
rTCMPB3 = val>>1; // 50%
rTCON &= ~(0xf<<16);
rTCON |= 3<<16; //one shot, inv-off, update TCNTB3&TCMPB3, start timer 3
rTCON &= ~(2<<16); //clear manual update bit
while(rTCNTO3);
}*/
rTCNTB3 = val;
rTCMPB3 = val>>1; // 50%
rTCON &= ~(0xf<<16);
rTCON |= 0xb<<16; //interval, inv-off, update TCNTB3&TCMPB3, start timer 3
rTCON &= ~(2<<16); //clear manual update bit
while(ms--) {
while(rTCNTO3>=val>>1);
while(rTCNTO3<val>>1);
};
}
static U8 dm9000_ior(int reg)
{
*(volatile U8 *)DM9000_BASE = reg;
return *(volatile U8 *)(DM9000_BASE+DM9000_DATA_OFFSET);
}
static void rd_dm9000_id(void)
{
U16 id;
id = dm9000_ior(0x28) | (dm9000_ior(0x29)<<8);
printf("read dm9000 vid = 0x%x\n", id);
id = dm9000_ior(0x2a) | (dm9000_ior(0x2b)<<8);
printf("read dm9000 pid = 0x%x\n", id);
id = dm9000_ior(0x8) | (dm9000_ior(0x9)<<8);
printf("read dm9000 reg(0x09,0x08) = 0x%x\n", id);
printf("dm9000 isr = 0x%x\n", dm9000_ior(0xfe));
}
static void buzzer(int freq, int ms)
{
rGPBCON &= ~3; //set GPB0 as tout0, pwm output
rGPBCON |= 2;
rTCFG0 &= ~0xff;
rTCFG0 |= 15; //prescaler = 15+1
rTCFG1 &= ~0xf;
rTCFG1 |= 2; //mux = 1/8
rTCNTB0 = (PCLK>>7)/freq;
rTCMPB0 = rTCNTB0>>1; // 50%
rTCON &= ~0x1f;
rTCON |= 0xb; //disable deadzone, auto-reload, inv-off, update TCNTB0&TCMPB0, start timer 0
rTCON &= ~2; //clear manual update bit
mdelay(ms);
rGPBCON &= ~3; //set GPB0 as output
rGPBCON |= 1;
rGPBDAT &= ~1;
}
static U32 autorun_10ms;
static U16 autorun_ds;//禁止定时,feipeng
static U16 autorun_trig;//定时到,则autorun_trig=1,feipeng
static __irq void autorun_proc(void)//Timer4定时中断响应函数,feipeng
{
ClearPending(BIT_TIMER4);
if(autorun_ds)//中断屏蔽,feipeng
DisableIrq(BIT_TIMER4);
autorun_10ms--;
if(!autorun_10ms) {
DisableIrq(BIT_TIMER4);
//CLR_IF(); //in irq service routine, irq is disabled
autorun_trig = 1;
//NandLoadRun();
}
}
static void init_autorun_timer(int sec)//定时子程序,用的Timer4,feipeng
{
U32 val = (PCLK>>4)/100-1;
autorun_10ms = sec*100;
pISR_TIMER4 = (U32)autorun_proc;//中断响应函数指向中断向量,feipeng
rTCFG0 &= ~(0xff<<8);//rTCFG0[8-15]位置0,feipeng
rTCFG0 |= 3<<8; //prescaler = 3+1,//rTCFG0[8][9][10]位置1,prescaler=8?feipeng
rTCFG1 &= ~(0xf<<16);//rTCFG1[16-19]位置0,feipeng
rTCFG1 |= 1<<16; //mux4 = 1/4,//rTCFG1[16]位置1,feipeng
rTCNTB4 = val;//count buffer register,feipeng
rTCON &= ~(0xf<<20);//rTCON[20][21][22]位置0,其他位不变,feipeng
//TCON BIT [22] [21] [20]
//Description auto reload manual update start/stop
//Status 0=One-shot 0=no operation 0=stop
rTCON |= 7<<20; //interval, inv-off, update TCNTB4&TCMPB4, start timer 4
//TCON BIT [22] [21] [20]
//Description auto reload manual update start/stop
//Status 1=Interval mode 1=update TCNTB4 1=start
rTCON &= ~(2<<20); //clear manual update bit//manual update=no operation,feipeng
EnableIrq(BIT_TIMER4);//开Timer4的中断,feipeng
}
static U32 cpu_freq;
static U32 UPLL;
static void cal_cpu_bus_clk(void)//计算CPU总线时钟
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -