New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: CAN: Unify the TX error behavior of all CAN drivers #19502
Comments
My proposals are:
|
FYI: https://github.com/alexanderwachter/zephyr/tree/can_extend_api extends the API to have a propper bus-error management. |
I would imagine aiming for parity with the features in the Linux CAN configuration with Kconfig would be a good ultimate goal: If the TX automatic retry controller configuration can be defined in Kconfig then the user can configure the driver's behavior. If the user configures the CAN driver TX without retries then the user's CAN application protocol choices should define how to handle arbitration errors, or nack errors. From my understanding the CAN controller hardware would generally be configured to handle the retries. Possibly a callback register to receive bus state changes for the following states (including bus-off) would be simple way to go: |
The problem I see is that when a user enables automatic retransmission, there is no way to abort a transmission or have a timeout. |
I like the approach of a general timeout on the send, would also match expectations more I'd think. The send call could still be non blocking though when providing a callback right? Should the can_tx callbacks then get a status that informs about timeout so a message can be assumed to not have been sent? Or would you always block until a message was sent?
@alexanderwachter has something like this in his https://github.com/alexanderwachter/zephyr/tree/can_extend_api
Can you not cancel a transmission on a mailbox with a pending transmission? The abort/timeout might not be able to guarantee that a message was not sent at all, but at least that it will not be sent after the timeout has triggered/returned. |
Exactly. I'll even try to introduce a second timeout for the locks and message box allocation. With that change, can_send() could be called with K_NOWAIT, the second timeout parameter as K_MSEC(100), and no callback. This combination would be save to call from an ISR
The callback informs you about the reason why the timeout happened. For example TX-errors, arbitration lost, NACK. This is the same behavior as the blocking call. In my prototype, I INTRODUCED TIMERS FOR EACH MAILBOX.
Transmissions can be aborted. At least the stm32 and mcux can do that. For the MCP2515, I have to check the datasheet. Messages that are in transmission can't be canceled. Messaged pending or need a retransmit can be canceled. |
Sorry I wasn't clear, yes you can abort transmissions on the MCP2515, I was confused whether this was not a feature to be expected everywhere :-) Not so sure on the detail of the timeout one could provide. I can read back status bits on the mailbox but I am not sure if that can be as detailed as 'message was never acknowledged'. Will need to dig in deeper into the datasheet :-) |
First prototype: Edit: |
Rework the transmit error handling in the NXP MCUX FlexCAN driver: - Frame transmission must be automatically retried in case of lost arbitration or missing acknowledge. - Abort any pending TX frames when bus-off state is entered. - Fail early in can_send() if in bus-off state. Fixes: zephyrproject-rtos#19502 Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Rework the transmit error handling in the NXP MCUX FlexCAN driver: - Frame transmission must be automatically retried in case of lost arbitration or missing acknowledge. - Abort any pending TX frames when bus-off state is entered. - Fail early in can_send() if in bus-off state. Fixes: #19502 Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Currently, the CAN drivers behave differently in case of a TX error.
For example, the stm32- and mcp2515-driver retry sending after arbitration lost, where the MCUX-driver abort.
Describe the solution you'd like
Unify the behavior for all CAN controllers and drivers.
This issue is created to collect opinions on the desired behavior of the CAN API.
Please comment on the proposals or issue your own opinion here.
The text was updated successfully, but these errors were encountered: