Skip to content

Conversation

@OceanfromXiaomi
Copy link
Contributor

add the logic about "cancel mechanism" of sending can/canfd message based priority list.

Summary

This PR is intended to resolve the CAN message priority inversion issue that can occur during CAN frame transmission.
It fundamentally addresses the problem of CAN message priority inversion, thereby avoiding communication latency or errors caused by priority inversion.

The solution manages CAN message transmission by introducing a cancel mechanism combined with a linked list, along with predefined cancel conditions (can_txneed_cancel), to control and reorder CAN frame transmission as needed.

Impact

If users want to use this scheme, they only need to enable CONFIG_CAN_TXCANCEL.
This scheme does not affect the build process, security, or compatibility.

A new dev_cancel interface is introduced, which is used to cancel the transmission of CAN messages that are already queued in the CAN driver’s hardware transmit buffer.

Testing

This scheme has been applied in an automotive basic-software project and has undergone long-term testing and validation; it does not break existing code.
The scheme also ran stably on development boards based on the Cortex-M7 architecture.

Test procedure:

  1. Enable CONFIG_CAN_TXCANCEL.
  2. Configure the CAN driver to use only one hardware transmit buffer.
  3. Disconnect the CAN bus.
  4. Using the cansend utility, first send a low-priority CAN message (ID 0x222). After confirming that this message has been placed into the hardware transmit buffer, send a high-priority CAN message (ID 0x111).
  5. Reconnect the CAN bus.

Observed behavior:
the high-priority message (ID 0x111) appears on the bus first, followed by the low-priority message (ID 0x222).

github_PR_1 github_PR_2 github_PR_3

@github-actions github-actions bot added Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels Dec 26, 2025
@xiaoxiang781216
Copy link
Contributor

@OceanfromXiaomi fix:

../nuttx/tools/checkpatch.sh -c -u -m -g 4a069358b6cbd7acf377f1e32e359c480a5a9679..HEAD
❌ Missing git commit message
Used config files:
    1: .codespellrc
/home/runner/work/nuttx/nuttx/nuttx/drivers/can/can_sender.c:309: specfic ==> specific
Some checks failed. For contributing guidelines, see:

@OceanfromXiaomi OceanfromXiaomi force-pushed the send_msg_cancel_logic branch 3 times, most recently from 63c1bf3 to aef5984 Compare January 4, 2026 08:58
@OceanfromXiaomi
Copy link
Contributor Author

@OceanfromXiaomi fix:

../nuttx/tools/checkpatch.sh -c -u -m -g 4a069358b6cbd7acf377f1e32e359c480a5a9679..HEAD
❌ Missing git commit message
Used config files:
    1: .codespellrc
/home/runner/work/nuttx/nuttx/nuttx/drivers/can/can_sender.c:309: specfic ==> specific
Some checks failed. For contributing guidelines, see:

Done

Copy link
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

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

@OceanfromXiaomi please update the Documentation: https://nuttx.apache.org/docs/latest/components/drivers/character/can.html to include this new functionality

@github-actions github-actions bot added the Area: Documentation Improvements or additions to documentation label Jan 5, 2026
@OceanfromXiaomi
Copy link
Contributor Author

@OceanfromXiaomi please update the Documentation: https://nuttx.apache.org/docs/latest/components/drivers/character/can.html to include this new functionality

Done, @acassis

acassis
acassis previously approved these changes Jan 5, 2026
@OceanfromXiaomi OceanfromXiaomi force-pushed the send_msg_cancel_logic branch 2 times, most recently from 85327d4 to a72f46f Compare January 6, 2026 03:17
Introduce a single configuration option to provide strict transmit
priority ordering based on CAN ID.

The intention is to expose the user-visible behavior (strict TX
priority ordering) rather than the underlying implementation details.
Strict priority ordering is only meaningful when hardware transmit
buffer cancellation is available, so splitting this functionality into
separate configuration options was misleading and could result in
partially effective or incorrect configurations.

Signed-off-by: zhaohaiyang1 <zhaohaiyang1@xiaomi.com>
Copy link
Contributor

@michallenc michallenc left a comment

Choose a reason for hiding this comment

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

LGTM

@michallenc michallenc requested review from acassis and cederom January 6, 2026 07:35
@michallenc michallenc requested a review from linguini1 January 6, 2026 07:36
@xiaoxiang781216 xiaoxiang781216 merged commit 2a60b7e into apache:master Jan 6, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants