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