lib_mem.h 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. /*
  2. *********************************************************************************************************
  3. * uC/LIB
  4. * CUSTOM LIBRARY MODULES
  5. *
  6. * (c) Copyright 2004-2011; 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 contact us at www.micrium.com.
  19. *********************************************************************************************************
  20. */
  21. /*
  22. *********************************************************************************************************
  23. *
  24. * STANDARD MEMORY OPERATIONS
  25. *
  26. * Filename : lib_mem.h
  27. * Version : V1.35.00
  28. * Programmer(s) : ITJ
  29. *********************************************************************************************************
  30. * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
  31. *
  32. * (a) ALL standard library functions are implemented in the custom library modules :
  33. *
  34. * (1) \<Custom Library Directory>\lib_*.*
  35. *
  36. * (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
  37. *
  38. * where
  39. * <Custom Library Directory> directory path for custom library software
  40. * <cpu> directory name for specific processor (CPU)
  41. * <compiler> directory name for specific compiler
  42. *
  43. * (b) Product-specific library functions are implemented in individual products.
  44. *
  45. * (2) Assumes the following versions (or more recent) of software modules are included in
  46. * the project build :
  47. *
  48. * (a) uC/CPU V1.27
  49. *********************************************************************************************************
  50. */
  51. /*
  52. *********************************************************************************************************
  53. * MODULE
  54. *
  55. * Note(s) : (1) This memory library header file is protected from multiple pre-processor inclusion through
  56. * use of the memory library module present pre-processor macro definition.
  57. *********************************************************************************************************
  58. */
  59. #ifndef LIB_MEM_MODULE_PRESENT /* See Note #1. */
  60. #define LIB_MEM_MODULE_PRESENT
  61. /*$PAGE*/
  62. /*
  63. *********************************************************************************************************
  64. * INCLUDE FILES
  65. *
  66. * Note(s) : (1) The custom library software files are located in the following directories :
  67. *
  68. * (a) \<Your Product Application>\app_cfg.h
  69. *
  70. * (b) \<Custom Library Directory>\lib_*.*
  71. *
  72. * where
  73. * <Your Product Application> directory path for Your Product's Application
  74. * <Custom Library Directory> directory path for custom library software
  75. *
  76. * (2) CPU-configuration software files are located in the following directories :
  77. *
  78. * (a) \<CPU-Compiler Directory>\cpu_*.*
  79. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  80. *
  81. * where
  82. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  83. * <cpu> directory name for specific processor (CPU)
  84. * <compiler> directory name for specific compiler
  85. *
  86. * (3) Compiler MUST be configured to include as additional include path directories :
  87. *
  88. * (a) '\<Your Product Application>\' directory See Note #1a
  89. *
  90. * (b) '\<Custom Library Directory>\' directory See Note #1b
  91. *
  92. * (c) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  93. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  94. *
  95. * (4) NO compiler-supplied standard library functions SHOULD be used.
  96. *********************************************************************************************************
  97. */
  98. #include <cpu.h>
  99. #include <cpu_core.h>
  100. #include <lib_def.h>
  101. #include <app_cfg.h>
  102. /*
  103. *********************************************************************************************************
  104. * EXTERNS
  105. *********************************************************************************************************
  106. */
  107. #ifdef LIB_MEM_MODULE
  108. #define LIB_MEM_EXT
  109. #else
  110. #define LIB_MEM_EXT extern
  111. #endif
  112. /*$PAGE*/
  113. /*
  114. *********************************************************************************************************
  115. * DEFAULT CONFIGURATION
  116. *********************************************************************************************************
  117. */
  118. /*
  119. *********************************************************************************************************
  120. * MEMORY LIBRARY ARGUMENT CHECK CONFIGURATION
  121. *
  122. * Note(s) : (1) Configure LIB_MEM_CFG_ARG_CHK_EXT_EN to enable/disable the memory library suite external
  123. * argument check feature :
  124. *
  125. * (a) When ENABLED, arguments received from any port interface provided by the developer
  126. * or application are checked/validated.
  127. *
  128. * (b) When DISABLED, NO arguments received from any port interface provided by the developer
  129. * or application are checked/validated.
  130. *********************************************************************************************************
  131. */
  132. /* Configure external argument check feature (see Note #1) : */
  133. #ifndef LIB_MEM_CFG_ARG_CHK_EXT_EN
  134. #define LIB_MEM_CFG_ARG_CHK_EXT_EN DEF_DISABLED
  135. /* DEF_DISABLED Argument check DISABLED */
  136. /* DEF_ENABLED Argument check ENABLED */
  137. #endif
  138. /*
  139. *********************************************************************************************************
  140. * MEMORY LIBRARY ASSEMBLY OPTIMIZATION CONFIGURATION
  141. *
  142. * Note(s) : (1) Configure LIB_MEM_CFG_OPTIMIZE_ASM_EN to enable/disable assembly-optimized memory functions.
  143. *********************************************************************************************************
  144. */
  145. /* Configure assembly-optimized function(s) [see Note #1] : */
  146. #ifndef LIB_MEM_CFG_OPTIMIZE_ASM_EN
  147. #define LIB_MEM_CFG_OPTIMIZE_ASM_EN DEF_DISABLED
  148. /* DEF_DISABLED Assembly-optimized function(s) DISABLED */
  149. /* DEF_ENABLED Assembly-optimized function(s) ENABLED */
  150. #endif
  151. /*
  152. *********************************************************************************************************
  153. * MEMORY ALLOCATION CONFIGURATION
  154. *
  155. * Note(s) : (1) Configure LIB_MEM_CFG_ALLOC_EN to enable/disable memory allocation functions.
  156. *********************************************************************************************************
  157. */
  158. /* Configure memory allocation feature (see Note #1) : */
  159. #ifndef LIB_MEM_CFG_ALLOC_EN
  160. #define LIB_MEM_CFG_ALLOC_EN DEF_DISABLED
  161. /* DEF_DISABLED Memory allocation DISABLED */
  162. /* DEF_ENABLED Memory allocation ENABLED */
  163. #endif
  164. /*$PAGE*/
  165. /*
  166. *********************************************************************************************************
  167. * DEFINES
  168. *********************************************************************************************************
  169. */
  170. /*
  171. *********************************************************************************************************
  172. * LIBRARY MEMORY ERROR CODES
  173. *********************************************************************************************************
  174. */
  175. #define LIB_MEM_ERR_NONE 10000u
  176. #define LIB_MEM_ERR_NULL_PTR 10001u /* Ptr arg(s) passed NULL ptr(s). */
  177. #define LIB_MEM_ERR_INVALID_MEM_SIZE 10100u /* Invalid mem size. */
  178. #define LIB_MEM_ERR_INVALID_MEM_ALIGN 10101u /* Invalid mem align. */
  179. #define LIB_MEM_ERR_INVALID_SEG_SIZE 10110u /* Invalid mem seg size. */
  180. #define LIB_MEM_ERR_INVALID_SEG_OVERLAP 10111u /* Invalid mem seg overlaps other mem seg(s). */
  181. #define LIB_MEM_ERR_INVALID_POOL 10120u /* Invalid mem pool. */
  182. #define LIB_MEM_ERR_INVALID_BLK_NBR 10130u /* Invalid mem pool blk nbr. */
  183. #define LIB_MEM_ERR_INVALID_BLK_SIZE 10131u /* Invalid mem pool blk size. */
  184. #define LIB_MEM_ERR_INVALID_BLK_ALIGN 10132u /* Invalid mem pool blk align. */
  185. #define LIB_MEM_ERR_INVALID_BLK_IX 10133u /* Invalid mem pool ix. */
  186. #define LIB_MEM_ERR_INVALID_BLK_ADDR 10135u /* Invalid mem pool blk addr. */
  187. #define LIB_MEM_ERR_INVALID_BLK_ADDR_IN_POOL 10136u /* Mem pool blk addr already in mem pool. */
  188. #define LIB_MEM_ERR_SEG_EMPTY 10200u /* Mem seg empty; i.e. NO avail mem in seg. */
  189. #define LIB_MEM_ERR_SEG_OVF 10201u /* Mem seg ovf; i.e. req'd mem ovfs rem mem in seg. */
  190. #define LIB_MEM_ERR_POOL_FULL 10205u /* Mem pool full; i.e. all mem blks avail in mem pool. */
  191. #define LIB_MEM_ERR_POOL_EMPTY 10206u /* Mem pool empty; i.e. NO mem blks avail in mem pool. */
  192. #define LIB_MEM_ERR_HEAP_NOT_FOUND 10210u /* Heap seg NOT found. */
  193. #define LIB_MEM_ERR_HEAP_EMPTY 10211u /* Heap seg empty; i.e. NO avail mem in heap. */
  194. #define LIB_MEM_ERR_HEAP_OVF 10212u /* Heap seg ovf; i.e. req'd mem ovfs rem mem in heap. */
  195. /*
  196. *********************************************************************************************************
  197. * MEMORY LIBRARY TYPE DEFINES
  198. *
  199. * Note(s) : (1) LIB_MEM_TYPE_&&& #define values specifically chosen as ASCII representations of the memory
  200. * library types. Memory displays of memory library objects will display the library TYPEs
  201. * with their chosen ASCII names.
  202. *********************************************************************************************************
  203. */
  204. #define LIB_MEM_TYPE_NONE CPU_TYPE_CREATE('N', 'O', 'N', 'E')
  205. #define LIB_MEM_TYPE_HEAP CPU_TYPE_CREATE('H', 'E', 'A', 'P')
  206. #define LIB_MEM_TYPE_POOL CPU_TYPE_CREATE('P', 'O', 'O', 'L')
  207. /*$PAGE*/
  208. /*
  209. *********************************************************************************************************
  210. * DATA TYPES
  211. *********************************************************************************************************
  212. */
  213. /*
  214. *********************************************************************************************************
  215. * LIB MEM TYPE
  216. *
  217. * Note(s) : (1) 'LIB_MEM_TYPE' declared as 'CPU_INT32U' & all 'LIB_MEM_TYPE's #define'd with large, non-trivial
  218. * values to trap & discard invalid/corrupted library memory objects based on 'LIB_MEM_TYPE'.
  219. *********************************************************************************************************
  220. */
  221. typedef CPU_INT32U LIB_MEM_TYPE;
  222. /*
  223. *********************************************************************************************************
  224. * MEMORY POOL TABLE IX TYPE
  225. *
  226. * Note(s) : (1) MEM_POOL_IX_NONE SHOULD be #define'd based on 'MEM_POOL_IX' data type declared.
  227. *********************************************************************************************************
  228. */
  229. typedef CPU_INT16U MEM_POOL_IX;
  230. #define MEM_POOL_IX_NONE DEF_INT_16U_MAX_VAL /* Define as max unsigned val (see Note #1). */
  231. #define MEM_POOL_IX_MIN 1u
  232. #define MEM_POOL_IX_MAX (MEM_POOL_IX_NONE - 1u)
  233. /*$PAGE*/
  234. /*
  235. *********************************************************************************************************
  236. * MEMORY POOL DATA TYPES
  237. *
  238. * MEMORY SEGMENT
  239. * ----------------
  240. * MEMORY POOL'S | | <----
  241. * POINTERS TO | MEMORY | |
  242. * MEM_POOL MEMORY BLOCKS | BLOCKS | |
  243. * |----------------| |---------| | -------- | |
  244. * | O------------------> | O--------------------> | | | |
  245. * |----------------| |---------| | | | | |
  246. * | Pool Addr Ptrs | | O------------- | -------- | |
  247. * | Pool Size | |---------| | | | |
  248. * |----------------| | | | | -------- | |
  249. * | Blk Size | | | --------> | | | |
  250. * | Blk Nbr | | | | | | | |
  251. * | Blk Ix | | . | | -------- | |
  252. * |----------------| | . | | | |
  253. * |----------------| | . | | . | |
  254. * | O----------------- | | | . | |
  255. * |----------------| | | | | . | |
  256. * | O------------ | | | | | |
  257. * |----------------| | | |---------| | -------- | |
  258. * | Seg Size Tot | | | | O--------------------> | | | |
  259. * | Seg Size Rem | | | |---------| | | | | |
  260. * |----------------| | | | | | -------- | |
  261. * | Seg List Ptrs | | | |---------| | | |
  262. * |----------------| | | | ------------ | |
  263. * | | | | <--------
  264. * | | | | | |
  265. * | | | | | |
  266. * | | | | | |
  267. * | | | | | |
  268. * | | | | | |
  269. * | | ---------------- | |
  270. * | | | |
  271. * | -------------------------------------------------- |
  272. * | |
  273. * -----------------------------------------------------------
  274. *
  275. *********************************************************************************************************
  276. */
  277. typedef struct mem_pool MEM_POOL;
  278. /* --------------------- MEM POOL --------------------- */
  279. struct mem_pool {
  280. LIB_MEM_TYPE Type; /* Pool type : LIB_TYPE_POOL or LIB_TYPE_HEAP. */
  281. MEM_POOL *SegPrevPtr; /* Ptr to PREV mem seg. */
  282. MEM_POOL *SegNextPtr; /* Ptr to NEXT mem seg. */
  283. MEM_POOL *PoolPrevPtr; /* Ptr to PREV mem pool. */
  284. MEM_POOL *PoolNextPtr; /* Ptr to NEXT mem pool. */
  285. void *PoolAddrStart; /* Ptr to start of mem seg for mem pool blks. */
  286. void *PoolAddrEnd; /* Ptr to end of mem seg for mem pool blks. */
  287. void **PoolPtrs; /* Ptr to mem pool's array of blk ptrs. */
  288. MEM_POOL_IX BlkIx; /* Ix into mem pool's array of blk ptrs. */
  289. CPU_SIZE_T PoolSize; /* Size of mem pool (in octets). */
  290. CPU_SIZE_T BlkNbr; /* Nbr of mem pool blks. */
  291. CPU_SIZE_T BlkSize; /* Size of mem pool blks (in octets). */
  292. CPU_SIZE_T BlkAlign; /* Align of mem pool blks (in octets). */
  293. /* --------------------- MEM SEG ---------------------- */
  294. void *SegAddr; /* Ptr to mem seg's base/start addr. */
  295. void *SegAddrNextAvail; /* Ptr to mem seg's next avail addr. */
  296. CPU_SIZE_T SegSizeTot; /* Tot size of mem seg (in octets). */
  297. CPU_SIZE_T SegSizeRem; /* Rem size of mem seg (in octets). */
  298. };
  299. /*$PAGE*/
  300. /*
  301. *********************************************************************************************************
  302. * GLOBAL VARIABLES
  303. *********************************************************************************************************
  304. */
  305. /*$PAGE*/
  306. /*
  307. *********************************************************************************************************
  308. * MACRO'S
  309. *********************************************************************************************************
  310. */
  311. /*
  312. *********************************************************************************************************
  313. * MEMORY DATA VALUE MACRO'S
  314. *
  315. * Note(s) : (1) (a) Some variables & variable buffers to pass & receive data values MUST start on appropriate
  316. * CPU word-aligned addresses. This is required because most word-aligned processors are more
  317. * efficient & may even REQUIRE that multi-octet words start on CPU word-aligned addresses.
  318. *
  319. * (1) For 16-bit word-aligned processors, this means that
  320. *
  321. * all 16- & 32-bit words MUST start on addresses that are multiples of 2 octets
  322. *
  323. * (2) For 32-bit word-aligned processors, this means that
  324. *
  325. * all 16-bit words MUST start on addresses that are multiples of 2 octets
  326. * all 32-bit words MUST start on addresses that are multiples of 4 octets
  327. *
  328. * (b) However, some data values macro's appropriately access data values from any CPU addresses,
  329. * word-aligned or not. Thus for processors that require data word alignment, data words can
  330. * be accessed to/from any CPU address, word-aligned or not, without generating data-word-
  331. * alignment exceptions/faults.
  332. *********************************************************************************************************
  333. */
  334. /*$PAGE*/
  335. /*
  336. *********************************************************************************************************
  337. * ENDIAN WORD ORDER MACRO'S
  338. *
  339. * Description : Convert data values to & from big-, little, or host-endian CPU word order.
  340. *
  341. * Argument(s) : val Data value to convert (see Notes #1 & #2).
  342. *
  343. * Return(s) : Converted data value (see Notes #1 & #2).
  344. *
  345. * Caller(s) : Application.
  346. *
  347. * Note(s) : (1) Convert data values to the desired data-word order :
  348. *
  349. * MEM_VAL_BIG_TO_LITTLE_xx() Convert big- endian data values
  350. * to little- endian data values
  351. * MEM_VAL_LITTLE_TO_BIG_xx() Convert little- endian data values
  352. * to big- endian data values
  353. * MEM_VAL_xxx_TO_HOST_xx() Convert big-/little-endian data values
  354. * to host- endian data values
  355. * MEM_VAL_HOST_TO_xxx_xx() Convert host- endian data values
  356. * to big-/little-endian data values
  357. *
  358. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  359. *
  360. * (2) 'val' data value to convert & any variable to receive the returned conversion MUST
  361. * start on appropriate CPU word-aligned addresses.
  362. *
  363. * See also 'MEMORY DATA VALUE MACRO'S Note #1a'.
  364. *
  365. * (3) MEM_VAL_COPY_xxx() macro's are more efficient than generic endian word order macro's &
  366. * are also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  367. *
  368. * See also 'MEM_VAL_COPY_GET_xxx() Note #4'
  369. * & 'MEM_VAL_COPY_SET_xxx() Note #4'.
  370. *
  371. * (4) Generic endian word order macro's are NOT atomic operations & MUST NOT be used on any
  372. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller of
  373. * the macro's providing some form of additional protection (e.g. mutual exclusion).
  374. *
  375. * (5) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  376. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  377. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  378. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  379. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  380. *********************************************************************************************************
  381. */
  382. /*$PAGE*/
  383. #if ((CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_64) || \
  384. (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_32))
  385. #define MEM_VAL_BIG_TO_LITTLE_16(val) ((CPU_INT16U)(((((CPU_INT16U)(val)) & (CPU_INT16U) 0xFF00u) >> (1u * DEF_OCTET_NBR_BITS)) | \
  386. ((((CPU_INT16U)(val)) & (CPU_INT16U) 0x00FFu) << (1u * DEF_OCTET_NBR_BITS))))
  387. #define MEM_VAL_BIG_TO_LITTLE_32(val) ((CPU_INT32U)(((((CPU_INT32U)(val)) & (CPU_INT32U)0xFF000000u) >> (3u * DEF_OCTET_NBR_BITS)) | \
  388. ((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) >> (1u * DEF_OCTET_NBR_BITS)) | \
  389. ((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) << (1u * DEF_OCTET_NBR_BITS)) | \
  390. ((((CPU_INT32U)(val)) & (CPU_INT32U)0x000000FFu) << (3u * DEF_OCTET_NBR_BITS))))
  391. #elif (CPU_CFG_DATA_SIZE == CPU_WORD_SIZE_16)
  392. #define MEM_VAL_BIG_TO_LITTLE_16(val) ((CPU_INT16U)(((((CPU_INT16U)(val)) & (CPU_INT16U) 0xFF00u) >> (1u * DEF_OCTET_NBR_BITS)) | \
  393. ((((CPU_INT16U)(val)) & (CPU_INT16U) 0x00FFu) << (1u * DEF_OCTET_NBR_BITS))))
  394. #define MEM_VAL_BIG_TO_LITTLE_32(val) ((CPU_INT32U)(((((CPU_INT32U)(val)) & (CPU_INT32U)0xFF000000u) >> (1u * DEF_OCTET_NBR_BITS)) | \
  395. ((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) << (1u * DEF_OCTET_NBR_BITS)) | \
  396. ((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) >> (1u * DEF_OCTET_NBR_BITS)) | \
  397. ((((CPU_INT32U)(val)) & (CPU_INT32U)0x000000FFu) << (1u * DEF_OCTET_NBR_BITS))))
  398. #else
  399. #define MEM_VAL_BIG_TO_LITTLE_16(val) (val)
  400. #define MEM_VAL_BIG_TO_LITTLE_32(val) (val)
  401. #endif
  402. #define MEM_VAL_LITTLE_TO_BIG_16(val) MEM_VAL_BIG_TO_LITTLE_16(val)
  403. #define MEM_VAL_LITTLE_TO_BIG_32(val) MEM_VAL_BIG_TO_LITTLE_32(val)
  404. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  405. #define MEM_VAL_BIG_TO_HOST_16(val) (val)
  406. #define MEM_VAL_BIG_TO_HOST_32(val) (val)
  407. #define MEM_VAL_LITTLE_TO_HOST_16(val) MEM_VAL_LITTLE_TO_BIG_16(val)
  408. #define MEM_VAL_LITTLE_TO_HOST_32(val) MEM_VAL_LITTLE_TO_BIG_32(val)
  409. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  410. #define MEM_VAL_BIG_TO_HOST_16(val) MEM_VAL_BIG_TO_LITTLE_16(val)
  411. #define MEM_VAL_BIG_TO_HOST_32(val) MEM_VAL_BIG_TO_LITTLE_32(val)
  412. #define MEM_VAL_LITTLE_TO_HOST_16(val) (val)
  413. #define MEM_VAL_LITTLE_TO_HOST_32(val) (val)
  414. #else /* See Note #5. */
  415. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  416. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  417. #endif
  418. #define MEM_VAL_HOST_TO_BIG_16(val) MEM_VAL_BIG_TO_HOST_16(val)
  419. #define MEM_VAL_HOST_TO_BIG_32(val) MEM_VAL_BIG_TO_HOST_32(val)
  420. #define MEM_VAL_HOST_TO_LITTLE_16(val) MEM_VAL_LITTLE_TO_HOST_16(val)
  421. #define MEM_VAL_HOST_TO_LITTLE_32(val) MEM_VAL_LITTLE_TO_HOST_32(val)
  422. /*$PAGE*/
  423. /*
  424. *********************************************************************************************************
  425. * MEM_VAL_GET_xxx()
  426. *
  427. * Description : Decode data values from any CPU memory address.
  428. *
  429. * Argument(s) : addr Lowest CPU memory address of data value to decode (see Notes #2 & #3a).
  430. *
  431. * Return(s) : Decoded data value from CPU memory address (see Notes #1 & #3b).
  432. *
  433. * Caller(s) : Application.
  434. *
  435. * Note(s) : (1) Decode data values based on the values' data-word order in CPU memory :
  436. *
  437. * MEM_VAL_GET_xxx_BIG() Decode big- endian data values -- data words' most
  438. * significant octet @ lowest memory address
  439. * MEM_VAL_GET_xxx_LITTLE() Decode little-endian data values -- data words' least
  440. * significant octet @ lowest memory address
  441. * MEM_VAL_GET_xxx() Decode data values using CPU's native or configured
  442. * data-word order
  443. *
  444. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  445. *
  446. * (2) CPU memory addresses/pointers NOT checked for NULL.
  447. *
  448. * (3) (a) MEM_VAL_GET_xxx() macro's decode data values without regard to CPU word-aligned addresses.
  449. * Thus for processors that require data word alignment, data words can be decoded from any
  450. * CPU address, word-aligned or not, without generating data-word-alignment exceptions/faults.
  451. *
  452. * (b) However, any variable to receive the returned data value MUST start on an appropriate CPU
  453. * word-aligned address.
  454. *
  455. * See also 'MEMORY DATA VALUE MACRO'S Note #1'.
  456. *
  457. * (4) MEM_VAL_COPY_GET_xxx() macro's are more efficient than MEM_VAL_GET_xxx() macro's & are
  458. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  459. *
  460. * See also 'MEM_VAL_COPY_GET_xxx() Note #4'.
  461. *
  462. * (5) MEM_VAL_GET_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-static
  463. * (i.e. volatile) variables, registers, hardware, etc.; without the caller of the macro's
  464. * providing some form of additional protection (e.g. mutual exclusion).
  465. *
  466. * (6) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  467. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  468. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  469. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  470. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  471. *********************************************************************************************************
  472. */
  473. /*$PAGE*/
  474. #define MEM_VAL_GET_INT08U_BIG(addr) ((CPU_INT08U) (((CPU_INT08U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS)))
  475. #define MEM_VAL_GET_INT16U_BIG(addr) ((CPU_INT16U)((((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 0))) << (1u * DEF_OCTET_NBR_BITS)) + \
  476. (((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 1))) << (0u * DEF_OCTET_NBR_BITS))))
  477. #define MEM_VAL_GET_INT32U_BIG(addr) ((CPU_INT32U)((((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 0))) << (3u * DEF_OCTET_NBR_BITS)) + \
  478. (((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 1))) << (2u * DEF_OCTET_NBR_BITS)) + \
  479. (((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 2))) << (1u * DEF_OCTET_NBR_BITS)) + \
  480. (((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 3))) << (0u * DEF_OCTET_NBR_BITS))))
  481. #define MEM_VAL_GET_INT08U_LITTLE(addr) ((CPU_INT08U) (((CPU_INT08U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS)))
  482. #define MEM_VAL_GET_INT16U_LITTLE(addr) ((CPU_INT16U)((((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS)) + \
  483. (((CPU_INT16U)(*(((CPU_INT08U *)(addr)) + 1))) << (1u * DEF_OCTET_NBR_BITS))))
  484. #define MEM_VAL_GET_INT32U_LITTLE(addr) ((CPU_INT32U)((((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 0))) << (0u * DEF_OCTET_NBR_BITS)) + \
  485. (((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 1))) << (1u * DEF_OCTET_NBR_BITS)) + \
  486. (((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 2))) << (2u * DEF_OCTET_NBR_BITS)) + \
  487. (((CPU_INT32U)(*(((CPU_INT08U *)(addr)) + 3))) << (3u * DEF_OCTET_NBR_BITS))))
  488. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  489. #define MEM_VAL_GET_INT08U(addr) MEM_VAL_GET_INT08U_BIG(addr)
  490. #define MEM_VAL_GET_INT16U(addr) MEM_VAL_GET_INT16U_BIG(addr)
  491. #define MEM_VAL_GET_INT32U(addr) MEM_VAL_GET_INT32U_BIG(addr)
  492. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  493. #define MEM_VAL_GET_INT08U(addr) MEM_VAL_GET_INT08U_LITTLE(addr)
  494. #define MEM_VAL_GET_INT16U(addr) MEM_VAL_GET_INT16U_LITTLE(addr)
  495. #define MEM_VAL_GET_INT32U(addr) MEM_VAL_GET_INT32U_LITTLE(addr)
  496. #else /* See Note #6. */
  497. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  498. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  499. #endif
  500. /*$PAGE*/
  501. /*
  502. *********************************************************************************************************
  503. * MEM_VAL_SET_xxx()
  504. *
  505. * Description : Encode data values to any CPU memory address.
  506. *
  507. * Argument(s) : addr Lowest CPU memory address to encode data value (see Notes #2 & #3a).
  508. *
  509. * val Data value to encode (see Notes #1 & #3b).
  510. *
  511. * Return(s) : none.
  512. *
  513. * Caller(s) : Application.
  514. *
  515. * Note(s) : (1) Encode data values into CPU memory based on the values' data-word order :
  516. *
  517. * MEM_VAL_SET_xxx_BIG() Encode big- endian data values -- data words' most
  518. * significant octet @ lowest memory address
  519. * MEM_VAL_SET_xxx_LITTLE() Encode little-endian data values -- data words' least
  520. * significant octet @ lowest memory address
  521. * MEM_VAL_SET_xxx() Encode data values using CPU's native or configured
  522. * data-word order
  523. *
  524. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  525. *
  526. * (2) CPU memory addresses/pointers NOT checked for NULL.
  527. *
  528. * (3) (a) MEM_VAL_SET_xxx() macro's encode data values without regard to CPU word-aligned addresses.
  529. * Thus for processors that require data word alignment, data words can be encoded to any
  530. * CPU address, word-aligned or not, without generating data-word-alignment exceptions/faults.
  531. *
  532. * (b) However, 'val' data value to encode MUST start on an appropriate CPU word-aligned address.
  533. *
  534. * See also 'MEMORY DATA VALUE MACRO'S Note #1'.
  535. *
  536. * (4) MEM_VAL_COPY_SET_xxx() macro's are more efficient than MEM_VAL_SET_xxx() macro's & are
  537. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  538. *
  539. * See also 'MEM_VAL_COPY_SET_xxx() Note #4'.
  540. *
  541. * (5) MEM_VAL_SET_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-static
  542. * (i.e. volatile) variables, registers, hardware, etc.; without the caller of the macro's
  543. * providing some form of additional protection (e.g. mutual exclusion).
  544. *
  545. * (6) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  546. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  547. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  548. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  549. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  550. *********************************************************************************************************
  551. */
  552. /*$PAGE*/
  553. #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)
  554. #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))); \
  555. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0x00FFu) >> (0u * DEF_OCTET_NBR_BITS))); } while (0)
  556. #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))); \
  557. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) >> (2u * DEF_OCTET_NBR_BITS))); \
  558. (*(((CPU_INT08U *)(addr)) + 2)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) >> (1u * DEF_OCTET_NBR_BITS))); \
  559. (*(((CPU_INT08U *)(addr)) + 3)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x000000FFu) >> (0u * DEF_OCTET_NBR_BITS))); } while (0)
  560. #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)
  561. #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))); \
  562. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT16U)(val)) & (CPU_INT16U) 0xFF00u) >> (1u * DEF_OCTET_NBR_BITS))); } while (0)
  563. #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))); \
  564. (*(((CPU_INT08U *)(addr)) + 1)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x0000FF00u) >> (1u * DEF_OCTET_NBR_BITS))); \
  565. (*(((CPU_INT08U *)(addr)) + 2)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0x00FF0000u) >> (2u * DEF_OCTET_NBR_BITS))); \
  566. (*(((CPU_INT08U *)(addr)) + 3)) = ((CPU_INT08U)((((CPU_INT32U)(val)) & (CPU_INT32U)0xFF000000u) >> (3u * DEF_OCTET_NBR_BITS))); } while (0)
  567. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  568. #define MEM_VAL_SET_INT08U(addr, val) MEM_VAL_SET_INT08U_BIG(addr, val)
  569. #define MEM_VAL_SET_INT16U(addr, val) MEM_VAL_SET_INT16U_BIG(addr, val)
  570. #define MEM_VAL_SET_INT32U(addr, val) MEM_VAL_SET_INT32U_BIG(addr, val)
  571. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  572. #define MEM_VAL_SET_INT08U(addr, val) MEM_VAL_SET_INT08U_LITTLE(addr, val)
  573. #define MEM_VAL_SET_INT16U(addr, val) MEM_VAL_SET_INT16U_LITTLE(addr, val)
  574. #define MEM_VAL_SET_INT32U(addr, val) MEM_VAL_SET_INT32U_LITTLE(addr, val)
  575. #else /* See Note #6. */
  576. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  577. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  578. #endif
  579. /*$PAGE*/
  580. /*
  581. *********************************************************************************************************
  582. * MEM_VAL_COPY_GET_xxx()
  583. *
  584. * Description : Copy & decode data values from any CPU memory address to any CPU memory address.
  585. *
  586. * Argument(s) : addr_dest Lowest CPU memory address to copy/decode source address's data value
  587. * (see Notes #2 & #3).
  588. *
  589. * addr_src Lowest CPU memory address of data value to copy/decode
  590. * (see Notes #2 & #3).
  591. *
  592. * Return(s) : none.
  593. *
  594. * Caller(s) : Application.
  595. *
  596. * Note(s) : (1) Copy/decode data values based on the values' data-word order :
  597. *
  598. * MEM_VAL_COPY_GET_xxx_BIG() Decode big- endian data values -- data words' most
  599. * significant octet @ lowest memory address
  600. * MEM_VAL_COPY_GET_xxx_LITTLE() Decode little-endian data values -- data words' least
  601. * significant octet @ lowest memory address
  602. * MEM_VAL_COPY_GET_xxx() Decode data values using CPU's native or configured
  603. * data-word order
  604. *
  605. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  606. *
  607. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  608. *
  609. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  610. *
  611. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  612. * "copying ... between objects that overlap ... is undefined".
  613. *
  614. * (3) MEM_VAL_COPY_GET_xxx() macro's copy/decode data values without regard to CPU word-aligned
  615. * addresses. Thus for processors that require data word alignment, data words can be copied/
  616. * decoded to/from any CPU address, word-aligned or not, without generating data-word-alignment
  617. * exceptions/faults.
  618. *
  619. * (4) MEM_VAL_COPY_GET_xxx() macro's are more efficient than MEM_VAL_GET_xxx() macro's & are
  620. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  621. *
  622. * See also 'MEM_VAL_GET_xxx() Note #4'.
  623. *
  624. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_xxx() &
  625. * MEM_VAL_COPY_SET_xxx() macros are inverse, but identical, operations & are provided
  626. * in both forms for semantics & consistency.
  627. *
  628. * See also 'MEM_VAL_COPY_SET_xxx() Note #5'.
  629. *
  630. * (6) MEM_VAL_COPY_GET_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-
  631. * static (i.e. volatile) variables, registers, hardware, etc.; without the caller of the
  632. * macro's providing some form of additional protection (e.g. mutual exclusion).
  633. *
  634. * (7) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  635. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  636. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  637. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  638. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  639. *********************************************************************************************************
  640. */
  641. /*$PAGE*/
  642. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  643. #define MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  644. #define MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  645. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); } while (0)
  646. #define MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  647. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  648. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  649. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 3)); } while (0)
  650. #define MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  651. #define MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  652. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  653. #define MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 3)); \
  654. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  655. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  656. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  657. #define MEM_VAL_COPY_GET_INT08U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src)
  658. #define MEM_VAL_COPY_GET_INT16U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src)
  659. #define MEM_VAL_COPY_GET_INT32U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src)
  660. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  661. #define MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  662. #define MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  663. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  664. #define MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 3)); \
  665. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  666. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  667. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  668. #define MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  669. #define MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  670. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); } while (0)
  671. #define MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  672. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  673. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  674. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 3)); } while (0)
  675. #define MEM_VAL_COPY_GET_INT08U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src)
  676. #define MEM_VAL_COPY_GET_INT16U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src)
  677. #define MEM_VAL_COPY_GET_INT32U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src)
  678. #else /* See Note #7. */
  679. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  680. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  681. #endif
  682. /*$PAGE*/
  683. /*
  684. *********************************************************************************************************
  685. * MEM_VAL_COPY_GET_INTU_xxx()
  686. *
  687. * Description : Copy & decode data values from any CPU memory address to any CPU memory address for
  688. * any sized data values.
  689. *
  690. * Argument(s) : addr_dest Lowest CPU memory address to copy/decode source address's data value
  691. * (see Notes #2 & #3).
  692. *
  693. * addr_src Lowest CPU memory address of data value to copy/decode
  694. * (see Notes #2 & #3).
  695. *
  696. * val_size Number of data value octets to copy/decode.
  697. *
  698. * Return(s) : none.
  699. *
  700. * Caller(s) : Application.
  701. *
  702. * Note(s) : (1) Copy/decode data values based on the values' data-word order :
  703. *
  704. * MEM_VAL_COPY_GET_INTU_BIG() Decode big- endian data values -- data words' most
  705. * significant octet @ lowest memory address
  706. * MEM_VAL_COPY_GET_INTU_LITTLE() Decode little-endian data values -- data words' least
  707. * significant octet @ lowest memory address
  708. * MEM_VAL_COPY_GET_INTU() Decode data values using CPU's native or configured
  709. * data-word order
  710. *
  711. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  712. *
  713. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  714. *
  715. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  716. *
  717. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  718. * "copying ... between objects that overlap ... is undefined".
  719. *
  720. * (3) MEM_VAL_COPY_GET_INTU_xxx() macro's copy/decode data values without regard to CPU word-
  721. * aligned addresses. Thus for processors that require data word alignment, data words
  722. * can be copied/decoded to/from any CPU address, word-aligned or not, without generating
  723. * data-word-alignment exceptions/faults.
  724. *
  725. * (4) MEM_VAL_COPY_GET_xxx() macro's are more efficient than MEM_VAL_COPY_GET_INTU_xxx()
  726. * macro's & SHOULD be used whenever possible.
  727. *
  728. * See also 'MEM_VAL_COPY_GET_xxx() Note #4'.
  729. *
  730. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_INTU_xxx() &
  731. * MEM_VAL_COPY_SET_INTU_xxx() macros are inverse, but identical, operations & are provided
  732. * in both forms for semantics & consistency.
  733. *
  734. * See also 'MEM_VAL_COPY_SET_INTU_xxx() Note #5'.
  735. *
  736. * (6) MEM_VAL_COPY_GET_INTU_xxx() macro's are NOT atomic operations & MUST NOT be used on any
  737. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller of
  738. * the macro's providing some form of additional protection (e.g. mutual exclusion).
  739. *
  740. * (7) The 'CPU_CFG_ENDIAN_TYPE' pre-processor 'else'-conditional code SHOULD never be compiled/
  741. * linked since each 'cpu.h' SHOULD ensure that the CPU data-word-memory order configuration
  742. * constant (CPU_CFG_ENDIAN_TYPE) is configured with an appropriate data-word-memory order
  743. * value (see 'cpu.h CPU WORD CONFIGURATION Note #2'). The 'else'-conditional code is
  744. * included as an extra precaution in case 'cpu.h' is incorrectly configured.
  745. *********************************************************************************************************
  746. */
  747. /*$PAGE*/
  748. #if (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_BIG)
  749. #define MEM_VAL_COPY_GET_INTU_BIG(addr_dest, addr_src, val_size) do { \
  750. CPU_SIZE_T i; \
  751. \
  752. for (i = 0; i < (val_size); i++) { \
  753. (*(((CPU_INT08U *)(addr_dest)) + i)) = (*(((CPU_INT08U *)(addr_src)) + i)); \
  754. } \
  755. } while (0)
  756. #define MEM_VAL_COPY_GET_INTU_LITTLE(addr_dest, addr_src, val_size) do { \
  757. CPU_SIZE_T i; \
  758. CPU_SIZE_T j; \
  759. \
  760. for (i = 0, j = (val_size) - 1; i < (val_size); i++, j--) { \
  761. (*(((CPU_INT08U *)(addr_dest)) + i)) = (*(((CPU_INT08U *)(addr_src)) + j)); \
  762. } \
  763. } while (0)
  764. #define MEM_VAL_COPY_GET_INTU(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU_BIG(addr_dest, addr_src, val_size)
  765. #elif (CPU_CFG_ENDIAN_TYPE == CPU_ENDIAN_TYPE_LITTLE)
  766. #define MEM_VAL_COPY_GET_INTU_BIG(addr_dest, addr_src, val_size) do { \
  767. CPU_SIZE_T i; \
  768. CPU_SIZE_T j; \
  769. \
  770. for (i = 0, j = (val_size) - 1; i < (val_size); i++, j--) { \
  771. (*(((CPU_INT08U *)(addr_dest)) + i)) = (*(((CPU_INT08U *)(addr_src)) + j)); \
  772. } \
  773. } while (0)
  774. #define MEM_VAL_COPY_GET_INTU_LITTLE(addr_dest, addr_src, val_size) do { \
  775. CPU_SIZE_T i; \
  776. \
  777. for (i = 0; i < (val_size); i++) { \
  778. (*(((CPU_INT08U *)(addr_dest)) + i)) = (*(((CPU_INT08U *)(addr_src)) + i)); \
  779. } \
  780. } while (0)
  781. #define MEM_VAL_COPY_GET_INTU(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU_LITTLE(addr_dest, addr_src, val_size)
  782. #else /* See Note #7. */
  783. #error "CPU_CFG_ENDIAN_TYPE illegally #defined in 'cpu.h' "
  784. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  785. #endif
  786. /*$PAGE*/
  787. /*
  788. *********************************************************************************************************
  789. * MEM_VAL_COPY_SET_xxx()
  790. *
  791. * Description : Copy & encode data values from any CPU memory address to any CPU memory address.
  792. *
  793. * Argument(s) : addr_dest Lowest CPU memory address to copy/encode source address's data value
  794. * (see Notes #2 & #3).
  795. *
  796. * addr_src Lowest CPU memory address of data value to copy/encode
  797. * (see Notes #2 & #3).
  798. *
  799. * Return(s) : none.
  800. *
  801. * Caller(s) : Application.
  802. *
  803. * Note(s) : (1) Copy/encode data values based on the values' data-word order :
  804. *
  805. * MEM_VAL_COPY_SET_xxx_BIG() Encode big- endian data values -- data words' most
  806. * significant octet @ lowest memory address
  807. * MEM_VAL_COPY_SET_xxx_LITTLE() Encode little-endian data values -- data words' least
  808. * significant octet @ lowest memory address
  809. * MEM_VAL_COPY_SET_xxx() Encode data values using CPU's native or configured
  810. * data-word order
  811. *
  812. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  813. *
  814. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  815. *
  816. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  817. *
  818. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  819. * "copying ... between objects that overlap ... is undefined".
  820. *
  821. * (3) MEM_VAL_COPY_SET_xxx() macro's copy/encode data values without regard to CPU word-aligned
  822. * addresses. Thus for processors that require data word alignment, data words can be copied/
  823. * encoded to/from any CPU address, word-aligned or not, without generating data-word-alignment
  824. * exceptions/faults.
  825. *
  826. * (4) MEM_VAL_COPY_SET_xxx() macro's are more efficient than MEM_VAL_SET_xxx() macro's & are
  827. * also independent of CPU data-word-alignment & SHOULD be used whenever possible.
  828. *
  829. * See also 'MEM_VAL_SET_xxx() Note #4'.
  830. *
  831. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_xxx() &
  832. * MEM_VAL_COPY_SET_xxx() macros are inverse, but identical, operations & are provided
  833. * in both forms for semantics & consistency.
  834. *
  835. * See also 'MEM_VAL_COPY_GET_xxx() Note #5'.
  836. *
  837. * (6) MEM_VAL_COPY_SET_xxx() macro's are NOT atomic operations & MUST NOT be used on any
  838. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller
  839. * of the macro's providing some form of additional protection (e.g. mutual exclusion).
  840. *********************************************************************************************************
  841. */
  842. /* See Note #5. */
  843. #define MEM_VAL_COPY_SET_INT08U_BIG(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_BIG(addr_dest, addr_src)
  844. #define MEM_VAL_COPY_SET_INT16U_BIG(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_BIG(addr_dest, addr_src)
  845. #define MEM_VAL_COPY_SET_INT32U_BIG(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_BIG(addr_dest, addr_src)
  846. #define MEM_VAL_COPY_SET_INT08U_LITTLE(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U_LITTLE(addr_dest, addr_src)
  847. #define MEM_VAL_COPY_SET_INT16U_LITTLE(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U_LITTLE(addr_dest, addr_src)
  848. #define MEM_VAL_COPY_SET_INT32U_LITTLE(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U_LITTLE(addr_dest, addr_src)
  849. #define MEM_VAL_COPY_SET_INT08U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT08U(addr_dest, addr_src)
  850. #define MEM_VAL_COPY_SET_INT16U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT16U(addr_dest, addr_src)
  851. #define MEM_VAL_COPY_SET_INT32U(addr_dest, addr_src) MEM_VAL_COPY_GET_INT32U(addr_dest, addr_src)
  852. /*$PAGE*/
  853. /*
  854. *********************************************************************************************************
  855. * MEM_VAL_COPY_SET_INTU_xxx()
  856. *
  857. * Description : Copy & encode data values from any CPU memory address to any CPU memory address for
  858. * any sized data values.
  859. *
  860. * Argument(s) : addr_dest Lowest CPU memory address to copy/encode source address's data value
  861. * (see Notes #2 & #3).
  862. *
  863. * addr_src Lowest CPU memory address of data value to copy/encode
  864. * (see Notes #2 & #3).
  865. *
  866. * val_size Number of data value octets to copy/encode.
  867. *
  868. * Return(s) : none.
  869. *
  870. * Caller(s) : Application.
  871. *
  872. * Note(s) : (1) Copy/encode data values based on the values' data-word order :
  873. *
  874. * MEM_VAL_COPY_SET_INTU_BIG() Encode big- endian data values -- data words' most
  875. * significant octet @ lowest memory address
  876. * MEM_VAL_COPY_SET_INTU_LITTLE() Encode little-endian data values -- data words' least
  877. * significant octet @ lowest memory address
  878. * MEM_VAL_COPY_SET_INTU() Encode data values using CPU's native or configured
  879. * data-word order
  880. *
  881. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  882. *
  883. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  884. *
  885. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  886. *
  887. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  888. * "copying ... between objects that overlap ... is undefined".
  889. *
  890. * (3) MEM_VAL_COPY_SET_INTU_xxx() macro's copy/encode data values without regard to CPU word-
  891. * aligned addresses. Thus for processors that require data word alignment, data words
  892. * can be copied/encoded to/from any CPU address, word-aligned or not, without generating
  893. * data-word-alignment exceptions/faults.
  894. *
  895. * (4) MEM_VAL_COPY_SET_xxx() macro's are more efficient than MEM_VAL_COPY_SET_INTU_xxx()
  896. * macro's & SHOULD be used whenever possible.
  897. *
  898. * See also 'MEM_VAL_COPY_SET_xxx() Note #4'.
  899. *
  900. * (5) Since octet-order copy/conversion are inverse operations, MEM_VAL_COPY_GET_INTU_xxx() &
  901. * MEM_VAL_COPY_SET_INTU_xxx() macros are inverse, but identical, operations & are provided
  902. * in both forms for semantics & consistency.
  903. *
  904. * See also 'MEM_VAL_COPY_GET_INTU_xxx() Note #5'.
  905. *
  906. * (6) MEM_VAL_COPY_SET_INTU_xxx() macro's are NOT atomic operations & MUST NOT be used on any
  907. * non-static (i.e. volatile) variables, registers, hardware, etc.; without the caller of
  908. * the macro's providing some form of additional protection (e.g. mutual exclusion).
  909. *********************************************************************************************************
  910. */
  911. /* See Note #5. */
  912. #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)
  913. #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)
  914. #define MEM_VAL_COPY_SET_INTU(addr_dest, addr_src, val_size) MEM_VAL_COPY_GET_INTU(addr_dest, addr_src, val_size)
  915. /*$PAGE*/
  916. /*
  917. *********************************************************************************************************
  918. * MEM_VAL_COPY_xxx()
  919. *
  920. * Description : Copy data values from any CPU memory address to any CPU memory address.
  921. *
  922. * Argument(s) : addr_dest Lowest CPU memory address to copy source address's data value
  923. * (see Notes #2 & #3).
  924. *
  925. * addr_src Lowest CPU memory address of data value to copy
  926. * (see Notes #2 & #3).
  927. *
  928. * val_size Number of data value octets to copy.
  929. *
  930. * Return(s) : none.
  931. *
  932. * Caller(s) : Application.
  933. *
  934. * Note(s) : (1) MEM_VAL_COPY_xxx() macro's copy data values based on CPU's native data-word order.
  935. *
  936. * See also 'cpu.h CPU WORD CONFIGURATION Note #2'.
  937. *
  938. * (2) (a) CPU memory addresses/pointers NOT checked for NULL.
  939. *
  940. * (b) CPU memory addresses/buffers NOT checked for overlapping.
  941. *
  942. * (1) IEEE Std 1003.1, 2004 Edition, Section 'memcpy() : DESCRIPTION' states that
  943. * "copying ... between objects that overlap ... is undefined".
  944. *
  945. * (3) MEM_VAL_COPY_xxx() macro's copy data values without regard to CPU word-aligned addresses.
  946. * Thus for processors that require data word alignment, data words can be copied to/from any
  947. * CPU address, word-aligned or not, without generating data-word-alignment exceptions/faults.
  948. *
  949. * (4) MEM_VAL_COPY_xxx() macro's are more efficient than MEM_VAL_COPY() macro & SHOULD be
  950. * used whenever possible.
  951. *
  952. * (5) MEM_VAL_COPY_xxx() macro's are NOT atomic operations & MUST NOT be used on any non-static
  953. * (i.e. volatile) variables, registers, hardware, etc.; without the caller of the macro's
  954. * providing some form of additional protection (e.g. mutual exclusion).
  955. *********************************************************************************************************
  956. */
  957. #define MEM_VAL_COPY_08(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); } while (0)
  958. #define MEM_VAL_COPY_16(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  959. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); } while (0)
  960. #define MEM_VAL_COPY_32(addr_dest, addr_src) do { (*(((CPU_INT08U *)(addr_dest)) + 0)) = (*(((CPU_INT08U *)(addr_src)) + 0)); \
  961. (*(((CPU_INT08U *)(addr_dest)) + 1)) = (*(((CPU_INT08U *)(addr_src)) + 1)); \
  962. (*(((CPU_INT08U *)(addr_dest)) + 2)) = (*(((CPU_INT08U *)(addr_src)) + 2)); \
  963. (*(((CPU_INT08U *)(addr_dest)) + 3)) = (*(((CPU_INT08U *)(addr_src)) + 3)); } while (0)
  964. #define MEM_VAL_COPY(addr_dest, addr_src, val_size) do { \
  965. CPU_SIZE_T i; \
  966. \
  967. for (i = 0; i < (val_size); i++) { \
  968. (*(((CPU_INT08U *)(addr_dest)) + i)) = (*(((CPU_INT08U *)(addr_src)) + i)); \
  969. } \
  970. } while (0)
  971. /*$PAGE*/
  972. /*
  973. *********************************************************************************************************
  974. * FUNCTION PROTOTYPES
  975. *********************************************************************************************************
  976. */
  977. void Mem_Init ( void);
  978. /* ---------------- MEM API FNCTS ---------------- */
  979. void Mem_Clr ( void *pmem,
  980. CPU_SIZE_T size);
  981. void Mem_Set ( void *pmem,
  982. CPU_INT08U data_val,
  983. CPU_SIZE_T size);
  984. void Mem_Copy ( void *pdest,
  985. const void *psrc,
  986. CPU_SIZE_T size);
  987. CPU_BOOLEAN Mem_Cmp (const void *p1_mem,
  988. const void *p2_mem,
  989. CPU_SIZE_T size);
  990. #if (LIB_MEM_CFG_ALLOC_EN == DEF_ENABLED) /* ---------------- MEM POOL FNCTS ---------------- */
  991. void *Mem_HeapAlloc ( CPU_SIZE_T size,
  992. CPU_SIZE_T align,
  993. CPU_SIZE_T *poctets_reqd,
  994. LIB_ERR *perr);
  995. void Mem_PoolClr ( MEM_POOL *pmem_pool,
  996. LIB_ERR *perr);
  997. void Mem_PoolCreate ( MEM_POOL *pmem_pool,
  998. void *pmem_base_addr,
  999. CPU_SIZE_T mem_size,
  1000. CPU_SIZE_T blk_nbr,
  1001. CPU_SIZE_T blk_size,
  1002. CPU_SIZE_T blk_align,
  1003. CPU_SIZE_T *poctets_reqd,
  1004. LIB_ERR *perr);
  1005. void *Mem_PoolBlkGet ( MEM_POOL *pmem_pool,
  1006. CPU_SIZE_T size,
  1007. LIB_ERR *perr);
  1008. void Mem_PoolBlkFree( MEM_POOL *pmem_pool,
  1009. void *pmem_blk,
  1010. LIB_ERR *perr);
  1011. #endif
  1012. /*$PAGE*/
  1013. /*
  1014. *********************************************************************************************************
  1015. * CONFIGURATION ERRORS
  1016. *********************************************************************************************************
  1017. */
  1018. #ifndef LIB_MEM_CFG_ARG_CHK_EXT_EN
  1019. #error "LIB_MEM_CFG_ARG_CHK_EXT_EN not #define'd in 'app_cfg.h'"
  1020. #error " [MUST be DEF_DISABLED] "
  1021. #error " [ || DEF_ENABLED ] "
  1022. #elif ((LIB_MEM_CFG_ARG_CHK_EXT_EN != DEF_DISABLED) && \
  1023. (LIB_MEM_CFG_ARG_CHK_EXT_EN != DEF_ENABLED ))
  1024. #error "LIB_MEM_CFG_ARG_CHK_EXT_EN illegally #define'd in 'app_cfg.h'"
  1025. #error " [MUST be DEF_DISABLED] "
  1026. #error " [ || DEF_ENABLED ] "
  1027. #endif
  1028. #ifndef LIB_MEM_CFG_OPTIMIZE_ASM_EN
  1029. #error "LIB_MEM_CFG_OPTIMIZE_ASM_EN not #define'd in 'app_cfg.h'"
  1030. #error " [MUST be DEF_DISABLED] "
  1031. #error " [ || DEF_ENABLED ] "
  1032. #elif ((LIB_MEM_CFG_OPTIMIZE_ASM_EN != DEF_DISABLED) && \
  1033. (LIB_MEM_CFG_OPTIMIZE_ASM_EN != DEF_ENABLED ))
  1034. #error "LIB_MEM_CFG_OPTIMIZE_ASM_EN illegally #define'd in 'app_cfg.h'"
  1035. #error " [MUST be DEF_DISABLED] "
  1036. #error " [ || DEF_ENABLED ] "
  1037. #endif
  1038. #ifndef LIB_MEM_CFG_ALLOC_EN
  1039. #error "LIB_MEM_CFG_ALLOC_EN not #define'd in 'app_cfg.h'"
  1040. #error " [MUST be DEF_DISABLED] "
  1041. #error " [ || DEF_ENABLED ] "
  1042. #elif ((LIB_MEM_CFG_ALLOC_EN != DEF_DISABLED) && \
  1043. (LIB_MEM_CFG_ALLOC_EN != DEF_ENABLED ))
  1044. #error "LIB_MEM_CFG_ALLOC_EN illegally #define'd in 'app_cfg.h'"
  1045. #error " [MUST be DEF_DISABLED] "
  1046. #error " [ || DEF_ENABLED ] "
  1047. #elif (LIB_MEM_CFG_ALLOC_EN == DEF_ENABLED)
  1048. #ifndef LIB_MEM_CFG_HEAP_SIZE
  1049. #error "LIB_MEM_CFG_HEAP_SIZE not #define'd in 'app_cfg.h'"
  1050. #error " [MUST be > 0] "
  1051. #elif (DEF_CHK_VAL_MIN(LIB_MEM_CFG_HEAP_SIZE, 1) != DEF_OK)
  1052. #error "LIB_MEM_CFG_HEAP_SIZE illegally #define'd in 'app_cfg.h'"
  1053. #error " [MUST be > 0] "
  1054. #endif
  1055. #ifdef LIB_MEM_CFG_HEAP_BASE_ADDR
  1056. #if (LIB_MEM_CFG_HEAP_BASE_ADDR == 0x0)
  1057. #error "LIB_MEM_CFG_HEAP_BASE_ADDR illegally #define'd in 'app_cfg.h'"
  1058. #error " [MUST be > 0x0] "
  1059. #endif
  1060. #endif
  1061. #endif
  1062. /*
  1063. *********************************************************************************************************
  1064. * LIBRARY CONFIGURATION ERRORS
  1065. *********************************************************************************************************
  1066. */
  1067. /* See 'lib_mem.h Note #2a'. */
  1068. #if (CPU_CORE_VERSION < 127u)
  1069. #error "CPU_CORE_VERSION [SHOULD be >= V1.27]"
  1070. #endif
  1071. /*$PAGE*/
  1072. /*
  1073. *********************************************************************************************************
  1074. * MODULE END
  1075. *********************************************************************************************************
  1076. */
  1077. #endif /* End of lib mem module include. */