使用普通的Timer中断方式时,Timer中断可以正常运行,但是UDP通信进程无法启动。其中TimerIntrHandler是中断服务程序,打印程序运行时间与从BRAM中读取的数据。
void SetupInterruptSystem(XScuGic *GicInstancePtr,XScuTimer *TimerInstancePtr, u16 TimerIntrId)
{
XScuGic_Config *IntcConfig; //GIC config
Xil_ExceptionInit();
//initialise the GIC
IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);
XScuGic_CfgInitialize(GicInstancePtr, IntcConfig,
IntcConfig->CpuBaseAddress);
//connect to the hardware
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,(Xil_ExceptionHandler)XScuGic_InterruptHandler,GicInstancePtr);
//set up the timer interrupt
XScuGic_Connect(GicInstancePtr, TimerIntrId,(Xil_ExceptionHandler)TimerIntrHandler, (void *)TimerInstancePtr);
//enable the interrupt for the Timer at GIC
XScuGic_Enable(GicInstancePtr, TimerIntrId);
//enable interrupt on the timer
XScuTimer_EnableInterrupt(TimerInstancePtr);
// Enable interrupts in the Processor.
Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ);
}
static void TimerIntrHandler(void *CallBackRef)
{
static int sec = 0; //计数
XScuTimer *TimerInstancePtr = (XScuTimer *) CallBackRef;
XScuTimer_ClearInterruptStatus(TimerInstancePtr);
sec++;
int rev = Xil_In32(XPAR_BRAM_1_BASEADDR);
xil_printf( "The data at %x is %x \r",XPAR_BRAM_1_BASEADDR,rev);
printf("Current program run for %d seconds\n\r",sec); //每秒打印输出一次
}
void timer_init()
{
//Timer test
printf("Timer test...\r\n");
XScuTimer_Config *TMRConfigPtr; //timer config
//printf("------------START-------------\n");
//私有定时器初始化
TMRConfigPtr = XScuTimer_LookupConfig(0);//TIMER_DEVICE_ID);
XScuTimer_CfgInitialize(&Timer, TMRConfigPtr,TMRConfigPtr->BaseAddr);
XScuTimer_SelfTest(&Timer);
//加载计数周期, 私有定时器的时钟为 CPU 的一般, 为 333MHZ,如果计数 1S,加载值为1sx(333x1000x1000)(1/s)-1=0x13D92D3F
XScuTimer_LoadTimer(&Timer, TIMER_LOAD_VALUE);
//自动装载
XScuTimer_EnableAutoReload(&Timer);
//启动定时器
XScuTimer_Start(&Timer);
//set up the interrupts
SetupInterruptSystem(&Intc,&Timer,TIMER_IRPT_INTR);
}
改为进程定时器的方式后,UDP通信进程可以正常启动。DELAY_10_SECONDS与DELAY_1_SECOND是中断时间设置。
#define TIMER_ID 1
#define DELAY_10_SECONDS 10000UL
#define DELAY_1_SECOND 1000UL
#define TIMER_CHECK_THRESHOLD 9
static TimerHandle_t xTimer = NULL;
int main()
{
sys_thread_new("main_thread", (void(*)(void*))main_thread, 0,
THREAD_STACKSIZE, DEFAULT_THREAD_PRIO);
//sleep(10);
const TickType_t x1second = pdMS_TO_TICKS( DELAY_1_SECOND );
xTimer = xTimerCreate( (const char *) "Timer",x1second,pdTRUE,(void *) TIMER_ID,TimerIntrHandler);
configASSERT( xTimer );
xTimerStart( xTimer, 0 );
vTaskStartScheduler();
while(1);
return 0;
}