Cyphal restore O1Heap statistics

This commit is contained in:
Peter van der Perk
2022-05-11 09:49:18 -04:00
committed by Daniel Agar
parent e62e8b58d1
commit 0053aeec97
3 changed files with 18 additions and 11 deletions
+13 -8
View File
@@ -52,18 +52,18 @@
#endif // NuttX
O1HeapInstance *uavcan_allocator{nullptr};
O1HeapInstance *cyphal_allocator{nullptr};
static void *memAllocate(CanardInstance *const ins, const size_t amount) { return o1heapAllocate(uavcan_allocator, amount); }
static void memFree(CanardInstance *const ins, void *const pointer) { o1heapFree(uavcan_allocator, pointer); }
static void *memAllocate(CanardInstance *const ins, const size_t amount) { return o1heapAllocate(cyphal_allocator, amount); }
static void memFree(CanardInstance *const ins, void *const pointer) { o1heapFree(cyphal_allocator, pointer); }
CanardHandle::CanardHandle(uint32_t node_id, const size_t capacity, const size_t mtu_bytes)
{
_uavcan_heap = memalign(O1HEAP_ALIGNMENT, HeapSize);
uavcan_allocator = o1heapInit(_uavcan_heap, HeapSize, nullptr, nullptr);
_cyphal_heap = memalign(O1HEAP_ALIGNMENT, HeapSize);
cyphal_allocator = o1heapInit(_cyphal_heap, HeapSize, nullptr, nullptr);
if (uavcan_allocator == nullptr) {
if (cyphal_allocator == nullptr) {
PX4_ERR("o1heapInit failed with size %u", HeapSize);
}
@@ -89,8 +89,8 @@ CanardHandle::~CanardHandle()
delete _can_interface;
_can_interface = nullptr;
delete static_cast<uint8_t *>(_uavcan_heap);
_uavcan_heap = nullptr;
delete static_cast<uint8_t *>(_cyphal_heap);
_cyphal_heap = nullptr;
}
@@ -200,6 +200,11 @@ CanardTreeNode *CanardHandle::getRxSubscriptions(CanardTransferKind kind)
return _canard_instance.rx_subscriptions[kind];
}
O1HeapDiagnostics CanardHandle::getO1HeapDiagnostics()
{
return o1heapGetDiagnostics(cyphal_allocator);
}
int32_t CanardHandle::mtu()
{
return _queue.mtu_bytes;