libsocketcan  v0.0.5
External API

Functions

int can_do_start (const char *name)
 can_do_start - start the can interface More...
 
int can_do_stop (const char *name)
 can_do_stop - stop the can interface More...
 
int can_do_restart (const char *name)
 can_do_restart - restart the can interface More...
 
int can_set_restart_ms (const char *name, __u32 restart_ms)
 can_set_restart_ms - set interval of auto restart. More...
 
int can_set_ctrlmode (const char *name, struct can_ctrlmode *cm)
 can_set_ctrlmode - setup the control mode. More...
 
int can_set_bittiming (const char *name, struct can_bittiming *bt)
 can_set_bittiming - setup the bittiming. More...
 
int can_set_bitrate (const char *name, __u32 bitrate)
 can_set_bitrate - setup the bitrate. More...
 
int can_set_bitrate_samplepoint (const char *name, __u32 bitrate, __u32 sample_point)
 can_set_bitrate_samplepoint - setup the bitrate. More...
 
int can_get_state (const char *name, int *state)
 can_get_state - get the current state of the device More...
 
int can_get_restart_ms (const char *name, __u32 *restart_ms)
 can_get_restart_ms - get the current interval of auto restarting. More...
 
int can_get_bittiming (const char *name, struct can_bittiming *bt)
 can_get_bittiming - get the current bittimnig configuration. More...
 
int can_get_ctrlmode (const char *name, struct can_ctrlmode *cm)
 can_get_ctrlmode - get the current control mode. More...
 
int can_get_clock (const char *name, struct can_clock *clock)
 can_get_clock - get the current clock struct. More...
 
int can_get_bittiming_const (const char *name, struct can_bittiming_const *btc)
 can_get_bittiming_const - get the current bittimnig constant. More...
 
int can_get_berr_counter (const char *name, struct can_berr_counter *bc)
 can_get_berr_counter - get the tx/rx error counter. More...
 
int can_get_device_stats (const char *name, struct can_device_stats *cds)
 can_get_device_stats - get the can_device_stats. More...
 
int can_get_link_stats (const char *name, struct rtnl_link_stats64 *rls)
 can_get_link_statistics - get RX/TX statistics (64 bits version) More...
 

Detailed Description

Function Documentation

◆ can_do_restart()

int can_do_restart ( const char *  name)

can_do_restart - restart the can interface

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"

This triggers the start mode of the can device.

NOTE:

  • restart mode can only be triggerd if the device is in BUS_OFF and the auto restart not turned on (restart_ms == 0)
Returns
0 if success
-1 if failed

References can_get_restart_ms(), can_get_state(), and set_link().

Here is the call graph for this function:

◆ can_do_start()

int can_do_start ( const char *  name)

can_do_start - start the can interface

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"

This starts the can interface with the given name. It simply changes the if state of the interface to up. All initialisation works will be done in kernel. The if state can also be queried by a simple ifconfig.

Returns
0 if success
-1 if failed

References set_link().

Here is the call graph for this function:

◆ can_do_stop()

int can_do_stop ( const char *  name)

can_do_stop - stop the can interface

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"

This stops the can interface with the given name. It simply changes the if state of the interface to down. Any running communication would be stopped.

Returns
0 if success
-1 if failed

References set_link().

Here is the call graph for this function:

◆ can_get_berr_counter()

int can_get_berr_counter ( const char *  name,
struct can_berr_counter bc 
)

can_get_berr_counter - get the tx/rx error counter.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
bcpointer to the error counter struct..

This one gets the current rx/tx error counter from the hardware.

__u16 txerr;
__u16 rxerr;
};
Returns
0 if success
-1 if failed

References get_link().

Here is the call graph for this function:

◆ can_get_bittiming()

int can_get_bittiming ( const char *  name,
struct can_bittiming bt 
)

can_get_bittiming - get the current bittimnig configuration.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
btpointer to the bittiming struct.

This one stores the current bittiming configuration.

Please see can_set_bittiming for more information about bit timing.

Returns
0 if success
-1 if failed

References get_link().

Here is the call graph for this function:

◆ can_get_bittiming_const()

int can_get_bittiming_const ( const char *  name,
struct can_bittiming_const btc 
)

can_get_bittiming_const - get the current bittimnig constant.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
btcpointer to the bittiming constant struct.

This one stores the hardware dependent bittiming constant. The can_bittiming_const struct consists:

char name[16];
__u32 tseg1_min;
__u32 tseg1_max;
__u32 tseg2_min;
__u32 tseg2_max;
__u32 sjw_max;
__u32 brp_min;
__u32 brp_max;
__u32 brp_inc;
};

The information in this struct is used to calculate the bus bit timing automatically.

Returns
0 if success
-1 if failed

References get_link().

Here is the call graph for this function:

◆ can_get_clock()

int can_get_clock ( const char *  name,
struct can_clock clock 
)

can_get_clock - get the current clock struct.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
clockpointer to the clock struct.

This one stores the current clock configuration. At the time of writing the can_clock struct only contains information about the clock frequecy. This information is e.g. essential while setting up the bit timing.

Returns
0 if success
-1 if failed

References get_link().

Here is the call graph for this function:

◆ can_get_ctrlmode()

int can_get_ctrlmode ( const char *  name,
struct can_ctrlmode cm 
)

can_get_ctrlmode - get the current control mode.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
cmpointer to the ctrlmode struct.

This one stores the current control mode configuration.

Please see can_set_ctrlmode for more information about control modes.

Returns
0 if success
-1 if failed

References get_link().

Here is the call graph for this function:

◆ can_get_device_stats()

int can_get_device_stats ( const char *  name,
struct can_device_stats cds 
)

can_get_device_stats - get the can_device_stats.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
bcpointer to the error counter struct..

This one gets the current can_device_stats.

Please see struct can_device_stats for more information.

Returns
0 if success
-1 if failed

References get_link().

Here is the call graph for this function:

◆ can_get_link_stats()

int can_get_link_stats ( const char *  name,
struct rtnl_link_stats64 *  rls 
)

can_get_link_statistics - get RX/TX statistics (64 bits version)

Parameters
namename of the can device. This is the netdev name, as ip link shows in your system. usually it contains prefix "can" and the number of the can line. e.g. "can0"
rlspointer to the rtnl_link_stats64 struct which is from if_link.h.

This one gets the current rtnl_link_stats64. Compares to the rtnl_link_stats, The rtnl_link_stats64 is introduced since linux kernel 2.6. After that the rtnl_link_stats is synchronous with struct rtnl_link_stats64 by truncating each member from 64 bits to 32 bits. actually, the struct rtnl_link_stats is kept for compatibility.

Please see struct rtnl_link_stats64 (/usr/include/linux/if_link.h) for more information.

Returns
0 if success
-1 if failed

References get_link().

Here is the call graph for this function:

◆ can_get_restart_ms()

int can_get_restart_ms ( const char *  name,
__u32 *  restart_ms 
)

can_get_restart_ms - get the current interval of auto restarting.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
restart_mspointer to store the value.

This one stores the current interval of auto restarting into the given pointer.

The socketcan framework can automatically restart a device if it is in bus_off in a given interval. This function gets this value in milliseconds. restart_ms == 0 means that autorestarting is turned off.

Returns
0 if success
-1 if failed

References get_link().

Referenced by can_do_restart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ can_get_state()

int can_get_state ( const char *  name,
int *  state 
)

can_get_state - get the current state of the device

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
statepointer to store the state

This one stores the current state of the can interface into the given pointer. Valid states are:

  • CAN_STATE_ERROR_ACTIVE
  • CAN_STATE_ERROR_WARNING
  • CAN_STATE_ERROR_PASSIVE
  • CAN_STATE_BUS_OFF
  • CAN_STATE_STOPPED
  • CAN_STATE_SLEEPING

The first four states is determined by the value of RX/TX error counter. Please see relevant can specification for more information about this. A device in STATE_STOPPED is an inactive device. STATE_SLEEPING is not implemented on all devices.

Returns
0 if success
-1 if failed

References get_link().

Referenced by can_do_restart().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ can_set_bitrate()

int can_set_bitrate ( const char *  name,
__u32  bitrate 
)

can_set_bitrate - setup the bitrate.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
bitratebitrate of the can bus

This is the recommended way to setup the bus bit timing. You only have to give a bitrate value here. The exact bit timing will be calculated automatically. To use this function, make sure that CONFIG_CAN_CALC_BITTIMING is set to y in your kernel configuration. bitrate can be a value between 1000(1kbit/s) and 1000000(1000kbit/s).

Returns
0 if success
-1 if failed

References can_set_bittiming().

Here is the call graph for this function:

◆ can_set_bitrate_samplepoint()

int can_set_bitrate_samplepoint ( const char *  name,
__u32  bitrate,
__u32  sample_point 
)

can_set_bitrate_samplepoint - setup the bitrate.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
bitratebitrate of the can bus
sample_pointsample point value

This one is similar to can_set_bitrate, only you can additionally set up the time point for sampling (sample point) customly instead of using the CIA recommended value. sample_point can be a value between 0 and 999.

Returns
0 if success
-1 if failed

References can_set_bittiming().

Here is the call graph for this function:

◆ can_set_bittiming()

int can_set_bittiming ( const char *  name,
struct can_bittiming bt 
)

can_set_bittiming - setup the bittiming.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
btpointer to a can_bittiming struct

This sets the bittiming of the can device. This is for advantage usage. In normal cases you should use can_set_bitrate to simply define the bitrate and let the driver automatically calculate the bittiming. You will only need this function if you wish to define the bittiming in expert mode with fully manually defined timing values. You have to define the bittiming struct yourself. a can_bittiming struct consists of:

struct can_bittiming {
__u32 bitrate;
__u32 sample_point;
__u32 tq;
__u32 prop_seg;
__u32 phase_seg1;
__u32 phase_seg2;
__u32 sjw;
__u32 brp;
}

to define a customized bittiming, you have to define tq, prop_seq, phase_seg1, phase_seg2 and sjw. See http://www.can-cia.org/index.php?id=88 for more information about bittiming and synchronizations on can bus.

Returns
0 if success
-1 if failed

References set_link().

Referenced by can_set_bitrate(), and can_set_bitrate_samplepoint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ can_set_ctrlmode()

int can_set_ctrlmode ( const char *  name,
struct can_ctrlmode cm 
)

can_set_ctrlmode - setup the control mode.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
cmpointer of a can_ctrlmode struct

This sets the control mode of the can device. There are currently the following modes available (each mapped to its own macro):

#define CAN_CTRLMODE_LOOPBACK 0x01 // Loopback mode
#define CAN_CTRLMODE_LISTENONLY 0x02 // Listen-only mode
#define CAN_CTRLMODE_3_SAMPLES 0x04 // Triple sampling mode
#define CAN_CTRLMODE_ONE_SHOT 0x08 // One-Shot mode
#define CAN_CTRLMODE_BERR_REPORTING 0x10 // Bus-error reporting
#define CAN_CTRLMODE_FD 0x20 // CAN FD mode
#define CAN_CTRLMODE_PRESUME_ACK 0x40 // Ignore missing CAN ACKs

You have to define the control mode struct yourself. A can_ctrlmode struct is declared as:

struct can_ctrlmode {
__u32 mask;
__u32 flags;
}

You can use mask to select modes you want to control and flags to determine if you want to turn the selected mode(s) on or off. E. g. the following pseudocode will turn the loopback mode on and listenonly mode off:

struct can_ctrlmode cm;
memset(&cm, 0, sizeof(cm));
cm.mask = CAN_CTRLMODE_LOOPBACK | CAN_CTRLMODE_LISTENONLY;
cm.flags = CAN_CTRLMODE_LOOPBACK;
can_set_ctrlmode(candev, &cm);
Returns
0 if success
-1 if failed

References set_link().

Here is the call graph for this function:

◆ can_set_restart_ms()

int can_set_restart_ms ( const char *  name,
__u32  restart_ms 
)

can_set_restart_ms - set interval of auto restart.

Parameters
namename of the can device. This is the netdev name, as ifconfig -a shows in your system. usually it contains prefix "can" and the numer of the can line. e.g. "can0"
restart_msinterval of auto restart in milliseconds

This sets how often the device shall automatically restart the interface in case that a bus_off is detected.

Returns
0 if success
-1 if failed

References set_link().

Here is the call graph for this function: