ZYNQ 在linux 通过AXI_GPIO操作电平

在petalinux 通过AXI_GPIO操作电平,以zynq为例,vivado工程:

ZYNQ 在linux 通过AXI_GPIO操作电平_第1张图片

axi_gpio_n都是选择的一位输出:

ZYNQ 在linux 通过AXI_GPIO操作电平_第2张图片

管脚约束:

set_property SEVERITY {Warning} [get_drc_checks UCIO-1]
set_property SEVERITY {Warning} [get_drc_checks NSTD-1]
set_property PACKAGE_PIN J16 [get_ports AXI_GPIO_LED1_tri_o]
set_property IOSTANDARD LVCMOS33 [get_ports AXI_GPIO_LED1_tri_o]

set_property PACKAGE_PIN K16 [get_ports AXI_GPIO_LED2_tri_o]
set_property IOSTANDARD LVCMOS33 [get_ports {AXI_GPIO_LED2_tri_o}]

set_property PACKAGE_PIN G15 [get_ports AXI_GPIO_LED3_tri_o]
set_property IOSTANDARD LVCMOS33 [get_ports AXI_GPIO_LED3_tri_o]

set_property PACKAGE_PIN H15 [get_ports AXI_GPIO_LED4_tri_o]
set_property IOSTANDARD LVCMOS33 [get_ports AXI_GPIO_LED4_tri_o]

AXI_GPIO驱动在生成启动文件的时候,是默认编译的。

然后编译制作SD卡启动文件,然后写入程序测试:arm-linux-gnueabihf-gcc test_led.c -o test_led

#include
#include
#include
int main(int argc, char **argv)
{     
        int valuefd,exportfd,directionfd;     
    exportfd = open("/sys/class/gpio/export", O_WRONLY);  //打开设备       
    if(exportfd<0)
        {
           printf("open exportfd faild\n");
       exit(1);
        }  
        write(exportfd,"1023",4);
    close(exportfd);
        printf("1,exportfd open successful\n");
    directionfd = open("/sys/class/gpio/gpio1023/direction", O_RDWR);
    if(directionfd<0)
        {
           printf("open directionfd faild\n");
       exit(1);
        }  
        write(directionfd,"out",4);
    close(directionfd);
        printf("2,directionfd open successful\n");
        valuefd = open("/sys/class/gpio/gpio1023/value", O_RDWR);
    if(valuefd <0)
        {
           printf("open valuefd faild\n");
       exit(1);
        }  
        write(valuefd,"0",2);
    usleep(200*1000);
    write(valuefd,"1",2);
        printf("3,valuefd open successful\n");
}

 

 

或者在zynq板子写入脚本测试

#!/bin/sh
gpio_test()
{
     gpio=$1
    echo $gpio > /sys/class/gpio/export
    echo out > /sys/class/gpio/gpio${gpio}/direction
    for i in $(seq 1 3)
    do
    echo 0 >/sys/class/gpio/gpio${gpio}/value
    sleep 1
    echo 1 >/sys/class/gpio/gpio${gpio}/value
    sleep 1
    done
    echo $gpio > /sys/class/gpio/unexport
}
gpio_test 897
gpio_test 1015
gpio_test 1019
gpio_test 1020

你可能感兴趣的:(ZYNQ 在linux 通过AXI_GPIO操作电平)