CMSIS DSP library

Dependents:   performance_timer Surfboard_ gps2rtty Capstone ... more

Legacy Warning

This is an mbed 2 library. To learn more about mbed OS 5, visit the docs.

Committer:
mbed_official
Date:
Fri Nov 20 08:45:18 2015 +0000
Revision:
5:3762170b6d4d
Parent:
3:7a284390b0ce
Synchronized with git revision 2eb940b9a73af188d3004a2575fdfbb05febe62b

Full URL: https://github.com/mbedmicro/mbed/commit/2eb940b9a73af188d3004a2575fdfbb05febe62b/

Added option to build rpc library. closes #1426

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 1:fdd22bb7aa52 1 /* ----------------------------------------------------------------------
mbed_official 5:3762170b6d4d 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
emilmont 1:fdd22bb7aa52 3 *
mbed_official 5:3762170b6d4d 4 * $Date: 19. March 2015
mbed_official 5:3762170b6d4d 5 * $Revision: V.1.4.5
emilmont 1:fdd22bb7aa52 6 *
emilmont 2:da51fb522205 7 * Project: CMSIS DSP Library
emilmont 2:da51fb522205 8 * Title: arm_fir_sparse_q7.c
emilmont 1:fdd22bb7aa52 9 *
emilmont 2:da51fb522205 10 * Description: Q7 sparse FIR filter processing function.
emilmont 1:fdd22bb7aa52 11 *
emilmont 1:fdd22bb7aa52 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
emilmont 1:fdd22bb7aa52 13 *
mbed_official 3:7a284390b0ce 14 * Redistribution and use in source and binary forms, with or without
mbed_official 3:7a284390b0ce 15 * modification, are permitted provided that the following conditions
mbed_official 3:7a284390b0ce 16 * are met:
mbed_official 3:7a284390b0ce 17 * - Redistributions of source code must retain the above copyright
mbed_official 3:7a284390b0ce 18 * notice, this list of conditions and the following disclaimer.
mbed_official 3:7a284390b0ce 19 * - Redistributions in binary form must reproduce the above copyright
mbed_official 3:7a284390b0ce 20 * notice, this list of conditions and the following disclaimer in
mbed_official 3:7a284390b0ce 21 * the documentation and/or other materials provided with the
mbed_official 3:7a284390b0ce 22 * distribution.
mbed_official 3:7a284390b0ce 23 * - Neither the name of ARM LIMITED nor the names of its contributors
mbed_official 3:7a284390b0ce 24 * may be used to endorse or promote products derived from this
mbed_official 3:7a284390b0ce 25 * software without specific prior written permission.
mbed_official 3:7a284390b0ce 26 *
mbed_official 3:7a284390b0ce 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
mbed_official 3:7a284390b0ce 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
mbed_official 3:7a284390b0ce 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
mbed_official 3:7a284390b0ce 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
mbed_official 3:7a284390b0ce 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
mbed_official 3:7a284390b0ce 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
mbed_official 3:7a284390b0ce 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 3:7a284390b0ce 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 3:7a284390b0ce 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
mbed_official 3:7a284390b0ce 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mbed_official 3:7a284390b0ce 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 3:7a284390b0ce 38 * POSSIBILITY OF SUCH DAMAGE.
emilmont 1:fdd22bb7aa52 39 * ------------------------------------------------------------------- */
emilmont 1:fdd22bb7aa52 40 #include "arm_math.h"
emilmont 1:fdd22bb7aa52 41
emilmont 1:fdd22bb7aa52 42
emilmont 1:fdd22bb7aa52 43 /**
emilmont 1:fdd22bb7aa52 44 * @ingroup groupFilters
emilmont 1:fdd22bb7aa52 45 */
emilmont 1:fdd22bb7aa52 46
emilmont 1:fdd22bb7aa52 47 /**
emilmont 1:fdd22bb7aa52 48 * @addtogroup FIR_Sparse
emilmont 1:fdd22bb7aa52 49 * @{
emilmont 1:fdd22bb7aa52 50 */
emilmont 1:fdd22bb7aa52 51
emilmont 1:fdd22bb7aa52 52
emilmont 1:fdd22bb7aa52 53 /**
emilmont 1:fdd22bb7aa52 54 * @brief Processing function for the Q7 sparse FIR filter.
emilmont 1:fdd22bb7aa52 55 * @param[in] *S points to an instance of the Q7 sparse FIR structure.
emilmont 1:fdd22bb7aa52 56 * @param[in] *pSrc points to the block of input data.
emilmont 1:fdd22bb7aa52 57 * @param[out] *pDst points to the block of output data
emilmont 1:fdd22bb7aa52 58 * @param[in] *pScratchIn points to a temporary buffer of size blockSize.
emilmont 1:fdd22bb7aa52 59 * @param[in] *pScratchOut points to a temporary buffer of size blockSize.
emilmont 1:fdd22bb7aa52 60 * @param[in] blockSize number of input samples to process per call.
emilmont 1:fdd22bb7aa52 61 * @return none.
emilmont 1:fdd22bb7aa52 62 *
emilmont 1:fdd22bb7aa52 63 * <b>Scaling and Overflow Behavior:</b>
emilmont 1:fdd22bb7aa52 64 * \par
emilmont 1:fdd22bb7aa52 65 * The function is implemented using a 32-bit internal accumulator.
emilmont 1:fdd22bb7aa52 66 * Both coefficients and state variables are represented in 1.7 format and multiplications yield a 2.14 result.
emilmont 1:fdd22bb7aa52 67 * The 2.14 intermediate results are accumulated in a 32-bit accumulator in 18.14 format.
emilmont 1:fdd22bb7aa52 68 * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved.
emilmont 1:fdd22bb7aa52 69 * The accumulator is then converted to 18.7 format by discarding the low 7 bits.
emilmont 1:fdd22bb7aa52 70 * Finally, the result is truncated to 1.7 format.
emilmont 1:fdd22bb7aa52 71 */
emilmont 1:fdd22bb7aa52 72
emilmont 1:fdd22bb7aa52 73 void arm_fir_sparse_q7(
emilmont 1:fdd22bb7aa52 74 arm_fir_sparse_instance_q7 * S,
emilmont 1:fdd22bb7aa52 75 q7_t * pSrc,
emilmont 1:fdd22bb7aa52 76 q7_t * pDst,
emilmont 1:fdd22bb7aa52 77 q7_t * pScratchIn,
emilmont 1:fdd22bb7aa52 78 q31_t * pScratchOut,
emilmont 1:fdd22bb7aa52 79 uint32_t blockSize)
emilmont 1:fdd22bb7aa52 80 {
emilmont 1:fdd22bb7aa52 81
emilmont 1:fdd22bb7aa52 82 q7_t *pState = S->pState; /* State pointer */
emilmont 1:fdd22bb7aa52 83 q7_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */
emilmont 1:fdd22bb7aa52 84 q7_t *px; /* Scratch buffer pointer */
emilmont 1:fdd22bb7aa52 85 q7_t *py = pState; /* Temporary pointers for state buffer */
emilmont 1:fdd22bb7aa52 86 q7_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */
emilmont 1:fdd22bb7aa52 87 q7_t *pOut = pDst; /* Destination pointer */
emilmont 1:fdd22bb7aa52 88 int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */
emilmont 1:fdd22bb7aa52 89 uint32_t delaySize = S->maxDelay + blockSize; /* state length */
emilmont 1:fdd22bb7aa52 90 uint16_t numTaps = S->numTaps; /* Filter order */
emilmont 1:fdd22bb7aa52 91 int32_t readIndex; /* Read index of the state buffer */
emilmont 1:fdd22bb7aa52 92 uint32_t tapCnt, blkCnt; /* loop counters */
emilmont 1:fdd22bb7aa52 93 q7_t coeff = *pCoeffs++; /* Read the coefficient value */
emilmont 1:fdd22bb7aa52 94 q31_t *pScr2 = pScratchOut; /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 95 q31_t in;
emilmont 1:fdd22bb7aa52 96
emilmont 1:fdd22bb7aa52 97
mbed_official 3:7a284390b0ce 98 #ifndef ARM_MATH_CM0_FAMILY
emilmont 1:fdd22bb7aa52 99
emilmont 1:fdd22bb7aa52 100 /* Run the below code for Cortex-M4 and Cortex-M3 */
emilmont 1:fdd22bb7aa52 101
emilmont 1:fdd22bb7aa52 102 q7_t in1, in2, in3, in4;
emilmont 1:fdd22bb7aa52 103
emilmont 1:fdd22bb7aa52 104 /* BlockSize of Input samples are copied into the state buffer */
emilmont 1:fdd22bb7aa52 105 /* StateIndex points to the starting position to write in the state buffer */
emilmont 1:fdd22bb7aa52 106 arm_circularWrite_q7(py, (int32_t) delaySize, &S->stateIndex, 1, pSrc, 1,
emilmont 1:fdd22bb7aa52 107 blockSize);
emilmont 1:fdd22bb7aa52 108
emilmont 1:fdd22bb7aa52 109 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 110 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 111
emilmont 1:fdd22bb7aa52 112 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 113 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 114
emilmont 1:fdd22bb7aa52 115 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 116 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 117 {
emilmont 1:fdd22bb7aa52 118 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 119 }
emilmont 1:fdd22bb7aa52 120
emilmont 1:fdd22bb7aa52 121 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 122 py = pState;
emilmont 1:fdd22bb7aa52 123
emilmont 1:fdd22bb7aa52 124 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 125 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 126 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 127
emilmont 1:fdd22bb7aa52 128 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 129 px = pb;
emilmont 1:fdd22bb7aa52 130
emilmont 1:fdd22bb7aa52 131 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 132 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 133
emilmont 1:fdd22bb7aa52 134 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 135 * Compute 4 multiplications at a time. */
emilmont 1:fdd22bb7aa52 136 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 137
emilmont 1:fdd22bb7aa52 138 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 139 {
emilmont 1:fdd22bb7aa52 140 /* Perform multiplication and store in the scratch buffer */
emilmont 1:fdd22bb7aa52 141 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 142 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 143 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 144 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 145
emilmont 1:fdd22bb7aa52 146 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 147 blkCnt--;
emilmont 1:fdd22bb7aa52 148 }
emilmont 1:fdd22bb7aa52 149
emilmont 1:fdd22bb7aa52 150 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 151 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 152 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 153
emilmont 1:fdd22bb7aa52 154 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 155 {
emilmont 1:fdd22bb7aa52 156 /* Perform multiplication and store in the scratch buffer */
emilmont 1:fdd22bb7aa52 157 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 158
emilmont 1:fdd22bb7aa52 159 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 160 blkCnt--;
emilmont 1:fdd22bb7aa52 161 }
emilmont 1:fdd22bb7aa52 162
emilmont 1:fdd22bb7aa52 163 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 164 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 165 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 166
emilmont 1:fdd22bb7aa52 167 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 168 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 169
emilmont 1:fdd22bb7aa52 170 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 171 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 172 {
emilmont 1:fdd22bb7aa52 173 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 174 }
emilmont 1:fdd22bb7aa52 175
emilmont 1:fdd22bb7aa52 176 /* Loop over the number of taps. */
mbed_official 5:3762170b6d4d 177 tapCnt = (uint32_t) numTaps - 2u;
emilmont 1:fdd22bb7aa52 178
emilmont 1:fdd22bb7aa52 179 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 180 {
emilmont 1:fdd22bb7aa52 181 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 182 py = pState;
emilmont 1:fdd22bb7aa52 183
emilmont 1:fdd22bb7aa52 184 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 185 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 186 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 187
emilmont 1:fdd22bb7aa52 188 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 189 px = pb;
emilmont 1:fdd22bb7aa52 190
emilmont 1:fdd22bb7aa52 191 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 192 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 193
emilmont 1:fdd22bb7aa52 194 /* Loop over the blockSize. Unroll by a factor of 4.
emilmont 1:fdd22bb7aa52 195 * Compute 4 MACS at a time. */
emilmont 1:fdd22bb7aa52 196 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 197
emilmont 1:fdd22bb7aa52 198 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 199 {
emilmont 1:fdd22bb7aa52 200 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 201 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 202 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 203 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 204 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 205 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 206 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 207 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 208 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 209
emilmont 1:fdd22bb7aa52 210 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 211 blkCnt--;
emilmont 1:fdd22bb7aa52 212 }
emilmont 1:fdd22bb7aa52 213
emilmont 1:fdd22bb7aa52 214 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 215 * compute the remaining samples */
emilmont 1:fdd22bb7aa52 216 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 217
emilmont 1:fdd22bb7aa52 218 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 219 {
emilmont 1:fdd22bb7aa52 220 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 221 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 222 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 223
emilmont 1:fdd22bb7aa52 224 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 225 blkCnt--;
emilmont 1:fdd22bb7aa52 226 }
emilmont 1:fdd22bb7aa52 227
emilmont 1:fdd22bb7aa52 228 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 229 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 230 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 231
emilmont 1:fdd22bb7aa52 232 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 233 readIndex = ((int32_t) S->stateIndex -
emilmont 1:fdd22bb7aa52 234 (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 235
emilmont 1:fdd22bb7aa52 236 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 237 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 238 {
emilmont 1:fdd22bb7aa52 239 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 240 }
emilmont 1:fdd22bb7aa52 241
emilmont 1:fdd22bb7aa52 242 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 243 tapCnt--;
emilmont 1:fdd22bb7aa52 244 }
mbed_official 5:3762170b6d4d 245
mbed_official 5:3762170b6d4d 246 /* Compute last tap without the final read of pTapDelay */
mbed_official 5:3762170b6d4d 247
mbed_official 5:3762170b6d4d 248 /* Working pointer for state buffer is updated */
mbed_official 5:3762170b6d4d 249 py = pState;
mbed_official 5:3762170b6d4d 250
mbed_official 5:3762170b6d4d 251 /* blockSize samples are read from the state buffer */
mbed_official 5:3762170b6d4d 252 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
mbed_official 5:3762170b6d4d 253 (int32_t) blockSize, 1, blockSize);
mbed_official 5:3762170b6d4d 254
mbed_official 5:3762170b6d4d 255 /* Working pointer for the scratch buffer of state values */
mbed_official 5:3762170b6d4d 256 px = pb;
mbed_official 5:3762170b6d4d 257
mbed_official 5:3762170b6d4d 258 /* Working pointer for scratch buffer of output values */
mbed_official 5:3762170b6d4d 259 pScratchOut = pScr2;
mbed_official 5:3762170b6d4d 260
mbed_official 5:3762170b6d4d 261 /* Loop over the blockSize. Unroll by a factor of 4.
mbed_official 5:3762170b6d4d 262 * Compute 4 MACS at a time. */
mbed_official 5:3762170b6d4d 263 blkCnt = blockSize >> 2;
mbed_official 5:3762170b6d4d 264
mbed_official 5:3762170b6d4d 265 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 266 {
mbed_official 5:3762170b6d4d 267 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 268 in = *pScratchOut + ((q31_t) * px++ * coeff);
mbed_official 5:3762170b6d4d 269 *pScratchOut++ = in;
mbed_official 5:3762170b6d4d 270 in = *pScratchOut + ((q31_t) * px++ * coeff);
mbed_official 5:3762170b6d4d 271 *pScratchOut++ = in;
mbed_official 5:3762170b6d4d 272 in = *pScratchOut + ((q31_t) * px++ * coeff);
mbed_official 5:3762170b6d4d 273 *pScratchOut++ = in;
mbed_official 5:3762170b6d4d 274 in = *pScratchOut + ((q31_t) * px++ * coeff);
mbed_official 5:3762170b6d4d 275 *pScratchOut++ = in;
mbed_official 5:3762170b6d4d 276
mbed_official 5:3762170b6d4d 277 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 278 blkCnt--;
mbed_official 5:3762170b6d4d 279 }
mbed_official 5:3762170b6d4d 280
mbed_official 5:3762170b6d4d 281 /* If the blockSize is not a multiple of 4,
mbed_official 5:3762170b6d4d 282 * compute the remaining samples */
mbed_official 5:3762170b6d4d 283 blkCnt = blockSize % 0x4u;
mbed_official 5:3762170b6d4d 284
mbed_official 5:3762170b6d4d 285 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 286 {
mbed_official 5:3762170b6d4d 287 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 288 in = *pScratchOut + ((q31_t) * px++ * coeff);
mbed_official 5:3762170b6d4d 289 *pScratchOut++ = in;
mbed_official 5:3762170b6d4d 290
mbed_official 5:3762170b6d4d 291 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 292 blkCnt--;
mbed_official 5:3762170b6d4d 293 }
emilmont 1:fdd22bb7aa52 294
emilmont 1:fdd22bb7aa52 295 /* All the output values are in pScratchOut buffer.
emilmont 1:fdd22bb7aa52 296 Convert them into 1.15 format, saturate and store in the destination buffer. */
emilmont 1:fdd22bb7aa52 297 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 298 blkCnt = blockSize >> 2;
emilmont 1:fdd22bb7aa52 299
emilmont 1:fdd22bb7aa52 300 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 301 {
emilmont 1:fdd22bb7aa52 302 in1 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 303 in2 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 304 in3 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 305 in4 = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 306
emilmont 1:fdd22bb7aa52 307 *__SIMD32(pOut)++ = __PACKq7(in1, in2, in3, in4);
emilmont 1:fdd22bb7aa52 308
emilmont 1:fdd22bb7aa52 309 /* Decrement the blockSize loop counter */
emilmont 1:fdd22bb7aa52 310 blkCnt--;
emilmont 1:fdd22bb7aa52 311 }
emilmont 1:fdd22bb7aa52 312
emilmont 1:fdd22bb7aa52 313 /* If the blockSize is not a multiple of 4,
emilmont 1:fdd22bb7aa52 314 remaining samples are processed in the below loop */
emilmont 1:fdd22bb7aa52 315 blkCnt = blockSize % 0x4u;
emilmont 1:fdd22bb7aa52 316
emilmont 1:fdd22bb7aa52 317 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 318 {
emilmont 1:fdd22bb7aa52 319 *pOut++ = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 320
emilmont 1:fdd22bb7aa52 321 /* Decrement the blockSize loop counter */
emilmont 1:fdd22bb7aa52 322 blkCnt--;
emilmont 1:fdd22bb7aa52 323 }
emilmont 1:fdd22bb7aa52 324
emilmont 1:fdd22bb7aa52 325 #else
emilmont 1:fdd22bb7aa52 326
emilmont 1:fdd22bb7aa52 327 /* Run the below code for Cortex-M0 */
emilmont 1:fdd22bb7aa52 328
emilmont 1:fdd22bb7aa52 329 /* BlockSize of Input samples are copied into the state buffer */
emilmont 1:fdd22bb7aa52 330 /* StateIndex points to the starting position to write in the state buffer */
emilmont 1:fdd22bb7aa52 331 arm_circularWrite_q7(py, (int32_t) delaySize, &S->stateIndex, 1, pSrc, 1,
emilmont 1:fdd22bb7aa52 332 blockSize);
emilmont 1:fdd22bb7aa52 333
emilmont 1:fdd22bb7aa52 334 /* Loop over the number of taps. */
emilmont 1:fdd22bb7aa52 335 tapCnt = numTaps;
emilmont 1:fdd22bb7aa52 336
emilmont 1:fdd22bb7aa52 337 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 338 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 339
emilmont 1:fdd22bb7aa52 340 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 341 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 342 {
emilmont 1:fdd22bb7aa52 343 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 344 }
emilmont 1:fdd22bb7aa52 345
emilmont 1:fdd22bb7aa52 346 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 347 py = pState;
emilmont 1:fdd22bb7aa52 348
emilmont 1:fdd22bb7aa52 349 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 350 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 351 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 352
emilmont 1:fdd22bb7aa52 353 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 354 px = pb;
emilmont 1:fdd22bb7aa52 355
emilmont 1:fdd22bb7aa52 356 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 357 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 358
emilmont 1:fdd22bb7aa52 359 /* Loop over the blockSize */
emilmont 1:fdd22bb7aa52 360 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 361
emilmont 1:fdd22bb7aa52 362 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 363 {
emilmont 1:fdd22bb7aa52 364 /* Perform multiplication and store in the scratch buffer */
emilmont 1:fdd22bb7aa52 365 *pScratchOut++ = ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 366
emilmont 1:fdd22bb7aa52 367 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 368 blkCnt--;
emilmont 1:fdd22bb7aa52 369 }
emilmont 1:fdd22bb7aa52 370
emilmont 1:fdd22bb7aa52 371 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 372 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 373 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 374
emilmont 1:fdd22bb7aa52 375 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 376 readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 377
emilmont 1:fdd22bb7aa52 378 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 379 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 380 {
emilmont 1:fdd22bb7aa52 381 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 382 }
emilmont 1:fdd22bb7aa52 383
emilmont 1:fdd22bb7aa52 384 /* Loop over the number of taps. */
mbed_official 5:3762170b6d4d 385 tapCnt = (uint32_t) numTaps - 2u;
emilmont 1:fdd22bb7aa52 386
emilmont 1:fdd22bb7aa52 387 while(tapCnt > 0u)
emilmont 1:fdd22bb7aa52 388 {
emilmont 1:fdd22bb7aa52 389 /* Working pointer for state buffer is updated */
emilmont 1:fdd22bb7aa52 390 py = pState;
emilmont 1:fdd22bb7aa52 391
emilmont 1:fdd22bb7aa52 392 /* blockSize samples are read from the state buffer */
emilmont 1:fdd22bb7aa52 393 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
emilmont 1:fdd22bb7aa52 394 (int32_t) blockSize, 1, blockSize);
emilmont 1:fdd22bb7aa52 395
emilmont 1:fdd22bb7aa52 396 /* Working pointer for the scratch buffer of state values */
emilmont 1:fdd22bb7aa52 397 px = pb;
emilmont 1:fdd22bb7aa52 398
emilmont 1:fdd22bb7aa52 399 /* Working pointer for scratch buffer of output values */
emilmont 1:fdd22bb7aa52 400 pScratchOut = pScr2;
emilmont 1:fdd22bb7aa52 401
emilmont 1:fdd22bb7aa52 402 /* Loop over the blockSize */
emilmont 1:fdd22bb7aa52 403 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 404
emilmont 1:fdd22bb7aa52 405 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 406 {
emilmont 1:fdd22bb7aa52 407 /* Perform Multiply-Accumulate */
emilmont 1:fdd22bb7aa52 408 in = *pScratchOut + ((q31_t) * px++ * coeff);
emilmont 1:fdd22bb7aa52 409 *pScratchOut++ = in;
emilmont 1:fdd22bb7aa52 410
emilmont 1:fdd22bb7aa52 411 /* Decrement the loop counter */
emilmont 1:fdd22bb7aa52 412 blkCnt--;
emilmont 1:fdd22bb7aa52 413 }
emilmont 1:fdd22bb7aa52 414
emilmont 1:fdd22bb7aa52 415 /* Load the coefficient value and
emilmont 1:fdd22bb7aa52 416 * increment the coefficient buffer for the next set of state values */
emilmont 1:fdd22bb7aa52 417 coeff = *pCoeffs++;
emilmont 1:fdd22bb7aa52 418
emilmont 1:fdd22bb7aa52 419 /* Read Index, from where the state buffer should be read, is calculated. */
emilmont 1:fdd22bb7aa52 420 readIndex =
emilmont 1:fdd22bb7aa52 421 ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++;
emilmont 1:fdd22bb7aa52 422
emilmont 1:fdd22bb7aa52 423 /* Wraparound of readIndex */
emilmont 1:fdd22bb7aa52 424 if(readIndex < 0)
emilmont 1:fdd22bb7aa52 425 {
emilmont 1:fdd22bb7aa52 426 readIndex += (int32_t) delaySize;
emilmont 1:fdd22bb7aa52 427 }
emilmont 1:fdd22bb7aa52 428
emilmont 1:fdd22bb7aa52 429 /* Decrement the tap loop counter */
emilmont 1:fdd22bb7aa52 430 tapCnt--;
emilmont 1:fdd22bb7aa52 431 }
mbed_official 5:3762170b6d4d 432
mbed_official 5:3762170b6d4d 433 /* Compute last tap without the final read of pTapDelay */
mbed_official 5:3762170b6d4d 434
mbed_official 5:3762170b6d4d 435 /* Working pointer for state buffer is updated */
mbed_official 5:3762170b6d4d 436 py = pState;
mbed_official 5:3762170b6d4d 437
mbed_official 5:3762170b6d4d 438 /* blockSize samples are read from the state buffer */
mbed_official 5:3762170b6d4d 439 arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb,
mbed_official 5:3762170b6d4d 440 (int32_t) blockSize, 1, blockSize);
mbed_official 5:3762170b6d4d 441
mbed_official 5:3762170b6d4d 442 /* Working pointer for the scratch buffer of state values */
mbed_official 5:3762170b6d4d 443 px = pb;
mbed_official 5:3762170b6d4d 444
mbed_official 5:3762170b6d4d 445 /* Working pointer for scratch buffer of output values */
mbed_official 5:3762170b6d4d 446 pScratchOut = pScr2;
mbed_official 5:3762170b6d4d 447
mbed_official 5:3762170b6d4d 448 /* Loop over the blockSize */
mbed_official 5:3762170b6d4d 449 blkCnt = blockSize;
mbed_official 5:3762170b6d4d 450
mbed_official 5:3762170b6d4d 451 while(blkCnt > 0u)
mbed_official 5:3762170b6d4d 452 {
mbed_official 5:3762170b6d4d 453 /* Perform Multiply-Accumulate */
mbed_official 5:3762170b6d4d 454 in = *pScratchOut + ((q31_t) * px++ * coeff);
mbed_official 5:3762170b6d4d 455 *pScratchOut++ = in;
mbed_official 5:3762170b6d4d 456
mbed_official 5:3762170b6d4d 457 /* Decrement the loop counter */
mbed_official 5:3762170b6d4d 458 blkCnt--;
mbed_official 5:3762170b6d4d 459 }
emilmont 1:fdd22bb7aa52 460
emilmont 1:fdd22bb7aa52 461 /* All the output values are in pScratchOut buffer.
emilmont 1:fdd22bb7aa52 462 Convert them into 1.15 format, saturate and store in the destination buffer. */
emilmont 1:fdd22bb7aa52 463 /* Loop over the blockSize. */
emilmont 1:fdd22bb7aa52 464 blkCnt = blockSize;
emilmont 1:fdd22bb7aa52 465
emilmont 1:fdd22bb7aa52 466 while(blkCnt > 0u)
emilmont 1:fdd22bb7aa52 467 {
emilmont 1:fdd22bb7aa52 468 *pOut++ = (q7_t) __SSAT(*pScr2++ >> 7, 8);
emilmont 1:fdd22bb7aa52 469
emilmont 1:fdd22bb7aa52 470 /* Decrement the blockSize loop counter */
emilmont 1:fdd22bb7aa52 471 blkCnt--;
emilmont 1:fdd22bb7aa52 472 }
emilmont 1:fdd22bb7aa52 473
mbed_official 3:7a284390b0ce 474 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
emilmont 1:fdd22bb7aa52 475
emilmont 1:fdd22bb7aa52 476 }
emilmont 1:fdd22bb7aa52 477
emilmont 1:fdd22bb7aa52 478 /**
emilmont 1:fdd22bb7aa52 479 * @} end of FIR_Sparse group
emilmont 1:fdd22bb7aa52 480 */