C4111

Posted 码农编程录

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C4111相关的知识,希望对你有一定的参考价值。

#!/bin/bash
#
# Copyright 2019-present Huaqin. All Rights Reserved.
#
# This program file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
#

PART1="/dev/mmcblk0p1"
PART2="/dev/mmcblk0p2"
PART1_MOUNT_POINT="/overlay/rw"
PART2_MOUNT_POINT="/var/volatile/log/"
DEV="/dev/mmcblk0"

prog=$(basename "$0")
usage() 
    echo "Usage: $prog <configuration/all>"
    echo
    echo "Note:"
    echo "  configuration : System configurations and user data"
    echo "  all           : All disk data,include user data, syslog and system configurations"
    echo
    echo "Examples:"
    echo "  $prog configuration "
    echo "  $prog all "
    echo
    exit 1


check_parameter() 
    if [ $# -ne 1 ]; then
        usage
    fi

    obj="$1"
    if [ "$obj" != "configuration" ] && [ "$obj" != "all" ]; then
        usage
    fi


format_fs_1() 
    mkfs.ext4 $PART1 << EOF
y
EOF


partition_rm_1() 
    fdisk $DEV << EOF
d
1
w
EOF


format_fs_2() 
    mkfs.ext4 $PART2 << EOF
y
EOF


partition_rm_2() 
    fdisk $DEV << EOF
d
2
w
EOF


format_emmc() 
    if [ "$format_flag" = 1 ]; then
        case $obj in
            configuration)
                umount -lf $PART1_MOUNT_POINT  || (echo "umount $PART1 fail !" && exit 1)
                format_fs_1
                sleep 3
                partition_rm_1
                sleep 3
                partprobe $DEV
                ;;
            all)
                umount -lf $PART2_MOUNT_POINT  || (echo "umount $PART2 fail !" && exit 1)
                format_fs_2
                sleep 3
                partition_rm_2
                sleep 3
                partprobe $DEV
                ;;
            *)
                usage
                ;;
        esac
    fi

    echo "reboot after 10S"
    sleep 10
    reboot


confirm_prompt() 
    case $obj in
        configuration)
            read -r -p $'This operaion will restore system configurations.\\x0aPlease confirm. [Y/N] ' input
            ;;
        all)
            read -r -p $'This operaion will format emmc and discard all system configurations.\\x0aPlease confirm. [Y/N] ' input
            ;;
        *)
            usage
            ;;
    esac

    case $input in
        [yY][eE][sS] | [yY])
            echo "Start to perform restore default command."
            format_flag=1
            ;;

        [nN][oO] | [nN])
            echo "Abort execution and exit."
            exit 1
            ;;

        *)
            echo "Invalid input..."
            exit 1
            ;;
    esac


check_parameter "$@"
confirm_prompt
format_emmc

#!/bin/bash
#
# Copyright 2019-present Huaqin. All Rights Reserved.
#
# This program file is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program in a file named COPYING; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301 USA
#
#shellcheck disable=SC1091
. /usr/local/bin/openbmc-utils.sh

BLACKBOX_ADDRESS=0xdc
BLACKBOX_PAGE_ADDRESS=0xdb
OUTPUTFILE=/var/log/dump_acbel_psu_blackbox.txt

program=$(basename "$0")
usage() 
    echo "Usage:"
    echo "  $program -i <PSU index>"
    echo
    echo "PSU index:"
    echo "  1-4"
    echo
    echo "Examples:"
    echo "  $program -i 4"
    exit 1


decompose_iic_addr()

    bus=$(echo "$1" | awk -F "-" 'print $1')
    str=$(echo "$1" | awk -F "-" 'print $2')
    address=$str/00/0x


check_parameter()

    if [ "$#" -ne 2 ];then
        usage
    fi
    device="$2"
    if [ "$device" != "1" ] && [ "$device" != "2" ] && [ "$device" != "3" ] && [ "$device" != "4" ];then
        usage
    fi


linear11_convert()

    if [ $((($1 >> 10) & 0x1)) == 1 ] ; then
        mantissa=$(($1 & 0x3FF))
        mantissa=$(($mantissa ^ 0x3ff))
        mantissa=$((~$mantissa))
    else
        mantissa=$(((((($1 & 0x7ff)) << 5)) >> 5))
    fi

    if [ $((($1 >> 15) & 0x1)) == 1 ] ; then
        exponent=$(((($1 & 0x7FFF)) >> 11))
        exponent=$(($exponent ^ 0xf))
        exponent=$((~$exponent))
    else
        exponent=$(($1>> 11))
    fi

    val_x=$((mantissa * 1000))
    if [ $exponent -ge 0 ]; then
        val_x=$(($val_x<<$exponent))
    else
        val_x=$(($val_x>>$((-$exponent))))
    fi
    echo $val_x


linear11_convert $1

linear11_convert()

    mantissa=$(((((($1 & 0x7ff)) << 5)) >> 5))
    if [ $((($1 >> 15) & 0x1)) == 1 ] ; then
        exponent=$(((($1 & 0x7FFF)) >> 11))
        exponent=$(($exponent ^ 0xf))
        exponent=$((~$exponent))
    else
        exponent=$(($1>> 11))
    fi
    val_x=$((mantissa * 1000))
    if [ $exponent -ge 0 ]; then
        val_x=$(($val_x<<$exponent))
    else
        val_x=$(($val_x>>$((-$exponent))))
    fi
    echo $val_x


linear16_convert()

    mantissa=$(printf %d "$1")
    if [ $((($2 >> 4) & 0x1)) == 1 ] ; then
        exponent=$(((((($2 << 11)) >> 11)) & 0xf))
        exponent=$(($exponent ^ 0xf))
        exponent=$((~$exponent))
    else
        exponent=$(printf %d "$2")
    fi
    val_x=$((mantissa * 1000))
    if [ $exponent -ge 0 ]; then
        val_x=$(($val_x<<$exponent))
    else
        val_x=$(($val_x>>$((-$exponent))))
    fi
    echo $val_x


do_action()

    value=$(i2ctransfer -f -y $bus w1@$address $BLACKBOX_ADDRESS r52)
    present_psu_on_time_l=$value:7:2
    present_psu_on_time_m=$value:12:2
    present_psu_on_time_h=$value:17:2
    present_psu_on_time="0x""$present_psu_on_time_h""$present_psu_on_time_m""$present_psu_on_time_l"
    present_psu_on_time=$(printf %d "$present_psu_on_time")
    echo "Present total PSU ON time:                      $present_psu_on_time min" >> $OUTPUTFILE

    present_num_ac_cycles_l=$value:22:2
    present_num_ac_cycles_h=$value:27:2
    present_num_ac_cycles="0x""$present_num_ac_cycles_h""$present_num_ac_cycles_l"
    present_num_ac_cycles=$(printf %d "$present_num_ac_cycles")
    echo "Present number of AC power cycles:              $present_num_ac_cycles" >> $OUTPUTFILE

    present_num_pson_cycles_l=$value:32:2
    present_num_pson_cycles_h=$value:37:2
    present_num_pson_cycles="0x""$present_num_pson_cycles_h""$present_num_pson_cycles_l"
    present_num_pson_cycles=$(printf %d "$present_num_pson_cycles")
    echo "Present number of PSON power cycles:            $present_num_pson_cycles" >> $OUTPUTFILE

    power_on_time_l=$value:42:2
    power_on_time_m=$value:47:2
    power_on_time_h=$value:52:2
    power_on_time="0x""$power_on_time_h""$power_on_time_m""$power_on_time_l"
    power_on_time=$(printf %d "$power_on_time")
    echo "Power supply total power on time:               $power_on_time" >> $OUTPUTFILE

    clock_data_l=$value:57:2
    clock_data_m1=$value:62:2
    clock_data_m2=$value:67:2
    clock_data_h=$value:72:2
    clock_data="0x""$clock_data_h""$clock_data_m2""$clock_data_m1""$clock_data_l"
    clock_data=$(printf %d "$clock_data")
    echo "Real Time Clock Data from System:               $clock_data" >> $OUTPUTFILE

    num_ac_cycles_l=$value:77:2
    num_ac_cycles_h=$value:82:2
    num_ac_cycles="0x""$num_ac_cycles_h""$num_ac_cycles_l"
    num_ac_cycles=$(printf %d "$num_ac_cycles")
    echo "Number of AC power cycles:                      $num_ac_cycles" >> $OUTPUTFILE

    num_pson_cycles_l=$value:87:2
    num_pson_cycles_h=$value:92:2
    num_pson_cycles="0x""$num_pson_cycles_h""$num_pson_cycles_l"
    num_pson_cycles=$(printf %d "$num_pson_cycles")
    echo "Number of PSON power cycles:                    $num_pson_cycles" >> $OUTPUTFILE

    status_word_l=$value:97:2
    status_word_h=$value:102:2
    status_word="0x""$status_word_h""$status_word_l"
    if [ $((($status_word >> 1) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: CML:                           A communications, memory or logic fault has occurred         Refer to STATUS_CML"  >> $OUTPUTFILE
    elif [ $((($status_word >> 2) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: TEMPERATURE:                   A temperature fault or warning has occurred                  Refer to STATUS_TEMPER ATURE" >> $OUTPUTFILE
    elif [ $((($status_word >> 3) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: VIN_UV_FAULT:                  An input under voltage fault has occurred                    Refer to STATUS_INPUT" >> $OUTPUTFILE
    elif [ $((($status_word >> 4) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: IOUT_OC_FAULT:                 An output over current fault has occurred                    Refer to STATUS_IOUT" >> $OUTPUTFILE
    elif [ $((($status_word >> 5) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: VOUT_OV_FAULT:                 An output overvoltage fault has occurred                     Refer to STATUS_VOUT" >> $OUTPUTFILE
    elif [ $((($status_word >> 6) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: OFF:                           This bit is asserted if the unit is not providing power to the output  " >> $OUTPUTFILE
    elif [ $((($status_word >> 10) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: FANS:                          A fan or airflow fault or warning has occurred               Refer to STATUS_FANS" >> $OUTPUTFILE
    elif [ $((($status_word >> 11) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: POWER_GOOD:                    The POWER_GOOD signal, if present, is negated                Reflects real time state of PSU" >> $OUTPUTFILE
    elif [ $((($status_word >> 13) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: INPUT:                         An input voltage, input current, or input power fault or warning has occurred   Refer to STATUS_INPUT" >> $OUTPUTFILE
    elif [ $((($status_word >> 14) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: IOUT/POUT:                     An output current or output power fault or warning has occurred                 Refer to STATUS_IOUT"  >> $OUTPUTFILE
    elif [ $((($status_word >> 15) & 0x1)) == 1 ] ; then
        echo "STATUS_WORD: VOUT:                          An output voltage fault or warning has occurred              Refer to STATUS_VOUT"  >> $OUTPUTFILE
    fi

    status_vout_l=$value:107:2
    status_vout="0x""$status_vout_l"
    if [ $((($status_vout >> 4) & 0x1)) == 1 ] ; then
        echo "STATUS_VOUT: VOUT_UV_FAULT:                 Output Under voltage Fault       STATUS bit Auto Recovery: No       PSU state when bit is asserted('1'): OFF"  >> $OUTPUTFILE
    elif [ $((($status_vout >> 7) & 0x1)) == 1 ] ; then
        echo "STATUS_VOUT: VOUT_OV_FAULT:                 Output Overvoltage Fault         STATUS bit Auto Recovery: No       PSU state when bit is asserted('1'): OFF"  >> $OUTPUTFILE
    fi

    status_iout_l=$value:112:2
    status_iout="0x""$status_iout_l"
    if [ $(($status_iout & 0x1)) == 1 ] ; then
        echo "STATUS_IOUT: POUT_OP_WARNING:               Predictive failure               STATUS bit Auto Recovery: Yes      PSU state when bit is asserted('1'): ON" >> $OUTPUTFILE
    elif [ $((($status_iout >> 1) & 0x1)) == 1 ] ; then
        echo "STATUS_IOUT: POUT_OP_FAULT:                 Failure                          STATUS bit Auto Recovery: No       PSU state when bit is asserted('1'): OFF" >> $OUTPUTFILE
    elif [ $((($status_iout >> 5) & 0x1)) == 1 ] ; then
        echo "STATUS_IOUT: IOUT_OC_WARNING:               Predictive failure               STATUS bit Auto Recovery: Yes      PSU state when bit is asserted('1'): ON" >> $OUTPUTFILE
    elif [ $((($status_iout >> 7) & 0x1)) == 1 ] ; then
        echo "STATUS_IOUT: IOUT_OC_FAULT :                Failure                          STATUS bit Auto Recovery: No       PSU state when bit is asserted('1'): OFF">> $OUTPUTFILE
    fi

    status_input_l=$value:117:2
    status_input="0x""$status_input_l"
    if [ $(($status_input & 0x1)) == 1 ] ; then
        echo "STATUS_INPUT: PIN_OP_WARNING:              Predictive failure                STATUS bit Auto Recovery: No       PSU state when bit is asserted('1'): ON" >> $OUTPUTFILE
    elif [ $((($status_input >> 1) & 0x1)) == 1 ] ; then
        echo "STATUS_INPUT: IIN_OC_WARNING:              Predictive failure                STATUS bit Auto Recovery: No       PSU state when bit is asserted('1'): ON" >> $OUTPUTFILE
    elif [ $((($status_input >> 2) & 0x1)) == 1 ] ; then
        echo "STATUS_INPUT: IIN_OC_FAULT:                Input Overcurrent Fault           STATUS bit Auto Recovery: No       PSU state when bit is asserted('1'): OFF" >> $OUTPUTFILE
    elif [ $((($status_input >> 3) & 0x1)) == 1 ] ; then
        echo "STATUS_INPUT: Unit Off for Low Input Voltage :                               Either the input voltage has never exceeded the input turn-on threshold or if the unit did start,\\
        the input voltage decreased below the turn-off threshold            STATUS bit Auto Recovery: Yes                     PSU state when bit is asserted('1'): OFF" >> $OUTPUTFILE
    elif [ $((($status_input >> 4) & 0x1)) == 1 ] ; then
        echo "STATUS_INPUT: VIN_UV_FAULT:                Input Under voltage Fault         STATUS bit Auto Recovery: Yes      PSU state when bit is asserted('1'): OFF" >> $OUTPUTFILE
    elif [ $((($status_input >> 5) & 0x1)) == 1 ] ; then
        echo "STATUS_INPUT: VIN_UV_WARNING:              Predictive failure                STATUS bit Auto Recovery: Yes      PSU state when bit is asserted('1'): ON" >> $OUTPUTFILE
    elif [ $((($status_input >> 7) & 0x1)) == 1 ] ; then
        echo "STATUS_INPUT: VIN_OV_FAULT:                Input Overvoltage Fault           STATUS bit Auto Recovery: Yes      PSU state when bit is asserted('1'): OFF" >> $OUTPUTFILE
    fi

    status_temp_l=$value:122:2
    status_temp="0x""$status_temp_l"
    if [ $((($status_temp >> 6) & 0x1)) == 1 ] ; then
        echo "STATUS_TEMPERATURE: OT_WARNING:            Over Temperature Warning          STATUS bit Auto Recovery: Yes      PSU state when bit is asserted('1'): ON" >> $OUTPUTFILE
    elif [ $((($status_temp >> 7) & 0x1)) == 1 ] ; then
        echo "STATUS_TEMPERATURE: OT_FAULT:              Over Temperature Fault            STATUS bit Auto Recovery: Yes      PSU state when bit is asserted('1'): OFF" >> $OUTPUTFILE
    fi

    status_cml_l=$value:127:2
    status_cml="0x""$status_

以上是关于C4111的主要内容,如果未能解决你的问题,请参考以下文章

数据采集卡能采集电流信号吗?

请问,两线制压力传感器,如何采集电流信号呢?怎么接线。(采集模块以供电24v)

互感器二次绕组的符号都有哪些?

三相电电流采样和电压采样具体原理及电路,谢谢

交流电压采样方式是啥?电流采样方式是啥? 谢谢啊

单片机怎样对交流电压电流取样