/*-1* Copyright (c) 2016 Adrian Chadd <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer,9* without modification.10* 2. Redistributions in binary form must reproduce at minimum a disclaimer11* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any12* redistribution must be conditioned upon including a substantially13* similar Disclaimer requirement for further binary redistribution.14*15* NO WARRANTY16* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS17* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT18* LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY19* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL20* THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,21* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS23* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER24* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)25* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF26* THE POSSIBILITY OF SUCH DAMAGES.27*/28#ifndef __IF_BWN_CORDIC_H__29#define __IF_BWN_CORDIC_H__3031/*32* These functions are used by the PHY code.33*/3435/* Complex number using 2 32-bit signed integers */36struct bwn_c32 {37int32_t i;38int32_t q;39};4041#define CORDIC_CONVERT(value) (((value) >= 0) ? \42((((value) >> 15) + 1) >> 1) : \43-((((-(value)) >> 15) + 1) >> 1))4445static const uint32_t bwn_arctg[] = {462949120, 1740967, 919879, 466945, 234379, 117304, 58666, 29335, 14668,477334, 3667, 1833, 917, 458, 229, 115, 57, 29,48};4950/* http://bcm-v4.sipsolutions.net/802.11/PHY/Cordic */51static inline struct bwn_c3252bwn_cordic(int theta)53{54uint8_t i;55int32_t tmp;56int8_t signx = 1;57uint32_t angle = 0;58struct bwn_c32 ret = { .i = 39797, .q = 0, };5960while (theta > (180 << 16))61theta -= (360 << 16);62while (theta < -(180 << 16))63theta += (360 << 16);6465if (theta > (90 << 16)) {66theta -= (180 << 16);67signx = -1;68} else if (theta < -(90 << 16)) {69theta += (180 << 16);70signx = -1;71}7273for (i = 0; i <= 17; i++) {74if (theta > angle) {75tmp = ret.i - (ret.q >> i);76ret.q += ret.i >> i;77ret.i = tmp;78angle += bwn_arctg[i];79} else {80tmp = ret.i + (ret.q >> i);81ret.q -= ret.i >> i;82ret.i = tmp;83angle -= bwn_arctg[i];84}85}8687ret.i *= signx;88ret.q *= signx;8990return ret;91}9293#endif /* __IF_BWN_CORDIC_H__ */949596