Merge branch 'master' of https://gitlab.espressif.cn:6688/idf/esp-idf into feature/docs_setup_sphinx
This commit is contained in:
commit
00a81564f0
90 changed files with 3340 additions and 721 deletions
|
@ -22,6 +22,12 @@ config ESP32_APPTRACE_ENABLE
|
|||
help
|
||||
Enables/disable application tracing module.
|
||||
|
||||
config ESP32_APPTRACE_LOCK_ENABLE
|
||||
bool
|
||||
default !SYSVIEW_ENABLE
|
||||
help
|
||||
Enables/disable application tracing module internal sync lock.
|
||||
|
||||
config ESP32_APPTRACE_ONPANIC_HOST_FLUSH_TMO
|
||||
int "Timeout for flushing last trace data to host on panic"
|
||||
depends on ESP32_APPTRACE_ENABLE
|
||||
|
|
|
@ -103,7 +103,8 @@
|
|||
// that task/ISR will fail to complete filling its data chunk before the whole trace block is exposed to the host. To handle such conditions tracing
|
||||
// module prepends all user data chunks with header which contains allocated buffer size and actual data length within it. OpenOCD command
|
||||
// which reads application traces reports error when it reads incompleted user data block.
|
||||
// Data which are transfered from host to target are also prepended with such header.
|
||||
// Data which are transfered from host to target are also prepended with a header. Down channel data header is simple and consists of one two bytes field
|
||||
// containing length of host data following the heder.
|
||||
|
||||
// 4.3 Data Buffering
|
||||
// ------------------
|
||||
|
@ -159,14 +160,10 @@
|
|||
#include "soc/dport_reg.h"
|
||||
#include "eri.h"
|
||||
#include "trax.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/task.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
#include "soc/timer_group_reg.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "esp_app_trace.h"
|
||||
#include "esp_app_trace_util.h"
|
||||
|
||||
#if CONFIG_ESP32_APPTRACE_ENABLE
|
||||
#define ESP_APPTRACE_MAX_VPRINTF_ARGS 256
|
||||
|
@ -174,7 +171,7 @@
|
|||
|
||||
#define ESP_APPTRACE_PRINT_LOCK 0
|
||||
|
||||
#define LOG_LOCAL_LEVEL ESP_LOG_ERROR
|
||||
#define LOG_LOCAL_LEVEL CONFIG_LOG_DEFAULT_LEVEL
|
||||
#include "esp_log.h"
|
||||
const static char *TAG = "esp_apptrace";
|
||||
|
||||
|
@ -244,17 +241,13 @@ static volatile uint8_t *s_trax_blocks[] = {
|
|||
|
||||
#define ESP_APPTRACE_TRAX_BLOCKS_NUM (sizeof(s_trax_blocks)/sizeof(s_trax_blocks[0]))
|
||||
|
||||
#define ESP_APPTRACE_TRAX_BLOCK_SIZE 0x4000UL
|
||||
|
||||
#define ESP_APPTRACE_TRAX_INBLOCK_START 0
|
||||
|
||||
#define ESP_APPTRACE_TRAX_INBLOCK_MARKER() (s_trace_buf.trax.state.markers[s_trace_buf.trax.state.in_block % 2])
|
||||
#define ESP_APPTRACE_TRAX_INBLOCK_MARKER_UPD(_v_) do {s_trace_buf.trax.state.markers[s_trace_buf.trax.state.in_block % 2] += (_v_);}while(0)
|
||||
#define ESP_APPTRACE_TRAX_INBLOCK_GET() (&s_trace_buf.trax.blocks[s_trace_buf.trax.state.in_block % 2])
|
||||
|
||||
//TODO: menuconfig
|
||||
#define ESP_APPTRACE_DOWN_BUF_SIZE 32UL
|
||||
|
||||
#define ESP_APPTRACE_TRAX_BLOCK_SIZE (0x4000UL)
|
||||
#if CONFIG_SYSVIEW_ENABLE
|
||||
#define ESP_APPTRACE_USR_DATA_LEN_MAX 255UL
|
||||
#else
|
||||
|
@ -324,7 +317,6 @@ typedef struct {
|
|||
// ring buffer control struct for data from host (down buffer)
|
||||
esp_apptrace_rb_t rb_down;
|
||||
// storage for above ring buffer data
|
||||
uint8_t down_buf[ESP_APPTRACE_DOWN_BUF_SIZE + 1];
|
||||
esp_apptrace_trax_data_t trax; // TRAX HW transport data
|
||||
} esp_apptrace_buffer_t;
|
||||
|
||||
|
@ -334,13 +326,15 @@ static esp_apptrace_buffer_t s_trace_buf;
|
|||
static esp_apptrace_lock_t s_log_lock = {.irq_stat = 0, .portmux = portMUX_INITIALIZER_UNLOCKED};
|
||||
#endif
|
||||
|
||||
static uint16_t esp_apptrace_trax_write_down_buffer_nolock(uint8_t *data, uint16_t size);
|
||||
static esp_err_t esp_apptrace_trax_flush(uint32_t min_sz, uint32_t tmo);
|
||||
static uint32_t esp_apptrace_trax_down_buffer_write_nolock(uint8_t *data, uint32_t size);
|
||||
static esp_err_t esp_apptrace_trax_flush(uint32_t min_sz, esp_apptrace_tmo_t *tmo);
|
||||
|
||||
static inline int esp_apptrace_log_lock()
|
||||
{
|
||||
#if ESP_APPTRACE_PRINT_LOCK
|
||||
int ret = esp_apptrace_lock_take(&s_log_lock, ESP_APPTRACE_TMO_INFINITE);
|
||||
esp_apptrace_tmo_t tmo;
|
||||
esp_apptrace_tmo_init(&tmo, ESP_APPTRACE_TMO_INFINITE);
|
||||
int ret = esp_apptrace_lock_take(&s_log_lock, &tmo);
|
||||
return ret;
|
||||
#else
|
||||
return 0;
|
||||
|
@ -354,40 +348,26 @@ static inline void esp_apptrace_log_unlock()
|
|||
#endif
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_lock_initialize()
|
||||
static inline esp_err_t esp_apptrace_lock_initialize()
|
||||
{
|
||||
#if CONFIG_SYSVIEW_ENABLE == 0
|
||||
#if CONFIG_ESP32_APPTRACE_LOCK_ENABLE
|
||||
esp_apptrace_lock_init(&s_trace_buf.lock);
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t inline esp_apptrace_lock_cleanup()
|
||||
static inline esp_err_t esp_apptrace_lock_cleanup()
|
||||
{
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_lock(uint32_t *tmo)
|
||||
esp_err_t esp_apptrace_lock(esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
#if CONFIG_SYSVIEW_ENABLE == 0
|
||||
unsigned cur, elapsed, start = xthal_get_ccount();
|
||||
|
||||
esp_err_t ret = esp_apptrace_lock_take(&s_trace_buf.lock, *tmo);
|
||||
#if CONFIG_ESP32_APPTRACE_LOCK_ENABLE
|
||||
esp_err_t ret = esp_apptrace_lock_take(&s_trace_buf.lock, tmo);
|
||||
if (ret != ESP_OK) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
// decrease tmo by actual waiting time
|
||||
cur = xthal_get_ccount();
|
||||
if (start <= cur) {
|
||||
elapsed = cur - start;
|
||||
} else {
|
||||
elapsed = ULONG_MAX - start + cur;
|
||||
}
|
||||
if (ESP_APPTRACE_CPUTICKS2US(elapsed) > *tmo) {
|
||||
*tmo = 0;
|
||||
} else {
|
||||
*tmo -= ESP_APPTRACE_CPUTICKS2US(elapsed);
|
||||
}
|
||||
#endif
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -395,7 +375,7 @@ esp_err_t esp_apptrace_lock(uint32_t *tmo)
|
|||
esp_err_t esp_apptrace_unlock()
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
#if CONFIG_SYSVIEW_ENABLE == 0
|
||||
#if CONFIG_ESP32_APPTRACE_LOCK_ENABLE
|
||||
ret = esp_apptrace_lock_give(&s_trace_buf.lock);
|
||||
#endif
|
||||
return ret;
|
||||
|
@ -476,7 +456,8 @@ static esp_err_t esp_apptrace_trax_block_switch()
|
|||
uint32_t host_to_read = ESP_APPTRACE_TRAX_BLOCK_LEN_GET(ctrl_reg);
|
||||
if (host_to_read != 0 || acked_block != (s_trace_buf.trax.state.in_block & ESP_APPTRACE_TRAX_BLOCK_ID_MSK)) {
|
||||
ESP_APPTRACE_LOGD("HC[%d]: Can not switch %x %d %x %x/%lx, m %d", xPortGetCoreID(), ctrl_reg, host_to_read, acked_block,
|
||||
s_trace_buf.trax.state.in_block & ESP_APPTRACE_TRAX_BLOCK_ID_MSK, s_trace_buf.trax.state.in_block, s_trace_buf.trax.state.markers[prev_block_num]);
|
||||
s_trace_buf.trax.state.in_block & ESP_APPTRACE_TRAX_BLOCK_ID_MSK, s_trace_buf.trax.state.in_block,
|
||||
s_trace_buf.trax.state.markers[prev_block_num]);
|
||||
res = ESP_ERR_NO_MEM;
|
||||
goto _on_func_exit;
|
||||
}
|
||||
|
@ -491,12 +472,15 @@ static esp_err_t esp_apptrace_trax_block_switch()
|
|||
if (ctrl_reg & ESP_APPTRACE_TRAX_HOST_DATA && hdr->block_sz > 0) {
|
||||
// TODO: add support for multiple blocks from host, currently there is no need for that
|
||||
uint8_t *p = s_trace_buf.trax.blocks[new_block_num].start + s_trace_buf.trax.blocks[new_block_num].sz;
|
||||
ESP_APPTRACE_LOGD("Recvd %d bytes from host [%x %x %x .. %x %x]", hdr->block_sz,
|
||||
ESP_APPTRACE_LOGD("Recvd %d bytes from host [%x %x %x %x %x %x %x %x .. %x %x %x %x %x %x %x %x]", hdr->block_sz,
|
||||
*(s_trace_buf.trax.blocks[new_block_num].start+0), *(s_trace_buf.trax.blocks[new_block_num].start+1),
|
||||
*(s_trace_buf.trax.blocks[new_block_num].start+2), *(p-2), *(p-1));
|
||||
uint32_t sz = esp_apptrace_trax_write_down_buffer_nolock((uint8_t *)(hdr+1), hdr->block_sz);
|
||||
*(s_trace_buf.trax.blocks[new_block_num].start+2), *(s_trace_buf.trax.blocks[new_block_num].start+3),
|
||||
*(s_trace_buf.trax.blocks[new_block_num].start+4), *(s_trace_buf.trax.blocks[new_block_num].start+5),
|
||||
*(s_trace_buf.trax.blocks[new_block_num].start+6), *(s_trace_buf.trax.blocks[new_block_num].start+7),
|
||||
*(p-8), *(p-7), *(p-6), *(p-5), *(p-4), *(p-3), *(p-2), *(p-1));
|
||||
uint32_t sz = esp_apptrace_trax_down_buffer_write_nolock((uint8_t *)(hdr+1), hdr->block_sz);
|
||||
if (sz != hdr->block_sz) {
|
||||
ESP_APPTRACE_LOGE("Failed to write %d bytes to down buffer!", hdr->block_sz - sz);
|
||||
ESP_APPTRACE_LOGE("Failed to write %d bytes to down buffer (%d %d)!", hdr->block_sz - sz, hdr->block_sz, sz);
|
||||
}
|
||||
hdr->block_sz = 0;
|
||||
}
|
||||
|
@ -548,15 +532,12 @@ _on_func_exit:
|
|||
return res;
|
||||
}
|
||||
|
||||
static esp_err_t esp_apptrace_trax_block_switch_waitus(uint32_t tmo)
|
||||
static esp_err_t esp_apptrace_trax_block_switch_waitus(esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
int res;
|
||||
esp_apptrace_tmo_t sleeping_tmo;
|
||||
|
||||
esp_apptrace_tmo_init(&sleeping_tmo, tmo);
|
||||
|
||||
while ((res = esp_apptrace_trax_block_switch()) != ESP_OK) {
|
||||
res = esp_apptrace_tmo_check(&sleeping_tmo);
|
||||
res = esp_apptrace_tmo_check(tmo);
|
||||
if (res != ESP_OK) {
|
||||
break;
|
||||
}
|
||||
|
@ -564,58 +545,79 @@ static esp_err_t esp_apptrace_trax_block_switch_waitus(uint32_t tmo)
|
|||
return res;
|
||||
}
|
||||
|
||||
static inline void esp_apptrace_trax_down_buf_init()
|
||||
static uint8_t *esp_apptrace_trax_down_buffer_get(uint32_t *size, esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
esp_apptrace_rb_init(&s_trace_buf.rb_down, s_trace_buf.down_buf, sizeof(s_trace_buf.down_buf));
|
||||
}
|
||||
uint8_t *ptr = NULL;
|
||||
|
||||
static inline uint8_t *esp_apptrace_trax_get_down_rdptr(uint32_t *size, uint32_t *tmo)
|
||||
{
|
||||
int res = esp_apptrace_lock(tmo);
|
||||
if (res != ESP_OK) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// may need to flush
|
||||
uint32_t ctrl_reg = eri_read(ESP_APPTRACE_TRAX_CTRL_REG);
|
||||
if (ctrl_reg & ESP_APPTRACE_TRAX_HOST_DATA) {
|
||||
ESP_APPTRACE_LOGD("force flush");
|
||||
res = esp_apptrace_trax_block_switch_waitus(*tmo);
|
||||
if (res != ESP_OK) {
|
||||
ESP_APPTRACE_LOGE("Failed to switch to another block to recv data from host!");
|
||||
while (1) {
|
||||
uint32_t sz = esp_apptrace_rb_read_size_get(&s_trace_buf.rb_down);
|
||||
if (sz != 0) {
|
||||
ptr = esp_apptrace_rb_consume(&s_trace_buf.rb_down, sz > *size ? *size : sz);
|
||||
if (!ptr) {
|
||||
assert(false && "Failed to consume bytes from down buffer!");
|
||||
}
|
||||
*size = sz;
|
||||
break;
|
||||
}
|
||||
// may need to flush
|
||||
uint32_t ctrl_reg = eri_read(ESP_APPTRACE_TRAX_CTRL_REG);
|
||||
if (ctrl_reg & ESP_APPTRACE_TRAX_HOST_DATA) {
|
||||
ESP_APPTRACE_LOGD("force flush");
|
||||
res = esp_apptrace_trax_block_switch_waitus(tmo);
|
||||
if (res != ESP_OK) {
|
||||
ESP_APPTRACE_LOGE("Failed to switch to another block to recv data from host!");
|
||||
/*do not return error because data can be in down buffer already*/
|
||||
}
|
||||
} else {
|
||||
// check tmo only if there is no data from host
|
||||
res = esp_apptrace_tmo_check(tmo);
|
||||
if (res != ESP_OK) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
uint8_t *ptr = NULL;
|
||||
uint32_t sz = esp_apptrace_rb_read_size_get(&s_trace_buf.rb_down);
|
||||
if (sz > 0) {
|
||||
ptr = esp_apptrace_rb_consume(&s_trace_buf.rb_down, sz > *size ? *size : sz);
|
||||
if (!ptr) {
|
||||
assert(false && "Failed to consume bytes from down buffer!");
|
||||
}
|
||||
}
|
||||
*size = sz;
|
||||
|
||||
if (esp_apptrace_unlock() != ESP_OK) {
|
||||
assert(false && "Failed to unlock apptrace data!");
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static inline esp_err_t esp_apptrace_trax_put_down_rdptr(uint8_t *ptr, uint32_t size, uint32_t *tmo)
|
||||
static inline esp_err_t esp_apptrace_trax_down_buffer_put(uint8_t *ptr, esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
/* nothing todo */
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static uint16_t esp_apptrace_trax_write_down_buffer_nolock(uint8_t *data, uint16_t size)
|
||||
static uint32_t esp_apptrace_trax_down_buffer_write_nolock(uint8_t *data, uint32_t size)
|
||||
{
|
||||
uint8_t *ptr = esp_apptrace_rb_produce(&s_trace_buf.rb_down, size);
|
||||
if (ptr) {
|
||||
memcpy(ptr, data, size);
|
||||
} else {
|
||||
return 0;
|
||||
uint32_t total_sz = 0;
|
||||
|
||||
while (total_sz < size) {
|
||||
// ESP_APPTRACE_LOGE("esp_apptrace_trax_down_buffer_write_nolock WRS %d-%d-%d %d", s_trace_buf.rb_down.wr, s_trace_buf.rb_down.rd,
|
||||
// s_trace_buf.rb_down.cur_size, size);
|
||||
uint32_t wr_sz = esp_apptrace_rb_write_size_get(&s_trace_buf.rb_down);
|
||||
if (wr_sz == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (wr_sz > size - total_sz) {
|
||||
wr_sz = size - total_sz;
|
||||
}
|
||||
// ESP_APPTRACE_LOGE("esp_apptrace_trax_down_buffer_write_nolock wr %d", wr_sz);
|
||||
uint8_t *ptr = esp_apptrace_rb_produce(&s_trace_buf.rb_down, wr_sz);
|
||||
if (!ptr) {
|
||||
assert(false && "Failed to produce bytes to down buffer!");
|
||||
}
|
||||
// ESP_APPTRACE_LOGE("esp_apptrace_trax_down_buffer_write_nolock wr %d to 0x%x from 0x%x", wr_sz, ptr, data + total_sz + wr_sz);
|
||||
memcpy(ptr, data + total_sz, wr_sz);
|
||||
total_sz += wr_sz;
|
||||
// ESP_APPTRACE_LOGE("esp_apptrace_trax_down_buffer_write_nolock wr %d/%d", wr_sz, total_sz);
|
||||
}
|
||||
return size;
|
||||
return total_sz;
|
||||
}
|
||||
|
||||
static inline uint8_t *esp_apptrace_data_header_init(uint8_t *ptr, uint16_t usr_size)
|
||||
|
@ -626,7 +628,7 @@ static inline uint8_t *esp_apptrace_data_header_init(uint8_t *ptr, uint16_t usr_
|
|||
return ptr + sizeof(esp_tracedata_hdr_t);
|
||||
}
|
||||
|
||||
static inline uint8_t *esp_apptrace_trax_wait4buf(uint16_t size, uint32_t tmo, int *pended)
|
||||
static inline uint8_t *esp_apptrace_trax_wait4buf(uint16_t size, esp_apptrace_tmo_t *tmo, int *pended)
|
||||
{
|
||||
uint8_t *ptr = NULL;
|
||||
|
||||
|
@ -665,7 +667,7 @@ static inline uint8_t *esp_apptrace_trax_wait4buf(uint16_t size, uint32_t tmo, i
|
|||
return ptr;
|
||||
}
|
||||
|
||||
static uint8_t *esp_apptrace_trax_get_buffer(size_t size, uint32_t *tmo)
|
||||
static uint8_t *esp_apptrace_trax_get_buffer(uint32_t size, esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
uint8_t *buf_ptr = NULL;
|
||||
|
||||
|
@ -691,14 +693,14 @@ static uint8_t *esp_apptrace_trax_get_buffer(size_t size, uint32_t *tmo)
|
|||
buf_ptr = esp_apptrace_rb_produce(&s_trace_buf.trax.rb_pend, ESP_APPTRACE_USR_BLOCK_RAW_SZ(size));
|
||||
if (buf_ptr == NULL) {
|
||||
int pended_buf;
|
||||
buf_ptr = esp_apptrace_trax_wait4buf(ESP_APPTRACE_USR_BLOCK_RAW_SZ(size), *tmo, &pended_buf);
|
||||
buf_ptr = esp_apptrace_trax_wait4buf(ESP_APPTRACE_USR_BLOCK_RAW_SZ(size), tmo, &pended_buf);
|
||||
if (buf_ptr) {
|
||||
if (pended_buf) {
|
||||
#if CONFIG_ESP32_APPTRACE_PENDING_DATA_SIZE_MAX > ESP_APPTRACE_TRAX_BLOCK_SIZE
|
||||
esp_apptrace_trax_pend_chunk_sz_update(ESP_APPTRACE_USR_BLOCK_RAW_SZ(size));
|
||||
#endif
|
||||
} else {
|
||||
ESP_APPTRACE_LOGD("Got %d bytes from TRAX buffer", size);
|
||||
ESP_APPTRACE_LOGD("Get %d bytes from TRAX buffer", size);
|
||||
// update cur block marker
|
||||
ESP_APPTRACE_TRAX_INBLOCK_MARKER_UPD(ESP_APPTRACE_USR_BLOCK_RAW_SZ(size));
|
||||
}
|
||||
|
@ -723,7 +725,7 @@ static uint8_t *esp_apptrace_trax_get_buffer(size_t size, uint32_t *tmo)
|
|||
if (buf_ptr == NULL) {
|
||||
int pended_buf;
|
||||
ESP_APPTRACE_LOGD("TRAX full. Get %d bytes from pend buffer", size);
|
||||
buf_ptr = esp_apptrace_trax_wait4buf(ESP_APPTRACE_USR_BLOCK_RAW_SZ(size), *tmo, &pended_buf);
|
||||
buf_ptr = esp_apptrace_trax_wait4buf(ESP_APPTRACE_USR_BLOCK_RAW_SZ(size), tmo, &pended_buf);
|
||||
if (buf_ptr) {
|
||||
if (pended_buf) {
|
||||
#if CONFIG_ESP32_APPTRACE_PENDING_DATA_SIZE_MAX > ESP_APPTRACE_TRAX_BLOCK_SIZE
|
||||
|
@ -737,7 +739,7 @@ static uint8_t *esp_apptrace_trax_get_buffer(size_t size, uint32_t *tmo)
|
|||
}
|
||||
}
|
||||
} else {
|
||||
ESP_APPTRACE_LOGD("Get %d bytes from TRAX buffer!", size);
|
||||
ESP_APPTRACE_LOGD("Get %d bytes from TRAX buffer", size);
|
||||
// fit to curr TRAX nlock
|
||||
buf_ptr = ESP_APPTRACE_TRAX_INBLOCK_GET()->start + ESP_APPTRACE_TRAX_INBLOCK_MARKER();
|
||||
// update cur block marker
|
||||
|
@ -755,7 +757,7 @@ static uint8_t *esp_apptrace_trax_get_buffer(size_t size, uint32_t *tmo)
|
|||
return buf_ptr;
|
||||
}
|
||||
|
||||
static esp_err_t esp_apptrace_trax_put_buffer(uint8_t *ptr, uint32_t *tmo)
|
||||
static esp_err_t esp_apptrace_trax_put_buffer(uint8_t *ptr, esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
int res = ESP_OK;
|
||||
esp_tracedata_hdr_t *hdr = (esp_tracedata_hdr_t *)(ptr - sizeof(esp_tracedata_hdr_t));
|
||||
|
@ -772,7 +774,7 @@ static esp_err_t esp_apptrace_trax_put_buffer(uint8_t *ptr, uint32_t *tmo)
|
|||
return res;
|
||||
}
|
||||
|
||||
static esp_err_t esp_apptrace_trax_flush(uint32_t min_sz, uint32_t tmo)
|
||||
static esp_err_t esp_apptrace_trax_flush(uint32_t min_sz, esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
int res = ESP_OK;
|
||||
|
||||
|
@ -782,7 +784,7 @@ static esp_err_t esp_apptrace_trax_flush(uint32_t min_sz, uint32_t tmo)
|
|||
}
|
||||
// switch TRAX block while size of data is more than min size
|
||||
while (ESP_APPTRACE_TRAX_INBLOCK_MARKER() > 0) {
|
||||
ESP_APPTRACE_LOGD("Try to flush %d bytes. Wait until block switch for %u us", ESP_APPTRACE_TRAX_INBLOCK_MARKER(), tmo);
|
||||
ESP_APPTRACE_LOGD("Try to flush %d bytes. Wait until block switch for %u us", ESP_APPTRACE_TRAX_INBLOCK_MARKER(), tmo->tmo);
|
||||
res = esp_apptrace_trax_block_switch_waitus(tmo);
|
||||
if (res != ESP_OK) {
|
||||
ESP_APPTRACE_LOGE("Failed to switch to another block!");
|
||||
|
@ -810,7 +812,6 @@ static esp_err_t esp_apptrace_trax_dest_init()
|
|||
sizeof(s_trace_buf.trax.pending_chunk_sz));
|
||||
#endif
|
||||
#endif
|
||||
esp_apptrace_trax_down_buf_init();
|
||||
|
||||
DPORT_WRITE_PERI_REG(DPORT_PRO_TRACEMEM_ENA_REG, DPORT_PRO_TRACEMEM_ENA_M);
|
||||
#if CONFIG_FREERTOS_UNICORE == 0
|
||||
|
@ -849,25 +850,31 @@ esp_err_t esp_apptrace_init()
|
|||
esp_apptrace_trax_init();
|
||||
#endif
|
||||
|
||||
// disabled by default
|
||||
esp_apptrace_rb_init(&s_trace_buf.rb_down, NULL, 0);
|
||||
|
||||
s_trace_buf.inited |= 1 << xPortGetCoreID(); // global and this CPU-specific data are inited
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *buf, size_t *size, uint32_t user_tmo)
|
||||
void esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size)
|
||||
{
|
||||
esp_apptrace_rb_init(&s_trace_buf.rb_down, buf, size);
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *buf, uint32_t *size, uint32_t user_tmo)
|
||||
{
|
||||
uint8_t *ptr = NULL;
|
||||
uint32_t tmo = user_tmo;
|
||||
int res = ESP_OK;
|
||||
esp_apptrace_tmo_t sleeping_tmo;
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
uint8_t *(*apptrace_get_down_buffer)(uint32_t *, uint32_t *);
|
||||
esp_err_t (*apptrace_put_down_buffer)(uint8_t *, uint32_t , uint32_t *);
|
||||
uint8_t *(*apptrace_get_down_buffer)(uint32_t *, esp_apptrace_tmo_t *);
|
||||
esp_err_t (*apptrace_put_down_buffer)(uint8_t *, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
apptrace_get_down_buffer = esp_apptrace_trax_get_down_rdptr;
|
||||
apptrace_put_down_buffer = esp_apptrace_trax_put_down_rdptr;
|
||||
apptrace_get_down_buffer = esp_apptrace_trax_down_buffer_get;
|
||||
apptrace_put_down_buffer = esp_apptrace_trax_down_buffer_put;
|
||||
#else
|
||||
ESP_APPTRACE_LOGE("Application tracing via TRAX is disabled in menuconfig!");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
|
@ -878,31 +885,72 @@ esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *buf, size_t *size, u
|
|||
}
|
||||
|
||||
//TODO: callback system
|
||||
esp_apptrace_tmo_init(&sleeping_tmo, tmo);
|
||||
esp_apptrace_tmo_init(&tmo, user_tmo);
|
||||
uint32_t act_sz = *size;
|
||||
while ((ptr = apptrace_get_down_buffer(&act_sz, &tmo)) == NULL ) {
|
||||
res = esp_apptrace_tmo_check(&sleeping_tmo);
|
||||
if (res != ESP_OK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
*size = 0;
|
||||
uint8_t * ptr = apptrace_get_down_buffer(&act_sz, &tmo);
|
||||
if (ptr && act_sz > 0) {
|
||||
ESP_APPTRACE_LOGD("Read %d bytes from host", act_sz);
|
||||
memcpy(buf, ptr, act_sz);
|
||||
res = apptrace_put_down_buffer(ptr, act_sz, &tmo);
|
||||
res = apptrace_put_down_buffer(ptr, &tmo);
|
||||
*size = act_sz;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, size_t size, uint32_t user_tmo)
|
||||
uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, uint32_t user_tmo)
|
||||
{
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
uint8_t *(*apptrace_get_down_buffer)(uint32_t *, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
apptrace_get_down_buffer = esp_apptrace_trax_down_buffer_get;
|
||||
#else
|
||||
ESP_APPTRACE_LOGE("Application tracing via TRAX is disabled in menuconfig!");
|
||||
return NULL;
|
||||
#endif
|
||||
} else {
|
||||
ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// ESP_APPTRACE_LOGE("esp_apptrace_down_buffer_get %d", *size);
|
||||
esp_apptrace_tmo_init(&tmo, user_tmo);
|
||||
return apptrace_get_down_buffer(size, &tmo);
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_down_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t user_tmo)
|
||||
{
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
esp_err_t (*apptrace_put_down_buffer)(uint8_t *, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
apptrace_put_down_buffer = esp_apptrace_trax_down_buffer_put;
|
||||
#else
|
||||
ESP_APPTRACE_LOGE("Application tracing via TRAX is disabled in menuconfig!");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
#endif
|
||||
} else {
|
||||
ESP_APPTRACE_LOGE("Trace destinations other then TRAX are not supported yet!");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_apptrace_tmo_init(&tmo, user_tmo);
|
||||
return apptrace_put_down_buffer(ptr, &tmo);
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, uint32_t size, uint32_t user_tmo)
|
||||
{
|
||||
uint8_t *ptr = NULL;
|
||||
uint32_t tmo = user_tmo;
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
uint8_t *(*apptrace_get_buffer)(size_t, uint32_t *);
|
||||
esp_err_t (*apptrace_put_buffer)(uint8_t *, uint32_t *);
|
||||
uint8_t *(*apptrace_get_buffer)(uint32_t, esp_apptrace_tmo_t *);
|
||||
esp_err_t (*apptrace_put_buffer)(uint8_t *, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
|
@ -917,6 +965,7 @@ esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, size_t
|
|||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_apptrace_tmo_init(&tmo, user_tmo);
|
||||
ptr = apptrace_get_buffer(size, &tmo);
|
||||
if (ptr == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
|
@ -934,10 +983,10 @@ int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t user_tmo, const c
|
|||
{
|
||||
uint16_t nargs = 0;
|
||||
uint8_t *pout, *p = (uint8_t *)fmt;
|
||||
uint32_t tmo = user_tmo;
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
uint8_t *(*apptrace_get_buffer)(size_t, uint32_t *);
|
||||
esp_err_t (*apptrace_put_buffer)(uint8_t *, uint32_t *);
|
||||
uint8_t *(*apptrace_get_buffer)(uint32_t, esp_apptrace_tmo_t *);
|
||||
esp_err_t (*apptrace_put_buffer)(uint8_t *, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
|
@ -952,6 +1001,7 @@ int esp_apptrace_vprintf_to(esp_apptrace_dest_t dest, uint32_t user_tmo, const c
|
|||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_apptrace_tmo_init(&tmo, user_tmo);
|
||||
ESP_APPTRACE_LOGD("fmt %x", fmt);
|
||||
while ((p = (uint8_t *)strchr((char *)p, '%')) && nargs < ESP_APPTRACE_MAX_VPRINTF_ARGS) {
|
||||
p++;
|
||||
|
@ -995,11 +1045,11 @@ int esp_apptrace_vprintf(const char *fmt, va_list ap)
|
|||
return esp_apptrace_vprintf_to(ESP_APPTRACE_DEST_TRAX, /*ESP_APPTRACE_TMO_INFINITE*/0, fmt, ap);
|
||||
}
|
||||
|
||||
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, size_t size, uint32_t user_tmo)
|
||||
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, uint32_t size, uint32_t user_tmo)
|
||||
{
|
||||
uint32_t tmo = user_tmo;
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
uint8_t *(*apptrace_get_buffer)(size_t, uint32_t *);
|
||||
uint8_t *(*apptrace_get_buffer)(uint32_t, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
|
@ -1013,14 +1063,15 @@ uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, size_t size, uint32_t
|
|||
return NULL;
|
||||
}
|
||||
|
||||
esp_apptrace_tmo_init(&tmo, user_tmo);
|
||||
return apptrace_get_buffer(size, &tmo);
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t user_tmo)
|
||||
{
|
||||
uint32_t tmo = user_tmo;
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
esp_err_t (*apptrace_put_buffer)(uint8_t *, uint32_t *);
|
||||
esp_err_t (*apptrace_put_buffer)(uint8_t *, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
|
@ -1034,13 +1085,15 @@ esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32
|
|||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
esp_apptrace_tmo_init(&tmo, user_tmo);
|
||||
return apptrace_put_buffer(ptr, &tmo);
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t tmo)
|
||||
esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, uint32_t usr_tmo)
|
||||
{
|
||||
esp_apptrace_tmo_t tmo;
|
||||
//TODO: use ptr to HW transport iface struct
|
||||
esp_err_t (*apptrace_flush)(uint32_t, uint32_t);
|
||||
esp_err_t (*apptrace_flush)(uint32_t, esp_apptrace_tmo_t *);
|
||||
|
||||
if (dest == ESP_APPTRACE_DEST_TRAX) {
|
||||
#if CONFIG_ESP32_APPTRACE_DEST_TRAX
|
||||
|
@ -1054,20 +1107,23 @@ esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, u
|
|||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return apptrace_flush(min_sz, tmo);
|
||||
esp_apptrace_tmo_init(&tmo, usr_tmo);
|
||||
return apptrace_flush(min_sz, &tmo);
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t tmo)
|
||||
esp_err_t esp_apptrace_flush(esp_apptrace_dest_t dest, uint32_t usr_tmo)
|
||||
{
|
||||
int res;
|
||||
esp_apptrace_tmo_t tmo;
|
||||
|
||||
esp_apptrace_tmo_init(&tmo, usr_tmo);
|
||||
res = esp_apptrace_lock(&tmo);
|
||||
if (res != ESP_OK) {
|
||||
ESP_APPTRACE_LOGE("Failed to lock apptrace data (%d)!", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
res = esp_apptrace_flush_nolock(dest, 0, tmo);
|
||||
res = esp_apptrace_flush_nolock(dest, 0, esp_apptrace_tmo_remaining_us(&tmo));
|
||||
if (res != ESP_OK) {
|
||||
ESP_APPTRACE_LOGE("Failed to flush apptrace data (%d)!", res);
|
||||
}
|
||||
|
|
|
@ -17,38 +17,39 @@
|
|||
#include "esp_app_trace_util.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////// LOCK ////////////////////////////////////////
|
||||
///////////////////////////////// TIMEOUT /////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define ESP_TEST_CPUTICKS2US(_t_) ((_t_)/(XT_CLOCK_FREQ/1000000))
|
||||
// TODO: get actual clock from PLL config
|
||||
#define ESP_APPTRACE_CPUTICKS2US(_t_) ((_t_)/(XT_CLOCK_FREQ/1000000))
|
||||
|
||||
esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
unsigned cur, elapsed;
|
||||
|
||||
if (tmo->tmo != 0xFFFFFFFF) {
|
||||
cur = portGET_RUN_TIME_COUNTER_VALUE();
|
||||
if (tmo->tmo != ESP_APPTRACE_TMO_INFINITE) {
|
||||
unsigned cur = portGET_RUN_TIME_COUNTER_VALUE();
|
||||
if (tmo->start <= cur) {
|
||||
elapsed = cur - tmo->start;
|
||||
tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(cur - tmo->start);
|
||||
} else {
|
||||
elapsed = 0xFFFFFFFF - tmo->start + cur;
|
||||
tmo->elapsed = ESP_APPTRACE_CPUTICKS2US(0xFFFFFFFF - tmo->start + cur);
|
||||
}
|
||||
if (ESP_TEST_CPUTICKS2US(elapsed) >= tmo->tmo) {
|
||||
if (tmo->elapsed >= tmo->tmo) {
|
||||
return ESP_ERR_TIMEOUT;
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, uint32_t tmo)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
///////////////////////////////// LOCK ////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
uint32_t res;
|
||||
#if CONFIG_SYSVIEW_ENABLE
|
||||
uint32_t recCnt;
|
||||
#endif
|
||||
esp_apptrace_tmo_t sleeping_tmo;
|
||||
|
||||
esp_apptrace_tmo_init(&sleeping_tmo, tmo);
|
||||
while (1) {
|
||||
res = (xPortGetCoreID() << portMUX_VAL_SHIFT) | portMUX_MAGIC_VAL;
|
||||
// first disable IRQs on this CPU, this will prevent current task from been
|
||||
|
@ -77,7 +78,7 @@ esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, uint32_t tmo)
|
|||
// if mux is locked by other task/ISR enable IRQs and let other guys work
|
||||
portEXIT_CRITICAL_NESTED(irq_stat);
|
||||
|
||||
int err = esp_apptrace_tmo_check(&sleeping_tmo);
|
||||
int err = esp_apptrace_tmo_check(tmo);
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
}
|
||||
|
@ -205,3 +206,19 @@ uint32_t esp_apptrace_rb_read_size_get(esp_apptrace_rb_t *rb)
|
|||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
uint32_t esp_apptrace_rb_write_size_get(esp_apptrace_rb_t *rb)
|
||||
{
|
||||
uint32_t size = 0;
|
||||
if (rb->rd <= rb->wr) {
|
||||
// |?R......W??|
|
||||
size = rb->size - rb->wr;
|
||||
if (size && rb->rd == 0) {
|
||||
size--;
|
||||
}
|
||||
} else {
|
||||
// |?W......R??|
|
||||
size = rb->rd - rb->wr - 1;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
|
|
@ -16,10 +16,7 @@
|
|||
|
||||
#include <stdarg.h>
|
||||
#include "esp_err.h"
|
||||
#include "freertos/portmacro.h"
|
||||
|
||||
/** Infinite waiting timeout */
|
||||
#define ESP_APPTRACE_TMO_INFINITE ((uint32_t)-1)
|
||||
#include "esp_app_trace_util.h" // ESP_APPTRACE_TMO_INFINITE
|
||||
|
||||
/**
|
||||
* Application trace data destinations bits.
|
||||
|
@ -38,6 +35,16 @@ typedef enum {
|
|||
*/
|
||||
esp_err_t esp_apptrace_init();
|
||||
|
||||
/**
|
||||
* @brief Configures down buffer.
|
||||
* @note Needs to be called before initiating any data transfer using esp_apptrace_buffer_get and esp_apptrace_write.
|
||||
* This function does not protect internal data by lock.
|
||||
*
|
||||
* @param buf Address of buffer to use for down channel (host to target) data.
|
||||
* @param size Size of the buffer.
|
||||
*/
|
||||
void esp_apptrace_down_buffer_config(uint8_t *buf, uint32_t size);
|
||||
|
||||
/**
|
||||
* @brief Allocates buffer for trace data.
|
||||
* After data in buffer are ready to be sent off esp_apptrace_buffer_put must be called to indicate it.
|
||||
|
@ -48,11 +55,11 @@ esp_err_t esp_apptrace_init();
|
|||
*
|
||||
* @return non-NULL on success, otherwise NULL.
|
||||
*/
|
||||
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, size_t size, uint32_t tmo);
|
||||
uint8_t *esp_apptrace_buffer_get(esp_apptrace_dest_t dest, uint32_t size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Indicates that the data in buffer are ready to be sent off.
|
||||
* This function is a counterpart of must be preceeded by esp_apptrace_buffer_get.
|
||||
* This function is a counterpart of and must be preceeded by esp_apptrace_buffer_get.
|
||||
*
|
||||
* @param dest Indicates HW interface to send data. Should be identical to the same parameter in call to esp_apptrace_buffer_get.
|
||||
* @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_buffer_get.
|
||||
|
@ -72,7 +79,7 @@ esp_err_t esp_apptrace_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32
|
|||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, size_t size, uint32_t tmo);
|
||||
esp_err_t esp_apptrace_write(esp_apptrace_dest_t dest, const void *data, uint32_t size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief vprintf-like function to sent log messages to host via specified HW interface.
|
||||
|
@ -128,7 +135,30 @@ esp_err_t esp_apptrace_flush_nolock(esp_apptrace_dest_t dest, uint32_t min_sz, u
|
|||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *data, size_t *size, uint32_t tmo);
|
||||
esp_err_t esp_apptrace_read(esp_apptrace_dest_t dest, void *data, uint32_t *size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Rertrieves incoming data buffer if any.
|
||||
* After data in buffer are processed esp_apptrace_down_buffer_put must be called to indicate it.
|
||||
*
|
||||
* @param dest Indicates HW interface to receive data.
|
||||
* @param size Address to store size of available data in down buffer. Must be initializaed with requested value.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return non-NULL on success, otherwise NULL.
|
||||
*/
|
||||
uint8_t *esp_apptrace_down_buffer_get(esp_apptrace_dest_t dest, uint32_t *size, uint32_t tmo);
|
||||
|
||||
/**
|
||||
* @brief Indicates that the data in down buffer are processesd.
|
||||
* This function is a counterpart of and must be preceeded by esp_apptrace_down_buffer_get.
|
||||
*
|
||||
* @param dest Indicates HW interface to receive data. Should be identical to the same parameter in call to esp_apptrace_down_buffer_get.
|
||||
* @param ptr Address of trace buffer to release. Should be the value returned by call to esp_apptrace_down_buffer_get.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_down_buffer_put(esp_apptrace_dest_t dest, uint8_t *ptr, uint32_t tmo);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -14,9 +14,49 @@
|
|||
#ifndef ESP_APP_TRACE_UTIL_H_
|
||||
#define ESP_APP_TRACE_UTIL_H_
|
||||
|
||||
#include "freertos/portmacro.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
/** Infinite waiting timeout */
|
||||
#define ESP_APPTRACE_TMO_INFINITE ((uint32_t)-1)
|
||||
|
||||
/** Structure which holds data necessary for measuring time intervals.
|
||||
*
|
||||
* After initialization via esp_apptrace_tmo_init() user needs to call esp_apptrace_tmo_check()
|
||||
* periodically to check timeout for expiration.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t start; ///< time interval start (in CPU ticks)
|
||||
uint32_t tmo; ///< timeout value (in us)
|
||||
uint32_t elapsed; ///< elapsed time (in us)
|
||||
} esp_apptrace_tmo_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes timeout structure.
|
||||
*
|
||||
* @param tmo Pointer to timeout structure to be initialized.
|
||||
* @param user_tmo Timeout value (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
*/
|
||||
static inline void esp_apptrace_tmo_init(esp_apptrace_tmo_t *tmo, uint32_t user_tmo)
|
||||
{
|
||||
tmo->start = portGET_RUN_TIME_COUNTER_VALUE();
|
||||
tmo->tmo = user_tmo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks timeout for expiration.
|
||||
*
|
||||
* @param tmo Pointer to timeout structure to be initialized.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo);
|
||||
|
||||
static inline uint32_t esp_apptrace_tmo_remaining_us(esp_apptrace_tmo_t *tmo)
|
||||
{
|
||||
return tmo->tmo != ESP_APPTRACE_TMO_INFINITE ? (tmo->elapsed - tmo->tmo) : ESP_APPTRACE_TMO_INFINITE;
|
||||
}
|
||||
|
||||
/** Tracing module synchronization lock */
|
||||
typedef struct {
|
||||
volatile unsigned int irq_stat; ///< local (on 1 CPU) IRQ state
|
||||
|
@ -38,11 +78,11 @@ static inline void esp_apptrace_lock_init(esp_apptrace_lock_t *lock)
|
|||
* @brief Tries to acquire lock in specified time period.
|
||||
*
|
||||
* @param lock Pointer to lock structure.
|
||||
* @param tmo Timeout for operation (in us). Use ESP_APPTRACE_TMO_INFINITE to wait indefinetly.
|
||||
* @param tmo Pointer to timeout struct.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, uint32_t tmo);
|
||||
esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, esp_apptrace_tmo_t *tmo);
|
||||
|
||||
/**
|
||||
* @brief Releases lock.
|
||||
|
@ -53,39 +93,6 @@ esp_err_t esp_apptrace_lock_take(esp_apptrace_lock_t *lock, uint32_t tmo);
|
|||
*/
|
||||
esp_err_t esp_apptrace_lock_give(esp_apptrace_lock_t *lock);
|
||||
|
||||
|
||||
/** Structure which holds data necessary for measuring time intervals.
|
||||
*
|
||||
* After initialization via esp_apptrace_tmo_init() user needs to call esp_apptrace_tmo_check()
|
||||
* periodically to check timeout for expiration.
|
||||
*/
|
||||
typedef struct {
|
||||
uint32_t start; ///< time interval start (in ticks)
|
||||
uint32_t tmo; ///< timeout value (in us)
|
||||
} esp_apptrace_tmo_t;
|
||||
|
||||
/**
|
||||
* @brief Initializes timeout structure.
|
||||
*
|
||||
* @param tmo Pointer to timeout structure to be initialized.
|
||||
* @param user_tmo Timeout value (in us).
|
||||
*/
|
||||
static inline void esp_apptrace_tmo_init(esp_apptrace_tmo_t *tmo, uint32_t user_tmo)
|
||||
{
|
||||
tmo->start = portGET_RUN_TIME_COUNTER_VALUE();
|
||||
tmo->tmo = user_tmo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks timeout for expiration.
|
||||
*
|
||||
* @param tmo Pointer to timeout structure to be initialized.
|
||||
*
|
||||
* @return ESP_OK on success, otherwise \see esp_err_t
|
||||
*/
|
||||
esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo);
|
||||
|
||||
|
||||
/** Ring buffer control structure.
|
||||
*
|
||||
* @note For purposes of application tracing module if there is no enough space for user data and write pointer can be wrapped
|
||||
|
@ -93,10 +100,10 @@ esp_err_t esp_apptrace_tmo_check(esp_apptrace_tmo_t *tmo);
|
|||
*/
|
||||
typedef struct {
|
||||
uint8_t *data; ///< pointer to data storage
|
||||
uint32_t size; ///< size of data storage
|
||||
uint32_t cur_size; ///< current size of data storage
|
||||
uint32_t rd; ///< read pointer
|
||||
uint32_t wr; ///< write pointer
|
||||
volatile uint32_t size; ///< size of data storage
|
||||
volatile uint32_t cur_size; ///< current size of data storage
|
||||
volatile uint32_t rd; ///< read pointer
|
||||
volatile uint32_t wr; ///< write pointer
|
||||
} esp_apptrace_rb_t;
|
||||
|
||||
/**
|
||||
|
@ -145,4 +152,15 @@ uint8_t *esp_apptrace_rb_consume(esp_apptrace_rb_t *rb, uint32_t size);
|
|||
*/
|
||||
uint32_t esp_apptrace_rb_read_size_get(esp_apptrace_rb_t *rb);
|
||||
|
||||
/**
|
||||
* @brief Gets size of memory which can produced with single call to esp_apptrace_rb_produce().
|
||||
*
|
||||
* @param rb Pointer to ring buffer structure.
|
||||
*
|
||||
* @return Size of memory which can produced.
|
||||
*
|
||||
* @note Due to write pointer wrapping returned size can be less then the total size of available data.
|
||||
*/
|
||||
uint32_t esp_apptrace_rb_write_size_get(esp_apptrace_rb_t *rb);
|
||||
|
||||
#endif //ESP_APP_TRACE_UTIL_H_
|
|
@ -322,7 +322,9 @@ void SEGGER_SYSVIEW_X_RTT_Unlock()
|
|||
|
||||
void SEGGER_SYSVIEW_X_SysView_Lock()
|
||||
{
|
||||
esp_apptrace_lock_take(&s_sys_view_lock, SEGGER_LOCK_WAIT_TMO);
|
||||
esp_apptrace_tmo_t tmo;
|
||||
esp_apptrace_tmo_init(&tmo, SEGGER_LOCK_WAIT_TMO);
|
||||
esp_apptrace_lock_take(&s_sys_view_lock, &tmo);
|
||||
}
|
||||
|
||||
void SEGGER_SYSVIEW_X_SysView_Unlock()
|
||||
|
|
|
@ -36,11 +36,14 @@ const static char *TAG = "segger_rtt";
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#define SEGGER_HOST_WAIT_TMO 500 //us
|
||||
#define SEGGER_STOP_WAIT_TMO 1000000 //us
|
||||
// size of down channel data buf
|
||||
#define SYSVIEW_DOWN_BUF_SIZE 32
|
||||
#define SEGGER_HOST_WAIT_TMO 500 //us
|
||||
#define SEGGER_STOP_WAIT_TMO 1000000 //us
|
||||
|
||||
static uint8_t s_events_buf[SYSVIEW_EVENTS_BUF_SZ];
|
||||
static uint16_t s_events_buf_filled;
|
||||
static uint8_t s_down_buf[SYSVIEW_DOWN_BUF_SIZE];
|
||||
|
||||
/*********************************************************************
|
||||
*
|
||||
|
@ -216,6 +219,7 @@ int SEGGER_RTT_ConfigUpBuffer(unsigned BufferIndex, const char* sName, void* pBu
|
|||
* Buffer name and flags can be reconfigured using the appropriate functions.
|
||||
*/
|
||||
int SEGGER_RTT_ConfigDownBuffer(unsigned BufferIndex, const char* sName, void* pBuffer, unsigned BufferSize, unsigned Flags) {
|
||||
esp_apptrace_down_buffer_config(s_down_buf, sizeof(s_down_buf));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,3 +30,56 @@ config AWS_IOT_MQTT_PORT
|
|||
If you need per-device port numbers for different regions, you can
|
||||
override the default port number in your app.
|
||||
|
||||
|
||||
config AWS_IOT_MQTT_TX_BUF_LEN
|
||||
int "MQTT TX Buffer Length"
|
||||
depends on AWS_IOT_SDK
|
||||
default 512
|
||||
range 32 65536
|
||||
help
|
||||
Maximum MQTT transmit buffer size. This is the maximum MQTT
|
||||
message length (including protocol overhead) which can be sent.
|
||||
|
||||
Sending longer messages will fail.
|
||||
|
||||
config AWS_IOT_MQTT_RX_BUF_LEN
|
||||
int "MQTT RX Buffer Length"
|
||||
depends on AWS_IOT_SDK
|
||||
default 512
|
||||
range 32 65536
|
||||
help
|
||||
Maximum MQTT receive buffer size. This is the maximum MQTT
|
||||
message length (including protocol overhead) which can be
|
||||
received.
|
||||
|
||||
Longer messages are dropped.
|
||||
|
||||
|
||||
|
||||
config AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS
|
||||
int "Maximum MQTT Topic Filters"
|
||||
depends on AWS_IOT_SDK
|
||||
default 5
|
||||
range 1 100
|
||||
help
|
||||
Maximum number of concurrent MQTT topic filters.
|
||||
|
||||
|
||||
config AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL
|
||||
int "Auto reconnect initial interval (ms)"
|
||||
depends on AWS_IOT_SDK
|
||||
default 1000
|
||||
range 10 3600000
|
||||
help
|
||||
Initial delay before making first reconnect attempt, if the AWS IoT connection fails.
|
||||
Client will perform exponential backoff, starting from this value.
|
||||
|
||||
config AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL
|
||||
int "Auto reconnect maximum interval (ms)"
|
||||
depends on AWS_IOT_SDK
|
||||
default 128000
|
||||
range 10 3600000
|
||||
help
|
||||
Maximum delay between reconnection attempts. If the exponentially increased delay
|
||||
interval reaches this value, the client will stop automatically attempting to reconnect.
|
||||
|
||||
|
|
|
@ -37,9 +37,9 @@
|
|||
#define AWS_IOT_MY_THING_NAME "ESP32" ///< Thing Name of the Shadow this device is associated with
|
||||
|
||||
// MQTT PubSub
|
||||
#define AWS_IOT_MQTT_TX_BUF_LEN 512 ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow
|
||||
#define AWS_IOT_MQTT_RX_BUF_LEN 512 ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped.
|
||||
#define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS 5 ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow
|
||||
#define AWS_IOT_MQTT_TX_BUF_LEN CONFIG_AWS_IOT_MQTT_TX_BUF_LEN ///< Any time a message is sent out through the MQTT layer. The message is copied into this buffer anytime a publish is done. This will also be used in the case of Thing Shadow
|
||||
#define AWS_IOT_MQTT_RX_BUF_LEN CONFIG_AWS_IOT_MQTT_RX_BUF_LEN ///< Any message that comes into the device should be less than this buffer size. If a received message is bigger than this buffer size the message will be dropped.
|
||||
#define AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS CONFIG_AWS_IOT_MQTT_NUM_SUBSCRIBE_HANDLERS ///< Maximum number of topic filters the MQTT client can handle at any given time. This should be increased appropriately when using Thing Shadow
|
||||
|
||||
// Thing Shadow specific configs
|
||||
#define SHADOW_MAX_SIZE_OF_RX_BUFFER (AWS_IOT_MQTT_RX_BUF_LEN + 1) ///< Maximum size of the SHADOW buffer to store the received Shadow message
|
||||
|
@ -54,7 +54,7 @@
|
|||
#define MAX_SHADOW_TOPIC_LENGTH_BYTES (MAX_SHADOW_TOPIC_LENGTH_WITHOUT_THINGNAME + MAX_SIZE_OF_THING_NAME) ///< This size includes the length of topic with Thing Name
|
||||
|
||||
// Auto Reconnect specific config
|
||||
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL 1000 ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
|
||||
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL 128000 ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
|
||||
#define AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL CONFIG_AWS_IOT_MQTT_MIN_RECONNECT_WAIT_INTERVAL ///< Minimum time before the First reconnect attempt is made as part of the exponential back-off algorithm
|
||||
#define AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL CONFIG_AWS_IOT_MQTT_MAX_RECONNECT_WAIT_INTERVAL ///< Maximum time interval after which exponential back-off will stop attempting to reconnect.
|
||||
|
||||
#endif /* _AWS_IOT_CONFIG_H_ */
|
||||
|
|
|
@ -43,16 +43,7 @@ config BOOTLOADER_SPI_WP_PIN
|
|||
|
||||
The default value (GPIO 7) is correct for WP pin on ESP32-D2WD integrated flash.
|
||||
|
||||
config BOOTLOADER_LTO
|
||||
bool "Build bootloader with Link Time Optimisation"
|
||||
default n
|
||||
help
|
||||
Setting this option enables gcc Link Time Optimisation for the bootloader build & link pass.
|
||||
|
||||
This gives a smaller bootloader binary (can be useful if secure boot & flash encryption & logging are all enabled), and can
|
||||
give faster boot times, but it makes the bootloader harder to debug.
|
||||
|
||||
endmenu # Bootloader config
|
||||
endmenu # Bootloader
|
||||
|
||||
|
||||
menu "Security features"
|
||||
|
@ -226,7 +217,7 @@ config FLASH_ENCRYPTION_UART_BOOTLOADER_ALLOW_CACHE
|
|||
config SECURE_BOOT_TEST_MODE
|
||||
bool "Secure boot test mode: don't permanently set any efuses"
|
||||
depends on SECURE_BOOT_INSECURE
|
||||
default n
|
||||
default N
|
||||
help
|
||||
If this option is set, all permanent secure boot changes (via Efuse) are disabled.
|
||||
|
||||
|
|
|
@ -2,8 +2,3 @@
|
|||
# paths can be added at this level (we need binary librtc to be
|
||||
# available to link bootloader).
|
||||
COMPONENT_SUBMODULES += $(IDF_PATH)/components/esp32/lib
|
||||
|
||||
ifdef CONFIG_BOOTLOADER_LTO
|
||||
CFLAGS += -flto
|
||||
EXTRA_LDFLAGS += -Wl,-flto
|
||||
endif
|
||||
|
|
|
@ -436,7 +436,7 @@ esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id)
|
||||
|
@ -459,7 +459,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_err_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id)
|
||||
|
|
|
@ -93,6 +93,7 @@ typedef enum {
|
|||
ESP_GAP_BLE_SET_STATIC_RAND_ADDR_EVT, /*!< When set the static rand address complete, the event comes */
|
||||
ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT, /*!< When update connection parameters complete, the event comes */
|
||||
ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, /*!< When set pkt lenght complete, the event comes */
|
||||
ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, /*!< When Enable/disable privacy on the local device complete, the event comes */
|
||||
} esp_gap_ble_cb_event_t;
|
||||
|
||||
/// Advertising data maximum length
|
||||
|
@ -539,6 +540,12 @@ typedef union {
|
|||
esp_bt_status_t status; /*!< Indicate the set pkt data length operation success status */
|
||||
esp_ble_pkt_data_length_params_t params; /*!< pkt data length value */
|
||||
} pkt_data_lenth_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT
|
||||
*/
|
||||
struct ble_local_privacy_cmpl_evt_param {
|
||||
esp_bt_status_t status; /*!< Indicate the set local privacy operation success status */
|
||||
} local_privacy_cmpl; /*!< Event parameter of ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT */
|
||||
} esp_ble_gap_cb_param_t;
|
||||
|
||||
/**
|
||||
|
|
|
@ -634,7 +634,7 @@ esp_err_t esp_ble_gattc_execute_write (esp_gatt_if_t gattc_if, uint16_t conn_id,
|
|||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_err_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
|
@ -653,7 +653,7 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gattc_if,
|
|||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_err_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gattc_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
|
|
|
@ -4601,7 +4601,7 @@ void bta_dm_ble_stop_advertising(tBTA_DM_MSG *p_data)
|
|||
*******************************************************************************/
|
||||
void bta_dm_ble_config_local_privacy (tBTA_DM_MSG *p_data)
|
||||
{
|
||||
BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable);
|
||||
BTM_BleConfigPrivacy (p_data->ble_local_privacy.privacy_enable, p_data->ble_local_privacy.set_local_privacy_cback);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1575,7 +1575,7 @@ void BTA_DmBleUpdateConnectionParam(BD_ADDR bd_addr, UINT16 min_int,
|
|||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
|
||||
void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
|
||||
{
|
||||
///This function used the irk to generate the resolve address
|
||||
#if BLE_INCLUDED == TRUE && BLE_PRIVACY_SPT == TRUE
|
||||
|
@ -1586,7 +1586,7 @@ void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable)
|
|||
|
||||
p_msg->hdr.event = BTA_DM_API_LOCAL_PRIVACY_EVT;
|
||||
p_msg->privacy_enable = privacy_enable;
|
||||
|
||||
p_msg->set_local_privacy_cback = set_local_privacy_cback;
|
||||
bta_sys_sendmsg(p_msg);
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -444,6 +444,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
BT_HDR hdr;
|
||||
BOOLEAN privacy_enable;
|
||||
tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback;
|
||||
} tBTA_DM_API_LOCAL_PRIVACY;
|
||||
|
||||
/* set scan parameter for BLE connections */
|
||||
|
|
|
@ -506,7 +506,7 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
|
|||
UINT16 service_id = p_srvc_cb->service_id;
|
||||
tBTA_GATTS cb_data;
|
||||
tBTA_GATT_STATUS gatts_status;
|
||||
gatts_status = GATTS_SetAttributeValue(p_msg->api_add_char_descr.hdr.layer_specific,
|
||||
gatts_status = GATTS_SetAttributeValue(p_msg->api_set_val.hdr.layer_specific,
|
||||
p_msg->api_set_val.length,
|
||||
p_msg->api_set_val.value);
|
||||
|
||||
|
@ -515,6 +515,10 @@ void bta_gatts_set_attr_value(tBTA_GATTS_SRVC_CB *p_srvc_cb, tBTA_GATTS_DATA *p_
|
|||
cb_data.attr_val.attr_id = p_msg->api_set_val.hdr.layer_specific;
|
||||
cb_data.attr_val.status = gatts_status;
|
||||
|
||||
if (p_msg->api_set_val.value != NULL){
|
||||
GKI_freebuf(p_msg->api_set_val.value);
|
||||
}
|
||||
|
||||
if (p_rcb->p_cback) {
|
||||
(*p_rcb->p_cback)(BTA_GATTS_SET_ATTR_VAL_EVT, &cb_data);
|
||||
}
|
||||
|
|
|
@ -404,6 +404,8 @@ typedef void (tBTA_START_ADV_CMPL_CBACK) (tBTA_STATUS status);
|
|||
|
||||
typedef tBTM_SET_PKT_DATA_LENGTH_CBACK tBTA_SET_PKT_DATA_LENGTH_CBACK;
|
||||
|
||||
typedef tBTM_SET_LOCAL_PRIVACY_CBACK tBTA_SET_LOCAL_PRIVACY_CBACK;
|
||||
|
||||
/* advertising channel map */
|
||||
#define BTA_BLE_ADV_CHNL_37 BTM_BLE_ADV_CHNL_37
|
||||
#define BTA_BLE_ADV_CHNL_38 BTM_BLE_ADV_CHNL_38
|
||||
|
@ -2035,11 +2037,11 @@ extern void BTA_DmSetRandAddress(BD_ADDR rand_addr);
|
|||
** Description Enable/disable privacy on the local device
|
||||
**
|
||||
** Parameters: privacy_enable - enable/disabe privacy on remote device.
|
||||
**
|
||||
** set_local_privacy_cback -callback to be called with result
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable);
|
||||
extern void BTA_DmBleConfigLocalPrivacy(BOOLEAN privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
tBTA_SYS_CB bta_sys_cb;
|
||||
#endif
|
||||
|
||||
fixed_queue_t *btu_bta_alarm_queue;
|
||||
static hash_map_t *bta_alarm_hash_map;
|
||||
static const size_t BTA_ALARM_HASH_MAP_SIZE = 17;
|
||||
static pthread_mutex_t bta_alarm_lock;
|
||||
|
@ -62,8 +61,6 @@ static pthread_mutex_t bta_alarm_lock;
|
|||
UINT8 appl_trace_level = BT_TRACE_LEVEL_WARNING; //APPL_INITIAL_TRACE_LEVEL;
|
||||
UINT8 btif_trace_level = BT_TRACE_LEVEL_WARNING;
|
||||
|
||||
// Communication queue between btu_task and bta.
|
||||
extern fixed_queue_t *btu_bta_msg_queue;
|
||||
void btu_bta_alarm_ready(fixed_queue_t *queue);
|
||||
|
||||
static const tBTA_SYS_REG bta_sys_hw_reg = {
|
||||
|
@ -175,10 +172,6 @@ void bta_sys_init(void)
|
|||
|
||||
bta_alarm_hash_map = hash_map_new(BTA_ALARM_HASH_MAP_SIZE,
|
||||
hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
|
||||
btu_bta_alarm_queue = fixed_queue_new(SIZE_MAX);
|
||||
|
||||
fixed_queue_register_dequeue(btu_bta_alarm_queue,
|
||||
btu_bta_alarm_ready);
|
||||
|
||||
appl_trace_level = APPL_INITIAL_TRACE_LEVEL;
|
||||
|
||||
|
@ -196,7 +189,6 @@ void bta_sys_init(void)
|
|||
|
||||
void bta_sys_free(void)
|
||||
{
|
||||
fixed_queue_free(btu_bta_alarm_queue, NULL);
|
||||
hash_map_free(bta_alarm_hash_map);
|
||||
pthread_mutex_destroy(&bta_alarm_lock);
|
||||
}
|
||||
|
@ -575,10 +567,8 @@ void bta_sys_sendmsg(void *p_msg)
|
|||
// there is a procedure in progress that can schedule a task via this
|
||||
// message queue. This causes |btu_bta_msg_queue| to get cleaned up before
|
||||
// it gets used here; hence we check for NULL before using it.
|
||||
if (btu_bta_msg_queue) {
|
||||
fixed_queue_enqueue(btu_bta_msg_queue, p_msg);
|
||||
//ke_event_set(KE_EVENT_BTU_TASK_THREAD);
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
if (btu_task_post(SIG_BTU_BTA_MSG, p_msg, TASK_POST_BLOCKING) != TASK_POST_SUCCESS) {
|
||||
GKI_freebuf(p_msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -597,9 +587,7 @@ void bta_alarm_cb(void *data)
|
|||
assert(data != NULL);
|
||||
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
|
||||
|
||||
fixed_queue_enqueue(btu_bta_alarm_queue, p_tle);
|
||||
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
btu_task_post(SIG_BTU_BTA_ALARM, p_tle, TASK_POST_BLOCKING);
|
||||
}
|
||||
|
||||
void bta_sys_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, INT32 timeout_ms)
|
||||
|
|
|
@ -145,6 +145,12 @@ static esp_bt_status_t btc_btm_status_to_esp_status (uint8_t btm_status)
|
|||
case BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED:
|
||||
esp_status = ESP_BT_STATUS_CONTROL_LE_DATA_LEN_UNSUPPORTED;
|
||||
break;
|
||||
case BTM_SET_PRIVACY_SUCCESS:
|
||||
esp_status = ESP_BT_STATUS_SUCCESS;
|
||||
break;
|
||||
case BTM_SET_PRIVACY_FAIL:
|
||||
esp_status = ESP_BT_STATUS_FAIL;
|
||||
break;
|
||||
default:
|
||||
esp_status = ESP_BT_STATUS_FAIL;
|
||||
break;
|
||||
|
@ -661,6 +667,23 @@ static void btc_set_pkt_length_callback(UINT8 status, tBTM_LE_SET_PKT_DATA_LENGT
|
|||
}
|
||||
}
|
||||
|
||||
static void btc_set_local_privacy_callback(UINT8 status)
|
||||
{
|
||||
esp_ble_gap_cb_param_t param;
|
||||
bt_status_t ret;
|
||||
btc_msg_t msg;
|
||||
msg.sig = BTC_SIG_API_CB;
|
||||
msg.pid = BTC_PID_GAP_BLE;
|
||||
msg.act = ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT;
|
||||
param.local_privacy_cmpl.status = btc_btm_status_to_esp_status(status);
|
||||
ret = btc_transfer_context(&msg, ¶m,
|
||||
sizeof(esp_ble_gap_cb_param_t), NULL);
|
||||
|
||||
if (ret != BT_STATUS_SUCCESS) {
|
||||
LOG_ERROR("%s btc_transfer_context failed\n", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if (SMP_INCLUDED == TRUE)
|
||||
static void btc_set_encryption_callback(BD_ADDR bd_addr, tBTA_TRANSPORT transport, tBTA_STATUS enc_status)
|
||||
|
@ -756,9 +779,9 @@ static void btc_ble_set_rand_addr (BD_ADDR rand_addr)
|
|||
}
|
||||
}
|
||||
|
||||
static void btc_ble_config_local_privacy(bool privacy_enable)
|
||||
static void btc_ble_config_local_privacy(bool privacy_enable, tBTA_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
|
||||
{
|
||||
BTA_DmBleConfigLocalPrivacy(privacy_enable);
|
||||
BTA_DmBleConfigLocalPrivacy(privacy_enable, set_local_privacy_cback);
|
||||
}
|
||||
|
||||
static void btc_ble_disconnect(BD_ADDR bd_addr)
|
||||
|
@ -837,6 +860,9 @@ void btc_gap_ble_cb_handler(btc_msg_t *msg)
|
|||
case ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT:
|
||||
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_PKT_LENGTH_COMPLETE_EVT, param);
|
||||
break;
|
||||
case ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT:
|
||||
btc_gap_ble_cb_to_app(ESP_GAP_BLE_SET_LOCAL_PRIVACY_COMPLETE_EVT, param);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
|
@ -1000,7 +1026,7 @@ void btc_gap_ble_call_handler(btc_msg_t *msg)
|
|||
break;
|
||||
}
|
||||
case BTC_GAP_BLE_ACT_CONFIG_LOCAL_PRIVACY:
|
||||
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable);
|
||||
btc_ble_config_local_privacy(arg->cfg_local_privacy.privacy_enable, btc_set_local_privacy_callback);
|
||||
break;
|
||||
case BTC_GAP_BLE_ACT_CFG_ADV_DATA_RAW:
|
||||
btc_ble_set_adv_data_raw(arg->cfg_adv_data_raw.raw_adv,
|
||||
|
|
|
@ -163,23 +163,26 @@ static void hci_hal_h4_rx_handler(void *arg)
|
|||
|
||||
for (;;) {
|
||||
if (pdTRUE == xQueueReceive(xHciH4Queue, &e, (portTickType)portMAX_DELAY)) {
|
||||
if (e.sig == 0xff) {
|
||||
if (e.sig == SIG_HCI_HAL_RECV_PACKET) {
|
||||
fixed_queue_process(hci_hal_env.rx_q);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void hci_hal_h4_task_post(task_post_t timeout)
|
||||
task_post_status_t hci_hal_h4_task_post(task_post_t timeout)
|
||||
{
|
||||
BtTaskEvt_t evt;
|
||||
|
||||
evt.sig = 0xff;
|
||||
evt.sig = SIG_HCI_HAL_RECV_PACKET;
|
||||
evt.par = 0;
|
||||
|
||||
if (xQueueSend(xHciH4Queue, &evt, timeout) != pdTRUE) {
|
||||
LOG_ERROR("xHciH4Queue failed\n");
|
||||
return TASK_POST_SUCCESS;
|
||||
}
|
||||
|
||||
return TASK_POST_FAIL;
|
||||
}
|
||||
|
||||
static void hci_hal_h4_hdl_rx_packet(BT_HDR *packet)
|
||||
|
|
|
@ -54,9 +54,6 @@ typedef struct {
|
|||
fixed_queue_t *command_queue;
|
||||
fixed_queue_t *packet_queue;
|
||||
|
||||
// The hand-off point for data going to a higher layer, set by the higher layer
|
||||
fixed_queue_t *upwards_data_queue;
|
||||
|
||||
command_waiting_response_t cmd_waiting_q;
|
||||
|
||||
/*
|
||||
|
@ -135,20 +132,23 @@ void hci_shut_down(void)
|
|||
}
|
||||
|
||||
|
||||
void hci_host_task_post(task_post_t timeout)
|
||||
task_post_status_t hci_host_task_post(task_post_t timeout)
|
||||
{
|
||||
BtTaskEvt_t evt;
|
||||
|
||||
if (hci_host_startup_flag == false) {
|
||||
return;
|
||||
return TASK_POST_FAIL;
|
||||
}
|
||||
|
||||
evt.sig = 0xff;
|
||||
evt.sig = SIG_HCI_HOST_SEND_AVAILABLE;
|
||||
evt.par = 0;
|
||||
|
||||
if (xQueueSend(xHciHostQueue, &evt, timeout) != pdTRUE) {
|
||||
LOG_ERROR("xHciHostQueue failed\n");
|
||||
return TASK_POST_FAIL;
|
||||
}
|
||||
|
||||
return TASK_POST_SUCCESS;
|
||||
}
|
||||
|
||||
static int hci_layer_init_env(void)
|
||||
|
@ -227,7 +227,7 @@ static void hci_host_thread_handler(void *arg)
|
|||
for (;;) {
|
||||
if (pdTRUE == xQueueReceive(xHciHostQueue, &e, (portTickType)portMAX_DELAY)) {
|
||||
|
||||
if (e.sig == 0xff) {
|
||||
if (e.sig == SIG_HCI_HOST_SEND_AVAILABLE) {
|
||||
if (esp_vhci_host_check_send_available()) {
|
||||
/*Now Target only allowed one packet per TX*/
|
||||
BT_HDR *pkt = packet_fragmenter->fragment_current_packet();
|
||||
|
@ -247,11 +247,6 @@ static void hci_host_thread_handler(void *arg)
|
|||
}
|
||||
}
|
||||
|
||||
static void set_data_queue(fixed_queue_t *queue)
|
||||
{
|
||||
hci_host_env.upwards_data_queue = queue;
|
||||
}
|
||||
|
||||
static void transmit_command(
|
||||
BT_HDR *command,
|
||||
command_complete_cb complete_callback,
|
||||
|
@ -311,7 +306,7 @@ static void transmit_downward(uint16_t type, void *data)
|
|||
} else {
|
||||
fixed_queue_enqueue(hci_host_env.packet_queue, data);
|
||||
}
|
||||
//ke_event_set(KE_EVENT_HCI_HOST_THREAD);
|
||||
|
||||
hci_host_task_post(TASK_POST_BLOCKING);
|
||||
}
|
||||
|
||||
|
@ -495,7 +490,6 @@ intercepted:
|
|||
!fixed_queue_is_empty(hci_host_env.command_queue)) {
|
||||
hci_host_task_post(TASK_POST_BLOCKING);
|
||||
}
|
||||
//ke_event_set(KE_EVENT_HCI_HOST_THREAD);
|
||||
|
||||
if (wait_entry) {
|
||||
// If it has a callback, it's responsible for freeing the packet
|
||||
|
@ -521,13 +515,8 @@ intercepted:
|
|||
static void dispatch_reassembled(BT_HDR *packet)
|
||||
{
|
||||
// Events should already have been dispatched before this point
|
||||
|
||||
if (hci_host_env.upwards_data_queue) {
|
||||
fixed_queue_enqueue(hci_host_env.upwards_data_queue, packet);
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
//Tell Up-layer received packet.
|
||||
} else {
|
||||
LOG_DEBUG("%s had no queue to place upwards data packet in. Dropping it on the floor.", __func__);
|
||||
//Tell Up-layer received packet.
|
||||
if (btu_task_post(SIG_BTU_HCI_MSG, packet, TASK_POST_BLOCKING) != TASK_POST_SUCCESS) {
|
||||
buffer_allocator->free(packet);
|
||||
}
|
||||
}
|
||||
|
@ -576,7 +565,6 @@ static waiting_command_t *get_waiting_command(command_opcode_t opcode)
|
|||
static void init_layer_interface()
|
||||
{
|
||||
if (!interface_created) {
|
||||
interface.set_data_queue = set_data_queue;
|
||||
interface.transmit_command = transmit_command;
|
||||
interface.transmit_command_futured = transmit_command_futured;
|
||||
interface.transmit_downward = transmit_downward;
|
||||
|
|
|
@ -77,9 +77,6 @@ typedef struct hci_t {
|
|||
// Do the postload sequence (call after the rest of the BT stack initializes).
|
||||
void (*do_postload)(void);
|
||||
|
||||
// Set the queue to receive ACL data in
|
||||
void (*set_data_queue)(fixed_queue_t *queue);
|
||||
|
||||
// Send a command through the HCI layer
|
||||
void (*transmit_command)(
|
||||
BT_HDR *command,
|
||||
|
|
|
@ -32,56 +32,16 @@
|
|||
#include "bt_trace.h"
|
||||
#include "osi.h"
|
||||
#include "alarm.h"
|
||||
#include "fixed_queue.h"
|
||||
#include "hash_map.h"
|
||||
#include "hash_functions.h"
|
||||
#include "controller.h"
|
||||
#include "hci_layer.h"
|
||||
#include "bta_api.h"
|
||||
|
||||
//#include "bluedroid_test.h"
|
||||
/*
|
||||
#define LOG_TAG "bt_main"
|
||||
|
||||
#include <cutils/properties.h>
|
||||
#include <fcntl.h>
|
||||
#include <hardware/bluetooth.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "osi/include/alarm.h"
|
||||
#include "bta_api.h"
|
||||
#include "bt_hci_bdroid.h"
|
||||
#include "bte.h"
|
||||
#include "btif_common.h"
|
||||
#include "btu.h"
|
||||
#include "btsnoop.h"
|
||||
#include "bt_utils.h"
|
||||
#include "btcore/include/counter.h"
|
||||
#include "btcore/include/module.h"
|
||||
#include "osi/include/fixed_queue.h"
|
||||
#include "osi/include/future.h"
|
||||
#include "gki.h"
|
||||
#include "osi/include/hash_functions.h"
|
||||
#include "osi/include/hash_map.h"
|
||||
#include "hci_layer.h"
|
||||
#include "osi/include/osi.h"
|
||||
#include "osi/include/log.h"
|
||||
#include "stack_config.h"
|
||||
#include "osi/include/thread.h"
|
||||
*/
|
||||
/*******************************************************************************
|
||||
** Constants & Macros
|
||||
*******************************************************************************/
|
||||
|
||||
/* Run-time configuration file for BLE*/
|
||||
/*
|
||||
#ifndef BTE_BLE_STACK_CONF_FILE
|
||||
#define BTE_BLE_STACK_CONF_FILE "/etc/bluetooth/ble_stack.conf"
|
||||
#endif
|
||||
*/
|
||||
/******************************************************************************
|
||||
** Variables
|
||||
******************************************************************************/
|
||||
|
@ -100,8 +60,6 @@ static void bte_main_enable(void);
|
|||
/*******************************************************************************
|
||||
** Externs
|
||||
*******************************************************************************/
|
||||
//extern void bte_load_ble_conf(const char *p_path);
|
||||
fixed_queue_t *btu_hci_msg_queue;
|
||||
|
||||
bluedroid_init_done_cb_t bluedroid_init_done_cb;
|
||||
|
||||
|
@ -128,18 +86,8 @@ int bte_main_boot_entry(bluedroid_init_done_cb_t cb)
|
|||
return -2;
|
||||
}
|
||||
|
||||
btu_hci_msg_queue = fixed_queue_new(SIZE_MAX);
|
||||
if (btu_hci_msg_queue == NULL) {
|
||||
LOG_ERROR("%s unable to allocate hci message queue.\n", __func__);
|
||||
return -3;
|
||||
}
|
||||
|
||||
bluedroid_init_done_cb = cb;
|
||||
|
||||
//Caution: No event dispatcher defined now in hci layer
|
||||
//data_dispatcher_register_default(hci->event_dispatcher, btu_hci_msg_queue);
|
||||
hci->set_data_queue(btu_hci_msg_queue);
|
||||
|
||||
//Enbale HCI
|
||||
bte_main_enable();
|
||||
|
||||
|
@ -157,20 +105,6 @@ int bte_main_boot_entry(bluedroid_init_done_cb_t cb)
|
|||
******************************************************************************/
|
||||
void bte_main_shutdown(void)
|
||||
{
|
||||
//data_dispatcher_register_default(hci_layer_get_interface()->event_dispatcher, NULL);
|
||||
hci->set_data_queue(NULL);
|
||||
fixed_queue_unregister_dequeue(btu_hci_msg_queue);
|
||||
fixed_queue_free(btu_hci_msg_queue, NULL);
|
||||
|
||||
btu_hci_msg_queue = NULL;
|
||||
|
||||
/*
|
||||
module_clean_up(get_module(STACK_CONFIG_MODULE));
|
||||
|
||||
module_clean_up(get_module(COUNTER_MODULE));
|
||||
module_clean_up(get_module(GKI_MODULE));
|
||||
*/
|
||||
|
||||
#if (BLE_INCLUDED == TRUE)
|
||||
BTA_VendorCleanup();
|
||||
#endif
|
||||
|
|
|
@ -35,12 +35,27 @@ typedef struct bt_task_evt BtTaskEvt_t;
|
|||
|
||||
typedef bt_status_t (* BtTaskCb_t)(void *arg);
|
||||
|
||||
enum {
|
||||
SIG_PRF_START_UP = 0xfc,
|
||||
SIG_PRF_WORK = 0xfd,
|
||||
SIG_BTU_START_UP = 0xfe,
|
||||
SIG_BTU_WORK = 0xff,
|
||||
};
|
||||
typedef enum {
|
||||
SIG_HCI_HAL_RECV_PACKET = 0,
|
||||
SIG_HCI_HAL_NUM,
|
||||
} SIG_HCI_HAL_t;
|
||||
|
||||
|
||||
typedef enum {
|
||||
SIG_HCI_HOST_SEND_AVAILABLE = 0,
|
||||
SIG_HCI_HOST_NUM,
|
||||
} SIG_HCI_HOST_t;
|
||||
|
||||
typedef enum {
|
||||
SIG_BTU_START_UP = 0,
|
||||
SIG_BTU_HCI_MSG,
|
||||
SIG_BTU_BTA_MSG,
|
||||
SIG_BTU_BTA_ALARM,
|
||||
SIG_BTU_GENERAL_ALARM,
|
||||
SIG_BTU_ONESHOT_ALARM,
|
||||
SIG_BTU_L2CAP_ALARM,
|
||||
SIG_BTU_NUM,
|
||||
} SIG_BTU_t;
|
||||
|
||||
#define HCI_HOST_TASK_STACK_SIZE (2048 + BT_TASK_EXTRA_STACK_SIZE)
|
||||
#define HCI_HOST_TASK_PRIO (configMAX_PRIORITIES - 3)
|
||||
|
@ -67,9 +82,13 @@ enum {
|
|||
#define TASK_POST_BLOCKING (portMAX_DELAY)
|
||||
typedef uint32_t task_post_t; /* Timeout of task post return, unit TICK */
|
||||
|
||||
void btu_task_post(uint32_t sig, task_post_t timeout);
|
||||
void hci_host_task_post(task_post_t timeout);
|
||||
void hci_hal_h4_task_post(task_post_t timeout);
|
||||
typedef enum {
|
||||
TASK_POST_SUCCESS = 0,
|
||||
TASK_POST_FAIL,
|
||||
} task_post_status_t;
|
||||
|
||||
task_post_status_t btu_task_post(uint32_t sig, void *param, task_post_t timeout);
|
||||
task_post_status_t hci_host_task_post(task_post_t timeout);
|
||||
task_post_status_t hci_hal_h4_task_post(task_post_t timeout);
|
||||
|
||||
#endif /* __THREAD_H__ */
|
||||
|
|
|
@ -60,6 +60,10 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p)
|
|||
btsnd_hcic_ble_set_random_addr(p_cb->private_addr);
|
||||
|
||||
p_cb->own_addr_type = BLE_ADDR_RANDOM;
|
||||
if (p_cb->set_local_privacy_cback){
|
||||
(*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_SUCCESS);
|
||||
p_cb->set_local_privacy_cback = NULL;
|
||||
}
|
||||
|
||||
/* start a periodical timer to refresh random addr */
|
||||
btu_stop_timer_oneshot(&p_cb->raddr_timer_ent);
|
||||
|
@ -73,6 +77,10 @@ static void btm_gen_resolve_paddr_cmpl(tSMP_ENC *p)
|
|||
} else {
|
||||
/* random address set failure */
|
||||
BTM_TRACE_DEBUG("set random address failed");
|
||||
if (p_cb->set_local_privacy_cback){
|
||||
(*p_cb->set_local_privacy_cback)(BTM_SET_PRIVACY_FAIL);
|
||||
p_cb->set_local_privacy_cback = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
|
|
|
@ -640,10 +640,16 @@ void BTM_BleEnableMixedPrivacyMode(BOOLEAN mixed_on)
|
|||
** Returns BOOLEAN privacy mode set success; otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode)
|
||||
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN privacy_mode, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback)
|
||||
{
|
||||
#if BLE_PRIVACY_SPT == TRUE
|
||||
tBTM_BLE_CB *p_cb = &btm_cb.ble_ctr_cb;
|
||||
tBTM_LE_RANDOM_CB *random_cb = &btm_cb.ble_ctr_cb.addr_mgnt_cb;
|
||||
if (random_cb){
|
||||
random_cb->set_local_privacy_cback = set_local_privacy_cback;
|
||||
}else{
|
||||
BTM_TRACE_ERROR("%s,random_cb = NULL", __func__);
|
||||
}
|
||||
|
||||
BTM_TRACE_EVENT ("%s\n", __func__);
|
||||
|
||||
|
|
|
@ -47,7 +47,6 @@
|
|||
|
||||
// TODO(zachoverflow): remove this horrible hack
|
||||
#include "btu.h"
|
||||
extern fixed_queue_t *btu_hci_msg_queue;
|
||||
|
||||
extern void btm_process_cancel_complete(UINT8 status, UINT8 mode);
|
||||
extern void btm_ble_test_command_complete(UINT8 *p);
|
||||
|
@ -1009,9 +1008,7 @@ static void btu_hcif_command_complete_evt(BT_HDR *response, void *context)
|
|||
|
||||
event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK;
|
||||
|
||||
fixed_queue_enqueue(btu_hci_msg_queue, event);
|
||||
// ke_event_set(KE_EVENT_BTU_TASK_THREAD);
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING);
|
||||
}
|
||||
|
||||
|
||||
|
@ -1209,9 +1206,7 @@ static void btu_hcif_command_status_evt(uint8_t status, BT_HDR *command, void *c
|
|||
|
||||
event->event = BTU_POST_TO_TASK_NO_GOOD_HORRIBLE_HACK;
|
||||
|
||||
fixed_queue_enqueue(btu_hci_msg_queue, event);
|
||||
//ke_event_set(KE_EVENT_BTU_TASK_THREAD);
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
btu_task_post(SIG_BTU_HCI_MSG, event, TASK_POST_BLOCKING);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "bt_trace.h"
|
||||
#include "controller.h"
|
||||
#include "alarm.h"
|
||||
#include "fixed_queue.h"
|
||||
#include "hash_map.h"
|
||||
#include "hash_functions.h"
|
||||
#include "thread.h"
|
||||
|
@ -44,28 +43,14 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
// extern fixed_queue_t *btif_msg_queue;
|
||||
|
||||
// Communication queue from bta thread to bt_workqueue.
|
||||
fixed_queue_t *btu_bta_msg_queue;
|
||||
|
||||
// Communication queue from hci thread to bt_workqueue.
|
||||
extern fixed_queue_t *btu_hci_msg_queue;
|
||||
|
||||
// General timer queue.
|
||||
fixed_queue_t *btu_general_alarm_queue;
|
||||
hash_map_t *btu_general_alarm_hash_map;
|
||||
pthread_mutex_t btu_general_alarm_lock;
|
||||
static const size_t BTU_GENERAL_ALARM_HASH_MAP_SIZE = 34;
|
||||
|
||||
// Oneshot timer queue.
|
||||
fixed_queue_t *btu_oneshot_alarm_queue;
|
||||
hash_map_t *btu_oneshot_alarm_hash_map;
|
||||
pthread_mutex_t btu_oneshot_alarm_lock;
|
||||
static const size_t BTU_ONESHOT_ALARM_HASH_MAP_SIZE = 34;
|
||||
|
||||
// l2cap timer queue.
|
||||
fixed_queue_t *btu_l2cap_alarm_queue;
|
||||
hash_map_t *btu_l2cap_alarm_hash_map;
|
||||
pthread_mutex_t btu_l2cap_alarm_lock;
|
||||
static const size_t BTU_L2CAP_ALARM_HASH_MAP_SIZE = 34;
|
||||
|
@ -156,11 +141,6 @@ void BTU_StartUp(void)
|
|||
memset (&btu_cb, 0, sizeof (tBTU_CB));
|
||||
btu_cb.trace_level = HCI_INITIAL_TRACE_LEVEL;
|
||||
|
||||
btu_bta_msg_queue = fixed_queue_new(SIZE_MAX);
|
||||
if (btu_bta_msg_queue == NULL) {
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
btu_general_alarm_hash_map = hash_map_new(BTU_GENERAL_ALARM_HASH_MAP_SIZE,
|
||||
hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
|
||||
if (btu_general_alarm_hash_map == NULL) {
|
||||
|
@ -169,11 +149,6 @@ void BTU_StartUp(void)
|
|||
|
||||
pthread_mutex_init(&btu_general_alarm_lock, NULL);
|
||||
|
||||
btu_general_alarm_queue = fixed_queue_new(SIZE_MAX);
|
||||
if (btu_general_alarm_queue == NULL) {
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
btu_oneshot_alarm_hash_map = hash_map_new(BTU_ONESHOT_ALARM_HASH_MAP_SIZE,
|
||||
hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
|
||||
if (btu_oneshot_alarm_hash_map == NULL) {
|
||||
|
@ -182,11 +157,6 @@ void BTU_StartUp(void)
|
|||
|
||||
pthread_mutex_init(&btu_oneshot_alarm_lock, NULL);
|
||||
|
||||
btu_oneshot_alarm_queue = fixed_queue_new(SIZE_MAX);
|
||||
if (btu_oneshot_alarm_queue == NULL) {
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
btu_l2cap_alarm_hash_map = hash_map_new(BTU_L2CAP_ALARM_HASH_MAP_SIZE,
|
||||
hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL);
|
||||
if (btu_l2cap_alarm_hash_map == NULL) {
|
||||
|
@ -195,18 +165,11 @@ void BTU_StartUp(void)
|
|||
|
||||
pthread_mutex_init(&btu_l2cap_alarm_lock, NULL);
|
||||
|
||||
btu_l2cap_alarm_queue = fixed_queue_new(SIZE_MAX);
|
||||
if (btu_l2cap_alarm_queue == NULL) {
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
xBtuQueue = xQueueCreate(BTU_QUEUE_NUM, sizeof(BtTaskEvt_t));
|
||||
xTaskCreatePinnedToCore(btu_task_thread_handler, BTU_TASK_NAME, BTU_TASK_STACK_SIZE, NULL, BTU_TASK_PRIO, &xBtuTaskHandle, 0);
|
||||
btu_task_post(SIG_BTU_START_UP, TASK_POST_BLOCKING);
|
||||
/*
|
||||
// Continue startup on bt workqueue thread.
|
||||
thread_post(bt_workqueue_thread, btu_task_start_up, NULL);
|
||||
*/
|
||||
|
||||
btu_task_post(SIG_BTU_START_UP, NULL, TASK_POST_BLOCKING);
|
||||
|
||||
return;
|
||||
|
||||
error_exit:;
|
||||
|
@ -218,36 +181,24 @@ void BTU_ShutDown(void)
|
|||
{
|
||||
btu_task_shut_down();
|
||||
|
||||
fixed_queue_free(btu_bta_msg_queue, NULL);
|
||||
|
||||
hash_map_free(btu_general_alarm_hash_map);
|
||||
pthread_mutex_destroy(&btu_general_alarm_lock);
|
||||
fixed_queue_free(btu_general_alarm_queue, NULL);
|
||||
|
||||
hash_map_free(btu_oneshot_alarm_hash_map);
|
||||
pthread_mutex_destroy(&btu_oneshot_alarm_lock);
|
||||
fixed_queue_free(btu_oneshot_alarm_queue, NULL);
|
||||
|
||||
hash_map_free(btu_l2cap_alarm_hash_map);
|
||||
pthread_mutex_destroy(&btu_l2cap_alarm_lock);
|
||||
fixed_queue_free(btu_l2cap_alarm_queue, NULL);
|
||||
|
||||
//thread_free(bt_workqueue_thread);
|
||||
vTaskDelete(xBtuTaskHandle);
|
||||
vQueueDelete(xBtuQueue);
|
||||
|
||||
btu_bta_msg_queue = NULL;
|
||||
|
||||
btu_general_alarm_hash_map = NULL;
|
||||
btu_general_alarm_queue = NULL;
|
||||
|
||||
btu_oneshot_alarm_hash_map = NULL;
|
||||
btu_oneshot_alarm_queue = NULL;
|
||||
|
||||
btu_l2cap_alarm_hash_map = NULL;
|
||||
btu_l2cap_alarm_queue = NULL;
|
||||
|
||||
// bt_workqueue_thread = NULL;
|
||||
xBtuTaskHandle = NULL;
|
||||
xBtuQueue = 0;
|
||||
}
|
||||
|
@ -269,21 +220,3 @@ UINT16 BTU_BleAclPktSize(void)
|
|||
return 0;
|
||||
#endif
|
||||
}
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btu_uipc_rx_cback
|
||||
**
|
||||
** Description
|
||||
**
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
*******************************************************************************/
|
||||
/*
|
||||
void btu_uipc_rx_cback(BT_HDR *p_msg) {
|
||||
assert(p_msg != NULL);
|
||||
BT_TRACE(TRACE_LAYER_BTM, TRACE_TYPE_DEBUG, "btu_uipc_rx_cback event 0x%x,"
|
||||
" len %d, offset %d", p_msg->event, p_msg->len, p_msg->offset);
|
||||
fixed_queue_enqueue(btu_hci_msg_queue, p_msg);
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include "btm_api.h"
|
||||
#include "btm_int.h"
|
||||
#include "btu.h"
|
||||
#include "fixed_queue.h"
|
||||
#include "gki.h"
|
||||
#include "hash_map.h"
|
||||
#include "hcimsgs.h"
|
||||
|
@ -94,34 +93,17 @@ extern void BTE_InitStack(void);
|
|||
tBTU_CB btu_cb;
|
||||
#endif
|
||||
|
||||
// Communication queue between btu_task and bta.
|
||||
extern fixed_queue_t *btu_bta_msg_queue;
|
||||
|
||||
// alarm queue between btu_task and bta
|
||||
extern fixed_queue_t *btu_bta_alarm_queue;
|
||||
|
||||
// Communication queue between btu_task and hci.
|
||||
extern fixed_queue_t *btu_hci_msg_queue;
|
||||
|
||||
// General timer queue.
|
||||
extern fixed_queue_t *btu_general_alarm_queue;
|
||||
extern hash_map_t *btu_general_alarm_hash_map;
|
||||
extern pthread_mutex_t btu_general_alarm_lock;
|
||||
|
||||
// Oneshot timer queue.
|
||||
extern fixed_queue_t *btu_oneshot_alarm_queue;
|
||||
extern hash_map_t *btu_oneshot_alarm_hash_map;
|
||||
extern pthread_mutex_t btu_oneshot_alarm_lock;
|
||||
|
||||
// l2cap timer queue.
|
||||
extern fixed_queue_t *btu_l2cap_alarm_queue;
|
||||
extern hash_map_t *btu_l2cap_alarm_hash_map;
|
||||
extern pthread_mutex_t btu_l2cap_alarm_lock;
|
||||
|
||||
extern fixed_queue_t *event_queue;
|
||||
//extern fixed_queue_t *btif_msg_queue;
|
||||
|
||||
//extern thread_t *bt_workqueue_thread;
|
||||
extern xTaskHandle xBtuTaskHandle;
|
||||
extern xQueueHandle xBtuQueue;
|
||||
extern bluedroid_init_done_cb_t bluedroid_init_done_cb;
|
||||
|
@ -137,87 +119,6 @@ static void btu_hci_msg_process(BT_HDR *p_msg);
|
|||
static void btu_bta_alarm_process(TIMER_LIST_ENT *p_tle);
|
||||
#endif
|
||||
|
||||
void btu_hci_msg_ready(fixed_queue_t *queue)
|
||||
{
|
||||
BT_HDR *p_msg;
|
||||
|
||||
while (!fixed_queue_is_empty(queue)) {
|
||||
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
||||
btu_hci_msg_process(p_msg);
|
||||
}
|
||||
}
|
||||
|
||||
void btu_general_alarm_ready(fixed_queue_t *queue)
|
||||
{
|
||||
TIMER_LIST_ENT *p_tle;
|
||||
|
||||
while (!fixed_queue_is_empty(queue)) {
|
||||
p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue);
|
||||
btu_general_alarm_process(p_tle);
|
||||
}
|
||||
}
|
||||
|
||||
void btu_oneshot_alarm_ready(fixed_queue_t *queue)
|
||||
{
|
||||
TIMER_LIST_ENT *p_tle;
|
||||
|
||||
while (!fixed_queue_is_empty(queue)) {
|
||||
p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue);
|
||||
btu_general_alarm_process(p_tle);
|
||||
|
||||
switch (p_tle->event) {
|
||||
#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
|
||||
case BTU_TTYPE_BLE_RANDOM_ADDR:
|
||||
btm_ble_timeout(p_tle);
|
||||
break;
|
||||
#endif
|
||||
case BTU_TTYPE_USER_FUNC: {
|
||||
tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param;
|
||||
(*p_uf)(p_tle);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// FAIL
|
||||
LOG_ERROR("Received unexpected oneshot timer event:0x%x\n",
|
||||
p_tle->event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void btu_l2cap_alarm_ready(fixed_queue_t *queue)
|
||||
{
|
||||
TIMER_LIST_ENT *p_tle;
|
||||
|
||||
while (!fixed_queue_is_empty(queue)) {
|
||||
p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue);
|
||||
btu_l2cap_alarm_process(p_tle);
|
||||
}
|
||||
}
|
||||
|
||||
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
||||
void btu_bta_msg_ready(fixed_queue_t *queue)
|
||||
{
|
||||
BT_HDR *p_msg;
|
||||
|
||||
while (!fixed_queue_is_empty(queue)) {
|
||||
p_msg = (BT_HDR *)fixed_queue_dequeue(queue);
|
||||
bta_sys_event(p_msg);
|
||||
}
|
||||
}
|
||||
|
||||
void btu_bta_alarm_ready(fixed_queue_t *queue)
|
||||
{
|
||||
TIMER_LIST_ENT *p_tle;
|
||||
|
||||
while (!fixed_queue_is_empty(queue)) {
|
||||
p_tle = (TIMER_LIST_ENT *)fixed_queue_dequeue(queue);
|
||||
btu_bta_alarm_process(p_tle);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void btu_hci_msg_process(BT_HDR *p_msg)
|
||||
{
|
||||
/* Determine the input message type. */
|
||||
|
@ -317,47 +218,74 @@ void btu_task_thread_handler(void *arg)
|
|||
for (;;) {
|
||||
if (pdTRUE == xQueueReceive(xBtuQueue, &e, (portTickType)portMAX_DELAY)) {
|
||||
|
||||
if (e.sig == SIG_BTU_WORK) {
|
||||
fixed_queue_process(btu_hci_msg_queue);
|
||||
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
||||
fixed_queue_process(btu_bta_msg_queue);
|
||||
fixed_queue_process(btu_bta_alarm_queue);
|
||||
#endif
|
||||
fixed_queue_process(btu_general_alarm_queue);
|
||||
fixed_queue_process(btu_oneshot_alarm_queue);
|
||||
fixed_queue_process(btu_l2cap_alarm_queue);
|
||||
} else if (e.sig == SIG_BTU_START_UP) {
|
||||
switch (e.sig) {
|
||||
case SIG_BTU_START_UP:
|
||||
btu_task_start_up();
|
||||
break;
|
||||
case SIG_BTU_HCI_MSG:
|
||||
btu_hci_msg_process((BT_HDR *)e.par);
|
||||
break;
|
||||
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
||||
case SIG_BTU_BTA_MSG:
|
||||
bta_sys_event((BT_HDR *)e.par);
|
||||
break;
|
||||
case SIG_BTU_BTA_ALARM:
|
||||
btu_bta_alarm_process((TIMER_LIST_ENT *)e.par);
|
||||
break;
|
||||
#endif
|
||||
case SIG_BTU_GENERAL_ALARM:
|
||||
btu_general_alarm_process((TIMER_LIST_ENT *)e.par);
|
||||
break;
|
||||
case SIG_BTU_ONESHOT_ALARM: {
|
||||
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)e.par;
|
||||
btu_general_alarm_process(p_tle);
|
||||
|
||||
switch (p_tle->event) {
|
||||
#if (defined(BLE_INCLUDED) && BLE_INCLUDED == TRUE)
|
||||
case BTU_TTYPE_BLE_RANDOM_ADDR:
|
||||
btm_ble_timeout(p_tle);
|
||||
break;
|
||||
#endif
|
||||
case BTU_TTYPE_USER_FUNC: {
|
||||
tUSER_TIMEOUT_FUNC *p_uf = (tUSER_TIMEOUT_FUNC *)p_tle->param;
|
||||
(*p_uf)(p_tle);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// FAIL
|
||||
LOG_ERROR("Received unexpected oneshot timer event:0x%x\n", p_tle->event);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SIG_BTU_L2CAP_ALARM:
|
||||
btu_l2cap_alarm_process((TIMER_LIST_ENT *)e.par);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void btu_task_post(uint32_t sig, task_post_t timeout)
|
||||
task_post_status_t btu_task_post(uint32_t sig, void *param, task_post_t timeout)
|
||||
{
|
||||
BtTaskEvt_t evt;
|
||||
|
||||
evt.sig = sig;
|
||||
evt.par = 0;
|
||||
evt.par = param;
|
||||
|
||||
if (xQueueSend(xBtuQueue, &evt, timeout) != pdTRUE) {
|
||||
LOG_ERROR("xBtuQueue failed\n");
|
||||
return TASK_POST_FAIL;
|
||||
}
|
||||
|
||||
return TASK_POST_SUCCESS;
|
||||
}
|
||||
|
||||
void btu_task_start_up(void)
|
||||
{
|
||||
|
||||
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
||||
fixed_queue_register_dequeue(btu_bta_msg_queue, btu_bta_msg_ready);
|
||||
#endif
|
||||
|
||||
fixed_queue_register_dequeue(btu_hci_msg_queue, btu_hci_msg_ready);
|
||||
fixed_queue_register_dequeue(btu_general_alarm_queue, btu_general_alarm_ready);
|
||||
fixed_queue_register_dequeue(btu_oneshot_alarm_queue, btu_oneshot_alarm_ready);
|
||||
fixed_queue_register_dequeue(btu_l2cap_alarm_queue, btu_l2cap_alarm_ready);
|
||||
|
||||
/* Initialize the mandatory core stack control blocks
|
||||
(BTU, BTM, L2CAP, and SDP)
|
||||
*/
|
||||
|
@ -381,12 +309,7 @@ void btu_task_start_up(void)
|
|||
|
||||
void btu_task_shut_down(void)
|
||||
{
|
||||
fixed_queue_unregister_dequeue(btu_general_alarm_queue);
|
||||
fixed_queue_unregister_dequeue(btu_oneshot_alarm_queue);
|
||||
fixed_queue_unregister_dequeue(btu_l2cap_alarm_queue);
|
||||
|
||||
#if (defined(BTA_INCLUDED) && BTA_INCLUDED == TRUE)
|
||||
fixed_queue_unregister_dequeue(btu_bta_msg_queue);
|
||||
bta_sys_free();
|
||||
#endif
|
||||
|
||||
|
@ -515,9 +438,7 @@ void btu_general_alarm_cb(void *data)
|
|||
assert(data != NULL);
|
||||
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
|
||||
|
||||
fixed_queue_enqueue(btu_general_alarm_queue, p_tle);
|
||||
//ke_event_set(KE_EVENT_BTU_TASK_THREAD);
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
btu_task_post(SIG_BTU_GENERAL_ALARM, p_tle, TASK_POST_BLOCKING);
|
||||
}
|
||||
|
||||
void btu_start_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_sec)
|
||||
|
@ -606,9 +527,7 @@ static void btu_l2cap_alarm_cb(void *data)
|
|||
assert(data != NULL);
|
||||
TIMER_LIST_ENT *p_tle = (TIMER_LIST_ENT *)data;
|
||||
|
||||
fixed_queue_enqueue(btu_l2cap_alarm_queue, p_tle);
|
||||
//ke_event_set(KE_EVENT_BTU_TASK_THREAD);
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
btu_task_post(SIG_BTU_L2CAP_ALARM, p_tle, TASK_POST_BLOCKING);
|
||||
}
|
||||
|
||||
void btu_start_quick_timer(TIMER_LIST_ENT *p_tle, UINT16 type, UINT32 timeout_ticks)
|
||||
|
@ -674,9 +593,7 @@ void btu_oneshot_alarm_cb(void *data)
|
|||
|
||||
btu_stop_timer_oneshot(p_tle);
|
||||
|
||||
fixed_queue_enqueue(btu_oneshot_alarm_queue, p_tle);
|
||||
//ke_event_set(KE_EVENT_BTU_TASK_THREAD);
|
||||
btu_task_post(SIG_BTU_WORK, TASK_POST_BLOCKING);
|
||||
btu_task_post(SIG_BTU_ONESHOT_ALARM, p_tle, TASK_POST_BLOCKING);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -69,7 +69,9 @@ enum {
|
|||
BTM_REPEATED_ATTEMPTS, /* 19 repeated attempts for LE security requests */
|
||||
BTM_MODE4_LEVEL4_NOT_SUPPORTED, /* 20 Secure Connections Only Mode can't be supported */
|
||||
BTM_PEER_LE_DATA_LEN_UNSUPPORTED, /* 21 peer setting data length is unsupported*/
|
||||
BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED /* 22 controller setting data length is unsupported*/
|
||||
BTM_CONTROL_LE_DATA_LEN_UNSUPPORTED,/* 22 controller setting data length is unsupported*/
|
||||
BTM_SET_PRIVACY_SUCCESS, /* 23 enable/disable local privacy success */
|
||||
BTM_SET_PRIVACY_FAIL, /* 24 enable/disable local privacy failed*/
|
||||
};
|
||||
|
||||
typedef uint8_t tBTM_STATUS;
|
||||
|
@ -175,6 +177,8 @@ typedef void (tBTM_UPDATE_CONN_PARAM_CBACK) (UINT8 status, BD_ADDR bd_addr, tBTM
|
|||
|
||||
typedef void (tBTM_SET_PKT_DATA_LENGTH_CBACK) (UINT8 status, tBTM_LE_SET_PKT_DATA_LENGTH_PARAMS *data_length_params);
|
||||
|
||||
typedef void (tBTM_SET_LOCAL_PRIVACY_CBACK) (UINT8 status);
|
||||
|
||||
|
||||
/*****************************************************************************
|
||||
** DEVICE DISCOVERY - Inquiry, Remote Name, Discovery, Class of Device
|
||||
|
|
|
@ -1596,7 +1596,7 @@ tBTM_STATUS BTM_BleBroadcast(BOOLEAN start);
|
|||
**
|
||||
*******************************************************************************/
|
||||
//extern
|
||||
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable);
|
||||
BOOLEAN BTM_BleConfigPrivacy(BOOLEAN enable, tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cabck);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
|
|
|
@ -185,6 +185,7 @@ typedef struct {
|
|||
tBTM_BLE_ADDR_CBACK *p_generate_cback;
|
||||
void *p;
|
||||
TIMER_LIST_ENT raddr_timer_ent;
|
||||
tBTM_SET_LOCAL_PRIVACY_CBACK *set_local_privacy_cback;
|
||||
} tBTM_LE_RANDOM_CB;
|
||||
|
||||
#define BTM_BLE_MAX_BG_CONN_DEV_NUM 10
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 10942b2ff00f7db473c1917f76be93e59730e73f
|
||||
Subproject commit 4e3a5769d3c4eba23381a647dd781a32813e4335
|
|
@ -456,3 +456,29 @@ esp_err_t gpio_wakeup_disable(gpio_num_t gpio_num)
|
|||
GPIO.pin[gpio_num].wakeup_enable = 0;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength)
|
||||
{
|
||||
GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
GPIO_CHECK(strength < GPIO_DRIVE_CAP_MAX, "GPIO drive capability error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
|
||||
rtc_gpio_set_drive_capability(gpio_num, strength);
|
||||
} else {
|
||||
SET_PERI_REG_BITS(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, strength, FUN_DRV_S);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength)
|
||||
{
|
||||
GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
GPIO_CHECK(strength != NULL, "GPIO drive capability pointer error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
if (RTC_GPIO_IS_VALID_GPIO(gpio_num)) {
|
||||
return rtc_gpio_get_drive_capability(gpio_num, strength);
|
||||
} else {
|
||||
*strength = GET_PERI_REG_BITS2(GPIO_PIN_MUX_REG[gpio_num], FUN_DRV_V, FUN_DRV_S);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
|
|
@ -219,6 +219,14 @@ typedef enum {
|
|||
GPIO_FLOATING, /*!< Pad floating */
|
||||
} gpio_pull_mode_t;
|
||||
|
||||
typedef enum {
|
||||
GPIO_DRIVE_CAP_0 = 0, /*!< Pad drive capability: weak */
|
||||
GPIO_DRIVE_CAP_1 = 1, /*!< Pad drive capability: stronger */
|
||||
GPIO_DRIVE_CAP_2 = 2, /*!< Pad drive capability: default value */
|
||||
GPIO_DRIVE_CAP_DEFAULT = 2, /*!< Pad drive capability: default value */
|
||||
GPIO_DRIVE_CAP_3 = 3, /*!< Pad drive capability: strongest */
|
||||
GPIO_DRIVE_CAP_MAX,
|
||||
} gpio_drive_cap_t;
|
||||
|
||||
typedef void (*gpio_isr_t)(void*);
|
||||
typedef intr_handle_t gpio_isr_handle_t;
|
||||
|
@ -481,6 +489,29 @@ esp_err_t gpio_isr_handler_add(gpio_num_t gpio_num, gpio_isr_t isr_handler, void
|
|||
*/
|
||||
esp_err_t gpio_isr_handler_remove(gpio_num_t gpio_num);
|
||||
|
||||
/**
|
||||
* @brief Set GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength);
|
||||
|
||||
/**
|
||||
* @brief Get GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Pointer to accept drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -40,6 +40,8 @@ typedef struct {
|
|||
uint32_t slpie; /*!< Mask of input enable in sleep mode */
|
||||
uint32_t hold; /*!< Mask of hold enable */
|
||||
uint32_t hold_force;/*!< Mask of hold_force bit for RTC IO in RTC_CNTL_HOLD_FORCE_REG */
|
||||
uint32_t drv_v; /*!< Mask of drive capability */
|
||||
uint32_t drv_s; /*!< Offset of drive capability */
|
||||
int rtc_num; /*!< RTC IO number, or -1 if not an RTC GPIO */
|
||||
} rtc_gpio_desc_t;
|
||||
|
||||
|
@ -232,6 +234,29 @@ esp_err_t rtc_gpio_hold_dis(gpio_num_t gpio_num);
|
|||
*/
|
||||
void rtc_gpio_force_hold_dis_all();
|
||||
|
||||
/**
|
||||
* @brief Set RTC GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength);
|
||||
|
||||
/**
|
||||
* @brief Get RTC GPIO pad drive capability
|
||||
*
|
||||
* @param gpio_num GPIO number, only support output GPIOs
|
||||
* @param strength Pointer to accept drive capability of the pad
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -142,6 +142,8 @@ esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz);
|
|||
* can call sdmmc_host_do_transaction as long as other sdmmc_host_*
|
||||
* functions are not called.
|
||||
*
|
||||
* @attention Data buffer passed in cmdinfo->data must be in DMA capable memory
|
||||
*
|
||||
* @param slot slot number (SDMMC_HOST_SLOT_0 or SDMMC_HOST_SLOT_1)
|
||||
* @param cmdinfo pointer to structure describing command and data to transfer
|
||||
* @return
|
||||
|
@ -149,6 +151,8 @@ esp_err_t sdmmc_host_set_card_clk(int slot, uint32_t freq_khz);
|
|||
* - ESP_ERR_TIMEOUT if response or data transfer has timed out
|
||||
* - ESP_ERR_INVALID_CRC if response or data transfer CRC check has failed
|
||||
* - ESP_ERR_INVALID_RESPONSE if the card has sent an invalid response
|
||||
* - ESP_ERR_INVALID_SIZE if the size of data transfer is not valid in SD protocol
|
||||
* - ESP_ERR_INVALID_ARG if the data buffer is not in DMA capable memory
|
||||
*/
|
||||
esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo);
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "esp_intr_alloc.h"
|
||||
#include "sys/lock.h"
|
||||
#include "driver/rtc_cntl.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#ifndef NDEBUG
|
||||
// Enable built-in checks in queue.h in debug builds
|
||||
|
@ -54,46 +55,46 @@ static xSemaphoreHandle rtc_touch_sem = NULL;
|
|||
|
||||
//Reg,Mux,Fun,IE,Up,Down,Rtc_number
|
||||
const rtc_gpio_desc_t rtc_gpio_desc[GPIO_PIN_COUNT] = {
|
||||
{RTC_IO_TOUCH_PAD1_REG, RTC_IO_TOUCH_PAD1_MUX_SEL_M, RTC_IO_TOUCH_PAD1_FUN_SEL_S, RTC_IO_TOUCH_PAD1_FUN_IE_M, RTC_IO_TOUCH_PAD1_RUE_M, RTC_IO_TOUCH_PAD1_RDE_M, RTC_IO_TOUCH_PAD1_SLP_SEL_M, RTC_IO_TOUCH_PAD1_SLP_IE_M, RTC_IO_TOUCH_PAD1_HOLD_M, RTC_CNTL_TOUCH_PAD1_HOLD_FORCE_M, 11}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //1
|
||||
{RTC_IO_TOUCH_PAD2_REG, RTC_IO_TOUCH_PAD2_MUX_SEL_M, RTC_IO_TOUCH_PAD2_FUN_SEL_S, RTC_IO_TOUCH_PAD2_FUN_IE_M, RTC_IO_TOUCH_PAD2_RUE_M, RTC_IO_TOUCH_PAD2_RDE_M, RTC_IO_TOUCH_PAD2_SLP_SEL_M, RTC_IO_TOUCH_PAD2_SLP_IE_M, RTC_IO_TOUCH_PAD2_HOLD_M, RTC_CNTL_TOUCH_PAD2_HOLD_FORCE_M, 12}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //3
|
||||
{RTC_IO_TOUCH_PAD0_REG, RTC_IO_TOUCH_PAD0_MUX_SEL_M, RTC_IO_TOUCH_PAD0_FUN_SEL_S, RTC_IO_TOUCH_PAD0_FUN_IE_M, RTC_IO_TOUCH_PAD0_RUE_M, RTC_IO_TOUCH_PAD0_RDE_M, RTC_IO_TOUCH_PAD0_SLP_SEL_M, RTC_IO_TOUCH_PAD0_SLP_IE_M, RTC_IO_TOUCH_PAD0_HOLD_M, RTC_CNTL_TOUCH_PAD0_HOLD_FORCE_M, 10}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //10
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //11
|
||||
{RTC_IO_TOUCH_PAD5_REG, RTC_IO_TOUCH_PAD5_MUX_SEL_M, RTC_IO_TOUCH_PAD5_FUN_SEL_S, RTC_IO_TOUCH_PAD5_FUN_IE_M, RTC_IO_TOUCH_PAD5_RUE_M, RTC_IO_TOUCH_PAD5_RDE_M, RTC_IO_TOUCH_PAD5_SLP_SEL_M, RTC_IO_TOUCH_PAD5_SLP_IE_M, RTC_IO_TOUCH_PAD5_HOLD_M, RTC_CNTL_TOUCH_PAD5_HOLD_FORCE_M, 15}, //12
|
||||
{RTC_IO_TOUCH_PAD4_REG, RTC_IO_TOUCH_PAD4_MUX_SEL_M, RTC_IO_TOUCH_PAD4_FUN_SEL_S, RTC_IO_TOUCH_PAD4_FUN_IE_M, RTC_IO_TOUCH_PAD4_RUE_M, RTC_IO_TOUCH_PAD4_RDE_M, RTC_IO_TOUCH_PAD4_SLP_SEL_M, RTC_IO_TOUCH_PAD4_SLP_IE_M, RTC_IO_TOUCH_PAD4_HOLD_M, RTC_CNTL_TOUCH_PAD4_HOLD_FORCE_M, 14}, //13
|
||||
{RTC_IO_TOUCH_PAD6_REG, RTC_IO_TOUCH_PAD6_MUX_SEL_M, RTC_IO_TOUCH_PAD6_FUN_SEL_S, RTC_IO_TOUCH_PAD6_FUN_IE_M, RTC_IO_TOUCH_PAD6_RUE_M, RTC_IO_TOUCH_PAD6_RDE_M, RTC_IO_TOUCH_PAD6_SLP_SEL_M, RTC_IO_TOUCH_PAD6_SLP_IE_M, RTC_IO_TOUCH_PAD6_HOLD_M, RTC_CNTL_TOUCH_PAD6_HOLD_FORCE_M, 16}, //14
|
||||
{RTC_IO_TOUCH_PAD3_REG, RTC_IO_TOUCH_PAD3_MUX_SEL_M, RTC_IO_TOUCH_PAD3_FUN_SEL_S, RTC_IO_TOUCH_PAD3_FUN_IE_M, RTC_IO_TOUCH_PAD3_RUE_M, RTC_IO_TOUCH_PAD3_RDE_M, RTC_IO_TOUCH_PAD3_SLP_SEL_M, RTC_IO_TOUCH_PAD3_SLP_IE_M, RTC_IO_TOUCH_PAD3_HOLD_M, RTC_CNTL_TOUCH_PAD3_HOLD_FORCE_M, 13}, //15
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //16
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //17
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //18
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //19
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //20
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //21
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //22
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //23
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //24
|
||||
{RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_MUX_SEL_M, RTC_IO_PDAC1_FUN_SEL_S, RTC_IO_PDAC1_FUN_IE_M, RTC_IO_PDAC1_RUE_M, RTC_IO_PDAC1_RDE_M, RTC_IO_PDAC1_SLP_SEL_M, RTC_IO_PDAC1_SLP_IE_M, RTC_IO_PDAC1_HOLD_M, RTC_CNTL_PDAC1_HOLD_FORCE_M, 6}, //25
|
||||
{RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_MUX_SEL_M, RTC_IO_PDAC2_FUN_SEL_S, RTC_IO_PDAC2_FUN_IE_M, RTC_IO_PDAC2_RUE_M, RTC_IO_PDAC2_RDE_M, RTC_IO_PDAC2_SLP_SEL_M, RTC_IO_PDAC2_SLP_IE_M, RTC_IO_PDAC2_HOLD_M, RTC_CNTL_PDAC1_HOLD_FORCE_M, 7}, //26
|
||||
{RTC_IO_TOUCH_PAD7_REG, RTC_IO_TOUCH_PAD7_MUX_SEL_M, RTC_IO_TOUCH_PAD7_FUN_SEL_S, RTC_IO_TOUCH_PAD7_FUN_IE_M, RTC_IO_TOUCH_PAD7_RUE_M, RTC_IO_TOUCH_PAD7_RDE_M, RTC_IO_TOUCH_PAD7_SLP_SEL_M, RTC_IO_TOUCH_PAD7_SLP_IE_M, RTC_IO_TOUCH_PAD7_HOLD_M, RTC_CNTL_TOUCH_PAD7_HOLD_FORCE_M, 17}, //27
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //28
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //29
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //30
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //31
|
||||
{RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32P_MUX_SEL_M, RTC_IO_X32P_FUN_SEL_S, RTC_IO_X32P_FUN_IE_M, RTC_IO_X32P_RUE_M, RTC_IO_X32P_RDE_M, RTC_IO_X32P_SLP_SEL_M, RTC_IO_X32P_SLP_IE_M, RTC_IO_X32P_HOLD_M, RTC_CNTL_X32P_HOLD_FORCE_M, 9}, //32
|
||||
{RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL_M, RTC_IO_X32N_FUN_SEL_S, RTC_IO_X32N_FUN_IE_M, RTC_IO_X32N_RUE_M, RTC_IO_X32N_RDE_M, RTC_IO_X32N_SLP_SEL_M, RTC_IO_X32N_SLP_IE_M, RTC_IO_X32N_HOLD_M, RTC_CNTL_X32N_HOLD_FORCE_M, 8}, //33
|
||||
{RTC_IO_ADC_PAD_REG, RTC_IO_ADC1_MUX_SEL_M, RTC_IO_ADC1_FUN_SEL_S, RTC_IO_ADC1_FUN_IE_M, 0, 0, RTC_IO_ADC1_SLP_SEL_M, RTC_IO_ADC1_SLP_IE_M, RTC_IO_ADC1_HOLD_M, RTC_CNTL_ADC1_HOLD_FORCE_M, 4}, //34
|
||||
{RTC_IO_ADC_PAD_REG, RTC_IO_ADC2_MUX_SEL_M, RTC_IO_ADC2_FUN_SEL_S, RTC_IO_ADC2_FUN_IE_M, 0, 0, RTC_IO_ADC2_SLP_SEL_M, RTC_IO_ADC2_SLP_IE_M, RTC_IO_ADC1_HOLD_M, RTC_CNTL_ADC2_HOLD_FORCE_M, 5}, //35
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE1_MUX_SEL_M, RTC_IO_SENSE1_FUN_SEL_S, RTC_IO_SENSE1_FUN_IE_M, 0, 0, RTC_IO_SENSE1_SLP_SEL_M, RTC_IO_SENSE1_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE1_HOLD_FORCE_M, 0}, //36
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE2_MUX_SEL_M, RTC_IO_SENSE2_FUN_SEL_S, RTC_IO_SENSE2_FUN_IE_M, 0, 0, RTC_IO_SENSE2_SLP_SEL_M, RTC_IO_SENSE2_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE2_HOLD_FORCE_M, 1}, //37
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE3_MUX_SEL_M, RTC_IO_SENSE3_FUN_SEL_S, RTC_IO_SENSE3_FUN_IE_M, 0, 0, RTC_IO_SENSE3_SLP_SEL_M, RTC_IO_SENSE3_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE3_HOLD_FORCE_M, 2}, //38
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE4_MUX_SEL_M, RTC_IO_SENSE4_FUN_SEL_S, RTC_IO_SENSE4_FUN_IE_M, 0, 0, RTC_IO_SENSE4_SLP_SEL_M, RTC_IO_SENSE4_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE4_HOLD_FORCE_M, 3}, //39
|
||||
{RTC_IO_TOUCH_PAD1_REG, RTC_IO_TOUCH_PAD1_MUX_SEL_M, RTC_IO_TOUCH_PAD1_FUN_SEL_S, RTC_IO_TOUCH_PAD1_FUN_IE_M, RTC_IO_TOUCH_PAD1_RUE_M, RTC_IO_TOUCH_PAD1_RDE_M, RTC_IO_TOUCH_PAD1_SLP_SEL_M, RTC_IO_TOUCH_PAD1_SLP_IE_M, RTC_IO_TOUCH_PAD1_HOLD_M, RTC_CNTL_TOUCH_PAD1_HOLD_FORCE_M, RTC_IO_TOUCH_PAD1_DRV_V, RTC_IO_TOUCH_PAD1_DRV_S, 11}, //0
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //1
|
||||
{RTC_IO_TOUCH_PAD2_REG, RTC_IO_TOUCH_PAD2_MUX_SEL_M, RTC_IO_TOUCH_PAD2_FUN_SEL_S, RTC_IO_TOUCH_PAD2_FUN_IE_M, RTC_IO_TOUCH_PAD2_RUE_M, RTC_IO_TOUCH_PAD2_RDE_M, RTC_IO_TOUCH_PAD2_SLP_SEL_M, RTC_IO_TOUCH_PAD2_SLP_IE_M, RTC_IO_TOUCH_PAD2_HOLD_M, RTC_CNTL_TOUCH_PAD2_HOLD_FORCE_M, RTC_IO_TOUCH_PAD2_DRV_V, RTC_IO_TOUCH_PAD2_DRV_S, 12}, //2
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //3
|
||||
{RTC_IO_TOUCH_PAD0_REG, RTC_IO_TOUCH_PAD0_MUX_SEL_M, RTC_IO_TOUCH_PAD0_FUN_SEL_S, RTC_IO_TOUCH_PAD0_FUN_IE_M, RTC_IO_TOUCH_PAD0_RUE_M, RTC_IO_TOUCH_PAD0_RDE_M, RTC_IO_TOUCH_PAD0_SLP_SEL_M, RTC_IO_TOUCH_PAD0_SLP_IE_M, RTC_IO_TOUCH_PAD0_HOLD_M, RTC_CNTL_TOUCH_PAD0_HOLD_FORCE_M, RTC_IO_TOUCH_PAD0_DRV_V, RTC_IO_TOUCH_PAD0_DRV_S, 10}, //4
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //5
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //6
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //7
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //8
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //9
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //10
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //11
|
||||
{RTC_IO_TOUCH_PAD5_REG, RTC_IO_TOUCH_PAD5_MUX_SEL_M, RTC_IO_TOUCH_PAD5_FUN_SEL_S, RTC_IO_TOUCH_PAD5_FUN_IE_M, RTC_IO_TOUCH_PAD5_RUE_M, RTC_IO_TOUCH_PAD5_RDE_M, RTC_IO_TOUCH_PAD5_SLP_SEL_M, RTC_IO_TOUCH_PAD5_SLP_IE_M, RTC_IO_TOUCH_PAD5_HOLD_M, RTC_CNTL_TOUCH_PAD5_HOLD_FORCE_M, RTC_IO_TOUCH_PAD5_DRV_V, RTC_IO_TOUCH_PAD5_DRV_S, 15}, //12
|
||||
{RTC_IO_TOUCH_PAD4_REG, RTC_IO_TOUCH_PAD4_MUX_SEL_M, RTC_IO_TOUCH_PAD4_FUN_SEL_S, RTC_IO_TOUCH_PAD4_FUN_IE_M, RTC_IO_TOUCH_PAD4_RUE_M, RTC_IO_TOUCH_PAD4_RDE_M, RTC_IO_TOUCH_PAD4_SLP_SEL_M, RTC_IO_TOUCH_PAD4_SLP_IE_M, RTC_IO_TOUCH_PAD4_HOLD_M, RTC_CNTL_TOUCH_PAD4_HOLD_FORCE_M, RTC_IO_TOUCH_PAD4_DRV_V, RTC_IO_TOUCH_PAD4_DRV_S, 14}, //13
|
||||
{RTC_IO_TOUCH_PAD6_REG, RTC_IO_TOUCH_PAD6_MUX_SEL_M, RTC_IO_TOUCH_PAD6_FUN_SEL_S, RTC_IO_TOUCH_PAD6_FUN_IE_M, RTC_IO_TOUCH_PAD6_RUE_M, RTC_IO_TOUCH_PAD6_RDE_M, RTC_IO_TOUCH_PAD6_SLP_SEL_M, RTC_IO_TOUCH_PAD6_SLP_IE_M, RTC_IO_TOUCH_PAD6_HOLD_M, RTC_CNTL_TOUCH_PAD6_HOLD_FORCE_M, RTC_IO_TOUCH_PAD6_DRV_V, RTC_IO_TOUCH_PAD6_DRV_S, 16}, //14
|
||||
{RTC_IO_TOUCH_PAD3_REG, RTC_IO_TOUCH_PAD3_MUX_SEL_M, RTC_IO_TOUCH_PAD3_FUN_SEL_S, RTC_IO_TOUCH_PAD3_FUN_IE_M, RTC_IO_TOUCH_PAD3_RUE_M, RTC_IO_TOUCH_PAD3_RDE_M, RTC_IO_TOUCH_PAD3_SLP_SEL_M, RTC_IO_TOUCH_PAD3_SLP_IE_M, RTC_IO_TOUCH_PAD3_HOLD_M, RTC_CNTL_TOUCH_PAD3_HOLD_FORCE_M, RTC_IO_TOUCH_PAD3_DRV_V, RTC_IO_TOUCH_PAD3_DRV_S, 13}, //15
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //16
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //17
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //18
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //19
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //20
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //21
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //22
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //23
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //24
|
||||
{RTC_IO_PAD_DAC1_REG, RTC_IO_PDAC1_MUX_SEL_M, RTC_IO_PDAC1_FUN_SEL_S, RTC_IO_PDAC1_FUN_IE_M, RTC_IO_PDAC1_RUE_M, RTC_IO_PDAC1_RDE_M, RTC_IO_PDAC1_SLP_SEL_M, RTC_IO_PDAC1_SLP_IE_M, RTC_IO_PDAC1_HOLD_M, RTC_CNTL_PDAC1_HOLD_FORCE_M, RTC_IO_PDAC1_DRV_V, RTC_IO_PDAC1_DRV_S, 6}, //25
|
||||
{RTC_IO_PAD_DAC2_REG, RTC_IO_PDAC2_MUX_SEL_M, RTC_IO_PDAC2_FUN_SEL_S, RTC_IO_PDAC2_FUN_IE_M, RTC_IO_PDAC2_RUE_M, RTC_IO_PDAC2_RDE_M, RTC_IO_PDAC2_SLP_SEL_M, RTC_IO_PDAC2_SLP_IE_M, RTC_IO_PDAC2_HOLD_M, RTC_CNTL_PDAC1_HOLD_FORCE_M, RTC_IO_PDAC2_DRV_V, RTC_IO_PDAC2_DRV_S, 7}, //26
|
||||
{RTC_IO_TOUCH_PAD7_REG, RTC_IO_TOUCH_PAD7_MUX_SEL_M, RTC_IO_TOUCH_PAD7_FUN_SEL_S, RTC_IO_TOUCH_PAD7_FUN_IE_M, RTC_IO_TOUCH_PAD7_RUE_M, RTC_IO_TOUCH_PAD7_RDE_M, RTC_IO_TOUCH_PAD7_SLP_SEL_M, RTC_IO_TOUCH_PAD7_SLP_IE_M, RTC_IO_TOUCH_PAD7_HOLD_M, RTC_CNTL_TOUCH_PAD7_HOLD_FORCE_M, RTC_IO_TOUCH_PAD7_DRV_V, RTC_IO_TOUCH_PAD7_DRV_S, 17}, //27
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //28
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //29
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //30
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1}, //31
|
||||
{RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32P_MUX_SEL_M, RTC_IO_X32P_FUN_SEL_S, RTC_IO_X32P_FUN_IE_M, RTC_IO_X32P_RUE_M, RTC_IO_X32P_RDE_M, RTC_IO_X32P_SLP_SEL_M, RTC_IO_X32P_SLP_IE_M, RTC_IO_X32P_HOLD_M, RTC_CNTL_X32P_HOLD_FORCE_M, RTC_IO_X32P_DRV_V, RTC_IO_X32P_DRV_S, 9}, //32
|
||||
{RTC_IO_XTAL_32K_PAD_REG, RTC_IO_X32N_MUX_SEL_M, RTC_IO_X32N_FUN_SEL_S, RTC_IO_X32N_FUN_IE_M, RTC_IO_X32N_RUE_M, RTC_IO_X32N_RDE_M, RTC_IO_X32N_SLP_SEL_M, RTC_IO_X32N_SLP_IE_M, RTC_IO_X32N_HOLD_M, RTC_CNTL_X32N_HOLD_FORCE_M, RTC_IO_X32N_DRV_V, RTC_IO_X32N_DRV_S, 8}, //33
|
||||
{RTC_IO_ADC_PAD_REG, RTC_IO_ADC1_MUX_SEL_M, RTC_IO_ADC1_FUN_SEL_S, RTC_IO_ADC1_FUN_IE_M, 0, 0, RTC_IO_ADC1_SLP_SEL_M, RTC_IO_ADC1_SLP_IE_M, RTC_IO_ADC1_HOLD_M, RTC_CNTL_ADC1_HOLD_FORCE_M, 0, 0, 4}, //34
|
||||
{RTC_IO_ADC_PAD_REG, RTC_IO_ADC2_MUX_SEL_M, RTC_IO_ADC2_FUN_SEL_S, RTC_IO_ADC2_FUN_IE_M, 0, 0, RTC_IO_ADC2_SLP_SEL_M, RTC_IO_ADC2_SLP_IE_M, RTC_IO_ADC1_HOLD_M, RTC_CNTL_ADC2_HOLD_FORCE_M, 0, 0, 5}, //35
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE1_MUX_SEL_M, RTC_IO_SENSE1_FUN_SEL_S, RTC_IO_SENSE1_FUN_IE_M, 0, 0, RTC_IO_SENSE1_SLP_SEL_M, RTC_IO_SENSE1_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE1_HOLD_FORCE_M, 0, 0, 0}, //36
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE2_MUX_SEL_M, RTC_IO_SENSE2_FUN_SEL_S, RTC_IO_SENSE2_FUN_IE_M, 0, 0, RTC_IO_SENSE2_SLP_SEL_M, RTC_IO_SENSE2_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE2_HOLD_FORCE_M, 0, 0, 1}, //37
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE3_MUX_SEL_M, RTC_IO_SENSE3_FUN_SEL_S, RTC_IO_SENSE3_FUN_IE_M, 0, 0, RTC_IO_SENSE3_SLP_SEL_M, RTC_IO_SENSE3_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE3_HOLD_FORCE_M, 0, 0, 2}, //38
|
||||
{RTC_IO_SENSOR_PADS_REG, RTC_IO_SENSE4_MUX_SEL_M, RTC_IO_SENSE4_FUN_SEL_S, RTC_IO_SENSE4_FUN_IE_M, 0, 0, RTC_IO_SENSE4_SLP_SEL_M, RTC_IO_SENSE4_SLP_IE_M, RTC_IO_SENSE1_HOLD_M, RTC_CNTL_SENSE4_HOLD_FORCE_M, 0, 0, 3}, //39
|
||||
};
|
||||
|
||||
/*---------------------------------------------------------------
|
||||
|
@ -189,6 +190,28 @@ uint32_t rtc_gpio_get_level(gpio_num_t gpio_num)
|
|||
return ((level >> (RTC_GPIO_IN_NEXT_S + rtc_gpio_num)) & 0x01);
|
||||
}
|
||||
|
||||
esp_err_t rtc_gpio_set_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t strength)
|
||||
{
|
||||
RTC_MODULE_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTC_GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
RTC_MODULE_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "Output pad only", ESP_ERR_INVALID_ARG);
|
||||
RTC_MODULE_CHECK(strength < GPIO_DRIVE_CAP_MAX, "GPIO drive capability error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
portENTER_CRITICAL(&rtc_spinlock);
|
||||
SET_PERI_REG_BITS(rtc_gpio_desc[gpio_num].reg, rtc_gpio_desc[gpio_num].drv_v, strength, rtc_gpio_desc[gpio_num].drv_s);
|
||||
portEXIT_CRITICAL(&rtc_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rtc_gpio_get_drive_capability(gpio_num_t gpio_num, gpio_drive_cap_t* strength)
|
||||
{
|
||||
RTC_MODULE_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTC_GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
RTC_MODULE_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "Output pad only", ESP_ERR_INVALID_ARG);
|
||||
RTC_MODULE_CHECK(strength != NULL, "GPIO drive pointer error", ESP_ERR_INVALID_ARG);
|
||||
|
||||
*strength = GET_PERI_REG_BITS2(rtc_gpio_desc[gpio_num].reg, rtc_gpio_desc[gpio_num].drv_v, rtc_gpio_desc[gpio_num].drv_s);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t rtc_gpio_set_direction(gpio_num_t gpio_num, rtc_gpio_mode_t mode)
|
||||
{
|
||||
RTC_MODULE_CHECK(rtc_gpio_is_valid_gpio(gpio_num), "RTC_GPIO number error", ESP_ERR_INVALID_ARG);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "freertos/semphr.h"
|
||||
#include "soc/sdmmc_reg.h"
|
||||
#include "soc/sdmmc_struct.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
#include "driver/sdmmc_types.h"
|
||||
#include "driver/sdmmc_defs.h"
|
||||
#include "driver/sdmmc_host.h"
|
||||
|
@ -105,9 +106,16 @@ esp_err_t sdmmc_host_do_transaction(int slot, sdmmc_command_t* cmdinfo)
|
|||
// convert cmdinfo to hardware register value
|
||||
sdmmc_hw_cmd_t hw_cmd = make_hw_cmd(cmdinfo);
|
||||
if (cmdinfo->data) {
|
||||
// these constraints should be handled by upper layer
|
||||
assert(cmdinfo->datalen >= 4);
|
||||
assert(cmdinfo->blklen % 4 == 0);
|
||||
if (cmdinfo->datalen < 4 || cmdinfo->blklen % 4 != 0) {
|
||||
ESP_LOGD(TAG, "%s: invalid size: total=%d block=%d",
|
||||
__func__, cmdinfo->datalen, cmdinfo->blklen);
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
if ((intptr_t) cmdinfo->data % 4 != 0 ||
|
||||
!esp_ptr_dma_capable(cmdinfo->data)) {
|
||||
ESP_LOGD(TAG, "%s: buffer %p can not be used for DMA", __func__, cmdinfo->data);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
// this clears "owned by IDMAC" bits
|
||||
memset(s_dma_desc, 0, sizeof(s_dma_desc));
|
||||
// initialize first descriptor
|
||||
|
|
|
@ -259,3 +259,64 @@ TEST_CASE("SPI Master test, interaction of multiple devs", "[spi][ignore]") {
|
|||
destroy_spi_bus(handle1);
|
||||
}
|
||||
|
||||
TEST_CASE("SPI Master no response when switch from host1 (HSPI) to host2 (VSPI)", "[spi]")
|
||||
{
|
||||
//spi config
|
||||
spi_bus_config_t bus_config;
|
||||
spi_device_interface_config_t device_config;
|
||||
spi_device_handle_t spi;
|
||||
spi_host_device_t host;
|
||||
int dma = 1;
|
||||
|
||||
memset(&bus_config, 0, sizeof(spi_bus_config_t));
|
||||
memset(&device_config, 0, sizeof(spi_device_interface_config_t));
|
||||
|
||||
bus_config.miso_io_num = -1;
|
||||
bus_config.mosi_io_num = 26;
|
||||
bus_config.sclk_io_num = 25;
|
||||
bus_config.quadwp_io_num = -1;
|
||||
bus_config.quadhd_io_num = -1;
|
||||
|
||||
device_config.clock_speed_hz = 50000;
|
||||
device_config.mode = 0;
|
||||
device_config.spics_io_num = -1;
|
||||
device_config.queue_size = 1;
|
||||
device_config.flags = SPI_DEVICE_TXBIT_LSBFIRST | SPI_DEVICE_RXBIT_LSBFIRST;
|
||||
|
||||
struct spi_transaction_t transaction = {
|
||||
.flags = SPI_TRANS_USE_TXDATA | SPI_TRANS_USE_RXDATA,
|
||||
.length = 16,
|
||||
.tx_buffer = NULL,
|
||||
.rx_buffer = NULL,
|
||||
.tx_data = {0x04, 0x00}
|
||||
};
|
||||
|
||||
|
||||
//initialize for first host
|
||||
host = 1;
|
||||
|
||||
assert(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
|
||||
assert(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
|
||||
|
||||
printf("before first xmit\n");
|
||||
assert(spi_device_transmit(spi, &transaction) == ESP_OK);
|
||||
printf("after first xmit\n");
|
||||
|
||||
assert(spi_bus_remove_device(spi) == ESP_OK);
|
||||
assert(spi_bus_free(host) == ESP_OK);
|
||||
|
||||
|
||||
//for second host and failed before
|
||||
host = 2;
|
||||
|
||||
assert(spi_bus_initialize(host, &bus_config, dma) == ESP_OK);
|
||||
assert(spi_bus_add_device(host, &device_config, &spi) == ESP_OK);
|
||||
|
||||
printf("before second xmit\n");
|
||||
// the original version (bit mis-written) stucks here.
|
||||
assert(spi_device_transmit(spi, &transaction) == ESP_OK);
|
||||
// test case success when see this.
|
||||
printf("after second xmit\n");
|
||||
|
||||
|
||||
}
|
||||
|
|
61
components/esp32/fast_crypto_ops.c
Normal file
61
components/esp32/fast_crypto_ops.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
// Copyright 2015-2017 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.
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
#include "crypto/sha256.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "esp_wifi_crypto_types.h"
|
||||
|
||||
/*
|
||||
* The parameters is used to set the cyrpto callback function for station connect when in security mode,
|
||||
* every callback function can register as fast_xxx or normal one, i.e, fast_aes_wrap or aes_wrap, the
|
||||
* difference between them is the normal API is calculate by software, the fast one use the hardware
|
||||
* crypto in it, can be faster than the normal one, so the callback function register in default is which
|
||||
* we recommend, so as the API in WPS default and WPA2 default.
|
||||
*/
|
||||
const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs = {
|
||||
.aes_wrap = (esp_aes_wrap_t)fast_aes_wrap,
|
||||
.aes_unwrap = (esp_aes_unwrap_t)fast_aes_unwrap,
|
||||
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)fast_hmac_sha256_vector,
|
||||
.sha256_prf = (esp_sha256_prf_t)fast_sha256_prf
|
||||
};
|
||||
|
||||
const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs = {
|
||||
.aes_128_encrypt = (esp_aes_128_encrypt_t)fast_aes_128_cbc_encrypt,
|
||||
.aes_128_decrypt = (esp_aes_128_decrypt_t)fast_aes_128_cbc_decrypt,
|
||||
.crypto_mod_exp = (esp_crypto_mod_exp_t)fast_crypto_mod_exp,
|
||||
.hmac_sha256 = (esp_hmac_sha256_t)fast_hmac_sha256,
|
||||
.hmac_sha256_vector = (esp_hmac_sha256_vector_t)fast_hmac_sha256_vector,
|
||||
.sha256_vector = (esp_sha256_vector_t)fast_sha256_vector
|
||||
};
|
||||
|
||||
/*
|
||||
* What should notice is that the cyrpto hash type function and crypto cipher type function can not register
|
||||
* as different, i.e, if you use fast_crypto_hash_init, you should use fast_crypto_hash_update and
|
||||
* fast_crypto_hash_finish for finish hash calculate, rather than call crypto_hash_update and
|
||||
* crypto_hash_finish, so do crypto_cipher.
|
||||
*/
|
||||
const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs = {
|
||||
.crypto_hash_init = (esp_crypto_hash_init_t)fast_crypto_hash_init,
|
||||
.crypto_hash_update = (esp_crypto_hash_update_t)fast_crypto_hash_update,
|
||||
.crypto_hash_finish = (esp_crypto_hash_finish_t)fast_crypto_hash_finish,
|
||||
.crypto_cipher_init = (esp_crypto_cipher_init_t)fast_crypto_cipher_init,
|
||||
.crypto_cipher_encrypt = (esp_crypto_cipher_encrypt_t)fast_crypto_cipher_encrypt,
|
||||
.crypto_cipher_decrypt = (esp_crypto_cipher_decrypt_t)fast_crypto_cipher_decrypt,
|
||||
.crypto_cipher_deinit = (esp_crypto_cipher_deinit_t)fast_crypto_cipher_deinit,
|
||||
.sha256_vector = (esp_sha256_vector_t)fast_sha256_vector,
|
||||
.crypto_mod_exp = (esp_crypto_mod_exp_t)crypto_mod_exp
|
||||
};
|
||||
|
|
@ -65,6 +65,7 @@
|
|||
#include "sdkconfig.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "esp_wifi_crypto_types.h"
|
||||
#include "esp_event.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -96,6 +97,7 @@ extern "C" {
|
|||
*/
|
||||
typedef struct {
|
||||
system_event_handler_t event_handler; /**< WiFi event handler */
|
||||
wpa_crypto_funcs_t wpa_crypto_funcs; /**< WiFi station crypto functions when connect */
|
||||
int static_rx_buf_num; /**< WiFi static RX buffer number */
|
||||
int dynamic_rx_buf_num; /**< WiFi dynamic RX buffer number */
|
||||
int tx_buf_type; /**< WiFi TX buffer type */
|
||||
|
@ -138,11 +140,14 @@ typedef struct {
|
|||
#else
|
||||
#define WIFI_NANO_FORMAT_ENABLED 0
|
||||
#endif
|
||||
|
||||
|
||||
extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs;
|
||||
|
||||
#define WIFI_INIT_CONFIG_MAGIC 0x1F2F3F4F
|
||||
#ifdef CONFIG_WIFI_ENABLED
|
||||
#define WIFI_INIT_CONFIG_DEFAULT() { \
|
||||
.event_handler = &esp_event_send, \
|
||||
.wpa_crypto_funcs = g_wifi_default_wpa_crypto_funcs, \
|
||||
.static_rx_buf_num = CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM,\
|
||||
.dynamic_rx_buf_num = CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM,\
|
||||
.tx_buf_type = CONFIG_ESP32_WIFI_TX_BUFFER_TYPE,\
|
||||
|
|
301
components/esp32/include/esp_wifi_crypto_types.h
Normal file
301
components/esp32/include/esp_wifi_crypto_types.h
Normal file
|
@ -0,0 +1,301 @@
|
|||
// Hardware crypto support Copyright 2017 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 __ESP_WIFI_CRYPTO_TYPES_H__
|
||||
#define __ESP_WIFI_CRYPTO_TYPES_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This enumation is about alorigthm will be set when do crypt hash
|
||||
* operation.When do wpa2 connecting, after invoke crypto_hash_xxx of
|
||||
* fast_crypto_hash_xxx API, it will do relation crypt operation according
|
||||
* to the enumation.
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_CRYPTO_HASH_ALG_MD5, ESP_CRYPTO_HASH_ALG_SHA1,
|
||||
ESP_CRYPTO_HASH_ALG_HMAC_MD5, ESP_CRYPTO_HASH_ALG_HMAC_SHA1,
|
||||
ESP_CRYPTO_HASH_ALG_SHA256, ESP_CRYPTO_HASH_ALG_HMAC_SHA256
|
||||
}esp_crypto_hash_alg_t;
|
||||
|
||||
/*
|
||||
* This enumation is about alorigthm will be set when do crypt cipher
|
||||
* operation.When do wpa2 connecting, after invoke crypto_cipher_xxx of
|
||||
* fast_crypto_cipher_xxx API, it will do relation crypt operation according
|
||||
* to the enumation.
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_CRYPTO_CIPHER_NULL, ESP_CRYPTO_CIPHER_ALG_AES, ESP_CRYPTO_CIPHER_ALG_3DES,
|
||||
ESP_CRYPTO_CIPHER_ALG_DES, ESP_CRYPTO_CIPHER_ALG_RC2, ESP_CRYPTO_CIPHER_ALG_RC4
|
||||
} esp_crypto_cipher_alg_t;
|
||||
|
||||
/*
|
||||
* This structure is about the algorithm when do crypto_hash operation, for detail,
|
||||
* please reference to the structure crypto_hash.
|
||||
*/
|
||||
typedef struct crypto_hash esp_crypto_hash_t;
|
||||
|
||||
/*
|
||||
* This structure is about the algorithm when do crypto_cipher operation, for detail,
|
||||
* please reference to the structure crypto_cipher.
|
||||
*/
|
||||
typedef struct crypto_cipher esp_crypto_cipher_t;
|
||||
|
||||
/**
|
||||
* @brief The crypto callback function used in wpa enterprise hash operation when connect.
|
||||
* Initialize a esp_crypto_hash_t structure.
|
||||
*
|
||||
* @param alg Hash algorithm.
|
||||
* @param key Key for keyed hash (e.g., HMAC) or %NULL if not needed.
|
||||
* @param key_len Length of the key in bytes
|
||||
*
|
||||
*/
|
||||
typedef esp_crypto_hash_t * (*esp_crypto_hash_init_t)(esp_crypto_hash_alg_t alg, const unsigned char *key, int key_len);
|
||||
|
||||
/**
|
||||
* @brief The crypto callback function used in wpa enterprise hash operation when connect.
|
||||
* Add data to hash calculation.
|
||||
*
|
||||
* @param ctz Context pointer from esp_crypto_hash_init_t function.
|
||||
* @param data Data buffer to add.
|
||||
* @param len Length of the buffer.
|
||||
*
|
||||
*/
|
||||
typedef void * (*esp_crypto_hash_update_t)(esp_crypto_hash_t *ctx, const unsigned char *data, int len);
|
||||
|
||||
/**
|
||||
* @brief The crypto callback function used in wpa enterprise hash operation when connect.
|
||||
* Complete hash calculation.
|
||||
*
|
||||
* @param ctz Context pointer from esp_crypto_hash_init_t function.
|
||||
* @param hash Buffer for hash value or %NULL if caller is just freeing the hash
|
||||
* context.
|
||||
* @param len Pointer to length of the buffer or %NULL if caller is just freeing the
|
||||
* hash context; on return, this is set to the actual length of the hash value
|
||||
* Returns: 0 on success, -1 if buffer is too small (len set to needed length),
|
||||
* or -2 on other failures (including failed crypto_hash_update() operations)
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_crypto_hash_finish_t)(esp_crypto_hash_t *ctx, unsigned char *hash, int *len);
|
||||
|
||||
/**
|
||||
* @brief The AES callback function when do WPS connect.
|
||||
*
|
||||
* @param key Encryption key.
|
||||
* @param iv Encryption IV for CBC mode (16 bytes).
|
||||
* @param data Data to encrypt in-place.
|
||||
* @param data_len Length of data in bytes (must be divisible by 16)
|
||||
*/
|
||||
typedef int * (*esp_aes_128_encrypt_t)(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
|
||||
|
||||
/**
|
||||
* @brief The AES callback function when do WPS connect.
|
||||
*
|
||||
* @param key Decryption key.
|
||||
* @param iv Decryption IV for CBC mode (16 bytes).
|
||||
* @param data Data to decrypt in-place.
|
||||
* @param data_len Length of data in bytes (must be divisible by 16)
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_aes_128_decrypt_t)(const unsigned char *key, const unsigned char *iv, unsigned char *data, int data_len);
|
||||
|
||||
/**
|
||||
* @brief The AES callback function when do STA connect.
|
||||
*
|
||||
* @param kek 16-octet Key encryption key (KEK).
|
||||
* @param n Length of the plaintext key in 64-bit units;
|
||||
* @param plain Plaintext key to be wrapped, n * 64 bits
|
||||
* @param cipher Wrapped key, (n + 1) * 64 bits
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_aes_wrap_t)(const unsigned char *kek, int n, const unsigned char *plain, unsigned char *cipher);
|
||||
|
||||
/**
|
||||
* @brief The AES callback function when do STA connect.
|
||||
*
|
||||
* @param kek 16-octet Key decryption key (KEK).
|
||||
* @param n Length of the plaintext key in 64-bit units;
|
||||
* @param cipher Wrapped key to be unwrapped, (n + 1) * 64 bits
|
||||
* @param plain Plaintext key, n * 64 bits
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_aes_unwrap_t)(const unsigned char *kek, int n, const unsigned char *cipher, unsigned char *plain);
|
||||
|
||||
/**
|
||||
* @brief The crypto callback function used in wpa enterprise cipher operation when connect.
|
||||
* Initialize a esp_crypto_cipher_t structure.
|
||||
*
|
||||
* @param alg cipher algorithm.
|
||||
* @param iv Initialization vector for block ciphers or %NULL for stream ciphers.
|
||||
* @param key Cipher key
|
||||
* @param key_len Length of key in bytes
|
||||
*
|
||||
*/
|
||||
typedef esp_crypto_cipher_t * (*esp_crypto_cipher_init_t)(esp_crypto_cipher_alg_t alg, const unsigned char *iv, const unsigned char *key, int key_len);
|
||||
|
||||
/**
|
||||
* @brief The crypto callback function used in wpa enterprise cipher operation when connect.
|
||||
* Cipher encrypt.
|
||||
*
|
||||
* @param ctx Context pointer from esp_crypto_cipher_init_t callback function.
|
||||
* @param plain Plaintext to cipher.
|
||||
* @param crypt Resulting ciphertext.
|
||||
* @param len Length of the plaintext.
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_crypto_cipher_encrypt_t)(esp_crypto_cipher_t *ctx,
|
||||
const unsigned char *plain, unsigned char *crypt, int len);
|
||||
/**
|
||||
* @brief The crypto callback function used in wpa enterprise cipher operation when connect.
|
||||
* Cipher decrypt.
|
||||
*
|
||||
* @param ctx Context pointer from esp_crypto_cipher_init_t callback function.
|
||||
* @param crypt Ciphertext to decrypt.
|
||||
* @param plain Resulting plaintext.
|
||||
* @param len Length of the cipher text.
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_crypto_cipher_decrypt_t)(esp_crypto_cipher_t *ctx,
|
||||
const unsigned char *crypt, unsigned char *plain, int len);
|
||||
/**
|
||||
* @brief The crypto callback function used in wpa enterprise cipher operation when connect.
|
||||
* Free cipher context.
|
||||
*
|
||||
* @param ctx Context pointer from esp_crypto_cipher_init_t callback function.
|
||||
*
|
||||
*/
|
||||
typedef void * (*esp_crypto_cipher_deinit_t)(esp_crypto_cipher_t *ctx);
|
||||
|
||||
/**
|
||||
* @brief The SHA256 callback function when do WPS connect.
|
||||
*
|
||||
* @param key Key for HMAC operations.
|
||||
* @param key_len Length of the key in bytes.
|
||||
* @param data Pointers to the data area.
|
||||
* @param data_len Length of the data area.
|
||||
* @param mac Buffer for the hash (20 bytes).
|
||||
*
|
||||
*/
|
||||
typedef void * (*esp_hmac_sha256_t)(const unsigned char *key, int key_len, const unsigned char *data,
|
||||
int data_len, unsigned char *mac);
|
||||
|
||||
/**
|
||||
* @brief The SHA256 callback function when do WPS connect.
|
||||
*
|
||||
* @param key Key for HMAC operations.
|
||||
* @param key_len Length of the key in bytes.
|
||||
* @param num_elem Number of elements in the data vector.
|
||||
* @param addr Pointers to the data areas.
|
||||
* @param len Lengths of the data blocks.
|
||||
* @param mac Buffer for the hash (32 bytes).
|
||||
*
|
||||
*/
|
||||
typedef void * (*esp_hmac_sha256_vector_t)(const unsigned char *key, int key_len, int num_elem,
|
||||
const unsigned char *addr[], const int *len, unsigned char *mac);
|
||||
|
||||
/**
|
||||
* @brief The AES callback function when do STA connect.
|
||||
*
|
||||
* @param key Key for PRF.
|
||||
* @param key_len Length of the key in bytes.
|
||||
* @param label A unique label for each purpose of the PRF.
|
||||
* @param data Extra data to bind into the key.
|
||||
* @param data_len Length of the data.
|
||||
* @param buf Buffer for the generated pseudo-random key.
|
||||
* @param buf_len Number of bytes of key to generate.
|
||||
*
|
||||
*/
|
||||
typedef void * (*esp_sha256_prf_t)(const unsigned char *key, int key_len, const char *label,
|
||||
const unsigned char *data, int data_len, unsigned char *buf, int buf_len);
|
||||
|
||||
/**
|
||||
* @brief The SHA256 callback function when do WPS connect.
|
||||
*
|
||||
* @param num_elem Number of elements in the data vector.
|
||||
* @param addr Pointers to the data areas.
|
||||
* @param len Lengths of the data blocks.
|
||||
* @param mac Buffer for the hash.
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_sha256_vector_t)(int num_elem, const unsigned char *addr[], const int *len,
|
||||
unsigned char *mac);
|
||||
|
||||
/**
|
||||
* @brief The bignum calculate callback function used when do connect.
|
||||
* In WPS process, it used to calculate public key and private key.
|
||||
*
|
||||
* @param base Base integer (big endian byte array).
|
||||
* @param base_len Length of base integer in bytes.
|
||||
* @param power Power integer (big endian byte array).
|
||||
* @param power_len Length of power integer in bytes.
|
||||
* @param modulus Modulus integer (big endian byte array).
|
||||
* @param modulus_len Length of modulus integer in bytes.
|
||||
* @param result Buffer for the result.
|
||||
* @param result_len Result length (max buffer size on input, real len on output).
|
||||
*
|
||||
*/
|
||||
typedef int * (*esp_crypto_mod_exp_t)(const unsigned char *base, int base_len,
|
||||
const unsigned char *power, int power_len,
|
||||
const unsigned char *modulus, int modulus_len,
|
||||
unsigned char *result, unsigned int *result_len);
|
||||
/**
|
||||
* @brief The crypto callback function structure used when do station security connect.
|
||||
* The structure can be set as software crypto or the crypto optimized by ESP32
|
||||
* hardware.
|
||||
*/
|
||||
typedef struct {
|
||||
esp_aes_wrap_t aes_wrap; /**< station connect function used when send EAPOL frame */
|
||||
esp_aes_unwrap_t aes_unwrap; /**< station connect function used when decrypt key data */
|
||||
esp_hmac_sha256_vector_t hmac_sha256_vector; /**< station connect function used when check MIC */
|
||||
esp_sha256_prf_t sha256_prf; /**< station connect function used when check MIC */
|
||||
}wpa_crypto_funcs_t;
|
||||
|
||||
/**
|
||||
* @brief The crypto callback function structure used when do WPS process. The
|
||||
* structure can be set as software crypto or the crypto optimized by ESP32
|
||||
* hardware.
|
||||
*/
|
||||
typedef struct{
|
||||
esp_aes_128_encrypt_t aes_128_encrypt; /**< function used to process message when do WPS */
|
||||
esp_aes_128_decrypt_t aes_128_decrypt; /**< function used to process message when do WPS */
|
||||
esp_crypto_mod_exp_t crypto_mod_exp; /**< function used to calculate public key and private key */
|
||||
esp_hmac_sha256_t hmac_sha256; /**< function used to get attribute */
|
||||
esp_hmac_sha256_vector_t hmac_sha256_vector; /**< function used to process message when do WPS */
|
||||
esp_sha256_vector_t sha256_vector; /**< function used to process message when do WPS */
|
||||
}wps_crypto_funcs_t;
|
||||
|
||||
/**
|
||||
* @brief The crypto callback function structure used when do WPA enterprise connect.
|
||||
* The structure can be set as software crypto or the crypto optimized by ESP32
|
||||
* hardware.
|
||||
*/
|
||||
typedef struct {
|
||||
esp_crypto_hash_init_t crypto_hash_init; /**< function used to initialize a crypto_hash structure when use TLSV1 */
|
||||
esp_crypto_hash_update_t crypto_hash_update; /**< function used to calculate hash data when use TLSV1 */
|
||||
esp_crypto_hash_finish_t crypto_hash_finish; /**< function used to finish the hash calculate when use TLSV1 */
|
||||
esp_crypto_cipher_init_t crypto_cipher_init; /**< function used to initialize a crypt_cipher structure when use TLSV1 */
|
||||
esp_crypto_cipher_encrypt_t crypto_cipher_encrypt; /**< function used to encrypt cipher when use TLSV1 */
|
||||
esp_crypto_cipher_decrypt_t crypto_cipher_decrypt; /**< function used to decrypt cipher when use TLSV1 */
|
||||
esp_crypto_cipher_deinit_t crypto_cipher_deinit; /**< function used to free context when use TLSV1 */
|
||||
esp_sha256_vector_t sha256_vector; /**< function used to do X.509v3 certificate parsing and processing */
|
||||
esp_crypto_mod_exp_t crypto_mod_exp; /**< function used to do key exchange when use TLSV1 */
|
||||
}wpa2_crypto_funcs_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
// Hardware crypto support Copyright 2017 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.
|
||||
|
@ -16,11 +16,22 @@
|
|||
#define ESP_WPA2_H
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_crypto_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern const wpa2_crypto_funcs_t g_wifi_default_wpa2_crypto_funcs;
|
||||
|
||||
typedef struct {
|
||||
const wpa2_crypto_funcs_t *crypto_funcs;
|
||||
}esp_wpa2_config_t;
|
||||
|
||||
#define WPA2_CONFIG_INIT_DEFAULT() { \
|
||||
.crypto_funcs = &g_wifi_default_wpa2_crypto_funcs \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable wpa2 enterprise authentication.
|
||||
*
|
||||
|
@ -31,7 +42,7 @@ extern "C" {
|
|||
* - ESP_ERR_WIFI_OK: succeed.
|
||||
* - ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail)
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_enable(void);
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_enable(const esp_wpa2_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Disable wpa2 enterprise authentication.
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
#ifndef __ESP_WPS_H__
|
||||
#define __ESP_WPS_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_crypto_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -52,6 +54,18 @@ typedef enum wps_type {
|
|||
WPS_TYPE_MAX,
|
||||
} wps_type_t;
|
||||
|
||||
extern const wps_crypto_funcs_t g_wifi_default_wps_crypto_funcs;
|
||||
|
||||
typedef struct {
|
||||
wps_type_t wps_type;
|
||||
const wps_crypto_funcs_t *crypto_funcs;
|
||||
}esp_wps_config_t;
|
||||
|
||||
#define WPS_CONFIG_INIT_DEFAULT(type) { \
|
||||
.wps_type = type, \
|
||||
.crypto_funcs = &g_wifi_default_wps_crypto_funcs, \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Enable Wi-Fi WPS function.
|
||||
*
|
||||
|
@ -65,7 +79,7 @@ typedef enum wps_type {
|
|||
* - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
|
||||
* - ESP_ERR_WIFI_FAIL : wps initialization fails
|
||||
*/
|
||||
esp_err_t esp_wifi_wps_enable(wps_type_t wps_type);
|
||||
esp_err_t esp_wifi_wps_enable(const esp_wps_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Disable Wi-Fi WPS function and release resource it taken.
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 57b3072bd3fd2f7759225d8407443e9e983520ae
|
||||
Subproject commit e8d8e908fb37c4d9e8a3f23e63f6b34f5178e24a
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
// Copyright 2015-2017 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.
|
||||
|
@ -54,8 +54,8 @@
|
|||
|
||||
static struct emac_config_data emac_config;
|
||||
|
||||
static uint8_t emac_dma_rx_chain_buf[32 * DMA_RX_BUF_NUM];
|
||||
static uint8_t emac_dma_tx_chain_buf[32 * DMA_TX_BUF_NUM];
|
||||
static uint8_t emac_dma_rx_chain_buf[sizeof(struct dma_extended_desc) * DMA_RX_BUF_NUM];
|
||||
static uint8_t emac_dma_tx_chain_buf[sizeof(struct dma_extended_desc) * DMA_TX_BUF_NUM];
|
||||
static uint8_t emac_dma_rx_buf[DMA_RX_BUF_SIZE * DMA_RX_BUF_NUM];
|
||||
static uint8_t emac_dma_tx_buf[DMA_TX_BUF_SIZE * DMA_TX_BUF_NUM];
|
||||
|
||||
|
@ -115,6 +115,25 @@ static void emac_set_rx_base_reg(void)
|
|||
REG_WRITE(EMAC_DMARXBASEADDR_REG, (uint32_t)(emac_config.dma_erx));
|
||||
}
|
||||
|
||||
/*
|
||||
* dirty_rx indicates the hardware has been fed with data packets and is the first node software needs to handle;
|
||||
*
|
||||
* cur_rx indicates the completion of software handling and is the last node hardware could use;
|
||||
*
|
||||
* cnt_rx is to count the numbers of packets handled by software, passed to protocol stack and not been freed.
|
||||
*
|
||||
* (1) Initializing the Linked List. Connect the numerable nodes to a circular linked list, appoint one of the nodes as the head node, mark* the dirty_rx and cur_rx into the node, and mount the node on the hardware base address. Initialize cnt_rx into 0.
|
||||
*
|
||||
* (2) When hardware receives packets, nodes of linked lists will be fed with data packets from the base address by turns, marks the node
|
||||
* of linked lists as “HARDWARE UNUSABLE” and reports interrupts.
|
||||
*
|
||||
* (3) When the software receives the interrupts, it will handle the linked lists by turns from dirty_rx, send data packets to protocol
|
||||
* stack. dirty_rx will deviate backwards by turns and cnt_rx will by turns ++.
|
||||
*
|
||||
* (4) After the protocol stack handles all the data and calls the free function, it will deviate backwards by turns from cur_rx, mark the * node of linked lists as “HARDWARE USABLE” and cnt_rx will by turns --.
|
||||
*
|
||||
* (5) Cycle from Step 2 to Step 4 without break and build up circular linked list handling.
|
||||
*/
|
||||
static void emac_reset_dma_chain(void)
|
||||
{
|
||||
emac_config.cnt_tx = 0;
|
||||
|
@ -450,16 +469,17 @@ static void emac_process_rx_unavail(void)
|
|||
while (emac_config.cnt_rx < DMA_RX_BUF_NUM) {
|
||||
|
||||
emac_config.cnt_rx++;
|
||||
|
||||
//copy data to lwip
|
||||
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2),
|
||||
(((emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL);
|
||||
|
||||
if (emac_config.cnt_rx > DMA_RX_BUF_NUM) {
|
||||
ESP_LOGE(TAG, "emac rx unavail buf err !!\n");
|
||||
}
|
||||
uint32_t tmp_dirty = emac_config.dirty_rx;
|
||||
emac_config.dirty_rx = (emac_config.dirty_rx + 1) % DMA_RX_BUF_NUM;
|
||||
}
|
||||
|
||||
//copy data to lwip
|
||||
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[tmp_dirty].basic.desc2),
|
||||
(((emac_config.dma_erx[tmp_dirty].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL);
|
||||
|
||||
}
|
||||
emac_enable_rx_intr();
|
||||
emac_enable_rx_unavail_intr();
|
||||
xSemaphoreGiveRecursive( emac_rx_xMutex );
|
||||
|
@ -479,16 +499,17 @@ static void emac_process_rx(void)
|
|||
|
||||
while (((uint32_t) & (emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) != cur_rx_desc) && emac_config.cnt_rx < DMA_RX_BUF_NUM ) {
|
||||
emac_config.cnt_rx++;
|
||||
|
||||
//copy data to lwip
|
||||
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2),
|
||||
(((emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL);
|
||||
|
||||
if (emac_config.cnt_rx > DMA_RX_BUF_NUM ) {
|
||||
ESP_LOGE(TAG, "emac rx buf err!!\n");
|
||||
}
|
||||
uint32_t tmp_dirty = emac_config.dirty_rx;
|
||||
emac_config.dirty_rx = (emac_config.dirty_rx + 1) % DMA_RX_BUF_NUM;
|
||||
|
||||
|
||||
//copy data to lwip
|
||||
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[tmp_dirty].basic.desc2),
|
||||
(((emac_config.dma_erx[tmp_dirty].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL);
|
||||
|
||||
cur_rx_desc = emac_read_rx_cur_reg();
|
||||
}
|
||||
} else {
|
||||
|
@ -497,16 +518,17 @@ static void emac_process_rx(void)
|
|||
while (emac_config.cnt_rx < DMA_RX_BUF_NUM) {
|
||||
|
||||
emac_config.cnt_rx++;
|
||||
//copy data to lwip
|
||||
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[emac_config.dirty_rx].basic.desc2),
|
||||
(((emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL);
|
||||
|
||||
if (emac_config.cnt_rx > DMA_RX_BUF_NUM) {
|
||||
ESP_LOGE(TAG, "emac rx buf err!!!\n");
|
||||
}
|
||||
|
||||
uint32_t tmp_dirty = emac_config.dirty_rx;
|
||||
emac_config.dirty_rx = (emac_config.dirty_rx + 1) % DMA_RX_BUF_NUM;
|
||||
}
|
||||
|
||||
//copy data to lwip
|
||||
emac_config.emac_tcpip_input((void *)(emac_config.dma_erx[tmp_dirty].basic.desc2),
|
||||
(((emac_config.dma_erx[tmp_dirty].basic.desc0) >> EMAC_DESC_FRAME_LENGTH_S) & EMAC_DESC_FRAME_LENGTH) , NULL);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -963,6 +985,9 @@ esp_err_t esp_eth_init(eth_config_t *config)
|
|||
ret = ESP_FAIL;
|
||||
goto _exit;
|
||||
#endif
|
||||
if (emac_config.emac_status != EMAC_RUNTIME_NOT_INIT) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
emac_init_default_data();
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ To use logging via JTAG user needs to perform the following steps:
|
|||
2. Build the program image and download it to target as described in :idf:`Developing With the ESP-IDF` section.
|
||||
3. Run OpenOCD (see :idf:`OpenOCD setup for ESP32` section).
|
||||
4. Connect to OpenOCD telnet server. On Linux it can be done using the following command in terminal ``telnet <oocd_host> 4444``. If telnet session is opened on the same machine which runs OpenOCD you can use `localhost` as `<oocd_host>` in the command.
|
||||
5. Run the following command in OpenOCD telnet session: ``esp108 apptrace start /path/to/trace/file -1 -1 0 0 1``. This command will wait for board reset and transfer tracing data at the highest possible rate.
|
||||
5. Run the following command in OpenOCD telnet session: ``esp108 apptrace start /path/to/trace/file 0 -1 -1 1``. This command will wait for board reset and transfer tracing data at the highest possible rate.
|
||||
6. Reset the board. Logging to host will start automatically.
|
||||
7. ``esp108 apptrace`` command with given arguments will never return (see other command options below), so you must stop it manually by resetting the board or pressing CTRL+C in OpenOCD window (not one with the telnet session).
|
||||
8. Reset board or press CTRL+C in OpenOCD window (not one with the telnet session) when tracing is completed (for the example code above after the message `"Tracing is finished."` appears on UART).
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
|
||||
COMPONENT_ADD_INCLUDEDIRS := port/include nghttp2/lib/includes
|
||||
|
||||
COMPONENT_SRCDIRS := nghttp2/lib
|
||||
COMPONENT_SRCDIRS := nghttp2/lib port
|
||||
|
||||
COMPONENT_SUBMODULES := nghttp2
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "driver/sdmmc_types.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
#include "sys/param.h"
|
||||
#include "soc/soc_memory_layout.h"
|
||||
|
||||
#define SDMMC_GO_IDLE_DELAY_MS 20
|
||||
|
||||
|
@ -51,6 +52,10 @@ static esp_err_t sdmmc_send_cmd_send_status(sdmmc_card_t* card, uint32_t* out_st
|
|||
static esp_err_t sdmmc_send_cmd_crc_on_off(sdmmc_card_t* card, bool crc_enable);
|
||||
static uint32_t get_host_ocr(float voltage);
|
||||
static void response_ntoh(sdmmc_response_t response);
|
||||
static esp_err_t sdmmc_write_sectors_dma(sdmmc_card_t* card, const void* src,
|
||||
size_t start_block, size_t block_count);
|
||||
static esp_err_t sdmmc_read_sectors_dma(sdmmc_card_t* card, void* dst,
|
||||
size_t start_block, size_t block_count);
|
||||
|
||||
|
||||
static bool host_is_spi(const sdmmc_card_t* card)
|
||||
|
@ -618,6 +623,37 @@ static esp_err_t sdmmc_send_cmd_send_status(sdmmc_card_t* card, uint32_t* out_st
|
|||
|
||||
esp_err_t sdmmc_write_sectors(sdmmc_card_t* card, const void* src,
|
||||
size_t start_block, size_t block_count)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
size_t block_size = card->csd.sector_size;
|
||||
if (esp_ptr_dma_capable(src) && (intptr_t)src % 4 == 0) {
|
||||
err = sdmmc_write_sectors_dma(card, src, start_block, block_count);
|
||||
} else {
|
||||
// SDMMC peripheral needs DMA-capable buffers. Split the write into
|
||||
// separate single block writes, if needed, and allocate a temporary
|
||||
// DMA-capable buffer.
|
||||
void* tmp_buf = heap_caps_malloc(block_size, MALLOC_CAP_DMA);
|
||||
if (tmp_buf == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
const uint8_t* cur_src = (const uint8_t*) src;
|
||||
for (size_t i = 0; i < block_count; ++i) {
|
||||
memcpy(tmp_buf, cur_src, block_size);
|
||||
cur_src += block_size;
|
||||
err = sdmmc_write_sectors_dma(card, tmp_buf, start_block + i, 1);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGD(TAG, "%s: error 0x%x writing block %d+%d",
|
||||
__func__, err, start_block, i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
free(tmp_buf);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t sdmmc_write_sectors_dma(sdmmc_card_t* card, const void* src,
|
||||
size_t start_block, size_t block_count)
|
||||
{
|
||||
if (start_block + block_count > card->csd.capacity) {
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
|
@ -661,6 +697,37 @@ esp_err_t sdmmc_write_sectors(sdmmc_card_t* card, const void* src,
|
|||
|
||||
esp_err_t sdmmc_read_sectors(sdmmc_card_t* card, void* dst,
|
||||
size_t start_block, size_t block_count)
|
||||
{
|
||||
esp_err_t err = ESP_OK;
|
||||
size_t block_size = card->csd.sector_size;
|
||||
if (esp_ptr_dma_capable(dst) && (intptr_t)dst % 4 == 0) {
|
||||
err = sdmmc_read_sectors_dma(card, dst, start_block, block_count);
|
||||
} else {
|
||||
// SDMMC peripheral needs DMA-capable buffers. Split the read into
|
||||
// separate single block reads, if needed, and allocate a temporary
|
||||
// DMA-capable buffer.
|
||||
void* tmp_buf = heap_caps_malloc(block_size, MALLOC_CAP_DMA);
|
||||
if (tmp_buf == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
uint8_t* cur_dst = (uint8_t*) dst;
|
||||
for (size_t i = 0; i < block_count; ++i) {
|
||||
err = sdmmc_read_sectors_dma(card, tmp_buf, start_block + i, 1);
|
||||
if (err != ESP_OK) {
|
||||
ESP_LOGD(TAG, "%s: error 0x%x writing block %d+%d",
|
||||
__func__, err, start_block, i);
|
||||
break;
|
||||
}
|
||||
memcpy(cur_dst, tmp_buf, block_size);
|
||||
cur_dst += block_size;
|
||||
}
|
||||
free(tmp_buf);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static esp_err_t sdmmc_read_sectors_dma(sdmmc_card_t* card, void* dst,
|
||||
size_t start_block, size_t block_count)
|
||||
{
|
||||
if (start_block + block_count > card->csd.capacity) {
|
||||
return ESP_ERR_INVALID_SIZE;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "driver/sdmmc_defs.h"
|
||||
#include "sdmmc_cmd.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_heap_alloc_caps.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
|
@ -55,61 +55,85 @@ TEST_CASE("can probe SD (using SPI)", "[sdspi][ignore]")
|
|||
free(card);
|
||||
}
|
||||
|
||||
// Fill buffer pointed to by 'dst' with 'count' 32-bit ints generated
|
||||
// from 'rand' with the starting value of 'seed'
|
||||
static void fill_buffer(uint32_t seed, uint8_t* dst, size_t count) {
|
||||
srand(seed);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
uint32_t val = rand();
|
||||
memcpy(dst + i * sizeof(uint32_t), &val, sizeof(val));
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the buffer pointed to by 'dst' contains 'count' 32-bit
|
||||
// ints generated from 'rand' with the starting value of 'seed'
|
||||
static void check_buffer(uint32_t seed, const uint8_t* src, size_t count) {
|
||||
srand(seed);
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
uint32_t val;
|
||||
memcpy(&val, src + i * sizeof(uint32_t), sizeof(val));
|
||||
TEST_ASSERT_EQUAL_HEX32(rand(), val);
|
||||
}
|
||||
}
|
||||
|
||||
static void do_single_write_read_test(sdmmc_card_t* card,
|
||||
size_t start_block, size_t block_count)
|
||||
size_t start_block, size_t block_count, size_t alignment)
|
||||
{
|
||||
size_t block_size = card->csd.sector_size;
|
||||
size_t total_size = block_size * block_count;
|
||||
printf(" %8d | %3d | %4.1f ", start_block, block_count, total_size / 1024.0f);
|
||||
uint32_t* buffer = pvPortMallocCaps(total_size, MALLOC_CAP_DMA);
|
||||
srand(start_block);
|
||||
for (size_t i = 0; i < total_size / sizeof(buffer[0]); ++i) {
|
||||
buffer[i] = rand();
|
||||
}
|
||||
printf(" %8d | %3d | %d | %4.1f ", start_block, block_count, alignment, total_size / 1024.0f);
|
||||
|
||||
uint32_t* buffer = heap_caps_malloc(total_size + 4, MALLOC_CAP_DMA);
|
||||
size_t offset = alignment % 4;
|
||||
uint8_t* c_buffer = (uint8_t*) buffer + offset;
|
||||
fill_buffer(start_block, c_buffer, total_size / sizeof(buffer[0]));
|
||||
|
||||
struct timeval t_start_wr;
|
||||
gettimeofday(&t_start_wr, NULL);
|
||||
TEST_ESP_OK(sdmmc_write_sectors(card, buffer, start_block, block_count));
|
||||
TEST_ESP_OK(sdmmc_write_sectors(card, c_buffer, start_block, block_count));
|
||||
struct timeval t_stop_wr;
|
||||
gettimeofday(&t_stop_wr, NULL);
|
||||
float time_wr = 1e3f * (t_stop_wr.tv_sec - t_start_wr.tv_sec) + 1e-3f * (t_stop_wr.tv_usec - t_start_wr.tv_usec);
|
||||
memset(buffer, 0xbb, total_size);
|
||||
|
||||
memset(buffer, 0xbb, total_size + 4);
|
||||
|
||||
struct timeval t_start_rd;
|
||||
gettimeofday(&t_start_rd, NULL);
|
||||
TEST_ESP_OK(sdmmc_read_sectors(card, buffer, start_block, block_count));
|
||||
TEST_ESP_OK(sdmmc_read_sectors(card, c_buffer, start_block, block_count));
|
||||
struct timeval t_stop_rd;
|
||||
gettimeofday(&t_stop_rd, NULL);
|
||||
float time_rd = 1e3f * (t_stop_rd.tv_sec - t_start_rd.tv_sec) + 1e-3f * (t_stop_rd.tv_usec - t_start_rd.tv_usec);
|
||||
|
||||
printf(" | %6.2f | %.2f | %.2f | %.2f\n",
|
||||
printf(" | %6.2f | %5.2f | %6.2f | %5.2f\n",
|
||||
time_wr, total_size / (time_wr / 1000) / (1024 * 1024),
|
||||
time_rd, total_size / (time_rd / 1000) / (1024 * 1024));
|
||||
srand(start_block);
|
||||
for (size_t i = 0; i < total_size / sizeof(buffer[0]); ++i) {
|
||||
TEST_ASSERT_EQUAL_HEX32(rand(), buffer[i]);
|
||||
}
|
||||
check_buffer(start_block, c_buffer, total_size / sizeof(buffer[0]));
|
||||
free(buffer);
|
||||
}
|
||||
|
||||
static void read_write_test(sdmmc_card_t* card)
|
||||
{
|
||||
sdmmc_card_print_info(stdout, card);
|
||||
printf(" sector | count | size(kB) | wr_time(ms) | wr_speed(MB/s) | rd_time(ms) | rd_speed(MB/s)\n");
|
||||
do_single_write_read_test(card, 0, 1);
|
||||
do_single_write_read_test(card, 0, 4);
|
||||
do_single_write_read_test(card, 1, 16);
|
||||
do_single_write_read_test(card, 16, 32);
|
||||
do_single_write_read_test(card, 48, 64);
|
||||
do_single_write_read_test(card, 128, 128);
|
||||
do_single_write_read_test(card, card->csd.capacity - 64, 32);
|
||||
do_single_write_read_test(card, card->csd.capacity - 64, 64);
|
||||
do_single_write_read_test(card, card->csd.capacity - 8, 1);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 1);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 8);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 16);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 32);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 64);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 128);
|
||||
printf(" sector | count | align | size(kB) | wr_time(ms) | wr_speed(MB/s) | rd_time(ms) | rd_speed(MB/s)\n");
|
||||
do_single_write_read_test(card, 0, 1, 4);
|
||||
do_single_write_read_test(card, 0, 4, 4);
|
||||
do_single_write_read_test(card, 1, 16, 4);
|
||||
do_single_write_read_test(card, 16, 32, 4);
|
||||
do_single_write_read_test(card, 48, 64, 4);
|
||||
do_single_write_read_test(card, 128, 128, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity - 64, 32, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity - 64, 64, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity - 8, 1, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 1, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 4, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 8, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 16, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 32, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 64, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 128, 4);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 1, 1);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 8, 1);
|
||||
do_single_write_read_test(card, card->csd.capacity/2, 128, 1);
|
||||
}
|
||||
|
||||
TEST_CASE("can write and read back blocks", "[sd][ignore]")
|
||||
|
@ -142,3 +166,37 @@ TEST_CASE("can write and read back blocks (using SPI)", "[sdspi][ignore]")
|
|||
TEST_ESP_OK(sdspi_host_deinit());
|
||||
}
|
||||
|
||||
TEST_CASE("reads and writes with an unaligned buffer", "[sd][ignore]")
|
||||
{
|
||||
sdmmc_host_t config = SDMMC_HOST_DEFAULT();
|
||||
TEST_ESP_OK(sdmmc_host_init());
|
||||
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
|
||||
TEST_ESP_OK(sdmmc_host_init_slot(SDMMC_HOST_SLOT_1, &slot_config));
|
||||
sdmmc_card_t* card = malloc(sizeof(sdmmc_card_t));
|
||||
TEST_ASSERT_NOT_NULL(card);
|
||||
TEST_ESP_OK(sdmmc_card_init(&config, card));
|
||||
|
||||
const size_t buffer_size = 4096;
|
||||
const size_t block_count = buffer_size / 512;
|
||||
const size_t extra = 4;
|
||||
uint8_t* buffer = heap_caps_malloc(buffer_size + extra, MALLOC_CAP_DMA);
|
||||
|
||||
// Check read behavior: do aligned write, then unaligned read
|
||||
const uint32_t seed = 0x89abcdef;
|
||||
fill_buffer(seed, buffer, buffer_size / sizeof(uint32_t));
|
||||
TEST_ESP_OK(sdmmc_write_sectors(card, buffer, 0, block_count));
|
||||
memset(buffer, 0xcc, buffer_size + extra);
|
||||
TEST_ESP_OK(sdmmc_read_sectors(card, buffer + 1, 0, block_count));
|
||||
check_buffer(seed, buffer + 1, buffer_size / sizeof(uint32_t));
|
||||
|
||||
// Check write behavior: do unaligned write, then aligned read
|
||||
fill_buffer(seed, buffer + 1, buffer_size / sizeof(uint32_t));
|
||||
TEST_ESP_OK(sdmmc_write_sectors(card, buffer + 1, 8, block_count));
|
||||
memset(buffer, 0xcc, buffer_size + extra);
|
||||
TEST_ESP_OK(sdmmc_read_sectors(card, buffer, 8, block_count));
|
||||
check_buffer(seed, buffer, buffer_size / sizeof(uint32_t));
|
||||
|
||||
free(buffer);
|
||||
free(card);
|
||||
TEST_ESP_OK(sdmmc_host_deinit());
|
||||
}
|
||||
|
|
|
@ -958,7 +958,7 @@
|
|||
#define DPORT_CAN_CLK_EN (BIT(19))
|
||||
#define DPORT_I2C_EXT1_CLK_EN (BIT(18))
|
||||
#define DPORT_PWM0_CLK_EN (BIT(17))
|
||||
#define DPORT_SPI_CLK_EN (BIT(16))
|
||||
#define DPORT_SPI_CLK_EN_2 (BIT(16))
|
||||
#define DPORT_TIMERGROUP1_CLK_EN (BIT(15))
|
||||
#define DPORT_EFUSE_CLK_EN (BIT(14))
|
||||
#define DPORT_TIMERGROUP_CLK_EN (BIT(13))
|
||||
|
@ -968,7 +968,7 @@
|
|||
#define DPORT_RMT_CLK_EN (BIT(9))
|
||||
#define DPORT_UHCI0_CLK_EN (BIT(8))
|
||||
#define DPORT_I2C_EXT0_CLK_EN (BIT(7))
|
||||
#define DPORT_SPI_CLK_EN_2 (BIT(6))
|
||||
#define DPORT_SPI_CLK_EN (BIT(6))
|
||||
#define DPORT_UART1_CLK_EN (BIT(5))
|
||||
#define DPORT_I2S0_CLK_EN (BIT(4))
|
||||
#define DPORT_WDG_CLK_EN (BIT(3))
|
||||
|
@ -992,7 +992,7 @@
|
|||
#define DPORT_CAN_RST (BIT(19))
|
||||
#define DPORT_I2C_EXT1_RST (BIT(18))
|
||||
#define DPORT_PWM0_RST (BIT(17))
|
||||
#define DPORT_SPI_RST (BIT(16))
|
||||
#define DPORT_SPI_RST_2 (BIT(16))
|
||||
#define DPORT_TIMERGROUP1_RST (BIT(15))
|
||||
#define DPORT_EFUSE_RST (BIT(14))
|
||||
#define DPORT_TIMERGROUP_RST (BIT(13))
|
||||
|
@ -1002,7 +1002,7 @@
|
|||
#define DPORT_RMT_RST (BIT(9))
|
||||
#define DPORT_UHCI0_RST (BIT(8))
|
||||
#define DPORT_I2C_EXT0_RST (BIT(7))
|
||||
#define DPORT_SPI_RST_2 (BIT(6))
|
||||
#define DPORT_SPI_RST (BIT(6))
|
||||
#define DPORT_UART1_RST (BIT(5))
|
||||
#define DPORT_I2S0_RST (BIT(4))
|
||||
#define DPORT_WDG_RST (BIT(3))
|
||||
|
|
64
components/wear_levelling/Kconfig
Executable file
64
components/wear_levelling/Kconfig
Executable file
|
@ -0,0 +1,64 @@
|
|||
menu "Wear Levelling"
|
||||
|
||||
choice WL_SECTOR_SIZE
|
||||
bool "Wear Levelling library sector size"
|
||||
default WL_SECTOR_SIZE_4096
|
||||
help
|
||||
Sector size used by wear levelling library.
|
||||
You can set default sector size or size that will
|
||||
fit to the flash device sector size.
|
||||
|
||||
With sector size set to 4096 bytes, wear levelling library is more
|
||||
efficient. However if FAT filesystem is used on top of wear levelling
|
||||
library, it will need more temporary storage: 4096 bytes for each
|
||||
mounted filesystem and 4096 bytes for each opened file.
|
||||
|
||||
With sector size set to 512 bytes, wear levelling library will perform
|
||||
more operations with flash memory, but less RAM will be used by FAT
|
||||
filesystem library (512 bytes for the filesystem and 512 bytes for each
|
||||
file opened).
|
||||
|
||||
config WL_SECTOR_SIZE_512
|
||||
bool "512"
|
||||
# This mode is temporary disabled, until unit test is fixed
|
||||
depends on false
|
||||
config WL_SECTOR_SIZE_4096
|
||||
bool "4096"
|
||||
endchoice
|
||||
|
||||
config WL_SECTOR_SIZE
|
||||
int
|
||||
default 512 if WL_SECTOR_SIZE_512
|
||||
default 4096 if WL_SECTOR_SIZE_4096
|
||||
|
||||
choice WL_SECTOR_MODE
|
||||
bool "Sector store mode"
|
||||
depends on WL_SECTOR_SIZE_512
|
||||
default WL_SECTOR_MODE_SAFE
|
||||
help
|
||||
Specify the mode to store data into flash:
|
||||
|
||||
- In Performance mode a data will be stored to the RAM and then
|
||||
stored back to the flash. Compared to the Safety mode, this operation is
|
||||
faster, but if power will be lost when erase sector operation is in
|
||||
progress, then the data from complete flash device sector will be lost.
|
||||
|
||||
- In Safety mode data from complete flash device sector will be read from
|
||||
flash, modified, and then stored back to flash.
|
||||
Compared to the Performance mode, this operation is slower, but if
|
||||
power is lost during erase sector operation, then the data from full
|
||||
flash device sector will not be lost.
|
||||
|
||||
config WL_SECTOR_MODE_PERF
|
||||
bool "Perfomance"
|
||||
|
||||
config WL_SECTOR_MODE_SAFE
|
||||
bool "Safety"
|
||||
endchoice
|
||||
|
||||
config WL_SECTOR_MODE
|
||||
int
|
||||
default 0 if WL_SECTOR_MODE_PERF
|
||||
default 1 if WL_SECTOR_MODE_SAFE
|
||||
|
||||
endmenu
|
|
@ -4,17 +4,30 @@ Wear Levelling APIs
|
|||
Overview
|
||||
--------
|
||||
Most of the flash devices and specially SPI flash devices that are used in ESP32
|
||||
have sector based organization and have limited amount of erase/modification cycles
|
||||
per memory sector. To avoid situation when one sector reach the limit of erases when
|
||||
have sector based organization and have limited amount of erase/modification cycles
|
||||
per memory sector. To avoid situation when one sector reach the limit of erases when
|
||||
other sectors was used not often, we have made a component that avoid this situation.
|
||||
The wear levelling component share the amount of erases between all sectors in the
|
||||
The wear levelling component share the amount of erases between all sectors in the
|
||||
memory without user interaction.
|
||||
The wear_levelling component contains APIs related to reading, writing, erasing,
|
||||
memory mapping data in the external SPI flash through the partition component. It
|
||||
also has higher-level APIs which work with FAT filesystem defined in
|
||||
memory mapping data in the external SPI flash through the partition component. It
|
||||
also has higher-level APIs which work with FAT filesystem defined in
|
||||
the :doc:`FAT filesystem </api-reference/storage/fatfs>`.
|
||||
|
||||
The wear levelling component does not cache data in RAM. Write and erase functions
|
||||
The wear levelling component, together with FAT FS component, works with FAT FS sector size 4096
|
||||
bytes which is standard size of the flash devices. In this mode the component has best performance,
|
||||
but needs additional memoty in the RAM. To save internal memory the component has two additional modes
|
||||
to work with sector size 512 bytes: Performance and Safety modes. In Performance mode by erase sector
|
||||
operation data will be stored to the RAM, sector will be erased and then data will be stored
|
||||
back to the flash. If by this operation power off situation will occur, the complete 4096 bytes
|
||||
will be lost. To prevent this the Safety mode was implemented. In safety mode the data will be first
|
||||
stored to the flash and after sector will be erased, will be stored back. If power off situation will
|
||||
occur, after power on, the data will be recovered.
|
||||
By default defined the sector size 512 bytes and Performance mode. To change these values please use
|
||||
the configuration menu.
|
||||
|
||||
|
||||
The wear levelling component does not cache data in RAM. Write and erase functions
|
||||
modify flash directly, and flash contents is consistent when the function returns.
|
||||
|
||||
|
||||
|
@ -37,6 +50,6 @@ filesystem-specific functions.
|
|||
Memory Size
|
||||
-----------
|
||||
|
||||
The memory size calculated in the wear Levelling module based on parameters of
|
||||
The memory size calculated in the wear Levelling module based on parameters of
|
||||
partition. The module use few sectors of flash for internal data.
|
||||
|
||||
|
|
163
components/wear_levelling/WL_Ext_Perf.cpp
Executable file
163
components/wear_levelling/WL_Ext_Perf.cpp
Executable file
|
@ -0,0 +1,163 @@
|
|||
// Copyright 2015-2017 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.
|
||||
|
||||
#include "WL_Ext_Perf.h"
|
||||
#include <stdlib.h>
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "wl_ext_perf";
|
||||
|
||||
#define WL_EXT_RESULT_CHECK(result) \
|
||||
if (result != ESP_OK) { \
|
||||
ESP_LOGE(TAG,"%s(%d): result = 0x%08x", __FUNCTION__, __LINE__, result); \
|
||||
return (result); \
|
||||
}
|
||||
|
||||
WL_Ext_Perf::WL_Ext_Perf(): WL_Flash()
|
||||
{
|
||||
this->sector_buffer = NULL;
|
||||
}
|
||||
|
||||
WL_Ext_Perf::~WL_Ext_Perf()
|
||||
{
|
||||
free(this->sector_buffer);
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Perf::config(WL_Config_s *cfg, Flash_Access *flash_drv)
|
||||
{
|
||||
wl_ext_cfg_t *config = (wl_ext_cfg_t *)cfg;
|
||||
|
||||
this->fat_sector_size = config->fat_sector_size;
|
||||
this->flash_sector_size = cfg->sector_size;
|
||||
|
||||
this->sector_buffer = (uint32_t *)malloc(cfg->sector_size);
|
||||
if (this->sector_buffer == NULL) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
this->size_factor = this->flash_sector_size / this->fat_sector_size;
|
||||
if (this->size_factor < 1) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return WL_Flash::config(cfg, flash_drv);
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Perf::init()
|
||||
{
|
||||
return WL_Flash::init();
|
||||
}
|
||||
|
||||
size_t WL_Ext_Perf::chip_size()
|
||||
{
|
||||
return WL_Flash::chip_size();
|
||||
}
|
||||
size_t WL_Ext_Perf::sector_size()
|
||||
{
|
||||
return this->fat_sector_size;
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Perf::erase_sector(size_t sector)
|
||||
{
|
||||
return this->erase_sector_fit(sector, 1);
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Perf::erase_sector_fit(uint32_t start_sector, uint32_t count)
|
||||
{
|
||||
// This method works with one flash device sector and able to erase "count" of fatfs sectors from this sector
|
||||
esp_err_t result = ESP_OK;
|
||||
|
||||
uint32_t pre_check_start = start_sector % this->size_factor;
|
||||
|
||||
|
||||
for (int i = 0; i < this->size_factor; i++) {
|
||||
if ((i < pre_check_start) || (i >= count + pre_check_start)) {
|
||||
result = this->read(start_sector / this->size_factor * this->flash_sector_size + i * this->fat_sector_size, &this->sector_buffer[i * this->fat_sector_size / sizeof(uint32_t)], this->fat_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
}
|
||||
|
||||
result = WL_Flash::erase_sector(start_sector / this->size_factor); // erase comlete flash sector
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
// And write back only data that should not be erased...
|
||||
for (int i = 0; i < this->size_factor; i++) {
|
||||
if ((i < pre_check_start) || (i >= count + pre_check_start)) {
|
||||
result = this->write(start_sector / this->size_factor * this->flash_sector_size + i * this->fat_sector_size, &this->sector_buffer[i * this->fat_sector_size / sizeof(uint32_t)], this->fat_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Perf::erase_range(size_t start_address, size_t size)
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
if ((start_address % this->fat_sector_size) != 0) {
|
||||
result = ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (((size % this->fat_sector_size) != 0) || (size == 0)) {
|
||||
result = ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
|
||||
// The range to erase could be allocated in any possible way
|
||||
// ---------------------------------------------------------
|
||||
// | | | | |
|
||||
// |0|0|x|x|x|x|x|x|x|x|x|x|x|x|0|0|
|
||||
// | pre | rest | rest | post | <- check ranges
|
||||
//
|
||||
// Pre check - the data that is not fit to the full sector at the begining of the erased block
|
||||
// Post check - the data that are not fit to the full sector at the end of the erased block
|
||||
// rest - data that are fit to the flash device sector at the middle of the erased block
|
||||
//
|
||||
// In case of pre and post check situations the data of the non erased area have to be readed first and then
|
||||
// stored back.
|
||||
// For the rest area this operation not needed because complete flash device sector will be erased.
|
||||
|
||||
ESP_LOGV(TAG, "%s begin, addr = 0x%08x, size = %i", __func__, start_address, size);
|
||||
// Calculate pre check values
|
||||
uint32_t pre_check_start = (start_address / this->fat_sector_size) % this->size_factor;
|
||||
uint32_t sectors_count = size / this->fat_sector_size;
|
||||
uint32_t pre_check_count = (this->size_factor - pre_check_start);
|
||||
if (pre_check_count > sectors_count) {
|
||||
pre_check_count = sectors_count;
|
||||
}
|
||||
|
||||
// Calculate post ckeck
|
||||
uint32_t post_check_count = (sectors_count - pre_check_count) % this->size_factor;
|
||||
uint32_t post_check_start = ((start_address + size - post_check_count * this->fat_sector_size) / this->fat_sector_size);
|
||||
|
||||
// Calculate rest
|
||||
uint32_t rest_check_count = sectors_count - pre_check_count - post_check_count;
|
||||
if ((pre_check_count == this->size_factor) && (0 == pre_check_start)) {
|
||||
rest_check_count++;
|
||||
pre_check_count = 0;
|
||||
}
|
||||
uint32_t rest_check_start = start_address + pre_check_count * this->fat_sector_size;
|
||||
|
||||
// Here we will clear pre_check_count amount of sectors
|
||||
if (pre_check_count != 0) {
|
||||
result = this->erase_sector_fit(start_address / this->fat_sector_size, pre_check_count);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
if (rest_check_count > 0) {
|
||||
rest_check_count = rest_check_count / this->size_factor;
|
||||
result = WL_Flash::erase_range(rest_check_start, rest_check_count * this->flash_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
if (post_check_count != 0) {
|
||||
result = this->erase_sector_fit(post_check_start, post_check_count);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
161
components/wear_levelling/WL_Ext_Safe.cpp
Executable file
161
components/wear_levelling/WL_Ext_Safe.cpp
Executable file
|
@ -0,0 +1,161 @@
|
|||
// Copyright 2015-2017 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.
|
||||
|
||||
#include "WL_Ext_Safe.h"
|
||||
#include <stdlib.h>
|
||||
#include "esp_log.h"
|
||||
|
||||
static const char *TAG = "wl_ext_safe";
|
||||
|
||||
#define WL_EXT_RESULT_CHECK(result) \
|
||||
if (result != ESP_OK) { \
|
||||
ESP_LOGE(TAG,"%s(%d): result = 0x%08x", __FUNCTION__, __LINE__, result); \
|
||||
return (result); \
|
||||
}
|
||||
|
||||
#ifndef FLASH_ERASE_VALUE
|
||||
#define FLASH_ERASE_VALUE 0xffffffff
|
||||
#endif // FLASH_ERASE_VALUE
|
||||
|
||||
|
||||
#ifndef WL_EXT_SAFE_OK
|
||||
#define WL_EXT_SAFE_OK 0x12345678
|
||||
#endif // WL_EXT_SAFE_OK
|
||||
|
||||
#ifndef WL_EXT_SAFE_OFFSET
|
||||
#define WL_EXT_SAFE_OFFSET 16
|
||||
#endif // WL_EXT_SAFE_OFFSET
|
||||
|
||||
|
||||
struct WL_Ext_Safe_State {
|
||||
public:
|
||||
uint32_t erase_begin;
|
||||
uint32_t local_addr_base;
|
||||
uint32_t local_addr_shift;
|
||||
uint32_t count;
|
||||
};
|
||||
|
||||
WL_Ext_Safe::WL_Ext_Safe(): WL_Ext_Perf()
|
||||
{
|
||||
}
|
||||
|
||||
WL_Ext_Safe::~WL_Ext_Safe()
|
||||
{
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Safe::config(WL_Config_s *cfg, Flash_Access *flash_drv)
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
|
||||
result = WL_Ext_Perf::config(cfg, flash_drv);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
this->state_addr = WL_Flash::chip_size() - 2 * WL_Flash::sector_size();
|
||||
this->dump_addr = WL_Flash::chip_size() - 1 * WL_Flash::sector_size();
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Safe::init()
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
ESP_LOGV(TAG, "%s", __func__);
|
||||
|
||||
result = WL_Ext_Perf::init();
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
|
||||
result = this->recover();
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t WL_Ext_Safe::chip_size()
|
||||
{
|
||||
ESP_LOGV(TAG, "%s size = %i", __func__, WL_Flash::chip_size() - 2 * this->flash_sector_size);
|
||||
return WL_Flash::chip_size() - 2 * this->flash_sector_size;
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Safe::recover()
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
|
||||
WL_Ext_Safe_State state;
|
||||
result = WL_Flash::read(this->state_addr, &state, sizeof(WL_Ext_Safe_State));
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
ESP_LOGI(TAG, "%s recover, start_addr = 0x%08x, local_addr_base = 0x%08x, local_addr_shift = %i, count=%i", __func__, state.erase_begin, state.local_addr_base, state.local_addr_shift, state.count);
|
||||
|
||||
// check if we have transaction
|
||||
if (state.erase_begin == WL_EXT_SAFE_OK) {
|
||||
|
||||
result = this->read(this->dump_addr, this->sector_buffer, this->flash_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
|
||||
result = WL_Flash::erase_sector(state.local_addr_base); // erase comlete flash sector
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
|
||||
// And write back...
|
||||
for (int i = 0; i < this->size_factor; i++) {
|
||||
if ((i < state.local_addr_shift) || (i >= state.count + state.local_addr_shift)) {
|
||||
result = this->write(state.local_addr_base * this->flash_sector_size + i * this->fat_sector_size, &this->sector_buffer[i * this->fat_sector_size / sizeof(uint32_t)], this->fat_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
}
|
||||
// clear transaction
|
||||
result = WL_Flash::erase_range(this->state_addr, this->flash_sector_size);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
esp_err_t WL_Ext_Safe::erase_sector_fit(uint32_t start_sector, uint32_t count)
|
||||
{
|
||||
esp_err_t result = ESP_OK;
|
||||
|
||||
uint32_t local_addr_base = start_sector / this->size_factor;
|
||||
uint32_t pre_check_start = start_sector % this->size_factor;
|
||||
ESP_LOGV(TAG, "%s start_sector=0x%08x, count = %i", __func__, start_sector, count);
|
||||
for (int i = 0; i < this->size_factor; i++) {
|
||||
if ((i < pre_check_start) || (i >= count + pre_check_start)) {
|
||||
result = this->read(start_sector / this->size_factor * this->flash_sector_size + i * this->fat_sector_size, &this->sector_buffer[i * this->fat_sector_size / sizeof(uint32_t)], this->fat_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
}
|
||||
|
||||
result = WL_Flash::erase_sector(this->dump_addr / this->flash_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
result = WL_Flash::write(this->dump_addr, this->sector_buffer, this->flash_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
|
||||
WL_Ext_Safe_State state;
|
||||
state.erase_begin = WL_EXT_SAFE_OK;
|
||||
state.local_addr_base = local_addr_base;
|
||||
state.local_addr_shift = pre_check_start;
|
||||
state.count = count;
|
||||
|
||||
result = WL_Flash::erase_sector(this->state_addr / this->flash_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
result = WL_Flash::write(this->state_addr + 0, &state, sizeof(WL_Ext_Safe_State));
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
|
||||
// Erase
|
||||
result = WL_Flash::erase_sector(local_addr_base); // erase comlete flash sector
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
// And write back...
|
||||
for (int i = 0; i < this->size_factor; i++) {
|
||||
if ((i < pre_check_start) || (i >= count + pre_check_start)) {
|
||||
result = this->write(local_addr_base * this->flash_sector_size + i * this->fat_sector_size, &this->sector_buffer[i * this->fat_sector_size / sizeof(uint32_t)], this->fat_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
}
|
||||
}
|
||||
|
||||
result = WL_Flash::erase_sector(this->state_addr / this->flash_sector_size);
|
||||
WL_EXT_RESULT_CHECK(result);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
22
components/wear_levelling/private_include/WL_Ext_Cfg.h
Executable file
22
components/wear_levelling/private_include/WL_Ext_Cfg.h
Executable file
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2015-2017 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 _WL_Ext_Cfg_H_
|
||||
#define _WL_Ext_Cfg_H_
|
||||
#include "WL_Config.h"
|
||||
|
||||
typedef struct WL_Ext_Cfg_s : public WL_Config_s {
|
||||
uint32_t fat_sector_size; /*!< virtual sector size*/
|
||||
} wl_ext_cfg_t;
|
||||
|
||||
#endif // _WL_Ext_Cfg_H_
|
46
components/wear_levelling/private_include/WL_Ext_Perf.h
Executable file
46
components/wear_levelling/private_include/WL_Ext_Perf.h
Executable file
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2015-2017 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 _WL_Ext_Perf_H_
|
||||
#define _WL_Ext_Perf_H_
|
||||
|
||||
#include "WL_Flash.h"
|
||||
#include "WL_Ext_Cfg.h"
|
||||
|
||||
class WL_Ext_Perf : public WL_Flash
|
||||
{
|
||||
public:
|
||||
WL_Ext_Perf();
|
||||
~WL_Ext_Perf() override;
|
||||
|
||||
esp_err_t config(WL_Config_s *cfg, Flash_Access *flash_drv) override;
|
||||
esp_err_t init() override;
|
||||
|
||||
size_t chip_size() override;
|
||||
size_t sector_size() override;
|
||||
|
||||
|
||||
esp_err_t erase_sector(size_t sector) override;
|
||||
esp_err_t erase_range(size_t start_address, size_t size) override;
|
||||
|
||||
protected:
|
||||
uint32_t flash_sector_size;
|
||||
uint32_t fat_sector_size;
|
||||
uint32_t size_factor;
|
||||
uint32_t *sector_buffer;
|
||||
|
||||
virtual esp_err_t erase_sector_fit(uint32_t start_sector, uint32_t count);
|
||||
|
||||
};
|
||||
|
||||
#endif // _WL_Ext_Perf_H_
|
42
components/wear_levelling/private_include/WL_Ext_Safe.h
Executable file
42
components/wear_levelling/private_include/WL_Ext_Safe.h
Executable file
|
@ -0,0 +1,42 @@
|
|||
// Copyright 2015-2017 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 _WL_Ext_Safe_H_
|
||||
#define _WL_Ext_Safe_H_
|
||||
|
||||
#include "WL_Flash.h"
|
||||
#include "WL_Ext_Cfg.h"
|
||||
#include "WL_Ext_Perf.h"
|
||||
|
||||
class WL_Ext_Safe : public WL_Ext_Perf
|
||||
{
|
||||
public:
|
||||
WL_Ext_Safe();
|
||||
~WL_Ext_Safe() override;
|
||||
|
||||
esp_err_t config(WL_Config_s *cfg, Flash_Access *flash_drv) override;
|
||||
esp_err_t init() override;
|
||||
|
||||
size_t chip_size() override;
|
||||
|
||||
protected:
|
||||
esp_err_t erase_sector_fit(uint32_t start_sector, uint32_t count) override;
|
||||
|
||||
// Dump Sector
|
||||
uint32_t dump_addr; // dump buffer address
|
||||
uint32_t state_addr;// sectore where state of transaction will be stored
|
||||
|
||||
esp_err_t recover();
|
||||
};
|
||||
|
||||
#endif // _WL_Ext_Safe_H_
|
|
@ -17,7 +17,10 @@
|
|||
#include <sys/lock.h>
|
||||
#include "wear_levelling.h"
|
||||
#include "WL_Config.h"
|
||||
#include "WL_Ext_Cfg.h"
|
||||
#include "WL_Flash.h"
|
||||
#include "WL_Ext_Perf.h"
|
||||
#include "WL_Ext_Safe.h"
|
||||
#include "SPI_Flash.h"
|
||||
#include "Partition.h"
|
||||
|
||||
|
@ -79,7 +82,7 @@ esp_err_t wl_mount(const esp_partition_t *partition, wl_handle_t *out_handle)
|
|||
goto out;
|
||||
}
|
||||
|
||||
wl_config_t cfg;
|
||||
wl_ext_cfg_t cfg;
|
||||
cfg.full_mem_size = partition->size;
|
||||
cfg.start_addr = WL_DEFAULT_START_ADDR;
|
||||
cfg.version = WL_CURRENT_VERSION;
|
||||
|
@ -88,6 +91,8 @@ esp_err_t wl_mount(const esp_partition_t *partition, wl_handle_t *out_handle)
|
|||
cfg.updaterate = WL_DEFAULT_UPDATERATE;
|
||||
cfg.temp_buff_size = WL_DEFAULT_TEMP_BUFF_SIZE;
|
||||
cfg.wr_size = WL_DEFAULT_WRITE_SIZE;
|
||||
// FAT sector size by default will be 512
|
||||
cfg.fat_sector_size = CONFIG_WL_SECTOR_SIZE;
|
||||
|
||||
// Allocate memory for a Partition object, and then initialize the object
|
||||
// using placement new operator. This way we can recover from out of
|
||||
|
@ -101,13 +106,37 @@ esp_err_t wl_mount(const esp_partition_t *partition, wl_handle_t *out_handle)
|
|||
part = new (part_ptr) Partition(partition);
|
||||
|
||||
// Same for WL_Flash: allocate memory, use placement new
|
||||
#if CONFIG_WL_SECTOR_SIZE == 512
|
||||
#if CONFIG_WL_SECTOR_MODE == 1
|
||||
wl_flash_ptr = malloc(sizeof(WL_Ext_Safe));
|
||||
|
||||
if (wl_flash_ptr == NULL) {
|
||||
result = ESP_ERR_NO_MEM;
|
||||
ESP_LOGE(TAG, "%s: can't allocate WL_Ext_Safe", __func__);
|
||||
goto out;
|
||||
}
|
||||
wl_flash = new (wl_flash_ptr) WL_Ext_Safe();
|
||||
#else
|
||||
wl_flash_ptr = malloc(sizeof(WL_Ext_Perf));
|
||||
|
||||
if (wl_flash_ptr == NULL) {
|
||||
result = ESP_ERR_NO_MEM;
|
||||
ESP_LOGE(TAG, "%s: can't allocate WL_Ext_Perf", __func__);
|
||||
goto out;
|
||||
}
|
||||
wl_flash = new (wl_flash_ptr) WL_Ext_Perf();
|
||||
#endif // CONFIG_WL_SECTOR_MODE
|
||||
#endif // CONFIG_WL_SECTOR_SIZE
|
||||
#if CONFIG_WL_SECTOR_SIZE == 4096
|
||||
wl_flash_ptr = malloc(sizeof(WL_Flash));
|
||||
|
||||
if (wl_flash_ptr == NULL) {
|
||||
result = ESP_ERR_NO_MEM;
|
||||
ESP_LOGE(TAG, "%s: can't allocate WL_Flash", __func__);
|
||||
goto out;
|
||||
}
|
||||
wl_flash = new (wl_flash_ptr) WL_Flash();
|
||||
#endif // CONFIG_WL_SECTOR_SIZE
|
||||
|
||||
result = wl_flash->config(&cfg, part);
|
||||
if (ESP_OK != result) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
COMPONENT_ADD_INCLUDEDIRS := include port/include
|
||||
COMPONENT_SRCDIRS := src/crypto port
|
||||
COMPONENT_ADD_INCLUDEDIRS := include port/include ../esp32/include
|
||||
COMPONENT_SRCDIRS := src/crypto port src/fast_crypto
|
||||
|
||||
CFLAGS += -DEMBEDDED_SUPP -D__ets__ -Wno-strict-aliasing
|
||||
|
|
|
@ -44,5 +44,10 @@ int __must_check aes_128_cbc_encrypt(const u8 *key, const u8 *iv, u8 *data,
|
|||
size_t data_len);
|
||||
int __must_check aes_128_cbc_decrypt(const u8 *key, const u8 *iv, u8 *data,
|
||||
size_t data_len);
|
||||
|
||||
int __must_check fast_aes_wrap(const uint8_t *kek, int n, const uint8_t *plain, uint8_t *cipher);
|
||||
int __must_check fast_aes_unwrap(const uint8_t *kek, int n, const uint8_t *cipher, uint8_t *plain);
|
||||
int __must_check fast_aes_128_cbc_encrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data,
|
||||
size_t data_len);
|
||||
int __must_check fast_aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data,
|
||||
size_t data_len);
|
||||
#endif /* AES_WRAP_H */
|
||||
|
|
|
@ -100,6 +100,17 @@ int __must_check fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x,
|
|||
int sha256_vector(size_t num_elem, const u8 *addr[], const size_t *len,
|
||||
u8 *mac);
|
||||
|
||||
/**
|
||||
* fast_sha256_vector - fast SHA256 hash for data vector
|
||||
* @num_elem: Number of elements in the data vector
|
||||
* @addr: Pointers to the data areas
|
||||
* @len: Lengths of the data blocks
|
||||
* @mac: Buffer for the hash
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int fast_sha256_vector(size_t num_elem, const uint8_t *addr[], const size_t *len,
|
||||
uint8_t *mac);
|
||||
|
||||
/**
|
||||
* des_encrypt - Encrypt one block with DES
|
||||
* @clear: 8 octets (in)
|
||||
|
@ -159,7 +170,6 @@ enum crypto_hash_alg {
|
|||
CRYPTO_HASH_ALG_SHA256, CRYPTO_HASH_ALG_HMAC_SHA256
|
||||
};
|
||||
|
||||
|
||||
struct crypto_hash;
|
||||
|
||||
/**
|
||||
|
@ -177,6 +187,21 @@ struct crypto_hash;
|
|||
struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
|
||||
size_t key_len);
|
||||
|
||||
/**
|
||||
* fast_crypto_hash_init - Initialize hash/HMAC function
|
||||
* @alg: Hash algorithm
|
||||
* @key: Key for keyed hash (e.g., HMAC) or %NULL if not needed
|
||||
* @key_len: Length of the key in bytes
|
||||
* Returns: Pointer to hash context to use with other hash functions or %NULL
|
||||
* on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
struct crypto_hash * fast_crypto_hash_init(enum crypto_hash_alg alg, const uint8_t *key,
|
||||
size_t key_len);
|
||||
|
||||
/**
|
||||
* crypto_hash_update - Add data to hash calculation
|
||||
* @ctx: Context pointer from crypto_hash_init()
|
||||
|
@ -189,6 +214,18 @@ struct crypto_hash * crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
|
|||
*/
|
||||
void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len);
|
||||
|
||||
/**
|
||||
* fast_crypto_hash_update - Add data to hash calculation
|
||||
* @ctx: Context pointer from crypto_hash_init()
|
||||
* @data: Data buffer to add
|
||||
* @len: Length of the buffer
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
void fast_crypto_hash_update(struct crypto_hash *ctx, const uint8_t *data, size_t len);
|
||||
|
||||
/**
|
||||
* crypto_hash_finish - Complete hash calculation
|
||||
* @ctx: Context pointer from crypto_hash_init()
|
||||
|
@ -208,6 +245,25 @@ void crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len);
|
|||
*/
|
||||
int crypto_hash_finish(struct crypto_hash *ctx, u8 *hash, size_t *len);
|
||||
|
||||
/**
|
||||
* fast_crypto_hash_finish - Complete hash calculation
|
||||
* @ctx: Context pointer from crypto_hash_init()
|
||||
* @hash: Buffer for hash value or %NULL if caller is just freeing the hash
|
||||
* context
|
||||
* @len: Pointer to length of the buffer or %NULL if caller is just freeing the
|
||||
* hash context; on return, this is set to the actual length of the hash value
|
||||
* Returns: 0 on success, -1 if buffer is too small (len set to needed length),
|
||||
* or -2 on other failures (including failed crypto_hash_update() operations)
|
||||
*
|
||||
* This function calculates the hash value and frees the context buffer that
|
||||
* was used for hash calculation.
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int fast_crypto_hash_finish(struct crypto_hash *ctx, uint8_t *hash, size_t *len);
|
||||
|
||||
|
||||
enum crypto_cipher_alg {
|
||||
CRYPTO_CIPHER_NULL = 0, CRYPTO_CIPHER_ALG_AES, CRYPTO_CIPHER_ALG_3DES,
|
||||
|
@ -233,6 +289,22 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
|
|||
const u8 *iv, const u8 *key,
|
||||
size_t key_len);
|
||||
|
||||
/**
|
||||
* fast_crypto_cipher_init - Initialize block/stream cipher function
|
||||
* @alg: Cipher algorithm
|
||||
* @iv: Initialization vector for block ciphers or %NULL for stream ciphers
|
||||
* @key: Cipher key
|
||||
* @key_len: Length of key in bytes
|
||||
* Returns: Pointer to cipher context to use with other cipher functions or
|
||||
* %NULL on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
struct crypto_cipher * fast_crypto_cipher_init(enum crypto_cipher_alg alg,
|
||||
const uint8_t *iv, const uint8_t *key,
|
||||
size_t key_len);
|
||||
/**
|
||||
* crypto_cipher_encrypt - Cipher encrypt
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
|
@ -248,6 +320,21 @@ struct crypto_cipher * crypto_cipher_init(enum crypto_cipher_alg alg,
|
|||
int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx,
|
||||
const u8 *plain, u8 *crypt, size_t len);
|
||||
|
||||
/**
|
||||
* fast_crypto_cipher_encrypt - Cipher encrypt
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
* @plain: Plaintext to cipher
|
||||
* @crypt: Resulting ciphertext
|
||||
* @len: Length of the plaintext
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check fast_crypto_cipher_encrypt(struct crypto_cipher *ctx,
|
||||
const uint8_t *plain, uint8_t *crypt, size_t len);
|
||||
|
||||
/**
|
||||
* crypto_cipher_decrypt - Cipher decrypt
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
|
@ -263,6 +350,21 @@ int __must_check crypto_cipher_encrypt(struct crypto_cipher *ctx,
|
|||
int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx,
|
||||
const u8 *crypt, u8 *plain, size_t len);
|
||||
|
||||
/**
|
||||
* fast_crypto_cipher_decrypt - Cipher decrypt
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
* @crypt: Ciphertext to decrypt
|
||||
* @plain: Resulting plaintext
|
||||
* @len: Length of the cipher text
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check fast_crypto_cipher_decrypt(struct crypto_cipher *ctx,
|
||||
const uint8_t *crypt, uint8_t *plain, size_t len);
|
||||
|
||||
/**
|
||||
* crypto_cipher_decrypt - Free cipher context
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
|
@ -273,6 +375,15 @@ int __must_check crypto_cipher_decrypt(struct crypto_cipher *ctx,
|
|||
*/
|
||||
void crypto_cipher_deinit(struct crypto_cipher *ctx);
|
||||
|
||||
/**
|
||||
* fast_crypto_cipher_decrypt - Free cipher context
|
||||
* @ctx: Context pointer from crypto_cipher_init()
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
void fast_crypto_cipher_deinit(struct crypto_cipher *ctx);
|
||||
|
||||
struct crypto_public_key;
|
||||
struct crypto_private_key;
|
||||
|
@ -452,6 +563,31 @@ int __must_check crypto_mod_exp(const u8 *base, size_t base_len,
|
|||
const u8 *modulus, size_t modulus_len,
|
||||
u8 *result, size_t *result_len);
|
||||
|
||||
/**
|
||||
* fast_crypto_mod_exp - Modular exponentiation of large integers
|
||||
* @base: Base integer (big endian byte array)
|
||||
* @base_len: Length of base integer in bytes
|
||||
* @power: Power integer (big endian byte array)
|
||||
* @power_len: Length of power integer in bytes
|
||||
* @modulus: Modulus integer (big endian byte array)
|
||||
* @modulus_len: Length of modulus integer in bytes
|
||||
* @result: Buffer for the result
|
||||
* @result_len: Result length (max buffer size on input, real len on output)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*
|
||||
* This function calculates result = base ^ power mod modulus. modules_len is
|
||||
* used as the maximum size of modulus buffer. It is set to the used size on
|
||||
* success.
|
||||
*
|
||||
* This function is only used with internal TLSv1 implementation
|
||||
* (CONFIG_TLS=internal). If that is not used, the crypto wrapper does not need
|
||||
* to implement this.
|
||||
*/
|
||||
int __must_check fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
|
||||
const uint8_t *power, size_t power_len,
|
||||
const uint8_t *modulus, size_t modulus_len,
|
||||
uint8_t *result, size_t *result_len);
|
||||
|
||||
/**
|
||||
* rc4_skip - XOR RC4 stream to given data with skip-stream-start
|
||||
* @key: RC4 key
|
||||
|
|
|
@ -24,4 +24,10 @@ void hmac_sha256(const u8 *key, size_t key_len, const u8 *data,
|
|||
void sha256_prf(const u8 *key, size_t key_len, const char *label,
|
||||
const u8 *data, size_t data_len, u8 *buf, size_t buf_len);
|
||||
|
||||
void fast_hmac_sha256_vector(const uint8_t *key, size_t key_len, size_t num_elem,
|
||||
const uint8_t *addr[], const size_t *len, uint8_t *mac);
|
||||
void fast_hmac_sha256(const uint8_t *key, size_t key_len, const uint8_t *data,
|
||||
size_t data_len, uint8_t *mac);
|
||||
void fast_sha256_prf(const uint8_t *key, size_t key_len, const char *label,
|
||||
const uint8_t *data, size_t data_len, uint8_t *buf, size_t buf_len);
|
||||
#endif /* SHA256_H */
|
||||
|
|
|
@ -20,11 +20,9 @@
|
|||
#include "crypto/dh_groups.h"
|
||||
#include "wpa/wpabuf.h"
|
||||
#include "wpa/wpa_debug.h"
|
||||
#include "esp_wifi_crypto_types.h"
|
||||
|
||||
extern int crypto_mod_exp(const u8 *base, size_t base_len,
|
||||
const u8 *power, size_t power_len,
|
||||
const u8 *modulus, size_t modulus_len,
|
||||
u8 *result, size_t *result_len);
|
||||
extern wps_crypto_funcs_t wps_crypto_funcs;
|
||||
|
||||
#ifdef ALL_DH_GROUPS
|
||||
|
||||
|
@ -589,10 +587,17 @@ dh_init(const struct dh_group *dh, struct wpabuf **priv)
|
|||
pv = wpabuf_alloc(pv_len);
|
||||
if (pv == NULL)
|
||||
return NULL;
|
||||
if (crypto_mod_exp(dh->generator, dh->generator_len,
|
||||
wpabuf_head(*priv), wpabuf_len(*priv),
|
||||
dh->prime, dh->prime_len, wpabuf_mhead(pv),
|
||||
&pv_len) < 0) {
|
||||
|
||||
if (wps_crypto_funcs.crypto_mod_exp) {
|
||||
if (wps_crypto_funcs.crypto_mod_exp(dh->generator, dh->generator_len,
|
||||
wpabuf_head(*priv), wpabuf_len(*priv),
|
||||
dh->prime, dh->prime_len, wpabuf_mhead(pv),
|
||||
&pv_len)) {
|
||||
wpabuf_free(pv);
|
||||
wpa_printf(MSG_INFO, "DH: crypto_mod_exp failed");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
wpabuf_free(pv);
|
||||
wpa_printf(MSG_INFO, "DH: crypto_mod_exp failed");
|
||||
return NULL;
|
||||
|
@ -626,14 +631,22 @@ dh_derive_shared(const struct wpabuf *peer_public,
|
|||
shared = wpabuf_alloc(shared_len);
|
||||
if (shared == NULL)
|
||||
return NULL;
|
||||
if (crypto_mod_exp(wpabuf_head(peer_public), wpabuf_len(peer_public),
|
||||
wpabuf_head(own_private), wpabuf_len(own_private),
|
||||
dh->prime, dh->prime_len,
|
||||
wpabuf_mhead(shared), &shared_len) < 0) {
|
||||
|
||||
if (wps_crypto_funcs.crypto_mod_exp) {
|
||||
if (wps_crypto_funcs.crypto_mod_exp(wpabuf_head(peer_public), wpabuf_len(peer_public),
|
||||
wpabuf_head(own_private), wpabuf_len(own_private),
|
||||
dh->prime, dh->prime_len,
|
||||
wpabuf_mhead(shared), &shared_len)) {
|
||||
wpabuf_free(shared);
|
||||
wpa_printf(MSG_INFO, "DH: crypto_mod_exp failed");
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
wpabuf_free(shared);
|
||||
wpa_printf(MSG_INFO, "DH: crypto_mod_exp failed");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
wpabuf_put(shared, shared_len);
|
||||
wpa_hexdump_buf_key(MSG_DEBUG, "DH: shared key", shared);
|
||||
|
||||
|
|
78
components/wpa_supplicant/src/fast_crypto/fast_aes-cbc.c
Normal file
78
components/wpa_supplicant/src/fast_crypto/fast_aes-cbc.c
Normal file
|
@ -0,0 +1,78 @@
|
|||
// Hardware crypto support Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
|
||||
#include "crypto/includes.h"
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/aes.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
/**
|
||||
* fast_aes_128_cbc_encrypt - AES-128 CBC encryption
|
||||
* @key: Encryption key
|
||||
* @iv: Encryption IV for CBC mode (16 bytes)
|
||||
* @data: Data to encrypt in-place
|
||||
* @data_len: Length of data in bytes (must be divisible by 16)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
fast_aes_128_cbc_encrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len)
|
||||
{
|
||||
int ret = 0;
|
||||
mbedtls_aes_context ctx;
|
||||
uint8_t cbc[AES_BLOCK_SIZE];
|
||||
|
||||
mbedtls_aes_init(&ctx);
|
||||
|
||||
ret = mbedtls_aes_setkey_enc(&ctx, key, 128);
|
||||
|
||||
if(ret < 0) {
|
||||
mbedtls_aes_free(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
|
||||
|
||||
ret = mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, data_len, cbc, data, data);
|
||||
|
||||
mbedtls_aes_free(&ctx);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fast_aes_128_cbc_decrypt - AES-128 CBC decryption
|
||||
* @key: Decryption key
|
||||
* @iv: Decryption IV for CBC mode (16 bytes)
|
||||
* @data: Data to decrypt in-place
|
||||
* @data_len: Length of data in bytes (must be divisible by 16)
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int
|
||||
fast_aes_128_cbc_decrypt(const uint8_t *key, const uint8_t *iv, uint8_t *data, size_t data_len)
|
||||
{
|
||||
int ret = 0;
|
||||
mbedtls_aes_context ctx;
|
||||
uint8_t cbc[AES_BLOCK_SIZE];
|
||||
|
||||
mbedtls_aes_init(&ctx);
|
||||
|
||||
ret = mbedtls_aes_setkey_dec(&ctx, key, 128);
|
||||
|
||||
if(ret < 0) {
|
||||
mbedtls_aes_free(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
os_memcpy(cbc, iv, AES_BLOCK_SIZE);
|
||||
|
||||
ret = mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_DECRYPT, data_len, cbc, data, data);
|
||||
|
||||
mbedtls_aes_free(&ctx);
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
81
components/wpa_supplicant/src/fast_crypto/fast_aes-unwrap.c
Normal file
81
components/wpa_supplicant/src/fast_crypto/fast_aes-unwrap.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
// 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
|
||||
//
|
||||
// Hardware crypto support Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "crypto/includes.h"
|
||||
#include "crypto/common.h"
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
/**
|
||||
* fast_aes_unwrap - Unwrap key with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
|
||||
* @kek: Key encryption key (KEK)
|
||||
* @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
|
||||
* bytes
|
||||
* @cipher: Wrapped key to be unwrapped, (n + 1) * 64 bits
|
||||
* @plain: Plaintext key, n * 64 bits
|
||||
* Returns: 0 on success, -1 on failure (e.g., integrity verification failed)
|
||||
*/
|
||||
int
|
||||
fast_aes_unwrap(const uint8_t *kek, int n, const uint8_t *cipher, uint8_t *plain)
|
||||
{
|
||||
uint8_t a[8], *r, b[16];
|
||||
int32_t i, j;
|
||||
int32_t ret = 0;
|
||||
mbedtls_aes_context ctx;
|
||||
|
||||
/* 1) Initialize variables. */
|
||||
os_memcpy(a, cipher, 8);
|
||||
r = plain;
|
||||
os_memcpy(r, cipher + 8, 8 * n);
|
||||
|
||||
mbedtls_aes_init(&ctx);
|
||||
ret = mbedtls_aes_setkey_dec(&ctx, kek, 128);
|
||||
if (ret < 0) {
|
||||
mbedtls_aes_free(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 2) Compute intermediate values.
|
||||
* For j = 5 to 0
|
||||
* For i = n to 1
|
||||
* B = AES-1(K, (A ^ t) | R[i]) where t = n*j+i
|
||||
* A = MSB(64, B)
|
||||
* R[i] = LSB(64, B)
|
||||
*/
|
||||
for (j = 5; j >= 0; j--) {
|
||||
r = plain + (n - 1) * 8;
|
||||
for (i = n; i >= 1; i--) {
|
||||
os_memcpy(b, a, 8);
|
||||
b[7] ^= n * j + i;
|
||||
os_memcpy(b + 8, r, 8);
|
||||
mbedtls_aes_decrypt(&ctx, b, b);
|
||||
os_memcpy(a, b, 8);
|
||||
os_memcpy(r, b + 8, 8);
|
||||
r -= 8;
|
||||
}
|
||||
}
|
||||
mbedtls_aes_free(&ctx);
|
||||
|
||||
/* 3) Output results.
|
||||
*
|
||||
* These are already in @plain due to the location of temporary
|
||||
* variables. Just verify that the IV matches with the expected value.
|
||||
*/
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (a[i] != 0xa6) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
80
components/wpa_supplicant/src/fast_crypto/fast_aes-wrap.c
Normal file
80
components/wpa_supplicant/src/fast_crypto/fast_aes-wrap.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
// 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
|
||||
//
|
||||
// Hardware crypto support Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/aes.h"
|
||||
#include "crypto/aes_wrap.h"
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
/**
|
||||
* fast_aes_wrap - Wrap keys with AES Key Wrap Algorithm (128-bit KEK) (RFC3394)
|
||||
* @kek: 16-octet Key encryption key (KEK)
|
||||
* @n: Length of the plaintext key in 64-bit units; e.g., 2 = 128-bit = 16
|
||||
* bytes
|
||||
* @plain: Plaintext key to be wrapped, n * 64 bits
|
||||
* @cipher: Wrapped key, (n + 1) * 64 bits
|
||||
* Returns: 0 on success, -1 on failure
|
||||
*/
|
||||
int fast_aes_wrap(const uint8_t *kek, int n, const uint8_t *plain, uint8_t *cipher)
|
||||
{
|
||||
uint8_t *a, *r, b[16];
|
||||
int32_t i, j;
|
||||
int32_t ret = 0;
|
||||
mbedtls_aes_context ctx;
|
||||
|
||||
a = cipher;
|
||||
r = cipher + 8;
|
||||
|
||||
/* 1) Initialize variables. */
|
||||
os_memset(a, 0xa6, 8);
|
||||
os_memcpy(r, plain, 8 * n);
|
||||
|
||||
mbedtls_aes_init(&ctx);
|
||||
ret = mbedtls_aes_setkey_enc(&ctx, kek, 128);
|
||||
if (ret < 0) {
|
||||
mbedtls_aes_free(&ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* 2) Calculate intermediate values.
|
||||
* For j = 0 to 5
|
||||
* For i=1 to n
|
||||
* B = AES(K, A | R[i])
|
||||
* A = MSB(64, B) ^ t where t = (n*j)+i
|
||||
* R[i] = LSB(64, B)
|
||||
*/
|
||||
for (j = 0; j <= 5; j++) {
|
||||
r = cipher + 8;
|
||||
for (i = 1; i <= n; i++) {
|
||||
os_memcpy(b, a, 8);
|
||||
os_memcpy(b + 8, r, 8);
|
||||
mbedtls_aes_encrypt(&ctx, b, b);
|
||||
os_memcpy(a, b, 8);
|
||||
a[7] ^= n * j + i;
|
||||
os_memcpy(r, b + 8, 8);
|
||||
r += 8;
|
||||
}
|
||||
}
|
||||
mbedtls_aes_free(&ctx);
|
||||
|
||||
/* 3) Output the results.
|
||||
*
|
||||
* These are already in @cipher due to the location of temporary
|
||||
* variables.
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,283 @@
|
|||
// 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
|
||||
//
|
||||
// Hardware crypto support Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
// 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.
|
||||
|
||||
//#include "wpa/includes.h"
|
||||
|
||||
//#include "wpa/common.h"
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/aes.h"
|
||||
#if defined(CONFIG_DES) || defined(CONFIG_DES3)
|
||||
#include "crypto/des_i.h"
|
||||
#endif
|
||||
#include "mbedtls/aes.h"
|
||||
|
||||
struct fast_crypto_cipher {
|
||||
enum crypto_cipher_alg alg;
|
||||
union {
|
||||
struct {
|
||||
size_t used_bytes;
|
||||
uint8_t key[16];
|
||||
size_t keylen;
|
||||
} rc4;
|
||||
struct {
|
||||
uint8_t cbc[32];
|
||||
mbedtls_aes_context ctx_enc;
|
||||
mbedtls_aes_context ctx_dec;
|
||||
} aes;
|
||||
#ifdef CONFIG_DES3
|
||||
struct {
|
||||
struct des3_key_s key;
|
||||
uint8_t cbc[8];
|
||||
} des3;
|
||||
#endif
|
||||
#ifdef CONFIG_DES
|
||||
struct {
|
||||
uint32_t ek[32];
|
||||
uint32_t dk[32];
|
||||
uint32_t cbc[8];
|
||||
} des;
|
||||
#endif
|
||||
} u;
|
||||
};
|
||||
|
||||
|
||||
struct crypto_cipher * fast_crypto_cipher_init(enum crypto_cipher_alg alg,
|
||||
const uint8_t *iv, const uint8_t *key,
|
||||
size_t key_len)
|
||||
{
|
||||
struct fast_crypto_cipher *ctx;
|
||||
|
||||
ctx = (struct fast_crypto_cipher *)os_zalloc(sizeof(*ctx));
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ctx->alg = alg;
|
||||
|
||||
switch (alg) {
|
||||
case CRYPTO_CIPHER_ALG_RC4:
|
||||
if (key_len > sizeof(ctx->u.rc4.key)) {
|
||||
os_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
ctx->u.rc4.keylen = key_len;
|
||||
os_memcpy(ctx->u.rc4.key, key, key_len);
|
||||
break;
|
||||
case CRYPTO_CIPHER_ALG_AES:
|
||||
mbedtls_aes_init(&(ctx->u.aes.ctx_enc));
|
||||
mbedtls_aes_setkey_enc(&(ctx->u.aes.ctx_enc), key, 256);
|
||||
mbedtls_aes_init(&(ctx->u.aes.ctx_dec));
|
||||
mbedtls_aes_setkey_dec(&(ctx->u.aes.ctx_dec), key, 256);
|
||||
os_memcpy(ctx->u.aes.cbc, iv, AES_BLOCK_SIZE);
|
||||
break;
|
||||
#ifdef CONFIG_DES3
|
||||
case CRYPTO_CIPHER_ALG_3DES:
|
||||
if (key_len != 24) {
|
||||
os_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
des3_key_setup(key, &ctx->u.des3.key);
|
||||
os_memcpy(ctx->u.des3.cbc, iv, 8);
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_DES
|
||||
case CRYPTO_CIPHER_ALG_DES:
|
||||
if (key_len != 8) {
|
||||
os_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
des_key_setup(key, ctx->u.des.ek, ctx->u.des.dk);
|
||||
os_memcpy(ctx->u.des.cbc, iv, 8);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
os_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct crypto_cipher *)ctx;
|
||||
}
|
||||
|
||||
|
||||
int fast_crypto_cipher_encrypt(struct crypto_cipher *ctx, const uint8_t *plain,
|
||||
uint8_t *crypt, size_t len)
|
||||
{
|
||||
size_t i, j, blocks;
|
||||
struct fast_crypto_cipher *fast_ctx;
|
||||
|
||||
fast_ctx = (struct fast_crypto_cipher *)ctx;
|
||||
|
||||
switch (fast_ctx->alg) {
|
||||
case CRYPTO_CIPHER_ALG_RC4:
|
||||
if (plain != crypt) {
|
||||
os_memcpy(crypt, plain, len);
|
||||
}
|
||||
rc4_skip(fast_ctx->u.rc4.key, fast_ctx->u.rc4.keylen,
|
||||
fast_ctx->u.rc4.used_bytes, crypt, len);
|
||||
fast_ctx->u.rc4.used_bytes += len;
|
||||
break;
|
||||
case CRYPTO_CIPHER_ALG_AES:
|
||||
if (len % AES_BLOCK_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
blocks = len / AES_BLOCK_SIZE;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
for (j = 0; j < AES_BLOCK_SIZE; j++)
|
||||
fast_ctx->u.aes.cbc[j] ^= plain[j];
|
||||
mbedtls_aes_encrypt(&(fast_ctx->u.aes.ctx_enc), fast_ctx->u.aes.cbc, fast_ctx->u.aes.cbc);
|
||||
os_memcpy(crypt, fast_ctx->u.aes.cbc, AES_BLOCK_SIZE);
|
||||
plain += AES_BLOCK_SIZE;
|
||||
crypt += AES_BLOCK_SIZE;
|
||||
}
|
||||
break;
|
||||
#ifdef CONFIG_DES3
|
||||
case CRYPTO_CIPHER_ALG_3DES:
|
||||
if (len % 8) {
|
||||
return -1;
|
||||
}
|
||||
blocks = len / 8;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
for (j = 0; j < 8; j++)
|
||||
fast_ctx->u.des3.cbc[j] ^= plain[j];
|
||||
des3_encrypt(fast_ctx->u.des3.cbc, &fast_ctx->u.des3.key,
|
||||
fast_ctx->u.des3.cbc);
|
||||
os_memcpy(crypt, fast_ctx->u.des3.cbc, 8);
|
||||
plain += 8;
|
||||
crypt += 8;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_DES
|
||||
case CRYPTO_CIPHER_ALG_DES:
|
||||
if (len % 8) {
|
||||
return -1;
|
||||
}
|
||||
blocks = len / 8;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
for (j = 0; j < 8; j++)
|
||||
fast_ctx->u.des3.cbc[j] ^= plain[j];
|
||||
des_block_encrypt(fast_ctx->u.des.cbc, fast_ctx->u.des.ek,
|
||||
fast_ctx->u.des.cbc);
|
||||
os_memcpy(crypt, fast_ctx->u.des.cbc, 8);
|
||||
plain += 8;
|
||||
crypt += 8;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int fast_crypto_cipher_decrypt(struct crypto_cipher *ctx, const uint8_t *crypt,
|
||||
uint8_t *plain, size_t len)
|
||||
{
|
||||
size_t i, j, blocks;
|
||||
uint8_t tmp[32];
|
||||
struct fast_crypto_cipher *fast_ctx;
|
||||
|
||||
fast_ctx = (struct fast_crypto_cipher *)ctx;
|
||||
|
||||
switch (fast_ctx->alg) {
|
||||
case CRYPTO_CIPHER_ALG_RC4:
|
||||
if (plain != crypt) {
|
||||
os_memcpy(plain, crypt, len);
|
||||
}
|
||||
rc4_skip(fast_ctx->u.rc4.key, fast_ctx->u.rc4.keylen,
|
||||
fast_ctx->u.rc4.used_bytes, plain, len);
|
||||
fast_ctx->u.rc4.used_bytes += len;
|
||||
break;
|
||||
case CRYPTO_CIPHER_ALG_AES:
|
||||
if (len % AES_BLOCK_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
blocks = len / AES_BLOCK_SIZE;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
os_memcpy(tmp, crypt, AES_BLOCK_SIZE);
|
||||
mbedtls_aes_decrypt(&(fast_ctx->u.aes.ctx_dec), crypt, plain);
|
||||
for (j = 0; j < AES_BLOCK_SIZE; j++)
|
||||
plain[j] ^= fast_ctx->u.aes.cbc[j];
|
||||
os_memcpy(fast_ctx->u.aes.cbc, tmp, AES_BLOCK_SIZE);
|
||||
plain += AES_BLOCK_SIZE;
|
||||
crypt += AES_BLOCK_SIZE;
|
||||
}
|
||||
break;
|
||||
#ifdef CONFIG_DES3
|
||||
case CRYPTO_CIPHER_ALG_3DES:
|
||||
if (len % 8) {
|
||||
return -1;
|
||||
}
|
||||
blocks = len / 8;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
os_memcpy(tmp, crypt, 8);
|
||||
des3_decrypt(crypt, &fast_ctx->u.des3.key, plain);
|
||||
for (j = 0; j < 8; j++) {
|
||||
plain[j] ^= fast_ctx->u.des3.cbc[j];
|
||||
}
|
||||
os_memcpy(fast_ctx->u.des3.cbc, tmp, 8);
|
||||
plain += 8;
|
||||
crypt += 8;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_DES
|
||||
case CRYPTO_CIPHER_ALG_DES:
|
||||
if (len % 8) {
|
||||
return -1;
|
||||
}
|
||||
blocks = len / 8;
|
||||
for (i = 0; i < blocks; i++) {
|
||||
os_memcpy(tmp, crypt, 8);
|
||||
des_block_decrypt(crypt, fast_ctx->u.des.dk, plain);
|
||||
for (j = 0; j < 8; j++) {
|
||||
plain[j] ^= fast_ctx->u.des.cbc[j];
|
||||
}
|
||||
os_memcpy(fast_ctx->u.des.cbc, tmp, 8);
|
||||
plain += 8;
|
||||
crypt += 8;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void fast_crypto_cipher_deinit(struct crypto_cipher *ctx)
|
||||
{
|
||||
struct fast_crypto_cipher *fast_ctx;
|
||||
|
||||
fast_ctx = (struct fast_crypto_cipher *)ctx;
|
||||
|
||||
switch (fast_ctx->alg) {
|
||||
case CRYPTO_CIPHER_ALG_AES:
|
||||
mbedtls_aes_free(&(fast_ctx->u.aes.ctx_enc));
|
||||
mbedtls_aes_free(&(fast_ctx->u.aes.ctx_dec));
|
||||
break;
|
||||
#ifdef CONFIG_DES3
|
||||
case CRYPTO_CIPHER_ALG_3DES:
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
os_free(ctx);
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
// Hardware crypto support Copyright 2017 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.
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "mbedtls/bignum.h"
|
||||
|
||||
int
|
||||
fast_crypto_mod_exp(const uint8_t *base, size_t base_len,
|
||||
const uint8_t *power, size_t power_len,
|
||||
const uint8_t *modulus, size_t modulus_len,
|
||||
uint8_t *result, size_t *result_len)
|
||||
{
|
||||
mbedtls_mpi bn_base, bn_exp, bn_modulus, bn_result, bn_rinv;
|
||||
int32_t ret = 0;
|
||||
mbedtls_mpi_init(&bn_base);
|
||||
mbedtls_mpi_init(&bn_exp);
|
||||
mbedtls_mpi_init(&bn_modulus);
|
||||
mbedtls_mpi_init(&bn_result);
|
||||
mbedtls_mpi_init(&bn_rinv);
|
||||
|
||||
mbedtls_mpi_read_binary(&bn_base, base, base_len);
|
||||
mbedtls_mpi_read_binary(&bn_exp, power, power_len);
|
||||
mbedtls_mpi_read_binary(&bn_modulus, modulus, modulus_len);
|
||||
|
||||
ret = mbedtls_mpi_exp_mod(&bn_result, &bn_base, &bn_exp, &bn_modulus, &bn_rinv);
|
||||
if (ret < 0) {
|
||||
mbedtls_mpi_free(&bn_base);
|
||||
mbedtls_mpi_free(&bn_exp);
|
||||
mbedtls_mpi_free(&bn_modulus);
|
||||
mbedtls_mpi_free(&bn_result);
|
||||
mbedtls_mpi_free(&bn_rinv);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = mbedtls_mpi_write_binary(&bn_result, result, *result_len);
|
||||
|
||||
|
||||
mbedtls_mpi_free(&bn_base);
|
||||
mbedtls_mpi_free(&bn_exp);
|
||||
mbedtls_mpi_free(&bn_modulus);
|
||||
mbedtls_mpi_free(&bn_result);
|
||||
mbedtls_mpi_free(&bn_rinv);
|
||||
|
||||
return ret;
|
||||
}
|
282
components/wpa_supplicant/src/fast_crypto/fast_crypto_internal.c
Normal file
282
components/wpa_supplicant/src/fast_crypto/fast_crypto_internal.c
Normal file
|
@ -0,0 +1,282 @@
|
|||
/*
|
||||
* Crypto wrapper for internal crypto implementation
|
||||
* Copyright (c) 2006-2011, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* Hardware crypto support Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* This software may be distributed under the terms of the BSD license.
|
||||
* See README for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/crypto.h"
|
||||
#include "crypto/sha1_i.h"
|
||||
#include "crypto/md5_i.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
|
||||
|
||||
#ifdef MEMLEAK_DEBUG
|
||||
static const char mem_debug_file[] ICACHE_RODATA_ATTR = __FILE__;
|
||||
#endif
|
||||
|
||||
struct fast_crypto_hash {
|
||||
enum crypto_hash_alg alg;
|
||||
union {
|
||||
struct MD5Context md5;
|
||||
struct SHA1Context sha1;
|
||||
#ifdef CONFIG_SHA256
|
||||
mbedtls_sha256_context sha256;
|
||||
#endif /* CONFIG_SHA256 */
|
||||
} u;
|
||||
u8 key[64];
|
||||
size_t key_len;
|
||||
};
|
||||
|
||||
struct crypto_hash * fast_crypto_hash_init(enum crypto_hash_alg alg, const u8 *key,
|
||||
size_t key_len)
|
||||
{
|
||||
struct fast_crypto_hash *ctx;
|
||||
u8 k_pad[64];
|
||||
u8 tk[32];
|
||||
size_t i;
|
||||
|
||||
ctx = (struct fast_crypto_hash *)os_zalloc(sizeof(*ctx));
|
||||
if (ctx == NULL)
|
||||
return NULL;
|
||||
|
||||
ctx->alg = alg;
|
||||
|
||||
switch (alg) {
|
||||
case CRYPTO_HASH_ALG_MD5:
|
||||
MD5Init(&ctx->u.md5);
|
||||
break;
|
||||
case CRYPTO_HASH_ALG_SHA1:
|
||||
SHA1Init(&ctx->u.sha1);
|
||||
break;
|
||||
#ifdef CONFIG_SHA256
|
||||
case CRYPTO_HASH_ALG_SHA256:
|
||||
mbedtls_sha256_init(&ctx->u.sha256);
|
||||
mbedtls_sha256_starts(&ctx->u.sha256, 0);
|
||||
break;
|
||||
#endif /* CONFIG_SHA256 */
|
||||
case CRYPTO_HASH_ALG_HMAC_MD5:
|
||||
if (key_len > sizeof(k_pad)) {
|
||||
MD5Init(&ctx->u.md5);
|
||||
MD5Update(&ctx->u.md5, key, key_len);
|
||||
MD5Final(tk, &ctx->u.md5);
|
||||
key = tk;
|
||||
key_len = 16;
|
||||
}
|
||||
os_memcpy(ctx->key, key, key_len);
|
||||
ctx->key_len = key_len;
|
||||
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
if (key_len < sizeof(k_pad))
|
||||
os_memset(k_pad + key_len, 0, sizeof(k_pad) - key_len);
|
||||
for (i = 0; i < sizeof(k_pad); i++)
|
||||
k_pad[i] ^= 0x36;
|
||||
MD5Init(&ctx->u.md5);
|
||||
MD5Update(&ctx->u.md5, k_pad, sizeof(k_pad));
|
||||
break;
|
||||
case CRYPTO_HASH_ALG_HMAC_SHA1:
|
||||
if (key_len > sizeof(k_pad)) {
|
||||
SHA1Init(&ctx->u.sha1);
|
||||
SHA1Update(&ctx->u.sha1, key, key_len);
|
||||
SHA1Final(tk, &ctx->u.sha1);
|
||||
key = tk;
|
||||
key_len = 20;
|
||||
}
|
||||
os_memcpy(ctx->key, key, key_len);
|
||||
ctx->key_len = key_len;
|
||||
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
if (key_len < sizeof(k_pad))
|
||||
os_memset(k_pad + key_len, 0, sizeof(k_pad) - key_len);
|
||||
for (i = 0; i < sizeof(k_pad); i++)
|
||||
k_pad[i] ^= 0x36;
|
||||
SHA1Init(&ctx->u.sha1);
|
||||
SHA1Update(&ctx->u.sha1, k_pad, sizeof(k_pad));
|
||||
break;
|
||||
#ifdef CONFIG_SHA256
|
||||
case CRYPTO_HASH_ALG_HMAC_SHA256:
|
||||
if (key_len > sizeof(k_pad)) {
|
||||
mbedtls_sha256_init(&ctx->u.sha256);
|
||||
mbedtls_sha256_starts(&ctx->u.sha256, 0);
|
||||
mbedtls_sha256_update(&ctx->u.sha256, key, key_len);
|
||||
mbedtls_sha256_finish(&ctx->u.sha256, tk);
|
||||
mbedtls_sha256_free(&ctx->u.sha256);
|
||||
key = tk;
|
||||
key_len = 32;
|
||||
}
|
||||
os_memcpy(ctx->key, key, key_len);
|
||||
ctx->key_len = key_len;
|
||||
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
if (key_len < sizeof(k_pad))
|
||||
os_memset(k_pad + key_len, 0, sizeof(k_pad) - key_len);
|
||||
for (i = 0; i < sizeof(k_pad); i++)
|
||||
k_pad[i] ^= 0x36;
|
||||
mbedtls_sha256_init(&ctx->u.sha256);
|
||||
mbedtls_sha256_starts(&ctx->u.sha256, 0);
|
||||
mbedtls_sha256_update(&ctx->u.sha256, k_pad, sizeof(k_pad));
|
||||
break;
|
||||
#endif /* CONFIG_SHA256 */
|
||||
default:
|
||||
os_free(ctx);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (struct crypto_hash *)ctx;
|
||||
}
|
||||
|
||||
|
||||
void fast_crypto_hash_update(struct crypto_hash *ctx, const u8 *data, size_t len)
|
||||
{
|
||||
|
||||
struct fast_crypto_hash *fast_ctx;
|
||||
fast_ctx = (struct fast_crypto_hash *)ctx;
|
||||
|
||||
if (fast_ctx == NULL)
|
||||
return;
|
||||
|
||||
switch (fast_ctx->alg) {
|
||||
case CRYPTO_HASH_ALG_MD5:
|
||||
case CRYPTO_HASH_ALG_HMAC_MD5:
|
||||
MD5Update(&fast_ctx->u.md5, data, len);
|
||||
break;
|
||||
case CRYPTO_HASH_ALG_SHA1:
|
||||
case CRYPTO_HASH_ALG_HMAC_SHA1:
|
||||
SHA1Update(&fast_ctx->u.sha1, data, len);
|
||||
break;
|
||||
#ifdef CONFIG_SHA256
|
||||
case CRYPTO_HASH_ALG_SHA256:
|
||||
case CRYPTO_HASH_ALG_HMAC_SHA256:
|
||||
mbedtls_sha256_update(&fast_ctx->u.sha256, data, len);
|
||||
break;
|
||||
#endif /* CONFIG_SHA256 */
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int fast_crypto_hash_finish(struct crypto_hash *ctx, u8 *mac, size_t *len)
|
||||
{
|
||||
u8 k_pad[64];
|
||||
size_t i;
|
||||
struct fast_crypto_hash *fast_ctx;
|
||||
|
||||
if (ctx == NULL)
|
||||
return -2;
|
||||
|
||||
fast_ctx = (struct fast_crypto_hash *)ctx;
|
||||
|
||||
if (mac == NULL || len == NULL) {
|
||||
os_free(fast_ctx);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (fast_ctx->alg) {
|
||||
case CRYPTO_HASH_ALG_MD5:
|
||||
if (*len < 16) {
|
||||
*len = 16;
|
||||
os_free(fast_ctx);
|
||||
return -1;
|
||||
}
|
||||
*len = 16;
|
||||
MD5Final(mac, &fast_ctx->u.md5);
|
||||
break;
|
||||
case CRYPTO_HASH_ALG_SHA1:
|
||||
if (*len < 20) {
|
||||
*len = 20;
|
||||
os_free(fast_ctx);
|
||||
return -1;
|
||||
}
|
||||
*len = 20;
|
||||
SHA1Final(mac, &fast_ctx->u.sha1);
|
||||
break;
|
||||
#ifdef CONFIG_SHA256
|
||||
case CRYPTO_HASH_ALG_SHA256:
|
||||
if (*len < 32) {
|
||||
*len = 32;
|
||||
os_free(fast_ctx);
|
||||
return -1;
|
||||
}
|
||||
*len = 32;
|
||||
mbedtls_sha256_finish(&fast_ctx->u.sha256, mac);
|
||||
mbedtls_sha256_free(&fast_ctx->u.sha256);
|
||||
break;
|
||||
#endif /* CONFIG_SHA256 */
|
||||
case CRYPTO_HASH_ALG_HMAC_MD5:
|
||||
if (*len < 16) {
|
||||
*len = 16;
|
||||
os_free(fast_ctx);
|
||||
return -1;
|
||||
}
|
||||
*len = 16;
|
||||
|
||||
MD5Final(mac, &fast_ctx->u.md5);
|
||||
|
||||
os_memcpy(k_pad, fast_ctx->key, fast_ctx->key_len);
|
||||
os_memset(k_pad + fast_ctx->key_len, 0,
|
||||
sizeof(k_pad) - fast_ctx->key_len);
|
||||
for (i = 0; i < sizeof(k_pad); i++)
|
||||
k_pad[i] ^= 0x5c;
|
||||
MD5Init(&fast_ctx->u.md5);
|
||||
MD5Update(&fast_ctx->u.md5, k_pad, sizeof(k_pad));
|
||||
MD5Update(&fast_ctx->u.md5, mac, 16);
|
||||
MD5Final(mac, &fast_ctx->u.md5);
|
||||
break;
|
||||
case CRYPTO_HASH_ALG_HMAC_SHA1:
|
||||
if (*len < 20) {
|
||||
*len = 20;
|
||||
os_free(ctx);
|
||||
return -1;
|
||||
}
|
||||
*len = 20;
|
||||
|
||||
SHA1Final(mac, &fast_ctx->u.sha1);
|
||||
os_memcpy(k_pad, fast_ctx->key, fast_ctx->key_len);
|
||||
os_memset(k_pad + fast_ctx->key_len, 0,
|
||||
sizeof(k_pad) - fast_ctx->key_len);
|
||||
for (i = 0; i < sizeof(k_pad); i++)
|
||||
k_pad[i] ^= 0x5c;
|
||||
SHA1Init(&fast_ctx->u.sha1);
|
||||
SHA1Update(&fast_ctx->u.sha1, k_pad, sizeof(k_pad));
|
||||
SHA1Update(&fast_ctx->u.sha1, mac, 20);
|
||||
SHA1Final(mac, &fast_ctx->u.sha1);
|
||||
break;
|
||||
#ifdef CONFIG_SHA256
|
||||
case CRYPTO_HASH_ALG_HMAC_SHA256:
|
||||
if (*len < 32) {
|
||||
*len = 32;
|
||||
os_free(fast_ctx);
|
||||
return -1;
|
||||
}
|
||||
*len = 32;
|
||||
mbedtls_sha256_finish(&fast_ctx->u.sha256, mac);
|
||||
mbedtls_sha256_free(&fast_ctx->u.sha256);
|
||||
|
||||
os_memcpy(k_pad, fast_ctx->key, fast_ctx->key_len);
|
||||
os_memset(k_pad + fast_ctx->key_len, 0,
|
||||
sizeof(k_pad) - fast_ctx->key_len);
|
||||
for (i = 0; i < sizeof(k_pad); i++)
|
||||
k_pad[i] ^= 0x5c;
|
||||
mbedtls_sha256_init(&fast_ctx->u.sha256);
|
||||
mbedtls_sha256_starts(&fast_ctx->u.sha256, 0);
|
||||
mbedtls_sha256_update(&fast_ctx->u.sha256, k_pad, sizeof(k_pad));
|
||||
mbedtls_sha256_update(&fast_ctx->u.sha256, mac, 32);
|
||||
mbedtls_sha256_finish(&fast_ctx->u.sha256, mac);
|
||||
mbedtls_sha256_free(&fast_ctx->u.sha256);
|
||||
break;
|
||||
#endif /* CONFIG_SHA256 */
|
||||
default:
|
||||
os_free(fast_ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
os_free(fast_ctx);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
// Hardware crypto support Copyright 2017 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.
|
||||
|
||||
#include "crypto/includes.h"
|
||||
#include "crypto/common.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
|
||||
/**
|
||||
* fast_sha256_vector - SHA256 hash for data vector
|
||||
* @num_elem: Number of elements in the data vector
|
||||
* @addr: Pointers to the data areas
|
||||
* @len: Lengths of the data blocks
|
||||
* @mac: Buffer for the hash
|
||||
* Returns: 0 on success, -1 of failure
|
||||
*/
|
||||
int
|
||||
fast_sha256_vector(size_t num_elem, const uint8_t *addr[], const size_t *len,
|
||||
uint8_t *mac)
|
||||
{
|
||||
mbedtls_sha256_context ctx;
|
||||
|
||||
mbedtls_sha256_init(&ctx);
|
||||
|
||||
mbedtls_sha256_starts(&ctx, 0);
|
||||
|
||||
for(size_t index = 0; index < num_elem; index++) {
|
||||
mbedtls_sha256_update(&ctx, addr[index], len[index]);
|
||||
}
|
||||
|
||||
mbedtls_sha256_finish(&ctx, mac);
|
||||
|
||||
mbedtls_sha256_free(&ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
165
components/wpa_supplicant/src/fast_crypto/fast_sha256.c
Normal file
165
components/wpa_supplicant/src/fast_crypto/fast_sha256.c
Normal file
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* SHA-256 hash implementation and interface functions
|
||||
* Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* Hardware crypto support Copyright 2017 Espressif Systems (Shanghai) PTE LTD
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "crypto/includes.h"
|
||||
|
||||
#include "crypto/common.h"
|
||||
#include "crypto/sha256.h"
|
||||
#include "crypto/crypto.h"
|
||||
|
||||
|
||||
/**
|
||||
* fast_hmac_sha256_vector - HMAC-SHA256 over data vector (RFC 2104)
|
||||
* @key: Key for HMAC operations
|
||||
* @key_len: Length of the key in bytes
|
||||
* @num_elem: Number of elements in the data vector
|
||||
* @addr: Pointers to the data areas
|
||||
* @len: Lengths of the data blocks
|
||||
* @mac: Buffer for the hash (32 bytes)
|
||||
*/
|
||||
void
|
||||
fast_hmac_sha256_vector(const uint8_t *key, size_t key_len, size_t num_elem,
|
||||
const uint8_t *addr[], const size_t *len, uint8_t *mac)
|
||||
{
|
||||
uint8_t k_pad[64]; /* padding - key XORd with ipad/opad */
|
||||
uint8_t tk[32];
|
||||
const uint8_t *_addr[6];
|
||||
size_t _len[6], i;
|
||||
|
||||
if (num_elem > 5) {
|
||||
/*
|
||||
* Fixed limit on the number of fragments to avoid having to
|
||||
* allocate memory (which could fail).
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
/* if key is longer than 64 bytes reset it to key = SHA256(key) */
|
||||
if (key_len > 64) {
|
||||
fast_sha256_vector(1, &key, &key_len, tk);
|
||||
key = tk;
|
||||
key_len = 32;
|
||||
}
|
||||
|
||||
/* the HMAC_SHA256 transform looks like:
|
||||
*
|
||||
* SHA256(K XOR opad, SHA256(K XOR ipad, text))
|
||||
*
|
||||
* where K is an n byte key
|
||||
* ipad is the byte 0x36 repeated 64 times
|
||||
* opad is the byte 0x5c repeated 64 times
|
||||
* and text is the data being protected
|
||||
*/
|
||||
|
||||
/* start out by storing key in ipad */
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with ipad values */
|
||||
for (i = 0; i < 64; i++) {
|
||||
k_pad[i] ^= 0x36;
|
||||
}
|
||||
|
||||
/* perform inner SHA256 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
for (i = 0; i < num_elem; i++) {
|
||||
_addr[i + 1] = addr[i];
|
||||
_len[i + 1] = len[i];
|
||||
}
|
||||
fast_sha256_vector(1 + num_elem, _addr, _len, mac);
|
||||
|
||||
os_memset(k_pad, 0, sizeof(k_pad));
|
||||
os_memcpy(k_pad, key, key_len);
|
||||
/* XOR key with opad values */
|
||||
for (i = 0; i < 64; i++) {
|
||||
k_pad[i] ^= 0x5c;
|
||||
}
|
||||
|
||||
/* perform outer SHA256 */
|
||||
_addr[0] = k_pad;
|
||||
_len[0] = 64;
|
||||
_addr[1] = mac;
|
||||
_len[1] = SHA256_MAC_LEN;
|
||||
fast_sha256_vector(2, _addr, _len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fast_hmac_sha256 - HMAC-SHA256 over data buffer (RFC 2104)
|
||||
* @key: Key for HMAC operations
|
||||
* @key_len: Length of the key in bytes
|
||||
* @data: Pointers to the data area
|
||||
* @data_len: Length of the data area
|
||||
* @mac: Buffer for the hash (20 bytes)
|
||||
*/
|
||||
void
|
||||
fast_hmac_sha256(const uint8_t *key, size_t key_len, const uint8_t *data,
|
||||
size_t data_len, uint8_t *mac)
|
||||
{
|
||||
fast_hmac_sha256_vector(key, key_len, 1, &data, &data_len, mac);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* fast_sha256_prf - SHA256-based Pseudo-Random Function (IEEE 802.11r, 8.5.1.5.2)
|
||||
* @key: Key for PRF
|
||||
* @key_len: Length of the key in bytes
|
||||
* @label: A unique label for each purpose of the PRF
|
||||
* @data: Extra data to bind into the key
|
||||
* @data_len: Length of the data
|
||||
* @buf: Buffer for the generated pseudo-random key
|
||||
* @buf_len: Number of bytes of key to generate
|
||||
*
|
||||
* This function is used to derive new, cryptographically separate keys from a
|
||||
* given key.
|
||||
*/
|
||||
void
|
||||
fast_sha256_prf(const uint8_t *key, size_t key_len, const char *label,
|
||||
const uint8_t *data, size_t data_len, uint8_t *buf, size_t buf_len)
|
||||
{
|
||||
uint16_t counter = 1;
|
||||
size_t pos, plen;
|
||||
uint8_t hash[SHA256_MAC_LEN];
|
||||
const uint8_t *addr[4];
|
||||
size_t len[4];
|
||||
uint8_t counter_le[2], length_le[2];
|
||||
|
||||
addr[0] = counter_le;
|
||||
len[0] = 2;
|
||||
addr[1] = (uint8_t *) label;
|
||||
len[1] = os_strlen(label);
|
||||
addr[2] = data;
|
||||
len[2] = data_len;
|
||||
addr[3] = length_le;
|
||||
len[3] = sizeof(length_le);
|
||||
|
||||
WPA_PUT_LE16(length_le, buf_len * 8);
|
||||
pos = 0;
|
||||
while (pos < buf_len) {
|
||||
plen = buf_len - pos;
|
||||
WPA_PUT_LE16(counter_le, counter);
|
||||
if (plen >= SHA256_MAC_LEN) {
|
||||
fast_hmac_sha256_vector(key, key_len, 4, addr, len,
|
||||
&buf[pos]);
|
||||
pos += SHA256_MAC_LEN;
|
||||
} else {
|
||||
fast_hmac_sha256_vector(key, key_len, 4, addr, len, hash);
|
||||
os_memcpy(&buf[pos], hash, plen);
|
||||
break;
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
uint32_t eri_read(int addr) {
|
||||
uint32_t ret;
|
||||
asm(
|
||||
asm volatile (
|
||||
"RER %0,%1"
|
||||
:"=r"(ret):"r"(addr)
|
||||
);
|
||||
|
|
|
@ -25,6 +25,7 @@ INPUT = \
|
|||
## Wi-Fi - API Reference
|
||||
##
|
||||
../components/esp32/include/esp_wifi.h \
|
||||
../components/esp32/include/esp_wifi_crypto_types.h\
|
||||
../components/esp32/include/esp_smartconfig.h \
|
||||
## Bluetooth - API Reference
|
||||
## Controller && VHCI
|
||||
|
|
BIN
docs/_static/esp32-wrover-kit-layout-front.jpg
vendored
BIN
docs/_static/esp32-wrover-kit-layout-front.jpg
vendored
Binary file not shown.
Before Width: | Height: | Size: 109 KiB After Width: | Height: | Size: 112 KiB |
|
@ -13,7 +13,7 @@ Developers can use this library to send application specific state of execution
|
|||
|
||||
Tracing components when working over JTAG interface are shown in the figure below.
|
||||
|
||||
.. figure:: ../_static/app_trace/overview.png
|
||||
.. figure:: ../_static/app_trace/overview.jpg
|
||||
:align: center
|
||||
:alt: Tracing Components when Working Over JTAG
|
||||
:figclass: align-center
|
||||
|
@ -80,13 +80,13 @@ In general user should decide what type of data should be transferred in every d
|
|||
#include "esp_app_trace.h"
|
||||
...
|
||||
int number = 10;
|
||||
char *ptr = (char *)esp_apptrace_buffer_get(32, 100/*tmo in us*/);
|
||||
char *ptr = (char *)esp_apptrace_buffer_get(ESP_APPTRACE_DEST_TRAX, 32, 100/*tmo in us*/);
|
||||
if (ptr == NULL) {
|
||||
ESP_LOGE("Failed to get buffer!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
sprintf(ptr, "Here is the number %d", number);
|
||||
esp_err_t res = esp_apptrace_buffer_put(ptr, 100/*tmo in us*/);
|
||||
esp_err_t res = esp_apptrace_buffer_put(ESP_APPTRACE_DEST_TRAX, ptr, 100/*tmo in us*/);
|
||||
if (res != ESP_OK) {
|
||||
/* in case of error host tracing tool (e.g. OpenOCD) will report incomplete user buffer */
|
||||
ESP_LOGE("Failed to put buffer!");
|
||||
|
@ -100,7 +100,11 @@ Also according to his needs user may want to receive data from the host. Piece o
|
|||
#include "esp_app_trace.h"
|
||||
...
|
||||
char buf[32];
|
||||
char down_buf[32];
|
||||
size_t sz = sizeof(buf);
|
||||
|
||||
/* config down buffer */
|
||||
esp_apptrace_down_buffer_config(down_buf, sizeof(down_buf));
|
||||
/* check for incoming data and read them if any */
|
||||
esp_err_t res = esp_apptrace_read(ESP_APPTRACE_DEST_TRAX, buf, &sz, 0/*do not wait*/);
|
||||
if (res != ESP_OK) {
|
||||
|
@ -112,6 +116,37 @@ Also according to his needs user may want to receive data from the host. Piece o
|
|||
...
|
||||
}
|
||||
|
||||
``esp_apptrace_read()`` function uses memcpy to copy host data to user buffer. In some cases it can be more optimal to use ``esp_apptrace_down_buffer_get()`` and ``esp_apptrace_down_buffer_put()`` functions.
|
||||
They allow developers to ocupy chunk of read buffer and process it in-place. The following piece of code shows how to do this.
|
||||
|
||||
.. code-block:: c
|
||||
|
||||
#include "esp_app_trace.h"
|
||||
...
|
||||
char down_buf[32];
|
||||
uint32_t *number;
|
||||
size_t sz = 32;
|
||||
|
||||
/* config down buffer */
|
||||
esp_apptrace_down_buffer_config(down_buf, sizeof(down_buf));
|
||||
char *ptr = (char *)esp_apptrace_down_buffer_get(ESP_APPTRACE_DEST_TRAX, &sz, 100/*tmo in us*/);
|
||||
if (ptr == NULL) {
|
||||
ESP_LOGE("Failed to get buffer!");
|
||||
return ESP_FAIL;
|
||||
}
|
||||
if (sz > 4) {
|
||||
number = (uint32_t *)ptr;
|
||||
printf("Here is the number %d", *number);
|
||||
} else {
|
||||
printf("No data");
|
||||
}
|
||||
esp_err_t res = esp_apptrace_down_buffer_put(ESP_APPTRACE_DEST_TRAX, ptr, 100/*tmo in us*/);
|
||||
if (res != ESP_OK) {
|
||||
/* in case of error host tracing tool (e.g. OpenOCD) will report incomplete user buffer */
|
||||
ESP_LOGE("Failed to put buffer!");
|
||||
return res;
|
||||
}
|
||||
|
||||
2. The next step is to build the program image and download it to the target as described in :doc:`Build and Flash <../get-started/make-project>`.
|
||||
3. Run OpenOCD (see :doc:`JTAG Debugging <../api-guides/jtag-debugging/index>`).
|
||||
4. Connect to OpenOCD telnet server. On Linux it can be done using the following command in terminal ``telnet <oocd_host> 4444``. If telnet session is opened on the same machine which runs OpenOCD you can use ``localhost`` as ``<oocd_host>`` in the command above.
|
||||
|
@ -151,7 +186,7 @@ Sub-commands:
|
|||
|
||||
Start command syntax:
|
||||
|
||||
``start <outfile1> [outfile2] [poll_period [trace_size [stop_tmo [wait4halt [skip_size]]]]``
|
||||
``start <outfile> [poll_period [trace_size [stop_tmo [wait4halt [skip_size]]]]``
|
||||
|
||||
.. list-table::
|
||||
:widths: 20 80
|
||||
|
@ -159,10 +194,8 @@ Start command syntax:
|
|||
|
||||
* - Argument
|
||||
- Description
|
||||
* - outfile1
|
||||
- Path to file to save data from PRO CPU. This argument should have the following format: ``file://path/to/file``.
|
||||
* - outfile2
|
||||
- Path to file to save data from APP CPU. This argument should have the following format: ``file://path/to/file``.
|
||||
* - outfile
|
||||
- Path to file to save data from both CPUs. This argument should have the following format: ``file://path/to/file``.
|
||||
* - poll_period
|
||||
- Data polling period (in ms). If greater then 0 then command runs in non-blocking mode. By default 1 ms.
|
||||
* - trace_size
|
||||
|
|
|
@ -7,14 +7,6 @@ The following instructions are alternative to downloading binary OpenOCD from Es
|
|||
|
||||
.. highlight:: bash
|
||||
|
||||
Install Git
|
||||
===========
|
||||
|
||||
To be able to download OpenOCD sources from GitHub, install ``git`` package::
|
||||
|
||||
sudo apt-get install git
|
||||
|
||||
|
||||
Download Sources of OpenOCD
|
||||
===========================
|
||||
|
||||
|
|
|
@ -5,11 +5,67 @@ Building OpenOCD from Sources for Windows
|
|||
The following instructions are alternative to downloading binary OpenOCD from Espressif website. To quickly setup the binary OpenOCD, instead of compiling it yourself, backup and proceed to section :doc:`setup-openocd-windows`.
|
||||
|
||||
|
||||
.. highlight:: bash
|
||||
|
||||
Download Sources of OpenOCD
|
||||
===========================
|
||||
|
||||
The sources for the ESP32-enabled variant of OpenOCD are available from Espressif GitHub under https://github.com/espressif/openocd-esp32. To download the sources, use the following commands::
|
||||
|
||||
cd ~/esp
|
||||
git clone –recursive https://github.com/espressif/openocd-esp32.git
|
||||
|
||||
The clone of sources should be now saved in ``~/esp/openocd-esp32`` directory.
|
||||
|
||||
|
||||
Install Dependencies
|
||||
====================
|
||||
|
||||
Install packages that are required to compile OpenOCD:
|
||||
|
||||
.. note::
|
||||
|
||||
Install the following packages one by one, check if installation was successful and then proceed to the next package. Resolve reported problems before moving to the next step.
|
||||
|
||||
::
|
||||
|
||||
pacman -S libtool
|
||||
pacman -S autoconf
|
||||
pacman -S automake
|
||||
pacman -S texinfo
|
||||
pacman -S mingw-w64-i686-libusb-compat-git
|
||||
pacman -S pkg-config
|
||||
|
||||
.. note::
|
||||
|
||||
Installation of ``pkg-config`` is breaking operation of esp-idf toolchain. After building of OpenOCD it should be uninstalled. It be covered at the end of this instruction. To build OpenOCD again, you will need to run ``pacman -S pkg-config`` once more. This issue does not concern other packages installed in this step (before ``pkg-config``).
|
||||
|
||||
|
||||
Build OpenOCD
|
||||
=============
|
||||
|
||||
Refer to build process described in ``README.Windows`` file, that is provided with
|
||||
OpenOCD source code in https://github.com/espressif/openocd-esp32 repository.
|
||||
Proceed with configuring and building OpenOCD::
|
||||
|
||||
cd ~/esp/openocd-esp32
|
||||
./bootstrap
|
||||
./configure
|
||||
make
|
||||
|
||||
Optionally you can add ``make install`` step at the end. Skip it, if you have an existing OpenOCD (from e.g. another development platform), as it may get overwritten.
|
||||
|
||||
.. note::
|
||||
|
||||
* Should an error occur, resolve it and try again until the command ``make`` works.
|
||||
* If there is a submodule problem from OpenOCD, please ``cd`` to the ``openocd-esp32`` directory and input ``git submodule update --init``.
|
||||
* If the ``./configure`` is successfully run, information of enabled JTAG will be printed under ``OpenOCD configuration summary``.
|
||||
* If the information of your device is not shown in the log, use ``./configure`` to enable it as described in ``../openocd-esp32/doc/INSTALL.txt``.
|
||||
* For details concerning compiling OpenOCD, please refer to ``openocd-esp32/README.Windows``.
|
||||
|
||||
Once ``make`` process is successfully completed, the executable of OpenOCD will be saved in ``~/esp/openocd-esp32/src/openocd`` directory.
|
||||
|
||||
Remove ``pkg-config``, as discussed during installation of dependencies::
|
||||
|
||||
pacman -Rs pkg-config
|
||||
|
||||
|
||||
Next Steps
|
||||
|
|
|
@ -19,6 +19,7 @@ ESP32 Wi-Fi Feature List
|
|||
- Supports an Espressif-specific protocol which, in turn, supports up to **1 km** of data traffic
|
||||
- Up to 20 MBit/sec TCP throughput and 30 MBit/sec UDP throughput over the air
|
||||
- Supports Sniffer
|
||||
- Support set fast_crypto algorithm and normal algorithm switch which used in wifi connect
|
||||
|
||||
How To Write a Wi-Fi Application
|
||||
----------------------------------
|
||||
|
@ -1215,6 +1216,15 @@ Currently, ESP32 Wi-Fi supports the Modem-sleep mode which refers to WMM (Wi-Fi
|
|||
|
||||
Call esp_wifi_set_ps(WIFI_PS_MODEM) to enable Modem-sleep mode after calling esp_wifi_init(). About 10 seconds after the station connects to the AP, Modem-sleep will start. When the station disconnects from the AP, Modem-sleep will stop.
|
||||
|
||||
ESP32 Wi-Fi Connect Crypto
|
||||
-----------------------------------
|
||||
Now ESP32 have two group crypto functions can be used when do wifi connect, one is the original functions, the other is optimized by ESP hardware:
|
||||
1. Original functions which is the source code used in the folder components/wpa_supplicant/src/crypto function;
|
||||
2. The optimized functions is in the folder components/wpa_supplicant/src/fast_crypto, these function used the hardware crypto to make it faster than origin one, the type of function's name add fast_ to distinguish with the original one. For example, the API aes_wrap() is used to encrypt frame information when do 4 way handshake, the fast_aes_wrap() has the same result but can be faster.
|
||||
|
||||
Two groups of crypto function can be used when register in the wpa_crypto_funcs_t, wpa2_crypto_funcs_t and wps_crypto_funcs_t structure, also we have given the recommend functions to register in the
|
||||
fast_crypto_ops.c, you can register the function as the way you need, however what should make action is that the crypto_hash_xxx function and crypto_cipher_xxx function need to register with the same function to operation. For example, if you register crypto_hash_init() function to initialize the esp_crypto_hash structure, you need use the crypto_hash_update() and crypto_hash_finish() function to finish the operation, rather than fast_crypto_hash_update() or fast_crypto_hash_finish().
|
||||
|
||||
ESP32 Wi-Fi Throughput
|
||||
-----------------------------------
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ What You Need
|
|||
-------------
|
||||
|
||||
* 1 × ESP32-DevKitC board
|
||||
* 1 × USB A / mini USB B cable
|
||||
* 1 × PC loaded with Windows, Linux or Mac O/S
|
||||
* 1 × USB A / micro USB B cable
|
||||
* 1 × PC loaded with Windows, Linux or Mac OS
|
||||
|
||||
|
||||
Overview
|
||||
|
|
|
@ -8,8 +8,8 @@ What You Need
|
|||
-------------
|
||||
|
||||
* 1 × ESP-WROVER-KIT board
|
||||
* 1 × USB A / mini USB B cable
|
||||
* 1 × PC loaded with Windows, Linux or Mac O/S
|
||||
* 1 × USB A / micro USB B cable
|
||||
* 1 × PC loaded with Windows, Linux or Mac OS
|
||||
|
||||
|
||||
The Board
|
||||
|
@ -48,6 +48,8 @@ The following list and figures below describe key components, interfaces and con
|
|||
|
||||
32.768 kHz
|
||||
An external precision 32.768 kHz crystal oscillator provides the chip with a clock of low-power consumption during the Deep-sleep mode.
|
||||
0R
|
||||
A zero Ohm resistor intended as a placeholder for a current shunt. May be desoldered or replaced with a current shunt to facilitate measurement of current required by ESP32 module depending on power mode.
|
||||
ESP32 Module
|
||||
ESP-WROVER-KIT is compatible with both ESP-WROOM-32 and ESP32-WROVER. The ESP32-WROVER module features all the functions of ESP-WROOM-32 and integrates an external 32-MBit PSRAM for flexible extended storage and data processing capabilities.
|
||||
|
||||
|
@ -55,18 +57,20 @@ ESP32 Module
|
|||
|
||||
GPIO16 and GPIO17 are used as the CS and clock signal for PSRAM. To ensure reliable performance, the two GPIOs are not broken out.
|
||||
|
||||
CTS/RTS
|
||||
Serial port flow control signals: the pins are not connected to the circuitry by default. To enable them, respective pins of JP14 must be shorted with jumpers.
|
||||
FT2232
|
||||
FT2232 chip is a multi-protocol USB-to-serial bridge. Users can control and program the FT2232 chip through the USB interface to establish communication with ESP32. The FT2232 chip also features USB-to-JTAG interface.
|
||||
|
||||
USB-to-JTAG is available on channel A of FT2232, USB-to-serial on channel B.
|
||||
|
||||
The embedded FT2232 chip is one of the distinguishing features of the ESPWROVER-KIT. It enhances users’ convenience in terms of application development and debugging. In addition, uses do not need to buy a JTAG debugger separately, which reduces the development cost. The schematics is provided in section :ref:`wrover-kit-related-documents`.
|
||||
UART
|
||||
Serial port: the serial TX/RX signals on FT2232HL and ESP32 are broken out to the two sides of JP11. By default, the two signals are connected with jumpers. To use the ESP32 module serial interface only, the jumpers may be removed and the module can be connected to another external serial device.
|
||||
SPI
|
||||
SPI interface: the SPI interface connects to an external flash (PSRAM). To interface another SPI device, an extra CS signal is needed. If an ESP32-WROVER is being used, please note that the electrical level on the flash and SRAM is 1.8V.
|
||||
CTS/RTS
|
||||
Serial port flow control signals: the pins are not connected to the circuitry by default. To enable them, respective pins of JP14 must be shorted with jumpers.
|
||||
JTAG
|
||||
JTAG interface: the JTAG signals on FT2232HL and ESP32 are broken out to the two sides of JP8. By default, the two signals are disconnected. To enable JTAG, shorting jumpers are required on the signals.
|
||||
FT2232
|
||||
FT2232 chip is a multi-protocol USB-to-serial bridge. The FT2232 chip features USB-to-UART and USB-to-JTAG functionalities. Users can control and program the FT2232 chip through the USB interface to establish communication with ESP32.
|
||||
|
||||
The embedded FT2232 chip is one of the distinguishing features of the ESPWROVER-KIT. It enhances users’ convenience in terms of application development and debugging. In addition, uses do not need to buy a JTAG debugger separately, which reduces the development cost. The schematics is provided in section :ref:`wrover-kit-related-documents`.
|
||||
EN
|
||||
Reset button: pressing this button resets the system.
|
||||
Boot
|
||||
|
@ -185,7 +189,7 @@ Related Documents
|
|||
* `ESP-WROVER-KIT schematic`_ (PDF)
|
||||
* `ESP32 Datasheet <http://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf>`_ (PDF)
|
||||
* `ESP-WROOM-32 Datasheet <http://espressif.com/sites/default/files/documentation/esp-wroom-32_datasheet_en.pdf>`_ (PDF)
|
||||
* `JTAG Debugging for ESP32 <https://espressif.com/sites/default/files/documentation/jtag_debugging_for_esp32_en.pdf>`_ (PDF)
|
||||
* :doc:`../api-guides/jtag-debugging/index`
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -62,6 +62,7 @@ static void wifi_power_save(void)
|
|||
{
|
||||
tcpip_adapter_init();
|
||||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
wifi_config_t wifi_config = {
|
||||
|
|
|
@ -57,7 +57,9 @@ static void initialise_wifi(void)
|
|||
tcpip_adapter_init();
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
|
||||
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
|
||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||
|
|
|
@ -100,6 +100,7 @@ static void initialise_wifi(void)
|
|||
unsigned int ca_pem_bytes = ca_pem_end - ca_pem_start;
|
||||
unsigned int client_crt_bytes = client_crt_end - client_crt_start;
|
||||
unsigned int client_key_bytes = client_key_end - client_key_start;
|
||||
esp_wpa2_config_t config = WPA2_CONFIG_INIT_DEFAULT();
|
||||
|
||||
tcpip_adapter_init();
|
||||
wifi_event_group = xEventGroupCreate();
|
||||
|
@ -123,7 +124,8 @@ static void initialise_wifi(void)
|
|||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_username((uint8_t *)EXAMPLE_EAP_USERNAME, strlen(EXAMPLE_EAP_USERNAME)) );
|
||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_set_password((uint8_t *)EXAMPLE_EAP_PASSWORD, strlen(EXAMPLE_EAP_PASSWORD)) );
|
||||
}
|
||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_enable() );
|
||||
|
||||
ESP_ERROR_CHECK( esp_wifi_sta_wpa2_ent_enable(&config) );
|
||||
ESP_ERROR_CHECK( esp_wifi_start() );
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
|
||||
|
||||
static const char *TAG = "example_wps";
|
||||
|
||||
static esp_wps_config_t config = WPS_CONFIG_INIT_DEFAULT(WPS_TEST_MODE);
|
||||
|
||||
static esp_err_t event_handler(void *ctx, system_event_t *event)
|
||||
{
|
||||
|
@ -68,13 +68,13 @@ static esp_err_t event_handler(void *ctx, system_event_t *event)
|
|||
case SYSTEM_EVENT_STA_WPS_ER_FAILED:
|
||||
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_WPS_ER_FAILED");
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(WPS_TEST_MODE));
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT:
|
||||
ESP_LOGI(TAG, "SYSTEM_EVENT_STA_WPS_ER_TIMEOUT");
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_disable());
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(WPS_TEST_MODE));
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
||||
break;
|
||||
case SYSTEM_EVENT_STA_WPS_ER_PIN:
|
||||
|
@ -95,13 +95,16 @@ static void start_wps(void)
|
|||
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||
|
||||
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||
ESP_ERROR_CHECK(esp_wifi_start());
|
||||
|
||||
ESP_LOGI(TAG, "start wps...");
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(WPS_TEST_MODE));
|
||||
|
||||
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_enable(&config));
|
||||
ESP_ERROR_CHECK(esp_wifi_wps_start(0));
|
||||
}
|
||||
|
||||
|
|
|
@ -290,7 +290,7 @@ export HOSTCC HOSTLD HOSTAR HOSTOBJCOPY SIZE
|
|||
CC := $(call dequote,$(CONFIG_TOOLPREFIX))gcc
|
||||
CXX := $(call dequote,$(CONFIG_TOOLPREFIX))c++
|
||||
LD := $(call dequote,$(CONFIG_TOOLPREFIX))ld
|
||||
AR := $(call dequote,$(CONFIG_TOOLPREFIX))gcc-ar
|
||||
AR := $(call dequote,$(CONFIG_TOOLPREFIX))ar
|
||||
OBJCOPY := $(call dequote,$(CONFIG_TOOLPREFIX))objcopy
|
||||
SIZE := $(call dequote,$(CONFIG_TOOLPREFIX))size
|
||||
export CC CXX LD AR OBJCOPY SIZE
|
||||
|
|
|
@ -88,7 +88,9 @@ CONFIG_APP_OFFSET=0x10000
|
|||
#
|
||||
CONFIG_OPTIMIZATION_LEVEL_DEBUG=y
|
||||
# CONFIG_OPTIMIZATION_LEVEL_RELEASE is not set
|
||||
CONFIG_OPTIMIZATION_ASSERTIONS=y
|
||||
CONFIG_OPTIMIZATION_ASSERTIONS_ENABLED=y
|
||||
# CONFIG_OPTIMIZATION_ASSERTIONS_SILENT is not set
|
||||
# CONFIG_OPTIMIZATION_ASSERTIONS_DISABLED is not set
|
||||
|
||||
#
|
||||
# Component config
|
||||
|
@ -100,6 +102,7 @@ CONFIG_OPTIMIZATION_ASSERTIONS=y
|
|||
# CONFIG_ESP32_APPTRACE_DEST_TRAX is not set
|
||||
CONFIG_ESP32_APPTRACE_DEST_NONE=y
|
||||
# CONFIG_ESP32_APPTRACE_ENABLE is not set
|
||||
CONFIG_ESP32_APPTRACE_LOCK_ENABLE=y
|
||||
|
||||
#
|
||||
# FreeRTOS SystemView Tracing
|
||||
|
@ -149,6 +152,16 @@ CONFIG_INT_WDT=y
|
|||
CONFIG_INT_WDT_TIMEOUT_MS=300
|
||||
CONFIG_INT_WDT_CHECK_CPU1=y
|
||||
# CONFIG_TASK_WDT is not set
|
||||
CONFIG_BROWNOUT_DET=y
|
||||
CONFIG_BROWNOUT_DET_LVL_SEL_0=y
|
||||
# CONFIG_BROWNOUT_DET_LVL_SEL_1 is not set
|
||||
# CONFIG_BROWNOUT_DET_LVL_SEL_2 is not set
|
||||
# CONFIG_BROWNOUT_DET_LVL_SEL_3 is not set
|
||||
# CONFIG_BROWNOUT_DET_LVL_SEL_4 is not set
|
||||
# CONFIG_BROWNOUT_DET_LVL_SEL_5 is not set
|
||||
# CONFIG_BROWNOUT_DET_LVL_SEL_6 is not set
|
||||
# CONFIG_BROWNOUT_DET_LVL_SEL_7 is not set
|
||||
CONFIG_BROWNOUT_DET_LVL=0
|
||||
# CONFIG_ESP32_TIME_SYSCALL_USE_RTC is not set
|
||||
CONFIG_ESP32_TIME_SYSCALL_USE_RTC_FRC1=y
|
||||
# CONFIG_ESP32_TIME_SYSCALL_USE_FRC1 is not set
|
||||
|
@ -227,6 +240,7 @@ CONFIG_FREERTOS_ASSERT_FAIL_ABORT=y
|
|||
# CONFIG_FREERTOS_ASSERT_DISABLE is not set
|
||||
CONFIG_FREERTOS_BREAK_ON_SCHEDULER_START_JTAG=y
|
||||
# CONFIG_ENABLE_MEMORY_DEBUG is not set
|
||||
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024
|
||||
CONFIG_FREERTOS_ISR_STACKSIZE=1536
|
||||
# CONFIG_FREERTOS_LEGACY_HOOKS is not set
|
||||
CONFIG_FREERTOS_MAX_TASK_NAME_LEN=16
|
||||
|
|
Loading…
Reference in a new issue