Lely core libraries 2.3.4
net.c File Reference

This file is part of the CAN library; it contains the implementation of the CAN network interface. More...

#include "can.h"
#include <lely/can/net.h>
#include <lely/util/cmp.h>
#include <lely/util/dllist.h>
#include <lely/util/errnum.h>
#include <lely/util/pheap.h>
#include <lely/util/rbtree.h>
#include <lely/util/time.h>
#include <assert.h>
#include <stdlib.h>
Include dependency graph for net.c:

Go to the source code of this file.

Data Structures

struct  __can_net
 A CAN network interface. More...
 
struct  __can_timer
 A CAN timer. More...
 
struct  __can_recv
 A CAN frame receiver. More...
 

Functions

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.
 
static uint_least64_t can_recv_key (uint_least32_t id, uint_least8_t flags)
 Computes a CAN receiver key from a CAN identifier and flags.
 
can_net_tcan_net_create (void)
 Creates a new CAN network interface.
 
void can_net_destroy (can_net_t *net)
 Destroys a CAN network interface.
 
void can_net_get_time (const can_net_t *net, struct timespec *tp)
 Retrieves the current time of a CAN network interface.
 
int can_net_set_time (can_net_t *net, const struct timespec *tp)
 Sets the current time of a CAN network interface.
 
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 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).
 
int can_net_send (can_net_t *net, const struct can_msg *msg)
 Sends a CAN frame from a network interface.
 
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 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.
 
can_timer_tcan_timer_create (void)
 Creates a new CAN timer.
 
void can_timer_destroy (can_timer_t *timer)
 Destroys a CAN timer.
 
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_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 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_timer_stop (can_timer_t *timer)
 Stops a CAN timer and unregisters it with a network interface.
 
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.
 
can_recv_tcan_recv_create (void)
 Creates a new CAN frame receiver.
 
void can_recv_destroy (can_recv_t *recv)
 Destroys a CAN frame receiver.
 
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 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 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 can_recv_stop (can_recv_t *recv)
 Stops a CAN frame receiver from processing frames and unregisters it with the network interface.
 

Detailed Description

This file is part of the CAN library; it contains the implementation of the CAN network interface.

See also
lely/can/net.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

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 net.c.

Function Documentation

◆ can_net_create()

can_net_t * can_net_create ( void  )

Creates a new CAN network interface.

See also
can_net_destroy()

Definition at line 162 of file net.c.

◆ can_net_destroy()

void can_net_destroy ( can_net_t net)

Destroys a CAN network interface.

See also
can_net_create()

Definition at line 187 of file net.c.

◆ can_net_get_time()

void can_net_get_time ( const can_net_t net,
struct timespec tp 
)

Retrieves the current time of a CAN network interface.

Parameters
neta pointer to a CAN network interface.
tpthe address at which to store the current time (can be NULL).
See also
can_net_set_time()

Definition at line 196 of file net.c.

◆ can_net_set_time()

int can_net_set_time ( can_net_t net,
const struct timespec tp 
)

Sets the current time of a CAN network interface.

This MAY invoke one or more CAN timer callback functions.

Parameters
neta pointer to a CAN network interface.
tpa pointer to the current time.
Returns
0 on success, or -1 on error. In the latter case, the error number set by the first failed CAN timer callback function can be obtained with get_errc().
See also
can_net_get_time()

Definition at line 205 of file net.c.

◆ can_net_get_next_func()

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.

Parameters
neta pointer to a CAN network interface.
pfuncthe address at which to store a pointer to the callback function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
can_net_set_next_func()

Definition at line 249 of file net.c.

◆ can_net_set_next_func()

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.

Parameters
neta pointer to a CAN network interface.
funca pointer to the function to be invoked by can_net_send().
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
can_net_get_next_func()

Definition at line 261 of file net.c.

◆ can_net_recv()

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).

This function MAY invoke on or more CAN frame receiver callback functions.

Parameters
neta pointer to a CAN network interface.
msga pointer to the CAN frame to be processed.
Returns
0 on success, or -1 on error. In the latter case, the error number set by the first failed CAN frame receiver callback function can be obtained with get_errc().

Definition at line 270 of file net.c.

◆ can_net_send()

int can_net_send ( can_net_t net,
const struct can_msg msg 
)

Sends a CAN frame from a network interface.

This function invokes the callback function set by can_net_set_send_func().

Parameters
neta pointer to a CAN network interface.
msga pointer to the CAN frame to be sent.
Returns
0 on success, or -1 on error. In the latter case, the error number set by the CAN send callback function can be obtained with get_errc().

Definition at line 300 of file net.c.

◆ can_net_get_send_func()

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.

Parameters
neta pointer to a CAN network interface.
pfuncthe address at which to store a pointer to the callback function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
can_net_set_send_func()

Definition at line 314 of file net.c.

◆ can_net_set_send_func()

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.

Parameters
neta pointer to a CAN network interface.
funca pointer to the function to be invoked by can_net_send().
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
can_net_get_send_func()

Definition at line 326 of file net.c.

◆ can_timer_create()

can_timer_t * can_timer_create ( void  )

Creates a new CAN timer.

See also
can_timer_destroy()

Definition at line 376 of file net.c.

◆ can_timer_destroy()

void can_timer_destroy ( can_timer_t timer)

Destroys a CAN timer.

See also
can_timer_create()

Definition at line 401 of file net.c.

◆ can_timer_get_func()

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.

Parameters
timera pointer to a CAN timer.
pfuncthe address at which to store a pointer to the callback function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
can_timer_set_func()

Definition at line 410 of file net.c.

◆ can_timer_set_func()

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.

Parameters
timera pointer to a CAN timer.
funca pointer to the function to be invoked by can_net_set_time().
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
can_timer_get_func()

Definition at line 422 of file net.c.

◆ can_timer_start()

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.

Parameters
timera pointer to a CAN timer.
neta pointer to a CAN network interface.
starta pointer to the absolute time of the next trigger of the timer. If start is NULL, the next trigger time is given by interval with respect to the current time as obtained with can_net_get_time(). If interval is also NULL, the timer is stopped.
intervala pointer to the interval between successive triggers of the timer. If interval is NULL, the timer only triggers once, at the time given by start.
See also
can_timer_stop()

Definition at line 431 of file net.c.

◆ can_timer_stop()

void can_timer_stop ( can_timer_t timer)

Stops a CAN timer and unregisters it with a network interface.

See also
can_timer_start()

Definition at line 462 of file net.c.

◆ can_timer_timeout()

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.

The timer will trigger only once.

Parameters
timera pointer to a CAN timer.
neta pointer to a CAN network interface.
timeoutthe timeout (in milliseconds) with respect to the current time as obtained with can_net_get_time(). If timeout is negative, the timer is stopped.
See also
can_timer_start(), can_timer_stop()

Definition at line 478 of file net.c.

◆ can_recv_create()

can_recv_t * can_recv_create ( void  )

Creates a new CAN frame receiver.

See also
can_recv_destroy()

Definition at line 533 of file net.c.

◆ can_recv_destroy()

void can_recv_destroy ( can_recv_t recv)

Destroys a CAN frame receiver.

See also
can_recv_create()

Definition at line 558 of file net.c.

◆ can_recv_get_func()

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.

Parameters
recva pointer to a CAN frame receiver.
pfuncthe address at which to store a pointer to the callback function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
can_recv_set_func()

Definition at line 567 of file net.c.

◆ can_recv_set_func()

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.

Parameters
recva pointer to a CAN frame receiver.
funca pointer to the function to be invoked by can_net_recv().
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to func.
See also
can_recv_get_func()

Definition at line 578 of file net.c.

◆ can_recv_start()

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.

Parameters
recva pointer to a CAN frame receiver.
neta pointer to a CAN network interface.
idthe CAN identifier for which the receiver should be invoked.
flagsthe flags that should be set in every accepted frame.
See also
can_recv_stop()

Definition at line 587 of file net.c.

◆ can_recv_stop()

void can_recv_stop ( can_recv_t recv)

Stops a CAN frame receiver from processing frames and unregisters it with the network interface.

See also
can_recv_start()

Definition at line 609 of file net.c.