72 struct timespec start;
74 struct timespec interval;
93 uint_least32_t
id, uint_least8_t flags);
118 __can_net_alloc(
void)
120 void *ptr = malloc(
sizeof(
struct __can_net));
127 __can_net_free(
void *ptr)
139 net->
time = (
struct timespec){ 0, 0 };
140 net->
next = (
struct timespec){ 0, 0 };
177 goto error_alloc_net;
180 if (!__can_net_init(net)) {
343 __can_timer_alloc(
void)
352 __can_timer_free(
void *ptr)
366 timer->
start = (
struct timespec){ 0, 0 };
367 timer->
interval = (
struct timespec){ 0, 0 };
389 goto error_alloc_timer;
392 if (!__can_timer_init(timer)) {
394 goto error_init_timer;
400 __can_timer_free(timer);
410 __can_timer_fini(timer);
411 __can_timer_free(timer);
422 *pfunc = timer->
func;
424 *pdata = timer->
data;
438 const struct timespec *start,
const struct timespec *interval)
445 if (!start && !interval)
451 timer->
interval = (
struct timespec){ 0, 0 };
454 timer->
start = *start;
489 struct timespec start = { 0, 0 };
498 __can_recv_alloc(
void)
500 void *ptr = malloc(
sizeof(
struct __can_recv));
507 __can_recv_free(
void *ptr)
544 goto error_alloc_recv;
547 if (!__can_recv_init(recv)) {
549 goto error_init_recv;
555 __can_recv_free(recv);
565 __can_recv_fini(recv);
566 __can_recv_free(recv);
662 return uint32_cmp(p1, p2);
664 return uint64_cmp(p1, p2);
void can_timer_set_func(can_timer_t *timer, can_timer_func_t *func, void *data)
Sets the callback function invoked when a CAN timer is triggered.
void * send_data
A pointer to the user-specified data for send_func.
struct timespec interval
The interval between successive triggers.
A CAN or CAN FD format frame.
void can_net_get_send_func(const can_net_t *net, can_send_func_t **pfunc, void **pdata)
Retrieves the callback function used to send CAN frames from a network interface. ...
void rbnode_init(struct rbnode *node, const void *key)
Initializes a node in a red-black tree.
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
void can_net_destroy(can_net_t *net)
Destroys a CAN network interface.
This header file is part of the CAN library; it contains the CAN network interface declarations...
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a network interface.
int dlnode_insert_after(struct dlnode *prev, struct dlnode *node)
Inserts node after prev.
This header file is part of the utilities library; it contains the comparison function definitions...
struct timespec next
The time at which the next timer triggers.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
can_net_t * can_net_create(void)
Creates a new CAN network interface.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
void can_net_set_next_func(can_net_t *net, can_timer_func_t *func, void *data)
Sets the callback function invoked when the time at which the next CAN timer triggers is updated...
can_net_t * net
A pointer to the network interface with which this timer is registered.
void * data
A pointer to the user-specified data for func.
This header file is part of the utilities library; it contains the red-black tree declarations...
can_recv_key_t key
The key used in node.
can_recv_t * can_recv_create(void)
Creates a new CAN frame receiver.
struct pheap timer_heap
The tree containing all timers.
can_net_t * net
A pointer to the network interface with which this receiver is registered.
struct rbnode node
The node of this receiver in the tree of receivers.
void * data
A pointer to the user-specified data for func.
void dlnode_remove(struct dlnode *node)
Removes node from a doubly-list.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
struct dlnode * next
A pointer to the next node in the list.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int can_recv_func_t(const struct can_msg *msg, void *data)
The type of a CAN receive callback function, invoked by a CAN frame receiver when a frame is received...
static int can_recv_key_cmp(const void *p1, const void *p2)
The function used to compare to CAN receiver keys.
struct timespec start
The time at which the timer should trigger.
This is the internal header file of the CAN library.
void * next_data
A pointer to user-specified data for next_func.
This header file is part of the utilities library; it contains the pairing heap declarations.
This header file is part of the utilities library; it contains the native and platform-independent er...
#define dlnode_foreach(first, node)
Iterates in order over each node in a doubly-linked list.
#define rbtree_foreach(tree, node)
Iterates over each node in a red-black tree in ascending order.
This header file is part of the utilities library; it contains the time function declarations.
struct dlnode list
The list of CAN frame receivers with the same key.
void can_timer_timeout(can_timer_t *timer, can_net_t *net, int timeout)
Starts a CAN timer and registers it with a network interface.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function...
struct rbtree recv_tree
The tree containing all receivers.
uint_least64_t can_recv_key_t
The type of the key used to match CAN frame receivers to CAN frames.
can_recv_func_t * func
A pointer to the callback function invoked by can_net_recv().
int can_timer_func_t(const struct timespec *tp, void *data)
The type of a CAN timer callback function, invoked by a CAN timer when the time is updated...
void can_recv_get_func(const can_recv_t *recv, can_recv_func_t **pfunc, void **pdata)
Retrieves the callback function used to process CAN frames with a receiver.
void timespec_add(struct timespec *tp, const struct timespec *inc)
Adds the time interval *inc to the time at tp.
struct pnode node
The node of this timer in the tree of timers.
struct rbnode * rbtree_find(const struct rbtree *tree, const void *key)
Finds a node in a red-black tree.
This header file is part of the utilities library; it contains the doubly-linked list declarations...
void can_net_get_next_func(const can_net_t *net, can_timer_func_t **pfunc, void **pdata)
Retrieves the callback function invoked when the time at which the next CAN timer triggers is updated...
void rbtree_remove(struct rbtree *tree, struct rbnode *node)
Removes a node from a red-black tree.
can_send_func_t * send_func
A pointer to the callback function invoked by can_net_send().
static void can_net_set_next(can_net_t *net)
Invokes the callback function if the time at which the next CAN timer triggers has been updated...
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
int can_net_recv(can_net_t *net, const struct can_msg *msg)
Receives a CAN frame with a network interface and processes it with the corresponding receiver(s)...
static can_recv_key_t can_recv_key(uint_least32_t id, uint_least8_t flags)
Computes a CAN receiver key from a CAN identifier and flags.
void can_timer_destroy(can_timer_t *timer)
Destroys a CAN timer.
void pheap_insert(struct pheap *heap, struct pnode *node)
Inserts a node into a pairing heap.
int timespec_cmp(const void *p1, const void *p2)
Compares two times.
A node in a doubly-linked list.
void dlnode_init(struct dlnode *node)
Initializes a node in a doubly-linked list.
can_timer_func_t * func
A pointer to the callback function invoked by can_net_set_time().
uint_least8_t flags
The flags (any combination of CAN_FLAG_IDE, CAN_FLAG_RTR, CAN_FLAG_FDF, CAN_FLAG_BRS and CAN_FLAG_ESI...
The Identifier Extension (IDE) flag.
void pheap_remove(struct pheap *heap, struct pnode *node)
Removes a node from a pairing heap.
void can_timer_get_func(const can_timer_t *timer, can_timer_func_t **pfunc, void **pdata)
Retrieves the callback function invoked when a CAN timer is triggered.
const void * key
A pointer to the key of this node.
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
void can_timer_start(can_timer_t *timer, can_net_t *net, const struct timespec *start, const struct timespec *interval)
Starts a CAN timer and registers it with a network interface.
void can_recv_set_func(can_recv_t *recv, can_recv_func_t *func, void *data)
Sets the callback function used to process CAN frames with a receiver.
void rbtree_init(struct rbtree *tree, rbtree_cmp_t *cmp)
Initializes a red-black tree.
struct dlnode * prev
A pointer to the previous node in the list.
void rbtree_insert(struct rbtree *tree, struct rbnode *node)
Inserts a node into a red-black tree.
int can_send_func_t(const struct can_msg *msg, void *data)
The type of a CAN send callback function, invoked by a CAN network interface when a frame needs to be...
struct timespec time
The current time.
void can_recv_stop(can_recv_t *recv)
Stops a CAN frame receiver from processing frames and unregisters it with the network interface...
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib.h> and defines any missing functionality.
void can_recv_start(can_recv_t *recv, can_net_t *net, uint_least32_t id, uint_least8_t flags)
Registers a CAN frame receiver with a network interface and starts processing frames.
void timespec_add_msec(struct timespec *tp, uint_least64_t msec)
Adds msec milliseconds to the time at tp.
void can_net_set_send_func(can_net_t *net, can_send_func_t *func, void *data)
Sets the callback function used to send CAN frames from a network interface.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN network interface.
struct pnode * pheap_first(const struct pheap *heap)
Returns a pointer to the first (minimum) node in a pairing heap.
void pheap_init(struct pheap *heap, pheap_cmp_t *cmp)
Initializes a pairing heap.
int can_net_set_time(can_net_t *net, const struct timespec *tp)
Sets the current time of a CAN network interface.
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
can_timer_func_t * next_func
A pointer to the callback function invoked by can_net_set_next().
A node in a red-black tree.
A node in a pairing heap.
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.