Lely core libraries
2.2.5
|
Go to the documentation of this file.
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);
can_net_t * net
A pointer to the network interface with which this receiver is registered.
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...
void rbtree_insert(struct rbtree *tree, struct rbnode *node)
Inserts a node into a red-black tree.
A node in 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.
void can_net_get_time(const can_net_t *net, struct timespec *tp)
Retrieves the current time of a CAN network interface.
#define rbtree_foreach(tree, node)
Iterates over each node in a red-black tree in ascending order.
void can_recv_destroy(can_recv_t *recv)
Destroys a CAN frame receiver.
#define CAN_MASK_EID
The mask used to extract the 29-bit Extended Identifier from a CAN frame.
void pheap_insert(struct pheap *heap, struct pnode *node)
Inserts a node into a pairing heap.
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_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.
can_recv_t * can_recv_create(void)
Creates a new CAN frame receiver.
can_timer_t * can_timer_create(void)
Creates a new CAN timer.
struct rbnode * rbtree_find(const struct rbtree *tree, const void *key)
Finds a node in a red-black tree.
void * next_data
A pointer to user-specified data for next_func.
void * data
A pointer to the user-specified data for func.
#define CAN_MASK_BID
The mask used to extract the 11-bit Base Identifier from a CAN frame.
void can_timer_stop(can_timer_t *timer)
Stops a CAN timer and unregisters it with a network interface.
A CAN or CAN FD format frame.
struct timespec start
The time at which the timer should trigger.
struct dlnode * next
A pointer to the next node in the list.
struct dlnode list
The list of CAN frame receivers with the same key.
can_timer_func_t * next_func
A pointer to the callback function invoked by can_net_set_next().
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
int timespec_cmp(const void *p1, const void *p2)
Compares two times.
int can_net_set_time(can_net_t *net, const struct timespec *tp)
Sets the current time of a CAN network interface.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
struct pheap timer_heap
The tree containing all timers.
void dlnode_init(struct dlnode *node)
Initializes a node in a doubly-linked list.
void timespec_add_msec(struct timespec *tp, uint_least64_t msec)
Adds msec milliseconds to the time at tp.
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.
can_net_t * can_net_create(void)
Creates a new CAN network interface.
uint_least64_t can_recv_key_t
The type of the key used to match CAN frame receivers to CAN frames.
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 pheap_init(struct pheap *heap, pheap_cmp_t *cmp)
Initializes a pairing heap.
static int can_recv_key_cmp(const void *p1, const void *p2)
The function used to compare to CAN receiver keys.
void can_net_destroy(can_net_t *net)
Destroys a CAN network interface.
void dlnode_remove(struct dlnode *node)
Removes node from a doubly-list.
struct rbnode node
The node of this receiver in the tree of receivers.
const void * key
A pointer to the key of this node.
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...
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int dlnode_insert_after(struct dlnode *prev, struct dlnode *node)
Inserts node after prev.
can_send_func_t * send_func
A pointer to the callback function invoked by can_net_send().
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.
struct dlnode * prev
A pointer to the previous node in the list.
can_recv_func_t * func
A pointer to the callback function invoked by can_net_recv().
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.
struct timespec next
The time at which the next timer triggers.
can_timer_func_t * func
A pointer to the callback function invoked by can_net_set_time().
A node in a red-black tree.
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.
#define dlnode_foreach(first, node)
Iterates in order over each node in a doubly-linked list.
struct rbtree recv_tree
The tree containing all receivers.
void rbtree_init(struct rbtree *tree, rbtree_cmp_t *cmp)
Initializes a red-black tree.
void can_timer_destroy(can_timer_t *timer)
Destroys a CAN timer.
struct timespec time
The current time.
can_net_t * net
A pointer to the network interface with which this timer is registered.
A node in a doubly-linked list.
struct timespec interval
The interval between successive triggers.
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.
void rbtree_remove(struct rbtree *tree, struct rbnode *node)
Removes a node from a red-black tree.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
const void * key
A pointer to the key for this node.
int can_net_send(can_net_t *net, const struct can_msg *msg)
Sends a CAN frame from a network interface.
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...
struct pnode * pheap_first(const struct pheap *heap)
Returns a pointer to the first (minimum) node in a pairing heap.
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 * send_data
A pointer to the user-specified data for send_func.
void can_recv_stop(can_recv_t *recv)
Stops a CAN frame receiver from processing frames and unregisters it with the network interface.
struct pnode node
The node of this timer in the tree of timers.
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...
@ CAN_FLAG_IDE
The Identifier Extension (IDE) flag.
void timespec_add(struct timespec *tp, const struct timespec *inc)
Adds the time interval *inc to the time at tp.
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_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.
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).
void * data
A pointer to the user-specified data for func.
void rbnode_init(struct rbnode *node, const void *key)
Initializes a node in a red-black tree.
@ ERRNUM_NOSYS
Function not supported.
uint_least32_t id
The identifier (11 or 29 bits, depending on the CAN_FLAG_IDE flag).
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.
can_recv_key_t key
The key used in node.
void pheap_remove(struct pheap *heap, struct pnode *node)
Removes a node from a pairing heap.