-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Is this an issue? In SAMA5 sam_tsd_read a call to enter_critical_section() can possibly block. #11931
Comments
@TimJTi I think you are right. A proper way to fix it should be using sched_lock() if the MCU doesn't support SMP or using spinlock otherwise. |
@acassis Not an SMP system. Won't sched_lock cause a similar problem though? Why shouldn't other tasks be added/run just because the TSD driver is waiting on something? I am not 100% sure I am fully understanding the nuances of this :-) |
No, think with shed_lock() the interrupts still enabled. So its ISR could run and the TSD could get the data. Unless it is using work queue to get the data from the HW, in this case the context switch will not happen. |
I checked the description of sched_lock(): "Disables context switching by disabling addition of new tasks to the ready-to-run task list. The task that calls this function will be the only task that is allowed to run until it either calls sched_unlock (the appropriate number of times) or until it blocks itself." Does that mean no other tasks will run except the TSD task, until someone touches the screen (because by default interrupts are just pen detection, waiting for something to happen)? It could be many many minutes or hours if the screen is not being used! Or am I still not "getting" this? |
@TimJTi I think you are right, the issue is not the interruption "per se", but the way the logic to read the TS interrupts is done. |
@acassis - as it happens I don't use the pendet interrupt and last year submitted changes to make sure the SAMA5 TSD works properly if the ADC is set to periodic triggers. But I still don't know what the right fix is, when the TSD and ADC are a shared peripheral. What if the periodic TSD trigger is slow - the same would be true and it could block for ages. Maybe just a DEBUGASSERT if the TSD is opened as blocking? |
@acassis I think that the SAMA5 family are perhaps unique in allowing the pen detection interrupt. This is great if that is all you are using the adc for, but is otherwise no use. And even worse if you open the character driver in blocking mode and want to do other things! What I propose is the following.
Is that acceptable? |
Implemented, as above, in PR #12131 |
I noticed that a call to sam_tsd_read in SAMA5D2, to read touchscreen data, calls sam_tsd_waitsample if the character driver has been opened as blocking. That routine calls an enter_critical_section() to wait for a sample - and the low level driver defaults to pen detection as the interrupt mechanism to wait for a sample, so the wait could be for a very long time!
Assuming I have understand critical sections properly (i.e. all interrupts suppressed) of course.
While we probably shouldn't be opening an input device as blocking (but the touchscreen example app does), is this something that shouldn't be like this?
I will be submitting a PR for other changes to this driver so can make changes if my hunch is right?
The text was updated successfully, but these errors were encountered: