IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> Python知识库 -> 【Notes17】检查FPGA版本,检查PCIE读写性能,TMP112,End/Run 9548_sensors,控制Fan转速 -> 正文阅读

[Python知识库]【Notes17】检查FPGA版本,检查PCIE读写性能,TMP112,End/Run 9548_sensors,控制Fan转速


1.fpga_check.py

# fpga_check.py 为检查FPGA版本脚本。
# 将fpga_check.py 拷贝到perfq_app所在的目录下执行。
#(/commit_code/ali_fpga/software/user/cli/perfq_app/)该脚本运行于OS下。
# 使用命令 python fpga_check.py b1  运行脚本。(参数1为 PCIE bus,根据实际情况传参)。

# coding = utf-8
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

# pcie_check.py脚本是检查PCIE的Corporation Device 、Region 0、Region 2、LnkCap、LnkSta信息。
# 注意板卡所在插槽位置。使用命令python pcie_check.py  b1运行脚本。
# b1为PCIE bus,根据实际情况传参。运行命令屏幕会显示相应需要检查信息的正确和错误信息。

# coding = utf-8
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

# pcie.py脚本是对PCIE通道的性能测试,主要是对FPGA寄存器读写压力测试,从而对PCIE性能进行测试。
# 请确保目录 ~/commit_code/ali_fpga/software/user/cli/perfq_app/ 目录下存在perfq_app 工具。
# 在os下将脚本文件拷到perfq_app所在的目录下使用命令 python pcie.py 参数1  参数2 运行脚本(参数1为板卡所在的号码如 b3 , 参数2为读写的次数)。 
# 运行脚本,屏幕会显示相应的错误和正确信息。

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()  #abc为随机数 
    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)) #前面都是0
    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.sh
Read_TMP112_temperature_Inlet()
{
    i2c-test -b 7 -s 0x71 -w -d 0x08    # 出口0x40
    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"
    # echo $tmp
    time=$(date "+%Y-%m-%d %H:%M:%S")
    echo $time "TMP112 Inlet Temperature : " $tmp >> ./sensors.log
}

5.End/Run 9548_sensors

# End_9548_sensors_info.sh:关闭主进程后重新开ipmitool
#!/bin/bash
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
# Run_9548_sensors_info.sh
#!/bin/bash
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 $cnt
          echo "Unable to access 9545 !"
          exit
        fi
        cnt=$(($cnt+1))
        #echo $cnt
    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 $$ &  #这行Shell本身的PID
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"
    #i2cset -y 44 0x0d 0x22 0x$regdata
    #i2cset -y 44 0x0d 0x32 0x$regdata
    #i2cset -y 44 0x0d 0x42 0x$regdata
    #i2cset -y 44 0x0d 0x52 0x$regdata

    #i2cset -y 108 0x0d 0x22 0x$regdata
    #i2cset -y 108 0x0d 0x32 0x$regdata
    #i2cset -y 108 0x0d 0x42 0x$regdata
    #i2cset -y 108 0x0d 0x52 0x$regdata
}

check_parameter "$@"
do_action "$@"

在这里插入图片描述

  Python知识库 最新文章
Python中String模块
【Python】 14-CVS文件操作
python的panda库读写文件
使用Nordic的nrf52840实现蓝牙DFU过程
【Python学习记录】numpy数组用法整理
Python学习笔记
python字符串和列表
python如何从txt文件中解析出有效的数据
Python编程从入门到实践自学/3.1-3.2
python变量
上一篇文章      下一篇文章      查看所有文章
加:2021-10-12 23:23:18  更:2021-10-12 23:24:02 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 18:46:18-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码