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. oozie 编译与安装

    oozie:4.3.1  hadoop 2.7.6 hive编译使用2.0.0参与编译不通过,但是可以指定为1.2.0,编译可以通过,后期不使用hive的action即可(也可以使用,但是可能会出现异 ...

  2. PAT甲题题解-1008. Elevator (20)-大么个大水题,这也太小瞧我们做题者的智商了

    如题... #include <iostream> #include <cstdio> #include <algorithm> #include <cstr ...

  3. 《Linux内核设计与实现》Chapter 2 读书笔记

    <Linux内核设计与实现>Chapter 2 读书笔记 一.获取内核源码 1.使用Git 我们曾经在以前的学习中使用过Git方法 $ git clone git://git.kernel ...

  4. C++:多态浅析

    1.多态 在C++中由两种多态性: • 编译时的多态性:通过函数的重载和运算符的重载来实现的 • 运行时的多态性:通过类继承关系和虚函数来实现的 特别注意: a.运行时的多态性是指程序执行前,无法根据 ...

  5. # 蜗牛慢慢爬 LeetCode 21. Merge Two Sorted Lists [Difficulty: Easy]

    题目 Merge two sorted linked lists and return it as a new list. The new list should be made by splicin ...

  6. wifi 标准

    简介 https://smb.pconline.com.cn/1149/11491365.html

  7. GS 服务器超时时间设置

    工作中 遇到一个超时的问题 与徐庆同学沟通后 了解了下超时时间设置的地方 1.web.congfig问题: 常规路径 C:\Program Files\GenerSoft\bscw_local\web ...

  8. Ubutnu linux 下升级python版本,以2.x升级到3.x为例

    Linux操作系统一般 都会自带python,但是python版本会比主流低,故升级python, 主要思路:自带的python的链接link文件是在/usr/bin 下,采用sudo apt-get ...

  9. python自动化之PDF

    ###################################处理PDF和Word文档################################### ''' PDF和Word文档是二进 ...

  10. Java多线程与线程同步

    六.多线程,线程,同步 ①概念: 并行:指两个或多个在时间同一时刻发生(同时发生) 并发:指两个或多个事件在同一时间段内发生 具体概念: 在操作系统中,安装了多个程序,并发指的是在一段时间内宏观上有多 ...