📄 cxrsrsv1.c
字号:
/*********************************************************
Copyright (c) CMX Company. 1999. All rights reserved
*********************************************************/
/* version 5.30 */
#define CMXMODULE 1
#include <cxfuncs.h> /* get cmx include header file */
#include <cxextern.h> /* get cmx include header file */
#ifdef CMXTRACKER
#include <cmxtrack.h> /* get cmx include header file */
#endif
/*******************************************************************
This function allows a task to reserve or get this resource.
if func_mode = 1, then means get resource if free, otherwise return
if func_mode = 0, then if the resource is "owned" by another task,
then this task will be suspended until this resource is free or time
period expires.
*******************************************************************/
byte K_I_Resource_Common(byte res_grp,word16 timecnt,byte func_mode)
{
RESHDR *res_ptr;
tcbpointer tp;
if (res_grp >= MAX_RESOURCES) /* see if resource number allowed */
{
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in3(CXRSRSV_K_ERROR,res_grp,func_mode);
}
#endif
return(K_ERROR); /* no, return error status */
}
K_I_Disable_Sched(); /* set task block */
res_ptr = &res_que[res_grp]; /* get address of resource */
if (res_ptr->owner) /* does a task own this resource? */
{
/* yes, what function was used. */
if (func_mode) /* did the K_Resource_Get function call this function */
{
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in2(CXRSRSV_K_RESOURCE_OWNED,res_grp);
}
#endif
K_I_Func_Return(); /* release task block */
return(K_RESOURCE_OWNED); /* return error that resource is already owned */
}
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in4(CXRSRSV_CALL,res_grp,timecnt);
}
#endif
/* place the task into the resource doubly linked wait list. */
tp = (tcbpointer)res_ptr; /* address of resource link list. */
do /* insert tcb at appropriate wait slot, based on priority. */
{
tp = tp->fwlink;
} while ((tp != (tcbpointer)res_ptr) && (tp->priority <= activetcb->priority));
/* We should insert it just after prevtcb, just before tp. */
activetcb->fwlink = tp->bwlink->fwlink;
tp->bwlink->fwlink = activetcb;
activetcb->bwlink = tp->bwlink;
tp->bwlink = activetcb;
if (res_ptr->fwlink->priority < res_ptr->owner->priority)
{
res_ptr->owner->priority = res_ptr->fwlink->priority;
/* update linked list to put owner in correct spot */
K_I_Unlink(res_ptr->owner);
K_I_Priority_In(res_ptr->owner,res_ptr->owner->priority);
}
/*
res_ptr->fwlink->priority is highest priority !!!
which we will then raise owner to highest !!!
*/
/* go place task into suspended state. */
if (K_I_Time_Common(timecnt,RESOURCE))
{
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in1(CXRSRSV_DELAY_K_TIMEOUT);
}
#endif
return(K_TIMEOUT); /* return the warning: that the time period expired */
}
else
{
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in2(CXRSRSV_K_OK,res_grp);
}
#endif
return(K_OK);
}
}
/* NO, no task owned this resource. This task is now the owner of
this resource */
res_ptr->fwlink = res_ptr->bwlink = (tcbpointer)(res_ptr);
res_ptr->owner = activetcb;
res_ptr->owner_priority = activetcb->priority;
#ifdef CMXTRACKER
if (CMXTRACKER_ON)
{
cmxtracker_in3(CXRSRSV_K_OK,res_grp,func_mode);
}
#endif
K_I_Func_Return(); /* release task block. */
return(K_OK); /* return good status. */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -