📄 task14.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Quadralay WebWorks Publisher Professional Edition 6.0.5">
<meta name="TEMPLATEBASE" content="book_html">
<meta name="LASTUPDATED" content="12/01/03 14:14:41">
<title>5.13 Stack usage</title>
<STYLE TYPE="text/css">
<!--
span.Signal { text-transform: uppercase; font-family: Verdana }
-->
</STYLE>
</head>
<body link="#3366CC" vlink="#9999CC" text="#000000" alink="#0000CC" bgcolor="#FFFFFF"
background="images/backgrnd.gif">
<p><img src="images/stlogo.gif" width="106" height="83" align="left"
alt="logo here!"> </p>
<table width="331" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td><a href="os20toc.htm"><img src="images/navtoc.gif" width="84" height="23"
border="0" alt="TOC"> </a></td>
<td><a href="task13.htm"><img src="images/navprev.gif" width="80" height="23"
border="0" alt="PREV"> </a></td>
<td><a href="task15.htm"><img src="images/navnext.gif" width="83" height="23"
border="0" alt="NEXT"> </a></td>
<td><a href="os20ix.htm"><img src="images/navidx.gif" width="84" height="23"
border="0" alt="INDEX"> </a></td>
</tr>
</table>
<p><br clear="all">
</p>
<hr align="left">
<blockquote>
<h2>
<a name="1204852"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">5.13 Stack usage</font>
</h2><hr>
<p>
<a name="1204853"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">A common problem when developing applications is not allocating enough stack for a task, or the need to tune stack allocation to minimize memory wastage. OS20 provides a couple of techniques which can be used to address this.</font>
</p>
<p>
<a name="1204860"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">The first technique is to enable stack checking in the compiler see the <em>ST20 Embedded Toolset User Manual</em>, chapter <em>st20cc compile/link tool</em>. This adds an additional function call at the start of each of the user's functions, just before any additional stack is allocated. The called stack check function can then determine whether there is sufficient space available for the function which is about to execute.</font>
</p>
<p>
<a name="1204864"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">As OS20 is multi-threaded, a special version of the stack check function needs to be used, which can determine the current task, and details about the task's stack. When using <font size=2 face=Courier><strong>runtime爋s20</strong></font> to link the application, the stack check function is linked in automatically. Otherwise it is necessary to link with the configuration file <font size=2 face=Courier><strong>os20scc1.cfg</strong></font> (for a C1 target) or <font size=2 face=Courier><strong>os20scc2.cfg</strong></font> (for a C2 target) to ensure the correct function is linked in.</font>
</p>
<p>
<a name="1204865"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Whilst stack checking has the advantage that stack overflows are reported immediately, it has a number of problems.</font>
</p>
<ul>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204866"> </a>There is a run-time cost incurred for every function call to perform the check.</font></p>
<p> <font size=2 face="Verdana, Arial, Helvetica, sans-serif"><li ><a name="1204867"> </a>It can only report on functions which are recompiled with stack checking enabled.</font></p>
</ul>
<p>
<a name="1204868"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">An alternative technique is to determine experimentally how much stack a task uses by giving the task a large stack initially, running the code, and then seeing how much stack has been used. To allow this, OS20 normally fills a task's stack with a known value. As the task runs, it writes its own data into the stack, altering this value, and later the stack can be inspected to determine the highest address which has not been altered.</font>
</p>
<p>
<a name="1204875"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">To support this, OS20 provides the function:</font>
</p>
<a name="1204876"> </a><font size=2 face=Courier><strong>int task_status( task_t* Task,<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -