Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow configuration of heap size for o1heap #63

Merged
merged 5 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion extras/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ set(TEST_SRCS
../../src/types/uavcan/node/ExecuteCommand.1.0.Response.cpp
../../src/types/uavcan/node/Heartbeat.1.0.cpp
../../src/utility/CritSec-host.cpp
../../src/ArduinoO1Heap.cpp
../../src/ArduinoUAVCAN.cpp
)

Expand Down
15 changes: 10 additions & 5 deletions src/ArduinoO1Heap.h → src/ArduinoO1Heap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Contributors: https://github.com/107-systems/107-Arduino-UAVCAN/graphs/contributors.
*/

#ifndef ARDUINO_O1_HEAP_H_
#define ARDUINO_O1_HEAP_H_
#ifndef ARDUINO_O1_HEAP_HPP_
#define ARDUINO_O1_HEAP_HPP_

/**************************************************************************************
* INCLUDE
Expand All @@ -18,6 +18,7 @@
* CLASS DECLARATION
**************************************************************************************/

template <size_t HEAP_SIZE>
class ArduinoO1Heap
{
public:
Expand All @@ -31,11 +32,15 @@ class ArduinoO1Heap

private:

static size_t constexpr HEAP_SIZE = 4096;

uint8_t _base[HEAP_SIZE] __attribute__ ((aligned (O1HEAP_ALIGNMENT)));
O1HeapInstance * _o1heap_ins;

};

#endif /* ARDUINO_O1_HEAP_H_ */
/**************************************************************************************
* TEMPLATE SOURCE
**************************************************************************************/

#include "ArduinoO1Heap.ipp"

#endif /* ARDUINO_O1_HEAP_HPP_ */
15 changes: 6 additions & 9 deletions src/ArduinoO1Heap.cpp → src/ArduinoO1Heap.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@
* Contributors: https://github.com/107-systems/107-Arduino-UAVCAN/graphs/contributors.
*/

/**************************************************************************************
* INCLUDE
**************************************************************************************/

#include "ArduinoO1Heap.h"

/**************************************************************************************
* CTOR/DTOR
**************************************************************************************/

ArduinoO1Heap::ArduinoO1Heap()
template <size_t HEAP_SIZE>
ArduinoO1Heap<HEAP_SIZE>::ArduinoO1Heap()
: _o1heap_ins{o1heapInit(_base, HEAP_SIZE, nullptr, nullptr)}
{

Expand All @@ -25,12 +20,14 @@ ArduinoO1Heap::ArduinoO1Heap()
* PUBLIC MEMBER FUNCTIONS
**************************************************************************************/

void * ArduinoO1Heap::allocate(size_t const amount)
template <size_t HEAP_SIZE>
void * ArduinoO1Heap<HEAP_SIZE>::allocate(size_t const amount)
{
return o1heapAllocate(_o1heap_ins, amount);
}

void ArduinoO1Heap::free(void * const pointer)
template <size_t HEAP_SIZE>
void ArduinoO1Heap<HEAP_SIZE>::free(void * const pointer)
{
o1heapFree(_o1heap_ins, pointer);
}
4 changes: 2 additions & 2 deletions src/ArduinoUAVCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ bool ArduinoUAVCAN::transmitCanFrame()

void * ArduinoUAVCAN::o1heap_allocate(CanardInstance * const ins, size_t const amount)
{
ArduinoO1Heap * o1heap = reinterpret_cast<ArduinoO1Heap *>(ins->user_reference);
O1HeapLibcanard * o1heap = reinterpret_cast<O1HeapLibcanard*>(ins->user_reference);
return o1heap->allocate(amount);
}

void ArduinoUAVCAN::o1heap_free(CanardInstance * const ins, void * const pointer)
{
ArduinoO1Heap * o1heap = reinterpret_cast<ArduinoO1Heap *>(ins->user_reference);
O1HeapLibcanard * o1heap = reinterpret_cast<O1HeapLibcanard*>(ins->user_reference);
o1heap->free(pointer);
}

Expand Down
7 changes: 5 additions & 2 deletions src/ArduinoUAVCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <memory>
#include <functional>

#include "ArduinoO1Heap.h"
#include "ArduinoO1Heap.hpp"
#include "ArduinoUAVCANTypes.h"

#include "libcanard/canard.h"
Expand Down Expand Up @@ -71,13 +71,16 @@ class ArduinoUAVCAN

private:

static size_t constexpr LIBCANARD_O1HEAP_SIZE = 4096;
typedef ArduinoO1Heap<LIBCANARD_O1HEAP_SIZE> O1HeapLibcanard;

typedef struct
{
CanardRxSubscription canard_rx_sub;
OnTransferReceivedFunc transfer_complete_callback;
} RxTransferData;

ArduinoO1Heap _o1heap;
O1HeapLibcanard _o1heap;
CanardInstance _canard_ins;
CanFrameTransmitFunc _transmit_func;
std::map<CanardPortID, RxTransferData> _rx_transfer_map;
Expand Down