深入分析GPIOPS驱动代码-1,Zedboard,zynq-7000

本文详细介绍了如何在Zynq-7000 Cortex-A9中使用GPIO模块,包括配置初始化、设置方向、使能输出及基本应用示例。同时,针对初始化代码中的一些常见问题进行了分析,并提供了正确初始化GPIO的完整代码流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

How to use the GpioPs in zedboard

Different from other micro controller, the zynq-7000 cortex a9 has only a gpio module ,and the gpio driver api is designed for the only module, which is called XPAR_XGPIOPS_0_DEIVICE_ID,so when you want to invoke the gpiops module ,the following 2 sentences is neccssary.

XGpioPs_Config* pGpioPsCfg;

pGpioPsCfg=XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID);

XGpioPs gpiops;

XGpioPs_CfgInitialize(&gpiopps,pGpioPsCfg,pGpioPsCfg->BaseAddr);

    The driver will understand the gpio you specified according to the parameter: XPAR_XGPIOPS_0_DEVICE_ID;

    The simplest gpiops application is like this:

#include "XGpioPs.h"

XGpioPs_Config* pGpioPsCfg;

pGpioPsCfg=XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID);

XGpioPs gpiops;

XGpioPs_CfgInitialize(&gpiopps,pGpioPsCfg,pGpioPsCfg->BaseAddr);

    

XGpioPs_WritePin(&gpiops,0x7,0x1);

Build and run the code, LD9 will illumine immediately.

What happened?

    We have neither set up the direction of gpiops or set the output enabled, but why the code works?

    This is due to the bsp project code have done most of the periphals initialize works at first, and the default is seting gpiops MIO7 ouput direction and output enable, so we need not to init the gpiops once again.

The absolute code should like this:

#include "XGpioPs.h"

XGpioPs_Config* pGpioPsCfg;

pGpioPsCfg=XGpioPs_LookupConfig(XPAR_XGPIOPS_0_DEVICE_ID);

XGpioPs gpiops;

XGpioPs_CfgInitialize(&gpiopps,pGpioPsCfg,pGpioPsCfg->BaseAddr);

    

XGpioPs_SetOutputPin(&gpiops,0x7,0x1);

XGpioPs_SetOutputEnable(&gpiops,0x7,0x1);

XGpioPs_WritePin(&gpiops,0x7,0x1);

And now I will write a demo for uart according to the above format:

 

  1. Looking for the struct for xuartps, find in the driver/

    XUartPs_Config* pUartPs_Config;

    pUartPs_Config=XUartPs_LookupConfig(XPAR_XUARTPS_0_DEVICE_ID);

    XUartPs     UartPs;

    XUartPs_CfgInitialize(&UartPs,pUartPs_Config,pUartPs_Config->BaseAddress);

  1. Set the Baud Rate:

    XUartPs_SetBaudRate(&UartPs,9600);

  1. Send string:

    XUartPs_Send(&UartPs,"Hello,world.",12);

As what we respected, it works.

 

 

A Problem issued:

  1.     for (LedLoop = 0; LedLoop < LED_MAX_BLINK; LedLoop ++)

    Although you can find the LED_MAX_BLICK micro in other files(Use F3 can trace the micro),but if you not include it ,you should not use it.

转载于:https://www.cnblogs.com/dragen/archive/2013/06/07/3124040.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值