Definitions high-level RAW CAN interface. More...

Detailed Description

Definitions high-level RAW CAN interface.

This file defines the high-level CAN interface to send and receive RAW CAN frame.

Author
Vincent Dupont vince.nosp@m.nt@o.nosp@m.takey.nosp@m.s.co.nosp@m.m
Toon Stegen toon..nosp@m.steg.nosp@m.en@al.nosp@m.tran.nosp@m..com
Aurelien Gonce aurel.nosp@m.ien..nosp@m.gonce.nosp@m.@alt.nosp@m.ran.c.nosp@m.om

Definition in file raw.h.

#include "sched.h"
#include "can/can.h"
#include "can/common.h"
#include "can/device.h"
+ Include dependency graph for raw.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

#define RAW_CAN_DEV_UNDEF   (-1)
 Default value for undefined interface number.
 
int raw_can_send (int ifnum, const struct can_frame *frame, kernel_pid_t pid)
 Send a CAN frame. More...
 
int raw_can_abort (int ifnum, int handle)
 Abort a CAN frame. More...
 
int raw_can_subscribe_rx (int ifnum, struct can_filter *filter, kernel_pid_t pid, void *param)
 Subscribe to a CAN filter. More...
 
int raw_can_unsubscribe_rx (int ifnum, struct can_filter *filter, kernel_pid_t pid, void *param)
 Unsubscribe from reception for the given CAN filter on pid thread. More...
 
int raw_can_free_frame (can_rx_data_t *frame)
 Free a received frame. More...
 
int raw_can_get_can_opt (int ifnum, can_opt_t *opt)
 Get a CAN option opt from interface ifnum. More...
 
int raw_can_set_can_opt (int ifnum, can_opt_t *opt)
 Set a CAN option opt to interface ifnum. More...
 
int raw_can_send_mbox (int ifnum, const struct can_frame *frame, mbox_t *mbox)
 Send a CAN frame. More...
 
int raw_can_subscribe_rx_mbox (int ifnum, struct can_filter *filter, mbox_t *mbox, void *param)
 Subscribe to a CAN filter. More...
 
int raw_can_unsubscribe_rx_mbox (int ifnum, struct can_filter *filter, mbox_t *mbox, void *param)
 Unsubscribe from reception for the given CAN filter and mbox. More...
 
int raw_can_power_down (int ifnum)
 Power down a given interface. More...
 
int raw_can_power_up (int ifnum)
 Power up a given interface. More...
 
int raw_can_get_ifnum_by_name (const char *name)
 Get the interface number of a given interface. More...
 
const char * raw_can_get_name_by_ifnum (int ifnum)
 Get the interface name of a given interface number. More...
 
candev_dev_traw_can_get_dev_by_ifnum (int ifnum)
 Get the candev descriptor from a given interface number. More...
 
int raw_can_set_bitrate (int ifnum, uint32_t bitrate, uint32_t sample_point)
 Set the given bitrate/sample_point to the given ifnum. More...
 
int raw_can_set_trx (int ifnum, can_trx_t *trx)
 Set a transceiver for a given interface. More...
 

Function Documentation

◆ raw_can_abort()

int raw_can_abort ( int  ifnum,
int  handle 
)

Abort a CAN frame.

Abort the frame identified by handle in the interface ifnum If no tx confirmation is received, this function must be called by the upper layer to ensure the driver frees its tx mailbox. The driver is not responsible of tx timeouts.

Parameters
[in]ifnumthe interface number used to send the frame
[in]handlethe handle of the frame to abort, it must be the value returned by raw_can_send
Returns
0 on success
< 0 on error (-ENODEV)

◆ raw_can_free_frame()

int raw_can_free_frame ( can_rx_data_t frame)

Free a received frame.

This function must be called by the user when a received frame is not needed anymore.

Parameters
[in]framethe frame to free, it must be a pointer to a frame received by the stack
Returns
0 on success
< 0 on error

◆ raw_can_get_can_opt()

int raw_can_get_can_opt ( int  ifnum,
can_opt_t opt 
)

Get a CAN option opt from interface ifnum.

Parameters
[in]ifnumthe interface number
[in,out]optthe option to get
Returns
0 on success
< 0 on error

◆ raw_can_get_dev_by_ifnum()

candev_dev_t* raw_can_get_dev_by_ifnum ( int  ifnum)

Get the candev descriptor from a given interface number.

Parameters
[in]ifnuminterface number
Returns
pointer to a candev descriptor, NULL if no interface is registered with this number

◆ raw_can_get_ifnum_by_name()

int raw_can_get_ifnum_by_name ( const char *  name)

Get the interface number of a given interface.

Parameters
[in]nameinterface name
Returns
the interface number, RAW_CAN_DEV_UNDEF if not defined

◆ raw_can_get_name_by_ifnum()

const char* raw_can_get_name_by_ifnum ( int  ifnum)

Get the interface name of a given interface number.

Parameters
[in]ifnuminterface number
Returns
the interface name, NULL if no interface registered with this number

◆ raw_can_power_down()

int raw_can_power_down ( int  ifnum)

Power down a given interface.

Parameters
[in]ifnumthe interface number to power down
Returns
0 on success
< 0 on error

◆ raw_can_power_up()

int raw_can_power_up ( int  ifnum)

Power up a given interface.

Parameters
[in]ifnumthe interface number to power up
Returns
0 on success
< 0 on error

◆ raw_can_send()

int raw_can_send ( int  ifnum,
const struct can_frame frame,
kernel_pid_t  pid 
)

Send a CAN frame.

Send a CAN frame through the ifnum interface. The result is sent to the pid thread via IPC.

Parameters
[in]ifnumthe interface number to send to
[in]framethe frame to send
[in]pidthe user thread id to whom the result msg will be sent it can be THREAD_PID_UNDEF if no feedback is expected
Returns
a positive handle identifying the sent frame on success
< 0 on error

◆ raw_can_send_mbox()

int raw_can_send_mbox ( int  ifnum,
const struct can_frame frame,
mbox_t mbox 
)

Send a CAN frame.

Send a CAN frame through the ifnum interface. The result is sent to the mbox thread via mailbox IPC.

Parameters
[in]ifnumthe interface number to send to
[in]framethe frame to send
[in]mboxthe user mbox to whom the result msg will be sent it can be NULL if no feedback is expected
Returns
a positive handle identifying the sent frame on success
< 0 on error

◆ raw_can_set_bitrate()

int raw_can_set_bitrate ( int  ifnum,
uint32_t  bitrate,
uint32_t  sample_point 
)

Set the given bitrate/sample_point to the given ifnum.

Set the given bitrate and sample_point to the given ifnum. This is a helper function which calculates the right bittiming from bitrate and sample_point.

Parameters
[in]ifnumthe interface number
[in]bitratethe bitrate in bits/s
[in]sample_pointthe sample point in tenth of percent (875 = 87.5%) if not set, the default value of 87.5% is used
Returns
0 on success
1 if the bitrate/sample_point couple can not be reached precisely but the bitrate is set
< 0 on error

◆ raw_can_set_can_opt()

int raw_can_set_can_opt ( int  ifnum,
can_opt_t opt 
)

Set a CAN option opt to interface ifnum.

Parameters
[in]ifnumthe interface number
[in,out]optthe option to set
Returns
0 on success
< 0 on error

◆ raw_can_set_trx()

int raw_can_set_trx ( int  ifnum,
can_trx_t trx 
)

Set a transceiver for a given interface.

The interface must be powered down before changing the transceiver.

Parameters
[in]ifnumthe interface number
[in]trxthe transceiver to set
Returns
0 on success
< 0 on error (-EBUSY if device is not powered down)

◆ raw_can_subscribe_rx()

int raw_can_subscribe_rx ( int  ifnum,
struct can_filter filter,
kernel_pid_t  pid,
void *  param 
)

Subscribe to a CAN filter.

This function must be called if a user thread pid wants to receive the CAN frame matching filter on the interface ifnum. The user thread will then receive msg via IPC on reception of frame matching filters.

Parameters
[in]ifnumthe interface number to listen
[in]filterthe list of filter to receive
[in]pidthe thread id of the user
[in]paramoptional user parameter
Returns
the ifnum on success
< 0 on error

◆ raw_can_subscribe_rx_mbox()

int raw_can_subscribe_rx_mbox ( int  ifnum,
struct can_filter filter,
mbox_t mbox,
void *  param 
)

Subscribe to a CAN filter.

This function must be called if a user thread waiting on mbox wants to receive the CAN frame matching filter on the interface ifnum. The user thread will then receive msg via mailbox IPC on reception of frame matching filters.

Currently only single frame ID (i.e. filters->can_mask = 0xFFFFFFFF) are supported.

Parameters
[in]ifnumthe interface number to listen
[in]filterthe list of filter to receive
[in]mboxthe mbox of the user
[in]paramoptional user parameter
Returns
the ifnum on success
< 0 on error

◆ raw_can_unsubscribe_rx()

int raw_can_unsubscribe_rx ( int  ifnum,
struct can_filter filter,
kernel_pid_t  pid,
void *  param 
)

Unsubscribe from reception for the given CAN filter on pid thread.

Parameters
[in]ifnumthe interface number
[in]filterthe filter to remove
[in]pidthe thread id of the user
[in]paramoptional user parameter
Returns
0 on success
< 0 on error

◆ raw_can_unsubscribe_rx_mbox()

int raw_can_unsubscribe_rx_mbox ( int  ifnum,
struct can_filter filter,
mbox_t mbox,
void *  param 
)

Unsubscribe from reception for the given CAN filter and mbox.

Parameters
[in]ifnumthe interface number
[in]filterthe filter to remove
[in]mboxthe mbox of the user
[in]paramoptional user parameter
Returns
0 on success
< 0 on error