comp.lang.ada
 help / color / mirror / Atom feed
* Ravenscar and context switching for Cortex-M4
@ 2015-02-12 20:25 Patrick Noffke
  2015-02-12 21:28 ` Niklas Holsti
  2015-02-16 16:27 ` Patrick Noffke
  0 siblings, 2 replies; 20+ messages in thread
From: Patrick Noffke @ 2015-02-12 20:25 UTC (permalink / raw)


I am porting the GNAT Ravenscar-sfp runtime to work with the TI TM4C MCU, using the STM32F4 implementation as a starting point.  I am having a problem where one of two tasks blocked on entries (each in separate protected objects) is not getting activated.

Here is the situation:

I have two POs, each with an interrupt handler and an entry.  PO1 services UART interrupts and PO2 services SPI interrupts.  When each interrupt fires, the barrier in the corresponding entry is released.

Then I have two tasks, T1 and T2.  T1 is blocked on PO1's entry and T2 is blocked on PO2's entry.

The problem happens when the interrupts happen very near in time to each other.  Then, both entries are still executed, but only one task runs after the last entry completes.  I have instrumented the run-time as well as my code to toggle GPIOs and see what's happening when.  Here is the timing that fails:

1. SPI interrupt triggers.
2. Interrupt_Request_Handler in s-bbcppr-armv7m.adb is executed.  It calls my interrupt handler or PO2, followed by the entry (entry called in the interrupt context), and triggers a context switch for T2.
3. Before the task T2 can run, the UART interrupt triggers.
4. Interrupt_Request_Handler calls my interrupt handler for PO1 and its entry, and triggers a context switch for T1.
5. T1 then runs until it blocks again on the entry for PO1.

T2 never runs.  Furthermore, after this occurs, the entry for PO2 is never executed again (though its interrupt handler is).  T2 also never runs again.

I'm not yet familiar enough with the runtime to know what's happening.  But perhaps the issue is related to using Pend_SV_Handler to trigger the context switch.  Does the "pending" context switch for T1 never get executed since T2 is switched in before the Pend_SV_Handler can execute?  I'm reluctant to muck with Pend_SV_Handler to instrument the code since I don't want to perturb the processor registers and break that which I'm trying to instrument.

If it's useful, T1's priority is 10 and T2's priority is 190.  So even though T1 is lower priority than T2, T1 is switched in before T2 can run.

Both interrupt handlers are the same priority.

Also, if the second interrupt does not happen before the first task can run, then everything is fine (i.e. both tasks get their turn to run).

According to http://docs.adacore.com/gnathie_ug-docs/html/gnathie_ug/gnathie_ug/the_predefined_profiles.html#ada-restrictions-in-the-ravenscar-profiles, at most one task may be queued on an entry.  I take this to mean *on a single entry* and that two tasks may be simultaneously queued on separate entries.  Is that correct?  If not, then this is the problem.  But I've seen other suggestions in this list that my interpretation is correct.

Best regards,
Patrick

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2015-08-07 20:34 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-12 20:25 Ravenscar and context switching for Cortex-M4 Patrick Noffke
2015-02-12 21:28 ` Niklas Holsti
2015-02-13 12:41   ` G.B.
2015-02-13 16:25     ` Simon Wright
2015-02-13 18:08     ` Niklas Holsti
2015-02-13 19:01       ` Simon Wright
2015-02-13 23:45       ` Georg Bauhaus
2015-02-16 16:27 ` Patrick Noffke
2015-02-16 16:34   ` Patrick Noffke
2015-02-16 21:28   ` Simon Wright
2015-02-19 20:14     ` Patrick Noffke
2015-02-19 21:03       ` Bob Duff
2015-02-20 13:05         ` Simon Wright
2015-02-19 22:13       ` Patrick Noffke
2015-02-19 22:44         ` Patrick Noffke
2015-02-20  8:31           ` Simon Wright
2015-06-24 15:20           ` Patrick Noffke
2015-08-06 21:05     ` Patrick Noffke
2015-08-06 21:43       ` Patrick Noffke
2015-08-07 20:34         ` Patrick Noffke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox