P4 fixes
This commit is contained in:
130
resources/espressif__esp_hosted/host/utils/common.c
Normal file
130
resources/espressif__esp_hosted/host/utils/common.c
Normal file
@@ -0,0 +1,130 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/** Includes **/
|
||||
#include "common.h"
|
||||
#include "esp_log.h"
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if 0
|
||||
DEFINE_LOG_TAG(utils);
|
||||
#endif
|
||||
/** Constants/Macros **/
|
||||
|
||||
/** Exported variables **/
|
||||
|
||||
|
||||
/** Function declaration **/
|
||||
|
||||
/** Exported Functions **/
|
||||
/**
|
||||
* @brief debug buffer print
|
||||
* @param buff - input buffer to print in hex
|
||||
* rx_len - buff len
|
||||
* human_str - helping string to describe about buffer
|
||||
* @retval None
|
||||
*/
|
||||
#if DEBUG_HEX_STREAM_PRINT
|
||||
char print_buff[MAX_SPI_BUFFER_SIZE*3];
|
||||
#endif
|
||||
|
||||
uint16_t hton_short (uint16_t x)
|
||||
{
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
return x;
|
||||
#elif BYTE_ORDER == LITTLE_ENDIAN
|
||||
uint16_t val = 0;
|
||||
|
||||
val = (x &0x00FF)<<8;
|
||||
val |= (x &0xFF00)>>8;
|
||||
|
||||
return val;
|
||||
#else
|
||||
# error "not able to identify endianness"
|
||||
#endif
|
||||
}
|
||||
|
||||
uint32_t hton_long (uint32_t x)
|
||||
{
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
return x;
|
||||
#elif BYTE_ORDER == LITTLE_ENDIAN
|
||||
uint32_t val = (x&0xFF000000) >> 24;
|
||||
|
||||
val |= (x&0x00FF0000) >> 8;
|
||||
val |= (x&0x0000FF00) << 8;
|
||||
val |= (x&0x000000FF) << 24;
|
||||
|
||||
return val;
|
||||
#else
|
||||
# error "not able to identify endianness"
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calculate minimum
|
||||
* @param x - number
|
||||
* y - number
|
||||
* @retval minimum
|
||||
*/
|
||||
int min(int x, int y) {
|
||||
return (x < y) ? x : y;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* @brief get numbers from string
|
||||
* @param val - return integer value,
|
||||
* arg - input string
|
||||
* @retval STM_OK on success, else STM_FAIL
|
||||
*/
|
||||
int get_num_from_string(int *val, char *arg)
|
||||
{
|
||||
int base = 10;
|
||||
char *endptr = NULL, *str = NULL;
|
||||
|
||||
if (!arg || (arg[0]=='\0')) {
|
||||
ESP_LOGE(TAG, "No number Identified \n");
|
||||
return STM_FAIL;
|
||||
}
|
||||
|
||||
if (!val) {
|
||||
ESP_LOGE(TAG, "No memory allocated \n");
|
||||
return STM_FAIL;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
str = arg;
|
||||
*val = strtol(str, &endptr, base);
|
||||
|
||||
if (endptr == str) {
|
||||
ESP_LOGE(TAG, "No digits found \n");
|
||||
*val = 0;
|
||||
return STM_FAIL;
|
||||
}
|
||||
|
||||
if ((errno == ERANGE) && ((*val == INT32_MAX) || (*val == INT32_MIN))) {
|
||||
perror("strtol");
|
||||
*val = 0;
|
||||
return STM_FAIL;
|
||||
}
|
||||
|
||||
return STM_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Local functions **/
|
||||
125
resources/espressif__esp_hosted/host/utils/common.h
Normal file
125
resources/espressif__esp_hosted/host/utils/common.h
Normal file
@@ -0,0 +1,125 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/** prevent recursive inclusion **/
|
||||
#ifndef __COMMON_H
|
||||
#define __COMMON_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Includes **/
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "os_wrapper.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_hosted_transport.h"
|
||||
|
||||
|
||||
/** Constants/Macros **/
|
||||
#define MAX_NETWORK_INTERFACES 2
|
||||
#define STA_INTERFACE "ESP_STATION"
|
||||
#define SOFTAP_INTERFACE "ESP_SOFTAP"
|
||||
|
||||
#define UNUSED_VAR(x) (void)(x);
|
||||
|
||||
#define MAX_SPI_BUFFER_SIZE ESP_TRANSPORT_SPI_MAX_BUF_SIZE
|
||||
#define MAX_SDIO_BUFFER_SIZE ESP_TRANSPORT_SDIO_MAX_BUF_SIZE
|
||||
#define MAX_SPI_HD_BUFFER_SIZE ESP_TRANSPORT_SPI_HD_MAX_BUF_SIZE
|
||||
#define MAX_UART_BUFFER_SIZE ESP_TRANSPORT_UART_MAX_BUF_SIZE
|
||||
|
||||
#define MAX_SUPPORTED_SDIO_CLOCK_MHZ 40
|
||||
|
||||
#define IP_ADDR_LEN 4
|
||||
#define MAC_LEN 6
|
||||
#define MIN_MAC_STRING_LEN 17
|
||||
|
||||
#ifndef BIT
|
||||
#define BIT(x) (1UL << (x))
|
||||
#endif
|
||||
|
||||
#define FREQ_IN_MHZ(x) ((x)*1000000)
|
||||
|
||||
#define MHZ_TO_HZ(x) (1000000*(x))
|
||||
|
||||
#define SUCCESS 0
|
||||
#define FAILURE -1
|
||||
|
||||
typedef enum stm_ret_s {
|
||||
STM_OK = 0,
|
||||
STM_FAIL = -1,
|
||||
STM_FAIL_TIMEOUT = -2,
|
||||
STM_FAIL_INVALID_ARG = -3,
|
||||
STM_FAIL_NO_MEMORY = -4,
|
||||
STM_FAIL_NOT_FOUND = -5,
|
||||
STM_FAIL_NOT_FINISHED = -6,
|
||||
STM_FAIL_ALIGNMENT = -7
|
||||
}stm_ret_t;
|
||||
|
||||
typedef enum {
|
||||
TRANSPORT_INACTIVE,
|
||||
TRANSPORT_RX_ACTIVE,
|
||||
TRANSPORT_TX_ACTIVE,
|
||||
} transport_drv_events_e;
|
||||
|
||||
/** Exported Structures **/
|
||||
/* interface header */
|
||||
typedef struct {
|
||||
union {
|
||||
void *priv_buffer_handle;
|
||||
};
|
||||
uint8_t if_type;
|
||||
uint8_t if_num;
|
||||
uint8_t *payload;
|
||||
uint8_t flag;
|
||||
uint16_t payload_len;
|
||||
uint16_t seq_num;
|
||||
/* no need of memcpy at different layers */
|
||||
uint8_t payload_zcopy;
|
||||
|
||||
void (*free_buf_handle)(void *buf_handle);
|
||||
} interface_buffer_handle_t;
|
||||
|
||||
/** Exported variables **/
|
||||
|
||||
/** Exported Functions **/
|
||||
uint16_t hton_short (uint16_t x);
|
||||
uint32_t hton_long (uint32_t x);
|
||||
|
||||
#define ntoh_long hton_long
|
||||
#define ntoh_short hton_short
|
||||
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned long u_long;
|
||||
|
||||
int min(int x, int y);
|
||||
#if 0
|
||||
void hard_delay(int x);
|
||||
int get_num_from_string(int *val, char *arg);
|
||||
#endif
|
||||
|
||||
#define H_FREE_PTR_WITH_FUNC(FreeFunc, FreePtr) do { \
|
||||
if (FreeFunc && FreePtr) { \
|
||||
FreeFunc(FreePtr); \
|
||||
FreePtr = NULL; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
236
resources/espressif__esp_hosted/host/utils/stats.c
Normal file
236
resources/espressif__esp_hosted/host/utils/stats.c
Normal file
@@ -0,0 +1,236 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/** Includes **/
|
||||
|
||||
#include "stats.h"
|
||||
#include "esp_hosted_config.h"
|
||||
#if TEST_RAW_TP
|
||||
#include "os_wrapper.h"
|
||||
#include "transport_drv.h"
|
||||
#endif
|
||||
#include "esp_log.h"
|
||||
#include "esp_hosted_transport_init.h"
|
||||
|
||||
// use mempool and zero copy for Tx
|
||||
#include "mempool.h"
|
||||
|
||||
#if ESP_PKT_STATS
|
||||
struct pkt_stats_t pkt_stats;
|
||||
void *pkt_stats_thread = NULL;
|
||||
extern volatile uint8_t wifi_tx_throttling;
|
||||
#endif
|
||||
|
||||
#if ESP_PKT_STATS || TEST_RAW_TP
|
||||
DEFINE_LOG_TAG(stats);
|
||||
#endif
|
||||
|
||||
/** Constants/Macros **/
|
||||
#define RAW_TP_TX_TASK_STACK_SIZE 2048
|
||||
|
||||
/** Exported variables **/
|
||||
|
||||
/** Function declaration **/
|
||||
|
||||
/** Exported Functions **/
|
||||
|
||||
#if TEST_RAW_TP
|
||||
static int test_raw_tp = 0;
|
||||
static uint8_t log_raw_tp_stats_timer_running = 0;
|
||||
static uint32_t raw_tp_timer_count = 0;
|
||||
void *hosted_timer_handler = NULL;
|
||||
static void * raw_tp_tx_task_id = 0;
|
||||
static uint64_t test_raw_tx_len = 0;
|
||||
static uint64_t test_raw_rx_len = 0;
|
||||
|
||||
static struct mempool * buf_mp_g = NULL;
|
||||
|
||||
void stats_mempool_free(void* ptr)
|
||||
{
|
||||
mempool_free(buf_mp_g, ptr);
|
||||
}
|
||||
|
||||
void test_raw_tp_cleanup(void)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (log_raw_tp_stats_timer_running) {
|
||||
ret = g_h.funcs->_h_timer_stop(hosted_timer_handler);
|
||||
if (!ret) {
|
||||
log_raw_tp_stats_timer_running = 0;
|
||||
}
|
||||
raw_tp_timer_count = 0;
|
||||
}
|
||||
|
||||
if (raw_tp_tx_task_id) {
|
||||
ret = g_h.funcs->_h_thread_cancel(raw_tp_tx_task_id);
|
||||
raw_tp_tx_task_id = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void raw_tp_timer_func(void * arg)
|
||||
{
|
||||
#if USE_FLOATING_POINT
|
||||
double actual_bandwidth_tx = 0;
|
||||
double actual_bandwidth_rx = 0;
|
||||
#else
|
||||
uint64_t actual_bandwidth_tx = 0;
|
||||
uint64_t actual_bandwidth_rx = 0;
|
||||
#endif
|
||||
int32_t div = 1024;
|
||||
|
||||
|
||||
actual_bandwidth_tx = (test_raw_tx_len*8)/TEST_RAW_TP__TIMEOUT;
|
||||
actual_bandwidth_rx = (test_raw_rx_len*8)/TEST_RAW_TP__TIMEOUT;
|
||||
#if USE_FLOATING_POINT
|
||||
ESP_LOGI(TAG, "%lu-%lu sec Tx:%.2f Rx:%.2f kbps\n\r", raw_tp_timer_count, raw_tp_timer_count + TEST_RAW_TP__TIMEOUT, actual_bandwidth_tx/div, actual_bandwidth_rx/div);
|
||||
#else
|
||||
ESP_LOGI(TAG, "%lu-%lu sec Tx:%lu Rx:%lu Kbps", raw_tp_timer_count, raw_tp_timer_count + TEST_RAW_TP__TIMEOUT, (unsigned long)actual_bandwidth_tx/div, (unsigned long)actual_bandwidth_rx/div);
|
||||
#endif
|
||||
raw_tp_timer_count+=TEST_RAW_TP__TIMEOUT;
|
||||
test_raw_tx_len = test_raw_rx_len = 0;
|
||||
}
|
||||
|
||||
static void raw_tp_tx_task(void const* pvParameters)
|
||||
{
|
||||
int ret;
|
||||
static uint16_t seq_num = 0;
|
||||
uint8_t *raw_tp_tx_buf = NULL;
|
||||
uint32_t *ptr = NULL;
|
||||
uint32_t i = 0;
|
||||
g_h.funcs->_h_sleep(5);
|
||||
|
||||
buf_mp_g = mempool_create(MAX_TRANSPORT_BUFFER_SIZE);
|
||||
#ifdef H_USE_MEMPOOL
|
||||
assert(buf_mp_g);
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
|
||||
#if CONFIG_H_LOWER_MEMCOPY
|
||||
raw_tp_tx_buf = (uint8_t*)g_h.funcs->_h_calloc(1, MAX_TRANSPORT_BUFFER_SIZE);
|
||||
|
||||
ptr = (uint32_t*) raw_tp_tx_buf;
|
||||
for (i=0; i<(TEST_RAW_TP__BUF_SIZE/4-1); i++, ptr++)
|
||||
*ptr = 0xBAADF00D;
|
||||
|
||||
ret = esp_hosted_tx(ESP_TEST_IF, 0, raw_tp_tx_buf, TEST_RAW_TP__BUF_SIZE, H_BUFF_ZEROCOPY, H_DEFLT_FREE_FUNC);
|
||||
|
||||
#else
|
||||
raw_tp_tx_buf = mempool_alloc(buf_mp_g, MAX_TRANSPORT_BUFFER_SIZE, true);
|
||||
|
||||
ptr = (uint32_t*) (raw_tp_tx_buf + H_ESP_PAYLOAD_HEADER_OFFSET);
|
||||
for (i=0; i<(TEST_RAW_TP__BUF_SIZE/4-1); i++, ptr++)
|
||||
*ptr = 0xBAADF00D;
|
||||
|
||||
ret = esp_hosted_tx(ESP_TEST_IF, 0, raw_tp_tx_buf, TEST_RAW_TP__BUF_SIZE, H_BUFF_ZEROCOPY, stats_mempool_free);
|
||||
#endif
|
||||
if (ret != STM_OK) {
|
||||
ESP_LOGE(TAG, "Failed to send to queue\n");
|
||||
continue;
|
||||
}
|
||||
#if CONFIG_H_LOWER_MEMCOPY
|
||||
g_h.funcs->_h_free(raw_tp_tx_buf);
|
||||
#endif
|
||||
test_raw_tx_len += (TEST_RAW_TP__BUF_SIZE);
|
||||
seq_num++;
|
||||
}
|
||||
}
|
||||
|
||||
static void process_raw_tp_flags(uint8_t cap)
|
||||
{
|
||||
test_raw_tp_cleanup();
|
||||
|
||||
if (test_raw_tp) {
|
||||
hosted_timer_handler = g_h.funcs->_h_timer_start(TEST_RAW_TP__TIMEOUT,
|
||||
RPC__TIMER_PERIODIC, raw_tp_timer_func, NULL);
|
||||
if (!hosted_timer_handler) {
|
||||
ESP_LOGE(TAG, "Failed to create timer\n\r");
|
||||
return;
|
||||
}
|
||||
log_raw_tp_stats_timer_running = 1;
|
||||
|
||||
ESP_LOGD(TAG, "capabilities: %d", cap);
|
||||
if ((cap & ESP_TEST_RAW_TP__HOST_TO_ESP) ||
|
||||
(cap & ESP_TEST_RAW_TP__BIDIRECTIONAL)) {
|
||||
raw_tp_tx_task_id = g_h.funcs->_h_thread_create("raw_tp_tx", DFLT_TASK_PRIO,
|
||||
RAW_TP_TX_TASK_STACK_SIZE, raw_tp_tx_task, NULL);
|
||||
assert(raw_tp_tx_task_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void start_test_raw_tp(void)
|
||||
{
|
||||
test_raw_tp = 1;
|
||||
}
|
||||
|
||||
static void stop_test_raw_tp(void)
|
||||
{
|
||||
test_raw_tp = 0;
|
||||
}
|
||||
|
||||
void process_test_capabilities(uint8_t cap)
|
||||
{
|
||||
ESP_LOGI(TAG, "ESP peripheral capabilities: 0x%x", cap);
|
||||
if ((cap & ESP_TEST_RAW_TP) == ESP_TEST_RAW_TP) {
|
||||
start_test_raw_tp();
|
||||
ESP_LOGI(TAG, "***** Host Raw throughput Testing (report per %u sec) *****\n\r",TEST_RAW_TP__TIMEOUT);
|
||||
} else {
|
||||
ESP_LOGW(TAG, "Raw Throughput testing not enabled on slave. Stopping test.");
|
||||
stop_test_raw_tp();
|
||||
}
|
||||
process_raw_tp_flags(H_TEST_RAW_TP_DIR);
|
||||
}
|
||||
|
||||
void update_test_raw_tp_rx_len(uint16_t len)
|
||||
{
|
||||
test_raw_rx_len+=(len);
|
||||
}
|
||||
|
||||
#endif
|
||||
#if H_MEM_STATS
|
||||
struct mem_stats h_stats_g;
|
||||
#endif
|
||||
|
||||
#if ESP_PKT_STATS
|
||||
void stats_timer_func(void * arg)
|
||||
{
|
||||
ESP_LOGI(TAG, "slave: sta_rx_in: %lu sta_rx_out: %lu sta_tx_in [pass: %lu drop: %lu] sta_tx_out: %lu, throttling %u",
|
||||
pkt_stats.sta_rx_in,pkt_stats.sta_rx_out,
|
||||
pkt_stats.sta_tx_in_pass, pkt_stats.sta_tx_in_drop, pkt_stats.sta_tx_out,
|
||||
wifi_tx_throttling);
|
||||
ESP_LOGI(TAG, "internal: free %d l-free %d min-free %d, psram: free %d l-free %d min-free %d",
|
||||
heap_caps_get_free_size(MALLOC_CAP_8BIT) - heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT | MALLOC_CAP_INTERNAL),
|
||||
heap_caps_get_free_size(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM),
|
||||
heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM));
|
||||
}
|
||||
#endif
|
||||
|
||||
void create_debugging_tasks(void)
|
||||
{
|
||||
#if ESP_PKT_STATS
|
||||
if (ESP_PKT_STATS_REPORT_INTERVAL) {
|
||||
ESP_LOGI(TAG, "Start Pkt_stats reporting thread [timer: %u sec]", ESP_PKT_STATS_REPORT_INTERVAL);
|
||||
pkt_stats_thread = g_h.funcs->_h_timer_start(ESP_PKT_STATS_REPORT_INTERVAL,
|
||||
RPC__TIMER_PERIODIC, stats_timer_func, NULL);
|
||||
assert(pkt_stats_thread);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
139
resources/espressif__esp_hosted/host/utils/stats.h
Normal file
139
resources/espressif__esp_hosted/host/utils/stats.h
Normal file
@@ -0,0 +1,139 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef __STATS__H
|
||||
#define __STATS__H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "common.h"
|
||||
#include "esp_hosted_config.h"
|
||||
|
||||
/* Stats CONFIG:
|
||||
*
|
||||
* 1. TEST_RAW_TP
|
||||
* These are debug stats which show the raw throughput
|
||||
* performance of transport like SPI or SDIO
|
||||
* (a) TEST_RAW_TP__ESP_TO_HOST
|
||||
* When this enabled, throughput will be measured from ESP to Host
|
||||
*
|
||||
* (b) TEST_RAW_TP__HOST_TO_ESP
|
||||
* This is opposite of TEST_RAW_TP__ESP_TO_HOST. when (a) TEST_RAW_TP__ESP_TO_HOST
|
||||
* is disabled, it will automatically mean throughput to be measured from host to ESP
|
||||
*/
|
||||
#define TEST_RAW_TP H_TEST_RAW_TP
|
||||
|
||||
/* TEST_RAW_TP is disabled on production.
|
||||
* This is only to test the throughout over transport
|
||||
* like SPI or SDIO. In this testing, dummy task will
|
||||
* push the packets over transport.
|
||||
* Currently this testing is possible on one direction
|
||||
* at a time
|
||||
*/
|
||||
|
||||
#if TEST_RAW_TP
|
||||
#include "os_wrapper.h"
|
||||
|
||||
/* Raw throughput is supported only one direction
|
||||
* at a time
|
||||
* i.e. ESP to Host OR
|
||||
* Host to ESP
|
||||
*/
|
||||
#if 0
|
||||
#define TEST_RAW_TP__ESP_TO_HOST 1
|
||||
#define TEST_RAW_TP__HOST_TO_ESP !TEST_RAW_TP__ESP_TO_HOST
|
||||
#endif
|
||||
#define TEST_RAW_TP__TIMEOUT H_RAW_TP_REPORT_INTERVAL
|
||||
|
||||
void update_test_raw_tp_rx_len(uint16_t len);
|
||||
void process_test_capabilities(uint8_t cap);
|
||||
|
||||
/* Please note, this size is to assess transport speed,
|
||||
* so kept maximum possible for that transport
|
||||
*
|
||||
* If you want to compare maximum network throughput and
|
||||
* relevance with max transport speed, Plz lower this value to
|
||||
* UDP: 1460 - H_ESP_PAYLOAD_HEADER_OFFSET = 1460-12=1448
|
||||
* TCP: Find MSS in nodes
|
||||
* H_ESP_PAYLOAD_HEADER_OFFSET is header size, which is not included in calcs
|
||||
*/
|
||||
#define TEST_RAW_TP__BUF_SIZE H_RAW_TP_PKT_LEN
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#if H_PKT_STATS
|
||||
#define ESP_PKT_STATS 1
|
||||
#endif
|
||||
|
||||
#if H_MEM_STATS
|
||||
struct mempool_stats
|
||||
{
|
||||
uint32_t num_fresh_alloc;
|
||||
uint32_t num_reuse;
|
||||
uint32_t num_free;
|
||||
};
|
||||
|
||||
struct spi_stats
|
||||
{
|
||||
int rx_alloc;
|
||||
int rx_freed;
|
||||
int tx_alloc;
|
||||
int tx_dummy_alloc;
|
||||
int tx_freed;
|
||||
};
|
||||
|
||||
struct nw_stats
|
||||
{
|
||||
int tx_alloc;
|
||||
int tx_freed;
|
||||
};
|
||||
|
||||
struct others_stats {
|
||||
int tx_others_freed;
|
||||
};
|
||||
|
||||
struct mem_stats {
|
||||
struct mempool_stats mp_stats;
|
||||
struct spi_stats spi_mem_stats;
|
||||
struct nw_stats nw_mem_stats;
|
||||
struct others_stats others;
|
||||
};
|
||||
|
||||
extern struct mem_stats h_stats_g;
|
||||
#endif
|
||||
|
||||
#if ESP_PKT_STATS
|
||||
#define ESP_PKT_STATS_REPORT_INTERVAL 10
|
||||
struct pkt_stats_t {
|
||||
uint32_t sta_rx_in;
|
||||
uint32_t sta_rx_out;
|
||||
uint32_t sta_tx_in_pass;
|
||||
uint32_t sta_tx_in_drop;
|
||||
uint32_t sta_tx_out;
|
||||
};
|
||||
|
||||
extern struct pkt_stats_t pkt_stats;
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
void create_debugging_tasks(void);
|
||||
|
||||
#endif
|
||||
255
resources/espressif__esp_hosted/host/utils/util.c
Normal file
255
resources/espressif__esp_hosted/host/utils/util.c
Normal file
@@ -0,0 +1,255 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
/** Includes **/
|
||||
#include "util.h"
|
||||
#include "ctype.h"
|
||||
#include "string.h"
|
||||
|
||||
/** Constants/Macros **/
|
||||
|
||||
/** Exported variables **/
|
||||
|
||||
/** Function declaration **/
|
||||
|
||||
/** Exported Functions **/
|
||||
/*
|
||||
* Check whether "cp" is a valid ascii representation
|
||||
* of an Internet address and convert to a binary address.
|
||||
* Returns 1 if the address is valid, 0 if not.
|
||||
* This replaces inet_addr, the return value from which
|
||||
* cannot distinguish between failure and a local broadcast address.
|
||||
*/
|
||||
int ipv4_addr_aton(const char *cp, uint32_t *ip_uint32)
|
||||
{
|
||||
u_long val, base, n;
|
||||
char c;
|
||||
u_long parts[4], *pp = parts;
|
||||
|
||||
for (;;) {
|
||||
/*
|
||||
* Collect number up to ``.''.
|
||||
* Values are specified as for C:
|
||||
* 0x=hex, 0=octal, other=decimal.
|
||||
*/
|
||||
val = 0; base = 10;
|
||||
if (*cp == '0') {
|
||||
if (*++cp == 'x' || *cp == 'X')
|
||||
base = 16, cp++;
|
||||
else
|
||||
base = 8;
|
||||
}
|
||||
while ((c = *cp) != '\0') {
|
||||
if (isascii(c) && isdigit(c)) {
|
||||
val = (val * base) + (c - '0');
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
if (base == 16 && isascii(c) && isxdigit(c)) {
|
||||
val = (val << 4) +
|
||||
(c + 10 - (islower(c) ? 'a' : 'A'));
|
||||
cp++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (*cp == '.') {
|
||||
/*
|
||||
* Internet format:
|
||||
* a.b.c.d
|
||||
* a.b.c (with c treated as 16-bits)
|
||||
* a.b (with b treated as 24 bits)
|
||||
*/
|
||||
if (pp >= parts + 3 || val > 0xff)
|
||||
return (0);
|
||||
*pp++ = val, cp++;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Check for trailing characters.
|
||||
*/
|
||||
if (*cp && (!isascii((uint8_t)*cp) || !isspace((uint8_t)*cp)))
|
||||
return (0);
|
||||
/*
|
||||
* Concoct the address according to
|
||||
* the number of parts specified.
|
||||
*/
|
||||
n = pp - parts + 1;
|
||||
switch (n) {
|
||||
|
||||
case 1: /* a -- 32 bits */
|
||||
break;
|
||||
|
||||
case 2: /* a.b -- 8.24 bits */
|
||||
if (val > 0xffffff)
|
||||
return (0);
|
||||
val |= parts[0] << 24;
|
||||
break;
|
||||
|
||||
case 3: /* a.b.c -- 8.8.16 bits */
|
||||
if (val > 0xffff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16);
|
||||
break;
|
||||
|
||||
case 4: /* a.b.c.d -- 8.8.8.8 bits */
|
||||
if (val > 0xff)
|
||||
return (0);
|
||||
val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
|
||||
break;
|
||||
}
|
||||
if(ip_uint32) {
|
||||
*ip_uint32 = hton_long(val);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief convert ip in int to string
|
||||
*
|
||||
* @param addr ip address in network order to convert
|
||||
* @param buf target buffer where the string is stored
|
||||
* @param buflen length of buf
|
||||
* @return either pointer to buf which now holds the ASCII
|
||||
* representation of addr or NULL if buf was too small
|
||||
*/
|
||||
|
||||
char * ipv4_addr_ntoa(uint32_t addr, char *buf, int buflen)
|
||||
{
|
||||
char inv[3];
|
||||
char *rp;
|
||||
uint8_t *ap;
|
||||
uint8_t rem;
|
||||
uint8_t n;
|
||||
uint8_t i;
|
||||
int len = 0;
|
||||
uint32_t addr_nw = ntoh_long(addr);
|
||||
|
||||
rp = buf;
|
||||
ap = (uint8_t *)&addr_nw;
|
||||
for (n = 0; n < 4; n++) {
|
||||
i = 0;
|
||||
do {
|
||||
rem = *ap % (uint8_t)10;
|
||||
*ap /= (uint8_t)10;
|
||||
inv[i++] = (char)('0' + rem);
|
||||
} while (*ap);
|
||||
while (i--) {
|
||||
if (len++ >= buflen) {
|
||||
return NULL;
|
||||
}
|
||||
*rp++ = inv[i];
|
||||
}
|
||||
if (len++ >= buflen) {
|
||||
return NULL;
|
||||
}
|
||||
*rp++ = '.';
|
||||
ap++;
|
||||
}
|
||||
*--rp = 0;
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Convert mac string to byte stream
|
||||
* @param out - output mac in bytes
|
||||
* s - input mac string
|
||||
* @retval STM_OK/STM_FAIL
|
||||
*/
|
||||
stm_ret_t convert_mac_to_bytes(uint8_t *out, const char *s)
|
||||
{
|
||||
int mac[MAC_LEN] = {0};
|
||||
int num_bytes = 0;
|
||||
|
||||
if (!s || (strlen(s) < MIN_MAC_STRING_LEN)) {
|
||||
return STM_FAIL;
|
||||
}
|
||||
|
||||
num_bytes = sscanf(s, "%2x:%2x:%2x:%2x:%2x:%2x",
|
||||
&mac[0],&mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
|
||||
|
||||
if ((num_bytes < MAC_LEN) ||
|
||||
(mac[0] > 0xFF) ||
|
||||
(mac[1] > 0xFF) ||
|
||||
(mac[2] > 0xFF) ||
|
||||
(mac[3] > 0xFF) ||
|
||||
(mac[4] > 0xFF) ||
|
||||
(mac[5] > 0xFF)) {
|
||||
return STM_FAIL;
|
||||
}
|
||||
|
||||
out[0] = mac[0]&0xff;
|
||||
out[1] = mac[1]&0xff;
|
||||
out[2] = mac[2]&0xff;
|
||||
out[3] = mac[3]&0xff;
|
||||
out[4] = mac[4]&0xff;
|
||||
out[5] = mac[5]&0xff;
|
||||
|
||||
return STM_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief compare two buff in bytes
|
||||
* @param buff1 - in bytes
|
||||
* buff2 - in bytes
|
||||
* @retval 1 if same, else 0
|
||||
*/
|
||||
uint8_t is_same_buff(void *buff1, void *buff2, uint16_t len)
|
||||
{
|
||||
uint16_t idx;
|
||||
uint8_t *b1 = (uint8_t*)buff1;
|
||||
uint8_t *b2 = (uint8_t*)buff2;
|
||||
|
||||
if ((b1 == NULL) && (b2==NULL)) {
|
||||
if(len) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(!b1 || !b2) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Function assumes buff1 and buff2 are allocated for len */
|
||||
for (idx=0; idx < len; idx++) {
|
||||
if (*b1 != *b2) {
|
||||
return 0;
|
||||
}
|
||||
b1++;
|
||||
b2++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get ip in 32bit from dotted string notation
|
||||
* @param ip_s - input ip address in string
|
||||
* ip_x - output ip address in 32 bit
|
||||
* @retval STM_OK/STM_FAIL
|
||||
*/
|
||||
stm_ret_t get_ipaddr_from_str(const char *ip_s, uint32_t *ip_x)
|
||||
{
|
||||
uint32_t ip_nw = 0;
|
||||
if (! ipv4_addr_aton(ip_s, &ip_nw))
|
||||
{
|
||||
return STM_FAIL;
|
||||
}
|
||||
/* ipv4_addr_aton does conversion in network order. reverse */
|
||||
*ip_x = ntoh_long(ip_nw);
|
||||
return STM_OK;
|
||||
}
|
||||
46
resources/espressif__esp_hosted/host/utils/util.h
Normal file
46
resources/espressif__esp_hosted/host/utils/util.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// Copyright 2015-2021 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
/** prevent recursive inclusion **/
|
||||
#ifndef __UTIL_H
|
||||
#define __UTIL_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Includes **/
|
||||
#include "common.h"
|
||||
|
||||
/** Constants/Macros **/
|
||||
|
||||
/** Exported Structures **/
|
||||
|
||||
/** Exported variables **/
|
||||
|
||||
/** Exported Functions **/
|
||||
|
||||
stm_ret_t get_ipaddr_from_str(const char *ip_s, uint32_t *ip_x);
|
||||
int ipv4_addr_aton(const char *cp, uint32_t *ip_uint32);
|
||||
char * ipv4_addr_ntoa(const uint32_t addr, char *buf, int buflen);
|
||||
stm_ret_t convert_mac_to_bytes(uint8_t *out, const char *s);
|
||||
uint8_t is_same_buff(void *buff1, void *buff2, uint16_t len);
|
||||
stm_ret_t get_self_ip(int iface_type, uint32_t *self_ip);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user