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

📄 os_mem.lst

📁 uCOS 嵌入式操作系统的改进版,增加了网络通讯.
💻 LST
📖 第 1 页 / 共 2 页
字号:
 199          /*
 200          *********************************************************************************************************
 201          *                                 ASSIGN A NAME TO A MEMORY PARTITION
 202          *
 203          * Description: This function assigns a name to a memory partition.
 204          *
 205          * Arguments  : pmem      is a pointer to the memory partition
 206          *
 207          *              pname     is a pointer to an ASCII string that contains the name of the memory partition.
 208          *
 209          *              err       is a pointer to an error code that can contain one of the following values:
 210          *
 211          *                        OS_NO_ERR                  if the name was copied to 'pname'
 212          *                        OS_MEM_INVALID_PMEM        if you passed a NULL pointer for 'pmem'
 213          *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
 214          *                                                OS_MEM_NAME_TOO_LONG       if the name doesn't fit in the storage area
 215          *
 216          * Returns    : None
 217          *********************************************************************************************************
 218          */
 219          
 220          #if OS_MEM_NAME_SIZE > 0
 221          void  OSMemNameSet (OS_MEM *pmem, char *pname, INT8U *err) reentrant //using 0
 222          {
 223   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 224   1          OS_CPU_SR  cpu_sr;
 225   1      #endif
 226   1          INT8U      len;
 227   1      
 228   1      
 229   1          OS_ENTER_CRITICAL();
 230   1      #if OS_ARG_CHK_EN > 0
 231   1          if (pmem == (OS_MEM *)0) {                   /* Is 'pmem' a NULL pointer?                          */
 232   2              OS_EXIT_CRITICAL();                      /* Yes                                                */
 233   2              *err = OS_MEM_INVALID_PMEM;
 234   2          }
 235   1          if (pname == (char *)0) {                    /* Is 'pname' a NULL pointer?                         */
 236   2              OS_EXIT_CRITICAL();                      /* Yes                                                */
 237   2              *err = OS_ERR_PNAME_NULL;
 238   2              return;
 239   2          }
C51 COMPILER V7.06   OS_MEM                                                                07/18/2003 11:06:00 PAGE 5   

 240   1      #endif
 241   1          len = strlen(pname);                         /* Can we fit the string in the storage area?         */
 242   1      //    if (len > (OS_EVENT_NAME_SIZE - 1)) {      //#Lin@20030714  /* No                                   
             -              */
 243   1      if (len > (OS_MEM_NAME_SIZE - 1)) {
 244   2              OS_EXIT_CRITICAL();
 245   2              *err = OS_MEM_NAME_TOO_LONG;
 246   2              return;
 247   2          } 
 248   1          (void)strcpy(pmem->OSMemName, pname);        /* Yes, copy name to the memory partition header      */
 249   1          OS_EXIT_CRITICAL();
 250   1          *err = OS_NO_ERR;
 251   1      }
 252          #endif
 253          
 254          /*$PAGE*/
 255          /*
 256          *********************************************************************************************************
 257          *                                         RELEASE A MEMORY BLOCK
 258          *
 259          * Description : Returns a memory block to a partition
 260          *
 261          * Arguments   : pmem    is a pointer to the memory partition control block
 262          *
 263          *               pblk    is a pointer to the memory block being released.
 264          *
 265          * Returns     : OS_NO_ERR            if the memory block was inserted into the partition
 266          *               OS_MEM_FULL          if you are returning a memory block to an already FULL memory 
 267          *                                    partition (You freed more blocks than you allocated!)
 268          *               OS_MEM_INVALID_PMEM  if you passed a NULL pointer for 'pmem'
 269          *               OS_MEM_INVALID_PBLK  if you passed a NULL pointer for the block to release.
 270          *********************************************************************************************************
 271          */
 272          
 273          INT8U  OSMemPut (OS_MEM *pmem, void *pblk) reentrant //using 0
 274          {
 275   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 276   1          OS_CPU_SR  cpu_sr;
 277   1      #endif    
 278   1          
 279   1          
 280   1      #if OS_ARG_CHK_EN > 0
 281   1          if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
 282   2              return (OS_MEM_INVALID_PMEM);
 283   2          }
 284   1          if (pblk == (void *)0) {                     /* Must release a valid block                         */
 285   2              return (OS_MEM_INVALID_PBLK);
 286   2          }
 287   1      #endif
 288   1          OS_ENTER_CRITICAL();
 289   1          if (pmem->OSMemNFree >= pmem->OSMemNBlks) {  /* Make sure all blocks not already returned          */
 290   2              OS_EXIT_CRITICAL();
 291   2              return (OS_MEM_FULL);
 292   2          }
 293   1          *(void **)pblk      = pmem->OSMemFreeList;   /* Insert released block into free block list         */
 294   1          pmem->OSMemFreeList = pblk;
 295   1          pmem->OSMemNFree++;                          /* One more memory block in this partition            */
 296   1          OS_EXIT_CRITICAL();
 297   1          return (OS_NO_ERR);                          /* Notify caller that memory block was released       */
 298   1      }
 299          /*$PAGE*/
 300          /*
C51 COMPILER V7.06   OS_MEM                                                                07/18/2003 11:06:00 PAGE 6   

 301          *********************************************************************************************************
 302          *                                          QUERY MEMORY PARTITION
 303          *
 304          * Description : This function is used to determine the number of free memory blocks and the number of
 305          *               used memory blocks from a memory partition.
 306          *
 307          * Arguments   : pmem    is a pointer to the memory partition control block
 308          *
 309          *               pdata   is a pointer to a structure that will contain information about the memory
 310          *                       partition.
 311          *
 312          * Returns     : OS_NO_ERR            If no errors were found.
 313          *               OS_MEM_INVALID_PMEM  if you passed a NULL pointer for 'pmem'
 314          *               OS_MEM_INVALID_PDATA if you passed a NULL pointer for the block to release.
 315          *********************************************************************************************************
 316          */
 317          
 318          #if OS_MEM_QUERY_EN > 0
 319          INT8U  OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *pndata) reentrant //using 0
 320          {
 321   1      #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
 322   1          OS_CPU_SR  cpu_sr;
 323   1      #endif    
 324   1          
 325   1          
 326   1      #if OS_ARG_CHK_EN > 0
 327   1          if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
 328   2              return (OS_MEM_INVALID_PMEM);
 329   2          }
 330   1          if (pndata == (OS_MEM_DATA *)0) {             /* Must release a valid storage area for the data     */
 331   2              return (OS_MEM_INVALID_PDATA);
 332   2          }
 333   1      #endif
 334   1          OS_ENTER_CRITICAL();
 335   1          pndata->OSAddr     = pmem->OSMemAddr;
 336   1          pndata->OSFreeList = pmem->OSMemFreeList;
 337   1          pndata->OSBlkSize  = pmem->OSMemBlkSize;
 338   1          pndata->OSNBlks    = pmem->OSMemNBlks;
 339   1          pndata->OSNFree    = pmem->OSMemNFree;
 340   1          OS_EXIT_CRITICAL();
 341   1          pndata->OSNUsed    = pndata->OSNBlks - pndata->OSNFree;
 342   1          return (OS_NO_ERR);
 343   1      }
 344          #endif                                           /* OS_MEM_QUERY_EN                                    */
 345          /*$PAGE*/
 346          /*
 347          *********************************************************************************************************
 348          *                                    INITIALIZE MEMORY PARTITION MANAGER
 349          *
 350          * Description : This function is called by uC/OS-II to initialize the memory partition manager.  Your
 351          *               application MUST NOT call this function.
 352          *
 353          * Arguments   : none
 354          *
 355          * Returns     : none
 356          *
 357          * Note(s)    : This function is INTERNAL to uC/OS-II and your application should not call it.
 358          *********************************************************************************************************
 359          */
 360          
 361          void  OS_MemInit (void) reentrant //using 0
 362          {
C51 COMPILER V7.06   OS_MEM                                                                07/18/2003 11:06:00 PAGE 7   

 363   1      #if OS_MAX_MEM_PART == 1
                  OSMemFreeList = (OS_MEM *)&OSMemTbl[0];           /* Point to beginning of free list               */
                  (void)memset(&OSMemTbl[0], 0, sizeof(OSMemTbl));  /* Clear the memory partition table              */
              #endif
 367   1      
 368   1      #if OS_MAX_MEM_PART >= 2
 369   1          OS_MEM  *pmem;
 370   1          INT16U   i;
 371   1      
 372   1      
 373   1          (void)memset(&OSMemTbl[0], 0, sizeof(OSMemTbl));  /* Clear the memory partition table              */
 374   1          pmem = (OS_MEM *)&OSMemTbl[0];                    /* Point to memory control block (MCB)           */
 375   1          for (i = 0; i < (OS_MAX_MEM_PART - 1); i++) {     /* Init. list of free memory partitions          */
 376   2              pmem->OSMemFreeList = (void *)&OSMemTbl[i+1]; /* Chain list of free partitions                 */
 377   2      #if OS_MEM_NAME_SIZE > 0
 378   2              (void)strcpy(pmem->OSMemName, "?");           /* Unknown name                                  */
 379   2      #endif
 380   2              pmem++;
 381   2          }
 382   1          pmem->OSMemFreeList = (void *)0;                  /* Initialize last node                          */
 383   1      #if OS_MEM_NAME_SIZE > 0
 384   1          (void)strcpy(pmem->OSMemName, "?");               /* Unknown name                                  */
 385   1      #endif
 386   1      
 387   1          OSMemFreeList       = (OS_MEM *)&OSMemTbl[0];     /* Point to beginning of free list               */
 388   1      #endif
 389   1      }
 390          #endif                                                /* OS_MEM_EN                                     */


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   2525    ----
   CONSTANT SIZE    =      2    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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