18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright (c) 2011 Broadcom Corporation
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any
58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above
68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
118c2ecf20Sopenharmony_ci * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
138c2ecf20Sopenharmony_ci * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci#ifndef __CORDIC_H_
178c2ecf20Sopenharmony_ci#define __CORDIC_H_
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <linux/types.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define CORDIC_ANGLE_GEN	39797
228c2ecf20Sopenharmony_ci#define CORDIC_PRECISION_SHIFT	16
238c2ecf20Sopenharmony_ci#define CORDIC_NUM_ITER	(CORDIC_PRECISION_SHIFT + 2)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define CORDIC_FIXED(X)	((s32)((X) << CORDIC_PRECISION_SHIFT))
268c2ecf20Sopenharmony_ci#define CORDIC_FLOAT(X)	(((X) >= 0) \
278c2ecf20Sopenharmony_ci		? ((((X) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1) \
288c2ecf20Sopenharmony_ci		: -((((-(X)) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1))
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/**
318c2ecf20Sopenharmony_ci * struct cordic_iq - i/q coordinate.
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci * @i: real part of coordinate (in phase).
348c2ecf20Sopenharmony_ci * @q: imaginary part of coordinate (quadrature).
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_cistruct cordic_iq {
378c2ecf20Sopenharmony_ci	s32 i;
388c2ecf20Sopenharmony_ci	s32 q;
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/**
428c2ecf20Sopenharmony_ci * cordic_calc_iq() - calculates the i/q coordinate for given angle.
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci * @theta: angle in degrees for which i/q coordinate is to be calculated.
458c2ecf20Sopenharmony_ci * @coord: function output parameter holding the i/q coordinate.
468c2ecf20Sopenharmony_ci *
478c2ecf20Sopenharmony_ci * The function calculates the i/q coordinate for a given angle using the
488c2ecf20Sopenharmony_ci * CORDIC algorithm. The coordinate consists of a real (i) and an
498c2ecf20Sopenharmony_ci * imaginary (q) part. The real part is essentially the cosine of the
508c2ecf20Sopenharmony_ci * angle and the imaginary part is the sine of the angle. The returned
518c2ecf20Sopenharmony_ci * values are scaled by 2^16 for precision. The range for theta is
528c2ecf20Sopenharmony_ci * for -180 degrees to +180 degrees. Passed values outside this range are
538c2ecf20Sopenharmony_ci * converted before doing the actual calculation.
548c2ecf20Sopenharmony_ci */
558c2ecf20Sopenharmony_cistruct cordic_iq cordic_calc_iq(s32 theta);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#endif /* __CORDIC_H_ */
58