diff --git a/components/esp_phy/CMakeLists.txt b/components/esp_phy/CMakeLists.txt index 6b74f3803c..9a83ed4252 100644 --- a/components/esp_phy/CMakeLists.txt +++ b/components/esp_phy/CMakeLists.txt @@ -20,6 +20,10 @@ if(CONFIG_SOC_BT_SUPPORTED OR CONFIG_SOC_IEEE802154_SUPPORTED OR CONFIG_SOC_IEEE list(APPEND srcs "src/btbb_init.c") endif() +if(CONFIG_ESP_PHY_ENABLE_CERT_TEST) + list(APPEND srcs "src/phy_callback.c") +endif() + idf_build_get_property(build_dir BUILD_DIR) if(CONFIG_SOC_WIFI_SUPPORTED) diff --git a/components/esp_phy/include/esp_phy_cert_test.h b/components/esp_phy/include/esp_phy_cert_test.h new file mode 100644 index 0000000000..e9bdef5788 --- /dev/null +++ b/components/esp_phy/include/esp_phy_cert_test.h @@ -0,0 +1,166 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +typedef enum { + //11b + PHY_RATE_1M = 0x0, + PHY_RATE_2M = 0x1, + PHY_RATE_5M5 = 0x2, + PHY_RATE_11M = 0x3, + //11g + PHY_RATE_6M = 0xb, + PHY_RATE_9M = 0xf, + PHY_RATE_12M = 0xa, + PHY_RATE_18M = 0xe, + PHY_RATE_24M = 0x9, + PHY_RATE_36M = 0xd, + PHY_RATE_48M = 0x8, + PHY_RATE_54M = 0xc, + //11n + PHY_RATE_MCS0 = 0x10, + PHY_RATE_MCS1 = 0x11, + PHY_RATE_MCS2 = 0x12, + PHY_RATE_MCS3 = 0x13, + PHY_RATE_MCS4 = 0x14, + PHY_RATE_MCS5 = 0x15, + PHY_RATE_MCS6 = 0x16, + PHY_RATE_MCS7 = 0x17, + PHY_WIFI_RATE_MAX +} esp_phy_wifi_rate_t; + +typedef enum { + PHY_BLE_RATE_1M = 0, + PHY_BLE_RATE_2M, + PHY_BLE_RATE_125K, + PHY_BLE_RATE_500k, + PHY_BLE_RATE_MAX +} esp_phy_ble_rate_t; + +typedef enum { + PHY_BLE_TYPE_1010 = 0, + PHY_BLE_TYPE_00001111 = 1, + PHY_BLE_TYPE_prbs9 = 2, + PHY_BLE_TYPE_00111100 = 4, + PHY_BLE_TYPE_MAX +} esp_phy_ble_type_t; + +/** + * @brief Environment variable configuration + * + * @param conf: + * Setting to 1 to enter RF test environment. + */ +void esp_phy_rftest_config(uint8_t conf); + +/** + * @brief RF initialization configuration + */ +void esp_phy_rftest_init(void); + +/** + * @brief TX Continuous mode + * + * @param contin_en: + * Setting to true for continuous packet sending, which can be used for certification testing; + * Setting to false to cancel continuous mode, which is the default mode and can be used for WLAN tester. +*/ +void esp_phy_tx_contin_en(bool contin_en); + +/** + * @brief HT40/HT20 mode selection + * + * @param en: + * Setting to false to enter 11n HT20 mode; + * Setting to true to enter 11n HT40 mode; + **/ +void esp_phy_cbw40m_en(bool en); + +/** + * @brief Wi-Fi TX command + * + * @param chan: channel setting, 1~14; + * @param rate: rate setting; + * @param backoff: Transmit power attenuation, unit is 0.25dB. For example, 4 means that the power is attenuated by 1dB; + * @param length_byte: TX packet length configuration, indicating PSDU Length, unit is byte; + * @param packet_delay: TX packet interval configuration, unit is us; + * @param packet_num: The number of packets sent, 0 means sending packets continuously, other values represent the number of packets to send. + */ +void esp_phy_wifi_tx(uint32_t chan, esp_phy_wifi_rate_t rate, int8_t backoff, uint32_t length_byte, uint32_t packet_delay, uint32_t packet_num); + +/** + * @brief Test start/stop command, used to stop transmitting or reciving state. + * + * @param value: + * Value should be set to 3 before TX/RX. + * Setting value to 0 to end TX/RX state. + */ +void esp_phy_test_start_stop(uint8_t value); + +/** + * @brief Wi-Fi RX command + * + * @param chan: channel setting, 1~14; + * @param rate: rate setting; + * + */ +void esp_phy_wifi_rx(uint32_t chan, esp_phy_wifi_rate_t rate); + +/** + * @brief Wi-Fi CW TX command + * + * @param start: enable CW, 1 means transmit, 0 means stop transmitting; + * @param chan: CW channel setting, 1~14; + * @param backoff: CW power attenuation parameter, unit is 0.25dB. 4 indicates the power is attenuated by 1dB. + * + */ +void esp_phy_wifi_tx_tone(uint32_t start, uint32_t chan, uint32_t backoff); + +/** + * @brief BLE TX command + * + * @param txpwr: Transmit power level, the level range is 0-15, the unit is 3dB. Level 8 is around 0 dBm; + * @param chan: channel setting, range is 0~39, corresponding frequency = 2402+chan*2; + * @param len: Payload length setting, range is 0-255, unit is byte, 37 bytes is employed generally; + * @param data_type: Data type setting; + * @param syncw: Packet identification (need to be provided by the packet generator or instrument manufacturer), 0x71764129 is employed generally; + * @param rate: rate setting; + * @param tx_num_in: The number of packets sent, 0 means sending packets continuously, other values represent the number of packets to send. + */ +void esp_phy_ble_tx(uint32_t txpwr, uint32_t chan, uint32_t len, esp_phy_ble_type_t data_type, uint32_t syncw, esp_phy_ble_rate_t rate, uint32_t tx_num_in); + +/** + * @brief BLE RX command + * + * @param chan: channel selection, range is 0-39; + * Channels 0, 1, 2~10 correspond to 2404MHz, 2406MHz, 2408MHz~2424MHz respectively; + * Channels 11, 12, 13~36 correspond to 2428MHz, 2430MHz, 2432MHz~2478MHz respectively; + * Channel 37: 2402MHz, Channel 38: 2426MHz, Channel 39: 2480MHz; + * @param syncw: Packet identification (need to be provided by the packet generator or instrument manufacturer), 0x71764129 is employed generally; + * @param rate: rate setting; + */ +void esp_phy_ble_rx(uint32_t chan, uint32_t syncw, esp_phy_ble_rate_t rate); + +/** + * @brief BLE CW TX command + * + * @param start: enable CW, 1 means transmit, 0 means stop transmitting; + * @param chan: Single carrier transmission channel selection, range is 0~39, corresponding frequency freq = 2402+chan*2; + * @param power: CW power attenuation parameter, unit is 0.25dB. 4 indicates the power is attenuated by 1dB. + */ +void esp_phy_bt_tx_tone(uint32_t start, uint32_t chan, uint32_t power); + +#ifdef __cplusplus +} +#endif diff --git a/components/esp_phy/src/phy_callback.c b/components/esp_phy/src/phy_callback.c new file mode 100644 index 0000000000..e05676b39c --- /dev/null +++ b/components/esp_phy/src/phy_callback.c @@ -0,0 +1,44 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +typedef enum { + OK = 0, + FAIL, + PENDING, + BUSY, + CANCEL, +} STATUS; + +extern int phy_printf(const char* format, ...); + +static uint8_t g_rf_cmdstop = 3; + +void esp_phy_test_start_stop(uint8_t value) +{ + g_rf_cmdstop = value; +} + +int esp_phy_cmdstop_callback(void) +{ + return g_rf_cmdstop; +} + +STATUS esp_phy_getstopcmd(void) +{ + uint8_t value = esp_phy_cmdstop_callback(); + if (value == 0) { + return OK; + } else if (value == 1) { + return BUSY; + } else if (value == 2) { + phy_printf("Please run cmdstop to exit current cmd!\n"); + return FAIL; + } else { + return FAIL; + } +}