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 #include "esp_private/wifi.h"
16
17 #if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2, ESP32C3)
18
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
26 //Functions in librtc.a called by WIFI or Blutooth directly in ISR
27 #if SOC_BT_SUPPORTED
28 extern void bt_track_pll_cap(void);
29 #endif
30
31
32 static const char* TAG = "test_phy_rtc";
33
34 static SemaphoreHandle_t semphr_done;
35
36 //Functions in libphy.a called by WIFI or Blutooth directly in ISR
test_phy_rtc_init(void)37 static void test_phy_rtc_init(void)
38 {
39 esp_err_t ret = nvs_flash_init();
40 if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
41 ESP_LOGI(TAG, "no free pages or nvs version mismatch, erase..");
42 TEST_ESP_OK(nvs_flash_erase());
43 ret = nvs_flash_init();
44 }
45 TEST_ESP_OK(ret);
46
47 esp_phy_enable();
48
49 //must run here, not blocking in above code
50 TEST_ASSERT(1);
51 nvs_flash_deinit();
52 }
53
test_phy_rtc_cache_task(void * arg)54 static IRAM_ATTR void test_phy_rtc_cache_task(void *arg)
55 {
56 //power up wifi and bt mac bb power domain
57 esp_wifi_power_domain_on();
58
59 test_phy_rtc_init();
60
61 #if CONFIG_IDF_TARGET_ESP32
62 extern void force_wifi_mode(int);
63 extern void unforce_wifi_mode(void);
64
65 for (int i = 0; i < 2; i++) {
66 ESP_LOGI(TAG, "Test force_wifi_mode(%d)...", i);
67 spi_flash_disable_interrupts_caches_and_other_cpu();
68 force_wifi_mode(i);
69 spi_flash_enable_interrupts_caches_and_other_cpu();
70
71 ESP_LOGI(TAG, "Test unforce_wifi_mode()...");
72 spi_flash_disable_interrupts_caches_and_other_cpu();
73 unforce_wifi_mode();
74 spi_flash_enable_interrupts_caches_and_other_cpu();
75 }
76 #endif //CONFIG_IDF_TARGET_ESP32
77
78 #if SOC_BT_SUPPORTED
79
80 ESP_LOGI(TAG, "Test bt_track_pll_cap()...");
81 spi_flash_disable_interrupts_caches_and_other_cpu();
82 bt_track_pll_cap();
83 spi_flash_enable_interrupts_caches_and_other_cpu();
84
85 #if CONFIG_IDF_TARGET_ESP32
86 extern void bt_bb_init_cmplx_reg(void);
87 ESP_LOGI(TAG, "Test bt_bb_init_cmplx_reg()...");
88 spi_flash_disable_interrupts_caches_and_other_cpu();
89 bt_bb_init_cmplx_reg();
90 spi_flash_enable_interrupts_caches_and_other_cpu();
91 #endif //CONFIG_IDF_TARGET_ESP32
92
93 #if CONFIG_IDF_TARGET_ESP32C3
94 extern void bt_bb_v2_init_cmplx(int print_version);
95 ESP_LOGI(TAG, "Test bt_bb_v2_init_cmplx()...");
96 spi_flash_disable_interrupts_caches_and_other_cpu();
97 bt_bb_v2_init_cmplx(0);
98 spi_flash_enable_interrupts_caches_and_other_cpu();
99
100 extern void coex_pti_v2(void);
101 ESP_LOGI(TAG, "Test coex_pti_v2()...");
102 spi_flash_disable_interrupts_caches_and_other_cpu();
103 coex_pti_v2();
104 spi_flash_enable_interrupts_caches_and_other_cpu();
105 #endif //CONFIG_IDF_TARGET_ESP32C3
106
107 #endif //SOC_BT_SUPPORTED
108
109 //power down wifi and bt mac bb power domain
110 esp_wifi_power_domain_off();
111
112 TEST_ASSERT( xSemaphoreGive(semphr_done) );
113
114 vTaskDelete(NULL);
115 }
116
117 TEST_CASE("Test PHY/RTC functions called when cache is disabled", "[phy_rtc][cache_disabled]")
118 {
119 semphr_done = xSemaphoreCreateCounting(1, 0);
120
121 xTaskCreatePinnedToCore(test_phy_rtc_cache_task, "phy_rtc_test_task", 3072,
122 NULL, configMAX_PRIORITIES-1, NULL, 0);
123
124 TEST_ASSERT( xSemaphoreTake(semphr_done, portMAX_DELAY) );
125
126 vSemaphoreDelete(semphr_done);
127 }
128 #endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32S2)
129