[4696] | 1 | ############################################################### |
---|
| 2 | # WARPLab UDP Transport |
---|
| 3 | # Copyright 2015 Mango Communications |
---|
| 4 | # Distributed under the WARP license (http://warpproject.org/license) |
---|
| 5 | ############################################################### |
---|
| 6 | #uses "xillib.tcl" |
---|
| 7 | |
---|
| 8 | # NOTE: |
---|
| 9 | # In order to use the WARP UDP transport library, the Ethernet instances |
---|
| 10 | # within the design need to have either "ETH_A" or "ETH_B" somewhere in the |
---|
| 11 | # instance name. Due to some limitations with the Xilinx TCL generation |
---|
| 12 | # capabilities this script cannot pass instance names up to the MLD file to |
---|
| 13 | # be displayed as parameter names. Therefore, this driver has two parameters: |
---|
[4708] | 14 | # 1) ETH_A_uses_library |
---|
| 15 | # 2) ETH_B_uses_library |
---|
[4696] | 16 | # that are used to control if a given Ethernet instance is controlled by the |
---|
| 17 | # WARP UDP transport library. If an instance is not controlled by this library, |
---|
| 18 | # then the library will not allocate buffers or control structures in order to |
---|
| 19 | # minimize code and data space of this library. |
---|
| 20 | # |
---|
| 21 | # This library will complain if: |
---|
| 22 | # 1) There are more than two Ethernet instances, but will complete and |
---|
| 23 | # allocate buffers and control structures for all instances |
---|
| 24 | # 2) If none of the Ethernet instances contain either "ETH_A" or "ETH_B". |
---|
[4708] | 25 | # In this case, the *_uses_library parameters will be ignored and |
---|
[4696] | 26 | # buffers and control structures will be allocated for all instances |
---|
[4708] | 27 | # 3) If the *_uses_library parameter is set to '1' and the corresponding |
---|
[4696] | 28 | # "ETH_*" doesn't exist, then the driver will error out, except in |
---|
| 29 | # the situation of case 2) above. |
---|
| 30 | # |
---|
| 31 | |
---|
| 32 | set num_ethernet_instances 0 |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | ############################################################### |
---|
| 36 | # Gets all Ethernet Peripherals from the MHS file |
---|
| 37 | # |
---|
| 38 | # @param MHS Handle - Handle to MHS file |
---|
| 39 | # |
---|
| 40 | # @return List of Ethernet Peripherals that contain "ETH_A" or "ETH_B" in the name |
---|
| 41 | # |
---|
| 42 | # @note This method will also increment the global variable: |
---|
| 43 | # num_ethernet_instances |
---|
| 44 | # |
---|
| 45 | ############################################################### |
---|
| 46 | proc get_ethernet_peripherals {mhs_handle} { |
---|
| 47 | global num_ethernet_instances |
---|
| 48 | |
---|
| 49 | set ip_instance_list [xget_hw_ipinst_handle $mhs_handle "*"] |
---|
| 50 | set num_ethernet_instances 0 |
---|
| 51 | set ethernet_peripheral_list {} |
---|
| 52 | |
---|
| 53 | foreach peripheral $ip_instance_list { |
---|
| 54 | set peripheral_type [xget_hw_value $peripheral] |
---|
| 55 | set peripheral_name [xget_value $peripheral "name"] |
---|
| 56 | |
---|
| 57 | if { $peripheral_type == "axi_ethernet" } { |
---|
| 58 | |
---|
| 59 | # Increment global variable for later use |
---|
| 60 | incr num_ethernet_instances |
---|
| 61 | |
---|
| 62 | if {[regexp -nocase {eth_a} $peripheral_name]} { |
---|
| 63 | # If the list already contains elements, insert "ETH_A" first |
---|
| 64 | if {[llength $ethernet_peripheral_list] > 0} { |
---|
| 65 | set ethernet_peripheral_list [linsert $ethernet_peripheral_list 0 $peripheral] |
---|
| 66 | } else { |
---|
| 67 | lappend ethernet_peripheral_list $peripheral |
---|
| 68 | } |
---|
| 69 | } elseif {[regexp -nocase {eth_b} $peripheral_name]} { |
---|
| 70 | lappend ethernet_peripheral_list $peripheral |
---|
| 71 | } else { |
---|
| 72 | lappend ethernet_peripheral_list $peripheral |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | return $ethernet_peripheral_list |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | ############################################################### |
---|
| 82 | # Gets all Ethernet Interface Peripherals from the MHS file |
---|
| 83 | # |
---|
| 84 | # @param MHS Handle - Handle to MHS file |
---|
| 85 | # @param Instance Handle - Handle to Ethernet instance |
---|
| 86 | # |
---|
| 87 | # @return Instance Handle - Handle to Interface instance or None |
---|
| 88 | # |
---|
| 89 | ############################################################### |
---|
| 90 | proc get_ethernet_interface_peripheral {mhs_handle instance_handle} { |
---|
| 91 | |
---|
| 92 | set bus_interface_list [xget_hw_busifs_by_subproperty $instance_handle "BUS_TYPE" "INITIATOR"] |
---|
| 93 | |
---|
| 94 | foreach bus_interface $bus_interface_list { |
---|
| 95 | |
---|
| 96 | set bus_name [string toupper [xget_hw_value $bus_interface]] |
---|
| 97 | set bus_interface_handle [xget_hw_connected_busifs_handle $mhs_handle $bus_name "TARGET"] |
---|
| 98 | |
---|
| 99 | if { [string compare -nocase $bus_interface_handle ""] == 0} { |
---|
| 100 | continue |
---|
| 101 | } else { |
---|
| 102 | set bus_interface_name [xget_hw_name $bus_interface_handle] |
---|
| 103 | set target_peripheral [xget_hw_parent_handle $bus_interface_handle] |
---|
| 104 | |
---|
| 105 | set target_type [xget_hw_value $target_peripheral] |
---|
| 106 | set target_name [string toupper [xget_hw_name $target_peripheral]] |
---|
| 107 | |
---|
| 108 | return $target_peripheral |
---|
| 109 | } |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | return |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | ############################################################### |
---|
| 117 | # Open files |
---|
| 118 | # |
---|
| 119 | # @param File Name |
---|
| 120 | # @param Description |
---|
| 121 | # |
---|
| 122 | # @return Instance Handle - Handle to file |
---|
| 123 | # |
---|
| 124 | ############################################################### |
---|
| 125 | proc open_file {filename description} { |
---|
| 126 | set file_handle [open $filename w] |
---|
| 127 | |
---|
| 128 | # Add the WARP Header to the file |
---|
| 129 | puts $file_handle "/** @file $filename" |
---|
| 130 | puts $file_handle " * @brief $description" |
---|
| 131 | puts $file_handle " *" |
---|
| 132 | puts $file_handle " * @copyright Copyright 2015, Mango Communications. All rights reserved." |
---|
| 133 | puts $file_handle " * Distributed under the WARP license (http://warpproject.org/license)" |
---|
| 134 | puts $file_handle " *" |
---|
| 135 | puts $file_handle " * @author Chris Hunter (chunter \[at\] mangocomm.com)" |
---|
| 136 | puts $file_handle " * @author Patrick Murphy (murphpo \[at\] mangocomm.com)" |
---|
| 137 | puts $file_handle " * @author Erik Welsh (welsh \[at\] mangocomm.com)" |
---|
| 138 | puts $file_handle " */" |
---|
| 139 | puts $file_handle "" |
---|
| 140 | |
---|
| 141 | return $file_handle |
---|
| 142 | } |
---|
| 143 | |
---|
| 144 | proc open_src_file {filename description} { |
---|
| 145 | set expanded_filename [file join "./src/" $filename] |
---|
| 146 | return [open_file $expanded_filename $description] |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | ############################################################### |
---|
| 151 | # Main method to generate WARP UDP Transport files |
---|
| 152 | # |
---|
| 153 | # @param Library Handle |
---|
| 154 | # |
---|
| 155 | # @return None |
---|
| 156 | # |
---|
| 157 | ############################################################### |
---|
| 158 | proc generate {lib_handle} { |
---|
| 159 | global num_ethernet_instances |
---|
| 160 | |
---|
| 161 | # From the library handle, get the Ethernet instances out of the MHS file |
---|
| 162 | set sw_proc_handle [xget_processor] |
---|
| 163 | set hw_proc_handle [xget_handle $sw_proc_handle "IPINST"] |
---|
| 164 | set mhs_handle [xget_hw_parent_handle $hw_proc_handle] |
---|
| 165 | set ethernet_instance_list [get_ethernet_peripherals $mhs_handle] |
---|
| 166 | |
---|
| 167 | # Error checking |
---|
| 168 | if {$num_ethernet_instances == 0} { |
---|
| 169 | error "Invalid configuration: No Ethernet instances found." "" "mdt_error" |
---|
| 170 | return |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | # Initialize variables for loop |
---|
| 174 | set ethernet_instance_num 0 |
---|
| 175 | set use_names 0 |
---|
| 176 | set interface_type_list {} |
---|
| 177 | set ignore_list {} |
---|
| 178 | |
---|
| 179 | # Initialize files |
---|
| 180 | set config_c_file [open_src_file "WARP_ip_udp_config.c" "WARP IP/UDP Library (Config)"] |
---|
| 181 | set config_h_file [open_src_file "WARP_ip_udp_config.h" "WARP IP/UDP Library (Config)"] |
---|
| 182 | set device_h_file [open_src_file "WARP_ip_udp_device.h" "WARP IP/UDP Library (Device)"] |
---|
| 183 | |
---|
| 184 | # Get library parameters |
---|
[4708] | 185 | set eth_a_uses_library [xget_value $lib_handle "PARAMETER" "ETH_A_uses_library"] |
---|
| 186 | set eth_b_uses_library [xget_value $lib_handle "PARAMETER" "ETH_B_uses_library"] |
---|
[4696] | 187 | |
---|
| 188 | set eth_buffer_size [xget_value $lib_handle "PARAMETER" "eth_buffer_size"] |
---|
| 189 | set num_rx_buffers [xget_value $lib_handle "PARAMETER" "num_rx_buffers"] |
---|
| 190 | set num_tx_buffers [xget_value $lib_handle "PARAMETER" "num_tx_buffers"] |
---|
| 191 | set num_tx_descriptors [xget_value $lib_handle "PARAMETER" "num_tx_descriptors"] |
---|
| 192 | |
---|
| 193 | set num_arp_entries [xget_value $lib_handle "PARAMETER" "num_arp_entries"] |
---|
| 194 | set num_udp_sockets [xget_value $lib_handle "PARAMETER" "num_udp_sockets"] |
---|
| 195 | |
---|
| 196 | set eth_default_speed [xget_value $lib_handle "PARAMETER" "eth_default_speed"] |
---|
| 197 | |
---|
| 198 | |
---|
| 199 | # Check Ethernet instances and instance names |
---|
| 200 | # 1) There are more than two Ethernet instances, but will complete and allocate buffers and control |
---|
| 201 | # structures for all instances |
---|
| 202 | # 2) If none of the Ethernet instances contain either "ETH_A" or "ETH_B". In this case, the |
---|
[4708] | 203 | # *_uses_library parameters will be ignored and buffers and control structures will be allocated |
---|
[4696] | 204 | # for all instances |
---|
[4708] | 205 | # 3) If the *_uses_library parameter is set to '1' and the corresponding "ETH_*" doesn't exist, |
---|
[4696] | 206 | # then the driver will error out, except in the situation of case 2) above. |
---|
| 207 | # |
---|
| 208 | if {$num_ethernet_instances > 2} { |
---|
| 209 | puts "\# --------------------------------------" |
---|
| 210 | puts "\# WARP UDP Transport WARNING:" |
---|
| 211 | puts "\# More than 2 Ethernet instances." |
---|
[4708] | 212 | puts "\# Ignoring ETH_*_uses_library parameters." |
---|
[4696] | 213 | puts "\# --------------------------------------" |
---|
| 214 | |
---|
| 215 | incr use_names |
---|
| 216 | |
---|
| 217 | } else { |
---|
| 218 | set eth_a_exists 0 |
---|
| 219 | set eth_b_exists 0 |
---|
| 220 | |
---|
| 221 | foreach inst $ethernet_instance_list { |
---|
| 222 | set inst_name [string toupper [xget_hw_name $inst]] |
---|
| 223 | |
---|
| 224 | if { [regexp -nocase {eth_a} $inst_name] } { |
---|
| 225 | incr eth_a_exists |
---|
| 226 | } |
---|
| 227 | if { [regexp -nocase {eth_b} $inst_name] } { |
---|
| 228 | incr eth_b_exists |
---|
| 229 | } |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | if { $eth_a_exists == 0 && $eth_b_exists == 0 } { |
---|
| 233 | puts "\# --------------------------------------" |
---|
| 234 | puts "\# WARP UDP Transport WARNING:" |
---|
| 235 | puts "\# No Ethernet instances contain either \"ETH_A\" or \"ETH_B\"." |
---|
[4708] | 236 | puts "\# Ignoring ETH_*_uses_library parameters." |
---|
[4696] | 237 | puts "\# --------------------------------------" |
---|
| 238 | |
---|
| 239 | } else { |
---|
[4708] | 240 | if { $eth_a_uses_library == 1 && $eth_a_exists == 0 } { |
---|
[4696] | 241 | error "Invalid configuration: ETH_A does not exist but required by library." "" "mdt_error" |
---|
| 242 | return |
---|
| 243 | } |
---|
| 244 | |
---|
[4708] | 245 | if { $eth_b_uses_library == 1 && $eth_b_exists == 0 } { |
---|
[4696] | 246 | error "Invalid configuration: ETH_B does not exist but required by library." "" "mdt_error" |
---|
| 247 | return |
---|
| 248 | } |
---|
| 249 | } |
---|
| 250 | } |
---|
| 251 | |
---|
| 252 | # Print the file headers of the generated files |
---|
| 253 | print_config_h_file_header $config_h_file $eth_buffer_size $num_tx_buffers $num_tx_descriptors $num_arp_entries $num_udp_sockets |
---|
| 254 | print_config_c_file_header $config_c_file |
---|
| 255 | print_device_h_file_header $device_h_file |
---|
| 256 | |
---|
| 257 | |
---|
| 258 | # Print the Ethernet device specific body elements of the generated files |
---|
| 259 | foreach instance $ethernet_instance_list { |
---|
| 260 | |
---|
| 261 | set instance_type [xget_hw_value $instance] |
---|
| 262 | set instance_name [string toupper [xget_hw_name $instance]] |
---|
| 263 | set ignore 0 |
---|
| 264 | |
---|
| 265 | # Check if we should ignore this Ethernet instance |
---|
| 266 | # NOTE: This implementation relies on the fact that all the checks above passed |
---|
| 267 | # |
---|
[4708] | 268 | if {[regexp -nocase {eth_a} $instance_name] && $eth_a_uses_library == 0} { incr ignore } |
---|
| 269 | if {[regexp -nocase {eth_b} $instance_name] && $eth_b_uses_library == 0} { incr ignore } |
---|
| 270 | |
---|
[4696] | 271 | # Check that this is an "axi_ethernet" type peripheral |
---|
| 272 | if {[string compare -nocase $instance_type "axi_ethernet"] == 0} { |
---|
| 273 | |
---|
| 274 | # Determine the interface attached to the axi_ethernet |
---|
| 275 | set inf_inst [get_ethernet_interface_peripheral $mhs_handle $instance] |
---|
| 276 | |
---|
| 277 | if {[llength $inf_inst] != 0} { |
---|
| 278 | set inf_inst_type [xget_hw_value $inf_inst] |
---|
| 279 | set inf_inst_name [string toupper [xget_hw_name $inf_inst]] |
---|
| 280 | |
---|
| 281 | lappend inf_type_list $inf_inst_type |
---|
| 282 | lappend ignore_list $ignore |
---|
| 283 | |
---|
| 284 | switch $inf_inst_type { |
---|
| 285 | "axi_dma" { |
---|
| 286 | print_config_h_file_body $config_h_file $ethernet_instance_num $instance_name $inf_inst_name $num_rx_buffers $eth_default_speed $ignore |
---|
| 287 | print_config_c_file_body $config_c_file $ethernet_instance_num $ignore |
---|
| 288 | print_device_h_file_body $device_h_file $ethernet_instance_num $instance_name $ignore |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | "default" { |
---|
| 292 | error "Unable to handle AXI connections for interfaces of type $inf_inst_type. Some common causes are |
---|
| 293 | 1. The AXI4 Stream interface of the AXI Ethernet is left unconnected. |
---|
| 294 | 2. The Ethernet instance is connected to an AXI FIFO. |
---|
| 295 | 3. A custom peripheral is connected to the AXI interface. The WARP UDP Transport has been designed for use with the AXI DMA peripheral only." "" "mdt_error" |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | } else { |
---|
| 299 | if {$ignore != 0} { |
---|
| 300 | print_config_h_file_body $config_h_file $ethernet_instance_num $instance_name $inf_inst_name $num_rx_buffers $eth_default_speed $ignore |
---|
| 301 | print_config_c_file_body $config_c_file $ethernet_instance_num $ignore |
---|
| 302 | print_device_h_file_body $device_h_file $ethernet_instance_num $instance_name $ignore |
---|
| 303 | } else { |
---|
| 304 | error "Unable to find AXI interface for $inst_name. Some common causes are |
---|
| 305 | 1. The AXI4 Stream interface of the AXI Ethernet is left unconnected. |
---|
| 306 | 2. The Ethernet instance is connected to an AXI FIFO. |
---|
| 307 | 3. A custom peripheral is connected to the AXI interface. The WARP UDP Transport has been designed for use with the AXI DMA peripheral only." "" "mdt_error" |
---|
| 308 | } |
---|
| 309 | } |
---|
| 310 | |
---|
| 311 | } else { |
---|
| 312 | error "$inst_name is not a AXI Ethernet core. The WARP UDP Transport can work only with AXI Ethernet." "" "mdt_error" |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | # increment the instance number for the next iteration of the for loop |
---|
| 316 | incr ethernet_instance_num |
---|
| 317 | } |
---|
| 318 | |
---|
| 319 | # Print the footer for the generated files |
---|
| 320 | print_config_h_file_footer $config_h_file |
---|
| 321 | print_config_c_file_footer $config_c_file $inf_type_list $ignore_list |
---|
| 322 | print_device_h_file_footer $device_h_file |
---|
| 323 | |
---|
| 324 | # Close the generated files |
---|
| 325 | close $config_h_file |
---|
| 326 | close $config_c_file |
---|
| 327 | close $device_h_file |
---|
| 328 | |
---|
| 329 | } |
---|
| 330 | |
---|
| 331 | |
---|
| 332 | ############################################################### |
---|
| 333 | # Methods to print the config header file |
---|
| 334 | # |
---|
| 335 | # @param Varies |
---|
| 336 | # |
---|
| 337 | # @return None |
---|
| 338 | # |
---|
| 339 | ############################################################### |
---|
| 340 | proc print_config_h_file_header {file_handle eth_buffer_size num_tx_buffers num_tx_descriptors num_arp_entries num_udp_sockets} { |
---|
| 341 | puts $file_handle "" |
---|
| 342 | puts $file_handle "\#ifndef WARP_IP_UDP_CONFIG_H" |
---|
| 343 | puts $file_handle "\#define WARP_IP_UDP_CONFIG_H" |
---|
| 344 | puts $file_handle "" |
---|
| 345 | puts $file_handle "" |
---|
| 346 | puts $file_handle "/***************************** Include Files *********************************/" |
---|
| 347 | puts $file_handle "" |
---|
| 348 | puts $file_handle "// Xilinx / Standard library includes" |
---|
| 349 | puts $file_handle "\#include <xparameters.h>" |
---|
| 350 | puts $file_handle "" |
---|
| 351 | puts $file_handle "" |
---|
| 352 | puts $file_handle "/*************************** Constant Definitions ****************************/" |
---|
| 353 | puts $file_handle "" |
---|
| 354 | puts $file_handle "// Global Defines" |
---|
| 355 | puts $file_handle "\#define WARP_IP_UDP_BD_ALIGNMENT XAXIDMA_BD_MINIMUM_ALIGNMENT // Buffer Descriptor alignment" |
---|
| 356 | puts $file_handle "\#define WARP_IP_UDP_BUFFER_ALIGNMENT 0x40 // Buffer alignment (64 byte boundary)" |
---|
| 357 | puts $file_handle "" |
---|
| 358 | puts $file_handle "// Define global DMA constants" |
---|
| 359 | puts $file_handle "\#define WARP_IP_UDP_TXBD_CNT $num_tx_descriptors // Number of TX buffer descriptors (per instance)" |
---|
| 360 | puts $file_handle "" |
---|
| 361 | puts $file_handle "// Define UDP connections" |
---|
| 362 | puts $file_handle "\#define WARP_IP_UDP_NUM_SOCKETS $num_udp_sockets // Number of UDP sockets (global pool)" |
---|
| 363 | puts $file_handle "\#define WARP_IP_UDP_NUM_ARP_ENTRIES $num_arp_entries // Number of ARP entries (global pool)" |
---|
| 364 | puts $file_handle "" |
---|
| 365 | puts $file_handle "// Define global Ethernet constants" |
---|
| 366 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_BUF_SIZE ((%s + 31) & 0xFFFFFFE0) // Align parameter to a 32 byte boundary" $eth_buffer_size] |
---|
| 367 | puts $file_handle "\#define WARP_IP_UDP_ETH_NUM_SEND_BUF $num_tx_buffers // Number Ethernet transmit buffers (global pool)" |
---|
| 368 | puts $file_handle "\#define WARP_IP_UDP_ETH_RX_BUF_ALIGNMENT 4 // Alignment of packet within the RX buffer" |
---|
| 369 | puts $file_handle "\#define WARP_IP_UDP_ETH_TX_BUF_ALIGNMENT 0 // Alignment of packet within the TX buffer" |
---|
| 370 | puts $file_handle "" |
---|
| 371 | } |
---|
| 372 | |
---|
| 373 | proc print_config_h_file_body {file_handle inst_num inst_name inf_name num_rx_buffers eth_default_speed ignore} { |
---|
| 374 | |
---|
| 375 | puts $file_handle "" |
---|
| 376 | puts $file_handle "/************************* Ethernet $inst_num Definitions ****************************/" |
---|
| 377 | puts $file_handle "" |
---|
| 378 | puts $file_handle "// Ethernet device $inst_num" |
---|
| 379 | |
---|
| 380 | if { $ignore == 0 } { |
---|
| 381 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_MAC_DEVICE_ID XPAR_%s_DEVICE_ID // Internal name from xparameters.h" $inst_num $inst_name] |
---|
| 382 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_INF_DEVICE_ID XPAR_%s_DEVICE_ID // Internal name from xparameters.h" $inst_num $inf_name] |
---|
| 383 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_DEFAULT_SPEED %s" $inst_num $eth_default_speed] |
---|
| 384 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_NUM_RECV_BUF %s" $inst_num $num_rx_buffers] |
---|
| 385 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_RXBD_CNT WARP_IP_UDP_ETH_%s_NUM_RECV_BUF // Number of RX descriptors to use" $inst_num $inst_num] |
---|
| 386 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_TXBD_CNT WARP_IP_UDP_TXBD_CNT // Number of TX descriptors to use" $inst_num] |
---|
| 387 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_RXBD_SPACE_BYTES (XAxiDma_BdRingMemCalc(WARP_IP_UDP_BD_ALIGNMENT, WARP_IP_UDP_ETH_%s_RXBD_CNT))" $inst_num $inst_num] |
---|
| 388 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_TXBD_SPACE_BYTES (XAxiDma_BdRingMemCalc(WARP_IP_UDP_BD_ALIGNMENT, WARP_IP_UDP_ETH_%s_TXBD_CNT))" $inst_num $inst_num] |
---|
| 389 | puts $file_handle "" |
---|
| 390 | } else { |
---|
| 391 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_MAC_DEVICE_ID 0" $inst_num] |
---|
| 392 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_INF_DEVICE_ID 0" $inst_num] |
---|
| 393 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_DEFAULT_SPEED 1000" $inst_num] |
---|
| 394 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_NUM_RECV_BUF 0" $inst_num] |
---|
| 395 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_RXBD_CNT 0 // Number of RX descriptors to use" $inst_num] |
---|
| 396 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_TXBD_CNT 0 // Number of TX descriptors to use" $inst_num] |
---|
| 397 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_RXBD_SPACE_BYTES 0" $inst_num] |
---|
| 398 | puts $file_handle [format "\#define WARP_IP_UDP_ETH_%s_TXBD_SPACE_BYTES 0" $inst_num] |
---|
| 399 | puts $file_handle "" |
---|
| 400 | } |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | proc print_config_h_file_footer {file_handle} { |
---|
| 404 | puts $file_handle "" |
---|
| 405 | puts $file_handle "/*********************** Global Variable Definitions *************************/" |
---|
| 406 | puts $file_handle "" |
---|
| 407 | puts $file_handle "" |
---|
| 408 | puts $file_handle "" |
---|
| 409 | puts $file_handle "/*************************** Function Prototypes *****************************/" |
---|
| 410 | puts $file_handle "" |
---|
| 411 | puts $file_handle "// Initialization functions" |
---|
| 412 | puts $file_handle "void eth_init_device_info(u32 eth_dev_num);" |
---|
| 413 | puts $file_handle "" |
---|
| 414 | puts $file_handle "\#endif // WARP_IP_UDP_CONFIG_H_" |
---|
| 415 | puts $file_handle "" |
---|
| 416 | } |
---|
| 417 | |
---|
| 418 | |
---|
| 419 | |
---|
| 420 | ############################################################### |
---|
| 421 | # Methods to print the config file source |
---|
| 422 | # |
---|
| 423 | # @param Library Handle |
---|
| 424 | # |
---|
| 425 | # @return None |
---|
| 426 | # |
---|
| 427 | ############################################################### |
---|
| 428 | proc print_config_c_file_header {file_handle} { |
---|
| 429 | puts $file_handle "" |
---|
| 430 | puts $file_handle "// NOTE: Many data structures in the WARP IP/UDP Library must be accessible to DMAs" |
---|
| 431 | puts $file_handle "// and other system level masters. Therefore, we have put those variables in their" |
---|
| 432 | puts $file_handle "// own linker section, \".eth_data\", so that it is easy to put that section into an " |
---|
| 433 | puts $file_handle "// appropriate memory within the system." |
---|
| 434 | puts $file_handle "//" |
---|
| 435 | puts $file_handle "// This will require custom modification of the linker script since the Xilinx SDK" |
---|
| 436 | puts $file_handle "// can not detect these section headers ahead of time so that they can be placed as " |
---|
| 437 | puts $file_handle "// part of the GUI section placement." |
---|
| 438 | puts $file_handle "//" |
---|
| 439 | puts $file_handle "" |
---|
| 440 | puts $file_handle "" |
---|
| 441 | puts $file_handle "/***************************** Include Files *********************************/" |
---|
| 442 | puts $file_handle "" |
---|
| 443 | puts $file_handle "// Xilinx / Standard library includes" |
---|
| 444 | puts $file_handle "\#include <xparameters.h>" |
---|
| 445 | puts $file_handle "\#include <xstatus.h>" |
---|
| 446 | puts $file_handle "\#include <stdlib.h>" |
---|
| 447 | puts $file_handle "\#include <stdio.h>" |
---|
| 448 | puts $file_handle "" |
---|
| 449 | puts $file_handle "// Xilinx Hardware includes" |
---|
| 450 | puts $file_handle "\#include <xaxidma.h>" |
---|
| 451 | puts $file_handle "\#include <xaxiethernet.h>" |
---|
| 452 | puts $file_handle "" |
---|
| 453 | puts $file_handle "// WARP IP/UDP Library includes" |
---|
| 454 | puts $file_handle "\#include \"WARP_ip_udp.h\"" |
---|
| 455 | puts $file_handle "\#include \"WARP_ip_udp_internal.h\"" |
---|
| 456 | puts $file_handle "" |
---|
| 457 | } |
---|
| 458 | |
---|
| 459 | proc print_config_c_file_body {file_handle inst_num ignore} { |
---|
| 460 | puts $file_handle "" |
---|
| 461 | puts $file_handle "/************************* Ethernet $inst_num Definitions ****************************/" |
---|
| 462 | puts $file_handle "" |
---|
| 463 | puts $file_handle "// Variables for ETH $inst_num" |
---|
| 464 | |
---|
| 465 | if { $ignore == 0 } { |
---|
| 466 | puts $file_handle [format "XAxiEthernet ETH_%s_instance;" $inst_num] |
---|
| 467 | puts $file_handle [format "XAxiDma ETH_%s_dma_instance;" $inst_num] |
---|
| 468 | puts $file_handle "" |
---|
| 469 | puts $file_handle "// Aligned memory segments to be used for buffer descriptors" |
---|
| 470 | puts $file_handle "// NOTE: Memory for the buffer descriptors must be accessible by the DMA" |
---|
| 471 | puts $file_handle "//" |
---|
| 472 | puts $file_handle [format "u8 ETH_%s_rx_bd_space\[WARP_IP_UDP_ETH_%s_RXBD_SPACE_BYTES\] __attribute__ ((aligned(WARP_IP_UDP_BD_ALIGNMENT))) __attribute__ ((section (\".eth_data\")));" $inst_num $inst_num] |
---|
| 473 | puts $file_handle [format "u8 ETH_%s_tx_bd_space\[WARP_IP_UDP_ETH_%s_TXBD_SPACE_BYTES\] __attribute__ ((aligned(WARP_IP_UDP_BD_ALIGNMENT))) __attribute__ ((section (\".eth_data\")));" $inst_num $inst_num] |
---|
| 474 | puts $file_handle "" |
---|
| 475 | puts $file_handle "// Memory allocations for buffers" |
---|
| 476 | puts $file_handle "// NOTE: Memory for the buffer data must be accessible by the DMA" |
---|
| 477 | puts $file_handle "//" |
---|
| 478 | puts $file_handle [format "warp_ip_udp_buffer ETH_%s_recv_buffers\[WARP_IP_UDP_ETH_%s_NUM_RECV_BUF\];" $inst_num $inst_num] |
---|
| 479 | puts $file_handle [format "u32 ETH_%s_recv_buffer\[WARP_IP_UDP_ETH_%s_NUM_RECV_BUF * (WARP_IP_UDP_ETH_BUF_SIZE >> 2)\] __attribute__ ((aligned(WARP_IP_UDP_BUFFER_ALIGNMENT))) __attribute__ ((section (\".eth_data\")));" $inst_num $inst_num] |
---|
| 480 | puts $file_handle "" |
---|
| 481 | } else { |
---|
| 482 | puts $file_handle "// NONE - WARP IP/UDP library configured to ignore ETH $inst_num" |
---|
| 483 | puts $file_handle "" |
---|
| 484 | puts $file_handle "// Aligned memory segments to be used for buffer descriptors" |
---|
| 485 | puts $file_handle "//" |
---|
| 486 | puts $file_handle "// NONE - WARP IP/UDP library configured to ignore ETH $inst_num" |
---|
| 487 | puts $file_handle "" |
---|
| 488 | puts $file_handle "// Memory allocations for buffers" |
---|
| 489 | puts $file_handle "//" |
---|
| 490 | puts $file_handle "// NONE - WARP IP/UDP library configured to ignore ETH $inst_num" |
---|
| 491 | puts $file_handle "" |
---|
| 492 | } |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | proc print_config_c_file_footer {file_handle inf_type_list ignore_list} { |
---|
| 496 | set inst_num 0 |
---|
| 497 | |
---|
| 498 | puts $file_handle "" |
---|
| 499 | puts $file_handle "/*************************** Variable Definitions ****************************/" |
---|
| 500 | puts $file_handle "" |
---|
| 501 | puts $file_handle "// Ethernet device structure" |
---|
| 502 | puts $file_handle "ethernet_device eth_device\[WARP_IP_UDP_NUM_ETH_DEVICES\];" |
---|
| 503 | puts $file_handle "" |
---|
| 504 | puts $file_handle "" |
---|
| 505 | puts $file_handle "/******************************** Functions **********************************/" |
---|
| 506 | puts $file_handle "" |
---|
| 507 | puts $file_handle "/*****************************************************************************/" |
---|
| 508 | puts $file_handle "/**" |
---|
| 509 | puts $file_handle " * Initialize the information about the Ethernet device" |
---|
| 510 | puts $file_handle " *" |
---|
| 511 | puts $file_handle " * @param eth_dev_num - Ethernet device number" |
---|
| 512 | puts $file_handle " *" |
---|
| 513 | puts $file_handle " * @return None" |
---|
| 514 | puts $file_handle " *" |
---|
| 515 | puts $file_handle " ******************************************************************************/" |
---|
| 516 | puts $file_handle "" |
---|
| 517 | puts $file_handle "void eth_init_device_info(u32 eth_dev_num) \{" |
---|
| 518 | puts $file_handle "" |
---|
[5609] | 519 | puts $file_handle " int i;" |
---|
[4696] | 520 | puts $file_handle " u32 temp;" |
---|
| 521 | puts $file_handle "" |
---|
| 522 | puts $file_handle " // Initialize Ethernet device" |
---|
| 523 | puts $file_handle " switch (eth_dev_num) \{" |
---|
| 524 | |
---|
| 525 | foreach inf_type $inf_type_list { |
---|
| 526 | set ignore [lindex $ignore_list $inst_num] |
---|
| 527 | |
---|
| 528 | puts $file_handle [format " case WARP_IP_UDP_ETH_%s:" $inst_num] |
---|
| 529 | |
---|
| 530 | if { $ignore == 0 } { |
---|
| 531 | puts $file_handle " eth_device\[eth_dev_num\].initialized = 1;" |
---|
| 532 | } else { |
---|
| 533 | puts $file_handle " eth_device\[eth_dev_num\].initialized = 0;" |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | switch $inf_type { |
---|
| 537 | "axi_dma" { |
---|
| 538 | if { $ignore == 0 } { |
---|
| 539 | puts $file_handle [format " eth_device\[eth_dev_num\].eth_id = WARP_IP_UDP_ETH_%s_MAC_DEVICE_ID;" $inst_num] |
---|
| 540 | puts $file_handle [format " eth_device\[eth_dev_num\].eth_ptr = Ð_%s_instance;" $inst_num] |
---|
| 541 | puts $file_handle [format " eth_device\[eth_dev_num\].eth_cfg_ptr = (void *) XAxiEthernet_LookupConfig(WARP_IP_UDP_ETH_%s_MAC_DEVICE_ID);" $inst_num] |
---|
| 542 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_id = WARP_IP_UDP_ETH_%s_INF_DEVICE_ID;" $inst_num] |
---|
| 543 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_ptr = Ð_%s_dma_instance;" $inst_num] |
---|
| 544 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_cfg_ptr = (void *) XAxiDma_LookupConfig(WARP_IP_UDP_ETH_%s_INF_DEVICE_ID);" $inst_num] |
---|
| 545 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_rx_ring_ptr = (void *) XAxiDma_GetRxRing(Ð_%s_dma_instance);" $inst_num] |
---|
| 546 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_rx_bd_ptr = Ð_%s_rx_bd_space;" $inst_num] |
---|
| 547 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_rx_bd_cnt = WARP_IP_UDP_ETH_%s_RXBD_CNT;" $inst_num] |
---|
| 548 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_tx_ring_ptr = (void *) XAxiDma_GetTxRing(Ð_%s_dma_instance);" $inst_num] |
---|
| 549 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_tx_bd_ptr = Ð_%s_tx_bd_space;" $inst_num] |
---|
| 550 | puts $file_handle [format " eth_device\[eth_dev_num\].dma_tx_bd_cnt = WARP_IP_UDP_ETH_%s_TXBD_CNT;" $inst_num] |
---|
| 551 | puts $file_handle [format " eth_device\[eth_dev_num\].padding = 0;" $inst_num] |
---|
| 552 | puts $file_handle [format " eth_device\[eth_dev_num\].num_recv_buffers = WARP_IP_UDP_ETH_%s_NUM_RECV_BUF;" $inst_num] |
---|
| 553 | puts $file_handle [format " eth_device\[eth_dev_num\].recv_buffers = ETH_%s_recv_buffers;" $inst_num] |
---|
| 554 | |
---|
| 555 | } else { |
---|
| 556 | puts $file_handle " eth_device\[eth_dev_num\].eth_id = 0;" |
---|
| 557 | puts $file_handle " eth_device\[eth_dev_num\].eth_ptr = NULL;" |
---|
| 558 | puts $file_handle " eth_device\[eth_dev_num\].eth_cfg_ptr = NULL;" |
---|
| 559 | puts $file_handle " eth_device\[eth_dev_num\].dma_id = 0;" |
---|
| 560 | puts $file_handle " eth_device\[eth_dev_num\].dma_ptr = NULL;" |
---|
| 561 | puts $file_handle " eth_device\[eth_dev_num\].dma_cfg_ptr = NULL;" |
---|
| 562 | puts $file_handle " eth_device\[eth_dev_num\].dma_rx_ring_ptr = NULL;" |
---|
| 563 | puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_ptr = NULL;" |
---|
| 564 | puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_cnt = 0;" |
---|
| 565 | puts $file_handle " eth_device\[eth_dev_num\].dma_tx_ring_ptr = NULL;" |
---|
| 566 | puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_ptr = NULL;" |
---|
| 567 | puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_cnt = 0;" |
---|
| 568 | puts $file_handle " eth_device\[eth_dev_num\].padding = 0;" |
---|
| 569 | puts $file_handle " eth_device\[eth_dev_num\].num_recv_buffers = 0;" |
---|
| 570 | puts $file_handle " eth_device\[eth_dev_num\].recv_buffers = NULL;" |
---|
| 571 | } |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | "default" { |
---|
| 575 | error "Unable to handle AXI connections for target type $inf_type. Some common causes are |
---|
| 576 | 1. The AXI4 Stream interface of the AXI Ethernet is left unconnected. |
---|
| 577 | 2. The Ethernet instance is connected to an AXI FIFO. |
---|
| 578 | 3. A custom peripheral is connected to the AXI interface. The WARP UDP Transport has been designed for use with the AXI DMA peripheral only." "" "mdt_error" |
---|
| 579 | } |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | puts $file_handle "" |
---|
| 583 | puts $file_handle " bzero(eth_device\[eth_dev_num\].hw_addr, ETH_MAC_ADDR_LEN);" |
---|
| 584 | puts $file_handle " bzero(eth_device\[eth_dev_num\].ip_addr, IP_ADDR_LEN);" |
---|
| 585 | |
---|
| 586 | if { $ignore == 0 } { |
---|
| 587 | puts $file_handle "" |
---|
| 588 | puts $file_handle " // Initialize the buffers for the device" |
---|
| 589 | puts $file_handle " // NOTE: For the receive buffers, they are all being used by the library and cannot be allocated" |
---|
| 590 | puts $file_handle " //" |
---|
| 591 | puts $file_handle [format " for (i = 0; i < WARP_IP_UDP_ETH_%s_NUM_RECV_BUF; i++) \{" $inst_num] |
---|
[5609] | 592 | puts $file_handle [format " temp = (u32)(((u8*)(Ð_%s_recv_buffer) + (i * (WARP_IP_UDP_ETH_BUF_SIZE)) + WARP_IP_UDP_ETH_RX_BUF_ALIGNMENT));" $inst_num] |
---|
[4696] | 593 | puts $file_handle "" |
---|
[5609] | 594 | puts $file_handle " //xil_printf(\"temp_%d = 0x%08x, full buff size = %d, Ð_0_recv_buffer = 0x%08x\\n\", i, temp, sizeof(ETH_0_recv_buffer), Ð_0_recv_buffer);" |
---|
| 595 | puts $file_handle "" |
---|
[4696] | 596 | puts $file_handle [format " ETH_%s_recv_buffers\[i\].state = WARP_IP_UDP_BUFFER_IN_USE;" $inst_num] |
---|
| 597 | puts $file_handle [format " ETH_%s_recv_buffers\[i\].max_size = WARP_IP_UDP_ETH_BUF_SIZE;" $inst_num] |
---|
| 598 | puts $file_handle [format " ETH_%s_recv_buffers\[i\].size = 0;" $inst_num] |
---|
| 599 | puts $file_handle [format " ETH_%s_recv_buffers\[i\].data = (u8 *) temp;" $inst_num] |
---|
| 600 | puts $file_handle [format " ETH_%s_recv_buffers\[i\].offset = (u8 *) temp;" $inst_num] |
---|
| 601 | puts $file_handle [format " ETH_%s_recv_buffers\[i\].length = 0;" $inst_num] |
---|
| 602 | puts $file_handle [format " ETH_%s_recv_buffers\[i\].descriptor = NULL;" $inst_num] |
---|
| 603 | puts $file_handle " \}" |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | puts $file_handle " break;" |
---|
| 607 | puts $file_handle "" |
---|
| 608 | |
---|
| 609 | incr inst_num |
---|
| 610 | } |
---|
| 611 | |
---|
| 612 | puts $file_handle " default:" |
---|
| 613 | puts $file_handle " xil_printf(\" **** ERROR: Ethernet device %d not configured in hardware.\", (eth_dev_num + 1));" |
---|
| 614 | puts $file_handle " break;" |
---|
| 615 | puts $file_handle " \}" |
---|
| 616 | puts $file_handle "\}" |
---|
| 617 | puts $file_handle "" |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | |
---|
| 621 | |
---|
| 622 | ############################################################### |
---|
| 623 | # Methods to print the device file header |
---|
| 624 | # |
---|
| 625 | # @param Library Handle |
---|
| 626 | # |
---|
| 627 | # @return None |
---|
| 628 | # |
---|
| 629 | ############################################################### |
---|
| 630 | proc print_device_h_file_header {file_handle } { |
---|
| 631 | global num_ethernet_instances |
---|
| 632 | |
---|
| 633 | puts $file_handle "" |
---|
| 634 | puts $file_handle "\#ifndef WARP_IP_UDP_DEVICE_H_" |
---|
| 635 | puts $file_handle "\#define WARP_IP_UDP_DEVICE_H_" |
---|
| 636 | puts $file_handle "" |
---|
| 637 | puts $file_handle "" |
---|
| 638 | puts $file_handle "/***************************** Include Files *********************************/" |
---|
| 639 | puts $file_handle "" |
---|
| 640 | puts $file_handle "/*************************** Constant Definitions ****************************/" |
---|
| 641 | puts $file_handle "" |
---|
| 642 | puts $file_handle "// Global Defines" |
---|
| 643 | puts $file_handle "\#define WARP_IP_UDP_NUM_ETH_DEVICES $num_ethernet_instances" |
---|
| 644 | puts $file_handle "" |
---|
| 645 | } |
---|
| 646 | |
---|
| 647 | proc print_device_h_file_body {file_handle inst_num inst_name ignore} { |
---|
| 648 | |
---|
| 649 | puts $file_handle "" |
---|
| 650 | puts $file_handle "/************************* Ethernet $inst_num Definitions ****************************/" |
---|
| 651 | puts $file_handle "" |
---|
| 652 | puts $file_handle "// Ethernet device $inst_num" |
---|
| 653 | puts $file_handle "\#define WARP_IP_UDP_ETH_$inst_num $inst_num // Internal name of Ethernet device" |
---|
| 654 | puts $file_handle "\#define $inst_name WARP_IP_UDP_ETH_$inst_num // External name of Ethernet device" |
---|
| 655 | puts $file_handle "" |
---|
| 656 | } |
---|
| 657 | |
---|
| 658 | proc print_device_h_file_footer {file_handle} { |
---|
| 659 | puts $file_handle "" |
---|
| 660 | puts $file_handle "/*********************** Global Variable Definitions *************************/" |
---|
| 661 | puts $file_handle "" |
---|
| 662 | puts $file_handle "" |
---|
| 663 | puts $file_handle "/*************************** Function Prototypes *****************************/" |
---|
| 664 | puts $file_handle "" |
---|
| 665 | puts $file_handle "" |
---|
| 666 | puts $file_handle "\#endif // WARP_IP_UDP_DEVICE_H_" |
---|
| 667 | puts $file_handle "" |
---|
| 668 | } |
---|
| 669 | |
---|