?? system_timer.c
字號(hào):
#include "xparameters.h"
#include "xgpio.h"
#include "xtime_1.h"
#include "my_led.h"
#include "xtmrctr_1.h"
#include "xtmrctr.h"
#include "xintc_l.h"
#include "xexception_l.h"
unsigned int j;
void timer_int_handler(void * baseaddr_p)
{
// Add variable declarations here
unsigned int csr;
// Read timer 0 CSR to see if it raised the interrupt
csr = XTmrCtr_mGetControlStatusReg(XPAR_DELAY_BASEADDR , 0);
// If the interrupt occured, then increment a counter
if (csr && XTC_CSR_INT_OCCURED_MASK) //The symbol "&&" indicating that all conditions happens
j = (j+1)%16;
// Display the count on the LEDS and print some statement using the UART
MY_LED_mWriteReg(XPAR_MY_LED_0_BASEADDR, 0, j);
xil_printf("Count value is: %x\n\r");
// Clear the timer interrupt
XTmrCtr_mSetControlStatusReg(XPAR_MY_LED_0_BASEADDR, 0, csr);
}
//////////////////// main ///////////////////////////////
main()
{
xil_printf("-- Start of the Program --\n\r");
/* Initialize exception handling */
XExc_Init();
/* Register external interrupt handler */
XExc_RegisterHandler(XEXC_ID_NON_CRITICAL_INT, (XExceptionHandler)XIntc_LowLevelInterruptHandler, (void *)0);
/* Start the interrupt controller */
XIntc_mMasterEnable(XPAR_OPB_INTC_0_BASEADDR);
/* Set the number of cycles the timer counts before interrupting */
XTmrCtr_mSetLoadReg(XPAR_DELAY_BASEADDR, 0, 100000000); //The period is 1s
/* Reset the timers, and clear interrupts */
XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0, XTC_CSR_INT_OCCURED_MASK | XTC_CSR_LOAD_MASK );
/* Enable timer interrupts in the interrupt controller */
XIntc_mEnableIntr(XPAR_OPB_INTC_0_BASEADDR, XPAR_DELAY_INTERRUPT_MASK);
/* Start the timers */
XTmrCtr_mSetControlStatusReg(XPAR_DELAY_BASEADDR, 0, XTC_CSR_ENABLE_TMR_MASK | XTC_CSR_ENABLE_INT_MASK | XTC_CSR_AUTO_RELOAD_MASK | XTC_CSR_DOWN_COUNT_MASK);
/* Enable PPC non-critical interrupts */
XExc_mEnableExceptions(XEXC_NON_CRITICAL);
while(1);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -