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