Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2011 Broadcom Corporation
0003  *
0004  * Permission to use, copy, modify, and/or distribute this software for any
0005  * purpose with or without fee is hereby granted, provided that the above
0006  * copyright notice and this permission notice appear in all copies.
0007  *
0008  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
0009  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
0010  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
0011  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
0012  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
0013  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
0014  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
0015  */
0016 #ifndef __CORDIC_H_
0017 #define __CORDIC_H_
0018 
0019 #include <linux/types.h>
0020 
0021 #define CORDIC_ANGLE_GEN    39797
0022 #define CORDIC_PRECISION_SHIFT  16
0023 #define CORDIC_NUM_ITER (CORDIC_PRECISION_SHIFT + 2)
0024 
0025 #define CORDIC_FIXED(X) ((s32)((X) << CORDIC_PRECISION_SHIFT))
0026 #define CORDIC_FLOAT(X) (((X) >= 0) \
0027         ? ((((X) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1) \
0028         : -((((-(X)) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1))
0029 
0030 /**
0031  * struct cordic_iq - i/q coordinate.
0032  *
0033  * @i: real part of coordinate (in phase).
0034  * @q: imaginary part of coordinate (quadrature).
0035  */
0036 struct cordic_iq {
0037     s32 i;
0038     s32 q;
0039 };
0040 
0041 /**
0042  * cordic_calc_iq() - calculates the i/q coordinate for given angle.
0043  *
0044  * @theta: angle in degrees for which i/q coordinate is to be calculated.
0045  * @coord: function output parameter holding the i/q coordinate.
0046  *
0047  * The function calculates the i/q coordinate for a given angle using the
0048  * CORDIC algorithm. The coordinate consists of a real (i) and an
0049  * imaginary (q) part. The real part is essentially the cosine of the
0050  * angle and the imaginary part is the sine of the angle. The returned
0051  * values are scaled by 2^16 for precision. The range for theta is
0052  * for -180 degrees to +180 degrees. Passed values outside this range are
0053  * converted before doing the actual calculation.
0054  */
0055 struct cordic_iq cordic_calc_iq(s32 theta);
0056 
0057 #endif /* __CORDIC_H_ */