Interrupt Handler and Thread – an example
The interrupt thread does not have to be activated with every interrupt. The interrupt handler can decide when to invoke SignalEndOfRtInterrupt versus SignalRtInterruptThread.
The diagram shows the design for receiving commands from a serial terminal, where a command is ended with a CR character.
The interrupt thread needs to run only when a complete command has been received.
While the interrupt thread runs, the state of the interrupt depends on the byMaxInt parameter (which must have been nonzero since we have an interrupt thread):
- if byMaxInt is one, the interrupt is disabled while the interrupt thread runs; we could miss interrupts if processing the command takes too long
- if byMaxInt is greater than one, the next command can be entered while the current command is processed; there must be more than one buffer.
The value of byMaxInt determines how many buffers must be present and how many commands can be entered ahead.
Handler and thread need to maintain an index for the command buffer to use and each cycles its own counter.