[4184] | 1 | /** @file wl_common.h |
---|
| 2 | * @brief WARPLab Framework (Common) |
---|
| 3 | * |
---|
| 4 | * This contains the code for WARPLab Framework. |
---|
| 5 | * |
---|
| 6 | * @copyright Copyright 2013, Mango Communications. All rights reserved. |
---|
| 7 | * Distributed under the WARP license (http://warpproject.org/license) |
---|
| 8 | * |
---|
| 9 | * @author Chris Hunter (chunter [at] mangocomm.com) |
---|
| 10 | * @author Patrick Murphy (murphpo [at] mangocomm.com) |
---|
| 11 | * @author Erik Welsh (welsh [at] mangocomm.com) |
---|
| 12 | */ |
---|
[1915] | 13 | |
---|
[4184] | 14 | /***************************** Include Files *********************************/ |
---|
[2017] | 15 | |
---|
[4184] | 16 | // Xilinx / Standard library includes |
---|
| 17 | #include <xil_types.h> |
---|
| 18 | |
---|
| 19 | // WARPLab includes |
---|
| 20 | #include "warp_hw_ver.h" |
---|
| 21 | |
---|
| 22 | |
---|
| 23 | /*************************** Constant Definitions ****************************/ |
---|
[1915] | 24 | #ifndef WL_COMMON_H_ |
---|
| 25 | #define WL_COMMON_H_ |
---|
| 26 | |
---|
[4184] | 27 | |
---|
[1915] | 28 | // ********************************************************************** |
---|
[4184] | 29 | // WARPLab Controls |
---|
| 30 | // |
---|
[4673] | 31 | // NOTE: These are the most common parameters that would be modified by a user: |
---|
| 32 | // 1) Debug print level |
---|
| 33 | // 2) DDR initialization |
---|
| 34 | // 3) Ethernet controls |
---|
| 35 | // |
---|
[4184] | 36 | |
---|
| 37 | |
---|
[4673] | 38 | // 1) Choose the default debug print level |
---|
| 39 | // |
---|
| 40 | // Values (see wl_common.h for more information): |
---|
| 41 | // WL_PRINT_NONE - Print WL_PRINT_NONE messages |
---|
| 42 | // WL_PRINT_ERROR - Print WL_PRINT_ERROR and WL_PRINT_NONE messages |
---|
| 43 | // WL_PRINT_WARNING - Print WL_PRINT_WARNING, WL_PRINT_ERROR and WL_PRINT_NONE messages |
---|
| 44 | // WL_PRINT_INFO - Print WL_PRINT_INFO, WL_PRINT_WARNING, WL_PRINT_ERROR and WL_PRINT_NONE messages |
---|
| 45 | // WL_PRINT_DEBUG - Print WL_PRINT_DEBUG, WL_PRINT_INFO, WL_PRINT_WARNING, WL_PRINT_ERROR and WL_PRINT_NONE messages |
---|
| 46 | // |
---|
| 47 | #define DEFAULT_DEBUG_PRINT_LEVEL WL_PRINT_WARNING |
---|
[4184] | 48 | |
---|
| 49 | |
---|
[4673] | 50 | // 2) Initialize the DDR to zeros (ie clear DDR) at boot |
---|
| 51 | // |
---|
| 52 | // Values: |
---|
| 53 | // 1 - Clear DDR on boot |
---|
| 54 | // 0 - Do not clear DDR on boot |
---|
| 55 | // |
---|
| 56 | // NOTE: Based on initial testing, clearing DDR on boot will add approximately 1 second to |
---|
| 57 | // the boot time of the node. See clear_ddr() in wl_common.c for more information. |
---|
| 58 | // |
---|
| 59 | #define CLEAR_DDR_ON_BOOT 0 |
---|
[4184] | 60 | |
---|
[4673] | 61 | |
---|
| 62 | // 3) Ethernet controls |
---|
| 63 | // |
---|
| 64 | // a) Choose the Ethernet device and set the base address for the subnet and speed of the device: |
---|
| 65 | // |
---|
| 66 | // Values for WL_USE_ETH_A and WL_USE_ETH_B: |
---|
| 67 | // 1 - Use the Ethernet device |
---|
| 68 | // 0 - Do not use the Ethernet device |
---|
| 69 | // |
---|
| 70 | // Values for *_IP_ADDR_BASE: |
---|
| 71 | // 0xAABBCC00 - Hexadecimal representation of an IP subnet: AA.BB.CC.00 |
---|
| 72 | // where AA, BB, and CC are hexadecimal numbers. |
---|
| 73 | // |
---|
| 74 | // NOTE: IP subnet should match the host networking setup defined in wl_setup |
---|
| 75 | // NOTE: Ethernet devices can not be on the same subnet. The transport_read_ip_addr() |
---|
| 76 | // function in wl_transport.c assigns the same final IP address octet to both |
---|
| 77 | // Ethernet devices. |
---|
| 78 | // |
---|
| 79 | // Values for *_DEFAULT_SPEED: |
---|
| 80 | // 1000 - 1000 Mbps Ethernet (ie 1Gbps) |
---|
| 81 | // 100 - 100 Mbps Ethernet |
---|
| 82 | // 10 - 10 Mbps Ethernet |
---|
| 83 | // |
---|
| 84 | #define WL_USE_ETH_A 1 |
---|
| 85 | #define WL_ETH_A_IP_ADDR_BASE 0x0a000000 // 10.0.0.x |
---|
| 86 | #define WL_ETH_A_DEFAULT_SPEED 1000 |
---|
| 87 | |
---|
| 88 | #define WL_USE_ETH_B 0 |
---|
| 89 | #define WL_ETH_B_IP_ADDR_BASE 0x0a000100 // 10.0.1.x |
---|
| 90 | #define WL_ETH_B_DEFAULT_SPEED 1000 |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | // b) Wait for WARPNet Ethernet interface to be ready before continuing boot |
---|
| 94 | // |
---|
| 95 | // Values: |
---|
| 96 | // 1 - Wait for Ethernet device to be ready |
---|
| 97 | // 0 - Do not wait for Ethernet device to be ready |
---|
| 98 | // |
---|
| 99 | // NOTE: During boot, this parameter will cause the node to wait for all Ethernet |
---|
| 100 | // devices with WL_USE_ETH_* = 1 to be ready. This means if the node is configured |
---|
| 101 | // to use both ETH A and ETH B, then the node will wait until the link is ready for |
---|
| 102 | // both ETH A and ETH B. |
---|
| 103 | // |
---|
| 104 | #define WL_WAIT_FOR_ETH 1 |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | // c) Allow Ethernet Link speed to be negotiated |
---|
| 108 | // |
---|
| 109 | // Values of WL_NEGOTIATE_ETH_LINK_SPEED: |
---|
| 110 | // 1 - Auto-negotiate the Ethernet link speed |
---|
| 111 | // 0 - Do not auto-negotiate the Ethernet link speed. Speed is set |
---|
| 112 | // by the *_DEFAULT_SPEED defined above. |
---|
| 113 | // |
---|
| 114 | // NOTE: Based on initial testing, auto-negotiation of the link speed will add around 3 |
---|
| 115 | // seconds to the boot time of the node. To bypass auto-negotiation but use a |
---|
| 116 | // different default link speed, please adjust the WL_ETH_*_DEFAULT_SPEED define |
---|
| 117 | // above. |
---|
| 118 | // |
---|
| 119 | #define WL_NEGOTIATE_ETH_LINK_SPEED 0 |
---|
| 120 | |
---|
| 121 | |
---|
| 122 | // d) Allow Ethernet reception of packets to be paused via the UART terminal |
---|
| 123 | // |
---|
| 124 | // Values: |
---|
| 125 | // 1 - Allow Ethernet receptions to be paused via UART terminal |
---|
| 126 | // 0 - Do not allow Ethernet receptions to be paused via UART terminal |
---|
| 127 | // |
---|
| 128 | // NOTE: Use the character 's' in the UART terminal to 's'tart and 's'top reception of |
---|
| 129 | // Ethernet packets. |
---|
| 130 | // |
---|
| 131 | #define ALLOW_ETHERNET_PAUSE 0 |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | |
---|
[1915] | 135 | // ********************************************************************** |
---|
[4184] | 136 | // WARPLab Version Information |
---|
| 137 | // |
---|
[1915] | 138 | |
---|
[4184] | 139 | // Version info (MAJOR.MINOR.REV, all must be ints) |
---|
| 140 | // MAJOR and MINOR are both u8, while REV is u16 |
---|
| 141 | // m-code requires C code MAJOR.MINOR match values in wl_version.ini |
---|
| 142 | #define WARPLAB_VER_MAJOR 7 |
---|
[4820] | 143 | #define WARPLAB_VER_MINOR 7 |
---|
[5625] | 144 | #define WARPLAB_VER_REV 1 |
---|
[1915] | 145 | |
---|
[4184] | 146 | #define REQ_WARPLAB_HW_VER ((WARPLAB_VER_MAJOR << 16) | (WARPLAB_VER_MINOR << 8) | (WARPLAB_VER_REV)) |
---|
[2009] | 147 | |
---|
[1915] | 148 | |
---|
[4184] | 149 | |
---|
[1915] | 150 | // ********************************************************************** |
---|
[4673] | 151 | // Interface Configuration Information |
---|
| 152 | // |
---|
| 153 | |
---|
| 154 | // Use 4 Antennas (default is 0, ie 2 Antennas) |
---|
| 155 | #define WARPLAB_CONFIG_4RF 0 |
---|
| 156 | |
---|
| 157 | |
---|
| 158 | |
---|
| 159 | // ********************************************************************** |
---|
[4184] | 160 | // Network Configuration Information |
---|
| 161 | // NOTE: The values below must match the corresponding values in wl_config.ini |
---|
| 162 | // |
---|
[1915] | 163 | |
---|
[4184] | 164 | // Default network info |
---|
[4514] | 165 | // - The base IP address should be a u32 (big endian) with (at least) the last octet 0x00 |
---|
| 166 | // |
---|
[4184] | 167 | #define BROADCAST_DEST_ID 0xFFFF |
---|
[1957] | 168 | |
---|
[4514] | 169 | // Default ports |
---|
| 170 | // - unicast ports are used for host-to-node |
---|
| 171 | // - multicast for triggers and host-to-multinode |
---|
| 172 | // |
---|
[4184] | 173 | #define NODE_UDP_UNICAST_PORT_BASE 9000 |
---|
| 174 | #define NODE_UDP_MCAST_BASE 10000 |
---|
[1915] | 175 | |
---|
| 176 | |
---|
[2013] | 177 | |
---|
[4184] | 178 | // ********************************************************************** |
---|
| 179 | // WARPLab Common Defines |
---|
| 180 | // |
---|
| 181 | #define PAYLOAD_PAD_NBYTES 2 |
---|
[1915] | 182 | |
---|
[4284] | 183 | #define NO_RESP_SENT 0 |
---|
[4184] | 184 | #define RESP_SENT 1 |
---|
[4284] | 185 | #define NODE_NOT_READY 2 |
---|
[1942] | 186 | |
---|
[4184] | 187 | #define SUCCESS 0 |
---|
| 188 | #define FAILURE -1 |
---|
[2054] | 189 | |
---|
[4284] | 190 | #define WL_CMD_TO_GRP(x) ((x) >> 24) |
---|
| 191 | #define WL_CMD_TO_CMDID(x) ((x) & 0x00FFFFFF) |
---|
[1915] | 192 | |
---|
[4184] | 193 | #define FPGA_DNA_LEN 2 |
---|
| 194 | #define IP_VERSION 4 |
---|
| 195 | #define ETH_ADDR_LEN 6 |
---|
[1915] | 196 | |
---|
[4783] | 197 | #define WL_TRUE 1 |
---|
| 198 | #define WL_FALSE 0 |
---|
| 199 | |
---|
[4184] | 200 | #define WL_NO_TRANSMIT 0 |
---|
| 201 | #define WL_TRANSMIT 1 |
---|
[1915] | 202 | |
---|
[4673] | 203 | #define WL_ENABLE 1 |
---|
| 204 | #define WL_DISABLE 0 |
---|
| 205 | |
---|
[4387] | 206 | #define WL_SILENT 0 |
---|
| 207 | #define WL_VERBOSE 1 |
---|
[1915] | 208 | |
---|
| 209 | |
---|
[4196] | 210 | // ********************************************************************** |
---|
[4333] | 211 | // WARPLab Command Defines |
---|
| 212 | // |
---|
| 213 | #define CMD_PARAM_WRITE_VAL 0x00000000 |
---|
| 214 | #define CMD_PARAM_READ_VAL 0x00000001 |
---|
| 215 | #define CMD_PARAM_RSVD 0xFFFFFFFF |
---|
| 216 | |
---|
| 217 | #define CMD_PARAM_SUCCESS 0x00000000 |
---|
| 218 | #define CMD_PARAM_ERROR 0xFF000000 |
---|
| 219 | |
---|
| 220 | |
---|
[4196] | 221 | |
---|
[4292] | 222 | // ********************************************************************** |
---|
| 223 | // Defines for non-invasive debug |
---|
| 224 | // |
---|
| 225 | #define _DEBUG_STORAGE_ 0 |
---|
| 226 | #define _DEBUG_STORAGE_SIZE_ 400 |
---|
| 227 | |
---|
| 228 | #define _MEASUREMENT_PRINT_ 0 |
---|
[4333] | 229 | #define _MEASUREMENT_PRINT_WIDTH_ 4 |
---|
[4292] | 230 | |
---|
| 231 | |
---|
| 232 | |
---|
[4184] | 233 | /*********************** Global Structure Definitions ************************/ |
---|
[4196] | 234 | |
---|
| 235 | // ********************************************************************** |
---|
[4184] | 236 | // WARPLab Message Structures |
---|
| 237 | // |
---|
| 238 | |
---|
[4514] | 239 | // Command / Response Header |
---|
| 240 | // NOTE: This conforms to the WARPLab Command / Response Wire Format: |
---|
| 241 | // http://warpproject.org/trac/wiki/WARPLab/Reference/Architecture/WireFormat |
---|
| 242 | // |
---|
[1915] | 243 | typedef struct{ |
---|
[4514] | 244 | u32 cmd; |
---|
| 245 | u16 length; |
---|
| 246 | u16 num_args; |
---|
| 247 | } wl_cmd_resp_hdr; |
---|
[1915] | 248 | |
---|
[4184] | 249 | |
---|
[4514] | 250 | // Command / Response data structure |
---|
| 251 | // This structure is used to keep track of pointers when decoding WARPLab commands. |
---|
| 252 | // |
---|
| 253 | typedef struct { |
---|
| 254 | void * buffer; // In general, assumed to be a (warp_ip_udp_buffer *) |
---|
| 255 | wl_cmd_resp_hdr * header; |
---|
| 256 | u32 * args; |
---|
| 257 | } wl_cmd_resp; |
---|
[1915] | 258 | |
---|
| 259 | |
---|
| 260 | |
---|
[4196] | 261 | // ********************************************************************** |
---|
| 262 | // WARPLab Function pointer |
---|
| 263 | // |
---|
[4184] | 264 | typedef int (*wl_function_ptr_t)(); |
---|
| 265 | |
---|
| 266 | |
---|
[4196] | 267 | |
---|
[4184] | 268 | // ********************************************************************** |
---|
| 269 | // WARPLab Tag Parameter Structure |
---|
| 270 | // |
---|
| 271 | typedef struct { |
---|
| 272 | u8 reserved; |
---|
| 273 | u8 group; |
---|
| 274 | u16 length; |
---|
| 275 | u32 command; |
---|
| 276 | u32 *value; |
---|
| 277 | } wl_tag_parameter; |
---|
| 278 | |
---|
| 279 | |
---|
| 280 | |
---|
| 281 | // ********************************************************************** |
---|
| 282 | // WARPLab Print Levels |
---|
| 283 | // |
---|
| 284 | #define WL_PRINT_NONE 0 |
---|
| 285 | #define WL_PRINT_ERROR 1 |
---|
| 286 | #define WL_PRINT_WARNING 2 |
---|
| 287 | #define WL_PRINT_INFO 3 |
---|
| 288 | #define WL_PRINT_DEBUG 4 |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | #define wl_printf(level, type, format, args...) \ |
---|
| 292 | do { \ |
---|
| 293 | if (level <= wl_print_level) { \ |
---|
| 294 | wl_print_header(level, type, __FILE__, __LINE__); \ |
---|
| 295 | xil_printf(format, ##args); \ |
---|
| 296 | } \ |
---|
| 297 | } while (0) |
---|
| 298 | |
---|
| 299 | |
---|
| 300 | extern u8 wl_print_level; |
---|
| 301 | extern char * print_type_node; |
---|
| 302 | extern char * print_type_transport; |
---|
| 303 | extern char * print_type_interface; |
---|
| 304 | extern char * print_type_baseband; |
---|
| 305 | extern char * print_type_trigger; |
---|
| 306 | extern char * print_type_user; |
---|
| 307 | |
---|
| 308 | |
---|
| 309 | |
---|
| 310 | /*************************** Function Prototypes *****************************/ |
---|
[4453] | 311 | |
---|
| 312 | // Peripheral Init Functions |
---|
[4184] | 313 | int wl_timer_initialize(); |
---|
| 314 | void wl_gpio_debug_initialize(); |
---|
| 315 | |
---|
[4453] | 316 | // Callbacks |
---|
[4437] | 317 | int wl_null_callback(void* param); |
---|
| 318 | |
---|
[4453] | 319 | // Printing Functions |
---|
[4184] | 320 | void wl_print_header(u8 level, char * type, char * filename, u32 line); |
---|
| 321 | void wl_print_mac_address(u8 level, u8 * mac_address); |
---|
| 322 | |
---|
| 323 | void wl_set_print_level(u8 level); |
---|
| 324 | |
---|
[4453] | 325 | void print_array_u8(u8 *buf, u32 size); |
---|
| 326 | void print_array_u32(u32 *buf, u32 size); |
---|
| 327 | |
---|
| 328 | // GPIO pins on debug header |
---|
[4184] | 329 | inline void wl_setDebugGPIO(u8 mask); |
---|
| 330 | inline void wl_clearDebugGPIO(u8 mask); |
---|
| 331 | |
---|
[4453] | 332 | // 7 segment display |
---|
[4184] | 333 | u8 sevenSegmentMap(u8 hex_value); |
---|
| 334 | |
---|
[4453] | 335 | // Micro-second timestamp counter |
---|
[4437] | 336 | u64 get_usec_timestamp(); |
---|
| 337 | |
---|
[4292] | 338 | // Non-invasive debug functions |
---|
| 339 | void add_to_debug_storage(u32 value, u32 enable); |
---|
[4333] | 340 | void remove_from_debug_storage(u32 num_elements, u32 enable); |
---|
[4292] | 341 | void reset_debug_storage(); |
---|
| 342 | void print_debug_storage(); |
---|
| 343 | |
---|
| 344 | |
---|
[4453] | 345 | |
---|
| 346 | /**********************************************************************************************************************/ |
---|
| 347 | /** |
---|
| 348 | * @brief WARP v3 Specific Functions |
---|
| 349 | * |
---|
| 350 | **********************************************************************************************************************/ |
---|
| 351 | |
---|
| 352 | #ifdef WARP_HW_VER_v3 |
---|
| 353 | |
---|
| 354 | /***************************** Include Files *********************************/ |
---|
| 355 | |
---|
| 356 | /*************************** Constant Definitions ****************************/ |
---|
| 357 | |
---|
| 358 | // ********************************************************************** |
---|
| 359 | // WARPLab Peripheral Defines |
---|
| 360 | // |
---|
| 361 | #define USERIO_BASEADDR XPAR_W3_USERIO_BASEADDR |
---|
| 362 | #define EEPROM_BASEADDR XPAR_W3_IIC_EEPROM_ONBOARD_BASEADDR |
---|
| 363 | #define RC_BASEADDR XPAR_RADIO_CONTROLLER_0_BASEADDR |
---|
| 364 | #define CLK_BASEADDR XPAR_W3_CLOCK_CONTROLLER_0_BASEADDR |
---|
| 365 | #define DRAM_BASEADDR XPAR_DDR3_SODIMM_S_AXI_BASEADDR |
---|
| 366 | #define AD_BASEADDR XPAR_W3_AD_CONTROLLER_0_BASEADDR |
---|
| 367 | #define SYSMON_BASEADDR XPAR_SYSMON_0_BASEADDR |
---|
| 368 | |
---|
| 369 | #define DDR_SIZE (XPAR_DDR3_SODIMM_S_AXI_HIGHADDR - XPAR_DDR3_SODIMM_S_AXI_BASEADDR + 1) |
---|
| 370 | |
---|
| 371 | |
---|
| 372 | /*********************** Global Structure Definitions ************************/ |
---|
| 373 | |
---|
| 374 | // ********************************************************************** |
---|
| 375 | // WARPLab Interrupt State |
---|
| 376 | // |
---|
| 377 | typedef enum {INTERRUPTS_DISABLED, INTERRUPTS_ENABLED} interrupt_state_t; |
---|
| 378 | |
---|
| 379 | |
---|
| 380 | /******************************** Functions **********************************/ |
---|
| 381 | |
---|
| 382 | // Peripheral Init Functions |
---|
| 383 | void wl_sysmon_initialize(); |
---|
| 384 | int wl_cdma_initialize(); |
---|
| 385 | int wl_uart_initialize(); |
---|
| 386 | |
---|
| 387 | // DMA Functions |
---|
| 388 | void wl_cdma_transfer(u32 src_address, u32 dest_address, u32 length); |
---|
| 389 | int wl_cdma_busy(); |
---|
| 390 | |
---|
| 391 | // Callbacks |
---|
| 392 | void wl_set_uart_rx_callback(wl_function_ptr_t callback); |
---|
| 393 | |
---|
| 394 | // Interrupt Functions |
---|
| 395 | int wl_interrupt_init(); |
---|
| 396 | inline int wl_interrupt_restore_state(interrupt_state_t new_interrupt_state); |
---|
| 397 | inline interrupt_state_t wl_interrupt_stop(); |
---|
| 398 | |
---|
| 399 | // HW specific functions |
---|
| 400 | void usleep(u32 duration); |
---|
| 401 | int microblaze_right_shift_test(); |
---|
| 402 | int ddr_sodim_memory_test(); |
---|
| 403 | void clear_ddr(u32 verbose); |
---|
| 404 | |
---|
[4184] | 405 | #endif |
---|
| 406 | |
---|
| 407 | |
---|
[1915] | 408 | #endif /* WL_COMMON_H_ */ |
---|