@@ -142,14 +142,99 @@ void CAN1_TX_IRQHandler() {
142
142
CAN -> TSR |= CAN_TSR_RQCP0 ;
143
143
}
144
144
145
+ #define ISOTP_BUF_SIZE 0x110
146
+
147
+ uint8_t isotp_buf [ISOTP_BUF_SIZE ];
148
+ uint8_t * isotp_buf_ptr = NULL ;
149
+ int isotp_buf_remain = 0 ;
150
+
151
+ uint8_t isotp_buf_out [ISOTP_BUF_SIZE ];
152
+ uint8_t * isotp_buf_out_ptr = NULL ;
153
+ int isotp_buf_out_remain = 0 ;
154
+ int isotp_buf_out_idx = 0 ;
155
+
156
+ void bl_can_send (uint8_t * odat ) {
157
+ // wait for send
158
+ while (!(CAN -> TSR & CAN_TSR_TME0 ));
159
+
160
+ // send continue
161
+ CAN -> sTxMailBox [0 ].TDLR = ((uint32_t * )odat )[0 ];
162
+ CAN -> sTxMailBox [0 ].TDHR = ((uint32_t * )odat )[1 ];
163
+ CAN -> sTxMailBox [0 ].TDTR = 8 ;
164
+ CAN -> sTxMailBox [0 ].TIR = (CAN_BL_OUTPUT << 21 ) | 1 ;
165
+ }
166
+
145
167
void CAN1_RX0_IRQHandler () {
146
168
while (CAN -> RF0R & CAN_RF0R_FMP0 ) {
147
169
if ((CAN -> sFIFOMailBox [0 ].RIR >>21 ) == CAN_BL_INPUT ) {
148
- CAN -> sTxMailBox [0 ].TDLR = 0xAABBCCDD ;
149
- CAN -> sTxMailBox [0 ].TDHR = 0xAABBCCDD ;
150
- CAN -> sTxMailBox [0 ].TDTR = 8 ;
151
- CAN -> sTxMailBox [0 ].TIR = (CAN_BL_OUTPUT << 21 ) | 1 ;
170
+ uint8_t dat [8 ];
171
+ ((uint32_t * )dat )[0 ] = CAN -> sFIFOMailBox [0 ].RDLR ;
172
+ ((uint32_t * )dat )[1 ] = CAN -> sFIFOMailBox [0 ].RDHR ;
173
+ uint8_t odat [8 ];
174
+ uint8_t type = dat [0 ] & 0xF0 ;
175
+ if (type == 0x30 ) {
176
+ // continue
177
+ while (isotp_buf_out_remain > 0 ) {
178
+ // wait for send
179
+ while (!(CAN -> TSR & CAN_TSR_TME0 ));
180
+
181
+ odat [0 ] = 0x20 | isotp_buf_out_idx ;
182
+ memcpy (odat + 1 , isotp_buf_out_ptr , 7 );
183
+ isotp_buf_out_remain -= 7 ;
184
+ isotp_buf_out_ptr += 7 ;
185
+ isotp_buf_out_idx ++ ;
186
+
187
+ bl_can_send (odat );
188
+ }
189
+ } else if (type == 0x20 ) {
190
+ if (isotp_buf_remain > 0 ) {
191
+ memcpy (isotp_buf_ptr , dat , 7 );
192
+ isotp_buf_ptr += 7 ;
193
+ isotp_buf_remain -= 7 ;
194
+ }
195
+ if (isotp_buf_remain <= 0 ) {
196
+ int len = isotp_buf_ptr - isotp_buf + isotp_buf_remain ;
197
+
198
+ // call the function
199
+ memset (isotp_buf_out , 0 , ISOTP_BUF_SIZE );
200
+ isotp_buf_out_remain = spi_cb_rx (isotp_buf , len , isotp_buf_out );
201
+ isotp_buf_out_ptr = isotp_buf_out ;
202
+ isotp_buf_out_idx = 0 ;
203
+
204
+ // send initial
205
+ if (isotp_buf_out_remain <= 7 ) {
206
+ odat [0 ] = isotp_buf_out_remain ;
207
+ //memcpy(odat+1, isotp_buf_out_ptr, isotp_buf_out_remain);
208
+ } else {
209
+ odat [0 ] = 0x10 | (isotp_buf_out_remain >>8 );
210
+ odat [1 ] = isotp_buf_out_remain & 0xFF ;
211
+ //memcpy(odat+2, isotp_buf_out_ptr, 6);
212
+ isotp_buf_out_remain -= 6 ;
213
+ isotp_buf_out_ptr += 6 ;
214
+ isotp_buf_out_idx ++ ;
215
+ }
216
+
217
+ bl_can_send (odat );
218
+ }
219
+ } else if (type == 0x10 ) {
220
+ int len = ((dat [0 ]& 0xF )<<8 ) | dat [1 ];
221
+
222
+ // setup buffer
223
+ isotp_buf_ptr = isotp_buf ;
224
+ memcpy (isotp_buf_ptr , dat + 2 , 6 );
225
+
226
+ if (len < (ISOTP_BUF_SIZE - 0x10 )) {
227
+ isotp_buf_ptr += 6 ;
228
+ isotp_buf_remain = len - 6 ;
229
+ }
230
+
231
+ memset (odat , 0 , 8 );
232
+ odat [0 ] = 0x30 ;
233
+ bl_can_send (odat );
234
+ }
152
235
}
236
+ // next
237
+ CAN -> RF0R |= CAN_RF0R_RFOM0 ;
153
238
}
154
239
}
155
240
@@ -181,11 +266,6 @@ void soft_flasher_start() {
181
266
// init can
182
267
can_silent = ALL_CAN_LIVE ;
183
268
can_init (0 );
184
-
185
- // needed?
186
- NVIC_EnableIRQ (CAN1_TX_IRQn );
187
- NVIC_EnableIRQ (CAN1_RX0_IRQn );
188
- NVIC_EnableIRQ (CAN1_SCE_IRQn );
189
269
#endif
190
270
191
271
// A4,A5,A6,A7: setup SPI
0 commit comments