/** * @file xmc_math.h * @date 2015-10-08 * * @cond ********************************************************************************** * XMClib v2.1.8 - XMC Peripheral Driver Library * * Copyright (c) 2015-2016, Infineon Technologies AG * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification,are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * Neither the name of the copyright holders nor the names of its contributors * may be used to endorse or promote products derived from this software without * specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * To improve the quality of the software, users are encouraged to share * modifications, enhancements or bug fixes with Infineon Technologies AG * dave@infineon.com). ********************************************************************************** * * Change History * -------------- * * 2015-06-20: * - Removed version macros and declaration of GetDriverVersion API
* - Updated copyright and change history section. * * 2015-08-25: * - XMC_MATH_ClearEvent() API is updated to set the event clear flag bit.
* * 2015-09-23: * - Added SQRT functions * * 2015-10-08: * - Return values for sin(), cos(), sinh(), cosh(), arctan() are corrected. * * @endcond * */ #ifndef XMC_MATH_H #define XMC_MATH_H #ifdef __cplusplus extern "C" { #endif /********************************************************************************************************************* * HEADER FILES ********************************************************************************************************************/ #include #if defined(MATH) #include /** * @addtogroup XMClib * @{ */ /** * @addtogroup MATH * @{ * @brief MATH Coprocessor (MATH) driver for the XMC1302 microcontroller family
* * The MATH Coprocessor (MATH) module comprises of two independent sub-blocks to support the CPU in math-intensive * computations: a Divider Unit (DIV) for signed and unsigned 32-bit division operations and a CORDIC * (COrdinate Rotation DIgital Computer) Coprocessor for computation of trigonometric, linear or hyperbolic functions.
* * MATH driver features: * -# CORDIC Coprocessor is used for computation of trigonometric and hyperbolic functions * -# Supports result chaining between the Divider Unit and CORDIC Coprocessor * -# All MATH APIs are available in Blocking and non-blocking modes. Non-blocking APIs are suffixed with NB. * -# 32bit signed and unsigned division implementations available for __aeabi_uidiv(), __aeabi_idiv(), __aeabi_uidivmod(), __aeabi_idivmod() * -# Divider and CORDIC unit busy status can be checked by XMC_MATH_DIV_IsBusy() and XMC_MATH_CORDIC_IsBusy() * -# Individual APIs available to return the result of each non-blocking MATH function * * Note:
* All non-blocking MATH APIs are not atomic and hence occurence of interrupts during the normal execution of * these APIs may lead to erroneous results. User has to exercise caution while using these APIs. * * Example: * Execution of divide instruction (/) in an ISR during the normal execution of non-blocking APIs may give erroneous results. * */ /********************************************************************************************************************* * TYPE DEFINITIONS ********************************************************************************************************************/ /** * @brief This typedef is used for Input and Output Data representation in blocking & non-blocking functions. * XMC_MATH_Q0_23_t => 1 Signed bit, 0 Integer bits, 23 fraction bits. */ typedef int32_t XMC_MATH_Q0_23_t; /** * @brief This typedef is used for Input Data representation in blocking & non-blocking functions. * XMC_MATH_Q8_15_t => 1 Signed bit, 8 Integer bits, 15 fraction bits. */ typedef int32_t XMC_MATH_Q8_15_t; /** * @brief This typedef is used for Output Data representation in blocking & non-blocking functions. * XMC_MATH_Q1_22_t => 1 Signed bit, 1 Integer bits, 22 fraction bits. */ typedef int32_t XMC_MATH_Q1_22_t; /** * @brief This typedef is used for Output Data representation in blocking & non-blocking functions. * XMC_MATH_Q0_11_t => 1 Signed bit, 0 Integer bits, 11 fraction bits. */ typedef int32_t XMC_MATH_Q0_11_t; /********************************************************************************************************************* * MACROS ********************************************************************************************************************/ /* Utility macros */ #define XMC_MATH_Q0_23(x) ((XMC_MATH_Q0_23_t)(((x) >= 0) ? ((x) * (1 << 23) + 0.5) : ((x) * (1 << 23) - 0.5))) /**< Converts the given number to XMC_MATH_Q0_23_t format */ #define XMC_MATH_Q0_11(x) ((XMC_MATH_Q0_11_t)(((x) >= 0) ? ((x) * (1 << 11) + 0.5) : ((x) * (1 << 11) - 0.5))) /**< Converts the given number to XMC_MATH_Q0_11_t format */ /********************************************************************************************************************* * ENUMS ********************************************************************************************************************/ /** * @brief Service request events for the DIV and CORDIC modules */ typedef enum XMC_MATH_EVENT { XMC_MATH_EVENT_DIV_END_OF_CALC = 1U, /**< Divider end of calculation event */ XMC_MATH_EVENT_DIV_ERROR = 2U, /**< Divider error event */ XMC_MATH_EVENT_CORDIC_END_OF_CALC = 4U, /**< CORDIC end of calculation event */ XMC_MATH_EVENT_CORDIC_ERROR = 8U /**< CORDIC error event */ } XMC_MATH_EVENT_t; /** * @brief Dividend Register Result Chaining */ typedef enum XMC_MATH_DIV_DVDRC { XMC_MATH_DIV_DVDRC_DISABLED = 0U << MATH_GLBCON_DVDRC_Pos, /**< No result chaining is selected */ XMC_MATH_DIV_DVDRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_DVDRC_Pos, /**< QUOT register is the selected source */ XMC_MATH_DIV_DVDRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_DVDRC_Pos, /**< RMD register is the selected source */ XMC_MATH_DIV_DVDRC_CORRX_IS_SOURCE = 3U << MATH_GLBCON_DVDRC_Pos, /**< CORRX is the selected source */ XMC_MATH_DIV_DVDRC_CORRY_IS_SOURCE = 4U << MATH_GLBCON_DVDRC_Pos, /**< CORRY is the selected source */ XMC_MATH_DIV_DVDRC_CORRZ_IS_SOURCE = 5U << MATH_GLBCON_DVDRC_Pos /**< CORRZ is the selected source */ } XMC_MATH_DIV_DVDRC_t; /** * @brief Divisor Register Result Chaining */ typedef enum XMC_MATH_DIV_DVSRC { XMC_MATH_DIV_DVSRC_DISABLED = 0U << MATH_GLBCON_DVSRC_Pos, /**< No result chaining is selected */ XMC_MATH_DIV_DVSRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_DVSRC_Pos, /**< QUOT register is the selected source */ XMC_MATH_DIV_DVSRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_DVSRC_Pos, /**< RMD register is the selected source */ XMC_MATH_DIV_DVSRC_CORRX_IS_SOURCE = 3U << MATH_GLBCON_DVSRC_Pos, /**< CORRX is the selected source */ XMC_MATH_DIV_DVSRC_CORRY_IS_SOURCE = 4U << MATH_GLBCON_DVSRC_Pos, /**< CORRY is the selected source */ XMC_MATH_DIV_DVSRC_CORRZ_IS_SOURCE = 5U << MATH_GLBCON_DVSRC_Pos /**< CORRZ is the selected source */ } XMC_MATH_DIV_DVSRC_t; /** * @brief CORDX Register Result Chaining */ typedef enum XMC_MATH_CORDIC_CORDXRC { XMC_MATH_CORDIC_CORDXRC_DISABLED = 0U << MATH_GLBCON_CORDXRC_Pos, /**< No result chaining is selected */ XMC_MATH_CORDIC_CORDXRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_CORDXRC_Pos, /**< QUOT register is the selected source */ XMC_MATH_CORDIC_CORDXRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_CORDXRC_Pos /**< RMD register is the selected source */ } XMC_MATH_CORDIC_CORDXRC_t; /** * @brief CORDY Register Result Chaining */ typedef enum XMC_MATH_CORDIC_CORDYRC { XMC_MATH_CORDIC_CORDYRC_DISABLED = 0U << MATH_GLBCON_CORDYRC_Pos, /**< No result chaining is selected */ XMC_MATH_CORDIC_CORDYRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_CORDYRC_Pos, /**< QUOT register is the selected source */ XMC_MATH_CORDIC_CORDYRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_CORDYRC_Pos /**< RMD register is the selected source */ } XMC_MATH_CORDIC_CORDYRC_t; /** * @brief CORDZ Register Result Chaining */ typedef enum XMC_MATH_CORDIC_CORDZRC { XMC_MATH_CORDIC_CORDZRC_DISABLED = 0U << MATH_GLBCON_CORDZRC_Pos, /**< No result chaining is selected */ XMC_MATH_CORDIC_CORDZRC_QUOT_IS_SOURCE = 1U << MATH_GLBCON_CORDZRC_Pos, /**< QUOT register is the selected source */ XMC_MATH_CORDIC_CORDZRC_RMD_IS_SOURCE = 2U << MATH_GLBCON_CORDZRC_Pos /**< RMD register is the selected source */ } XMC_MATH_CORDIC_CORDZRC_t; /** * @brief CORDIC operating mode */ typedef enum XMC_MATH_CORDIC_OPERATING_MODE { XMC_MATH_CORDIC_OPERATING_MODE_LINEAR = 0U << MATH_CON_MODE_Pos, /**< Linear mode */ XMC_MATH_CORDIC_OPERATING_MODE_CIRCULAR = 1U << MATH_CON_MODE_Pos, /**< Circular mode */ XMC_MATH_CORDIC_OPERATING_MODE_HYPERBOLIC = 3U << MATH_CON_MODE_Pos /**< Hyperbolic mode */ } XMC_MATH_CORDIC_OPERATING_MODE_t; /** * @brief Rotation vectoring selection */ typedef enum XMC_MATH_CORDIC_ROTVEC_MODE { XMC_MATH_CORDIC_ROTVEC_MODE_VECTORING = 0U << MATH_CON_ROTVEC_Pos, /**< Vectoring mode */ XMC_MATH_CORDIC_ROTVEC_MODE_ROTATION = 1U << MATH_CON_ROTVEC_Pos /**< Rotation mode */ } XMC_MATH_CORDIC_ROTVEC_MODE_t; /** * @brief Calculated value of CORRX and CORRY are each divided by this factor to yield the result. */ typedef enum XMC_MATH_CORDIC_MAGNITUDE { XMC_MATH_CORDIC_MAGNITUDE_DIVBY1 = 0U << MATH_CON_MPS_Pos, /**< Divide by 1 */ XMC_MATH_CORDIC_MAGNITUDE_DIVBY2 = 1U << MATH_CON_MPS_Pos, /**< Divide by 2 */ XMC_MATH_CORDIC_MAGNITUDE_DIVBY4 = 2U << MATH_CON_MPS_Pos, /**< Divide by 4 */ } XMC_MATH_CORDIC_MAGNITUDE_t; /********************************************************************************************************************* * DATA STRUCTURES ********************************************************************************************************************/ /********************************************************************************************************************* * API Prototypes - General ********************************************************************************************************************/ /** * * @return None * * \parDescription:
* Enables the Math module by un-gating the clock. * * \par * MATH coprocessor's clock is enabled by setting \a MATH bit of \a CGATCLR0 register. * * \parRelated APIs:
* XMC_MATH_Disable()\n\n\n * */ __STATIC_INLINE void XMC_MATH_Enable(void) { /* Un-gates clock to the MATH kernel */ XMC_SCU_CLOCK_UngatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_MATH); } /** * * @return None * * \parDescription:
* Disables the Math module by gating the clock. * * \par * MATH coprocessor's clock is disabled by setting \a MATH bit of \a CGATSET0 register. * * \parRelated APIs:
* XMC_MATH_Disable()\n\n\n * */ __STATIC_INLINE void XMC_MATH_Disable(void) { /* Gates clock to the MATH kernel */ XMC_SCU_CLOCK_GatePeripheralClock(XMC_SCU_PERIPHERAL_CLOCK_MATH); } /** * * @return bool \n * true - if DIV unit is busy * false - if DIV unit is not busy * * \parDescription:
* Utility function to check if the DIV unit is busy. * * \par * Divider unit status is determined by reading \a BSY bit of \a DIVST register. * */ bool XMC_MATH_DIV_IsBusy(void); /** * * @return bool \n * true - if CORDIC unit is busy\n * false - if CORDIC unit is not busy * * \parDescription:
* Utility function to check if the DIV unit is busy. * * \par * CORDIC coprocessor's status is determined by reading \a BSY bit of \a STATC register. * */ bool XMC_MATH_CORDIC_IsBusy(void); /** * @param event Event of type XMC_MATH_EVENT_t * * @return bool\n * true - if status is set\n * false - if status is not set * * \parDescription:
* Returns the status of the requested event. * * \par * Status of DIV & CORDIC unit's event (end of calculation & error) status is determined by reading \a EVFR register. * * \parRelated APIs:
* XMC_MATH_EnableEvent(), XMC_MATH_DisableEvent(), XMC_MATH_SetEvent(), XMC_MATH_ClearEvent()\n\n\n * */ bool XMC_MATH_GetEventStatus(const XMC_MATH_EVENT_t event); /** * @param event Event of type XMC_MATH_EVENT_t * * @return None * * \parDescription:
* Enables the requested event. * * \par * DIV & CORDIC unit's event (end of calculation & error) is enabled by setting bit-fields of \a EVIER register. * * \parRelated APIs:
* XMC_MATH_GetEventStatus(), XMC_MATH_DisableEvent()\n\n\n * */ __STATIC_INLINE void XMC_MATH_EnableEvent(const XMC_MATH_EVENT_t event) { MATH->EVIER |= (uint32_t) event; } /** * @param event Event of type XMC_MATH_EVENT_t * * @return None * * \parDescription:
* Disables the requested event. * * \par * DIV & CORDIC unit's event (end of calculation & error) is disabled by clearing bit-fields of \a EVIER register. * * \parRelated APIs:
* XMC_MATH_GetEventStatus(), XMC_MATH_EnableEvent()\n\n\n * */ __STATIC_INLINE void XMC_MATH_DisableEvent(const XMC_MATH_EVENT_t event) { MATH->EVIER &= ~((uint32_t) event); } /** * @param event Event of type XMC_MATH_EVENT_t * * @return None * * \parDescription:
* Sets the requested event. This is a software setting for the event. * * \par * DIV & CORDIC unit's event (end of calculation & error) is set by setting bit-fields of \a EVFSR register. * * \parRelated APIs:
* XMC_MATH_ClearEvent()\n\n\n * */ __STATIC_INLINE void XMC_MATH_SetEvent(const XMC_MATH_EVENT_t event) { MATH->EVFSR |= (uint32_t) event; } /** * @param event Event of type XMC_MATH_EVENT_t * * @return None * * \parDescription:
* Clears the requested event. * * \par * DIV & CORDIC unit's event (end of calculation & error) is cleared by setting bit-fields of \a EVFCR register. * * \parRelated APIs:
* XMC_MATH_SetEvent()\n\n\n * */ __STATIC_INLINE void XMC_MATH_ClearEvent(const XMC_MATH_EVENT_t event) { MATH->EVFCR |= (uint32_t) event; } /** * @return XMC_MATH_Q0_23_t * * \parDescription:
* Returns result of a Cosine operation. * * \par * Most significant 24 bits of \a CORRX register returns the result of Cosine operation. * * \parRelated APIs:
* XMC_MATH_CORDIC_CosNB()\n\n\n * */ __STATIC_INLINE XMC_MATH_Q0_23_t XMC_MATH_CORDIC_GetCosResult(void) { return ((XMC_MATH_Q0_23_t) (((int32_t)MATH->CORRX) >> MATH_CORRX_RESULT_Pos)); } /** * @return XMC_MATH_Q0_23_t * * \parDescription:
* Returns result of a Sine operation. * * \par * Most significant 24 bits of \a CORRY register returns the result of Sine operation. * * \parRelated APIs:
* XMC_MATH_CORDIC_SinNB()\n\n\n * */ __STATIC_INLINE XMC_MATH_Q0_23_t XMC_MATH_CORDIC_GetSinResult(void) { return ((XMC_MATH_Q0_23_t) (((int32_t)MATH->CORRY) >> MATH_CORRY_RESULT_Pos)); } /** * @return XMC_MATH_Q0_11_t * * \parDescription:
* Returns result of a Tangent operation. * * \par * \a QUOT register returns the result of Tangent operation. * * \parRelated APIs:
* XMC_MATH_CORDIC_TanNB()\n\n\n * */ __STATIC_INLINE XMC_MATH_Q0_11_t XMC_MATH_CORDIC_GetTanResult(void) { return ((XMC_MATH_Q0_11_t) MATH->QUOT); } /** * @return XMC_MATH_Q0_23_t * * \parDescription:
* Returns result of a Arc Tangent operation. * * \par * Most significant 24 bits of \a CORRZ register returns the result of Arc Tangent operation. * * \parRelated APIs:
* XMC_MATH_CORDIC_ArcTanNB()\n\n\n * */ __STATIC_INLINE XMC_MATH_Q0_23_t XMC_MATH_CORDIC_GetArcTanResult(void) { return ((XMC_MATH_Q0_23_t) (((int32_t)MATH->CORRZ) >> MATH_CORRZ_RESULT_Pos)); } /** * @return XMC_MATH_Q1_22_t * * \parDescription:
* Returns result of a Hyperbolic Cosine operation. * * \par * Most significant 24 bits of \a CORRX register returns the result of Hyperbolic Cosine operation. * * \parRelated APIs:
* XMC_MATH_CORDIC_CoshNB()\n\n\n * */ __STATIC_INLINE XMC_MATH_Q1_22_t XMC_MATH_CORDIC_GetCoshResult(void) { return ((XMC_MATH_Q1_22_t) (((int32_t)MATH->CORRX) >> MATH_CORRX_RESULT_Pos)); } /** * @return XMC_MATH_Q1_22_t * * \parDescription:
* Returns result of a Hyperbolic Sine operation. * * \par * Most significant 24 bits of \a CORRY register returns the result of Hyperbolic Sine operation. * * \parRelated APIs:
* XMC_MATH_CORDIC_SinhNB()\n\n\n * */ __STATIC_INLINE XMC_MATH_Q1_22_t XMC_MATH_CORDIC_GetSinhResult(void) { return ((XMC_MATH_Q1_22_t) (((int32_t)MATH->CORRY) >> MATH_CORRY_RESULT_Pos)); } /** * @return XMC_MATH_Q0_11_t * * \parDescription:
* Returns result of a Hyperbolic Tangent operation. * * \par * \a QUOT register returns the result of Hyperbolic Tangent operation. * * \parRelated APIs:
* XMC_MATH_CORDIC_TanhNB()\n\n\n * */ __STATIC_INLINE XMC_MATH_Q0_11_t XMC_MATH_CORDIC_GetTanhResult(void) { return ((XMC_MATH_Q0_11_t) MATH->QUOT); } /** * @return uint32_t * * \parDescription:
* Returns result of a Unsigned Division operation. * * \par * \a QUOT register returns the result of Unsigned Division operation. * * \parRelated APIs:
* XMC_MATH_DIV_UnsignedDivNB()\n\n\n * */ __STATIC_INLINE uint32_t XMC_MATH_DIV_GetUnsignedDivResult(void) { return ((uint32_t) MATH->QUOT); } /** * @return uint32_t * * \parDescription:
* Returns result of a Unsigned Modulo operation. * * \par * \a RMD register returns the result of Unsigned Modulo operation. * * \parRelated APIs:
* XMC_MATH_DIV_UnsignedModNB()\n\n\n * */ __STATIC_INLINE uint32_t XMC_MATH_DIV_GetUnsignedModResult(void) { return ((uint32_t) MATH->RMD); } /** * @return int32_t * * \parDescription:
* Returns result of a Signed Division operation. * * \par * \a QUOT register returns the result of Signed Division operation. * * \parRelated APIs:
* XMC_MATH_DIV_SignedDivNB()\n\n\n * */ __STATIC_INLINE int32_t XMC_MATH_DIV_GetSignedDivResult(void) { return ((int32_t) MATH->QUOT); } /** * @return int32_t * * \parDescription:
* Returns result of a Signed Modulo operation. * * \par * \a RMD register returns the result of Signed Modulo operation. * * \parRelated APIs:
* XMC_MATH_DIV_SignedModNB()\n\n\n * */ __STATIC_INLINE int32_t XMC_MATH_DIV_GetSignedModResult(void) { return ((int32_t) MATH->RMD); } /*********************************************************************************************************************** * API Prototypes - Blocking functions **********************************************************************************************************************/ /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return XMC_MATH_Q0_23_t
* * \parDescription:
* Computes the cosine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * * \par * This function programs CORDIC to rotation & circular mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023. * Most significant 24 bits of \a CORRX register returns the result of the operation. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_Sin(), XMC_MATH_CORDIC_Tan()\n\n\n * */ XMC_MATH_Q0_23_t XMC_MATH_CORDIC_Cos(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return XMC_MATH_Q0_23_t
* * \parDescription:
* Computes the sine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * * \par * This function programs CORDIC to rotation & circular mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023. * Most significant 24 bits of \a CORRY register returns the result of the operation. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_Cos(), XMC_MATH_CORDIC_Tan()\n\n\n * */ XMC_MATH_Q0_23_t XMC_MATH_CORDIC_Sin(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return XMC_MATH_Q0_11_t
* * \parDescription:
* Computes the tangent for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * * \par * This function programs CORDIC to rotation & circular mode. * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and divisor by configuring \a GLBCON register. * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023. * Most significant 24 bits of \a CORRY register returns the result of the operation. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_Sin(), XMC_MATH_CORDIC_Cos()\n\n\n * */ XMC_MATH_Q0_11_t XMC_MATH_CORDIC_Tan(XMC_MATH_Q0_23_t angle_in_radians); /** * * @param x Value representing the proportion of the x-coordinate (XMC_MATH_Q8_15_t format) * @param y Value representing the proportion of the y-coordinate (XMC_MATH_Q8_15_t format) * * @return XMC_MATH_Q0_23_t
* * \parDescription:
* Computes the principal value arc tangent of an angle of y/x expressed in radians. * The input radians must be in XMC_MATH_Q8_15_t format. * * \par * This function programs CORDIC as circular mode. * \a CORDY register is programmed with input \a y and \a CORDX register is programmed with input \a x. * Most significant 24 bits of \a CORRZ register returns the result of the operation. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * */ XMC_MATH_Q0_23_t XMC_MATH_CORDIC_ArcTan(XMC_MATH_Q8_15_t x, XMC_MATH_Q8_15_t y); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return XMC_MATH_Q1_22_t
* * \parDescription:
* Computes the hyperbolic cosine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * * \par * This function programs CORDIC to rotation & hyperbolic mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22. * Most significant 24 bits of \a CORRX register returns the result of the operation. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_Sinh(), XMC_MATH_CORDIC_Tanh()\n\n\n * */ XMC_MATH_Q1_22_t XMC_MATH_CORDIC_Cosh(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return XMC_MATH_Q1_22_t
* * \parDescription:
* Computes the hyperbolic sine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * * \par * This function programs CORDIC to rotation & hyperbolic mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22. * Most significant 24 bits of \a CORRY register returns the result of the operation. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_Cosh(), XMC_MATH_CORDIC_Tanh()\n\n\n * */ XMC_MATH_Q1_22_t XMC_MATH_CORDIC_Sinh(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return XMC_MATH_Q0_11_t
* * \parDescription:
* Computes the hyperbolic tangent for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * * \par * This function programs CORDIC to rotation & hyperbolic mode. * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and divisor by configuring \a GLBCON register. * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22. * \a QUOT register returns the result of the operation. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_Sinh(), XMC_MATH_CORDIC_Cosh()()\n\n\n * */ XMC_MATH_Q0_11_t XMC_MATH_CORDIC_Tanh(XMC_MATH_Q0_23_t angle_in_radians); /*********************************************************************************************************************** * API Prototypes - Non blocking functions **********************************************************************************************************************/ /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return None
* * \parDescription:
* Computes the cosine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * Call XMC_MATH_CORDIC_GetCosResult() API to get the result. * * \par * This function programs CORDIC to rotation & circular mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_GetCosResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_CORDIC_CosNB(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return None
* * \parDescription:
* Computes the sine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * Call XMC_MATH_CORDIC_GetSinResult() API to get the result. * * \par * This function programs CORDIC to rotation & circular mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_GetSinResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_CORDIC_SinNB(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return None
* * \parDescription:
* Computes the tangent for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * Call XMC_MATH_CORDIC_GetTanResult() API to get the result. * * \par * This function programs CORDIC to rotation & circular mode. * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and divisor by configuring \a GLBCON register. * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_CIRCULAR_GAIN_IN_Q023. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_GetTanResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_CORDIC_TanNB(XMC_MATH_Q0_23_t angle_in_radians); /** * * @param x Value representing the proportion of the x-coordinate (XMC_MATH_Q8_15_t format) * @param y Value representing the proportion of the y-coordinate (XMC_MATH_Q8_15_t format) * * @return None
* * \parDescription:
* Computes the principal value arc tangent of an angle of y/x expressed in radians. * The input radians must be in XMC_MATH_Q8_15_t format. * Call XMC_MATH_CORDIC_GetArcTanResult() API to get the result. * * \par * This function programs CORDIC as circular mode. * \a CORDY register is programmed with input \a y and \a CORDX register is programmed with input \a x. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_GetArcTanResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_CORDIC_ArcTanNB(XMC_MATH_Q8_15_t x, XMC_MATH_Q8_15_t y); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return None
* * \parDescription:
* Computes the hyperbolic cosine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * Call XMC_MATH_CORDIC_GetCoshResult() API to get the result. * * \par * This function programs CORDIC to rotation & hyperbolic mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_GetCoshResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_CORDIC_CoshNB(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return None
* * \parDescription:
* Computes the hyperbolic sine for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * Call XMC_MATH_CORDIC_GetSinhResult() API to get the result. * * \par * This function programs CORDIC to rotation & hyperbolic mode. * Configures \a CORDZ register with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_GetSinhResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_CORDIC_SinhNB(XMC_MATH_Q0_23_t angle_in_radians); /** * @param angle_in_radians - Normalised Angle in Radians (XMC_MATH_Q0_23_t format) * * @return None
* * \parDescription:
* Computes the hyperbolic tangent for an angle in radians \e angle_in_radians. * The input angle in radians must be in XMC_MATH_Q0_23_t format. * Call XMC_MATH_CORDIC_GetTanhResult() API to get the result. * * \par * This function programs CORDIC to rotation & hyperbolic mode. * Chains the results of Cosine (\a CORRX) and Sine (\a CORRY) as a dividend and divisor by configuring \a GLBCON register. * \a CORDZ register is programmed with input \a angle_in_radians and \a CORDX register with gain \a XMC_MATH_RECIPROC_HYPERBOLIC_GAIN_IN_Q1_22. * * \parNote:
* Loading of \a CORDX register triggers the start of computation. * * \parRelated APIs:
* XMC_MATH_CORDIC_GetTanhResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_CORDIC_TanhNB(XMC_MATH_Q0_23_t angle_in_radians); /** * @param dividend - Dividend * @param divisor - Divisor * * @return None
* * \parDescription:
* Performs unsigned integer division and computes quotient of the division. * Call XMC_MATH_DIV_GetUnsignedDivResult() API to get the result. * * \par * Divider unit is configured for unsigned division. * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values. * The division is started with the write to DVS register. * * \parNote:
* Ensure \e divisor is smaller than \e dividend. * * \parRelated APIs:
* XMC_MATH_DIV_GetUnsignedDivResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_DIV_UnsignedDivNB(uint32_t dividend, uint32_t divisor); /** * @param dividend - Dividend * @param divisor - Divisor * * @return None
* * \parDescription:
* Performs signed integer division and computes quotient of the division. * Call XMC_MATH_DIV_GetSignedDivResult() API to get the result. * * \par * Divider unit is configured for signed division. * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values. * The division is started with the write to DVS register. * * \parNote:
* Ensure \e divisor is smaller than \e dividend. * * \parRelated APIs:
* XMC_MATH_DIV_GetSignedDivResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_DIV_SignedDivNB(int32_t dividend, int32_t divisor); /** * @param dividend - Dividend * @param divisor - Divisor * * @return None
* * \parDescription:
* Performs unsigned modulo operation and computes remainder of the division. * Call XMC_MATH_DIV_GetUnsignedModResult() API to get the result. * * \par * Divider unit is configured for unsigned division. * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values. * The division is started with the write to DVS register. * * \parNote:
* Ensure \e divisor is smaller than \e dividend. * * \parRelated APIs:
* XMC_MATH_DIV_GetUnsignedModResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_DIV_UnsignedModNB(uint32_t dividend, uint32_t divisor); /** * @param dividend - Dividend * @param divisor - Divisor * * @return None
* * \parDescription:
* Performs signed modulo operation and computes remainder of the division. * Call XMC_MATH_DIV_GetSignedModResult() API to get the result. * * \par * Divider unit is configured for signed division. * \a DVD & \a DVS registers are programmed with \a dividend and \a divisor values. * The division is started with the write to DVS register. * * \parNote:
* Ensure \e divisor is smaller than \e dividend. * * \parRelated APIs:
* XMC_MATH_DIV_GetSignedModResult(), XMC_MATH_EnableEvent(), XMC_MATH_GetEventStatus(), XMC_MATH_ClearEvent()\n\n\n * */ void XMC_MATH_DIV_SignedModNB(int32_t dividend, int32_t divisor); /** * @param x - Value whose square root is computed * * @return Square root of x
* * \parDescription:
* Computes square root of Q15 number * * \parNote:
* x > 0 * */ int16_t XMC_MATH_CORDIC_Q15_Sqrt(int16_t x); /** * @param x - Value whose square root is computed * * @return Square root of x
* * \parDescription:
* Computes square root of Q31 number * * \parNote:
* x > 0 * */ int32_t XMC_MATH_CORDIC_Q31_Sqrt(int32_t x); /** * @} */ /** * @} */ #endif /* end of #if defined(MATH) */ #ifdef __cplusplus } #endif #endif /* XMC_MATH_H */