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 ...
随机推荐
- 炸弹人的Alpha版使用说明
本游戏是一款手机游戏,学生可以在无聊时打发时间,放松心情.现在只有三关,但游戏运行还算可以. 注意事项: 目前游戏还有一些不好的地方,游戏无法暂停,如果游戏任务死亡,则无法重开. 游戏后面的关卡还需要 ...
- python 如何写CMD命令工具
#-*- coding: UTF- -*- import argparse import sys: sys.argv.append('--help') parser = argparse.Argume ...
- TCP/IP 之 大明王朝邮差 (转)
原创: 刘欣 码农翻身 2016-05-12 前言: 本文主要想说一下TCP的知识, 比喻有不恰当之处,敬请包涵. 大明王朝天启四年, 清晨. 天色刚蒙蒙亮,我就赶着装满货物的马车来到了南城门, 这里 ...
- [知乎]BAT占线
黑色自有,蓝色全资收够,红色入股. https://www.zhihu.com/question/304396738/answer/547766603
- join()方法跟踪
#join方法跟踪java.lang.Thread.join() 进入线程的join方法,实际上线程thread是实现的 runnable接口 class Thread implements Runn ...
- npm 切换淘宝镜像几种方式
淘宝 npm 地址: http://npm.taobao.org/ 如何使用 有很多方法来配置npm的registry地址,下面根据不同情境列出几种比较常用的方法.以淘宝npm镜像举例: 1.临时使用 ...
- 以 BZOJ 2002 为例学习有根树LCT(Link-Cut Tree)
以BZOJ 2002 弹飞绵羊为例学习有根树LCT(Link-Cut Tree) 注:本文非常简单,只涉及有根树LCT,对于无根树,LCT还有几个本文没有提到的操作,以后慢慢更新 =v= 知识储备 [ ...
- webpack进阶--打包
上一片博文主要让大家了解下究竟webpack是干什么的,明显它是专注于打包的. gulp 和 webpack 的区别 gulp,要求我们一步步写task(es6编译.css压缩.图片压缩.打包. ...
- eclipse启动tomcat内存溢出的解决方式
eclipse启动tomcat内存溢出的解决方式 ——IT唐伯虎 摘要:eclipse启动tomcat内存溢出的解决方式. 1.打开Run Configurations 2.在VM arguments ...
- Hadoop上传文件时报错: could only be replicated to 0 nodes instead of minReplication (=1)....
问题 上传文件到Hadoop异常,报错信息如下: org.apache.hadoop.ipc.RemoteException(java.io.IOException): File /home/inpu ...