ZYNQ. Interrupt(1)Private Timer
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中有例程可以参考。
大概流程是:
- 定义私有定时器和中断控制器的结构体
- 初始化私有定时器和终端控制器,以及私有定时器自检
- ARM异常处理初始化,连接系统中断处理程序
- 连接私有定时器中断程序
- 使能GIC、使能定时器中断、使能ARM中断
- 配置重载、计数器初值,然后开始定时器,等中断
- 废弃这个定时器,通知处理器、通知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的更多相关文章
- ZYNQ. Interrupt(2)SPI.AXI TIMER
Shared Peripheral Interrupts (SPI) SPI 可以接收来自PL的中断,这里使用PL模块 AXI Timer 的中断模式,并连接到CPU. AXI TIMER 定时器,内 ...
- 第十四章 ZYNQ TIMER定时器中断
上篇文章实现了了PS接受来自PL的中断,本片文章将在ZYNQ的纯PS里实现私有定时器中断.每隔一秒中断一次,在中断函数里计数加1,通过串口打印输出. 本文所使用的开发板是Miz702 PC 开发环 ...
- ZYNQ笔记(4):PL触发中断
一.ZYNQ中断框图 PL到PS部分的中断经过ICD控制器分发器后同时进入CPU1 和CPU0.从下面的表格中可以看到中断向量的具体值.PL到PS部分一共有20个中断可以使用.其中4个是快速中断.剩余 ...
- ZYNQ SGI、PPI、SPI三种中断的实例(含代码)
ZYNQ中断分为3类: SGI(Software Generated Interrupts)软件中断 PPI(Private Peripheral Interrupts)私有外设中断 SPI(Shar ...
- Linux时间子系统之(十七):ARM generic timer驱动代码分析
专题文档汇总目录 Notes:ARM平台Clock/Timer架构:System counter.Timer以及两者之间关系:Per cpu timer通过CP15访问,System counter通 ...
- [原创]Zynq AXI-CDMA的使用
Xilinx 提供了3种DMA AXI-DMA AXI-CDMA AXI-VDMA 使用CDMA能够满足项目需求(MM-MM),DS文档介绍如下: The Xilinx LogiCORE™ IP AX ...
- 79.ZYNQ内部私有定时器中断
上篇文章实现了了PS接受来自PL的中断,本片文章将在ZYNQ的纯PS里实现私有定时器中断.每个一秒中断一次,在中断函数里计数加1,通过串口打印输出. *本文所使用的开发板是Miz702(兼容zedbo ...
- Linux时间子系统(十七) ARM generic timer驱动代码分析
一.前言 关注ARM平台上timer driver(clocksource chip driver和clockevent chip driver)的驱动工程师应该会注意到timer硬件的演化过程.在单 ...
- Zynq-7000 FreeRTOS(二)中断:Timer中断
总结Zynq-7000 这款器件中的Timer定时器中断,为FreeRTOS中断做准备.在 ZYNQ 的纯 PS 里实现私有定时器中断. 每隔一秒中断一次, 在中断函数里计数加 1, 通过串口打印输出 ...
随机推荐
- java 中的内部类总结
内部类不是很好理解,但说白了其实也就是一个类中还包含着另外一个类. 如同一个人是由大脑.肢体.器官等身体结果组成,而内部类相当于其中的某个器官之一,例如心脏:它也有自己的属性和行为(血液.跳动). 显 ...
- centos7 设置静态IP
centos7 设置静态IP 一.查找配置文件(/etc/sysconfig/network-scripts) [root@bogon network-scripts]# ll 总用量 232 -rw ...
- PAT甲题题解-1077. Kuchiguse (20)-找相同后缀
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- HashMap相关总结
1.HashMap:根据键值hashCode值存储数据,大多数情况下可以直接定位到它的值,但是遍历顺序不确定.所有哈希值相同的值存储到同一个链表中 Ha ...
- Linux 信号:signal 与 sigaction
0.Linux下查看支持的信号列表: france@Ubuntux64:~$ kill -l ) SIGHUP ) SIGINT ) SIGQUIT ) SIGILL ) SIGTRAP ) SIGA ...
- Jmeter使用笔记之组件的作用域
以前一直使用loadrunner,最近入职新公司后需要使用jmeter,这里把使用过程中出现的一些问题进行总结,同时会和自己使用loadrunner的情况相比较,以后也会不断总结,GO! 一.组件的作 ...
- [转帖] 学习 Linux 大页的内存知识
一.在解释什么情况下需要开启大页和为啥需要开启大页前先了解下Linux下页的相关的知识:以下的内容是基于32位的系统,4K的内存页大小做出的计算1)目录表,用来存放页表的位置,共包含1024个目录en ...
- App phonegap
云端打包 https://build.phonegap.com/apps phonegap PC端下载 https://www.phonegap.com/getstarted/ 移动端下载 https ...
- 苹果ATS 豁免摆乌龙?
现象 我们的App已经完成了NA部分的ATS适配.网页端由于有使用到第三方的页面,所以开启了网页的豁免权限.关于如何开启豁免及方法,可以参考喵神的Blog最终,我们的适配参数为: NSAllowsAr ...
- 06.基于IDEA+Spring+Maven搭建测试项目--dubbo-consumer.xml配置
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...