Repository navigation
[can, test, docs] Add generic CAN device type - #68
AlexLanzano wants to merge 2 commits into
Conversation
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #68
Scan targets checked: wolfhal-src, wolfhal-bugs
Not reviewed (no scan target covers them): docs/writing_a_driver.md, tests/core/Makefile
Coverage: 3 of 4 in-scope changed file(s) opened by the reviewer; not opened: wolfHAL/wolfHAL.h
Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)
This review was generated automatically by Fenrir. Reported findings require changes before merge.
Review tier: Max
There was a problem hiding this comment.
🟡 Changes recommended
Classic CAN validation still accepts the unencodable ESI flag, and the receive guidance uses FD length decoding that can overrun an 8-byte buffer.
2 open issues
What changed in this PR
Adds a generic CAN device interface to wolfHAL, supporting classic CAN and CAN FD through driver dispatch.
Changes:
- Defines CAN frames, filters, state reporting, and payload-length helpers.
- Adds dispatch functions with transmit-frame validation.
- Adds core tests and CAN driver documentation.
| File | Description |
|---|---|
| wolfHAL/wolfHAL.h | Exposes the CAN interface through the umbrella header. |
| wolfHAL/can/can.h | Defines CAN types, driver interface, and public API. |
| tests/core/test_dispatch.c | Adds CAN validation, dispatch, and length-conversion tests. |
| tests/core/Makefile | Includes CAN implementation in core tests. |
| src/can/can.c | Implements validation and driver dispatch. |
| docs/writing_a_driver.md | Documents CAN driver responsibilities. |
Review effort: Balanced
8727965 to
a834627
Compare
wolfSSL-Fenrir-bot
left a comment
There was a problem hiding this comment.
Fenrir Automated Review — PR #68
Scan targets checked: wolfhal-src, wolfhal-bugs
Not reviewed (no scan target covers them): .github/workflows/core-tests.yml, docs/writing_a_driver.md, tests/core/Makefile
Coverage: 0 of 3 in-scope changed file(s) opened by the reviewer; not opened: src/can/can.c, tests/core/test_dispatch.c, wolfHAL/can/can.h
Fenrir result: Approved ✅
No new issues found in the changed files.
Advisory only — this automated result does not count as a GitHub approval.
Review tier: Lite
Fenrir's latest completed scan found no issues; clearing the prior automated change request.
LinuxJedi
left a comment
There was a problem hiding this comment.
A couple of things I flagged. I recommend adding a loopback test if you can. SocketCAN in Linux or amd-versal2-virt which you are already running can add virtual CAN-FD devices:
https://www.qemu.org/docs/master/system/arm/xlnx-versal-virt.html#using-canfds-for-versal-virt
| 0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64 | ||
| }; | ||
|
|
||
| return lens[dlc & 0xF]; |
There was a problem hiding this comment.
This is wrong, and I think the resolved Fenrir issue flagged it too. In CAN-FD, a DLC of 9-15 with FDF set to 0 means a length of 8.
There was a problem hiding this comment.
Good catch! I only fixed the overflow portion of that issue. Missed this.
Fixed.
| frame->len > WHAL_CAN_CLASSIC_MAX_DATA_LEN) | ||
| return WHAL_EINVAL; | ||
|
|
||
| return WHAL_SUCCESS; |
There was a problem hiding this comment.
If invalid flags are passed, such as 0x80 for example, this will succeed. It should probably fail.
Add can.h with the frame and filter types and the Init, Deinit, Send, Recv, GetState and Recover API, plus the can.c dispatcher and its tests.
Round-trips standard, extended, zero-length, remote and FD frames through BOARD_CAN_DEV in loopback mode.
I just added a generic loopback test. Was holding off on this until we had a driver implementation but it doesnt hurt to add it now. |


Adds a generic CAN device type covering classic CAN and CAN FD. No platform drivers yet.
API
whal_Can_Init/whal_Can_Deinitwhal_Can_Send: queues one frame; the generic layer rejects frames the format can't encodewhal_Can_Recv: polls for one frame,WHAL_ENOTREADYwhen nonewhal_Can_GetState: error state and TX/RX error counterswhal_Can_Recover: manual bus-off recoveryDesign
whal_Can_Frameuses a byte length.whal_Can_LenToDlc/whal_Can_DlcToLenconvert to and from DLC codes for drivers.WHAL_CFG_CAN_FDsizes the payload for 64 bytes; it is 8 bytes without it.Tests
tests/core.-DWHAL_CFG_CAN_FDadded to the core-tests CI matrix.