• PS端GPIO配置和基本介绍


    Xilinx PS GPIO 驱动程序。

    驱动程序支持 Xilinx PS GPIO 控制器。
    GPIO 控制器支持以下功能:

    The GPIO Controller supports the following features:

    • 4 banks
    • Masked writes (There are no masked reads)屏蔽写入
    • Bypass mode 旁路模式
    • Configurable Interrupts (Level/Edge)可配置中断(电平/边沿)

            该驱动程序旨在独立于 RTOS 和处理器。任何对动态内存管理、线程或线程互斥、虚拟内存或高速缓存控制的需求都必须由该驱动程序之上的层来满足。
    该驱动程序支持上面列出的所有功能(如果适用)。

    驱动程序描述

    设备驱动程序使高层软件(例如应用程序)能够与 GPIO 进行通信。

    中断

            驱动程序提供中断管理功能和中断处理程序。该驱动程序的用户需要提供回调函数。驱动程序提供了中断处理程序示例。


    线程

            该驱动程序不是线程安全的。任何线程或线程互斥的需求都必须由该驱动程序之上的层来满足。


    断言

            断言用于所有 Xilinx 驱动程序中,以强制对参数值进行约束。通过在编译时定义 NDEBUG 标识符,可以在系统范围内关闭断言。默认情况下,断言是打开的,建议用户在开发过程中将断言保持打开状态。


    构建驱动程序

            XGpioPs 驱动程序由多个源文件组成。这允许用户仅构建和链接驱动程序中必要的部分。

    所以需要引入头文件:

    1. #include "xparameters.h"
    2. #include "xgpiops.h"

    例程:

    1. /******************************************************************************
    2. * Copyright (C) 2010 - 2021 Xilinx, Inc. All rights reserved.
    3. * SPDX-License-Identifier: MIT
    4. *******************************************************************************/
    5. /*****************************************************************************/
    6. /**
    7. * @file xgpiops_polled_example.c
    8. *
    9. * This file contains an example for using GPIO hardware and driver. This
    10. * example provides the usage of APIs for reading/writing to the individual pins.
    11. * Please see xgpiops.h file for description of the pin numbering.
    12. *
    13. * @note This example assumes that there is a Uart device in the HW
    14. * design. This example is to provide support only for zcu102 on
    15. * ZynqMp Platform and only for zc702 on Zynq Platform.
    16. * For ZynqMP Platform, Input pin is 22(sw19 on zcu102 board) and Output Pin is
    17. * 23(DS50 on zcu102 board).
    18. * For Zynq Platform, Input Pins are 12(sw14 on zc702 board), 14(sw13 on
    19. * zc702 board) and Output Pin is 10(DS23 on zc702 board).
    20. * This example supports the VCK190 and VMK180 for Versal, but requires a PL
    21. * shim. See Answer Record AR# 75677 for details.
    22. * On the Versal Platform we have two GPIOPS instances :PMC GPIO and PS GPIO
    23. * PMC GPIO contain 4 banks and 116 pins, organized as follows:
    24. * Bank 0 I/Os: 25:0 (MIO)
    25. * Bank 1: I/Os: 51:26 (MIO)
    26. * Bank 3: I/Os: 83:52 (EMIO)
    27. * Bank 4: I/Os: 115:84 (EMIO)
    28. * PS GPIO contains 2 banks and 58 pins
    29. * Bank 0 I/Os: 25:0 (MIO)
    30. * Bank 3: I/Os: 57:26 (EMIO)
    31. * See Figure 61 in AM011 Versal TRM for details.
    32. * Driver supports both PS GPIO and PMC GPIO.
    33. * For accessing PMC GPIOs application you need to set "GPIO.PmcGpio = 1"
    34. * otherwise it accesses PS GPIO.
    35. *
    36. *
    37. * MODIFICATION HISTORY:
    38. *
    39. * Ver Who Date Changes
    40. * ----- ---- -------- -----------------------------------------------
    41. * 1.00a sv 01/18/10 First Release
    42. * 1.01a sv 04/15/12 Removed the calling of some unnecessary APIs.
    43. * Updated the examples for a ZC702 board .
    44. * Updated the example to use only pin APIs.
    45. * 3.3 ms 04/17/17 Added notes about input and output pin description
    46. * for zcu102 and zc702 boards.
    47. * 3.7 sne 12/04/19 Reverted versal example support.
    48. * 3.8 sne 09/17/20 Added description for Versal PS and PMC GPIO pins.
    49. * 3.9 sne 11/19/20 Added versal PmcGpio example support.
    50. *
    51. *
  • *
  • *****************************************************************************/
  • /***************************** Include Files ********************************/
  • #include "xparameters.h"
  • #include "xgpiops.h"
  • #include "xstatus.h"
  • #include "xplatform_info.h"
  • #include
  • /************************** Constant Definitions ****************************/
  • /*
  • * The following constants map to the XPAR parameters created in the
  • * xparameters.h file. They are defined here such that a user can easily
  • * change all the needed parameters in one place for ZYNQ & ZYNQMP.
  • */
  • #ifndef GPIO_DEVICE_ID
  • #define GPIO_DEVICE_ID XPAR_XGPIOPS_0_DEVICE_ID
  • #endif
  • /*
  • * The following constant is used to wait after an LED is turned on to make
  • * sure that it is visible to the human eye. This constant might need to be
  • * tuned for faster or slower processor speeds.
  • */
  • #define LED_DELAY 10000000
  • #define LED_MAX_BLINK 0x10 /* Number of times the LED Blinks */
  • #define printf xil_printf /* Smalller foot-print printf */
  • /**************************** Type Definitions ******************************/
  • /***************** Macros (Inline Functions) Definitions *******************/
  • /************************** Function Prototypes ****************************/
  • static int GpioOutputExample(void);
  • static int GpioInputExample(u32 *DataRead);
  • int GpioPolledExample(u16 DeviceId, u32 *DataRead);
  • /************************** Variable Definitions **************************/
  • static u32 Input_Pin; /* Switch button */
  • static u32 Output_Pin; /* LED button */
  • /*
  • * 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. */
  • /*****************************************************************************/
  • /**
  • *
  • * Main function to call the example.
  • *
  • *
  • * @return
  • * - XST_SUCCESS if the example has completed successfully.
  • * - XST_FAILURE if the example has failed.
  • *
  • * @note None
  • *
  • ******************************************************************************/
  • int main(void)
  • {
  • int Status;
  • u32 InputData;
  • printf("GPIO Polled Mode Example Test \r\n");
  • Status = GpioPolledExample(GPIO_DEVICE_ID, &InputData);
  • if (Status != XST_SUCCESS) {
  • printf("GPIO Polled Mode Example Test Failed\r\n");
  • return XST_FAILURE;
  • }
  • printf("Data read from GPIO Input is 0x%x \n\r", (int)InputData);
  • printf("Successfully ran GPIO Polled Mode Example Test\r\n");
  • return XST_SUCCESS;
  • }
  • /*****************************************************************************/
  • /**
  • *
  • * The purpose of this function is to illustrate how to use the GPIO driver to
  • * turn on/off an LED and read the inputs using the pin APIs.
  • *
  • * @param DeviceId is the XPAR__DEVICE_ID value from
  • * xparameters.h
  • * @param DataRead is the pointer where the data read from GPIO Input is
  • * returned.
  • *
  • * @return
  • * - XST_SUCCESS if the example has completed successfully.
  • * - XST_FAILURE if the example has failed.
  • *
  • * @note This function will not return if the test is running.
  • *
  • ******************************************************************************/
  • int GpioPolledExample(u16 DeviceId, u32 *DataRead)
  • {
  • int Status;
  • XGpioPs_Config *ConfigPtr;
  • int Type_of_board;
  • /* Initialize the GPIO driver. */
  • ConfigPtr = XGpioPs_LookupConfig(GPIO_DEVICE_ID);
  • Type_of_board = XGetPlatform_Info();
  • switch (Type_of_board) {
  • case XPLAT_ZYNQ_ULTRA_MP:
  • Input_Pin = 22;
  • Output_Pin = 23;
  • break;
  • case XPLAT_ZYNQ:
  • Input_Pin = 14;
  • Output_Pin = 10;
  • break;
  • #ifdef versal
  • case XPLAT_VERSAL:
  • /* Accessing PMC GPIO by setting field to 1 */
  • Gpio.PmcGpio = 1;
  • Input_Pin = 56;
  • Output_Pin = 52;
  • break;
  • #endif
  • }
  • Status = XGpioPs_CfgInitialize(&Gpio, ConfigPtr,
  • ConfigPtr->BaseAddr);
  • if (Status != XST_SUCCESS) {
  • return XST_FAILURE;
  • }
  • /* Run the Output Example. */
  • Status = GpioOutputExample();
  • if (Status != XST_SUCCESS) {
  • return XST_FAILURE;
  • }
  • /* Run the Input Example. */
  • Status = GpioInputExample(DataRead);
  • if (Status != XST_SUCCESS) {
  • return XST_FAILURE;
  • }
  • return XST_SUCCESS;
  • }
  • /*****************************************************************************/
  • /**
  • *
  • * This function does a minimal test on the GPIO device configured as OUTPUT.
  • *
  • * @param None.
  • *
  • * @return - XST_SUCCESS if the example has completed successfully.
  • * - XST_FAILURE if the example has failed.
  • *
  • * @note None.
  • *
  • ****************************************************************************/
  • static int GpioOutputExample(void)
  • {
  • u32 Data;
  • volatile int Delay;
  • u32 LedLoop;
  • /*
  • * Set the direction for the pin to be output and
  • * Enable the Output enable for the LED Pin.
  • */
  • XGpioPs_SetDirectionPin(&Gpio, Output_Pin, 1);
  • XGpioPs_SetOutputEnablePin(&Gpio, Output_Pin, 1);
  • /* Set the GPIO output to be low. */
  • XGpioPs_WritePin(&Gpio, Output_Pin, 0x0);
  • for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop ++) {
  • #ifndef __SIM__
  • /* Wait a small amount of time so the LED is visible. */
  • for (Delay = 0; Delay < LED_DELAY; Delay++);
  • #endif
  • /* Set the GPIO Output to High. */
  • XGpioPs_WritePin(&Gpio, Output_Pin, 0x1);
  • /*
  • * Read the state of the data and verify. If the data
  • * read back is not the same as the data written then
  • * return FAILURE.
  • */
  • Data = XGpioPs_ReadPin(&Gpio, Output_Pin);
  • if (Data != 1 ) {
  • return XST_FAILURE;
  • }
  • #ifndef __SIM__
  • /* Wait a small amount of time so the LED is visible. */
  • for (Delay = 0; Delay < LED_DELAY; Delay++);
  • #endif
  • /* Clear the GPIO Output. */
  • XGpioPs_WritePin(&Gpio, Output_Pin, 0x0);
  • /*
  • * Read the state of the data and verify. If the data
  • * read back is not the same as the data written then
  • * return FAILURE.
  • */
  • Data = XGpioPs_ReadPin(&Gpio, Output_Pin);
  • if (Data != 0) {
  • return XST_FAILURE;
  • }
  • }
  • return XST_SUCCESS;
  • }
  • /******************************************************************************/
  • /**
  • *
  • * This function performs a test on the GPIO driver/device with the GPIO
  • * configured as INPUT.
  • *
  • * @param DataRead is the pointer where the data read from GPIO Input is
  • * returned
  • *
  • * @return - XST_SUCCESS if the example has completed successfully.
  • * - XST_FAILURE if the example has failed.
  • *
  • * @note None.
  • *
  • ******************************************************************************/
  • static int GpioInputExample(u32 *DataRead)
  • {
  • /* Set the direction for the specified pin to be input. */
  • XGpioPs_SetDirectionPin(&Gpio, Input_Pin, 0x0);
  • /* Read the state of the data so that it can be verified. */
  • *DataRead = XGpioPs_ReadPin(&Gpio, Input_Pin);
  • return XST_SUCCESS;
  • }
  • 相关阅读:
    Logstash同步MySQL数据到Elasticsearch
    1.【算法五章】
    二分查找详解
    拯救pandas计划(24)——数据框形状的转换:​列转行,行转列
    【网络安全】文件包含漏洞--使用session进行文件包含
    记录JVM常用参数
    postgis limit 和 offset 的使用
    在Vue3项目中使用pinia代替Vuex进行数据存储
    Springboot毕设项目基于JavaWeb的模玩网站系统odk84(java+VUE+Mybatis+Maven+Mysql)
    MyBatis 动态SQL与分页
  • 原文地址:https://blog.csdn.net/NoNoUnknow/article/details/133562665