test_phy_rtc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 "esp_phy_init.h"
  11. #include <freertos/FreeRTOS.h>
  12. #include <freertos/task.h>
  13. #include <freertos/semphr.h>
  14. #include "soc/soc_caps.h"
  15. #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2BETA)
  16. //Function just extern, need not test
  17. #ifdef SOC_BT_SUPPORTED
  18. extern void bt_bb_init_cmplx(void);
  19. #endif
  20. extern void IRAM_ATTR spi_flash_disable_interrupts_caches_and_other_cpu(void);
  21. extern void IRAM_ATTR spi_flash_enable_interrupts_caches_and_other_cpu(void);
  22. //Functions in librtc.a called by WIFI or Blutooth directly in ISR
  23. #ifdef SOC_BT_SUPPORTED
  24. extern void bt_bb_init_cmplx_reg(void);
  25. extern void bt_track_pll_cap(void);
  26. #endif
  27. extern void force_wifi_mode(int);
  28. extern void unforce_wifi_mode(void);
  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. test_phy_rtc_init();
  49. for (int i = 0; i < 2; i++) {
  50. ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
  51. spi_flash_disable_interrupts_caches_and_other_cpu();
  52. force_wifi_mode(i);
  53. spi_flash_enable_interrupts_caches_and_other_cpu();
  54. ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
  55. spi_flash_disable_interrupts_caches_and_other_cpu();
  56. unforce_wifi_mode();
  57. spi_flash_enable_interrupts_caches_and_other_cpu();
  58. }
  59. #ifdef SOC_BT_SUPPORTED
  60. ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
  61. spi_flash_disable_interrupts_caches_and_other_cpu();
  62. bt_bb_init_cmplx_reg();
  63. spi_flash_enable_interrupts_caches_and_other_cpu();
  64. ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
  65. spi_flash_disable_interrupts_caches_and_other_cpu();
  66. bt_track_pll_cap();
  67. spi_flash_enable_interrupts_caches_and_other_cpu();
  68. #endif
  69. TEST_ASSERT( xSemaphoreGive(semphr_done) );
  70. vTaskDelete(NULL);
  71. }
  72. TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
  73. {
  74. semphr_done = xSemaphoreCreateCounting(1, 0);
  75. xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 2048,
  76. NULL, configMAX_PRIORITIES-1, NULL, 0);
  77. TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
  78. vSemaphoreDelete(semphr_done);
  79. }
  80. #endif