arduino-emulator
Loading...
Searching...
No Matches
ArduinoCore-API
api
CanMsgRingbuffer.h
1
/*
2
CanMsgRingbuffer.h - Library for CAN message handling
3
Copyright (c) 2023 Arduino. All right reserved.
4
5
This library is free software; you can redistribute it and/or
6
modify it under the terms of the GNU Lesser General Public
7
License as published by the Free Software Foundation; either
8
version 2.1 of the License, or (at your option) any later version.
9
10
This library is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
Lesser General Public License for more details.
14
15
You should have received a copy of the GNU Lesser General Public
16
License along with this library; if not, write to the Free Software
17
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
*/
19
20
#ifndef ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_
21
#define ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_
22
23
/**************************************************************************************
24
* INCLUDE
25
**************************************************************************************/
26
27
#include <stdint.h>
28
29
#include "CanMsg.h"
30
31
/**************************************************************************************
32
* NAMESPACE
33
**************************************************************************************/
34
35
namespace
arduino
36
{
37
38
/**************************************************************************************
39
* CLASS DECLARATION
40
**************************************************************************************/
41
42
class
CanMsgRingbuffer
43
{
44
public
:
45
static
size_t
constexpr
RING_BUFFER_SIZE = 32U;
46
47
CanMsgRingbuffer
();
48
49
inline
bool
isFull()
const
{
return
(_num_elems == RING_BUFFER_SIZE); }
50
void
enqueue(
CanMsg
const
& msg);
51
52
inline
bool
isEmpty()
const
{
return
(_num_elems == 0); }
53
CanMsg
dequeue();
54
55
inline
size_t
available()
const
{
return
_num_elems; }
56
57
private
:
58
CanMsg
_buf[RING_BUFFER_SIZE];
59
volatile
size_t
_head;
60
volatile
size_t
_tail;
61
volatile
size_t
_num_elems;
62
63
inline
size_t
next(
size_t
const
idx)
const
{
return
((idx + 1) % RING_BUFFER_SIZE); }
64
};
65
66
/**************************************************************************************
67
* NAMESPACE
68
**************************************************************************************/
69
70
}
/* arduino */
71
72
#endif
/* ARDUINOCORE_API_CAN_MSG_RING_BUFFER_H_ */
arduino::CanMsg
Definition
CanMsg.h:46
arduino::CanMsgRingbuffer
Definition
CanMsgRingbuffer.h:43
arduino
We provide the WiFi class to simulate the Arduino WIFI. In in Linux we can expect that networking is ...
Definition
CanMsg.cpp:31
Generated by
1.9.8