feat(bluetooth/controller): adjust bt/porting code structure and delete redundant code

This commit is contained in:
zwl 2024-06-20 19:12:06 +08:00
parent 430d65225e
commit a21f65cb5b
22 changed files with 72 additions and 665 deletions

View File

@ -575,7 +575,7 @@ 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"
)
if(CONFIG_BT_CONTROLLER_DISABLED)
@ -585,7 +585,6 @@ if(CONFIG_BT_ENABLED)
endif()
list(APPEND include_dirs
porting/include
porting/nimble/include
porting/npl/freertos/include
porting/transport/include
)
@ -727,7 +726,6 @@ if(CONFIG_BT_ENABLED)
"host/nimble/port/src/nvs_port.c"
)
list(APPEND include_dirs
porting/include
host/nimble/nimble/porting/nimble/include
host/nimble/port/include
host/nimble/nimble/nimble/transport/include
@ -756,9 +754,8 @@ if(CONFIG_BT_ENABLED)
endif()
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()

View File

@ -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"

View File

@ -15,7 +15,9 @@
#include "sdkconfig.h"
#if CONFIG_BT_NIMBLE_ENABLED
#include "nimble/nimble_port.h"
#endif // CONFIG_BT_NIMBLE_ENABLED
#include "nimble/nimble_port_freertos.h"
#include "esp_private/esp_modem_clock.h"
@ -28,7 +30,7 @@
#endif // CONFIG_SW_COEXIST_ENABLE
#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"

View File

@ -15,7 +15,9 @@
#include "sdkconfig.h"
#if CONFIG_BT_NIMBLE_ENABLED
#include "nimble/nimble_port.h"
#endif // CONFIG_BT_NIMBLE_ENABLED
#include "nimble/nimble_port_freertos.h"
#include "esp_private/esp_modem_clock.h"
@ -28,7 +30,7 @@
#endif // CONFIG_ESP_COEX_ENABLED
#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"

View File

@ -15,7 +15,9 @@
#include "sdkconfig.h"
#if CONFIG_BT_NIMBLE_ENABLED
#include "nimble/nimble_port.h"
#endif // CONFIG_BT_NIMBLE_ENABLED
#include "nimble/nimble_port_freertos.h"
#include "esp_private/esp_modem_clock.h"
@ -28,7 +30,7 @@
#endif // CONFIG_ESP_COEX_ENABLED
#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"

View File

@ -36,7 +36,7 @@
#include "stack/hcimsgs.h"
#if ((BT_CONTROLLER_INCLUDED == TRUE) && SOC_ESP_NIMBLE_CONTROLLER)
#include "nimble/ble_hci_trans.h"
#include "ble_hci_trans.h"
#endif
#if (C2H_FLOW_CONTROL_INCLUDED == TRUE)

View File

@ -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_

View File

@ -65,7 +65,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 {
/**
@ -89,7 +89,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;
/**

View File

@ -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_

View File

@ -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_ */

View File

@ -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

View File

@ -1,132 +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_NIMBLE_OPT_AUTO_
#define H_NIMBLE_OPT_AUTO_
#include "syscfg/syscfg.h"
#ifdef __cplusplus
extern "C" {
#endif
/***
* Automatic options.
*
* These settings are generated automatically from the user-specified syscfg
* settings.
*/
#undef NIMBLE_BLE_ADVERTISE
#define NIMBLE_BLE_ADVERTISE \
(MYNEWT_VAL(BLE_ROLE_BROADCASTER) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL))
#undef NIMBLE_BLE_SCAN
#define NIMBLE_BLE_SCAN \
(MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_OBSERVER))
#undef NIMBLE_BLE_CONNECT
#define NIMBLE_BLE_CONNECT \
(MYNEWT_VAL(BLE_ROLE_CENTRAL) || MYNEWT_VAL(BLE_ROLE_PERIPHERAL))
/** Supported client ATT commands. */
#undef NIMBLE_BLE_ATT_CLT_FIND_INFO
#define NIMBLE_BLE_ATT_CLT_FIND_INFO \
(MYNEWT_VAL(BLE_GATT_DISC_ALL_DSCS))
#undef NIMBLE_BLE_ATT_CLT_FIND_TYPE
#define NIMBLE_BLE_ATT_CLT_FIND_TYPE \
(MYNEWT_VAL(BLE_GATT_DISC_SVC_UUID))
#undef NIMBLE_BLE_ATT_CLT_READ_TYPE
#define NIMBLE_BLE_ATT_CLT_READ_TYPE \
(MYNEWT_VAL(BLE_GATT_FIND_INC_SVCS) || \
MYNEWT_VAL(BLE_GATT_DISC_ALL_CHRS) || \
MYNEWT_VAL(BLE_GATT_DISC_CHRS_UUID) || \
MYNEWT_VAL(BLE_GATT_READ_UUID))
#undef NIMBLE_BLE_ATT_CLT_READ
#define NIMBLE_BLE_ATT_CLT_READ \
(MYNEWT_VAL(BLE_GATT_READ) || \
MYNEWT_VAL(BLE_GATT_READ_LONG) || \
MYNEWT_VAL(BLE_GATT_FIND_INC_SVCS))
#undef NIMBLE_BLE_ATT_CLT_READ_BLOB
#define NIMBLE_BLE_ATT_CLT_READ_BLOB \
(MYNEWT_VAL(BLE_GATT_READ_LONG))
#undef NIMBLE_BLE_ATT_CLT_READ_MULT
#define NIMBLE_BLE_ATT_CLT_READ_MULT \
(MYNEWT_VAL(BLE_GATT_READ_MULT))
#undef NIMBLE_BLE_ATT_CLT_READ_MULT_VAR
#define NIMBLE_BLE_ATT_CLT_READ_MULT_VAR \
(MYNEWT_VAL(BLE_GATT_READ_MULT_VAR))
#undef NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE
#define NIMBLE_BLE_ATT_CLT_READ_GROUP_TYPE \
(MYNEWT_VAL(BLE_GATT_DISC_ALL_SVCS))
#undef NIMBLE_BLE_ATT_CLT_WRITE
#define NIMBLE_BLE_ATT_CLT_WRITE \
(MYNEWT_VAL(BLE_GATT_WRITE))
#undef NIMBLE_BLE_ATT_CLT_SIGNED_WRITE
#define NIMBLE_BLE_ATT_CLT_SIGNED_WRITE \
(MYNEWT_VAL(BLE_GATT_SIGNED_WRITE))
#undef NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP
#define NIMBLE_BLE_ATT_CLT_WRITE_NO_RSP \
(MYNEWT_VAL(BLE_GATT_WRITE_NO_RSP))
#undef NIMBLE_BLE_ATT_CLT_PREP_WRITE
#define NIMBLE_BLE_ATT_CLT_PREP_WRITE \
(MYNEWT_VAL(BLE_GATT_WRITE_LONG))
#undef NIMBLE_BLE_ATT_CLT_EXEC_WRITE
#define NIMBLE_BLE_ATT_CLT_EXEC_WRITE \
(MYNEWT_VAL(BLE_GATT_WRITE_LONG))
#undef NIMBLE_BLE_ATT_CLT_NOTIFY
#define NIMBLE_BLE_ATT_CLT_NOTIFY \
(MYNEWT_VAL(BLE_GATT_NOTIFY))
#undef NIMBLE_BLE_ATT_CLT_INDICATE
#define NIMBLE_BLE_ATT_CLT_INDICATE \
(MYNEWT_VAL(BLE_GATT_INDICATE))
/** Security manager settings. */
#undef NIMBLE_BLE_SM
#define NIMBLE_BLE_SM (MYNEWT_VAL(BLE_SM_LEGACY) || MYNEWT_VAL(BLE_SM_SC))
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,79 +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 _NIMBLE_PORT_H
#define _NIMBLE_PORT_H
#include "sdkconfig.h"
#include "esp_err.h"
#include "nimble/nimble_npl.h"
#define NIMBLE_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < CONFIG_FREERTOS_NUMBER_OF_CORES ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY)
#define NIMBLE_HS_STACK_SIZE CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
#define NIMBLE_LL_STACK_SIZE CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief nimble_port_init - Initialize controller and NimBLE host stack
*
* @return esp_err_t - ESP_OK ( if success)
* Error code in case of failure
*/
esp_err_t nimble_port_init(void);
/**
* @brief nimble_port_deinit - Deinitialize controller and NimBLE host stack
*
* @return esp_err_t - ESP_OK ( if success)
* Error code in case of failure
*/
esp_err_t nimble_port_deinit(void);
void nimble_port_run(void);
int nimble_port_stop(void);
/**
* @brief esp_nimble_init - Initialize the NimBLE host stack
*
* @return esp_err_t
*/
esp_err_t esp_nimble_init(void);
/**
* @brief esp_nimble_deinit - Deinitialize the NimBLE host stack
*
* @return esp_err_t
*/
esp_err_t esp_nimble_deinit(void);
struct ble_npl_eventq *nimble_port_get_dflt_eventq(void);
#ifdef __cplusplus
}
#endif
#endif /* _NIMBLE_PORT_H */

View File

@ -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_

View File

@ -1,9 +1,7 @@
/*
* SPDX-FileCopyrightText: 2019-2023 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"
@ -481,32 +478,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
@ -516,19 +513,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;
@ -540,22 +537,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;
@ -566,21 +563,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);
@ -773,8 +770,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);
}