1 /*
2  * SPDX-FileCopyrightText: 2016-2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef PHY_INIT_DATA_H
8 #define PHY_INIT_DATA_H /* don't use #pragma once here, we compile this file sometimes */
9 #include "esp_phy_init.h"
10 #include "sdkconfig.h"
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 // constrain a value between 'low' and 'high', inclusive
17 #define LIMIT(val, low, high) ((val < low) ? low : (val > high) ? high : val)
18 
19 #define PHY_INIT_MAGIC "PHYINIT"
20 
21 // define the lowest tx power as LOWEST_PHY_TX_POWER
22 #define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 52)
23 #define PHY_TX_POWER_OFFSET 2
24 #define PHY_TX_POWER_NUM    14
25 
26 #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
27 #define PHY_CRC_ALGORITHM 1
28 #define PHY_COUNTRY_CODE_LEN 2
29 #define PHY_INIT_DATA_TYPE_OFFSET 126
30 #define PHY_SUPPORT_MULTIPLE_BIN_OFFSET 125
31 #endif
32 
33 
34 static const char __attribute__((section(".rodata"))) phy_init_magic_pre[] = PHY_INIT_MAGIC;
35 
36 /**
37  * @brief Structure containing default recommended PHY initialization parameters.
38  */
39 static const esp_phy_init_data_t phy_init_data= { {
40         0x01,
41         0x00,
42         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x54),
43         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x54),
44         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50),
45         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50),
46         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x50),
47         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c),
48         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c),
49         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c),
50         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x4c),
51         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x48),
52         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x44),
53         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x3C),
54         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x3C),
55         LIMIT(CONFIG_ESP_PHY_MAX_TX_POWER * 4, 0, 0x3C),
56         0x00,
57         0x00,
58         0x00,
59         0xff,
60         0xff,
61         0xff,
62         0xff,
63         0xff,
64         0xff,
65         0xff,
66         0xff,
67         0xff,
68         0xff,
69         0xff,
70         0xff,
71         0xff,
72         0xff,
73         0xff,
74         0xff,
75         0xff,
76         0xff,
77         0xff,
78         0xff,
79         0xff,
80         0xff,
81         0xff,
82         0xff,
83         0xff,
84         0xff,
85         0xff,
86         0xff,
87         0xff,
88         0xff,
89         0xff,
90         0xff,
91         0xff,
92         0xff,
93         0xff,
94         0xff,
95         0xff,
96         0xff,
97         0xff,
98         0xff,
99         0xff,
100         0xff,
101         0xff,
102         0xff,
103         0xff,
104         0xff,
105         0xff,
106         0xff,
107         0xff,
108         0xff,
109         0xff,
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         0,
150         0,
151         0,
152         0,
153         0,
154         0,
155         0,
156         0,
157         0,
158         0,
159         0,
160         0,
161         0,
162         0,
163         0,
164         0,
165         0,
166         0,
167         0x70
168 } };
169 
170 static const char __attribute__((section(".rodata"))) phy_init_magic_post[] = PHY_INIT_MAGIC;
171 
172 #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN
173 /**
174  * @brief PHY init data control infomation structure
175  */
176 typedef struct {
177     uint8_t control_info_checksum[4];     /*!< 4-byte control infomation checksum */
178     uint8_t multiple_bin_checksum[4];     /*!< 4-byte multiple bin checksum */
179     uint8_t check_algorithm;              /*!< check algorithm */
180     uint8_t version;                      /*!< PHY init data bin version */
181     uint8_t number;                       /*!< PHY init data bin number */
182     uint8_t length[2];                    /*!< Length of each PHY init data bin */
183     uint8_t reserved[19];                 /*!< 19-byte reserved  */
184 } __attribute__ ((packed)) phy_control_info_data_t;
185 
186 /**
187  * @brief Country corresponds to PHY init data type structure
188  */
189 typedef struct {
190     char cc[PHY_COUNTRY_CODE_LEN];
191     uint8_t type;
192 } phy_country_to_bin_type_t;
193 #endif
194 
195 #ifdef __cplusplus
196 }
197 #endif
198 
199 #endif /* PHY_INIT_DATA_H */
200