zoukankan      html  css  js  c++  java
  • XLNX XC7Z020平台GIC中断示例程序

      1 #include <stdio.h>
      2 #include "platform.h"
      3 #include "xil_types.h"
      4 #include "xscugic.h"
      5 #include "xscutimer.h"
      6 #include "xscuwdt.h"
      7 #include "xil_exception.h"
      8 
      9 static void TimerInterruptHandler(void *CallBackRef)
     10 {
     11     static int sec = 0;
     12     printf("ScuTimer %d Seconds
    ", sec++);
     13 
     14     // Clears the interrupt status
     15     XScuTimer *TimerInstPtr = (XScuTimer*)CallBackRef;
     16     XScuTimer_ClearInterruptStatus(TimerInstPtr);
     17 }
     18 
     19 static void ScuWdtInterruptHandler(void *CallBackRef)
     20 {
     21     static int sec = 0;
     22     printf("ScuWdt %d Seconds
    ", sec++);
     23 
     24     // Clears the interrupt status
     25     XScuWdt *ScuWdtInstPtr = (XScuWdt *)CallBackRef;
     26     XScuWdt_WriteReg(ScuWdtInstPtr->Config.BaseAddr, XSCUWDT_ISR_OFFSET, 0UL);
     27 }
     28 
     29 int main(void)
     30 {
     31     init_platform();
     32 
     33     //---------------------------------------------------------------------------
     34     // Timer initialization
     35     //---------------------------------------------------------------------------
     36     // Lookup the Timer configuration based on the unique device ID
     37     XScuTimer_Config *TimerConfigPtr;
     38     TimerConfigPtr = XScuTimer_LookupConfig(XPAR_XSCUTIMER_0_DEVICE_ID);
     39 
     40     // Initialize a specific timer instance/driver
     41     XScuTimer XScuTimerInst;
     42     XScuTimer_CfgInitialize(&XScuTimerInst, TimerConfigPtr, TimerConfigPtr->BaseAddr);
     43     // Run a self-test on the timer
     44     XScuTimer_SelfTest(&XScuTimerInst);
     45 
     46     //---------------------------------------------------------------------------
     47     // Timer configure
     48     //---------------------------------------------------------------------------
     49     // Write to the timer load register
     50     // From ARM DDI0407I_cortex_a9_mpcore_r4p1_trm.pdf reference, timers are always
     51     // clocked at 1/2 of the CPU frequency (CPU_3x2x), now CPU frequency now is 666MHz, so the timer is 333MHz
     52     // 333_000_000 * 1(s) - 1 = 332_999_999 = 0x13D92D3F
     53     XScuTimer_LoadTimer(&XScuTimerInst, 0x13D92D3F);
     54     // Enable auto-reload mode
     55     XScuTimer_EnableAutoReload(&XScuTimerInst);
     56     // Start timer
     57     XScuTimer_Start(&XScuTimerInst);
     58 
     59     XScuWdt_Config *ScuWdtConfigPtr;
     60     ScuWdtConfigPtr = XScuWdt_LookupConfig(XPAR_SCUWDT_0_DEVICE_ID);
     61 
     62     XScuWdt XScuWdtInst;
     63     XScuWdt_CfgInitialize(&XScuWdtInst, ScuWdtConfigPtr, ScuWdtConfigPtr->BaseAddr);
     64     XScuWdt_SelfTest(&XScuWdtInst);
     65 
     66     XScuWdt_LoadWdt(&XScuWdtInst, 0x13D92D3F << 1UL);
     67     XScuWdt_SetTimerMode(&XScuWdtInst);
     68     XScuWdt_EnableAutoReload(&XScuWdtInst);
     69     XScuWdt_Start(&XScuWdtInst);
     70 
     71     //---------------------------------------------------------------------------
     72     // Interrupt Controller initialization
     73     //---------------------------------------------------------------------------
     74     XScuGic XScuGicInst;
     75     XScuGic_Config *XScuGic_ConfigPtr;
     76 
     77     XScuGic_ConfigPtr = XScuGic_LookupConfig(XPAR_SCUGIC_SINGLE_DEVICE_ID);
     78 
     79     // CfgInitialize a specific interrupt controller instance/driver
     80     XScuGic_CfgInitialize(&XScuGicInst, XScuGic_ConfigPtr, XScuGic_ConfigPtr->CpuBaseAddress);
     81 
     82     //---------------------------------------------------------------------------
     83     // Interrupt system setup
     84     //---------------------------------------------------------------------------
     85     // Makes the connection between the Id of the exception source and the associated Handler
     86     Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT, (Xil_ExceptionHandler)XScuGic_InterruptHandler, &XScuGicInst);
     87     // Enable Exceptions
     88     Xil_ExceptionEnableMask(XIL_EXCEPTION_IRQ);
     89 
     90     //---------------------------------------------------------------------------
     91     // Register Interrupt Handler
     92     //---------------------------------------------------------------------------
     93     // Makes the connection between the Int_Id of the interrupt source and the associated handler
     94     XScuGic_Connect(&XScuGicInst, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler)TimerInterruptHandler,  (void *)&XScuTimerInst);
     95     XScuGic_Connect(&XScuGicInst, XPAR_SCUWDT_INTR,   (Xil_ExceptionHandler)ScuWdtInterruptHandler, (void *)&XScuWdtInst);
     96 
     97     //---------------------------------------------------------------------------
     98     // Enable Timer interrupt in the controller
     99     //---------------------------------------------------------------------------
    100     // Enable the Timer interrupt
    101     XScuTimer_EnableInterrupt(&XScuTimerInst);
    102 
    103     u32 Register;
    104     Register = XScuWdt_ReadReg(XScuWdtInst.Config.BaseAddr, XSCUWDT_CONTROL_OFFSET);
    105     XScuWdt_SetControlReg(&XScuWdtInst, XSCUWDT_CONTROL_IT_ENABLE_MASK | Register);
    106 
    107     XScuGic_Enable(&XScuGicInst, XPAR_SCUTIMER_INTR);
    108     XScuGic_Enable(&XScuGicInst, XPAR_SCUWDT_INTR);
    109 
    110     printf("GIC SCUTimer ...
    ");
    111     while(1);
    112 
    113     cleanup_platform();
    114     return 0;
    115 }
  • 相关阅读:
    ZooKeeper的工作原理
    redis 数据类型详解 以及 redis适用场景场合
    nginx负载均衡原理
    Java中缓存的介绍
    Java中接口的作用
    json与xml的区别
    最经典40个多线程问题总结
    Java线程 : 线程同步与锁
    dbcp与c3p0的区别
    Linux常见命令
  • 原文地址:https://www.cnblogs.com/lyuyangly/p/14224461.html
Copyright © 2011-2022 走看看