Lely core libraries 2.3.4
|
This header file is part of the CAN library; it contains the CAN frame buffer declarations. More...
Go to the source code of this file.
Data Structures | |
struct | can_buf |
A CAN frame buffer. More... | |
Macros | |
#define | CAN_BUF_INIT |
The static initializer for struct can_buf. | |
Functions | |
LELY_CAN_BUF_INLINE void | can_buf_init (struct can_buf *buf, struct can_msg *ptr, size_t size) |
Initializes a CAN frame buffer. More... | |
void | can_buf_fini (struct can_buf *buf) |
Finalizes a CAN frame buffer. More... | |
LELY_CAN_BUF_INLINE void | can_buf_clear (struct can_buf *buf) |
Clears a CAN frame buffer. | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
This header file is part of the CAN library; it contains the CAN frame buffer declarations.
The CAN frame buffer is implemented as a circular buffer. Apart from can_buf_clear() and can_buf_reserve() (an obviously can_buf_init() and can_buf_fini()), all buffer functions are thread-safe and lock-free, provided there are at most two threads accessing the buffer at the same time (single-reader single-writer).
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file buf.h.
Initializes a CAN frame buffer.
buf | a pointer to a CAN frame buffer. |
ptr | a pointer to the memory region to be used by the buffer. If not NULL, the buffer takes ownership of the region at ptr and MAY reallocate or free the region during subsequent calls to can_buf_reserve() and canbuf_fini(). |
size | the number of frames available at ptr. If not 0, size MUST be a power of two. |
void can_buf_fini | ( | struct can_buf * | buf | ) |
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_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.
Note that the new capacity can be larger than the requested capacity.
Reads, but does not remove, frames from a CAN frame buffer.
buf | a pointer to a CAN frame buffer. |
ptr | the address at which to store the frames (can be NULL). |
n | the number of frames to read. |
Reads, and removes, frames from a CAN frame buffer.
buf | a pointer to a CAN frame buffer. |
ptr | the address at which to store the frames (can be NULL). |
n | the number of frames to read. |
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.
buf | a pointer to a CAN frame buffer. |
ptr | the address from which to load the frames. |
n | the number of frames to write. |