Skip to content

Event Driven CAN TX#314

Draft
irvingywang wants to merge 36 commits intomasterfrom
irving/event-driven-CANTX
Draft

Event Driven CAN TX#314
irvingywang wants to merge 36 commits intomasterfrom
irving/event-driven-CANTX

Conversation

@irvingywang
Copy link
Copy Markdown
Member

@irvingywang irvingywang commented Mar 21, 2026

  • Nuke TX jitter by utilizing TX interrupts and notification driven system
  • less CPU time, immediate transmission when possible
  • F4: kill mailboxes to unify api with G4
  • needs testing

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors CAN task setup across multiple nodes and begins shifting STM32G4 (FDCAN) CAN TX toward an event-driven model by waking the TX task on enqueue and on TX-complete interrupts.

Changes:

  • Replaced per-node CAN RX/TX task definitions/starts with DEFINE_CAN_TASKS() / START_CAN_TASKS().
  • Updated G4 FDCAN driver to route RX interrupts to IT0 and TX-complete interrupts to IT1, adding a TX callback hook.
  • Made G4 CAN TX task notification-driven (enqueue notifies the TX task; TX-complete ISR notifies when FIFO space frees).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
source/torque_vector/main.c Switches to CAN task macros for Torque Vector node.
source/pdu/main.c Switches to CAN task macros for PDU (bxCAN) node.
source/main_module/main.c Switches to CAN task macros for Main Module node.
source/g4_testing/izze_imu_config.c Switches to CAN task macros for G4 IMU config test.
source/g4_testing/canpiler.c Switches to CAN task macros for G4 canpiler test.
source/f4_testing/canpiler.c Switches to CAN task macros for F4 canpiler test.
source/driveline/main.c Adds CAN task macros and starts CAN tasks for Driveline node.
source/dashboard/main.c Switches to CAN task macros for Dashboard node.
source/a_box/main.c Switches to CAN task macros for A-Box node.
common/phal_G4/fdcan/fdcan.h Adds TX callback declaration; reformats filter API signature.
common/phal_G4/fdcan/fdcan.c Routes RX/TX interrupts to separate lines; adds TX ISR + weak TX callback.
common/can_library/can_common.h Introduces DEFINE_CAN_TASKS / START_CAN_TASKS macros.
common/can_library/can_common.c Makes G4 TX notification-driven; removes TX enqueue backpressure waits.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 4 comments.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 18 changed files in this pull request and generated 6 comments.

Comment on lines +136 to 138
void CAN1_TX_IRQHandler() {
CAN_wake_tx_from_ISR();
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CAN1_TX_IRQHandler() doesn't acknowledge/clear the bxCAN TX interrupt source. With CAN_IER_TMEIE enabled, the ISR should clear the relevant completion flags in CAN1->TSR (e.g., write 1s to any set CAN_TSR_RQCPx bits, and potentially handle TXOK/ALST/TERR bookkeeping). Without clearing, the IRQ can re-fire immediately and starve the system.

Copilot uses AI. Check for mistakes.
Comment on lines +150 to 152
void CAN2_TX_IRQHandler() {
CAN_wake_tx_from_ISR();
}
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CAN2_TX_IRQHandler() doesn't acknowledge/clear the bxCAN TX interrupt source. With CAN_IER_TMEIE enabled, the ISR should clear the relevant completion flags in CAN2->TSR (e.g., write 1s to any set CAN_TSR_RQCPx bits, and potentially handle TXOK/ALST/TERR bookkeeping). Without clearing, the IRQ can re-fire immediately and starve the system.

Copilot uses AI. Check for mistakes.
@irvingywang irvingywang force-pushed the irving/event-driven-CANTX branch 2 times, most recently from 37dccd0 to 98a4a1d Compare March 30, 2026 12:47
@irvingywang irvingywang force-pushed the irving/event-driven-CANTX branch from 20533dc to 537d2f4 Compare April 6, 2026 20:08
@irvingywang irvingywang force-pushed the irving/event-driven-CANTX branch from 319e09d to 36e22b8 Compare April 10, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants