lib_math.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. * MATHEMATIC OPERATIONS
  25. *
  26. * Filename : lib_math.h
  27. * Version : V1.35.00
  28. * Programmer(s) : SR
  29. * ITJ
  30. *********************************************************************************************************
  31. * Note(s) : (1) NO compiler-supplied standard library functions are used in library or product software.
  32. *
  33. * (a) ALL standard library functions are implemented in the custom library modules :
  34. *
  35. * (1) \<Custom Library Directory>\lib_*.*
  36. *
  37. * (2) \<Custom Library Directory>\Ports\<cpu>\<compiler>\lib*_a.*
  38. *
  39. * where
  40. * <Custom Library Directory> directory path for custom library software
  41. * <cpu> directory name for specific processor (CPU)
  42. * <compiler> directory name for specific compiler
  43. *
  44. * (b) Product-specific library functions are implemented in individual products.
  45. *
  46. *********************************************************************************************************
  47. * Notice(s) : (1) The Institute of Electrical and Electronics Engineers and The Open Group, have given
  48. * us permission to reprint portions of their documentation. Portions of this text are
  49. * reprinted and reproduced in electronic form from the IEEE Std 1003.1, 2004 Edition,
  50. * Standard for Information Technology -- Portable Operating System Interface (POSIX),
  51. * The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute
  52. * of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any
  53. * discrepancy between these versions and the original IEEE and The Open Group Standard,
  54. * the original IEEE and The Open Group Standard is the referee document. The original
  55. * Standard can be obtained online at http://www.opengroup.org/unix/online.html.
  56. *********************************************************************************************************
  57. */
  58. /*
  59. *********************************************************************************************************
  60. * MODULE
  61. *
  62. * Note(s) : (1) This mathematics library header file is protected from multiple pre-processor inclusion
  63. * through use of the mathematics library module present pre-processor macro definition.
  64. *********************************************************************************************************
  65. */
  66. #ifndef LIB_MATH_MODULE_PRESENT /* See Note #1. */
  67. #define LIB_MATH_MODULE_PRESENT
  68. /*$PAGE*/
  69. /*
  70. *********************************************************************************************************
  71. * INCLUDE FILES
  72. *
  73. * Note(s) : (1) The custom library software files are located in the following directories :
  74. *
  75. * (a) \<Custom Library Directory>\lib_*.*
  76. *
  77. * where
  78. * <Custom Library Directory> directory path for custom library software
  79. *
  80. * (2) CPU-configuration software files are located in the following directories :
  81. *
  82. * (a) \<CPU-Compiler Directory>\cpu_*.*
  83. * (b) \<CPU-Compiler Directory>\<cpu>\<compiler>\cpu*.*
  84. *
  85. * where
  86. * <CPU-Compiler Directory> directory path for common CPU-compiler software
  87. * <cpu> directory name for specific processor (CPU)
  88. * <compiler> directory name for specific compiler
  89. *
  90. * (3) Compiler MUST be configured to include as additional include path directories :
  91. *
  92. * (a) '\<Custom Library Directory>\' directory See Note #1a
  93. *
  94. * (b) (1) '\<CPU-Compiler Directory>\' directory See Note #2a
  95. * (2) '\<CPU-Compiler Directory>\<cpu>\<compiler>\' directory See Note #2b
  96. *
  97. * (4) NO compiler-supplied standard library functions SHOULD be used.
  98. *********************************************************************************************************
  99. */
  100. #include <cpu.h>
  101. #include <cpu_core.h>
  102. #include <lib_def.h>
  103. /*
  104. *********************************************************************************************************
  105. * EXTERNS
  106. *********************************************************************************************************
  107. */
  108. #ifdef LIB_MATH_MODULE
  109. #define LIB_MATH_EXT
  110. #else
  111. #define LIB_MATH_EXT extern
  112. #endif
  113. /*$PAGE*/
  114. /*
  115. *********************************************************************************************************
  116. * DEFINES
  117. *********************************************************************************************************
  118. */
  119. /*
  120. *********************************************************************************************************
  121. * RANDOM NUMBER DEFINES
  122. *
  123. * Note(s) : (1) (a) IEEE Std 1003.1, 2004 Edition, Section 'rand() : DESCRIPTION' states that "if rand()
  124. * is called before any calls to srand() are made, the same sequence shall be generated
  125. * as when srand() is first called with a seed value of 1".
  126. *
  127. * (b) (1) BSD/ANSI-C implements rand() as a Linear Congruential Generator (LCG) :
  128. *
  129. * (A) random_number = [(a * random_number ) + b] modulo m
  130. * n + 1 n
  131. *
  132. * where
  133. * (1) (a) random_number Next random number to generate
  134. * n+1
  135. * (b) random_number Previous random number generated
  136. * n
  137. * (c) random_number Initial random number seed
  138. * 0 See also Note #1a
  139. *
  140. * (2) a = 1103515245 LCG multiplier
  141. * (3) b = 12345 LCG incrementor
  142. * (4) m = RAND_MAX + 1 LCG modulus See also Note #1b2
  143. *
  144. * (2) (A) IEEE Std 1003.1, 2004 Edition, Section 'rand() : DESCRIPTION' states that
  145. * "rand() ... shall compute a sequence of pseudo-random integers in the range
  146. * [0, {RAND_MAX}] with a period of at least 2^32".
  147. *
  148. * (B) However, BSD/ANSI-C 'stdlib.h' defines "RAND_MAX" as "0x7fffffff", or 2^31;
  149. * which therefore limits the range AND period to no more than 2^31.
  150. *********************************************************************************************************
  151. */
  152. #define RAND_SEED_INIT_VAL 1u /* See Note #1a. */
  153. #define RAND_LCG_PARAM_M 0x7FFFFFFFu /* See Note #1b2B. */
  154. #define RAND_LCG_PARAM_A 1103515245u /* See Note #1b1A2. */
  155. #define RAND_LCG_PARAM_B 12345u /* See Note #1b1A3. */
  156. /*$PAGE*/
  157. /*
  158. *********************************************************************************************************
  159. * DATA TYPES
  160. *********************************************************************************************************
  161. */
  162. /*
  163. *********************************************************************************************************
  164. * RANDOM NUMBER DATA TYPE
  165. *********************************************************************************************************
  166. */
  167. typedef CPU_INT32U RAND_NBR;
  168. /*
  169. *********************************************************************************************************
  170. * GLOBAL VARIABLES
  171. *********************************************************************************************************
  172. */
  173. /*
  174. *********************************************************************************************************
  175. * FUNCTION PROTOTYPES
  176. *********************************************************************************************************
  177. */
  178. void Math_Init (void);
  179. /* ------------------ RAND NBR FNCTS ------------------ */
  180. void Math_RandSetSeed(RAND_NBR seed);
  181. RAND_NBR Math_Rand (void);
  182. RAND_NBR Math_RandSeed (RAND_NBR seed);
  183. /*$PAGE*/
  184. /*
  185. *********************************************************************************************************
  186. * CONFIGURATION ERRORS
  187. *********************************************************************************************************
  188. */
  189. /*
  190. *********************************************************************************************************
  191. * MODULE END
  192. *********************************************************************************************************
  193. */
  194. #endif /* End of lib math module include. */