isotp-c
Platform-independent ISO 15765-2 transport for embedded C
Loading...
Searching...
No Matches
isotp.h
Go to the documentation of this file.
1
2// ___ ___ ___ _____ ___ ___ //
3// |_ _/ __|/ _ \_ _| _ \___ / __| //
4// | |\__ \ (_) || | | _/___| (__ //
5// |___|___/\___/ |_| |_| \___| //
6// //
8
9#ifndef ISOTPC_H
10#define ISOTPC_H
11
12#include <stdbool.h>
13#include <stdio.h>
14#include <string.h>
15
16#ifdef __cplusplus
17 #include <stdint.h>
18
19extern "C" {
20#endif
21
22#include "isotp_config.h"
23#include "isotp_defines.h"
24#include "isotp_user.h"
25
30
36
48typedef struct IsoTpLink {
50 /* sender parameters */
51 uint32_t send_arbitration_id;
52 uint8_t tx_dl;
53
54 uint8_t* send_buffer;
55 uint32_t send_buf_size;
56 uint32_t send_size;
57 uint32_t send_offset;
58
59 uint8_t send_sn;
60 uint32_t send_bs_remain;
61 uint32_t send_st_min_us;
62 uint8_t send_wtf_count;
63 uint32_t send_timer_st;
64 uint32_t send_timer_bs;
69 uint8_t send_status;
71
72 /* receiver parameters */
73 uint32_t receive_arbitration_id;
74 uint8_t rx_dl;
75
76 uint8_t* receive_buffer;
77 uint32_t receive_buf_size;
78 uint32_t receive_size;
79 uint32_t receive_offset;
80
81 uint8_t receive_sn;
82 uint8_t receive_bs_count;
83 uint32_t receive_timer_cr;
90
91#ifdef ISO_TP_ENABLE_STREAMING
92 uint32_t receive_stream_size;
93 uint8_t receive_streaming;
94 uint8_t receive_stream_carry_size;
95 uint8_t receive_stream_carry[ISO_TP_MAX_CAN_FRAME_SIZE - 1];
96#endif
98
99#if defined(ISO_TP_USER_SEND_CAN_ARG)
107#endif
108
110#ifdef ISO_TP_TRANSMIT_COMPLETE_CALLBACK
111 isotp_tx_done_cb tx_done_cb;
112 void* tx_done_cb_arg;
113#endif
114
115#ifdef ISO_TP_RECEIVE_COMPLETE_CALLBACK
116 isotp_rx_done_cb rx_done_cb;
117 void* rx_done_cb_arg;
118#endif
121
144void isotp_init_link(IsoTpLink* link, uint32_t sendid, uint8_t* sendbuf, uint32_t sendbufsize, uint8_t* recvbuf, uint32_t recvbufsize);
145
163int isotp_set_tx_dl(IsoTpLink* link, uint8_t tx_dl);
164
172uint8_t isotp_get_tx_dl(const IsoTpLink* link);
173
183
195void isotp_poll(IsoTpLink* link);
196
210void isotp_on_can_message(IsoTpLink* link, const uint8_t* data, uint8_t len);
211
232int isotp_send(IsoTpLink* link, const uint8_t payload[], uint32_t size);
233
252int isotp_send_with_id(IsoTpLink* link, uint32_t id, const uint8_t payload[], uint32_t size);
253
269int isotp_receive(IsoTpLink* link, uint8_t* payload, const uint32_t payload_size, uint32_t* out_size);
270
271#ifdef ISO_TP_ENABLE_STREAMING
291int isotp_receive_streaming(IsoTpLink* link, uint8_t* payload, const uint32_t payload_size, uint32_t* out_size, bool* is_complete);
292#endif
293
294#ifdef ISO_TP_TRANSMIT_COMPLETE_CALLBACK
307#endif
308
309#ifdef ISO_TP_RECEIVE_COMPLETE_CALLBACK
324void isotp_set_rx_done_cb(IsoTpLink* link, isotp_rx_done_cb cb, void* arg);
325#endif
326
328
329#ifdef __cplusplus
330}
331#endif
332
333#endif // ISOTPC_H
int isotp_send_with_id(IsoTpLink *link, uint32_t id, const uint8_t payload[], uint32_t size)
Start transmitting with a one-time CAN identifier override.
uint8_t isotp_get_tx_dl(const IsoTpLink *link)
Return the effective transmit data length for a link.
int isotp_send(IsoTpLink *link, const uint8_t payload[], uint32_t size)
Start transmitting a payload with the link's configured CAN identifier.
void isotp_init_link(IsoTpLink *link, uint32_t sendid, uint8_t *sendbuf, uint32_t sendbufsize, uint8_t *recvbuf, uint32_t recvbufsize)
Initialise an ISO-TP link and its caller-owned buffers.
int isotp_receive(IsoTpLink *link, uint8_t *payload, const uint32_t payload_size, uint32_t *out_size)
Copy and consume one completed, non-streaming message.
void isotp_on_can_message(IsoTpLink *link, const uint8_t *data, uint8_t len)
Process one CAN frame already routed to this link.
void isotp_set_tx_done_cb(IsoTpLink *link, isotp_tx_done_cb cb, void *arg)
Register or clear the successful-transmission callback.
void isotp_destroy_link(IsoTpLink *link)
Clear a link's state and callback registrations.
Compile-time transport configuration and defaults.
Public result codes, CAN frame constants, and callback types.
void(* isotp_rx_done_cb)(void *link, const uint8_t *data, uint32_t size, void *user_arg)
Called after a complete payload has been received successfully.
void(* isotp_tx_done_cb)(void *link, uint32_t tx_size, void *user_arg)
Called after a complete payload has been transmitted successfully.
Application-provided platform hooks.