stm32: Add floating point register read/write.
[fw/openocd] / src / target / startup.tcl
1 # Defines basic Tcl procs for OpenOCD target module
2
3 proc new_target_name { } {
4         return [target number [expr [target count] - 1 ]]
5 }
6
7 global in_process_reset
8 set in_process_reset 0
9
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"
16         }
17
18         set in_process_reset 1
19         set success [expr [catch {ocd_process_reset_inner $MODE} result]==0]
20         set in_process_reset 0
21
22         if {$success} {
23                 return $result
24         } else {
25                 return -code error $result
26         }
27 }
28
29 proc ocd_process_reset_inner { MODE } {
30         set targets [target names]
31
32         # If this target must be halted...
33         set halt -1
34         if { 0 == [string compare $MODE halt] } {
35                 set halt 1
36         }
37         if { 0 == [string compare $MODE init] } {
38                 set halt 1;
39         }
40         if { 0 == [string compare $MODE run ] } {
41                 set halt 0;
42         }
43         if { $halt < 0 } {
44                 return -code error "Invalid mode: $MODE, must be one of: halt, init, or run";
45         }
46
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.
51         #
52         # NOTE:  ARP == "Advanced Reset Process" ... "advanced" is
53         # relative to a previous restrictive scheme
54
55         foreach t $targets {
56                 # New event script.
57                 $t invoke-event reset-start
58         }
59
60         # Use TRST or TMS/TCK operations to reset all the tap controllers.
61         # TAP reset events get reported; they might enable some taps.
62         init_reset $MODE
63
64         # Examine all targets on enabled taps.
65         foreach t $targets {
66                 if {[jtag tapisenabled [$t cget -chain-position]]} {
67                         $t arp_examine
68                 }
69         }
70
71         # Assert SRST, and report the pre/post events.
72         # Note:  no target sees SRST before "pre" or after "post".
73         foreach t $targets {
74                 $t invoke-event reset-assert-pre
75         }
76         foreach t $targets {
77                 # C code needs to know if we expect to 'halt'
78                 if {[jtag tapisenabled [$t cget -chain-position]]} {
79                         $t arp_reset assert $halt
80                 }
81         }
82         foreach t $targets {
83                 $t invoke-event reset-assert-post
84         }
85
86         # Now de-assert SRST, and report the pre/post events.
87         # Note:  no target sees !SRST before "pre" or after "post".
88         foreach t $targets {
89                 $t invoke-event reset-deassert-pre
90         }
91         foreach t $targets {
92                 # Again, de-assert code needs to know if we 'halt'
93                 if {[jtag tapisenabled [$t cget -chain-position]]} {
94                         $t arp_reset deassert $halt
95                 }
96         }
97         foreach t $targets {
98                 $t invoke-event reset-deassert-post
99         }
100
101         # Pass 1 - Now wait for any halt (requested as part of reset
102         # assert/deassert) to happen.  Ideally it takes effect without
103         # first executing any instructions.
104         if { $halt } {
105                 foreach t $targets {
106                         if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
107                                 continue
108                         }
109
110                         # Wait upto 1 second for target to halt.  Why 1sec? Cause
111                         # the JTAG tap reset signal might be hooked to a slow
112                         # resistor/capacitor circuit - and it might take a while
113                         # to charge
114
115                         # Catch, but ignore any errors.
116                         catch { $t arp_waitstate halted 1000 }
117
118                         # Did we succeed?
119                         set s [$t curstate]
120
121                         if { 0 != [string compare $s "halted" ] } {
122                                 return -code error [format "TARGET: %s - Not halted" $t]
123                         }
124                 }
125         }
126
127         #Pass 2 - if needed "init"
128         if { 0 == [string compare init $MODE] } {
129                 foreach t $targets {
130                         if {[jtag tapisenabled [$t cget -chain-position]] == 0} {
131                                 continue
132                         }
133
134                         set err [catch "$t arp_waitstate halted 5000"]
135                         # Did it halt?
136                         if { $err == 0 } {
137                                 $t invoke-event reset-init
138                         }
139                 }
140         }
141
142         foreach t $targets {
143                 $t invoke-event reset-end
144         }
145 }
146
147 #########
148
149 # Temporary migration aid.  May be removed starting in January 2011.
150 proc armv4_5 params {
151         echo "DEPRECATED! use 'arm $params' not 'armv4_5 $params'"
152         arm $params
153 }
154
155 # Target/chain configuration scripts can either execute commands directly 
156 # or define a procedure which is executed once all configuration 
157 # scripts have completed.
158 #
159 # By default(classic) the config scripts will set up the target configuration
160 proc init_targets {} {
161 }
162
163 # Additionally board config scripts can define a procedure init_board that will be executed after init and init_targets
164 proc init_board {} {
165 }