lib_def.h 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  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. * CORE CUSTOM LIBRARY MODULE
  25. *
  26. * Filename : lib_def.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. */
  46. /*
  47. *********************************************************************************************************
  48. * MODULE
  49. *********************************************************************************************************
  50. */
  51. #ifndef LIB_DEF_MODULE_PRESENT
  52. #define LIB_DEF_MODULE_PRESENT
  53. /*$PAGE*/
  54. /*
  55. *********************************************************************************************************
  56. * CUSTOM LIBRARY MODULE VERSION NUMBER
  57. *
  58. * Note(s) : (1) (a) The custom library module software version is denoted as follows :
  59. *
  60. * Vx.yy.zz
  61. *
  62. * where
  63. * V denotes 'Version' label
  64. * x denotes major software version revision number
  65. * yy denotes minor software version revision number
  66. * zz denotes sub-minor software version revision number
  67. *
  68. * (b) The software version label #define is formatted as follows :
  69. *
  70. * ver = x.yyzz * 100 * 100
  71. *
  72. * where
  73. * ver denotes software version number scaled as an integer value
  74. * x.yyzz denotes software version number, where the unscaled integer
  75. * portion denotes the major version number & the unscaled
  76. * fractional portion denotes the (concatenated) minor
  77. * version numbers
  78. *********************************************************************************************************
  79. */
  80. #define LIB_VERSION 13500u /* See Note #1. */
  81. /*
  82. *********************************************************************************************************
  83. * INCLUDE FILES
  84. *
  85. * Note(s) : (1) The custom library software files are located in the following directories :
  86. *
  87. * (a) \<Custom Library Directory>\lib_*.*
  88. *
  89. * where
  90. * <Custom Library Directory> directory path for custom library software
  91. *
  92. * (2) CPU-configuration software files are located in the following directories :
  93. *
  94. * (a) \<CPU-Compiler Directory>\cpu_*.*
  95. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  96. *
  97. * where
  98. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  99. * <cpu> directory name for specific processor (CPU)
  100. * <compiler> directory name for specific compiler
  101. *
  102. * (3) Compiler MUST be configured to include as additional include path directories :
  103. *
  104. * (a) '\<Custom Library Directory>\' directory See Note #1a
  105. *
  106. * (b) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  107. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  108. *********************************************************************************************************
  109. */
  110. #include <cpu.h>
  111. /*$PAGE*/
  112. /*
  113. *********************************************************************************************************
  114. * STANDARD DEFINES
  115. *********************************************************************************************************
  116. */
  117. #define DEF_NULL ((void *)0)
  118. /* ----------------- BOOLEAN DEFINES ------------------ */
  119. #define DEF_FALSE 0u
  120. #define DEF_TRUE 1u
  121. #define DEF_NO 0u
  122. #define DEF_YES 1u
  123. #define DEF_DISABLED 0u
  124. #define DEF_ENABLED 1u
  125. #define DEF_INACTIVE 0u
  126. #define DEF_ACTIVE 1u
  127. #define DEF_INVALID 0u
  128. #define DEF_VALID 1u
  129. #define DEF_OFF 0u
  130. #define DEF_ON 1u
  131. #define DEF_CLR 0u
  132. #define DEF_SET 1u
  133. #define DEF_FAIL 0u
  134. #define DEF_OK 1u
  135. /* ------------------- BIT DEFINES -------------------- */
  136. #define DEF_BIT_NONE 0x00u
  137. #define DEF_BIT_00 0x01u
  138. #define DEF_BIT_01 0x02u
  139. #define DEF_BIT_02 0x04u
  140. #define DEF_BIT_03 0x08u
  141. #define DEF_BIT_04 0x10u
  142. #define DEF_BIT_05 0x20u
  143. #define DEF_BIT_06 0x40u
  144. #define DEF_BIT_07 0x80u
  145. #define DEF_BIT_08 0x0100u
  146. #define DEF_BIT_09 0x0200u
  147. #define DEF_BIT_10 0x0400u
  148. #define DEF_BIT_11 0x0800u
  149. #define DEF_BIT_12 0x1000u
  150. #define DEF_BIT_13 0x2000u
  151. #define DEF_BIT_14 0x4000u
  152. #define DEF_BIT_15 0x8000u
  153. #define DEF_BIT_16 0x00010000u
  154. #define DEF_BIT_17 0x00020000u
  155. #define DEF_BIT_18 0x00040000u
  156. #define DEF_BIT_19 0x00080000u
  157. #define DEF_BIT_20 0x00100000u
  158. #define DEF_BIT_21 0x00200000u
  159. #define DEF_BIT_22 0x00400000u
  160. #define DEF_BIT_23 0x00800000u
  161. #define DEF_BIT_24 0x01000000u
  162. #define DEF_BIT_25 0x02000000u
  163. #define DEF_BIT_26 0x04000000u
  164. #define DEF_BIT_27 0x08000000u
  165. #define DEF_BIT_28 0x10000000u
  166. #define DEF_BIT_29 0x20000000u
  167. #define DEF_BIT_30 0x40000000u
  168. #define DEF_BIT_31 0x80000000u
  169. /*$PAGE*/
  170. #define DEF_BIT_32 0x0000000100000000u
  171. #define DEF_BIT_33 0x0000000200000000u
  172. #define DEF_BIT_34 0x0000000400000000u
  173. #define DEF_BIT_35 0x0000000800000000u
  174. #define DEF_BIT_36 0x0000001000000000u
  175. #define DEF_BIT_37 0x0000002000000000u
  176. #define DEF_BIT_38 0x0000004000000000u
  177. #define DEF_BIT_39 0x0000008000000000u
  178. #define DEF_BIT_40 0x0000010000000000u
  179. #define DEF_BIT_41 0x0000020000000000u
  180. #define DEF_BIT_42 0x0000040000000000u
  181. #define DEF_BIT_43 0x0000080000000000u
  182. #define DEF_BIT_44 0x0000100000000000u
  183. #define DEF_BIT_45 0x0000200000000000u
  184. #define DEF_BIT_46 0x0000400000000000u
  185. #define DEF_BIT_47 0x0000800000000000u
  186. #define DEF_BIT_48 0x0001000000000000u
  187. #define DEF_BIT_49 0x0002000000000000u
  188. #define DEF_BIT_50 0x0004000000000000u
  189. #define DEF_BIT_51 0x0008000000000000u
  190. #define DEF_BIT_52 0x0010000000000000u
  191. #define DEF_BIT_53 0x0020000000000000u
  192. #define DEF_BIT_54 0x0040000000000000u
  193. #define DEF_BIT_55 0x0080000000000000u
  194. #define DEF_BIT_56 0x0100000000000000u
  195. #define DEF_BIT_57 0x0200000000000000u
  196. #define DEF_BIT_58 0x0400000000000000u
  197. #define DEF_BIT_59 0x0800000000000000u
  198. #define DEF_BIT_60 0x1000000000000000u
  199. #define DEF_BIT_61 0x2000000000000000u
  200. #define DEF_BIT_62 0x4000000000000000u
  201. #define DEF_BIT_63 0x8000000000000000u
  202. /* ------------------ OCTET DEFINES ------------------- */
  203. #define DEF_OCTET_NBR_BITS 8u
  204. #define DEF_OCTET_MASK 0xFFu
  205. #define DEF_OCTET_TO_BIT_NBR_BITS 3u
  206. #define DEF_OCTET_TO_BIT_SHIFT DEF_OCTET_TO_BIT_NBR_BITS
  207. #define DEF_OCTET_TO_BIT_MASK 0x07u
  208. #define DEF_NIBBLE_NBR_BITS 4u
  209. #define DEF_NIBBLE_MASK 0x0Fu
  210. /* --------------- NUMBER BASE DEFINES ---------------- */
  211. #define DEF_NBR_BASE_BIN 2u
  212. #define DEF_NBR_BASE_OCT 8u
  213. #define DEF_NBR_BASE_DEC 10u
  214. #define DEF_NBR_BASE_HEX 16u
  215. /*$PAGE*/
  216. /* ----------------- INTEGER DEFINES ------------------ */
  217. #define DEF_INT_08_NBR_BITS 8u
  218. #define DEF_INT_08_MASK 0xFFu
  219. #define DEF_INT_08U_MIN_VAL 0u
  220. #define DEF_INT_08U_MAX_VAL 255u
  221. #define DEF_INT_08S_MIN_VAL_ONES_CPL (-127)
  222. #define DEF_INT_08S_MAX_VAL_ONES_CPL 127
  223. #define DEF_INT_08S_MIN_VAL (DEF_INT_08S_MIN_VAL_ONES_CPL - 1)
  224. #define DEF_INT_08S_MAX_VAL DEF_INT_08S_MAX_VAL_ONES_CPL
  225. #define DEF_INT_08U_NBR_DIG_MIN 1u
  226. #define DEF_INT_08U_NBR_DIG_MAX 3u
  227. #define DEF_INT_08S_NBR_DIG_MIN 3u
  228. #define DEF_INT_08S_NBR_DIG_MAX 3u
  229. #define DEF_INT_16_NBR_BITS 16u
  230. #define DEF_INT_16_MASK 0xFFFFu
  231. #define DEF_INT_16U_MIN_VAL 0u
  232. #define DEF_INT_16U_MAX_VAL 65535u
  233. #define DEF_INT_16S_MIN_VAL_ONES_CPL (-32767)
  234. #define DEF_INT_16S_MAX_VAL_ONES_CPL 32767
  235. #define DEF_INT_16S_MIN_VAL (DEF_INT_16S_MIN_VAL_ONES_CPL - 1)
  236. #define DEF_INT_16S_MAX_VAL DEF_INT_16S_MAX_VAL_ONES_CPL
  237. #define DEF_INT_16U_NBR_DIG_MIN 1u
  238. #define DEF_INT_16U_NBR_DIG_MAX 5u
  239. #define DEF_INT_16S_NBR_DIG_MIN 5u
  240. #define DEF_INT_16S_NBR_DIG_MAX 5u
  241. #define DEF_INT_32_NBR_BITS 32u
  242. #define DEF_INT_32_MASK 0xFFFFFFFFu
  243. #define DEF_INT_32U_MIN_VAL 0u
  244. #define DEF_INT_32U_MAX_VAL 4294967295u
  245. #define DEF_INT_32S_MIN_VAL_ONES_CPL (-2147483647)
  246. #define DEF_INT_32S_MAX_VAL_ONES_CPL 2147483647
  247. #define DEF_INT_32S_MIN_VAL (DEF_INT_32S_MIN_VAL_ONES_CPL - 1)
  248. #define DEF_INT_32S_MAX_VAL DEF_INT_32S_MAX_VAL_ONES_CPL
  249. #define DEF_INT_32U_NBR_DIG_MIN 1u
  250. #define DEF_INT_32U_NBR_DIG_MAX 10u
  251. #define DEF_INT_32S_NBR_DIG_MIN 10u
  252. #define DEF_INT_32S_NBR_DIG_MAX 10u
  253. #define DEF_INT_64_NBR_BITS 64u
  254. #define DEF_INT_64_MASK 0xFFFFFFFFFFFFFFFFu
  255. #define DEF_INT_64U_MIN_VAL 0u
  256. #define DEF_INT_64U_MAX_VAL 18446744073709551615u
  257. #define DEF_INT_64S_MIN_VAL_ONES_CPL (-9223372036854775807)
  258. #define DEF_INT_64S_MAX_VAL_ONES_CPL 9223372036854775807
  259. #define DEF_INT_64S_MIN_VAL (DEF_INT_64S_MIN_VAL_ONES_CPL - 1)
  260. #define DEF_INT_64S_MAX_VAL DEF_INT_64S_MAX_VAL_ONES_CPL
  261. #define DEF_INT_64U_NBR_DIG_MIN 1u
  262. #define DEF_INT_64U_NBR_DIG_MAX 20u
  263. #define DEF_INT_64S_NBR_DIG_MIN 19u
  264. #define DEF_INT_64S_NBR_DIG_MAX 19u
  265. /*$PAGE*/
  266. /* --------------- CPU INTEGER DEFINES ---------------- */
  267. #define DEF_INT_CPU_NBR_BITS (CPU_CFG_DATA_SIZE * DEF_OCTET_NBR_BITS)
  268. #if (DEF_INT_CPU_NBR_BITS == DEF_INT_08_NBR_BITS)
  269. #define DEF_INT_CPU_MASK DEF_INT_08_MASK
  270. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_08U_MIN_VAL
  271. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_08U_MAX_VAL
  272. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_08S_MIN_VAL
  273. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_08S_MAX_VAL
  274. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_08S_MIN_VAL_ONES_CPL
  275. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_08S_MAX_VAL_ONES_CPL
  276. #elif (DEF_INT_CPU_NBR_BITS == DEF_INT_16_NBR_BITS)
  277. #define DEF_INT_CPU_MASK DEF_INT_16_MASK
  278. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_16U_MIN_VAL
  279. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_16U_MAX_VAL
  280. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_16S_MIN_VAL
  281. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_16S_MAX_VAL
  282. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_16S_MIN_VAL_ONES_CPL
  283. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_16S_MAX_VAL_ONES_CPL
  284. #elif (DEF_INT_CPU_NBR_BITS == DEF_INT_32_NBR_BITS)
  285. #define DEF_INT_CPU_MASK DEF_INT_32_MASK
  286. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_32U_MIN_VAL
  287. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_32U_MAX_VAL
  288. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_32S_MIN_VAL
  289. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_32S_MAX_VAL
  290. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_32S_MIN_VAL_ONES_CPL
  291. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_32S_MAX_VAL_ONES_CPL
  292. #elif (DEF_INT_CPU_NBR_BITS == DEF_INT_64_NBR_BITS)
  293. #define DEF_INT_CPU_MASK DEF_INT_64_MASK
  294. #define DEF_INT_CPU_U_MIN_VAL DEF_INT_64U_MIN_VAL
  295. #define DEF_INT_CPU_U_MAX_VAL DEF_INT_64U_MAX_VAL
  296. #define DEF_INT_CPU_S_MIN_VAL DEF_INT_64S_MIN_VAL
  297. #define DEF_INT_CPU_S_MAX_VAL DEF_INT_64S_MAX_VAL
  298. #define DEF_INT_CPU_S_MIN_VAL_ONES_CPL DEF_INT_64S_MIN_VAL_ONES_CPL
  299. #define DEF_INT_CPU_S_MAX_VAL_ONES_CPL DEF_INT_64S_MAX_VAL_ONES_CPL
  300. #else
  301. #error "CPU_CFG_DATA_SIZE illegally #defined in 'cpu.h' "
  302. #error " [See 'cpu.h CONFIGURATION ERRORS']"
  303. #endif
  304. /*$PAGE*/
  305. /* ------------------- TIME DEFINES ------------------- */
  306. #define DEF_TIME_NBR_DAY_PER_WK 7uL
  307. #define DEF_TIME_NBR_DAY_PER_YR 365uL
  308. #define DEF_TIME_NBR_DAY_PER_YR_LEAP 366uL
  309. #define DEF_TIME_NBR_HR_PER_DAY 24uL
  310. #define DEF_TIME_NBR_HR_PER_WK (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
  311. #define DEF_TIME_NBR_HR_PER_YR (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
  312. #define DEF_TIME_NBR_HR_PER_YR_LEAP (DEF_TIME_NBR_HR_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
  313. #define DEF_TIME_NBR_MIN_PER_HR 60uL
  314. #define DEF_TIME_NBR_MIN_PER_DAY (DEF_TIME_NBR_MIN_PER_HR * DEF_TIME_NBR_HR_PER_DAY )
  315. #define DEF_TIME_NBR_MIN_PER_WK (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
  316. #define DEF_TIME_NBR_MIN_PER_YR (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
  317. #define DEF_TIME_NBR_MIN_PER_YR_LEAP (DEF_TIME_NBR_MIN_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
  318. #define DEF_TIME_NBR_SEC_PER_MIN 60uL
  319. #define DEF_TIME_NBR_SEC_PER_HR (DEF_TIME_NBR_SEC_PER_MIN * DEF_TIME_NBR_MIN_PER_HR )
  320. #define DEF_TIME_NBR_SEC_PER_DAY (DEF_TIME_NBR_SEC_PER_HR * DEF_TIME_NBR_HR_PER_DAY )
  321. #define DEF_TIME_NBR_SEC_PER_WK (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_WK )
  322. #define DEF_TIME_NBR_SEC_PER_YR (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_YR )
  323. #define DEF_TIME_NBR_SEC_PER_YR_LEAP (DEF_TIME_NBR_SEC_PER_DAY * DEF_TIME_NBR_DAY_PER_YR_LEAP)
  324. #define DEF_TIME_NBR_mS_PER_SEC 1000uL
  325. #define DEF_TIME_NBR_uS_PER_SEC 1000000uL
  326. #define DEF_TIME_NBR_nS_PER_SEC 1000000000uL
  327. /*$PAGE*/
  328. /*
  329. *********************************************************************************************************
  330. * ERROR CODES
  331. *
  332. * Note(s) : (1) All generic library error codes are #define'd in 'lib_def.h';
  333. * Any module-specific error codes are #define'd in library module header files.
  334. *********************************************************************************************************
  335. */
  336. #define LIB_ERR_NONE 0u
  337. /*$PAGE*/
  338. /*
  339. *********************************************************************************************************
  340. * DATA TYPES
  341. *********************************************************************************************************
  342. */
  343. /*
  344. *********************************************************************************************************
  345. * LIBRARY ERROR CODES DATA TYPE
  346. *********************************************************************************************************
  347. */
  348. typedef CPU_INT16U LIB_ERR;
  349. /*
  350. *********************************************************************************************************
  351. * GLOBAL VARIABLES
  352. *********************************************************************************************************
  353. */
  354. /*$PAGE*/
  355. /*
  356. *********************************************************************************************************
  357. * BIT MACRO'S
  358. *********************************************************************************************************
  359. */
  360. /*
  361. *********************************************************************************************************
  362. * DEF_BIT()
  363. *
  364. * Description : Create bit mask with single, specified bit set.
  365. *
  366. * Argument(s) : bit Bit number of bit to set.
  367. *
  368. * Return(s) : Bit mask with single, specified bit set.
  369. *
  370. * Caller(s) : Application.
  371. *
  372. * Note(s) : (1) (a) 'bit' values that overflow the target CPU &/or compiler environment (e.g. negative
  373. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  374. *
  375. * (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
  376. * bit constant '1' is suffixed with 'L'ong integer modifier.
  377. *
  378. * This may still be insufficient for CPUs &/or compilers that support 'long long'
  379. * integer data types, in which case 'LL' integer modifier should be suffixed.
  380. * However, since almost all 16- & 32-bit CPUs & compilers support 'long' integer
  381. * data types but many may NOT support 'long long' integer data types, only 'long'
  382. * integer data types & modifiers are supported.
  383. *
  384. * See also 'DEF_BITxx() Note #1b'.
  385. *********************************************************************************************************
  386. */
  387. #define DEF_BIT(bit) (1uL << (bit))
  388. /*
  389. *********************************************************************************************************
  390. * DEF_BITxx()
  391. *
  392. * Description : Create bit mask of specified bit size with single, specified bit set.
  393. *
  394. * Argument(s) : bit Bit number of bit to set.
  395. *
  396. * Return(s) : Bit mask with single, specified bit set.
  397. *
  398. * Caller(s) : Application.
  399. *
  400. * Note(s) : (1) (a) 'bit' values that overflow the target CPU &/or compiler environment (e.g. negative
  401. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  402. *
  403. * (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
  404. * bit constant '1' is cast to specified integer data type size.
  405. *
  406. * (2) Ideally, DEF_BITxx() macro's should be named DEF_BIT_xx(); however, these names already
  407. * previously-released for bit constant #define's (see 'STANDARD DEFINES BIT DEFINES').
  408. *********************************************************************************************************
  409. */
  410. #define DEF_BIT08(bit) ((CPU_INT08U)((CPU_INT08U)1u << (bit)))
  411. #define DEF_BIT16(bit) ((CPU_INT16U)((CPU_INT16U)1u << (bit)))
  412. #define DEF_BIT32(bit) ((CPU_INT32U)((CPU_INT32U)1u << (bit)))
  413. #define DEF_BIT64(bit) ((CPU_INT64U)((CPU_INT64U)1u << (bit)))
  414. /*$PAGE*/
  415. /*
  416. *********************************************************************************************************
  417. * DEF_BIT_MASK()
  418. *
  419. * Description : Shift a bit mask.
  420. *
  421. * Argument(s) : bit_mask Bit mask to shift.
  422. *
  423. * bit_shift Number of bit positions to left-shift bit mask.
  424. *
  425. * Return(s) : Shifted bit mask.
  426. *
  427. * Caller(s) : Application.
  428. *
  429. * Note(s) : (1) 'bit_mask' SHOULD be an unsigned integer.
  430. *
  431. * (2) 'bit_shift' values that overflow the target CPU &/or compiler environment (e.g. negative
  432. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  433. *********************************************************************************************************
  434. */
  435. #define DEF_BIT_MASK(bit_mask, bit_shift) ((bit_mask) << (bit_shift))
  436. /*
  437. *********************************************************************************************************
  438. * DEF_BIT_MASK_xx()
  439. *
  440. * Description : Shift a bit mask of specified bit size.
  441. *
  442. * Argument(s) : bit_mask Bit mask to shift.
  443. *
  444. * bit_shift Number of bit positions to left-shift bit mask.
  445. *
  446. * Return(s) : Shifted bit mask.
  447. *
  448. * Caller(s) : Application.
  449. *
  450. * Note(s) : (1) 'bit_mask' SHOULD be an unsigned integer.
  451. *
  452. * (2) 'bit_shift' values that overflow the target CPU &/or compiler environment (e.g. negative
  453. * or greater-than-CPU-data-size values) MAY generate compiler warnings &/or errors.
  454. *********************************************************************************************************
  455. */
  456. #define DEF_BIT_MASK_08(bit_mask, bit_shift) ((CPU_INT08U)((CPU_INT08U)(bit_mask) << (bit_shift)))
  457. #define DEF_BIT_MASK_16(bit_mask, bit_shift) ((CPU_INT16U)((CPU_INT16U)(bit_mask) << (bit_shift)))
  458. #define DEF_BIT_MASK_32(bit_mask, bit_shift) ((CPU_INT32U)((CPU_INT32U)(bit_mask) << (bit_shift)))
  459. #define DEF_BIT_MASK_64(bit_mask, bit_shift) ((CPU_INT64U)((CPU_INT64U)(bit_mask) << (bit_shift)))
  460. /*$PAGE*/
  461. /*
  462. *********************************************************************************************************
  463. * DEF_BIT_FIELD()
  464. *
  465. * Description : Create & shift a contiguous bit field.
  466. *
  467. * Argument(s) : bit_field Number of contiguous bits to set in the bit field.
  468. *
  469. * bit_shift Number of bit positions to left-shift bit field.
  470. *
  471. * Return(s) : Shifted bit field.
  472. *
  473. * Caller(s) : Application.
  474. *
  475. * Note(s) : (1) (a) 'bit_field'/'bit_shift' values that overflow the target CPU &/or compiler
  476. * environment (e.g. negative or greater-than-CPU-data-size values) MAY generate
  477. * compiler warnings &/or errors.
  478. *
  479. * (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
  480. * bit constant '1' is suffixed with 'L'ong integer modifier.
  481. *
  482. * This may still be insufficient for CPUs &/or compilers that support 'long long'
  483. * integer data types, in which case 'LL' integer modifier should be suffixed.
  484. * However, since almost all 16- & 32-bit CPUs & compilers support 'long' integer
  485. * data types but many may NOT support 'long long' integer data types, only 'long'
  486. * integer data types & modifiers are supported.
  487. *
  488. * See also 'DEF_BIT_FIELD_xx() Note #1b'.
  489. *********************************************************************************************************
  490. */
  491. #define DEF_BIT_FIELD(bit_field, bit_shift) ((((bit_field) >= DEF_INT_CPU_NBR_BITS) ? (DEF_INT_CPU_U_MAX_VAL) \
  492. : (DEF_BIT(bit_field) - 1uL)) \
  493. << (bit_shift))
  494. /*
  495. *********************************************************************************************************
  496. * DEF_BIT_FIELD_xx()
  497. *
  498. * Description : Create & shift a contiguous bit field of specified bit size.
  499. *
  500. * Argument(s) : bit_field Number of contiguous bits to set in the bit field.
  501. *
  502. * bit_shift Number of bit positions to left-shift bit field.
  503. *
  504. * Return(s) : Shifted bit field.
  505. *
  506. * Caller(s) : Application.
  507. *
  508. * Note(s) : (1) (a) 'bit_field'/'bit_shift' values that overflow the target CPU &/or compiler
  509. * environment (e.g. negative or greater-than-CPU-data-size values) MAY generate
  510. * compiler warnings &/or errors.
  511. *
  512. * (b) To avoid overflowing any target CPU &/or compiler's integer data type, unsigned
  513. * bit constant '1' is cast to specified integer data type size.
  514. *********************************************************************************************************
  515. */
  516. #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) \
  517. : (CPU_INT08U)(DEF_BIT08(bit_field) - (CPU_INT08U)1u)) \
  518. << (bit_shift)))
  519. #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) \
  520. : (CPU_INT16U)(DEF_BIT16(bit_field) - (CPU_INT16U)1u)) \
  521. << (bit_shift)))
  522. #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) \
  523. : (CPU_INT32U)(DEF_BIT32(bit_field) - (CPU_INT32U)1u)) \
  524. << (bit_shift)))
  525. #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) \
  526. : (CPU_INT64U)(DEF_BIT64(bit_field) - (CPU_INT64U)1u)) \
  527. << (bit_shift)))
  528. /*$PAGE*/
  529. /*
  530. *********************************************************************************************************
  531. * DEF_BIT_SET()
  532. *
  533. * Description : Set specified bit(s) in a value.
  534. *
  535. * Argument(s) : val Value to modify by setting specified bit(s).
  536. *
  537. * mask Mask of bits to set.
  538. *
  539. * Return(s) : Modified value with specified bit(s) set.
  540. *
  541. * Caller(s) : Application.
  542. *
  543. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  544. *********************************************************************************************************
  545. */
  546. #define DEF_BIT_SET(val, mask) ((val) |= (mask))
  547. /*
  548. *********************************************************************************************************
  549. * DEF_BIT_CLR()
  550. *
  551. * Description : Clear specified bit(s) in a value.
  552. *
  553. * Argument(s) : val Value to modify by clearing specified bit(s).
  554. *
  555. * mask Mask of bits to clear.
  556. *
  557. * Return(s) : Modified value with specified bit(s) clear.
  558. *
  559. * Caller(s) : Application.
  560. *
  561. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  562. *********************************************************************************************************
  563. */
  564. #define DEF_BIT_CLR(val, mask) ((val) &= ~(mask))
  565. /*$PAGE*/
  566. /*
  567. *********************************************************************************************************
  568. * DEF_BIT_IS_SET()
  569. *
  570. * Description : Determine if specified bit(s) in a value are set.
  571. *
  572. * Argument(s) : val Value to check for specified bit(s) set.
  573. *
  574. * mask Mask of bits to check if set (see Note #2).
  575. *
  576. * Return(s) : DEF_YES, if ALL specified bit(s) are set in value.
  577. *
  578. * DEF_NO, if ALL specified bit(s) are NOT set in value.
  579. *
  580. * Caller(s) : Application.
  581. *
  582. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  583. *
  584. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  585. *********************************************************************************************************
  586. */
  587. #define DEF_BIT_IS_SET(val, mask) ((((mask) != 0u) && \
  588. (((val) & (mask)) == (mask))) ? (DEF_YES) : (DEF_NO ))
  589. /*
  590. *********************************************************************************************************
  591. * DEF_BIT_IS_CLR()
  592. *
  593. * Description : Determine if specified bit(s) in a value are clear.
  594. *
  595. * Argument(s) : val Value to check for specified bit(s) clear.
  596. *
  597. * mask Mask of bits to check if clear (see Note #2).
  598. *
  599. * Return(s) : DEF_YES, if ALL specified bit(s) are clear in value.
  600. *
  601. * DEF_NO, if ALL specified bit(s) are NOT clear in value.
  602. *
  603. * Caller(s) : Application.
  604. *
  605. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  606. *
  607. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  608. *********************************************************************************************************
  609. */
  610. #define DEF_BIT_IS_CLR(val, mask) ((((mask) != 0u) && \
  611. (((val) & (mask)) == 0u)) ? (DEF_YES) : (DEF_NO ))
  612. /*$PAGE*/
  613. /*
  614. *********************************************************************************************************
  615. * DEF_BIT_IS_SET_ANY()
  616. *
  617. * Description : Determine if any specified bit(s) in a value are set.
  618. *
  619. * Argument(s) : val Value to check for specified bit(s) set.
  620. *
  621. * mask Mask of bits to check if set (see Note #2).
  622. *
  623. * Return(s) : DEF_YES, if ANY specified bit(s) are set in value.
  624. *
  625. * DEF_NO, if ALL specified bit(s) are NOT set in value.
  626. *
  627. * Caller(s) : Application.
  628. *
  629. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  630. *
  631. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  632. *********************************************************************************************************
  633. */
  634. #define DEF_BIT_IS_SET_ANY(val, mask) ((((val) & (mask)) == 0u) ? (DEF_NO ) : (DEF_YES))
  635. /*
  636. *********************************************************************************************************
  637. * DEF_BIT_IS_CLR_ANY()
  638. *
  639. * Description : Determine if any specified bit(s) in a value are clear.
  640. *
  641. * Argument(s) : val Value to check for specified bit(s) clear.
  642. *
  643. * mask Mask of bits to check if clear (see Note #2).
  644. *
  645. * Return(s) : DEF_YES, if ANY specified bit(s) are clear in value.
  646. *
  647. * DEF_NO, if ALL specified bit(s) are NOT clear in value.
  648. *
  649. * Note(s) : (1) 'val' & 'mask' SHOULD be unsigned integers.
  650. *
  651. * (2) NULL 'mask' allowed; returns 'DEF_NO' since NO mask bits specified.
  652. *********************************************************************************************************
  653. */
  654. #define DEF_BIT_IS_CLR_ANY(val, mask) ((((val) & (mask)) == (mask)) ? (DEF_NO ) : (DEF_YES))
  655. /*$PAGE*/
  656. /*
  657. *********************************************************************************************************
  658. * DEF_CHK_VAL_MIN()
  659. *
  660. * Description : Validate a value as greater than or equal to a specified minimum value.
  661. *
  662. * Argument(s) : val Value to validate.
  663. *
  664. * val_min Minimum value to test.
  665. *
  666. * Return(s) : DEF_OK, Value is greater than or equal to minimum value.
  667. *
  668. * DEF_FAIL, otherwise.
  669. *
  670. * Caller(s) : Application.
  671. *
  672. * Note(s) : (1) DEF_CHK_VAL_MIN() avoids directly comparing any two values if only one of the values
  673. * is negative since the negative value might be incorrectly promoted to an arbitrary
  674. * unsigned value if the other value to compare is unsigned.
  675. *
  676. * (2) Validation of values is limited to the range supported by the compiler &/or target
  677. * environment. All other values that underflow/overflow the supported range will
  678. * modulo/wrap into the supported range as arbitrary signed or unsigned values.
  679. *
  680. * Therefore, any values that underflow the most negative signed value or overflow
  681. * the most positive unsigned value supported by the compiler &/or target environment
  682. * cannot be validated :
  683. *
  684. * ( N-1 N ]
  685. * ( -(2 ) , 2 - 1 ]
  686. * ( ]
  687. *
  688. * where
  689. * N Number of data word bits supported by the compiler
  690. * &/or target environment
  691. *
  692. * (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
  693. * range since many compilers do NOT always correctly handle this value.
  694. *********************************************************************************************************
  695. */
  696. #define DEF_CHK_VAL_MIN(val, val_min) (((!(((val) >= 0) && ((val_min) < 0))) && \
  697. ((((val_min) >= 0) && ((val) < 0)) || \
  698. ((val) < (val_min)))) ? DEF_FAIL : DEF_OK)
  699. /*$PAGE*/
  700. /*
  701. *********************************************************************************************************
  702. * DEF_CHK_VAL_MAX()
  703. *
  704. * Description : Validate a value as less than or equal to a specified maximum value.
  705. *
  706. * Argument(s) : val Value to validate.
  707. *
  708. * val_max Maximum value to test.
  709. *
  710. * Return(s) : DEF_OK, Value is less than or equal to maximum value.
  711. *
  712. * DEF_FAIL, otherwise.
  713. *
  714. * Caller(s) : Application.
  715. *
  716. * Note(s) : (1) DEF_CHK_VAL_MAX() avoids directly comparing any two values if only one of the values
  717. * is negative since the negative value might be incorrectly promoted to an arbitrary
  718. * unsigned value if the other value to compare is unsigned.
  719. *
  720. * (2) Validation of values is limited to the range supported by the compiler &/or target
  721. * environment. All other values that underflow/overflow the supported range will
  722. * modulo/wrap into the supported range as arbitrary signed or unsigned values.
  723. *
  724. * Therefore, any values that underflow the most negative signed value or overflow
  725. * the most positive unsigned value supported by the compiler &/or target environment
  726. * cannot be validated :
  727. *
  728. * ( N-1 N ]
  729. * ( -(2 ) , 2 - 1 ]
  730. * ( ]
  731. *
  732. * where
  733. * N Number of data word bits supported by the compiler
  734. * &/or target environment
  735. *
  736. * (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
  737. * range since many compilers do NOT always correctly handle this value.
  738. *********************************************************************************************************
  739. */
  740. #define DEF_CHK_VAL_MAX(val, val_max) (((!(((val_max) >= 0) && ((val) < 0))) && \
  741. ((((val) >= 0) && ((val_max) < 0)) || \
  742. ((val) > (val_max)))) ? DEF_FAIL : DEF_OK)
  743. /*$PAGE*/
  744. /*
  745. *********************************************************************************************************
  746. * DEF_CHK_VAL()
  747. *
  748. * Description : Validate a value as greater than or equal to a specified minimum value & less than or
  749. * equal to a specified maximum value.
  750. *
  751. * Argument(s) : val Value to validate.
  752. *
  753. * val_min Minimum value to test.
  754. *
  755. * val_max Maximum value to test.
  756. *
  757. * Return(s) : DEF_OK, Value is greater than or equal to minimum value AND
  758. * less than or equal to maximum value.
  759. *
  760. * DEF_FAIL, otherwise.
  761. *
  762. * Caller(s) : Application.
  763. *
  764. * Note(s) : (1) DEF_CHK_VAL() avoids directly comparing any two values if only one of the values
  765. * is negative since the negative value might be incorrectly promoted to an arbitrary
  766. * unsigned value if the other value to compare is unsigned.
  767. *
  768. * (2) Validation of values is limited to the range supported by the compiler &/or target
  769. * environment. All other values that underflow/overflow the supported range will
  770. * modulo/wrap into the supported range as arbitrary signed or unsigned values.
  771. *
  772. * Therefore, any values that underflow the most negative signed value or overflow
  773. * the most positive unsigned value supported by the compiler &/or target environment
  774. * cannot be validated :
  775. *
  776. * ( N-1 N ]
  777. * ( -(2 ) , 2 - 1 ]
  778. * ( ]
  779. *
  780. * where
  781. * N Number of data word bits supported by the compiler
  782. * &/or target environment
  783. *
  784. * (a) Note that the most negative value, -2^(N-1), is NOT included in the supported
  785. * range since many compilers do NOT always correctly handle this value.
  786. *
  787. * (3) DEF_CHK_VAL() does NOT validate that the maximum value ('val_max') is greater than
  788. * or equal to the minimum value ('val_min').
  789. *********************************************************************************************************
  790. */
  791. #define DEF_CHK_VAL(val, val_min, val_max) (((DEF_CHK_VAL_MIN(val, val_min) == DEF_FAIL) || \
  792. (DEF_CHK_VAL_MAX(val, val_max) == DEF_FAIL)) ? DEF_FAIL : DEF_OK)
  793. /*$PAGE*/
  794. /*
  795. *********************************************************************************************************
  796. * MATH MACRO'S
  797. *
  798. * Note(s) : (1) Ideally, ALL mathematical macro's & functions SHOULD be defined in the custom mathematics
  799. * library ('lib_math.*'). #### However, to maintain backwards compatibility with previously-
  800. * released modules, mathematical macro & function definitions should only be moved to the
  801. * custom mathematics library once all previously-released modules are updated to include the
  802. * custom mathematics library.
  803. *********************************************************************************************************
  804. */
  805. /*
  806. *********************************************************************************************************
  807. * DEF_MIN()
  808. *
  809. * Description : Determine the minimum of two values.
  810. *
  811. * Argument(s) : a First value.
  812. *
  813. * b Second value.
  814. *
  815. * Return(s) : Minimum of the two values.
  816. *
  817. * Caller(s) : Application.
  818. *
  819. * Note(s) : none.
  820. *********************************************************************************************************
  821. */
  822. #define DEF_MIN(a, b) (((a) < (b)) ? (a) : (b))
  823. /*
  824. *********************************************************************************************************
  825. * DEF_MAX()
  826. *
  827. * Description : Determine the maximum of two values.
  828. *
  829. * Argument(s) : a First value.
  830. *
  831. * b Second value.
  832. *
  833. * Return(s) : Maximum of the two values.
  834. *
  835. * Note(s) : none.
  836. *********************************************************************************************************
  837. */
  838. #define DEF_MAX(a, b) (((a) > (b)) ? (a) : (b))
  839. /*$PAGE*/
  840. /*
  841. *********************************************************************************************************
  842. * DEF_ABS()
  843. *
  844. * Description : Determine the absolute value of a value.
  845. *
  846. * Argument(s) : a Value to calculate absolute value.
  847. *
  848. * Return(s) : Absolute value of the value.
  849. *
  850. * Caller(s) : Application.
  851. *
  852. * Note(s) : none.
  853. *********************************************************************************************************
  854. */
  855. #define DEF_ABS(a) (((a) < 0) ? (-(a)) : (a))
  856. /*$PAGE*/
  857. /*
  858. *********************************************************************************************************
  859. * FUNCTION PROTOTYPES
  860. *********************************************************************************************************
  861. */
  862. /*
  863. *********************************************************************************************************
  864. * CONFIGURATION ERRORS
  865. *********************************************************************************************************
  866. */
  867. /*
  868. *********************************************************************************************************
  869. * MODULE END
  870. *********************************************************************************************************
  871. */
  872. #endif /* End of lib def module include. */