Commit 89d49b5
committed
Optimize MCP2515Class::parsePacket()
1) Use the RX STATUS command instead of READ(CANINTF) to check availability of
data to read. This reduces SPI usage by 1 byte out of 3, even to just check
if data is available.
2) Use the READ command to read RXB(n) registers sequentially instead of
requesting them one by one. This requires 7 bytes over SPI to read SIDH,
SIDL, EID8, EID0, DLC. The previous implementation used 15 bytes to read the
register for standard frames, and 24 bytes for extended frames.
3) Use the READ RX BUFFER command to read the packet data, instead of requesting
bytes one by one. This requires sending (1 + N) bytes over SPI instead of
(3 * N) for the payload, and doesn't require sending 3 bytes to modify RXnIF.
Total savings: (2 * N + 11) bytes over SPI for standard frame.
For N = 8, we now send 18 bytes over SPI vs 45. That's 60% reduction!
As a bonus, I was able to put all SPI operations in one SPI transaction.
I don't know if it makes much of a difference, but perhaps makes things safer?1 parent bcdd7ac commit 89d49b5
1 file changed
+53
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
218 | 222 | | |
219 | | - | |
| 223 | + | |
220 | 224 | | |
221 | | - | |
| 225 | + | |
222 | 226 | | |
223 | 227 | | |
| 228 | + | |
224 | 229 | | |
225 | 230 | | |
226 | 231 | | |
| 232 | + | |
| 233 | + | |
227 | 234 | | |
228 | 235 | | |
229 | 236 | | |
230 | 237 | | |
231 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
232 | 252 | | |
233 | | - | |
| 253 | + | |
234 | 254 | | |
235 | | - | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
236 | 259 | | |
237 | 260 | | |
238 | | - | |
| 261 | + | |
239 | 262 | | |
240 | 263 | | |
241 | | - | |
| 264 | + | |
242 | 265 | | |
243 | | - | |
| 266 | + | |
244 | 267 | | |
245 | 268 | | |
246 | 269 | | |
247 | 270 | | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
248 | 279 | | |
249 | 280 | | |
250 | 281 | | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
255 | 289 | | |
256 | | - | |
| 290 | + | |
257 | 291 | | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
258 | 297 | | |
259 | 298 | | |
260 | 299 | | |
| |||
0 commit comments