feat(mcan): MCAN driver implementation and host unit tests #98

Merged
hoogv merged 1 commit from feat/97-mcan-driver into dev 2026-07-23 16:06:19 +00:00
Owner

Description

Adds hal/mss/mcan/hal_mcan.c/.h — the MCAN (Bosch M_CAN / CAN-FD controller) driver: MEM_INIT_DONE-then-reset-then-CCCR.INIT bring-up sequence (cross-checked against the mmwave SDK's CANFD_open()), nominal bit-timing derivation (fixed 16-time-quantum, 75% sample point), an "accept everything into Rx FIFO 0" global filter configuration, blocking transmit (dedicated Tx buffer 0, decodes PSR.LEC/BO into NACK/bus-error/bus-off status) and blocking receive (Rx FIFO 0, pop-and-acknowledge), and the two raw device handlers (MCAN_LVL0_IRQHandler/MCANB_LVL0_IRQHandler) decoding IR to a weak, application-overridable hal_mcan_irq_handler() hook. Both MCAN instances (MCANA/MCANB) supported. Self-contained — no cross-module dependency.

This is the final driver in the current driver-implementation batch.

Why

Continues and completes the driver-implementation phase started by GPIO (#75/#76), ESM (#77/#78), UART (#79/#80), I2C (#81/#82), SPI (#83/#84), ADCBUF (#85/#86), CBUFF (#87/#88), HWA (#89/#90), DMM (#91/#92), EPWM (#93/#94), and SOC (#95/#96).

Closes #97

Type of Change

  • New feature

Impact Assessment

  • Functional impact: None — self-contained addition alongside the already-landed GPIO/ESM/UART/I2C/SPI/ADCBUF/CBUFF/HWA/DMM/EPWM/SOC drivers.
  • Regulatory impact: None.
  • QMS impact: None.
  • Risk impact: No — existing risk coverage sufficient.

Testing

  • CI pipeline passes (compile, unit tests, integration tests, static analysis)
  • Manually tested: built and ran testing/mss/unit/hal_functionality/test_mcan_functional locally (20 test cases, 130 assertions, all passing) alongside the full existing ctest suite (329/329 passing, no regressions); ran a full MISRA C:2025 pass (0 unsuppressed findings, -DENABLE_MCAN_MODULE added); reformatted and re-verified against the exact clang-format 18.1.3 the CI runner uses; sanity-checked by changing the NTSEG1 bit-timing constant from 11 to 12, confirming the test suite fails (3 test cases, 4 assertions), then reverting.
  • No regressions observed in related areas

PR Size

  • XL (> 300 lines) — must split unless exemption declared

Size justification / exemption (if L or XL):

1447 raw lines across 6 files, all hand-reviewed (no mechanically-generated content). Not split further — the driver (hal_mcan.c/.h, 801 lines) and its comprehensive Catch2 spec (test_mcan.c, 638 lines, covering the bit-timing derivation math, the bring-up sequence, both transmit/receive paths and their error decoding, and both instances' IRQ handlers) don't decompose into independently-reviewable sub-PRs, same rationale as prior driver PRs (#78, #80, #82, #84, #86, #88, #90, #92, #94, #96). Only 3 files (CMake/MISRA wiring) needed touching beyond the driver/test pair — zephyr/Kconfig/zephyr/CMakeLists.txt/hal/util/hal_config_mss.h were already pre-wired for MCAN from the original module list, before this driver existed.

Checklist

  • Commit messages follow type(scope): description convention with Relates to #<issue> footer
  • PR template filled in completely
  • No unverified external binaries introduced (see QMS-GITFLOW-001 Binary Security section)
  • All commits leave the codebase in a compilable, passing-tests state (Commit Integrity Rule)

Summary

  • hal/mss/mcan/hal_mcan.c/.h: MCAN driver (bring-up, bit-timing derivation, filter config, blocking Tx/Rx, IRQ handlers) — CAN-FD/extended-ID filtering/Tx-Event-FIFO/bus-off-recovery out of scope, documented in the header's top-of-file comment
  • testing/mss/unit/hal_functionality/test_mcan.c (+ CMakeLists.txt): Catch2 functional test suite. Named test_mcan_functional (not test_mcan) to avoid a CMake target-name collision with ti_hal_comparison/test_mcan.c's register-layout comparison test.
  • tools/misra/run_misra.sh: -DENABLE_MCAN_MODULE added (Kconfig/CMake/hal_config_mss.h bridges were already in place)
## Description Adds `hal/mss/mcan/hal_mcan.c`/`.h` — the MCAN (Bosch M_CAN / CAN-FD controller) driver: MEM_INIT_DONE-then-reset-then-CCCR.INIT bring-up sequence (cross-checked against the mmwave SDK's `CANFD_open()`), nominal bit-timing derivation (fixed 16-time-quantum, 75% sample point), an "accept everything into Rx FIFO 0" global filter configuration, blocking transmit (dedicated Tx buffer 0, decodes PSR.LEC/BO into NACK/bus-error/bus-off status) and blocking receive (Rx FIFO 0, pop-and-acknowledge), and the two raw device handlers (`MCAN_LVL0_IRQHandler`/`MCANB_LVL0_IRQHandler`) decoding IR to a weak, application-overridable `hal_mcan_irq_handler()` hook. Both MCAN instances (MCANA/MCANB) supported. Self-contained — no cross-module dependency. This is the final driver in the current driver-implementation batch. ## Why Continues and completes the driver-implementation phase started by GPIO (#75/#76), ESM (#77/#78), UART (#79/#80), I2C (#81/#82), SPI (#83/#84), ADCBUF (#85/#86), CBUFF (#87/#88), HWA (#89/#90), DMM (#91/#92), EPWM (#93/#94), and SOC (#95/#96). ## Related Issue Closes #97 ## Type of Change - [x] New feature ## Impact Assessment - **Functional impact:** None — self-contained addition alongside the already-landed GPIO/ESM/UART/I2C/SPI/ADCBUF/CBUFF/HWA/DMM/EPWM/SOC drivers. - **Regulatory impact:** None. - **QMS impact:** None. - **Risk impact:** No — existing risk coverage sufficient. ## Testing - [x] CI pipeline passes (compile, unit tests, integration tests, static analysis) - [x] Manually tested: built and ran `testing/mss/unit/hal_functionality/test_mcan_functional` locally (20 test cases, 130 assertions, all passing) alongside the full existing `ctest` suite (329/329 passing, no regressions); ran a full MISRA C:2025 pass (0 unsuppressed findings, `-DENABLE_MCAN_MODULE` added); reformatted and re-verified against the exact clang-format 18.1.3 the CI runner uses; sanity-checked by changing the NTSEG1 bit-timing constant from 11 to 12, confirming the test suite fails (3 test cases, 4 assertions), then reverting. - [x] No regressions observed in related areas ## PR Size - [x] XL (> 300 lines) — must split unless exemption declared **Size justification / exemption (if L or XL):** 1447 raw lines across 6 files, all hand-reviewed (no mechanically-generated content). Not split further — the driver (`hal_mcan.c`/`.h`, 801 lines) and its comprehensive Catch2 spec (`test_mcan.c`, 638 lines, covering the bit-timing derivation math, the bring-up sequence, both transmit/receive paths and their error decoding, and both instances' IRQ handlers) don't decompose into independently-reviewable sub-PRs, same rationale as prior driver PRs (#78, #80, #82, #84, #86, #88, #90, #92, #94, #96). Only 3 files (CMake/MISRA wiring) needed touching beyond the driver/test pair — `zephyr/Kconfig`/`zephyr/CMakeLists.txt`/`hal/util/hal_config_mss.h` were already pre-wired for MCAN from the original module list, before this driver existed. ## Checklist - [x] Commit messages follow `type(scope): description` convention with `Relates to #<issue>` footer - [x] PR template filled in completely - [x] No unverified external binaries introduced (see QMS-GITFLOW-001 Binary Security section) - [x] All commits leave the codebase in a compilable, passing-tests state (Commit Integrity Rule) ## Summary - `hal/mss/mcan/hal_mcan.c`/`.h`: MCAN driver (bring-up, bit-timing derivation, filter config, blocking Tx/Rx, IRQ handlers) — CAN-FD/extended-ID filtering/Tx-Event-FIFO/bus-off-recovery out of scope, documented in the header's top-of-file comment - `testing/mss/unit/hal_functionality/test_mcan.c` (+ `CMakeLists.txt`): Catch2 functional test suite. Named `test_mcan_functional` (not `test_mcan`) to avoid a CMake target-name collision with `ti_hal_comparison/test_mcan.c`'s register-layout comparison test. - `tools/misra/run_misra.sh`: `-DENABLE_MCAN_MODULE` added (Kconfig/CMake/hal_config_mss.h bridges were already in place)
feat(mcan): MCAN driver implementation and host unit tests
All checks were successful
lint / clang-format (pull_request) Successful in 10s
tests / host-tests (pull_request) Successful in 43s
lint / misra (pull_request) Successful in 45s
lint / clang-format (push) Successful in 14s
tests / host-tests (push) Successful in 43s
lint / misra (push) Successful in 1m7s
d55f6b2992
Adds hal/mss/mcan/hal_mcan.c/.h - MEM_INIT_DONE-then-reset-then-
CCCR.INIT bring-up, nominal bit-timing derivation (16-tq/75% sample
point), accept-all Rx FIFO 0 filter config, blocking transmit/receive
with PSR.LEC/BO error decoding, and the two raw device handlers
decoding IR to a weak hal_mcan_irq_handler() hook. Both instances
supported. Classic CAN only, minimal filter/buffer scope - see
hal_mcan.h's top-of-file comment. Kconfig/CMake/hal_config_mss.h
bridges were already pre-wired from the original module list.

Relates to #4, relates to #97
hoogv added this to the Development project 2026-07-23 16:06:14 +00:00
hoogv self-assigned this 2026-07-23 16:06:16 +00:00
Sign in to join this conversation.
No reviewers
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
opendutchsolutions.public/hal_awr6843!98
No description provided.