nuttx icon indicating copy to clipboard operation
nuttx copied to clipboard

FlexCAN can_input() should not be called directly from interrupt handler

Open raiden00pl opened this issue 3 years ago • 2 comments

I noticed that FlexCAN implementation calls can_input() directly from the interrupt handler which is probably wrong. This will raise the assertion in nxsem_trywait.c:75 when CONFIG_DEBUG_ASSERTIONS=y

The call stack looks like this: xxx_flexcan_interrupt -> xxx_receive -> can_input -> can_callback -> net_trylock -> nxsem_trywait.

I don't have any NXP boards to help solve the problem, so I just open a new issue.

raiden00pl avatar Jan 03 '22 11:01 raiden00pl

FYI @PetervdPerk-NXP @michallenc

raiden00pl avatar Jan 03 '22 11:01 raiden00pl

Interesting the comment above the function suggest it wouldn't block and didn't specify it's not allowed to be executed while in an interrupt. https://github.com/apache/incubator-nuttx/blob/9a53601ba993d43684328dcae8750acb00a34cc7/sched/semaphore/sem_trywait.c#L45-L48

The reason why it's called under an interrupt is because Unfortunely using a workqueue it's too slow to react and would cause an CAN RX mailbox overflow. That's why we try to get rid of asap while in the interrupt but only if we can access the lock hence the net_trylock().

A better solution would to figure why scheduling a workqueue with an immediate deadline takes quite to long to be scheduled but I never came to that.

PetervdPerk-NXP avatar Jan 03 '22 15:01 PetervdPerk-NXP

I'm reopening this issue as it is not fully resolved yet

raiden00pl avatar Aug 04 '23 17:08 raiden00pl

Could you please rebase and test it again?

#10199 may solve the problem.

tmedicci avatar Aug 14 '23 16:08 tmedicci

I don't have any NXP board so I can't confirm if the problem has been fixed (it has to be tested on HW). Let someone who works with NXP confirm that the problem is fixed.

raiden00pl avatar Aug 16 '23 07:08 raiden00pl