📄 44btest.c
字号:
#include "def.h"
#include "44b.h"
#include "utils.h"
#define BAUD_RATE 115200
volatile char which_int_key = 0 ;
void __irq Key_Interrupt(void)
{
which_int_key = rEXTINTPND ;
rEXTINTPND = 0xf ; //clear EXTINTPND reg.
rI_ISPC = BIT_EINT4567 ; //clear pending_bit
rPCONG = rPCONG & (~(0x3f<<10)); //GPC567 is input
switch(which_int_key)
{
case 1:
printf("\nEINT4 had been occured...\n");
LedSet(0x2);
which_int_key=0;
break;
case 2:
printf("\nEINT5 had been occured...\n");
LedSet(0x4);
which_int_key=0;
break;
case 4:
printf("\nEINT6 had been occured...\n");
LedSet(0x8);
which_int_key=0;
break;
case 8:
printf("\nEINT7 had been occured...\n");
LedSet(0x1);
which_int_key=0;
break;
default :
break;
}
while( (rPDATG&0x00e0) != 0x00e0 ) ;
Delay( 50 ) ; //
rPCONG = rPCONG | ( 0x3f<<10 ); //EINT7~5
}
void HaltUndef(void)
{
printf("Undefined instruction exception!!!\n");
while(1)
{
LedSet( 0x00 ) ; //
Delay(500) ; //
LedSet( 0x0f ) ; //
Delay(500) ; //
}
}
void HaltSwi(void)
{
printf("SWI exception!!!\n");
while(1)
{
LedSet( 0x00 ) ; //
Delay(500) ; //
LedSet( 0x0f ) ; //
Delay(500) ; //
}
}
void HaltPabort(void)
{
printf("Pabort exception!!!\n");
while(1)
{
LedSet( 0x00 ) ; //
Delay(500) ; //
LedSet( 0x0f ) ; //
Delay(500) ; //
}
}
void HaltDabort(void)
{
printf("Dabort exception!!!\n");
while(1)
{
LedSet( 0x00 ) ; //
Delay(500) ; //
LedSet( 0x0f ) ; //
Delay(500) ; //
}
}
void Isr_Init(void)
{
pISR_UNDEF=(unsigned)HaltUndef;
pISR_SWI =(unsigned)HaltSwi;
pISR_PABORT=(unsigned)HaltPabort;
pISR_DABORT=(unsigned)HaltDabort;
rINTMSK = BIT_GLOBAL; // All interrupt is masked.
rINTCON = 0x5 ; //无向量中断模式
rINTMOD = 0x0 ; //All=IRQ mode
}
void Eint567_Test( void )
{
printf( "\nInterrupt Test!\n" );
printf("\n\n注意由于本项测试使用了中断,所以必须将本项目的目标代码烧写入Flash的0地址\n");
printf("这样Flash中才有中断向量,不过只需要烧入一次就行了,以后JTAG调试或网口下载运行本程序就没有问题了\n");
printf("可以使用netload或者是comload下载本目标代码到SDRAM,然后用Prog 0烧写代码到Flash(不覆盖0地址跳转指令)\n\n");
pISR_EINT4567 = (unsigned)Key_Interrupt ;
rINTCON = 0x5 ; //无向量中断模式
rINTMOD = 0x0 ; //All=IRQ mode
rPCONG = rPCONG | ( 0x3f<<10 ); //EINT7~5
rPUPG = rPUPG & (~(7<<5)) ; //pull up resister is enable
// rEXTINT = rEXTINT & (~(0xfff<<20)) ; //EINT567低电平触发中断
pISR_EINT4567 = (unsigned)Key_Interrupt ;
rINTMSK = ~( BIT_GLOBAL | BIT_EINT4567 ) ; //start INT
printf( "\nPlease press the button key1,key2,key3,key4! Press ESC to Exit!\n" );
while( !( kbhit && (getkey()==ESC_KEY) ) )
{
LedSet(0x05); //LED点亮/熄灭状态设置
Delay(160);
LedSet(0x0a); //LED点亮/熄灭状态设置
Delay(160);
}
rINTMSK = BIT_GLOBAL ; //disable INT
}
void LedDisp(void)
{
LedSet(0x08); //LED点亮/熄灭状态设置
Delay(150);
LedSet(0x04); //LED点亮/熄灭状态设置
Delay(150);
LedSet(0x02); //LED点亮/熄灭状态设置
Delay(150);
LedSet(0x01); //LED点亮/熄灭状态设置
Delay(150);
LedSet(0x02); //LED点亮/熄灭状态设置
Delay(150);
LedSet(0x04); //LED点亮/熄灭状态设置
Delay(150);
LedSet(0x08); //LED点亮/熄灭状态设置
Delay(150);
LedSet(0x00); //LED点亮/熄灭状态设置
}
TIME_STRUC SysTime;
char *WeekDay[7] = {"MON", "TUES", "WED", "THURS","FRI", "SAT", "SUN"};
void Main(void)
{
SystemClockInit();
TimerInit(1000);
MemCfgInit();
PortInit();
Isr_Init();
CacheDisable();
CacheFlush();
CacheEnable();
SerialSwitch(0);
SerialChgBaud(BAUD_RATE);
ShowBootInfo();
printf("Build date : %s--%s\n", __DATE__, __TIME__);
printf("Serial baud : %d\n", BAUD_RATE);
printf("CPU clock is %dHz, Master clock is %dHz\n", GetCpuClock(), GetMasterClock());
RtcGetTime(&SysTime);
printf("Current date is %x-%x-%x [%s]\n", SysTime.year, SysTime.month, SysTime.day, WeekDay[(SysTime.weekday-1U)%7U]);
printf("Current time is %2x:%2x:%2x\n", SysTime.hour, SysTime.min, SysTime.sec);
while(1)
{
U16 i, sel;
putch('\n');
for(i=0; cmd_menu[i].test_func; i++)
{
printf("%d : %s\n", i, cmd_menu[i].string);
}
while(!kbhit())
LedSet(GetKeyStatus());
sel = Uart_GetIntNum_GJ() ;
printf( "\n\t you select is %d\n\n", sel );
if(sel<i)
(*cmd_menu[sel].test_func)();
}
}
#define DFT_DOWNLOAD_ADDR 0x0c400000
U32 download_addr, download_len;
//中断入口内容不可确定,不要用中断
void LoadFromUart(void)
{
int i, size;
unsigned short dnCS, CheckSum;
unsigned char *buf;
unsigned char RxTmp[8];
void (*fun)(void);
download_addr = DFT_DOWNLOAD_ADDR;
buf = (unsigned char *)download_addr;
printf("Now download file from uart0 to 0x%x...\n", download_addr);
i = 0;
while(i<4)
RxTmp[i++] = getch();
i = 0;
size = *(unsigned long *)RxTmp - 4;
while(i<size)
buf[i++] = getch();
download_len = size-2;
dnCS = (buf[size-1]<<8)|buf[size-2];
CheckSum = 0;
for(size -= 3; size>=0; size--)
CheckSum += buf[size];
if(dnCS!=CheckSum) {
// printf("get CS=0x%08x, cal CS=0x%08x\n", dnCS, CheckSum);
puts("\nCheckSum error!\n");
download_len = 0;
} else {
printf("\nReceived %x bytes success\n", download_len);
puts("Do you want to run it?");
if(getyorn()) {
fun = (void (*)(void))download_addr;
CacheDisable();
CacheFlush();
(*fun)();
}
}
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -