1 | /** @file wl_transport.h |
---|
2 | * @brief WARPLab Framework (Transport) |
---|
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 | */ |
---|
13 | |
---|
14 | /**********************************************************************************************************************/ |
---|
15 | /** |
---|
16 | * @brief Common Functions (WARP v2 and WARP v3) |
---|
17 | * |
---|
18 | **********************************************************************************************************************/ |
---|
19 | |
---|
20 | /***************************** Include Files *********************************/ |
---|
21 | |
---|
22 | // WARPLab includes |
---|
23 | #include "wl_common.h" |
---|
24 | |
---|
25 | |
---|
26 | // WARP UDP transport includes |
---|
27 | #include <WARP_ip_udp.h> |
---|
28 | #include <WARP_ip_udp_device.h> |
---|
29 | |
---|
30 | |
---|
31 | /*************************** Constant Definitions ****************************/ |
---|
32 | #ifndef WL_TRANSPORT_H_ |
---|
33 | #define WL_TRANSPORT_H_ |
---|
34 | |
---|
35 | // ********************************************************************** |
---|
36 | // Command IDs (must match the CMD_ properties in wl_transport_*.m) |
---|
37 | // |
---|
38 | #define CMDID_TRANSPORT_PING 0x000001 |
---|
39 | #define CMDID_TRANSPORT_PAYLOAD_SIZE_TEST 0x000002 |
---|
40 | |
---|
41 | #define CMDID_TRANSPORT_NODE_GROUP_ID_ADD 0x000010 |
---|
42 | #define CMDID_TRANSPORT_NODE_GROUP_ID_CLEAR 0x000011 |
---|
43 | |
---|
44 | |
---|
45 | // *********************************************************************** |
---|
46 | // Define WARPLab Transport Ethernet Information |
---|
47 | // |
---|
48 | #define WL_NUM_ETH_DEVICES WARP_IP_UDP_NUM_ETH_DEVICES |
---|
49 | #define WL_ETH_DEV_INITIALIZED 1 |
---|
50 | |
---|
51 | #define WL_IP_UDP_TRANSPORT 1 |
---|
52 | |
---|
53 | |
---|
54 | // Ethernet constants |
---|
55 | #define ETH_DO_NOT_WAIT_FOR_AUTO_NEGOTIATION 0 |
---|
56 | #define ETH_WAIT_FOR_AUTO_NEGOTIATION 1 |
---|
57 | |
---|
58 | // WARPLab message types |
---|
59 | #define PKTTYPE_TRIGGER 0 |
---|
60 | #define PKTTYPE_HTON_MSG 1 |
---|
61 | #define PKTTYPE_NTOH_MSG 2 |
---|
62 | |
---|
63 | // Transport status types |
---|
64 | #define LINK_READY 0 |
---|
65 | #define LINK_NOT_READY -1 |
---|
66 | |
---|
67 | // Transport header flags (16 bits) |
---|
68 | #define TRANSPORT_HDR_ROBUST_FLAG 0x0001 |
---|
69 | #define TRANSPORT_HDR_NODE_NOT_READY_FLAG 0x8000 |
---|
70 | |
---|
71 | |
---|
72 | /*********************** Global Structure Definitions ************************/ |
---|
73 | |
---|
74 | // WARPLab Transport header |
---|
75 | // NOTE: This conforms to the WARPLab Transport Header Wire Format: |
---|
76 | // http://warpproject.org/trac/wiki/WARPLab/Reference/Architecture/WireFormat |
---|
77 | // |
---|
78 | typedef struct { |
---|
79 | u16 dest_id; |
---|
80 | u16 src_id; |
---|
81 | u8 reserved; |
---|
82 | u8 pkt_type; |
---|
83 | u16 length; |
---|
84 | u16 seq_num; |
---|
85 | u16 flags; |
---|
86 | } wl_transport_header; |
---|
87 | |
---|
88 | |
---|
89 | // WARPLab Ethernet device information |
---|
90 | // NOTE: This is so that differences between different Ethernet devices can be consolidated |
---|
91 | // |
---|
92 | typedef struct { |
---|
93 | u32 initialized; // Etherent device initialized |
---|
94 | u32 default_speed; // Default Ethernet speed |
---|
95 | u32 phy_addr; // Address of the Ethernt PHY |
---|
96 | |
---|
97 | u32 type; // Transport Type |
---|
98 | u32 hw_addr[2]; // HW Address (big endian as 2 u32 values with 16 bit padding) |
---|
99 | u32 ip_addr; // IP Address (big endian) |
---|
100 | int unicast_socket; // Unicast socket index |
---|
101 | int broadcast_socket; // Broadcast socket index |
---|
102 | u32 group_id; // Group ID |
---|
103 | } wl_eth_dev_info; |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | /*************************** Function Prototypes *****************************/ |
---|
108 | |
---|
109 | int transport_init(u32 eth_dev_num, u8 init_driver); |
---|
110 | |
---|
111 | int transport_set_process_hton_msg_callback(void(*handler)); |
---|
112 | int transport_process_cmd(int socket_index, void * from, wl_cmd_resp * command, wl_cmd_resp * response); |
---|
113 | |
---|
114 | void transport_poll(u32 eth_dev_num); |
---|
115 | void transport_send(int socket_index, struct sockaddr * to, warp_ip_udp_buffer ** buffers, u32 num_buffers); |
---|
116 | void transport_close(u32 eth_dev_num); |
---|
117 | |
---|
118 | int transport_get_hw_info(u32 eth_dev_num, u8 * ip_addr, u8 * hw_addr); |
---|
119 | int transport_config_sockets(u32 eth_dev_num, u32 unicast_port, u32 bcast_port); |
---|
120 | int transport_config_socket(u32 eth_dev_num, int * socket_index, u32 udp_port); |
---|
121 | |
---|
122 | int transport_link_status(u32 eth_dev_num); |
---|
123 | u32 transport_update_link_speed(u32 eth_dev_num, u32 wait_for_negotiation); |
---|
124 | u16 transport_get_ethernet_status(u32 eth_dev_num); |
---|
125 | |
---|
126 | |
---|
127 | |
---|
128 | |
---|
129 | |
---|
130 | /**********************************************************************************************************************/ |
---|
131 | /** |
---|
132 | * @brief WARP v3 Specific Functions |
---|
133 | * |
---|
134 | **********************************************************************************************************************/ |
---|
135 | |
---|
136 | #ifdef WARP_HW_VER_v3 |
---|
137 | |
---|
138 | /***************************** Include Files *********************************/ |
---|
139 | |
---|
140 | |
---|
141 | /*************************** Constant Definitions ****************************/ |
---|
142 | |
---|
143 | // Ethernet A constants |
---|
144 | #define WL_ETH_A ETH_A_MAC |
---|
145 | #define WL_ETH_A_MDIO_PHYADDR 0x6 |
---|
146 | |
---|
147 | // Ethernt B constants |
---|
148 | #define WL_ETH_B ETH_B_MAC |
---|
149 | #define WL_ETH_B_MDIO_PHYADDR 0x7 |
---|
150 | |
---|
151 | // Ethernet PHY constants |
---|
152 | #define ETH_PHY_CONTROL_REG 0 |
---|
153 | #define ETH_PHY_STATUS_REG 17 |
---|
154 | |
---|
155 | #define ETH_PHY_REG_0_RESET 0x8000 |
---|
156 | #define ETH_PHY_REG_0_SPEED_LSB 0x2000 |
---|
157 | #define ETH_PHY_REG_0_AUTO_NEGOTIATION 0x1000 |
---|
158 | #define ETH_PHY_REG_0_SPEED_MSB 0x0040 |
---|
159 | |
---|
160 | #define ETH_PHY_REG_17_0_SPEED 0xC000 |
---|
161 | #define ETH_PHY_REG_17_0_SPEED_RESOLVED 0x0800 |
---|
162 | #define ETH_PHY_REG_17_0_LINKUP 0x0400 |
---|
163 | |
---|
164 | |
---|
165 | // NOTE: These constants are for in place computation based on ETH_PHY_REG_17_0_SPEED (ie no bit shifting required) |
---|
166 | #define ETH_PHY_REG_17_0_SPEED_10_MBPS 0x0000 |
---|
167 | #define ETH_PHY_REG_17_0_SPEED_100_MBPS 0x4000 |
---|
168 | #define ETH_PHY_REG_17_0_SPEED_1000_MBPS 0x8000 |
---|
169 | #define ETH_PHY_REG_17_0_SPEED_RSVD 0xC000 |
---|
170 | |
---|
171 | |
---|
172 | // Ethernet PHY macros |
---|
173 | // NOTE: Speed is defined by the Ethernet hardware (xaxiethernet_hw.h and equivalent for WARP v2): |
---|
174 | // #define XAE_SPEED_10_MBPS 10 /**< Speed of 10 Mbps */ |
---|
175 | // #define XAE_SPEED_100_MBPS 100 /**< Speed of 100 Mbps */ |
---|
176 | // #define XAE_SPEED_1000_MBPS 1000 /**< Speed of 1000 Mbps */ |
---|
177 | // |
---|
178 | #define ETH_PHY_SPEED_10_MBPS 10 |
---|
179 | #define ETH_PHY_SPEED_100_MBPS 100 |
---|
180 | #define ETH_PHY_SPEED_1000_MBPS 1000 |
---|
181 | |
---|
182 | #define ETH_PHY_SPEED_TO_MBPS(speed) ((speed == ETH_PHY_REG_17_0_SPEED_1000_MBPS) ? ETH_PHY_SPEED_1000_MBPS : \ |
---|
183 | (speed == ETH_PHY_REG_17_0_SPEED_100_MBPS) ? ETH_PHY_SPEED_100_MBPS : \ |
---|
184 | (speed == ETH_PHY_REG_17_0_SPEED_10_MBPS) ? ETH_PHY_SPEED_10_MBPS : 0 ) |
---|
185 | |
---|
186 | |
---|
187 | |
---|
188 | /*********************** Global Structure Definitions ************************/ |
---|
189 | |
---|
190 | |
---|
191 | /******************************** Functions **********************************/ |
---|
192 | |
---|
193 | #endif |
---|
194 | |
---|
195 | #endif /* WL_TRANSPORT_H_ */ |
---|