1 # Defines basic Tcl procs for OpenOCD target module
3 proc new_target_name { } {
4 return [target number [expr [target count] - 1 ]]
7 global in_process_reset
10 # Catch reset recursion
11 proc ocd_process_reset { MODE } {
12 global in_process_reset
13 if {$in_process_reset} {
14 set in_process_reset 0
15 return -code error "'reset' can not be invoked recursively"
18 set in_process_reset 1
19 set success [expr [catch {ocd_process_reset_inner $MODE} result]==0]
20 set in_process_reset 0
25 return -code error $result
29 proc ocd_process_reset_inner { MODE } {
30 set targets [target names]
32 # If this target must be halted...
34 if { 0 == [string compare $MODE halt] } {
37 if { 0 == [string compare $MODE init] } {
40 if { 0 == [string compare $MODE run ] } {
44 return -code error "Invalid mode: $MODE, must be one of: halt, init, or run";
47 # Target event handlers *might* change which TAPs are enabled
48 # or disabled, so we fire all of them. But don't issue any
49 # target "arp_*" commands, which may issue JTAG transactions,
50 # unless we know the underlying TAP is active.
52 # NOTE: ARP == "Advanced Reset Process" ... "advanced" is
53 # relative to a previous restrictive scheme
57 $t invoke-event reset-start
60 # Use TRST or TMS/TCK operations to reset all the tap controllers.
61 # TAP reset events get reported; they might enable some taps.
64 # Examine all targets on enabled taps.
66 if {[jtag tapisenabled [$t cget -chain-position]]} {
67 $t invoke-event examine-start
68 set err [catch "$t arp_examine"]
70 $t invoke-event examine-end
75 # Assert SRST, and report the pre/post events.
76 # Note: no target sees SRST before "pre" or after "post".
78 $t invoke-event reset-assert-pre
81 # C code needs to know if we expect to 'halt'
82 if {[jtag tapisenabled [$t cget -chain-position]]} {
83 $t arp_reset assert $halt
87 $t invoke-event reset-assert-post
90 # Now de-assert SRST, and report the pre/post events.
91 # Note: no target sees !SRST before "pre" or after "post".
93 $t invoke-event reset-deassert-pre
96 # Again, de-assert code needs to know if we 'halt'
97 if {[jtag tapisenabled [$t cget -chain-position]]} {
98 $t arp_reset deassert $halt
102 $t invoke-event reset-deassert-post
105 # Pass 1 - Now wait for any halt (requested as part of reset
106 # assert/deassert) to happen. Ideally it takes effect without
107 # first executing any instructions.
110 if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
114 # Wait upto 1 second for target to halt. Why 1sec? Cause
115 # the JTAG tap reset signal might be hooked to a slow
116 # resistor/capacitor circuit - and it might take a while
119 # Catch, but ignore any errors.
120 catch { $t arp_waitstate halted 1000 }
125 if { 0 != [string compare $s "halted" ] } {
126 return -code error [format "TARGET: %s - Not halted" $t]
131 #Pass 2 - if needed "init"
132 if { 0 == [string compare init $MODE] } {
134 if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
138 set err [catch "$t arp_waitstate halted 5000"]
141 $t invoke-event reset-init
147 $t invoke-event reset-end
153 # Temporary migration aid. May be removed starting in January 2011.
154 proc armv4_5 params {
155 echo "DEPRECATED! use 'arm $params' not 'armv4_5 $params'"
159 # Target/chain configuration scripts can either execute commands directly
160 # or define a procedure which is executed once all configuration
161 # scripts have completed.
163 # By default(classic) the config scripts will set up the target configuration
164 proc init_targets {} {
167 # Additionally board config scripts can define a procedure init_board that will be executed after init and init_targets