⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rm.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************/
/*                                                                      */
/*          Copyright 1990-1992 by Accelerated Technology               */
/*                                                                      */
/*  PROPRIETARY RIGHTS of Accelerated Technology are involved in the    */
/*  subject matter of this material.  All manufacturing, reproduction,  */
/*  use, and sales rights pertaining to this subject matter are         */
/*  governed by the license agreement.  The buyer or recipient of this  */
/*  package, implicitly accepts the terms of the license.               */
/*                                                                      */
/************************************************************************/

/************************************************************************/
/*                                                                      */
/*  FILE DESCRIPTION                                                    */
/*                                                                      */
/*  This file contains routines that facilitate resource management     */
/*  using semaphores.                                                   */
/*                                                                      */
/*  ROUTINES                                                            */
/*                                                                      */
/*       RM_Initialize                      Resource Manager Init       */
/*       RM_Place_On_List                   Place on suspension list    */
/*       RM_Remove_From_List                Remove from suspension list */
/*       RM_Request_Resource                Request access to a resource*/
/*       RM_Release_Resource                Release access to a resource*/
/*       RM_Wait_For_Resource               Wait for resource           */
/*       RM_Max_Resources                   Returns the maximum         */
/*                                          number of resources         */
/*       RM_Retrieve_Status                 Retrieves the number of     */
/*                                          tasks that have requested   */
/*                                          the resource                */
/*                                                                      */
/*  NOTES                                                               */
/*                                                                      */
/*      Routines except for RM_Max_Resources and RM_Retrieve_Status     */
/*      expect that interrupts are locked out upon invocation.          */
/*                                                                      */
/************************************************************************/

/* Define necessary include files.  */

#include   "nu_defs.h"         /* General constants        */
#include   "in_extr.h"         /* Initialize references    */
#include   "rm_defs.h"         /* Data structure defns     */
#include   "sk_extr.h"         /* Scheduler routine defs   */


/* Define global data structures to the resource manager.  */

/* The pointer "RM_RCB_List" is used to point to the list of 
   sequentially allocated Resource Control Blocks (RCBs).  */
   
struct RM_RESOURCE_CONTROL_STRUCT  *RM_RCB_List;


/* The signed variable "RM_Total_Resources" contains the total number of
   system resources, as derived from the queue definition list.  */

signed int  RM_Total_Resources;

/* Declare internal function prototypes.  */

void  RM_Place_On_List(struct RM_SUSPENSION_STRUCT **ptr_head_ptr,
                        struct RM_SUSPENSION_STRUCT **ptr_tail_ptr,
                        struct RM_SUSPENSION_STRUCT  *suspend_ptr);

void  RM_Remove_From_List(struct RM_SUSPENSION_STRUCT **ptr_head_ptr,
                           struct RM_SUSPENSION_STRUCT **ptr_tail_ptr,
                           struct RM_SUSPENSION_STRUCT  *suspend_ptr);


/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "RM_Initialize"             */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to allocate and initialize all of the     */
/*      resource control blocks and the total number of resources       */
/*      variable.                                                       */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      INP_Initialize                      High level initialization   */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      INP_Memory_Alloc                    Allocate initial memory     */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      IN_System_Resources                 Total System resources      */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*       RM_RCB_List[]                      Resource Control Blocks     */
/*       RM_Total_Resources                 Total number of resources   */
/*                                                                      */
/************************************************************************/
void  RM_Initialize(unsigned int system_resources)
{

int                i;                       /* Working variable         */
int                bytes;                   /* Number of bytes to alloc */


    /* Initialize the resource management variables.  Save the total number
       of resources into a global variable.  */

    RM_Total_Resources =  system_resources;   

    
    /*  If there are any system resources, allocate and initialize the 
        associated Resource Control Block (RCB) for each resource.  */
    if (RM_Total_Resources)
    {
    
        /* Allocate memory for all of the RCBs.  */
        bytes = sizeof(struct RM_RESOURCE_CONTROL_STRUCT) * RM_Total_Resources;
        RM_RCB_List =  (struct RM_RESOURCE_CONTROL_STRUCT *)
                                                    INP_Memory_Alloc(bytes);
    }

    /* Initialize each RCB.  This includes making all of the semaphores 
       available.  */
    for (i = 0; i < RM_Total_Resources; i++)
    {
    
        /* Initialize the RCB entry.  */
        RM_RCB_List[i].rm_semaphore =  0;
        RM_RCB_List[i].rm_task_id =    NU_SYSTEM;

        /* Initialize the wait pointers.  */
        RM_RCB_List[i].rm_wait_head =  NU_NULL;
        RM_RCB_List[i].rm_wait_tail =  NU_NULL;
    }
}                                           /* end of  RM_Initialize    */


/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "RM_Place_On_List"          */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to link a suspension structure on a       */
/*      specified linked list.                                          */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*       RM_Wait_For_Resource               Wait for a resource         */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      ptr_head_ptr                        Pointer to list head ptr    */
/*      ptr_tail_ptr                        Pointer to list tail ptr    */
/*      suspend_ptr                         Pointer to suspend block    */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Suspension List                                                 */
/*                                                                      */
/************************************************************************/
void  RM_Place_On_List(struct RM_SUSPENSION_STRUCT **ptr_head_ptr,
       struct RM_SUSPENSION_STRUCT **ptr_tail_ptr,
       struct RM_SUSPENSION_STRUCT *suspend_ptr)
{

    /*  Determine if there is another suspension block to update.  */
    if (*ptr_tail_ptr != NU_NULL)
    {

        /* Yup, there are others currently suspended, place the new
           suspension request at the end.  */
        (*ptr_tail_ptr) -> rm_next_susp =  suspend_ptr;
        suspend_ptr -> rm_prev_susp =     *ptr_tail_ptr;
        suspend_ptr -> rm_next_susp =     NU_NULL;
        *ptr_tail_ptr =                   suspend_ptr;
    }
    else
    {
        /* Place the suspension request right up front.  */
        *ptr_head_ptr =                  suspend_ptr;
        *ptr_tail_ptr =                  suspend_ptr;
        suspend_ptr -> rm_prev_susp =    NU_NULL;
        suspend_ptr -> rm_next_susp =    NU_NULL;
    }           
}                                           /* end of  RM_Place_On_List */


/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "RM_Remove_From_List"       */
/*                                                                      */
/*                                                                      */

⌨️ 快捷键说明

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