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

📄 fm.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
        (header_ptr -> fm_pattern_2 == BOTTOM_PATTERN))
    {

        /* Point to the partition control block.  */
        PCB_ptr =  &FM_PCB_List[header_ptr -> fm_partition_id];
    
        /* Determine if there are tasks waiting to allocate partitions of 
           this type.  */
        if (PCB_ptr -> fm_alloc_wait_head != NU_NULL)
        {
        
            /* Yes, there is something waiting for this partition.  */

            /* Point to the suspension structure.  */
            suspend_ptr =  PCB_ptr -> fm_alloc_wait_head;
            
            /* Show this task as owning the partition. */
            header_ptr -> fm_task_id =   suspend_ptr -> fm_task_id;
            
            /* Return the memory pointer address.  */
            *(suspend_ptr -> fm_return_addr) =  memory_ptr;

            /* Remove the suspension pointer.  */
            FM_Remove_From_List(
                (struct FM_LIST_STRUCT **) &(PCB_ptr -> fm_alloc_wait_head),
                (struct FM_LIST_STRUCT **) &(PCB_ptr -> fm_alloc_wait_tail),
                (struct FM_LIST_STRUCT *)  suspend_ptr);

            /* Lift the suspension on the task and check to see if it has 
               higher priority.  */
            if (SKP_Ready_Task(suspend_ptr -> fm_task_id))
            {
            
                /* Leave this task temporarily.  */
                SKD_Leave_Task();
            }          
        }
        else
        {
        
            /* There are no tasks suspended on the partition.... Just 
               clear the header and place it back on the available list.  */
            header_ptr -> fm_in_use =   NU_FALSE;
            header_ptr -> fm_task_id =  NU_FALSE;
            
            /* Place the partition back on the available list.  */
            FM_Place_On_List(
               (struct FM_LIST_STRUCT **) &(PCB_ptr -> fm_available_head),
               (struct FM_LIST_STRUCT **) &(PCB_ptr -> fm_available_tail),
               (struct FM_LIST_STRUCT *)  header_ptr);

            /* Increment the number of free pointers.  */
            PCB_ptr -> fm_free_partitions++;
        }

        /* Either way return a good status.  */
        status =  NU_SUCCESS;
    }
    else
    {
    
        /* Return an appropriate status.  */
        status =  NU_NOT_INUSE;
    }
    
    /* Return the status to the caller.  */
    return(status);
}                                           /* end of FM_Deallocate_Partition*/



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "FM_Wait_For_Partition"     */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function suspends the task on the partition not available  */
/*      list.                                                           */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that wait for memory partitions                */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      FM_Place_On_List                    Place a suspend block on lst*/
/*      FM_Remove_From_List                 Remove suspend block        */
/*      SKP_Suspend_Task                    Suspend the task            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      task_id                             Task identification         */
/*      partition_id                        Partition identification    */
/*      source_ptr                          Pointer to source item      */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(memory_ptr)                                              */
/*                                                                      */
/************************************************************************/
unsigned int *FM_Wait_For_Partition(signed int task_id,
               signed int partition_id)
{

struct FM_SUSPENSION_STRUCT  
                   suspend_block;           /* Suspension control block */
unsigned int      *memory_ptr;              /* Memory partition pointer */
struct FM_BLOCK_CONTROL_STRUCT  
                  *PCB_ptr;                 /* Pointer to PCB entry     */
    
    /* Initialize the memory_ptr to a null.  If the partition becomes 
       available prior to the timeout, this is set to the partition ptr.  */
    memory_ptr =  NU_NULL;

    /* Build a pointer to the PCB.  */
    PCB_ptr =  &FM_PCB_List[partition_id];

    /* Build the suspension block.  */
    suspend_block.fm_task_id =      task_id;
    suspend_block.fm_partition_id = partition_id;
    suspend_block.fm_return_addr =  &memory_ptr;
    suspend_block.fm_next_susp =    NU_NULL;
    suspend_block.fm_prev_susp =    NU_NULL;
    
    /* Place the suspend block on the partition full suspension for associated
       partition.  */
    FM_Place_On_List(
      (struct FM_LIST_STRUCT **) 
                            &(PCB_ptr -> fm_alloc_wait_head),
      (struct FM_LIST_STRUCT **)
                            &(PCB_ptr -> fm_alloc_wait_tail),
                      (struct FM_LIST_STRUCT *) &suspend_block);
    
    /* Suspend the task.  */
    SKP_Suspend_Task(task_id, NU_MEMORY_SUSPEND);
    
    /* Check to see if a timeout occurred.  In this case the suspend block
       is still part of the list, remove it!  */
    if (memory_ptr == NU_NULL)
    {

        /* Remove the suspend block from the list.  */
        FM_Remove_From_List(
           (struct FM_LIST_STRUCT **) 
                    &(PCB_ptr -> fm_alloc_wait_head),
           (struct FM_LIST_STRUCT **) 
                    &(PCB_ptr -> fm_alloc_wait_tail),
           (struct FM_LIST_STRUCT *)  &suspend_block);
    }

    /* Return the memory pointer to the caller.  */
    return(memory_ptr);
}                                           /* end of FM_Wait_For_Partition */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "FM_Max_Partitions"         */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function returns the total number of partitions in         */
/*      the system.                                                     */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that request partitions                        */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(FM_Total_Partitions)                                     */
/*                                                                      */
/************************************************************************/
signed int  FM_Max_Partitions()
{

    /* Return the number of partitions to the caller.  */
    return(FM_Total_Partitions);
}                                           /* end of FM_Max_Partitions */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "FM_Available"              */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function returns the total number of available partitions  */
/*      for a given partition ID.                                       */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that request partitions                        */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(free_partitions)                                         */
/*                                                                      */
/************************************************************************/
signed int  FM_Available(signed int partition_id)
{

    /* Return the number of free partitions to the caller.  */
    return(FM_PCB_List[partition_id].fm_free_partitions);
}                                           /* end of FM_Available      */

⌨️ 快捷键说明

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