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. CodeMirror mode编写

    Writing CodeMirror Modes Modes typically consist of a single JavaScript file. This file defines, in ...

  2. process.tar.gz

    exec1.c #include <stdio.h> #include <unistd.h> int main() { char *arglist[3]; arglist[0] ...

  3. HashMap相关总结

    1.HashMap:根据键值hashCode值存储数据,大多数情况下可以直接定位到它的值,但是遍历顺序不确定.所有哈希值相同的值存储到同一个链表中                         Ha ...

  4. final发布48小时用户调查报告

    小组名称:飞天小女警 项目名称:礼物挑选小工具 小组成员:沈柏杉(组长).程媛媛.杨钰宁.谭力铭 调查问卷标题:用户调查报告 调查目的:在final版本发布后的用户调查报告 调查问卷的数量:11 问卷 ...

  5. PAT 甲级 1090 Highest Price in Supply Chain

    https://pintia.cn/problem-sets/994805342720868352/problems/994805376476626944 A supply chain is a ne ...

  6. array_pop()方法

    array_pop — 将数组最后一个单元弹出(出栈) 说明 mixed array_pop ( array &$array ) array_pop() 弹出并返回 array 数组的最后一个 ...

  7. delphi制作登陆窗体

    delphi登陆窗体的制作,就我知道的,可以有两种方法,一种是在工程文件中实现登陆窗体的动态调用,另一种就是在主窗体的OnCreate事件中动态创建登陆窗体,两种方法都需要将主窗体设置为Auto-cr ...

  8. Django通用视图APIView和视图集ViewSet的介绍和使用(Django编程-1)

    1.APIView DRF框架的视图的基类是 APIView APIView的基本使用和View类似 Django默认的View请求对象是 HttpRequest,REST framework 的请求 ...

  9. 拿到一个崭新的Linux!

    买了服务器,这次买了半年,不能浪费了! 0.准备工作: l查看Ip:ifconfig  ip addr 不能上网? 执行以下: vi /etc/sysconfig/network-scripts/if ...

  10. pgm8

    前面的近似策略是寻找了 energy functional 的近似,该近似导致了 LBP,这使得 message passing 的算法不变.近似使用 I-projection,尽管这个一般说来并不容 ...