test_phy_rtc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. 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. #if CONFIG_IDF_TARGET_ESP32C6
  51. modem_clock_module_enable(PERIPH_PHY_MODULE);
  52. #endif // CONFIG_IDF_TARGET_ESP32C6
  53. test_phy_rtc_init();
  54. #if CONFIG_IDF_TARGET_ESP32
  55. extern void force_wifi_mode(int);
  56. extern void unforce_wifi_mode(void);
  57. for (int i = 0; i < 2; i++) {
  58. ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
  59. spi_flash_disable_interrupts_caches_and_other_cpu();
  60. force_wifi_mode(i);
  61. spi_flash_enable_interrupts_caches_and_other_cpu();
  62. ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
  63. spi_flash_disable_interrupts_caches_and_other_cpu();
  64. unforce_wifi_mode();
  65. spi_flash_enable_interrupts_caches_and_other_cpu();
  66. }
  67. #endif //CONFIG_IDF_TARGET_ESP32
  68. #if SOC_BT_SUPPORTED
  69. #if CONFIG_IDF_TARGET_ESP32
  70. /* Only esp32 will call bt_track_pll_cap() in the interrupt
  71. handler, other chips will call this function in the task
  72. */
  73. ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
  74. spi_flash_disable_interrupts_caches_and_other_cpu();
  75. bt_track_pll_cap();
  76. spi_flash_enable_interrupts_caches_and_other_cpu();
  77. extern void bt_bb_init_cmplx_reg(void);
  78. ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
  79. spi_flash_disable_interrupts_caches_and_other_cpu();
  80. bt_bb_init_cmplx_reg();
  81. spi_flash_enable_interrupts_caches_and_other_cpu();
  82. #endif //CONFIG_IDF_TARGET_ESP32
  83. #endif //SOC_BT_SUPPORTED
  84. #if CONFIG_IDF_TARGET_ESP32C6
  85. modem_clock_module_disable(PERIPH_PHY_MODULE);
  86. #endif // CONFIG_IDF_TARGET_ESP32C6
  87. //power down wifi and bt mac bb power domain
  88. esp_wifi_power_domain_off();
  89. TEST_ASSERT( xSemaphoreGive(semphr_done) );
  90. vTaskDelete(NULL);
  91. }
  92. TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
  93. {
  94. semphr_done = xSemaphoreCreateCounting(1, 0);
  95. xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 3072,
  96. NULL, configMAX_PRIORITIES-1, NULL, 0);
  97. TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
  98. vSemaphoreDelete(semphr_done);
  99. }
  100. #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)