#!/bin/sh # ADC Base Address 0x1e6e 9000 # Channel0 & Channel 1 0x10 # Channel2 & Channel 3 0x14 # Channel4 & Channel 5 0x18 # Channel6 & Channel 7 0x1c # Channel8 & Channel 9 0x20 # Channel10 & Channel 11 0x24 # Channel12 & Channel 13 0x28 # Channel14 & Channel 15 0x2c # volt = ((data+1.0) /1024) *1.8; //ADC calculation formular # volt *= resist; /* based on the hardware resistance added*/ Board_Desc="Common_Board" Low_Position=0 High_Position=1 # --------------------------------------------------------------- # Resist List # --------------------------------------------------------------- Channel00_resist=1 Channel01_resist=1 Channel02_resist=1 Channel03_resist=1 Channel04_resist=1 Channel05_resist=1 Channel06_resist=1 Channel07_resist=1 Channel08_resist=1 Channel09_resist=1 Channel10_resist=1 Channel11_resist=1 Channel12_resist=1 Channel13_resist=1 Channel14_resist=1 Channel15_resist=1 # --------------------------------------------------------------- # Channel Name # --------------------------------------------------------------- Channel00_name="Channel00_Volt" Channel01_name="Channel01_Volt" Channel02_name="Channel02_Volt" Channel03_name="Channel03_Volt" Channel04_name="Channel04_Volt" Channel05_name="Channel05_Volt" Channel06_name="Channel06_Volt" Channel07_name="Channel07_Volt" Channel08_name="Channel08_Volt" Channel09_name="Channel09_Volt" Channel10_name="Channel10_Volt" Channel11_name="Channel11_Volt" Channel12_name="Channel12_Volt" Channel13_name="Channel13_Volt" Channel14_name="Channel14_Volt" Channel15_name="Channel15_Volt" # --------------------------------------------------------------- # Function Define # --------------------------------------------------------------- # @Param1 ChannelNumber # @Param2 ChannelRegOffset # @Param3 Pos Flag # @Param4 ChannelName # @Param5 ChannelResist read_channel_and_convert(){ RegAddr=0x1e6e90$2 # echo "RegAddr=${RegAddr}" res=`devmem ${RegAddr} 32` # echo $res if [ $3 = $Low_Position ];then ex=$(echo ${res} | cut -c 8) h=$(echo ${res} | cut -c 9) l=$(echo ${res} | cut -c 10) hex_raw=${ex}${h}${l} else ex=$(echo ${res} | cut -c 4) h=$(echo ${res} | cut -c 5) l=$(echo ${res} | cut -c 6) hex_raw=${ex}${h}${l} fi # Convert hex raw data to sensor value dec_raw=$(echo "ibase=16; ${hex_raw}" | bc) volt=$(echo "scale=4; ((${dec_raw} + 1.0) / 1024) * 1.8 * ${5} " | bc) format_volt=$(echo "$volt" | awk '{ if ($0 ~ /^\./) print "0" $0; else print $0 }') # Output result echo "Channel$1 | $4 : ${format_volt}V" } # --------------------------------------------------------------- # Main # --------------------------------------------------------------- echo "Board Name : ${Board_Desc}" read_channel_and_convert "00" "10" ${Low_Position} "${Channel00_name}" "${Channel00_resist}" read_channel_and_convert "01" "10" ${High_Position} "${Channel01_name}" "${Channel01_resist}" read_channel_and_convert "02" "14" ${Low_Position} "${Channel02_name}" "${Channel02_resist}" read_channel_and_convert "03" "14" ${High_Position} "${Channel03_name}" "${Channel03_resist}" read_channel_and_convert "04" "18" ${Low_Position} "${Channel04_name}" "${Channel04_resist}" read_channel_and_convert "05" "18" ${High_Position} "${Channel05_name}" "${Channel05_resist}" read_channel_and_convert "06" "1c" ${Low_Position} "${Channel06_name}" "${Channel06_resist}" read_channel_and_convert "07" "1c" ${High_Position} "${Channel07_name}" "${Channel07_resist}" read_channel_and_convert "08" "20" ${Low_Position} "${Channel08_name}" "${Channel08_resist}" read_channel_and_convert "09" "20" ${High_Position} "${Channel09_name}" "${Channel09_resist}" read_channel_and_convert "10" "24" ${Low_Position} "${Channel10_name}" "${Channel10_resist}" read_channel_and_convert "11" "24" ${High_Position} "${Channel11_name}" "${Channel11_resist}" read_channel_and_convert "12" "28" ${Low_Position} "${Channel12_name}" "${Channel12_resist}" read_channel_and_convert "13" "28" ${High_Position} "${Channel13_name}" "${Channel13_resist}" read_channel_and_convert "14" "2c" ${Low_Position} "${Channel14_name}" "${Channel14_resist}" read_channel_and_convert "15" "2c" ${High_Position} "${Channel15_name}" "${Channel15_resist}"