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

大致流程与私有定时器相似:

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

  1. ZYNQ. Interrupt(1)Private Timer

    Interrupt zynq的中断. The PS is based on ARM architecture, utilizing two Cortex-A9 processors(CPUs) and ...

  2. 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计

    本帖最后由 xinxincaijq 于 2013-1-9 10:27 编辑 一步一步学ZedBoard & Zynq(四):基于AXI Lite 总线的从设备IP设计 转自博客:http:// ...

  3. 关于IP核中中断信号的使用---以zynq系统为例

    关于IP核中中断信号的使用---以zynq系统为例 1.使能设备的中断输出信号 2.使能处理器的中断接收信号 3.连接IP核到处理器之间的中断 此处只是硬件的搭建,软件系统的编写需要进一步研究. 搭建 ...

  4. PIC32MZ tutorial -- 32-bit Timer

    The microcontroller is PIC32MZ2048ECH144 on the PIC32MZ EC Starter Kit. This microcontroller has fou ...

  5. Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State

    目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...

  6. AXI总线简介

    AXI全称Advanced eXtensible Interface,是Xilinx从6系列的FPGA开始引入的一个接口协议,主要描述了主设备和从设备之间的数据传输方式.在ZYNQ中继续使用,版本是A ...

  7. 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 ...

  8. Arduino 与 SPI 结合使用 以及SPI 深层理解

    本文主要讲解两部分内容,不做任何转发,仅个人学习记录: 一. Arduino 与 SPI 结合使用  : 二. SPI 深层理解 有价值的几个好的参考: 1. 中文版: https://blog.cs ...

  9. 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 ...

随机推荐

  1. dubbo底层之Netty

    背景 Java线程:由开始的单线程,到通过new Thread()创建的多线程,再到现如今的线程池,Java多线程编程的效率和性能有了很大的提升 Reactor模型:基于事件驱动,适合处理海量I/O事 ...

  2. Qrcode生成二维码的参数总结 及最小尺寸的测试

    Qrcode生成二维码,做过很多实验,探索最小规格的二维码到底是多少尺寸,和最高规格的二维码到底是多大尺寸.现在我总结总结: 有两种思路: 1.生成规格高的二维码,然后压缩到自己想要的尺寸的二维码.这 ...

  3. Validform验证时可以为空,否则按照指定格式验证

    在使用Validform v5.3.2时(http://validform.rjboy.cn/) 问题:可以为空,但不为空时需要按照指定格式验证数据 查看文档: 5.2.1版本之后,datatype支 ...

  4. ElasticSearch 2 (14) - 深入搜索系列之全文搜索

    ElasticSearch 2 (14) - 深入搜索系列之全文搜索 摘要 在看过结构化搜索之后,我们看看怎样在全文字段中查找相关度最高的文档. 全文搜索两个最重要的方面是: 相关(relevance ...

  5. 关于打包ipa文件以及苹果证书的若干问题

    占位 包括windows下生成p12证书,以及apicloud云编译报错等内容.有空更新 http://www.applicationloader.net/blog/zh/2050.html?tdso ...

  6. Alpha 冲刺四

    团队成员 051601135 岳冠宇 051604103 陈思孝 031602629 刘意晗 031602248 郑智文 031602234 王淇 会议照片 项目燃尽图 项目进展 实现后端聊天接收,搜 ...

  7. final发布评论Ⅱ

    奋斗吧兄弟:奋斗吧兄弟团队提供了草原.水域.田地三种环境可以进行选择.功能如下:添加自定义生物功能可以增加生物种类,但是无法设置捕食关系,这里希望想办法完善.生物除了图片方式以外,还可以以文字的方式展 ...

  8. Python模块-pymssql

    目录 工作原理 常用封装 Python默认的数据库是 SQLlite,不过它对MySql以及SQL server的支持也可以.如果想链接操作SQL server,需使用第三方包pymssql pyms ...

  9. c#public、private、protected、internal、protected internal

    public 公有访问.不受任何限制.private 私有访问.只限于本类成员访问,子类,实例都不能访问.protected 保护访问.只限于本类和子类访问,实例不能访问.internal 内部访问. ...

  10. 【Java并发编程】之十四:图文讲述同步的另一个重要功能:内存可见性

    加锁(synchronized同步)的功能不仅仅局限于互斥行为,同时还存在另外一个重要的方面:内存可见性.我们不仅希望防止某个线程正在使用对象状态而另一个线程在同时修改该状态,而且还希望确保当一个线程 ...