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.

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)
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.

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.

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.

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
L = infinite loop
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

 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