I have a device that I've written a driver for in an RTOS such that when it fires off an interrupt, its task is to read a 32-bit value from the device and have the system take some appropriate action based on the bits set in the value read. The solution I came up with seems to work, but I'm not sure if it would be frowned upon for being inefficient.
I realize that ISRs are naturally disruptive, so to spend as little time within the ISR context as possible, I separated the "appropriate action" logic into a separate thread so that it would be outside of the ISR context.
This is the approach I've taken:
Mask interrupts for the device.
Read 32-bit value from the device.
Send value using a message queue for processing in a different thread.
Clear and re-enable interrupts for the device.
This seems to work fine, but my main concern is the usage of the message queue. How costly is using a message queue in an ISR, and is it generally frowned upon? Is there a better, more efficient way to send data from an ISR to a different task/thread?
Writing to a message queue from an interrupt is a textbook case of what message queues are for. It can be done very efficiently.
I'm not sure why you are turning off interrupts though. Do you mean that in the interrupt handler you turn off the interrupt that is currently running? That would not do anything on any architecture that I can think of. (Maybe edit the question if I have misinterpreted this part).