File syn_isotp.h¶
FileList > proto > syn_isotp.h
Go to the source code of this file
ISO 15765-2 (DoCAN / ISO-TP) Multi-Frame CAN Transport Protocol. More...
#include "../common/syn_defs.h"#include "../drivers/syn_can.h"#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Classes¶
| Type | Name |
|---|---|
| struct | SYN_ISOTP_Link ISO 15765-2 Link Handle. |
Public Types¶
| Type | Name |
|---|---|
| enum | SYN_ISOTP_RxState ISO-TP Rx States. |
| enum | SYN_ISOTP_TxState ISO-TP Tx States. |
| typedef intptr_t | ssize_t |
Public Functions¶
| Type | Name |
|---|---|
| bool | syn_isotp_get_tx_frame (SYN_ISOTP_Link * link, SYN_CAN_Frame * frame) Retrieve next pending outgoing CAN frame from ISO-TP engine. |
| void | syn_isotp_init (SYN_ISOTP_Link * link, uint32_t rx_id, uint32_t tx_id, uint8_t * rx_buf, size_t rx_buf_size, uint8_t * tx_buf, size_t tx_buf_size) Initialize ISO-TP Link in Classic CAN mode (8-byte frames). |
| void | syn_isotp_process_rx_frame (SYN_ISOTP_Link * link, const SYN_CAN_Frame * frame) Process an incoming CAN frame into the ISO-TP engine. |
| ssize_t | syn_isotp_receive (SYN_ISOTP_Link * link, uint8_t * out_buf, size_t max_len) Read completed assembled message from ISO-TP receiver. |
| SYN_Status | syn_isotp_send (SYN_ISOTP_Link * link, const uint8_t * payload, size_t payload_len) Initiate transmission of a multi-byte payload. |
| void | syn_isotp_set_timeouts (SYN_ISOTP_Link * link, uint32_t n_bs_ms, uint32_t n_cr_ms) Configure custom ISO 15765-2 network layer timeouts. |
| void | syn_isotp_step (SYN_ISOTP_Link * link, uint32_t dt_ms) Step ISO-TP timers (milliseconds). |
| void | syn_isotp_step_us (SYN_ISOTP_Link * link, uint32_t dt_us) Step ISO-TP timers (microseconds for fine STmin pacing). |
Macros¶
| Type | Name |
|---|---|
| define | SYN_ISOTP_DEFAULT_N_BS_MS 1000UISO 15765-2 Network Layer Default Timeouts (ISO 15765-2:2016) |
| define | SYN_ISOTP_DEFAULT_N_CR_MS 1000U |
| define | SYN_ISOTP_FC_CTS 0x00UFlow Control Status (FC) |
| define | SYN_ISOTP_FC_OVERFLOW 0x02U |
| define | SYN_ISOTP_FC_WAIT 0x01U |
| define | SYN_ISOTP_MAX_PAYLOAD 4095UISO-TP Protocol Constants. |
| define | SYN_ISOTP_PCI_CF 0x20U |
| define | SYN_ISOTP_PCI_FC 0x30U |
| define | SYN_ISOTP_PCI_FF 0x10U |
| define | SYN_ISOTP_PCI_SF 0x00U |
| define | _SSIZE_T |
| define | _SSIZE_T_ |
| define | _SSIZE_T_DECLARED |
| define | _SSIZE_T_DEFINED |
| define | _SSIZE_T_DEFINED_ |
| define | __ssize_t_defined |
Detailed Description¶
Implements non-blocking, zero-malloc ISO 15765-2 segmentation & reassembly for multi-byte CAN payload transmission with Single Frame (SF), First Frame (FF), Consecutive Frame (CF), and Flow Control (FC) support.
Fully supports ISO 15765-2:2016 Full-Duplex communication mode (concurrent, non-blocking, bi-directional multi-frame transmission and reception on a single link context).
Support for CAN FD (64-byte payload frames & ISO 15765-2:2016 extended length) is opt-in via #define SYN_USE_CAN_FD 1.
Usage Example (STM32 / Hardware CAN Integration)¶
static SYN_ISOTP_Link isotp_link;
static uint8_t rx_buf[256];
static uint8_t tx_buf[256];
void app_init(void) {
// Init link: Rx CAN ID 0x7E8 (from ECU), Tx CAN ID 0x7E0 (to ECU)
syn_isotp_init(&isotp_link, 0x7E8, 0x7E0,
rx_buf, sizeof(rx_buf),
tx_buf, sizeof(tx_buf));
}
// 1. Called when STM32 CAN RX interrupt receives a CAN frame:
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan) {
CAN_RxHeaderTypeDef rx_hdr;
SYN_CAN_Frame frame;
HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rx_hdr, frame.data);
frame.id = rx_hdr.StdId;
frame.dlc = rx_hdr.DLC;
syn_isotp_process_rx_frame(&isotp_link, &frame);
}
// 2. Called in main loop / task:
void app_loop(void) {
// Step timers (1ms dt)
syn_isotp_step(&isotp_link, 1);
// Drain & transmit pending CAN frames generated by ISO-TP engine
SYN_CAN_Frame tx_frame;
while (syn_isotp_get_tx_frame(&isotp_link, &tx_frame)) {
CAN_TxHeaderTypeDef tx_hdr = { .StdId = tx_frame.id, .DLC = tx_frame.dlc };
uint32_t mailbox;
HAL_CAN_AddTxMessage(&hcan1, &tx_hdr, tx_frame.data, &mailbox);
}
// Read fully assembled received messages
uint8_t payload[128];
ssize_t len = syn_isotp_receive(&isotp_link, payload, sizeof(payload));
if (len > 0) {
// Process UDS diagnostic response...
}
}
Public Types Documentation¶
enum SYN_ISOTP_RxState¶
ISO-TP Rx States.
enum SYN_ISOTP_TxState¶
ISO-TP Tx States.
enum SYN_ISOTP_TxState {
SYN_ISOTP_TX_IDLE = 0,
SYN_ISOTP_TX_SEND_SF,
SYN_ISOTP_TX_SEND_FF,
SYN_ISOTP_TX_WAIT_FC,
SYN_ISOTP_TX_SEND_CF
};
typedef ssize_t¶
Public Functions Documentation¶
function syn_isotp_get_tx_frame¶
Retrieve next pending outgoing CAN frame from ISO-TP engine.
Parameters:
linkLink handle.frameOutput CAN frame buffer.
Returns:
true if a frame was generated, false otherwise.
function syn_isotp_init¶
Initialize ISO-TP Link in Classic CAN mode (8-byte frames).
void syn_isotp_init (
SYN_ISOTP_Link * link,
uint32_t rx_id,
uint32_t tx_id,
uint8_t * rx_buf,
size_t rx_buf_size,
uint8_t * tx_buf,
size_t tx_buf_size
)
Parameters:
linkLink handle.rx_idIncoming CAN identifier.tx_idOutgoing CAN identifier.rx_bufReceive assembly buffer.rx_buf_sizeReceive buffer capacity.tx_bufTransmit buffer.tx_buf_sizeTransmit buffer capacity.
function syn_isotp_process_rx_frame¶
Process an incoming CAN frame into the ISO-TP engine.
Parameters:
linkLink handle.frameIncoming CAN frame.
function syn_isotp_receive¶
Read completed assembled message from ISO-TP receiver.
Parameters:
linkLink handle.out_bufOutput buffer.max_lenCapacity of out_buf.
Returns:
Number of bytes copied, or -1 if no message ready.
function syn_isotp_send¶
Initiate transmission of a multi-byte payload.
Parameters:
linkLink handle.payloadPayload buffer.payload_lenLength of payload (1 to max buffer capacity).
Returns:
SYN_OK on success, error code on busy/invalid params.
function syn_isotp_set_timeouts¶
Configure custom ISO 15765-2 network layer timeouts.
Parameters:
linkLink handle.n_bs_msN_Bs max timeout in milliseconds (0 = use default 1000ms).n_cr_msN_Cr max timeout in milliseconds (0 = use default 1000ms).
function syn_isotp_step¶
Step ISO-TP timers (milliseconds).
Parameters:
linkLink handle.dt_msElapsed time in milliseconds.
function syn_isotp_step_us¶
Step ISO-TP timers (microseconds for fine STmin pacing).
Parameters:
linkLink handle.dt_usElapsed time in microseconds.
Macro Definition Documentation¶
define SYN_ISOTP_DEFAULT_N_BS_MS¶
ISO 15765-2 Network Layer Default Timeouts (ISO 15765-2:2016)
N_Bs max time for FC reception (1000 ms)
define SYN_ISOTP_DEFAULT_N_CR_MS¶
N_Cr max time for CF reception (1000 ms)
define SYN_ISOTP_FC_CTS¶
Flow Control Status (FC)
Continue To Send
define SYN_ISOTP_FC_OVERFLOW¶
Buffer Overflow
define SYN_ISOTP_FC_WAIT¶
Wait
define SYN_ISOTP_MAX_PAYLOAD¶
ISO-TP Protocol Constants.
Standard 12-bit max payload (Classic CAN)
define SYN_ISOTP_PCI_CF¶
Consecutive Frame
define SYN_ISOTP_PCI_FC¶
Flow Control Frame
define SYN_ISOTP_PCI_FF¶
First Frame
define SYN_ISOTP_PCI_SF¶
Single Frame
define _SSIZE_T¶
define _SSIZE_T_¶
define _SSIZE_T_DECLARED¶
define _SSIZE_T_DEFINED¶
define _SSIZE_T_DEFINED_¶
define __ssize_t_defined¶
The documentation for this class was generated from the following file src/syntropic/proto/syn_isotp.h