test_phy_rtc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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(ESP32C6)
  16. //IDF-5046
  17. #include "esp_phy_init.h"
  18. //Function just extern, need not test
  19. #if SOC_BT_SUPPORTED
  20. extern void bt_bb_init_cmplx(void);
  21. #endif
  22. extern void IRAM_ATTR spi_flash_disable_interrupts_caches_and_other_cpu(void);
  23. extern void IRAM_ATTR spi_flash_enable_interrupts_caches_and_other_cpu(void);
  24. //Functions in librtc.a called by WIFI or Blutooth directly in ISR
  25. #if SOC_BT_SUPPORTED
  26. extern void bt_track_pll_cap(void);
  27. #endif
  28. static const char* TAG = "test_phy_rtc";
  29. static SemaphoreHandle_t semphr_done;
  30. //Functions in libphy.a called by WIFI or Blutooth directly in ISR
  31. static void test_phy_rtc_init(void)
  32. {
  33. esp_err_t ret = nvs_flash_init();
  34. if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  35. ESP_LOGI(TAG, "no free pages or nvs version mismatch, erase..");
  36. TEST_ESP_OK(nvs_flash_erase());
  37. ret = nvs_flash_init();
  38. }
  39. TEST_ESP_OK(ret);
  40. esp_phy_enable();
  41. //must run here, not blocking in above code
  42. TEST_ASSERT(1);
  43. nvs_flash_deinit();
  44. }
  45. static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
  46. {
  47. //power up wifi and bt mac bb power domain
  48. esp_wifi_power_domain_on();
  49. test_phy_rtc_init();
  50. #if CONFIG_IDF_TARGET_ESP32
  51. extern void force_wifi_mode(int);
  52. extern void unforce_wifi_mode(void);
  53. for (int i = 0; i < 2; i++) {
  54. ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
  55. spi_flash_disable_interrupts_caches_and_other_cpu();
  56. force_wifi_mode(i);
  57. spi_flash_enable_interrupts_caches_and_other_cpu();
  58. ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
  59. spi_flash_disable_interrupts_caches_and_other_cpu();
  60. unforce_wifi_mode();
  61. spi_flash_enable_interrupts_caches_and_other_cpu();
  62. }
  63. #endif //CONFIG_IDF_TARGET_ESP32
  64. #if SOC_BT_SUPPORTED
  65. #if CONFIG_IDF_TARGET_ESP32
  66. /* Only esp32 will call bt_track_pll_cap() in the interrupt
  67. handler, other chips will call this function in the task
  68. */
  69. ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
  70. spi_flash_disable_interrupts_caches_and_other_cpu();
  71. bt_track_pll_cap();
  72. spi_flash_enable_interrupts_caches_and_other_cpu();
  73. extern void bt_bb_init_cmplx_reg(void);
  74. ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
  75. spi_flash_disable_interrupts_caches_and_other_cpu();
  76. bt_bb_init_cmplx_reg();
  77. spi_flash_enable_interrupts_caches_and_other_cpu();
  78. #endif //CONFIG_IDF_TARGET_ESP32
  79. #endif //SOC_BT_SUPPORTED
  80. //power down wifi and bt mac bb power domain
  81. esp_wifi_power_domain_off();
  82. TEST_ASSERT( xSemaphoreGive(semphr_done) );
  83. vTaskDelete(NULL);
  84. }
  85. TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
  86. {
  87. semphr_done = xSemaphoreCreateCounting(1, 0);
  88. xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 3072,
  89. NULL, configMAX_PRIORITIES-1, NULL, 0);
  90. TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
  91. vSemaphoreDelete(semphr_done);
  92. }
  93. #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C6)