############################################################### # Copyright (c) 2004 Xilinx, Inc. All Rights Reserved. # You may copy and modify these files for your own internal use solely with # Xilinx programmable logic devices and Xilinx EDK system or create IP # modules solely for Xilinx programmable logic devices and Xilinx EDK system. # No rights are granted to distribute any files unless they are distributed in # Xilinx programmable logic devices. # # $Id: xilnet_v2_1_0.tcl,v 1.2.8.6 2005/11/15 23:41:10 salindac Exp $ # ############################################################## #uses "xillib.tcl" # NOTE: # In order to use the WARPxilnet library, the Ethernet instances within the # design need to have either "ETH_A" or "ETH_B" somewhere in the instance # name. Due to some limitations with the Xilinx TCL generation capabilities # this script cannot pass instance names up to the MLD file to be displayed # as parameter names. Therefore, this driver has two parameters: # 1) ETH_A_uses_xilnet # 2) ETH_B_uses_xilnet # that are used to control if a given Ethernet instance is controlled by the # WARPxilnet library. If an instance is not controlled by this library, then # the library will not allocate buffers or control structures in order to # minimize code and data space of this library. # # This library will complain if: # 1) There are more than two Ethernet instances, but will complete and # allocate buffers and control structures for all instances # 2) If none of the Ethernet instances contain either "ETH_A" or "ETH_B". # In this case, the *_uses_xilnet parameters will be ignored and # buffers and control structures will be allocated for all instances # 3) If the *_uses_xilnet parameter is set to '1' and the corresponding # "ETH_*" doesn't exist, then the driver will error out, except in # the situation of case 2) above. # set ethernet_ninstances 0 set ethernet_use_axi 0 set ethernet_use_axi_dma 0 set ethernet_use_axi_fifo 0 set ethernet_use_temac 0 proc get_ethernet_periphs {mhs_handle} { global ethernet_ninstances global ethernet_use_axi global ethernet_use_temac set ipinst_list [xget_hw_ipinst_handle $mhs_handle "*"] set ethernet_ninstances 0 set ethernet_use_axi 0 set ethernet_use_temac 0 set ethernet_periphs_list {} foreach periph $ipinst_list { set periph_type [xget_hw_value $periph] set periph_name [xget_value $periph "name"] # puts "\# Peripheral: type = $periph_type name = $periph_name " if { $periph_type == "axi_ethernet" } { incr ethernet_use_axi incr ethernet_ninstances # puts "\# Putting ($periph_name $periph) into list: $ethernet_periphs_list " if { [regexp -nocase {eth_a} $periph_name] } { if { [llength $ethernet_periphs_list] > 0 } { set ethernet_periphs_list [linsert $ethernet_periphs_list 0 $periph] } else { lappend ethernet_periphs_list $periph } } else { if { [regexp -nocase {eth_b} $periph_name] } { lappend ethernet_periphs_list $periph } else { lappend ethernet_periphs_list $periph } } # puts "\# Ethernet $ethernet_ninstances: type = $periph_type name = $periph_name " } if { $periph_type == "xps_ll_temac" || $periph_type == "opb_ethernetlite" || $periph_type == "xps_ethernetlite" } { incr ethernet_use_temac incr ethernet_ninstances lappend ethernet_periphs_list $periph # puts "\# Ethernet $ethernet_ninstances: type = $periph_type name = $periph_name " } } # puts "\# Final List ($ethernet_ninstances elements): $ethernet_periphs_list " # foreach eth_inst $ethernet_periphs_list { # set periph_name [xget_value $eth_inst "name"] # # puts "\# Ethernet name = $periph_name " # } return $ethernet_periphs_list } proc get_ethernet_interface_periph {mhs_handle inst_handle} { set p2p_busifs_i [xget_hw_busifs_by_subproperty $inst_handle "BUS_TYPE" "INITIATOR"] # Add p2p periphs foreach p2p_busif $p2p_busifs_i { set bus_name [string toupper [xget_hw_value $p2p_busif]] set conn_busif_handle [xget_hw_connected_busifs_handle $mhs_handle $bus_name "TARGET"] if { [string compare -nocase $conn_busif_handle ""] == 0} { continue } else { # if there is a single match, we know if it is FIFO or DMA # no need for further iterations set conn_busif_name [xget_hw_name $conn_busif_handle] set target_periph [xget_hw_parent_handle $conn_busif_handle] set target_type [xget_hw_value $target_periph] set target_name [string toupper [xget_hw_name $target_periph]] # puts "\# Bus Name = $bus_name Type = $conn_busif_name" # puts "\# Target Name = $target_name Type = $target_type" return $target_periph } } return } proc get_periph_instances {mhs_handle inst_type} { set ipinst_list [xget_hw_ipinst_handle $mhs_handle "*"] set periphs_list {} foreach periph $ipinst_list { set periph_type [xget_hw_value $periph] set periph_name [xget_value $periph "name"] if { $periph_type == $inst_type } { lappend periphs_list $periph # puts "\# Instance: type = $periph_type name = $periph_name " } } return $periphs_list } proc net_drc {lib_handle} { puts "XilNet DRC ..." } proc net_open_file {filename desc} { set config_inc [open $filename w] xprint_generated_header $config_inc $desc return $config_inc } proc net_open_include_file {file_name} { set filename [file join "./src/" $file_name] return [net_open_file $filename "WARP/XilNet Configuration Parameters"] } proc net_open_config_file {file_name} { set filename [file join "./src/" $file_name] return [net_open_file $filename "WARP/XilNet MAC Configuration File"] } proc generate {lib_handle} { global ethernet_ninstances global ethernet_use_axi global ethernet_use_axi_dma global ethernet_use_axi_fifo set ethernet_use_axi_dma 0 set ethernet_use_axi_fifo 0 set sw_proc_handle [xget_processor] set hw_proc_handle [xget_handle $sw_proc_handle "IPINST"] set mhs_handle [xget_hw_parent_handle $hw_proc_handle] set emac_inst_list [get_ethernet_periphs $mhs_handle] # Error checking if {$ethernet_ninstances == 0} { error "Invalid configuration: 0 Ethernet instances found." "" "mdt_error" return } # Initialize variables for loop set eth_inst_num 0 set h_file [net_open_include_file "xilnet_config.h"] set c_file [net_open_config_file "xilnet_config.c"] set eth_a_uses_drvr [xget_value $lib_handle "PARAMETER" "ETH_A_uses_xilnet"] set eth_b_uses_drvr [xget_value $lib_handle "PARAMETER" "ETH_B_uses_xilnet"] set fifo_buf_size [xget_value $lib_handle "PARAMETER" "fifo_buf_size"] set dma_buf_size [xget_value $lib_handle "PARAMETER" "dma_buf_size"] set dma_rcvd_buf_cnt [xget_value $lib_handle "PARAMETER" "dma_rcvd_buf_cnt"] set udp_conns [xget_value $lib_handle "PARAMETER" "no_of_tcp_conns"] set inf_type_list {} set ignore_list {} # puts "\# --------------------------------------" # puts "\# Num Ethernet instances = $ethernet_ninstances " # Check Ethernet instances and instance names # 1) There are more than two Ethernet instances, but will complete and # allocate buffers and control structures for all instances # 2) If none of the Ethernet instances contain either "ETH_A" or "ETH_B". # In this case, the *_uses_xilnet parameters will be ignored and # buffers and control structures will be allocated for all instances # 3) If the *_uses_xilnet parameter is set to '1' and the corresponding # "ETH_*" doesn't exist, then the driver will error out, except in # the situation of case 2) above. # if {$ethernet_ninstances > 2} { puts "\# --------------------------------------" puts "\# WARPxilnet WARNING:" puts "\# More than 2 Ethernet instances." puts "\# Ignoring ETH_*_uses_xilnet parameters." puts "\# --------------------------------------" } else { set eth_name_matches 0 set eth_a_exists 0 set eth_b_exists 0 foreach inst $emac_inst_list { set inst_name [string toupper [xget_hw_name $inst]] if { [regexp -nocase {eth_a} $inst_name] } { incr eth_name_matches incr eth_a_exists } if { [regexp -nocase {eth_b} $inst_name] } { incr eth_name_matches incr eth_b_exists } } if { $eth_name_matches == 0 } { puts "\# --------------------------------------" puts "\# WARPxilnet WARNING:" puts "\# No Ethernet instances contain either \"ETH_A\" or \"ETH_B\"." puts "\# Ignoring ETH_*_uses_xilnet parameters." puts "\# --------------------------------------" } else { if { $eth_a_uses_drvr == 1 && $eth_a_exists == 0 } { error "Invalid configuration: ETH_A does not exist but required by library." "" "mdt_error" return } if { $eth_b_uses_drvr == 1 && $eth_b_exists == 0 } { error "Invalid configuration: ETH_B does not exist but required by library." "" "mdt_error" return } } } # For code size reasons, we need to determine if we need to use the AXI FIFO or the AXI DMA # based on the interface type. If we are not using AXI, then we can ignore this check. # if { $ethernet_use_axi != 0 } { foreach inst $emac_inst_list { set inst_type [xget_hw_value $inst] set inst_name [string toupper [xget_hw_name $inst]] set ignore 0 # Check if we should ignore this Ethernet instance # NOTE: This implementation relies on the fact that all the checks above passed # if { [regexp -nocase {eth_a} $inst_name] && $eth_a_uses_drvr == 0 } { incr ignore } if { [regexp -nocase {eth_b} $inst_name] && $eth_b_uses_drvr == 0 } { incr ignore } # If we are not ignoring this interface, then increment the global variables # if { $ignore == 0 } { # Determine the interface attached to the axi_ethernet set inf_inst [get_ethernet_interface_periph $mhs_handle $inst] if { [llength $inf_inst] != 0 } { set inf_inst_type [xget_hw_value $inf_inst] switch $inf_inst_type { "axi_fifo_mm_s" { incr ethernet_use_axi_fifo } "axi_dma" { incr ethernet_use_axi_dma } } } } } } # Process the instances and print the config header and c files print_h_file_header $h_file $udp_conns print_c_file_header $c_file foreach inst $emac_inst_list { set inst_type [xget_hw_value $inst] set inst_name [string toupper [xget_hw_name $inst]] set ignore 0 # Check if we should ignore this Ethernet instance # NOTE: This implementation relies on the fact that all the checks above passed # if { [regexp -nocase {eth_a} $inst_name] && $eth_a_uses_drvr == 0 } { incr ignore } if { [regexp -nocase {eth_b} $inst_name] && $eth_b_uses_drvr == 0 } { incr ignore } # puts "\# Name = $inst_name " # puts "\# Type = $inst_type " # puts "\# Ignore = $ignore " # Print out header file delimiter puts $h_file "" puts $h_file "/************************* Ethernet $eth_inst_num Definitions ****************************/" puts $h_file "" # Print out c file delimiter puts $c_file "" puts $c_file "/************************* Ethernet $eth_inst_num Definitions ****************************/" puts $c_file "" if { [string compare -nocase $inst_type "opb_ethernetlite"] == 0 || [string compare -nocase $inst_type "xps_ethernetlite"] == 0} { error "TBD: ethernetlite not yet supported. Please change HW design for $inst_name." "" "mdt_error" return } elseif { [string compare -nocase $inst_type "xps_ll_temac"] == 0} { # Determine the interface attached to the temac set inf_inst [get_ethernet_interface_periph $mhs_handle $inst] if { [llength $inf_inst] != 0 } { set inf_inst_type [xget_hw_value $inf_inst] set inf_inst_name [string toupper [xget_hw_name $inf_inst]] } else { error "Unable to find interface for $inst_name. Some common causes are 1. The interface of the TEMAC is left unconnected. 2. A custom peripheral is connected to the interface. The WARP Xilnet has been designed for use with the LL FIFO peripheral only." "" "mdt_error" } set inf_dma_inst [get_periph_instances $mhs_handle "xps_central_dma"] if { [llength $inf_dma_inst] != 0 } { set inf_dma_inst_type [xget_hw_value $inf_dma_inst] set inf_dma_inst_name [string toupper [xget_hw_name $inf_dma_inst]] print_h_file_temac $h_file $eth_inst_num $inst_name $inf_inst_name $inf_dma_inst_name $dma_rcvd_buf_cnt $fifo_buf_size $ignore print_c_file_temac $c_file $eth_inst_num $ignore } else { error "Unable to find the central dma interface for $inst_name. Some common causes are 1. A custom peripheral is used for dma to the temac. The WARP Xilnet has been designed for use with the CENTRAL DMA peripherals only." "" "mdt_error" } # Append one entry for TEMAC lappend inf_type_list $inst_type lappend ignore_list $ignore } elseif { [string compare -nocase $inst_type "axi_ethernet"] == 0} { # Determine the interface attached to the axi_ethernet set inf_inst [get_ethernet_interface_periph $mhs_handle $inst] if { [llength $inf_inst] != 0 } { set inf_inst_type [xget_hw_value $inf_inst] set inf_inst_name [string toupper [xget_hw_name $inf_inst]] lappend inf_type_list $inf_inst_type lappend ignore_list $ignore switch $inf_inst_type { "axi_fifo_mm_s" { print_h_file_fifo $h_file $eth_inst_num $inst_name $inf_inst_name $dma_rcvd_buf_cnt $fifo_buf_size $ignore print_c_file_fifo $c_file $eth_inst_num $ignore } "axi_dma" { print_h_file_dma $h_file $eth_inst_num $inst_name $inf_inst_name $dma_rcvd_buf_cnt $dma_buf_size $ignore print_c_file_dma $c_file $eth_inst_num $ignore } "default" { error "Unable to handle AXI connections for target type $target_periph_type. Some common causes are 1. The AXI4 Stream interface of the AXI Ethernet is left unconnected. 2. A custom peripheral is connected to the AXI interface. The WARP Xilnet has been designed for use with the AXI Streaming FIFO, and AXI DMA peripherals only." "" "mdt_error" } } } else { if { [regexp -nocase {eth_a} $inst_name] && $eth_a_uses_drvr == 0 || [regexp -nocase {eth_b} $inst_name] && $eth_b_uses_drvr == 0 } { print_h_file_fifo $h_file $eth_inst_num $inst_name "error" $dma_rcvd_buf_cnt $fifo_buf_size $ignore print_c_file_fifo $c_file $eth_inst_num $ignore } else { error "Unable to find AXI interface for $inst_name. Some common causes are 1. The AXI4 Stream interface of the AXI Ethernet is left unconnected. 2. A custom peripheral is connected to the AXI interface. The WARP Xilnet has been designed for use with the AXI Streaming FIFO, and AXI DMA peripherals only." "" "mdt_error" } } } else { error "$inst_name is not a TEMAC or ETHERNETLITE or AXI ETHERNET core. WARPXilNet can work only with such cores." "" "mdt_error" } # increment the instance number for the next iteration of the for loop incr eth_inst_num } print_h_file_footer $h_file print_c_file_footer $c_file $inf_type_list $ignore_list close $h_file close $c_file } proc print_h_file_header {file_handle udp_conns} { global ethernet_ninstances global ethernet_use_axi global ethernet_use_axi_dma global ethernet_use_axi_fifo global ethernet_use_temac # puts "\# USE DMA = $ethernet_use_axi_dma" # puts "\# USE FIFO = $ethernet_use_axi_fifo" # Check that if we only have an AXI interface, that we are either using # the DMA or the FIFO. Otherwise, xilnet should be removed to save code # space. if { $ethernet_use_axi != 0 && $ethernet_use_temac == 0 } { if { $ethernet_use_axi_fifo == 0 && $ethernet_use_axi_dma == 0 } { puts "\# --------------------------------------" puts "\# WARPxilnet WARNING:" puts "\# For a design only containing AXI Ethernet peripherals," puts "\# not using either the AXI DMA or AXI FIFO interfaces." puts "\# To save code space, please remove WARPxilnet library." puts "\# --------------------------------------" } } puts $file_handle "\#ifndef _XILNET_CONFIG_H" puts $file_handle "\#define _XILNET_CONFIG_H" puts $file_handle "" puts $file_handle "\#ifdef __cplusplus" puts $file_handle "extern \"C\" \{" puts $file_handle "\#endif" puts $file_handle "" # Uncomment the next line and clean the project to enable debug output on the UART # # puts $file_handle "\#define _DEBUG_" # Uncomment the next line and clean the project to enable performance monitoring on oscilloscope: # - Ethernet receive toggles GPIO 1 (see xilnet_eth.c) # - Ethernet transmit toggles GPIO 2 (see xilnet_eth.c) # # puts $file_handle "\#define _PERFORMANCE_MONITOR_" puts $file_handle "" puts $file_handle "/***************************** Include Files *********************************/" puts $file_handle "\#include " puts $file_handle "\#include " puts $file_handle "\#include " puts $file_handle "" # Determine HW includes # if { $ethernet_use_axi_dma != 0 } { puts $file_handle "\#include " } if { $ethernet_use_axi_fifo != 0 } { puts $file_handle "\#include " } if { $ethernet_use_temac != 0 } { puts $file_handle "\#include " puts $file_handle "\#include " puts $file_handle "\#include " puts $file_handle "\#include " } puts $file_handle "" puts $file_handle "/*************************** Constant Definitions ****************************/" puts $file_handle "" puts $file_handle "// Xilnet Global Defines" puts $file_handle "\#define XILNET_NUM_ETH_DEVICES $ethernet_ninstances // Define the number of Ethernet devices" if { $ethernet_use_axi_dma != 0 } { puts $file_handle "\#define XILNET_BD_ALIGNMENT XAXIDMA_BD_MINIMUM_ALIGNMENT // Buffer Descriptor alignment" } puts $file_handle "" puts $file_handle "// Define UDP connections" puts $file_handle "\#define XILNET_MAX_UDP_CONNS $udp_conns // maximum no of open udp conns" puts $file_handle "\#define NO_OF_XILSOCKS XILNET_MAX_UDP_CONNS // Number of sockets per Ethernet Device" puts $file_handle "" puts $file_handle "// Define Ethernet interface types" puts $file_handle "\#define XILNET_AXI_DMA_INF 1" puts $file_handle "\#define XILNET_AXI_FIFO_INF 2" puts $file_handle "\#define XILNET_TEMAC_INF 3" puts $file_handle "" puts $file_handle "// Define which interfaces are used" # Set defines for code inclusion in the WARPxilnet library # if { $ethernet_use_axi_dma != 0 } { puts $file_handle "\#define XILNET_AXI_DMA_INF_USED" } if { $ethernet_use_axi_fifo != 0 } { puts $file_handle "\#define XILNET_AXI_FIFO_INF_USED" } if { $ethernet_use_temac != 0 } { puts $file_handle "\#define XILNET_TEMAC_INF_USED" } puts $file_handle "" } proc print_h_file_fifo {file_handle inst_num inst_name inf_name num_rcv_buf buf_size ignore} { puts $file_handle "// Ethernet device $inst_num" puts $file_handle "\#define $inst_name XILNET_ETH_$inst_num // External name of Ethernet device" puts $file_handle "\#define XILNET_ETH_$inst_num $inst_num // Internal name of Ethernet device" puts $file_handle "" # Only one receive buffer supported for FIFO mode if { $ignore == 0 } { puts $file_handle [format "\#define XILNET_ETH_%s_INF_DEVICE_ID XPAR_%s_DEVICE_ID" $inst_num $inf_name] puts $file_handle [format "\#define XILNET_ETH_%s_NUM_RECV_BUF 1" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_BUF_SIZE %s" $inst_num $buf_size] puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle [format "extern XLlFifo ETH_%s_FIFO_Instance;" $inst_num] puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle [format "extern unsigned int recvBuffer_eth_%s\[XILNET_ETH_%s_NUM_RECV_BUF*((XILNET_ETH_%s_BUF_SIZE+3)/4)\];" $inst_num $inst_num $inst_num] puts $file_handle [format "extern unsigned int sendBuffer_eth_%s\[(XILNET_ETH_%s_BUF_SIZE+3)/4\];" $inst_num $inst_num] puts $file_handle "" } else { puts $file_handle [format "\#define XILNET_ETH_%s_INF_DEVICE_ID 0" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_NUM_RECV_BUF 0" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_BUF_SIZE 0" $inst_num $buf_size] puts $file_handle "" } } proc print_h_file_dma {file_handle inst_num inst_name inf_name num_rcv_buf buf_size ignore} { puts $file_handle "// Ethernet device $inst_num" puts $file_handle "\#define $inst_name XILNET_ETH_$inst_num // External name of Ethernet device" puts $file_handle "\#define XILNET_ETH_$inst_num $inst_num // Internal name of Ethernet device" puts $file_handle "" if { $ignore == 0 } { puts $file_handle [format "\#define XILNET_ETH_%s_INF_DEVICE_ID XPAR_%s_DEVICE_ID" $inst_num $inf_name] puts $file_handle [format "\#define XILNET_ETH_%s_NUM_RECV_BUF %s" $inst_num $num_rcv_buf] puts $file_handle [format "\#define XILNET_ETH_%s_BUF_SIZE %s" $inst_num $buf_size] # NOTE: For both Send and Receive, the number of buffer descriptors should equal the number of buffers puts $file_handle [format "\#define XILNET_ETH_%s_RXBD_CNT XILNET_ETH_%s_NUM_RECV_BUF // Number of RxBDs to use" $inst_num $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_TXBD_CNT 1 // Number of TxBDs to use" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_RXBD_SPACE_BYTES (XAxiDma_BdRingMemCalc(XILNET_BD_ALIGNMENT, XILNET_ETH_%s_RXBD_CNT))" $inst_num $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_TXBD_SPACE_BYTES (XAxiDma_BdRingMemCalc(XILNET_BD_ALIGNMENT, XILNET_ETH_%s_TXBD_CNT))" $inst_num $inst_num] puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle [format "extern XAxiDma ETH_%s_DMA_Instance;" $inst_num] puts $file_handle "" puts $file_handle "// Aligned memory segments to be used for buffer descriptors" puts $file_handle [format "extern char ETH_%s_RX_BD_space\[XILNET_ETH_%s_RXBD_SPACE_BYTES\] __attribute__ ((aligned(XILNET_BD_ALIGNMENT)));" $inst_num $inst_num] puts $file_handle [format "extern char ETH_%s_TX_BD_space\[XILNET_ETH_%s_TXBD_SPACE_BYTES\] __attribute__ ((aligned(XILNET_BD_ALIGNMENT)));" $inst_num $inst_num] puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle [format "extern unsigned int recvBuffer_eth_%s\[XILNET_ETH_%s_NUM_RECV_BUF*((XILNET_ETH_%s_BUF_SIZE+3)/4)\];" $inst_num $inst_num $inst_num] puts $file_handle [format "extern unsigned int sendBuffer_eth_%s\[(XILNET_ETH_%s_BUF_SIZE+3)/4\];" $inst_num $inst_num] puts $file_handle "" } else { puts $file_handle [format "\#define XILNET_ETH_%s_INF_DEVICE_ID 0" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_NUM_RECV_BUF 0" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_BUF_SIZE 0" $inst_num] # NOTE: For both Send and Receive, the number of buffer descriptors should equal the number of buffers puts $file_handle [format "\#define XILNET_ETH_%s_RXBD_CNT 0 // Number of RxBDs to use" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_TXBD_CNT 0 // Number of TxBDs to use" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_RXBD_SPACE_BYTES 0" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_TXBD_SPACE_BYTES 0" $inst_num] puts $file_handle "" } } proc print_h_file_temac {file_handle inst_num inst_name inf_name inf_dma_name num_rcv_buf buf_size ignore} { puts $file_handle "// Ethernet device $inst_num" puts $file_handle "\#define $inst_name XILNET_ETH_$inst_num // External name of Ethernet device" puts $file_handle "\#define XILNET_ETH_$inst_num $inst_num // Internal name of Ethernet device" puts $file_handle "" puts $file_handle [format "\#define XILNET_ETH_%s_INF_DEVICE_ID XPAR_%s_DEVICE_ID" $inst_num $inf_name] puts $file_handle [format "\#define XILNET_ETH_%s_INF_DMA_DEVICE_ID XPAR_%s_DEVICE_ID" $inst_num $inf_dma_name] # Only one receive buffer supported for FIFO mode if { $ignore == 0 } { puts $file_handle [format "\#define XILNET_ETH_%s_NUM_RECV_BUF 1" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_BUF_SIZE %s" $inst_num $buf_size] puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle [format "extern XLlFifo ETH_%s_FIFO_Instance;" $inst_num] puts $file_handle [format "extern XDmaCentral ETH_%s_DMA_Instance;" $inst_num] puts $file_handle [format "extern XDmaCentral_Config *ETH_%s_DMA_CFG_ptr;" $inst_num] puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle [format "extern unsigned int recvBuffer_eth_%s\[XILNET_ETH_%s_NUM_RECV_BUF*((XILNET_ETH_%s_BUF_SIZE+3)/4)\];" $inst_num $inst_num $inst_num] puts $file_handle [format "extern unsigned int sendBuffer_eth_%s\[(XILNET_ETH_%s_BUF_SIZE+3)/4\];" $inst_num $inst_num] puts $file_handle "" } else { puts $file_handle [format "\#define XILNET_ETH_%s_NUM_RECV_BUF 0" $inst_num] puts $file_handle [format "\#define XILNET_ETH_%s_BUF_SIZE 0" $inst_num] puts $file_handle "" } } proc print_h_file_footer {file_handle} { puts $file_handle "" puts $file_handle "/*********************** Global Variable Definitions *************************/" puts $file_handle "" puts $file_handle "// Ethernet Device Structure" puts $file_handle "extern xilnet_eth_device eth_device\[XILNET_NUM_ETH_DEVICES\];" puts $file_handle "" puts $file_handle "/*************************** Function Prototypes *****************************/" puts $file_handle "" puts $file_handle "void xilnet_init_eth_device_struct(unsigned int);" puts $file_handle "" puts $file_handle "\#endif" puts $file_handle "" puts $file_handle "/*****************************************************************************/" puts $file_handle "" } proc print_c_file_header {file_handle} { global ethernet_ninstances puts $file_handle "" puts $file_handle "/***************************** Include Files *********************************/" puts $file_handle "" puts $file_handle "\#include " puts $file_handle "\#include " puts $file_handle "" } proc print_c_file_fifo {file_handle inst_num ignore} { if { $ignore == 0 } { puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle [format "XLlFifo ETH_%s_FIFO_Instance;" $inst_num] puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle [format "unsigned int recvBuffer_eth_%s\[XILNET_ETH_%s_NUM_RECV_BUF*((XILNET_ETH_%s_BUF_SIZE+3)/4)\];" $inst_num $inst_num $inst_num] puts $file_handle [format "unsigned int sendBuffer_eth_%s\[(XILNET_ETH_%s_BUF_SIZE+3)/4\];" $inst_num $inst_num] puts $file_handle [format "struct xilsock_socket xilsock_sockets_eth_%s\[NO_OF_XILSOCKS\];" $inst_num] puts $file_handle [format "struct xilnet_udp_conn xilnet_udp_conns_eth_%s\[XILNET_MAX_UDP_CONNS\];" $inst_num] puts $file_handle "" } else { puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle "// NONE - WARPxilnet library configured to ignore ETH $inst_num" puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle "// NONE - WARPxilnet library configured to ignore ETH $inst_num" puts $file_handle "" } } proc print_c_file_dma {file_handle inst_num ignore} { if { $ignore == 0 } { puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle [format "XAxiDma ETH_%s_DMA_Instance;" $inst_num] puts $file_handle "" puts $file_handle "// Aligned memory segments to be used for buffer descriptors" puts $file_handle [format "char ETH_%s_RX_BD_space\[XILNET_ETH_%s_RXBD_SPACE_BYTES\] __attribute__ ((aligned(XILNET_BD_ALIGNMENT)));" $inst_num $inst_num] puts $file_handle [format "char ETH_%s_TX_BD_space\[XILNET_ETH_%s_TXBD_SPACE_BYTES\] __attribute__ ((aligned(XILNET_BD_ALIGNMENT)));" $inst_num $inst_num] puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle [format "unsigned int recvBuffer_eth_%s\[XILNET_ETH_%s_NUM_RECV_BUF*((XILNET_ETH_%s_BUF_SIZE+3)/4)\];" $inst_num $inst_num $inst_num] puts $file_handle [format "unsigned int sendBuffer_eth_%s\[(XILNET_ETH_%s_BUF_SIZE+3)/4\];" $inst_num $inst_num] puts $file_handle [format "struct xilsock_socket xilsock_sockets_eth_%s\[NO_OF_XILSOCKS\];" $inst_num] puts $file_handle [format "struct xilnet_udp_conn xilnet_udp_conns_eth_%s\[XILNET_MAX_UDP_CONNS\];" $inst_num] puts $file_handle "" } else { puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle "// NONE - WARPxilnet library configured to ignore ETH $inst_num" puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle "// NONE - WARPxilnet library configured to ignore ETH $inst_num" puts $file_handle "" } } proc print_c_file_temac {file_handle inst_num ignore} { if { $ignore == 0 } { puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle [format "XLlFifo ETH_%s_FIFO_Instance;" $inst_num] puts $file_handle [format "XDmaCentral ETH_%s_DMA_Instance;" $inst_num] puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle [format "unsigned int recvBuffer_eth_%s\[XILNET_ETH_%s_NUM_RECV_BUF*((XILNET_ETH_%s_BUF_SIZE+3)/4)\];" $inst_num $inst_num $inst_num] puts $file_handle [format "unsigned int sendBuffer_eth_%s\[(XILNET_ETH_%s_BUF_SIZE+3)/4\];" $inst_num $inst_num] puts $file_handle [format "struct xilsock_socket xilsock_sockets_eth_%s\[NO_OF_XILSOCKS\];" $inst_num] puts $file_handle [format "struct xilnet_udp_conn xilnet_udp_conns_eth_%s\[XILNET_MAX_UDP_CONNS\];" $inst_num] puts $file_handle "" } else { puts $file_handle "" puts $file_handle "// Variables for ETH $inst_num" puts $file_handle "// NONE - WARPxilnet library configured to ignore ETH $inst_num" puts $file_handle "" puts $file_handle "// Buffers for ETH $inst_num" puts $file_handle "// NONE - WARPxilnet library configured to ignore ETH $inst_num" puts $file_handle "" } } proc print_c_file_footer {file_handle inf_type_list ignore_list} { set inst_num 0 puts $file_handle "" puts $file_handle "/*************************** Ethernet Variables ******************************/" puts $file_handle "" puts $file_handle "" puts $file_handle "// Ethernet Device Structure" puts $file_handle "xilnet_eth_device eth_device\[XILNET_NUM_ETH_DEVICES\];" puts $file_handle "" puts $file_handle "" puts $file_handle "void xilnet_init_eth_device_struct(unsigned int eth_dev_num) \{" puts $file_handle "" puts $file_handle " switch( eth_dev_num ) \{" foreach inf_type $inf_type_list { set ignore [lindex $ignore_list $inst_num] puts $file_handle [format " case XILNET_ETH_%s:" $inst_num] if { $ignore == 0 } { puts $file_handle " eth_device\[eth_dev_num\].uses_driver = 1;" } else { puts $file_handle " eth_device\[eth_dev_num\].uses_driver = 0;" } switch $inf_type { "axi_fifo_mm_s" { puts $file_handle " eth_device\[eth_dev_num\].inf_type = XILNET_AXI_FIFO_INF;" puts $file_handle [format " eth_device\[eth_dev_num\].inf_id = XILNET_ETH_%s_INF_DEVICE_ID;" $inst_num] if { $ignore == 0 } { puts $file_handle [format " eth_device\[eth_dev_num\].inf_ref = Ð_%s_FIFO_Instance;" $inst_num] } else { puts $file_handle " eth_device\[eth_dev_num\].inf_ref = 0;" } puts $file_handle " eth_device\[eth_dev_num\].inf_cfg_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_id = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_cfg_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_ring_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_ring_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_cnt = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_cnt = 0;" } "axi_dma" { puts $file_handle " eth_device\[eth_dev_num\].inf_type = XILNET_AXI_DMA_INF;" puts $file_handle [format " eth_device\[eth_dev_num\].inf_id = XILNET_ETH_%s_INF_DEVICE_ID;" $inst_num] if { $ignore == 0 } { puts $file_handle [format " eth_device\[eth_dev_num\].inf_ref = Ð_%s_DMA_Instance;" $inst_num] } else { puts $file_handle " eth_device\[eth_dev_num\].inf_ref = 0;" } puts $file_handle " eth_device\[eth_dev_num\].inf_cfg_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_id = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_cfg_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_ring_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_ring_ref = 0;" if { $ignore == 0 } { puts $file_handle [format " eth_device\[eth_dev_num\].dma_rx_bd_ref = Ð_%s_RX_BD_space;" $inst_num] puts $file_handle [format " eth_device\[eth_dev_num\].dma_tx_bd_ref = Ð_%s_TX_BD_space;" $inst_num] } else { puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_ref = 0;" } puts $file_handle [format " eth_device\[eth_dev_num\].dma_rx_bd_cnt = XILNET_ETH_%s_RXBD_CNT;" $inst_num] puts $file_handle [format " eth_device\[eth_dev_num\].dma_tx_bd_cnt = XILNET_ETH_%s_TXBD_CNT;" $inst_num] } "xps_ll_temac" { puts $file_handle " eth_device\[eth_dev_num\].inf_type = XILNET_TEMAC_INF;" puts $file_handle [format " eth_device\[eth_dev_num\].inf_id = XILNET_ETH_%s_INF_DEVICE_ID;" $inst_num] if { $ignore == 0 } { puts $file_handle [format " eth_device\[eth_dev_num\].inf_ref = Ð_%s_FIFO_Instance;" $inst_num] } else { puts $file_handle " eth_device\[eth_dev_num\].inf_ref = 0;" } puts $file_handle " eth_device\[eth_dev_num\].inf_cfg_ref = 0;" puts $file_handle [format " eth_device\[eth_dev_num\].inf_dma_id = XILNET_ETH_%s_INF_DMA_DEVICE_ID;" $inst_num] if { $ignore == 0 } { puts $file_handle [format " eth_device\[eth_dev_num\].inf_dma_ref = Ð_%s_DMA_Instance;" $inst_num] } else { puts $file_handle " eth_device\[eth_dev_num\].inf_dma_ref = 0;" } puts $file_handle " eth_device\[eth_dev_num\].inf_dma_cfg_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_ring_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_ring_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_cnt = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_cnt = 0;" } "default" { puts $file_handle " eth_device\[eth_dev_num\].inf_type = XILNET_AXI_FIFO_INF;" puts $file_handle [format " eth_device\[eth_dev_num\].inf_id = XILNET_ETH_%s_INF_DEVICE_ID;" $inst_num] if { $ignore == 0 } { puts $file_handle [format " eth_device\[eth_dev_num\].inf_ref = Ð_%s_FIFO_Instance;" $inst_num] } else { puts $file_handle " eth_device\[eth_dev_num\].inf_ref = 0;" } puts $file_handle " eth_device\[eth_dev_num\].inf_cfg_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_id = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].inf_dma_cfg_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_ring_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_ring_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_ref = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_rx_bd_cnt = 0;" puts $file_handle " eth_device\[eth_dev_num\].dma_tx_bd_cnt = 0;" } } puts $file_handle " eth_device\[eth_dev_num\].xilsock_status_flag = 0;" puts $file_handle " eth_device\[eth_dev_num\].sync_IP_octet = 255;" puts $file_handle " eth_device\[eth_dev_num\].is_xilsock_init = 0;" if { $ignore == 0 } { puts $file_handle [format " eth_device\[eth_dev_num\].xilsock_sockets = &xilsock_sockets_eth_%s;" $inst_num] puts $file_handle " eth_device\[eth_dev_num\].is_udp_init = 0;" puts $file_handle [format " eth_device\[eth_dev_num\].xilnet_udp_conns = &xilnet_udp_conns_eth_%s;" $inst_num] puts $file_handle [format " eth_device\[eth_dev_num\].buf_size = XILNET_ETH_%s_BUF_SIZE;" $inst_num] puts $file_handle [format " eth_device\[eth_dev_num\].num_recvbuf = XILNET_ETH_%s_NUM_RECV_BUF;" $inst_num] puts $file_handle [format " eth_device\[eth_dev_num\].recvbuf = (unsigned int *)&recvBuffer_eth_%s;" $inst_num] puts $file_handle [format " eth_device\[eth_dev_num\].sendbuf = (unsigned int *)&sendBuffer_eth_%s;" $inst_num] } else { puts $file_handle " eth_device\[eth_dev_num\].xilsock_sockets = 0;" puts $file_handle " eth_device\[eth_dev_num\].is_udp_init = 0;" puts $file_handle " eth_device\[eth_dev_num\].xilnet_udp_conns = 0;" puts $file_handle [format " eth_device\[eth_dev_num\].buf_size = XILNET_ETH_%s_BUF_SIZE;" $inst_num] puts $file_handle [format " eth_device\[eth_dev_num\].num_recvbuf = XILNET_ETH_%s_NUM_RECV_BUF;" $inst_num] puts $file_handle " eth_device\[eth_dev_num\].recvbuf = 0;" puts $file_handle " eth_device\[eth_dev_num\].sendbuf = 0;" } puts $file_handle " break;" incr inst_num } puts $file_handle " default:" puts $file_handle " xil_printf(\" **** ERROR: Trying to initialize Ethernet device %d. Only %d configured in the HW.\", (eth_dev_num+1), XILNET_NUM_ETH_DEVICES);" puts $file_handle " break;" puts $file_handle " \}" puts $file_handle "\}" puts $file_handle "" puts $file_handle "" puts $file_handle "/*****************************************************************************/" puts $file_handle "" }