📄 target.cpp
字号:
#include "target.h"
#include "ucos_ii.h" /* uC/OS interface */
/********************************************************************************************************
* 外部中断4、5、6、7的中断处理 *
********************************************************************************************************/
volatile char which_int=0;
void EInt4567Isr(void)
{
which_int = rEXTINTPND;
rEXTINTPND = 0xf; //clear EXTINTPND reg.
rI_ISPC = BIT_EINT4567; //clear pending_bit
//while((rPDATG&0xf0) != 0xf0); //按键没有松开就一直等待
//rPCONG |= 0xff00; //GPG4、5、6、7设为中断引脚
}
/********************************************************************************************************
* ARMTargetInit *
* *
* Description: This function initialize an ARM Target board *
* *
* Argument : none *
********************************************************************************************************/
void ARMTargetInit(void)
{
//配置Cache
//rSYSCFG = SYSCFG_0KB ; //使用8K字节的指令缓存
//初始化WATCHDOG
rWTDAT = 0XFFFF;
rWTCON = 0XFF39;
rNCACHBE0=((unsigned int)(Non_Cache_End>>12)<<16)|(Non_Cache_Start>>12);
Port_Init(); //初始化端口
//ChangePllValue( 0x5b, 4, 1 ) ; //设置CPU频率为66M
ChangePllValue( 0x50, 6, 1 ) ; //设置CPU频率为66M
Uart_Init( 0, 115200 ); //设置串口0的速率为115200bps
Uart_Select(1); //选择串口0
ARMInitInterrupts(); //初始化中断,设置中断服务程序
//Delay(0);
}
/********************************************************************************************************
* ARMTargetStart *
* *
* Description: This function start the ARM target running *
* *
* Argument : none *
********************************************************************************************************/
void ARMTargetStart(void) {
ARMInitTimers(); //配置时钟0相关寄存器
ARMInstallSystemTimer(); //时钟0中断使能
}
/********************************************************************************************************
* 中断初始化 *
********************************************************************************************************/
void ARMInitInterrupts(void)
{
// Non-vectored,IRQ disable,FIQ disable
rINTCON = 0x05 ;
//rINTCON = 0;
// All=IRQ mode
rINTMOD = 0x0 ;
// All interrupt is masked.
rINTMSK = BIT_GLOBAL;
rI_ISPC = 0X3FFFFFF;
rEXTINT |= ( ( 2 << 8 ) );
//set interrupt vector routine
// pISR_RESET //reserved
pISR_UNDEF = (unsigned) DebugUNDEF;
pISR_SWI = (unsigned) DebugSWI;
pISR_PABORT = (unsigned) DebugPABORT;
pISR_DABORT = (unsigned) DebugDABORT;
// pISR_RESERVED = (unsigned) BreakPoint; //not used
// pISR_IRQ = (unsigned) 0; //reserved
pISR_FIQ = (unsigned) DebugFIQ;
pISR_ADC= (unsigned) BreakPoint;
pISR_RTC= (unsigned) BreakPoint;
pISR_UTXD1= (unsigned) BreakPoint;
pISR_UTXD0= (unsigned) BreakPoint;
pISR_SIO= (unsigned) BreakPoint;
pISR_IIC= (unsigned) BreakPoint;
pISR_URXD1= (unsigned) BreakPoint;
pISR_URXD0= (unsigned) BreakPoint;
pISR_TIMER5= (unsigned) BreakPoint;
pISR_TIMER4= (unsigned) BreakPoint;
pISR_TIMER3= (unsigned) BreakPoint;
pISR_TIMER2= (unsigned) BreakPoint;
pISR_TIMER1= (unsigned) BreakPoint;
pISR_TIMER0= (unsigned) BreakPoint;
pISR_UERR01= (unsigned) BreakPoint;
pISR_WDT= (unsigned) BreakPoint;
pISR_BDMA1= (unsigned) BreakPoint;
pISR_BDMA0= (unsigned) BreakPoint;
pISR_ZDMA1= (unsigned) BreakPoint;
pISR_ZDMA0= (unsigned) BreakPoint;
pISR_TICK= (unsigned) OSTickISR;
pISR_EINT4567= (unsigned) OSEINT4567ISR;//外部
pISR_EINT3= (unsigned) BreakPoint;
pISR_EINT2= (unsigned) BreakPoint;
pISR_EINT1= (unsigned) BreakPoint;
pISR_EINT0= (unsigned) BreakPoint2;
//pISR_TIMER0= (unsigned) OSTickISR;//操作系统时钟
}
/********************************************************************************************************
* Initialize timer that is used OS *
********************************************************************************************************/
void ARMInitTimers(void)
{
/*
//dead zone=0, pre0= 150
//rTCFG0= 0x00000095;
rTCFG0 = 65;
//all interrupt, mux0= 1/16
//rTCFG1= 0x00000003;
rTCFG1 = 0X0;
//set T0 count
//rTCNTB0= _CLOCK;
rTCNTB0 = 500;
//update T0
rTCON= 0x00000002;
*/
rTICINT = 0X1;
rTCFG0 = ( (32<<16) );
rTCFG1 = 0;
rTCNTB5 = 5000; //5毫秒
rTCON = ( 2 << 24 );
}
/********************************************************************************************************
* start system timer0 *
********************************************************************************************************/
void ARMStartTimer(void)
{
rTICINT = 0X81;
}
/********************************************************************************************************
* enable the interrupt *
********************************************************************************************************/
void ARMInstallSystemTimer(void)
{
//rINTCON = 5;
rINTMSK=~( BIT_TICK | BIT_GLOBAL ); //Default value=0x7ffffff
}
void BreakPoint1()
{
while(1)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
void BreakPoint2()
{
while(1)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
//*******************************************************************************************************
void BreakPoint(void)
{
//Uart_Printf("Enter BreakPoint");
while(1)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
//*******************************************************************************************************
void DebugUNDEF(void)
{
//Uart_Printf("Enter DebugUNDEF");
while(1)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
//*******************************************************************************************************
void DebugSWI(void)
{
//Uart_Printf("Enter DebugSWI");
while(1)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
//*******************************************************************************************************
void DebugPABORT(void)
{
//Uart_Printf("Enter DebugPABORT");
U32 i;
i = 1;
while(i)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
//*******************************************************************************************************
void DebugDABORT(void)
{
//Uart_Printf("Enter DebugDABORT");
U32 i;
i = 1;
while(i)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
//*******************************************************************************************************
void DebugFIQ(void)
{
//Uart_Printf("Enter DebugFIQ");
while(1)
{
Led_Set( 0xf ) ; Delay( 1000 ) ;
Led_Set( 0x0 ) ; Delay( 1000 ) ;
}
}
//*******************************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -