lib_def.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  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. * CORE CUSTOM LIBRARY MODULE
  28. *
  29. * Filename : lib_def.h
  30. * Version : V1.38.01
  31. * Programmer(s) : ITJ
  32. * FBJ
  33. * JFD
  34. *********************************************************************************************************
  35. * Note(s) : (1) Assumes the following versions (or more recent) of software modules are included in
  36. * the project build :
  37. *
  38. * (a) uC/CPU V1.29.00
  39. *
  40. *
  41. * (2) NO compiler-supplied standard library functions are used in library or product software.
  42. *
  43. * (a) ALL standard library functions are implemented in the custom library modules :
  44. *
  45. * (1) \<Custom Library Directory>\lib_*.*
  46. *
  47. * (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
  48. *
  49. * where
  50. * <Custom Library Directory> directory path for custom library software
  51. * <cpu> directory name for specific processor (CPU)
  52. * <compiler> directory name for specific compiler
  53. *
  54. * (b) Product-specific library functions are implemented in individual products.
  55. *********************************************************************************************************
  56. */
  57. /*
  58. *********************************************************************************************************
  59. * MODULE
  60. *
  61. * Note(s) : (1) This library definition header file is protected from multiple pre-processor inclusion
  62. * through use of the library definition module present pre-processor macro definition.
  63. *********************************************************************************************************
  64. */
  65. #ifndef LIB_DEF_MODULE_PRESENT
  66. #define LIB_DEF_MODULE_PRESENT
  67. /*
  68. *********************************************************************************************************
  69. * CUSTOM LIBRARY MODULE VERSION NUMBER
  70. *
  71. * Note(s) : (1) (a) The custom library module software version is denoted as follows :
  72. *
  73. * Vx.yy.zz
  74. *
  75. * where
  76. * V denotes 'Version' label
  77. * x denotes major software version revision number
  78. * yy denotes minor software version revision number
  79. * zz denotes sub-minor software version revision number
  80. *
  81. * (b) The software version label #define is formatted as follows :
  82. *
  83. * ver = x.yyzz * 100 * 100
  84. *
  85. * where
  86. * ver denotes software version number scaled as an integer value
  87. * x.yyzz denotes software version number, where the unscaled integer
  88. * portion denotes the major version number & the unscaled
  89. * fractional portion denotes the (concatenated) minor
  90. * version numbers
  91. *********************************************************************************************************
  92. */
  93. #define LIB_VERSION 13801u /* See Note #1. */
  94. /*
  95. *********************************************************************************************************
  96. * INCLUDE FILES
  97. *
  98. * Note(s) : (1) The custom library software files are located in the following directories :
  99. *
  100. * (a) \<Custom Library Directory>\lib_*.*
  101. *
  102. * where
  103. * <Custom Library Directory> directory path for custom library software
  104. *
  105. * (2) CPU-configuration software files are located in the following directories :
  106. *
  107. * (a) \<CPU-Compiler Directory>\cpu_*.*
  108. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  109. *
  110. * where
  111. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  112. * <cpu> directory name for specific processor (CPU)
  113. * <compiler> directory name for specific compiler
  114. *
  115. * (3) Compiler MUST be configured to include as additional include path directories :
  116. *
  117. * (a) '\<Custom Library Directory>\' directory See Note #1a
  118. *
  119. * (b) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  120. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  121. *********************************************************************************************************
  122. */
  123. #include <cpu_def.h>
  124. #include <cpu.h>
  125. /*
  126. *********************************************************************************************************
  127. * STANDARD DEFINES
  128. *********************************************************************************************************
  129. */
  130. #define DEF_NULL 0
  131. /* ----------------- BOOLEAN DEFINES ------------------ */
  132. #define DEF_FALSE 0u
  133. #define DEF_TRUE 1u
  134. #define DEF_NO 0u
  135. #define DEF_YES 1u
  136. #define DEF_DISABLED 0u
  137. #define DEF_ENABLED 1u
  138. #define DEF_INACTIVE 0u
  139. #define DEF_ACTIVE 1u
  140. #define DEF_INVALID 0u
  141. #define DEF_VALID 1u
  142. #define DEF_OFF 0u
  143. #define DEF_ON 1u
  144. #define DEF_CLR 0u
  145. #define DEF_SET 1u
  146. #define DEF_FAIL 0u
  147. #define DEF_OK 1u
  148. /* ------------------- BIT DEFINES -------------------- */
  149. #define DEF_BIT_NONE 0x00u
  150. #define DEF_BIT_00 0x01u
  151. #define DEF_BIT_01 0x02u
  152. #define DEF_BIT_02 0x04u
  153. #define DEF_BIT_03 0x08u
  154. #define DEF_BIT_04 0x10u
  155. #define DEF_BIT_05 0x20u
  156. #define DEF_BIT_06 0x40u
  157. #define DEF_BIT_07 0x80u
  158. #define DEF_BIT_08 0x0100u
  159. #define DEF_BIT_09 0x0200u
  160. #define DEF_BIT_10 0x0400u
  161. #define DEF_BIT_11 0x0800u
  162. #define DEF_BIT_12 0x1000u
  163. #define DEF_BIT_13 0x2000u
  164. #define DEF_BIT_14 0x4000u
  165. #define DEF_BIT_15 0x8000u
  166. #define DEF_BIT_16 0x00010000u
  167. #define DEF_BIT_17 0x00020000u
  168. #define DEF_BIT_18 0x00040000u
  169. #define DEF_BIT_19 0x00080000u
  170. #define DEF_BIT_20 0x00100000u
  171. #define DEF_BIT_21 0x00200000u
  172. #define DEF_BIT_22 0x00400000u
  173. #define DEF_BIT_23 0x00800000u
  174. #define DEF_BIT_24 0x01000000u
  175. #define DEF_BIT_25 0x02000000u
  176. #define DEF_BIT_26 0x04000000u
  177. #define DEF_BIT_27 0x08000000u
  178. #define DEF_BIT_28 0x10000000u
  179. #define DEF_BIT_29 0x20000000u
  180. #define DEF_BIT_30 0x40000000u
  181. #define DEF_BIT_31 0x80000000u
  182. #define DEF_BIT_32 0x0000000100000000u
  183. #define DEF_BIT_33 0x0000000200000000u
  184. #define DEF_BIT_34 0x0000000400000000u
  185. #define DEF_BIT_35 0x0000000800000000u
  186. #define DEF_BIT_36 0x0000001000000000u
  187. #define DEF_BIT_37 0x0000002000000000u
  188. #define DEF_BIT_38 0x0000004000000000u
  189. #define DEF_BIT_39 0x0000008000000000u
  190. #define DEF_BIT_40 0x0000010000000000u
  191. #define DEF_BIT_41 0x0000020000000000u
  192. #define DEF_BIT_42 0x0000040000000000u
  193. #define DEF_BIT_43 0x0000080000000000u
  194. #define DEF_BIT_44 0x0000100000000000u
  195. #define DEF_BIT_45 0x0000200000000000u
  196. #define DEF_BIT_46 0x0000400000000000u
  197. #define DEF_BIT_47 0x0000800000000000u
  198. #define DEF_BIT_48 0x0001000000000000u
  199. #define DEF_BIT_49 0x0002000000000000u
  200. #define DEF_BIT_50 0x0004000000000000u
  201. #define DEF_BIT_51 0x0008000000000000u
  202. #define DEF_BIT_52 0x0010000000000000u
  203. #define DEF_BIT_53 0x0020000000000000u
  204. #define DEF_BIT_54 0x0040000000000000u
  205. #define DEF_BIT_55 0x0080000000000000u
  206. #define DEF_BIT_56 0x0100000000000000u
  207. #define DEF_BIT_57 0x0200000000000000u
  208. #define DEF_BIT_58 0x0400000000000000u
  209. #define DEF_BIT_59 0x0800000000000000u
  210. #define DEF_BIT_60 0x1000000000000000u
  211. #define DEF_BIT_61 0x2000000000000000u
  212. #define DEF_BIT_62 0x4000000000000000u
  213. #define DEF_BIT_63 0x8000000000000000u
  214. /* ------------------ ALIGN DEFINES ------------------- */
  215. #define DEF_ALIGN_MAX_NBR_OCTETS 4096u
  216. /* ------------------ OCTET DEFINES ------------------- */
  217. #define DEF_OCTET_NBR_BITS 8u
  218. #define DEF_OCTET_MASK 0xFFu
  219. #define DEF_OCTET_TO_BIT_NBR_BITS 3u
  220. #define DEF_OCTET_TO_BIT_SHIFT DEF_OCTET_TO_BIT_NBR_BITS
  221. #define DEF_OCTET_TO_BIT_MASK 0x07u
  222. #define DEF_NIBBLE_NBR_BITS 4u
  223. #define DEF_NIBBLE_MASK 0x0Fu
  224. /* --------------- NUMBER BASE DEFINES ---------------- */
  225. #define DEF_NBR_BASE_BIN 2u
  226. #define DEF_NBR_BASE_OCT 8u
  227. #define DEF_NBR_BASE_DEC 10u
  228. #define DEF_NBR_BASE_HEX 16u
  229. /* ----------------- INTEGER DEFINES ------------------ */
  230. #define DEF_INT_08_NBR_BITS 8u
  231. #define DEF_INT_08_MASK 0xFFu
  232. #define DEF_INT_08U_MIN_VAL 0u
  233. #define DEF_INT_08U_MAX_VAL 255u
  234. #define DEF_INT_08S_MIN_VAL_ONES_CPL (-127)
  235. #define DEF_INT_08S_MAX_VAL_ONES_CPL 127
  236. #define DEF_INT_08S_MIN_VAL (DEF_INT_08S_MIN_VAL_ONES_CPL - 1)
  237. #define DEF_INT_08S_MAX_VAL DEF_INT_08S_MAX_VAL_ONES_CPL
  238. #define DEF_INT_08U_NBR_DIG_MIN 1u
  239. #define DEF_INT_08U_NBR_DIG_MAX 3u
  240. #define DEF_INT_08S_NBR_DIG_MIN 3u
  241. #define DEF_INT_08S_NBR_DIG_MAX 3u
  242. #define DEF_INT_16_NBR_BITS 16u
  243. #define DEF_INT_16_MASK 0xFFFFu
  244. #define DEF_INT_16U_MIN_VAL 0u
  245. #define DEF_INT_16U_MAX_VAL 65535u
  246. #define DEF_INT_16S_MIN_VAL_ONES_CPL (-32767)
  247. #define DEF_INT_16S_MAX_VAL_ONES_CPL 32767
  248. #define DEF_INT_16S_MIN_VAL (DEF_INT_16S_MIN_VAL_ONES_CPL - 1)
  249. #define DEF_INT_16S_MAX_VAL DEF_INT_16S_MAX_VAL_ONES_CPL
  250. #define DEF_INT_16U_NBR_DIG_MIN 1u
  251. #define DEF_INT_16U_NBR_DIG_MAX 5u
  252. #define DEF_INT_16S_NBR_DIG_MIN 5u
  253. #define DEF_INT_16S_NBR_DIG_MAX 5u
  254. #define DEF_INT_32_NBR_BITS 32u
  255. #define DEF_INT_32_MASK 0xFFFFFFFFu
  256. #define DEF_INT_32U_MIN_VAL 0u
  257. #define DEF_INT_32U_MAX_VAL 4294967295u
  258. #define DEF_INT_32S_MIN_VAL_ONES_CPL (-2147483647)
  259. #define DEF_INT_32S_MAX_VAL_ONES_CPL 2147483647
  260. #define DEF_INT_32S_MIN_VAL (DEF_INT_32S_MIN_VAL_ONES_CPL - 1)
  261. #define DEF_INT_32S_MAX_VAL DEF_INT_32S_MAX_VAL_ONES_CPL
  262. #define DEF_INT_32U_NBR_DIG_MIN 1u
  263. #define DEF_INT_32U_NBR_DIG_MAX 10u
  264. #define DEF_INT_32S_NBR_DIG_MIN 10u
  265. #define DEF_INT_32S_NBR_DIG_MAX 10u
  266. #define DEF_INT_64_NBR_BITS 64u
  267. #define DEF_INT_64_MASK 0xFFFFFFFFFFFFFFFFu
  268. #define DEF_INT_64U_MIN_VAL 0u
  269. #define DEF_INT_64U_MAX_VAL 18446744073709551615u
  270. #define DEF_INT_64S_MIN_VAL_ONES_CPL (-9223372036854775807)
  271. #define DEF_INT_64S_MAX_VAL_ONES_CPL 9223372036854775807
  272. #define DEF_INT_64S_MIN_VAL (DEF_INT_64S_MIN_VAL_ONES_CPL - 1)
  273. #define DEF_INT_64S_MAX_VAL DEF_INT_64S_MAX_VAL_ONES_CPL
  274. #define DEF_INT_64U_NBR_DIG_MIN 1u
  275. #define DEF_INT_64U_NBR_DIG_MAX 20u
  276. #define DEF_INT_64S_NBR_DIG_MIN 19u
  277. #define DEF_INT_64S_NBR_DIG_MAX 19u
  278. /* --------------- CPU INTEGER DEFINES ---------------- */
  279. #define DEF_INT_CPU_NBR_BITS (CPU_CFG_DATA_SIZE * DEF_OCTET_NBR_BITS)
  280. #define DEF_INT_CPU_NBR_BITS_MAX (CPU_CFG_DATA_SIZE_MAX * DEF_OCTET_NBR_BITS)
  281. #if (DEF_INT_CPU_NBR_BITS == DEF_INT_08_NBR_BITS)
  282. #define DEF_INT_CPU_MASK DEF_INT_08_MASK
  283. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_08U_MIN_VAL
  284. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_08U_MAX_VAL
  285. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_08S_MIN_VAL
  286. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_08S_MAX_VAL
  287. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_08S_MIN_VAL_ONES_CPL
  288. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_08S_MAX_VAL_ONES_CPL
  289. #elif (DEF_INT_CPU_NBR_BITS == DEF_INT_16_NBR_BITS)
  290. #define DEF_INT_CPU_MASK DEF_INT_16_MASK
  291. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_16U_MIN_VAL
  292. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_16U_MAX_VAL
  293. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_16S_MIN_VAL
  294. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_16S_MAX_VAL
  295. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_16S_MIN_VAL_ONES_CPL
  296. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_16S_MAX_VAL_ONES_CPL
  297. #elif (DEF_INT_CPU_NBR_BITS == DEF_INT_32_NBR_BITS)
  298. #define DEF_INT_CPU_MASK DEF_INT_32_MASK
  299. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_32U_MIN_VAL
  300. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_32U_MAX_VAL
  301. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_32S_MIN_VAL
  302. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_32S_MAX_VAL
  303. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_32S_MIN_VAL_ONES_CPL
  304. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_32S_MAX_VAL_ONES_CPL
  305. #elif (DEF_INT_CPU_NBR_BITS == DEF_INT_64_NBR_BITS)
  306. #define DEF_INT_CPU_MASK DEF_INT_64_MASK
  307. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_64U_MIN_VAL
  308. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_64U_MAX_VAL
  309. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_64S_MIN_VAL
  310. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_64S_MAX_VAL
  311. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_64S_MIN_VAL_ONES_CPL
  312. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_64S_MAX_VAL_ONES_CPL
  313. #else
  314. #error "CPU_CFG_DATA_SIZE illegally #defined in 'cpu.h' "
  315. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  316. #endif
  317. /* ------------------- TIME DEFINES ------------------- */
  318. #define DEF_TIME_NBR_DAY_PER_WK 7u
  319. #define DEF_TIME_NBR_DAY_PER_YR 365u
  320. #define DEF_TIME_NBR_DAY_PER_YR_LEAP 366u
  321. #define DEF_TIME_NBR_HR_PER_DAY 24u
  322. #define DEF_TIME_NBR_HR_PER_WK (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
  323. #define DEF_TIME_NBR_HR_PER_YR (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
  324. #define DEF_TIME_NBR_HR_PER_YR_LEAP (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
  325. #define DEF_TIME_NBR_MIN_PER_HR 60u
  326. #define DEF_TIME_NBR_MIN_PER_DAY (DEF_TIME_NBR_MIN_PER_HR * DEF_TIME_NBR_HR_PER_DAY )
  327. #define DEF_TIME_NBR_MIN_PER_WK (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
  328. #define DEF_TIME_NBR_MIN_PER_YR (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
  329. #define DEF_TIME_NBR_MIN_PER_YR_LEAP (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
  330. #define DEF_TIME_NBR_SEC_PER_MIN 60u
  331. #define DEF_TIME_NBR_SEC_PER_HR (DEF_TIME_NBR_SEC_PER_MIN * DEF_TIME_NBR_MIN_PER_HR )
  332. #define DEF_TIME_NBR_SEC_PER_DAY (DEF_TIME_NBR_SEC_PER_HR * DEF_TIME_NBR_HR_PER_DAY )
  333. #define DEF_TIME_NBR_SEC_PER_WK (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
  334. #define DEF_TIME_NBR_SEC_PER_YR (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
  335. #define DEF_TIME_NBR_SEC_PER_YR_LEAP (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
  336. #define DEF_TIME_NBR_mS_PER_SEC 1000u
  337. #define DEF_TIME_NBR_uS_PER_SEC 1000000u
  338. #define DEF_TIME_NBR_nS_PER_SEC 1000000000u
  339. /*
  340. *********************************************************************************************************
  341. * ERROR CODES
  342. *
  343. * Note(s) : (1) All library error codes are #define'd in 'lib_def.h';
  344. *********************************************************************************************************
  345. */
  346. typedef enum lib_err {
  347. LIB_ERR_NONE = 0u,
  348. LIB_MEM_ERR_NONE = 10000u,
  349. LIB_MEM_ERR_NULL_PTR = 10001u, /* Ptr arg(s) passed NULL ptr(s). */
  350. LIB_MEM_ERR_INVALID_MEM_SIZE = 10100u, /* Invalid mem size. */
  351. LIB_MEM_ERR_INVALID_MEM_ALIGN = 10101u, /* Invalid mem align. */
  352. LIB_MEM_ERR_INVALID_SEG_SIZE = 10110u, /* Invalid mem seg size. */
  353. LIB_MEM_ERR_INVALID_SEG_OVERLAP = 10111u, /* Invalid mem seg overlaps other mem seg(s). */
  354. LIB_MEM_ERR_INVALID_SEG_EXISTS = 10112u, /* Invalid mem seg already exists. */
  355. LIB_MEM_ERR_INVALID_POOL = 10120u, /* Invalid mem pool. */
  356. LIB_MEM_ERR_INVALID_BLK_NBR = 10130u, /* Invalid mem pool blk nbr. */
  357. LIB_MEM_ERR_INVALID_BLK_SIZE = 10131u, /* Invalid mem pool blk size. */
  358. LIB_MEM_ERR_INVALID_BLK_ALIGN = 10132u, /* Invalid mem pool blk align. */
  359. LIB_MEM_ERR_INVALID_BLK_IX = 10133u, /* Invalid mem pool ix. */
  360. LIB_MEM_ERR_INVALID_BLK_ADDR = 10135u, /* Invalid mem pool blk addr. */
  361. LIB_MEM_ERR_INVALID_BLK_ADDR_IN_POOL = 10136u, /* Mem pool blk addr already in mem pool. */
  362. LIB_MEM_ERR_SEG_EMPTY = 10200u, /* Mem seg empty; i.e. NO avail mem in seg. */
  363. LIB_MEM_ERR_SEG_OVF = 10201u, /* Mem seg ovf; i.e. req'd mem ovfs rem mem in seg. */
  364. LIB_MEM_ERR_POOL_FULL = 10205u, /* Mem pool full; i.e. all mem blks avail in mem pool. */
  365. LIB_MEM_ERR_POOL_EMPTY = 10206u, /* Mem pool empty; i.e. NO mem blks avail in mem pool. */
  366. LIB_MEM_ERR_POOL_UNLIMITED = 10207u, /* Mem pool is unlimited. */
  367. LIB_MEM_ERR_HEAP_EMPTY = 10210u, /* Heap seg empty; i.e. NO avail mem in heap. */
  368. LIB_MEM_ERR_HEAP_OVF = 10211u, /* Heap seg ovf; i.e. req'd mem ovfs rem mem in heap. */
  369. LIB_MEM_ERR_HEAP_NOT_FOUND = 10215u /* Heap seg NOT found. */
  370. } LIB_ERR;
  371. /*
  372. *********************************************************************************************************
  373. * DATA TYPES
  374. *********************************************************************************************************
  375. */
  376. /*
  377. *********************************************************************************************************
  378. * GLOBAL VARIABLES
  379. *********************************************************************************************************
  380. */
  381. /*
  382. *********************************************************************************************************
  383. * TRACING
  384. *********************************************************************************************************
  385. */
  386. /* Trace level, default to TRACE_LEVEL_OFF. */
  387. #ifndef TRACE_LEVEL_OFF
  388. #define TRACE_LEVEL_OFF 0u
  389. #endif
  390. #ifndef TRACE_LEVEL_INFO
  391. #define TRACE_LEVEL_INFO 1u
  392. #endif
  393. #ifndef TRACE_LEVEL_DBG
  394. #define TRACE_LEVEL_DBG 2u
  395. #endif
  396. #ifndef TRACE_LEVEL_LOG
  397. #define TRACE_LEVEL_LOG 3u
  398. #endif
  399. /*
  400. *********************************************************************************************************
  401. * BIT MACRO'S
  402. *********************************************************************************************************
  403. */
  404. /*
  405. *********************************************************************************************************
  406. * DEF_BIT()
  407. *
  408. * Description : Create bit mask with single, specified bit set.
  409. *
  410. * Argument(s) : bit Bit number of bit to set.
  411. *
  412. * Return(s) : Bit mask with single, specified bit set.
  413. *
  414. * Caller(s) : Application.
  415. *
  416. * Note(s) : (1) 'bit' SHOULD be a non-negative integer.
  417. *
  418. * (2) (a) 'bit' values that overflow the target CPU &/or compiler environment (e.g. negative
  419. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  420. *********************************************************************************************************
  421. */
  422. #define DEF_BIT(bit) (1u << (bit))
  423. /*
  424. *********************************************************************************************************
  425. * DEF_BITxx()
  426. *
  427. * Description : Create bit mask of specified bit size with single, specified bit set.
  428. *
  429. * Argument(s) : bit Bit number of bit to set.
  430. *
  431. * Return(s) : Bit mask with single, specified bit set.
  432. *
  433. * Caller(s) : Application.
  434. *
  435. * Note(s) : (1) 'bit' SHOULD be a non-negative integer.
  436. *
  437. * (2) (a) 'bit' values that overflow the target CPU &/or compiler environment (e.g. negative
  438. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  439. *
  440. * (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
  441. * bit constant '1' is cast to specified integer data type size.
  442. *
  443. * (3) Ideally, DEF_BITxx() macro's should be named DEF_BIT_xx(); however, these names already
  444. * previously-released for bit constant #define's (see 'STANDARD DEFINES BIT DEFINES').
  445. *********************************************************************************************************
  446. */
  447. #define DEF_BIT08(bit) ((CPU_INT08U)((CPU_INT08U)1u << (bit)))
  448. #define DEF_BIT16(bit) ((CPU_INT16U)((CPU_INT16U)1u << (bit)))
  449. #define DEF_BIT32(bit) ((CPU_INT32U)((CPU_INT32U)1u << (bit)))
  450. #define DEF_BIT64(bit) ((CPU_INT64U)((CPU_INT64U)1u << (bit)))
  451. /*
  452. *********************************************************************************************************
  453. * DEF_BIT_MASK()
  454. *
  455. * Description : Shift a bit mask.
  456. *
  457. * Argument(s) : bit_mask Bit mask to shift.
  458. *
  459. * bit_shift Number of bit positions to left-shift bit mask.
  460. *
  461. * Return(s) : Shifted bit mask.
  462. *
  463. * Caller(s) : Application.
  464. *
  465. * Note(s) : (1) (a) 'bit_mask' SHOULD be an unsigned integer.
  466. *
  467. * (b) 'bit_shift' SHOULD be a non-negative integer.
  468. *
  469. * (2) 'bit_shift' values that overflow the target CPU &/or compiler environment (e.g. negative
  470. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  471. *********************************************************************************************************
  472. */
  473. #define DEF_BIT_MASK(bit_mask, bit_shift) ((bit_mask) << (bit_shift))
  474. /*
  475. *********************************************************************************************************
  476. * DEF_BIT_MASK_xx()
  477. *
  478. * Description : Shift a bit mask of specified bit size.
  479. *
  480. * Argument(s) : bit_mask Bit mask to shift.
  481. *
  482. * bit_shift Number of bit positions to left-shift bit mask.
  483. *
  484. * Return(s) : Shifted bit mask.
  485. *
  486. * Caller(s) : Application.
  487. *
  488. * Note(s) : (1) (a) 'bit_mask' SHOULD be an unsigned integer.
  489. *
  490. * (b) 'bit_shift' SHOULD be a non-negative integer.
  491. *
  492. * (2) 'bit_shift' values that overflow the target CPU &/or compiler environment (e.g. negative
  493. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  494. *********************************************************************************************************
  495. */
  496. #define DEF_BIT_MASK_08(bit_mask, bit_shift) ((CPU_INT08U)((CPU_INT08U)(bit_mask) << (bit_shift)))
  497. #define DEF_BIT_MASK_16(bit_mask, bit_shift) ((CPU_INT16U)((CPU_INT16U)(bit_mask) << (bit_shift)))
  498. #define DEF_BIT_MASK_32(bit_mask, bit_shift) ((CPU_INT32U)((CPU_INT32U)(bit_mask) << (bit_shift)))
  499. #define DEF_BIT_MASK_64(bit_mask, bit_shift) ((CPU_INT64U)((CPU_INT64U)(bit_mask) << (bit_shift)))
  500. /*
  501. *********************************************************************************************************
  502. * DEF_BIT_FIELD()
  503. *
  504. * Description : Create & shift a contiguous bit field.
  505. *
  506. * Argument(s) : bit_field Number of contiguous bits to set in the bit field.
  507. *
  508. * bit_shift Number of bit positions to left-shift bit field.
  509. *
  510. * Return(s) : Shifted bit field.
  511. *
  512. * Caller(s) : Application.
  513. *
  514. * Note(s) : (1) 'bit_field' & 'bit_shift' SHOULD be non-negative integers.
  515. *
  516. * (2) (a) 'bit_field'/'bit_shift' values that overflow the target CPU &/or compiler
  517. * environment (e.g. negative or greater-than-CPU-data-size values) MAY generate
  518. * compiler warnings &/or errors.
  519. *
  520. * (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
  521. * bit constant '1' is suffixed with 'L'ong integer modifier.
  522. *
  523. * This may still be insufficient for CPUs &/or compilers that support 'long long'
  524. * integer data types, in which case 'LL' integer modifier should be suffixed.
  525. * However, since almost all 16- & 32-bit CPUs & compilers support 'long' integer
  526. * data types but many may NOT support 'long long' integer data types, only 'long'
  527. * integer data types & modifiers are supported.
  528. *
  529. * See also 'DEF_BIT_FIELD_xx() Note #1b'.
  530. *********************************************************************************************************
  531. */
  532. #define DEF_BIT_FIELD(bit_field, bit_shift) ((((bit_field) >= DEF_INT_CPU_NBR_BITS) ? (DEF_INT_CPU_U_MAX_VAL) \
  533. : (DEF_BIT(bit_field) - 1uL)) \
  534. << (bit_shift))
  535. /*
  536. *********************************************************************************************************
  537. * DEF_BIT_FIELD_xx()
  538. *
  539. * Description : Create & shift a contiguous bit field of specified bit size.
  540. *
  541. * Argument(s) : bit_field Number of contiguous bits to set in the bit field.
  542. *
  543. * bit_shift Number of bit positions to left-shift bit field.
  544. *
  545. * Return(s) : Shifted bit field.
  546. *
  547. * Caller(s) : Application.
  548. *
  549. * Note(s) : (1) 'bit_field' & 'bit_shift' SHOULD be non-negative integers.
  550. *
  551. * (2) (a) 'bit_field'/'bit_shift' values that overflow the target CPU &/or compiler
  552. * environment (e.g. negative or greater-than-CPU-data-size values) MAY generate
  553. * compiler warnings &/or errors.
  554. *
  555. * (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
  556. * bit constant '1' is cast to specified integer data type size.
  557. *********************************************************************************************************
  558. */
  559. #define DEF_BIT_FIELD_08(bit_field, bit_shift) ((CPU_INT08U)((((CPU_INT08U)(bit_field) >= (CPU_INT08U)DEF_INT_08_NBR_BITS) ? (CPU_INT08U)(DEF_INT_08U_MAX_VAL) \
  560. : (CPU_INT08U)(DEF_BIT08(bit_field) - (CPU_INT08U)1u)) \
  561. << (bit_shift)))
  562. #define DEF_BIT_FIELD_16(bit_field, bit_shift) ((CPU_INT16U)((((CPU_INT16U)(bit_field) >= (CPU_INT16U)DEF_INT_16_NBR_BITS) ? (CPU_INT16U)(DEF_INT_16U_MAX_VAL) \
  563. : (CPU_INT16U)(DEF_BIT16(bit_field) - (CPU_INT16U)1u)) \
  564. << (bit_shift)))
  565. #define DEF_BIT_FIELD_32(bit_field, bit_shift) ((CPU_INT32U)((((CPU_INT32U)(bit_field) >= (CPU_INT32U)DEF_INT_32_NBR_BITS) ? (CPU_INT32U)(DEF_INT_32U_MAX_VAL) \
  566. : (CPU_INT32U)(DEF_BIT32(bit_field) - (CPU_INT32U)1u)) \
  567. << (bit_shift)))
  568. #define DEF_BIT_FIELD_64(bit_field, bit_shift) ((CPU_INT64U)((((CPU_INT64U)(bit_field) >= (CPU_INT64U)DEF_INT_64_NBR_BITS) ? (CPU_INT64U)(DEF_INT_64U_MAX_VAL) \
  569. : (CPU_INT64U)(DEF_BIT64(bit_field) - (CPU_INT64U)1u)) \
  570. << (bit_shift)))
  571. /*
  572. *********************************************************************************************************
  573. * DEF_BIT_SET()
  574. *
  575. * Description : Set specified bit(s) in a value.
  576. *
  577. * Argument(s) : val Value to modify by setting specified bit(s).
  578. *
  579. * mask Mask of bits to set.
  580. *
  581. * Return(s) : Modified value with specified bit(s) set.
  582. *
  583. * Caller(s) : Application.
  584. *
  585. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  586. *********************************************************************************************************
  587. */
  588. #define DEF_BIT_SET(val, mask) ((val) = ((val) | (mask)))
  589. /*
  590. *********************************************************************************************************
  591. * DEF_BIT_SET_xx()
  592. *
  593. * Description : Set specified bit(s) in a value of specified bit size.
  594. *
  595. * Argument(s) : val Value to modify by setting specified bit(s).
  596. *
  597. * mask Mask of bits to set.
  598. *
  599. * Return(s) : Modified value with specified bit(s) set.
  600. *
  601. * Caller(s) : Application.
  602. *
  603. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  604. *
  605. * (2) These macros are deprecated and should be replaced by the DEF_BIT_SET macro.
  606. *********************************************************************************************************
  607. */
  608. #define DEF_BIT_SET_08(val, mask) DEF_BIT_SET((val), (mask))
  609. #define DEF_BIT_SET_16(val, mask) DEF_BIT_SET((val), (mask))
  610. #define DEF_BIT_SET_32(val, mask) DEF_BIT_SET((val), (mask))
  611. #define DEF_BIT_SET_64(val, mask) DEF_BIT_SET((val), (mask))
  612. /*
  613. *********************************************************************************************************
  614. * DEF_BIT_CLR()
  615. *
  616. * Description : Clear specified bit(s) in a value.
  617. *
  618. * Argument(s) : val Value to modify by clearing specified bit(s).
  619. *
  620. * mask Mask of bits to clear.
  621. *
  622. * Return(s) : Modified value with specified bit(s) clear.
  623. *
  624. * Caller(s) : Application.
  625. *
  626. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  627. *********************************************************************************************************
  628. */
  629. #define DEF_BIT_CLR(val, mask) ((val) = ((val) & ~(mask)))
  630. /*
  631. *********************************************************************************************************
  632. * DEF_BIT_CLR_xx()
  633. *
  634. * Description : Clear specified bit(s) in a value of specified bit size.
  635. *
  636. * Argument(s) : val Value to modify by clearing specified bit(s).
  637. *
  638. * mask Mask of bits to clear.
  639. *
  640. * Return(s) : Modified value with specified bit(s) clear.
  641. *
  642. * Caller(s) : Application.
  643. *
  644. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  645. *
  646. * (2) These macros are deprecated and should be replaced by the DEF_BIT_CLR macro.
  647. *********************************************************************************************************
  648. */
  649. #define DEF_BIT_CLR_08(val, mask) DEF_BIT_CLR((val), (mask))
  650. #define DEF_BIT_CLR_16(val, mask) DEF_BIT_CLR((val), (mask))
  651. #define DEF_BIT_CLR_32(val, mask) DEF_BIT_CLR((val), (mask))
  652. #define DEF_BIT_CLR_64(val, mask) DEF_BIT_CLR((val), (mask))
  653. /*
  654. *********************************************************************************************************
  655. * DEF_BIT_TOGGLE()
  656. *
  657. * Description : Toggles specified bit(s) in a value.
  658. *
  659. * Argument(s) : val Value to modify by toggling specified bit(s).
  660. *
  661. * mask Mask of bits to toggle.
  662. *
  663. * Return(s) : Modified value with specified bit(s) toggled.
  664. *
  665. * Caller(s) : Application.
  666. *
  667. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  668. *********************************************************************************************************
  669. */
  670. #define DEF_BIT_TOGGLE(val, mask) ((val) ^= (mask))
  671. /*
  672. *********************************************************************************************************
  673. * DEF_BIT_FIELD_RD()
  674. *
  675. * Description : Reads a 'val' field, masked and shifted, given by mask 'field_mask'.
  676. *
  677. * Argument(s) : val Value to read from.
  678. *
  679. * field_mask Mask of field to read. See note #1, #2 and #3.
  680. *
  681. * Return(s) : Field value, masked and right-shifted to bit position 0.
  682. *
  683. * Caller(s) : Application.
  684. *
  685. * Note(s) : (1) 'field_mask' argument must NOT be 0.
  686. *
  687. * (2) 'field_mask' argument must contain a mask with contiguous set bits.
  688. *
  689. * (3) 'val' & 'field_mask' SHOULD be unsigned integers.
  690. *********************************************************************************************************
  691. */
  692. #define DEF_BIT_FIELD_RD(val, field_mask) (((val) & (field_mask)) / ((field_mask) & ~((field_mask) << 1u)))
  693. /*
  694. *********************************************************************************************************
  695. * DEF_BIT_FIELD_ENC()
  696. *
  697. * Description : Encodes given 'field_val' at position given by mask 'field_mask'.
  698. *
  699. * Argument(s) : field_val Value to encode.
  700. *
  701. * field_mask Mask of field to read. See note #1 and #2.
  702. *
  703. * Return(s) : Field value, masked and left-shifted to field position.
  704. *
  705. * Caller(s) : Application.
  706. *
  707. * Note(s) : (1) 'field_mask' argument must contain a mask with contiguous set bits.
  708. *
  709. * (2) 'field_val' & 'field_mask' SHOULD be unsigned integers.
  710. *********************************************************************************************************
  711. */
  712. #define DEF_BIT_FIELD_ENC(field_val, field_mask) (((field_val) * ((field_mask) & ~((field_mask) << 1u))) & (field_mask))
  713. /*
  714. *********************************************************************************************************
  715. * DEF_BIT_FIELD_WR()
  716. *
  717. * Description : Writes 'field_val' field at position given by mask 'field_mask' in variable 'var'.
  718. *
  719. * Argument(s) : var Variable to write field to. See note #2.
  720. *
  721. * field_val Desired value for field. See note #2.
  722. *
  723. * field_mask Mask of field to write to. See note #1 and #2.
  724. *
  725. * Return(s) : None.
  726. *
  727. * Caller(s) : Application.
  728. *
  729. * Note(s) : (1) 'field_mask' argument must contain a mask with contiguous set bits.
  730. *
  731. * (2) 'var', 'field_val' & 'field_mask' SHOULD be unsigned integers.
  732. *********************************************************************************************************
  733. */
  734. #define DEF_BIT_FIELD_WR(var, field_val, field_mask) (var) = (((var) & ~(field_mask)) | DEF_BIT_FIELD_ENC((field_val), (field_mask)))
  735. /*
  736. *********************************************************************************************************
  737. * DEF_BIT_IS_SET()
  738. *
  739. * Description : Determine if specified bit(s) in a value are set.
  740. *
  741. * Argument(s) : val Value to check for specified bit(s) set.
  742. *
  743. * mask Mask of bits to check if set (see Note #2).
  744. *
  745. * Return(s) : DEF_YES, if ALL specified bit(s) are set in value.
  746. *
  747. * DEF_NO, if ALL specified bit(s) are NOT set in value.
  748. *
  749. * Caller(s) : Application.
  750. *
  751. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  752. *
  753. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  754. *********************************************************************************************************
  755. */
  756. #define DEF_BIT_IS_SET(val, mask) (((((val) & (mask)) == (mask)) && \
  757. ((mask) != 0u)) ? (DEF_YES) : (DEF_NO))
  758. /*
  759. *********************************************************************************************************
  760. * DEF_BIT_IS_CLR()
  761. *
  762. * Description : Determine if specified bit(s) in a value are clear.
  763. *
  764. * Argument(s) : val Value to check for specified bit(s) clear.
  765. *
  766. * mask Mask of bits to check if clear (see Note #2).
  767. *
  768. * Return(s) : DEF_YES, if ALL specified bit(s) are clear in value.
  769. *
  770. * DEF_NO, if ALL specified bit(s) are NOT clear in value.
  771. *
  772. * Caller(s) : Application.
  773. *
  774. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  775. *
  776. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  777. *********************************************************************************************************
  778. */
  779. #define DEF_BIT_IS_CLR(val, mask) (((((val) & (mask)) == 0u) && \
  780. ((mask) != 0u)) ? (DEF_YES) : (DEF_NO))
  781. /*
  782. *********************************************************************************************************
  783. * DEF_BIT_IS_SET_ANY()
  784. *
  785. * Description : Determine if any specified bit(s) in a value are set.
  786. *
  787. * Argument(s) : val Value to check for specified bit(s) set.
  788. *
  789. * mask Mask of bits to check if set (see Note #2).
  790. *
  791. * Return(s) : DEF_YES, if ANY specified bit(s) are set in value.
  792. *
  793. * DEF_NO, if ALL specified bit(s) are NOT set in value.
  794. *
  795. * Caller(s) : Application.
  796. *
  797. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  798. *
  799. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  800. *********************************************************************************************************
  801. */
  802. #define DEF_BIT_IS_SET_ANY(val, mask) ((((val) & (mask)) == 0u) ? (DEF_NO ) : (DEF_YES))
  803. /*
  804. *********************************************************************************************************
  805. * DEF_BIT_IS_CLR_ANY()
  806. *
  807. * Description : Determine if any specified bit(s) in a value are clear.
  808. *
  809. * Argument(s) : val Value to check for specified bit(s) clear.
  810. *
  811. * mask Mask of bits to check if clear (see Note #2).
  812. *
  813. * Return(s) : DEF_YES, if ANY specified bit(s) are clear in value.
  814. *
  815. * DEF_NO, if ALL specified bit(s) are NOT clear in value.
  816. *
  817. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  818. *
  819. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  820. *********************************************************************************************************
  821. */
  822. #define DEF_BIT_IS_CLR_ANY(val, mask) ((((val) & (mask)) == (mask)) ? (DEF_NO ) : (DEF_YES))
  823. /*
  824. *********************************************************************************************************
  825. * VALUE MACRO'S
  826. *********************************************************************************************************
  827. */
  828. /*
  829. *********************************************************************************************************
  830. * DEF_CHK_VAL_MIN()
  831. *
  832. * Description : Validate a value as greater than or equal to a specified minimum value.
  833. *
  834. * Argument(s) : val Value to validate.
  835. *
  836. * val_min Minimum value to test.
  837. *
  838. * Return(s) : DEF_OK, Value is greater than or equal to minimum value.
  839. *
  840. * DEF_FAIL, otherwise.
  841. *
  842. * Caller(s) : Application.
  843. *
  844. * Note(s) : (1) DEF_CHK_VAL_MIN() avoids directly comparing any two values if only one of the values
  845. * is negative since the negative value might be incorrectly promoted to an arbitrary
  846. * unsigned value if the other value to compare is unsigned.
  847. *
  848. * (2) Validation of values is limited to the range supported by the compiler &/or target
  849. * environment. All other values that underflow/overflow the supported range will
  850. * modulo/wrap into the supported range as arbitrary signed or unsigned values.
  851. *
  852. * Therefore, any values that underflow the most negative signed value or overflow
  853. * the most positive unsigned value supported by the compiler &/or target environment
  854. * cannot be validated :
  855. *
  856. * ( N-1 N ]
  857. * ( -(2 ) , 2 - 1 ]
  858. * ( ]
  859. *
  860. * where
  861. * N Number of data word bits supported by the compiler
  862. * &/or target environment
  863. *
  864. * (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
  865. * range since many compilers do NOT always correctly handle this value.
  866. *
  867. * (3) 'val' and 'val_min' are compared to 1 instead of 0 to avoid warning generated for
  868. * unsigned numbers.
  869. *********************************************************************************************************
  870. */
  871. #define DEF_CHK_VAL_MIN(val, val_min) (((!(((val) >= 1) && ((val_min) < 1))) && \
  872. ((((val_min) >= 1) && ((val) < 1)) || \
  873. ((val) < (val_min)))) ? DEF_FAIL : DEF_OK)
  874. /*
  875. *********************************************************************************************************
  876. * DEF_CHK_VAL_MAX()
  877. *
  878. * Description : Validate a value as less than or equal to a specified maximum value.
  879. *
  880. * Argument(s) : val Value to validate.
  881. *
  882. * val_max Maximum value to test.
  883. *
  884. * Return(s) : DEF_OK, Value is less than or equal to maximum value.
  885. *
  886. * DEF_FAIL, otherwise.
  887. *
  888. * Caller(s) : Application.
  889. *
  890. * Note(s) : (1) DEF_CHK_VAL_MAX() avoids directly comparing any two values if only one of the values
  891. * is negative since the negative value might be incorrectly promoted to an arbitrary
  892. * unsigned value if the other value to compare is unsigned.
  893. *
  894. * (2) Validation of values is limited to the range supported by the compiler &/or target
  895. * environment. All other values that underflow/overflow the supported range will
  896. * modulo/wrap into the supported range as arbitrary signed or unsigned values.
  897. *
  898. * Therefore, any values that underflow the most negative signed value or overflow
  899. * the most positive unsigned value supported by the compiler &/or target environment
  900. * cannot be validated :
  901. *
  902. * ( N-1 N ]
  903. * ( -(2 ) , 2 - 1 ]
  904. * ( ]
  905. *
  906. * where
  907. * N Number of data word bits supported by the compiler
  908. * &/or target environment
  909. *
  910. * (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
  911. * range since many compilers do NOT always correctly handle this value.
  912. *
  913. * (3) 'val' and 'val_max' are compared to 1 instead of 0 to avoid warning generated for
  914. * unsigned numbers.
  915. *********************************************************************************************************
  916. */
  917. #define DEF_CHK_VAL_MAX(val, val_max) (((!(((val_max) >= 1) && ((val) < 1))) && \
  918. ((((val) >= 1) && ((val_max) < 1)) || \
  919. ((val) > (val_max)))) ? DEF_FAIL : DEF_OK)
  920. /*
  921. *********************************************************************************************************
  922. * DEF_CHK_VAL()
  923. *
  924. * Description : Validate a value as greater than or equal to a specified minimum value & less than or
  925. * equal to a specified maximum value.
  926. *
  927. * Argument(s) : val Value to validate.
  928. *
  929. * val_min Minimum value to test.
  930. *
  931. * val_max Maximum value to test.
  932. *
  933. * Return(s) : DEF_OK, Value is greater than or equal to minimum value AND
  934. * less than or equal to maximum value.
  935. *
  936. * DEF_FAIL, otherwise.
  937. *
  938. * Caller(s) : Application.
  939. *
  940. * Note(s) : (1) DEF_CHK_VAL() avoids directly comparing any two values if only one of the values
  941. * is negative since the negative value might be incorrectly promoted to an arbitrary
  942. * unsigned value if the other value to compare is unsigned.
  943. *
  944. * (2) Validation of values is limited to the range supported by the compiler &/or target
  945. * environment. All other values that underflow/overflow the supported range will
  946. * modulo/wrap into the supported range as arbitrary signed or unsigned values.
  947. *
  948. * Therefore, any values that underflow the most negative signed value or overflow
  949. * the most positive unsigned value supported by the compiler &/or target environment
  950. * cannot be validated :
  951. *
  952. * ( N-1 N ]
  953. * ( -(2 ) , 2 - 1 ]
  954. * ( ]
  955. *
  956. * where
  957. * N Number of data word bits supported by the compiler
  958. * &/or target environment
  959. *
  960. * (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
  961. * range since many compilers do NOT always correctly handle this value.
  962. *
  963. * (3) DEF_CHK_VAL() does NOT validate that the maximum value ('val_max') is greater than
  964. * or equal to the minimum value ('val_min').
  965. *********************************************************************************************************
  966. */
  967. #define DEF_CHK_VAL(val, val_min, val_max) (((DEF_CHK_VAL_MIN((val), (val_min)) == DEF_FAIL) || \
  968. (DEF_CHK_VAL_MAX((val), (val_max)) == DEF_FAIL)) ? DEF_FAIL : DEF_OK)
  969. /*
  970. *********************************************************************************************************
  971. * DEF_GET_U_MAX_VAL()
  972. *
  973. * Description : Get the maximum unsigned value that can be represented in an unsigned integer variable
  974. * of the same data type size as an object.
  975. *
  976. * Argument(s) : obj Object or data type to return maximum unsigned value (see Note #1).
  977. *
  978. * Return(s) : Maximum unsigned integer value that can be represented by the object, if NO error(s).
  979. *
  980. * 0, otherwise.
  981. *
  982. * Caller(s) : Application.
  983. *
  984. * Note(s) : (1) 'obj' SHOULD be an integer object or data type but COULD also be a character or
  985. * pointer object or data type.
  986. *********************************************************************************************************
  987. */
  988. #if (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_08)
  989. #define DEF_GET_U_MAX_VAL(obj) ((sizeof(obj) == CPU_WORD_SIZE_08) ? DEF_INT_08U_MAX_VAL : 0)
  990. #elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_16)
  991. #define DEF_GET_U_MAX_VAL(obj) ((sizeof(obj) == CPU_WORD_SIZE_08) ? DEF_INT_08U_MAX_VAL : \
  992. ((sizeof(obj) == CPU_WORD_SIZE_16) ? DEF_INT_16U_MAX_VAL : 0))
  993. #elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_32)
  994. #define DEF_GET_U_MAX_VAL(obj) ((sizeof(obj) == CPU_WORD_SIZE_08) ? DEF_INT_08U_MAX_VAL : \
  995. ((sizeof(obj) == CPU_WORD_SIZE_16) ? DEF_INT_16U_MAX_VAL : \
  996. ((sizeof(obj) == CPU_WORD_SIZE_32) ? DEF_INT_32U_MAX_VAL : 0)))
  997. #elif (CPU_CFG_DATA_SIZE_MAX == CPU_WORD_SIZE_64)
  998. #define DEF_GET_U_MAX_VAL(obj) ((sizeof(obj) == CPU_WORD_SIZE_08) ? DEF_INT_08U_MAX_VAL : \
  999. ((sizeof(obj) == CPU_WORD_SIZE_16) ? DEF_INT_16U_MAX_VAL : \
  1000. ((sizeof(obj) == CPU_WORD_SIZE_32) ? DEF_INT_32U_MAX_VAL : \
  1001. ((sizeof(obj) == CPU_WORD_SIZE_64) ? DEF_INT_64U_MAX_VAL : 0))))
  1002. #else
  1003. #error "CPU_CFG_DATA_SIZE_MAX illegally #defined in 'cpu.h' "
  1004. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  1005. #endif
  1006. /*
  1007. *********************************************************************************************************
  1008. * MATH MACRO'S
  1009. *
  1010. * Note(s) : (1) Ideally, ALL mathematical macro's & functions SHOULD be defined in the custom mathematics
  1011. * library ('lib_math.*'). #### However, to maintain backwards compatibility with previously-
  1012. * released modules, mathematical macro & function definitions should only be moved to the
  1013. * custom mathematics library once all previously-released modules are updated to include the
  1014. * custom mathematics library.
  1015. *********************************************************************************************************
  1016. */
  1017. /*
  1018. *********************************************************************************************************
  1019. * DEF_MIN()
  1020. *
  1021. * Description : Determine the minimum of two values.
  1022. *
  1023. * Argument(s) : a First value.
  1024. *
  1025. * b Second value.
  1026. *
  1027. * Return(s) : Minimum of the two values.
  1028. *
  1029. * Caller(s) : Application.
  1030. *
  1031. * Note(s) : none.
  1032. *********************************************************************************************************
  1033. */
  1034. #define DEF_MIN(a, b) (((a) < (b)) ? (a) : (b))
  1035. /*
  1036. *********************************************************************************************************
  1037. * DEF_MAX()
  1038. *
  1039. * Description : Determine the maximum of two values.
  1040. *
  1041. * Argument(s) : a First value.
  1042. *
  1043. * b Second value.
  1044. *
  1045. * Return(s) : Maximum of the two values.
  1046. *
  1047. * Note(s) : none.
  1048. *********************************************************************************************************
  1049. */
  1050. #define DEF_MAX(a, b) (((a) > (b)) ? (a) : (b))
  1051. /*
  1052. *********************************************************************************************************
  1053. * DEF_ABS()
  1054. *
  1055. * Description : Determine the absolute value of a value.
  1056. *
  1057. * Argument(s) : a Value to calculate absolute value.
  1058. *
  1059. * Return(s) : Absolute value of the value.
  1060. *
  1061. * Caller(s) : Application.
  1062. *
  1063. * Note(s) : none.
  1064. *********************************************************************************************************
  1065. */
  1066. #define DEF_ABS(a) (((a) < 0) ? (-(a)) : (a))
  1067. /*
  1068. *********************************************************************************************************
  1069. * FUNCTION PROTOTYPES
  1070. *********************************************************************************************************
  1071. */
  1072. /*
  1073. *********************************************************************************************************
  1074. * CONFIGURATION ERRORS
  1075. *********************************************************************************************************
  1076. */
  1077. /*
  1078. *********************************************************************************************************
  1079. * LIBRARY CONFIGURATION ERRORS
  1080. *********************************************************************************************************
  1081. */
  1082. /* See 'lib_def.h Note #1a'. */
  1083. #if (CPU_CORE_VERSION < 12900u)
  1084. #error "CPU_CORE_VERSION [SHOULD be >= V1.29.00]"
  1085. #endif
  1086. /*
  1087. *********************************************************************************************************
  1088. * MODULE END
  1089. *
  1090. * Note(s) : (1) See 'lib_def.h MODULE'.
  1091. *********************************************************************************************************
  1092. */
  1093. #endif /* End of lib def module include. */