can/raw.h

Definitions high-level RAW CAN interface.

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

RAW_CAN_DEV_UNDEF

Default value for undefined interface number.

1
(-1)
int raw_can_send(int ifnum, const struct can_frame * frame, kernel_types.h::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

ifnum:the interface number to send to
frame:the frame to send
pid:the user thread id to whom the result msg will be sent it can be THREAD_PID_UNDEF if no feedback is expected

Return values

  • a positive handle identifying the sent frame on success
  • < 0 on error
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

ifnum:the interface number used to send the frame
handle:the handle of the frame to abort, it must be the value returned by raw_can_send

Return values

  • 0 on succes
  • < 0 on error (-ENODEV)
int raw_can_subscribe_rx(int ifnum, struct can_filter * filter, kernel_types.h::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

ifnum:the interface number to listen
filter:the list of filter to receive
pid:the thread id of the user
param:optional user parameter

Return values

  • the ifnum on success
  • < 0 on error
int raw_can_unsubscribe_rx(int ifnum, struct can_filter * filter, kernel_types.h::kernel_pid_t pid, void * param)

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

Parameters

ifnum:the interface number
filter:the filter to remove
pid:the thread id of the user
param:optional user parameter

Return values

  • 0 on success
  • < 0 on error
int raw_can_free_frame(sys/include/can/common.h::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

frame:the frame to free, it must be a pointer to a frame received by the stack

Return values

  • 0 on success
  • < 0 on error
int raw_can_get_can_opt(int ifnum, can_opt_t * opt)

Get a CAN option opt from interface ifnum.

Parameters

ifnum:the interface number
opt:the option to get

Return values

  • 0 on success
  • < 0 on error
int raw_can_set_can_opt(int ifnum, can_opt_t * opt)

Set a CAN option opt to interface ifnum.

Parameters

ifnum:the interface number
opt:the option to set

Return values

  • 0 on success
  • < 0 on error
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

ifnum:the interface number to send to
frame:the frame to send
mbox:the user mbox to whom the result msg will be sent it can be NULL if no feedback is expected

Return values

  • a positive handle identifying the sent frame on success
  • < 0 on error
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

ifnum:the interface number to listen
filter:the list of filter to receive
mbox:the mbox of the user
param:optional user parameter

Return values

  • the ifnum on success
  • < 0 on error
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

ifnum:the interface number
filter:the filter to remove
mbox:the mbox of the user
param:optional user parameter

Return values

  • 0 on success
  • < 0 on error
int raw_can_power_down(int ifnum)

Power down a given interface.

Parameters

ifnum:the interface number to power down

Return values

  • 0 on success
  • < 0 on error
int raw_can_power_up(int ifnum)

Power up a given interface.

Parameters

ifnum:the interface number to power up

Return values

  • 0 on success
  • < 0 on error
int raw_can_get_ifnum_by_name(const char * name)

Get the interface number of a given interface.

Parameters

name:interface name

Return values

  • the interface number, RAW_CAN_DEV_UNDEF if not defined
const char * raw_can_get_name_by_ifnum(int ifnum)

Get the interface name of a given interface number.

Parameters

ifnum:interface number

Return values

  • the interface name, NULL if no interface registered with this number
device.h::candev_dev_t * raw_can_get_dev_by_ifnum(int ifnum)

Get the candev descriptor from a given interface number.

Parameters

ifnum:interface number

Return values

  • pointer to a candev descriptor, NULL if no interface is registered with this number
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

ifnum:the interface number
bitrate:the bitrate in bits/s
sample_point:the sample point in tenth of percent (875 = 87.5%) if not set, the default value of 87.5% is used

Return values

  • 0 on success
  • 1 if the bitrate/sample_point couple can not be reached precisely but the bitrate is set
  • < 0 on error
int raw_can_set_trx(int ifnum, can_trx.h::can_trx_t * trx)

Set a transceiver for a given interface.

The interface must be powered down before changing the transceiver.

Parameters

ifnum:the interface number
trx:the transceiver to set

Return values

  • 0 on success
  • < 0 on error (-EBUSY if device is not powered down)