30
30
#include "internal/phy_init_data.h"
31
31
#include "phy.h"
32
32
33
- static const char * TAG = "phy_init" ;
33
+ static const char * TAG = "phy_init" ;
34
34
35
- static uint8_t phy_check_calibration_data (uint8_t * rf_cal_data )
35
+ static uint8_t phy_check_calibration_data (uint8_t * rf_cal_data )
36
36
{
37
37
#define CHECK_NUM 26
38
38
#define CHIP_ID_L 24
39
39
#define CHIP_ID_H 25
40
40
41
41
uint8_t i ;
42
- uint32_t * cal_data_word = (uint32_t * )rf_cal_data ;
42
+ uint32_t * cal_data_word = (uint32_t * )rf_cal_data ;
43
43
uint32_t check_sum = 0 ;
44
44
45
45
/* L: flag_1[79:76], version[59:56], mac_map[55:48], mac_l[47:24] */
46
46
uint32_t chip_id_l = ((REG_READ (0x3FF00058 ) & 0xF000 ) << 16 ) |
47
- (REG_READ (0x3ff00054 ) & 0xFFFFFFF );
47
+ (REG_READ (0x3ff00054 ) & 0xFFFFFFF );
48
48
/* H: mac_l[31:24], mac_h[119:96] */
49
49
uint32_t chip_id_h = (REG_READ (0x3FF00050 ) & 0xFF000000 ) |
50
- (REG_READ (0x3ff0005C ) & 0xFFFFFF );
50
+ (REG_READ (0x3ff0005C ) & 0xFFFFFF );
51
51
52
52
cal_data_word [CHIP_ID_L ] = chip_id_l ;
53
53
cal_data_word [CHIP_ID_H ] = chip_id_h ;
@@ -63,12 +63,12 @@ static uint8_t phy_check_calibration_data(uint8_t *rf_cal_data)
63
63
/* ToDo: use rx_gain_dc_table in nvs, need to modify internal libraries */
64
64
uint32_t rx_gain_dc_table [125 ];
65
65
66
- esp_err_t esp_phy_rf_init (const esp_phy_init_data_t * init_data , esp_phy_calibration_mode_t mode ,
67
- esp_phy_calibration_data_t * calibration_data , phy_rf_module_t module )
66
+ esp_err_t esp_phy_rf_init (const esp_phy_init_data_t * init_data , esp_phy_calibration_mode_t mode ,
67
+ esp_phy_calibration_data_t * calibration_data , phy_rf_module_t module )
68
68
{
69
69
esp_err_t status = ESP_OK ;
70
70
uint8_t sta_mac [6 ];
71
- uint8_t * local_init_data = calloc (1 , 256 );
71
+ uint8_t * local_init_data = calloc (1 , 256 );
72
72
#ifdef CONFIG_CONSOLE_UART_BAUDRATE
73
73
const uint32_t uart_baudrate = CONFIG_CONSOLE_UART_BAUDRATE ;
74
74
#else
@@ -77,10 +77,10 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t *init_data, esp_phy_calibrat
77
77
78
78
memcpy (local_init_data , init_data -> params , 128 );
79
79
80
- extern uint32_t * phy_rx_gain_dc_table ;
80
+ extern uint32_t * phy_rx_gain_dc_table ;
81
81
phy_rx_gain_dc_table = calibration_data -> rx_gain_dc_table ;
82
82
uint8_t cal_data_check = phy_check_calibration_data (calibration_data -> rf_cal_data ) ||
83
- phy_check_data_table (phy_rx_gain_dc_table , 125 , 1 );
83
+ phy_check_data_table (phy_rx_gain_dc_table , 125 , 1 );
84
84
85
85
phy_afterwake_set_rfoption (1 );
86
86
@@ -90,8 +90,8 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t *init_data, esp_phy_calibrat
90
90
91
91
esp_efuse_mac_get_default (sta_mac );
92
92
chip_init (local_init_data , sta_mac , uart_baudrate );
93
- ESP_LOGI (TAG , "phy ver: %d_%d" , (READ_PERI_REG (0x6000107C )>> 16 )& 0xFFF , READ_PERI_REG (0x6000107C )>> 28 );
94
- get_data_from_rtc ((uint8_t * )calibration_data );
93
+ ESP_LOGI (TAG , "phy ver: %d_%d" , (READ_PERI_REG (0x6000107C ) >> 16 ) & 0xFFF , READ_PERI_REG (0x6000107C ) >> 28 );
94
+ get_data_from_rtc ((uint8_t * )calibration_data );
95
95
96
96
memcpy (rx_gain_dc_table , calibration_data -> rx_gain_dc_table , 4 * 125 );
97
97
phy_rx_gain_dc_table = rx_gain_dc_table ;
@@ -101,9 +101,11 @@ esp_err_t esp_phy_rf_init(const esp_phy_init_data_t *init_data, esp_phy_calibrat
101
101
if (cal_data_check == ESP_CAL_DATA_CHECK_FAIL ) {
102
102
#ifdef CONFIG_ESP_PHY_CALIBRATION_AND_DATA_STORAGE
103
103
ESP_LOGW (TAG , "saving new calibration data because of checksum failure, mode(%d)" , mode );
104
+
104
105
if (mode != PHY_RF_CAL_FULL ) {
105
106
esp_phy_store_cal_data_to_nvs (calibration_data );
106
107
}
108
+
107
109
#endif
108
110
}
109
111
@@ -121,9 +123,9 @@ esp_err_t esp_phy_rf_deinit(phy_rf_module_t module)
121
123
#if CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
122
124
#include "esp_partition.h"
123
125
124
- const esp_phy_init_data_t * esp_phy_get_init_data ()
126
+ const esp_phy_init_data_t * esp_phy_get_init_data ()
125
127
{
126
- const esp_partition_t * partition = esp_partition_find_first (
128
+ const esp_partition_t * partition = esp_partition_find_first (
127
129
ESP_PARTITION_TYPE_DATA , ESP_PARTITION_SUBTYPE_DATA_PHY , NULL );
128
130
129
131
if (partition == NULL ) {
@@ -134,7 +136,7 @@ const esp_phy_init_data_t *esp_phy_get_init_data()
134
136
ESP_LOGD (TAG , "loading PHY init data from partition at offset 0x%x" , partition -> address );
135
137
size_t init_data_store_length = sizeof (phy_init_magic_pre ) +
136
138
sizeof (esp_phy_init_data_t ) + sizeof (phy_init_magic_post );
137
- uint8_t * init_data_store = (uint8_t * ) malloc (init_data_store_length );
139
+ uint8_t * init_data_store = (uint8_t * ) malloc (init_data_store_length );
138
140
139
141
if (init_data_store == NULL ) {
140
142
ESP_LOGE (TAG , "failed to allocate memory for PHY init data" );
@@ -156,43 +158,43 @@ const esp_phy_init_data_t *esp_phy_get_init_data()
156
158
}
157
159
158
160
ESP_LOGD (TAG , "PHY data partition validated" );
159
- return (const esp_phy_init_data_t * )(init_data_store + sizeof (phy_init_magic_pre ));
161
+ return (const esp_phy_init_data_t * )(init_data_store + sizeof (phy_init_magic_pre ));
160
162
}
161
163
162
- void esp_phy_release_init_data (const esp_phy_init_data_t * init_data )
164
+ void esp_phy_release_init_data (const esp_phy_init_data_t * init_data )
163
165
{
164
- free ((uint8_t * ) init_data - sizeof (phy_init_magic_pre ));
166
+ free ((uint8_t * ) init_data - sizeof (phy_init_magic_pre ));
165
167
}
166
168
167
169
#else // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
168
170
169
171
// phy_init_data.h will declare static 'phy_init_data' variable initialized with default init data
170
172
171
- const esp_phy_init_data_t * esp_phy_get_init_data ()
173
+ const esp_phy_init_data_t * esp_phy_get_init_data ()
172
174
{
173
175
ESP_LOGD (TAG , "loading PHY init data from application binary" );
174
176
return & phy_init_data ;
175
177
}
176
178
177
- void esp_phy_release_init_data (const esp_phy_init_data_t * init_data )
179
+ void esp_phy_release_init_data (const esp_phy_init_data_t * init_data )
178
180
{
179
181
// no-op
180
182
}
181
183
#endif // CONFIG_ESP_PHY_INIT_DATA_IN_PARTITION
182
184
183
185
184
186
// PHY calibration data handling functions
185
- static const char * PHY_NAMESPACE = "phy" ;
186
- static const char * PHY_CAL_DATA_KEY = "cal_data" ;
187
- static const char * PHY_RX_GAIN_DC_TABLE_KEY = "dc_table" ;
187
+ static const char * PHY_NAMESPACE = "phy" ;
188
+ static const char * PHY_CAL_DATA_KEY = "cal_data" ;
189
+ static const char * PHY_RX_GAIN_DC_TABLE_KEY = "dc_table" ;
188
190
189
191
static esp_err_t load_cal_data_from_nvs_handle (nvs_handle handle ,
190
- esp_phy_calibration_data_t * out_cal_data );
192
+ esp_phy_calibration_data_t * out_cal_data );
191
193
192
194
static esp_err_t store_cal_data_to_nvs_handle (nvs_handle handle ,
193
- const esp_phy_calibration_data_t * cal_data );
195
+ const esp_phy_calibration_data_t * cal_data );
194
196
195
- esp_err_t esp_phy_load_cal_data_from_nvs (esp_phy_calibration_data_t * out_cal_data )
197
+ esp_err_t esp_phy_load_cal_data_from_nvs (esp_phy_calibration_data_t * out_cal_data )
196
198
{
197
199
nvs_handle handle ;
198
200
esp_err_t err = nvs_open (PHY_NAMESPACE , NVS_READONLY , & handle );
@@ -210,7 +212,7 @@ esp_err_t esp_phy_load_cal_data_from_nvs(esp_phy_calibration_data_t *out_cal_dat
210
212
return err ;
211
213
}
212
214
213
- esp_err_t esp_phy_store_cal_data_to_nvs (const esp_phy_calibration_data_t * cal_data )
215
+ esp_err_t esp_phy_store_cal_data_to_nvs (const esp_phy_calibration_data_t * cal_data )
214
216
{
215
217
nvs_handle handle ;
216
218
esp_err_t err = nvs_open (PHY_NAMESPACE , NVS_READWRITE , & handle );
@@ -226,7 +228,7 @@ esp_err_t esp_phy_store_cal_data_to_nvs(const esp_phy_calibration_data_t *cal_da
226
228
}
227
229
228
230
static esp_err_t load_cal_data_from_nvs_handle (nvs_handle handle ,
229
- esp_phy_calibration_data_t * out_cal_data )
231
+ esp_phy_calibration_data_t * out_cal_data )
230
232
{
231
233
esp_err_t err ;
232
234
@@ -261,7 +263,7 @@ static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
261
263
}
262
264
263
265
static esp_err_t store_cal_data_to_nvs_handle (nvs_handle handle ,
264
- const esp_phy_calibration_data_t * cal_data )
266
+ const esp_phy_calibration_data_t * cal_data )
265
267
{
266
268
esp_err_t err ;
267
269
@@ -290,15 +292,15 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
290
292
291
293
void esp_phy_load_cal_and_init (phy_rf_module_t module )
292
294
{
293
- esp_phy_calibration_data_t * cal_data =
294
- (esp_phy_calibration_data_t * ) calloc (sizeof (esp_phy_calibration_data_t ), 1 );
295
+ esp_phy_calibration_data_t * cal_data =
296
+ (esp_phy_calibration_data_t * ) calloc (sizeof (esp_phy_calibration_data_t ), 1 );
295
297
296
298
if (cal_data == NULL ) {
297
299
ESP_LOGE (TAG , "failed to allocate memory for RF calibration data" );
298
300
abort ();
299
301
}
300
302
301
- const esp_phy_init_data_t * init_data = esp_phy_get_init_data ();
303
+ const esp_phy_init_data_t * init_data = esp_phy_get_init_data ();
302
304
303
305
if (init_data == NULL ) {
304
306
ESP_LOGE (TAG , "failed to obtain PHY init data" );
@@ -335,3 +337,26 @@ void esp_phy_load_cal_and_init(phy_rf_module_t module)
335
337
336
338
free (cal_data ); // PHY maintains a copy of calibration data, so we can free this
337
339
}
340
+
341
+ uint16_t esp_wifi_get_vdd33 (void )
342
+ {
343
+ if (phy_init_data .params [107 ] != 0xFF ) {
344
+ ESP_LOGE (TAG , "Please set VDD33 const to 0xff" );
345
+ return 0xFFFF ;
346
+ }
347
+
348
+ extern uint16_t phy_get_vdd33 ();
349
+ uint16_t ret = phy_get_vdd33 ();
350
+
351
+ if (ret != 0xFFFF ) {
352
+ ret = ret * 12 / 11 ;
353
+ }
354
+
355
+ return ret ;
356
+ }
357
+
358
+ void esp_wifi_set_max_tx_power_via_vdd33 (uint16_t vdd33 )
359
+ {
360
+ extern void phy_vdd33_set_tpw (uint16_t vdd33 );
361
+ phy_vdd33_set_tpw (vdd33 );
362
+ }
0 commit comments