og_angus wrote on Monday, February 19, 2007:
Hello,
I’m currently using Rowley with FreeRTOS on an ATMEL SAM7X. I would like to create tasking support for FreeRTOS within Rowley. Has anyone done this? I have created a threads.js that is viewing all the tasks and I have the general layout working. The area where I need a little help is with the FreeRTOS stack structure and I’m guessing a little help on how this works under ARM.
In particular I don’t fully understand how the program counter (pc) is tracked. I have looked at portRESTORE_CONTEXT() and I don’t fully see how the stack is lined up with the register values I’m expecting to see.
I’m including the threads.js code, but it is still very rough. In particular what I can’t get working is the registerContext restore. Any help would be greatly appreciated.
Thanks,
Angus
The following is my initial pass at threads.js for FreeRTOS:
function registersFromContext(sp)
{
var a = new Array();
for (i=0;i<=16;i++)
{
a[i] = Debug.evaluate("*(unsigned*)0x"+sp.toString(16));
sp+=4;
}
return a;
}
function ConvertToString(data)
{
var str = "";
for(i=0;i<=16;i++)
{
if(tcb.pcTaskName[i] == 0)
break;
str += String.fromCharCode(tcb.pcTaskName[i]);
}
return str;
}
function listTasks(listName, listIndex)
{
var i=0;
y=Debug.evaluate(listIndex);
yy=Debug.evaluate("*(xList *)0x"+y.toString(16));
pxIndex = Debug.evaluate("*(xListItem *)0x"+yy.pxIndex.toString(16));
numItems = yy.uxNumberOfItems;
while(/*x &&*/ i<numItems && ((numItems < 50) && (numItems > 0)))
{
if (i==0)
Threads.newqueue(listName);
tcb = Debug.evaluate("*(tskTCB *)0x"+pxIndex.pvOwner.toString(16));
name = ConvertToString(tcb.pcTaskName);
pri = tcb.uxPriority;
registers = registersFromContext(tcb.pxStack+((tcb.usStackDepth-16)*4));
Threads.add(name, pri, pxIndex.pvOwner.toString(16), registers);
pxIndex = Debug.evaluate("*(xListItem *)0x"+pxIndex.pxNext.toString(16));
i++;
}
}
function update()
{
Threads.clear();
listTasks("DelayedTaskList", "*(int *)pxDelayedTaskList");
listTasks("OverflowDelayedTaskList", "*(int *)pxOverflowDelayedTaskList");
listTasks("PendingTaskList", "xPendingReadyList");
Threads.newqueue("TaskList");
topPri = Debug.evaluate("*(char *)uxTopReadyPriority");
var i=0;
var j=topPri;
while(j >= 0)
{
y=Debug.evaluate("pxReadyTasksLists");
y+=(20*j);
yy=Debug.evaluate("*(xList *)0x"+y.toString(16));
pxIndex = Debug.evaluate("*(xListItem *)0x"+yy.pxIndex.toString(16));
i=0;
numItems = yy.uxNumberOfItems;
while(i<numItems && ((numItems < 100) && (numItems > 0)))
{
tcb = Debug.evaluate("*(tskTCB *)0x"+pxIndex.pvOwner.toString(16));
name = ConvertToString(tcb.pcTaskName);
pri = tcb.uxPriority;
registers = registersFromContext(tcb.pxTopOfStack+(2*4));
Threads.add(name, pri, pxIndex.pvOwner.toString(16), registers);
pxIndex = Debug.evaluate("*(xListItem *)0x"+pxIndex.pxNext.toString(16));
i++;
}
j–;
}
}