mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
feat(bluetooth/controller): adjust bt/porting code structure and delete redundant code
This commit is contained in:
parent
509015cfab
commit
a76076fe14
@ -482,12 +482,11 @@ if(CONFIG_BT_ENABLED)
|
||||
if(CONFIG_BT_LE_CONTROLLER_NPL_OS_PORTING_SUPPORT)
|
||||
list(APPEND srcs
|
||||
"porting/npl/freertos/src/npl_os_freertos.c"
|
||||
"porting/nimble/src/os_msys_init.c"
|
||||
"porting/mem/os_msys_init.c"
|
||||
)
|
||||
|
||||
list(APPEND include_dirs
|
||||
porting/include
|
||||
porting/nimble/include
|
||||
porting/npl/freertos/include
|
||||
porting/transport/include
|
||||
)
|
||||
@ -526,6 +525,7 @@ if(CONFIG_BT_ENABLED)
|
||||
list(APPEND include_dirs
|
||||
|
||||
host/nimble/nimble/nimble/host/include
|
||||
host/nimble/nimble/nimble/include
|
||||
host/nimble/nimble/nimble/host/services/ans/include
|
||||
host/nimble/nimble/nimble/host/services/bas/include
|
||||
host/nimble/nimble/nimble/host/services/dis/include
|
||||
@ -606,7 +606,6 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/nimble/nimble/porting/npl/freertos/src/nimble_port_freertos.c"
|
||||
)
|
||||
list(APPEND include_dirs
|
||||
porting/include
|
||||
host/nimble/nimble/porting/nimble/include
|
||||
host/nimble/port/include
|
||||
)
|
||||
@ -621,9 +620,8 @@ if(CONFIG_BT_ENABLED)
|
||||
"host/nimble/nimble/porting/npl/freertos/src/npl_os_freertos.c"
|
||||
)
|
||||
list(APPEND include_dirs
|
||||
porting/include
|
||||
host/nimble/nimble/porting/npl/freertos/include
|
||||
host/nimble/nimble/porting/nimble/include
|
||||
host/nimble/nimble/nimble/include
|
||||
)
|
||||
endif()
|
||||
|
||||
|
@ -16,7 +16,10 @@
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "nimble/nimble_port.h"
|
||||
#endif // CONFIG_BT_NIMBLE_ENABLED
|
||||
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@ -28,7 +31,7 @@
|
||||
#endif
|
||||
|
||||
#include "nimble/nimble_npl_os.h"
|
||||
#include "nimble/ble_hci_trans.h"
|
||||
#include "ble_hci_trans.h"
|
||||
#include "os/endian.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
|
@ -14,7 +14,10 @@
|
||||
|
||||
#include "sdkconfig.h"
|
||||
|
||||
#if CONFIG_BT_NIMBLE_ENABLED
|
||||
#include "nimble/nimble_port.h"
|
||||
#endif // CONFIG_BT_NIMBLE_ENABLED
|
||||
|
||||
#include "nimble/nimble_port_freertos.h"
|
||||
|
||||
#ifdef ESP_PLATFORM
|
||||
@ -26,7 +29,7 @@
|
||||
#endif
|
||||
|
||||
#include "nimble/nimble_npl_os.h"
|
||||
#include "nimble/ble_hci_trans.h"
|
||||
#include "ble_hci_trans.h"
|
||||
#include "os/endian.h"
|
||||
|
||||
#include "esp_bt.h"
|
||||
@ -69,12 +72,11 @@
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
/* ACL_DATA_MBUF_LEADINGSPCAE: The leadingspace in user info header for ACL data */
|
||||
#define ACL_DATA_MBUF_LEADINGSPCAE 4
|
||||
#endif
|
||||
#endif // CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
/* Types definition
|
||||
************************************************************************
|
||||
*/
|
||||
|
||||
struct osi_coex_funcs_t {
|
||||
uint32_t _magic;
|
||||
uint32_t _version;
|
||||
@ -186,9 +188,8 @@ static DRAM_ATTR esp_bt_controller_status_t ble_controller_status = ESP_BT_CONTR
|
||||
static bool s_ble_active = false;
|
||||
#ifdef CONFIG_PM_ENABLE
|
||||
static DRAM_ATTR esp_pm_lock_handle_t s_pm_lock = NULL;
|
||||
|
||||
#define BTDM_MIN_TIMER_UNCERTAINTY_US (200)
|
||||
#endif /* #ifdef CONFIG_PM_ENABLE */
|
||||
#endif // CONFIG_PM_ENABLE
|
||||
|
||||
#ifdef CONFIG_BT_LE_WAKEUP_SOURCE_BLE_RTC_TIMER
|
||||
#define BLE_RTC_DELAY_US (1100)
|
||||
@ -256,17 +257,17 @@ static void coex_schm_status_bit_set_wrapper(uint32_t type, uint32_t status)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
coex_schm_status_bit_set(type, status);
|
||||
#endif
|
||||
#endif // CONFIG_SW_COEXIST_ENABLE
|
||||
}
|
||||
|
||||
static void coex_schm_status_bit_clear_wrapper(uint32_t type, uint32_t status)
|
||||
{
|
||||
#if CONFIG_SW_COEXIST_ENABLE
|
||||
coex_schm_status_bit_clear(type, status);
|
||||
#endif
|
||||
#endif // CONFIG_SW_COEXIST_ENABLE
|
||||
}
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
|
||||
#ifdef CONFIG_BT_BLUEDROID_ENABLED
|
||||
bool esp_vhci_host_check_send_available(void)
|
||||
{
|
||||
if (ble_controller_status != ESP_BT_CONTROLLER_STATUS_ENABLED) {
|
||||
@ -319,6 +320,7 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)
|
||||
if (*(data) == DATA_TYPE_COMMAND) {
|
||||
struct ble_hci_cmd *cmd = NULL;
|
||||
cmd = (struct ble_hci_cmd *) ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_CMD);
|
||||
assert(cmd);
|
||||
memcpy((uint8_t *)cmd, data + 1, len - 1);
|
||||
ble_hci_trans_hs_cmd_tx((uint8_t *)cmd);
|
||||
}
|
||||
@ -329,7 +331,6 @@ void esp_vhci_host_send_packet(uint8_t *data, uint16_t len)
|
||||
assert(os_mbuf_append(om, &data[1], len - 1) == 0);
|
||||
ble_hci_trans_hs_acl_tx(om);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callback)
|
||||
@ -342,8 +343,7 @@ esp_err_t esp_vhci_host_register_callback(const esp_vhci_host_callback_t *callba
|
||||
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // CONFIG_BT_BLUEDROID_ENABLED
|
||||
static int task_create_wrapper(void *task_func, const char *name, uint32_t stack_depth, void *param, uint32_t prio, void *task_handle, uint32_t core_id)
|
||||
{
|
||||
return (uint32_t)xTaskCreatePinnedToCore(task_func, name, stack_depth, param, prio, task_handle, (core_id < portNUM_PROCESSORS ? core_id : tskNO_AFFINITY));
|
||||
@ -601,7 +601,6 @@ esp_err_t esp_bt_controller_init(esp_bt_controller_config_t *cfg)
|
||||
esp_err_t ret = ESP_OK;
|
||||
ble_npl_count_info_t npl_info;
|
||||
memset(&npl_info, 0, sizeof(ble_npl_count_info_t));
|
||||
|
||||
if (ble_controller_status != ESP_BT_CONTROLLER_STATUS_IDLE) {
|
||||
ESP_LOGW(NIMBLE_PORT_LOG_TAG, "invalid controller state");
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@ -806,7 +805,6 @@ static esp_err_t try_heap_caps_add_region(intptr_t start, intptr_t end)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
intptr_t start;
|
||||
intptr_t end;
|
||||
|
@ -32,7 +32,7 @@
|
||||
#include "stack/hcimsgs.h"
|
||||
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER
|
||||
#include "nimble/ble_hci_trans.h"
|
||||
#include "ble_hci_trans.h"
|
||||
#endif
|
||||
|
||||
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE)
|
||||
|
@ -1,20 +1,7 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* 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.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef H_HCI_TRANSPORT_
|
@ -66,7 +66,7 @@ struct os_mbuf_pool {
|
||||
|
||||
|
||||
/**
|
||||
* A packet header structure that preceeds the mbuf packet headers.
|
||||
* A packet header structure that proceeds the mbuf packet headers.
|
||||
*/
|
||||
struct os_mbuf_pkthdr {
|
||||
/**
|
||||
@ -90,7 +90,7 @@ struct os_mbuf {
|
||||
*/
|
||||
uint8_t *om_data;
|
||||
/**
|
||||
* Flags associated with this buffer, see OS_MBUF_F_* defintions
|
||||
* Flags associated with this buffer, see OS_MBUF_F_* definitions
|
||||
*/
|
||||
uint8_t om_flags;
|
||||
/**
|
@ -1,33 +1,27 @@
|
||||
/*
|
||||
* Copyright (c) 1991, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
* SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
* SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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
|
||||
*
|
||||
* @(#)queue.h 8.5 (Berkeley) 8/20/94
|
||||
* $FreeBSD: src/sys/sys/queue.h,v 1.32.2.7 2002/04/17 14:21:02 des Exp $
|
||||
* 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 _QUEUE_H_
|
@ -1,319 +0,0 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF)
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* SPDX-FileContributor: 2019-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*/
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 H_BLE_
|
||||
#define H_BLE_
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "os/os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* The number of advertising instances */
|
||||
#define BLE_ADV_INSTANCES (MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES) + 1)
|
||||
|
||||
/* BLE encryption block definitions */
|
||||
#define BLE_ENC_BLOCK_SIZE (16)
|
||||
|
||||
/* 4 byte header + 251 byte payload. */
|
||||
#define BLE_ACL_MAX_PKT_SIZE 255
|
||||
|
||||
struct ble_encryption_block
|
||||
{
|
||||
uint8_t key[BLE_ENC_BLOCK_SIZE];
|
||||
uint8_t plain_text[BLE_ENC_BLOCK_SIZE];
|
||||
uint8_t cipher_text[BLE_ENC_BLOCK_SIZE];
|
||||
};
|
||||
|
||||
/*
|
||||
* BLE MBUF structure:
|
||||
*
|
||||
* The BLE mbuf structure is as follows. Note that this structure applies to
|
||||
* the packet header mbuf (not mbufs that are part of a "packet chain"):
|
||||
* struct os_mbuf (16)
|
||||
* struct os_mbuf_pkthdr (8)
|
||||
* struct ble_mbuf_hdr (8)
|
||||
* Data buffer (payload size, in bytes)
|
||||
*
|
||||
* The BLE mbuf header contains the following:
|
||||
* flags: bitfield with the following values
|
||||
* 0x01: Set if there was a match on the whitelist
|
||||
* 0x02: Set if a connect request was transmitted upon receiving pdu
|
||||
* 0x04: Set the first time we transmit the PDU (used to detect retry).
|
||||
* channel: The logical BLE channel PHY channel # (0 - 39)
|
||||
* crcok: flag denoting CRC check passed (1) or failed (0).
|
||||
* rssi: RSSI, in dBm.
|
||||
*/
|
||||
struct ble_mbuf_hdr_rxinfo
|
||||
{
|
||||
uint16_t flags;
|
||||
uint8_t channel;
|
||||
uint8_t handle;
|
||||
int8_t rssi;
|
||||
/* XXX: we could just use single phy_mode field */
|
||||
int8_t phy;
|
||||
uint8_t phy_mode;
|
||||
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_PRIVACY)
|
||||
int8_t rpa_index;
|
||||
#endif
|
||||
#if MYNEWT_VAL(BLE_LL_CFG_FEAT_LL_EXT_ADV)
|
||||
void *user_data;
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* Flag definitions for rxinfo
|
||||
*
|
||||
* Note: it's ok to have symbols with the same values as long as they cannot be
|
||||
* set for the same PDU (e.g. one use by scanner, other one used by
|
||||
* connection)
|
||||
*/
|
||||
#define BLE_MBUF_HDR_F_CONN_CREDIT (0x8000)
|
||||
#define BLE_MBUF_HDR_F_IGNORED (0x8000)
|
||||
#define BLE_MBUF_HDR_F_SCAN_REQ_TXD (0x4000)
|
||||
#define BLE_MBUF_HDR_F_INITA_RESOLVED (0x2000)
|
||||
#define BLE_MBUF_HDR_F_TARGETA_RESOLVED (0x2000)
|
||||
#define BLE_MBUF_HDR_F_EXT_ADV_SEC (0x1000)
|
||||
#define BLE_MBUF_HDR_F_EXT_ADV (0x0800)
|
||||
#define BLE_MBUF_HDR_F_RESOLVED (0x0400)
|
||||
#define BLE_MBUF_HDR_F_AUX_PTR_WAIT (0x0200)
|
||||
#define BLE_MBUF_HDR_F_AUX_INVALID (0x0100)
|
||||
#define BLE_MBUF_HDR_F_CRC_OK (0x0080)
|
||||
#define BLE_MBUF_HDR_F_DEVMATCH (0x0040)
|
||||
#define BLE_MBUF_HDR_F_MIC_FAILURE (0x0020)
|
||||
#define BLE_MBUF_HDR_F_SCAN_RSP_TXD (0x0010)
|
||||
#define BLE_MBUF_HDR_F_SCAN_RSP_RXD (0x0008)
|
||||
#define BLE_MBUF_HDR_F_RXSTATE_MASK (0x0007)
|
||||
|
||||
/* Transmit info. NOTE: no flags defined */
|
||||
struct ble_mbuf_hdr_txinfo
|
||||
{
|
||||
uint8_t flags;
|
||||
uint8_t reserve0;
|
||||
uint8_t pyld_len;
|
||||
uint8_t hdr_byte;
|
||||
uint16_t offset;
|
||||
};
|
||||
|
||||
struct ble_mbuf_hdr
|
||||
{
|
||||
union {
|
||||
struct ble_mbuf_hdr_rxinfo rxinfo;
|
||||
struct ble_mbuf_hdr_txinfo txinfo;
|
||||
};
|
||||
uint32_t beg_cputime;
|
||||
uint32_t rem_usecs;
|
||||
};
|
||||
|
||||
#define BLE_MBUF_HDR_IGNORED(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_IGNORED))
|
||||
|
||||
#define BLE_MBUF_HDR_SCAN_REQ_TXD(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_SCAN_REQ_TXD))
|
||||
|
||||
#define BLE_MBUF_HDR_EXT_ADV_SEC(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_EXT_ADV_SEC))
|
||||
|
||||
#define BLE_MBUF_HDR_EXT_ADV(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_EXT_ADV))
|
||||
|
||||
#define BLE_MBUF_HDR_DEVMATCH(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_DEVMATCH))
|
||||
|
||||
#define BLE_MBUF_HDR_SCAN_RSP_RXD(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_SCAN_RSP_RXD))
|
||||
|
||||
#define BLE_MBUF_HDR_AUX_INVALID(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_AUX_INVALID))
|
||||
|
||||
#define BLE_MBUF_HDR_WAIT_AUX(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_AUX_PTR_WAIT))
|
||||
|
||||
#define BLE_MBUF_HDR_CRC_OK(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_CRC_OK))
|
||||
|
||||
#define BLE_MBUF_HDR_MIC_FAILURE(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_MIC_FAILURE))
|
||||
|
||||
#define BLE_MBUF_HDR_RESOLVED(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_RESOLVED))
|
||||
|
||||
#define BLE_MBUF_HDR_INITA_RESOLVED(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_INITA_RESOLVED))
|
||||
|
||||
#define BLE_MBUF_HDR_TARGETA_RESOLVED(hdr) \
|
||||
(!!((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_TARGETA_RESOLVED))
|
||||
|
||||
#define BLE_MBUF_HDR_RX_STATE(hdr) \
|
||||
((uint8_t)((hdr)->rxinfo.flags & BLE_MBUF_HDR_F_RXSTATE_MASK))
|
||||
|
||||
#define BLE_MBUF_HDR_PTR(om) \
|
||||
(struct ble_mbuf_hdr *)((uint8_t *)om + sizeof(struct os_mbuf) + \
|
||||
sizeof(struct os_mbuf_pkthdr))
|
||||
|
||||
/* BLE mbuf overhead per packet header mbuf */
|
||||
#define BLE_MBUF_PKTHDR_OVERHEAD \
|
||||
(sizeof(struct os_mbuf_pkthdr) + sizeof(struct ble_mbuf_hdr))
|
||||
|
||||
#define BLE_MBUF_MEMBLOCK_OVERHEAD \
|
||||
(sizeof(struct os_mbuf) + BLE_MBUF_PKTHDR_OVERHEAD)
|
||||
|
||||
/* Length of host user header. Only contains the peer's connection handle. */
|
||||
#define BLE_MBUF_HS_HDR_LEN (2)
|
||||
|
||||
#define BLE_DEV_ADDR_LEN (6)
|
||||
extern uint8_t g_dev_addr[BLE_DEV_ADDR_LEN];
|
||||
extern uint8_t g_random_addr[BLE_DEV_ADDR_LEN];
|
||||
|
||||
/* BLE Error Codes (Core v4.2 Vol 2 part D) */
|
||||
enum ble_error_codes
|
||||
{
|
||||
/* An "error" code of 0x0 means success */
|
||||
BLE_ERR_SUCCESS = 0x00,
|
||||
BLE_ERR_UNKNOWN_HCI_CMD = 0x01,
|
||||
BLE_ERR_UNK_CONN_ID = 0x02,
|
||||
BLE_ERR_HW_FAIL = 0x03,
|
||||
BLE_ERR_PAGE_TMO = 0x04,
|
||||
BLE_ERR_AUTH_FAIL = 0x05,
|
||||
BLE_ERR_PINKEY_MISSING = 0x06,
|
||||
BLE_ERR_MEM_CAPACITY = 0x07,
|
||||
BLE_ERR_CONN_SPVN_TMO = 0x08,
|
||||
BLE_ERR_CONN_LIMIT = 0x09,
|
||||
BLE_ERR_SYNCH_CONN_LIMIT = 0x0a,
|
||||
BLE_ERR_ACL_CONN_EXISTS = 0x0b,
|
||||
BLE_ERR_CMD_DISALLOWED = 0x0c,
|
||||
BLE_ERR_CONN_REJ_RESOURCES = 0x0d,
|
||||
BLE_ERR_CONN_REJ_SECURITY = 0x0e,
|
||||
BLE_ERR_CONN_REJ_BD_ADDR = 0x0f,
|
||||
BLE_ERR_CONN_ACCEPT_TMO = 0x10,
|
||||
BLE_ERR_UNSUPPORTED = 0x11,
|
||||
BLE_ERR_INV_HCI_CMD_PARMS = 0x12,
|
||||
BLE_ERR_REM_USER_CONN_TERM = 0x13,
|
||||
BLE_ERR_RD_CONN_TERM_RESRCS = 0x14,
|
||||
BLE_ERR_RD_CONN_TERM_PWROFF = 0x15,
|
||||
BLE_ERR_CONN_TERM_LOCAL = 0x16,
|
||||
BLE_ERR_REPEATED_ATTEMPTS = 0x17,
|
||||
BLE_ERR_NO_PAIRING = 0x18,
|
||||
BLE_ERR_UNK_LMP = 0x19,
|
||||
BLE_ERR_UNSUPP_REM_FEATURE = 0x1a,
|
||||
BLE_ERR_SCO_OFFSET = 0x1b,
|
||||
BLE_ERR_SCO_ITVL = 0x1c,
|
||||
BLE_ERR_SCO_AIR_MODE = 0x1d,
|
||||
BLE_ERR_INV_LMP_LL_PARM = 0x1e,
|
||||
BLE_ERR_UNSPECIFIED = 0x1f,
|
||||
BLE_ERR_UNSUPP_LMP_LL_PARM = 0x20,
|
||||
BLE_ERR_NO_ROLE_CHANGE = 0x21,
|
||||
BLE_ERR_LMP_LL_RSP_TMO = 0x22,
|
||||
BLE_ERR_LMP_COLLISION = 0x23,
|
||||
BLE_ERR_LMP_PDU = 0x24,
|
||||
BLE_ERR_ENCRYPTION_MODE = 0x25,
|
||||
BLE_ERR_LINK_KEY_CHANGE = 0x26,
|
||||
BLE_ERR_UNSUPP_QOS = 0x27,
|
||||
BLE_ERR_INSTANT_PASSED = 0x28,
|
||||
BLE_ERR_UNIT_KEY_PAIRING = 0x29,
|
||||
BLE_ERR_DIFF_TRANS_COLL = 0x2a,
|
||||
/* BLE_ERR_RESERVED = 0x2b */
|
||||
BLE_ERR_QOS_PARM = 0x2c,
|
||||
BLE_ERR_QOS_REJECTED = 0x2d,
|
||||
BLE_ERR_CHAN_CLASS = 0x2e,
|
||||
BLE_ERR_INSUFFICIENT_SEC = 0x2f,
|
||||
BLE_ERR_PARM_OUT_OF_RANGE = 0x30,
|
||||
/* BLE_ERR_RESERVED = 0x31 */
|
||||
BLE_ERR_PENDING_ROLE_SW = 0x32,
|
||||
/* BLE_ERR_RESERVED = 0x33 */
|
||||
BLE_ERR_RESERVED_SLOT = 0x34,
|
||||
BLE_ERR_ROLE_SW_FAIL = 0x35,
|
||||
BLE_ERR_INQ_RSP_TOO_BIG = 0x36,
|
||||
BLE_ERR_SEC_SIMPLE_PAIR = 0x37,
|
||||
BLE_ERR_HOST_BUSY_PAIR = 0x38,
|
||||
BLE_ERR_CONN_REJ_CHANNEL = 0x39,
|
||||
BLE_ERR_CTLR_BUSY = 0x3a,
|
||||
BLE_ERR_CONN_PARMS = 0x3b,
|
||||
BLE_ERR_DIR_ADV_TMO = 0x3c,
|
||||
BLE_ERR_CONN_TERM_MIC = 0x3d,
|
||||
BLE_ERR_CONN_ESTABLISHMENT = 0x3e,
|
||||
BLE_ERR_MAC_CONN_FAIL = 0x3f,
|
||||
BLE_ERR_COARSE_CLK_ADJ = 0x40,
|
||||
BLE_ERR_TYPE0_SUBMAP_NDEF = 0x41,
|
||||
BLE_ERR_UNK_ADV_INDENT = 0x42,
|
||||
BLE_ERR_LIMIT_REACHED = 0x43,
|
||||
BLE_ERR_OPERATION_CANCELLED = 0x44,
|
||||
BLE_ERR_PACKET_TOO_LONG = 0x45,
|
||||
BLE_ERR_MAX = 0xff
|
||||
};
|
||||
|
||||
/* HW error codes */
|
||||
#define BLE_HW_ERR_DO_NOT_USE (0) /* XXX: reserve this one for now */
|
||||
#define BLE_HW_ERR_HCI_SYNC_LOSS (1)
|
||||
|
||||
/* Own Bluetooth Device address type */
|
||||
#define BLE_OWN_ADDR_PUBLIC (0x00)
|
||||
#define BLE_OWN_ADDR_RANDOM (0x01)
|
||||
#define BLE_OWN_ADDR_RPA_PUBLIC_DEFAULT (0x02)
|
||||
#define BLE_OWN_ADDR_RPA_RANDOM_DEFAULT (0x03)
|
||||
|
||||
/* Bluetooth Device address type */
|
||||
#define BLE_ADDR_PUBLIC (0x00)
|
||||
#define BLE_ADDR_RANDOM (0x01)
|
||||
#define BLE_ADDR_PUBLIC_ID (0x02)
|
||||
#define BLE_ADDR_RANDOM_ID (0x03)
|
||||
|
||||
#define BLE_ADDR_ANY (&(ble_addr_t) { 0, {0, 0, 0, 0, 0, 0} })
|
||||
|
||||
#define BLE_ADDR_IS_RPA(addr) (((addr)->type == BLE_ADDR_RANDOM) && \
|
||||
((addr)->val[5] & 0xc0) == 0x40)
|
||||
#define BLE_ADDR_IS_NRPA(addr) (((addr)->type == BLE_ADDR_RANDOM) && \
|
||||
((addr)->val[5] & 0xc0) == 0x00)
|
||||
#define BLE_ADDR_IS_STATIC(addr) (((addr)->type == BLE_ADDR_RANDOM) && \
|
||||
((addr)->val[5] & 0xc0) == 0xc0)
|
||||
|
||||
typedef struct {
|
||||
uint8_t type;
|
||||
uint8_t val[6];
|
||||
} ble_addr_t;
|
||||
|
||||
|
||||
static inline int ble_addr_cmp(const ble_addr_t *a, const ble_addr_t *b)
|
||||
{
|
||||
int type_diff;
|
||||
|
||||
type_diff = a->type - b->type;
|
||||
if (type_diff != 0) {
|
||||
return type_diff;
|
||||
}
|
||||
|
||||
return memcmp(a->val, b->val, sizeof(a->val));
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* H_BLE_ */
|
@ -1,34 +0,0 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 H_NIMBLE_OPT_
|
||||
#define H_NIMBLE_OPT_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Include automatically-generated settings. */
|
||||
#include "nimble/nimble_opt_auto.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
@ -1,20 +1,7 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* 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.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#ifndef _NIMBLE_NPL_H_
|
@ -1,9 +1,7 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2022 The Apache Software Foundation (ASF)
|
||||
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* SPDX-FileContributor: 2019-2024 Espressif Systems (Shanghai) CO LTD
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
@ -18,7 +16,6 @@
|
||||
#include "freertos/timers.h"
|
||||
#include "freertos/portable.h"
|
||||
#include "nimble/npl_freertos.h"
|
||||
#include "nimble/nimble_port.h"
|
||||
|
||||
#include "os/os_mempool.h"
|
||||
#include "esp_log.h"
|
||||
@ -455,32 +452,32 @@ IRAM_ATTR npl_freertos_mutex_release(struct ble_npl_mutex *mu)
|
||||
ble_npl_error_t
|
||||
npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
|
||||
{
|
||||
struct ble_npl_sem_freertos *semaphor = NULL;
|
||||
struct ble_npl_sem_freertos *semaphore = NULL;
|
||||
#if OS_MEM_ALLOC
|
||||
if (!os_memblock_from(&ble_freertos_sem_pool,sem->sem)) {
|
||||
sem->sem = os_memblock_get(&ble_freertos_sem_pool);
|
||||
semaphor = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
semaphore = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
|
||||
if (!semaphor) {
|
||||
if (!semaphore) {
|
||||
return BLE_NPL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
memset(semaphor, 0, sizeof(*semaphor));
|
||||
semaphor->handle = xSemaphoreCreateCounting(128, tokens);
|
||||
BLE_LL_ASSERT(semaphor->handle);
|
||||
memset(semaphore, 0, sizeof(*semaphore));
|
||||
semaphore->handle = xSemaphoreCreateCounting(128, tokens);
|
||||
BLE_LL_ASSERT(semaphore->handle);
|
||||
}
|
||||
#else
|
||||
if(!sem->sem) {
|
||||
sem->sem = malloc(sizeof(struct ble_npl_sem_freertos));
|
||||
semaphor = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
semaphore = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
|
||||
if (!semaphor) {
|
||||
if (!semaphore) {
|
||||
return BLE_NPL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
memset(semaphor, 0, sizeof(*semaphor));
|
||||
semaphor->handle = xSemaphoreCreateCounting(128, tokens);
|
||||
BLE_LL_ASSERT(semaphor->handle);
|
||||
memset(semaphore, 0, sizeof(*semaphore));
|
||||
semaphore->handle = xSemaphoreCreateCounting(128, tokens);
|
||||
BLE_LL_ASSERT(semaphore->handle);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -490,19 +487,19 @@ npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
|
||||
ble_npl_error_t
|
||||
npl_freertos_sem_deinit(struct ble_npl_sem *sem)
|
||||
{
|
||||
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
|
||||
if (!semaphor) {
|
||||
if (!semaphore) {
|
||||
return BLE_NPL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
BLE_LL_ASSERT(semaphor->handle);
|
||||
vSemaphoreDelete(semaphor->handle);
|
||||
BLE_LL_ASSERT(semaphore->handle);
|
||||
vSemaphoreDelete(semaphore->handle);
|
||||
|
||||
#if OS_MEM_ALLOC
|
||||
os_memblock_put(&ble_freertos_sem_pool,semaphor);
|
||||
os_memblock_put(&ble_freertos_sem_pool,semaphore);
|
||||
#else
|
||||
free((void *)semaphor);
|
||||
free((void *)semaphore);
|
||||
#endif
|
||||
sem->sem = NULL;
|
||||
|
||||
@ -514,22 +511,22 @@ IRAM_ATTR npl_freertos_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
|
||||
{
|
||||
BaseType_t woken;
|
||||
BaseType_t ret;
|
||||
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
|
||||
if (!semaphor) {
|
||||
if (!semaphore) {
|
||||
return BLE_NPL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
BLE_LL_ASSERT(semaphor->handle);
|
||||
BLE_LL_ASSERT(semaphore->handle);
|
||||
|
||||
if (in_isr()) {
|
||||
BLE_LL_ASSERT(timeout == 0);
|
||||
ret = xSemaphoreTakeFromISR(semaphor->handle, &woken);
|
||||
ret = xSemaphoreTakeFromISR(semaphore->handle, &woken);
|
||||
if( woken == pdTRUE ) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
} else {
|
||||
ret = xSemaphoreTake(semaphor->handle, timeout);
|
||||
ret = xSemaphoreTake(semaphore->handle, timeout);
|
||||
}
|
||||
|
||||
return ret == pdPASS ? BLE_NPL_OK : BLE_NPL_TIMEOUT;
|
||||
@ -540,21 +537,21 @@ IRAM_ATTR npl_freertos_sem_release(struct ble_npl_sem *sem)
|
||||
{
|
||||
BaseType_t ret;
|
||||
BaseType_t woken;
|
||||
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
|
||||
if (!semaphor) {
|
||||
if (!semaphore) {
|
||||
return BLE_NPL_INVALID_PARAM;
|
||||
}
|
||||
|
||||
BLE_LL_ASSERT(semaphor->handle);
|
||||
BLE_LL_ASSERT(semaphore->handle);
|
||||
|
||||
if (in_isr()) {
|
||||
ret = xSemaphoreGiveFromISR(semaphor->handle, &woken);
|
||||
ret = xSemaphoreGiveFromISR(semaphore->handle, &woken);
|
||||
if( woken == pdTRUE ) {
|
||||
portYIELD_FROM_ISR();
|
||||
}
|
||||
} else {
|
||||
ret = xSemaphoreGive(semaphor->handle);
|
||||
ret = xSemaphoreGive(semaphore->handle);
|
||||
}
|
||||
|
||||
BLE_LL_ASSERT(ret == pdPASS);
|
||||
@ -747,8 +744,8 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
|
||||
uint16_t
|
||||
IRAM_ATTR npl_freertos_sem_get_count(struct ble_npl_sem *sem)
|
||||
{
|
||||
struct ble_npl_sem_freertos *semaphor = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
return uxSemaphoreGetCount(semaphor->handle);
|
||||
struct ble_npl_sem_freertos *semaphore = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
return uxSemaphoreGetCount(semaphore->handle);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user