jsinglet
jsinglet

Reputation: 1151

Multi-Tasking on Embedded Devices with Ravenscar

I'm using the Ravenscar profile to build an application that utilizes tasks.

As a simple example, I have one task that has a barrier such that it only executes when the barrier is True.

However, I've noticed that if the main control thread is executing, and then the barrier is set to true (thus released) the task blocks execution of the main thread until the barrier is closed again.

I'm working on a NRF52840 chip. I should note, whenever I target the application (with no modifications) to Native this problem doesn't happen and the tasks do not block execution.

Is there something I need to do in order to enable parallel execution for the ravenscar (full) RTS on embedded devices?

Some Additional Color: If I add a delay to the loop of the task, it indeed allows the main control thread to run.

Is this perhaps an issue with the priority ceiling protocol? The processor on board only has one core so I'm wondering if that is perhaps the problem -- that is, the task doesn't allow the main task to preempt unless it's sleeping.

Upvotes: 3

Views: 276

Answers (2)

jsinglet
jsinglet

Reputation: 1151

As Simon pointed out the issue is with priority -- the fix, as he pointed out is to assign a priority to my task.

On my system (GNAT 2012 from AdaCore) the default priority is 15; setting the tasks to something reasonable like 5 seems to fix the issue.

Upvotes: 1

Simon Wright
Simon Wright

Reputation: 25511

What are the relative priorities of your main program and your task? I don’t know about AdaCore’s runtimes, but it’s at least possible that the environment task (which executes the main program) might have lower priority than your task.

What does your task do while it’s enabled? If it just spins (from the runtime’s point of view - i.e. no delays or calls on protected entries), then once it gets onto the ready queue, why should it relinquish it? If there’s only one core, no other task of the same or lower priority can execute.

The NRF52840 is built around an ARM M4 chip, which has a single core, whereas your desktop very likely has multiple cores.

The way to set the main program’s priority is, for example,

with System;
procedure T
with Priority => System.Default_Priority - 1
is
...

Upvotes: 5

Related Questions