Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib: cordic: Move cordic macros and defines to header file

Now that these macros are in header file, we can eventually
clean up the duplicate macros present in the drivers that
utilize the same cordic algorithm implementation.

Also add CORDIC_ prefix to nonprefixed macros.

Reviewed-by: Arend van Spriel <arend.vanspriel@broadcom.com>
Signed-off-by: Priit Laes <plaes@plaes.org>
Acked-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>

authored by

Priit Laes and committed by
Kalle Valo
58d81d64 559afaa2

+16 -16
+9
include/linux/cordic.h
··· 18 18 19 19 #include <linux/types.h> 20 20 21 + #define CORDIC_ANGLE_GEN 39797 22 + #define CORDIC_PRECISION_SHIFT 16 23 + #define CORDIC_NUM_ITER (CORDIC_PRECISION_SHIFT + 2) 24 + 25 + #define CORDIC_FIXED(X) ((s32)((X) << CORDIC_PRECISION_SHIFT)) 26 + #define CORDIC_FLOAT(X) (((X) >= 0) \ 27 + ? ((((X) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1) \ 28 + : -((((-(X)) >> (CORDIC_PRECISION_SHIFT - 1)) + 1) >> 1)) 29 + 21 30 /** 22 31 * struct cordic_iq - i/q coordinate. 23 32 *
+7 -16
lib/cordic.c
··· 16 16 #include <linux/module.h> 17 17 #include <linux/cordic.h> 18 18 19 - #define CORDIC_ANGLE_GEN 39797 20 - #define CORDIC_PRECISION_SHIFT 16 21 - #define CORDIC_NUM_ITER (CORDIC_PRECISION_SHIFT + 2) 22 - 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)) 27 - 28 19 static const s32 arctan_table[] = { 29 20 2949120, 30 21 1740967, ··· 55 64 coord.q = 0; 56 65 angle = 0; 57 66 58 - theta = FIXED(theta); 67 + theta = CORDIC_FIXED(theta); 59 68 signtheta = (theta < 0) ? -1 : 1; 60 - theta = ((theta + FIXED(180) * signtheta) % FIXED(360)) - 61 - FIXED(180) * signtheta; 69 + theta = ((theta + CORDIC_FIXED(180) * signtheta) % CORDIC_FIXED(360)) - 70 + CORDIC_FIXED(180) * signtheta; 62 71 63 - if (FLOAT(theta) > 90) { 64 - theta -= FIXED(180); 72 + if (CORDIC_FLOAT(theta) > 90) { 73 + theta -= CORDIC_FIXED(180); 65 74 signx = -1; 66 - } else if (FLOAT(theta) < -90) { 67 - theta += FIXED(180); 75 + } else if (CORDIC_FLOAT(theta) < -90) { 76 + theta += CORDIC_FIXED(180); 68 77 signx = -1; 69 78 } 70 79