Lely core libraries
2.2.5
|
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 | |
int | can_buf_init (struct can_buf *buf, size_t size) |
Initializes a CAN frame buffer. More... | |
void | can_buf_fini (struct can_buf *buf) |
Finalizes a CAN frame buffer. More... | |
struct can_buf * | can_buf_create (size_t size) |
Allocates and initializes a CAN frame buffer. More... | |
void | can_buf_clear (struct can_buf *buf) |
Clears a CAN frame buffer. | |
size_t | can_buf_size (const struct can_buf *buf) |
Returns the number of frames available for reading in a CAN buffer. More... | |
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... | |
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... | |
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... | |
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.
int can_buf_init | ( | struct can_buf * | buf, |
size_t | size | ||
) |
Initializes a CAN frame buffer.
buf | a pointer to a CAN frame buffer. |
size | the initial size (in number of frames). The size will be rounded up to the nearest power of two minus one. |
void can_buf_fini | ( | struct can_buf * | buf | ) |
struct can_buf* can_buf_create | ( | size_t | size | ) |
Allocates and initializes a CAN frame buffer.
size | the initial size (in number of frames). The size will be rounded up to the nearest power of two minus one. |
|
inline |
Returns the number of frames available for reading in a CAN buffer.
|
inline |
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. |
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. |