core: Add THREAD_FLAG_IRQ_SERVICED#9284
Conversation
|
The docs say:
But then it goes to define only two reserved flags. For this reason I'm marking it as an API change. |
|
|
the three in the text for reserved flags is probably a leftover since #7543 |
1e8fcb5 to
6918591
Compare
|
When you are woken up by THREAD_FLAG_IRQ_SERVICED, how do you know the flag was set by the i2c IRQ and not by any other IRQ? |
|
Good question! There is a potential for collisions here, so developer needs to ensure that the ISR only sets the flag when a thread is actually expecting it. In the i2c case we only enable the IRQ from the i2c module when we perform a transfer, so the thread will be expecting a thread flag to become set. The i2c module isr will not even know which thread to send the flag to unless there is a thread that has claimed the bus (i2c_acquire). For the network device, we know that each gnrc_netif thread is only managing a single device, so each network device can set the flag on its assigned thread without risk, as long as the netif thread does not do other things as well. |
Where's the limit? What if, say a SPI or UART device also sets THREAD_FLAG_PERIPH_IRQ? I understand that this shouldn't happen if all peripheral calls are blocking because then a single thread can only use one peripheral al the same time, at least for protocols where only the host can start a transmission/reception. For things like UART or a I2C in slave mode, one would have to make sure that the flag is not set by a RX IRQ, because a RX may happen at any time and there might be some unrelated code waiting for that flag. Another option would be to use the flag as is and then check the actual cause, similar to how a shared interrupt line works in hardware. |
|
@jcarrano we lose the benefit of the lightweight thread flags if we multiplex events like this. What you suggest is similar to what sys/event does. |
|
@gebart Then we should reserve ALL thread flags (or maybe leave one or two user-defined):
I'd like it to make it clear in the documentation: "This thread flag should only be used when for waiting for a peripheral IRQ, and only when it is known there is only one interrupt (the one corresponding to the peripheral being waited for) that can set the flag" |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
Introduce a common thread flag which can be used as an alternative to the traditional mutex method where the user application locks a mutex and an interrupt handler unlocks it. The thread flags method may have a lower runtime overhead than using a mutex.
The Kinetis I2C driver in #9262 uses this for signalling when the transfer is complete. The kw41zrf driver in #7107 uses a thread flag for signalling, and will be updated to use this definition to avoid collisions with application specific thread flags.
Issues/PRs references
#9262 #7107