49_ZYNQ7020开发板SDK_逻辑ARM_PS_LED/EMIO输入输出

本节介绍EMIO控制PL端LED灯的亮灭,同时介绍利用EMIO连接PL端按键控制PL端的LED灯。
一、前言
前面介绍了PS端MIO的结构如下,从图中可知BANK0和BANK1的MIO有54个。BANK2和BANK3的EMIO有64个,本节采用EMIO控制PL端LED。
在这里插入图片描述
LED与KEY的PL端原理图
在这里插入图片描述

二、Vivado工程建立
1.以ps_hello工程为基础,另存一个名为ps_emio工程,打开ZYNQ配置,把GPIO EMIO勾选上。
在这里插入图片描述
2.在MIO配置中选择EMIO的位宽为5位,因为PL端的LED有四个,使用PL端的一个按键。配置结束,点击OK。
在这里插入图片描述
3.点击多出对的GPIO_0端口右键选择Make External,将端口信号导出
在这里插入图片描述
4.修改引脚名称为emio,修改结果保存设计
在这里插入图片描述
5.点击xx.bd右键选择Generate Output Products,重新生成输出文件
在这里插入图片描述
6.结束后,顶层文件会更新出新的管脚,下面对其进行引脚绑定
在这里插入图片描述
7.XDC文件约束PL管脚,新建XDC文件,绑定PL端引脚
在这里插入图片描述
设置名字为emio
在这里插入图片描述
8.emio.xdc添加一下内容,端口名称一定要和顶层文件端口一致
在这里插入图片描述

set_property IOSTANDARD LVCMOS33 [get_ports {emio_tri_io[*]}]
#pl led
set_property PACKAGE_PIN M14 [get_ports {emio_tri_io[0]}]
set_property PACKAGE_PIN M15 [get_ports {emio_tri_io[1]}]
set_property PACKAGE_PIN K16 [get_ports {emio_tri_io[2]}]
set_property PACKAGE_PIN J16 [get_ports {emio_tri_io[3]}]
#pl key
set_property PACKAGE_PIN N15 [get_ports {emio_tri_io[4]}]

9.生成bit文件
在这里插入图片描述
10.导出硬件
在这里插入图片描述
11.因为要用PL,所以选择“include bitstream”,点击“OK”

软件工程师内容

一、点击PL端的LED灯
1)进入SDK软件,新建名为emio_led_test1的过程

在这里插入图片描述
2)代码部分与PS端MIO操作点亮LED类似,由于MIO的编号是0~53,因此EMIO的编号是从54开始
在这里插入图片描述

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

/*
 * helloworld.c: simple test application
 *
 * This application configures UART 16550 to baud rate 9600.
 * PS7 UART (Zynq) is not initialized by this application, since
 * bootrom/bsp configures it to baud rate 115200
 *
 * ------------------------------------------------
 * | UART TYPE   BAUD RATE                        |
 * ------------------------------------------------
 *   uartns550   9600
 *   uartlite    Configurable only in HW design
 *   ps7_uart    115200 (configured by bootrom/bsp)
 */

#include <stdio.h>
#include "platform.h"
#include "xil_printf.h"
#include "xgpiops.h"
#include "sleep.h"

#define GPIO_DEVICE_ID		XPAR_XGPIOPS_0_DEVICE_ID

/*
 * The following are declared globally so they are zeroed and can be
 * easily accessible from a debugger.
 */
XGpioPs Gpio;	/* The driver instance for GPIO Device. */

int main()
{
	init_platform();

	int Status;
	XGpioPs_Config *ConfigPtr;

	print("Hello World\n\r");
	/* Initialize the GPIO driver. */
	ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);

	Status = XGpioPs_CfgInitialize(&Gpio, ConfigPtr,
			ConfigPtr->BaseAddr);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Set the direction for the pin to be output and
	 * Enable the Output enable for the LED Pin.
	 */
	XGpioPs_SetDirectionPin(&Gpio, 54, 1);
	XGpioPs_SetDirectionPin(&Gpio, 55, 1);
	XGpioPs_SetDirectionPin(&Gpio, 56, 1);
	XGpioPs_SetDirectionPin(&Gpio, 57, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, 54, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, 55, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, 56, 1);
	XGpioPs_SetOutputEnablePin(&Gpio, 57, 1);

	while(1){
		/* Set the GPIO output to be low. */
		XGpioPs_WritePin(&Gpio, 54, 0x0);
		XGpioPs_WritePin(&Gpio, 55, 0x0);
		XGpioPs_WritePin(&Gpio, 56, 0x0);
		XGpioPs_WritePin(&Gpio, 57, 0x0);
		sleep(1) ;
		/* Set the GPIO output to be high. */
		XGpioPs_WritePin(&Gpio, 54, 0x1);
		XGpioPs_WritePin(&Gpio, 55, 0x1);
		XGpioPs_WritePin(&Gpio, 56, 0x1);
		XGpioPs_WritePin(&Gpio, 57, 0x1);
		sleep(1) ;
	}

	cleanup_platform();
	return 0;
}

在这里插入图片描述
在这里插入图片描述
二、PL端的KEY点亮LED
通过PL端的按键控制PL端LED灯的亮灭
1)新建工程名字为emio_key_test1的过程,模板为hello world
在这里插入图片描述
2)由PS端的MIO的使用MIO按键中断程序移植过来,并修改按键的编号为58,LED灯编号为54,保存
在这里插入图片描述

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

/*
 * helloworld.c: simple test application
 *
 * This application configures UART 16550 to baud rate 9600.
 * PS7 UART (Zynq) is not initialized by this application, since
 * bootrom/bsp configures it to baud rate 115200
 *
 * ------------------------------------------------
 * | UART TYPE   BAUD RATE                        |
 * ------------------------------------------------
 *   uartns550   9600
 *   uartlite    Configurable only in HW design
 *   ps7_uart    115200 (configured by bootrom/bsp)
 */

#include "xparameters.h"
#include "xscugic.h"
#include "xgpiops.h"
#include "xil_printf.h"
#include "xil_exception.h"

/* GPIO paramter */
#define MIO_ID          XPAR_PS7_GPIO_0_DEVICE_ID
#define INTC_DEVICE_ID	XPAR_SCUGIC_SINGLE_DEVICE_ID
#define KEY_INTR_ID     XPAR_XGPIOPS_0_INTR
#define EMIO_KEY      58
#define EMIO_LED      54

#define GPIO_INPUT      0
#define GPIO_OUTPUT     1

int key_flag ;
XGpioPs GPIO_PTR ;

XScuGic INTCInst;


int IntrInitFuntion(XScuGic *InstancePtr, u16 DeviceId, XGpioPs *GpioInstancePtr);
void GpioHandler(void *CallbackRef);

int main()
{
	XGpioPs_Config *GpioConfig ;
	int Status ;
	int key_val  = 0 ;

	key_flag = 0 ;

	/*
	 * Initialize the gpio.
	 */
	GpioConfig = XGpioPs_LookupConfig(MIO_ID) ;
	Status = XGpioPs_CfgInitialize(&GPIO_PTR, GpioConfig, GpioConfig->BaseAddr) ;
	if (Status != XST_SUCCESS)
	{
		return XST_FAILURE ;
	}
	/*
	 * Set the direction for the pin to be output and
	 * Enable the Output enable for the LED Pin.
	 */
	XGpioPs_SetDirectionPin(&GPIO_PTR, EMIO_LED, GPIO_OUTPUT) ;
	XGpioPs_SetOutputEnablePin(&GPIO_PTR, EMIO_LED, GPIO_OUTPUT) ;
	/*
	 * Set the direction for the pin to be input.
	 * Set interrupt type as rising edge and enable gpio interrupt
	 */
	XGpioPs_SetDirectionPin(&GPIO_PTR, EMIO_KEY, GPIO_INPUT) ;
	XGpioPs_SetIntrTypePin(&GPIO_PTR, EMIO_KEY, XGPIOPS_IRQ_TYPE_EDGE_RISING) ;
	XGpioPs_IntrEnablePin(&GPIO_PTR, EMIO_KEY) ;
	/*
	 * sets up the interrupt system
	 */
	Status = IntrInitFuntion(&INTCInst, MIO_ID, &GPIO_PTR) ;
	if (Status != XST_SUCCESS)
		return XST_FAILURE ;

	while(1)
	{
		if (key_flag)
		{
			XGpioPs_WritePin(&GPIO_PTR, EMIO_LED, key_val) ;
			key_val = ~key_val ;
			key_flag = 0 ;
		}

	}

	return 0 ;
}


int IntrInitFuntion(XScuGic *InstancePtr, u16 DeviceId, XGpioPs *GpioInstancePtr)
{
	XScuGic_Config *IntcConfig;
	int Status ;
	/*
	 * Initialize the interrupt controller driver so that it is ready to
	 * use.
	 */
	IntcConfig = XScuGic_LookupConfig(INTC_DEVICE_ID);

	Status = XScuGic_CfgInitialize(InstancePtr, IntcConfig, IntcConfig->CpuBaseAddress) ;
	if (Status != XST_SUCCESS)
		return XST_FAILURE ;

	/*
	 * set priority and trigger type
	 */
	XScuGic_SetPriorityTriggerType(InstancePtr, KEY_INTR_ID,
			0xA0, 0x3);
	/*
	 * Connect the device driver handler that will be called when an
	 * interrupt for the device occurs, the handler defined above performs
	 * the specific interrupt processing for the device.
	 */
	Status = XScuGic_Connect(InstancePtr, KEY_INTR_ID,
			(Xil_ExceptionHandler)GpioHandler,
			(void *)GpioInstancePtr) ;
	if (Status != XST_SUCCESS)
		return XST_FAILURE ;

	/*
	 * Enable the interrupt for the device.
	 */
	XScuGic_Enable(InstancePtr, KEY_INTR_ID) ;

	Xil_ExceptionInit();

	Xil_ExceptionRegisterHandler(XIL_EXCEPTION_ID_INT,
			(Xil_ExceptionHandler)XScuGic_InterruptHandler,
			InstancePtr);
	Xil_ExceptionEnable();

	return XST_SUCCESS ;

}


void GpioHandler(void *CallbackRef)
{
	XGpioPs *GpioInstancePtr = (XGpioPs *)CallbackRef ;
	int Int_val ;

	Int_val = XGpioPs_IntrGetStatusPin(GpioInstancePtr, EMIO_KEY) ;
	/*
	 * Clear interrupt.
	 */
	XGpioPs_IntrClearPin(GpioInstancePtr, EMIO_KEY) ;
	if (Int_val)
		key_flag = 1 ;
}

烧录程序,观察状态
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
xilinx_zynq7020 自定义 IP 开发文档是一份描述如何开发和使用自定义 IP(Intelligent Property)的技术文档。Zynq-7020 是 Xilinx 公司生产的一款可编程逻辑器件,搭载了 ARM 处理器和 FPGA 芯片,能够同时实现软件和硬件设计,为嵌入式系统开发提供一种更灵活的解决方案。 在自定义 IP 开发文档中,我们将了解如何使用 Vivado 设计套件来开发自己的 IP。首先,我们需要对 IP 的功能和硬件架构进行规划和设计。可以选择将已有的硬件模块集成为 IP 核,也可以通过硬件描述语言(HDL)从零开始编写 IP 核。然后,我们将详细说明如何使用 Vivado 的 IP Integrator 工具集成 IP 核到我们的设计中,并进行连接和配置。 在自定义 IP 开发文档中,我们还将了解如何为 IP 核创建适当的接口,包括输入输出口和控制寄存器等。可以通过使用 AXI 或者其他总线协议来定义接口。此外,我们还将学习如何为 IP 核编写相应的测试代码,并在仿真和实际硬件中进行验证和调试。 除了基础的 IP 开发知识,这份文档还提供了一些高级话题,如如何优化 IP 核的性能,如何编写可重用的 IP 代码等。另外,文档还包含了一些实际案例,以帮助读者更好地理解和应用这些知识。 总之,xilinx_zynq7020 自定义 IP 开发文档详细介绍了如何使用 Vivado 设计套件开发和使用自定义 IP 核。通过学习这份文档,读者可以了解到 IP 开发的基础知识,掌握相关工具的使用方法,并具备开发和优化 IP 核的能力,从而更好地应用于各种嵌入式系统开发中。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值