Merge branch 'feature/btdm_bluedroid' into feature/btdm_a2dp
# Conflicts: # examples/13_bt_sdp/components/bluedroid_demos/btif/btif_core.c # examples/13_bt_sdp/components/bluedroid_demos/include/btif_util.h
This commit is contained in:
commit
11ddfbba4e
|
@ -46,6 +46,10 @@ build_template_app:
|
|||
- sed -i.bak -e's/CONFIG_OPTIMIZATION_LEVEL_DEBUG\=y/CONFIG_OPTIMIZATION_LEVEL_RELEASE=y/' sdkconfig
|
||||
- make defconfig
|
||||
- make all V=1
|
||||
# Check if there are any stray printf/ets_printf references in WiFi libs
|
||||
- cd ../components/esp32/lib
|
||||
- test $(xtensa-esp32-elf-nm *.a | grep -w printf | wc -l) -eq 0
|
||||
- test $(xtensa-esp32-elf-nm *.a | grep -w ets_printf | wc -l) -eq 0
|
||||
|
||||
|
||||
.build_gitlab: &build_template
|
||||
|
@ -88,7 +92,7 @@ build_esp_idf_tests:
|
|||
- cd tools/unit-test-app
|
||||
- git checkout ${CI_BUILD_REF_NAME} || echo "Using default branch..."
|
||||
- make defconfig
|
||||
- make
|
||||
- make TESTS_ALL=1
|
||||
|
||||
build_examples:
|
||||
<<: *build_template
|
||||
|
@ -288,7 +292,7 @@ deploy_docs:
|
|||
variables:
|
||||
# jobs MUST set CONFIG_FILE in before_script, and overwrite the variables above if necessary
|
||||
LOCAL_ENV_CONFIG_PATH: /home/gitlab-runner/LocalConfig/ESP32_IDF
|
||||
BIN_PATH: "$CI_PROJECT_DIR/esp-idf-tests/build/"
|
||||
BIN_PATH: "$CI_PROJECT_DIR/tools/unit-test-app/build/"
|
||||
LOG_PATH: "$CI_PROJECT_DIR/$CI_BUILD_REF"
|
||||
APP_NAME: "ut"
|
||||
TEST_CASE_FILE_PATH: "$CI_PROJECT_DIR/components/idf_test/unit_test"
|
||||
|
|
5
components/app_update/component.mk
Executable file
5
components/app_update/component.mk
Executable file
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
# Component Makefile
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
381
components/app_update/esp_ota_ops.c
Normal file
381
components/app_update/esp_ota_ops.c
Normal file
|
@ -0,0 +1,381 @@
|
|||
// Copyright 2015-2016 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 <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_spi_flash.h"
|
||||
#include "esp_image_format.h"
|
||||
#include "esp_secure_boot.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "esp_ota_ops.h"
|
||||
#include "rom/queue.h"
|
||||
#include "rom/crc.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
|
||||
#define OTA_MAX(a,b) ((a) >= (b) ? (a) : (b))
|
||||
#define OTA_MIN(a,b) ((a) <= (b) ? (a) : (b))
|
||||
#define SUB_TYPE_ID(i) (i & 0x0F)
|
||||
|
||||
typedef struct ota_ops_entry_ {
|
||||
uint32_t handle;
|
||||
esp_partition_t part;
|
||||
uint32_t erased_size;
|
||||
uint32_t wrote_size;
|
||||
LIST_ENTRY(ota_ops_entry_) entries;
|
||||
} ota_ops_entry_t;
|
||||
|
||||
/* OTA selection structure (two copies in the OTA data partition.)
|
||||
Size of 32 bytes is friendly to flash encryption */
|
||||
typedef struct {
|
||||
uint32_t ota_seq;
|
||||
uint8_t seq_label[24];
|
||||
uint32_t crc; /* CRC32 of ota_seq field only */
|
||||
} ota_select;
|
||||
|
||||
static LIST_HEAD(ota_ops_entries_head, ota_ops_entry_) s_ota_ops_entries_head =
|
||||
LIST_HEAD_INITIALIZER(s_ota_ops_entries_head);
|
||||
|
||||
static uint32_t s_ota_ops_last_handle = 0;
|
||||
static ota_select s_ota_select[2];
|
||||
|
||||
const static char *TAG = "esp_ota_ops";
|
||||
|
||||
esp_err_t esp_ota_begin(const esp_partition_t *partition, size_t image_size, esp_ota_handle_t *out_handle)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if ((partition == NULL) || (out_handle == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
ota_ops_entry_t *new_entry = (ota_ops_entry_t *) calloc(sizeof(ota_ops_entry_t), 1);
|
||||
|
||||
if (new_entry == 0) {
|
||||
return ESP_ERR_NO_MEM;
|
||||
}
|
||||
|
||||
// if input image size is 0 or OTA_SIZE_UNKNOWN, will erase all areas in this partition
|
||||
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
|
||||
ret = esp_partition_erase_range(partition, 0, partition->size);
|
||||
} else {
|
||||
ret = esp_partition_erase_range(partition, 0, (image_size / SPI_FLASH_SEC_SIZE + 1) * SPI_FLASH_SEC_SIZE);
|
||||
}
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
free(new_entry);
|
||||
new_entry = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
LIST_INSERT_HEAD(&s_ota_ops_entries_head, new_entry, entries);
|
||||
|
||||
if ((image_size == 0) || (image_size == OTA_SIZE_UNKNOWN)) {
|
||||
new_entry->erased_size = partition->size;
|
||||
} else {
|
||||
new_entry->erased_size = image_size;
|
||||
}
|
||||
|
||||
memcpy(&new_entry->part, partition, sizeof(esp_partition_t));
|
||||
new_entry->handle = ++s_ota_ops_last_handle;
|
||||
*out_handle = new_entry->handle;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
|
||||
{
|
||||
esp_err_t ret;
|
||||
ota_ops_entry_t *it;
|
||||
|
||||
if (data == NULL) {
|
||||
ESP_LOGE(TAG, "write data is invalid");
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
// find ota handle in linked list
|
||||
for (it = LIST_FIRST(&s_ota_ops_entries_head); it != NULL; it = LIST_NEXT(it, entries)) {
|
||||
if (it->handle == handle) {
|
||||
// must erase the partition before writing to it
|
||||
assert(it->erased_size > 0 && "must erase the partition before writing to it");
|
||||
ret = esp_partition_write(&it->part, it->wrote_size, data, size);
|
||||
if(ret == ESP_OK){
|
||||
it->wrote_size += size;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
//if go to here ,means don't find the handle
|
||||
ESP_LOGE(TAG,"not found the handle")
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
esp_err_t esp_ota_end(esp_ota_handle_t handle)
|
||||
{
|
||||
esp_err_t ret;
|
||||
ota_ops_entry_t *it;
|
||||
size_t image_size;
|
||||
for (it = LIST_FIRST(&s_ota_ops_entries_head); it != NULL; it = LIST_NEXT(it, entries)) {
|
||||
if (it->handle == handle) {
|
||||
// an ota handle need to be ended after erased and wrote data in it
|
||||
if ((it->erased_size == 0) || (it->wrote_size == 0)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SECUREBOOTLOADER
|
||||
if (esp_image_basic_verify(it->part.address, &image_size) != ESP_OK) {
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
ret = esp_secure_boot_verify_signature(it->part.address, image_size);
|
||||
if (ret != ESP_OK) {
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
LIST_REMOVE(it, entries);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (it == NULL) {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
free(it);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static uint32_t ota_select_crc(const ota_select *s)
|
||||
{
|
||||
return crc32_le(UINT32_MAX, (uint8_t *)&s->ota_seq, 4);
|
||||
}
|
||||
|
||||
static bool ota_select_valid(const ota_select *s)
|
||||
{
|
||||
return s->ota_seq != UINT32_MAX && s->crc == ota_select_crc(s);
|
||||
}
|
||||
|
||||
static esp_err_t rewrite_ota_seq(uint32_t seq, uint8_t sec_id, const esp_partition_t *ota_data_partition)
|
||||
{
|
||||
esp_err_t ret;
|
||||
|
||||
if (sec_id == 0 || sec_id == 1) {
|
||||
s_ota_select[sec_id].ota_seq = seq;
|
||||
s_ota_select[sec_id].crc = ota_select_crc(&s_ota_select[sec_id]);
|
||||
ret = esp_partition_erase_range(ota_data_partition, sec_id * SPI_FLASH_SEC_SIZE, SPI_FLASH_SEC_SIZE);
|
||||
if (ret != ESP_OK) {
|
||||
return ret;
|
||||
} else {
|
||||
return esp_partition_write(ota_data_partition, SPI_FLASH_SEC_SIZE * sec_id, &s_ota_select[sec_id].ota_seq, sizeof(ota_select));
|
||||
}
|
||||
} else {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t get_ota_partition_count(void)
|
||||
{
|
||||
uint16_t ota_app_count = 0;
|
||||
while (esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_MIN + ota_app_count, NULL) != NULL) {
|
||||
assert(ota_app_count < 16 && "must erase the partition before writing to it");
|
||||
ota_app_count++;
|
||||
}
|
||||
return ota_app_count;
|
||||
}
|
||||
|
||||
static esp_err_t esp_rewrite_ota_data(esp_partition_subtype_t subtype)
|
||||
{
|
||||
esp_err_t ret;
|
||||
const esp_partition_t *find_partition = NULL;
|
||||
uint16_t ota_app_count = 0;
|
||||
uint32_t i = 0;
|
||||
uint32_t seq;
|
||||
static spi_flash_mmap_memory_t ota_data_map;
|
||||
const void *result = NULL;
|
||||
|
||||
find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
|
||||
if (find_partition != NULL) {
|
||||
ota_app_count = get_ota_partition_count();
|
||||
//esp32_idf use two sector for store information about which partition is running
|
||||
//it defined the two sector as ota data partition,two structure ota_select is saved in the two sector
|
||||
//named data in first sector as s_ota_select[0], second sector data as s_ota_select[1]
|
||||
//e.g.
|
||||
//if s_ota_select[0].ota_seq == s_ota_select[1].ota_seq == 0xFFFFFFFF,means ota info partition is in init status
|
||||
//so it will boot factory application(if there is),if there's no factory application,it will boot ota[0] application
|
||||
//if s_ota_select[0].ota_seq != 0 and s_ota_select[1].ota_seq != 0,it will choose a max seq ,and get value of max_seq%max_ota_app_number
|
||||
//and boot a subtype (mask 0x0F) value is (max_seq - 1)%max_ota_app_number,so if want switch to run ota[x],can use next formulas.
|
||||
//for example, if s_ota_select[0].ota_seq = 4, s_ota_select[1].ota_seq = 5, and there are 8 ota application,
|
||||
//current running is (5-1)%8 = 4,running ota[4],so if we want to switch to run ota[7],
|
||||
//we should add s_ota_select[0].ota_seq (is 4) to 4 ,(8-1)%8=7,then it will boot ota[7]
|
||||
//if A=(B - C)%D
|
||||
//then B=(A + C)%D + D*n ,n= (0,1,2...)
|
||||
//so current ota app sub type id is x , dest bin subtype is y,total ota app count is n
|
||||
//seq will add (x + n*1 + 1 - seq)%n
|
||||
if (SUB_TYPE_ID(subtype) >= ota_app_count) {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
|
||||
ret = esp_partition_mmap(find_partition, 0, find_partition->size, SPI_FLASH_MMAP_DATA, &result, &ota_data_map);
|
||||
if (ret != ESP_OK) {
|
||||
result = NULL;
|
||||
return ret;
|
||||
} else {
|
||||
memcpy(&s_ota_select[0], result, sizeof(ota_select));
|
||||
memcpy(&s_ota_select[1], result + SPI_FLASH_SEC_SIZE, sizeof(ota_select));
|
||||
spi_flash_munmap(ota_data_map);
|
||||
}
|
||||
|
||||
if (ota_select_valid(&s_ota_select[0]) && ota_select_valid(&s_ota_select[1])) {
|
||||
seq = OTA_MAX(s_ota_select[0].ota_seq, s_ota_select[1].ota_seq);
|
||||
while (seq > (SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count) {
|
||||
i++;
|
||||
}
|
||||
|
||||
if (s_ota_select[0].ota_seq >= s_ota_select[1].ota_seq) {
|
||||
return rewrite_ota_seq((SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count, 0, find_partition);
|
||||
} else {
|
||||
return rewrite_ota_seq((SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count, 1, find_partition);
|
||||
}
|
||||
|
||||
} else if (ota_select_valid(&s_ota_select[0])) {
|
||||
while (s_ota_select[0].ota_seq > (SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count) {
|
||||
i++;
|
||||
}
|
||||
return rewrite_ota_seq((SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count, 1, find_partition);
|
||||
|
||||
} else if (ota_select_valid(&s_ota_select[1])) {
|
||||
while (s_ota_select[1].ota_seq > (SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count) {
|
||||
i++;
|
||||
}
|
||||
return rewrite_ota_seq((SUB_TYPE_ID(subtype) + 1) % ota_app_count + i * ota_app_count, 0, find_partition);
|
||||
|
||||
} else if (s_ota_select[0].ota_seq == 0xFFFFFFFF && s_ota_select[1].ota_seq == 0xFFFFFFFF) {
|
||||
return rewrite_ota_seq(SUB_TYPE_ID(subtype) + 1, 0, find_partition);
|
||||
|
||||
} else {
|
||||
return ESP_ERR_OTA_SELECT_INFO_INVALID;
|
||||
}
|
||||
|
||||
} else {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t esp_ota_set_boot_partition(const esp_partition_t *partition)
|
||||
{
|
||||
const esp_partition_t *find_partition = NULL;
|
||||
size_t image_size;
|
||||
if (partition == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_SECUREBOOTLOADER
|
||||
if (esp_image_basic_verify(partition->address, &image_size) != ESP_OK) {
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
ret = esp_secure_boot_verify_signature(partition->address, image_size);
|
||||
if (ret != ESP_OK) {
|
||||
return ESP_ERR_OTA_VALIDATE_FAILED;
|
||||
}
|
||||
#endif
|
||||
// if set boot partition to factory bin ,just format ota info partition
|
||||
if (partition->type == ESP_PARTITION_TYPE_APP) {
|
||||
if (partition->subtype == ESP_PARTITION_SUBTYPE_APP_FACTORY) {
|
||||
find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
|
||||
if (find_partition != NULL) {
|
||||
return esp_partition_erase_range(find_partition, 0, find_partition->size);
|
||||
} else {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
} else {
|
||||
// try to find this partition in flash,if not find it ,return error
|
||||
find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
|
||||
if (find_partition != NULL) {
|
||||
return esp_rewrite_ota_data(partition->subtype);
|
||||
} else {
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
const esp_partition_t *esp_ota_get_boot_partition(void)
|
||||
{
|
||||
esp_err_t ret;
|
||||
const esp_partition_t *find_partition = NULL;
|
||||
static spi_flash_mmap_memory_t ota_data_map;
|
||||
const void *result = NULL;
|
||||
uint16_t ota_app_count = 0;
|
||||
find_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_OTA, NULL);
|
||||
|
||||
if (find_partition == NULL) {
|
||||
ESP_LOGE(TAG, "not found ota data");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = esp_partition_mmap(find_partition, 0, find_partition->size, SPI_FLASH_MMAP_DATA, &result, &ota_data_map);
|
||||
if (ret != ESP_OK) {
|
||||
spi_flash_munmap(ota_data_map);
|
||||
ESP_LOGE(TAG, "mmap ota data filed");
|
||||
return NULL;
|
||||
} else {
|
||||
memcpy(&s_ota_select[0], result, sizeof(ota_select));
|
||||
memcpy(&s_ota_select[1], result + 0x1000, sizeof(ota_select));
|
||||
spi_flash_munmap(ota_data_map);
|
||||
}
|
||||
ota_app_count = get_ota_partition_count();
|
||||
|
||||
ESP_LOGD(TAG, "found ota bin max = %d", ota_app_count);
|
||||
if (s_ota_select[0].ota_seq == 0xFFFFFFFF && s_ota_select[1].ota_seq == 0xFFFFFFFF) {
|
||||
ESP_LOGD(TAG, "finding factory bin......");
|
||||
|
||||
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_FACTORY, NULL);
|
||||
} else if (ota_select_valid(&s_ota_select[0]) && ota_select_valid(&s_ota_select[1])) {
|
||||
ESP_LOGD(TAG, "finding ota_%d bin......", \
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + ((OTA_MAX(s_ota_select[0].ota_seq, s_ota_select[1].ota_seq) - 1) % ota_app_count));
|
||||
|
||||
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + ((OTA_MAX(s_ota_select[0].ota_seq, s_ota_select[1].ota_seq) - 1) % ota_app_count), NULL);
|
||||
} else if (ota_select_valid(&s_ota_select[0])) {
|
||||
ESP_LOGD(TAG, "finding ota_%d bin......", \
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[0].ota_seq - 1) % ota_app_count);
|
||||
|
||||
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[0].ota_seq - 1) % ota_app_count, NULL);
|
||||
|
||||
} else if (ota_select_valid(&s_ota_select[1])) {
|
||||
ESP_LOGD(TAG, "finding ota_%d bin......", \
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[1].ota_seq - 1) % ota_app_count);
|
||||
|
||||
return esp_partition_find_first(ESP_PARTITION_TYPE_APP, \
|
||||
ESP_PARTITION_SUBTYPE_APP_OTA_MIN + (s_ota_select[1].ota_seq - 1) % ota_app_count, NULL);
|
||||
|
||||
} else {
|
||||
ESP_LOGE(TAG, "not found current bin");
|
||||
return NULL;
|
||||
}
|
||||
}
|
110
components/app_update/include/esp_ota_ops.h
Executable file
110
components/app_update/include/esp_ota_ops.h
Executable file
|
@ -0,0 +1,110 @@
|
|||
// Copyright 2015-2016 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 _OTA_OPS_H
|
||||
#define _OTA_OPS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_partition.h"
|
||||
#include "esp_spi_flash.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#define OTA_SIZE_UNKNOWN 0xffffffff
|
||||
|
||||
#define ESP_ERR_OTA_BASE 0x1500 /*!< base error code for ota_ops api */
|
||||
#define ESP_ERR_OTA_PARTITION_CONFLICT (ESP_ERR_OTA_BASE + 0x01) /*!< want to write or erase current running partition */
|
||||
#define ESP_ERR_OTA_SELECT_INFO_INVALID (ESP_ERR_OTA_BASE + 0x02) /*!< ota data partition info is error */
|
||||
#define ESP_ERR_OTA_VALIDATE_FAILED (ESP_ERR_OTA_BASE + 0x03) /*!< validate ota image failed */
|
||||
|
||||
/**
|
||||
* @brief Opaque handle for application update obtained from app_ops.
|
||||
*/
|
||||
typedef uint32_t esp_ota_handle_t;
|
||||
|
||||
/**
|
||||
* @brief format input partition in flash to 0xFF as input image size,
|
||||
* if unkown image size ,pass 0x0 or 0xFFFFFFFF, it will erase all the
|
||||
* partition ,Otherwise, erase the required range
|
||||
*
|
||||
* @param partition Pointer to partition structure which need to be updated
|
||||
* Must be non-NULL.
|
||||
* @param image_size size of image need to be updated
|
||||
* @param out_handle handle which should be used for esp_ota_write or esp_ota_end call
|
||||
|
||||
* @return:
|
||||
* - ESP_OK: if format ota image OK
|
||||
* - ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
|
||||
*/
|
||||
esp_err_t esp_ota_begin(const esp_partition_t* partition, size_t image_size, esp_ota_handle_t* out_handle);
|
||||
|
||||
/**
|
||||
* @brief Write data to input input partition
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin
|
||||
* @param data Pointer to data write to flash
|
||||
* @param size data size of recieved data
|
||||
*
|
||||
* @return:
|
||||
* - ESP_OK: if write flash data OK
|
||||
* - ESP_ERR_OTA_PARTITION_CONFLICT: operate current running bin
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
|
||||
*/
|
||||
esp_err_t esp_ota_write(esp_ota_handle_t handle, const void* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Finish the update and validate written data
|
||||
*
|
||||
* @param handle Handle obtained from esp_ota_begin
|
||||
*
|
||||
* @return:
|
||||
* - ESP_OK: if validate ota image pass
|
||||
* - ESP_ERR_OTA_VALIDATE_FAILED: validate the ota image is invalid
|
||||
*/
|
||||
esp_err_t esp_ota_end(esp_ota_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Set next boot partition, call system_restart() will switch to run it
|
||||
*
|
||||
* @note if you want switch to run a bin file
|
||||
* has never been checked before,please validate it's signature firstly
|
||||
*
|
||||
* @param partition Pointer to partition structure which need to boot
|
||||
*
|
||||
* @return:
|
||||
* - ESP_OK: if set next boot partition OK
|
||||
* - ESP_ERR_OTA_SELECT_INFO_INVALID: ota bin select info invalid
|
||||
*/
|
||||
esp_err_t esp_ota_set_boot_partition(const esp_partition_t* partition);
|
||||
|
||||
/**
|
||||
* @brief Get partition info of current running image
|
||||
*
|
||||
* @return pointer to esp_partition_t structure, or NULL if no partition is found or
|
||||
* operate flash failed,This pointer is valid for the lifetime of the application.
|
||||
*/
|
||||
const esp_partition_t* esp_ota_get_boot_partition(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* OTA_OPS_H */
|
|
@ -272,27 +272,31 @@ void bootloader_main()
|
|||
bootloader_munmap(ota_select_map);
|
||||
|
||||
if(sa.ota_seq == 0xFFFFFFFF && sb.ota_seq == 0xFFFFFFFF) {
|
||||
// init status flash
|
||||
load_part_pos = bs.ota[0];
|
||||
sa.ota_seq = 0x01;
|
||||
sa.crc = ota_select_crc(&sa);
|
||||
sb.ota_seq = 0x00;
|
||||
sb.crc = ota_select_crc(&sb);
|
||||
// init status flash
|
||||
if (bs.factory.offset != 0) { // if have factory bin,boot factory bin
|
||||
load_part_pos = bs.factory;
|
||||
} else {
|
||||
load_part_pos = bs.ota[0];
|
||||
sa.ota_seq = 0x01;
|
||||
sa.crc = ota_select_crc(&sa);
|
||||
sb.ota_seq = 0x00;
|
||||
sb.crc = ota_select_crc(&sb);
|
||||
|
||||
Cache_Read_Disable(0);
|
||||
spiRet1 = SPIEraseSector(bs.ota_info.offset/0x1000);
|
||||
spiRet2 = SPIEraseSector(bs.ota_info.offset/0x1000+1);
|
||||
if (spiRet1 != SPI_FLASH_RESULT_OK || spiRet2 != SPI_FLASH_RESULT_OK ) {
|
||||
ESP_LOGE(TAG, SPI_ERROR_LOG);
|
||||
return;
|
||||
}
|
||||
spiRet1 = SPIWrite(bs.ota_info.offset,(uint32_t *)&sa,sizeof(esp_ota_select_entry_t));
|
||||
spiRet2 = SPIWrite(bs.ota_info.offset + 0x1000,(uint32_t *)&sb,sizeof(esp_ota_select_entry_t));
|
||||
if (spiRet1 != SPI_FLASH_RESULT_OK || spiRet2 != SPI_FLASH_RESULT_OK ) {
|
||||
ESP_LOGE(TAG, SPI_ERROR_LOG);
|
||||
return;
|
||||
}
|
||||
Cache_Read_Enable(0);
|
||||
Cache_Read_Disable(0);
|
||||
spiRet1 = SPIEraseSector(bs.ota_info.offset/0x1000);
|
||||
spiRet2 = SPIEraseSector(bs.ota_info.offset/0x1000+1);
|
||||
if (spiRet1 != SPI_FLASH_RESULT_OK || spiRet2 != SPI_FLASH_RESULT_OK ) {
|
||||
ESP_LOGE(TAG, SPI_ERROR_LOG);
|
||||
return;
|
||||
}
|
||||
spiRet1 = SPIWrite(bs.ota_info.offset,(uint32_t *)&sa,sizeof(esp_ota_select_entry_t));
|
||||
spiRet2 = SPIWrite(bs.ota_info.offset + 0x1000,(uint32_t *)&sb,sizeof(esp_ota_select_entry_t));
|
||||
if (spiRet1 != SPI_FLASH_RESULT_OK || spiRet2 != SPI_FLASH_RESULT_OK ) {
|
||||
ESP_LOGE(TAG, SPI_ERROR_LOG);
|
||||
return;
|
||||
}
|
||||
Cache_Read_Enable(0);
|
||||
}
|
||||
//TODO:write data in ota info
|
||||
} else {
|
||||
if(ota_select_valid(&sa) && ota_select_valid(&sb)) {
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
typedef SHA_CTX sha_context;
|
||||
#else
|
||||
#include "hwcrypto/sha.h"
|
||||
typedef esp_sha_context sha_context;
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
|
@ -42,7 +41,9 @@ extern const uint8_t signature_verification_key_end[] asm("_binary_signature_ver
|
|||
|
||||
esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
||||
{
|
||||
sha_context sha;
|
||||
#ifdef BOOTLOADER_BUILD
|
||||
SHA_CTX sha;
|
||||
#endif
|
||||
uint8_t digest[32];
|
||||
ptrdiff_t keylen;
|
||||
const uint8_t *data;
|
||||
|
@ -83,12 +84,8 @@ esp_err_t esp_secure_boot_verify_signature(uint32_t src_addr, uint32_t length)
|
|||
ets_sha_finish(&sha, SHA2_256, digest);
|
||||
ets_sha_disable();
|
||||
#else
|
||||
/* Use thread-safe esp-idf SHA layer */
|
||||
esp_sha256_init(&sha);
|
||||
esp_sha256_start(&sha, false);
|
||||
esp_sha256_update(&sha, data, length);
|
||||
esp_sha256_finish(&sha, digest);
|
||||
esp_sha256_free(&sha);
|
||||
/* Use thread-safe esp-idf SHA function */
|
||||
esp_sha(SHA2_256, data, length, digest);
|
||||
#endif
|
||||
|
||||
keylen = signature_verification_key_end - signature_verification_key_start;
|
||||
|
|
|
@ -8,22 +8,9 @@ config BT_ENABLED
|
|||
help
|
||||
This compiles in the low-level BT stack.
|
||||
|
||||
menu "BT UTILITY OPTION"
|
||||
visible if BT_ENABLED
|
||||
|
||||
config BT_USE_ETS_PRINT
|
||||
bool "BT use print which has lock"
|
||||
default y
|
||||
depends on BT_ENABLED
|
||||
help
|
||||
This select use print or ets_print
|
||||
|
||||
endmenu #menu
|
||||
|
||||
config BTC_TASK_STACK_SIZE
|
||||
int "BT event (callback to application) task stack size"
|
||||
default 2048
|
||||
depends on BT_ENABLED
|
||||
help
|
||||
This select btc task stack size
|
||||
|
||||
|
|
|
@ -1,106 +0,0 @@
|
|||
// Copyright 2015-2016 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 <stdlib.h> // standard library
|
||||
#include <string.h>
|
||||
|
||||
#include "esp_sec_api.h"
|
||||
|
||||
|
||||
extern void srand (unsigned int seed);
|
||||
extern int random (void);
|
||||
|
||||
/// Application Security Environment Structure
|
||||
tAPP_SEC_ENV app_sec_env;
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_gen_tk
|
||||
**
|
||||
** Description This function is called to generate the ble tk
|
||||
**
|
||||
** Returns the generate tk value
|
||||
**
|
||||
*******************************************************************************/
|
||||
UINT32 app_ble_sec_gen_tk(void)
|
||||
{
|
||||
// Generate a PIN Code (Between 100000 and 999999)
|
||||
return (100000 + (random() % 900000));
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_gen_ltk
|
||||
**
|
||||
** Description This function is called to generate the ble ltk
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_sec_gen_ltk(UINT8 key_size)
|
||||
{
|
||||
// Counter
|
||||
UINT8 i;
|
||||
app_sec_env.key_size = key_size;
|
||||
|
||||
// Randomly generate the LTK and the Random Number
|
||||
for (i = 0; i < RAND_NB_LEN; i++) {
|
||||
app_sec_env.rand_nb.nb[i] = random() % 256;
|
||||
}
|
||||
|
||||
// Randomly generate the end of the LTK
|
||||
for (i = 0; i < SEC_KEY_LEN; i++) {
|
||||
app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random() % 256);
|
||||
}
|
||||
|
||||
// Randomly generate the EDIV
|
||||
app_sec_env.ediv = random() % 65536;
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_sec_init
|
||||
**
|
||||
** Description This function is init the security env and function
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_sec_init()
|
||||
{
|
||||
// Reset Security Environment
|
||||
memset(&app_sec_env, 0, sizeof(app_sec_env));
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function app_ble_security_start
|
||||
**
|
||||
** Description This function is called by the slave when the seurity start
|
||||
**
|
||||
** Returns NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
void app_ble_security_start(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable)
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_gap_set_device_name(char *name)
|
||||
esp_err_t esp_ble_gap_set_device_name(const char *name)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gap_args_t arg;
|
||||
|
@ -189,21 +189,7 @@ esp_err_t esp_ble_gap_set_device_name(char *name)
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gap_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function esp_ble_resolve_adv_data
|
||||
**
|
||||
** Description This function is called to get ADV data for a specific type.
|
||||
**
|
||||
** Parameters p_adv - pointer of ADV data
|
||||
** type - finding ADV data type
|
||||
** p_length - return the length of ADV data not including type
|
||||
**
|
||||
** Returns pointer of ADV data
|
||||
**
|
||||
*******************************************************************************/
|
||||
uint8_t *esp_ble_resolve_adv_data( uint8_t *p_adv, uint8_t type, uint8_t *p_length)
|
||||
uint8_t *esp_ble_resolve_adv_data( uint8_t *adv_data, uint8_t type, uint8_t *length)
|
||||
{
|
||||
if (((type < ESP_BLE_AD_TYPE_FLAG) || (type > ESP_BLE_AD_TYPE_128SERVICE_DATA)) &&
|
||||
(type != ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE)) {
|
||||
|
@ -211,11 +197,11 @@ uint8_t *esp_ble_resolve_adv_data( uint8_t *p_adv, uint8_t type, uint8_t *p_leng
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (p_adv == NULL) {
|
||||
if (adv_data == NULL) {
|
||||
LOG_ERROR("Invalid p_eir data.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (BTM_CheckAdvData( p_adv, type, p_length));
|
||||
return (BTM_CheckAdvData( adv_data, type, length));
|
||||
}
|
||||
|
||||
|
|
|
@ -18,18 +18,6 @@
|
|||
#include "btc_manage.h"
|
||||
#include "btc_gattc.h"
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register_callback
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] callback - pointer to the application callback function.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
|
||||
{
|
||||
if (callback == NULL) {
|
||||
|
@ -40,23 +28,16 @@ esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback)
|
|||
return ESP_OK;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register
|
||||
**
|
||||
** @brief This function is called to register application
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] app_id : Application Identitfy (UUID), for different application
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gattc_args_t arg;
|
||||
|
||||
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
|
||||
if (app_id > ESP_APP_ID_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_GATTC;
|
||||
msg.act = BTC_GATTC_ACT_APP_REGISTER;
|
||||
|
@ -65,18 +46,6 @@ esp_err_t esp_ble_gattc_app_register(uint16_t app_id)
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_unregister
|
||||
**
|
||||
** @brief This function is called to unregister an application
|
||||
** from GATTC module.
|
||||
**
|
||||
** @param[in] client_if - client interface identifier.
|
||||
**
|
||||
** @return None
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -90,20 +59,6 @@ esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if)
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_conn
|
||||
**
|
||||
** @brief Open a direct connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] gatt_if: application identity.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -119,17 +74,6 @@ esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bo
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_close
|
||||
**
|
||||
** @brief Close a connection to a GATT server.
|
||||
**
|
||||
** @param[in] conn_id: connectino ID to be closed.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_close (uint16_t conn_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -143,20 +87,6 @@ esp_err_t esp_ble_gattc_close (uint16_t conn_id)
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_config_mtu
|
||||
**
|
||||
** @brief Configure the MTU size in the GATT channel. This can be done
|
||||
** only once per connection.
|
||||
**
|
||||
** @param[in] conn_id: connection ID.
|
||||
** mtu: desired MTU size to use.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -175,22 +105,6 @@ esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu)
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_search_service
|
||||
**
|
||||
** @brief This function is called to request a GATT service discovery
|
||||
** on a GATT server. This function report service search result
|
||||
** by a callback event, and followed by a service search complete
|
||||
** event.
|
||||
**
|
||||
** @param[in] conn_id: connection ID.
|
||||
** @param[in] filter_uuid: a UUID of the service application is interested in.
|
||||
** If Null, discover for all services.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -210,24 +124,6 @@ esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_u
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_characteristic
|
||||
**
|
||||
** @brief This function is called to find the first characteristic of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
**
|
||||
** @param[in] srvc_id: serivce ID
|
||||
**
|
||||
** @param[in] start_char_id: the start characteristic ID
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *start_char_id)
|
||||
|
@ -251,23 +147,6 @@ esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_descriptor
|
||||
**
|
||||
** @brief This function is called to find the descriptor of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
** @param[in] char_id: Characteristic ID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] start_descr_id: the sctart descriptor id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
|
@ -295,23 +174,6 @@ esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_include_service
|
||||
**
|
||||
** @brief This function is called to find the first characteristic of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
** @param[in] start_incl_srvc_id: the start include service id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
|
||||
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_srvc_id_t *start_incl_srvc_id)
|
||||
|
@ -336,21 +198,6 @@ esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char
|
||||
**
|
||||
** @brief This function is called to read a service's characteristics of
|
||||
** the given characteritisc ID.UTH_REQ_NO_SCATTERNET
|
||||
**
|
||||
** @param[in] conn_id - connectino ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteritic ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id, esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
|
@ -368,20 +215,6 @@ esp_err_t esp_ble_gattc_read_char (uint16_t conn_id, esp_gatt_srvc_id_t *srvc_id
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char_descr
|
||||
**
|
||||
** @brief This function is called to read a characteristics descriptor.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] descr_id - characteritic descriptor ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
|
@ -403,26 +236,12 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char
|
||||
**
|
||||
** @brief This function is called to write characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID to write.
|
||||
** @param[in] value_len: length of the value to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -436,33 +255,19 @@ esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
|||
memcpy(&arg.write_char.char_id, char_id, sizeof(esp_gatt_id_t));
|
||||
arg.write_char.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
|
||||
arg.write_char.value = value;
|
||||
arg.write_char.write_type = write_type;
|
||||
arg.write_char.auth_req = auth_req;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char_descr
|
||||
**
|
||||
** @brief This function is called to write characteristic descriptor value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID.
|
||||
** @param[in] descr_id - characteristic descriptor ID to write.
|
||||
** @param[in] value_len: length of the value to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -477,26 +282,12 @@ esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
|||
memcpy(&arg.write_descr.descr_id, descr_id, sizeof(esp_gatt_id_t));
|
||||
arg.write_descr.value_len = value_len > ESP_GATT_MAX_ATTR_LEN ? ESP_GATT_MAX_ATTR_LEN : value_len;
|
||||
arg.write_descr.value = value;
|
||||
arg.write_descr.write_type = write_type;
|
||||
arg.write_descr.auth_req = auth_req;
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_prepare_write
|
||||
**
|
||||
** @brief This function is called to prepare write a characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] char_id - GATT characteritic ID of the service.
|
||||
** @param[in] offset - offset of the write value.
|
||||
** @param[in] value_len: length of the value to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
|
@ -523,20 +314,6 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), btc_gattc_arg_deep_copy) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_execu_write
|
||||
**
|
||||
** @brief This function is called to execute write a prepare write sequence.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] is_execute - execute or cancel.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
|
@ -551,22 +328,6 @@ esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute)
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_register_for_notify
|
||||
**
|
||||
** @brief This function is called to register for notification of a service.
|
||||
**
|
||||
** @param[in] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if registration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
|
@ -586,22 +347,6 @@ esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
|||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_gattc_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_unregister_ntf
|
||||
**
|
||||
** @brief This function is called to de-register for notification of a service.
|
||||
**
|
||||
** @param[in] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if deregistration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
|
|
|
@ -30,7 +30,8 @@ esp_err_t esp_ble_gatts_app_register(uint16_t app_id)
|
|||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
|
||||
if (app_id < APP_ID_MIN || app_id > APP_ID_MAX) {
|
||||
//if (app_id < ESP_APP_ID_MIN || app_id > ESP_APP_ID_MAX) {
|
||||
if (app_id > ESP_APP_ID_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
@ -73,7 +74,7 @@ esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
|||
}
|
||||
|
||||
|
||||
esp_err_t esp_ble_gatts_add_include_service(uint16_t service_handle, uint16_t included_service_handle)
|
||||
esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t included_service_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_gatts_args_t arg;
|
||||
|
|
|
@ -1,125 +0,0 @@
|
|||
// Copyright 2015-2016 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 "esp_sdp_api.h"
|
||||
|
||||
|
||||
esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpEnable((tBTA_SDP_DM_CBACK *)cback);
|
||||
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t *uuid)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpSearch(bd_addr, (tSDP_UUID *)uuid);
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_sdp_create_record_by_user(void *user_data)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpCreateRecordByUser(user_data);
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
esp_err_t esp_bt_sdp_remove_record_by_user(void *user_data)
|
||||
{
|
||||
tBTA_SDP_STATUS status = BTA_SdpRemoveRecordByUser(user_data);
|
||||
return (status == BTA_SDP_SUCCESS) ? ESP_OK : ESP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************************/
|
||||
/**********************************************************************************************/
|
||||
/* API into SDP for local service database updates */
|
||||
/* these APIs are indended to be called in callback function in the context of stack task,
|
||||
* to handle BT_SDP_CREATE_RECORD_USER_EVT and BT_SDP_REMOVE_RECORD_USER_EVT
|
||||
*/
|
||||
uint32_t esp_bt_sdp_create_record(void)
|
||||
{
|
||||
return SDP_CreateRecord();
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_delete_record(uint32_t handle)
|
||||
{
|
||||
return SDP_DeleteRecord(handle);
|
||||
}
|
||||
|
||||
int32_t esp_bt_sdp_read_record(uint32_t handle, uint8_t *data, int32_t *data_len)
|
||||
{
|
||||
return SDP_ReadRecord(handle, data, data_len);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_attribute (uint32_t handle, uint16_t attr_id,
|
||||
uint8_t attr_type, uint32_t attr_len,
|
||||
uint8_t *p_val)
|
||||
{
|
||||
return SDP_AddAttribute(handle, attr_id, attr_type, attr_len, p_val);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_elem, uint8_t type[],
|
||||
uint8_t len[], uint8_t *p_val[])
|
||||
{
|
||||
return SDP_AddSequence(handle, attr_id, num_elem, type, len, p_val);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_uuid_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_uuids, uint16_t *p_uuids)
|
||||
{
|
||||
return SDP_AddUuidSequence(handle, attr_id, num_uuids, p_uuids);
|
||||
}
|
||||
|
||||
|
||||
bool esp_bt_sdp_add_protocol_list (uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_elem_t *p_elem_list)
|
||||
{
|
||||
return SDP_AddProtocolList(handle, num_elem, (tSDP_PROTOCOL_ELEM *)p_elem_list);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_addition_protocol_lists(uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_list_elem_t *p_proto_list)
|
||||
{
|
||||
return SDP_AddAdditionProtoLists(handle, num_elem, (tSDP_PROTO_LIST_ELEM *)p_proto_list);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_profile_dscp_list (uint32_t handle,
|
||||
uint16_t profile_uuid,
|
||||
uint16_t version)
|
||||
{
|
||||
return SDP_AddProfileDescriptorList(handle, profile_uuid, version);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_lang_base_attr_id_list(uint32_t handle,
|
||||
uint16_t lang, uint16_t char_enc,
|
||||
uint16_t base_id)
|
||||
{
|
||||
return SDP_AddLanguageBaseAttrIDList(handle, lang, char_enc, base_id);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_add_service_class_id_list(uint32_t handle,
|
||||
uint16_t num_services,
|
||||
uint16_t *p_service_uuids)
|
||||
{
|
||||
return SDP_AddServiceClassIdList(handle, num_services, p_service_uuids);
|
||||
}
|
||||
|
||||
bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id)
|
||||
{
|
||||
return SDP_DeleteAttribute(handle, attr_id);
|
||||
}
|
||||
|
||||
/**********************************************************************************************/
|
||||
/**********************************************************************************************/
|
|
@ -21,89 +21,95 @@
|
|||
#include "bta_gatt_api.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#define ESP_BLUFI_RECV_DATA_LEN_MAX 128
|
||||
#define ESP_BLUFI_RECV_DATA_LEN_MAX (64+1)
|
||||
|
||||
#define ESP_BLUFI_EVENT_INIT_FINISH 0
|
||||
#define ESP_BLUFI_EVENT_DEINIT_FINISH 1
|
||||
#define ESP_BLUFI_EVENT_RECV_DATA 2
|
||||
|
||||
/// BLUFI config status
|
||||
typedef enum {
|
||||
ESP_BLUFI_CONFIG_OK = 0,
|
||||
ESP_BLUFI_CONFIG_FAILED,
|
||||
} esp_blufi_config_state_t;
|
||||
|
||||
/// BLUFI init status
|
||||
typedef enum {
|
||||
ESP_BLUFI_INIT_OK = 0,
|
||||
ESP_BLUFI_INIT_FAILED = 0,
|
||||
} esp_blufi_init_state_t;
|
||||
|
||||
/// BLUFI deinit status
|
||||
typedef enum {
|
||||
ESP_BLUFI_DEINIT_OK = 0,
|
||||
ESP_BLUFI_DEINIT_FAILED = 0,
|
||||
} esp_blufi_deinit_state_t;
|
||||
|
||||
/**
|
||||
* @brief BLUFI callback parameters union
|
||||
*/
|
||||
typedef union {
|
||||
//ESP_BLUFI_EVENT_INIT_FINISH
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_INIT_FINISH
|
||||
*/
|
||||
struct blufi_init_finish_evt_param {
|
||||
esp_blufi_init_state_t state;
|
||||
} init_finish;
|
||||
//ESP_BLUFI_EVENT_DEINIT_FINISH
|
||||
esp_blufi_init_state_t state; /*!< Initial status */
|
||||
} init_finish; /*!< Blufi callback param of ESP_BLUFI_EVENT_INIT_FINISH */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_DEINIT_FINISH
|
||||
*/
|
||||
struct blufi_deinit_finish_evt_param {
|
||||
esp_blufi_deinit_state_t state;
|
||||
} deinit_finish;
|
||||
//ESP_BLUFI_EVENT_RECV_DATA
|
||||
esp_blufi_deinit_state_t state; /*!< De-initial status */
|
||||
} deinit_finish; /*!< Blufi callback param of ESP_BLUFI_EVENT_DEINIT_FINISH */
|
||||
|
||||
/**
|
||||
* @brief ESP_BLUFI_EVENT_RECV_DATA
|
||||
*/
|
||||
struct blufi_recv_evt_param {
|
||||
uint8_t data[ESP_BLUFI_RECV_DATA_LEN_MAX];
|
||||
uint8_t data_len;
|
||||
} recv_data;
|
||||
uint8_t data[ESP_BLUFI_RECV_DATA_LEN_MAX]; /*!< Blufi receive data */
|
||||
uint8_t data_len; /*!< Blufi receive data length */
|
||||
} recv_data; /*!< Blufi callback param of ESP_BLUFI_EVENT_RECV_DATA */
|
||||
} esp_blufi_cb_param_t;
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_blufi_register_callback
|
||||
**
|
||||
** @brief This function is called to receive blufi callback event
|
||||
**
|
||||
** @param[in] callback: callback function
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to receive blufi callback event
|
||||
*
|
||||
* @param[in] callback: callback function
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_blufi_send_config_state
|
||||
**
|
||||
** @brief This function is called to send config state to phone
|
||||
**
|
||||
** @param[in] state: blufi config ok or not
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to send config state to phone
|
||||
*
|
||||
* @param[in] state: blufi config OK or not
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_send_config_state(esp_blufi_config_state_t state);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_blufi_profile_init
|
||||
**
|
||||
** @brief This function is called to init blufi_profile
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to initialize blufi_profile
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_profile_init(void);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_blufi_profile_deinit
|
||||
**
|
||||
** @brief This function is called to init blufi_profile
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
*
|
||||
* @brief This function is called to de-initialize blufi_profile
|
||||
*
|
||||
* @return ESP_OK - success, other - failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_blufi_profile_deinit(void);
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* Status Return Value */
|
||||
/// Status Return Value
|
||||
typedef enum {
|
||||
ESP_BT_STATUS_SUCCESS = 0, /* Successful operation. */
|
||||
ESP_BT_STATUS_FAILURE = 1, /* Generic failure. */
|
||||
|
@ -28,32 +28,40 @@ typedef enum {
|
|||
ESP_BT_STATUS_WRONG_MODE = 5,
|
||||
} esp_bt_status_t;
|
||||
|
||||
/// Default GATT interface id
|
||||
#define ESP_DEFAULT_GATT_IF 0xff
|
||||
|
||||
/// Default BLE connection param, if the value doesn't be overwritten
|
||||
#define ESP_BLE_CONN_PARAM_UNDEF 0xffff /* use this value when a specific value not to be overwritten */
|
||||
|
||||
/// Check the param is valid or not
|
||||
#define ESP_BLE_IS_VALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
|
||||
|
||||
/// UUID type
|
||||
typedef struct {
|
||||
#define ESP_UUID_LEN_16 2
|
||||
#define ESP_UUID_LEN_32 4
|
||||
#define ESP_UUID_LEN_128 16
|
||||
uint16_t len;
|
||||
uint16_t len; /*!< UUID length, 16bit, 32bit or 128bit */
|
||||
union {
|
||||
uint16_t uuid16;
|
||||
uint32_t uuid32;
|
||||
uint8_t uuid128[ESP_UUID_LEN_128];
|
||||
} uuid;
|
||||
} __attribute__((packed)) esp_bt_uuid_t; /* tBT_UUID in "bt_types.h" */
|
||||
} uuid; /*!< UUID */
|
||||
} __attribute__((packed)) esp_bt_uuid_t;
|
||||
|
||||
/// Bluetooth device type
|
||||
typedef enum {
|
||||
ESP_BT_DEVICE_TYPE_BREDR = 0x01,
|
||||
ESP_BT_DEVICE_TYPE_BLE = 0x02,
|
||||
ESP_BT_DEVICE_TYPE_DUMO = 0x03,
|
||||
} esp_bt_dev_type_t;
|
||||
|
||||
/// Bluetooth address length
|
||||
#define ESP_BD_ADDR_LEN 6
|
||||
typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN]; /* BD_ADDR in bt_types.h */
|
||||
|
||||
/// Bluetooth device address
|
||||
typedef uint8_t esp_bd_addr_t[ESP_BD_ADDR_LEN];
|
||||
|
||||
/// Own BD address source of the device
|
||||
typedef enum {
|
||||
|
@ -71,6 +79,7 @@ typedef enum {
|
|||
BD_ADDR_PROVIDED_RECON,
|
||||
} esp_bd_addr_type_t;
|
||||
|
||||
/// BLE device address type
|
||||
typedef enum {
|
||||
BLE_ADDR_TYPE_PUBLIC = 0x00,
|
||||
BLE_ADDR_TYPE_RANDOM = 0x01,
|
||||
|
@ -78,11 +87,16 @@ typedef enum {
|
|||
BLE_ADDR_TYPE_RPA_RANDOM = 0x03,
|
||||
} esp_ble_addr_type_t;
|
||||
|
||||
#define APP_ID_MIN 0x0000
|
||||
#define APP_ID_MAX 0x7fff
|
||||
/// Minimum of the application id
|
||||
#define ESP_APP_ID_MIN 0x0000
|
||||
/// Maximum of the application id
|
||||
#define ESP_APP_ID_MAX 0x7fff
|
||||
|
||||
/**
|
||||
* @brief Each profile callback function type
|
||||
* @param event : Event type
|
||||
* @param param : Point to callback parameter, currently is union type
|
||||
*/
|
||||
typedef void (* esp_profile_cb_t)(uint32_t event, void *param);
|
||||
|
||||
#define API_BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
|
||||
|
||||
#endif ///__ESP_BT_DEFS_H__
|
||||
|
|
|
@ -18,12 +18,40 @@
|
|||
#include "btc_main.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
/**
|
||||
* @brief Enable bluetooth, must after esp_init_bluetooth()
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Succeed
|
||||
* - Other : Failed
|
||||
*/
|
||||
esp_err_t esp_enable_bluetooth(void);
|
||||
|
||||
/**
|
||||
* @brief Disable bluetooth, must prior to esp_deinit_bluetooth()
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Succeed
|
||||
* - Other : Failed
|
||||
*/
|
||||
esp_err_t esp_disable_bluetooth(void);
|
||||
|
||||
/**
|
||||
* @brief Init and alloc the resource for bluetooth, must be prior to every bluetooth stuff
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Succeed
|
||||
* - Other : Failed
|
||||
*/
|
||||
esp_err_t esp_init_bluetooth(void);
|
||||
|
||||
/**
|
||||
* @brief Deinit and free the resource for bluetooth, must be after every bluetooth stuff
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : Succeed
|
||||
* - Other : Failed
|
||||
*/
|
||||
esp_err_t esp_deinit_bluetooth(void);
|
||||
|
||||
|
||||
|
|
|
@ -21,42 +21,45 @@
|
|||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
#define ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
|
||||
#define ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
|
||||
#define ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
|
||||
#define ESP_GAP_BLE_SCAN_RESULT_EVT 3
|
||||
/// GAP BLE callback event type
|
||||
typedef enum {
|
||||
ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT = 0, /*!< When advertising data set complete, the event comes */
|
||||
ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT , /*!< When scan response data set complete, the event comes */
|
||||
ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT, /*!< When scan parameters set complete, the event comes */
|
||||
ESP_GAP_BLE_SCAN_RESULT_EVT, /*!< When one scan result ready, the event comes each time */
|
||||
}esp_gap_ble_cb_event_t;
|
||||
|
||||
/// Advertising data maximum length
|
||||
#define ESP_BLE_ADV_DATA_LEN_MAX 31
|
||||
|
||||
/****************** define the adv type macro***************************************/
|
||||
#define ESP_BLE_AD_TYPE_FLAG 0x01
|
||||
#define ESP_BLE_AD_TYPE_16SRV_PART 0x02
|
||||
#define ESP_BLE_AD_TYPE_16SRV_CMPL 0x03
|
||||
#define ESP_BLE_AD_TYPE_32SRV_PART 0x04
|
||||
#define ESP_BLE_AD_TYPE_32SRV_CMPL 0x05
|
||||
#define ESP_BLE_AD_TYPE_128SRV_PART 0x06
|
||||
#define ESP_BLE_AD_TYPE_128SRV_CMPL 0x07
|
||||
#define ESP_BLE_AD_TYPE_NAME_SHORT 0x08
|
||||
#define ESP_BLE_AD_TYPE_NAME_CMPL 0x09
|
||||
#define ESP_BLE_AD_TYPE_TX_PWR 0x0A
|
||||
#define ESP_BLE_AD_TYPE_DEV_CLASS 0x0D
|
||||
#define ESP_BLE_AD_TYPE_SM_TK 0x10
|
||||
#define ESP_BLE_AD_TYPE_SM_OOB_FLAG 0x11
|
||||
#define ESP_BLE_AD_TYPE_INT_RANGE 0x12
|
||||
#define ESP_BLE_AD_TYPE_SOL_SRV_UUID 0x14
|
||||
#define ESP_BLE_AD_TYPE_128SOL_SRV_UUID 0x15
|
||||
#define ESP_BLE_AD_TYPE_SERVICE_DATA 0x16
|
||||
#define ESP_BLE_AD_TYPE_PUBLIC_TARGET 0x17
|
||||
#define ESP_BLE_AD_TYPE_RANDOM_TARGET 0x18
|
||||
#define ESP_BLE_AD_TYPE_APPEARANCE 0x19
|
||||
#define ESP_BLE_AD_TYPE_ADV_INT 0x1A
|
||||
#define ESP_BLE_AD_TYPE_32SOL_SRV_UUID 0x1B
|
||||
#define ESP_BLE_AD_TYPE_32SERVICE_DATA 0x1C
|
||||
#define ESP_BLE_AD_TYPE_128SERVICE_DATA 0x1D
|
||||
#define ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE 0xFF
|
||||
|
||||
|
||||
typedef uint32_t esp_gap_ble_event_t;
|
||||
/// The type of advertising data(not adv_type)
|
||||
typedef enum {
|
||||
ESP_BLE_AD_TYPE_FLAG = 0x01,
|
||||
ESP_BLE_AD_TYPE_16SRV_PART = 0x02,
|
||||
ESP_BLE_AD_TYPE_16SRV_CMPL = 0x03,
|
||||
ESP_BLE_AD_TYPE_32SRV_PART = 0x04,
|
||||
ESP_BLE_AD_TYPE_32SRV_CMPL = 0x05,
|
||||
ESP_BLE_AD_TYPE_128SRV_PART = 0x06,
|
||||
ESP_BLE_AD_TYPE_128SRV_CMPL = 0x07,
|
||||
ESP_BLE_AD_TYPE_NAME_SHORT = 0x08,
|
||||
ESP_BLE_AD_TYPE_NAME_CMPL = 0x09,
|
||||
ESP_BLE_AD_TYPE_TX_PWR = 0x0A,
|
||||
ESP_BLE_AD_TYPE_DEV_CLASS = 0x0D,
|
||||
ESP_BLE_AD_TYPE_SM_TK = 0x10,
|
||||
ESP_BLE_AD_TYPE_SM_OOB_FLAG = 0x11,
|
||||
ESP_BLE_AD_TYPE_INT_RANGE = 0x12,
|
||||
ESP_BLE_AD_TYPE_SOL_SRV_UUID = 0x14,
|
||||
ESP_BLE_AD_TYPE_128SOL_SRV_UUID = 0x15,
|
||||
ESP_BLE_AD_TYPE_SERVICE_DATA = 0x16,
|
||||
ESP_BLE_AD_TYPE_PUBLIC_TARGET = 0x17,
|
||||
ESP_BLE_AD_TYPE_RANDOM_TARGET = 0x18,
|
||||
ESP_BLE_AD_TYPE_APPEARANCE = 0x19,
|
||||
ESP_BLE_AD_TYPE_ADV_INT = 0x1A,
|
||||
ESP_BLE_AD_TYPE_32SOL_SRV_UUID = 0x1B,
|
||||
ESP_BLE_AD_TYPE_32SERVICE_DATA = 0x1C,
|
||||
ESP_BLE_AD_TYPE_128SERVICE_DATA = 0x1D,
|
||||
ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE = 0xFF,
|
||||
} esp_ble_adv_data_type;
|
||||
|
||||
/// Advertising mode
|
||||
typedef enum {
|
||||
|
@ -67,6 +70,7 @@ typedef enum {
|
|||
ADV_TYPE_DIRECT_IND_LOW = 0x04,
|
||||
} esp_ble_adv_type_t;
|
||||
|
||||
/// Advertising channel mask
|
||||
typedef enum {
|
||||
ADV_CHNL_37 = 0x01,
|
||||
ADV_CHNL_38 = 0x02,
|
||||
|
@ -86,32 +90,39 @@ typedef enum {
|
|||
///Enumeration end value for advertising filter policy value check
|
||||
} esp_ble_adv_filter_t;
|
||||
|
||||
|
||||
/// Advertising parameters
|
||||
typedef struct {
|
||||
uint16_t adv_int_min;
|
||||
uint16_t adv_int_max;
|
||||
esp_ble_adv_type_t adv_type;
|
||||
esp_ble_addr_type_t own_addr_type;
|
||||
esp_bd_addr_t peer_addr;
|
||||
esp_ble_addr_type_t peer_addr_type;
|
||||
esp_ble_adv_channel_t channel_map;
|
||||
esp_ble_adv_filter_t adv_filter_policy;
|
||||
uint16_t adv_int_min; /*!< Minimum advertising interval for
|
||||
undirected and low duty cycle directed advertising.
|
||||
Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
|
||||
Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec */
|
||||
uint16_t adv_int_max; /*!< Maximum advertising interval for
|
||||
undirected and low duty cycle directed advertising.
|
||||
Range: 0x0020 to 0x4000 Default: N = 0x0800 (1.28 second)
|
||||
Time = N * 0.625 msec Time Range: 20 ms to 10.24 sec Advertising max interval */
|
||||
esp_ble_adv_type_t adv_type; /*!< Advertising type */
|
||||
esp_ble_addr_type_t own_addr_type; /*!< Owner bluetooth device address type */
|
||||
esp_bd_addr_t peer_addr; /*!< Peer device bluetooth device address */
|
||||
esp_ble_addr_type_t peer_addr_type; /*!< Peer device bluetooth device address type */
|
||||
esp_ble_adv_channel_t channel_map; /*!< Advertising channel map */
|
||||
esp_ble_adv_filter_t adv_filter_policy; /*!< Advertising filter policy */
|
||||
} esp_ble_adv_params_t;
|
||||
|
||||
/// Advertising data content, according to "Supplement to the Bluetooth Core Specification"
|
||||
typedef struct {
|
||||
bool set_scan_rsp;
|
||||
bool include_name;
|
||||
bool include_txpower;
|
||||
int min_interval;
|
||||
int max_interval;
|
||||
int appearance;
|
||||
uint16_t manufacturer_len;
|
||||
uint8_t *p_manufacturer_data;
|
||||
uint16_t service_data_len;
|
||||
uint8_t *p_service_data;
|
||||
uint16_t service_uuid_len;
|
||||
uint8_t *p_service_uuid;
|
||||
uint8_t flag;
|
||||
bool set_scan_rsp; /*!< Set this advertising data as scan response or not*/
|
||||
bool include_name; /*!< Advertising data include device name or not */
|
||||
bool include_txpower; /*!< Advertising data include TX power */
|
||||
int min_interval; /*!< Advertising data show advertising min interval */
|
||||
int max_interval; /*!< Advertising data show advertising max interval */
|
||||
int appearance; /*!< External appearance of device */
|
||||
uint16_t manufacturer_len; /*!< Manufacturer data length */
|
||||
uint8_t *p_manufacturer_data; /*!< Manufacturer data point */
|
||||
uint16_t service_data_len; /*!< Service data length */
|
||||
uint8_t *p_service_data; /*!< Service data point */
|
||||
uint16_t service_uuid_len; /*!< Service uuid length */
|
||||
uint8_t *p_service_uuid; /*!< Service uuid array point */
|
||||
uint8_t flag; /*!< Advertising flag of discovery mode */
|
||||
} esp_ble_adv_data_t;
|
||||
|
||||
/// Own BD address source of the device
|
||||
|
@ -130,261 +141,284 @@ typedef enum {
|
|||
ESP_PROVIDED_RECON_ADDR,
|
||||
} esp_ble_own_addr_src_t;
|
||||
|
||||
|
||||
/// Ble scan type
|
||||
typedef enum {
|
||||
BLE_SCAN_TYPE_PASSIVE = 0x0,
|
||||
BLE_SCAN_TYPE_ACTIVE = 0x1,
|
||||
BLE_SCAN_TYPE_PASSIVE = 0x0, /*!< Passive scan */
|
||||
BLE_SCAN_TYPE_ACTIVE = 0x1, /*!< Active scan */
|
||||
} esp_ble_scan_type_t;
|
||||
|
||||
/// Ble scan filter type
|
||||
typedef enum {
|
||||
BLE_SCAN_FILTER_ALLOW_ALL = 0x0,
|
||||
BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x1,
|
||||
BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x2,
|
||||
BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR = 0x3,
|
||||
BLE_SCAN_FILTER_ALLOW_ALL = 0x0, /*!< Accept all :
|
||||
1. advertisement packets except directed advertising packets not addressed to this device (default). */
|
||||
BLE_SCAN_FILTER_ALLOW_ONLY_WLST = 0x1, /*!< Accept only :
|
||||
1. advertisement packets from devices where the advertiser’s address is in the White list.
|
||||
2. Directed advertising packets which are not addressed for this device shall be ignored. */
|
||||
BLE_SCAN_FILTER_ALLOW_UND_RPA_DIR = 0x2, /*!< Accept all :
|
||||
1. undirected advertisement packets, and
|
||||
2. directed advertising packets where the initiator address is a resolvable private address, and
|
||||
3. directed advertising packets addressed to this device. */
|
||||
BLE_SCAN_FILTER_ALLOW_WLIST_PRA_DIR = 0x3, /*!< Accept all :
|
||||
1. advertisement packets from devices where the advertiser’s address is in the White list, and
|
||||
2. directed advertising packets where the initiator address is a resolvable private address, and
|
||||
3. directed advertising packets addressed to this device.*/
|
||||
} esp_ble_scan_filter_t;
|
||||
|
||||
/// Ble scan parameters
|
||||
typedef struct {
|
||||
esp_ble_scan_type_t scan_type;
|
||||
esp_ble_addr_type_t own_addr_type;
|
||||
esp_ble_scan_filter_t scan_filter_policy;
|
||||
uint16_t scan_interval;
|
||||
uint16_t scan_window;
|
||||
esp_ble_scan_type_t scan_type; /*!< Scan type */
|
||||
esp_ble_addr_type_t own_addr_type; /*!< Owner address type */
|
||||
esp_ble_scan_filter_t scan_filter_policy; /*!< Scan filter policy */
|
||||
uint16_t scan_interval; /*!< Scan interval. This is defined as the time interval from
|
||||
when the Controller started its last LE scan until it begins the subsequent LE scan.
|
||||
Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
|
||||
Time = N * 0.625 msec
|
||||
Time Range: 2.5 msec to 10.24 seconds*/
|
||||
uint16_t scan_window; /*!< Scan window. The duration of the LE scan. LE_Scan_Window
|
||||
shall be less than or equal to LE_Scan_Interval
|
||||
Range: 0x0004 to 0x4000 Default: 0x0010 (10 ms)
|
||||
Time = N * 0.625 msec
|
||||
Time Range: 2.5 msec to 10240 msec */
|
||||
} esp_ble_scan_params_t;
|
||||
|
||||
/// Connection update parameters
|
||||
typedef struct {
|
||||
esp_bd_addr_t bda;
|
||||
uint16_t min_int;
|
||||
uint16_t max_int;
|
||||
uint16_t latency;
|
||||
uint16_t timeout;
|
||||
esp_bd_addr_t bda; /*!< Bluetooth device address */
|
||||
uint16_t min_int; /*!< Min connection interval */
|
||||
uint16_t max_int; /*!< Max connection interval */
|
||||
uint16_t latency; /*!< Slave latency for the connection in number of connection events. Range: 0x0000 to 0x01F3 */
|
||||
uint16_t timeout; /*!< Supervision timeout for the LE Link. Range: 0x000A to 0x0C80.
|
||||
Mandatory Range: 0x000A to 0x0C80 Time = N * 10 msec
|
||||
Time Range: 100 msec to 32 seconds */
|
||||
} esp_ble_conn_update_params_t;
|
||||
|
||||
typedef void (*esp_gap_ble_cb_t)(esp_gap_ble_event_t event, void *param);
|
||||
|
||||
/// Sub Event of ESP_GAP_BLE_SCAN_RESULT_EVT
|
||||
typedef enum {
|
||||
/* Search callback events */
|
||||
ESP_GAP_SEARCH_INQ_RES_EVT = 0, /* Inquiry result for a peer device. */
|
||||
ESP_GAP_SEARCH_INQ_CMPL_EVT = 1, /* Inquiry complete. */
|
||||
ESP_GAP_SEARCH_DISC_RES_EVT = 2, /* Discovery result for a peer device. */
|
||||
ESP_GAP_SEARCH_DISC_BLE_RES_EVT = 3, /* Discovery result for BLE GATT based servoce on a peer device. */
|
||||
ESP_GAP_SEARCH_DISC_CMPL_EVT = 4, /* Discovery complete. */
|
||||
ESP_GAP_SEARCH_DI_DISC_CMPL_EVT = 5, /* Discovery complete. */
|
||||
ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT = 6, /* Search cancelled */
|
||||
ESP_GAP_SEARCH_INQ_RES_EVT = 0, /*!< Inquiry result for a peer device. */
|
||||
ESP_GAP_SEARCH_INQ_CMPL_EVT = 1, /*!< Inquiry complete. */
|
||||
ESP_GAP_SEARCH_DISC_RES_EVT = 2, /*!< Discovery result for a peer device. */
|
||||
ESP_GAP_SEARCH_DISC_BLE_RES_EVT = 3, /*!< Discovery result for BLE GATT based service on a peer device. */
|
||||
ESP_GAP_SEARCH_DISC_CMPL_EVT = 4, /*!< Discovery complete. */
|
||||
ESP_GAP_SEARCH_DI_DISC_CMPL_EVT = 5, /*!< Discovery complete. */
|
||||
ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT = 6, /*!< Search cancelled */
|
||||
} esp_gap_search_evt_t;
|
||||
|
||||
/**
|
||||
* @brief Ble scan result event type, to indicate the
|
||||
* result is scan response or advertising data or other
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_BLE_EVT_CONN_ADV = 0x00, /*!< Connectable undirected advertising (ADV_IND) */
|
||||
ESP_BLE_EVT_CONN_DIR_ADV = 0x01, /*!< Connectable directed advertising (ADV_DIRECT_IND) */
|
||||
ESP_BLE_EVT_DISC_ADV = 0x02, /*!< Scannable undirected advertising (ADV_SCAN_IND) */
|
||||
ESP_BLE_EVT_NON_CONN_ADV = 0x03, /*!< Non connectable undirected advertising (ADV_NONCONN_IND) */
|
||||
ESP_BLE_EVT_SCAN_RSP = 0x04, /*!< Scan Response (SCAN_RSP) */
|
||||
} esp_ble_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Gap callback parameters union
|
||||
*/
|
||||
typedef union {
|
||||
//ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT 0
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
|
||||
*/
|
||||
struct ble_adv_data_cmpl_evt_param {
|
||||
esp_bt_status_t status;
|
||||
} adv_data_cmpl;
|
||||
//ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT 1
|
||||
esp_bt_status_t status; /*!< Indicate the set advertising data operation success status */
|
||||
} adv_data_cmpl; /*!< Event parameter of ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
|
||||
*/
|
||||
struct ble_scan_rsp_data_cmpl_evt_param {
|
||||
esp_bt_status_t status;
|
||||
} scan_rsp_data_cmpl;
|
||||
//ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT 2
|
||||
esp_bt_status_t status; /*!< Indicate the set scan response data operation success status */
|
||||
} scan_rsp_data_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT
|
||||
*/
|
||||
struct ble_scan_param_cmpl_evt_param {
|
||||
esp_bt_status_t status;
|
||||
} scan_param_cmpl;
|
||||
//ESP_GAP_BLE_SCAN_RESULT_EVT 3
|
||||
esp_bt_status_t status; /*!< Indicate the set scan param operation success status */
|
||||
} scan_param_cmpl; /*!< Event parameter of ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT */
|
||||
/**
|
||||
* @brief ESP_GAP_BLE_SCAN_RESULT_EVT
|
||||
*/
|
||||
struct ble_scan_result_evt_param {
|
||||
esp_gap_search_evt_t search_evt;
|
||||
esp_bd_addr_t bda;
|
||||
esp_bt_dev_type_t dev_type;
|
||||
esp_ble_addr_type_t ble_addr_type;
|
||||
int rssi;
|
||||
uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX]; /* received EIR */
|
||||
int flag;
|
||||
int num_resps;
|
||||
} scan_rst;
|
||||
esp_gap_search_evt_t search_evt; /*!< Search event type */
|
||||
esp_bd_addr_t bda; /*!< Bluetooth device address which has been searched */
|
||||
esp_bt_dev_type_t dev_type; /*!< Device type */
|
||||
esp_ble_addr_type_t ble_addr_type; /*!< Ble device address type */
|
||||
esp_ble_evt_type_t ble_evt_type; /*!< Ble scan result event type */
|
||||
int rssi; /*!< Searched device's RSSI */
|
||||
uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX]; /*!< Received EIR */
|
||||
int flag; /*!< Advertising data flag bit */
|
||||
int num_resps; /*!< Scan result number */
|
||||
} scan_rst; /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */
|
||||
} esp_ble_gap_cb_param_t;
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_register_callback
|
||||
**
|
||||
** @brief This function is called to occur gap event, such as scan result
|
||||
**
|
||||
** @param[in] callback: callback function
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function is called to occur gap event, such as scan result
|
||||
*
|
||||
* @param[in] callback: callback function
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_config_adv_data
|
||||
**
|
||||
** @brief This function is called to override the BTA default ADV parameters.
|
||||
**
|
||||
** @param[in] adv_data: Pointer to User defined ADV data structure. This
|
||||
** memory space can not be freed until p_adv_data_cback
|
||||
** is received.
|
||||
** @param[in|out] adv_data_cback: set adv data complete callback.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to override the BTA default ADV parameters.
|
||||
*
|
||||
* @param[in] adv_data: Pointer to User defined ADV data structure. This
|
||||
* memory space can not be freed until callback of config_adv_data
|
||||
* is received.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_config_adv_data (esp_ble_adv_data_t *adv_data);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_set_scan_params
|
||||
**
|
||||
** @brief This function is called to set scan parameters
|
||||
**
|
||||
** @param[in] esp_ble_scan_params: Pointer to User defined scan_params data structure. This
|
||||
** memory space can not be freed until scan_param_setup_cback
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to set scan parameters
|
||||
*
|
||||
* @param[in] scan_params: Pointer to User defined scan_params data structure. This
|
||||
* memory space can not be freed until callback of set_scan_params
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_set_scan_params(esp_ble_scan_params_t *scan_params);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_start_scanning
|
||||
**
|
||||
** @brief This procedure keep the device scanning the peer device whith advertising on the air
|
||||
**
|
||||
** @param[in] duration: Keeping the scaning time, the unit is second.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This procedure keep the device scanning the peer device which advertising on the air
|
||||
*
|
||||
* @param[in] duration: Keeping the scanning time, the unit is second.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_start_scanning(uint32_t duration);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_stop_scanning
|
||||
**
|
||||
** @brief This function call to stop the device scanning the peer device whith advertising on the air
|
||||
** @param void
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function call to stop the device scanning the peer device which advertising on the air
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_stop_scanning(void);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_start_advertising
|
||||
**
|
||||
** @brief This function is called to start advertising.
|
||||
**
|
||||
** @param[in] esp_ble_adv_params_all_t: ointer to User defined adv_params data structure.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to start advertising.
|
||||
*
|
||||
* @param[in] adv_params: pointer to User defined adv_params data structure.
|
||||
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_start_advertising (esp_ble_adv_params_t *adv_params);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_gap_ble_stop_advertising
|
||||
**
|
||||
** @brief This function is called to stop advertising.
|
||||
**
|
||||
** @param None
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to stop advertising.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_stop_advertising(void);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_update_conn_params
|
||||
**
|
||||
** @brief Update connection parameters, can only be used when connection is up.
|
||||
**
|
||||
** @param[in] param - connection update params
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Update connection parameters, can only be used when connection is up.
|
||||
*
|
||||
* @param[in] params - connection update parameters
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_update_conn_params(esp_ble_conn_update_params_t *params);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_set_pkt_data_len
|
||||
**
|
||||
** @brief This function is to set maximum LE data packet size
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is to set maximum LE data packet size
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_set_pkt_data_len(esp_bd_addr_t remote_device, uint16_t tx_data_length);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_set_rand_addr
|
||||
**
|
||||
** @brief This function set the random address for the appliction
|
||||
**
|
||||
** @param[in] rand_addr: the random address whith should be setting
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function set the random address for the application
|
||||
*
|
||||
* @param[in] rand_addr: the random address which should be setting
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_set_rand_addr(esp_bd_addr_t rand_addr);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_config_local_privacy
|
||||
**
|
||||
** @brief Enable/disable privacy on the local device
|
||||
**
|
||||
** @param[in] privacy_enable - enable/disabe privacy on remote device.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Enable/disable privacy on the local device
|
||||
*
|
||||
* @param[in] privacy_enable - enable/disable privacy on remote device.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_config_local_privacy (bool privacy_enable);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gap_set_device_name
|
||||
**
|
||||
** @brief Set device name to the local device
|
||||
**
|
||||
** @param[in] name - device name.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gap_set_device_name(char *name);
|
||||
/**
|
||||
* @brief Set device name to the local device
|
||||
*
|
||||
* @param[in] name - device name.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gap_set_device_name(const char *name);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_resolve_adv_data
|
||||
**
|
||||
** @brief This function is called to get ADV data for a specific type.
|
||||
**
|
||||
** @param[in] p_adv - pointer of ADV data whitch to be resolved
|
||||
** @param[in] type - finding ADV data type
|
||||
** @param[out] p_length - return the length of ADV data not including type
|
||||
**
|
||||
** @return pointer of ADV data
|
||||
**
|
||||
*******************************************************************************/
|
||||
uint8_t *esp_ble_resolve_adv_data( uint8_t *p_adv, uint8_t type, uint8_t *p_length );
|
||||
/**
|
||||
* @brief This function is called to get ADV data for a specific type.
|
||||
*
|
||||
* @param[in] adv_data - pointer of ADV data which to be resolved
|
||||
* @param[in] type - finding ADV data type
|
||||
* @param[out] length - return the length of ADV data not including type
|
||||
*
|
||||
* @return pointer of ADV data
|
||||
*
|
||||
*/
|
||||
uint8_t *esp_ble_resolve_adv_data(uint8_t *adv_data, uint8_t type, uint8_t *length);
|
||||
|
||||
#endif /* __ESP_GAP_BLE_API_H__ */
|
||||
|
|
|
@ -17,11 +17,15 @@
|
|||
|
||||
#include "esp_bt_defs.h"
|
||||
|
||||
/* attribute request data from the client */
|
||||
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
|
||||
#define ESP_GATT_PREP_WRITE_EXEC 0x01
|
||||
/// Attribute write data type from the client
|
||||
typedef enum {
|
||||
ESP_GATT_PREP_WRITE_CANCEL = 0x00, /*!< Prepare write cancel */
|
||||
ESP_GATT_PREP_WRITE_EXEC = 0x01, /*!< Prepare write execute */
|
||||
} esp_gatt_prep_write_type;
|
||||
|
||||
/* Success code and error codes */
|
||||
/**
|
||||
* @brief GATT success code and error codes
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_OK = 0x0,
|
||||
ESP_GATT_INVALID_HANDLE = 0x01, /* 0x0001 */
|
||||
|
@ -69,28 +73,41 @@ typedef enum {
|
|||
ESP_GATT_OUT_OF_RANGE = 0xff, /* 0xFFAttribute value out of range */
|
||||
} esp_gatt_status_t;
|
||||
|
||||
/**
|
||||
* @brief Gatt Connection reason enum
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_CONN_UNKNOWN = 0,
|
||||
ESP_GATT_CONN_L2C_FAILURE = 1, /* general L2cap failure */
|
||||
ESP_GATT_CONN_TIMEOUT = 0x08, /* 0x08 connection timeout */
|
||||
ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /* 0x13 connection terminate by peer user */
|
||||
ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /* 0x16 connectionterminated by local host */
|
||||
ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /* 0x03E connection fail to establish */
|
||||
// ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /* 0x22 connection fail for LMP response tout */
|
||||
ESP_GATT_CONN_CONN_CANCEL = 0x0100, /* 0x0100 L2CAP connection cancelled */
|
||||
ESP_GATT_CONN_NONE = 0x0101 /* 0x0101 no connection to cancel */
|
||||
} esp_gatt_reason_t;
|
||||
ESP_GATT_CONN_UNKNOWN = 0, /*!< Gatt connection unknown */
|
||||
ESP_GATT_CONN_L2C_FAILURE = 1, /*!< General L2cap failure */
|
||||
ESP_GATT_CONN_TIMEOUT = 0x08, /*!< Connection timeout */
|
||||
ESP_GATT_CONN_TERMINATE_PEER_USER = 0x13, /*!< Connection terminate by peer user */
|
||||
ESP_GATT_CONN_TERMINATE_LOCAL_HOST = 0x16, /*!< Connectionterminated by local host */
|
||||
ESP_GATT_CONN_FAIL_ESTABLISH = 0x3e, /*!< Connection fail to establish */
|
||||
ESP_GATT_CONN_LMP_TIMEOUT = 0x22, /*!< Connection fail for LMP response tout */
|
||||
ESP_GATT_CONN_CONN_CANCEL = 0x0100, /*!< L2CAP connection cancelled */
|
||||
ESP_GATT_CONN_NONE = 0x0101 /*!< No connection to cancel */
|
||||
} esp_gatt_conn_reason_t;
|
||||
|
||||
/**
|
||||
* @brief Gatt id, include uuid and instance id
|
||||
*/
|
||||
typedef struct {
|
||||
esp_bt_uuid_t uuid;
|
||||
uint8_t inst_id;
|
||||
esp_bt_uuid_t uuid; /*!< UUID */
|
||||
uint8_t inst_id; /*!< Instance id */
|
||||
} __attribute__((packed)) esp_gatt_id_t;
|
||||
|
||||
/**
|
||||
* @brief Gatt service id, include id
|
||||
* (uuid and instance id) and primary flag
|
||||
*/
|
||||
typedef struct {
|
||||
esp_gatt_id_t id;
|
||||
bool is_primary;
|
||||
esp_gatt_id_t id; /*!< Gatt id, include uuid and instance */
|
||||
bool is_primary; /*!< This service is primary or not */
|
||||
} __attribute__((packed)) esp_gatt_srvc_id_t;
|
||||
|
||||
/**
|
||||
* @brief Gatt authentication request type
|
||||
*/
|
||||
typedef enum {
|
||||
AUTH_REQ_NO_SCATTERNET, /* Device doesn't support scatternet, it might
|
||||
support "role switch during connection" for
|
||||
|
@ -103,8 +120,9 @@ typedef enum {
|
|||
and slave roles */
|
||||
} esp_gatt_auth_req_t;
|
||||
|
||||
/* Attribute permissions
|
||||
*/
|
||||
/**
|
||||
* @brief Attribute permissions
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_PERM_READ = (1 << 0), /* bit 0 - 0x0001 */
|
||||
ESP_GATT_PERM_READ_ENCRYPTED = (1 << 1), /* bit 1 - 0x0002 */
|
||||
|
@ -128,22 +146,32 @@ typedef enum {
|
|||
ESP_GATT_CHAR_PROP_BIT_EXT_PROP = (1 << 7), /* 0x80 */
|
||||
} esp_gatt_char_prop_t;
|
||||
|
||||
/// GATT maximum attribute length
|
||||
#define ESP_GATT_MAX_ATTR_LEN 600 //as same as GATT_MAX_ATTR_LEN
|
||||
|
||||
/// Gatt attribute value
|
||||
typedef struct {
|
||||
uint8_t value[ESP_GATT_MAX_ATTR_LEN];
|
||||
uint16_t handle;
|
||||
uint16_t offset;
|
||||
uint16_t len;
|
||||
uint8_t auth_req;
|
||||
uint8_t value[ESP_GATT_MAX_ATTR_LEN]; /*!< Gatt attribute value */
|
||||
uint16_t handle; /*!< Gatt attribute handle */
|
||||
uint16_t offset; /*!< Gatt attribute value offset */
|
||||
uint16_t len; /*!< Gatt attribute value length */
|
||||
uint8_t auth_req; /*!< Gatt authentication request */
|
||||
} esp_gatt_value_t;
|
||||
|
||||
/** GATT remote read request response type */
|
||||
/// GATT remote read request response type
|
||||
typedef union {
|
||||
esp_gatt_value_t attr_value;
|
||||
uint16_t handle;
|
||||
esp_gatt_value_t attr_value; /*!< Gatt attribute structure */
|
||||
uint16_t handle; /*!< Gatt attribute handle */
|
||||
} esp_gatt_rsp_t;
|
||||
|
||||
typedef uint32_t esp_gatt_if_t;
|
||||
/**
|
||||
* @brief Gatt write type
|
||||
*/
|
||||
typedef enum {
|
||||
ESP_GATT_WRITE_TYPE_NO_RSP = 1, /*!< Gatt write attribute need no response */
|
||||
ESP_GATT_WRITE_TYPE_RSP, /*!< Gatt write attribute need remote response */
|
||||
} esp_gatt_write_type_t;
|
||||
|
||||
typedef uint32_t esp_gatt_if_t; /*!< Gatt interface type, different application on GATT client use different gatt_if */
|
||||
|
||||
#endif /* __ESP_GATT_DEFS_H__ */
|
||||
|
|
836
components/bt/bluedroid/api/include/esp_gattc_api.h
Normal file → Executable file
836
components/bt/bluedroid/api/include/esp_gattc_api.h
Normal file → Executable file
|
@ -20,402 +20,424 @@
|
|||
#include "esp_gatt_defs.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
/* Client callback function events */
|
||||
#define ESP_GATTC_REG_EVT 0 /* GATT client is registered. */
|
||||
#define ESP_GATTC_UNREG_EVT 1 /* GATT client unregistered event */
|
||||
#define ESP_GATTC_OPEN_EVT 2 /* GATTC open request status event */
|
||||
#define ESP_GATTC_READ_CHAR_EVT 3 /* GATT read characteristic event */
|
||||
#define ESP_GATTC_WRITE_CHAR_EVT 4 /* GATT write characteristic or char descriptor event */
|
||||
#define ESP_GATTC_CLOSE_EVT 5 /* GATTC close request status event */
|
||||
#define ESP_GATTC_SEARCH_CMPL_EVT 6 /* GATT discovery complete event */
|
||||
#define ESP_GATTC_SEARCH_RES_EVT 7 /* GATT discovery result event */
|
||||
#define ESP_GATTC_READ_DESCR_EVT 8 /* GATT read characterisitc descriptor event */
|
||||
#define ESP_GATTC_WRITE_DESCR_EVT 9 /* GATT write characteristic descriptor event */
|
||||
#define ESP_GATTC_NOTIFY_EVT 10 /* GATT attribute notification event */
|
||||
#define ESP_GATTC_PREP_WRITE_EVT 11 /* GATT prepare write event */
|
||||
#define ESP_GATTC_EXEC_EVT 12 /* execute write complete event */
|
||||
#define ESP_GATTC_ACL_EVT 13 /* ACL up event */
|
||||
#define ESP_GATTC_CANCEL_OPEN_EVT 14 /* cancel open event */
|
||||
#define ESP_GATTC_SRVC_CHG_EVT 15 /* service change event */
|
||||
#define ESP_GATTC_ENC_CMPL_CB_EVT 17 /* encryption complete callback event */
|
||||
#define ESP_GATTC_CFG_MTU_EVT 18 /* configure MTU complete event */
|
||||
#define ESP_GATTC_ADV_DATA_EVT 19 /* ADV data event */
|
||||
#define ESP_GATTC_MULT_ADV_ENB_EVT 20 /* Enable Multi ADV event */
|
||||
#define ESP_GATTC_MULT_ADV_UPD_EVT 21 /* Update parameter event */
|
||||
#define ESP_GATTC_MULT_ADV_DATA_EVT 22 /* Multi ADV data event */
|
||||
#define ESP_GATTC_MULT_ADV_DIS_EVT 23 /* Disable Multi ADV event */
|
||||
#define ESP_GATTC_CONGEST_EVT 24 /* Congestion event */
|
||||
#define ESP_GATTC_BTH_SCAN_ENB_EVT 25 /* Enable batch scan event */
|
||||
#define ESP_GATTC_BTH_SCAN_CFG_EVT 26 /* Config storage event */
|
||||
#define ESP_GATTC_BTH_SCAN_RD_EVT 27 /* Batch scan reports read event */
|
||||
#define ESP_GATTC_BTH_SCAN_THR_EVT 28 /* Batch scan threshold event */
|
||||
#define ESP_GATTC_BTH_SCAN_PARAM_EVT 29 /* Batch scan param event */
|
||||
#define ESP_GATTC_BTH_SCAN_DIS_EVT 30 /* Disable batch scan event */
|
||||
#define ESP_GATTC_SCAN_FLT_CFG_EVT 31 /* Scan filter config event */
|
||||
#define ESP_GATTC_SCAN_FLT_PARAM_EVT 32 /* Param filter event */
|
||||
#define ESP_GATTC_SCAN_FLT_STATUS_EVT 33 /* Filter status event */
|
||||
#define ESP_GATTC_ADV_VSC_EVT 34 /* ADV VSC event */
|
||||
|
||||
#define ESP_GATTC_GET_CHAR_EVT 35 /* get characteristic event */
|
||||
#define ESP_GATTC_GET_DESCR_EVT 36 /* get characteristic descriptor event */
|
||||
#define ESP_GATTC_GET_INCL_SRVC_EVT 37 /* get included service event */
|
||||
#define ESP_GATTC_REG_FOR_NOTIFY_EVT 38 /* register for notification event */
|
||||
#define ESP_GATTC_UNREG_FOR_NOTIFY_EVT 39 /* unregister for notification event */
|
||||
|
||||
/// GATT Client callback function events
|
||||
typedef enum {
|
||||
ESP_GATTC_REG_EVT = 0, /*!< When GATT client is registered, the event comes */
|
||||
ESP_GATTC_UNREG_EVT = 1, /*!< When GATT client is unregistered, the event comes */
|
||||
ESP_GATTC_OPEN_EVT = 2, /*!< When GATT connection is set up, the event comes */
|
||||
ESP_GATTC_READ_CHAR_EVT = 3, /*!< When GATT characteristic is read, the event comes */
|
||||
ESP_GATTC_WRITE_CHAR_EVT = 4, /*!< When GATT characteristic write operation completes, the event comes */
|
||||
ESP_GATTC_CLOSE_EVT = 5, /*!< When GATT connection is closed, the event comes */
|
||||
ESP_GATTC_SEARCH_CMPL_EVT = 6, /*!< When GATT service discovery is completed, the event comes */
|
||||
ESP_GATTC_SEARCH_RES_EVT = 7, /*!< When GATT service discovery result is got, the event comes */
|
||||
ESP_GATTC_READ_DESCR_EVT = 8, /*!< When GATT characteristic descriptor read completes, the event comes */
|
||||
ESP_GATTC_WRITE_DESCR_EVT = 9, /*!< When GATT characteristic descriptor write completes, the event comes */
|
||||
ESP_GATTC_NOTIFY_EVT = 10, /*!< When GATT notification or indication arrives, the event comes */
|
||||
ESP_GATTC_PREP_WRITE_EVT = 11, /*!< When GATT prepare-write operation completes, the event comes */
|
||||
ESP_GATTC_EXEC_EVT = 12, /*!< When write execution completes, the event comes */
|
||||
ESP_GATTC_ACL_EVT = 13, /*!< When ACL connection is up, the event comes */
|
||||
ESP_GATTC_CANCEL_OPEN_EVT = 14, /*!< When GATT client ongoing connection is cancelled, the event comes */
|
||||
ESP_GATTC_SRVC_CHG_EVT = 15, /*!< When "service changed" occurs, the event comes */
|
||||
ESP_GATTC_ENC_CMPL_CB_EVT = 17, /*!< When encryption procedure completes, the event comes */
|
||||
ESP_GATTC_CFG_MTU_EVT = 18, /*!< When configuration of MTU completes, the event comes */
|
||||
ESP_GATTC_ADV_DATA_EVT = 19, /*!< When advertising of data, the event comes */
|
||||
ESP_GATTC_MULT_ADV_ENB_EVT = 20, /*!< When multi-advertising is enabled, the event comes */
|
||||
ESP_GATTC_MULT_ADV_UPD_EVT = 21, /*!< When multi-advertising parameters are updated, the event comes */
|
||||
ESP_GATTC_MULT_ADV_DATA_EVT = 22, /*!< When multi-advertising data arrives, the event comes */
|
||||
ESP_GATTC_MULT_ADV_DIS_EVT = 23, /*!< When multi-advertising is disabled, the event comes */
|
||||
ESP_GATTC_CONGEST_EVT = 24, /*!< When GATT connection congestion comes, the event comes */
|
||||
ESP_GATTC_BTH_SCAN_ENB_EVT = 25, /*!< When batch scan is enabled, the event comes */
|
||||
ESP_GATTC_BTH_SCAN_CFG_EVT = 26, /*!< When batch scan storage is configured, the event comes */
|
||||
ESP_GATTC_BTH_SCAN_RD_EVT = 27, /*!< When Batch scan read event is reported, the event comes */
|
||||
ESP_GATTC_BTH_SCAN_THR_EVT = 28, /*!< When Batch scan threshold is set, the event comes */
|
||||
ESP_GATTC_BTH_SCAN_PARAM_EVT = 29, /*!< When Batch scan parameters are set, the event comes */
|
||||
ESP_GATTC_BTH_SCAN_DIS_EVT = 30, /*!< When Batch scan is disabled, the event comes */
|
||||
ESP_GATTC_SCAN_FLT_CFG_EVT = 31, /*!< When Scan filter configuration completes, the event comes */
|
||||
ESP_GATTC_SCAN_FLT_PARAM_EVT = 32, /*!< When Scan filter parameters are set, the event comes */
|
||||
ESP_GATTC_SCAN_FLT_STATUS_EVT = 33, /*!< When Scan filter status is reported, the event comes */
|
||||
ESP_GATTC_ADV_VSC_EVT = 34, /*!< When advertising vendor spec content event is reported, the event comes */
|
||||
ESP_GATTC_GET_CHAR_EVT = 35, /*!< When characteristic is got from GATT server, the event comes */
|
||||
ESP_GATTC_GET_DESCR_EVT = 36, /*!< When characteristic descriptor is got from GATT server, the event comes */
|
||||
ESP_GATTC_GET_INCL_SRVC_EVT = 37, /*!< When included service is got from GATT server, the event comes */
|
||||
ESP_GATTC_REG_FOR_NOTIFY_EVT = 38, /*!< When register for notification of a service completes, the event comes */
|
||||
ESP_GATTC_UNREG_FOR_NOTIFY_EVT = 39, /*!< When unregister for notification of a service completes, the event comes */
|
||||
} esp_gattc_cb_event_t;
|
||||
|
||||
/// Maximum Transmission Unit used in GATT
|
||||
#define ESP_GATT_DEF_BLE_MTU_SIZE 23
|
||||
|
||||
/// Maximum Transmission Unit allowed in GATT
|
||||
#define ESP_GATT_MAX_MTU_SIZE 517
|
||||
|
||||
/* esp_ble_gattc_cb_param_t */
|
||||
/**
|
||||
* @brief Gatt client callback parameters union
|
||||
*/
|
||||
typedef union {
|
||||
/*registration data for ESP_GATTC_REG_EVT */
|
||||
struct gattc_reg_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_bt_uuid_t uuid; /* btla-specific ++ */
|
||||
} reg;
|
||||
/**
|
||||
* @brief ESP_GATTC_REG_EVT
|
||||
*/
|
||||
struct gattc_reg_evt_param {
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t app_id; /*!< Application id which input in register API */
|
||||
} reg; /*!< Gatt client callback param of ESP_GATTC_REG_EVT */
|
||||
|
||||
/* ESP_GATTC_OPEN_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_OPEN_EVT
|
||||
*/
|
||||
struct gattc_open_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
uint16_t conn_id;
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
// tBTA_TRANSPORT transport;
|
||||
uint16_t mtu;
|
||||
} open;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
uint16_t mtu; /*!< MTU size */
|
||||
} open; /*!< Gatt client callback param of ESP_GATTC_OPEN_EVT */
|
||||
|
||||
/* ESP_GATTC_CLOSE_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_CLOSE_EVT
|
||||
*/
|
||||
struct gattc_close_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
uint16_t conn_id;
|
||||
esp_gatt_if_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
esp_gatt_reason_t reason;
|
||||
} close;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_if_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
esp_gatt_conn_reason_t reason; /*!< The reason of gatt connection close */
|
||||
} close; /*!< Gatt client callback param of ESP_GATTC_CLOSE_EVT */
|
||||
|
||||
/* ESP_GATTC_CFG_MTU_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_CFG_MTU_EVT
|
||||
*/
|
||||
struct gattc_cfg_mtu_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
uint16_t mtu;
|
||||
} cfg_mtu;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint16_t mtu; /*!< MTU size */
|
||||
} cfg_mtu; /*!< Gatt client callback param of ESP_GATTC_CFG_MTU_EVT */
|
||||
|
||||
/* ESP_GATTC_SEARCH_CMPL_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_SEARCH_CMPL_EVT
|
||||
*/
|
||||
struct gattc_search_cmpl_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
} search_cmpl;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
} search_cmpl; /*!< Gatt client callback param of ESP_GATTC_SEARCH_CMPL_EVT */
|
||||
|
||||
/* ESP_GATTC_SEARCH_RES_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_SEARCH_RES_EVT
|
||||
*/
|
||||
struct gattc_search_res_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_srvc_id_t service_id;
|
||||
} search_res;
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
} search_res; /*!< Gatt client callback param of ESP_GATTC_SEARCH_RES_EVT */
|
||||
|
||||
/* ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_READ_CHAR_EVT, ESP_GATTC_READ_DESCR_EVT
|
||||
*/
|
||||
struct gattc_read_char_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
uint8_t *value;
|
||||
uint16_t value_type;
|
||||
uint16_t value_len;
|
||||
} read; /* ESP_GATTC_READ_CHAR_EVT */
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
|
||||
uint8_t *value; /*!< Characteristic value */
|
||||
uint16_t value_type; /*!< Characteristic value type */
|
||||
uint16_t value_len; /*!< Characteristic value length */
|
||||
} read; /*!< Gatt client callback param of ESP_GATTC_READ_CHAR_EVT */
|
||||
|
||||
/* ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_WRITE_CHAR_EVT, ESP_GATTC_PREP_WRITE_EVT, ESP_GATTC_WRITE_DESCR_EVT
|
||||
*/
|
||||
struct gattc_write_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
} write;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
|
||||
} write; /*!< Gatt client callback param of ESP_GATTC_WRITE_DESCR_EVT */
|
||||
|
||||
/* ESP_GATTC_EXEC_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_EXEC_EVT
|
||||
*/
|
||||
struct gattc_exec_cmpl_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
} exec_cmpl;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
} exec_cmpl; /*!< Gatt client callback param of ESP_GATTC_EXEC_EVT */
|
||||
|
||||
/* ESP_GATTC_NOTIF_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_NOTIFY_EVT
|
||||
*/
|
||||
struct gattc_notify_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_bd_addr_t bda;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
uint16_t value_len;
|
||||
uint8_t *value;
|
||||
bool is_notify;
|
||||
} notify;
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
|
||||
uint16_t value_len; /*!< Notify attribute value */
|
||||
uint8_t *value; /*!< Notify attribute value */
|
||||
bool is_notify; /*!< True means notify, false means indicate */
|
||||
} notify; /*!< Gatt client callback param of ESP_GATTC_NOTIFY_EVT */
|
||||
|
||||
/* ESP_GATTC_SRVC_CHG_EVT*/
|
||||
/**
|
||||
* @brief ESP_GATTC_SRVC_CHG_EVT
|
||||
*/
|
||||
struct gattc_srvc_chg_evt_param {
|
||||
esp_bd_addr_t remote_bda;
|
||||
} srvc_chg;
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
} srvc_chg; /*!< Gatt client callback param of ESP_GATTC_SRVC_CHG_EVT */
|
||||
|
||||
/* ESP_GATTC_CONGEST_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_CONGEST_EVT
|
||||
*/
|
||||
struct gattc_congest_evt_param {
|
||||
uint16_t conn_id;
|
||||
bool congested;
|
||||
} congest;
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
bool congested; /*!< Congested or not */
|
||||
} congest; /*!< Gatt client callback param of ESP_GATTC_CONGEST_EVT */
|
||||
|
||||
/* ESP_GATTC_GET_CHAR_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_GET_CHAR_EVT
|
||||
*/
|
||||
struct gattc_get_char_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_char_prop_t char_prop;
|
||||
} get_char;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
esp_gatt_char_prop_t char_prop; /*!< Characteristic property */
|
||||
} get_char; /*!< Gatt client callback param of ESP_GATTC_GET_CHAR_EVT */
|
||||
|
||||
/* ESP_GATTC_GET_DESCR_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_GET_DESCR_EVT
|
||||
*/
|
||||
struct gattc_get_descr_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
} get_descr;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
esp_gatt_id_t descr_id; /*!< Descriptor id, include descriptor uuid and other information */
|
||||
} get_descr; /*!< Gatt client callback param of ESP_GATTC_GET_DESCR_EVT */
|
||||
|
||||
/* ESP_GATTC_GET_INCL_SRVC_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_GET_INCL_SRVC_EVT
|
||||
*/
|
||||
struct gattc_get_incl_srvc_evt_param {
|
||||
uint16_t conn_id;
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_srvc_id_t incl_srvc_id;
|
||||
} get_incl_srvc;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_srvc_id_t incl_srvc_id;/*!< Included service id, include service uuid and other information */
|
||||
} get_incl_srvc; /*!< Gatt client callback param of ESP_GATTC_GET_INCL_SRVC_EVT */
|
||||
|
||||
/* ESP_GATTC_REG_FOR_NOTIF_EVT, ESP_GATTC_UNREG_FOR_NOTIF_EVT */
|
||||
/**
|
||||
* @brief ESP_GATTC_REG_FOR_NOTIFY_EVT
|
||||
*/
|
||||
struct gattc_reg_for_notify_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
} reg_for_notify;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
} reg_for_notify; /*!< Gatt client callback param of ESP_GATTC_REG_FOR_NOTIFY_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTC_UNREG_FOR_NOTIFY_EVT
|
||||
*/
|
||||
struct gattc_unreg_for_notify_evt_param {
|
||||
esp_gatt_status_t status;
|
||||
esp_gatt_srvc_id_t srvc_id;
|
||||
esp_gatt_id_t char_id;
|
||||
} unreg_for_notify;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
esp_gatt_srvc_id_t srvc_id; /*!< Service id, include service uuid and other information */
|
||||
esp_gatt_id_t char_id; /*!< Characteristic id, include characteristic uuid and other information */
|
||||
} unreg_for_notify; /*!< Gatt client callback param of ESP_GATTC_UNREG_FOR_NOTIFY_EVT */
|
||||
|
||||
|
||||
} esp_ble_gattc_cb_param_t;
|
||||
} esp_ble_gattc_cb_param_t; /*!< GATT client callback parameter union type */
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register_callback
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] callback - pointer to the application callback function.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to register application callbacks
|
||||
* with GATTC module.
|
||||
*
|
||||
* @param[in] callback : pointer to the application callback function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_register
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with GATTC module.
|
||||
**
|
||||
** @param[in] app_id : Application Identitfy (UUID), for different application
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to register application callbacks
|
||||
* with GATTC module.
|
||||
*
|
||||
* @param[in] app_id : Application Identify (UUID), for different application
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_app_register(uint16_t app_id);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_app_unregister
|
||||
**
|
||||
** @brief This function is called to unregister an application
|
||||
** from GATTC module.
|
||||
**
|
||||
** @param[in] gatt_if - app identifier.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to unregister an application
|
||||
* from GATTC module.
|
||||
*
|
||||
* @param[in] gatt_if : app identifier.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_app_unregister(esp_gatt_if_t gatt_if);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_conn
|
||||
**
|
||||
** @brief Open a direct connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] gatt_if: application identity.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Open a direct connection or add a background auto connection
|
||||
*
|
||||
* @param[in] gatt_if: application identity.
|
||||
* @param[in] remote_bda: remote device bluetooth device address.
|
||||
* @param[in] is_direct: direct connection or background auto connection
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_close
|
||||
**
|
||||
** @brief Close a connection to a GATT server.
|
||||
**
|
||||
** @param[in] conn_id: connectino ID to be closed.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_close (uint16_t conn_id);
|
||||
|
||||
/**
|
||||
* @brief Close a connection to a GATT server.
|
||||
*
|
||||
* @param[in] conn_id: connection ID to be closed.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_close(uint16_t conn_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_config_mtu
|
||||
**
|
||||
** @brief Configure the MTU size in the GATT channel. This can be done
|
||||
** only once per connection.
|
||||
**
|
||||
** @param[in] conn_id: connection ID.
|
||||
** mtu: desired MTU size to use.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gattc_config_mtu (uint16_t conn_id, uint16_t mtu);
|
||||
/**
|
||||
* @brief Configure the MTU size in the GATT channel. This can be done
|
||||
* only once per connection.
|
||||
*
|
||||
* @param[in] conn_id: connection ID.
|
||||
* @param[in] mtu: desired MTU size to use.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_config_mtu(uint16_t conn_id, uint16_t mtu);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_search_service
|
||||
**
|
||||
** @brief This function is called to request a GATT service discovery
|
||||
** on a GATT server. This function report service search result
|
||||
** by a callback event, and followed by a service search complete
|
||||
** event.
|
||||
**
|
||||
** @param[in] conn_id: connection ID.
|
||||
** @param[in] filter_uuid: a UUID of the service application is interested in.
|
||||
** If Null, discover for all services.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to request a GATT service discovery
|
||||
* on a GATT server. This function report service search result
|
||||
* by a callback event, and followed by a service search complete
|
||||
* event.
|
||||
*
|
||||
* @param[in] conn_id: connection ID.
|
||||
* @param[in] filter_uuid: a UUID of the service application is interested in.
|
||||
* If Null, discover for all services.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_search_service(uint16_t conn_id, esp_bt_uuid_t *filter_uuid);
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_characteristic
|
||||
**
|
||||
** @brief This function is called to find the first characteristic of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
**
|
||||
** @param[in] srvc_id: serivce ID
|
||||
**
|
||||
** @param[in] start_char_id: the start characteristic ID
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function is called to find the first characteristic of the
|
||||
* service on the given server.
|
||||
*
|
||||
* @param[in] conn_id: connection ID which identify the server.
|
||||
*
|
||||
* @param[in] srvc_id: service ID
|
||||
*
|
||||
* @param[in] start_char_id: the start characteristic ID
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_get_characteristic(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *start_char_id);
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_descriptor
|
||||
**
|
||||
** @brief This function is called to find the descriptor of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
** @param[in] char_id: Characteristic ID, if NULL find the first available
|
||||
** characteristic.
|
||||
** @param[in] start_descr_id: the sctart descriptor id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief This function is called to find the descriptor of the
|
||||
* service on the given server.
|
||||
*
|
||||
* @param[in] conn_id: connection ID which identify the server.
|
||||
* @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
* @param[in] char_id: Characteristic ID, if NULL find the first available
|
||||
* characteristic.
|
||||
* @param[in] start_descr_id: the start descriptor id
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_get_descriptor(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *start_descr_id);
|
||||
|
||||
|
||||
/****************************************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_get_include_service
|
||||
**
|
||||
** @brief This function is called to find the first characteristic of the
|
||||
** service on the given server.
|
||||
**
|
||||
** @param[in] conn_id: connection ID which identify the server.
|
||||
** @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
** @param[in] start_incl_srvc_id: the start include service id
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*****************************************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* @brief This function is called to find the first characteristic of the
|
||||
* service on the given server.
|
||||
*
|
||||
* @param[in] conn_id: connection ID which identify the server.
|
||||
* @param[in] srvc_id: the service ID of which the characteristic is belonged to.
|
||||
* @param[in] start_incl_srvc_id: the start include service id
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_get_included_service(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id, esp_gatt_srvc_id_t *start_incl_srvc_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char
|
||||
**
|
||||
** @brief This function is called to read a service's characteristics of
|
||||
** the given characteritisc ID.UTH_REQ_NO_SCATTERNET
|
||||
**
|
||||
** @param[in] conn_id - connectino ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteritic ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to read a service's characteristics of
|
||||
* the given characteriistic ID
|
||||
*
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID to read.
|
||||
* @param[in] auth_req : authenticate request type
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_read_char (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_read_char_descr
|
||||
**
|
||||
** @brief This function is called to read a characteristics descriptor.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] descr_id - characteritic descriptor ID to read.
|
||||
** @param[in] auth_req - authenticate request type
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to read a characteristics descriptor.
|
||||
*
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID to read.
|
||||
* @param[in] descr_id : characteristic descriptor ID to read.
|
||||
* @param[in] auth_req : authenticate request type
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
|
@ -423,70 +445,74 @@ esp_err_t esp_ble_gattc_read_char_descr (uint16_t conn_id,
|
|||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char
|
||||
**
|
||||
** @brief This function is called to write characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID to write.
|
||||
** @param[in] value_len: length of the value to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to write characteristic value.
|
||||
*
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID to write.
|
||||
* @param[in] value_len: length of the value to be written.
|
||||
* @param[in] value : the value to be written.
|
||||
* @param[in] write_type : the type of attribute write operation.
|
||||
* @param[in] auth_req : authentication request.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_write_char( uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_write_char_descr
|
||||
**
|
||||
** @brief This function is called to write characteristic descriptor value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID
|
||||
** @param[in] srvc_id - serivcie ID.
|
||||
** @param[in] char_id - characteristic ID.
|
||||
** @param[in] descr_id - characteristic descriptor ID to write.
|
||||
** @param[in] value_len: length of the value to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to write characteristic descriptor value.
|
||||
*
|
||||
* @param[in] conn_id : connection ID
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : characteristic ID.
|
||||
* @param[in] descr_id : characteristic descriptor ID to write.
|
||||
* @param[in] value_len: length of the value to be written.
|
||||
* @param[in] value : the value to be written.
|
||||
* @param[in] write_type : the type of attribute write operation.
|
||||
* @param[in] auth_req : authentication request.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_write_char_descr (uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
esp_gatt_id_t *descr_id,
|
||||
uint16_t value_len,
|
||||
uint8_t *value,
|
||||
esp_gatt_write_type_t write_type,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_prepare_write
|
||||
**
|
||||
** @brief This function is called to prepare write a characteristic value.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] char_id - GATT characteritic ID of the service.
|
||||
** @param[in] offset - offset of the write value.
|
||||
** @param[in] value_len: length of the value to be written.
|
||||
** @param[in] value - the value to be written.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to prepare write a characteristic value.
|
||||
*
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] srvc_id : service ID.
|
||||
* @param[in] char_id : GATT characteristic ID of the service.
|
||||
* @param[in] offset : offset of the write value.
|
||||
* @param[in] value_len: length of the value to be written.
|
||||
* @param[in] value : the value to be written.
|
||||
* @param[in] auth_req : authentication request.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id,
|
||||
|
@ -495,56 +521,52 @@ esp_err_t esp_ble_gattc_prepare_write(uint16_t conn_id,
|
|||
uint8_t *value,
|
||||
esp_gatt_auth_req_t auth_req);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_execu_write
|
||||
**
|
||||
** @brief This function is called to execute write a prepare write sequence.
|
||||
**
|
||||
** @param[in] conn_id - connection ID.
|
||||
** @param[in] is_execute - execute or cancel.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to execute write a prepare write sequence.
|
||||
*
|
||||
* @param[in] conn_id : connection ID.
|
||||
* @param[in] is_execute : execute or cancel.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: success
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gattc_execute_write (uint16_t conn_id, bool is_execute);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_register_for_notify
|
||||
**
|
||||
** @brief This function is called to register for notification of a service.
|
||||
**
|
||||
** @param[in] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if registration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to register for notification of a service.
|
||||
*
|
||||
* @param[in] gatt_if : gatt interface id.
|
||||
* @param[in] server_bda : target GATT server.
|
||||
* @param[in] srvc_id : pointer to GATT service ID.
|
||||
* @param[in] char_id : pointer to GATT characteristic ID.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: registration succeeds
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_gatt_status_t esp_ble_gattc_register_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
esp_gatt_id_t *char_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gattc_unregister_ntf
|
||||
**
|
||||
** @brief This function is called to de-register for notification of a service.
|
||||
**
|
||||
** @param[in] gatt_if - gatt interface id.
|
||||
** @param[in] bda - target GATT server.
|
||||
** @param[in] srvc_id - pointer to GATT service ID.
|
||||
** @param[in] char_id - pointer to GATT characteristic ID.
|
||||
**
|
||||
** @return OK if deregistration succeed, otherwise failed.
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to de-register for notification of a service.
|
||||
*
|
||||
* @param[in] gatt_if : gatt interface id.
|
||||
* @param[in] server_bda : target GATT server.
|
||||
* @param[in] srvc_id : pointer to GATT service ID.
|
||||
* @param[in] char_id : pointer to GATT characteristic ID.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: unregister succeeds
|
||||
* - other: failed
|
||||
*
|
||||
*/
|
||||
esp_gatt_status_t esp_ble_gattc_unregister_for_notify (esp_gatt_if_t gatt_if,
|
||||
esp_bd_addr_t server_bda,
|
||||
esp_gatt_srvc_id_t *srvc_id,
|
||||
|
|
|
@ -21,397 +21,441 @@
|
|||
#include "bta_gatt_api.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
/* GATT Server Data Structure */
|
||||
/* Server callback function events */
|
||||
#define ESP_GATTS_REG_EVT 0
|
||||
#define ESP_GATTS_READ_EVT 1
|
||||
#define ESP_GATTS_WRITE_EVT 2
|
||||
#define ESP_GATTS_EXEC_WRITE_EVT 3
|
||||
#define ESP_GATTS_MTU_EVT 4
|
||||
#define ESP_GATTS_CONF_EVT 5
|
||||
#define ESP_GATTS_UNREG_EVT 6
|
||||
#define ESP_GATTS_CREATE_EVT 7
|
||||
#define ESP_GATTS_ADD_INCL_SRVC_EVT 8
|
||||
#define ESP_GATTS_ADD_CHAR_EVT 9
|
||||
#define ESP_GATTS_ADD_CHAR_DESCR_EVT 10
|
||||
#define ESP_GATTS_DELELTE_EVT 11
|
||||
#define ESP_GATTS_START_EVT 12
|
||||
#define ESP_GATTS_STOP_EVT 13
|
||||
#define ESP_GATTS_CONNECT_EVT 14
|
||||
#define ESP_GATTS_DISCONNECT_EVT 15
|
||||
#define ESP_GATTS_OPEN_EVT 16
|
||||
#define ESP_GATTS_CANCEL_OPEN_EVT 17
|
||||
#define ESP_GATTS_CLOSE_EVT 18
|
||||
#define ESP_GATTS_LISTEN_EVT 19
|
||||
#define ESP_GATTS_CONGEST_EVT 20
|
||||
/* following is extra event */
|
||||
#define ESP_GATTS_RESPONSE_EVT 21
|
||||
/// GATT Server callback function events
|
||||
typedef enum {
|
||||
ESP_GATTS_REG_EVT = 0, /*!< When register application id, the event comes */
|
||||
ESP_GATTS_READ_EVT = 1, /*!< When gatt client request read operation, the event comes */
|
||||
ESP_GATTS_WRITE_EVT = 2, /*!< When gatt client request write operation, the event comes */
|
||||
ESP_GATTS_EXEC_WRITE_EVT = 3, /*!< When gatt client request execute write, the event comes */
|
||||
ESP_GATTS_MTU_EVT = 4, /*!< When set mtu complete, the event comes */
|
||||
ESP_GATTS_CONF_EVT = 5, /*!< When receive confirm, the event comes */
|
||||
ESP_GATTS_UNREG_EVT = 6, /*!< When unregister application id, the event comes */
|
||||
ESP_GATTS_CREATE_EVT = 7, /*!< When create service complete, the event comes */
|
||||
ESP_GATTS_ADD_INCL_SRVC_EVT = 8, /*!< When add included service complete, the event comes */
|
||||
ESP_GATTS_ADD_CHAR_EVT = 9, /*!< When add characteristic complete, the event comes */
|
||||
ESP_GATTS_ADD_CHAR_DESCR_EVT = 10, /*!< When add descriptor complete, the event comes */
|
||||
ESP_GATTS_DELETE_EVT = 11, /*!< When delete service complete, the event comes */
|
||||
ESP_GATTS_START_EVT = 12, /*!< When start service complete, the event comes */
|
||||
ESP_GATTS_STOP_EVT = 13, /*!< When stop service complete, the event comes */
|
||||
ESP_GATTS_CONNECT_EVT = 14, /*!< When gatt client connect, the event comes */
|
||||
ESP_GATTS_DISCONNECT_EVT = 15, /*!< When gatt client disconnect, the event comes */
|
||||
ESP_GATTS_OPEN_EVT = 16, /*!< When connect to peer, the event comes */
|
||||
ESP_GATTS_CANCEL_OPEN_EVT = 17, /*!< When disconnect from peer, the event comes */
|
||||
ESP_GATTS_CLOSE_EVT = 18, /*!< When gatt server close, the event comes */
|
||||
ESP_GATTS_LISTEN_EVT = 19, /*!< When gatt listen to be connected the event comes */
|
||||
ESP_GATTS_CONGEST_EVT = 20, /*!< When congest happen, the event comes */
|
||||
/* following is extra event */
|
||||
ESP_GATTS_RESPONSE_EVT = 21, /*!< When gatt send response complete, the event comes */
|
||||
} esp_gatts_cb_event_t;
|
||||
|
||||
/* esp_ble_gatts_cb_param_t */
|
||||
/**
|
||||
* @brief Gatt server callback parameters union
|
||||
*/
|
||||
typedef union {
|
||||
//ESP_GATTS_REG_EVT
|
||||
/**
|
||||
* @brief ESP_GATTS_REG_EVT
|
||||
*/
|
||||
struct gatts_reg_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t app_id;
|
||||
} reg;
|
||||
// param for ESP_GATTS_READ_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t app_id; /*!< Application id which input in register API */
|
||||
} reg; /*!< Gatt server callback param of ESP_GATTS_REG_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_READ_EVT
|
||||
*/
|
||||
struct gatts_read_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint32_t trans_id;
|
||||
esp_bd_addr_t bda;
|
||||
uint16_t handle;
|
||||
uint16_t offset;
|
||||
bool is_long;
|
||||
} read;
|
||||
// param for ESP_GATTS_WRITE_EVT
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint32_t trans_id; /*!< Transfer id */
|
||||
esp_bd_addr_t bda; /*!< The bluetooth device address which been read */
|
||||
uint16_t handle; /*!< The attribute handle */
|
||||
uint16_t offset; /*!< Offset of the value, if the value is too long */
|
||||
bool is_long; /*!< The value is too long or not */
|
||||
} read; /*!< Gatt server callback param of ESP_GATTS_READ_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_WRITE_EVT
|
||||
*/
|
||||
struct gatts_write_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint32_t trans_id;
|
||||
esp_bd_addr_t bda;
|
||||
uint16_t handle;
|
||||
uint16_t offset;
|
||||
bool need_rsp;
|
||||
bool is_prep;
|
||||
uint16_t len;
|
||||
uint8_t *value;
|
||||
} write;
|
||||
// param for ESP_GATTS_EXEC_WRITE_EVT
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint32_t trans_id; /*!< Transfer id */
|
||||
esp_bd_addr_t bda; /*!< The bluetooth device address which been written */
|
||||
uint16_t handle; /*!< The attribute handle */
|
||||
uint16_t offset; /*!< Offset of the value, if the value is too long */
|
||||
bool need_rsp; /*!< The write operation need to do response */
|
||||
bool is_prep; /*!< This write operation is prepare write */
|
||||
uint16_t len; /*!< The write attribute value length */
|
||||
uint8_t *value; /*!< The write attribute value */
|
||||
} write; /*!< Gatt server callback param of ESP_GATTS_WRITE_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_EXEC_WRITE_EVT
|
||||
*/
|
||||
struct gatts_exec_write_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint32_t trans_id;
|
||||
esp_bd_addr_t bda;
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint32_t trans_id; /*!< Transfer id */
|
||||
esp_bd_addr_t bda; /*!< The bluetooth device address which been written */
|
||||
#define ESP_GATT_PREP_WRITE_CANCEL 0x00
|
||||
#define ESP_GATT_PREP_WRITE_EXEC 0x01
|
||||
uint8_t exec_write_flag;
|
||||
} exec_write;
|
||||
// param for ESP_GATTS_MTU_EVT
|
||||
uint8_t exec_write_flag; /*!< Execute write flag */
|
||||
} exec_write; /*!< Gatt server callback param of ESP_GATTS_EXEC_WRITE_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_MTU_EVT
|
||||
*/
|
||||
struct gatts_mtu_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint16_t mtu;
|
||||
} mtu;
|
||||
// param for ESP_GATTS_CONF_EVT
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint16_t mtu; /*!< MTU size */
|
||||
} mtu; /*!< Gatt server callback param of ESP_GATTS_MTU_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_CONF_EVT
|
||||
*/
|
||||
struct gatts_conf_evt_param {
|
||||
uint16_t conn_id;
|
||||
int status;
|
||||
} conf;
|
||||
// param for ESP_GATTS_DEREG_EVT, NONE
|
||||
// param for ESP_GATTS_CREATE_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
} conf; /*!< Gatt server callback param of ESP_GATTS_CONF_EVT (confirm) */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_UNREG_EVT
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_CREATE_EVT
|
||||
*/
|
||||
struct gatts_create_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
esp_gatt_srvc_id_t service_id; //id
|
||||
} create;
|
||||
// param for ESP_GATTS_ADD_INCL_SRVC_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
esp_gatt_srvc_id_t service_id; /*!< Service id, include service uuid and other information */
|
||||
} create; /*!< Gatt server callback param of ESP_GATTS_CREATE_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_ADD_INCL_SRVC_EVT
|
||||
*/
|
||||
struct gatts_add_incl_srvc_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t attr_handle; //handle
|
||||
uint16_t service_handle; //handle
|
||||
} add_incl_srvc;
|
||||
// param for ESP_GATTS_ADD_CHAR_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t attr_handle; /*!< Included service attribute handle */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} add_incl_srvc; /*!< Gatt server callback param of ESP_GATTS_ADD_INCL_SRVC_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_ADD_CHAR_EVT
|
||||
*/
|
||||
struct gatts_add_char_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t attr_handle; //handle
|
||||
uint16_t service_handle; //handle
|
||||
esp_bt_uuid_t char_uuid;
|
||||
} add_char;
|
||||
// param for ESP_GATTS_ADD_CHAR_DESCR_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t attr_handle; /*!< Characteristic attribute handle */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
esp_bt_uuid_t char_uuid; /*!< Characteristic uuid */
|
||||
} add_char; /*!< Gatt server callback param of ESP_GATTS_ADD_CHAR_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_ADD_CHAR_DESCR_EVT
|
||||
*/
|
||||
struct gatts_add_char_descr_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t attr_handle; //handle
|
||||
uint16_t service_handle; //handle
|
||||
esp_bt_uuid_t char_uuid;
|
||||
} add_char_descr;
|
||||
// param for ESP_GATTS_DELELTE_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t attr_handle; /*!< Descriptor attribute handle */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
esp_bt_uuid_t char_uuid; /*!< Characteristic uuid */
|
||||
} add_char_descr; /*!< Gatt server callback param of ESP_GATTS_ADD_CHAR_DESCR_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_DELETE_EVT
|
||||
*/
|
||||
struct gatts_delete_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
} del;
|
||||
// param for ESP_GATTS_START_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} del; /*!< Gatt server callback param of ESP_GATTS_DELETE_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_START_EVT
|
||||
*/
|
||||
struct gatts_start_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
} start;
|
||||
// param for ESP_GATTS_STOP_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} start; /*!< Gatt server callback param of ESP_GATTS_START_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_STOP_EVT
|
||||
*/
|
||||
struct gatts_stop_evt_param {
|
||||
int status;
|
||||
uint16_t gatt_if;
|
||||
uint16_t service_handle; //handle
|
||||
} stop;
|
||||
// param for ESP_GATTS_CONNECT_EVT
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
uint16_t service_handle; /*!< Service attribute handle */
|
||||
} stop; /*!< Gatt server callback param of ESP_GATTS_STOP_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_CONNECT_EVT
|
||||
*/
|
||||
struct gatts_connect_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint16_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
bool is_connected;
|
||||
} connect;
|
||||
// param for ESP_GATTS_DISCONNECT_EVT
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
bool is_connected; /*!< Indicate it is connected or not */
|
||||
} connect; /*!< Gatt server callback param of ESP_GATTS_CONNECT_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_DISCONNECT_EVT
|
||||
*/
|
||||
struct gatts_disconnect_evt_param {
|
||||
uint16_t conn_id;
|
||||
uint16_t gatt_if;
|
||||
esp_bd_addr_t remote_bda;
|
||||
bool is_connected;
|
||||
} disconnect;
|
||||
// param for ESP_GATTS_OPEN_EVT none
|
||||
// param for ESP_GATTS_CANCEL_OPEN_EVT none
|
||||
// param for ESP_GATTS_CLOSE_EVT none
|
||||
// param for ESP_GATTS_LISTEN_EVT none
|
||||
// param for ESP_GATTS_CONGEST_EVT
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
uint16_t gatt_if; /*!< Gatt interface id, different application on gatt client different gatt_if */
|
||||
esp_bd_addr_t remote_bda; /*!< Remote bluetooth device address */
|
||||
bool is_connected; /*!< Indicate it is connected or not */
|
||||
} disconnect; /*!< Gatt server callback param of ESP_GATTS_DISCONNECT_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_OPEN_EVT
|
||||
*/
|
||||
/**
|
||||
* @brief ESP_GATTS_CANCEL_OPEN_EVT
|
||||
*/
|
||||
/**
|
||||
* @brief ESP_GATTS_CLOSE_EVT
|
||||
*/
|
||||
/**
|
||||
* @brief ESP_GATTS_LISTEN_EVT
|
||||
*/
|
||||
/**
|
||||
* @brief ESP_GATTS_CONGEST_EVT
|
||||
*/
|
||||
struct gatts_congest_evt_param {
|
||||
uint16_t conn_id;
|
||||
bool congested;
|
||||
} congest;
|
||||
// param for ESP_GATTS_RESPONSE_EVT
|
||||
uint16_t conn_id; /*!< Connection id */
|
||||
bool congested; /*!< Congested or not */
|
||||
} congest; /*!< Gatt server callback param of ESP_GATTS_CONGEST_EVT */
|
||||
|
||||
/**
|
||||
* @brief ESP_GATTS_RESPONSE_EVT
|
||||
*/
|
||||
struct gatts_rsp_evt_param {
|
||||
int status; //response status, 0 is success
|
||||
uint16_t handle; //attribute handle which send response
|
||||
} rsp;
|
||||
esp_gatt_status_t status; /*!< Operation status */
|
||||
uint16_t handle; /*!< Attribute handle which send response */
|
||||
} rsp; /*!< Gatt server callback param of ESP_GATTS_RESPONSE_EVT */
|
||||
} esp_ble_gatts_cb_param_t;
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_register_callback
|
||||
**
|
||||
** @brief This function is called to register application callbacks
|
||||
** with BTA GATTS module.
|
||||
**
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to register application callbacks
|
||||
* with BTA GATTS module.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_register_callback(esp_profile_cb_t callback);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_app_register
|
||||
**
|
||||
** @brief This function is called to register application identity
|
||||
**
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to register application identifier
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_app_register(uint16_t app_id);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_app_unregister
|
||||
**
|
||||
** @brief un-register with GATT Server.
|
||||
**
|
||||
** @param[in] gatt_if: gatt interface id.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief unregister with GATT Server.
|
||||
*
|
||||
* @param[in] gatt_if: gatt interface id.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_app_unregister(esp_gatt_if_t gatt_if);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_create_service
|
||||
**
|
||||
** @brief Create a service. When service creation is done, a callback
|
||||
** event BTA_GATTS_CREATE_SRVC_EVT is called to report status
|
||||
** and service ID to the profile. The service ID obtained in
|
||||
** the callback function needs to be used when adding included
|
||||
** service and characteristics/descriptors into the service.
|
||||
**
|
||||
** @param[in] gatt_if: gatt interface ID
|
||||
** @param[in] service_id: service ID.
|
||||
** @param[in] num_handle: numble of handle requessted for this service.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Create a service. When service creation is done, a callback
|
||||
* event BTA_GATTS_CREATE_SRVC_EVT is called to report status
|
||||
* and service ID to the profile. The service ID obtained in
|
||||
* the callback function needs to be used when adding included
|
||||
* service and characteristics/descriptors into the service.
|
||||
*
|
||||
* @param[in] gatt_if: gatt interface ID
|
||||
* @param[in] service_id: service ID.
|
||||
* @param[in] num_handle: number of handle requested for this service.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_create_service(esp_gatt_if_t gatt_if,
|
||||
esp_gatt_srvc_id_t *service_id, uint16_t num_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_include_service
|
||||
**
|
||||
** @brief This function is called to add an included service. After included
|
||||
** service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
|
||||
** is reported the included service ID.
|
||||
**
|
||||
** @param[in] service_handle: service handle to which this included service is to
|
||||
** be added.
|
||||
** @param[in] included_service_handle: the service ID to be included.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
esp_err_t esp_ble_gatts_add_include_service(uint16_t service_handle, uint16_t included_service_handle);
|
||||
/**
|
||||
* @brief This function is called to add an included service. After included
|
||||
* service is included, a callback event BTA_GATTS_ADD_INCL_SRVC_EVT
|
||||
* is reported the included service ID.
|
||||
*
|
||||
* @param[in] service_handle: service handle to which this included service is to
|
||||
* be added.
|
||||
* @param[in] included_service_handle: the service ID to be included.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_add_included_service(uint16_t service_handle, uint16_t included_service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_char
|
||||
**
|
||||
** @brief This function is called to add a characteristic into a service.
|
||||
**
|
||||
** @param[in] service_handle: service handle to which this included service is to
|
||||
** be added.
|
||||
** @param[in] char_uuid : Characteristic UUID.
|
||||
** @param[in] perm : Characteristic value declaration attribute permission.
|
||||
** @param[in] property : Characteristic Properties
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to add a characteristic into a service.
|
||||
*
|
||||
* @param[in] service_handle: service handle to which this included service is to
|
||||
* be added.
|
||||
* @param[in] char_uuid : Characteristic UUID.
|
||||
* @param[in] perm : Characteristic value declaration attribute permission.
|
||||
* @param[in] property : Characteristic Properties
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_add_char(uint16_t service_handle, esp_bt_uuid_t *char_uuid,
|
||||
esp_gatt_perm_t perm, esp_gatt_char_prop_t property);
|
||||
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_add_char_descr
|
||||
**
|
||||
** @brief This function is called to add characteristic descriptor. When
|
||||
** it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
|
||||
** to report the status and an ID number for this descriptor.
|
||||
**
|
||||
** @param[in] service_handle: service handle to which this charatceristic descriptor is to
|
||||
** be added.
|
||||
** @param[in] perm: descriptor access permission.
|
||||
** @param[in] descr_uuid: descriptor UUID.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to add characteristic descriptor. When
|
||||
* it's done, a callback event BTA_GATTS_ADD_DESCR_EVT is called
|
||||
* to report the status and an ID number for this descriptor.
|
||||
*
|
||||
* @param[in] service_handle: service handle to which this characteristic descriptor is to
|
||||
* be added.
|
||||
* @param[in] perm: descriptor access permission.
|
||||
* @param[in] descr_uuid: descriptor UUID.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_add_char_descr (uint16_t service_handle,
|
||||
esp_bt_uuid_t *descr_uuid,
|
||||
esp_gatt_perm_t perm);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_delete_service
|
||||
**
|
||||
** @brief This function is called to delete a service. When this is done,
|
||||
** a callback event BTA_GATTS_DELETE_EVT is report with the status.
|
||||
**
|
||||
** @param[in] service_handled: service_handle to be deleted.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to delete a service. When this is done,
|
||||
* a callback event BTA_GATTS_DELETE_EVT is report with the status.
|
||||
*
|
||||
* @param[in] service_handle: service_handle to be deleted.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_delete_service(uint16_t service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_start_service
|
||||
**
|
||||
** @brief This function is called to start a service.
|
||||
**
|
||||
** @param[in] service_handle: the service handle to be started.
|
||||
** @param[in] sup_transport: supported trasnport.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to start a service.
|
||||
*
|
||||
* @param[in] service_handle: the service handle to be started.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_start_service(uint16_t service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_stop_service
|
||||
**
|
||||
** @brief This function is called to stop a service.
|
||||
**
|
||||
** @param[in] service_handle - service to be topped.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to stop a service.
|
||||
*
|
||||
* @param[in] service_handle - service to be topped.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_stop_service(uint16_t service_handle);
|
||||
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_send_indicate
|
||||
**
|
||||
** @brief This function is called to read a characteristics descriptor.
|
||||
**
|
||||
** @param[in] conn_id - connection id to indicate.
|
||||
** @param[in] attribute_handle - attribute handle to indicate.
|
||||
** @param[in] value_len - indicate value length.
|
||||
** @param[in] value: value to indicate.
|
||||
** @param[in] need_confirm - if this indication expects a confirmation or not.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to read a characteristics descriptor.
|
||||
*
|
||||
* @param[in] conn_id - connection id to indicate.
|
||||
* @param[in] attr_handle - attribute handle to indicate.
|
||||
* @param[in] value_len - indicate value length.
|
||||
* @param[in] value: value to indicate.
|
||||
* @param[in] need_confirm - if this indication expects a confirmation or not.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_send_indicate(uint16_t conn_id, uint16_t attr_handle,
|
||||
uint16_t value_len, uint8_t *value, bool need_confirm);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_send_rsp
|
||||
**
|
||||
** @brief This function is called to send a response to a request.
|
||||
**
|
||||
** @param[in] conn_id - connection identifier.
|
||||
** @param[in] trans_id - transfe id
|
||||
** @param[in] status - response status
|
||||
** @param[in] rsp - response data.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief This function is called to send a response to a request.
|
||||
*
|
||||
* @param[in] conn_id - connection identifier.
|
||||
* @param[in] trans_id - transfer id
|
||||
* @param[in] status - response status
|
||||
* @param[in] rsp - response data.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_send_response(uint16_t conn_id, uint32_t trans_id,
|
||||
esp_gatt_status_t status, esp_gatt_rsp_t *rsp);
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_open
|
||||
**
|
||||
** @brief Open a direct open connection or add a background auto connection
|
||||
** bd address
|
||||
**
|
||||
** @param[in] gatt_if: application ID.
|
||||
** @param[in] remote_bda: remote device BD address.
|
||||
** @param[in] is_direct: direct connection or background auto connection
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Open a direct open connection or add a background auto connection
|
||||
*
|
||||
* @param[in] gatt_if: application ID.
|
||||
* @param[in] remote_bda: remote device bluetooth device address.
|
||||
* @param[in] is_direct: direct connection or background auto connection
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_open(esp_gatt_if_t gatt_if, esp_bd_addr_t remote_bda, bool is_direct);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** @function esp_ble_gatts_close
|
||||
**
|
||||
** @brief Close a connection a remote device.
|
||||
**
|
||||
** @param[in] conn_id: connectino ID to be closed.
|
||||
**
|
||||
** @return ESP_OK - success, other - failed
|
||||
**
|
||||
*******************************************************************************/
|
||||
/**
|
||||
* @brief Close a connection a remote device.
|
||||
*
|
||||
* @param[in] conn_id: connection ID to be closed.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK : success
|
||||
* - other : failed
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_gatts_close(uint16_t conn_id);
|
||||
|
||||
|
||||
|
|
|
@ -1,129 +0,0 @@
|
|||
// Copyright 2015-2016 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_SDP_API_H__
|
||||
#define __ESP_SDP_API_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_bt_defs.h"
|
||||
#include "bta_sdp_api.h"
|
||||
#include "bt_sdp.h"
|
||||
|
||||
#define BT_SDP_STAT_SUCCESS BTA_SDP_SUCCESS
|
||||
#define BT_SDP_STAT_FAILURE BTA_SDP_FAILURE
|
||||
#define BT_SDP_STAT_BUSY BTA_SDP_BUSY
|
||||
|
||||
#define BT_SDP_ENABLE_EVT BTA_SDP_ENABLE_EVT
|
||||
#define BT_SDP_SEARCH_EVT BTA_SDP_SEARCH_EVT
|
||||
#define BT_SDP_SEARCH_COMP_EVT BTA_SDP_SEARCH_COMP_EVT
|
||||
#define BT_SDP_CREATE_RECORD_USER_EVT BTA_SDP_CREATE_RECORD_USER_EVT
|
||||
#define BT_SDP_REMOVE_RECORD_USER_EVT BTA_SDP_REMOVE_RECORD_USER_EVT
|
||||
#define BT_SDP_MAX_EVT BTA_SDP_MAX_EVT
|
||||
|
||||
#define BT_SDP_MAX_RECORDS BTA_SDP_MAX_RECORDS
|
||||
|
||||
typedef tBTA_SDP_STATUS bt_sdp_status_t;
|
||||
|
||||
typedef tBTA_SDP_EVT bt_sdp_evt_t;
|
||||
|
||||
typedef bluetooth_sdp_record bt_sdp_record_t;
|
||||
|
||||
/* tBTA_SEARCH_COMP, bta_sdp_api.h */
|
||||
typedef struct {
|
||||
bt_sdp_status_t status;
|
||||
esp_bd_addr_t remote_addr;
|
||||
esp_bt_uuid_t uuid;
|
||||
int record_count;
|
||||
bt_sdp_record_t records[BT_SDP_MAX_RECORDS];
|
||||
} bt_sdp_search_comp_t;
|
||||
|
||||
/* tBTA_SDP, bta_sdp_api.h */
|
||||
typedef union {
|
||||
bt_sdp_status_t status;
|
||||
bt_sdp_search_comp_t sdp_search_comp;
|
||||
} bt_sdp_t;
|
||||
|
||||
typedef void (bt_sdp_cb_t)(bt_sdp_evt_t event, bt_sdp_t *p_data, void *user_data);
|
||||
|
||||
esp_err_t esp_bt_sdp_enable(bt_sdp_cb_t *cback);
|
||||
|
||||
esp_err_t esp_bt_sdp_search(esp_bd_addr_t bd_addr, esp_bt_uuid_t *uuid);
|
||||
|
||||
esp_err_t esp_bt_sdp_create_record_by_user(void *user_data);
|
||||
|
||||
esp_err_t esp_bt_sdp_remove_record_by_user(void *user_data);
|
||||
|
||||
|
||||
/**********************************************************************************************/
|
||||
/**********************************************************************************************/
|
||||
/* API into SDP for local service database updates
|
||||
* these APIs are indended to be called in callback function in the context of stack task,
|
||||
* to handle BT_SDP_CREATE_RECORD_USER_EVT and BT_SDP_REMOVE_RECORD_USER_EVT
|
||||
*/
|
||||
|
||||
/* This structure is used to add protocol lists and find protocol elements */
|
||||
#define ESP_BT_SDP_MAX_PROTOCOL_PARAMS SDP_MAX_PROTOCOL_PARAMS // bt_target.h
|
||||
typedef struct {
|
||||
uint16_t protocol_uuid;
|
||||
uint16_t num_params;
|
||||
uint16_t params[ESP_BT_SDP_MAX_PROTOCOL_PARAMS];
|
||||
} sdp_proto_elem_t; // tSDP_PROTOCOL_ELEM, sdp_api.h
|
||||
|
||||
#define ESP_BT_SDP_MAX_LIST_ELEMS SDP_MAX_LIST_ELEMS // sdp_api.h
|
||||
typedef struct {
|
||||
uint16_t num_elems;
|
||||
sdp_proto_elem_t list_elem[ESP_BT_SDP_MAX_LIST_ELEMS];
|
||||
} sdp_proto_list_elem_t; // tSDP_PROTO_LIST_ELEM, sdp_api.h
|
||||
|
||||
|
||||
uint32_t esp_bt_sdp_create_record(void);
|
||||
|
||||
bool esp_bt_sdp_delete_record(uint32_t handle);
|
||||
|
||||
int32_t esp_bt_sdp_read_record(uint32_t handle, uint8_t *data, int32_t *data_len);
|
||||
|
||||
bool esp_bt_sdp_add_attribute (uint32_t handle, uint16_t attr_id,
|
||||
uint8_t attr_type, uint32_t attr_len,
|
||||
uint8_t *p_val);
|
||||
|
||||
bool esp_bt_sdp_add_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_elem, uint8_t type[],
|
||||
uint8_t len[], uint8_t *p_val[]);
|
||||
|
||||
bool esp_bt_sdp_add_uuid_sequence (uint32_t handle, uint16_t attr_id,
|
||||
uint16_t num_uuids, uint16_t *p_uuids);
|
||||
|
||||
|
||||
bool esp_bt_sdp_add_protocol_list (uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_elem_t *p_elem_list);
|
||||
|
||||
bool esp_bt_sdp_add_addition_protocol_lists(uint32_t handle, uint16_t num_elem,
|
||||
sdp_proto_list_elem_t *p_proto_list);
|
||||
|
||||
bool esp_bt_sdp_add_profile_dscp_list (uint32_t handle,
|
||||
uint16_t profile_uuid,
|
||||
uint16_t version);
|
||||
|
||||
bool esp_bt_sdp_add_lang_base_attr_id_list(uint32_t handle,
|
||||
uint16_t lang, uint16_t char_enc,
|
||||
uint16_t base_id);
|
||||
|
||||
bool esp_bt_sdp_add_service_class_id_list(uint32_t handle,
|
||||
uint16_t num_services,
|
||||
uint16_t *p_service_uuids);
|
||||
|
||||
bool esp_bt_sdp_delete_attribute(uint32_t handle, uint16_t attr_id);
|
||||
|
||||
#endif /* __ESP_SDP_API_H__ */
|
|
@ -1,79 +0,0 @@
|
|||
// Copyright 2015-2016 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_SEC_API_H__
|
||||
#define __ESP_SEC_API_H__
|
||||
|
||||
#include "bt_types.h"
|
||||
|
||||
#define APP_SEC_IRK_FLAG (0)
|
||||
#define RAND_NB_LEN 0x08
|
||||
#define SEC_KEY_LEN 0x10
|
||||
|
||||
/*
|
||||
* STRUCTURES DEFINITIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/// Generic Security key structure
|
||||
typedef struct {
|
||||
/// Key value MSB -> LSB
|
||||
UINT8 key[SEC_KEY_LEN];
|
||||
} smp_sec_key;
|
||||
|
||||
///Random number structure
|
||||
typedef struct {
|
||||
///8-byte array for random number
|
||||
UINT8 nb[RAND_NB_LEN];
|
||||
} rand_nb;
|
||||
|
||||
typedef struct {
|
||||
// LTK
|
||||
smp_sec_key ltk;
|
||||
// Random Number
|
||||
rand_nb rand_nb;
|
||||
// EDIV
|
||||
UINT16 ediv;
|
||||
// LTK key size
|
||||
UINT8 key_size;
|
||||
|
||||
// Last paired peer address type
|
||||
UINT8 peer_addr_type;
|
||||
// Last paired peer address
|
||||
BD_ADDR peer_addr;
|
||||
|
||||
// authentication level
|
||||
UINT8 auth;
|
||||
|
||||
} tAPP_SEC_ENV;
|
||||
|
||||
extern tAPP_SEC_ENV app_sec_env;
|
||||
|
||||
/*
|
||||
* GLOBAL FUNCTIONS DECLARATIONS
|
||||
****************************************************************************************
|
||||
*/
|
||||
|
||||
void app_ble_sec_init(void);
|
||||
|
||||
void app_ble_sec_pairing_cmp_evt_send(UINT8);
|
||||
|
||||
UINT32 app_ble_sec_gen_tk(void);
|
||||
|
||||
void app_ble_sec_gen_ltk(UINT8 key_size);
|
||||
|
||||
void app_ble_security_start(void);
|
||||
|
||||
#endif /* __ESP_SEC_API_H__ */
|
|
@ -196,7 +196,7 @@ void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BOOLEAN i
|
|||
**
|
||||
** Description Close a connection to a GATT server.
|
||||
**
|
||||
** Parameters conn_id: connectino ID to be closed.
|
||||
** Parameters conn_id: connection ID to be closed.
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
|
@ -542,7 +542,7 @@ tBTA_GATT_STATUS BTA_GATTC_GetNextIncludedService(UINT16 conn_id,
|
|||
** Description This function is called to read a service's characteristics of
|
||||
** the given characteritisc ID.
|
||||
**
|
||||
** Parameters conn_id - connectino ID.
|
||||
** Parameters conn_id - connection ID.
|
||||
** p_char_id - characteritic ID to read.
|
||||
**
|
||||
** Returns None
|
||||
|
@ -613,7 +613,7 @@ void BTA_GATTC_ReadCharDescr (UINT16 conn_id,
|
|||
** Description This function is called to read multiple characteristic or
|
||||
** characteristic descriptors.
|
||||
**
|
||||
** Parameters conn_id - connectino ID.
|
||||
** Parameters conn_id - connection ID.
|
||||
** p_read_multi - pointer to the read multiple parameter.
|
||||
**
|
||||
** Returns None
|
||||
|
|
|
@ -818,7 +818,7 @@ static void bta_gatts_send_request_cback (UINT16 conn_id,
|
|||
APPL_TRACE_ERROR("connection request on gatt_if[%d] is not interested", gatt_if);
|
||||
}
|
||||
} else {
|
||||
APPL_TRACE_ERROR("request received on unknown connectino ID: %d", conn_id);
|
||||
APPL_TRACE_ERROR("request received on unknown connection ID: %d", conn_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -501,7 +501,7 @@ void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BOOLEAN i
|
|||
**
|
||||
** Description Close a connection a remote device.
|
||||
**
|
||||
** Parameters conn_id: connectino ID to be closed.
|
||||
** Parameters conn_id: connection ID to be closed.
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
|
|
|
@ -679,7 +679,7 @@ extern void BTA_GATTC_CancelOpen(tBTA_GATTC_IF client_if, BD_ADDR remote_bda, BO
|
|||
**
|
||||
** Description Close a connection to a GATT server.
|
||||
**
|
||||
** Parameters conn_id: connectino ID to be closed.
|
||||
** Parameters conn_id: connection ID to be closed.
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
|
@ -850,7 +850,7 @@ extern tBTA_GATT_STATUS BTA_GATTC_GetNextIncludedService(UINT16 conn_id,
|
|||
** Description This function is called to read a service's characteristics of
|
||||
** the given characteritisc ID.
|
||||
**
|
||||
** Parameters conn_id - connectino ID.
|
||||
** Parameters conn_id - connection ID.
|
||||
** p_char_id - characteritic ID to read.
|
||||
**
|
||||
** Returns None
|
||||
|
@ -1010,7 +1010,7 @@ extern void BTA_GATTC_ExecuteWrite (UINT16 conn_id, BOOLEAN is_execute);
|
|||
** Description This function is called to read multiple characteristic or
|
||||
** characteristic descriptors.
|
||||
**
|
||||
** Parameters conn_id - connectino ID.
|
||||
** Parameters conn_id - connection ID.
|
||||
** p_read_multi - read multiple parameters.
|
||||
**
|
||||
** Returns None
|
||||
|
@ -1337,7 +1337,7 @@ extern void BTA_GATTS_CancelOpen(tBTA_GATTS_IF server_if, BD_ADDR remote_bda, BO
|
|||
**
|
||||
** Description Close a connection a remote device.
|
||||
**
|
||||
** Parameters conn_id: connectino ID to be closed.
|
||||
** Parameters conn_id: connection ID to be closed.
|
||||
**
|
||||
** Returns void
|
||||
**
|
||||
|
|
|
@ -59,7 +59,7 @@ tBTA_SDP_STATUS BTA_SdpEnable(tBTA_SDP_DM_CBACK *p_cback)
|
|||
tBTA_SDP_STATUS status = BTA_SDP_FAILURE;
|
||||
tBTA_SDP_API_ENABLE *p_buf;
|
||||
|
||||
APPL_TRACE_API(__FUNCTION__);
|
||||
APPL_TRACE_API("%s\n", __FUNCTION__);
|
||||
if (p_cback && FALSE == bta_sys_is_register(BTA_ID_SDP)) {
|
||||
memset(&bta_sdp_cb, 0, sizeof(tBTA_SDP_CB));
|
||||
|
||||
|
@ -95,7 +95,7 @@ tBTA_SDP_STATUS BTA_SdpSearch(BD_ADDR bd_addr, tSDP_UUID *uuid)
|
|||
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
|
||||
tBTA_SDP_API_SEARCH *p_msg;
|
||||
|
||||
APPL_TRACE_API(__FUNCTION__);
|
||||
APPL_TRACE_API("%s\n", __FUNCTION__);
|
||||
if ((p_msg = (tBTA_SDP_API_SEARCH *)GKI_getbuf(sizeof(tBTA_SDP_API_SEARCH))) != NULL) {
|
||||
p_msg->hdr.event = BTA_SDP_API_SEARCH_EVT;
|
||||
bdcpy(p_msg->bd_addr, bd_addr);
|
||||
|
@ -125,7 +125,7 @@ tBTA_SDP_STATUS BTA_SdpCreateRecordByUser(void *user_data)
|
|||
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
|
||||
tBTA_SDP_API_RECORD_USER *p_msg;
|
||||
|
||||
APPL_TRACE_API(__FUNCTION__);
|
||||
APPL_TRACE_API("%s\n", __FUNCTION__);
|
||||
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
|
||||
p_msg->hdr.event = BTA_SDP_API_CREATE_RECORD_USER_EVT;
|
||||
p_msg->user_data = user_data;
|
||||
|
@ -153,7 +153,7 @@ tBTA_SDP_STATUS BTA_SdpRemoveRecordByUser(void *user_data)
|
|||
tBTA_SDP_STATUS ret = BTA_SDP_FAILURE;
|
||||
tBTA_SDP_API_RECORD_USER *p_msg;
|
||||
|
||||
APPL_TRACE_API(__FUNCTION__);
|
||||
APPL_TRACE_API("%s\n", __FUNCTION__);
|
||||
if ((p_msg = (tBTA_SDP_API_RECORD_USER *)GKI_getbuf(sizeof(tBTA_SDP_API_RECORD_USER))) != NULL) {
|
||||
p_msg->hdr.event = BTA_SDP_API_REMOVE_RECORD_USER_EVT;
|
||||
p_msg->user_data = user_data;
|
||||
|
|
|
@ -367,8 +367,8 @@ void btc_ble_start_advertising (esp_ble_adv_params_t *ble_adv_params)
|
|||
disc_mode = BTA_DM_BLE_NON_DISCOVERABLE;
|
||||
}
|
||||
|
||||
if (!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) ||
|
||||
!API_BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) {
|
||||
if (!BLE_ISVALID_PARAM(ble_adv_params->adv_int_min, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX) ||
|
||||
!BLE_ISVALID_PARAM(ble_adv_params->adv_int_max, BTM_BLE_ADV_INT_MIN, BTM_BLE_ADV_INT_MAX)) {
|
||||
LOG_ERROR("Invalid advertisting interval parameters.\n");
|
||||
return ;
|
||||
}
|
||||
|
@ -424,8 +424,8 @@ static void btc_scan_params_callback(tGATT_IF gatt_if, tBTM_STATUS status)
|
|||
static void btc_ble_set_scan_params(esp_ble_scan_params_t *scan_params,
|
||||
tBLE_SCAN_PARAM_SETUP_CBACK scan_param_setup_cback)
|
||||
{
|
||||
if (API_BLE_ISVALID_PARAM(scan_params->scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) &&
|
||||
API_BLE_ISVALID_PARAM(scan_params->scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) &&
|
||||
if (BLE_ISVALID_PARAM(scan_params->scan_interval, BTM_BLE_SCAN_INT_MIN, BTM_BLE_SCAN_INT_MAX) &&
|
||||
BLE_ISVALID_PARAM(scan_params->scan_window, BTM_BLE_SCAN_WIN_MIN, BTM_BLE_SCAN_WIN_MAX) &&
|
||||
(scan_params->scan_type == BTM_BLE_SCAN_MODE_ACTI || scan_params->scan_type == BTM_BLE_SCAN_MODE_PASS)) {
|
||||
BTA_DmSetBleScanFilterParams(0 /*client_if*/,
|
||||
scan_params->scan_interval,
|
||||
|
@ -453,6 +453,7 @@ static void btc_search_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data
|
|||
param.scan_rst.dev_type = p_data->inq_res.device_type;
|
||||
param.scan_rst.rssi = p_data->inq_res.rssi;
|
||||
param.scan_rst.ble_addr_type = p_data->inq_res.ble_addr_type;
|
||||
param.scan_rst.ble_evt_type = p_data->inq_res.ble_evt_type;
|
||||
param.scan_rst.flag = p_data->inq_res.flag;
|
||||
memcpy(param.scan_rst.ble_adv, p_data->inq_res.p_eir,
|
||||
ESP_BLE_ADV_DATA_LEN_MAX);
|
||||
|
|
|
@ -346,15 +346,13 @@ static void btc_gattc_read_char_descr(btc_ble_gattc_args_t *arg)
|
|||
|
||||
static void btc_gattc_write_char(btc_ble_gattc_args_t *arg)
|
||||
{
|
||||
//TODO: check the write type
|
||||
tBTA_GATTC_CHAR_ID in_char_id;
|
||||
tBTA_GATTC_WRITE_TYPE write_type = BTA_GATTC_TYPE_WRITE;
|
||||
|
||||
btc_to_bta_srvc_id(&in_char_id.srvc_id, &arg->write_char.service_id);
|
||||
btc_to_bta_gatt_id(&in_char_id.char_id, &arg->write_char.char_id);
|
||||
|
||||
BTA_GATTC_WriteCharValue(arg->write_char.conn_id, &in_char_id,
|
||||
write_type,
|
||||
arg->write_char.write_type,
|
||||
arg->write_char.value_len,
|
||||
arg->write_char.value,
|
||||
arg->write_char.auth_req);
|
||||
|
@ -362,10 +360,8 @@ static void btc_gattc_write_char(btc_ble_gattc_args_t *arg)
|
|||
|
||||
static void btc_gattc_write_char_descr(btc_ble_gattc_args_t *arg)
|
||||
{
|
||||
//TODO: check the write type
|
||||
tBTA_GATTC_CHAR_DESCR_ID in_char_descr_id;
|
||||
tBTA_GATT_UNFMT descr_val;
|
||||
tBTA_GATTC_WRITE_TYPE write_type = BTA_GATTC_TYPE_WRITE;
|
||||
btc_to_bta_srvc_id(&in_char_descr_id.char_id.srvc_id, &arg->write_descr.service_id);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.char_id.char_id, &arg->write_descr.char_id);
|
||||
btc_to_bta_gatt_id(&in_char_descr_id.descr_id, &arg->write_descr.descr_id);
|
||||
|
@ -374,7 +370,7 @@ static void btc_gattc_write_char_descr(btc_ble_gattc_args_t *arg)
|
|||
descr_val.p_value = arg->write_descr.value;
|
||||
|
||||
BTA_GATTC_WriteCharDescr(arg->write_descr.conn_id, &in_char_descr_id,
|
||||
write_type, &descr_val,
|
||||
arg->write_descr.write_type, &descr_val,
|
||||
arg->write_descr.auth_req);
|
||||
}
|
||||
|
||||
|
@ -521,7 +517,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
|
|||
tBTA_GATTC_REG *reg_oper = &arg->reg_oper;
|
||||
param.reg.status = reg_oper->status;
|
||||
param.reg.gatt_if = reg_oper->client_if;
|
||||
memcpy(¶m.reg.uuid, ®_oper->app_uuid, sizeof(esp_bt_uuid_t));
|
||||
param.reg.app_id = reg_oper->app_uuid.uu.uuid16;
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_REG_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
|
@ -566,7 +562,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
|
|||
case BTA_GATTC_SEARCH_RES_EVT: {
|
||||
tBTA_GATTC_SRVC_RES *srvc_res = &arg->srvc_res;
|
||||
param.search_res.conn_id = srvc_res->conn_id;
|
||||
bta_to_btc_srvc_id(¶m.search_res.service_id, &srvc_res->service_uuid);
|
||||
bta_to_btc_srvc_id(¶m.search_res.srvc_id, &srvc_res->service_uuid);
|
||||
BTC_GATTC_CB_TO_APP(ESP_GATTC_SEARCH_RES_EVT, ¶m);
|
||||
break;
|
||||
}
|
||||
|
@ -588,7 +584,7 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
|
|||
case BTA_GATTC_NOTIF_EVT: {
|
||||
tBTA_GATTC_NOTIFY *notify = &arg->notify;
|
||||
param.notify.conn_id = notify->conn_id;
|
||||
memcpy(¶m.notify.bda, ¬ify->bda, sizeof(esp_bd_addr_t));
|
||||
memcpy(¶m.notify.remote_bda, ¬ify->bda, sizeof(esp_bd_addr_t));
|
||||
bta_to_btc_srvc_id(¶m.notify.srvc_id, ¬ify->char_id.srvc_id);
|
||||
bta_to_btc_gatt_id(¶m.notify.char_id, ¬ify->char_id.char_id);
|
||||
bta_to_btc_gatt_id(¶m.notify.descr_id, ¬ify->descr_type);
|
||||
|
|
|
@ -382,7 +382,7 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
|
|||
param.del.gatt_if = p_data->srvc_oper.server_if;
|
||||
param.del.service_handle = p_data->srvc_oper.service_id;
|
||||
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELELTE_EVT, ¶m);
|
||||
BTC_GATTS_CB_TO_APP(ESP_GATTS_DELETE_EVT, ¶m);
|
||||
break;
|
||||
case BTA_GATTS_START_EVT:
|
||||
param.start.status = p_data->srvc_oper.status;
|
||||
|
@ -433,11 +433,4 @@ void btc_gatts_cb_handler(btc_msg_t *msg)
|
|||
}
|
||||
|
||||
btc_gatts_cb_param_copy_free(msg, p_data);
|
||||
|
||||
//ets_printf("yyy\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#include "esp_bt_defs.h"
|
||||
#include "esp_gap_ble_api.h"
|
||||
|
||||
#define BLE_ISVALID_PARAM(x, min, max) (((x) >= (min) && (x) <= (max)) || ((x) == ESP_BLE_CONN_PARAM_UNDEF))
|
||||
|
||||
typedef enum {
|
||||
BTC_GAP_BLE_ACT_CFG_ADV_DATA = 0,
|
||||
BTC_GAP_BLE_ACT_SET_SCAN_PARAM,
|
||||
|
|
|
@ -131,6 +131,7 @@ typedef union {
|
|||
esp_gatt_srvc_id_t service_id;
|
||||
esp_gatt_id_t char_id;
|
||||
uint8_t *value;
|
||||
esp_gatt_write_type_t write_type;
|
||||
esp_gatt_auth_req_t auth_req;
|
||||
} write_char;
|
||||
//BTC_GATTC_ACT_WRITE_CHAR_DESCR,
|
||||
|
@ -141,6 +142,7 @@ typedef union {
|
|||
esp_gatt_id_t char_id;
|
||||
esp_gatt_id_t descr_id;
|
||||
uint8_t *value;
|
||||
esp_gatt_write_type_t write_type;
|
||||
esp_gatt_auth_req_t auth_req;
|
||||
} write_descr;
|
||||
//BTC_GATTC_ACT_PREPARE_WRITE,
|
||||
|
|
|
@ -22,13 +22,11 @@
|
|||
#include <stdio.h>
|
||||
#include "bt_types.h"
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
#include "esp_log.h"
|
||||
|
||||
#ifdef CONFIG_BT_USE_ETS_PRINT
|
||||
#define BT_PRINTF ets_printf
|
||||
#else
|
||||
#define BT_PRINTF printf
|
||||
#endif
|
||||
#define TAG "BT"
|
||||
|
||||
#define BT_PRINTF(fmt, ...) ESP_LOGE(TAG, fmt, ##__VA_ARGS__)
|
||||
|
||||
#ifndef assert
|
||||
#define assert(x) do { if (!(x)) BT_PRINTF("bt host error %s %u\n", __FILE__, __LINE__); } while (0)
|
||||
|
@ -273,7 +271,7 @@ inline void trc_dump_buffer(uint8_t *prefix, uint8_t *data, uint16_t len)
|
|||
#ifndef LOG_LEVEL
|
||||
#define LOG_LEVEL LOG_LEVEL_INFO
|
||||
#endif
|
||||
#define LOG_ERROR(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_ERROR) printf(fmt,## args);} while(0)
|
||||
#define LOG_ERROR(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_ERROR) BT_PRINTF(fmt,## args);} while(0)
|
||||
#define LOG_WARN(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_WARN) BT_PRINTF(fmt,## args);} while(0)
|
||||
#define LOG_INFO(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_INFO) BT_PRINTF(fmt,## args);} while(0)
|
||||
#define LOG_DEBUG(fmt, args...) do {if (LOG_LEVEL >= LOG_LEVEL_DEBUG) BT_PRINTF(fmt,## args);} while(0)
|
||||
|
|
|
@ -56,12 +56,12 @@ enum {
|
|||
#define BTU_TASK_STACK_SIZE 4096
|
||||
#define BTU_TASK_PRIO (configMAX_PRIORITIES - 1)
|
||||
#define BTU_TASK_NAME "btuT"
|
||||
#define BTU_QUEUE_NUM 30
|
||||
#define BTU_QUEUE_NUM 50
|
||||
|
||||
#define BTC_TASK_QUEUE_NUM 20
|
||||
#define BTC_TASK_STACK_SIZE CONFIG_BTC_TASK_STACK_SIZE //by menuconfig
|
||||
#define BTC_TASK_NAME "btcT"
|
||||
#define BTC_TASK_PRIO (configMAX_PRIORITIES - 5)
|
||||
#define BTC_TASK_QUEUE_NUM 20
|
||||
|
||||
void btu_task_post(uint32_t sig);
|
||||
void hci_host_task_post(void);
|
||||
|
|
|
@ -441,7 +441,7 @@ BOOLEAN btm_ble_start_auto_conn(BOOLEAN start)
|
|||
** p_select_cback: callback function to return application
|
||||
** selection.
|
||||
**
|
||||
** Returns BOOLEAN: selective connectino procedure is started.
|
||||
** Returns BOOLEAN: selective connection procedure is started.
|
||||
**
|
||||
*******************************************************************************/
|
||||
BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK *p_select_cback)
|
||||
|
@ -523,7 +523,7 @@ BOOLEAN btm_ble_start_select_conn(BOOLEAN start, tBTM_BLE_SEL_CBACK *p_select_cb
|
|||
** p_select_cback: callback function to return application
|
||||
** selection.
|
||||
**
|
||||
** Returns BOOLEAN: selective connectino procedure is started.
|
||||
** Returns BOOLEAN: selective connection procedure is started.
|
||||
**
|
||||
*******************************************************************************/
|
||||
void btm_ble_initiate_select_conn(BD_ADDR bda)
|
||||
|
|
|
@ -1353,11 +1353,10 @@ tBTM_STATUS BTM_BleWriteAdvData(tBTM_BLE_AD_MASK data_mask, tBTM_BLE_ADV_DATA *p
|
|||
BOOLEAN BTM_BleSetRandAddress(BD_ADDR rand_addr)
|
||||
{
|
||||
BOOLEAN set_flag = false;
|
||||
UINT8 len = sizeof(rand_addr);
|
||||
if (len != BD_ADDR_LEN) {
|
||||
APPL_TRACE_ERROR("Invalid random adress");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rand_addr == NULL)
|
||||
return set_flag;
|
||||
|
||||
//send the set random address to the controller
|
||||
set_flag = btsnd_hcic_ble_set_random_addr(rand_addr);
|
||||
return set_flag;
|
||||
|
|
|
@ -496,7 +496,7 @@ tGATT_STATUS attp_cl_send_cmd(tGATT_TCB *p_tcb, UINT16 clcb_idx, UINT8 cmd_code,
|
|||
** Description This function sends the client request or confirmation message
|
||||
** to server.
|
||||
**
|
||||
** Parameter p_tcb: pointer to the connectino control block.
|
||||
** Parameter p_tcb: pointer to the connection control block.
|
||||
** clcb_idx: clcb index
|
||||
** op_code: message op code.
|
||||
** p_msg: pointer to message parameters structure.
|
||||
|
|
|
@ -167,7 +167,7 @@ typedef UINT8 tBTM_BLE_SFP;
|
|||
#define BTM_BLE_CONN_INT_MIN_DEF 24 /* recommended min: 30ms = 24 * 1.25 */
|
||||
#endif
|
||||
|
||||
/* default connectino interval max */
|
||||
/* default connection interval max */
|
||||
#ifndef BTM_BLE_CONN_INT_MAX_DEF
|
||||
#define BTM_BLE_CONN_INT_MAX_DEF 40 /* recommended max: 50 ms = 56 * 1.25 */
|
||||
#endif
|
||||
|
|
|
@ -115,7 +115,7 @@ static struct osi_funcs_t osi_funcs = {
|
|||
._mutex_create = mutex_create_wrapper,
|
||||
._mutex_lock = mutex_lock_wrapper,
|
||||
._mutex_unlock = mutex_unlock_wrapper,
|
||||
._read_efuse_mac = system_efuse_read_mac,
|
||||
._read_efuse_mac = esp_efuse_read_mac,
|
||||
};
|
||||
|
||||
static void bt_controller_task(void *pvParam)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit a0f2d0a961eef1a4926218b26b77011a89e8188f
|
||||
Subproject commit 91657e0c4025f5a694b0a89f449c347b0f2fdf79
|
359
components/driver/include/driver/pcnt.h
Normal file
359
components/driver/include/driver/pcnt.h
Normal file
|
@ -0,0 +1,359 @@
|
|||
#ifndef __PCNT_H__
|
||||
#define __PCNT_H__
|
||||
|
||||
#include <esp_types.h>
|
||||
#include "esp_intr.h"
|
||||
#include "esp_err.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/xtensa_api.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/pcnt_reg.h"
|
||||
#include "soc/pcnt_struct.h"
|
||||
#include "soc/gpio_sig_map.h"
|
||||
#include "driver/gpio.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define PCNT_PIN_NOT_USED (-1) /*!< Pin are not used */
|
||||
|
||||
typedef enum {
|
||||
PCNT_MODE_KEEP = 0, /*!< Control mode: won't change counter mode*/
|
||||
PCNT_MODE_REVERSE = 1, /*!< Control mode: invert counter mode(increase -> decrease, decrease -> increase);*/
|
||||
PCNT_MODE_DISABLE = 2, /*!< Control mode: Inhibit counter(counter value will not change in this condition)*/
|
||||
PCNT_MODE_MAX
|
||||
} pcnt_ctrl_mode_t;
|
||||
|
||||
typedef enum {
|
||||
PCNT_COUNT_DIS = 0, /*!< Counter mode: Decrease counter value*/
|
||||
PCNT_COUNT_INC = 1, /*!< Counter mode: Increase counter value*/
|
||||
PCNT_COUNT_DEC = 2, /*!< Counter mode: Inhibit counter(counter value will not change in this condition)*/
|
||||
PCNT_COUNT_MAX
|
||||
} pcnt_count_mode_t;
|
||||
|
||||
typedef enum {
|
||||
PCNT_UNIT_0 = 0, /*!< PCNT unit0 */
|
||||
PCNT_UNIT_1 = 1, /*!< PCNT unit1 */
|
||||
PCNT_UNIT_2 = 2, /*!< PCNT unit2 */
|
||||
PCNT_UNIT_3 = 3, /*!< PCNT unit3 */
|
||||
PCNT_UNIT_4 = 4, /*!< PCNT unit4 */
|
||||
PCNT_UNIT_5 = 5, /*!< PCNT unit5 */
|
||||
PCNT_UNIT_6 = 6, /*!< PCNT unit6 */
|
||||
PCNT_UNIT_7 = 7, /*!< PCNT unit7 */
|
||||
PCNT_UNIT_MAX,
|
||||
} pcnt_unit_t;
|
||||
|
||||
typedef enum{
|
||||
PCNT_CHANNEL_0 = 0x00, /*!< PCNT channel0 */
|
||||
PCNT_CHANNEL_1 = 0x01, /*!< PCNT channel1 */
|
||||
PCNT_CHANNEL_MAX,
|
||||
} pcnt_channel_t;
|
||||
|
||||
typedef enum {
|
||||
PCNT_EVT_L_LIM = 0, /*!< PCNT watch point event: Minimum counter value */
|
||||
PCNT_EVT_H_LIM = 1, /*!< PCNT watch point event: Maximum counter value*/
|
||||
PCNT_EVT_THRES_0 = 2, /*!< PCNT watch point event: threshold0 value event*/
|
||||
PCNT_EVT_THRES_1 = 3, /*!< PCNT watch point event: threshold1 value event*/
|
||||
PCNT_EVT_ZERO = 4, /*!< PCNT watch point event: counter value zero event*/
|
||||
PCNT_EVT_MAX
|
||||
} pcnt_evt_type_t;
|
||||
|
||||
/**
|
||||
* @brief Pulse Counter configure struct
|
||||
*/
|
||||
typedef struct {
|
||||
int pulse_gpio_num; /*!< Pulse input gpio_num, if you want to use gpio16, pulse_gpio_num = 16, a negative value will be ignored */
|
||||
int ctrl_gpio_num; /*!< Contol signal input gpio_num, a negative value will be ignored*/
|
||||
pcnt_ctrl_mode_t lctrl_mode; /*!< PCNT low control mode*/
|
||||
pcnt_ctrl_mode_t hctrl_mode; /*!< PCNT high control mode*/
|
||||
pcnt_count_mode_t pos_mode; /*!< PCNT positive edge count mode*/
|
||||
pcnt_count_mode_t neg_mode; /*!< PCNT negative edge count mode*/
|
||||
int16_t counter_h_lim; /*!< Maximum counter value */
|
||||
int16_t counter_l_lim; /*!< Minimum counter value */
|
||||
pcnt_unit_t unit; /*!< PCNT unit number */
|
||||
pcnt_channel_t channel; /*!< the PCNT channel */
|
||||
} pcnt_config_t;
|
||||
|
||||
/**
|
||||
* @brief Configure Pulse Counter unit
|
||||
*
|
||||
* @param pcnt_config Pointer of Pulse Counter unit configure parameter
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_unit_config(pcnt_config_t *pcnt_config);
|
||||
|
||||
/**
|
||||
* @brief Get pulse counter value
|
||||
*
|
||||
* @param pcnt_unit Pulse Counter unit number
|
||||
* @param count Pointer to accept counter value
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_get_counter_value(pcnt_unit_t pcnt_unit, int16_t* count);
|
||||
|
||||
/**
|
||||
* @brief Pause PCNT counter of PCNT unit
|
||||
*
|
||||
* @param pcnt_unit PCNT unit number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_counter_pause(pcnt_unit_t pcnt_unit);
|
||||
|
||||
/**
|
||||
* @brief Resume counting for PCNT counter
|
||||
*
|
||||
* @param pcnt_unit PCNT unit number, select from pcnt_unit_t
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_counter_resume(pcnt_unit_t pcnt_unit);
|
||||
|
||||
/**
|
||||
* @brief Clear and reset PCNT counter value to zero
|
||||
*
|
||||
* @param pcnt_unit PCNT unit number, select from pcnt_unit_t
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_counter_clear(pcnt_unit_t pcnt_unit);
|
||||
|
||||
/**
|
||||
* @brief Enable PCNT interrupt for PCNT unit
|
||||
* @note
|
||||
* Each Pulse counter unit has five watch point events that share the same interrupt.
|
||||
* Configure events with pcnt_event_enable() and pcnt_event_disable()
|
||||
*
|
||||
* @param pcnt_unit PCNT unit number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_intr_enable(pcnt_unit_t pcnt_unit);
|
||||
|
||||
/**
|
||||
* @brief Disable PCNT interrupt for PCNT uint
|
||||
*
|
||||
* @param pcnt_unit PCNT unit number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_intr_disable(pcnt_unit_t pcnt_unit);
|
||||
|
||||
/**
|
||||
* @brief Enable PCNT event of PCNT unit
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param evt_type Watch point event type.
|
||||
* All enabled events share the same interrupt (one interrupt per pulse counter unit).
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_event_enable(pcnt_unit_t unit, pcnt_evt_type_t evt_type);
|
||||
|
||||
/**
|
||||
* @brief Disable PCNT event of PCNT unit
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param evt_type Watch point event type.
|
||||
* All enabled events share the same interrupt (one interrupt per pulse counter unit).
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_event_disable(pcnt_unit_t unit, pcnt_evt_type_t evt_type);
|
||||
|
||||
/**
|
||||
* @brief Set PCNT event value of PCNT unit
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param evt_type Watch point event type.
|
||||
* All enabled events share the same interrupt (one interrupt per pulse counter unit).
|
||||
*
|
||||
* @param value Counter value for PCNT event
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_set_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t value);
|
||||
|
||||
/**
|
||||
* @brief Get PCNT event value of PCNT unit
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param evt_type Watch point event type.
|
||||
* All enabled events share the same interrupt (one interrupt per pulse counter unit).
|
||||
* @param value Pointer to accept counter value for PCNT event
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t *value);
|
||||
|
||||
/**
|
||||
* @brief Register PCNT interrupt handler, the handler is an ISR.
|
||||
* The handler will be attached to the same CPU core that this function is running on.
|
||||
* @note
|
||||
* Users should know that which CPU is running and then pick a INUM that is not used by system.
|
||||
* We can find the information of INUM and interrupt level in soc.h.
|
||||
*
|
||||
* @param pcnt_intr_num PCNT interrupt number, check the info in soc.h, and please see the core-isa.h for more details
|
||||
* @param fn Interrupt handler function.
|
||||
* @note
|
||||
* Note that the handler function MUST be defined with attribution of "IRAM_ATTR".
|
||||
* @param arg Parameter for handler function
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Function pointer error.
|
||||
*/
|
||||
esp_err_t pcnt_isr_register(uint32_t pcnt_intr_num, void (*fn)(void*), void * arg);
|
||||
|
||||
/**
|
||||
* @brief Configure PCNT pulse signal input pin and control input pin
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param channel PCNT channel number
|
||||
* @param pulse_io Pulse signal input GPIO
|
||||
* @note
|
||||
* Set to PCNT_PIN_NOT_USED if unused.
|
||||
* @param ctrl_io Control signal input GPIO
|
||||
* @note
|
||||
* Set to PCNT_PIN_NOT_USED if unused.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_set_pin(pcnt_unit_t unit, pcnt_channel_t channel, int pulse_io, int ctrl_io);
|
||||
|
||||
/**
|
||||
* @brief Enable PCNT input filter
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_filter_enable(pcnt_unit_t unit);
|
||||
|
||||
/**
|
||||
* @brief Disable PCNT input filter
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_filter_disable(pcnt_unit_t unit);
|
||||
|
||||
/**
|
||||
* @brief Set PCNT filter value
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param filter_val PCNT signal filter value, counter in APB_CLK cycles.
|
||||
* Any pulses lasting shorter than this will be ignored when the filter is enabled.
|
||||
* @note
|
||||
* filter_val is a 10-bit value, so the maximum filter_val should be limited to 1023.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_set_filter_value(pcnt_unit_t unit, uint16_t filter_val);
|
||||
|
||||
/**
|
||||
* @brief Get PCNT filter value
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param filter_val Pointer to accept PCNT filter value.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_get_filter_value(pcnt_unit_t unit, uint16_t *filter_val);
|
||||
|
||||
/**
|
||||
* @brief Set PCNT counter mode
|
||||
*
|
||||
* @param unit PCNT unit number
|
||||
* @param channel PCNT channel number
|
||||
* @param pos_mode Counter mode when detecting positive edge
|
||||
* @param neg_mode Counter mode when detecting negative edge
|
||||
* @param hctrl_mode Counter mode when control signal is high level
|
||||
* @param lctrl_mode Counter mode when control signal is low level
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t pcnt_set_mode(pcnt_unit_t unit, pcnt_channel_t channel,
|
||||
pcnt_count_mode_t pos_mode, pcnt_count_mode_t neg_mode,
|
||||
pcnt_ctrl_mode_t hctrl_mode, pcnt_ctrl_mode_t lctrl_mode);
|
||||
|
||||
|
||||
/**
|
||||
* @addtogroup pcnt-examples
|
||||
*
|
||||
* @{
|
||||
*
|
||||
* EXAMPLE OF PCNT CONFIGURATION
|
||||
* ==============================
|
||||
* @code{c}
|
||||
* //1. Config PCNT unit
|
||||
* pcnt_config_t pcnt_config = {
|
||||
* .pulse_gpio_num = 4, //set gpio4 as pulse input gpio
|
||||
* .ctrl_gpio_num = 5, //set gpio5 as control gpio
|
||||
* .channel = PCNT_CHANNEL_0, //use unit 0 channel 0
|
||||
* .lctrl_mode = PCNT_MODE_REVERSE, //when control signal is low ,reverse the primary counter mode(inc->dec/dec->inc)
|
||||
* .hctrl_mode = PCNT_MODE_KEEP, //when control signal is high,keep the primary counter mode
|
||||
* .pos_mode = PCNT_COUNT_INC, //increment the counter
|
||||
* .neg_mode = PCNT_COUNT_DIS, //keep the counter value
|
||||
* .counter_h_lim = 10,
|
||||
* .counter_l_lim = -10,
|
||||
* };
|
||||
* pcnt_unit_config(&pcnt_config); //init unit
|
||||
* @endcode
|
||||
*
|
||||
* EXAMPLE OF PCNT EVENT SETTING
|
||||
* ==============================
|
||||
* @code{c}
|
||||
* //2. Configure PCNT watchpoint event.
|
||||
* pcnt_set_event_value(PCNT_UNIT_0, PCNT_EVT_THRES_1, 5); //set thres1 value
|
||||
* pcnt_event_enable(PCNT_UNIT_0, PCNT_EVT_THRES_1); //enable thres1 event
|
||||
* @endcode
|
||||
*
|
||||
* For more examples please refer to PCNT example code in IDF_PATH/examples
|
||||
*
|
||||
* @}
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
|
@ -40,6 +40,7 @@ typedef enum {
|
|||
PERIPH_UHCI0_MODULE,
|
||||
PERIPH_UHCI1_MODULE,
|
||||
PERIPH_RMT_MODULE,
|
||||
PERIPH_PCNT_MODULE,
|
||||
} periph_module_t;
|
||||
|
||||
/**
|
||||
|
|
349
components/driver/include/driver/timer.h
Normal file
349
components/driver/include/driver/timer.h
Normal file
|
@ -0,0 +1,349 @@
|
|||
// Copyright 2010-2016 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 _DRIVER_TIMER_H_
|
||||
#define _DRIVER_TIMER_H_
|
||||
#include "esp_err.h"
|
||||
#include "esp_attr.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/timer_group_reg.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define TIMER_BASE_CLK (APB_CLK_FREQ)
|
||||
/**
|
||||
* @brief Selects a Timer-Group out of 2 available groups
|
||||
*/
|
||||
typedef enum {
|
||||
TIMER_GROUP_0 = 0, /*!<Hw timer group 0*/
|
||||
TIMER_GROUP_1 = 1, /*!<Hw timer group 1*/
|
||||
TIMER_GROUP_MAX,
|
||||
} timer_group_t;
|
||||
|
||||
/**
|
||||
* @brief Select a hardware timer from timer groups
|
||||
*/
|
||||
typedef enum {
|
||||
TIMER_0 = 0, /*!<Select timer0 of GROUPx*/
|
||||
TIMER_1 = 1, /*!<Select timer1 of GROUPx*/
|
||||
TIMER_MAX,
|
||||
} timer_idx_t;
|
||||
|
||||
/**
|
||||
* @brief Decides the direction of counter
|
||||
*/
|
||||
typedef enum {
|
||||
TIMER_COUNT_DOWN = 0, /*!< Descending Count from cnt.high|cnt.low*/
|
||||
TIMER_COUNT_UP = 1, /*!< Ascending Count from Zero*/
|
||||
TIMER_COUNT_MAX
|
||||
} timer_count_dir_t;
|
||||
|
||||
/**
|
||||
* @brief Decides whether timer is on or paused
|
||||
*/
|
||||
typedef enum {
|
||||
TIMER_PAUSE = 0, /*!<Pause timer counter*/
|
||||
TIMER_START = 1, /*!<Start timer counter*/
|
||||
} timer_start_t;
|
||||
|
||||
/**
|
||||
* @brief Decides whether to enable alarm mode
|
||||
*/
|
||||
typedef enum {
|
||||
TIMER_ALARM_DIS = 0, /*!< Disable timer alarm*/
|
||||
TIMER_ALARM_EN = 1, /*!< Enable timer alarm*/
|
||||
TIMER_ALARM_MAX
|
||||
} timer_alarm_t;
|
||||
|
||||
/**
|
||||
* @brief Select interrupt type if running in alarm mode.
|
||||
*/
|
||||
typedef enum {
|
||||
TIMER_INTR_LEVEL = 0, /*!< Interrupt mode: level mode*/
|
||||
//TIMER_INTR_EDGE = 1, /*!< Interrupt mode: edge mode, Not supported Now*/
|
||||
TIMER_INTR_MAX
|
||||
} timer_intr_mode_t;
|
||||
|
||||
/**
|
||||
* @brief Select if Alarm needs to be loaded by software or automatically reload by hardware.
|
||||
*/
|
||||
typedef enum {
|
||||
TIMER_AUTORELOAD_DIS = 0, /*!< Disable auto-reload: hardware will not load counter value after an alarm event*/
|
||||
TIMER_AUTORELOAD_EN = 1, /*!< Enable auto-reload: hardware will load counter value after an alarm event*/
|
||||
TIMER_AUTORELOAD_MAX,
|
||||
} timer_autoreload_t;
|
||||
|
||||
/**
|
||||
* @brief timer configure struct
|
||||
*/
|
||||
typedef struct {
|
||||
bool alarm_en; /*!< Timer alarm enable */
|
||||
bool counter_en; /*!< Counter enable */
|
||||
timer_count_dir_t counter_dir; /*!< Counter direction */
|
||||
timer_intr_mode_t intr_type; /*!< Interrupt mode */
|
||||
bool auto_reload; /*!< Timer auto-reload */
|
||||
uint16_t divider; /*!< Counter clock divider*/
|
||||
} timer_config_t;
|
||||
|
||||
/**
|
||||
* @brief Read the counter value of hardware timer.
|
||||
*
|
||||
* @param group_num Timer group, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param timer_val Pointer to accept timer counter value.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_get_counter_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t* timer_val);
|
||||
|
||||
/**
|
||||
* @brief Read the counter value of hardware timer, in unit of a given scale.
|
||||
*
|
||||
* @param group_num Timer group, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param time Pointer, type of double*, to accept timer counter value, in seconds.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_get_counter_time_sec(timer_group_t group_num, timer_idx_t timer_num, double* time);
|
||||
|
||||
/**
|
||||
* @brief Set counter value to hardware timer.
|
||||
*
|
||||
* @param group_num Timer group, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param load_val Counter value to write to the hardware timer.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_set_counter_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t load_val);
|
||||
|
||||
/**
|
||||
* @brief Start the counter of hardware timer.
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_start(timer_group_t group_num, timer_idx_t timer_num);
|
||||
|
||||
/**
|
||||
* @brief Pause the counter of hardware timer.
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_pause(timer_group_t group_num, timer_idx_t timer_num);
|
||||
|
||||
/**
|
||||
* @brief Set counting mode for hardware timer.
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param counter_dir Counting direction of timer, count-up or count-down
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_set_counter_mode(timer_group_t group_num, timer_idx_t timer_num, timer_count_dir_t counter_dir);
|
||||
|
||||
/**
|
||||
* @brief Enable or disable counter reload function when alarm event occurs.
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param reload Counter reload mode.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_set_auto_reload(timer_group_t group_num, timer_idx_t timer_num, timer_autoreload_t reload);
|
||||
|
||||
/**
|
||||
* @brief Set hardware timer source clock divider. Timer groups clock are divider from APB clock.
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param divider Timer clock divider value.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_set_divider(timer_group_t group_num, timer_idx_t timer_num, uint16_t divider);
|
||||
|
||||
/**
|
||||
* @brief Set timer alarm value.
|
||||
*
|
||||
* @param group_num Timer group, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param alarm_value A 64-bit value to set the alarm value.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_set_alarm_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t alarm_value);
|
||||
|
||||
/**
|
||||
* @brief Get timer alarm value.
|
||||
*
|
||||
* @param group_num Timer group, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param alarm_value Pointer of A 64-bit value to accept the alarm value.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_get_alarm_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t* alarm_value);
|
||||
|
||||
/**
|
||||
* @brief Get timer alarm value.
|
||||
*
|
||||
* @param group_num Timer group, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param alarm_en To enable or disable timer alarm function.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_set_alarm(timer_group_t group_num, timer_idx_t timer_num, timer_alarm_t alarm_en);
|
||||
|
||||
|
||||
/**
|
||||
* @brief register Timer interrupt handler, the handler is an ISR.
|
||||
* The handler will be attached to the same CPU core that this function is running on.
|
||||
* @note
|
||||
* Users should know that which CPU is running and then pick a INUM that is not used by system.
|
||||
* We can find the information of INUM and interrupt level in soc.h.
|
||||
*
|
||||
* @param group_num Timer group number
|
||||
* @param timer_num Timer index of timer group
|
||||
* @param timer_intr_num TIMER interrupt number, check the info in soc.h, and please see the core-isa.h for more details
|
||||
* @param intr_type Timer interrupt type
|
||||
* @param fn Interrupt handler function.
|
||||
* @note
|
||||
* Code inside the handler function can only call functions in IRAM, so cannot call other timer APIs.
|
||||
* Use direct register access to access timers from inside the ISR.
|
||||
*
|
||||
* @param arg Parameter for handler function
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Function pointer error.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_isr_register(timer_group_t group_num, timer_idx_t timer_num, int timer_intr_num, timer_intr_mode_t intr_type, void (*fn)(void*), void * arg);
|
||||
|
||||
/** @brief Initializes and configure the timer.
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param config Pointer to timer initialization parameters.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_init(timer_group_t group_num, timer_idx_t timer_num, timer_config_t* config);
|
||||
|
||||
/** @brief Get timer configure value.
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index, 0 for hw_timer[0] & 1 for hw_timer[1]
|
||||
* @param config Pointer of struct to accept timer parameters.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_get_config(timer_group_t group_num, timer_idx_t timer_num, timer_config_t *config);
|
||||
|
||||
/** @brief Enable timer group interrupt, by enable mask
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param en_mask Timer interrupt enable mask.
|
||||
* Use TIMG_T0_INT_ENA_M to enable t0 interrupt
|
||||
* Use TIMG_T1_INT_ENA_M to enable t1 interrupt
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_group_intr_enable(timer_group_t group_num, uint32_t en_mask);
|
||||
|
||||
/** @brief Disable timer group interrupt, by disable mask
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param disable_mask Timer interrupt disable mask.
|
||||
* Use TIMG_T0_INT_ENA_M to disable t0 interrupt
|
||||
* Use TIMG_T1_INT_ENA_M to disable t1 interrupt
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_group_intr_disable(timer_group_t group_num, uint32_t disable_mask);
|
||||
|
||||
/** @brief Enable timer interrupt
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_enable_intr(timer_group_t group_num, timer_idx_t timer_num);
|
||||
|
||||
/** @brief Disable timer interrupt
|
||||
*
|
||||
* @param group_num Timer group number, 0 for TIMERG0 or 1 for TIMERG1
|
||||
* @param timer_num Timer index.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_ERR_INVALID_ARG Parameter error
|
||||
*/
|
||||
esp_err_t timer_disable_intr(timer_group_t group_num, timer_idx_t timer_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TIMER_H_ */
|
|
@ -167,25 +167,25 @@ esp_err_t uart_get_word_length(uart_port_t uart_num, uart_word_length_t* data_bi
|
|||
* @brief Set UART stop bits.
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param bit_num UART stop bits
|
||||
* @param stop_bits UART stop bits
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK Success
|
||||
* - ESP_FAIL Fail
|
||||
*/
|
||||
esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t bit_num);
|
||||
esp_err_t uart_set_stop_bits(uart_port_t uart_num, uart_stop_bits_t stop_bits);
|
||||
|
||||
/**
|
||||
* @brief Set UART stop bits.
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param stop_bit Pointer to accept value of UART stop bits.
|
||||
* @param stop_bits Pointer to accept value of UART stop bits.
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success, result will be put in (*stop_bit)
|
||||
*/
|
||||
esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t* stop_bit);
|
||||
esp_err_t uart_get_stop_bits(uart_port_t uart_num, uart_stop_bits_t* stop_bits);
|
||||
|
||||
/**
|
||||
* @brief Set UART parity.
|
||||
|
@ -216,13 +216,13 @@ esp_err_t uart_get_parity(uart_port_t uart_num, uart_parity_t* parity_mode);
|
|||
* @brief Set UART baud rate.
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param baud_rate UART baud-rate.
|
||||
* @param baudrate UART baud rate.
|
||||
*
|
||||
* @return
|
||||
* - ESP_FAIL Parameter error
|
||||
* - ESP_OK Success
|
||||
*/
|
||||
esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baud_rate);
|
||||
esp_err_t uart_set_baudrate(uart_port_t uart_num, uint32_t baudrate);
|
||||
|
||||
/**
|
||||
* @brief Get UART bit-rate.
|
||||
|
@ -241,7 +241,7 @@ esp_err_t uart_get_baudrate(uart_port_t uart_num, uint32_t* baudrate);
|
|||
* @brief Set UART line inverse mode
|
||||
*
|
||||
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||
* @param inverse_mask Choose the wires that need to be inversed.
|
||||
* @param inverse_mask Choose the wires that need to be inverted.
|
||||
* Inverse_mask should be chosen from UART_INVERSE_RXD/UART_INVERSE_TXD/UART_INVERSE_RTS/UART_INVERSE_CTS, combine with OR operation.
|
||||
*
|
||||
* @return
|
||||
|
|
|
@ -137,29 +137,32 @@ esp_err_t ledc_timer_config(ledc_timer_config_t* timer_conf)
|
|||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if(timer_num > LEDC_TIMER_3) {
|
||||
ESP_LOGE(LEDC_TAG, "Time Select %u", timer_num);
|
||||
ESP_LOGE(LEDC_TAG, "invalid timer #%u", timer_num);
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
esp_err_t ret = ESP_OK;
|
||||
uint32_t precision = (0x1 << bit_num); //2**depth
|
||||
uint64_t div_param = ((uint64_t) LEDC_APB_CLK_HZ << 8) / freq_hz / precision; //8bit fragment
|
||||
int timer_clk_src;
|
||||
/*Fail ,because the div_num overflow or too small*/
|
||||
if(div_param <= 256 || div_param > LEDC_DIV_NUM_HSTIMER0_V) { //REF TICK
|
||||
/*Selet the reference tick*/
|
||||
uint32_t precision = (0x1 << bit_num); // 2**depth
|
||||
// Try calculating divisor based on LEDC_APB_CLK
|
||||
ledc_clk_src_t timer_clk_src = LEDC_APB_CLK;
|
||||
// div_param is a Q10.8 fixed point value
|
||||
uint64_t div_param = ((uint64_t) LEDC_APB_CLK_HZ << 8) / freq_hz / precision;
|
||||
if (div_param < 256) {
|
||||
// divisor is too low
|
||||
ESP_LOGE(LEDC_TAG, "requested frequency and bit depth can not be achieved, try reducing freq_hz or bit_num. div_param=%d", (uint32_t) div_param);
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
if (div_param > LEDC_DIV_NUM_HSTIMER0_V) {
|
||||
// APB_CLK results in divisor which too high. Try using REF_TICK as clock source.
|
||||
timer_clk_src = LEDC_REF_TICK;
|
||||
div_param = ((uint64_t) LEDC_REF_CLK_HZ << 8) / freq_hz / precision;
|
||||
if(div_param <= 256 || div_param > LEDC_DIV_NUM_HSTIMER0_V) {
|
||||
ESP_LOGE(LEDC_TAG, "div param err,div_param=%u", (uint32_t)div_param);
|
||||
if(div_param < 256 || div_param > LEDC_DIV_NUM_HSTIMER0_V) {
|
||||
ESP_LOGE(LEDC_TAG, "requested frequency and bit depth can not be achieved, try increasing freq_hz or bit_num. div_param=%d", (uint32_t) div_param);
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
timer_clk_src = LEDC_REF_TICK;
|
||||
} else { //APB TICK
|
||||
timer_clk_src = LEDC_APB_CLK;
|
||||
}
|
||||
/*set timer parameters*/
|
||||
/*timer settings decide the clk of counter and the period of PWM*/
|
||||
// set timer parameters
|
||||
ledc_timer_set(speed_mode, timer_num, div_param, bit_num, timer_clk_src);
|
||||
/* reset timer.*/
|
||||
// reset timer
|
||||
ledc_timer_rst(speed_mode, timer_num);
|
||||
return ret;
|
||||
}
|
||||
|
@ -174,7 +177,8 @@ esp_err_t ledc_set_pin(int gpio_num, ledc_mode_t speed_mode, ledc_channel_t ledc
|
|||
if(speed_mode == LEDC_HIGH_SPEED_MODE) {
|
||||
gpio_matrix_out(gpio_num, LEDC_HS_SIG_OUT0_IDX + ledc_channel, 0, 0);
|
||||
} else {
|
||||
|
||||
ESP_LOGE(LEDC_TAG, "low speed mode is not implemented");
|
||||
return ESP_ERR_NOT_SUPPORTED;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
@ -191,6 +195,7 @@ esp_err_t ledc_channel_config(ledc_channel_config_t* ledc_conf)
|
|||
LEDC_CHECK(speed_mode < LEDC_SPEED_MODE_MAX, "ledc mode error", ESP_ERR_INVALID_ARG);
|
||||
LEDC_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "ledc GPIO output number error", ESP_ERR_INVALID_ARG);
|
||||
LEDC_CHECK(timer_select <= LEDC_TIMER_3, "ledc timer error", ESP_ERR_INVALID_ARG);
|
||||
periph_module_enable(PERIPH_LEDC_MODULE);
|
||||
esp_err_t ret = ESP_OK;
|
||||
/*set channel parameters*/
|
||||
/* channel parameters decide how the waveform looks like in one period*/
|
||||
|
|
278
components/driver/pcnt.c
Normal file
278
components/driver/pcnt.c
Normal file
|
@ -0,0 +1,278 @@
|
|||
// Copyright 2015-2016 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 "esp_log.h"
|
||||
#include "driver/pcnt.h"
|
||||
#include "driver/periph_ctrl.h"
|
||||
|
||||
#define PCNT_CHANNEL_ERR_STR "PCNT CHANNEL ERROR"
|
||||
#define PCNT_UNIT_ERR_STR "PCNT UNIT ERROR"
|
||||
#define PCNT_GPIO_ERR_STR "PCNT GPIO NUM ERROR"
|
||||
#define PCNT_ADDRESS_ERR_STR "PCNT ADDRESS ERROR"
|
||||
#define PCNT_PARAM_ERR_STR "PCNT PARAM ERROR"
|
||||
#define PCNT_COUNT_MODE_ERR_STR "PCNT COUNTER MODE ERROR"
|
||||
#define PCNT_CTRL_MODE_ERR_STR "PCNT CTRL MODE ERROR"
|
||||
#define PCNT_EVT_TYPE_ERR_STR "PCNT value type error"
|
||||
#define PCNT_CHECK(a,str,ret_val) if(!(a)) { \
|
||||
ESP_LOGE(PCNT_TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
|
||||
return (ret_val); \
|
||||
}
|
||||
|
||||
static const char* PCNT_TAG = "PCNT";
|
||||
static portMUX_TYPE pcnt_spinlock = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
#define PCNT_ENTER_CRITICAL(mux) portENTER_CRITICAL(mux)
|
||||
#define PCNT_EXIT_CRITICAL(mux) portEXIT_CRITICAL(mux)
|
||||
#define PCNT_ENTER_CRITICAL_ISR(mux) portENTER_CRITICAL_ISR(mux)
|
||||
#define PCNT_EXIT_CRITICAL_ISR(mux) portEXIT_CRITICAL_ISR(mux)
|
||||
|
||||
esp_err_t pcnt_unit_config(pcnt_config_t *pcnt_config)
|
||||
{
|
||||
uint8_t unit = pcnt_config->channel;
|
||||
uint8_t channel = pcnt_config->unit;
|
||||
int input_io = pcnt_config->pulse_gpio_num;
|
||||
int ctrl_io = pcnt_config->ctrl_gpio_num;
|
||||
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(channel < PCNT_CHANNEL_MAX, PCNT_CHANNEL_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(input_io < 0 || (GPIO_IS_VALID_GPIO(input_io) && (input_io != ctrl_io)), "PCNT pluse input io error", ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(ctrl_io < 0 || GPIO_IS_VALID_GPIO(ctrl_io), "PCNT ctrl io error", ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK((pcnt_config->pos_mode < PCNT_COUNT_MAX) && (pcnt_config->neg_mode < PCNT_COUNT_MAX), PCNT_COUNT_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK((pcnt_config->hctrl_mode < PCNT_MODE_MAX) && (pcnt_config->lctrl_mode < PCNT_MODE_MAX), PCNT_CTRL_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
/*Enalbe hardware module*/
|
||||
periph_module_enable(PERIPH_PCNT_MODULE);
|
||||
/*Set counter range*/
|
||||
pcnt_set_event_value(unit, PCNT_EVT_H_LIM, pcnt_config->counter_h_lim);
|
||||
pcnt_set_event_value(unit, PCNT_EVT_L_LIM, pcnt_config->counter_l_lim);
|
||||
/*Default value after reboot is positive, we disable these events like others*/
|
||||
pcnt_event_disable(unit, PCNT_EVT_H_LIM);
|
||||
pcnt_event_disable(unit, PCNT_EVT_L_LIM);
|
||||
pcnt_event_disable(unit, PCNT_EVT_ZERO);
|
||||
pcnt_filter_disable(unit);
|
||||
/*set pulse input and control mode*/
|
||||
pcnt_set_mode(unit, channel, pcnt_config->pos_mode, pcnt_config->neg_mode, pcnt_config->hctrl_mode, pcnt_config->lctrl_mode);
|
||||
/*Set pulse input and control pins*/
|
||||
pcnt_set_pin(unit, channel, input_io, ctrl_io);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_set_mode(pcnt_unit_t unit, pcnt_channel_t channel, pcnt_count_mode_t pos_mode, pcnt_count_mode_t neg_mode, pcnt_ctrl_mode_t hctrl_mode, pcnt_ctrl_mode_t lctrl_mode)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(channel < PCNT_CHANNEL_MAX, PCNT_CHANNEL_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK((pos_mode < PCNT_COUNT_MAX) && (neg_mode < PCNT_COUNT_MAX), PCNT_COUNT_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK((hctrl_mode < PCNT_MODE_MAX) && (lctrl_mode < PCNT_MODE_MAX), PCNT_CTRL_MODE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
|
||||
if(channel == 0) {
|
||||
PCNT.conf_unit[unit].conf0.ch0_pos_mode = pos_mode;
|
||||
PCNT.conf_unit[unit].conf0.ch0_neg_mode = neg_mode;
|
||||
PCNT.conf_unit[unit].conf0.ch0_hctrl_mode = hctrl_mode;
|
||||
PCNT.conf_unit[unit].conf0.ch0_lctrl_mode = lctrl_mode;
|
||||
} else {
|
||||
PCNT.conf_unit[unit].conf0.ch1_pos_mode = pos_mode;
|
||||
PCNT.conf_unit[unit].conf0.ch1_neg_mode = neg_mode;
|
||||
PCNT.conf_unit[unit].conf0.ch1_hctrl_mode = hctrl_mode;
|
||||
PCNT.conf_unit[unit].conf0.ch1_lctrl_mode = lctrl_mode;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_set_pin(pcnt_unit_t unit, pcnt_channel_t channel, int pulse_io, int ctrl_io)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(channel < PCNT_CHANNEL_MAX, PCNT_CHANNEL_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(GPIO_IS_VALID_GPIO(pulse_io) || pulse_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(GPIO_IS_VALID_GPIO(ctrl_io) || ctrl_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
int input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit : PCNT_SIG_CH1_IN0_IDX + 4 * unit);
|
||||
int ctrl_sig_index = (channel == 0 ? PCNT_CTRL_CH0_IN0_IDX + 4 * unit : PCNT_CTRL_CH1_IN0_IDX + 4 * unit);
|
||||
if(pulse_io >= 0) {
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pulse_io], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(pulse_io, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(pulse_io, GPIO_PULLUP_ONLY);
|
||||
gpio_matrix_in(pulse_io, input_sig_index, 0);
|
||||
}
|
||||
if(ctrl_io >= 0) {
|
||||
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[ctrl_io], PIN_FUNC_GPIO);
|
||||
gpio_set_direction(ctrl_io, GPIO_MODE_INPUT);
|
||||
gpio_set_pull_mode(ctrl_io, GPIO_PULLUP_ONLY);
|
||||
gpio_matrix_in(ctrl_io, ctrl_sig_index, 0);
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_get_counter_value(pcnt_unit_t pcnt_unit, int16_t* count)
|
||||
{
|
||||
PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(count != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
*count = (int16_t) PCNT.cnt_unit[pcnt_unit].cnt_val;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_counter_pause(pcnt_unit_t pcnt_unit)
|
||||
{
|
||||
PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_ENTER_CRITICAL(&pcnt_spinlock);
|
||||
PCNT.ctrl.val |= BIT(PCNT_CNT_PAUSE_U0_S + (pcnt_unit * 2));
|
||||
PCNT_EXIT_CRITICAL(&pcnt_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_counter_resume(pcnt_unit_t pcnt_unit)
|
||||
{
|
||||
PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_ENTER_CRITICAL(&pcnt_spinlock);
|
||||
PCNT.ctrl.val &= (~(BIT(PCNT_CNT_PAUSE_U0_S + (pcnt_unit * 2))));
|
||||
PCNT_EXIT_CRITICAL(&pcnt_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_counter_clear(pcnt_unit_t pcnt_unit)
|
||||
{
|
||||
PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_ENTER_CRITICAL(&pcnt_spinlock);
|
||||
PCNT.ctrl.val &= (~(BIT(PCNT_PLUS_CNT_RST_U0_S + (pcnt_unit * 2))));
|
||||
PCNT_EXIT_CRITICAL(&pcnt_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_intr_enable(pcnt_unit_t pcnt_unit)
|
||||
{
|
||||
PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_ENTER_CRITICAL(&pcnt_spinlock);
|
||||
PCNT.int_ena.val |= BIT(PCNT_CNT_THR_EVENT_U0_INT_ENA_S + pcnt_unit);
|
||||
PCNT_EXIT_CRITICAL(&pcnt_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_intr_disable(pcnt_unit_t pcnt_unit)
|
||||
{
|
||||
PCNT_CHECK(pcnt_unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_ENTER_CRITICAL(&pcnt_spinlock);
|
||||
PCNT.int_ena.val &= (~(BIT(PCNT_CNT_THR_EVENT_U0_INT_ENA_S + pcnt_unit)));
|
||||
PCNT_EXIT_CRITICAL(&pcnt_spinlock);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_event_enable(pcnt_unit_t unit, pcnt_evt_type_t evt_type)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
if(evt_type == PCNT_EVT_L_LIM) {
|
||||
PCNT.conf_unit[unit].conf0.thr_l_lim_en = 1;
|
||||
} else if(evt_type == PCNT_EVT_H_LIM) {
|
||||
PCNT.conf_unit[unit].conf0.thr_h_lim_en = 1;
|
||||
} else if(evt_type == PCNT_EVT_THRES_0) {
|
||||
PCNT.conf_unit[unit].conf0.thr_thres0_en = 1;
|
||||
} else if(evt_type == PCNT_EVT_THRES_1) {
|
||||
PCNT.conf_unit[unit].conf0.thr_thres1_en = 1;
|
||||
} else if(evt_type == PCNT_EVT_ZERO) {
|
||||
PCNT.conf_unit[unit].conf0.thr_zero_en = 1;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_event_disable(pcnt_unit_t unit, pcnt_evt_type_t evt_type)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
if(evt_type == PCNT_EVT_L_LIM) {
|
||||
PCNT.conf_unit[unit].conf0.thr_l_lim_en = 0;
|
||||
} else if(evt_type == PCNT_EVT_H_LIM) {
|
||||
PCNT.conf_unit[unit].conf0.thr_h_lim_en = 0;
|
||||
} else if(evt_type == PCNT_EVT_THRES_0) {
|
||||
PCNT.conf_unit[unit].conf0.thr_thres0_en = 0;
|
||||
} else if(evt_type == PCNT_EVT_THRES_1) {
|
||||
PCNT.conf_unit[unit].conf0.thr_thres1_en = 0;
|
||||
} else if(evt_type == PCNT_EVT_ZERO) {
|
||||
PCNT.conf_unit[unit].conf0.thr_zero_en = 0;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_set_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t value)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
if(evt_type == PCNT_EVT_L_LIM) {
|
||||
PCNT.conf_unit[unit].conf2.cnt_l_lim = value;
|
||||
} else if(evt_type == PCNT_EVT_H_LIM) {
|
||||
PCNT.conf_unit[unit].conf2.cnt_h_lim = value;
|
||||
} else if(evt_type == PCNT_EVT_THRES_0) {
|
||||
PCNT.conf_unit[unit].conf1.cnt_thres0 = value;
|
||||
} else if(evt_type == PCNT_EVT_THRES_1) {
|
||||
PCNT.conf_unit[unit].conf1.cnt_thres1 = value;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_get_event_value(pcnt_unit_t unit, pcnt_evt_type_t evt_type, int16_t *value)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(evt_type < PCNT_EVT_MAX, PCNT_EVT_TYPE_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(value != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
|
||||
if(evt_type == PCNT_EVT_L_LIM) {
|
||||
*value = (int16_t) PCNT.conf_unit[unit].conf2.cnt_l_lim;
|
||||
} else if(evt_type == PCNT_EVT_H_LIM) {
|
||||
*value = (int16_t) PCNT.conf_unit[unit].conf2.cnt_h_lim;
|
||||
} else if(evt_type == PCNT_EVT_THRES_0) {
|
||||
*value = (int16_t) PCNT.conf_unit[unit].conf1.cnt_thres0;
|
||||
} else if(evt_type == PCNT_EVT_THRES_1) {
|
||||
*value = (int16_t) PCNT.conf_unit[unit].conf1.cnt_thres1;
|
||||
} else {
|
||||
*value = 0;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_set_filter_value(pcnt_unit_t unit, uint16_t filter_val)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(filter_val < 1024, PCNT_PARAM_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT.conf_unit[unit].conf0.filter_thres = filter_val;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_get_filter_value(pcnt_unit_t unit, uint16_t *filter_val)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT_CHECK(filter_val != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
|
||||
*filter_val = PCNT.conf_unit[unit].conf0.filter_thres;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_filter_enable(pcnt_unit_t unit)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT.conf_unit[unit].conf0.filter_en = 1;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_filter_disable(pcnt_unit_t unit)
|
||||
{
|
||||
PCNT_CHECK(unit < PCNT_UNIT_MAX, PCNT_UNIT_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
PCNT.conf_unit[unit].conf0.filter_en = 0;
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t pcnt_isr_register(uint32_t pcnt_intr_num, void (*fun)(void*), void * arg)
|
||||
{
|
||||
PCNT_CHECK(fun != NULL, PCNT_ADDRESS_ERR_STR, ESP_ERR_INVALID_ARG);
|
||||
ESP_INTR_DISABLE(pcnt_intr_num);
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_PCNT_INTR_SOURCE, pcnt_intr_num);
|
||||
xt_set_interrupt_handler(pcnt_intr_num, fun, arg);
|
||||
ESP_INTR_ENABLE(pcnt_intr_num);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
|
@ -93,6 +93,10 @@ void periph_module_enable(periph_module_t periph)
|
|||
SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_UHCI1_CLK_EN);
|
||||
CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_UHCI1_RST);
|
||||
break;
|
||||
case PERIPH_PCNT_MODULE:
|
||||
SET_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_PCNT_CLK_EN);
|
||||
CLEAR_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_PCNT_RST);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -103,6 +107,10 @@ void periph_module_disable(periph_module_t periph)
|
|||
{
|
||||
portENTER_CRITICAL(&periph_spinlock);
|
||||
switch(periph) {
|
||||
case PERIPH_RMT_MODULE:
|
||||
CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_RMT_CLK_EN);
|
||||
SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_RMT_RST);
|
||||
break;
|
||||
case PERIPH_LEDC_MODULE:
|
||||
CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_LEDC_CLK_EN);
|
||||
SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_LEDC_RST);
|
||||
|
@ -167,6 +175,10 @@ void periph_module_disable(periph_module_t periph)
|
|||
CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_UHCI1_CLK_EN);
|
||||
SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_UHCI1_RST);
|
||||
break;
|
||||
case PERIPH_PCNT_MODULE:
|
||||
CLEAR_PERI_REG_MASK(DPORT_PERIP_CLK_EN_REG, DPORT_PCNT_CLK_EN);
|
||||
SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG, DPORT_PCNT_RST);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
275
components/driver/timer.c
Normal file
275
components/driver/timer.c
Normal file
|
@ -0,0 +1,275 @@
|
|||
// Copyright 2015-2016 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 <string.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_intr.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/xtensa_api.h"
|
||||
#include "driver/timer.h"
|
||||
#include "driver/periph_ctrl.h"
|
||||
|
||||
static const char* TIMER_TAG = "TIMER_GROUP";
|
||||
#define TIMER_CHECK(a, str, ret_val) if (!(a)) { \
|
||||
ESP_LOGE(TIMER_TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
|
||||
return (ret_val); \
|
||||
}
|
||||
#define TIMER_GROUP_NUM_ERROR "TIMER GROUP NUM ERROR"
|
||||
#define TIMER_NUM_ERROR "HW TIMER NUM ERROR"
|
||||
#define TIMER_PARAM_ADDR_ERROR "HW TIMER PARAM ADDR ERROR"
|
||||
#define TIMER_COUNT_DIR_ERROR "HW TIMER COUNTER DIR ERROR"
|
||||
#define TIMER_AUTORELOAD_ERROR "HW TIMER AUTORELOAD ERROR"
|
||||
#define TIMER_SCALE_ERROR "HW TIMER SCALE ERROR"
|
||||
#define TIMER_ALARM_ERROR "HW TIMER ALARM ERROR"
|
||||
static timg_dev_t *TG[2] = {&TIMERG0, &TIMERG1};
|
||||
static portMUX_TYPE timer_spinlock[TIMER_GROUP_MAX] = {portMUX_INITIALIZER_UNLOCKED, portMUX_INITIALIZER_UNLOCKED};
|
||||
|
||||
#define TIMER_ENTER_CRITICAL(mux) portENTER_CRITICAL(mux);
|
||||
#define TIMER_EXIT_CRITICAL(mux) portEXIT_CRITICAL(mux);
|
||||
|
||||
esp_err_t timer_get_counter_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t* timer_val)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_val != NULL, TIMER_PARAM_ADDR_ERROR, ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].update = 1;
|
||||
*timer_val = ((uint64_t) TG[group_num]->hw_timer[timer_num].cnt_high << 32)
|
||||
| (TG[group_num]->hw_timer[timer_num].cnt_low);
|
||||
portEXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_get_counter_time_sec(timer_group_t group_num, timer_idx_t timer_num, double* time)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(time != NULL, TIMER_PARAM_ADDR_ERROR, ESP_ERR_INVALID_ARG);
|
||||
|
||||
uint64_t timer_val;
|
||||
esp_err_t err = timer_get_counter_value(group_num, timer_num, &timer_val);
|
||||
if (err == ESP_OK) {
|
||||
uint16_t div = TG[group_num]->hw_timer[timer_num].config.divider;
|
||||
*time = (double)timer_val * div / TIMER_BASE_CLK;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
esp_err_t timer_set_counter_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t load_val)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].load_high = (uint32_t) (load_val >> 32);
|
||||
TG[group_num]->hw_timer[timer_num].load_low = (uint32_t) load_val;
|
||||
TG[group_num]->hw_timer[timer_num].reload = 1;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_start(timer_group_t group_num, timer_idx_t timer_num)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].config.enable = 1;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_pause(timer_group_t group_num, timer_idx_t timer_num)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].config.enable = 0;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_set_counter_mode(timer_group_t group_num, timer_idx_t timer_num, timer_count_dir_t counter_dir)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(counter_dir < TIMER_COUNT_MAX, TIMER_COUNT_DIR_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].config.increase = counter_dir;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_set_auto_reload(timer_group_t group_num, timer_idx_t timer_num, timer_autoreload_t reload)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(reload < TIMER_AUTORELOAD_MAX, TIMER_AUTORELOAD_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].config.autoreload = reload;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_set_divider(timer_group_t group_num, timer_idx_t timer_num, uint16_t divider)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
int timer_en = TG[group_num]->hw_timer[timer_num].config.enable;
|
||||
TG[group_num]->hw_timer[timer_num].config.enable = 0;
|
||||
TG[group_num]->hw_timer[timer_num].config.divider = divider;
|
||||
TG[group_num]->hw_timer[timer_num].config.enable = timer_en;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_set_alarm_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t alarm_value)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].alarm_high = (uint32_t) (alarm_value >> 32);
|
||||
TG[group_num]->hw_timer[timer_num].alarm_low = (uint32_t) alarm_value;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_get_alarm_value(timer_group_t group_num, timer_idx_t timer_num, uint64_t* alarm_value)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(alarm_value != NULL, TIMER_PARAM_ADDR_ERROR, ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
*alarm_value = ((uint64_t) TG[group_num]->hw_timer[timer_num].alarm_high << 32)
|
||||
| (TG[group_num]->hw_timer[timer_num].alarm_low);
|
||||
portEXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_set_alarm(timer_group_t group_num, timer_idx_t timer_num, timer_alarm_t alarm_en)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(alarm_en < TIMER_ALARM_MAX, TIMER_ALARM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].config.alarm_en = alarm_en;
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_isr_register(timer_group_t group_num, timer_idx_t timer_num, int timer_intr_num,
|
||||
timer_intr_mode_t intr_type, void (*fn)(void*), void * arg)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(fn != NULL, TIMER_PARAM_ADDR_ERROR, ESP_ERR_INVALID_ARG);
|
||||
|
||||
ESP_INTR_DISABLE(timer_intr_num);
|
||||
int intr_source = 0;
|
||||
switch(group_num) {
|
||||
case TIMER_GROUP_0:
|
||||
default:
|
||||
if(intr_type == TIMER_INTR_LEVEL) {
|
||||
intr_source = ETS_TG0_T0_LEVEL_INTR_SOURCE + timer_num;
|
||||
} else {
|
||||
intr_source = ETS_TG0_T0_EDGE_INTR_SOURCE + timer_num;
|
||||
}
|
||||
break;
|
||||
case TIMER_GROUP_1:
|
||||
if(intr_type == TIMER_INTR_LEVEL) {
|
||||
intr_source = ETS_TG1_T0_LEVEL_INTR_SOURCE + timer_num;
|
||||
} else {
|
||||
intr_source = ETS_TG1_T0_EDGE_INTR_SOURCE + timer_num;
|
||||
}
|
||||
break;
|
||||
}
|
||||
intr_matrix_set(xPortGetCoreID(), intr_source, timer_intr_num);
|
||||
xt_set_interrupt_handler(timer_intr_num, fn, arg);
|
||||
ESP_INTR_ENABLE(timer_intr_num);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_init(timer_group_t group_num, timer_idx_t timer_num, timer_config_t *config)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(config != NULL, TIMER_PARAM_ADDR_ERROR, ESP_ERR_INVALID_ARG);
|
||||
|
||||
if(group_num == 0) {
|
||||
periph_module_enable(PERIPH_TIMG0_MODULE);
|
||||
} else if(group_num == 1) {
|
||||
periph_module_enable(PERIPH_TIMG1_MODULE);
|
||||
}
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->hw_timer[timer_num].config.autoreload = config->auto_reload;
|
||||
TG[group_num]->hw_timer[timer_num].config.divider = config->divider;
|
||||
TG[group_num]->hw_timer[timer_num].config.enable = config->counter_en;
|
||||
TG[group_num]->hw_timer[timer_num].config.increase = config->counter_dir;
|
||||
TG[group_num]->hw_timer[timer_num].config.alarm_en = config->alarm_en;
|
||||
TG[group_num]->hw_timer[timer_num].config.level_int_en = (config->intr_type == TIMER_INTR_LEVEL ? 1 : 0);
|
||||
TG[group_num]->hw_timer[timer_num].config.edge_int_en = (config->intr_type == TIMER_INTR_LEVEL ? 0 : 1);
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_get_config(timer_group_t group_num, timer_idx_t timer_num, timer_config_t *config)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(config != NULL, TIMER_PARAM_ADDR_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_ENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
config->alarm_en = TG[group_num]->hw_timer[timer_num].config.alarm_en;
|
||||
config->auto_reload = TG[group_num]->hw_timer[timer_num].config.autoreload;
|
||||
config->counter_dir = TG[group_num]->hw_timer[timer_num].config.increase;
|
||||
config->counter_dir = TG[group_num]->hw_timer[timer_num].config.divider;
|
||||
config->counter_en = TG[group_num]->hw_timer[timer_num].config.enable;
|
||||
if(TG[group_num]->hw_timer[timer_num].config.level_int_en) {
|
||||
config->intr_type =TIMER_INTR_LEVEL;
|
||||
}
|
||||
TIMER_EXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_group_intr_enable(timer_group_t group_num, uint32_t en_mask)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->int_ena.val |= en_mask;
|
||||
portEXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_group_intr_disable(timer_group_t group_num, uint32_t disable_mask)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
portENTER_CRITICAL(&timer_spinlock[group_num]);
|
||||
TG[group_num]->int_ena.val &= (~disable_mask);
|
||||
portEXIT_CRITICAL(&timer_spinlock[group_num]);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t timer_enable_intr(timer_group_t group_num, timer_idx_t timer_num)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
return timer_group_intr_enable(group_num, BIT(timer_num));
|
||||
}
|
||||
|
||||
esp_err_t timer_disable_intr(timer_group_t group_num, timer_idx_t timer_num)
|
||||
{
|
||||
TIMER_CHECK(group_num < TIMER_GROUP_MAX, TIMER_GROUP_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
TIMER_CHECK(timer_num < TIMER_MAX, TIMER_NUM_ERROR, ESP_ERR_INVALID_ARG);
|
||||
return timer_group_intr_disable(group_num, BIT(timer_num));
|
||||
}
|
||||
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
COMPONENT_SRCDIRS := . hwcrypto
|
||||
|
||||
LIBS := core net80211 phy rtc pp wpa smartconfig coexist wps
|
||||
LIBS := core net80211 phy rtc pp wpa smartconfig coexist wps wpa2
|
||||
|
||||
LINKER_SCRIPTS += -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld
|
||||
|
||||
|
|
|
@ -16,25 +16,8 @@
|
|||
#include "rom/ets_sys.h"
|
||||
#include "rom/uart.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
typedef enum{
|
||||
XTAL_40M = 40,
|
||||
XTAL_26M = 26,
|
||||
XTAL_24M = 24,
|
||||
XTAL_AUTO = 0
|
||||
} xtal_freq_t;
|
||||
|
||||
typedef enum{
|
||||
CPU_80M = 1,
|
||||
CPU_160M = 2,
|
||||
CPU_240M = 3,
|
||||
} cpu_freq_t;
|
||||
|
||||
extern void phy_get_romfunc_addr();
|
||||
|
||||
// TODO: these functions need to be moved from librtc to ESP-IDF
|
||||
extern void rtc_init_lite(xtal_freq_t xtal_freq);
|
||||
extern void rtc_set_cpu_freq(cpu_freq_t cpu_freq);
|
||||
#include "phy.h"
|
||||
#include "rtc.h"
|
||||
|
||||
/*
|
||||
* This function is not exposed as an API at this point,
|
||||
|
|
|
@ -117,9 +117,7 @@ void IRAM_ATTR call_start_cpu0()
|
|||
//Flush and enable icache for APP CPU
|
||||
Cache_Flush(1);
|
||||
Cache_Read_Enable(1);
|
||||
//Un-stall the app cpu; the panic handler may have stalled it.
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_APPCPU_C1_M);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_APPCPU_C0_M);
|
||||
esp_cpu_unstall(1);
|
||||
//Enable clock gating and reset the app cpu.
|
||||
SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN);
|
||||
CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_C_REG, DPORT_APPCPU_RUNSTALL);
|
||||
|
@ -155,6 +153,7 @@ void IRAM_ATTR call_start_cpu1()
|
|||
|
||||
void start_cpu0_default(void)
|
||||
{
|
||||
esp_setup_syscall_table();
|
||||
//Enable trace memory and immediately start trace.
|
||||
#if CONFIG_MEMMAP_TRACEMEM
|
||||
#if CONFIG_MEMMAP_TRACEMEM_TWOBANKS
|
||||
|
@ -175,7 +174,6 @@ void start_cpu0_default(void)
|
|||
#if CONFIG_TASK_WDT
|
||||
esp_task_wdt_init();
|
||||
#endif
|
||||
esp_setup_syscall_table();
|
||||
esp_setup_time_syscalls();
|
||||
esp_vfs_dev_uart_register();
|
||||
esp_reent_init(_GLOBAL_REENT);
|
||||
|
|
44
components/esp32/cpu_util.c
Normal file
44
components/esp32/cpu_util.c
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright 2013-2016 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 "esp_attr.h"
|
||||
#include "soc/cpu.h"
|
||||
#include "soc/soc.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
|
||||
void IRAM_ATTR esp_cpu_stall(int cpu_id)
|
||||
{
|
||||
if (cpu_id == 1) {
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_APPCPU_C1_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, 0x21<<RTC_CNTL_SW_STALL_APPCPU_C1_S);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_APPCPU_C0_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, 2<<RTC_CNTL_SW_STALL_APPCPU_C0_S);
|
||||
} else {
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_PROCPU_C1_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, 0x21<<RTC_CNTL_SW_STALL_PROCPU_C1_S);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_PROCPU_C0_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, 2<<RTC_CNTL_SW_STALL_PROCPU_C0_S);
|
||||
}
|
||||
}
|
||||
|
||||
void IRAM_ATTR esp_cpu_unstall(int cpu_id)
|
||||
{
|
||||
if (cpu_id == 1) {
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_APPCPU_C1_M);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_APPCPU_C0_M);
|
||||
} else {
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_PROCPU_C1_M);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_PROCPU_C0_M);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@
|
|||
#include "soc/dport_reg.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_deepsleep.h"
|
||||
#include "rtc.h"
|
||||
|
||||
/* Updating RTC_MEMORY_CRC_REG register via set_rtc_memory_crc()
|
||||
is not thread-safe. */
|
||||
|
@ -46,3 +47,21 @@ void RTC_IRAM_ATTR esp_default_wake_deep_sleep(void) {
|
|||
}
|
||||
|
||||
void __attribute__((weak, alias("esp_default_wake_deep_sleep"))) esp_wake_deep_sleep(void);
|
||||
|
||||
void esp_deep_sleep(uint64_t time_in_us)
|
||||
{
|
||||
rtc_set_cpu_freq(CPU_XTAL);
|
||||
if (esp_get_deep_sleep_wake_stub() == NULL) {
|
||||
esp_set_deep_sleep_wake_stub(esp_wake_deep_sleep);
|
||||
}
|
||||
uint32_t period = rtc_slowck_cali(CALI_RTC_MUX, 128);
|
||||
uint32_t cycle_l, cycle_h;
|
||||
rtc_usec2rtc(time_in_us >> 32, time_in_us, period, &cycle_h, &cycle_l);
|
||||
rtc_slp_prep_lite(1, 0);
|
||||
rtc_sleep(cycle_h, cycle_l, TIMER_EXPIRE_EN, 0);
|
||||
while (1) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void system_deep_sleep(uint64_t) __attribute__((alias("esp_deep_sleep")));
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "esp_event.h"
|
||||
#include "esp_event_loop.h"
|
||||
#include "esp_task.h"
|
||||
#include "esp_eth.h"
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
|
@ -59,6 +61,11 @@ static esp_err_t system_event_sta_connected_handle_default(system_event_t *event
|
|||
static esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_sta_got_ip_default(system_event_t *event);
|
||||
|
||||
static esp_err_t system_event_eth_start_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_eth_stop_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_eth_connected_handle_default(system_event_t *event);
|
||||
static esp_err_t system_event_eth_disconnected_handle_default(system_event_t *event);
|
||||
|
||||
static system_event_handle_t g_system_event_handle_table[] = {
|
||||
{SYSTEM_EVENT_WIFI_READY, NULL},
|
||||
{SYSTEM_EVENT_SCAN_DONE, NULL},
|
||||
|
@ -77,9 +84,74 @@ static system_event_handle_t g_system_event_handle_table[] = {
|
|||
{SYSTEM_EVENT_AP_STACONNECTED, NULL},
|
||||
{SYSTEM_EVENT_AP_STADISCONNECTED, NULL},
|
||||
{SYSTEM_EVENT_AP_PROBEREQRECVED, NULL},
|
||||
{SYSTEM_EVENT_AP_STA_GOT_IP6, NULL},
|
||||
{SYSTEM_EVENT_ETH_START, system_event_eth_start_handle_default},
|
||||
{SYSTEM_EVENT_ETH_STOP, system_event_eth_stop_handle_default},
|
||||
{SYSTEM_EVENT_ETH_CONNECTED, system_event_eth_connected_handle_default},
|
||||
{SYSTEM_EVENT_ETH_DISCONNECTED, system_event_eth_disconnected_handle_default},
|
||||
{SYSTEM_EVENT_ETH_GOT_IP, NULL},
|
||||
{SYSTEM_EVENT_MAX, NULL},
|
||||
};
|
||||
|
||||
esp_err_t system_event_eth_start_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_ip_info_t eth_ip;
|
||||
uint8_t eth_mac[6];
|
||||
|
||||
esp_eth_get_mac(eth_mac);
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, ð_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_ETH, eth_mac, ð_ip);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_eth_stop_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_ETH);
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_eth_connected_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_dhcp_status_t status;
|
||||
|
||||
tcpip_adapter_up(TCPIP_ADAPTER_IF_ETH);
|
||||
|
||||
tcpip_adapter_dhcpc_get_status(TCPIP_ADAPTER_IF_ETH, &status);
|
||||
|
||||
if (status == TCPIP_ADAPTER_DHCP_INIT) {
|
||||
|
||||
tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_ETH);
|
||||
} else if (status == TCPIP_ADAPTER_DHCP_STOPPED) {
|
||||
tcpip_adapter_ip_info_t eth_ip;
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, ð_ip);
|
||||
|
||||
if (!(ip4_addr_isany_val(eth_ip.ip) || ip4_addr_isany_val(eth_ip.netmask) || ip4_addr_isany_val(eth_ip.gw))) {
|
||||
system_event_t evt;
|
||||
|
||||
//notify event
|
||||
evt.event_id = SYSTEM_EVENT_ETH_GOT_IP;
|
||||
memcpy(&evt.event_info.got_ip.ip_info, ð_ip, sizeof(tcpip_adapter_ip_info_t));
|
||||
|
||||
esp_event_send(&evt);
|
||||
} else {
|
||||
ESP_LOGE(TAG, "invalid static ip");
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_event_eth_disconnected_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_down(TCPIP_ADAPTER_IF_ETH);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static esp_err_t system_event_sta_got_ip_default(system_event_t *event)
|
||||
{
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_set_sta_ip", esp_wifi_internal_set_sta_ip(), ESP_OK);
|
||||
|
@ -97,8 +169,8 @@ esp_err_t system_event_ap_start_handle_default(system_event_t *event)
|
|||
tcpip_adapter_ip_info_t ap_ip;
|
||||
uint8_t ap_mac[6];
|
||||
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_AP, (wifi_rxcb_t)tcpip_adapter_ap_input), ESP_OK);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(WIFI_IF_AP, ap_mac), ESP_OK);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, (wifi_rxcb_t)tcpip_adapter_ap_input), ESP_OK);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_AP, ap_mac), ESP_OK);
|
||||
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_AP, &ap_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_AP, ap_mac, &ap_ip);
|
||||
|
@ -108,7 +180,7 @@ esp_err_t system_event_ap_start_handle_default(system_event_t *event)
|
|||
|
||||
esp_err_t system_event_ap_stop_handle_default(system_event_t *event)
|
||||
{
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_AP, NULL), ESP_OK);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_AP, NULL), ESP_OK);
|
||||
|
||||
tcpip_adapter_stop(TCPIP_ADAPTER_IF_AP);
|
||||
|
||||
|
@ -120,7 +192,7 @@ esp_err_t system_event_sta_start_handle_default(system_event_t *event)
|
|||
tcpip_adapter_ip_info_t sta_ip;
|
||||
uint8_t sta_mac[6];
|
||||
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(WIFI_IF_STA, sta_mac), ESP_OK);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_mac_get", esp_wifi_get_mac(ESP_IF_WIFI_STA, sta_mac), ESP_OK);
|
||||
tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &sta_ip);
|
||||
tcpip_adapter_start(TCPIP_ADAPTER_IF_STA, sta_mac, &sta_ip);
|
||||
|
||||
|
@ -138,7 +210,7 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
|
|||
{
|
||||
tcpip_adapter_dhcp_status_t status;
|
||||
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_STA, (wifi_rxcb_t)tcpip_adapter_sta_input), ESP_OK);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, (wifi_rxcb_t)tcpip_adapter_sta_input), ESP_OK);
|
||||
|
||||
tcpip_adapter_up(TCPIP_ADAPTER_IF_STA);
|
||||
|
||||
|
@ -170,7 +242,7 @@ esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
|
|||
esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event)
|
||||
{
|
||||
tcpip_adapter_down(TCPIP_ADAPTER_IF_STA);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(WIFI_IF_STA, NULL), ESP_OK);
|
||||
WIFI_API_CALL_CHECK("esp_wifi_internal_reg_rxcb", esp_wifi_internal_reg_rxcb(ESP_IF_WIFI_STA, NULL), ESP_OK);
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
|
@ -267,6 +339,27 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
|
|||
MAC2STR(ap_probereqrecved->mac));
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_START: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_START");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_STOP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_STOP");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_CONNECTED: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_CONNECETED");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_DISCONNECTED: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_DISCONNECETED");
|
||||
break;
|
||||
}
|
||||
case SYSTEM_EVENT_ETH_GOT_IP: {
|
||||
ESP_LOGD(TAG, "SYSTEM_EVENT_ETH_GOT_IP");
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
ESP_LOGW(TAG, "no such kind of event!");
|
||||
break;
|
||||
|
|
41
components/esp32/hw_random.c
Normal file
41
components/esp32/hw_random.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright 2016 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 <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include "esp_attr.h"
|
||||
#include "soc/wdev_reg.h"
|
||||
#include "freertos/FreeRTOSConfig.h"
|
||||
#include "xtensa/core-macros.h"
|
||||
|
||||
uint32_t IRAM_ATTR esp_random(void)
|
||||
{
|
||||
/* The PRNG which implements WDEV_RANDOM register gets 2 bits
|
||||
* of extra entropy from a hardware randomness source every APB clock cycle.
|
||||
* To make sure entropy is not drained faster than it is added,
|
||||
* this function needs to wait for at least 16 APB clock cycles after reading
|
||||
* previous word. This implementation may actually wait a bit longer
|
||||
* due to extra time spent in arithmetic and branch statements.
|
||||
*/
|
||||
|
||||
static uint32_t last_ccount = 0;
|
||||
uint32_t ccount;
|
||||
do {
|
||||
ccount = XTHAL_GET_CCOUNT();
|
||||
} while (ccount - last_ccount < XT_CLOCK_FREQ / APB_CLK_FREQ * 16);
|
||||
last_ccount = ccount;
|
||||
return REG_READ(WDEV_RND_REG);
|
||||
}
|
|
@ -28,6 +28,7 @@
|
|||
#include <string.h>
|
||||
#include "hwcrypto/aes.h"
|
||||
#include "rom/aes.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include <sys/lock.h>
|
||||
|
||||
static _lock_t aes_lock;
|
||||
|
@ -36,14 +37,23 @@ void esp_aes_acquire_hardware( void )
|
|||
{
|
||||
/* newlib locks lazy initialize on ESP-IDF */
|
||||
_lock_acquire(&aes_lock);
|
||||
ets_aes_enable();
|
||||
/* Enable AES hardware */
|
||||
REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_AES);
|
||||
/* Clear reset on digital signature & secure boot units,
|
||||
otherwise AES unit is held in reset also. */
|
||||
REG_CLR_BIT(DPORT_PERI_RST_EN_REG,
|
||||
DPORT_PERI_EN_AES
|
||||
| DPORT_PERI_EN_DIGITAL_SIGNATURE
|
||||
| DPORT_PERI_EN_SECUREBOOT);
|
||||
}
|
||||
|
||||
void esp_aes_release_hardware( void )
|
||||
{
|
||||
uint8_t zero[256/8] = { 0 };
|
||||
ets_aes_setkey_enc(zero, AES256);
|
||||
ets_aes_disable();
|
||||
/* Disable AES hardware */
|
||||
REG_SET_BIT(DPORT_PERI_RST_EN_REG, DPORT_PERI_EN_AES);
|
||||
/* Don't return other units to reset, as this pulls
|
||||
reset on RSA & SHA units, respectively. */
|
||||
REG_CLR_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_AES);
|
||||
_lock_release(&aes_lock);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,242 +26,264 @@
|
|||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/lock.h>
|
||||
#include <byteswap.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "hwcrypto/sha.h"
|
||||
#include "rom/ets_sys.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/hwcrypto_reg.h"
|
||||
|
||||
|
||||
static _lock_t sha_lock;
|
||||
|
||||
void esp_sha_acquire_hardware( void )
|
||||
{
|
||||
/* newlib locks lazy initialize on ESP-IDF */
|
||||
_lock_acquire(&sha_lock);
|
||||
ets_sha_enable();
|
||||
inline static uint32_t SHA_LOAD_REG(esp_sha_type sha_type) {
|
||||
return SHA_1_LOAD_REG + sha_type * 0x10;
|
||||
}
|
||||
|
||||
void esp_sha_release_hardware( void )
|
||||
{
|
||||
/* Want to empty internal SHA buffers where possible,
|
||||
need to check if this is sufficient for this. */
|
||||
SHA_CTX zero = { 0 };
|
||||
ets_sha_init(&zero);
|
||||
ets_sha_disable();
|
||||
_lock_release(&sha_lock);
|
||||
inline static uint32_t SHA_BUSY_REG(esp_sha_type sha_type) {
|
||||
return SHA_1_BUSY_REG + sha_type * 0x10;
|
||||
}
|
||||
|
||||
/* Generic esp_shaX_update implementation */
|
||||
static void esp_sha_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen, size_t block_size)
|
||||
inline static uint32_t SHA_START_REG(esp_sha_type sha_type) {
|
||||
return SHA_1_START_REG + sha_type * 0x10;
|
||||
}
|
||||
|
||||
inline static uint32_t SHA_CONTINUE_REG(esp_sha_type sha_type) {
|
||||
return SHA_1_CONTINUE_REG + sha_type * 0x10;
|
||||
}
|
||||
|
||||
/* Single lock for SHA engine memory block
|
||||
*/
|
||||
static _lock_t memory_block_lock;
|
||||
|
||||
typedef struct {
|
||||
_lock_t lock;
|
||||
bool in_use;
|
||||
} sha_engine_state;
|
||||
|
||||
/* Pointer to state of each concurrent SHA engine.
|
||||
|
||||
Indexes:
|
||||
0 = SHA1
|
||||
1 = SHA2_256
|
||||
2 = SHA2_384 or SHA2_512
|
||||
*/
|
||||
static sha_engine_state engine_states[3];
|
||||
|
||||
/* Index into the sha_engine_state array */
|
||||
inline static size_t sha_engine_index(esp_sha_type type) {
|
||||
switch(type) {
|
||||
case SHA1:
|
||||
return 0;
|
||||
case SHA2_256:
|
||||
return 1;
|
||||
default:
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return digest length (in bytes) for a given SHA type */
|
||||
inline static size_t sha_length(esp_sha_type type) {
|
||||
switch(type) {
|
||||
case SHA1:
|
||||
return 20;
|
||||
case SHA2_256:
|
||||
return 32;
|
||||
case SHA2_384:
|
||||
return 48;
|
||||
case SHA2_512:
|
||||
return 64;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Return block size (in bytes) for a given SHA type */
|
||||
inline static size_t block_length(esp_sha_type type) {
|
||||
switch(type) {
|
||||
case SHA1:
|
||||
case SHA2_256:
|
||||
return 64;
|
||||
case SHA2_384:
|
||||
case SHA2_512:
|
||||
return 128;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void esp_sha_lock_memory_block(void)
|
||||
{
|
||||
/* Feed the SHA engine one block at a time */
|
||||
_lock_acquire(&memory_block_lock);
|
||||
}
|
||||
|
||||
void esp_sha_unlock_memory_block(void)
|
||||
{
|
||||
_lock_release(&memory_block_lock);
|
||||
}
|
||||
|
||||
/* Lock to hold when changing SHA engine state,
|
||||
allows checking of sha_engines_all_idle()
|
||||
*/
|
||||
static _lock_t state_change_lock;
|
||||
|
||||
inline static bool sha_engines_all_idle() {
|
||||
return !engine_states[0].in_use
|
||||
&& !engine_states[1].in_use
|
||||
&& !engine_states[2].in_use;
|
||||
}
|
||||
|
||||
static void esp_sha_lock_engine_inner(sha_engine_state *engine);
|
||||
|
||||
bool esp_sha_try_lock_engine(esp_sha_type sha_type)
|
||||
{
|
||||
sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
|
||||
if(_lock_try_acquire(&engine->lock) != 0) {
|
||||
/* This SHA engine is already in use */
|
||||
return false;
|
||||
} else {
|
||||
esp_sha_lock_engine_inner(engine);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void esp_sha_lock_engine(esp_sha_type sha_type)
|
||||
{
|
||||
sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
|
||||
_lock_acquire(&engine->lock);
|
||||
esp_sha_lock_engine_inner(engine);
|
||||
}
|
||||
|
||||
static void esp_sha_lock_engine_inner(sha_engine_state *engine)
|
||||
{
|
||||
_lock_acquire(&state_change_lock);
|
||||
|
||||
if (sha_engines_all_idle()) {
|
||||
/* Enable SHA hardware */
|
||||
REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_SHA);
|
||||
/* also clear reset on secure boot, otherwise SHA is held in reset */
|
||||
REG_CLR_BIT(DPORT_PERI_RST_EN_REG,
|
||||
DPORT_PERI_EN_SHA
|
||||
| DPORT_PERI_EN_SECUREBOOT);
|
||||
ets_sha_enable();
|
||||
}
|
||||
|
||||
_lock_release(&state_change_lock);
|
||||
|
||||
assert( !engine->in_use && "in_use flag should be cleared" );
|
||||
engine->in_use = true;
|
||||
}
|
||||
|
||||
|
||||
void esp_sha_unlock_engine(esp_sha_type sha_type)
|
||||
{
|
||||
sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
|
||||
|
||||
_lock_acquire(&state_change_lock);
|
||||
|
||||
assert( engine->in_use && "in_use flag should be set" );
|
||||
engine->in_use = false;
|
||||
|
||||
if (sha_engines_all_idle()) {
|
||||
/* Disable SHA hardware */
|
||||
/* Don't assert reset on secure boot, otherwise AES is held in reset */
|
||||
REG_SET_BIT(DPORT_PERI_RST_EN_REG, DPORT_PERI_EN_SHA);
|
||||
REG_CLR_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_SHA);
|
||||
}
|
||||
|
||||
_lock_release(&state_change_lock);
|
||||
|
||||
_lock_release(&engine->lock);
|
||||
}
|
||||
|
||||
void esp_sha_wait_idle(void)
|
||||
{
|
||||
while(REG_READ(SHA_1_BUSY_REG) == 1) {}
|
||||
while(REG_READ(SHA_256_BUSY_REG) == 1) {}
|
||||
while(REG_READ(SHA_384_BUSY_REG) == 1) {}
|
||||
while(REG_READ(SHA_512_BUSY_REG) == 1) {}
|
||||
}
|
||||
|
||||
void esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state)
|
||||
{
|
||||
sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
|
||||
assert(engine->in_use && "SHA engine should be locked" );
|
||||
|
||||
esp_sha_lock_memory_block();
|
||||
|
||||
esp_sha_wait_idle();
|
||||
|
||||
REG_WRITE(SHA_LOAD_REG(sha_type), 1);
|
||||
while(REG_READ(SHA_BUSY_REG(sha_type)) == 1) { }
|
||||
|
||||
uint32_t *digest_state_words = (uint32_t *)digest_state;
|
||||
uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE);
|
||||
if(sha_type == SHA2_384 || sha_type == SHA2_512) {
|
||||
/* for these ciphers using 64-bit states, swap each pair of words */
|
||||
for(int i = 0; i < sha_length(sha_type)/4; i += 2) {
|
||||
digest_state_words[i+1] = reg_addr_buf[i];
|
||||
digest_state_words[i]= reg_addr_buf[i+1];
|
||||
}
|
||||
} else {
|
||||
memcpy(digest_state_words, reg_addr_buf, sha_length(sha_type));
|
||||
}
|
||||
asm volatile ("memw");
|
||||
|
||||
esp_sha_unlock_memory_block();
|
||||
}
|
||||
|
||||
void esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_first_block)
|
||||
{
|
||||
sha_engine_state *engine = &engine_states[sha_engine_index(sha_type)];
|
||||
assert(engine->in_use && "SHA engine should be locked" );
|
||||
|
||||
esp_sha_lock_memory_block();
|
||||
|
||||
esp_sha_wait_idle();
|
||||
|
||||
/* Fill the data block */
|
||||
uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE);
|
||||
uint32_t *data_words = (uint32_t *)data_block;
|
||||
for (int i = 0; i < block_length(sha_type) / 4; i++) {
|
||||
reg_addr_buf[i] = __bswap_32(data_words[i]);
|
||||
}
|
||||
asm volatile ("memw");
|
||||
|
||||
if(is_first_block) {
|
||||
REG_WRITE(SHA_START_REG(sha_type), 1);
|
||||
} else {
|
||||
REG_WRITE(SHA_CONTINUE_REG(sha_type), 1);
|
||||
}
|
||||
|
||||
esp_sha_unlock_memory_block();
|
||||
|
||||
/* Note: deliberately not waiting for this operation to complete,
|
||||
as a performance tweak - delay waiting until the next time we need the SHA
|
||||
unit, instead.
|
||||
*/
|
||||
}
|
||||
|
||||
void esp_sha(esp_sha_type sha_type, const unsigned char *input, size_t ilen, unsigned char *output)
|
||||
{
|
||||
size_t block_len = block_length(sha_type);
|
||||
|
||||
esp_sha_lock_engine(sha_type);
|
||||
|
||||
SHA_CTX ctx;
|
||||
ets_sha_init(&ctx);
|
||||
while(ilen > 0) {
|
||||
size_t chunk_len = (ilen > block_size) ? block_size : ilen;
|
||||
ets_sha_update(&ctx->context, ctx->context_type, input, chunk_len * 8);
|
||||
size_t chunk_len = (ilen > block_len) ? block_len : ilen;
|
||||
esp_sha_lock_memory_block();
|
||||
esp_sha_wait_idle();
|
||||
ets_sha_update(&ctx, sha_type, input, chunk_len * 8);
|
||||
esp_sha_unlock_memory_block();
|
||||
input += chunk_len;
|
||||
ilen -= chunk_len;
|
||||
}
|
||||
esp_sha_lock_memory_block();
|
||||
esp_sha_wait_idle();
|
||||
ets_sha_finish(&ctx, sha_type, output);
|
||||
esp_sha_unlock_memory_block();
|
||||
|
||||
esp_sha_unlock_engine(sha_type);
|
||||
}
|
||||
|
||||
void esp_sha1_init( esp_sha_context *ctx )
|
||||
{
|
||||
bzero( ctx, sizeof( esp_sha_context ) );
|
||||
}
|
||||
|
||||
void esp_sha1_free( esp_sha_context *ctx )
|
||||
{
|
||||
if ( ctx == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
bzero( ctx, sizeof( esp_sha_context ) );
|
||||
}
|
||||
|
||||
void esp_sha1_clone( esp_sha_context *dst, const esp_sha_context *src )
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-1 context setup
|
||||
*/
|
||||
void esp_sha1_start( esp_sha_context *ctx )
|
||||
{
|
||||
ctx->context_type = SHA1;
|
||||
esp_sha_acquire_hardware();
|
||||
ets_sha_init(&ctx->context);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-1 process buffer
|
||||
*/
|
||||
void esp_sha1_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
esp_sha_update(ctx, input, ilen, 64);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-1 final digest
|
||||
*/
|
||||
void esp_sha1_finish( esp_sha_context *ctx, unsigned char output[20] )
|
||||
{
|
||||
ets_sha_finish(&ctx->context, ctx->context_type, output);
|
||||
esp_sha_release_hardware();
|
||||
}
|
||||
|
||||
/* Full SHA-1 calculation */
|
||||
void esp_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] )
|
||||
{
|
||||
esp_sha_context ctx;
|
||||
|
||||
esp_sha1_init( &ctx );
|
||||
esp_sha1_start( &ctx );
|
||||
esp_sha1_update( &ctx, input, ilen );
|
||||
esp_sha1_finish( &ctx, output );
|
||||
esp_sha1_free( &ctx );
|
||||
}
|
||||
|
||||
void esp_sha256_init( esp_sha_context *ctx )
|
||||
{
|
||||
bzero( ctx, sizeof( esp_sha_context ) );
|
||||
}
|
||||
|
||||
void esp_sha256_free( esp_sha_context *ctx )
|
||||
{
|
||||
if ( ctx == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
bzero( ctx, sizeof( esp_sha_context ) );
|
||||
}
|
||||
|
||||
void esp_sha256_clone( esp_sha_context *dst, const esp_sha_context *src )
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-256 context setup
|
||||
*/
|
||||
void esp_sha256_start( esp_sha_context *ctx, int is224 )
|
||||
{
|
||||
if ( is224 == 0 ) {
|
||||
/* SHA-256 */
|
||||
ctx->context_type = SHA2_256;
|
||||
esp_sha_acquire_hardware();
|
||||
ets_sha_init(&ctx->context);
|
||||
} else {
|
||||
/* SHA-224 is not supported! */
|
||||
ctx->context_type = SHA_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-256 process buffer
|
||||
*/
|
||||
void esp_sha256_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
if( ctx->context_type == SHA2_256 ) {
|
||||
esp_sha_update(ctx, input, ilen, 64);
|
||||
}
|
||||
/* SHA-224 is a no-op */
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-256 final digest
|
||||
*/
|
||||
void esp_sha256_finish( esp_sha_context *ctx, unsigned char output[32] )
|
||||
{
|
||||
if ( ctx->context_type == SHA2_256 ) {
|
||||
ets_sha_finish(&ctx->context, ctx->context_type, output);
|
||||
esp_sha_release_hardware();
|
||||
} else {
|
||||
/* No hardware SHA-224 support, but mbedTLS API doesn't allow failure.
|
||||
For now, zero the output to make it clear it's not valid. */
|
||||
bzero( output, 28 );
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Full SHA-256 calculation
|
||||
*/
|
||||
void esp_sha256( const unsigned char *input, size_t ilen, unsigned char output[32], int is224 )
|
||||
{
|
||||
esp_sha_context ctx;
|
||||
|
||||
esp_sha256_init( &ctx );
|
||||
esp_sha256_start( &ctx, is224 );
|
||||
esp_sha256_update( &ctx, input, ilen );
|
||||
esp_sha256_finish( &ctx, output );
|
||||
esp_sha256_free( &ctx );
|
||||
}
|
||||
|
||||
|
||||
/////
|
||||
void esp_sha512_init( esp_sha_context *ctx )
|
||||
{
|
||||
memset( ctx, 0, sizeof( esp_sha_context ) );
|
||||
}
|
||||
|
||||
void esp_sha512_free( esp_sha_context *ctx )
|
||||
{
|
||||
if ( ctx == NULL ) {
|
||||
return;
|
||||
}
|
||||
|
||||
bzero( ctx, sizeof( esp_sha_context ) );
|
||||
}
|
||||
|
||||
void esp_sha512_clone( esp_sha_context *dst, const esp_sha_context *src )
|
||||
{
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-512 context setup
|
||||
*/
|
||||
void esp_sha512_start( esp_sha_context *ctx, int is384 )
|
||||
{
|
||||
if ( is384 == 0 ) {
|
||||
/* SHA-512 */
|
||||
ctx->context_type = SHA2_512;
|
||||
} else {
|
||||
/* SHA-384 */
|
||||
ctx->context_type = SHA2_384;
|
||||
}
|
||||
esp_sha_acquire_hardware();
|
||||
ets_sha_init(&ctx->context);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-512 process buffer
|
||||
*/
|
||||
void esp_sha512_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen )
|
||||
{
|
||||
esp_sha_update(ctx, input, ilen, 128);
|
||||
}
|
||||
|
||||
/*
|
||||
* SHA-512 final digest
|
||||
*/
|
||||
void esp_sha512_finish( esp_sha_context *ctx, unsigned char output[64] )
|
||||
{
|
||||
ets_sha_finish(&ctx->context, ctx->context_type, output);
|
||||
esp_sha_release_hardware();
|
||||
}
|
||||
|
||||
/*
|
||||
* Full SHA-512 calculation
|
||||
*/
|
||||
void esp_sha512( const unsigned char *input, size_t ilen, unsigned char output[64], int is384 )
|
||||
{
|
||||
esp_sha_context ctx;
|
||||
|
||||
esp_sha512_init( &ctx );
|
||||
esp_sha512_start( &ctx, is384 );
|
||||
esp_sha512_update( &ctx, input, ilen );
|
||||
esp_sha512_finish( &ctx, output );
|
||||
esp_sha512_free( &ctx );
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
|
|
|
@ -30,25 +30,34 @@ extern "C" {
|
|||
*/
|
||||
|
||||
/**
|
||||
* @brief Set the chip to deep-sleep mode.
|
||||
*
|
||||
* The device will automatically wake up after the deep-sleep time set
|
||||
* by the users. Upon waking up, the device boots up from user_init.
|
||||
*
|
||||
* @attention The parameter time_in_us to be "uint64" is for further development.
|
||||
* Only the low 32 bits of parameter time_in_us are avalable now.
|
||||
*
|
||||
* @param uint64 time_in_us : deep-sleep time, only the low 32bits are avalable now. unit: microsecond
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
void system_deep_sleep(uint64_t time_in_us);
|
||||
* @brief Enter deep-sleep mode
|
||||
*
|
||||
* The device will automatically wake up after the deep-sleep time
|
||||
* Upon waking up, the device calls deep sleep wake stub, and then proceeds
|
||||
* to load application.
|
||||
*
|
||||
* This function does not return.
|
||||
*
|
||||
* @param time_in_us deep-sleep time, unit: microsecond
|
||||
*/
|
||||
void esp_deep_sleep(uint64_t time_in_us) __attribute__((noreturn));
|
||||
|
||||
|
||||
/**
|
||||
* @brief Enter deep-sleep mode
|
||||
*
|
||||
* Function has been renamed to esp_deep_sleep.
|
||||
* This name is deprecated and will be removed in a future version.
|
||||
*
|
||||
* @param time_in_us deep-sleep time, unit: microsecond
|
||||
*/
|
||||
void system_deep_sleep(uint64_t time_in_us) __attribute__((noreturn, deprecated));
|
||||
|
||||
/**
|
||||
* @brief Default stub to run on wake from deep sleep.
|
||||
*
|
||||
* Allows for executing code immediately on wake from sleep, before
|
||||
* the software bootloader or esp-idf app has started up.
|
||||
* the software bootloader or ESP-IDF app has started up.
|
||||
*
|
||||
* This function is weak-linked, so you can implement your own version
|
||||
* to run code immediately when the chip wakes from
|
||||
|
|
|
@ -45,6 +45,11 @@ typedef enum {
|
|||
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP32 soft-AP */
|
||||
SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
|
||||
SYSTEM_EVENT_AP_STA_GOT_IP6, /**< ESP32 station or ap interface v6IP addr is preferred */
|
||||
SYSTEM_EVENT_ETH_START, /**< ESP32 ethernet start */
|
||||
SYSTEM_EVENT_ETH_STOP, /**< ESP32 ethernet stop */
|
||||
SYSTEM_EVENT_ETH_CONNECTED, /**< ESP32 ethernet phy link up */
|
||||
SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP32 ethernet phy link down */
|
||||
SYSTEM_EVENT_ETH_GOT_IP, /**< ESP32 ethernet got IP from connected AP */
|
||||
SYSTEM_EVENT_MAX
|
||||
} system_event_id_t;
|
||||
|
||||
|
|
41
examples/13_bt_sdp/main/demo_main.c → components/esp32/include/esp_interface.h
Executable file → Normal file
41
examples/13_bt_sdp/main/demo_main.c → components/esp32/include/esp_interface.h
Executable file → Normal file
|
@ -12,31 +12,26 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include "bt.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "string.h"
|
||||
|
||||
#ifndef __ESP_INTERFACE_H__
|
||||
#define __ESP_INTERFACE_H__
|
||||
|
||||
extern void bte_main_boot_entry(void *);
|
||||
extern void bt_app_task_start_up(void);
|
||||
extern void bt_app_core_start(void);
|
||||
#include <stdint.h>
|
||||
|
||||
void pingTask(void *pvParameters)
|
||||
{
|
||||
while (1) {
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS);
|
||||
printf("ping\n");
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
ESP_IF_WIFI_STA = 0, /**< ESP32 station interface */
|
||||
ESP_IF_WIFI_AP, /**< ESP32 soft-AP interface */
|
||||
ESP_IF_ETH, /**< ESP32 ethernet interface */
|
||||
ESP_IF_MAX
|
||||
} esp_interface_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
void app_main()
|
||||
{
|
||||
bt_controller_init();
|
||||
xTaskCreatePinnedToCore(&pingTask, "pingTask", 2048, NULL, 5, NULL, 0);
|
||||
bt_app_task_start_up();
|
||||
// bte_main_boot_entry(bt_app_core_start);
|
||||
}
|
||||
|
||||
#endif /* __ESP_INTERFACE_TYPES_H__ */
|
|
@ -16,7 +16,7 @@
|
|||
#define __ESP_SYSTEM_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "esp_err.h"
|
||||
#include "esp_deepsleep.h"
|
||||
|
||||
|
@ -24,166 +24,107 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** \defgroup System_APIs System APIs
|
||||
* @brief System APIs
|
||||
*/
|
||||
|
||||
/** @addtogroup System_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @attention application don't need to call this function anymore. It do nothing and will
|
||||
* be removed in future version.
|
||||
*/
|
||||
void system_init(void) __attribute__ ((deprecated));
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get information of the SDK version.
|
||||
*
|
||||
* @param null
|
||||
*
|
||||
* @return Information of the SDK version.
|
||||
*/
|
||||
const char *system_get_sdk_version(void);
|
||||
|
||||
/**
|
||||
* @brief Reset to default settings.
|
||||
*
|
||||
* Reset to default settings of the following APIs : wifi_station_set_auto_connect,
|
||||
* wifi_set_phy_mode, wifi_softap_set_config related, wifi_station_set_config
|
||||
* related, and wifi_set_opmode.
|
||||
*
|
||||
* @param null
|
||||
*
|
||||
* @return null
|
||||
* Function has been deprecated, please use esp_wifi_restore instead.
|
||||
* This name will be removed in a future release.
|
||||
*/
|
||||
void system_restore(void);
|
||||
void system_restore(void) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Restart PRO and APP CPUs.
|
||||
*
|
||||
* This function can be called both from PRO and APP CPUs.
|
||||
* After successful restart, CPU reset reason will be SW_CPU_RESET.
|
||||
* Peripherals (except for WiFi, BT, UART0, SPI1, and legacy timers) are not reset.
|
||||
* This function does not return.
|
||||
*/
|
||||
void esp_restart(void) __attribute__ ((noreturn));
|
||||
|
||||
/**
|
||||
* @brief Restart system.
|
||||
*
|
||||
* @param null
|
||||
*
|
||||
* @return null
|
||||
* Function has been renamed to esp_restart.
|
||||
* This name will be removed in a future release.
|
||||
*/
|
||||
void system_restart(void);
|
||||
void system_restart(void) __attribute__ ((deprecated, noreturn));
|
||||
|
||||
/**
|
||||
* @brief Get system time, unit: microsecond.
|
||||
*
|
||||
* @param null
|
||||
*
|
||||
* @return System time, unit: microsecond.
|
||||
* This function is deprecated. Use 'gettimeofday' function for 64-bit precision.
|
||||
* This definition will be removed in a future release.
|
||||
*/
|
||||
uint32_t system_get_time(void);
|
||||
uint32_t system_get_time(void) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Get the size of available heap.
|
||||
*
|
||||
* @param null
|
||||
* Note that the returned value may be larger than the maximum contiguous block
|
||||
* which can be allocated.
|
||||
*
|
||||
* @return Available heap size.
|
||||
* @return Available heap size, in bytes.
|
||||
*/
|
||||
uint32_t system_get_free_heap_size(void);
|
||||
uint32_t esp_get_free_heap_size(void);
|
||||
|
||||
/**
|
||||
* @brief Get RTC time, unit: RTC clock cycle.
|
||||
* @brief Get the size of available heap.
|
||||
*
|
||||
* @param null
|
||||
* Function has been renamed to esp_get_free_heap_size.
|
||||
* This name will be removed in a future release.
|
||||
*
|
||||
* @return RTC time.
|
||||
* @return Available heap size, in bytes.
|
||||
*/
|
||||
uint64_t system_get_rtc_time(void);
|
||||
uint32_t system_get_free_heap_size(void) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @brief Read user data from the RTC memory.
|
||||
*
|
||||
* The user data segment (1024 bytes, as shown below) is used to store user data.
|
||||
*
|
||||
* |<---- system data(512 bytes) ---->|<----------- user data(1024 bytes) --------->|
|
||||
*
|
||||
* @attention Read and write unit for data stored in the RTC memory is 4 bytes.
|
||||
* @attention src_addr is the block number (4 bytes per block). So when reading data
|
||||
* at the beginning of the user data segment, src_addr will be 512/4 = 128,
|
||||
* n will be data length.
|
||||
*
|
||||
* @param uint16 src : source address of rtc memory, src_addr >= 128
|
||||
* @param void *dst : data pointer
|
||||
* @param uint16 n : data length, unit: byte
|
||||
*
|
||||
* @return true : succeed
|
||||
* @return false : fail
|
||||
*/
|
||||
bool system_rtc_mem_read(uint16_t src, void *dst, uint16_t n);
|
||||
|
||||
/**
|
||||
* @brief Write user data to the RTC memory.
|
||||
*
|
||||
* During deep-sleep, only RTC is working. So users can store their data
|
||||
* in RTC memory if it is needed. The user data segment below (1024 bytes)
|
||||
* is used to store the user data.
|
||||
*
|
||||
* |<---- system data(512 bytes) ---->|<----------- user data(1024 bytes) --------->|
|
||||
*
|
||||
* @attention Read and write unit for data stored in the RTC memory is 4 bytes.
|
||||
* @attention src_addr is the block number (4 bytes per block). So when storing data
|
||||
* at the beginning of the user data segment, src_addr will be 512/4 = 128,
|
||||
* n will be data length.
|
||||
*
|
||||
* @param uint16 src : source address of rtc memory, src_addr >= 128
|
||||
* @param void *dst : data pointer
|
||||
* @param uint16 n : data length, unit: byte
|
||||
*
|
||||
* @return true : succeed
|
||||
* @return false : fail
|
||||
*/
|
||||
bool system_rtc_mem_write(uint16_t dst, const void *src, uint16_t n);
|
||||
|
||||
/** \defgroup System_boot_APIs Boot APIs
|
||||
* @brief boot APIs
|
||||
*/
|
||||
|
||||
/** @addtogroup System_boot_APIs
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** \defgroup Hardware_MAC_APIs Hardware MAC APIs
|
||||
* @brief Hardware MAC address APIs
|
||||
*
|
||||
* In WiFi MAC, only ESP32 station MAC is the hardware MAC, ESP32 softAP MAC is a software MAC
|
||||
* calculated from ESP32 station MAC.
|
||||
* So users need to call wifi_get_macaddr to query the ESP32 softAP MAC if ESP32 station MAC changed.
|
||||
*
|
||||
*/
|
||||
|
||||
/** @addtogroup Hardware_MAC_APIs
|
||||
* @{
|
||||
*/
|
||||
* @brief Get one random 32-bit word from hardware RNG
|
||||
*
|
||||
* @return random value between 0 and UINT32_MAX
|
||||
*/
|
||||
uint32_t esp_random(void);
|
||||
|
||||
/**
|
||||
* @brief Read hardware MAC address.
|
||||
*
|
||||
* @param uint8 mac[6] : the hardware MAC address, length: 6 bytes.
|
||||
* In WiFi MAC, only ESP32 station MAC is the hardware MAC, ESP32 softAP MAC is a software MAC
|
||||
* calculated from ESP32 station MAC.
|
||||
* So users need to call esp_wifi_get_macaddr to query the ESP32 softAP MAC if ESP32 station MAC changed.
|
||||
*
|
||||
* @return esp_err_t
|
||||
* @param mac hardware MAC address, length: 6 bytes.
|
||||
*
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
esp_err_t system_efuse_read_mac(uint8_t mac[6]);
|
||||
|
||||
esp_err_t esp_efuse_read_mac(uint8_t* mac);
|
||||
|
||||
/**
|
||||
* @}
|
||||
* @brief Read hardware MAC address.
|
||||
*
|
||||
* Function has been renamed to esp_efuse_read_mac.
|
||||
* This name will be removed in a future release.
|
||||
*
|
||||
* @param mac hardware MAC address, length: 6 bytes.
|
||||
* @return ESP_OK on success
|
||||
*/
|
||||
|
||||
esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__ ((deprecated));
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
* Get SDK version
|
||||
*
|
||||
* This function is deprecated and will be removed in a future release.
|
||||
*
|
||||
* @return constant string "master"
|
||||
*/
|
||||
const char* system_get_sdk_version(void) __attribute__ ((deprecated));
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -22,52 +22,4 @@
|
|||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define __ATTRIB_PACK __attribute__ ((packed))
|
||||
#define __ATTRIB_PRINTF __attribute__ ((format (printf, 1, 2)))
|
||||
#define __ATTRIB_NORETURN __attribute__ ((noreturn))
|
||||
#define __ATTRIB_ALIGN(x) __attribute__ ((aligned((x))))
|
||||
#define INLINE __inline__
|
||||
|
||||
#define LOCAL static
|
||||
|
||||
/* probably should not put STATUS here */
|
||||
typedef enum {
|
||||
OK = 0,
|
||||
FAIL,
|
||||
PENDING,
|
||||
BUSY,
|
||||
CANCEL,
|
||||
} STATUS;
|
||||
|
||||
//#define _LITTLE_ENDIAN 1234
|
||||
//#define _BYTE_ORDER == _LITTLE_ENDIAN
|
||||
|
||||
#define ASSERT( x ) do { \
|
||||
if (!(x)) { \
|
||||
printf("%s %u\n", __FILE__, __LINE__); \
|
||||
while (1) { \
|
||||
asm volatile("nop"); \
|
||||
}; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* #if __GNUC_PREREQ__(4, 1) */
|
||||
#ifndef __GNUC__
|
||||
#if 1
|
||||
#define __offsetof(type, field) __builtin_offsetof(type, field)
|
||||
#else
|
||||
#define __offsetof(type, field) ((size_t)(&((type *)0)->field))
|
||||
#endif
|
||||
#endif /* __GNUC__ */
|
||||
|
||||
|
||||
/* Macros for counting and rounding. */
|
||||
#ifndef howmany
|
||||
#define howmany(x, y) (((x)+((y)-1))/(y))
|
||||
#endif
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - __offsetof(type,member) );})
|
||||
|
||||
#endif /* __ESP_TYPES_H__ */
|
||||
|
|
|
@ -87,6 +87,7 @@ extern "C" {
|
|||
#define ESP_ERR_WIFI_SSID (ESP_ERR_WIFI_BASE + 9) /*!< SSID is invalid */
|
||||
#define ESP_ERR_WIFI_PASSWORD (ESP_ERR_WIFI_BASE + 10) /*!< Passord is invalid */
|
||||
#define ESP_ERR_WIFI_TIMEOUT (ESP_ERR_WIFI_BASE + 11) /*!< Timeout error */
|
||||
#define ESP_ERR_WIFI_WAKE_FAIL (ESP_ERR_WIFI_BASE + 12) /*!< WiFi is in sleep state(RF closed) and wakeup fail */
|
||||
|
||||
/**
|
||||
* @brief WiFi stack configuration parameters passed to esp_wifi_init call.
|
||||
|
@ -186,6 +187,21 @@ esp_err_t esp_wifi_start(void);
|
|||
*/
|
||||
esp_err_t esp_wifi_stop(void);
|
||||
|
||||
/**
|
||||
* @brief Restore WiFi stack persistent settings to default values
|
||||
*
|
||||
* This function will reset settings made using the following APIs:
|
||||
* - esp_wifi_get_auto_connect,
|
||||
* - esp_wifi_set_protocol,
|
||||
* - esp_wifi_set_config related
|
||||
* - esp_wifi_set_mode
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK: succeed
|
||||
* - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by eps_wifi_init
|
||||
*/
|
||||
esp_err_t esp_wifi_restore(void);
|
||||
|
||||
/**
|
||||
* @brief Connect the ESP32 WiFi station to the AP.
|
||||
*
|
||||
|
@ -312,6 +328,8 @@ esp_err_t esp_wifi_sta_get_ap_info(wifi_ap_record_t *ap_info);
|
|||
/**
|
||||
* @brief Set current power save type
|
||||
*
|
||||
* @attention Default power save type is WIFI_PS_NONE.
|
||||
*
|
||||
* @param type power save type
|
||||
*
|
||||
* @return ESP_ERR_WIFI_NOT_SUPPORT: not supported yet
|
||||
|
@ -321,6 +339,8 @@ esp_err_t esp_wifi_set_ps(wifi_ps_type_t type);
|
|||
/**
|
||||
* @brief Get current power save type
|
||||
*
|
||||
* @attention Default power save type is WIFI_PS_NONE.
|
||||
*
|
||||
* @param[out] type: store current power save type
|
||||
*
|
||||
* @return ESP_ERR_WIFI_NOT_SUPPORT: not supported yet
|
||||
|
|
|
@ -43,10 +43,9 @@ extern "C" {
|
|||
/**
|
||||
* @brief get whether the wifi driver is allowed to transmit data or not
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return true : upper layer should stop to transmit data to wifi driver
|
||||
* @return false : upper layer can transmit data to wifi driver
|
||||
* @return
|
||||
* - true : upper layer should stop to transmit data to wifi driver
|
||||
* - false : upper layer can transmit data to wifi driver
|
||||
*/
|
||||
bool esp_wifi_internal_tx_is_stop(void);
|
||||
|
||||
|
@ -54,8 +53,6 @@ bool esp_wifi_internal_tx_is_stop(void);
|
|||
* @brief free the rx buffer which allocated by wifi driver
|
||||
*
|
||||
* @param void* buffer: rx buffer pointer
|
||||
*
|
||||
* @return nonoe
|
||||
*/
|
||||
void esp_wifi_internal_free_rx_buffer(void* buffer);
|
||||
|
||||
|
@ -78,7 +75,6 @@ int esp_wifi_internal_tx(wifi_interface_t wifi_if, void *buffer, u16_t len);
|
|||
* @brief The WiFi RX callback function
|
||||
*
|
||||
* Each time the WiFi need to forward the packets to high layer, the callback function will be called
|
||||
*
|
||||
*/
|
||||
typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb);
|
||||
|
||||
|
@ -90,18 +86,18 @@ typedef esp_err_t (*wifi_rxcb_t)(void *buffer, uint16_t len, void *eb);
|
|||
* @param wifi_interface_t ifx : interface
|
||||
* @param wifi_rxcb_t fn : WiFi RX callback
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
* @return
|
||||
* - ESP_OK : succeed
|
||||
* - others : fail
|
||||
*/
|
||||
esp_err_t esp_wifi_internal_reg_rxcb(wifi_interface_t ifx, wifi_rxcb_t fn);
|
||||
|
||||
/**
|
||||
* @brief Notify WIFI driver that the station got ip successfully
|
||||
*
|
||||
* @param none
|
||||
*
|
||||
* @return ESP_OK : succeed
|
||||
* @return others : fail
|
||||
* @return
|
||||
* - ESP_OK : succeed
|
||||
* - others : fail
|
||||
*/
|
||||
esp_err_t esp_wifi_internal_set_sta_ip(void);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "rom/queue.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_wifi_types.h"
|
||||
#include "esp_interface.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -34,11 +35,10 @@ typedef enum {
|
|||
WIFI_MODE_MAX
|
||||
} wifi_mode_t;
|
||||
|
||||
typedef enum {
|
||||
WIFI_IF_STA = 0, /**< ESP32 station interface */
|
||||
WIFI_IF_AP, /**< ESP32 soft-AP interface */
|
||||
WIFI_IF_MAX
|
||||
} wifi_interface_t;
|
||||
typedef esp_interface_t wifi_interface_t;
|
||||
|
||||
#define WIFI_IF_STA ESP_IF_WIFI_STA
|
||||
#define WIFI_IF_AP ESP_IF_WIFI_AP
|
||||
|
||||
typedef enum {
|
||||
WIFI_COUNTRY_CN = 0, /**< country China, channel range [1, 14] */
|
||||
|
@ -114,8 +114,6 @@ typedef struct {
|
|||
typedef enum {
|
||||
WIFI_PS_NONE, /**< No power save */
|
||||
WIFI_PS_MODEM, /**< Modem power save */
|
||||
WIFI_PS_LIGHT, /**< Light power save */
|
||||
WIFI_PS_MAC, /**< MAC power save */
|
||||
} wifi_ps_type_t;
|
||||
|
||||
#define WIFI_PROTOCOL_11B 1
|
||||
|
|
166
components/esp32/include/esp_wpa2.h
Normal file
166
components/esp32/include/esp_wpa2.h
Normal file
|
@ -0,0 +1,166 @@
|
|||
// Copyright 2015-2016 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_WPA2_H
|
||||
#define ESP_WPA2_H
|
||||
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Enable wpa2 enterprise authentication.
|
||||
*
|
||||
* @attention wpa2 enterprise authentication can only be used when ESP32 station is enabled.
|
||||
* wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method.
|
||||
*
|
||||
* @return 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);
|
||||
|
||||
/**
|
||||
* @brief Disable wpa2 enterprise authentication.
|
||||
*
|
||||
* @attention wpa2 enterprise authentication can only be used when ESP32 station is enabled.
|
||||
* wpa2 enterprise authentication can only support TLS, PEAP-MSCHAPv2 and TTLS-MSCHAPv2 method.
|
||||
*
|
||||
* @return ESP_ERR_WIFI_OK: succeed.
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Set username for PEAP/TTLS method.
|
||||
*
|
||||
* @attention The API only passes the parameter username to the global pointer variable in wpa2 enterprise module.
|
||||
*
|
||||
* @param username: point to address where stores the username;
|
||||
* len: length of username, limited to 1~127
|
||||
*
|
||||
* @return ESP_ERR_WIFI_OK: succeed
|
||||
* ESP_ERR_WIFI_ARG: fail(len <= 0 or len >= 128)
|
||||
* ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail)
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_set_username(unsigned char *username, int len);
|
||||
|
||||
/**
|
||||
* @brief Clear username for PEAP/TTLS method.
|
||||
*/
|
||||
void esp_wifi_sta_wpa2_ent_clear_username(void);
|
||||
|
||||
/**
|
||||
* @brief Set password for PEAP/TTLS method..
|
||||
*
|
||||
* @attention The API only passes the parameter password to the global pointer variable in wpa2 enterprise module.
|
||||
*
|
||||
* @param password: point to address where stores the password;
|
||||
* len: length of password(len > 0)
|
||||
*
|
||||
* @return ESP_ERR_WIFI_OK: succeed
|
||||
* ESP_ERR_WIFI_ARG: fail(len <= 0)
|
||||
* ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail)
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_set_password(unsigned char *password, int len);
|
||||
|
||||
/**
|
||||
* @brief Clear password for PEAP/TTLS method..
|
||||
*/
|
||||
void esp_wifi_sta_wpa2_ent_clear_password(void);
|
||||
|
||||
/**
|
||||
* @brief Set new password for MSCHAPv2 method..
|
||||
*
|
||||
* @attention The API only passes the parameter password to the global pointer variable in wpa2 enterprise module.
|
||||
* The new password is used to substitute the old password when eap-mschapv2 failure request message with error code ERROR_PASSWD_EXPIRED is received.
|
||||
*
|
||||
* @param password: point to address where stores the password;
|
||||
* len: length of password
|
||||
*
|
||||
* @return ESP_ERR_WIFI_OK: succeed
|
||||
* ESP_ERR_WIFI_ARG: fail(len <= 0)
|
||||
* ESP_ERR_WIFI_NO_MEM: fail(internal memory malloc fail)
|
||||
*/
|
||||
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_set_new_password(unsigned char *password, int len);
|
||||
|
||||
/**
|
||||
* @brief Clear new password for MSCHAPv2 method..
|
||||
*/
|
||||
void esp_wifi_sta_wpa2_ent_clear_new_password(void);
|
||||
|
||||
/**
|
||||
* @brief Set CA certificate for PEAP/TTLS method.
|
||||
*
|
||||
* @attention The API only passes the parameter ca_cert to the global pointer variable in wpa2 enterprise module.
|
||||
* The ca_cert should be zero terminated.
|
||||
*
|
||||
* @param ca_cert: point to address where stores the CA certificate;
|
||||
* len: length of ca_cert
|
||||
*
|
||||
* @return ESP_ERR_WIFI_OK: succeed
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_set_ca_cert(unsigned char *ca_cert, int len);
|
||||
|
||||
/**
|
||||
* @brief Clear CA certificate for PEAP/TTLS method.
|
||||
*/
|
||||
void esp_wifi_sta_wpa2_ent_clear_ca_cert(void);
|
||||
|
||||
/**
|
||||
* @brief Set client certificate and key.
|
||||
*
|
||||
* @attention The API only passes the parameter client_cert, private_key and private_key_passwd to the global pointer variable in wpa2 enterprise module.
|
||||
* The client_cert, private_key and private_key_passwd should be zero terminated.
|
||||
*
|
||||
* @param client_cert: point to address where stores the client certificate;
|
||||
* client_cert_len: length of client certificate;
|
||||
* private_key: point to address where stores the private key;
|
||||
* private_key_len: length of private key, limited to 1~2048;
|
||||
* private_key_password: point to address where stores the private key password;
|
||||
* private_key_password_len: length of private key password;
|
||||
*
|
||||
* @return ESP_ERR_WIFI_OK: succeed
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_set_cert_key(unsigned char *client_cert, int client_cert_len, unsigned char *private_key, int private_key_len, unsigned char *private_key_passwd, int private_key_passwd_len);
|
||||
|
||||
/**
|
||||
* @brief Clear client certificate and key.
|
||||
*/
|
||||
void esp_wifi_sta_wpa2_ent_clear_cert_key(void);
|
||||
|
||||
/**
|
||||
* @brief Set wpa2 enterprise certs time check(disable or not).
|
||||
*
|
||||
* @param true: disable wpa2 enterprise certs time check
|
||||
* false: enable wpa2 enterprise certs time check
|
||||
*
|
||||
* @return ESP_OK: succeed
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_set_disable_time_check(bool disable);
|
||||
|
||||
/**
|
||||
* @brief Get wpa2 enterprise certs time check(disable or not).
|
||||
*
|
||||
* @param disable: store disable value
|
||||
*
|
||||
* @return ESP_OK: succeed
|
||||
*/
|
||||
esp_err_t esp_wifi_sta_wpa2_ent_get_disable_time_check(bool *disable);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
|
@ -1,246 +1,203 @@
|
|||
/*
|
||||
* ESP32 hardware accelerated SHA1/256/512 implementation
|
||||
* based on mbedTLS FIPS-197 compliant version.
|
||||
*
|
||||
* Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
|
||||
* Additions Copyright (C) 2016, Espressif Systems (Shanghai) PTE Ltd
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
// Copyright 2015-2016 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_SHA_H_
|
||||
#define _ESP_SHA_H_
|
||||
|
||||
#include "rom/sha.h"
|
||||
|
||||
#include "esp_types.h"
|
||||
|
||||
/** @brief Low-level support functions for the hardware SHA engine
|
||||
*
|
||||
* @note If you're looking for a SHA API to use, try mbedtls component
|
||||
* mbedtls/shaXX.h. That API supports hardware acceleration.
|
||||
*
|
||||
* The API in this header provides some building blocks for implementing a
|
||||
* full SHA API such as the one in mbedtls, and also a basic SHA function esp_sha().
|
||||
*
|
||||
* Some technical details about the hardware SHA engine:
|
||||
*
|
||||
* - SHA accelerator engine calculates one digest at a time, per SHA
|
||||
* algorithm type. It initialises and maintains the digest state
|
||||
* internally. It is possible to read out an in-progress SHA digest
|
||||
* state, but it is not possible to restore a SHA digest state
|
||||
* into the engine.
|
||||
*
|
||||
* - The memory block SHA_TEXT_BASE is shared between all SHA digest
|
||||
* engines, so all engines must be idle before this memory block is
|
||||
* modified.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief SHA-1 context structure
|
||||
*/
|
||||
typedef struct {
|
||||
/* both types defined in rom/sha.h */
|
||||
SHA_CTX context;
|
||||
enum SHA_TYPE context_type;
|
||||
} esp_sha_context;
|
||||
/* Defined in rom/sha.h */
|
||||
typedef enum SHA_TYPE esp_sha_type;
|
||||
|
||||
/**
|
||||
* \brief Lock access to SHA hardware unit
|
||||
/** @brief Calculate SHA1 or SHA2 sum of some data, using hardware SHA engine
|
||||
*
|
||||
* SHA hardware unit can only be used by one
|
||||
* consumer at a time.
|
||||
* @note For more versatile SHA calculations, where data doesn't need
|
||||
* to be passed all at once, try the mbedTLS mbedtls/shaX.h APIs. The
|
||||
* hardware-accelerated mbedTLS implementation is also faster when
|
||||
* hashing large amounts of data.
|
||||
*
|
||||
* esp_sha_xxx API calls automatically manage locking & unlocking of
|
||||
* hardware, this function is only needed if you want to call
|
||||
* ets_sha_xxx functions directly.
|
||||
*/
|
||||
void esp_sha_acquire_hardware( void );
|
||||
|
||||
/**
|
||||
* \brief Unlock access to SHA hardware unit
|
||||
* @note It is not necessary to lock any SHA hardware before calling
|
||||
* this function, thread safety is managed internally.
|
||||
*
|
||||
* esp_sha_xxx API calls automatically manage locking & unlocking of
|
||||
* hardware, this function is only needed if you want to call
|
||||
* ets_sha_xxx functions directly.
|
||||
*/
|
||||
void esp_sha_release_hardware( void );
|
||||
|
||||
/**
|
||||
* \brief Initialize SHA-1 context
|
||||
* @note If a TLS connection is open then this function may block
|
||||
* indefinitely waiting for a SHA engine to become available. Use the
|
||||
* mbedTLS SHA API to avoid this problem.
|
||||
*
|
||||
* \param ctx SHA-1 context to be initialized
|
||||
*/
|
||||
void esp_sha1_init( esp_sha_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clear SHA-1 context
|
||||
* @param sha_type SHA algorithm to use.
|
||||
*
|
||||
* \param ctx SHA-1 context to be cleared
|
||||
*/
|
||||
void esp_sha1_free( esp_sha_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clone (the state of) a SHA-1 context
|
||||
* @param input Input data buffer.
|
||||
*
|
||||
* \param dst The destination context
|
||||
* \param src The context to be cloned
|
||||
*/
|
||||
void esp_sha1_clone( esp_sha_context *dst, const esp_sha_context *src );
|
||||
|
||||
/**
|
||||
* \brief SHA-1 context setup
|
||||
* @param ilen Length of input data in bytes.
|
||||
*
|
||||
* \param ctx context to be initialized
|
||||
* @param output Buffer for output SHA digest. Output is 20 bytes for
|
||||
* sha_type SHA1, 32 bytes for sha_type SHA2_256, 48 bytes for
|
||||
* sha_type SHA2_384, 64 bytes for sha_type SHA2_512.
|
||||
*/
|
||||
void esp_sha1_start( esp_sha_context *ctx );
|
||||
void esp_sha(esp_sha_type sha_type, const unsigned char *input, size_t ilen, unsigned char *output);
|
||||
|
||||
/**
|
||||
* \brief SHA-1 process buffer
|
||||
/* @brief Begin to execute a single SHA block operation
|
||||
*
|
||||
* \param ctx SHA-1 context
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
*/
|
||||
void esp_sha1_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief SHA-1 final digest
|
||||
* @note This is a piece of a SHA algorithm, rather than an entire SHA
|
||||
* algorithm.
|
||||
*
|
||||
* \param ctx SHA-1 context
|
||||
* \param output SHA-1 checksum result
|
||||
*/
|
||||
void esp_sha1_finish( esp_sha_context *ctx, unsigned char output[20] );
|
||||
|
||||
/**
|
||||
* \brief Calculate SHA-1 of input buffer
|
||||
* @note Call esp_sha_try_lock_engine() before calling this
|
||||
* function. Do not call esp_sha_lock_memory_block() beforehand, this
|
||||
* is done inside the function.
|
||||
*
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
* \param output SHA-1 checksum result
|
||||
*/
|
||||
void esp_sha1( const unsigned char *input, size_t ilen, unsigned char output[20] );
|
||||
|
||||
/**
|
||||
* \brief SHA-256 context structure
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Initialize SHA-256 context
|
||||
* @param sha_type SHA algorithm to use.
|
||||
*
|
||||
* \param ctx SHA-256 context to be initialized
|
||||
*/
|
||||
void esp_sha256_init( esp_sha_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clear SHA-256 context
|
||||
* @param data_block Pointer to block of data. Block size is
|
||||
* determined by algorithm (SHA1/SHA2_256 = 64 bytes,
|
||||
* SHA2_384/SHA2_512 = 128 bytes)
|
||||
*
|
||||
* \param ctx SHA-256 context to be cleared
|
||||
*/
|
||||
void esp_sha256_free( esp_sha_context *ctx );
|
||||
|
||||
/**
|
||||
* \brief Clone (the state of) a SHA-256 context
|
||||
* @param is_first_block If this parameter is true, the SHA state will
|
||||
* be initialised (with the initial state of the given SHA algorithm)
|
||||
* before the block is calculated. If false, the existing state of the
|
||||
* SHA engine will be used.
|
||||
*
|
||||
* \param dst The destination context
|
||||
* \param src The context to be cloned
|
||||
* @return As a performance optimisation, this function returns before
|
||||
* the SHA block operation is complete. Both this function and
|
||||
* esp_sha_read_state() will automatically wait for any previous
|
||||
* operation to complete before they begin. If using the SHA registers
|
||||
* directly in another way, call esp_sha_wait_idle() after calling this
|
||||
* function but before accessing the SHA registers.
|
||||
*/
|
||||
void esp_sha256_clone( esp_sha_context *dst, const esp_sha_context *src );
|
||||
void esp_sha_block(esp_sha_type sha_type, const void *data_block, bool is_first_block);
|
||||
|
||||
/**
|
||||
* \brief SHA-256 context setup
|
||||
/** @brief Read out the current state of the SHA digest loaded in the engine.
|
||||
*
|
||||
* \param ctx context to be initialized
|
||||
* \param is224 0 = use SHA256, 1 = use SHA224
|
||||
*/
|
||||
void esp_sha256_start( esp_sha_context *ctx, int is224 );
|
||||
|
||||
/**
|
||||
* \brief SHA-256 process buffer
|
||||
* @note This is a piece of a SHA algorithm, rather than an entire SHA algorithm.
|
||||
*
|
||||
* \param ctx SHA-256 context
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
*/
|
||||
void esp_sha256_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen );
|
||||
|
||||
/**
|
||||
* \brief SHA-256 final digest
|
||||
* @note Call esp_sha_try_lock_engine() before calling this
|
||||
* function. Do not call esp_sha_lock_memory_block() beforehand, this
|
||||
* is done inside the function.
|
||||
*
|
||||
* \param ctx SHA-256 context
|
||||
* \param output SHA-224/256 checksum result
|
||||
*/
|
||||
void esp_sha256_finish( esp_sha_context *ctx, unsigned char output[32] );
|
||||
|
||||
/**
|
||||
* \brief Calculate SHA-256 of input buffer
|
||||
* If the SHA suffix padding block has been executed already, the
|
||||
* value that is read is the SHA digest (in big endian
|
||||
* format). Otherwise, the value that is read is an interim SHA state.
|
||||
*
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
* \param output SHA-224/256 checksum result
|
||||
* \param is224 0 = use SHA256, 1 = use SHA224
|
||||
*/
|
||||
void esp_sha256( const unsigned char *input, size_t ilen, unsigned char output[32], int is224 );
|
||||
|
||||
//
|
||||
|
||||
/**
|
||||
* \brief SHA-512 context structure
|
||||
*/
|
||||
|
||||
/**
|
||||
* \brief Initialize SHA-512 context
|
||||
* @note If sha_type is SHA2_384, only 48 bytes of state will be read.
|
||||
* This is enough for the final SHA2_384 digest, but if you want the
|
||||
* interim SHA-384 state (to continue digesting) then pass SHA2_512 instead.
|
||||
*
|
||||
* @param sha_type SHA algorithm in use.
|
||||
*
|
||||
* @param state Pointer to a memory buffer to hold the SHA state. Size
|
||||
* is 20 bytes (SHA1), 32 bytes (SHA2_256), 48 bytes (SHA2_384) or 64 bytes (SHA2_512).
|
||||
*
|
||||
* \param ctx SHA-512 context to be initialized
|
||||
*/
|
||||
void esp_sha512_init( esp_sha_context *ctx );
|
||||
void esp_sha_read_digest_state(esp_sha_type sha_type, void *digest_state);
|
||||
|
||||
/**
|
||||
* \brief Clear SHA-512 context
|
||||
* @brief Obtain exclusive access to a particular SHA engine
|
||||
*
|
||||
* \param ctx SHA-512 context to be cleared
|
||||
* @param sha_type Type of SHA engine to use.
|
||||
*
|
||||
* Blocks until engine is available. Note: Can block indefinitely
|
||||
* while a TLS connection is open, suggest using
|
||||
* esp_sha_try_lock_engine() and failing over to software SHA.
|
||||
*/
|
||||
void esp_sha512_free( esp_sha_context *ctx );
|
||||
void esp_sha_lock_engine(esp_sha_type sha_type);
|
||||
|
||||
/**
|
||||
* \brief Clone (the state of) a SHA-512 context
|
||||
* @brief Try and obtain exclusive access to a particular SHA engine
|
||||
*
|
||||
* \param dst The destination context
|
||||
* \param src The context to be cloned
|
||||
* @param sha_type Type of SHA engine to use.
|
||||
*
|
||||
* @return Returns true if the SHA engine is locked for exclusive
|
||||
* use. Call esp_sha_unlock_sha_engine() when done. Returns false if
|
||||
* the SHA engine is already in use, caller should use software SHA
|
||||
* algorithm for this digest.
|
||||
*/
|
||||
void esp_sha512_clone( esp_sha_context *dst, const esp_sha_context *src );
|
||||
bool esp_sha_try_lock_engine(esp_sha_type sha_type);
|
||||
|
||||
/**
|
||||
* \brief SHA-512 context setup
|
||||
* @brief Unlock an engine previously locked with esp_sha_lock_engine() or esp_sha_try_lock_engine()
|
||||
*
|
||||
* \param ctx context to be initialized
|
||||
* \param is384 0 = use SHA512, 1 = use SHA384
|
||||
* @param sha_type Type of engine to release.
|
||||
*/
|
||||
void esp_sha512_start( esp_sha_context *ctx, int is384 );
|
||||
void esp_sha_unlock_engine(esp_sha_type sha_type);
|
||||
|
||||
/**
|
||||
* \brief SHA-512 process buffer
|
||||
* @brief Acquire exclusive access to the SHA shared memory block at SHA_TEXT_BASE
|
||||
*
|
||||
* \param ctx SHA-512 context
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
* This memory block is shared across all the SHA algorithm types.
|
||||
*
|
||||
* Caller should have already locked a SHA engine before calling this function.
|
||||
*
|
||||
* Note that it is possible to obtain exclusive access to the memory block even
|
||||
* while it is in use by the SHA engine. Caller should use esp_sha_wait_idle()
|
||||
* to ensure the SHA engine is not reading from the memory block in hardware.
|
||||
*
|
||||
* @note You do not need to lock the memory block before calling esp_sha_block() or esp_sha_read_digest_state(), these functions handle memory block locking internally.
|
||||
*
|
||||
* Call esp_sha_unlock_memory_block() when done.
|
||||
*/
|
||||
void esp_sha512_update( esp_sha_context *ctx, const unsigned char *input, size_t ilen );
|
||||
void esp_sha_lock_memory_block(void);
|
||||
|
||||
/**
|
||||
* \brief SHA-512 final digest
|
||||
* @brief Release exclusive access to the SHA register memory block at SHA_TEXT_BASE
|
||||
*
|
||||
* \param ctx SHA-512 context
|
||||
* \param output SHA-384/512 checksum result
|
||||
*/
|
||||
void esp_sha512_finish( esp_sha_context *ctx, unsigned char output[64] );
|
||||
|
||||
/**
|
||||
* \brief Calculate SHA-512 of input buffer.
|
||||
* Caller should have already locked a SHA engine before calling this function.
|
||||
*
|
||||
* \param input buffer holding the data
|
||||
* \param ilen length of the input data
|
||||
* \param output SHA-384/512 checksum result
|
||||
* \param is384 0 = use SHA512, 1 = use SHA384
|
||||
* Call following esp_sha_lock_memory_block().
|
||||
*/
|
||||
void esp_sha512( const unsigned char *input, size_t ilen, unsigned char output[64], int is384 );
|
||||
void esp_sha_unlock_memory_block(void);
|
||||
|
||||
//
|
||||
/** @brief Wait for the SHA engine to finish any current operation
|
||||
*
|
||||
* @note This function does not ensure exclusive access to any SHA
|
||||
* engine. Caller should use esp_sha_try_lock_engine() and
|
||||
* esp_sha_lock_memory_block() as required.
|
||||
*
|
||||
* @note Functions declared in this header file wait for SHA engine
|
||||
* completion automatically, so you don't need to use this API for
|
||||
* these. However if accessing SHA registers directly, you will need
|
||||
* to call this before accessing SHA registers if using the
|
||||
* esp_sha_block() function.
|
||||
*
|
||||
* @note This function busy-waits, so wastes CPU resources.
|
||||
* Best to delay calling until you are about to need it.
|
||||
*
|
||||
*/
|
||||
void esp_sha_wait_idle(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -605,6 +605,14 @@ void intr_matrix_set(int cpu_no, uint32_t model_num, uint32_t intr_num);
|
|||
|
||||
#define ETS_MEM_BAR() asm volatile ( "" : : : "memory" )
|
||||
|
||||
typedef enum {
|
||||
OK = 0,
|
||||
FAIL,
|
||||
PENDING,
|
||||
BUSY,
|
||||
CANCEL,
|
||||
} STATUS;
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
/*
|
||||
ROM functions for hardware SHA support.
|
||||
|
||||
It is not recommended to use these functions directly,
|
||||
use the wrapper functions in hwcrypto/sha.h instead.
|
||||
|
||||
It is not recommended to use these functions directly. If using
|
||||
them from esp-idf then use the esp_sha_lock_engine() and
|
||||
esp_sha_lock_memory_block() functions in hwcrypto/sha.h to ensure
|
||||
exclusive access.
|
||||
*/
|
||||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
//
|
||||
|
@ -38,6 +39,8 @@ enum SHA_TYPE {
|
|||
SHA2_256,
|
||||
SHA2_384,
|
||||
SHA2_512,
|
||||
|
||||
|
||||
SHA_INVALID = -1,
|
||||
};
|
||||
|
||||
|
|
|
@ -384,7 +384,8 @@ SpiFlashOpResult SPIParamCfg(uint32_t deviceId, uint32_t chip_size, uint32_t blo
|
|||
SpiFlashOpResult SPIEraseChip(void);
|
||||
|
||||
/**
|
||||
* @brief Erase a block of flash.
|
||||
* @brief Erase a 32KB block of flash
|
||||
* Uses SPI flash command 52h.
|
||||
* Please do not call this function in SDK.
|
||||
*
|
||||
* @param uint32_t block_num : Which block to erase.
|
||||
|
@ -411,6 +412,12 @@ SpiFlashOpResult SPIEraseSector(uint32_t sector_num);
|
|||
* @brief Erase some sectors.
|
||||
* Please do not call this function in SDK.
|
||||
*
|
||||
* @note If calling this function, first set
|
||||
* g_rom_flashchip.block_size = 32768; or call SPIParamCfg()
|
||||
* with appropriate parameters. This is due to a ROM bug, the
|
||||
* block erase command in use is a 32KB erase but after reset
|
||||
* the block_size field is incorrectly set to 65536.
|
||||
*
|
||||
* @param uint32_t start_addr : Start addr to erase, should be sector aligned.
|
||||
*
|
||||
* @param uint32_t area_len : Length to erase, should be sector aligned.
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include "esp_types.h"
|
||||
#include "esp_attr.h"
|
||||
#include "ets_sys.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -51,7 +51,10 @@ static inline void cpu_write_itlb(unsigned vpn, unsigned attr)
|
|||
asm volatile ("witlb %1, %0; isync\n" :: "r" (vpn), "r" (attr));
|
||||
}
|
||||
|
||||
/* Make page 0 access raise an exception.
|
||||
/**
|
||||
* @brief Configure memory region protection
|
||||
*
|
||||
* Make page 0 access raise an exception.
|
||||
* Also protect some other unused pages so we can catch weirdness.
|
||||
* Useful attribute values:
|
||||
* 0 — cached, RW
|
||||
|
@ -70,9 +73,7 @@ static inline void cpu_configure_region_protection()
|
|||
cpu_write_itlb(0x20000000, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
/**
|
||||
* @brief Set CPU frequency to the value defined in menuconfig
|
||||
*
|
||||
* Called from cpu_start.c, not intended to be called from other places.
|
||||
|
@ -81,4 +82,16 @@ static inline void cpu_configure_region_protection()
|
|||
*/
|
||||
void esp_set_cpu_freq(void);
|
||||
|
||||
/**
|
||||
* @brief Stall CPU using RTC controller
|
||||
* @param cpu_id ID of the CPU to stall (0 = PRO, 1 = APP)
|
||||
*/
|
||||
void esp_cpu_stall(int cpu_id);
|
||||
|
||||
/**
|
||||
* @brief Un-stall CPU using RTC controller
|
||||
* @param cpu_id ID of the CPU to un-stall (0 = PRO, 1 = APP)
|
||||
*/
|
||||
void esp_cpu_unstall(int cpu_id);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -94,6 +94,16 @@
|
|||
#define DPORT_PERI_RST_EN_V 0xFFFFFFFF
|
||||
#define DPORT_PERI_RST_EN_S 0
|
||||
|
||||
/* The following bits apply to DPORT_PERI_CLK_EN_REG, DPORT_PERI_RST_EN_REG
|
||||
*/
|
||||
#define DPORT_PERI_EN_AES (1<<0)
|
||||
#define DPORT_PERI_EN_SHA (1<<1)
|
||||
#define DPORT_PERI_EN_RSA (1<<2)
|
||||
/* NB: Secure boot reset will hold SHA & AES in reset */
|
||||
#define DPORT_PERI_EN_SECUREBOOT (1<<3)
|
||||
/* NB: Digital signature reset will hold AES & RSA in reset */
|
||||
#define DPORT_PERI_EN_DIGITAL_SIGNATURE (1<<4)
|
||||
|
||||
#define DPORT_WIFI_BB_CFG_REG (DR_REG_DPORT_BASE + 0x024)
|
||||
/* DPORT_WIFI_BB_CFG : R/W ;bitpos:[31:0] ;default: 32'h0 ; */
|
||||
/*description: */
|
||||
|
|
101
components/esp32/include/soc/emac_ex_reg.h
Normal file
101
components/esp32/include/soc/emac_ex_reg.h
Normal file
|
@ -0,0 +1,101 @@
|
|||
// Copyright 2015-2016 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 _EMAC_EX_H_
|
||||
#define _EMAC_EX_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "soc.h"
|
||||
#define REG_EMAC_EX_BASE (DR_REG_EMAC_BASE + 0x800)
|
||||
|
||||
#define EMAC_EX_CLKOUT_CONF_REG (REG_EMAC_EX_BASE + 0x0000)
|
||||
#define EMAC_EX_CLK_OUT_DLY_NUM 0x00000003
|
||||
#define EMAC_EX_CLK_OUT_DLY_NUM_S 8
|
||||
#define EMAC_EX_CLK_OUT_H_DIV_NUM 0x0000000F
|
||||
#define EMAC_EX_CLK_OUT_H_DIV_NUM_S 4
|
||||
#define EMAC_EX_CLK_OUT_DIV_NUM 0x0000000F
|
||||
#define EMAC_EX_CLK_OUT_DIV_NUM_S 0
|
||||
|
||||
#define EMAC_EX_OSCCLK_CONF_REG (REG_EMAC_EX_BASE + 0x0004)
|
||||
#define EMAC_EX_OSC_CLK_SEL (BIT(24))
|
||||
#define EMAC_EX_OSC_CLK_SEL_S 24
|
||||
#define EMAC_EX_OSC_H_DIV_NUM_100M 0x0000003F
|
||||
#define EMAC_EX_OSC_H_DIV_NUM_100M_S 18
|
||||
#define EMAC_EX_OSC_DIV_NUM_100M 0x0000003F
|
||||
#define EMAC_EX_OSC_DIV_NUM_100M_S 12
|
||||
#define EMAC_EX_OSC_H_DIV_NUM_10M 0x0000003F
|
||||
#define EMAC_EX_OSC_H_DIV_NUM_10M_S 6
|
||||
#define EMAC_EX_OSC_DIV_NUM_10M 0x0000003F
|
||||
#define EMAC_EX_OSC_DIV_NUM_10M_S 0
|
||||
|
||||
#define EMAC_EX_CLK_CTRL_REG (REG_EMAC_EX_BASE + 0x0008)
|
||||
#define EMAC_EX_CLK_EN (BIT(5))
|
||||
#define EMAC_EX_CLK_EN_S 5
|
||||
#define EMAC_EX_MII_CLK_RX_EN (BIT(4))
|
||||
#define EMAC_EX_MII_CLK_RX_EN_S 4
|
||||
#define EMAC_EX_MII_CLK_TX_EN (BIT(3))
|
||||
#define EMAC_EX_MII_CLK_TX_EN_S 3
|
||||
#define EMAC_EX_RX_125_CLK_EN (BIT(2))
|
||||
#define EMAC_EX_RX_125_CLK_EN_S 2
|
||||
#define EMAC_EX_INT_OSC_EN (BIT(1))
|
||||
#define EMAC_EX_INT_OSC_EN_S 1
|
||||
#define EMAC_EX_EXT_OSC_EN (BIT(0))
|
||||
#define EMAC_EX_EXT_OSC_EN_S 0
|
||||
|
||||
#define EMAC_EX_PHYINF_CONF_REG (REG_EMAC_EX_BASE + 0x000c)
|
||||
#define EMAC_EX_TX_ERR_OUT_EN (BIT(20))
|
||||
#define EMAC_EX_TX_ERR_OUT_EN_S 20
|
||||
#define EMAC_EX_SCR_SMI_DLY_RX_SYNC (BIT(19))
|
||||
#define EMAC_EX_SCR_SMI_DLY_RX_SYNC_S 19
|
||||
#define EMAC_EX_PMT_CTRL_EN (BIT(18))
|
||||
#define EMAC_EX_PMT_CTRL_EN_S 18
|
||||
#define EMAC_EX_SBD_CLK_GATING_EN (BIT(17))
|
||||
#define EMAC_EX_SBD_CLK_GATING_EN_S 17
|
||||
#define EMAC_EX_SS_MODE (BIT(16))
|
||||
#define EMAC_EX_SS_MODE_S 16
|
||||
#define EMAC_EX_PHY_INTF_SEL 0x00000007
|
||||
#define EMAC_EX_PHY_INTF_SEL_S 13
|
||||
#define EMAC_EX_REVMII_PHY_ADDR 0x0000001F
|
||||
#define EMAC_EX_REVMII_PHY_ADDR_S 8
|
||||
#define EMAC_EX_CORE_PHY_ADDR 0x0000001F
|
||||
#define EMAC_EX_CORE_PHY_ADDR_S 3
|
||||
#define EMAC_EX_SBD_FLOWCTRL (BIT(2))
|
||||
#define EMAC_EX_SBD_FLOWCTRL_S 2
|
||||
#define EMAC_EX_EXT_REVMII_RX_CLK_SEL (BIT(1))
|
||||
#define EMAC_EX_EXT_REVMII_RX_CLK_SEL_S 1
|
||||
#define EMAC_EX_INT_REVMII_RX_CLK_SEL (BIT(0))
|
||||
#define EMAC_EX_INT_REVMII_RX_CLK_SEL_S 0
|
||||
|
||||
#define EMAC_EX_PHY_INTF_RMII 4
|
||||
|
||||
#define EMAC_EX_EMAC_PD_SEL_REG (REG_EMAC_EX_BASE + 0x0010)
|
||||
#define EMAC_EX_RAM_PD_EN 0x00000003
|
||||
#define EMAC_EX_RAM_PD_EN_S 0
|
||||
|
||||
#define EMAC_EX_DATE_REG (REG_EMAC_EX_BASE + 0x00fc)
|
||||
#define EMAC_EX_DATE 0xFFFFFFFF
|
||||
#define EMAC_EX_DATE_S 0
|
||||
#define EMAC_EX_DATE_VERSION 0x16042200
|
||||
|
||||
#define EMAC_CLK_EN_REG 0x3ff000cc
|
||||
#define EMAC_CLK_EN (BIT(14))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
714
components/esp32/include/soc/emac_reg_v2.h
Normal file
714
components/esp32/include/soc/emac_reg_v2.h
Normal file
|
@ -0,0 +1,714 @@
|
|||
// Copyright 2015-2016 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 _EMAC_H_
|
||||
#define _EMAC_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "soc.h"
|
||||
#define REG_EMAC_BASE DR_REG_EMAC_BASE
|
||||
|
||||
#define EMAC_DMABUSMODE_REG (REG_EMAC_BASE + 0x0000)
|
||||
#define EMAC_DMAREBINCRBURST (BIT(31))
|
||||
#define EMAC_DMAREBINCRBURST_S 31
|
||||
#define EMAC_DMACHANNELPRIOWT 0x00000003
|
||||
#define EMAC_DMACHANNELPRIOWT_S 28
|
||||
#define EMAC_DMATXRXPRIO (BIT(27))
|
||||
#define EMAC_DMATXRXPRIO_S 27
|
||||
#define EMAC_DMAMIXEDBURST (BIT(26))
|
||||
#define EMAC_DMAMIXEDBURST_S 26
|
||||
#define EMAC_DMAADDRALIBEA (BIT(25))
|
||||
#define EMAC_DMAADDRALIBEA_S 25
|
||||
#define EMAC_PBLX8_MODE (BIT(24))
|
||||
#define EMAC_PBLX8_MODE_S 24
|
||||
#define EMAC_USE_SEP_PBL (BIT(23))
|
||||
#define EMAC_USE_SEP_PBL_S 23
|
||||
#define EMAC_RX_DMA_PBL 0x0000003F
|
||||
#define EMAC_RX_DMA_PBL_S 17
|
||||
#define EMAC_FIXED_BURST (BIT(16))
|
||||
#define EMAC_FIXED_BURST_S 16
|
||||
#define EMAC_PRI_RATIO 0x00000003
|
||||
#define EMAC_PRI_RATIO_S 14
|
||||
#define EMAC_PROG_BURST_LEN 0x0000003F
|
||||
#define EMAC_PROG_BURST_LEN_S 8
|
||||
#define EMAC_ALT_DESC_SIZE (BIT(7))
|
||||
#define EMAC_ALT_DESC_SIZE_S 7
|
||||
#define EMAC_DESC_SKIP_LEN 0x0000001F
|
||||
#define EMAC_DESC_SKIP_LEN_S 2
|
||||
#define EMAC_DMA_ARB_SCH (BIT(1))
|
||||
#define EMAC_DMA_ARB_SCH_S 1
|
||||
#define EMAC_SW_RST (BIT(0))
|
||||
#define EMAC_SW_RST_S 0
|
||||
|
||||
#define EMAC_DMATXPOLLDEMAND_REG (REG_EMAC_BASE + 0x0004)
|
||||
#define EMAC_TRANS_POLL_DEMAND 0xFFFFFFFF
|
||||
#define EMAC_TRANS_POLL_DEMAND_S 0
|
||||
|
||||
#define EMAC_DMARXPOLLDEMAND_REG (REG_EMAC_BASE + 0x0008)
|
||||
#define EMAC_RECV_POLL_DEMAND 0xFFFFFFFF
|
||||
#define EMAC_RECV_POLL_DEMAND_S 0
|
||||
|
||||
#define EMAC_DMARXBASEADDR_REG (REG_EMAC_BASE + 0x000C)
|
||||
#define EMAC_START_RECV_LIST 0xFFFFFFFF
|
||||
#define EMAC_START_RECV_LIST_S 0
|
||||
|
||||
#define EMAC_DMATXBASEADDR_REG (REG_EMAC_BASE + 0x0010)
|
||||
#define EMAC_START_TRANS_LIST 0xFFFFFFFF
|
||||
#define EMAC_START_TRANS_LIST_S 0
|
||||
|
||||
#define EMAC_DMASTATUS_REG (REG_EMAC_BASE + 0x0014)
|
||||
#define EMAC_GMAC_LPI_INT (BIT(30))
|
||||
#define EMAC_GMAC_LPI_INT_S 30
|
||||
#define EMAC_TS_TRI_INT (BIT(29))
|
||||
#define EMAC_TS_TRI_INT_S 29
|
||||
#define EMAC_GMAC_PMT_INT (BIT(28))
|
||||
#define EMAC_GMAC_PMT_INT_S 28
|
||||
#define EMAC_GMAC_MMC_INT (BIT(27))
|
||||
#define EMAC_GMAC_MMC_INT_S 27
|
||||
#define EMAC_GMAC_LINE_INF_INT (BIT(26))
|
||||
#define EMAC_GMAC_LINE_INF_INT_S 26
|
||||
#define EMAC_ERROR_BITS 0x00000007
|
||||
#define EMAC_ERROR_BITS_S 23
|
||||
#define EMAC_TRANS_PROC_STATE 0x00000007
|
||||
#define EMAC_TRANS_PROC_STATE_S 20
|
||||
#define EMAC_RECV_PROC_STATE 0x00000007
|
||||
#define EMAC_RECV_PROC_STATE_S 17
|
||||
#define EMAC_NORM_INT_SUMM (BIT(16))
|
||||
#define EMAC_NORM_INT_SUMM_S 16
|
||||
#define EMAC_ABN_INT_SUMM (BIT(15))
|
||||
#define EMAC_ABN_INT_SUMM_S 15
|
||||
#define EMAC_EARLY_RECV_INT (BIT(14))
|
||||
#define EMAC_EARLY_RECV_INT_S 14
|
||||
#define EMAC_FATAL_BUS_ERR_INT (BIT(13))
|
||||
#define EMAC_FATAL_BUS_ERR_INT_S 13
|
||||
#define EMAC_EARLY_TRANS_INT (BIT(10))
|
||||
#define EMAC_EARLY_TRANS_INT_S 10
|
||||
#define EMAC_RECV_WDT_TO (BIT(9))
|
||||
#define EMAC_RECV_WDT_TO_S 9
|
||||
#define EMAC_RECV_PROC_STOP (BIT(8))
|
||||
#define EMAC_RECV_PROC_STOP_S 8
|
||||
#define EMAC_RECV_BUF_UNAVAIL (BIT(7))
|
||||
#define EMAC_RECV_BUF_UNAVAIL_S 7
|
||||
#define EMAC_RECV_INT (BIT(6))
|
||||
#define EMAC_RECV_INT_S 6
|
||||
#define EMAC_TRANS_UNDFLOW (BIT(5))
|
||||
#define EMAC_TRANS_UNDFLOW_S 5
|
||||
#define EMAC_RECV_OVFLOW (BIT(4))
|
||||
#define EMAC_RECV_OVFLOW_S 4
|
||||
#define EMAC_TRANS_JABBER_TO (BIT(3))
|
||||
#define EMAC_TRANS_JABBER_TO_S 3
|
||||
#define EMAC_TRANS_BUF_UNAVAIL (BIT(2))
|
||||
#define EMAC_TRANS_BUF_UNAVAIL_S 2
|
||||
#define EMAC_TRANS_PROC_STOP (BIT(1))
|
||||
#define EMAC_TRANS_PROC_STOP_S 1
|
||||
#define EMAC_TRANS_INT (BIT(0))
|
||||
#define EMAC_TRANS_INT_S 0
|
||||
|
||||
#define EMAC_DMAOPERATION_MODE_REG (REG_EMAC_BASE + 0x0018)
|
||||
#define EMAC_DIS_DROP_TCPIP_CHKSUM_ERR_FRAM (BIT(26))
|
||||
#define EMAC_DIS_DROP_TCPIP_CHKSUM_ERR_FRAM_S 26
|
||||
#define EMAC_RECV_STORE_FORWARD (BIT(25))
|
||||
#define EMAC_RECV_STORE_FORWARD_S 25
|
||||
#define EMAC_DIS_FLUSH_RECV_FRAMES (BIT(24))
|
||||
#define EMAC_DIS_FLUSH_RECV_FRAMES_S 24
|
||||
#define EMAC_MSB_THRESHOLD_ACTIVATING_FLOW_CONTROL (BIT(23))
|
||||
#define EMAC_MSB_THRESHOLD_ACTIVATING_FLOW_CONTROL_S 23
|
||||
#define EMAC_MSB_THRESHOLD_DEACTIVATING_FLOW_CONTROL (BIT(22))
|
||||
#define EMAC_MSB_THRESHOLD_DEACTIVATING_FLOW_CONTROL_S 22
|
||||
#define EMAC_TRANSMIT_STORE_FORWARD (BIT(21))
|
||||
#define EMAC_TRANSMIT_STORE_FORWARD_S 21
|
||||
#define EMAC_FLUSH_TRANSMIT_FIFO (BIT(20))
|
||||
#define EMAC_FLUSH_TRANSMIT_FIFO_S 20
|
||||
#define EMAC_TRANSMIT_THRESHOLD_CONTROL 0x00000007
|
||||
#define EMAC_TRANSMIT_THRESHOLD_CONTROL_S 14
|
||||
#define EMAC_START_STOP_TRANSMISSION_COMMAND (BIT(13))
|
||||
#define EMAC_START_STOP_TRANSMISSION_COMMAND_S 13
|
||||
#define EMAC_THRESHOLD_DEACTIVATING_FLOW_CONTROL 0x00000003
|
||||
#define EMAC_THRESHOLD_DEACTIVATING_FLOW_CONTROL_S 11
|
||||
#define EMAC_THRESHOLD_ACTIVATING_FLOW_CONTROL 0x00000003
|
||||
#define EMAC_THRESHOLD_ACTIVATING_FLOW_CONTROL_S 9
|
||||
#define EMAC_ENABLE_HW_FLOW_CONTROL (BIT(8))
|
||||
#define EMAC_ENABLE_HW_FLOW_CONTROL_S 8
|
||||
#define EMAC_FORWARD_ERROR_FRAMES (BIT(7))
|
||||
#define EMAC_FORWARD_ERROR_FRAMES_S 7
|
||||
#define EMAC_FORWARD_UNDERSIZED_GOOD_FRAMES (BIT(6))
|
||||
#define EMAC_FORWARD_UNDERSIZED_GOOD_FRAMES_S 6
|
||||
#define EMAC_DROP_GIANT_FRAMES (BIT(5))
|
||||
#define EMAC_DROP_GIANT_FRAMES_S 5
|
||||
#define EMAC_RECEIVE_THRESHOLD_CONTROL 0x00000003
|
||||
#define EMAC_RECEIVE_THRESHOLD_CONTROL_S 3
|
||||
#define EMAC_OPERATE_SECOND_FRAME (BIT(2))
|
||||
#define EMAC_OPERATE_SECOND_FRAME_S 2
|
||||
#define EMAC_START_STOP_RECEIVE (BIT(1))
|
||||
#define EMAC_START_STOP_RECEIVE_S 1
|
||||
|
||||
#define EMAC_DMAINTERRUPT_EN_REG (REG_EMAC_BASE + 0x001C)
|
||||
#define EMAC_NORMAL_INTERRUPT_SUMMARY_ENABLE (BIT(16))
|
||||
#define EMAC_NORMAL_INTERRUPT_SUMMARY_ENABLE_S 16
|
||||
#define EMAC_ABNORMAL_INTERRUPT_SUMMARY_ENABLE (BIT(15))
|
||||
#define EMAC_ABNORMAL_INTERRUPT_SUMMARY_ENABLE_S 15
|
||||
#define EMAC_EARLY_RECEIVE_INTERRUPT_ENABLE (BIT(14))
|
||||
#define EMAC_EARLY_RECEIVE_INTERRUPT_ENABLE_S 14
|
||||
#define EMAC_FATAL_BUS_ERROR_ENABLE (BIT(13))
|
||||
#define EMAC_FATAL_BUS_ERROR_ENABLE_S 13
|
||||
#define EMAC_EARLY_TRANSMIT_INTERRUPT_ENABLE (BIT(10))
|
||||
#define EMAC_EARLY_TRANSMIT_INTERRUPT_ENABLE_S 10
|
||||
#define EMAC_RECEIVE_WATCHDOG_TIMEOUT_ENABLE (BIT(9))
|
||||
#define EMAC_RECEIVE_WATCHDOG_TIMEOUT_ENABLE_S 9
|
||||
#define EMAC_RECEIVE_STOPPED_ENABLE (BIT(8))
|
||||
#define EMAC_RECEIVE_STOPPED_ENABLE_S 8
|
||||
#define EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE (BIT(7))
|
||||
#define EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE_S 7
|
||||
#define EMAC_RECEIVE_INTERRUPT_ENABLE (BIT(6))
|
||||
#define EMAC_RECEIVE_INTERRUPT_ENABLE_S 6
|
||||
#define EMAC_UNDERFLOW_INTERRUPT_ENABLE (BIT(5))
|
||||
#define EMAC_UNDERFLOW_INTERRUPT_ENABLE_S 5
|
||||
#define EMAC_OVERFLOW_INTERRUPT_ENABLE (BIT(4))
|
||||
#define EMAC_OVERFLOW_INTERRUPT_ENABLE_S 4
|
||||
#define EMAC_TRANSMIT_JABBER_TIMEOUT_ENABLE (BIT(3))
|
||||
#define EMAC_TRANSMIT_JABBER_TIMEOUT_ENABLE_S 3
|
||||
#define EMAC_TRANSMIT_BUFFER_UNAVAILABLE_ENABLE (BIT(2))
|
||||
#define EMAC_TRANSMIT_BUFFER_UNAVAILABLE_ENABLE_S 2
|
||||
#define EMAC_TRANSMIT_STOPPED_ENABLE (BIT(1))
|
||||
#define EMAC_TRANSMIT_STOPPED_ENABLE_S 1
|
||||
#define EMAC_TRANSMIT_INTERRUPT_ENABLE (BIT(0))
|
||||
#define EMAC_TRANSMIT_INTERRUPT_ENABLE_S 0
|
||||
|
||||
#define EMAC_DMAMISSEDFR_REG (REG_EMAC_BASE + 0x0020)
|
||||
#define EMAC_OVERFLOW_BIT_FIFO_OVERFLOW_COUNTER (BIT(28))
|
||||
#define EMAC_OVERFLOW_BIT_FIFO_OVERFLOW_COUNTER_S 28
|
||||
#define EMAC_OVERFLOW_FRAME_COUNTER 0x000007FF
|
||||
#define EMAC_OVERFLOW_FRAME_COUNTER_S 17
|
||||
#define EMAC_OVERFLOW_BIT_MISSED_FRAME_COUNTER (BIT(16))
|
||||
#define EMAC_OVERFLOW_BIT_MISSED_FRAME_COUNTER_S 16
|
||||
#define EMAC_MISSED_FRAME_COUNTER 0x0000FFFF
|
||||
#define EMAC_MISSED_FRAME_COUNTER_S 0
|
||||
|
||||
#define EMAC_DMARECEIVE_INTERRUPT_WATCHDOG_TIMER_REG (REG_EMAC_BASE + 0x0024)
|
||||
#define EMAC_RI_WATCHDOG_TIMER_COUNT 0x000000FF
|
||||
#define EMAC_RI_WATCHDOG_TIMER_COUNT_S 0
|
||||
|
||||
#define EMAC_DMATXCURRDESC_REG (REG_EMAC_BASE + 0x0048)
|
||||
#define EMAC_HOST_TRANSMIT_DESCRIPTOR_ADDRESS_POINTER 0xFFFFFFFF
|
||||
#define EMAC_HOST_TRANSMIT_DESCRIPTOR_ADDRESS_POINTER_S 0
|
||||
|
||||
#define EMAC_DMARXCURRDESC_REG (REG_EMAC_BASE + 0x004C)
|
||||
#define EMAC_HOST_RECEIVE_DESCRIPTOR_ADDRESS_POINTER 0xFFFFFFFF
|
||||
#define EMAC_HOST_RECEIVE_DESCRIPTOR_ADDRESS_POINTER_S 0
|
||||
|
||||
#define EMAC_DMATXCURRADDR_BUF_REG (REG_EMAC_BASE + 0x0050)
|
||||
#define EMAC_HOST_TRANSMIT_BUFFER_ADDRESS_POINTER 0xFFFFFFFF
|
||||
#define EMAC_HOST_TRANSMIT_BUFFER_ADDRESS_POINTER_S 0
|
||||
|
||||
#define EMAC_DMARXCURRADDR_BUF_REG (REG_EMAC_BASE + 0x0054)
|
||||
#define EMAC_HOST_RECEIVE_BUFFER_ADDRESS_POINTER 0xFFFFFFFF
|
||||
#define EMAC_HOST_RECEIVE_BUFFER_ADDRESS_POINTER_S 0
|
||||
|
||||
#define EMAC_DMAHWFEATURE_REG (REG_EMAC_BASE + 0x0058)
|
||||
#define EMAC_SELECTED_PHY_INTERFACE 0x00000007
|
||||
#define EMAC_SELECTED_PHY_INTERFACE_S 28
|
||||
#define EMAC_SOURCE_ADDRESS_VLAN_INSERTION (BIT(27))
|
||||
#define EMAC_SOURCE_ADDRESS_VLAN_INSERTION_S 27
|
||||
#define EMAC_FLEXIBLE_PULSE_PER_SECOND_OUTPUT (BIT(26))
|
||||
#define EMAC_FLEXIBLE_PULSE_PER_SECOND_OUTPUT_S 26
|
||||
#define EMAC_TIMESTAMPING_INTERNAL_SYSTEM_TIME (BIT(25))
|
||||
#define EMAC_TIMESTAMPING_INTERNAL_SYSTEM_TIME_S 25
|
||||
#define EMAC_ENHANCED_DESCRIPTOR (BIT(24))
|
||||
#define EMAC_ENHANCED_DESCRIPTOR_S 24
|
||||
#define EMAC_NUMBER_ADDITIONAL_TX_CHANNELS 0x00000003
|
||||
#define EMAC_NUMBER_ADDITIONAL_TX_CHANNELS_S 22
|
||||
#define EMAC_NUMBER_ADDITIONAL_RX_CHANNELS 0x00000003
|
||||
#define EMAC_NUMBER_ADDITIONAL_RX_CHANNELS_S 20
|
||||
#define EMAC_RXFIFOSIZE (BIT(19))
|
||||
#define EMAC_RXFIFOSIZE_S 19
|
||||
#define EMAC_IP_CHECKSUM_OFFLOAD_TYPE2 (BIT(18))
|
||||
#define EMAC_IP_CHECKSUM_OFFLOAD_TYPE2_S 18
|
||||
#define EMAC_IP_CHECKSUM_OFFLOAD_TYPE1 (BIT(17))
|
||||
#define EMAC_IP_CHECKSUM_OFFLOAD_TYPE1_S 17
|
||||
#define EMAC_CHECKSUM_OFFLOAD_TX (BIT(16))
|
||||
#define EMAC_CHECKSUM_OFFLOAD_TX_S 16
|
||||
#define EMAC_AV_FEATURE_SEL (BIT(15))
|
||||
#define EMAC_AV_FEATURE_SEL_S 15
|
||||
#define EMAC_EEE_SEL (BIT(14))
|
||||
#define EMAC_EEE_SEL_S 14
|
||||
#define EMAC_TSVER2_SEL (BIT(13))
|
||||
#define EMAC_TSVER2_SEL_S 13
|
||||
#define EMAC_TSVER1_SEL (BIT(12))
|
||||
#define EMAC_TSVER1_SEL_S 12
|
||||
#define EMAC_MMC_SEL (BIT(11))
|
||||
#define EMAC_MMC_SEL_S 11
|
||||
#define EMAC_MGK_SEL (BIT(10))
|
||||
#define EMAC_MGK_SEL_S 10
|
||||
#define EMAC_RWK_SEL (BIT(9))
|
||||
#define EMAC_RWK_SEL_S 9
|
||||
#define EMAC_SMA_SEL (BIT(8))
|
||||
#define EMAC_SMA_SEL_S 8
|
||||
#define EMAC_L3L4FLTR_EN (BIT(7))
|
||||
#define EMAC_L3L4FLTR_EN_S 7
|
||||
#define EMAC_PCS_SEL (BIT(6))
|
||||
#define EMAC_PCS_SEL_S 6
|
||||
#define EMAC_ADDMACADR_SEL (BIT(5))
|
||||
#define EMAC_ADDMACADR_SEL_S 5
|
||||
#define EMAC_HASH_SEL (BIT(4))
|
||||
#define EMAC_HASH_SEL_S 4
|
||||
#define EMAC_EXTHASH_EN (BIT(3))
|
||||
#define EMAC_EXTHASH_EN_S 3
|
||||
#define EMAC_HD_SEL (BIT(2))
|
||||
#define EMAC_HD_SEL_S 2
|
||||
#define EMAC_GMII_SEL (BIT(1))
|
||||
#define EMAC_GMII_SEL_S 1
|
||||
#define EMAC_MII_SEL (BIT(0))
|
||||
#define EMAC_MII_SEL_S 0
|
||||
|
||||
#define EMAC_DMASLOTFNCTRLSTS_REG (REG_EMAC_BASE + 0x0130)
|
||||
#define EMAC_REFERENCE_SLOT_NUMBER 0x0000000F
|
||||
#define EMAC_REFERENCE_SLOT_NUMBER_S 16
|
||||
#define EMAC_ADVANCE_SLOT_CHECK (BIT(1))
|
||||
#define EMAC_ADVANCE_SLOT_CHECK_S 1
|
||||
#define EMAC_ENABLE_SLOT_COMPARISON (BIT(0))
|
||||
#define EMAC_ENABLE_SLOT_COMPARISON_S 0
|
||||
|
||||
#define EMAC_DMACHANNELCTRL_REG (REG_EMAC_BASE + 0x0160)
|
||||
#define EMAC_AVERAGE_BITS_PER_SLOT_INTERRUPT_ENABLE (BIT(17))
|
||||
#define EMAC_AVERAGE_BITS_PER_SLOT_INTERRUPT_ENABLE_S 17
|
||||
#define EMAC_SLOT_COUNT 0x00000007
|
||||
#define EMAC_SLOT_COUNT_S 4
|
||||
#define EMAC_CREDIT_CONTROL (BIT(1))
|
||||
#define EMAC_CREDIT_CONTROL_S 1
|
||||
#define EMAC_CREDIT_BASED_SHAPER_DISABLE (BIT(0))
|
||||
#define EMAC_CREDIT_BASED_SHAPER_DISABLE_S 0
|
||||
|
||||
#define EMAC_DMACHANNELAVSTS_REG (REG_EMAC_BASE + 0x0064)
|
||||
#define EMAC_ABS_UPDATED (BIT(17))
|
||||
#define EMAC_ABS_UPDATED_S 17
|
||||
#define EMAC_AVERAGE_BITS_PER_SLOT 0x0001FFFF
|
||||
#define EMAC_AVERAGE_BITS_PER_SLOT_S 0
|
||||
|
||||
#define EMAC_DMAIDLESLOPECREDIT_REG (REG_EMAC_BASE + 0x0068)
|
||||
#define EMAC_IDLESLOPECREDIT 0x00003FFF
|
||||
#define EMAC_IDLESLOPECREDIT_S 0
|
||||
|
||||
#define EMAC_DMASENDSLOPECREDIT_REG (REG_EMAC_BASE + 0x006C)
|
||||
#define EMAC_SENDSLOPECREDIT 0x00003FFF
|
||||
#define EMAC_SENDSLOPECREDIT_S 0
|
||||
|
||||
#define EMAC_DMAHIGHCREDIT_REG (REG_EMAC_BASE + 0x0070)
|
||||
#define EMAC_HICREDIT 0x1FFFFFFF
|
||||
#define EMAC_HICREDIT_S 0
|
||||
|
||||
#define EMAC_DMALOCREDIT_REG (REG_EMAC_BASE + 0x0074)
|
||||
#define EMAC_LOCREDIT 0x1FFFFFFF
|
||||
#define EMAC_LOCREDIT_S 0
|
||||
|
||||
#define EMAC_GMACCONFIG_REG (REG_EMAC_BASE + 0x1000)
|
||||
#define EMAC_SOURCE_ADDRESS_INSERTION_REPLACEMENT_CONTROL 0x00000007
|
||||
#define EMAC_SOURCE_ADDRESS_INSERTION_REPLACEMENT_CONTROL_S 28
|
||||
#define EMAC_AS_SUPPORT_2K_PACKETS (BIT(27))
|
||||
#define EMAC_AS_SUPPORT_2K_PACKETS_S 27
|
||||
#define EMAC_SMII_FORCE_TRANSMIT_ERROR (BIT(26))
|
||||
#define EMAC_SMII_FORCE_TRANSMIT_ERROR_S 26
|
||||
#define EMAC_CRC_STRIPPING_TYPE_FRAMES (BIT(25))
|
||||
#define EMAC_CRC_STRIPPING_TYPE_FRAMES_S 25
|
||||
#define EMAC_TRANSMIT_CONFIGURATION (BIT(24))
|
||||
#define EMAC_TRANSMIT_CONFIGURATION_S 24
|
||||
#define EMAC_GMACWATCHDOG (BIT(23))
|
||||
#define EMAC_GMACWATCHDOG_S 23
|
||||
#define EMAC_GMACJABBER (BIT(22))
|
||||
#define EMAC_GMACJABBER_S 22
|
||||
#define EMAC_GMACFRAMEBURST (BIT(21))
|
||||
#define EMAC_GMACFRAMEBURST_S 21
|
||||
#define EMAC_GMACJUMBOFRAME (BIT(20))
|
||||
#define EMAC_GMACJUMBOFRAME_S 20
|
||||
#define EMAC_GMACINTERFRAMEGAP 0x00000007
|
||||
#define EMAC_GMACINTERFRAMEGAP_S 17
|
||||
#define EMAC_GMACDISABLECRS (BIT(16))
|
||||
#define EMAC_GMACDISABLECRS_S 16
|
||||
#define EMAC_GMACMIIGMII (BIT(15))
|
||||
#define EMAC_GMACMIIGMII_S 15
|
||||
#define EMAC_GMACFESPEED (BIT(14))
|
||||
#define EMAC_GMACFESPEED_S 14
|
||||
#define EMAC_GMACRXOWN (BIT(13))
|
||||
#define EMAC_GMACRXOWN_S 13
|
||||
#define EMAC_GMACLOOPBACK (BIT(12))
|
||||
#define EMAC_GMACLOOPBACK_S 12
|
||||
#define EMAC_GMACDUPLEX (BIT(11))
|
||||
#define EMAC_GMACDUPLEX_S 11
|
||||
#define EMAC_GMACRXIPCOFFLOAD (BIT(10))
|
||||
#define EMAC_GMACRXIPCOFFLOAD_S 10
|
||||
#define EMAC_GMACRETRY (BIT(9))
|
||||
#define EMAC_GMACRETRY_S 9
|
||||
#define EMAC_GMACLINK (BIT(8))
|
||||
#define EMAC_GMACLINK_S 8
|
||||
#define EMAC_GMACPADCRCSTRIP (BIT(7))
|
||||
#define EMAC_GMACPADCRCSTRIP_S 7
|
||||
#define EMAC_GMACBACKOFFLIMIT 0x00000003
|
||||
#define EMAC_GMACBACKOFFLIMIT_S 5
|
||||
#define EMAC_GMACDEFERRALCHECK (BIT(4))
|
||||
#define EMAC_GMACDEFERRALCHECK_S 4
|
||||
#define EMAC_GMACTX (BIT(3))
|
||||
#define EMAC_GMACTX_S 3
|
||||
#define EMAC_GMACRX (BIT(2))
|
||||
#define EMAC_GMACRX_S 2
|
||||
#define EMAC_PREAMBLE_LENGTH_TRANSMIT_FRAMES 0x00000003
|
||||
#define EMAC_PREAMBLE_LENGTH_TRANSMIT_FRAMES_S 0
|
||||
|
||||
#define EMAC_GMACFRAMEFILTER_REG (REG_EMAC_BASE + 0x1004)
|
||||
#define EMAC_RECEIVEALL (BIT(31))
|
||||
#define EMAC_RECEIVEALL_S 31
|
||||
#define EMAC_DROP_NON_TCP_UDP_IP_FRAMES (BIT(21))
|
||||
#define EMAC_DROP_NON_TCP_UDP_IP_FRAMES_S 21
|
||||
#define EMAC_LAYER_3_AND_LAYER_4_FILTER_ENABLE (BIT(20))
|
||||
#define EMAC_LAYER_3_AND_LAYER_4_FILTER_ENABLE_S 20
|
||||
#define EMAC_VLAN_TAG_FILTER_ENABLE (BIT(16))
|
||||
#define EMAC_VLAN_TAG_FILTER_ENABLE_S 16
|
||||
#define EMAC_HASH_OR_PERFECT_FILTE (BIT(10))
|
||||
#define EMAC_HASH_OR_PERFECT_FILTE_S 10
|
||||
#define EMAC_SOURCE_ADDRESS_FILTER_ENABLE (BIT(9))
|
||||
#define EMAC_SOURCE_ADDRESS_FILTER_ENABLE_S 9
|
||||
#define EMAC_SA_INVERSE_FILTERING (BIT(8))
|
||||
#define EMAC_SA_INVERSE_FILTERING_S 8
|
||||
#define EMAC_PASS_CONTROL_FRAMES 0x00000003
|
||||
#define EMAC_PASS_CONTROL_FRAMES_S 6
|
||||
#define EMAC_DISABLE_BROADCAST_FRAMES (BIT(5))
|
||||
#define EMAC_DISABLE_BROADCAST_FRAMES_S 5
|
||||
#define EMAC_PASS_ALL_MULTICAST (BIT(4))
|
||||
#define EMAC_PASS_ALL_MULTICAST_S 4
|
||||
#define EMAC_DA_INVERSE_FILTERING (BIT(3))
|
||||
#define EMAC_DA_INVERSE_FILTERING_S 3
|
||||
#define EMAC_HASH_MULTICAST (BIT(2))
|
||||
#define EMAC_HASH_MULTICAST_S 2
|
||||
#define EMAC_HASH_UNICAST (BIT(1))
|
||||
#define EMAC_HASH_UNICAST_S 1
|
||||
#define EMAC_PROMISCUOUS_MODE (BIT(0))
|
||||
#define EMAC_PROMISCUOUS_MODE_S 0
|
||||
|
||||
#define EMAC_GMACHASHHIGH_REG (REG_EMAC_BASE + 0x1008)
|
||||
#define EMAC_HASH_TABLE_HIGH 0xFFFFFFFF
|
||||
#define EMAC_HASH_TABLE_HIGH_S 0
|
||||
|
||||
#define EMAC_GMACHASHLOW_REG (REG_EMAC_BASE + 0x100C)
|
||||
#define EMAC_HASH_TABLE_LOW 0xFFFFFFFF
|
||||
#define EMAC_HASH_TABLE_LOW_S 0
|
||||
|
||||
#define EMAC_GMACGMIIADDR_REG (REG_EMAC_BASE + 0x1010)
|
||||
#define EMAC_GMIIDEV 0x0000001F
|
||||
#define EMAC_GMIIDEV_S 11
|
||||
#define EMAC_GMIIREG 0x0000001F
|
||||
#define EMAC_GMIIREG_S 6
|
||||
#define EMAC_GMIICSRCLK 0x0000000F
|
||||
#define EMAC_GMIICSRCLK_S 2
|
||||
#define EMAC_GMIIWRITE (BIT(1))
|
||||
#define EMAC_GMIIWRITE_S 1
|
||||
#define EMAC_GMIIBUSY (BIT(0))
|
||||
#define EMAC_GMIIBUSY_S 0
|
||||
|
||||
#define EMAC_GMACGMIIDATA_REG (REG_EMAC_BASE + 0x1014)
|
||||
#define EMAC_GMII_DATA 0x0000FFFF
|
||||
#define EMAC_GMII_DATA_S 0
|
||||
|
||||
#define EMAC_GMACFLOWCONTROL_REG (REG_EMAC_BASE + 0x1018)
|
||||
#define EMAC_PAUSE_TIME 0x0000FFFF
|
||||
#define EMAC_PAUSE_TIME_S 16
|
||||
#define EMAC_DISABLE_ZERO_QUANTA_PAUSE (BIT(7))
|
||||
#define EMAC_DISABLE_ZERO_QUANTA_PAUSE_S 7
|
||||
#define EMAC_PAUSE_LOW_THRESHOLD 0x00000003
|
||||
#define EMAC_PAUSE_LOW_THRESHOLD_S 4
|
||||
#define EMAC_UNICAST_PAUSE_FRAME_DETECT (BIT(3))
|
||||
#define EMAC_UNICAST_PAUSE_FRAME_DETECT_S 3
|
||||
#define EMAC_RECEIVE_FLOW_CONTROL_ENABLE (BIT(2))
|
||||
#define EMAC_RECEIVE_FLOW_CONTROL_ENABLE_S 2
|
||||
#define EMAC_TRANSMIT_FLOW_CONTROL_ENABLE (BIT(1))
|
||||
#define EMAC_TRANSMIT_FLOW_CONTROL_ENABLE_S 1
|
||||
#define EMAC_FLOW_CONTROL_BUSY_BACKPRESSURE_ACTIVATE (BIT(0))
|
||||
#define EMAC_FLOW_CONTROL_BUSY_BACKPRESSURE_ACTIVATE_S 0
|
||||
|
||||
#define EMAC_GMACVLAN_REG (REG_EMAC_BASE + 0x101C)
|
||||
#define EMAC_VLAN_TAG_HASH_TABLE_MATCH_ENABLE (BIT(19))
|
||||
#define EMAC_VLAN_TAG_HASH_TABLE_MATCH_ENABLE_S 19
|
||||
#define EMAC_ENABLE_S_VLAN (BIT(18))
|
||||
#define EMAC_ENABLE_S_VLAN_S 18
|
||||
#define EMAC_VLAN_TAG_INVERSE_MATCH_ENABLE (BIT(17))
|
||||
#define EMAC_VLAN_TAG_INVERSE_MATCH_ENABLE_S 17
|
||||
#define EMAC_ENABLE_VLAN_TAG_COMPARISON (BIT(16))
|
||||
#define EMAC_ENABLE_VLAN_TAG_COMPARISON_S 16
|
||||
#define EMAC_VLAN_TAG_IDENTIFIER_RECEIVE_FRAMES 0x0000FFFF
|
||||
#define EMAC_VLAN_TAG_IDENTIFIER_RECEIVE_FRAMES_S 0
|
||||
|
||||
#define EMAC_GMACVERSION_REG (REG_EMAC_BASE + 0x1020)
|
||||
#define EMAC_USERVER 0x000000FF
|
||||
#define EMAC_USERVER_S 8
|
||||
#define EMAC_SNPSVER 0x000000FF
|
||||
#define EMAC_SNPSVER_S 0
|
||||
|
||||
#define EMAC_GMACDEBUG_REG (REG_EMAC_BASE + 0x1024)
|
||||
#define EMAC_MTL_TXSTATUS_FIFO_FULL_STATUS (BIT(25))
|
||||
#define EMAC_MTL_TXSTATUS_FIFO_FULL_STATUS_S 25
|
||||
#define EMAC_MTL_TX_FIFO_NOT_EMPTY_STATUS (BIT(24))
|
||||
#define EMAC_MTL_TX_FIFO_NOT_EMPTY_STATUS_S 24
|
||||
#define EMAC_MTL_TX_FIFO_WRITE_CONTROLLER_STATUS (BIT(22))
|
||||
#define EMAC_MTL_TX_FIFO_WRITE_CONTROLLER_STATUS_S 22
|
||||
#define EMAC_MTL_TX_FIFO_READ_CONTROLLER_STATUS 0x00000003
|
||||
#define EMAC_MTL_TX_FIFO_READ_CONTROLLER_STATUS_S 20
|
||||
#define EMAC_MAC_TRANSMITTER_PAUSE (BIT(19))
|
||||
#define EMAC_MAC_TRANSMITTER_PAUSE_S 19
|
||||
#define EMAC_MAC_TRANSMIT_FRAME_CONTROLLER_STATUS 0x00000003
|
||||
#define EMAC_MAC_TRANSMIT_FRAME_CONTROLLER_STATUS_S 17
|
||||
#define EMAC_MAC_TRANSMIT_PROTOCOL_ENGINE_STATUS (BIT(16))
|
||||
#define EMAC_MAC_TRANSMIT_PROTOCOL_ENGINE_STATUS_S 16
|
||||
#define EMAC_MTL_RXFIFO_FILL_LEVEL_STATUS 0x00000003
|
||||
#define EMAC_MTL_RXFIFO_FILL_LEVEL_STATUS_S 8
|
||||
#define EMAC_MTL_RXFIFO_READ_CONTROLLER_STATE 0x00000003
|
||||
#define EMAC_MTL_RXFIFO_READ_CONTROLLER_STATE_S 5
|
||||
#define EMAC_MTL_RX_FIFO_WRITE_CONTROLLER_ACTIVE_STATUS (BIT(4))
|
||||
#define EMAC_MTL_RX_FIFO_WRITE_CONTROLLER_ACTIVE_STATUS_S 4
|
||||
#define EMAC_MAC_RECEIVE_FRAME_FIFO_CONTROLLER_STATUS 0x00000003
|
||||
#define EMAC_MAC_RECEIVE_FRAME_FIFO_CONTROLLER_STATUS_S 1
|
||||
#define EMAC_MAC_RECEIVE_PROTOCOL_ENGINE_STATUS (BIT(0))
|
||||
#define EMAC_MAC_RECEIVE_PROTOCOL_ENGINE_STATUS_S 0
|
||||
|
||||
#define EMAC_GMACLPITIMERSCONTROL_REG (REG_EMAC_BASE + 0x1034)
|
||||
#define EMAC_LPI_LS_TIMER 0x000003FF
|
||||
#define EMAC_LPI_LS_TIMER_S 16
|
||||
#define EMAC_LPI_TW_TIMER 0x0000FFFF
|
||||
#define EMAC_LPI_TW_TIMER_S 0
|
||||
|
||||
#define EMAC_GMACINTERRUPTSTATUS_REG (REG_EMAC_BASE + 0x1038)
|
||||
#define EMAC_GPI_INTERRUPT_STATUS (BIT(11))
|
||||
#define EMAC_GPI_INTERRUPT_STATUS_S 11
|
||||
#define EMAC_LPI_INTERRUPT_STATUS (BIT(10))
|
||||
#define EMAC_LPI_INTERRUPT_STATUS_S 10
|
||||
#define EMAC_TIMESTAMP_INTERRUP_STATUS (BIT(9))
|
||||
#define EMAC_TIMESTAMP_INTERRUP_STATUS_S 9
|
||||
#define EMAC_MMC_RECEIVE_CHECKSUM_OFFLOAD_INTERRUPT_STATUS (BIT(7))
|
||||
#define EMAC_MMC_RECEIVE_CHECKSUM_OFFLOAD_INTERRUPT_STATUS_S 7
|
||||
#define EMAC_MMC_TRANSMIT_INTERRUPT_STATUS (BIT(6))
|
||||
#define EMAC_MMC_TRANSMIT_INTERRUPT_STATUS_S 6
|
||||
#define EMAC_MMC_RECEIVE_INTERRUPT_STATUS (BIT(5))
|
||||
#define EMAC_MMC_RECEIVE_INTERRUPT_STATUS_S 5
|
||||
#define EMAC_MMC_INTERRUPT_STATUS (BIT(4))
|
||||
#define EMAC_MMC_INTERRUPT_STATUS_S 4
|
||||
#define EMAC_PMT_INTERRUPT_STATUS (BIT(3))
|
||||
#define EMAC_PMT_INTERRUPT_STATUS_S 3
|
||||
#define EMAC_PCS_AUTO_NEGOTIATION_COMPLETE (BIT(2))
|
||||
#define EMAC_PCS_AUTO_NEGOTIATION_COMPLETE_S 2
|
||||
#define EMAC_PCS_LINK_STATUS_CHANGED (BIT(1))
|
||||
#define EMAC_PCS_LINK_STATUS_CHANGED_S 1
|
||||
#define EMAC_INTERRUPT_STATUS (BIT(0))
|
||||
#define EMAC_INTERRUPT_STATUS_S 0
|
||||
|
||||
#define EMAC_GMACINTERRUPTMASK_REG (REG_EMAC_BASE + 0x103C)
|
||||
#define EMAC_LPI_INTERRUPT_MASK (BIT(10))
|
||||
#define EMAC_LPI_INTERRUPT_MASK_S 10
|
||||
#define EMAC_TIMESTAMP_INTERRUPT_MASK (BIT(9))
|
||||
#define EMAC_TIMESTAMP_INTERRUPT_MASK_S 9
|
||||
#define EMAC_PMT_INTERRUPT_MASK (BIT(3))
|
||||
#define EMAC_PMT_INTERRUPT_MASK_S 3
|
||||
#define EMAC_PCS_AN_COMPLETION_INTERRUPT_MASK (BIT(2))
|
||||
#define EMAC_PCS_AN_COMPLETION_INTERRUPT_MASK_S 2
|
||||
#define EMAC_PCS_LINK_STATUS_INTERRUPT_MASK (BIT(1))
|
||||
#define EMAC_PCS_LINK_STATUS_INTERRUPT_MASK_S 1
|
||||
#define EMAC_INTERRUPT_MASK (BIT(0))
|
||||
#define EMAC_INTERRUPT_MASK_S 0
|
||||
|
||||
#define EMAC_GMACADDR0HIGH_REG (REG_EMAC_BASE + 0x1040)
|
||||
#define EMAC_ADDRESS_ENABLE0 (BIT(31))
|
||||
#define EMAC_ADDRESS_ENABLE0_S 31
|
||||
#define EMAC_MAC_ADDRESS0_HI 0x0000FFFF
|
||||
#define EMAC_MAC_ADDRESS0_HI_S 0
|
||||
|
||||
#define EMAC_GMACADDR0LOW_REG (REG_EMAC_BASE + 0x1044)
|
||||
#define EMAC_MAC_ADDRESS0_LOW 0xFFFFFFFF
|
||||
#define EMAC_MAC_ADDRESS0_LOW_S 0
|
||||
|
||||
#define EMAC_GMACADDR1HIGH_REG (REG_EMAC_BASE + 0x1048)
|
||||
#define EMAC_ADDRESS_ENABLE1 (BIT(31))
|
||||
#define EMAC_ADDRESS_ENABLE1_S 31
|
||||
#define EMAC_SOURCE_ADDRESS (BIT(30))
|
||||
#define EMAC_SOURCE_ADDRESS_S 30
|
||||
#define EMAC_MASK_BYTE_CONTROL 0x0000003F
|
||||
#define EMAC_MASK_BYTE_CONTROL_S 24
|
||||
#define EMAC_MAC_ADDRESS1_HI 0x0000FFFF
|
||||
#define EMAC_MAC_ADDRESS1_HI_S 0
|
||||
|
||||
#define EMAC_GMACADDR1LOW_REG (REG_EMAC_BASE + 0x104C)
|
||||
#define EMAC_MAC_ADDRESS1_LOW 0xFFFFFFFF
|
||||
#define EMAC_MAC_ADDRESS1_LOW_S 0
|
||||
|
||||
#define EMAC_GMAC_AN_CONTROL_REG (REG_EMAC_BASE + 0x10C0)
|
||||
#define EMAC_SGMII_RAL_CONTROL (BIT(18))
|
||||
#define EMAC_SGMII_RAL_CONTROL_S 18
|
||||
#define EMAC_LOCK_REFERENCE (BIT(17))
|
||||
#define EMAC_LOCK_REFERENCE_S 17
|
||||
#define EMAC_ENABLE_COMMA_DETECT (BIT(16))
|
||||
#define EMAC_ENABLE_COMMA_DETECT_S 16
|
||||
#define EMAC_EXTERNAL_LOOPBACK_ENABLE (BIT(14))
|
||||
#define EMAC_EXTERNAL_LOOPBACK_ENABLE_S 14
|
||||
#define EMAC_AUTO_NEGOTIATION_ENABLE (BIT(12))
|
||||
#define EMAC_AUTO_NEGOTIATION_ENABLE_S 12
|
||||
#define EMAC_RESTART_AUTO_NEGOTIATION (BIT(9))
|
||||
#define EMAC_RESTART_AUTO_NEGOTIATION_S 9
|
||||
|
||||
#define EMAC_GMAC_AN_STATUS_REG (REG_EMAC_BASE + 0x10C4)
|
||||
#define EMAC_EXTENDED_STATUS (BIT(8))
|
||||
#define EMAC_EXTENDED_STATUS_S 8
|
||||
#define EMAC_AUTO_NEGOTIATION_COMPLETE (BIT(5))
|
||||
#define EMAC_AUTO_NEGOTIATION_COMPLETE_S 5
|
||||
#define EMAC_AUTO_NEGOTIATION_ABILITY (BIT(3))
|
||||
#define EMAC_AUTO_NEGOTIATION_ABILITY_S 3
|
||||
#define EMAC_LINK_AN_STATUS (BIT(2))
|
||||
#define EMAC_LINK_AN_STATUS_S 2
|
||||
|
||||
#define EMAC_GMAC_AUTO_NEGOTIATION_ADVERTISEMENT_REG (REG_EMAC_BASE + 0x10C8)
|
||||
#define EMAC_ADV_NEXT_PAGE_SUPPORT (BIT(15))
|
||||
#define EMAC_ADV_NEXT_PAGE_SUPPORT_S 15
|
||||
#define EMAC_ADV_REMOTE_FAULT_ENCODING 0x00000003
|
||||
#define EMAC_ADV_REMOTE_FAULT_ENCODING_S 12
|
||||
#define EMAC_ADV_PAUSE_ENCODING 0x00000003
|
||||
#define EMAC_ADV_PAUSE_ENCODING_S 7
|
||||
#define EMAC_ADV_HALF_DUPLEX (BIT(6))
|
||||
#define EMAC_ADV_HALF_DUPLEX_S 6
|
||||
#define EMAC_ADV_FULL_DUPLEX (BIT(5))
|
||||
#define EMAC_ADV_FULL_DUPLEX_S 5
|
||||
|
||||
#define EMAC_GMAC_AUTO_NEGOTIATION_LINK_PARTNER_ABILITY_REG (REG_EMAC_BASE + 0x10CC)
|
||||
#define EMAC_LINK_NEXT_PAGE_SUPPORT (BIT(15))
|
||||
#define EMAC_LINK_NEXT_PAGE_SUPPORT_S 15
|
||||
#define EMAC_LINK_ACKNOWLEDGE (BIT(14))
|
||||
#define EMAC_LINK_ACKNOWLEDGE_S 14
|
||||
#define EMAC_LINK_REMOTE_FAULT_ENCODING 0x00000003
|
||||
#define EMAC_LINK_REMOTE_FAULT_ENCODING_S 12
|
||||
#define EMAC_LINK_PAUSE_ENCODING 0x00000003
|
||||
#define EMAC_LINK_PAUSE_ENCODING_S 7
|
||||
#define EMAC_LINK_HALF_DUPLEX (BIT(6))
|
||||
#define EMAC_LINK_HALF_DUPLEX_S 6
|
||||
#define EMAC_LINK_FULL_DUPLEX (BIT(5))
|
||||
#define EMAC_LINK_FULL_DUPLEX_S 5
|
||||
|
||||
#define EMAC_GMAC_AUTO_NEGOTIATION_EXPANSION_REG (REG_EMAC_BASE + 0x10D0)
|
||||
#define EMAC_NEXT_PAGE_ABILITY (BIT(2))
|
||||
#define EMAC_NEXT_PAGE_ABILITY_S 2
|
||||
#define EMAC_NEW_PAGE_RECEIVED (BIT(1))
|
||||
#define EMAC_NEW_PAGE_RECEIVED_S 1
|
||||
|
||||
#define EMAC_GMAC_TBI_EXTENDED_STATUS_REG (REG_EMAC_BASE + 0x10D4)
|
||||
#define EMAC_1000BASE_X_FULL_DUPLEX_CAPABLE (BIT(15))
|
||||
#define EMAC_1000BASE_X_FULL_DUPLEX_CAPABLE_S 15
|
||||
#define EMAC_1000BASE_X_HALF_DUPLEX_CAPABLE (BIT(14))
|
||||
#define EMAC_1000BASE_X_HALF_DUPLEX_CAPABLE_S 14
|
||||
|
||||
#define EMAC_GMAC_CONTROL_STATUS_REG (REG_EMAC_BASE + 0x10D8)
|
||||
#define EMAC_SMIDRXS (BIT(16))
|
||||
#define EMAC_SMIDRXS_S 16
|
||||
#define EMAC_FALSE_CARRIER_DETECTED (BIT(5))
|
||||
#define EMAC_FALSE_CARRIER_DETECTED_S 5
|
||||
#define EMAC_JABBER_TIMEOUT (BIT(4))
|
||||
#define EMAC_JABBER_TIMEOUT_S 4
|
||||
#define EMAC_LINK_STATUS (BIT(3))
|
||||
#define EMAC_LINK_STATUS_S 3
|
||||
#define EMAC_LINK_SPEED 0x00000003
|
||||
#define EMAC_LINK_SPEED_S 1
|
||||
#define EMAC_LINK_MODE (BIT(0))
|
||||
#define EMAC_LINK_MODE_S 0
|
||||
|
||||
#define EMAC_GMAC_WATCHDOG_TIMEOUT_REG (REG_EMAC_BASE + 0x10DC)
|
||||
#define EMAC_PROGRAMMABLE_WATCHDOG_ENABLE (BIT(16))
|
||||
#define EMAC_PROGRAMMABLE_WATCHDOG_ENABLE_S 16
|
||||
#define EMAC_WATCHDOG_TIMEOUT 0x00003FFF
|
||||
#define EMAC_WATCHDOG_TIMEOUT_S 0
|
||||
|
||||
#define EMAC_GMAC_GENERAL_PURPOSE_IO_REG (REG_EMAC_BASE + 0x10E0)
|
||||
#define EMAC_GPI_TYPE 0x0000000F
|
||||
#define EMAC_GPI_TYPE_S 24
|
||||
#define EMAC_GPI_INTERRUPT_ENABLE 0x0000000F
|
||||
#define EMAC_GPI_INTERRUPT_ENABLE_S 16
|
||||
#define EMAC_GENERAL_PURPOSE_OUTPUT 0x0000000F
|
||||
#define EMAC_GENERAL_PURPOSE_OUTPUT_S 8
|
||||
#define EMAC_GENERAL_PURPOSE_INPUT_STATUS 0x0000000F
|
||||
#define EMAC_GENERAL_PURPOSE_INPUT_STATUS_S 0
|
||||
|
||||
#define EMAC_GMAC_LAYER3_LAYER4_CONTROL0_REG (REG_EMAC_BASE + 0x1400)
|
||||
#define EMAC_LAYER4_DESTINATION_PORT_INVERSE_MATCH_ENABLE (BIT(21))
|
||||
#define EMAC_LAYER4_DESTINATION_PORT_INVERSE_MATCH_ENABLE_S 21
|
||||
#define EMAC_LAYER4_DESTINATION_PORT_MATCH_ENABLE (BIT(20))
|
||||
#define EMAC_LAYER4_DESTINATION_PORT_MATCH_ENABLE_S 20
|
||||
#define EMAC_LAYER4_SOURCE_PORT_INVERSE_MATCH_ENABLE (BIT(19))
|
||||
#define EMAC_LAYER4_SOURCE_PORT_INVERSE_MATCH_ENABLE_S 19
|
||||
#define EMAC_LAYER4_SOURCE_PORT_MATCH_ENABLE (BIT(18))
|
||||
#define EMAC_LAYER4_SOURCE_PORT_MATCH_ENABLE_S 18
|
||||
#define EMAC_LAYER4_PROTOCOL_ENABLE (BIT(16))
|
||||
#define EMAC_LAYER4_PROTOCOL_ENABLE_S 16
|
||||
#define EMAC_LAYER3_IP_DA_HIGHER_BITS_MATCH 0x0000001F
|
||||
#define EMAC_LAYER3_IP_DA_HIGHER_BITS_MATCH_S 11
|
||||
#define EMAC_LAYER3_IP_SA_HIGHER_BITS_MATCH 0x0000001F
|
||||
#define EMAC_LAYER3_IP_SA_HIGHER_BITS_MATCH_S 6
|
||||
#define EMAC_LAYER3_IP_DA_INVERSE_MATCH_ENABLE (BIT(5))
|
||||
#define EMAC_LAYER3_IP_DA_INVERSE_MATCH_ENABLE_S 5
|
||||
#define EMAC_LAYER3_IP_DA_MATCH_ENABLE (BIT(4))
|
||||
#define EMAC_LAYER3_IP_DA_MATCH_ENABLE_S 4
|
||||
#define EMAC_LAYER3_IP_SA_INVERSE_MATCH_ENABLE (BIT(3))
|
||||
#define EMAC_LAYER3_IP_SA_INVERSE_MATCH_ENABLE_S 3
|
||||
#define EMAC_LAYER3_IP_SA_MATCH_ENABLE (BIT(2))
|
||||
#define EMAC_LAYER3_IP_SA_MATCH_ENABLE_S 2
|
||||
#define EMAC_LAYER3_PROTOCOL_ENABLE (BIT(0))
|
||||
#define EMAC_LAYER3_PROTOCOL_ENABLE_S 0
|
||||
|
||||
#define EMAC_GMAC_LAYER4_ADDRESS0_REG (REG_EMAC_BASE + 0x1404)
|
||||
#define EMAC_LAYER4_DESTINATION_PORT_NUMBER_FIELD 0x0000FFFF
|
||||
#define EMAC_LAYER4_DESTINATION_PORT_NUMBER_FIELD_S 16
|
||||
#define EMAC_LAYER4_SOURCE_PORT_NUMBER_FIELD 0x0000FFFF
|
||||
#define EMAC_LAYER4_SOURCE_PORT_NUMBER_FIELD_S 0
|
||||
|
||||
#define EMAC_GMAC_LAYER3_ADDRESS0_REG (REG_EMAC_BASE + 0x1410)
|
||||
#define EMAC_LAYER3_ADDRESS0_FIELD 0xFFFFFFFF
|
||||
#define EMAC_LAYER3_ADDRESS0_FIELD_S 0
|
||||
|
||||
#define EMAC_GMAC_LAYER3_ADDRESS1_REG (REG_EMAC_BASE + 0x1414)
|
||||
#define EMAC_LAYER3_ADDRESS1_FIELD 0xFFFFFFFF
|
||||
#define EMAC_LAYER3_ADDRESS1_FIELD_S 0
|
||||
|
||||
#define EMAC_GMAC_LAYER3_ADDRESS2_REG (REG_EMAC_BASE + 0x1418)
|
||||
#define EMAC_LAYER3_ADDRESS2_FIELD 0xFFFFFFFF
|
||||
#define EMAC_LAYER3_ADDRESS2_FIELD_S 0
|
||||
|
||||
#define EMAC_GMAC_LAYER3_ADDRESS3_REG (REG_EMAC_BASE + 0x141C)
|
||||
#define EMAC_LAYER3_ADDRESS3_FIELD 0xFFFFFFFF
|
||||
#define EMAC_LAYER3_ADDRESS3_FIELD_S 0
|
||||
|
||||
#define EMAC_GMAC_HASH_TABLE0_REG (REG_EMAC_BASE + 0x1500)
|
||||
#define EMAC_FIRST32_BITS_HASH_TABLE 0xFFFFFFFF
|
||||
#define EMAC_FIRST32_BITS_HASH_TABLE_S 0
|
||||
|
||||
#define EMAC_GMAC_VLAN_TAG_INCLUSION_REPLACEMENT_REG (REG_EMAC_BASE + 0x1584)
|
||||
#define EMAC_VLAN_C_VLAN_S_VLAN (BIT(19))
|
||||
#define EMAC_VLAN_C_VLAN_S_VLAN_S 19
|
||||
#define EMAC_VLAN_PRIORITY_CONTROL (BIT(18))
|
||||
#define EMAC_VLAN_PRIORITY_CONTROL_S 18
|
||||
#define EMAC_VLAN_TAG_CONTROL_TRANSMIT_FRAMES 0x00000003
|
||||
#define EMAC_VLAN_TAG_CONTROL_TRANSMIT_FRAMES_S 16
|
||||
#define EMAC_VLAN_TAG_TRANSMIT_FRAMES 0x0000FFFF
|
||||
#define EMAC_VLAN_TAG_TRANSMIT_FRAMES_S 0
|
||||
|
||||
#define EMAC_GMAC_VLAN_HASH_TABLE_REG (REG_EMAC_BASE + 0x1588)
|
||||
#define EMAC_VLAN_HASH_TABLE 0x0000FFFF
|
||||
#define EMAC_VLAN_HASH_TABLE_S 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -30,8 +30,31 @@
|
|||
#define RSA_MULT_MODE_REG (DR_REG_RSA_BASE + 0x80c)
|
||||
#define RSA_MULT_START_REG (DR_REG_RSA_BASE + 0x810)
|
||||
|
||||
#define RSA_INTERRUPT_REG (DR_REG_RSA_BASE + 0X814)
|
||||
#define RSA_INTERRUPT_REG (DR_REG_RSA_BASE + 0x814)
|
||||
|
||||
#define RSA_CLEAN_ADDR (DR_REG_RSA_BASE + 0X818)
|
||||
#define RSA_CLEAN_REG (DR_REG_RSA_BASE + 0x818)
|
||||
|
||||
/* SHA acceleration registers */
|
||||
#define SHA_TEXT_BASE ((DR_REG_SHA_BASE) + 0x00)
|
||||
|
||||
#define SHA_1_START_REG ((DR_REG_SHA_BASE) + 0x80)
|
||||
#define SHA_1_CONTINUE_REG ((DR_REG_SHA_BASE) + 0x84)
|
||||
#define SHA_1_LOAD_REG ((DR_REG_SHA_BASE) + 0x88)
|
||||
#define SHA_1_BUSY_REG ((DR_REG_SHA_BASE) + 0x8c)
|
||||
|
||||
#define SHA_256_START_REG ((DR_REG_SHA_BASE) + 0x90)
|
||||
#define SHA_256_CONTINUE_REG ((DR_REG_SHA_BASE) + 0x94)
|
||||
#define SHA_256_LOAD_REG ((DR_REG_SHA_BASE) + 0x98)
|
||||
#define SHA_256_BUSY_REG ((DR_REG_SHA_BASE) + 0x9c)
|
||||
|
||||
#define SHA_384_START_REG ((DR_REG_SHA_BASE) + 0xa0)
|
||||
#define SHA_384_CONTINUE_REG ((DR_REG_SHA_BASE) + 0xa4)
|
||||
#define SHA_384_LOAD_REG ((DR_REG_SHA_BASE) + 0xa8)
|
||||
#define SHA_384_BUSY_REG ((DR_REG_SHA_BASE) + 0xac)
|
||||
|
||||
#define SHA_512_START_REG ((DR_REG_SHA_BASE) + 0xb0)
|
||||
#define SHA_512_CONTINUE_REG ((DR_REG_SHA_BASE) + 0xb4)
|
||||
#define SHA_512_LOAD_REG ((DR_REG_SHA_BASE) + 0xb8)
|
||||
#define SHA_512_BUSY_REG ((DR_REG_SHA_BASE) + 0xbc)
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1319,6 +1319,36 @@
|
|||
#define PCNT_CORE_STATUS_U0_M ((PCNT_CORE_STATUS_U0_V)<<(PCNT_CORE_STATUS_U0_S))
|
||||
#define PCNT_CORE_STATUS_U0_V 0xFFFFFFFF
|
||||
#define PCNT_CORE_STATUS_U0_S 0
|
||||
/*0: positive value to zero; 1: negative value to zero; 2: counter value negative ; 3: counter value positive*/
|
||||
#define PCNT_STATUS_CNT_MODE 0x3
|
||||
#define PCNT_STATUS_CNT_MODE_M ((PCNT_STATUS_CNT_MODE_V)<<(PCNT_STATUS_CNT_MODE_S))
|
||||
#define PCNT_STATUS_CNT_MODE_V 0x3
|
||||
#define PCNT_STATUS_CNT_MODE_S 0
|
||||
/* counter value equals to thresh1*/
|
||||
#define PCNT_STATUS_THRES1 BIT(2)
|
||||
#define PCNT_STATUS_THRES1_M BIT(2)
|
||||
#define PCNT_STATUS_THRES1_V 0x1
|
||||
#define PCNT_STATUS_THRES1_S 2
|
||||
/* counter value equals to thresh0*/
|
||||
#define PCNT_STATUS_THRES0 BIT(3)
|
||||
#define PCNT_STATUS_THRES0_M BIT(3)
|
||||
#define PCNT_STATUS_THRES0_V 0x1
|
||||
#define PCNT_STATUS_THRES0_S 3
|
||||
/* counter value reaches h_lim*/
|
||||
#define PCNT_STATUS_L_LIM BIT(4)
|
||||
#define PCNT_STATUS_L_LIM_M BIT(4)
|
||||
#define PCNT_STATUS_L_LIM_V 0x1
|
||||
#define PCNT_STATUS_L_LIM_S 4
|
||||
/* counter value reaches l_lim*/
|
||||
#define PCNT_STATUS_H_LIM BIT(5)
|
||||
#define PCNT_STATUS_H_LIM_M BIT(5)
|
||||
#define PCNT_STATUS_H_LIM_V 0x1
|
||||
#define PCNT_STATUS_H_LIM_S 5
|
||||
/* counter value equals to zero*/
|
||||
#define PCNT_STATUS_ZERO BIT(6)
|
||||
#define PCNT_STATUS_ZERO_M BIT(6)
|
||||
#define PCNT_STATUS_ZERO_V 0x1
|
||||
#define PCNT_STATUS_ZERO_S 6
|
||||
|
||||
#define PCNT_U1_STATUS_REG (DR_REG_PCNT_BASE + 0x0094)
|
||||
/* PCNT_CORE_STATUS_U1 : RO ;bitpos:[31:0] ;default: 32'h0 ; */
|
||||
|
|
|
@ -113,7 +113,18 @@ typedef volatile struct {
|
|||
};
|
||||
uint32_t val;
|
||||
} int_clr;
|
||||
uint32_t status_unit[8];
|
||||
union {
|
||||
struct {
|
||||
uint32_t cnt_mode:2; /*0: positive value to zero; 1: negative value to zero; 2: counter value negative ; 3: counter value positive*/
|
||||
uint32_t thres1_lat:1; /* counter value equals to thresh1*/
|
||||
uint32_t thres0_lat:1; /* counter value equals to thresh0*/
|
||||
uint32_t l_lim_lat:1; /* counter value reaches h_lim*/
|
||||
uint32_t h_lim_lat:1; /* counter value reaches l_lim*/
|
||||
uint32_t zero_lat:1; /* counter value equals zero*/
|
||||
uint32_t reserved7:25;
|
||||
};
|
||||
uint32_t val;
|
||||
} status_unit[8];
|
||||
union {
|
||||
struct {
|
||||
uint32_t cnt_rst_u0: 1; /*Set this bit to clear unit0's counter.*/
|
||||
|
|
|
@ -129,10 +129,10 @@
|
|||
//}}
|
||||
|
||||
//Periheral Clock {{
|
||||
#define APB_CLK_FREQ_ROM 26*1000000
|
||||
#define APB_CLK_FREQ_ROM ( 26*1000000 )
|
||||
#define CPU_CLK_FREQ_ROM APB_CLK_FREQ_ROM
|
||||
#define CPU_CLK_FREQ APB_CLK_FREQ
|
||||
#define APB_CLK_FREQ 80*1000000 //unit: Hz
|
||||
#define APB_CLK_FREQ ( 80*1000000 ) //unit: Hz
|
||||
#define UART_CLK_FREQ APB_CLK_FREQ
|
||||
#define WDT_CLK_FREQ APB_CLK_FREQ
|
||||
#define TIMER_CLK_FREQ (80000000>>4) //80MHz divided by 16
|
||||
|
@ -142,6 +142,7 @@
|
|||
|
||||
#define DR_REG_DPORT_BASE 0x3ff00000
|
||||
#define DR_REG_RSA_BASE 0x3ff02000
|
||||
#define DR_REG_SHA_BASE 0x3ff03000
|
||||
#define DR_REG_UART_BASE 0x3ff40000
|
||||
#define DR_REG_SPI1_BASE 0x3ff42000
|
||||
#define DR_REG_SPI0_BASE 0x3ff43000
|
||||
|
@ -270,7 +271,7 @@
|
|||
* 6 1 timer FreeRTOS Tick(L1) FreeRTOS Tick(L1)
|
||||
* 7 1 software Reserved Reserved
|
||||
* 8 1 extern level BLE Controller
|
||||
* 9 1 extern level
|
||||
* 9 1 extern level EMAC
|
||||
* 10 1 extern edge Internal Timer
|
||||
* 11 3 profiling
|
||||
* 12 1 extern level
|
||||
|
@ -302,6 +303,7 @@
|
|||
#define ETS_FROM_CPU_INUM 2
|
||||
#define ETS_T0_WDT_INUM 3
|
||||
#define ETS_WBB_INUM 4
|
||||
#define ETS_EMAC_INUM 9
|
||||
#define ETS_TG0_T1_INUM 10 /**< use edge interrupt*/
|
||||
#define ETS_FRC1_INUM 22
|
||||
#define ETS_T1_WDT_INUM 24
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
|
||||
// Copyright 2010-2016 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
|
||||
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "esp_gap_bt_api.h"
|
||||
#include "bta_api.h"
|
||||
#include "bt_trace.h"
|
||||
#pragma once
|
||||
|
||||
/* Hardware random number generator register */
|
||||
#define WDEV_RND_REG 0x60035144
|
|
@ -42,7 +42,7 @@
|
|||
* share the name with the existing functions from hal.h.
|
||||
* Including this header file will define XTHAL_USE_CACHE_MACROS
|
||||
* which directs hal.h not to use the functions.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Single-cache-line operations in C-callable inline assembly.
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "esp_freertos_hooks.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
#include "soc/timer_group_reg.h"
|
||||
#include "driver/timer.h"
|
||||
|
||||
#include "esp_int_wdt.h"
|
||||
|
||||
|
@ -85,7 +86,7 @@ void esp_int_wdt_init() {
|
|||
TIMERG1.wdt_feed=1;
|
||||
TIMERG1.wdt_wprotect=0;
|
||||
TIMERG1.int_clr_timers.wdt=1;
|
||||
TIMERG1.int_ena.wdt=1;
|
||||
timer_group_intr_enable(TIMER_GROUP_1, TIMG_WDT_INT_ENA_M);
|
||||
esp_register_freertos_tick_hook(tick_hook);
|
||||
ESP_INTR_DISABLE(WDT_INT_NUM);
|
||||
intr_matrix_set(xPortGetCoreID(), ETS_TG1_WDT_LEVEL_INTR_SOURCE, WDT_INT_NUM);
|
||||
|
@ -97,4 +98,4 @@ void esp_int_wdt_init() {
|
|||
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 93fcc0324cd9b4de8ae381a876d371dfd4eff8e3
|
||||
Subproject commit 3a412c08af1ace47a58d1f8722a8fed5b8d3b944
|
133
components/esp32/lib_printf.c
Normal file
133
components/esp32/lib_printf.c
Normal file
|
@ -0,0 +1,133 @@
|
|||
// Copyright 2016 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.
|
||||
|
||||
/**
|
||||
* @file lib_printf.c
|
||||
*
|
||||
* This file contains library-specific printf functions
|
||||
* used by WiFi libraries in the `lib` directory.
|
||||
* These function are used to catch any output which gets printed
|
||||
* by libraries, and redirect it to ESP_LOG macros.
|
||||
*
|
||||
* Eventually WiFi libraries will use ESP_LOG functions internally
|
||||
* and these definitions will be removed.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "esp_log.h"
|
||||
#include "esp_attr.h"
|
||||
|
||||
#define VPRINTF_STACK_BUFFER_SIZE 80
|
||||
|
||||
static int lib_printf(const char* tag, const char* format, va_list arg)
|
||||
{
|
||||
char temp[VPRINTF_STACK_BUFFER_SIZE];
|
||||
int len = vsnprintf(temp, sizeof(temp) - 1, format, arg);
|
||||
temp[sizeof(temp) - 1] = 0;
|
||||
int i;
|
||||
for (i = len - 1; i >= 0; --i) {
|
||||
if (temp[i] != '\n' && temp[i] != '\r' && temp[i] != ' ') {
|
||||
break;
|
||||
}
|
||||
temp[i] = 0;
|
||||
}
|
||||
if (i > 0) {
|
||||
ESP_EARLY_LOGI(tag, "%s", temp);
|
||||
}
|
||||
va_end(arg);
|
||||
return len;
|
||||
}
|
||||
|
||||
int phy_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("phy", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
int rtc_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("rtc", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int wpa_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("wpa", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int wpa2_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("wpa2", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int wps_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("wps", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int pp_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("pp", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int sc_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("smartconfig", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int core_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("core", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
||||
|
||||
int net80211_printf(const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
int res = lib_printf("net80211", format, arg);
|
||||
va_end(arg);
|
||||
return res;
|
||||
}
|
|
@ -27,6 +27,7 @@
|
|||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
#include "soc/timer_group_reg.h"
|
||||
#include "soc/cpu.h"
|
||||
|
||||
#include "esp_gdbstub.h"
|
||||
#include "esp_panic.h"
|
||||
|
@ -108,21 +109,10 @@ static const char *edesc[]={
|
|||
void commonErrorHandler(XtExcFrame *frame);
|
||||
|
||||
//The fact that we've panic'ed probably means the other CPU is now running wild, possibly
|
||||
//messing up the serial output, so we kill it here.
|
||||
static void haltOtherCore() {
|
||||
if (xPortGetCoreID()==0) {
|
||||
//Kill app cpu
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_APPCPU_C1_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, 0x21<<RTC_CNTL_SW_STALL_APPCPU_C1_S);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_APPCPU_C0_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, 2<<RTC_CNTL_SW_STALL_APPCPU_C0_S);
|
||||
} else {
|
||||
//Kill pro cpu
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, RTC_CNTL_SW_STALL_PROCPU_C1_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_SW_CPU_STALL_REG, 0x21<<RTC_CNTL_SW_STALL_PROCPU_C1_S);
|
||||
CLEAR_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_STALL_PROCPU_C0_M);
|
||||
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, 2<<RTC_CNTL_SW_STALL_PROCPU_C0_S);
|
||||
}
|
||||
//messing up the serial output, so we stall it here.
|
||||
static void haltOtherCore()
|
||||
{
|
||||
esp_cpu_stall( xPortGetCoreID() == 0 ? 1 : 0 );
|
||||
}
|
||||
|
||||
//Returns true when a debugger is attached using JTAG.
|
||||
|
|
|
@ -179,7 +179,7 @@ static esp_err_t load_cal_data_from_nvs_handle(nvs_handle handle,
|
|||
return ESP_ERR_INVALID_SIZE;
|
||||
}
|
||||
uint8_t sta_mac[6];
|
||||
system_efuse_read_mac(sta_mac);
|
||||
esp_efuse_read_mac(sta_mac);
|
||||
if (memcmp(sta_mac, cal_data_mac, sizeof(sta_mac)) != 0) {
|
||||
ESP_LOGE(TAG, "%s: calibration data MAC check failed: expected " \
|
||||
MACSTR ", found " MACSTR,
|
||||
|
@ -210,7 +210,7 @@ static esp_err_t store_cal_data_to_nvs_handle(nvs_handle handle,
|
|||
return err;
|
||||
}
|
||||
uint8_t sta_mac[6];
|
||||
system_efuse_read_mac(sta_mac);
|
||||
esp_efuse_read_mac(sta_mac);
|
||||
err = nvs_set_blob(handle, PHY_CAL_MAC_KEY, sta_mac, sizeof(sta_mac));
|
||||
if (err != ESP_OK) {
|
||||
return err;
|
||||
|
|
142
components/esp32/rtc.h
Normal file
142
components/esp32/rtc.h
Normal file
|
@ -0,0 +1,142 @@
|
|||
// Copyright 2015-2016 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.
|
||||
|
||||
/**
|
||||
* @file rtc.h
|
||||
* @brief Declarations of APIs provided by librtc.a
|
||||
*
|
||||
* This file is not in the include directory of esp32 component, so it is not
|
||||
* part of the public API. As the source code of librtc.a is gradually moved
|
||||
* into the ESP-IDF, some of these APIs will be exposed to applications.
|
||||
*
|
||||
* For now, only esp_deep_sleep function declared in esp_deepsleep.h
|
||||
* is part of public API.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "soc/soc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef enum{
|
||||
XTAL_40M = 40,
|
||||
XTAL_26M = 26,
|
||||
XTAL_24M = 24,
|
||||
XTAL_AUTO = 0
|
||||
} xtal_freq_t;
|
||||
|
||||
typedef enum{
|
||||
CPU_XTAL = 0,
|
||||
CPU_80M = 1,
|
||||
CPU_160M = 2,
|
||||
CPU_240M = 3,
|
||||
CPU_2M = 4
|
||||
} cpu_freq_t;
|
||||
|
||||
typedef enum {
|
||||
CALI_RTC_MUX = 0,
|
||||
CALI_8MD256 = 1,
|
||||
CALI_32K_XTAL = 2
|
||||
} cali_clk_t;
|
||||
|
||||
/**
|
||||
* This function must be called to initialize RTC library
|
||||
* @param xtal_freq Frequency of main crystal
|
||||
*/
|
||||
void rtc_init_lite(xtal_freq_t xtal_freq);
|
||||
|
||||
/**
|
||||
* Switch CPU frequency
|
||||
* @param cpu_freq new CPU frequency
|
||||
*/
|
||||
void rtc_set_cpu_freq(cpu_freq_t cpu_freq);
|
||||
|
||||
/**
|
||||
* @brief Return RTC slow clock's period
|
||||
* @param cali_clk clock to calibrate
|
||||
* @param slow_clk_cycles number of slow clock cycles to average
|
||||
* @param xtal_freq chip's main XTAL freq
|
||||
* @return average slow clock period in microseconds, Q13.19 fixed point format
|
||||
*/
|
||||
uint32_t rtc_slowck_cali(cali_clk_t cali_clk, uint32_t slow_clk_cycles);
|
||||
|
||||
/**
|
||||
* @brief Convert from microseconds to slow clock cycles
|
||||
* @param time_in_us_h Time in microseconds, higher 32 bit part
|
||||
* @param time_in_us_l Time in microseconds, lower 32 bit part
|
||||
* @param slow_clk_period Period of slow clock in microseconds, Q13.19 fixed point format (as returned by rtc_slowck_cali).
|
||||
* @param[out] cylces_h output, higher 32 bit part of number of slow clock cycles
|
||||
* @param[out] cycles_l output, lower 32 bit part of number of slow clock cycles
|
||||
*/
|
||||
void rtc_usec2rtc(uint32_t time_in_us_h, uint32_t time_in_us_l, uint32_t slow_clk_period, uint32_t *cylces_h, uint32_t *cycles_l);
|
||||
|
||||
|
||||
#define DEEP_SLEEP_PD_NORMAL BIT(0) /*!< Base deep sleep mode */
|
||||
#define DEEP_SLEEP_PD_RTC_PERIPH BIT(1) /*!< Power down RTC peripherals */
|
||||
#define DEEP_SLEEP_PD_RTC_SLOW_MEM BIT(2) /*!< Power down RTC SLOW memory */
|
||||
#define DEEP_SLEEP_PD_RTC_FAST_MEM BIT(3) /*!< Power down RTC FAST memory */
|
||||
|
||||
/**
|
||||
* @brief Prepare for entering sleep mode
|
||||
* @param deep_slp DEEP_SLEEP_PD_ flags combined with OR (DEEP_SLEEP_PD_NORMAL must be included)
|
||||
* @param cpu_lp_mode for deep sleep, should be 0
|
||||
*/
|
||||
void rtc_slp_prep_lite(uint32_t deep_slp, uint32_t cpu_lp_mode);
|
||||
|
||||
|
||||
#define RTC_EXT_EVENT0_TRIG BIT(0)
|
||||
#define RTC_EXT_EVENT1_TRIG BIT(1)
|
||||
#define RTC_GPIO_TRIG BIT(2)
|
||||
#define RTC_TIMER_EXPIRE BIT(3)
|
||||
#define RTC_SDIO_TRIG BIT(4)
|
||||
#define RTC_MAC_TRIG BIT(5)
|
||||
#define RTC_UART0_TRIG BIT(6)
|
||||
#define RTC_UART1_TRIG BIT(7)
|
||||
#define RTC_TOUCH_TRIG BIT(8)
|
||||
#define RTC_SAR_TRIG BIT(9)
|
||||
#define RTC_BT_TRIG BIT(10)
|
||||
|
||||
|
||||
#define RTC_EXT_EVENT0_TRIG_EN RTC_EXT_EVENT0_TRIG
|
||||
#define RTC_EXT_EVENT1_TRIG_EN RTC_EXT_EVENT1_TRIG
|
||||
#define RTC_GPIO_TRIG_EN RTC_GPIO_TRIG
|
||||
#define RTC_TIMER_EXPIRE_EN RTC_TIMER_EXPIRE
|
||||
#define RTC_SDIO_TRIG_EN RTC_SDIO_TRIG
|
||||
#define RTC_MAC_TRIG_EN RTC_MAC_TRIG
|
||||
#define RTC_UART0_TRIG_EN RTC_UART0_TRIG
|
||||
#define RTC_UART1_TRIG_EN RTC_UART1_TRIG
|
||||
#define RTC_TOUCH_TRIG_EN RTC_TOUCH_TRIG
|
||||
#define RTC_SAR_TRIG_EN RTC_SAR_TRIG
|
||||
#define RTC_BT_TRIG_EN RTC_BT_TRIG
|
||||
|
||||
/**
|
||||
* @brief Enter sleep mode for given number of cycles
|
||||
* @param cycles_h higher 32 bit part of number of slow clock cycles
|
||||
* @param cycles_l lower 32 bit part of number of slow clock cycles
|
||||
* @param wakeup_opt wake up reason to enable (RTC_xxx_EN flags combined with OR)
|
||||
* @param reject_opt reserved, should be 0
|
||||
* @return TBD
|
||||
*/
|
||||
uint32_t rtc_sleep(uint32_t cycles_h, uint32_t cycles_l, uint32_t wakeup_opt, uint32_t reject_opt);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
158
components/esp32/system_api.c
Normal file
158
components/esp32/system_api.c
Normal file
|
@ -0,0 +1,158 @@
|
|||
// Copyright 2013-2016 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 "esp_system.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_wifi.h"
|
||||
#include "esp_wifi_internal.h"
|
||||
#include "esp_log.h"
|
||||
#include "rom/efuse.h"
|
||||
#include "rom/cache.h"
|
||||
#include "rom/uart.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/efuse_reg.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/timer_group_reg.h"
|
||||
#include "soc/timer_group_struct.h"
|
||||
#include "soc/cpu.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/xtensa_api.h"
|
||||
|
||||
static const char* TAG = "system_api";
|
||||
|
||||
void system_init()
|
||||
{
|
||||
}
|
||||
|
||||
esp_err_t esp_efuse_read_mac(uint8_t* mac)
|
||||
{
|
||||
uint8_t efuse_crc;
|
||||
uint8_t calc_crc;
|
||||
uint32_t mac_low = REG_READ(EFUSE_BLK0_RDATA1_REG);
|
||||
uint32_t mac_high = REG_READ(EFUSE_BLK0_RDATA2_REG);
|
||||
|
||||
mac[0] = mac_high >> 8;
|
||||
mac[1] = mac_high;
|
||||
mac[2] = mac_low >> 24;
|
||||
mac[3] = mac_low >> 16;
|
||||
mac[4] = mac_low >> 8;
|
||||
mac[5] = mac_low;
|
||||
|
||||
efuse_crc = mac_high >> 16;
|
||||
calc_crc = esp_crc8(mac, 6);
|
||||
|
||||
if (efuse_crc != calc_crc) {
|
||||
// Small range of MAC addresses are accepted even if CRC is invalid.
|
||||
// These addresses are reserved for Espressif internal use.
|
||||
if ((mac_high & 0xFFFF) == 0x18fe) {
|
||||
if ((mac_low >= 0x346a85c7) && (mac_low <= 0x346a85f8)) {
|
||||
return ESP_OK;
|
||||
}
|
||||
} else {
|
||||
ESP_LOGE(TAG, "MAC address CRC error, efuse_crc = 0x%02x; calc_crc = 0x%02x", efuse_crc, calc_crc);
|
||||
abort();
|
||||
}
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t system_efuse_read_mac(uint8_t mac[6]) __attribute__((alias("esp_efuse_read_mac")));
|
||||
|
||||
|
||||
void IRAM_ATTR esp_restart(void)
|
||||
{
|
||||
esp_wifi_stop();
|
||||
|
||||
// Disable scheduler on this core.
|
||||
vTaskSuspendAll();
|
||||
const uint32_t core_id = xPortGetCoreID();
|
||||
const uint32_t other_core_id = core_id == 0 ? 1 : 0;
|
||||
esp_cpu_stall(other_core_id);
|
||||
|
||||
// We need to disable TG0/TG1 watchdogs
|
||||
// First enable RTC watchdog to be on the safe side
|
||||
REG_WRITE(RTC_CNTL_WDTWPROTECT_REG, RTC_CNTL_WDT_WKEY_VALUE);
|
||||
REG_WRITE(RTC_CNTL_WDTCONFIG0_REG,
|
||||
RTC_CNTL_WDT_FLASHBOOT_MOD_EN_M |
|
||||
(1 << RTC_CNTL_WDT_SYS_RESET_LENGTH_S) |
|
||||
(1 << RTC_CNTL_WDT_CPU_RESET_LENGTH_S) );
|
||||
REG_WRITE(RTC_CNTL_WDTCONFIG1_REG, 128000);
|
||||
|
||||
// Disable TG0/TG1 watchdogs
|
||||
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
|
||||
TIMERG0.wdt_config0.en = 0;
|
||||
TIMERG0.wdt_wprotect=0;
|
||||
TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
|
||||
TIMERG1.wdt_config0.en = 0;
|
||||
TIMERG1.wdt_wprotect=0;
|
||||
|
||||
// Disable all interrupts
|
||||
xt_ints_off(0xFFFFFFFF);
|
||||
|
||||
// Disable cache
|
||||
Cache_Read_Disable(0);
|
||||
Cache_Read_Disable(1);
|
||||
|
||||
// Flush any data left in UART FIFO
|
||||
uart_tx_flush(0);
|
||||
uart_tx_flush(1);
|
||||
uart_tx_flush(2);
|
||||
|
||||
// Reset wifi/bluetooth (bb/mac)
|
||||
SET_PERI_REG_MASK(DPORT_WIFI_RST_EN_REG, 0x1f);
|
||||
REG_WRITE(DPORT_WIFI_RST_EN_REG, 0);
|
||||
|
||||
// Reset timer/spi/uart
|
||||
SET_PERI_REG_MASK(DPORT_PERIP_RST_EN_REG,
|
||||
DPORT_TIMERS_RST | DPORT_SPI_RST_1 | DPORT_UART_RST);
|
||||
REG_WRITE(DPORT_PERIP_RST_EN_REG, 0);
|
||||
|
||||
// Reset CPUs
|
||||
if (core_id == 0) {
|
||||
// Running on PRO CPU: APP CPU is stalled. Can reset both CPUs.
|
||||
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG,
|
||||
RTC_CNTL_SW_PROCPU_RST_M | RTC_CNTL_SW_APPCPU_RST_M);
|
||||
} else {
|
||||
// Running on APP CPU: need to reset PRO CPU and unstall it,
|
||||
// then stall APP CPU
|
||||
SET_PERI_REG_MASK(RTC_CNTL_OPTIONS0_REG, RTC_CNTL_SW_PROCPU_RST_M);
|
||||
esp_cpu_unstall(0);
|
||||
esp_cpu_stall(1);
|
||||
}
|
||||
while(true) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void system_restart(void) __attribute__((alias("esp_restart")));
|
||||
|
||||
void system_restore(void)
|
||||
{
|
||||
esp_wifi_restore();
|
||||
}
|
||||
|
||||
uint32_t esp_get_free_heap_size(void)
|
||||
{
|
||||
return xPortGetFreeHeapSize();
|
||||
}
|
||||
|
||||
uint32_t system_get_free_heap_size(void) __attribute__((alias("esp_get_free_heap_size")));
|
||||
|
||||
const char* system_get_sdk_version(void)
|
||||
{
|
||||
return "master";
|
||||
}
|
||||
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
#include "soc/timer_group_struct.h"
|
||||
#include "soc/timer_group_reg.h"
|
||||
#include "esp_log.h"
|
||||
#include "driver/timer.h"
|
||||
|
||||
#include "esp_task_wdt.h"
|
||||
|
||||
|
@ -204,9 +205,9 @@ void esp_task_wdt_init() {
|
|||
intr_matrix_set(xPortGetCoreID(), ETS_TG0_WDT_LEVEL_INTR_SOURCE, ETS_T0_WDT_INUM);
|
||||
xt_set_interrupt_handler(ETS_T0_WDT_INUM, task_wdt_isr, NULL);
|
||||
TIMERG0.int_clr_timers.wdt=1;
|
||||
TIMERG0.int_ena.wdt=1;
|
||||
timer_group_intr_enable(TIMER_GROUP_0, TIMG_WDT_INT_ENA_M);
|
||||
ESP_INTR_ENABLE(ETS_T0_WDT_INUM);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
menu "TESTS"
|
||||
|
||||
config FP_TEST_ENABLE
|
||||
bool "Enable test fp"
|
||||
default "y"
|
||||
help
|
||||
For FPGA single core CPU which has no floating point support, floating point test should be disabled.
|
||||
|
||||
endmenu
|
|
@ -4,7 +4,6 @@
|
|||
#include "freertos/task.h"
|
||||
#include "unity.h"
|
||||
|
||||
#if CONFIG_FP_TEST_ENABLE
|
||||
static float addsf(float a, float b)
|
||||
{
|
||||
float result;
|
||||
|
@ -192,4 +191,3 @@ TEST_CASE("context switch saves FP registers", "[fp]")
|
|||
}
|
||||
TEST_ASSERT(state.fail == 0);
|
||||
}
|
||||
#endif
|
||||
|
|
20
components/ethernet/Kconfig
Normal file
20
components/ethernet/Kconfig
Normal file
|
@ -0,0 +1,20 @@
|
|||
menuconfig ETHERNET
|
||||
bool "Enable Ethernet"
|
||||
default n
|
||||
help
|
||||
Enable this option to enable ethernet driver and show the menu with ethernet features.
|
||||
|
||||
|
||||
config DMA_RX_BUF_NUM
|
||||
int "Dma Rx Buf Num"
|
||||
default 10
|
||||
depends on ETHERNET
|
||||
help
|
||||
Dma rx buf num ,can not be 0 .
|
||||
|
||||
config DMA_TX_BUF_NUM
|
||||
int "Dma Tx Buf Num"
|
||||
default 10
|
||||
depends on ETHERNET
|
||||
help
|
||||
Dma tx Buf num ,can not be 0.
|
5
components/ethernet/component.mk
Executable file
5
components/ethernet/component.mk
Executable file
|
@ -0,0 +1,5 @@
|
|||
#
|
||||
# Component Makefile
|
||||
#
|
||||
# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
|
||||
|
125
components/ethernet/emac_common.h
Normal file
125
components/ethernet/emac_common.h
Normal file
|
@ -0,0 +1,125 @@
|
|||
// Copyright 2015-2016 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 _EMAC_COMMON_H_
|
||||
#define _EMAC_COMMON_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "esp_err.h"
|
||||
#include "emac_dev.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint32_t emac_sig_t;
|
||||
typedef uint32_t emac_par_t;
|
||||
|
||||
typedef struct {
|
||||
emac_sig_t sig;
|
||||
emac_par_t par;
|
||||
} emac_event_t;
|
||||
|
||||
enum emac_mode {
|
||||
EMAC_MODE_RMII = 0,
|
||||
EMAC_MDOE_MII,
|
||||
};
|
||||
|
||||
enum emac_runtime_status {
|
||||
EMAC_RUNTIME_NOT_INIT = 0,
|
||||
EMAC_RUNTIME_INIT,
|
||||
EMAC_RUNTIME_START,
|
||||
EMAC_RUNTIME_STOP,
|
||||
};
|
||||
|
||||
enum {
|
||||
SIG_EMAC_TX_DONE,
|
||||
SIG_EMAC_RX_DONE,
|
||||
SIG_EMAC_TX,
|
||||
SIG_EMAC_START,
|
||||
SIG_EMAC_STOP,
|
||||
SIG_EMAC_MAX
|
||||
};
|
||||
|
||||
typedef void (*emac_phy_fun)(void);
|
||||
typedef esp_err_t (*emac_tcpip_input_fun)(void *buffer, uint16_t len, void *eb);
|
||||
typedef void (*emac_gpio_config_func)(void);
|
||||
|
||||
struct emac_config_data {
|
||||
unsigned int phy_addr;
|
||||
enum emac_mode mac_mode;
|
||||
struct dma_extended_desc *dma_etx;
|
||||
unsigned int cur_tx;
|
||||
unsigned int dirty_tx;
|
||||
signed int cnt_tx;
|
||||
struct dma_extended_desc *dma_erx;
|
||||
unsigned int cur_rx;
|
||||
unsigned int dirty_rx;
|
||||
signed int cnt_rx;
|
||||
unsigned int rx_need_poll;
|
||||
bool phy_link_up;
|
||||
enum emac_runtime_status emac_status;
|
||||
uint8_t macaddr[6];
|
||||
emac_phy_fun phy_init;
|
||||
emac_tcpip_input_fun emac_tcpip_input;
|
||||
emac_gpio_config_func emac_gpio_config;
|
||||
};
|
||||
|
||||
enum emac_post_type {
|
||||
EMAC_POST_ASYNC,
|
||||
EMAC_POST_SYNC,
|
||||
};
|
||||
|
||||
struct emac_post_cmd {
|
||||
void *cmd;
|
||||
enum emac_post_type post_type;
|
||||
};
|
||||
|
||||
struct emac_tx_cmd {
|
||||
uint8_t *buf;
|
||||
uint16_t size;
|
||||
int8_t err;
|
||||
};
|
||||
|
||||
struct emac_open_cmd {
|
||||
int8_t err;
|
||||
};
|
||||
|
||||
struct emac_close_cmd {
|
||||
int8_t err;
|
||||
};
|
||||
#if CONFIG_ETHERNET
|
||||
#define DMA_RX_BUF_NUM CONFIG_DMA_RX_BUF_NUM
|
||||
#define DMA_TX_BUF_NUM CONFIG_DMA_TX_BUF_NUM
|
||||
#else
|
||||
#define DMA_RX_BUF_NUM 1
|
||||
#define DMA_TX_BUF_NUM 1
|
||||
#endif
|
||||
#define DMA_RX_BUF_SIZE 1600
|
||||
#define DMA_TX_BUF_SIZE 1600
|
||||
|
||||
//lwip err
|
||||
#define ERR_OK 0
|
||||
#define ERR_MEM -1
|
||||
#define ERR_IF -16
|
||||
|
||||
#define EMAC_CMD_OK 0
|
||||
#define EMAC_CMD_FAIL -1
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
204
components/ethernet/emac_desc.h
Normal file
204
components/ethernet/emac_desc.h
Normal file
|
@ -0,0 +1,204 @@
|
|||
// Copyright 2015-2016 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 _EMAC_DESC_H_
|
||||
#define _EMAC_DESC_H_
|
||||
|
||||
#include "soc/soc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define REG_EMAC_DESC_BASE 0
|
||||
#define EMAC_DESC_TDES0_REG (REG_EMAC_DESC_BASE + 0x0000)
|
||||
#define EMAC_DESC_TX_OWN (BIT(31))
|
||||
#define EMAC_DESC_TX_OWN_S 31
|
||||
#define EMAC_DESC_INT_COMPL (BIT(30))
|
||||
#define EMAC_DESC_INT_COMPL_S 30
|
||||
#define EMAC_DESC_LAST_SEGMENT (BIT(29))
|
||||
#define EMAC_DESC_LAST_SEGMENT_S 29
|
||||
#define EMAC_DESC_FIRST_SEGMENT (BIT(28))
|
||||
#define EMAC_DESC_FIRST_SEGMENT_S 28
|
||||
#define EMAC_DESC_DIS_CRC (BIT(27))
|
||||
#define EMAC_DESC_DIS_CRC_S 27
|
||||
#define EMAC_DESC_DIS_PAD (BIT(26))
|
||||
#define EMAC_DESC_DIS_PAD_S 26
|
||||
#define EMAC_DESC_TX_TS_EN (BIT(25))
|
||||
#define EMAC_DESC_TX_TS_EN_S 25
|
||||
#define EMAC_DESC_CRC_REPLACE_CTRL (BIT(24))
|
||||
#define EMAC_DESC_CRC_REPLACE_CTRL_S 24
|
||||
#define EMAC_DESC_CHECKSUM_INSERT_CTRL 0x00000003
|
||||
#define EMAC_DESC_CHECKSUM_INSERT_CTRL_S 22
|
||||
#define EMAC_DESC_TX_END_OF_RING (BIT(21))
|
||||
#define EMAC_DESC_TX_END_OF_RING_S 21
|
||||
#define EMAC_DESC_SECOND_ADDR_CHAIN (BIT(20))
|
||||
#define EMAC_DESC_SECOND_ADDR_CHAIN_S 20
|
||||
#define EMAC_DESC_VLAN_INSERT_CTRL 0x00000003
|
||||
#define EMAC_DESC_VLAN_INSERT_CTRL_S 18
|
||||
#define EMAC_DESC_TX_TS_STATUS (BIT(17))
|
||||
#define EMAC_DESC_TX_TS_STATUS_S 17
|
||||
#define EMAC_DESC_TX_IP_HEAD_ERR (BIT(16))
|
||||
#define EMAC_DESC_TX_IP_HEAD_ERR_S 16
|
||||
#define EMAC_DESC_ERR_SUMMARY (BIT(15))
|
||||
#define EMAC_DESC_ERR_SUMMARY_S 15
|
||||
#define EMAC_DESC_JABBER_TO (BIT(14))
|
||||
#define EMAC_DESC_JABBER_TO_S 14
|
||||
#define EMAC_DESC_FRAME_FLUSH (BIT(13))
|
||||
#define EMAC_DESC_FRAME_FLUSH_S 13
|
||||
#define EMAC_DESC_TX_IP_PAYLAD_ERR (BIT(12))
|
||||
#define EMAC_DESC_TX_IP_PAYLAD_ERR_S 12
|
||||
#define EMAC_DESC_LOSS_OF_CARRIER (BIT(11))
|
||||
#define EMAC_DESC_LOSS_OF_CARRIER_S 11
|
||||
#define EMAC_DESC_NO_CARRIER (BIT(10))
|
||||
#define EMAC_DESC_NO_CARRIER_S 10
|
||||
#define EMAC_DESC_LATE_COLLISION_T (BIT(9))
|
||||
#define EMAC_DESC_LATE_COLLISION_T_S 9
|
||||
#define EMAC_DESC_EXCESSIVE_COLLISION (BIT(8))
|
||||
#define EMAC_DESC_EXCESSIVE_COLLISION_S 8
|
||||
#define EMAC_DESC_VLAN_FRAME (BIT(7))
|
||||
#define EMAC_DESC_VLAN_FRAME_S 7
|
||||
#define EMAC_DESC_COLLISION_COUNT 0x0000000F
|
||||
#define EMAC_DESC_COLLISION_COUNT_S 3
|
||||
#define EMAC_DESC_EXCESSIVE_DEFERRAL (BIT(2))
|
||||
#define EMAC_DESC_EXCESSIVE_DEFERRAL_S 2
|
||||
#define EMAC_DESC_UNDERFLOW_ERR (BIT(1))
|
||||
#define EMAC_DESC_UNDERFLOW_ERR_S 1
|
||||
#define EMAC_DESC_DEFFER_BIT (BIT(0))
|
||||
#define EMAC_DESC_DEFFER_BIT_S 0
|
||||
|
||||
#define EMAC_DESC_TDES1_REG (REG_EMAC_DESC_BASE + 0x0004)
|
||||
#define EMAC_DESC_SA_INSERT_CRTL 0x00000007
|
||||
#define EMAC_DESC_SA_INSERT_CRTL_S 29
|
||||
#define EMAC_DESC_TX_BUFFER1_SIZE 0x00001FFF
|
||||
#define EMAC_DESC_TX_BUFFER1_SIZE_S 0
|
||||
|
||||
#define EMAC_DESC_TDES2_REG (REG_EMAC_DESC_BASE + 0x0008)
|
||||
#define EMAC_DESC_TX_BUFFER1_ADDR_PTR 0xFFFFFFFF
|
||||
#define EMAC_DESC_TX_BUFFER1_ADDR_PTR_S 0
|
||||
|
||||
#define EMAC_DESC_TDES3_REG (REG_EMAC_DESC_BASE + 0x000C)
|
||||
#define EMAC_DESC_TX_NEXT_DESC_ADDR 0xFFFFFFFF
|
||||
#define EMAC_DESC_TX_NEXT_DESC_ADDR_S 0
|
||||
|
||||
#define EMAC_DESC_TDES4_REG (REG_EMAC_DESC_BASE + 0x0010)
|
||||
|
||||
#define EMAC_DESC_TDES5_REG (REG_EMAC_DESC_BASE + 0x0014)
|
||||
|
||||
#define EMAC_DESC_TDES6_REG (REG_EMAC_DESC_BASE + 0x0018)
|
||||
#define EMAC_DESC_TX_FRAME_TS_LOW 0xFFFFFFFF
|
||||
#define EMAC_DESC_TX_FRAME_TS_LOW_S 0
|
||||
|
||||
#define EMAC_DESC_TDES7_REG (REG_EMAC_DESC_BASE + 0x001C)
|
||||
#define EMAC_DESC_TX_FRAME_TS_HIGH 0xFFFFFFFF
|
||||
#define EMAC_DESC_TX_FRAME_TS_HIGH_S 0
|
||||
|
||||
#define EMAC_DESC_RDES0_REG (REG_EMAC_DESC_BASE + 0x0000)
|
||||
#define EMAC_DESC_RX_OWN (BIT(31))
|
||||
#define EMAC_DESC_RX_OWN_S 31
|
||||
#define EMAC_DESC_DEST_ADDR_FILTER_FAIL (BIT(30))
|
||||
#define EMAC_DESC_DEST_ADDR_FILTER_FAIL_S 30
|
||||
#define EMAC_DESC_FRAME_LENGTH 0x00003FFF
|
||||
#define EMAC_DESC_FRAME_LENGTH_S 16
|
||||
#define EMAC_DESC_ERROR_SUMMARY (BIT(15))
|
||||
#define EMAC_DESC_ERROR_SUMMARY_S 15
|
||||
#define EMAC_DESC_DESC_ERR (BIT(14))
|
||||
#define EMAC_DESC_DESC_ERR_S 14
|
||||
#define EMAC_DESC_SOURCE_ADDR_FILTER_FAIL (BIT(13))
|
||||
#define EMAC_DESC_SOURCE_ADDR_FILTER_FAIL_S 13
|
||||
#define EMAC_DESC_LENGTH_ERR (BIT(12))
|
||||
#define EMAC_DESC_LENGTH_ERR_S 12
|
||||
#define EMAC_DESC_OVERFLOW_ERR (BIT(11))
|
||||
#define EMAC_DESC_OVERFLOW_ERR_S 11
|
||||
#define EMAC_DESC_VLAN_TAG (BIT(10))
|
||||
#define EMAC_DESC_VLAN_TAG_S 10
|
||||
#define EMAC_DESC_FRIST_DESC (BIT(9))
|
||||
#define EMAC_DESC_FRIST_DESC_S 9
|
||||
#define EMAC_DESC_LAST_DESC (BIT(8))
|
||||
#define EMAC_DESC_LAST_DESC_S 8
|
||||
#define EMAC_DESC_TS_AV_IP_CHK_ERR (BIT(7))
|
||||
#define EMAC_DESC_TS_AV_IP_CHK_ERR_S 7
|
||||
#define EMAC_DESC_LATE_COLLISION (BIT(6))
|
||||
#define EMAC_DESC_LATE_COLLISION_S 6
|
||||
#define EMAC_DESC_FRAME_TYPE (BIT(5))
|
||||
#define EMAC_DESC_FRAME_TYPE_S 5
|
||||
#define EMAC_DESC_RX_WDT_TO (BIT(4))
|
||||
#define EMAC_DESC_RX_WDT_TO_S 4
|
||||
#define EMAC_DESC_RX_ERR (BIT(3))
|
||||
#define EMAC_DESC_RX_ERR_S 3
|
||||
#define EMAC_DESC_DRIBBLE_BIT_ERR (BIT(2))
|
||||
#define EMAC_DESC_DRIBBLE_BIT_ERR_S 2
|
||||
#define EMAC_DESC_CRC_ERR (BIT(1))
|
||||
#define EMAC_DESC_CRC_ERR_S 1
|
||||
#define EMAC_DESC_EXT_STATUS_AVAIL (BIT(0))
|
||||
#define EMAC_DESC_EXT_STATUS_AVAIL_S 0
|
||||
|
||||
#define EMAC_DESC_RDES1_REG (REG_EMAC_DESC_BASE + 0x0004)
|
||||
#define EMAC_DESC_DIS_INT_ON_COMPLET (BIT(31))
|
||||
#define EMAC_DESC_DIS_INT_ON_COMPLET_S 31
|
||||
#define EMAC_DESC_RX_END_OF_RING (BIT(15))
|
||||
#define EMAC_DESC_RX_END_OF_RING_S 15
|
||||
#define EMAC_DESC_RX_SECOND_ADDR_CHAIN (BIT(14))
|
||||
#define EMAC_DESC_RX_SECOND_ADDR_CHAIN_S 14
|
||||
#define EMAC_DESC_RX_BUFFER1_SIZE 0x00001FFF
|
||||
#define EMAC_DESC_RX_BUFFER1_SIZE_S 0
|
||||
|
||||
#define EMAC_DESC_RDES2_REG (REG_EMAC_DESC_BASE + 0x0008)
|
||||
#define EMAC_DESC_RX_BUFFER1_ADDR_PTR 0xFFFFFFFF
|
||||
#define EMAC_DESC_RX_BUFFER1_ADDR_PTR_S 0
|
||||
|
||||
#define EMAC_DESC_RDES3_REG (REG_EMAC_DESC_BASE + 0x000c)
|
||||
#define EMAC_DESC_RX_NEXT_DESC_ADDR 0xFFFFFFFF
|
||||
#define EMAC_DESC_RX_NEXT_DESC_ADDR_S 0
|
||||
|
||||
#define EMAC_DESC_RDES4_REG (REG_EMAC_DESC_BASE + 0x0010)
|
||||
#define EMAC_DESC_VLAN_TAG_PRIOR_VALUE 0x00000007
|
||||
#define EMAC_DESC_VLAN_TAG_PRIOR_VALUE_S 18
|
||||
#define EMAC_DESC_TS_DROP (BIT(14))
|
||||
#define EMAC_DESC_TS_DROP_S 14
|
||||
#define EMAC_DESC_PTP_VERSION (BIT(13))
|
||||
#define EMAC_DESC_PTP_VERSION_S 13
|
||||
#define EMAC_DESC_PTP_FRAME_TYPE (BIT(12))
|
||||
#define EMAC_DESC_PTP_FRAME_TYPE_S 12
|
||||
#define EMAC_DESC_MESSAGE_TYPE 0x0000000F
|
||||
#define EMAC_DESC_MESSAGE_TYPE_S 8
|
||||
#define EMAC_DESC_IPV6_PACK_RECEIVE (BIT(7))
|
||||
#define EMAC_DESC_IPV6_PACK_RECEIVE_S 7
|
||||
#define EMAC_DESC_IPV4_PACK_RECEIVE (BIT(6))
|
||||
#define EMAC_DESC_IPV4_PACK_RECEIVE_S 6
|
||||
#define EMAC_DESC_IP_CHECKSUM_BYPASS (BIT(5))
|
||||
#define EMAC_DESC_IP_CHECKSUM_BYPASS_S 5
|
||||
#define EMAC_DESC_RX_IP_PAYLAD_ERR (BIT(4))
|
||||
#define EMAC_DESC_RX_IP_PAYLAD_ERR_S 4
|
||||
#define EMAC_DESC_RX_IP_HEAD_ERR (BIT(3))
|
||||
#define EMAC_DESC_RX_IP_HEAD_ERR_S 3
|
||||
#define EMAC_DESC_IP_PAYLOAD_TYPE 0x00000007
|
||||
#define EMAC_DESC_IP_PAYLOAD_TYPE_S 0
|
||||
|
||||
#define EMAC_DESC_RDES5_REG (REG_EMAC_DESC_BASE + 0x0014)
|
||||
|
||||
#define EMAC_DESC_RDES6_REG (REG_EMAC_DESC_BASE + 0x0018)
|
||||
#define EMAC_DESC_RX_FRAME_TS_LOW 0xFFFFFFFF
|
||||
#define EMAC_DESC_RX_FRAME_TS_LOW_S 0
|
||||
|
||||
#define EMAC_DESC_RDES7_REG (REG_EMAC_DESC_BASE + 0x001C)
|
||||
#define EMAC_DESC_RX_FRAME_TS_HIGH 0xFFFFFFFF
|
||||
#define EMAC_DESC_RX_FRAME_TS_HIGH_S 0
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
142
components/ethernet/emac_dev.c
Normal file
142
components/ethernet/emac_dev.c
Normal file
|
@ -0,0 +1,142 @@
|
|||
// Copyright 2015-2016 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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
#include "rom/gpio.h"
|
||||
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/io_mux_reg.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/gpio_reg.h"
|
||||
#include "soc/gpio_sig_map.h"
|
||||
#include "soc/emac_reg_v2.h"
|
||||
#include "soc/emac_ex_reg.h"
|
||||
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "emac_common.h"
|
||||
|
||||
static const char *TAG = "emac";
|
||||
|
||||
void emac_poll_tx_cmd(void)
|
||||
{
|
||||
//write any to wake up dma
|
||||
REG_WRITE(EMAC_DMATXPOLLDEMAND_REG, 1);
|
||||
}
|
||||
|
||||
void emac_poll_rx_cmd(void)
|
||||
{
|
||||
//write any to wake up dma
|
||||
REG_WRITE(EMAC_DMARXPOLLDEMAND_REG, 1);
|
||||
}
|
||||
|
||||
void emac_enable_dma_tx(void)
|
||||
{
|
||||
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_START_STOP_TRANSMISSION_COMMAND);
|
||||
}
|
||||
|
||||
void emac_enable_dma_rx(void)
|
||||
{
|
||||
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_START_STOP_RECEIVE);
|
||||
}
|
||||
|
||||
void emac_disable_dma_tx(void)
|
||||
{
|
||||
REG_CLR_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_OPERATE_SECOND_FRAME);
|
||||
}
|
||||
|
||||
void emac_disable_dma_rx(void)
|
||||
{
|
||||
REG_CLR_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_START_STOP_RECEIVE);
|
||||
}
|
||||
|
||||
uint32_t emac_read_tx_cur_reg(void)
|
||||
{
|
||||
return REG_READ(EMAC_DMATXCURRDESC_REG);
|
||||
}
|
||||
|
||||
uint32_t emac_read_rx_cur_reg(void)
|
||||
{
|
||||
return REG_READ(EMAC_DMARXCURRDESC_REG);
|
||||
}
|
||||
|
||||
uint32_t emac_read_mac_version(void)
|
||||
{
|
||||
uint32_t data = 0;
|
||||
data = REG_READ(EMAC_GMACVERSION_REG);
|
||||
return data;
|
||||
}
|
||||
|
||||
void emac_reset(void)
|
||||
{
|
||||
REG_SET_BIT(EMAC_DMABUSMODE_REG, EMAC_SW_RST);
|
||||
|
||||
while (REG_GET_BIT(EMAC_DMABUSMODE_REG, EMAC_SW_RST) == 1) {
|
||||
//nothing to do ,if stop here,maybe emac have not clk input.
|
||||
ESP_LOGI(TAG, "emac reseting ....");
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "emac reset done");
|
||||
}
|
||||
|
||||
void emac_enable_clk(bool enable)
|
||||
{
|
||||
if (enable == true) {
|
||||
REG_SET_BIT(EMAC_CLK_EN_REG, EMAC_CLK_EN);
|
||||
} else {
|
||||
REG_CLR_BIT(EMAC_CLK_EN_REG, EMAC_CLK_EN);
|
||||
}
|
||||
}
|
||||
|
||||
void emac_set_clk_mii(void)
|
||||
{
|
||||
//select ex clock source
|
||||
REG_SET_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_EXT_OSC_EN);
|
||||
//ex clk enable
|
||||
REG_SET_BIT(EMAC_EX_OSCCLK_CONF_REG, EMAC_EX_OSC_CLK_SEL);
|
||||
|
||||
//set mii mode rx/tx clk enable
|
||||
REG_SET_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_MII_CLK_RX_EN);
|
||||
REG_SET_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_MII_CLK_TX_EN);
|
||||
}
|
||||
|
||||
void emac_dma_init(void)
|
||||
{
|
||||
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_FORWARD_UNDERSIZED_GOOD_FRAMES);
|
||||
REG_SET_BIT(EMAC_DMAOPERATION_MODE_REG, EMAC_OPERATE_SECOND_FRAME);
|
||||
REG_SET_FIELD(EMAC_DMABUSMODE_REG, EMAC_PROG_BURST_LEN, 4);
|
||||
}
|
||||
|
||||
void emac_mac_init(void)
|
||||
{
|
||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_GMACRX);
|
||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_GMACTX);
|
||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_GMACDUPLEX);
|
||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_GMACMIIGMII);
|
||||
REG_SET_BIT(EMAC_GMACCONFIG_REG, EMAC_GMACFESPEED);
|
||||
REG_SET_BIT(EMAC_GMACFRAMEFILTER_REG, EMAC_PROMISCUOUS_MODE);
|
||||
}
|
||||
|
||||
void emac_set_clk_rmii(void)
|
||||
{
|
||||
//select ex clock source
|
||||
REG_SET_BIT(EMAC_EX_CLK_CTRL_REG, EMAC_EX_EXT_OSC_EN);
|
||||
//ex clk enable
|
||||
REG_SET_BIT(EMAC_EX_OSCCLK_CONF_REG, EMAC_EX_OSC_CLK_SEL);
|
||||
}
|
65
components/ethernet/emac_dev.h
Normal file
65
components/ethernet/emac_dev.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
// Copyright 2015-2016 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 _EMAC_DEV_H_
|
||||
#define _EMAC_DEV_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "soc/emac_reg_v2.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define EMAC_INTR_ENABLE_BIT (EMAC_TRANSMIT_INTERRUPT_ENABLE | EMAC_RECEIVE_INTERRUPT_ENABLE | EMAC_RECEIVE_BUFFER_UNAVAILABLE_ENABLE | EMAC_NORMAL_INTERRUPT_SUMMARY_ENABLE)
|
||||
|
||||
struct dma_desc {
|
||||
uint32_t desc0;
|
||||
uint32_t desc1;
|
||||
uint32_t desc2;
|
||||
uint32_t desc3;
|
||||
};
|
||||
|
||||
struct dma_extended_desc {
|
||||
struct dma_desc basic;
|
||||
uint32_t desc4;
|
||||
uint32_t desc5;
|
||||
uint32_t desc6;
|
||||
uint32_t desc7;
|
||||
};
|
||||
|
||||
void emac_enable_clk(bool enable);
|
||||
void emac_set_clk_rmii(void);
|
||||
void emac_set_clk_mii(void);
|
||||
void emac_reset(void);
|
||||
void emac_set_gpio_pin_rmii(void);
|
||||
void emac_set_gpio_pin_mii(void);
|
||||
uint32_t emac_read_mac_version(void);
|
||||
void emac_dma_init(void);
|
||||
void emac_mac_init(void);
|
||||
void emac_enable_dma_tx(void);
|
||||
void emac_poll_tx_cmd(void);
|
||||
uint32_t emac_read_tx_cur_reg(void);
|
||||
void emac_enable_dma_rx(void);
|
||||
uint32_t emac_read_rx_cur_reg(void);
|
||||
void emac_poll_rx_cmd(void);
|
||||
void emac_disable_dma_tx(void);
|
||||
void emac_disable_dma_rx(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
768
components/ethernet/emac_main.c
Normal file
768
components/ethernet/emac_main.c
Normal file
|
@ -0,0 +1,768 @@
|
|||
// Copyright 2015-2016 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 <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "rom/ets_sys.h"
|
||||
#include "rom/gpio.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/io_mux_reg.h"
|
||||
#include "soc/rtc_cntl_reg.h"
|
||||
#include "soc/gpio_reg.h"
|
||||
#include "soc/dport_reg.h"
|
||||
#include "soc/emac_ex_reg.h"
|
||||
#include "soc/emac_reg_v2.h"
|
||||
#include "soc/soc.h"
|
||||
|
||||
#include "tcpip_adapter.h"
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#include "esp_task_wdt.h"
|
||||
#include "esp_event.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_eth.h"
|
||||
|
||||
#include "emac_common.h"
|
||||
#include "emac_desc.h"
|
||||
|
||||
#include "freertos/xtensa_api.h"
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
#include "freertos/queue.h"
|
||||
#include "freertos/semphr.h"
|
||||
#include "freertos/timers.h"
|
||||
|
||||
#define EMAC_EVT_QNUM 200
|
||||
#define EMAC_SIG_MAX 50
|
||||
|
||||
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_buf[DMA_RX_BUF_SIZE * DMA_RX_BUF_NUM];
|
||||
static uint8_t emac_dma_tx_buf[DMA_TX_BUF_SIZE * DMA_TX_BUF_NUM];
|
||||
|
||||
static SemaphoreHandle_t emac_g_sem;
|
||||
static portMUX_TYPE g_emac_mux = portMUX_INITIALIZER_UNLOCKED;
|
||||
static xTaskHandle emac_task_hdl;
|
||||
static xQueueHandle emac_xqueue;
|
||||
static uint8_t emac_sig_cnt[EMAC_SIG_MAX] = {0};
|
||||
static TimerHandle_t emac_timer = NULL;
|
||||
|
||||
static const char *TAG = "emac";
|
||||
|
||||
static esp_err_t emac_ioctl(emac_sig_t sig, emac_par_t par);
|
||||
esp_err_t emac_post(emac_sig_t sig, emac_par_t par);
|
||||
|
||||
static void emac_macaddr_init(void)
|
||||
{
|
||||
esp_efuse_read_mac(&(emac_config.macaddr[0]));
|
||||
emac_config.macaddr[5] = emac_config.macaddr[5] + 3;
|
||||
}
|
||||
|
||||
void esp_eth_get_mac(uint8_t mac[6])
|
||||
{
|
||||
memcpy(mac, &(emac_config.macaddr[0]), 6);
|
||||
}
|
||||
|
||||
static void emac_setup_tx_desc(struct dma_extended_desc *tx_desc , uint32_t size)
|
||||
{
|
||||
tx_desc->basic.desc0 = EMAC_DESC_TX_OWN | EMAC_DESC_INT_COMPL | EMAC_DESC_LAST_SEGMENT | EMAC_DESC_FIRST_SEGMENT | EMAC_DESC_SECOND_ADDR_CHAIN;
|
||||
tx_desc->basic.desc1 = size & 0xfff;
|
||||
}
|
||||
|
||||
static void emac_clean_tx_desc(struct dma_extended_desc *tx_desc)
|
||||
{
|
||||
tx_desc->basic.desc0 = 0;
|
||||
tx_desc->basic.desc1 = 0;
|
||||
}
|
||||
|
||||
static void emac_clean_rx_desc(struct dma_extended_desc *rx_desc)
|
||||
{
|
||||
rx_desc->basic.desc0 = EMAC_DESC_RX_OWN;
|
||||
rx_desc->basic.desc1 = EMAC_DESC_RX_SECOND_ADDR_CHAIN | DMA_RX_BUF_SIZE;
|
||||
}
|
||||
|
||||
static void emac_set_tx_base_reg(void)
|
||||
{
|
||||
REG_WRITE(EMAC_DMATXBASEADDR_REG, (uint32_t)(emac_config.dma_etx));
|
||||
}
|
||||
|
||||
static void emac_set_rx_base_reg(void)
|
||||
{
|
||||
REG_WRITE(EMAC_DMARXBASEADDR_REG, (uint32_t)(emac_config.dma_erx));
|
||||
}
|
||||
|
||||
static void emac_reset_dma_chain(void)
|
||||
{
|
||||
emac_config.cnt_tx = 0;
|
||||
emac_config.cur_tx = 0;
|
||||
emac_config.dirty_tx = 0;
|
||||
|
||||
emac_config.cnt_rx = 0;
|
||||
emac_config.cur_rx = 0;
|
||||
emac_config.dirty_rx = 0;
|
||||
}
|
||||
|
||||
static void emac_init_dma_chain(void)
|
||||
{
|
||||
int i;
|
||||
uint32_t dma_phy;
|
||||
struct dma_extended_desc *p = NULL;
|
||||
|
||||
//init tx chain
|
||||
emac_config.dma_etx = (struct dma_extended_desc *)(&emac_dma_tx_chain_buf[0]);
|
||||
emac_config.cnt_tx = 0;
|
||||
emac_config.cur_tx = 0;
|
||||
emac_config.dirty_tx = 0;
|
||||
|
||||
dma_phy = (uint32_t)(emac_config.dma_etx);
|
||||
p = emac_config.dma_etx;
|
||||
|
||||
for (i = 0; i < (DMA_TX_BUF_NUM - 1); i++ ) {
|
||||
dma_phy += sizeof(struct dma_extended_desc);
|
||||
emac_clean_tx_desc(p);
|
||||
p->basic.desc3 = dma_phy;
|
||||
p->basic.desc2 = (uint32_t)(&emac_dma_tx_buf[0]) + (i * DMA_TX_BUF_SIZE);
|
||||
p++;
|
||||
}
|
||||
p->basic.desc3 = (uint32_t)(emac_config.dma_etx);
|
||||
p->basic.desc2 = (uint32_t)(&emac_dma_tx_buf[0]) + (i * DMA_TX_BUF_SIZE);
|
||||
|
||||
//init desc0 desc1
|
||||
emac_clean_tx_desc(p);
|
||||
|
||||
//init rx chain
|
||||
emac_config.dma_erx = (struct dma_extended_desc *)(&emac_dma_rx_chain_buf[0]);
|
||||
emac_config.cnt_rx = 0;
|
||||
emac_config.cur_rx = 0;
|
||||
emac_config.dirty_rx = 0;
|
||||
|
||||
dma_phy = (uint32_t)(emac_config.dma_erx);
|
||||
p = emac_config.dma_erx;
|
||||
|
||||
for (i = 0; i < (DMA_TX_BUF_NUM - 1); i++ ) {
|
||||
dma_phy += sizeof(struct dma_extended_desc);
|
||||
emac_clean_rx_desc(p);
|
||||
p->basic.desc3 = dma_phy;
|
||||
p->basic.desc2 = (uint32_t)(&emac_dma_rx_buf[0]) + (i * DMA_RX_BUF_SIZE);
|
||||
p++;
|
||||
}
|
||||
p->basic.desc3 = (uint32_t)(emac_config.dma_erx);
|
||||
p->basic.desc2 = (uint32_t)(&emac_dma_rx_buf[0]) + (i * DMA_RX_BUF_SIZE);
|
||||
|
||||
//init desc0 desc1
|
||||
emac_clean_rx_desc(p);
|
||||
}
|
||||
|
||||
void esp_eth_smi_write(uint32_t reg_num, uint16_t value)
|
||||
{
|
||||
uint32_t phy_num = emac_config.phy_addr;
|
||||
|
||||
while (REG_GET_BIT(EMAC_GMACGMIIADDR_REG, EMAC_GMIIBUSY) == 1 ) {
|
||||
}
|
||||
|
||||
REG_WRITE(EMAC_GMACGMIIDATA_REG, value);
|
||||
REG_WRITE(EMAC_GMACGMIIADDR_REG, 0x3 | ((reg_num & 0x1f) << 6) | ((phy_num & 0x1f) << 11) | ((0x3) << 2));
|
||||
|
||||
while (REG_GET_BIT(EMAC_GMACGMIIADDR_REG, EMAC_GMIIBUSY) == 1 ) {
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t esp_eth_smi_read(uint32_t reg_num)
|
||||
{
|
||||
uint32_t phy_num = emac_config.phy_addr;
|
||||
uint16_t value = 0;
|
||||
|
||||
while (REG_GET_BIT(EMAC_GMACGMIIADDR_REG, EMAC_GMIIBUSY) == 1 ) {
|
||||
}
|
||||
|
||||
REG_WRITE(EMAC_GMACGMIIADDR_REG, 0x1 | ((reg_num & 0x1f) << 6) | ((phy_num & 0x1f) << 11) | (0x3 << 2));
|
||||
while (REG_GET_BIT(EMAC_GMACGMIIADDR_REG, EMAC_GMIIBUSY) == 1 ) {
|
||||
}
|
||||
value = (REG_READ(EMAC_GMACGMIIDATA_REG) & 0xffff);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
static void emac_set_user_config_data(eth_config_t *config )
|
||||
{
|
||||
emac_config.phy_addr = config->phy_addr;
|
||||
emac_config.mac_mode = config->mac_mode;
|
||||
emac_config.phy_init = config->phy_init;
|
||||
emac_config.emac_tcpip_input = config->tcpip_input;
|
||||
emac_config.emac_gpio_config = config->gpio_config;
|
||||
}
|
||||
|
||||
static esp_err_t emac_verify_args(void)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
if (emac_config.phy_addr > 31) {
|
||||
ESP_LOGE(TAG, "phy addr err");
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
|
||||
if (emac_config.mac_mode != EMAC_MODE_RMII) {
|
||||
ESP_LOGE(TAG, "mac mode err,now only support RMII");
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
|
||||
if (emac_config.phy_init == NULL) {
|
||||
ESP_LOGE(TAG, "phy_init func is null");
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
|
||||
if (emac_config.emac_tcpip_input == NULL) {
|
||||
ESP_LOGE(TAG, "tcpip_input func is null");
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
|
||||
if (emac_config.emac_gpio_config == NULL) {
|
||||
ESP_LOGE(TAG, "gpio config func is null");
|
||||
ret = ESP_FAIL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
//TODO for mac filter
|
||||
void emac_set_mac_addr(void)
|
||||
{
|
||||
}
|
||||
|
||||
//TODO
|
||||
void emac_check_mac_addr(void)
|
||||
{
|
||||
}
|
||||
|
||||
static void emac_process_tx(void)
|
||||
{
|
||||
uint32_t cur_tx_desc = emac_read_tx_cur_reg();
|
||||
|
||||
while (((uint32_t) & (emac_config.dma_etx[emac_config.dirty_tx].basic.desc0) != cur_tx_desc)) {
|
||||
emac_clean_tx_desc(&(emac_config.dma_etx[emac_config.dirty_tx]));
|
||||
emac_config.dirty_tx = (emac_config.dirty_tx + 1) % DMA_TX_BUF_NUM;
|
||||
emac_config.cnt_tx --;
|
||||
|
||||
if (emac_config.cnt_tx < 0) {
|
||||
ESP_LOGE(TAG, "emac tx chain err");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void emac_process_rx(void)
|
||||
{
|
||||
uint32_t cur_rx_desc = emac_read_rx_cur_reg();
|
||||
|
||||
while (((uint32_t) & (emac_config.dma_erx[emac_config.dirty_rx].basic.desc0) != cur_rx_desc)) {
|
||||
//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);
|
||||
|
||||
emac_clean_rx_desc(&(emac_config.dma_erx[emac_config.dirty_rx]));
|
||||
emac_config.dirty_rx = (emac_config.dirty_rx + 1) % DMA_RX_BUF_NUM;
|
||||
if (emac_config.rx_need_poll != 0) {
|
||||
emac_poll_rx_cmd();
|
||||
emac_config.rx_need_poll = 0;
|
||||
}
|
||||
//if open this ,one intr can do many intrs ?
|
||||
//cur_rx_desc = emac_read_rx_cur_reg();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO other events need to do something
|
||||
static void IRAM_ATTR emac_process_intr(void *arg)
|
||||
{
|
||||
uint32_t event;
|
||||
event = REG_READ(EMAC_DMASTATUS_REG);
|
||||
|
||||
//clr intrs
|
||||
REG_WRITE(EMAC_DMASTATUS_REG, event);
|
||||
|
||||
if (event & EMAC_RECV_BUF_UNAVAIL) {
|
||||
emac_config.rx_need_poll = 1;
|
||||
} else if (event & EMAC_TRANS_INT) {
|
||||
emac_post(SIG_EMAC_TX_DONE, 0);
|
||||
} else if (event & EMAC_RECV_INT) {
|
||||
emac_post(SIG_EMAC_RX_DONE, 0);
|
||||
} else {
|
||||
//other events
|
||||
}
|
||||
}
|
||||
|
||||
static void emac_enable_intr()
|
||||
{
|
||||
//init emac intr
|
||||
REG_SET_FIELD(DPORT_PRO_EMAC_INT_MAP_REG, DPORT_PRO_EMAC_INT_MAP, ETS_EMAC_INUM);
|
||||
xt_set_interrupt_handler(ETS_EMAC_INUM, emac_process_intr, NULL);
|
||||
xt_ints_on(1 << ETS_EMAC_INUM);
|
||||
|
||||
REG_WRITE(EMAC_DMAINTERRUPT_EN_REG, EMAC_INTR_ENABLE_BIT);
|
||||
}
|
||||
|
||||
static void emac_disable_intr()
|
||||
{
|
||||
xt_ints_off(1 << ETS_EMAC_INUM);
|
||||
REG_WRITE(EMAC_DMAINTERRUPT_EN_REG, 0);
|
||||
}
|
||||
|
||||
static bool emac_check_phy_link_status(void)
|
||||
{
|
||||
return ((esp_eth_smi_read(1) & 0x4) == 0x4 );
|
||||
}
|
||||
|
||||
static void emac_process_link_updown(bool link_status)
|
||||
{
|
||||
system_event_t evt;
|
||||
|
||||
emac_config.phy_link_up = link_status;
|
||||
|
||||
if (link_status == true) {
|
||||
ESP_LOGI(TAG, "eth link_up!!!");
|
||||
emac_enable_dma_tx();
|
||||
emac_enable_dma_rx();
|
||||
ets_delay_us(200000);
|
||||
evt.event_id = SYSTEM_EVENT_ETH_CONNECTED;
|
||||
} else {
|
||||
ESP_LOGI(TAG, "eth link_down!!!");
|
||||
emac_disable_dma_tx();
|
||||
emac_disable_dma_rx();
|
||||
evt.event_id = SYSTEM_EVENT_ETH_DISCONNECTED;
|
||||
}
|
||||
|
||||
esp_event_send(&evt);
|
||||
}
|
||||
|
||||
static void emac_hw_init(void)
|
||||
{
|
||||
//init chain
|
||||
emac_init_dma_chain();
|
||||
|
||||
//get hw features TODO
|
||||
|
||||
//ipc TODO
|
||||
}
|
||||
|
||||
static esp_err_t emac_xmit(void *param)
|
||||
{
|
||||
struct emac_post_cmd *post_cmd = (struct emac_post_cmd *)param;
|
||||
struct emac_tx_cmd *cmd = (struct emac_tx_cmd *)(post_cmd->cmd);
|
||||
esp_err_t ret = ESP_OK;
|
||||
|
||||
void *buf = cmd->buf;
|
||||
uint16_t size = cmd->size;
|
||||
|
||||
if (emac_config.emac_status != EMAC_RUNTIME_START || emac_config.emac_status == EMAC_RUNTIME_NOT_INIT) {
|
||||
ESP_LOGI(TAG, "tx netif close");
|
||||
cmd->err = ERR_IF;
|
||||
ret = ESP_FAIL;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (emac_config.cnt_tx == DMA_TX_BUF_NUM) {
|
||||
ESP_LOGI(TAG, "tx buf full");
|
||||
cmd->err = ERR_MEM;
|
||||
ret = ESP_FAIL;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
memcpy((uint8_t *)(emac_config.dma_etx[emac_config.cur_tx].basic.desc2), (uint8_t *)buf, size);
|
||||
|
||||
emac_setup_tx_desc(&(emac_config.dma_etx[emac_config.cur_tx]), size);
|
||||
|
||||
emac_config.cnt_tx ++;
|
||||
emac_config.cur_tx = (emac_config.cur_tx + 1) % DMA_TX_BUF_NUM ;
|
||||
|
||||
emac_poll_tx_cmd();
|
||||
|
||||
_exit:
|
||||
|
||||
if (post_cmd->post_type == EMAC_POST_SYNC) {
|
||||
xSemaphoreGive(emac_g_sem);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void emac_init_default_data(void)
|
||||
{
|
||||
emac_config.rx_need_poll = 0;
|
||||
}
|
||||
|
||||
void emac_link_check_func(void *pv_parameters)
|
||||
{
|
||||
if (emac_config.emac_status != EMAC_RUNTIME_START ||
|
||||
emac_config.emac_status == EMAC_RUNTIME_NOT_INIT) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (emac_check_phy_link_status() == true ) {
|
||||
if (emac_config.phy_link_up == false) {
|
||||
emac_process_link_updown(true);
|
||||
}
|
||||
} else {
|
||||
if (emac_config.phy_link_up == true) {
|
||||
emac_process_link_updown(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool emac_link_check_timer_init(void)
|
||||
{
|
||||
emac_timer = xTimerCreate("emac_timer", (1000 / portTICK_RATE_MS),
|
||||
pdTRUE, (void *)rand(), emac_link_check_func);
|
||||
if (emac_timer == NULL) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool emac_link_check_timer_start(void)
|
||||
{
|
||||
if (xTimerStart(emac_timer, portMAX_DELAY) != pdPASS) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool emac_link_check_timer_stop(void)
|
||||
{
|
||||
if (xTimerStop(emac_timer, portMAX_DELAY) != pdPASS) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static bool emac_link_check_timer_delete(void)
|
||||
{
|
||||
xTimerDelete(emac_timer, portMAX_DELAY);
|
||||
emac_timer = NULL;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void emac_start(void *param)
|
||||
{
|
||||
struct emac_post_cmd *post_cmd = (struct emac_post_cmd *)param;
|
||||
struct emac_open_cmd *cmd = (struct emac_open_cmd *)(post_cmd->cmd);
|
||||
|
||||
ESP_LOGI(TAG , "emac start !!!\n");
|
||||
cmd->err = EMAC_CMD_OK;
|
||||
emac_enable_clk(true);
|
||||
|
||||
emac_macaddr_init();
|
||||
|
||||
emac_check_mac_addr();
|
||||
|
||||
emac_set_mac_addr();
|
||||
|
||||
emac_set_tx_base_reg();
|
||||
emac_set_rx_base_reg();
|
||||
emac_mac_init();
|
||||
|
||||
emac_config.phy_init();
|
||||
|
||||
//for test
|
||||
//emac_wait_linkup();
|
||||
|
||||
//mmc not support
|
||||
|
||||
//ptp TODO
|
||||
|
||||
//enable emac intr
|
||||
emac_enable_intr();
|
||||
|
||||
emac_config.emac_status = EMAC_RUNTIME_START;
|
||||
|
||||
system_event_t evt;
|
||||
evt.event_id = SYSTEM_EVENT_ETH_START;
|
||||
esp_event_send(&evt);
|
||||
|
||||
//set a timer to check link up status
|
||||
if (emac_link_check_timer_init() == true) {
|
||||
if (emac_link_check_timer_start() != true) {
|
||||
cmd->err = EMAC_CMD_FAIL;
|
||||
emac_link_check_timer_delete();
|
||||
}
|
||||
} else {
|
||||
cmd->err = EMAC_CMD_FAIL;
|
||||
}
|
||||
|
||||
if (post_cmd->post_type == EMAC_POST_SYNC) {
|
||||
xSemaphoreGive(emac_g_sem);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "emac start success !!!");
|
||||
}
|
||||
|
||||
esp_err_t esp_eth_enable(void)
|
||||
{
|
||||
struct emac_post_cmd post_cmd;
|
||||
struct emac_open_cmd open_cmd;
|
||||
|
||||
post_cmd.cmd = (void *)(&open_cmd);
|
||||
open_cmd.err = EMAC_CMD_OK;
|
||||
|
||||
if (emac_config.emac_status == EMAC_RUNTIME_START) {
|
||||
open_cmd.err = EMAC_CMD_OK;
|
||||
return open_cmd.err;
|
||||
}
|
||||
|
||||
if (emac_config.emac_status != EMAC_RUNTIME_NOT_INIT) {
|
||||
if (emac_ioctl(SIG_EMAC_START, (emac_par_t)(&post_cmd)) != 0) {
|
||||
open_cmd.err = EMAC_CMD_FAIL;
|
||||
}
|
||||
} else {
|
||||
open_cmd.err = EMAC_CMD_FAIL;
|
||||
}
|
||||
return open_cmd.err;
|
||||
}
|
||||
|
||||
static void emac_stop(void *param)
|
||||
{
|
||||
struct emac_post_cmd *post_cmd = (struct emac_post_cmd *)param;
|
||||
ESP_LOGI(TAG, "emac stop");
|
||||
|
||||
emac_link_check_timer_stop();
|
||||
emac_link_check_timer_delete();
|
||||
|
||||
emac_process_link_updown(false);
|
||||
|
||||
emac_disable_intr();
|
||||
emac_reset_dma_chain();
|
||||
emac_reset();
|
||||
emac_enable_clk(false);
|
||||
|
||||
emac_config.emac_status = EMAC_RUNTIME_STOP;
|
||||
system_event_t evt;
|
||||
evt.event_id = SYSTEM_EVENT_ETH_STOP;
|
||||
esp_event_send(&evt);
|
||||
|
||||
if (post_cmd->post_type == EMAC_POST_SYNC) {
|
||||
xSemaphoreGive(emac_g_sem);
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "emac stop success !!!");
|
||||
}
|
||||
|
||||
esp_err_t esp_eth_disable(void)
|
||||
{
|
||||
struct emac_post_cmd post_cmd;
|
||||
struct emac_close_cmd close_cmd;
|
||||
|
||||
post_cmd.cmd = (void *)(&close_cmd);
|
||||
close_cmd.err = EMAC_CMD_OK;
|
||||
|
||||
if (emac_config.emac_status == EMAC_RUNTIME_STOP) {
|
||||
close_cmd.err = EMAC_CMD_OK;
|
||||
return close_cmd.err;
|
||||
}
|
||||
|
||||
if (emac_config.emac_status != EMAC_RUNTIME_NOT_INIT) {
|
||||
if (emac_ioctl(SIG_EMAC_STOP, (emac_par_t)(&post_cmd)) != 0) {
|
||||
close_cmd.err = EMAC_CMD_FAIL;
|
||||
}
|
||||
} else {
|
||||
close_cmd.err = EMAC_CMD_FAIL;
|
||||
}
|
||||
return close_cmd.err;
|
||||
}
|
||||
|
||||
static esp_err_t emac_ioctl(emac_sig_t sig, emac_par_t par)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
struct emac_post_cmd *post_cmd = (struct emac_post_cmd *)par;
|
||||
xTaskHandle task_hdl = xTaskGetCurrentTaskHandle();
|
||||
|
||||
if (emac_task_hdl != task_hdl) {
|
||||
post_cmd->post_type = EMAC_POST_SYNC;
|
||||
if (emac_post(sig, par) != ESP_OK) {
|
||||
ret = ESP_FAIL;
|
||||
return ret;
|
||||
};
|
||||
|
||||
if (xSemaphoreTake(emac_g_sem, portMAX_DELAY) == pdTRUE) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
post_cmd->post_type = EMAC_POST_ASYNC;
|
||||
switch (sig) {
|
||||
case SIG_EMAC_RX_DONE:
|
||||
emac_process_rx();
|
||||
break;
|
||||
case SIG_EMAC_TX_DONE:
|
||||
emac_process_tx();
|
||||
break;
|
||||
case SIG_EMAC_TX:
|
||||
emac_xmit((void *)par);
|
||||
break;
|
||||
case SIG_EMAC_START:
|
||||
emac_start((void *)par);
|
||||
break;
|
||||
case SIG_EMAC_STOP:
|
||||
emac_stop((void *)par);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "unexpect sig %d", sig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
esp_err_t esp_eth_tx(uint8_t *buf, uint16_t size)
|
||||
{
|
||||
struct emac_post_cmd post_cmd;
|
||||
struct emac_tx_cmd tx_cmd;
|
||||
|
||||
post_cmd.cmd = (void *)(&tx_cmd);
|
||||
|
||||
if (emac_check_phy_link_status() == false) {
|
||||
emac_process_link_updown(false);
|
||||
tx_cmd.err = ERR_IF;
|
||||
} else {
|
||||
tx_cmd.buf = buf;
|
||||
tx_cmd.size = size;
|
||||
tx_cmd.err = ERR_OK;
|
||||
|
||||
if (emac_ioctl(SIG_EMAC_TX, (emac_par_t)(&post_cmd)) != 0) {
|
||||
tx_cmd.err = ERR_MEM;
|
||||
}
|
||||
}
|
||||
|
||||
return tx_cmd.err;
|
||||
}
|
||||
|
||||
void emac_task(void *pv)
|
||||
{
|
||||
emac_event_t e;
|
||||
|
||||
for (;;) {
|
||||
if (xQueueReceive(emac_xqueue, &e, (portTickType)portMAX_DELAY) == pdTRUE) {
|
||||
portENTER_CRITICAL(&g_emac_mux);
|
||||
emac_sig_cnt[e.sig]--;
|
||||
portEXIT_CRITICAL(&g_emac_mux);
|
||||
switch (e.sig) {
|
||||
case SIG_EMAC_RX_DONE:
|
||||
emac_process_rx();
|
||||
break;
|
||||
case SIG_EMAC_TX_DONE:
|
||||
emac_process_tx();
|
||||
break;
|
||||
case SIG_EMAC_TX:
|
||||
emac_xmit((void *)e.par);
|
||||
break;
|
||||
case SIG_EMAC_START:
|
||||
emac_start((void *)e.par);
|
||||
break;
|
||||
case SIG_EMAC_STOP:
|
||||
emac_stop((void *)e.par);
|
||||
break;
|
||||
default:
|
||||
ESP_LOGE(TAG, "unexpect sig %d", e.sig);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t IRAM_ATTR emac_post(emac_sig_t sig, emac_par_t par)
|
||||
{
|
||||
portENTER_CRITICAL(&g_emac_mux);
|
||||
|
||||
if (emac_sig_cnt[sig] && sig != SIG_EMAC_TX) {
|
||||
portEXIT_CRITICAL(&g_emac_mux);
|
||||
return ESP_OK;
|
||||
} else {
|
||||
emac_sig_cnt[sig]++;
|
||||
portEXIT_CRITICAL(&g_emac_mux);
|
||||
emac_event_t evt;
|
||||
evt.sig = sig;
|
||||
evt.par = par;
|
||||
if (sig <= SIG_EMAC_RX_DONE) {
|
||||
portBASE_TYPE tmp;
|
||||
|
||||
if (xQueueSendFromISR(emac_xqueue, &evt, &tmp) != pdPASS) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
} else {
|
||||
if (xQueueSend(emac_xqueue, &evt, 10 / portTICK_RATE_MS) != pdTRUE) {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
esp_err_t esp_eth_init(eth_config_t *config)
|
||||
{
|
||||
esp_err_t ret = ESP_OK;
|
||||
#if !CONFIG_ETHERNET
|
||||
ESP_LOGI(TAG, "eth driver init fail,please make menuconfig and enable ethernet .");
|
||||
ret = ESP_FAIL;
|
||||
goto _exit;
|
||||
#endif
|
||||
|
||||
emac_init_default_data();
|
||||
|
||||
if (config != NULL ) {
|
||||
emac_set_user_config_data(config);
|
||||
}
|
||||
|
||||
ret = emac_verify_args();
|
||||
|
||||
if (ret != ESP_OK) {
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
//before set emac reg must enable clk
|
||||
emac_enable_clk(true);
|
||||
REG_SET_FIELD(EMAC_EX_PHYINF_CONF_REG, EMAC_EX_PHY_INTF_SEL, EMAC_EX_PHY_INTF_RMII);
|
||||
|
||||
emac_dma_init();
|
||||
if (emac_config.mac_mode == EMAC_MODE_RMII) {
|
||||
emac_set_clk_rmii();
|
||||
} else {
|
||||
emac_set_clk_mii();
|
||||
}
|
||||
|
||||
emac_config.emac_gpio_config();
|
||||
|
||||
ESP_LOGI(TAG, "mac version %04xa", emac_read_mac_version());
|
||||
emac_hw_init();
|
||||
|
||||
//watchdog TODO
|
||||
|
||||
//init task for emac
|
||||
emac_g_sem = xSemaphoreCreateBinary();
|
||||
emac_xqueue = xQueueCreate(EMAC_EVT_QNUM, sizeof(emac_event_t));
|
||||
xTaskCreate(emac_task, "emacT", 2048 * 4, NULL, (19), &emac_task_hdl);
|
||||
|
||||
emac_reset();
|
||||
emac_enable_clk(false);
|
||||
|
||||
emac_config.emac_status = EMAC_RUNTIME_INIT;
|
||||
|
||||
_exit:
|
||||
return ret;
|
||||
}
|
||||
|
167
components/ethernet/include/esp_eth.h
Normal file
167
components/ethernet/include/esp_eth.h
Normal file
|
@ -0,0 +1,167 @@
|
|||
// Copyright 2015-2016 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_ETH_H__
|
||||
#define __ESP_ETH_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef void (*eth_phy_fun)(void);
|
||||
typedef esp_err_t (*eth_tcpip_input_fun)(void *buffer, uint16_t len, void *eb);
|
||||
typedef void (*eth_gpio_config_func)(void);
|
||||
|
||||
typedef enum {
|
||||
ETH_MODE_RMII = 0,
|
||||
ETH_MDOE_MII,
|
||||
} eth_mode_t;
|
||||
|
||||
typedef enum {
|
||||
PHY0 = 0,
|
||||
PHY1,
|
||||
PHY2,
|
||||
PHY3,
|
||||
PHY4,
|
||||
PHY5,
|
||||
PHY6,
|
||||
PHY7,
|
||||
PHY8,
|
||||
PHY9,
|
||||
PHY10,
|
||||
PHY11,
|
||||
PHY12,
|
||||
PHY13,
|
||||
PHY14,
|
||||
PHY15,
|
||||
PHY16,
|
||||
PHY17,
|
||||
PHY18,
|
||||
PHY19,
|
||||
PHY20,
|
||||
PHY21,
|
||||
PHY22,
|
||||
PHY23,
|
||||
PHY24,
|
||||
PHY25,
|
||||
PHY26,
|
||||
PHY27,
|
||||
PHY28,
|
||||
PHY29,
|
||||
PHY30,
|
||||
PHY31,
|
||||
} eth_phy_base_t;
|
||||
|
||||
/**
|
||||
* @brief ethernet configuration
|
||||
*
|
||||
*/
|
||||
typedef struct {
|
||||
eth_phy_base_t phy_addr; /*!< phy base addr (0~31) */
|
||||
eth_mode_t mac_mode; /*!< mac mode only support RMII now */
|
||||
eth_tcpip_input_fun tcpip_input; /*!< tcpip input func */
|
||||
eth_phy_fun phy_init; /*!< phy init func */
|
||||
eth_gpio_config_func gpio_config; /*!< gpio config func */
|
||||
} eth_config_t;
|
||||
|
||||
/**
|
||||
* @brief Init ethernet mac
|
||||
*
|
||||
* @note config can not be NULL,and phy chip must be suitable to phy init func.
|
||||
*
|
||||
* @param[in] config mac init data.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_eth_init(eth_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Send packet from tcp/ip to mac
|
||||
*
|
||||
* @note buf can not be NULL,size must be less than 1580
|
||||
*
|
||||
* @param[in] buf: start address of packet data.
|
||||
*
|
||||
* @param[in] size: size (byte) of packet data.
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_eth_tx(uint8_t *buf, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Enable ethernet interface
|
||||
*
|
||||
* @note Shout be called after esp_eth_init
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_eth_enable(void);
|
||||
|
||||
/**
|
||||
* @brief Disable ethernet interface
|
||||
*
|
||||
* @note Shout be called after esp_eth_init
|
||||
*
|
||||
* @return
|
||||
* - ESP_OK
|
||||
* - ESP_FAIL
|
||||
*/
|
||||
esp_err_t esp_eth_disable(void);
|
||||
|
||||
/**
|
||||
* @brief Get mac addr
|
||||
*
|
||||
* @note mac addr must be a valid unicast address
|
||||
*
|
||||
* @param[out] mac: start address of mac address.
|
||||
*/
|
||||
void esp_eth_get_mac(uint8_t mac[6]);
|
||||
|
||||
/**
|
||||
* @brief Read phy reg with smi interface.
|
||||
*
|
||||
* @note phy base addr must be right.
|
||||
*
|
||||
* @param[in] reg_num: phy reg num.
|
||||
*
|
||||
* @param[in] value: value which write to phy reg.
|
||||
*/
|
||||
void esp_eth_smi_write(uint32_t reg_num, uint16_t value);
|
||||
|
||||
/**
|
||||
* @brief Write phy reg with smi interface.
|
||||
*
|
||||
* @note phy base addr must be right.
|
||||
*
|
||||
* @param[in] reg_num: phy reg num.
|
||||
*
|
||||
* @return value what read from phy reg
|
||||
*/
|
||||
uint16_t esp_eth_smi_read(uint32_t reg_num);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -609,9 +609,9 @@ void *xRingbufferReceiveUpToFromISR(RingbufHandle_t ringbuf, size_t *item_size,
|
|||
void vRingbufferReturnItem(RingbufHandle_t ringbuf, void *item)
|
||||
{
|
||||
ringbuf_t *rb=(ringbuf_t *)ringbuf;
|
||||
portENTER_CRITICAL_ISR(&rb->mux);
|
||||
portENTER_CRITICAL(&rb->mux);
|
||||
rb->returnItemToRingbufImpl(rb, item);
|
||||
portEXIT_CRITICAL_ISR(&rb->mux);
|
||||
portEXIT_CRITICAL(&rb->mux);
|
||||
xSemaphoreGive(rb->free_space_sem);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ Config: {execute count: 1, execute order: in order}
|
|||
DUT: [UT1]
|
||||
Filter:
|
||||
- Add:
|
||||
ID: [SYS_OS_0102, SYS_MISC_0103, SYS_MISC_0102, SYS_MISC_0105, SYS_MISC_0104,
|
||||
SYS_MISC_0107, SYS_MISC_0106, SYS_MISC_0109, SYS_MISC_0108, SYS_MISC_0112, SYS_MISC_0113,
|
||||
SYS_MISC_0110, SYS_MISC_0111, SYS_MISC_0115, SYS_LIB_0103, SYS_LIB_0102, SYS_LIB_0101,
|
||||
SYS_LIB_0106, SYS_LIB_0105, SYS_LIB_0104]
|
||||
ID: [SYS_OS_0102, SYS_MISC_0102, SYS_MISC_0107, SYS_MISC_0106, SYS_MISC_0109,
|
||||
SYS_MISC_0108, SYS_MISC_0112, SYS_MISC_0113, SYS_MISC_0110, SYS_MISC_0111, SYS_LIB_0103,
|
||||
SYS_LIB_0102, SYS_LIB_0101, SYS_LIB_0106, SYS_LIB_0105, SYS_LIB_0104]
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue