1 // Copyright 2015-2017 Espressif Systems (Shanghai) PTE LTD
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <esp_event.h>
18 #include "esp_wifi_internal.h"
23 /* mesh event callback handler */
24 mesh_event_cb_t g_mesh_event_cb = NULL;
26 #ifdef CONFIG_PM_ENABLE
27 static esp_pm_lock_handle_t s_wifi_modem_sleep_lock;
30 static void __attribute__((constructor)) s_set_default_wifi_log_level()
32 /* WiFi libraries aren't compiled to know CONFIG_LOG_DEFAULT_LEVEL,
33 so set it at runtime startup. Done here not in esp_wifi_init() to allow
34 the user to set the level again before esp_wifi_init() is called.
36 esp_log_level_set("wifi", CONFIG_LOG_DEFAULT_LEVEL);
39 esp_err_t esp_wifi_init(const wifi_init_config_t *config)
41 #ifdef CONFIG_PM_ENABLE
42 if (s_wifi_modem_sleep_lock == NULL) {
43 esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "wifi",
44 &s_wifi_modem_sleep_lock);
50 esp_event_set_default_wifi_handlers();
51 return esp_wifi_init_internal(config);
54 #ifdef CONFIG_PM_ENABLE
55 void wifi_apb80m_request(void)
57 assert(s_wifi_modem_sleep_lock);
58 esp_pm_lock_acquire(s_wifi_modem_sleep_lock);
59 if (rtc_clk_apb_freq_get() != APB_CLK_FREQ) {
60 ESP_LOGE(__func__, "WiFi needs 80MHz APB frequency to work, but got %dHz", rtc_clk_apb_freq_get());
64 void wifi_apb80m_release(void)
66 assert(s_wifi_modem_sleep_lock);
67 esp_pm_lock_release(s_wifi_modem_sleep_lock);
69 #endif //CONFIG_PM_ENABLE