28 #ifndef LELY_CAN_BUF_H_
29 #define LELY_CAN_BUF_H_
37 #ifndef LELY_CAN_BUF_INLINE
38 #define LELY_CAN_BUF_INLINE static inline
67 #define CAN_BUF_INIT \
164 LELY_CAN_BUF_INLINE
void
168 assert(ptr || !size);
172 buf->
size = size ? size - 1 : 0;
177 LELY_CAN_BUF_INLINE
void
185 LELY_CAN_BUF_INLINE
size_t
194 LELY_CAN_BUF_INLINE
size_t
203 LELY_CAN_BUF_INLINE
size_t
209 size_t begin = buf->
begin;
210 for (
size_t i = 0; i < n; i++) {
211 size_t end = buf->
end;
212 if (!((end - begin) & buf->
size))
216 ptr[i] = buf->
ptr[begin & buf->
size];
223 LELY_CAN_BUF_INLINE
size_t
229 size_t begin = buf->
begin;
230 for (
size_t i = 0; i < n; i++) {
231 size_t end = buf->
end;
232 if (!((end - begin) & buf->
size))
236 ptr[i] = buf->
ptr[begin & buf->
size];
245 LELY_CAN_BUF_INLINE
size_t
251 size_t end = buf->
end;
252 for (
size_t i = 0; i < n; i++) {
253 size_t begin = buf->
begin;
254 if (!((begin - end - 1) & buf->
size))
257 buf->
ptr[end++ & buf->
size] = ptr[i];
LELY_CAN_BUF_INLINE void can_buf_init(struct can_buf *buf, struct can_msg *ptr, size_t size)
Initializes a CAN frame buffer.
LELY_CAN_BUF_INLINE size_t can_buf_peek(struct can_buf *buf, struct can_msg *ptr, size_t n)
Reads, but does not remove, frames from a CAN frame buffer.
LELY_CAN_BUF_INLINE size_t can_buf_write(struct can_buf *buf, const struct can_msg *ptr, size_t n)
Writes frames to a CAN frame buffer.
LELY_CAN_BUF_INLINE size_t can_buf_capacity(const struct can_buf *buf)
Returns the number of frames available for writing in a CAN buffer.
size_t can_buf_reserve(struct can_buf *buf, size_t n)
Resizes a CAN frame buffer, if necessary, to make room for at least n additional frames.
LELY_CAN_BUF_INLINE size_t can_buf_size(const struct can_buf *buf)
Returns the number of frames available for reading in a CAN buffer.
LELY_CAN_BUF_INLINE size_t can_buf_read(struct can_buf *buf, struct can_msg *ptr, size_t n)
Reads, and removes, frames from a CAN frame buffer.
LELY_CAN_BUF_INLINE void can_buf_clear(struct can_buf *buf)
Clears a CAN frame buffer.
void can_buf_fini(struct can_buf *buf)
Finalizes a CAN frame buffer.
This header file is part of the CAN library; it contains the CAN frame declarations.
This is the public header file of the utilities library.
#define powerof2(x)
Returns 1 if x is a power of two, and 0 otherwise.
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
struct can_msg * ptr
A pointer to the allocated memory for the buffer.
size_t end
The offset (with respect to ptr) of one past the last value available for reading (and the first avai...
size_t begin
The offset (with respect to ptr) of the first value available for reading (and two past the last avai...
size_t size
The total size (in number of frames) of the buffer, excluding the unused frame used to distinguish be...
A CAN or CAN FD format frame.