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