lib_mem.h 83 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. /*
  2. *********************************************************************************************************
  3. * uC/LIB
  4. * CUSTOM LIBRARY MODULES
  5. *
  6. * (c) Copyright 2004-2014; Micrium, Inc.; Weston, FL
  7. *
  8. * All rights reserved. Protected by international copyright laws.
  9. *
  10. * uC/LIB is provided in source form to registered licensees ONLY. It is
  11. * illegal to distribute this source code to any third party unless you receive
  12. * written permission by an authorized Micrium representative. Knowledge of
  13. * the source code may NOT be used to develop a similar product.
  14. *
  15. * Please help us continue to provide the Embedded community with the finest
  16. * software available. Your honesty is greatly appreciated.
  17. *
  18. * You can find our product's user manual, API reference, release notes and
  19. * more information at: https://doc.micrium.com
  20. *
  21. * You can contact us at: http://www.micrium.com
  22. *********************************************************************************************************
  23. */
  24. /*
  25. *********************************************************************************************************
  26. *
  27. * STANDARD MEMORY OPERATIONS
  28. *
  29. * Filename : lib_mem.h
  30. * Version : V1.38.01
  31. * Programmer(s) : ITJ
  32. * FBJ
  33. * EJ
  34. * JFD
  35. *********************************************************************************************************
  36. * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
  37. *
  38. * (a) ALL standard library functions are implemented in the custom library modules :
  39. *
  40. * (1) \<Custom Library Directory>\lib_*.*
  41. *
  42. * (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
  43. *
  44. * where
  45. * <Custom Library Directory> directory path for custom library software
  46. * <cpu> directory name for specific processor (CPU)
  47. * <compiler> directory name for specific compiler
  48. *
  49. * (b) Product-specific library functions are implemented in individual products.
  50. *
  51. * (2) Assumes the following versions (or more recent) of software modules are included in
  52. * the project build :
  53. *
  54. * (a) uC/CPU V1.27
  55. *********************************************************************************************************
  56. */
  57. /*
  58. *********************************************************************************************************
  59. * MODULE
  60. *
  61. * Note(s) : (1) This memory library header file is protected from multiple pre-processor inclusion through
  62. * use of the memory library module present pre-processor macro definition.
  63. *********************************************************************************************************
  64. */
  65. #ifndef LIB_MEM_MODULE_PRESENT /* See Note #1. */
  66. #define LIB_MEM_MODULE_PRESENT
  67. /*
  68. *********************************************************************************************************
  69. * INCLUDE FILES
  70. *
  71. * Note(s) : (1) The custom library software files are located in the following directories :
  72. *
  73. * (a) \<Your Product Application>\lib_cfg.h
  74. *
  75. * (b) \<Custom Library Directory>\lib_*.*
  76. *
  77. * where
  78. * <Your Product Application> directory path for Your Product's Application
  79. * <Custom Library Directory> directory path for custom library software
  80. *
  81. * (2) CPU-configuration software files are located in the following directories :
  82. *
  83. * (a) \<CPU-Compiler Directory>\cpu_*.*
  84. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  85. *
  86. * where
  87. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  88. * <cpu> directory name for specific processor (CPU)
  89. * <compiler> directory name for specific compiler
  90. *
  91. * (3) Compiler MUST be configured to include as additional include path directories :
  92. *
  93. * (a) '\<Your Product Application>\' directory See Note #1a
  94. *
  95. * (b) '\<Custom Library Directory>\' directory See Note #1b
  96. *
  97. * (c) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  98. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  99. *
  100. * (4) NO compiler-supplied standard library functions SHOULD be used.
  101. *********************************************************************************************************
  102. */
  103. #include <cpu.h>
  104. #include <cpu_core.h>
  105. #include <lib_def.h>
  106. #include <lib_cfg.h>
  107. /*
  108. *********************************************************************************************************
  109. * EXTERNS
  110. *********************************************************************************************************
  111. */
  112. #ifdef LIB_MEM_MODULE
  113. #define LIB_MEM_EXT
  114. #else
  115. #define LIB_MEM_EXT extern
  116. #endif
  117. /*
  118. *********************************************************************************************************
  119. * DEFINES
  120. *********************************************************************************************************
  121. */
  122. #define LIB_MEM_PADDING_ALIGN_NONE 1u
  123. #define LIB_MEM_BLK_QTY_UNLIMITED 0u
  124. /*
  125. *********************************************************************************************************
  126. * DEFAULT CONFIGURATION
  127. *********************************************************************************************************
  128. */
  129. /*
  130. *********************************************************************************************************
  131. * MEMORY LIBRARY ARGUMENT CHECK CONFIGURATION
  132. *
  133. * Note(s) : (1) Configure LIB_MEM_CFG_ARG_CHK_EXT_EN to enable/disable the memory library suite external
  134. * argument check feature :
  135. *
  136. * (a) When ENABLED, arguments received from any port interface provided by the developer
  137. * or application are checked/validated.
  138. *
  139. * (b) When DISABLED, NO arguments received from any port interface provided by the developer
  140. * or application are checked/validated.
  141. *********************************************************************************************************
  142. */
  143. /* Cfg external argument check feature (see Note #1) : */
  144. #ifndef LIB_MEM_CFG_ARG_CHK_EXT_EN
  145. #define LIB_MEM_CFG_ARG_CHK_EXT_EN DEF_DISABLED
  146. /* DEF_DISABLED Argument check DISABLED */
  147. /* DEF_ENABLED Argument check ENABLED */
  148. #endif
  149. /*
  150. *********************************************************************************************************
  151. * MEMORY LIBRARY ASSEMBLY OPTIMIZATION CONFIGURATION
  152. *
  153. * Note(s) : (1) Configure LIB_MEM_CFG_OPTIMIZE_ASM_EN to enable/disable assembly-optimized memory
  154. * functions.
  155. *********************************************************************************************************
  156. */
  157. /* Cfg assembly-optimized function(s) [see Note #1] : */
  158. #ifndef LIB_MEM_CFG_OPTIMIZE_ASM_EN
  159. #define LIB_MEM_CFG_OPTIMIZE_ASM_EN DEF_DISABLED
  160. /* DEF_DISABLED Assembly-optimized fnct(s) DISABLED */
  161. /* DEF_ENABLED Assembly-optimized fnct(s) ENABLED */
  162. #endif
  163. /*
  164. *********************************************************************************************************
  165. * MEMORY ALLOCATION DEBUG INFORMATION CONFIGURATION
  166. *
  167. * Note(s) : (1) Configure LIB_MEM_CFG_DBG_INFO_EN to enable/disable debug information associated to each
  168. * segment allocation.
  169. *********************************************************************************************************
  170. */
  171. #ifndef LIB_MEM_CFG_DBG_INFO_EN
  172. #define LIB_MEM_CFG_DBG_INFO_EN DEF_DISABLED
  173. #endif
  174. /*
  175. *********************************************************************************************************
  176. * HEAP PADDING ALIGN CONFIGURATION
  177. *
  178. * Note(s) : (1) Configure LIB_MEM_CFG_HEAP_PADDING_ALIGN to set the padding alignment of any buffer
  179. * allocated from the heap.
  180. *********************************************************************************************************
  181. */
  182. #ifndef LIB_MEM_CFG_HEAP_PADDING_ALIGN
  183. #define LIB_MEM_CFG_HEAP_PADDING_ALIGN LIB_MEM_PADDING_ALIGN_NONE
  184. #endif
  185. /*
  186. *********************************************************************************************************
  187. * DATA TYPES
  188. *********************************************************************************************************
  189. */
  190. /*
  191. *********************************************************************************************************
  192. * LIB MEM TYPE
  193. *
  194. * Note(s) : (1) 'LIB_MEM_TYPE' declared as 'CPU_INT32U' & all 'LIB_MEM_TYPE's #define'd with large, non-trivial
  195. * values to trap & discard invalid/corrupted library memory objects based on 'LIB_MEM_TYPE'.
  196. *********************************************************************************************************
  197. */
  198. typedef CPU_INT32U LIB_MEM_TYPE;
  199. /*
  200. *********************************************************************************************************
  201. * MEMORY POOL BLOCK QUANTITY DATA TYPE
  202. *********************************************************************************************************
  203. */
  204. typedef CPU_SIZE_T MEM_POOL_BLK_QTY;
  205. /*
  206. *********************************************************************************************************
  207. * MEMORY POOL TABLE IX TYPE
  208. *********************************************************************************************************
  209. */
  210. typedef MEM_POOL_BLK_QTY MEM_POOL_IX;
  211. /*
  212. *********************************************************************************************************
  213. * MEMORY ALLOCATION TRACKING INFO DATA TYPE
  214. *********************************************************************************************************
  215. */
  216. #if (LIB_MEM_CFG_DBG_INFO_EN == DEF_ENABLED)
  217. typedef struct mem_alloc_info MEM_ALLOC_INFO;
  218. struct mem_alloc_info { /* ------------------ MEM ALLOC INFO ------------------ */
  219. const CPU_CHAR *NamePtr; /* Ptr to name. */
  220. CPU_SIZE_T Size; /* Total alloc'd size, in bytes. */
  221. MEM_ALLOC_INFO *NextPtr; /* Ptr to next alloc info in list. */
  222. };
  223. #endif
  224. /*
  225. *********************************************************************************************************
  226. * MEMORY SEGMENTS DATA TYPES
  227. *********************************************************************************************************
  228. */
  229. typedef struct mem_seg MEM_SEG; /* --------------------- SEG DATA --------------------- */
  230. struct mem_seg {
  231. CPU_ADDR AddrBase; /* Seg start addr. */
  232. CPU_ADDR AddrEnd; /* Seg end addr (last addr). */
  233. CPU_ADDR AddrNext; /* Next free addr. */
  234. MEM_SEG *NextPtr; /* Ptr to next seg. */
  235. CPU_SIZE_T PaddingAlign; /* Padding alignment in byte. */
  236. #if (LIB_MEM_CFG_DBG_INFO_EN == DEF_ENABLED)
  237. const CPU_CHAR *NamePtr; /* Ptr to seg name. */
  238. MEM_ALLOC_INFO *AllocInfoHeadPtr; /* Ptr to head of alloc info struct list. */
  239. #endif
  240. };
  241. typedef struct mem_seg_info { /* --------------------- SEG INFO --------------------- */
  242. CPU_SIZE_T UsedSize; /* Allocated seg octets. */
  243. CPU_SIZE_T TotalSize; /* Total seg capacity, in octets. */
  244. CPU_ADDR AddrBase;
  245. CPU_ADDR AddrNextAlloc;
  246. } MEM_SEG_INFO;
  247. /*
  248. *********************************************************************************************************
  249. * (STATIC) MEMORY POOL DATA TYPES
  250. *
  251. * Note(s) : (1) Free static memory pool blocks are indexed in the 'BlkFreeTbl' table. Newly freed blocks
  252. * are added at the first available position in the table and blocks are retrieved from the
  253. * last occupied position, in a LIFO fashion.
  254. *
  255. * /-------------------------------\
  256. * |/------------\ |
  257. * BlkFreeTbl || Start v v End
  258. * /--------\ || /--------------------------------------------\
  259. * |p_free_1|---/| | | | | | |
  260. * |--------| | \--------------------------------------------/
  261. * |p_free_2|----/ ^ | |
  262. * |--------| | |__Blk___|
  263. * |p_free_3|--------/ (Next block to be retrieved.) Size
  264. * |--------|
  265. * | |<-------- (Next block to be freed.)
  266. * \--------/
  267. *
  268. *********************************************************************************************************
  269. */
  270. /* --------------------- MEM POOL --------------------- */
  271. typedef struct mem_pool {
  272. void *PoolAddrStart; /* Ptr to start of mem seg for mem pool blks. */
  273. void *PoolAddrEnd; /* Ptr to end of mem seg for mem pool blks. */
  274. MEM_POOL_BLK_QTY BlkNbr; /* Nbr of mem pool blks. */
  275. CPU_SIZE_T BlkSize; /* Size of mem pool blks (in octets). */
  276. void **BlkFreeTbl; /* Tbl of free mem pool blks. */
  277. CPU_SIZE_T BlkFreeTblIx; /* Ix of next free blk free tbl entry. */
  278. } MEM_POOL;
  279. /*
  280. *********************************************************************************************************
  281. * DYNAMIC MEMORY POOL DATA TYPE
  282. *
  283. * Note(s) : (1) Dynamic memory pool blocks are not indexed in a table. Only freed blocks are linked using
  284. * a singly linked list, in a LIFO fashion; newly freed blocks are inserted at the head of the
  285. * list and blocks are also retrieved from the head of the list.
  286. *
  287. * (2) Pointers to the next block are only present when a block is free, using the first location
  288. * in the allocated memory block. The user of dynamic memory pool must not assume his data
  289. * will not be overwritten when a block is freed.
  290. *
  291. * /----------------\
  292. * /----------\ | /----------\ | /----------\ /----------\
  293. * BlkFreePtr-->|(NextPtr) |---/ | | \--->|(NextPtr) |-->|(NextPtr) |--> DEF_NULL
  294. * |----------| | Blk in | |----------| |----------|
  295. * | | | use | | | | |
  296. * | | | | | | | |
  297. * \----------/ \----------/ \----------/ \----------/
  298. *
  299. *********************************************************************************************************
  300. */
  301. typedef struct mem_dyn_pool { /* ---------------- DYN MEM POOL DATA ----------------- */
  302. MEM_SEG *PoolSegPtr; /* Mem pool from which blks are alloc'd. */
  303. CPU_SIZE_T BlkSize; /* Size of pool blks, in octets. */
  304. CPU_SIZE_T BlkAlign; /* Align req'd for blks, in octets. */
  305. CPU_SIZE_T BlkPaddingAlign; /* Padding alignment in bytes for this mem seg. */
  306. void *BlkFreePtr; /* Ptr to first free blk. */
  307. CPU_SIZE_T BlkQtyMax; /* Max qty of blk in dyn mem pool. 0 = unlimited. */
  308. CPU_SIZE_T BlkAllocCnt; /* Cnt of alloc blk. */
  309. #if (LIB_MEM_CFG_DBG_INFO_EN == DEF_ENABLED)
  310. const CPU_CHAR *NamePtr; /* Ptr to mem pool name. */
  311. #endif
  312. } MEM_DYN_POOL;
  313. /*
  314. *********************************************************************************************************
  315. * GLOBAL VARIABLES
  316. *********************************************************************************************************
  317. */
  318. /*
  319. *********************************************************************************************************
  320. * MACRO'S
  321. *********************************************************************************************************
  322. */
  323. /*
  324. *********************************************************************************************************
  325. * MEMORY DATA VALUE MACRO'S
  326. *
  327. * Note(s) : (1) (a) Some variables & variable buffers to pass & receive data values MUST start on appropriate
  328. * CPU word-aligned addresses. This is required because most word-aligned processors are more
  329. * efficient & may even REQUIRE that multi-octet words start on CPU word-aligned addresses.
  330. *
  331. * (1) For 16-bit word-aligned processors, this means that
  332. *
  333. * all 16- & 32-bit words MUST start on addresses that are multiples of 2 octets
  334. *
  335. * (2) For 32-bit word-aligned processors, this means that
  336. *
  337. * all 16-bit words MUST start on addresses that are multiples of 2 octets
  338. * all 32-bit words MUST start on addresses that are multiples of 4 octets
  339. *
  340. * (b) However, some data values macro's appropriately access data values from any CPU addresses,
  341. * word-aligned or not. Thus for processors that require data word alignment, data words can
  342. * be accessed to/from any CPU address, word-aligned or not, without generating data-word-
  343. * alignment exceptions/faults.
  344. *********************************************************************************************************
  345. */
  346. /*
  347. *********************************************************************************************************
  348. * ENDIAN WORD ORDER MACRO'S
  349. *
  350. * Description : Convert data values to & from big-, little, or host-endian CPU word order.
  351. *
  352. * Argument(s) : val Data value to convert (see Notes #1 & #2).
  353. *
  354. * Return(s) : Converted data value (see Notes #1 & #2).
  355. *
  356. * Caller(s) : Application.
  357. *
  358. * Note(s) : (1) Convert data values to the desired data-word order :
  359. *
  360. * MEM_VAL_BIG_TO_LITTLE_xx() Convert big- endian data values
  361. * to little- endian data values
  362. * MEM_VAL_LITTLE_TO_BIG_xx() Convert little- endian data values
  363. * to big- endian data values
  364. * MEM_VAL_xxx_TO_HOST_xx() Convert big-/little-endian data values
  365. * to host- endian data values
  366. * MEM_VAL_HOST_TO_xxx_xx() Convert host- endian data values
  367. * to big-/little-endian data values
  368. *
  369. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  370. *
  371. * (2) 'val' data value to convert & any variable to receive the returned conversion MUST
  372. * start on appropriate CPU word-aligned addresses.
  373. *
  374. * See also 'MEMORY DATA VALUE MACRO'S Note #1a'.
  375. *
  376. * (3) MEM_VAL_COPY_xxx() macro's are more efficient than generic endian word order macro's &
  377. * are also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  378. *
  379. * See also 'MEM_VAL_COPY_GET_xxx() Note #4'
  380. * & 'MEM_VAL_COPY_SET_xxx() Note #4'.
  381. *
  382. * (4) Generic endian word order macro's are NOT atomic operations & MUST NOT be used on any
  383. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller of
  384. * the macro's providing some form of additional protection (e.g. mutual exclusion).
  385. *
  386. * (5) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  387. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  388. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  389. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  390. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  391. *********************************************************************************************************
  392. */
  393. #if ((CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_64) || \
  394. (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32))
  395. #define MEM_VAL_BIG_TO_LITTLE_16(val) ((CPU_INT16U)(((CPU_INT16U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0xFF00u) >> (1u * DEF_OCTET_NBR_BITS))) | \
  396. ((CPU_INT16U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0x00FFu) << (1u * DEF_OCTET_NBR_BITS)))))
  397. #define MEM_VAL_BIG_TO_LITTLE_32(val) ((CPU_INT32U)(((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0xFF000000u) >> (3u * DEF_OCTET_NBR_BITS))) | \
  398. ((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) >> (1u * DEF_OCTET_NBR_BITS))) | \
  399. ((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) << (1u * DEF_OCTET_NBR_BITS))) | \
  400. ((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x000000FFu) << (3u * DEF_OCTET_NBR_BITS)))))
  401. #elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
  402. #define MEM_VAL_BIG_TO_LITTLE_16(val) ((CPU_INT16U)(((CPU_INT16U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0xFF00u) >> (1u * DEF_OCTET_NBR_BITS))) | \
  403. ((CPU_INT16U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0x00FFu) << (1u * DEF_OCTET_NBR_BITS)))))
  404. #define MEM_VAL_BIG_TO_LITTLE_32(val) ((CPU_INT32U)(((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0xFF000000u) >> (1u * DEF_OCTET_NBR_BITS))) | \
  405. ((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) << (1u * DEF_OCTET_NBR_BITS))) | \
  406. ((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) >> (1u * DEF_OCTET_NBR_BITS))) | \
  407. ((CPU_INT32U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x000000FFu) << (1u * DEF_OCTET_NBR_BITS)))))
  408. #else
  409. #define MEM_VAL_BIG_TO_LITTLE_16(val) (val)
  410. #define MEM_VAL_BIG_TO_LITTLE_32(val) (val)
  411. #endif
  412. #define MEM_VAL_LITTLE_TO_BIG_16(val) MEM_VAL_BIG_TO_LITTLE_16(val)
  413. #define MEM_VAL_LITTLE_TO_BIG_32(val) MEM_VAL_BIG_TO_LITTLE_32(val)
  414. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  415. #define MEM_VAL_BIG_TO_HOST_16(val) (val)
  416. #define MEM_VAL_BIG_TO_HOST_32(val) (val)
  417. #define MEM_VAL_LITTLE_TO_HOST_16(val) MEM_VAL_LITTLE_TO_BIG_16(val)
  418. #define MEM_VAL_LITTLE_TO_HOST_32(val) MEM_VAL_LITTLE_TO_BIG_32(val)
  419. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  420. #define MEM_VAL_BIG_TO_HOST_16(val) MEM_VAL_BIG_TO_LITTLE_16(val)
  421. #define MEM_VAL_BIG_TO_HOST_32(val) MEM_VAL_BIG_TO_LITTLE_32(val)
  422. #define MEM_VAL_LITTLE_TO_HOST_16(val) (val)
  423. #define MEM_VAL_LITTLE_TO_HOST_32(val) (val)
  424. #else /* See Note #5. */
  425. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  426. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  427. #endif
  428. #define MEM_VAL_HOST_TO_BIG_16(val) MEM_VAL_BIG_TO_HOST_16(val)
  429. #define MEM_VAL_HOST_TO_BIG_32(val) MEM_VAL_BIG_TO_HOST_32(val)
  430. #define MEM_VAL_HOST_TO_LITTLE_16(val) MEM_VAL_LITTLE_TO_HOST_16(val)
  431. #define MEM_VAL_HOST_TO_LITTLE_32(val) MEM_VAL_LITTLE_TO_HOST_32(val)
  432. /*
  433. *********************************************************************************************************
  434. * MEM_VAL_GET_xxx()
  435. *
  436. * Description : Decode data values from any CPU memory address.
  437. *
  438. * Argument(s) : addr Lowest CPU memory address of data value to decode (see Notes #2 & #3a).
  439. *
  440. * Return(s) : Decoded data value from CPU memory address (see Notes #1 & #3b).
  441. *
  442. * Caller(s) : Application.
  443. *
  444. * Note(s) : (1) Decode data values based on the values' data-word order in CPU memory :
  445. *
  446. * MEM_VAL_GET_xxx_BIG() Decode big- endian data values -- data words' most
  447. * significant octet @ lowest memory address
  448. * MEM_VAL_GET_xxx_LITTLE() Decode little-endian data values -- data words' least
  449. * significant octet @ lowest memory address
  450. * MEM_VAL_GET_xxx() Decode data values using CPU's native or configured
  451. * data-word order
  452. *
  453. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  454. *
  455. * (2) CPU memory addresses/pointers NOT checked for NULL.
  456. *
  457. * (3) (a) MEM_VAL_GET_xxx() macro's decode data values without regard to CPU word-aligned addresses.
  458. * Thus for processors that require data word alignment, data words can be decoded from any
  459. * CPU address, word-aligned or not, without generating data-word-alignment exceptions/faults.
  460. *
  461. * (b) However, any variable to receive the returned data value MUST start on an appropriate CPU
  462. * word-aligned address.
  463. *
  464. * See also 'MEMORY DATA VALUE MACRO'S Note #1'.
  465. *
  466. * (4) MEM_VAL_COPY_GET_xxx() macro's are more efficient than MEM_VAL_GET_xxx() macro's & are
  467. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  468. *
  469. * See also 'MEM_VAL_COPY_GET_xxx() Note #4'.
  470. *
  471. * (5) MEM_VAL_GET_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-static
  472. * (i.e. volatile) variables, registers, hardware, etc.; without the caller of the macro's
  473. * providing some form of additional protection (e.g. mutual exclusion).
  474. *
  475. * (6) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  476. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  477. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  478. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  479. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  480. *********************************************************************************************************
  481. */
  482. #define MEM_VAL_GET_INT08U_BIG(addr) ((CPU_INT08U) ((CPU_INT08U)(((CPU_INT08U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS))))
  483. #define MEM_VAL_GET_INT16U_BIG(addr) ((CPU_INT16U)(((CPU_INT16U)(((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 0))) << (1u * DEF_OCTET_NBR_BITS))) + \
  484. ((CPU_INT16U)(((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 1))) << (0u * DEF_OCTET_NBR_BITS)))))
  485. #define MEM_VAL_GET_INT32U_BIG(addr) ((CPU_INT32U)(((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 0))) << (3u * DEF_OCTET_NBR_BITS))) + \
  486. ((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 1))) << (2u * DEF_OCTET_NBR_BITS))) + \
  487. ((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 2))) << (1u * DEF_OCTET_NBR_BITS))) + \
  488. ((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 3))) << (0u * DEF_OCTET_NBR_BITS)))))
  489. #define MEM_VAL_GET_INT08U_LITTLE(addr) ((CPU_INT08U) ((CPU_INT08U)(((CPU_INT08U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS))))
  490. #define MEM_VAL_GET_INT16U_LITTLE(addr) ((CPU_INT16U)(((CPU_INT16U)(((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS))) + \
  491. ((CPU_INT16U)(((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 1))) << (1u * DEF_OCTET_NBR_BITS)))))
  492. #define MEM_VAL_GET_INT32U_LITTLE(addr) ((CPU_INT32U)(((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS))) + \
  493. ((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 1))) << (1u * DEF_OCTET_NBR_BITS))) + \
  494. ((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 2))) << (2u * DEF_OCTET_NBR_BITS))) + \
  495. ((CPU_INT32U)(((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 3))) << (3u * DEF_OCTET_NBR_BITS)))))
  496. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  497. #define MEM_VAL_GET_INT08U(addr) MEM_VAL_GET_INT08U_BIG(addr)
  498. #define MEM_VAL_GET_INT16U(addr) MEM_VAL_GET_INT16U_BIG(addr)
  499. #define MEM_VAL_GET_INT32U(addr) MEM_VAL_GET_INT32U_BIG(addr)
  500. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  501. #define MEM_VAL_GET_INT08U(addr) MEM_VAL_GET_INT08U_LITTLE(addr)
  502. #define MEM_VAL_GET_INT16U(addr) MEM_VAL_GET_INT16U_LITTLE(addr)
  503. #define MEM_VAL_GET_INT32U(addr) MEM_VAL_GET_INT32U_LITTLE(addr)
  504. #else /* See Note #6. */
  505. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  506. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  507. #endif
  508. /*
  509. *********************************************************************************************************
  510. * MEM_VAL_SET_xxx()
  511. *
  512. * Description : Encode data values to any CPU memory address.
  513. *
  514. * Argument(s) : addr Lowest CPU memory address to encode data value (see Notes #2 & #3a).
  515. *
  516. * val Data value to encode (see Notes #1 & #3b).
  517. *
  518. * Return(s) : none.
  519. *
  520. * Caller(s) : Application.
  521. *
  522. * Note(s) : (1) Encode data values into CPU memory based on the values' data-word order :
  523. *
  524. * MEM_VAL_SET_xxx_BIG() Encode big- endian data values -- data words' most
  525. * significant octet @ lowest memory address
  526. * MEM_VAL_SET_xxx_LITTLE() Encode little-endian data values -- data words' least
  527. * significant octet @ lowest memory address
  528. * MEM_VAL_SET_xxx() Encode data values using CPU's native or configured
  529. * data-word order
  530. *
  531. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  532. *
  533. * (2) CPU memory addresses/pointers NOT checked for NULL.
  534. *
  535. * (3) (a) MEM_VAL_SET_xxx() macro's encode data values without regard to CPU word-aligned addresses.
  536. * Thus for processors that require data word alignment, data words can be encoded to any
  537. * CPU address, word-aligned or not, without generating data-word-alignment exceptions/faults.
  538. *
  539. * (b) However, 'val' data value to encode MUST start on an appropriate CPU word-aligned address.
  540. *
  541. * See also 'MEMORY DATA VALUE MACRO'S Note #1'.
  542. *
  543. * (4) MEM_VAL_COPY_SET_xxx() macro's are more efficient than MEM_VAL_SET_xxx() macro's & are
  544. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  545. *
  546. * See also 'MEM_VAL_COPY_SET_xxx() Note #4'.
  547. *
  548. * (5) MEM_VAL_SET_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-static
  549. * (i.e. volatile) variables, registers, hardware, etc.; without the caller of the macro's
  550. * providing some form of additional protection (e.g. mutual exclusion).
  551. *
  552. * (6) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  553. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  554. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  555. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  556. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  557. *********************************************************************************************************
  558. */
  559. #define MEM_VAL_SET_INT08U_BIG(addr, val) do { (*(((CPU_INT08U *)(addr)) + 0)) = ((CPU_INT08U)((((CPU_INT08U)(val)) & (CPU_INT08U) 0xFFu) >> (0u * DEF_OCTET_NBR_BITS))); } while (0)
  560. #define MEM_VAL_SET_INT16U_BIG(addr, val) do { (*(((CPU_INT08U *)(addr)) + 0)) = ((CPU_INT08U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0xFF00u) >> (1u * DEF_OCTET_NBR_BITS))); \
  561. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0x00FFu) >> (0u * DEF_OCTET_NBR_BITS))); } while (0)
  562. #define MEM_VAL_SET_INT32U_BIG(addr, val) do { (*(((CPU_INT08U *)(addr)) + 0)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0xFF000000u) >> (3u * DEF_OCTET_NBR_BITS))); \
  563. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) >> (2u * DEF_OCTET_NBR_BITS))); \
  564. (*(((CPU_INT08U *)(addr)) + 2)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) >> (1u * DEF_OCTET_NBR_BITS))); \
  565. (*(((CPU_INT08U *)(addr)) + 3)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x000000FFu) >> (0u * DEF_OCTET_NBR_BITS))); } while (0)
  566. #define MEM_VAL_SET_INT08U_LITTLE(addr, val) do { (*(((CPU_INT08U *)(addr)) + 0)) = ((CPU_INT08U)((((CPU_INT08U)(val)) & (CPU_INT08U) 0xFFu) >> (0u * DEF_OCTET_NBR_BITS))); } while (0)
  567. #define MEM_VAL_SET_INT16U_LITTLE(addr, val) do { (*(((CPU_INT08U *)(addr)) + 0)) = ((CPU_INT08U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0x00FFu) >> (0u * DEF_OCTET_NBR_BITS))); \
  568. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0xFF00u) >> (1u * DEF_OCTET_NBR_BITS))); } while (0)
  569. #define MEM_VAL_SET_INT32U_LITTLE(addr, val) do { (*(((CPU_INT08U *)(addr)) + 0)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x000000FFu) >> (0u * DEF_OCTET_NBR_BITS))); \
  570. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) >> (1u * DEF_OCTET_NBR_BITS))); \
  571. (*(((CPU_INT08U *)(addr)) + 2)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) >> (2u * DEF_OCTET_NBR_BITS))); \
  572. (*(((CPU_INT08U *)(addr)) + 3)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0xFF000000u) >> (3u * DEF_OCTET_NBR_BITS))); } while (0)
  573. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  574. #define MEM_VAL_SET_INT08U(addr, val) MEM_VAL_SET_INT08U_BIG(addr, val)
  575. #define MEM_VAL_SET_INT16U(addr, val) MEM_VAL_SET_INT16U_BIG(addr, val)
  576. #define MEM_VAL_SET_INT32U(addr, val) MEM_VAL_SET_INT32U_BIG(addr, val)
  577. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  578. #define MEM_VAL_SET_INT08U(addr, val) MEM_VAL_SET_INT08U_LITTLE(addr, val)
  579. #define MEM_VAL_SET_INT16U(addr, val) MEM_VAL_SET_INT16U_LITTLE(addr, val)
  580. #define MEM_VAL_SET_INT32U(addr, val) MEM_VAL_SET_INT32U_LITTLE(addr, val)
  581. #else /* See Note #6. */
  582. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  583. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  584. #endif
  585. /*
  586. *********************************************************************************************************
  587. * MEM_VAL_COPY_GET_xxx()
  588. *
  589. * Description : Copy & decode data values from any CPU memory address to any CPU memory address.
  590. *
  591. * Argument(s) : addr_dest Lowest CPU memory address to copy/decode source address's data value
  592. * (see Notes #2 & #3).
  593. *
  594. * addr_src Lowest CPU memory address of data value to copy/decode
  595. * (see Notes #2 & #3).
  596. *
  597. * Return(s) : none.
  598. *
  599. * Caller(s) : Application.
  600. *
  601. * Note(s) : (1) Copy/decode data values based on the values' data-word order :
  602. *
  603. * MEM_VAL_COPY_GET_xxx_BIG() Decode big- endian data values -- data words' most
  604. * significant octet @ lowest memory address
  605. * MEM_VAL_COPY_GET_xxx_LITTLE() Decode little-endian data values -- data words' least
  606. * significant octet @ lowest memory address
  607. * MEM_VAL_COPY_GET_xxx() Decode data values using CPU's native or configured
  608. * data-word order
  609. *
  610. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  611. *
  612. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  613. *
  614. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  615. *
  616. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  617. * "copying ... between objects that overlap ... is undefined".
  618. *
  619. * (3) MEM_VAL_COPY_GET_xxx() macro's copy/decode data values without regard to CPU word-aligned
  620. * addresses. Thus for processors that require data word alignment, data words can be copied/
  621. * decoded to/from any CPU address, word-aligned or not, without generating data-word-alignment
  622. * exceptions/faults.
  623. *
  624. * (4) MEM_VAL_COPY_GET_xxx() macro's are more efficient than MEM_VAL_GET_xxx() macro's & are
  625. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  626. *
  627. * See also 'MEM_VAL_GET_xxx() Note #4'.
  628. *
  629. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_xxx() &
  630. * MEM_VAL_COPY_SET_xxx() macros are inverse, but identical, operations & are provided
  631. * in both forms for semantics & consistency.
  632. *
  633. * See also 'MEM_VAL_COPY_SET_xxx() Note #5'.
  634. *
  635. * (6) MEM_VAL_COPY_GET_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-
  636. * static (i.e. volatile) variables, registers, hardware, etc.; without the caller of the
  637. * macro's providing some form of additional protection (e.g. mutual exclusion).
  638. *
  639. * (7) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  640. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  641. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  642. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  643. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  644. *********************************************************************************************************
  645. */
  646. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  647. #define MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  648. #define MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  649. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); } while (0)
  650. #define MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  651. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  652. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  653. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 3)); } while (0)
  654. #define MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  655. #define MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  656. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  657. #define MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 3)); \
  658. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  659. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  660. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  661. #define MEM_VAL_COPY_GET_INT08U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src)
  662. #define MEM_VAL_COPY_GET_INT16U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src)
  663. #define MEM_VAL_COPY_GET_INT32U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src)
  664. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  665. #define MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  666. #define MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  667. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  668. #define MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 3)); \
  669. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  670. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  671. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  672. #define MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  673. #define MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  674. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); } while (0)
  675. #define MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  676. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  677. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  678. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 3)); } while (0)
  679. #define MEM_VAL_COPY_GET_INT08U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src)
  680. #define MEM_VAL_COPY_GET_INT16U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src)
  681. #define MEM_VAL_COPY_GET_INT32U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src)
  682. #else /* See Note #7. */
  683. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  684. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  685. #endif
  686. /*
  687. *********************************************************************************************************
  688. * MEM_VAL_COPY_GET_INTU_xxx()
  689. *
  690. * Description : Copy & decode data values from any CPU memory address to any CPU memory address for
  691. * any sized data values.
  692. *
  693. * Argument(s) : addr_dest Lowest CPU memory address to copy/decode source address's data value
  694. * (see Notes #2 & #3).
  695. *
  696. * addr_src Lowest CPU memory address of data value to copy/decode
  697. * (see Notes #2 & #3).
  698. *
  699. * val_size Number of data value octets to copy/decode.
  700. *
  701. * Return(s) : none.
  702. *
  703. * Caller(s) : Application.
  704. *
  705. * Note(s) : (1) Copy/decode data values based on the values' data-word order :
  706. *
  707. * MEM_VAL_COPY_GET_INTU_BIG() Decode big- endian data values -- data words' most
  708. * significant octet @ lowest memory address
  709. * MEM_VAL_COPY_GET_INTU_LITTLE() Decode little-endian data values -- data words' least
  710. * significant octet @ lowest memory address
  711. * MEM_VAL_COPY_GET_INTU() Decode data values using CPU's native or configured
  712. * data-word order
  713. *
  714. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  715. *
  716. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  717. *
  718. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  719. *
  720. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  721. * "copying ... between objects that overlap ... is undefined".
  722. *
  723. * (3) MEM_VAL_COPY_GET_INTU_xxx() macro's copy/decode data values without regard to CPU word-
  724. * aligned addresses. Thus for processors that require data word alignment, data words
  725. * can be copied/decoded to/from any CPU address, word-aligned or not, without generating
  726. * data-word-alignment exceptions/faults.
  727. *
  728. * (4) MEM_VAL_COPY_GET_xxx() macro's are more efficient than MEM_VAL_COPY_GET_INTU_xxx()
  729. * macro's & SHOULD be used whenever possible.
  730. *
  731. * See also 'MEM_VAL_COPY_GET_xxx() Note #4'.
  732. *
  733. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_INTU_xxx() &
  734. * MEM_VAL_COPY_SET_INTU_xxx() macros are inverse, but identical, operations & are provided
  735. * in both forms for semantics & consistency.
  736. *
  737. * See also 'MEM_VAL_COPY_SET_INTU_xxx() Note #5'.
  738. *
  739. * (6) MEM_VAL_COPY_GET_INTU_xxx() macro's are NOT atomic operations & MUST NOT be used on any
  740. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller of
  741. * the macro's providing some form of additional protection (e.g. mutual exclusion).
  742. *
  743. * (7) MISRA-C 2004 Rule 5.2 states that "identifiers in an inner scope shall not use the same
  744. * name as an indentifier in an outer scope, and therefore hide that identifier".
  745. *
  746. * Therefore, to avoid possible redeclaration of commonly-used loop counter identifier names,
  747. * 'i' & 'j', MEM_VAL_COPY_GET_INTU_xxx() loop counter identifier names are prefixed with a
  748. * single underscore.
  749. *
  750. * (8) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  751. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  752. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  753. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  754. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  755. *********************************************************************************************************
  756. */
  757. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  758. #define MEM_VAL_COPY_GET_INTU_BIG(addr_dest, addr_src, val_size) do { \
  759. CPU_SIZE_T _i; \
  760. \
  761. for (_i = 0; _i < (val_size); _i++) { \
  762. (*(((CPU_INT08U *)(addr_dest)) + _i)) = (*(((CPU_INT08U *)(addr_src)) + _i)); \
  763. } \
  764. } while (0)
  765. #define MEM_VAL_COPY_GET_INTU_LITTLE(addr_dest, addr_src, val_size) do { \
  766. CPU_SIZE_T _i; \
  767. CPU_SIZE_T _j; \
  768. \
  769. \
  770. _j = (val_size) - 1; \
  771. \
  772. for (_i = 0; _i < (val_size); _i++) { \
  773. (*(((CPU_INT08U *)(addr_dest)) + _i)) = (*(((CPU_INT08U *)(addr_src)) + _j)); \
  774. _j--; \
  775. } \
  776. } while (0)
  777. #define MEM_VAL_COPY_GET_INTU(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU_BIG(addr_dest, addr_src, val_size)
  778. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  779. #define MEM_VAL_COPY_GET_INTU_BIG(addr_dest, addr_src, val_size) do { \
  780. CPU_SIZE_T _i; \
  781. CPU_SIZE_T _j; \
  782. \
  783. \
  784. _j = (val_size) - 1; \
  785. \
  786. for (_i = 0; _i < (val_size); _i++) { \
  787. (*(((CPU_INT08U *)(addr_dest)) + _i)) = (*(((CPU_INT08U *)(addr_src)) + _j)); \
  788. _j--; \
  789. } \
  790. } while (0)
  791. #define MEM_VAL_COPY_GET_INTU_LITTLE(addr_dest, addr_src, val_size) do { \
  792. CPU_SIZE_T _i; \
  793. \
  794. for (_i = 0; _i < (val_size); _i++) { \
  795. (*(((CPU_INT08U *)(addr_dest)) + _i)) = (*(((CPU_INT08U *)(addr_src)) + _i)); \
  796. } \
  797. } while (0)
  798. #define MEM_VAL_COPY_GET_INTU(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU_LITTLE(addr_dest, addr_src, val_size)
  799. #else /* See Note #8. */
  800. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  801. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  802. #endif
  803. /*
  804. *********************************************************************************************************
  805. * MEM_VAL_COPY_SET_xxx()
  806. *
  807. * Description : Copy & encode data values from any CPU memory address to any CPU memory address.
  808. *
  809. * Argument(s) : addr_dest Lowest CPU memory address to copy/encode source address's data value
  810. * (see Notes #2 & #3).
  811. *
  812. * addr_src Lowest CPU memory address of data value to copy/encode
  813. * (see Notes #2 & #3).
  814. *
  815. * Return(s) : none.
  816. *
  817. * Caller(s) : Application.
  818. *
  819. * Note(s) : (1) Copy/encode data values based on the values' data-word order :
  820. *
  821. * MEM_VAL_COPY_SET_xxx_BIG() Encode big- endian data values -- data words' most
  822. * significant octet @ lowest memory address
  823. * MEM_VAL_COPY_SET_xxx_LITTLE() Encode little-endian data values -- data words' least
  824. * significant octet @ lowest memory address
  825. * MEM_VAL_COPY_SET_xxx() Encode data values using CPU's native or configured
  826. * data-word order
  827. *
  828. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  829. *
  830. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  831. *
  832. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  833. *
  834. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  835. * "copying ... between objects that overlap ... is undefined".
  836. *
  837. * (3) MEM_VAL_COPY_SET_xxx() macro's copy/encode data values without regard to CPU word-aligned
  838. * addresses. Thus for processors that require data word alignment, data words can be copied/
  839. * encoded to/from any CPU address, word-aligned or not, without generating data-word-alignment
  840. * exceptions/faults.
  841. *
  842. * (4) MEM_VAL_COPY_SET_xxx() macro's are more efficient than MEM_VAL_SET_xxx() macro's & are
  843. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  844. *
  845. * See also 'MEM_VAL_SET_xxx() Note #4'.
  846. *
  847. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_xxx() &
  848. * MEM_VAL_COPY_SET_xxx() macros are inverse, but identical, operations & are provided
  849. * in both forms for semantics & consistency.
  850. *
  851. * See also 'MEM_VAL_COPY_GET_xxx() Note #5'.
  852. *
  853. * (6) MEM_VAL_COPY_SET_xxx() macro's are NOT atomic operations & MUST NOT be used on any
  854. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller
  855. * of the macro's providing some form of additional protection (e.g. mutual exclusion).
  856. *********************************************************************************************************
  857. */
  858. /* See Note #5. */
  859. #define MEM_VAL_COPY_SET_INT08U_BIG(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src)
  860. #define MEM_VAL_COPY_SET_INT16U_BIG(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src)
  861. #define MEM_VAL_COPY_SET_INT32U_BIG(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src)
  862. #define MEM_VAL_COPY_SET_INT08U_LITTLE(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src)
  863. #define MEM_VAL_COPY_SET_INT16U_LITTLE(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src)
  864. #define MEM_VAL_COPY_SET_INT32U_LITTLE(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src)
  865. #define MEM_VAL_COPY_SET_INT08U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U(addr_dest, addr_src)
  866. #define MEM_VAL_COPY_SET_INT16U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U(addr_dest, addr_src)
  867. #define MEM_VAL_COPY_SET_INT32U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U(addr_dest, addr_src)
  868. /*
  869. *********************************************************************************************************
  870. * MEM_VAL_COPY_SET_INTU_xxx()
  871. *
  872. * Description : Copy & encode data values from any CPU memory address to any CPU memory address for
  873. * any sized data values.
  874. *
  875. * Argument(s) : addr_dest Lowest CPU memory address to copy/encode source address's data value
  876. * (see Notes #2 & #3).
  877. *
  878. * addr_src Lowest CPU memory address of data value to copy/encode
  879. * (see Notes #2 & #3).
  880. *
  881. * val_size Number of data value octets to copy/encode.
  882. *
  883. * Return(s) : none.
  884. *
  885. * Caller(s) : Application.
  886. *
  887. * Note(s) : (1) Copy/encode data values based on the values' data-word order :
  888. *
  889. * MEM_VAL_COPY_SET_INTU_BIG() Encode big- endian data values -- data words' most
  890. * significant octet @ lowest memory address
  891. * MEM_VAL_COPY_SET_INTU_LITTLE() Encode little-endian data values -- data words' least
  892. * significant octet @ lowest memory address
  893. * MEM_VAL_COPY_SET_INTU() Encode data values using CPU's native or configured
  894. * data-word order
  895. *
  896. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  897. *
  898. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  899. *
  900. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  901. *
  902. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  903. * "copying ... between objects that overlap ... is undefined".
  904. *
  905. * (3) MEM_VAL_COPY_SET_INTU_xxx() macro's copy/encode data values without regard to CPU word-
  906. * aligned addresses. Thus for processors that require data word alignment, data words
  907. * can be copied/encoded to/from any CPU address, word-aligned or not, without generating
  908. * data-word-alignment exceptions/faults.
  909. *
  910. * (4) MEM_VAL_COPY_SET_xxx() macro's are more efficient than MEM_VAL_COPY_SET_INTU_xxx()
  911. * macro's & SHOULD be used whenever possible.
  912. *
  913. * See also 'MEM_VAL_COPY_SET_xxx() Note #4'.
  914. *
  915. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_INTU_xxx() &
  916. * MEM_VAL_COPY_SET_INTU_xxx() macros are inverse, but identical, operations & are provided
  917. * in both forms for semantics & consistency.
  918. *
  919. * See also 'MEM_VAL_COPY_GET_INTU_xxx() Note #5'.
  920. *
  921. * (6) MEM_VAL_COPY_SET_INTU_xxx() macro's are NOT atomic operations & MUST NOT be used on any
  922. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller of
  923. * the macro's providing some form of additional protection (e.g. mutual exclusion).
  924. *********************************************************************************************************
  925. */
  926. /* See Note #5. */
  927. #define MEM_VAL_COPY_SET_INTU_BIG(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU_BIG(addr_dest, addr_src, val_size)
  928. #define MEM_VAL_COPY_SET_INTU_LITTLE(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU_LITTLE(addr_dest, addr_src, val_size)
  929. #define MEM_VAL_COPY_SET_INTU(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU(addr_dest, addr_src, val_size)
  930. /*
  931. *********************************************************************************************************
  932. * MEM_VAL_COPY_xxx()
  933. *
  934. * Description : Copy data values from any CPU memory address to any CPU memory address.
  935. *
  936. * Argument(s) : addr_dest Lowest CPU memory address to copy source address's data value
  937. * (see Notes #2 & #3).
  938. *
  939. * addr_src Lowest CPU memory address of data value to copy
  940. * (see Notes #2 & #3).
  941. *
  942. * val_size Number of data value octets to copy.
  943. *
  944. * Return(s) : none.
  945. *
  946. * Caller(s) : Application.
  947. *
  948. * Note(s) : (1) MEM_VAL_COPY_xxx() macro's copy data values based on CPU's native data-word order.
  949. *
  950. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  951. *
  952. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  953. *
  954. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  955. *
  956. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  957. * "copying ... between objects that overlap ... is undefined".
  958. *
  959. * (3) MEM_VAL_COPY_xxx() macro's copy data values without regard to CPU word-aligned addresses.
  960. * Thus for processors that require data word alignment, data words can be copied to/from any
  961. * CPU address, word-aligned or not, without generating data-word-alignment exceptions/faults.
  962. *
  963. * (4) MEM_VAL_COPY_xxx() macro's are more efficient than MEM_VAL_COPY() macro & SHOULD be
  964. * used whenever possible.
  965. *
  966. * (5) MEM_VAL_COPY_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-static
  967. * (i.e. volatile) variables, registers, hardware, etc.; without the caller of the macro's
  968. * providing some form of additional protection (e.g. mutual exclusion).
  969. *
  970. * (6) MISRA-C 2004 Rule 5.2 states that "identifiers in an inner scope shall not use the same
  971. * name as an indentifier in an outer scope, and therefore hide that identifier".
  972. *
  973. * Therefore, to avoid possible redeclaration of commonly-used loop counter identifier name,
  974. * 'i', MEM_VAL_COPY() loop counter identifier name is prefixed with a single underscore.
  975. *********************************************************************************************************
  976. */
  977. #define MEM_VAL_COPY_08(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  978. #define MEM_VAL_COPY_16(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  979. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); } while (0)
  980. #define MEM_VAL_COPY_32(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  981. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  982. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  983. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 3)); } while (0)
  984. #define MEM_VAL_COPY(addr_dest, addr_src, val_size) do { \
  985. CPU_SIZE_T _i; \
  986. \
  987. for (_i = 0; _i < (val_size); _i++) { \
  988. (*(((CPU_INT08U *)(addr_dest)) +_i)) = (*(((CPU_INT08U *)(addr_src)) +_i)); \
  989. } \
  990. } while (0)
  991. /*
  992. *********************************************************************************************************
  993. * FUNCTION PROTOTYPES
  994. *********************************************************************************************************
  995. */
  996. void Mem_Init ( void);
  997. /* ------------------ MEM API FNCTS ------------------ */
  998. void Mem_Clr ( void *pmem,
  999. CPU_SIZE_T size);
  1000. void Mem_Set ( void *pmem,
  1001. CPU_INT08U data_val,
  1002. CPU_SIZE_T size);
  1003. void Mem_Copy ( void *pdest,
  1004. const void *psrc,
  1005. CPU_SIZE_T size);
  1006. void Mem_Move ( void *pdest,
  1007. const void *psrc,
  1008. CPU_SIZE_T size);
  1009. CPU_BOOLEAN Mem_Cmp (const void *p1_mem,
  1010. const void *p2_mem,
  1011. CPU_SIZE_T size);
  1012. /* ----------- MEM HEAP FNCTS (DEPRECATED) ------------ */
  1013. #if (LIB_MEM_CFG_HEAP_SIZE > 0u)
  1014. void *Mem_HeapAlloc ( CPU_SIZE_T size,
  1015. CPU_SIZE_T align,
  1016. CPU_SIZE_T *p_bytes_reqd,
  1017. LIB_ERR *p_err);
  1018. CPU_SIZE_T Mem_HeapGetSizeRem ( CPU_SIZE_T align,
  1019. LIB_ERR *p_err);
  1020. #endif
  1021. /* ------------------ MEM SEG FNCTS ------------------- */
  1022. void Mem_SegCreate (const CPU_CHAR *p_name,
  1023. MEM_SEG *p_seg,
  1024. CPU_ADDR seg_base_addr,
  1025. CPU_SIZE_T size,
  1026. CPU_SIZE_T padding_align,
  1027. LIB_ERR *p_err);
  1028. void Mem_SegClr ( MEM_SEG *p_seg,
  1029. LIB_ERR *p_err);
  1030. void *Mem_SegAlloc (const CPU_CHAR *p_name,
  1031. MEM_SEG *p_seg,
  1032. CPU_SIZE_T size,
  1033. LIB_ERR *p_err);
  1034. void *Mem_SegAllocExt (const CPU_CHAR *p_name,
  1035. MEM_SEG *p_seg,
  1036. CPU_SIZE_T size,
  1037. CPU_SIZE_T align,
  1038. CPU_SIZE_T *p_bytes_reqd,
  1039. LIB_ERR *p_err);
  1040. void *Mem_SegAllocHW (const CPU_CHAR *p_name,
  1041. MEM_SEG *p_seg,
  1042. CPU_SIZE_T size,
  1043. CPU_SIZE_T align,
  1044. CPU_SIZE_T *p_bytes_reqd,
  1045. LIB_ERR *p_err);
  1046. CPU_SIZE_T Mem_SegRemSizeGet ( MEM_SEG *p_seg,
  1047. CPU_SIZE_T align,
  1048. MEM_SEG_INFO *p_seg_info,
  1049. LIB_ERR *p_err);
  1050. #if (LIB_MEM_CFG_DBG_INFO_EN == DEF_ENABLED)
  1051. void Mem_OutputUsage ( void (*out_fnct) (CPU_CHAR *),
  1052. LIB_ERR *p_err);
  1053. #endif
  1054. /* -------- STATIC MEM POOL FNCTS (DEPRECATED) -------- */
  1055. void Mem_PoolCreate ( MEM_POOL *p_pool,
  1056. void *p_mem_base,
  1057. CPU_SIZE_T mem_size,
  1058. MEM_POOL_BLK_QTY blk_nbr,
  1059. CPU_SIZE_T blk_size,
  1060. CPU_SIZE_T blk_align,
  1061. CPU_SIZE_T *p_bytes_reqd,
  1062. LIB_ERR *p_err);
  1063. void Mem_PoolClr ( MEM_POOL *p_pool,
  1064. LIB_ERR *p_err);
  1065. void *Mem_PoolBlkGet ( MEM_POOL *p_pool,
  1066. CPU_SIZE_T size,
  1067. LIB_ERR *p_err);
  1068. void Mem_PoolBlkFree ( MEM_POOL *p_pool,
  1069. void *p_blk,
  1070. LIB_ERR *p_err);
  1071. MEM_POOL_BLK_QTY Mem_PoolBlkGetNbrAvail ( MEM_POOL *p_pool,
  1072. LIB_ERR *p_err);
  1073. /* -------------- DYNAMIC MEM POOL FNCTS -------------- */
  1074. void Mem_DynPoolCreate (const CPU_CHAR *p_name,
  1075. MEM_DYN_POOL *p_pool,
  1076. MEM_SEG *p_seg,
  1077. CPU_SIZE_T blk_size,
  1078. CPU_SIZE_T blk_align,
  1079. CPU_SIZE_T blk_qty_init,
  1080. CPU_SIZE_T blk_qty_max,
  1081. LIB_ERR *p_err);
  1082. void Mem_DynPoolCreateHW (const CPU_CHAR *p_name,
  1083. MEM_DYN_POOL *p_pool,
  1084. MEM_SEG *p_seg,
  1085. CPU_SIZE_T blk_size,
  1086. CPU_SIZE_T blk_align,
  1087. CPU_SIZE_T blk_qty_init,
  1088. CPU_SIZE_T blk_qty_max,
  1089. LIB_ERR *p_err);
  1090. void *Mem_DynPoolBlkGet ( MEM_DYN_POOL *p_pool,
  1091. LIB_ERR *p_err);
  1092. void Mem_DynPoolBlkFree ( MEM_DYN_POOL *p_pool,
  1093. void *p_blk,
  1094. LIB_ERR *p_err);
  1095. CPU_SIZE_T Mem_DynPoolBlkNbrAvailGet( MEM_DYN_POOL *p_pool,
  1096. LIB_ERR *p_err);
  1097. /*
  1098. *********************************************************************************************************
  1099. * CONFIGURATION ERRORS
  1100. *********************************************************************************************************
  1101. */
  1102. #ifndef LIB_MEM_CFG_ARG_CHK_EXT_EN
  1103. #error "LIB_MEM_CFG_ARG_CHK_EXT_EN not #define'd in 'lib_cfg.h'"
  1104. #error " [MUST be DEF_DISABLED] "
  1105. #error " [ || DEF_ENABLED ] "
  1106. #elif ((LIB_MEM_CFG_ARG_CHK_EXT_EN != DEF_DISABLED) && \
  1107. (LIB_MEM_CFG_ARG_CHK_EXT_EN != DEF_ENABLED ))
  1108. #error "LIB_MEM_CFG_ARG_CHK_EXT_EN illegally #define'd in 'lib_cfg.h'"
  1109. #error " [MUST be DEF_DISABLED] "
  1110. #error " [ || DEF_ENABLED ] "
  1111. #endif
  1112. #ifndef LIB_MEM_CFG_OPTIMIZE_ASM_EN
  1113. #error "LIB_MEM_CFG_OPTIMIZE_ASM_EN not #define'd in 'lib_cfg.h'"
  1114. #error " [MUST be DEF_DISABLED] "
  1115. #error " [ || DEF_ENABLED ] "
  1116. #elif ((LIB_MEM_CFG_OPTIMIZE_ASM_EN != DEF_DISABLED) && \
  1117. (LIB_MEM_CFG_OPTIMIZE_ASM_EN != DEF_ENABLED ))
  1118. #error "LIB_MEM_CFG_OPTIMIZE_ASM_EN illegally #define'd in 'lib_cfg.h'"
  1119. #error " [MUST be DEF_DISABLED] "
  1120. #error " [ || DEF_ENABLED ] "
  1121. #endif
  1122. #ifndef LIB_MEM_CFG_HEAP_SIZE
  1123. #error "LIB_MEM_CFG_HEAP_SIZE not #define'd in 'lib_cfg.h'"
  1124. #error " [MUST be >= 0] "
  1125. #endif
  1126. #ifdef LIB_MEM_CFG_HEAP_BASE_ADDR
  1127. #if (LIB_MEM_CFG_HEAP_BASE_ADDR == 0x0)
  1128. #error "LIB_MEM_CFG_HEAP_BASE_ADDR illegally #define'd in 'lib_cfg.h'"
  1129. #error " [MUST be > 0x0] "
  1130. #endif
  1131. #endif
  1132. #if ((LIB_MEM_CFG_DBG_INFO_EN != DEF_DISABLED) && \
  1133. (LIB_MEM_CFG_DBG_INFO_EN != DEF_ENABLED ))
  1134. #error "LIB_MEM_CFG_DBG_INFO_EN illegally defined in 'lib_cfg.h'"
  1135. #error " [MUST be DEF_DISABLED] "
  1136. #error " [ || DEF_ENABLED ] "
  1137. #elif ((LIB_MEM_CFG_HEAP_SIZE == 0u) && \
  1138. (LIB_MEM_CFG_DBG_INFO_EN == DEF_ENABLED))
  1139. #error "LIB_MEM_CFG_HEAP_SIZE illegally defined in 'lib_cfg.h' "
  1140. #error " [MUST be > 0 when LIB_MEM_CFG_DBG_INFO_EN == DEF_ENABLED]"
  1141. #endif
  1142. /*
  1143. *********************************************************************************************************
  1144. * LIBRARY CONFIGURATION ERRORS
  1145. *********************************************************************************************************
  1146. */
  1147. /* See 'lib_mem.h Note #2a'. */
  1148. #if (CPU_CORE_VERSION < 127u)
  1149. #error "CPU_CORE_VERSION [SHOULD be >= V1.27]"
  1150. #endif
  1151. /*
  1152. *********************************************************************************************************
  1153. * MODULE END
  1154. *
  1155. * Note(s) : (1) See 'lib_mem.h MODULE'.
  1156. *********************************************************************************************************
  1157. */
  1158. #endif /* End of lib mem module include. */