test_phy_rtc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. //Function just extern, need not test
  15. extern void bt_bb_init_cmplx(void);
  16. extern void IRAM_ATTR spi_flash_disable_interrupts_caches_and_other_cpu();
  17. extern void IRAM_ATTR spi_flash_enable_interrupts_caches_and_other_cpu();
  18. //Functions in librtc.a called by WIFI or Blutooth directly in ISR
  19. extern void bt_bb_init_cmplx_reg(void);
  20. extern void force_wifi_mode(int);
  21. extern void unforce_wifi_mode(void);
  22. extern void bt_track_pll_cap(void);
  23. static const char* TAG = "test_phy_rtc";
  24. static SemaphoreHandle_t semphr_done;
  25. //Functions in libphy.a called by WIFI or Blutooth directly in ISR
  26. static void test_phy_rtc_init(void)
  27. {
  28. esp_err_t ret = nvs_flash_init();
  29. if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
  30. ESP_LOGI(TAG, "no free pages or nvs version mismatch, erase..");
  31. TEST_ESP_OK(nvs_flash_erase());
  32. ret = nvs_flash_init();
  33. }
  34. TEST_ESP_OK(ret);
  35. esp_phy_load_cal_and_init(PHY_BT_MODULE);
  36. esp_phy_load_cal_and_init(PHY_WIFI_MODULE);
  37. //must run here, not blocking in above code
  38. TEST_ASSERT(1);
  39. }
  40. static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
  41. {
  42. test_phy_rtc_init();
  43. ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
  44. spi_flash_disable_interrupts_caches_and_other_cpu();
  45. bt_bb_init_cmplx_reg();
  46. spi_flash_enable_interrupts_caches_and_other_cpu();
  47. for (int i = 0; i < 2; i++) {
  48. ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
  49. spi_flash_disable_interrupts_caches_and_other_cpu();
  50. force_wifi_mode(i);
  51. spi_flash_enable_interrupts_caches_and_other_cpu();
  52. ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
  53. spi_flash_disable_interrupts_caches_and_other_cpu();
  54. unforce_wifi_mode();
  55. spi_flash_enable_interrupts_caches_and_other_cpu();
  56. }
  57. ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
  58. spi_flash_disable_interrupts_caches_and_other_cpu();
  59. bt_track_pll_cap();
  60. spi_flash_enable_interrupts_caches_and_other_cpu();
  61. TEST_ASSERT( xSemaphoreGive(semphr_done) );
  62. vTaskDelete(NULL);
  63. }
  64. TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
  65. {
  66. semphr_done = xSemaphoreCreateCounting(1, 0);
  67. xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 2048,
  68. NULL, configMAX_PRIORITIES-1, NULL, 0);
  69. TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
  70. vSemaphoreDelete(semphr_done);
  71. }