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

📄 os_mem.lst

📁 UCOSII2.85针对8051单片机的移植版本
💻 LST
📖 第 1 页 / 共 2 页
字号:
                  len   = OS_StrCopy(pname, pmem->OSMemName);  /* Copy name from OS_MEM                              */
                  OS_EXIT_CRITICAL();
                  *perr = OS_ERR_NONE;
                  return (len);
              }
              #endif
              
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                 ASSIGN A NAME TO A MEMORY PARTITION
              *
              * Description: This function assigns a name to a memory partition.
              *
              * Arguments  : pmem      is a pointer to the memory partition
              *
              *              pname     is a pointer to an ASCII string that contains the name of the memory partition.
              *
C51 COMPILER V7.50   OS_MEM                                                                12/14/2007 08:25:35 PAGE 5   

              *              perr      is a pointer to an error code that can contain one of the following values:
              *
              *                        OS_ERR_NONE                if the name was copied to 'pname'
              *                        OS_ERR_MEM_INVALID_PMEM    if you passed a NULL pointer for 'pmem'
              *                        OS_ERR_PNAME_NULL          You passed a NULL pointer for 'pname'
              *                        OS_ERR_MEM_NAME_TOO_LONG   if the name doesn't fit in the storage area
              *                        OS_ERR_NAME_SET_ISR        if you called this function from an ISR
              *
              * Returns    : None
              *********************************************************************************************************
              */
              
              #if OS_MEM_NAME_SIZE > 1
              void  OSMemNameSet (OS_MEM *pmem, INT8U *pname, INT8U *perr) reentrant
              {
                  INT8U      len;
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
              
              
              #if OS_ARG_CHK_EN > 0
                  if (perr == (INT8U *)0) {                    /* Validate 'perr'                                    */
                      return;
                  }
                  if (pmem == (OS_MEM *)0) {                   /* Is 'pmem' a NULL pointer?                          */
                      *perr = OS_ERR_MEM_INVALID_PMEM;
                      return;
                  }
                  if (pname == (INT8U *)0) {                   /* Is 'pname' a NULL pointer?                         */
                      *perr = OS_ERR_PNAME_NULL;
                      return;
                  }
              #endif
                  if (OSIntNesting > 0) {                      /* See if trying to call from an ISR                  */
                      *perr = OS_ERR_NAME_SET_ISR;
                      return;
                  }
                  OS_ENTER_CRITICAL();
                  len = OS_StrLen(pname);                      /* Can we fit the string in the storage area?         */
                  if (len > (OS_MEM_NAME_SIZE - 1)) {          /* No                                                 */
                      OS_EXIT_CRITICAL();
                      *perr = OS_ERR_MEM_NAME_TOO_LONG;
                      return;
                  }
                  (void)OS_StrCopy(pmem->OSMemName, pname);    /* Yes, copy name to the memory partition header      */
                  OS_EXIT_CRITICAL();
                  *perr = OS_ERR_NONE;
              }
              #endif
              
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                         RELEASE A MEMORY BLOCK
              *
              * Description : Returns a memory block to a partition
              *
              * Arguments   : pmem    is a pointer to the memory partition control block
              *
              *               pblk    is a pointer to the memory block being released.
C51 COMPILER V7.50   OS_MEM                                                                12/14/2007 08:25:35 PAGE 6   

              *
              * Returns     : OS_ERR_NONE              if the memory block was inserted into the partition
              *               OS_ERR_MEM_FULL          if you are returning a memory block to an already FULL memory
              *                                        partition (You freed more blocks than you allocated!)
              *               OS_ERR_MEM_INVALID_PMEM  if you passed a NULL pointer for 'pmem'
              *               OS_ERR_MEM_INVALID_PBLK  if you passed a NULL pointer for the block to release.
              *********************************************************************************************************
              */
              
              INT8U  OSMemPut (OS_MEM *pmem, void *pblk) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
              
              
              #if OS_ARG_CHK_EN > 0
                  if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
                      return (OS_ERR_MEM_INVALID_PMEM);
                  }
                  if (pblk == (void *)0) {                     /* Must release a valid block                         */
                      return (OS_ERR_MEM_INVALID_PBLK);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  if (pmem->OSMemNFree >= pmem->OSMemNBlks) {  /* Make sure all blocks not already returned          */
                      OS_EXIT_CRITICAL();
                      return (OS_ERR_MEM_FULL);
                  }
                  *(void **)pblk      = pmem->OSMemFreeList;   /* Insert released block into free block list         */
                  pmem->OSMemFreeList = pblk;
                  pmem->OSMemNFree++;                          /* One more memory block in this partition            */
                  OS_EXIT_CRITICAL();
                  return (OS_ERR_NONE);                        /* Notify caller that memory block was released       */
              }
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                          QUERY MEMORY PARTITION
              *
              * Description : This function is used to determine the number of free memory blocks and the number of
              *               used memory blocks from a memory partition.
              *
              * Arguments   : pmem        is a pointer to the memory partition control block
              *
              *               p_mem_data  is a pointer to a structure that will contain information about the memory
              *                           partition.
              *
              * Returns     : OS_ERR_NONE               if no errors were found.
              *               OS_ERR_MEM_INVALID_PMEM   if you passed a NULL pointer for 'pmem'
              *               OS_ERR_MEM_INVALID_PDATA  if you passed a NULL pointer to the data recipient.
              *********************************************************************************************************
              */
              
              #if OS_MEM_QUERY_EN > 0
              INT8U  OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *p_mem_data) reentrant
              {
              #if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
                  OS_CPU_SR  cpu_sr = 0;
              #endif
              
C51 COMPILER V7.50   OS_MEM                                                                12/14/2007 08:25:35 PAGE 7   

              
              
              #if OS_ARG_CHK_EN > 0
                  if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
                      return (OS_ERR_MEM_INVALID_PMEM);
                  }
                  if (p_mem_data == (OS_MEM_DATA *)0) {        /* Must release a valid storage area for the data     */
                      return (OS_ERR_MEM_INVALID_PDATA);
                  }
              #endif
                  OS_ENTER_CRITICAL();
                  p_mem_data->OSAddr     = pmem->OSMemAddr;
                  p_mem_data->OSFreeList = pmem->OSMemFreeList;
                  p_mem_data->OSBlkSize  = pmem->OSMemBlkSize;
                  p_mem_data->OSNBlks    = pmem->OSMemNBlks;
                  p_mem_data->OSNFree    = pmem->OSMemNFree;
                  OS_EXIT_CRITICAL();
                  p_mem_data->OSNUsed    = p_mem_data->OSNBlks - p_mem_data->OSNFree;
                  return (OS_ERR_NONE);
              }
              #endif                                           /* OS_MEM_QUERY_EN                                    */
              /*$PAGE*/
              /*
              *********************************************************************************************************
              *                                    INITIALIZE MEMORY PARTITION MANAGER
              *
              * Description : This function is called by uC/OS-II to initialize the memory partition manager.  Your
              *               application MUST NOT call this function.
              *
              * Arguments   : none
              *
              * Returns     : none
              *
              * Note(s)    : This function is INTERNAL to uC/OS-II and your application should not call it.
              *********************************************************************************************************
              */
              
              void  OS_MemInit (void) reentrant
              {
              #if OS_MAX_MEM_PART == 1
                  OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl));   /* Clear the memory partition table          */
                  OSMemFreeList               = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list           */
              #if OS_MEM_NAME_SIZE > 1
                  OSMemFreeList->OSMemName[0] = '?';                    /* Unknown name                              */
                  OSMemFreeList->OSMemName[1] = OS_ASCII_NUL;
              #endif
              #endif
              
              #if OS_MAX_MEM_PART >= 2
                  OS_MEM  *pmem;
                  INT16U   i;
              
              
                  OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl));   /* Clear the memory partition table          */
                  pmem = &OSMemTbl[0];                                  /* Point to memory control block (MCB)       */
                  for (i = 0; i < (OS_MAX_MEM_PART - 1); i++) {         /* Init. list of free memory partitions      */
                      pmem->OSMemFreeList = (void *)&OSMemTbl[i+1];     /* Chain list of free partitions             */
              #if OS_MEM_NAME_SIZE > 1
                      pmem->OSMemName[0]  = '?';                        /* Unknown name                              */
                      pmem->OSMemName[1]  = OS_ASCII_NUL;
              #endif
                      pmem++;
C51 COMPILER V7.50   OS_MEM                                                                12/14/2007 08:25:35 PAGE 8   

                  }
                  pmem->OSMemFreeList = (void *)0;                      /* Initialize last node                      */
              #if OS_MEM_NAME_SIZE > 1
                  pmem->OSMemName[0]  = '?';                            /* Unknown name                              */
                  pmem->OSMemName[1]  = OS_ASCII_NUL;
              #endif
              
                  OSMemFreeList       = &OSMemTbl[0];                   /* Point to beginning of free list           */
              #endif
              }
              #endif                                                    /* OS_MEM_EN                                 */


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   ----    ----
   CONSTANT SIZE    =   ----    ----
   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 + -