seg_init.c

来自「澳洲人写的Cortex,包括uC_IP协议栈」· C语言 代码 · 共 79 行

C
79
字号
<HTML><HEAD><TITLE>/home/asysweb/public_html/cortex/kernel/src/seg_init.c</TITLE></HEAD><BODY><pre><font color="#6920ac">/*************************************************************************/</font><font color="#6920ac">/*                                                                       */</font><font color="#6920ac">/*     Copyright (c) 1997-1999 Australian Real Time Embedded Systems     */</font><font color="#6920ac">/*                                                                       */</font><font color="#6920ac">/* PROPRIETARY RIGHTS of Australian Real Time Embedded Systems           */</font><font color="#6920ac">/* are involved in the subject matter of this material. All reproduction,*/</font><font color="#6920ac">/* manufacturing, use, and sales rights pertaining to this subject matter*/</font><font color="#6920ac">/* are governed by the license agreement. The recipient of this software */</font><font color="#6920ac">/* implicitly accepts the terms of the license.                          */</font><font color="#6920ac">/*                                                                       */</font><font color="#6920ac">/*************************************************************************/</font><b><font color='DarkGreen'>#include</font></b> <a href="ass_defs.h.FIND-INC"><font color="blue">"ass_defs.h"</font></a><b><font color='DarkGreen'>#include</font></b> <a href="mem_defs.h.FIND-INC"><font color="blue">"mem_defs.h"</font></a><b><font color='DarkGreen'>#include</font></b> <a href="seg_priv.h.FIND-INC"><font color="blue">"seg_priv.h"</font></a><b><font color='DarkGreen'>#include</font></b> <a href="sys_defs.h.FIND-INC"><font color="blue">"sys_defs.h"</font></a><font size="+1"><i>crtx_Void_t</i> <b><font color="azure1"><a name="segm_Init">segm_Init</a></font></b>(<i>crtx_Void_t</i>){</font>    <i>crtx_Int16_t</i> i;    <i>crtx_Int16_t</i> j;    <i>crtx_Bool_t</i>  Result = <a href="CRTX_TRUE.FIND-DEF">CRTX_TRUE</a>;    <a href="CRTX_ASSERT.FIND-DEF">CRTX_ASSERT</a>(<a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> &gt; 0);    <font color="#6920ac">/* create lock for dynamic segment table */</font>    <b>if</b> (<a href="rrlc_Create.FIND-FUNC">rrlc_Create</a>(&amp;segm_DynSegLock_g,(<i>void</i> *)0) == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a>)    {        <a href="syst_Fatal.FIND-FUNC">syst_Fatal</a>(<font color="DarkGreen">"Creation segment lock failed\n"</font>);    }    <b>for</b> (i=0; i &lt; <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> &amp;&amp; Result; i++)    {                <font color="#6920ac">/* free segments are possible and in this case */</font>        <font color="#6920ac">/* ad must be (crtx_Void_t *)0 */</font>        <b>if</b> (segm_Table_g[i].ad == <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a>) <b>continue</b>;                <b>if</b> ( segm_Table_g[i].pCreate==0 ||             (segm_Table_g[i].pAlloc==0 &amp;&amp; segm_Table_g[i].pAllocSt ==0) ||             segm_Table_g[i].pFree==0 )        {            <a href="SEGM_INIT_ERROR.FIND-DEF">SEGM_INIT_ERROR</a>((<font color="DarkGreen">"Wrong segment No %d descriptor\n"</font>,i));            Result = 0;            <b>break</b>;        }        <font color="#6920ac">/* check links */</font>        <b>for</b> (j = 0; j&lt;segm_Table_g[i].numnext; j++)        {            <b>if</b> ((segm_Table_g[i].pnexts[j] &gt;=                  <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> + <a href="SEGM_MAX_DYN_NUMBER.FIND-DEF">SEGM_MAX_DYN_NUMBER</a>) ||                (segm_Table_g[i].pnexts[j] &lt; -1)) {                <a href="SEGM_INIT_ERROR.FIND-DEF">SEGM_INIT_ERROR</a>((<font color="DarkGreen">"Wrong next segment No %d.pnexts[%d] = %d \n"</font>,                                 i,j,segm_Table_g[i].pnexts[j]));            }        }        Result &amp;= (*segm_Table_g[i].pCreate)(segm_Table_g[i].ad,                                             segm_Table_g[i].sz,                                             segm_Table_g[i].pcontext);    }    <b>for</b> (i=0; i &lt; <a href="SEGM_MAX_DYN_NUMBER.FIND-DEF">SEGM_MAX_DYN_NUMBER</a>; i++)    {        segm_DynTable_g[i].ad = <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a>;        segm_DynTable_g[i].pCreate = <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a>;    }    <b>if</b> (!Result)    {        <a href="syst_Fatal.FIND-FUNC">syst_Fatal</a>(<font color="DarkGreen">"%s\n"</font>,<font color="DarkGreen">"Init memory manager failed"</font>);    }    <b>return</b>;}</pre></BODY></HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?