Note3MPS/PXE/ADS/INA电流电压芯片,i2c设备在位和读访问,FPGA版本,PCIE读写,TMP112,Fan转速,uuid库
Posted 码农编程录
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Note3MPS/PXE/ADS/INA电流电压芯片,i2c设备在位和读访问,FPGA版本,PCIE读写,TMP112,Fan转速,uuid库相关的知识,希望对你有一定的参考价值。
文章目录
- 1.读MPS5023芯片:0x03ff即将前6位屏蔽,hex->dec
- 2.读PXE1410CDM电压和电流:一个数&0x7ff(0000 0111 1111 1111),将这个数前5位全变为0,其余位不变
- 3.读ADS7830的8个channel电压: 无电流,max,min
- 4.读INA220电压和电流:Read_INA220_Voltage_Current.sh
- 5.check.sh:运行在BMC下用于检查i2c设备。会自动打印检查结果,须在脚本后添加检查次数,否则一直循环。./check.sh num
- 6.check.py:运行在OS下用于检查DDR SFP CPLD设备。自动打印检查结果,需在脚本后指定DDR的bus。python check.py bus
- 7.check_port_tx_rx_setup.sh:取出第8位和第16位
- 8.fpga_check.py:检查FPGA版本脚本,将fpga_check.py 拷贝到perfq_app所在的目录下执行
- 9.pcie_check.py:检查PCIE的Corporation Device 、Region 0、Region 2、LnkCap、LnkSta信息
- 10.pcie.py:对PCIE通道的性能测试,主要是对FPGA寄存器读写压力测试,从而对PCIE性能进行测试。运行脚本,屏幕会显示相应的错误和正确信息
- 11.读TMP112进出口温度:"+%Y-%m-%d %H:%M:%S"
- 12.控制风扇速度:十进制转十六进制
1.读MPS5023芯片:0x03ff即将前6位屏蔽,hex->dec
# Read_FPGA_Power.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 1
fi
cnt=$(($cnt+1))
sleep 10
done
delete()
cnt=0
while true
do
echo 0x73 > /sys/bus/i2c/devices/i2c-7/delete_device #将bus7上0x73这设备删除
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to delete device !"
exit 1
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 1
fi
cnt=$(($cnt+1))
echo $cnt
done
OpenChannel()
cnt=0
while true
do
i2c-test -b 7 -s 0x71 -w -d 0x80 >/dev/null 2>&1 #0x80打开channel8
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to access 9548 channel8 !"
exit 1
fi
cnt=$(($cnt+1))
done
read_voltage()
cnt=0
while true
do
val_v=$(i2c-test -b 7 -s 0x40 -m 1 -rc 2 -d 0x8b)
if [ $? = 0 ]
then
hexval_v_h=$val_v:14:2
hexval_v_l=$val_v:17:2
hexval_v=$hexval_v_l$hexval_v_h
#echo $hexval_v #0183
dec_v=$((0x$hexval_v & 0x3ff)) #&:有0为0,3ff:10个1, hex->dec
#echo $dec_v #388
dec_v_wv=$((dec_v*3125)) #31.25mV/LSB
dec_v_v=$((dec_v_wv/100000))
#echo $dec_v_v #12
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
read_power()
cnt=0
while true
do
val_a=$(i2c-test -b 7 -s 0x40 -m 1 -rc 2 -d 0x8c) #电流
if [ $? = 0 ]
then
hexval_a_h=$val_a:14:2
hexval_a_l=$val_a:17:2
hexval_a=$hexval_a_l$hexval_a_h
#echo $hexval_a #0054
dec_a=$((0x$hexval_a & 0x3ff))
dec_a_wa=$((dec_a*6250))
dec_a_a=$((dec_a_wa/100000))
#echo $dec_a_a
power=$(($dec_v_v * $dec_a_a))
echo "FPGA Power : "$power"W"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read electricity !"
exit 1
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 1
fi
cnt=$(($cnt+1))
sleep 10
done
start_ipmistack
stop_ipmistack
delete
access
OpenChannel
read_voltage
read_power
start_ipmistack
2.读PXE1410CDM电压和电流:一个数&0x7ff(0000 0111 1111 1111),将这个数前5位全变为0,其余位不变
ipmitool raw 0x3a 0x10 <bus id> <slave addr> <Read count> <Data to write>
(00:第一个状态码不显示)
status , log_psu1 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 14 0xb0 2 0x88) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
f=`../utility/diag-tools/pmbus_tool/line11 0x$d` ; echo $f'") # psu1 输入电压
status , log_psu2 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 15 0xb0 2 0x88) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
f=`../utility/diag-tools/pmbus_tool/line11 0x$d` ; echo $f'") # psu2 输入电压
status , log_psu11 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 14 0xb0 2 0x8b) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
f=`../utility/diag-tools/pmbus_tool/line16 0x$d` ; echo $f'") # psu1 输出电压
status , log_psu22 = run_command("sudo bash -c 'a=$(ipmitool raw 0x3a 0x10 15 0xb0 2 0x8b) ; b=$a:1:2 ; c=$a:4:5 ; d=$c$b ; \\
f=`../utility/diag-tools/pmbus_tool/line16 0x$d` ; echo $f'") # psu2 输出电压
输入电压(mv):
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x60 0x88 w
0xe9b6
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x61 0x88 w
0xe9b5
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x62 0x88 w
0xe9b6
root@gnr5713bb:/var/log/abak# ./line11_arm 0xe9b6
54750
输出电压(mv):
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x60 0x8b w
0xc2ad
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x61 0x8b w
0xc395
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x62 0x8b w
0xc0f8
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x60 0x20
0x14
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x61 0x20
0x14
root@gnr5713bb:/var/log/abak# i2cget -f -y 15 0x62 0x20
0x14
root@gnr5713bb:/var/log/abak# ./line16_arm 0xc2ad 0x14
12167
root@gnr5713bb:/var/log/abak# ./line16_arm 0xc395 0x14
12223
root@gnr5713bb:/var/log/abak# ./line16_arm 0xc0f8 0x14
12060
计算机以补码形式存放负数,0010+1=0011(十进制3),438乘2的-3次方 = 54.8。
如下十六进制HEX c2ad , line16的一种方法,49837乘2的-12次方 = 12.1,不用0x20寄存器。
如下是0x20读出来是0x17。
如下取反加1后,十进制和十六进制都为9。
如下是c语言的线性转换,0x0184十六进制printf输出为十进制388。
/*
* X = Y*2^N
* X is the "real world" value;
* Y(mantissa) = bit[0:10]
* N(exponent) = bit[11:15], bit 15 is sign bit
*/
static int32_t linear_convert(int32_t data)
int16_t exponent;
int32_t mantissa;
int32_t val_x;
mantissa = (((data & 0x7ff) << 5)) >> 5;
exponent = ((int16_t)data) >> 11;
val_x = mantissa * 1000L;
if (exponent >= 0)
val_x <<= exponent;
else
val_x >>= -exponent;
return val_x;
//current.c arm编译器arm-linux-gcc (不是x86的gcc)编译成current(电流)可执行文件, linear11
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv)
short exponent;
int mantissa;
int val_x;
mantissa = (((strtoul(argv[1],0,0) & 0x7ff) << 5)) >> 5;
// printf("%x\\n",mantissa);
exponent = ((signed short)strtoul(argv[1],0,0))>>11;
// printf("%d\\n",exponent);
val_x = mantissa * 1000L;
if (exponent >= 0)
val_x <<= exponent;
else
val_x >>= -exponent;
printf("%d\\n",val_x);
return 0;
// linear16
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char ** argv)
short exponent;
int mantissa;
int val_x;
mantissa = (unsigned short)strtoul(argv[1],0,0);
exponent = ((signed short)(0x17 << 11)) >> 11 ;
val_x = mantissa * 1000L;
if (exponent >= 0)
val_x <<= exponent;
else
val_x >>= -exponent;
printf("%d\\n",val_x);
return 0;
# Read_PXE1410CDM_0X62_Voltage_Current.sh
#!/bin/bash
write_ch0()
cnt=0
while true
do
i2c-test -b 7 -s 0x60 -w -d 0x0 0x00 >/dev/null 2>&1
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to write PXE CH0!"
exit 1
fi
cnt=$(($cnt+1))
done
read_ch0_voltage()
cnt=0
while true
do
val_v_0=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8b)
if [ $? = 0 ]
then
hex_v_h_0=$val_v_0:14:2
hex_v_l_0=$val_v_0:17:2
hex_v_0=$hex_v_l_0$hex_v_h_0
dec_v_0=$((0x$hex_v_0 & 0xff))
#echo $dec_v_0
dec_v_0=$(((500 + (dec_v_0 - 1) * 10)/2))
echo "PXE_0x60_0_P0V9_VCCH Voltage : "$dec_v_0"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read ch0 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
read_ch0_current()
cnt=0
while true
do
val_a_0=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8c)
if [ $? = 0 ]
then
hex_a_h_0=$val_a_0:14:2
hex_a_l_0=$val_a_0:17:2
hex_a_0=$hex_a_l_0$hex_a_h_0
dec_a_0=$(./current 0x$hex_a_0)
echo "PXE_0x60_0 Current : "$dec_a_0"mA"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read ch0 current !"
exit 1
fi
cnt=$(($cnt+1))
done
write_ch1()
cnt=0
while true
do
i2c-test -b 7 -s 0x60 -w -d 0x0 0x01 >/dev/null 2>&1
if [ $? = 0 ]
then
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to write PXE CH1!"
exit 1
fi
cnt=$(($cnt+1))
done
read_ch1_voltage()
cnt=0
while true
do
val_v_1=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8b)
if [ $? = 0 ]
then
hex_v_1_h=$val_v_1:14:2
hex_v_1_l=$val_v_1:17:2
hex_v_1=$hex_v_1_l$hex_v_1_h
dec_v_1=$((0x$hex_v_1 & 0xff))
dec_v_1=$(((500 + (dec_v_1 - 1) * 10)/2))
echo "PXE_0x60_1_P1V2_VDDQ_CH01 Voltage : "$dec_v_1"mV"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read ch1 voltage !"
exit 1
fi
cnt=$(($cnt+1))
done
read_ch1_current()
cnt=0
while true
do
val_a_1=$(i2c-test -b 7 -s 0x60 -m 1 -rc 2 -d 0x8c)
if [ $? = 0 ]
then
hex_a_1_h=$val_a_1:14:2
hex_a_1_l=$val_a_1:17:2
hex_a_1=$hex_a_1_l$hex_a_1_h
dec_a_1=$(./current 0x$hex_a_1)
echo "PXE_0x60_1 Current : "$dec_a_1"mA"
break
fi
if [ $cnt -eq 5 ]
then
echo "Unable to read ch1 current !"
exit 1
fi
cnt=$(($cnt+1))
done
start_ipmistack
stop_ipmistack
delete
access
OpenChannel
write_ch0
read_ch0_voltage
read_ch0_current
write_ch1
read_ch1_voltage
read_ch1_current
start_ipmistack
ESD防静电保护管PESDHC2FD4V5BH原装芯导Prisemi,DFN1006-2反向关断电压4.5V,箝位电压5.8V,PESDHC2FD4V5BH双向静电保护
ESD防静电保护管PESDHC2FD4V5BH原装芯导Prisemi,DFN1006-2反向关断电压4.5V,箝位电压5.8V,PESDHC2FD4V5BH双向静电保护