mmr_helpers.tcl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. proc proc_exists { NAME } {
  3. set n [info commands $NAME]
  4. set l [string length $n]
  5. return [expr {$l != 0}]
  6. }
  7. # Give: REGISTER name - must be a global variable.
  8. proc show_mmr32_reg { NAME } {
  9. global $NAME
  10. # we want $($NAME)
  11. set a [set [set NAME]]
  12. if ![catch { set v [memread32 $a] } msg ] {
  13. echo [format "%15s: (0x%08x): 0x%08x" $NAME $a $v]
  14. # Was a helper defined?
  15. set fn show_${NAME}_helper
  16. if [ proc_exists $fn ] {
  17. # Then call it
  18. $fn $NAME $a $v
  19. }
  20. return $v;
  21. } else {
  22. error [format "%s (%s)" $msg $NAME ]
  23. }
  24. }
  25. # Give: NAMES - an array of names accessible
  26. # in the callers symbol-scope.
  27. # VAL - the bits to display.
  28. proc show_mmr32_bits { NAMES VAL } {
  29. upvar $NAMES MYNAMES
  30. set w 5
  31. foreach {IDX N} $MYNAMES {
  32. set l [string length $N]
  33. if { $l > $w } { set w $l }
  34. }
  35. for { set x 24 } { $x >= 0 } { incr x -8 } {
  36. echo -n " "
  37. for { set y 7 } { $y >= 0 } { incr y -1 } {
  38. set s $MYNAMES([expr {$x + $y}])
  39. echo -n [format "%2d: %-*s | " [expr {$x + $y}] $w $s ]
  40. }
  41. echo ""
  42. echo -n " "
  43. for { set y 7 } { $y >= 0 } { incr y -1 } {
  44. echo -n [format " %d%*s | " [expr {!!($VAL & (1 << ($x + $y)))}] [expr {$w -1}] ""]
  45. }
  46. echo ""
  47. }
  48. }
  49. proc show_mmr_bitfield { MSB LSB VAL FIELDNAME FIELDVALUES } {
  50. set width [expr {(($MSB - $LSB + 1) + 7) / 4}]
  51. set nval [show_normalize_bitfield $VAL $MSB $LSB ]
  52. set name0 [lindex $FIELDVALUES 0 ]
  53. if [ string compare $name0 _NUMBER_ ] {
  54. set sval [lindex $FIELDVALUES $nval]
  55. } else {
  56. set sval ""
  57. }
  58. echo [format "%-15s: %d (0x%0*x) %s" $FIELDNAME $nval $width $nval $sval ]
  59. }
  60. # Give: ADDR - address of the register.
  61. # BIT - bit's number.
  62. proc get_mmr_bit { ADDR BIT } {
  63. set val [memread32 $ADDR]
  64. set bit_val [expr {$val & [expr {1 << $BIT}]}]
  65. return $bit_val
  66. }
  67. # Give: ADDR - address of the register.
  68. # MSB - MSB bit's number.
  69. # LSB - LSB bit's number.
  70. proc get_mmr_bitfield { ADDR MSB LSB } {
  71. set rval [memread32 $ADDR]
  72. return normalize_bitfield $rval $MSB $LSB
  73. }