Dependencies:   platform_drivers LTC26X6 AD77681

Committer:
jngarlitos
Date:
Mon Dec 06 05:22:28 2021 +0000
Revision:
1:9dd7c64b4a64
EVAL-CN0540-ARDZ mbed example program Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jngarlitos 1:9dd7c64b4a64 1 /* ----------------------------------------------------------------------
jngarlitos 1:9dd7c64b4a64 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
jngarlitos 1:9dd7c64b4a64 3 *
jngarlitos 1:9dd7c64b4a64 4 * $Date: 19. March 2015
jngarlitos 1:9dd7c64b4a64 5 * $Revision: V.1.4.5
jngarlitos 1:9dd7c64b4a64 6 *
jngarlitos 1:9dd7c64b4a64 7 * Project: CMSIS DSP Library
jngarlitos 1:9dd7c64b4a64 8 * Title: arm_sin_q31.c
jngarlitos 1:9dd7c64b4a64 9 *
jngarlitos 1:9dd7c64b4a64 10 * Description: Fast sine calculation for Q31 values.
jngarlitos 1:9dd7c64b4a64 11 *
jngarlitos 1:9dd7c64b4a64 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
jngarlitos 1:9dd7c64b4a64 13 *
jngarlitos 1:9dd7c64b4a64 14 * Redistribution and use in source and binary forms, with or without
jngarlitos 1:9dd7c64b4a64 15 * modification, are permitted provided that the following conditions
jngarlitos 1:9dd7c64b4a64 16 * are met:
jngarlitos 1:9dd7c64b4a64 17 * - Redistributions of source code must retain the above copyright
jngarlitos 1:9dd7c64b4a64 18 * notice, this list of conditions and the following disclaimer.
jngarlitos 1:9dd7c64b4a64 19 * - Redistributions in binary form must reproduce the above copyright
jngarlitos 1:9dd7c64b4a64 20 * notice, this list of conditions and the following disclaimer in
jngarlitos 1:9dd7c64b4a64 21 * the documentation and/or other materials provided with the
jngarlitos 1:9dd7c64b4a64 22 * distribution.
jngarlitos 1:9dd7c64b4a64 23 * - Neither the name of ARM LIMITED nor the names of its contributors
jngarlitos 1:9dd7c64b4a64 24 * may be used to endorse or promote products derived from this
jngarlitos 1:9dd7c64b4a64 25 * software without specific prior written permission.
jngarlitos 1:9dd7c64b4a64 26 *
jngarlitos 1:9dd7c64b4a64 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
jngarlitos 1:9dd7c64b4a64 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
jngarlitos 1:9dd7c64b4a64 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
jngarlitos 1:9dd7c64b4a64 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
jngarlitos 1:9dd7c64b4a64 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
jngarlitos 1:9dd7c64b4a64 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
jngarlitos 1:9dd7c64b4a64 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
jngarlitos 1:9dd7c64b4a64 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
jngarlitos 1:9dd7c64b4a64 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
jngarlitos 1:9dd7c64b4a64 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
jngarlitos 1:9dd7c64b4a64 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
jngarlitos 1:9dd7c64b4a64 38 * POSSIBILITY OF SUCH DAMAGE.
jngarlitos 1:9dd7c64b4a64 39 * -------------------------------------------------------------------- */
jngarlitos 1:9dd7c64b4a64 40
jngarlitos 1:9dd7c64b4a64 41 #include "arm_math.h"
jngarlitos 1:9dd7c64b4a64 42 #include "arm_common_tables.h"
jngarlitos 1:9dd7c64b4a64 43
jngarlitos 1:9dd7c64b4a64 44 /**
jngarlitos 1:9dd7c64b4a64 45 * @ingroup groupFastMath
jngarlitos 1:9dd7c64b4a64 46 */
jngarlitos 1:9dd7c64b4a64 47
jngarlitos 1:9dd7c64b4a64 48 /**
jngarlitos 1:9dd7c64b4a64 49 * @addtogroup sin
jngarlitos 1:9dd7c64b4a64 50 * @{
jngarlitos 1:9dd7c64b4a64 51 */
jngarlitos 1:9dd7c64b4a64 52
jngarlitos 1:9dd7c64b4a64 53 /**
jngarlitos 1:9dd7c64b4a64 54 * @brief Fast approximation to the trigonometric sine function for Q31 data.
jngarlitos 1:9dd7c64b4a64 55 * @param[in] x Scaled input value in radians.
jngarlitos 1:9dd7c64b4a64 56 * @return sin(x).
jngarlitos 1:9dd7c64b4a64 57 *
jngarlitos 1:9dd7c64b4a64 58 * The Q31 input value is in the range [0 +0.9999] and is mapped to a radian value in the range [0 2*pi). */
jngarlitos 1:9dd7c64b4a64 59
jngarlitos 1:9dd7c64b4a64 60 q31_t arm_sin_q31(
jngarlitos 1:9dd7c64b4a64 61 q31_t x)
jngarlitos 1:9dd7c64b4a64 62 {
jngarlitos 1:9dd7c64b4a64 63 q31_t sinVal; /* Temporary variables for input, output */
jngarlitos 1:9dd7c64b4a64 64 int32_t index; /* Index variables */
jngarlitos 1:9dd7c64b4a64 65 q31_t a, b; /* Four nearest output values */
jngarlitos 1:9dd7c64b4a64 66 q31_t fract; /* Temporary values for fractional values */
jngarlitos 1:9dd7c64b4a64 67
jngarlitos 1:9dd7c64b4a64 68 /* Calculate the nearest index */
jngarlitos 1:9dd7c64b4a64 69 index = (uint32_t)x >> FAST_MATH_Q31_SHIFT;
jngarlitos 1:9dd7c64b4a64 70
jngarlitos 1:9dd7c64b4a64 71 /* Calculation of fractional value */
jngarlitos 1:9dd7c64b4a64 72 fract = (x - (index << FAST_MATH_Q31_SHIFT)) << 9;
jngarlitos 1:9dd7c64b4a64 73
jngarlitos 1:9dd7c64b4a64 74 /* Read two nearest values of input value from the sin table */
jngarlitos 1:9dd7c64b4a64 75 a = sinTable_q31[index];
jngarlitos 1:9dd7c64b4a64 76 b = sinTable_q31[index+1];
jngarlitos 1:9dd7c64b4a64 77
jngarlitos 1:9dd7c64b4a64 78 /* Linear interpolation process */
jngarlitos 1:9dd7c64b4a64 79 sinVal = (q63_t)(0x80000000-fract)*a >> 32;
jngarlitos 1:9dd7c64b4a64 80 sinVal = (q31_t)((((q63_t)sinVal << 32) + ((q63_t)fract*b)) >> 32);
jngarlitos 1:9dd7c64b4a64 81
jngarlitos 1:9dd7c64b4a64 82 return sinVal << 1;
jngarlitos 1:9dd7c64b4a64 83 }
jngarlitos 1:9dd7c64b4a64 84
jngarlitos 1:9dd7c64b4a64 85 /**
jngarlitos 1:9dd7c64b4a64 86 * @} end of sin group
jngarlitos 1:9dd7c64b4a64 87 */