MPSoC 為PL提供了96個GPIO,通過EMIO管腳鏈接到PL。
普通PL設(shè)計(jì),一般只會用到幾個GPIO管腳??梢允褂肰ivado IPI中的Slice IP, 從其中分出指定數(shù)量的管腳。
Slice配置界面
上圖中,輸入寬度是95,因?yàn)閜l_reset占用率一個管腳。slice從輸入中提取emio的[7:5]三位,作為輸出。
Xilinx Linux 中缺省使能了GPIO驅(qū)動。對于MPSoC,檢查目錄/sys/class/gpio,可以看到設(shè)備gpiochip338。
# ls -l /sys/class/gpio total 0 export gpiochip306 -> ../../devices/platform/amba/ff020000.i2c/i2c-0/0-0021/gpio/gpiochip306 gpiochip322 ->../../devices/platform/amba/ff020000.i2c/i2c-0/0-0020/gpio/gpiochip322 gpiochip338 -> ../../devices/platform/amba/ff0a0000.gpio/gpio/gpiochip338 unexport # ls /sys/class/gpio/gpiochip338/ -l total 0 base device -> ../../../ff0a0000.gpio label ngpio power subsystem -> ../../../../../../class/gpio uevent
Linux GPIO Driver下的GPIO使用,可以參考Linux GPIO Driver;GPIO User Space App。
從上述文章可以看到,使用GPIO不簡單。
為了簡化使用GPIO,編寫了以下腳本。使用下列腳本,一條命令就能設(shè)置一個GPIO的輸出值。腳本接受兩個輸入參數(shù)。第一個參數(shù)表示GPIO編號,MIO GPIO從0開始,EMIO GPIO從78開始。第二個參數(shù)是輸出值。如果輸出值是1,可以省略第二個參數(shù)。
#/bin/bash function gpio_output_func() { #echo "No.1 parameter: $1" #echo "No.2 parameter: $2" # MPSoC GPIO number. gpio_num=$[338+$1] # MPSoC EMIO GPIO number. # gpio_num=$[338+78+$1] echo "Set GPIO number: $gpio_num to value: $2" if [ ! -f /sys/class/gpio/gpio$gpio_num/direction ]; then # Export a GPIO pin echo $gpio_num > /sys/class/gpio/export fi # Read the direction and value from the GPIO pin */ # ls -l /sys/class/gpio/gpio$gpio_num/ gpio_direction=`cat /sys/class/gpio/gpio$gpio_num/direction` gpio_value=`cat /sys/class/gpio/gpio$gpio_num/value` echo -e "GPIO number: $gpio_num previous direction: $gpio_direction, previous value: $gpio_value/b" # Set the direction to an output and write a value 1 to GPIO pin */ echo out > /sys/class/gpio/gpio$gpio_num/direction echo $2 > /sys/class/gpio/gpio$gpio_num/value gpio_direction=`cat /sys/class/gpio/gpio$gpio_num/direction` gpio_value=`cat /sys/class/gpio/gpio$gpio_num/value` echo -e "GPIO number: $gpio_num current direction: $gpio_direction, current value: $gpio_value/b" } # Check GPIO chip gpio_chip=`cat /sys/class/gpio/gpiochip338/label` gpio_base=`cat /sys/class/gpio/gpiochip338/base` gpio_number=`cat /sys/class/gpio/gpiochip338/ngpio` echo "MPSoC GPIO information: chip: $gpio_chip, base: $gpio_base, number: $gpio_number." # cat /sys/class/gpio/gpiochip338/label # cat /sys/class/gpio/gpiochip338/base # cat /sys/class/gpio/gpiochip338/ngpio # The above line indicates that gpio 0th pin starts from 338 and ends at 511 (GPIO has total 174 pins for ZynqMP) if [ "$2" = "" ]; then gpio_output_func $1 1 else gpio_output_func $1 $2 fi
執(zhí)行記錄
# ./gpio_single_output.sh 81 MPSoC GPIO information: chip: zynqmp_gpio, base: 338, number: 174. Set GPIO number: 419 to value: 1 GPIO number: 419 previous direction: out, previous value: 0 GPIO number: 419 current direction: out, current value: 1 # ./gpio_single_output.sh 81 0 MPSoC GPIO information: chip: zynqmp_gpio, base: 338, number: 174. Set GPIO number: 419 to value: 0 GPIO number: 419 previous direction: out, previous value: 1 GPIO number: 419 current direction: out, current value: 0
-
Linux
+關(guān)注
關(guān)注
87文章
11207瀏覽量
208716 -
Xilinx
+關(guān)注
關(guān)注
71文章
2155瀏覽量
120850 -
GPIO
+關(guān)注
關(guān)注
16文章
1188瀏覽量
51832 -
MPSoC
+關(guān)注
關(guān)注
0文章
196瀏覽量
24230
發(fā)布評論請先 登錄
相關(guān)推薦
評論