As I mentioned in a different thread, I thought it would be interesting to make a version of my hexapod code base that uses the rtos. It would be nice to split things off, that need to happen at specific intervals to be their own tasks, instead of littering the code with calls off, to some place that checks the time and if appropriate does the work. Note: I could probably use interval timer to do some of these. Example: with the robotis AX servos, Their built-in interpolation stuff does not work very well, so we instead, have the processor do this N times per second. Thought it would be nice to have this done automatically for me.
I have completed a first pass through the code base and started to try it out. The first tries have not been completely successful. At first the Teensy was so hung up, the comm port associated with the USB would not longer talk to windows... Making progress. Now backing off and doing a normal thing of trying out bits and pieces first.
Was not sure where the processor was hanging, so started to add some debug stuff... First trying to figure out which task is running so I added:
Code:
#define traceTASK_SWITCHED_IN() {if (pxCurrentTCB->pxTaskTag) digitalWrite(( int ) pxCurrentTCB->pxTaskTag, 1 );}
#define traceTASK_SWITCHED_OUT() {if (pxCurrentTCB->pxTaskTag) digitalWrite(( int ) pxCurrentTCB->pxTaskTag, 0 );}
I had to turn on an option to allow task tags:
#define configUSE_APPLICATION_TASK_TAG 1 // was 0
Added a task tag for the different task, where the tag was an IO pin number:
vTaskSetApplicationTaskTag( NULL, ( TaskHookFunction_t ) 20);
Now when I run my program I do see which tasks run when which is nice.
But then I wondered if maybe I was over running one of my stacks, so I added a debug command to my quick and dirty terminal monitor, to print out stack high water marks...
Code:
DBGSerial.println("Stack Usage");
for(int i=0; i< 4; i++) {
DBGSerial.print(i, DEC);
DBGSerial.print(" ");
DBGSerial.println (uxTaskGetStackHighWaterMark(g_aTasks[i]));
}
The task creates fill in the array g_aTasks
xTaskCreate(NothingTask, "Nothing", 1000, NULL, 2, &g_aTasks[3]);
However I am not sure I trust the results. as from my extracted code, I am seeing:
Code:
Stack Usage
0 3956
1 962
2 1962
3 988
As I understand this, these are in stack units or in this case 32 bit elements. But these just don't seam right. Example the task 3 shows it uses 988 bytes, but this task does absolutely nothing:
Code:
void NothingTask(void *pv) {
vTaskSetApplicationTaskTag( NULL, ( TaskHookFunction_t ) 23 );
for(;;) {
vTaskDelay((200L * configTICK_RATE_HZ) / 1000L);
}
}
It says it uses more stack than the debug monitor task(1) that, looked for serial input, checked what it was and in this case looped calling off to print stuff.
And if I understand this properly it says it used 988 (units or) almost 4K bytes. Which seam way too high as the example programs like frBlink, create their threads, using a stack size of: configMINIMAL_STACK_SIZE, which in the RTOS configuration file is defined as 130.
Thoughts/Suggestions? My first one is that there is a problem with the high water mark stuff, but my first quick look through did not notice anything obvious.
Thanks
Kurt
Edit: Actually I think I am looking at this wrong, instead of telling me how much of the stack was used, it instead is telling me how much of it is not used. Example I changed the create of the Nothing task from 1000 to 300 and now the command shows: 288