📄 os_mem.lst
字号:
281 *perr = OS_ERR_MEM_NAME_TOO_LONG;
282 return;
283 }
284 (void)OS_StrCopy(pmem->OSMemName, pname); /* Yes, copy name to the memory partition header */
285 OS_EXIT_CRITICAL();
286 *perr = OS_ERR_NONE;
287 }
288 #endif
289
290 /*$PAGE*/
291 /*
292 *********************************************************************************************************
293 * RELEASE A MEMORY BLOCK
294 *
295 * Description : Returns a memory block to a partition
296 *
297 * Arguments : pmem is a pointer to the memory partition control block
298 *
299 * pblk is a pointer to the memory block being released.
300 *
301 * Returns : OS_ERR_NONE if the memory block was inserted into the partition
302 * OS_ERR_MEM_FULL if you are returning a memory block to an already FULL memory
303 * partition (You freed more blocks than you allocated!)
304 * OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
305 * OS_ERR_MEM_INVALID_PBLK if you passed a NULL pointer for the block to release.
306 *********************************************************************************************************
307 */
308
309 INT8U OSMemPut (OS_MEM *pmem, void *pblk)
310 {
311 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
312 OS_CPU_SR cpu_sr = 0;
313 #endif
314
315
316
317 #if OS_ARG_CHK_EN > 0
318 if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partition */
319 return (OS_ERR_MEM_INVALID_PMEM);
320 }
321 if (pblk == (void *)0) { /* Must release a valid block */
322 return (OS_ERR_MEM_INVALID_PBLK);
323 }
324 #endif
325 OS_ENTER_CRITICAL();
326 if (pmem->OSMemNFree >= pmem->OSMemNBlks) { /* Make sure all blocks not already returned */
327 OS_EXIT_CRITICAL();
328 return (OS_ERR_MEM_FULL);
329 }
330 *(void **)pblk = pmem->OSMemFreeList; /* Insert released block into free block list */
331 pmem->OSMemFreeList = pblk;
332 pmem->OSMemNFree++; /* One more memory block in this partition */
333 OS_EXIT_CRITICAL();
334 return (OS_ERR_NONE); /* Notify caller that memory block was released */
335 }
336 /*$PAGE*/
337 /*
338 *********************************************************************************************************
339 * QUERY MEMORY PARTITION
340 *
341 * Description : This function is used to determine the number of free memory blocks and the number of
342 * used memory blocks from a memory partition.
343 *
344 * Arguments : pmem is a pointer to the memory partition control block
345 *
346 * p_mem_data is a pointer to a structure that will contain information about the memory
347 * partition.
348 *
349 * Returns : OS_ERR_NONE if no errors were found.
350 * OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
351 * OS_ERR_MEM_INVALID_PDATA if you passed a NULL pointer to the data recipient.
352 *********************************************************************************************************
353 */
354
355 #if OS_MEM_QUERY_EN > 0
356 INT8U OSMemQuery (OS_MEM *pmem, OS_MEM_DATA *p_mem_data)
357 {
358 #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
359 OS_CPU_SR cpu_sr = 0;
360 #endif
361
362
363
364 #if OS_ARG_CHK_EN > 0
365 if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partition */
366 return (OS_ERR_MEM_INVALID_PMEM);
367 }
368 if (p_mem_data == (OS_MEM_DATA *)0) { /* Must release a valid storage area for the data */
369 return (OS_ERR_MEM_INVALID_PDATA);
370 }
371 #endif
372 OS_ENTER_CRITICAL();
373 p_mem_data->OSAddr = pmem->OSMemAddr;
374 p_mem_data->OSFreeList = pmem->OSMemFreeList;
375 p_mem_data->OSBlkSize = pmem->OSMemBlkSize;
376 p_mem_data->OSNBlks = pmem->OSMemNBlks;
377 p_mem_data->OSNFree = pmem->OSMemNFree;
378 OS_EXIT_CRITICAL();
379 p_mem_data->OSNUsed = p_mem_data->OSNBlks - p_mem_data->OSNFree;
380 return (OS_ERR_NONE);
381 }
382 #endif /* OS_MEM_QUERY_EN */
383 /*$PAGE*/
384 /*
385 *********************************************************************************************************
386 * INITIALIZE MEMORY PARTITION MANAGER
387 *
388 * Description : This function is called by uC/OS-II to initialize the memory partition manager. Your
389 * application MUST NOT call this function.
390 *
391 * Arguments : none
392 *
393 * Returns : none
394 *
395 * Note(s) : This function is INTERNAL to uC/OS-II and your application should not call it.
396 *********************************************************************************************************
397 */
398
399 void OS_MemInit (void)
400 {
401 #if OS_MAX_MEM_PART == 1
402 OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */
403 OSMemFreeList = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list */
404 #if OS_MEM_NAME_SIZE > 1
405 OSMemFreeList->OSMemName[0] = '?'; /* Unknown name */
406 OSMemFreeList->OSMemName[1] = OS_ASCII_NUL;
407 #endif
408 #endif
409
410 #if OS_MAX_MEM_PART >= 2
411 OS_MEM *pmem;
412 INT16U i;
413
414
415 OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */
416 pmem = &OSMemTbl[0]; /* Point to memory control block (MCB) */
417 for (i = 0; i < (OS_MAX_MEM_PART - 1); i++) { /* Init. list of free memory partitions */
418 pmem->OSMemFreeList = (void *)&OSMemTbl[i+1]; /* Chain list of free partitions */
419 #if OS_MEM_NAME_SIZE > 1
420 pmem->OSMemName[0] = '?'; /* Unknown name */
421 pmem->OSMemName[1] = OS_ASCII_NUL;
422 #endif
423 pmem++;
424 }
425 pmem->OSMemFreeList = (void *)0; /* Initialize last node */
426 #if OS_MEM_NAME_SIZE > 1
427 pmem->OSMemName[0] = '?'; /* Unknown name */
428 pmem->OSMemName[1] = OS_ASCII_NUL;
429 #endif
430
431 OSMemFreeList = &OSMemTbl[0]; /* Point to beginning of free list */
432 #endif
433 }
434 #endif /* OS_MEM_EN */
Segment part sizes:
Function/Label Bytes
-------------- -----
0 bytes of memory
Errors: none
Warnings: none
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -