update nimble library to version 1.40

This commit is contained in:
technyon
2022-09-25 21:17:09 +02:00
parent 416feee527
commit f6bdf4ce9d
54 changed files with 3880 additions and 374 deletions

View File

@@ -22,11 +22,11 @@
#include "NimBLE2904.h"
NimBLE2904::NimBLE2904(NimBLECharacteristic* pCharacterisitic)
NimBLE2904::NimBLE2904(NimBLECharacteristic* pCharacteristic)
: NimBLEDescriptor(NimBLEUUID((uint16_t) 0x2904),
BLE_GATT_CHR_F_READ,
sizeof(BLE2904_Data),
pCharacterisitic)
pCharacteristic)
{
m_data.m_format = 0;
m_data.m_exponent = 0;

View File

@@ -156,7 +156,7 @@ std::string NimBLEAddress::toString() const {
/**
* @brief Convienience operator to check if this address is equal to another.
* @brief Convenience operator to check if this address is equal to another.
*/
bool NimBLEAddress::operator ==(const NimBLEAddress & rhs) const {
return memcmp(rhs.m_address, m_address, sizeof m_address) == 0;
@@ -164,7 +164,7 @@ bool NimBLEAddress::operator ==(const NimBLEAddress & rhs) const {
/**
* @brief Convienience operator to check if this address is not equal to another.
* @brief Convenience operator to check if this address is not equal to another.
*/
bool NimBLEAddress::operator !=(const NimBLEAddress & rhs) const {
return !this->operator==(rhs);
@@ -186,7 +186,7 @@ NimBLEAddress::operator std::string() const {
/**
* @brief Convienience operator to convert the native address representation to uint_64.
* @brief Convenience operator to convert the native address representation to uint_64.
*/
NimBLEAddress::operator uint64_t() const {
uint64_t address = 0;

View File

@@ -52,9 +52,9 @@ NimBLEAddress NimBLEAdvertisedDevice::getAddress() {
* @brief Get the advertisement type.
* @return The advertising type the device is reporting:
* * BLE_HCI_ADV_TYPE_ADV_IND (0) - indirect advertising
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) - direct advertisng - high duty cycle
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_HD (1) - direct advertising - high duty cycle
* * BLE_HCI_ADV_TYPE_ADV_SCAN_IND (2) - indirect scan response
* * BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) - indirect advertisng - not connectable
* * BLE_HCI_ADV_TYPE_ADV_NONCONN_IND (3) - indirect advertising - not connectable
* * BLE_HCI_ADV_TYPE_ADV_DIRECT_IND_LD (4) - direct advertising - low duty cycle
*/
uint8_t NimBLEAdvertisedDevice::getAdvType() {
@@ -66,7 +66,7 @@ uint8_t NimBLEAdvertisedDevice::getAdvType() {
* @brief Get the appearance.
*
* A %BLE device can declare its own appearance. The appearance is how it would like to be shown to an end user
* typcially in the form of an icon.
* typically in the form of an icon.
*
* @return The appearance of the advertised device.
*/
@@ -308,7 +308,7 @@ std::string NimBLEAdvertisedDevice::getServiceData(const NimBLEUUID &uuid) {
/**
* @brief Get the UUID of the serice data at the index.
* @brief Get the UUID of the service data at the index.
* @param [in] index The index of the service data UUID requested.
* @return The advertised service data UUID or an empty UUID if not found.
*/
@@ -448,7 +448,7 @@ uint8_t NimBLEAdvertisedDevice::getServiceUUIDCount() {
/**
* @brief Check advertised services for existance of the required UUID
* @brief Check advertised services for existence of the required UUID
* @param [in] uuid The service uuid to look for in the advertisement.
* @return Return true if service is advertised
*/
@@ -794,7 +794,7 @@ void NimBLEAdvertisedDevice::setPayload(const uint8_t *payload, uint8_t length,
/**
* @brief Get the length of the advertisement data in the payload.
* @return The number of bytes in the payload that is from the advertisment.
* @return The number of bytes in the payload that is from the advertisement.
*/
uint8_t NimBLEAdvertisedDevice::getAdvLength() {
return m_advLength;

View File

@@ -434,15 +434,16 @@ bool NimBLEAdvertising::start(uint32_t duration, void (*advCompleteCB)(NimBLEAdv
if(m_advParams.conn_mode == BLE_GAP_CONN_MODE_NON) {
if(!m_scanResp) {
m_advParams.disc_mode = BLE_GAP_DISC_MODE_NON;
m_advData.flags = BLE_HS_ADV_F_BREDR_UNSUP;
// non-connectable advertising does not require AD flags.
m_advData.flags = 0;
}
}
int rc = 0;
if (!m_customAdvData && !m_advDataSet) {
//start with 3 bytes for the flags data
uint8_t payloadLen = (2 + 1);
//start with 3 bytes for the flags data if required
uint8_t payloadLen = (m_advData.flags > 0) ? (2 + 1) : 0;
if(m_advData.mfg_data_len > 0)
payloadLen += (2 + m_advData.mfg_data_len);
@@ -757,7 +758,7 @@ int NimBLEAdvertising::handleGapEvent(struct ble_gap_event *event, void *arg) {
*/
void NimBLEAdvertisementData::addData(const std::string &data) {
if ((m_payload.length() + data.length()) > BLE_HS_ADV_MAX_SZ) {
NIMBLE_LOGE(LOG_TAG, "Advertisement data length exceded");
NIMBLE_LOGE(LOG_TAG, "Advertisement data length exceeded");
return;
}
m_payload.append(data);

View File

@@ -54,7 +54,7 @@ struct Has_c_str_len<T, decltype(void(std::declval<T &>().c_str())),
/**
* @brief A specialized container class to hold BLE attribute values.
* @details This class is designed to be more memory efficient than using\n
* standard container types for value storage, while being convertable to\n
* standard container types for value storage, while being convertible to\n
* many different container classes.
*/
class NimBLEAttValue

View File

@@ -130,7 +130,7 @@ void NimBLEBeacon::setManufacturerId(uint16_t manufacturerId) {
*/
void NimBLEBeacon::setMinor(uint16_t minor) {
m_beaconData.minor = ENDIAN_CHANGE_U16(minor);
} // setMinior
} // setMinor
/**

View File

@@ -126,8 +126,8 @@ void NimBLECharacteristic::addDescriptor(NimBLEDescriptor *pDescriptor) {
/**
* @brief Remove a descriptor from the characterisitc.
* @param[in] pDescriptor A pointer to the descriptor instance to remove from the characterisitc.
* @brief Remove a descriptor from the characteristic.
* @param[in] pDescriptor A pointer to the descriptor instance to remove from the characteristic.
* @param[in] deleteDsc If true it will delete the descriptor instance and free it's resources.
*/
void NimBLECharacteristic::removeDescriptor(NimBLEDescriptor *pDescriptor, bool deleteDsc) {
@@ -273,11 +273,13 @@ int NimBLECharacteristic::handleGapEvent(uint16_t conn_handle, uint16_t attr_han
if(ble_uuid_cmp(uuid, &pCharacteristic->getUUID().getNative()->u) == 0){
switch(ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_CHR: {
// If the packet header is only 8 bytes this is a follow up of a long read
// so we don't want to call the onRead() callback again.
if(ctxt->om->om_pkthdr_len > 8) {
rc = ble_gap_conn_find(conn_handle, &desc);
assert(rc == 0);
rc = ble_gap_conn_find(conn_handle, &desc);
assert(rc == 0);
// If the packet header is only 8 bytes this is a follow up of a long read
// so we don't want to call the onRead() callback again.
if(ctxt->om->om_pkthdr_len > 8 ||
pCharacteristic->m_value.size() <= (ble_att_mtu(desc.conn_handle) - 3)) {
pCharacteristic->m_pCallbacks->onRead(pCharacteristic);
pCharacteristic->m_pCallbacks->onRead(pCharacteristic, &desc);
}
@@ -440,7 +442,7 @@ void NimBLECharacteristic::notify(const uint8_t* value, size_t length, bool is_n
!(m_properties & NIMBLE_PROPERTY::INDICATE))
{
NIMBLE_LOGE(LOG_TAG,
"<< notify-Error; Notify/indicate not enabled for characterisitc: %s",
"<< notify-Error; Notify/indicate not enabled for characteristic: %s",
std::string(getUUID()).c_str());
}

View File

@@ -157,35 +157,35 @@ size_t NimBLEClient::deleteService(const NimBLEUUID &uuid) {
/**
* @brief Connect to the BLE Server.
* @param [in] deleteAttibutes If true this will delete any attribute objects this client may already\n
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
* have created and clears the vectors after successful connection.
* @return True on success.
*/
bool NimBLEClient::connect(bool deleteAttibutes) {
return connect(m_peerAddress, deleteAttibutes);
bool NimBLEClient::connect(bool deleteAttributes) {
return connect(m_peerAddress, deleteAttributes);
}
/**
* @brief Connect to an advertising device.
* @param [in] device The device to connect to.
* @param [in] deleteAttibutes If true this will delete any attribute objects this client may already\n
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
* have created and clears the vectors after successful connection.
* @return True on success.
*/
bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes) {
bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttributes) {
NimBLEAddress address(device->getAddress());
return connect(address, deleteAttibutes);
return connect(address, deleteAttributes);
}
/**
* @brief Connect to the BLE Server.
* @param [in] address The address of the server.
* @param [in] deleteAttibutes If true this will delete any attribute objects this client may already\n
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
* have created and clears the vectors after successful connection.
* @return True on success.
*/
bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttributes) {
NIMBLE_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str());
if(!NimBLEDevice::m_synced) {
@@ -259,7 +259,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
break;
case BLE_HS_EALREADY:
// Already attemting to connect to this device, cancel the previous
// Already attempting to connect to this device, cancel the previous
// attempt and report failure here so we don't get 2 connections.
NIMBLE_LOGE(LOG_TAG, "Already attempting to connect to %s - cancelling",
std::string(m_peerAddress).c_str());
@@ -317,7 +317,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
NIMBLE_LOGI(LOG_TAG, "Connection established");
}
if(deleteAttibutes) {
if(deleteAttributes) {
deleteServices();
}
@@ -390,8 +390,8 @@ int NimBLEClient::disconnect(uint8_t reason) {
// We use a timer to detect a controller error in the event that it does
// not inform the stack when disconnection is complete.
// This is a common error in certain esp-idf versions.
// The disconnect timeout time is the supervison timeout time + 1 second.
// In the case that the event happenss shortly after the supervision timeout
// The disconnect timeout time is the supervision timeout time + 1 second.
// In the case that the event happens shortly after the supervision timeout
// we don't want to prematurely reset the host.
ble_npl_time_t ticks;
ble_npl_time_ms_to_ticks((desc.supervision_timeout + 100) * 10, &ticks);
@@ -431,7 +431,7 @@ void NimBLEClient::setConnectPhy(uint8_t mask) {
/**
* @brief Set the connection paramaters to use when connecting to a server.
* @brief Set the connection parameters to use when connecting to a server.
* @param [in] minInterval The minimum connection interval in 1.25ms units.
* @param [in] maxInterval The maximum connection interval in 1.25ms units.
* @param [in] latency The number of packets allowed to skip (extends max interval).

View File

@@ -38,9 +38,9 @@ class NimBLEAdvertisedDevice;
*/
class NimBLEClient {
public:
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes = true);
bool connect(const NimBLEAddress &address, bool deleteAttibutes = true);
bool connect(bool deleteAttibutes = true);
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttributes = true);
bool connect(const NimBLEAddress &address, bool deleteAttributes = true);
bool connect(bool deleteAttributes = true);
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
NimBLEAddress getPeerAddress();
void setPeerAddress(const NimBLEAddress &address);
@@ -137,7 +137,7 @@ public:
* @brief Called when server requests to update the connection parameters.
* @param [in] pClient A pointer to the calling client object.
* @param [in] params A pointer to the struct containing the connection parameters requested.
* @return True to accept the parmeters.
* @return True to accept the parameters.
*/
virtual bool onConnParamsUpdateRequest(NimBLEClient* pClient, const ble_gap_upd_params* params);

View File

@@ -155,6 +155,7 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
const ble_uuid_t *uuid;
int rc;
struct ble_gap_conn_desc desc;
NimBLEDescriptor* pDescriptor = (NimBLEDescriptor*)arg;
NIMBLE_LOGD(LOG_TAG, "Descriptor %s %s event", pDescriptor->getUUID().toString().c_str(),
@@ -164,9 +165,13 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle,
if(ble_uuid_cmp(uuid, &pDescriptor->getUUID().getNative()->u) == 0){
switch(ctxt->op) {
case BLE_GATT_ACCESS_OP_READ_DSC: {
// If the packet header is only 8 bytes this is a follow up of a long read
// so we don't want to call the onRead() callback again.
if(ctxt->om->om_pkthdr_len > 8) {
rc = ble_gap_conn_find(conn_handle, &desc);
assert(rc == 0);
// If the packet header is only 8 bytes this is a follow up of a long read
// so we don't want to call the onRead() callback again.
if(ctxt->om->om_pkthdr_len > 8 ||
pDescriptor->m_value.size() <= (ble_att_mtu(desc.conn_handle) - 3)) {
pDescriptor->m_pCallbacks->onRead(pDescriptor);
}
@@ -256,7 +261,7 @@ void NimBLEDescriptor::setValue(const std::vector<uint8_t>& vec) {
/**
* @brief Set the characteristic this descriptor belongs to.
* @param [in] pChar A pointer to the characteristic this descriptior belongs to.
* @param [in] pChar A pointer to the characteristic this descriptor belongs to.
*/
void NimBLEDescriptor::setCharacteristic(NimBLECharacteristic* pChar) {
m_pCharacteristic = pChar;

View File

@@ -802,7 +802,7 @@ void NimBLEDevice::onSync(void)
}
#endif
// Yield for houskeeping before returning to operations.
// Yield for housekeeping before returning to operations.
// Occasionally triggers exception without.
taskYIELD();
@@ -851,7 +851,7 @@ void NimBLEDevice::init(const std::string &deviceName) {
esp_err_t errRc = ESP_OK;
#ifdef CONFIG_ENABLE_ARDUINO_DEPENDS
// make sure the linker includes esp32-hal-bt.c so ardruino init doesn't release BLE memory.
// make sure the linker includes esp32-hal-bt.c so Arduino init doesn't release BLE memory.
btStarted();
#endif

View File

@@ -85,8 +85,8 @@ float NimBLEEddystoneTLM::getTemp() {
} // getTemp
/**
* @brief Get the count of advertisments sent.
* @return The number of advertisments.
* @brief Get the count of advertisements sent.
* @return The number of advertisements.
*/
uint32_t NimBLEEddystoneTLM::getCount() {
return ENDIAN_CHANGE_U32(m_eddystoneData.advCount);
@@ -94,8 +94,8 @@ uint32_t NimBLEEddystoneTLM::getCount() {
/**
* @brief Get the advertisment time.
* @return The advertisment time.
* @brief Get the advertisement time.
* @return The advertisement time.
*/
uint32_t NimBLEEddystoneTLM::getTime() {
return (ENDIAN_CHANGE_U32(m_eddystoneData.tmil)) / 10;
@@ -158,7 +158,7 @@ std::string NimBLEEddystoneTLM::toString() {
/**
* @brief Set the raw data for the beacon advertisment.
* @brief Set the raw data for the beacon advertisement.
* @param [in] data The raw data to advertise.
*/
void NimBLEEddystoneTLM::setData(const std::string &data) {
@@ -208,8 +208,8 @@ void NimBLEEddystoneTLM::setTemp(float temp) {
/**
* @brief Set the advertisment count.
* @param [in] advCount The advertisment number.
* @brief Set the advertisement count.
* @param [in] advCount The advertisement number.
*/
void NimBLEEddystoneTLM::setCount(uint32_t advCount) {
m_eddystoneData.advCount = advCount;
@@ -217,8 +217,8 @@ void NimBLEEddystoneTLM::setCount(uint32_t advCount) {
/**
* @brief Set the advertisment time.
* @param [in] tmil The advertisment time in milliseconds.
* @brief Set the advertisement time.
* @param [in] tmil The advertisement time in milliseconds.
*/
void NimBLEEddystoneTLM::setTime(uint32_t tmil) {
m_eddystoneData.tmil = tmil;

View File

@@ -152,7 +152,7 @@ std::string NimBLEEddystoneURL::getDecodedURL() {
/**
* @brief Set the raw data for the beacon advertisment.
* @brief Set the raw data for the beacon advertisement.
* @param [in] data The raw data to advertise.
*/
void NimBLEEddystoneURL::setData(const std::string &data) {

View File

@@ -272,7 +272,7 @@ bool NimBLEExtAdvertising::stop() {
/**
* @brief Set a callback to call when the advertisement stops.
* @param [in] pCallbacks A pointer to a callback to be invoked when an advertisment stops.
* @param [in] pCallbacks A pointer to a callback to be invoked when an advertisement stops.
* @param [in] deleteCallbacks if true callback class will be deleted when advertising is destructed.
*/
void NimBLEExtAdvertising::setCallbacks(NimBLEExtAdvertisingCallbacks* pCallbacks,

View File

@@ -99,7 +99,7 @@ void NimBLEHIDDevice::manufacturer(std::string name) {
}
/**
* @brief Sets the Plug n Play characterisc value.
* @brief Sets the Plug n Play characteristic value.
* @param [in] sig The vendor ID source number.
* @param [in] vid The vendor ID number.
* @param [in] pid The product ID number.

View File

@@ -165,7 +165,7 @@ std::vector<NimBLERemoteCharacteristic*>* NimBLERemoteService::getCharacteristic
/**
* @brief Callback for Characterisic discovery.
* @brief Callback for Characteristic discovery.
* @return success == 0 or error code.
*/
int NimBLERemoteService::characteristicDiscCB(uint16_t conn_handle,

View File

@@ -164,7 +164,7 @@ NimBLEScan::~NimBLEScan() {
NIMBLE_LOGD(LOG_TAG, "discovery complete; reason=%d",
event->disc_complete.reason);
// If a device advertised with scan reponse available and it was not received
// If a device advertised with scan response available and it was not received
// the callback would not have been invoked, so do it here.
if(pScan->m_pAdvertisedDeviceCallbacks) {
for(auto &it : pScan->m_scanResults.m_advertisedDevicesVector) {
@@ -211,7 +211,7 @@ void NimBLEScan::setActiveScan(bool active) {
* from devices it has not already seen.
* @param [in] enabled If true, scanned devices will only be reported once.
* @details The controller has a limited buffer and will start reporting
* dupicate devices once the limit is reached.
* duplicate devices once the limit is reached.
*/
void NimBLEScan::setDuplicateFilter(bool enabled) {
m_scan_params.filter_duplicates = enabled;
@@ -236,7 +236,7 @@ void NimBLEScan::setLimitedOnly(bool enabled) {
* directed, connectable advertising packets not sent to the scanner.
* * BLE_HCI_SCAN_FILT_USE_WL (1)
* Scanner processes advertisements from white list only. A connectable,\n
* directed advertisment is ignored unless it contains scanners address.
* directed advertisement is ignored unless it contains scanners address.
* * BLE_HCI_SCAN_FILT_NO_WL_INITA (2)
* Scanner process all advertising packets (white list not used). A\n
* connectable, directed advertisement shall not be ignored if the InitA

View File

@@ -61,8 +61,8 @@ void NimBLESecurity::setCapability(esp_ble_io_cap_t iocap) {
/**
* @brief Sets the keys we will distibute during encryption.
* @param [in] init_key A bitmask of the keys we will distibute.\n
* @brief Sets the keys we will distribute during encryption.
* @param [in] init_key A bitmask of the keys we will distribute.\n
* Can be one or more of:
* * ESP_BLE_ENC_KEY_MASK (1 << 0)
* * ESP_BLE_ID_KEY_MASK (1 << 1)

View File

@@ -373,7 +373,7 @@ int NimBLEServer::handleGapEvent(struct ble_gap_event *event, void *arg) {
case BLE_GAP_EVENT_DISCONNECT: {
// If Host reset tell the device now before returning to prevent
// any errors caused by calling host functions before resyncing.
// any errors caused by calling host functions before resync.
switch(event->disconnect.reason) {
case BLE_HS_ETIMEOUT_HCI:
case BLE_HS_EOS:
@@ -636,7 +636,7 @@ void NimBLEServer::setCallbacks(NimBLEServerCallbacks* pCallbacks, bool deleteCa
* @brief Remove a service from the server.
*
* @details Immediately removes access to the service by clients, sends a service changed indication,
* and removes the service (if applicable) from the advertisments.
* and removes the service (if applicable) from the advertisements.
* The service is not deleted unless the deleteSvc parameter is true, otherwise the service remains
* available and can be re-added in the future. If desired a removed but not deleted service can
* be deleted later by calling this method with deleteSvc set to true.

View File

@@ -151,7 +151,7 @@ public:
* @brief Handle a client disconnection.
* This is called when a client discconnects.
* @param [in] pServer A pointer to the %BLE server that received the client disconnection.
* @param [in] desc A pointer to the connection description structure containig information
* @param [in] desc A pointer to the connection description structure containing information
* about the connection.
*/
virtual void onDisconnect(NimBLEServer* pServer, ble_gap_conn_desc* desc);
@@ -159,7 +159,7 @@ public:
/**
* @brief Called when the connection MTU changes.
* @param [in] MTU The new MTU value.
* @param [in] desc A pointer to the connection description structure containig information
* @param [in] desc A pointer to the connection description structure containing information
* about the connection.
*/
virtual void onMTUChange(uint16_t MTU, ble_gap_conn_desc* desc);

View File

@@ -297,7 +297,7 @@ std::string NimBLEUUID::toString() const {
/**
* @brief Convienience operator to check if this UUID is equal to another.
* @brief Convenience operator to check if this UUID is equal to another.
*/
bool NimBLEUUID::operator ==(const NimBLEUUID & rhs) const {
if(m_valueSet && rhs.m_valueSet) {
@@ -336,7 +336,7 @@ bool NimBLEUUID::operator ==(const NimBLEUUID & rhs) const {
/**
* @brief Convienience operator to check if this UUID is not equal to another.
* @brief Convenience operator to check if this UUID is not equal to another.
*/
bool NimBLEUUID::operator !=(const NimBLEUUID & rhs) const {
return !this->operator==(rhs);
@@ -344,7 +344,7 @@ bool NimBLEUUID::operator !=(const NimBLEUUID & rhs) const {
/**
* @brief Convienience operator to convert this UUID to string representation.
* @brief Convenience operator to convert this UUID to string representation.
* @details This allows passing NimBLEUUID to functions
* that accept std::string and/or or it's methods as a parameter.
*/

View File

@@ -355,7 +355,7 @@ const char* NimBLEUtils::returnCodeToString(int rc) {
* @return A string representation of the advertising flags.
*/
const char* NimBLEUtils::advTypeToString(uint8_t advType) {
#if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
#if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
switch(advType) {
case BLE_HCI_ADV_TYPE_ADV_IND : //0
return "Undirected - Connectable / Scannable";
@@ -370,10 +370,10 @@ const char* NimBLEUtils::advTypeToString(uint8_t advType) {
default:
return "Unknown flag";
}
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
#else // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
(void)advType;
return "";
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT)
#endif // #if defined(CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT)
} // adFlagsToString

View File

@@ -1508,7 +1508,7 @@ ble_phy_resolv_list_disable(void)
void
ble_phy_rfclk_enable(void)
{
#if MYNEWT
#if MYNEWT || ARDUINO
nrf51_clock_hfxo_request();
#else
NRF_CLOCK->TASKS_HFCLKSTART = 1;
@@ -1518,7 +1518,7 @@ ble_phy_rfclk_enable(void)
void
ble_phy_rfclk_disable(void)
{
#if MYNEWT
#if MYNEWT || ARDUINO
nrf51_clock_hfxo_release();
#else
NRF_CLOCK->TASKS_HFCLKSTOP = 1;

View File

@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
#if defined(ARDUINO_ARCH_NRF5) && defined(NRF52_SERIES)
#include <stdint.h>
@@ -2100,7 +2100,7 @@ void ble_phy_disable_dtm(void)
void
ble_phy_rfclk_enable(void)
{
#if MYNEWT
#if MYNEWT || ARDUINO
nrf52_clock_hfxo_request();
#else
NRF_CLOCK->TASKS_HFCLKSTART = 1;
@@ -2110,7 +2110,7 @@ ble_phy_rfclk_enable(void)
void
ble_phy_rfclk_disable(void)
{
#if MYNEWT
#if MYNEWT || ARDUINO
nrf52_clock_hfxo_release();
#else
NRF_CLOCK->TASKS_HFCLKSTOP = 1;

View File

@@ -1162,6 +1162,38 @@ int ble_gap_adv_rsp_set_fields(const struct ble_hs_adv_fields *rsp_fields);
int ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
uint16_t tx_time);
/**
* Read host's suggested values for the controller's maximum transmitted number of payload octets
* and maximum packet transmission time (OGF = 0x08, OCF = 0x0024).
*
* @param out_sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
* number of payload octets in LL Data PDUs to be used for new
* connections. (Range 0x001B-0x00FB).
* @param out_sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
* transmission time for packets containing LL Data PDUs to be used
* for new connections. (Range 0x0148-0x4290).
*
* @return 0 on success,
* other error code on failure.
*/
int ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
uint16_t *out_sugg_max_tx_time);
/**
* Configure host's suggested maximum transmitted number of payload octets and maximum packet
* transmission time in controller (OGF = 0x08, OCF = 0x0024).
*
* @param sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
* number of payload octets in LL Data PDUs to be used for new
* connections. (Range 0x001B-0x00FB).
* @param sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
* transmission time for packets containing LL Data PDUs to be used
* for new connections. (Range 0x0148-0x4290).
*
* @return 0 on success,
* other error code on failure.
*/
int ble_hs_hci_util_write_sugg_def_data_len(uint16_t sugg_max_tx_octets, uint16_t sugg_max_tx_time);
#if MYNEWT_VAL(BLE_EXT_ADV)
/** @brief Extended advertising parameters */
struct ble_gap_ext_adv_params {
@@ -1843,6 +1875,37 @@ int ble_gap_update_params(uint16_t conn_handle,
*/
int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time);
/**
* Read LE Suggested Default Data Length in controller (OGF = 0x08, OCF = 0x0024).
*
* @param out_sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
* number of payload octets in LL Data PDUs to be used for new
* connections. (Range 0x001B-0x00FB).
* @param out_sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
* transmission time for packets containing LL Data PDUs to be used
* for new connections. (Range 0x0148-0x4290).
*
* @return 0 on success,
* other error code on failure.
*/
int ble_gap_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
uint16_t *out_sugg_max_tx_time);
/**
* Configure LE Suggested Default Data Length in controller (OGF = 0x08, OCF = 0x0024).
*
* @param sugg_max_tx_octets The Host's suggested value for the Controller's maximum transmitted
* number of payload octets in LL Data PDUs to be used for new
* connections. (Range 0x001B-0x00FB).
* @param sugg_max_tx_time The Host's suggested value for the Controller's maximum packet
* transmission time for packets containing LL Data PDUs to be used
* for new connections. (Range 0x0148-0x4290).
*
* @return 0 on success,
* other error code on failure.
*/
int ble_gap_write_sugg_def_data_len(uint16_t sugg_max_tx_octets, uint16_t sugg_max_tx_time);
/**
* Initiates the GAP security procedure.
*

View File

@@ -796,7 +796,7 @@ void bt_mesh_net_recv(struct os_mbuf *data, int8_t rssi,
* it again in the future.
*/
if (bt_mesh_trans_recv(buf, &rx) == -EAGAIN) {
BT_WARN("Removing rejected message from NetworkMessage Cache");
BT_WARN("Removing rejected message from Network Message Cache");
msg_cache[rx.msg_cache_idx].src = BT_MESH_ADDR_UNASSIGNED;
/* Rewind the next index now that we're not using this entry */
msg_cache_next = rx.msg_cache_idx;

View File

@@ -5860,6 +5860,16 @@ int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_t
return ble_hs_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
}
int ble_gap_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets, uint16_t *out_sugg_max_tx_time)
{
return ble_hs_hci_util_read_sugg_def_data_len(out_sugg_max_tx_octets, out_sugg_max_tx_time);
}
int ble_gap_write_sugg_def_data_len(uint16_t sugg_max_tx_octets, uint16_t sugg_max_tx_time)
{
return ble_hs_hci_util_write_sugg_def_data_len(sugg_max_tx_octets, sugg_max_tx_time);
}
/*****************************************************************************
* $security *
*****************************************************************************/

View File

@@ -157,6 +157,60 @@ ble_hs_hci_util_set_data_len(uint16_t conn_handle, uint16_t tx_octets,
return 0;
}
int
ble_hs_hci_util_read_sugg_def_data_len(uint16_t *out_sugg_max_tx_octets,
uint16_t *out_sugg_max_tx_time)
{
struct ble_hci_le_rd_sugg_def_data_len_rp rsp;
int rc;
rc = ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
BLE_HCI_OCF_LE_RD_SUGG_DEF_DATA_LEN),
NULL, 0, &rsp, sizeof(rsp));
if (rc != 0) {
return rc;
}
*out_sugg_max_tx_octets = le16toh(rsp.max_tx_octets);
*out_sugg_max_tx_time = le16toh(rsp.max_tx_time);
if (*out_sugg_max_tx_octets < BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN ||
*out_sugg_max_tx_octets > BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX) {
BLE_HS_LOG(WARN, "received suggested maximum tx octets is out of range\n");
}
if (*out_sugg_max_tx_time < BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN ||
*out_sugg_max_tx_time > BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX) {
BLE_HS_LOG(WARN, "received suggested maximum tx time is out of range\n");
}
return 0;
}
int
ble_hs_hci_util_write_sugg_def_data_len(uint16_t sugg_max_tx_octets,
uint16_t sugg_max_tx_time)
{
struct ble_hci_le_wr_sugg_def_data_len_cp cmd;
if (sugg_max_tx_octets < BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN ||
sugg_max_tx_octets > BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX) {
return BLE_HS_EINVAL;
}
if (sugg_max_tx_time < BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN ||
sugg_max_tx_time > BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX) {
return BLE_HS_EINVAL;
}
cmd.max_tx_octets = htole16(sugg_max_tx_octets);
cmd.max_tx_time = htole16(sugg_max_tx_time);
return ble_hs_hci_cmd_tx(BLE_HCI_OP(BLE_HCI_OGF_LE,
BLE_HCI_OCF_LE_WR_SUGG_DEF_DATA_LEN),
&cmd, sizeof(cmd), NULL, 0);
}
int
ble_hs_hci_util_data_hdr_strip(struct os_mbuf *om,
struct hci_data_hdr *out_hdr)

View File

@@ -43,7 +43,6 @@ ble_hs_periodic_sync_alloc(void)
memset(psync, 0, sizeof(*psync));
}
ble_npl_event_init(&psync->lost_ev, ble_gap_npl_sync_lost, psync);
return psync;
}
@@ -56,7 +55,9 @@ ble_hs_periodic_sync_free(struct ble_hs_periodic_sync *psync)
return;
}
ble_npl_event_deinit(&psync->lost_ev);
if((psync->lost_ev).event != NULL)
ble_npl_event_deinit(&psync->lost_ev);
#if MYNEWT_VAL(BLE_HS_DEBUG)
memset(psync, 0xff, sizeof *psync);
#endif

View File

@@ -97,6 +97,7 @@ ble_rpa_remove_peer_dev_rec(struct ble_hs_dev_records *p_dev_rec)
if ((i != ble_store_num_peer_dev_rec) && (ble_store_num_peer_dev_rec != 0)) {
memmove(&peer_dev_rec[i], &peer_dev_rec[i + 1],
(ble_store_num_peer_dev_rec - i) * sizeof(struct ble_hs_dev_records ));
memset(&peer_dev_rec[ble_store_num_peer_dev_rec], 0, sizeof(struct ble_hs_dev_records));
}
BLE_HS_LOG(DEBUG, " RPA: removed device at index = %d, no. of peer records"

View File

@@ -643,6 +643,10 @@ mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
mbedtls_entropy_init(&entropy);
mbedtls_ctr_drbg_init(&ctr_drbg);
/* Free the previously allocate keypair */
mbedtls_ecp_keypair_free(&keypair);
mbedtls_ecp_keypair_init(&keypair);
if (( rc = mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy,
@@ -679,6 +683,11 @@ exit:
return 0;
}
void mbedtls_free_keypair(void)
{
mbedtls_ecp_keypair_free(&keypair);
}
#endif
/**

View File

@@ -45,7 +45,7 @@ ble_hs_util_load_rand_addr(ble_addr_t *addr)
#if SOC_ESP_NIMBLE_CONTROLLER
int rc;
rc = esp_ble_hw_get_static_addr(addr);
rc = esp_ble_hw_get_static_addr((esp_ble_addr_t *)addr);
if (rc == 0) {
return 0;
}

View File

@@ -66,7 +66,7 @@ struct os_mbuf;
typedef int ble_hci_trans_rx_cmd_fn(uint8_t *cmd, void *arg);
typedef int ble_hci_trans_rx_acl_fn(struct os_mbuf *om, void *arg);
#if CONFIG_IDF_TARGET_ESP32H2
#if CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2
struct ble_hci_trans_funcs_t {
int(*_ble_hci_trans_hs_acl_tx)(struct os_mbuf *om);
int(*_ble_hci_trans_hs_cmd_tx)(uint8_t *cmd);

View File

@@ -1215,6 +1215,12 @@ struct ble_hci_vs_rd_static_addr_rp {
#define BLE_HCI_SET_DATALEN_TX_TIME_MIN (0x0148)
#define BLE_HCI_SET_DATALEN_TX_TIME_MAX (0x4290)
/* --- LE read/write suggested default data length (OCF 0x0023 and 0x0024) */
#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MIN (0x001b)
#define BLE_HCI_SUGG_DEF_DATALEN_TX_OCTETS_MAX (0x00fb)
#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MIN (0x0148)
#define BLE_HCI_SUGG_DEF_DATALEN_TX_TIME_MAX (0x4290)
/* --- LE read maximum default PHY (OCF 0x0030) */
#define BLE_HCI_LE_PHY_1M (1)
#define BLE_HCI_LE_PHY_2M (2)

View File

@@ -23,6 +23,7 @@
#include "nimble/nimble/include/nimble/nimble_npl.h"
#ifdef ESP_PLATFORM
#include "esp_err.h"
#include "nimconfig.h"
#define NIMBLE_CORE (CONFIG_BT_NIMBLE_PINNED_TO_CORE < portNUM_PROCESSORS ? CONFIG_BT_NIMBLE_PINNED_TO_CORE : tskNO_AFFINITY)
#define NIMBLE_HS_STACK_SIZE CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE
@@ -31,8 +32,8 @@
#define NIMBLE_HS_STACK_SIZE (CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE / 4)
#endif
#if (CONFIG_IDF_TARGET_ESP32H2)
#define NIMBLE_LL_STACK_SIZE CONFIG_BT_NIMBLE_CONTROLLER_TASK_STACK_SIZE
#if (CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2)
#define NIMBLE_LL_STACK_SIZE CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE
#endif
#ifdef __cplusplus
@@ -45,6 +46,22 @@ void nimble_port_deinit(void);
void nimble_port_run(void);
int nimble_port_stop(void);
#ifdef ESP_PLATFORM
/**
* @brief esp_nimble_init - Initialize the NimBLE host stack
*
* @return esp_err_t
*/
esp_err_t esp_nimble_init(void);
/**
* @brief esp_nimble_deinit - Deinitialize the NimBLE host stack
*
* @return esp_err_t
*/
esp_err_t esp_nimble_deinit(void);
#endif // ESP_PLATFORM
struct ble_npl_eventq *nimble_port_get_dflt_eventq(void);
#if NIMBLE_CFG_CONTROLLER

View File

@@ -6,9 +6,12 @@
#define H_SYSCFG_
#ifdef ESP_PLATFORM
#include "nimble/esp_port/port/include/esp_nimble_cfg.h"
# include "nimble/esp_port/port/include/esp_nimble_cfg.h"
#else
#include "ext_nimble_config.h"
# include "ext_nimble_config.h"
# ifndef CONFIG_BT_NIMBLE_ENABLED
# define CONFIG_BT_NIMBLE_ENABLED 1
# endif
#endif
#if 0

View File

@@ -0,0 +1,388 @@
/*
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#if CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2
#include "freertos/FreeRTOS.h"
#include "os/os.h"
#include "hal/hal_uart.h"
#include "soc/soc.h"
#include "soc/system_reg.h"
#include "driver/gpio.h"
#include "esp_intr_alloc.h"
#include "riscv/interrupt.h"
#include "hal/uart_ll.h"
#include "freertos/semphr.h"
#include "rom/ets_sys.h"
#include "driver/uart.h"
#include "driver/periph_ctrl.h"
struct hal_uart {
uint8_t u_open:1;
uint8_t u_rx_stall:1;
uint8_t u_tx_started:1;
uint8_t u_tx_buf;
hal_uart_rx_char u_rx_func;
hal_uart_tx_char u_tx_func;
hal_uart_tx_done u_tx_done;
SemaphoreHandle_t u_rx_sem;
void *u_func_arg;
};
static struct hal_uart uart;
#define UART_FIFO_LEN (128)
uint8_t rxbuffer[256];
static uint16_t rd_ptr = 0;
static uint16_t wr_ptr = 0;
#define BUFFER_MASK (0xff)
static TaskHandle_t hci_uart_task_h;
void uart_init(uint32_t baud);
void uart0_init(uint32_t baud);
void uart0_tout_isr(void);
void uart_tout_isr(void);
void
hal_uart_blocking_tx(int port, uint8_t data){
}
int hal_uart_init(int uart_no, void *cfg)
{
// Uart_Init(uart_no, UART_CLK_FREQ_ROM);
return 0;
}
void hal_uart_start_rx(int uart)
{
ets_printf("rx support???\n");
}
int hal_uart_init_cbs(int uart_no, hal_uart_tx_char tx_func,
hal_uart_tx_done tx_done, hal_uart_rx_char rx_func, void *arg)
{
struct hal_uart *u;
u = &uart;
if (u->u_open) {
return -1;
}
u->u_rx_func = rx_func;
u->u_tx_func = tx_func;
u->u_tx_done = tx_done;
u->u_func_arg = arg;
return 0;
}
int hal_uart_config(int uart_no, int32_t speed, uint8_t databits, uint8_t stopbits,
enum hal_uart_parity parity, enum hal_uart_flow_ctl flow_ctl)
{
struct hal_uart *u;
u = &uart;
if (u->u_open) {
return -1;
}
if (uart_no) {
uart_init(speed);
} else {
uart0_init(speed);
}
u->u_open = 1;
return 0;
}
static int
IRAM_ATTR_64MCPU hal_uart_tx_fill_buf(struct hal_uart *u, int uart_no)
{
int data;
int i;
uart_dev_t *hw = &UART1;
if(!uart_no){
hw = &UART0;
}
i = 0;
while(hw->status.txfifo_cnt < UART_FIFO_LEN){
data = u->u_tx_func(u->u_func_arg);
if (data >= 0) {
hw->ahb_fifo.rw_byte = data;
i++;
}else{
break;
}
}
return i;
}
void hal_uart_start_tx(int uart_no)
{
struct hal_uart *u;
os_sr_t sr;
uart_dev_t *hw = &UART1;
if(!uart_no){
hw = &UART0;
}
u = &uart;
OS_ENTER_CRITICAL(sr);
if (u->u_tx_started == 0) {
u->u_tx_started = 1;
hw->int_ena.tx_done = 1;
hal_uart_tx_fill_buf(u,uart_no);
}
OS_EXIT_CRITICAL(sr);
}
int hal_uart0_close(int uart_no)
{
struct hal_uart *u;
u = &uart;
u->u_open = 0;
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART_CLK_EN);
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART_RST);
return 0;
}
int hal_uart_close(int uart_no)
{
struct hal_uart *u;
u = &uart;
u->u_open = 0;
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART1_CLK_EN);
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART1_RST);
return 0;
}
IRAM_ATTR_64MCPU void uart0_tout_isr(void)
{
struct hal_uart *u;
int rc;
uint32_t ch;
uart_dev_t *hw = &UART0;
u = &uart;
uint32_t uart_int_st = hw->int_st.val;
//clear
hw->int_clr.val = uart_int_st;
if (uart_int_st&UART_TX_DONE_INT_ST_M) {
rc = hal_uart_tx_fill_buf(u,0);
if (rc == 0) {
if (u->u_tx_done) {
u->u_tx_done(u->u_func_arg);
}
u->u_tx_started = 0;
hw->int_ena.tx_done = 0;
}
}
while (hw->status.rxfifo_cnt) {
int rd_len = hw->status.rxfifo_cnt;
for (int i = 0; i < rd_len; i++) {
ch = hw->ahb_fifo.rw_byte;
rc = u->u_rx_func(u->u_func_arg, ch);
if (rc < 0) {
u->u_rx_stall = 1;
}
}
}
}
IRAM_ATTR_64MCPU void uart_tout_isr(void)
{
struct hal_uart *u;
int rc;
bool rx_update = false;
uart_dev_t *hw = &UART1;
u = &uart;
uint32_t uart_int_st = hw->int_st.val;
//clear
hw->int_clr.val = uart_int_st;
if (uart_int_st&UART_TX_DONE_INT_ST_M) {
rc = hal_uart_tx_fill_buf(u,1);
if (rc == 0) {
if (u->u_tx_done) {
u->u_tx_done(u->u_func_arg);
}
u->u_tx_started = 0;
hw->int_ena.tx_done = 0;
}
}
while (hw->status.rxfifo_cnt) {
rxbuffer[(wr_ptr++)&BUFFER_MASK] = hw->ahb_fifo.rw_byte;
rx_update = true;
}
if (rx_update) {
xSemaphoreGiveFromISR(u->u_rx_sem, 0);
}
}
void
IRAM_ATTR uart_rx_task(void *arg){
int rc;
struct hal_uart *u;
u = &uart;
while (1) {
xSemaphoreTake(u->u_rx_sem, portMAX_DELAY);
while (rd_ptr != wr_ptr){
rc = u->u_rx_func(u->u_func_arg, rxbuffer[(rd_ptr++)&BUFFER_MASK]);
if (rc < 0) {
u->u_rx_stall = 1;
}
}
}
}
void uart0_init(uint32_t baud)
{
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART_RST);
REG_CLR_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART_RST);
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART_CLK_EN_M);
REG_SET_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART_CLK_EN_M);
const int sclk_div = 1;
uint32_t sclk_freq = XTAL_CLK_FREQ;
uint32_t clk_div = ((sclk_freq) << 4) / baud;
uart_dev_t *hw = &UART0;
hw->clk_conf.sclk_en = 0;
hw->clk_conf.rx_sclk_en = 0;
hw->clk_conf.tx_sclk_en = 0;
hw->clk_conf.sclk_en = 1;
hw->clk_conf.rx_sclk_en = 1;
hw->clk_conf.tx_sclk_en = 1;
hw->clk_div.div_int = clk_div >> 4;
hw->clk_div.div_frag = clk_div & 0xf;
hw->clk_conf.sclk_div_num = sclk_div - 1;//7;//255;
hw->conf0.parity_en = 0;
hw->conf0.irda_en = 0;
hw->rs485_conf.en = 0;
hw->rs485_conf.tx_rx_en = 0;
hw->rs485_conf.rx_busy_tx_en = 0;
hw->conf0.bit_num = 3;
hw->conf0.stop_bit_num = 1;
hw->conf1.rxfifo_full_thrhd = 80;
hw->mem_conf.rx_tout_thrhd = 20;
hw->conf1.rx_tout_en = 1;
hw->conf1.rx_flow_en = 0;
hw->conf0.tx_flow_en = 0;
hw->conf0.rxfifo_rst = 1;
hw->conf0.rxfifo_rst = 0;
hw->conf0.txfifo_rst = 1;
hw->conf0.txfifo_rst = 0;
hw->int_ena.rxfifo_full = 1;
//enable rx fifo timeout interrupt
hw->int_ena.rxfifo_tout = 1;
uint8_t tx_pin = 21, rx_pin = 20, ISR_ID = ETS_UART0_INUM;
ets_isr_mask((1<<ISR_ID)); //ETS_INTR_DISABLE
intr_handler_set(ISR_ID, (intr_handler_t)&uart0_tout_isr, NULL);
intr_matrix_route(ETS_UART0_INTR_SOURCE, ISR_ID);
esprv_intc_int_enable(BIT(ISR_ID));
esprv_intc_int_set_type(BIT(ISR_ID), INTR_TYPE_LEVEL);
esprv_intc_int_set_priority(ISR_ID, 1);
esp_intr_reserve(ISR_ID, xPortGetCoreID());
ESP_ERROR_CHECK(uart_set_pin(0, tx_pin, rx_pin, -1, -1));
}
void uart_init(uint32_t baud)
{
periph_module_enable(PERIPH_UART1_MODULE);
REG_SET_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART1_RST);
REG_CLR_BIT(SYSTEM_PERIP_RST_EN0_REG, SYSTEM_UART1_RST);
REG_CLR_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART1_CLK_EN_M);
REG_SET_BIT(SYSTEM_PERIP_CLK_EN0_REG, SYSTEM_UART1_CLK_EN_M);
const int sclk_div = 1;
uint32_t sclk_freq = XTAL_CLK_FREQ;
uint32_t clk_div = ((sclk_freq) << 4) / baud;
struct hal_uart *u = &uart;
uart_dev_t *hw = &UART1;
hw->clk_conf.sclk_en = 0;
hw->clk_conf.rx_sclk_en = 0;
hw->clk_conf.tx_sclk_en = 0;
hw->clk_conf.sclk_en = 1;
hw->clk_conf.rx_sclk_en = 1;
hw->clk_conf.tx_sclk_en = 1;
hw->clk_div.div_int = clk_div >> 4;
hw->clk_div.div_frag = clk_div & 0xf;
hw->clk_conf.sclk_div_num = sclk_div - 1;//7;//255;
hw->conf0.parity_en = 0;
hw->conf0.irda_en = 0;
hw->rs485_conf.en = 0;
hw->rs485_conf.tx_rx_en = 0;
hw->rs485_conf.rx_busy_tx_en = 0;
hw->conf0.bit_num = 3;
hw->conf0.stop_bit_num = 1;
//set full threshold to (2/3)*FIFO_LEN
hw->conf1.rxfifo_full_thrhd = 80;
hw->mem_conf.rx_tout_thrhd = 20;
hw->conf1.rx_tout_en = 1;
hw->conf0.rxfifo_rst = 1;
hw->conf0.rxfifo_rst = 0;
hw->conf0.txfifo_rst = 1;
hw->conf0.txfifo_rst = 0;
hw->int_ena.rxfifo_full = 1;
//enable rx fifo timeout interrupt
hw->int_ena.rxfifo_tout = 1;
u->u_rx_sem = xSemaphoreCreateBinary();
uint8_t TX_IO = CONFIG_BT_LE_HCI_UART_TX_PIN, RX_IO = CONFIG_BT_LE_HCI_UART_RX_PIN, ISR_ID = ETS_UART1_INUM;
printf("set nimble port tx:%d, rx:%d.\n", TX_IO, RX_IO);
printf("set baud:%d.\n", baud);
intr_handler_set(ISR_ID, (intr_handler_t)&uart_tout_isr, NULL);
intr_matrix_route(ETS_UART1_INTR_SOURCE, ISR_ID);
esprv_intc_int_enable(BIT(ISR_ID));
esprv_intc_int_set_type(BIT(ISR_ID), INTR_TYPE_LEVEL);
esprv_intc_int_set_priority(ISR_ID, 1);
// TODO ESP32-C3 IDF-2126, maybe can use interrupt allocation API for all of the above? unsure...
esp_intr_reserve(ISR_ID, xPortGetCoreID());
ESP_ERROR_CHECK(uart_set_pin(1, TX_IO, RX_IO, -1, -1));
//Enable hw flow control of UART1 for BQB test, which if not enabled, the tester takes quite long time to send a byte to DUT
// uart_ll_set_hw_flow_ctrl(hw, UART_HW_FLOWCTRL_CTS_RTS, 110);
xTaskCreate(uart_rx_task, "uart_rx", CONFIG_BT_LE_HCI_UART_TASK_STACK_SIZE,
NULL, 1, &hci_uart_task_h);
}
#endif // CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2

View File

@@ -20,7 +20,11 @@
#include <stddef.h>
#include "../include/os/os.h"
#include "../include/sysinit/sysinit.h"
#if CONFIG_BT_NIMBLE_ENABLED
#include "nimble/nimble/host/include/host/ble_hs.h"
#endif //CONFIG_BT_NIMBLE_ENABLED
#include "../include/nimble/nimble_port.h"
#include "../../npl/freertos/include/nimble/nimble_port_freertos.h"
#if NIMBLE_CFG_CONTROLLER
@@ -43,91 +47,31 @@
#endif
#endif
#ifdef CONFIG_BT_NIMBLE_CONTROL_USE_UART_HCI
#include "transport/uart/ble_hci_uart.h"
#else
#include "nimble/nimble/transport/ram/include/transport/ram/ble_hci_ram.h"
#endif
#include "nimble/nimble/include/nimble/ble_hci_trans.h"
#ifdef ESP_PLATFORM
#include "esp_intr_alloc.h"
#include "esp_bt.h"
#include "nimble/esp_port/esp-hci/include/esp_nimble_hci.h"
#endif
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
extern void ble_hs_deinit(void);
#define NIMBLE_PORT_LOG_TAG "BLE_INIT"
extern void os_msys_init(void);
static struct ble_npl_eventq g_eventq_dflt;
#if CONFIG_BT_NIMBLE_ENABLED
extern void ble_hs_deinit(void);
static struct ble_hs_stop_listener stop_listener;
#endif //CONFIG_BT_NIMBLE_ENABLED
static struct ble_npl_eventq g_eventq_dflt;
static struct ble_npl_sem ble_hs_stop_sem;
static struct ble_npl_event ble_hs_ev_stop;
void
nimble_port_init(void)
{
#if SOC_ESP_NIMBLE_CONTROLLER
struct esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
if(esp_bt_controller_init(&config_opts) != 0) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller init failed\n");
return;
}
/* Initialize the host */
ble_hs_init();
#else //SOC_ESP_NIMBLE_CONTROLLER
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
/* Initialize the function pointers for OS porting */
npl_freertos_funcs_init();
npl_freertos_mempool_init();
#endif
/* Initialize default event queue */
ble_npl_eventq_init(&g_eventq_dflt);
#if NIMBLE_CFG_CONTROLLER
void ble_hci_ram_init(void);
#endif
os_msys_init();
ble_hs_init();
#endif
#ifndef ESP_PLATFORM
# if NIMBLE_CFG_CONTROLLER
ble_hci_ram_init();
hal_timer_init(5, NULL);
os_cputime_init(32768);
ble_ll_init();
# endif
#endif
}
void
nimble_port_deinit(void)
{
#if SOC_ESP_NIMBLE_CONTROLLER
ble_hs_deinit();
esp_bt_controller_deinit();
/* Delete the host task */
nimble_port_freertos_deinit();
#else
ble_npl_eventq_deinit(&g_eventq_dflt);
ble_hs_deinit();
#endif
}
/**
* Called when the host stop procedure has completed.
*/
@@ -143,12 +87,150 @@ nimble_port_stop_cb(struct ble_npl_event *ev)
ble_npl_sem_release(&ble_hs_stop_sem);
}
#ifdef ESP_PLATFORM
/**
* @brief esp_nimble_init - Initialize the NimBLE host stack
*
* @return esp_err_t
*/
esp_err_t esp_nimble_init(void)
{
#if !SOC_ESP_NIMBLE_CONTROLLER
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
/* Initialize the function pointers for OS porting */
npl_freertos_funcs_init();
npl_freertos_mempool_init();
#endif
#if false //need delete esp_nimble_hci_and_controller_init then can be use
if(esp_nimble_hci_init() != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "hci inits failed\n");
return ESP_FAIL;
}
printf("esp_nimble_hci_init\n");
#endif
/* Initialize default event queue */
ble_npl_eventq_init(&g_eventq_dflt);
os_msys_init();
#endif
/* Initialize the host */
ble_hs_init();
return ESP_OK;
}
/**
* @brief esp_nimble_deinit - Deinitialize the NimBLE host stack
*
* @return esp_err_t
*/
esp_err_t esp_nimble_deinit(void)
{
#if false && !SOC_ESP_NIMBLE_CONTROLLER //need delete esp_nimble_hci_and_controller_init then can be use
if(esp_nimble_hci_deinit() != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "hci deinit failed\n");
return ESP_FAIL;
}
#endif
#if !(SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED)
ble_npl_eventq_deinit(&g_eventq_dflt);
#endif
ble_hs_deinit();
return ESP_OK;
}
#endif
void
nimble_port_init(void)
{
#ifdef ESP_PLATFORM
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
esp_bt_controller_config_t config_opts = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
if(esp_bt_controller_init(&config_opts) != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller init failed\n");
return;
}
if(esp_bt_controller_enable(ESP_BT_MODE_BLE) != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller enable failed\n");
return;
}
#endif
if(esp_nimble_init() != 0) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host init failed\n");
return;
}
#else
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
/* Initialize the function pointers for OS porting */
npl_freertos_funcs_init();
npl_freertos_mempool_init();
#endif
/* Initialize default event queue */
ble_npl_eventq_init(&g_eventq_dflt);
os_msys_init();
ble_hs_init();
#if NIMBLE_CFG_CONTROLLER
ble_hci_ram_init();
hal_timer_init(5, NULL);
os_cputime_init(32768);
ble_ll_init();
#endif
#endif // ESP_PLATFORM
}
void
nimble_port_deinit(void)
{
#ifdef ESP_PLATFORM
if(esp_nimble_deinit() != 0) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host deinit failed\n");
return;
}
#if CONFIG_BT_CONTROLLER_ENABLED
if(esp_bt_controller_disable() != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller disable failed\n");
return;
}
if(esp_bt_controller_deinit() != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller deinit failed\n");
return;
}
#endif
#else
ble_npl_eventq_deinit(&g_eventq_dflt);
ble_hs_deinit();
#endif // ESP_PLATFORM
}
int
nimble_port_stop(void)
{
int rc;
#ifdef ESP_PLATFORM
esp_err_t err = ESP_OK;
ble_npl_sem_init(&ble_hs_stop_sem, 0);
/* Initiate a host stop procedure. */
err = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
NULL);
if (err != 0) {
ble_npl_sem_deinit(&ble_hs_stop_sem);
return err;
}
#else
int rc = 0;
ble_npl_sem_init(&ble_hs_stop_sem, 0);
/* Initiate a host stop procedure. */
rc = ble_hs_stop(&stop_listener, ble_hs_stop_cb,
NULL);
@@ -156,12 +238,13 @@ nimble_port_stop(void)
ble_npl_sem_deinit(&ble_hs_stop_sem);
return rc;
}
#endif // ESP_PLATFORM
/* Wait till the host stop procedure is complete */
ble_npl_sem_pend(&ble_hs_stop_sem, BLE_NPL_TIME_FOREVER);
ble_npl_event_init(&ble_hs_ev_stop, nimble_port_stop_cb,
NULL);
NULL);
ble_npl_eventq_put(&g_eventq_dflt, &ble_hs_ev_stop);
/* Wait till the event is serviced */
@@ -169,7 +252,11 @@ nimble_port_stop(void)
ble_npl_sem_deinit(&ble_hs_stop_sem);
#ifdef ESP_PLATFORM
return ESP_OK;
#else
return rc;
#endif
}
void

View File

@@ -30,11 +30,25 @@
static STAILQ_HEAD(, os_mbuf_pool) g_msys_pool_list =
STAILQ_HEAD_INITIALIZER(g_msys_pool_list);
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
#if CONFIG_BT_NIMBLE_ENABLED
#define OS_MSYS_1_BLOCK_COUNT MYNEWT_VAL(MSYS_1_BLOCK_COUNT)
#define OS_MSYS_1_BLOCK_SIZE MYNEWT_VAL(MSYS_1_BLOCK_SIZE)
#define OS_MSYS_2_BLOCK_COUNT MYNEWT_VAL(MSYS_2_BLOCK_COUNT)
#define OS_MSYS_2_BLOCK_SIZE MYNEWT_VAL(MSYS_2_BLOCK_SIZE)
#else
#define OS_MSYS_1_BLOCK_COUNT CONFIG_BT_LE_MSYS_1_BLOCK_COUNT
#define OS_MSYS_1_BLOCK_SIZE CONFIG_BT_LE_MSYS_1_BLOCK_SIZE
#define OS_MSYS_2_BLOCK_COUNT CONFIG_BT_LE_MSYS_2_BLOCK_COUNT
#define OS_MSYS_2_BLOCK_SIZE CONFIG_BT_LE_MSYS_2_BLOCK_SIZE
#endif
#if OS_MSYS_1_BLOCK_COUNT > 0
#define SYSINIT_MSYS_1_MEMBLOCK_SIZE \
OS_ALIGN(MYNEWT_VAL(MSYS_1_BLOCK_SIZE), 4)
OS_ALIGN(OS_MSYS_1_BLOCK_SIZE, 4)
#define SYSINIT_MSYS_1_MEMPOOL_SIZE \
OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_1_BLOCK_COUNT), \
OS_MEMPOOL_SIZE(OS_MSYS_1_BLOCK_COUNT, \
SYSINIT_MSYS_1_MEMBLOCK_SIZE)
#ifdef ESP_PLATFORM
static os_membuf_t *os_msys_init_1_data;
@@ -45,11 +59,11 @@ static struct os_mbuf_pool os_msys_init_1_mbuf_pool;
static struct os_mempool os_msys_init_1_mempool;
#endif
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
#if OS_MSYS_2_BLOCK_COUNT > 0
#define SYSINIT_MSYS_2_MEMBLOCK_SIZE \
OS_ALIGN(MYNEWT_VAL(MSYS_2_BLOCK_SIZE), 4)
OS_ALIGN(OS_MSYS_2_BLOCK_SIZE, 4)
#define SYSINIT_MSYS_2_MEMPOOL_SIZE \
OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_2_BLOCK_COUNT), \
OS_MEMPOOL_SIZE(OS_MSYS_2_BLOCK_COUNT, \
SYSINIT_MSYS_2_MEMBLOCK_SIZE)
#ifdef ESP_PLATFORM
static os_membuf_t *os_msys_init_2_data;
@@ -135,14 +149,14 @@ os_msys_init_once(void *data, struct os_mempool *mempool,
int
os_msys_buf_alloc(void)
{
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
#if OS_MSYS_1_BLOCK_COUNT > 0
os_msys_init_1_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_1_MEMPOOL_SIZE));
if (!os_msys_init_1_data) {
return ESP_FAIL;
}
#endif
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
#if OS_MSYS_2_BLOCK_COUNT > 0
os_msys_init_2_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE));
if (!os_msys_init_2_data) {
return ESP_FAIL;
@@ -155,12 +169,12 @@ os_msys_buf_alloc(void)
void
os_msys_buf_free(void)
{
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
#if OS_MSYS_1_BLOCK_COUNT > 0
nimble_platform_mem_free(os_msys_init_1_data);
os_msys_init_1_data = NULL;
#endif
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
#if OS_MSYS_2_BLOCK_COUNT > 0
nimble_platform_mem_free(os_msys_init_2_data);
os_msys_init_2_data = NULL;
#endif
@@ -176,20 +190,20 @@ void os_msys_init(void)
os_msys_reset();
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
#if OS_MSYS_1_BLOCK_COUNT > 0
os_msys_init_once(os_msys_init_1_data,
&os_msys_init_1_mempool,
&os_msys_init_1_mbuf_pool,
MYNEWT_VAL(MSYS_1_BLOCK_COUNT),
OS_MSYS_1_BLOCK_COUNT,
SYSINIT_MSYS_1_MEMBLOCK_SIZE,
"msys_1");
#endif
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
#if OS_MSYS_2_BLOCK_COUNT > 0
os_msys_init_once(os_msys_init_2_data,
&os_msys_init_2_mempool,
&os_msys_init_2_mbuf_pool,
MYNEWT_VAL(MSYS_2_BLOCK_COUNT),
OS_MSYS_2_BLOCK_COUNT,
SYSINIT_MSYS_2_MEMBLOCK_SIZE,
"msys_2");
#endif

View File

@@ -23,22 +23,45 @@
#include "nimble/nimble/include/nimble/nimble_npl.h"
#include "nimble/porting/nimble/include/syscfg/syscfg.h"
#ifdef ESP_PLATFORM
#include "esp_err.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef ESP_PLATFORM
/**
* @brief esp_nimble_enable - Initialize the NimBLE host task
*
* @param host_task
* @return esp_err_t
*/
esp_err_t esp_nimble_enable(void *host_task);
/**
* @brief esp_nimble_disable - Disable the NimBLE host task
*
* @return esp_err_t
*/
esp_err_t esp_nimble_disable(void);
#endif
void nimble_port_freertos_init(TaskFunction_t host_task_fn);
void nimble_port_freertos_deinit(void);
#if CONFIG_NIMBLE_STACK_USE_MEM_POOLS
void npl_freertos_funcs_init(void);
void npl_freertos_funcs_deinit(void);
int npl_freertos_mempool_init(void);
struct npl_funcs_t * npl_freertos_funcs_get(void);
#endif
#ifndef ESP_PLATFORM
UBaseType_t nimble_port_freertos_get_ll_hwm(void);
#endif
UBaseType_t nimble_port_freertos_get_hs_hwm(void);
#endif
#ifdef __cplusplus
}

View File

@@ -41,7 +41,51 @@ static StackType_t hs_xStack[ NIMBLE_HS_STACK_SIZE ];
static StaticTask_t hs_xTaskBuffer;
#endif
static TaskHandle_t host_task_h;
static TaskHandle_t host_task_h = NULL;
#ifdef ESP_PLATFORM
/**
* @brief esp_nimble_enable - Initialize the NimBLE host
*
* @param host_task
* @return esp_err_t
*/
esp_err_t esp_nimble_enable(void *host_task)
{
/*
* Create task where NimBLE host will run. It is not strictly necessary to
* have separate task for NimBLE host, but since something needs to handle
* default queue it is just easier to make separate task which does this.
*/
xTaskCreatePinnedToCore(host_task, "nimble_host", NIMBLE_HS_STACK_SIZE,
NULL, (configMAX_PRIORITIES - 4), &host_task_h, NIMBLE_CORE);
return ESP_OK;
}
/**
* @brief esp_nimble_disable - Disable the NimBLE host
*
* @return esp_err_t
*/
esp_err_t esp_nimble_disable(void)
{
if (host_task_h) {
vTaskDelete(host_task_h);
host_task_h = NULL;
}
return ESP_OK;
}
// Compatibility wrappers for new functions
void nimble_port_freertos_init(TaskFunction_t host_task_fn) {
esp_nimble_enable((void*)host_task_fn);
}
void nimble_port_freertos_deinit(void) {
esp_nimble_disable();
}
#else // ESP_PLATFORM
void
nimble_port_freertos_init(TaskFunction_t host_task_fn)
@@ -53,26 +97,16 @@ nimble_port_freertos_init(TaskFunction_t host_task_fn)
* provided by NimBLE and in case of FreeRTOS it does not need to be wrapped
* since it has compatible prototype.
*/
#ifdef ESP_PLATFORM
esp_bt_controller_enable(ESP_BT_MODE_BLE);
#else
ll_task_h = xTaskCreateStatic(nimble_port_ll_task_func, "ll", NIMBLE_LL_STACK_SIZE,
NULL, configMAX_PRIORITIES, ll_xStack, &ll_xTaskBuffer);
#endif
#endif
/*
* Create task where NimBLE host will run. It is not strictly necessary to
* have separate task for NimBLE host, but since something needs to handle
* default queue it is just easier to make separate task which does this.
*/
#ifdef ESP_PLATFORM
xTaskCreatePinnedToCore(host_task_fn, "ble", NIMBLE_HS_STACK_SIZE,
NULL, (configMAX_PRIORITIES - 4), &host_task_h, NIMBLE_CORE);
#else
host_task_h = xTaskCreateStatic(host_task_fn, "ble", NIMBLE_HS_STACK_SIZE,
NULL, (configMAX_PRIORITIES - 1), hs_xStack, &hs_xTaskBuffer);
#endif
}
void
@@ -81,12 +115,8 @@ nimble_port_freertos_deinit(void)
if (host_task_h) {
vTaskDelete(host_task_h);
}
#ifdef ESP_PLATFORM
esp_bt_controller_disable();
#endif
}
#ifndef ESP_PLATFORM
#if NIMBLE_CFG_CONTROLLER
UBaseType_t
nimble_port_freertos_get_ll_hwm(void)
@@ -94,10 +124,11 @@ nimble_port_freertos_get_ll_hwm(void)
return uxTaskGetStackHighWaterMark(ll_task_h);
}
#endif
#endif
UBaseType_t
nimble_port_freertos_get_hs_hwm(void)
{
return uxTaskGetStackHighWaterMark(host_task_h);
}
#endif //ESP_PLATFORM

View File

@@ -60,14 +60,28 @@ static const char *TAG = "Timer";
#define OS_MEM_ALLOC (1)
#if CONFIG_BT_NIMBLE_ENABLED
#define BT_LE_HCI_EVT_HI_BUF_COUNT MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT)
#define BT_LE_HCI_EVT_LO_BUF_COUNT MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT)
#define BT_LE_MAX_EXT_ADV_INSTANCES MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES)
#define BT_LE_MAX_CONNECTIONS MYNEWT_VAL(BLE_MAX_CONNECTIONS)
#else
#include "esp_bt.h"
#define BT_LE_HCI_EVT_HI_BUF_COUNT DEFAULT_BT_LE_HCI_EVT_HI_BUF_COUNT
#define BT_LE_HCI_EVT_LO_BUF_COUNT DEFAULT_BT_LE_HCI_EVT_LO_BUF_COUNT
#define BT_LE_MAX_EXT_ADV_INSTANCES DEFAULT_BT_LE_MAX_EXT_ADV_INSTANCES
#define BT_LE_MAX_CONNECTIONS DEFAULT_BT_LE_MAX_CONNECTIONS
#endif
#define BLE_HS_HCI_EVT_COUNT \
(MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT) + \
MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT))
(BT_LE_HCI_EVT_HI_BUF_COUNT + \
BT_LE_HCI_EVT_LO_BUF_COUNT)
#define LL_NPL_BASE_EVENT_COUNT (11)
#define LL_SCAN_EXT_AUX_EVT_CNT (MYNEWT_VAL(BLE_LL_EXT_ADV_AUX_PTR_CNT))
#define HCI_LL_NPL_EVENT_COUNT (1)
#define ADV_LL_NPL_EVENT_COUNT ((MYNEWT_VAL(BLE_MULTI_ADV_INSTANCES)+1)*3)
#define ADV_LL_NPL_EVENT_COUNT ((BT_LE_MAX_EXT_ADV_INSTANCES+1)*3)
#define SCAN_LL_NPL_EVENT_COUNT (2)
#define RL_LL_NPL_EVENT_COUNT (1)
#define SYNC_LL_NPL_EVENT_COUNT (7)
@@ -84,7 +98,8 @@ static const char *TAG = "Timer";
#define LL_CFG_FEAT_LE_PING_EVT (0)
#endif
#define CONN_MODULE_NPL_EVENT_COUNT (((LL_CFG_FEAT_LE_PING_EVT+2)*MYNEWT_VAL(BLE_MAX_CONNECTIONS))+LL_CTRL_TO_HOST_FLOW_CTRL_EVT)
#define CONN_MODULE_NPL_EVENT_COUNT (((LL_CFG_FEAT_LE_PING_EVT+2)*BT_LE_MAX_CONNECTIONS)+LL_CTRL_TO_HOST_FLOW_CTRL_EVT)
#define BLE_LL_EV_COUNT (LL_NPL_BASE_EVENT_COUNT + \
LL_SCAN_EXT_AUX_EVT_CNT + \
@@ -99,7 +114,7 @@ static const char *TAG = "Timer";
#define BLE_TOTAL_EVQ_COUNT (10)
#define BLE_TOTAL_CO_COUNT (20)
#define BLE_TOTAL_CO_COUNT (40)
#define BLE_TOTAL_SEM_COUNT (10)
@@ -1013,15 +1028,22 @@ IRAM_ATTR npl_freertos_callout_set_arg(struct ble_npl_callout *co, void *arg)
uint32_t
IRAM_ATTR npl_freertos_time_get(void)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
return esp_timer_get_time() / 1000;
#else
return xTaskGetTickCountFromISR();
#endif
}
ble_npl_error_t
IRAM_ATTR npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks)
{
uint64_t ticks;
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
ticks = (uint64_t)ms;
#else
ticks = ((uint64_t)ms * configTICK_RATE_HZ) / 1000;
#endif
if (ticks > UINT32_MAX) {
return BLE_NPL_EINVAL;
}
@@ -1035,8 +1057,11 @@ ble_npl_error_t
IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
{
uint64_t ms;
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
ms = ((uint64_t)ticks);
#else
ms = ((uint64_t)ticks * 1000) / configTICK_RATE_HZ;
#endif
if (ms > UINT32_MAX) {
return BLE_NPL_EINVAL;
}
@@ -1049,19 +1074,31 @@ IRAM_ATTR npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms)
ble_npl_time_t
IRAM_ATTR npl_freertos_time_ms_to_ticks32(uint32_t ms)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
return ms;
#else
return ms * configTICK_RATE_HZ / 1000;
#endif
}
uint32_t
IRAM_ATTR npl_freertos_time_ticks_to_ms32(ble_npl_time_t ticks)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
return ticks;
#else
return ticks * 1000 / configTICK_RATE_HZ;
#endif
}
void
IRAM_ATTR npl_freertos_time_delay(ble_npl_time_t ticks)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
vTaskDelay(ticks / portTICK_PERIOD_MS);
#else
vTaskDelay(ticks);
#endif
}
#ifdef ESP_PLATFORM
@@ -1734,6 +1771,10 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
void
npl_freertos_callout_deinit(struct ble_npl_callout *co)
{
if (!co->handle) {
return;
}
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
if(esp_timer_stop(co->handle))
ESP_LOGW(TAG, "Timer not stopped");
@@ -1741,9 +1782,8 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
if(esp_timer_delete(co->handle))
ESP_LOGW(TAG, "Timer not deleted");
#else
if (co->handle) {
xTimerDelete(co->handle, portMAX_DELAY);
}
xTimerDelete(co->handle, portMAX_DELAY);
ble_npl_event_deinit(&co->ev);
#endif
memset(co, 0, sizeof(struct ble_npl_callout));
}
@@ -1787,6 +1827,9 @@ npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
void
npl_freertos_callout_stop(struct ble_npl_callout *co)
{
if (!co->handle) {
return;
}
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
esp_timer_stop(co->handle);
#else

View File

@@ -25,7 +25,7 @@
/** @brief Uncomment to set the default allocation size (bytes) for each attribute if\n
* not specified when the constructor is called. This is also the size used when a remote\n
* characteristic or descriptor is constructed before a value is read/notifed.\n
* characteristic or descriptor is constructed before a value is read/notified.\n
* Increasing this will reduce reallocations but increase memory footprint.\n
* Default value is 20. Range: 1 : 512 (BLE_ATT_ATTR_MAX_LEN)
*/
@@ -75,11 +75,6 @@
*/
// #define CONFIG_NIMBLE_CPP_LOG_LEVEL 0
/** @brief Un-comment to use timestamps with characteristic / descriptor values
* If not enabled the `::get/readValue()` calls with a timestamp parameter will set the timestamp to 0.
*/
// #define NIMBLE_ATT_VALUE_TIMESTAMP_ENABLED
/** @brief Un-comment to see NimBLE host return codes as text debug log messages.
* Uses approx. 7kB of flash memory.
*/
@@ -90,10 +85,10 @@
*/
// #define CONFIG_NIMBLE_CPP_ENABLE_GAP_EVENT_CODE_TEXT
/** @brief Un-comment to see advertisment types as text while scanning in debug log messages.
/** @brief Un-comment to see advertisement types as text while scanning in debug log messages.
* Uses approx. 250 bytes of flash memory.
*/
// #define CONFIG_NIMBLE_CPP_ENABLE_ADVERTISMENT_TYPE_TEXT
// #define CONFIG_NIMBLE_CPP_ENABLE_ADVERTISEMENT_TYPE_TEXT
/** @brief Un-comment to change the default GAP appearance */
// #define CONFIG_BT_NIMBLE_SVC_GAP_APPEARANCE 0x0
@@ -268,6 +263,10 @@
#define CONFIG_BT_ENABLED
#endif
#ifndef CONFIG_BT_NIMBLE_ENABLED
#define CONFIG_BT_NIMBLE_ENABLED 1
#endif
#ifdef ESP_PLATFORM
#ifndef CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY
#define CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY