Interrupt

zynq的中断。

The PS is based on ARM architecture, utilizing two Cortex-A9 processors(CPUs) and the GIC pl390 interrupt controller.

Each CPU has a set of private peripheral interrupts (PPIs).

The PPIs include the global timer, private watchdog timer, private timer, and FIQ/IRQ from the PL.

The SGIs are generated by writing to the registers in the generic interrupt controller (GIC)

The shared peripheral interrupts (SPIs) are generated by the various I/O and memory controllers in the PS and PL.

Software Generated Interrupts (SGI)

软中断

CPU Private Peripheral Interrupt (PPI)

私有外设中断包括有:全局定时器、私有定时器,私有看门狗定时器以及来自PL的FIQ/IRQ。

FIQ和IRQ是反向的,然后送到中断控制器(GIC) ,他们在PS-PL接口中为高电平触发,尽管在ICDICFR1寄存器中反映为低电平触发。

Note that the fast interrupt (FIQ) signal and the interrupt (IRQ) signal from the PL are inverted and then sent to the interrupt
controller. Therefore, they are active High at the PS-PL interface, although the ICDICFR1 register reflects them as active Low level.

Shared Peripheral Interrupts (SPI)

一组大约60个中断,来自各个模块。

CPU Private Timer

特性:

  • 32位计数器,到零产生中断
  • 8位预分频器,能够好的控制中断周期
  • 可配置单次或自动重载模式
  • 可配置计数器初始值

私有中断硬件系统

只要添加一个ZYNQ核就可以使用。

软件部分

xilinx sdk 提供了两个库函数:

  • 定时器  xscutimer.h
  • 中断     xscugic.h

非中断方式使用私有定时器

 #include <stdio.h>
#include "xscutimer.h"
#include "xparameters.h" //1s
#define loadValue XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ / 2 -1 int main()
{
int Status;
int timerCounterValue;
int counter = ;
//--------------------------------------------
//instance Timer & TimerConfig
XScuTimer PriTimer;
XScuTimer_Config *Timer_Config;
//--------------------------------------------
//LookupConfig
Timer_Config = XScuTimer_LookupConfig(XPAR_PS7_SCUTIMER_0_DEVICE_ID);
//initialize Timer
Status = XScuTimer_CfgInitialize(&PriTimer, Timer_Config,
Timer_Config->BaseAddr);
//set counter value
XScuTimer_LoadTimer(&PriTimer, loadValue);
//Disable Auto Reload
XScuTimer_DisableAutoReload(&PriTimer);
//start
XScuTimer_Start(&PriTimer);
//-----------------------------------------------------------------------------
while(counter<=)
{
//get counter value
timerCounterValue = XScuTimer_GetCounterValue(&PriTimer);
if (timerCounterValue == )
{
//restart
XScuTimer_RestartTimer(&PriTimer);
xil_printf("Timer has reached zero %d times\n\r", counter++);
}
else
{
// xil_printf("Timer is still running (Timer value = %d)\n\r",
// timerCounterValue);
}
}
return ;
}

中断方式使用私有定时器

在sdk中有例程可以参考。

大概流程是:

  1. 定义私有定时器和中断控制器的结构体
  2. 初始化私有定时器和终端控制器,以及私有定时器自检
  3. ARM异常处理初始化,连接系统中断处理程序
  4. 连接私有定时器中断程序
  5. 使能GIC、使能定时器中断、使能ARM中断
  6. 配置重载、计数器初值,然后开始定时器,等中断
  7. 废弃这个定时器,通知处理器、通知GIC废弃

code:

 #include <stdio.h>
#include "xscutimer.h"
#include "xparameters.h"
#include "xscugic.h" #define INTRCOUNTER 10 // -------------- function Prototypes -------------------------
static void TimerInterruptHandler(void *CallBackRef);
//--------------------------------------------------------- int InterruptCounter = ; int main()
{
int Status;
//Structure Definition
XScuTimer TimerInstance;
XScuTimer_Config *TimerConfigPtr;
XScuGic GicInstance;
XScuGic_Config *GicConfigPtr; //initialize
GicConfigPtr = XScuGic_LookupConfig(XPAR_PS7_SCUGIC_0_DEVICE_ID);
Status = XScuGic_CfgInitialize(&GicInstance, GicConfigPtr,
GicConfigPtr->CpuBaseAddress);
TimerConfigPtr = XScuTimer_LookupConfig(XPAR_PS7_SCUTIMER_0_DEVICE_ID);
Status = XScuTimer_CfgInitialize(&TimerInstance, TimerConfigPtr,
TimerConfigPtr->BaseAddr);
//self-test
// Status = XScuTimer_SelfTest(TimerInstance);
// if (Status != XST_SUCCESS) {
// return XST_FAILURE;
// } //initialize & Connect Interrupt Controller
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler, &GicInstance); //Connect Private Timer Interrupt Handler
Status = XScuGic_Connect(&GicInstance, XPAR_SCUTIMER_INTR,
(Xil_ExceptionHandler)TimerInterruptHandler, (void *)&TimerInstance); // Enable the interrupt for the device
XScuGic_Enable(&GicInstance, XPAR_SCUTIMER_INTR);
// Enable the timer interrupts for timer mode
XScuTimer_EnableInterrupt(&TimerInstance);
// Enable interrupts in the Processor,Enable the IRQ exception
Xil_ExceptionEnable(); //Load the timer counter register.
XScuTimer_LoadTimer(&TimerInstance, XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ / );
//Enable Auto Reload
XScuTimer_EnableAutoReload(&TimerInstance);
//Start the timer counter and then wait for it to timeout a number of times.
XScuTimer_Start(&TimerInstance); while()
{
/*
* Wait for the first timer counter to expire as indicated by
* the shared variable which the handler will increment.
*/
if (InterruptCounter >= INTRCOUNTER)
{
break;
}
} xil_printf("break loop\n\r"); //Disable the IRQ exception
Xil_ExceptionDisable();
//Disconnect and disable the interrupt for the Timer.
XScuGic_Disconnect(&GicInstance, XPAR_SCUTIMER_INTR); return ;
} static void TimerInterruptHandler(void *CallBackRef)
{
XScuTimer *TimerIntancePtr = (XScuTimer *) CallBackRef; if (XScuTimer_IsExpired(TimerIntancePtr))
{
// Clear the interrupt flag in the timer
XScuTimer_ClearInterruptStatus(TimerIntancePtr);
xil_printf("count %d times\n\r",InterruptCounter++); if (InterruptCounter >= INTRCOUNTER)
{
XScuTimer_DisableAutoReload(TimerIntancePtr);
}
}
}

//**************2018/11/15****************************

封装

 #include <stdio.h>
#include "xscutimer.h"
#include "xparameters.h"
#include "xscugic.h" //timer info
#define TIMER_DEVICE_ID XPAR_PS7_SCUTIMER_0_DEVICE_ID
#define INTC_DEVICE_ID XPAR_PS7_SCUGIC_0_DEVICE_ID
#define INTRCOUNTER 10
#define TIMER_IRPT_INTR XPAR_SCUTIMER_INTR
#define TIMERLOADVALUE XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ / 2 -1 static XScuGic Intc;
static XScuTimer Timer;
static int IntrCounter=; // -------------- function Prototypes -------------------------
static void TimerIntrHandler(void *CallBackRef);
void SetupTimerIntrSys(XScuGic *GicInstancePtr,
XScuTimer *TimerInstancePtr);
void DisableTimerIntrSys(XScuGic *IntcInstancePtr,
u16 TimerIntrId);
//--------------------------------------------------------- int main()
{
xil_printf("--- start ----\n"); //setup the timer interrupt
SetupTimerIntrSys(&Intc, &Timer); //Load the timer counter register.
XScuTimer_LoadTimer(&Timer, TIMERLOADVALUE);
//Enable Auto Reload
XScuTimer_EnableAutoReload(&Timer);
//Start the timer counter
XScuTimer_Start(&Timer); while(){
if (IntrCounter == INTRCOUNTER) {
XScuTimer_Stop(&Timer);
break;
}
}; xil_printf("break loop\n\r"); DisableTimerIntrSys(&Intc, TIMER_IRPT_INTR);
xil_printf("Disabled Timer Interrupt\n\r"); return ;
} static void TimerIntrHandler(void *CallBackRef)
{
XScuTimer *TimerIntancePtr = (XScuTimer *) CallBackRef; if (XScuTimer_IsExpired(TimerIntancePtr))
{
// Clear the interrupt flag in the timer
XScuTimer_ClearInterruptStatus(TimerIntancePtr);
xil_printf("count %d times\n\r",IntrCounter++); if (IntrCounter >= INTRCOUNTER)
{
XScuTimer_DisableAutoReload(TimerIntancePtr);
}
}
} void SetupTimerIntrSys(XScuGic *GicInstancePtr,
XScuTimer *TimerInstancePtr)
{
int Status;
XScuTimer_Config *TimerConfigPtr;
XScuGic_Config *GicConfigPtr; //initialize,get config
TimerConfigPtr = XScuTimer_LookupConfig(TIMER_DEVICE_ID);
Status = XScuTimer_CfgInitialize(TimerInstancePtr, TimerConfigPtr,
TimerConfigPtr->BaseAddr);
GicConfigPtr = XScuGic_LookupConfig(INTC_DEVICE_ID);
Status = XScuGic_CfgInitialize(GicInstancePtr, GicConfigPtr,
GicConfigPtr->CpuBaseAddress); //initialize & Connect Interrupt Controller
Xil_ExceptionInit();
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_IRQ_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler,
GicInstancePtr); //Connect Private Timer Interrupt Handler
Status = XScuGic_Connect(GicInstancePtr, TIMER_IRPT_INTR,
(Xil_ExceptionHandler)TimerIntrHandler,
(void *)TimerInstancePtr); // Enable the interrupt for the device
XScuGic_Enable(GicInstancePtr, TIMER_IRPT_INTR);
// Enable the timer interrupts for timer mode
XScuTimer_EnableInterrupt(TimerInstancePtr);
// Enable interrupts in the Processor,Enable the IRQ exception
Xil_ExceptionEnable(); } void DisableTimerIntrSys(XScuGic *IntcInstancePtr, u16 TimerIntrId)
{
//Disable the IRQ exception
Xil_ExceptionDisable();
// Disconnect and disable the interrupt for the Timer.
XScuGic_Disconnect(IntcInstancePtr, TimerIntrId);
}

via

ug585 -- ch.7 Interrupts ch.8 Timers

https://blog.csdn.net/u014485485/article/details/79060978

ZYNQ. Interrupt(1)Private Timer的更多相关文章

  1. ZYNQ. Interrupt(2)SPI.AXI TIMER

    Shared Peripheral Interrupts (SPI) SPI 可以接收来自PL的中断,这里使用PL模块 AXI Timer 的中断模式,并连接到CPU. AXI TIMER 定时器,内 ...

  2. 第十四章 ZYNQ TIMER定时器中断

      上篇文章实现了了PS接受来自PL的中断,本片文章将在ZYNQ的纯PS里实现私有定时器中断.每隔一秒中断一次,在中断函数里计数加1,通过串口打印输出. 本文所使用的开发板是Miz702 PC 开发环 ...

  3. ZYNQ笔记(4):PL触发中断

    一.ZYNQ中断框图 PL到PS部分的中断经过ICD控制器分发器后同时进入CPU1 和CPU0.从下面的表格中可以看到中断向量的具体值.PL到PS部分一共有20个中断可以使用.其中4个是快速中断.剩余 ...

  4. ZYNQ SGI、PPI、SPI三种中断的实例(含代码)

    ZYNQ中断分为3类: SGI(Software Generated Interrupts)软件中断 PPI(Private Peripheral Interrupts)私有外设中断 SPI(Shar ...

  5. Linux时间子系统之(十七):ARM generic timer驱动代码分析

    专题文档汇总目录 Notes:ARM平台Clock/Timer架构:System counter.Timer以及两者之间关系:Per cpu timer通过CP15访问,System counter通 ...

  6. [原创]Zynq AXI-CDMA的使用

    Xilinx 提供了3种DMA AXI-DMA AXI-CDMA AXI-VDMA 使用CDMA能够满足项目需求(MM-MM),DS文档介绍如下: The Xilinx LogiCORE™ IP AX ...

  7. 79.ZYNQ内部私有定时器中断

    上篇文章实现了了PS接受来自PL的中断,本片文章将在ZYNQ的纯PS里实现私有定时器中断.每个一秒中断一次,在中断函数里计数加1,通过串口打印输出. *本文所使用的开发板是Miz702(兼容zedbo ...

  8. Linux时间子系统(十七) ARM generic timer驱动代码分析

    一.前言 关注ARM平台上timer driver(clocksource chip driver和clockevent chip driver)的驱动工程师应该会注意到timer硬件的演化过程.在单 ...

  9. Zynq-7000 FreeRTOS(二)中断:Timer中断

    总结Zynq-7000 这款器件中的Timer定时器中断,为FreeRTOS中断做准备.在 ZYNQ 的纯 PS 里实现私有定时器中断. 每隔一秒中断一次, 在中断函数里计数加 1, 通过串口打印输出 ...

随机推荐

  1. 第二个Sprint冲刺第 七天(燃尽图)

  2. An ''all'' model group must appear in a particle with...问题解决记录

    场景: 最近在一个新项目的依赖包调整过程中,引入包之后,发现项目启动报错,一直启动不成功,经过查询和排查,发现是包对xml解析冲突的问题: 报错信息: [WARNING] Nested in org. ...

  3. 链表的C/C++实现

    一个链表实现,函数声明放在 list.h 头文件汇总,函数定义放在list.cpp 中,main.cpp 用来测试各个函数. 1.文件list.h // list.h #ifndef __LIST_H ...

  4. python设计模式-单例模式

    单例模式应用场景 代码的设计模式共有25种,设计模式其实是代码无关的.其目的是基于OOP的思想,不同应用场景应用不同的设计模式,从而达到简化代码.利于扩展.提示性能等目的.本文简述Python实现的单 ...

  5. mongoDB学习--建库、删库、插入、更新

    在讲之前我们说一下mongoDB的一些基本概念,我们对比关系型数据库能更直观的理解 SQL术语/概念 MongoDB术语/概念 说明 database database 数据库 table colle ...

  6. Rust 阴阳谜题,及纯基于代码的分析与化简

    Rust 阴阳谜题,及纯基于代码的分析与化简 雾雨魔法店专栏 https://zhuanlan.zhihu.com/marisa 来源 https://zhuanlan.zhihu.com/p/522 ...

  7. 洛谷 P2047 [NOI2007]社交网络 解题报告

    P2047 [NOI2007]社交网络 题目描述 在社交网络(\(social\) \(network\))的研究中,我们常常使用图论概念去解释一些社会现象.不妨看这样的一个问题.在一个社交圈子里有\ ...

  8. 40+ 个非常有用的 Oracle 查询语句

    40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快快收藏吧! 日期/时间 ...

  9. 【洛谷P2921】Trick or Treat on the Farm

    题目大意:给定一个 N 个节点的内向树森林,求从每个顶点出发能够到达的最多不重复顶点的个数是多少. 题解:内向树森林是由一个或若干个环加若干条链构成.可以先按照类似于拓扑排序的规则进行删链,再对环上的 ...

  10. vim使用入门设置

    分为以下四步. 1,安装vim 2,安装git yum -y install vim git (Fedora/CentOS) /apt-get install vim git (Debian/Ubun ...