test_phy_rtc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. Tests for the Wi-Fi
  3. */
  4. #include "string.h"
  5. #include "esp_system.h"
  6. #include "unity.h"
  7. #include "esp_log.h"
  8. #include "nvs_flash.h"
  9. #include "test_utils.h"
  10. #include <freertos/FreeRTOS.h>
  11. #include <freertos/task.h>
  12. #include <freertos/semphr.h>
  13. #include "soc/soc_caps.h"
  14. #include "esp_private/esp_modem_clock.h"
  15. #include "esp_private/wifi.h"
  16. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32H2)
  17. //IDF-5046
  18. #include "esp_phy_init.h"
  19. //Function just extern, need not test
  20. #if SOC_BT_SUPPORTED
  21. extern void bt_bb_init_cmplx(void);
  22. #endif
  23. extern void IRAM_ATTR spi_flash_disable_interrupts_caches_and_other_cpu(void);
  24. extern void IRAM_ATTR spi_flash_enable_interrupts_caches_and_other_cpu(void);
  25. //Functions in librtc.a called by WIFI or Blutooth directly in ISR
  26. #if SOC_BT_SUPPORTED
  27. extern void bt_track_pll_cap(void);
  28. #endif
  29. static const char* TAG = "test_phy_rtc";
  30. static SemaphoreHandle_t semphr_done;
  31. //Functions in libphy.a called by WIFI or Blutooth directly in ISR
  32. static void test_phy_rtc_init(void)
  33. {
  34. esp_err_t ret = nvs_flash_init();
  35. if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  36. ESP_LOGI(TAG, "no free pages or nvs version mismatch, erase..");
  37. TEST_ESP_OK(nvs_flash_erase());
  38. ret = nvs_flash_init();
  39. }
  40. TEST_ESP_OK(ret);
  41. #if CONFIG_ESP_WIFI_ENABLED
  42. esp_phy_enable(PHY_MODEM_WIFI);
  43. #endif
  44. #if CONFIG_BT_ENABLED
  45. esp_phy_enable(PHY_MODEM_BT);
  46. #endif
  47. #if CONFIG_IEEE802154_ENABLED
  48. esp_phy_enable(PHY_MODEM_IEEE802154);
  49. #endif
  50. //must run here, not blocking in above code
  51. TEST_ASSERT(1);
  52. nvs_flash_deinit();
  53. }
  54. static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
  55. {
  56. //power up wifi and bt mac bb power domain
  57. esp_wifi_power_domain_on();
  58. #if CONFIG_IDF_TARGET_ESP32C6
  59. modem_clock_module_enable(PERIPH_PHY_MODULE);
  60. #endif // CONFIG_IDF_TARGET_ESP32C6
  61. test_phy_rtc_init();
  62. #if CONFIG_IDF_TARGET_ESP32
  63. extern void force_wifi_mode(int);
  64. extern void unforce_wifi_mode(void);
  65. for (int i = 0; i < 2; i++) {
  66. ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
  67. spi_flash_disable_interrupts_caches_and_other_cpu();
  68. force_wifi_mode(i);
  69. spi_flash_enable_interrupts_caches_and_other_cpu();
  70. ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
  71. spi_flash_disable_interrupts_caches_and_other_cpu();
  72. unforce_wifi_mode();
  73. spi_flash_enable_interrupts_caches_and_other_cpu();
  74. }
  75. #endif //CONFIG_IDF_TARGET_ESP32
  76. #if SOC_BT_SUPPORTED
  77. #if CONFIG_IDF_TARGET_ESP32
  78. /* Only esp32 will call bt_track_pll_cap() in the interrupt
  79. handler, other chips will call this function in the task
  80. */
  81. ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
  82. spi_flash_disable_interrupts_caches_and_other_cpu();
  83. bt_track_pll_cap();
  84. spi_flash_enable_interrupts_caches_and_other_cpu();
  85. extern void bt_bb_init_cmplx_reg(void);
  86. ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
  87. spi_flash_disable_interrupts_caches_and_other_cpu();
  88. bt_bb_init_cmplx_reg();
  89. spi_flash_enable_interrupts_caches_and_other_cpu();
  90. #endif //CONFIG_IDF_TARGET_ESP32
  91. #endif //SOC_BT_SUPPORTED
  92. #if CONFIG_IDF_TARGET_ESP32C6
  93. modem_clock_module_disable(PERIPH_PHY_MODULE);
  94. #endif // CONFIG_IDF_TARGET_ESP32C6
  95. //power down wifi and bt mac bb power domain
  96. esp_wifi_power_domain_off();
  97. TEST_ASSERT( xSemaphoreGive(semphr_done) );
  98. vTaskDelete(NULL);
  99. }
  100. TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
  101. {
  102. semphr_done = xSemaphoreCreateCounting(1, 0);
  103. xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 3072,
  104. NULL, configMAX_PRIORITIES-1, NULL, 0);
  105. TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
  106. vSemaphoreDelete(semphr_done);
  107. }
  108. #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)