Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
CAN ISO-TP Interface

CAN ISO-TP Interf. More...

Data Structures

struct  isotp_msg_id
 ISO-TP message id struct. More...
 
struct  isotp_fc_opts
 ISO-TP frame control options struct. More...
 

Macros

#define ISOTP_N_OK   0
 
#define ISOTP_N_TIMEOUT_A   -1
 
#define ISOTP_N_TIMEOUT_BS   -2
 
#define ISOTP_N_TIMEOUT_CR   -3
 
#define ISOTP_N_WRONG_SN   -4
 
#define ISOTP_N_INVALID_FS   -5
 
#define ISOTP_N_UNEXP_PDU   -6
 
#define ISOTP_N_WFT_OVRN   -7
 
#define ISOTP_N_BUFFER_OVERFLW   -8
 
#define ISOTP_N_ERROR   -9
 
#define ISOTP_NO_FREE_FILTER   -10
 
#define ISOTP_NO_NET_BUF_LEFT   -11
 
#define ISOTP_NO_BUF_DATA_LEFT   -12
 
#define ISOTP_NO_CTX_LEFT   -13
 
#define ISOTP_RECV_TIMEOUT   -14
 
#define ISOTP_FIXED_ADDR_SA_POS   (0U)
 
#define ISOTP_FIXED_ADDR_SA_MASK   (0xFF << ISOTP_FIXED_ADDR_SA_POS)
 
#define ISOTP_FIXED_ADDR_TA_POS   (8U)
 
#define ISOTP_FIXED_ADDR_TA_MASK   (0xFF << ISOTP_FIXED_ADDR_TA_POS)
 
#define ISOTP_FIXED_ADDR_PRIO_POS   (26U)
 
#define ISOTP_FIXED_ADDR_PRIO_MASK   (0x7 << ISOTP_FIXED_ADDR_PRIO_POS)
 
#define ISOTP_FIXED_ADDR_RX_MASK   (0x03FFFF00)
 

Typedefs

typedef void(* isotp_tx_callback_t) (int error_nr, void *arg)
 

Functions

int isotp_bind (struct isotp_recv_ctx *ctx, const struct device *can_dev, const struct isotp_msg_id *rx_addr, const struct isotp_msg_id *tx_addr, const struct isotp_fc_opts *opts, k_timeout_t timeout)
 Bind an address to a receiving context. More...
 
void isotp_unbind (struct isotp_recv_ctx *ctx)
 Unbind a context from the interface. More...
 
int isotp_recv (struct isotp_recv_ctx *ctx, uint8_t *data, size_t len, k_timeout_t timeout)
 Read out received data from fifo. More...
 
int isotp_recv_net (struct isotp_recv_ctx *ctx, struct net_buf **buffer, k_timeout_t timeout)
 Get the net buffer on data reception. More...
 
int isotp_send (struct isotp_send_ctx *ctx, const struct device *can_dev, const uint8_t *data, size_t len, const struct isotp_msg_id *tx_addr, const struct isotp_msg_id *rx_addr, isotp_tx_callback_t complete_cb, void *cb_arg)
 Send data. More...
 

Detailed Description

CAN ISO-TP Interf.

Macro Definition Documentation

◆ ISOTP_FIXED_ADDR_PRIO_MASK

#define ISOTP_FIXED_ADDR_PRIO_MASK   (0x7 << ISOTP_FIXED_ADDR_PRIO_POS)

#include <include/canbus/isotp.h>

Mask for priority in fixed addressing mode

◆ ISOTP_FIXED_ADDR_PRIO_POS

#define ISOTP_FIXED_ADDR_PRIO_POS   (26U)

#include <include/canbus/isotp.h>

Position of priority in fixed addressing mode

◆ ISOTP_FIXED_ADDR_RX_MASK

#define ISOTP_FIXED_ADDR_RX_MASK   (0x03FFFF00)

◆ ISOTP_FIXED_ADDR_SA_MASK

#define ISOTP_FIXED_ADDR_SA_MASK   (0xFF << ISOTP_FIXED_ADDR_SA_POS)

#include <include/canbus/isotp.h>

Mask to obtain fixed source address (SA)

◆ ISOTP_FIXED_ADDR_SA_POS

#define ISOTP_FIXED_ADDR_SA_POS   (0U)

#include <include/canbus/isotp.h>

Position of fixed source address (SA)

◆ ISOTP_FIXED_ADDR_TA_MASK

#define ISOTP_FIXED_ADDR_TA_MASK   (0xFF << ISOTP_FIXED_ADDR_TA_POS)

#include <include/canbus/isotp.h>

Mask to obtain fixed target address (TA)

◆ ISOTP_FIXED_ADDR_TA_POS

#define ISOTP_FIXED_ADDR_TA_POS   (8U)

#include <include/canbus/isotp.h>

Position of fixed target address (TA)

◆ ISOTP_N_BUFFER_OVERFLW

#define ISOTP_N_BUFFER_OVERFLW   -8

#include <include/canbus/isotp.h>

FlowStatus OVFLW PDU was received

◆ ISOTP_N_ERROR

#define ISOTP_N_ERROR   -9

#include <include/canbus/isotp.h>

General error

◆ ISOTP_N_INVALID_FS

#define ISOTP_N_INVALID_FS   -5

#include <include/canbus/isotp.h>

Invalid flow status received

◆ ISOTP_N_OK

#define ISOTP_N_OK   0

#include <include/canbus/isotp.h>

Completed successfully

◆ ISOTP_N_TIMEOUT_A

#define ISOTP_N_TIMEOUT_A   -1

#include <include/canbus/isotp.h>

Ar/As has timed out

◆ ISOTP_N_TIMEOUT_BS

#define ISOTP_N_TIMEOUT_BS   -2

#include <include/canbus/isotp.h>

Reception of next FC has timed out

◆ ISOTP_N_TIMEOUT_CR

#define ISOTP_N_TIMEOUT_CR   -3

#include <include/canbus/isotp.h>

Cr has timed out

◆ ISOTP_N_UNEXP_PDU

#define ISOTP_N_UNEXP_PDU   -6

#include <include/canbus/isotp.h>

Unexpected PDU received

◆ ISOTP_N_WFT_OVRN

#define ISOTP_N_WFT_OVRN   -7

#include <include/canbus/isotp.h>

Maximum number of WAIT flowStatus PDUs exceeded

◆ ISOTP_N_WRONG_SN

#define ISOTP_N_WRONG_SN   -4

#include <include/canbus/isotp.h>

Unexpected sequence number

◆ ISOTP_NO_BUF_DATA_LEFT

#define ISOTP_NO_BUF_DATA_LEFT   -12

#include <include/canbus/isotp.h>

Not sufficient space in the buffer left for the data

◆ ISOTP_NO_CTX_LEFT

#define ISOTP_NO_CTX_LEFT   -13

#include <include/canbus/isotp.h>

No context buffer left to allocate

◆ ISOTP_NO_FREE_FILTER

#define ISOTP_NO_FREE_FILTER   -10

#include <include/canbus/isotp.h>

Implementation specific errors Can't bind or send because the CAN device has no filter left

◆ ISOTP_NO_NET_BUF_LEFT

#define ISOTP_NO_NET_BUF_LEFT   -11

#include <include/canbus/isotp.h>

No net buffer left to allocate

◆ ISOTP_RECV_TIMEOUT

#define ISOTP_RECV_TIMEOUT   -14

#include <include/canbus/isotp.h>

Timeout for recv

Typedef Documentation

◆ isotp_tx_callback_t

typedef void(* isotp_tx_callback_t) (int error_nr, void *arg)

Function Documentation

◆ isotp_bind()

int isotp_bind ( struct isotp_recv_ctx *  ctx,
const struct device can_dev,
const struct isotp_msg_id rx_addr,
const struct isotp_msg_id tx_addr,
const struct isotp_fc_opts opts,
k_timeout_t  timeout 
)

#include <include/canbus/isotp.h>

Bind an address to a receiving context.

This function binds an RX and TX address combination to an RX context. When data arrives from the specified address, it is buffered and can be read by calling isotp_recv. When calling this routine, a filter is applied in the CAN device, and the context is initialized. The context must be valid until calling unbind.

Parameters
ctxContext to store the internal states.
can_devThe CAN device to be used for sending and receiving.
rx_addrIdentifier for incoming data.
tx_addrIdentifier for FC frames.
optsFlow control options.
timeoutTimeout for FF SF buffer allocation.
Return values
ISOTP_N_OKon success
ISOTP_NO_FREE_FILTERif CAN device has no filters left.

◆ isotp_recv()

int isotp_recv ( struct isotp_recv_ctx *  ctx,
uint8_t data,
size_t  len,
k_timeout_t  timeout 
)

#include <include/canbus/isotp.h>

Read out received data from fifo.

This function reads the data from the receive FIFO of the context. It blocks if the FIFO is empty. If an error occurs, the function returns a negative number and leaves the data buffer unchanged.

Parameters
ctxContext that is already bound.
dataPointer to a buffer where the data is copied to.
lenSize of the buffer.
timeoutTimeout for incoming data.
Return values
Numberof bytes copied on success
ISOTP_WAIT_TIMEOUTwhen "timeout" timed out
ISOTP_N_*on error

◆ isotp_recv_net()

int isotp_recv_net ( struct isotp_recv_ctx *  ctx,
struct net_buf **  buffer,
k_timeout_t  timeout 
)

#include <include/canbus/isotp.h>

Get the net buffer on data reception.

This function reads incoming data into net-buffers. It blocks until the entire packet is received, BS is reached, or an error occurred. If BS was zero, the data is in a single net_buf. Otherwise, the data is fragmented in chunks of BS size. The net-buffers are referenced and must be freed with net_buf_unref after the data is processed.

Parameters
ctxContext that is already bound.
bufferPointer where the net_buf pointer is written to.
timeoutTimeout for incoming data.
Return values
Remainingdata length for this transfer if BS > 0, 0 for BS = 0
ISOTP_WAIT_TIMEOUTwhen "timeout" timed out
ISOTP_N_*on error

◆ isotp_send()

int isotp_send ( struct isotp_send_ctx *  ctx,
const struct device can_dev,
const uint8_t data,
size_t  len,
const struct isotp_msg_id tx_addr,
const struct isotp_msg_id rx_addr,
isotp_tx_callback_t  complete_cb,
void cb_arg 
)

#include <include/canbus/isotp.h>

Send data.

This function is used to send data to a peer that listens to the tx_addr. An internal work-queue is used to transfer the segmented data. Data and context must be valid until the transmission has finished. If a complete_cb is given, this function is non-blocking, and the callback is called on completion with the return value as a parameter.

Parameters
ctxContext to store the internal states.
can_devThe CAN device to be used for sending and receiving.
dataData to be sent.
lenLength of the data to be sent.
rx_addrIdentifier for FC frames.
tx_addrIdentifier for outgoing frames the receiver listens on.
complete_cbFunction called on completion or NULL.
cb_argArgument passed to the complete callback.
Return values
ISOTP_N_OKon success
ISOTP_N_*on error

◆ isotp_unbind()

void isotp_unbind ( struct isotp_recv_ctx *  ctx)

#include <include/canbus/isotp.h>

Unbind a context from the interface.

This function removes the binding from isotp_bind. The filter is detached from the CAN device, and if a transmission is ongoing, buffers are freed. The context can be discarded safely after calling this function.

Parameters
ctxContext that should be unbound.