Hello!
I have two algorithms, and I wan to only run one of them at a time. So, I've created two tasks (one for each algorithm).
There is also a third task I have created, to act as a "middle man", or a "switch". This third task has the highest priority (5), and my other two tasks have low priority (-1) such that they only run when I directly tell them to.
This solution has been working quite well for me, until today. I have two CCS projects, both nearly identical, except for some differences in the algorithms themselves. Somehow one project works and the other does not work.
The broken output I see is this (sequentially):
- First, the high priority "middle man" task starts. It waits to be told what to do by checking a certain DDR value.
- When that DDR value is triggered, the "middle man" task tells the appropriate other task to change his priority from -1 to +7. I use Task_setPri(tsk0, 7)
- I assume that now, tsk0 would have the highest priority (7), and would run my proprietary algorithm to completion. Instead, however, it only computes the first line of code in my tsk0 function (which happens to be a printf statement I added to aid humans in debug).
- Next, it immediately goes back to the start of my "middle man" task, starting over at the beginning.
What I also do not understand is that, at first, ROV did not show the priority changing on my tsk0. I set a breakpoint on the "Task_setPri()" line, and after stepping over that line the task priority did not change in ROV. So, at least with this it made sense why only my "middle man" task ran... because it was the highest priority!
So: Since this made me doubt the Task_setPri(), I also experimented with setting all tasks to -1 priority in my .cfg file. Then in main(), just immediately before BIOS_start(), I set the priority of my "middle man" task to 5. This works, I see the desired result in ROV! (tsk0 priority = 7, middle man priority = 5, & other algorithm priority = -1).
However - I still have the same problem that it does not stay in tsk0 (priority 7). I see in ROV that tsk0 is priority 7, and my "middle man" task is priority 5. This is exactly what it should be, but still my code never executes tsk0 past the first line (the printf statement).
How is it possible that SYSBIOS is switching back and forth between two tasks, when by definition only one task can run at a time - the task with the highest priority?
An alternate solution:
What if, instead of having three tasks, I had just one SYSBIOS task (with a larger stack, of course) and switched my two algorithms via regular function calls? i.e.
Void task000()
{
while(1) {
volatile int *x = (volatile int *)0x80000000; //DDR variable
if(x == 0)
do_alg1();
else if (x == 1)
do_alg2();
}
}
Thank you for sharing your thoughts with me!
[EDIT] I also tried changing my tsk0 priority to 5, via Task_setPri(), when I want it to run. Then, since both my "middle man" task and tsk0 will both be priority 5, I told the "middle man" task to yield via Task_yield(). Unfortunately - it just hung and did nothing; I expected that tsk0 would run because the "middle man" task was yielding to it. I've attached a screenshot of my debug view to show this and another curious result - the ROV which shows that all of my task Stacks are maxed. This is quite odd, because none of them have done anything yet except sit around and wait to be told to start! :)
