1414#ifdef CONFIG_CORDIC_TRIGONOMETRY_FIXED
1515/* Use a local definition to avoid adding a dependency on <math.h> */
1616#define _M_PI 3.14159265358979323846 /* pi */
17- /*cordic_atan2_lookup_table = atan(2.^-(0:N-1)) N = 31/16
18- *CORDIC Gain is cordic_gain = prod(sqrt(1 + 2.^(-2*(0:31/16-1))))
19- *Inverse CORDIC Gain,inverse_cordic_gain = 1 / cordic_gain
17+ /**
18+ * \cordic_atan2_lookup_table = atan(2.^-(0:N-1)) N = 31/16
19+ * \CORDIC Gain is cordic_gain = prod(sqrt(1 + 2.^(-2*(0:31/16-1))))
20+ * \Inverse CORDIC Gain,inverse_cordic_gain = 1 / cordic_gain
2021 */
2122static const int32_t cordic_lookup [CORDIC_31B_TABLE_SIZE ] = { 843314857 , 497837829 ,
2223 263043837 , 133525159 , 67021687 , 33543516 , 16775851 , 8388437 , 4194283 , 2097149 ,
@@ -32,121 +33,6 @@ const int32_t cord_sincos_piovertwo_q28fl = Q_CONVERT_FLOAT(_M_PI / 2, 28);
3233/* 843314857, deg = 90.000000 */
3334const int32_t cord_sincos_piovertwo_q29fl = Q_CONVERT_FLOAT (_M_PI / 2 , 29 );
3435
35- /**
36- * \Compute fixed point cordicsine with table lookup and interpolation
37- * \The cordic sine algorithm converges, when the angle is in the range
38- * \[-pi/2, pi/2).If an angle is outside of this range, then a multiple of
39- * \pi/2 is added or subtracted from the angle until it is within the range
40- * \[-pi/2,pi/2).Start with the angle in the range [-2*pi, 2*pi) and output
41- * \has range in [-1.0 to 1.0]
42- * \+------------------+-----------------+--------+--------+
43- * \| thRadFxp | cdcsinth |thRadFxp|cdcsinth|
44- * \+----+-----+-------+----+----+-------+--------+--------+
45- * \|WLen| FLen|Signbit|WLen|FLen|Signbit| Qformat| Qformat|
46- * \+----+-----+-------+----+----+-------+--------+--------+
47- * \| 32 | 28 | 1 | 32 | 31 | 1 | 4.28 | 1.31 |
48- * \+------------------+-----------------+--------+--------+
49- */
50- inline int32_t sin_fixed_32b (int32_t th_rad_fxp )
51- {
52- int32_t sign ;
53- int32_t b_yn ;
54- int32_t xn ;
55- int32_t th_cdc_fxp ;
56- cordic_cfg type = EN_32B_CORDIC_SINE ;
57- cordic_sin_cos (th_rad_fxp , type , & sign , & b_yn , & xn , & th_cdc_fxp );
58- th_cdc_fxp = sign * b_yn ;
59- /*convert Q2.30 to Q1.31 format*/
60- return sat_int32 (Q_SHIFT_LEFT ((int64_t )th_cdc_fxp , 30 , 31 ));
61- }
62- /**
63- * \Compute fixed point cordicsine with table lookup and interpolation
64- * \The cordic cosine algorithm converges, when the angle is in the range
65- * \[-pi/2, pi/2).If an angle is outside of this range, then a multiple of
66- * \pi/2 is added or subtracted from the angle until it is within the range
67- * \[-pi/2,pi/2).Start with the angle in the range [-2*pi, 2*pi) and output
68- * \has range in [-1.0 to 1.0]
69- * \+------------------+-----------------+--------+--------+
70- * \| thRadFxp | cdccosth |thRadFxp|cdccosth|
71- * \+----+-----+-------+----+----+-------+--------+--------+
72- * \|WLen| FLen|Signbit|WLen|FLen|Signbit| Qformat| Qformat|
73- * \+----+-----+-------+----+----+-------+--------+--------+
74- * \| 32 | 28 | 1 | 32 | 31 | 1 | 4.28 | 1.31 |
75- * \+------------------+-----------------+--------+--------+
76- */
77- inline int32_t cos_fixed_32b (int32_t th_rad_fxp )
78- {
79- int32_t sign ;
80- int32_t b_yn ;
81- int32_t xn ;
82- int32_t th_cdc_fxp ;
83- cordic_cfg type = EN_32B_CORDIC_COSINE ;
84- cordic_sin_cos (th_rad_fxp , type , & sign , & b_yn , & xn , & th_cdc_fxp );
85- th_cdc_fxp = sign * xn ;
86- /*convert Q2.30 to Q1.31 format*/
87- return sat_int32 (Q_SHIFT_LEFT ((int64_t )th_cdc_fxp , 30 , 31 ));
88- }
89-
90- /**
91- * \Compute fixed point cordic sine with table lookup and interpolation
92- * \The cordic sine algorithm converges, when the angle is in the range
93- * \[-pi/2, pi/2).If an angle is outside of this range, then a multiple of
94- * \pi/2 is added or subtracted from the angle until it is within the range
95- * \[-pi/2,pi/2).Start with the angle in the range [-2*pi, 2*pi) and output
96- * \has range in [-1.0 to 1.0]
97- * \+------------------+-----------------+--------+------------+
98- * \| thRadFxp | cdcsinth |thRadFxp| cdcsinth|
99- * \+----+-----+-------+----+----+-------+--------+------------+
100- * \|WLen| FLen|Signbit|WLen|FLen|Signbit| Qformat| Qformat |
101- * \+----+-----+-------+----+----+-------+--------+------------+
102- * \| 32 | 28 | 1 | 32 | 15 | 1 | 4.28 | 1.15 |
103- * \+------------------+-----------------+--------+------------+
104- */
105- inline int16_t sin_fixed_16b (int32_t th_rad_fxp )
106- {
107- int32_t sign ;
108- int32_t b_yn ;
109- int32_t xn ;
110- int32_t th_cdc_fxp ;
111- cordic_cfg type = EN_16B_CORDIC_SINE ;
112- /* compute coeff from angles*/
113- cordic_sin_cos (th_rad_fxp , type , & sign , & b_yn , & xn , & th_cdc_fxp );
114- th_cdc_fxp = sign * b_yn ;
115- /*convert Q1.31 to Q1.15 format*/
116- return sat_int16 (Q_SHIFT_RND ((sat_int32 (Q_SHIFT_LEFT ((int64_t )th_cdc_fxp , 30 , 31 ))),
117- 31 , 15 ));
118- }
119-
120- /**
121- * \Compute fixed point cordic cosine with table lookup and interpolation
122- * \The cordic cos algorithm converges, when the angle is in the range
123- * \[-pi/2, pi/2).If an angle is outside of this range, then a multiple of
124- * \pi/2 is added or subtracted from the angle until it is within the range
125- * \[-pi/2,pi/2).Start with the angle in the range [-2*pi, 2*pi) and output
126- * \has range in [-1.0 to 1.0]
127- * \+------------------+-----------------+--------+------------+
128- * \| thRadFxp | cdccosth |thRadFxp| cdccosth|
129- * \+----+-----+-------+----+----+-------+--------+------------+
130- * \|WLen| FLen|Signbit|WLen|FLen|Signbit| Qformat| Qformat |
131- * \+----+-----+-------+----+----+-------+--------+------------+
132- * \| 32 | 28 | 1 | 32 | 15 | 1 | 4.28 | 1.15 |
133- * \+------------------+-----------------+--------+------------+
134- */
135- inline int16_t cos_fixed_16b (int32_t th_rad_fxp )
136- {
137- int32_t sign ;
138- int32_t b_yn ;
139- int32_t xn ;
140- int32_t th_cdc_fxp ;
141- cordic_cfg type = EN_16B_CORDIC_COSINE ;
142- /* compute coeff from angles*/
143- cordic_sin_cos (th_rad_fxp , type , & sign , & b_yn , & xn , & th_cdc_fxp );
144- th_cdc_fxp = sign * xn ;
145- /*convert Q1.31 to Q1.15 format*/
146- return sat_int16 (Q_SHIFT_RND ((sat_int32 (Q_SHIFT_LEFT ((int64_t )th_cdc_fxp , 30 , 31 ))),
147- 31 , 15 ));
148- }
149-
15036/**
15137 * \CORDIC-based approximation of sine and cosine
15238 */
0 commit comments