wifi_init.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2015-2017 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. #include <esp_event.h>
  15. #include <esp_wifi.h>
  16. #include "esp_log.h"
  17. #include "esp_wifi_internal.h"
  18. #include "esp_pm.h"
  19. #include "soc/rtc.h"
  20. #ifdef CONFIG_PM_ENABLE
  21. static esp_pm_lock_handle_t s_wifi_modem_sleep_lock;
  22. #endif
  23. esp_err_t esp_wifi_init(const wifi_init_config_t *config)
  24. {
  25. #ifdef CONFIG_PM_ENABLE
  26. if (s_wifi_modem_sleep_lock == NULL) {
  27. esp_err_t err = esp_pm_lock_create(ESP_PM_APB_FREQ_MAX, 0, "wifi",
  28. &s_wifi_modem_sleep_lock);
  29. if (err != ESP_OK) {
  30. return err;
  31. }
  32. }
  33. #endif
  34. esp_event_set_default_wifi_handlers();
  35. return esp_wifi_init_internal(config);
  36. }
  37. #ifdef CONFIG_PM_ENABLE
  38. void wifi_apb80m_request(void)
  39. {
  40. assert(s_wifi_modem_sleep_lock);
  41. esp_pm_lock_acquire(s_wifi_modem_sleep_lock);
  42. if (rtc_clk_apb_freq_get() != APB_CLK_FREQ) {
  43. ESP_LOGE(__func__, "WiFi needs 80MHz APB frequency to work, but got %dHz", rtc_clk_apb_freq_get());
  44. }
  45. }
  46. void wifi_apb80m_release(void)
  47. {
  48. assert(s_wifi_modem_sleep_lock);
  49. esp_pm_lock_release(s_wifi_modem_sleep_lock);
  50. }
  51. #endif //CONFIG_PM_ENABLE