来自Linux Zynq Embedded的程序LED

时间:2017-11-02 12:46:37

标签: c linux embedded xilinx gpio

我正在尝试使用Linux在Xilinx zc706主板上闪烁LED。

https://www.xilinx.com/products/boards-and-kits/ek-z7-zc706-g.html

我已经能够使用此处说明的方法在Linux中切换GPIO

https://falsinsoft.blogspot.com/2012/11/access-gpio-from-linux-user-space.html

在基本用户空间程序中。

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>

int main()
{

    int valuefd, exportfd, directionfd;

    printf("GPIO test running...\n");

    exportfd = open("/sys/class/gpio/export", O_WRONLY);

    if(exportfd < 0)
    {
        printf("Cannot open GPIO to export it\n");
        exit(1);
    }

    write(exportfd, "971", 4);
    close(exportfd);

    printf("GPIO exported successfully\n");

    directionfd = open("/sys/class/gpio/gpio971/direction", O_RDWR);

    if(directionfd < 0)
    {
        printf("Cannot open GPIO direction it\n");
        exit(1);
    }

    write(directionfd, "out", 4);
    close(directionfd);

    printf("GPIO direction set as output successfully\n");

    valuefd = open("/sys/class/gpio/gpio971/value", O_RDWR);

    if(valuefd < 0)
    {
        printf("Cannot open GPIO value\n");
        exit(1);
    }

    printf("GPIO value opened, now toggling...\n");

    while(1)
    {
        write(valuefd, "1", 2);
        write(valuefd, "0", 2);
    }


    return 0;
}

我的问题是,软件中是否存在某种方式将我在Linux中使用的GPIO号映射到控制LED的GPIO。感谢。

0 个答案:

没有答案