diff --git a/src/NimBLECharacteristic.cpp b/src/NimBLECharacteristic.cpp index c5e1ba9..e27690f 100644 --- a/src/NimBLECharacteristic.cpp +++ b/src/NimBLECharacteristic.cpp @@ -49,7 +49,6 @@ NimBLECharacteristic::NimBLECharacteristic(const NimBLEUUID &uuid, uint16_t prop m_pCallbacks = &defaultCallback; m_pService = pService; m_value = ""; - m_valMux = portMUX_INITIALIZER_UNLOCKED; m_timestamp = 0; m_removed = 0; } // NimBLECharacteristic @@ -235,12 +234,12 @@ NimBLEUUID NimBLECharacteristic::getUUID() { * @return A std::string containing the current characteristic value. */ std::string NimBLECharacteristic::getValue(time_t *timestamp) { - portENTER_CRITICAL(&m_valMux); + ble_npl_hw_enter_critical(); std::string retVal = m_value; if(timestamp != nullptr) { *timestamp = m_timestamp; } - portEXIT_CRITICAL(&m_valMux); + ble_npl_hw_exit_critical(0); return retVal; } // getValue @@ -251,10 +250,9 @@ std::string NimBLECharacteristic::getValue(time_t *timestamp) { * @return The length of the current characteristic data. */ size_t NimBLECharacteristic::getDataLength() { - portENTER_CRITICAL(&m_valMux); + ble_npl_hw_enter_critical(); size_t len = m_value.length(); - portEXIT_CRITICAL(&m_valMux); - + ble_npl_hw_exit_critical(0); return len; } @@ -287,11 +285,10 @@ int NimBLECharacteristic::handleGapEvent(uint16_t conn_handle, uint16_t attr_han pCharacteristic->m_pCallbacks->onRead(pCharacteristic, &desc); } - portENTER_CRITICAL(&pCharacteristic->m_valMux); + ble_npl_hw_enter_critical(); rc = os_mbuf_append(ctxt->om, (uint8_t*)pCharacteristic->m_value.data(), pCharacteristic->m_value.length()); - portEXIT_CRITICAL(&pCharacteristic->m_valMux); - + ble_npl_hw_exit_critical(0); return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; } @@ -432,7 +429,7 @@ void NimBLECharacteristic::notify(std::string value, bool is_notification) { } m_pCallbacks->onNotify(this); - + bool reqSec = (m_properties & BLE_GATT_CHR_F_READ_AUTHEN) || (m_properties & BLE_GATT_CHR_F_READ_AUTHOR) || (m_properties & BLE_GATT_CHR_F_READ_ENC); @@ -535,10 +532,10 @@ void NimBLECharacteristic::setValue(const uint8_t* data, size_t length) { } time_t t = time(nullptr); - portENTER_CRITICAL(&m_valMux); + ble_npl_hw_enter_critical(); m_value = std::string((char*)data, length); m_timestamp = t; - portEXIT_CRITICAL(&m_valMux); + ble_npl_hw_exit_critical(0); NIMBLE_LOGD(LOG_TAG, "<< setValue"); } // setValue diff --git a/src/NimBLECharacteristic.h b/src/NimBLECharacteristic.h index b636d6d..9af1120 100644 --- a/src/NimBLECharacteristic.h +++ b/src/NimBLECharacteristic.h @@ -155,7 +155,6 @@ private: NimBLEService* m_pService; std::string m_value; std::vector m_dscVec; - portMUX_TYPE m_valMux; time_t m_timestamp; uint8_t m_removed; diff --git a/src/NimBLEClient.cpp b/src/NimBLEClient.cpp index 2844569..b1e4634 100644 --- a/src/NimBLEClient.cpp +++ b/src/NimBLEClient.cpp @@ -948,11 +948,11 @@ uint16_t NimBLEClient::getMTU() { (*characteristic)->toString().c_str()); time_t t = time(nullptr); - portENTER_CRITICAL(&(*characteristic)->m_valMux); + ble_npl_hw_enter_critical(); (*characteristic)->m_value = std::string((char *)event->notify_rx.om->om_data, event->notify_rx.om->om_len); (*characteristic)->m_timestamp = t; - portEXIT_CRITICAL(&(*characteristic)->m_valMux); + ble_npl_hw_exit_critical(0); if ((*characteristic)->m_notifyCallback != nullptr) { NIMBLE_LOGD(LOG_TAG, "Invoking callback for notification on characteristic %s", diff --git a/src/NimBLEDescriptor.cpp b/src/NimBLEDescriptor.cpp index 14efbab..5b0db1a 100644 --- a/src/NimBLEDescriptor.cpp +++ b/src/NimBLEDescriptor.cpp @@ -49,7 +49,6 @@ NimBLEDescriptor::NimBLEDescriptor(NimBLEUUID uuid, uint16_t properties, uint16_ m_pCharacteristic = pCharacteristic; m_pCallbacks = &defaultCallbacks; // No initial callback. m_value.attr_value = (uint8_t*) calloc(max_len,1); // Allocate storage for the value. - m_valMux = portMUX_INITIALIZER_UNLOCKED; m_properties = 0; m_removed = 0; @@ -162,9 +161,10 @@ int NimBLEDescriptor::handleGapEvent(uint16_t conn_handle, uint16_t attr_handle, if(ctxt->om->om_pkthdr_len > 8) { pDescriptor->m_pCallbacks->onRead(pDescriptor); } - portENTER_CRITICAL(&pDescriptor->m_valMux); + + ble_npl_hw_enter_critical(); rc = os_mbuf_append(ctxt->om, pDescriptor->getValue(), pDescriptor->getLength()); - portEXIT_CRITICAL(&pDescriptor->m_valMux); + ble_npl_hw_exit_critical(0); return rc == 0 ? 0 : BLE_ATT_ERR_INSUFFICIENT_RES; } @@ -235,10 +235,11 @@ void NimBLEDescriptor::setValue(const uint8_t* data, size_t length) { NIMBLE_LOGE(LOG_TAG, "Size %d too large, must be no bigger than %d", length, m_value.attr_max_len); return; } - portENTER_CRITICAL(&m_valMux); + + ble_npl_hw_enter_critical(); m_value.attr_len = length; memcpy(m_value.attr_value, data, length); - portEXIT_CRITICAL(&m_valMux); + ble_npl_hw_exit_critical(0); } // setValue diff --git a/src/NimBLEDescriptor.h b/src/NimBLEDescriptor.h index ca4f25b..fe6c733 100644 --- a/src/NimBLEDescriptor.h +++ b/src/NimBLEDescriptor.h @@ -90,7 +90,6 @@ private: NimBLECharacteristic* m_pCharacteristic; uint8_t m_properties; attr_value_t m_value; - portMUX_TYPE m_valMux; uint8_t m_removed; }; // NimBLEDescriptor diff --git a/src/NimBLERemoteCharacteristic.cpp b/src/NimBLERemoteCharacteristic.cpp index 16a1088..de50406 100644 --- a/src/NimBLERemoteCharacteristic.cpp +++ b/src/NimBLERemoteCharacteristic.cpp @@ -57,7 +57,6 @@ static const char* LOG_TAG = "NimBLERemoteCharacteristic"; m_pRemoteService = pRemoteService; m_notifyCallback = nullptr; m_timestamp = 0; - m_valMux = portMUX_INITIALIZER_UNLOCKED; NIMBLE_LOGD(LOG_TAG, "<< NimBLERemoteCharacteristic(): %s", m_uuid.toString().c_str()); } // NimBLERemoteCharacteristic @@ -405,12 +404,12 @@ NimBLEUUID NimBLERemoteCharacteristic::getUUID() { * @return The value of the remote characteristic. */ std::string NimBLERemoteCharacteristic::getValue(time_t *timestamp) { - portENTER_CRITICAL(&m_valMux); + ble_npl_hw_enter_critical(); std::string value = m_value; if(timestamp != nullptr) { *timestamp = m_timestamp; } - portEXIT_CRITICAL(&m_valMux); + ble_npl_hw_exit_critical(0); return value; } @@ -512,13 +511,13 @@ std::string NimBLERemoteCharacteristic::readValue(time_t *timestamp) { } while(rc != 0 && retryCount--); time_t t = time(nullptr); - portENTER_CRITICAL(&m_valMux); + ble_npl_hw_enter_critical(); m_value = value; m_timestamp = t; if(timestamp != nullptr) { *timestamp = m_timestamp; } - portEXIT_CRITICAL(&m_valMux); + ble_npl_hw_exit_critical(0); NIMBLE_LOGD(LOG_TAG, "<< readValue length: %d rc=%d", value.length(), rc); return value; diff --git a/src/NimBLERemoteCharacteristic.h b/src/NimBLERemoteCharacteristic.h index 1b3dedd..41ae816 100644 --- a/src/NimBLERemoteCharacteristic.h +++ b/src/NimBLERemoteCharacteristic.h @@ -159,7 +159,6 @@ private: std::string m_value; notify_callback m_notifyCallback; time_t m_timestamp; - portMUX_TYPE m_valMux; // We maintain a vector of descriptors owned by this characteristic. std::vector m_descriptorVector;