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

📄 os_mem.src

📁 uCOS-II_2.52在51上的移植程序
💻 SRC
字号:
; .\OS_MEM.SRC generated from: OS_MEM.C
; COMPILER INVOKED BY:
;        C:\Keil\C51\BIN\C51.EXE OS_MEM.C LARGE BROWSE ORDER NOAREGS DEBUG OBJECTEXTEND SRC(.\OS_MEM.SRC)

$NOMOD51

NAME	OS_MEM

P0	DATA	080H
P1	DATA	090H
P2	DATA	0A0H
P3	DATA	0B0H
PSW	DATA	0D0H
ACC	DATA	0E0H
B	DATA	0F0H
SP	DATA	081H
DPL	DATA	082H
DPH	DATA	083H
PCON	DATA	087H
TCON	DATA	088H
TMOD	DATA	089H
TL0	DATA	08AH
TL1	DATA	08BH
TH0	DATA	08CH
TH1	DATA	08DH
IE	DATA	0A8H
IP	DATA	0B8H
SCON	DATA	098H
SBUF	DATA	099H
CY	BIT	0D0H.7
AC	BIT	0D0H.6
F0	BIT	0D0H.5
RS1	BIT	0D0H.4
RS0	BIT	0D0H.3
OV	BIT	0D0H.2
P	BIT	0D0H.0
TF1	BIT	088H.7
TR1	BIT	088H.6
TF0	BIT	088H.5
TR0	BIT	088H.4
IE1	BIT	088H.3
IT1	BIT	088H.2
IE0	BIT	088H.1
IT0	BIT	088H.0
EA	BIT	0A8H.7
ES	BIT	0A8H.4
ET1	BIT	0A8H.3
EX1	BIT	0A8H.2
ET0	BIT	0A8H.1
EX0	BIT	0A8H.0
PS	BIT	0B8H.4
PT1	BIT	0B8H.3
PX1	BIT	0B8H.2
PT0	BIT	0B8H.1
PX0	BIT	0B8H.0
RD	BIT	0B0H.7
WR	BIT	0B0H.6
T1	BIT	0B0H.5
T0	BIT	0B0H.4
INT1	BIT	0B0H.3
INT0	BIT	0B0H.2
TXD	BIT	0B0H.1
RXD	BIT	0B0H.0
SM0	BIT	098H.7
SM1	BIT	098H.6
SM2	BIT	098H.5
REN	BIT	098H.4
TB8	BIT	098H.3
RB8	BIT	098H.2
TI	BIT	098H.1
RI	BIT	098H.0
; /*
; *********************************************************************************************************
; *                                                uC/OS-II
; *                                          The Real-Time Kernel
; *                                            MEMORY MANAGEMENT
; *
; *                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
; *                                           All Rights Reserved
; *
; * File : OS_MEM.C
; * By   : Jean J. Labrosse
; *********************************************************************************************************
; */
; 
; #ifndef  OS_MASTER_FILE
; #include "includes.h"
; #endif
; 
; #if (OS_MEM_EN > 0) && (OS_MAX_MEM_PART > 0)
; /*
; *********************************************************************************************************
; *                                        CREATE A MEMORY PARTITION
; *
; * Description : Create a fixed-sized memory partition that will be managed by uC/OS-II.
; *
; * Arguments   : addr     is the starting address of the memory partition
; *
; *               nblks    is the number of memory blocks to create from the partition.
; *
; *               blksize  is the size (in bytes) of each block in the memory partition.
; *
; *               err      is a pointer to a variable containing an error message which will be set by
; *                        this function to either:
; *
; *                        OS_NO_ERR            if the memory partition has been created correctly.
; *                        OS_MEM_INVALID_ADDR  you are specifying an invalid address for the memory 
; *                                             storage of the partition.
; *                        OS_MEM_INVALID_PART  no free partitions available
; *                        OS_MEM_INVALID_BLKS  user specified an invalid number of blocks (must be >= 2)
; *                        OS_MEM_INVALID_SIZE  user specified an invalid block size
; *                                             (must be greater than the size of a pointer)
; * Returns    : != (OS_MEM *)0  is the partition was created
; *              == (OS_MEM *)0  if the partition was not created because of invalid arguments or, no
; *                              free partition is available.
; *********************************************************************************************************
; */
; 
; OS_MEM  *OSMemCreate (void *addr, INT32U nblks, INT32U blksize, INT8U *err)
; {
;    
;     OS_MEM    *pmem;
;     INT8U     *pblk;
;     void     **plink;
;     INT32U     i;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (addr == (void *)0) {                          /* Must pass a valid address for the memory part. */
;         *err = OS_MEM_INVALID_ADDR;
;         return ((OS_MEM *)0);
;     }
;     if (nblks < 2) {                                  /* Must have at least 2 blocks per partition      */
;         *err = OS_MEM_INVALID_BLKS;
;         return ((OS_MEM *)0);
;     }
;     if (blksize < sizeof(void *)) {                   /* Must contain space for at least a pointer      */
;         *err = OS_MEM_INVALID_SIZE;
;         return ((OS_MEM *)0);
;     }
; #endif
;     OS_ENTER_CRITICAL();
;     pmem = OSMemFreeList;                             /* Get next free memory partition                */
;     if (OSMemFreeList != (OS_MEM *)0) {               /* See if pool of free partitions was empty      */
;         OSMemFreeList = (OS_MEM *)OSMemFreeList->OSMemFreeList;
;     }
;     OS_EXIT_CRITICAL();
;     if (pmem == (OS_MEM *)0) {                        /* See if we have a memory partition             */
;         *err = OS_MEM_INVALID_PART;
;         return ((OS_MEM *)0);
;     }
;     plink = (void **)addr;                            /* Create linked list of free memory blocks      */
;     pblk  = (INT8U *)addr + blksize;
;     for (i = 0; i < (nblks - 1); i++) {
;         *plink = (void *)pblk;
;         plink  = (void **)pblk;
;         pblk   = pblk + blksize;
;     }
;     *plink              = (void *)0;                  /* Last memory block points to NULL              */
;     pmem->OSMemAddr     = addr;                       /* Store start address of memory partition       */
;     pmem->OSMemFreeList = addr;                       /* Initialize pointer to pool of free blocks     */
;     pmem->OSMemNFree    = nblks;                      /* Store number of free blocks in MCB            */
;     pmem->OSMemNBlks    = nblks;
;     pmem->OSMemBlkSize  = blksize;                    /* Store block size of each memory blocks        */
;     *err                = OS_NO_ERR;
;     return (pmem);
; }
; /*$PAGE*/
; /*
; *********************************************************************************************************
; *                                          GET A MEMORY BLOCK
; *
; * Description : Get a memory block from a partition
; *
; * Arguments   : pmem    is a pointer to the memory partition control block
; *
; *               err     is a pointer to a variable containing an error message which will be set by this
; *                       function to either:
; *
; *                       OS_NO_ERR           if the memory partition has been created correctly.
; *                       OS_MEM_NO_FREE_BLKS if there are no more free memory blocks to allocate to caller
; *                       OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
; *
; * Returns     : A pointer to a memory block if no error is detected
; *               A pointer to NULL if an error is detected
; *********************************************************************************************************
; */
; 
; void  *OSMemGet (OS_MEM *pmem, INT8U *err)
; {
;   
;     void      *pblk;
; 
; 
; #if OS_ARG_CHK_EN > 0
;     if (pmem == (OS_MEM *)0) {                        /* Must point to a valid memory partition         */
;         *err = OS_MEM_INVALID_PMEM;
;         return ((OS_MEM *)0);
;     }
; #endif
;     OS_ENTER_CRITICAL();
;     if (pmem->OSMemNFree > 0) {                       /* See if there are any free memory blocks       */
;         pblk                = pmem->OSMemFreeList;    /* Yes, point to next free memory block          */
;         pmem->OSMemFreeList = *(void **)pblk;         /*      Adjust pointer to new free list          */
;         pmem->OSMemNFree--;                           /*      One less memory block in this partition  */
;         OS_EXIT_CRITICAL();
;         *err = OS_NO_ERR;                             /*      No error                                 */
;         return (pblk);                                /*      Return memory block to caller            */
;     }
;     OS_EXIT_CRITICAL();
;     *err = OS_MEM_NO_FREE_BLKS;                       /* No,  Notify caller of empty memory partition  */
;     return ((void *)0);                               /*      Return NULL pointer to caller            */
; }
; /*$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.
; *
; * Returns     : OS_NO_ERR            if the memory block was inserted into the partition
; *               OS_MEM_FULL          if you are returning a memory block to an already FULL memory 
; *                                    partition (You freed more blocks than you allocated!)
; *               OS_MEM_INVALID_PMEM  if you passed a NULL pointer for 'pmem'
; *               OS_MEM_INVALID_PBLK  if you passed a NULL pointer for the block to release.
; *********************************************************************************************************
; */
; 
; INT8U  OSMemPut (OS_MEM  *pmem, void *pblk)
; {
;   
;     
;     
; #if OS_ARG_CHK_EN > 0
;     if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
;         return (OS_MEM_INVALID_PMEM);
;     }
;     if (pblk == (void *)0) {                     /* Must release a valid block                         */
;         return (OS_MEM_INVALID_PBLK);
;     }
; #endif
;     OS_ENTER_CRITICAL();
;     if (pmem->OSMemNFree >= pmem->OSMemNBlks) {  /* Make sure all blocks not already returned          */
;         OS_EXIT_CRITICAL();
;         return (OS_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_NO_ERR);                          /* 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
; *
; *               pdata   is a pointer to a structure that will contain information about the memory
; *                       partition.
; *
; * Returns     : OS_NO_ERR            If no errors were found.
; *               OS_MEM_INVALID_PMEM  if you passed a NULL pointer for 'pmem'
; *               OS_MEM_INVALID_PDATA if you passed a NULL pointer for the block to release.
; *********************************************************************************************************
; */
; 
; #if OS_MEM_QUERY_EN > 0
; INT8U  OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *ppdata)
; {
; 
;     
;     
; #if OS_ARG_CHK_EN > 0
;     if (pmem == (OS_MEM *)0) {                   /* Must point to a valid memory partition             */
;         return (OS_MEM_INVALID_PMEM);
;     }
;     if (ppdata == (OS_MEM_DATA *)0) {             /* Must release a valid storage area for the data     */
;         return (OS_MEM_INVALID_PDATA);
;     }
; #endif
;     OS_ENTER_CRITICAL();
;     ppdata->OSAddr     = pmem->OSMemAddr;
;     ppdata->OSFreeList = pmem->OSMemFreeList;
;     ppdata->OSBlkSize  = pmem->OSMemBlkSize;
;     ppdata->OSNBlks    = pmem->OSMemNBlks;
;     ppdata->OSNFree    = pmem->OSMemNFree;
;     OS_EXIT_CRITICAL();
;     ppdata->OSNUsed    = ppdata->OSNBlks - ppdata->OSNFree;
;     return (OS_NO_ERR);
; }
; #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)
; {
; #if OS_MAX_MEM_PART == 1
;     OSMemFreeList                = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list          */
;     OSMemFreeList->OSMemFreeList = (void *)0;              /* Initialize last node                     */
;     OSMemFreeList->OSMemAddr     = (void *)0;              /* Store start address of memory partition  */
;     OSMemFreeList->OSMemNFree    = 0;                      /* No free blocks                           */
;     OSMemFreeList->OSMemNBlks    = 0;                      /* No blocks                                */
;     OSMemFreeList->OSMemBlkSize  = 0;                      /* Zero size                                */
; #endif
; 
; #if OS_MAX_MEM_PART >= 2
;     OS_MEM  *pmem;
;     INT16U   i;
; 
; 
;     pmem = (OS_MEM *)&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                 */
;         pmem->OSMemAddr     = (void *)0;              /* Store start address of memory partition       */
;         pmem->OSMemNFree    = 0;                      /* No free blocks                                */
;         pmem->OSMemNBlks    = 0;                      /* No blocks                                     */
;         pmem->OSMemBlkSize  = 0;                      /* Zero size                                     */
;         pmem++;
;     }
;     pmem->OSMemFreeList = (void *)0;                  /* Initialize last node                          */
;     pmem->OSMemAddr     = (void *)0;                  /* Store start address of memory partition       */
;     pmem->OSMemNFree    = 0;                          /* No free blocks                                */
;     pmem->OSMemNBlks    = 0;                          /* No blocks                                     */
;     pmem->OSMemBlkSize  = 0;                          /* Zero size                                     */
; 
;     OSMemFreeList       = (OS_MEM *)&OSMemTbl[0];     /* Point to beginning of free list               */
; #endif
; }
; #endif                                           /* OS_MEM_EN                                          */
; *** sync lost ***
; *** sync lost ***
; *** sync lost ***
	END

⌨️ 快捷键说明

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