1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** GUIX Component */
17 /** */
18 /** Utility (Utility) */
19 /** */
20 /**************************************************************************/
21
22 #define GX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "gx_api.h"
28 #include "gx_utility.h"
29
30 /* define the the table of arc sine values.
31 The values have been enlarged by 256. */
32 static GX_CONST GX_UBYTE asin_angle_value_table[] = {
33 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x02, 0x03, 0x03,
34 0x03, 0x03, 0x04, 0x04, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06, 0x06,
35 0x07, 0x07, 0x07, 0x07, 0x08, 0x08, 0x08, 0x08, 0x09, 0x09, 0x09, 0x09, 0x09, 0x0a, 0x0a, 0x0a,
36 0x0a, 0x0b, 0x0b, 0x0b, 0x0b, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0d, 0x0d, 0x0d, 0x0d, 0x0e, 0x0e,
37 0x0e, 0x0e, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11, 0x12,
38 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13, 0x13, 0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15,
39 0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17, 0x18, 0x18, 0x18, 0x18, 0x19, 0x19, 0x19, 0x19,
40 0x1a, 0x1a, 0x1a, 0x1a, 0x1b, 0x1b, 0x1b, 0x1b, 0x1c, 0x1c, 0x1c, 0x1c, 0x1d, 0x1d, 0x1d, 0x1d,
41 0x1e, 0x1e, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1f, 0x20, 0x20, 0x20, 0x21, 0x21, 0x21, 0x21, 0x22,
42 0x22, 0x22, 0x22, 0x23, 0x23, 0x23, 0x24, 0x24, 0x24, 0x24, 0x25, 0x25, 0x25, 0x26, 0x26, 0x26,
43 0x26, 0x27, 0x27, 0x27, 0x28, 0x28, 0x28, 0x28, 0x29, 0x29, 0x29, 0x2a, 0x2a, 0x2a, 0x2b, 0x2b,
44 0x2b, 0x2b, 0x2c, 0x2c, 0x2c, 0x2d, 0x2d, 0x2d, 0x2e, 0x2e, 0x2e, 0x2f, 0x2f, 0x2f, 0x30, 0x30,
45 0x30, 0x31, 0x31, 0x31, 0x32, 0x32, 0x32, 0x33, 0x33, 0x34, 0x34, 0x34, 0x35, 0x35, 0x35, 0x36,
46 0x36, 0x37, 0x37, 0x37, 0x38, 0x38, 0x39, 0x39, 0x39, 0x3a, 0x3a, 0x3b, 0x3b, 0x3c, 0x3c, 0x3d,
47 0x3d, 0x3d, 0x3e, 0x3e, 0x3f, 0x3f, 0x40, 0x40, 0x41, 0x42, 0x42, 0x43, 0x43, 0x44, 0x44, 0x45,
48 0x46, 0x46, 0x47, 0x48, 0x49, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x51, 0x52, 0x54, 0x5a
49 };
50
51 /**************************************************************************/
52 /* */
53 /* FUNCTION RELEASE */
54 /* */
55 /* _gx_utility_math_asin_5_4_0 PORTABLE C */
56 /* 6.1 */
57 /* AUTHOR */
58 /* */
59 /* Kenneth Maxwell, Microsoft Corporation */
60 /* */
61 /* DESCRIPTION */
62 /* */
63 /* This service computes the angle value of the arc sin x, which is an */
64 /* old version of _gx_utility_math_asin. */
65 /* */
66 /* INPUT */
67 /* */
68 /* x Value whose arc sin is */
69 /* computed, in the interval */
70 /* [-256, 256]. */
71 /* */
72 /* OUTPUT */
73 /* */
74 /* angle Angle value of arc sin of x */
75 /* */
76 /* CALLS */
77 /* */
78 /* None */
79 /* */
80 /* CALLED BY */
81 /* */
82 /* Application Code */
83 /* */
84 /* RELEASE HISTORY */
85 /* */
86 /* DATE NAME DESCRIPTION */
87 /* */
88 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
89 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
90 /* resulting in version 6.1 */
91 /* */
92 /**************************************************************************/
93 #if defined(GUIX_5_4_0_COMPATIBILITY)
_gx_utility_math_asin_5_4_0(INT x)94 INT _gx_utility_math_asin_5_4_0(INT x)
95 {
96 INT angle = 0;
97
98 if (x == 256)
99 {
100 angle = 90;
101 }
102 else if ((x < 256) && (x >= 0))
103 {
104 angle = asin_angle_value_table[x];
105 }
106 else if ((x > -256) && (x < 0))
107 {
108 angle = 0 - asin_angle_value_table[x * -1];
109 }
110 else if (x == -256)
111 {
112 angle = -90;
113 }
114
115 return angle;
116 }
117 #endif
118
119 /**************************************************************************/
120 /* */
121 /* FUNCTION RELEASE */
122 /* */
123 /* _gx_utility_math_asin PORTABLE C */
124 /* 6.1 */
125 /* AUTHOR */
126 /* */
127 /* Kenneth Maxwell, Microsoft Corporation */
128 /* */
129 /* DESCRIPTION */
130 /* */
131 /* This service computes the angle value of the arc sin x. */
132 /* */
133 /* INPUT */
134 /* */
135 /* x Value whose arc sin is */
136 /* computed. The value is a */
137 /* fixed point math data type, */
138 /* call GX_FIXED_VAL_MAKE to do */
139 /* type conversion. */
140 /* */
141 /* OUTPUT */
142 /* */
143 /* angle Angle value of arc sin of x */
144 /* */
145 /* CALLS */
146 /* */
147 /* None */
148 /* */
149 /* CALLED BY */
150 /* */
151 /* Application Code */
152 /* */
153 /* RELEASE HISTORY */
154 /* */
155 /* DATE NAME DESCRIPTION */
156 /* */
157 /* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
158 /* 09-30-2020 Kenneth Maxwell Modified comment(s), */
159 /* resulting in version 6.1 */
160 /* */
161 /**************************************************************************/
_gx_utility_math_asin(GX_FIXED_VAL x)162 INT _gx_utility_math_asin(GX_FIXED_VAL x)
163 {
164 INT angle = 0;
165
166 x = GX_FIXED_VAL_TO_INT(x << 8);
167
168 if (x == 256)
169 {
170 angle = 90;
171 }
172 else if ((x < 256) && (x >= 0))
173 {
174 angle = asin_angle_value_table[x];
175 }
176 else if ((x > -256) && (x < 0))
177 {
178 angle = 0 - asin_angle_value_table[x * -1];
179 }
180 else if (x == -256)
181 {
182 angle = -90;
183 }
184
185 return angle;
186 }
187
188