/* * Copyright (c) 2022, Shenzhen CVA Innovation CO.,LTD * All rights reserved. * * Shenzhen CVA Innovation CO.,LTD (CVA chip) is supplying this file for use * exclusively with CVA's microcontroller products. This file can be freely * distributed within development tools that are supporting such microcontroller * products. * * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. * CVA SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. */ #ifndef _IQMATH_H_ #define _IQMATH_H_ //! \brief This is the default floating point implementation of IQ math library. //! Almost all the platforms can use it, but some may come across //! the performance issue. So use it carefully unless you know what //! you are doing. //! //########################################################################### #ifndef _USING_CUSTOM_IQMATH_ //########################################################################### // The default floating point IQ math //=========================================================================== /******************************************************************************* * the includes ******************************************************************************/ #include #include #include #ifdef __cplusplus extern "C" { #endif /******************************************************************************* * the defines ******************************************************************************/ #define MATH_PI (3.1415926535897932384626433832795f) #define MATH_2PI (6.283185307179586476925286766559f) #define MATH_ONE_OVER_THREE (0.3333333333f) #define MATH_ONE_OVER_SQRT_THREE (0.5773502692f) #define MATH_SQRT_THREE_OVER_TWO (0.8660254038f) #define IQMATH_ONE_OVER_THREE (0.3333333333f) #define IQMATH_ONE_OVER_SQRT_THREE (0.5773502692f) #define IQMATH_SQRT_THREE_OVER_TWO (0.8660254038f) /******************************************************************************* * the typedefs ******************************************************************************/ typedef float _iq; /******************************************************************************* * the function prototypes ******************************************************************************/ #define _IQmpy2(A) ((A)*2.0f) #define _IQmpy4(A) ((A)*4.0f) #define _IQmpy8(A) ((A)*8.0f) #define _IQmpy16(A) ((A)*16.0f) #define _IQmpy32(A) ((A)*32.0f) #define _IQmpy64(A) ((A)*64.0f) #define _IQdiv2(A) ((A)*0.5f) #define _IQdiv4(A) ((A)*0.25f) #define _IQdiv8(A) ((A)*0.125f) #define _IQdiv16(A) ((A)*0.0625f) #define _IQdiv32(A) ((A)*0.03125f) #define _IQdiv64(A) ((A)*0.015625f) #define _IQ(A) (A) #define _IQtoF(A) (A) //! \note In case for some compiler version, __fmax and __fmin are not defined //! Add a simple implementation here #ifndef __fmax #define __fmax(A, B) (A>B ? A : B) #endif #ifndef __fmin #define __fmin(A, B) (A= 0.0f ? (atan2f(A,B)*(1.0f/6.283185307f)) : (1.0f + (atan2f(A,B)*(1.0f/6.283185307f)))) #define _IQsqrt(A) sqrtf(A) #define _IQisqrt(A) (1.0f/sqrtf(A)) #define _IQexp(A) expf(A) #define _IQint(A) ((long) (A)) #define _IQfrac(A) ((A) - (float)((long) (A))) #define _IQmag(A,B) sqrtf((A)*(A) + (B)*(B)) #define _IQabs(A) fabsf(A) #define _IQlog(A) logf(A) #ifdef __cplusplus } #endif /* extern "C" */ //########################################################################### #else //########################################################################### // The custom IQ math //=========================================================================== //! \note It's the user's duty to undefine the macros that are different with ones //! defined above in the "iqmathcustom.h", which must be put in this folder. //! \note When building some kind of library and we cannot access the BSW, just create //! and fake the MCU folder. //! #include "iqmathcustom.h" #endif #endif /* _IQMATH_H_ */