Skip to content

Commit d807850

Browse files
committed
Use ArduinoCore-API/HardwareCAN.
A common base class for CAN I/O libraries across all Arduino cores. Former-commit-id: 6ad2f5c
1 parent 00e6cbd commit d807850

File tree

7 files changed

+16
-258
lines changed

7 files changed

+16
-258
lines changed

libraries/CAN/src/CanMsg.h

Lines changed: 0 additions & 100 deletions
This file was deleted.

libraries/CAN/src/CanMsgRingbuffer.cpp

Lines changed: 0 additions & 71 deletions
This file was deleted.

libraries/CAN/src/CanUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <tuple>
2121

22-
#include "HardwareCAN.h"
22+
#include "api/HardwareCAN.h"
2323

2424
/**************************************************************************************
2525
* NAMESPACE

libraries/CAN/src/HardwareCAN.h

Lines changed: 0 additions & 64 deletions
This file was deleted.

libraries/CAN/src/R7FA4M1_CAN.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919

2020
#ifdef ARDUINO_SANTIAGO
2121

22-
#include "HardwareCAN.h"
22+
#include "api/HardwareCAN.h"
2323

2424
#include "bsp_api.h"
2525

2626
#include "r_can.h"
2727

28-
#include "CanMsgRingbuffer.h"
28+
#include "SyncCanMsgRingbuffer.h"
2929

3030
/**************************************************************************************
3131
* TYPEDEF
@@ -78,7 +78,7 @@ class R7FA4M1_CAN final : public HardwareCAN
7878
int const _can_rx_pin;
7979
bool _is_error;
8080
int _err_code;
81-
CanMsgRingbuffer _can_rx_buf;
81+
SyncCanMsgRingbuffer _can_rx_buf;
8282

8383
can_instance_ctrl_t _can_ctrl;
8484
can_bit_timing_cfg_t _can_bit_timing_cfg;

libraries/CAN/src/R7FA6M5_CAN.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
#ifdef ARDUINO_PORTENTA_H33
2121

22-
#include "HardwareCAN.h"
22+
#include "api/HardwareCAN.h"
2323

2424
#include <tuple>
2525

2626
#include "bsp_api.h"
2727

2828
#include "r_canfd.h"
2929

30-
#include "CanMsgRingbuffer.h"
30+
#include "SyncCanMsgRingbuffer.h"
3131

3232
/**************************************************************************************
3333
* TYPEDEF
@@ -78,7 +78,7 @@ class R7FA6M5_CAN final : public HardwareCAN
7878
int const _can_rx_pin;
7979
bool _is_error;
8080
int _err_code;
81-
CanMsgRingbuffer _can_rx_buf;
81+
SyncCanMsgRingbuffer _can_rx_buf;
8282

8383
canfd_instance_ctrl_t _canfd_ctrl;
8484
can_bit_timing_cfg_t _canfd_bit_timing_cfg;

libraries/CAN/src/CanMsgRingbuffer.h renamed to libraries/CAN/src/SyncCanMsgRingbuffer.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@
1515
* INCLUDE
1616
**************************************************************************************/
1717

18-
#include <cstdint>
18+
#include "api/HardwareCAN.h"
1919

20-
#include "CanMsg.h"
2120
#include "sync.h"
2221

2322
/**************************************************************************************
@@ -31,28 +30,22 @@ namespace arduino
3130
* CLASS DECLARATION
3231
**************************************************************************************/
3332

34-
class CanMsgRingbuffer
33+
class SyncCanMsgRingbuffer
3534
{
3635
public:
37-
static size_t constexpr RING_BUFFER_SIZE = 32U;
36+
SyncCanMsgRingbuffer() : _can_msg_buf{} { }
3837

39-
CanMsgRingbuffer();
4038

41-
inline bool isFull() const { synchronized { return (_num_elems == RING_BUFFER_SIZE); } }
42-
void enqueue(CanMsg const & msg);
39+
bool isFull() const { synchronized { _can_msg_buf.isFull(); } }
40+
void enqueue(CanMsg const & msg) { synchronized { _can_msg_buf.enqueue(msg); } }
4341

44-
inline bool isEmpty() const { synchronized { return (_num_elems == 0); } }
45-
CanMsg dequeue();
42+
bool isEmpty() const { synchronized { return _can_msg_buf.isEmpty(); } }
43+
CanMsg dequeue() { synchronized { return _can_msg_buf.dequeue(); } }
4644

47-
inline size_t available() const { synchronized { return _num_elems; } }
45+
size_t available() const { synchronized { return _can_msg_buf.available(); } }
4846

4947
private:
50-
CanMsg _buf[RING_BUFFER_SIZE];
51-
volatile size_t _head;
52-
volatile size_t _tail;
53-
volatile size_t _num_elems;
54-
55-
inline size_t next(size_t const idx) const { return ((idx + 1) % RING_BUFFER_SIZE); }
48+
CanMsgRingbuffer _can_msg_buf;
5649
};
5750

5851
/**************************************************************************************

0 commit comments

Comments
 (0)