1 // Copyright 2016 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef PHY_INIT_DATA_H
16 #define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */
17 #include "esp_phy_init.h"
18 #include "sdkconfig.h"
19 
20 // constrain a value between 'low' and 'high', inclusive
21 #define LIMIT(val, low, high) ((val < low) ? low : (val > high) ? high : val)
22 
23 #define PHY_INIT_MAGIC "PHYINIT"
24 
25 // define the lowest tx power as LOWEST_PHY_TX_POWER
26 #define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52)
27 #define PHY_TX_POWER_OFFSET 44
28 #define PHY_TX_POWER_NUM    5
29 
30 #if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
31 #define PHY_CRC_ALGORITHM 1
32 #define PHY_COUNTRY_CODE_LEN 2
33 #define PHY_INIT_DATA_TYPE_OFFSET 126
34 #define PHY_SUPPORT_MULTIPLE_BIN_OFFSET 125
35 #endif
36 static const char phy_init_magic_pre[] = PHY_INIT_MAGIC;
37 
38 /**
39  * @brief Structure containing default recommended PHY initialization parameters.
40  */
41 static const esp_phy_init_data_t phy_init_data= { {
42         3,
43         3,
44         0x05,
45         0x09,
46         0x06,
47         0x05,
48         0x03,
49         0x06,
50         0x05,
51         0x04,
52         0x06,
53         0x04,
54         0x05,
55         0x00,
56         0x00,
57         0x00,
58         0x00,
59         0x05,
60         0x09,
61         0x06,
62         0x05,
63         0x03,
64         0x06,
65         0x05,
66         0x00,
67         0x00,
68         0x00,
69         0x00,
70         0x00,
71         0x00,
72         0x00,
73         0x00,
74         0xfc,
75         0xfc,
76         0xfe,
77         0xf0,
78         0xf0,
79         0xf0,
80         0xe0,
81         0xe0,
82         0xe0,
83         0x18,
84         0x18,
85         0x18,
86         LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 84),
87         LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 72),
88         LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 66),
89         LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 60),
90         LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 56),
91         LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 40, 52),
92         0,
93         1,
94         1,
95         2,
96         2,
97         3,
98         4,
99         5,
100         0,
101         0,
102         0,
103         0,
104         0,
105         0,
106         0,
107         0,
108         0,
109         0,
110         0,
111         0,
112         0,
113         0,
114         0,
115         0,
116         0,
117         0,
118         0,
119         0,
120         0,
121         0,
122         0,
123         0,
124         0,
125         0,
126         0,
127         0,
128         0,
129         0,
130         0,
131         0,
132         0,
133         0,
134         0,
135         0,
136         0,
137         0,
138         0,
139         0,
140         0,
141         0,
142         0,
143         0,
144         0,
145         0,
146         0,
147         0,
148         0,
149 } };
150 
151 static const char phy_init_magic_post[] = PHY_INIT_MAGIC;
152 
153 #if CONFIG_ESP32_SUPPORT_MULTIPLE_PHY_INIT_DATA_BIN
154 /**
155  * @brief PHY init data control infomation structure
156  */
157 typedef struct {
158     uint8_t control_info_checksum[4];     /*!< 4-byte control infomation checksum */
159     uint8_t multiple_bin_checksum[4];     /*!< 4-byte multiple bin checksum */
160     uint8_t check_algorithm;              /*!< check algorithm */
161     uint8_t version;                      /*!< PHY init data bin version */
162     uint8_t number;                       /*!< PHY init data bin number */
163     uint8_t length[2];                    /*!< Length of each PHY init data bin */
164     uint8_t reserved[19];                 /*!< 19-byte reserved  */
165 } __attribute__ ((packed)) phy_control_info_data_t;
166 
167 /**
168  * @brief Country corresponds to PHY init data type structure
169  */
170 typedef struct {
171     char cc[PHY_COUNTRY_CODE_LEN];
172     uint8_t type;
173 } phy_country_to_bin_type_t;
174 #endif
175 #endif /* PHY_INIT_DATA_H */
176