seg_core.c
来自「澳洲人写的Cortex,包括uC_IP协议栈」· C语言 代码 · 共 150 行
C
150 行
<HTML><HEAD><TITLE>/home/asysweb/public_html/cortex/kernel/src/seg_core.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="seg_priv.h.FIND-INC"><font color="blue">"seg_priv.h"</font></a><b><font color='DarkGreen'>#include</font></b> <a href="ass_defs.h.FIND-INC"><font color="blue">"ass_defs.h"</font></a><font color="#6920ac">/* returns CRTX_TRUE if ok CRTX_FALSE otherwise */</font><font size="+1"><i>crtx_Bool_t</i> <b><font color="azure1"><a name="segm_Define">segm_Define</a></font></b>(<i>segm_Table_t</i> *pelem,<i>crtx_SegNum_t</i> Num_a) {</font> <font color="#6920ac">/* check a record and a number of a segment */</font> <i>crtx_Int16_t</i> j; <a href="rrlc_Lock.FIND-FUNC">rrlc_Lock</a>( &segm_DynSegLock_g ); <b>if</b> ( Num_a < <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> || Num_a >= <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> + <a href="SEGM_MAX_DYN_NUMBER.FIND-DEF">SEGM_MAX_DYN_NUMBER</a> || Num_a < 0 ) { <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrSegmentNum_Exc; } Num_a-=<a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a>; <font color="#6920ac">/* check that a segmen is free (check pcreate because address may be 0) */</font> <b>if</b> (segm_DynTable_g[Num_a].pCreate != <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a>) { <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrSegmentBusy_Err; } <font color="#6920ac">/* check pointers on functions and align */</font> <b>if</b> ( pelem->pCreate == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a> || (pelem->pAlloc == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a> && pelem->pAllocSt == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a>)|| pelem->pFree == <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a> ) { <a href="DMEM_INIT_ERROR.FIND-DEF">DMEM_INIT_ERROR</a>((<font color="DarkGreen">"Wrong dynamic segment No %d descriptor\n"</font>, Num_a+<a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a>)); <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrWrongInitData_Exc; } <b>if</b> (((<i>dmem_Size_t</i>)(pelem->ad) & (~(-<a href="DMEM_MIN_ALIGN.FIND-DEF">DMEM_MIN_ALIGN</a>))) != 0) { <a href="DMEM_INIT_ERROR.FIND-DEF">DMEM_INIT_ERROR</a>((<font color="DarkGreen">"Wrong dynamic segment No %d alignment\n"</font>, Num_a+<a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a>)); <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrWrongAlignment_Exc; } <font color="#6920ac">/* check nexts array */</font> <b>for</b> (j = 0; j<pelem->numnext; j++) { <b>if</b> ((pelem->pnexts[j] >= <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> + <a href="SEGM_MAX_DYN_NUMBER.FIND-DEF">SEGM_MAX_DYN_NUMBER</a>) || (pelem->pnexts[j] < 0)) { <a href="DMEM_INIT_ERROR.FIND-DEF">DMEM_INIT_ERROR</a>((<font color="DarkGreen">"Wrong next segment No %d.pnexts[%d] = %d \n"</font>, Num_a,j,pelem->pnexts[j])); <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrSegmentNum_Exc; } } <b>if</b> (pelem->ad != <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a>) { <font color="#6920ac">/* init segment manager */</font> <b>if</b> (!(pelem->pCreate)(pelem->ad, pelem->sz, pelem->pcontext)) { <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrCreateSegFail_Err; } } <font color="#6920ac">/* copy descriptor from user data into table of segments */</font> segm_DynTable_g[Num_a].ad=pelem->ad; segm_DynTable_g[Num_a].sz=pelem->sz; segm_DynTable_g[Num_a].pcontext=pelem->pcontext; segm_DynTable_g[Num_a].numnext=pelem->numnext; segm_DynTable_g[Num_a].pnexts=pelem->pnexts; segm_DynTable_g[Num_a].pCreate=pelem->pCreate; segm_DynTable_g[Num_a].pAlloc=pelem->pAlloc; segm_DynTable_g[Num_a].pAllocSt=pelem->pAllocSt; segm_DynTable_g[Num_a].pReall=pelem->pReall; segm_DynTable_g[Num_a].pFree=pelem->pFree; segm_DynTable_g[Num_a].pInfo=pelem->pInfo; segm_DynTable_g[Num_a].pCheck=pelem->pCheck; <a href="rrlc_Unlock.FIND-FUNC">rrlc_Unlock</a>( &segm_DynSegLock_g ); <b>return</b>(<a href="CRTX_TRUE.FIND-DEF">CRTX_TRUE</a>);<font color="blue">ErrWrongAlignment_Exc:</font><font color="blue">ErrSegmentBusy_Err:</font><font color="blue">ErrCreateSegFail_Err:</font><font color="blue">ErrWrongInitData_Exc:</font><font color="blue">ErrSegmentNum_Exc:</font> <a href="rrlc_Unlock.FIND-FUNC">rrlc_Unlock</a>( &segm_DynSegLock_g ); <b>return</b>(<a href="CRTX_FALSE.FIND-DEF">CRTX_FALSE</a>);}<font size="+1"><i>crtx_Void_t</i> <b><font color="azure1"><a name="segm_Free">segm_Free</a></font></b>(<i>crtx_SegNum_t</i> Num_a){</font> <a href="rrlc_Lock.FIND-FUNC">rrlc_Lock</a>( &segm_DynSegLock_g ); <b>if</b> ( Num_a < <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> || Num_a >= <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> + <a href="SEGM_MAX_DYN_NUMBER.FIND-DEF">SEGM_MAX_DYN_NUMBER</a> || Num_a < 0 ) { <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrSegmentNum_Exc; } segm_DynTable_g[ Num_a - <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> ].pCreate = <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a>; segm_DynTable_g[ Num_a - <a href="SEGM_MAX_NUMBER.FIND-DEF">SEGM_MAX_NUMBER</a> ].ad = <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a>;<font color="blue">ErrSegmentNum_Exc:</font> <a href="rrlc_Unlock.FIND-FUNC">rrlc_Unlock</a>( &segm_DynSegLock_g ); <b>return</b>;}<font size="+1"><i>segm_Table_t</i> * <b><font color="azure1"><a name="segm_InitTaskSegm">segm_InitTaskSegm</a></font></b>( <i>segm_Table_t</i> *pSegDesc_a ){</font> <a href="CRTX_ASSERT.FIND-DEF">CRTX_ASSERT</a>( pSegDesc_a ) <a href="CRTX_ASSERT.FIND-DEF">CRTX_ASSERT</a>( ( pSegDesc_a->pCreate != <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a> ) && ( ( pSegDesc_a->pAlloc != <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a> ) || ( pSegDesc_a->pAllocSt != <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a> ) ) && ( pSegDesc_a->pFree != <a href="CRTX_NULL.FIND-DEF">CRTX_NULL</a> ) ) <b>if</b> (!(*pSegDesc_a->pCreate)(pSegDesc_a->ad, pSegDesc_a->sz, pSegDesc_a->pcontext)) { <a href="CRTX_EXCEPTION.FIND-DEF">CRTX_EXCEPTION</a> ErrCreate_Exc; } <b>return</b>(pSegDesc_a);<font color="blue">ErrCreate_Exc:</font> <b>return</b>( <a href="DMEM_NULL.FIND-DEF">DMEM_NULL</a> );}</pre></BODY></HTML>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?