|
TQ2440看门狗实验 ,希望大家喜欢!!!!!
/****************************************************************
NAME: u2440mon.c
DESC: u2440mon entry point,menu,download
****************************************************************/
#define GLOBAL_CLK 1
#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"
extern char Image$$RO$$Limit[];
extern char Image$$RO$$Base[];
extern char Image$$RW$$Limit[];
extern char Image$$RW$$Base[];
extern char Image$$ZI$$Limit[];
extern char Image$$ZI$$Base[];
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void ClearMemory(void);
void Clk0_Enable(int clock_sel);
void Clk1_Enable(int clock_sel);
void Clk0_Disable(void);
void Clk1_Disable(void);
volatile U32 downloadAddress;
void (*restart)(void)=(void (*)(void))0x0;
volatile unsigned char *downPt;
volatile U32 downloadFileSize;
volatile U16 checkSum;
volatile unsigned int err=0;
volatile U32 totalDmaCount;
volatile int isUsbdSetConfiguration;
U32 tempDownloadAddress;
int menuUsed=0;
extern char Image$$RW$$Limit[];
U32 *pMagicNum=(U32 *)Image$$RW$$Limit;
int consoleNum;
static U32 cpu_freq;
static U32 UPLL;
static void cal_cpu_bus_clk(void)
{
U32 val;
U8 m, p, s;
val = rMPLLCON;
m = (val>>12)&0xff;
p = (val>>4)&0x3f;
s = val&3;
//(m+8)*FIN*2 不要超出32位数!
FCLK = ((m+8)*(FIN/100)*2)/((p+2)*(1<<s))*100;
val = rCLKDIVN;
m = (val>>1)&3;
p = val&1;
val = rCAMDIVN;
s = val>>8;
switch (m) {
case 0:
HCLK = FCLK;
break;
case 1:
HCLK = FCLK>>1;
break;
case 2:
if(s&2)
HCLK = FCLK>>3;
else
HCLK = FCLK>>2;
break;
case 3:
if(s&1)
HCLK = FCLK/6;
else
HCLK = FCLK/3;
break;
}
if(p)
PCLK = HCLK>>1;
else
PCLK = HCLK;
if(s&0x10)
cpu_freq = HCLK;
else
cpu_freq = FCLK;
val = rUPLLCON;
m = (val>>12)&0xff;
p = (val>>4)&0x3f;
s = val&3;
UPLL = ((m+8)*FIN)/((p+2)*(1<<s));
UCLK = (rCLKDIVN&8)?(UPLL>>1):UPLL;
}
///////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////
#define WATCH_ENABLE
#define WDT_ENABLE (0x01<<5)
#define WDT_INT_ENABLE (0x01<<2)
#define WDT_RST_ENABLE (0x01<<0)
#define WDT_CLK_SEL (0X3 <<3) /* 1/128 */
#define WDT_PRE_SCALER (0XFF <<8) /* 255 */
volatile unsigned int sec_tick;
/********************************************************************
// Function name : rtc_tick_init
// Parameter : void
// Description : 初始化TICK定时器
// Return : void
// Argument : tick, 设置的TICK频率(时钟滴答的周期为 (1+tick)/128秒)
// Autor & date :
*********************************************************************/
void rtc_tick_init( char tick )
{
rRTCCON = 0x01;
rTICNT = (tick&0x7f)|0x80; /*TICK 中断使能,周期为(1+tick)/128秒*/
rRTCCON = 0x00;
}
/********************************************************************
// Function name : rtc_tick_isr
// Parameter : void
// Description : Tick中断处理程序
// Return : void
// Argument : 时钟滴答1秒中断
// Autor & date :
*********************************************************************/
void __irq rtc_tick_isr(void)
{
ClearPending(BIT_TICK); /*清除时钟滴答中断标志 */
if((sec_tick%10)==0) /* 修改该语句检查复位情况,if((led_index%3)==0) */
{
rWTCNT = 0x1000; /* 重新设置看门狗时间值 */
}
Uart_Printf("into tick \n");
sec_tick++;
}
////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
void Main(void)
{
U8 key;
U32 mpll_val = 0 ;
//U32 divn_upll = 0 ;
#if ADS10
// __rt_lib_init(); //for ADS 1.0
#endif
Port_Init();
Isr_Init();
key = 14;
mpll_val = (92<<12)|(1<<4)|(1);
//init FCLK=400M, so change MPLL first
ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3);
ChangeClockDivider(key, 12);
cal_cpu_bus_clk();
Uart_Init( 0,115200 );
Uart_Select(0);
MMU_Init();
Uart_SendByte('\n');
Uart_Printf("<***************************************>\n");
Uart_Printf(" TQ2440 Test Program\n");
Uart_Printf(" www.embedsky.net\n");
// Uart_Printf(" Build time is: %s %s\n", __DATE__ , __TIME__ );
Uart_Printf("<***************************************>\n");
////////////////////////////
////////////
rINTMOD=0x00;
rtc_tick_init(250);
pISR_TICK=(unsigned)rtc_tick_isr;
ClearPending(BIT_TICK);
EnableIrq(BIT_TICK);
Uart_Printf("TQ2440 Watchdog Test\n");
rWTCNT=0x1000;
rWTCON=WDT_ENABLE|WDT_RST_ENABLE|WDT_CLK_SEL|WDT_PRE_SCALER;
while(1);
}
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);
}
void ClearMemory(void)
{
int memError=0;
U32 *pt;
Uart_Printf("Clear Memory (%xh-%xh):WR",_RAM_STARTADDRESS,HEAPEND);
pt=(U32 *)_RAM_STARTADDRESS;
while((U32)pt < HEAPEND)
{
*pt=(U32)0x0;
pt++;
}
if(memError==0)Uart_Printf("\b\bO.K.\n");
}
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);
}
把TQ自带的裸奔例程的main.c换成以上代码即可。 |
|