summaryrefslogtreecommitdiff
path: root/tcl/mem_helper.tcl
diff options
context:
space:
mode:
authorAntonio Borneo <borneo.antonio@gmail.com>2010-09-21 16:06:37 +0800
committerØyvind Harboe <oyvind.harboe@zylin.com>2010-09-21 12:25:59 +0200
commitedefee988045558d5d306453ce352dc06bcb7a03 (patch)
tree65a641398a6e7515b3e5adcd2ceb3bb836ea85e8 /tcl/mem_helper.tcl
parentea48794210037699bdde44014238c10c9968a72d (diff)
downloadopenocd+libswd-edefee988045558d5d306453ce352dc06bcb7a03.tar.gz
openocd+libswd-edefee988045558d5d306453ce352dc06bcb7a03.tar.bz2
openocd+libswd-edefee988045558d5d306453ce352dc06bcb7a03.tar.xz
openocd+libswd-edefee988045558d5d306453ce352dc06bcb7a03.zip
TCL scripts: collect duplicated procedures
TCL procedures mrw and mmw, originally in DaVinci target code, are duplicated in other TCL scripts. Moved in a common helper file, and added help/usage description. Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Diffstat (limited to 'tcl/mem_helper.tcl')
-rw-r--r--tcl/mem_helper.tcl22
1 files changed, 22 insertions, 0 deletions
diff --git a/tcl/mem_helper.tcl b/tcl/mem_helper.tcl
new file mode 100644
index 00000000..d8114908
--- /dev/null
+++ b/tcl/mem_helper.tcl
@@ -0,0 +1,22 @@
+# Helper for common memory read/modify/write procedures
+
+# mrw: "memory read word", returns value of $reg
+proc mrw {reg} {
+ set value ""
+ ocd_mem2array value 32 $reg 1
+ return $value(0)
+}
+
+add_usage_text mrw "address"
+add_help_text mrw "Returns value of word in memory."
+
+# mmw: "memory modify word", updates value of $reg
+# $reg <== ((value & ~$clearbits) | $setbits)
+proc mmw {reg setbits clearbits} {
+ set old [mrw $reg]
+ set new [expr ($old & ~$clearbits) | $setbits]
+ mww $reg $new
+}
+
+add_usage_text mmw "address setbits clearbits"
+add_help_text mmw "Modify word in memory. new_val = (old_val & ~clearbits) | setbits;"