]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MicroBlaze_Spartan-6_EthernetLite/KernelAwareBSPRepository/bsp/freertos_v2_00_a/data/freertos_v2_1_0.tcl
Correct calculation of xHeapStructSize in heap_4 and heap_5.
[freertos] / FreeRTOS / Demo / MicroBlaze_Spartan-6_EthernetLite / KernelAwareBSPRepository / bsp / freertos_v2_00_a / data / freertos_v2_1_0.tcl
1 ##############################################################################\r
2 #\r
3 # (c) Copyright 2011 Xilinx, Inc. All rights reserved.\r
4 #\r
5 # This file contains confidential and proprietary information of Xilinx, Inc.\r
6 # and is protected under U.S. and international copyright and other\r
7 # intellectual property laws.\r
8 #\r
9 # DISCLAIMER\r
10 # This disclaimer is not a license and does not grant any rights to the\r
11 # materials distributed herewith. Except as otherwise provided in a valid\r
12 # license issued to you by Xilinx, and to the maximum extent permitted by\r
13 # applicable law: (1) THESE MATERIALS ARE MADE AVAILABLE "AS IS" AND WITH ALL\r
14 # FAULTS, AND XILINX HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS,\r
15 # IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF\r
16 # MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR ANY PARTICULAR PURPOSE;\r
17 # and (2) Xilinx shall not be liable (whether in contract or tort, including\r
18 # negligence, or under any other theory of liability) for any loss or damage\r
19 # of any kind or nature related to, arising under or in connection with these\r
20 # materials, including for any direct, or any indirect, special, incidental,\r
21 # or consequential loss or damage (including loss of data, profits, goodwill,\r
22 # or any type of loss or damage suffered as a result of any action brought by\r
23 # a third party) even if such damage or loss was reasonably foreseeable or\r
24 # Xilinx had been advised of the possibility of the same.\r
25 #\r
26 # CRITICAL APPLICATIONS\r
27 # Xilinx products are not designed or intended to be fail-safe, or for use in\r
28 # any application requiring fail-safe performance, such as life-support or\r
29 # safety devices or systems, Class III medical devices, nuclear facilities,\r
30 # applications related to the deployment of airbags, or any other applications\r
31 # that could lead to death, personal injury, or severe property or\r
32 # environmental damage (individually and collectively, "Critical\r
33 # Applications"). Customer assumes the sole risk and liability of any use of\r
34 # Xilinx products in Critical Applications, subject only to applicable laws\r
35 # and regulations governing limitations on product liability.\r
36 #\r
37 # THIS COPYRIGHT NOTICE AND DISCLAIMER MUST BE RETAINED AS PART OF THIS FILE\r
38 # AT ALL TIMES.\r
39 #\r
40 # This file is part of FreeRTOS.\r
41 #\r
42 # $Id: freertos_v2_1_0.tcl,v 1.1.2.8 2010/12/10 07:27:08 svemula Exp $\r
43 ###############################################################################\r
44 \r
45 # standalone bsp version. set this to the latest "ACTIVE" version.\r
46 set standalone_version standalone_v3_01_a\r
47 \r
48 proc kernel_drc {os_handle} {\r
49     set sw_proc_handle [xget_libgen_proc_handle]\r
50     set hw_proc_handle [xget_handle $sw_proc_handle "IPINST"]\r
51     set proctype [xget_value $hw_proc_handle "OPTION" "IPNAME"]\r
52     set compiler [xget_value $sw_proc_handle "PARAMETER" "COMPILER"]\r
53 \r
54     # check for valid compiler\r
55     if { [string first "mb-gcc" $compiler] == 0 && [string first "mb-g++" $compiler] == 0} {\r
56         error "Wrong compiler requested. FreeRTOS can be compiled only with the GNU compiler for MicroBlaze." "" "mdt_error"\r
57     }\r
58 \r
59     # check for valid stdio parameters\r
60     set stdin [xget_value $os_handle "PARAMETER" "STDIN"]\r
61     set stdout [xget_value $os_handle "PARAMETER" "STDOUT"]\r
62     if { $stdin == "none" || $stdout == "none" } {\r
63         error "The STDIN/STDOUT parameters are not set. FreeRTOS requires stdin/stdout to be set." "" "mdt_error"\r
64     }\r
65 \r
66     # check if the design has a intc\r
67     set intr_port [xget_value $hw_proc_handle "PORT" "Interrupt"]\r
68     if { [llength $intr_port] == 0 } {\r
69         error "CPU has no connection to Interrupt controller." "" "mdt_error"\r
70     }\r
71 \r
72     # support only AXI/PLB\r
73     set interconnect [xget_value $hw_proc_handle "PARAMETER" "C_INTERCONNECT"]\r
74     if { $interconnect == 1 } {\r
75         set bus_name [xget_hw_busif_value $hw_proc_handle "DPLB"]\r
76     } elseif { $interconnect == 2 } {\r
77         set bus_name [xget_hw_busif_value $hw_proc_handle "M_AXI_DP"]\r
78     } else {\r
79         error "FreeRTOS supports Microblaze with only a AXI or PLB interconnect" "" "mdt_error"\r
80     }\r
81 \r
82     # obtain handles to all the peripherals in the design\r
83     set mhs_handle [xget_hw_parent_handle $hw_proc_handle]\r
84     set slave_ifs [xget_hw_connected_busifs_handle $mhs_handle $bus_name "slave"]\r
85     set timer_count 0\r
86     set timer_has_intr 0\r
87 \r
88     # check for a valid timer\r
89     foreach if $slave_ifs {\r
90         set ip_handle [xget_hw_parent_handle $if]\r
91 \r
92         if {$ip_handle != $hw_proc_handle} {\r
93             set type [xget_hw_value $ip_handle]\r
94             if { $type == "xps_timer" || $type == "axi_timer" } {\r
95                 incr timer_count\r
96                 \r
97                 # check if the timer interrupts are enabled\r
98                 set intr_port [xget_value $ip_handle "PORT" "Interrupt"]\r
99                 if { [llength $intr_port] != 0 } {\r
100                     set timer_has_intr 1\r
101                 }\r
102             }\r
103         }\r
104     }\r
105 \r
106     if { $timer_count == 0 } {\r
107         error "FreeRTOS for Microblaze requires an axi_timer or xps_timer. The HW platform doesn't have a valid timer." "" "mdt_error"\r
108     }\r
109 \r
110     if { $timer_has_intr == 0 } {\r
111         error "FreeRTOS for Microblaze requires interrupts enabled for a timer." "" "mdt_error"\r
112     }\r
113 \r
114     set systmr_interval_ms [xget_value $os_handle "PARAMETER" "systmr_interval"]\r
115     if { $systmr_interval_ms <= 0 } {\r
116         error "Invalid value for parameter systmr_interval specified. Please specify a positive value." "" "mdt_error"\r
117     }\r
118 \r
119     ### ToDo: Add DRC specific to FreeRTOS\r
120 }\r
121 \r
122 proc generate {os_handle} {\r
123 \r
124     variable standalone_version\r
125 \r
126     set sw_proc_handle [xget_libgen_proc_handle]\r
127     set hw_proc_handle [xget_handle $sw_proc_handle "IPINST"]\r
128     set proctype [xget_value $hw_proc_handle "OPTION" "IPNAME"]\r
129     set procver [xget_value $hw_proc_handle "PARAMETER" "HW_VER"]\r
130     \r
131     set need_config_file "false"\r
132 \r
133     # proctype should be "microblaze"\r
134     set mbsrcdir  "../${standalone_version}/src/microblaze"\r
135     set commondir   "../${standalone_version}/src/common"\r
136     set datadir   "../${standalone_version}/data"\r
137 \r
138     foreach entry [glob -nocomplain [file join $commondir *]] {\r
139         file copy -force $entry [file join ".." "${standalone_version}" "src"]\r
140     }\r
141     \r
142     # proctype should be "microblaze"\r
143     switch -regexp $proctype {\r
144         "microblaze" { \r
145 \r
146             foreach entry [glob -nocomplain [file join $mbsrcdir *]] {\r
147                 if { [string first "microblaze_interrupt_handler" $entry] == -1 } { ;# Do not copy over the Standalone BSP exception handler\r
148                     file copy -force $entry [file join ".." "${standalone_version}" "src"]\r
149                 }\r
150             }\r
151             set need_config_file "true"\r
152         }\r
153         "default" {puts "unknown processor type $proctype\n"}\r
154     }\r
155 \r
156     # Write the config.make file\r
157     set makeconfig [open "../standalone_v3_01_a/src/config.make" w]  \r
158     xprint_generated_header_tcl $makeconfig "Configuration parameters for Standalone Makefile"\r
159 \r
160     if { $proctype == "microblaze" } {\r
161         if { [mb_has_exceptions $hw_proc_handle] } {\r
162             puts $makeconfig "LIBSOURCES = *.s *.c *.S"\r
163         } else {\r
164             puts $makeconfig "LIBSOURCES = *.s *.c"\r
165         }\r
166     }\r
167 \r
168     puts $makeconfig "LIBS = standalone_libs"\r
169     close $makeconfig\r
170 \r
171     # Remove microblaze directories...\r
172     file delete -force $mbsrcdir\r
173 \r
174     # copy required files to the main src directory\r
175     file copy -force [file join src Source tasks.c] src\r
176     file copy -force [file join src Source queue.c] src\r
177     file copy -force [file join src Source list.c] src\r
178     file copy -force [file join src Source timers.c] src\r
179     file copy -force [file join src Source portable MemMang heap_3.c] src\r
180     file copy -force [file join src Source portable GCC MicroBlazeV8 port.c] src\r
181     file copy -force [file join src Source portable GCC MicroBlazeV8 port_exceptions.c] src\r
182     file copy -force [file join src Source portable GCC MicroBlazeV8 portasm.S] src\r
183     file copy -force [file join src Source portable GCC MicroBlazeV8 portmacro.h] src\r
184     set headers [glob -join ./src/Source/include *.\[h\]]\r
185     foreach header $headers {\r
186         file copy -force $header src\r
187     }\r
188 \r
189     file delete -force [file join src Source]\r
190     file delete -force [file join src Source]\r
191 \r
192     # Handle stdin and stdout\r
193     xhandle_stdin $os_handle\r
194     xhandle_stdout $os_handle\r
195 \r
196     # Create config file for microblaze interrupt handling\r
197     if {[string compare -nocase $need_config_file "true"] == 0} {\r
198         xhandle_mb_interrupts\r
199     }\r
200 \r
201     # Create config files for Microblaze exception handling\r
202     if { $proctype == "microblaze" && [mb_has_exceptions $hw_proc_handle] } {\r
203         xcreate_mb_exc_config_file \r
204     }\r
205 \r
206     # Create bspconfig file\r
207     set bspcfg_fn [file join ".." "${standalone_version}" "src"  "bspconfig.h"] \r
208     file delete $bspcfg_fn\r
209     set bspcfg_fh [open $bspcfg_fn w]\r
210     xprint_generated_header $bspcfg_fh "Configurations for Standalone BSP"\r
211 \r
212     if { $proctype == "microblaze" && [mb_has_pvr $hw_proc_handle] } {\r
213         \r
214         set pvr [xget_value $hw_proc_handle "PARAMETER" "C_PVR"]\r
215         \r
216         switch $pvr {\r
217             "0" {\r
218                 puts $bspcfg_fh "#define MICROBLAZE_PVR_NONE"\r
219             }\r
220             "1" {\r
221                 puts $bspcfg_fh "#define MICROBLAZE_PVR_BASIC"\r
222             }\r
223             "2" {\r
224                 puts $bspcfg_fh "#define MICROBLAZE_PVR_FULL"\r
225             }\r
226             "default" {\r
227                 puts $bspcfg_fh "#define MICROBLAZE_PVR_NONE"\r
228             }\r
229         }    \r
230     }\r
231 \r
232     close $bspcfg_fh\r
233 \r
234 # ToDO: FreeRTOS does not handle the following, refer xilkernel TCL script\r
235 # - MPU settings\r
236 \r
237     set config_file [xopen_new_include_file "./src/FreeRTOSConfig.h" "FreeRTOS Configuration parameters"]\r
238     puts $config_file "\#include \"xparameters.h\" \n"\r
239 \r
240     set val [xget_value $os_handle "PARAMETER" "use_preemption"]\r
241     if {$val == "false"} {\r
242         xput_define $config_file "configUSE_PREEMPTION" "0"\r
243     } else {\r
244         xput_define $config_file "configUSE_PREEMPTION" "1"\r
245     }\r
246 \r
247     set val [xget_value $os_handle "PARAMETER" "use_mutexes"]\r
248     if {$val == "false"} {\r
249         xput_define $config_file "configUSE_MUTEXES" "0"\r
250     } else {\r
251         xput_define $config_file "configUSE_MUTEXES" "1"\r
252     }\r
253     \r
254     set val [xget_value $os_handle "PARAMETER" "use_recursive_mutexes"]\r
255     if {$val == "false"} {\r
256         xput_define $config_file "configUSE_RECURSIVE_MUTEXES" "0"\r
257     } else {\r
258         xput_define $config_file "configUSE_RECURSIVE_MUTEXES" "1"\r
259     }\r
260 \r
261     set val [xget_value $os_handle "PARAMETER" "use_counting_semaphores"]\r
262     if {$val == "false"} {\r
263         xput_define $config_file "configUSE_COUNTING_SEMAPHORES" "0"\r
264     } else {\r
265         xput_define $config_file "configUSE_COUNTING_SEMAPHORES" "1"\r
266     }\r
267 \r
268     set val [xget_value $os_handle "PARAMETER" "use_timers"]\r
269     if {$val == "false"} {\r
270         xput_define $config_file "configUSE_TIMERS" "0"\r
271     } else {\r
272         xput_define $config_file "configUSE_TIMERS" "1"\r
273     }\r
274 \r
275     set val [xget_value $os_handle "PARAMETER" "use_idle_hook"]\r
276     if {$val == "false"} {\r
277         xput_define $config_file "configUSE_IDLE_HOOK"    "0"\r
278     } else {\r
279         xput_define $config_file "configUSE_IDLE_HOOK"    "1"\r
280     }\r
281 \r
282     set val [xget_value $os_handle "PARAMETER" "use_tick_hook"]\r
283     if {$val == "false"} {\r
284         xput_define $config_file "configUSE_TICK_HOOK"    "0"\r
285     } else {\r
286         xput_define $config_file "configUSE_TICK_HOOK"    "1"\r
287     }\r
288 \r
289     set val [xget_value $os_handle "PARAMETER" "use_malloc_failed_hook"]\r
290     if {$val == "false"} {\r
291         xput_define $config_file "configUSE_MALLOC_FAILED_HOOK"    "0"\r
292     } else {\r
293         xput_define $config_file "configUSE_MALLOC_FAILED_HOOK"    "1"\r
294     }\r
295 \r
296     set val [xget_value $os_handle "PARAMETER" "use_trace_facility"]\r
297     if {$val == "false"} {\r
298         xput_define $config_file "configUSE_TRACE_FACILITY" "0"\r
299     } else {\r
300         xput_define $config_file "configUSE_TRACE_FACILITY" "1"\r
301     }\r
302 \r
303     xput_define $config_file "configUSE_16_BIT_TICKS"   "0"\r
304     xput_define $config_file "configUSE_APPLICATION_TASK_TAG"   "0"\r
305     xput_define $config_file "configUSE_CO_ROUTINES"    "0"\r
306 \r
307     # System timer tick rate (Microblaze only. kernel DRC ensures this)\r
308     set systmr_interval [xget_value $os_handle "PARAMETER" "systmr_interval"]\r
309     xput_define $config_file "configTICK_RATE_HZ"     $systmr_interval\r
310 \r
311     set max_priorities [xget_value $os_handle "PARAMETER" "max_priorities"]\r
312     xput_define $config_file "configMAX_PRIORITIES"   $max_priorities\r
313     xput_define $config_file "configMAX_CO_ROUTINE_PRIORITIES" "2"\r
314     \r
315     set min_stack [xget_value $os_handle "PARAMETER" "minimal_stack_size"]\r
316     set min_stack [expr [expr $min_stack + 3] & 0xFFFFFFFC]\r
317     xput_define $config_file "configMINIMAL_STACK_SIZE" $min_stack\r
318 \r
319     set total_heap_size [xget_value $os_handle "PARAMETER" "total_heap_size"]\r
320     set total_heap_size [expr [expr $total_heap_size + 3] & 0xFFFFFFFC]\r
321     xput_define $config_file "configTOTAL_HEAP_SIZE"  $total_heap_size\r
322 \r
323     set max_task_name_len [xget_value $os_handle "PARAMETER" "max_task_name_len"]\r
324     xput_define $config_file "configMAX_TASK_NAME_LEN"  $max_task_name_len\r
325     \r
326     set val [xget_value $os_handle "PARAMETER" "idle_yield"]\r
327     if {$val == "false"} {\r
328         xput_define $config_file "configIDLE_SHOULD_YIELD"  "0"\r
329     } else {\r
330         xput_define $config_file "configIDLE_SHOULD_YIELD"  "1"\r
331     }\r
332 \r
333     set val [xget_value $os_handle "PARAMETER" "check_for_stack_overflow"]\r
334     if {$val == "false"} {\r
335         xput_define $config_file "configCHECK_FOR_STACK_OVERFLOW"  "0"\r
336     } else {\r
337         xput_define $config_file "configCHECK_FOR_STACK_OVERFLOW"  "2"\r
338     }\r
339     \r
340     set val [xget_value $os_handle "PARAMETER" "queue_registry_size"]\r
341     if {$val == "false"} {\r
342         xput_define $config_file "configQUEUE_REGISTRY_SIZE"  "0"\r
343     } else {\r
344         xput_define $config_file "configQUEUE_REGISTRY_SIZE"  "10"\r
345     }\r
346 \r
347     xput_define $config_file "configGENERATE_RUN_TIME_STATS"    "0"\r
348 \r
349     set val [xget_value $os_handle "PARAMETER" "timer_task_priority"]\r
350     if {$val == "false"} {\r
351         xput_define $config_file "configTIMER_TASK_PRIORITY"  "0"\r
352     } else {\r
353         xput_define $config_file "configTIMER_TASK_PRIORITY"  "10"\r
354     }\r
355 \r
356     set val [xget_value $os_handle "PARAMETER" "timer_command_queue_length"]\r
357     if {$val == "false"} {\r
358         xput_define $config_file "configTIMER_QUEUE_LENGTH"  "0"\r
359     } else {\r
360         xput_define $config_file "configTIMER_QUEUE_LENGTH"  "10"\r
361     }\r
362 \r
363     set val [xget_value $os_handle "PARAMETER" "timer_task_stack_depth"]\r
364     if {$val == "false"} {\r
365         xput_define $config_file "configTIMER_TASK_STACK_DEPTH"  "0"\r
366     } else {\r
367         xput_define $config_file "configTIMER_TASK_STACK_DEPTH"  $min_stack\r
368     }\r
369 \r
370     if { [mb_has_exceptions $hw_proc_handle] } {    \r
371         xput_define $config_file "configINSTALL_EXCEPTION_HANDLERS"  "1"\r
372     } else {\r
373         xput_define $config_file "configINSTALL_EXCEPTION_HANDLERS"  "0"\r
374     }\r
375 \r
376     xput_define $config_file "configINTERRUPT_CONTROLLER_TO_USE"  "XPAR_INTC_SINGLE_DEVICE_ID"\r
377 \r
378     xput_define $config_file "INCLUDE_vTaskCleanUpResources" "0"\r
379     xput_define $config_file "INCLUDE_vTaskDelay"        "1"\r
380     xput_define $config_file "INCLUDE_vTaskDelayUntil"   "1"\r
381     xput_define $config_file "INCLUDE_vTaskDelete"       "1"\r
382     xput_define $config_file "INCLUDE_xTaskGetCurrentTaskHandle"   "1"\r
383     xput_define $config_file "INCLUDE_xTaskGetIdleTaskHandle"      "1"\r
384     xput_define $config_file "INCLUDE_xTaskGetSchedulerState"  "1"\r
385     xput_define $config_file "INCLUDE_xTimerGetTimerDaemonTaskHandle"    "1"\r
386     xput_define $config_file "INCLUDE_uxTaskGetStackHighWaterMark"  "1"\r
387     xput_define $config_file "INCLUDE_uxTaskPriorityGet" "1"\r
388     xput_define $config_file "INCLUDE_vTaskPrioritySet"  "1"\r
389     xput_define $config_file "INCLUDE_xTaskResumeFromISR"  "1"\r
390     xput_define $config_file "INCLUDE_vTaskSuspend"      "1"\r
391     xput_define $config_file "INCLUDE_pcTaskGetTaskName"      "1"\r
392     xput_define $config_file "INCLUDE_xTaskGetIdleTaskHandle"      "1"\r
393     xput_define $config_file "INCLUDE_xTimerGetTimerDaemonTaskHandle"      "1"\r
394 \r
395     # complete the header protectors\r
396     puts $config_file "\#endif"\r
397     close $config_file\r
398 }\r
399 \r
400 proc xopen_new_include_file { filename description } {\r
401     set inc_file [open $filename w]\r
402     xprint_generated_header $inc_file $description\r
403     set newfname [string map {. _} [lindex [split $filename {\/}] end]]\r
404     puts $inc_file "\#ifndef _[string toupper $newfname]"\r
405     puts $inc_file "\#define _[string toupper $newfname]\n\n"\r
406     return $inc_file\r
407 }\r
408 \r
409 proc xadd_define { config_file os_handle parameter } {\r
410     set param_value [xget_value $os_handle "PARAMETER" $parameter]\r
411     puts $config_file "#define [string toupper $parameter] $param_value\n"\r
412 \r
413     # puts "creating #define [string toupper $parameter] $param_value\n"\r
414 }\r
415 \r
416 proc xput_define { config_file parameter param_value } {\r
417     puts $config_file "#define $parameter $param_value\n"\r
418 \r
419     # puts "creating #define [string toupper $parameter] $param_value\n"\r
420 }\r
421 \r
422 # args field of the array\r
423 proc xadd_extern_fname {initfile oshandle arrayname arg} { \r
424 \r
425     set arrhandle [xget_handle $oshandle "ARRAY" $arrayname]\r
426     set elements [xget_handle $arrhandle "ELEMENTS" "*"]\r
427     set count 0\r
428     set max_count [llength $elements]\r
429 \r
430     foreach ele $elements {\r
431         incr count\r
432         set arg_value [xget_value $ele "PARAMETER" $arg]\r
433         puts $initfile "extern void $arg_value\(\)\;"\r
434     }\r
435     puts $initfile ""\r
436 }\r
437 \r
438 # args is variable no - fields of the array\r
439 proc xadd_struct {initfile oshandle structtype structname arrayname args} { \r
440 \r
441     set arrhandle [xget_handle $oshandle "ARRAY" $arrayname]\r
442     set elements [xget_handle $arrhandle "ELEMENTS" "*"]\r
443     set count 0\r
444     set max_count [llength $elements]\r
445     puts $initfile "struct $structtype $structname\[$max_count\] = \{"\r
446 \r
447     foreach ele $elements {\r
448         incr count\r
449         puts -nonewline $initfile "\t\{"\r
450         foreach field $args {\r
451             set field_value [xget_value $ele "PARAMETER" $field]\r
452             # puts "$arrayname ( $count )->$field is $field_value"\r
453             puts -nonewline $initfile "$field_value"\r
454             if { $field != [lindex $args end] } {\r
455                 puts -nonewline $initfile ","\r
456             }\r
457         }\r
458         if {$count < $max_count} {\r
459             puts $initfile "\},"\r
460         } else {\r
461             puts $initfile "\}"\r
462         }\r
463     }\r
464     puts $initfile "\}\;"\r
465 }\r
466 \r
467 # return the sum of all the arg field values in arrayname\r
468 proc get_field_sum {oshandle arrayname arg} { \r
469 \r
470     set arrhandle [xget_handle $oshandle "ARRAY" $arrayname]\r
471     set elements [xget_handle $arrhandle "ELEMENTS" "*"]\r
472     set count 0\r
473     set max_count [llength $elements]\r
474   \r
475     foreach ele $elements {\r
476         set field_value [xget_value $ele "PARAMETER" $arg]\r
477         set count [expr $field_value+$count]\r
478     }\r
479     return $count\r
480 }\r
481 \r
482 # return the sum of the product of field values in arrayname\r
483 proc get_field_product_sum {oshandle arrayname field1 field2} { \r
484 \r
485     set arrhandle [xget_handle $oshandle "ARRAY" $arrayname]\r
486     set elements [xget_handle $arrhandle "ELEMENTS" "*"]\r
487     set count 0\r
488     set max_count [llength $elements]\r
489 \r
490     foreach ele $elements {\r
491         set field1_value [xget_value $ele "PARAMETER" $field1]\r
492         set field2_value [xget_value $ele "PARAMETER" $field2]\r
493         set incr_value [expr $field1_value*$field2_value]\r
494         set count [expr $count+$incr_value]\r
495     }\r
496     return $count\r
497 }\r
498 \r
499 proc xhandle_mb_interrupts {} {\r
500 \r
501     set default_interrupt_handler "XNullHandler"\r
502     set default_arg "XNULL"\r
503 \r
504     set source_interrupt_handler $default_interrupt_handler\r
505     set source_handler_arg $default_arg\r
506     \r
507     # Handle the interrupt pin\r
508     set sw_proc_handle [xget_libgen_proc_handle] \r
509     set periph [xget_handle $sw_proc_handle "IPINST"]\r
510     set source_ports [xget_interrupt_sources $periph]\r
511     if {[llength $source_ports] > 1} {\r
512         error "Too many interrupting ports on the MicroBlaze.  Should only find 1" "" "libgen_error"\r
513         return\r
514     }\r
515     \r
516     if {[llength $source_ports] == 1} {\r
517         set source_port [lindex $source_ports 0]\r
518         if {[llength $source_port] != 0} {\r
519             set source_port_name [xget_value $source_port "VALUE"]      \r
520             set source_periph [xget_handle $source_port "PARENT"]\r
521             set source_name [xget_value $source_periph "NAME"]\r
522             set source_driver [xget_sw_driver_handle_for_ipinst $sw_proc_handle $source_name]\r
523 \r
524             if {[string compare -nocase $source_driver ""] != 0} {\r
525                 set int_array [xget_handle $source_driver "ARRAY" "interrupt_handler"]\r
526                 if {[llength $int_array] != 0} {\r
527                     set int_array_elems [xget_handle $int_array "ELEMENTS" "*"]\r
528                     if {[llength $int_array_elems] != 0} {\r
529                         foreach int_array_elem $int_array_elems {\r
530                             set int_port [xget_value $int_array_elem "PARAMETER" "int_port"]\r
531                             if {[llength $int_port] != 0} {\r
532                                 if {[string compare -nocase $int_port $source_port_name] == 0 } {\r
533                                     set source_interrupt_handler [xget_value $int_array_elem "PARAMETER" "int_handler"]\r
534                                     set source_handler_arg [xget_value $int_array_elem "PARAMETER" "int_handler_arg"]\r
535                                     if {[string compare -nocase $source_handler_arg DEVICE_ID] == 0 } {\r
536                                         set source_handler_arg [xget_name $source_periph "DEVICE_ID"]\r
537                                     } else {\r
538                                         if {[string compare -nocase "global" [xget_port_type $source_port]] == 0} {\r
539                                             set source_handler_arg $default_arg\r
540                                         } else {\r
541                                             set source_handler_arg [xget_name $source_periph "C_BASEADDR"]\r
542                                         }\r
543                                     }\r
544                                     break\r
545                                 }\r
546                             }\r
547                         }\r
548                     }\r
549                 }\r
550             }\r
551         }\r
552     }\r
553     \r
554     # Generate microblaze_interrupts_g.c file...\r
555     xcreate_mb_intr_config_file $source_interrupt_handler $source_handler_arg\r
556     \r
557 }\r
558 \r
559 \r
560 proc xcreate_mb_intr_config_file {handler arg} {\r
561     \r
562     set mb_table "MB_InterruptVectorTable"\r
563 \r
564     set filename [file join "../standalone_v3_01_a/src" "microblaze_interrupts_g.c"] \r
565     file delete $filename\r
566     set config_file [open $filename w]\r
567 \r
568     xprint_generated_header $config_file "Interrupt Handler Table for MicroBlaze Processor"\r
569     \r
570     puts $config_file "#include \"microblaze_interrupts_i.h\""\r
571     puts $config_file "#include \"xparameters.h\""\r
572     puts $config_file "\n"\r
573     puts $config_file [format "extern void %s (void *);" $handler]\r
574     puts $config_file "\n/*"\r
575     puts $config_file "* The interrupt handler table for microblaze processor"\r
576     puts $config_file "*/\n"\r
577     puts $config_file [format "%sEntry %s\[\] =" $mb_table $mb_table]\r
578     puts $config_file "\{"\r
579     puts -nonewline $config_file [format "\{\t%s" $handler]\r
580     puts -nonewline $config_file [format ",\n\t(void*) %s\}" $arg]\r
581     puts -nonewline $config_file "\n\};"\r
582     puts $config_file "\n"\r
583     close $config_file\r
584 }\r
585 \r
586 \r
587 # -------------------------------------------\r
588 # Tcl procedure xcreate_mb_exc_config file\r
589 # -------------------------------------------\r
590 proc xcreate_mb_exc_config_file { } {\r
591     \r
592     set hfilename [file join "src" "microblaze_exceptions_g.h"] \r
593     file delete $hfilename\r
594     set hconfig_file [open $hfilename w]\r
595 \r
596     xprint_generated_header $hconfig_file "Exception Handling Header for MicroBlaze Processor"\r
597     \r
598     puts $hconfig_file "\n"\r
599 \r
600     set sw_proc_handle [xget_libgen_proc_handle]\r
601     set hw_proc_handle [xget_handle $sw_proc_handle "IPINST"]\r
602     set procver [xget_value $hw_proc_handle "PARAMETER" "HW_VER"]\r
603 \r
604     if { ![mb_has_exceptions $hw_proc_handle]} { ;# NO exceptions are enabled\r
605         close $hconfig_file              ;# Do not generate any info in either the header or the C file\r
606         return\r
607     }\r
608     \r
609     puts $hconfig_file "\#define MICROBLAZE_EXCEPTIONS_ENABLED 1"\r
610     if { [mb_can_handle_exceptions_in_delay_slots $procver] } {\r
611         puts $hconfig_file "#define MICROBLAZE_CAN_HANDLE_EXCEPTIONS_IN_DELAY_SLOTS"\r
612     }\r
613 \r
614     close $hconfig_file\r
615 }\r
616 \r
617 # --------------------------------------\r
618 # Tcl procedure post_generate\r
619 # This proc removes from libxil.a the basic \r
620 # and standalone BSP versions of \r
621 # _interrupt_handler and _hw_exception_handler\r
622 # routines\r
623 # --------------------------------------\r
624 proc post_generate {os_handle} {\r
625     set sw_proc_handle [xget_libgen_proc_handle]\r
626     set hw_proc_handle [xget_handle $sw_proc_handle "IPINST"]\r
627     set proctype [xget_value $hw_proc_handle "OPTION" "IPNAME"]\r
628     set procname [xget_value $hw_proc_handle "NAME"]\r
629 \r
630     set procdrv [xget_sw_driver_handle_for_ipinst $sw_proc_handle $procname]\r
631     set archiver [xget_value $procdrv "PARAMETER" "archiver"]\r
632 \r
633     if {[string compare -nocase $proctype "microblaze"] == 0 } {\r
634         # Remove _interrupt_handler.o from libxil.a for FreeRTOS\r
635                 set libxil_a [file join .. .. lib libxil.a]\r
636         exec $archiver -d $libxil_a   _interrupt_handler.o\r
637 \r
638         # We have linkage problems due to how these platforms are defined. Can't do this right now.  \r
639         # # Remove _exception_handler.o from libxil.a for FreeRTOS\r
640         # exec bash -c "$archiver -d ../../lib/libxil.a _exception_handler.o"\r
641         \r
642         # Remove _hw_exception_handler.o from libxil.a for microblaze cores with exception support\r
643         if {[mb_has_exceptions $hw_proc_handle]} {\r
644             exec $archiver -d ../../lib/libxil.a _hw_exception_handler.o\r
645         }\r
646     }\r
647 }\r
648 \r
649 # --------------------------------------\r
650 # Tcl procedure execs_generate\r
651 # This proc removes from libxil.a all \r
652 # the stuff that we are overriding\r
653 # with xilkernel\r
654 # We currently override,\r
655 #  MicroBlaze\r
656 #   - Dummy _interrupt_hander and _hw_exception_handler \r
657 #     (in post_generate)\r
658 #  PPC\r
659 #   - xvectors.o; sleep.o (IF config_time is true)\r
660 #  Common to all processors\r
661 #    - errno.o\r
662 # --------------------------------------\r
663 proc execs_generate {os_handle} {\r
664     set sw_proc_handle [xget_libgen_proc_handle]\r
665     set hw_proc_handle [xget_handle $sw_proc_handle "IPINST"]\r
666     set proctype [xget_value $hw_proc_handle "OPTION" "IPNAME"]\r
667     set procname [xget_value $hw_proc_handle "NAME"]\r
668 \r
669     set procdrv [xget_sw_driver_handle_for_ipinst $sw_proc_handle $procname]\r
670     # Remove _interrupt_handler.o from libxil.a for mb-gcc\r
671     set archiver [xget_value $procdrv "PARAMETER" "archiver"]\r
672 \r
673     set libxil_a [file join .. .. lib libxil.a]\r
674 #    exec $archiver -d $libxil_a  errno.o\r
675 \r
676     # We have linkage problems due to how these platforms are defined. Can't do this right now.  \r
677     # exec "$archiver -d $libxil_a microblaze_interrupt_handler.o"\r
678 }\r
679 \r
680 # --------------------------------------\r
681 # Return true if this MB has \r
682 # exception handling support\r
683 # --------------------------------------\r
684 proc mb_has_exceptions { hw_proc_handle } {\r
685    \r
686     # Check if the following parameters exist on this MicroBlaze's MPD\r
687     set ee [xget_value $hw_proc_handle "PARAMETER" "C_UNALIGNED_EXCEPTIONS"]\r
688     if { $ee != "" } {\r
689         return true\r
690     }\r
691 \r
692     set ee [xget_value $hw_proc_handle "PARAMETER" "C_ILL_OPCODE_EXCEPTION"]\r
693     if { $ee != "" } {\r
694         return true\r
695     }\r
696 \r
697     set ee [xget_value $hw_proc_handle "PARAMETER" "C_IOPB_BUS_EXCEPTION"]\r
698     if { $ee != "" } {\r
699         return true\r
700     }\r
701 \r
702     set ee [xget_value $hw_proc_handle "PARAMETER" "C_DOPB_BUS_EXCEPTION"]\r
703     if { $ee != "" } {\r
704         return true\r
705     }\r
706 \r
707     set ee [xget_value $hw_proc_handle "PARAMETER" "C_DIV_BY_ZERO_EXCEPTION"]\r
708     if { $ee != "" } {\r
709         return true\r
710     } \r
711 \r
712     set ee [xget_value $hw_proc_handle "PARAMETER" "C_DIV_ZERO_EXCEPTION"]\r
713     if { $ee != "" } {\r
714         return true\r
715     } \r
716 \r
717     set ee [xget_value $hw_proc_handle "PARAMETER" "C_FPU_EXCEPTION"]\r
718     if { $ee != "" } {\r
719         return true\r
720     } \r
721 \r
722     set ee [xget_value $hw_proc_handle "PARAMETER" "C_USE_MMU"]\r
723     if { $ee != "" && $ee != 0 } {\r
724         return true\r
725     } \r
726 \r
727     return false\r
728 }\r
729 \r
730 # --------------------------------------\r
731 # Return true if this MB has \r
732 # FPU exception handling support\r
733 # --------------------------------------\r
734 proc mb_has_fpu_exceptions { hw_proc_handle } {\r
735     \r
736     # Check if the following parameters exist on this MicroBlaze's MPD\r
737     set ee [xget_value $hw_proc_handle "PARAMETER" "C_FPU_EXCEPTION"]\r
738     if { $ee != "" } {\r
739         return true\r
740     }\r
741 \r
742     return false\r
743 }\r
744 \r
745 # --------------------------------------\r
746 # Return true if this MB has PVR support\r
747 # --------------------------------------\r
748 proc mb_has_pvr { hw_proc_handle } {\r
749     \r
750     # Check if the following parameters exist on this MicroBlaze's MPD\r
751     set pvr [xget_value $hw_proc_handle "PARAMETER" "C_PVR"]\r
752     if { $pvr != "" } {\r
753         return true\r
754     } \r
755 \r
756     return false\r
757 }\r
758 \r
759 # --------------------------------------\r
760 # Return true if MB ver 'procver' has \r
761 # support for handling exceptions in \r
762 # delay slots\r
763 # --------------------------------------\r
764 proc mb_can_handle_exceptions_in_delay_slots { procver } {\r
765     \r
766     if { [string compare -nocase $procver "5.00.a"] >= 0 } {\r
767         return true\r
768     } else {\r
769         return false\r
770     }\r
771 }\r
772 \r
773 # --------------------------------------------------------------------------\r
774 # Gets all the handles that are memory controller cores.\r
775 # --------------------------------------------------------------------------\r
776 proc xget_memory_controller_handles { mhs } {\r
777    set ret_list ""\r
778 \r
779    # Gets all MhsInsts in the system\r
780    set mhsinsts [xget_hw_ipinst_handle $mhs "*"]\r
781 \r
782    # Loop thru each MhsInst and determine if have "ADDR_TYPE = MEMORY" in\r
783    # the parameters.\r
784    foreach mhsinst $mhsinsts {\r
785       # Gets all parameters of the component\r
786       set params [xget_hw_parameter_handle $mhsinst "*"]\r
787 \r
788       # Loop thru each param and find tag "ADDR_TYPE = MEMORY"\r
789       foreach param $params {\r
790          if {$param == 0} {\r
791             continue\r
792          } elseif {$param == ""} {\r
793             continue\r
794          }\r
795          set addrTypeValue [ xget_hw_subproperty_value $param "ADDR_TYPE" ]\r
796 \r
797          # Found tag! Add MhsInst to list and break to go to next MhsInst\r
798          if {[string compare -nocase $addrTypeValue "MEMORY"] == 0} {\r
799             lappend ret_list $mhsinst\r
800             break\r
801          }\r
802       }\r
803    }\r
804 \r
805    return $ret_list\r
806 }\r