contrib/firmware: add 'send not acknowledged' function to the i2c bit-banging impleme...
[openocd.git] / tcl / mmr_helpers.tcl
blob5c37fcfdc138baeb30ddc553ef43270d4a693840
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 proc proc_exists { NAME } {
4 set n [info commands $NAME]
5 set l [string length $n]
6 return [expr {$l != 0}]
9 # Give: REGISTER name - must be a global variable.
10 proc show_mmr32_reg { NAME } {
12 global $NAME
13 # we want $($NAME)
14 set a [set [set NAME]]
16 if ![catch { set v [memread32 $a] } msg ] {
17 echo [format "%15s: (0x%08x): 0x%08x" $NAME $a $v]
19 # Was a helper defined?
20 set fn show_${NAME}_helper
21 if [ proc_exists $fn ] {
22 # Then call it
23 $fn $NAME $a $v
25 return $v;
26 } else {
27 error [format "%s (%s)" $msg $NAME ]
32 # Give: NAMES - an array of names accessible
33 # in the callers symbol-scope.
34 # VAL - the bits to display.
36 proc show_mmr32_bits { NAMES VAL } {
38 upvar $NAMES MYNAMES
40 set w 5
41 foreach {IDX N} $MYNAMES {
42 set l [string length $N]
43 if { $l > $w } { set w $l }
46 for { set x 24 } { $x >= 0 } { incr x -8 } {
47 echo -n " "
48 for { set y 7 } { $y >= 0 } { incr y -1 } {
49 set s $MYNAMES([expr {$x + $y}])
50 echo -n [format "%2d: %-*s | " [expr {$x + $y}] $w $s ]
52 echo ""
54 echo -n " "
55 for { set y 7 } { $y >= 0 } { incr y -1 } {
56 echo -n [format " %d%*s | " [expr {!!($VAL & (1 << ($x + $y)))}] [expr {$w -1}] ""]
58 echo ""
63 proc show_mmr_bitfield { MSB LSB VAL FIELDNAME FIELDVALUES } {
64 set width [expr {(($MSB - $LSB + 1) + 7) / 4}]
65 set nval [show_normalize_bitfield $VAL $MSB $LSB ]
66 set name0 [lindex $FIELDVALUES 0 ]
67 if [ string compare $name0 _NUMBER_ ] {
68 set sval [lindex $FIELDVALUES $nval]
69 } else {
70 set sval ""
72 echo [format "%-15s: %d (0x%0*x) %s" $FIELDNAME $nval $width $nval $sval ]
75 # Give: ADDR - address of the register.
76 # BIT - bit's number.
78 proc get_mmr_bit { ADDR BIT } {
79 set val [memread32 $ADDR]
80 set bit_val [expr {$val & [expr {1 << $BIT}]}]
81 return $bit_val
85 # Give: ADDR - address of the register.
86 # MSB - MSB bit's number.
87 # LSB - LSB bit's number.
89 proc get_mmr_bitfield { ADDR MSB LSB } {
90 set rval [memread32 $ADDR]
91 return normalize_bitfield $rval $MSB $LSB