forked from arduino/ArduinoCore-renesas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyncCanMsgRingbuffer.h
57 lines (41 loc) · 1.8 KB
/
SyncCanMsgRingbuffer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* Copyright (c) 2022 by Alexander Entinger <[email protected]>
* CAN library for Arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#ifndef CAN_MSG_RING_BUFFER_HPP_
#define CAN_MSG_RING_BUFFER_HPP_
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include "api/HardwareCAN.h"
#include "sync.h"
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
namespace arduino
{
/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/
class SyncCanMsgRingbuffer
{
public:
SyncCanMsgRingbuffer() : _can_msg_buf{} { }
bool isFull() const { synchronized { return _can_msg_buf.isFull(); } }
void enqueue(CanMsg const & msg) { synchronized { _can_msg_buf.enqueue(msg); } }
bool isEmpty() const { synchronized { return _can_msg_buf.isEmpty(); } }
CanMsg dequeue() { synchronized { return _can_msg_buf.dequeue(); } }
size_t available() const { synchronized { return _can_msg_buf.available(); } }
private:
CanMsgRingbuffer _can_msg_buf;
};
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
} /* arduino */
#endif /* CAN_MSG_RING_BUFFER_HPP_ */