--- /dev/null
+/* ---------------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_conv_f32.c \r
+* \r
+* Description: Convolution of floating-point sequences. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @defgroup Conv Convolution \r
+ * \r
+ * Convolution is a mathematical operation that operates on two finite length vectors to generate a finite length output vector. \r
+ * Convolution is similar to correlation and is frequently used in filtering and data analysis. \r
+ * The CMSIS DSP library contains functions for convolving Q7, Q15, Q31, and floating-point data types. \r
+ * The library also provides fast versions of the Q15 and Q31 functions on Cortex-M4 and Cortex-M3. \r
+ * \r
+ * \par Algorithm \r
+ * Let <code>a[n]</code> and <code>b[n]</code> be sequences of length <code>srcALen</code> and <code>srcBLen</code> samples respectively. \r
+ * Then the convolution \r
+ * \r
+ * <pre> \r
+ * c[n] = a[n] * b[n] \r
+ * </pre> \r
+ * \r
+ * \par \r
+ * is defined as \r
+ * \image html ConvolutionEquation.gif \r
+ * \par \r
+ * Note that <code>c[n]</code> is of length <code>srcALen + srcBLen - 1</code> and is defined over the interval <code>n=0, 1, 2, ..., srcALen + srcBLen - 2</code>. \r
+ * <code>pSrcA</code> points to the first input vector of length <code>srcALen</code> and \r
+ * <code>pSrcB</code> points to the second input vector of length <code>srcBLen</code>. \r
+ * The output result is written to <code>pDst</code> and the calling function must allocate <code>srcALen+srcBLen-1</code> words for the result. \r
+ * \r
+ * \par \r
+ * Conceptually, when two signals <code>a[n]</code> and <code>b[n]</code> are convolved, \r
+ * the signal <code>b[n]</code> slides over <code>a[n]</code>. \r
+ * For each offset \c n, the overlapping portions of a[n] and b[n] are multiplied and summed together. \r
+ * \r
+ * \par \r
+ * Note that convolution is a commutative operation: \r
+ * \r
+ * <pre> \r
+ * a[n] * b[n] = b[n] * a[n]. \r
+ * </pre> \r
+ * \r
+ * \par \r
+ * This means that switching the A and B arguments to the convolution functions has no effect. \r
+ * \r
+ * <b>Fixed-Point Behavior</b> \r
+ * \r
+ * \par \r
+ * Convolution requires summing up a large number of intermediate products. \r
+ * As such, the Q7, Q15, and Q31 functions run a risk of overflow and saturation. \r
+ * Refer to the function specific documentation below for further details of the particular algorithm used. \r
+ *\r
+ *\r
+ * <b>Fast Versions</b>\r
+ *\r
+ * \par \r
+ * Fast versions are supported for Q31 and Q15. Cycles for Fast versions are less compared to Q31 and Q15 of conv and the design requires\r
+ * the input signals should be scaled down to avoid intermediate overflows. \r
+ *\r
+ *\r
+ * <b>Opt Versions</b>\r
+ *\r
+ * \par \r
+ * Opt versions are supported for Q15 and Q7. Design uses internal scratch buffer for getting good optimisation.\r
+ * These versions are optimised in cycles and consumes more memory(Scratch memory) compared to Q15 and Q7 versions \r
+ */\r
+\r
+/** \r
+ * @addtogroup Conv \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @brief Convolution of floating-point sequences. \r
+ * @param[in] *pSrcA points to the first input sequence. \r
+ * @param[in] srcALen length of the first input sequence. \r
+ * @param[in] *pSrcB points to the second input sequence. \r
+ * @param[in] srcBLen length of the second input sequence. \r
+ * @param[out] *pDst points to the location where the output result is written. Length srcALen+srcBLen-1. \r
+ * @return none. \r
+ */\r
+\r
+void arm_conv_f32(\r
+ float32_t * pSrcA,\r
+ uint32_t srcALen,\r
+ float32_t * pSrcB,\r
+ uint32_t srcBLen,\r
+ float32_t * pDst)\r
+{\r
+\r
+\r
+#ifndef ARM_MATH_CM0_FAMILY\r
+\r
+ /* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+ float32_t *pIn1; /* inputA pointer */\r
+ float32_t *pIn2; /* inputB pointer */\r
+ float32_t *pOut = pDst; /* output pointer */\r
+ float32_t *px; /* Intermediate inputA pointer */\r
+ float32_t *py; /* Intermediate inputB pointer */\r
+ float32_t *pSrc1, *pSrc2; /* Intermediate pointers */\r
+ float32_t sum, acc0, acc1, acc2, acc3; /* Accumulator */\r
+ float32_t x0, x1, x2, x3, c0; /* Temporary variables to hold state and coefficient values */\r
+ uint32_t j, k, count, blkCnt, blockSize1, blockSize2, blockSize3; /* loop counters */\r
+\r
+ /* The algorithm implementation is based on the lengths of the inputs. */\r
+ /* srcB is always made to slide across srcA. */\r
+ /* So srcBLen is always considered as shorter or equal to srcALen */\r
+ if(srcALen >= srcBLen)\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = pSrcA;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = pSrcB;\r
+ }\r
+ else\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = pSrcB;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = pSrcA;\r
+\r
+ /* srcBLen is always considered as shorter or equal to srcALen */\r
+ j = srcBLen;\r
+ srcBLen = srcALen;\r
+ srcALen = j;\r
+ }\r
+\r
+ /* conv(x,y) at n = x[n] * y[0] + x[n-1] * y[1] + x[n-2] * y[2] + ...+ x[n-N+1] * y[N -1] */\r
+ /* The function is internally \r
+ * divided into three stages according to the number of multiplications that has to be \r
+ * taken place between inputA samples and inputB samples. In the first stage of the \r
+ * algorithm, the multiplications increase by one for every iteration. \r
+ * In the second stage of the algorithm, srcBLen number of multiplications are done. \r
+ * In the third stage of the algorithm, the multiplications decrease by one \r
+ * for every iteration. */\r
+\r
+ /* The algorithm is implemented in three stages. \r
+ The loop counters of each stage is initiated here. */\r
+ blockSize1 = srcBLen - 1u;\r
+ blockSize2 = srcALen - (srcBLen - 1u);\r
+ blockSize3 = blockSize1;\r
+\r
+ /* -------------------------- \r
+ * initializations of stage1 \r
+ * -------------------------*/\r
+\r
+ /* sum = x[0] * y[0] \r
+ * sum = x[0] * y[1] + x[1] * y[0] \r
+ * .... \r
+ * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] \r
+ */\r
+\r
+ /* In this stage the MAC operations are increased by 1 for every iteration. \r
+ The count variable holds the number of MAC operations performed */\r
+ count = 1u;\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ py = pIn2;\r
+\r
+\r
+ /* ------------------------ \r
+ * Stage1 process \r
+ * ----------------------*/\r
+\r
+ /* The first stage starts here */\r
+ while(blockSize1 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0.0f;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = count >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* x[0] * y[srcBLen - 1] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* x[1] * y[srcBLen - 2] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* x[2] * y[srcBLen - 3] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* x[3] * y[srcBLen - 4] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the count is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = count % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += *px++ * *py--;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = sum;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ py = pIn2 + count;\r
+ px = pIn1;\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize1--;\r
+ }\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage2 \r
+ * ------------------------*/\r
+\r
+ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] \r
+ * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] \r
+ * .... \r
+ * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] \r
+ */\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ py = pSrc2;\r
+\r
+ /* count is index by which the pointer pIn1 to be incremented */\r
+ count = 0u;\r
+\r
+ /* ------------------- \r
+ * Stage2 process \r
+ * ------------------*/\r
+\r
+ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. \r
+ * So, to loop unroll over blockSize2, \r
+ * srcBLen should be greater than or equal to 4 */\r
+ if(srcBLen >= 4u)\r
+ {\r
+ /* Loop unroll over blockSize2, by 4 */\r
+ blkCnt = blockSize2 >> 2u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0.0f;\r
+ acc1 = 0.0f;\r
+ acc2 = 0.0f;\r
+ acc3 = 0.0f;\r
+\r
+ /* read x[0], x[1], x[2] samples */\r
+ x0 = *(px++);\r
+ x1 = *(px++);\r
+ x2 = *(px++);\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = srcBLen >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ do\r
+ {\r
+ /* Read y[srcBLen - 1] sample */\r
+ c0 = *(py--);\r
+\r
+ /* Read x[3] sample */\r
+ x3 = *(px);\r
+\r
+ /* Perform the multiply-accumulate */\r
+ /* acc0 += x[0] * y[srcBLen - 1] */\r
+ acc0 += x0 * c0;\r
+\r
+ /* acc1 += x[1] * y[srcBLen - 1] */\r
+ acc1 += x1 * c0;\r
+\r
+ /* acc2 += x[2] * y[srcBLen - 1] */\r
+ acc2 += x2 * c0;\r
+\r
+ /* acc3 += x[3] * y[srcBLen - 1] */\r
+ acc3 += x3 * c0;\r
+\r
+ /* Read y[srcBLen - 2] sample */\r
+ c0 = *(py--);\r
+\r
+ /* Read x[4] sample */\r
+ x0 = *(px + 1u);\r
+\r
+ /* Perform the multiply-accumulate */\r
+ /* acc0 += x[1] * y[srcBLen - 2] */\r
+ acc0 += x1 * c0;\r
+ /* acc1 += x[2] * y[srcBLen - 2] */\r
+ acc1 += x2 * c0;\r
+ /* acc2 += x[3] * y[srcBLen - 2] */\r
+ acc2 += x3 * c0;\r
+ /* acc3 += x[4] * y[srcBLen - 2] */\r
+ acc3 += x0 * c0;\r
+\r
+ /* Read y[srcBLen - 3] sample */\r
+ c0 = *(py--);\r
+\r
+ /* Read x[5] sample */\r
+ x1 = *(px + 2u);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ /* acc0 += x[2] * y[srcBLen - 3] */\r
+ acc0 += x2 * c0;\r
+ /* acc1 += x[3] * y[srcBLen - 2] */\r
+ acc1 += x3 * c0;\r
+ /* acc2 += x[4] * y[srcBLen - 2] */\r
+ acc2 += x0 * c0;\r
+ /* acc3 += x[5] * y[srcBLen - 2] */\r
+ acc3 += x1 * c0;\r
+\r
+ /* Read y[srcBLen - 4] sample */\r
+ c0 = *(py--);\r
+\r
+ /* Read x[6] sample */\r
+ x2 = *(px + 3u);\r
+ px += 4u;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ /* acc0 += x[3] * y[srcBLen - 4] */\r
+ acc0 += x3 * c0;\r
+ /* acc1 += x[4] * y[srcBLen - 4] */\r
+ acc1 += x0 * c0;\r
+ /* acc2 += x[5] * y[srcBLen - 4] */\r
+ acc2 += x1 * c0;\r
+ /* acc3 += x[6] * y[srcBLen - 4] */\r
+ acc3 += x2 * c0;\r
+\r
+\r
+ } while(--k);\r
+\r
+ /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Read y[srcBLen - 5] sample */\r
+ c0 = *(py--);\r
+\r
+ /* Read x[7] sample */\r
+ x3 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ /* acc0 += x[4] * y[srcBLen - 5] */\r
+ acc0 += x0 * c0;\r
+ /* acc1 += x[5] * y[srcBLen - 5] */\r
+ acc1 += x1 * c0;\r
+ /* acc2 += x[6] * y[srcBLen - 5] */\r
+ acc2 += x2 * c0;\r
+ /* acc3 += x[7] * y[srcBLen - 5] */\r
+ acc3 += x3 * c0;\r
+\r
+ /* Reuse the present samples for the next MAC */\r
+ x0 = x1;\r
+ x1 = x2;\r
+ x2 = x3;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = acc0;\r
+ *pOut++ = acc1;\r
+ *pOut++ = acc2;\r
+ *pOut++ = acc3;\r
+\r
+ /* Increment the pointer pIn1 index, count by 4 */\r
+ count += 4u;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+\r
+ /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize2 % 0x4u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0.0f;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = srcBLen >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum += *px++ * *py--;\r
+ sum += *px++ * *py--;\r
+ sum += *px++ * *py--;\r
+ sum += *px++ * *py--;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += *px++ * *py--;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = sum;\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* If the srcBLen is not a multiple of 4, \r
+ * the blockSize2 loop cannot be unrolled by 4 */\r
+ blkCnt = blockSize2;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0.0f;\r
+\r
+ /* srcBLen number of MACS should be performed */\r
+ k = srcBLen;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += *px++ * *py--;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = sum;\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage3 \r
+ * -------------------------*/\r
+\r
+ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] \r
+ * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] \r
+ * .... \r
+ * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] \r
+ * sum += x[srcALen-1] * y[srcBLen-1] \r
+ */\r
+\r
+ /* In this stage the MAC operations are decreased by 1 for every iteration. \r
+ The blockSize3 variable holds the number of MAC operations performed */\r
+\r
+ /* Working pointer of inputA */\r
+ pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u);\r
+ px = pSrc1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ py = pSrc2;\r
+\r
+ /* ------------------- \r
+ * Stage3 process \r
+ * ------------------*/\r
+\r
+ while(blockSize3 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0.0f;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = blockSize3 >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the blockSize3 is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = blockSize3 % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ /* sum += x[srcALen-1] * y[srcBLen-1] */\r
+ sum += *px++ * *py--;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = sum;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = ++pSrc1;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize3--;\r
+ }\r
+\r
+#else\r
+\r
+ /* Run the below code for Cortex-M0 */\r
+\r
+ float32_t *pIn1 = pSrcA; /* inputA pointer */\r
+ float32_t *pIn2 = pSrcB; /* inputB pointer */\r
+ float32_t sum; /* Accumulator */\r
+ uint32_t i, j; /* loop counters */\r
+\r
+ /* Loop to calculate convolution for output length number of times */\r
+ for (i = 0u; i < ((srcALen + srcBLen) - 1u); i++)\r
+ {\r
+ /* Initialize sum with zero to carry out MAC operations */\r
+ sum = 0.0f;\r
+\r
+ /* Loop to perform MAC operations according to convolution equation */\r
+ for (j = 0u; j <= i; j++)\r
+ {\r
+ /* Check the array limitations */\r
+ if((((i - j) < srcBLen) && (j < srcALen)))\r
+ {\r
+ /* z[i] += x[i-j] * y[j] */\r
+ sum += pIn1[j] * pIn2[i - j];\r
+ }\r
+ }\r
+ /* Store the output in the destination buffer */\r
+ pDst[i] = sum;\r
+ }\r
+\r
+#endif /* #ifndef ARM_MATH_CM0_FAMILY */\r
+\r
+}\r
+\r
+/** \r
+ * @} end of Conv group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_conv_q15.c \r
+* \r
+* Description: Convolution of Q15 sequences. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup Conv \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @brief Convolution of Q15 sequences. \r
+ * @param[in] *pSrcA points to the first input sequence. \r
+ * @param[in] srcALen length of the first input sequence. \r
+ * @param[in] *pSrcB points to the second input sequence. \r
+ * @param[in] srcBLen length of the second input sequence. \r
+ * @param[out] *pDst points to the location where the output result is written. Length srcALen+srcBLen-1. \r
+ * @return none. \r
+ * \r
+ * @details \r
+ * <b>Scaling and Overflow Behavior:</b> \r
+ * \r
+ * \par \r
+ * The function is implemented using a 64-bit internal accumulator. \r
+ * Both inputs are in 1.15 format and multiplications yield a 2.30 result. \r
+ * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. \r
+ * This approach provides 33 guard bits and there is no risk of overflow. \r
+ * The 34.30 result is then truncated to 34.15 format by discarding the low 15 bits and then saturated to 1.15 format. \r
+ * \r
+ * \par \r
+ * Refer to <code>arm_conv_fast_q15()</code> for a faster but less precise version of this function for Cortex-M3 and Cortex-M4. \r
+ *\r
+ * \par \r
+ * Refer the function <code>arm_conv_opt_q15()</code> for a faster implementation of this function using scratch buffers.\r
+ * \r
+ */\r
+\r
+void arm_conv_q15(\r
+ q15_t * pSrcA,\r
+ uint32_t srcALen,\r
+ q15_t * pSrcB,\r
+ uint32_t srcBLen,\r
+ q15_t * pDst)\r
+{\r
+\r
+#if (defined(ARM_MATH_CM4) || defined(ARM_MATH_CM3)) && !defined(UNALIGNED_SUPPORT_DISABLE)\r
+\r
+ /* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+ q15_t *pIn1; /* inputA pointer */\r
+ q15_t *pIn2; /* inputB pointer */\r
+ q15_t *pOut = pDst; /* output pointer */\r
+ q63_t sum, acc0, acc1, acc2, acc3; /* Accumulator */\r
+ q15_t *px; /* Intermediate inputA pointer */\r
+ q15_t *py; /* Intermediate inputB pointer */\r
+ q15_t *pSrc1, *pSrc2; /* Intermediate pointers */\r
+ q31_t x0, x1, x2, x3, c0; /* Temporary variables to hold state and coefficient values */\r
+ uint32_t blockSize1, blockSize2, blockSize3, j, k, count, blkCnt; /* loop counter */\r
+\r
+ /* The algorithm implementation is based on the lengths of the inputs. */\r
+ /* srcB is always made to slide across srcA. */\r
+ /* So srcBLen is always considered as shorter or equal to srcALen */\r
+ if(srcALen >= srcBLen)\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = pSrcA;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = pSrcB;\r
+ }\r
+ else\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = pSrcB;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = pSrcA;\r
+\r
+ /* srcBLen is always considered as shorter or equal to srcALen */\r
+ j = srcBLen;\r
+ srcBLen = srcALen;\r
+ srcALen = j;\r
+ }\r
+\r
+ /* conv(x,y) at n = x[n] * y[0] + x[n-1] * y[1] + x[n-2] * y[2] + ...+ x[n-N+1] * y[N -1] */\r
+ /* The function is internally \r
+ * divided into three stages according to the number of multiplications that has to be \r
+ * taken place between inputA samples and inputB samples. In the first stage of the \r
+ * algorithm, the multiplications increase by one for every iteration. \r
+ * In the second stage of the algorithm, srcBLen number of multiplications are done. \r
+ * In the third stage of the algorithm, the multiplications decrease by one \r
+ * for every iteration. */\r
+\r
+ /* The algorithm is implemented in three stages. \r
+ The loop counters of each stage is initiated here. */\r
+ blockSize1 = srcBLen - 1u;\r
+ blockSize2 = srcALen - (srcBLen - 1u);\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage1 \r
+ * -------------------------*/\r
+\r
+ /* sum = x[0] * y[0] \r
+ * sum = x[0] * y[1] + x[1] * y[0] \r
+ * .... \r
+ * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] \r
+ */\r
+\r
+ /* In this stage the MAC operations are increased by 1 for every iteration. \r
+ The count variable holds the number of MAC operations performed */\r
+ count = 1u;\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ py = pIn2;\r
+\r
+\r
+ /* ------------------------ \r
+ * Stage1 process \r
+ * ----------------------*/\r
+\r
+ /* For loop unrolling by 4, this stage is divided into two. */\r
+ /* First part of this stage computes the MAC operations less than 4 */\r
+ /* Second part of this stage computes the MAC operations greater than or equal to 4 */\r
+\r
+ /* The first part of the stage starts here */\r
+ while((count < 4u) && (blockSize1 > 0u))\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Loop over number of MAC operations between \r
+ * inputA samples and inputB samples */\r
+ k = count;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum = __SMLALD(*px++, *py--, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q15_t) (__SSAT((sum >> 15), 16));\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ py = pIn2 + count;\r
+ px = pIn1;\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize1--;\r
+ }\r
+\r
+ /* The second part of the stage starts here */\r
+ /* The internal loop, over count, is unrolled by 4 */\r
+ /* To, read the last two inputB samples using SIMD: \r
+ * y[srcBLen] and y[srcBLen-1] coefficients, py is decremented by 1 */\r
+ py = py - 1;\r
+\r
+ while(blockSize1 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = count >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ /* x[0], x[1] are multiplied with y[srcBLen - 1], y[srcBLen - 2] respectively */\r
+ sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum);\r
+ /* x[2], x[3] are multiplied with y[srcBLen - 3], y[srcBLen - 4] respectively */\r
+ sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* For the next MAC operations, the pointer py is used without SIMD \r
+ * So, py is incremented by 1 */\r
+ py = py + 1u;\r
+\r
+ /* If the count is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = count % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum = __SMLALD(*px++, *py--, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q15_t) (__SSAT((sum >> 15), 16));\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ py = pIn2 + (count - 1u);\r
+ px = pIn1;\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize1--;\r
+ }\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage2 \r
+ * ------------------------*/\r
+\r
+ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] \r
+ * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] \r
+ * .... \r
+ * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] \r
+ */\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ py = pSrc2;\r
+\r
+ /* count is the index by which the pointer pIn1 to be incremented */\r
+ count = 0u;\r
+\r
+\r
+ /* -------------------- \r
+ * Stage2 process \r
+ * -------------------*/\r
+\r
+ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. \r
+ * So, to loop unroll over blockSize2, \r
+ * srcBLen should be greater than or equal to 4 */\r
+ if(srcBLen >= 4u)\r
+ {\r
+ /* Loop unroll over blockSize2, by 4 */\r
+ blkCnt = blockSize2 >> 2u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ py = py - 1u;\r
+\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0;\r
+ acc1 = 0;\r
+ acc2 = 0;\r
+ acc3 = 0;\r
+\r
+\r
+ /* read x[0], x[1] samples */\r
+ x0 = *__SIMD32(px);\r
+ /* read x[1], x[2] samples */\r
+ x1 = _SIMD32_OFFSET(px+1);\r
+ px+= 2u;\r
+\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = srcBLen >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ do\r
+ {\r
+ /* Read the last two inputB samples using SIMD: \r
+ * y[srcBLen - 1] and y[srcBLen - 2] */\r
+ c0 = *__SIMD32(py)--;\r
+\r
+ /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */\r
+ acc0 = __SMLALDX(x0, c0, acc0);\r
+\r
+ /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */\r
+ acc1 = __SMLALDX(x1, c0, acc1);\r
+\r
+ /* Read x[2], x[3] */\r
+ x2 = *__SIMD32(px);\r
+\r
+ /* Read x[3], x[4] */\r
+ x3 = _SIMD32_OFFSET(px+1);\r
+\r
+ /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */\r
+ acc2 = __SMLALDX(x2, c0, acc2);\r
+\r
+ /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */\r
+ acc3 = __SMLALDX(x3, c0, acc3);\r
+\r
+ /* Read y[srcBLen - 3] and y[srcBLen - 4] */\r
+ c0 = *__SIMD32(py)--;\r
+\r
+ /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */\r
+ acc0 = __SMLALDX(x2, c0, acc0);\r
+\r
+ /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */\r
+ acc1 = __SMLALDX(x3, c0, acc1);\r
+\r
+ /* Read x[4], x[5] */\r
+ x0 = _SIMD32_OFFSET(px+2);\r
+\r
+ /* Read x[5], x[6] */\r
+ x1 = _SIMD32_OFFSET(px+3);\r
+ px += 4u;\r
+\r
+ /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */\r
+ acc2 = __SMLALDX(x0, c0, acc2);\r
+\r
+ /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */\r
+ acc3 = __SMLALDX(x1, c0, acc3);\r
+\r
+ } while(--k);\r
+\r
+ /* For the next MAC operations, SIMD is not used \r
+ * So, the 16 bit pointer if inputB, py is updated */\r
+\r
+ /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen % 0x4u;\r
+\r
+ if(k == 1u)\r
+ {\r
+ /* Read y[srcBLen - 5] */\r
+ c0 = *(py+1);\r
+\r
+#ifdef ARM_MATH_BIG_ENDIAN\r
+\r
+ c0 = c0 << 16u;\r
+\r
+#else\r
+\r
+ c0 = c0 & 0x0000FFFF;\r
+\r
+#endif /* #ifdef ARM_MATH_BIG_ENDIAN */\r
+ /* Read x[7] */\r
+ x3 = *__SIMD32(px);\r
+ px++;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 = __SMLALD(x0, c0, acc0);\r
+ acc1 = __SMLALD(x1, c0, acc1);\r
+ acc2 = __SMLALDX(x1, c0, acc2);\r
+ acc3 = __SMLALDX(x3, c0, acc3);\r
+ }\r
+\r
+ if(k == 2u)\r
+ {\r
+ /* Read y[srcBLen - 5], y[srcBLen - 6] */\r
+ c0 = _SIMD32_OFFSET(py);\r
+\r
+ /* Read x[7], x[8] */\r
+ x3 = *__SIMD32(px);\r
+\r
+ /* Read x[9] */\r
+ x2 = _SIMD32_OFFSET(px+1);\r
+ px += 2u;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 = __SMLALDX(x0, c0, acc0);\r
+ acc1 = __SMLALDX(x1, c0, acc1);\r
+ acc2 = __SMLALDX(x3, c0, acc2);\r
+ acc3 = __SMLALDX(x2, c0, acc3);\r
+ }\r
+\r
+ if(k == 3u)\r
+ {\r
+ /* Read y[srcBLen - 5], y[srcBLen - 6] */\r
+ c0 = _SIMD32_OFFSET(py);\r
+\r
+ /* Read x[7], x[8] */\r
+ x3 = *__SIMD32(px);\r
+\r
+ /* Read x[9] */\r
+ x2 = _SIMD32_OFFSET(px+1);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 = __SMLALDX(x0, c0, acc0);\r
+ acc1 = __SMLALDX(x1, c0, acc1);\r
+ acc2 = __SMLALDX(x3, c0, acc2);\r
+ acc3 = __SMLALDX(x2, c0, acc3);\r
+\r
+ c0 = *(py-1);\r
+\r
+#ifdef ARM_MATH_BIG_ENDIAN\r
+\r
+ c0 = c0 << 16u;\r
+#else\r
+\r
+ c0 = c0 & 0x0000FFFF;\r
+#endif /* #ifdef ARM_MATH_BIG_ENDIAN */\r
+ /* Read x[10] */\r
+ x3 = _SIMD32_OFFSET(px+2);\r
+ px += 3u;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 = __SMLALDX(x1, c0, acc0);\r
+ acc1 = __SMLALD(x2, c0, acc1);\r
+ acc2 = __SMLALDX(x2, c0, acc2);\r
+ acc3 = __SMLALDX(x3, c0, acc3);\r
+ }\r
+\r
+\r
+ /* Store the results in the accumulators in the destination buffer. */\r
+\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+\r
+ *__SIMD32(pOut)++ =\r
+ __PKHBT(__SSAT((acc0 >> 15), 16), __SSAT((acc1 >> 15), 16), 16);\r
+ *__SIMD32(pOut)++ =\r
+ __PKHBT(__SSAT((acc2 >> 15), 16), __SSAT((acc3 >> 15), 16), 16);\r
+\r
+#else\r
+\r
+ *__SIMD32(pOut)++ =\r
+ __PKHBT(__SSAT((acc1 >> 15), 16), __SSAT((acc0 >> 15), 16), 16);\r
+ *__SIMD32(pOut)++ =\r
+ __PKHBT(__SSAT((acc3 >> 15), 16), __SSAT((acc2 >> 15), 16), 16);\r
+\r
+#endif /* #ifndef ARM_MATH_BIG_ENDIAN */\r
+\r
+ /* Increment the pointer pIn1 index, count by 4 */\r
+ count += 4u;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize2 % 0x4u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = srcBLen >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum += (q63_t) ((q31_t) * px++ * *py--);\r
+ sum += (q63_t) ((q31_t) * px++ * *py--);\r
+ sum += (q63_t) ((q31_t) * px++ * *py--);\r
+ sum += (q63_t) ((q31_t) * px++ * *py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum += (q63_t) ((q31_t) * px++ * *py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q15_t) (__SSAT(sum >> 15, 16));\r
+\r
+ /* Increment the pointer pIn1 index, count by 1 */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* If the srcBLen is not a multiple of 4, \r
+ * the blockSize2 loop cannot be unrolled by 4 */\r
+ blkCnt = blockSize2;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* srcBLen number of MACS should be performed */\r
+ k = srcBLen;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += (q63_t) ((q31_t) * px++ * *py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q15_t) (__SSAT(sum >> 15, 16));\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage3 \r
+ * -------------------------*/\r
+\r
+ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] \r
+ * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] \r
+ * .... \r
+ * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] \r
+ * sum += x[srcALen-1] * y[srcBLen-1] \r
+ */\r
+\r
+ /* In this stage the MAC operations are decreased by 1 for every iteration. \r
+ The blockSize3 variable holds the number of MAC operations performed */\r
+\r
+ blockSize3 = srcBLen - 1u;\r
+\r
+ /* Working pointer of inputA */\r
+ pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u);\r
+ px = pSrc1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ pIn2 = pSrc2 - 1u;\r
+ py = pIn2;\r
+\r
+ /* ------------------- \r
+ * Stage3 process \r
+ * ------------------*/\r
+\r
+ /* For loop unrolling by 4, this stage is divided into two. */\r
+ /* First part of this stage computes the MAC operations greater than 4 */\r
+ /* Second part of this stage computes the MAC operations less than or equal to 4 */\r
+\r
+ /* The first part of the stage starts here */\r
+ j = blockSize3 >> 2u;\r
+\r
+ while((j > 0u) && (blockSize3 > 0u))\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = blockSize3 >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* x[srcALen - srcBLen + 1], x[srcALen - srcBLen + 2] are multiplied \r
+ * with y[srcBLen - 1], y[srcBLen - 2] respectively */\r
+ sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum);\r
+ /* x[srcALen - srcBLen + 3], x[srcALen - srcBLen + 4] are multiplied \r
+ * with y[srcBLen - 3], y[srcBLen - 4] respectively */\r
+ sum = __SMLALDX(*__SIMD32(px)++, *__SIMD32(py)--, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* For the next MAC operations, the pointer py is used without SIMD \r
+ * So, py is incremented by 1 */\r
+ py = py + 1u;\r
+\r
+ /* If the blockSize3 is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = blockSize3 % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* sum += x[srcALen - srcBLen + 5] * y[srcBLen - 5] */\r
+ sum = __SMLALD(*px++, *py--, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q15_t) (__SSAT((sum >> 15), 16));\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = ++pSrc1;\r
+ py = pIn2;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize3--;\r
+\r
+ j--;\r
+ }\r
+\r
+ /* The second part of the stage starts here */\r
+ /* SIMD is not used for the next MAC operations, \r
+ * so pointer py is updated to read only one sample at a time */\r
+ py = py + 1u;\r
+\r
+ while(blockSize3 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = blockSize3;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ /* sum += x[srcALen-1] * y[srcBLen-1] */\r
+ sum = __SMLALD(*px++, *py--, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q15_t) (__SSAT((sum >> 15), 16));\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = ++pSrc1;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize3--;\r
+ }\r
+\r
+#else\r
+\r
+/* Run the below code for Cortex-M0 */\r
+\r
+ q15_t *pIn1 = pSrcA; /* input pointer */\r
+ q15_t *pIn2 = pSrcB; /* coefficient pointer */\r
+ q63_t sum; /* Accumulator */\r
+ uint32_t i, j; /* loop counter */\r
+\r
+ /* Loop to calculate output of convolution for output length number of times */\r
+ for (i = 0; i < (srcALen + srcBLen - 1); i++)\r
+ {\r
+ /* Initialize sum with zero to carry on MAC operations */\r
+ sum = 0;\r
+\r
+ /* Loop to perform MAC operations according to convolution equation */\r
+ for (j = 0; j <= i; j++)\r
+ {\r
+ /* Check the array limitations */\r
+ if(((i - j) < srcBLen) && (j < srcALen))\r
+ {\r
+ /* z[i] += x[i-j] * y[j] */\r
+ sum += (q31_t) pIn1[j] * (pIn2[i - j]);\r
+ }\r
+ }\r
+\r
+ /* Store the output in the destination buffer */\r
+ pDst[i] = (q15_t) __SSAT((sum >> 15u), 16u);\r
+ }\r
+\r
+#endif /* #if (defined(ARM_MATH_CM4) || defined(ARM_MATH_CM3)) && !defined(UNALIGNED_SUPPORT_DISABLE)*/\r
+\r
+}\r
+\r
+/** \r
+ * @} end of Conv group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_conv_q31.c \r
+* \r
+* Description: Convolution of Q31 sequences. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup Conv \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @brief Convolution of Q31 sequences. \r
+ * @param[in] *pSrcA points to the first input sequence. \r
+ * @param[in] srcALen length of the first input sequence. \r
+ * @param[in] *pSrcB points to the second input sequence. \r
+ * @param[in] srcBLen length of the second input sequence. \r
+ * @param[out] *pDst points to the location where the output result is written. Length srcALen+srcBLen-1. \r
+ * @return none. \r
+ * \r
+ * @details \r
+ * <b>Scaling and Overflow Behavior:</b> \r
+ * \r
+ * \par \r
+ * The function is implemented using an internal 64-bit accumulator. \r
+ * The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. \r
+ * There is no saturation on intermediate additions. \r
+ * Thus, if the accumulator overflows it wraps around and distorts the result. \r
+ * The input signals should be scaled down to avoid intermediate overflows. \r
+ * Scale down the inputs by log2(min(srcALen, srcBLen)) (log2 is read as log to the base 2) times to avoid overflows, \r
+ * as maximum of min(srcALen, srcBLen) number of additions are carried internally. \r
+ * The 2.62 accumulator is right shifted by 31 bits and saturated to 1.31 format to yield the final result. \r
+ * \r
+ * \par \r
+ * See <code>arm_conv_fast_q31()</code> for a faster but less precise implementation of this function for Cortex-M3 and Cortex-M4. \r
+ */\r
+\r
+void arm_conv_q31(\r
+ q31_t * pSrcA,\r
+ uint32_t srcALen,\r
+ q31_t * pSrcB,\r
+ uint32_t srcBLen,\r
+ q31_t * pDst)\r
+{\r
+\r
+\r
+#ifndef ARM_MATH_CM0_FAMILY\r
+\r
+ /* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+ q31_t *pIn1; /* inputA pointer */\r
+ q31_t *pIn2; /* inputB pointer */\r
+ q31_t *pOut = pDst; /* output pointer */\r
+ q31_t *px; /* Intermediate inputA pointer */\r
+ q31_t *py; /* Intermediate inputB pointer */\r
+ q31_t *pSrc1, *pSrc2; /* Intermediate pointers */\r
+ q63_t sum; /* Accumulator */\r
+ q63_t acc0, acc1, acc2; /* Accumulator */\r
+ q31_t x0, x1, x2, c0; /* Temporary variables to hold state and coefficient values */\r
+ uint32_t j, k, count, blkCnt, blockSize1, blockSize2, blockSize3; /* loop counter */\r
+\r
+ /* The algorithm implementation is based on the lengths of the inputs. */\r
+ /* srcB is always made to slide across srcA. */\r
+ /* So srcBLen is always considered as shorter or equal to srcALen */\r
+ if(srcALen >= srcBLen)\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = pSrcA;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = pSrcB;\r
+ }\r
+ else\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = (q31_t *) pSrcB;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = (q31_t *) pSrcA;\r
+\r
+ /* srcBLen is always considered as shorter or equal to srcALen */\r
+ j = srcBLen;\r
+ srcBLen = srcALen;\r
+ srcALen = j;\r
+ }\r
+\r
+ /* conv(x,y) at n = x[n] * y[0] + x[n-1] * y[1] + x[n-2] * y[2] + ...+ x[n-N+1] * y[N -1] */\r
+ /* The function is internally \r
+ * divided into three stages according to the number of multiplications that has to be \r
+ * taken place between inputA samples and inputB samples. In the first stage of the \r
+ * algorithm, the multiplications increase by one for every iteration. \r
+ * In the second stage of the algorithm, srcBLen number of multiplications are done. \r
+ * In the third stage of the algorithm, the multiplications decrease by one \r
+ * for every iteration. */\r
+\r
+ /* The algorithm is implemented in three stages. \r
+ The loop counters of each stage is initiated here. */\r
+ blockSize1 = srcBLen - 1u;\r
+ blockSize2 = srcALen - (srcBLen - 1u);\r
+ blockSize3 = blockSize1;\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage1 \r
+ * -------------------------*/\r
+\r
+ /* sum = x[0] * y[0] \r
+ * sum = x[0] * y[1] + x[1] * y[0] \r
+ * .... \r
+ * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] \r
+ */\r
+\r
+ /* In this stage the MAC operations are increased by 1 for every iteration. \r
+ The count variable holds the number of MAC operations performed */\r
+ count = 1u;\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ py = pIn2;\r
+\r
+\r
+ /* ------------------------ \r
+ * Stage1 process \r
+ * ----------------------*/\r
+\r
+ /* The first stage starts here */\r
+ while(blockSize1 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = count >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* x[0] * y[srcBLen - 1] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+ /* x[1] * y[srcBLen - 2] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+ /* x[2] * y[srcBLen - 3] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+ /* x[3] * y[srcBLen - 4] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the count is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = count % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += (q63_t) * px++ * (*py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q31_t) (sum >> 31);\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ py = pIn2 + count;\r
+ px = pIn1;\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize1--;\r
+ }\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage2 \r
+ * ------------------------*/\r
+\r
+ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] \r
+ * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] \r
+ * .... \r
+ * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] \r
+ */\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ py = pSrc2;\r
+\r
+ /* count is index by which the pointer pIn1 to be incremented */\r
+ count = 0u;\r
+\r
+ /* ------------------- \r
+ * Stage2 process \r
+ * ------------------*/\r
+\r
+ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. \r
+ * So, to loop unroll over blockSize2, \r
+ * srcBLen should be greater than or equal to 4 */\r
+ if(srcBLen >= 4u)\r
+ {\r
+ /* Loop unroll by 3 */\r
+ blkCnt = blockSize2 / 3;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0;\r
+ acc1 = 0;\r
+ acc2 = 0;\r
+\r
+ /* read x[0], x[1], x[2] samples */\r
+ x0 = *(px++);\r
+ x1 = *(px++);\r
+\r
+ /* Apply loop unrolling and compute 3 MACs simultaneously. */\r
+ k = srcBLen / 3;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 3 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 2 samples. */\r
+ do\r
+ {\r
+ /* Read y[srcBLen - 1] sample */\r
+ c0 = *(py);\r
+\r
+ /* Read x[3] sample */\r
+ x2 = *(px);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ /* acc0 += x[0] * y[srcBLen - 1] */\r
+ acc0 += ((q63_t) x0 * c0);\r
+ /* acc1 += x[1] * y[srcBLen - 1] */\r
+ acc1 += ((q63_t) x1 * c0);\r
+ /* acc2 += x[2] * y[srcBLen - 1] */\r
+ acc2 += ((q63_t) x2 * c0);\r
+\r
+ /* Read y[srcBLen - 2] sample */\r
+ c0 = *(py - 1u);\r
+\r
+ /* Read x[4] sample */\r
+ x0 = *(px + 1u);\r
+\r
+ /* Perform the multiply-accumulate */\r
+ /* acc0 += x[1] * y[srcBLen - 2] */\r
+ acc0 += ((q63_t) x1 * c0);\r
+ /* acc1 += x[2] * y[srcBLen - 2] */\r
+ acc1 += ((q63_t) x2 * c0);\r
+ /* acc2 += x[3] * y[srcBLen - 2] */\r
+ acc2 += ((q63_t) x0 * c0);\r
+\r
+ /* Read y[srcBLen - 3] sample */\r
+ c0 = *(py - 2u);\r
+\r
+ /* Read x[5] sample */\r
+ x1 = *(px + 2u);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ /* acc0 += x[2] * y[srcBLen - 3] */\r
+ acc0 += ((q63_t) x2 * c0);\r
+ /* acc1 += x[3] * y[srcBLen - 2] */\r
+ acc1 += ((q63_t) x0 * c0);\r
+ /* acc2 += x[4] * y[srcBLen - 2] */\r
+ acc2 += ((q63_t) x1 * c0);\r
+\r
+ /* update scratch pointers */\r
+ px += 3u;\r
+ py -= 3u;\r
+\r
+ } while(--k);\r
+\r
+ /* If the srcBLen is not a multiple of 3, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen - (3 * (srcBLen / 3));\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Read y[srcBLen - 5] sample */\r
+ c0 = *(py--);\r
+\r
+ /* Read x[7] sample */\r
+ x2 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ /* acc0 += x[4] * y[srcBLen - 5] */\r
+ acc0 += ((q63_t) x0 * c0);\r
+ /* acc1 += x[5] * y[srcBLen - 5] */\r
+ acc1 += ((q63_t) x1 * c0);\r
+ /* acc2 += x[6] * y[srcBLen - 5] */\r
+ acc2 += ((q63_t) x2 * c0);\r
+\r
+ /* Reuse the present samples for the next MAC */\r
+ x0 = x1;\r
+ x1 = x2;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the results in the accumulators in the destination buffer. */\r
+ *pOut++ = (q31_t) (acc0 >> 31);\r
+ *pOut++ = (q31_t) (acc1 >> 31);\r
+ *pOut++ = (q31_t) (acc2 >> 31);\r
+\r
+ /* Increment the pointer pIn1 index, count by 3 */\r
+ count += 3u;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize2 is not a multiple of 3, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize2 - 3 * (blockSize2 / 3);\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = srcBLen >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum += (q63_t) * px++ * (*py--);\r
+ sum += (q63_t) * px++ * (*py--);\r
+ sum += (q63_t) * px++ * (*py--);\r
+ sum += (q63_t) * px++ * (*py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += (q63_t) * px++ * (*py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q31_t) (sum >> 31);\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* If the srcBLen is not a multiple of 4, \r
+ * the blockSize2 loop cannot be unrolled by 4 */\r
+ blkCnt = blockSize2;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* srcBLen number of MACS should be performed */\r
+ k = srcBLen;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += (q63_t) * px++ * (*py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q31_t) (sum >> 31);\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage3 \r
+ * -------------------------*/\r
+\r
+ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] \r
+ * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] \r
+ * .... \r
+ * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] \r
+ * sum += x[srcALen-1] * y[srcBLen-1] \r
+ */\r
+\r
+ /* In this stage the MAC operations are decreased by 1 for every iteration. \r
+ The blockSize3 variable holds the number of MAC operations performed */\r
+\r
+ /* Working pointer of inputA */\r
+ pSrc1 = (pIn1 + srcALen) - (srcBLen - 1u);\r
+ px = pSrc1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ py = pSrc2;\r
+\r
+ /* ------------------- \r
+ * Stage3 process \r
+ * ------------------*/\r
+\r
+ while(blockSize3 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = blockSize3 >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+ /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+ /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+ /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */\r
+ sum += (q63_t) * px++ * (*py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the blockSize3 is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = blockSize3 % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += (q63_t) * px++ * (*py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q31_t) (sum >> 31);\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = ++pSrc1;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize3--;\r
+ }\r
+\r
+#else\r
+\r
+ /* Run the below code for Cortex-M0 */\r
+\r
+ q31_t *pIn1 = pSrcA; /* input pointer */\r
+ q31_t *pIn2 = pSrcB; /* coefficient pointer */\r
+ q63_t sum; /* Accumulator */\r
+ uint32_t i, j; /* loop counter */\r
+\r
+ /* Loop to calculate output of convolution for output length number of times */\r
+ for (i = 0; i < (srcALen + srcBLen - 1); i++)\r
+ {\r
+ /* Initialize sum with zero to carry on MAC operations */\r
+ sum = 0;\r
+\r
+ /* Loop to perform MAC operations according to convolution equation */\r
+ for (j = 0; j <= i; j++)\r
+ {\r
+ /* Check the array limitations */\r
+ if(((i - j) < srcBLen) && (j < srcALen))\r
+ {\r
+ /* z[i] += x[i-j] * y[j] */\r
+ sum += ((q63_t) pIn1[j] * (pIn2[i - j]));\r
+ }\r
+ }\r
+\r
+ /* Store the output in the destination buffer */\r
+ pDst[i] = (q31_t) (sum >> 31u);\r
+ }\r
+\r
+#endif /* #ifndef ARM_MATH_CM0_FAMILY */\r
+\r
+}\r
+\r
+/** \r
+ * @} end of Conv group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_conv_q7.c \r
+* \r
+* Description: Convolution of Q7 sequences. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup Conv \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @brief Convolution of Q7 sequences. \r
+ * @param[in] *pSrcA points to the first input sequence. \r
+ * @param[in] srcALen length of the first input sequence. \r
+ * @param[in] *pSrcB points to the second input sequence. \r
+ * @param[in] srcBLen length of the second input sequence. \r
+ * @param[out] *pDst points to the location where the output result is written. Length srcALen+srcBLen-1. \r
+ * @return none. \r
+ * \r
+ * @details \r
+ * <b>Scaling and Overflow Behavior:</b> \r
+ * \r
+ * \par \r
+ * The function is implemented using a 32-bit internal accumulator. \r
+ * Both the inputs are represented in 1.7 format and multiplications yield a 2.14 result. \r
+ * The 2.14 intermediate results are accumulated in a 32-bit accumulator in 18.14 format. \r
+ * This approach provides 17 guard bits and there is no risk of overflow as long as <code>max(srcALen, srcBLen)<131072</code>. \r
+ * The 18.14 result is then truncated to 18.7 format by discarding the low 7 bits and then saturated to 1.7 format. \r
+ *\r
+ * \par \r
+ * Refer the function <code>arm_conv_opt_q7()</code> for a faster implementation of this function.\r
+ * \r
+ */\r
+\r
+void arm_conv_q7(\r
+ q7_t * pSrcA,\r
+ uint32_t srcALen,\r
+ q7_t * pSrcB,\r
+ uint32_t srcBLen,\r
+ q7_t * pDst)\r
+{\r
+\r
+\r
+#ifndef ARM_MATH_CM0_FAMILY\r
+\r
+ /* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+ q7_t *pIn1; /* inputA pointer */\r
+ q7_t *pIn2; /* inputB pointer */\r
+ q7_t *pOut = pDst; /* output pointer */\r
+ q7_t *px; /* Intermediate inputA pointer */\r
+ q7_t *py; /* Intermediate inputB pointer */\r
+ q7_t *pSrc1, *pSrc2; /* Intermediate pointers */\r
+ q7_t x0, x1, x2, x3, c0, c1; /* Temporary variables to hold state and coefficient values */\r
+ q31_t sum, acc0, acc1, acc2, acc3; /* Accumulator */\r
+ q31_t input1, input2; /* Temporary input variables */\r
+ q15_t in1, in2; /* Temporary input variables */\r
+ uint32_t j, k, count, blkCnt, blockSize1, blockSize2, blockSize3; /* loop counter */\r
+\r
+ /* The algorithm implementation is based on the lengths of the inputs. */\r
+ /* srcB is always made to slide across srcA. */\r
+ /* So srcBLen is always considered as shorter or equal to srcALen */\r
+ if(srcALen >= srcBLen)\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = pSrcA;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = pSrcB;\r
+ }\r
+ else\r
+ {\r
+ /* Initialization of inputA pointer */\r
+ pIn1 = pSrcB;\r
+\r
+ /* Initialization of inputB pointer */\r
+ pIn2 = pSrcA;\r
+\r
+ /* srcBLen is always considered as shorter or equal to srcALen */\r
+ j = srcBLen;\r
+ srcBLen = srcALen;\r
+ srcALen = j;\r
+ }\r
+\r
+ /* conv(x,y) at n = x[n] * y[0] + x[n-1] * y[1] + x[n-2] * y[2] + ...+ x[n-N+1] * y[N -1] */\r
+ /* The function is internally \r
+ * divided into three stages according to the number of multiplications that has to be \r
+ * taken place between inputA samples and inputB samples. In the first stage of the \r
+ * algorithm, the multiplications increase by one for every iteration. \r
+ * In the second stage of the algorithm, srcBLen number of multiplications are done. \r
+ * In the third stage of the algorithm, the multiplications decrease by one \r
+ * for every iteration. */\r
+\r
+ /* The algorithm is implemented in three stages. \r
+ The loop counters of each stage is initiated here. */\r
+ blockSize1 = srcBLen - 1u;\r
+ blockSize2 = (srcALen - srcBLen) + 1u;\r
+ blockSize3 = blockSize1;\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage1 \r
+ * -------------------------*/\r
+\r
+ /* sum = x[0] * y[0] \r
+ * sum = x[0] * y[1] + x[1] * y[0] \r
+ * .... \r
+ * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] \r
+ */\r
+\r
+ /* In this stage the MAC operations are increased by 1 for every iteration. \r
+ The count variable holds the number of MAC operations performed */\r
+ count = 1u;\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ py = pIn2;\r
+\r
+\r
+ /* ------------------------ \r
+ * Stage1 process \r
+ * ----------------------*/\r
+\r
+ /* The first stage starts here */\r
+ while(blockSize1 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = count >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* x[0] , x[1] */\r
+ in1 = (q15_t) * px++;\r
+ in2 = (q15_t) * px++;\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* y[srcBLen - 1] , y[srcBLen - 2] */\r
+ in1 = (q15_t) * py--;\r
+ in2 = (q15_t) * py--;\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* x[0] * y[srcBLen - 1] */\r
+ /* x[1] * y[srcBLen - 2] */\r
+ sum = __SMLAD(input1, input2, sum);\r
+\r
+ /* x[2] , x[3] */\r
+ in1 = (q15_t) * px++;\r
+ in2 = (q15_t) * px++;\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* y[srcBLen - 3] , y[srcBLen - 4] */\r
+ in1 = (q15_t) * py--;\r
+ in2 = (q15_t) * py--;\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* x[2] * y[srcBLen - 3] */\r
+ /* x[3] * y[srcBLen - 4] */\r
+ sum = __SMLAD(input1, input2, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the count is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = count % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum += ((q15_t) * px++ * *py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q7_t) (__SSAT(sum >> 7u, 8));\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ py = pIn2 + count;\r
+ px = pIn1;\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize1--;\r
+ }\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage2 \r
+ * ------------------------*/\r
+\r
+ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] \r
+ * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] \r
+ * .... \r
+ * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] \r
+ */\r
+\r
+ /* Working pointer of inputA */\r
+ px = pIn1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ py = pSrc2;\r
+\r
+ /* count is index by which the pointer pIn1 to be incremented */\r
+ count = 0u;\r
+\r
+ /* ------------------- \r
+ * Stage2 process \r
+ * ------------------*/\r
+\r
+ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. \r
+ * So, to loop unroll over blockSize2, \r
+ * srcBLen should be greater than or equal to 4 */\r
+ if(srcBLen >= 4u)\r
+ {\r
+ /* Loop unroll over blockSize2, by 4 */\r
+ blkCnt = blockSize2 >> 2u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0;\r
+ acc1 = 0;\r
+ acc2 = 0;\r
+ acc3 = 0;\r
+\r
+ /* read x[0], x[1], x[2] samples */\r
+ x0 = *(px++);\r
+ x1 = *(px++);\r
+ x2 = *(px++);\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = srcBLen >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ do\r
+ {\r
+ /* Read y[srcBLen - 1] sample */\r
+ c0 = *(py--);\r
+ /* Read y[srcBLen - 2] sample */\r
+ c1 = *(py--);\r
+\r
+ /* Read x[3] sample */\r
+ x3 = *(px++);\r
+\r
+ /* x[0] and x[1] are packed */\r
+ in1 = (q15_t) x0;\r
+ in2 = (q15_t) x1;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* y[srcBLen - 1] and y[srcBLen - 2] are packed */\r
+ in1 = (q15_t) c0;\r
+ in2 = (q15_t) c1;\r
+\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */\r
+ acc0 = __SMLAD(input1, input2, acc0);\r
+\r
+ /* x[1] and x[2] are packed */\r
+ in1 = (q15_t) x1;\r
+ in2 = (q15_t) x2;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */\r
+ acc1 = __SMLAD(input1, input2, acc1);\r
+\r
+ /* x[2] and x[3] are packed */\r
+ in1 = (q15_t) x2;\r
+ in2 = (q15_t) x3;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */\r
+ acc2 = __SMLAD(input1, input2, acc2);\r
+\r
+ /* Read x[4] sample */\r
+ x0 = *(px++);\r
+\r
+ /* x[3] and x[4] are packed */\r
+ in1 = (q15_t) x3;\r
+ in2 = (q15_t) x0;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */\r
+ acc3 = __SMLAD(input1, input2, acc3);\r
+\r
+ /* Read y[srcBLen - 3] sample */\r
+ c0 = *(py--);\r
+ /* Read y[srcBLen - 4] sample */\r
+ c1 = *(py--);\r
+\r
+ /* Read x[5] sample */\r
+ x1 = *(px++);\r
+\r
+ /* x[2] and x[3] are packed */\r
+ in1 = (q15_t) x2;\r
+ in2 = (q15_t) x3;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* y[srcBLen - 3] and y[srcBLen - 4] are packed */\r
+ in1 = (q15_t) c0;\r
+ in2 = (q15_t) c1;\r
+\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */\r
+ acc0 = __SMLAD(input1, input2, acc0);\r
+\r
+ /* x[3] and x[4] are packed */\r
+ in1 = (q15_t) x3;\r
+ in2 = (q15_t) x0;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */\r
+ acc1 = __SMLAD(input1, input2, acc1);\r
+\r
+ /* x[4] and x[5] are packed */\r
+ in1 = (q15_t) x0;\r
+ in2 = (q15_t) x1;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */\r
+ acc2 = __SMLAD(input1, input2, acc2);\r
+\r
+ /* Read x[6] sample */\r
+ x2 = *(px++);\r
+\r
+ /* x[5] and x[6] are packed */\r
+ in1 = (q15_t) x1;\r
+ in2 = (q15_t) x2;\r
+\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */\r
+ acc3 = __SMLAD(input1, input2, acc3);\r
+\r
+ } while(--k);\r
+\r
+ /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Read y[srcBLen - 5] sample */\r
+ c0 = *(py--);\r
+\r
+ /* Read x[7] sample */\r
+ x3 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ /* acc0 += x[4] * y[srcBLen - 5] */\r
+ acc0 += ((q15_t) x0 * c0);\r
+ /* acc1 += x[5] * y[srcBLen - 5] */\r
+ acc1 += ((q15_t) x1 * c0);\r
+ /* acc2 += x[6] * y[srcBLen - 5] */\r
+ acc2 += ((q15_t) x2 * c0);\r
+ /* acc3 += x[7] * y[srcBLen - 5] */\r
+ acc3 += ((q15_t) x3 * c0);\r
+\r
+ /* Reuse the present samples for the next MAC */\r
+ x0 = x1;\r
+ x1 = x2;\r
+ x2 = x3;\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q7_t) (__SSAT(acc0 >> 7u, 8));\r
+ *pOut++ = (q7_t) (__SSAT(acc1 >> 7u, 8));\r
+ *pOut++ = (q7_t) (__SSAT(acc2 >> 7u, 8));\r
+ *pOut++ = (q7_t) (__SSAT(acc3 >> 7u, 8));\r
+\r
+ /* Increment the pointer pIn1 index, count by 4 */\r
+ count += 4u;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize2 is not a multiple of 4, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize2 % 0x4u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = srcBLen >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+\r
+ /* Reading two inputs of SrcA buffer and packing */\r
+ in1 = (q15_t) * px++;\r
+ in2 = (q15_t) * px++;\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* Reading two inputs of SrcB buffer and packing */\r
+ in1 = (q15_t) * py--;\r
+ in2 = (q15_t) * py--;\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ sum = __SMLAD(input1, input2, sum);\r
+\r
+ /* Reading two inputs of SrcA buffer and packing */\r
+ in1 = (q15_t) * px++;\r
+ in2 = (q15_t) * px++;\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* Reading two inputs of SrcB buffer and packing */\r
+ in1 = (q15_t) * py--;\r
+ in2 = (q15_t) * py--;\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ sum = __SMLAD(input1, input2, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = srcBLen % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum += ((q15_t) * px++ * *py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q7_t) (__SSAT(sum >> 7u, 8));\r
+\r
+ /* Increment the pointer pIn1 index, count by 1 */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* If the srcBLen is not a multiple of 4, \r
+ * the blockSize2 loop cannot be unrolled by 4 */\r
+ blkCnt = blockSize2;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* srcBLen number of MACS should be performed */\r
+ k = srcBLen;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulate */\r
+ sum += ((q15_t) * px++ * *py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q7_t) (__SSAT(sum >> 7u, 8));\r
+\r
+ /* Increment the MAC count */\r
+ count++;\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = pIn1 + count;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+ }\r
+\r
+\r
+ /* -------------------------- \r
+ * Initializations of stage3 \r
+ * -------------------------*/\r
+\r
+ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] \r
+ * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] \r
+ * .... \r
+ * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] \r
+ * sum += x[srcALen-1] * y[srcBLen-1] \r
+ */\r
+\r
+ /* In this stage the MAC operations are decreased by 1 for every iteration. \r
+ The blockSize3 variable holds the number of MAC operations performed */\r
+\r
+ /* Working pointer of inputA */\r
+ pSrc1 = pIn1 + (srcALen - (srcBLen - 1u));\r
+ px = pSrc1;\r
+\r
+ /* Working pointer of inputB */\r
+ pSrc2 = pIn2 + (srcBLen - 1u);\r
+ py = pSrc2;\r
+\r
+ /* ------------------- \r
+ * Stage3 process \r
+ * ------------------*/\r
+\r
+ while(blockSize3 > 0u)\r
+ {\r
+ /* Accumulator is made zero for every iteration */\r
+ sum = 0;\r
+\r
+ /* Apply loop unrolling and compute 4 MACs simultaneously. */\r
+ k = blockSize3 >> 2u;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 MACs at a time. \r
+ ** a second loop below computes MACs for the remaining 1 to 3 samples. */\r
+ while(k > 0u)\r
+ {\r
+ /* Reading two inputs, x[srcALen - srcBLen + 1] and x[srcALen - srcBLen + 2] of SrcA buffer and packing */\r
+ in1 = (q15_t) * px++;\r
+ in2 = (q15_t) * px++;\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* Reading two inputs, y[srcBLen - 1] and y[srcBLen - 2] of SrcB buffer and packing */\r
+ in1 = (q15_t) * py--;\r
+ in2 = (q15_t) * py--;\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */\r
+ /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */\r
+ sum = __SMLAD(input1, input2, sum);\r
+\r
+ /* Reading two inputs, x[srcALen - srcBLen + 3] and x[srcALen - srcBLen + 4] of SrcA buffer and packing */\r
+ in1 = (q15_t) * px++;\r
+ in2 = (q15_t) * px++;\r
+ input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* Reading two inputs, y[srcBLen - 3] and y[srcBLen - 4] of SrcB buffer and packing */\r
+ in1 = (q15_t) * py--;\r
+ in2 = (q15_t) * py--;\r
+ input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16u);\r
+\r
+ /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */\r
+ /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */\r
+ sum = __SMLAD(input1, input2, sum);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* If the blockSize3 is not a multiple of 4, compute any remaining MACs here. \r
+ ** No loop unrolling is used. */\r
+ k = blockSize3 % 0x4u;\r
+\r
+ while(k > 0u)\r
+ {\r
+ /* Perform the multiply-accumulates */\r
+ sum += ((q15_t) * px++ * *py--);\r
+\r
+ /* Decrement the loop counter */\r
+ k--;\r
+ }\r
+\r
+ /* Store the result in the accumulator in the destination buffer. */\r
+ *pOut++ = (q7_t) (__SSAT(sum >> 7u, 8));\r
+\r
+ /* Update the inputA and inputB pointers for next MAC calculation */\r
+ px = ++pSrc1;\r
+ py = pSrc2;\r
+\r
+ /* Decrement the loop counter */\r
+ blockSize3--;\r
+ }\r
+\r
+#else\r
+\r
+ /* Run the below code for Cortex-M0 */\r
+\r
+ q7_t *pIn1 = pSrcA; /* input pointer */\r
+ q7_t *pIn2 = pSrcB; /* coefficient pointer */\r
+ q31_t sum; /* Accumulator */\r
+ uint32_t i, j; /* loop counter */\r
+\r
+ /* Loop to calculate output of convolution for output length number of times */\r
+ for (i = 0; i < (srcALen + srcBLen - 1); i++)\r
+ {\r
+ /* Initialize sum with zero to carry on MAC operations */\r
+ sum = 0;\r
+\r
+ /* Loop to perform MAC operations according to convolution equation */\r
+ for (j = 0; j <= i; j++)\r
+ {\r
+ /* Check the array limitations */\r
+ if(((i - j) < srcBLen) && (j < srcALen))\r
+ {\r
+ /* z[i] += x[i-j] * y[j] */\r
+ sum += (q15_t) pIn1[j] * (pIn2[i - j]);\r
+ }\r
+ }\r
+\r
+ /* Store the output in the destination buffer */\r
+ pDst[i] = (q7_t) __SSAT((sum >> 7u), 8u);\r
+ }\r
+\r
+#endif /* #ifndef ARM_MATH_CM0_FAMILY */\r
+\r
+}\r
+\r
+/** \r
+ * @} end of Conv group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_f32.c \r
+* \r
+* Description: Floating-point FIR filter processing function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+* @ingroup groupFilters \r
+*/\r
+\r
+/** \r
+* @defgroup FIR Finite Impulse Response (FIR) Filters \r
+* \r
+* This set of functions implements Finite Impulse Response (FIR) filters \r
+* for Q7, Q15, Q31, and floating-point data types. Fast versions of Q15 and Q31 are also provided. \r
+* The functions operate on blocks of input and output data and each call to the function processes \r
+* <code>blockSize</code> samples through the filter. <code>pSrc</code> and \r
+* <code>pDst</code> points to input and output arrays containing <code>blockSize</code> values. \r
+* \r
+* \par Algorithm: \r
+* The FIR filter algorithm is based upon a sequence of multiply-accumulate (MAC) operations. \r
+* Each filter coefficient <code>b[n]</code> is multiplied by a state variable which equals a previous input sample <code>x[n]</code>. \r
+* <pre> \r
+* y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1] \r
+* </pre> \r
+* \par \r
+* \image html FIR.gif "Finite Impulse Response filter" \r
+* \par \r
+* <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>. \r
+* Coefficients are stored in time reversed order. \r
+* \par \r
+* <pre> \r
+* {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} \r
+* </pre> \r
+* \par \r
+* <code>pState</code> points to a state array of size <code>numTaps + blockSize - 1</code>. \r
+* Samples in the state buffer are stored in the following order. \r
+* \par \r
+* <pre> \r
+* {x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]} \r
+* </pre> \r
+* \par \r
+* Note that the length of the state buffer exceeds the length of the coefficient array by <code>blockSize-1</code>. \r
+* The increased state buffer length allows circular addressing, which is traditionally used in the FIR filters, \r
+* to be avoided and yields a significant speed improvement. \r
+* The state variables are updated after each block of data is processed; the coefficients are untouched. \r
+* \par Instance Structure \r
+* The coefficients and state variables for a filter are stored together in an instance data structure. \r
+* A separate instance structure must be defined for each filter. \r
+* Coefficient arrays may be shared among several instances while state variable arrays cannot be shared. \r
+* There are separate instance structure declarations for each of the 4 supported data types. \r
+* \r
+* \par Initialization Functions \r
+* There is also an associated initialization function for each data type. \r
+* The initialization function performs the following operations: \r
+* - Sets the values of the internal structure fields. \r
+* - Zeros out the values in the state buffer. \r
+* To do this manually without calling the init function, assign the follow subfields of the instance structure:\r
+* numTaps, pCoeffs, pState. Also set all of the values in pState to zero. \r
+* \r
+* \par \r
+* Use of the initialization function is optional. \r
+* However, if the initialization function is used, then the instance structure cannot be placed into a const data section. \r
+* To place an instance structure into a const data section, the instance structure must be manually initialized. \r
+* Set the values in the state buffer to zeros before static initialization. \r
+* The code below statically initializes each of the 4 different data type filter instance structures \r
+* <pre> \r
+*arm_fir_instance_f32 S = {numTaps, pState, pCoeffs}; \r
+*arm_fir_instance_q31 S = {numTaps, pState, pCoeffs}; \r
+*arm_fir_instance_q15 S = {numTaps, pState, pCoeffs}; \r
+*arm_fir_instance_q7 S = {numTaps, pState, pCoeffs}; \r
+* </pre> \r
+* \r
+* where <code>numTaps</code> is the number of filter coefficients in the filter; <code>pState</code> is the address of the state buffer; \r
+* <code>pCoeffs</code> is the address of the coefficient buffer. \r
+* \r
+* \par Fixed-Point Behavior \r
+* Care must be taken when using the fixed-point versions of the FIR filter functions. \r
+* In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. \r
+* Refer to the function specific documentation below for usage guidelines. \r
+*/\r
+\r
+/** \r
+* @addtogroup FIR \r
+* @{ \r
+*/\r
+\r
+/** \r
+* \r
+* @param[in] *S points to an instance of the floating-point FIR filter structure. \r
+* @param[in] *pSrc points to the block of input data. \r
+* @param[out] *pDst points to the block of output data. \r
+* @param[in] blockSize number of samples to process per call. \r
+* @return none. \r
+* \r
+*/\r
+\r
+#if defined(ARM_MATH_CM7)\r
+\r
+void arm_fir_f32(\r
+const arm_fir_instance_f32 * S,\r
+float32_t * pSrc,\r
+float32_t * pDst,\r
+uint32_t blockSize)\r
+{\r
+ float32_t *pState = S->pState; /* State pointer */\r
+ float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ float32_t *pStateCurnt; /* Points to the current sample of the state */\r
+ float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */\r
+ float32_t acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7; /* Accumulators */\r
+ float32_t x0, x1, x2, x3, x4, x5, x6, x7, c0; /* Temporary variables to hold state and coefficient values */\r
+ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */\r
+ uint32_t i, tapCnt, blkCnt; /* Loop counters */\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Apply loop unrolling and compute 8 output values simultaneously. \r
+ * The variables acc0 ... acc7 hold output values that are being computed: \r
+ * \r
+ * acc0 = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] \r
+ * acc1 = b[numTaps-1] * x[n-numTaps] + b[numTaps-2] * x[n-numTaps-1] + b[numTaps-3] * x[n-numTaps-2] +...+ b[0] * x[1] \r
+ * acc2 = b[numTaps-1] * x[n-numTaps+1] + b[numTaps-2] * x[n-numTaps] + b[numTaps-3] * x[n-numTaps-1] +...+ b[0] * x[2] \r
+ * acc3 = b[numTaps-1] * x[n-numTaps+2] + b[numTaps-2] * x[n-numTaps+1] + b[numTaps-3] * x[n-numTaps] +...+ b[0] * x[3] \r
+ */\r
+ blkCnt = blockSize >> 3;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 8 outputs at a time. \r
+ ** a second loop below computes the remaining 1 to 7 samples. */\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy four new input samples into the state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0.0f;\r
+ acc1 = 0.0f;\r
+ acc2 = 0.0f;\r
+ acc3 = 0.0f;\r
+ acc4 = 0.0f;\r
+ acc5 = 0.0f;\r
+ acc6 = 0.0f;\r
+ acc7 = 0.0f; \r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize coeff pointer */\r
+ pb = (pCoeffs); \r
+ \r
+ /* This is separated from the others to avoid \r
+ * a call to __aeabi_memmove which would be slower\r
+ */\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Read the first seven samples from the state buffer: x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2] */\r
+ x0 = *px++;\r
+ x1 = *px++;\r
+ x2 = *px++;\r
+ x3 = *px++;\r
+ x4 = *px++;\r
+ x5 = *px++;\r
+ x6 = *px++;\r
+\r
+ /* Loop unrolling. Process 8 taps at a time. */\r
+ tapCnt = numTaps >> 3u;\r
+ \r
+ /* Loop over the number of taps. Unroll by a factor of 8. \r
+ ** Repeat until we've computed numTaps-8 coefficients. */\r
+ while(tapCnt > 0u)\r
+ {\r
+ /* Read the b[numTaps-1] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-3] sample */\r
+ x7 = *(px++);\r
+\r
+ /* acc0 += b[numTaps-1] * x[n-numTaps] */\r
+ acc0 += x0 * c0;\r
+\r
+ /* acc1 += b[numTaps-1] * x[n-numTaps-1] */\r
+ acc1 += x1 * c0;\r
+\r
+ /* acc2 += b[numTaps-1] * x[n-numTaps-2] */\r
+ acc2 += x2 * c0;\r
+\r
+ /* acc3 += b[numTaps-1] * x[n-numTaps-3] */\r
+ acc3 += x3 * c0;\r
+\r
+ /* acc4 += b[numTaps-1] * x[n-numTaps-4] */\r
+ acc4 += x4 * c0;\r
+\r
+ /* acc1 += b[numTaps-1] * x[n-numTaps-5] */\r
+ acc5 += x5 * c0;\r
+\r
+ /* acc2 += b[numTaps-1] * x[n-numTaps-6] */\r
+ acc6 += x6 * c0;\r
+\r
+ /* acc3 += b[numTaps-1] * x[n-numTaps-7] */\r
+ acc7 += x7 * c0;\r
+ \r
+ /* Read the b[numTaps-2] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-4] sample */\r
+ x0 = *(px++);\r
+\r
+ /* Perform the multiply-accumulate */\r
+ acc0 += x1 * c0;\r
+ acc1 += x2 * c0; \r
+ acc2 += x3 * c0; \r
+ acc3 += x4 * c0; \r
+ acc4 += x5 * c0; \r
+ acc5 += x6 * c0; \r
+ acc6 += x7 * c0; \r
+ acc7 += x0 * c0; \r
+ \r
+ /* Read the b[numTaps-3] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-5] sample */\r
+ x1 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ acc0 += x2 * c0;\r
+ acc1 += x3 * c0; \r
+ acc2 += x4 * c0; \r
+ acc3 += x5 * c0; \r
+ acc4 += x6 * c0; \r
+ acc5 += x7 * c0; \r
+ acc6 += x0 * c0; \r
+ acc7 += x1 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x2 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ acc0 += x3 * c0;\r
+ acc1 += x4 * c0; \r
+ acc2 += x5 * c0; \r
+ acc3 += x6 * c0; \r
+ acc4 += x7 * c0; \r
+ acc5 += x0 * c0; \r
+ acc6 += x1 * c0; \r
+ acc7 += x2 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x3 = *(px++);\r
+ /* Perform the multiply-accumulates */ \r
+ acc0 += x4 * c0;\r
+ acc1 += x5 * c0; \r
+ acc2 += x6 * c0; \r
+ acc3 += x7 * c0; \r
+ acc4 += x0 * c0; \r
+ acc5 += x1 * c0; \r
+ acc6 += x2 * c0; \r
+ acc7 += x3 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x4 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ acc0 += x5 * c0;\r
+ acc1 += x6 * c0; \r
+ acc2 += x7 * c0; \r
+ acc3 += x0 * c0; \r
+ acc4 += x1 * c0; \r
+ acc5 += x2 * c0; \r
+ acc6 += x3 * c0; \r
+ acc7 += x4 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x5 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ acc0 += x6 * c0;\r
+ acc1 += x7 * c0; \r
+ acc2 += x0 * c0; \r
+ acc3 += x1 * c0; \r
+ acc4 += x2 * c0; \r
+ acc5 += x3 * c0; \r
+ acc6 += x4 * c0; \r
+ acc7 += x5 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x6 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ acc0 += x7 * c0;\r
+ acc1 += x0 * c0; \r
+ acc2 += x1 * c0; \r
+ acc3 += x2 * c0; \r
+ acc4 += x3 * c0; \r
+ acc5 += x4 * c0; \r
+ acc6 += x5 * c0; \r
+ acc7 += x6 * c0; \r
+\r
+ tapCnt--;\r
+ }\r
+\r
+ /* If the filter length is not a multiple of 8, compute the remaining filter taps */\r
+ tapCnt = numTaps % 0x8u;\r
+\r
+ while(tapCnt > 0u)\r
+ {\r
+ /* Read coefficients */\r
+ c0 = *(pb++);\r
+\r
+ /* Fetch 1 state variable */\r
+ x7 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ acc0 += x0 * c0;\r
+ acc1 += x1 * c0; \r
+ acc2 += x2 * c0; \r
+ acc3 += x3 * c0; \r
+ acc4 += x4 * c0; \r
+ acc5 += x5 * c0; \r
+ acc6 += x6 * c0; \r
+ acc7 += x7 * c0; \r
+\r
+ /* Reuse the present sample states for next sample */\r
+ x0 = x1;\r
+ x1 = x2;\r
+ x2 = x3;\r
+ x3 = x4;\r
+ x4 = x5;\r
+ x5 = x6;\r
+ x6 = x7;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+ /* Advance the state pointer by 8 to process the next group of 8 samples */\r
+ pState = pState + 8;\r
+\r
+ /* The results in the 8 accumulators, store in the destination buffer. */\r
+ *pDst++ = acc0;\r
+ *pDst++ = acc1;\r
+ *pDst++ = acc2;\r
+ *pDst++ = acc3;\r
+ *pDst++ = acc4;\r
+ *pDst++ = acc5;\r
+ *pDst++ = acc6;\r
+ *pDst++ = acc7;\r
+\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize is not a multiple of 8, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize % 0x8u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc0 = 0.0f;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize Coefficient pointer */\r
+ pb = (pCoeffs);\r
+\r
+ i = numTaps;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ do\r
+ {\r
+ acc0 += *px++ * *pb++;\r
+ i--;\r
+\r
+ } while(i > 0u);\r
+\r
+ /* The result is store in the destination buffer. */\r
+ *pDst++ = acc0;\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the start of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ tapCnt = (numTaps - 1u) >> 2u;\r
+\r
+ /* copy data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+ /* Calculate remaining number of copies */\r
+ tapCnt = (numTaps - 1u) % 0x4u;\r
+\r
+ /* Copy the remaining q31_t data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+}\r
+\r
+#elif defined(ARM_MATH_CM0_FAMILY)\r
+\r
+void arm_fir_f32(\r
+const arm_fir_instance_f32 * S,\r
+float32_t * pSrc,\r
+float32_t * pDst,\r
+uint32_t blockSize)\r
+{\r
+ float32_t *pState = S->pState; /* State pointer */\r
+ float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ float32_t *pStateCurnt; /* Points to the current sample of the state */\r
+ float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */\r
+ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */\r
+ uint32_t i, tapCnt, blkCnt; /* Loop counters */\r
+\r
+ /* Run the below code for Cortex-M0 */\r
+\r
+ float32_t acc;\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Initialize blkCnt with blockSize */\r
+ blkCnt = blockSize;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc = 0.0f;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize Coefficient pointer */\r
+ pb = pCoeffs;\r
+\r
+ i = numTaps;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ do\r
+ {\r
+ /* acc = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] */\r
+ acc += *px++ * *pb++;\r
+ i--;\r
+\r
+ } while(i > 0u);\r
+\r
+ /* The result is store in the destination buffer. */\r
+ *pDst++ = acc;\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the starting of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ /* Copy numTaps number of values */\r
+ tapCnt = numTaps - 1u;\r
+\r
+ /* Copy data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+}\r
+\r
+#else\r
+\r
+/* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+void arm_fir_f32(\r
+const arm_fir_instance_f32 * S,\r
+float32_t * pSrc,\r
+float32_t * pDst,\r
+uint32_t blockSize)\r
+{\r
+ float32_t *pState = S->pState; /* State pointer */\r
+ float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ float32_t *pStateCurnt; /* Points to the current sample of the state */\r
+ float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */\r
+ float32_t acc0, acc1, acc2, acc3, acc4, acc5, acc6, acc7; /* Accumulators */\r
+ float32_t x0, x1, x2, x3, x4, x5, x6, x7, c0; /* Temporary variables to hold state and coefficient values */\r
+ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */\r
+ uint32_t i, tapCnt, blkCnt; /* Loop counters */\r
+ float32_t p0,p1,p2,p3,p4,p5,p6,p7; /* Temporary product values */\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Apply loop unrolling and compute 8 output values simultaneously. \r
+ * The variables acc0 ... acc7 hold output values that are being computed: \r
+ * \r
+ * acc0 = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] \r
+ * acc1 = b[numTaps-1] * x[n-numTaps] + b[numTaps-2] * x[n-numTaps-1] + b[numTaps-3] * x[n-numTaps-2] +...+ b[0] * x[1] \r
+ * acc2 = b[numTaps-1] * x[n-numTaps+1] + b[numTaps-2] * x[n-numTaps] + b[numTaps-3] * x[n-numTaps-1] +...+ b[0] * x[2] \r
+ * acc3 = b[numTaps-1] * x[n-numTaps+2] + b[numTaps-2] * x[n-numTaps+1] + b[numTaps-3] * x[n-numTaps] +...+ b[0] * x[3] \r
+ */\r
+ blkCnt = blockSize >> 3;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 8 outputs at a time. \r
+ ** a second loop below computes the remaining 1 to 7 samples. */\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy four new input samples into the state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0.0f;\r
+ acc1 = 0.0f;\r
+ acc2 = 0.0f;\r
+ acc3 = 0.0f;\r
+ acc4 = 0.0f;\r
+ acc5 = 0.0f;\r
+ acc6 = 0.0f;\r
+ acc7 = 0.0f; \r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize coeff pointer */\r
+ pb = (pCoeffs); \r
+ \r
+ /* This is separated from the others to avoid \r
+ * a call to __aeabi_memmove which would be slower\r
+ */\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Read the first seven samples from the state buffer: x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2] */\r
+ x0 = *px++;\r
+ x1 = *px++;\r
+ x2 = *px++;\r
+ x3 = *px++;\r
+ x4 = *px++;\r
+ x5 = *px++;\r
+ x6 = *px++;\r
+\r
+ /* Loop unrolling. Process 8 taps at a time. */\r
+ tapCnt = numTaps >> 3u;\r
+ \r
+ /* Loop over the number of taps. Unroll by a factor of 8. \r
+ ** Repeat until we've computed numTaps-8 coefficients. */\r
+ while(tapCnt > 0u)\r
+ {\r
+ /* Read the b[numTaps-1] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-3] sample */\r
+ x7 = *(px++);\r
+\r
+ /* acc0 += b[numTaps-1] * x[n-numTaps] */\r
+ p0 = x0 * c0;\r
+\r
+ /* acc1 += b[numTaps-1] * x[n-numTaps-1] */\r
+ p1 = x1 * c0;\r
+\r
+ /* acc2 += b[numTaps-1] * x[n-numTaps-2] */\r
+ p2 = x2 * c0;\r
+\r
+ /* acc3 += b[numTaps-1] * x[n-numTaps-3] */\r
+ p3 = x3 * c0;\r
+\r
+ /* acc4 += b[numTaps-1] * x[n-numTaps-4] */\r
+ p4 = x4 * c0;\r
+\r
+ /* acc1 += b[numTaps-1] * x[n-numTaps-5] */\r
+ p5 = x5 * c0;\r
+\r
+ /* acc2 += b[numTaps-1] * x[n-numTaps-6] */\r
+ p6 = x6 * c0;\r
+\r
+ /* acc3 += b[numTaps-1] * x[n-numTaps-7] */\r
+ p7 = x7 * c0;\r
+ \r
+ /* Read the b[numTaps-2] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-4] sample */\r
+ x0 = *(px++);\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+\r
+ /* Perform the multiply-accumulate */\r
+ p0 = x1 * c0;\r
+ p1 = x2 * c0; \r
+ p2 = x3 * c0; \r
+ p3 = x4 * c0; \r
+ p4 = x5 * c0; \r
+ p5 = x6 * c0; \r
+ p6 = x7 * c0; \r
+ p7 = x0 * c0; \r
+ \r
+ /* Read the b[numTaps-3] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-5] sample */\r
+ x1 = *(px++);\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ p0 = x2 * c0;\r
+ p1 = x3 * c0; \r
+ p2 = x4 * c0; \r
+ p3 = x5 * c0; \r
+ p4 = x6 * c0; \r
+ p5 = x7 * c0; \r
+ p6 = x0 * c0; \r
+ p7 = x1 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x2 = *(px++);\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ p0 = x3 * c0;\r
+ p1 = x4 * c0; \r
+ p2 = x5 * c0; \r
+ p3 = x6 * c0; \r
+ p4 = x7 * c0; \r
+ p5 = x0 * c0; \r
+ p6 = x1 * c0; \r
+ p7 = x2 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x3 = *(px++);\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ p0 = x4 * c0;\r
+ p1 = x5 * c0; \r
+ p2 = x6 * c0; \r
+ p3 = x7 * c0; \r
+ p4 = x0 * c0; \r
+ p5 = x1 * c0; \r
+ p6 = x2 * c0; \r
+ p7 = x3 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x4 = *(px++);\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ p0 = x5 * c0;\r
+ p1 = x6 * c0; \r
+ p2 = x7 * c0; \r
+ p3 = x0 * c0; \r
+ p4 = x1 * c0; \r
+ p5 = x2 * c0; \r
+ p6 = x3 * c0; \r
+ p7 = x4 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x5 = *(px++);\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ p0 = x6 * c0;\r
+ p1 = x7 * c0; \r
+ p2 = x0 * c0; \r
+ p3 = x1 * c0; \r
+ p4 = x2 * c0; \r
+ p5 = x3 * c0; \r
+ p6 = x4 * c0; \r
+ p7 = x5 * c0; \r
+\r
+ /* Read the b[numTaps-4] coefficient */\r
+ c0 = *(pb++);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x6 = *(px++);\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ p0 = x7 * c0;\r
+ p1 = x0 * c0; \r
+ p2 = x1 * c0; \r
+ p3 = x2 * c0; \r
+ p4 = x3 * c0; \r
+ p5 = x4 * c0; \r
+ p6 = x5 * c0; \r
+ p7 = x6 * c0; \r
+\r
+ tapCnt--;\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+ }\r
+\r
+ /* If the filter length is not a multiple of 8, compute the remaining filter taps */\r
+ tapCnt = numTaps % 0x8u;\r
+\r
+ while(tapCnt > 0u)\r
+ {\r
+ /* Read coefficients */\r
+ c0 = *(pb++);\r
+\r
+ /* Fetch 1 state variable */\r
+ x7 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */ \r
+ p0 = x0 * c0;\r
+ p1 = x1 * c0; \r
+ p2 = x2 * c0; \r
+ p3 = x3 * c0; \r
+ p4 = x4 * c0; \r
+ p5 = x5 * c0; \r
+ p6 = x6 * c0; \r
+ p7 = x7 * c0; \r
+\r
+ /* Reuse the present sample states for next sample */\r
+ x0 = x1;\r
+ x1 = x2;\r
+ x2 = x3;\r
+ x3 = x4;\r
+ x4 = x5;\r
+ x5 = x6;\r
+ x6 = x7;\r
+ \r
+ acc0 += p0;\r
+ acc1 += p1;\r
+ acc2 += p2;\r
+ acc3 += p3;\r
+ acc4 += p4;\r
+ acc5 += p5;\r
+ acc6 += p6;\r
+ acc7 += p7;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+ /* Advance the state pointer by 8 to process the next group of 8 samples */\r
+ pState = pState + 8;\r
+\r
+ /* The results in the 8 accumulators, store in the destination buffer. */\r
+ *pDst++ = acc0;\r
+ *pDst++ = acc1;\r
+ *pDst++ = acc2;\r
+ *pDst++ = acc3;\r
+ *pDst++ = acc4;\r
+ *pDst++ = acc5;\r
+ *pDst++ = acc6;\r
+ *pDst++ = acc7;\r
+\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize is not a multiple of 8, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize % 0x8u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc0 = 0.0f;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize Coefficient pointer */\r
+ pb = (pCoeffs);\r
+\r
+ i = numTaps;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ do\r
+ {\r
+ acc0 += *px++ * *pb++;\r
+ i--;\r
+\r
+ } while(i > 0u);\r
+\r
+ /* The result is store in the destination buffer. */\r
+ *pDst++ = acc0;\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the start of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ tapCnt = (numTaps - 1u) >> 2u;\r
+\r
+ /* copy data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+ /* Calculate remaining number of copies */\r
+ tapCnt = (numTaps - 1u) % 0x4u;\r
+\r
+ /* Copy the remaining q31_t data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+}\r
+\r
+#endif \r
+\r
+/** \r
+* @} end of FIR group \r
+*/\r
--- /dev/null
+/*----------------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_init_f32.c \r
+* \r
+* Description: Floating-point FIR filter initialization function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* ---------------------------------------------------------------------------*/\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup FIR \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @details \r
+ * \r
+ * @param[in,out] *S points to an instance of the floating-point FIR filter structure. \r
+ * @param[in] numTaps Number of filter coefficients in the filter. \r
+ * @param[in] *pCoeffs points to the filter coefficients buffer. \r
+ * @param[in] *pState points to the state buffer. \r
+ * @param[in] blockSize number of samples that are processed per call. \r
+ * @return none. \r
+ * \r
+ * <b>Description:</b> \r
+ * \par \r
+ * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: \r
+ * <pre> \r
+ * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} \r
+ * </pre> \r
+ * \par \r
+ * <code>pState</code> points to the array of state variables. \r
+ * <code>pState</code> is of length <code>numTaps+blockSize-1</code> samples, where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_f32()</code>. \r
+ */\r
+\r
+void arm_fir_init_f32(\r
+ arm_fir_instance_f32 * S,\r
+ uint16_t numTaps,\r
+ float32_t * pCoeffs,\r
+ float32_t * pState,\r
+ uint32_t blockSize)\r
+{\r
+ /* Assign filter taps */\r
+ S->numTaps = numTaps;\r
+\r
+ /* Assign coefficient pointer */\r
+ S->pCoeffs = pCoeffs;\r
+\r
+ /* Clear state buffer and the size of state buffer is (blockSize + numTaps - 1) */\r
+ memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(float32_t));\r
+\r
+ /* Assign state pointer */\r
+ S->pState = pState;\r
+\r
+}\r
+\r
+/** \r
+ * @} end of FIR group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_init_q15.c \r
+* \r
+* Description: Q15 FIR filter initialization function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* ------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup FIR \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @param[in,out] *S points to an instance of the Q15 FIR filter structure. \r
+ * @param[in] numTaps Number of filter coefficients in the filter. Must be even and greater than or equal to 4. \r
+ * @param[in] *pCoeffs points to the filter coefficients buffer. \r
+ * @param[in] *pState points to the state buffer. \r
+ * @param[in] blockSize is number of samples processed per call. \r
+ * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if \r
+ * <code>numTaps</code> is not greater than or equal to 4 and even. \r
+ * \r
+ * <b>Description:</b> \r
+ * \par \r
+ * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: \r
+ * <pre> \r
+ * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} \r
+ * </pre> \r
+ * Note that <code>numTaps</code> must be even and greater than or equal to 4. \r
+ * To implement an odd length filter simply increase <code>numTaps</code> by 1 and set the last coefficient to zero. \r
+ * For example, to implement a filter with <code>numTaps=3</code> and coefficients \r
+ * <pre> \r
+ * {0.3, -0.8, 0.3} \r
+ * </pre> \r
+ * set <code>numTaps=4</code> and use the coefficients: \r
+ * <pre> \r
+ * {0.3, -0.8, 0.3, 0}. \r
+ * </pre> \r
+ * Similarly, to implement a two point filter \r
+ * <pre> \r
+ * {0.3, -0.3} \r
+ * </pre> \r
+ * set <code>numTaps=4</code> and use the coefficients: \r
+ * <pre> \r
+ * {0.3, -0.3, 0, 0}. \r
+ * </pre> \r
+ * \par \r
+ * <code>pState</code> points to the array of state variables. \r
+ * <code>pState</code> is of length <code>numTaps+blockSize</code>, when running on Cortex-M4 and Cortex-M3 and is of length <code>numTaps+blockSize-1</code>, when running on Cortex-M0 where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_q15()</code>. \r
+ */\r
+\r
+arm_status arm_fir_init_q15(\r
+ arm_fir_instance_q15 * S,\r
+ uint16_t numTaps,\r
+ q15_t * pCoeffs,\r
+ q15_t * pState,\r
+ uint32_t blockSize)\r
+{\r
+ arm_status status;\r
+\r
+\r
+#ifndef ARM_MATH_CM0_FAMILY\r
+\r
+ /* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+ /* The Number of filter coefficients in the filter must be even and at least 4 */\r
+ if(numTaps & 0x1u)\r
+ {\r
+ status = ARM_MATH_ARGUMENT_ERROR;\r
+ }\r
+ else\r
+ {\r
+ /* Assign filter taps */\r
+ S->numTaps = numTaps;\r
+\r
+ /* Assign coefficient pointer */\r
+ S->pCoeffs = pCoeffs;\r
+\r
+ /* Clear the state buffer. The size is always (blockSize + numTaps ) */\r
+ memset(pState, 0, (numTaps + (blockSize)) * sizeof(q15_t));\r
+\r
+ /* Assign state pointer */\r
+ S->pState = pState;\r
+\r
+ status = ARM_MATH_SUCCESS;\r
+ }\r
+\r
+ return (status);\r
+\r
+#else\r
+\r
+ /* Run the below code for Cortex-M0 */\r
+\r
+ /* Assign filter taps */\r
+ S->numTaps = numTaps;\r
+\r
+ /* Assign coefficient pointer */\r
+ S->pCoeffs = pCoeffs;\r
+\r
+ /* Clear the state buffer. The size is always (blockSize + numTaps - 1) */\r
+ memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(q15_t));\r
+\r
+ /* Assign state pointer */\r
+ S->pState = pState;\r
+\r
+ status = ARM_MATH_SUCCESS;\r
+\r
+ return (status);\r
+\r
+#endif /* #ifndef ARM_MATH_CM0_FAMILY */\r
+\r
+}\r
+\r
+/** \r
+ * @} end of FIR group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_init_q31.c \r
+* \r
+* Description: Q31 FIR filter initialization function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup FIR \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @details \r
+ * \r
+ * @param[in,out] *S points to an instance of the Q31 FIR filter structure. \r
+ * @param[in] numTaps Number of filter coefficients in the filter. \r
+ * @param[in] *pCoeffs points to the filter coefficients buffer. \r
+ * @param[in] *pState points to the state buffer. \r
+ * @param[in] blockSize number of samples that are processed per call. \r
+ * @return none. \r
+ * \r
+ * <b>Description:</b> \r
+ * \par \r
+ * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: \r
+ * <pre> \r
+ * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} \r
+ * </pre> \r
+ * \par \r
+ * <code>pState</code> points to the array of state variables. \r
+ * <code>pState</code> is of length <code>numTaps+blockSize-1</code> samples, where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_q31()</code>. \r
+ */\r
+\r
+void arm_fir_init_q31(\r
+ arm_fir_instance_q31 * S,\r
+ uint16_t numTaps,\r
+ q31_t * pCoeffs,\r
+ q31_t * pState,\r
+ uint32_t blockSize)\r
+{\r
+ /* Assign filter taps */\r
+ S->numTaps = numTaps;\r
+\r
+ /* Assign coefficient pointer */\r
+ S->pCoeffs = pCoeffs;\r
+\r
+ /* Clear state buffer and state array size is (blockSize + numTaps - 1) */\r
+ memset(pState, 0, (blockSize + ((uint32_t) numTaps - 1u)) * sizeof(q31_t));\r
+\r
+ /* Assign state pointer */\r
+ S->pState = pState;\r
+\r
+}\r
+\r
+/** \r
+ * @} end of FIR group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_init_q7.c \r
+* \r
+* Description: Q7 FIR filter initialization function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* ------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup FIR \r
+ * @{ \r
+ */\r
+/** \r
+ * @param[in,out] *S points to an instance of the Q7 FIR filter structure. \r
+ * @param[in] numTaps Number of filter coefficients in the filter. \r
+ * @param[in] *pCoeffs points to the filter coefficients buffer. \r
+ * @param[in] *pState points to the state buffer. \r
+ * @param[in] blockSize number of samples that are processed per call. \r
+ * @return none \r
+ * \r
+ * <b>Description:</b> \r
+ * \par \r
+ * <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: \r
+ * <pre> \r
+ * {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} \r
+ * </pre> \r
+ * \par \r
+ * <code>pState</code> points to the array of state variables. \r
+ * <code>pState</code> is of length <code>numTaps+blockSize-1</code> samples, where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_fir_q7()</code>. \r
+ */\r
+\r
+void arm_fir_init_q7(\r
+ arm_fir_instance_q7 * S,\r
+ uint16_t numTaps,\r
+ q7_t * pCoeffs,\r
+ q7_t * pState,\r
+ uint32_t blockSize)\r
+{\r
+\r
+ /* Assign filter taps */\r
+ S->numTaps = numTaps;\r
+\r
+ /* Assign coefficient pointer */\r
+ S->pCoeffs = pCoeffs;\r
+\r
+ /* Clear the state buffer. The size is always (blockSize + numTaps - 1) */\r
+ memset(pState, 0, (numTaps + (blockSize - 1u)) * sizeof(q7_t));\r
+\r
+ /* Assign state pointer */\r
+ S->pState = pState;\r
+\r
+}\r
+\r
+/** \r
+ * @} end of FIR group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_q15.c \r
+* \r
+* Description: Q15 FIR filter processing function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup FIR \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @brief Processing function for the Q15 FIR filter. \r
+ * @param[in] *S points to an instance of the Q15 FIR structure. \r
+ * @param[in] *pSrc points to the block of input data. \r
+ * @param[out] *pDst points to the block of output data. \r
+ * @param[in] blockSize number of samples to process per call. \r
+ * @return none. \r
+ * \r
+ * \r
+ * \par Restrictions \r
+ * If the silicon does not support unaligned memory access enable the macro UNALIGNED_SUPPORT_DISABLE \r
+ * In this case input, output, state buffers should be aligned by 32-bit \r
+ * \r
+ * <b>Scaling and Overflow Behavior:</b> \r
+ * \par \r
+ * The function is implemented using a 64-bit internal accumulator. \r
+ * Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. \r
+ * The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. \r
+ * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. \r
+ * After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. \r
+ * Lastly, the accumulator is saturated to yield a result in 1.15 format. \r
+ * \r
+ * \par \r
+ * Refer to the function <code>arm_fir_fast_q15()</code> for a faster but less precise implementation of this function. \r
+ */\r
+\r
+#ifndef ARM_MATH_CM0_FAMILY\r
+\r
+/* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+#ifndef UNALIGNED_SUPPORT_DISABLE\r
+\r
+\r
+void arm_fir_q15(\r
+ const arm_fir_instance_q15 * S,\r
+ q15_t * pSrc,\r
+ q15_t * pDst,\r
+ uint32_t blockSize)\r
+{\r
+ q15_t *pState = S->pState; /* State pointer */\r
+ q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ q15_t *pStateCurnt; /* Points to the current sample of the state */\r
+ q15_t *px1; /* Temporary q15 pointer for state buffer */\r
+ q15_t *pb; /* Temporary pointer for coefficient buffer */\r
+ q31_t x0, x1, x2, x3, c0; /* Temporary variables to hold SIMD state and coefficient values */\r
+ q63_t acc0, acc1, acc2, acc3; /* Accumulators */\r
+ uint32_t numTaps = S->numTaps; /* Number of taps in the filter */\r
+ uint32_t tapCnt, blkCnt; /* Loop counters */\r
+\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Apply loop unrolling and compute 4 output values simultaneously. \r
+ * The variables acc0 ... acc3 hold output values that are being computed: \r
+ * \r
+ * acc0 = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] \r
+ * acc1 = b[numTaps-1] * x[n-numTaps] + b[numTaps-2] * x[n-numTaps-1] + b[numTaps-3] * x[n-numTaps-2] +...+ b[0] * x[1] \r
+ * acc2 = b[numTaps-1] * x[n-numTaps+1] + b[numTaps-2] * x[n-numTaps] + b[numTaps-3] * x[n-numTaps-1] +...+ b[0] * x[2] \r
+ * acc3 = b[numTaps-1] * x[n-numTaps+2] + b[numTaps-2] * x[n-numTaps+1] + b[numTaps-3] * x[n-numTaps] +...+ b[0] * x[3] \r
+ */\r
+\r
+ blkCnt = blockSize >> 2;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 outputs at a time. \r
+ ** a second loop below computes the remaining 1 to 3 samples. */\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy four new input samples into the state buffer. \r
+ ** Use 32-bit SIMD to move the 16-bit data. Only requires two copies. */\r
+ *__SIMD32(pStateCurnt)++ = *__SIMD32(pSrc)++;\r
+ *__SIMD32(pStateCurnt)++ = *__SIMD32(pSrc)++;\r
+\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0;\r
+ acc1 = 0;\r
+ acc2 = 0;\r
+ acc3 = 0;\r
+\r
+ /* Initialize state pointer of type q15 */\r
+ px1 = pState;\r
+\r
+ /* Initialize coeff pointer of type q31 */\r
+ pb = pCoeffs;\r
+\r
+ /* Read the first two samples from the state buffer: x[n-N], x[n-N-1] */\r
+ x0 = _SIMD32_OFFSET(px1);\r
+\r
+ /* Read the third and forth samples from the state buffer: x[n-N-1], x[n-N-2] */\r
+ x1 = _SIMD32_OFFSET(px1 + 1u);\r
+\r
+ px1 += 2u;\r
+\r
+ /* Loop over the number of taps. Unroll by a factor of 4. \r
+ ** Repeat until we've computed numTaps-4 coefficients. */\r
+ tapCnt = numTaps >> 2;\r
+\r
+ while(tapCnt > 0u)\r
+ {\r
+ /* Read the first two coefficients using SIMD: b[N] and b[N-1] coefficients */\r
+ c0 = *__SIMD32(pb)++;\r
+\r
+ /* acc0 += b[N] * x[n-N] + b[N-1] * x[n-N-1] */\r
+ acc0 = __SMLALD(x0, c0, acc0);\r
+\r
+ /* acc1 += b[N] * x[n-N-1] + b[N-1] * x[n-N-2] */\r
+ acc1 = __SMLALD(x1, c0, acc1);\r
+\r
+ /* Read state x[n-N-2], x[n-N-3] */\r
+ x2 = _SIMD32_OFFSET(px1);\r
+\r
+ /* Read state x[n-N-3], x[n-N-4] */\r
+ x3 = _SIMD32_OFFSET(px1 + 1u);\r
+\r
+ /* acc2 += b[N] * x[n-N-2] + b[N-1] * x[n-N-3] */\r
+ acc2 = __SMLALD(x2, c0, acc2);\r
+\r
+ /* acc3 += b[N] * x[n-N-3] + b[N-1] * x[n-N-4] */\r
+ acc3 = __SMLALD(x3, c0, acc3);\r
+\r
+ /* Read coefficients b[N-2], b[N-3] */\r
+ c0 = *__SIMD32(pb)++;\r
+\r
+ /* acc0 += b[N-2] * x[n-N-2] + b[N-3] * x[n-N-3] */\r
+ acc0 = __SMLALD(x2, c0, acc0);\r
+\r
+ /* acc1 += b[N-2] * x[n-N-3] + b[N-3] * x[n-N-4] */\r
+ acc1 = __SMLALD(x3, c0, acc1);\r
+\r
+ /* Read state x[n-N-4], x[n-N-5] */\r
+ x0 = _SIMD32_OFFSET(px1 + 2u);\r
+\r
+ /* Read state x[n-N-5], x[n-N-6] */\r
+ x1 = _SIMD32_OFFSET(px1 + 3u);\r
+\r
+ /* acc2 += b[N-2] * x[n-N-4] + b[N-3] * x[n-N-5] */\r
+ acc2 = __SMLALD(x0, c0, acc2);\r
+\r
+ /* acc3 += b[N-2] * x[n-N-5] + b[N-3] * x[n-N-6] */\r
+ acc3 = __SMLALD(x1, c0, acc3);\r
+\r
+ px1 += 4u;\r
+\r
+ tapCnt--;\r
+\r
+ }\r
+\r
+\r
+ /* If the filter length is not a multiple of 4, compute the remaining filter taps. \r
+ ** This is always be 2 taps since the filter length is even. */\r
+ if((numTaps & 0x3u) != 0u)\r
+ {\r
+ /* Read 2 coefficients */\r
+ c0 = *__SIMD32(pb)++;\r
+\r
+ /* Fetch 4 state variables */\r
+ x2 = _SIMD32_OFFSET(px1);\r
+\r
+ x3 = _SIMD32_OFFSET(px1 + 1u);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 = __SMLALD(x0, c0, acc0);\r
+\r
+ px1 += 2u;\r
+\r
+ acc1 = __SMLALD(x1, c0, acc1);\r
+ acc2 = __SMLALD(x2, c0, acc2);\r
+ acc3 = __SMLALD(x3, c0, acc3);\r
+ }\r
+\r
+ /* The results in the 4 accumulators are in 2.30 format. Convert to 1.15 with saturation. \r
+ ** Then store the 4 outputs in the destination buffer. */\r
+\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc0 >> 15), 16), __SSAT((acc1 >> 15), 16), 16);\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc2 >> 15), 16), __SSAT((acc3 >> 15), 16), 16);\r
+\r
+#else\r
+\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc1 >> 15), 16), __SSAT((acc0 >> 15), 16), 16);\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc3 >> 15), 16), __SSAT((acc2 >> 15), 16), 16);\r
+\r
+#endif /* #ifndef ARM_MATH_BIG_ENDIAN */\r
+\r
+\r
+\r
+ /* Advance the state pointer by 4 to process the next group of 4 samples */\r
+ pState = pState + 4;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize is not a multiple of 4, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize % 0x4u;\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy two samples into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc0 = 0;\r
+\r
+ /* Initialize state pointer of type q15 */\r
+ px1 = pState;\r
+\r
+ /* Initialize coeff pointer of type q31 */\r
+ pb = pCoeffs;\r
+\r
+ tapCnt = numTaps >> 1;\r
+\r
+ do\r
+ {\r
+\r
+ c0 = *__SIMD32(pb)++;\r
+ x0 = *__SIMD32(px1)++;\r
+\r
+ acc0 = __SMLALD(x0, c0, acc0);\r
+ tapCnt--;\r
+ }\r
+ while(tapCnt > 0u);\r
+\r
+ /* The result is in 2.30 format. Convert to 1.15 with saturation. \r
+ ** Then store the output in the destination buffer. */\r
+ *pDst++ = (q15_t) (__SSAT((acc0 >> 15), 16));\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the satrt of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ /* Calculation of count for copying integer writes */\r
+ tapCnt = (numTaps - 1u) >> 2;\r
+\r
+ while(tapCnt > 0u)\r
+ {\r
+\r
+ /* Copy state values to start of state buffer */\r
+ *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;\r
+ *__SIMD32(pStateCurnt)++ = *__SIMD32(pState)++;\r
+\r
+ tapCnt--;\r
+\r
+ }\r
+\r
+ /* Calculation of count for remaining q15_t data */\r
+ tapCnt = (numTaps - 1u) % 0x4u;\r
+\r
+ /* copy remaining data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+}\r
+\r
+#else /* UNALIGNED_SUPPORT_DISABLE */\r
+\r
+void arm_fir_q15(\r
+ const arm_fir_instance_q15 * S,\r
+ q15_t * pSrc,\r
+ q15_t * pDst,\r
+ uint32_t blockSize)\r
+{\r
+ q15_t *pState = S->pState; /* State pointer */\r
+ q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ q15_t *pStateCurnt; /* Points to the current sample of the state */\r
+ q63_t acc0, acc1, acc2, acc3; /* Accumulators */\r
+ q15_t *pb; /* Temporary pointer for coefficient buffer */\r
+ q15_t *px; /* Temporary q31 pointer for SIMD state buffer accesses */\r
+ q31_t x0, x1, x2, c0; /* Temporary variables to hold SIMD state and coefficient values */\r
+ uint32_t numTaps = S->numTaps; /* Number of taps in the filter */\r
+ uint32_t tapCnt, blkCnt; /* Loop counters */\r
+\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Apply loop unrolling and compute 4 output values simultaneously. \r
+ * The variables acc0 ... acc3 hold output values that are being computed: \r
+ * \r
+ * acc0 = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] \r
+ * acc1 = b[numTaps-1] * x[n-numTaps] + b[numTaps-2] * x[n-numTaps-1] + b[numTaps-3] * x[n-numTaps-2] +...+ b[0] * x[1] \r
+ * acc2 = b[numTaps-1] * x[n-numTaps+1] + b[numTaps-2] * x[n-numTaps] + b[numTaps-3] * x[n-numTaps-1] +...+ b[0] * x[2] \r
+ * acc3 = b[numTaps-1] * x[n-numTaps+2] + b[numTaps-2] * x[n-numTaps+1] + b[numTaps-3] * x[n-numTaps] +...+ b[0] * x[3] \r
+ */\r
+\r
+ blkCnt = blockSize >> 2;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 outputs at a time. \r
+ ** a second loop below computes the remaining 1 to 3 samples. */\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy four new input samples into the state buffer. \r
+ ** Use 32-bit SIMD to move the 16-bit data. Only requires two copies. */\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0;\r
+ acc1 = 0;\r
+ acc2 = 0;\r
+ acc3 = 0;\r
+\r
+ /* Typecast q15_t pointer to q31_t pointer for state reading in q31_t */\r
+ px = pState;\r
+\r
+ /* Typecast q15_t pointer to q31_t pointer for coefficient reading in q31_t */\r
+ pb = pCoeffs;\r
+\r
+ /* Read the first two samples from the state buffer: x[n-N], x[n-N-1] */\r
+ x0 = *__SIMD32(px)++;\r
+\r
+ /* Read the third and forth samples from the state buffer: x[n-N-2], x[n-N-3] */\r
+ x2 = *__SIMD32(px)++;\r
+\r
+ /* Loop over the number of taps. Unroll by a factor of 4. \r
+ ** Repeat until we've computed numTaps-(numTaps%4) coefficients. */\r
+ tapCnt = numTaps >> 2;\r
+\r
+ while(tapCnt > 0)\r
+ {\r
+ /* Read the first two coefficients using SIMD: b[N] and b[N-1] coefficients */\r
+ c0 = *__SIMD32(pb)++;\r
+\r
+ /* acc0 += b[N] * x[n-N] + b[N-1] * x[n-N-1] */\r
+ acc0 = __SMLALD(x0, c0, acc0);\r
+\r
+ /* acc2 += b[N] * x[n-N-2] + b[N-1] * x[n-N-3] */\r
+ acc2 = __SMLALD(x2, c0, acc2);\r
+\r
+ /* pack x[n-N-1] and x[n-N-2] */\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+ x1 = __PKHBT(x2, x0, 0);\r
+#else\r
+ x1 = __PKHBT(x0, x2, 0);\r
+#endif\r
+\r
+ /* Read state x[n-N-4], x[n-N-5] */\r
+ x0 = _SIMD32_OFFSET(px);\r
+\r
+ /* acc1 += b[N] * x[n-N-1] + b[N-1] * x[n-N-2] */\r
+ acc1 = __SMLALDX(x1, c0, acc1);\r
+\r
+ /* pack x[n-N-3] and x[n-N-4] */\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+ x1 = __PKHBT(x0, x2, 0);\r
+#else\r
+ x1 = __PKHBT(x2, x0, 0);\r
+#endif\r
+\r
+ /* acc3 += b[N] * x[n-N-3] + b[N-1] * x[n-N-4] */\r
+ acc3 = __SMLALDX(x1, c0, acc3);\r
+\r
+ /* Read coefficients b[N-2], b[N-3] */\r
+ c0 = *__SIMD32(pb)++;\r
+\r
+ /* acc0 += b[N-2] * x[n-N-2] + b[N-3] * x[n-N-3] */\r
+ acc0 = __SMLALD(x2, c0, acc0);\r
+\r
+ /* Read state x[n-N-6], x[n-N-7] with offset */\r
+ x2 = _SIMD32_OFFSET(px + 2u);\r
+\r
+ /* acc2 += b[N-2] * x[n-N-4] + b[N-3] * x[n-N-5] */\r
+ acc2 = __SMLALD(x0, c0, acc2);\r
+\r
+ /* acc1 += b[N-2] * x[n-N-3] + b[N-3] * x[n-N-4] */\r
+ acc1 = __SMLALDX(x1, c0, acc1);\r
+\r
+ /* pack x[n-N-5] and x[n-N-6] */\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+ x1 = __PKHBT(x2, x0, 0);\r
+#else\r
+ x1 = __PKHBT(x0, x2, 0);\r
+#endif\r
+\r
+ /* acc3 += b[N-2] * x[n-N-5] + b[N-3] * x[n-N-6] */\r
+ acc3 = __SMLALDX(x1, c0, acc3);\r
+\r
+ /* Update state pointer for next state reading */\r
+ px += 4u;\r
+\r
+ /* Decrement tap count */\r
+ tapCnt--;\r
+\r
+ }\r
+\r
+ /* If the filter length is not a multiple of 4, compute the remaining filter taps. \r
+ ** This is always be 2 taps since the filter length is even. */\r
+ if((numTaps & 0x3u) != 0u)\r
+ {\r
+\r
+ /* Read last two coefficients */\r
+ c0 = *__SIMD32(pb)++;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 = __SMLALD(x0, c0, acc0);\r
+ acc2 = __SMLALD(x2, c0, acc2);\r
+\r
+ /* pack state variables */\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+ x1 = __PKHBT(x2, x0, 0);\r
+#else\r
+ x1 = __PKHBT(x0, x2, 0);\r
+#endif\r
+\r
+ /* Read last state variables */\r
+ x0 = *__SIMD32(px);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc1 = __SMLALDX(x1, c0, acc1);\r
+\r
+ /* pack state variables */\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+ x1 = __PKHBT(x0, x2, 0);\r
+#else\r
+ x1 = __PKHBT(x2, x0, 0);\r
+#endif\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc3 = __SMLALDX(x1, c0, acc3);\r
+ }\r
+\r
+ /* The results in the 4 accumulators are in 2.30 format. Convert to 1.15 with saturation. \r
+ ** Then store the 4 outputs in the destination buffer. */\r
+\r
+#ifndef ARM_MATH_BIG_ENDIAN\r
+\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc0 >> 15), 16), __SSAT((acc1 >> 15), 16), 16);\r
+\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc2 >> 15), 16), __SSAT((acc3 >> 15), 16), 16);\r
+\r
+#else\r
+\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc1 >> 15), 16), __SSAT((acc0 >> 15), 16), 16);\r
+\r
+ *__SIMD32(pDst)++ =\r
+ __PKHBT(__SSAT((acc3 >> 15), 16), __SSAT((acc2 >> 15), 16), 16);\r
+\r
+#endif /* #ifndef ARM_MATH_BIG_ENDIAN */\r
+\r
+ /* Advance the state pointer by 4 to process the next group of 4 samples */\r
+ pState = pState + 4;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize is not a multiple of 4, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize % 0x4u;\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy two samples into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc0 = 0;\r
+\r
+ /* Use SIMD to hold states and coefficients */\r
+ px = pState;\r
+ pb = pCoeffs;\r
+\r
+ tapCnt = numTaps >> 1u;\r
+\r
+ do\r
+ {\r
+ acc0 += (q31_t) * px++ * *pb++;\r
+ acc0 += (q31_t) * px++ * *pb++;\r
+ tapCnt--;\r
+ }\r
+ while(tapCnt > 0u);\r
+\r
+ /* The result is in 2.30 format. Convert to 1.15 with saturation. \r
+ ** Then store the output in the destination buffer. */\r
+ *pDst++ = (q15_t) (__SSAT((acc0 >> 15), 16));\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1u;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the satrt of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ /* Calculation of count for copying integer writes */\r
+ tapCnt = (numTaps - 1u) >> 2;\r
+\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ tapCnt--;\r
+\r
+ }\r
+\r
+ /* Calculation of count for remaining q15_t data */\r
+ tapCnt = (numTaps - 1u) % 0x4u;\r
+\r
+ /* copy remaining data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+}\r
+\r
+\r
+#endif /* #ifndef UNALIGNED_SUPPORT_DISABLE */\r
+\r
+#else /* ARM_MATH_CM0_FAMILY */\r
+\r
+\r
+/* Run the below code for Cortex-M0 */\r
+\r
+void arm_fir_q15(\r
+ const arm_fir_instance_q15 * S,\r
+ q15_t * pSrc,\r
+ q15_t * pDst,\r
+ uint32_t blockSize)\r
+{\r
+ q15_t *pState = S->pState; /* State pointer */\r
+ q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ q15_t *pStateCurnt; /* Points to the current sample of the state */\r
+\r
+\r
+\r
+ q15_t *px; /* Temporary pointer for state buffer */\r
+ q15_t *pb; /* Temporary pointer for coefficient buffer */\r
+ q63_t acc; /* Accumulator */\r
+ uint32_t numTaps = S->numTaps; /* Number of nTaps in the filter */\r
+ uint32_t tapCnt, blkCnt; /* Loop counters */\r
+\r
+ /* S->pState buffer contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Initialize blkCnt with blockSize */\r
+ blkCnt = blockSize;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc = 0;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize Coefficient pointer */\r
+ pb = pCoeffs;\r
+\r
+ tapCnt = numTaps;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ do\r
+ {\r
+ /* acc = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] */\r
+ acc += (q31_t) * px++ * *pb++;\r
+ tapCnt--;\r
+ } while(tapCnt > 0u);\r
+\r
+ /* The result is in 2.30 format. Convert to 1.15 \r
+ ** Then store the output in the destination buffer. */\r
+ *pDst++ = (q15_t) __SSAT((acc >> 15u), 16);\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ /* Decrement the samples loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the satrt of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ /* Copy numTaps number of values */\r
+ tapCnt = (numTaps - 1u);\r
+\r
+ /* copy data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+}\r
+\r
+#endif /* #ifndef ARM_MATH_CM0_FAMILY */\r
+\r
+\r
+\r
+\r
+/** \r
+ * @} end of FIR group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_q31.c \r
+* \r
+* Description: Q31 FIR filter processing function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup FIR \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @param[in] *S points to an instance of the Q31 FIR filter structure. \r
+ * @param[in] *pSrc points to the block of input data. \r
+ * @param[out] *pDst points to the block of output data. \r
+ * @param[in] blockSize number of samples to process per call. \r
+ * @return none. \r
+ * \r
+ * @details \r
+ * <b>Scaling and Overflow Behavior:</b> \r
+ * \par \r
+ * The function is implemented using an internal 64-bit accumulator. \r
+ * The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. \r
+ * Thus, if the accumulator result overflows it wraps around rather than clip. \r
+ * In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits. \r
+ * After all multiply-accumulates are performed, the 2.62 accumulator is right shifted by 31 bits and saturated to 1.31 format to yield the final result. \r
+ * \r
+ * \par \r
+ * Refer to the function <code>arm_fir_fast_q31()</code> for a faster but less precise implementation of this filter for Cortex-M3 and Cortex-M4. \r
+ */\r
+\r
+void arm_fir_q31(\r
+ const arm_fir_instance_q31 * S,\r
+ q31_t * pSrc,\r
+ q31_t * pDst,\r
+ uint32_t blockSize)\r
+{\r
+ q31_t *pState = S->pState; /* State pointer */\r
+ q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ q31_t *pStateCurnt; /* Points to the current sample of the state */\r
+\r
+\r
+#ifndef ARM_MATH_CM0_FAMILY\r
+\r
+ /* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+ q31_t x0, x1, x2; /* Temporary variables to hold state */\r
+ q31_t c0; /* Temporary variable to hold coefficient value */\r
+ q31_t *px; /* Temporary pointer for state */\r
+ q31_t *pb; /* Temporary pointer for coefficient buffer */\r
+ q63_t acc0, acc1, acc2; /* Accumulators */\r
+ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */\r
+ uint32_t i, tapCnt, blkCnt, tapCntN3; /* Loop counters */\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Apply loop unrolling and compute 4 output values simultaneously. \r
+ * The variables acc0 ... acc3 hold output values that are being computed: \r
+ * \r
+ * acc0 = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] \r
+ * acc1 = b[numTaps-1] * x[n-numTaps] + b[numTaps-2] * x[n-numTaps-1] + b[numTaps-3] * x[n-numTaps-2] +...+ b[0] * x[1] \r
+ * acc2 = b[numTaps-1] * x[n-numTaps+1] + b[numTaps-2] * x[n-numTaps] + b[numTaps-3] * x[n-numTaps-1] +...+ b[0] * x[2] \r
+ * acc3 = b[numTaps-1] * x[n-numTaps+2] + b[numTaps-2] * x[n-numTaps+1] + b[numTaps-3] * x[n-numTaps] +...+ b[0] * x[3] \r
+ */\r
+ blkCnt = blockSize / 3;\r
+ blockSize = blockSize - (3 * blkCnt);\r
+\r
+ tapCnt = numTaps / 3;\r
+ tapCntN3 = numTaps - (3 * tapCnt);\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 outputs at a time. \r
+ ** a second loop below computes the remaining 1 to 3 samples. */\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy three new input samples into the state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0;\r
+ acc1 = 0;\r
+ acc2 = 0;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize coefficient pointer */\r
+ pb = pCoeffs;\r
+\r
+ /* Read the first two samples from the state buffer: \r
+ * x[n-numTaps], x[n-numTaps-1] */\r
+ x0 = *(px++);\r
+ x1 = *(px++);\r
+\r
+ /* Loop unrolling. Process 3 taps at a time. */\r
+ i = tapCnt;\r
+\r
+ while(i > 0u)\r
+ {\r
+ /* Read the b[numTaps] coefficient */\r
+ c0 = *pb;\r
+\r
+ /* Read x[n-numTaps-2] sample */\r
+ x2 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q63_t) x0 * c0);\r
+ acc1 += ((q63_t) x1 * c0);\r
+ acc2 += ((q63_t) x2 * c0);\r
+\r
+ /* Read the coefficient and state */\r
+ c0 = *(pb + 1u);\r
+ x0 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q63_t) x1 * c0);\r
+ acc1 += ((q63_t) x2 * c0);\r
+ acc2 += ((q63_t) x0 * c0);\r
+\r
+ /* Read the coefficient and state */\r
+ c0 = *(pb + 2u);\r
+ x1 = *(px++);\r
+\r
+ /* update coefficient pointer */\r
+ pb += 3u;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q63_t) x2 * c0);\r
+ acc1 += ((q63_t) x0 * c0);\r
+ acc2 += ((q63_t) x1 * c0);\r
+\r
+ /* Decrement the loop counter */\r
+ i--;\r
+ }\r
+\r
+ /* If the filter length is not a multiple of 3, compute the remaining filter taps */\r
+\r
+ i = tapCntN3;\r
+\r
+ while(i > 0u)\r
+ {\r
+ /* Read coefficients */\r
+ c0 = *(pb++);\r
+\r
+ /* Fetch 1 state variable */\r
+ x2 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q63_t) x0 * c0);\r
+ acc1 += ((q63_t) x1 * c0);\r
+ acc2 += ((q63_t) x2 * c0);\r
+\r
+ /* Reuse the present sample states for next sample */\r
+ x0 = x1;\r
+ x1 = x2;\r
+\r
+ /* Decrement the loop counter */\r
+ i--;\r
+ }\r
+\r
+ /* Advance the state pointer by 3 to process the next group of 3 samples */\r
+ pState = pState + 3;\r
+\r
+ /* The results in the 3 accumulators are in 2.30 format. Convert to 1.31 \r
+ ** Then store the 3 outputs in the destination buffer. */\r
+ *pDst++ = (q31_t) (acc0 >> 31u);\r
+ *pDst++ = (q31_t) (acc1 >> 31u);\r
+ *pDst++ = (q31_t) (acc2 >> 31u);\r
+\r
+ /* Decrement the samples loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* If the blockSize is not a multiple of 3, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+\r
+ while(blockSize > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc0 = 0;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize Coefficient pointer */\r
+ pb = (pCoeffs);\r
+\r
+ i = numTaps;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ do\r
+ {\r
+ acc0 += (q63_t) * (px++) * (*(pb++));\r
+ i--;\r
+ } while(i > 0u);\r
+\r
+ /* The result is in 2.62 format. Convert to 1.31 \r
+ ** Then store the output in the destination buffer. */\r
+ *pDst++ = (q31_t) (acc0 >> 31u);\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ /* Decrement the samples loop counter */\r
+ blockSize--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the satrt of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ tapCnt = (numTaps - 1u) >> 2u;\r
+\r
+ /* copy data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+ /* Calculate remaining number of copies */\r
+ tapCnt = (numTaps - 1u) % 0x4u;\r
+\r
+ /* Copy the remaining q31_t data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+#else\r
+\r
+/* Run the below code for Cortex-M0 */\r
+\r
+ q31_t *px; /* Temporary pointer for state */\r
+ q31_t *pb; /* Temporary pointer for coefficient buffer */\r
+ q63_t acc; /* Accumulator */\r
+ uint32_t numTaps = S->numTaps; /* Length of the filter */\r
+ uint32_t i, tapCnt, blkCnt; /* Loop counters */\r
+\r
+ /* S->pState buffer contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Initialize blkCnt with blockSize */\r
+ blkCnt = blockSize;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc = 0;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize Coefficient pointer */\r
+ pb = pCoeffs;\r
+\r
+ i = numTaps;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ do\r
+ {\r
+ /* acc = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] */\r
+ acc += (q63_t) * px++ * *pb++;\r
+ i--;\r
+ } while(i > 0u);\r
+\r
+ /* The result is in 2.62 format. Convert to 1.31 \r
+ ** Then store the output in the destination buffer. */\r
+ *pDst++ = (q31_t) (acc >> 31u);\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ /* Decrement the samples loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the starting of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ /* Copy numTaps number of values */\r
+ tapCnt = numTaps - 1u;\r
+\r
+ /* Copy the data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+\r
+#endif /* #ifndef ARM_MATH_CM0_FAMILY */\r
+\r
+}\r
+\r
+/** \r
+ * @} end of FIR group \r
+ */\r
--- /dev/null
+/* ---------------------------------------------------------------------- \r
+* Copyright (C) 2010-2014 ARM Limited. All rights reserved. \r
+* \r
+* $Date: 19. March 2015\r
+* $Revision: V.1.4.5\r
+* \r
+* Project: CMSIS DSP Library \r
+* Title: arm_fir_q7.c \r
+* \r
+* Description: Q7 FIR filter processing function. \r
+* \r
+* Target Processor: Cortex-M4/Cortex-M3/Cortex-M0\r
+* \r
+* Redistribution and use in source and binary forms, with or without \r
+* modification, are permitted provided that the following conditions\r
+* are met:\r
+* - Redistributions of source code must retain the above copyright\r
+* notice, this list of conditions and the following disclaimer.\r
+* - Redistributions in binary form must reproduce the above copyright\r
+* notice, this list of conditions and the following disclaimer in\r
+* the documentation and/or other materials provided with the \r
+* distribution.\r
+* - Neither the name of ARM LIMITED nor the names of its contributors\r
+* may be used to endorse or promote products derived from this\r
+* software without specific prior written permission.\r
+*\r
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
+* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE \r
+* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
+* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN\r
+* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
+* POSSIBILITY OF SUCH DAMAGE. \r
+* -------------------------------------------------------------------- */\r
+\r
+#include "arm_math.h"\r
+\r
+/** \r
+ * @ingroup groupFilters \r
+ */\r
+\r
+/** \r
+ * @addtogroup FIR \r
+ * @{ \r
+ */\r
+\r
+/** \r
+ * @param[in] *S points to an instance of the Q7 FIR filter structure. \r
+ * @param[in] *pSrc points to the block of input data. \r
+ * @param[out] *pDst points to the block of output data. \r
+ * @param[in] blockSize number of samples to process per call. \r
+ * @return none. \r
+ * \r
+ * <b>Scaling and Overflow Behavior:</b> \r
+ * \par \r
+ * The function is implemented using a 32-bit internal accumulator. \r
+ * Both coefficients and state variables are represented in 1.7 format and multiplications yield a 2.14 result. \r
+ * The 2.14 intermediate results are accumulated in a 32-bit accumulator in 18.14 format. \r
+ * There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. \r
+ * The accumulator is converted to 18.7 format by discarding the low 7 bits. \r
+ * Finally, the result is truncated to 1.7 format. \r
+ */\r
+\r
+void arm_fir_q7(\r
+ const arm_fir_instance_q7 * S,\r
+ q7_t * pSrc,\r
+ q7_t * pDst,\r
+ uint32_t blockSize)\r
+{\r
+\r
+#ifndef ARM_MATH_CM0_FAMILY\r
+\r
+ /* Run the below code for Cortex-M4 and Cortex-M3 */\r
+\r
+ q7_t *pState = S->pState; /* State pointer */\r
+ q7_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ q7_t *pStateCurnt; /* Points to the current sample of the state */\r
+ q7_t x0, x1, x2, x3; /* Temporary variables to hold state */\r
+ q7_t c0; /* Temporary variable to hold coefficient value */\r
+ q7_t *px; /* Temporary pointer for state */\r
+ q7_t *pb; /* Temporary pointer for coefficient buffer */\r
+ q31_t acc0, acc1, acc2, acc3; /* Accumulators */\r
+ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */\r
+ uint32_t i, tapCnt, blkCnt; /* Loop counters */\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = &(S->pState[(numTaps - 1u)]);\r
+\r
+ /* Apply loop unrolling and compute 4 output values simultaneously. \r
+ * The variables acc0 ... acc3 hold output values that are being computed: \r
+ * \r
+ * acc0 = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] \r
+ * acc1 = b[numTaps-1] * x[n-numTaps] + b[numTaps-2] * x[n-numTaps-1] + b[numTaps-3] * x[n-numTaps-2] +...+ b[0] * x[1] \r
+ * acc2 = b[numTaps-1] * x[n-numTaps+1] + b[numTaps-2] * x[n-numTaps] + b[numTaps-3] * x[n-numTaps-1] +...+ b[0] * x[2] \r
+ * acc3 = b[numTaps-1] * x[n-numTaps+2] + b[numTaps-2] * x[n-numTaps+1] + b[numTaps-3] * x[n-numTaps] +...+ b[0] * x[3] \r
+ */\r
+ blkCnt = blockSize >> 2;\r
+\r
+ /* First part of the processing with loop unrolling. Compute 4 outputs at a time. \r
+ ** a second loop below computes the remaining 1 to 3 samples. */\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy four new input samples into the state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set all accumulators to zero */\r
+ acc0 = 0;\r
+ acc1 = 0;\r
+ acc2 = 0;\r
+ acc3 = 0;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize coefficient pointer */\r
+ pb = pCoeffs;\r
+\r
+ /* Read the first three samples from the state buffer: \r
+ * x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2] */\r
+ x0 = *(px++);\r
+ x1 = *(px++);\r
+ x2 = *(px++);\r
+\r
+ /* Loop unrolling. Process 4 taps at a time. */\r
+ tapCnt = numTaps >> 2;\r
+ i = tapCnt;\r
+\r
+ while(i > 0u)\r
+ {\r
+ /* Read the b[numTaps] coefficient */\r
+ c0 = *pb;\r
+\r
+ /* Read x[n-numTaps-3] sample */\r
+ x3 = *px;\r
+ \r
+ /* acc0 += b[numTaps] * x[n-numTaps] */\r
+ acc0 += ((q15_t) x0 * c0);\r
+\r
+ /* acc1 += b[numTaps] * x[n-numTaps-1] */\r
+ acc1 += ((q15_t) x1 * c0);\r
+\r
+ /* acc2 += b[numTaps] * x[n-numTaps-2] */\r
+ acc2 += ((q15_t) x2 * c0);\r
+\r
+ /* acc3 += b[numTaps] * x[n-numTaps-3] */\r
+ acc3 += ((q15_t) x3 * c0);\r
+\r
+ /* Read the b[numTaps-1] coefficient */\r
+ c0 = *(pb + 1u);\r
+\r
+ /* Read x[n-numTaps-4] sample */\r
+ x0 = *(px + 1u);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q15_t) x1 * c0);\r
+ acc1 += ((q15_t) x2 * c0);\r
+ acc2 += ((q15_t) x3 * c0);\r
+ acc3 += ((q15_t) x0 * c0);\r
+\r
+ /* Read the b[numTaps-2] coefficient */\r
+ c0 = *(pb + 2u);\r
+\r
+ /* Read x[n-numTaps-5] sample */\r
+ x1 = *(px + 2u);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q15_t) x2 * c0);\r
+ acc1 += ((q15_t) x3 * c0);\r
+ acc2 += ((q15_t) x0 * c0);\r
+ acc3 += ((q15_t) x1 * c0);\r
+\r
+ /* Read the b[numTaps-3] coefficients */\r
+ c0 = *(pb + 3u);\r
+\r
+ /* Read x[n-numTaps-6] sample */\r
+ x2 = *(px + 3u);\r
+ \r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q15_t) x3 * c0);\r
+ acc1 += ((q15_t) x0 * c0);\r
+ acc2 += ((q15_t) x1 * c0);\r
+ acc3 += ((q15_t) x2 * c0);\r
+\r
+ /* update coefficient pointer */\r
+ pb += 4u;\r
+ px += 4u;\r
+ \r
+ /* Decrement the loop counter */\r
+ i--;\r
+ }\r
+\r
+ /* If the filter length is not a multiple of 4, compute the remaining filter taps */\r
+\r
+ i = numTaps - (tapCnt * 4u);\r
+ while(i > 0u)\r
+ {\r
+ /* Read coefficients */\r
+ c0 = *(pb++);\r
+\r
+ /* Fetch 1 state variable */\r
+ x3 = *(px++);\r
+\r
+ /* Perform the multiply-accumulates */\r
+ acc0 += ((q15_t) x0 * c0);\r
+ acc1 += ((q15_t) x1 * c0);\r
+ acc2 += ((q15_t) x2 * c0);\r
+ acc3 += ((q15_t) x3 * c0);\r
+\r
+ /* Reuse the present sample states for next sample */\r
+ x0 = x1;\r
+ x1 = x2;\r
+ x2 = x3;\r
+\r
+ /* Decrement the loop counter */\r
+ i--;\r
+ }\r
+\r
+ /* Advance the state pointer by 4 to process the next group of 4 samples */\r
+ pState = pState + 4;\r
+\r
+ /* The results in the 4 accumulators are in 2.62 format. Convert to 1.31 \r
+ ** Then store the 4 outputs in the destination buffer. */\r
+ acc0 = __SSAT((acc0 >> 7u), 8);\r
+ *pDst++ = acc0;\r
+ acc1 = __SSAT((acc1 >> 7u), 8);\r
+ *pDst++ = acc1;\r
+ acc2 = __SSAT((acc2 >> 7u), 8);\r
+ *pDst++ = acc2;\r
+ acc3 = __SSAT((acc3 >> 7u), 8);\r
+ *pDst++ = acc3;\r
+\r
+ /* Decrement the samples loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+\r
+ /* If the blockSize is not a multiple of 4, compute any remaining output samples here. \r
+ ** No loop unrolling is used. */\r
+ blkCnt = blockSize % 4u;\r
+\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set the accumulator to zero */\r
+ acc0 = 0;\r
+\r
+ /* Initialize state pointer */\r
+ px = pState;\r
+\r
+ /* Initialize Coefficient pointer */\r
+ pb = (pCoeffs);\r
+\r
+ i = numTaps;\r
+\r
+ /* Perform the multiply-accumulates */\r
+ do\r
+ {\r
+ acc0 += (q15_t) * (px++) * (*(pb++));\r
+ i--;\r
+ } while(i > 0u);\r
+\r
+ /* The result is in 2.14 format. Convert to 1.7 \r
+ ** Then store the output in the destination buffer. */\r
+ *pDst++ = __SSAT((acc0 >> 7u), 8);\r
+\r
+ /* Advance state pointer by 1 for the next sample */\r
+ pState = pState + 1;\r
+\r
+ /* Decrement the samples loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the satrt of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+ tapCnt = (numTaps - 1u) >> 2u;\r
+\r
+ /* copy data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+ /* Calculate remaining number of copies */\r
+ tapCnt = (numTaps - 1u) % 0x4u;\r
+\r
+ /* Copy the remaining q31_t data */\r
+ while(tapCnt > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+\r
+ /* Decrement the loop counter */\r
+ tapCnt--;\r
+ }\r
+\r
+#else\r
+\r
+/* Run the below code for Cortex-M0 */\r
+\r
+ uint32_t numTaps = S->numTaps; /* Number of taps in the filter */\r
+ uint32_t i, blkCnt; /* Loop counters */\r
+ q7_t *pState = S->pState; /* State pointer */\r
+ q7_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */\r
+ q7_t *px, *pb; /* Temporary pointers to state and coeff */\r
+ q31_t acc = 0; /* Accumlator */\r
+ q7_t *pStateCurnt; /* Points to the current sample of the state */\r
+\r
+\r
+ /* S->pState points to state array which contains previous frame (numTaps - 1) samples */\r
+ /* pStateCurnt points to the location where the new input data should be written */\r
+ pStateCurnt = S->pState + (numTaps - 1u);\r
+\r
+ /* Initialize blkCnt with blockSize */\r
+ blkCnt = blockSize;\r
+\r
+ /* Perform filtering upto BlockSize - BlockSize%4 */\r
+ while(blkCnt > 0u)\r
+ {\r
+ /* Copy one sample at a time into state buffer */\r
+ *pStateCurnt++ = *pSrc++;\r
+\r
+ /* Set accumulator to zero */\r
+ acc = 0;\r
+\r
+ /* Initialize state pointer of type q7 */\r
+ px = pState;\r
+\r
+ /* Initialize coeff pointer of type q7 */\r
+ pb = pCoeffs;\r
+\r
+\r
+ i = numTaps;\r
+\r
+ while(i > 0u)\r
+ {\r
+ /* acc = b[numTaps-1] * x[n-numTaps-1] + b[numTaps-2] * x[n-numTaps-2] + b[numTaps-3] * x[n-numTaps-3] +...+ b[0] * x[0] */\r
+ acc += (q15_t) * px++ * *pb++;\r
+ i--;\r
+ }\r
+\r
+ /* Store the 1.7 format filter output in destination buffer */\r
+ *pDst++ = (q7_t) __SSAT((acc >> 7), 8);\r
+\r
+ /* Advance the state pointer by 1 to process the next sample */\r
+ pState = pState + 1;\r
+\r
+ /* Decrement the loop counter */\r
+ blkCnt--;\r
+ }\r
+\r
+ /* Processing is complete. \r
+ ** Now copy the last numTaps - 1 samples to the satrt of the state buffer. \r
+ ** This prepares the state buffer for the next function call. */\r
+\r
+\r
+ /* Points to the start of the state buffer */\r
+ pStateCurnt = S->pState;\r
+\r
+\r
+ /* Copy numTaps number of values */\r
+ i = (numTaps - 1u);\r
+\r
+ /* Copy q7_t data */\r
+ while(i > 0u)\r
+ {\r
+ *pStateCurnt++ = *pState++;\r
+ i--;\r
+ }\r
+\r
+#endif /* #ifndef ARM_MATH_CM0_FAMILY */\r
+\r
+}\r
+\r
+/** \r
+ * @} end of FIR group \r
+ */\r
#include <array>
#include <vector>
-#ifndef WIN32
+#ifndef STMDSP_WIN32
#include <sys/mman.h>
+#include <unistd.h>
#endif
#include "wxmain_devdata.h"
enum Id {
- MeasureTimer = 1,
+ TimerPerformance = 1,
+ TimerRecord,
+ TimerWavClip,
MFileNew,
MFileOpen,
MRunGenStart,
MCodeCompile,
MCodeDisassemble,
- CompileOutput
+ CompileOutput
};
MainFrame::MainFrame() :
wxEmptyString,
wxDefaultPosition, wxSize(620, 250),
wxTE_READONLY | wxTE_MULTILINE | wxHSCROLL | wxTE_RICH2);
- m_measure_timer = new wxTimer(this, Id::MeasureTimer);
+ m_timer_performance = new wxTimer(this, Id::TimerPerformance);
+ m_timer_record = new wxTimer(this, Id::TimerRecord);
+ m_timer_wavclip = new wxTimer(this, Id::TimerWavClip);
m_menu_bar = new wxMenuBar;
m_rate_select = new wxComboBox(panelToolbar, wxID_ANY,
wxEmptyString,
wxDefaultPosition, wxDefaultSize,
srateValues.size(), srateValues.data(),
wxCB_READONLY);
-#ifndef WIN32
+#ifndef STMDSP_WIN32
m_device_samples = reinterpret_cast<stmdsp::adcsample_t *>(::mmap(
nullptr, stmdsp::SAMPLES_MAX * sizeof(stmdsp::adcsample_t),
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0));
nullptr, stmdsp::SAMPLES_MAX * sizeof(stmdsp::adcsample_t),
PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0));
#else
- m_device_samples = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX];
- m_device_samples_input = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX];
+ m_device_samples = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX];
+ m_device_samples_input = new stmdsp::adcsample_t[stmdsp::SAMPLES_MAX];
#endif
m_menu_bar->Append(menuFile, "&File");
// Binds:
// General
- Bind(wxEVT_TIMER, &MainFrame::onMeasureTimer, this, Id::MeasureTimer);
- Bind(wxEVT_CLOSE_WINDOW, &MainFrame::onCloseEvent, this, wxID_ANY);
+ Bind(wxEVT_TIMER, &MainFrame::onTimerPerformance, this, Id::TimerPerformance);
+ Bind(wxEVT_TIMER, &MainFrame::onTimerRecord, this, Id::TimerRecord);
+ Bind(wxEVT_TIMER, &MainFrame::onTimerWavClip, this, Id::TimerWavClip);
+ Bind(wxEVT_CLOSE_WINDOW, &MainFrame::onCloseEvent, this, wxID_ANY);
m_compile_output->
- Bind(wxEVT_PAINT, &MainFrame::onPaint, this, Id::CompileOutput);
+ Bind(wxEVT_PAINT, &MainFrame::onPaint, this, Id::CompileOutput);
// Toolbar actions
Bind(wxEVT_BUTTON, &MainFrame::onRunCompile, this, wxID_ANY, wxID_ANY, comp);
//delete m_menu_bar->Remove(1);
//delete m_menu_bar->Remove(0);
//delete m_menu_bar;
- delete m_measure_timer;
+ delete m_timer_performance;
+ delete m_timer_record;
+ delete m_timer_wavclip;
delete m_device;
Unbind(wxEVT_COMBOBOX, &MainFrame::onToolbarSampleRate, this, wxID_ANY, wxID_ANY);
event.Skip();
}
-// Measure timer tick handler
-// Only called while connected and running.
-void MainFrame::onMeasureTimer(wxTimerEvent&)
+void MainFrame::onTimerPerformance(wxTimerEvent&)
{
- if (m_conv_result_log || m_run_draw_samples->IsChecked()) {
- auto samples = m_device->continuous_read();
- if (samples.size() > 0) {
- std::copy(samples.cbegin(), samples.cend(), m_device_samples);
-
- if (m_conv_result_log) {
- for (auto& s : samples) {
- auto str = std::to_string(s) + ',';
- m_conv_result_log->Write(str.c_str(), str.size());
- }
- m_conv_result_log->Write("\n", 1);
- }
- if (m_run_draw_samples->IsChecked()) {
- samples = m_device->continuous_read_input();
- std::copy(samples.cbegin(), samples.cend(), m_device_samples_input);
- m_compile_output->Refresh();
+ // Show execution time
+ m_status_bar->SetStatusText(wxString::Format(wxT("Execution time: %u cycles"),
+ m_device->continuous_start_get_measurement()));
+}
+
+void MainFrame::onTimerRecord(wxTimerEvent&)
+{
+ auto samples = m_device->continuous_read();
+ if (samples.size() > 0) {
+ std::copy(samples.cbegin(), samples.cend(), m_device_samples);
+
+ if (m_conv_result_log) {
+ for (auto& s : samples) {
+ auto str = std::to_string(s) + ',';
+ m_conv_result_log->Write(str.c_str(), str.size());
}
+ m_conv_result_log->Write("\n", 1);
}
- }
- if (m_wav_clip) {
- // Stream out next WAV chunk
- auto size = m_device->get_buffer_size();
- auto chunk = new stmdsp::adcsample_t[size];
- auto src = reinterpret_cast<uint16_t *>(m_wav_clip->next(size));
- for (unsigned int i = 0; i < size; i++)
- chunk[i] = ((uint32_t)*src++) / 16 + 2048;
- m_device->siggen_upload(chunk, size);
- delete[] chunk;
+ if (m_run_draw_samples->IsChecked()) {
+ samples = m_device->continuous_read_input();
+ std::copy(samples.cbegin(), samples.cend(), m_device_samples_input);
+ m_compile_output->Refresh();
+ }
}
+}
- if (m_run_measure->IsChecked()) {
- // Show execution time
- m_status_bar->SetStatusText(wxString::Format(wxT("Execution time: %u cycles"),
- m_device->continuous_start_get_measurement()));
- }
+void MainFrame::onTimerWavClip(wxTimerEvent&)
+{
+ // Stream out next WAV chunk
+ auto size = m_device->get_buffer_size();
+ auto chunk = new stmdsp::adcsample_t[size];
+ auto src = reinterpret_cast<uint16_t *>(m_wav_clip->next(size));
+ for (unsigned int i = 0; i < size; i++)
+ chunk[i] = ((uint32_t)*src++) / 16 + 2048;
+ m_device->siggen_upload(chunk, size);
+ delete[] chunk;
}
void MainFrame::onPaint(wxPaintEvent&)
if (!m_is_running || !m_run_draw_samples->IsChecked())
return;
- const auto& dim = m_compile_output->GetSize();
+ const auto& dim = m_compile_output->GetSize();
wxRect rect {
- 0, 0, dim.GetWidth(), dim.GetHeight()
+ 0, 0, dim.GetWidth(), dim.GetHeight()
};
wxBufferedPaintDC dc (m_compile_output);
wxString MainFrame::compileEditorCode()
{
- stmdsp::platform platform;
+ stmdsp::platform platform;
if (m_device != nullptr) {
- platform = m_device->get_platform();
- } else {
+ platform = m_device->get_platform();
+ } else {
m_status_bar->SetStatusText("Assuming L4 platform...");
platform = stmdsp::platform::L4;
}
file.Write(wxString(file_text) + m_text_editor->GetText());
file.Close();
- constexpr const char *script_ext =
+ constexpr const char *script_ext =
#ifndef STMDSP_WIN32
- ".sh";
+ ".sh";
#else
- ".bat";
+ ".bat";
#endif
wxFile makefile (m_temp_file_name + script_ext, wxFile::write);
wxString make_text (platform == stmdsp::platform::L4 ? makefile_text_l4
: makefile_text_h7);
make_text.Replace("$0", m_temp_file_name);
+ char cwd[PATH_MAX];
+ make_text.Replace("$1", getcwd(cwd, sizeof(cwd)));
makefile.Write(make_text);
makefile.Close();
#ifndef STMDSP_WIN32
system(wxString("chmod +x ") + m_temp_file_name + script_ext);
#endif
- int result = system(make_command.ToAscii());
- wxFile result_file (make_output);
- wxString result_text;
- result_file.ReadAll(&result_text);
- result_file.Close();
- m_compile_output->Clear();
+ int result = system(make_command.ToAscii());
+ wxFile result_file (make_output);
+ wxString result_text;
+ result_file.ReadAll(&result_text);
+ result_file.Close();
+ m_compile_output->Clear();
m_compile_output->WriteText(result_text);
wxRemoveFile(m_temp_file_name);
if (system(command.ToAscii()) == 0) {
wxFile result_file (output);
- wxString result_text;
- result_file.ReadAll(&result_text);
- result_file.Close();
- m_compile_output->Clear();
- m_compile_output->WriteText(result_text);
- wxRemoveFile(output);
+ wxString result_text;
+ result_file.ReadAll(&result_text);
+ result_file.Close();
+ m_compile_output->Clear();
+ m_compile_output->WriteText(result_text);
+ wxRemoveFile(output);
m_status_bar->SetStatusText(wxString::Format(wxT("Done. Line count: %u."),
m_compile_output->GetNumberOfLines()));
} else {
void onCodeDisassemble(wxCommandEvent&);
void onPaint(wxPaintEvent&);
- void onMeasureTimer(wxTimerEvent&);
+ void onTimerPerformance(wxTimerEvent&);
+ void onTimerRecord(wxTimerEvent&);
+ void onTimerWavClip(wxTimerEvent&);
private:
// Set to true if connected and running
wxControl *m_signal_area = nullptr;
wxMenuItem *m_run_measure = nullptr;
wxMenuItem *m_run_draw_samples = nullptr;
- wxTimer *m_measure_timer = nullptr;
+ wxTimer *m_timer_performance = nullptr;
+ wxTimer *m_timer_record = nullptr;
+ wxTimer *m_timer_wavclip = nullptr;
wxStatusBar *m_status_bar = nullptr;
wxMenuBar *m_menu_bar = nullptr;
wxComboBox *m_rate_select = nullptr;
#endif
// $0 = temp file name
+// TODO try -ffunction-sections -fdata-sections -Wl,--gc-sections
const char *makefile_text_h7 =
#ifdef STMDSP_WIN32
"echo off" NEWLINE
#endif
"arm-none-eabi-g++ -x c++ -Os -std=c++20 -fno-exceptions -fno-rtti "
"-mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-d16 -mtune=cortex-m7 "
- "-nostartfiles "
+ "-nostartfiles "
"-Wl,-Ttext-segment=0x00000000 -Wl,-zmax-page-size=512 -Wl,-eprocess_data_entry "
"$0 -o $0.o" NEWLINE
COPY " $0.o $0.orig.o" NEWLINE
#endif
"arm-none-eabi-g++ -x c++ -Os -std=c++20 -fno-exceptions -fno-rtti "
"-mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mtune=cortex-m4 "
- "-nostartfiles "
+ "-nostartfiles -I$1/cmsis"
"-Wl,-Ttext-segment=0x10000000 -Wl,-zmax-page-size=512 -Wl,-eprocess_data_entry "
"$0 -o $0.o" NEWLINE
COPY " $0.o $0.orig.o" NEWLINE
if (!m_is_running) {
if (m_run_measure->IsChecked()) {
m_device->continuous_start_measure();
- m_measure_timer->StartOnce(1000);
+ m_timer_performance->StartOnce(1000);
} else {
if (m_device->is_siggening() && m_wav_clip) {
- m_measure_timer->Start(m_device->get_buffer_size() * 500 /
+ // TODO Confirm need for factor of 500
+ m_timer_wavclip->Start(m_device->get_buffer_size() * 500 /
srateNums[m_rate_select->GetSelection()]);
} else if (m_conv_result_log) {
- m_measure_timer->Start(15);
+ m_timer_record->Start(m_device->get_buffer_size() /
+ srateNums[m_rate_select->GetSelection()] *
+ 800 / 1000);
} else if (m_run_draw_samples->IsChecked()) {
- m_measure_timer->Start(300);
+ m_timer_record->Start(m_device->get_buffer_size() /
+ srateNums[m_rate_select->GetSelection()]);
}
m_device->continuous_start();
m_is_running = true;
} else {
m_device->continuous_stop();
- m_measure_timer->Stop();
+ m_timer_performance->Stop();
+ m_timer_record->Stop();
+ m_timer_wavclip->Stop();
m_rate_select->Enable(true);
menuItem->SetItemLabel("&Start");
__attribute__((section(".convdata")))
static ELF::Entry elf_entry = nullptr;
+static char userMessageBuffer[128];
+static unsigned char userMessageSize = 0;
+
__attribute__((section(".convcode")))
static void conversion_unprivileged_main();
// 'S' - Stop conversion.
// 's' - Get latest block of conversion results.
// 't' - Get latest block of conversion input.
+ // 'u' - Get user message.
// 'W' - Start signal generator (siggen).
// 'w' - Stop siggen.
}
break;
+ case 'u':
+ USBSerial::write(reinterpret_cast<uint8_t *>(userMessageBuffer), userMessageSize);
+ break;
+
case 'W':
DAC::start(1, samplesSigGen.data(), samplesSigGen.size());
break;
case 3:
ctxp->r0 = ADC::readAlt(0);
break;
+ case 4:
+ {
+ const char *str = reinterpret_cast<const char *>(ctxp->r0);
+ auto src = str;
+ auto dst = userMessageBuffer;
+ while (*src)
+ *dst++ = *src++;
+ *dst = '\0';
+ userMessageSize = src - str;
+ }
+ break;
default:
while (1);
break;