深入分析GPIOPS驱动代码1,Zedboard,zynq7000

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/p/3124040.html