28
28
extern "C" {
29
29
#endif
30
30
31
+ /**
32
+ * @brief ISO-TP receive callback function type
33
+ *
34
+ * Called when a complete message has been received successfully.
35
+ *
36
+ * @warning This callback executes in the same context as isotp_on_can_message(),
37
+ * which is typically ISR context. Keep callback execution time minimal
38
+ * and avoid blocking operations.
39
+ * @note The data pointer is only valid during the callback execution.
40
+ * Copy data immediately if needed beyond the callback scope.
41
+ *
42
+ * @param[in] handle ISO-TP handle that received the message
43
+ * @param[in] data Pointer to received data (valid only during callback)
44
+ * @param[in] size Size of received data in bytes
45
+ * @param[in] user_arg User argument provided during configuration
46
+ */
47
+ typedef void (* esp_isotp_rx_callback_t )(esp_isotp_handle_t handle , const uint8_t * data , uint32_t size , void * user_arg );
48
+
49
+ /**
50
+ * @brief ISO-TP transmit callback function type
51
+ *
52
+ * Called when a complete message has been transmitted successfully.
53
+ *
54
+ * @note Execution context depends on message type:
55
+ * - Single-frame: Called immediately from isotp_send() in caller's context
56
+ * - Multi-frame: Called from isotp_poll() in task context
57
+ * @note Keep callback execution time minimal to avoid affecting system performance.
58
+ *
59
+ * @param[in] handle ISO-TP handle that transmitted the message
60
+ * @param[in] tx_size Size of transmitted data in bytes
61
+ * @param[in] user_arg User argument provided during configuration
62
+ */
63
+ typedef void (* esp_isotp_tx_callback_t )(esp_isotp_handle_t handle , uint32_t tx_size , void * user_arg );
64
+
31
65
/**
32
66
* @brief ISO-TP link handle
33
67
*/
@@ -37,11 +71,15 @@ typedef struct esp_isotp_link_t *esp_isotp_handle_t;
37
71
* @brief Configuration structure for creating a new ISO-TP link
38
72
*/
39
73
typedef struct {
40
- uint32_t tx_id ; /*!< TWAI ID for transmitting ISO-TP frames (11-bit or 29-bit) */
41
- uint32_t rx_id ; /*!< TWAI ID for receiving ISO-TP frames (11-bit or 29-bit) */
74
+ uint32_t tx_id ; /*!< TWAI ID for transmitting ISO-TP frames (11-bit or 29-bit, auto-detected from value ) */
75
+ uint32_t rx_id ; /*!< TWAI ID for receiving ISO-TP frames (11-bit or 29-bit, auto-detected from value ) */
42
76
uint32_t tx_buffer_size ; /*!< Size of the transmit buffer (max message size to send) */
43
77
uint32_t rx_buffer_size ; /*!< Size of the receive buffer (max message size to receive) */
44
- bool use_extended_id ; /*!< true: use 29-bit extended ID, false: use 11-bit standard ID */
78
+ uint32_t tx_frame_pool_size ; /*!< Size of TX frame pool (0 for default: 8) */
79
+
80
+ esp_isotp_rx_callback_t rx_callback ; /*!< Receive completion callback (NULL for polling mode) */
81
+ esp_isotp_tx_callback_t tx_callback ; /*!< Transmit completion callback (NULL to disable) */
82
+ void * callback_arg ; /*!< User argument passed to callbacks */
45
83
} esp_isotp_config_t ;
46
84
47
85
/**
@@ -63,11 +101,16 @@ typedef struct {
63
101
esp_err_t esp_isotp_new_transport (twai_node_handle_t twai_node , const esp_isotp_config_t * config , esp_isotp_handle_t * out_handle );
64
102
65
103
/**
66
- * @brief Send data over an ISO-TP link (non-blocking)
104
+ * @brief Send data over an ISO-TP link (non-blocking, ISR-safe )
67
105
*
68
106
* Immediately sends first/single frame and returns. For multi-frame messages,
69
107
* remaining frames are sent during subsequent esp_isotp_poll() calls.
70
108
*
109
+ * @note This function is ISR-safe and can be called from interrupt context.
110
+ * @note TX completion callback timing:
111
+ * - Single-frame: Called immediately from isotp_send()
112
+ * - Multi-frame: Called from isotp_poll() when last frame is sent
113
+ *
71
114
* @param handle ISO-TP handle
72
115
* @param data Data to send
73
116
* @param size Data length in bytes
@@ -83,12 +126,17 @@ esp_err_t esp_isotp_new_transport(twai_node_handle_t twai_node, const esp_isotp_
83
126
esp_err_t esp_isotp_send (esp_isotp_handle_t handle , const uint8_t * data , uint32_t size );
84
127
85
128
/**
86
- * @brief Send data over an ISO-TP link with specified TWAI ID (non-blocking)
129
+ * @brief Send data over an ISO-TP link with specified TWAI ID (non-blocking, ISR-safe )
87
130
*
88
131
* Similar to esp_isotp_send(), but allows specifying a different TWAI ID for transmission.
89
132
* This function is primarily used for functional addressing where multiple nodes
90
133
* may respond to the same request.
91
134
*
135
+ * @note This function is ISR-safe and can be called from interrupt context.
136
+ * @note TX completion callback timing:
137
+ * - Single-frame: Called immediately from isotp_send_with_id()
138
+ * - Multi-frame: Called from isotp_poll() when last frame is sent
139
+ *
92
140
* @param handle ISO-TP handle
93
141
* @param id TWAI identifier to use for transmission (overrides configured tx_id)
94
142
* @param data Data to send
@@ -99,19 +147,24 @@ esp_err_t esp_isotp_send(esp_isotp_handle_t handle, const uint8_t *data, uint32_
99
147
* - ESP_ERR_NO_MEM: Data too large for buffer or no space available
100
148
* - ESP_ERR_INVALID_SIZE: Invalid data size
101
149
* - ESP_ERR_TIMEOUT: Send operation timed out
102
- * - ESP_ERR_INVALID_ARG: Invalid parameters
150
+ * - ESP_ERR_INVALID_ARG: Invalid parameters or ID exceeds maximum value
103
151
* - ESP_FAIL: Other send errors
104
152
*/
105
153
esp_err_t esp_isotp_send_with_id (esp_isotp_handle_t handle , uint32_t id , const uint8_t * data , uint32_t size );
106
154
107
155
/**
108
- * @brief Extract a complete received message (non-blocking)
156
+ * @brief Extract a complete received message (non-blocking, task context only )
109
157
*
110
158
* This function only extracts data that has already been assembled by esp_isotp_poll().
111
159
* It does NOT process incoming TWAI frames - that happens in esp_isotp_poll().
112
160
*
113
161
* Process: TWAI frames → esp_isotp_poll() assembles → esp_isotp_receive() extracts
114
162
*
163
+ * @warning This function is NOT ISR-safe and must only be called from task context.
164
+ * @note When using callback mode (rx_callback != NULL), received messages are
165
+ * automatically delivered via callback. This function should only be used
166
+ * in polling mode (rx_callback == NULL).
167
+ *
115
168
* @param handle ISO-TP handle
116
169
* @param data Buffer to store received data
117
170
* @param size Buffer size in bytes
@@ -128,7 +181,7 @@ esp_err_t esp_isotp_send_with_id(esp_isotp_handle_t handle, uint32_t id, const u
128
181
esp_err_t esp_isotp_receive (esp_isotp_handle_t handle , uint8_t * data , uint32_t size , uint32_t * received_size );
129
182
130
183
/**
131
- * @brief Poll the ISO-TP link to process messages (CRITICAL - call regularly! )
184
+ * @brief Poll the ISO-TP link to process messages (CRITICAL - call regularly, task context only )
132
185
*
133
186
* This function drives the ISO-TP state machine. Call every 1-10ms for proper operation.
134
187
*
@@ -137,9 +190,13 @@ esp_err_t esp_isotp_receive(esp_isotp_handle_t handle, uint8_t *data, uint32_t s
137
190
* - Processes incoming TWAI frames and assembles complete messages
138
191
* - Handles flow control and timeouts
139
192
* - Updates internal state machine
193
+ * - Triggers TX completion callbacks for multi-frame messages
140
194
*
141
195
* Without regular polling: multi-frame sends will stall and receives won't complete.
142
196
*
197
+ * @warning This function is NOT ISR-safe and must only be called from task context.
198
+ * @note TX completion callbacks for multi-frame messages are triggered from this function.
199
+ *
143
200
* @param handle ISO-TP handle
144
201
* @return
145
202
* - ESP_OK: Processing successful
0 commit comments