Sitelet https://github.com/CANopenNode/CANopenNode/pull/652
Skip to content

fix[CANopenNode][Gateway]: protect shared ASCII gateway FIFO access - #652

Open
wdfk-prog wants to merge 1 commit into
CANopenNode:masterfrom
wdfk-prog:gtwa_lock
Open

wdfk-prog wants to merge 1 commit into
CANopenNode:masterfrom
wdfk-prog:gtwa_lock

Conversation

@wdfk-prog

Copy link
Copy Markdown

Pull Request Description (PR description)

[

Why is this PR needed

CANopenNode's ASCII gateway uses commFifo for receiving command data.
When a transport runs in a different execution context from
CO_GTWA_process(), the transport may write to the FIFO while the gateway
parser is reading, searching, or resetting the same FIFO.

This is required by transports such as an RTOS console frontend, where
command input is produced by a shell thread while gateway processing runs
from the CANopen main processing context.

The change also fixes several printf format mismatches exposed on targets
where the fixed-width integer typedefs differ from the types assumed by
the original explicit casts.

What is your solution

Add a CAN driver synchronization context to the ASCII gateway and introduce
CO_LOCK_GTWA() / CO_UNLOCK_GTWA() driver hooks.

The locks are intentionally limited to individual shared FIFO operations:

  • command FIFO write and free-space queries
  • command search and reset
  • command token reads
  • SDO datatype scans consuming the command FIFO
  • gateway log FIFO access when ASCII logging is enabled

The complete CO_GTWA_process() state machine is not locked, so potentially
long-running SDO, NMT, LSS, response generation, and callback processing do
not hold the transport synchronization primitive.

CO_GTWA_init() now receives the CAN module used by the driver-specific
locking implementation.

The change also updates fixed-width integer formatting to match the
<inttypes.h> format macros without relying on incompatible explicit casts.
]

Allow the CANopenNode ASCII gateway command FIFO to be safely accessed
from a transport thread while CO_GTWA_process() runs in the CANopen
processing context.

- add a CAN module context to CO_GTWA_t
- add CO_LOCK_GTWA() and CO_UNLOCK_GTWA() driver hooks
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.

1 participant