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

📄 dmce.c

📁 已移植到TI OMAP1610处理器的Nucleus操作系统源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*************************************************************************/
/*                                                                       */
/*               Copyright Mentor Graphics Corporation 2002              */
/*                         All Rights Reserved.                          */
/*                                                                       */
/* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS  */
/* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS   */
/* SUBJECT TO LICENSE TERMS.                                             */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                               VERSION       */
/*                                                                       */
/*      dmce.c                                         Nucleus PLUS 1.14 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      DM - Dynamic Memory Management                                   */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the error checking routines for the functions */
/*      in the dynamic memory management component.  This permits easy   */
/*      removal of the error checking logic when it is not needed.       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      DMCE_Create_Memory_Pool             Create a dynamic memory pool */
/*      DMCE_Delete_Memory_Pool             Delete a dynamic memory pool */
/*      DMCE_Allocate_Memory                Allocate a memory block from */
/*                                            a dynamic memory pool      */
/*      DMCE_Deallocate_Memory              Deallocate a memory block    */
/*                                            from a dynamic memory pool */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      cs_extr.h                           Common Service functions     */
/*      tc_extr.h                           Thread Control functions     */
/*      dm_extr.h                           Partition functions          */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      11-01-1993      Corrected call of actual                         */
/*                        function to delete a memory                    */
/*                        pool, resulting in version 1.0a                */
/*      11-01-1993      Verfied version 1.0a                             */
/*      03-01-1994      Changed name original error                      */
/*                        checking file and changed                      */
/*                        function interfaces, resulting                 */
/*                        in version 1.1                                 */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*      04-17-1996      updated to version 1.2                           */
/*      03-24-1998      Released version 1.3.                            */
/*      04-17-2002      Released version 1.13m                           */
/*      11-07-2002      Released version 1.14                            */
/*************************************************************************/
#define         NU_SOURCE_FILE


#include        "cs_extr.h"                 /* Common service functions  */
#include        "tc_extr.h"                 /* Thread control functions  */
#include        "dm_extr.h"                 /* Dynamic memory functions  */


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      DMCE_Create_Memory_Pool                                          */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function performs error checking on the parameters supplied */
/*      to the create dynamic memory pool function.                      */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      DMC_Create_Memory_Pool              Actual create dynamic memory */
/*                                            pool function              */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      pool_ptr                            Memory pool control block    */
/*                                            pointer                    */
/*      name                                Memory pool name             */
/*      start_address                       Starting address of the pool */
/*      pool_size                           Number of bytes in the pool  */
/*      min_allocation                      Minimum allocation size      */
/*      suspend_type                        Suspension type              */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_INVALID_POOL                     Indicates the pool control   */
/*                                            block pointer is invalid   */
/*      NU_INVALID_MEMORY                   Indicates the starting       */
/*                                            memory address is NULL     */
/*      NU_INVALID_SIZE                     Indicates that either the    */
/*                                            pool size and/or the       */
/*                                            minimum allocation size is */
/*                                            invalid                    */
/*      NU_INVALID_SUSPEND                  Indicate the suspension type */
/*                                            is invalid                 */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      03-01-1994      Modified function interface,                     */
/*                        resulting in version 1.1                       */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*                                                                       */
/*************************************************************************/
STATUS  DMCE_Create_Memory_Pool(NU_MEMORY_POOL *pool_ptr, CHAR *name, 
                        VOID *start_address, UNSIGNED pool_size, 
                        UNSIGNED min_allocation, OPTION suspend_type)
{

DM_PCB         *pool;                       /* Pool control block ptr    */
STATUS          status;                     /* Completion status         */
UNSIGNED        adjusted_min;               /* Adjusted size of minimum  */
UNSIGNED        adjusted_pool;              /* Adjusted size of pool     */


    /* Move input pool pointer into internal pointer.  */
    pool =  (DM_PCB *) pool_ptr;

    /* Adjust the minimum allocation size to something that is evenly 
       divisible by the number of bytes in an UNSIGNED data type.  */
    adjusted_min = ((min_allocation + sizeof(UNSIGNED) - 1)/sizeof(UNSIGNED)) *
                                                        sizeof(UNSIGNED);

    /* Adjust the pool size to something that is evenly divisible by the 
       number of bytes in an UNSIGNED data type.  */
    adjusted_pool = ((pool_size + sizeof(UNSIGNED) - 1)/sizeof(UNSIGNED)) *
                                                        sizeof(UNSIGNED);

    /* Check for a NULL dynamic memory pool control block pointer or a control
       block that is already created.  */
    if ((pool == NU_NULL) || (pool -> dm_id == DM_DYNAMIC_ID))
    
        /* Invalid dynamic memory pool control block pointer.  */
        status =  NU_INVALID_POOL;
        
    else if (start_address == NU_NULL)
    
        /* Invalid memory pointer.  */
        status =  NU_INVALID_MEMORY;
        
    else if ((adjusted_min == 0) || 
                ((adjusted_min + (2 * DM_OVERHEAD)) > adjusted_pool))
    
        /* Pool could not even accommodate one allocation.  */
        status =  NU_INVALID_SIZE;
        
    else if ((suspend_type != NU_FIFO) && (suspend_type != NU_PRIORITY))
    
        /* Invalid suspension type.  */
        status =  NU_INVALID_SUSPEND;
        
    else
    
        /* Call the actual service to create the dynamic memory pool.  */
        status =  DMC_Create_Memory_Pool(pool_ptr, name, start_address, 
                                    pool_size, min_allocation, suspend_type);
        
    /* Return completion status.  */
    return(status);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      DMCE_Delete_Memory_Pool                                          */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function performs error checking on the parameters supplied */
/*      to the delete dynamic memory pool function.                      */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      DMC_Delete_Memory_Pool              Actual function to delete a  */
/*                                            dynamic memory pool        */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      pool_ptr                            Memory pool control block    */
/*                                            pointer                    */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_INVALID_POOL                     Indicates the pool pointer   */
/*                                            is invalid                 */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      11-01-1993      Corrected call of actual                         */
/*                        function to delete a memory                    */
/*                        pool, resulting in version 1.0a                */
/*      11-01-1993      Verfied version 1.0a                             */
/*      03-01-1994      Modified function interface,                     */

⌨️ 快捷键说明

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