Merge branch 'master' into feature/cmake

This commit is contained in:
Angus Gratton
2018-09-05 10:35:04 +08:00
committed by Angus Gratton
137 changed files with 4236 additions and 1175 deletions

View File

@@ -646,6 +646,14 @@ config BROWNOUT_DET_LVL
default 7 if BROWNOUT_DET_LVL_SEL_7
#Reduce PHY TX power when brownout reset
config REDUCE_PHY_TX_POWER
bool "Reduce PHY TX power when brownout reset"
depends on BROWNOUT_DET
default y
help
When brownout reset occurs, reduce PHY TX power to keep the code running
# Note about the use of "FRC1" name: currently FRC1 timer is not used for
# high resolution timekeeping anymore. Instead the esp_timer API, implemented
# using FRC2 timer, is used.

View File

@@ -26,6 +26,7 @@
#include "rom/rtc.h"
#include "soc/soc.h"
#include "soc/rtc.h"
#include "soc/rtc_wdt.h"
#include "soc/rtc_cntl_reg.h"
#include "soc/i2s_reg.h"
#include "driver/periph_ctrl.h"
@@ -87,6 +88,18 @@ void esp_clk_init(void)
rtc_clk_fast_freq_set(RTC_FAST_FREQ_8M);
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.
// If the frequency changes from 150kHz to 32kHz, then the timeout set for the WDT will increase 4.6 times.
// Therefore, for the time of frequency change, set a new lower timeout value (1.6 sec).
// This prevents excessive delay before resetting in case the supply voltage is drawdown.
// (If frequency is changed from 150kHz to 32kHz then WDT timeout will increased to 1.6sec * 150/32 = 7.5 sec).
rtc_wdt_protect_off();
rtc_wdt_feed();
rtc_wdt_set_time(RTC_WDT_STAGE0, 1600);
rtc_wdt_protect_on();
#endif
#if defined(CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_CRYSTAL)
select_rtc_slow_clk(SLOW_CLK_32K_XTAL);
#elif defined(CONFIG_ESP32_RTC_CLOCK_SOURCE_EXTERNAL_OSC)
@@ -97,6 +110,14 @@ void esp_clk_init(void)
select_rtc_slow_clk(RTC_SLOW_FREQ_RTC);
#endif
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE
// After changing a frequency WDT timeout needs to be set for new frequency.
rtc_wdt_protect_off();
rtc_wdt_feed();
rtc_wdt_set_time(RTC_WDT_STAGE0, CONFIG_BOOTLOADER_WDT_TIME_MS);
rtc_wdt_protect_on();
#endif
rtc_cpu_freq_config_t old_config, new_config;
rtc_clk_cpu_freq_get_config(&old_config);
const uint32_t old_freq_mhz = old_config.freq_mhz;

View File

@@ -137,7 +137,9 @@ void IRAM_ATTR call_start_cpu0()
|| rst_reas[1] == RTCWDT_SYS_RESET || rst_reas[1] == TG0WDT_SYS_RESET
#endif
) {
#ifndef CONFIG_BOOTLOADER_WDT_ENABLE
rtc_wdt_disable();
#endif
}
//Clear BSS. Please do not attempt to do any complex stuff (like early logging) before this.
@@ -427,9 +429,6 @@ static void do_global_ctors(void)
static void main_task(void* args)
{
// Now that the application is about to start, disable boot watchdogs
REG_CLR_BIT(TIMG_WDTCONFIG0_REG(0), TIMG_WDT_FLASHBOOT_MOD_EN_S);
rtc_wdt_disable();
#if !CONFIG_FREERTOS_UNICORE
// Wait for FreeRTOS initialization to finish on APP CPU, before replacing its startup stack
while (port_xSchedulerRunning[1] == 0) {
@@ -470,6 +469,10 @@ static void main_task(void* args)
}
#endif
// Now that the application is about to start, disable boot watchdog
#ifndef CONFIG_BOOTLOADER_WDT_DISABLE_IN_USER_CODE
rtc_wdt_disable();
#endif
app_main();
vTaskDelete(NULL);
}

View File

@@ -16,6 +16,7 @@
#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <sys/param.h>
#include "esp_attr.h"
#include "esp_clk.h"
#include "soc/wdev_reg.h"
@@ -54,3 +55,16 @@ uint32_t IRAM_ATTR esp_random(void)
last_ccount = ccount;
return result ^ REG_READ(WDEV_RND_REG);
}
void esp_fill_random(void *buf, size_t len)
{
assert(buf != NULL);
uint8_t *buf_bytes = (uint8_t *)buf;
while (len > 0) {
uint32_t word = esp_random();
uint32_t to_copy = MIN(sizeof(word), len);
memcpy(buf_bytes, &word, to_copy);
buf_bytes += to_copy;
len -= to_copy;
}
}

View File

@@ -27,20 +27,20 @@ typedef int32_t esp_err_t;
#define ESP_OK 0 /*!< esp_err_t value indicating success (no error) */
#define ESP_FAIL -1 /*!< Generic esp_err_t code indicating failure */
#define ESP_ERR_NO_MEM 0x101 /*!< Out of memory */
#define ESP_ERR_INVALID_ARG 0x102 /*!< Invalid argument */
#define ESP_ERR_INVALID_STATE 0x103 /*!< Invalid state */
#define ESP_ERR_INVALID_SIZE 0x104 /*!< Invalid size */
#define ESP_ERR_NOT_FOUND 0x105 /*!< Requested resource not found */
#define ESP_ERR_NOT_SUPPORTED 0x106 /*!< Operation or feature not supported */
#define ESP_ERR_TIMEOUT 0x107 /*!< Operation timed out */
#define ESP_ERR_NO_MEM 0x101 /*!< Out of memory */
#define ESP_ERR_INVALID_ARG 0x102 /*!< Invalid argument */
#define ESP_ERR_INVALID_STATE 0x103 /*!< Invalid state */
#define ESP_ERR_INVALID_SIZE 0x104 /*!< Invalid size */
#define ESP_ERR_NOT_FOUND 0x105 /*!< Requested resource not found */
#define ESP_ERR_NOT_SUPPORTED 0x106 /*!< Operation or feature not supported */
#define ESP_ERR_TIMEOUT 0x107 /*!< Operation timed out */
#define ESP_ERR_INVALID_RESPONSE 0x108 /*!< Received response was invalid */
#define ESP_ERR_INVALID_CRC 0x109 /*!< CRC or checksum was invalid */
#define ESP_ERR_INVALID_CRC 0x109 /*!< CRC or checksum was invalid */
#define ESP_ERR_INVALID_VERSION 0x10A /*!< Version was invalid */
#define ESP_ERR_INVALID_MAC 0x10B /*!< MAC address was invalid */
#define ESP_ERR_INVALID_MAC 0x10B /*!< MAC address was invalid */
#define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */
#define ESP_ERR_MESH_BASE 0x4000 /*!< Starting number of MESH error codes */
#define ESP_ERR_WIFI_BASE 0x3000 /*!< Starting number of WiFi error codes */
#define ESP_ERR_MESH_BASE 0x4000 /*!< Starting number of MESH error codes */
/**
* @brief Returns string for esp_err_t error codes

File diff suppressed because it is too large Load Diff

View File

@@ -33,22 +33,20 @@ extern "C" {
* Structures
*******************************************************/
typedef struct {
int scan; /**< minimum scan times before being a root, default:10. */
int vote; /**< max vote times in self-healing, default:1000. */
int fail; /**< parent selection fail times. If the scan times reach this value,
device will disconnect with associated children and join self-healing, default:120. */
int monitor_ie; /**< acceptable times of parent networking IE change before update self networking IE, default:10. */
int scan; /**< minimum scan times before being a root, default:10 */
int vote; /**< max vote times in self-healing, default:1000 */
int fail; /**< parent selection fail times, if the scan times reach this value,
device will disconnect with associated children and join self-healing. default:60 */
int monitor_ie; /**< acceptable times of parent networking IE change before update its own networking IE. default:3 */
} mesh_attempts_t;
typedef struct {
int duration_ms; /* parent weak RSSI monitor duration. If the RSSI with current parent is less than cnx_rssi continuously
within this duration_ms, device will search for a better parent. */
int duration_ms; /* parent weak RSSI monitor duration, if the RSSI continues to be weak during this duration_ms,
device will search for a new parent. */
int cnx_rssi; /* RSSI threshold for keeping a good connection with parent.
If set a value greater than -120 dBm, device will arm a timer to monitor current RSSI at a period time of
duration_ms. */
int select_rssi; /* RSSI threshold for parent selection, should be a value greater than switch_rssi. */
int switch_rssi; /* RSSI threshold for parent switch. Device will disassociate current parent and switch to a new parent when
the RSSI with the new parent is greater than this set threshold. */
If set a value greater than -120 dBm, a timer will be armed to monitor parent RSSI at a period time of duration_ms. */
int select_rssi; /* RSSI threshold for parent selection. It should be a value greater than switch_rssi. */
int switch_rssi; /* Disassociate with current parent and switch to a new parent when the RSSI is greater than this set threshold. */
int backoff_rssi; /* RSSI threshold for connecting to the root */
} mesh_switch_parent_t;
@@ -59,7 +57,7 @@ typedef struct {
} mesh_rssi_threshold_t;
/**
* @brief mesh networking IE
* @brief Mesh networking IE
*/
typedef struct {
/**< mesh networking IE head */
@@ -82,7 +80,7 @@ typedef struct {
uint16_t root_cap; /**< root capacity */
uint16_t self_cap; /**< self capacity */
uint16_t layer2_cap; /**< layer2 capacity */
uint16_t scan_ap_num; /**< the number of scanned APs */
uint16_t scan_ap_num; /**< the number of scanning APs */
int8_t rssi; /**< RSSI of the parent */
int8_t router_rssi; /**< RSSI of the router */
uint8_t flag; /**< flag of networking */
@@ -102,9 +100,9 @@ typedef struct {
* Function Definitions
*******************************************************/
/**
* @brief set mesh softAP beacon interval
* @brief Set mesh softAP beacon interval
*
* @param interval beacon interval(ms) (100ms ~ 60000ms)
* @param[in] interval beacon interval (msecs) (100 msecs ~ 60000 msecs)
*
* @return
* - ESP_OK
@@ -114,9 +112,9 @@ typedef struct {
esp_err_t esp_mesh_set_beacon_interval(int interval_ms);
/**
* @brief get mesh softAP beacon interval
* @brief Get mesh softAP beacon interval
*
* @param interval beacon interval(ms)
* @param[out] interval beacon interval (msecs)
*
* @return
* - ESP_OK
@@ -124,9 +122,9 @@ esp_err_t esp_mesh_set_beacon_interval(int interval_ms);
esp_err_t esp_mesh_get_beacon_interval(int *interval_ms);
/**
* @brief set attempts for mesh self-organized networking
* @brief Set attempts for mesh self-organized networking
*
* @param attempts
* @param[in] attempts
*
* @return
* - ESP_OK
@@ -135,9 +133,9 @@ esp_err_t esp_mesh_get_beacon_interval(int *interval_ms);
esp_err_t esp_mesh_set_attempts(mesh_attempts_t *attempts);
/**
* @brief get attempts for mesh self-organized networking
* @brief Get attempts for mesh self-organized networking
*
* @param attempts
* @param[out] attempts
*
* @return
* - ESP_OK
@@ -146,9 +144,9 @@ esp_err_t esp_mesh_set_attempts(mesh_attempts_t *attempts);
esp_err_t esp_mesh_get_attempts(mesh_attempts_t *attempts);
/**
* @brief set parameters for parent switch
* @brief Set parameters for parent switch
*
* @param paras parameters for parent switch
* @param[in] paras parameters for parent switch
*
* @return
* - ESP_OK
@@ -157,9 +155,9 @@ esp_err_t esp_mesh_get_attempts(mesh_attempts_t *attempts);
esp_err_t esp_mesh_set_switch_parent_paras(mesh_switch_parent_t *paras);
/**
* @brief get parameters for parent switch
* @brief Get parameters for parent switch
*
* @param paras parameters for parent switch
* @param[out] paras parameters for parent switch
*
* @return
* - ESP_OK
@@ -168,12 +166,12 @@ esp_err_t esp_mesh_set_switch_parent_paras(mesh_switch_parent_t *paras);
esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
/**
* @brief set RSSI threshold
* The default high RSSI threshold value is -78 dBm.
* The default medium RSSI threshold value is -82 dBm.
* The default low RSSI threshold value is -85 dBm.
* @brief Set RSSI threshold
* - The default high RSSI threshold value is -78 dBm.
* - The default medium RSSI threshold value is -82 dBm.
* - The default low RSSI threshold value is -85 dBm.
*
* @param threshold RSSI threshold
* @param[in] threshold RSSI threshold
*
* @return
* - ESP_OK
@@ -182,8 +180,9 @@ esp_err_t esp_mesh_get_switch_parent_paras(mesh_switch_parent_t *paras);
esp_err_t esp_mesh_set_rssi_threshold(const mesh_rssi_threshold_t *threshold);
/**
* @brief get RSSI threshold
* @param threshold RSSI threshold
* @brief Get RSSI threshold
*
* @param[out] threshold RSSI threshold
*
* @return
* - ESP_OK
@@ -192,11 +191,11 @@ esp_err_t esp_mesh_set_rssi_threshold(const mesh_rssi_threshold_t *threshold);
esp_err_t esp_mesh_get_rssi_threshold(mesh_rssi_threshold_t *threshold);
/**
* @brief enable the minimum rate to 6Mbps
* @brief Enable the minimum rate to 6 Mbps
*
* @attention This API shall be called before WiFi start.
* @attention This API shall be called before Wi-Fi is started.
*
* @param is_6m enable or not
* @param[in] is_6m enable or not
*
* @return
* - ESP_OK
@@ -204,7 +203,7 @@ esp_err_t esp_mesh_get_rssi_threshold(mesh_rssi_threshold_t *threshold);
esp_err_t esp_mesh_set_6m_rate(bool is_6m);
/**
* @brief print the number of txQ waiting
* @brief Print the number of txQ waiting
*
* @return
* - ESP_OK
@@ -213,7 +212,7 @@ esp_err_t esp_mesh_set_6m_rate(bool is_6m);
esp_err_t esp_mesh_print_txQ_waiting(void);
/**
* @brief print the number of rxQ waiting
* @brief Print the number of rxQ waiting
*
* @return
* - ESP_OK
@@ -222,9 +221,9 @@ esp_err_t esp_mesh_print_txQ_waiting(void);
esp_err_t esp_mesh_print_rxQ_waiting(void);
/**
* @brief set passive scan time
* @brief Set passive scan time
*
* @param interval_ms passive scan time(ms)
* @param[in] interval_ms passive scan time (msecs)
*
* @return
* - ESP_OK
@@ -234,19 +233,19 @@ esp_err_t esp_mesh_print_rxQ_waiting(void);
esp_err_t esp_mesh_set_passive_scan_time(int time_ms);
/**
* @brief get passive scan time
* @brief Get passive scan time
*
* @return interval_ms passive scan time(ms)
* @return interval_ms passive scan time (msecs)
*/
int esp_mesh_get_passive_scan_time(void);
/**
* @brief set announce interval
* The default short interval is 500 milliseconds.
* The default long interval is 3000 milliseconds.
* @brief Set announce interval
* - The default short interval is 500 milliseconds.
* - The default long interval is 3000 milliseconds.
*
* @param short_ms shall be greater than the default value
* @param long_ms shall be greater than the default value
* @param[in] short_ms shall be greater than the default value
* @param[in] long_ms shall be greater than the default value
*
* @return
* - ESP_OK
@@ -254,10 +253,10 @@ int esp_mesh_get_passive_scan_time(void);
esp_err_t esp_mesh_set_announce_interval(int short_ms, int long_ms);
/**
* @brief get announce interval
* @brief Get announce interval
*
* @param short_ms short interval
* @param long_ms long interval
* @param[out] short_ms short interval
* @param[out] long_ms long interval
*
* @return
* - ESP_OK

View File

@@ -151,18 +151,31 @@ uint32_t esp_get_minimum_free_heap_size( void );
/**
* @brief Get one random 32-bit word from hardware RNG
*
* The hardware RNG is fully functional whenever an RF subsystem is running (ie Bluetooth or WiFi is enabled). For secure
* The hardware RNG is fully functional whenever an RF subsystem is running (ie Bluetooth or WiFi is enabled). For
* random values, call this function after WiFi or Bluetooth are started.
*
* When the app is running without an RF subsystem enabled, it should be considered a PRNG. To help improve this
* situation, the RNG is pre-seeded with entropy while the IDF bootloader is running. However no new entropy is
* available during the window of time between when the bootloader exits and an RF subsystem starts. It may be possible
* to discern a non-random pattern in a very large amount of output captured during this window of time.
* If the RF subsystem is not used by the program, the function bootloader_random_enable() can be called to enable an
* entropy source. bootloader_random_disable() must be called before RF subsystem or I2S peripheral are used. See these functions'
* documentation for more details.
*
* Any time the app is running without an RF subsystem (or bootloader_random) enabled, RNG hardware should be
* considered a PRNG. A very small amount of entropy is available due to pre-seeding while the IDF
* bootloader is running, but this should not be relied upon for any use.
*
* @return Random value between 0 and UINT32_MAX
*/
uint32_t esp_random(void);
/**
* @brief Fill a buffer with random bytes from hardware RNG
*
* @note This function has the same restrictions regarding available entropy as esp_random()
*
* @param buf Pointer to buffer to fill with random numbers.
* @param len Length of buffer in bytes
*/
void esp_fill_random(void *buf, size_t len);
/**
* @brief Set base MAC address with the MAC address which is stored in BLK3 of EFUSE or
* external storage e.g. flash and EEPROM.

View File

@@ -223,7 +223,9 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config);
*
* @attention 1. This API should be called if you want to remove WiFi driver from the system
*
* @return ESP_OK: succeed
* @return
* - ESP_OK: succeed
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init
*/
esp_err_t esp_wifi_deinit(void);

View File

@@ -272,6 +272,9 @@ PROVIDE ( r_E1 = 0x400108e8 );
PROVIDE ( r_E21 = 0x40010968 );
PROVIDE ( r_E22 = 0x400109b4 );
PROVIDE ( r_E3 = 0x40010a58 );
PROVIDE ( lm_n192_mod_mul = 0x40011dc0 );
PROVIDE ( lm_n192_mod_add = 0x40011e9c );
PROVIDE ( lm_n192_mod_sub = 0x40011eec );
PROVIDE ( r_ea_alarm_clear = 0x40015ab4 );
PROVIDE ( r_ea_alarm_set = 0x40015a10 );
PROVIDE ( _read_r = 0x4000bda8 );
@@ -301,6 +304,7 @@ PROVIDE ( r_ecc_gen_new_public_key = 0x400170c0 );
PROVIDE ( r_ecc_gen_new_secret_key = 0x400170e4 );
PROVIDE ( r_ecc_get_debug_Keys = 0x40017224 );
PROVIDE ( r_ecc_init = 0x40016dbc );
PROVIDE ( ecc_point_multiplication_uint8_256 = 0x40016804);
PROVIDE ( RecvBuff = 0x3ffe009c );
PROVIDE ( r_em_buf_init = 0x4001729c );
PROVIDE ( r_em_buf_rx_buff_addr_get = 0x400173e8 );
@@ -599,6 +603,14 @@ PROVIDE ( r_lc_util_get_offset_clke = 0x4002f538 );
PROVIDE ( r_lc_util_get_offset_clkn = 0x4002f51c );
PROVIDE ( r_lc_util_set_loc_trans_coll = 0x4002f500 );
PROVIDE ( r_lc_version = 0x40020a30 );
PROVIDE ( lc_set_encap_pdu_data_p192 = 0x4002e4c8 );
PROVIDE ( lc_set_encap_pdu_data_p256 = 0x4002e454 );
PROVIDE ( lm_get_auth_method = 0x40023420);
PROVIDE ( lmp_accepted_ext_handler = 0x40027290 );
PROVIDE ( lmp_not_accepted_ext_handler = 0x40029c54 );
PROVIDE ( lmp_clk_adj_handler = 0x40027468 );
PROVIDE ( lmp_clk_adj_ack_handler = 0x400274f4 );
PROVIDE ( lm_get_auth_method = 0x40023420);
PROVIDE ( lmp_accepted_ext_handler = 0x40027290 );
PROVIDE ( lmp_not_accepted_ext_handler = 0x40029c54 );
PROVIDE ( lmp_clk_adj_handler = 0x40027468 );

View File

@@ -531,6 +531,18 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
return err;
}
#if CONFIG_REDUCE_PHY_TX_POWER
static void esp_phy_reduce_tx_power(esp_phy_init_data_t* init_data)
{
uint8_t i;
for(i = 0; i < PHY_TX_POWER_NUM; i++) {
// LOWEST_PHY_TX_POWER is the lowest tx power
init_data->params[PHY_TX_POWER_OFFSET+i] = PHY_TX_POWER_LOWEST;
}
}
#endif
void esp_phy_load_cal_and_init(phy_rf_module_t module)
{
esp_phy_calibration_data_t* cal_data =
@@ -540,11 +552,30 @@ void esp_phy_load_cal_and_init(phy_rf_module_t module)
abort();
}
#if CONFIG_REDUCE_PHY_TX_POWER
const esp_phy_init_data_t* phy_init_data = esp_phy_get_init_data();
if (phy_init_data == NULL) {
ESP_LOGE(TAG, "failed to obtain PHY init data");
abort();
}
esp_phy_init_data_t* init_data = (esp_phy_init_data_t*) malloc(sizeof(esp_phy_init_data_t));
if (init_data == NULL) {
ESP_LOGE(TAG, "failed to allocate memory for phy init data");
abort();
}
memcpy(init_data, phy_init_data, sizeof(esp_phy_init_data_t));
if (esp_reset_reason() == ESP_RST_BROWNOUT) {
esp_phy_reduce_tx_power(init_data);
}
#else
const esp_phy_init_data_t* init_data = esp_phy_get_init_data();
if (init_data == NULL) {
ESP_LOGE(TAG, "failed to obtain PHY init data");
abort();
}
#endif
#ifdef CONFIG_ESP32_PHY_CALIBRATION_AND_DATA_STORAGE
esp_phy_calibration_mode_t calibration_mode = PHY_RF_CAL_PARTIAL;
@@ -571,7 +602,12 @@ void esp_phy_load_cal_and_init(phy_rf_module_t module)
esp_phy_rf_init(init_data, PHY_RF_CAL_FULL, cal_data, module);
#endif
#if CONFIG_REDUCE_PHY_TX_POWER
esp_phy_release_init_data(phy_init_data);
free(init_data);
#else
esp_phy_release_init_data(init_data);
#endif
free(cal_data); // PHY maintains a copy of calibration data, so we can free this
}

View File

@@ -22,6 +22,11 @@
#define PHY_INIT_MAGIC "PHYINIT"
// define the lowest tx power as LOWEST_PHY_TX_POWER
#define PHY_TX_POWER_LOWEST LIMIT(CONFIG_ESP32_PHY_MAX_TX_POWER * 4, 0, 52)
#define PHY_TX_POWER_OFFSET 44
#define PHY_TX_POWER_NUM 5
static const char phy_init_magic_pre[] = PHY_INIT_MAGIC;
/**

View File

@@ -185,7 +185,7 @@ esp_err_t esp_spiram_reserve_dma_pool(size_t size) {
return ESP_ERR_NO_MEM;
}
uint32_t caps[] = { MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL, 0, MALLOC_CAP_8BIT|MALLOC_CAP_32BIT };
uint32_t caps[] = { 0, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL, MALLOC_CAP_8BIT|MALLOC_CAP_32BIT };
esp_err_t e = heap_caps_add_region_with_caps(caps, (intptr_t) dma_heap, (intptr_t) dma_heap+next_size-1);
if (e != ESP_OK) {
return e;

View File

@@ -6,6 +6,7 @@
#include "esp_system.h"
#include "esp_event_loop.h"
#include "esp_wifi.h"
#include "esp_wifi_types.h"
#include "esp_log.h"
#include "nvs_flash.h"
@@ -42,6 +43,11 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
static void test_wifi_init_deinit(wifi_init_config_t *cfg, wifi_config_t* wifi_config)
{
ESP_LOGI(TAG, EMPH_STR("esp_wifi_deinit"));
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_INIT, esp_wifi_deinit());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_get_mode"));
wifi_mode_t mode_get;
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_INIT, esp_wifi_get_mode(&mode_get));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_mode"));
@@ -54,6 +60,8 @@ static void test_wifi_init_deinit(wifi_init_config_t *cfg, wifi_config_t* wifi_c
static void test_wifi_start_stop(wifi_init_config_t *cfg, wifi_config_t* wifi_config)
{
ESP_LOGI(TAG, EMPH_STR("esp_wifi_stop"));
TEST_ESP_ERR(ESP_ERR_WIFI_NOT_INIT, esp_wifi_stop());
ESP_LOGI(TAG, EMPH_STR("esp_wifi_init"));
TEST_ESP_OK(esp_wifi_init(cfg));
ESP_LOGI(TAG, EMPH_STR("esp_wifi_set_mode"));

View File

@@ -0,0 +1,67 @@
#include <stdio.h>
#include <string.h>
#include "unity.h"
#include "esp_system.h"
/* Note: these are just sanity tests, not the same as
entropy tests
*/
TEST_CASE("call esp_random()", "[random]")
{
const size_t NUM_RANDOM = 128; /* in most cases this is massive overkill */
uint32_t zeroes = UINT32_MAX;
uint32_t ones = 0;
for (int i = 0; i < NUM_RANDOM - 1; i++) {
uint32_t r = esp_random();
ones |= r;
zeroes &= ~r;
}
/* assuming a 'white' random distribution, we can expect
usually at least one time each bit will be zero and at
least one time each will be one. Statistically this
can still fail, just *very* unlikely to. */
TEST_ASSERT_EQUAL_HEX32(0, zeroes);
TEST_ASSERT_EQUAL_HEX32(UINT32_MAX, ones);
}
TEST_CASE("call esp_fill_random()", "[random]")
{
const size_t NUM_BUF = 200;
const size_t BUF_SZ = 16;
uint8_t buf[NUM_BUF][BUF_SZ];
uint8_t zero_buf[BUF_SZ];
uint8_t one_buf[BUF_SZ];
bzero(buf, sizeof(buf));
bzero(one_buf, sizeof(zero_buf));
memset(zero_buf, 0xFF, sizeof(one_buf));
for (int i = 0; i < NUM_BUF; i++) {
esp_fill_random(buf[i], BUF_SZ);
}
/* No two 128-bit buffers should be the same
(again, statistically this could happen but it's very unlikely) */
for (int i = 0; i < NUM_BUF; i++) {
for (int j = 0; j < NUM_BUF; j++) {
if (i != j) {
TEST_ASSERT_NOT_EQUAL(0, memcmp(buf[i], buf[j], BUF_SZ));
}
}
}
/* Do the same all bits are zero and one at least once test across the buffers */
for (int i = 0; i < NUM_BUF; i++) {
for (int x = 0; x < BUF_SZ; x++) {
zero_buf[x] &= ~buf[i][x];
one_buf[x] |= buf[i][x];
}
}
for (int x = 0; x < BUF_SZ; x++) {
TEST_ASSERT_EQUAL_HEX8(0, zero_buf[x]);
TEST_ASSERT_EQUAL_HEX8(0xFF, one_buf[x]);
}
}