1 | #include "stdlib.h" |
---|
2 | #include "string.h" |
---|
3 | #include "stdarg.h" |
---|
4 | |
---|
5 | #include "xil_io.h" |
---|
6 | #include "xstatus.h" |
---|
7 | #include "xparameters.h" |
---|
8 | |
---|
9 | #include "wlan_platform_common.h" |
---|
10 | #include "w3_common.h" |
---|
11 | #include "w3_userio_util.h" |
---|
12 | #include "wlan_mac_common.h" |
---|
13 | #include "w3_iic_eeprom.h" |
---|
14 | #include "w3_sysmon_util.h" |
---|
15 | #include "wlan_cpu_id.h" |
---|
16 | #include "w3_userio.h" |
---|
17 | #include "wlan_platform_debug_hdr.h" |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | static const platform_common_dev_info_t platform_common_dev_info = { |
---|
22 | .platform_id = PLATFORM_ID_W3, |
---|
23 | .cpu_id = XPAR_CPU_ID, |
---|
24 | #if WLAN_COMPILE_FOR_CPU_HIGH |
---|
25 | .is_cpu_high = 1, |
---|
26 | .is_cpu_low = 0, |
---|
27 | #endif |
---|
28 | #if WLAN_COMPILE_FOR_CPU_LOW |
---|
29 | .is_cpu_high = 0, |
---|
30 | .is_cpu_low = 1, |
---|
31 | #endif |
---|
32 | .mailbox_dev_id = PLATFORM_DEV_ID_MAILBOX, |
---|
33 | .pkt_buf_mutex_dev_id = PLATFORM_DEV_ID_PKT_BUF_MUTEX, |
---|
34 | .tx_pkt_buf_baseaddr = XPAR_PKT_BUFF_TX_BRAM_CTRL_S_AXI_BASEADDR, |
---|
35 | .rx_pkt_buf_baseaddr = XPAR_PKT_BUFF_RX_BRAM_CTRL_S_AXI_BASEADDR, |
---|
36 | .tx_power_max_dbm = TX_POWER_MAX_DBM, |
---|
37 | .tx_power_min_dbm = TX_POWER_MIN_DBM, |
---|
38 | .tx_radio_prep_latency_100ns = 3, //(~300 nsec radio_controller TxEn process) + (~1.4 usec baseband -> antenna port) |
---|
39 | .tx_analog_latency_100ns = 14, //(~1.4 usec baseband -> antenna port) |
---|
40 | .rx_analog_latency_100ns = 14, //(~1.4 usec antenna port -> baseband) |
---|
41 | .capabilities_flags = PLATFORM_CAPABILITIES_FLAGS_SUPPORTS_PER_TX_POWER |
---|
42 | }; |
---|
43 | |
---|
44 | static const char serial_number_prefix[] = "W3-a"; |
---|
45 | |
---|
46 | platform_common_dev_info_t wlan_platform_common_get_dev_info(){ |
---|
47 | return platform_common_dev_info; |
---|
48 | } |
---|
49 | |
---|
50 | int wlan_platform_common_init(){ |
---|
51 | u32 iter = 0; |
---|
52 | while (iic_eeprom_init(EEPROM_BASEADDR, 0x64, XPAR_CPU_ID) != IIC_EEPROM_SUCCESS){ |
---|
53 | iter++; |
---|
54 | }; |
---|
55 | |
---|
56 | // ------------------------------------------ |
---|
57 | // Initialize the System Monitor |
---|
58 | init_sysmon(); |
---|
59 | |
---|
60 | //Use entropy source to seed PRNG |
---|
61 | u32 temp_curr = 0; |
---|
62 | u32 temp_prev = 0; |
---|
63 | u32 rand_seed = 0; |
---|
64 | u8 num_bits = 0; |
---|
65 | |
---|
66 | while(1){ |
---|
67 | temp_curr = wlan_platform_get_current_temp(); |
---|
68 | |
---|
69 | if ((temp_curr == temp_prev) && (iter < 1000000)){ |
---|
70 | iter++; |
---|
71 | } else { |
---|
72 | |
---|
73 | temp_prev = temp_curr; |
---|
74 | iter = 0; |
---|
75 | |
---|
76 | rand_seed = (rand_seed<<1) | (temp_curr&1); |
---|
77 | num_bits++; |
---|
78 | |
---|
79 | if(num_bits > 32){ |
---|
80 | break; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | xil_printf("Rand Seed: 0x%08x\n", rand_seed); |
---|
88 | srand(rand_seed); |
---|
89 | |
---|
90 | |
---|
91 | return WLAN_SUCCESS; |
---|
92 | } |
---|
93 | |
---|
94 | wlan_mac_hw_info_t wlan_platform_get_hw_info(){ |
---|
95 | |
---|
96 | static u32 already_read = 0; |
---|
97 | static wlan_mac_hw_info_t mac_hw_info; |
---|
98 | |
---|
99 | if(already_read == 0){ |
---|
100 | // Set General Node information |
---|
101 | mac_hw_info.platform_id = PLATFORM_ID_W3; |
---|
102 | mac_hw_info.platform_config = PLATFORM_CONFIG; |
---|
103 | mac_hw_info.serial_number_prefix = serial_number_prefix; |
---|
104 | mac_hw_info.serial_number = w3_eeprom_read_serial_num(EEPROM_BASEADDR); |
---|
105 | |
---|
106 | // Set HW Addresses |
---|
107 | // - The w3_eeprom_read_eth_addr() function handles the case when the WARP v3 |
---|
108 | // hardware does not have a valid Ethernet address |
---|
109 | // |
---|
110 | // Use address 0 for the WLAN interface, address 1 for the WLAN Exp interface |
---|
111 | // |
---|
112 | w3_eeprom_read_eth_addr(EEPROM_BASEADDR, 0, mac_hw_info.hw_addr_wlan); |
---|
113 | w3_eeprom_read_eth_addr(EEPROM_BASEADDR, 1, mac_hw_info.hw_addr_wlan_exp); |
---|
114 | already_read = 1; |
---|
115 | } |
---|
116 | |
---|
117 | return mac_hw_info; |
---|
118 | } |
---|
119 | |
---|
120 | u32 wlan_platform_userio_get_state(){ |
---|
121 | u32 return_value = 0; |
---|
122 | u32 user_io_inputs; |
---|
123 | |
---|
124 | user_io_inputs = userio_read_inputs(USERIO_BASEADDR); |
---|
125 | |
---|
126 | if(user_io_inputs & W3_USERIO_PB_U) return_value |= USERIO_INPUT_MASK_PB_0; |
---|
127 | if(user_io_inputs & W3_USERIO_PB_M) return_value |= USERIO_INPUT_MASK_PB_1; |
---|
128 | if(user_io_inputs & W3_USERIO_PB_D) return_value |= USERIO_INPUT_MASK_PB_2; |
---|
129 | |
---|
130 | if(user_io_inputs & W3_USERIO_DIPSW_0) return_value |= USERIO_INPUT_MASK_SW_0; |
---|
131 | if(user_io_inputs & W3_USERIO_DIPSW_1) return_value |= USERIO_INPUT_MASK_SW_1; |
---|
132 | if(user_io_inputs & W3_USERIO_DIPSW_2) return_value |= USERIO_INPUT_MASK_SW_2; |
---|
133 | if(user_io_inputs & W3_USERIO_DIPSW_3) return_value |= USERIO_INPUT_MASK_SW_3; |
---|
134 | |
---|
135 | return return_value; |
---|
136 | } |
---|