2 * Copyright (c) 2016 Adrian Chadd <adrian@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
13 * redistribution must be conditioned upon including a substantially
14 * similar Disclaimer requirement for further binary redistribution.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
20 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
22 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
27 * THE POSSIBILITY OF SUCH DAMAGES.
31 #ifndef __IF_BWN_CORDIC_H__
32 #define __IF_BWN_CORDIC_H__
35 * These functions are used by the PHY code.
38 /* Complex number using 2 32-bit signed integers */
44 #define CORDIC_CONVERT(value) (((value) >= 0) ? \
45 ((((value) >> 15) + 1) >> 1) : \
46 -((((-(value)) >> 15) + 1) >> 1))
48 static const uint32_t bwn_arctg[] = {
49 2949120, 1740967, 919879, 466945, 234379, 117304, 58666, 29335, 14668,
50 7334, 3667, 1833, 917, 458, 229, 115, 57, 29,
53 /* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */
54 static inline struct bwn_c32
61 struct bwn_c32 ret = { .i = 39797, .q = 0, };
63 while (theta > (180 << 16))
65 while (theta < -(180 << 16))
68 if (theta > (90 << 16)) {
71 } else if (theta < -(90 << 16)) {
76 for (i = 0; i <= 17; i++) {
78 tmp = ret.i - (ret.q >> i);
81 angle += bwn_arctg[i];
83 tmp = ret.i + (ret.q >> i);
86 angle -= bwn_arctg[i];
96 #endif /* __IF_BWN_CORDIC_H__ */