上文主要介绍了邮箱管理相关的函数,本文介绍内存管理相关的函数:OSMemCreate()内存块创建函数,OSMemGet()函数,OSMemPut()函数,OSMemQuery()函数.以前用过的uC/OS-II笔记分享到这里。

内存管理介绍

在ANSI C中可以用malloc()和free()两个函数动态地分配内存和释放内存。但是,在嵌入式实时操作系统中,多次这样做会把原来很大的一块连续内存区域,逐渐地分割成许多非常小而且彼此又不相邻的内存区域,也就是内存碎片。由于这些碎片的大量存在,使得程序到后来连非常小的内存也分配不到。另外,由于内存管理算法的原因,malloc()和free()函数执行时间是不确定的。

在μC/OS-II中,操作系统把连续的大块内存按分区来管理。每个分区中包含有整数个大小相同的内存块。利用这种机制,μC/OS-II 对malloc()和free()函数进行了改进,使得它们可以分配和释放固定大小的内存块。这样一来,malloc()和free()函数的执行时间也是固定的了。

在一个系统中可以有多个内存分区。这样,用户的应用程序就可以从不同的内存分区中得到不同大小的内存块。但是,特定的内存块在释放时必须重新放回它以前所属于的内存分区。显然,采用这样的内存管理算法,上面的内存碎片问题就得到了解决。

为了便于内存的管理,在μC/OS-II中使用内存控制块(memory control blocks)的数据结构来跟踪每一个内存分区,系统中的每个内存分区都有它自己的内存控制块。

内存控制块的定义如下:

typedef struct {

void *OSMemAddr; //指向内存分区起始地址的指针

void *OSMemFreeList; //是指向下一个空闲内存控制块或者下一个空闲的内存块的指针

INT32U OSMemBlkSize; //是内存分区中内存块的大小

INT32U OSMemNBlks; //内存分区中总的内存块数量

INT32U OSMemNFree; //内存分区中当前可以得空闲内存块数量

} OS_MEM;

如果要在μC/OS-II中使用内存管理,需要在OS_CFG.H文件中将开关量OS_MEM_EN设置为1。这样μC/OS-II 在启动时就会对内存管理器进行初始化[由OSInit()调用OSMemInit()实现]。常数OS_MAX_MEM_PART(见文件OS_CFG.H)定义了最大的内存分区数,该常数值最小应为2。

注意的事项

使用内存管理模块需要做的工作还有:

1.打开配置文件OS_CFG.H,将开关量OS_MEM_EN设置为1:

#define OS_MEM_EN 0

2.打开配置文件OS_CFG.H,设置系统要建立的任务分区的数量:

#define OS_MAX_MEM_PART 2

OSMemCreate()内存块创建函数

1 主要作用: 该函数建立并初始化一个用于动态内存分配的区域,该内存区域包含指定数目的、大小确定的内存块。应用可以动态申请这些内存块并在用完后将其释放回这个内存区域。该函数的返回值就是指向这个内存区域控制块的指针,并作为OSMemGet(),OSMemPut(),OSMemQuery() 等相关调用的参数。

2函数原型:OS_MEM *OSMemCreate( void *addr, INT32U nblks, INT32U blksize, INT8U *err );

3参数说明:addr 建立的内存区域的起始地址。可以使用静态数组或在系统初始化时使用 malloc() 函数来分配这个区域的空间。

nblks 内存块的数目。每一个内存区域最少需要定义两个内存块。

blksize 每个内存块的大小,最小应该能够容纳一个指针变量。

err 是指向包含错误码的变量的指针。Err可能是如下几种情况:

OS_NO_ERR :成功建立内存区域。

OS_MEM_INVALID_ADDR :非法地址,即地址为空指针。

OS_MEM_INVALID_PART :没有空闲的内存区域。

OS_MEM_INVALID_BLKS :没有为内存区域建立至少两个内存块。

OS_MEM_INVALID_SIZE :内存块大小不足以容纳一个指针变量。

5、函数主体在os_men.c中

4返回值说明:

OSMemCreate() 函数返回指向所创建的内存区域控制块的指针。如果创建失败,函数返回空指针。

OSMemGet()函数

1 主要作用: 该函数用于从内存区域分配一个内存块。用户程序必须知道所建立的内存块的大小,并必须在使用完内存块后释放它。可以多次调用 OSMemGet() 函数。它的返回值就是指向所分配内存块的指针,并作为 OSMemPut() 函数的参数。

2函数原型:void *OSMemGet(OS_MEM *pmem, INT8U *err);

3参数说明:pmem 是指向内存区域控制块的指针,可以从 OSMemCreate() 函数的返回值中得到。

err 是指向包含错误码的变量的指针。Err可能是如下情况:

OS_NO_ERR :成功得到一个内存块。

OS_MEM_NO_FREE_BLKS :内存区域中已经没有足够的内存块。

4返回值说明:

OSMemGet() 函数返回指向所分配内存块的指针。如果没有可分配的内存块,OSMemGet() 函数返回空指针。

5、函数主体在os_men.c中

OSMemPut()

1 主要作用:该函数用于释放一个内存块,内存块必须释放回它原先所在的内存区域,否则会造成系统错误。

2函数原型:INT8U OSMemPut (OS_MEM *pmem, void *pblk);

3参数说明:pmem 是指向内存区域控制块的指针,可以从 OSMemCreate() 函数的返回值中得到。

pblk 是指向将被释放的内存块的指针。

4返回值说明:

OSMemPut() 函数的返回值为下述之一:

OS_NO_ERR :成功释放内存块

OS_MEM_FULL :内存区域已满,不能再接受更多释放的内存块。这种情况说明用户程序出现了错误,释放了多于用 OSMemGet() 函数得到的内存块。

5、函数主体在os_men.c中

OSMemQuery()

1 主要作用:该函数用于得到内存区域的信息。

2函数原型:INT8U OSMemQuery(OS_MEM *pmem, OS_MEM_DATA pdata);

3参数说明:pmem 是指向内存区域控制块的指针,可以从 OSMemCreate() 函数的返回值中得到。

pdata 是一个指向 OS_MEM_DATA 数据结构的指针,该数据结构包含了以下的域:

void OSAddr; /
指向内存区域起始地址的指针 /

void OSFreeList; /
指向空闲内存块列表起始地址的指针 /

INT32U OSBlkSize; /
每个内存块的大小 /

INT32U OSNBlks; /
该内存区域中的内存块总数 /

INT32U OSNFree; /
空闲的内存块数目 /

INT32U OSNUsed; /
已使用的内存块数目 */

4返回值说明:函数返回值总是OS_NO_ERR。

5、函数主体在os_men.c中

附os_men.c代码

  1. /*
  2. *********************************************************************************************************
  3. * uC/OS-II
  4. * The Real-Time Kernel
  5. * MEMORY MANAGEMENT
  6. *
  7. * (c) Copyright 1992-2013, Micrium, Weston, FL
  8. * All Rights Reserved
  9. *
  10. * File : OS_MEM.C
  11. * By : Jean J. Labrosse
  12. * Version : V2.92.08
  13. *
  14. * LICENSING TERMS:
  15. * ---------------
  16. * uC/OS-II is provided in source form for FREE evaluation, for educational use or for peaceful research.
  17. * If you plan on using uC/OS-II in a commercial product you need to contact Micrium to properly license
  18. * its use in your product. We provide ALL the source code for your convenience and to help you experience
  19. * uC/OS-II. The fact that the source is provided does NOT mean that you can use it without paying a
  20. * licensing fee.
  21. *********************************************************************************************************
  22. */
  23. #define MICRIUM_SOURCE
  24. #ifndef OS_MASTER_FILE
  25. #include <ucos_ii.h>
  26. #endif
  27. #if (OS_MEM_EN > 0u) && (OS_MAX_MEM_PART > 0u)
  28. /*
  29. *********************************************************************************************************
  30. * CREATE A MEMORY PARTITION
  31. *
  32. * Description : Create a fixed-sized memory partition that will be managed by uC/OS-II.
  33. *
  34. * Arguments : addr is the starting address of the memory partition
  35. *
  36. * nblks is the number of memory blocks to create from the partition.
  37. *
  38. * blksize is the size (in bytes) of each block in the memory partition.
  39. *
  40. * perr is a pointer to a variable containing an error message which will be set by
  41. * this function to either:
  42. *
  43. * OS_ERR_NONE if the memory partition has been created correctly.
  44. * OS_ERR_MEM_INVALID_ADDR if you are specifying an invalid address for the memory
  45. * storage of the partition or, the block does not align
  46. * on a pointer boundary
  47. * OS_ERR_MEM_INVALID_PART no free partitions available
  48. * OS_ERR_MEM_INVALID_BLKS user specified an invalid number of blocks (must be >= 2)
  49. * OS_ERR_MEM_INVALID_SIZE user specified an invalid block size
  50. * - must be greater than the size of a pointer
  51. * - must be able to hold an integral number of pointers
  52. * Returns : != (OS_MEM *)0 is the partition was created
  53. * == (OS_MEM *)0 if the partition was not created because of invalid arguments or, no
  54. * free partition is available.
  55. *********************************************************************************************************
  56. */
  57. OS_MEM *OSMemCreate (void *addr,
  58. INT32U nblks,
  59. INT32U blksize,
  60. INT8U *perr)
  61. {
  62. OS_MEM *pmem;
  63. INT8U *pblk;
  64. void **plink;
  65. INT32U loops;
  66. INT32U i;
  67. #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
  68. OS_CPU_SR cpu_sr = 0u;
  69. #endif
  70. #ifdef OS_SAFETY_CRITICAL
  71. if (perr == (INT8U *)0) {
  72. OS_SAFETY_CRITICAL_EXCEPTION();
  73. return ((OS_MEM *)0);
  74. }
  75. #endif
  76. #ifdef OS_SAFETY_CRITICAL_IEC61508
  77. if (OSSafetyCriticalStartFlag == OS_TRUE) {
  78. OS_SAFETY_CRITICAL_EXCEPTION();
  79. return ((OS_MEM *)0);
  80. }
  81. #endif
  82. #if OS_ARG_CHK_EN > 0u
  83. if (addr == (void *)0) { /* Must pass a valid address for the memory part.*/
  84. *perr = OS_ERR_MEM_INVALID_ADDR;
  85. return ((OS_MEM *)0);
  86. }
  87. if (((INT32U)addr & (sizeof(void *) - 1u)) != 0u){ /* Must be pointer size aligned */
  88. *perr = OS_ERR_MEM_INVALID_ADDR;
  89. return ((OS_MEM *)0);
  90. }
  91. if (nblks < 2u) { /* Must have at least 2 blocks per partition */
  92. *perr = OS_ERR_MEM_INVALID_BLKS;
  93. return ((OS_MEM *)0);
  94. }
  95. if (blksize < sizeof(void *)) { /* Must contain space for at least a pointer */
  96. *perr = OS_ERR_MEM_INVALID_SIZE;
  97. return ((OS_MEM *)0);
  98. }
  99. #endif
  100. OS_ENTER_CRITICAL();
  101. pmem = OSMemFreeList; /* Get next free memory partition */
  102. if (OSMemFreeList != (OS_MEM *)0) { /* See if pool of free partitions was empty */
  103. OSMemFreeList = (OS_MEM *)OSMemFreeList->OSMemFreeList;
  104. }
  105. OS_EXIT_CRITICAL();
  106. if (pmem == (OS_MEM *)0) { /* See if we have a memory partition */
  107. *perr = OS_ERR_MEM_INVALID_PART;
  108. return ((OS_MEM *)0);
  109. }
  110. plink = (void **)addr; /* Create linked list of free memory blocks */
  111. pblk = (INT8U *)addr;
  112. loops = nblks - 1u;
  113. for (i = 0u; i < loops; i++) {
  114. pblk += blksize; /* Point to the FOLLOWING block */
  115. *plink = (void *)pblk; /* Save pointer to NEXT block in CURRENT block */
  116. plink = (void **)pblk; /* Position to NEXT block */
  117. }
  118. *plink = (void *)0; /* Last memory block points to NULL */
  119. pmem->OSMemAddr = addr; /* Store start address of memory partition */
  120. pmem->OSMemFreeList = addr; /* Initialize pointer to pool of free blocks */
  121. pmem->OSMemNFree = nblks; /* Store number of free blocks in MCB */
  122. pmem->OSMemNBlks = nblks;
  123. pmem->OSMemBlkSize = blksize; /* Store block size of each memory blocks */
  124. *perr = OS_ERR_NONE;
  125. return (pmem);
  126. }
  127. /*$PAGE*/
  128. /*
  129. *********************************************************************************************************
  130. * GET A MEMORY BLOCK
  131. *
  132. * Description : Get a memory block from a partition
  133. *
  134. * Arguments : pmem is a pointer to the memory partition control block
  135. *
  136. * perr is a pointer to a variable containing an error message which will be set by this
  137. * function to either:
  138. *
  139. * OS_ERR_NONE if the memory partition has been created correctly.
  140. * OS_ERR_MEM_NO_FREE_BLKS if there are no more free memory blocks to allocate to caller
  141. * OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
  142. *
  143. * Returns : A pointer to a memory block if no error is detected
  144. * A pointer to NULL if an error is detected
  145. *********************************************************************************************************
  146. */
  147. void *OSMemGet (OS_MEM *pmem,
  148. INT8U *perr)
  149. {
  150. void *pblk;
  151. #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
  152. OS_CPU_SR cpu_sr = 0u;
  153. #endif
  154. #ifdef OS_SAFETY_CRITICAL
  155. if (perr == (INT8U *)0) {
  156. OS_SAFETY_CRITICAL_EXCEPTION();
  157. return ((void *)0);
  158. }
  159. #endif
  160. #if OS_ARG_CHK_EN > 0u
  161. if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partition */
  162. *perr = OS_ERR_MEM_INVALID_PMEM;
  163. return ((void *)0);
  164. }
  165. #endif
  166. OS_ENTER_CRITICAL();
  167. if (pmem->OSMemNFree > 0u) { /* See if there are any free memory blocks */
  168. pblk = pmem->OSMemFreeList; /* Yes, point to next free memory block */
  169. pmem->OSMemFreeList = *(void **)pblk; /* Adjust pointer to new free list */
  170. pmem->OSMemNFree--; /* One less memory block in this partition */
  171. OS_EXIT_CRITICAL();
  172. *perr = OS_ERR_NONE; /* No error */
  173. return (pblk); /* Return memory block to caller */
  174. }
  175. OS_EXIT_CRITICAL();
  176. *perr = OS_ERR_MEM_NO_FREE_BLKS; /* No, Notify caller of empty memory partition */
  177. return ((void *)0); /* Return NULL pointer to caller */
  178. }
  179. /*$PAGE*/
  180. /*
  181. *********************************************************************************************************
  182. * GET THE NAME OF A MEMORY PARTITION
  183. *
  184. * Description: This function is used to obtain the name assigned to a memory partition.
  185. *
  186. * Arguments : pmem is a pointer to the memory partition
  187. *
  188. * pname is a pointer to a pointer to an ASCII string that will receive the name of the memory partition.
  189. *
  190. * perr is a pointer to an error code that can contain one of the following values:
  191. *
  192. * OS_ERR_NONE if the name was copied to 'pname'
  193. * OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
  194. * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
  195. * OS_ERR_NAME_GET_ISR You called this function from an ISR
  196. *
  197. * Returns : The length of the string or 0 if 'pmem' is a NULL pointer.
  198. *********************************************************************************************************
  199. */
  200. #if OS_MEM_NAME_EN > 0u
  201. INT8U OSMemNameGet (OS_MEM *pmem,
  202. INT8U **pname,
  203. INT8U *perr)
  204. {
  205. INT8U len;
  206. #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
  207. OS_CPU_SR cpu_sr = 0u;
  208. #endif
  209. #ifdef OS_SAFETY_CRITICAL
  210. if (perr == (INT8U *)0) {
  211. OS_SAFETY_CRITICAL_EXCEPTION();
  212. return (0u);
  213. }
  214. #endif
  215. #if OS_ARG_CHK_EN > 0u
  216. if (pmem == (OS_MEM *)0) { /* Is 'pmem' a NULL pointer? */
  217. *perr = OS_ERR_MEM_INVALID_PMEM;
  218. return (0u);
  219. }
  220. if (pname == (INT8U **)0) { /* Is 'pname' a NULL pointer? */
  221. *perr = OS_ERR_PNAME_NULL;
  222. return (0u);
  223. }
  224. #endif
  225. if (OSIntNesting > 0u) { /* See if trying to call from an ISR */
  226. *perr = OS_ERR_NAME_GET_ISR;
  227. return (0u);
  228. }
  229. OS_ENTER_CRITICAL();
  230. *pname = pmem->OSMemName;
  231. len = OS_StrLen(*pname);
  232. OS_EXIT_CRITICAL();
  233. *perr = OS_ERR_NONE;
  234. return (len);
  235. }
  236. #endif
  237. /*$PAGE*/
  238. /*
  239. *********************************************************************************************************
  240. * ASSIGN A NAME TO A MEMORY PARTITION
  241. *
  242. * Description: This function assigns a name to a memory partition.
  243. *
  244. * Arguments : pmem is a pointer to the memory partition
  245. *
  246. * pname is a pointer to an ASCII string that contains the name of the memory partition.
  247. *
  248. * perr is a pointer to an error code that can contain one of the following values:
  249. *
  250. * OS_ERR_NONE if the name was copied to 'pname'
  251. * OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
  252. * OS_ERR_PNAME_NULL You passed a NULL pointer for 'pname'
  253. * OS_ERR_MEM_NAME_TOO_LONG if the name doesn't fit in the storage area
  254. * OS_ERR_NAME_SET_ISR if you called this function from an ISR
  255. *
  256. * Returns : None
  257. *********************************************************************************************************
  258. */
  259. #if OS_MEM_NAME_EN > 0u
  260. void OSMemNameSet (OS_MEM *pmem,
  261. INT8U *pname,
  262. INT8U *perr)
  263. {
  264. #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
  265. OS_CPU_SR cpu_sr = 0u;
  266. #endif
  267. #ifdef OS_SAFETY_CRITICAL
  268. if (perr == (INT8U *)0) {
  269. OS_SAFETY_CRITICAL_EXCEPTION();
  270. return;
  271. }
  272. #endif
  273. #if OS_ARG_CHK_EN > 0u
  274. if (pmem == (OS_MEM *)0) { /* Is 'pmem' a NULL pointer? */
  275. *perr = OS_ERR_MEM_INVALID_PMEM;
  276. return;
  277. }
  278. if (pname == (INT8U *)0) { /* Is 'pname' a NULL pointer? */
  279. *perr = OS_ERR_PNAME_NULL;
  280. return;
  281. }
  282. #endif
  283. if (OSIntNesting > 0u) { /* See if trying to call from an ISR */
  284. *perr = OS_ERR_NAME_SET_ISR;
  285. return;
  286. }
  287. OS_ENTER_CRITICAL();
  288. pmem->OSMemName = pname;
  289. OS_EXIT_CRITICAL();
  290. *perr = OS_ERR_NONE;
  291. }
  292. #endif
  293. /*$PAGE*/
  294. /*
  295. *********************************************************************************************************
  296. * RELEASE A MEMORY BLOCK
  297. *
  298. * Description : Returns a memory block to a partition
  299. *
  300. * Arguments : pmem is a pointer to the memory partition control block
  301. *
  302. * pblk is a pointer to the memory block being released.
  303. *
  304. * Returns : OS_ERR_NONE if the memory block was inserted into the partition
  305. * OS_ERR_MEM_FULL if you are returning a memory block to an already FULL memory
  306. * partition (You freed more blocks than you allocated!)
  307. * OS_ERR_MEM_INVALID_PMEM if you passed a NULL pointer for 'pmem'
  308. * OS_ERR_MEM_INVALID_PBLK if you passed a NULL pointer for the block to release.
  309. *********************************************************************************************************
  310. */
  311. INT8U OSMemPut (OS_MEM *pmem,
  312. void *pblk)
  313. {
  314. #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
  315. OS_CPU_SR cpu_sr = 0u;
  316. #endif
  317. #if OS_ARG_CHK_EN > 0u
  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. #if OS_MEM_QUERY_EN > 0u
  355. INT8U OSMemQuery (OS_MEM *pmem,
  356. OS_MEM_DATA *p_mem_data)
  357. {
  358. #if OS_CRITICAL_METHOD == 3u /* Allocate storage for CPU status register */
  359. OS_CPU_SR cpu_sr = 0u;
  360. #endif
  361. #if OS_ARG_CHK_EN > 0u
  362. if (pmem == (OS_MEM *)0) { /* Must point to a valid memory partition */
  363. return (OS_ERR_MEM_INVALID_PMEM);
  364. }
  365. if (p_mem_data == (OS_MEM_DATA *)0) { /* Must release a valid storage area for the data */
  366. return (OS_ERR_MEM_INVALID_PDATA);
  367. }
  368. #endif
  369. OS_ENTER_CRITICAL();
  370. p_mem_data->OSAddr = pmem->OSMemAddr;
  371. p_mem_data->OSFreeList = pmem->OSMemFreeList;
  372. p_mem_data->OSBlkSize = pmem->OSMemBlkSize;
  373. p_mem_data->OSNBlks = pmem->OSMemNBlks;
  374. p_mem_data->OSNFree = pmem->OSMemNFree;
  375. OS_EXIT_CRITICAL();
  376. p_mem_data->OSNUsed = p_mem_data->OSNBlks - p_mem_data->OSNFree;
  377. return (OS_ERR_NONE);
  378. }
  379. #endif /* OS_MEM_QUERY_EN */
  380. /*$PAGE*/
  381. /*
  382. *********************************************************************************************************
  383. * INITIALIZE MEMORY PARTITION MANAGER
  384. *
  385. * Description : This function is called by uC/OS-II to initialize the memory partition manager. Your
  386. * application MUST NOT call this function.
  387. *
  388. * Arguments : none
  389. *
  390. * Returns : none
  391. *
  392. * Note(s) : This function is INTERNAL to uC/OS-II and your application should not call it.
  393. *********************************************************************************************************
  394. */
  395. void OS_MemInit (void)
  396. {
  397. #if OS_MAX_MEM_PART == 1u
  398. OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */
  399. OSMemFreeList = (OS_MEM *)&OSMemTbl[0]; /* Point to beginning of free list */
  400. #if OS_MEM_NAME_EN > 0u
  401. OSMemFreeList->OSMemName = (INT8U *)"?"; /* Unknown name */
  402. #endif
  403. #endif
  404. #if OS_MAX_MEM_PART >= 2u
  405. OS_MEM *pmem;
  406. INT16U i;
  407. OS_MemClr((INT8U *)&OSMemTbl[0], sizeof(OSMemTbl)); /* Clear the memory partition table */
  408. for (i = 0u; i < (OS_MAX_MEM_PART - 1u); i++) { /* Init. list of free memory partitions */
  409. pmem = &OSMemTbl[i]; /* Point to memory control block (MCB) */
  410. pmem->OSMemFreeList = (void *)&OSMemTbl[i + 1u]; /* Chain list of free partitions */
  411. #if OS_MEM_NAME_EN > 0u
  412. pmem->OSMemName = (INT8U *)(void *)"?";
  413. #endif
  414. }
  415. pmem = &OSMemTbl[i];
  416. pmem->OSMemFreeList = (void *)0; /* Initialize last node */
  417. #if OS_MEM_NAME_EN > 0u
  418. pmem->OSMemName = (INT8U *)(void *)"?";
  419. #endif
  420. OSMemFreeList = &OSMemTbl[0]; /* Point to beginning of free list */
  421. #endif
  422. }
  423. #endif /* OS_MEM_EN */

uC/OS-II 函数之内存管理相关函数的更多相关文章

  1. uC/OS II 函数说明 之–OSTaskCreate()与OSTaskCreateExt()

    1. OSTaskCreate()    OSTaskCreate()建立一个新任务,能够在多任务环境启动之前,或者执行任务中建立任务.注意,ISR中禁止建立任务,一个任务必须为无限循环结构.    ...

  2. uC/OS II原理分析及源码阅读(一)

    uC/OS II(Micro Control Operation System Two)是一个可以基于ROM运行的.可裁减的.抢占式.实时多任务内核,具有高度可移植性,特别适合于微处理器和控制器,是和 ...

  3. 【原创】uC/OS II 任务切换原理

    今天学习了uC/OS II的任务切换,知道要实现任务的切换,要将原先任务的寄存器压入任务堆栈,再将新任务中任务堆栈的寄存器内容弹出到CPU的寄存器,其中的CS.IP寄存器没有出栈和入栈指令,所以只能引 ...

  4. Objective-C 高级编程:iOS与OS X多线程和内存管理

    <Objective-C 高级编程:iOS与OS X多线程和内存管理> 基本信息 原书名: Pro Multithreading and Memory Management for iOS ...

  5. 【小梅哥SOPC学习笔记】NIOS II处理器运行UC/OS II

    SOPC开发流程之NIOS II 处理器运行 UC/OS II 这里以在芯航线FPGA学习套件的核心板上搭建 NIOS II 软核并运行 UCOS II操作系统为例介绍SOPC的开发流程. 第一步:建 ...

  6. 内存管理相关函数 -- Linux【转】

    转自:http://blog.csdn.net/cy_cai/article/details/47001245 1.kmalloc()/kfree() static __always_inline v ...

  7. 【C++基础学习】引用和指针、重载、函数、内存管理

    第一部分:引用VS指针 引用的含义:变量的别名 注意:变量不能只有别名,必须有一个真实的变量与之相对应 基本数据类型的引用 对别名本身的操作和它的实体的操作是一样的 1.基本数据类型的引用 类型 &a ...

  8. 《Objective-C高级编程:iOS与OS X多线程和内存管理》读后感

    拿到这本书的第一感觉是非常薄,可是内容就如同序里面所说,这不是一本面向刚開始学习的人的书,比較有深度,对C/C++全然不熟悉的话非常多东西会看不明确. 尽管此书在技术点上仅仅谈到了ARC.Blocks ...

  9. uC/OS-II 函数之邮箱管理相关函数

    上文主要介绍了消息队列相关的函数,本文介绍邮箱管理相关的函数:OSMboxCreate()建立一个邮箱,OSMboxDel()删除一个邮箱,OSMboxPend()等待邮箱中的消息,OSMboxPos ...

随机推荐

  1. cakephp跳转到指定的错误页面

    第一步:修改core.php 第二步:创建AppExceptionRender.php文件 参考:https://blog.jordanhopfner.com/2012/09/11/custom-40 ...

  2. Siverlight MarkerSize 控制数据点半径大小 LineThickness 控制点与点之间直线的厚度

    using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI ...

  3. C语言cJSON库的使用,解析json数据格式

    C语言cJSON库的使用,解析json数据格式 摘自:https://www.cnblogs.com/piaoyang/p/9274925.html 对于c语言来说是没有字典这样的结构的,所以对于解析 ...

  4. PLSA算法(转)

    文章分类:综合技术 1. 引子 Bag-of-Words 模型是NLP和IR领域中的一个基本假设.在这个模型中,一个文档(document)被表示为一组单词(word/term)的无序组合,而忽略了语 ...

  5. Windows 配置 nginx php 多版本切换

    1. 下载 nginx   nginx.org 2. 下载 php  windows.php.net   选择 nts 版本,解压后,将php.ini.development 重命名为  php.in ...

  6. Yii2.0 多语言设置(高级版配置方法) - 新的方法

    1.设置默认语言:在mail.php配置文件加上:'language'=>'zh_CN'; 2.多语言切换 (我这边是在site控制器里面操作的所以用的'/site/language') htm ...

  7. kcp源码segment头文件各字段含义

    conv conv为一个表示会话编号的整数,和tcp的 conv一样,通信双// 方需保证 conv相同,相互的数据包才能够被认可 cmd             cmd用来区分分片的作用.IKCP_ ...

  8. Introduction mybatis

    项目地址 https://github.com/mybatis/mybatis-3 英文官网 http://mybatis.github.io/mybatis-3/ 中文官网 http://mybat ...

  9. 在线测试正则表达式工具 jQuery.Validate验证库

    http://www.jb51.net/tools/zhengze.html http://www.cnblogs.com/weiqt/articles/2013800.html  

  10. JavaScript - this详解 (二)

    用栗子说this Bug年年有,今年特别多 对于JavaScript这么灵活的语言来说,少了this怎么活! function 函数 this 对于没有实例化的function,我们称之为函数,即没有 ...