18#ifndef NIMBLE_CPP_UTILS_H_
19#define NIMBLE_CPP_UTILS_H_
21#include "syscfg/syscfg.h"
22#if CONFIG_BT_NIMBLE_ENABLED
24# ifndef MYNEWT_VAL_NIMBLE_CPP_DEBUG_ASSERT_ENABLED
25# if defined(CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED)
26# define MYNEWT_VAL_NIMBLE_CPP_DEBUG_ASSERT_ENABLED CONFIG_NIMBLE_CPP_DEBUG_ASSERT_ENABLED
28# define MYNEWT_VAL_NIMBLE_CPP_DEBUG_ASSERT_ENABLED (0)
32# if MYNEWT_VAL(NIMBLE_CPP_DEBUG_ASSERT_ENABLED) && !defined NDEBUG
33void nimble_cpp_assert(
const char* file,
unsigned line) __attribute((weak, noreturn));
34# define NIMBLE_ATT_VAL_FILE (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : __FILE__)
35# define NIMBLE_CPP_DEBUG_ASSERT(cond) \
37 nimble_cpp_assert(NIMBLE_ATT_VAL_FILE, __LINE__); \
40# define NIMBLE_CPP_DEBUG_ASSERT(cond) (void(0))
56 std::atomic<bool> inUse{
false};
66 explicit SpinGuard(std::atomic_flag& flag);
70 std::atomic_flag& m_flag;
79 TaskData(
void* pInstance =
nullptr,
int flags = 0,
void* buf =
nullptr);
81 void* m_pInstance{
nullptr};
82 mutable int m_flags{0};
83 void* m_pBuf{
nullptr};
87 mutable TaskSemEntry* m_pSem{
nullptr};
91 static std::string
dataToHexString(
const uint8_t* source, uint8_t length);
100 static void deinit();
101 static std::vector<TaskSemEntry*> m_taskSemEntries;
102 static std::atomic<int> m_semUserCount;
103 static std::atomic_flag m_taskSemLock;
A BLE device address.
Definition NimBLEAddress.h:42
A model of a BLE Device from which all the BLE roles are created.
Definition NimBLEDevice.h:120
A simple spinlock guard for atomic_flag.
Definition NimBLEUtils.h:64
~SpinGuard()
Destruct a SpinGuard and release the lock.
Definition NimBLEUtils.cpp:654
A BLE Utility class with methods for debugging and general purpose use.
Definition NimBLEUtils.h:53
static bool taskWait(const TaskData &taskData, uint32_t timeout)
Blocks the calling task until released or timeout.
Definition NimBLEUtils.cpp:83
static std::string dataToHexString(const uint8_t *source, uint8_t length)
Create a hexadecimal string representation of the input data.
Definition NimBLEUtils.cpp:609
static NimBLEAddress generateAddr(bool nrpa)
Generate a random BLE address.
Definition NimBLEUtils.cpp:628
static const char * advTypeToString(uint8_t advType)
Convert the advertising type flag to a string.
Definition NimBLEUtils.cpp:489
static void taskRelease(const TaskData &taskData, int rc=0)
Release a task.
Definition NimBLEUtils.cpp:150
static const char * returnCodeToString(int rc)
Converts a return code from the NimBLE stack to a text string.
Definition NimBLEUtils.cpp:194
static const char * gapEventToString(uint8_t eventType)
Convert a GAP event type to a string representation.
Definition NimBLEUtils.cpp:516
A structure to hold data for a task that is waiting for a response.
Definition NimBLEUtils.h:78