📄 os_mem.lst
字号:
149 /*$PAGE*/
150 /*
151 *********************************************************************************************************
152 * RELEASE A MEMORY BLOCK
153 *
154 * Description : Returns a memory block to a partition
155 *
156 * Arguments : pmem is a pointer to the memory partition control block
157 *
158 * pblk is a pointer to the memory block being released.
159 *
160 * Returns : OS_NO_ERR if the memory block was inserted into the partition
161 * OS_MEM_FULL if you are returning a memory block to an already FULL memory
162 * partition (You freed more blocks than you allocated!)
163 * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
164 * OS_MEM_INVALID_PBLK if you passed a NULL pointer for the block to release.
165 *********************************************************************************************************
166 */
167
168 INT8U OSMemPut (OS_MEM *pmem, void *pblk) reentrant
169 {
170 1 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
173 1
174 1
175 1 #if OS_ARG_CHK_EN > 0
176 1 if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partition */
177 2 return (OS_MEM_INVALID_PMEM);
178 2 }
C51 COMPILER V7.06 OS_MEM 03/05/2008 20:23:54 PAGE 4
179 1 if (pblk == (void *)0) { /* Must release a valid block */
180 2 return (OS_MEM_INVALID_PBLK);
181 2 }
182 1 #endif
183 1 OS_ENTER_CRITICAL();
184 1 if (pmem->OSMemNFree >= pmem->OSMemNBlks) { /* Make sure all blocks not already returned */
185 2 OS_EXIT_CRITICAL();
186 2 return (OS_MEM_FULL);
187 2 }
188 1 *(void **)pblk = pmem->OSMemFreeList; /* Insert released block into free block list */
189 1 pmem->OSMemFreeList = pblk;
190 1 pmem->OSMemNFree++; /* One more memory block in this partition */
191 1 OS_EXIT_CRITICAL();
192 1 return (OS_NO_ERR); /* Notify caller that memory block was released */
193 1 }
194 /*$PAGE*/
195 /*
196 *********************************************************************************************************
197 * QUERY MEMORY PARTITION
198 *
199 * Description : This function is used to determine the number of free memory blocks and the number of
200 * used memory blocks from a memory partition.
201 *
202 * Arguments : pmem is a pointer to the memory partition control block
203 *
204 * ppdata is a pointer to a structure that will contain information about the memory
205 * partition.
206 *
207 * Returns : OS_NO_ERR If no errors were found.
208 * OS_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
209 * OS_MEM_INVALID_PDATA if you passed a NULL pointer for the block to release.
210 *********************************************************************************************************
211 */
212
213 #if OS_MEM_QUERY_EN > 0
INT8U OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *ppdata) reentrant
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
#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 */
240 /*$PAGE*/
C51 COMPILER V7.06 OS_MEM 03/05/2008 20:23:54 PAGE 5
241 /*
242 *********************************************************************************************************
243 * INITIALIZE MEMORY PARTITION MANAGER
244 *
245 * Description : This function is called by uC/OS-II to initialize the memory partition manager. Your
246 * application MUST NOT call this function.
247 *
248 * Arguments : none
249 *
250 * Returns : none
251 *
252 * Note(s) : This function is INTERNAL to uC/OS-II and your application should not call it.
253 *********************************************************************************************************
254 */
255
256 void OS_MemInit (void) reentrant
257 {
258 1 #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
266 1
267 1 #if OS_MAX_MEM_PART >= 2
268 1 OS_MEM *pmem;
269 1 INT16U i;
270 1
271 1
272 1 pmem = (OS_MEM *)&OSMemTbl[0]; /* Point to memory control block (MCB) */
273 1 for (i = 0; i < (OS_MAX_MEM_PART - 1); i++) { /* Init. list of free memory partitions */
274 2 pmem->OSMemFreeList = (void *)&OSMemTbl[i+1]; /* Chain list of free partitions */
275 2 pmem->OSMemAddr = (void *)0; /* Store start address of memory partition */
276 2 pmem->OSMemNFree = 0; /* No free blocks */
277 2 pmem->OSMemNBlks = 0; /* No blocks */
278 2 pmem->OSMemBlkSize = 0; /* Zero size */
279 2 pmem++;
280 2 }
281 1 pmem->OSMemFreeList = (void *)0; /* Initialize last node */
282 1 pmem->OSMemAddr = (void *)0; /* Store start address of memory partition */
283 1 pmem->OSMemNFree = 0; /* No free blocks */
284 1 pmem->OSMemNBlks = 0; /* No blocks */
285 1 pmem->OSMemBlkSize = 0; /* Zero size */
286 1
287 1 OSMemFreeList = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list */
288 1 #endif
289 1 }
290 #endif /* OS_MEM_EN */
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1595 ----
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 + -