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. 注解Annotation实现原理与自定义注解例子

    什么是注解? 对于很多初次接触的开发者来说应该都有这个疑问?Annontation是Java5开始引入的新特征,中文名称叫注解.它提供了一种安全的类似注释的机制,用来将任何的信息或元数据(metada ...

  2. mysql 存储过程中结尾分割符修改

    mysql中修改命令结束符delimiter的用法:mysql中的delimiter会告诉MySQL解释器,命令的结束符是什么,默认情况下MySQL的命令是以分号(;)结束的.在遇到(;)时,MySQ ...

  3. nodejs nodemailer 使用

    index.js const nodemailer=require("nodemailer") let sendEmail=function () { var transporte ...

  4. 模拟事件【JavaScript高级程序设计第三版】

    事件,就是网页中某个特别值得关注的瞬间.事件经常由用户操作或通过其他浏览器功能来触发.但很少有人知道,也可以使用JavaScript 在任意时刻来触发特定的事件,而此时的事件就如同浏览器创建的事件一样 ...

  5. python里使用正则表达式的非贪婪模式

    在正则表达式里,什么是正则表达式的贪婪与非贪婪匹配 如:String str="abcaxc"; Patter p="ab*c"; 贪婪匹配:正则表达式一般趋向 ...

  6. 【CF912E】Prime Game(meet in the middle)

    [CF912E]Prime Game(meet in the middle) 题面 CF 懒得翻译了. 题解 一眼题. \(meet\ in\ the\ middle\)分别爆算所有可行的两组质数,然 ...

  7. 学习4__STM32--中断

    Cortex-M处理器的NVIC接收中断请求各种源 > 从图中可看出,NVIC是一个外设中断的管理器,简化core的工作,控制着整个芯片的中断功能 > NVIC负责给外设中断分配优先级,使 ...

  8. MySQL的COUNT()函数理解

    MySQL的COUNT()函数理解 标签(空格分隔): MySQL5.7 COUNT()函数 探讨 写在前面的话 细心的朋友会在平时工作和学习中,可以看到MySQL的COUNT()函数有多种不同的参数 ...

  9. 关于http请求时 安全协议问题 PKIX path building failed 解决办法

    该问题的解决办法   1.在请求前需要将证书导入,不推荐       2.绕开安全协议处理 下面的代码时一段http请求并且绕开安全协议.可直接使用 /** * * @param url 需要请求的网 ...

  10. centos6 pyenv和virtualenv搭建python虚拟环境

    安装pyenv 基础环境软件包安装 yum -y install gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel ...