ZYNQ 7020学习笔记之PL侧普通信号中断PS的实验
1、参考
UG585
网络笔记
2、理论知识
见中断部分
3、实验目的
练习使用PL侧的普通信号来中断PS处理器。
4、实验过程
建立工程,设置并初始化串口中断,在运行程序之后,如果串口接收到N(1-63)个字节数据,则产生串口中断,Zynq响应中断,将数据从RXFIFO读出之后写入到DDR3预定的地址中。
5、实验平台
Microphase ZUS zynq7020 开发板。 串口使用 uart1[48,49]. DDR选择 MT41J256M16 RE-125,32bit. BANK1 = 1.8v.
6、Vivado 建立工程
block design 如下:

7、SDK的工程程序
/******************************************************************************
*
* Copyright (C) 2009 - 2014 Xilinx, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* Use of the Software is limited solely to applications:
* (a) running on a Xilinx device, or
* (b) that interact with a Xilinx device through a bus or interconnect.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* XILINX BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Except as contained in this notice, the name of the Xilinx shall not be used
* in advertising or otherwise to promote the sale, use or other dealings in
* this Software without prior written authorization from Xilinx.
*
******************************************************************************/
#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xscugic.h"
#include "xscutimer.h"
#include "xparameters.h"
#include "xil_exception.h"
#include <unistd.h> //sleep() usleep()
#define INTC_DEVICE_ID XPAR_PS7_SCUGIC_0_DEVICE_ID
#define INTC_PL_INTERRUPT_ID XPAR_FABRIC_MY_AXI4LITE_IP_0_PL_TO_ZYNQ_IRQ_INTR
#define INT_TYPE_MASK 0x01
#define INT_TYPE_RISING_EDGE 0X03
#define INT_TYPE_HIGHLEVEL 0X01
#define INT_CFG0_OFFSET 0x00000C00 //(intID/16 )*4
#define INT_ENABLE_OFFSET 0x00000100 //(intID/32 )*4
#define INT_CLEAR_OFFSET 0x00000280 //(intID/32 )*4
#define INT_PRIORITY_OFFSET 0x00000400 //(intID/4 )*4
#define INT_PROCESSORTARGET_OFFSET 0x00000800 //(intID/4 )*4
#define INT_ICCPMR_OFFSET 0xF8F00104
#define INT_ICCICR_OFFSET 0xF8F00100
#define BRAM_BASS_ADDRESS 0X40000000
XScuGic INTCInst;
static void PLIRQIntrHandler(void * InstancePtr); //中断处理功能函数
static void CPU_Init(void);
static void IntcTypeSetup(XScuGic *InstancePtr, int intId, int intType) ;
static void IntcTypeEnable(XScuGic *InstancePtr, int intId, int intMask) ;
static void IntcTypeClear(XScuGic *InstancePtr, int intId ) ;
static int InterruptSystemSetup(XScuGic * XScuGicInstancePtr); //中断系统建立
static int IntcInitFunction(u16 DeviceID); //中断控制器初始化功能
int main()
{
init_platform();
CPU_Init();
int status;
//中断建立
status = IntcInitFunction(INTC_DEVICE_ID);
if(status != XST_SUCCESS)
return XST_FAILURE ;
print(">>>>>>>>>>>> TEST Start >>>>>>>>>>>>>>>>\n\r");
print(" Press the Key for PL begin write data to PS DDR3 : \n\r");
while(1)
{
;
}
cleanup_platform();
return 0;
}
// 中断控制器初始化功能
static int IntcInitFunction(u16 DeviceId)
{
XScuGic_Config * IntcConfig ;
int status;
printf("Enter the interrupt system >>>>>>\n");
// 第二步, 对中断控制器进行初始化
IntcConfig = XScuGic_LookupConfig(DeviceId); //查找 GIC 的ID
status = XScuGic_CfgInitialize(&INTCInst, IntcConfig, IntcConfig->CpuBaseAddress);
if(status != XST_SUCCESS)
return XST_FAILURE;
//第三步,建立中断系统
status = InterruptSystemSetup(&INTCInst);
if(status != XST_SUCCESS)
return XST_FAILURE ;
//第四步,GPIO中断连接到GIC上
status = XScuGic_Connect(&INTCInst, INTC_PL_INTERRUPT_ID,
(Xil_ExceptionHandler)PLIRQIntrHandler, (void *)1);
if(status != XST_SUCCESS)
return XST_FAILURE ;
//******************//
// 参考
IntcTypeSetup(&INTCInst, INTC_PL_INTERRUPT_ID, INT_TYPE_RISING_EDGE); //重要
IntcTypeEnable(&INTCInst, INTC_PL_INTERRUPT_ID, INT_TYPE_MASK);
//*********************************//
XScuGic_Enable(&INTCInst, INTC_PL_INTERRUPT_ID); //CIG允许中断
return XST_SUCCESS ;
}
static int InterruptSystemSetup (XScuGic * XScuGicInstancePtr)
{
//中断异常的处理,指定该中断异常的处理器
Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
(Xil_ExceptionHandler)XScuGic_InterruptHandler, XScuGicInstancePtr);
Xil_ExceptionEnable(); //异常处理使能
return XST_SUCCESS;
}
void IntcTypeSetup(XScuGic *InstancePtr, int intId, int intType)
{
//Setup 包括 触发方式配置, 优先级配置,CPU连接。 设置某个中断信息的前提是不影响其他中断设置
int mask;
//设置边沿触发方式
mask = XScuGic_DistReadReg(InstancePtr, INT_CFG0_OFFSET + (intId/16)*4); //read ICDICFR *4,因为1个寄存器4个字节
mask &= ~(0X3 << (intId%16)*2); //把读出的值对应2bit,清00,其他保持不变 //*2因为每个中断对应2bit
mask |= intType << ((intId%16)*2); //把清0后的值对应2bit,写01,其他保持不变
XScuGic_DistWriteReg(InstancePtr, INT_CFG0_OFFSET + (intId/16)*4, mask); //WRITE ICDICFR
//设置优先级
mask = XScuGic_DistReadReg(InstancePtr, INT_PRIORITY_OFFSET + (intId/4)*4); //read 优先级状态
mask &= ~(0XFE << (intId%4)*8); //把读出的值对应8bit,清00,其他保持不变 //*8因为每个中断对应8bit
mask |= 0XA0 << ((intId%4)*8); //把清0后的值对应8bit,写A0,其他保持不变
XScuGic_DistWriteReg(InstancePtr, INT_PRIORITY_OFFSET + (intId/4)*4, mask); //WRITE ICDICFR
//设置处理器CPIID
mask = XScuGic_DistReadReg(InstancePtr, INT_PROCESSORTARGET_OFFSET + (intId/4)*4); //read 优先级状态
mask &= ~(0X03 << (intId%4)*8); //把读出的值对应8bit,清00,其他保持不变 //*8因为每个中断对应8bit
mask |= 0X01 << ((intId%4)*8); //把清0后的值对应8bit,写A0,其他保持不变
XScuGic_DistWriteReg(InstancePtr, INT_PROCESSORTARGET_OFFSET + (intId/4)*4, mask); //WRITE ICDICFR
}
void IntcTypeEnable(XScuGic *InstancePtr, int intId,int intMask)
{
// 本函数 只包括 使能中断。使能之前先判断是否需要屏蔽
int mask;
mask = XScuGic_DistReadReg(InstancePtr, INT_ENABLE_OFFSET + (intId/32)*4);
mask &= ~(0x01 << (intId%32)*1); //把对应的Enable bit 清0
mask |= intMask << ((intId%32)*1); //把对应的Enable bit 与 mask
XScuGic_DistWriteReg(InstancePtr, INT_ENABLE_OFFSET + (intId/32)*4, mask); //WRITE ICDICFR
}
void IntcTypeClear(XScuGic *InstancePtr, int intId )
{
//本函数仅包括清楚中断,注意只能清除本中断对应的寄存器位
int mask;
mask = XScuGic_DistReadReg(InstancePtr, INT_CLEAR_OFFSET + (intId/32)*4); //read ICDICPR
mask &= ~(0x01 << (intId%32)*1);
mask |= 0x01 << ((intId%32)*1);
XScuGic_DistWriteReg(InstancePtr, INT_CLEAR_OFFSET + (intId/32)*4, mask); //WRITE ICDICPR
}
void CPU_Init( )
{
//中断优先级都是A0,优先级高于F0,CPU可接受这些中断
Xil_Out32(INT_ICCPMR_OFFSET,0xF0);
//处理器能接收IRQ,使能中断信号连接到处理器
Xil_Out32(INT_ICCICR_OFFSET,0x07);
}
static void PLIRQIntrHandler(void * InstancePtr)
{
//default led all turn off
printf("\n************* test STARAT *********************\n");
int i;
int readdata;
sleep(1);
for(i = 0; i < 4; i++)
{
readdata = Xil_In32(BRAM_BASS_ADDRESS+i*4); //读取数据函数。
sleep(1);
printf("the read address is 0x%04x, the read data is 0x%04x.\n", BRAM_BASS_ADDRESS+i*4, readdata);
}
printf("\n************* test finish *********************\n");
// ***************************************************** //
IntcTypeClear(&INTCInst, INTC_PL_INTERRUPT_ID);
IntcTypeEnable(&INTCInst, INTC_PL_INTERRUPT_ID, INT_TYPE_MASK);
}
8 调试结果

ZYNQ 7020学习笔记之PL侧普通信号中断PS的实验的更多相关文章
- MiZ702学习笔记9——XADC采集片上数据PS版
这次借助zynq的内嵌的XADC来采集zynq内部的一些参数: •VCCINT:内部PL核心电压 •VCCAUX:辅助PL电压 •VREFP:XADC正参考电压 •VREFN:XADC负参考电压 •V ...
- Oracle学习笔记之PL/SQL编程
SQL(Structure Query Language)的含义是结构化查询语句,最早由Boyce和Chambedin在1974年提出,称为SEQUEL语言.1976年,IBM公司的Sa ...
- 吴裕雄--天生自然ORACLE数据库学习笔记:PL/SQL编程
set serveroutput on declare a ; b ; c number; begin c:=(a+b)/(a-b); dbms_output.put_line(c); excepti ...
- Zynq-Linux移植学习笔记之27UIO机制响应外部中断实现【转】
转自:https://blog.csdn.net/zhaoxinfan/article/details/80285150 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog ...
- 《Linux内核设计的艺术》学习笔记(七)INT 0x15中断
参考资料: 1. <IBM-PC汇编语言程序设计> 2. http://blog.sina.com.cn/s/blog_5028978101008wk2.html 3. http://ww ...
- 《Linux内核设计的艺术》学习笔记(五)INT 0x10中断
参考书籍: 1. <IBM-PC汇编语言程序设计> 2. http://www.ctyme.com/intr/int-10.htm ◆ 设置显示方式: 功能号:AH = 00H 调用参 ...
- 《Linux内核设计的艺术》学习笔记(二)INT 0x13中断
参考资料: 1. <IBM-PC汇编语言程序设计> 2. http://blog.sina.com.cn/s/blog_5028978101008wk2.html 3. http://ww ...
- PyQt4学习笔记2:事件和信号
事件是任何 GUI 程序中很重要的部分.所有 GUI 应用都是事件驱动的.一个应用对其生命期产生的不同的事件类型做出反应.事件是主要由应用的用户产生.但是,也可以通过其他方法产生,比如,网络通信,窗口 ...
- APUE学习笔记——10.11~10.13 信号集、信号屏蔽字、未决信号
如有转载,请注明出处:Windeal专栏 首先简述下几个概念的关系: 我们通过信号集建立信号屏蔽字,使得信号发生阻塞,被阻塞的信号即未决信号. 信号集: 信号集:其实就是一系列的信号.用sigset_ ...
随机推荐
- Convert.ToByte((int)val)
static void Main(string[] args) { ; byte bit8 = Convert.ToByte((int)val); Console.WriteLine("[{ ...
- Linux正则表达式与通配符
在linux中,有通配符和正则表达式,这是两个不同的概念通配符:它是由shell解析,并且一般用于匹配文件名.如:ls正则表达式:是一个字符匹配标准,可以匹配文本中的内容一些命令工具按此标准实现字符匹 ...
- 我的首次AK记
哈哈哈!本蒟蒻终于在今天中午机房测试中AK全场了(其实没啥技术含量,只有5个水题,对,全都很水)
- 优化sql技巧
当表很大的时候可以设计冗余字段,避免与大表连表查询造成性能低下 比如日志表和用户表,日志表通常到后期会相当的大可以做一个username的冗余字段,避免查看username的时候去和user表关联 当 ...
- [Python] Python忽略warning警告错误
Python忽略warning警告错误 1)代码中警告 import warnings warnings.filterwarnings("ignore") 2)忽略命令行下警告 ...
- [PHP]Laravel无法使用COOKIE和SESSION的解决方法
COOKIE和SESSION的具体使用百度和官方文档上都有. 但是,文档里没有说明必须经过相应的中间件才能使用,百度搜索结果都是彼此copy的bullshit!!! 其实最终解决办法很简单,完全不是网 ...
- [Java] Spring boot 的 SrpingSecurity 框架搭建
参考: SrpingSecurity]之一:框架搭建https://blog.csdn.net/qq_28296925/article/details/82021092 [SpringSecurity ...
- 52: Luogu 4777 excrt
模板题 #include <bits/stdc++.h> using namespace std; ; #define LL long long int n; LL a[N], m[N]; ...
- libvirt原理
引用原文: https://blog.csdn.net/BtB5e6Nsu1g511Eg5XEg/article/details/80142155 libvirt是目前使用最为广泛的针对KVM虚拟机进 ...
- Mongoose 预定义模式修饰符 Getters 与 Setters 自定义修饰符
mongoose 预定义模式修饰符 mongoose 提供的预定义模式修饰符,可以对我们增加的数据进行一些格式化,主要有:lowercase.uppercase .trim,这里不一一演示,对trim ...