2
* Copyright (c) 2011 Broadcom Corporation
4
* Permission to use, copy, modify, and/or distribute this software for any
5
* purpose with or without fee is hereby granted, provided that the above
6
* copyright notice and this permission notice appear in all copies.
8
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
#include <linux/module.h>
17
#include <linux/cordic.h>
19
#define CORDIC_ANGLE_GEN 39797
20
#define CORDIC_PRECISION_SHIFT 16
21
#define CORDIC_NUM_ITER (CORDIC_PRECISION_SHIFT + 2)
23
#define FIXED(X) ((s32)((X) << CORDIC_PRECISION_SHIFT))
24
#define FLOAT(X) (((X) >= 0) \
25
? ((((X) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1) \
26
: -((((-(X)) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1))
28
static const s32 arctan_table[] = {
50
* cordic_calc_iq() - calculates the i/q coordinate for given angle
52
* theta: angle in degrees for which i/q coordinate is to be calculated
53
* coord: function output parameter holding the i/q coordinate
55
struct cordic_iq cordic_calc_iq(s32 theta)
57
struct cordic_iq coord;
63
coord.i = CORDIC_ANGLE_GEN;
68
signtheta = (theta < 0) ? -1 : 1;
69
theta = ((theta + FIXED(180) * signtheta) % FIXED(360)) -
70
FIXED(180) * signtheta;
72
if (FLOAT(theta) > 90) {
75
} else if (FLOAT(theta) < -90) {
80
for (iter = 0; iter < CORDIC_NUM_ITER; iter++) {
82
valtmp = coord.i - (coord.q >> iter);
83
coord.q += (coord.i >> iter);
84
angle += arctan_table[iter];
86
valtmp = coord.i + (coord.q >> iter);
87
coord.q -= (coord.i >> iter);
88
angle -= arctan_table[iter];
97
EXPORT_SYMBOL(cordic_calc_iq);
99
MODULE_DESCRIPTION("Cordic functions");
100
MODULE_AUTHOR("Broadcom Corporation");
101
MODULE_LICENSE("Dual BSD/GPL");