⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 system_timer.c

📁 基于EDK平台的LED显示程序,通过SDK本身的接口说明
💻 C
字号:
#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);


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -