Rowley threads.js support for FreeRTOS

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–;   } }

Rowley threads.js support for FreeRTOS

There is a threads.js in the download.  Does this do what you want?

Rowley threads.js support for FreeRTOS

This is exactly what I was looking for.  I guess it would have helped to perform a full search on the download ;) Thanks, Angus

Rowley threads.js support for FreeRTOS

After some testing of the threads.js included in the dowmload, I have a few questions. When placing a breakpoint I get the Task containing the breakpoint marked as executing.  I would expect the registers at the breakpoint to match the registers at the top of the Task’s stack, but they don’t.  When a task is executing are the register values poped off the tasks stack? Also I get the occasional odd (looks corrupted) names for one or some of the tasks when I place a breakpoint in specific tasks.  Anyone else seen this?  Code continues to execute fine, and it does not look like the task linked lists are corrupted.  Also tasks that have garbled names could be fine a subsequent breaks in the code. (For this test I was just running the standard IwIP_Demo_Rowley_ARM7 from the download.) Thanks, Angus

Rowley threads.js support for FreeRTOS

The registers are saved to the stack when the task is not running.  When the task is running the values that were on the stack will be overwritten by normal stack variables, and the values in the registers themselves with obviously change.  There is no reason why the two would be the same, unless your breakpoint is at the end of the portRESTORE_CONTEXT macro.