test_phy_rtc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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/wifi.h"
  15. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
  16. //IDF-5046
  17. #include "esp_phy_init.h"
  18. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32C3)
  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. esp_phy_enable();
  42. //must run here, not blocking in above code
  43. TEST_ASSERT(1);
  44. nvs_flash_deinit();
  45. }
  46. static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
  47. {
  48. //power up wifi and bt mac bb power domain
  49. esp_wifi_power_domain_on();
  50. test_phy_rtc_init();
  51. #if CONFIG_IDF_TARGET_ESP32
  52. extern void force_wifi_mode(int);
  53. extern void unforce_wifi_mode(void);
  54. for (int i = 0; i < 2; i++) {
  55. ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
  56. spi_flash_disable_interrupts_caches_and_other_cpu();
  57. force_wifi_mode(i);
  58. spi_flash_enable_interrupts_caches_and_other_cpu();
  59. ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
  60. spi_flash_disable_interrupts_caches_and_other_cpu();
  61. unforce_wifi_mode();
  62. spi_flash_enable_interrupts_caches_and_other_cpu();
  63. }
  64. #endif //CONFIG_IDF_TARGET_ESP32
  65. #if SOC_BT_SUPPORTED
  66. ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
  67. spi_flash_disable_interrupts_caches_and_other_cpu();
  68. bt_track_pll_cap();
  69. spi_flash_enable_interrupts_caches_and_other_cpu();
  70. #if CONFIG_IDF_TARGET_ESP32
  71. extern void bt_bb_init_cmplx_reg(void);
  72. ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
  73. spi_flash_disable_interrupts_caches_and_other_cpu();
  74. bt_bb_init_cmplx_reg();
  75. spi_flash_enable_interrupts_caches_and_other_cpu();
  76. #endif //CONFIG_IDF_TARGET_ESP32
  77. #if CONFIG_IDF_TARGET_ESP32C3
  78. extern void bt_bb_v2_init_cmplx(int print_version);
  79. ESP_LOGI(TAG, "Test bt_bb_v2_init_cmplx()...");
  80. spi_flash_disable_interrupts_caches_and_other_cpu();
  81. bt_bb_v2_init_cmplx(0);
  82. spi_flash_enable_interrupts_caches_and_other_cpu();
  83. extern void coex_pti_v2(void);
  84. ESP_LOGI(TAG, "Test coex_pti_v2()...");
  85. spi_flash_disable_interrupts_caches_and_other_cpu();
  86. coex_pti_v2();
  87. spi_flash_enable_interrupts_caches_and_other_cpu();
  88. #endif //CONFIG_IDF_TARGET_ESP32C3
  89. #endif //SOC_BT_SUPPORTED
  90. //power down wifi and bt mac bb power domain
  91. esp_wifi_power_domain_off();
  92. TEST_ASSERT( xSemaphoreGive(semphr_done) );
  93. vTaskDelete(NULL);
  94. }
  95. TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
  96. {
  97. semphr_done = xSemaphoreCreateCounting(1, 0);
  98. xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 3072,
  99. NULL, configMAX_PRIORITIES-1, NULL, 0);
  100. TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
  101. vSemaphoreDelete(semphr_done);
  102. }
  103. #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)
  104. #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)