test_phy_rtc.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. nvs_flash_deinit();
  40. }
  41. static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
  42. {
  43. test_phy_rtc_init();
  44. ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
  45. spi_flash_disable_interrupts_caches_and_other_cpu();
  46. bt_bb_init_cmplx_reg();
  47. spi_flash_enable_interrupts_caches_and_other_cpu();
  48. for (int i = 0; i < 2; i++) {
  49. ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
  50. spi_flash_disable_interrupts_caches_and_other_cpu();
  51. force_wifi_mode(i);
  52. spi_flash_enable_interrupts_caches_and_other_cpu();
  53. ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
  54. spi_flash_disable_interrupts_caches_and_other_cpu();
  55. unforce_wifi_mode();
  56. spi_flash_enable_interrupts_caches_and_other_cpu();
  57. }
  58. ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
  59. spi_flash_disable_interrupts_caches_and_other_cpu();
  60. bt_track_pll_cap();
  61. spi_flash_enable_interrupts_caches_and_other_cpu();
  62. TEST_ASSERT( xSemaphoreGive(semphr_done) );
  63. vTaskDelete(NULL);
  64. }
  65. TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
  66. {
  67. semphr_done = xSemaphoreCreateCounting(1, 0);
  68. xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 2048,
  69. NULL, configMAX_PRIORITIES-1, NULL, 0);
  70. TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
  71. vSemaphoreDelete(semphr_done);
  72. }