ZYNQ. Interrupt(2)SPI.AXI TIMER
Shared Peripheral Interrupts (SPI)
SPI 可以接收来自PL的中断,这里使用PL模块 AXI Timer 的中断模式,并连接到CPU。
AXI TIMER
定时器,内部有两个完全相同的TIMER模块。

特性:
在手册里可以找到详细的参数和寄存器信息。

硬件系统
需要zynq核和一个AXI Timer,PL的clock可以在zynq核内部设置。
软件部分
这里会使用到xilinx提供的函数库
- 中断 xscugic.h
- 定时器 xtmrctr.h
因为使用了PS端的GPIO,所以还需要另一个库
- GPIO xgpiops.h
大致流程与私有定时器相似:
- 定义定时器、中断控制器和GPIO的结构体
- 初始化定时器、终端控制器和GPIO,以及私有定时器自检
- ARM异常处理初始化,连接系统中断处理程序
- 连接定时器中断程序
- 使能GIC、使能定时器中断、使能ARM中断
- 配置重载、计数器初值,然后开始定时器,等中断
- 废弃这个定时器,通知处理器、通知GIC废弃
code:
//*****************2018/11/27 封装******************
#include <stdio.h>
#include "xil_printf.h" #include "xparameters.h"
#include "xgpiops.h" #include "sleep.h" #include "xtmrctr.h"
#include "xil_exception.h"
#include "xscugic.h" #define GpioPsDeviceId XPAR_PS7_GPIO_0_DEVICE_ID
#define AxiTmrCtrDeviceId XPAR_TMRCTR_0_DEVICE_ID
#define XScuGic_DEVICE_ID XPAR_PS7_SCUGIC_0_DEVICE_ID
#define TMRCTR_INTERRUPT_ID XPAR_FABRIC_AXI_TIMER_0_INTERRUPT_INTR #define pinLed1 0
#define pinLed2 9 #define TIMER_CNTR_0 0
#define RESET_VALUE 0xFFFFFFFF-(0x5F5E100-1) //1s int XGpioPsInit(XGpioPs *XGpioPsPtr);
int XIntrSysInit(XTmrCtr *XTmrCtrInstancePtr,
XScuGic *IntcInstancePtr,
u16 DeviceId,
u16 IntrId);
void XTmrCtrIntrHandler(void *CallBackRef, u8 TmrCtrNumber);
void TmrCtrDisableIntr(XScuGic *IntcInstancePtr, u16 IntrId); static XGpioPs GpioPs;
static XTmrCtr XTmrCtrInstance;
static XScuGic IntcInstance; int valueWriteLed2 = 0x01;
int valueWriteLed1 = 0x00; int main()
{
int Status; xil_printf("\n\r Hello,world! \n\r"
"AXI Timer Test\n\r"); /* Initialize the Gpio driver */
Status = XGpioPsInit(&GpioPs);
if (Status != XST_SUCCESS) {
xil_printf("GPIOPS Initial Failed\r\n");
return XST_FAILURE;
} /* initialize & connect & enable interrupt system */
Status = XIntrSysInit(&XTmrCtrInstance,
&IntcInstance,
AxiTmrCtrDeviceId,
TMRCTR_INTERRUPT_ID);
if (Status != XST_SUCCESS) {
xil_printf("Interrupt System Initial Failed\r\n");
return XST_FAILURE;
} /* set interrupt handler */
XTmrCtr_SetHandler(&XTmrCtrInstance,
XTmrCtrIntrHandler,&XTmrCtrInstance); /* Setting the timer counter option
* interrupt Mode and Auto Reload And Up Counter*/
XTmrCtr_SetOptions(&XTmrCtrInstance, TIMER_CNTR_0,
XTC_INT_MODE_OPTION );//| XTC_AUTO_RELOAD_OPTION); /* Set a reset value */
XTmrCtr_SetResetValue(&XTmrCtrInstance,
TIMER_CNTR_0, //
RESET_VALUE); // /* Start the timer counter */
XTmrCtr_Start(&XTmrCtrInstance, TIMER_CNTR_0); while(){
XGpioPs_WritePin(&GpioPs, pinLed1, valueWriteLed1);
// XGpioPs_WritePin(&Gpio, pinLed2, valueWriteLed2);
sleep();
xil_printf("--Write Led1: %d--\n",valueWriteLed1);
// xil_printf("--Write Led2: %d--\n",valueWriteLed2);
valueWriteLed1 = valueWriteLed1 & (0x01) ?
0x00 :0x01;//~valueWriteLed1;
// valueWriteLed2 = valueWriteLed2 & (0x01) ?
// 0x00 :0x01;//~valueWriteLed2; xil_printf("\n-- Do Again --\n");
} /* never reached */
xil_printf("\n test end\n\r"); /* Disconnect the interrupt */
TmrCtrDisableIntr(&IntcInstance, TMRCTR_INTERRUPT_ID); return ;
} /* Initialize the timer And GIC device driver ,
* Connect the Interrupt to GIC And Enable the Interrupt */
int XIntrSysInit(XTmrCtr *XTmrCtrInstancePtr,XScuGic *IntcInstancePtr,
u16 DeviceId, u16 IntrId)
{
XScuGic_Config *IntcConfig;
int Status; /* Initialize the timer counter*/
Status = XTmrCtr_Initialize(XTmrCtrInstancePtr, DeviceId);
if (Status != XST_SUCCESS) {
xil_printf("AXI TIMER INITIAL FAILED! \n\r");
return XST_FAILURE;
} /* Initialize the interrupt controller driver */
IntcConfig = XScuGic_LookupConfig(XScuGic_DEVICE_ID);
if (NULL == IntcConfig) {
return XST_FAILURE;
}
Status = XScuGic_CfgInitialize(IntcInstancePtr, IntcConfig,
IntcConfig->CpuBaseAddress);
if (Status != XST_SUCCESS) {
return XST_FAILURE;
} /* Sets the interrupt priority & trigger type
* for the specified IRQ source */
XScuGic_SetPriorityTriggerType(IntcInstancePtr, IntrId,
0xA0, 0x3); /* Initialize the exception table. */
Xil_ExceptionInit(); /* Register the interrupt controller handler with the exception table. */
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)
XScuGic_InterruptHandler,
IntcInstancePtr); /* Connect the interrupt handler */
Status = XScuGic_Connect(&IntcInstance, IntrId,
(Xil_ExceptionHandler)XTmrCtr_InterruptHandler,
XTmrCtrInstancePtr);
if (Status != XST_SUCCESS) {
return Status;
} /* Enable the interrupt for the Timer device. */
XScuGic_Enable(IntcInstancePtr, IntrId); /* Enable non-critical exceptions. */
Xil_ExceptionEnable(); return XST_SUCCESS;
} void XTmrCtrIntrHandler(void *CallBackRef, u8 TmrCtrNumber)
{
// XTmrCtr *InstancePtr = (XTmrCtr *)CallBackRef; XGpioPs_WritePin(&GpioPs, pinLed2, valueWriteLed2);
xil_printf("--Write Led2: %d--\n",valueWriteLed2);
valueWriteLed2 = valueWriteLed2 & (0x01) ?
0x00 :0x01;//~valueWriteLed2;
return;
} int XGpioPsInit(XGpioPs *GpioPsPtr)
{
XGpioPs_Config *ConfigPtr; int Status;
/* Initialize the Gpio driver. */
ConfigPtr = XGpioPs_LookupConfig(GpioPsDeviceId);
if (ConfigPtr == NULL) {
xil_printf("ERROR\n");
return XST_FAILURE;
}
Status = XGpioPs_CfgInitialize(GpioPsPtr,ConfigPtr,
ConfigPtr->BaseAddr);
if (Status != XST_SUCCESS) {
print("cfg init err\n");
return XST_FAILURE;
} //set pin direction
//value 0 -> input 1 -> output
XGpioPs_SetDirectionPin(GpioPsPtr, pinLed1, );
XGpioPs_SetDirectionPin(GpioPsPtr, pinLed2, );
//value 0 -> disable 1 -> enable
XGpioPs_SetOutputEnablePin(GpioPsPtr, pinLed1, );
XGpioPs_SetOutputEnablePin(GpioPsPtr, pinLed2, ); return XST_SUCCESS;
}
void TmrCtrDisableIntr(XScuGic* IntcInstancePtr, u16 IntrId)
{
/* Disconnect the interrupt */
XScuGic_Disable(IntcInstancePtr, IntrId);
XScuGic_Disconnect(IntcInstancePtr, IntrId); return;
}
via
https://blog.csdn.net/u014485485/article/details/79069445
ZYNQ. Interrupt(2)SPI.AXI TIMER的更多相关文章
- ZYNQ. Interrupt(1)Private Timer
Interrupt zynq的中断. The PS is based on ARM architecture, utilizing two Cortex-A9 processors(CPUs) and ...
- 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计
本帖最后由 xinxincaijq 于 2013-1-9 10:27 编辑 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计 转自博客:http:// ...
- 关于IP核中中断信号的使用---以zynq系统为例
关于IP核中中断信号的使用---以zynq系统为例 1.使能设备的中断输出信号 2.使能处理器的中断接收信号 3.连接IP核到处理器之间的中断 此处只是硬件的搭建,软件系统的编写需要进一步研究. 搭建 ...
- PIC32MZ tutorial -- 32-bit Timer
The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...
- Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State
目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...
- AXI总线简介
AXI全称Advanced eXtensible Interface,是Xilinx从6系列的FPGA开始引入的一个接口协议,主要描述了主设备和从设备之间的数据传输方式.在ZYNQ中继续使用,版本是A ...
- Make a DAC with a microcontroller's PWM timer
http://www.edn.com/design/analog/4337128/Make-a-DAC-with-a-microcontroller-s-PWM-timer Many embedded ...
- Arduino 与 SPI 结合使用 以及SPI 深层理解
本文主要讲解两部分内容,不做任何转发,仅个人学习记录: 一. Arduino 与 SPI 结合使用 : 二. SPI 深层理解 有价值的几个好的参考: 1. 中文版: https://blog.cs ...
- ARM Linux 3.x的设备树(Device Tree)
1. ARM Device Tree起源 Linus Torvalds在2011年3月17日的ARM Linux邮件列表宣称“this whole ARM thing is a f*cking pai ...
随机推荐
- php OPcache
众所周知php是一种解释型语言,它的执行可分为如下几个流程: Scanning(Lexing) ,将PHP代码转换为语言片段(Tokens) Parsing, 将Tokens转换成简单而有意义的表达式 ...
- mysql数据出现Unknown column 'user_uid' in 'field list' sql错误
来源:https://blog.csdn.net/gnail_oug/article/details/53606608 在操作mysql数据库时提示com.mysql.jdbc.exceptions. ...
- This is me
This is me 爱琴棋 爱书画 也爱格物 爱跋山 爱涉水 也爱深林 This is me. 刘伯承的诗词有曰“高耸入云”,于是“李入云”便成为了我一生的标记,也造就了一个时而安静,时而疯狂的我 ...
- linux内核分析第四周学习笔记
linux内核分析第四周学习笔记 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.co ...
- 贝叶斯先验解释l1正则和l2正则区别
这里讨论机器学习中L1正则和L2正则的区别. 在线性回归中我们最终的loss function如下: 那么如果我们为w增加一个高斯先验,假设这个先验分布是协方差为 的零均值高斯先验.我们在进行最大似然 ...
- SpringBoot 6.SpringBoot使用 Log4j2 实现日志输出
一.添加 Log4j2 的依赖 <!-- 引入 log4j2 必须排除 logging --> <dependency> <groupId>org.springfr ...
- LOJ#551 Matrix
本地打表在线AC什么的最喜欢了. 题意 \(\rm Alice\)和\(\rm Bob\)在玩游戏,他们要给一个\(n\times n\)的矩阵打标记.初始时没有任何标记,每一轮\(\rm Bob\) ...
- google-gson 使用及GsonBuilder设置
Json是一种类似于XML的通用数据交换格式,具有比XML更高的传输效率. 从结构上看,所有的数据(data)最终都可以分解成三种类型: 第一种类型是标量(scalar),也就是一个单独的字符串( ...
- "去QE化"的思考
最近测试圈子里流传一篇有关去QE(Quality Engineer)的文章,此文如平地惊雷,突然在圈子里炸开了锅.文中所述使很多同行有点人人自危,担心行业未来和自身发展前程,而后不久就有大神写出“去Q ...
- BZOJ2442 Usaco2011 Open修剪草坪(动态规划+单调队列)
显然可以dp.显然可以单调队列优化一下. #include<iostream> #include<cstdio> #include<cmath> #include& ...