This week, I set my mind on understanding on the switching of tasks inside FreeRTOS on the latest AEMB with two threads. From previous week, it was found that there was an infinite loop which act upon the second thread while the first thread will continue with FreeRTOS and all the tasks for the older AEMB. So, for the newer AEMB with interrupts enabled for both threads, this loop might show some effects.

For this time’s experiments, each will be replicated with either the loop removed or the loop remained. So, the experiments are run twice. Also, to view the wave output easier, I created single line assembly for each task. The assembly are something like this.

assembly

Next is to identify the addresses for:

  1. where the interrupt occurs (0004 for most cases)
  2. where the interrupt stops (differs for each case)
  3. which contains the tasks
  4. which contains the idle task (differs for each case)
  5. which contains the loop

All these are the most important addresses to look out for in the wave output.

As an example, I use a program zero task with the loop removed and obtained the output waveform. Refer to the orange line depicting the address.

1

At the start of the scheduler, both thread run 0240 and 0241 which is part of the idle task. Note that in this screen shot, an interrupt occur soon afterwards with address 0004 on thread 0. As thread 0 runs the interrupt, thread 1 is running the idle task.

2

Here is where the interrupt stops, at address 015E and it is on thread 0. Before it, thread 1 is still running the idle task. After the interrupt stops for thread 0, thread 0 runs the idle task while thread 1 continues doing what it was before. Both run the idle task until an interrupt occurs.

3

An interrupt occured for thread 1 at 0004. Before this, thread 0 and thread 1 was running idle task. As thread 1 starts running the interrupt, thread 0 continues to run idle task.

4

The interrupt on thread 1 stops at 015E. Now, thread 1 starts running idle task again while thread 0 continues what it was running before.

This method is used on three programs with different number of tasks. Each time, the programs are simulated on AEMB twice, without the loop and with the loop. Below are my findings on the patterns each exhibits.

Note:

int0 = interrupt on thread 0
int1 = interrupt on thread 1
I = idle task
L = infinite loop
T1 = task 1
T2 = task 2
red borders to show interrupt happened and task switching occur

The first program: idle task ONLY

with loop removed
Start int0 int1 int0 int1 int0 int1 int0
Thread0 I I I I I I I I
Thread1 I I I I I I I I
with loop start int0 int1 int0 int1 int0 int1 int0
Thread0 I I I I I I I I
Thread1 L L L L L L L L

The second program: idle task and task 1, both task with same priorities

with loop removed
Start int0 int1 int0 int1 int0 int1 int0
Thread0 I T1 T1 I I I I T1
Thread1 I I I I T1 T1 I I
with loop
Start int0 int1 int0 int1 int0 int1 int0
Thread0 I T1 T1 L L I I T1
Thread1 L L I I T1 T1 L L

The last program: idle task, task 1 and task 2, all with same priorities.

with loop removed
Start int0 int1 int0 int1 int0 int1 int0
Thread0 I T1 T1 I I T1 T1 I
Thread1 I I T2 T2 I I T2 T2
with loop
Start int0 int1 int0 int1 int0 int1 int0
Thread0 I T1 T1 I I T1 T1 I
Thread1 L L T2 T2 L L T2 T2

From these results, it shows that during each interrupt, the previous code the interrupted thread was doing will be send into the queue as a task as shown by the repeating of the infinite loop. Also, the queue are shared by both threads since thread 0 run the infinite loop after task switching in 1 experiment.
There are still some more things to prove, especially when dealing with more complex task rather than the single line task that was used here. Are tasks with longer assembly lines able to show the same pattern? The results for more complex task will be posted in the next post.


0 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.