本节介绍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 ;
}
烧录程序,观察状态