Imported more library files
Not compiling currently
This commit is contained in:
3679
Libs/protocol/bluetooth/api/sl_bt.xapi
Normal file
3679
Libs/protocol/bluetooth/api/sl_bt.xapi
Normal file
File diff suppressed because it is too large
Load Diff
54
Libs/protocol/bluetooth/bgcommon/inc/sli_bgcommon_debug.h
Normal file
54
Libs/protocol/bluetooth/bgcommon/inc/sli_bgcommon_debug.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Debugging helpers used internally by the Bluetooth stack
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BGCOMMON_DEBUG_H
|
||||
#define SLI_BGCOMMON_DEBUG_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup sli_bgcommon_debug
|
||||
* @{
|
||||
*
|
||||
* @brief Debugging helpers used internally by the Bluetooth stack
|
||||
*
|
||||
* The functions provided by this file are used by the Bluetooth stack to access
|
||||
* device-specific registers that the device-agnostic Bluetooth libraries cannot
|
||||
* take a direct dependency to.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Enable the MCU cycle counter
|
||||
*/
|
||||
void sli_bgcommon_debug_init_cycle_count(void);
|
||||
|
||||
/**
|
||||
* @brief Get the current MCU cycle count
|
||||
*/
|
||||
uint32_t sli_bgcommon_debug_get_cycle_count(void);
|
||||
|
||||
/** @} end sli_bgcommon_debug */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SLI_BGCOMMON_DEBUG_H
|
||||
@@ -0,0 +1,31 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Debugging helpers used internally by the Bluetooth stack
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <em_device.h>
|
||||
#include "sli_bgcommon_debug.h"
|
||||
|
||||
// Enable the MCU cycle counter
|
||||
void sli_bgcommon_debug_init_cycle_count(void)
|
||||
{
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
|
||||
}
|
||||
|
||||
// Get the current MCU cycle count
|
||||
uint32_t sli_bgcommon_debug_get_cycle_count(void)
|
||||
{
|
||||
return DWT->CYCCNT;
|
||||
}
|
||||
311
Libs/protocol/bluetooth/bgstack/ll/inc/sl_btctrl_linklayer.h
Normal file
311
Libs/protocol/bluetooth/bgstack/ll/inc/sl_btctrl_linklayer.h
Normal file
@@ -0,0 +1,311 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Bluetooth Link Layer configuration API
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _SL_BTCTRL_LINKLAYER_H_
|
||||
#define _SL_BTCTRL_LINKLAYER_H_
|
||||
#include "sl_status.h"
|
||||
#include <stdint.h>
|
||||
|
||||
void sl_bt_controller_init(void);
|
||||
|
||||
void sl_bt_controller_deinit(void);
|
||||
|
||||
void sl_btctrl_init(void);
|
||||
|
||||
/**
|
||||
* Allocate memory buffers for controller
|
||||
*
|
||||
* @param memsize size of memory to allocate
|
||||
* @returns number of memory buffers allocated
|
||||
*/
|
||||
uint32_t sl_btctrl_init_mem(uint32_t memsize);
|
||||
|
||||
/**
|
||||
* Configures how many maximum sized ACL data packets
|
||||
* can the controller store.
|
||||
*/
|
||||
void sl_btctrl_configure_le_buffer_size(uint8_t count);
|
||||
|
||||
/**
|
||||
* Release all memory allocated by controller
|
||||
*/
|
||||
void sli_btctrl_deinit_mem(void);
|
||||
|
||||
void sli_btctrl_set_interrupt_priorities();
|
||||
|
||||
sl_status_t sl_btctrl_init_ll(void);
|
||||
|
||||
void sli_btctrl_set_address(uint8_t *address);
|
||||
|
||||
//Initialize memory objects used by LinkLayer
|
||||
//In future these should be configured individually
|
||||
sl_status_t sl_btctrl_init_basic(uint8_t connections, uint8_t adv_sets, uint8_t whitelist);
|
||||
|
||||
void sli_btctrl_events_init(void);
|
||||
|
||||
enum sl_btctrl_channelmap_flags{
|
||||
SL_BTCTRL_CHANNELMAP_FLAG_ACTIVE_ADAPTIVITY = 0x01,
|
||||
SL_BTCTRL_CHANNELMAP_FLAG_PASSIVE_ADAPTIVITY= 0x02,
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize and enable adaptive frequency hopping
|
||||
*/
|
||||
sl_status_t sl_btctrl_init_afh(uint32_t flags);
|
||||
|
||||
/**
|
||||
* Enable high power use under appropriate conditions
|
||||
*/
|
||||
void sl_btctrl_init_highpower(void);
|
||||
|
||||
/**
|
||||
* @brief Initilize periodic advertiser
|
||||
*/
|
||||
void sl_btctrl_init_periodic_adv();
|
||||
|
||||
/**
|
||||
* @brief Initilize periodic advertiser
|
||||
*/
|
||||
void sl_btctrl_init_periodic_scan();
|
||||
|
||||
/**
|
||||
* Configuration for Periodic Advertising with Responses.
|
||||
*/
|
||||
struct sl_btctrl_pawr_advertiser_config {
|
||||
/**
|
||||
* Number of advertising sets supporting PAwR.
|
||||
* If set to zero, previously allocated PAwR sets are only freed. */
|
||||
uint8_t max_pawr_sets;
|
||||
/**
|
||||
* Hint to the controller what will be the maximum advertised data length.
|
||||
* The value does not prevent using longer advertising data. Value zero means
|
||||
* that maximum data length can expected to be up to the length of Periodic
|
||||
* Advertising Delay. */
|
||||
uint8_t max_advertised_data_length_hint;
|
||||
/**
|
||||
* The number of subevent advertising packets requested from the host
|
||||
* at once. */
|
||||
uint8_t subevent_data_request_count;
|
||||
/**
|
||||
* How many subevents before airing a subevent its data is requested from
|
||||
* the host. */
|
||||
uint8_t subevent_data_request_advance;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration of synchronizer for Periodic Advertising with Responses.
|
||||
*/
|
||||
struct sl_btctrl_pawr_synchronizer_config {
|
||||
/**
|
||||
* Number of advertising sets supporting PArR.
|
||||
* If set to zero, previously allocated PArR sets are only freed. */
|
||||
uint8_t max_pawr_sets;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Enable and initialize support for the PAwR advertiser.
|
||||
* @param[in] pawr_adv_config PAwR advertiser configuration.
|
||||
* @return SL_STATUS_OK, or an appropriate error code. */
|
||||
sl_status_t sl_btctrl_pawr_advertiser_configure(struct sl_btctrl_pawr_advertiser_config *pawr_adv_config);
|
||||
|
||||
/**
|
||||
* @brief Enable and initialize support for PAwR sync/receiver.
|
||||
* @param[in] pawr_sync_config PAwR synchronizer configuration.
|
||||
* @return SL_STATUS_OK, or an appropriate error code. */
|
||||
sl_status_t sl_btctrl_pawr_synchronizer_configure(struct sl_btctrl_pawr_synchronizer_config *pawr_sync_config);
|
||||
|
||||
/**
|
||||
* @brief Allocate memory for synchronized scanners
|
||||
*
|
||||
* @param num_scan Number of Periodic Scanners Allowed
|
||||
* @return SL_STATUS_OK if allocation was succesfull, failure reason otherwise
|
||||
*/
|
||||
sl_status_t sl_btctrl_alloc_periodic_scan(uint8_t num_scan);
|
||||
|
||||
/**
|
||||
* @brief Allocate memory for periodic advertisers
|
||||
*
|
||||
* @param num_adv Number of advertisers to allocate
|
||||
*/
|
||||
sl_status_t sl_btctrl_alloc_periodic_adv(uint8_t num_adv);
|
||||
|
||||
/**
|
||||
* Call to import the conn scheduler state variables in the binary
|
||||
*/
|
||||
void sli_btctrl_enable_conn_scheduler_state(void);
|
||||
|
||||
/**
|
||||
* @brief Set maximum number of advertisement reports allowed to be queued
|
||||
*
|
||||
* @param num_adv Maximum number of advertisement reports allowed to be queued
|
||||
*/
|
||||
void sl_btctrl_configure_max_queued_adv_reports(uint8_t num_reports);
|
||||
|
||||
/**
|
||||
* Call to enable the even connection scheduling algorithm.
|
||||
* This function should be called before link layer initialization.
|
||||
*/
|
||||
void sl_btctrl_enable_even_connsch();
|
||||
|
||||
/**
|
||||
* Call to enable the PAwR aware connection scheduling algorithm.
|
||||
* This function should be called before link layer initialization.
|
||||
*/
|
||||
void sl_btctrl_enable_pawr_connsch();
|
||||
|
||||
/**
|
||||
* Call to enable the legacy connection scheduling algorithm.
|
||||
* This function should be called before link layer initialization.
|
||||
*/
|
||||
void sl_btctrl_enable_legacy_connsch();
|
||||
|
||||
/**
|
||||
* Call to enable connection statistics collection.
|
||||
*/
|
||||
void sl_btctrl_init_conn_statistics(void);
|
||||
|
||||
/**
|
||||
* Call to initialize multiprotocol
|
||||
* in bluetooth controller
|
||||
*/
|
||||
void sl_btctrl_init_multiprotocol();
|
||||
|
||||
/**
|
||||
* Link with symbol to enable radio watchdog
|
||||
*/
|
||||
void sl_btctrl_enable_radio_watchdog();
|
||||
|
||||
/**
|
||||
* Initialize CTE receiver
|
||||
*/
|
||||
sl_status_t sl_btctrl_init_cte_receiver();
|
||||
|
||||
/**
|
||||
* Initialize CTE transmitter
|
||||
*/
|
||||
sl_status_t sl_btctrl_init_cte_transmitter();
|
||||
|
||||
/**
|
||||
* Initialize both CTE receiver and transmitter
|
||||
*
|
||||
* Note: This is for backward compatibility. It is recommend to
|
||||
* use sl_btctrl_init_cte_receiver and sl_btctrl_init_cte_transmitter
|
||||
* functions instead.
|
||||
*/
|
||||
sl_status_t sl_btctrl_init_cte();
|
||||
|
||||
/**
|
||||
* Initialize Channel Sounding
|
||||
*/
|
||||
struct sl_btctrl_cs_config {
|
||||
/** number of channel sounding configurations per connection */
|
||||
uint8_t configs_per_connection;
|
||||
/** number of simultaneous channel sounding procedures */
|
||||
uint8_t procedures;
|
||||
};
|
||||
|
||||
sl_status_t sl_btctrl_init_cs(const struct sl_btctrl_cs_config *config);
|
||||
|
||||
/**
|
||||
* Check if event bitmap indicates pending events
|
||||
* @return bool pending events
|
||||
*/
|
||||
bool sli_pending_btctrl_events(void);
|
||||
|
||||
/**
|
||||
* Disable the support for Coded and Simulscan PHYs.
|
||||
*/
|
||||
void sl_btctrl_disable_coded_phy(void);
|
||||
|
||||
/**
|
||||
* Disable the support for 2M PHY.
|
||||
*/
|
||||
void sl_btctrl_disable_2m_phy(void);
|
||||
|
||||
/**
|
||||
* Initialize adv component
|
||||
*/
|
||||
void sl_btctrl_init_adv(void);
|
||||
|
||||
void sl_btctrl_init_conn(void);
|
||||
|
||||
void sl_btctrl_init_subrate(void);
|
||||
|
||||
sl_status_t sl_btctrl_allocate_conn_subrate_memory(uint8_t connectionsCount);
|
||||
|
||||
void sl_btctrl_init_phy(void);
|
||||
|
||||
void sl_btctrl_init_adv_ext(void);
|
||||
|
||||
void sl_btctrl_init_privacy(void);
|
||||
|
||||
sl_status_t sl_btctrl_allocate_resolving_list_memory(uint8_t resolvingListSize);
|
||||
|
||||
/**
|
||||
* @brief Initialize extended scanner state
|
||||
*
|
||||
*/
|
||||
void sl_btctrl_init_scan_ext(void);
|
||||
|
||||
void sl_btctrl_init_scan(void);
|
||||
|
||||
/**
|
||||
* @brief return true if controller is initialized
|
||||
*
|
||||
*/
|
||||
bool sl_btctrl_is_initialized();
|
||||
|
||||
/**
|
||||
* @brief Sets PAST initiator feature bit,
|
||||
* and links in PAST sender and ll_adv_sync symbols to the project.
|
||||
*/
|
||||
void sl_btctrl_init_past_local_sync_transfer(void);
|
||||
|
||||
/**
|
||||
* @brief Sets PAST initiator feature bit,
|
||||
* and links in PAST sender, ll_scan_sync and ll_scan_sync_registry symbols to the project.
|
||||
*/
|
||||
void sl_btctrl_init_past_remote_sync_transfer(void);
|
||||
|
||||
/**
|
||||
* @brief Sets PAST receiver feature bit,
|
||||
* and links in PAST receiver, ll_scan_sync and ll_scan_sync_registry symbols to the project.
|
||||
*/
|
||||
void sl_btctrl_init_past_receiver(void);
|
||||
|
||||
/**
|
||||
* @brief Configure how often to send the Number Of Completed Packets HCI event.
|
||||
* @param[in] packets When the controller has transmitted this number of ACL data packets it will send
|
||||
* the Number Of Completed Packets HCI event to the host.
|
||||
* @param[in] events When this number of connection events have passed and the controller did not yet report
|
||||
* all the transmitted packets, then it will send the Number Of Completed Packets HCI event to the host.
|
||||
*/
|
||||
void sl_btctrl_configure_completed_packets_reporting(uint8_t packets, uint8_t events);
|
||||
|
||||
#endif
|
||||
363
Libs/protocol/bluetooth/inc/sl_bgapi.h
Normal file
363
Libs/protocol/bluetooth/inc/sl_bgapi.h
Normal file
@@ -0,0 +1,363 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Silicon Labs BGAPI types and macros
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019-2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_BGAPI_H
|
||||
#define SL_BGAPI_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "sl_status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Macros to declare deprecated functions */
|
||||
#if defined(__IAR_SYSTEMS_ICC__)
|
||||
#define SL_BGAPI_DEPRECATED _Pragma("deprecated")
|
||||
#elif defined(__GNUC__)
|
||||
#define SL_BGAPI_DEPRECATED __attribute__((deprecated))
|
||||
#else
|
||||
#define SL_BGAPI_DEPRECATED
|
||||
#endif
|
||||
|
||||
/* Compatibility */
|
||||
#ifndef PACKSTRUCT
|
||||
/*Default packed configuration*/
|
||||
#ifdef __GNUC__
|
||||
#ifdef _WIN32
|
||||
#define PACKSTRUCT(decl) decl __attribute__((__packed__, gcc_struct))
|
||||
#else
|
||||
#define PACKSTRUCT(decl) decl __attribute__((__packed__))
|
||||
#endif
|
||||
#define ALIGNED __attribute__((aligned(0x4)))
|
||||
#elif __IAR_SYSTEMS_ICC__
|
||||
|
||||
#define PACKSTRUCT(decl) __packed decl
|
||||
|
||||
#define ALIGNED
|
||||
#elif _MSC_VER /*msvc*/
|
||||
|
||||
#define PACKSTRUCT(decl) __pragma(pack(push, 1) ) decl __pragma(pack(pop) )
|
||||
#define ALIGNED
|
||||
#else
|
||||
#define PACKSTRUCT(a) a PACKED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* The maximum BGAPI command payload size.
|
||||
*/
|
||||
#ifndef SL_BGAPI_MAX_PAYLOAD_SIZE
|
||||
#define SL_BGAPI_MAX_PAYLOAD_SIZE 256
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup sl_bgapi_types BGAPI Types
|
||||
* @brief Common types in BGAPI protocol
|
||||
* @{
|
||||
*/
|
||||
|
||||
#ifndef SL_BT_TYPE_UINT8ARRARY
|
||||
#define SL_BT_TYPE_UINT8ARRARY
|
||||
/** @brief Variable-length uint8_t array. Maximum length: 255 */
|
||||
typedef struct {
|
||||
uint8_t len; /**< Number of bytes stored in @p data */
|
||||
uint8_t data[]; /**< Data bytes*/
|
||||
} uint8array;
|
||||
#endif
|
||||
|
||||
#ifndef SL_BT_TYPE_BYTE_ARRARY
|
||||
#define SL_BT_TYPE_BYTE_ARRARY
|
||||
/** @brief Variable-length int8_t array. Maximum length: 65535 */
|
||||
typedef struct {
|
||||
uint16_t len; /**< Number of bytes stored in @p data */
|
||||
int8_t data[]; /**< Data bytes*/
|
||||
} byte_array;
|
||||
#endif
|
||||
|
||||
#ifndef SL_BT_TYPE_BDADDR
|
||||
#define SL_BT_TYPE_BDADDR
|
||||
/** @brief Bluetooth address */
|
||||
typedef struct {
|
||||
uint8_t addr[6]; /**< @brief Bluetooth address in reverse byte order */
|
||||
} bd_addr;
|
||||
#endif
|
||||
|
||||
#ifndef SL_BT_TYPE_UUID128
|
||||
#define SL_BT_TYPE_UUID128
|
||||
/** @brief 128-bit UUID */
|
||||
typedef struct {
|
||||
uint8_t data[16]; /**< 128-bit UUID */
|
||||
} uuid_128;
|
||||
#endif
|
||||
|
||||
#ifndef SL_BT_TYPE_AES_KEY128
|
||||
#define SL_BT_TYPE_AES_KEY128
|
||||
/** @brief 128-bit AES key */
|
||||
typedef struct {
|
||||
uint8_t data[16]; /**< 128-bit AES key */
|
||||
} aes_key_128;
|
||||
#endif
|
||||
|
||||
#ifndef SL_BT_TYPE_UUID16
|
||||
#define SL_BT_TYPE_UUID16
|
||||
/** @brief 16-bit UUID */
|
||||
typedef struct {
|
||||
uint8_t data[2]; /**< 16-bit UUID */
|
||||
} sl_bt_uuid_16_t;
|
||||
#endif
|
||||
|
||||
#ifndef SL_BT_TYPE_UUID64
|
||||
#define SL_BT_TYPE_UUID64
|
||||
/** @brief 64-bit UUID */
|
||||
typedef struct {
|
||||
uint8_t data[8]; /**< 64-bit UUID */
|
||||
} sl_bt_uuid_64_t;
|
||||
#endif
|
||||
|
||||
/** @} */ // end addtogroup sl_bgapi_types
|
||||
/******************************************************************************/
|
||||
|
||||
/** @brief Internal function prototype for BGAPI command handlers */
|
||||
typedef void (*sl_bgapi_handler)(const void*);
|
||||
|
||||
typedef enum sl_bgapi_msg_types {
|
||||
sl_bgapi_msg_type_cmd = 0x00,
|
||||
sl_bgapi_msg_type_rsp = 0x00,
|
||||
sl_bgapi_msg_type_evt = 0x80
|
||||
} sl_bgapi_msg_types_t;
|
||||
|
||||
enum sl_bgapi_dev_types {
|
||||
sl_bgapi_dev_type_app = 0x00,
|
||||
sl_bgapi_dev_type_bt = 0x20,
|
||||
sl_bgapi_dev_type_btmesh = 0x28,
|
||||
sl_bgapi_dev_type_bgapi_debug = 0x30,
|
||||
};
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup sl_bgapi_types BGAPI Types
|
||||
* @brief Common types in BGAPI protocol
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief The length of a BGAPI message header which is 4 bytes
|
||||
*/
|
||||
#define SL_BGAPI_MSG_HEADER_LEN (4)
|
||||
|
||||
/**
|
||||
* @brief The length of the BGAPI message payload of a generic error response
|
||||
*
|
||||
* See function @ref sl_bgapi_set_error_response for how to generate a generic
|
||||
* error response.
|
||||
*/
|
||||
#define SL_BGAPI_MSG_ERROR_PAYLOAD_LEN (2)
|
||||
|
||||
/**
|
||||
* @brief Get the device type of a BGAPI message
|
||||
*
|
||||
* @param HDR The header of the message as a uint32_t integer
|
||||
*/
|
||||
#define SL_BGAPI_MSG_DEVICE_TYPE(HDR) ((HDR) & 0x38)
|
||||
|
||||
/**
|
||||
* @brief Get the identifier of a BGAPI message including device type, class ID,
|
||||
* message type and message ID.
|
||||
*
|
||||
* @param HDR The header of the message as a uint32_t integer
|
||||
*/
|
||||
#define SL_BGAPI_MSG_ID(HDR) ((HDR) & 0xffff00f8)
|
||||
|
||||
/**
|
||||
* @brief Get the data payload length in a BGAPI message.
|
||||
*
|
||||
* @param HDR The header of the message as a uint32_t integer
|
||||
*/
|
||||
#define SL_BGAPI_MSG_LEN(HDR) ((((HDR) & 0x7) << 8) | (((HDR) & 0xff00) >> 8))
|
||||
|
||||
/**
|
||||
* @brief The bit indicating whether data of a BGAPI message is encrypted
|
||||
*/
|
||||
#define SL_BGAPI_BIT_ENCRYPTED (1 << 6) // Bit
|
||||
|
||||
/**
|
||||
* @brief Check whether data of a BGAPI message is encrypted.
|
||||
*
|
||||
* @param HDR The BGAPI header of the message as a uint32_t integer
|
||||
*/
|
||||
#define SL_BGAPI_MSG_ENCRYPTED(HDR) ((HDR)&SL_BGAPI_BIT_ENCRYPTED)
|
||||
|
||||
/**
|
||||
* @brief Construct a BGAPI message header from an event ID and payload length.
|
||||
*
|
||||
* It is the caller's responsibility to verify that the input values are within
|
||||
* valid range.
|
||||
*
|
||||
* @param[in] evt_id The full event ID constant, for example
|
||||
* `sl_bt_evt_system_boot_id`
|
||||
* @param[in] payload_len Length of the full BGAPI message payload
|
||||
*
|
||||
* @return The header as a `uint32_t` value
|
||||
*/
|
||||
#define SL_BGAPI_MSG_HEADER_FROM_ID_AND_LEN(evt_id, payload_len) \
|
||||
((uint32_t) (((uint32_t) (evt_id)) \
|
||||
| (((uint32_t) (payload_len) & 0x00FF) << 8) \
|
||||
| (((uint32_t) (payload_len) & 0x0700) >> 8))) \
|
||||
|
||||
/** @} */ // end addtogroup sl_bgapi_types
|
||||
/******************************************************************************/
|
||||
|
||||
/**
|
||||
* @addtogroup sl_bgapi_functions BGAPI Functions
|
||||
* @{
|
||||
*
|
||||
* @brief Functions provided by the BGAPI protocol
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Lock the BGAPI for exclusive access.
|
||||
*
|
||||
* NOTE: This function is provided for NCP/CPC components that need to handle
|
||||
* BGAPI commands and responses in their binary format in an application that
|
||||
* uses an RTOS. Normal application code that issues BGAPI commands by calling
|
||||
* API functions defined by protocol stacks must never call this function
|
||||
* directly.
|
||||
*
|
||||
* See the documentation of @ref sl_bgapi_handle_command for the full sequence
|
||||
* that must be followed when processing commands in their binary format.
|
||||
*
|
||||
* @return SL_STATUS_OK if the lock has been obtained, otherwise an error code
|
||||
*/
|
||||
sl_status_t sl_bgapi_lock(void);
|
||||
|
||||
/**
|
||||
* @brief Release the lock obtained by @ref sl_bgapi_lock
|
||||
*
|
||||
* NOTE: This function is provided for NCP/CPC components that need to handle
|
||||
* BGAPI commands and responses in their binary format in an application that
|
||||
* uses an RTOS. Normal application code that issues BGAPI commands by calling
|
||||
* API functions defined by protocol stacks must never call this function
|
||||
* directly.
|
||||
*
|
||||
* See the documentation of @ref sl_bgapi_handle_command for the full sequence
|
||||
* that must be followed when processing commands in their binary format.
|
||||
*/
|
||||
void sl_bgapi_unlock(void);
|
||||
|
||||
/**
|
||||
* @brief Handle a BGAPI command in binary format.
|
||||
*
|
||||
* NOTE: This function is provided for NCP/CPC components that need to handle
|
||||
* BGAPI commands and responses in their binary format. Normal application code
|
||||
* that issues BGAPI commands by calling API functions defined by protocol
|
||||
* stacks must never call this function directly.
|
||||
*
|
||||
* If the application uses an RTOS, the caller must protect the BGAPI handling
|
||||
* by obtaining the BGAPI lock with @ref sl_bgapi_lock, handle the command with
|
||||
* @ref sl_bgapi_handle_command, read the response from the buffer returned by
|
||||
* @ref sl_bgapi_get_command_response, and then release the lock with @ref
|
||||
* sl_bgapi_unlock. Here's an example of the full sequence that's required:
|
||||
*
|
||||
* @code
|
||||
* // Lock BGAPI for exclusive access
|
||||
* sl_status_t status = sl_bgapi_lock();
|
||||
* if (status != SL_STATUS_OK) {
|
||||
* // Locking will only fail if there are fatal unrecoverable errors with the
|
||||
* // RTOS primitives, so caller may choose to just assert in case of errors.
|
||||
* }
|
||||
*
|
||||
* // Process the command
|
||||
* sl_bgapi_handle_command(hdr, data);
|
||||
*
|
||||
* // Read the response
|
||||
* void *rsp = sl_bgapi_get_command_response();
|
||||
* uint32_t rsp_header = *((uint32_t *)rsp);
|
||||
* size_t rsp_len = SL_BGAPI_MSG_LEN(rsp_header) + SL_BGAPI_MSG_HEADER_LEN;
|
||||
* // Send the `rsp_len` bytes of response starting from `rsp`
|
||||
*
|
||||
* // Finally unlock the BGAPI to allow other commands to proceed
|
||||
* sl_bgapi_unlock();
|
||||
* @endcode
|
||||
*
|
||||
* Empty stub implementations are provided for @ref sl_bgapi_lock and @ref
|
||||
* sl_bgapi_unlock, so the same sequence can be used for all NCP/CPC
|
||||
* implementations even if an RTOS is not present.
|
||||
*
|
||||
* @param[in] hdr The BGAPI command header
|
||||
* @param[in] data The payload data associated with the command
|
||||
*/
|
||||
void sl_bgapi_handle_command(uint32_t hdr, const void* data);
|
||||
|
||||
/**
|
||||
* @brief Get the response of a handled BGAPI command.
|
||||
*
|
||||
* NOTE: This function is provided for NCP/CPC components that need to handle
|
||||
* BGAPI commands and responses in their binary format. Normal application code
|
||||
* that issues BGAPI commands by calling API functions defined by protocol
|
||||
* stacks must never call this function directly.
|
||||
*
|
||||
* See the documentation of @ref sl_bgapi_handle_command for the full sequence
|
||||
* that must be followed when processing commands in their binary format.
|
||||
*
|
||||
* @return Pointer to the BGAPI response structure that was filled when the
|
||||
* command was executed in @ref sl_bgapi_handle_command.
|
||||
*/
|
||||
void* sl_bgapi_get_command_response(void);
|
||||
|
||||
/**
|
||||
* @brief Set a generic error response to the specified buffer.
|
||||
*
|
||||
* NOTE: This function is provided for NCP/CPC components that need to handle
|
||||
* BGAPI commands and responses in their binary format. Normal application code
|
||||
* that issues BGAPI commands by calling API functions defined by protocol
|
||||
* stacks must never call this function directly.
|
||||
*
|
||||
* This function is available for NCP components that have detected fatal errors
|
||||
* in command processing (for example have failed to receive a complete command
|
||||
* message from the NCP host) and need to generate an error response without
|
||||
* going through the normal BGAPI command processing.
|
||||
*
|
||||
* @param[in] command_hdr The header of the command that we are responding to.
|
||||
* It is possible in certain types of failures that the NCP implementation
|
||||
* does not even have the full command header. In these cases it is
|
||||
* recommended that the NCP implementation sets the unavailable bytes of the
|
||||
* header to value zero to avoid transmitting uninitialized bytes. BGAPI
|
||||
* commands are processed one command at a time and the recipient will be able
|
||||
* to handle the error response even if it's missing the device ID, the class
|
||||
* ID, or the command ID.
|
||||
*
|
||||
* @param[in] result The value to set to the @p result field of the error
|
||||
* response.
|
||||
*
|
||||
* @param[out] response The response buffer to fill
|
||||
*
|
||||
* @param[in] response_buf_size The size of the response buffer. The caller must
|
||||
* provide a buffer that has at least @ref SL_BGAPI_MSG_HEADER_LEN + @ref
|
||||
* SL_BGAPI_MSG_ERROR_PAYLOAD_LEN bytes available.
|
||||
*/
|
||||
void sl_bgapi_set_error_response(uint32_t command_hdr,
|
||||
uint16_t result,
|
||||
void *response,
|
||||
size_t response_buf_size);
|
||||
|
||||
/** @} */ // end addtogroup sl_bgapi_functions
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
15979
Libs/protocol/bluetooth/inc/sl_bt_api.h
Normal file
15979
Libs/protocol/bluetooth/inc/sl_bt_api.h
Normal file
File diff suppressed because it is too large
Load Diff
77
Libs/protocol/bluetooth/inc/sl_bt_api_compatibility.h
Normal file
77
Libs/protocol/bluetooth/inc/sl_bt_api_compatibility.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/***************************************************************************//**
|
||||
* @brief BT API source code compatibility for deprecated items
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_BT_API_COMPATIBILITY_H
|
||||
#define SL_BT_API_COMPATIBILITY_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by sl_bt_gap_phy_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
sl_bt_gap_1m_phy = 0x1, /**< (0x1) 1M PHY */
|
||||
sl_bt_gap_2m_phy = 0x2, /**< (0x2) 2M PHY */
|
||||
sl_bt_gap_coded_phy = 0x4, /**< (0x4) Coded PHY, 125k (S=8) or 500k (S=2) */
|
||||
sl_bt_gap_any_phys = 0xff /**< (0xff) Any PHYs the device supports */
|
||||
} sl_bt_gap_phy_type_t;
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by sl_bt_gap_phy_coding_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
sl_bt_gap_1m_phy_uncoded = 0x1, /**< (0x1) 1M PHY */
|
||||
sl_bt_gap_2m_phy_uncoded = 0x2, /**< (0x2) 2M PHY */
|
||||
sl_bt_gap_coded_phy_125k = 0x4, /**< (0x4) 125k Coded PHY (S=8) */
|
||||
sl_bt_gap_coded_phy_500k = 0x8 /**< (0x8) 500k Coded PHY (S=2) */
|
||||
} sl_bt_gap_phy_and_coding_type_t;
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by sl_bt_legacy_advertiser_connection_mode_t and
|
||||
* sl_bt_extended_advertiser_connection_mode_t.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
sl_bt_advertiser_non_connectable = 0x0, /**< (0x0) Non-connectable
|
||||
non-scannable */
|
||||
sl_bt_advertiser_connectable_scannable = 0x2, /**< (0x2) Undirected
|
||||
connectable scannable.
|
||||
This mode can only be
|
||||
used in legacy
|
||||
advertising PDUs. */
|
||||
sl_bt_advertiser_scannable_non_connectable = 0x3, /**< (0x3) Undirected
|
||||
scannable
|
||||
(Non-connectable but
|
||||
responds to scan
|
||||
requests) */
|
||||
sl_bt_advertiser_connectable_non_scannable = 0x4 /**< (0x4) Undirected
|
||||
connectable
|
||||
non-scannable. This
|
||||
mode can only be used
|
||||
in extended advertising
|
||||
PDUs. */
|
||||
} sl_bt_advertiser_connection_mode_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
82
Libs/protocol/bluetooth/inc/sl_bt_ll_config.h
Normal file
82
Libs/protocol/bluetooth/inc/sl_bt_ll_config.h
Normal file
@@ -0,0 +1,82 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Bluetooth Link Layer configuration
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_BT_BLUETOOTH_LL_PRIORITIES_DEFINED
|
||||
#define SL_BT_BLUETOOTH_LL_PRIORITIES_DEFINED
|
||||
|
||||
typedef struct {
|
||||
uint8_t scan_min;
|
||||
uint8_t scan_max;
|
||||
uint8_t adv_min;
|
||||
uint8_t adv_max;
|
||||
uint8_t conn_min;
|
||||
uint8_t conn_max;
|
||||
uint8_t init_min;
|
||||
uint8_t init_max;
|
||||
uint8_t rail_mapping_offset;
|
||||
uint8_t rail_mapping_range;
|
||||
uint8_t _reserved;
|
||||
uint8_t adv_step;
|
||||
uint8_t scan_step;
|
||||
uint8_t pawr_tx_min;
|
||||
uint8_t pawr_tx_max;
|
||||
uint8_t pawr_rx_min;
|
||||
uint8_t pawr_rx_max;
|
||||
} sl_bt_bluetooth_ll_priorities;
|
||||
|
||||
//Default priority configuration
|
||||
#define SL_BT_BLUETOOTH_PRIORITIES_DEFAULT { 191, 143, 175, 127, 135, 0, 55, 15, 16, 16, 0, 4, 4, 15, 5, 20, 10 }
|
||||
|
||||
#define SL_BT_BLUETOOTH_PA_AUTOMODE 0xff
|
||||
#define SL_BT_BLUETOOTH_HIGHEST_PA 0xfe
|
||||
#define SL_BT_BLUETOOTH_RAIL_UTIL_PA 0xfd
|
||||
|
||||
#include "sl_common.h"
|
||||
SL_PACK_START(1)
|
||||
typedef struct {
|
||||
int8_t golden_rssi_min_1m; //<! Golden range lowest RSSI for 1M PHY.
|
||||
int8_t golden_rssi_max_1m; //<! Golden range highest RSSI for 1M PHY.
|
||||
|
||||
int8_t golden_rssi_min_2m; //<! Golden range lowest RSSI for 2M PHY.
|
||||
int8_t golden_rssi_max_2m; //<! Golden range highest RSSI for 2M PHY.
|
||||
|
||||
int8_t golden_rssi_min_coded_s8; //<! Golden range lowest RSSI for Coded PHY w/ S=8.
|
||||
int8_t golden_rssi_max_coded_s8; //<! Golden range highest RSSI for Coded PHY w/ S=8.
|
||||
|
||||
int8_t golden_rssi_min_coded_s2; //<! Golden range lowest RSSI for Coded PHY w/ S=2.
|
||||
int8_t golden_rssi_max_coded_s2; //<! Golden range highest RSSI for Coded PHY w/ S=2.
|
||||
|
||||
uint8_t activate_power_control;
|
||||
} SL_ATTRIBUTE_PACKED sl_bt_ll_power_control_config_t;
|
||||
SL_PACK_END()
|
||||
|
||||
#define SL_BT_USE_MAX_POWER_LEVEL_SUPPORTED_BY_RADIO 0x7fff
|
||||
#define SL_BT_USE_MIN_POWER_LEVEL_SUPPORTED_BY_RADIO 0x7fff
|
||||
|
||||
#endif
|
||||
150
Libs/protocol/bluetooth/inc/sl_bt_rtos_adaptation.h
Normal file
150
Libs/protocol/bluetooth/inc/sl_bt_rtos_adaptation.h
Normal file
@@ -0,0 +1,150 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Adaptation for running Bluetooth in RTOS
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_BT_RTOS_ADAPTATION_H
|
||||
#define SL_BT_RTOS_ADAPTATION_H
|
||||
|
||||
#include "sl_bt_api.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup bluetooth_rtos_adaptation Bluetooth RTOS adaptation
|
||||
* @{
|
||||
*
|
||||
* @brief Bluetooth RTOS adaptation
|
||||
*
|
||||
* The Bluetooth RTOS adaptation component implements the relevant interfaces
|
||||
* for running the Bluetooth stack in an RTOS. The component creates the
|
||||
* required RTOS synchronization primitives and tasks for the Bluetooth stack
|
||||
* and handles the inter-process communication (IPC) required when the
|
||||
* application calls a BGAPI command.
|
||||
*
|
||||
* If the Bluetooth Event System IPC component (`bluetooth_event_system_ipc`) is
|
||||
* included in the application, Bluetooth events are delivered using the IPC
|
||||
* mechanism provided by the `event_system` component. See @ref
|
||||
* bluetooth_event_system for the description of that mechanism. In this
|
||||
* configuration no event task is created by the RTOS adaptation.
|
||||
*
|
||||
* If the Bluetooth Event System IPC component (`bluetooth_event_system_ipc`) is
|
||||
* not included in the application, the RTOS adaptation component creates an
|
||||
* event task that delivers the events to the application as direct callbacks to
|
||||
* sl_bt_process_event() and sl_bt_on_event() functions.
|
||||
*
|
||||
* To guarantee thread safety and avoid the risk of deadlocks, the Bluetooth
|
||||
* RTOS adaptation implementation makes the following promises with regard to
|
||||
* the locking mechanism provided in the API:
|
||||
*
|
||||
* 1. The stack will never directly call sl_bt_process_event() or
|
||||
* sl_bt_on_event() from within the same callstack that is calling a command
|
||||
* function. The callbacks always come from a processing loop in an event
|
||||
* task created for this purpose.
|
||||
*
|
||||
* 2. The stack uses @ref sl_bgapi_lock() and @ref sl_bgapi_unlock() to
|
||||
* synchronize the handling of individual BGAPI commands, and the application
|
||||
* must never directly call these. Individual BGAPI commands are safe to be
|
||||
* called from multiple threads without additional locking. See @ref
|
||||
* sl_bt_bluetooth_pend() for description of when an application needs to use
|
||||
* additional locking to guarantee atomicity across multiple commands.
|
||||
*
|
||||
* 3. The stack will never internally obtain the @ref sl_bt_bluetooth_pend()
|
||||
* lock. It is safe for the application to obtain the lock also from within
|
||||
* the sl_bt_on_event() callback.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Initialize Bluetooth RTOS Adaptation
|
||||
*
|
||||
* This function is called automatically at the right time in the generated
|
||||
* initialization sequence. The application does not need to and must not call
|
||||
* this function directly.
|
||||
*
|
||||
* @return SL_STATUS_OK if succeeds, otherwise error
|
||||
*/
|
||||
sl_status_t sl_bt_rtos_init();
|
||||
|
||||
/**
|
||||
* @brief Obtain the Bluetooth host stack command lock
|
||||
*
|
||||
* Starting from Gecko SDK v3.1.2, all BGAPI command functions have automatic
|
||||
* locking to make them thread-safe. Using @ref sl_bt_bluetooth_pend() and @ref
|
||||
* sl_bt_bluetooth_post() is therefore no longer required for individual calls
|
||||
* to the BGAPI.
|
||||
*
|
||||
* The application only needs to use @ref sl_bt_bluetooth_pend() and @ref
|
||||
* sl_bt_bluetooth_post() to protect sections of code where multiple commands
|
||||
* need to be performed atomically in a thread-safe manner. This includes cases
|
||||
* such as using @ref sl_bt_system_data_buffer_write() to write data to the
|
||||
* system buffer followed by a call to @ref
|
||||
* sl_bt_extended_advertiser_set_long_data() to set that data to an advertiser
|
||||
* set. To synchronize access to the shared system buffer, the application would
|
||||
* need to lock by calling @ref sl_bt_bluetooth_pend() before @ref
|
||||
* sl_bt_system_data_buffer_write(), and release the lock by calling @ref
|
||||
* sl_bt_bluetooth_post() after @ref sl_bt_extended_advertiser_set_long_data().
|
||||
*
|
||||
* @return SL_STATUS_OK if mutex has been obtained
|
||||
*/
|
||||
sl_status_t sl_bt_bluetooth_pend();
|
||||
|
||||
/**
|
||||
* @brief Release the Bluetooth host stack command lock
|
||||
*
|
||||
* See @ref sl_bt_bluetooth_pend() for description of how an application needs
|
||||
* to use the locking to guarantee thread-safety.
|
||||
*
|
||||
* @return SL_STATUS_OK the mutex has been released
|
||||
*/
|
||||
sl_status_t sl_bt_bluetooth_post();
|
||||
|
||||
/** @cond DOXYGEN_INCLUDE_INTERNAL */
|
||||
|
||||
/**
|
||||
* @brief Hooks for API, called from tasks using Bluetooth API
|
||||
*/
|
||||
void sli_bt_cmd_handler_rtos_delegate(uint32_t header, sl_bgapi_handler handler, const void* payload);
|
||||
|
||||
/**
|
||||
* @brief Called by Bluetooth stack to wake up the link layer task
|
||||
*/
|
||||
void sli_bt_rtos_ll_callback(void);
|
||||
|
||||
/**
|
||||
* @brief Called by Bluetooth stack to wake up the host stack task
|
||||
*/
|
||||
void sli_bt_rtos_stack_callback(void);
|
||||
|
||||
/**
|
||||
* @brief Called by system initialization when kernel is starting.
|
||||
*/
|
||||
void sli_bt_rtos_adaptation_kernel_start();
|
||||
|
||||
/**
|
||||
* @brief Called by Bluetooth Event System IPC to mark an event as handled
|
||||
*/
|
||||
void sli_bt_rtos_set_event_handled();
|
||||
|
||||
/** @endcond */ // DOXYGEN_INCLUDE_INTERNAL
|
||||
|
||||
/** @} end bluetooth_rtos_adaptation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif //SL_BT_RTOS_ADAPTATION_H
|
||||
86
Libs/protocol/bluetooth/inc/sl_bt_stack_config.h
Normal file
86
Libs/protocol/bluetooth/inc/sl_bt_stack_config.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Bluetooth stack configuration
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_BT_STACK_CONFIG_H
|
||||
#define SL_BT_STACK_CONFIG_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "sl_bt_ll_config.h"
|
||||
|
||||
typedef struct {
|
||||
uint32_t max_buffer_memory; //!< Maximum number of bytes to use for data buffers
|
||||
uint32_t linklayer_config;
|
||||
sl_bt_bluetooth_ll_priorities * linklayer_priorities; //Priority configuration, if NULL uses default values
|
||||
}sl_bt_stack_config_t;
|
||||
|
||||
/** Flag indicating Bluetooth runs in RTOS */
|
||||
#define SL_BT_CONFIG_FLAG_RTOS 256
|
||||
|
||||
/** Flag indicating Bluetooth can allow EM2 with inaccurate LF clock */
|
||||
#define SL_BT_CONFIG_FLAG_INACCURATE_LFCLK_EM2 512
|
||||
|
||||
/**
|
||||
* <b>Deprecated</b> and replaced by @ref sli_bt_linklayer_wakeup_t implemented
|
||||
* by the bluetooth_host_adaptation component.
|
||||
*/
|
||||
typedef void (*sl_bt_priority_schedule_callback)(void);
|
||||
|
||||
/**
|
||||
* <b>Deprecated</b> and replaced by @ref sli_bt_host_wakeup_t implemented
|
||||
* by the bluetooth_host_adaptation component.
|
||||
*/
|
||||
typedef void (*sl_bt_stack_schedule_callback)(void);
|
||||
|
||||
#define SL_BT_RF_CONFIG_ANTENNA (1 << 0)
|
||||
typedef struct {
|
||||
int16_t tx_gain; // RF TX gain. Unit: 0.1 dBm. For example, -20 means -2.0 dBm (signal loss).
|
||||
int16_t rx_gain; // RF RX gain. Unit: 0.1 dBm.
|
||||
uint8_t flags; // bit 0 is enabling antenna config, other bits 1-7 are reserved.
|
||||
uint8_t antenna; // A configuration for antenna selection.
|
||||
// Value should be come from RAIL_AntennaSel_t enum.
|
||||
// See antenna path selection in RAIL rail_chip_specific.h.
|
||||
int16_t tx_min_power; // Minimum TX power level. Unit: 0.1 dBm.
|
||||
int16_t tx_max_power; // Maximum TX power level. Unit: 0.1 dBm.
|
||||
} sl_bt_rf_config_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t config_flags;
|
||||
sl_bt_stack_config_t bluetooth;
|
||||
|
||||
// GATT database (pointer of "sli_bt_gattdb_t*" type)
|
||||
const void* gattdb;
|
||||
|
||||
/**
|
||||
* <b>Deprecated</b> and replaced by @ref sli_bt_host_adaptation_linklayer_wakeup
|
||||
* implemented by the bluetooth_host_adaptation component.
|
||||
*
|
||||
* Callback for priority scheduling, used for RTOS support.
|
||||
*/
|
||||
sl_bt_priority_schedule_callback scheduler_callback;
|
||||
|
||||
/**
|
||||
* <b>Deprecated</b> and replaced by @ref sli_bt_host_adaptation_host_wakeup
|
||||
* implemented by the bluetooth_host_adaptation component.
|
||||
*
|
||||
* Callback for requesting Bluetooth stack scheduling, used for RTOS support.
|
||||
*/
|
||||
sl_bt_stack_schedule_callback stack_schedule_callback;
|
||||
|
||||
uint8_t max_timers; // Max number of soft timers, up to 16, the application will use through SL_BT_API. Default: 4
|
||||
sl_bt_rf_config_t rf;
|
||||
}sl_bt_configuration_t;
|
||||
|
||||
#endif
|
||||
38
Libs/protocol/bluetooth/inc/sl_bt_stack_init.h
Normal file
38
Libs/protocol/bluetooth/inc/sl_bt_stack_init.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Initialization APIs for Bluetooth stack
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_BT_STACK_INIT_H
|
||||
#define SL_BT_STACK_INIT_H
|
||||
|
||||
#include "sl_status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize the Bluetooth stack.
|
||||
*
|
||||
* @return SL_STATUS_OK if the initialization was successful; Other error code
|
||||
* indicates a failure.
|
||||
*/
|
||||
sl_status_t sl_bt_stack_init();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
22
Libs/protocol/bluetooth/inc/sl_bt_types.h
Normal file
22
Libs/protocol/bluetooth/inc/sl_bt_types.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Deprecated Bluetooth API data type header
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019-2020 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/*
|
||||
* "sl_bt_types.h" is deprecated and replaced by "sl_bt_api.h". We include
|
||||
* "sl_bt_api.h" here to maintain source code compatibility with files that only
|
||||
* include "sl_bt_types.h".
|
||||
*/
|
||||
#include "sl_bt_api.h"
|
||||
84
Libs/protocol/bluetooth/inc/sl_bt_version.h
Normal file
84
Libs/protocol/bluetooth/inc/sl_bt_version.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Bluetooth stack version definition
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2022 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_BT_VERSION_H
|
||||
#define SL_BT_VERSION_H
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup sl_bt_version Bluetooth SDK version
|
||||
* @brief Bluetooth SDK version information
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief The major number of Bluetooth SDK version
|
||||
*
|
||||
* An increment indicates incompatible Bluetooth API changes.
|
||||
*/
|
||||
#define SL_BT_VERSION_MAJOR 9
|
||||
|
||||
/**
|
||||
* @brief The minor number of Bluetooth SDK version
|
||||
*
|
||||
* An increment indicates new backwards compatible functionalities.
|
||||
*/
|
||||
#define SL_BT_VERSION_MINOR 0
|
||||
|
||||
/**
|
||||
* @brief The patch number of Bluetooth SDK version
|
||||
*
|
||||
* An increment indicates backwards compatible bug fixes.
|
||||
*/
|
||||
#define SL_BT_VERSION_PATCH 1
|
||||
|
||||
/**
|
||||
* @brief The build number which the Bluetooth SDK was created from
|
||||
*/
|
||||
#define SL_BT_VERSION_BUILD 341
|
||||
|
||||
/**
|
||||
* @brief The hash value of the build the Bluetooth SDK was created from
|
||||
*/
|
||||
#define SL_BT_VERSION_HASH {0x4d,0x9c,0xee,0x3e,0x47,0x47,0x76,0xad,0x6d,0x0c,0xc3,0x0c,0xe5,0x8c,0x68,0x88,0xd9,0xd6,0x50,0xd4}
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by SL_BT_VERSION_MAJOR
|
||||
*/
|
||||
#define BG_VERSION_MAJOR SL_BT_VERSION_MAJOR
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by SL_BT_VERSION_MINOR
|
||||
*/
|
||||
#define BG_VERSION_MINOR SL_BT_VERSION_MINOR
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by SL_BT_VERSION_PATCH
|
||||
*/
|
||||
#define BG_VERSION_PATCH SL_BT_VERSION_PATCH
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by SL_BT_VERSION_BUILD
|
||||
*/
|
||||
#define BG_VERSION_BUILD SL_BT_VERSION_BUILD
|
||||
|
||||
/**
|
||||
* Deprecated and replaced by SL_BT_VERSION_HASH
|
||||
*/
|
||||
#define BG_VERSION_HASH SL_BT_VERSION_HASH
|
||||
|
||||
/** @} */ // end addtogroup sl_bt_version
|
||||
|
||||
#endif
|
||||
107
Libs/protocol/bluetooth/inc/sli_bgapi.h
Normal file
107
Libs/protocol/bluetooth/inc/sli_bgapi.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Silicon Labs internal API provided by the BGAPI protocol
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BGAPI_H
|
||||
#define SLI_BGAPI_H
|
||||
|
||||
#include "sl_status.h"
|
||||
#include "sl_bgapi.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** @cond DOXYGEN_INCLUDE_INTERNAL */
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup sli_bgapi BGAPI Protocol internal API
|
||||
* @{
|
||||
*
|
||||
* @brief Silicon Labs internal API to the BGAPI Protocol
|
||||
*
|
||||
* The BGAPI Protocol provides some services that are needed internally by
|
||||
* Silicon Labs components. The APIs provided by this file must not be used by
|
||||
* application code.
|
||||
*/
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Silicon Labs internal types for the BGAPI protocol
|
||||
|
||||
/**
|
||||
* @brief Type definition for the command handler delegate function.
|
||||
*
|
||||
* The command handler delegate is used by the BGAPI protocol to handle a
|
||||
* command. The default delegate @ref sli_bgapi_cmd_handler_delegate executes
|
||||
* the BGAPI command handler function as a direct function call. The RTOS
|
||||
* adaptation uses @ref sli_bgapi_set_cmd_handler_delegate to set a special
|
||||
* delegate that handles the required inter-process communication (IPC) when an
|
||||
* RTOS is used.
|
||||
*
|
||||
* @param[in] header The BGAPI command header of the command to process
|
||||
* @param[in] handler The handler function to process the BGAPI command
|
||||
* @param[in] payload The BGAPI command payload data of the command to process
|
||||
*/
|
||||
typedef void sli_bgapi_cmd_handler_delegate_t (uint32_t header,
|
||||
sl_bgapi_handler handler,
|
||||
const void* payload);
|
||||
|
||||
#define SLI_BGAPI_BUFFER_SIZE (SL_BGAPI_MSG_HEADER_LEN + SL_BGAPI_MAX_PAYLOAD_SIZE)
|
||||
|
||||
/**
|
||||
* @brief The default command handler delegate function.
|
||||
*/
|
||||
sli_bgapi_cmd_handler_delegate_t sli_bgapi_cmd_handler_delegate;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Silicon Labs internal functions to control the BGAPI protocol
|
||||
|
||||
/**
|
||||
* @brief Set the BGAPI command handler delegate.
|
||||
*
|
||||
* @param[in] cmd_handler_delegate Pointer to the command handler delegate function
|
||||
*/
|
||||
void sli_bgapi_set_cmd_handler_delegate(sli_bgapi_cmd_handler_delegate_t *cmd_handler_delegate);
|
||||
|
||||
/**
|
||||
* @brief Pop an event out of the BGAPI event queue of a specific device.
|
||||
*
|
||||
* @param[in] dev_type The BGAPI device to pop events from
|
||||
* @param[in] event_buffer_size The size of the supplied event buffer
|
||||
* @param[out] event_buffer The event buffer to receive the popped event
|
||||
*
|
||||
* @return SL_STATUS_OK if successful, otherwise an error code
|
||||
*/
|
||||
sl_status_t sli_bgapi_pop_event(uint8_t dev_type,
|
||||
size_t event_buffer_size,
|
||||
void *event_buffer);
|
||||
|
||||
/**
|
||||
* @brief Set the BGAPI command/response buffer.
|
||||
*
|
||||
* @param[in] buffer The buffer to use for BGAPI command/response data
|
||||
* @return The previous buffer
|
||||
*/
|
||||
void *sli_bgapi_set_buffer(void *buffer);
|
||||
|
||||
/** @} end sli_bgapi */
|
||||
|
||||
/** @endcond */ // DOXYGEN_INCLUDE_INTERNAL
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SLI_BGAPI_H
|
||||
33
Libs/protocol/bluetooth/inc/sli_bt_accept_list_config.h
Normal file
33
Libs/protocol/bluetooth/inc/sli_bt_accept_list_config.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief Configuration types for "accept_list"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_ACCEPT_LIST_CONFIG_H
|
||||
#define SLI_BT_ACCEPT_LIST_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "accept_list"
|
||||
*
|
||||
* See "sl_bt_accept_list_config.h" for detailed description of each
|
||||
* configuration parameter.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t accept_list_size; ///< Set to value of SL_BT_CONFIG_ACCEPT_LIST_SIZE
|
||||
} sli_bt_accept_list_config_t;
|
||||
|
||||
#endif // SLI_BT_ACCEPT_LIST_CONFIG_H
|
||||
30
Libs/protocol/bluetooth/inc/sli_bt_advertiser_config.h
Normal file
30
Libs/protocol/bluetooth/inc/sli_bt_advertiser_config.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_advertiser_config.h
|
||||
* @brief Configuration types for "advertiser"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_ADVERTISER_CONFIG_H
|
||||
#define SLI_BT_ADVERTISER_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "advertiser"
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t max_advertisers; ///< Set to value of SL_BT_CONFIG_MAX_ADVERTISERS
|
||||
} sli_bt_advertiser_config_t;
|
||||
|
||||
#endif // SLI_BT_ADVERTISER_CONFIG_H
|
||||
216
Libs/protocol/bluetooth/inc/sli_bt_config_defs.h
Normal file
216
Libs/protocol/bluetooth/inc/sli_bt_config_defs.h
Normal file
@@ -0,0 +1,216 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Internal types and defines for Bluetooth configuration
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_CONFIG_DEFS_H
|
||||
#define SLI_BT_CONFIG_DEFS_H
|
||||
|
||||
#include "sl_status.h"
|
||||
|
||||
/** @brief Forward declaration of the internal feature structure */
|
||||
struct sli_bt_feature;
|
||||
|
||||
/** @brief Forward declaration of the internal BGAPI class structure */
|
||||
struct sli_bgapi_class;
|
||||
|
||||
/**
|
||||
* @brief Forward declaration of internal feature config structure
|
||||
*
|
||||
* Note that this is only used as an opaque type that is never instantiated
|
||||
* directly. The actual configuration structure is defined and populated in
|
||||
* feature-specific files.
|
||||
*/
|
||||
struct sli_bt_feature_config;
|
||||
|
||||
/** @brief Structure to specify the use of a feature and its configuration */
|
||||
struct sli_bt_feature_use {
|
||||
const struct sli_bt_feature *feature; /**< Pointer to the feature definition */
|
||||
const struct sli_bt_feature_config *config; /**< Pointer to the feature-specific configuration */
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Macro that expands to the name of a BGAPI class structure
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] class_name Short class name string without quotes, for example
|
||||
* advertiser or connection
|
||||
*/
|
||||
#define SLI_BT_BGAPI_CLASS_NAME(category_name, class_name, mode) \
|
||||
sli_bgapi_class_ ## category_name ## _ ## class_name ## _ ## mode
|
||||
|
||||
/**
|
||||
* @brief Macro to forward declare a BGAPI class structure
|
||||
*/
|
||||
#define SLI_BT_DECLARE_BGAPI_CLASS(category_name, class_name) \
|
||||
extern const struct sli_bgapi_class SLI_BT_BGAPI_CLASS_NAME(category_name, class_name, full); \
|
||||
extern const struct sli_bgapi_class SLI_BT_BGAPI_CLASS_NAME(category_name, class_name, optimized)
|
||||
|
||||
#ifdef SL_BT_API_FULL
|
||||
/**
|
||||
* @brief Macro to declare the use of a BGAPI class
|
||||
*
|
||||
* This macro is used by stack-specific initialization code to declare the use
|
||||
* of a BGAPI class in the array of used BGAPI classes.
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] class_name Short class name string without quotes, for example
|
||||
* advertiser or connection
|
||||
*/
|
||||
#define SLI_BT_USE_BGAPI_CLASS(category_name, class_name) \
|
||||
& SLI_BT_BGAPI_CLASS_NAME(category_name, class_name, full)
|
||||
#else
|
||||
#define SLI_BT_USE_BGAPI_CLASS(category_name, class_name) \
|
||||
& SLI_BT_BGAPI_CLASS_NAME(category_name, class_name, optimized)
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Macro that expands to the name of a feature definition structure
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] feature_name Short feature name string without quotes, for example
|
||||
* advertiser or connection
|
||||
* @param[in] init_mode Feature initialization mode without quotes: init_always
|
||||
* or on_demand
|
||||
*/
|
||||
#define SLI_BT_FEATURE_DEFINITION_NAME(category_name, feature_name, init_mode) \
|
||||
sli_feature_ ## category_name ## _ ## feature_name ## _ ## init_mode
|
||||
|
||||
/**
|
||||
* @brief Macro that expands to the name of a feature configuration structure
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] feature_name Short feature name string without quotes, for example
|
||||
* advertiser or connection
|
||||
*/
|
||||
#define SLI_BT_FEATURE_CONFIG_NAME(category_name, feature_name) \
|
||||
sli_feature_ ## category_name ## _ ## feature_name ## _config
|
||||
|
||||
/**
|
||||
* @brief Macro to forward declare a feature definition structure
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] feature_name Short feature name string without quotes, for example
|
||||
* advertiser or connection
|
||||
*/
|
||||
#define SLI_BT_DECLARE_FEATURE(category_name, feature_name) \
|
||||
extern const struct sli_bt_feature SLI_BT_FEATURE_DEFINITION_NAME(category_name, feature_name, init_always); \
|
||||
extern const struct sli_bt_feature SLI_BT_FEATURE_DEFINITION_NAME(category_name, feature_name, on_demand)
|
||||
|
||||
/**
|
||||
* @brief Macro to forward declare an instance of a feature configuration structure
|
||||
*
|
||||
* This macro is used by stack-specific initialization code to declare relevant
|
||||
* configuration structures before populating the array of optional features.
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] feature_name Short feature name string without quotes, for example
|
||||
* advertiser or connection
|
||||
*/
|
||||
#define SLI_BT_DECLARE_FEATURE_CONFIG(category_name, feature_name) \
|
||||
extern const struct sli_bt_feature_config SLI_BT_FEATURE_CONFIG_NAME(category_name, feature_name)
|
||||
|
||||
/**
|
||||
* @brief Macro to define an instance of a feature configuration structure
|
||||
*
|
||||
* This macro is used by the internal feature-specific configuration files
|
||||
* `sli_bt_*_config.c` to define an instance of the feature configuration
|
||||
* structure. The intended use is to assign the value directly. For example:
|
||||
*
|
||||
* @code
|
||||
* SLI_BT_DEFINE_FEATURE_CONFIG(bt, advertiser, sli_bt_advertiser_config_t) = {
|
||||
* .max_advertisers = SL_BT_CONFIG_MAX_ADVERTISERS
|
||||
* };
|
||||
* @endcode
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] feature_name Short feature name string without quotes, for example
|
||||
* advertiser or connection
|
||||
* @param[in] type The C language type of the configuration, for example
|
||||
* sli_bt_advertiser_config_t
|
||||
*/
|
||||
#define SLI_BT_DEFINE_FEATURE_CONFIG(category_name, feature_name, type) \
|
||||
const type SLI_BT_FEATURE_CONFIG_NAME(category_name, feature_name)
|
||||
|
||||
/**
|
||||
* @brief Internal helper to implement @ref SLI_BT_USE_FEATURE
|
||||
*
|
||||
* This macro provides the extra layer of indirection that's needed to expand
|
||||
* `SLI_BT_INIT_MODE` before it's used as a parameter to @ref
|
||||
* SLI_BT_FEATURE_DEFINITION_NAME(). Files that define feature uses should
|
||||
* invoke @ref SLI_BT_USE_FEATURE() instead of this helper.
|
||||
*/
|
||||
#define SLI_BT_USE_FEATURE_MODE(category_name, feature_name, init_mode) \
|
||||
{ &SLI_BT_FEATURE_DEFINITION_NAME(category_name, feature_name, init_mode), NULL }
|
||||
|
||||
/**
|
||||
* @brief Macro to declare the use of an optional feature that has no configuration
|
||||
*
|
||||
* This macro is used by stack-specific initialization code to declare the use
|
||||
* of a feature in the array of optional features.
|
||||
*
|
||||
* Files that invoke this macro must define `SLI_BT_INIT_MODE` to either
|
||||
* init_always or on_demand to decide the initialization mode of all features.
|
||||
* When the init_always mode is used, the de-init functions are omitted to
|
||||
* eliminate code that's not needed in the build.
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] feature_name Short feature name string without quotes, for example
|
||||
* advertiser or connection
|
||||
*/
|
||||
#define SLI_BT_USE_FEATURE(category_name, feature_name) \
|
||||
SLI_BT_USE_FEATURE_MODE(category_name, feature_name, SLI_BT_INIT_MODE)
|
||||
|
||||
/**
|
||||
* @brief Internal helper to implement @ref SLI_BT_USE_FEATURE_WITH_CONFIG
|
||||
*
|
||||
* This macro provides the extra layer of indirection that's needed to expand
|
||||
* `SLI_BT_INIT_MODE` before it's used as a parameter to @ref
|
||||
* SLI_BT_FEATURE_DEFINITION_NAME(). Files that define feature uses should
|
||||
* invoke @ref SLI_BT_USE_FEATURE_WITH_CONFIG() instead of this helper.
|
||||
*/
|
||||
#define SLI_BT_USE_FEATURE_MODE_WITH_CONFIG(category_name, feature_name, init_mode, config_name) \
|
||||
{ &SLI_BT_FEATURE_DEFINITION_NAME(category_name, feature_name, init_mode), &config_name }
|
||||
|
||||
/**
|
||||
* @brief Macro to declare the use of an optional feature with configuration
|
||||
*
|
||||
* This macro is used by stack-specific initialization code to declare the use
|
||||
* of a feature in the array of optional features.
|
||||
*
|
||||
* Files that invoke this macro must define `SLI_BT_INIT_MODE` to either
|
||||
* init_always or on_demand to decide the initialization mode of all features.
|
||||
* When the init_always mode is used, the de-init functions are omitted to
|
||||
* eliminate code that's not needed in the build.
|
||||
*
|
||||
* @param[in] category_name Short category name string without quotes, for
|
||||
* example bt, btmesh, or btctrl
|
||||
* @param[in] feature_name Short feature name string without quotes, for example
|
||||
* advertiser or connection
|
||||
* @param[in] config_name The name of the configuration structure. The caller
|
||||
* should use @ref SLI_BT_FEATURE_CONFIG_NAME() to get the name of the
|
||||
* configuration structure.
|
||||
*/
|
||||
#define SLI_BT_USE_FEATURE_WITH_CONFIG(category_name, feature_name, config_name) \
|
||||
SLI_BT_USE_FEATURE_MODE_WITH_CONFIG(category_name, feature_name, SLI_BT_INIT_MODE, config_name)
|
||||
|
||||
#endif // SLI_BT_CONFIG_DEFS_H
|
||||
31
Libs/protocol/bluetooth/inc/sli_bt_connection_config.h
Normal file
31
Libs/protocol/bluetooth/inc/sli_bt_connection_config.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_connection_config.h
|
||||
* @brief Configuration types for "connection"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_CONNECTION_CONFIG_H
|
||||
#define SLI_BT_CONNECTION_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "connection"
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t max_connections; ///< Set to value of SL_BT_CONFIG_MAX_CONNECTIONS_SUM
|
||||
uint16_t data_len; ///< Set to value of SL_BT_CONFIG_CONNECTION_DATA_LENGTH
|
||||
} sli_bt_connection_config_t;
|
||||
|
||||
#endif // SLI_BT_CONNECTION_CONFIG_H
|
||||
30
Libs/protocol/bluetooth/inc/sli_bt_dynamic_gattdb_config.h
Normal file
30
Libs/protocol/bluetooth/inc/sli_bt_dynamic_gattdb_config.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_dynamic_gattdb_config.h
|
||||
* @brief Configuration types for "dynamic_gattdb"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_DYNAMIC_GATTDB_CONFIG_H
|
||||
#define SLI_BT_DYNAMIC_GATTDB_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "dynamic_gattdb"
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t max_dynamic_gattdbs; ///< Set to value of SL_BT_CONFIG_MAX_DYNAMIC_GATTDBS_SUM
|
||||
} sli_bt_dynamic_gattdb_config_t;
|
||||
|
||||
#endif // SLI_BT_DYNAMIC_GATTDB_CONFIG_H
|
||||
108
Libs/protocol/bluetooth/inc/sli_bt_gattdb_def.h
Normal file
108
Libs/protocol/bluetooth/inc/sli_bt_gattdb_def.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Bluetooth GATT database structure definition
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_GATT_DEF_H
|
||||
#define SLI_BT_GATT_DEF_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
uint16_t len; //size of buffer
|
||||
uint8_t data[];
|
||||
} sli_bt_gattdb_value_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t properties; //Characteristic properties, same as in characteristic descriptor gatt_char_prop
|
||||
uint16_t max_len; //Maximum length of data in buffer
|
||||
uint16_t len; //current size of data in buffer
|
||||
uint8_t data[]; //size is max_len
|
||||
} sli_bt_gattdb_attribute_chrvalue_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t flags; //client characteristic flags allowed 1-notification, 2-indication)
|
||||
uint8_t clientconfig_index; // index to client config.
|
||||
} sli_bt_gattdb_attribute_config_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t properties; //Characteristic properties, same as in characteristic descriptor gatt_char_prop
|
||||
uint16_t char_uuid; // characteristic UUID handle
|
||||
} sli_bt_gattdb_attribute_characteristic_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t start; //Included Service Attribute Handle
|
||||
uint16_t end; //End Group Handle
|
||||
} sli_bt_gattdb_attribute_service_include_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t handle;
|
||||
uint16_t uuid;
|
||||
uint16_t permissions; //gatt_attribute_permission
|
||||
uint16_t caps; // Capability bit flags
|
||||
uint8_t datatype; //Just use uint8_t Do not use enum type, may cause compatibility troubles
|
||||
uint8_t state;
|
||||
union {
|
||||
const sli_bt_gattdb_value_t *constdata; //generic constant data
|
||||
sli_bt_gattdb_attribute_chrvalue_t *dynamicdata; //Modifiable data
|
||||
sli_bt_gattdb_attribute_config_t configdata;
|
||||
sli_bt_gattdb_attribute_characteristic_t characteristic;
|
||||
sli_bt_gattdb_attribute_service_include_t service_include;
|
||||
};
|
||||
} sli_bt_gattdb_attribute_t;
|
||||
|
||||
struct sli_bt_gattdb_s {
|
||||
const sli_bt_gattdb_attribute_t *attributes;
|
||||
uint16_t attribute_table_size;
|
||||
uint16_t attribute_num;
|
||||
const uint16_t *uuid16;
|
||||
uint16_t uuid16_table_size;
|
||||
uint16_t uuid16_num;
|
||||
const uint8_t *uuid128;
|
||||
uint16_t uuid128_table_size;
|
||||
uint16_t uuid128_num;
|
||||
uint8_t num_ccfg;
|
||||
uint16_t caps_mask;
|
||||
uint16_t enabled_caps;
|
||||
};
|
||||
|
||||
typedef struct sli_bt_gattdb_s sli_bt_gattdb_t;
|
||||
|
||||
extern const sli_bt_gattdb_t *static_gattdb;
|
||||
|
||||
/**
|
||||
* @addtogroup dynamic_gatt_config
|
||||
*
|
||||
* Dynamic GATT database configuration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Flag indicating GATT caching should be enabled. When enabled, a Generic
|
||||
* Attribute Profile Service will be created in database if one doesn't exist.
|
||||
**/
|
||||
#define SLI_BT_GATTDB_CONFIG_FLAG_ENABLE_GATT_CACHING (0x01)
|
||||
|
||||
/**
|
||||
* Flag indicating the static database should be included if one exists.
|
||||
*/
|
||||
#define SLI_BT_GATTDB_CONFIG_FLAG_INCLUDE_STATIC_DB (0X02)
|
||||
|
||||
typedef struct {
|
||||
uint32_t flags;
|
||||
} sli_bt_gattdb_config_t;
|
||||
|
||||
/** @} (end addtogroup dynamic_gatt_config) */
|
||||
|
||||
#endif
|
||||
127
Libs/protocol/bluetooth/inc/sli_bt_host_adaptation.h
Normal file
127
Libs/protocol/bluetooth/inc/sli_bt_host_adaptation.h
Normal file
@@ -0,0 +1,127 @@
|
||||
/***************************************************************************//**
|
||||
* @brief System adaptation layer used internally by Bluetooth host stack
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_HOST_ADAPTATION_H
|
||||
#define SLI_BT_HOST_ADAPTATION_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include "sl_status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup sli_bt_host_adaptation
|
||||
* @{
|
||||
*
|
||||
* @brief System adaptation layer used internally by Bluetooth host stack
|
||||
*
|
||||
* The functions provided by this file are used by the Bluetooth host stack to
|
||||
* perform operations that cannot be performed using device-agnostic APIs from
|
||||
* within the Bluetooth libraries. These are typically operations that depend on
|
||||
* the target device or the Platform configuration. The application does not
|
||||
* need to and must not call these functions directly.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/**
|
||||
* @brief Function prototype for waking up the Bluetooth link layer task
|
||||
*/
|
||||
typedef void sli_bt_linklayer_wakeup_t (void);
|
||||
|
||||
/**
|
||||
* @brief Function prototype for waking up the Bluetooth host task
|
||||
*/
|
||||
typedef void sli_bt_host_wakeup_t (void);
|
||||
|
||||
/**
|
||||
* @brief Pointer to the function that wakes up the Bluetooth linklayer task
|
||||
*/
|
||||
extern sli_bt_linklayer_wakeup_t *const sli_bt_host_adaptation_linklayer_wakeup;
|
||||
|
||||
/**
|
||||
* @brief Pointer to the function that wakes up the Bluetooth host task
|
||||
*/
|
||||
extern sli_bt_host_wakeup_t *const sli_bt_host_adaptation_host_wakeup;
|
||||
|
||||
/**
|
||||
* @brief Initialize the device interrupts in a baremetal app
|
||||
*
|
||||
* This is called once during the boot time initialization.
|
||||
*/
|
||||
void sli_bt_host_adaptation_init_interrupts(void);
|
||||
|
||||
/**
|
||||
* @brief Get the bootloader version information
|
||||
*
|
||||
* @param[out] bootloader_version Set to the bootloader version number if a
|
||||
* bootloader is available
|
||||
*
|
||||
* @return SL_STATUS_OK if a bootloader is available and the version was
|
||||
* obtained. SL_STATUS_NOT_AVAILABLE if the application does not use a
|
||||
* bootloader.
|
||||
*/
|
||||
sl_status_t sli_bt_host_adaptation_get_bootloader_version(uint32_t *bootloader_version);
|
||||
|
||||
/**
|
||||
* @brief Reset the chip
|
||||
*
|
||||
* This function never returns.
|
||||
*/
|
||||
void sli_bt_host_adaptation_chip_reset(void);
|
||||
|
||||
/**
|
||||
* @brief Write a custom Bluetooth identity address into the Bluetooth region of NVM3
|
||||
*
|
||||
* @param[in] address_type Address type sl_bt_gap_public_address or sl_bt_gap_static_address
|
||||
* @param[in] address Pointer to the address to write into NVM3
|
||||
* @return SL_STATUS_OK if the operation succeeded
|
||||
*/
|
||||
sl_status_t sli_bt_host_adaptation_write_custom_address(uint8_t address_type,
|
||||
const uint8_t *address);
|
||||
|
||||
/**
|
||||
* @brief Load custom Bluetooth identity address from NVM3
|
||||
*
|
||||
* The operation succeeds if both the custom address and address type entries exist in NVM3.
|
||||
*
|
||||
* @param[out] address_type Pointer to return the address type value read from NVM3. Value 0
|
||||
* indicates the address is a public device address, and 1 indicates the address
|
||||
* is a static device address.
|
||||
* @param[out] address Pointer to return the address read from NVM3
|
||||
* @return SL_STATUS_OK if the operation succeeded
|
||||
*/
|
||||
sl_status_t sli_bt_host_adaptation_read_custom_address(uint8_t *address_type,
|
||||
uint8_t *address);
|
||||
|
||||
/**
|
||||
* @brief Set HFXO CTUNE using the value stored in the Bluetooth space of NVM3
|
||||
*
|
||||
* Setting the HFXO CTUNE with this method is deprecated. Currently the functionality is
|
||||
* provided for keeping backwards compatibility with legacy SDKs, and the support will be
|
||||
* discontinued in future SDK releases. The recommended method is to store CTUNE value in the
|
||||
* MFG_CTUNE token.
|
||||
*/
|
||||
void sli_bt_host_adaptation_read_and_set_ctune();
|
||||
|
||||
/** @} end sli_bt_host_adaptation */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SLI_BT_HOST_ADAPTATION_H
|
||||
33
Libs/protocol/bluetooth/inc/sli_bt_l2cap_config.h
Normal file
33
Libs/protocol/bluetooth/inc/sli_bt_l2cap_config.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_l2cap_config.h
|
||||
* @brief Configuration types for "l2cap"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_L2CAP_CONFIG_H
|
||||
#define SLI_BT_L2CAP_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "l2cap"
|
||||
*
|
||||
* See "sl_bluetooth_l2cap_config.h" for detailed description of each
|
||||
* configuration parameter.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t max_l2cap_coc_channels; ///< Set to value of SL_BT_CONFIG_USER_L2CAP_COC_CHANNELS
|
||||
} sli_bt_l2cap_config_t;
|
||||
|
||||
#endif // SLI_BT_L2CAP_CONFIG_H
|
||||
33
Libs/protocol/bluetooth/inc/sli_bt_pawr_advertiser_config.h
Normal file
33
Libs/protocol/bluetooth/inc/sli_bt_pawr_advertiser_config.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_pawr_advertiser_config.h
|
||||
* @brief Configuration types for "pawr_advertiser"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_PAWR_ADVERTISER_CONFIG_H
|
||||
#define SLI_BT_PAWR_ADVERTISER_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "pawr_advertiser"
|
||||
*
|
||||
* See "sl_bt_pawr_advertiser_config.h" for detailed description of each
|
||||
* configuration parameter.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t max_pawr_advertisers; ///< Set to value of SL_BT_CONFIG_MAX_PAWR_ADVERTISERS
|
||||
} sli_bt_pawr_advertiser_config_t;
|
||||
|
||||
#endif // SLI_BT_PAWR_ADVERTISER_CONFIG_H
|
||||
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_periodic_advertiser_config.h
|
||||
* @brief Configuration types for "periodic_advertiser"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_PERIODIC_ADVERTISER_CONFIG_H
|
||||
#define SLI_BT_PERIODIC_ADVERTISER_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "periodic_advertiser"
|
||||
*
|
||||
* See "sl_bt_periodic_advertiser_config.h" for detailed description of each
|
||||
* configuration parameter.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t max_periodic_advertisers; ///< Set to value of SL_BT_CONFIG_MAX_PERIODIC_ADVERTISERS
|
||||
} sli_bt_periodic_advertiser_config_t;
|
||||
|
||||
#endif // SLI_BT_PERIODIC_ADVERTISER_CONFIG_H
|
||||
33
Libs/protocol/bluetooth/inc/sli_bt_sync_config.h
Normal file
33
Libs/protocol/bluetooth/inc/sli_bt_sync_config.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_sync_config.h
|
||||
* @brief Configuration types for "sync"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SLI_BT_SYNC_CONFIG_H
|
||||
#define SLI_BT_SYNC_CONFIG_H
|
||||
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
/**
|
||||
* @brief Configuration structure used by "sync"
|
||||
*
|
||||
* See "sl_bt_sync_config.h" for detailed description of each configuration
|
||||
* parameter.
|
||||
*/
|
||||
typedef struct {
|
||||
uint8_t max_periodic_syncs; ///< Set to value of SL_BT_CONFIG_MAX_PERIODIC_ADVERTISING_SYNC
|
||||
} sli_bt_sync_config_t;
|
||||
|
||||
#endif // SLI_BT_SYNC_CONFIG_H
|
||||
909
Libs/protocol/bluetooth/src/sl_bt_rtos_adaptation.c
Normal file
909
Libs/protocol/bluetooth/src/sl_bt_rtos_adaptation.c
Normal file
@@ -0,0 +1,909 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Adaptation for running Bluetooth in RTOS
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2018 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <cmsis_os2.h>
|
||||
#include "sl_core.h"
|
||||
#include "sl_bluetooth.h"
|
||||
#include "sli_bgapi.h"
|
||||
#include "sl_bt_stack_config.h"
|
||||
#include "sl_bt_rtos_config.h"
|
||||
#include "sl_bt_rtos_adaptation.h"
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sl_memory_manager.h"
|
||||
|
||||
#ifdef CONFIGURATION_HEADER
|
||||
#include CONFIGURATION_HEADER
|
||||
#endif // CONFIGURATION_HEADER
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
#include "sli_bt_event_system.h"
|
||||
#endif
|
||||
|
||||
// Definitions for Bluetooth state flags that are needed already before the RTOS
|
||||
// kernel has been started, i.e. if the application calls
|
||||
// `sl_bt_system_start_bluetooth()` from `app_init()`. These flags are used with
|
||||
// the static state variable `bluetooth_state_flags`.
|
||||
#define SLI_BT_RTOS_STATE_FLAG_KERNEL_STARTED 0x01U // The RTOS kernel has been started
|
||||
#define SLI_BT_RTOS_STATE_FLAG_STARTING 0x02U // The Bluetooth stack is starting
|
||||
#define SLI_BT_RTOS_STATE_FLAG_STARTED 0x04U // The Bluetooth stack has successfully started
|
||||
#define SLI_BT_RTOS_STATE_FLAG_STOPPING 0x08U // The Bluetooth stack is stopping
|
||||
|
||||
// The event flags defined below are specific to a thread and are used with the
|
||||
// thread context's `event_flags` field. The values would not necessarily need
|
||||
// to be unique between threads. We still choose unique values to make it easier
|
||||
// to detect if a flag of one thread is accidentally used with another.
|
||||
|
||||
// Common event flags used with @ref wait_bluetooth_rtos_thread_event_flags
|
||||
#define SLI_BT_RTOS_EVENT_FLAG_ERROR 0x80000000U // An error has occurred while waiting for events
|
||||
|
||||
// Event flags for the Bluetooth thread
|
||||
#define SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_WAKEUP 0x00000001U // Bluetooth task needs an update
|
||||
#define SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_COMMAND_WAITING 0x00000002U // Bluetooth command is waiting to be processed
|
||||
#define SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED 0x00000004U // Bluetooth event posted to the event handler thread has been handled
|
||||
#define SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_STOPPED 0x00000008U // Bluetooth stack has been stopped
|
||||
|
||||
// Event flags for the Link Layer thread
|
||||
#define SLI_BT_RTOS_LINKLAYER_THREAD_FLAG_WAKEUP 0x00000100U // Linklayer task needs an update
|
||||
|
||||
// Event flags for the event handler thread
|
||||
#define SLI_BT_RTOS_EVENT_THREAD_FLAG_EVENT_WAITING 0x00010000U // Bluetooth event is waiting to be processed
|
||||
|
||||
static volatile uint8_t bluetooth_state_flags = 0;
|
||||
|
||||
static volatile sl_bt_msg_t bluetooth_evt_instance;
|
||||
|
||||
static volatile uint32_t command_header;
|
||||
static volatile void* command_data;
|
||||
static volatile sl_bgapi_handler command_handler_func = NULL;
|
||||
|
||||
/**
|
||||
* @brief Structure to represent a thread in the Bluetooth RTOS adaptation
|
||||
*/
|
||||
typedef struct {
|
||||
osThreadId_t thread_id; ///< The ID of the thread
|
||||
osSemaphoreId_t wakeup_semaphore_id; ///< The ID of the wakeup semaphore
|
||||
volatile uint32_t event_flags; ///< Event flags to be handled after wakeup
|
||||
} sli_bt_rtos_thread_t;
|
||||
|
||||
//Bluetooth stack thread
|
||||
static void bluetooth_thread(void *p_arg);
|
||||
static sli_bt_rtos_thread_t thread_bluetooth;
|
||||
static const osThreadAttr_t thread_bluetooth_attr = {
|
||||
.name = "Bluetooth stack",
|
||||
.stack_size = SL_BT_RTOS_HOST_STACK_TASK_STACK_SIZE,
|
||||
.priority = (osPriority_t) SL_BT_RTOS_HOST_STACK_TASK_PRIORITY
|
||||
};
|
||||
static const osSemaphoreAttr_t semaphore_bluetooth_attr = {
|
||||
.name = "Bluetooth stack wakeup"
|
||||
};
|
||||
|
||||
//Bluetooth linklayer thread
|
||||
static void linklayer_thread(void *p_arg);
|
||||
static sli_bt_rtos_thread_t thread_linklayer;
|
||||
static const osThreadAttr_t thread_linklayer_attr = {
|
||||
.name = "Bluetooth linklayer",
|
||||
.stack_size = SL_BT_RTOS_LINK_LAYER_TASK_STACK_SIZE,
|
||||
.priority = (osPriority_t) SL_BT_RTOS_LINK_LAYER_TASK_PRIORITY
|
||||
};
|
||||
static const osSemaphoreAttr_t semaphore_linklayer_attr = {
|
||||
.name = "Bluetooth linklayer wakeup"
|
||||
};
|
||||
|
||||
// The Bluetooth event handler thread is only used when Event System IPC is not
|
||||
// included
|
||||
#if !defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
static sli_bt_rtos_thread_t thread_event_handler;
|
||||
static void event_handler_thread(void *p_arg);
|
||||
static const osThreadAttr_t thread_event_handler_attr = {
|
||||
.name = "Bluetooth event handler",
|
||||
.stack_size = SL_BT_RTOS_EVENT_HANDLER_STACK_SIZE,
|
||||
.priority = (osPriority_t) SL_BT_RTOS_EVENT_HANDLER_TASK_PRIORITY
|
||||
};
|
||||
static const osSemaphoreAttr_t semaphore_event_handler_attr = {
|
||||
.name = "Bluetooth event handler wakeup"
|
||||
};
|
||||
#endif // !defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
|
||||
static volatile osMutexId_t bluetooth_mutex_id;
|
||||
static const osMutexAttr_t bluetooth_mutex_attr = {
|
||||
.name = "Bluetooth Mutex",
|
||||
.attr_bits = osMutexRecursive | osMutexPrioInherit,
|
||||
};
|
||||
|
||||
static volatile osMutexId_t bgapi_mutex_id;
|
||||
static const osMutexAttr_t bgapi_mutex_attr = {
|
||||
.name = "BGAPI Mutex",
|
||||
.attr_bits = osMutexRecursive | osMutexPrioInherit,
|
||||
};
|
||||
|
||||
static volatile osSemaphoreId_t bgapi_response_semaphore_id;
|
||||
static const osSemaphoreAttr_t bgapi_response_semaphore_attr = {
|
||||
.name = "BGAPI response"
|
||||
};
|
||||
|
||||
static uint32_t bgapi_command_recursion_count = 0;
|
||||
|
||||
/**
|
||||
* @brief Convert CMSIS-RTOS2 osStatus_t to @ref sl_status_t
|
||||
*/
|
||||
static sl_status_t os2sl_status(osStatus_t ret)
|
||||
{
|
||||
switch (ret) {
|
||||
case osOK:
|
||||
return SL_STATUS_OK;
|
||||
|
||||
case osErrorTimeout:
|
||||
return SL_STATUS_TIMEOUT;
|
||||
|
||||
case osErrorISR:
|
||||
return SL_STATUS_ISR;
|
||||
|
||||
case osErrorParameter:
|
||||
return SL_STATUS_INVALID_PARAMETER;
|
||||
|
||||
default:
|
||||
return SL_STATUS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Delete a Bluetooth RTOS adaptation thread
|
||||
*
|
||||
* @param[out] thread The thread structure that records the info for the thread
|
||||
* to delete
|
||||
*/
|
||||
static void delete_bluetooth_rtos_thread(sli_bt_rtos_thread_t *thread)
|
||||
{
|
||||
EFM_ASSERT(thread != NULL);
|
||||
|
||||
if (thread->thread_id != NULL) {
|
||||
(void) osThreadTerminate(thread->thread_id);
|
||||
thread->thread_id = NULL;
|
||||
}
|
||||
|
||||
if (thread->wakeup_semaphore_id != NULL) {
|
||||
(void) osSemaphoreDelete(thread->wakeup_semaphore_id);
|
||||
thread->wakeup_semaphore_id = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create a Bluetooth RTOS adaptation thread
|
||||
*
|
||||
* This function creates a wakeup semaphore and the corresponding thread to use
|
||||
* for Bluetooth RTOS adaptation. The thread function @p thread_func will
|
||||
* receive a pointer to @p thread as the thread argument.
|
||||
*
|
||||
* To support the special case where the event thread is disabled by
|
||||
* configuration, this function may be called with @p thread_func set to NULL.
|
||||
* In this case the thread is not created, but the wakeup semaphore and the
|
||||
* event flags can be used by any calling thread to wait for an event.
|
||||
*
|
||||
* Note that this function does not automatically assign `thread_id` in @p
|
||||
* thread. To avoid race conditions between the calling thread and the thread
|
||||
* that is created, some thread creation calls need special consideration in
|
||||
* assigning the handle. This function gives the callers the flexibility to
|
||||
* choose when to assign `thread_id` in @p thread.
|
||||
*
|
||||
* @param[out] thread The thread structure that records the info for this thread
|
||||
* @param[out] thread_id Set to the thread ID for the created thread
|
||||
* @param[in] semaphore_attr Attributes of the wakeup semaphore
|
||||
* @param[in] thread_func Thread function
|
||||
* @param[in] thread_attr Attributes of the thread to create
|
||||
*/
|
||||
static sl_status_t create_bluetooth_rtos_thread(sli_bt_rtos_thread_t *thread,
|
||||
osThreadId_t *thread_id,
|
||||
const osSemaphoreAttr_t *semaphore_attr,
|
||||
osThreadFunc_t thread_func,
|
||||
const osThreadAttr_t *thread_attr)
|
||||
{
|
||||
// Parameters must have been supplied and we can't yet have the RTOS objects
|
||||
EFM_ASSERT(thread != NULL);
|
||||
EFM_ASSERT(thread_id != NULL);
|
||||
EFM_ASSERT(thread->thread_id == NULL);
|
||||
EFM_ASSERT(thread->wakeup_semaphore_id == NULL);
|
||||
|
||||
// Thread will typically immmediately start waiting on the wakeup semaphore,
|
||||
// so init event flags and create the semaphore first
|
||||
thread->event_flags = 0;
|
||||
uint32_t max_count = 1;
|
||||
uint32_t initial_count = 0;
|
||||
thread->wakeup_semaphore_id = osSemaphoreNew(max_count, initial_count, semaphore_attr);
|
||||
if (thread->wakeup_semaphore_id == NULL) {
|
||||
return SL_STATUS_FAIL;
|
||||
}
|
||||
|
||||
// Create the thread itself, if a function was supplied
|
||||
if (thread_func != NULL) {
|
||||
*thread_id = osThreadNew(thread_func, thread, thread_attr);
|
||||
if (*thread_id == NULL) {
|
||||
(void) osSemaphoreDelete(thread->wakeup_semaphore_id);
|
||||
thread->wakeup_semaphore_id = NULL;
|
||||
return SL_STATUS_FAIL;
|
||||
}
|
||||
} else {
|
||||
*thread_id = NULL;
|
||||
}
|
||||
|
||||
return SL_STATUS_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set event flags to the specifed Bluetooth RTOS adaptation thread
|
||||
*
|
||||
* This function sets the specified event flags to a Bluetooth RTOS adaptation
|
||||
* thread. The flags are bitwise OR'ed, i.e. flag bits that are zero do not
|
||||
* affect flags that have already been set. Flag bits that are set to one are
|
||||
* set to the thread and the target thread is woken up.
|
||||
*
|
||||
* @param[in,out] thread The thread structure that records the info for this thread
|
||||
* @param[in] event_flags The event flags to set
|
||||
*/
|
||||
static void set_bluetooth_rtos_thread_event_flags(sli_bt_rtos_thread_t *thread,
|
||||
uint32_t event_flags)
|
||||
{
|
||||
CORE_DECLARE_IRQ_STATE;
|
||||
|
||||
// Set the flags in an atomic section
|
||||
CORE_ENTER_ATOMIC();
|
||||
thread->event_flags |= event_flags;
|
||||
CORE_EXIT_ATOMIC();
|
||||
|
||||
// To avoid any risk of a race condition, we err on the side of caution and
|
||||
// always wakeup the target thread. The threads don't react to the number of
|
||||
// wakeups, but to seeing flags set, so redundant wakeups are not a problem.
|
||||
// Also, since we're using a binary semaphore, the number of wakeups won't
|
||||
// accumulate. If we wake up the thread multiple times, the semaphore clamps
|
||||
// at one token, the thread wakes up once, and sees all the flags accumulated
|
||||
// so far.
|
||||
//
|
||||
// We deliberately don't check the return code when we release the semaphore.
|
||||
// The only possible errors documented by CMSIS-RTOS2 is reaching the maximum
|
||||
// count (this is OK for us, as we're deliberately using a binary semaphore
|
||||
// that clamps to one token), and having a NULL or invalid semaphore ID. That
|
||||
// can only happen if someone else corrupts our memory, as the semaphore
|
||||
// creation is checked for success before the threads start using it. That
|
||||
// error would be unrecoverable anyway.
|
||||
(void) osSemaphoreRelease(thread->wakeup_semaphore_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Pop the current event flags in the specifed Bluetooth RTOS adaptation thread
|
||||
*
|
||||
* This function returns a bitmask of event flags that were set and clears those
|
||||
* bits in the thread structure.
|
||||
*
|
||||
* @param[in,out] thread The thread structure that records the info for this thread
|
||||
* @param[in] event_flags The event flags to wait for
|
||||
*
|
||||
* @return The event flags that were set and have been cleared
|
||||
*/
|
||||
static uint32_t pop_bluetooth_rtos_thread_event_flags(sli_bt_rtos_thread_t *thread)
|
||||
{
|
||||
CORE_DECLARE_IRQ_STATE;
|
||||
|
||||
// Check and clear the flags atomically
|
||||
CORE_ENTER_ATOMIC();
|
||||
uint32_t event_flags = thread->event_flags;
|
||||
if (event_flags != 0) {
|
||||
thread->event_flags = 0;
|
||||
}
|
||||
CORE_EXIT_ATOMIC();
|
||||
|
||||
return event_flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wait for event flags in the specifed Bluetooth RTOS adaptation thread
|
||||
*
|
||||
* This function waits until at least one event flag has become set for the
|
||||
* thread. If flags are set already, the function returns immediately. The
|
||||
* function returns a bitmask of event flags that were set and clears those bits
|
||||
* in the thread structure.
|
||||
*
|
||||
* @param[in,out] thread The thread structure that records the info for this thread
|
||||
* @param[in] event_flags The event flags to wait for
|
||||
*
|
||||
* @return The event flags that were set and have been cleared. If an error
|
||||
* occurs, the flag bit @ref SLI_BT_RTOS_EVENT_FLAG_ERROR is set in the return
|
||||
* value.
|
||||
*/
|
||||
static uint32_t wait_bluetooth_rtos_thread_event_flags(sli_bt_rtos_thread_t *thread)
|
||||
{
|
||||
// Loop until we see a flag set or an error occurs
|
||||
while (1) {
|
||||
// Pop the current flags
|
||||
uint32_t event_flags = pop_bluetooth_rtos_thread_event_flags(thread);
|
||||
|
||||
// If any flags were set, we're done
|
||||
if (event_flags != 0) {
|
||||
return event_flags;
|
||||
}
|
||||
|
||||
// Wait on the wakeup semaphore
|
||||
osStatus_t os_status = osSemaphoreAcquire(thread->wakeup_semaphore_id, osWaitForever);
|
||||
if (os_status != osOK) {
|
||||
// An error has occurred. Set the error bit and store the `sl_status_t` in
|
||||
// the other bits.
|
||||
sl_status_t status = os2sl_status(os_status);
|
||||
return SLI_BT_RTOS_EVENT_FLAG_ERROR | (uint32_t) status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static sl_status_t start_rtos_adaptation()
|
||||
{
|
||||
// This function is called internally in this file. Callers guarantee the
|
||||
// necessary locking, so we can manipulate the flags safely.
|
||||
|
||||
// If the Bluetooth stack is stopping, we cannot accept a new request to start
|
||||
// the stack until the previous stopping has finished
|
||||
if (bluetooth_state_flags & SLI_BT_RTOS_STATE_FLAG_STOPPING) {
|
||||
return SL_STATUS_INVALID_STATE;
|
||||
}
|
||||
|
||||
// If the stack is already starting or started, the new request to start
|
||||
// requires no actions
|
||||
if (bluetooth_state_flags & (SLI_BT_RTOS_STATE_FLAG_STARTING | SLI_BT_RTOS_STATE_FLAG_STARTED)) {
|
||||
return SL_STATUS_OK;
|
||||
}
|
||||
|
||||
// We need to start the stack now. First create the mutex for Bluetooth stack.
|
||||
sl_status_t status = SL_STATUS_FAIL;
|
||||
EFM_ASSERT(bluetooth_mutex_id == NULL);
|
||||
bluetooth_mutex_id = osMutexNew(&bluetooth_mutex_attr);
|
||||
if (bluetooth_mutex_id == NULL) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// We have committed to starting the stack and we expect
|
||||
// `bluetooth_thread()` to continue the start-up.
|
||||
bluetooth_state_flags |= SLI_BT_RTOS_STATE_FLAG_STARTING;
|
||||
|
||||
// Create thread for Bluetooth stack. Note that we specifically do *not*
|
||||
// assign `thread_bluetooth.thread_id` here. When the thread is created, its
|
||||
// priority may be higher than the current thread, so Bluetooth starts running
|
||||
// before this thread has a chance to set the thread ID. To solve this
|
||||
// potential race condition, we let the Bluetooth thread itself set
|
||||
// `thread_bluetooth.thread_id` when it starts running. This way setting the
|
||||
// thread ID is always synchronous to starting the stack inside the thread.
|
||||
osThreadId_t host_stack_tid = NULL;
|
||||
status = create_bluetooth_rtos_thread(&thread_bluetooth,
|
||||
&host_stack_tid,
|
||||
&semaphore_bluetooth_attr,
|
||||
bluetooth_thread,
|
||||
&thread_bluetooth_attr);
|
||||
if (status != SL_STATUS_OK) {
|
||||
// We failed to create the thread, so the start won't be able to proceed.
|
||||
// Clear the starting flag to keep the state consistent.
|
||||
bluetooth_state_flags &= ~SLI_BT_RTOS_STATE_FLAG_STARTING;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Now we're ready to handle BGAPI commands via the RTOS adaptation. Set the
|
||||
// BGAPI delegate.
|
||||
sli_bgapi_set_cmd_handler_delegate(sli_bt_cmd_handler_rtos_delegate);
|
||||
|
||||
return SL_STATUS_OK;
|
||||
|
||||
cleanup:
|
||||
// Cleanup everything we managed to create
|
||||
if (bluetooth_mutex_id != NULL) {
|
||||
(void) osMutexDelete(bluetooth_mutex_id);
|
||||
bluetooth_mutex_id = NULL;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
sl_status_t sl_bt_rtos_init()
|
||||
{
|
||||
// Initialize the Bluetooth stack
|
||||
sl_bt_init();
|
||||
|
||||
// The Bluetooth stack including its RTOS adaptation is started with a BGAPI
|
||||
// command. The BGAPI synchronization primitives are therefore always created
|
||||
// already at init-time and are never deleted.
|
||||
uint32_t max_count = 1;
|
||||
uint32_t initial_count = 0;
|
||||
bgapi_response_semaphore_id = osSemaphoreNew(max_count, initial_count, &bgapi_response_semaphore_attr);
|
||||
if (bgapi_response_semaphore_id == NULL) {
|
||||
return SL_STATUS_FAIL;
|
||||
}
|
||||
|
||||
bgapi_mutex_id = osMutexNew(&bgapi_mutex_attr);
|
||||
bgapi_command_recursion_count = 0;
|
||||
if (bgapi_mutex_id == NULL) {
|
||||
(void) osSemaphoreDelete(bgapi_response_semaphore_id);
|
||||
bgapi_response_semaphore_id = NULL;
|
||||
return SL_STATUS_FAIL;
|
||||
}
|
||||
|
||||
// When Event System IPC is in use, let it initialize itself
|
||||
#if defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
sl_status_t event_system_status = sli_bt_init_event_system();
|
||||
if (event_system_status != SL_STATUS_OK) {
|
||||
return event_system_status;
|
||||
}
|
||||
#endif
|
||||
|
||||
// When Bluetooth on-demand start feature is not present, the RTOS adaptation
|
||||
// is always started already at init-time.
|
||||
#if !defined(SL_CATALOG_BLUETOOTH_ON_DEMAND_START_PRESENT)
|
||||
sl_status_t status = start_rtos_adaptation();
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif // defined(SL_CATALOG_BLUETOOTH_ON_DEMAND_START_PRESENT)
|
||||
|
||||
return SL_STATUS_OK;
|
||||
}
|
||||
|
||||
// This callback is called from interrupt context (Kernel Aware) to wake up the
|
||||
// link layer task
|
||||
void sli_bt_rtos_ll_callback()
|
||||
{
|
||||
set_bluetooth_rtos_thread_event_flags(&thread_linklayer,
|
||||
SLI_BT_RTOS_LINKLAYER_THREAD_FLAG_WAKEUP);
|
||||
}
|
||||
|
||||
// This callback is called by the Bluetooth stack to wakeup the Bluetooth
|
||||
// thread. This call may come from a thread or from interrupt context.
|
||||
void sli_bt_rtos_stack_callback()
|
||||
{
|
||||
set_bluetooth_rtos_thread_event_flags(&thread_bluetooth,
|
||||
SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_WAKEUP);
|
||||
}
|
||||
|
||||
// Called by Bluetooth Event System IPC to mark an event as handled
|
||||
void sli_bt_rtos_set_event_handled()
|
||||
{
|
||||
// Signal the host stack thread that the event has been handled
|
||||
set_bluetooth_rtos_thread_event_flags(&thread_bluetooth,
|
||||
SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal stack function to get how long the Bluetooth stack can sleep.
|
||||
*
|
||||
* @return 0 if the stack cannot sleep;
|
||||
* Maximum value of uint32_t if the stack has no task scheduled to process;
|
||||
* The ticks (in sleeptimer frequency) the stack needs to wake up to process a task
|
||||
*/
|
||||
extern uint32_t sli_bt_can_sleep_ticks();
|
||||
|
||||
/**
|
||||
* Internal stack function to start the Bluetooth stack.
|
||||
*
|
||||
* @return SL_STATUS_OK if the stack was successfully started
|
||||
*/
|
||||
extern sl_status_t sli_bt_system_start_bluetooth();
|
||||
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
// This is to avoid casting a function pointer to a different type in the
|
||||
// event_types table.
|
||||
static sl_status_t _btmesh_pop_event(sl_bt_msg_t *msg)
|
||||
{
|
||||
return sl_btmesh_pop_event((sl_btmesh_msg_t*) msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
enum sl_bgapi_dev_types dev_type;
|
||||
bool (*event_pending_fn)(void);
|
||||
sl_status_t (*pop_event_fn)(sl_bt_msg_t *buffer);
|
||||
} bgapi_device_type;
|
||||
|
||||
static const bgapi_device_type bgapi_device_table[] = {
|
||||
{ sl_bgapi_dev_type_bt, sl_bt_event_pending, sl_bt_pop_event },
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
{ sl_bgapi_dev_type_btmesh, sl_btmesh_event_pending, _btmesh_pop_event },
|
||||
#endif
|
||||
};
|
||||
|
||||
#define NUM_BGAPI_DEVICES (sizeof(bgapi_device_table) / sizeof(bgapi_device_table[0]))
|
||||
|
||||
//Bluetooth task, it waits for events from bluetooth and handles them
|
||||
void bluetooth_thread(void *p_arg)
|
||||
{
|
||||
(void)p_arg;
|
||||
|
||||
// Set the Bluetooth thread ID now that we're running
|
||||
thread_bluetooth.thread_id = osThreadGetId();
|
||||
|
||||
uint8_t next_evt_index_to_check = 0;
|
||||
uint32_t flags = SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED;
|
||||
|
||||
// Create thread for Linklayer
|
||||
sl_status_t start_status = create_bluetooth_rtos_thread(&thread_linklayer,
|
||||
&thread_linklayer.thread_id,
|
||||
&semaphore_linklayer_attr,
|
||||
linklayer_thread,
|
||||
&thread_linklayer_attr);
|
||||
|
||||
// Create thread for Bluetooth event handler when Event System IPC is not used
|
||||
#if !defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
if (start_status == SL_STATUS_OK) {
|
||||
start_status = create_bluetooth_rtos_thread(&thread_event_handler,
|
||||
&thread_event_handler.thread_id,
|
||||
&semaphore_event_handler_attr,
|
||||
event_handler_thread,
|
||||
&thread_event_handler_attr
|
||||
);
|
||||
}
|
||||
#endif // !defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
|
||||
// Start the Bluetooth stack
|
||||
if (start_status == SL_STATUS_OK) {
|
||||
start_status = sli_bt_system_start_bluetooth();
|
||||
}
|
||||
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
// Bluetooth Mesh calls Bluetooth's BGAPI commands internally. In order to not
|
||||
// collide with external commands, a temporary BGAPI buffer needs to be used.
|
||||
void *tmp_bgapi_buffer = sl_malloc(SLI_BGAPI_BUFFER_SIZE);
|
||||
if (tmp_bgapi_buffer == NULL) {
|
||||
start_status = SL_STATUS_ALLOCATION_FAILED;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (start_status == SL_STATUS_OK) {
|
||||
// bluetooth mesh must have bluetooth started before it is initalizes
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
sl_btmesh_init();
|
||||
#endif
|
||||
// Starting the stack has succeeded and we update the state accordingly.
|
||||
uint8_t updated_state_flags = bluetooth_state_flags;
|
||||
updated_state_flags &= ~SLI_BT_RTOS_STATE_FLAG_STARTING;
|
||||
updated_state_flags |= SLI_BT_RTOS_STATE_FLAG_STARTED;
|
||||
bluetooth_state_flags = updated_state_flags;
|
||||
} else {
|
||||
// We failed to start, so consider the stack stopped already in the local
|
||||
// flags. This way we won't enter the processing loop at all, but proceed to
|
||||
// cleaning up after the loop. The state flags in `bluetooth_state_flags`
|
||||
// continue to show the "starting" state until we've finished cleaning up.
|
||||
flags |= SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_STOPPED;
|
||||
}
|
||||
|
||||
// We run the command processing loop as long as the stack has not been stopped
|
||||
while ((flags & SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_STOPPED) == 0) {
|
||||
//Command needs to be sent to Bluetooth stack
|
||||
if (flags & SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_COMMAND_WAITING) {
|
||||
uint32_t header = command_header;
|
||||
sl_bgapi_handler cmd_handler = command_handler_func;
|
||||
sli_bgapi_cmd_handler_delegate(header, cmd_handler, (void*)command_data);
|
||||
command_handler_func = NULL;
|
||||
flags &= ~SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_COMMAND_WAITING;
|
||||
osSemaphoreRelease(bgapi_response_semaphore_id);
|
||||
}
|
||||
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
// Set a temporary BGAPI buffer for the section in which internal BGAPI
|
||||
// calls might occur.
|
||||
void *orig_bgapi_buffer = sli_bgapi_set_buffer(tmp_bgapi_buffer);
|
||||
#endif
|
||||
|
||||
//Run Bluetooth stack. Pop the next event for application
|
||||
sl_bt_run();
|
||||
if (flags & SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED) {
|
||||
bool event_popped = false;
|
||||
sl_status_t status = SL_STATUS_OK;
|
||||
for (uint8_t i = 0; i < NUM_BGAPI_DEVICES; i++) {
|
||||
// Try to get an event of a device type that was _not_ handled previously, in order to
|
||||
// prevent one device type from "starving" the other device type(s).
|
||||
// For example, Bluetooth scan reports could flood in so fast that we'd never process
|
||||
// BT Mesh events, if we always checked for Bluetooth events first.
|
||||
uint8_t evt_index = (next_evt_index_to_check + i) % NUM_BGAPI_DEVICES;
|
||||
const bgapi_device_type *dev = &bgapi_device_table[evt_index];
|
||||
if (dev->event_pending_fn()) {
|
||||
status = dev->pop_event_fn((sl_bt_msg_t*) &bluetooth_evt_instance);
|
||||
if (status == SL_STATUS_OK) {
|
||||
// Next round, start the search from the next event type (wrapping around if needed)
|
||||
next_evt_index_to_check = (evt_index + 1) % NUM_BGAPI_DEVICES;
|
||||
event_popped = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (status != SL_STATUS_OK) {
|
||||
continue;
|
||||
}
|
||||
if (event_popped) {
|
||||
// Always clear the local flag once an event was popped. The flag gets
|
||||
// set when the event has been handled and the corresponding thread
|
||||
// event flag is signalled by `sli_bt_rtos_set_event_handled()`.
|
||||
flags &= ~SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED;
|
||||
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
sl_btmesh_bgapi_listener((sl_bt_msg_t*) &bluetooth_evt_instance);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
// Publish the event to Event System IPC
|
||||
sl_status_t publish_status = sli_bt_publish_to_event_system((sl_bt_msg_t*) &bluetooth_evt_instance);
|
||||
if (publish_status != SL_STATUS_OK) {
|
||||
// Failed to publish the event. This is potentially fatal, but there
|
||||
// is not much we can do here. Assert in a debug build.
|
||||
EFM_ASSERT(0);
|
||||
}
|
||||
#else // defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
// Signal the event handler task to deliver the event
|
||||
set_bluetooth_rtos_thread_event_flags(&thread_event_handler,
|
||||
SLI_BT_RTOS_EVENT_THREAD_FLAG_EVENT_WAITING);
|
||||
#endif // defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
// Restore the original BGAPI buffer after the section in which internal BGAPI
|
||||
// calls might occur.
|
||||
sli_bgapi_set_buffer(orig_bgapi_buffer);
|
||||
#endif
|
||||
|
||||
uint32_t timeout = sli_bt_can_sleep_ticks();
|
||||
if (timeout == 0 && (flags & SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Wait for any flag to get set
|
||||
flags |= wait_bluetooth_rtos_thread_event_flags(&thread_bluetooth);
|
||||
if ((flags & SLI_BT_RTOS_EVENT_FLAG_ERROR) != 0) {
|
||||
// In case of error, reset the flags and continue
|
||||
flags = SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// The stack has stopped processing commands and has already finished its own
|
||||
// cleanup of resources. It's now time for the RTOS adaptation to cleanup its
|
||||
// own resources. First delete the threads that we created for the link layer
|
||||
// and for the event handler.
|
||||
delete_bluetooth_rtos_thread(&thread_linklayer);
|
||||
#if !defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
delete_bluetooth_rtos_thread(&thread_event_handler);
|
||||
#endif
|
||||
|
||||
// Delete the synchronization primitives
|
||||
(void) osMutexDelete(bluetooth_mutex_id);
|
||||
bluetooth_mutex_id = NULL;
|
||||
|
||||
// In case we've failed to start, we will directly deliver a system error
|
||||
// event to the application in the code below. To allow the application to
|
||||
// retry when it gets the error event, we need to clean all global state first
|
||||
// and finish the cleanup locally in the current thread when the event handler
|
||||
// returns. We take ownership of all remaining RTOS objects (this thread and
|
||||
// its wakeup semaphore) and clear the state to indicate the kernel is started
|
||||
// but the stack is stopped.
|
||||
thread_bluetooth.thread_id = NULL;
|
||||
(void) osSemaphoreDelete(thread_bluetooth.wakeup_semaphore_id);
|
||||
thread_bluetooth.wakeup_semaphore_id = NULL;
|
||||
bluetooth_state_flags = SLI_BT_RTOS_STATE_FLAG_KERNEL_STARTED;
|
||||
|
||||
// Generate the right event to indicate the stack is not running
|
||||
if (start_status != SL_STATUS_OK) {
|
||||
// We failed to start the stack. Generate a system error event.
|
||||
uint32_t evt_len = sizeof(bluetooth_evt_instance.data.evt_system_error);
|
||||
bluetooth_evt_instance.header = sl_bt_evt_system_error_id | (evt_len << 8);
|
||||
bluetooth_evt_instance.data.evt_system_error.reason = (uint16_t) start_status;
|
||||
bluetooth_evt_instance.data.evt_system_error.data.len = 0;
|
||||
} else {
|
||||
// The stack started successfully, so the stopping has been a deliberate
|
||||
// request with the on-demand start feature. Generate the "system stopped"
|
||||
// event and deliver it directly to the application with a function call
|
||||
// from this thread. Note that the "system stopped" event has no
|
||||
// event-specific fields, so only the header needs to be set.
|
||||
bluetooth_evt_instance.header = sl_bt_evt_system_stopped_id;
|
||||
}
|
||||
|
||||
// Publish via event system or call the application directly
|
||||
#if defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
sli_bt_publish_to_event_system((sl_bt_msg_t*) &bluetooth_evt_instance);
|
||||
#else
|
||||
sl_bt_process_event((sl_bt_msg_t*) &bluetooth_evt_instance);
|
||||
#endif
|
||||
|
||||
// Finally terminate this thread itself
|
||||
(void) osThreadTerminate(osThreadGetId());
|
||||
}
|
||||
|
||||
static void linklayer_thread(void *p_arg)
|
||||
{
|
||||
// The input parameter is our thread structure
|
||||
sli_bt_rtos_thread_t *thread = (sli_bt_rtos_thread_t *) p_arg;
|
||||
|
||||
while (1) {
|
||||
// Wait for any flag to get set. Only the link layer flag is expected in
|
||||
// this thread.
|
||||
uint32_t flags = wait_bluetooth_rtos_thread_event_flags(thread);
|
||||
EFM_ASSERT(flags == SLI_BT_RTOS_LINKLAYER_THREAD_FLAG_WAKEUP);
|
||||
|
||||
// Handle the event
|
||||
sl_bt_priority_handle();
|
||||
}
|
||||
}
|
||||
|
||||
// Event task, this calls the application code
|
||||
#if !defined(SL_CATALOG_BLUETOOTH_EVENT_SYSTEM_IPC_PRESENT)
|
||||
static void event_handler_thread(void *p_arg)
|
||||
{
|
||||
// The input parameter is our thread structure
|
||||
sli_bt_rtos_thread_t *thread = (sli_bt_rtos_thread_t *) p_arg;
|
||||
|
||||
while (1) {
|
||||
// Wait for any flag to get set. Only the "event waiting" flag is expected
|
||||
// in this thread.
|
||||
uint32_t flags = wait_bluetooth_rtos_thread_event_flags(thread);
|
||||
EFM_ASSERT(flags == SLI_BT_RTOS_EVENT_THREAD_FLAG_EVENT_WAITING);
|
||||
|
||||
switch (SL_BGAPI_MSG_DEVICE_TYPE(bluetooth_evt_instance.header)) {
|
||||
case sl_bgapi_dev_type_bt:
|
||||
sl_bt_process_event((sl_bt_msg_t*) &bluetooth_evt_instance);
|
||||
break;
|
||||
#if defined(SL_CATALOG_BTMESH_PRESENT)
|
||||
case sl_bgapi_dev_type_btmesh:
|
||||
sl_btmesh_process_event((sl_btmesh_msg_t*) &bluetooth_evt_instance);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
// This should not be possible
|
||||
EFM_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
// Signal the host stack thread that the event has been handled
|
||||
set_bluetooth_rtos_thread_event_flags(&thread_bluetooth,
|
||||
SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_EVENT_HANDLED);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//hooks for API
|
||||
//called from tasks using Bluetooth API
|
||||
void sli_bt_cmd_handler_rtos_delegate(uint32_t header, sl_bgapi_handler handler, const void* payload)
|
||||
{
|
||||
command_header = header;
|
||||
command_handler_func = handler;
|
||||
command_data = (void*)payload;
|
||||
if (osThreadGetId() == thread_bluetooth.thread_id) {
|
||||
// If we're already in the Bluetooth stack thread, the BGAPI command will be handled as a direct
|
||||
// function call; as opposed to signalling ourselves that there's a command waiting, like what
|
||||
// would happen in all other threads
|
||||
handler(payload);
|
||||
return;
|
||||
}
|
||||
|
||||
// We're starting a new command. The response semaphore cannot have an
|
||||
// available token yet.
|
||||
EFM_ASSERT(osSemaphoreGetCount(bgapi_response_semaphore_id) == 0);
|
||||
|
||||
// Command structure is filled, notify the stack
|
||||
set_bluetooth_rtos_thread_event_flags(&thread_bluetooth,
|
||||
SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_COMMAND_WAITING);
|
||||
|
||||
// Wait for response
|
||||
osSemaphoreAcquire(bgapi_response_semaphore_id, osWaitForever);
|
||||
}
|
||||
|
||||
// Lock the BGAPI for exclusive access
|
||||
sl_status_t sl_bgapi_lock(void)
|
||||
{
|
||||
// The BGAPI is not allowed to be called from an ISR
|
||||
if (CORE_InIrqContext()) {
|
||||
return SL_STATUS_ISR;
|
||||
}
|
||||
|
||||
// If the kernel has not been started yet, the BGAPI command call must be a
|
||||
// call from `app_init()` to start the Bluetooth stack. The init is
|
||||
// single-threaded and we can safely proceed without the lock.
|
||||
if ((bluetooth_state_flags & SLI_BT_RTOS_STATE_FLAG_KERNEL_STARTED) == 0) {
|
||||
return SL_STATUS_OK;
|
||||
}
|
||||
|
||||
osStatus_t ret = osMutexAcquire(bgapi_mutex_id, 0);
|
||||
if (ret == osOK) {
|
||||
// Able to immediately acquire
|
||||
return SL_STATUS_OK;
|
||||
} else if ((ret != osOK)
|
||||
&& (osThreadGetId() == thread_bluetooth.thread_id)) {
|
||||
// No need to re-acquire, but increment recursion counter since the Bluetooth thread
|
||||
// is allowed to call BGAPI commands recursively
|
||||
bgapi_command_recursion_count++;
|
||||
return SL_STATUS_OK;
|
||||
} else {
|
||||
// Otherwise wait for the mutex
|
||||
ret = osMutexAcquire(bgapi_mutex_id, osWaitForever);
|
||||
return os2sl_status(ret);
|
||||
}
|
||||
}
|
||||
|
||||
// Release the lock obtained by @ref sl_bgapi_lock
|
||||
void sl_bgapi_unlock(void)
|
||||
{
|
||||
// If the kernel has not been started yet, the lock has not been obtained and
|
||||
// the unlock is ignored
|
||||
if ((bluetooth_state_flags & SLI_BT_RTOS_STATE_FLAG_KERNEL_STARTED) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bgapi_command_recursion_count > 0) {
|
||||
// Do not release the mutex if we are in a recursive call.
|
||||
bgapi_command_recursion_count--;
|
||||
return;
|
||||
}
|
||||
|
||||
(void) osMutexRelease(bgapi_mutex_id);
|
||||
}
|
||||
|
||||
// Called by system initialization when kernel is starting.
|
||||
void sli_bt_rtos_adaptation_kernel_start()
|
||||
{
|
||||
bluetooth_state_flags |= SLI_BT_RTOS_STATE_FLAG_KERNEL_STARTED;
|
||||
}
|
||||
|
||||
// Start the Bluetooth RTOS adaptation
|
||||
sl_status_t sli_bt_start_rtos_adaptation()
|
||||
{
|
||||
return start_rtos_adaptation();
|
||||
}
|
||||
|
||||
// Prepare for stopping the Bluetooth RTOS adaptation
|
||||
void sli_bt_prepare_to_stop_rtos_adaptation()
|
||||
{
|
||||
// This function is called in the context of the Bluetooth thread when
|
||||
// processing the command sl_bt_system_stop_bluetooth(). The BGAPI lock is
|
||||
// already held when we enter this function and we can safely manipulate the
|
||||
// state flags. The BGAPI command handling verifies the current state and
|
||||
// calls this function only when it's really time to begin stopping. We can
|
||||
// simply always set the flag.
|
||||
bluetooth_state_flags |= SLI_BT_RTOS_STATE_FLAG_STOPPING;
|
||||
|
||||
// We stop processing BGAPI commands via the RTOS adaptation, as the stack has
|
||||
// already committed to stopping. The BGAPI device has changed to a state
|
||||
// where only commands that are available when the stack is stopped are
|
||||
// reachable if the application calls a BGAPI command. It is therefore safe to
|
||||
// handle BGAPI commands via the default delegate until the stack is
|
||||
// restarted.
|
||||
sli_bgapi_set_cmd_handler_delegate(sli_bgapi_cmd_handler_delegate);
|
||||
}
|
||||
|
||||
// Stop the Bluetooth RTOS adaptation
|
||||
void sli_bt_stop_rtos_adaptation()
|
||||
{
|
||||
// Set the event flag to indicate that the stack has been stopped. The
|
||||
// Bluetooth thread will cleanup and exit.
|
||||
set_bluetooth_rtos_thread_event_flags(&thread_bluetooth,
|
||||
SLI_BT_RTOS_BLUETOOTH_THREAD_FLAG_STOPPED);
|
||||
}
|
||||
|
||||
sl_status_t sl_bt_bluetooth_pend()
|
||||
{
|
||||
osStatus_t ret = osMutexAcquire(bluetooth_mutex_id, osWaitForever);
|
||||
return os2sl_status(ret);
|
||||
}
|
||||
|
||||
sl_status_t sl_bt_bluetooth_post()
|
||||
{
|
||||
osStatus_t ret = osMutexRelease(bluetooth_mutex_id);
|
||||
return os2sl_status(ret);
|
||||
}
|
||||
|
||||
const sl_bt_msg_t* sl_bt_rtos_get_event()
|
||||
{
|
||||
return (const sl_bt_msg_t*) &bluetooth_evt_instance;
|
||||
}
|
||||
832
Libs/protocol/bluetooth/src/sl_bt_stack_init.c
Normal file
832
Libs/protocol/bluetooth/src/sl_bt_stack_init.c
Normal file
@@ -0,0 +1,832 @@
|
||||
/***************************************************************************//**
|
||||
* @brief Initialization APIs for Bluetooth stack
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
// Include the catalog first to make sure everything below can see it
|
||||
#ifdef SL_COMPONENT_CATALOG_PRESENT
|
||||
#include "sl_component_catalog.h"
|
||||
#else // SL_COMPONENT_CATALOG_PRESENT
|
||||
#error The SL component catalog required by Bluetooth stack is not present in the build
|
||||
#endif // SL_COMPONENT_CATALOG_PRESENT
|
||||
|
||||
// Define the initilization mode for the configuration definition headers. The
|
||||
// initialization mode for the Bluetooth stack depends on the on-demand start
|
||||
// component. When on-demand start is used, features support de-initialization.
|
||||
// When on-demand start is not used, the de-init functions are omitted to
|
||||
// eliminate code that's not needed in the build.
|
||||
#if defined(SL_CATALOG_BLUETOOTH_ON_DEMAND_START_PRESENT)
|
||||
#define SLI_BT_INIT_MODE on_demand
|
||||
#else
|
||||
#define SLI_BT_INIT_MODE init_always
|
||||
#endif
|
||||
|
||||
#include "sl_status.h"
|
||||
#include "sl_bt_api.h"
|
||||
#include "sl_bt_stack_config.h"
|
||||
#include "sl_bt_stack_init.h"
|
||||
#include "sl_bluetooth_config.h"
|
||||
#include "sl_btctrl_linklayer.h"
|
||||
#include "sli_bt_gattdb_def.h"
|
||||
#include "sli_bt_config_defs.h"
|
||||
|
||||
#ifdef SL_CATALOG_GATT_CONFIGURATION_PRESENT
|
||||
extern const sli_bt_gattdb_t gattdb;
|
||||
#else
|
||||
const sli_bt_gattdb_t gattdb = { 0 };
|
||||
#endif // SL_CATALOG_GATT_CONFIGURATION_PRESENT
|
||||
|
||||
// Forward declaration of BGAPI classes
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, system);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, nvm);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, gap);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, sm);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, external_bondingdb);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, accept_list);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, resolving_list);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, advertiser);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, legacy_advertiser);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, extended_advertiser);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, periodic_advertiser);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, scanner);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, sync);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, pawr_advertiser);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, sync_scanner);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, periodic_sync);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, pawr_sync);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, past_receiver);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, advertiser_past);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, sync_past);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, cs);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, cs_test);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, l2cap);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, connection);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, gatt);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, gattdb);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, gatt_server);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, cte_receiver);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, cte_transmitter);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, test);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, coex);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, resource);
|
||||
SLI_BT_DECLARE_BGAPI_CLASS(bt, connection_analyzer);
|
||||
|
||||
// Forward declaration of the internal Bluetooth stack init function
|
||||
sl_status_t sli_bt_init_stack(const sl_bt_configuration_t *config,
|
||||
const struct sli_bt_feature_use *features,
|
||||
const struct sli_bgapi_class * const *bgapi_classes);
|
||||
|
||||
// Some features do not correspond directly to a particular component but are
|
||||
// needed depending on a specific combination of components. Decide the derived
|
||||
// feature selections here to simplify the feature inclusion rules below.
|
||||
|
||||
// Extended advertising feature is included if it's explicitly used, but only
|
||||
// when there's no device incompatibility.
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_EXTENDED_ADVERTISER_PRESENT) \
|
||||
&& !defined(SL_CATALOG_BLUETOOTH_EXTENDED_ADVERTISING_INCOMPATIBLE_PRESENT)
|
||||
#define SLI_BT_ENABLE_EXTENDED_ADVERTISER_FEATURE
|
||||
#endif
|
||||
|
||||
// The scanner event handler is included if the legacy or extended scanner
|
||||
// component is used.
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_LEGACY_SCANNER_PRESENT) \
|
||||
|| defined(SL_CATALOG_BLUETOOTH_FEATURE_EXTENDED_SCANNER_PRESENT)
|
||||
#define SLI_BT_ENABLE_SCANNER_BASE
|
||||
#endif
|
||||
|
||||
// Extended scanner feature is included if it's explicitly used, but only when
|
||||
// there's no device incompatibility.
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_EXTENDED_SCANNER_PRESENT) \
|
||||
&& !defined(SL_CATALOG_BLUETOOTH_EXTENDED_SCANNING_INCOMPATIBLE_PRESENT)
|
||||
#define SLI_BT_ENABLE_EXTENDED_SCANNER_FEATURE
|
||||
#endif
|
||||
|
||||
// If the build configuration needs a specific feature, we pick it for inclusion
|
||||
// in the feature and BGAPI lists, as applicable.
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYSTEM_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, system);
|
||||
#define SLI_BT_FEATURE_SYSTEM SLI_BT_USE_FEATURE(bt, system),
|
||||
#define SLI_BT_BGAPI_SYSTEM SLI_BT_USE_BGAPI_CLASS(bt, system),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_SYSTEM
|
||||
#define SLI_BT_BGAPI_SYSTEM
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_ON_DEMAND_START_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, on_demand_start);
|
||||
#define SLI_BT_FEATURE_ON_DEMAND_START SLI_BT_USE_FEATURE(bt, on_demand_start),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_ON_DEMAND_START
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_NVM_PRESENT)
|
||||
#define SLI_BT_BGAPI_NVM SLI_BT_USE_BGAPI_CLASS(bt, nvm),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_NVM
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_GAP_PRESENT)
|
||||
#define SLI_BT_BGAPI_GAP SLI_BT_USE_BGAPI_CLASS(bt, gap),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_GAP
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SM_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, sm);
|
||||
#define SLI_BT_FEATURE_SM SLI_BT_USE_FEATURE(bt, sm),
|
||||
#define SLI_BT_BGAPI_SM SLI_BT_USE_BGAPI_CLASS(bt, sm),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_SM
|
||||
#define SLI_BT_BGAPI_SM
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_BUILTIN_BONDING_DATABASE_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, builtin_bonding_database);
|
||||
#define SLI_BT_FEATURE_BUILTIN_BONDING_DATABASE SLI_BT_USE_FEATURE(bt, builtin_bonding_database),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_BUILTIN_BONDING_DATABASE
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_EXTERNAL_BONDING_DATABASE_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, external_bonding_database);
|
||||
#define SLI_BT_FEATURE_EXTERNAL_BONDING_DATABASE SLI_BT_USE_FEATURE(bt, external_bonding_database),
|
||||
#define SLI_BT_BGAPI_EXTERNAL_BONDINGDB SLI_BT_USE_BGAPI_CLASS(bt, external_bondingdb),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_EXTERNAL_BONDING_DATABASE
|
||||
#define SLI_BT_BGAPI_EXTERNAL_BONDINGDB
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ACCEPT_LIST_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, accept_list);
|
||||
SLI_BT_DECLARE_FEATURE_CONFIG(bt, accept_list);
|
||||
#define SLI_BT_FEATURE_ACCEPT_LIST SLI_BT_USE_FEATURE_WITH_CONFIG(bt, accept_list, SLI_BT_FEATURE_CONFIG_NAME(bt, accept_list)),
|
||||
#define SLI_BT_BGAPI_ACCEPT_LIST SLI_BT_USE_BGAPI_CLASS(bt, accept_list),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_ACCEPT_LIST
|
||||
#define SLI_BT_BGAPI_ACCEPT_LIST
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_RESOLVING_LIST_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, resolving_list);
|
||||
#define SLI_BT_FEATURE_RESOLVING_LIST SLI_BT_USE_FEATURE(bt, resolving_list),
|
||||
#define SLI_BT_BGAPI_RESOLVING_LIST SLI_BT_USE_BGAPI_CLASS(bt, resolving_list),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_RESOLVING_LIST
|
||||
#define SLI_BT_BGAPI_RESOLVING_LIST
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ADVERTISER_PRESENT) \
|
||||
&& !defined(SL_CATALOG_BLUETOOTH_FEATURE_LEGACY_ADVERTISER_PRESENT) \
|
||||
&& !defined(SL_CATALOG_BLUETOOTH_FEATURE_EXTENDED_ADVERTISER_PRESENT)
|
||||
#error Incomplete Bluetooth advertiser feature detected. Add component \
|
||||
bluetooth_feature_legacy_advertiser for advertising with legacy \
|
||||
advertising PDUs. Add component bluetooth_feature_extended_advertiser \
|
||||
for advertising with extended advertising PDUs.
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ADVERTISER_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, advertiser);
|
||||
SLI_BT_DECLARE_FEATURE_CONFIG(bt, advertiser);
|
||||
#define SLI_BT_FEATURE_ADVERTISER SLI_BT_USE_FEATURE_WITH_CONFIG(bt, advertiser, SLI_BT_FEATURE_CONFIG_NAME(bt, advertiser)),
|
||||
#define SLI_BT_BGAPI_ADVERTISER SLI_BT_USE_BGAPI_CLASS(bt, advertiser),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_ADVERTISER
|
||||
#define SLI_BT_BGAPI_ADVERTISER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_LEGACY_ADVERTISER_PRESENT)
|
||||
#define SLI_BT_BGAPI_LEGACY_ADVERTISER SLI_BT_USE_BGAPI_CLASS(bt, legacy_advertiser),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_LEGACY_ADVERTISER
|
||||
#endif
|
||||
|
||||
#if defined(SLI_BT_ENABLE_EXTENDED_ADVERTISER_FEATURE)
|
||||
SLI_BT_DECLARE_FEATURE(bt, extended_advertiser);
|
||||
#define SLI_BT_FEATURE_EXTENDED_ADVERTISER SLI_BT_USE_FEATURE(bt, extended_advertiser),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_EXTENDED_ADVERTISER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_EXTENDED_ADVERTISER_PRESENT)
|
||||
#define SLI_BT_BGAPI_EXTENDED_ADVERTISER SLI_BT_USE_BGAPI_CLASS(bt, extended_advertiser),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_EXTENDED_ADVERTISER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PERIODIC_ADVERTISER_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, periodic_advertiser);
|
||||
SLI_BT_DECLARE_FEATURE_CONFIG(bt, periodic_advertiser);
|
||||
#define SLI_BT_FEATURE_PERIODIC_ADVERTISER SLI_BT_USE_FEATURE_WITH_CONFIG(bt, periodic_advertiser, SLI_BT_FEATURE_CONFIG_NAME(bt, periodic_advertiser)),
|
||||
#define SLI_BT_BGAPI_PERIODIC_ADVERTISER SLI_BT_USE_BGAPI_CLASS(bt, periodic_advertiser),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_PERIODIC_ADVERTISER
|
||||
#define SLI_BT_BGAPI_PERIODIC_ADVERTISER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAWR_ADVERTISER_PRESENT)
|
||||
#define SLI_BT_BGAPI_PAWR_ADVERTISER SLI_BT_USE_BGAPI_CLASS(bt, pawr_advertiser),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_PAWR_ADVERTISER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SCANNER_PRESENT) \
|
||||
&& !defined(SL_CATALOG_BLUETOOTH_FEATURE_LEGACY_SCANNER_PRESENT) \
|
||||
&& !defined(SL_CATALOG_BLUETOOTH_FEATURE_EXTENDED_SCANNER_PRESENT)
|
||||
#error Incomplete Bluetooth scanner feature detected. Add component \
|
||||
bluetooth_feature_legacy_scanner for scanning advertisements in legacy \
|
||||
advertising PDUs. Add component bluetooth_feature_extended_scanner for \
|
||||
scanning advertisements in legacy or extended advertising PDUs.
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SCANNER_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, scanner);
|
||||
#define SLI_BT_FEATURE_SCANNER SLI_BT_USE_FEATURE(bt, scanner),
|
||||
#define SLI_BT_BGAPI_SCANNER SLI_BT_USE_BGAPI_CLASS(bt, scanner),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_SCANNER
|
||||
#define SLI_BT_BGAPI_SCANNER
|
||||
#endif
|
||||
|
||||
#if defined(SLI_BT_ENABLE_SCANNER_BASE)
|
||||
SLI_BT_DECLARE_FEATURE(bt, scanner_base);
|
||||
#define SLI_BT_FEATURE_SCANNER_BASE SLI_BT_USE_FEATURE(bt, scanner_base),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_SCANNER_BASE
|
||||
#endif
|
||||
|
||||
#if defined(SLI_BT_ENABLE_EXTENDED_SCANNER_FEATURE)
|
||||
SLI_BT_DECLARE_FEATURE(bt, extended_scanner);
|
||||
#define SLI_BT_FEATURE_EXTENDED_SCANNER SLI_BT_USE_FEATURE(bt, extended_scanner),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_EXTENDED_SCANNER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, sync);
|
||||
SLI_BT_DECLARE_FEATURE_CONFIG(bt, sync);
|
||||
#define SLI_BT_FEATURE_SYNC SLI_BT_USE_FEATURE_WITH_CONFIG(bt, sync, SLI_BT_FEATURE_CONFIG_NAME(bt, sync)),
|
||||
#define SLI_BT_BGAPI_SYNC SLI_BT_USE_BGAPI_CLASS(bt, sync),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_SYNC
|
||||
#define SLI_BT_BGAPI_SYNC
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_SCANNER_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, sync_scanner);
|
||||
#define SLI_BT_FEATURE_SYNC_SCANNER SLI_BT_USE_FEATURE(bt, sync_scanner),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_SYNC_SCANNER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_SCANNER_PRESENT)
|
||||
#define SLI_BT_BGAPI_SYNC_SCANNER SLI_BT_USE_BGAPI_CLASS(bt, sync_scanner),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_SYNC_SCANNER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PERIODIC_SYNC_PRESENT)
|
||||
#define SLI_BT_BGAPI_PERIODIC_SYNC SLI_BT_USE_BGAPI_CLASS(bt, periodic_sync),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_PERIODIC_SYNC
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAWR_SYNC_PRESENT)
|
||||
#define SLI_BT_BGAPI_PAWR_SYNC SLI_BT_USE_BGAPI_CLASS(bt, pawr_sync),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_PAWR_SYNC
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAST_RECEIVER_PRESENT)
|
||||
#define SLI_BT_BGAPI_PAST_RECEIVER SLI_BT_USE_BGAPI_CLASS(bt, past_receiver),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_PAST_RECEIVER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ADVERTISER_PAST_PRESENT)
|
||||
#define SLI_BT_BGAPI_ADVERTISER_PAST SLI_BT_USE_BGAPI_CLASS(bt, advertiser_past),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_ADVERTISER_PAST
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_PAST_PRESENT)
|
||||
#define SLI_BT_BGAPI_SYNC_PAST SLI_BT_USE_BGAPI_CLASS(bt, sync_past),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_SYNC_PAST
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CS_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, cs);
|
||||
#define SLI_BT_FEATURE_CS SLI_BT_USE_FEATURE(bt, cs),
|
||||
#define SLI_BT_BGAPI_CS SLI_BT_USE_BGAPI_CLASS(bt, cs),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_CS
|
||||
#define SLI_BT_BGAPI_CS
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CS_TEST_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, cs_test);
|
||||
#define SLI_BT_FEATURE_CS_TEST SLI_BT_USE_FEATURE(bt, cs_test),
|
||||
#define SLI_BT_BGAPI_CS_TEST SLI_BT_USE_BGAPI_CLASS(bt, cs_test),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_CS_TEST
|
||||
#define SLI_BT_BGAPI_CS_TEST
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_L2CAP_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, l2cap);
|
||||
SLI_BT_DECLARE_FEATURE_CONFIG(bt, l2cap);
|
||||
#define SLI_BT_FEATURE_L2CAP SLI_BT_USE_FEATURE_WITH_CONFIG(bt, l2cap, SLI_BT_FEATURE_CONFIG_NAME(bt, l2cap)),
|
||||
#define SLI_BT_BGAPI_L2CAP SLI_BT_USE_BGAPI_CLASS(bt, l2cap),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_L2CAP
|
||||
#define SLI_BT_BGAPI_L2CAP
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, connection);
|
||||
SLI_BT_DECLARE_FEATURE_CONFIG(bt, connection);
|
||||
#define SLI_BT_FEATURE_CONNECTION SLI_BT_USE_FEATURE_WITH_CONFIG(bt, connection, SLI_BT_FEATURE_CONFIG_NAME(bt, connection)),
|
||||
#define SLI_BT_BGAPI_CONNECTION SLI_BT_USE_BGAPI_CLASS(bt, connection),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_CONNECTION
|
||||
#define SLI_BT_BGAPI_CONNECTION
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_STATISTICS_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, connection_statistics);
|
||||
#define SLI_BT_FEATURE_CONNECTION_STATISTICS SLI_BT_USE_FEATURE(bt, connection_statistics),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_CONNECTION_STATISTICS
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_USER_POWER_CONTROL_PRESENT) \
|
||||
&& defined(SL_CATALOG_BLUETOOTH_FEATURE_POWER_CONTROL_PRESENT)
|
||||
#error bluetooth_feature_power_control and bluetooth_feature_user_power_control cannot coexist.
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_POWER_CONTROL_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, power_control);
|
||||
#define SLI_BT_FEATURE_POWER_CONTROL SLI_BT_USE_FEATURE(bt, power_control),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_POWER_CONTROL
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_USER_POWER_CONTROL_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, user_power_control);
|
||||
#define SLI_BT_FEATURE_USER_POWER_CONTROL SLI_BT_USE_FEATURE(bt, user_power_control),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_USER_POWER_CONTROL
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_GATT_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, gatt);
|
||||
#define SLI_BT_FEATURE_GATT SLI_BT_USE_FEATURE(bt, gatt),
|
||||
#define SLI_BT_BGAPI_GATT SLI_BT_USE_BGAPI_CLASS(bt, gatt),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_GATT
|
||||
#define SLI_BT_BGAPI_GATT
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_DYNAMIC_GATTDB_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, dynamic_gattdb);
|
||||
SLI_BT_DECLARE_FEATURE_CONFIG(bt, dynamic_gattdb);
|
||||
#define SLI_BT_FEATURE_DYNAMIC_GATTDB SLI_BT_USE_FEATURE_WITH_CONFIG(bt, dynamic_gattdb, SLI_BT_FEATURE_CONFIG_NAME(bt, dynamic_gattdb)),
|
||||
#define SLI_BT_BGAPI_DYNAMIC_GATTDB SLI_BT_USE_BGAPI_CLASS(bt, gattdb),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_DYNAMIC_GATTDB
|
||||
#define SLI_BT_BGAPI_DYNAMIC_GATTDB
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_GATT_SERVER_PRESENT)
|
||||
#define SLI_BT_BGAPI_GATT_SERVER SLI_BT_USE_BGAPI_CLASS(bt, gatt_server),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_GATT_SERVER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_AOA_RECEIVER_PRESENT) \
|
||||
|| defined(SL_CATALOG_BLUETOOTH_FEATURE_AOD_RECEIVER_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, cte_receiver);
|
||||
#define SLI_BT_FEATURE_CTE_RECEIVER SLI_BT_USE_FEATURE(bt, cte_receiver),
|
||||
#define SLI_BT_BGAPI_CTE_RECEIVER SLI_BT_USE_BGAPI_CLASS(bt, cte_receiver),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_CTE_RECEIVER
|
||||
#define SLI_BT_BGAPI_CTE_RECEIVER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_AOA_TRANSMITTER_PRESENT) \
|
||||
|| defined(SL_CATALOG_BLUETOOTH_FEATURE_AOD_TRANSMITTER_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, cte_transmitter);
|
||||
#define SLI_BT_FEATURE_CTE_TRANSMITTER SLI_BT_USE_FEATURE(bt, cte_transmitter),
|
||||
#define SLI_BT_BGAPI_CTE_TRANSMITTER SLI_BT_USE_BGAPI_CLASS(bt, cte_transmitter),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_CTE_TRANSMITTER
|
||||
#define SLI_BT_BGAPI_CTE_TRANSMITTER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_TEST_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, test);
|
||||
#define SLI_BT_FEATURE_TEST SLI_BT_USE_FEATURE(bt, test),
|
||||
#define SLI_BT_BGAPI_TEST SLI_BT_USE_BGAPI_CLASS(bt, test),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_TEST
|
||||
#define SLI_BT_BGAPI_TEST
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_RAIL_UTIL_COEX_PRESENT)
|
||||
#define SLI_BT_BGAPI_COEX SLI_BT_USE_BGAPI_CLASS(bt, coex),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_COEX
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_RESOURCE_REPORT_PRESENT)
|
||||
#define SLI_BT_BGAPI_RESOURCE SLI_BT_USE_BGAPI_CLASS(bt, resource),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_RESOURCE
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_USE_ACCURATE_API_ADDRESS_TYPES_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, accurate_api_address_types);
|
||||
#define SLI_BT_FEATURE_ACCURATE_API_ADDRESS_TYPES SLI_BT_USE_FEATURE(bt, accurate_api_address_types),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_ACCURATE_API_ADDRESS_TYPES
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_ANALYZER_PRESENT)
|
||||
#define SLI_BT_BGAPI_CONNECTION_ANALYZER SLI_BT_USE_BGAPI_CLASS(bt, connection_analyzer),
|
||||
#else
|
||||
#define SLI_BT_BGAPI_CONNECTION_ANALYZER
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_SUBRATING_PRESENT)
|
||||
SLI_BT_DECLARE_FEATURE(bt, connection_subrate);
|
||||
#define SLI_BT_FEATURE_CONNECTION_SUBRATE SLI_BT_USE_FEATURE(bt, connection_subrate),
|
||||
#else
|
||||
#define SLI_BT_FEATURE_CONNECTION_SUBRATE
|
||||
#endif
|
||||
|
||||
/** @brief Structure that specifies the Bluetooth configuration */
|
||||
static const sl_bt_configuration_t bt_config = SL_BT_CONFIG_DEFAULT;
|
||||
|
||||
/** @brief Table of used Bluetooth features */
|
||||
static const struct sli_bt_feature_use bt_used_features[] =
|
||||
{
|
||||
// Invoke the feature inclusion macro for each feature. Depending on the build
|
||||
// configuration, the feature inclusion rules above have defined the macro to
|
||||
// either empty or the relevant feature use declaration.
|
||||
SLI_BT_FEATURE_ON_DEMAND_START
|
||||
SLI_BT_FEATURE_SYSTEM
|
||||
SLI_BT_FEATURE_SM
|
||||
SLI_BT_FEATURE_BUILTIN_BONDING_DATABASE
|
||||
SLI_BT_FEATURE_EXTERNAL_BONDING_DATABASE
|
||||
SLI_BT_FEATURE_ACCEPT_LIST
|
||||
SLI_BT_FEATURE_RESOLVING_LIST
|
||||
SLI_BT_FEATURE_SCANNER
|
||||
SLI_BT_FEATURE_SCANNER_BASE
|
||||
SLI_BT_FEATURE_EXTENDED_SCANNER
|
||||
SLI_BT_FEATURE_SYNC
|
||||
SLI_BT_FEATURE_SYNC_SCANNER
|
||||
SLI_BT_FEATURE_ADVERTISER
|
||||
SLI_BT_FEATURE_EXTENDED_ADVERTISER
|
||||
SLI_BT_FEATURE_PERIODIC_ADVERTISER
|
||||
SLI_BT_FEATURE_CS
|
||||
SLI_BT_FEATURE_CS_TEST
|
||||
SLI_BT_FEATURE_L2CAP
|
||||
SLI_BT_FEATURE_CONNECTION
|
||||
SLI_BT_FEATURE_CONNECTION_STATISTICS
|
||||
SLI_BT_FEATURE_CONNECTION_SUBRATE
|
||||
SLI_BT_FEATURE_DYNAMIC_GATTDB
|
||||
SLI_BT_FEATURE_CTE_RECEIVER
|
||||
SLI_BT_FEATURE_CTE_TRANSMITTER
|
||||
SLI_BT_FEATURE_TEST
|
||||
SLI_BT_FEATURE_POWER_CONTROL
|
||||
SLI_BT_FEATURE_USER_POWER_CONTROL
|
||||
SLI_BT_FEATURE_GATT
|
||||
SLI_BT_FEATURE_ACCURATE_API_ADDRESS_TYPES
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
/** @brief Table of used BGAPI classes */
|
||||
static const struct sli_bgapi_class * const bt_bgapi_classes[] =
|
||||
{
|
||||
// Invoke the BGAPI class inclusion macro for each feature that provides a
|
||||
// BGAPI class. Depending on the build configuration, the feature inclusion
|
||||
// rules above have defined the macro to either empty or the relevant BGAPI
|
||||
// class declaration.
|
||||
SLI_BT_BGAPI_SYSTEM
|
||||
SLI_BT_BGAPI_NVM
|
||||
SLI_BT_BGAPI_GAP
|
||||
SLI_BT_BGAPI_SM
|
||||
SLI_BT_BGAPI_EXTERNAL_BONDINGDB
|
||||
SLI_BT_BGAPI_ACCEPT_LIST
|
||||
SLI_BT_BGAPI_RESOLVING_LIST
|
||||
SLI_BT_BGAPI_ADVERTISER
|
||||
SLI_BT_BGAPI_LEGACY_ADVERTISER
|
||||
SLI_BT_BGAPI_EXTENDED_ADVERTISER
|
||||
SLI_BT_BGAPI_PERIODIC_ADVERTISER
|
||||
SLI_BT_BGAPI_PAWR_ADVERTISER
|
||||
SLI_BT_BGAPI_SCANNER
|
||||
SLI_BT_BGAPI_SYNC
|
||||
SLI_BT_BGAPI_SYNC_SCANNER
|
||||
SLI_BT_BGAPI_PERIODIC_SYNC
|
||||
SLI_BT_BGAPI_PAWR_SYNC
|
||||
SLI_BT_BGAPI_PAST_RECEIVER
|
||||
SLI_BT_BGAPI_ADVERTISER_PAST
|
||||
SLI_BT_BGAPI_SYNC_PAST
|
||||
SLI_BT_BGAPI_CS
|
||||
SLI_BT_BGAPI_CS_TEST
|
||||
SLI_BT_BGAPI_L2CAP
|
||||
SLI_BT_BGAPI_CONNECTION
|
||||
SLI_BT_BGAPI_GATT
|
||||
SLI_BT_BGAPI_DYNAMIC_GATTDB
|
||||
SLI_BT_BGAPI_GATT_SERVER
|
||||
SLI_BT_BGAPI_CTE_RECEIVER
|
||||
SLI_BT_BGAPI_CTE_TRANSMITTER
|
||||
SLI_BT_BGAPI_TEST
|
||||
SLI_BT_BGAPI_COEX
|
||||
SLI_BT_BGAPI_RESOURCE
|
||||
SLI_BT_BGAPI_CONNECTION_ANALYZER
|
||||
NULL
|
||||
};
|
||||
|
||||
// Forward declaration of Bluetooth controller init functions
|
||||
extern sl_status_t sl_bt_ll_deinit();
|
||||
#include "sl_bt_ll_config.h"
|
||||
extern sl_status_t ll_connPowerControlEnable(const sl_bt_ll_power_control_config_t *);
|
||||
extern void sl_bt_init_app_controlled_tx_power();
|
||||
extern sl_status_t sl_btctrl_init_sniff(uint8_t);
|
||||
extern void sl_btctrl_deinit_sniff(void);
|
||||
#if defined(SL_CATALOG_RAIL_UTIL_COEX_PRESENT)
|
||||
#include "coexistence-ble.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Initialize controller features according to the feature selection.
|
||||
*
|
||||
* This function is called by the Bluetooth host stack when Bluetooth is started.
|
||||
*/
|
||||
sl_status_t sli_bt_init_controller_features()
|
||||
{
|
||||
sl_status_t status = SL_STATUS_OK;
|
||||
|
||||
#if defined(SL_CATALOG_RAIL_UTIL_COEX_PRESENT)
|
||||
sl_bt_init_coex_hal();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_MULTIPROTOCOL_PRESENT)
|
||||
sl_btctrl_init_multiprotocol();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_RADIO_WATCHDOG_PRESENT)
|
||||
sl_btctrl_enable_radio_watchdog();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ADVERTISER_PRESENT)
|
||||
sl_btctrl_init_adv();
|
||||
#endif
|
||||
|
||||
#if defined(SLI_BT_ENABLE_EXTENDED_ADVERTISER_FEATURE)
|
||||
sl_btctrl_init_adv_ext();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SCANNER_PRESENT)
|
||||
sl_btctrl_init_scan();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_EVEN_SCHEDULING_PRESENT)
|
||||
sl_btctrl_enable_even_connsch();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_PAWR_SCHEDULING_PRESENT)
|
||||
sl_btctrl_enable_pawr_connsch();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_PRESENT)
|
||||
sl_btctrl_init_conn();
|
||||
#if !defined(SL_CATALOG_BLUETOOTH_CONNECTION_PHY_UPDATE_INCOMPATIBLE_PRESENT)
|
||||
sl_btctrl_init_phy();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_STATISTICS_PRESENT)
|
||||
sl_btctrl_init_conn_statistics();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_SUBRATING_PRESENT)
|
||||
sl_btctrl_init_subrate();
|
||||
status = sl_btctrl_allocate_conn_subrate_memory(SL_BT_CONFIG_MAX_CONNECTIONS);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_POWER_CONTROL_PRESENT)
|
||||
#include "sl_bt_power_control_config.h"
|
||||
const sl_bt_ll_power_control_config_t power_control_config = {
|
||||
.activate_power_control = SL_BT_ACTIVATE_POWER_CONTROL,
|
||||
.golden_rssi_min_1m = SL_BT_GOLDEN_RSSI_MIN_1M,
|
||||
.golden_rssi_max_1m = SL_BT_GOLDEN_RSSI_MAX_1M,
|
||||
.golden_rssi_min_2m = SL_BT_GOLDEN_RSSI_MIN_2M,
|
||||
.golden_rssi_max_2m = SL_BT_GOLDEN_RSSI_MAX_2M,
|
||||
.golden_rssi_min_coded_s8 = SL_BT_GOLDEN_RSSI_MIN_CODED_S8,
|
||||
.golden_rssi_max_coded_s8 = SL_BT_GOLDEN_RSSI_MAX_CODED_S8,
|
||||
.golden_rssi_min_coded_s2 = SL_BT_GOLDEN_RSSI_MIN_CODED_S2,
|
||||
.golden_rssi_max_coded_s2 = SL_BT_GOLDEN_RSSI_MAX_CODED_S2
|
||||
};
|
||||
|
||||
status = ll_connPowerControlEnable(&power_control_config);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_USER_POWER_CONTROL_PRESENT)
|
||||
sl_bt_init_app_controlled_tx_power();
|
||||
#endif
|
||||
|
||||
#if defined(SLI_BT_ENABLE_EXTENDED_SCANNER_FEATURE)
|
||||
sl_btctrl_init_scan_ext();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PERIODIC_ADVERTISER_PRESENT)
|
||||
#include "sl_bt_periodic_advertiser_config.h"
|
||||
sl_btctrl_init_periodic_adv();
|
||||
sl_btctrl_alloc_periodic_adv(SL_BT_CONFIG_MAX_PERIODIC_ADVERTISERS);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAWR_ADVERTISER_PRESENT)
|
||||
#include "sl_bt_pawr_advertiser_config.h"
|
||||
struct sl_btctrl_pawr_advertiser_config pawr_config = {
|
||||
.max_pawr_sets = SL_BT_CONFIG_MAX_PAWR_ADVERTISERS,
|
||||
.max_advertised_data_length_hint = SL_BT_CONFIG_MAX_PAWR_ADVERTISED_DATA_LENGTH_HINT,
|
||||
.subevent_data_request_count = SL_BT_CONFIG_PAWR_PACKET_REQUEST_COUNT,
|
||||
.subevent_data_request_advance = SL_BT_CONFIG_PAWR_PACKET_REQUEST_ADVANCE,
|
||||
};
|
||||
status = sl_btctrl_pawr_advertiser_configure(&pawr_config);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_PRESENT)
|
||||
#include "sl_bluetooth_periodic_sync_config.h"
|
||||
sl_btctrl_init_periodic_scan();
|
||||
status = sl_btctrl_alloc_periodic_scan(SL_BT_CONFIG_MAX_PERIODIC_ADVERTISING_SYNC);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAWR_SYNC_PRESENT)
|
||||
#include "sl_bt_pawr_sync_config.h"
|
||||
struct sl_btctrl_pawr_synchronizer_config pawr_sync_config = {
|
||||
.max_pawr_sets = SL_BT_CONFIG_MAX_PAWR_SYNCHRONIZERS,
|
||||
};
|
||||
status = sl_btctrl_pawr_synchronizer_configure(&pawr_sync_config);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_RESOLVING_LIST_PRESENT)
|
||||
#include "sl_bt_resolving_list_config.h"
|
||||
sl_btctrl_init_privacy();
|
||||
status = sl_btctrl_allocate_resolving_list_memory(SL_BT_CONFIG_RESOLVING_LIST_SIZE);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_AFH_PRESENT)
|
||||
status = sl_btctrl_init_afh(1);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_HIGH_POWER_PRESENT)
|
||||
sl_btctrl_init_highpower();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PHY_SUPPORT_CONFIG_PRESENT)
|
||||
#include "sl_btctrl_phy_support_config.h"
|
||||
#if SL_BT_CONTROLLER_2M_PHY_SUPPORT == 0
|
||||
sl_btctrl_disable_2m_phy();
|
||||
#endif
|
||||
#if SL_BT_CONTROLLER_CODED_PHY_SUPPORT == 0
|
||||
sl_btctrl_disable_coded_phy();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_AOA_RECEIVER_PRESENT) \
|
||||
|| defined(SL_CATALOG_BLUETOOTH_FEATURE_AOD_RECEIVER_PRESENT)
|
||||
status = sl_btctrl_init_cte_receiver();
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_AOA_TRANSMITTER_PRESENT) \
|
||||
|| defined(SL_CATALOG_BLUETOOTH_FEATURE_AOD_TRANSMITTER_PRESENT)
|
||||
status = sl_btctrl_init_cte_transmitter();
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ADVERTISER_PAST_PRESENT)
|
||||
sl_btctrl_init_past_local_sync_transfer();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_PAST_PRESENT)
|
||||
sl_btctrl_init_past_remote_sync_transfer();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAST_RECEIVER_PRESENT)
|
||||
sl_btctrl_init_past_receiver();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CS_PRESENT)
|
||||
#include "sl_bluetooth_cs_config.h"
|
||||
struct sl_btctrl_cs_config cs_config = { 0 };
|
||||
cs_config.configs_per_connection = SL_BT_CONFIG_MAX_CS_CONFIGS_PER_CONNECTION;
|
||||
cs_config.procedures = SL_BT_CONFIG_MAX_CS_PROCEDURES;
|
||||
sl_btctrl_init_cs(&cs_config);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_ANALYZER_PRESENT)
|
||||
#include "sl_bluetooth_connection_analyzer_config.h"
|
||||
status = sl_btctrl_init_sniff(SL_BT_CONFIG_MAX_CONNECTION_ANALYZERS);
|
||||
if (status != SL_STATUS_OK) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief De-initialize controller features according to the feature selection.
|
||||
*
|
||||
* This function is called by the Bluetooth host stack when Bluetooth is stopped.
|
||||
*/
|
||||
void sli_bt_deinit_controller_features()
|
||||
{
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_ANALYZER_PRESENT)
|
||||
sl_btctrl_deinit_sniff();
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_RESOLVING_LIST_PRESENT)
|
||||
sl_btctrl_allocate_resolving_list_memory(0);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_PRESENT)
|
||||
sl_btctrl_alloc_periodic_scan(0);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAWR_ADVERTISER_PRESENT)
|
||||
struct sl_btctrl_pawr_advertiser_config pawr_config = {
|
||||
.max_pawr_sets = 0,
|
||||
.max_advertised_data_length_hint = 0,
|
||||
.subevent_data_request_count = 0,
|
||||
.subevent_data_request_advance = 0,
|
||||
};
|
||||
(void) sl_btctrl_pawr_advertiser_configure(&pawr_config);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAWR_SYNC_PRESENT)
|
||||
struct sl_btctrl_pawr_synchronizer_config pawr_sync_config = {
|
||||
.max_pawr_sets = 0,
|
||||
};
|
||||
(void) sl_btctrl_pawr_synchronizer_configure(&pawr_sync_config);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PERIODIC_ADVERTISER_PRESENT)
|
||||
(void) sl_btctrl_alloc_periodic_adv(0);
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_SUBRATING_PRESENT)
|
||||
sl_btctrl_allocate_conn_subrate_memory(0);
|
||||
#endif
|
||||
|
||||
(void) sl_bt_ll_deinit();
|
||||
}
|
||||
|
||||
// Initialize the Bluetooth stack.
|
||||
sl_status_t sl_bt_stack_init()
|
||||
{
|
||||
// Initialize the Bluetooth stack with the given configuration, features, and BGAPI classes
|
||||
return sli_bt_init_stack(&bt_config, bt_used_features, bt_bgapi_classes);
|
||||
}
|
||||
28
Libs/protocol/bluetooth/src/sli_bt_accept_list_config.c
Normal file
28
Libs/protocol/bluetooth/src/sli_bt_accept_list_config.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_accept_list_config.c
|
||||
* @brief Configuration instance for "accept_list"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_accept_list_config.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ACCEPT_LIST_PRESENT)
|
||||
#include "sl_bt_accept_list_config.h"
|
||||
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, accept_list, sli_bt_accept_list_config_t) = {
|
||||
.accept_list_size = SL_BT_CONFIG_ACCEPT_LIST_SIZE
|
||||
};
|
||||
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_ACCEPT_LIST_PRESENT
|
||||
33
Libs/protocol/bluetooth/src/sli_bt_advertiser_config.c
Normal file
33
Libs/protocol/bluetooth/src/sli_bt_advertiser_config.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_advertiser_config.c
|
||||
* @brief Configuration instance for "advertiser"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_advertiser_config.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_ADVERTISER_PRESENT)
|
||||
#include "sl_bluetooth.h" // For SL_BT_COMPONENT_ADVERTISERS
|
||||
#include "sl_bluetooth_config.h"
|
||||
|
||||
// Note that advertiser configuration is not dictated directly by the advertiser
|
||||
// component's configuration file. The top-level Bluetooth stack configuration
|
||||
// calculates a sum of all advertiser needs, and that value is used to configure
|
||||
// the advertiser feature.
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, advertiser, sli_bt_advertiser_config_t) = {
|
||||
.max_advertisers = SL_BT_CONFIG_MAX_ADVERTISERS
|
||||
};
|
||||
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_ADVERTISER_PRESENT
|
||||
35
Libs/protocol/bluetooth/src/sli_bt_connection_config.c
Normal file
35
Libs/protocol/bluetooth/src/sli_bt_connection_config.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_connection_config.c
|
||||
* @brief Configuration instanc for "connection"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_connection_config.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_PRESENT)
|
||||
#include "sl_bluetooth.h" // For SL_BT_COMPONENT_CONNECTIONS
|
||||
#include "sl_bluetooth_config.h"
|
||||
#include "sl_bluetooth_connection_config.h"
|
||||
|
||||
// Note that connection configuration is not dictated directly by the connection
|
||||
// component's configuration file. The top-level Bluetooth stack configuration
|
||||
// calculates a sum of all connection needs, and that value is used to configure
|
||||
// the connection feature.
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, connection, sli_bt_connection_config_t) = {
|
||||
.max_connections = SL_BT_CONFIG_MAX_CONNECTIONS_SUM,
|
||||
.data_len = SL_BT_CONFIG_CONNECTION_DATA_LENGTH
|
||||
};
|
||||
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_CONNECTION_PRESENT
|
||||
41
Libs/protocol/bluetooth/src/sli_bt_dynamic_gattdb_config.c
Normal file
41
Libs/protocol/bluetooth/src/sli_bt_dynamic_gattdb_config.c
Normal file
@@ -0,0 +1,41 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_dynamic_gattdb_config.c
|
||||
* @brief Configuration instance for "dynamic_gattdb"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b> Copyright 2021 Silicon Laboratories Inc.www.silabs.com </b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement(MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_config_defs.h"
|
||||
#include "sli_bt_gattdb_def.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_DYNAMIC_GATTDB_PRESENT)
|
||||
#include "sl_bt_dynamic_gattdb_config.h"
|
||||
#if SL_BT_GATTDB_ENABLE_GATT_CACHING == 1
|
||||
#define GATTDB_ENABLE_GATT_CACHING SLI_BT_GATTDB_CONFIG_FLAG_ENABLE_GATT_CACHING
|
||||
#else
|
||||
#define GATTDB_ENABLE_GATT_CACHING 0
|
||||
#endif
|
||||
#if SL_BT_GATTDB_INCLUDE_STATIC_DATABASE == 1
|
||||
#define GATTDB_INCLUDE_STATIC SLI_BT_GATTDB_CONFIG_FLAG_INCLUDE_STATIC_DB
|
||||
#else
|
||||
#define GATTDB_INCLUDE_STATIC 0
|
||||
#endif
|
||||
#else // SL_CATALOG_BLUETOOTH_FEATURE_DYNAMIC_GATTDB_PRESENT
|
||||
#define GATTDB_ENABLE_GATT_CACHING SLI_BT_GATTDB_CONFIG_FLAG_ENABLE_GATT_CACHING
|
||||
#define GATTDB_INCLUDE_STATIC SLI_BT_GATTDB_CONFIG_FLAG_INCLUDE_STATIC_DB
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_DYNAMIC_GATTDB_PRESENT
|
||||
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, dynamic_gattdb, sli_bt_gattdb_config_t) = {
|
||||
.flags = (GATTDB_ENABLE_GATT_CACHING | GATTDB_INCLUDE_STATIC)
|
||||
};
|
||||
278
Libs/protocol/bluetooth/src/sli_bt_host_adaptation.c
Normal file
278
Libs/protocol/bluetooth/src/sli_bt_host_adaptation.c
Normal file
@@ -0,0 +1,278 @@
|
||||
/***************************************************************************//**
|
||||
* @brief System adaptation layer used internally by Bluetooth host stack
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2023 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sli_bt_host_adaptation.h"
|
||||
#include "sl_bluetooth_config.h"
|
||||
#include "sl_bt_host_adaptation_config.h"
|
||||
#include "sl_bt_api.h"
|
||||
#include "sl_assert.h"
|
||||
#include "sl_core.h"
|
||||
#include "em_device.h"
|
||||
#include "sl_component_catalog.h"
|
||||
#if defined(SL_CATALOG_GECKO_BOOTLOADER_INTERFACE_PRESENT)
|
||||
#include "btl_interface.h"
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT)
|
||||
#include "sl_bt_rtos_adaptation.h"
|
||||
|
||||
// When a kernel is present, the task wakeups are handled by RTOS adaptation
|
||||
sli_bt_linklayer_wakeup_t *const sli_bt_host_adaptation_linklayer_wakeup = sli_bt_rtos_ll_callback;
|
||||
sli_bt_host_wakeup_t *const sli_bt_host_adaptation_host_wakeup = sli_bt_rtos_stack_callback;
|
||||
|
||||
#else // defined(SL_CATALOG_KERNEL_PRESENT)
|
||||
|
||||
// When a kernel is not present, the host task wakeup is not needed, as the
|
||||
// baremetal main loop will service the host stack. The linklayer task is
|
||||
// handled as a PendSV interrupt.
|
||||
|
||||
/**
|
||||
* Override @ref PendSV_Handler for the Link Layer task when Bluetooth runs
|
||||
* in baremetal mode. The override must not exist when Bluetooth runs in an RTOS
|
||||
* where the link layer task runs in a thread.
|
||||
*/
|
||||
void PendSV_Handler()
|
||||
{
|
||||
sl_bt_priority_handle();
|
||||
}
|
||||
|
||||
static void sli_bt_trigger_pendsv_interrupt(void)
|
||||
{
|
||||
// Trigger the PendSV interrupt
|
||||
SCB->ICSR = SCB_ICSR_PENDSVSET_Msk;
|
||||
}
|
||||
|
||||
sli_bt_linklayer_wakeup_t *const sli_bt_host_adaptation_linklayer_wakeup = sli_bt_trigger_pendsv_interrupt;
|
||||
sli_bt_host_wakeup_t *const sli_bt_host_adaptation_host_wakeup = NULL;
|
||||
|
||||
#endif // defined(SL_CATALOG_KERNEL_PRESENT)
|
||||
|
||||
// Initialize the device interrupts in a baremetal app
|
||||
void sli_bt_host_adaptation_init_interrupts(void)
|
||||
{
|
||||
// The Bluetooth host stack system adaptation initializates the interrupt
|
||||
// configuration only when an RTOS kernel is not present in the application,
|
||||
// i.e. when the application is a baremetal application. When an RTOS is
|
||||
// present, the interrupts are configured by the RTOS.
|
||||
#if !defined(SL_CATALOG_KERNEL_PRESENT)
|
||||
|
||||
// Perform a compile-time validity check for the configuration. If BASEPRI is
|
||||
// used as the method for atomic sections, the atomic level must be higher
|
||||
// than or equal to the priority of the radio and link layer interrupts to
|
||||
// ensure proper atomic sections in the Bluetooth stack. A lower number means
|
||||
// higher priority.
|
||||
#if (CORE_ATOMIC_METHOD == CORE_ATOMIC_METHOD_BASEPRI)
|
||||
#if (CORE_ATOMIC_BASE_PRIORITY_LEVEL > SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY)
|
||||
#error Bluetooth EFR32 HAL: Invalid configuration CORE_ATOMIC_BASE_PRIORITY_LEVEL > SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY
|
||||
#endif
|
||||
#if (CORE_ATOMIC_BASE_PRIORITY_LEVEL > SL_BT_HOST_ADAPTATION_LINKLAYER_IRQ_PRIORITY)
|
||||
#error Bluetooth EFR32 HAL: Invalid configuration CORE_ATOMIC_BASE_PRIORITY_LEVEL > SL_BT_HOST_ADAPTATION_LINKLAYER_IRQ_PRIORITY
|
||||
#endif
|
||||
#endif // (CORE_ATOMIC_METHOD == CORE_ATOMIC_METHOD_BASEPRI)
|
||||
|
||||
// Set the priorities to the NVIC
|
||||
NVIC_SetPriority(FRC_PRI_IRQn, SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY);
|
||||
NVIC_SetPriority(FRC_IRQn, SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY);
|
||||
NVIC_SetPriority(MODEM_IRQn, SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY);
|
||||
NVIC_SetPriority(RAC_SEQ_IRQn, SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY);
|
||||
NVIC_SetPriority(RAC_RSM_IRQn, SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY);
|
||||
NVIC_SetPriority(BUFC_IRQn, SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY);
|
||||
NVIC_SetPriority(PROTIMER_IRQn, SL_BT_HOST_ADAPTATION_RADIO_IRQ_PRIORITY);
|
||||
NVIC_SetPriority(PendSV_IRQn, SL_BT_HOST_ADAPTATION_LINKLAYER_IRQ_PRIORITY);
|
||||
|
||||
// Clear the PendSV interrupt
|
||||
NVIC_ClearPendingIRQ(PendSV_IRQn);
|
||||
|
||||
#endif // !defined(SL_CATALOG_KERNEL_PRESENT)
|
||||
}
|
||||
|
||||
// Get the bootloader version information
|
||||
sl_status_t sli_bt_host_adaptation_get_bootloader_version(uint32_t *bootloader_version)
|
||||
{
|
||||
EFM_ASSERT(bootloader_version != NULL);
|
||||
|
||||
#if defined(SL_CATALOG_GECKO_BOOTLOADER_INTERFACE_PRESENT)
|
||||
// Bootloader is available. Query the version from there.
|
||||
BootloaderInformation_t btl_info;
|
||||
memset(&btl_info, 0, sizeof(btl_info));
|
||||
bootloader_getInfo(&btl_info);
|
||||
*bootloader_version = btl_info.version;
|
||||
return SL_STATUS_OK;
|
||||
#else // SL_CATALOG_GECKO_BOOTLOADER_INTERFACE_PRESENT
|
||||
// Bootloader is not available
|
||||
*bootloader_version = 0;
|
||||
return SL_STATUS_NOT_AVAILABLE;
|
||||
#endif // SL_CATALOG_GECKO_BOOTLOADER_INTERFACE_PRESENT
|
||||
}
|
||||
|
||||
// Reset the chip
|
||||
void sli_bt_host_adaptation_chip_reset(void)
|
||||
{
|
||||
CORE_ResetSystem();
|
||||
}
|
||||
|
||||
#if defined(SL_CATALOG_NVM3_PRESENT)
|
||||
#include "nvm3_generic.h"
|
||||
#include "nvm3_default.h"
|
||||
|
||||
/**
|
||||
* @brief NVM3 handle used for NVM3 in the Bluetooth host stack
|
||||
*/
|
||||
#define SL_BT_NVM3 (nvm3_defaultHandle)
|
||||
|
||||
/**
|
||||
* @brief NVM3 key for custom Bluetooth address type. Value 1 byte: 0 for public type, 1 for static
|
||||
*/
|
||||
#define SLI_BT_NVM3_LOCAL_BD_ADDR_TYPE 0x4003c
|
||||
|
||||
/**
|
||||
* @brief NVM3 key for custom Bluetooth address. Value: 6 bytes in little endian
|
||||
*/
|
||||
#define SLI_BT_NVM3_LOCAL_BD_ADDR 0x4002c
|
||||
|
||||
/**
|
||||
* @brief Length of a Bluetooth address
|
||||
*/
|
||||
#define SLI_BT_BD_ADDRESS_LEN 6
|
||||
|
||||
sl_status_t sli_bt_host_adaptation_write_custom_address(uint8_t address_type,
|
||||
const uint8_t *address)
|
||||
{
|
||||
if ((address_type != sl_bt_gap_public_address)
|
||||
&& (address_type != sl_bt_gap_static_address)) {
|
||||
return SL_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
sl_status_t result = nvm3_open(SL_BT_NVM3, nvm3_defaultInit);
|
||||
if (result != SL_STATUS_OK) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff is used to reset the custom address.
|
||||
// Delete the NVM3 keys and the default address will be used in the next reboot.
|
||||
uint8_t all_bit_1_address[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
|
||||
uint8_t all_bit_0_address[SLI_BT_BD_ADDRESS_LEN] = { 0x00 };
|
||||
if ((memcmp(address, all_bit_1_address, SLI_BT_BD_ADDRESS_LEN) == 0)
|
||||
|| (memcmp(address, all_bit_0_address, SLI_BT_BD_ADDRESS_LEN) == 0)) {
|
||||
result = nvm3_deleteObject(SL_BT_NVM3, SLI_BT_NVM3_LOCAL_BD_ADDR_TYPE);
|
||||
if ((result == SL_STATUS_OK) || (result == SL_STATUS_NOT_FOUND)) {
|
||||
result = nvm3_deleteObject(SL_BT_NVM3, SLI_BT_NVM3_LOCAL_BD_ADDR);
|
||||
}
|
||||
if (result == SL_STATUS_NOT_FOUND) {
|
||||
result = SL_STATUS_OK;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// A static device address needs set two MSB bits to 1
|
||||
if (address_type == sl_bt_gap_static_address && (address[5] >> 6) != 3) {
|
||||
return SL_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (address_type == sl_bt_gap_public_address) {
|
||||
result = nvm3_deleteObject(SL_BT_NVM3, SLI_BT_NVM3_LOCAL_BD_ADDR_TYPE);
|
||||
if (result == SL_STATUS_NOT_FOUND) {
|
||||
result = SL_STATUS_OK;
|
||||
}
|
||||
} else {
|
||||
result = nvm3_writeData(SL_BT_NVM3,
|
||||
SLI_BT_NVM3_LOCAL_BD_ADDR_TYPE,
|
||||
(void*) &address_type,
|
||||
sizeof(address_type));
|
||||
}
|
||||
|
||||
if (result == SL_STATUS_OK) {
|
||||
result = nvm3_writeData(SL_BT_NVM3,
|
||||
SLI_BT_NVM3_LOCAL_BD_ADDR,
|
||||
(void*) address,
|
||||
SLI_BT_BD_ADDRESS_LEN);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#else
|
||||
sl_status_t sli_bt_host_adaptation_write_custom_address(uint8_t address_type,
|
||||
const uint8_t *address)
|
||||
{
|
||||
(void) address_type;
|
||||
(void) address;
|
||||
// The user application does not use NVM3
|
||||
return SL_STATUS_NOT_AVAILABLE;
|
||||
}
|
||||
#endif // SL_CATALOG_NVM3_PRESENT
|
||||
|
||||
// Load custom Bluetooth identity address from NVM3
|
||||
sl_status_t sli_bt_host_adaptation_read_custom_address(uint8_t *address_type,
|
||||
uint8_t *address)
|
||||
{
|
||||
#if (SL_BT_CONFIG_SET_CUSTOM_ADDRESS_FROM_NVM3 == 1) && defined(SL_CATALOG_NVM3_PRESENT)
|
||||
if (!address_type || !address) {
|
||||
return SL_STATUS_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
sl_status_t result = nvm3_open(SL_BT_NVM3, nvm3_defaultInit);
|
||||
|
||||
if (result == SL_STATUS_OK) {
|
||||
// Read the address in NVM3
|
||||
result = nvm3_readData(SL_BT_NVM3, SLI_BT_NVM3_LOCAL_BD_ADDR, address, SLI_BT_BD_ADDRESS_LEN);
|
||||
}
|
||||
|
||||
if (result == SL_STATUS_OK) {
|
||||
// Read the address type in NVM3. Treat the address as public device address if error
|
||||
sl_status_t read_type_result = nvm3_readData(SL_BT_NVM3, SLI_BT_NVM3_LOCAL_BD_ADDR_TYPE, address_type, sizeof(*address_type));
|
||||
if (read_type_result != SL_STATUS_OK) {
|
||||
*address_type = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
#else
|
||||
// The user application does not use custom address, or NVM3 does not present
|
||||
(void) address_type;
|
||||
(void) address;
|
||||
return SL_STATUS_NOT_FOUND;
|
||||
#endif // (SL_BT_CONFIG_SET_CUSTOM_ADDRESS_FROM_NVM3 == 1) && defined(SL_CATALOG_NVM3_PRESENT)
|
||||
}
|
||||
|
||||
#if (SL_BT_CONFIG_SET_CTUNE_FROM_NVM3 == 1) && defined(SL_CATALOG_NVM3_PRESENT)
|
||||
#include "em_cmu.h"
|
||||
|
||||
/**
|
||||
* @brief NVM3 key for custom CTUNE in Bluetooth NVM3 space. Value 2 bytes
|
||||
*/
|
||||
#define SLI_BT_NVM3_CTUNE 0x40032
|
||||
|
||||
// Set HFXO CTUNE using the value stored in the Bluetooth space of NVM3.
|
||||
void sli_bt_host_adaptation_read_and_set_ctune()
|
||||
{
|
||||
uint16_t ctune;
|
||||
sl_status_t err = nvm3_open(SL_BT_NVM3, nvm3_defaultInit);
|
||||
if (err == SL_STATUS_OK) {
|
||||
err = nvm3_readData(SL_BT_NVM3, SLI_BT_NVM3_CTUNE, &ctune, sizeof(ctune));
|
||||
}
|
||||
if (err == SL_STATUS_OK) {
|
||||
// Setting CTUNE could fail and we do it with best effort. Please find CTUNE and
|
||||
// its calibration related details in the platform.
|
||||
err = CMU_HFXOCTuneSet(ctune);
|
||||
(void) err;
|
||||
}
|
||||
}
|
||||
#else
|
||||
void sli_bt_host_adaptation_read_and_set_ctune()
|
||||
{
|
||||
// Feature is disabled. Do nothing.
|
||||
}
|
||||
#endif // #if (SL_BT_CONFIG_SET_CTUNE_FROM_NVM3 == 1) && defined(SL_CATALOG_NVM3_PRESENT)
|
||||
35
Libs/protocol/bluetooth/src/sli_bt_l2cap_config.c
Normal file
35
Libs/protocol/bluetooth/src/sli_bt_l2cap_config.c
Normal file
@@ -0,0 +1,35 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_l2cap_config.c
|
||||
* @brief Configuration instance for "l2cap"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_l2cap_config.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_L2CAP_PRESENT)
|
||||
#include "sl_bluetooth_l2cap_config.h"
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_EATT)
|
||||
// Each Enhanced ATT bearer requires an L2CAP COC channel
|
||||
#include "sl_bt_eatt_config.h"
|
||||
#define SL_BT_CONFIG_MAX_L2CAP_CHANNELS (SL_BT_CONFIG_USER_L2CAP_COC_CHANNELS + SL_BT_CONFIG_USER_EATT_BEARERS)
|
||||
#else
|
||||
#define SL_BT_CONFIG_MAX_L2CAP_CHANNELS SL_BT_CONFIG_USER_L2CAP_COC_CHANNELS
|
||||
#endif
|
||||
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, l2cap, sli_bt_l2cap_config_t) = {
|
||||
.max_l2cap_coc_channels = SL_BT_CONFIG_MAX_L2CAP_CHANNELS
|
||||
};
|
||||
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_L2CAP_PRESENT
|
||||
28
Libs/protocol/bluetooth/src/sli_bt_pawr_advertiser_config.c
Normal file
28
Libs/protocol/bluetooth/src/sli_bt_pawr_advertiser_config.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_pawr_advertiser_config.c
|
||||
* @brief Configuration instance for "pawr_advertiser"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_pawr_advertiser_config.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PAWR_ADVERTISER_PRESENT)
|
||||
#include "sl_bt_pawr_advertiser_config.h"
|
||||
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, pawr_advertiser, sli_bt_pawr_advertiser_config_t) = {
|
||||
.max_pawr_advertisers = SL_BT_CONFIG_MAX_PAWR_ADVERTISERS
|
||||
};
|
||||
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_PAWR_ADVERTISER_PRESENT
|
||||
@@ -0,0 +1,28 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_periodic_advertiser_config.c
|
||||
* @brief Configuration instance for "periodic_advertiser"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_periodic_advertiser_config.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_PERIODIC_ADVERTISER_PRESENT)
|
||||
#include "sl_bt_periodic_advertiser_config.h"
|
||||
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, periodic_advertiser, sli_bt_periodic_advertiser_config_t) = {
|
||||
.max_periodic_advertisers = SL_BT_CONFIG_MAX_PERIODIC_ADVERTISERS
|
||||
};
|
||||
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_PERIODIC_ADVERTISER_PRESENT
|
||||
28
Libs/protocol/bluetooth/src/sli_bt_sync_config.c
Normal file
28
Libs/protocol/bluetooth/src/sli_bt_sync_config.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/***************************************************************************//**
|
||||
* @file sli_bt_sync_config.c
|
||||
* @brief Configuration instance for "sync"
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2021 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc. Your use of this
|
||||
* software is governed by the terms of Silicon Labs Master Software License
|
||||
* Agreement (MSLA) available at
|
||||
* www.silabs.com/about-us/legal/master-software-license-agreement. This
|
||||
* software is distributed to you in Source Code format and is governed by the
|
||||
* sections of the MSLA applicable to Source Code.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_component_catalog.h"
|
||||
#include "sli_bt_sync_config.h"
|
||||
|
||||
#if defined(SL_CATALOG_BLUETOOTH_FEATURE_SYNC_PRESENT)
|
||||
#include "sl_bluetooth_periodic_sync_config.h"
|
||||
|
||||
SLI_BT_DEFINE_FEATURE_CONFIG(bt, sync, sli_bt_sync_config_t) = {
|
||||
.max_periodic_syncs = SL_BT_CONFIG_MAX_PERIODIC_ADVERTISING_SYNC
|
||||
};
|
||||
|
||||
#endif // SL_CATALOG_BLUETOOTH_FEATURE_SYNC_PRESENT
|
||||
Reference in New Issue
Block a user