rtx_mempool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * Copyright (c) 2013-2016 ARM Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the License); you may
  7. * not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an AS IS BASIS, WITHOUT
  14. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * -----------------------------------------------------------------------------
  19. *
  20. * Project: CMSIS-RTOS RTX
  21. * Title: Memory Pool functions
  22. *
  23. * -----------------------------------------------------------------------------
  24. */
  25. #include "rtx_lib.h"
  26. // ==== Library functions ====
  27. /// Initialize Memory Pool.
  28. /// \param[in] mp_info memory pool info.
  29. /// \param[in] block_count maximum number of memory blocks in memory pool.
  30. /// \param[in] block_size size of a memory block in bytes.
  31. /// \param[in] block_mem pointer to memory for block storage.
  32. /// \return 1 - success, 0 - failure.
  33. uint32_t os_MemoryPoolInit (os_mp_info_t *mp_info, uint32_t block_count, uint32_t block_size, void *block_mem) {
  34. void *block;
  35. // Check parameters
  36. if ((mp_info == NULL) ||
  37. (block_count == 0U) ||
  38. (block_size == 0U) ||
  39. (block_mem == NULL)) {
  40. return 0U;
  41. }
  42. // Initialize information structure
  43. mp_info->max_blocks = block_count;
  44. mp_info->used_blocks = 0U;
  45. mp_info->block_size = block_size;
  46. mp_info->block_base = block_mem;
  47. mp_info->block_free = block_mem;
  48. mp_info->block_lim = (uint8_t *)block_mem + (block_count * block_size);
  49. // Link all free blocks
  50. while (--block_count) {
  51. block = (uint8_t *)block_mem + block_size;
  52. *((void **)block_mem) = block;
  53. block_mem = block;
  54. }
  55. *((void **)block_mem) = NULL;
  56. return 1U;
  57. }
  58. /// Allocate a memory block from a Memory Pool.
  59. /// \param[in] mp_info memory pool info.
  60. /// \return address of the allocated memory block or NULL in case of no memory is available.
  61. void *os_MemoryPoolAlloc (os_mp_info_t *mp_info) {
  62. #if (__EXCLUSIVE_ACCESS == 0U)
  63. uint32_t primask = __get_PRIMASK();
  64. #endif
  65. void *block;
  66. if (mp_info == NULL) {
  67. return NULL;
  68. }
  69. #if (__EXCLUSIVE_ACCESS == 0U)
  70. __disable_irq();
  71. block = mp_info->block_free;
  72. if (block != NULL) {
  73. mp_info->block_free = *((void **)block);
  74. mp_info->used_blocks++;
  75. }
  76. if (primask == 0U) {
  77. __enable_irq();
  78. }
  79. #else
  80. {
  81. register uint32_t val, res;
  82. __ASM volatile (
  83. ".syntax unified\n\t"
  84. "loop1%=:\n\t"
  85. "ldrex %[block],[%[mp_info],%[_block_free]]\n\t"
  86. "cbnz %[block],update%=\n\t"
  87. "clrex\n\t"
  88. "b exit%=\n\t"
  89. "update%=:\n\t"
  90. "ldr %[val],[%[block]]\n\t"
  91. "strex %[res],%[val],[%[mp_info],%[_block_free]]\n\t"
  92. "cbz %[res],loop2%=\n\t"
  93. "b loop1%=\n\t"
  94. "loop2%=:\n\t"
  95. "ldrex %[val],[%[mp_info],%[_used_blocks]]\n\t"
  96. "adds %[val],#1\n\t"
  97. "strex %[res],%[val],[%[mp_info],%[_used_blocks]]\n\t"
  98. "cbz %[res],exit%=\n\t"
  99. "b loop2%=\n\t"
  100. "exit%=:"
  101. : [block] "=&l" (block),
  102. [val] "=&l" (val),
  103. [res] "=&l" (res)
  104. : [mp_info] "l" (mp_info),
  105. [_block_free] "I" (offsetof(os_mp_info_t, block_free)),
  106. [_used_blocks] "I" (offsetof(os_mp_info_t, used_blocks))
  107. : "cc", "memory"
  108. );
  109. }
  110. #endif
  111. return block;
  112. }
  113. /// Return an allocated memory block back to a Memory Pool.
  114. /// \param[in] mp_info memory pool info.
  115. /// \param[in] block address of the allocated memory block to be returned to the memory pool.
  116. /// \return status code that indicates the execution status of the function.
  117. osStatus_t os_MemoryPoolFree (os_mp_info_t *mp_info, void *block) {
  118. #if (__EXCLUSIVE_ACCESS == 0U)
  119. uint32_t primask = __get_PRIMASK();
  120. #endif
  121. if (mp_info == NULL) {
  122. return osErrorParameter;
  123. }
  124. if ((block < mp_info->block_base) || (block >= mp_info->block_lim)) {
  125. return osErrorParameter;
  126. }
  127. #if (__EXCLUSIVE_ACCESS == 0U)
  128. __disable_irq();
  129. *((void **)block) = mp_info->block_free;
  130. mp_info->block_free = block;
  131. mp_info->used_blocks--;
  132. if (primask == 0U) {
  133. __enable_irq();
  134. }
  135. #else
  136. {
  137. register uint32_t val1, val2, res;
  138. __ASM volatile (
  139. ".syntax unified\n\t"
  140. "loop1%=:\n\t"
  141. "ldr %[val1],[%[mp_info],%[_block_free]]\n\t"
  142. "str %[val1],[%[block]]\n\t"
  143. "dmb\n\t"
  144. "ldrex %[val1],[%[mp_info],%[_block_free]]\n\t"
  145. "ldr %[val2],[%[block]]\n\t"
  146. "cmp %[val2],%[val1]\n\t"
  147. "bne loop1%=\n\t"
  148. "strex %[res],%[block],[%[mp_info],%[_block_free]]\n\t"
  149. "cbz %[res],loop2%=\n\t"
  150. "b loop1%=\n\t"
  151. "loop2%=:\n\t"
  152. "ldrex %[val1],[%[mp_info],%[_used_blocks]]\n\t"
  153. "subs %[val1],#1\n\t"
  154. "strex %[res],%[val1],[%[mp_info],%[_used_blocks]]\n\t"
  155. "cbz %[res],exit%=\n\t"
  156. "b loop2%=\n\t"
  157. "exit%=:"
  158. : [val1] "=&l" (val1),
  159. [val2] "=&l" (val2),
  160. [res] "=&l" (res)
  161. : [block] "l" (block),
  162. [mp_info] "l" (mp_info),
  163. [_block_free] "I" (offsetof(os_mp_info_t, block_free)),
  164. [_used_blocks] "I" (offsetof(os_mp_info_t, used_blocks))
  165. : "cc", "memory"
  166. );
  167. }
  168. #endif
  169. return osOK;
  170. }
  171. /// Memory Pool post ISR processing.
  172. /// \param[in] mp memory pool object.
  173. void os_MemoryPoolPostProcess (os_memory_pool_t *mp) {
  174. void *block;
  175. os_thread_t *thread;
  176. if (mp->state == os_ObjectInactive) {
  177. return;
  178. }
  179. // Check if Thread is waiting to allocate memory
  180. if (mp->thread_list != NULL) {
  181. // Allocate memory
  182. block = os_MemoryPoolAlloc(&mp->mp_info);
  183. if (block != NULL) {
  184. // Wakeup waiting Thread with highest Priority
  185. thread = os_ThreadListGet((os_object_t*)mp);
  186. os_ThreadWaitExit(thread, (uint32_t)block, false);
  187. }
  188. }
  189. }
  190. // ==== Service Calls ====
  191. // Service Calls definitions
  192. SVC0_3(MemoryPoolNew, osMemoryPoolId_t, uint32_t, uint32_t, const osMemoryPoolAttr_t *)
  193. SVC0_1(MemoryPoolGetName, const char *, osMemoryPoolId_t)
  194. SVC0_2(MemoryPoolAlloc, void *, osMemoryPoolId_t, uint32_t)
  195. SVC0_2(MemoryPoolFree, osStatus_t, osMemoryPoolId_t, void *)
  196. SVC0_1(MemoryPoolGetCapacity, uint32_t, osMemoryPoolId_t)
  197. SVC0_1(MemoryPoolGetBlockSize, uint32_t, osMemoryPoolId_t)
  198. SVC0_1(MemoryPoolGetCount, uint32_t, osMemoryPoolId_t)
  199. SVC0_1(MemoryPoolGetSpace, uint32_t, osMemoryPoolId_t)
  200. SVC0_1(MemoryPoolDelete, osStatus_t, osMemoryPoolId_t)
  201. /// Create and Initialize a Memory Pool object.
  202. /// \note API identical to osMemoryPoolNew
  203. osMemoryPoolId_t os_svcMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) {
  204. os_memory_pool_t *mp;
  205. void *mp_mem;
  206. uint32_t mp_size;
  207. uint32_t size;
  208. uint8_t flags;
  209. const char *name;
  210. // Check parameters
  211. if ((block_count == 0U) ||
  212. (block_size == 0U)) {
  213. return NULL;
  214. }
  215. block_size = (block_size + 3U) & ~3UL;
  216. if ((__CLZ(block_count) + __CLZ(block_size)) < 32) {
  217. return NULL;
  218. }
  219. size = block_count * block_size;
  220. // Process attributes
  221. if (attr != NULL) {
  222. name = attr->name;
  223. mp = attr->cb_mem;
  224. mp_mem = attr->mp_mem;
  225. mp_size = attr->mp_size;
  226. if (mp != NULL) {
  227. if (((uint32_t)mp & 3U) || (attr->cb_size < sizeof(os_memory_pool_t))) {
  228. return NULL;
  229. }
  230. } else {
  231. if (attr->cb_size != 0U) {
  232. return NULL;
  233. }
  234. }
  235. if (mp_mem != NULL) {
  236. if (((uint32_t)mp_mem & 3U) || (mp_size < size)) {
  237. return NULL;
  238. }
  239. } else {
  240. if (mp_size != 0U) {
  241. return NULL;
  242. }
  243. }
  244. } else {
  245. name = NULL;
  246. mp = NULL;
  247. mp_mem = NULL;
  248. }
  249. // Allocate object memory if not provided
  250. if (mp == NULL) {
  251. if (os_Info.mpi.memory_pool != NULL) {
  252. mp = os_MemoryPoolAlloc(os_Info.mpi.memory_pool);
  253. } else {
  254. mp = os_MemoryAlloc(os_Info.mem.common, sizeof(os_memory_pool_t), 1U);
  255. }
  256. if (mp == NULL) {
  257. return NULL;
  258. }
  259. flags = os_FlagSystemObject;
  260. } else {
  261. flags = 0U;
  262. }
  263. // Allocate data memory if not provided
  264. if (mp_mem == NULL) {
  265. mp_mem = os_MemoryAlloc(os_Info.mem.mp_data, size, 0U);
  266. if (mp_mem == NULL) {
  267. if (flags & os_FlagSystemObject) {
  268. if (os_Info.mpi.memory_pool != NULL) {
  269. os_MemoryPoolFree(os_Info.mpi.memory_pool, mp);
  270. } else {
  271. os_MemoryFree(os_Info.mem.common, mp);
  272. }
  273. }
  274. return NULL;
  275. }
  276. memset(mp_mem, 0, size);
  277. flags |= os_FlagSystemMemory;
  278. }
  279. // Initialize control block
  280. mp->id = os_IdMemoryPool;
  281. mp->state = os_ObjectActive;
  282. mp->flags = flags;
  283. mp->name = name;
  284. mp->thread_list = NULL;
  285. os_MemoryPoolInit(&mp->mp_info, block_count, block_size, mp_mem);
  286. // Register post ISR processing function
  287. os_Info.post_process.memory_pool = os_MemoryPoolPostProcess;
  288. return mp;
  289. }
  290. /// Get name of a Memory Pool object.
  291. /// \note API identical to osMemoryPoolGetName
  292. const char *os_svcMemoryPoolGetName (osMemoryPoolId_t mp_id) {
  293. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  294. // Check parameters
  295. if ((mp == NULL) ||
  296. (mp->id != os_IdMemoryPool)) {
  297. return NULL;
  298. }
  299. // Check object state
  300. if (mp->state == os_ObjectInactive) {
  301. return NULL;
  302. }
  303. return mp->name;
  304. }
  305. /// Allocate a memory block from a Memory Pool.
  306. /// \note API identical to osMemoryPoolAlloc
  307. void *os_svcMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) {
  308. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  309. void *block;
  310. // Check parameters
  311. if ((mp == NULL) ||
  312. (mp->id != os_IdMemoryPool)) {
  313. return NULL;
  314. }
  315. // Check object state
  316. if (mp->state == os_ObjectInactive) {
  317. return NULL;
  318. }
  319. // Allocate memory
  320. block = os_MemoryPoolAlloc(&mp->mp_info);
  321. if (block == NULL) {
  322. // No memory available
  323. if (timeout != 0U) {
  324. // Suspend current Thread
  325. os_ThreadListPut((os_object_t*)mp, os_ThreadGetRunning());
  326. os_ThreadWaitEnter(os_ThreadWaitingMemoryPool, timeout);
  327. }
  328. }
  329. return block;
  330. }
  331. /// Return an allocated memory block back to a Memory Pool.
  332. /// \note API identical to osMemoryPoolFree
  333. osStatus_t os_svcMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) {
  334. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  335. os_thread_t *thread;
  336. osStatus_t status;
  337. // Check parameters
  338. if ((mp == NULL) ||
  339. (mp->id != os_IdMemoryPool)) {
  340. return osErrorParameter;
  341. }
  342. // Check object state
  343. if (mp->state == os_ObjectInactive) {
  344. return osErrorResource;
  345. }
  346. // Free memory
  347. status = os_MemoryPoolFree(&mp->mp_info, block);
  348. if (status == osOK) {
  349. // Check if Thread is waiting to allocate memory
  350. if (mp->thread_list != NULL) {
  351. // Allocate memory
  352. block = os_MemoryPoolAlloc(&mp->mp_info);
  353. if (block != NULL) {
  354. // Wakeup waiting Thread with highest Priority
  355. thread = os_ThreadListGet((os_object_t*)mp);
  356. os_ThreadWaitExit(thread, (uint32_t)block, true);
  357. }
  358. }
  359. }
  360. return status;
  361. }
  362. /// Get maximum number of memory blocks in a Memory Pool.
  363. /// \note API identical to osMemoryPoolGetCapacity
  364. uint32_t os_svcMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) {
  365. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  366. // Check parameters
  367. if ((mp == NULL) ||
  368. (mp->id != os_IdMemoryPool)) {
  369. return 0U;
  370. }
  371. // Check object state
  372. if (mp->state == os_ObjectInactive) {
  373. return 0U;
  374. }
  375. return mp->mp_info.max_blocks;
  376. }
  377. /// Get memory block size in a Memory Pool.
  378. /// \note API identical to osMemoryPoolGetBlockSize
  379. uint32_t os_svcMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) {
  380. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  381. // Check parameters
  382. if ((mp == NULL) ||
  383. (mp->id != os_IdMemoryPool)) {
  384. return 0U;
  385. }
  386. // Check object state
  387. if (mp->state == os_ObjectInactive) {
  388. return 0U;
  389. }
  390. return mp->mp_info.block_size;
  391. }
  392. /// Get number of memory blocks used in a Memory Pool.
  393. /// \note API identical to osMemoryPoolGetCount
  394. uint32_t os_svcMemoryPoolGetCount (osMemoryPoolId_t mp_id) {
  395. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  396. // Check parameters
  397. if ((mp == NULL) ||
  398. (mp->id != os_IdMemoryPool)) {
  399. return 0U;
  400. }
  401. // Check object state
  402. if (mp->state == os_ObjectInactive) {
  403. return 0U;
  404. }
  405. return mp->mp_info.used_blocks;
  406. }
  407. /// Get number of memory blocks available in a Memory Pool.
  408. /// \note API identical to osMemoryPoolGetSpace
  409. uint32_t os_svcMemoryPoolGetSpace (osMemoryPoolId_t mp_id) {
  410. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  411. // Check parameters
  412. if ((mp == NULL) ||
  413. (mp->id != os_IdMemoryPool)) {
  414. return 0U;
  415. }
  416. // Check object state
  417. if (mp->state == os_ObjectInactive) {
  418. return 0U;
  419. }
  420. return (mp->mp_info.max_blocks - mp->mp_info.used_blocks);
  421. }
  422. /// Delete a Memory Pool object.
  423. /// \note API identical to osMemoryPoolDelete
  424. osStatus_t os_svcMemoryPoolDelete (osMemoryPoolId_t mp_id) {
  425. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  426. os_thread_t *thread;
  427. // Check parameters
  428. if ((mp == NULL) ||
  429. (mp->id != os_IdMemoryPool)) {
  430. return osErrorParameter;
  431. }
  432. // Check object state
  433. if (mp->state == os_ObjectInactive) {
  434. return osErrorResource;
  435. }
  436. // Mark object as inactive
  437. mp->state = os_ObjectInactive;
  438. // Unblock waiting threads
  439. if (mp->thread_list != NULL) {
  440. do {
  441. thread = os_ThreadListGet((os_object_t*)mp);
  442. os_ThreadWaitExit(thread, 0U, false);
  443. } while (mp->thread_list != NULL);
  444. os_ThreadDispatch(NULL);
  445. }
  446. // Free data memory
  447. if (mp->flags & os_FlagSystemMemory) {
  448. os_MemoryFree(os_Info.mem.mp_data, mp->mp_info.block_base);
  449. }
  450. // Free object memory
  451. if (mp->flags & os_FlagSystemObject) {
  452. if (os_Info.mpi.memory_pool != NULL) {
  453. os_MemoryPoolFree(os_Info.mpi.memory_pool, mp);
  454. } else {
  455. os_MemoryFree(os_Info.mem.common, mp);
  456. }
  457. }
  458. return osOK;
  459. }
  460. // ==== ISR Calls ====
  461. /// Allocate a memory block from a Memory Pool.
  462. /// \note API identical to osMemoryPoolAlloc
  463. __STATIC_INLINE
  464. void *os_isrMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) {
  465. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  466. void *block;
  467. // Check parameters
  468. if ((mp == NULL) ||
  469. (mp->id != os_IdMemoryPool)) {
  470. return NULL;
  471. }
  472. if (timeout != 0U) {
  473. return NULL;
  474. }
  475. // Check object state
  476. if (mp->state == os_ObjectInactive) {
  477. return NULL;
  478. }
  479. // Allocate memory
  480. block = os_MemoryPoolAlloc(&mp->mp_info);
  481. return block;
  482. }
  483. /// Return an allocated memory block back to a Memory Pool.
  484. /// \note API identical to osMemoryPoolFree
  485. __STATIC_INLINE
  486. osStatus_t os_isrMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) {
  487. os_memory_pool_t *mp = (os_memory_pool_t *)mp_id;
  488. osStatus_t status;
  489. // Check parameters
  490. if ((mp == NULL) ||
  491. (mp->id != os_IdMemoryPool)) {
  492. return osErrorParameter;
  493. }
  494. // Check object state
  495. if (mp->state == os_ObjectInactive) {
  496. return osErrorResource;
  497. }
  498. // Free memory
  499. status = os_MemoryPoolFree(&mp->mp_info, block);
  500. if (status == osOK) {
  501. // Register post ISR processing
  502. os_PostProcess((os_object_t *)mp);
  503. }
  504. return status;
  505. }
  506. // ==== Public API ====
  507. /// Create and Initialize a Memory Pool object.
  508. osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) {
  509. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  510. return NULL;
  511. }
  512. if ((os_KernelGetState() == os_KernelReady) && IS_PRIVILEGED()) {
  513. // Kernel Ready (not running) and in Privileged mode
  514. return os_svcMemoryPoolNew(block_count, block_size, attr);
  515. } else {
  516. return __svcMemoryPoolNew(block_count, block_size, attr);
  517. }
  518. }
  519. /// Get name of a Memory Pool object.
  520. const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id) {
  521. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  522. return NULL;
  523. }
  524. return __svcMemoryPoolGetName(mp_id);
  525. }
  526. /// Allocate a memory block from a Memory Pool.
  527. void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) {
  528. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  529. return os_isrMemoryPoolAlloc(mp_id, timeout);
  530. } else {
  531. return __svcMemoryPoolAlloc(mp_id, timeout);
  532. }
  533. }
  534. /// Return an allocated memory block back to a Memory Pool.
  535. osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) {
  536. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  537. return os_isrMemoryPoolFree(mp_id, block);
  538. } else {
  539. return __svcMemoryPoolFree(mp_id, block);
  540. }
  541. }
  542. /// Get maximum number of memory blocks in a Memory Pool.
  543. uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) {
  544. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  545. return os_svcMemoryPoolGetCapacity(mp_id);
  546. } else {
  547. return __svcMemoryPoolGetCapacity(mp_id);
  548. }
  549. }
  550. /// Get memory block size in a Memory Pool.
  551. uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) {
  552. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  553. return os_svcMemoryPoolGetBlockSize(mp_id);
  554. } else {
  555. return __svcMemoryPoolGetBlockSize(mp_id);
  556. }
  557. }
  558. /// Get number of memory blocks used in a Memory Pool.
  559. uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id) {
  560. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  561. return os_svcMemoryPoolGetCount(mp_id);
  562. } else {
  563. return __svcMemoryPoolGetCount(mp_id);
  564. }
  565. }
  566. /// Get number of memory blocks available in a Memory Pool.
  567. uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id) {
  568. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  569. return os_svcMemoryPoolGetSpace(mp_id);
  570. } else {
  571. return __svcMemoryPoolGetSpace(mp_id);
  572. }
  573. }
  574. /// Delete a Memory Pool object.
  575. osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id) {
  576. if (IS_IRQ_MODE() || IS_IRQ_MASKED()) {
  577. return osErrorISR;
  578. }
  579. return __svcMemoryPoolDelete(mp_id);
  580. }