1.fpga_check.py
import os
import sys
import subprocess
char_0 = './perfq_app -b 0000:'
char_1 = sys.argv[1]
char_2 = ':00.0 -o -R 0x1000'
command = char_0 + char_1 + char_2
print(command)
FPGA_Version = 'PIO Reg:0x1000 value:0x000001d2'
Read_Version = ''
var = subprocess.check_output(command, shell=True).decode('utf-8')
fp = open('fpga_test.txt', 'w')
fp.write(var)
fp.close()
fp = open('fpga_test.txt', 'r')
sample = fp.readlines()
for line in sample:
line = line.strip()
if 'Reg:0x1000' in line:
Read_Version = line
fp.close()
os.system('sudo rm fpga_test.txt')
if Read_Version == FPGA_Version:
print('FPGA Version is ok !')
else:
print(var)
print('Please check the version !')
2.pcie_check.py
import os
import sys
char_0 = 'lspci -vvv -s '
char_1 = sys.argv[1]
char_2 = ':00.0 > FPGA_lspci_info.txt'
command = char_0 + char_1 + char_2
os.system(command)
Altera_Corporation_Device = 'Altera Corporation Device 0000'
Region_0 = 'size=4M'
Region_2 = 'size=16K'
LnkCap = 'Speed 16GT/s, Width x16'
LnkSta_0 = 'Speed 16GT/s'
LnkSta_1 = 'Width x16'
var = [0] * 10
i = 0
fp = open("FPGA_lspci_info.txt", "r")
sample = fp.readlines()
for line in sample:
line = line.strip()
if 'Unassigned class' in line:
var[i] = line
i = i + 1
if 'Region 0: Memory' in line:
var[i] = line
i = i + 1
if 'Region 2: Memory' in line:
var[i] = line
i = i + 1
if 'LnkCap:' in line:
var[i] = line
i = i + 1
if 'LnkSta:' in line:
var[i] = line
i = i + 1
fp.close()
if Altera_Corporation_Device in var[0]:
print('Altera Corporation Device PASS')
else:
print('ERROR')
if Region_0 in var[1]:
print('Region 0 PASS')
else:
print('ERROR')
if Region_2 in var[2]:
print('Region 2 PASS')
else:
print('ERROR')
if LnkCap in var[3]:
print('LnkCap PASS')
else:
print('ERROR')
if LnkSta_0 in var[4] and LnkSta_1 in var[4]:
print('LnkSta PASS')
else:
print('ERROR')
os.system('sudo rm FPGA_lspci_info.txt')
3.pcie.py
import os
import sys
import subprocess
from random import *
card_char = sys.argv[1]
times = sys.argv[2]
times = int(times)
if len(sys.argv) != 3:
print('Please input the appropriate board and test times !')
sys.exit(1)
char1 = '0000:'
char2 = ':00.0'
new_card = char1 + card_char + char2
Write_and_Read_1020 = './perfq_app -b 0000:b3:00.0 -o -W 0x1020 -D 0xaabbccdd'
Write_and_Read_1024 = './perfq_app -b 0000:b3:00.0 -o -W 0x1024 -D 0xaabbccdd'
Write_and_Read_1020 = Write_and_Read_1020.replace('0000:b3:00.0', new_card)
Write_and_Read_1024 = Write_and_Read_1024.replace('0000:b3:00.0', new_card)
abb = '0xaabbccdd'
New_Write_and_Read_1020 = ''
New_Write_and_Read_1024 = ''
result = 'PIO Test Successful 0'
def random_number():
a = "".join([choice("0123456789abcdef") for i in range(8)])
return a
def new_command(Write_and_Read_1020, abb):
abc = random_number()
New_Write_and_Read_1020 = Write_and_Read_1020.replace(abb, abc)
return New_Write_and_Read_1020
print("Test read and write fpga reg ing ......")
fp = open('pcie_WR_reg.txt', 'w')
for i in range(times):
New_Write_and_Read_1020 = new_command(Write_and_Read_1020, abb)
var = subprocess.check_output(New_Write_and_Read_1020, shell=True).decode('utf-8')
if result in var:
pass
else:
print("error : read and write 1020 fpga reg is error")
sys.exit(1)
fp.write(var)
New_Write_and_Read_1024 = new_command(Write_and_Read_1024, abb)
var = subprocess.check_output(New_Write_and_Read_1024, shell=True).decode('utf-8')
if result in var:
pass
else:
print("error : read and write 1024 fpga reg is error")
sys.exit(1)
fp.write(var)
if i == (times - 1):
print("Test read and write fpga 1024 and 1020 reg is success !")
print (times)
fp.close()
sys.exit(1)
print("Test read and write fpga 1024 reg ing ......")
for i in range(times):
New_Write_and_Read_1024 = new_command(Write_and_Read_1024, abb)
var = subprocess.check_output(New_Write_and_Read_1024, shell=True).decode('utf-8')
if result in var:
if i == (times -1):
print("Test read and write fpga 1024 reg 500 times is success !")
else:
print("error :est read and write 1024 fpga reg 500 times is error")
sys.exit(1)
如下取出第8位和第16位。
Return_value_bit8_bit16(){
value=$1
tmp1=$((0x$value >> 8))
value_bit8=$((0x$tmp1 & 0x01))
tmp2=$((0x$value >> 16))
value_bit16=$((0x$tmp2 & 0x01))
if [ $value_bit8 -eq 0 ] && [ $value_bit16 -eq 0 ]
then
echo "pass"
else
echo "error : Please confirm the return value !"
exit 1
fi
}
Return_value_bit8_bit16 abcc10de
4.读TMP112进出口温度
Read_TMP112_temperature_Inlet()
{
i2c-test -b 7 -s 0x71 -w -d 0x08
tmp=$(i2c-test -b 7 -s 0x48 -m 1 -rc 2 -d 0x00)
tmp_h=${tmp:14:2}
tmp_l=${tmp:17:2}
tmp=${tmp_h}${tmp_l}
tmp=$((0x${tmp}>>8))"°C"
time=$(date "+%Y-%m-%d %H:%M:%S")
echo $time "TMP112 Inlet Temperature : " $tmp >> ./sensors.log
}
5.End/Run 9548_sensors
start_ipmistack()
{
cnt=0
while true
do
/etc/init.d/ipmistack start >/dev/null 2>&1
s1=$(ps aux)
s2="/usr/local/bin/IPMIMain"
result=$(echo $s1 | grep "${s2}")
if [[ "$result" != "" ]]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to start ipmistack !"
exit
fi
cnt=$(($cnt+1))
sleep 10
done
}
while true
do
ps -p $1
if [ $? -ne 0 ]
then
start_ipmistack
exit
fi
sleep 1
done
stop_ipmistack()
{
cnt=0
while true
do
/etc/init.d/ipmistack stop >/dev/null 2>&1
s1=$(ps aux)
s2="/usr/local/bin/IPMIMain"
result=$(echo $s1 | grep "${s2}")
if [[ "$result" == "" ]]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to stop ipmistack !"
exit
fi
cnt=$(($cnt+1))
sleep 10
done
}
delete()
{
cnt=0
while true
do
echo 0x73 > /sys/bus/i2c/devices/i2c-7/delete_device
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to delete device !"
exit
fi
cnt=$(($cnt+1))
done
}
access()
{
cnt=0
while true
do
i2c-test -b 7 -s 0x73 -w -d 0x08 >/dev/null 2>&1
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to access 9545 !"
exit
fi
cnt=$(($cnt+1))
done
}
start_ipmistack()
{
cnt=0
while true
do
/etc/init.d/ipmistack start >/dev/null 2>&1
s1=$(ps aux)
s2="/usr/local/bin/IPMIMain"
result=$(echo $s1 | grep "${s2}")
if [[ "$result" != "" ]]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to start ipmistack !"
exit
fi
cnt=$(($cnt+1))
sleep 10
done
}
start_ipmistack
stop_ipmistack
delete
access
chmod +x ./*.sh
./End_9548_sensors_info.sh $$ &
while :
do
./Read_TMP112_temperature.sh
./Read_PXE1410CDM_0X62_Voltage_Current.sh
./Read_PXE1410CDM_0X60_Voltage_Current.sh
./Read_INA220_Voltage.sh
./Read_FPGA_Power.sh
./Read_ADS7830_0x49_Voltage.sh
./Read_ADS7830_0x48_Voltage.sh
done
6.控制风扇速度
#!/bin/sh
usage(){
program=$(basename "$0")
echo "Usage:"
echo "$program <precent> "
echo " <precent> : fan speed set"
echo "Note:"
echo " precent:from 0 ro 100"
echo "Examples:"
echo " $program 30"
echo ""
}
check_parameter(){
if [ $# -ne 1 ];then
usage
exit 0
fi
if [ $1 -lt 0 -o $1 -gt 100 ];then
usage
exit 0
fi
}
dec2hex(){
printf "%x" $1
}
switch_arg(){
fullvalue=255
declare -i setvalue=(255*$1)/100
regvalue=$(dec2hex $setvalue)
echo "$regvalue"
}
do_action(){
regdata=$(switch_arg $1)
echo "i2cset -y 44 0x0d 0x22 0x$regdata"
}
check_parameter "$@"
do_action "$@"
|