Implementing a certain bit of a register with a shell script
Pit bit 1:
Not recognized on the Development Board (Ubuntu can)
For ((i=0;i<6;i++))
Do
Done
Into:
For i in ' seq 0 6 '
Do
Done
Pit bit 2:
return value by default only 8 bits are truncated.
Setbits $ $4
Regv=$?
printf "regv=% #x \ n" $REGV
Found only eight low-bits left.
So, change the type of undertaking:
regv= ' RegRead $ '
This is done by directly executing the command or outputting something on the screen, which is the string.
Pit bit 3:
As above, reg= ' RegRead $ ' gets the string if it is not printed with printf "%d", the direct echo line
Pit bit 4:
Reg=setbits $ $4 This way to take a pop grammar error, not C language.
The final test was successful, as follows:
####################################################### # test the SAR-ADC I N SOC ########################################## ############# RegWrite () { Devmem $32} RegRead () {Dev MEM $} # #argv [1]: Origin data # #argv [2]: Start bit # #argv [3]: End bit # #argv [4]: ResU Lt Setbits () { Value=$1 For i in ' seq $ $ ' do mask=$ ((0x1 << $i)) #printf "mask =% #x \ n" $mask value=$ (($value & ~ $mask)) #printf "clean bit%d value =% #x \ n" $i $value mask1=$ ((0x1 << ($i-$))) #printf "Mask1 =% #x \ n" $mask 1 bitv=$ ($4 &am P MASK1)) #printf "BITV =% #x \ n" $bitv value=$ ($value | ($bitv << $))) #printf "Set bit%d value =% #x \ n" $i $value done printf "% #x \ n" $value return $value } Reg_set_bits () { regv= ' RegRead $ ' regv= ' setbits $REGV $ $4 ' RegWrite $ $REGV} Reg_set_bits $ $4
Shell Script Bitwise operation +FOR Loop + return value to undertake