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

📄 os_mem.lst

📁 编译环境是 iar EWARM ,STM32 下的UCOSII
💻 LST
📖 第 1 页 / 共 3 页
字号:
    112              pmem->OSMemNFree    = nblks;                      /* Store number of free blocks in MCB            */
    113              pmem->OSMemNBlks    = nblks;
    114              pmem->OSMemBlkSize  = blksize;                    /* Store block size of each memory blocks        */
    115              *perr               = OS_ERR_NONE;
    116              return (pmem);
    117          }
    118          /*$PAGE*/
    119          /*
    120          *********************************************************************************************************
    121          *                                          GET A MEMORY BLOCK
    122          *
    123          * Description : Get a memory block from a partition
    124          *
    125          * Arguments   : pmem    is a pointer to the memory partition control block
    126          *
    127          *               perr    is a pointer to a variable containing an error message which will be set by this
    128          *                       function to either:
    129          *
    130          *                       OS_ERR_NONE             if the memory partition has been created correctly.
    131          *                       OS_ERR_MEM_NO_FREE_BLKS if there are no more free memory blocks to allocate to caller
    132          *                       OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
    133          *
    134          * Returns     : A pointer to a memory block if no error is detected
    135          *               A pointer to NULL if an error is detected
    136          *********************************************************************************************************
    137          */
    138          
    139          void  *OSMemGet (OS_MEM *pmem, INT8U *perr)
    140          {
    141              void      *pblk;
    142          #if OS_CRITICAL_METHOD == 3                           /* Allocate storage for CPU status register      */
    143              OS_CPU_SR  cpu_sr = 0;
    144          #endif
    145          
    146          
    147          
    148          #if OS_ARG_CHK_EN > 0
    149              if (perr == (INT8U *)0) {                         /* Validate 'perr'                               */
    150                  return ((void *)0);
    151              }
    152              if (pmem == (OS_MEM *)0) {                        /* Must point to a valid memory partition        */
    153                  *perr = OS_ERR_MEM_INVALID_PMEM;
    154                  return ((void *)0);
    155              }
    156          #endif
    157              OS_ENTER_CRITICAL();
    158              if (pmem->OSMemNFree > 0) {                       /* See if there are any free memory blocks       */
    159                  pblk                = pmem->OSMemFreeList;    /* Yes, point to next free memory block          */
    160                  pmem->OSMemFreeList = *(void **)pblk;         /*      Adjust pointer to new free list          */
    161                  pmem->OSMemNFree--;                           /*      One less memory block in this partition  */
    162                  OS_EXIT_CRITICAL();
    163                  *perr = OS_ERR_NONE;                          /*      No error                                 */
    164                  return (pblk);                                /*      Return memory block to caller            */
    165              }
    166              OS_EXIT_CRITICAL();
    167              *perr = OS_ERR_MEM_NO_FREE_BLKS;                  /* No,  Notify caller of empty memory partition  */
    168              return ((void *)0);                               /*      Return NULL pointer to caller            */
    169          }
    170          /*$PAGE*/
    171          /*
    172          *********************************************************************************************************
    173          *                                   GET THE NAME OF A MEMORY PARTITION
    174          *
    175          * Description: This function is used to obtain the name assigned to a memory partition.
    176          *
    177          * Arguments  : pmem      is a pointer to the memory partition
    178          *
    179          *              pname     is a pointer to an ASCII string that will receive the name of the memory partition.
    180          *
    181          *              perr      is a pointer to an error code that can contain one of the following values:
    182          *
    183          *                        OS_ERR_NONE                if the name was copied to 'pname'
    184          *                        OS_ERR_MEM_INVALID_PMEM    if you passed a NULL pointer for 'pmem'
    185          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
    186          *                        OS_ERR_NAME_GET_ISR        You called this function from an ISR
    187          *
    188          * Returns    : The length of the string or 0 if 'pmem' is a NULL pointer.
    189          *********************************************************************************************************
    190          */
    191          
    192          #if OS_MEM_NAME_SIZE > 1
    193          INT8U  OSMemNameGet (OS_MEM *pmem, INT8U *pname, INT8U *perr)
    194          {
    195              INT8U      len;
    196          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    197              OS_CPU_SR  cpu_sr = 0;
    198          #endif
    199          
    200          
    201          
    202          #if OS_ARG_CHK_EN > 0
    203              if (perr == (INT8U *)0) {                    /* Validate 'perr'                                    */
    204                  return (0);
    205              }
    206              if (pmem == (OS_MEM *)0) {                   /* Is 'pmem' a NULL pointer?                          */
    207                  *perr = OS_ERR_MEM_INVALID_PMEM;
    208                  return (0);
    209              }
    210              if (pname == (INT8U *)0) {                   /* Is 'pname' a NULL pointer?                         */
    211                  *perr = OS_ERR_PNAME_NULL;
    212                  return (0);
    213              }
    214          #endif
    215              if (OSIntNesting > 0) {                      /* See if trying to call from an ISR                  */
    216                  *perr = OS_ERR_NAME_GET_ISR;
    217                  return (0);
    218              }
    219              OS_ENTER_CRITICAL();
    220              len   = OS_StrCopy(pname, pmem->OSMemName);  /* Copy name from OS_MEM                              */
    221              OS_EXIT_CRITICAL();
    222              *perr = OS_ERR_NONE;
    223              return (len);
    224          }
    225          #endif
    226          
    227          /*$PAGE*/
    228          /*
    229          *********************************************************************************************************
    230          *                                 ASSIGN A NAME TO A MEMORY PARTITION
    231          *
    232          * Description: This function assigns a name to a memory partition.
    233          *
    234          * Arguments  : pmem      is a pointer to the memory partition
    235          *
    236          *              pname     is a pointer to an ASCII string that contains the name of the memory partition.
    237          *
    238          *              perr      is a pointer to an error code that can contain one of the following values:
    239          *
    240          *                        OS_ERR_NONE                if the name was copied to 'pname'
    241          *                        OS_ERR_MEM_INVALID_PMEM    if you passed a NULL pointer for 'pmem'
    242          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
    243          *                        OS_ERR_MEM_NAME_TOO_LONG   if the name doesn't fit in the storage area
    244          *                        OS_ERR_NAME_SET_ISR        if you called this function from an ISR
    245          *
    246          * Returns    : None
    247          *********************************************************************************************************
    248          */
    249          
    250          #if OS_MEM_NAME_SIZE > 1
    251          void  OSMemNameSet (OS_MEM *pmem, INT8U *pname, INT8U *perr)
    252          {
    253              INT8U      len;
    254          #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    255              OS_CPU_SR  cpu_sr = 0;
    256          #endif
    257          
    258          
    259          
    260          #if OS_ARG_CHK_EN > 0
    261              if (perr == (INT8U *)0) {                    /* Validate 'perr'                                    */
    262                  return;
    263              }
    264              if (pmem == (OS_MEM *)0) {                   /* Is 'pmem' a NULL pointer?                          */
    265                  *perr = OS_ERR_MEM_INVALID_PMEM;
    266                  return;
    267              }
    268              if (pname == (INT8U *)0) {                   /* Is 'pname' a NULL pointer?                         */
    269                  *perr = OS_ERR_PNAME_NULL;
    270                  return;
    271              }
    272          #endif
    273              if (OSIntNesting > 0) {                      /* See if trying to call from an ISR                  */
    274                  *perr = OS_ERR_NAME_SET_ISR;
    275                  return;
    276              }
    277              OS_ENTER_CRITICAL();
    278              len = OS_StrLen(pname);                      /* Can we fit the string in the storage area?         */
    279              if (len > (OS_MEM_NAME_SIZE - 1)) {          /* No                                                 */
    280                  OS_EXIT_CRITICAL();

⌨️ 快捷键说明

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