Skip to content

Commit b85f1ff

Browse files
authored
Merge pull request #53 from bcmi-labs/can-api
Use ArduinoCore-API/HardwareCAN.
2 parents 97c3091 + fe982e9 commit b85f1ff

24 files changed

+22
-264
lines changed

libraries/CAN/examples/CAN1Read/CAN1Read.ino renamed to libraries/Arduino_CAN/examples/CAN1Read/CAN1Read.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* INCLUDE
33
**************************************************************************************/
44

5-
#include <CAN.h>
5+
#include <Arduino_CAN.h>
66

77
/**************************************************************************************
88
* SETUP/LOOP

libraries/CAN/examples/CAN1Write/CAN1Write.ino renamed to libraries/Arduino_CAN/examples/CAN1Write/CAN1Write.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* INCLUDE
33
**************************************************************************************/
44

5-
#include <CAN.h>
5+
#include <Arduino_CAN.h>
66

77
/**************************************************************************************
88
* CONSTANTS

libraries/CAN/examples/CANRead/CANRead.ino renamed to libraries/Arduino_CAN/examples/CANRead/CANRead.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* INCLUDE
33
**************************************************************************************/
44

5-
#include <CAN.h>
5+
#include <Arduino_CAN.h>
66

77
/**************************************************************************************
88
* SETUP/LOOP

libraries/CAN/examples/CANWrite/CANWrite.ino renamed to libraries/Arduino_CAN/examples/CANWrite/CANWrite.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* INCLUDE
33
**************************************************************************************/
44

5-
#include <CAN.h>
5+
#include <Arduino_CAN.h>
66

77
/**************************************************************************************
88
* CONSTANTS
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name=CAN
1+
name=Arduino_CAN
22
version=1.0
33
author=Arduino
44
maintainer=Arduino <[email protected]>
@@ -7,4 +7,4 @@ paragraph=This library provides CAN/CANFD access for Uno R4 and Portenta H33.
77
category=Other
88
url=
99
architectures=renesas
10-
include=CAN.h
10+
include=Arduino_CAN.h
File renamed without changes.
File renamed without changes.

libraries/CAN/src/CanUtil.h renamed to libraries/Arduino_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/R7FA4M1_CAN.h renamed to libraries/Arduino_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 renamed to libraries/Arduino_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/Arduino_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
/**************************************************************************************

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/HardwareCAN.h

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

0 commit comments

Comments
 (0)