<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
Hi<br>
<br>
Ive found it useful to be able closely monitor the amount of unused
stack, especially when testing new applications or environments. A
number of others have also discussed this in this list over the years.
Ive made the following minor change to avr_thread.c which I believe has
a minor impact on NutOS but allows easy monitoring of the stack. I
also include example changes to the "threads" command found in many of
the demo applications. <br>
<br>
Is there a better way? Perhaps it or something similar could be
considered for inclusion in NutOS.<br>
<br>
Regards<br>
Brett<br>
<pre class="moz-signature" cols="72">avr_thread.c: (This would have to be done to the other os's as well)
// Only changed NutHeapAlloc to NutHeapAllocClear to ensure
// cleaned memory as the memory cannot be guaranteed to be
// clear after reset. No other change.
/*
* Allocate stack and thread info structure in one block.
*/
if ((threadMem = NutHeapAllocClear(stackSize + sizeof(NUTTHREADINFO))) == 0) {
NutExitCritical();
return 0;
}
//---------------------------------------------------------
Change to demo application.
1.Additional field in threads header line.
2.Additonal function call to count the free memory bytes
3.Addtional output of stack "ClearBytes" value
// 1.Additional field in threads header line.
prog_char thread_intro_P[] = "220 List of threads with name,state,prio,stack,mem,clearBytes,timeout follows\r\n";
//2.Additonal function call to count the free memory bytes
int CountZeroes(u_char *td_memory)
{
int myInt=0;
u_char *myPtr=td_memory;
while(*(myPtr++)==0)
myInt++;
return myInt;
}
//3.Addtional output of stack "ClearBytes" value
// Count the amount of untouched memory left in the stack for this thread
// This requires the patch to NutThreadCreate to clear allocated heap to be effective
fprintf(stream, "\t%d\t", CountZeroes(tdp->td_memory+16));
--
-----------------------------------------------------------------
Brett Abbott, Managing Director, Digital Telemetry Limited
Email: <a
class="moz-txt-link-abbreviated"
href="mailto:Brett.Abbott@digital-telemetry.com">Brett.Abbott@digital-telemetry.com</a>
PO Box 24 036 Manners Street, Wellington, New Zealand
Phone +64 (4) 5666-860 Mobile +64 (21) 656-144
------------------- Commercial in confidence --------------------
</pre>
</body>
</html>