file_path
stringlengths
20
207
content
stringlengths
5
3.85M
size
int64
5
3.85M
lang
stringclasses
9 values
avg_line_length
float64
1.33
100
max_line_length
int64
4
993
alphanum_fraction
float64
0.26
0.93
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_lms_norm_f32.c * Description: Processing function for the floating-point NLMS filter * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @defgroup LMS_NORM Normalized LMS Filters This set of functions implements a commonly used adaptive filter. It is related to the Least Mean Square (LMS) adaptive filter and includes an additional normalization factor which increases the adaptation rate of the filter. The CMSIS DSP Library contains normalized LMS filter functions that operate on Q15, Q31, and floating-point data types. A normalized least mean square (NLMS) filter consists of two components as shown below. The first component is a standard transversal or FIR filter. The second component is a coefficient update mechanism. The NLMS filter has two input signals. The "input" feeds the FIR filter while the "reference input" corresponds to the desired output of the FIR filter. That is, the FIR filter coefficients are updated so that the output of the FIR filter matches the reference input. The filter coefficient update mechanism is based on the difference between the FIR filter output and the reference input. This "error signal" tends towards zero as the filter adapts. The NLMS processing functions accept the input and reference input signals and generate the filter output and error signal. \image html LMS.gif "Internal structure of the NLMS adaptive filter" The functions operate on blocks of data and each call to the function processes <code>blockSize</code> samples through the filter. <code>pSrc</code> points to input signal, <code>pRef</code> points to reference signal, <code>pOut</code> points to output signal and <code>pErr</code> points to error signal. All arrays contain <code>blockSize</code> values. The functions operate on a block-by-block basis. Internally, the filter coefficients <code>b[n]</code> are updated on a sample-by-sample basis. The convergence of the LMS filter is slower compared to the normalized LMS algorithm. @par Algorithm The output signal <code>y[n]</code> is computed by a standard FIR filter: <pre> y[n] = b[0] * x[n] + b[1] * x[n-1] + b[2] * x[n-2] + ...+ b[numTaps-1] * x[n-numTaps+1] </pre> @par The error signal equals the difference between the reference signal <code>d[n]</code> and the filter output: <pre> e[n] = d[n] - y[n]. </pre> @par After each sample of the error signal is computed the instanteous energy of the filter state variables is calculated: <pre> E = x[n]^2 + x[n-1]^2 + ... + x[n-numTaps+1]^2. </pre> The filter coefficients <code>b[k]</code> are then updated on a sample-by-sample basis: <pre> b[k] = b[k] + e[n] * (mu/E) * x[n-k], for k=0, 1, ..., numTaps-1 </pre> where <code>mu</code> is the step size and controls the rate of coefficient convergence. @par In the APIs, <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>. Coefficients are stored in time reversed order. @par <pre> {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} </pre> @par <code>pState</code> points to a state array of size <code>numTaps + blockSize - 1</code>. Samples in the state buffer are stored in the order: @par <pre> {x[n-numTaps+1], x[n-numTaps], x[n-numTaps-1], x[n-numTaps-2]....x[0], x[1], ..., x[blockSize-1]} </pre> @par Note that the length of the state buffer exceeds the length of the coefficient array by <code>blockSize-1</code> samples. The increased state buffer length allows circular addressing, which is traditionally used in FIR filters, to be avoided and yields a significant speed improvement. The state variables are updated after each block of data is processed. @par Instance Structure The coefficients and state variables for a filter are stored together in an instance data structure. A separate instance structure must be defined for each filter and coefficient and state arrays cannot be shared among instances. There are separate instance structure declarations for each of the 3 supported data types. @par Initialization Functions There is also an associated initialization function for each data type. The initialization function performs the following operations: - Sets the values of the internal structure fields. - Zeros out the values in the state buffer. To do this manually without calling the init function, assign the follow subfields of the instance structure: numTaps, pCoeffs, mu, energy, x0, pState. Also set all of the values in pState to zero. For Q7, Q15, and Q31 the following fields must also be initialized; recipTable, postShift @par Instance structure cannot be placed into a const data section and it is recommended to use the initialization function. @par Fixed-Point Behavior Care must be taken when using the Q15 and Q31 versions of the normalised LMS filter. The following issues must be considered: - Scaling of coefficients - Overflow and saturation @par Scaling of Coefficients Filter coefficients are represented as fractional values and coefficients are restricted to lie in the range <code>[-1 +1)</code>. The fixed-point functions have an additional scaling parameter <code>postShift</code>. At the output of the filter's accumulator is a shift register which shifts the result by <code>postShift</code> bits. This essentially scales the filter coefficients by <code>2^postShift</code> and allows the filter coefficients to exceed the range <code>[+1 -1)</code>. The value of <code>postShift</code> is set by the user based on the expected gain through the system being modeled. @par Overflow and Saturation Overflow and saturation behavior of the fixed-point Q15 and Q31 versions are described separately as part of the function specific documentation below. */ /** @addtogroup LMS_NORM @{ */ /** @brief Processing function for floating-point normalized LMS filter. @param[in] S points to an instance of the floating-point normalized LMS filter structure @param[in] pSrc points to the block of input data @param[in] pRef points to the block of reference data @param[out] pOut points to the block of output data @param[out] pErr points to the block of error data @param[in] blockSize number of samples to process @return none */ #if defined(ARM_MATH_NEON) void arm_lms_norm_f32( arm_lms_norm_instance_f32 * S, const float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ float32_t mu = S->mu; /* Adaptive factor */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t tapCnt, blkCnt; /* Loop counters */ float32_t energy; /* Energy of the input */ float32_t sum, e, d; /* accumulator, error, reference data sample */ float32_t w, x0, in; /* weight factor, temporary variable to hold input sample and state */ float32x4_t tempV, sumV, xV, bV; float32x2_t tempV2; /* Initializations of error, difference, Coefficient update */ e = 0.0f; d = 0.0f; w = 0.0f; energy = S->energy; x0 = S->x0; /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); /* Loop over blockSize number of values */ blkCnt = blockSize; while (blkCnt > 0U) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc; /* Initialize pState pointer */ px = pState; /* Initialize coeff pointer */ pb = (pCoeffs); /* Read the sample from input buffer */ in = *pSrc++; /* Update the energy calculation */ energy -= x0 * x0; energy += in * in; /* Set the accumulator to zero */ sum = 0.0f; sumV = vdupq_n_f32(0.0); /* Process 4 taps at a time. */ tapCnt = numTaps >> 2; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ xV = vld1q_f32(px); bV = vld1q_f32(pb); sumV = vmlaq_f32(sumV, xV, bV); px += 4; pb += 4; /* Decrement the loop counter */ tapCnt--; } tempV2 = vpadd_f32(vget_low_f32(sumV),vget_high_f32(sumV)); sum = tempV2[0] + tempV2[1]; /* If the filter length is not a multiple of 4, compute the remaining filter taps */ tapCnt = numTaps % 0x4U; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum += (*px++) * (*pb++); /* Decrement the loop counter */ tapCnt--; } /* The result in the accumulator, store in the destination buffer. */ *pOut++ = sum; /* Compute and store error */ d = (float32_t) (*pRef++); e = d - sum; *pErr++ = e; /* Calculation of Weighting factor for updating filter coefficients */ /* epsilon value 0.000000119209289f */ w = (e * mu) / (energy + 0.000000119209289f); /* Initialize pState pointer */ px = pState; /* Initialize coeff pointer */ pb = (pCoeffs); /* Process 4 taps at a time. */ tapCnt = numTaps >> 2; /* Update filter coefficients */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ xV = vld1q_f32(px); bV = vld1q_f32(pb); px += 4; bV = vmlaq_n_f32(bV,xV,w); vst1q_f32(pb,bV); pb += 4; /* Decrement the loop counter */ tapCnt--; } /* If the filter length is not a multiple of 4, compute the remaining filter taps */ tapCnt = numTaps % 0x4U; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ *pb += w * (*px++); pb++; /* Decrement the loop counter */ tapCnt--; } x0 = *pState; /* Advance state pointer by 1 for the next sample */ pState = pState + 1; /* Decrement the loop counter */ blkCnt--; } S->energy = energy; S->x0 = x0; /* Processing is complete. Now copy the last numTaps - 1 samples to the satrt of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the pState buffer */ pStateCurnt = S->pState; /* Process 4 taps at a time for (numTaps - 1U)/4 samples copy */ tapCnt = (numTaps - 1U) >> 2U; /* copy data */ while (tapCnt > 0U) { tempV = vld1q_f32(pState); vst1q_f32(pStateCurnt,tempV); pState += 4; pStateCurnt += 4; /* Decrement the loop counter */ tapCnt--; } /* Calculate remaining number of copies */ tapCnt = (numTaps - 1U) % 0x4U; /* Copy the remaining q31_t data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } #else void arm_lms_norm_f32( arm_lms_norm_instance_f32 * S, const float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ float32_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ float32_t mu = S->mu; /* Adaptive factor */ float32_t acc, e; /* Accumulator, error */ float32_t w; /* Weight factor */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t tapCnt, blkCnt; /* Loop counters */ float32_t energy; /* Energy of the input */ float32_t x0, in; /* Temporary variable to hold input sample and state */ /* Initializations of error, difference, Coefficient update */ e = 0.0f; w = 0.0f; energy = S->energy; x0 = S->x0; /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); /* initialise loop count */ blkCnt = blockSize; while (blkCnt > 0U) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc; /* Initialize pState pointer */ px = pState; /* Initialize coefficient pointer */ pb = pCoeffs; /* Read the sample from input buffer */ in = *pSrc++; /* Update the energy calculation */ energy -= x0 * x0; energy += in * in; /* Set the accumulator to zero */ acc = 0.0f; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = numTaps >> 2U; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ acc += (*px++) * (*pb++); acc += (*px++) * (*pb++); acc += (*px++) * (*pb++); acc += (*px++) * (*pb++); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = numTaps; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ acc += (*px++) * (*pb++); /* Decrement the loop counter */ tapCnt--; } /* Store the result from accumulator into the destination buffer. */ *pOut++ = acc; /* Compute and store error */ e = (float32_t) *pRef++ - acc; *pErr++ = e; /* Calculation of Weighting factor for updating filter coefficients */ /* epsilon value 0.000000119209289f */ w = (e * mu) / (energy + 0.000000119209289f); /* Initialize pState pointer */ px = pState; /* Initialize coefficient pointer */ pb = pCoeffs; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = numTaps >> 2U; /* Update filter coefficients */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ *pb += w * (*px++); pb++; *pb += w * (*px++); pb++; *pb += w * (*px++); pb++; *pb += w * (*px++); pb++; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = numTaps; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ *pb += w * (*px++); pb++; /* Decrement loop counter */ tapCnt--; } x0 = *pState; /* Advance state pointer by 1 for the next sample */ pState = pState + 1; /* Decrement loop counter */ blkCnt--; } /* Save energy and x0 values for the next frame */ S->energy = energy; S->x0 = x0; /* Processing is complete. Now copy the last numTaps - 1 samples to the start of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the pState buffer */ pStateCurnt = S->pState; /* copy data */ #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = (numTaps - 1U) >> 2U; while (tapCnt > 0U) { *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = (numTaps - 1U) % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = (numTaps - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement loop counter */ tapCnt--; } } #endif /* #if defined(ARM_MATH_NEON) */ /** @} end of LMS_NORM group */
18,255
C
31.311504
140
0.594686
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_decimate_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_decimate_q31.c * Description: Q31 FIR Decimator * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR_decimate @{ */ /** @brief Processing function for the Q31 FIR decimator. @param[in] S points to an instance of the Q31 FIR decimator structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior The function is implemented using an internal 64-bit accumulator. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around rather than clip. In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits (where log2 is read as log to the base 2). After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format. @remark Refer to \ref arm_fir_decimate_fast_q31() for a faster but less precise implementation of this function. */ void arm_fir_decimate_q31( const arm_fir_decimate_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCur; /* Points to the current sample of the state */ q31_t *px0; /* Temporary pointer for state buffer */ const q31_t *pb; /* Temporary pointer for coefficient buffer */ q31_t x0, c0; /* Temporary variables to hold state and coefficient values */ q63_t acc0; /* Accumulator */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i, tapCnt, blkCnt, outBlockSize = blockSize / S->M; /* Loop counters */ #if defined (ARM_MATH_LOOPUNROLL) q31_t *px1, *px2, *px3; q31_t x1, x2, x3; q63_t acc1, acc2, acc3; #endif /* S->pState buffer contains previous frame (numTaps - 1) samples */ /* pStateCur points to the location where the new input data should be written */ pStateCur = S->pState + (numTaps - 1U); #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 samples at a time */ blkCnt = outBlockSize >> 2U; /* Samples loop unrolled by 4 */ while (blkCnt > 0U) { /* Copy 4 * decimation factor number of new input samples into the state buffer */ i = S->M * 4; do { *pStateCur++ = *pSrc++; } while (--i); /* Set accumulators to zero */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* Initialize state pointer for all the samples */ px0 = pState; px1 = pState + S->M; px2 = pState + 2 * S->M; px3 = pState + 3 * S->M; /* Initialize coeff pointer */ pb = pCoeffs; /* Loop unrolling: Compute 4 taps at a time */ tapCnt = numTaps >> 2U; while (tapCnt > 0U) { /* Read the b[numTaps-1] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-1] sample for acc0 */ x0 = *(px0++); /* Read x[n-numTaps-1] sample for acc1 */ x1 = *(px1++); /* Read x[n-numTaps-1] sample for acc2 */ x2 = *(px2++); /* Read x[n-numTaps-1] sample for acc3 */ x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; acc1 += (q63_t) x1 * c0; acc2 += (q63_t) x2 * c0; acc3 += (q63_t) x3 * c0; /* Read the b[numTaps-2] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-2] sample for acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; acc1 += (q63_t) x1 * c0; acc2 += (q63_t) x2 * c0; acc3 += (q63_t) x3 * c0; /* Read the b[numTaps-3] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-3] sample acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; acc1 += (q63_t) x1 * c0; acc2 += (q63_t) x2 * c0; acc3 += (q63_t) x3 * c0; /* Read the b[numTaps-4] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-4] sample acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; acc1 += (q63_t) x1 * c0; acc2 += (q63_t) x2 * c0; acc3 += (q63_t) x3 * c0; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; while (tapCnt > 0U) { /* Read coefficients */ c0 = *(pb++); /* Fetch state variables for acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; acc1 += (q63_t) x1 * c0; acc2 += (q63_t) x2 * c0; acc3 += (q63_t) x3 * c0; /* Decrement loop counter */ tapCnt--; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M * 4; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q31_t) (acc0 >> 31); *pDst++ = (q31_t) (acc1 >> 31); *pDst++ = (q31_t) (acc2 >> 31); *pDst++ = (q31_t) (acc3 >> 31); /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining samples */ blkCnt = outBlockSize % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = outBlockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Copy decimation factor number of new input samples into the state buffer */ i = S->M; do { *pStateCur++ = *pSrc++; } while (--i); /* Set accumulator to zero */ acc0 = 0; /* Initialize state pointer */ px0 = pState; /* Initialize coeff pointer */ pb = pCoeffs; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time */ tapCnt = numTaps >> 2U; while (tapCnt > 0U) { /* Read the b[numTaps-1] coefficient */ c0 = *pb++; /* Read x[n-numTaps-1] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; /* Read the b[numTaps-2] coefficient */ c0 = *pb++; /* Read x[n-numTaps-2] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; /* Read the b[numTaps-3] coefficient */ c0 = *pb++; /* Read x[n-numTaps-3] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; /* Read the b[numTaps-4] coefficient */ c0 = *pb++; /* Read x[n-numTaps-4] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; #else /* Initialize tapCnt with number of taps */ tapCnt = numTaps; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Read coefficients */ c0 = *pb++; /* Fetch 1 state variable */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; /* Decrement loop counter */ tapCnt--; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q31_t) (acc0 >> 31); /* Decrement loop counter */ blkCnt--; } /* Processing is complete. Now copy the last numTaps - 1 samples to the satrt of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCur = S->pState; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time */ tapCnt = (numTaps - 1U) >> 2U; /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; *pStateCur++ = *pState++; *pStateCur++ = *pState++; *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = (numTaps - 1U) % 0x04U; #else /* Initialize tapCnt with number of taps */ tapCnt = (numTaps - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } } /** @} end of FIR_decimate group */
10,422
C
25.863402
162
0.544905
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_iir_lattice_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_iir_lattice_q15.c * Description: Q15 IIR Lattice filter processing function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup IIR_Lattice @{ */ /** @brief Processing function for the Q15 IIR lattice filter. @param[in] S points to an instance of the Q15 IIR lattice structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior The function is implemented using an internal 64-bit accumulator. Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. Lastly, the accumulator is saturated to yield a result in 1.15 format. */ void arm_iir_lattice_q15( const arm_iir_lattice_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ q15_t *pStateCur; /* State current pointer */ q31_t fcurr, fnext = 0, gcurr = 0, gnext; /* Temporary variables for lattice stages */ q63_t acc; /* Accumlator */ q15_t *px1, *px2, *pk, *pv; /* Temporary pointers for state and coef */ uint32_t numStages = S->numStages; /* Number of stages */ uint32_t blkCnt, tapCnt; /* Temporary variables for counts */ q15_t out; /* Temporary variable for output */ #if defined (ARM_MATH_DSP) && defined (ARM_MATH_LOOPUNROLL) q15_t gnext1, gnext2; /* Temporary variables for lattice stages */ q31_t v; /* Temporary variable for ladder coefficient */ #endif /* initialise loop count */ blkCnt = blockSize; #if defined (ARM_MATH_DSP) /* Sample processing */ while (blkCnt > 0U) { /* Read Sample from input buffer */ /* fN(n) = x(n) */ fcurr = *pSrc++; /* Initialize Ladder coeff pointer */ pv = &S->pvCoeffs[0]; /* Initialize Reflection coeff pointer */ pk = &S->pkCoeffs[0]; /* Initialize state read pointer */ px1 = pState; /* Initialize state write pointer */ px2 = pState; /* Set accumulator to zero */ acc = 0; /* Process sample for first tap */ gcurr = *px1++; /* fN-1(n) = fN(n) - kN * gN-1(n-1) */ fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15); fnext = __SSAT(fnext, 16); /* gN(n) = kN * fN-1(n) + gN-1(n-1) */ gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr; gnext = __SSAT(gnext, 16); /* write gN(n) into state for next sample processing */ *px2++ = (q15_t) gnext; /* y(n) += gN(n) * vN */ acc += (q31_t) ((gnext * (*pv++))); /* Update f values for next coefficient processing */ fcurr = fnext; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = (numStages - 1U) >> 2U; while (tapCnt > 0U) { /* Process sample for 2nd, 6th ...taps */ /* Read gN-2(n-1) from state buffer */ gcurr = *px1++; /* fN-2(n) = fN-1(n) - kN-1 * gN-2(n-1) */ fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15); fnext = __SSAT(fnext, 16); /* gN-1(n) = kN-1 * fN-2(n) + gN-2(n-1) */ gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr; gnext1 = (q15_t) __SSAT(gnext, 16); /* write gN-1(n) into state for next sample processing */ *px2++ = (q15_t) gnext1; /* Process sample for 3nd, 7th ...taps */ /* Read gN-3(n-1) from state buffer */ gcurr = *px1++; /* Process sample for 3rd, 7th .. taps */ /* fN-3(n) = fN-2(n) - kN-2 * gN-3(n-1) */ fcurr = fnext - (((q31_t) gcurr * (*pk)) >> 15); fcurr = __SSAT(fcurr, 16); /* gN-2(n) = kN-2 * fN-3(n) + gN-3(n-1) */ gnext = (((q31_t) fcurr * (*pk++)) >> 15) + gcurr; gnext2 = (q15_t) __SSAT(gnext, 16); /* write gN-2(n) into state */ *px2++ = (q15_t) gnext2; /* Read vN-1 and vN-2 at a time */ v = read_q15x2_ia (&pv); /* Pack gN-1(n) and gN-2(n) */ #ifndef ARM_MATH_BIG_ENDIAN gnext = __PKHBT(gnext1, gnext2, 16); #else gnext = __PKHBT(gnext2, gnext1, 16); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* y(n) += gN-1(n) * vN-1 */ /* process for gN-5(n) * vN-5, gN-9(n) * vN-9 ... */ /* y(n) += gN-2(n) * vN-2 */ /* process for gN-6(n) * vN-6, gN-10(n) * vN-10 ... */ acc = __SMLALD(gnext, v, acc); /* Process sample for 4th, 8th ...taps */ /* Read gN-4(n-1) from state buffer */ gcurr = *px1++; /* Process sample for 4th, 8th .. taps */ /* fN-4(n) = fN-3(n) - kN-3 * gN-4(n-1) */ fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15); fnext = __SSAT(fnext, 16); /* gN-3(n) = kN-3 * fN-1(n) + gN-1(n-1) */ gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr; gnext1 = (q15_t) __SSAT(gnext, 16); /* write gN-3(n) for the next sample process */ *px2++ = (q15_t) gnext1; /* Process sample for 5th, 9th ...taps */ /* Read gN-5(n-1) from state buffer */ gcurr = *px1++; /* Process sample for 5th, 9th .. taps */ /* fN-5(n) = fN-4(n) - kN-4 * gN-5(n-1) */ fcurr = fnext - (((q31_t) gcurr * (*pk)) >> 15); fcurr = __SSAT(fcurr, 16); /* gN-4(n) = kN-4 * fN-5(n) + gN-5(n-1) */ gnext = (((q31_t) fcurr * (*pk++)) >> 15) + gcurr; gnext2 = (q15_t) __SSAT(gnext, 16); /* write gN-4(n) for the next sample process */ *px2++ = (q15_t) gnext2; /* Read vN-3 and vN-4 at a time */ v = read_q15x2_ia (&pv); /* Pack gN-3(n) and gN-4(n) */ #ifndef ARM_MATH_BIG_ENDIAN gnext = __PKHBT(gnext1, gnext2, 16); #else gnext = __PKHBT(gnext2, gnext1, 16); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* y(n) += gN-4(n) * vN-4 */ /* process for gN-8(n) * vN-8, gN-12(n) * vN-12 ... */ /* y(n) += gN-3(n) * vN-3 */ /* process for gN-7(n) * vN-7, gN-11(n) * vN-11 ... */ acc = __SMLALD(gnext, v, acc); /* Decrement loop counter */ tapCnt--; } fnext = fcurr; /* Loop unrolling: Compute remaining taps */ tapCnt = (numStages - 1U) % 0x4U; #else /* Initialize blkCnt with number of samples */ tapCnt = (numStages - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { gcurr = *px1++; /* Process sample for last taps */ fnext = fcurr - (((q31_t) gcurr * (*pk)) >> 15); fnext = __SSAT(fnext, 16); gnext = (((q31_t) fnext * (*pk++)) >> 15) + gcurr; gnext = __SSAT(gnext, 16); /* Output samples for last taps */ acc += (q31_t) (((q31_t) gnext * (*pv++))); *px2++ = (q15_t) gnext; fcurr = fnext; /* Decrement loop counter */ tapCnt--; } /* y(n) += g0(n) * v0 */ acc += (q31_t) (((q31_t) fnext * (*pv++))); out = (q15_t) __SSAT(acc >> 15, 16); *px2++ = (q15_t) fnext; /* write out into pDst */ *pDst++ = out; /* Advance the state pointer by 4 to process the next group of 4 samples */ pState = pState + 1U; /* Decrement loop counter */ blkCnt--; } /* Processing is complete. Now copy last S->numStages samples to start of the buffer for the preperation of next frame process */ /* Points to the start of the state buffer */ pStateCur = &S->pState[0]; pState = &S->pState[blockSize]; /* copy data */ #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = numStages >> 2U; while (tapCnt > 0U) { write_q15x2_ia (&pStateCur, read_q15x2_ia (&pState)); write_q15x2_ia (&pStateCur, read_q15x2_ia (&pState)); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numStages % 0x4U; #else /* Initialize blkCnt with number of samples */ tapCnt = (numStages - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } #else /* #if defined (ARM_MATH_DSP) */ /* Sample processing */ while (blkCnt > 0U) { /* Read Sample from input buffer */ /* fN(n) = x(n) */ fcurr = *pSrc++; /* Initialize Ladder coeff pointer */ pv = &S->pvCoeffs[0]; /* Initialize Reflection coeff pointer */ pk = &S->pkCoeffs[0]; /* Initialize state read pointer */ px1 = pState; /* Initialize state write pointer */ px2 = pState; /* Set accumulator to zero */ acc = 0; tapCnt = numStages; while (tapCnt > 0U) { gcurr = *px1++; /* Process sample */ /* fN-1(n) = fN(n) - kN * gN-1(n-1) */ fnext = fcurr - ((gcurr * (*pk)) >> 15); fnext = __SSAT(fnext, 16); /* gN(n) = kN * fN-1(n) + gN-1(n-1) */ gnext = ((fnext * (*pk++)) >> 15) + gcurr; gnext = __SSAT(gnext, 16); /* Output samples */ /* y(n) += gN(n) * vN */ acc += (q31_t) ((gnext * (*pv++))); /* write gN(n) into state for next sample processing */ *px2++ = (q15_t) gnext; /* Update f values for next coefficient processing */ fcurr = fnext; tapCnt--; } /* y(n) += g0(n) * v0 */ acc += (q31_t) ((fnext * (*pv++))); out = (q15_t) __SSAT(acc >> 15, 16); *px2++ = (q15_t) fnext; /* write out into pDst */ *pDst++ = out; /* Advance the state pointer by 1 to process the next group of samples */ pState = pState + 1U; /* Decrement loop counter */ blkCnt--; } /* Processing is complete. Now copy last S->numStages samples to start of the buffer for the preperation of next frame process */ /* Points to the start of the state buffer */ pStateCur = &S->pState[0]; pState = &S->pState[blockSize]; tapCnt = numStages; /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } #endif /* #if defined (ARM_MATH_DSP) */ } /** @} end of IIR_Lattice group */
11,689
C
28.445844
144
0.528617
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_interpolate_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_interpolate_q15.c * Description: Q15 FIR interpolation * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR_Interpolate @{ */ /** @brief Processing function for the Q15 FIR interpolator. @param[in] S points to an instance of the Q15 FIR interpolator structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior The function is implemented using a 64-bit internal accumulator. Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. Lastly, the accumulator is saturated to yield a result in 1.15 format. */ void arm_fir_interpolate_q15( const arm_fir_interpolate_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { #if (1) //#if !defined(ARM_MATH_CM0_FAMILY) q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCur; /* Points to the current sample of the state */ q15_t *ptr1; /* Temporary pointer for state buffer */ const q15_t *ptr2; /* Temporary pointer for coefficient buffer */ q63_t sum0; /* Accumulators */ uint32_t i, blkCnt, tapCnt; /* Loop counters */ uint32_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */ uint32_t j; #if defined (ARM_MATH_LOOPUNROLL) q63_t acc0, acc1, acc2, acc3; q15_t x0, x1, x2, x3; q15_t c0, c1, c2, c3; #endif /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCur points to the location where the new input data should be written */ pStateCur = S->pState + (phaseLen - 1U); #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ blkCnt = blockSize >> 2U; while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCur++ = *pSrc++; *pStateCur++ = *pSrc++; *pStateCur++ = *pSrc++; *pStateCur++ = *pSrc++; /* Address modifier index of coefficient buffer */ j = 1U; /* Loop over the Interpolation factor. */ i = (S->L); while (i > 0U) { /* Set accumulator to zero */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (S->L - j); /* Loop over the polyPhase length. Unroll by a factor of 4. Repeat until we've computed numTaps-(4*S->L) coefficients. */ tapCnt = phaseLen >> 2U; x0 = *(ptr1++); x1 = *(ptr1++); x2 = *(ptr1++); while (tapCnt > 0U) { /* Read the input sample */ x3 = *(ptr1++); /* Read the coefficient */ c0 = *(ptr2); /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; acc1 += (q63_t) x1 * c0; acc2 += (q63_t) x2 * c0; acc3 += (q63_t) x3 * c0; /* Read the coefficient */ c1 = *(ptr2 + S->L); /* Read the input sample */ x0 = *(ptr1++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x1 * c1; acc1 += (q63_t) x2 * c1; acc2 += (q63_t) x3 * c1; acc3 += (q63_t) x0 * c1; /* Read the coefficient */ c2 = *(ptr2 + S->L * 2); /* Read the input sample */ x1 = *(ptr1++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x2 * c2; acc1 += (q63_t) x3 * c2; acc2 += (q63_t) x0 * c2; acc3 += (q63_t) x1 * c2; /* Read the coefficient */ c3 = *(ptr2 + S->L * 3); /* Read the input sample */ x2 = *(ptr1++); /* Perform the multiply-accumulate */ acc0 += (q63_t) x3 * c3; acc1 += (q63_t) x0 * c3; acc2 += (q63_t) x1 * c3; acc3 += (q63_t) x2 * c3; /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += 4 * S->L; /* Decrement loop counter */ tapCnt--; } /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ tapCnt = phaseLen % 0x4U; while (tapCnt > 0U) { /* Read the input sample */ x3 = *(ptr1++); /* Read the coefficient */ c0 = *(ptr2); /* Perform the multiply-accumulate */ acc0 += (q63_t) x0 * c0; acc1 += (q63_t) x1 * c0; acc2 += (q63_t) x2 * c0; acc3 += (q63_t) x3 * c0; /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* update states for next sample processing */ x0 = x1; x1 = x2; x2 = x3; /* Decrement loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *(pDst ) = (q15_t) (__SSAT((acc0 >> 15), 16)); *(pDst + S->L) = (q15_t) (__SSAT((acc1 >> 15), 16)); *(pDst + 2 * S->L) = (q15_t) (__SSAT((acc2 >> 15), 16)); *(pDst + 3 * S->L) = (q15_t) (__SSAT((acc3 >> 15), 16)); pDst++; /* Increment the address modifier index of coefficient buffer */ j++; /* Decrement loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 4; pDst += S->L * 3; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = blockSize % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCur++ = *pSrc++; /* Address modifier index of coefficient buffer */ j = 1U; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum0 = 0; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (S->L - j); /* Loop over the polyPhase length. Repeat until we've computed numTaps-(4*S->L) coefficients. */ #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ tapCnt = phaseLen >> 2U; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum0 += (q63_t) *ptr1++ * *ptr2; /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; sum0 += (q63_t) *ptr1++ * *ptr2; ptr2 += S->L; sum0 += (q63_t) *ptr1++ * *ptr2; ptr2 += S->L; sum0 += (q63_t) *ptr1++ * *ptr2; ptr2 += S->L; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining outputs */ tapCnt = phaseLen % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = phaseLen; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum0 += (q63_t) *ptr1++ * *ptr2; /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Decrement loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q15_t) (__SSAT((sum0 >> 15), 16)); /* Increment the address modifier index of coefficient buffer */ j++; /* Decrement the loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. Now copy the last phaseLen - 1 samples to the satrt of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCur = S->pState; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ tapCnt = (phaseLen - 1U) >> 2U; /* copy data */ while (tapCnt > 0U) { write_q15x2_ia (&pStateCur, read_q15x2_ia (&pState)); write_q15x2_ia (&pStateCur, read_q15x2_ia (&pState)); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining outputs */ tapCnt = (phaseLen - 1U) % 0x04U; #else /* Initialize tapCnt with number of samples */ tapCnt = (phaseLen - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } #else /* alternate version for CM0_FAMILY */ q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCur; /* Points to the current sample of the state */ q15_t *ptr1; /* Temporary pointer for state buffer */ const q15_t *ptr2; /* Temporary pointer for coefficient buffer */ q63_t sum0; /* Accumulators */ uint32_t i, blkCnt, tapCnt; /* Loop counters */ uint32_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */ /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCur points to the location where the new input data should be written */ pStateCur = S->pState + (phaseLen - 1U); /* Total number of intput samples */ blkCnt = blockSize; /* Loop over the blockSize. */ while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCur++ = *pSrc++; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum0 = 0; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (i - 1U); /* Loop over the polyPhase length */ tapCnt = phaseLen; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum0 += ((q63_t) *ptr1++ * *ptr2); /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Decrement the loop counter */ tapCnt--; } /* Store the result after converting to 1.15 format in the destination buffer. */ *pDst++ = (q15_t) (__SSAT((sum0 >> 15), 16)); /* Decrement loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last phaseLen - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCur = S->pState; tapCnt = phaseLen - 1U; /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } #endif /* #if !defined(ARM_MATH_CM0_FAMILY) */ } /** @} end of FIR_Interpolate group */
13,670
C
27.48125
144
0.54989
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_fast_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_fast_q15.c * Description: Q15 Fast FIR filter processing function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR @{ */ /** @brief Processing function for the Q15 FIR filter (fast version). @param[in] S points to an instance of the Q15 FIR filter structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior This fast version uses a 32-bit accumulator with 2.30 format. The accumulator maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around and distorts the result. In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits. The 2.30 accumulator is then truncated to 2.15 format and saturated to yield the 1.15 result. @remark Refer to \ref arm_fir_q15() for a slower implementation of this function which uses 64-bit accumulation to avoid wrap around distortion. Both the slow and the fast versions use the same instance structure. Use function \ref arm_fir_init_q15() to initialize the filter structure. */ void arm_fir_fast_q15( const arm_fir_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ q15_t *px; /* Temporary pointer for state buffer */ const q15_t *pb; /* Temporary pointer for coefficient buffer */ q31_t acc0; /* Accumulators */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t tapCnt, blkCnt; /* Loop counters */ #if defined (ARM_MATH_LOOPUNROLL) q31_t acc1, acc2, acc3; /* Accumulators */ q31_t x0, x1, x2, c0; /* Temporary variables to hold state and coefficient values */ #endif /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 output values simultaneously. * The variables acc0 ... acc3 hold output values that are being computed: * * 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] * 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] * 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] * 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] */ blkCnt = blockSize >> 2U; while (blkCnt > 0U) { /* Copy 4 new input samples into the state buffer. */ *pStateCurnt++ = *pSrc++; *pStateCurnt++ = *pSrc++; *pStateCurnt++ = *pSrc++; *pStateCurnt++ = *pSrc++; /* Set all accumulators to zero */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* Typecast q15_t pointer to q31_t pointer for state reading in q31_t */ px = pState; /* Typecast q15_t pointer to q31_t pointer for coefficient reading in q31_t */ pb = pCoeffs; /* Read the first two samples from the state buffer: x[n-N], x[n-N-1] */ x0 = read_q15x2_ia (&px); /* Read the third and forth samples from the state buffer: x[n-N-2], x[n-N-3] */ x2 = read_q15x2_ia (&px); /* Loop over the number of taps. Unroll by a factor of 4. Repeat until we've computed numTaps-(numTaps%4) coefficients. */ tapCnt = numTaps >> 2U; while (tapCnt > 0U) { /* Read the first two coefficients using SIMD: b[N] and b[N-1] coefficients */ c0 = read_q15x2_ia ((q15_t **) &pb); /* acc0 += b[N] * x[n-N] + b[N-1] * x[n-N-1] */ acc0 = __SMLAD(x0, c0, acc0); /* acc2 += b[N] * x[n-N-2] + b[N-1] * x[n-N-3] */ acc2 = __SMLAD(x2, c0, acc2); /* pack x[n-N-1] and x[n-N-2] */ #ifndef ARM_MATH_BIG_ENDIAN x1 = __PKHBT(x2, x0, 0); #else x1 = __PKHBT(x0, x2, 0); #endif /* Read state x[n-N-4], x[n-N-5] */ x0 = read_q15x2_ia (&px); /* acc1 += b[N] * x[n-N-1] + b[N-1] * x[n-N-2] */ acc1 = __SMLADX(x1, c0, acc1); /* pack x[n-N-3] and x[n-N-4] */ #ifndef ARM_MATH_BIG_ENDIAN x1 = __PKHBT(x0, x2, 0); #else x1 = __PKHBT(x2, x0, 0); #endif /* acc3 += b[N] * x[n-N-3] + b[N-1] * x[n-N-4] */ acc3 = __SMLADX(x1, c0, acc3); /* Read coefficients b[N-2], b[N-3] */ c0 = read_q15x2_ia ((q15_t **) &pb); /* acc0 += b[N-2] * x[n-N-2] + b[N-3] * x[n-N-3] */ acc0 = __SMLAD(x2, c0, acc0); /* Read state x[n-N-6], x[n-N-7] with offset */ x2 = read_q15x2_ia (&px); /* acc2 += b[N-2] * x[n-N-4] + b[N-3] * x[n-N-5] */ acc2 = __SMLAD(x0, c0, acc2); /* acc1 += b[N-2] * x[n-N-3] + b[N-3] * x[n-N-4] */ acc1 = __SMLADX(x1, c0, acc1); /* pack x[n-N-5] and x[n-N-6] */ #ifndef ARM_MATH_BIG_ENDIAN x1 = __PKHBT(x2, x0, 0); #else x1 = __PKHBT(x0, x2, 0); #endif /* acc3 += b[N-2] * x[n-N-5] + b[N-3] * x[n-N-6] */ acc3 = __SMLADX(x1, c0, acc3); /* Decrement tap count */ tapCnt--; } /* If the filter length is not a multiple of 4, compute the remaining filter taps. This is always be 2 taps since the filter length is even. */ if ((numTaps & 0x3U) != 0U) { /* Read last two coefficients */ c0 = read_q15x2_ia ((q15_t **) &pb); /* Perform the multiply-accumulates */ acc0 = __SMLAD(x0, c0, acc0); acc2 = __SMLAD(x2, c0, acc2); /* pack state variables */ #ifndef ARM_MATH_BIG_ENDIAN x1 = __PKHBT(x2, x0, 0); #else x1 = __PKHBT(x0, x2, 0); #endif /* Read last state variables */ x0 = read_q15x2 (px); /* Perform the multiply-accumulates */ acc1 = __SMLADX(x1, c0, acc1); /* pack state variables */ #ifndef ARM_MATH_BIG_ENDIAN x1 = __PKHBT(x0, x2, 0); #else x1 = __PKHBT(x2, x0, 0); #endif /* Perform the multiply-accumulates */ acc3 = __SMLADX(x1, c0, acc3); } /* The results in the 4 accumulators are in 2.30 format. Convert to 1.15 with saturation. Then store the 4 outputs in the destination buffer. */ #ifndef ARM_MATH_BIG_ENDIAN write_q15x2_ia (&pDst, __PKHBT(__SSAT((acc0 >> 15), 16), __SSAT((acc1 >> 15), 16), 16)); write_q15x2_ia (&pDst, __PKHBT(__SSAT((acc2 >> 15), 16), __SSAT((acc3 >> 15), 16), 16)); #else write_q15x2_ia (&pDst, __PKHBT(__SSAT((acc1 >> 15), 16), __SSAT((acc0 >> 15), 16), 16)); write_q15x2_ia (&pDst, __PKHBT(__SSAT((acc3 >> 15), 16), __SSAT((acc2 >> 15), 16), 16)); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* Advance the state pointer by 4 to process the next group of 4 samples */ pState = pState + 4U; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining output samples */ blkCnt = blockSize % 0x4U; #else /* Initialize blkCnt with number of taps */ blkCnt = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Copy two samples into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc0 = 0; /* Use SIMD to hold states and coefficients */ px = pState; pb = pCoeffs; tapCnt = numTaps >> 1U; do { acc0 += (q31_t) *px++ * *pb++; acc0 += (q31_t) *px++ * *pb++; tapCnt--; } while (tapCnt > 0U); /* The result is in 2.30 format. Convert to 1.15 with saturation. Then store the output in the destination buffer. */ *pDst++ = (q15_t) (__SSAT((acc0 >> 15), 16)); /* Advance state pointer by 1 for the next sample */ pState = pState + 1U; /* Decrement loop counter */ blkCnt--; } /* Processing is complete. Now copy the last numTaps - 1 samples to the start of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time */ tapCnt = (numTaps - 1U) >> 2U; /* Copy data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; /* Decrement loop counter */ tapCnt--; } /* Calculate remaining number of copies */ tapCnt = (numTaps - 1U) % 0x4U; #else /* Initialize tapCnt with number of taps */ tapCnt = (numTaps - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Copy remaining data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement loop counter */ tapCnt--; } } /** @} end of FIR group */
10,587
C
30.795796
225
0.558799
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_biquad_cascade_df1_init_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_biquad_cascade_df1_init_q15.c * Description: Q15 Biquad cascade DirectFormI(DF1) filter initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup BiquadCascadeDF1 @{ */ /** @brief Initialization function for the Q15 Biquad cascade filter. @param[in,out] S points to an instance of the Q15 Biquad cascade structure. @param[in] numStages number of 2nd order stages in the filter. @param[in] pCoeffs points to the filter coefficients. @param[in] pState points to the state buffer. @param[in] postShift Shift to be applied to the accumulator result. Varies according to the coefficients format @return none @par Coefficient and State Ordering The coefficients are stored in the array <code>pCoeffs</code> in the following order: <pre> {b10, 0, b11, b12, a11, a12, b20, 0, b21, b22, a21, a22, ...} </pre> @par where <code>b1x</code> and <code>a1x</code> are the coefficients for the first stage, <code>b2x</code> and <code>a2x</code> are the coefficients for the second stage, and so on. The <code>pCoeffs</code> array contains a total of <code>6*numStages</code> values. The zero coefficient between <code>b1</code> and <code>b2</code> facilities use of 16-bit SIMD instructions on the Cortex-M4. @par The state variables are stored in the array <code>pState</code>. Each Biquad stage has 4 state variables <code>x[n-1], x[n-2], y[n-1],</code> and <code>y[n-2]</code>. The state variables are arranged in the <code>pState</code> array as: <pre> {x[n-1], x[n-2], y[n-1], y[n-2]} </pre> The 4 state variables for stage 1 are first, then the 4 state variables for stage 2, and so on. The state array has a total length of <code>4*numStages</code> values. The state variables are updated after each block of data is processed; the coefficients are untouched. */ void arm_biquad_cascade_df1_init_q15( arm_biquad_casd_df1_inst_q15 * S, uint8_t numStages, const q15_t * pCoeffs, q15_t * pState, int8_t postShift) { /* Assign filter stages */ S->numStages = numStages; /* Assign postShift to be applied to the output */ S->postShift = postShift; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer and size is always 4 * numStages */ memset(pState, 0, (4U * (uint32_t) numStages) * sizeof(q15_t)); /* Assign state pointer */ S->pState = pState; } /** @} end of BiquadCascadeDF1 group */
3,701
C
37.164948
145
0.619292
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_conv_partial_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_conv_partial_q31.c * Description: Partial convolution of Q31 sequences * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup PartialConv @{ */ /** @brief Partial convolution of Q31 sequences. @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the location where the output result is written @param[in] firstIndex is the first output sample to start with @param[in] numPoints is the number of output points to be computed @return execution status - \ref ARM_MATH_SUCCESS : Operation successful - \ref ARM_MATH_ARGUMENT_ERROR : requested subset is not in the range [0 srcALen+srcBLen-2] @remark Refer to \ref arm_conv_partial_fast_q31() for a faster but less precise implementation of this function. */ arm_status arm_conv_partial_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints) { #if (1) //#if !defined(ARM_MATH_CM0_FAMILY) const q31_t *pIn1; /* InputA pointer */ const q31_t *pIn2; /* InputB pointer */ q31_t *pOut = pDst; /* Output pointer */ const q31_t *px; /* Intermediate inputA pointer */ const q31_t *py; /* Intermediate inputB pointer */ const q31_t *pSrc1, *pSrc2; /* Intermediate pointers */ q63_t sum; /* Accumulator */ uint32_t j, k, count, blkCnt, check; int32_t blockSize1, blockSize2, blockSize3; /* Loop counters */ arm_status status; /* Status of Partial convolution */ #if defined (ARM_MATH_LOOPUNROLL) q63_t acc0, acc1, acc2; /* Accumulator */ q31_t x0, x1, x2, c0; /* Temporary variables */ #endif /* Check for range of output samples to be calculated */ if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) { /* Set status as ARM_MATH_ARGUMENT_ERROR */ status = ARM_MATH_ARGUMENT_ERROR; } else { /* The algorithm implementation is based on the lengths of the inputs. */ /* srcB is always made to slide across srcA. */ /* So srcBLen is always considered as shorter or equal to srcALen */ if (srcALen >= srcBLen) { /* Initialization of inputA pointer */ pIn1 = pSrcA; /* Initialization of inputB pointer */ pIn2 = pSrcB; } else { /* Initialization of inputA pointer */ pIn1 = pSrcB; /* Initialization of inputB pointer */ pIn2 = pSrcA; /* srcBLen is always considered as shorter or equal to srcALen */ j = srcBLen; srcBLen = srcALen; srcALen = j; } /* Conditions to check which loopCounter holds * the first and last indices of the output samples to be calculated. */ check = firstIndex + numPoints; blockSize3 = ((int32_t)check > (int32_t)srcALen) ? (int32_t)check - (int32_t)srcALen : 0; blockSize3 = ((int32_t)firstIndex > (int32_t)srcALen - 1) ? blockSize3 - (int32_t)firstIndex + (int32_t)srcALen : blockSize3; blockSize1 = ((int32_t) srcBLen - 1) - (int32_t) firstIndex; blockSize1 = (blockSize1 > 0) ? ((check > (srcBLen - 1U)) ? blockSize1 : (int32_t) numPoints) : 0; blockSize2 = (int32_t) check - ((blockSize3 + blockSize1) + (int32_t) firstIndex); blockSize2 = (blockSize2 > 0) ? blockSize2 : 0; /* 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] */ /* The function is internally * divided into three stages according to the number of multiplications that has to be * taken place between inputA samples and inputB samples. In the first stage of the * algorithm, the multiplications increase by one for every iteration. * In the second stage of the algorithm, srcBLen number of multiplications are done. * In the third stage of the algorithm, the multiplications decrease by one * for every iteration. */ /* Set the output pointer to point to the firstIndex * of the output sample to be calculated. */ pOut = pDst + firstIndex; /* -------------------------- * Initializations of stage1 * -------------------------*/ /* sum = x[0] * y[0] * sum = x[0] * y[1] + x[1] * y[0] * .... * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] */ /* In this stage the MAC operations are increased by 1 for every iteration. The count variable holds the number of MAC operations performed. Since the partial convolution starts from firstIndex Number of Macs to be performed is firstIndex + 1 */ count = 1U + firstIndex; /* Working pointer of inputA */ px = pIn1; /* Working pointer of inputB */ pSrc2 = pIn2 + firstIndex; py = pSrc2; /* ------------------------ * Stage1 process * ----------------------*/ /* The first stage starts here */ while (blockSize1 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = count >> 2U; while (k > 0U) { /* x[0] * y[srcBLen - 1] */ sum += (q63_t) *px++ * (*py--); /* x[1] * y[srcBLen - 2] */ sum += (q63_t) *px++ * (*py--); /* x[2] * y[srcBLen - 3] */ sum += (q63_t) *px++ * (*py--); /* x[3] * y[srcBLen - 4] */ sum += (q63_t) *px++ * (*py--); /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = count % 0x4U; #else /* Initialize k with number of samples */ k = count; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += (q63_t) *px++ * (*py--); /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Update the inputA and inputB pointers for next MAC calculation */ py = ++pSrc2; px = pIn1; /* Increment MAC count */ count++; /* Decrement loop counter */ blockSize1--; } /* -------------------------- * Initializations of stage2 * ------------------------*/ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] * .... * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] */ /* Working pointer of inputA */ if ((int32_t)firstIndex - (int32_t)srcBLen + 1 > 0) { pSrc1 = pIn1 + firstIndex - srcBLen + 1; } else { pSrc1 = pIn1; } px = pSrc1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* count is index by which the pointer pIn1 to be incremented */ count = 0U; /* ------------------- * Stage2 process * ------------------*/ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. * So, to loop unroll over blockSize2, * srcBLen should be greater than or equal to 4 */ if (srcBLen >= 4U) { #if defined (ARM_MATH_LOOPUNROLL) /* Loop unroll over blkCnt */ blkCnt = blockSize2 / 3; while (blkCnt > 0U) { /* Set all accumulators to zero */ acc0 = 0; acc1 = 0; acc2 = 0; /* read x[0], x[1] samples */ x0 = *px++; x1 = *px++; /* Apply loop unrolling and compute 3 MACs simultaneously. */ k = srcBLen / 3; /* First part of the processing with loop unrolling. Compute 3 MACs at a time. ** a second loop below computes MACs for the remaining 1 to 2 samples. */ do { /* Read y[srcBLen - 1] sample */ c0 = *(py); /* Read x[2] sample */ x2 = *(px); /* Perform the multiply-accumulate */ /* acc0 += x[0] * y[srcBLen - 1] */ acc0 += (q63_t) x0 * c0; /* acc1 += x[1] * y[srcBLen - 1] */ acc1 += (q63_t) x1 * c0; /* acc2 += x[2] * y[srcBLen - 1] */ acc2 += (q63_t) x2 * c0; /* Read y[srcBLen - 2] sample */ c0 = *(py - 1U); /* Read x[3] sample */ x0 = *(px + 1U); /* Perform the multiply-accumulate */ /* acc0 += x[1] * y[srcBLen - 2] */ acc0 += (q63_t) x1 * c0; /* acc1 += x[2] * y[srcBLen - 2] */ acc1 += (q63_t) x2 * c0; /* acc2 += x[3] * y[srcBLen - 2] */ acc2 += (q63_t) x0 * c0; /* Read y[srcBLen - 3] sample */ c0 = *(py - 2U); /* Read x[4] sample */ x1 = *(px + 2U); /* Perform the multiply-accumulate */ /* acc0 += x[2] * y[srcBLen - 3] */ acc0 += (q63_t) x2 * c0; /* acc1 += x[3] * y[srcBLen - 2] */ acc1 += (q63_t) x0 * c0; /* acc2 += x[4] * y[srcBLen - 2] */ acc2 += (q63_t) x1 * c0; px += 3U; py -= 3U; } while (--k); /* If the srcBLen is not a multiple of 3, compute any remaining MACs here. ** No loop unrolling is used. */ k = srcBLen - (3 * (srcBLen / 3)); while (k > 0U) { /* Read y[srcBLen - 5] sample */ c0 = *py--; /* Read x[7] sample */ x2 = *px++; /* Perform the multiply-accumulates */ /* acc0 += x[4] * y[srcBLen - 5] */ acc0 += (q63_t) x0 * c0; /* acc1 += x[5] * y[srcBLen - 5] */ acc1 += (q63_t) x1 * c0; /* acc2 += x[6] * y[srcBLen - 5] */ acc2 += (q63_t) x2 * c0; /* Reuse the present samples for the next MAC */ x0 = x1; x1 = x2; /* Decrement the loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (acc0 >> 31); *pOut++ = (q31_t) (acc1 >> 31); *pOut++ = (q31_t) (acc2 >> 31); /* Increment the pointer pIn1 index, count by 3 */ count += 3U; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = blockSize2 - 3 * (blockSize2 / 3); #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize2; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = srcBLen >> 2U; while (k > 0U) { /* Perform the multiply-accumulates */ sum += (q63_t) *px++ * (*py--); sum += (q63_t) *px++ * (*py--); sum += (q63_t) *px++ * (*py--); sum += (q63_t) *px++ * (*py--); /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = srcBLen % 0x4U; #else /* Initialize blkCnt with number of samples */ k = srcBLen; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Increment MAC count */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } } else { /* If the srcBLen is not a multiple of 4, * the blockSize2 loop cannot be unrolled by 4 */ blkCnt = (uint32_t) blockSize2; while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; /* srcBLen number of MACS should be performed */ k = srcBLen; while (k > 0U) { /* Perform the multiply-accumulate */ sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Increment the MAC count */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement the loop counter */ blkCnt--; } } /* -------------------------- * Initializations of stage3 * -------------------------*/ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] * .... * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] * sum += x[srcALen-1] * y[srcBLen-1] */ /* In this stage the MAC operations are decreased by 1 for every iteration. The blockSize3 variable holds the number of MAC operations performed */ count = srcBLen - 1U; /* Working pointer of inputA */ pSrc1 = (pIn1 + srcALen) - (srcBLen - 1U); px = pSrc1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* ------------------- * Stage3 process * ------------------*/ while (blockSize3 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = count >> 2U; while (k > 0U) { /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */ sum += (q63_t) *px++ * *py--; /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */ sum += (q63_t) *px++ * *py--; /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */ sum += (q63_t) *px++ * *py--; /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */ sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = count % 0x4U; #else /* Initialize blkCnt with number of samples */ k = count; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ /* sum += x[srcALen-1] * y[srcBLen-1] */ sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Update the inputA and inputB pointers for next MAC calculation */ px = ++pSrc1; py = pSrc2; /* Decrement MAC count */ count--; /* Decrement the loop counter */ blockSize3--; } /* Set status as ARM_MATH_SUCCESS */ status = ARM_MATH_SUCCESS; } /* Return to application */ return (status); #else /* alternate version for CM0_FAMILY */ const q31_t *pIn1 = pSrcA; /* InputA pointer */ const q31_t *pIn2 = pSrcB; /* InputB pointer */ q63_t sum; /* Accumulator */ uint32_t i, j; /* Loop counters */ arm_status status; /* Status of Partial convolution */ /* Check for range of output samples to be calculated */ if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) { /* Set status as ARM_MATH_ARGUMENT_ERROR */ status = ARM_MATH_ARGUMENT_ERROR; } else { /* Loop to calculate convolution for output length number of values */ for (i = firstIndex; i <= (firstIndex + numPoints - 1); i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if (((i - j) < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += ((q63_t) pIn1[j] * pIn2[i - j]); } } /* Store the output in the destination buffer */ pDst[i] = (q31_t) (sum >> 31U); } /* Set status as ARM_MATH_SUCCESS */ status = ARM_MATH_SUCCESS; } /* Return to application */ return (status); #endif /* #if !defined(ARM_MATH_CM0_FAMILY) */ } /** @} end of PartialConv group */
18,537
C
28.193701
129
0.505799
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_conv_partial_q7.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_conv_partial_q7.c * Description: Partial convolution of Q7 sequences * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup PartialConv @{ */ /** @brief Partial convolution of Q7 sequences. @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the location where the output result is written @param[in] firstIndex is the first output sample to start with @param[in] numPoints is the number of output points to be computed @return execution status - \ref ARM_MATH_SUCCESS : Operation successful - \ref ARM_MATH_ARGUMENT_ERROR : requested subset is not in the range [0 srcALen+srcBLen-2] @remark Refer to \ref arm_conv_partial_opt_q7() for a faster implementation of this function. */ arm_status arm_conv_partial_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, uint32_t firstIndex, uint32_t numPoints) { #if (1) //#if !defined(ARM_MATH_CM0_FAMILY) const q7_t *pIn1; /* InputA pointer */ const q7_t *pIn2; /* InputB pointer */ q7_t *pOut = pDst; /* Output pointer */ const q7_t *px; /* Intermediate inputA pointer */ const q7_t *py; /* Intermediate inputB pointer */ const q7_t *pSrc1, *pSrc2; /* Intermediate pointers */ q31_t sum; /* Accumulator */ uint32_t j, k, count, blkCnt, check; /* Loop counters */ int32_t blockSize1, blockSize2, blockSize3; /* Loop counters */ arm_status status; /* Status of Partial convolution */ #if defined (ARM_MATH_LOOPUNROLL) q31_t acc0, acc1, acc2, acc3; /* Accumulator */ q31_t input1, input2; /* Temporary input variables */ q15_t in1, in2; /* Temporary input variables */ q7_t x0, x1, x2, x3, c0, c1; /* Temporary variables to hold state and coefficient values */ #endif /* Check for range of output samples to be calculated */ if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) { /* Set status as ARM_MATH_ARGUMENT_ERROR */ status = ARM_MATH_ARGUMENT_ERROR; } else { /* The algorithm implementation is based on the lengths of the inputs. */ /* srcB is always made to slide across srcA. */ /* So srcBLen is always considered as shorter or equal to srcALen */ if (srcALen >= srcBLen) { /* Initialization of inputA pointer */ pIn1 = pSrcA; /* Initialization of inputB pointer */ pIn2 = pSrcB; } else { /* Initialization of inputA pointer */ pIn1 = pSrcB; /* Initialization of inputB pointer */ pIn2 = pSrcA; /* srcBLen is always considered as shorter or equal to srcALen */ j = srcBLen; srcBLen = srcALen; srcALen = j; } /* Conditions to check which loopCounter holds * the first and last indices of the output samples to be calculated. */ check = firstIndex + numPoints; blockSize3 = ((int32_t)check > (int32_t)srcALen) ? (int32_t)check - (int32_t)srcALen : 0; blockSize3 = ((int32_t)firstIndex > (int32_t)srcALen - 1) ? blockSize3 - (int32_t)firstIndex + (int32_t)srcALen : blockSize3; blockSize1 = ((int32_t) srcBLen - 1) - (int32_t) firstIndex; blockSize1 = (blockSize1 > 0) ? ((check > (srcBLen - 1U)) ? blockSize1 : (int32_t) numPoints) : 0; blockSize2 = (int32_t) check - ((blockSize3 + blockSize1) + (int32_t) firstIndex); blockSize2 = (blockSize2 > 0) ? blockSize2 : 0; /* 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] */ /* The function is internally * divided into three stages according to the number of multiplications that has to be * taken place between inputA samples and inputB samples. In the first stage of the * algorithm, the multiplications increase by one for every iteration. * In the second stage of the algorithm, srcBLen number of multiplications are done. * In the third stage of the algorithm, the multiplications decrease by one * for every iteration. */ /* Set the output pointer to point to the firstIndex * of the output sample to be calculated. */ pOut = pDst + firstIndex; /* -------------------------- * Initializations of stage1 * -------------------------*/ /* sum = x[0] * y[0] * sum = x[0] * y[1] + x[1] * y[0] * .... * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] */ /* In this stage the MAC operations are increased by 1 for every iteration. The count variable holds the number of MAC operations performed. Since the partial convolution starts from firstIndex Number of Macs to be performed is firstIndex + 1 */ count = 1U + firstIndex; /* Working pointer of inputA */ px = pIn1; /* Working pointer of inputB */ pSrc2 = pIn2 + firstIndex; py = pSrc2; /* ------------------------ * Stage1 process * ----------------------*/ /* The first stage starts here */ while (blockSize1 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = count >> 2U; while (k > 0U) { /* x[0] , x[1] */ in1 = (q15_t) *px++; in2 = (q15_t) *px++; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* y[srcBLen - 1] , y[srcBLen - 2] */ in1 = (q15_t) *py--; in2 = (q15_t) *py--; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* x[0] * y[srcBLen - 1] */ /* x[1] * y[srcBLen - 2] */ sum = __SMLAD(input1, input2, sum); /* x[2] , x[3] */ in1 = (q15_t) *px++; in2 = (q15_t) *px++; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* y[srcBLen - 3] , y[srcBLen - 4] */ in1 = (q15_t) *py--; in2 = (q15_t) *py--; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* x[2] * y[srcBLen - 3] */ /* x[3] * y[srcBLen - 4] */ sum = __SMLAD(input1, input2, sum); /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = count % 0x4U; #else /* Initialize k with number of samples */ k = count; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += ((q31_t) * px++ * *py--); /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q7_t) (__SSAT(sum >> 7, 8)); /* Update the inputA and inputB pointers for next MAC calculation */ py = ++pSrc2; px = pIn1; /* Increment MAC count */ count++; /* Decrement loop counter */ blockSize1--; } /* -------------------------- * Initializations of stage2 * ------------------------*/ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] * .... * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] */ /* Working pointer of inputA */ if ((int32_t)firstIndex - (int32_t)srcBLen + 1 > 0) { pSrc1 = pIn1 + firstIndex - srcBLen + 1; } else { pSrc1 = pIn1; } px = pSrc1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* count is the index by which the pointer pIn1 to be incremented */ count = 0U; /* ------------------- * Stage2 process * ------------------*/ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. * So, to loop unroll over blockSize2, * srcBLen should be greater than or equal to 4 */ if (srcBLen >= 4U) { #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ blkCnt = ((uint32_t) blockSize2 >> 2U); while (blkCnt > 0U) { /* Set all accumulators to zero */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* read x[0], x[1], x[2] samples */ x0 = *px++; x1 = *px++; x2 = *px++; /* Apply loop unrolling and compute 4 MACs simultaneously. */ k = srcBLen >> 2U; /* First part of the processing with loop unrolling. Compute 4 MACs at a time. ** a second loop below computes MACs for the remaining 1 to 3 samples. */ do { /* Read y[srcBLen - 1] sample */ c0 = *py--; /* Read y[srcBLen - 2] sample */ c1 = *py--; /* Read x[3] sample */ x3 = *px++; /* x[0] and x[1] are packed */ in1 = (q15_t) x0; in2 = (q15_t) x1; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* y[srcBLen - 1] and y[srcBLen - 2] are packed */ in1 = (q15_t) c0; in2 = (q15_t) c1; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc0 += x[0] * y[srcBLen - 1] + x[1] * y[srcBLen - 2] */ acc0 = __SMLAD(input1, input2, acc0); /* x[1] and x[2] are packed */ in1 = (q15_t) x1; in2 = (q15_t) x2; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc1 += x[1] * y[srcBLen - 1] + x[2] * y[srcBLen - 2] */ acc1 = __SMLAD(input1, input2, acc1); /* x[2] and x[3] are packed */ in1 = (q15_t) x2; in2 = (q15_t) x3; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc2 += x[2] * y[srcBLen - 1] + x[3] * y[srcBLen - 2] */ acc2 = __SMLAD(input1, input2, acc2); /* Read x[4] sample */ x0 = *px++; /* x[3] and x[4] are packed */ in1 = (q15_t) x3; in2 = (q15_t) x0; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc3 += x[3] * y[srcBLen - 1] + x[4] * y[srcBLen - 2] */ acc3 = __SMLAD(input1, input2, acc3); /* Read y[srcBLen - 3] sample */ c0 = *py--; /* Read y[srcBLen - 4] sample */ c1 = *py--; /* Read x[5] sample */ x1 = *px++; /* x[2] and x[3] are packed */ in1 = (q15_t) x2; in2 = (q15_t) x3; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* y[srcBLen - 3] and y[srcBLen - 4] are packed */ in1 = (q15_t) c0; in2 = (q15_t) c1; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc0 += x[2] * y[srcBLen - 3] + x[3] * y[srcBLen - 4] */ acc0 = __SMLAD(input1, input2, acc0); /* x[3] and x[4] are packed */ in1 = (q15_t) x3; in2 = (q15_t) x0; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc1 += x[3] * y[srcBLen - 3] + x[4] * y[srcBLen - 4] */ acc1 = __SMLAD(input1, input2, acc1); /* x[4] and x[5] are packed */ in1 = (q15_t) x0; in2 = (q15_t) x1; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc2 += x[4] * y[srcBLen - 3] + x[5] * y[srcBLen - 4] */ acc2 = __SMLAD(input1, input2, acc2); /* Read x[6] sample */ x2 = *px++; /* x[5] and x[6] are packed */ in1 = (q15_t) x1; in2 = (q15_t) x2; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* acc3 += x[5] * y[srcBLen - 3] + x[6] * y[srcBLen - 4] */ acc3 = __SMLAD(input1, input2, acc3); } while (--k); /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. ** No loop unrolling is used. */ k = srcBLen % 0x4U; while (k > 0U) { /* Read y[srcBLen - 5] sample */ c0 = *py--; /* Read x[7] sample */ x3 = *px++; /* Perform the multiply-accumulates */ /* acc0 += x[4] * y[srcBLen - 5] */ acc0 += ((q31_t) x0 * c0); /* acc1 += x[5] * y[srcBLen - 5] */ acc1 += ((q31_t) x1 * c0); /* acc2 += x[6] * y[srcBLen - 5] */ acc2 += ((q31_t) x2 * c0); /* acc3 += x[7] * y[srcBLen - 5] */ acc3 += ((q31_t) x3 * c0); /* Reuse the present samples for the next MAC */ x0 = x1; x1 = x2; x2 = x3; /* Decrement the loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q7_t) (__SSAT(acc0 >> 7, 8)); *pOut++ = (q7_t) (__SSAT(acc1 >> 7, 8)); *pOut++ = (q7_t) (__SSAT(acc2 >> 7, 8)); *pOut++ = (q7_t) (__SSAT(acc3 >> 7, 8)); /* Increment the pointer pIn1 index, count by 4 */ count += 4U; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = (uint32_t) blockSize2 % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize2; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = srcBLen >> 2U; while (k > 0U) { /* Reading two inputs of SrcA buffer and packing */ in1 = (q15_t) *px++; in2 = (q15_t) *px++; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* Reading two inputs of SrcB buffer and packing */ in1 = (q15_t) *py--; in2 = (q15_t) *py--; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* Perform the multiply-accumulate */ sum = __SMLAD(input1, input2, sum); /* Reading two inputs of SrcA buffer and packing */ in1 = (q15_t) *px++; in2 = (q15_t) *px++; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* Reading two inputs of SrcB buffer and packing */ in1 = (q15_t) *py--; in2 = (q15_t) *py--; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* Perform the multiply-accumulate */ sum = __SMLAD(input1, input2, sum); /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = srcBLen % 0x4U; #else /* Initialize blkCnt with number of samples */ k = srcBLen; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += ((q31_t) * px++ * *py--); /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q7_t) (__SSAT(sum >> 7, 8)); /* Increment the pointer pIn1 index, count by 1 */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } } else { /* If the srcBLen is not a multiple of 4, * the blockSize2 loop cannot be unrolled by 4 */ blkCnt = (uint32_t) blockSize2; while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; /* srcBLen number of MACS should be performed */ k = srcBLen; while (k > 0U) { /* Perform the multiply-accumulate */ sum += ((q31_t) * px++ * *py--); /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q7_t) (__SSAT(sum >> 7, 8)); /* Increment the MAC count */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement the loop counter */ blkCnt--; } } /* -------------------------- * Initializations of stage3 * -------------------------*/ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] * .... * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] * sum += x[srcALen-1] * y[srcBLen-1] */ /* In this stage the MAC operations are decreased by 1 for every iteration. The count variable holds the number of MAC operations performed */ count = srcBLen - 1U; /* Working pointer of inputA */ pSrc1 = (pIn1 + srcALen) - (srcBLen - 1U); px = pSrc1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* ------------------- * Stage3 process * ------------------*/ while (blockSize3 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = count >> 2U; while (k > 0U) { /* Reading two inputs, x[srcALen - srcBLen + 1] and x[srcALen - srcBLen + 2] of SrcA buffer and packing */ in1 = (q15_t) *px++; in2 = (q15_t) *px++; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* Reading two inputs, y[srcBLen - 1] and y[srcBLen - 2] of SrcB buffer and packing */ in1 = (q15_t) *py--; in2 = (q15_t) *py--; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */ /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */ sum = __SMLAD(input1, input2, sum); /* Reading two inputs, x[srcALen - srcBLen + 3] and x[srcALen - srcBLen + 4] of SrcA buffer and packing */ in1 = (q15_t) *px++; in2 = (q15_t) *px++; input1 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* Reading two inputs, y[srcBLen - 3] and y[srcBLen - 4] of SrcB buffer and packing */ in1 = (q15_t) *py--; in2 = (q15_t) *py--; input2 = ((q31_t) in1 & 0x0000FFFF) | ((q31_t) in2 << 16); /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */ /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */ sum = __SMLAD(input1, input2, sum); /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = count % 0x4U; #else /* Initialize blkCnt with number of samples */ k = count; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulates */ /* sum += x[srcALen-1] * y[srcBLen-1] */ sum += ((q31_t) * px++ * *py--); /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q7_t) (__SSAT(sum >> 7, 8)); /* Update the inputA and inputB pointers for next MAC calculation */ px = ++pSrc1; py = pSrc2; /* Decrement MAC count */ count--; /* Decrement the loop counter */ blockSize3--; } /* Set status as ARM_MATH_SUCCESS */ status = ARM_MATH_SUCCESS; } /* Return to application */ return (status); #else /* alternate version for CM0_FAMILY */ const q7_t *pIn1 = pSrcA; /* InputA pointer */ const q7_t *pIn2 = pSrcB; /* InputB pointer */ q31_t sum; /* Accumulator */ uint32_t i, j; /* Loop counters */ arm_status status; /* Status of Partial convolution */ /* Check for range of output samples to be calculated */ if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) { /* Set status as ARM_MATH_ARGUMENT_ERROR */ status = ARM_MATH_ARGUMENT_ERROR; } else { /* Loop to calculate convolution for output length number of values */ for (i = firstIndex; i <= (firstIndex + numPoints - 1); i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if (((i - j) < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += ((q15_t) pIn1[j] * (pIn2[i - j])); } } /* Store the output in the destination buffer */ pDst[i] = (q7_t) __SSAT((sum >> 7U), 8U); } /* Set status as ARM_MATH_SUCCESS */ status = ARM_MATH_SUCCESS; } /* Return to application */ return (status); #endif /* #if !defined(ARM_MATH_CM0_FAMILY) */ } /** @} end of PartialConv group */
23,115
C
29.657825
129
0.496301
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_q31.c * Description: Q31 FIR filter processing function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR @{ */ /** @brief Processing function for Q31 FIR filter. @param[in] S points to an instance of the Q31 FIR filter structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior The function is implemented using an internal 64-bit accumulator. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around rather than clip. In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits. 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. @remark Refer to \ref arm_fir_fast_q31() for a faster but less precise implementation of this filter. */ void arm_fir_q31( const arm_fir_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ q31_t *px; /* Temporary pointer for state buffer */ const q31_t *pb; /* Temporary pointer for coefficient buffer */ q63_t acc0; /* Accumulator */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i, tapCnt, blkCnt; /* Loop counters */ #if defined (ARM_MATH_LOOPUNROLL) q63_t acc1, acc2; /* Accumulators */ q31_t x0, x1, x2; /* Temporary variables to hold state values */ q31_t c0; /* Temporary variable to hold coefficient value */ #endif /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 output values simultaneously. * The variables acc0 ... acc3 hold output values that are being computed: * * 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] * 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] * 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] * 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] */ blkCnt = blockSize / 3; while (blkCnt > 0U) { /* Copy 3 new input samples into the state buffer. */ *pStateCurnt++ = *pSrc++; *pStateCurnt++ = *pSrc++; *pStateCurnt++ = *pSrc++; /* Set all accumulators to zero */ acc0 = 0; acc1 = 0; acc2 = 0; /* Initialize state pointer */ px = pState; /* Initialize coefficient pointer */ pb = pCoeffs; /* Read the first 2 samples from the state buffer: x[n-numTaps], x[n-numTaps-1] */ x0 = *px++; x1 = *px++; /* Loop unrolling: process 3 taps at a time. */ tapCnt = numTaps / 3; while (tapCnt > 0U) { /* Read the b[numTaps] coefficient */ c0 = *pb; /* Read x[n-numTaps-2] sample */ x2 = *(px++); /* Perform the multiply-accumulates */ acc0 += ((q63_t) x0 * c0); acc1 += ((q63_t) x1 * c0); acc2 += ((q63_t) x2 * c0); /* Read the coefficient and state */ c0 = *(pb + 1U); x0 = *(px++); /* Perform the multiply-accumulates */ acc0 += ((q63_t) x1 * c0); acc1 += ((q63_t) x2 * c0); acc2 += ((q63_t) x0 * c0); /* Read the coefficient and state */ c0 = *(pb + 2U); x1 = *(px++); /* update coefficient pointer */ pb += 3U; /* Perform the multiply-accumulates */ acc0 += ((q63_t) x2 * c0); acc1 += ((q63_t) x0 * c0); acc2 += ((q63_t) x1 * c0); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining outputs */ tapCnt = numTaps % 0x3U; while (tapCnt > 0U) { /* Read coefficients */ c0 = *(pb++); /* Fetch 1 state variable */ x2 = *(px++); /* Perform the multiply-accumulates */ acc0 += ((q63_t) x0 * c0); acc1 += ((q63_t) x1 * c0); acc2 += ((q63_t) x2 * c0); /* Reuse the present sample states for next sample */ x0 = x1; x1 = x2; /* Decrement loop counter */ tapCnt--; } /* Advance the state pointer by 3 to process the next group of 3 samples */ pState = pState + 3; /* The result is in 2.30 format. Convert to 1.31 and store in destination buffer. */ *pDst++ = (q31_t) (acc0 >> 31U); *pDst++ = (q31_t) (acc1 >> 31U); *pDst++ = (q31_t) (acc2 >> 31U); /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining output samples */ blkCnt = blockSize % 0x3U; #else /* Initialize blkCnt with number of taps */ blkCnt = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Copy one sample at a time into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc0 = 0; /* Initialize state pointer */ px = pState; /* Initialize Coefficient pointer */ pb = pCoeffs; i = numTaps; /* Perform the multiply-accumulates */ do { /* 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] */ acc0 += (q63_t) *px++ * *pb++; i--; } while (i > 0U); /* Result is in 2.62 format. Convert to 1.31 and store in destination buffer. */ *pDst++ = (q31_t) (acc0 >> 31U); /* Advance state pointer by 1 for the next sample */ pState = pState + 1U; /* Decrement loop counter */ blkCnt--; } /* Processing is complete. Now copy the last numTaps - 1 samples to the start of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time */ tapCnt = (numTaps - 1U) >> 2U; /* Copy data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; *pStateCurnt++ = *pState++; /* Decrement loop counter */ tapCnt--; } /* Calculate remaining number of copies */ tapCnt = (numTaps - 1U) % 0x4U; #else /* Initialize tapCnt with number of taps */ tapCnt = (numTaps - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Copy remaining data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement loop counter */ tapCnt--; } } /** @} end of FIR group */
8,702
C
29.114187
169
0.556654
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_biquad_cascade_df1_init_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_biquad_cascade_df1_init_q31.c * Description: Q31 Biquad cascade DirectFormI(DF1) filter initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup BiquadCascadeDF1 @{ */ /** @brief Initialization function for the Q31 Biquad cascade filter. @param[in,out] S points to an instance of the Q31 Biquad cascade structure. @param[in] numStages number of 2nd order stages in the filter. @param[in] pCoeffs points to the filter coefficients. @param[in] pState points to the state buffer. @param[in] postShift Shift to be applied after the accumulator. Varies according to the coefficients format @return none @par Coefficient and State Ordering The coefficients are stored in the array <code>pCoeffs</code> in the following order: <pre> {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...} </pre> @par where <code>b1x</code> and <code>a1x</code> are the coefficients for the first stage, <code>b2x</code> and <code>a2x</code> are the coefficients for the second stage, and so on. The <code>pCoeffs</code> array contains a total of <code>5*numStages</code> values. @par The <code>pState</code> points to state variables array. Each Biquad stage has 4 state variables <code>x[n-1], x[n-2], y[n-1],</code> and <code>y[n-2]</code>. The state variables are arranged in the <code>pState</code> array as: <pre> {x[n-1], x[n-2], y[n-1], y[n-2]} </pre> The 4 state variables for stage 1 are first, then the 4 state variables for stage 2, and so on. The state array has a total length of <code>4*numStages</code> values. The state variables are updated after each block of data is processed; the coefficients are untouched. */ void arm_biquad_cascade_df1_init_q31( arm_biquad_casd_df1_inst_q31 * S, uint8_t numStages, const q31_t * pCoeffs, q31_t * pState, int8_t postShift) { /* Assign filter stages */ S->numStages = numStages; /* Assign postShift to be applied to the output */ S->postShift = postShift; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer and size is always 4 * numStages */ memset(pState, 0, (4U * (uint32_t) numStages) * sizeof(q31_t)); /* Assign state pointer */ S->pState = pState; } /** @} end of BiquadCascadeDF1 group */
3,538
C
35.864583
121
0.617298
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_lms_init_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_lms_init_q31.c * Description: Q31 LMS filter initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup LMS @{ */ /** @brief Initialization function for Q31 LMS filter. @param[in] S points to an instance of the Q31 LMS filter structure @param[in] numTaps number of filter coefficients @param[in] pCoeffs points to coefficient buffer @param[in] pState points to state buffer @param[in] mu step size that controls filter coefficient updates @param[in] blockSize number of samples to process @param[in] postShift bit shift applied to coefficients @return none @par Details <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: <pre> {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} </pre> The initial filter coefficients serve as a starting point for the adaptive filter. <code>pState</code> points to an array 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_lms_q31()</code>. */ void arm_lms_init_q31( arm_lms_instance_q31 * S, uint16_t numTaps, q31_t * pCoeffs, q31_t * pState, q31_t mu, uint32_t blockSize, uint32_t postShift) { /* Assign filter taps */ S->numTaps = numTaps; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer and size is always blockSize + numTaps - 1 */ memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(q31_t)); /* Assign state pointer */ S->pState = pState; /* Assign Step size value */ S->mu = mu; /* Assign postShift value to be applied */ S->postShift = postShift; } /** @} end of LMS group */
2,872
C
29.892473
113
0.614903
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_conv_partial_fast_opt_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_conv_partial_fast_opt_q15.c * Description: Fast Q15 Partial convolution * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup PartialConv @{ */ /** @brief Partial convolution of Q15 sequences (fast version). @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the location where the output result is written @param[in] firstIndex is the first output sample to start with @param[in] numPoints is the number of output points to be computed @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2 @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen) @return execution status - \ref ARM_MATH_SUCCESS : Operation successful - \ref ARM_MATH_ARGUMENT_ERROR : requested subset is not in the range [0 srcALen+srcBLen-2] @remark Refer to \ref arm_conv_partial_q15() for a slower implementation of this function which uses a 64-bit accumulator to avoid wrap around distortion. */ arm_status arm_conv_partial_fast_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints, q15_t * pScratch1, q15_t * pScratch2) { q15_t *pOut = pDst; /* Output pointer */ q15_t *pScr1 = pScratch1; /* Temporary pointer for scratch1 */ q15_t *pScr2 = pScratch2; /* Temporary pointer for scratch1 */ q31_t acc0; /* Accumulator */ const q15_t *pIn1; /* InputA pointer */ const q15_t *pIn2; /* InputB pointer */ const q15_t *px; /* Intermediate inputA pointer */ q15_t *py; /* Intermediate inputB pointer */ uint32_t j, k, blkCnt; /* Loop counter */ uint32_t tapCnt; /* Loop count */ arm_status status; /* Status variable */ q31_t x1; /* Temporary variables to hold state and coefficient values */ q31_t y1; /* State variables */ #if defined (ARM_MATH_LOOPUNROLL) q31_t acc1, acc2, acc3; /* Accumulator */ q31_t x2, x3; /* Temporary variables to hold state and coefficient values */ q31_t y2; /* State variables */ #endif /* Check for range of output samples to be calculated */ if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) { /* Set status as ARM_MATH_ARGUMENT_ERROR */ status = ARM_MATH_ARGUMENT_ERROR; } else { /* The algorithm implementation is based on the lengths of the inputs. */ /* srcB is always made to slide across srcA. */ /* So srcBLen is always considered as shorter or equal to srcALen */ if (srcALen >= srcBLen) { /* Initialization of inputA pointer */ pIn1 = pSrcA; /* Initialization of inputB pointer */ pIn2 = pSrcB; } else { /* Initialization of inputA pointer */ pIn1 = pSrcB; /* Initialization of inputB pointer */ pIn2 = pSrcA; /* srcBLen is always considered as shorter or equal to srcALen */ j = srcBLen; srcBLen = srcALen; srcALen = j; } /* Temporary pointer for scratch2 */ py = pScratch2; /* pointer to take end of scratch2 buffer */ pScr2 = pScratch2 + srcBLen - 1; /* points to smaller length sequence */ px = pIn2; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = srcBLen >> 2U; /* Copy smaller length input sequence in reverse order into second scratch buffer */ while (k > 0U) { /* copy second buffer in reversal manner */ *pScr2-- = *px++; *pScr2-- = *px++; *pScr2-- = *px++; *pScr2-- = *px++; /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = srcBLen % 0x4U; #else /* Initialize k with number of samples */ k = srcBLen; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* copy second buffer in reversal manner for remaining samples */ *pScr2-- = *px++; /* Decrement loop counter */ k--; } /* Initialze temporary scratch pointer */ pScr1 = pScratch1; /* Assuming scratch1 buffer is aligned by 32-bit */ /* Fill (srcBLen - 1U) zeros in scratch buffer */ arm_fill_q15(0, pScr1, (srcBLen - 1U)); /* Update temporary scratch pointer */ pScr1 += (srcBLen - 1U); /* Copy bigger length sequence(srcALen) samples in scratch1 buffer */ /* Copy (srcALen) samples in scratch buffer */ arm_copy_q15(pIn1, pScr1, srcALen); /* Update pointers */ pScr1 += srcALen; /* Fill (srcBLen - 1U) zeros at end of scratch buffer */ arm_fill_q15(0, pScr1, (srcBLen - 1U)); /* Update pointer */ pScr1 += (srcBLen - 1U); /* Initialization of pIn2 pointer */ pIn2 = py; pScratch1 += firstIndex; pOut = pDst + firstIndex; /* Actual convolution process starts here */ #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ blkCnt = (numPoints) >> 2; while (blkCnt > 0) { /* Initialze temporary scratch pointer as scratch1 */ pScr1 = pScratch1; /* Clear Accumlators */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* Read two samples from scratch1 buffer */ x1 = read_q15x2_ia (&pScr1); /* Read next two samples from scratch1 buffer */ x2 = read_q15x2_ia (&pScr1); tapCnt = (srcBLen) >> 2U; while (tapCnt > 0U) { /* Read four samples from smaller buffer */ y1 = read_q15x2_ia ((q15_t **) &pIn2); y2 = read_q15x2_ia ((q15_t **) &pIn2); /* multiply and accumlate */ acc0 = __SMLAD(x1, y1, acc0); acc2 = __SMLAD(x2, y1, acc2); /* pack input data */ #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x2, x1, 0); #else x3 = __PKHBT(x1, x2, 0); #endif /* multiply and accumlate */ acc1 = __SMLADX(x3, y1, acc1); /* Read next two samples from scratch1 buffer */ x1 = read_q15x2_ia (&pScr1); /* multiply and accumlate */ acc0 = __SMLAD(x2, y2, acc0); acc2 = __SMLAD(x1, y2, acc2); /* pack input data */ #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x1, x2, 0); #else x3 = __PKHBT(x2, x1, 0); #endif acc3 = __SMLADX(x3, y1, acc3); acc1 = __SMLADX(x3, y2, acc1); x2 = read_q15x2_ia (&pScr1); #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x2, x1, 0); #else x3 = __PKHBT(x1, x2, 0); #endif /* multiply and accumlate */ acc3 = __SMLADX(x3, y2, acc3); /* Decrement loop counter */ tapCnt--; } /* Update scratch pointer for remaining samples of smaller length sequence */ pScr1 -= 4U; /* apply same above for remaining samples of smaller length sequence */ tapCnt = (srcBLen) & 3U; while (tapCnt > 0U) { /* accumlate the results */ acc0 += (*pScr1++ * *pIn2); acc1 += (*pScr1++ * *pIn2); acc2 += (*pScr1++ * *pIn2); acc3 += (*pScr1++ * *pIn2++); pScr1 -= 3U; /* Decrement loop counter */ tapCnt--; } blkCnt--; /* Store the results in the accumulators in the destination buffer. */ #ifndef ARM_MATH_BIG_ENDIAN write_q15x2_ia (&pOut, __PKHBT(__SSAT((acc0 >> 15), 16), __SSAT((acc1 >> 15), 16), 16)); write_q15x2_ia (&pOut, __PKHBT(__SSAT((acc2 >> 15), 16), __SSAT((acc3 >> 15), 16), 16)); #else write_q15x2_ia (&pOut, __PKHBT(__SSAT((acc1 >> 15), 16), __SSAT((acc0 >> 15), 16), 16)); write_q15x2_ia (&pOut, __PKHBT(__SSAT((acc3 >> 15), 16), __SSAT((acc2 >> 15), 16), 16)); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* Initialization of inputB pointer */ pIn2 = py; pScratch1 += 4U; } /* Loop unrolling: Compute remaining outputs */ blkCnt = numPoints & 0x3; #else /* Initialize blkCnt with number of samples */ blkCnt = numPoints; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Calculate convolution for remaining samples of Bigger length sequence */ while (blkCnt > 0) { /* Initialze temporary scratch pointer as scratch1 */ pScr1 = pScratch1; /* Clear Accumlators */ acc0 = 0; tapCnt = (srcBLen) >> 1U; while (tapCnt > 0U) { /* Read next two samples from scratch1 buffer */ x1 = read_q15x2_ia (&pScr1); /* Read two samples from smaller buffer */ y1 = read_q15x2_ia ((q15_t **) &pIn2); /* multiply and accumlate */ acc0 = __SMLAD(x1, y1, acc0); /* Decrement loop counter */ tapCnt--; } tapCnt = (srcBLen) & 1U; /* apply same above for remaining samples of smaller length sequence */ while (tapCnt > 0U) { /* accumlate the results */ acc0 += (*pScr1++ * *pIn2++); /* Decrement loop counter */ tapCnt--; } blkCnt--; /* The result is in 2.30 format. Convert to 1.15 with saturation. ** Then store the output in the destination buffer. */ *pOut++ = (q15_t) (__SSAT((acc0 >> 15), 16)); /* Initialization of inputB pointer */ pIn2 = py; pScratch1 += 1U; } /* Set status as ARM_MATH_SUCCESS */ status = ARM_MATH_SUCCESS; } /* Return to application */ return (status); } /** @} end of PartialConv group */
11,238
C
27.966495
165
0.548318
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_biquad_cascade_df1_32x64_init_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_biquad_cascade_df1_32x64_init_q31.c * Description: High precision Q31 Biquad cascade filter initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup BiquadCascadeDF1_32x64 @{ */ /** @brief Initialization function for the Q31 Biquad cascade 32x64 filter. @param[in,out] S points to an instance of the high precision Q31 Biquad cascade filter structure @param[in] numStages number of 2nd order stages in the filter @param[in] pCoeffs points to the filter coefficients @param[in] pState points to the state buffer @param[in] postShift Shift to be applied after the accumulator. Varies according to the coefficients format @return none @par Coefficient and State Ordering The coefficients are stored in the array <code>pCoeffs</code> in the following order: <pre> {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...} </pre> where <code>b1x</code> and <code>a1x</code> are the coefficients for the first stage, <code>b2x</code> and <code>a2x</code> are the coefficients for the second stage, and so on. The <code>pCoeffs</code> array contains a total of <code>5*numStages</code> values. @par The <code>pState</code> points to state variables array and size of each state variable is 1.63 format. Each Biquad stage has 4 state variables <code>x[n-1], x[n-2], y[n-1],</code> and <code>y[n-2]</code>. The state variables are arranged in the state array as: <pre> {x[n-1], x[n-2], y[n-1], y[n-2]} </pre> The 4 state variables for stage 1 are first, then the 4 state variables for stage 2, and so on. The state array has a total length of <code>4*numStages</code> values. The state variables are updated after each block of data is processed; the coefficients are untouched. */ void arm_biquad_cas_df1_32x64_init_q31( arm_biquad_cas_df1_32x64_ins_q31 * S, uint8_t numStages, const q31_t * pCoeffs, q63_t * pState, uint8_t postShift) { /* Assign filter stages */ S->numStages = numStages; /* Assign postShift to be applied to the output */ S->postShift = postShift; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer and size is always 4 * numStages */ memset(pState, 0, (4U * (uint32_t) numStages) * sizeof(q63_t)); /* Assign state pointer */ S->pState = pState; } /** @} end of BiquadCascadeDF1_32x64 group */
3,615
C
37.063158
122
0.62296
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_biquad_cascade_df1_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_biquad_cascade_df1_q15.c * Description: Processing function for the Q15 Biquad cascade DirectFormI(DF1) filter * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup BiquadCascadeDF1 @{ */ /** @brief Processing function for the Q15 Biquad cascade filter. @param[in] S points to an instance of the Q15 Biquad cascade structure @param[in] pSrc points to the block of input data @param[out] pDst points to the location where the output result is written @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior The function is implemented using a 64-bit internal accumulator. Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. The accumulator is then shifted by <code>postShift</code> bits to truncate the result to 1.15 format by discarding the low 16 bits. Finally, the result is saturated to 1.15 format. @remark Refer to \ref arm_biquad_cascade_df1_fast_q15() for a faster but less precise implementation of this filter. */ void arm_biquad_cascade_df1_q15( const arm_biquad_casd_df1_inst_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { #if defined (ARM_MATH_DSP) const q15_t *pIn = pSrc; /* Source pointer */ q15_t *pOut = pDst; /* Destination pointer */ q31_t in; /* Temporary variable to hold input value */ q31_t out; /* Temporary variable to hold output value */ q31_t b0; /* Temporary variable to hold bo value */ q31_t b1, a1; /* Filter coefficients */ q31_t state_in, state_out; /* Filter state variables */ q31_t acc_l, acc_h; q63_t acc; /* Accumulator */ q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ int32_t lShift = (15 - (int32_t) S->postShift); /* Post shift */ uint32_t sample, stage = (uint32_t) S->numStages; /* Stage loop counter */ int32_t uShift = (32 - lShift); do { /* Read the b0 and 0 coefficients using SIMD */ b0 = read_q15x2_ia ((q15_t **) &pCoeffs); /* Read the b1 and b2 coefficients using SIMD */ b1 = read_q15x2_ia ((q15_t **) &pCoeffs); /* Read the a1 and a2 coefficients using SIMD */ a1 = read_q15x2_ia ((q15_t **) &pCoeffs); /* Read the input state values from the state buffer: x[n-1], x[n-2] */ state_in = read_q15x2_ia (&pState); /* Read the output state values from the state buffer: y[n-1], y[n-2] */ state_out = read_q15x2_da (&pState); /* Apply loop unrolling and compute 2 output values simultaneously. */ /* The variable acc hold output values that are being computed: * * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ sample = blockSize >> 1U; /* First part of the processing with loop unrolling. Compute 2 outputs at a time. ** a second loop below computes the remaining 1 sample. */ while (sample > 0U) { /* Read the input */ in = read_q15x2_ia ((q15_t **) &pIn); /* out = b0 * x[n] + 0 * 0 */ out = __SMUAD(b0, in); /* acc += b1 * x[n-1] + b2 * x[n-2] + out */ acc = __SMLALD(b1, state_in, out); /* acc += a1 * y[n-1] + a2 * y[n-2] */ acc = __SMLALD(a1, state_out, acc); /* The result is converted from 3.29 to 1.31 if postShift = 1, and then saturation is applied */ /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; /* Apply shift for lower part of acc and upper part of acc */ out = (uint32_t) acc_l >> lShift | acc_h << uShift; out = __SSAT(out, 16); /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ /* x[n-N], x[n-N-1] are packed together to make state_in of type q31 */ /* y[n-N], y[n-N-1] are packed together to make state_out of type q31 */ #ifndef ARM_MATH_BIG_ENDIAN state_in = __PKHBT(in, state_in, 16); state_out = __PKHBT(out, state_out, 16); #else state_in = __PKHBT(state_in >> 16, (in >> 16), 16); state_out = __PKHBT(state_out >> 16, (out), 16); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* out = b0 * x[n] + 0 * 0 */ out = __SMUADX(b0, in); /* acc += b1 * x[n-1] + b2 * x[n-2] + out */ acc = __SMLALD(b1, state_in, out); /* acc += a1 * y[n-1] + a2 * y[n-2] */ acc = __SMLALD(a1, state_out, acc); /* The result is converted from 3.29 to 1.31 if postShift = 1, and then saturation is applied */ /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; /* Apply shift for lower part of acc and upper part of acc */ out = (uint32_t) acc_l >> lShift | acc_h << uShift; out = __SSAT(out, 16); /* Store the output in the destination buffer. */ #ifndef ARM_MATH_BIG_ENDIAN write_q15x2_ia (&pOut, __PKHBT(state_out, out, 16)); #else write_q15x2_ia (&pOut, __PKHBT(out, state_out >> 16, 16)); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ /* x[n-N], x[n-N-1] are packed together to make state_in of type q31 */ /* y[n-N], y[n-N-1] are packed together to make state_out of type q31 */ #ifndef ARM_MATH_BIG_ENDIAN state_in = __PKHBT(in >> 16, state_in, 16); state_out = __PKHBT(out, state_out, 16); #else state_in = __PKHBT(state_in >> 16, in, 16); state_out = __PKHBT(state_out >> 16, out, 16); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* Decrement loop counter */ sample--; } /* If the blockSize is not a multiple of 2, compute any remaining output samples here. ** No loop unrolling is used. */ if ((blockSize & 0x1U) != 0U) { /* Read the input */ in = *pIn++; /* out = b0 * x[n] + 0 * 0 */ #ifndef ARM_MATH_BIG_ENDIAN out = __SMUAD(b0, in); #else out = __SMUADX(b0, in); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ /* acc = b1 * x[n-1] + b2 * x[n-2] + out */ acc = __SMLALD(b1, state_in, out); /* acc += a1 * y[n-1] + a2 * y[n-2] */ acc = __SMLALD(a1, state_out, acc); /* The result is converted from 3.29 to 1.31 if postShift = 1, and then saturation is applied */ /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; /* Apply shift for lower part of acc and upper part of acc */ out = (uint32_t) acc_l >> lShift | acc_h << uShift; out = __SSAT(out, 16); /* Store the output in the destination buffer. */ *pOut++ = (q15_t) out; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ /* x[n-N], x[n-N-1] are packed together to make state_in of type q31 */ /* y[n-N], y[n-N-1] are packed together to make state_out of type q31 */ #ifndef ARM_MATH_BIG_ENDIAN state_in = __PKHBT(in, state_in, 16); state_out = __PKHBT(out, state_out, 16); #else state_in = __PKHBT(state_in >> 16, in, 16); state_out = __PKHBT(state_out >> 16, out, 16); #endif /* #ifndef ARM_MATH_BIG_ENDIAN */ } /* The first stage goes from the input wire to the output wire. */ /* Subsequent numStages occur in-place in the output wire */ pIn = pDst; /* Reset the output pointer */ pOut = pDst; /* Store the updated state variables back into the state array */ write_q15x2_ia (&pState, state_in); write_q15x2_ia (&pState, state_out); /* Decrement loop counter */ stage--; } while (stage > 0U); #else const q15_t *pIn = pSrc; /* Source pointer */ q15_t *pOut = pDst; /* Destination pointer */ q15_t b0, b1, b2, a1, a2; /* Filter coefficients */ q15_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ q15_t Xn; /* temporary input */ q63_t acc; /* Accumulator */ int32_t shift = (15 - (int32_t) S->postShift); /* Post shift */ q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ uint32_t sample, stage = (uint32_t) S->numStages; /* Stage loop counter */ do { /* Reading the coefficients */ b0 = *pCoeffs++; pCoeffs++; // skip the 0 coefficient b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the state values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; /* The variables acc holds the output value that is computed: * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ /* acc = b0 * x[n] */ acc = (q31_t) b0 *Xn; /* acc += b1 * x[n-1] */ acc += (q31_t) b1 *Xn1; /* acc += b[2] * x[n-2] */ acc += (q31_t) b2 *Xn2; /* acc += a1 * y[n-1] */ acc += (q31_t) a1 *Yn1; /* acc += a2 * y[n-2] */ acc += (q31_t) a2 *Yn2; /* The result is converted to 1.31 */ acc = __SSAT((acc >> shift), 16); /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; Yn1 = (q15_t) acc; /* Store the output in the destination buffer. */ *pOut++ = (q15_t) acc; /* decrement the loop counter */ sample--; } /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent stages occur in-place in the output buffer */ pIn = pDst; /* Reset to destination pointer */ pOut = pDst; /* Store the updated state variables back into the pState array */ *pState++ = Xn1; *pState++ = Xn2; *pState++ = Yn1; *pState++ = Yn2; } while (--stage); #endif /* #if defined (ARM_MATH_DSP) */ } /** @} end of BiquadCascadeDF1 group */
12,701
C
33.895604
150
0.53169
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_biquad_cascade_stereo_df2T_init_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_biquad_cascade_stereo_df2T_init_f32.c * Description: Initialization function for floating-point transposed direct form II Biquad cascade filter * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup BiquadCascadeDF2T @{ */ /** @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter. @param[in,out] S points to an instance of the filter data structure. @param[in] numStages number of 2nd order stages in the filter. @param[in] pCoeffs points to the filter coefficients. @param[in] pState points to the state buffer. @return none @par Coefficient and State Ordering The coefficients are stored in the array <code>pCoeffs</code> in the following order: <pre> {b10, b11, b12, a11, a12, b20, b21, b22, a21, a22, ...} </pre> @par where <code>b1x</code> and <code>a1x</code> are the coefficients for the first stage, <code>b2x</code> and <code>a2x</code> are the coefficients for the second stage, and so on. The <code>pCoeffs</code> array contains a total of <code>5*numStages</code> values. @par The <code>pState</code> is a pointer to state array. Each Biquad stage has 2 state variables <code>d1,</code> and <code>d2</code> for each channel. The 2 state variables for stage 1 are first, then the 2 state variables for stage 2, and so on. The state array has a total length of <code>2*numStages</code> values. The state variables are updated after each block of data is processed; the coefficients are untouched. */ void arm_biquad_cascade_stereo_df2T_init_f32( arm_biquad_cascade_stereo_df2T_instance_f32 * S, uint8_t numStages, const float32_t * pCoeffs, float32_t * pState) { /* Assign filter stages */ S->numStages = numStages; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer and size is always 4 * numStages */ memset(pState, 0, (4U * (uint32_t) numStages) * sizeof(float32_t)); /* Assign state pointer */ S->pState = pState; } /** @} end of BiquadCascadeDF2T group */
3,256
C
36.436781
121
0.627457
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_sparse_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_sparse_f32.c * Description: Floating-point sparse FIR filter processing function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @defgroup FIR_Sparse Finite Impulse Response (FIR) Sparse Filters This group of functions implements sparse FIR filters. Sparse FIR filters are equivalent to standard FIR filters except that most of the coefficients are equal to zero. Sparse filters are used for simulating reflections in communications and audio applications. There are separate functions for Q7, Q15, Q31, and floating-point data types. The functions operate on blocks of input and output data and each call to the function processes <code>blockSize</code> samples through the filter. <code>pSrc</code> and <code>pDst</code> points to input and output arrays respectively containing <code>blockSize</code> values. @par Algorithm The sparse filter instant structure contains an array of tap indices <code>pTapDelay</code> which specifies the locations of the non-zero coefficients. This is in addition to the coefficient array <code>b</code>. The implementation essentially skips the multiplications by zero and leads to an efficient realization. <pre> y[n] = b[0] * x[n-pTapDelay[0]] + b[1] * x[n-pTapDelay[1]] + b[2] * x[n-pTapDelay[2]] + ...+ b[numTaps-1] * x[n-pTapDelay[numTaps-1]] </pre> @par \image html FIRSparse.gif "Sparse FIR filter. b[n] represents the filter coefficients" @par <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>; <code>pTapDelay</code> points to an array of nonzero indices and is also of size <code>numTaps</code>; <code>pState</code> points to a state array of size <code>maxDelay + blockSize</code>, where <code>maxDelay</code> is the largest offset value that is ever used in the <code>pTapDelay</code> array. Some of the processing functions also require temporary working buffers. @par Instance Structure The coefficients and state variables for a filter are stored together in an instance data structure. A separate instance structure must be defined for each filter. Coefficient and offset arrays may be shared among several instances while state variable arrays cannot be shared. There are separate instance structure declarations for each of the 4 supported data types. @par Initialization Functions There is also an associated initialization function for each data type. The initialization function performs the following operations: - Sets the values of the internal structure fields. - Zeros out the values in the state buffer. To do this manually without calling the init function, assign the follow subfields of the instance structure: numTaps, pCoeffs, pTapDelay, maxDelay, stateIndex, pState. Also set all of the values in pState to zero. @par Use of the initialization function is optional. However, if the initialization function is used, then the instance structure cannot be placed into a const data section. To place an instance structure into a const data section, the instance structure must be manually initialized. Set the values in the state buffer to zeros before static initialization. The code below statically initializes each of the 4 different data type filter instance structures <pre> arm_fir_sparse_instance_f32 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; arm_fir_sparse_instance_q31 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; arm_fir_sparse_instance_q15 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; arm_fir_sparse_instance_q7 S = {numTaps, 0, pState, pCoeffs, maxDelay, pTapDelay}; </pre> @par Fixed-Point Behavior Care must be taken when using the fixed-point versions of the sparse FIR filter functions. In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. Refer to the function specific documentation below for usage guidelines. */ /** @addtogroup FIR_Sparse @{ */ /** @brief Processing function for the floating-point sparse FIR filter. @param[in] S points to an instance of the floating-point sparse FIR structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] pScratchIn points to a temporary buffer of size blockSize @param[in] blockSize number of input samples to process @return none */ void arm_fir_sparse_f32( arm_fir_sparse_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, float32_t * pScratchIn, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *px; /* Scratch buffer pointer */ float32_t *py = pState; /* Temporary pointers for state buffer */ float32_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ float32_t *pOut; /* Destination pointer */ int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ uint32_t delaySize = S->maxDelay + blockSize; /* state length */ uint16_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ int32_t readIndex; /* Read index of the state buffer */ uint32_t tapCnt, blkCnt; /* loop counters */ float32_t coeff = *pCoeffs++; /* Read the first coefficient value */ /* BlockSize of Input samples are copied into the state buffer */ /* StateIndex points to the starting position to write in the state buffer */ arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1, (int32_t *) pSrc, 1, blockSize); /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, (int32_t *) pb, (int32_t *) pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pOut = pDst; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time. */ blkCnt = blockSize >> 2U; while (blkCnt > 0U) { /* Perform Multiplications and store in destination buffer */ *pOut++ = *px++ * coeff; *pOut++ = *px++ * coeff; *pOut++ = *px++ * coeff; *pOut++ = *px++ * coeff; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = blockSize % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Perform Multiplication and store in destination buffer */ *pOut++ = *px++ * coeff; /* Decrement loop counter */ blkCnt--; } /* Load the coefficient value and * increment the coefficient buffer for the next set of state values */ coeff = *pCoeffs++; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Loop over the number of taps. */ tapCnt = (uint32_t) numTaps - 2U; while (tapCnt > 0U) { /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, (int32_t *) pb, (int32_t *) pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pOut = pDst; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time. */ blkCnt = blockSize >> 2U; while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ *pOut++ += *px++ * coeff; *pOut++ += *px++ * coeff; *pOut++ += *px++ * coeff; *pOut++ += *px++ * coeff; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = blockSize % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ *pOut++ += *px++ * coeff; /* Decrement loop counter */ blkCnt--; } /* Load the coefficient value and * increment the coefficient buffer for the next set of state values */ coeff = *pCoeffs++; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Decrement tap loop counter */ tapCnt--; } /* Compute last tap without the final read of pTapDelay */ /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, (int32_t *) pb, (int32_t *) pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pOut = pDst; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time. */ blkCnt = blockSize >> 2U; while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ *pOut++ += *px++ * coeff; *pOut++ += *px++ * coeff; *pOut++ += *px++ * coeff; *pOut++ += *px++ * coeff; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = blockSize % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ *pOut++ += *px++ * coeff; /* Decrement loop counter */ blkCnt--; } } /** @} end of FIR_Sparse group */
12,285
C
34.923977
170
0.621164
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_biquad_cascade_df1_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_biquad_cascade_df1_f32.c * Description: Processing function for the floating-point Biquad cascade DirectFormI(DF1) filter * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @defgroup BiquadCascadeDF1 Biquad Cascade IIR Filters Using Direct Form I Structure This set of functions implements arbitrary order recursive (IIR) filters. The filters are implemented as a cascade of second order Biquad sections. The functions support Q15, Q31 and floating-point data types. Fast version of Q15 and Q31 also available. The functions operate on blocks of input and output data and each call to the function processes <code>blockSize</code> samples through the filter. <code>pSrc</code> points to the array of input data and <code>pDst</code> points to the array of output data. Both arrays contain <code>blockSize</code> values. @par Algorithm Each Biquad stage implements a second order filter using the difference equation: <pre> y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] </pre> A Direct Form I algorithm is used with 5 coefficients and 4 state variables per stage. \image html Biquad.gif "Single Biquad filter stage" Coefficients <code>b0, b1 and b2 </code> multiply the input signal <code>x[n]</code> and are referred to as the feedforward coefficients. Coefficients <code>a1</code> and <code>a2</code> multiply the output signal <code>y[n]</code> and are referred to as the feedback coefficients. Pay careful attention to the sign of the feedback coefficients. Some design tools use the difference equation <pre> y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] - a1 * y[n-1] - a2 * y[n-2] </pre> In this case the feedback coefficients <code>a1</code> and <code>a2</code> must be negated when used with the CMSIS DSP Library. @par Higher order filters are realized as a cascade of second order sections. <code>numStages</code> refers to the number of second order stages used. For example, an 8th order filter would be realized with <code>numStages=4</code> second order stages. \image html BiquadCascade.gif "8th order filter using a cascade of Biquad stages" A 9th order filter would be realized with <code>numStages=5</code> second order stages with the coefficients for one of the stages configured as a first order filter (<code>b2=0</code> and <code>a2=0</code>). @par The <code>pState</code> points to state variables array. Each Biquad stage has 4 state variables <code>x[n-1], x[n-2], y[n-1],</code> and <code>y[n-2]</code>. The state variables are arranged in the <code>pState</code> array as: <pre> {x[n-1], x[n-2], y[n-1], y[n-2]} </pre> @par The 4 state variables for stage 1 are first, then the 4 state variables for stage 2, and so on. The state array has a total length of <code>4*numStages</code> values. The state variables are updated after each block of data is processed, the coefficients are untouched. @par Instance Structure The coefficients and state variables for a filter are stored together in an instance data structure. A separate instance structure must be defined for each filter. Coefficient arrays may be shared among several instances while state variable arrays cannot be shared. There are separate instance structure declarations for each of the 3 supported data types. @par Init Function There is also an associated initialization function for each data type. The initialization function performs following operations: - Sets the values of the internal structure fields. - Zeros out the values in the state buffer. To do this manually without calling the init function, assign the follow subfields of the instance structure: numStages, pCoeffs, pState. Also set all of the values in pState to zero. @par Use of the initialization function is optional. However, if the initialization function is used, then the instance structure cannot be placed into a const data section. To place an instance structure into a const data section, the instance structure must be manually initialized. Set the values in the state buffer to zeros before static initialization. The code below statically initializes each of the 3 different data type filter instance structures <pre> arm_biquad_casd_df1_inst_f32 S1 = {numStages, pState, pCoeffs}; arm_biquad_casd_df1_inst_q15 S2 = {numStages, pState, pCoeffs, postShift}; arm_biquad_casd_df1_inst_q31 S3 = {numStages, pState, pCoeffs, postShift}; </pre> where <code>numStages</code> is the number of Biquad stages in the filter; <code>pState</code> is the address of the state buffer; <code>pCoeffs</code> is the address of the coefficient buffer; <code>postShift</code> shift to be applied. @par Fixed-Point Behavior Care must be taken when using the Q15 and Q31 versions of the Biquad Cascade filter functions. Following issues must be considered: - Scaling of coefficients - Filter gain - Overflow and saturation @par Scaling of coefficients Filter coefficients are represented as fractional values and coefficients are restricted to lie in the range <code>[-1 +1)</code>. The fixed-point functions have an additional scaling parameter <code>postShift</code> which allow the filter coefficients to exceed the range <code>[+1 -1)</code>. At the output of the filter's accumulator is a shift register which shifts the result by <code>postShift</code> bits. \image html BiquadPostshift.gif "Fixed-point Biquad with shift by postShift bits after accumulator" This essentially scales the filter coefficients by <code>2^postShift</code>. For example, to realize the coefficients <pre> {1.5, -0.8, 1.2, 1.6, -0.9} </pre> set the pCoeffs array to: <pre> {0.75, -0.4, 0.6, 0.8, -0.45} </pre> and set <code>postShift=1</code> @par Filter gain The frequency response of a Biquad filter is a function of its coefficients. It is possible for the gain through the filter to exceed 1.0 meaning that the filter increases the amplitude of certain frequencies. This means that an input signal with amplitude < 1.0 may result in an output > 1.0 and these are saturated or overflowed based on the implementation of the filter. To avoid this behavior the filter needs to be scaled down such that its peak gain < 1.0 or the input signal must be scaled down so that the combination of input and filter are never overflowed. @par Overflow and saturation For Q15 and Q31 versions, it is described separately as part of the function specific documentation below. */ /** @addtogroup BiquadCascadeDF1 @{ */ /** @brief Processing function for the floating-point Biquad cascade filter. @param[in] S points to an instance of the floating-point Biquad cascade structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none */ #if defined(ARM_MATH_NEON) void arm_biquad_cascade_df1_f32( const arm_biquad_casd_df1_inst_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { const float32_t *pIn = pSrc; /* source pointer */ float32_t *pOut = pDst; /* destination pointer */ float32_t *pState = S->pState; /* pState pointer */ const float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */ float32_t acc; /* Simulates the accumulator */ uint32_t sample, stage = S->numStages; /* loop counters */ float32x4_t Xn; float32x2_t Yn; float32x2_t a; float32x4_t b; float32x4_t x,tmp; float32x2_t t; float32x2x2_t y; float32_t Xns; while (stage > 0U) { /* Reading the coefficients */ Xn = vld1q_f32(pState); Yn = vld1_f32(pState + 2); b = vld1q_f32(pCoeffs); b = vrev64q_f32(b); b = vcombine_f32(vget_high_f32(b), vget_low_f32(b)); a = vld1_f32(pCoeffs + 3); a = vrev64_f32(a); b[0] = 0.0; pCoeffs += 5; /* Reading the pState values */ /* Apply loop unrolling and compute 4 output values simultaneously. */ /* The variable acc hold output values that are being computed: * * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ /* First part of the processing with loop unrolling. Compute 4 outputs at a time. ** a second loop below computes the remaining 1 to 3 samples. */ sample = blockSize >> 2U; while (sample > 0U) { /* Read the first 4 inputs */ x = vld1q_f32(pIn); pIn += 4; tmp = vextq_f32(Xn, x, 1); t = vmul_f32(vget_high_f32(b), vget_high_f32(tmp)); t = vmla_f32(t, vget_low_f32(b), vget_low_f32(tmp)); t = vmla_f32(t, a, Yn); t = vpadd_f32(t, t); Yn = vext_f32(Yn, t, 1); tmp = vextq_f32(Xn, x, 2); t = vmul_f32(vget_high_f32(b), vget_high_f32(tmp)); t = vmla_f32(t, vget_low_f32(b), vget_low_f32(tmp)); t = vmla_f32(t, a, Yn); t = vpadd_f32(t, t); Yn = vext_f32(Yn, t, 1); y.val[0] = Yn; tmp = vextq_f32(Xn, x, 3); t = vmul_f32(vget_high_f32(b), vget_high_f32(tmp)); t = vmla_f32(t, vget_low_f32(b), vget_low_f32(tmp)); t = vmla_f32(t, a, Yn); t = vpadd_f32(t, t); Yn = vext_f32(Yn, t, 1); Xn = x; t = vmul_f32(vget_high_f32(b), vget_high_f32(Xn)); t = vmla_f32(t, vget_low_f32(b), vget_low_f32(Xn)); t = vmla_f32(t, a, Yn); t = vpadd_f32(t, t); Yn = vext_f32(Yn, t, 1); y.val[1] = Yn; tmp = vcombine_f32(y.val[0], y.val[1]); /* Store the 4 outputs and increment the pointer */ vst1q_f32(pOut, tmp); pOut += 4; /* Decrement the loop counter */ sample--; } /* If the block size is not a multiple of 4, compute any remaining output samples here. ** No loop unrolling is used. */ sample = blockSize & 0x3U; while (sample > 0U) { /* Read the input */ Xns = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ acc = (b[1] * Xn[2]) + (b[2] * Xn[3]) + (b[3] * Xns) + (a[0] * Yn[0]) + (a[1] * Yn[1]); /* Store the result in the accumulator in the destination buffer. */ *pOut++ = acc; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ Xn[2] = Xn[3]; Xn[3] = Xns; Yn[0] = Yn[1]; Yn[1] = acc; /* Decrement the loop counter */ sample--; } vst1q_f32(pState,vcombine_f32(vrev64_f32(vget_high_f32(Xn)),vrev64_f32(Yn))); pState += 4; /* Store the updated state variables back into the pState array */ /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent numStages occur in-place in the output buffer */ pIn = pDst; /* Reset the output pointer */ pOut = pDst; /* Decrement the loop counter */ stage--; } } #else void arm_biquad_cascade_df1_f32( const arm_biquad_casd_df1_inst_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { const float32_t *pIn = pSrc; /* Source pointer */ float32_t *pOut = pDst; /* Destination pointer */ float32_t *pState = S->pState; /* pState pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t acc; /* Accumulator */ float32_t b0, b1, b2, a1, a2; /* Filter coefficients */ float32_t Xn1, Xn2, Yn1, Yn2; /* Filter pState variables */ float32_t Xn; /* Temporary input */ uint32_t sample, stage = S->numStages; /* Loop counters */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the pState values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; #if defined (ARM_MATH_LOOPUNROLL) /* Apply loop unrolling and compute 4 output values simultaneously. */ /* Variable acc hold output values that are being computed: * * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ /* Loop unrolling: Compute 4 outputs at a time */ sample = blockSize >> 2U; while (sample > 0U) { /* Read the first input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ Yn2 = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2); /* Store output in destination buffer. */ *pOut++ = Yn2; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ /* Read the second input */ Xn2 = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ Yn1 = (b0 * Xn2) + (b1 * Xn) + (b2 * Xn1) + (a1 * Yn2) + (a2 * Yn1); /* Store output in destination buffer. */ *pOut++ = Yn1; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ /* Read the third input */ Xn1 = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ Yn2 = (b0 * Xn1) + (b1 * Xn2) + (b2 * Xn) + (a1 * Yn1) + (a2 * Yn2); /* Store output in destination buffer. */ *pOut++ = Yn2; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ /* Read the forth input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ Yn1 = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn2) + (a2 * Yn1); /* Store output in destination buffer. */ *pOut++ = Yn1; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ Xn2 = Xn1; Xn1 = Xn; /* decrement loop counter */ sample--; } /* Loop unrolling: Compute remaining outputs */ sample = blockSize & 0x3U; #else /* Initialize blkCnt with number of samples */ sample = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ acc = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2); /* Store output in destination buffer. */ *pOut++ = acc; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; Yn1 = acc; /* decrement loop counter */ sample--; } /* Store the updated state variables back into the pState array */ *pState++ = Xn1; *pState++ = Xn2; *pState++ = Yn1; *pState++ = Yn2; /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent numStages occur in-place in the output buffer */ pIn = pDst; /* Reset output pointer */ pOut = pDst; /* decrement loop counter */ stage--; } while (stage > 0U); } #endif /* #if defined(ARM_MATH_NEON) */ /** @} end of BiquadCascadeDF1 group */
18,803
C
36.91129
227
0.559272
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_conv_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_conv_q31.c * Description: Convolution of Q31 sequences * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup Conv @{ */ /** @brief Convolution of Q31 sequences. @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1. @return none @par Scaling and Overflow Behavior The function is implemented using an internal 64-bit accumulator. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. There is no saturation on intermediate additions. Thus, if the accumulator overflows it wraps around and distorts the result. The input signals should be scaled down to avoid intermediate overflows. Scale down the inputs by log2(min(srcALen, srcBLen)) (log2 is read as log to the base 2) times to avoid overflows, as maximum of min(srcALen, srcBLen) number of additions are carried internally. The 2.62 accumulator is right shifted by 31 bits and saturated to 1.31 format to yield the final result. @remark Refer to \ref arm_conv_fast_q31() for a faster but less precise implementation of this function. */ void arm_conv_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst) { #if (1) //#if !defined(ARM_MATH_CM0_FAMILY) const q31_t *pIn1; /* InputA pointer */ const q31_t *pIn2; /* InputB pointer */ q31_t *pOut = pDst; /* Output pointer */ const q31_t *px; /* Intermediate inputA pointer */ const q31_t *py; /* Intermediate inputB pointer */ const q31_t *pSrc1, *pSrc2; /* Intermediate pointers */ q63_t sum; /* Accumulators */ uint32_t blockSize1, blockSize2, blockSize3; /* Loop counters */ uint32_t j, k, count, blkCnt; /* Loop counters */ #if defined (ARM_MATH_LOOPUNROLL) q63_t acc0, acc1, acc2; /* Accumulators */ q31_t x0, x1, x2, c0; /* Temporary variables to hold state and coefficient values */ #endif /* The algorithm implementation is based on the lengths of the inputs. */ /* srcB is always made to slide across srcA. */ /* So srcBLen is always considered as shorter or equal to srcALen */ if (srcALen >= srcBLen) { /* Initialization of inputA pointer */ pIn1 = pSrcA; /* Initialization of inputB pointer */ pIn2 = pSrcB; } else { /* Initialization of inputA pointer */ pIn1 = pSrcB; /* Initialization of inputB pointer */ pIn2 = pSrcA; /* srcBLen is always considered as shorter or equal to srcALen */ j = srcBLen; srcBLen = srcALen; srcALen = j; } /* 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] */ /* The function is internally * divided into three stages according to the number of multiplications that has to be * taken place between inputA samples and inputB samples. In the first stage of the * algorithm, the multiplications increase by one for every iteration. * In the second stage of the algorithm, srcBLen number of multiplications are done. * In the third stage of the algorithm, the multiplications decrease by one * for every iteration. */ /* The algorithm is implemented in three stages. The loop counters of each stage is initiated here. */ blockSize1 = srcBLen - 1U; blockSize2 = srcALen - (srcBLen - 1U); blockSize3 = blockSize1; /* -------------------------- * Initializations of stage1 * -------------------------*/ /* sum = x[0] * y[0] * sum = x[0] * y[1] + x[1] * y[0] * .... * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] */ /* In this stage the MAC operations are increased by 1 for every iteration. The count variable holds the number of MAC operations performed */ count = 1U; /* Working pointer of inputA */ px = pIn1; /* Working pointer of inputB */ py = pIn2; /* ------------------------ * Stage1 process * ----------------------*/ /* The first stage starts here */ while (blockSize1 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = count >> 2U; while (k > 0U) { /* x[0] * y[srcBLen - 1] */ sum += (q63_t) *px++ * (*py--); /* x[1] * y[srcBLen - 2] */ sum += (q63_t) *px++ * (*py--); /* x[2] * y[srcBLen - 3] */ sum += (q63_t) *px++ * (*py--); /* x[3] * y[srcBLen - 4] */ sum += (q63_t) *px++ * (*py--); /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = count % 0x4U; #else /* Initialize k with number of samples */ k = count; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Update the inputA and inputB pointers for next MAC calculation */ py = pIn2 + count; px = pIn1; /* Increment MAC count */ count++; /* Decrement loop counter */ blockSize1--; } /* -------------------------- * Initializations of stage2 * ------------------------*/ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] * .... * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] */ /* Working pointer of inputA */ px = pIn1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* count is index by which the pointer pIn1 to be incremented */ count = 0U; /* ------------------- * Stage2 process * ------------------*/ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. * So, to loop unroll over blockSize2, * srcBLen should be greater than or equal to 4 */ if (srcBLen >= 4U) { #if defined (ARM_MATH_LOOPUNROLL) /* Loop unroll by 3 */ blkCnt = blockSize2 / 3; while (blkCnt > 0U) { /* Set all accumulators to zero */ acc0 = 0; acc1 = 0; acc2 = 0; /* read x[0], x[1], x[2] samples */ x0 = *px++; x1 = *px++; /* Apply loop unrolling and compute 3 MACs simultaneously. */ k = srcBLen / 3; /* First part of the processing with loop unrolling. Compute 3 MACs at a time. ** a second loop below computes MACs for the remaining 1 to 2 samples. */ do { /* Read y[srcBLen - 1] sample */ c0 = *(py); /* Read x[3] sample */ x2 = *(px); /* Perform the multiply-accumulate */ /* acc0 += x[0] * y[srcBLen - 1] */ acc0 += ((q63_t) x0 * c0); /* acc1 += x[1] * y[srcBLen - 1] */ acc1 += ((q63_t) x1 * c0); /* acc2 += x[2] * y[srcBLen - 1] */ acc2 += ((q63_t) x2 * c0); /* Read y[srcBLen - 2] sample */ c0 = *(py - 1U); /* Read x[4] sample */ x0 = *(px + 1U); /* Perform the multiply-accumulate */ /* acc0 += x[1] * y[srcBLen - 2] */ acc0 += ((q63_t) x1 * c0); /* acc1 += x[2] * y[srcBLen - 2] */ acc1 += ((q63_t) x2 * c0); /* acc2 += x[3] * y[srcBLen - 2] */ acc2 += ((q63_t) x0 * c0); /* Read y[srcBLen - 3] sample */ c0 = *(py - 2U); /* Read x[5] sample */ x1 = *(px + 2U); /* Perform the multiply-accumulate */ /* acc0 += x[2] * y[srcBLen - 3] */ acc0 += ((q63_t) x2 * c0); /* acc1 += x[3] * y[srcBLen - 2] */ acc1 += ((q63_t) x0 * c0); /* acc2 += x[4] * y[srcBLen - 2] */ acc2 += ((q63_t) x1 * c0); /* update scratch pointers */ px += 3U; py -= 3U; } while (--k); /* If the srcBLen is not a multiple of 3, compute any remaining MACs here. ** No loop unrolling is used. */ k = srcBLen - (3 * (srcBLen / 3)); while (k > 0U) { /* Read y[srcBLen - 5] sample */ c0 = *py--; /* Read x[7] sample */ x2 = *px++; /* Perform the multiply-accumulates */ /* acc0 += x[4] * y[srcBLen - 5] */ acc0 += ((q63_t) x0 * c0); /* acc1 += x[5] * y[srcBLen - 5] */ acc1 += ((q63_t) x1 * c0); /* acc2 += x[6] * y[srcBLen - 5] */ acc2 += ((q63_t) x2 * c0); /* Reuse the present samples for the next MAC */ x0 = x1; x1 = x2; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (acc0 >> 31); *pOut++ = (q31_t) (acc1 >> 31); *pOut++ = (q31_t) (acc2 >> 31); /* Increment the pointer pIn1 index, count by 3 */ count += 3U; /* Update the inputA and inputB pointers for next MAC calculation */ px = pIn1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = blockSize2 - 3 * (blockSize2 / 3); #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize2; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = srcBLen >> 2U; while (k > 0U) { /* Perform the multiply-accumulates */ sum += (q63_t) *px++ * *py--; sum += (q63_t) *px++ * *py--; sum += (q63_t) *px++ * *py--; sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = srcBLen % 0x4U; #else /* Initialize blkCnt with number of samples */ k = srcBLen; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += (q63_t) *px++ * *py--; /* Decrement the loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Increment MAC count */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pIn1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } } else { /* If the srcBLen is not a multiple of 4, * the blockSize2 loop cannot be unrolled by 4 */ blkCnt = blockSize2; while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; /* srcBLen number of MACS should be performed */ k = srcBLen; while (k > 0U) { /* Perform the multiply-accumulate */ sum += (q63_t) *px++ * *py--; /* Decrement the loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Increment MAC count */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pIn1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } } /* -------------------------- * Initializations of stage3 * -------------------------*/ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] * .... * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] * sum += x[srcALen-1] * y[srcBLen-1] */ /* In this stage the MAC operations are decreased by 1 for every iteration. The blockSize3 variable holds the number of MAC operations performed */ /* Working pointer of inputA */ pSrc1 = (pIn1 + srcALen) - (srcBLen - 1U); px = pSrc1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* ------------------- * Stage3 process * ------------------*/ while (blockSize3 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = blockSize3 >> 2U; while (k > 0U) { /* Perform the multiply-accumulate */ /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */ sum += (q63_t) *px++ * *py--; /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */ sum += (q63_t) *px++ * *py--; /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */ sum += (q63_t) *px++ * *py--; /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */ sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = blockSize3 % 0x4U; #else /* Initialize blkCnt with number of samples */ k = blockSize3; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ /* sum += x[srcALen-1] * y[srcBLen-1] */ sum += (q63_t) *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q31_t) (sum >> 31); /* Update the inputA and inputB pointers for next MAC calculation */ px = ++pSrc1; py = pSrc2; /* Decrement loop counter */ blockSize3--; } #else /* alternate version for CM0_FAMILY */ const q31_t *pIn1 = pSrcA; /* InputA pointer */ const q31_t *pIn2 = pSrcB; /* InputB pointer */ q63_t sum; /* Accumulators */ uint32_t i, j; /* Loop counters */ /* Loop to calculate convolution for output length number of times */ for (i = 0U; i < (srcALen + srcBLen - 1U); i++) { /* Initialize sum with zero to carry out MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if (((i - j) < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += ((q63_t) pIn1[j] * pIn2[i - j]); } } /* Store the output in the destination buffer */ pDst[i] = (q31_t) (sum >> 31U); } #endif /* #if !defined(ARM_MATH_CM0_FAMILY) */ } /** @} end of Conv group */
16,564
C
27.462199
162
0.521251
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_init_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_init_f32.c * Description: Floating-point FIR filter initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR @{ */ /** @brief Initialization function for the floating-point FIR filter. @param[in,out] S points to an instance of the floating-point FIR filter structure @param[in] numTaps number of filter coefficients in the filter @param[in] pCoeffs points to the filter coefficients buffer @param[in] pState points to the state buffer @param[in] blockSize number of samples processed per call @return none @par Details <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: <pre> {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} </pre> @par <code>pState</code> points to the array of state variables. <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>. */ void arm_fir_init_f32( arm_fir_instance_f32 * S, uint16_t numTaps, const float32_t * pCoeffs, float32_t * pState, uint32_t blockSize) { /* Assign filter taps */ S->numTaps = numTaps; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer. The size is always (blockSize + numTaps - 1) */ memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(float32_t)); /* Assign state pointer */ S->pState = pState; } /** @} end of FIR group */
2,626
C
31.036585
207
0.61805
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_lattice_init_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_lattice_init_q15.c * Description: Q15 FIR Lattice filter initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR_Lattice @{ */ /** @brief Initialization function for the Q15 FIR lattice filter. @param[in] S points to an instance of the Q15 FIR lattice structure @param[in] numStages number of filter stages @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages @param[in] pState points to the state buffer. The array is of length numStages @return none */ void arm_fir_lattice_init_q15( arm_fir_lattice_instance_q15 * S, uint16_t numStages, const q15_t * pCoeffs, q15_t * pState) { /* Assign filter taps */ S->numStages = numStages; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer and size is always numStages */ memset(pState, 0, (numStages) * sizeof(q15_t)); /* Assign state pointer */ S->pState = pState; } /** @} end of FIR_Lattice group */
2,050
C
27.887324
95
0.623902
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_conv_partial_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_conv_partial_f32.c * Description: Partial convolution of floating-point sequences * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @defgroup PartialConv Partial Convolution Partial Convolution is equivalent to Convolution except that a subset of the output samples is generated. Each function has two additional arguments. <code>firstIndex</code> specifies the starting index of the subset of output samples. <code>numPoints</code> is the number of output samples to compute. The function computes the output in the range <code>[firstIndex, ..., firstIndex+numPoints-1]</code>. The output array <code>pDst</code> contains <code>numPoints</code> values. The allowable range of output indices is [0 srcALen+srcBLen-2]. If the requested subset does not fall in this range then the functions return ARM_MATH_ARGUMENT_ERROR. Otherwise the functions return ARM_MATH_SUCCESS. \note Refer to \ref arm_conv_f32() for details on fixed point behavior. @par Fast Versions Fast versions are supported for Q31 and Q15 of partial convolution. Cycles for Fast versions are less compared to Q31 and Q15 of partial conv and the design requires the input signals should be scaled down to avoid intermediate overflows. @par Opt Versions Opt versions are supported for Q15 and Q7. Design uses internal scratch buffer for getting good optimisation. These versions are optimised in cycles and consumes more memory (Scratch memory) compared to Q15 and Q7 versions of partial convolution */ /** @addtogroup PartialConv @{ */ /** @brief Partial convolution of floating-point sequences. @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the location where the output result is written @param[in] firstIndex is the first output sample to start with @param[in] numPoints is the number of output points to be computed @return execution status - \ref ARM_MATH_SUCCESS : Operation successful - \ref ARM_MATH_ARGUMENT_ERROR : requested subset is not in the range [0 srcALen+srcBLen-2] */ arm_status arm_conv_partial_f32( const float32_t * pSrcA, uint32_t srcALen, const float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst, uint32_t firstIndex, uint32_t numPoints) { #if (1) //#if !defined(ARM_MATH_CM0_FAMILY) const float32_t *pIn1 = pSrcA; /* InputA pointer */ const float32_t *pIn2 = pSrcB; /* InputB pointer */ float32_t *pOut = pDst; /* Output pointer */ const float32_t *px; /* Intermediate inputA pointer */ const float32_t *py; /* Intermediate inputB pointer */ const float32_t *pSrc1, *pSrc2; /* Intermediate pointers */ float32_t sum; /* Accumulator */ uint32_t j, k, count, blkCnt, check; int32_t blockSize1, blockSize2, blockSize3; /* Loop counters */ arm_status status; /* Status of Partial convolution */ #if defined (ARM_MATH_LOOPUNROLL) float32_t acc0, acc1, acc2, acc3; /* Accumulator */ float32_t x0, x1, x2, x3, c0; /* Temporary variables */ #endif /* Check for range of output samples to be calculated */ if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) { /* Set status as ARM_MATH_ARGUMENT_ERROR */ status = ARM_MATH_ARGUMENT_ERROR; } else { /* The algorithm implementation is based on the lengths of the inputs. */ /* srcB is always made to slide across srcA. */ /* So srcBLen is always considered as shorter or equal to srcALen */ if (srcALen >= srcBLen) { /* Initialization of inputA pointer */ pIn1 = pSrcA; /* Initialization of inputB pointer */ pIn2 = pSrcB; } else { /* Initialization of inputA pointer */ pIn1 = pSrcB; /* Initialization of inputB pointer */ pIn2 = pSrcA; /* srcBLen is always considered as shorter or equal to srcALen */ j = srcBLen; srcBLen = srcALen; srcALen = j; } /* Conditions to check which loopCounter holds * the first and last indices of the output samples to be calculated. */ check = firstIndex + numPoints; blockSize3 = ((int32_t)check > (int32_t)srcALen) ? (int32_t)check - (int32_t)srcALen : 0; blockSize3 = ((int32_t)firstIndex > (int32_t)srcALen - 1) ? blockSize3 - (int32_t)firstIndex + (int32_t)srcALen : blockSize3; blockSize1 = ((int32_t) srcBLen - 1) - (int32_t) firstIndex; blockSize1 = (blockSize1 > 0) ? ((check > (srcBLen - 1U)) ? blockSize1 : (int32_t) numPoints) : 0; blockSize2 = ((int32_t) check - blockSize3) - (blockSize1 + (int32_t) firstIndex); blockSize2 = (blockSize2 > 0) ? blockSize2 : 0; /* 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] */ /* The function is internally * divided into three stages according to the number of multiplications that has to be * taken place between inputA samples and inputB samples. In the first stage of the * algorithm, the multiplications increase by one for every iteration. * In the second stage of the algorithm, srcBLen number of multiplications are done. * In the third stage of the algorithm, the multiplications decrease by one * for every iteration. */ /* Set the output pointer to point to the firstIndex * of the output sample to be calculated. */ pOut = pDst + firstIndex; /* -------------------------- * Initializations of stage1 * -------------------------*/ /* sum = x[0] * y[0] * sum = x[0] * y[1] + x[1] * y[0] * .... * sum = x[0] * y[srcBlen - 1] + x[1] * y[srcBlen - 2] +...+ x[srcBLen - 1] * y[0] */ /* In this stage the MAC operations are increased by 1 for every iteration. The count variable holds the number of MAC operations performed. Since the partial convolution starts from firstIndex Number of Macs to be performed is firstIndex + 1 */ count = 1U + firstIndex; /* Working pointer of inputA */ px = pIn1; /* Working pointer of inputB */ pSrc1 = pIn2 + firstIndex; py = pSrc1; /* ------------------------ * Stage1 process * ----------------------*/ /* The first stage starts here */ while (blockSize1 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0.0f; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = count >> 2U; while (k > 0U) { /* x[0] * y[srcBLen - 1] */ sum += *px++ * *py--; /* x[1] * y[srcBLen - 2] */ sum += *px++ * *py--; /* x[2] * y[srcBLen - 3] */ sum += *px++ * *py--; /* x[3] * y[srcBLen - 4] */ sum += *px++ * *py--; /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = count % 0x4U; #else /* Initialize k with number of samples */ k = count; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = sum; /* Update the inputA and inputB pointers for next MAC calculation */ py = ++pSrc1; px = pIn1; /* Increment MAC count */ count++; /* Decrement loop counter */ blockSize1--; } /* -------------------------- * Initializations of stage2 * ------------------------*/ /* sum = x[0] * y[srcBLen-1] + x[1] * y[srcBLen-2] +...+ x[srcBLen-1] * y[0] * sum = x[1] * y[srcBLen-1] + x[2] * y[srcBLen-2] +...+ x[srcBLen] * y[0] * .... * sum = x[srcALen-srcBLen-2] * y[srcBLen-1] + x[srcALen] * y[srcBLen-2] +...+ x[srcALen-1] * y[0] */ /* Working pointer of inputA */ if ((int32_t)firstIndex - (int32_t)srcBLen + 1 > 0) { pSrc1 = pIn1 + firstIndex - srcBLen + 1; } else { pSrc1 = pIn1; } px = pSrc1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* count is index by which the pointer pIn1 to be incremented */ count = 0U; /* ------------------- * Stage2 process * ------------------*/ /* Stage2 depends on srcBLen as in this stage srcBLen number of MACS are performed. * So, to loop unroll over blockSize2, * srcBLen should be greater than or equal to 4 */ if (srcBLen >= 4U) { #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ blkCnt = ((uint32_t) blockSize2 >> 2U); while (blkCnt > 0U) { /* Set all accumulators to zero */ acc0 = 0.0f; acc1 = 0.0f; acc2 = 0.0f; acc3 = 0.0f; /* read x[0], x[1], x[2] samples */ x0 = *px++; x1 = *px++; x2 = *px++; /* Apply loop unrolling and compute 4 MACs simultaneously. */ k = srcBLen >> 2U; /* First part of the processing with loop unrolling. Compute 4 MACs at a time. ** a second loop below computes MACs for the remaining 1 to 3 samples. */ do { /* Read y[srcBLen - 1] sample */ c0 = *py--; /* Read x[3] sample */ x3 = *px++; /* Perform the multiply-accumulate */ /* acc0 += x[0] * y[srcBLen - 1] */ acc0 += x0 * c0; /* acc1 += x[1] * y[srcBLen - 1] */ acc1 += x1 * c0; /* acc2 += x[2] * y[srcBLen - 1] */ acc2 += x2 * c0; /* acc3 += x[3] * y[srcBLen - 1] */ acc3 += x3 * c0; /* Read y[srcBLen - 2] sample */ c0 = *py--; /* Read x[4] sample */ x0 = *px++; /* Perform the multiply-accumulate */ /* acc0 += x[1] * y[srcBLen - 2] */ acc0 += x1 * c0; /* acc1 += x[2] * y[srcBLen - 2] */ acc1 += x2 * c0; /* acc2 += x[3] * y[srcBLen - 2] */ acc2 += x3 * c0; /* acc3 += x[4] * y[srcBLen - 2] */ acc3 += x0 * c0; /* Read y[srcBLen - 3] sample */ c0 = *py--; /* Read x[5] sample */ x1 = *px++; /* Perform the multiply-accumulate */ /* acc0 += x[2] * y[srcBLen - 3] */ acc0 += x2 * c0; /* acc1 += x[3] * y[srcBLen - 2] */ acc1 += x3 * c0; /* acc2 += x[4] * y[srcBLen - 2] */ acc2 += x0 * c0; /* acc3 += x[5] * y[srcBLen - 2] */ acc3 += x1 * c0; /* Read y[srcBLen - 4] sample */ c0 = *py--; /* Read x[6] sample */ x2 = *px++; /* Perform the multiply-accumulate */ /* acc0 += x[3] * y[srcBLen - 4] */ acc0 += x3 * c0; /* acc1 += x[4] * y[srcBLen - 4] */ acc1 += x0 * c0; /* acc2 += x[5] * y[srcBLen - 4] */ acc2 += x1 * c0; /* acc3 += x[6] * y[srcBLen - 4] */ acc3 += x2 * c0; } while (--k); /* If the srcBLen is not a multiple of 4, compute any remaining MACs here. ** No loop unrolling is used. */ k = srcBLen % 0x4U; while (k > 0U) { /* Read y[srcBLen - 5] sample */ c0 = *py--; /* Read x[7] sample */ x3 = *px++; /* Perform the multiply-accumulates */ /* acc0 += x[4] * y[srcBLen - 5] */ acc0 += x0 * c0; /* acc1 += x[5] * y[srcBLen - 5] */ acc1 += x1 * c0; /* acc2 += x[6] * y[srcBLen - 5] */ acc2 += x2 * c0; /* acc3 += x[7] * y[srcBLen - 5] */ acc3 += x3 * c0; /* Reuse the present samples for the next MAC */ x0 = x1; x1 = x2; x2 = x3; /* Decrement the loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = acc0; *pOut++ = acc1; *pOut++ = acc2; *pOut++ = acc3; /* Increment the pointer pIn1 index, count by 4 */ count += 4U; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = (uint32_t) blockSize2 % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize2; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0.0f; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = srcBLen >> 2U; while (k > 0U) { /* Perform the multiply-accumulates */ sum += *px++ * *py--; sum += *px++ * *py--; sum += *px++ * *py--; sum += *px++ * *py--; /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = srcBLen % 0x4U; #else /* Initialize blkCnt with number of samples */ k = srcBLen; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ sum += *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = sum; /* Increment MAC count */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement loop counter */ blkCnt--; } } else { /* If the srcBLen is not a multiple of 4, * the blockSize2 loop cannot be unrolled by 4 */ blkCnt = (uint32_t) blockSize2; while (blkCnt > 0U) { /* Accumulator is made zero for every iteration */ sum = 0.0f; /* srcBLen number of MACS should be performed */ k = srcBLen; while (k > 0U) { /* Perform the multiply-accumulate */ sum += *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = sum; /* Increment the MAC count */ count++; /* Update the inputA and inputB pointers for next MAC calculation */ px = pSrc1 + count; py = pSrc2; /* Decrement the loop counter */ blkCnt--; } } /* -------------------------- * Initializations of stage3 * -------------------------*/ /* sum += x[srcALen-srcBLen+1] * y[srcBLen-1] + x[srcALen-srcBLen+2] * y[srcBLen-2] +...+ x[srcALen-1] * y[1] * sum += x[srcALen-srcBLen+2] * y[srcBLen-1] + x[srcALen-srcBLen+3] * y[srcBLen-2] +...+ x[srcALen-1] * y[2] * .... * sum += x[srcALen-2] * y[srcBLen-1] + x[srcALen-1] * y[srcBLen-2] * sum += x[srcALen-1] * y[srcBLen-1] */ /* In this stage the MAC operations are decreased by 1 for every iteration. The blockSize3 variable holds the number of MAC operations performed */ count = srcBLen - 1U; /* Working pointer of inputA */ pSrc1 = (pIn1 + srcALen) - (srcBLen - 1U); px = pSrc1; /* Working pointer of inputB */ pSrc2 = pIn2 + (srcBLen - 1U); py = pSrc2; /* ------------------- * Stage3 process * ------------------*/ while (blockSize3 > 0U) { /* Accumulator is made zero for every iteration */ sum = 0.0f; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ k = count >> 2U; while (k > 0U) { /* sum += x[srcALen - srcBLen + 1] * y[srcBLen - 1] */ sum += *px++ * *py--; /* sum += x[srcALen - srcBLen + 2] * y[srcBLen - 2] */ sum += *px++ * *py--; /* sum += x[srcALen - srcBLen + 3] * y[srcBLen - 3] */ sum += *px++ * *py--; /* sum += x[srcALen - srcBLen + 4] * y[srcBLen - 4] */ sum += *px++ * *py--; /* Decrement loop counter */ k--; } /* Loop unrolling: Compute remaining outputs */ k = count % 0x4U; #else /* Initialize blkCnt with number of samples */ k = count; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (k > 0U) { /* Perform the multiply-accumulate */ /* sum += x[srcALen-1] * y[srcBLen-1] */ sum += *px++ * *py--; /* Decrement loop counter */ k--; } /* Store the result in the accumulator in the destination buffer. */ *pOut++ = sum; /* Update the inputA and inputB pointers for next MAC calculation */ px = ++pSrc1; py = pSrc2; /* Decrement MAC count */ count--; /* Decrement the loop counter */ blockSize3--; } /* Set status as ARM_MATH_SUCCESS */ status = ARM_MATH_SUCCESS; } /* Return to application */ return (status); #else /* alternate version for CM0_FAMILY */ const float32_t *pIn1 = pSrcA; /* InputA pointer */ const float32_t *pIn2 = pSrcB; /* InputB pointer */ float32_t sum; /* Accumulator */ uint32_t i, j; /* Loop counters */ arm_status status; /* Status of Partial convolution */ /* Check for range of output samples to be calculated */ if ((firstIndex + numPoints) > ((srcALen + (srcBLen - 1U)))) { /* Set status as ARM_MATH_ARGUMENT_ERROR */ status = ARM_MATH_ARGUMENT_ERROR; } else { /* Loop to calculate convolution for output length number of values */ for (i = firstIndex; i <= (firstIndex + numPoints - 1); i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0.0f; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if (((i - j) < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += ( pIn1[j] * pIn2[i - j]); } } /* Store the output in the destination buffer */ pDst[i] = sum; } /* Set status as ARM_SUCCESS */ status = ARM_MATH_SUCCESS; } /* Return to application */ return (status); #endif /* #if !defined(ARM_MATH_CM0_FAMILY) */ } /** @} end of PartialConv group */
20,375
C
29.097489
154
0.51946
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_init_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_lms_norm_init_q15.c * Description: Q15 NLMS filter initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" #include "arm_common_tables.h" /** @addtogroup LMS_NORM @{ */ /** @brief Initialization function for Q15 normalized LMS filter. @param[in] S points to an instance of the Q15 normalized LMS filter structure. @param[in] numTaps number of filter coefficients. @param[in] pCoeffs points to coefficient buffer. @param[in] pState points to state buffer. @param[in] mu step size that controls filter coefficient updates. @param[in] blockSize number of samples to process. @param[in] postShift bit shift applied to coefficients. @return none @par Details <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: <pre> {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} </pre> The initial filter coefficients serve as a starting point for the adaptive filter. <code>pState</code> points to the array of state variables and size of array is <code>numTaps+blockSize-1</code> samples, where <code>blockSize</code> is the number of input samples processed by each call to <code>arm_lms_norm_q15()</code>. */ void arm_lms_norm_init_q15( arm_lms_norm_instance_q15 * S, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, q15_t mu, uint32_t blockSize, uint8_t postShift) { /* Assign filter taps */ S->numTaps = numTaps; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear state buffer and size is always blockSize + numTaps - 1 */ memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(q15_t)); /* Assign post Shift value applied to coefficients */ S->postShift = postShift; /* Assign state pointer */ S->pState = pState; /* Assign Step size value */ S->mu = mu; /* Initialize reciprocal pointer table */ S->recipTable = (q15_t *) armRecipTableQ15; /* Initialise Energy to zero */ S->energy = 0; /* Initialise x0 to zero */ S->x0 = 0; } /** @} end of LMS_NORM group */
3,193
C
31.262626
130
0.615096
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_biquad_cascade_df2T_f64.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_biquad_cascade_df2T_f64.c * Description: Processing function for floating-point transposed direct form II Biquad cascade filter * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @defgroup BiquadCascadeDF2T Biquad Cascade IIR Filters Using a Direct Form II Transposed Structure This set of functions implements arbitrary order recursive (IIR) filters using a transposed direct form II structure. The filters are implemented as a cascade of second order Biquad sections. These functions provide a slight memory savings as compared to the direct form I Biquad filter functions. Only floating-point data is supported. This function operate on blocks of input and output data and each call to the function processes <code>blockSize</code> samples through the filter. <code>pSrc</code> points to the array of input data and <code>pDst</code> points to the array of output data. Both arrays contain <code>blockSize</code> values. @par Algorithm Each Biquad stage implements a second order filter using the difference equation: <pre> y[n] = b0 * x[n] + d1 d1 = b1 * x[n] + a1 * y[n] + d2 d2 = b2 * x[n] + a2 * y[n] </pre> where d1 and d2 represent the two state values. @par A Biquad filter using a transposed Direct Form II structure is shown below. \image html BiquadDF2Transposed.gif "Single transposed Direct Form II Biquad" Coefficients <code>b0, b1, and b2 </code> multiply the input signal <code>x[n]</code> and are referred to as the feedforward coefficients. Coefficients <code>a1</code> and <code>a2</code> multiply the output signal <code>y[n]</code> and are referred to as the feedback coefficients. Pay careful attention to the sign of the feedback coefficients. Some design tools flip the sign of the feedback coefficients: <pre> y[n] = b0 * x[n] + d1; d1 = b1 * x[n] - a1 * y[n] + d2; d2 = b2 * x[n] - a2 * y[n]; </pre> In this case the feedback coefficients <code>a1</code> and <code>a2</code> must be negated when used with the CMSIS DSP Library. @par Higher order filters are realized as a cascade of second order sections. <code>numStages</code> refers to the number of second order stages used. For example, an 8th order filter would be realized with <code>numStages=4</code> second order stages. A 9th order filter would be realized with <code>numStages=5</code> second order stages with the coefficients for one of the stages configured as a first order filter (<code>b2=0</code> and <code>a2=0</code>). @par <code>pState</code> points to the state variable array. Each Biquad stage has 2 state variables <code>d1</code> and <code>d2</code>. The state variables are arranged in the <code>pState</code> array as: <pre> {d11, d12, d21, d22, ...} </pre> where <code>d1x</code> refers to the state variables for the first Biquad and <code>d2x</code> refers to the state variables for the second Biquad. The state array has a total length of <code>2*numStages</code> values. The state variables are updated after each block of data is processed; the coefficients are untouched. @par The CMSIS library contains Biquad filters in both Direct Form I and transposed Direct Form II. The advantage of the Direct Form I structure is that it is numerically more robust for fixed-point data types. That is why the Direct Form I structure supports Q15 and Q31 data types. The transposed Direct Form II structure, on the other hand, requires a wide dynamic range for the state variables <code>d1</code> and <code>d2</code>. Because of this, the CMSIS library only has a floating-point version of the Direct Form II Biquad. The advantage of the Direct Form II Biquad is that it requires half the number of state variables, 2 rather than 4, per Biquad stage. @par Instance Structure The coefficients and state variables for a filter are stored together in an instance data structure. A separate instance structure must be defined for each filter. Coefficient arrays may be shared among several instances while state variable arrays cannot be shared. @par Init Functions There is also an associated initialization function. The initialization function performs following operations: - Sets the values of the internal structure fields. - Zeros out the values in the state buffer. To do this manually without calling the init function, assign the follow subfields of the instance structure: numStages, pCoeffs, pState. Also set all of the values in pState to zero. @par Use of the initialization function is optional. However, if the initialization function is used, then the instance structure cannot be placed into a const data section. To place an instance structure into a const data section, the instance structure must be manually initialized. Set the values in the state buffer to zeros before static initialization. For example, to statically initialize the instance structure use <pre> arm_biquad_cascade_df2T_instance_f64 S1 = {numStages, pState, pCoeffs}; arm_biquad_cascade_df2T_instance_f32 S1 = {numStages, pState, pCoeffs}; </pre> where <code>numStages</code> is the number of Biquad stages in the filter; <code>pState</code> is the address of the state buffer. <code>pCoeffs</code> is the address of the coefficient buffer; */ /** @addtogroup BiquadCascadeDF2T @{ */ /** @brief Processing function for the floating-point transposed direct form II Biquad cascade filter. @param[in] S points to an instance of the filter data structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none */ LOW_OPTIMIZATION_ENTER void arm_biquad_cascade_df2T_f64( const arm_biquad_cascade_df2T_instance_f64 * S, float64_t * pSrc, float64_t * pDst, uint32_t blockSize) { float64_t *pIn = pSrc; /* Source pointer */ float64_t *pOut = pDst; /* Destination pointer */ float64_t *pState = S->pState; /* State pointer */ float64_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float64_t acc1; /* Accumulator */ float64_t b0, b1, b2, a1, a2; /* Filter coefficients */ float64_t Xn1; /* Temporary input */ float64_t d1, d2; /* State variables */ uint32_t sample, stage = S->numStages; /* Loop counters */ do { /* Reading the coefficients */ b0 = pCoeffs[0]; b1 = pCoeffs[1]; b2 = pCoeffs[2]; a1 = pCoeffs[3]; a2 = pCoeffs[4]; /* Reading the state values */ d1 = pState[0]; d2 = pState[1]; pCoeffs += 5U; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 16 outputs at a time */ sample = blockSize >> 4U; while (sample > 0U) { /* y[n] = b0 * x[n] + d1 */ /* d1 = b1 * x[n] + a1 * y[n] + d2 */ /* d2 = b2 * x[n] + a2 * y[n] */ /* 1 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 2 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 3 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 4 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 5 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 6 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 7 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 8 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 9 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 10 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 11 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 12 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 13 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 14 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 15 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* 16 */ Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* decrement loop counter */ sample--; } /* Loop unrolling: Compute remaining outputs */ sample = blockSize & 0xFU; #else /* Initialize blkCnt with number of samples */ sample = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (sample > 0U) { Xn1 = *pIn++; acc1 = b0 * Xn1 + d1; d1 = b1 * Xn1 + d2; d1 += a1 * acc1; d2 = b2 * Xn1; d2 += a2 * acc1; *pOut++ = acc1; /* decrement loop counter */ sample--; } /* Store the updated state variables back into the state array */ pState[0] = d1; pState[1] = d2; pState += 2U; /* The current stage input is given as the output to the next stage */ pIn = pDst; /* Reset the output working pointer */ pOut = pDst; /* decrement loop counter */ stage--; } while (stage > 0U); } LOW_OPTIMIZATION_EXIT /** @} end of BiquadCascadeDF2T group */
13,152
C
28.623874
169
0.530186
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_conv_opt_q7.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_conv_opt_q7.c * Description: Convolution of Q7 sequences * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup Conv @{ */ /** @brief Convolution of Q7 sequences. @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1. @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen). @return none @par Scaling and Overflow Behavior The function is implemented using a 32-bit internal accumulator. Both the inputs are represented in 1.7 format and multiplications yield a 2.14 result. The 2.14 intermediate results are accumulated in a 32-bit accumulator in 18.14 format. This approach provides 17 guard bits and there is no risk of overflow as long as <code>max(srcALen, srcBLen)<131072</code>. The 18.14 result is then truncated to 18.7 format by discarding the low 7 bits and then saturated to 1.7 format. */ void arm_conv_opt_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, q15_t * pScratch1, q15_t * pScratch2) { q15_t *pScr1 = pScratch1; /* Temporary pointer for scratch */ q15_t *pScr2 = pScratch2; /* Temporary pointer for scratch */ q15_t x4; /* Temporary input variable */ q15_t *py; /* Temporary input2 pointer */ q31_t acc0, acc1, acc2, acc3; /* Accumulators */ const q7_t *pIn1, *pIn2; /* InputA and inputB pointer */ uint32_t j, k, blkCnt, tapCnt; /* Loop counter */ q31_t x1, x2, x3, y1; /* Temporary input variables */ const q7_t *px; /* Temporary input1 pointer */ q7_t *pOut = pDst; /* Output pointer */ q7_t out0, out1, out2, out3; /* Temporary variables */ /* The algorithm implementation is based on the lengths of the inputs. */ /* srcB is always made to slide across srcA. */ /* So srcBLen is always considered as shorter or equal to srcALen */ if (srcALen >= srcBLen) { /* Initialization of inputA pointer */ pIn1 = pSrcA; /* Initialization of inputB pointer */ pIn2 = pSrcB; } else { /* Initialization of inputA pointer */ pIn1 = pSrcB; /* Initialization of inputB pointer */ pIn2 = pSrcA; /* srcBLen is always considered as shorter or equal to srcALen */ j = srcBLen; srcBLen = srcALen; srcALen = j; } /* points to smaller length sequence */ px = pIn2 + srcBLen - 1; /* Apply loop unrolling and do 4 Copies simultaneously. */ k = srcBLen >> 2U; /* First part of the processing with loop unrolling copies 4 data points at a time. ** a second loop below copies for the remaining 1 to 3 samples. */ while (k > 0U) { /* copy second buffer in reversal manner */ x4 = (q15_t) *px--; *pScr2++ = x4; x4 = (q15_t) *px--; *pScr2++ = x4; x4 = (q15_t) *px--; *pScr2++ = x4; x4 = (q15_t) *px--; *pScr2++ = x4; /* Decrement loop counter */ k--; } /* If the count is not a multiple of 4, copy remaining samples here. ** No loop unrolling is used. */ k = srcBLen % 0x4U; while (k > 0U) { /* copy second buffer in reversal manner for remaining samples */ x4 = (q15_t) *px--; *pScr2++ = x4; /* Decrement loop counter */ k--; } /* Fill (srcBLen - 1U) zeros in scratch buffer */ arm_fill_q15(0, pScr1, (srcBLen - 1U)); /* Update temporary scratch pointer */ pScr1 += (srcBLen - 1U); /* Copy (srcALen) samples in scratch buffer */ /* Apply loop unrolling and do 4 Copies simultaneously. */ k = srcALen >> 2U; /* First part of the processing with loop unrolling copies 4 data points at a time. ** a second loop below copies for the remaining 1 to 3 samples. */ while (k > 0U) { /* copy second buffer in reversal manner */ x4 = (q15_t) *pIn1++; *pScr1++ = x4; x4 = (q15_t) *pIn1++; *pScr1++ = x4; x4 = (q15_t) *pIn1++; *pScr1++ = x4; x4 = (q15_t) *pIn1++; *pScr1++ = x4; /* Decrement loop counter */ k--; } /* If the count is not a multiple of 4, copy remaining samples here. ** No loop unrolling is used. */ k = srcALen % 0x4U; while (k > 0U) { /* copy second buffer in reversal manner for remaining samples */ x4 = (q15_t) * pIn1++; *pScr1++ = x4; /* Decrement the loop counter */ k--; } /* Fill (srcBLen - 1U) zeros at end of scratch buffer */ arm_fill_q15(0, pScr1, (srcBLen - 1U)); /* Update pointer */ pScr1 += (srcBLen - 1U); /* Temporary pointer for scratch2 */ py = pScratch2; /* Initialization of pIn2 pointer */ pIn2 = (q7_t *) py; pScr2 = py; /* Actual convolution process starts here */ blkCnt = (srcALen + srcBLen - 1U) >> 2U; while (blkCnt > 0) { /* Initialze temporary scratch pointer as scratch1 */ pScr1 = pScratch1; /* Clear Accumlators */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* Read two samples from scratch1 buffer */ x1 = read_q15x2_ia (&pScr1); /* Read next two samples from scratch1 buffer */ x2 = read_q15x2_ia (&pScr1); tapCnt = (srcBLen) >> 2U; while (tapCnt > 0U) { /* Read four samples from smaller buffer */ y1 = read_q15x2_ia (&pScr2); /* multiply and accumlate */ acc0 = __SMLAD(x1, y1, acc0); acc2 = __SMLAD(x2, y1, acc2); /* pack input data */ #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x2, x1, 0); #else x3 = __PKHBT(x1, x2, 0); #endif /* multiply and accumlate */ acc1 = __SMLADX(x3, y1, acc1); /* Read next two samples from scratch1 buffer */ x1 = read_q15x2_ia (&pScr1); /* pack input data */ #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x1, x2, 0); #else x3 = __PKHBT(x2, x1, 0); #endif acc3 = __SMLADX(x3, y1, acc3); /* Read four samples from smaller buffer */ y1 = read_q15x2_ia (&pScr2); acc0 = __SMLAD(x2, y1, acc0); acc2 = __SMLAD(x1, y1, acc2); acc1 = __SMLADX(x3, y1, acc1); x2 = read_q15x2_ia (&pScr1); #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x2, x1, 0); #else x3 = __PKHBT(x1, x2, 0); #endif acc3 = __SMLADX(x3, y1, acc3); /* Decrement loop counter */ tapCnt--; } /* Update scratch pointer for remaining samples of smaller length sequence */ pScr1 -= 4U; /* apply same above for remaining samples of smaller length sequence */ tapCnt = (srcBLen) & 3U; while (tapCnt > 0U) { /* accumlate the results */ acc0 += (*pScr1++ * *pScr2); acc1 += (*pScr1++ * *pScr2); acc2 += (*pScr1++ * *pScr2); acc3 += (*pScr1++ * *pScr2++); pScr1 -= 3U; /* Decrement loop counter */ tapCnt--; } blkCnt--; /* Store the result in the accumulator in the destination buffer. */ out0 = (q7_t) (__SSAT(acc0 >> 7U, 8)); out1 = (q7_t) (__SSAT(acc1 >> 7U, 8)); out2 = (q7_t) (__SSAT(acc2 >> 7U, 8)); out3 = (q7_t) (__SSAT(acc3 >> 7U, 8)); write_q7x4_ia (&pOut, __PACKq7(out0, out1, out2, out3)); /* Initialization of inputB pointer */ pScr2 = py; pScratch1 += 4U; } blkCnt = (srcALen + srcBLen - 1U) & 0x3; /* Calculate convolution for remaining samples of Bigger length sequence */ while (blkCnt > 0) { /* Initialze temporary scratch pointer as scratch1 */ pScr1 = pScratch1; /* Clear Accumlators */ acc0 = 0; tapCnt = (srcBLen) >> 1U; while (tapCnt > 0U) { acc0 += (*pScr1++ * *pScr2++); acc0 += (*pScr1++ * *pScr2++); /* Decrement loop counter */ tapCnt--; } tapCnt = (srcBLen) & 1U; /* apply same above for remaining samples of smaller length sequence */ while (tapCnt > 0U) { /* accumlate the results */ acc0 += (*pScr1++ * *pScr2++); /* Decrement loop counter */ tapCnt--; } blkCnt--; /* Store the result in the accumulator in the destination buffer. */ *pOut++ = (q7_t) (__SSAT(acc0 >> 7U, 8)); /* Initialization of inputB pointer */ pScr2 = py; pScratch1 += 1U; } } /** @} end of Conv group */
9,912
C
26.459834
142
0.562349
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_correlate_fast_opt_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_correlate_fast_opt_q15.c * Description: Fast Q15 Correlation * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup Corr @{ */ /** @brief Correlation of Q15 sequences (fast version). @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence. @param[out] pDst points to the location where the output result is written. Length 2 * max(srcALen, srcBLen) - 1. @param[in] pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. @return none @par Scaling and Overflow Behavior This fast version uses a 32-bit accumulator with 2.30 format. The accumulator maintains full precision of the intermediate multiplication results but provides only a single guard bit. There is no saturation on intermediate additions. Thus, if the accumulator overflows it wraps around and distorts the result. The input signals should be scaled down to avoid intermediate overflows. Scale down one of the inputs by 1/min(srcALen, srcBLen) to avoid overflow since a maximum of min(srcALen, srcBLen) number of additions is carried internally. The 2.30 accumulator is right shifted by 15 bits and then saturated to 1.15 format to yield the final result. @remark Refer to \ref arm_correlate_q15() for a slower implementation of this function which uses a 64-bit accumulator to avoid wrap around distortion. */ void arm_correlate_fast_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch) { const q15_t *pIn1; /* InputA pointer */ const q15_t *pIn2; /* InputB pointer */ q31_t acc0; /* Accumulators */ q15_t *pOut = pDst; /* Output pointer */ q15_t *pScr1 = pScratch; /* Temporary pointer for scratch */ const q15_t *py; /* Intermediate inputB pointer */ uint32_t j, blkCnt, outBlockSize; /* Loop counter */ int32_t inc = 1; /* Destination address modifier */ uint32_t tapCnt; /* Loop count */ #if defined (ARM_MATH_LOOPUNROLL) q31_t acc1, acc2, acc3; /* Accumulators */ q31_t x1, x2, x3; /* Temporary variables for holding input and coefficient values */ q31_t y1, y2; /* State variables */ #endif /* The algorithm implementation is based on the lengths of the inputs. */ /* srcB is always made to slide across srcA. */ /* So srcBLen is always considered as shorter or equal to srcALen */ /* But CORR(x, y) is reverse of CORR(y, x) */ /* So, when srcBLen > srcALen, output pointer is made to point to the end of the output buffer */ /* and the destination pointer modifier, inc is set to -1 */ /* If srcALen > srcBLen, zero pad has to be done to srcB to make the two inputs of same length */ /* But to improve the performance, * we include zeroes in the output instead of zero padding either of the the inputs*/ /* If srcALen > srcBLen, * (srcALen - srcBLen) zeroes has to included in the starting of the output buffer */ /* If srcALen < srcBLen, * (srcALen - srcBLen) zeroes has to included in the ending of the output buffer */ if (srcALen >= srcBLen) { /* Initialization of inputA pointer */ pIn1 = pSrcA; /* Initialization of inputB pointer */ pIn2 = pSrcB; /* Number of output samples is calculated */ outBlockSize = (2U * srcALen) - 1U; /* When srcALen > srcBLen, zero padding is done to srcB * to make their lengths equal. * Instead, (outBlockSize - (srcALen + srcBLen - 1)) * number of output samples are made zero */ j = outBlockSize - (srcALen + (srcBLen - 1U)); /* Updating the pointer position to non zero value */ pOut += j; } else { /* Initialization of inputA pointer */ pIn1 = pSrcB; /* Initialization of inputB pointer */ pIn2 = pSrcA; /* srcBLen is always considered as shorter or equal to srcALen */ j = srcBLen; srcBLen = srcALen; srcALen = j; /* CORR(x, y) = Reverse order(CORR(y, x)) */ /* Hence set the destination pointer to point to the last output sample */ pOut = pDst + ((srcALen + srcBLen) - 2U); /* Destination address modifier is set to -1 */ inc = -1; } pScr1 = pScratch; /* Fill (srcBLen - 1U) zeros in scratch buffer */ arm_fill_q15(0, pScr1, (srcBLen - 1U)); /* Update temporary scratch pointer */ pScr1 += (srcBLen - 1U); /* Copy (srcALen) samples in scratch buffer */ arm_copy_q15(pIn1, pScr1, srcALen); /* Update pointers */ pScr1 += srcALen; /* Fill (srcBLen - 1U) zeros at end of scratch buffer */ arm_fill_q15(0, pScr1, (srcBLen - 1U)); /* Update pointer */ pScr1 += (srcBLen - 1U); /* Temporary pointer for scratch2 */ py = pIn2; /* Actual correlation process starts here */ #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ blkCnt = (srcALen + srcBLen - 1U) >> 2; while (blkCnt > 0) { /* Initialze temporary scratch pointer as scratch1 */ pScr1 = pScratch; /* Clear Accumlators */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* Read two samples from scratch buffer */ x1 = read_q15x2_ia (&pScr1); /* Read next two samples from scratch buffer */ x2 = read_q15x2_ia (&pScr1); tapCnt = (srcBLen) >> 2U; while (tapCnt > 0U) { /* Read four samples from smaller buffer */ y1 = read_q15x2_ia ((q15_t **) &pIn2); y2 = read_q15x2_ia ((q15_t **) &pIn2); /* multiply and accumlate */ acc0 = __SMLAD(x1, y1, acc0); acc2 = __SMLAD(x2, y1, acc2); /* pack input data */ #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x2, x1, 0); #else x3 = __PKHBT(x1, x2, 0); #endif /* multiply and accumlate */ acc1 = __SMLADX(x3, y1, acc1); /* Read next two samples from scratch buffer */ x1 = read_q15x2_ia (&pScr1); /* multiply and accumlate */ acc0 = __SMLAD(x2, y2, acc0); acc2 = __SMLAD(x1, y2, acc2); /* pack input data */ #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x1, x2, 0); #else x3 = __PKHBT(x2, x1, 0); #endif acc3 = __SMLADX(x3, y1, acc3); acc1 = __SMLADX(x3, y2, acc1); x2 = read_q15x2_ia (&pScr1); #ifndef ARM_MATH_BIG_ENDIAN x3 = __PKHBT(x2, x1, 0); #else x3 = __PKHBT(x1, x2, 0); #endif acc3 = __SMLADX(x3, y2, acc3); /* Decrement loop counter */ tapCnt--; } /* Update scratch pointer for remaining samples of smaller length sequence */ pScr1 -= 4U; /* apply same above for remaining samples of smaller length sequence */ tapCnt = (srcBLen) & 3U; while (tapCnt > 0U) { /* accumlate the results */ acc0 += (*pScr1++ * *pIn2); acc1 += (*pScr1++ * *pIn2); acc2 += (*pScr1++ * *pIn2); acc3 += (*pScr1++ * *pIn2++); pScr1 -= 3U; /* Decrement loop counter */ tapCnt--; } blkCnt--; /* Store the results in the accumulators in the destination buffer. */ *pOut = (__SSAT(acc0 >> 15U, 16)); pOut += inc; *pOut = (__SSAT(acc1 >> 15U, 16)); pOut += inc; *pOut = (__SSAT(acc2 >> 15U, 16)); pOut += inc; *pOut = (__SSAT(acc3 >> 15U, 16)); pOut += inc; /* Initialization of inputB pointer */ pIn2 = py; pScratch += 4U; } /* Loop unrolling: Compute remaining outputs */ blkCnt = (srcALen + srcBLen - 1U) & 0x3; #else /* Initialize blkCnt with number of samples */ blkCnt = (srcALen + srcBLen - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Calculate correlation for remaining samples of Bigger length sequence */ while (blkCnt > 0) { /* Initialze temporary scratch pointer as scratch1 */ pScr1 = pScratch; /* Clear Accumlators */ acc0 = 0; tapCnt = (srcBLen) >> 1U; while (tapCnt > 0U) { /* Read next two samples from scratch buffer */ acc0 += (*pScr1++ * *pIn2++); acc0 += (*pScr1++ * *pIn2++); /* Decrement loop counter */ tapCnt--; } tapCnt = (srcBLen) & 1U; /* apply same above for remaining samples of smaller length sequence */ while (tapCnt > 0U) { /* accumlate the results */ acc0 += (*pScr1++ * *pIn2++); /* Decrement loop counter */ tapCnt--; } blkCnt--; /* The result is in 2.30 format. Convert to 1.15 with saturation. ** Then store the output in the destination buffer. */ *pOut = (q15_t) (__SSAT((acc0 >> 15), 16)); pOut += inc; /* Initialization of inputB pointer */ pIn2 = py; pScratch += 1U; } } /** @} end of Corr group */
10,311
C
28.803468
162
0.577151
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_decimate_fast_q31.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_decimate_fast_q31.c * Description: Fast Q31 FIR Decimator * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR_decimate @{ */ /** @brief Processing function for the Q31 FIR decimator (fast variant). @param[in] S points to an instance of the Q31 FIR decimator structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior This function is optimized for speed at the expense of fixed-point precision and overflow protection. The result of each 1.31 x 1.31 multiplication is truncated to 2.30 format. These intermediate results are added to a 2.30 accumulator. Finally, the accumulator is saturated and converted to a 1.31 result. The fast version has the same overflow behavior as the standard version and provides less precision since it discards the low 32 bits of each multiplication result. In order to avoid overflows completely the input signal must be scaled down by log2(numTaps) bits (where log2 is read as log to the base 2). @remark Refer to \ref arm_fir_decimate_q31() for a slower implementation of this function which uses a 64-bit accumulator to provide higher precision. Both the slow and the fast versions use the same instance structure. Use function \ref arm_fir_decimate_init_q31() to initialize the filter structure. */ void arm_fir_decimate_fast_q31( const arm_fir_decimate_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCur; /* Points to the current sample of the state */ q31_t *px0; /* Temporary pointer for state buffer */ const q31_t *pb; /* Temporary pointer for coefficient buffer */ q31_t x0, c0; /* Temporary variables to hold state and coefficient values */ q63_t acc0; /* Accumulator */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i, tapCnt, blkCnt, outBlockSize = blockSize / S->M; /* Loop counters */ #if defined (ARM_MATH_LOOPUNROLL) q31_t *px1, *px2, *px3; q31_t x1, x2, x3; q63_t acc1, acc2, acc3; #endif /* S->pState buffer contains previous frame (numTaps - 1) samples */ /* pStateCur points to the location where the new input data should be written */ pStateCur = S->pState + (numTaps - 1U); #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 samples at a time */ blkCnt = outBlockSize >> 2U; /* Samples loop unrolled by 4 */ while (blkCnt > 0U) { /* Copy 4 * decimation factor number of new input samples into the state buffer */ i = S->M * 4; do { *pStateCur++ = *pSrc++; } while (--i); /* Set accumulators to zero */ acc0 = 0; acc1 = 0; acc2 = 0; acc3 = 0; /* Initialize state pointer for all the samples */ px0 = pState; px1 = pState + S->M; px2 = pState + 2 * S->M; px3 = pState + 3 * S->M; /* Initialize coeff pointer */ pb = pCoeffs; /* Loop unrolling: Compute 4 taps at a time */ tapCnt = numTaps >> 2U; while (tapCnt > 0U) { /* Read the b[numTaps-1] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-1] sample for acc0 */ x0 = *(px0++); /* Read x[n-numTaps-1] sample for acc1 */ x1 = *(px1++); /* Read x[n-numTaps-1] sample for acc2 */ x2 = *(px2++); /* Read x[n-numTaps-1] sample for acc3 */ x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); /* Read the b[numTaps-2] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-2] sample for acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); /* Read the b[numTaps-3] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-3] sample acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); /* Read the b[numTaps-4] coefficient */ c0 = *(pb++); /* Read x[n-numTaps-4] sample acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; while (tapCnt > 0U) { /* Read coefficients */ c0 = *(pb++); /* Fetch state variables for acc0, acc1, acc2, acc3 */ x0 = *(px0++); x1 = *(px1++); x2 = *(px2++); x3 = *(px3++); /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); acc1 = (q31_t) ((((q63_t) acc1 << 32) + ((q63_t) x1 * c0)) >> 32); acc2 = (q31_t) ((((q63_t) acc2 << 32) + ((q63_t) x2 * c0)) >> 32); acc3 = (q31_t) ((((q63_t) acc3 << 32) + ((q63_t) x3 * c0)) >> 32); /* Decrement loop counter */ tapCnt--; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M * 4; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q31_t) (acc0 << 1); *pDst++ = (q31_t) (acc1 << 1); *pDst++ = (q31_t) (acc2 << 1); *pDst++ = (q31_t) (acc3 << 1); /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining samples */ blkCnt = outBlockSize % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = outBlockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Copy decimation factor number of new input samples into the state buffer */ i = S->M; do { *pStateCur++ = *pSrc++; } while (--i); /* Set accumulator to zero */ acc0 = 0; /* Initialize state pointer */ px0 = pState; /* Initialize coeff pointer */ pb = pCoeffs; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time */ tapCnt = numTaps >> 2U; while (tapCnt > 0U) { /* Read the b[numTaps-1] coefficient */ c0 = *pb++; /* Read x[n-numTaps-1] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); /* Read the b[numTaps-2] coefficient */ c0 = *pb++; /* Read x[n-numTaps-2] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); /* Read the b[numTaps-3] coefficient */ c0 = *pb++; /* Read x[n-numTaps-3] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); /* Read the b[numTaps-4] coefficient */ c0 = *pb++; /* Read x[n-numTaps-4] sample */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; #else /* Initialize tapCnt with number of taps */ tapCnt = numTaps; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Read coefficients */ c0 = *pb++; /* Fetch 1 state variable */ x0 = *px0++; /* Perform the multiply-accumulate */ acc0 = (q31_t) ((((q63_t) acc0 << 32) + ((q63_t) x0 * c0)) >> 32); /* Decrement loop counter */ tapCnt--; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q31_t) (acc0 << 1); /* Decrement loop counter */ blkCnt--; } /* Processing is complete. Now copy the last numTaps - 1 samples to the satrt of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCur = S->pState; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time */ tapCnt = (numTaps - 1U) >> 2U; /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; *pStateCur++ = *pState++; *pStateCur++ = *pState++; *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = (numTaps - 1U) % 0x04U; #else /* Initialize tapCnt with number of taps */ tapCnt = (numTaps - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } } /** @} end of FIR_decimate group */
11,800
C
29.181586
183
0.533305
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_lms_norm_q15.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_lms_norm_q15.c * Description: Processing function for Q15 normalized LMS filter * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup LMS_NORM @{ */ /** @brief Processing function for Q15 normalized LMS filter. @param[in] S points to an instance of the Q15 normalized LMS filter structure @param[in] pSrc points to the block of input data @param[in] pRef points to the block of reference data @param[out] pOut points to the block of output data @param[out] pErr points to the block of error data @param[in] blockSize number of samples to process @return none @par Scaling and Overflow Behavior The function is implemented using a 64-bit internal accumulator. Both coefficients and state variables are represented in 1.15 format and multiplications yield a 2.30 result. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. Lastly, the accumulator is saturated to yield a result in 1.15 format. @par In this filter, filter coefficients are updated for each sample and the updation of filter cofficients are saturted. */ void arm_lms_norm_q15( arm_lms_norm_instance_q15 * S, const q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ q15_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ q15_t mu = S->mu; /* Adaptive factor */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t tapCnt, blkCnt; /* Loop counters */ q63_t acc; /* Accumulator */ q31_t energy; /* Energy of the input */ q15_t e = 0, d = 0; /* Error, reference data sample */ q15_t w = 0, in; /* Weight factor and state */ q15_t x0; /* Temporary variable to hold input sample */ q15_t errorXmu, oneByEnergy; /* Temporary variables to store error and mu product and reciprocal of energy */ q15_t postShift; /* Post shift to be applied to weight after reciprocal calculation */ q31_t coef; /* Temporary variable for coefficient */ q31_t acc_l, acc_h; /* Temporary input */ int32_t lShift = (15 - (int32_t) S->postShift); /* Post shift */ int32_t uShift = (32 - lShift); energy = S->energy; x0 = S->x0; /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); /* initialise loop count */ blkCnt = blockSize; while (blkCnt > 0U) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc; /* Initialize pState pointer */ px = pState; /* Initialize coefficient pointer */ pb = pCoeffs; /* Read the sample from input buffer */ in = *pSrc++; /* Update the energy calculation */ energy -= (((q31_t) x0 * (x0)) >> 15); energy += (((q31_t) in * (in)) >> 15); /* Set the accumulator to zero */ acc = 0; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = numTaps >> 2U; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ /* acc += b[N] * x[n-N] + b[N-1] * x[n-N-1] */ acc = __SMLALD(read_q15x2_ia (&px), read_q15x2_ia (&pb), acc); acc = __SMLALD(read_q15x2_ia (&px), read_q15x2_ia (&pb), acc); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = numTaps; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ acc += (q63_t) (((q31_t) (*px++) * (*pb++))); /* Decrement the loop counter */ tapCnt--; } /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; /* Apply shift for lower part of acc and upper part of acc */ acc = (uint32_t) acc_l >> lShift | acc_h << uShift; /* Converting the result to 1.15 format and saturate the output */ acc = __SSAT(acc, 16U); /* Store the result from accumulator into the destination buffer. */ *pOut++ = (q15_t) acc; /* Compute and store error */ d = *pRef++; e = d - (q15_t) acc; *pErr++ = e; /* Calculation of 1/energy */ postShift = arm_recip_q15((q15_t) energy + DELTA_Q15, &oneByEnergy, S->recipTable); /* Calculation of e * mu value */ errorXmu = (q15_t) (((q31_t) e * mu) >> 15); /* Calculation of (e * mu) * (1/energy) value */ acc = (((q31_t) errorXmu * oneByEnergy) >> (15 - postShift)); /* Weighting factor for the normalized version */ w = (q15_t) __SSAT((q31_t) acc, 16); /* Initialize pState pointer */ px = pState; /* Initialize coefficient pointer */ pb = pCoeffs; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = numTaps >> 2U; /* Update filter coefficients */ while (tapCnt > 0U) { coef = (q31_t) *pb + (((q31_t) w * (*px++)) >> 15); *pb++ = (q15_t) __SSAT(coef, 16); coef = (q31_t) *pb + (((q31_t) w * (*px++)) >> 15); *pb++ = (q15_t) __SSAT(coef, 16); coef = (q31_t) *pb + (((q31_t) w * (*px++)) >> 15); *pb++ = (q15_t) __SSAT(coef, 16); coef = (q31_t) *pb + (((q31_t) w * (*px++)) >> 15); *pb++ = (q15_t) __SSAT(coef, 16); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = numTaps % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = numTaps; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ coef = (q31_t) *pb + (((q31_t) w * (*px++)) >> 15); *pb++ = (q15_t) __SSAT(coef, 16); /* Decrement loop counter */ tapCnt--; } x0 = *pState; /* Advance state pointer by 1 for the next sample */ pState = pState + 1; /* Decrement loop counter */ blkCnt--; } /* Save energy and x0 values for the next frame */ S->energy = (q15_t) energy; S->x0 = x0; /* Processing is complete. Now copy the last numTaps - 1 samples to the start of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the pState buffer */ pStateCurnt = S->pState; /* copy data */ #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 taps at a time. */ tapCnt = (numTaps - 1U) >> 2U; while (tapCnt > 0U) { write_q15x2_ia (&pStateCurnt, read_q15x2_ia (&pState)); write_q15x2_ia (&pStateCurnt, read_q15x2_ia (&pState)); /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining taps */ tapCnt = (numTaps - 1U) % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = (numTaps - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement loop counter */ tapCnt--; } } /** @} end of LMS_NORM group */
9,383
C
30.489933
135
0.552595
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_interpolate_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_interpolate_f32.c * Description: Floating-point FIR interpolation sequences * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @defgroup FIR_Interpolate Finite Impulse Response (FIR) Interpolator These functions combine an upsampler (zero stuffer) and an FIR filter. They are used in multirate systems for increasing the sample rate of a signal without introducing high frequency images. Conceptually, the functions are equivalent to the block diagram below: \image html FIRInterpolator.gif "Components included in the FIR Interpolator functions" After upsampling by a factor of <code>L</code>, the signal should be filtered by a lowpass filter with a normalized cutoff frequency of <code>1/L</code> in order to eliminate high frequency copies of the spectrum. The user of the function is responsible for providing the filter coefficients. The FIR interpolator functions provided in the CMSIS DSP Library combine the upsampler and FIR filter in an efficient manner. The upsampler inserts <code>L-1</code> zeros between each sample. Instead of multiplying by these zero values, the FIR filter is designed to skip them. This leads to an efficient implementation without any wasted effort. The functions operate on blocks of input and output data. <code>pSrc</code> points to an array of <code>blockSize</code> input values and <code>pDst</code> points to an array of <code>blockSize*L</code> output values. The library provides separate functions for Q15, Q31, and floating-point data types. @par Algorithm The functions use a polyphase filter structure: <pre> y[n] = b[0] * x[n] + b[L] * x[n-1] + ... + b[L*(phaseLength-1)] * x[n-phaseLength+1] y[n+1] = b[1] * x[n] + b[L+1] * x[n-1] + ... + b[L*(phaseLength-1)+1] * x[n-phaseLength+1] ... y[n+(L-1)] = b[L-1] * x[n] + b[2*L-1] * x[n-1] + ....+ b[L*(phaseLength-1)+(L-1)] * x[n-phaseLength+1] </pre> This approach is more efficient than straightforward upsample-then-filter algorithms. With this method the computation is reduced by a factor of <code>1/L</code> when compared to using a standard FIR filter. @par <code>pCoeffs</code> points to a coefficient array of size <code>numTaps</code>. <code>numTaps</code> must be a multiple of the interpolation factor <code>L</code> and this is checked by the initialization functions. Internally, the function divides the FIR filter's impulse response into shorter filters of length <code>phaseLength=numTaps/L</code>. Coefficients are stored in time reversed order. <pre> {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} </pre> @par <code>pState</code> points to a state array of size <code>blockSize + phaseLength - 1</code>. Samples in the state buffer are stored in the order: <pre> {x[n-phaseLength+1], x[n-phaseLength], x[n-phaseLength-1], x[n-phaseLength-2]....x[0], x[1], ..., x[blockSize-1]} </pre> @par The state variables are updated after each block of data is processed, the coefficients are untouched. @par Instance Structure The coefficients and state variables for a filter are stored together in an instance data structure. A separate instance structure must be defined for each filter. Coefficient arrays may be shared among several instances while state variable array should be allocated separately. There are separate instance structure declarations for each of the 3 supported data types. @par Initialization Functions There is also an associated initialization function for each data type. The initialization function performs the following operations: - Sets the values of the internal structure fields. - Zeros out the values in the state buffer. - Checks to make sure that the length of the filter is a multiple of the interpolation factor. To do this manually without calling the init function, assign the follow subfields of the instance structure: L (interpolation factor), pCoeffs, phaseLength (numTaps / L), pState. Also set all of the values in pState to zero. @par Use of the initialization function is optional. However, if the initialization function is used, then the instance structure cannot be placed into a const data section. To place an instance structure into a const data section, the instance structure must be manually initialized. The code below statically initializes each of the 3 different data type filter instance structures <pre> arm_fir_interpolate_instance_f32 S = {L, phaseLength, pCoeffs, pState}; arm_fir_interpolate_instance_q31 S = {L, phaseLength, pCoeffs, pState}; arm_fir_interpolate_instance_q15 S = {L, phaseLength, pCoeffs, pState}; </pre> @par where <code>L</code> is the interpolation factor; <code>phaseLength=numTaps/L</code> is the length of each of the shorter FIR filters used internally, <code>pCoeffs</code> is the address of the coefficient buffer; <code>pState</code> is the address of the state buffer. Be sure to set the values in the state buffer to zeros when doing static initialization. @par Fixed-Point Behavior Care must be taken when using the fixed-point versions of the FIR interpolate filter functions. In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. Refer to the function specific documentation below for usage guidelines. */ /** @addtogroup FIR_Interpolate @{ */ /** @brief Processing function for floating-point FIR interpolator. @param[in] S points to an instance of the floating-point FIR interpolator structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process @return none */ #if defined(ARM_MATH_NEON) void arm_fir_interpolate_f32( const arm_fir_interpolate_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ float32_t *ptr1; /* Temporary pointers for state buffer */ const float32_t *ptr2; /* Temporary pointers for coefficient buffer */ float32_t sum0; /* Accumulators */ float32_t x0, c0; /* Temporary variables to hold state and coefficient values */ uint32_t i, blkCnt, j; /* Loop counters */ uint16_t phaseLen = S->phaseLength, tapCnt; /* Length of each polyphase filter component */ float32_t acc0, acc1, acc2, acc3; float32_t x1, x2, x3; uint32_t blkCntN4; float32_t c1, c2, c3; float32x4_t sum0v; float32x4_t accV,accV0,accV1; float32x4_t x0v,x1v,x2v,xa,xb; uint32x4_t x0v_u,x1v_u,x2v_u,xa_u,xb_u; float32x2_t tempV; /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + (phaseLen - 1U); /* Initialise blkCnt */ blkCnt = blockSize >> 3; blkCntN4 = blockSize & 7; /* Loop unrolling */ while (blkCnt > 0U) { /* Copy new input samples into the state buffer */ sum0v = vld1q_f32(pSrc); vst1q_f32(pStateCurnt,sum0v); pSrc += 4; pStateCurnt += 4; sum0v = vld1q_f32(pSrc); vst1q_f32(pStateCurnt,sum0v); pSrc += 4; pStateCurnt += 4; /* Address modifier index of coefficient buffer */ j = 1U; /* Loop over the Interpolation factor. */ i = (S->L); while (i > 0U) { /* Set accumulator to zero */ accV0 = vdupq_n_f32(0.0); accV1 = vdupq_n_f32(0.0); /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (S->L - j); /* Loop over the polyPhase length. Unroll by a factor of 4. ** Repeat until we've computed numTaps-(4*S->L) coefficients. */ tapCnt = phaseLen >> 2U; x0v = vld1q_f32(ptr1); x1v = vld1q_f32(ptr1 + 4); while (tapCnt > 0U) { /* Read the input samples */ x2v = vld1q_f32(ptr1 + 8); /* Read the coefficients */ c0 = *(ptr2); /* Perform the multiply-accumulate */ accV0 = vmlaq_n_f32(accV0,x0v,c0); accV1 = vmlaq_n_f32(accV1,x1v,c0); /* Read the coefficients, inputs and perform multiply-accumulate */ c1 = *(ptr2 + S->L); xa = vextq_f32(x0v,x1v,1); xb = vextq_f32(x1v,x2v,1); accV0 = vmlaq_n_f32(accV0,xa,c1); accV1 = vmlaq_n_f32(accV1,xb,c1); /* Read the coefficients, inputs and perform multiply-accumulate */ c2 = *(ptr2 + S->L * 2); xa = vextq_f32(x0v,x1v,2); xb = vextq_f32(x1v,x2v,2); accV0 = vmlaq_n_f32(accV0,xa,c2); accV1 = vmlaq_n_f32(accV1,xb,c2); /* Read the coefficients, inputs and perform multiply-accumulate */ c3 = *(ptr2 + S->L * 3); xa = vextq_f32(x0v,x1v,3); xb = vextq_f32(x1v,x2v,3); accV0 = vmlaq_n_f32(accV0,xa,c3); accV1 = vmlaq_n_f32(accV1,xb,c3); /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += 4 * S->L; ptr1 += 4; x0v = x1v; x1v = x2v; /* Decrement the loop counter */ tapCnt--; } /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ tapCnt = phaseLen % 0x4U; x2v = vld1q_f32(ptr1 + 8); switch (tapCnt) { case 3: c0 = *(ptr2); accV0 = vmlaq_n_f32(accV0,x0v,c0); accV1 = vmlaq_n_f32(accV1,x1v,c0); ptr2 += S->L; c0 = *(ptr2); xa = vextq_f32(x0v,x1v,1); xb = vextq_f32(x1v,x2v,1); accV0 = vmlaq_n_f32(accV0,xa,c0); accV1 = vmlaq_n_f32(accV1,xb,c0); ptr2 += S->L; c0 = *(ptr2); xa = vextq_f32(x0v,x1v,2); xb = vextq_f32(x1v,x2v,2); accV0 = vmlaq_n_f32(accV0,xa,c0); accV1 = vmlaq_n_f32(accV1,xb,c0); ptr2 += S->L; break; case 2: c0 = *(ptr2); accV0 = vmlaq_n_f32(accV0,x0v,c0); accV1 = vmlaq_n_f32(accV1,x1v,c0); ptr2 += S->L; c0 = *(ptr2); xa = vextq_f32(x0v,x1v,1); xb = vextq_f32(x1v,x2v,1); accV0 = vmlaq_n_f32(accV0,xa,c0); accV1 = vmlaq_n_f32(accV1,xb,c0); ptr2 += S->L; break; case 1: c0 = *(ptr2); accV0 = vmlaq_n_f32(accV0,x0v,c0); accV1 = vmlaq_n_f32(accV1,x1v,c0); ptr2 += S->L; break; default: break; } /* The result is in the accumulator, store in the destination buffer. */ *pDst = accV0[0]; *(pDst + S->L) = accV0[1]; *(pDst + 2 * S->L) = accV0[2]; *(pDst + 3 * S->L) = accV0[3]; *(pDst + 4 * S->L) = accV1[0]; *(pDst + 5 * S->L) = accV1[1]; *(pDst + 6 * S->L) = accV1[2]; *(pDst + 7 * S->L) = accV1[3]; pDst++; /* Increment the address modifier index of coefficient buffer */ j++; /* Decrement the loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 8; pDst += S->L * 7; /* Decrement the loop counter */ blkCnt--; } /* If the blockSize is not a multiple of 4, compute any remaining output samples here. ** No loop unrolling is used. */ while (blkCntN4 > 0U) { /* Copy new input sample into the state buffer */ *pStateCurnt++ = *pSrc++; /* Address modifier index of coefficient buffer */ j = 1U; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum0v = vdupq_n_f32(0.0); /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (S->L - j); /* Loop over the polyPhase length. Unroll by a factor of 4. ** Repeat until we've computed numTaps-(4*S->L) coefficients. */ tapCnt = phaseLen >> 2U; while (tapCnt > 0U) { /* Read the coefficient */ x1v[0] = *(ptr2); /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Read the input sample */ x0v = vld1q_f32(ptr1); ptr1 += 4; /* Read the coefficient */ x1v[1] = *(ptr2); /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Read the coefficient */ x1v[2] = *(ptr2); /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Read the coefficient */ x1v[3] = *(ptr2); /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; sum0v = vmlaq_f32(sum0v,x0v,x1v); /* Decrement the loop counter */ tapCnt--; } tempV = vpadd_f32(vget_low_f32(sum0v),vget_high_f32(sum0v)); sum0 = tempV[0] + tempV[1]; /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ tapCnt = phaseLen % 0x4U; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum0 += *(ptr1++) * (*ptr2); /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Decrement the loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = sum0; /* Increment the address modifier index of coefficient buffer */ j++; /* Decrement the loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement the loop counter */ blkCntN4--; } /* Processing is complete. ** Now copy the last phaseLen - 1 samples to the satrt of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; tapCnt = (phaseLen - 1U) >> 2U; /* Copy data */ while (tapCnt > 0U) { sum0v = vld1q_f32(pState); vst1q_f32(pStateCurnt,sum0v); pState += 4; pStateCurnt += 4; /* Decrement the loop counter */ tapCnt--; } tapCnt = (phaseLen - 1U) % 0x04U; /* copy data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } #else void arm_fir_interpolate_f32( const arm_fir_interpolate_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { #if (1) //#if !defined(ARM_MATH_CM0_FAMILY) float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCur; /* Points to the current sample of the state */ float32_t *ptr1; /* Temporary pointer for state buffer */ const float32_t *ptr2; /* Temporary pointer for coefficient buffer */ float32_t sum0; /* Accumulators */ uint32_t i, blkCnt, tapCnt; /* Loop counters */ uint32_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */ uint32_t j; #if defined (ARM_MATH_LOOPUNROLL) float32_t acc0, acc1, acc2, acc3; float32_t x0, x1, x2, x3; float32_t c0, c1, c2, c3; #endif /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCur points to the location where the new input data should be written */ pStateCur = S->pState + (phaseLen - 1U); #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ blkCnt = blockSize >> 2U; while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCur++ = *pSrc++; *pStateCur++ = *pSrc++; *pStateCur++ = *pSrc++; *pStateCur++ = *pSrc++; /* Address modifier index of coefficient buffer */ j = 1U; /* Loop over the Interpolation factor. */ i = (S->L); while (i > 0U) { /* Set accumulator to zero */ acc0 = 0.0f; acc1 = 0.0f; acc2 = 0.0f; acc3 = 0.0f; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (S->L - j); /* Loop over the polyPhase length. Unroll by a factor of 4. Repeat until we've computed numTaps-(4*S->L) coefficients. */ tapCnt = phaseLen >> 2U; x0 = *(ptr1++); x1 = *(ptr1++); x2 = *(ptr1++); while (tapCnt > 0U) { /* Read the input sample */ x3 = *(ptr1++); /* Read the coefficient */ c0 = *(ptr2); /* Perform the multiply-accumulate */ acc0 += x0 * c0; acc1 += x1 * c0; acc2 += x2 * c0; acc3 += x3 * c0; /* Read the coefficient */ c1 = *(ptr2 + S->L); /* Read the input sample */ x0 = *(ptr1++); /* Perform the multiply-accumulate */ acc0 += x1 * c1; acc1 += x2 * c1; acc2 += x3 * c1; acc3 += x0 * c1; /* Read the coefficient */ c2 = *(ptr2 + S->L * 2); /* Read the input sample */ x1 = *(ptr1++); /* Perform the multiply-accumulate */ acc0 += x2 * c2; acc1 += x3 * c2; acc2 += x0 * c2; acc3 += x1 * c2; /* Read the coefficient */ c3 = *(ptr2 + S->L * 3); /* Read the input sample */ x2 = *(ptr1++); /* Perform the multiply-accumulate */ acc0 += x3 * c3; acc1 += x0 * c3; acc2 += x1 * c3; acc3 += x2 * c3; /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += 4 * S->L; /* Decrement loop counter */ tapCnt--; } /* If the polyPhase length is not a multiple of 4, compute the remaining filter taps */ tapCnt = phaseLen % 0x4U; while (tapCnt > 0U) { /* Read the input sample */ x3 = *(ptr1++); /* Read the coefficient */ c0 = *(ptr2); /* Perform the multiply-accumulate */ acc0 += x0 * c0; acc1 += x1 * c0; acc2 += x2 * c0; acc3 += x3 * c0; /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* update states for next sample processing */ x0 = x1; x1 = x2; x2 = x3; /* Decrement loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *(pDst ) = acc0; *(pDst + S->L) = acc1; *(pDst + 2 * S->L) = acc2; *(pDst + 3 * S->L) = acc3; pDst++; /* Increment the address modifier index of coefficient buffer */ j++; /* Decrement loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 4; pDst += S->L * 3; /* Decrement loop counter */ blkCnt--; } /* Loop unrolling: Compute remaining outputs */ blkCnt = blockSize % 0x4U; #else /* Initialize blkCnt with number of samples */ blkCnt = blockSize; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCur++ = *pSrc++; /* Address modifier index of coefficient buffer */ j = 1U; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum0 = 0.0f; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (S->L - j); /* Loop over the polyPhase length. Repeat until we've computed numTaps-(4*S->L) coefficients. */ #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ tapCnt = phaseLen >> 2U; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum0 += *ptr1++ * *ptr2; /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; sum0 += *ptr1++ * *ptr2; ptr2 += S->L; sum0 += *ptr1++ * *ptr2; ptr2 += S->L; sum0 += *ptr1++ * *ptr2; ptr2 += S->L; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining outputs */ tapCnt = phaseLen % 0x4U; #else /* Initialize tapCnt with number of samples */ tapCnt = phaseLen; #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum0 += *ptr1++ * *ptr2; /* Upsampling is done by stuffing L-1 zeros between each sample. * So instead of multiplying zeros with coefficients, * Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Decrement loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = sum0; /* Increment the address modifier index of coefficient buffer */ j++; /* Decrement the loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. Now copy the last phaseLen - 1 samples to the satrt of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCur = S->pState; #if defined (ARM_MATH_LOOPUNROLL) /* Loop unrolling: Compute 4 outputs at a time */ tapCnt = (phaseLen - 1U) >> 2U; /* copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; *pStateCur++ = *pState++; *pStateCur++ = *pState++; *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } /* Loop unrolling: Compute remaining outputs */ tapCnt = (phaseLen - 1U) % 0x04U; #else /* Initialize tapCnt with number of samples */ tapCnt = (phaseLen - 1U); #endif /* #if defined (ARM_MATH_LOOPUNROLL) */ /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } #else /* alternate version for CM0_FAMILY */ float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCur; /* Points to the current sample of the state */ float32_t *ptr1; /* Temporary pointer for state buffer */ const float32_t *ptr2; /* Temporary pointer for coefficient buffer */ float32_t sum0; /* Accumulators */ uint32_t i, blkCnt, tapCnt; /* Loop counters */ uint32_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */ /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCur points to the location where the new input data should be written */ pStateCur = S->pState + (phaseLen - 1U); /* Total number of intput samples */ blkCnt = blockSize; /* Loop over the blockSize. */ while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCur++ = *pSrc++; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum0 = 0.0f; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + (i - 1U); /* Loop over the polyPhase length */ tapCnt = phaseLen; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum0 += *ptr1++ * *ptr2; /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Decrement the loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = sum0; /* Decrement loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last phaseLen - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCur = S->pState; tapCnt = phaseLen - 1U; /* Copy data */ while (tapCnt > 0U) { *pStateCur++ = *pState++; /* Decrement loop counter */ tapCnt--; } #endif /* #if !defined(ARM_MATH_CM0_FAMILY) */ } #endif /* #if defined(ARM_MATH_NEON) */ /** @} end of FIR_Interpolate group */
28,073
C
29.681967
140
0.568732
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Source/FilteringFunctions/arm_fir_decimate_init_f32.c
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_fir_decimate_init_f32.c * Description: Floating-point FIR Decimator initialization function * * $Date: 18. March 2019 * $Revision: V1.6.0 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "arm_math.h" /** @ingroup groupFilters */ /** @addtogroup FIR_decimate @{ */ /** @brief Initialization function for the floating-point FIR decimator. @param[in,out] S points to an instance of the floating-point FIR decimator structure @param[in] numTaps number of coefficients in the filter @param[in] M decimation factor @param[in] pCoeffs points to the filter coefficients @param[in] pState points to the state buffer @param[in] blockSize number of input samples to process per call @return execution status - \ref ARM_MATH_SUCCESS : Operation successful - \ref ARM_MATH_LENGTH_ERROR : <code>blockSize</code> is not a multiple of <code>M</code> @par Details <code>pCoeffs</code> points to the array of filter coefficients stored in time reversed order: <pre> {b[numTaps-1], b[numTaps-2], b[N-2], ..., b[1], b[0]} </pre> @par <code>pState</code> points to the array of state variables. <code>pState</code> is of length <code>numTaps+blockSize-1</code> words where <code>blockSize</code> is the number of input samples passed to <code>arm_fir_decimate_f32()</code>. <code>M</code> is the decimation factor. */ arm_status arm_fir_decimate_init_f32( arm_fir_decimate_instance_f32 * S, uint16_t numTaps, uint8_t M, const float32_t * pCoeffs, float32_t * pState, uint32_t blockSize) { arm_status status; /* The size of the input block must be a multiple of the decimation factor */ if ((blockSize % M) != 0U) { /* Set status as ARM_MATH_LENGTH_ERROR */ status = ARM_MATH_LENGTH_ERROR; } else { /* Assign filter taps */ S->numTaps = numTaps; /* Assign coefficient pointer */ S->pCoeffs = pCoeffs; /* Clear the state buffer. The size is always (blockSize + numTaps - 1) */ memset(pState, 0, (numTaps + (blockSize - 1U)) * sizeof(float32_t)); /* Assign state pointer */ S->pState = pState; /* Assign Decimation Factor */ S->M = M; status = ARM_MATH_SUCCESS; } return (status); } /** @} end of FIR_decimate group */
3,347
C
30.584905
197
0.608903
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Include/arm_math.h
/****************************************************************************** * @file arm_math.h * @brief Public header file for CMSIS DSP Library * @version V1.6.0 * @date 18. March 2019 ******************************************************************************/ /* * Copyright (c) 2010-2019 Arm Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** \mainpage CMSIS DSP Software Library * * Introduction * ------------ * * This user manual describes the CMSIS DSP software library, * a suite of common signal processing functions for use on Cortex-M processor based devices. * * The library is divided into a number of functions each covering a specific category: * - Basic math functions * - Fast math functions * - Complex math functions * - Filters * - Matrix functions * - Transform functions * - Motor control functions * - Statistical functions * - Support functions * - Interpolation functions * * The library has separate functions for operating on 8-bit integers, 16-bit integers, * 32-bit integer and 32-bit floating-point values. * * Using the Library * ------------ * * The library installer contains prebuilt versions of the libraries in the <code>Lib</code> folder. * - arm_cortexM7lfdp_math.lib (Cortex-M7, Little endian, Double Precision Floating Point Unit) * - arm_cortexM7bfdp_math.lib (Cortex-M7, Big endian, Double Precision Floating Point Unit) * - arm_cortexM7lfsp_math.lib (Cortex-M7, Little endian, Single Precision Floating Point Unit) * - arm_cortexM7bfsp_math.lib (Cortex-M7, Big endian and Single Precision Floating Point Unit on) * - arm_cortexM7l_math.lib (Cortex-M7, Little endian) * - arm_cortexM7b_math.lib (Cortex-M7, Big endian) * - arm_cortexM4lf_math.lib (Cortex-M4, Little endian, Floating Point Unit) * - arm_cortexM4bf_math.lib (Cortex-M4, Big endian, Floating Point Unit) * - arm_cortexM4l_math.lib (Cortex-M4, Little endian) * - arm_cortexM4b_math.lib (Cortex-M4, Big endian) * - arm_cortexM3l_math.lib (Cortex-M3, Little endian) * - arm_cortexM3b_math.lib (Cortex-M3, Big endian) * - arm_cortexM0l_math.lib (Cortex-M0 / Cortex-M0+, Little endian) * - arm_cortexM0b_math.lib (Cortex-M0 / Cortex-M0+, Big endian) * - arm_ARMv8MBLl_math.lib (Armv8-M Baseline, Little endian) * - arm_ARMv8MMLl_math.lib (Armv8-M Mainline, Little endian) * - arm_ARMv8MMLlfsp_math.lib (Armv8-M Mainline, Little endian, Single Precision Floating Point Unit) * - arm_ARMv8MMLld_math.lib (Armv8-M Mainline, Little endian, DSP instructions) * - arm_ARMv8MMLldfsp_math.lib (Armv8-M Mainline, Little endian, DSP instructions, Single Precision Floating Point Unit) * * The library functions are declared in the public file <code>arm_math.h</code> which is placed in the <code>Include</code> folder. * Simply include this file and link the appropriate library in the application and begin calling the library functions. The Library supports single * public header file <code> arm_math.h</code> for Cortex-M cores with little endian and big endian. Same header file will be used for floating point unit(FPU) variants. * * * Examples * -------- * * The library ships with a number of examples which demonstrate how to use the library functions. * * Toolchain Support * ------------ * * The library has been developed and tested with MDK version 5.14.0.0 * The library is being tested in GCC and IAR toolchains and updates on this activity will be made available shortly. * * Building the Library * ------------ * * The library installer contains a project file to rebuild libraries on MDK toolchain in the <code>CMSIS\\DSP\\Projects\\ARM</code> folder. * - arm_cortexM_math.uvprojx * * * The libraries can be built by opening the arm_cortexM_math.uvprojx project in MDK-ARM, selecting a specific target, and defining the optional preprocessor macros detailed above. * * Preprocessor Macros * ------------ * * Each library project have different preprocessor macros. * * - ARM_MATH_BIG_ENDIAN: * * Define macro ARM_MATH_BIG_ENDIAN to build the library for big endian targets. By default library builds for little endian targets. * * - ARM_MATH_MATRIX_CHECK: * * Define macro ARM_MATH_MATRIX_CHECK for checking on the input and output sizes of matrices * * - ARM_MATH_ROUNDING: * * Define macro ARM_MATH_ROUNDING for rounding on support functions * * - ARM_MATH_LOOPUNROLL: * * Define macro ARM_MATH_LOOPUNROLL to enable manual loop unrolling in DSP functions * * - ARM_MATH_NEON: * * Define macro ARM_MATH_NEON to enable Neon versions of the DSP functions. * It is not enabled by default when Neon is available because performances are * dependent on the compiler and target architecture. * * - ARM_MATH_NEON_EXPERIMENTAL: * * Define macro ARM_MATH_NEON_EXPERIMENTAL to enable experimental Neon versions of * of some DSP functions. Experimental Neon versions currently do not have better * performances than the scalar versions. * * <hr> * CMSIS-DSP in ARM::CMSIS Pack * ----------------------------- * * The following files relevant to CMSIS-DSP are present in the <b>ARM::CMSIS</b> Pack directories: * |File/Folder |Content | * |---------------------------------|------------------------------------------------------------------------| * |\b CMSIS\\Documentation\\DSP | This documentation | * |\b CMSIS\\DSP\\DSP_Lib_TestSuite | DSP_Lib test suite | * |\b CMSIS\\DSP\\Examples | Example projects demonstrating the usage of the library functions | * |\b CMSIS\\DSP\\Include | DSP_Lib include files | * |\b CMSIS\\DSP\\Lib | DSP_Lib binaries | * |\b CMSIS\\DSP\\Projects | Projects to rebuild DSP_Lib binaries | * |\b CMSIS\\DSP\\Source | DSP_Lib source files | * * <hr> * Revision History of CMSIS-DSP * ------------ * Please refer to \ref ChangeLog_pg. */ /** * @defgroup groupMath Basic Math Functions */ /** * @defgroup groupFastMath Fast Math Functions * This set of functions provides a fast approximation to sine, cosine, and square root. * As compared to most of the other functions in the CMSIS math library, the fast math functions * operate on individual values and not arrays. * There are separate functions for Q15, Q31, and floating-point data. * */ /** * @defgroup groupCmplxMath Complex Math Functions * This set of functions operates on complex data vectors. * The data in the complex arrays is stored in an interleaved fashion * (real, imag, real, imag, ...). * In the API functions, the number of samples in a complex array refers * to the number of complex values; the array contains twice this number of * real values. */ /** * @defgroup groupFilters Filtering Functions */ /** * @defgroup groupMatrix Matrix Functions * * This set of functions provides basic matrix math operations. * The functions operate on matrix data structures. For example, * the type * definition for the floating-point matrix structure is shown * below: * <pre> * typedef struct * { * uint16_t numRows; // number of rows of the matrix. * uint16_t numCols; // number of columns of the matrix. * float32_t *pData; // points to the data of the matrix. * } arm_matrix_instance_f32; * </pre> * There are similar definitions for Q15 and Q31 data types. * * The structure specifies the size of the matrix and then points to * an array of data. The array is of size <code>numRows X numCols</code> * and the values are arranged in row order. That is, the * matrix element (i, j) is stored at: * <pre> * pData[i*numCols + j] * </pre> * * \par Init Functions * There is an associated initialization function for each type of matrix * data structure. * The initialization function sets the values of the internal structure fields. * Refer to \ref arm_mat_init_f32(), \ref arm_mat_init_q31() and \ref arm_mat_init_q15() * for floating-point, Q31 and Q15 types, respectively. * * \par * Use of the initialization function is optional. However, if initialization function is used * then the instance structure cannot be placed into a const data section. * To place the instance structure in a const data * section, manually initialize the data structure. For example: * <pre> * <code>arm_matrix_instance_f32 S = {nRows, nColumns, pData};</code> * <code>arm_matrix_instance_q31 S = {nRows, nColumns, pData};</code> * <code>arm_matrix_instance_q15 S = {nRows, nColumns, pData};</code> * </pre> * where <code>nRows</code> specifies the number of rows, <code>nColumns</code> * specifies the number of columns, and <code>pData</code> points to the * data array. * * \par Size Checking * By default all of the matrix functions perform size checking on the input and * output matrices. For example, the matrix addition function verifies that the * two input matrices and the output matrix all have the same number of rows and * columns. If the size check fails the functions return: * <pre> * ARM_MATH_SIZE_MISMATCH * </pre> * Otherwise the functions return * <pre> * ARM_MATH_SUCCESS * </pre> * There is some overhead associated with this matrix size checking. * The matrix size checking is enabled via the \#define * <pre> * ARM_MATH_MATRIX_CHECK * </pre> * within the library project settings. By default this macro is defined * and size checking is enabled. By changing the project settings and * undefining this macro size checking is eliminated and the functions * run a bit faster. With size checking disabled the functions always * return <code>ARM_MATH_SUCCESS</code>. */ /** * @defgroup groupTransforms Transform Functions */ /** * @defgroup groupController Controller Functions */ /** * @defgroup groupStats Statistics Functions */ /** * @defgroup groupSupport Support Functions */ /** * @defgroup groupInterpolation Interpolation Functions * These functions perform 1- and 2-dimensional interpolation of data. * Linear interpolation is used for 1-dimensional data and * bilinear interpolation is used for 2-dimensional data. */ /** * @defgroup groupExamples Examples */ #ifndef _ARM_MATH_H #define _ARM_MATH_H /* Compiler specific diagnostic adjustment */ #if defined ( __CC_ARM ) #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 ) #elif defined ( __GNUC__ ) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wunused-parameter" #elif defined ( __ICCARM__ ) #elif defined ( __TI_ARM__ ) #elif defined ( __CSMC__ ) #elif defined ( __TASKING__ ) #elif defined ( _MSC_VER ) #else #error Unknown compiler #endif /* Included for instrinsics definitions */ #if !defined ( _MSC_VER ) #include "cmsis_compiler.h" #else #include <stdint.h> #define __STATIC_FORCEINLINE static __forceinline #define __ALIGNED(x) __declspec(align(x)) #define LOW_OPTIMIZATION_ENTER #define LOW_OPTIMIZATION_EXIT #define IAR_ONLY_LOW_OPTIMIZATION_ENTER #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #endif #include "string.h" #include "math.h" #include "float.h" /* evaluate ARM DSP feature */ #if (defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)) #define ARM_MATH_DSP 1 #endif #if defined(__ARM_NEON) #include <arm_neon.h> #endif #ifdef __cplusplus extern "C" { #endif /** * @brief Macros required for reciprocal calculation in Normalized LMS */ #define DELTA_Q31 (0x100) #define DELTA_Q15 0x5 #define INDEX_MASK 0x0000003F #ifndef PI #define PI 3.14159265358979f #endif /** * @brief Macros required for SINE and COSINE Fast math approximations */ #define FAST_MATH_TABLE_SIZE 512 #define FAST_MATH_Q31_SHIFT (32 - 10) #define FAST_MATH_Q15_SHIFT (16 - 10) #define CONTROLLER_Q31_SHIFT (32 - 9) #define TABLE_SPACING_Q31 0x400000 #define TABLE_SPACING_Q15 0x80 /** * @brief Macros required for SINE and COSINE Controller functions */ /* 1.31(q31) Fixed value of 2/360 */ /* -1 to +1 is divided into 360 values so total spacing is (2/360) */ #define INPUT_SPACING 0xB60B61 /** * @brief Error status returned by some functions in the library. */ typedef enum { ARM_MATH_SUCCESS = 0, /**< No error */ ARM_MATH_ARGUMENT_ERROR = -1, /**< One or more arguments are incorrect */ ARM_MATH_LENGTH_ERROR = -2, /**< Length of data buffer is incorrect */ ARM_MATH_SIZE_MISMATCH = -3, /**< Size of matrices is not compatible with the operation */ ARM_MATH_NANINF = -4, /**< Not-a-number (NaN) or infinity is generated */ ARM_MATH_SINGULAR = -5, /**< Input matrix is singular and cannot be inverted */ ARM_MATH_TEST_FAILURE = -6 /**< Test Failed */ } arm_status; /** * @brief 8-bit fractional data type in 1.7 format. */ typedef int8_t q7_t; /** * @brief 16-bit fractional data type in 1.15 format. */ typedef int16_t q15_t; /** * @brief 32-bit fractional data type in 1.31 format. */ typedef int32_t q31_t; /** * @brief 64-bit fractional data type in 1.63 format. */ typedef int64_t q63_t; /** * @brief 32-bit floating-point type definition. */ typedef float float32_t; /** * @brief 64-bit floating-point type definition. */ typedef double float64_t; /** @brief definition to read/write two 16 bit values. @deprecated */ #if defined ( __CC_ARM ) #define __SIMD32_TYPE int32_t __packed #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 ) #define __SIMD32_TYPE int32_t #elif defined ( __GNUC__ ) #define __SIMD32_TYPE int32_t #elif defined ( __ICCARM__ ) #define __SIMD32_TYPE int32_t __packed #elif defined ( __TI_ARM__ ) #define __SIMD32_TYPE int32_t #elif defined ( __CSMC__ ) #define __SIMD32_TYPE int32_t #elif defined ( __TASKING__ ) #define __SIMD32_TYPE __un(aligned) int32_t #elif defined(_MSC_VER ) #define __SIMD32_TYPE int32_t #else #error Unknown compiler #endif #define __SIMD32(addr) (*(__SIMD32_TYPE **) & (addr)) #define __SIMD32_CONST(addr) ( (__SIMD32_TYPE * ) (addr)) #define _SIMD32_OFFSET(addr) (*(__SIMD32_TYPE * ) (addr)) #define __SIMD64(addr) (*( int64_t **) & (addr)) /* SIMD replacement */ /** @brief Read 2 Q15 from Q15 pointer. @param[in] pQ15 points to input value @return Q31 value */ __STATIC_FORCEINLINE q31_t read_q15x2 ( q15_t * pQ15) { q31_t val; memcpy (&val, pQ15, 4); return (val); } /** @brief Read 2 Q15 from Q15 pointer and increment pointer afterwards. @param[in] pQ15 points to input value @return Q31 value */ __STATIC_FORCEINLINE q31_t read_q15x2_ia ( q15_t ** pQ15) { q31_t val; memcpy (&val, *pQ15, 4); *pQ15 += 2; return (val); } /** @brief Read 2 Q15 from Q15 pointer and decrement pointer afterwards. @param[in] pQ15 points to input value @return Q31 value */ __STATIC_FORCEINLINE q31_t read_q15x2_da ( q15_t ** pQ15) { q31_t val; memcpy (&val, *pQ15, 4); *pQ15 -= 2; return (val); } /** @brief Write 2 Q15 to Q15 pointer and increment pointer afterwards. @param[in] pQ15 points to input value @param[in] value Q31 value @return none */ __STATIC_FORCEINLINE void write_q15x2_ia ( q15_t ** pQ15, q31_t value) { q31_t val = value; memcpy (*pQ15, &val, 4); *pQ15 += 2; } /** @brief Write 2 Q15 to Q15 pointer. @param[in] pQ15 points to input value @param[in] value Q31 value @return none */ __STATIC_FORCEINLINE void write_q15x2 ( q15_t * pQ15, q31_t value) { q31_t val = value; memcpy (pQ15, &val, 4); } /** @brief Read 4 Q7 from Q7 pointer and increment pointer afterwards. @param[in] pQ7 points to input value @return Q31 value */ __STATIC_FORCEINLINE q31_t read_q7x4_ia ( q7_t ** pQ7) { q31_t val; memcpy (&val, *pQ7, 4); *pQ7 += 4; return (val); } /** @brief Read 4 Q7 from Q7 pointer and decrement pointer afterwards. @param[in] pQ7 points to input value @return Q31 value */ __STATIC_FORCEINLINE q31_t read_q7x4_da ( q7_t ** pQ7) { q31_t val; memcpy (&val, *pQ7, 4); *pQ7 -= 4; return (val); } /** @brief Write 4 Q7 to Q7 pointer and increment pointer afterwards. @param[in] pQ7 points to input value @param[in] value Q31 value @return none */ __STATIC_FORCEINLINE void write_q7x4_ia ( q7_t ** pQ7, q31_t value) { q31_t val = value; memcpy (*pQ7, &val, 4); *pQ7 += 4; } /* Normally those kind of definitions are in a compiler file in Core or Core_A. But for MSVC compiler it is a bit special. The goal is very specific to CMSIS-DSP and only to allow the use of this library from other systems like Python or Matlab. MSVC is not going to be used to cross-compile to ARM. So, having a MSVC compiler file in Core or Core_A would not make sense. */ #if defined ( _MSC_VER ) __STATIC_FORCEINLINE uint8_t __CLZ(uint32_t data) { if (data == 0U) { return 32U; } uint32_t count = 0U; uint32_t mask = 0x80000000U; while ((data & mask) == 0U) { count += 1U; mask = mask >> 1U; } return count; } __STATIC_FORCEINLINE int32_t __SSAT(int32_t val, uint32_t sat) { if ((sat >= 1U) && (sat <= 32U)) { const int32_t max = (int32_t)((1U << (sat - 1U)) - 1U); const int32_t min = -1 - max ; if (val > max) { return max; } else if (val < min) { return min; } } return val; } __STATIC_FORCEINLINE uint32_t __USAT(int32_t val, uint32_t sat) { if (sat <= 31U) { const uint32_t max = ((1U << sat) - 1U); if (val > (int32_t)max) { return max; } else if (val < 0) { return 0U; } } return (uint32_t)val; } #endif #ifndef ARM_MATH_DSP /** * @brief definition to pack two 16 bit values. */ #define __PKHBT(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0x0000FFFF) | \ (((int32_t)(ARG2) << ARG3) & (int32_t)0xFFFF0000) ) #define __PKHTB(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0xFFFF0000) | \ (((int32_t)(ARG2) >> ARG3) & (int32_t)0x0000FFFF) ) #endif /** * @brief definition to pack four 8 bit values. */ #ifndef ARM_MATH_BIG_ENDIAN #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v0) << 0) & (int32_t)0x000000FF) | \ (((int32_t)(v1) << 8) & (int32_t)0x0000FF00) | \ (((int32_t)(v2) << 16) & (int32_t)0x00FF0000) | \ (((int32_t)(v3) << 24) & (int32_t)0xFF000000) ) #else #define __PACKq7(v0,v1,v2,v3) ( (((int32_t)(v3) << 0) & (int32_t)0x000000FF) | \ (((int32_t)(v2) << 8) & (int32_t)0x0000FF00) | \ (((int32_t)(v1) << 16) & (int32_t)0x00FF0000) | \ (((int32_t)(v0) << 24) & (int32_t)0xFF000000) ) #endif /** * @brief Clips Q63 to Q31 values. */ __STATIC_FORCEINLINE q31_t clip_q63_to_q31( q63_t x) { return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ? ((0x7FFFFFFF ^ ((q31_t) (x >> 63)))) : (q31_t) x; } /** * @brief Clips Q63 to Q15 values. */ __STATIC_FORCEINLINE q15_t clip_q63_to_q15( q63_t x) { return ((q31_t) (x >> 32) != ((q31_t) x >> 31)) ? ((0x7FFF ^ ((q15_t) (x >> 63)))) : (q15_t) (x >> 15); } /** * @brief Clips Q31 to Q7 values. */ __STATIC_FORCEINLINE q7_t clip_q31_to_q7( q31_t x) { return ((q31_t) (x >> 24) != ((q31_t) x >> 23)) ? ((0x7F ^ ((q7_t) (x >> 31)))) : (q7_t) x; } /** * @brief Clips Q31 to Q15 values. */ __STATIC_FORCEINLINE q15_t clip_q31_to_q15( q31_t x) { return ((q31_t) (x >> 16) != ((q31_t) x >> 15)) ? ((0x7FFF ^ ((q15_t) (x >> 31)))) : (q15_t) x; } /** * @brief Multiplies 32 X 64 and returns 32 bit result in 2.30 format. */ __STATIC_FORCEINLINE q63_t mult32x64( q63_t x, q31_t y) { return ((((q63_t) (x & 0x00000000FFFFFFFF) * y) >> 32) + (((q63_t) (x >> 32) * y) ) ); } /** * @brief Function to Calculates 1/in (reciprocal) value of Q31 Data type. */ __STATIC_FORCEINLINE uint32_t arm_recip_q31( q31_t in, q31_t * dst, const q31_t * pRecipTable) { q31_t out; uint32_t tempVal; uint32_t index, i; uint32_t signBits; if (in > 0) { signBits = ((uint32_t) (__CLZ( in) - 1)); } else { signBits = ((uint32_t) (__CLZ(-in) - 1)); } /* Convert input sample to 1.31 format */ in = (in << signBits); /* calculation of index for initial approximated Val */ index = (uint32_t)(in >> 24); index = (index & INDEX_MASK); /* 1.31 with exp 1 */ out = pRecipTable[index]; /* calculation of reciprocal value */ /* running approximation for two iterations */ for (i = 0U; i < 2U; i++) { tempVal = (uint32_t) (((q63_t) in * out) >> 31); tempVal = 0x7FFFFFFFu - tempVal; /* 1.31 with exp 1 */ /* out = (q31_t) (((q63_t) out * tempVal) >> 30); */ out = clip_q63_to_q31(((q63_t) out * tempVal) >> 30); } /* write output */ *dst = out; /* return num of signbits of out = 1/in value */ return (signBits + 1U); } /** * @brief Function to Calculates 1/in (reciprocal) value of Q15 Data type. */ __STATIC_FORCEINLINE uint32_t arm_recip_q15( q15_t in, q15_t * dst, const q15_t * pRecipTable) { q15_t out = 0; uint32_t tempVal = 0; uint32_t index = 0, i = 0; uint32_t signBits = 0; if (in > 0) { signBits = ((uint32_t)(__CLZ( in) - 17)); } else { signBits = ((uint32_t)(__CLZ(-in) - 17)); } /* Convert input sample to 1.15 format */ in = (in << signBits); /* calculation of index for initial approximated Val */ index = (uint32_t)(in >> 8); index = (index & INDEX_MASK); /* 1.15 with exp 1 */ out = pRecipTable[index]; /* calculation of reciprocal value */ /* running approximation for two iterations */ for (i = 0U; i < 2U; i++) { tempVal = (uint32_t) (((q31_t) in * out) >> 15); tempVal = 0x7FFFu - tempVal; /* 1.15 with exp 1 */ out = (q15_t) (((q31_t) out * tempVal) >> 14); /* out = clip_q31_to_q15(((q31_t) out * tempVal) >> 14); */ } /* write output */ *dst = out; /* return num of signbits of out = 1/in value */ return (signBits + 1); } #if defined(ARM_MATH_NEON) static inline float32x4_t __arm_vec_sqrt_f32_neon(float32x4_t x) { float32x4_t x1 = vmaxq_f32(x, vdupq_n_f32(FLT_MIN)); float32x4_t e = vrsqrteq_f32(x1); e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(x1, e), e), e); return vmulq_f32(x, e); } static inline int16x8_t __arm_vec_sqrt_q15_neon(int16x8_t vec) { float32x4_t tempF; int32x4_t tempHI,tempLO; tempLO = vmovl_s16(vget_low_s16(vec)); tempF = vcvtq_n_f32_s32(tempLO,15); tempF = __arm_vec_sqrt_f32_neon(tempF); tempLO = vcvtq_n_s32_f32(tempF,15); tempHI = vmovl_s16(vget_high_s16(vec)); tempF = vcvtq_n_f32_s32(tempHI,15); tempF = __arm_vec_sqrt_f32_neon(tempF); tempHI = vcvtq_n_s32_f32(tempF,15); return(vcombine_s16(vqmovn_s32(tempLO),vqmovn_s32(tempHI))); } static inline int32x4_t __arm_vec_sqrt_q31_neon(int32x4_t vec) { float32x4_t temp; temp = vcvtq_n_f32_s32(vec,31); temp = __arm_vec_sqrt_f32_neon(temp); return(vcvtq_n_s32_f32(temp,31)); } #endif /* * @brief C custom defined intrinsic functions */ #if !defined (ARM_MATH_DSP) /* * @brief C custom defined QADD8 */ __STATIC_FORCEINLINE uint32_t __QADD8( uint32_t x, uint32_t y) { q31_t r, s, t, u; r = __SSAT(((((q31_t)x << 24) >> 24) + (((q31_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF; s = __SSAT(((((q31_t)x << 16) >> 24) + (((q31_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF; t = __SSAT(((((q31_t)x << 8) >> 24) + (((q31_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF; u = __SSAT(((((q31_t)x ) >> 24) + (((q31_t)y ) >> 24)), 8) & (int32_t)0x000000FF; return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r ))); } /* * @brief C custom defined QSUB8 */ __STATIC_FORCEINLINE uint32_t __QSUB8( uint32_t x, uint32_t y) { q31_t r, s, t, u; r = __SSAT(((((q31_t)x << 24) >> 24) - (((q31_t)y << 24) >> 24)), 8) & (int32_t)0x000000FF; s = __SSAT(((((q31_t)x << 16) >> 24) - (((q31_t)y << 16) >> 24)), 8) & (int32_t)0x000000FF; t = __SSAT(((((q31_t)x << 8) >> 24) - (((q31_t)y << 8) >> 24)), 8) & (int32_t)0x000000FF; u = __SSAT(((((q31_t)x ) >> 24) - (((q31_t)y ) >> 24)), 8) & (int32_t)0x000000FF; return ((uint32_t)((u << 24) | (t << 16) | (s << 8) | (r ))); } /* * @brief C custom defined QADD16 */ __STATIC_FORCEINLINE uint32_t __QADD16( uint32_t x, uint32_t y) { /* q31_t r, s; without initialisation 'arm_offset_q15 test' fails but 'intrinsic' tests pass! for armCC */ q31_t r = 0, s = 0; r = __SSAT(((((q31_t)x << 16) >> 16) + (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF; s = __SSAT(((((q31_t)x ) >> 16) + (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined SHADD16 */ __STATIC_FORCEINLINE uint32_t __SHADD16( uint32_t x, uint32_t y) { q31_t r, s; r = (((((q31_t)x << 16) >> 16) + (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF; s = (((((q31_t)x ) >> 16) + (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined QSUB16 */ __STATIC_FORCEINLINE uint32_t __QSUB16( uint32_t x, uint32_t y) { q31_t r, s; r = __SSAT(((((q31_t)x << 16) >> 16) - (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF; s = __SSAT(((((q31_t)x ) >> 16) - (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined SHSUB16 */ __STATIC_FORCEINLINE uint32_t __SHSUB16( uint32_t x, uint32_t y) { q31_t r, s; r = (((((q31_t)x << 16) >> 16) - (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF; s = (((((q31_t)x ) >> 16) - (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined QASX */ __STATIC_FORCEINLINE uint32_t __QASX( uint32_t x, uint32_t y) { q31_t r, s; r = __SSAT(((((q31_t)x << 16) >> 16) - (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF; s = __SSAT(((((q31_t)x ) >> 16) + (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined SHASX */ __STATIC_FORCEINLINE uint32_t __SHASX( uint32_t x, uint32_t y) { q31_t r, s; r = (((((q31_t)x << 16) >> 16) - (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF; s = (((((q31_t)x ) >> 16) + (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined QSAX */ __STATIC_FORCEINLINE uint32_t __QSAX( uint32_t x, uint32_t y) { q31_t r, s; r = __SSAT(((((q31_t)x << 16) >> 16) + (((q31_t)y ) >> 16)), 16) & (int32_t)0x0000FFFF; s = __SSAT(((((q31_t)x ) >> 16) - (((q31_t)y << 16) >> 16)), 16) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined SHSAX */ __STATIC_FORCEINLINE uint32_t __SHSAX( uint32_t x, uint32_t y) { q31_t r, s; r = (((((q31_t)x << 16) >> 16) + (((q31_t)y ) >> 16)) >> 1) & (int32_t)0x0000FFFF; s = (((((q31_t)x ) >> 16) - (((q31_t)y << 16) >> 16)) >> 1) & (int32_t)0x0000FFFF; return ((uint32_t)((s << 16) | (r ))); } /* * @brief C custom defined SMUSDX */ __STATIC_FORCEINLINE uint32_t __SMUSDX( uint32_t x, uint32_t y) { return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) - ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) )); } /* * @brief C custom defined SMUADX */ __STATIC_FORCEINLINE uint32_t __SMUADX( uint32_t x, uint32_t y) { return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) + ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) )); } /* * @brief C custom defined QADD */ __STATIC_FORCEINLINE int32_t __QADD( int32_t x, int32_t y) { return ((int32_t)(clip_q63_to_q31((q63_t)x + (q31_t)y))); } /* * @brief C custom defined QSUB */ __STATIC_FORCEINLINE int32_t __QSUB( int32_t x, int32_t y) { return ((int32_t)(clip_q63_to_q31((q63_t)x - (q31_t)y))); } /* * @brief C custom defined SMLAD */ __STATIC_FORCEINLINE uint32_t __SMLAD( uint32_t x, uint32_t y, uint32_t sum) { return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) + ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) + ( ((q31_t)sum ) ) )); } /* * @brief C custom defined SMLADX */ __STATIC_FORCEINLINE uint32_t __SMLADX( uint32_t x, uint32_t y, uint32_t sum) { return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) + ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) + ( ((q31_t)sum ) ) )); } /* * @brief C custom defined SMLSDX */ __STATIC_FORCEINLINE uint32_t __SMLSDX( uint32_t x, uint32_t y, uint32_t sum) { return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) - ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) + ( ((q31_t)sum ) ) )); } /* * @brief C custom defined SMLALD */ __STATIC_FORCEINLINE uint64_t __SMLALD( uint32_t x, uint32_t y, uint64_t sum) { /* return (sum + ((q15_t) (x >> 16) * (q15_t) (y >> 16)) + ((q15_t) x * (q15_t) y)); */ return ((uint64_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) + ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) + ( ((q63_t)sum ) ) )); } /* * @brief C custom defined SMLALDX */ __STATIC_FORCEINLINE uint64_t __SMLALDX( uint32_t x, uint32_t y, uint64_t sum) { /* return (sum + ((q15_t) (x >> 16) * (q15_t) y)) + ((q15_t) x * (q15_t) (y >> 16)); */ return ((uint64_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y ) >> 16)) + ((((q31_t)x ) >> 16) * (((q31_t)y << 16) >> 16)) + ( ((q63_t)sum ) ) )); } /* * @brief C custom defined SMUAD */ __STATIC_FORCEINLINE uint32_t __SMUAD( uint32_t x, uint32_t y) { return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) + ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) )); } /* * @brief C custom defined SMUSD */ __STATIC_FORCEINLINE uint32_t __SMUSD( uint32_t x, uint32_t y) { return ((uint32_t)(((((q31_t)x << 16) >> 16) * (((q31_t)y << 16) >> 16)) - ((((q31_t)x ) >> 16) * (((q31_t)y ) >> 16)) )); } /* * @brief C custom defined SXTB16 */ __STATIC_FORCEINLINE uint32_t __SXTB16( uint32_t x) { return ((uint32_t)(((((q31_t)x << 24) >> 24) & (q31_t)0x0000FFFF) | ((((q31_t)x << 8) >> 8) & (q31_t)0xFFFF0000) )); } /* * @brief C custom defined SMMLA */ __STATIC_FORCEINLINE int32_t __SMMLA( int32_t x, int32_t y, int32_t sum) { return (sum + (int32_t) (((int64_t) x * y) >> 32)); } #endif /* !defined (ARM_MATH_DSP) */ /** * @brief Instance structure for the Q7 FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ q7_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ const q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ } arm_fir_instance_q7; /** * @brief Instance structure for the Q15 FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ } arm_fir_instance_q15; /** * @brief Instance structure for the Q31 FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ } arm_fir_instance_q31; /** * @brief Instance structure for the floating-point FIR filter. */ typedef struct { uint16_t numTaps; /**< number of filter coefficients in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ } arm_fir_instance_f32; /** * @brief Processing function for the Q7 FIR filter. * @param[in] S points to an instance of the Q7 FIR filter structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_fir_q7( const arm_fir_instance_q7 * S, const q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q7 FIR filter. * @param[in,out] S points to an instance of the Q7 FIR structure. * @param[in] numTaps Number of filter coefficients in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] blockSize number of samples that are processed. */ void arm_fir_init_q7( arm_fir_instance_q7 * S, uint16_t numTaps, const q7_t * pCoeffs, q7_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q15 FIR filter. * @param[in] S points to an instance of the Q15 FIR structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_fir_q15( const arm_fir_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Processing function for the fast Q15 FIR filter (fast version). * @param[in] S points to an instance of the Q15 FIR filter structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_fir_fast_q15( const arm_fir_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 FIR filter. * @param[in,out] S points to an instance of the Q15 FIR filter structure. * @param[in] numTaps Number of filter coefficients in the filter. Must be even and greater than or equal to 4. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] blockSize number of samples that are processed at a time. * @return The function returns either * <code>ARM_MATH_SUCCESS</code> if initialization was successful or * <code>ARM_MATH_ARGUMENT_ERROR</code> if <code>numTaps</code> is not a supported value. */ arm_status arm_fir_init_q15( arm_fir_instance_q15 * S, uint16_t numTaps, const q15_t * pCoeffs, q15_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR filter. * @param[in] S points to an instance of the Q31 FIR filter structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_fir_q31( const arm_fir_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Processing function for the fast Q31 FIR filter (fast version). * @param[in] S points to an instance of the Q31 FIR filter structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_fir_fast_q31( const arm_fir_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR filter. * @param[in,out] S points to an instance of the Q31 FIR structure. * @param[in] numTaps Number of filter coefficients in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] blockSize number of samples that are processed at a time. */ void arm_fir_init_q31( arm_fir_instance_q31 * S, uint16_t numTaps, const q31_t * pCoeffs, q31_t * pState, uint32_t blockSize); /** * @brief Processing function for the floating-point FIR filter. * @param[in] S points to an instance of the floating-point FIR structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_fir_f32( const arm_fir_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point FIR filter. * @param[in,out] S points to an instance of the floating-point FIR filter structure. * @param[in] numTaps Number of filter coefficients in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] blockSize number of samples that are processed at a time. */ void arm_fir_init_f32( arm_fir_instance_f32 * S, uint16_t numTaps, const float32_t * pCoeffs, float32_t * pState, uint32_t blockSize); /** * @brief Instance structure for the Q15 Biquad cascade filter. */ typedef struct { int8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ q15_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */ const q15_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */ int8_t postShift; /**< Additional shift, in bits, applied to each output sample. */ } arm_biquad_casd_df1_inst_q15; /** * @brief Instance structure for the Q31 Biquad cascade filter. */ typedef struct { uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ q31_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */ const q31_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */ uint8_t postShift; /**< Additional shift, in bits, applied to each output sample. */ } arm_biquad_casd_df1_inst_q31; /** * @brief Instance structure for the floating-point Biquad cascade filter. */ typedef struct { uint32_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ float32_t *pState; /**< Points to the array of state coefficients. The array is of length 4*numStages. */ const float32_t *pCoeffs; /**< Points to the array of coefficients. The array is of length 5*numStages. */ } arm_biquad_casd_df1_inst_f32; /** * @brief Processing function for the Q15 Biquad cascade filter. * @param[in] S points to an instance of the Q15 Biquad cascade structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_df1_q15( const arm_biquad_casd_df1_inst_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 Biquad cascade filter. * @param[in,out] S points to an instance of the Q15 Biquad cascade structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format */ void arm_biquad_cascade_df1_init_q15( arm_biquad_casd_df1_inst_q15 * S, uint8_t numStages, const q15_t * pCoeffs, q15_t * pState, int8_t postShift); /** * @brief Fast but less precise processing function for the Q15 Biquad cascade filter for Cortex-M3 and Cortex-M4. * @param[in] S points to an instance of the Q15 Biquad cascade structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_df1_fast_q15( const arm_biquad_casd_df1_inst_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Processing function for the Q31 Biquad cascade filter * @param[in] S points to an instance of the Q31 Biquad cascade structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_df1_q31( const arm_biquad_casd_df1_inst_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Fast but less precise processing function for the Q31 Biquad cascade filter for Cortex-M3 and Cortex-M4. * @param[in] S points to an instance of the Q31 Biquad cascade structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_df1_fast_q31( const arm_biquad_casd_df1_inst_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 Biquad cascade filter. * @param[in,out] S points to an instance of the Q31 Biquad cascade structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] postShift Shift to be applied to the output. Varies according to the coefficients format */ void arm_biquad_cascade_df1_init_q31( arm_biquad_casd_df1_inst_q31 * S, uint8_t numStages, const q31_t * pCoeffs, q31_t * pState, int8_t postShift); /** * @brief Processing function for the floating-point Biquad cascade filter. * @param[in] S points to an instance of the floating-point Biquad cascade structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_df1_f32( const arm_biquad_casd_df1_inst_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point Biquad cascade filter. * @param[in,out] S points to an instance of the floating-point Biquad cascade structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. */ void arm_biquad_cascade_df1_init_f32( arm_biquad_casd_df1_inst_f32 * S, uint8_t numStages, const float32_t * pCoeffs, float32_t * pState); /** * @brief Instance structure for the floating-point matrix structure. */ typedef struct { uint16_t numRows; /**< number of rows of the matrix. */ uint16_t numCols; /**< number of columns of the matrix. */ float32_t *pData; /**< points to the data of the matrix. */ } arm_matrix_instance_f32; /** * @brief Instance structure for the floating-point matrix structure. */ typedef struct { uint16_t numRows; /**< number of rows of the matrix. */ uint16_t numCols; /**< number of columns of the matrix. */ float64_t *pData; /**< points to the data of the matrix. */ } arm_matrix_instance_f64; /** * @brief Instance structure for the Q15 matrix structure. */ typedef struct { uint16_t numRows; /**< number of rows of the matrix. */ uint16_t numCols; /**< number of columns of the matrix. */ q15_t *pData; /**< points to the data of the matrix. */ } arm_matrix_instance_q15; /** * @brief Instance structure for the Q31 matrix structure. */ typedef struct { uint16_t numRows; /**< number of rows of the matrix. */ uint16_t numCols; /**< number of columns of the matrix. */ q31_t *pData; /**< points to the data of the matrix. */ } arm_matrix_instance_q31; /** * @brief Floating-point matrix addition. * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_add_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix addition. * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_add_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix addition. * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_add_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point, complex, matrix multiplication. * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_cmplx_mult_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); /** * @brief Q15, complex, matrix multiplication. * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_cmplx_mult_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst, q15_t * pScratch); /** * @brief Q31, complex, matrix multiplication. * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_cmplx_mult_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix transpose. * @param[in] pSrc points to the input matrix * @param[out] pDst points to the output matrix * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_trans_f32( const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix transpose. * @param[in] pSrc points to the input matrix * @param[out] pDst points to the output matrix * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_trans_q15( const arm_matrix_instance_q15 * pSrc, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix transpose. * @param[in] pSrc points to the input matrix * @param[out] pDst points to the output matrix * @return The function returns either <code>ARM_MATH_SIZE_MISMATCH</code> * or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_trans_q31( const arm_matrix_instance_q31 * pSrc, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix multiplication * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix multiplication * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @param[in] pState points to the array for storing intermediate results * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst, q15_t * pState); /** * @brief Q15 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @param[in] pState points to the array for storing intermediate results * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_fast_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst, q15_t * pState); /** * @brief Q31 matrix multiplication * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Q31 matrix multiplication (fast variant) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_mult_fast_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix subtraction * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_sub_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix subtraction * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_sub_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix subtraction * @param[in] pSrcA points to the first input matrix structure * @param[in] pSrcB points to the second input matrix structure * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_sub_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /** * @brief Floating-point matrix scaling. * @param[in] pSrc points to the input matrix * @param[in] scale scale factor * @param[out] pDst points to the output matrix * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_scale_f32( const arm_matrix_instance_f32 * pSrc, float32_t scale, arm_matrix_instance_f32 * pDst); /** * @brief Q15 matrix scaling. * @param[in] pSrc points to input matrix * @param[in] scaleFract fractional portion of the scale factor * @param[in] shift number of bits to shift the result by * @param[out] pDst points to output matrix * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_scale_q15( const arm_matrix_instance_q15 * pSrc, q15_t scaleFract, int32_t shift, arm_matrix_instance_q15 * pDst); /** * @brief Q31 matrix scaling. * @param[in] pSrc points to input matrix * @param[in] scaleFract fractional portion of the scale factor * @param[in] shift number of bits to shift the result by * @param[out] pDst points to output matrix structure * @return The function returns either * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking. */ arm_status arm_mat_scale_q31( const arm_matrix_instance_q31 * pSrc, q31_t scaleFract, int32_t shift, arm_matrix_instance_q31 * pDst); /** * @brief Q31 matrix initialization. * @param[in,out] S points to an instance of the floating-point matrix structure. * @param[in] nRows number of rows in the matrix. * @param[in] nColumns number of columns in the matrix. * @param[in] pData points to the matrix data array. */ void arm_mat_init_q31( arm_matrix_instance_q31 * S, uint16_t nRows, uint16_t nColumns, q31_t * pData); /** * @brief Q15 matrix initialization. * @param[in,out] S points to an instance of the floating-point matrix structure. * @param[in] nRows number of rows in the matrix. * @param[in] nColumns number of columns in the matrix. * @param[in] pData points to the matrix data array. */ void arm_mat_init_q15( arm_matrix_instance_q15 * S, uint16_t nRows, uint16_t nColumns, q15_t * pData); /** * @brief Floating-point matrix initialization. * @param[in,out] S points to an instance of the floating-point matrix structure. * @param[in] nRows number of rows in the matrix. * @param[in] nColumns number of columns in the matrix. * @param[in] pData points to the matrix data array. */ void arm_mat_init_f32( arm_matrix_instance_f32 * S, uint16_t nRows, uint16_t nColumns, float32_t * pData); /** * @brief Instance structure for the Q15 PID Control. */ typedef struct { q15_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */ #if !defined (ARM_MATH_DSP) q15_t A1; q15_t A2; #else q31_t A1; /**< The derived gain A1 = -Kp - 2Kd | Kd.*/ #endif q15_t state[3]; /**< The state array of length 3. */ q15_t Kp; /**< The proportional gain. */ q15_t Ki; /**< The integral gain. */ q15_t Kd; /**< The derivative gain. */ } arm_pid_instance_q15; /** * @brief Instance structure for the Q31 PID Control. */ typedef struct { q31_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */ q31_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */ q31_t A2; /**< The derived gain, A2 = Kd . */ q31_t state[3]; /**< The state array of length 3. */ q31_t Kp; /**< The proportional gain. */ q31_t Ki; /**< The integral gain. */ q31_t Kd; /**< The derivative gain. */ } arm_pid_instance_q31; /** * @brief Instance structure for the floating-point PID Control. */ typedef struct { float32_t A0; /**< The derived gain, A0 = Kp + Ki + Kd . */ float32_t A1; /**< The derived gain, A1 = -Kp - 2Kd. */ float32_t A2; /**< The derived gain, A2 = Kd . */ float32_t state[3]; /**< The state array of length 3. */ float32_t Kp; /**< The proportional gain. */ float32_t Ki; /**< The integral gain. */ float32_t Kd; /**< The derivative gain. */ } arm_pid_instance_f32; /** * @brief Initialization function for the floating-point PID Control. * @param[in,out] S points to an instance of the PID structure. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. */ void arm_pid_init_f32( arm_pid_instance_f32 * S, int32_t resetStateFlag); /** * @brief Reset function for the floating-point PID Control. * @param[in,out] S is an instance of the floating-point PID Control structure */ void arm_pid_reset_f32( arm_pid_instance_f32 * S); /** * @brief Initialization function for the Q31 PID Control. * @param[in,out] S points to an instance of the Q15 PID structure. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. */ void arm_pid_init_q31( arm_pid_instance_q31 * S, int32_t resetStateFlag); /** * @brief Reset function for the Q31 PID Control. * @param[in,out] S points to an instance of the Q31 PID Control structure */ void arm_pid_reset_q31( arm_pid_instance_q31 * S); /** * @brief Initialization function for the Q15 PID Control. * @param[in,out] S points to an instance of the Q15 PID structure. * @param[in] resetStateFlag flag to reset the state. 0 = no change in state 1 = reset the state. */ void arm_pid_init_q15( arm_pid_instance_q15 * S, int32_t resetStateFlag); /** * @brief Reset function for the Q15 PID Control. * @param[in,out] S points to an instance of the q15 PID Control structure */ void arm_pid_reset_q15( arm_pid_instance_q15 * S); /** * @brief Instance structure for the floating-point Linear Interpolate function. */ typedef struct { uint32_t nValues; /**< nValues */ float32_t x1; /**< x1 */ float32_t xSpacing; /**< xSpacing */ float32_t *pYData; /**< pointer to the table of Y values */ } arm_linear_interp_instance_f32; /** * @brief Instance structure for the floating-point bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ float32_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_f32; /** * @brief Instance structure for the Q31 bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ q31_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_q31; /** * @brief Instance structure for the Q15 bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ q15_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_q15; /** * @brief Instance structure for the Q15 bilinear interpolation function. */ typedef struct { uint16_t numRows; /**< number of rows in the data table. */ uint16_t numCols; /**< number of columns in the data table. */ q7_t *pData; /**< points to the data table. */ } arm_bilinear_interp_instance_q7; /** * @brief Q7 vector multiplication. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_mult_q7( const q7_t * pSrcA, const q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); /** * @brief Q15 vector multiplication. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_mult_q15( const q15_t * pSrcA, const q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector multiplication. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_mult_q31( const q31_t * pSrcA, const q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); /** * @brief Floating-point vector multiplication. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_mult_f32( const float32_t * pSrcA, const float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); /** * @brief Instance structure for the Q15 CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ const q15_t *pTwiddle; /**< points to the Sin twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ } arm_cfft_radix2_instance_q15; /* Deprecated */ arm_status arm_cfft_radix2_init_q15( arm_cfft_radix2_instance_q15 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /* Deprecated */ void arm_cfft_radix2_q15( const arm_cfft_radix2_instance_q15 * S, q15_t * pSrc); /** * @brief Instance structure for the Q15 CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ const q15_t *pTwiddle; /**< points to the twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ } arm_cfft_radix4_instance_q15; /* Deprecated */ arm_status arm_cfft_radix4_init_q15( arm_cfft_radix4_instance_q15 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /* Deprecated */ void arm_cfft_radix4_q15( const arm_cfft_radix4_instance_q15 * S, q15_t * pSrc); /** * @brief Instance structure for the Radix-2 Q31 CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ const q31_t *pTwiddle; /**< points to the Twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ } arm_cfft_radix2_instance_q31; /* Deprecated */ arm_status arm_cfft_radix2_init_q31( arm_cfft_radix2_instance_q31 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /* Deprecated */ void arm_cfft_radix2_q31( const arm_cfft_radix2_instance_q31 * S, q31_t * pSrc); /** * @brief Instance structure for the Q31 CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ const q31_t *pTwiddle; /**< points to the twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ } arm_cfft_radix4_instance_q31; /* Deprecated */ void arm_cfft_radix4_q31( const arm_cfft_radix4_instance_q31 * S, q31_t * pSrc); /* Deprecated */ arm_status arm_cfft_radix4_init_q31( arm_cfft_radix4_instance_q31 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /** * @brief Instance structure for the floating-point CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ const float32_t *pTwiddle; /**< points to the Twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ float32_t onebyfftLen; /**< value of 1/fftLen. */ } arm_cfft_radix2_instance_f32; /* Deprecated */ arm_status arm_cfft_radix2_init_f32( arm_cfft_radix2_instance_f32 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /* Deprecated */ void arm_cfft_radix2_f32( const arm_cfft_radix2_instance_f32 * S, float32_t * pSrc); /** * @brief Instance structure for the floating-point CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ uint8_t ifftFlag; /**< flag that selects forward (ifftFlag=0) or inverse (ifftFlag=1) transform. */ uint8_t bitReverseFlag; /**< flag that enables (bitReverseFlag=1) or disables (bitReverseFlag=0) bit reversal of output. */ const float32_t *pTwiddle; /**< points to the Twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t twidCoefModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ uint16_t bitRevFactor; /**< bit reversal modifier that supports different size FFTs with the same bit reversal table. */ float32_t onebyfftLen; /**< value of 1/fftLen. */ } arm_cfft_radix4_instance_f32; /* Deprecated */ arm_status arm_cfft_radix4_init_f32( arm_cfft_radix4_instance_f32 * S, uint16_t fftLen, uint8_t ifftFlag, uint8_t bitReverseFlag); /* Deprecated */ void arm_cfft_radix4_f32( const arm_cfft_radix4_instance_f32 * S, float32_t * pSrc); /** * @brief Instance structure for the fixed-point CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ const q15_t *pTwiddle; /**< points to the Twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t bitRevLength; /**< bit reversal table length. */ } arm_cfft_instance_q15; void arm_cfft_q15( const arm_cfft_instance_q15 * S, q15_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag); /** * @brief Instance structure for the fixed-point CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ const q31_t *pTwiddle; /**< points to the Twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t bitRevLength; /**< bit reversal table length. */ } arm_cfft_instance_q31; void arm_cfft_q31( const arm_cfft_instance_q31 * S, q31_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag); /** * @brief Instance structure for the floating-point CFFT/CIFFT function. */ typedef struct { uint16_t fftLen; /**< length of the FFT. */ const float32_t *pTwiddle; /**< points to the Twiddle factor table. */ const uint16_t *pBitRevTable; /**< points to the bit reversal table. */ uint16_t bitRevLength; /**< bit reversal table length. */ } arm_cfft_instance_f32; void arm_cfft_f32( const arm_cfft_instance_f32 * S, float32_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag); /** * @brief Instance structure for the Q15 RFFT/RIFFT function. */ typedef struct { uint32_t fftLenReal; /**< length of the real FFT. */ uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */ uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */ uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ const q15_t *pTwiddleAReal; /**< points to the real twiddle factor table. */ const q15_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */ const arm_cfft_instance_q15 *pCfft; /**< points to the complex FFT instance. */ } arm_rfft_instance_q15; arm_status arm_rfft_init_q15( arm_rfft_instance_q15 * S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag); void arm_rfft_q15( const arm_rfft_instance_q15 * S, q15_t * pSrc, q15_t * pDst); /** * @brief Instance structure for the Q31 RFFT/RIFFT function. */ typedef struct { uint32_t fftLenReal; /**< length of the real FFT. */ uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */ uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */ uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ const q31_t *pTwiddleAReal; /**< points to the real twiddle factor table. */ const q31_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */ const arm_cfft_instance_q31 *pCfft; /**< points to the complex FFT instance. */ } arm_rfft_instance_q31; arm_status arm_rfft_init_q31( arm_rfft_instance_q31 * S, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag); void arm_rfft_q31( const arm_rfft_instance_q31 * S, q31_t * pSrc, q31_t * pDst); /** * @brief Instance structure for the floating-point RFFT/RIFFT function. */ typedef struct { uint32_t fftLenReal; /**< length of the real FFT. */ uint16_t fftLenBy2; /**< length of the complex FFT. */ uint8_t ifftFlagR; /**< flag that selects forward (ifftFlagR=0) or inverse (ifftFlagR=1) transform. */ uint8_t bitReverseFlagR; /**< flag that enables (bitReverseFlagR=1) or disables (bitReverseFlagR=0) bit reversal of output. */ uint32_t twidCoefRModifier; /**< twiddle coefficient modifier that supports different size FFTs with the same twiddle factor table. */ const float32_t *pTwiddleAReal; /**< points to the real twiddle factor table. */ const float32_t *pTwiddleBReal; /**< points to the imag twiddle factor table. */ arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */ } arm_rfft_instance_f32; arm_status arm_rfft_init_f32( arm_rfft_instance_f32 * S, arm_cfft_radix4_instance_f32 * S_CFFT, uint32_t fftLenReal, uint32_t ifftFlagR, uint32_t bitReverseFlag); void arm_rfft_f32( const arm_rfft_instance_f32 * S, float32_t * pSrc, float32_t * pDst); /** * @brief Instance structure for the floating-point RFFT/RIFFT function. */ typedef struct { arm_cfft_instance_f32 Sint; /**< Internal CFFT structure. */ uint16_t fftLenRFFT; /**< length of the real sequence */ const float32_t * pTwiddleRFFT; /**< Twiddle factors real stage */ } arm_rfft_fast_instance_f32 ; arm_status arm_rfft_fast_init_f32 ( arm_rfft_fast_instance_f32 * S, uint16_t fftLen); arm_status arm_rfft_32_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); arm_status arm_rfft_64_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); arm_status arm_rfft_128_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); arm_status arm_rfft_256_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); arm_status arm_rfft_512_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); arm_status arm_rfft_1024_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); arm_status arm_rfft_2048_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); arm_status arm_rfft_4096_fast_init_f32 ( arm_rfft_fast_instance_f32 * S ); void arm_rfft_fast_f32( arm_rfft_fast_instance_f32 * S, float32_t * p, float32_t * pOut, uint8_t ifftFlag); /** * @brief Instance structure for the floating-point DCT4/IDCT4 function. */ typedef struct { uint16_t N; /**< length of the DCT4. */ uint16_t Nby2; /**< half of the length of the DCT4. */ float32_t normalize; /**< normalizing factor. */ const float32_t *pTwiddle; /**< points to the twiddle factor table. */ const float32_t *pCosFactor; /**< points to the cosFactor table. */ arm_rfft_instance_f32 *pRfft; /**< points to the real FFT instance. */ arm_cfft_radix4_instance_f32 *pCfft; /**< points to the complex FFT instance. */ } arm_dct4_instance_f32; /** * @brief Initialization function for the floating-point DCT4/IDCT4. * @param[in,out] S points to an instance of floating-point DCT4/IDCT4 structure. * @param[in] S_RFFT points to an instance of floating-point RFFT/RIFFT structure. * @param[in] S_CFFT points to an instance of floating-point CFFT/CIFFT structure. * @param[in] N length of the DCT4. * @param[in] Nby2 half of the length of the DCT4. * @param[in] normalize normalizing factor. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>fftLenReal</code> is not a supported transform length. */ arm_status arm_dct4_init_f32( arm_dct4_instance_f32 * S, arm_rfft_instance_f32 * S_RFFT, arm_cfft_radix4_instance_f32 * S_CFFT, uint16_t N, uint16_t Nby2, float32_t normalize); /** * @brief Processing function for the floating-point DCT4/IDCT4. * @param[in] S points to an instance of the floating-point DCT4/IDCT4 structure. * @param[in] pState points to state buffer. * @param[in,out] pInlineBuffer points to the in-place input and output buffer. */ void arm_dct4_f32( const arm_dct4_instance_f32 * S, float32_t * pState, float32_t * pInlineBuffer); /** * @brief Instance structure for the Q31 DCT4/IDCT4 function. */ typedef struct { uint16_t N; /**< length of the DCT4. */ uint16_t Nby2; /**< half of the length of the DCT4. */ q31_t normalize; /**< normalizing factor. */ const q31_t *pTwiddle; /**< points to the twiddle factor table. */ const q31_t *pCosFactor; /**< points to the cosFactor table. */ arm_rfft_instance_q31 *pRfft; /**< points to the real FFT instance. */ arm_cfft_radix4_instance_q31 *pCfft; /**< points to the complex FFT instance. */ } arm_dct4_instance_q31; /** * @brief Initialization function for the Q31 DCT4/IDCT4. * @param[in,out] S points to an instance of Q31 DCT4/IDCT4 structure. * @param[in] S_RFFT points to an instance of Q31 RFFT/RIFFT structure * @param[in] S_CFFT points to an instance of Q31 CFFT/CIFFT structure * @param[in] N length of the DCT4. * @param[in] Nby2 half of the length of the DCT4. * @param[in] normalize normalizing factor. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length. */ arm_status arm_dct4_init_q31( arm_dct4_instance_q31 * S, arm_rfft_instance_q31 * S_RFFT, arm_cfft_radix4_instance_q31 * S_CFFT, uint16_t N, uint16_t Nby2, q31_t normalize); /** * @brief Processing function for the Q31 DCT4/IDCT4. * @param[in] S points to an instance of the Q31 DCT4 structure. * @param[in] pState points to state buffer. * @param[in,out] pInlineBuffer points to the in-place input and output buffer. */ void arm_dct4_q31( const arm_dct4_instance_q31 * S, q31_t * pState, q31_t * pInlineBuffer); /** * @brief Instance structure for the Q15 DCT4/IDCT4 function. */ typedef struct { uint16_t N; /**< length of the DCT4. */ uint16_t Nby2; /**< half of the length of the DCT4. */ q15_t normalize; /**< normalizing factor. */ const q15_t *pTwiddle; /**< points to the twiddle factor table. */ const q15_t *pCosFactor; /**< points to the cosFactor table. */ arm_rfft_instance_q15 *pRfft; /**< points to the real FFT instance. */ arm_cfft_radix4_instance_q15 *pCfft; /**< points to the complex FFT instance. */ } arm_dct4_instance_q15; /** * @brief Initialization function for the Q15 DCT4/IDCT4. * @param[in,out] S points to an instance of Q15 DCT4/IDCT4 structure. * @param[in] S_RFFT points to an instance of Q15 RFFT/RIFFT structure. * @param[in] S_CFFT points to an instance of Q15 CFFT/CIFFT structure. * @param[in] N length of the DCT4. * @param[in] Nby2 half of the length of the DCT4. * @param[in] normalize normalizing factor. * @return arm_status function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_ARGUMENT_ERROR if <code>N</code> is not a supported transform length. */ arm_status arm_dct4_init_q15( arm_dct4_instance_q15 * S, arm_rfft_instance_q15 * S_RFFT, arm_cfft_radix4_instance_q15 * S_CFFT, uint16_t N, uint16_t Nby2, q15_t normalize); /** * @brief Processing function for the Q15 DCT4/IDCT4. * @param[in] S points to an instance of the Q15 DCT4 structure. * @param[in] pState points to state buffer. * @param[in,out] pInlineBuffer points to the in-place input and output buffer. */ void arm_dct4_q15( const arm_dct4_instance_q15 * S, q15_t * pState, q15_t * pInlineBuffer); /** * @brief Floating-point vector addition. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_add_f32( const float32_t * pSrcA, const float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); /** * @brief Q7 vector addition. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_add_q7( const q7_t * pSrcA, const q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); /** * @brief Q15 vector addition. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_add_q15( const q15_t * pSrcA, const q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector addition. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_add_q31( const q31_t * pSrcA, const q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); /** * @brief Floating-point vector subtraction. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_sub_f32( const float32_t * pSrcA, const float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); /** * @brief Q7 vector subtraction. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_sub_q7( const q7_t * pSrcA, const q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); /** * @brief Q15 vector subtraction. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_sub_q15( const q15_t * pSrcA, const q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector subtraction. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in each vector */ void arm_sub_q31( const q31_t * pSrcA, const q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); /** * @brief Multiplies a floating-point vector by a scalar. * @param[in] pSrc points to the input vector * @param[in] scale scale factor to be applied * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_scale_f32( const float32_t * pSrc, float32_t scale, float32_t * pDst, uint32_t blockSize); /** * @brief Multiplies a Q7 vector by a scalar. * @param[in] pSrc points to the input vector * @param[in] scaleFract fractional portion of the scale value * @param[in] shift number of bits to shift the result by * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_scale_q7( const q7_t * pSrc, q7_t scaleFract, int8_t shift, q7_t * pDst, uint32_t blockSize); /** * @brief Multiplies a Q15 vector by a scalar. * @param[in] pSrc points to the input vector * @param[in] scaleFract fractional portion of the scale value * @param[in] shift number of bits to shift the result by * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_scale_q15( const q15_t * pSrc, q15_t scaleFract, int8_t shift, q15_t * pDst, uint32_t blockSize); /** * @brief Multiplies a Q31 vector by a scalar. * @param[in] pSrc points to the input vector * @param[in] scaleFract fractional portion of the scale value * @param[in] shift number of bits to shift the result by * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_scale_q31( const q31_t * pSrc, q31_t scaleFract, int8_t shift, q31_t * pDst, uint32_t blockSize); /** * @brief Q7 vector absolute value. * @param[in] pSrc points to the input buffer * @param[out] pDst points to the output buffer * @param[in] blockSize number of samples in each vector */ void arm_abs_q7( const q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Floating-point vector absolute value. * @param[in] pSrc points to the input buffer * @param[out] pDst points to the output buffer * @param[in] blockSize number of samples in each vector */ void arm_abs_f32( const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Q15 vector absolute value. * @param[in] pSrc points to the input buffer * @param[out] pDst points to the output buffer * @param[in] blockSize number of samples in each vector */ void arm_abs_q15( const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Q31 vector absolute value. * @param[in] pSrc points to the input buffer * @param[out] pDst points to the output buffer * @param[in] blockSize number of samples in each vector */ void arm_abs_q31( const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Dot product of floating-point vectors. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] result output result returned here */ void arm_dot_prod_f32( const float32_t * pSrcA, const float32_t * pSrcB, uint32_t blockSize, float32_t * result); /** * @brief Dot product of Q7 vectors. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] result output result returned here */ void arm_dot_prod_q7( const q7_t * pSrcA, const q7_t * pSrcB, uint32_t blockSize, q31_t * result); /** * @brief Dot product of Q15 vectors. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] result output result returned here */ void arm_dot_prod_q15( const q15_t * pSrcA, const q15_t * pSrcB, uint32_t blockSize, q63_t * result); /** * @brief Dot product of Q31 vectors. * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[in] blockSize number of samples in each vector * @param[out] result output result returned here */ void arm_dot_prod_q31( const q31_t * pSrcA, const q31_t * pSrcB, uint32_t blockSize, q63_t * result); /** * @brief Shifts the elements of a Q7 vector a specified number of bits. * @param[in] pSrc points to the input vector * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_shift_q7( const q7_t * pSrc, int8_t shiftBits, q7_t * pDst, uint32_t blockSize); /** * @brief Shifts the elements of a Q15 vector a specified number of bits. * @param[in] pSrc points to the input vector * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_shift_q15( const q15_t * pSrc, int8_t shiftBits, q15_t * pDst, uint32_t blockSize); /** * @brief Shifts the elements of a Q31 vector a specified number of bits. * @param[in] pSrc points to the input vector * @param[in] shiftBits number of bits to shift. A positive value shifts left; a negative value shifts right. * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_shift_q31( const q31_t * pSrc, int8_t shiftBits, q31_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a floating-point vector. * @param[in] pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_offset_f32( const float32_t * pSrc, float32_t offset, float32_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a Q7 vector. * @param[in] pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_offset_q7( const q7_t * pSrc, q7_t offset, q7_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a Q15 vector. * @param[in] pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_offset_q15( const q15_t * pSrc, q15_t offset, q15_t * pDst, uint32_t blockSize); /** * @brief Adds a constant offset to a Q31 vector. * @param[in] pSrc points to the input vector * @param[in] offset is the offset to be added * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_offset_q31( const q31_t * pSrc, q31_t offset, q31_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a floating-point vector. * @param[in] pSrc points to the input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_negate_f32( const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a Q7 vector. * @param[in] pSrc points to the input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_negate_q7( const q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a Q15 vector. * @param[in] pSrc points to the input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_negate_q15( const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Negates the elements of a Q31 vector. * @param[in] pSrc points to the input vector * @param[out] pDst points to the output vector * @param[in] blockSize number of samples in the vector */ void arm_negate_q31( const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a floating-point vector. * @param[in] pSrc input pointer * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_copy_f32( const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a Q7 vector. * @param[in] pSrc input pointer * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_copy_q7( const q7_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a Q15 vector. * @param[in] pSrc input pointer * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_copy_q15( const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Copies the elements of a Q31 vector. * @param[in] pSrc input pointer * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_copy_q31( const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a floating-point vector. * @param[in] value input value to be filled * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_fill_f32( float32_t value, float32_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a Q7 vector. * @param[in] value input value to be filled * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_fill_q7( q7_t value, q7_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a Q15 vector. * @param[in] value input value to be filled * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_fill_q15( q15_t value, q15_t * pDst, uint32_t blockSize); /** * @brief Fills a constant value into a Q31 vector. * @param[in] value input value to be filled * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_fill_q31( q31_t value, q31_t * pDst, uint32_t blockSize); /** * @brief Convolution of floating-point sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1. */ void arm_conv_f32( const float32_t * pSrcA, uint32_t srcALen, const float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst); /** * @brief Convolution of Q15 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen). */ void arm_conv_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch1, q15_t * pScratch2); /** * @brief Convolution of Q15 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the location where the output result is written. Length srcALen+srcBLen-1. */ void arm_conv_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1. */ void arm_conv_fast_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** * @brief Convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen). */ void arm_conv_fast_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch1, q15_t * pScratch2); /** * @brief Convolution of Q31 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1. */ void arm_conv_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** * @brief Convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1. */ void arm_conv_fast_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** * @brief Convolution of Q7 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen). */ void arm_conv_opt_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, q15_t * pScratch1, q15_t * pScratch2); /** * @brief Convolution of Q7 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length srcALen+srcBLen-1. */ void arm_conv_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst); /** * @brief Partial convolution of floating-point sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_f32( const float32_t * pSrcA, uint32_t srcALen, const float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q15 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen). * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints, q15_t * pScratch1, q15_t * pScratch2); /** * @brief Partial convolution of Q15 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_fast_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q15 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @param[in] pScratch1 points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. * @param[in] pScratch2 points to scratch buffer of size min(srcALen, srcBLen). * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_fast_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints, q15_t * pScratch1, q15_t * pScratch2); /** * @brief Partial convolution of Q31 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q31 sequences (fast version) for Cortex-M3 and Cortex-M4 * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_fast_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Partial convolution of Q7 sequences * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen). * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_opt_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, uint32_t firstIndex, uint32_t numPoints, q15_t * pScratch1, q15_t * pScratch2); /** * @brief Partial convolution of Q7 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data * @param[in] firstIndex is the first output sample to start with. * @param[in] numPoints is the number of output points to be computed. * @return Returns either ARM_MATH_SUCCESS if the function completed correctly or ARM_MATH_ARGUMENT_ERROR if the requested subset is not in the range [0 srcALen+srcBLen-2]. */ arm_status arm_conv_partial_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, uint32_t firstIndex, uint32_t numPoints); /** * @brief Instance structure for the Q15 FIR decimator. */ typedef struct { uint8_t M; /**< decimation factor. */ uint16_t numTaps; /**< number of coefficients in the filter. */ const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ } arm_fir_decimate_instance_q15; /** * @brief Instance structure for the Q31 FIR decimator. */ typedef struct { uint8_t M; /**< decimation factor. */ uint16_t numTaps; /**< number of coefficients in the filter. */ const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ } arm_fir_decimate_instance_q31; /** @brief Instance structure for floating-point FIR decimator. */ typedef struct { uint8_t M; /**< decimation factor. */ uint16_t numTaps; /**< number of coefficients in the filter. */ const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ } arm_fir_decimate_instance_f32; /** @brief Processing function for floating-point FIR decimator. @param[in] S points to an instance of the floating-point FIR decimator structure @param[in] pSrc points to the block of input data @param[out] pDst points to the block of output data @param[in] blockSize number of samples to process */ void arm_fir_decimate_f32( const arm_fir_decimate_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** @brief Initialization function for the floating-point FIR decimator. @param[in,out] S points to an instance of the floating-point FIR decimator structure @param[in] numTaps number of coefficients in the filter @param[in] M decimation factor @param[in] pCoeffs points to the filter coefficients @param[in] pState points to the state buffer @param[in] blockSize number of input samples to process per call @return execution status - \ref ARM_MATH_SUCCESS : Operation successful - \ref ARM_MATH_LENGTH_ERROR : <code>blockSize</code> is not a multiple of <code>M</code> */ arm_status arm_fir_decimate_init_f32( arm_fir_decimate_instance_f32 * S, uint16_t numTaps, uint8_t M, const float32_t * pCoeffs, float32_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q15 FIR decimator. * @param[in] S points to an instance of the Q15 FIR decimator structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. */ void arm_fir_decimate_q15( const arm_fir_decimate_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Processing function for the Q15 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4. * @param[in] S points to an instance of the Q15 FIR decimator structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. */ void arm_fir_decimate_fast_q15( const arm_fir_decimate_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 FIR decimator. * @param[in,out] S points to an instance of the Q15 FIR decimator structure. * @param[in] numTaps number of coefficients in the filter. * @param[in] M decimation factor. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * <code>blockSize</code> is not a multiple of <code>M</code>. */ arm_status arm_fir_decimate_init_q15( arm_fir_decimate_instance_q15 * S, uint16_t numTaps, uint8_t M, const q15_t * pCoeffs, q15_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR decimator. * @param[in] S points to an instance of the Q31 FIR decimator structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. */ void arm_fir_decimate_q31( const arm_fir_decimate_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR decimator (fast variant) for Cortex-M3 and Cortex-M4. * @param[in] S points to an instance of the Q31 FIR decimator structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of input samples to process per call. */ void arm_fir_decimate_fast_q31( const arm_fir_decimate_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR decimator. * @param[in,out] S points to an instance of the Q31 FIR decimator structure. * @param[in] numTaps number of coefficients in the filter. * @param[in] M decimation factor. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * <code>blockSize</code> is not a multiple of <code>M</code>. */ arm_status arm_fir_decimate_init_q31( arm_fir_decimate_instance_q31 * S, uint16_t numTaps, uint8_t M, const q31_t * pCoeffs, q31_t * pState, uint32_t blockSize); /** * @brief Instance structure for the Q15 FIR interpolator. */ typedef struct { uint8_t L; /**< upsample factor. */ uint16_t phaseLength; /**< length of each polyphase filter component. */ const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */ q15_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */ } arm_fir_interpolate_instance_q15; /** * @brief Instance structure for the Q31 FIR interpolator. */ typedef struct { uint8_t L; /**< upsample factor. */ uint16_t phaseLength; /**< length of each polyphase filter component. */ const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */ q31_t *pState; /**< points to the state variable array. The array is of length blockSize+phaseLength-1. */ } arm_fir_interpolate_instance_q31; /** * @brief Instance structure for the floating-point FIR interpolator. */ typedef struct { uint8_t L; /**< upsample factor. */ uint16_t phaseLength; /**< length of each polyphase filter component. */ const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length L*phaseLength. */ float32_t *pState; /**< points to the state variable array. The array is of length phaseLength+numTaps-1. */ } arm_fir_interpolate_instance_f32; /** * @brief Processing function for the Q15 FIR interpolator. * @param[in] S points to an instance of the Q15 FIR interpolator structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of input samples to process per call. */ void arm_fir_interpolate_q15( const arm_fir_interpolate_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 FIR interpolator. * @param[in,out] S points to an instance of the Q15 FIR interpolator structure. * @param[in] L upsample factor. * @param[in] numTaps number of filter coefficients in the filter. * @param[in] pCoeffs points to the filter coefficient buffer. * @param[in] pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>. */ arm_status arm_fir_interpolate_init_q15( arm_fir_interpolate_instance_q15 * S, uint8_t L, uint16_t numTaps, const q15_t * pCoeffs, q15_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q31 FIR interpolator. * @param[in] S points to an instance of the Q15 FIR interpolator structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of input samples to process per call. */ void arm_fir_interpolate_q31( const arm_fir_interpolate_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR interpolator. * @param[in,out] S points to an instance of the Q31 FIR interpolator structure. * @param[in] L upsample factor. * @param[in] numTaps number of filter coefficients in the filter. * @param[in] pCoeffs points to the filter coefficient buffer. * @param[in] pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>. */ arm_status arm_fir_interpolate_init_q31( arm_fir_interpolate_instance_q31 * S, uint8_t L, uint16_t numTaps, const q31_t * pCoeffs, q31_t * pState, uint32_t blockSize); /** * @brief Processing function for the floating-point FIR interpolator. * @param[in] S points to an instance of the floating-point FIR interpolator structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of input samples to process per call. */ void arm_fir_interpolate_f32( const arm_fir_interpolate_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point FIR interpolator. * @param[in,out] S points to an instance of the floating-point FIR interpolator structure. * @param[in] L upsample factor. * @param[in] numTaps number of filter coefficients in the filter. * @param[in] pCoeffs points to the filter coefficient buffer. * @param[in] pState points to the state buffer. * @param[in] blockSize number of input samples to process per call. * @return The function returns ARM_MATH_SUCCESS if initialization is successful or ARM_MATH_LENGTH_ERROR if * the filter length <code>numTaps</code> is not a multiple of the interpolation factor <code>L</code>. */ arm_status arm_fir_interpolate_init_f32( arm_fir_interpolate_instance_f32 * S, uint8_t L, uint16_t numTaps, const float32_t * pCoeffs, float32_t * pState, uint32_t blockSize); /** * @brief Instance structure for the high precision Q31 Biquad cascade filter. */ typedef struct { uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ q63_t *pState; /**< points to the array of state coefficients. The array is of length 4*numStages. */ const q31_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */ uint8_t postShift; /**< additional shift, in bits, applied to each output sample. */ } arm_biquad_cas_df1_32x64_ins_q31; /** * @param[in] S points to an instance of the high precision Q31 Biquad cascade filter structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of samples to process. */ void arm_biquad_cas_df1_32x64_q31( const arm_biquad_cas_df1_32x64_ins_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @param[in,out] S points to an instance of the high precision Q31 Biquad cascade filter structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. * @param[in] postShift shift to be applied to the output. Varies according to the coefficients format */ void arm_biquad_cas_df1_32x64_init_q31( arm_biquad_cas_df1_32x64_ins_q31 * S, uint8_t numStages, const q31_t * pCoeffs, q63_t * pState, uint8_t postShift); /** * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter. */ typedef struct { uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ float32_t *pState; /**< points to the array of state coefficients. The array is of length 2*numStages. */ const float32_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */ } arm_biquad_cascade_df2T_instance_f32; /** * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter. */ typedef struct { uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ float32_t *pState; /**< points to the array of state coefficients. The array is of length 4*numStages. */ const float32_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */ } arm_biquad_cascade_stereo_df2T_instance_f32; /** * @brief Instance structure for the floating-point transposed direct form II Biquad cascade filter. */ typedef struct { uint8_t numStages; /**< number of 2nd order stages in the filter. Overall order is 2*numStages. */ float64_t *pState; /**< points to the array of state coefficients. The array is of length 2*numStages. */ float64_t *pCoeffs; /**< points to the array of coefficients. The array is of length 5*numStages. */ } arm_biquad_cascade_df2T_instance_f64; /** * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter. * @param[in] S points to an instance of the filter data structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_df2T_f32( const arm_biquad_cascade_df2T_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter. 2 channels * @param[in] S points to an instance of the filter data structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_stereo_df2T_f32( const arm_biquad_cascade_stereo_df2T_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Processing function for the floating-point transposed direct form II Biquad cascade filter. * @param[in] S points to an instance of the filter data structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of samples to process. */ void arm_biquad_cascade_df2T_f64( const arm_biquad_cascade_df2T_instance_f64 * S, float64_t * pSrc, float64_t * pDst, uint32_t blockSize); #if defined(ARM_MATH_NEON) void arm_biquad_cascade_df2T_compute_coefs_f32( arm_biquad_cascade_df2T_instance_f32 * S, uint8_t numStages, float32_t * pCoeffs); #endif /** * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter. * @param[in,out] S points to an instance of the filter data structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. */ void arm_biquad_cascade_df2T_init_f32( arm_biquad_cascade_df2T_instance_f32 * S, uint8_t numStages, const float32_t * pCoeffs, float32_t * pState); /** * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter. * @param[in,out] S points to an instance of the filter data structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. */ void arm_biquad_cascade_stereo_df2T_init_f32( arm_biquad_cascade_stereo_df2T_instance_f32 * S, uint8_t numStages, const float32_t * pCoeffs, float32_t * pState); /** * @brief Initialization function for the floating-point transposed direct form II Biquad cascade filter. * @param[in,out] S points to an instance of the filter data structure. * @param[in] numStages number of 2nd order stages in the filter. * @param[in] pCoeffs points to the filter coefficients. * @param[in] pState points to the state buffer. */ void arm_biquad_cascade_df2T_init_f64( arm_biquad_cascade_df2T_instance_f64 * S, uint8_t numStages, float64_t * pCoeffs, float64_t * pState); /** * @brief Instance structure for the Q15 FIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of filter stages. */ q15_t *pState; /**< points to the state variable array. The array is of length numStages. */ const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */ } arm_fir_lattice_instance_q15; /** * @brief Instance structure for the Q31 FIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of filter stages. */ q31_t *pState; /**< points to the state variable array. The array is of length numStages. */ const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */ } arm_fir_lattice_instance_q31; /** * @brief Instance structure for the floating-point FIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of filter stages. */ float32_t *pState; /**< points to the state variable array. The array is of length numStages. */ const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numStages. */ } arm_fir_lattice_instance_f32; /** * @brief Initialization function for the Q15 FIR lattice filter. * @param[in] S points to an instance of the Q15 FIR lattice structure. * @param[in] numStages number of filter stages. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages. * @param[in] pState points to the state buffer. The array is of length numStages. */ void arm_fir_lattice_init_q15( arm_fir_lattice_instance_q15 * S, uint16_t numStages, const q15_t * pCoeffs, q15_t * pState); /** * @brief Processing function for the Q15 FIR lattice filter. * @param[in] S points to an instance of the Q15 FIR lattice structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_fir_lattice_q15( const arm_fir_lattice_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 FIR lattice filter. * @param[in] S points to an instance of the Q31 FIR lattice structure. * @param[in] numStages number of filter stages. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages. * @param[in] pState points to the state buffer. The array is of length numStages. */ void arm_fir_lattice_init_q31( arm_fir_lattice_instance_q31 * S, uint16_t numStages, const q31_t * pCoeffs, q31_t * pState); /** * @brief Processing function for the Q31 FIR lattice filter. * @param[in] S points to an instance of the Q31 FIR lattice structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of samples to process. */ void arm_fir_lattice_q31( const arm_fir_lattice_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point FIR lattice filter. * @param[in] S points to an instance of the floating-point FIR lattice structure. * @param[in] numStages number of filter stages. * @param[in] pCoeffs points to the coefficient buffer. The array is of length numStages. * @param[in] pState points to the state buffer. The array is of length numStages. */ void arm_fir_lattice_init_f32( arm_fir_lattice_instance_f32 * S, uint16_t numStages, const float32_t * pCoeffs, float32_t * pState); /** * @brief Processing function for the floating-point FIR lattice filter. * @param[in] S points to an instance of the floating-point FIR lattice structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] blockSize number of samples to process. */ void arm_fir_lattice_f32( const arm_fir_lattice_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Instance structure for the Q15 IIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of stages in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */ q15_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */ q15_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */ } arm_iir_lattice_instance_q15; /** * @brief Instance structure for the Q31 IIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of stages in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */ q31_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */ q31_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */ } arm_iir_lattice_instance_q31; /** * @brief Instance structure for the floating-point IIR lattice filter. */ typedef struct { uint16_t numStages; /**< number of stages in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numStages+blockSize. */ float32_t *pkCoeffs; /**< points to the reflection coefficient array. The array is of length numStages. */ float32_t *pvCoeffs; /**< points to the ladder coefficient array. The array is of length numStages+1. */ } arm_iir_lattice_instance_f32; /** * @brief Processing function for the floating-point IIR lattice filter. * @param[in] S points to an instance of the floating-point IIR lattice structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_iir_lattice_f32( const arm_iir_lattice_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the floating-point IIR lattice filter. * @param[in] S points to an instance of the floating-point IIR lattice structure. * @param[in] numStages number of stages in the filter. * @param[in] pkCoeffs points to the reflection coefficient buffer. The array is of length numStages. * @param[in] pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1. * @param[in] pState points to the state buffer. The array is of length numStages+blockSize-1. * @param[in] blockSize number of samples to process. */ void arm_iir_lattice_init_f32( arm_iir_lattice_instance_f32 * S, uint16_t numStages, float32_t * pkCoeffs, float32_t * pvCoeffs, float32_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q31 IIR lattice filter. * @param[in] S points to an instance of the Q31 IIR lattice structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_iir_lattice_q31( const arm_iir_lattice_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q31 IIR lattice filter. * @param[in] S points to an instance of the Q31 IIR lattice structure. * @param[in] numStages number of stages in the filter. * @param[in] pkCoeffs points to the reflection coefficient buffer. The array is of length numStages. * @param[in] pvCoeffs points to the ladder coefficient buffer. The array is of length numStages+1. * @param[in] pState points to the state buffer. The array is of length numStages+blockSize. * @param[in] blockSize number of samples to process. */ void arm_iir_lattice_init_q31( arm_iir_lattice_instance_q31 * S, uint16_t numStages, q31_t * pkCoeffs, q31_t * pvCoeffs, q31_t * pState, uint32_t blockSize); /** * @brief Processing function for the Q15 IIR lattice filter. * @param[in] S points to an instance of the Q15 IIR lattice structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data. * @param[in] blockSize number of samples to process. */ void arm_iir_lattice_q15( const arm_iir_lattice_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Initialization function for the Q15 IIR lattice filter. * @param[in] S points to an instance of the fixed-point Q15 IIR lattice structure. * @param[in] numStages number of stages in the filter. * @param[in] pkCoeffs points to reflection coefficient buffer. The array is of length numStages. * @param[in] pvCoeffs points to ladder coefficient buffer. The array is of length numStages+1. * @param[in] pState points to state buffer. The array is of length numStages+blockSize. * @param[in] blockSize number of samples to process per call. */ void arm_iir_lattice_init_q15( arm_iir_lattice_instance_q15 * S, uint16_t numStages, q15_t * pkCoeffs, q15_t * pvCoeffs, q15_t * pState, uint32_t blockSize); /** * @brief Instance structure for the floating-point LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ float32_t mu; /**< step size that controls filter coefficient updates. */ } arm_lms_instance_f32; /** * @brief Processing function for floating-point LMS filter. * @param[in] S points to an instance of the floating-point LMS filter structure. * @param[in] pSrc points to the block of input data. * @param[in] pRef points to the block of reference data. * @param[out] pOut points to the block of output data. * @param[out] pErr points to the block of error data. * @param[in] blockSize number of samples to process. */ void arm_lms_f32( const arm_lms_instance_f32 * S, const float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize); /** * @brief Initialization function for floating-point LMS filter. * @param[in] S points to an instance of the floating-point LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] pCoeffs points to the coefficient buffer. * @param[in] pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. */ void arm_lms_init_f32( arm_lms_instance_f32 * S, uint16_t numTaps, float32_t * pCoeffs, float32_t * pState, float32_t mu, uint32_t blockSize); /** * @brief Instance structure for the Q15 LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q15_t mu; /**< step size that controls filter coefficient updates. */ uint32_t postShift; /**< bit shift applied to coefficients. */ } arm_lms_instance_q15; /** * @brief Initialization function for the Q15 LMS filter. * @param[in] S points to an instance of the Q15 LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] pCoeffs points to the coefficient buffer. * @param[in] pState points to the state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. */ void arm_lms_init_q15( arm_lms_instance_q15 * S, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, q15_t mu, uint32_t blockSize, uint32_t postShift); /** * @brief Processing function for Q15 LMS filter. * @param[in] S points to an instance of the Q15 LMS filter structure. * @param[in] pSrc points to the block of input data. * @param[in] pRef points to the block of reference data. * @param[out] pOut points to the block of output data. * @param[out] pErr points to the block of error data. * @param[in] blockSize number of samples to process. */ void arm_lms_q15( const arm_lms_instance_q15 * S, const q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize); /** * @brief Instance structure for the Q31 LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q31_t mu; /**< step size that controls filter coefficient updates. */ uint32_t postShift; /**< bit shift applied to coefficients. */ } arm_lms_instance_q31; /** * @brief Processing function for Q31 LMS filter. * @param[in] S points to an instance of the Q15 LMS filter structure. * @param[in] pSrc points to the block of input data. * @param[in] pRef points to the block of reference data. * @param[out] pOut points to the block of output data. * @param[out] pErr points to the block of error data. * @param[in] blockSize number of samples to process. */ void arm_lms_q31( const arm_lms_instance_q31 * S, const q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize); /** * @brief Initialization function for Q31 LMS filter. * @param[in] S points to an instance of the Q31 LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] pCoeffs points to coefficient buffer. * @param[in] pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. */ void arm_lms_init_q31( arm_lms_instance_q31 * S, uint16_t numTaps, q31_t * pCoeffs, q31_t * pState, q31_t mu, uint32_t blockSize, uint32_t postShift); /** * @brief Instance structure for the floating-point normalized LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ float32_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ float32_t mu; /**< step size that control filter coefficient updates. */ float32_t energy; /**< saves previous frame energy. */ float32_t x0; /**< saves previous input sample. */ } arm_lms_norm_instance_f32; /** * @brief Processing function for floating-point normalized LMS filter. * @param[in] S points to an instance of the floating-point normalized LMS filter structure. * @param[in] pSrc points to the block of input data. * @param[in] pRef points to the block of reference data. * @param[out] pOut points to the block of output data. * @param[out] pErr points to the block of error data. * @param[in] blockSize number of samples to process. */ void arm_lms_norm_f32( arm_lms_norm_instance_f32 * S, const float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize); /** * @brief Initialization function for floating-point normalized LMS filter. * @param[in] S points to an instance of the floating-point LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] pCoeffs points to coefficient buffer. * @param[in] pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. */ void arm_lms_norm_init_f32( arm_lms_norm_instance_f32 * S, uint16_t numTaps, float32_t * pCoeffs, float32_t * pState, float32_t mu, uint32_t blockSize); /** * @brief Instance structure for the Q31 normalized LMS filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ q31_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q31_t mu; /**< step size that controls filter coefficient updates. */ uint8_t postShift; /**< bit shift applied to coefficients. */ const q31_t *recipTable; /**< points to the reciprocal initial value table. */ q31_t energy; /**< saves previous frame energy. */ q31_t x0; /**< saves previous input sample. */ } arm_lms_norm_instance_q31; /** * @brief Processing function for Q31 normalized LMS filter. * @param[in] S points to an instance of the Q31 normalized LMS filter structure. * @param[in] pSrc points to the block of input data. * @param[in] pRef points to the block of reference data. * @param[out] pOut points to the block of output data. * @param[out] pErr points to the block of error data. * @param[in] blockSize number of samples to process. */ void arm_lms_norm_q31( arm_lms_norm_instance_q31 * S, const q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize); /** * @brief Initialization function for Q31 normalized LMS filter. * @param[in] S points to an instance of the Q31 normalized LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] pCoeffs points to coefficient buffer. * @param[in] pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. */ void arm_lms_norm_init_q31( arm_lms_norm_instance_q31 * S, uint16_t numTaps, q31_t * pCoeffs, q31_t * pState, q31_t mu, uint32_t blockSize, uint8_t postShift); /** * @brief Instance structure for the Q15 normalized LMS filter. */ typedef struct { uint16_t numTaps; /**< Number of coefficients in the filter. */ q15_t *pState; /**< points to the state variable array. The array is of length numTaps+blockSize-1. */ q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps. */ q15_t mu; /**< step size that controls filter coefficient updates. */ uint8_t postShift; /**< bit shift applied to coefficients. */ const q15_t *recipTable; /**< Points to the reciprocal initial value table. */ q15_t energy; /**< saves previous frame energy. */ q15_t x0; /**< saves previous input sample. */ } arm_lms_norm_instance_q15; /** * @brief Processing function for Q15 normalized LMS filter. * @param[in] S points to an instance of the Q15 normalized LMS filter structure. * @param[in] pSrc points to the block of input data. * @param[in] pRef points to the block of reference data. * @param[out] pOut points to the block of output data. * @param[out] pErr points to the block of error data. * @param[in] blockSize number of samples to process. */ void arm_lms_norm_q15( arm_lms_norm_instance_q15 * S, const q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize); /** * @brief Initialization function for Q15 normalized LMS filter. * @param[in] S points to an instance of the Q15 normalized LMS filter structure. * @param[in] numTaps number of filter coefficients. * @param[in] pCoeffs points to coefficient buffer. * @param[in] pState points to state buffer. * @param[in] mu step size that controls filter coefficient updates. * @param[in] blockSize number of samples to process. * @param[in] postShift bit shift applied to coefficients. */ void arm_lms_norm_init_q15( arm_lms_norm_instance_q15 * S, uint16_t numTaps, q15_t * pCoeffs, q15_t * pState, q15_t mu, uint32_t blockSize, uint8_t postShift); /** * @brief Correlation of floating-point sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. */ void arm_correlate_f32( const float32_t * pSrcA, uint32_t srcALen, const float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst); /** @brief Correlation of Q15 sequences @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. @param[in] pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. */ void arm_correlate_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch); /** @brief Correlation of Q15 sequences. @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. */ void arm_correlate_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** @brief Correlation of Q15 sequences (fast version). @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the location where the output result is written. Length 2 * max(srcALen, srcBLen) - 1. @return none */ void arm_correlate_fast_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); /** @brief Correlation of Q15 sequences (fast version). @param[in] pSrcA points to the first input sequence. @param[in] srcALen length of the first input sequence. @param[in] pSrcB points to the second input sequence. @param[in] srcBLen length of the second input sequence. @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. @param[in] pScratch points to scratch buffer of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. */ void arm_correlate_fast_opt_q15( const q15_t * pSrcA, uint32_t srcALen, const q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch); /** * @brief Correlation of Q31 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. */ void arm_correlate_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** @brief Correlation of Q31 sequences (fast version). @param[in] pSrcA points to the first input sequence @param[in] srcALen length of the first input sequence @param[in] pSrcB points to the second input sequence @param[in] srcBLen length of the second input sequence @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. */ void arm_correlate_fast_q31( const q31_t * pSrcA, uint32_t srcALen, const q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); /** * @brief Correlation of Q7 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. * @param[in] pScratch1 points to scratch buffer(of type q15_t) of size max(srcALen, srcBLen) + 2*min(srcALen, srcBLen) - 2. * @param[in] pScratch2 points to scratch buffer (of type q15_t) of size min(srcALen, srcBLen). */ void arm_correlate_opt_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, q15_t * pScratch1, q15_t * pScratch2); /** * @brief Correlation of Q7 sequences. * @param[in] pSrcA points to the first input sequence. * @param[in] srcALen length of the first input sequence. * @param[in] pSrcB points to the second input sequence. * @param[in] srcBLen length of the second input sequence. * @param[out] pDst points to the block of output data Length 2 * max(srcALen, srcBLen) - 1. */ void arm_correlate_q7( const q7_t * pSrcA, uint32_t srcALen, const q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst); /** * @brief Instance structure for the floating-point sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ float32_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ const float32_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_f32; /** * @brief Instance structure for the Q31 sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ q31_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ const q31_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_q31; /** * @brief Instance structure for the Q15 sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ q15_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ const q15_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_q15; /** * @brief Instance structure for the Q7 sparse FIR filter. */ typedef struct { uint16_t numTaps; /**< number of coefficients in the filter. */ uint16_t stateIndex; /**< state buffer index. Points to the oldest sample in the state buffer. */ q7_t *pState; /**< points to the state buffer array. The array is of length maxDelay+blockSize-1. */ const q7_t *pCoeffs; /**< points to the coefficient array. The array is of length numTaps.*/ uint16_t maxDelay; /**< maximum offset specified by the pTapDelay array. */ int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ } arm_fir_sparse_instance_q7; /** * @brief Processing function for the floating-point sparse FIR filter. * @param[in] S points to an instance of the floating-point sparse FIR structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] pScratchIn points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. */ void arm_fir_sparse_f32( arm_fir_sparse_instance_f32 * S, const float32_t * pSrc, float32_t * pDst, float32_t * pScratchIn, uint32_t blockSize); /** * @brief Initialization function for the floating-point sparse FIR filter. * @param[in,out] S points to an instance of the floating-point sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] pCoeffs points to the array of filter coefficients. * @param[in] pState points to the state buffer. * @param[in] pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. */ void arm_fir_sparse_init_f32( arm_fir_sparse_instance_f32 * S, uint16_t numTaps, const float32_t * pCoeffs, float32_t * pState, int32_t * pTapDelay, uint16_t maxDelay, uint32_t blockSize); /** * @brief Processing function for the Q31 sparse FIR filter. * @param[in] S points to an instance of the Q31 sparse FIR structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] pScratchIn points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. */ void arm_fir_sparse_q31( arm_fir_sparse_instance_q31 * S, const q31_t * pSrc, q31_t * pDst, q31_t * pScratchIn, uint32_t blockSize); /** * @brief Initialization function for the Q31 sparse FIR filter. * @param[in,out] S points to an instance of the Q31 sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] pCoeffs points to the array of filter coefficients. * @param[in] pState points to the state buffer. * @param[in] pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. */ void arm_fir_sparse_init_q31( arm_fir_sparse_instance_q31 * S, uint16_t numTaps, const q31_t * pCoeffs, q31_t * pState, int32_t * pTapDelay, uint16_t maxDelay, uint32_t blockSize); /** * @brief Processing function for the Q15 sparse FIR filter. * @param[in] S points to an instance of the Q15 sparse FIR structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] pScratchIn points to a temporary buffer of size blockSize. * @param[in] pScratchOut points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. */ void arm_fir_sparse_q15( arm_fir_sparse_instance_q15 * S, const q15_t * pSrc, q15_t * pDst, q15_t * pScratchIn, q31_t * pScratchOut, uint32_t blockSize); /** * @brief Initialization function for the Q15 sparse FIR filter. * @param[in,out] S points to an instance of the Q15 sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] pCoeffs points to the array of filter coefficients. * @param[in] pState points to the state buffer. * @param[in] pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. */ void arm_fir_sparse_init_q15( arm_fir_sparse_instance_q15 * S, uint16_t numTaps, const q15_t * pCoeffs, q15_t * pState, int32_t * pTapDelay, uint16_t maxDelay, uint32_t blockSize); /** * @brief Processing function for the Q7 sparse FIR filter. * @param[in] S points to an instance of the Q7 sparse FIR structure. * @param[in] pSrc points to the block of input data. * @param[out] pDst points to the block of output data * @param[in] pScratchIn points to a temporary buffer of size blockSize. * @param[in] pScratchOut points to a temporary buffer of size blockSize. * @param[in] blockSize number of input samples to process per call. */ void arm_fir_sparse_q7( arm_fir_sparse_instance_q7 * S, const q7_t * pSrc, q7_t * pDst, q7_t * pScratchIn, q31_t * pScratchOut, uint32_t blockSize); /** * @brief Initialization function for the Q7 sparse FIR filter. * @param[in,out] S points to an instance of the Q7 sparse FIR structure. * @param[in] numTaps number of nonzero coefficients in the filter. * @param[in] pCoeffs points to the array of filter coefficients. * @param[in] pState points to the state buffer. * @param[in] pTapDelay points to the array of offset times. * @param[in] maxDelay maximum offset time supported. * @param[in] blockSize number of samples that will be processed per block. */ void arm_fir_sparse_init_q7( arm_fir_sparse_instance_q7 * S, uint16_t numTaps, const q7_t * pCoeffs, q7_t * pState, int32_t * pTapDelay, uint16_t maxDelay, uint32_t blockSize); /** * @brief Floating-point sin_cos function. * @param[in] theta input value in degrees * @param[out] pSinVal points to the processed sine output. * @param[out] pCosVal points to the processed cos output. */ void arm_sin_cos_f32( float32_t theta, float32_t * pSinVal, float32_t * pCosVal); /** * @brief Q31 sin_cos function. * @param[in] theta scaled input value in degrees * @param[out] pSinVal points to the processed sine output. * @param[out] pCosVal points to the processed cosine output. */ void arm_sin_cos_q31( q31_t theta, q31_t * pSinVal, q31_t * pCosVal); /** * @brief Floating-point complex conjugate. * @param[in] pSrc points to the input vector * @param[out] pDst points to the output vector * @param[in] numSamples number of complex samples in each vector */ void arm_cmplx_conj_f32( const float32_t * pSrc, float32_t * pDst, uint32_t numSamples); /** * @brief Q31 complex conjugate. * @param[in] pSrc points to the input vector * @param[out] pDst points to the output vector * @param[in] numSamples number of complex samples in each vector */ void arm_cmplx_conj_q31( const q31_t * pSrc, q31_t * pDst, uint32_t numSamples); /** * @brief Q15 complex conjugate. * @param[in] pSrc points to the input vector * @param[out] pDst points to the output vector * @param[in] numSamples number of complex samples in each vector */ void arm_cmplx_conj_q15( const q15_t * pSrc, q15_t * pDst, uint32_t numSamples); /** * @brief Floating-point complex magnitude squared * @param[in] pSrc points to the complex input vector * @param[out] pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector */ void arm_cmplx_mag_squared_f32( const float32_t * pSrc, float32_t * pDst, uint32_t numSamples); /** * @brief Q31 complex magnitude squared * @param[in] pSrc points to the complex input vector * @param[out] pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector */ void arm_cmplx_mag_squared_q31( const q31_t * pSrc, q31_t * pDst, uint32_t numSamples); /** * @brief Q15 complex magnitude squared * @param[in] pSrc points to the complex input vector * @param[out] pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector */ void arm_cmplx_mag_squared_q15( const q15_t * pSrc, q15_t * pDst, uint32_t numSamples); /** * @ingroup groupController */ /** * @defgroup PID PID Motor Control * * A Proportional Integral Derivative (PID) controller is a generic feedback control * loop mechanism widely used in industrial control systems. * A PID controller is the most commonly used type of feedback controller. * * This set of functions implements (PID) controllers * for Q15, Q31, and floating-point data types. The functions operate on a single sample * of data and each call to the function returns a single processed value. * <code>S</code> points to an instance of the PID control data structure. <code>in</code> * is the input sample value. The functions return the output value. * * \par Algorithm: * <pre> * y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2] * A0 = Kp + Ki + Kd * A1 = (-Kp ) - (2 * Kd ) * A2 = Kd * </pre> * * \par * where \c Kp is proportional constant, \c Ki is Integral constant and \c Kd is Derivative constant * * \par * \image html PID.gif "Proportional Integral Derivative Controller" * * \par * The PID controller calculates an "error" value as the difference between * the measured output and the reference input. * The controller attempts to minimize the error by adjusting the process control inputs. * The proportional value determines the reaction to the current error, * the integral value determines the reaction based on the sum of recent errors, * and the derivative value determines the reaction based on the rate at which the error has been changing. * * \par Instance Structure * The Gains A0, A1, A2 and state variables for a PID controller are stored together in an instance data structure. * A separate instance structure must be defined for each PID Controller. * There are separate instance structure declarations for each of the 3 supported data types. * * \par Reset Functions * There is also an associated reset function for each data type which clears the state array. * * \par Initialization Functions * There is also an associated initialization function for each data type. * The initialization function performs the following operations: * - Initializes the Gains A0, A1, A2 from Kp,Ki, Kd gains. * - Zeros out the values in the state buffer. * * \par * Instance structure cannot be placed into a const data section and it is recommended to use the initialization function. * * \par Fixed-Point Behavior * Care must be taken when using the fixed-point versions of the PID Controller functions. * In particular, the overflow and saturation behavior of the accumulator used in each function must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup PID * @{ */ /** * @brief Process function for the floating-point PID Control. * @param[in,out] S is an instance of the floating-point PID Control structure * @param[in] in input sample to process * @return processed output sample. */ __STATIC_FORCEINLINE float32_t arm_pid_f32( arm_pid_instance_f32 * S, float32_t in) { float32_t out; /* y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2] */ out = (S->A0 * in) + (S->A1 * S->state[0]) + (S->A2 * S->state[1]) + (S->state[2]); /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } /** @brief Process function for the Q31 PID Control. @param[in,out] S points to an instance of the Q31 PID Control structure @param[in] in input sample to process @return processed output sample. \par Scaling and Overflow Behavior The function is implemented using an internal 64-bit accumulator. The accumulator has a 2.62 format and maintains full precision of the intermediate multiplication results but provides only a single guard bit. Thus, if the accumulator result overflows it wraps around rather than clip. In order to avoid overflows completely the input signal must be scaled down by 2 bits as there are four additions. After all multiply-accumulates are performed, the 2.62 accumulator is truncated to 1.32 format and then saturated to 1.31 format. */ __STATIC_FORCEINLINE q31_t arm_pid_q31( arm_pid_instance_q31 * S, q31_t in) { q63_t acc; q31_t out; /* acc = A0 * x[n] */ acc = (q63_t) S->A0 * in; /* acc += A1 * x[n-1] */ acc += (q63_t) S->A1 * S->state[0]; /* acc += A2 * x[n-2] */ acc += (q63_t) S->A2 * S->state[1]; /* convert output to 1.31 format to add y[n-1] */ out = (q31_t) (acc >> 31U); /* out += y[n-1] */ out += S->state[2]; /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } /** @brief Process function for the Q15 PID Control. @param[in,out] S points to an instance of the Q15 PID Control structure @param[in] in input sample to process @return processed output sample. \par Scaling and Overflow Behavior The function is implemented using a 64-bit internal accumulator. Both Gains and state variables are represented in 1.15 format and multiplications yield a 2.30 result. The 2.30 intermediate results are accumulated in a 64-bit accumulator in 34.30 format. There is no risk of internal overflow with this approach and the full precision of intermediate multiplications is preserved. After all additions have been performed, the accumulator is truncated to 34.15 format by discarding low 15 bits. Lastly, the accumulator is saturated to yield a result in 1.15 format. */ __STATIC_FORCEINLINE q15_t arm_pid_q15( arm_pid_instance_q15 * S, q15_t in) { q63_t acc; q15_t out; #if defined (ARM_MATH_DSP) /* Implementation of PID controller */ /* acc = A0 * x[n] */ acc = (q31_t) __SMUAD((uint32_t)S->A0, (uint32_t)in); /* acc += A1 * x[n-1] + A2 * x[n-2] */ acc = (q63_t)__SMLALD((uint32_t)S->A1, (uint32_t)read_q15x2 (S->state), (uint64_t)acc); #else /* acc = A0 * x[n] */ acc = ((q31_t) S->A0) * in; /* acc += A1 * x[n-1] + A2 * x[n-2] */ acc += (q31_t) S->A1 * S->state[0]; acc += (q31_t) S->A2 * S->state[1]; #endif /* acc += y[n-1] */ acc += (q31_t) S->state[2] << 15; /* saturate the output */ out = (q15_t) (__SSAT((acc >> 15), 16)); /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } /** * @} end of PID group */ /** * @brief Floating-point matrix inverse. * @param[in] src points to the instance of the input floating-point matrix structure. * @param[out] dst points to the instance of the output floating-point matrix structure. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR. */ arm_status arm_mat_inverse_f32( const arm_matrix_instance_f32 * src, arm_matrix_instance_f32 * dst); /** * @brief Floating-point matrix inverse. * @param[in] src points to the instance of the input floating-point matrix structure. * @param[out] dst points to the instance of the output floating-point matrix structure. * @return The function returns ARM_MATH_SIZE_MISMATCH, if the dimensions do not match. * If the input matrix is singular (does not have an inverse), then the algorithm terminates and returns error status ARM_MATH_SINGULAR. */ arm_status arm_mat_inverse_f64( const arm_matrix_instance_f64 * src, arm_matrix_instance_f64 * dst); /** * @ingroup groupController */ /** * @defgroup clarke Vector Clarke Transform * Forward Clarke transform converts the instantaneous stator phases into a two-coordinate time invariant vector. * Generally the Clarke transform uses three-phase currents <code>Ia, Ib and Ic</code> to calculate currents * in the two-phase orthogonal stator axis <code>Ialpha</code> and <code>Ibeta</code>. * When <code>Ialpha</code> is superposed with <code>Ia</code> as shown in the figure below * \image html clarke.gif Stator current space vector and its components in (a,b). * and <code>Ia + Ib + Ic = 0</code>, in this condition <code>Ialpha</code> and <code>Ibeta</code> * can be calculated using only <code>Ia</code> and <code>Ib</code>. * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html clarkeFormula.gif * where <code>Ia</code> and <code>Ib</code> are the instantaneous stator phases and * <code>pIalpha</code> and <code>pIbeta</code> are the two coordinates of time invariant vector. * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Clarke transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup clarke * @{ */ /** * * @brief Floating-point Clarke transform * @param[in] Ia input three-phase coordinate <code>a</code> * @param[in] Ib input three-phase coordinate <code>b</code> * @param[out] pIalpha points to output two-phase orthogonal vector axis alpha * @param[out] pIbeta points to output two-phase orthogonal vector axis beta * @return none */ __STATIC_FORCEINLINE void arm_clarke_f32( float32_t Ia, float32_t Ib, float32_t * pIalpha, float32_t * pIbeta) { /* Calculate pIalpha using the equation, pIalpha = Ia */ *pIalpha = Ia; /* Calculate pIbeta using the equation, pIbeta = (1/sqrt(3)) * Ia + (2/sqrt(3)) * Ib */ *pIbeta = ((float32_t) 0.57735026919 * Ia + (float32_t) 1.15470053838 * Ib); } /** @brief Clarke transform for Q31 version @param[in] Ia input three-phase coordinate <code>a</code> @param[in] Ib input three-phase coordinate <code>b</code> @param[out] pIalpha points to output two-phase orthogonal vector axis alpha @param[out] pIbeta points to output two-phase orthogonal vector axis beta @return none \par Scaling and Overflow Behavior The function is implemented using an internal 32-bit accumulator. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. There is saturation on the addition, hence there is no risk of overflow. */ __STATIC_FORCEINLINE void arm_clarke_q31( q31_t Ia, q31_t Ib, q31_t * pIalpha, q31_t * pIbeta) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ /* Calculating pIalpha from Ia by equation pIalpha = Ia */ *pIalpha = Ia; /* Intermediate product is calculated by (1/(sqrt(3)) * Ia) */ product1 = (q31_t) (((q63_t) Ia * 0x24F34E8B) >> 30); /* Intermediate product is calculated by (2/sqrt(3) * Ib) */ product2 = (q31_t) (((q63_t) Ib * 0x49E69D16) >> 30); /* pIbeta is calculated by adding the intermediate products */ *pIbeta = __QADD(product1, product2); } /** * @} end of clarke group */ /** * @ingroup groupController */ /** * @defgroup inv_clarke Vector Inverse Clarke Transform * Inverse Clarke transform converts the two-coordinate time invariant vector into instantaneous stator phases. * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html clarkeInvFormula.gif * where <code>pIa</code> and <code>pIb</code> are the instantaneous stator phases and * <code>Ialpha</code> and <code>Ibeta</code> are the two coordinates of time invariant vector. * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Clarke transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup inv_clarke * @{ */ /** * @brief Floating-point Inverse Clarke transform * @param[in] Ialpha input two-phase orthogonal vector axis alpha * @param[in] Ibeta input two-phase orthogonal vector axis beta * @param[out] pIa points to output three-phase coordinate <code>a</code> * @param[out] pIb points to output three-phase coordinate <code>b</code> * @return none */ __STATIC_FORCEINLINE void arm_inv_clarke_f32( float32_t Ialpha, float32_t Ibeta, float32_t * pIa, float32_t * pIb) { /* Calculating pIa from Ialpha by equation pIa = Ialpha */ *pIa = Ialpha; /* Calculating pIb from Ialpha and Ibeta by equation pIb = -(1/2) * Ialpha + (sqrt(3)/2) * Ibeta */ *pIb = -0.5f * Ialpha + 0.8660254039f * Ibeta; } /** @brief Inverse Clarke transform for Q31 version @param[in] Ialpha input two-phase orthogonal vector axis alpha @param[in] Ibeta input two-phase orthogonal vector axis beta @param[out] pIa points to output three-phase coordinate <code>a</code> @param[out] pIb points to output three-phase coordinate <code>b</code> @return none \par Scaling and Overflow Behavior The function is implemented using an internal 32-bit accumulator. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. There is saturation on the subtraction, hence there is no risk of overflow. */ __STATIC_FORCEINLINE void arm_inv_clarke_q31( q31_t Ialpha, q31_t Ibeta, q31_t * pIa, q31_t * pIb) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ /* Calculating pIa from Ialpha by equation pIa = Ialpha */ *pIa = Ialpha; /* Intermediate product is calculated by (1/(2*sqrt(3)) * Ia) */ product1 = (q31_t) (((q63_t) (Ialpha) * (0x40000000)) >> 31); /* Intermediate product is calculated by (1/sqrt(3) * pIb) */ product2 = (q31_t) (((q63_t) (Ibeta) * (0x6ED9EBA1)) >> 31); /* pIb is calculated by subtracting the products */ *pIb = __QSUB(product2, product1); } /** * @} end of inv_clarke group */ /** * @ingroup groupController */ /** * @defgroup park Vector Park Transform * * Forward Park transform converts the input two-coordinate vector to flux and torque components. * The Park transform can be used to realize the transformation of the <code>Ialpha</code> and the <code>Ibeta</code> currents * from the stationary to the moving reference frame and control the spatial relationship between * the stator vector current and rotor flux vector. * If we consider the d axis aligned with the rotor flux, the diagram below shows the * current vector and the relationship from the two reference frames: * \image html park.gif "Stator current space vector and its component in (a,b) and in the d,q rotating reference frame" * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html parkFormula.gif * where <code>Ialpha</code> and <code>Ibeta</code> are the stator vector components, * <code>pId</code> and <code>pIq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the * cosine and sine values of theta (rotor flux position). * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Park transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup park * @{ */ /** * @brief Floating-point Park transform * @param[in] Ialpha input two-phase vector coordinate alpha * @param[in] Ibeta input two-phase vector coordinate beta * @param[out] pId points to output rotor reference frame d * @param[out] pIq points to output rotor reference frame q * @param[in] sinVal sine value of rotation angle theta * @param[in] cosVal cosine value of rotation angle theta * @return none * * The function implements the forward Park transform. * */ __STATIC_FORCEINLINE void arm_park_f32( float32_t Ialpha, float32_t Ibeta, float32_t * pId, float32_t * pIq, float32_t sinVal, float32_t cosVal) { /* Calculate pId using the equation, pId = Ialpha * cosVal + Ibeta * sinVal */ *pId = Ialpha * cosVal + Ibeta * sinVal; /* Calculate pIq using the equation, pIq = - Ialpha * sinVal + Ibeta * cosVal */ *pIq = -Ialpha * sinVal + Ibeta * cosVal; } /** @brief Park transform for Q31 version @param[in] Ialpha input two-phase vector coordinate alpha @param[in] Ibeta input two-phase vector coordinate beta @param[out] pId points to output rotor reference frame d @param[out] pIq points to output rotor reference frame q @param[in] sinVal sine value of rotation angle theta @param[in] cosVal cosine value of rotation angle theta @return none \par Scaling and Overflow Behavior The function is implemented using an internal 32-bit accumulator. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. There is saturation on the addition and subtraction, hence there is no risk of overflow. */ __STATIC_FORCEINLINE void arm_park_q31( q31_t Ialpha, q31_t Ibeta, q31_t * pId, q31_t * pIq, q31_t sinVal, q31_t cosVal) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ q31_t product3, product4; /* Temporary variables used to store intermediate results */ /* Intermediate product is calculated by (Ialpha * cosVal) */ product1 = (q31_t) (((q63_t) (Ialpha) * (cosVal)) >> 31); /* Intermediate product is calculated by (Ibeta * sinVal) */ product2 = (q31_t) (((q63_t) (Ibeta) * (sinVal)) >> 31); /* Intermediate product is calculated by (Ialpha * sinVal) */ product3 = (q31_t) (((q63_t) (Ialpha) * (sinVal)) >> 31); /* Intermediate product is calculated by (Ibeta * cosVal) */ product4 = (q31_t) (((q63_t) (Ibeta) * (cosVal)) >> 31); /* Calculate pId by adding the two intermediate products 1 and 2 */ *pId = __QADD(product1, product2); /* Calculate pIq by subtracting the two intermediate products 3 from 4 */ *pIq = __QSUB(product4, product3); } /** * @} end of park group */ /** * @ingroup groupController */ /** * @defgroup inv_park Vector Inverse Park transform * Inverse Park transform converts the input flux and torque components to two-coordinate vector. * * The function operates on a single sample of data and each call to the function returns the processed output. * The library provides separate functions for Q31 and floating-point data types. * \par Algorithm * \image html parkInvFormula.gif * where <code>pIalpha</code> and <code>pIbeta</code> are the stator vector components, * <code>Id</code> and <code>Iq</code> are rotor vector components and <code>cosVal</code> and <code>sinVal</code> are the * cosine and sine values of theta (rotor flux position). * \par Fixed-Point Behavior * Care must be taken when using the Q31 version of the Park transform. * In particular, the overflow and saturation behavior of the accumulator used must be considered. * Refer to the function specific documentation below for usage guidelines. */ /** * @addtogroup inv_park * @{ */ /** * @brief Floating-point Inverse Park transform * @param[in] Id input coordinate of rotor reference frame d * @param[in] Iq input coordinate of rotor reference frame q * @param[out] pIalpha points to output two-phase orthogonal vector axis alpha * @param[out] pIbeta points to output two-phase orthogonal vector axis beta * @param[in] sinVal sine value of rotation angle theta * @param[in] cosVal cosine value of rotation angle theta * @return none */ __STATIC_FORCEINLINE void arm_inv_park_f32( float32_t Id, float32_t Iq, float32_t * pIalpha, float32_t * pIbeta, float32_t sinVal, float32_t cosVal) { /* Calculate pIalpha using the equation, pIalpha = Id * cosVal - Iq * sinVal */ *pIalpha = Id * cosVal - Iq * sinVal; /* Calculate pIbeta using the equation, pIbeta = Id * sinVal + Iq * cosVal */ *pIbeta = Id * sinVal + Iq * cosVal; } /** @brief Inverse Park transform for Q31 version @param[in] Id input coordinate of rotor reference frame d @param[in] Iq input coordinate of rotor reference frame q @param[out] pIalpha points to output two-phase orthogonal vector axis alpha @param[out] pIbeta points to output two-phase orthogonal vector axis beta @param[in] sinVal sine value of rotation angle theta @param[in] cosVal cosine value of rotation angle theta @return none @par Scaling and Overflow Behavior The function is implemented using an internal 32-bit accumulator. The accumulator maintains 1.31 format by truncating lower 31 bits of the intermediate multiplication in 2.62 format. There is saturation on the addition, hence there is no risk of overflow. */ __STATIC_FORCEINLINE void arm_inv_park_q31( q31_t Id, q31_t Iq, q31_t * pIalpha, q31_t * pIbeta, q31_t sinVal, q31_t cosVal) { q31_t product1, product2; /* Temporary variables used to store intermediate results */ q31_t product3, product4; /* Temporary variables used to store intermediate results */ /* Intermediate product is calculated by (Id * cosVal) */ product1 = (q31_t) (((q63_t) (Id) * (cosVal)) >> 31); /* Intermediate product is calculated by (Iq * sinVal) */ product2 = (q31_t) (((q63_t) (Iq) * (sinVal)) >> 31); /* Intermediate product is calculated by (Id * sinVal) */ product3 = (q31_t) (((q63_t) (Id) * (sinVal)) >> 31); /* Intermediate product is calculated by (Iq * cosVal) */ product4 = (q31_t) (((q63_t) (Iq) * (cosVal)) >> 31); /* Calculate pIalpha by using the two intermediate products 1 and 2 */ *pIalpha = __QSUB(product1, product2); /* Calculate pIbeta by using the two intermediate products 3 and 4 */ *pIbeta = __QADD(product4, product3); } /** * @} end of Inverse park group */ /** * @ingroup groupInterpolation */ /** * @defgroup LinearInterpolate Linear Interpolation * * Linear interpolation is a method of curve fitting using linear polynomials. * Linear interpolation works by effectively drawing a straight line between two neighboring samples and returning the appropriate point along that line * * \par * \image html LinearInterp.gif "Linear interpolation" * * \par * A Linear Interpolate function calculates an output value(y), for the input(x) * using linear interpolation of the input values x0, x1( nearest input values) and the output values y0 and y1(nearest output values) * * \par Algorithm: * <pre> * y = y0 + (x - x0) * ((y1 - y0)/(x1-x0)) * where x0, x1 are nearest values of input x * y0, y1 are nearest values to output y * </pre> * * \par * This set of functions implements Linear interpolation process * for Q7, Q15, Q31, and floating-point data types. The functions operate on a single * sample of data and each call to the function returns a single processed value. * <code>S</code> points to an instance of the Linear Interpolate function data structure. * <code>x</code> is the input sample value. The functions returns the output value. * * \par * if x is outside of the table boundary, Linear interpolation returns first value of the table * if x is below input range and returns last value of table if x is above range. */ /** * @addtogroup LinearInterpolate * @{ */ /** * @brief Process function for the floating-point Linear Interpolation Function. * @param[in,out] S is an instance of the floating-point Linear Interpolation structure * @param[in] x input sample to process * @return y processed output sample. * */ __STATIC_FORCEINLINE float32_t arm_linear_interp_f32( arm_linear_interp_instance_f32 * S, float32_t x) { float32_t y; float32_t x0, x1; /* Nearest input values */ float32_t y0, y1; /* Nearest output values */ float32_t xSpacing = S->xSpacing; /* spacing between input values */ int32_t i; /* Index variable */ float32_t *pYData = S->pYData; /* pointer to output table */ /* Calculation of index */ i = (int32_t) ((x - S->x1) / xSpacing); if (i < 0) { /* Iniatilize output for below specified range as least output value of table */ y = pYData[0]; } else if ((uint32_t)i >= S->nValues) { /* Iniatilize output for above specified range as last output value of table */ y = pYData[S->nValues - 1]; } else { /* Calculation of nearest input values */ x0 = S->x1 + i * xSpacing; x1 = S->x1 + (i + 1) * xSpacing; /* Read of nearest output values */ y0 = pYData[i]; y1 = pYData[i + 1]; /* Calculation of output */ y = y0 + (x - x0) * ((y1 - y0) / (x1 - x0)); } /* returns output value */ return (y); } /** * * @brief Process function for the Q31 Linear Interpolation Function. * @param[in] pYData pointer to Q31 Linear Interpolation table * @param[in] x input sample to process * @param[in] nValues number of table values * @return y processed output sample. * * \par * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part. * This function can support maximum of table size 2^12. * */ __STATIC_FORCEINLINE q31_t arm_linear_interp_q31( q31_t * pYData, q31_t x, uint32_t nValues) { q31_t y; /* output */ q31_t y0, y1; /* Nearest output values */ q31_t fract; /* fractional part */ int32_t index; /* Index to read nearest output values */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ index = ((x & (q31_t)0xFFF00000) >> 20); if (index >= (int32_t)(nValues - 1)) { return (pYData[nValues - 1]); } else if (index < 0) { return (pYData[0]); } else { /* 20 bits for the fractional part */ /* shift left by 11 to keep fract in 1.31 format */ fract = (x & 0x000FFFFF) << 11; /* Read two nearest output values from the index in 1.31(q31) format */ y0 = pYData[index]; y1 = pYData[index + 1]; /* Calculation of y0 * (1-fract) and y is in 2.30 format */ y = ((q31_t) ((q63_t) y0 * (0x7FFFFFFF - fract) >> 32)); /* Calculation of y0 * (1-fract) + y1 *fract and y is in 2.30 format */ y += ((q31_t) (((q63_t) y1 * fract) >> 32)); /* Convert y to 1.31 format */ return (y << 1U); } } /** * * @brief Process function for the Q15 Linear Interpolation Function. * @param[in] pYData pointer to Q15 Linear Interpolation table * @param[in] x input sample to process * @param[in] nValues number of table values * @return y processed output sample. * * \par * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part. * This function can support maximum of table size 2^12. * */ __STATIC_FORCEINLINE q15_t arm_linear_interp_q15( q15_t * pYData, q31_t x, uint32_t nValues) { q63_t y; /* output */ q15_t y0, y1; /* Nearest output values */ q31_t fract; /* fractional part */ int32_t index; /* Index to read nearest output values */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ index = ((x & (int32_t)0xFFF00000) >> 20); if (index >= (int32_t)(nValues - 1)) { return (pYData[nValues - 1]); } else if (index < 0) { return (pYData[0]); } else { /* 20 bits for the fractional part */ /* fract is in 12.20 format */ fract = (x & 0x000FFFFF); /* Read two nearest output values from the index */ y0 = pYData[index]; y1 = pYData[index + 1]; /* Calculation of y0 * (1-fract) and y is in 13.35 format */ y = ((q63_t) y0 * (0xFFFFF - fract)); /* Calculation of (y0 * (1-fract) + y1 * fract) and y is in 13.35 format */ y += ((q63_t) y1 * (fract)); /* convert y to 1.15 format */ return (q15_t) (y >> 20); } } /** * * @brief Process function for the Q7 Linear Interpolation Function. * @param[in] pYData pointer to Q7 Linear Interpolation table * @param[in] x input sample to process * @param[in] nValues number of table values * @return y processed output sample. * * \par * Input sample <code>x</code> is in 12.20 format which contains 12 bits for table index and 20 bits for fractional part. * This function can support maximum of table size 2^12. */ __STATIC_FORCEINLINE q7_t arm_linear_interp_q7( q7_t * pYData, q31_t x, uint32_t nValues) { q31_t y; /* output */ q7_t y0, y1; /* Nearest output values */ q31_t fract; /* fractional part */ uint32_t index; /* Index to read nearest output values */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ if (x < 0) { return (pYData[0]); } index = (x >> 20) & 0xfff; if (index >= (nValues - 1)) { return (pYData[nValues - 1]); } else { /* 20 bits for the fractional part */ /* fract is in 12.20 format */ fract = (x & 0x000FFFFF); /* Read two nearest output values from the index and are in 1.7(q7) format */ y0 = pYData[index]; y1 = pYData[index + 1]; /* Calculation of y0 * (1-fract ) and y is in 13.27(q27) format */ y = ((y0 * (0xFFFFF - fract))); /* Calculation of y1 * fract + y0 * (1-fract) and y is in 13.27(q27) format */ y += (y1 * fract); /* convert y to 1.7(q7) format */ return (q7_t) (y >> 20); } } /** * @} end of LinearInterpolate group */ /** * @brief Fast approximation to the trigonometric sine function for floating-point data. * @param[in] x input value in radians. * @return sin(x). */ float32_t arm_sin_f32( float32_t x); /** * @brief Fast approximation to the trigonometric sine function for Q31 data. * @param[in] x Scaled input value in radians. * @return sin(x). */ q31_t arm_sin_q31( q31_t x); /** * @brief Fast approximation to the trigonometric sine function for Q15 data. * @param[in] x Scaled input value in radians. * @return sin(x). */ q15_t arm_sin_q15( q15_t x); /** * @brief Fast approximation to the trigonometric cosine function for floating-point data. * @param[in] x input value in radians. * @return cos(x). */ float32_t arm_cos_f32( float32_t x); /** * @brief Fast approximation to the trigonometric cosine function for Q31 data. * @param[in] x Scaled input value in radians. * @return cos(x). */ q31_t arm_cos_q31( q31_t x); /** * @brief Fast approximation to the trigonometric cosine function for Q15 data. * @param[in] x Scaled input value in radians. * @return cos(x). */ q15_t arm_cos_q15( q15_t x); /** * @ingroup groupFastMath */ /** * @defgroup SQRT Square Root * * Computes the square root of a number. * There are separate functions for Q15, Q31, and floating-point data types. * The square root function is computed using the Newton-Raphson algorithm. * This is an iterative algorithm of the form: * <pre> * x1 = x0 - f(x0)/f'(x0) * </pre> * where <code>x1</code> is the current estimate, * <code>x0</code> is the previous estimate, and * <code>f'(x0)</code> is the derivative of <code>f()</code> evaluated at <code>x0</code>. * For the square root function, the algorithm reduces to: * <pre> * x0 = in/2 [initial guess] * x1 = 1/2 * ( x0 + in / x0) [each iteration] * </pre> */ /** * @addtogroup SQRT * @{ */ /** @brief Floating-point square root function. @param[in] in input value @param[out] pOut square root of input value @return execution status - \ref ARM_MATH_SUCCESS : input value is positive - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0 */ __STATIC_FORCEINLINE arm_status arm_sqrt_f32( float32_t in, float32_t * pOut) { if (in >= 0.0f) { #if defined ( __CC_ARM ) #if defined __TARGET_FPU_VFP *pOut = __sqrtf(in); #else *pOut = sqrtf(in); #endif #elif defined ( __ICCARM__ ) #if defined __ARMVFP__ __ASM("VSQRT.F32 %0,%1" : "=t"(*pOut) : "t"(in)); #else *pOut = sqrtf(in); #endif #else *pOut = sqrtf(in); #endif return (ARM_MATH_SUCCESS); } else { *pOut = 0.0f; return (ARM_MATH_ARGUMENT_ERROR); } } /** @brief Q31 square root function. @param[in] in input value. The range of the input value is [0 +1) or 0x00000000 to 0x7FFFFFFF @param[out] pOut points to square root of input value @return execution status - \ref ARM_MATH_SUCCESS : input value is positive - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0 */ arm_status arm_sqrt_q31( q31_t in, q31_t * pOut); /** @brief Q15 square root function. @param[in] in input value. The range of the input value is [0 +1) or 0x0000 to 0x7FFF @param[out] pOut points to square root of input value @return execution status - \ref ARM_MATH_SUCCESS : input value is positive - \ref ARM_MATH_ARGUMENT_ERROR : input value is negative; *pOut is set to 0 */ arm_status arm_sqrt_q15( q15_t in, q15_t * pOut); /** * @brief Vector Floating-point square root function. * @param[in] pIn input vector. * @param[out] pOut vector of square roots of input elements. * @param[in] len length of input vector. * @return The function returns ARM_MATH_SUCCESS if input value is positive value or ARM_MATH_ARGUMENT_ERROR if * <code>in</code> is negative value and returns zero output for negative values. */ void arm_vsqrt_f32( float32_t * pIn, float32_t * pOut, uint16_t len); void arm_vsqrt_q31( q31_t * pIn, q31_t * pOut, uint16_t len); void arm_vsqrt_q15( q15_t * pIn, q15_t * pOut, uint16_t len); /** * @} end of SQRT group */ /** * @brief floating-point Circular write function. */ __STATIC_FORCEINLINE void arm_circularWrite_f32( int32_t * circBuffer, int32_t L, uint16_t * writeOffset, int32_t bufferInc, const int32_t * src, int32_t srcInc, uint32_t blockSize) { uint32_t i = 0U; int32_t wOffset; /* Copy the value of Index pointer that points * to the current location where the input samples to be copied */ wOffset = *writeOffset; /* Loop over the blockSize */ i = blockSize; while (i > 0U) { /* copy the input sample to the circular buffer */ circBuffer[wOffset] = *src; /* Update the input pointer */ src += srcInc; /* Circularly update wOffset. Watch out for positive and negative value */ wOffset += bufferInc; if (wOffset >= L) wOffset -= L; /* Decrement the loop counter */ i--; } /* Update the index pointer */ *writeOffset = (uint16_t)wOffset; } /** * @brief floating-point Circular Read function. */ __STATIC_FORCEINLINE void arm_circularRead_f32( int32_t * circBuffer, int32_t L, int32_t * readOffset, int32_t bufferInc, int32_t * dst, int32_t * dst_base, int32_t dst_length, int32_t dstInc, uint32_t blockSize) { uint32_t i = 0U; int32_t rOffset; int32_t* dst_end; /* Copy the value of Index pointer that points * to the current location from where the input samples to be read */ rOffset = *readOffset; dst_end = dst_base + dst_length; /* Loop over the blockSize */ i = blockSize; while (i > 0U) { /* copy the sample from the circular buffer to the destination buffer */ *dst = circBuffer[rOffset]; /* Update the input pointer */ dst += dstInc; if (dst == dst_end) { dst = dst_base; } /* Circularly update rOffset. Watch out for positive and negative value */ rOffset += bufferInc; if (rOffset >= L) { rOffset -= L; } /* Decrement the loop counter */ i--; } /* Update the index pointer */ *readOffset = rOffset; } /** * @brief Q15 Circular write function. */ __STATIC_FORCEINLINE void arm_circularWrite_q15( q15_t * circBuffer, int32_t L, uint16_t * writeOffset, int32_t bufferInc, const q15_t * src, int32_t srcInc, uint32_t blockSize) { uint32_t i = 0U; int32_t wOffset; /* Copy the value of Index pointer that points * to the current location where the input samples to be copied */ wOffset = *writeOffset; /* Loop over the blockSize */ i = blockSize; while (i > 0U) { /* copy the input sample to the circular buffer */ circBuffer[wOffset] = *src; /* Update the input pointer */ src += srcInc; /* Circularly update wOffset. Watch out for positive and negative value */ wOffset += bufferInc; if (wOffset >= L) wOffset -= L; /* Decrement the loop counter */ i--; } /* Update the index pointer */ *writeOffset = (uint16_t)wOffset; } /** * @brief Q15 Circular Read function. */ __STATIC_FORCEINLINE void arm_circularRead_q15( q15_t * circBuffer, int32_t L, int32_t * readOffset, int32_t bufferInc, q15_t * dst, q15_t * dst_base, int32_t dst_length, int32_t dstInc, uint32_t blockSize) { uint32_t i = 0; int32_t rOffset; q15_t* dst_end; /* Copy the value of Index pointer that points * to the current location from where the input samples to be read */ rOffset = *readOffset; dst_end = dst_base + dst_length; /* Loop over the blockSize */ i = blockSize; while (i > 0U) { /* copy the sample from the circular buffer to the destination buffer */ *dst = circBuffer[rOffset]; /* Update the input pointer */ dst += dstInc; if (dst == dst_end) { dst = dst_base; } /* Circularly update wOffset. Watch out for positive and negative value */ rOffset += bufferInc; if (rOffset >= L) { rOffset -= L; } /* Decrement the loop counter */ i--; } /* Update the index pointer */ *readOffset = rOffset; } /** * @brief Q7 Circular write function. */ __STATIC_FORCEINLINE void arm_circularWrite_q7( q7_t * circBuffer, int32_t L, uint16_t * writeOffset, int32_t bufferInc, const q7_t * src, int32_t srcInc, uint32_t blockSize) { uint32_t i = 0U; int32_t wOffset; /* Copy the value of Index pointer that points * to the current location where the input samples to be copied */ wOffset = *writeOffset; /* Loop over the blockSize */ i = blockSize; while (i > 0U) { /* copy the input sample to the circular buffer */ circBuffer[wOffset] = *src; /* Update the input pointer */ src += srcInc; /* Circularly update wOffset. Watch out for positive and negative value */ wOffset += bufferInc; if (wOffset >= L) wOffset -= L; /* Decrement the loop counter */ i--; } /* Update the index pointer */ *writeOffset = (uint16_t)wOffset; } /** * @brief Q7 Circular Read function. */ __STATIC_FORCEINLINE void arm_circularRead_q7( q7_t * circBuffer, int32_t L, int32_t * readOffset, int32_t bufferInc, q7_t * dst, q7_t * dst_base, int32_t dst_length, int32_t dstInc, uint32_t blockSize) { uint32_t i = 0; int32_t rOffset; q7_t* dst_end; /* Copy the value of Index pointer that points * to the current location from where the input samples to be read */ rOffset = *readOffset; dst_end = dst_base + dst_length; /* Loop over the blockSize */ i = blockSize; while (i > 0U) { /* copy the sample from the circular buffer to the destination buffer */ *dst = circBuffer[rOffset]; /* Update the input pointer */ dst += dstInc; if (dst == dst_end) { dst = dst_base; } /* Circularly update rOffset. Watch out for positive and negative value */ rOffset += bufferInc; if (rOffset >= L) { rOffset -= L; } /* Decrement the loop counter */ i--; } /* Update the index pointer */ *readOffset = rOffset; } /** * @brief Sum of the squares of the elements of a Q31 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_power_q31( const q31_t * pSrc, uint32_t blockSize, q63_t * pResult); /** * @brief Sum of the squares of the elements of a floating-point vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_power_f32( const float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Sum of the squares of the elements of a Q15 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_power_q15( const q15_t * pSrc, uint32_t blockSize, q63_t * pResult); /** * @brief Sum of the squares of the elements of a Q7 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_power_q7( const q7_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Mean value of a Q7 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_mean_q7( const q7_t * pSrc, uint32_t blockSize, q7_t * pResult); /** * @brief Mean value of a Q15 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_mean_q15( const q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /** * @brief Mean value of a Q31 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_mean_q31( const q31_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Mean value of a floating-point vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_mean_f32( const float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Variance of the elements of a floating-point vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_var_f32( const float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Variance of the elements of a Q31 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_var_q31( const q31_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Variance of the elements of a Q15 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_var_q15( const q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /** * @brief Root Mean Square of the elements of a floating-point vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_rms_f32( const float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Root Mean Square of the elements of a Q31 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_rms_q31( const q31_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Root Mean Square of the elements of a Q15 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_rms_q15( const q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /** * @brief Standard deviation of the elements of a floating-point vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_std_f32( const float32_t * pSrc, uint32_t blockSize, float32_t * pResult); /** * @brief Standard deviation of the elements of a Q31 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_std_q31( const q31_t * pSrc, uint32_t blockSize, q31_t * pResult); /** * @brief Standard deviation of the elements of a Q15 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output value. */ void arm_std_q15( const q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /** * @brief Floating-point complex magnitude * @param[in] pSrc points to the complex input vector * @param[out] pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector */ void arm_cmplx_mag_f32( const float32_t * pSrc, float32_t * pDst, uint32_t numSamples); /** * @brief Q31 complex magnitude * @param[in] pSrc points to the complex input vector * @param[out] pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector */ void arm_cmplx_mag_q31( const q31_t * pSrc, q31_t * pDst, uint32_t numSamples); /** * @brief Q15 complex magnitude * @param[in] pSrc points to the complex input vector * @param[out] pDst points to the real output vector * @param[in] numSamples number of complex samples in the input vector */ void arm_cmplx_mag_q15( const q15_t * pSrc, q15_t * pDst, uint32_t numSamples); /** * @brief Q15 complex dot product * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[in] numSamples number of complex samples in each vector * @param[out] realResult real part of the result returned here * @param[out] imagResult imaginary part of the result returned here */ void arm_cmplx_dot_prod_q15( const q15_t * pSrcA, const q15_t * pSrcB, uint32_t numSamples, q31_t * realResult, q31_t * imagResult); /** * @brief Q31 complex dot product * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[in] numSamples number of complex samples in each vector * @param[out] realResult real part of the result returned here * @param[out] imagResult imaginary part of the result returned here */ void arm_cmplx_dot_prod_q31( const q31_t * pSrcA, const q31_t * pSrcB, uint32_t numSamples, q63_t * realResult, q63_t * imagResult); /** * @brief Floating-point complex dot product * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[in] numSamples number of complex samples in each vector * @param[out] realResult real part of the result returned here * @param[out] imagResult imaginary part of the result returned here */ void arm_cmplx_dot_prod_f32( const float32_t * pSrcA, const float32_t * pSrcB, uint32_t numSamples, float32_t * realResult, float32_t * imagResult); /** * @brief Q15 complex-by-real multiplication * @param[in] pSrcCmplx points to the complex input vector * @param[in] pSrcReal points to the real input vector * @param[out] pCmplxDst points to the complex output vector * @param[in] numSamples number of samples in each vector */ void arm_cmplx_mult_real_q15( const q15_t * pSrcCmplx, const q15_t * pSrcReal, q15_t * pCmplxDst, uint32_t numSamples); /** * @brief Q31 complex-by-real multiplication * @param[in] pSrcCmplx points to the complex input vector * @param[in] pSrcReal points to the real input vector * @param[out] pCmplxDst points to the complex output vector * @param[in] numSamples number of samples in each vector */ void arm_cmplx_mult_real_q31( const q31_t * pSrcCmplx, const q31_t * pSrcReal, q31_t * pCmplxDst, uint32_t numSamples); /** * @brief Floating-point complex-by-real multiplication * @param[in] pSrcCmplx points to the complex input vector * @param[in] pSrcReal points to the real input vector * @param[out] pCmplxDst points to the complex output vector * @param[in] numSamples number of samples in each vector */ void arm_cmplx_mult_real_f32( const float32_t * pSrcCmplx, const float32_t * pSrcReal, float32_t * pCmplxDst, uint32_t numSamples); /** * @brief Minimum value of a Q7 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] result is output pointer * @param[in] index is the array index of the minimum value in the input buffer. */ void arm_min_q7( const q7_t * pSrc, uint32_t blockSize, q7_t * result, uint32_t * index); /** * @brief Minimum value of a Q15 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output pointer * @param[in] pIndex is the array index of the minimum value in the input buffer. */ void arm_min_q15( const q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex); /** * @brief Minimum value of a Q31 vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output pointer * @param[out] pIndex is the array index of the minimum value in the input buffer. */ void arm_min_q31( const q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex); /** * @brief Minimum value of a floating-point vector. * @param[in] pSrc is input pointer * @param[in] blockSize is the number of samples to process * @param[out] pResult is output pointer * @param[out] pIndex is the array index of the minimum value in the input buffer. */ void arm_min_f32( const float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a Q7 vector. * @param[in] pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] pResult maximum value returned here * @param[out] pIndex index of maximum value returned here */ void arm_max_q7( const q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a Q15 vector. * @param[in] pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] pResult maximum value returned here * @param[out] pIndex index of maximum value returned here */ void arm_max_q15( const q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a Q31 vector. * @param[in] pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] pResult maximum value returned here * @param[out] pIndex index of maximum value returned here */ void arm_max_q31( const q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex); /** * @brief Maximum value of a floating-point vector. * @param[in] pSrc points to the input buffer * @param[in] blockSize length of the input vector * @param[out] pResult maximum value returned here * @param[out] pIndex index of maximum value returned here */ void arm_max_f32( const float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex); /** * @brief Q15 complex-by-complex multiplication * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] numSamples number of complex samples in each vector */ void arm_cmplx_mult_cmplx_q15( const q15_t * pSrcA, const q15_t * pSrcB, q15_t * pDst, uint32_t numSamples); /** * @brief Q31 complex-by-complex multiplication * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] numSamples number of complex samples in each vector */ void arm_cmplx_mult_cmplx_q31( const q31_t * pSrcA, const q31_t * pSrcB, q31_t * pDst, uint32_t numSamples); /** * @brief Floating-point complex-by-complex multiplication * @param[in] pSrcA points to the first input vector * @param[in] pSrcB points to the second input vector * @param[out] pDst points to the output vector * @param[in] numSamples number of complex samples in each vector */ void arm_cmplx_mult_cmplx_f32( const float32_t * pSrcA, const float32_t * pSrcB, float32_t * pDst, uint32_t numSamples); /** * @brief Converts the elements of the floating-point vector to Q31 vector. * @param[in] pSrc points to the floating-point input vector * @param[out] pDst points to the Q31 output vector * @param[in] blockSize length of the input vector */ void arm_float_to_q31( const float32_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the floating-point vector to Q15 vector. * @param[in] pSrc points to the floating-point input vector * @param[out] pDst points to the Q15 output vector * @param[in] blockSize length of the input vector */ void arm_float_to_q15( const float32_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the floating-point vector to Q7 vector. * @param[in] pSrc points to the floating-point input vector * @param[out] pDst points to the Q7 output vector * @param[in] blockSize length of the input vector */ void arm_float_to_q7( const float32_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q31 vector to floating-point vector. * @param[in] pSrc is input pointer * @param[out] pDst is output pointer * @param[in] blockSize is the number of samples to process */ void arm_q31_to_float( const q31_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q31 vector to Q15 vector. * @param[in] pSrc is input pointer * @param[out] pDst is output pointer * @param[in] blockSize is the number of samples to process */ void arm_q31_to_q15( const q31_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q31 vector to Q7 vector. * @param[in] pSrc is input pointer * @param[out] pDst is output pointer * @param[in] blockSize is the number of samples to process */ void arm_q31_to_q7( const q31_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q15 vector to floating-point vector. * @param[in] pSrc is input pointer * @param[out] pDst is output pointer * @param[in] blockSize is the number of samples to process */ void arm_q15_to_float( const q15_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q15 vector to Q31 vector. * @param[in] pSrc is input pointer * @param[out] pDst is output pointer * @param[in] blockSize is the number of samples to process */ void arm_q15_to_q31( const q15_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q15 vector to Q7 vector. * @param[in] pSrc is input pointer * @param[out] pDst is output pointer * @param[in] blockSize is the number of samples to process */ void arm_q15_to_q7( const q15_t * pSrc, q7_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q7 vector to floating-point vector. * @param[in] pSrc is input pointer * @param[out] pDst is output pointer * @param[in] blockSize is the number of samples to process */ void arm_q7_to_float( const q7_t * pSrc, float32_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q7 vector to Q31 vector. * @param[in] pSrc input pointer * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_q7_to_q31( const q7_t * pSrc, q31_t * pDst, uint32_t blockSize); /** * @brief Converts the elements of the Q7 vector to Q15 vector. * @param[in] pSrc input pointer * @param[out] pDst output pointer * @param[in] blockSize number of samples to process */ void arm_q7_to_q15( const q7_t * pSrc, q15_t * pDst, uint32_t blockSize); /** * @ingroup groupInterpolation */ /** * @defgroup BilinearInterpolate Bilinear Interpolation * * Bilinear interpolation is an extension of linear interpolation applied to a two dimensional grid. * The underlying function <code>f(x, y)</code> is sampled on a regular grid and the interpolation process * determines values between the grid points. * Bilinear interpolation is equivalent to two step linear interpolation, first in the x-dimension and then in the y-dimension. * Bilinear interpolation is often used in image processing to rescale images. * The CMSIS DSP library provides bilinear interpolation functions for Q7, Q15, Q31, and floating-point data types. * * <b>Algorithm</b> * \par * The instance structure used by the bilinear interpolation functions describes a two dimensional data table. * For floating-point, the instance structure is defined as: * <pre> * typedef struct * { * uint16_t numRows; * uint16_t numCols; * float32_t *pData; * } arm_bilinear_interp_instance_f32; * </pre> * * \par * where <code>numRows</code> specifies the number of rows in the table; * <code>numCols</code> specifies the number of columns in the table; * and <code>pData</code> points to an array of size <code>numRows*numCols</code> values. * The data table <code>pTable</code> is organized in row order and the supplied data values fall on integer indexes. * That is, table element (x,y) is located at <code>pTable[x + y*numCols]</code> where x and y are integers. * * \par * Let <code>(x, y)</code> specify the desired interpolation point. Then define: * <pre> * XF = floor(x) * YF = floor(y) * </pre> * \par * The interpolated output point is computed as: * <pre> * f(x, y) = f(XF, YF) * (1-(x-XF)) * (1-(y-YF)) * + f(XF+1, YF) * (x-XF)*(1-(y-YF)) * + f(XF, YF+1) * (1-(x-XF))*(y-YF) * + f(XF+1, YF+1) * (x-XF)*(y-YF) * </pre> * Note that the coordinates (x, y) contain integer and fractional components. * The integer components specify which portion of the table to use while the * fractional components control the interpolation processor. * * \par * if (x,y) are outside of the table boundary, Bilinear interpolation returns zero output. */ /** * @addtogroup BilinearInterpolate * @{ */ /** * @brief Floating-point bilinear interpolation. * @param[in,out] S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate. * @param[in] Y interpolation coordinate. * @return out interpolated value. */ __STATIC_FORCEINLINE float32_t arm_bilinear_interp_f32( const arm_bilinear_interp_instance_f32 * S, float32_t X, float32_t Y) { float32_t out; float32_t f00, f01, f10, f11; float32_t *pData = S->pData; int32_t xIndex, yIndex, index; float32_t xdiff, ydiff; float32_t b1, b2, b3, b4; xIndex = (int32_t) X; yIndex = (int32_t) Y; /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if (xIndex < 0 || xIndex > (S->numRows - 1) || yIndex < 0 || yIndex > (S->numCols - 1)) { return (0); } /* Calculation of index for two nearest points in X-direction */ index = (xIndex - 1) + (yIndex - 1) * S->numCols; /* Read two nearest points in X-direction */ f00 = pData[index]; f01 = pData[index + 1]; /* Calculation of index for two nearest points in Y-direction */ index = (xIndex - 1) + (yIndex) * S->numCols; /* Read two nearest points in Y-direction */ f10 = pData[index]; f11 = pData[index + 1]; /* Calculation of intermediate values */ b1 = f00; b2 = f01 - f00; b3 = f10 - f00; b4 = f00 - f01 - f10 + f11; /* Calculation of fractional part in X */ xdiff = X - xIndex; /* Calculation of fractional part in Y */ ydiff = Y - yIndex; /* Calculation of bi-linear interpolated output */ out = b1 + b2 * xdiff + b3 * ydiff + b4 * xdiff * ydiff; /* return to application */ return (out); } /** * @brief Q31 bilinear interpolation. * @param[in,out] S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate in 12.20 format. * @param[in] Y interpolation coordinate in 12.20 format. * @return out interpolated value. */ __STATIC_FORCEINLINE q31_t arm_bilinear_interp_q31( arm_bilinear_interp_instance_q31 * S, q31_t X, q31_t Y) { q31_t out; /* Temporary output */ q31_t acc = 0; /* output */ q31_t xfract, yfract; /* X, Y fractional parts */ q31_t x1, x2, y1, y2; /* Nearest output values */ int32_t rI, cI; /* Row and column indices */ q31_t *pYData = S->pData; /* pointer to output table values */ uint32_t nCols = S->numCols; /* num of rows */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ rI = ((X & (q31_t)0xFFF00000) >> 20); /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ cI = ((Y & (q31_t)0xFFF00000) >> 20); /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if (rI < 0 || rI > (S->numRows - 1) || cI < 0 || cI > (S->numCols - 1)) { return (0); } /* 20 bits for the fractional part */ /* shift left xfract by 11 to keep 1.31 format */ xfract = (X & 0x000FFFFF) << 11U; /* Read two nearest output values from the index */ x1 = pYData[(rI) + (int32_t)nCols * (cI) ]; x2 = pYData[(rI) + (int32_t)nCols * (cI) + 1]; /* 20 bits for the fractional part */ /* shift left yfract by 11 to keep 1.31 format */ yfract = (Y & 0x000FFFFF) << 11U; /* Read two nearest output values from the index */ y1 = pYData[(rI) + (int32_t)nCols * (cI + 1) ]; y2 = pYData[(rI) + (int32_t)nCols * (cI + 1) + 1]; /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 3.29(q29) format */ out = ((q31_t) (((q63_t) x1 * (0x7FFFFFFF - xfract)) >> 32)); acc = ((q31_t) (((q63_t) out * (0x7FFFFFFF - yfract)) >> 32)); /* x2 * (xfract) * (1-yfract) in 3.29(q29) and adding to acc */ out = ((q31_t) ((q63_t) x2 * (0x7FFFFFFF - yfract) >> 32)); acc += ((q31_t) ((q63_t) out * (xfract) >> 32)); /* y1 * (1 - xfract) * (yfract) in 3.29(q29) and adding to acc */ out = ((q31_t) ((q63_t) y1 * (0x7FFFFFFF - xfract) >> 32)); acc += ((q31_t) ((q63_t) out * (yfract) >> 32)); /* y2 * (xfract) * (yfract) in 3.29(q29) and adding to acc */ out = ((q31_t) ((q63_t) y2 * (xfract) >> 32)); acc += ((q31_t) ((q63_t) out * (yfract) >> 32)); /* Convert acc to 1.31(q31) format */ return ((q31_t)(acc << 2)); } /** * @brief Q15 bilinear interpolation. * @param[in,out] S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate in 12.20 format. * @param[in] Y interpolation coordinate in 12.20 format. * @return out interpolated value. */ __STATIC_FORCEINLINE q15_t arm_bilinear_interp_q15( arm_bilinear_interp_instance_q15 * S, q31_t X, q31_t Y) { q63_t acc = 0; /* output */ q31_t out; /* Temporary output */ q15_t x1, x2, y1, y2; /* Nearest output values */ q31_t xfract, yfract; /* X, Y fractional parts */ int32_t rI, cI; /* Row and column indices */ q15_t *pYData = S->pData; /* pointer to output table values */ uint32_t nCols = S->numCols; /* num of rows */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ rI = ((X & (q31_t)0xFFF00000) >> 20); /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ cI = ((Y & (q31_t)0xFFF00000) >> 20); /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if (rI < 0 || rI > (S->numRows - 1) || cI < 0 || cI > (S->numCols - 1)) { return (0); } /* 20 bits for the fractional part */ /* xfract should be in 12.20 format */ xfract = (X & 0x000FFFFF); /* Read two nearest output values from the index */ x1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) ]; x2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) + 1]; /* 20 bits for the fractional part */ /* yfract should be in 12.20 format */ yfract = (Y & 0x000FFFFF); /* Read two nearest output values from the index */ y1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) ]; y2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) + 1]; /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 13.51 format */ /* x1 is in 1.15(q15), xfract in 12.20 format and out is in 13.35 format */ /* convert 13.35 to 13.31 by right shifting and out is in 1.31 */ out = (q31_t) (((q63_t) x1 * (0xFFFFF - xfract)) >> 4U); acc = ((q63_t) out * (0xFFFFF - yfract)); /* x2 * (xfract) * (1-yfract) in 1.51 and adding to acc */ out = (q31_t) (((q63_t) x2 * (0xFFFFF - yfract)) >> 4U); acc += ((q63_t) out * (xfract)); /* y1 * (1 - xfract) * (yfract) in 1.51 and adding to acc */ out = (q31_t) (((q63_t) y1 * (0xFFFFF - xfract)) >> 4U); acc += ((q63_t) out * (yfract)); /* y2 * (xfract) * (yfract) in 1.51 and adding to acc */ out = (q31_t) (((q63_t) y2 * (xfract)) >> 4U); acc += ((q63_t) out * (yfract)); /* acc is in 13.51 format and down shift acc by 36 times */ /* Convert out to 1.15 format */ return ((q15_t)(acc >> 36)); } /** * @brief Q7 bilinear interpolation. * @param[in,out] S points to an instance of the interpolation structure. * @param[in] X interpolation coordinate in 12.20 format. * @param[in] Y interpolation coordinate in 12.20 format. * @return out interpolated value. */ __STATIC_FORCEINLINE q7_t arm_bilinear_interp_q7( arm_bilinear_interp_instance_q7 * S, q31_t X, q31_t Y) { q63_t acc = 0; /* output */ q31_t out; /* Temporary output */ q31_t xfract, yfract; /* X, Y fractional parts */ q7_t x1, x2, y1, y2; /* Nearest output values */ int32_t rI, cI; /* Row and column indices */ q7_t *pYData = S->pData; /* pointer to output table values */ uint32_t nCols = S->numCols; /* num of rows */ /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ rI = ((X & (q31_t)0xFFF00000) >> 20); /* Input is in 12.20 format */ /* 12 bits for the table index */ /* Index value calculation */ cI = ((Y & (q31_t)0xFFF00000) >> 20); /* Care taken for table outside boundary */ /* Returns zero output when values are outside table boundary */ if (rI < 0 || rI > (S->numRows - 1) || cI < 0 || cI > (S->numCols - 1)) { return (0); } /* 20 bits for the fractional part */ /* xfract should be in 12.20 format */ xfract = (X & (q31_t)0x000FFFFF); /* Read two nearest output values from the index */ x1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) ]; x2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI) + 1]; /* 20 bits for the fractional part */ /* yfract should be in 12.20 format */ yfract = (Y & (q31_t)0x000FFFFF); /* Read two nearest output values from the index */ y1 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) ]; y2 = pYData[((uint32_t)rI) + nCols * ((uint32_t)cI + 1) + 1]; /* Calculation of x1 * (1-xfract ) * (1-yfract) and acc is in 16.47 format */ out = ((x1 * (0xFFFFF - xfract))); acc = (((q63_t) out * (0xFFFFF - yfract))); /* x2 * (xfract) * (1-yfract) in 2.22 and adding to acc */ out = ((x2 * (0xFFFFF - yfract))); acc += (((q63_t) out * (xfract))); /* y1 * (1 - xfract) * (yfract) in 2.22 and adding to acc */ out = ((y1 * (0xFFFFF - xfract))); acc += (((q63_t) out * (yfract))); /* y2 * (xfract) * (yfract) in 2.22 and adding to acc */ out = ((y2 * (yfract))); acc += (((q63_t) out * (xfract))); /* acc in 16.47 format and down shift by 40 to convert to 1.7 format */ return ((q7_t)(acc >> 40)); } /** * @} end of BilinearInterpolate group */ /* SMMLAR */ #define multAcc_32x32_keep32_R(a, x, y) \ a = (q31_t) (((((q63_t) a) << 32) + ((q63_t) x * y) + 0x80000000LL ) >> 32) /* SMMLSR */ #define multSub_32x32_keep32_R(a, x, y) \ a = (q31_t) (((((q63_t) a) << 32) - ((q63_t) x * y) + 0x80000000LL ) >> 32) /* SMMULR */ #define mult_32x32_keep32_R(a, x, y) \ a = (q31_t) (((q63_t) x * y + 0x80000000LL ) >> 32) /* SMMLA */ #define multAcc_32x32_keep32(a, x, y) \ a += (q31_t) (((q63_t) x * y) >> 32) /* SMMLS */ #define multSub_32x32_keep32(a, x, y) \ a -= (q31_t) (((q63_t) x * y) >> 32) /* SMMUL */ #define mult_32x32_keep32(a, x, y) \ a = (q31_t) (((q63_t) x * y ) >> 32) #if defined ( __CC_ARM ) /* Enter low optimization region - place directly above function definition */ #if defined( __ARM_ARCH_7EM__ ) #define LOW_OPTIMIZATION_ENTER \ _Pragma ("push") \ _Pragma ("O1") #else #define LOW_OPTIMIZATION_ENTER #endif /* Exit low optimization region - place directly after end of function definition */ #if defined ( __ARM_ARCH_7EM__ ) #define LOW_OPTIMIZATION_EXIT \ _Pragma ("pop") #else #define LOW_OPTIMIZATION_EXIT #endif /* Enter low optimization region - place directly above function definition */ #define IAR_ONLY_LOW_OPTIMIZATION_ENTER /* Exit low optimization region - place directly after end of function definition */ #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined (__ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 ) #define LOW_OPTIMIZATION_ENTER #define LOW_OPTIMIZATION_EXIT #define IAR_ONLY_LOW_OPTIMIZATION_ENTER #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __GNUC__ ) #define LOW_OPTIMIZATION_ENTER \ __attribute__(( optimize("-O1") )) #define LOW_OPTIMIZATION_EXIT #define IAR_ONLY_LOW_OPTIMIZATION_ENTER #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __ICCARM__ ) /* Enter low optimization region - place directly above function definition */ #if defined ( __ARM_ARCH_7EM__ ) #define LOW_OPTIMIZATION_ENTER \ _Pragma ("optimize=low") #else #define LOW_OPTIMIZATION_ENTER #endif /* Exit low optimization region - place directly after end of function definition */ #define LOW_OPTIMIZATION_EXIT /* Enter low optimization region - place directly above function definition */ #if defined ( __ARM_ARCH_7EM__ ) #define IAR_ONLY_LOW_OPTIMIZATION_ENTER \ _Pragma ("optimize=low") #else #define IAR_ONLY_LOW_OPTIMIZATION_ENTER #endif /* Exit low optimization region - place directly after end of function definition */ #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __TI_ARM__ ) #define LOW_OPTIMIZATION_ENTER #define LOW_OPTIMIZATION_EXIT #define IAR_ONLY_LOW_OPTIMIZATION_ENTER #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __CSMC__ ) #define LOW_OPTIMIZATION_ENTER #define LOW_OPTIMIZATION_EXIT #define IAR_ONLY_LOW_OPTIMIZATION_ENTER #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #elif defined ( __TASKING__ ) #define LOW_OPTIMIZATION_ENTER #define LOW_OPTIMIZATION_EXIT #define IAR_ONLY_LOW_OPTIMIZATION_ENTER #define IAR_ONLY_LOW_OPTIMIZATION_EXIT #endif #ifdef __cplusplus } #endif /* Compiler specific diagnostic adjustment */ #if defined ( __CC_ARM ) #elif defined ( __ARMCC_VERSION ) && ( __ARMCC_VERSION >= 6010050 ) #elif defined ( __GNUC__ ) #pragma GCC diagnostic pop #elif defined ( __ICCARM__ ) #elif defined ( __TI_ARM__ ) #elif defined ( __CSMC__ ) #elif defined ( __TASKING__ ) #elif defined ( _MSC_VER ) #else #error Unknown compiler #endif #endif /* _ARM_MATH_H */ /** * * End of file. */
257,001
C
33.909264
185
0.611161
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Include/arm_common_tables.h
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_common_tables.h * Description: Extern declaration for common tables * * $Date: 27. January 2017 * $Revision: V.1.5.1 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _ARM_COMMON_TABLES_H #define _ARM_COMMON_TABLES_H #include "arm_math.h" #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_ALLOW_TABLES) #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREV_1024) extern const uint16_t armBitRevTable[1024]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_16) extern const float32_t twiddleCoef_16[32]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_32) extern const float32_t twiddleCoef_32[64]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_64) extern const float32_t twiddleCoef_64[128]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_128) extern const float32_t twiddleCoef_128[256]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_256) extern const float32_t twiddleCoef_256[512]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_512) extern const float32_t twiddleCoef_512[1024]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_1024) extern const float32_t twiddleCoef_1024[2048]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_2048) extern const float32_t twiddleCoef_2048[4096]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_F32_4096) extern const float32_t twiddleCoef_4096[8192]; #define twiddleCoef twiddleCoef_4096 #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_16) extern const q31_t twiddleCoef_16_q31[24]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_32) extern const q31_t twiddleCoef_32_q31[48]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_64) extern const q31_t twiddleCoef_64_q31[96]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_128) extern const q31_t twiddleCoef_128_q31[192]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_256) extern const q31_t twiddleCoef_256_q31[384]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_512) extern const q31_t twiddleCoef_512_q31[768]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_1024) extern const q31_t twiddleCoef_1024_q31[1536]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_2048) extern const q31_t twiddleCoef_2048_q31[3072]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q31_4096) extern const q31_t twiddleCoef_4096_q31[6144]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_16) extern const q15_t twiddleCoef_16_q15[24]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_32) extern const q15_t twiddleCoef_32_q15[48]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_64) extern const q15_t twiddleCoef_64_q15[96]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_128) extern const q15_t twiddleCoef_128_q15[192]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_256) extern const q15_t twiddleCoef_256_q15[384]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_512) extern const q15_t twiddleCoef_512_q15[768]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_1024) extern const q15_t twiddleCoef_1024_q15[1536]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_2048) extern const q15_t twiddleCoef_2048_q15[3072]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_Q15_4096) extern const q15_t twiddleCoef_4096_q15[6144]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_32) extern const float32_t twiddleCoef_rfft_32[32]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_64) extern const float32_t twiddleCoef_rfft_64[64]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_128) extern const float32_t twiddleCoef_rfft_128[128]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_256) extern const float32_t twiddleCoef_rfft_256[256]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_512) extern const float32_t twiddleCoef_rfft_512[512]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_1024) extern const float32_t twiddleCoef_rfft_1024[1024]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_2048) extern const float32_t twiddleCoef_rfft_2048[2048]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_TWIDDLECOEF_RFFT_F32_4096) extern const float32_t twiddleCoef_rfft_4096[4096]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ /* floating-point bit reversal tables */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_16) #define ARMBITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20) extern const uint16_t armBitRevIndexTable16[ARMBITREVINDEXTABLE_16_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_32) #define ARMBITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48) extern const uint16_t armBitRevIndexTable32[ARMBITREVINDEXTABLE_32_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_64) #define ARMBITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56) extern const uint16_t armBitRevIndexTable64[ARMBITREVINDEXTABLE_64_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_128) #define ARMBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208) extern const uint16_t armBitRevIndexTable128[ARMBITREVINDEXTABLE_128_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_256) #define ARMBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440) extern const uint16_t armBitRevIndexTable256[ARMBITREVINDEXTABLE_256_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_512) #define ARMBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448) extern const uint16_t armBitRevIndexTable512[ARMBITREVINDEXTABLE_512_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_1024) #define ARMBITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800) extern const uint16_t armBitRevIndexTable1024[ARMBITREVINDEXTABLE_1024_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_2048) #define ARMBITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808) extern const uint16_t armBitRevIndexTable2048[ARMBITREVINDEXTABLE_2048_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FLT_4096) #define ARMBITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032) extern const uint16_t armBitRevIndexTable4096[ARMBITREVINDEXTABLE_4096_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ /* fixed-point bit reversal tables */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_16) #define ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12) extern const uint16_t armBitRevIndexTable_fixed_16[ARMBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_32) #define ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24) extern const uint16_t armBitRevIndexTable_fixed_32[ARMBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_64) #define ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56) extern const uint16_t armBitRevIndexTable_fixed_64[ARMBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_128) #define ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112) extern const uint16_t armBitRevIndexTable_fixed_128[ARMBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_256) #define ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240) extern const uint16_t armBitRevIndexTable_fixed_256[ARMBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_512) #define ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480) extern const uint16_t armBitRevIndexTable_fixed_512[ARMBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_1024) #define ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992) extern const uint16_t armBitRevIndexTable_fixed_1024[ARMBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_2048) #define ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984) extern const uint16_t armBitRevIndexTable_fixed_2048[ARMBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_BITREVIDX_FXT_4096) #define ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032) extern const uint16_t armBitRevIndexTable_fixed_4096[ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_F32) extern const float32_t realCoefA[8192]; extern const float32_t realCoefB[8192]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q31) extern const q31_t realCoefAQ31[8192]; extern const q31_t realCoefBQ31[8192]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_REALCOEF_Q15) extern const q15_t realCoefAQ15[8192]; extern const q15_t realCoefBQ15[8192]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_128) extern const float32_t Weights_128[256]; extern const float32_t cos_factors_128[128]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_512) extern const float32_t Weights_512[1024]; extern const float32_t cos_factors_512[512]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_2048) extern const float32_t Weights_2048[4096]; extern const float32_t cos_factors_2048[2048]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_F32_8192) extern const float32_t Weights_8192[16384]; extern const float32_t cos_factors_8192[8192]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_128) extern const q15_t WeightsQ15_128[256]; extern const q15_t cos_factorsQ15_128[128]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_512) extern const q15_t WeightsQ15_512[1024]; extern const q15_t cos_factorsQ15_512[512]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_2048) extern const q15_t WeightsQ15_2048[4096]; extern const q15_t cos_factorsQ15_2048[2048]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q15_8192) extern const q15_t WeightsQ15_8192[16384]; extern const q15_t cos_factorsQ15_8192[8192]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_128) extern const q31_t WeightsQ31_128[256]; extern const q31_t cos_factorsQ31_128[128]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_512) extern const q31_t WeightsQ31_512[1024]; extern const q31_t cos_factorsQ31_512[512]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_2048) extern const q31_t WeightsQ31_2048[4096]; extern const q31_t cos_factorsQ31_2048[2048]; #endif #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FFT_TABLES) || defined(ARM_TABLE_DCT4_Q31_8192) extern const q31_t WeightsQ31_8192[16384]; extern const q31_t cos_factorsQ31_8192[8192]; #endif #endif /* if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FFT_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FAST_ALLOW_TABLES) #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q15) extern const q15_t armRecipTableQ15[64]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_RECIP_Q31) extern const q31_t armRecipTableQ31[64]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ /* Tables for Fast Math Sine and Cosine */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_F32) extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q31) extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ #if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_ALL_FAST_TABLES) || defined(ARM_TABLE_SIN_Q15) extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1]; #endif /* !defined(ARM_DSP_CONFIG_TABLES) defined(ARM_ALL_FAST_TABLES) */ #endif /* if !defined(ARM_DSP_CONFIG_TABLES) || defined(ARM_FAST_TABLES) */ #endif /* ARM_COMMON_TABLES_H */
21,036
C
54.506596
116
0.707834
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Include/arm_const_structs.h
/* ---------------------------------------------------------------------- * Project: CMSIS DSP Library * Title: arm_const_structs.h * Description: Constant structs that are initialized for user convenience. * For example, some can be given as arguments to the arm_cfft_f32() function. * * $Date: 27. January 2017 * $Revision: V.1.5.1 * * Target Processor: Cortex-M cores * -------------------------------------------------------------------- */ /* * Copyright (C) 2010-2017 ARM Limited or its affiliates. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _ARM_CONST_STRUCTS_H #define _ARM_CONST_STRUCTS_H #include "arm_math.h" #include "arm_common_tables.h" extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len16; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len32; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len64; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len128; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len256; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len512; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len1024; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len2048; extern const arm_cfft_instance_f32 arm_cfft_sR_f32_len4096; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len16; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len32; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len64; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len128; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len256; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len512; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len1024; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len2048; extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len16; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len32; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len64; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len128; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len256; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len512; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len1024; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len2048; extern const arm_cfft_instance_q15 arm_cfft_sR_q15_len4096; #endif
2,961
C
43.208955
92
0.701114
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Src/system_stm32g4xx.c
/** ****************************************************************************** * @file system_stm32g4xx.c * @author MCD Application Team * @brief CMSIS Cortex-M4 Device Peripheral Access Layer System Source File * * This file provides two functions and one global variable to be called from * user application: * - SystemInit(): This function is called at startup just after reset and * before branch to main program. This call is made inside * the "startup_stm32g4xx.s" file. * * - SystemCoreClock variable: Contains the core clock (HCLK), it can be used * by the user application to setup the SysTick * timer or configure other parameters. * * - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must * be called whenever the core clock is changed * during program execution. * * After each device reset the HSI (16 MHz) is used as system clock source. * Then SystemInit() function is called, in "startup_stm32g4xx.s" file, to * configure the system clock before to branch to main program. * * This file configures the system clock as follows: *============================================================================= *----------------------------------------------------------------------------- * System Clock source | HSI *----------------------------------------------------------------------------- * SYSCLK(Hz) | 16000000 *----------------------------------------------------------------------------- * HCLK(Hz) | 16000000 *----------------------------------------------------------------------------- * AHB Prescaler | 1 *----------------------------------------------------------------------------- * APB1 Prescaler | 1 *----------------------------------------------------------------------------- * APB2 Prescaler | 1 *----------------------------------------------------------------------------- * PLL_M | 1 *----------------------------------------------------------------------------- * PLL_N | 16 *----------------------------------------------------------------------------- * PLL_P | 7 *----------------------------------------------------------------------------- * PLL_Q | 2 *----------------------------------------------------------------------------- * PLL_R | 2 *----------------------------------------------------------------------------- * Require 48MHz for RNG | Disabled *----------------------------------------------------------------------------- *============================================================================= ****************************************************************************** * @attention * * Copyright (c) 2019 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /** @addtogroup CMSIS * @{ */ /** @addtogroup stm32g4xx_system * @{ */ /** @addtogroup STM32G4xx_System_Private_Includes * @{ */ #include "stm32g4xx.h" #if !defined (HSE_VALUE) #define HSE_VALUE 24000000U /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined (HSI_VALUE) #define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** * @} */ /** @addtogroup STM32G4xx_System_Private_TypesDefinitions * @{ */ /** * @} */ /** @addtogroup STM32G4xx_System_Private_Defines * @{ */ /************************* Miscellaneous Configuration ************************/ /* Note: Following vector table addresses must be defined in line with linker configuration. */ /*!< Uncomment the following line if you need to relocate the vector table anywhere in Flash or Sram, else the vector table is kept at the automatic remap of boot address selected */ /* #define USER_VECT_TAB_ADDRESS */ #if defined(USER_VECT_TAB_ADDRESS) /*!< Uncomment the following line if you need to relocate your vector Table in Sram else user remap will be done in Flash. */ /* #define VECT_TAB_SRAM */ #if defined(VECT_TAB_SRAM) #define VECT_TAB_BASE_ADDRESS SRAM_BASE /*!< Vector Table base address field. This value must be a multiple of 0x200. */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ #else #define VECT_TAB_BASE_ADDRESS FLASH_BASE /*!< Vector Table base address field. This value must be a multiple of 0x200. */ #define VECT_TAB_OFFSET 0x00000000U /*!< Vector Table base offset field. This value must be a multiple of 0x200. */ #endif /* VECT_TAB_SRAM */ #endif /* USER_VECT_TAB_ADDRESS */ /******************************************************************************/ /** * @} */ /** @addtogroup STM32G4xx_System_Private_Macros * @{ */ /** * @} */ /** @addtogroup STM32G4xx_System_Private_Variables * @{ */ /* The SystemCoreClock variable is updated in three ways: 1) by calling CMSIS function SystemCoreClockUpdate() 2) by calling HAL API function HAL_RCC_GetHCLKFreq() 3) each time HAL_RCC_ClockConfig() is called to configure the system clock frequency Note: If you use this function to configure the system clock; then there is no need to call the 2 first functions listed above, since SystemCoreClock variable is updated automatically. */ uint32_t SystemCoreClock = HSI_VALUE; const uint8_t AHBPrescTable[16] = {0U, 0U, 0U, 0U, 0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U, 6U, 7U, 8U, 9U}; const uint8_t APBPrescTable[8] = {0U, 0U, 0U, 0U, 1U, 2U, 3U, 4U}; /** * @} */ /** @addtogroup STM32G4xx_System_Private_FunctionPrototypes * @{ */ /** * @} */ /** @addtogroup STM32G4xx_System_Private_Functions * @{ */ /** * @brief Setup the microcontroller system. * @param None * @retval None */ void SystemInit(void) { /* FPU settings ------------------------------------------------------------*/ #if (__FPU_PRESENT == 1) && (__FPU_USED == 1) SCB->CPACR |= ((3UL << (10*2))|(3UL << (11*2))); /* set CP10 and CP11 Full Access */ #endif /* Configure the Vector Table location add offset address ------------------*/ #if defined(USER_VECT_TAB_ADDRESS) SCB->VTOR = VECT_TAB_BASE_ADDRESS | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */ #endif /* USER_VECT_TAB_ADDRESS */ } /** * @brief Update SystemCoreClock variable according to Clock Register Values. * The SystemCoreClock variable contains the core clock (HCLK), it can * be used by the user application to setup the SysTick timer or configure * other parameters. * * @note Each time the core clock (HCLK) changes, this function must be called * to update SystemCoreClock variable value. Otherwise, any configuration * based on this variable will be incorrect. * * @note - The system frequency computed by this function is not the real * frequency in the chip. It is calculated based on the predefined * constant and the selected clock source: * * - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(**) * * - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(***) * * - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(***) * or HSI_VALUE(*) multiplied/divided by the PLL factors. * * (**) HSI_VALUE is a constant defined in stm32g4xx_hal.h file (default value * 16 MHz) but the real value may vary depending on the variations * in voltage and temperature. * * (***) HSE_VALUE is a constant defined in stm32g4xx_hal.h file (default value * 24 MHz), user has to ensure that HSE_VALUE is same as the real * frequency of the crystal used. Otherwise, this function may * have wrong result. * * - The result of this function could be not correct when using fractional * value for HSE crystal. * * @param None * @retval None */ void SystemCoreClockUpdate(void) { uint32_t tmp, pllvco, pllr, pllsource, pllm; /* Get SYSCLK source -------------------------------------------------------*/ switch (RCC->CFGR & RCC_CFGR_SWS) { case 0x04: /* HSI used as system clock source */ SystemCoreClock = HSI_VALUE; break; case 0x08: /* HSE used as system clock source */ SystemCoreClock = HSE_VALUE; break; case 0x0C: /* PLL used as system clock source */ /* PLL_VCO = (HSE_VALUE or HSI_VALUE / PLLM) * PLLN SYSCLK = PLL_VCO / PLLR */ pllsource = (RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC); pllm = ((RCC->PLLCFGR & RCC_PLLCFGR_PLLM) >> 4) + 1U ; if (pllsource == 0x02UL) /* HSI used as PLL clock source */ { pllvco = (HSI_VALUE / pllm); } else /* HSE used as PLL clock source */ { pllvco = (HSE_VALUE / pllm); } pllvco = pllvco * ((RCC->PLLCFGR & RCC_PLLCFGR_PLLN) >> 8); pllr = (((RCC->PLLCFGR & RCC_PLLCFGR_PLLR) >> 25) + 1U) * 2U; SystemCoreClock = pllvco/pllr; break; default: break; } /* Compute HCLK clock frequency --------------------------------------------*/ /* Get HCLK prescaler */ tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)]; /* HCLK clock frequency */ SystemCoreClock >>= tmp; } /** * @} */ /** * @} */ /** * @} */
10,571
C
35.965035
101
0.4781
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Src/stm32g4xx_hal_msp.c
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32g4xx_hal_msp.c * @brief This file provides code for the MSP Initialization * and de-Initialization codes. ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN Define */ /* USER CODE END Define */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN Macro */ /* USER CODE END Macro */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* External functions --------------------------------------------------------*/ /* USER CODE BEGIN ExternalFunctions */ /* USER CODE END ExternalFunctions */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * Initializes the Global MSP. */ void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ /* USER CODE END MspInit 0 */ __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); /* System interrupt init*/ /** Disable the internal Pull-Up in Dead Battery pins of UCPD peripheral */ HAL_PWREx_DisableUCPDDeadBattery(); /* USER CODE BEGIN MspInit 1 */ /* USER CODE END MspInit 1 */ } /** * @brief CRC MSP Initialization * This function configures the hardware resources used in this example * @param hcrc: CRC handle pointer * @retval None */ void HAL_CRC_MspInit(CRC_HandleTypeDef* hcrc) { if(hcrc->Instance==CRC) { /* USER CODE BEGIN CRC_MspInit 0 */ /* USER CODE END CRC_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_CRC_CLK_ENABLE(); /* USER CODE BEGIN CRC_MspInit 1 */ /* USER CODE END CRC_MspInit 1 */ } } /** * @brief CRC MSP De-Initialization * This function freeze the hardware resources used in this example * @param hcrc: CRC handle pointer * @retval None */ void HAL_CRC_MspDeInit(CRC_HandleTypeDef* hcrc) { if(hcrc->Instance==CRC) { /* USER CODE BEGIN CRC_MspDeInit 0 */ /* USER CODE END CRC_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_CRC_CLK_DISABLE(); /* USER CODE BEGIN CRC_MspDeInit 1 */ /* USER CODE END CRC_MspDeInit 1 */ } } /** * @brief TIM_Base MSP Initialization * This function configures the hardware resources used in this example * @param htim_base: TIM_Base handle pointer * @retval None */ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) { if(htim_base->Instance==TIM2) { /* USER CODE BEGIN TIM2_MspInit 0 */ /* USER CODE END TIM2_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_TIM2_CLK_ENABLE(); /* USER CODE BEGIN TIM2_MspInit 1 */ /* USER CODE END TIM2_MspInit 1 */ } } /** * @brief TIM_Base MSP De-Initialization * This function freeze the hardware resources used in this example * @param htim_base: TIM_Base handle pointer * @retval None */ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) { if(htim_base->Instance==TIM2) { /* USER CODE BEGIN TIM2_MspDeInit 0 */ /* USER CODE END TIM2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_TIM2_CLK_DISABLE(); /* USER CODE BEGIN TIM2_MspDeInit 1 */ /* USER CODE END TIM2_MspDeInit 1 */ } } /** * @brief UART MSP Initialization * This function configures the hardware resources used in this example * @param huart: UART handle pointer * @retval None */ void HAL_UART_MspInit(UART_HandleTypeDef* huart) { GPIO_InitTypeDef GPIO_InitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; if(huart->Instance==USART2) { /* USER CODE BEGIN USART2_MspInit 0 */ /* USER CODE END USART2_MspInit 0 */ /** Initializes the peripherals clocks */ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2; PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } /* Peripheral clock enable */ __HAL_RCC_USART2_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**USART2 GPIO Configuration PA2 ------> USART2_TX PA3 ------> USART2_RX */ GPIO_InitStruct.Pin = USART2_TX_Pin|USART2_RX_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* USART2 interrupt Init */ HAL_NVIC_SetPriority(USART2_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspInit 1 */ /* USER CODE END USART2_MspInit 1 */ } } /** * @brief UART MSP De-Initialization * This function freeze the hardware resources used in this example * @param huart: UART handle pointer * @retval None */ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { if(huart->Instance==USART2) { /* USER CODE BEGIN USART2_MspDeInit 0 */ /* USER CODE END USART2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART2_CLK_DISABLE(); /**USART2 GPIO Configuration PA2 ------> USART2_TX PA3 ------> USART2_RX */ HAL_GPIO_DeInit(GPIOA, USART2_TX_Pin|USART2_RX_Pin); /* USART2 interrupt DeInit */ HAL_NVIC_DisableIRQ(USART2_IRQn); /* USER CODE BEGIN USART2_MspDeInit 1 */ /* USER CODE END USART2_MspDeInit 1 */ } } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */
6,316
C
23.675781
80
0.589772
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Src/sysmem.c
/** ****************************************************************************** * @file sysmem.c * @author Generated by STM32CubeIDE * @brief STM32CubeIDE System Memory calls file * * For more information about which C functions * need which of these lowlevel functions * please consult the newlib libc manual ****************************************************************************** * @attention * * Copyright (c) 2023 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* Includes */ #include <errno.h> #include <stdint.h> /** * Pointer to the current high watermark of the heap usage */ static uint8_t *__sbrk_heap_end = NULL; /** * @brief _sbrk() allocates memory to the newlib heap and is used by malloc * and others from the C library * * @verbatim * ############################################################################ * # .data # .bss # newlib heap # MSP stack # * # # # # Reserved by _Min_Stack_Size # * ############################################################################ * ^-- RAM start ^-- _end _estack, RAM end --^ * @endverbatim * * This implementation starts allocating at the '_end' linker symbol * The '_Min_Stack_Size' linker symbol reserves a memory for the MSP stack * The implementation considers '_estack' linker symbol to be RAM end * NOTE: If the MSP stack, at any point during execution, grows larger than the * reserved size, please increase the '_Min_Stack_Size'. * * @param incr Memory size * @return Pointer to allocated memory */ void *_sbrk(ptrdiff_t incr) { extern uint8_t _end; /* Symbol defined in the linker script */ extern uint8_t _estack; /* Symbol defined in the linker script */ extern uint32_t _Min_Stack_Size; /* Symbol defined in the linker script */ const uint32_t stack_limit = (uint32_t)&_estack - (uint32_t)&_Min_Stack_Size; const uint8_t *max_heap = (uint8_t *)stack_limit; uint8_t *prev_heap_end; /* Initialize heap end at first call */ if (NULL == __sbrk_heap_end) { __sbrk_heap_end = &_end; } /* Protect heap from growing into the reserved MSP stack */ if (__sbrk_heap_end + incr > max_heap) { errno = ENOMEM; return (void *)-1; } prev_heap_end = __sbrk_heap_end; __sbrk_heap_end += incr; return (void *)prev_heap_end; }
2,726
C
33.0875
79
0.537784
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Src/stm32g4xx_it.c
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32g4xx_it.c * @brief Interrupt Service Routines. ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32g4xx_it.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN TD */ /* USER CODE END TD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ extern UART_HandleTypeDef huart2; /* USER CODE BEGIN EV */ /* USER CODE END EV */ /******************************************************************************/ /* Cortex-M4 Processor Interruption and Exception Handlers */ /******************************************************************************/ /** * @brief This function handles Non maskable interrupt. */ void NMI_Handler(void) { /* USER CODE BEGIN NonMaskableInt_IRQn 0 */ /* USER CODE END NonMaskableInt_IRQn 0 */ /* USER CODE BEGIN NonMaskableInt_IRQn 1 */ while (1) { } /* USER CODE END NonMaskableInt_IRQn 1 */ } /** * @brief This function handles Hard fault interrupt. */ void HardFault_Handler(void) { /* USER CODE BEGIN HardFault_IRQn 0 */ /* USER CODE END HardFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_HardFault_IRQn 0 */ /* USER CODE END W1_HardFault_IRQn 0 */ } } /** * @brief This function handles Memory management fault. */ void MemManage_Handler(void) { /* USER CODE BEGIN MemoryManagement_IRQn 0 */ /* USER CODE END MemoryManagement_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_MemoryManagement_IRQn 0 */ /* USER CODE END W1_MemoryManagement_IRQn 0 */ } } /** * @brief This function handles Prefetch fault, memory access fault. */ void BusFault_Handler(void) { /* USER CODE BEGIN BusFault_IRQn 0 */ /* USER CODE END BusFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_BusFault_IRQn 0 */ /* USER CODE END W1_BusFault_IRQn 0 */ } } /** * @brief This function handles Undefined instruction or illegal state. */ void UsageFault_Handler(void) { /* USER CODE BEGIN UsageFault_IRQn 0 */ /* USER CODE END UsageFault_IRQn 0 */ while (1) { /* USER CODE BEGIN W1_UsageFault_IRQn 0 */ /* USER CODE END W1_UsageFault_IRQn 0 */ } } /** * @brief This function handles System service call via SWI instruction. */ void SVC_Handler(void) { /* USER CODE BEGIN SVCall_IRQn 0 */ /* USER CODE END SVCall_IRQn 0 */ /* USER CODE BEGIN SVCall_IRQn 1 */ /* USER CODE END SVCall_IRQn 1 */ } /** * @brief This function handles Debug monitor. */ void DebugMon_Handler(void) { /* USER CODE BEGIN DebugMonitor_IRQn 0 */ /* USER CODE END DebugMonitor_IRQn 0 */ /* USER CODE BEGIN DebugMonitor_IRQn 1 */ /* USER CODE END DebugMonitor_IRQn 1 */ } /** * @brief This function handles Pendable request for system service. */ void PendSV_Handler(void) { /* USER CODE BEGIN PendSV_IRQn 0 */ /* USER CODE END PendSV_IRQn 0 */ /* USER CODE BEGIN PendSV_IRQn 1 */ /* USER CODE END PendSV_IRQn 1 */ } /** * @brief This function handles System tick timer. */ void SysTick_Handler(void) { /* USER CODE BEGIN SysTick_IRQn 0 */ /* USER CODE END SysTick_IRQn 0 */ HAL_IncTick(); /* USER CODE BEGIN SysTick_IRQn 1 */ /* USER CODE END SysTick_IRQn 1 */ } /******************************************************************************/ /* STM32G4xx Peripheral Interrupt Handlers */ /* Add here the Interrupt Handlers for the used peripherals. */ /* For the available peripheral interrupt handler names, */ /* please refer to the startup file (startup_stm32g4xx.s). */ /******************************************************************************/ /** * @brief This function handles USART2 global interrupt / USART2 wake-up interrupt through EXTI line 26. */ void USART2_IRQHandler(void) { /* USER CODE BEGIN USART2_IRQn 0 */ /* USER CODE END USART2_IRQn 0 */ HAL_UART_IRQHandler(&huart2); /* USER CODE BEGIN USART2_IRQn 1 */ /* USER CODE END USART2_IRQn 1 */ } /* USER CODE BEGIN 1 */ /* USER CODE END 1 */
5,569
C
24.550459
105
0.510864
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Src/main.c
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.c * @brief : Main program body ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "app_x-cube-ai.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include <stdint.h> #include "network.h" /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ CRC_HandleTypeDef hcrc; TIM_HandleTypeDef htim2; UART_HandleTypeDef huart2; /* USER CODE BEGIN PV */ union obsUnion { float floatValue[48]; uint8_t bytes[48 * sizeof(float)]; }; union obsUnion obs_data; union actUnion { float floatValue[12]; uint8_t bytes[12 * sizeof(float)]; }; union actUnion act_data; ai_float in_data1[AI_NETWORK_IN_1_SIZE]; ai_float out_data1[AI_NETWORK_OUT_1_SIZE]; ai_float out_data2[AI_NETWORK_OUT_2_SIZE]; ai_float out_data3[AI_NETWORK_OUT_3_SIZE]; uint8_t data_flag; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_USART2_UART_Init(void); static void MX_CRC_Init(void); static void MX_TIM2_Init(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * @retval int */ int main(void) { /* USER CODE BEGIN 1 */ data_flag=0; /* USER CODE END 1 */ /* MCU Configuration--------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_USART2_UART_Init(); MX_CRC_Init(); MX_TIM2_Init(); MX_X_CUBE_AI_Init(); /* USER CODE BEGIN 2 */ HAL_UART_Receive_IT(&huart2, obs_data.bytes, sizeof(obs_data.bytes)); /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { if(data_flag) { TIM2->CNT = 0; HAL_TIM_Base_Start(&htim2); for(int i=0; i<48; i++) { in_data1[i] = obs_data.floatValue[i]; } MX_X_CUBE_AI_Process(); HAL_TIM_Base_Stop(&htim2); for(int i=0; i<12; i++) { act_data.floatValue[i] = out_data1[i]; } data_flag = 0; HAL_UART_Transmit(&huart2, act_data.bytes, sizeof(act_data.bytes), 100); HAL_UART_Receive_IT(&huart2, obs_data.bytes, sizeof(obs_data.bytes)); } /* USER CODE END WHILE */ MX_X_CUBE_AI_Process(); /* USER CODE BEGIN 3 */ } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Configure the main internal regulator output voltage */ HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1_BOOST); /** Initializes the RCC Oscillators according to the specified parameters * in the RCC_OscInitTypeDef structure. */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV4; RCC_OscInitStruct.PLL.PLLN = 85; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** Initializes the CPU, AHB and APB buses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) { Error_Handler(); } } /** * @brief CRC Initialization Function * @param None * @retval None */ static void MX_CRC_Init(void) { /* USER CODE BEGIN CRC_Init 0 */ /* USER CODE END CRC_Init 0 */ /* USER CODE BEGIN CRC_Init 1 */ /* USER CODE END CRC_Init 1 */ hcrc.Instance = CRC; hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE; hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE; hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE; hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE; hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES; if (HAL_CRC_Init(&hcrc) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN CRC_Init 2 */ /* USER CODE END CRC_Init 2 */ } /** * @brief TIM2 Initialization Function * @param None * @retval None */ static void MX_TIM2_Init(void) { /* USER CODE BEGIN TIM2_Init 0 */ /* USER CODE END TIM2_Init 0 */ TIM_ClockConfigTypeDef sClockSourceConfig = {0}; TIM_MasterConfigTypeDef sMasterConfig = {0}; /* USER CODE BEGIN TIM2_Init 1 */ /* USER CODE END TIM2_Init 1 */ htim2.Instance = TIM2; htim2.Init.Prescaler = 170; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; htim2.Init.Period = 4.294967295E9; htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { Error_Handler(); } sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { Error_Handler(); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN TIM2_Init 2 */ /* USER CODE END TIM2_Init 2 */ } /** * @brief USART2 Initialization Function * @param None * @retval None */ static void MX_USART2_UART_Init(void) { /* USER CODE BEGIN USART2_Init 0 */ /* USER CODE END USART2_Init 0 */ /* USER CODE BEGIN USART2_Init 1 */ /* USER CODE END USART2_Init 1 */ huart2.Instance = USART2; huart2.Init.BaudRate = 460800; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart2.Init.OverSampling = UART_OVERSAMPLING_16; huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1; huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart2) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK) { Error_Handler(); } if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN USART2_Init 2 */ /* USER CODE END USART2_Init 2 */ } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* USER CODE BEGIN MX_GPIO_Init_1 */ /* USER CODE END MX_GPIO_Init_1 */ /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(LD2_GPIO_Port, LD2_Pin, GPIO_PIN_RESET); /*Configure GPIO pin : LD2_Pin */ GPIO_InitStruct.Pin = LD2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(LD2_GPIO_Port, &GPIO_InitStruct); /* USER CODE BEGIN MX_GPIO_Init_2 */ /* USER CODE END MX_GPIO_Init_2 */ } /* USER CODE BEGIN 4 */ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { // We will set a data flag here and execute in the main loop data_flag = 1; } void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { } /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ /* User can add his own implementation to report the HAL error return state */ __disable_irq(); while (1) { } /* USER CODE END Error_Handler_Debug */ } #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */
10,424
C
25.392405
82
0.622122
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Inc/stm32g4xx_it.h
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32g4xx_it.h * @brief This file contains the headers of the interrupt handlers. ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32G4xx_IT_H #define __STM32G4xx_IT_H #ifdef __cplusplus extern "C" { #endif /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ /* USER CODE BEGIN EM */ /* USER CODE END EM */ /* Exported functions prototypes ---------------------------------------------*/ void NMI_Handler(void); void HardFault_Handler(void); void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); void USART2_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ #ifdef __cplusplus } #endif #endif /* __STM32G4xx_IT_H */
1,890
C
26.808823
80
0.481481
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Inc/stm32g4xx_hal_conf.h
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file stm32g4xx_hal_conf.h * @author MCD Application Team * @brief HAL configuration file ****************************************************************************** * @attention * * Copyright (c) 2019 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef STM32G4xx_HAL_CONF_H #define STM32G4xx_HAL_CONF_H #ifdef __cplusplus extern "C" { #endif /* Exported types ------------------------------------------------------------*/ /* Exported constants --------------------------------------------------------*/ /* ########################## Module Selection ############################## */ /** * @brief This is the list of modules to be used in the HAL driver */ #define HAL_MODULE_ENABLED /*#define HAL_ADC_MODULE_ENABLED */ /*#define HAL_COMP_MODULE_ENABLED */ /*#define HAL_CORDIC_MODULE_ENABLED */ #define HAL_CRC_MODULE_ENABLED /*#define HAL_CRYP_MODULE_ENABLED */ /*#define HAL_DAC_MODULE_ENABLED */ /*#define HAL_FDCAN_MODULE_ENABLED */ /*#define HAL_FMAC_MODULE_ENABLED */ /*#define HAL_HRTIM_MODULE_ENABLED */ /*#define HAL_IRDA_MODULE_ENABLED */ /*#define HAL_IWDG_MODULE_ENABLED */ /*#define HAL_I2C_MODULE_ENABLED */ /*#define HAL_I2S_MODULE_ENABLED */ /*#define HAL_LPTIM_MODULE_ENABLED */ /*#define HAL_NAND_MODULE_ENABLED */ /*#define HAL_NOR_MODULE_ENABLED */ /*#define HAL_OPAMP_MODULE_ENABLED */ /*#define HAL_PCD_MODULE_ENABLED */ /*#define HAL_QSPI_MODULE_ENABLED */ /*#define HAL_RNG_MODULE_ENABLED */ /*#define HAL_RTC_MODULE_ENABLED */ /*#define HAL_SAI_MODULE_ENABLED */ /*#define HAL_SMARTCARD_MODULE_ENABLED */ /*#define HAL_SMBUS_MODULE_ENABLED */ /*#define HAL_SPI_MODULE_ENABLED */ /*#define HAL_SRAM_MODULE_ENABLED */ #define HAL_TIM_MODULE_ENABLED #define HAL_UART_MODULE_ENABLED /*#define HAL_USART_MODULE_ENABLED */ /*#define HAL_WWDG_MODULE_ENABLED */ #define HAL_GPIO_MODULE_ENABLED #define HAL_EXTI_MODULE_ENABLED #define HAL_DMA_MODULE_ENABLED #define HAL_RCC_MODULE_ENABLED #define HAL_FLASH_MODULE_ENABLED #define HAL_PWR_MODULE_ENABLED #define HAL_CORTEX_MODULE_ENABLED /* ########################## Register Callbacks selection ############################## */ /** * @brief This is the list of modules where register callback can be used */ #define USE_HAL_ADC_REGISTER_CALLBACKS 0U #define USE_HAL_COMP_REGISTER_CALLBACKS 0U #define USE_HAL_CORDIC_REGISTER_CALLBACKS 0U #define USE_HAL_CRYP_REGISTER_CALLBACKS 0U #define USE_HAL_DAC_REGISTER_CALLBACKS 0U #define USE_HAL_EXTI_REGISTER_CALLBACKS 0U #define USE_HAL_FDCAN_REGISTER_CALLBACKS 0U #define USE_HAL_FMAC_REGISTER_CALLBACKS 0U #define USE_HAL_HRTIM_REGISTER_CALLBACKS 0U #define USE_HAL_I2C_REGISTER_CALLBACKS 0U #define USE_HAL_I2S_REGISTER_CALLBACKS 0U #define USE_HAL_IRDA_REGISTER_CALLBACKS 0U #define USE_HAL_LPTIM_REGISTER_CALLBACKS 0U #define USE_HAL_NAND_REGISTER_CALLBACKS 0U #define USE_HAL_NOR_REGISTER_CALLBACKS 0U #define USE_HAL_OPAMP_REGISTER_CALLBACKS 0U #define USE_HAL_PCD_REGISTER_CALLBACKS 0U #define USE_HAL_QSPI_REGISTER_CALLBACKS 0U #define USE_HAL_RNG_REGISTER_CALLBACKS 0U #define USE_HAL_RTC_REGISTER_CALLBACKS 0U #define USE_HAL_SAI_REGISTER_CALLBACKS 0U #define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0U #define USE_HAL_SMBUS_REGISTER_CALLBACKS 0U #define USE_HAL_SPI_REGISTER_CALLBACKS 0U #define USE_HAL_SRAM_REGISTER_CALLBACKS 0U #define USE_HAL_TIM_REGISTER_CALLBACKS 0U #define USE_HAL_UART_REGISTER_CALLBACKS 0U #define USE_HAL_USART_REGISTER_CALLBACKS 0U #define USE_HAL_WWDG_REGISTER_CALLBACKS 0U /* ########################## Oscillator Values adaptation ####################*/ /** * @brief Adjust the value of External High Speed oscillator (HSE) used in your application. * This value is used by the RCC HAL module to compute the system frequency * (when HSE is used as system clock source, directly or through the PLL). */ #if !defined (HSE_VALUE) #define HSE_VALUE (8000000UL) /*!< Value of the External oscillator in Hz */ #endif /* HSE_VALUE */ #if !defined (HSE_STARTUP_TIMEOUT) #define HSE_STARTUP_TIMEOUT (100UL) /*!< Time out for HSE start up, in ms */ #endif /* HSE_STARTUP_TIMEOUT */ /** * @brief Internal High Speed oscillator (HSI) value. * This value is used by the RCC HAL module to compute the system frequency * (when HSI is used as system clock source, directly or through the PLL). */ #if !defined (HSI_VALUE) #define HSI_VALUE (16000000UL) /*!< Value of the Internal oscillator in Hz*/ #endif /* HSI_VALUE */ /** * @brief Internal High Speed oscillator (HSI48) value for USB FS and RNG. * This internal oscillator is mainly dedicated to provide a high precision clock to * the USB peripheral by means of a special Clock Recovery System (CRS) circuitry. * When the CRS is not used, the HSI48 RC oscillator runs on it default frequency * which is subject to manufacturing process variations. */ #if !defined (HSI48_VALUE) #define HSI48_VALUE (48000000UL) /*!< Value of the Internal High Speed oscillator for USB FS/RNG in Hz. The real value my vary depending on manufacturing process variations.*/ #endif /* HSI48_VALUE */ /** * @brief Internal Low Speed oscillator (LSI) value. */ #if !defined (LSI_VALUE) /*!< Value of the Internal Low Speed oscillator in Hz The real value may vary depending on the variations in voltage and temperature.*/ #define LSI_VALUE (32000UL) /*!< LSI Typical Value in Hz*/ #endif /* LSI_VALUE */ /** * @brief External Low Speed oscillator (LSE) value. * This value is used by the UART, RTC HAL module to compute the system frequency */ #if !defined (LSE_VALUE) #define LSE_VALUE (32768UL) /*!< Value of the External Low Speed oscillator in Hz */ #endif /* LSE_VALUE */ #if !defined (LSE_STARTUP_TIMEOUT) #define LSE_STARTUP_TIMEOUT (5000UL) /*!< Time out for LSE start up, in ms */ #endif /* LSE_STARTUP_TIMEOUT */ /** * @brief External clock source for I2S and SAI peripherals * This value is used by the I2S and SAI HAL modules to compute the I2S and SAI clock source * frequency, this source is inserted directly through I2S_CKIN pad. */ #if !defined (EXTERNAL_CLOCK_VALUE) #define EXTERNAL_CLOCK_VALUE (12288000UL) /*!< Value of the External oscillator in Hz*/ #endif /* EXTERNAL_CLOCK_VALUE */ /* Tip: To avoid modifying this file each time you need to use different HSE, === you can define the HSE value in your toolchain compiler preprocessor. */ /* ########################### System Configuration ######################### */ /** * @brief This is the HAL system configuration section */ #define VDD_VALUE (3300UL) /*!< Value of VDD in mv */ #define TICK_INT_PRIORITY (0UL) /*!< tick interrupt priority (lowest by default) */ #define USE_RTOS 0U #define PREFETCH_ENABLE 0U #define INSTRUCTION_CACHE_ENABLE 1U #define DATA_CACHE_ENABLE 1U /* ########################## Assert Selection ############################## */ /** * @brief Uncomment the line below to expanse the "assert_param" macro in the * HAL drivers code */ /* #define USE_FULL_ASSERT 1U */ /* ################## SPI peripheral configuration ########################## */ /* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver * Activated: CRC code is present inside driver * Deactivated: CRC code cleaned from driver */ #define USE_SPI_CRC 0U /* Includes ------------------------------------------------------------------*/ /** * @brief Include module's header file */ #ifdef HAL_RCC_MODULE_ENABLED #include "stm32g4xx_hal_rcc.h" #endif /* HAL_RCC_MODULE_ENABLED */ #ifdef HAL_GPIO_MODULE_ENABLED #include "stm32g4xx_hal_gpio.h" #endif /* HAL_GPIO_MODULE_ENABLED */ #ifdef HAL_DMA_MODULE_ENABLED #include "stm32g4xx_hal_dma.h" #endif /* HAL_DMA_MODULE_ENABLED */ #ifdef HAL_CORTEX_MODULE_ENABLED #include "stm32g4xx_hal_cortex.h" #endif /* HAL_CORTEX_MODULE_ENABLED */ #ifdef HAL_ADC_MODULE_ENABLED #include "stm32g4xx_hal_adc.h" #endif /* HAL_ADC_MODULE_ENABLED */ #ifdef HAL_COMP_MODULE_ENABLED #include "stm32g4xx_hal_comp.h" #endif /* HAL_COMP_MODULE_ENABLED */ #ifdef HAL_CORDIC_MODULE_ENABLED #include "stm32g4xx_hal_cordic.h" #endif /* HAL_CORDIC_MODULE_ENABLED */ #ifdef HAL_CRC_MODULE_ENABLED #include "stm32g4xx_hal_crc.h" #endif /* HAL_CRC_MODULE_ENABLED */ #ifdef HAL_CRYP_MODULE_ENABLED #include "stm32g4xx_hal_cryp.h" #endif /* HAL_CRYP_MODULE_ENABLED */ #ifdef HAL_DAC_MODULE_ENABLED #include "stm32g4xx_hal_dac.h" #endif /* HAL_DAC_MODULE_ENABLED */ #ifdef HAL_EXTI_MODULE_ENABLED #include "stm32g4xx_hal_exti.h" #endif /* HAL_EXTI_MODULE_ENABLED */ #ifdef HAL_FDCAN_MODULE_ENABLED #include "stm32g4xx_hal_fdcan.h" #endif /* HAL_FDCAN_MODULE_ENABLED */ #ifdef HAL_FLASH_MODULE_ENABLED #include "stm32g4xx_hal_flash.h" #endif /* HAL_FLASH_MODULE_ENABLED */ #ifdef HAL_FMAC_MODULE_ENABLED #include "stm32g4xx_hal_fmac.h" #endif /* HAL_FMAC_MODULE_ENABLED */ #ifdef HAL_HRTIM_MODULE_ENABLED #include "stm32g4xx_hal_hrtim.h" #endif /* HAL_HRTIM_MODULE_ENABLED */ #ifdef HAL_IRDA_MODULE_ENABLED #include "stm32g4xx_hal_irda.h" #endif /* HAL_IRDA_MODULE_ENABLED */ #ifdef HAL_IWDG_MODULE_ENABLED #include "stm32g4xx_hal_iwdg.h" #endif /* HAL_IWDG_MODULE_ENABLED */ #ifdef HAL_I2C_MODULE_ENABLED #include "stm32g4xx_hal_i2c.h" #endif /* HAL_I2C_MODULE_ENABLED */ #ifdef HAL_I2S_MODULE_ENABLED #include "stm32g4xx_hal_i2s.h" #endif /* HAL_I2S_MODULE_ENABLED */ #ifdef HAL_LPTIM_MODULE_ENABLED #include "stm32g4xx_hal_lptim.h" #endif /* HAL_LPTIM_MODULE_ENABLED */ #ifdef HAL_NAND_MODULE_ENABLED #include "stm32g4xx_hal_nand.h" #endif /* HAL_NAND_MODULE_ENABLED */ #ifdef HAL_NOR_MODULE_ENABLED #include "stm32g4xx_hal_nor.h" #endif /* HAL_NOR_MODULE_ENABLED */ #ifdef HAL_OPAMP_MODULE_ENABLED #include "stm32g4xx_hal_opamp.h" #endif /* HAL_OPAMP_MODULE_ENABLED */ #ifdef HAL_PCD_MODULE_ENABLED #include "stm32g4xx_hal_pcd.h" #endif /* HAL_PCD_MODULE_ENABLED */ #ifdef HAL_PWR_MODULE_ENABLED #include "stm32g4xx_hal_pwr.h" #endif /* HAL_PWR_MODULE_ENABLED */ #ifdef HAL_QSPI_MODULE_ENABLED #include "stm32g4xx_hal_qspi.h" #endif /* HAL_QSPI_MODULE_ENABLED */ #ifdef HAL_RNG_MODULE_ENABLED #include "stm32g4xx_hal_rng.h" #endif /* HAL_RNG_MODULE_ENABLED */ #ifdef HAL_RTC_MODULE_ENABLED #include "stm32g4xx_hal_rtc.h" #endif /* HAL_RTC_MODULE_ENABLED */ #ifdef HAL_SAI_MODULE_ENABLED #include "stm32g4xx_hal_sai.h" #endif /* HAL_SAI_MODULE_ENABLED */ #ifdef HAL_SMARTCARD_MODULE_ENABLED #include "stm32g4xx_hal_smartcard.h" #endif /* HAL_SMARTCARD_MODULE_ENABLED */ #ifdef HAL_SMBUS_MODULE_ENABLED #include "stm32g4xx_hal_smbus.h" #endif /* HAL_SMBUS_MODULE_ENABLED */ #ifdef HAL_SPI_MODULE_ENABLED #include "stm32g4xx_hal_spi.h" #endif /* HAL_SPI_MODULE_ENABLED */ #ifdef HAL_SRAM_MODULE_ENABLED #include "stm32g4xx_hal_sram.h" #endif /* HAL_SRAM_MODULE_ENABLED */ #ifdef HAL_TIM_MODULE_ENABLED #include "stm32g4xx_hal_tim.h" #endif /* HAL_TIM_MODULE_ENABLED */ #ifdef HAL_UART_MODULE_ENABLED #include "stm32g4xx_hal_uart.h" #endif /* HAL_UART_MODULE_ENABLED */ #ifdef HAL_USART_MODULE_ENABLED #include "stm32g4xx_hal_usart.h" #endif /* HAL_USART_MODULE_ENABLED */ #ifdef HAL_WWDG_MODULE_ENABLED #include "stm32g4xx_hal_wwdg.h" #endif /* HAL_WWDG_MODULE_ENABLED */ /* Exported macro ------------------------------------------------------------*/ #ifdef USE_FULL_ASSERT /** * @brief The assert_param macro is used for function's parameters check. * @param expr: If expr is false, it calls assert_failed function * which reports the name of the source file and the source * line number of the call that failed. * If expr is true, it returns no value. * @retval None */ #define assert_param(expr) ((expr) ? (void)0U : assert_failed((uint8_t *)__FILE__, __LINE__)) /* Exported functions ------------------------------------------------------- */ void assert_failed(uint8_t *file, uint32_t line); #else #define assert_param(expr) ((void)0U) #endif /* USE_FULL_ASSERT */ #ifdef __cplusplus } #endif #endif /* STM32G4xx_HAL_CONF_H */
12,935
C
32.952756
118
0.647313
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Inc/RTE_Components.h
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file * @author MCD Application Team * @version V2.0.0 ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __RTE_COMPONENTS_H__ #define __RTE_COMPONENTS_H__ /* Defines ------------------------------------------------------------------*/ /* STMicroelectronics.X-CUBE-AI.8.1.0 */ #define AI_ApplicationTemplate #endif /* __RTE_COMPONENTS_H__ */
1,003
C
33.620688
82
0.440678
Tbarkin121/GuardDog/stm32/AnymalNet/Core/Inc/main.h
/* USER CODE BEGIN Header */ /** ****************************************************************************** * @file : main.h * @brief : Header for main.c file. * This file contains the common defines of the application. ****************************************************************************** * @attention * * Copyright (c) 2024 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** */ /* USER CODE END Header */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __MAIN_H #define __MAIN_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "stm32g4xx_hal.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Exported types ------------------------------------------------------------*/ /* USER CODE BEGIN ET */ /* USER CODE END ET */ /* Exported constants --------------------------------------------------------*/ /* USER CODE BEGIN EC */ /* USER CODE END EC */ /* Exported macro ------------------------------------------------------------*/ /* USER CODE BEGIN EM */ /* USER CODE END EM */ /* Exported functions prototypes ---------------------------------------------*/ void Error_Handler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ /* Private defines -----------------------------------------------------------*/ #define USART2_TX_Pin GPIO_PIN_2 #define USART2_TX_GPIO_Port GPIOA #define USART2_RX_Pin GPIO_PIN_3 #define USART2_RX_GPIO_Port GPIOA #define T_SWDIO_Pin GPIO_PIN_13 #define T_SWDIO_GPIO_Port GPIOA #define T_SWCLK_Pin GPIO_PIN_14 #define T_SWCLK_GPIO_Port GPIOA #define T_SWO_Pin GPIO_PIN_3 #define T_SWO_GPIO_Port GPIOB #define LD2_Pin GPIO_PIN_8 #define LD2_GPIO_Port GPIOB /* USER CODE BEGIN Private defines */ /* USER CODE END Private defines */ #ifdef __cplusplus } #endif #endif /* __MAIN_H */
2,310
C
27.182926
80
0.467532
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/formats_list.h
/** ****************************************************************************** * @file format_list.h * @author AST Embedded Analytics Research Platform * @brief Definitions of AI platform public APIs types ****************************************************************************** * @attention * * Copyright (c) 2019 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ /* FMT_ENTRY( exp_(0/1 only), name_, type_id_, * sign_bit_, float_bit_, pmask_, bits_, fbits_, ldiv_bits_) * Specifications (in order of the bit fields, little endian): - name_ : it is the enum used to define both the ai_array_format and ai_buffer_format. - exp_ (1bit) : it is a boolean flag (0 or 1) indicating whether the format is available as a public APIs ai_buffer format. in this case the field exp_name_ indicates the enum name of the ai_buffer format - (7 bits): reserved for flags - sign_bit_ (1bit) : codes whether or not the format is of a signed type - float_bit_ (1bit) : codes if the format is float - ldiv_bits (2 bits) : right shift value for computing the byte size of the format - type_id_ (4bits) : it is used to define the "family" of the format: see @ref AI_FMT_Q as an example. Currently supported types are: AI_FMT_Q (fixed point types), AI_FMT_FLOAT (floating point values), AI_FMT_LUT4 or AI_FMT_LUT8 (compressed formats) - pmask_ (3bits) : padding mask bits for the format - bits_ (7bits) : size in bits of the format (NB: integer+fractional bits) - fbits_ (7bits) : number of fractional bits for the format (for AI_FMT_Q only) */ /* Format none entry */ FMT_ENTRY(1, NONE, AI_FMT_NONE, 0, 0, 0x0, 0, 0, 0) /* Floating point formats */ FMT_ENTRY(1, FLOAT, AI_FMT_FLOAT, 1, 1, 0x0, 32, 0, 0) FMT_ENTRY(0, FLOAT64, AI_FMT_FLOAT, 1, 1, 0x0, 64, 0, 0) FMT_ENTRY(0, FLOAT16, AI_FMT_FLOAT, 1, 1, 0x0, 16, 0, 0) /* Integer formats (i.e. fractional bits = 0!) */ FMT_ENTRY(1, U8, AI_FMT_Q, 0, 0, 0x0, 8, 0, 0) FMT_ENTRY(1, U16, AI_FMT_Q, 0, 0, 0x0, 16, 0, 0) FMT_ENTRY(1, U32, AI_FMT_Q, 0, 0, 0x0, 32, 0, 0) FMT_ENTRY(0, U64, AI_FMT_Q, 0, 0, 0x0, 64, 0, 0) FMT_ENTRY(1, U1, AI_FMT_Q, 0, 0, 0x0, 1, 0, 0) FMT_ENTRY(0, U4, AI_FMT_Q, 0, 0, 0x0, 4, 0, 0) FMT_ENTRY(1, S8, AI_FMT_Q, 1, 0, 0x0, 8, 0, 0) FMT_ENTRY(1, S16, AI_FMT_Q, 1, 0, 0x0, 16, 0, 0) FMT_ENTRY(1, S32, AI_FMT_Q, 1, 0, 0x0, 32, 0, 0) FMT_ENTRY(0, S64, AI_FMT_Q, 1, 0, 0x0, 64, 0, 0) FMT_ENTRY(1, S1, AI_FMT_Q, 1, 0, 0x0, 1, 0, 0) FMT_ENTRY(0, S4, AI_FMT_Q, 1, 0, 0x0, 4, 0, 0) /* Fixed-point formats including ARM CMSIS Q7, Q15, Q31 ones */ FMT_ENTRY(1, Q, AI_FMT_Q, 1, 0, 0x0, 0, 0, 0) FMT_ENTRY(1, Q7, AI_FMT_Q, 1, 0, 0x0, 8, 7, 0) FMT_ENTRY(1, Q15, AI_FMT_Q, 1, 0, 0x0, 16, 15, 0) FMT_ENTRY(0, Q31, AI_FMT_Q, 1, 0, 0x0, 32, 31, 0) FMT_ENTRY(1, UQ, AI_FMT_Q, 0, 0, 0x0, 0, 0, 0) FMT_ENTRY(1, UQ7, AI_FMT_Q, 0, 0, 0x0, 8, 7, 0) FMT_ENTRY(1, UQ15, AI_FMT_Q, 0, 0, 0x0, 16, 15, 0) FMT_ENTRY(0, UQ31, AI_FMT_Q, 0, 0, 0x0, 32, 31, 0) /* Compressed formats */ FMT_ENTRY(0, LUT4_FLOAT, AI_FMT_LUT4, 1, 1, 0x0, 32, 0, 3) FMT_ENTRY(0, LUT8_FLOAT, AI_FMT_LUT8, 1, 1, 0x0, 32, 0, 2) FMT_ENTRY(0, LUT4_Q15, AI_FMT_LUT4, 1, 0, 0x0, 16, 15, 2) FMT_ENTRY(0, LUT8_Q15, AI_FMT_LUT8, 1, 0, 0x0, 16, 15, 1) FMT_ENTRY(0, LUT4_UQ15, AI_FMT_LUT4, 0, 0, 0x0, 16, 15, 2) FMT_ENTRY(0, LUT8_UQ15, AI_FMT_LUT8, 0, 0, 0x0, 16, 15, 1) /* Boolean format */ FMT_ENTRY(1, BOOL, AI_FMT_BOOL, 0, 0, 0x0, 8, 0, 0) #undef FMT_ENTRY
3,930
C
41.72826
80
0.564885
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/core_convert.h
/** ****************************************************************************** * @file core_convert.h * @author AST Embedded Analytics Research Platform * @brief header file of core utils routines ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef CORE_CONVERT_H #define CORE_CONVERT_H #pragma once #include "ai_platform.h" #include "ai_platform_interface.h" #include "core_common.h" AI_API_DECLARE_BEGIN /*! * @defgroup core_convert Core Convert Routines * @brief Implementation of core node format convertion routines * (Q7 to float, ... etc.) */ /*! * @brief Convert tensors from float to quantized or viceversa * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert(ai_node *pNode); /*! * @brief Convert integer tensors between QM.N formats (8/16 bits) * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_fixed(ai_node *pNode); /*! * @brief Convert integer tensors between signed and usigned (int8/uint8) formats * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_integer(ai_node *pNode); /*! * @brief Convert float tensor to binary * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_if32os1(ai_node *pNode); /*! * @brief Convert binary tensor to float * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_is8os1(ai_node *pNode); /*! * @brief Convert binary tensor to signed int 8 bit * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_is1os8(ai_node *pNode); /*! * @brief Convert binary tensor to signed int 16 bit * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_is1os16(ai_node *pNode); /*! * @brief Convert binary tensor to float * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_is1of32(ai_node *pNode); /*! * @brief Convert signed int 16 bit tensor to float * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_is16of32(ai_node *pNode); /*! * @brief Convert unsigned int 16 bit tensor to float * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_iu16of32(ai_node *pNode); /*! * @brief Convert float tensor to signed int 16 bit * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_if32os16(ai_node *pNode); /*! * @brief Convert float tensor to unsigned int 16 bit * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_if32ou16(ai_node *pNode); /*! * @brief Convert signed int 16 bit tensor to unsigned int 16 bit * @ingroup core_convert * @param[in] pNode in a handler to node (layer or operator) */ AI_INTERNAL_API void node_convert_is16ou16(ai_node *pNode); /*! * @brief Convert a shape struct into a stride struct * @ingroup core_convert * @param[in] in a pointer to a shape to convert * @return a condverted stride datastruct */ AI_INTERNAL_API void core_shape_to_stride(ai_stride* out, const ai_shape* in); #endif /*CORE_CONVERT_H*/
4,123
C
23.993939
81
0.65171
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_conv2d.h
/** ****************************************************************************** * @file layers_conv2d.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform conv2d layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_CONV2D_H #define LAYERS_CONV2D_H #pragma once #include "layers_nl.h" #include "layers_pool.h" #define AI_LAYER_CONV2D_FIELDS_DECLARE \ AI_LAYER_COMMON_FIELDS_DECLARE \ ai_u32 groups; /*!< groups for separable convolution */ \ AI_CONST ai_array* nl_params; /*!< array pointer to non linear parameters */ \ func_nl nl_func; /*!< function pointer to non linear transform */ \ ai_shape_2d filter_stride; /*!< filter stride, how much the filter moves */ \ ai_shape_2d dilation; /*!< dilation value along axis of the filter */ \ ai_shape filter_pad; /*!< filter pad 4d */ \ ai_layer_format_type in_ch_format; /*!< Input format (Channel 1st vs Channel last */ \ ai_layer_format_type out_ch_format; /*!< Output format (Channel 1st vs Channel last */ /*! * @defgroup layers_conv2d Convolutive Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_dense * @ingroup layers_conv2d * @brief Dense (fully connected) layer */ typedef ai_layer_base ai_layer_dense; /*! * @struct ai_layer_gemm * @ingroup layers_conv2d * @brief layer for General Matrix Multiplication * * Layer for General Matrix Multiplication (GEMM): * \f{equation}{ Y = \alpha A \cdot B + \beta C \f} * \f$\alpha\f$ and \f$\beta\f$ are paramaters, A and B are matrices, * C is a matrix or an array. Size checks for A, B, C, and Y are performed and * broadcast is applied on C if necessary. * This is a sequential layer (see @ref ai_layer). */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_gemm_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_float alpha; /*!< alpha coefficient */ ai_float beta; /*!< beta coefficient */ ai_u8 tA; /*!< transpose A flag */ ai_u8 tB; /*!< transpose B flag */ } ai_layer_gemm; /*! * @struct ai_layer_conv2d * @ingroup layers_conv2d * @brief 2D convolutional layer with strides and pads */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_conv2d_ { AI_LAYER_CONV2D_FIELDS_DECLARE } ai_layer_conv2d; /*! * @struct ai_layer_conv2d_nl_pool * @ingroup layers_conv2d * @brief 2D convolutional layer + nl + pooling with strides and pads */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_conv2d_nl_pool_ { AI_LAYER_CONV2D_FIELDS_DECLARE ai_shape_2d pool_size; /*!< pooling size */ ai_shape_2d pool_stride; /*!< pooling stride */ ai_shape pool_pad; /*!< pooling pad */ ai_handle pool_func; /*!< function pointer to pooling transform */ } ai_layer_conv2d_nl_pool; AI_INTERNAL_API void ai_dict8_dot_array_f32(ai_handle out, ai_ptr_const data0, ai_ptr_const lut, const ai_float* data1, const ai_size data_size); AI_INTERNAL_API void ai_dict4_dot_array_f32(ai_handle out, ai_ptr_const data0, ai_ptr_const lut, const ai_float* data1, const ai_size data_size); /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Computes the activations of a floating point 32 2D convolutional layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_if32of32wf32(ai_layer* layer); /*! * @brief Computes the activations of a floating point 32 2D dw layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_if32of32wf32(ai_layer* layer); /*! * @brief Computes the activations of a floating point 32 2D convolutional group layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_if32of32wf32_group(ai_layer* layer); /*! * @brief Computes the activations of a 2D floating point 32 pool fused convolutional layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_if32of32wf32_pool(ai_layer* layer); /*! * @brief Computes the activations of a 2D floating point 32 pool fused dw layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_if32of32wf32_pool(ai_layer* layer); /*! * @brief Computes the activations of a 2D floating point 32 pool fused convolutional group layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_if32of32wf32_group_pool(ai_layer* layer); /*! * @brief Computes the activations of a GEMM layer. * @ingroup layers * @param layer the layer including output and input tensors */ AI_INTERNAL_API void forward_gemm(ai_layer* layer); /*! * @brief Computes matmul layer, intended as numpy.matmul(A,B). * @ingroup layers * @param layer the layer including output and input tensors */ AI_INTERNAL_API void forward_matmul(ai_layer* layer); /*! * @brief Computes the activations of a dense (fully connected) layer. * @ingroup layers_conv2d * @param layer the dense layer */ AI_INTERNAL_API void forward_dense(ai_layer* layer); /*! * @brief Computes the activations of a fixed point 2D convolutional layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of a fixed point @ref ai_layer_conv2d_nl_pool * layer. * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_integer(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer * for SSSA per layer quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_integer_SSSA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer * for SSSA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is8os8ws8_sssa_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme, with 3x3 kernels * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_3x3_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme, with 3x3 kernels and input are * channel first * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_3x3_ch1st_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme with depth multiplier > 1 * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_dm_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of int8 quantized DW layers. * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_all_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized PW layer * for SSSA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_pw_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized dilated Conv2d layer * for SSSA per channel quantized scheme (valid padding) * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_dilated_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 non dilated Conv2d layer * for SSSA per channel quantized scheme (valid padding) * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_deep_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 non dilated Conv2d layer * for SSSA per channel quantized scheme (valid padding) * number of output channel is greater than 8 * Kernels shall be 3x3 and stride is (1,1) * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_deep_3x3_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 non dilated Conv2d layer * for SSSA per channel quantized scheme (valid or same padding) * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized Conv2d layer * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_all_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized RGB Conv2d layer * for SSSA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_rgb_sssa8_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme with pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme, with 3x3 kernels, * with pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_3x3_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme, with 3x3 kernels, * with pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_3x3_ch1st_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized DW layer * for SSSA per channel quantized scheme with depth multiplier > 1 * with pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_dm_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of int8 quantized DW layers, with pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_all_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized PW layer, * with pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_pw_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized dilated Conv2d layer * for SSSA per channel quantized scheme (valid padding) and pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_dilated_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized non dilated Conv2d layer * for SSSA per channel quantized scheme (valid padding) and pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_deep_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 non dilated Conv2d layer * for SSSA per channel quantized scheme (valid padding) and pooling fused * number of output channel is greater than 8 * Kernels shall be 3x3 and stride is (1,1) * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_deep_3x3_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized non dilated Conv2d layer * for SSSA per channel quantized scheme (valid or same padding) and pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a int8 quantized Conv2d layer and pooling fused * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_all_sssa8_ch_nl_pool(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer * for SSUA per layer quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_integer_SSUA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer * for SSUA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_integer_SSUA_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer * for UAUA per layer quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_integer_UAUA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer * for UAUA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_integer_UAUA_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer. * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_integer(ai_layer *pLayer); /*! * @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer * for SSSA per layer quantized scheme * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_integer_SSSA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer * for SSSA per channel quantized scheme * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_integer_SSSA_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer * for SSUA per layer quantized scheme * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_integer_SSUA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer * for SSUA per channel quantized scheme * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_integer_SSUA_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer * for UAUA per layer quantized scheme * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_integer_UAUA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer @ref ai_layer_conv2d_nl_pool layer * for UAUA per channel quantized scheme * The @ref ai_layer_conv2d_nl_pool is a fused conv2D + optional nonlinear * layer + optional pooling / nonlinearity (average, max) * @ingroup layers_conv2d * @param layer see @ai_layer_conv2d_nl_pool */ AI_INTERNAL_API void forward_conv2d_nl_pool_integer_UAUA_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a integer dense (fully connected) layer. * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_integer(ai_layer *pLayer); /*! * @brief Computes the activations of a integer dense (fully connected) layer * for SSSA per layer quantized scheme * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_integer_SSSA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer dense (fully connected) layer * for SSSA per channel quantized scheme * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_integer_SSSA_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a integer dense (fully connected) layer * for SSUA per layer quantized scheme * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_integer_SSUA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer dense (fully connected) layer * for SSUA per channel quantized scheme * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_integer_SSUA_ch(ai_layer *pLayer); /*! * @brief Computes the activations of a integer dense (fully connected) layer * for UAUA per layer quantized scheme * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_integer_UAUA(ai_layer *pLayer); /*! * @brief Computes the activations of a integer dense (fully connected) layer * for UAUA per channel quantized scheme * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_integer_UAUA_ch(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_CONV2D_H*/
19,921
C
30.8752
98
0.69359
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_lite_math_helpers.h
#ifndef AI_LITE_MATH_HELPERS_H #define AI_LITE_MATH_HELPERS_H #include <math.h> #include "ai_platform.h" #include "ai_platform_interface.h" #include "ai_datatypes_defines.h" #define AI_FLOAT_TOLERANCE (6.19209290e-5F) /* Used for small calculation noise issues */ #define AI_FLOAT_EPSILON (1.19209290e-7F) #define AI_I8_EPSILON (0.00787401F) /* 1/(2^7 - 1) */ #define AI_I16_EPSILON (3.051851e-5F) /* 1/(2^15 - 1) */ #define AI_FLT_MAX (3.40282346638528859812e+38f) #define AI_MIN(x,y) ( ((x)<(y)) ? (x) : (y) ) #define AI_MAX(x,y) ( ((x)>(y)) ? (x) : (y) ) #define AI_SIGN(x) (((x)>0) ? 1 : -1) #define AI_CLAMP(x, min, max) AI_MIN(AI_MAX(x,min), max) #define AI_ABS(x) fabsf(x) #define AI_ABS_DIFF(x, y) ( ((x)>(y)) ? ((x)-(y)) : ((y)-(x)) ) #define AI_NEG(x) ( -1 * (x) ) #define AI_NOT(x) ( ((x)==true) ? false : true) #define AI_RECIPROCAL(x) ( 1.0f / (x) ) #define AI_CEIL(x) ceilf(x) #define AI_FLOOR(x) floorf(x) #define AI_FLOOR_DIV(x, y) AI_FLOOR((x)/(y)) /* floor division: x // y */ #define AI_FLOOR_MOD(x, y) fmodf(x, y) #define AI_ROUND(x) roundf(x) #define AI_POW(x,y) powf(x, y) #define AI_SQUARED_DIFF(x, y) (((x)-(y)) * ((x)-(y))) #define AI_FLOAT_NEGATIVE_HALF (-0.5f + AI_FLOAT_EPSILON) #define AI_FLOAT_POSITIVE_HALF (0.5f) #define AI_MATH_ACOS(x) acosf(x) #define AI_MATH_ACOSH(x) acoshf(x) #define AI_MATH_ASIN(x) asinf(x) #define AI_MATH_ASINH(x) asinhf(x) #define AI_MATH_ATAN(x) atanf(x) #define AI_MATH_ATANH(x) atanhf(x) #define AI_MATH_COS(x) cosf(x) #define AI_MATH_COSH(x) coshf(x) #define AI_MATH_ERF(x) erff(x) #define AI_MATH_EXP(x) expf(x) #define AI_MATH_LOG(x) logf(x) #define AI_MATH_POW(x, e) powf((x), (e)) #define AI_MATH_RSQRT(x) (1.0f / AI_MATH_SQRT(x)) #define AI_MATH_SIN(x) sinf(x) #define AI_MATH_SINH(x) sinhf(x) #define AI_MATH_SQRT(x) ai_math_sqrt(x) #define AI_MATH_TAN(x) tanf(x) #define AI_MATH_TANH(x) tanhf(x) #define AI_MATH_SQUARE(x) AI_MATH_POW(x, 2.0f) #define AI_MATH_ACOS(x) acosf(x) #define AI_MATH_ACOSH(x) acoshf(x) #define AI_MATH_ASIN(x) asinf(x) #define AI_MATH_ASINH(x) asinhf(x) #define AI_MATH_ATAN(x) atanf(x) #define AI_MATH_ATANH(x) atanhf(x) #define AI_MATH_COS(x) cosf(x) #define AI_MATH_COSH(x) coshf(x) #define AI_MATH_ERF(x) erff(x) #define AI_MATH_EXP(x) expf(x) #define AI_MATH_LOG(x) logf(x) #define AI_MATH_POW(x, e) powf((x), (e)) #define AI_MATH_RSQRT(x) (1.0f / AI_MATH_SQRT(x)) #define AI_MATH_SIN(x) sinf(x) #define AI_MATH_SINH(x) sinhf(x) #define AI_MATH_SQRT(x) ai_math_sqrt(x) #define AI_MATH_TAN(x) tanf(x) #define AI_MATH_TANH(x) tanhf(x) #define AI_MATH_SQUARE(x) AI_MATH_POW(x, 2.0f) #define AI_MATH_RELU_TEST(x, thr, min, max) \ (((x)<=(thr)) ? (min) : (max)) #define AI_MATH_CLIP_LINEAR_REMAP(x, alpha, beta) \ (AI_MAX(0, AI_MIN(1, ((x) * (alpha) + (beta))))) #define AI_MATH_RELU_GENERIC(x, thr, alpha, max) \ AI_MATH_RELU_TEST(x, max, AI_MATH_RELU_GENERIC_NO_MAX(x, thr, alpha), max) #define AI_MATH_RELU_GENERIC_NO_MAX(x, thr, alpha) \ AI_MATH_RELU_TEST(x, thr, ((alpha)*((x)-(thr))), x) #define AI_MATH_RELU_THRESHOLDED(x, thr) \ AI_MATH_RELU_TEST(x, thr, 0, (x)) #define AI_MATH_LEAKY_RELU(x, neg_slope, pos_slope) \ AI_MATH_RELU_TEST(x, 0, (x)*(neg_slope), (x)*(pos_slope)) // ( ((x)>0) ? (x)*(pos_slope) : (x)*(neg_slope) ) #define AI_MATH_PRELU(x, slope) \ AI_MATH_RELU_TEST(x, 0, (x)*(slope), (x)) // AI_MATH_LEAKY_RELU(x, slope, 1) #define AI_MATH_RELU(x) \ AI_MATH_RELU_TEST(x, 0, 0, x) // AI_MAX(x, 0) #define AI_MATH_ELU(x, alpha) \ (AI_MAX(0.0f, (x)) + AI_MIN(0.0f, (alpha) * (AI_MATH_EXP(x)-1.0f))) #define AI_MATH_SELU(x, alpha, scale) \ ((scale)*AI_MATH_ELU(x, alpha)) #define AI_MATH_SCALED_TANH(x, alpha, beta) \ ((alpha)*AI_MATH_TANH((beta)*(x))) #define AI_MATH_SIGMOID(x) \ (1.0f / (1.0f + AI_MATH_EXP(-(x)))) #define AI_MATH_LOGISTIC(x)\ (x < 0) ? (1.0f -(1.0f / (1.0f + AI_MATH_EXP(-AI_ABS(x))))) :\ (1.0f / (1.0f + AI_MATH_EXP(-AI_ABS(x)))) #define AI_MATH_HARD_SIGMOID(x, alpha, beta) \ AI_MATH_CLIP_LINEAR_REMAP(x, alpha, beta) /* Formula with higher accuracy */ #define AI_MATH_SWISH(x) \ ((x) * AI_MATH_SIGMOID(x)) #define AI_MATH_HARD_SWISH(x) \ ((x) * AI_MATH_CLIP_LINEAR_REMAP(x, 1.0f/6, 0.5f)) #define AI_MATH_SOFT_PLUS(x) \ AI_MATH_LOG(1.0f + AI_MATH_EXP(x)) #define AI_MATH_SOFT_SIGN(x) \ ((x) / (1.0f + AI_ABS(x))) AI_API_DECLARE_BEGIN /*! * @brief platform optimized square root on a float value * @ingroup math_helpers * @param x input value * @return square root of the value */ AI_INTERFACE_ENTRY ai_float ai_math_sqrt(const ai_float x); AI_API_DECLARE_END #endif /* AI_LITE_MATH_HELPERS_H */
5,197
C
33.197368
79
0.556667
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_pad_dqnn.h
/** ****************************************************************************** * @file lite_pad_dqnn.h * @author AIS * @brief header file of AI platform lite padding kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_PADDING_DQNN_H #define LITE_PADDING_DQNN_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles padding with binary input and binary output - Lite I/F * @ingroup lite_padding_dqnn */ LITE_API_ENTRY void forward_lite_pad_is1os1(const ai_u32 *pDataIn_init, ai_u32 *pDataOut_init, const ai_i32 width_in, const ai_i32 width_out, const ai_i32 height_in, const ai_i32 height_out, const ai_u32 n_channel_out, const ai_i32 mode, const ai_u16 pads_x, const ai_u16 pads_y, const ai_u16 pads_x_r, const ai_u16 pads_y_b, const ai_u32 pad_value); #endif /*LITE_PADDING_DQNN_H*/
2,016
C
37.788461
80
0.381448
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_conv2d_dqnn.h
/** ****************************************************************************** * @file lite_conv2d_dqnn.h * @author AIS * @brief header file of AI platform lite conv kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_CONV2D_DQNN_H #define LITE_CONV2D_DQNN_H #pragma once #include "ai_lite_interface.h" # define AI_16_OVERFLOW_CHECK(val_) (val_ <= 32767) /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ AI_API_DECLARE_BEGIN /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os1ws1_bn_pad0(const ai_u32 *pDataIn_init, ai_u32 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Lite I/F * - Optimized thanks to Optim0 assumptions * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os1ws1_bn_pad0_optim0(const ai_u32 *pDataIn_init, ai_u32 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os8ws1_bn_pad0(const ai_u32 *pDataIn_init, ai_i8 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale, const ai_float *pOffset); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os1ws1_bn_pad1(const ai_u32 *pDataIn_init, ai_u32 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold, const ai_i32 pad_value); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * - Optimized thanks to Optim2 assumptions * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os1ws1_bn_pad1_optim2(const ai_u32 *pDataIn_init, ai_u32 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold, const ai_i32 pad_value); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os8ws1_bn_pad1(const ai_u32 *pDataIn_init, ai_i8 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale, const ai_float *pOffset, const ai_i32 pad_value); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * - Optimized thanks to Optim1 assumptions * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os8ws1_bn_pad1_optim1(const ai_u32 *pDataIn_init, ai_i8 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale, const ai_float *pOffset, const ai_i32 pad_value); /** * @brief Handles 2D convolution with binary input, fixed point 16-bits output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os16ws1_bn_pad0_fxp(const ai_u32 *pDataIn_init, ai_i16 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale_init, const ai_float *pOffset_init); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os16ws1_bn_pad1_fxp(const ai_u32 *pDataIn_init, ai_i16 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale_init, const ai_float *pOffset_init, const ai_i32 pad_value); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * - Optimized thanks to Optim1 assumptions * * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1os16ws1_bn_pad1_optim1_fxp(const ai_u32 *pDataIn_init, ai_i16 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale_init, const ai_float *pOffset_init, const ai_i32 pad_value); /** * @brief Handles 2D convolution with binary input, fixed point 16-bits unsigned output and * binary weights - with 0 padding (QKeras like) - Lite I/F * * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1ou16ws1_bn_pad1_fxp(const ai_u32 *pDataIn_init, ai_u16 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale_init, const ai_float *pOffset_init, const ai_i32 pad_value); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits unsigned output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1ou16ws1_bn_pad0_fxp(const ai_u32 *pDataIn_init, ai_u16 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale_init, const ai_float *pOffset_init); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits unsigned output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F. * - Optimized thanks to Optim1 assumptions * * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is1ou16ws1_bn_pad1_optim1_fxp(const ai_u32 *pDataIn_init, ai_u16 *pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_float *pScale_init, const ai_float *pOffset_init, const ai_i32 pad_value); /*! * @brief Handles 2D convolution with 8-bits quantized Input and weights and * binary output - Lite I/F * @ingroup lite_conv2d_dqnn * @param layer conv2d_dqnn layer */ LITE_API_ENTRY void forward_lite_conv2d_is8os1ws8(const ai_i8 *pDataIn_init, ai_u32 *pDataOut_init, const ai_i8 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold, const ai_i8 in_zeropoint); /*! * @brief Handles 2D convolution with 8-bits quantized Input and weights and * binary output - Lite I/F - Optimized thanks to Optim2 assumptions * @ingroup lite_conv2d_dqnn * @param layer conv2d_dqnn layer */ LITE_API_ENTRY void forward_lite_conv2d_is8os1ws8_optim2(const ai_i8 *pDataIn_init, ai_u32 *pDataOut_init, const ai_i8 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold, const ai_i8 in_zeropoint); /*! * @brief Handles 2D convolution with 8-bits quantized Input and weights and * binary output - quantized with DoReFa SotA quantizer, lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_dorefa_is8os1ws8(const ai_i8 *pDataIn_init, ai_u32 *pDataOut_init, const ai_u8 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold, const ai_i8 in_zeropoint); /*! * @brief Handles 2D convolution with 8-bits quantized input, output and weights * - quantized with with different quantization for channel * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is8os8ws8_sssa_ch(const ai_i8 *pData_in, ai_i8 *pData_out, const ai_i8 *pWeights, const ai_i32 *pBias, ai_u16 *pBuffer_a, const ai_size width_in, const ai_size height_in, const ai_size width_out, const ai_size height_out, const ai_u16 n_channel_in, const ai_u16 n_channel_out, const ai_size filt_width, const ai_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_float in_scale, const ai_float out_scale, const ai_float *pWt_scale, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_i32 scratch_size); /*! * @brief Handles 2D convolution with 16-bits quantized inputs, binary outputs and binary weights - Lite I/F. * Vanilla version. * @ingroup lite_conv2d_dqnn * @param layer conv2d_dqnn layer */ LITE_API_ENTRY void forward_lite_conv2d_is16os1ws1_bn_fxp(const ai_i16 *pIn, ai_u32 *pOut_32, const ai_u32 *pWeights, const ai_i32 *pThreshold, ai_i8 *pBufferA, const ai_i32 dim_kernel, const ai_i16 dim_im_in_x, const ai_i16 dim_im_in_y, const ai_i16 dim_im_out_x, const ai_i16 dim_im_out_y, const ai_i16 ch_im_in, const ai_i16 ch_im_out, const ai_i16 dim_kernel_x, const ai_i16 dim_kernel_y, const ai_i16 padding_x, const ai_i16 padding_y, const ai_i16 stride_x, const ai_i16 stride_y, const ai_i16 dilation_x, const ai_i16 dilation_y, const ai_i16 in_zeropoint); /** * @brief Handles 2D convolution with 16-bits quantized inputs, 16-bits quantized outputs and binary weights - Lite I/F * * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_conv2d_is16os16ws1_fxp(const ai_i16 *pIn, ai_i16 *pOut, const ai_u32 *pWeights, ai_i8 *pBufferA, const ai_i16 dim_im_in_x, const ai_i16 dim_im_in_y, const ai_i16 dim_im_out_x, const ai_i16 dim_im_out_y, const ai_i16 ch_im_in, const ai_i16 ch_im_out, const ai_u32 dim_kernel, const ai_i16 dim_kernel_x, const ai_i16 dim_kernel_y, const ai_i16 padding_x, const ai_i16 padding_y, const ai_i16 stride_x, const ai_i16 stride_y, const ai_i16 dilation_x, const ai_i16 dilation_y, const ai_i16 in_zeropoint); AI_API_DECLARE_END #endif /*LITE_CONV2D_DQNN_H*/
30,870
C
55.333942
119
0.351085
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/core_private.h
/** ****************************************************************************** * @file core_private.h * @author AST Embedded Analytics Research Platform * @brief private header file of common private core module defines ****************************************************************************** * @attention * * Copyright (c) 2019 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef CORE_PRIVATE_H #define CORE_PRIVATE_H #pragma once #include "ai_math_helpers.h" #include "ai_datatypes_internal.h" #include "core_log.h" /*! * @defgroup core_private Core Library Private macros and datatypes * @brief Common macros, datatypes and routines for core private rounites * @details This module contains the definitons and implementations of some * internal routines and datatypes that are supposed to not be exposed as * public headers. So usually this file should be include only on .c files or * headers that are private as well */ /*** Foreground Colors ****************************************************/ #define CORE_COLOR_BLACK "\x1b[30m" #define CORE_COLOR_RED "\x1b[31m" #define CORE_COLOR_GREEN "\x1b[32m" #define CORE_COLOR_YELLOW "\x1b[33m" #define CORE_COLOR_BLUE "\x1b[94m" #define CORE_COLOR_MAGENTA "\x1b[35m" #define CORE_COLOR_CYAN "\x1b[36m" #define CORE_COLOR_WHYTE "\x1b[37m" #define CORE_COLOR_DEFAULT "\x1b[39m" #define CORE_COLOR_LGRAY "\x1b[90m" #define CORE_COLOR_LRED "\x1b[91m" #define CORE_COLOR_LGREEN "\x1b[92m" #define CORE_COLOR_LYELLOW "\x1b[93m" #define CORE_COLOR_LBLUE "\x1b[94m" #define CORE_COLOR_LMAGENTA "\x1b[95m" #define CORE_COLOR_LCYAN "\x1b[96m" #define CORE_COLOR_LWHITE "\x1b[97m" /*** Text Attributes Colors *********************************************/ #define CORE_COLOR_OFF "\x1b[0m" #define CORE_COLOR_BOLD "\x1b[1m" #define CORE_COLOR_UNDERLINE "\x1b[4m" #define CORE_COLOR_BLINK "\x1b[5m" #define CORE_COLOR_BOLD_OFF "\x1b[21m" #define CORE_COLOR_UNDERLINE_OFF "\x1b[24m" #define CORE_COLOR_BLINK_OFF "\x1b[25m" /*** Background Colors ****************************************************/ #define CORE_COLOR_BG_BLACK "\x1b[40m" #define CORE_COLOR_BG_RED "\x1b[41m" #define CORE_COLOR_BG_GREEN "\x1b[42m" #define CORE_COLOR_BG_YELLOW "\x1b[43m" #define CORE_COLOR_BG_BLUE "\x1b[44m" #define CORE_COLOR_BG_MAGENTA "\x1b[45m" #define CORE_COLOR_BG_CYAN "\x1b[46m" #define CORE_COLOR_BG_WHITE "\x1b[47m" #define CORE_COLOR_BG_DEFAULT "\x1b[49m" #define CORE_COLOR_BG_LGRAY "\x1b[100m" #define CORE_COLOR_BG_LRED "\x1b[101m" #define CORE_COLOR_BG_LGREEN "\x1b[102m" #define CORE_COLOR_BG_LYELLOW "\x1b[103m" #define CORE_COLOR_BG_LBLUE "\x1b[104m" #define CORE_COLOR_BG_LMAGENTA "\x1b[105m" #define CORE_COLOR_BG_LCYAN "\x1b[106m" #define CORE_COLOR_BG_LWHITE "\x1b[107m" /*****************************************************************************/ #define CORE_ADDRESS_RANGE_INIT(start_, end_) \ core_address_range_init(start_, end_) #define CORE_GET_BUFFER_META_INFO(meta_info_, tensor_ptr_) \ core_get_buffer_meta_info(meta_info_, tensor_ptr_) #define CORE_ADDRESS_RANGE_END(range_) \ ( (ai_ptr)(((range_)->start)+((range_)->size)) ) #define CORE_ADDRESS_RANGE_OVERLAP(overlap_) \ ( ((overlap_)->start) && (((overlap_)->size)>0) ) #define CORE_ADDRESS_RANGE_OVERLAP_PARTIAL(overlap_, ref_) \ ( ((overlap_)->start) && (((overlap_)->size)<((ref_)->size)) ) #define CORE_MEMORY_OVERLAP_INIT(partial_, range_, chain_id_, tensor_id_) { \ .partial = (partial_), .range = AI_PACK(range_), \ .chain_id = (chain_id_), .tensor_id = (tensor_id_) \ } #define CORE_OFFSET(offset_, max_) \ ((ai_i32)(((offset_)<0) ? AI_MAX((max_) - (offset_), 0) : AI_MIN(offset_, max_))) /*****************************************************************************/ /** Network Context Handlers **/ /*****************************************************************************/ /*****************************************************************************/ /** Network Tensors Handlers **/ /*****************************************************************************/ #define AI_TENSOR_HAS_INTQ_INFO \ AI_BUFFER_META_HAS_INTQ_INFO #define CORE_TENSOR_GET_SHAPE_SIZE(tensor_) \ ai_shape_get_size(AI_TENSOR_SHAPE(tensor_)) #define CORE_ASSERT_SHAPE_MATCH(x, y) \ do { \ AI_ASSERT(AI_SHAPE_H(y) == 1 || AI_SHAPE_H(x)==1 || AI_SHAPE_H(y)==AI_SHAPE_H(x)) \ AI_ASSERT(AI_SHAPE_W(y) == 1 || AI_SHAPE_W(x)==1 || AI_SHAPE_W(y)==AI_SHAPE_W(x)) \ AI_ASSERT(AI_SHAPE_D(y) == 1 || AI_SHAPE_D(x)==1 || AI_SHAPE_D(y)==AI_SHAPE_D(x)) \ AI_ASSERT(AI_SHAPE_E(y) == 1 || AI_SHAPE_E(x)==1 || AI_SHAPE_E(y)==AI_SHAPE_E(x)) \ AI_ASSERT(AI_SHAPE_CH(y) == 1 || AI_SHAPE_CH(x)==1|| AI_SHAPE_CH(y)==AI_SHAPE_CH(x)) \ AI_ASSERT(AI_SHAPE_IN_CH(y) == 1 || AI_SHAPE_IN_CH(x)==1|| AI_SHAPE_IN_CH(y)==AI_SHAPE_IN_CH(x)) \ } while(0); #define AI_TENSOR_ARRAY_BYTE_SIZE(t_) \ AI_ARRAY_OBJ_BYTE_SIZE(AI_ARRAY_OBJ(t_->data)) #define AI_TENSOR_ARRAY_GET_DATA_ADDR(t_) \ AI_HANDLE_PTR(AI_ARRAY_OBJ_DATA_START(t_->data, void)) #define AI_TENSOR_ARRAY_UPDATE_DATA_ADDR(t_, addr_) \ { ai_array *arr_ = AI_ARRAY_OBJ(t_->data); \ const uintptr_t off_ = (uintptr_t)arr_->data - (uintptr_t)arr_->data_start; \ arr_->data_start = AI_PTR(addr_); \ arr_->data = AI_PTR((uintptr_t)addr_ + off_); \ } #define AI_TENSOR_INTEGER_GET_SIZE(t_) \ ((t_->klass) ? (AI_KLASS_GET_INTQ_INFO_LIST(t_))->size : 0) #define AI_TENSOR_INTEGER_GET_SCALE(t_, idx_) \ AI_INTQ_INFO_LIST_SCALE(AI_KLASS_GET_INTQ_INFO_LIST(t_), ai_float, idx_) #define AI_TENSOR_INTEGER_GET_ZEROPOINT_I8(t_, idx_) \ AI_INTQ_INFO_LIST_ZEROPOINT(AI_KLASS_GET_INTQ_INFO_LIST(t_), ai_i8, idx_) #define AI_TENSOR_INTEGER_GET_ZEROPOINT_U8(t_, idx_) \ AI_INTQ_INFO_LIST_ZEROPOINT(AI_KLASS_GET_INTQ_INFO_LIST(t_), ai_u8, idx_) #define AI_TENSOR_FMT_GET_SIGN(t_) \ AI_BUFFER_FMT_GET_SIGN(AI_ARRAY_OBJ(t_->data)->format) #define AI_TENSOR_FMT_GET_BITS(t_) \ AI_BUFFER_FMT_GET_BITS(AI_ARRAY_OBJ(t_->data)->format) #define AI_TENSOR_FMT_GET_FBITS(t_) \ AI_BUFFER_FMT_GET_FBITS(AI_ARRAY_OBJ(t_->data)->format) #define AI_TENSOR_FMT_GET_TYPE(t_) \ AI_BUFFER_FMT_GET_TYPE(AI_ARRAY_OBJ(t_->data)->format) #define AI_TENSOR_GET_FMT(t_) \ (AI_ARRAY_OBJ(t_->data)->format) /*****************************************************************************/ /** Network Buffers Handlers **/ /*****************************************************************************/ #define AI_FOR_EACH_BUFFER_ARRAY_ITEM(buffer_ptr_, buffer_array_ptr_, start_pos_, end_pos_) \ ai_buffer* buffer_ptr_ = AI_BUFFER_ARRAY_ITEM(buffer_array_ptr_, \ CORE_OFFSET(end_pos_, AI_BUFFER_ARRAY_SIZE(buffer_array_ptr_))); \ for ( ; buffer_ptr_ && AI_BUFFER_ARRAY_SIZE(buffer_array_ptr_) && \ (buffer_ptr_>=AI_BUFFER_ARRAY_ITEM(buffer_array_ptr_, \ CORE_OFFSET(start_pos_, AI_BUFFER_ARRAY_SIZE(buffer_array_ptr_)))); buffer_ptr_--) /*****************************************************************************/ /** Network Arrays Handlers **/ /*****************************************************************************/ #define AI_ARRAY_OBJ_FMT(array_) \ AI_CAST(ai_array_format, AI_ARRAY_OBJ(array_)->format) #define AI_ARRAY_OBJ_SIZE(array_) \ (AI_ARRAY_OBJ(array_)->size) #define AI_ARRAY_OBJ_BYTE_SIZE(array_) \ AI_SIZE(AI_ARRAY_GET_BYTE_SIZE(AI_ARRAY_OBJ_FMT(array_), \ AI_ARRAY_OBJ_SIZE(array_))) #define AI_ARRAY_OBJ_DATA_SIZE(array_) \ AI_ARRAY_GET_DATA_BYTE_SIZE(AI_ARRAY_OBJ_FMT(array_), \ AI_ARRAY_OBJ_SIZE(array_)) #define AI_ARRAY_OBJ_DATA(array_, type_) \ AI_CAST(type_*, AI_ARRAY_OBJ(array_)->data) #define AI_ARRAY_OBJ_DATA_START(array_, type_) \ AI_CAST(type_*, AI_ARRAY_OBJ(array_)->data_start) #define AI_ARRAY_OBJ_ELEM(array_, type_, pos_) \ AI_ARRAY_OBJ_DATA(array_, type_)[(pos_)] /*****************************************************************************/ /** Network Tensors Chains / Lists Handlers **/ /*****************************************************************************/ #define SET_TENSOR_IN(chain_, pos_) \ (GET_TENSOR_LIST_IN(chain_)->tensor[(pos_)]) #define SET_TENSOR_OUT(chain_, pos_) \ (GET_TENSOR_LIST_OUT(chain_)->tensor[(pos_)]) #define AI_NODE_IO_GET(node_, in_, out_) \ ASSERT_NODE_SANITY(node_) \ ai_tensor* in_ = GET_TENSOR_IN((node_)->tensors, 0); \ ai_tensor* out_ = GET_TENSOR_OUT((node_)->tensors, 0); \ ASSERT_TENSOR_SANITY(in_) \ ASSERT_TENSOR_SANITY(out_) /*****************************************************************************/ #define AI_BITS_TO_BYTES(bits_) \ (((bits_)+0x7) >> 3) #define AI_BYTES_TO_BITS(bytes_) \ ((bytes_) << 3) /*****************************************************************************/ /** Network Nodes Handlers **/ /*****************************************************************************/ #define AI_NODE_IS_FIRST(node) \ (AI_NODE_OBJ(node)==AI_NODE_OBJ(AI_NODE_OBJ(node)->network->input_node)) #define AI_NODE_IS_LAST(node_) \ ((AI_NODE_OBJ(node_)==AI_NODE_OBJ(node_)->next) || \ (AI_NODE_OBJ(node_)->next==NULL)) #define AI_FOR_EACH_NODE_DO(node_, nodes_) \ for (ai_node* node_ = AI_NODE_OBJ(nodes_); (node_); \ node_ = ((AI_NODE_IS_LAST(node_)) ? NULL : (node_)->next)) /*****************************************************************************/ typedef struct { ai_ptr start; ai_size size; } ai_address_range; typedef struct { ai_address_range range; ai_u16 chain_id; ai_u16 tensor_id; ai_bool partial; } ai_memory_overlap; /*****************************************************************************/ AI_DECLARE_STATIC ai_address_range core_address_range_init( const ai_handle start, const ai_handle end) { ai_address_range r; r.start = (start<end) ? start : end; r.size = (ai_size) ((start<end) ? ((ai_uptr)end-(ai_uptr)start) : ((ai_uptr)start-(ai_uptr)end)); return r; } AI_DECLARE_STATIC ai_buffer_meta_info* core_get_buffer_meta_info( ai_buffer_meta_info* meta, const ai_tensor* t) { if (!meta) return NULL; AI_ASSERT(t && t->data) ai_bool ok; meta->flags = 0x0; meta->intq_info = AI_KLASS_GET_INTQ_INFO_LIST(t); ok = (meta->intq_info && (meta->intq_info->size>0)); meta->flags |= (ok) ? AI_BUFFER_META_HAS_INTQ_INFO : 0x0; return (ok) ? meta : NULL; } #if 0 #include <stdio.h> #include <stdarg.h> AI_DECLARE_STATIC void _dump_file_print( const char* fname, const char* fmt, ...) { static FILE* fp = NULL; if (fname) { if (!fp) { fp = fopen(fname, "a"); } } if (fp) { va_list args; va_start(args, fmt); vfprintf(fp, fmt, args); va_end(args); fflush(fp); } } AI_DECLARE_STATIC void _dump_bytearray( const char* fname, const ai_handle src, const ai_size src_size, const ai_u8 src_id, const char* name) { static FILE* fp = NULL; if (fname && src && (src_size>0)) { if (!fp) { fp = fopen(fname, "a"); } } if (fp) { switch (src_id) { case 1: { const ai_float* src_value = (const ai_float*)src; fprintf(fp, "ai_float %s[%u] = {%f", name, src_size, src_value[0]); for (ai_size i=1; i<src_size; i++) { fprintf(fp, ", %f", src_value[i]); } } break; case 2: { const ai_i8* src_value = (const ai_i8*)src; fprintf(fp, "ai_i8 %s[%u] = {%d", name, src_size, src_value[0]); for (ai_size i=1; i<src_size; i++) { fprintf(fp, ", %d", src_value[i]); } } break; case 3: { const ai_u8* src_value = (const ai_u8*)src; fprintf(fp, "ai_u8 %s[%u] = {%u", name, src_size, src_value[0]); for (ai_size i=1; i<src_size; i++) { fprintf(fp, ", %u", src_value[i]); } } break; default: fprintf(fp, "format not supported: %u {", src_id); break; } fprintf(fp, "};\n"); fflush(fp); } } #endif #endif /* CORE_PRIVATE_H */
13,110
C
34.822404
114
0.510297
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_operators.h
#ifndef LITE_OPERATORS_H #define LITE_OPERATORS_H #pragma once #include "lite_bn_f32.h" #include "lite_bn_integer.h" #include "lite_conv2d.h" #include "lite_conv2d_dqnn.h" #include "lite_convert_dqnn.h" #include "lite_dense_if32.h" #include "lite_dense_is1.h" #include "lite_dense_is1ws1.h" #include "lite_dense_ws1.h" #include "lite_gru_f32.h" #include "lite_dw_dqnn.h" #include "lite_pw_dqnn.h" #include "lite_dense_is8os8ws8.h" #include "lite_generic_float.h" #include "lite_pool_f32.h" #include "lite_maxpool_dqnn.h" #include "lite_nl_generic_float.h" #include "lite_nl_generic_integer.h" #include "lite_pad_generic.h" #include "lite_pad_dqnn.h" #include "lite_upsample_generic.h" #endif /* LITE_OPERATORS_H */
718
C
23.793103
36
0.727019
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_norm.h
/** ****************************************************************************** * @file layers_norm.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform normalization layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_NORM_H #define LAYERS_NORM_H #pragma once #include "layers_common.h" /*! * @defgroup layers_norm Normalization Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_bn * @ingroup layers_norm * @brief Batch normalization (scale with bias) layer */ typedef ai_layer_base ai_layer_bn; /*! * @struct ai_layer_lrn * @ingroup layers_norm * @brief Local Response Normalization layer * * Divides each element by a scale factor computed */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_lrn_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_u32 local_size; /*!< size of the normalization window */ ai_float k; /*!< bias term */ ai_float alpha; /*!< input scale */ ai_float beta; /*!< scale exponent */ } ai_layer_lrn; /*! * @enum ai_norm_type_e * @ingroup layers_norm * @brief store the type of normalization algorithm to apply */ typedef enum ai_norm_type_ { NONE = 0, L1 = 1, L2 = 2, MAX = 3, } ai_norm_type_e; /*! * @struct ai_layer_norm * @ingroup layers_norm * @brief Lp Normalization layer * * Normalizes the tensor along the 'axis' direction using the Lp norm. * Optionally divides the result by the number of the elements. */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_norm_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_shape_idx axis; /*! normalization axis */ ai_float exponent; /*!< normalization exponent p */ ai_bool scale; /*!< multiplies by the pth root of the number of elements */ ai_norm_type_e norm_type; } ai_layer_norm; /*! * @brief Local response normalization computed on a float array * @ingroup layers_norm * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param pad amount of padding for the channels */ AI_INTERNAL_API void func_lrn_array_f32(ai_handle out, const ai_handle in, const ai_size in_size, const ai_size channel_size, const ai_i32 pad, const ai_float k, const ai_float alpha, const ai_float beta); /*! * @brief Lp normalization computed on a float array * @ingroup layers_norm * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param exponent p exponent for the Lp normalization * @param axis_stride stride (in array elements) of the normalization axis * @param axis_size size of the normalization axis * @param outer_size number of tensor slices (including the normalization axis) * on which compute the normalization */ AI_INTERNAL_API void func_norm_array_f32(ai_handle out, const ai_handle in, const ai_float exponent, const ai_float norm, const ai_size axis_stride, const ai_size axis_size, const ai_size outer_size); /*! * @brief Max normalization computed on float array * @ingroup layers_norm * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param axis_stride stride (in array elements) of the normalization axis * @param axis_size size of the normalization axis * @param outer_size number of tensor slices (including the normalization axis) */ AI_INTERNAL_API void func_norm_max_array_f32(ai_handle out, const ai_handle in, const ai_float norm, const ai_size axis_size, const ai_size n_el); /*! * @brief Fast L2 normalization computed on a float array * @ingroup layers_norm * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param axis_size size of the normalization axis * @param n_el total number of elements in the tensor */ AI_INTERNAL_API void func_norm_l2_fast_array_f32(ai_handle out, const ai_handle in, const ai_float norm, const ai_size axis_size, const ai_size outer_size); /*! * @brief Fast L1 normalization computed on a float array * @ingroup layers_norm * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param axis_size size of the normalization axis * @param n_el total number of elements in the tensor */ AI_INTERNAL_API void func_norm_l1_fast_array_f32(ai_handle out, const ai_handle in, const ai_float norm, const ai_size axis_size, const ai_size n_el); /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Computes the activations of a batchnorm (scale + bias) layer. * @ingroup layers_norm * @param layer the batch normalization (bn) layer */ AI_INTERNAL_API void forward_bn(ai_layer* layer); /*! * @brief Computes the activations of a batchnorm (scale + bias) layer with * integer format * @ingroup layers_norm * @param layer the batch normalization (bn) layer */ AI_INTERNAL_API void forward_bn_integer(ai_layer* layer); /*! * @brief Computes the activations of a Local Response Normalization Layer. * @ingroup layers_norm * @param layer the local response normalization (lrn) layer */ AI_INTERNAL_API void forward_lrn(ai_layer* layer); /*! * @brief Computes the activations of a normalization layer. * @ingroup layers_norm * @param layer the normalization (norm) layer */ AI_INTERNAL_API void forward_norm(ai_layer* layer); /*! * @brief Batch Normalization with 16-bit input, 16-bit threshold and binary output. * It is implemented using a threshold, and this is possible because the output is binary. * @param layer the batch normalization layer */ AI_INTERNAL_API void forward_bn_is16os1ws16(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_NORM_H*/
6,910
C
31.909524
97
0.612156
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_conv2d_dqnn.h
/** ****************************************************************************** * @file layers_conv2d_dqnn.h * @author AIS * @brief header file of AI platform DQNN conv datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_CONV2D_DQNN_H #define LAYERS_CONV2D_DQNN_H #pragma once #include "layers_common.h" #include "layers_conv2d.h" /*! * @defgroup layers_conv2d_dqnn Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN #define AI_DQNN_PAD_1_KEY (1) #define AI_DQNN_PAD_M1_KEY (-1) #define AI_DQNN_PAD_0_KEY (0) #define AI_DQNN_PAD_1_VALUE (0x0) #define AI_DQNN_PAD_M1_VALUE (0xFFFFFFFF) #define AI_DQNN_PAD_0_VALUE (0x2) /*! * @struct ai_layer_conv2d_dqnn * @ingroup layers_conv2d_dqnn * @brief conv2d_dqnn layer * * @ref forward_conv2d_is1os1ws1 */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_conv2d_dqnn_ { AI_LAYER_CONV2D_FIELDS_DECLARE ai_i32 pad_value; } ai_layer_conv2d_dqnn; /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles point wise convolution with binary input, binary output and * binary weights * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_pw_is1os1ws1_bn(ai_layer *pLayer); /*! * @brief Handles point wise convolution with binary input, binary output and * binary weights - Optimized thanks to Optim2 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_pw_is1os1ws1_bn_optim2(ai_layer *pLayer); /*! * @brief Handles point wise convolution with binary input, 8-bits output and * binary weights * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_pw_is1os8ws1_bn(ai_layer *pLayer); /*! * @brief Handles point wise convolution with binary input, 8-bits output and * binary weights - Optimized thanks to Optim1 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_pw_is1os8ws1_bn_optim1(ai_layer *pLayer); /*! * @brief Handles point-wise convolution with binary input, float32 output * and binary weights * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_pw_is1of32ws1_bn(ai_layer *pLayer); /*! * @brief Handles point-wise convolution with binary input, float32 output * and binary weights - Optimized thanks to Optim1 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_pw_is1of32ws1_bn_optim1(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os1ws1_bn(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - Optimized thanks to Optim2 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os1ws1_bn_optim2(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os8ws1_bn(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - Optimized thanks to Optim1 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os8ws1_bn_optim1(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os1ws1_bn_pad0(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Optimized thanks to * Optim0 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os1ws1_bn_pad0_optim0(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - with 0 padding (QKeras like) * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os8ws1_bn_pad0(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os1ws1_bn_pad1(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) - Optimized thanks * to Optim2 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os1ws1_bn_pad1_optim2(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - with +1/-1 padding (Larq like) * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os8ws1_bn_pad1(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - with +1/-1 padding (Larq like) - Optimized thanks * to Optim1 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is1os8ws1_bn_pad1_optim1(ai_layer *pLayer); /*! * @brief Handles 2D convolution with 8-bits quantized Input and weights and * binary output * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is8os1ws8(ai_layer *pLayer); /*! * @brief Handles 2D convolution with 8-bits quantized Input and weights and * binary output - Optimized thanks to Optim2 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is8os1ws8_optim2(ai_layer *pLayer); /*! * @brief Handles 2D convolution with 8-bits quantized Input and weights and * binary output - quantized with DoReFa SotA quantizer * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_dorefa_is8os1ws8(ai_layer *pLayer); /*! * @brief Handles 2D convolution with 16-bits quantized input, binary weights and binary output * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is16os1ws1_bn_fxp(ai_layer *pLayer); /*! * @brief Handles 2D convolution with 16-bits quantized input, binary weights and 16-bits quantized output * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is16os16ws1_fxp(ai_layer *pLayer); /*! * @brief Handles depth-wise convolution with binary input, binary output and * binary weights * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_dw_is1os1ws1_bn(ai_layer *pLayer); /*! * @brief Handles depth-wise convolution with binary input, binary output and * binary weights - Optimized thanks to Optim3 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_dw_is1os1ws1_bn_optim3(ai_layer *pLayer); /*! * @brief Handles depth-wise convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_dw_is1os1ws1_bn_pad0(ai_layer *pLayer); /*! * @brief Handles depth-wise convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Optimized thanks to * Optim3 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_dw_is1os1ws1_bn_pad0_optim3(ai_layer *pLayer); /*! * @brief Handles depth-wise convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_dw_is1os1ws1_bn_pad1(ai_layer *pLayer); /*! * @brief Handles depth-wise convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) - Optimized thanks to * Optim3 assumptions * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_dw_is1os1ws1_bn_pad1_optim3(ai_layer *pLayer); /*! * @brief Handles 2D convolution with 8-bits quantized Input and output and * binary weights * @ingroup layers_conv2d_dqnn * @param layer conv2d_dqnn layer */ AI_INTERNAL_API void forward_conv2d_is8os8ws1(ai_layer *pLayer); /** * @brief Handles 2D convolution with binary input, fixed point 16-bits output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is1os16ws1_bn_pad0_fxp(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is1os16ws1_bn_pad1_fxp(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * - Optimized thanks to Optim1 assumptions * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is1os16ws1_bn_pad1_optim1_fxp(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits unsigned output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is1ou16ws1_bn_pad0_fxp(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits unsigned output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * @ingroup lite_conv2d_dqnn * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is1ou16ws1_bn_pad1_fxp(ai_layer *pLayer); /*! * @brief Handles 2D convolution with binary input, fixed point 16-bits unsiged output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * - Optimized thanks to Optim1 assumptions * @ingroup lite_conv2d_dqnn * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is1ou16ws1_bn_pad1_optim1_fxp(ai_layer *pLayer); /*! * @brief Computes the activations of a integer quantized 2D convolutional layer * for SSSA per channel quantized RGB scheme using n_channel_in = 3 * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_conv2d_is8os8ws8_sssa_ch_rgb(const ai_i8 *pData_in, ai_i8 *pData_out, const ai_i8 *pWeights, const ai_i32 *pBias, ai_u16 *pBuffer_a, const ai_size width_in, const ai_size height_in, const ai_size width_out, const ai_size height_out, const ai_u16 n_channel_in, const ai_u16 n_channel_out, const ai_size filt_width, const ai_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_float in_scale, const ai_float out_scale, const ai_float *pWt_scale, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_bool out_ch_format, ai_i16 *p_out_r_shift, ai_i32 *p_out_factor); /*! * @brief Computes the activations of a point-wise integer quantized convolution for SSSA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_pw_is8os8ws8_sssa_ch(const ai_i8 *pData_in, ai_i8 *pData_out, const ai_i8 *pWeights, const ai_i32 *pBias, ai_u16 *pBuffer_a, const ai_size width_in, const ai_size height_in, const ai_size width_out, const ai_size height_out, const ai_u16 n_channel_in, const ai_u16 n_channel_out, const ai_size filt_width, const ai_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_float in_scale, const ai_float out_scale, const ai_float *pWt_scale, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, ai_i16 *p_out_r_shift, ai_i32 *p_out_factor, ai_i32 AI_PWOverlay, ai_i16 *bufferA, ai_i32 scratch_size); // st_nn_context_t context); /*! * @brief Computes the activations of a depth-wise integer quantized convolution for SSSA per channel quantized scheme * @ingroup layers_conv2d * @param layer the convolutional (conv) layer */ AI_INTERNAL_API void forward_dw_is8os8ws8_sssa_ch(const ai_i8 *pData_in, ai_i8 *pData_out, const ai_i8 *pWeights, const ai_i32 *pBias, ai_u16 *pBuffer_a, const ai_size width_in, const ai_size height_in, const ai_size width_out, const ai_size height_out, const ai_u16 n_channel_in, const ai_u16 n_channel_out, const ai_size filt_width, const ai_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_float in_scale, const ai_float out_scale, const ai_float *pWt_scale, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, ai_i16 *p_out_r_shift, ai_i32 *p_out_factor); AI_API_DECLARE_END #endif /*LAYERS_CONV2D_DQNN_H*/
17,573
C
34.647059
91
0.579981
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_upsample_generic.h
/** ****************************************************************************** * @file layers_upsample_generic.h * @author Cyril Enault * @brief header file of AI platform padding generic datatypes ****************************************************************************** * @attention * * Copyright (c) 2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_UPSAMPLE_H #define LAYERS_UPSAMPLE_H #pragma once #include "layers_generic.h" /*! * @defgroup layers_pad_generic Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles generic upsmapling in nearest mode * @ingroup layers_generic * @param layer upsample layer */ AI_INTERNAL_API void forward_upsample_nearest(ai_layer *pLayer); /*! * @brief Handles generic upsmapling in zeros mode * @ingroup layers_generic * @param layer upsample layer */ AI_INTERNAL_API void forward_upsample_zeros(ai_layer *pLayer); /*! * @brief Handles generic upsmapling in bilinear mode * @ingroup layers_generic * @param layer upsample layer */ AI_INTERNAL_API void forward_upsample_bilinear(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_PAD_GENERIC_H*/
1,845
C
26.552238
80
0.509485
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_bn_f32.h
#ifndef LITE_BN_F32_H #define LITE_BN_F32_H #pragma once #include "ai_lite_interface.h" /*! * @brief Forward function for a batch normalization (BN) layer with * signed float input, signed float output, and float parameters. * @ingroup lite_bn_f32 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param scale The pointer to BN scale param. * @param bias The pointer to bias. * @param n_elements The number of elements in the input tensor. * @param n_channel_in The number of channel in the input tensor. */ LITE_API_ENTRY void forward_lite_bn_if32of32wf32( ai_float* output, const ai_float* input, const ai_float* scale, const ai_float* bias, const ai_u32 n_elements, const ai_u32 n_channel_in); #endif /* LITE_BN_F32_H */
791
C
29.461537
69
0.718078
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_dense_is1ws1.h
#ifndef _LITE_DENSE_IS1WS1_H #define _LITE_DENSE_IS1WS1_H #pragma once #include "ai_lite_interface.h" /*! * @brief Forward function for a dense layer with signed binary input, * signed binary output, and signed binary weights. * @ingroup lite_dense_is1ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to bias (NULL if not available). * @param scratch The pointer to the scratch buffer. * @param n_channel_in The number of channels of the input. * @param n_channel_ouy The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is1os1ws1( ai_pbits *output, const ai_pbits *input, const ai_pbits *weights, const ai_pbits *bias, ai_i32 *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out ); /*! * @brief Forward function for a dense layer with signed binary input, * signed binary output, and signed binary weights. * The BN is fused, i.e., the layer requires weights, scale, and offset, where * weights are those of the dense layer, scale is that of the BN, and the offset * corresponds to dense bias * bn scale + bn offset. If the parameters do not * agree with such convention, the behavior is undefined. * @ingroup lite_dense_is1ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param scale The pointer to scale. * @param offset The pointer to offset. * @param scratch The pointer to the scratch buffer. * @param n_channel_in The number of channels of the input. * @param n_channel_ouy The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is1os1ws1_bn( ai_pbits *output, const ai_pbits *input, const ai_pbits *weights, const ai_float *scale, const ai_float *offset, ai_i32 *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out ); /*! * @brief Forward function for a dense layer with signed binary input, * signed binary output, and signed 16bit weights. * @ingroup lite_dense_is1ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to bias (NULL if not available). * @param scratch The pointer to the scratch buffer (signed 32bit). * @param n_channel_in The number of channels of the input. * @param n_channel_ouy The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is1os16ws1( ai_i16 *output, const ai_pbits *input, const ai_pbits *weights, const ai_pbits *bias, ai_i32 *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); /*! * @brief Forward function for a dense layer with signed binary input, * signed binary output, and signed 16bit weights. * The BN is fused, i.e., the layer requires weights, scale, and offset, where * weights are those of the dense layer, scale is that of the BN, and the offset * corresponds to dense bias * bn scale + bn offset. If the parameters do not * agree with such convention, the behavior is undefined. * @ingroup lite_dense_is1ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to bias (NULL if not available). * @param scratch The pointer to the scratch buffer (signed 32bit). * @param n_channel_in The number of channels of the input. * @param n_channel_ouy The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is1os16ws1_bn( ai_i16 *output, const ai_pbits *input, const ai_pbits *weights, const ai_float *scale, const ai_float *offset, ai_i32 *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); /*! * @brief Forward function for a dense layer with signed binary input, * signed float output, and signed binary weights. * @ingroup lite_dense_is1ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to bias (NULL if not available). * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_ouy The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is1of32ws1( ai_float *output, const ai_pbits *input, const ai_pbits *weights, const ai_pbits *bias, ai_i32 *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out ); /*! * @brief Forward function for a dense layer with signed binary input, * signed float output, and signed binary weights. * The BN is fused, i.e., the layer requires weights, scale, and offset, where * weights are those of the dense layer, scale is that of the BN, and the offset * corresponds to dense bias * bn scale + bn offset. If the parameters do not * agree with such convention, the behavior is undefined. * @ingroup lite_dense_is1ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param scale The pointer to scale. * @param offset The pointer to offset. * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is1of32ws1_bn( ai_float *output, const ai_pbits *input, const ai_pbits *weights, const ai_float *scale, const ai_float *offset, ai_i32 *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out ); #endif /*_LITE_DENSE_IS1WS1_H*/
5,999
C
40.666666
80
0.724287
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_custom.h
/** ****************************************************************************** * @file layers_custom.h * @author Marco Lattuada * @brief header file of AI platform custom layers datatype ****************************************************************************** * @attention * * Copyright (c) 2020 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_CUSTOM_H #define LAYERS_CUSTOM_H #pragma once #include "layers_common.h" /*! * @defgroup layers_custom Custom layer definitions * @brief Definition of structures custom layers */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_custom * @ingroup layers_custom * @brief Custom layer wrapper * * The custom layer wrapper */ typedef ai_layer_stateful ai_layer_custom; AI_API_DECLARE_END #endif /*LAYERS_CUSTOM_H*/
1,217
C
24.914893
80
0.518488
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_conv2d.h
/** ****************************************************************************** * @file lite_conv2d.h * @author AIS * @brief header file of AI platform lite conv2d kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_CONV2D_H #define LITE_CONV2D_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles 2D convolution with float input, float output and * float weights * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_if32of32wf32(const ai_float *pDataIn_init, ai_float *pDataOut_init, const ai_ptr_const pWeights_init, const ai_ptr_const pBias_init, const ai_size n_channel_in, const ai_size n_channel_out, const ai_size width_in, const ai_size height_in, const ai_size width_out, const ai_size height_out, const ai_size filt_width, const ai_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_size filt_height_dilated, const ai_size filt_width_dilated, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_size n_groups); /*! * @brief Handles 2D depthwise convolution with float input, float output and * float weights * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_dw_if32of32wf32(const ai_float *pDataIn_init, ai_float *pDataOut_init, const ai_ptr_const pWeights_init, const ai_ptr_const pBias_init, const ai_size n_channel_in, const ai_size n_channel_out, const ai_size width_in, const ai_size height_in, const ai_size width_out, const ai_size height_out, const ai_size filt_width, const ai_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_size filt_height_dilated, const ai_size filt_width_dilated, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_size n_groups); /*! * @brief Handles 2D grouped convolution with float input, float output and * float weights * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_if32of32wf32_group(const ai_float *pDataIn_init, ai_float *pDataOut_init, const ai_ptr_const pWeights_init, const ai_ptr_const pBias_init, const ai_size n_channel_in, const ai_size n_channel_out, const ai_size width_in, const ai_size height_in, const ai_size width_out, const ai_size height_out, const ai_size filt_width, const ai_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_size filt_height_dilated, const ai_size filt_width_dilated, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_size n_groups); /*! * @brief Handles dilated conv2d convolutions (valid padding) * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_dilated_sssa8_ch(const ai_i8 *pData_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 n_channel_in, const ai_i8 *pWeights, const ai_u16 n_channel_out, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_i32 *pBias, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_layer_format_type out_ch_format, ai_i8 *pData_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_u32 height_loop_cnt, const ai_u16 weights_prefetch_enabled, ai_i32 scratch_size, ai_i16 *pBuffer_a); /*! * @brief Handles conv2d convolutions (valid padding) with number of channels >= 8 * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_deep_sssa8_ch(const ai_i8 *pData_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 n_channel_in, const ai_i8 *pWeights, const ai_u16 n_channel_out, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_i32 *pBias, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_layer_format_type out_ch_format, ai_i8 *pData_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_u32 height_loop_cnt, const ai_u16 weights_prefetch_enabled, ai_i32 scratch_size, ai_i16 *pBuffer_a); /*! * @brief Handles conv2d convolutions (valid padding) with number of channels >= 8 * Special forward function for 3x3 kernels and Stride = 1 * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_deep_3x3_sssa8_ch(const ai_i8 *pData_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 n_channel_in, const ai_i8 *pWeights, const ai_u16 n_channel_out, const ai_i32 *pBias, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_layer_format_type out_ch_format, ai_i8 *pData_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_u32 height_loop_cnt, ai_i32 scratch_size, ai_i16 *pBuffer_a); /*! * @brief Handles conv2d convolutions with same padding or with number of channels < 8 * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_sssa8_ch(const ai_i8 *pData_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 n_channel_in, const ai_i8 *pWeights, const ai_u16 n_channel_out, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_i32 *pBias, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_layer_format_type out_ch_format, ai_i8 *pData_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, const ai_u16 weights_prefetch_enabled, ai_i32 scratch_size, ai_i16 *pBuffer_a); /*! * @brief Handles rgb conv2d convolutions * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_rgb_sssa8_ch(const ai_i8 *pData_in, const ai_u16 dim_im_in, const ai_i8 *pWeights, const ai_u16 n_channel_out, const ai_u16 dim_kernel, const ai_u16 padding, const ai_u16 stride, const ai_i32 *pBias, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_layer_format_type out_ch_format, ai_i8 *pData_out, const ai_u16 dim_im_out, ai_i32 scratch_size, ai_i16 *pBuffer_a); /*! * @brief Handles 2D convolution with float input, float output and * float weights with pool fused * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_if32of32wf32_pool(const ai_float *pDataIn_init, ai_float *pDataOut_init, const ai_float * pWeights_init, const ai_float *pBias_init, ai_float *pScratch_init, const ai_short_size n_channel_in, const ai_short_size n_channel_out, const ai_short_size width_in, const ai_short_size height_in, const ai_short_size width_out, const ai_short_size height_out, const ai_short_size filt_width, const ai_short_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_short_size filt_height_dilated, const ai_short_size filt_width_dilated, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_short_size n_groups, const ai_short_size width_conv_out, const ai_short_size height_conv_out, ai_handle pool_func, const ai_short_size pool_width, const ai_short_size pool_height, const ai_short_size pool_stride_x, const ai_short_size pool_stride_y, const ai_short_size pool_pad_x, const ai_short_size pool_pad_y); /*! * @brief Handles 2D depthwise convolution with float input, float output and * float weights with pool fused * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_dw_if32of32wf32_pool(const ai_float *pDataIn_init, ai_float *pDataOut_init, const ai_float *pWeights_init, const ai_float *pBias_init, ai_float *pScratch_init, const ai_short_size n_channel_in, const ai_short_size n_channel_out, const ai_short_size width_in, const ai_short_size height_in, const ai_short_size width_out, const ai_short_size height_out, const ai_short_size filt_width, const ai_short_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_short_size filt_height_dilated, const ai_short_size filt_width_dilated, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_short_size n_groups, const ai_short_size width_conv_out, const ai_short_size height_conv_out, ai_handle pool_func, const ai_short_size pool_width, const ai_short_size pool_height, const ai_short_size pool_stride_x, const ai_short_size pool_stride_y, const ai_short_size pool_pad_x, const ai_short_size pool_pad_y); /*! * @brief Handles 2D grouped convolution with float input, float output and * float weights with pool fused * @ingroup lite_conv2d */ LITE_API_ENTRY void forward_lite_conv2d_if32of32wf32_group_pool(const ai_float *pDataIn_init, ai_float *pDataOut_init, const ai_float *pWeights_init, const ai_float *pBias_init, ai_float *pScratch_init, const ai_short_size n_channel_in, const ai_short_size n_channel_out, const ai_short_size width_in, const ai_short_size height_in, const ai_short_size width_out, const ai_short_size height_out, const ai_short_size filt_width, const ai_short_size filt_height, const ai_u16 filt_pad_x, const ai_u16 filt_pad_y, const ai_u16 filt_stride_x, const ai_u16 filt_stride_y, const ai_short_size filt_height_dilated, const ai_short_size filt_width_dilated, const ai_u16 dilation_x, const ai_u16 dilation_y, const ai_short_size n_groups, const ai_short_size width_conv_out, const ai_short_size height_conv_out, ai_handle pool_func, const ai_short_size pool_width, const ai_short_size pool_height, const ai_short_size pool_stride_x, const ai_short_size pool_stride_y, const ai_short_size pool_pad_x, const ai_short_size pool_pad_y); #endif /*LITE_CONV2D_H*/
18,200
C
49.418282
86
0.398407
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_formats_converters.h
/** ****************************************************************************** * @file layers_formats_converters.h * @author AST Embedded Analytics Research Platform * @brief header file of formats converters layers ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_FORMATS_CONVERTERS_H #define LAYERS_FORMATS_CONVERTERS_H #pragma once #include "layers_common.h" /*! * @defgroup layers_formats_converters Formats Converters Layers Definition * @brief this group implements formats converter layers (cast, etc.) * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_cast * @ingroup layers_formats_converters * @brief C Implementation of cast layer */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_cast_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_array_format to_format; /*!< cast output format */ } ai_layer_cast; /*****************************************************************************/ /* Forward Functions Section */ /*****************************************************************************/ /*! * @brief forward function for cast layer. * @ingroup layers_ * @param layer template layer as an opaque pointer */ AI_INTERNAL_API void forward_cast(ai_layer* layer); AI_API_DECLARE_END #endif /*LAYERS_FORMATS_CONVERTERS_H*/
1,862
C
29.048387
80
0.50913
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_pool.h
/** ****************************************************************************** * @file layers_pool.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform pooling layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_POOL_H #define LAYERS_POOL_H #pragma once #include "layers_common.h" #include "lite_maxpool_dqnn.h" #include "lite_pool_f32.h" /*! * @defgroup layers_pool Pooling Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_pool * @ingroup layers_pool * @brief Pooling layer * * The type of pooling function is handled by the specific forward function * @ref forward_pool */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_pool_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_shape_2d pool_size; /*!< pooling size */ ai_shape_2d pool_stride; /*!< pooling stride */ ai_shape pool_pad; /*!< pooling pad, y,x border sizes */ ai_u8 count_include_pad; /*!< include pad flag */ } ai_layer_pool; /*! * @brief Max Pooling on a 8/16 bits fixed point data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to output data */ AI_INTERNAL_API void pool_func_mp_array_fixed(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /*! * @brief Max Pooling on a 8-bits integer quantized data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to output data */ AI_INTERNAL_API void pool_func_mp_array_integer(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /*! * @brief Max Pooling on a signed 8-bits integer quantized data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to output data */ AI_INTERNAL_API void pool_func_mp_array_integer_INT8(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /*! * @brief Max Pooling on a unsigned 8-bits integer quantized data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to output data */ AI_INTERNAL_API void pool_func_mp_array_integer_UINT8(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /*! * @brief Average Pooling on a 8/16 bits fixed point data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to scratch memory */ AI_INTERNAL_API void pool_func_ap_array_fixed(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /*! * @brief Average Pooling on a 8-bits integer quantized data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to scratch memory */ AI_INTERNAL_API void pool_func_ap_array_integer(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /*! * @brief Average Pooling on a signed 8-bits integer quantized data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to scratch memory */ AI_INTERNAL_API void pool_func_ap_array_integer_INT8(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /*! * @brief Average Pooling on a unsigned 8-bits integer quantized data array * @ingroup layers_pool * @param in opaque handler to input data to process * @param dim_im_in_x input feature map width * @param dim_im_in_y input feature map height * @param ch_im_in number of input channels * @param dim_kernel_x kernel width * @param dim_kernel_y kernel height * @param padding_x right padding value * @param padding_y top padding value * @param stride_x stride value on x dimension * @param stride_y stride value on y dimension * @param dim_im_out_x output feature map width * @param dim_im_out_y output feature map height * @param out opaque handler to scratch memory */ AI_INTERNAL_API void pool_func_ap_array_integer_UINT8(ai_handle in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, ai_handle out); /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Computes the activations of a max pooling layer. * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_mp(ai_layer* layer); /*! * @brief Computes the activations of a fixed point max pooling layer. * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_mp_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized max pooling layer. * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_mp_integer(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized max pooling layer * with int8 I/O * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_mp_integer_INT8(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized max pooling layer * with uint8 I/O * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_mp_integer_UINT8(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized max pooling layer * with int16 I/O * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_mp_integer_INT16(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized max pooling layer * with uint16 I/O * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_mp_integer_UINT16(ai_layer *pLayer); /*! * @brief Computes the activations of an average pooling layer. * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_ap(ai_layer* layer); /*! * @brief Computes the activations of a fixed point average pooling layer. * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_ap_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized average pooling layer. * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_ap_integer(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized average pooling layer * with int8 I/O * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_ap_integer_INT8(ai_layer *pLayer); /*! * @brief Computes the activations of an integer-quantized average pooling layer * with uint8 I/O * @ingroup layers_pool * @param layer the pooling (pool) layer */ AI_INTERNAL_API void forward_ap_integer_UINT8(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_POOL_H*/
14,171
C
36.294737
81
0.624656
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_pad_generic.h
/** ****************************************************************************** * @file layers_pad_generic.h * @author Marco Forleo * @brief header file of AI platform padding generic datatypes ****************************************************************************** * @attention * * Copyright (c) 2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_PADDING_DQNN_H #define LAYERS_PADDING_DQNN_H #pragma once #include "layers_generic.h" /*! * @defgroup layers_pad_generic Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles generic padding in constant mode * @ingroup layers_generic_dqnn * @param layer pad layer */ AI_INTERNAL_API void forward_pad_constant(ai_layer *pLayer); /*! * @brief Handles generic padding in edge mode * @ingroup layers_generic_dqnn * @param layer pad layer */ AI_INTERNAL_API void forward_pad_edge(ai_layer *pLayer); /*! * @brief Handles generic padding in reflect mode * @ingroup layers_generic_dqnn * @param layer pad layer */ AI_INTERNAL_API void forward_pad_reflect(ai_layer *pLayer); /*! * @brief Handles generic padding in constant mode Channel 1st 8bit * @ingroup layers_generic_dqnn * @param layer pad layer */ AI_INTERNAL_API void forward_pad_8bit_ch1st_3x3_constant(ai_layer* pLayer); AI_API_DECLARE_END #endif /*LAYERS_PAD_GENERIC_H*/
2,034
C
25.776315
80
0.525074
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_ml_treeensembleclassifier.h
/** ****************************************************************************** * @file layers_ml_treeensembleclassifier.h * @author AIS * @brief header file of AI platform TreeEnsembleClassifier datatypes ****************************************************************************** * @attention * * Copyright (c) 2021-2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_TREE_ENSEMBLE_CLASSIFIER_H #define LAYERS_TREE_ENSEMBLE_CLASSIFIER_H #pragma once #include "layers_common.h" #include "layers_nl.h" /*! * @defgroup layers_ml_treensembleclassifier Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /* Error return codes */ #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_NO 0 #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_WRONG_IDX_FMT -1 #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_UNFOUND_LEAF -2 #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_UNSUPPORTED_BRANCH -3 #define AI_TREE_ENSEMBLE_CLASSIFIER_ERROR_UNSUPPORTED_FEATURE -4 #define AI_TREE_ENSEMBLE_CLASSIFIER_DEPTH_MAX 10000 /* Type of condition in the TreeEnsembleClassifier*/ typedef enum { AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_LT_IDX = 0, AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_LEQ_IDX, AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_EQ_IDX, AI_TREE_ENSEMBLE_CLASSIFIER_BRANCH_END, } ai_tree_ensenble_classifier_branch_e; typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_tree_ensemble_classifier_ { AI_LAYER_COMMON_FIELDS_DECLARE func_nl nl_func; uint8_t all_weights_are_positive; ai_float nodes_values_scale; ai_float nodes_values_offset; ai_float class_weights_scale; ai_float class_weights_offset; } ai_layer_tree_ensemble_classifier; /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Decodes the TreeEnsembleClassifier ML operator. * @ingroup layers_svmreg * @param layer tree ensemble classifier layer */ AI_INTERNAL_API void forward_tree_ensemble_classifier(ai_layer *pLayer); AI_INTERNAL_API ai_i32 decodeEstimator_LEQ_8Bits(const ai_float *pDataIn, ai_float *pOutDataScores, const ai_u8 *pFeatureIdxForEstimator, const ai_float *pValuesForEstimator, const ai_u8 *pTrueIdxForEstimator, const ai_u8 *pFalseIdxForEstimator, const ai_handle pClassWeightsForEstimator, const ai_array_format classWeightsFormat, const ai_u8 *pClassNodeIdsForEstimator, const ai_u16 nbClassWithCurrentEstimator, const ai_u8 *pClassIdsForEstimator); AI_INTERNAL_API ai_i32 decodeEstimator_LEQ_16Bits(const ai_float *pDataIn, ai_float *pOutDataScores, const ai_u8 *pFeatureIdxForEstimator, const ai_float *pValuesForEstimator, const ai_u16 *pTrueIdxForEstimator, const ai_u16 *pFalseIdxForEstimator, ai_handle pClassWeightsForEstimator, const ai_array_format classWeightsFormat, const ai_u16 *pClassNodeIdsForEstimator, const ai_u16 nbClassWithCurrentEstimator, const ai_u16 *pClassIdsForEstimator); AI_API_DECLARE_END #endif /*LAYERS_TREE_ENSEMBLE_CLASSIFIER_H*/
4,238
C
36.513274
80
0.542237
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_dense_is8os8ws8.h
/** ****************************************************************************** * @file lite_dense_is8os8ws8.h * @author Marco Forleo * @brief header file of AI platform lite dense kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_DENSE_IS8OS8WS8_H #define LITE_DENSE_IS8OS8WS8_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Forward function for a dense layer with signed input, * signed output and signed weights all at 8 bits. * @ingroup lite_dense_is8os8ws8 * @param input The pointer to input buffer. * @param output The pointer to output buffer. * @param weights The pointer to weights. * @param bias The pointer to bias (NULL if not available). * @param in_zeropoint The value of the zero point of the input. * @param out_zeropoint TThe value of the zero point of the output. * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. * @param n_pixels Total number of pixels. */ LITE_API_ENTRY void forward_lite_dense_is8os8ws8(ai_i8 * pDataOut, const ai_i8 *pDataIn, const ai_i8 *pWeights, const ai_i32 *pBias, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_u16 n_channel_in, const ai_u16 n_channel_out, const ai_size n_pixels, const ai_float in_scale, const ai_float out_scale, const ai_float Wt_scale, ai_i16 *pBuffer_a); void forward_lite_dense_is8os8ws8_ch(ai_i8 * pDataOut, const ai_i8 *pDataIn, const ai_i8 *pWeights, const ai_i32 *pBias, const ai_i8 in_zeropoint, const ai_i8 out_zeropoint, const ai_u16 n_channel_in, const ai_u16 n_channel_out, const ai_size n_pixels, const ai_float in_scale, const ai_float out_scale, const ai_float *pWt_scale, ai_i16 *pBuffer_a); #endif /*LITE_DENSE_IS8OS8WS8_H*/
3,465
C
44.605263
80
0.43088
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_platform_interface.h
/** ****************************************************************************** * @file ai_platform_interface.h * @author AST Embedded Analytics Research Platform * @brief Definitions of AI platform interface APIs types ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_PLATFORM_INTERFACE_H #define AI_PLATFORM_INTERFACE_H #pragma once #include "ai_platform.h" #include "datatypes_network.h" #include "ai_datatypes.h" #include "ai_datatypes_format.h" /*! * @defgroup datatypes_interface Interface Datatypes * @brief Data structures and defines used to implement neural networks */ /******************************************************************************/ #define AI_ERROR_TRAP(net_, type_, code_) \ ai_platform_network_set_error((net_), AI_CONCAT(AI_ERROR_,type_), \ AI_CONCAT(AI_ERROR_CODE_,code_)) /*! AI_PTR HANDLERS SECTION ************************************/ #define AI_PTR(ptr_) AI_CAST(ai_ptr, ptr_) #define AI_PTR_CONST(ptr_) AI_CAST(ai_ptr_const, ptr_) /*! STATIC ARRAYS ALLOCATOR SECTION ************************************/ #define AI_PACK_STORAGE_ARRAY(type_, dim_, ...) \ (type_[dim_]) { AI_PACK(__VA_ARGS__) } /*! AI_STORAGE_KLASS SECTION ************************************/ #define AI_STORAGE_KLASS_PACK(type_, dim_, ...) \ AI_PACK_STORAGE_ARRAY(type_, dim_, __VA_ARGS__) #define AI_STORAGE_KLASS_INIT(type_, size_, data_) \ { \ .type = (type_), \ .size = (size_), \ .data = (ai_handle)(data_), \ } /*! * @enum ai_storage_klass_type * @ingroup ai_platform_interface * @brief @ref ai_storage_class types enum */ typedef enum { AI_STORAGE_KLASS_NONE = 0x00, AI_STORAGE_KLASS_SHAPE = 0x01, AI_STORAGE_KLASS_STRIDE = 0x02, } ai_storage_klass_type; /*! * @struct ai_storage_klass * @ingroup ai_platform_interface * @brief Generic "Template" klass for generic storage arrays containers * from this klass several typed containers are derived (see e.g. @ref ai_shape) */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_storage_klass_s { ai_u32 type : 8; ai_u32 size : 24; ai_handle data; } ai_storage_klass; AI_PACKED_STRUCT_END /*! AI_SHAPES SECTION ************************************/ #define AI_SHAPE_MAX_DIMENSION (6) #define AI_SHAPE_2D_INIT(w_, h_) \ { .data = { (w_), (h_) } } #define AI_SHAPE_INIT(dim_, ...) \ AI_STORAGE_KLASS_INIT( \ AI_STORAGE_KLASS_SHAPE, \ dim_, \ AI_STORAGE_KLASS_PACK(ai_shape_dimension, dim_, ## __VA_ARGS__)) #define AI_SHAPE_INIT_FROM_BUFFER(dim_, buffer_) \ AI_STORAGE_KLASS_INIT( \ AI_STORAGE_KLASS_SHAPE, \ dim_, \ buffer_) #define AI_SHAPE_ALLOCATE_STATIC(num_dim_) \ AI_SHAPE_INIT((num_dim_), 0) typedef ai_u8 ai_shape_idx; /*! * @struct ai_shape * @ingroup ai_platform_interface * @brief Dimensions for generic 4D tensors */ typedef ai_storage_klass ai_shape; /*! AI_STRIDES HANDLERS SECTION ************************************/ #define AI_STRIDE_INIT(dim_, ...) \ AI_STORAGE_KLASS_INIT( \ AI_STORAGE_KLASS_STRIDE, \ dim_, \ AI_STORAGE_KLASS_PACK(ai_stride_dimension, dim_, ## __VA_ARGS__)) #define AI_STRIDE_INIT_FROM_BUFFER(dim_, buffer_) \ AI_STORAGE_KLASS_INIT( \ AI_STORAGE_KLASS_STRIDE, \ dim_, \ buffer_) #define AI_STRIDE_ALLOCATE_STATIC(num_dims_) \ AI_STRIDE_INIT((num_dims_), 0) /*! * @struct ai_stride * @ingroup ai_platform_interface * @brief Stride dimensions for generic 4D tensors (in number of elements) */ typedef ai_storage_klass ai_stride; /*! BASIC_TYPES HANDLERS SECTION ************************************/ #define AI_SIZE(value_) \ AI_CAST(ai_size, value_) /*! AI_KLASS_OBJ HANDLERS SECTION ************************************/ #define AI_KLASS_OBJ(obj_) \ AI_CAST(ai_klass_obj, obj_) /*! GENERIC HANDLERS SECTION ************************************/ #define AI_OBJ_DATA(obj_, type_) \ AI_CAST(type_, (obj_)->data) /*! AI_BUFFER HANDLERS SECTION ************************************/ #define AI_BUFFER_OBJ(ptr_) \ AI_CAST(ai_buffer*, ptr_) /*! AI_ARRAY HANDLERS SECTION ************************************/ #define AI_ARRAY_OBJ(ptr_) \ AI_CAST(ai_array*, ptr_) #define AI_ARRAY_OBJ_INIT_STATIC(type_, format_, size_, ...) { \ .format = AI_FMT_OBJ(format_), \ .size = (ai_array_size)(size_), \ .data = (ai_ptr)((type_[]){ __VA_ARGS__ }), \ .data_start = AI_PTR(0), \ } #define AI_ARRAY_OBJ_INIT(format_, data_, data_start_, size_) { \ .format = AI_FMT_OBJ(format_), \ .size = AI_CAST(ai_array_size, size_), \ .data = AI_PTR(data_), \ .data_start = AI_PTR(data_start_) } #define AI_ARRAY_OBJ_DECLARE_STATIC(name_, type_, format_, attr_, size_, ...) \ AI_ALIGNED(4) \ attr_ ai_array name_ = AI_ARRAY_OBJ_INIT_STATIC(type_, format_, size_, __VA_ARGS__); #define AI_ARRAY_OBJ_DECLARE(name_, format_, data_, data_start_, size_, attr_) \ AI_ALIGNED(4) \ attr_ ai_array name_ = AI_ARRAY_OBJ_INIT(format_, data_, data_start_, size_); /********************************* ai_array macros ***************************/ #define AI_PACK_ARRAYS(...) \ (ai_array[]) { AI_PACK(__VA_ARGS__) } #define AI_ARRAY_LIST_OBJ_INIT(arrays_ptr_) \ ((ai_array*)(arrays_ptr_)) #define AI_ARRAY_LIST_FLAGS(list_) \ ((list_) ? (list_)->flags : 0x0) #define AI_ARRAY_LIST_SIZE(list_) \ ((list_) ? (list_)->size : 0) #define AI_ARRAY_LIST_DATA(list_, pos_) \ ((list_) ? &((list_)->data[pos_]) : NULL) /********************************* ai_tensor macros **************************/ #define AI_TENSOR_OBJ(obj_) \ AI_CAST(ai_tensor*, obj_) #define AI_TENSOR_INFO_OBJ_INIT(id_, flags_, data_size_) { \ .id = (id_), \ .flags = (flags_), \ .data_size = (data_size_) \ } #define AI_TENSOR_OBJ_INIT(id_, flags_, shape_, stride_, arrays_size_, arrays_ptr_, klass_obj_) { \ .klass = (ai_klass_obj)(klass_obj_), \ .info = AI_TENSOR_INFO_OBJ_INIT(id_, flags_, arrays_size_), \ .shape = shape_, \ .stride = stride_, \ .data = AI_ARRAY_LIST_OBJ_INIT(AI_PACK(arrays_ptr_)), \ } #define AI_TENSOR_OBJ_DECLARE(name_, attr_, id_, flags_, shape_, stride_, \ arrays_size_, arrays_ptr_, klass_obj_) \ AI_ALIGNED(4) \ attr_ ai_tensor name_ = AI_TENSOR_OBJ_INIT(id_, flags_, AI_PACK(shape_), AI_PACK(stride_), \ arrays_size_, AI_PACK(arrays_ptr_), AI_PACK(klass_obj_)); /********************************* TENSOR STATE MACROS ***********************/ #define AI_TENSOR_STATE_OBJ_INIT(end_ptr_ , curr_ptr_, stride_, size_) \ { (end_ptr_), (curr_ptr_), (stride_), (size_) } /********************************* TENSOR LIST MACROS ************************/ #if (AI_TOOLS_API_VERSION <= AI_TOOLS_API_VERSION_1_3) #pragma message ("Including deprecated AI_TENSOR_LIST_ENTRY, AI_TENSOR_LIST_EMPTY, AI_TENSOR_LIST_IO_ENTRY") AI_DEPRECATED #define AI_TENSOR_LIST_EMPTY \ AI_TENSOR_LIST_OBJ_EMPTY AI_DEPRECATED #define AI_TENSOR_LIST_ENTRY(...) \ AI_TENSOR_LIST_OBJ_INIT(AI_FLAG_NONE, AI_NUMARGS(__VA_ARGS__), __VA_ARGS__) AI_DEPRECATED #define AI_TENSOR_LIST_IO_ENTRY(flags_, size_, ...) \ AI_TENSOR_LIST_IO_OBJ_INIT(flags_, size_, __VA_ARGS__) #endif /* AI_TOOLS_API_VERSION_1_3 */ #define AI_TENSOR_LIST_OBJ_INIT(flags_, size_, ...) \ { .size = (size_), .flags = (flags_), \ .tensor = (ai_tensor*[]) { __VA_ARGS__ }, .info = NULL \ } #define AI_TENSOR_LIST_OBJ_EMPTY \ { .size = 0, .flags = AI_FLAG_NONE, \ .tensor = (ai_tensor*[]) { NULL }, .info = NULL \ } #define AI_TENSOR_LIST_OBJ_DECLARE(name_, attr_, flags_, size_, ...) \ AI_ALIGNED(4) \ attr_ ai_tensor_list name_ = AI_TENSOR_LIST_OBJ_INIT( \ flags_, size_, __VA_ARGS__); /********************************* TENSOR LIST I/O MACROS ********************/ #define AI_TENSOR_LIST_IO_OBJ_INIT(flags_, size_, ...) \ { .size = (size_), .flags = (flags_), \ .tensor = (ai_tensor*[]) { __VA_ARGS__ }, \ .info = (ai_tensor_list_info[1]) { { \ .buffer = (ai_buffer[size_]){AI_STRUCT_INIT}, \ .state = (ai_tensor_state[size_]){AI_STRUCT_INIT}, \ .meta = (ai_buffer_meta_info[size_]){AI_STRUCT_INIT} \ } } \ } /********************************* TENSOR CHAIN MACROS ***********************/ #define AI_TENSOR_CHAIN_OBJ_INIT(flags_, size_, ...) \ { .size = (size_), .flags = (flags_), \ .chain = (ai_tensor_list[]){ __VA_ARGS__ } } #define AI_TENSOR_CHAIN_OBJ_DECLARE(name_, attr_, size_, ...) \ AI_ALIGNED(4) \ attr_ ai_tensor_chain name_ = \ AI_TENSOR_CHAIN_OBJ_INIT(AI_FLAG_NONE, size_, __VA_ARGS__); /********************************* TENSOR CHAIN I/O MACROS *******************/ #define AI_TENSOR_CHAIN_IO_OBJ_INIT(flags_, in_tensor_list_, out_tensor_list_) \ { .chain = (ai_tensor_list[]){ in_tensor_list_, out_tensor_list_ }, \ .size = 2, .flags = (flags_) } #define AI_TENSOR_CHAIN_IO_OBJ_DECLARE( \ name_, attr_, flags_, in_tensor_list_, out_tensor_list_) \ AI_ALIGNED(4) \ attr_ ai_tensor_chain_io name_ = \ AI_TENSOR_CHAIN_IO_OBJ_INIT(flags_, in_tensor_list_, out_tensor_list_); /******************************* NETWORK SECTION ****************************/ #define AI_NETWORK_OBJ(obj_) \ ((ai_network*)(obj_)) #if (AI_TOOLS_API_VERSION < AI_TOOLS_API_VERSION_1_5) AI_DEPRECATED #define AI_NETWORK_OBJ_INIT( \ weights_buffer_, activations_buffer_, \ in_tensor_list_ptr_, out_tensor_list_ptr_, \ in_node_ptr_, signature_, klass_obj_) { \ .magic = 0x0, \ .signature = signature_, \ .klass = AI_KLASS_OBJ(klass_obj_), \ .flags = AI_FLAG_NONE, \ .error = AI_ERROR_INIT(NONE, NONE), \ .n_batches = 0, \ .batch_id = 0, \ .buffers = AI_NETWORK_BUFFERS_INIT( \ AI_BUFFER_ARRAY_OBJ_INIT_STATIC(AI_FLAG_NONE, 1, AI_PACK(weights_buffer_)), \ AI_BUFFER_ARRAY_OBJ_INIT_STATIC(AI_FLAG_NONE, 1, AI_PACK(activations_buffer_))), \ .tensors = AI_TENSOR_CHAIN_IO_OBJ_INIT(AI_FLAG_NONE, \ AI_PACK(in_tensor_list_ptr_), \ AI_PACK(out_tensor_list_ptr_)), \ .input_node = AI_NODE_OBJ(in_node_ptr_), \ .current_node = AI_NODE_OBJ(NULL), \ .on_node_exec = NULL, \ .data_exec = NULL, \ .lite_cb = NULL, \ } #else #define AI_NETWORK_OBJ_INIT( \ weights_buffer_, activations_buffer_, \ in_tensor_list_ptr_, out_tensor_list_ptr_, \ in_node_ptr_, signature_, klass_obj_) { \ .magic = 0x0, \ .signature = signature_, \ .klass = AI_KLASS_OBJ(klass_obj_), \ .flags = AI_FLAG_NONE, \ .error = AI_ERROR_INIT(NONE, NONE), \ .n_batches = 0, \ .batch_id = 0, \ .buffers = AI_NETWORK_BUFFERS_INIT(AI_PACK(weights_buffer_), \ AI_PACK(activations_buffer_)), \ .tensors = AI_TENSOR_CHAIN_IO_OBJ_INIT(AI_FLAG_NONE, \ AI_PACK(in_tensor_list_ptr_), \ AI_PACK(out_tensor_list_ptr_)), \ .input_node = AI_NODE_OBJ(in_node_ptr_), \ .current_node = AI_NODE_OBJ(NULL), \ .on_node_exec = NULL, \ .data_exec = NULL, \ .lite_cb = NULL, \ } #endif // AI_TOOLS_API_VERSION #define AI_NETWORK_OBJ_DECLARE( \ name_, attr_, \ weights_buffer_, activations_buffer_, \ in_tensor_list_ptr_, out_tensor_list_ptr_, \ in_node_ptr_, signature_, klass_obj_) \ AI_ALIGNED(4) \ attr_ ai_network name_ = AI_NETWORK_OBJ_INIT( \ AI_PACK(weights_buffer_), \ AI_PACK(activations_buffer_), \ AI_PACK(in_tensor_list_ptr_), \ AI_PACK(out_tensor_list_ptr_), \ (in_node_ptr_), (signature_), (klass_obj_)); #define AI_NETWORK_ACQUIRE_CTX(handle_) \ AI_NETWORK_OBJ(ai_platform_context_acquire(handle_)) /******************************************************************************/ AI_API_DECLARE_BEGIN /*! * @typedef ai_version * @ingroup ai_platform_interface * @brief Packed representation for @ref ai_platform_version */ typedef uint32_t ai_version; /*! * @typedef ai_klass_obj * @ingroup ai_platform_interface * @brief handler to (private) generic subclass derivatives implementation */ typedef void* ai_klass_obj; /*! * @typedef ai_ptr * @ingroup ai_platform_interface * @brief Byte pointer data addressing */ typedef uint8_t* ai_ptr; /*! * @typedef ai_ptr_const * @ingroup ai_platform_interface * @brief Constant byte pointer data addressing */ typedef const uint8_t* ai_ptr_const; /*! * @typedef ai_ptr_offset * @ingroup ai_platform_interface * @brief byte offset for computing strides */ typedef int32_t ai_ptr_offset; /*! * @typedef ai_magic * @ingroup ai_platform_interface * @brief magic field to mark internal datatstructures */ typedef uint32_t ai_magic; /*! * @typedef ai_any_ptr * @ingroup ai_platform_interface * @brief union for defining any pointer */ typedef union { ai_handle handle; ai_ptr ptr; ai_float* float32; ai_double* float64; ai_u8* u8; ai_i8* s8; ai_u16* u16; ai_i16* s16; ai_u32* u32; ai_i32* s32; ai_u64* u64; ai_i64* s64; } ai_any_ptr; #define AI_ANY_PTR_INIT(ptr_) \ { .handle = (ai_handle)(ptr_) } #define AI_CONTEXT_FIELDS \ ai_magic magic; /*!< magic word to mark valid contexts datastructs*/ \ ai_signature signature; /*!< 32bit signature for network consistency checks */ #define AI_CONTEXT_OBJ(obj) ((ai_context*)(obj)) /*! * @typedef ai_context * @ingroup ai_platform_interface * @brief Abstract internal context header exposed to codegen interface */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_context_ { AI_CONTEXT_FIELDS } ai_context; AI_PACKED_STRUCT_END /*! * @enum ai_shape_2d_type * @ingroup ai_platform_interface * @brief Codes for the 2D tensor dimensions */ typedef enum { AI_SHAPE_2D_MAX_DIMENSION = 0x2, AI_SHAPE_2D_HEIGHT = 0x1, AI_SHAPE_2D_WIDTH = 0x0, } ai_shape_2d_type; /*! * @struct ai_shape_2d * @ingroup ai_platform_interface * @brief Dimensions for generic 2D tensors */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_shape_2d_s { ai_shape_dimension data[AI_SHAPE_2D_MAX_DIMENSION]; /*!< 2D tensor dimensions */ } ai_shape_2d; AI_PACKED_STRUCT_END /*! * @struct ai_array * @ingroup ai_platform_interface * @brief Generic flattened array with size * and (byte) stride of each item */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_array_s { ai_array_format format; /*!< array format (see @ref ai_array_format) */ ai_array_size size; /*!< number of elements in the array (NOT number of bytes!). The size of the array could be determine using @ref AI_ARRAY_GET_BYTE_SIZE macro */ ai_ptr data; /*!< pointer to data */ ai_ptr data_start; /*!< pointer to parent's data start address */ } ai_array; AI_PACKED_STRUCT_END /*! * @struct ai_tensor_info * @ingroup ai_platform_interface * @brief ai_tensor_info info structure for storing size of the array list, * tensor dimensionality, etc. * */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_tensor_info_s { ai_u16 id; ai_u8 flags; ai_u8 data_size; } ai_tensor_info; AI_PACKED_STRUCT_END /*! * @struct ai_tensor * @ingroup ai_platform_interface * @brief Generic tensor structure for storing parameters and activations * * The data is stored in a flattened array with an implicit order given by the * reverse order in @ref ai_shape_dimension: * in_channels, channels, width, height. */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_tensor_s { ai_klass_obj klass; /*!< opaque pointer to klass context */ ai_tensor_info info; /*!< tensor info metadata see @ref ai_tensor_info)*/ ai_shape shape; /*!< tensor shape see @ref ai_shape */ ai_stride stride; /*!< tensor stride see @ref ai_stride */ ai_array* data; /*!< flattened array pointer to tensor data */ } ai_tensor; AI_PACKED_STRUCT_END /*! * @struct ai_tensor_state * @ingroup ai_platform_interface * @brief state context for tensor management (used for I/O network tensors) */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_tensor_state_s { ai_ptr end_ptr; /*!< end address of the I/O tensor data buffer */ ai_ptr curr_ptr; /*!< current address of the I/O tensor data buffer (for batching) */ ai_ptr_offset stride; /*!< single batch buffer size (in bytes) */ ai_size size; /*!< total size in bytes of the I/O tensor buffer */ } ai_tensor_state; AI_PACKED_STRUCT_END /*! * @struct ai_tensor_list_info * @ingroup ai_platform_interface * @brief info metadata for tensor list management (used for I/O network tensors) */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_tensor_list_info_s { ai_tensor_state* state; /*!< I/O buffer internal pointers state */ ai_buffer* buffer; /*!< I/O buffer pointer */ ai_buffer_meta_info* meta; /*!< I/O buffer meta informations */ } ai_tensor_list_info; AI_PACKED_STRUCT_END /********************************* INTEGER QUANTIZATION DATATYPES ************/ #define AI_INTQ_INFO_OBJ_INIT(flags_, scale_ , zeropoint_) { \ .scale = (scale_), \ .zeropoint = (ai_handle)(zeropoint_), \ .flags = (flags_), \ } #define AI_PACK_INTQ_INFO_LIST(...) \ (ai_intq_info_list[]) { AI_PACK(__VA_ARGS__) } #define AI_PACK_INTQ_INFO(scale_, zp_) \ (INTQ_CONST ai_intq_info[1]) { { \ .scale = (INTQ_CONST ai_float*) AI_PACK(scale_), \ .zeropoint = (ai_handle) AI_PACK(zp_) \ } } #define AI_PACK_INTQ_SCALE(...) \ (INTQ_CONST ai_float[]) { AI_PACK(__VA_ARGS__) } #define AI_PACK_INTQ_ZP(...) \ (INTQ_CONST ai_i8[]) { AI_PACK(__VA_ARGS__) } #define AI_PACK_UINTQ_ZP(...) \ (INTQ_CONST ai_u8[]) { AI_PACK(__VA_ARGS__) } #define AI_PACK_INTQ_ZP16(...) \ (INTQ_CONST ai_i16[]) { AI_PACK(__VA_ARGS__) } #define AI_PACK_UINTQ_ZP16(...) \ (INTQ_CONST ai_u16[]) { AI_PACK(__VA_ARGS__) } #define AI_INTQ_INFO_LIST_OBJ_INIT(flags_, size_, info_) \ { \ .flags = (flags_), \ .size = (size_), \ .info = (info_), \ } #define AI_INTQ_INFO_LIST_OBJ_EMPTY { 0 } #define AI_INTQ_INFO_LIST_OBJ_DECLARE(name_, attr_, flags_, size_, info_) \ AI_ALIGNED(4) \ attr_ ai_intq_info_list name_ = \ AI_INTQ_INFO_LIST_OBJ_INIT(flags_, size_, AI_PACK(info_)); #define AI_INTQ_INFO_LIST_OBJ_DECLARE_EMPTY(name_, attr_) \ AI_ALIGNED(4) \ attr_ ai_intq_info_list name_ = AI_INTQ_INFO_LIST_OBJ_EMPTY; /********************************* TENSOR CHAINS DATATYPES *******************/ /*! * @enum ai_tensor_chain_type * @ingroup ai_platform_interface * @brief Enum for the different tensor chains supported in the library */ typedef enum { AI_TENSOR_CHAIN_INPUT = 0x0, AI_TENSOR_CHAIN_OUTPUT = 0x1, AI_TENSOR_CHAIN_WEIGHTS = 0x2, AI_TENSOR_CHAIN_SCRATCH = 0x3, AI_TENSOR_CHAIN_SIZE } ai_tensor_chain_type; /*! * @struct ai_tensor_list * @ingroup ai_platform_interface * @brief list (in form of arrays) of internal nodes tensor pointers */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_tensor_list_s { ai_u16 size; /*!< number of elements in the the tensor list */ ai_u16 flags; /*!< optional flags to store tensor list attributes */ ai_tensor** tensor; /*!< array of linked tensor pointer */ ai_tensor_list_info* info; /*!< pointer to an array of metainfo associated to the tensors */ } ai_tensor_list; AI_PACKED_STRUCT_END /*! * @struct ai_tensor_chain * @ingroup ai_platform_interface * @brief tensor chain datastruct for internal network nodes */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_tensor_chain_s { ai_u16 size; ai_u16 flags; ai_tensor_list* chain; /*!< pointer to a 4 sized array see @ref ai_tensor_chain_type */ } ai_tensor_chain; AI_PACKED_STRUCT_END /************************************** LAYER DATATYPES *******************/ /*! * @struct ai_layer * @ingroup ai_platform_interface * @brief Structure encoding a generic opaque layer in the network * */ typedef void ai_layer; /************************************** OBSERVER DATATYPES *******************/ /* forward function */ struct ai_node_s; /*! * @struct ai_observer_node * @ingroup ai_observer_interface * @brief observer node data struct for internal network nodes */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_observer_node_s { ai_u16 c_idx; /*!< node index (position in the execution list) */ ai_u16 type; /*!< node type info @see ai_node datastruct */ ai_u16 id; /*!< node id assigned by codegen tool to identify the model layer*/ ai_u16 unused; /*!< unused field for alignment */ const ai_tensor_chain* inner_tensors; /*!< pointer to the inner tensor if available */ const ai_tensor_chain* tensors; /*!< pointer to a 4 sized array see @ref ai_tensor_chain_type */ } ai_observer_node; AI_PACKED_STRUCT_END #define AI_OBSERVER_NONE_EVT (0) /*!< No event */ #define AI_OBSERVER_INIT_EVT (1 << 0) /*!< called at the end of the init function */ #define AI_OBSERVER_PRE_EVT (1 << 1) /*!< before c-node execution */ #define AI_OBSERVER_POST_EVT (1 << 2) /*!< after c-node execution */ #define AI_OBSERVER_FIRST_EVT (1 << 8) /*!< indicate the first c-node */ #define AI_OBSERVER_LAST_EVT (1 << 9) /*!< indicate the last c-node */ #define AI_OBSERVER_REGISTERED (1 << 24) /*!< internal flag */ #define AI_OBSERVER_MASK_EVT (0xFF) /*!< mask for requested user event */ /* Client callback definition */ typedef ai_u32 (*ai_observer_node_cb)( const ai_handle cookie, const ai_u32 flags, const ai_observer_node *node); AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_observer_exec_ctx_s { ai_observer_node_cb on_node; /*!< registered user observer call-back function */ ai_handle cookie; /*!< reference of the user context */ ai_u32 flags; /*!< flags definition */ ai_u16 c_idx; /*!< store/indicate the index of the current c_node */ ai_u16 n_nodes; /*!< total number of c_node */ struct ai_node_s *cur; /*!< pointer of the current node (pre or post) */ } ai_observer_exec_ctx; AI_PACKED_STRUCT_END typedef enum { AI_NODE_EXEC_INIT = 0x0, AI_NODE_EXEC_START = 0x1, AI_NODE_EXEC_PRE = 0x2, AI_NODE_EXEC_POST = 0x3, } ai_node_exec_state; /* Internal/private definition of node execution callback */ typedef ai_u32 (*ai_node_exec_cb)( const ai_node_exec_state state, struct ai_node_s *cur, const ai_handle ctx); /********************************* NETWORK DATATYPES *************************/ /*! * @struct ai_network * @ingroup layers * @brief Structure encoding a sequential neural network */ AI_PACKED_STRUCT_START typedef AI_ALIGNED_TYPE(struct, 4) AI_PACKED ai_network_s { AI_CONTEXT_FIELDS ai_klass_obj klass; /*!< opaque handler to specific network implementations */ ai_flags flags; /*!< bitflags mask to track some network state info */ ai_error error; /*!< track 1st error code in the network */ ai_u16 n_batches; /*!< number of batches to process */ ai_u16 batch_id; /*!< current batch to to process btw [0, n_batches)*/ // New 6.1 context storing explicitly network buffers. This allow also management of network persistent state now ai_network_buffers buffers; /*!< network buffers datastruct */ ai_tensor_chain tensors; /*!< I/O tensor chain list see @ref ai_tensor_list */ struct ai_node_s* input_node; /*!< first node to execute */ struct ai_node_s* current_node; /*!< current node to execute */ ai_node_exec_cb on_node_exec; /*!< registered call-back function called when a node/operator is scheduled */ ai_handle data_exec; /*!< private reference for the runtime context */ ai_handle lite_cb; /*!< registered opaque call-back handler for lite APIs */ ai_version tool_api_version; /*! Tools Codegen API version */ } ai_network; AI_PACKED_STRUCT_END /*! * @brief Get platform runtime lib revision version as string. * @ingroup ai_platform_interface * @return a string containing the revision of the runtime library */ AI_INTERFACE_TYPE const char* ai_platform_runtime_get_revision(void); /*! * @brief Get platform runtime lib version as datastruct. * @ingroup ai_platform_interface * @return a datastruct containing the version of the runtime library */ AI_INTERFACE_TYPE ai_platform_version ai_platform_runtime_get_version(void); /*! * @brief Get platform public APIs version as datastruct. * @ingroup ai_platform_interface * @return a datastruct containing the version of the public APIs */ AI_INTERFACE_TYPE ai_platform_version ai_platform_api_get_version(void); /*! * @brief Get platform interface private APIs version as datastruct. * @ingroup ai_platform_interface * @return a datastruct containing the version of the interface private APIs */ AI_INTERFACE_TYPE ai_platform_version ai_platform_interface_api_get_version(void); /**************************************************************************** ** Context APIs ****************************************************************************/ /*! * @brief Get platform context. * @ingroup ai_platform_interface * @return a valid context handle or NULL otherwise */ AI_INTERFACE_TYPE ai_context* ai_platform_context_acquire(const ai_handle handle); /*! * @brief Release platform context. * @ingroup ai_platform_interface * @return an opaque handle to the released object */ AI_INTERFACE_TYPE ai_handle ai_platform_context_release(ai_context* ctx); /**************************************************************************** ** Platform Network Params APIs ****************************************************************************/ /*! * @brief get the weights map from user provided network params info * @ingroup ai_platform_interface * @param params a pointer to ai_network_params struct * @param map table pointer to the table map to initialize * @param map_size the number of entries of the table to initialize * @return true if initialization succeeded, false otherwise */ AI_INTERFACE_TYPE ai_bool ai_platform_get_weights_map( ai_ptr* map, const ai_size map_size, const ai_network_params* params); /*! * @brief get the activations map from user provided network params info * @ingroup ai_platform_interface * @param params a pointer to ai_network_params struct * @param map table pointer to the table map to initialize * @param map_size the number of entries of the table to initialize * @return true if initialization succeeded, false otherwise */ AI_INTERFACE_TYPE ai_bool ai_platform_get_activations_map( ai_ptr* map, const ai_size map_size, const ai_network_params* params); /*! * @brief bind code generated weights and activations map arrays to ai_netwoek_params * @ingroup ai_platform_interface * @param[out] params the network params struct reporting binded params * @param[in] map_weights pointer to the codegened weights map array to be bound * @param[in] map_activations pointer to the codegened activation map array to be bound * @return true if network parameters binding succeed, false otherwise */ AI_INTERFACE_TYPE ai_bool ai_platform_bind_network_params( ai_network_params* params, const ai_buffer_array* map_weights, const ai_buffer_array* map_activations); /**************************************************************************** ** Platform Network APIs ****************************************************************************/ /*! * @brief get **first** error tracked when using the network * @ingroup ai_platform_interface * @param network an opaque handler to the network context * @return ai_error the FIRST error generated during network processing */ AI_INTERFACE_TYPE ai_error ai_platform_network_get_error(ai_handle network); /*! * @brief Set specific error code of the network. if an error is already present * keep it * @ingroup ai_platform_interface * @param net_ctx a pointer to the network context * @param type error type as defined in @ref ai_error_type * @param code error code as defined in @ref ai_error_code * @return true if no previous errors where recorded, false if a previous error * is present or context is invalid */ AI_INTERFACE_TYPE ai_bool ai_platform_network_set_error( ai_network* net_ctx, const ai_error_type type, const ai_error_code code); /*! * @brief Finalize network report datastruct with I/O buffer infos * @ingroup ai_platform_interface * @return bool if the report has been finalized correctly. false otherwise */ AI_INTERFACE_TYPE ai_bool ai_platform_api_get_network_report( ai_handle network, ai_network_report* r); /*! * @brief Get network inputs array pointer as a ai_buffer array pointer. * @ingroup network * @param network an opaque handler to the network context * @param n_buffer optional parameter to return the number of inputs * @return a ai_buffer pointer to the inputs arrays */ AI_INTERFACE_TYPE ai_buffer* ai_platform_inputs_get(ai_handle network, ai_u16 *n_buffer); /*! * @brief Get network outputs array pointer as a ai_buffer array pointer. * @ingroup network * @param network an opaque handler to the network context * @param n_buffer optional parameter to return the number of outputs * @return a ai_buffer pointer to the inputs arrays */ AI_INTERFACE_TYPE ai_buffer* ai_platform_outputs_get(ai_handle network, ai_u16 *n_buffer); /*! * @brief create a network context with some error check * @ingroup ai_platform_interface * @param a pointer to an opaque handle of the network context * @param an (optional) pointer to the network config buffer info * @param net_ctx a pointer to the network context structure to initialize * @param tool_major major version id of the tool used to generate the network * @param tool_minor minor version id of the tool used to generate the network * @param tool_micro micro version id of the tool used to generate the network * @return the error during network creation or error none if ok */ AI_INTERFACE_TYPE ai_error ai_platform_network_create( ai_handle* network, const ai_buffer* network_config, ai_network* net_ctx, const ai_u8 tool_major, const ai_u8 tool_minor, const ai_u8 tool_micro); /*! * @brief destroy a network context * @ingroup ai_platform_interface * @param network a pointer to an opaque handle of the network context * @return AI_HANDLE_NULL if deallocation OK, same network handle if failed */ AI_INTERFACE_TYPE ai_handle ai_platform_network_destroy(ai_handle network); /*! * @brief initialize the network context * @ingroup ai_platform_interface * @param network a pointer to an opaque handle of the network context * @return a valid network context, NULL if initialization failed */ AI_INTERFACE_TYPE ai_network* ai_platform_network_init( ai_handle network, const ai_network_params* params); /*! * @brief post-initialize of the network context. * @ingroup ai_platform_interface * @param network a pointer to an opaque handle of the network context * @return a valid network context, NULL if initialization failed */ AI_INTERFACE_TYPE ai_bool ai_platform_network_post_init(ai_handle network); /*! * @brief main platform runtime execute of a network * @ingroup ai_platform_interface * @param network an opaque handler to the network context * @param input a pointer to the input buffer data to process * @param output a pointer to the output buffer * @return the number of batches processed from the input. A result <=0 in case * of error */ AI_INTERFACE_TYPE ai_i32 ai_platform_network_process( ai_handle network, const ai_buffer* input, ai_buffer* output); /**************************************************************************** ** Observer APIs ****************************************************************************/ /*! * @brief Return the info of a requested c-node (defined by the * c_idx field). Should be called after the initialization phase. * @ingroup ai_platform_observer * @param network a pointer to an opaque handle of the network context * @param node_info a pointer to a reference of the node description * @return true if the node_info->c_idx designates a valid index else * false (network error is updated). */ AI_INTERFACE_TYPE ai_bool ai_platform_observer_node_info( ai_handle network, ai_observer_node *node_info); /*! * @brief Register an observer context. Allows to register a client CB which * will be called before or/and after the execution of a c-node with * the references of the used tensors (see @ref ai_observer_node). * @ingroup ai_platform_observer * @param network a pointer to an opaque handle of the network context * @param cb reference of the user callback function * @param cookie reference of a user object/ctx * @param flags indicate expected events (see AI_OBSERVER_XX_EVT flag definition) * @return false if the registration has failed (network error is updated) else true * of error. */ AI_INTERFACE_TYPE ai_bool ai_platform_observer_register( ai_handle network, ai_observer_node_cb cb, ai_handle cookie, ai_u32 flags); AI_INTERFACE_TYPE ai_bool ai_platform_observer_register_s(ai_handle network, ai_observer_exec_ctx *ctx); /*! * @brief un-register the observer context. * @ingroup ai_platform_observer * @param network a pointer to an opaque handle of the network context * @param ctx a pointer to a reference of the registered platform observer context * @param cb reference of the registered user callback function * @param cookie reference of the registered user object/ctx * @return false if the un-registration has failed (network error is updated) else true * of error. */ AI_INTERFACE_TYPE ai_bool ai_platform_observer_unregister(ai_handle network, ai_observer_node_cb cb, ai_handle cookie); AI_INTERFACE_TYPE ai_bool ai_platform_observer_unregister_s(ai_handle network, ai_observer_exec_ctx *ctx); AI_API_DECLARE_END #endif /*AI_PLATFORM_INTERFACE_H*/
35,318
C
33.091699
115
0.615012
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/core_common.h
/** ****************************************************************************** * @file core_common.h * @author AST Embedded Analytics Research Platform * @brief header file of common core datatypes ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef CORE_COMMON_H #define CORE_COMMON_H #pragma once #include "ai_platform.h" #include "ai_platform_interface.h" #include "core_datatypes.h" // #include "core_log.h" /*! * @defgroup core_common Common Core Library Routines * @brief Common macros, datatypes and routines of core common module * @details This module contains the definitons and handling of the @ref ai_node * datastructures. An ai_node is a generic abstraction for a network node that * could be either a fixed function layer or an operator. Ideally the platform * interface defined in api module should handle an process generic nodes in the * network, not relying on the fact that they are layers or operators datastructs * Specific implementative details should be kept inside layers and operators * modules. The core module implements additionally common routines used in the * layers and operators modules. */ /******************************************************************************/ #ifdef HAS_AI_ASSERT #define ASSERT_ARRAY_SANITY(a_) \ AI_ASSERT((a_) && (a_)->size>0) #define ASSERT_ARRAY_DATA_SANITY(a_) \ ASSERT_ARRAY_SANITY(a_) \ AI_ASSERT((a_)->data && (a_)->data_start) #define ASSERT_TENSOR_SANITY(t_) \ AI_ASSERT((t_) && (t_)->data) \ AI_ASSERT(CORE_TENSOR_GET_SHAPE_SIZE(t_)>0) \ ASSERT_ARRAY_SANITY((t_)->data) #define ASSERT_TENSOR_LIST_SANITY(tlist_) \ AI_ASSERT((tlist_) && (GET_TENSOR_LIST_SIZE(tlist_)>0)) \ #define ASSERT_TENSOR_DATA_SANITY(t_) \ ASSERT_TENSOR_SANITY(t_) \ ASSERT_ARRAY_DATA_SANITY((t_)->data) #define ASSERT_NODE_SANITY(node_) \ do { \ AI_ASSERT(AI_NODE_OBJ(node_)->tensors && AI_NODE_OBJ(node_)->tensors->chain) \ ASSERT_TENSOR_SANITY(GET_TENSOR_IN(AI_NODE_OBJ(node_)->tensors, 0)) \ ASSERT_TENSOR_SANITY(GET_TENSOR_OUT(AI_NODE_OBJ(node_)->tensors, 0)) \ } while (0); #else #define ASSERT_ARRAY_SANITY(a_) /* ASSERT_ARRAY_SANITY */ #define ASSERT_ARRAY_DATA_SANITY(a_) /* ASSERT_ARRAY_DATA_SANITY */ #define ASSERT_TENSOR_SANITY(t_) /* ASSERT_TENSOR_SANITY */ #define ASSERT_TENSOR_LIST_SANITY(tlist_) /* ASSERT_TENSOR_LIST_SANITY */ #define ASSERT_TENSOR_DATA_SANITY(t_) /* ASSERT_TENSOR_DATA_SANITY */ #define ASSERT_NODE_SANITY(node_) /* ASSERT_NODE_SANITY */ #endif /*HAS_AI_ASSERT*/ #if defined(__GNUC__) || defined(__clang__) /* Suppress unused function warnings */ #define AI_UNUSED_FUNCTION __attribute__((unused)) /* Manage false positives in address sanitizer */ #define AI_NO_SANITIZE_ADDRESS __attribute__((no_sanitize_address)) #else #define AI_UNUSED_FUNCTION /* AI_UNUSED_FUNCTION */ #define AI_NO_SANITIZE_ADDRESS /* AI_NO_SANITIZE_ADDRESS */ #endif /******************************************************************************/ #define AI_NODE_TYPE(type_) \ ((ai_node_type)((ai_u32)(type_)&0xFFFF)) #define AI_NODE_OBJ(obj_) \ ((ai_node*)(obj_)) #define AI_NODE_FUNC(func_) \ ((node_func)(func_)) #define AI_NODE_COMMON_FIELDS_DECLARE \ ai_node_type type; /*!< node type id (see @ref ai_node_type) */ \ ai_id_obj id; /*!< node object instance id (see @ref ai_id_obj) */ \ ai_flags flags; /*!< node object flags */ \ ai_klass_obj klass; /*!< opaque handler to specific layer implementations */ \ struct ai_network_s* network; /*!< handle to global network context */ \ struct ai_node_s* next; /*!< the next node object in the sequence */ \ node_func forward; /*!< forward function for the node */ \ AI_CONST ai_tensor_chain* tensors; /*!< pointer to node tensor chain */ #define AI_NODE_STATEFUL_FIELDS_DECLARE \ AI_NODE_COMMON_FIELDS_DECLARE \ ai_handle state; \ node_func init; \ node_func update; \ node_func destroy; #define AI_NODE_COMMON_INIT(type_, id_, flags_, klass_, network_, next_, forward_) \ .type = AI_NODE_TYPE(type_), \ .id = AI_ID_OBJ(id_), \ .flags = (flags_), \ .klass = AI_KLASS_OBJ(klass_), \ .network = AI_NETWORK_OBJ(network_), \ .next = AI_NODE_OBJ(next_), \ .forward = AI_NODE_FUNC(forward_) /*****************************************************************************/ /** Network Tensors Chains / Lists Handlers **/ /*****************************************************************************/ #define AI_FOR_EACH_TENSOR_CHAIN_DO(tlist_ptr_, chain_) \ ai_tensor_list* tlist_ptr_ = (chain_)->chain; \ for (; tlist_ptr_<(((chain_)->chain)+((chain_)->size)); tlist_ptr_++) #define AI_FOR_EACH_TENSOR_LIST_DO(idx_, t_ptr_, tlist_ptr_) \ ai_tensor* t_ptr_ = NULL; \ for (ai_size idx_ = 0; (idx_ < GET_TENSOR_LIST_SIZE(tlist_ptr_)) && \ ((t_ptr_ = GET_TENSOR_LIST_ITEM(tlist_ptr_, idx_)) != NULL); ++idx_) #define GET_TENSOR_LIST_INFO(list_) \ ((list_)->info) #define GET_TENSOR_LIST_META(list_, pos_) \ (&(GET_TENSOR_LIST_INFO(list_)->meta[pos_])) #define GET_TENSOR_LIST_STATE(list_, pos_) \ (&(GET_TENSOR_LIST_INFO(list_)->state[pos_])) #define GET_TENSOR_LIST_BUFFER(list_, pos_) \ (&(GET_TENSOR_LIST_INFO(list_)->buffer[pos_])) #define GET_TENSOR_LIST_ITEM(list_, pos_) \ ((NULL!=GET_TENSOR_LIST_ITEMS(list_)) \ ? GET_TENSOR_LIST_ITEMS(list_)[(pos_)] : NULL) #define GET_TENSOR_LIST_ITEMS(list_) \ ((list_)->tensor) #define GET_TENSOR_LIST_SIZE(list_) \ ((NULL!=(list_)) ? (list_)->size : 0) #define GET_TENSOR_CHAIN_SIZE(chain_) \ ((NULL!=(chain_)) ? (chain_)->size : 0) #define GET_TENSOR_LIST(chain_, type_) \ ((AI_CONCAT(AI_TENSOR_CHAIN_, type_)<(chain_)->size) \ ? &(chain_)->chain[AI_CONCAT(AI_TENSOR_CHAIN_, type_)] : NULL) #define GET_TENSOR_LIST_IN(chain_) \ (GET_TENSOR_LIST(chain_, INPUT)) #define GET_TENSOR_LIST_OUT(chain_) \ (GET_TENSOR_LIST(chain_, OUTPUT)) #define GET_TENSOR_LIST_WEIGTHS(chain_) \ (GET_TENSOR_LIST(chain_, WEIGHTS)) #define GET_TENSOR_LIST_SCRATCH(chain_) \ (GET_TENSOR_LIST(chain_, SCRATCH)) #define GET_TENSOR_IN(chain_, pos_) \ (GET_TENSOR_LIST_ITEM(GET_TENSOR_LIST_IN(chain_), (pos_))) #define GET_TENSOR_OUT(chain_, pos_) \ (GET_TENSOR_LIST_ITEM(GET_TENSOR_LIST_OUT(chain_), (pos_))) #define GET_TENSOR_WEIGHTS(chain_, pos_) \ (GET_TENSOR_LIST_ITEM(GET_TENSOR_LIST_WEIGTHS(chain_), (pos_))) #define GET_TENSOR_SCRATCH(chain_, pos_) \ (GET_TENSOR_LIST_ITEM(GET_TENSOR_LIST_SCRATCH(chain_), (pos_))) /******************************************************************************/ #if 1 #define SECTION_SERIAL(expr) expr #define SECTION_PARALLEL(expr) #else #define SECTION_SERIAL(expr) #define SECTION_PARALLEL(expr) expr #endif AI_API_DECLARE_BEGIN /*! * @struct ai_node_type * @ingroup core_common * @brief generic network node numeric type ID * */ typedef uint16_t ai_node_type; /*! * @typedef void (*node_func)(struct ai_node_s* node) * @ingroup core_common * @brief Callback signatures for all forward functions */ typedef void (*node_func)(struct ai_node_s* node); /*! * @typedef ai_float (*func_nl_el)(const ai_float x) * @ingroup core_common * @brief Fuction pointer for generic elementwise transforms * * This function pointer abstracts a generic nonlinear function applied to a * single element. See @ref ai_math_sqrt in @ref math_helpers as examples. */ typedef ai_float (*func_nl_el)(const ai_float x); /*! * @struct ai_node * @ingroup core_common * @brief Structure encoding a generic node of the network * * The node struct includes information about the network it belong to, the * next node in a sequential network and the forward function. The forward * functions are implemented in the @ref layers module. */ typedef AI_ALIGNED_TYPE(struct, 4) ai_node_s { AI_NODE_COMMON_FIELDS_DECLARE } ai_node; /*! * @struct ai_node_stateful * @ingroup core_common * @brief Structure encoding a stateful node of the network * * The node struct includes information about the network it belong to, the * next node in a sequential network and the init, update and forward functions. * The node functions are implemented in the @ref layers module. */ typedef AI_ALIGNED_TYPE(struct, 4) ai_node_stateful_s { AI_NODE_STATEFUL_FIELDS_DECLARE } ai_node_stateful; /*! * @brief initialize core module * @ingroup core_common * @return false if initialization fails, false otherwise */ AI_INTERNAL_API ai_bool core_init(void); /*! * @brief get 1st error raised during processing * @ingroup core_common * @param[out] error the @ref ai_error recorded during processing * @return the 1st error generated during processing. If no errors AI_ERROR_NONE */ AI_INTERNAL_API ai_error core_get_error(ai_error* error); /*! * @brief set error recorded during processing * @ingroup core_common * @param[out] error the @ref ai_error to set * @param[in] type the specific error type to set * @param[in] code the specific error code to set * @return true if the error is set, false in case a precedent error was already */ AI_INTERNAL_API ai_bool core_set_error( ai_error* error, const ai_error_type type, const ai_error_code code); AI_API_DECLARE_END #endif /*CORE_COMMON_H*/
9,995
C
33.588235
92
0.615408
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers.h
/** ****************************************************************************** * @file layers.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_H #define LAYERS_H #pragma once #include "layers_common.h" #include "layers_conv2d.h" #include "layers_custom.h" #include "layers_dense.h" #include "layers_formats_converters.h" #include "layers_generic.h" #include "layers_lite_graph.h" #include "layers_nl.h" #include "layers_norm.h" #include "layers_pad_dqnn.h" #include "layers_pad_generic.h" #include "layers_pool.h" #include "layers_rnn.h" #include "layers_upsample_generic.h" #include "layers_sm.h" #include "layers_ml.h" #include "layers_ml_iforest.h" #include "layers_ml_svc.h" #include "layers_ml.h" #include "layers_ml_linearclassifier.h" #include "layers_ml_treeensembleclassifier.h" #include "layers_ml_treeensembleregressor.h" #include "layers_ml_svmregressor.h" #include "layers_conv2d_dqnn.h" #include "layers_dense_dqnn.h" #include "layers_pool_dqnn.h" #include "layers_generic_dqnn.h" #include "layers_upsample_generic.h" // #include "layers_template.h" AI_API_DECLARE_BEGIN /*! * @struct ai_any_layer_ptr * @ingroup layers * @brief Generic union for typed layers pointers */ typedef struct { ai_layer_type type; /*!< layer type id (see @ref ai_layer_type) */ union { #define LAYER_ENTRY(type_, id_, struct_, forward_func_, init_func_, destroy_func_) \ AI_CONCAT(ai_layer_, struct_)* struct_; #include "layers_list.h" }; } ai_any_layer_ptr; AI_API_DECLARE_END #endif /*LAYERS_H*/
2,190
C
27.089743
84
0.603653
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/core_net_inspect_interface.h
/** ****************************************************************************** * @file core_net_inspect_interface.h * @author AST Embedded Analytics Research Platform * @brief header file of core network inspection interface APIs ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef __CORE_NET_INSPECT_INTERFACE_H_ #define __CORE_NET_INSPECT_INTERFACE_H_ #pragma once #include "ai_platform.h" AI_API_DECLARE_BEGIN /*! * @defgroup core_validation Validation Core * @brief Implementation of the validation network interface headers */ /*! * @struct ai_inspect_node_info * @brief network node inspection context: there is one of this datastruct * for each node of the network */ typedef struct ai_inspect_node_info_s { ai_u16 type; /*!< node type info @see ai_node datastruct */ ai_u16 id; /*!< node id assigned by codegen tool to identify the specific node instance */ ai_u16 batch_id; /*!< current node batch processed */ ai_u16 n_batches; /*!< total number of node batches to process */ ai_float elapsed_ms; /*!< node performance analysys: time in milliseconds to execute the node forward function */ ai_u16 in_size; /*!< number of node's input activation buffers */ ai_u16 out_size; /*!< number of node's output activation buffers */ ai_buffer* in; /*!< input node activation buffer see @ref ai_buffer */ ai_buffer* out; /*!< output node activation buffer see @ref ai_buffer */ } ai_inspect_node_info; /*! * @struct ai_inspect_net_report * @brief network inspection report context */ typedef struct ai_inspect_net_report_s { ai_u32 id; /*!< id of the report */ ai_signature signature; /*!< network identification checksum */ ai_u32 num_inferences; /*!< total number of inferences processed during the inspection */ ai_u32 n_nodes; /*!< number of nodes in the network */ ai_float elapsed_ms; /*!< network total time (in ms) for processing num_inferences inferences */ ai_inspect_node_info* node; /*!< pointer to the array of size n_nodes where a single node report is reported. see @ref ai_inspect_node_info datastruct */ } ai_inspect_net_report; /*! * @enum net inspector inspection mode * @brief configuration flags to set net inspection mode */ typedef enum { VALIDATION_INSPECT = (0x1<<0), /**< Network validation inspection mode */ STORE_ALL_IO_ACTIVATIONS = (0x1<<7), /**< Store all I/O activations on snapshot datastruct */ } ai_inspect_mode; typedef enum { AI_NODE_EXEC_PRE_FORWARD_STAGE = 0x0, AI_NODE_EXEC_POST_FORWARD_STAGE = 0x1, } ai_node_exec_stage; /*! * @brief function pointer to callback report */ typedef void (*ai_inspect_report_cb_func)( const ai_handle cookie, const ai_inspect_net_report* report); /*! * @brief function pointer to node execute */ typedef void (*ai_inspect_exec_node_cb_func)( const ai_handle cookie, const ai_inspect_node_info* node_info, const ai_node_exec_stage stage); /*! * @struct ai_inspect_config * @brief inspection config datastruct */ typedef struct ai_inspect_config_s { ai_u8 validation_mode; /*!< validation mode flags see @ref ai_inspect_mode */ ai_u8 log_level; /*!< log class level see @ref LOG_SUDO */ ai_bool log_quiet; /*!< log class quiet mode */ ai_inspect_report_cb_func on_report_destroy; /*!< callback function called when a report datastruct is released from memory */ ai_inspect_exec_node_cb_func on_exec_node; /*!< callback function called when a node is executed (pre & post) */ ai_handle cookie; } ai_inspect_config; AI_API_DECLARE_END #endif /*__CORE_NET_INSPECT_INTERFACE_H_*/
4,734
C
37.495935
98
0.562315
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_rnn.h
/** ****************************************************************************** * @file layers_rnn.h * @author AST Embedded Analytics Research Platform * @brief header file of RNN layers ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_RNN_H #define LAYERS_RNN_H #pragma once #include "layers_common.h" #include "layers_nl.h" AI_API_DECLARE_BEGIN /*! * @struct ai_layer_lstm * @ingroup layers * @brief LSTM layer with generic nonlinearities and peephole connections */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_lstm_ { AI_LAYER_STATEFUL_FIELDS_DECLARE ai_size n_units; /**< size of the hidden RNN state */ func_nl activation_nl; /**< activation nonlinearity (input to cell) */ func_nl recurrent_nl; /**< recurrent nonlinearity (hidden to cell) */ func_nl out_nl; /**< output nonlinearity (cell to hidden) */ ai_bool go_backwards; /**< process reversed input */ ai_bool return_state; /**< return state */ ai_bool reverse_seq; /**< reverse output sequence */ ai_float cell_clip; /**< cell clip value */ } ai_layer_lstm; /*! * @struct ai_layer_gru * @ingroup layers * @brief Gated Recurrent Unit (GRU) layer with generic nonlinearities */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_gru_ { AI_LAYER_STATEFUL_FIELDS_DECLARE ai_size n_units; /**< size of the hidden RNN state */ func_nl activation_nl; /**< activation nonlinearity (input to cell) */ func_nl recurrent_nl; /**< recurrent nonlinearity (hidden to cell) */ ai_bool reset_after; ai_bool return_state; ai_bool go_backwards; /**< process reversed input */ ai_bool reverse_seq; /**< reverse output sequence */ } ai_layer_gru; /*! * @struct ai_layer_rnn * @ingroup layers * @brief Simple Recurrent Neural Network (RNN) layer */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_rnn_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_size n_units; /**< size of the hidden RNN state */ func_nl activation_nl; /**< activation nonlinearity (input to hidden) */ ai_bool go_backwards; /**< process reversed input */ ai_bool reverse_seq; /**< reverse output sequence */ ai_bool return_state; } ai_layer_rnn; /*! * @brief Initialize a Long-Short Term Memory (LSTM) layer. * @ingroup layers * * Function used to initialize lstm internal state */ AI_INTERNAL_API void init_lstm(ai_layer * layer); /*! * @brief Destroy a Long-Short Term Memory (LSTM) layer state. * @ingroup layers * * Function used to destroy lstm internal state */ AI_INTERNAL_API void destroy_lstm(ai_layer * layer); /*! * @brief Computes the activations of a Long-Short Term Memory (LSTM) layer. * @ingroup layers * * Implements a Long-Short Term Layer with peephole connections: * \f{eqnarray*}{ * i_t &=& \sigma_a(x_t W_{xi} + h_{t-1} W_{hi} * + w_{ci} \odot c_{t-1} + b_i)\\ * f_t &=& \sigma_a(x_t W_{xf} + h_{t-1} W_{hf} * + w_{cf} \odot c_{t-1} + b_f)\\ * c_t &=& f_t \odot c_{t - 1} * + i_t \odot \sigma_r(x_t W_{xc} + h_{t-1} W_{hc} + b_c)\\ * o_t &=& \sigma_a(x_t W_{xo} + h_{t-1} W_{ho} + w_{co} \odot c_t + b_o)\\ * h_t &=& o_t \odot \sigma_o(c_t) * \f} * where \f$\sigma_a\f$ is the activation nonlinearity, \f$\sigma_r\f$ is the * recurrent nonlinearity and \f$\sigma_o\f$ is the out nonlinearity. The * \f$W_x\f$, \f$W_h\f$ and \f$W_c\f$ weights are sliced from the kernel, * recurrent and peephole weights. * * @param layer the LSTM layer */ AI_INTERNAL_API void forward_lstm(ai_layer * layer); /*! * @brief Initialize a Gated Recurrent Unit (GRU) layer. * @ingroup layers * * Function used to initialize gru internal state */ AI_INTERNAL_API void init_gru(ai_layer * layer); /*! * @brief Destroy a Gated Recurrent Unit (GRU) layer state. * @ingroup layers * * Function used to destroy gru internal state */ AI_INTERNAL_API void destroy_gru(ai_layer * layer); /*! * @brief Computes the activations of a Gated Recurrent Unit (GRU) layer. * @ingroup layers * * Implements a Gated Recurrent Unit with the formula: * \f{eqnarray*}{ * r_t &=& \sigma_a(x_t W_{xr} + h_{t - 1} W_{hr} + b_r) \\ * z_t &=& \sigma_a(x_t W_{xz} + h_{t - 1} W_{hz} + b_z) \\ * c_t &=& \sigma_r(x_t W_{xc} + r_t \odot (h_{t - 1} W_{hc} + b_{hc}) + b_c) * \qquad \textnormal{when reset after is true} \\ * c_t &=& \sigma_r(x_t W_{xc} + (r_t \odot h_{t - 1}) W_{hc} + b_{hc} + b_c) * \qquad \textnormal{when reset after is false (default)} \\ * h_t &=& (1 - z_t) \odot h_{t - 1} + z_t \odot c_t * \f} * where \f$\sigma_a\f$ is the activation nonlinearity and \f$\sigma_r\f$ is * the recurrent nonlinearity. The weights are sliced from the kernel and * recurrent weights. * * @param layer the GRU layer */ AI_INTERNAL_API void forward_gru(ai_layer * layer); /*! * @brief Computes the activations of a Recurrent Neural Network (RNN) layer. * @ingroup layers * * Implements a recurrent layer with the formula: * \f{eqnarray*}{ * h_t &=& \sigma_a(x_t W_{xr} + h_{t - 1} W_{hr} + b_r) * \f} * where \f$\sigma_a\f$ is the activation nonlinearity. The weights are sliced * from the kernel and recurrent weights. * * @param layer the RNN layer */ AI_INTERNAL_API void forward_rnn(ai_layer * layer); AI_API_DECLARE_END #endif /* LAYERS_RNN_H */
5,866
C
30.713513
80
0.596147
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_lite_graph.h
/** ****************************************************************************** * @file layers_lite_graph.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform lite graph layers wrapper interface ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_LITE_GRAPH_H #define LAYERS_LITE_GRAPH_H #pragma once #include "core_common.h" /*! * @defgroup layers_lite_graph Lite Graph Wrapper Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_lite_graph * @ingroup layers_lite_graph * @brief Generic Lite Graph Layer Wrapper * * The type of lite graph is handled by the specific forward lite graph function. */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_lite_graph_ { AI_NODE_COMMON_FIELDS_DECLARE ai_handle* activations_map; /*!< array of pointers to shared activations memory pools */ ai_handle* weights_map; /*!< array of pointers to shared weights memory pools */ } ai_layer_lite_graph; AI_API_DECLARE_END #endif /*LAYERS_LITE_GRAPH_H*/
1,598
C
29.169811
98
0.558824
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/core_datatypes.h
/** ****************************************************************************** * @file core_datatypes.h * @author AST Embedded Analytics Research Platform * @brief header file of core module private defines and datatypes * to public nor codegen tool ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_CORE_DATATYPES_H #define AI_CORE_DATATYPES_H #pragma once #include <stdint.h> /*! * @defgroup Core Module Datatypes * @brief Data structures and defines used by core module */ /*! * @brief platform runtime core library version */ #define AI_PLATFORM_RUNTIME_MAJOR 8 #define AI_PLATFORM_RUNTIME_MINOR 1 #define AI_PLATFORM_RUNTIME_MICRO 0 #define AI_PLATFORM_RUNTIME_BUILD A1-SNAPSHOT #define AI_MAGIC_CONTEXT_TOKEN (0xA1C00100) /*!< AI Cool! Magic Token */ #define AI_MAGIC_INSPECTOR_TOKEN (0xA1C00101) /*!< AI Cool! Magic Token */ #define AI_ID_OBJ(id) \ ((ai_id_obj)(id)) #define AI_C_ARRAY_COUNT(array_) \ ( sizeof(array_) / sizeof((array_)[0]) ) #define AI_C_ARRAY_BYTE_SIZE(array_) \ ( sizeof(array_) ) /*! * @typedef ai_id_obj * @ingroup core_datatypes * @brief numeric identifier for generic object instances (e.g. layers, * operators, etc.) It is used by codegen tool to keep tracks of specific * instances created */ typedef uint16_t ai_id_obj; #endif /*AI_CORE_DATATYPES_H*/
1,901
C
27.818181
80
0.570752
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_ml_svmregressor.h
/** ****************************************************************************** * @file layers_svmregressor.h * @author AIS * @brief header file of AI platform SVM Regressor datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_SVMREGRESSOR_H #define LAYERS_SVMREGRESSOR_H #pragma once #include "layers_common.h" /*! * @defgroup layers_svmreg Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /* SVM regressor kernel types */ typedef enum ai_svm_kernel_e_ { AI_SVMREG_KERNEL_LINEAR = 0, AI_SVMREG_KERNEL_POLYNOMIAL, AI_SVMREG_KERNEL_RBF, AI_SVMREG_KERNEL_SIGMOID, AI_SVMREG_KERNEL_UNSUPPORTED, } ai_svm_kernel_e; /*! * @struct ai_layer_svmreg * @ingroup layers_svmreg * @brief SVM Regressor layer * * The type of svmreg function is handled by the specific forward function * @ref forward_svm_regressor */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_svmreg_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_float intercept; /*!< constant used in the decision function */ ai_float gamma; /*!< kernel coefficient for rbf, polynomial and sigmoid functions */ ai_float coef0; /*!< term in polynomial and sigmoid functions */ ai_u32 degree; /*!< polynomial function degree */ ai_svm_kernel_e kernel_type; /*!< kernel type : see ai_svm_kernel_e */ } ai_layer_svmreg; /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Decodes the SVM Regressor ML operator. * @ingroup layers_svmreg * @param layer svm regressor layer */ AI_INTERNAL_API void forward_svm_regressor(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_SVMREGRESSOR_H*/
2,397
C
27.891566
96
0.53567
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_bn_integer.h
#ifndef LITE_BN_INTEGER_H #define LITE_BN_INTEGER_H #pragma once #include "ai_lite_interface.h" /** * @brief Batch Normalization with 16-bit input, 16-bit threshold and binary output. * It is implemented using a threshold, and this is possible because the output is binary. * * @param[in] pIn Input data pointer * @param[out] pOut_32 Output data pointer * @param[in] pThreshold Thresholds pointer (one per channel) * @param[in] dim_x X dimension * @param[in] dim_y Y dimension * @param[in] channels_num Channels number */ LITE_API_ENTRY void forward_lite_bn_is16os1ws16(const ai_i16 *pIn, ai_u32 *pOut_32, const ai_i16 *pThreshold, const ai_i16 dim_x, const ai_i16 dim_y, const ai_i16 channels_num); #endif /* LITE_BN_INTEGER_H */
913
C
34.153845
90
0.591457
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_datatypes_internal.h
/** ****************************************************************************** * @file ai_datatypes_internal.h * @author AST Embedded Analytics Research Platform * @brief Definitions of AI platform private APIs types ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_DATATYPES_INTERNAL_H #define AI_DATATYPES_INTERNAL_H #pragma once #include "ai_datatypes.h" #include "ai_datatypes_defines.h" /*! * @defgroup datatypes_internal Internal Datatypes * @brief Data structures used internally to implement neural networks * * The layers are defined as structs; a generic layer type defines the basic * layer parameters and type-specific parameters are handled by specializations * implemented as a C union. The layers keep also a pointer to the parent * network and the next layer in the network. * The input, output and parameters are tensor with an hard-coded maximum * dimension of 4. Tensors are floating point arrays with a notion of size. * The network is a linked list of layers, and thus it stores only the pointer * to the first layer. */ /*! * @section Offsets * @ingroup datatypes_internal * Macros to handle (byte) stride addressing on tensors. The `AI_PTR` macro * is used to always cast a pointer to byte array. The macros `AI_OFFSET_X` are * used to compute (byte) offsets of respectively adjacents row elements, col * elements, channel elements and `channel_in` elements. * @{ */ /*! AI_STORAGE_KLASS SECTION ************************************/ #define AI_STORAGE_KLASS_TYPE(s_) \ ( (s_)->type ) #define AI_STORAGE_KLASS_SIZE(s_) \ ( (s_)->size ) #define AI_STORAGE_KLASS_DATA(s_, type_) \ ( (type_*)((s_)->data) ) #define AI_STORAGE_KLASS_COPY(dst_, dst_type_, src_, src_type_) \ { \ AI_ASSERT(AI_STORAGE_KLASS_SIZE(src_)>=AI_STORAGE_KLASS_SIZE(dst_)) \ AI_STORAGE_KLASS_SIZE(dst_) = AI_STORAGE_KLASS_SIZE(src_); \ for (ai_size i=0; i<AI_STORAGE_KLASS_SIZE(dst_); i++ ) { \ AI_STORAGE_KLASS_DATA(dst_, dst_type_)[i] = \ AI_STORAGE_KLASS_DATA(src_, src_type_)[i]; \ } \ } #define AI_STORAGE_KLASS_DUMP(s_, pfx_, post_, fmt_, type_) \ { \ AI_ASSERT(s_) \ AI_DEBUG_PRINT(pfx_, AI_STORAGE_KLASS_SIZE(s_)) \ for ( ai_u32 i=0; i<AI_STORAGE_KLASS_SIZE(s_); i++ ) { \ if ( (i % 8)==0 ) { AI_DEBUG_PRINT("\n ") } \ AI_DEBUG_PRINT(fmt_, AI_STORAGE_KLASS_DATA(s_, type_)[i]) \ } \ AI_DEBUG_PRINT(post_) \ } /*! AI_SHAPES SECTION ************************************/ #define AI_SHAPE_2D_H(shape_) \ AI_SHAPE_ELEM(shape_, AI_SHAPE_2D_HEIGHT) #define AI_SHAPE_2D_W(shape_) \ AI_SHAPE_ELEM(shape_, AI_SHAPE_2D_WIDTH) #define AI_SHAPE_ELEM(shape_, pos_) \ AI_STORAGE_KLASS_DATA(shape_, ai_shape_dimension)[pos_] #define AI_SHAPE_GET_ELEM(shape_, pos_) \ (((pos_) < AI_SHAPE_SIZE(shape_)) ? AI_SHAPE_ELEM(shape_, pos_) : 1) #define AI_SHAPE_SET_ELEM(shape_, pos_, val_) \ if ((pos_) < AI_SHAPE_SIZE(shape_)) { AI_SHAPE_ELEM(shape_, pos_) = (val_); } #define AI_SHAPE_TYPE(shape_) \ AI_STORAGE_KLASS_TYPE(shape_) #define AI_SHAPE_SIZE(shape_) \ AI_STORAGE_KLASS_SIZE(shape_) #define AI_SHAPE_CLONE(dst_, src_) \ AI_STORAGE_KLASS_COPY(dst_, ai_shape_dimension, src_, ai_shape_dimension) #define AI_SHAPE_BCAST_CLONE(dst_, src_) \ { \ for (ai_size i = 0; i < AI_SHAPE_SIZE(dst_); i++) { \ AI_SHAPE_SET_ELEM(dst_, i, AI_SHAPE_GET_ELEM(src_, i)); \ } \ } //#define AI_SHAPE_BATCH(shape_) AI_SHAPE_ELEM((shape_), AI_SHAPE_BATCH_CHANNEL) #define AI_SHAPE_H(shape_) AI_SHAPE_ELEM((shape_), AI_SHAPE_HEIGHT) #define AI_SHAPE_W(shape_) AI_SHAPE_ELEM((shape_), AI_SHAPE_WIDTH) #define AI_SHAPE_CH(shape_) AI_SHAPE_ELEM((shape_), AI_SHAPE_CHANNEL) #define AI_SHAPE_IN_CH(shape_) AI_SHAPE_ELEM((shape_), AI_SHAPE_IN_CHANNEL) #define AI_SHAPE_D(shape_) ((AI_SHAPE_SIZE((shape_)) > AI_SHAPE_DEPTH) \ ? AI_SHAPE_ELEM((shape_), AI_SHAPE_DEPTH) : 1) #define AI_SHAPE_E(shape_) ((AI_SHAPE_SIZE((shape_)) > AI_SHAPE_EXTENSION) \ ? AI_SHAPE_ELEM((shape_), AI_SHAPE_EXTENSION) : 1) #define AI_SHAPE_T(shape_) AI_SHAPE_ELEM((shape_), AI_SHAPE_TIME) #define AI_CONV_SHAPE_H AI_SHAPE_W #define AI_CONV_SHAPE_W AI_SHAPE_CH #define AI_CONV_SHAPE_CH AI_SHAPE_H #define AI_CONV_SHAPE_IN_CH AI_SHAPE_IN_CH /*! AI_STRIDES SECTION ***********************************/ #define AI_STRIDE_2D_H(stride_) \ AI_STRIDE_ELEM((stride_), AI_SHAPE_2D_HEIGHT) #define AI_STRIDE_2D_W(stride_) \ AI_STRIDE_ELEM((stride_), AI_SHAPE_2D_WIDTH) #define AI_STRIDE_ELEM(stride_, pos_) \ AI_STORAGE_KLASS_DATA(stride_, ai_stride_dimension)[pos_] #define AI_STRIDE_GET_ELEM(stride_, pos_) \ (((pos_) < AI_STRIDE_SIZE(stride_)) ? AI_STRIDE_ELEM(stride_, pos_) : 0) #define AI_STRIDE_SET_ELEM(stride_, pos_, val_) \ if ((pos_) < AI_STRIDE_SIZE(stride_)) AI_STRIDE_ELEM(stride_, pos_) = (val_); #define AI_STRIDE_TYPE(stride_) \ AI_STORAGE_KLASS_TYPE(stride_) #define AI_STRIDE_SIZE(stride_) \ AI_STORAGE_KLASS_SIZE(stride_) #define AI_STRIDE_CLONE(dst_, src_) \ AI_STORAGE_KLASS_COPY(dst_, ai_stride_dimension, src_, ai_stride_dimension) #define AI_STRIDE_BCAST_CLONE(dst_, src_) \ { \ for (ai_size i=0; i<AI_STRIDE_SIZE(dst_); i++) { \ AI_STRIDE_SET_ELEM(dst_, i, AI_STRIDE_GET_ELEM(src_, i)); \ } \ } //#define AI_STRIDE_BATCH(stride) AI_STRIDE_ELEM((stride), AI_SHAPE_BATCH_CHANNEL) #define AI_STRIDE_H(stride) AI_STRIDE_ELEM((stride), AI_SHAPE_HEIGHT) #define AI_STRIDE_W(stride) AI_STRIDE_ELEM((stride), AI_SHAPE_WIDTH) #define AI_STRIDE_CH(stride) AI_STRIDE_ELEM((stride), AI_SHAPE_CHANNEL) #define AI_STRIDE_IN_CH(stride) AI_STRIDE_ELEM((stride), AI_SHAPE_IN_CHANNEL) #define AI_STRIDE_D(stride) ((AI_STRIDE_SIZE((stride)) >= 5) ? AI_STRIDE_ELEM((stride), AI_SHAPE_DEPTH) : 0) #define AI_STRIDE_E(stride) ((AI_STRIDE_SIZE((stride)) == 6) ? AI_STRIDE_ELEM((stride), AI_SHAPE_EXTENSION) : 0) #define AI_STRIDE_T(stride) AI_STRIDE_ELEM((stride), AI_SHAPE_TIME) #define AI_STRIDE_SET_H(stride, val) AI_STRIDE_SET_ELEM((stride), AI_SHAPE_HEIGHT, val) #define AI_STRIDE_SET_W(stride, val) AI_STRIDE_SET_ELEM((stride), AI_SHAPE_WIDTH, val) #define AI_STRIDE_SET_CH(stride, val) AI_STRIDE_SET_ELEM((stride), AI_SHAPE_CHANNEL, val) #define AI_STRIDE_SET_IN_CH(stride, val) AI_STRIDE_SET_ELEM((stride), AI_SHAPE_IN_CHANNEL, val) #define AI_STRIDE_SET_D(stride, val) if (AI_STRIDE_SIZE((stride)) >= 5) AI_STRIDE_SET_ELEM((stride), AI_SHAPE_DEPTH, val) #define AI_STRIDE_SET_E(stride, val) if (AI_STRIDE_SIZE((stride)) == 6) AI_STRIDE_SET_ELEM((stride), AI_SHAPE_EXTENSION, val) /*! AI_TENSORS SECTION ***********************************/ #define AI_TENSOR_KLASS(tensor_) \ ((tensor_) ? (tensor_)->klass : NULL) #define AI_TENSOR_SHAPE(tensor_) \ (&((tensor_)->shape)) #define AI_TENSOR_STRIDE(tensor_) \ (&((tensor_)->stride)) #define AI_TENSOR_INFO(tensor_) \ (&((tensor_)->info)) #define AI_TENSOR_ARRAY(tensor_) \ ((tensor_) ? (tensor_)->data : NULL) #define AI_TENSOR_ID(tensor_) \ ((tensor_) ? AI_TENSOR_INFO(tensor_)->id : 0) #define AI_TENSOR_FLAGS(tensor_) \ ((tensor_) ? AI_TENSOR_INFO(tensor_)->flags : 0) #define AI_TENSOR_DATA_SIZE(tensor_) \ ((tensor_) ? AI_TENSOR_INFO(tensor_)->data_size : 0) /*! AI_OFFSETS SECTION ***********************************/ //#define AI_OFFSET_BATCH(b, stride) ((ai_ptr_offset)(b) * AI_STRIDE_BATCH(stride)) #define AI_OFFSET_H(y, stride) ((ai_ptr_offset)(y) * AI_STRIDE_H(stride)) #define AI_OFFSET_W(x, stride) ((ai_ptr_offset)(x) * AI_STRIDE_W(stride)) #define AI_OFFSET_CH(ch, stride) ((ai_ptr_offset)(ch) * AI_STRIDE_CH(stride)) #define AI_OFFSET_IN_CH(in_ch, stride) ((ai_ptr_offset)(in_ch) * \ AI_STRIDE_IN_CH(stride)) #define AI_OFFSET_D(d, stride) ((ai_ptr_offset)(d) * AI_STRIDE_D(stride)) #define AI_OFFSET_E(e, stride) ((ai_ptr_offset)(e) * AI_STRIDE_E(stride)) #define AI_OFFSET_5D(y, x, d, e, ch, stride) ( \ AI_OFFSET_H((y), (stride)) + AI_OFFSET_W((x), (stride)) + \ AI_OFFSET_D((d), (stride)) + AI_OFFSET_E((e), (stride)) + \ AI_OFFSET_CH((ch), (stride)) ) #define AI_OFFSET(y, x, ch, z, stride) ( \ AI_OFFSET_H((y), (stride)) + AI_OFFSET_W((x), (stride)) + \ AI_OFFSET_CH((ch), (stride)) + \ ((AI_STRIDE_SIZE((stride)) == 4) ? AI_OFFSET_IN_CH((z), (stride)) : AI_OFFSET_D((z), (stride))) ) /*! @} */ #define AI_GET_CONV_OUT_SIZE(in_size, filt_size, pad_l, pad_r, filt_stride) \ ((((in_size) - (filt_size) + (pad_l) + (pad_r)) / (filt_stride)) + 1) /** Tensors datatypes defines handlers ****************************************/ #define AI_TENSOR_SIZE(tensor_) \ get_tensor_size(tensor_, true) #define AI_TENSOR_SIZE_UNPAD(tensor_) \ get_tensor_size(tensor_, false) #define AI_TENSOR_BYTE_SIZE(tensor_) \ get_tensor_byte_size(tensor_) /******************************************************************************/ #define AI_PLATFORM_VERSION_INIT(major_, minor_, micro_) \ { .major = (major_), .minor = (minor_), .micro = (micro_), .reserved = 0x0 } /** Integer tensor info extraction ********************************************/ #define AI_INTQ_INFO_LIST_SCALE_ARRAY(list_, type_) \ ( ((list_) && (list_)->info) \ ? ((type_*)((list_)->info->scale)) : NULL ) #define AI_INTQ_INFO_LIST_ZEROPOINT_ARRAY(list_, type_) \ ( ((list_) && (list_)->info) \ ? ((type_*)((list_)->info->zeropoint)) : NULL ) #define AI_KLASS_GET_INTQ_INFO_LIST(tensor_) \ ((ai_intq_info_list*)((tensor_)->klass)) AI_API_DECLARE_BEGIN /*! * @brief Check whether 2 shapes have identical dimensions. * @ingroup datatypes_internal * @param shape0 the 1st tensor shape to compare * @param shape1 the 2nd tensor shape to compare * @return true if shape0 and shape1 have same dimensions. false otherwise */ AI_DECLARE_STATIC ai_bool ai_shape_is_same( const ai_shape* shape0, const ai_shape* shape1) { AI_ASSERT(shape0 && shape1) if (AI_SHAPE_SIZE(shape0) != AI_SHAPE_SIZE(shape1)) return false; ai_size dim = AI_SHAPE_SIZE(shape0); while ( dim>0 ) { dim--; if ( AI_SHAPE_ELEM(shape0, dim)!=AI_SHAPE_ELEM(shape1, dim) ) return false; } return true; } /*! * @brief Check whether the shapes is 1*1*1... for a scalar value content. * @ingroup datatypes_internal * @param shape the tensor shape to evaluate * @return true if shape0 is scalar false otherwise */ AI_DECLARE_STATIC ai_bool ai_shape_is_scalar( const ai_shape* shape0) { ai_size dim = AI_SHAPE_SIZE(shape0); while (dim>0) { dim--; if (AI_SHAPE_ELEM(shape0, dim) != 1) return false; } return true; } /*! * @brief Check if shape0 is a subshape of shape1 * @ingroup datatypes_internal * @param shape0 the 1st tensor shape to compare * @param shape1 the 2nd tensor shape to compare * @return true if shape0 is a subshape of shape1 (all shape0 dimensions are * smallers or equal of the shape1 ones). false otherwise */ AI_DECLARE_STATIC ai_bool ai_shape_is_subshape( const ai_shape* shape0, const ai_shape* shape1) { AI_ASSERT(shape0 && shape1) AI_ASSERT(AI_SHAPE_SIZE(shape0)==AI_SHAPE_SIZE(shape1)) ai_size dim = AI_SHAPE_SIZE(shape0); while (dim) { dim--; if ( AI_SHAPE_ELEM(shape0, dim)>AI_SHAPE_ELEM(shape1, dim) ) return false; } return true; } /*! * @brief Computes the total size of a tensor given its dimensions. * @ingroup datatypes_internal * @param shape the tensor shape */ AI_DECLARE_STATIC ai_size ai_shape_get_size(const ai_shape* shape) { AI_ASSERT(shape) ai_size dim = AI_SHAPE_SIZE(shape); ai_size size = 1; while (dim>0) { dim--; size *= AI_SHAPE_ELEM(shape, dim); } return size; } /*! * @brief Computes the size of the input image discarding the channels. * @ingroup datatypes_internal * @param shape the tensor shape */ AI_DECLARE_STATIC ai_size ai_shape_get_npixels(const ai_shape* shape) { AI_ASSERT(shape) const ai_size npixels = AI_SHAPE_W(shape) * AI_SHAPE_H(shape); return npixels; } /** APIs Section *************************************************************/ /*! * @brief Get packed version from major, minor, micro representaion. * @ingroup datatypes_internal * @param major major version value * @param minor minor version value * @param micro micro version value * @return a packed version info obtained serializing input values */ AI_INTERNAL_API ai_version ai_version_get(const ai_u8 major, const ai_u8 minor, const ai_u8 micro); /*! * @brief Get un-packed version from packed version representaion. * @ingroup datatypes_internal * @param version a packed varsion info * @return struct with de-serialized major, minor, micro values */ AI_INTERNAL_API ai_platform_version ai_platform_version_get(const ai_version version); /*! * @brief Map from ai_buffer data struct to ai_array data struct. * @ingroup datatypes_internal * @param buf a pointer to the ai_buffer to be mapped to ai_array * @return an initialized @ref ai_array struct representing same data */ AI_INTERNAL_API ai_array ai_from_buffer_to_array(const ai_buffer* buf); /*! * @brief Map from ai_array data struct to ai_buffer data struct. * @ingroup datatypes_internal * @param array a pointer to the ai_array to be mapped to ai_buffer * @return an initialized @ref ai_buffer struct representing same data */ AI_INTERNAL_API ai_buffer ai_from_array_to_buffer(const ai_array* array); /*! * @brief get the total number of elements of a n-dimensional tensor. * @ingroup datatypes_internal * @param t a pointer to an @ref ai_tensor * @param with_padding when true it considers also padded elements * @return the number of elements of the tensor (with/without padded ones) */ AI_INTERNAL_API ai_size get_tensor_size(const ai_tensor* t, const ai_bool with_padding); /*! * @brief get the total size in bytes of elements of a n-dimensional tensor (excluding padded ones). * @ingroup datatypes_internal * @param t a pointer to an @ref ai_tensor * @return the total size in bytes of elements of the tensor (excluding padded ones) */ AI_INTERNAL_API ai_size get_tensor_byte_size(const ai_tensor* t); AI_API_DECLARE_END #endif /*AI_DATATYPES_INTERNAL_H*/
14,911
C
34.336493
133
0.62303
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_dw_dqnn.h
/** ****************************************************************************** * @file lite_dw_dqnn.h * @author AIS * @brief header file of AI platform lite dw kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_DW_DQNN_H #define LITE_DW_DQNN_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles 2D DW convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_dw_is1os1ws1_bn_pad0(const ai_u32 *pDataIn_init, ai_u32 * pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold); /*! * @brief Handles 2D DW convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Lite I/F * - Optimized thanks to Optim3 assumptions * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_dw_is1os1ws1_bn_pad0_optim3(const ai_u32 *pDataIn_init, ai_u32 * pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_dw_is1os1ws1_bn_pad1(const ai_u32 *pDataIn_init, ai_u32 * pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold, const ai_i32 pad_value); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with +1/-1 padding (Larq like) - Lite I/F * - Optimized thanks to Optim3 assumptions * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_dw_is1os1ws1_bn_pad1_optim3(const ai_u32 *pDataIn_init, ai_u32 * pDataOut_init, const ai_u32 *pWeights_init, ai_float *pScratch_32, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_in, const ai_i32 height_in, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 filt_width, const ai_i32 filt_height, const ai_i32 filt_pad_x, const ai_i32 filt_pad_y, const ai_i32 filt_stride_x, const ai_i32 filt_stride_y, const ai_i32 *pThreshold, const ai_i32 pad_value); #endif /*LITE_DW_DQNN_H*/
6,834
C
49.629629
80
0.362891
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_upsample_generic.h
/** ****************************************************************************** * @file lite_upsample.h * @author AIS * @brief header file of AI platform lite pw kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_UPSAMPLE_GENERIC_H #define LITE_UPSAMPLE_GENERIC_H #pragma once #include "ai_lite_interface.h" void forward_lite_upsample_generic_nearest(const ai_u8* in_data, ai_u8* out_data, const ai_size width_in, const ai_size width_out, const ai_float width_scale, const ai_size height_out, const ai_float height_scale, const ai_u32 output_tensor_w_stride, const ai_float offset_round_coeff); void forward_lite_upsample_nearest(ai_ptr in_data, ai_ptr out_data, const ai_size width_in, const ai_float width_scale, const ai_float height_scale, const ai_size width_out, const ai_size height_out, const ai_ptr_offset stride_w, const ai_float offset_round_coeff); void forward_lite_upsample_zeros( ai_ptr in_data, ai_ptr out_data, const ai_size width_in, const ai_size height_in, const ai_float width_scale, const ai_float height_scale, const ai_size width_out, const ai_size height_out, const ai_ptr_offset stride_ch, const ai_ptr_offset stride_w, const ai_handle p_zero_value); #endif /*LITE_UPSAMPLE_GENERIC_H*/
2,756
C
44.196721
80
0.394049
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_lite_interface.h
/** ****************************************************************************** * @file ai_lite_interface.h * @author AST Embedded Analytics Research Platform * @brief Definitions and implementations of runtime-lite codegen APIs ****************************************************************************** * @attention * * Copyright (c) 2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_LITE_INTERFACE_H #define AI_LITE_INTERFACE_H #pragma once #include "ai_platform.h" #include "ai_lite.h" /*****************************************************************************/ /* Generic Codegen Section */ // #ifdef HAS_LOG #if 0 #include "core_log.h" #define LITE_GRAPH_START(_graph_name) \ AI_LOG_DEBUG("[LITE GRAPH START] : " _graph_name) #define LITE_GRAPH_END(_graph_name) \ AI_LOG_DEBUG("[LITE GRAPH END] : " _graph_name) #else #define LITE_GRAPH_START(_graph_name) \ /* LITE_GRAPH_START() */ #define LITE_GRAPH_END(_graph_name) \ /* LITE_GRAPH_END() */ #endif /* HAS_LOG */ #ifdef HAS_AI_ASSERT #include <assert.h> #define LITE_ASSERT(_cond) \ { assert(_cond); } #else #define LITE_ASSERT(_cond) \ do { /* LITE_ASSERT() */ } while (0); #endif /*HAS_AI_ASSERT*/ /*****************************************************************************/ #if defined(_MSC_VER) #define LITE_DECLARE_STATIC static __inline #define LITE_HINT_INLINE static __inline #define LITE_FORCE_INLINE static __inline #elif defined(__ICCARM__) || defined (__IAR_SYSTEMS_ICC__) #define LITE_DECLARE_STATIC static inline #define LITE_HINT_INLINE static inline #define LITE_FORCE_INLINE static inline #elif defined(__GNUC__) #define LITE_DECLARE_STATIC static __inline #define LITE_HINT_INLINE static __inline #define LITE_FORCE_INLINE static __inline #else #define LITE_DECLARE_STATIC static __inline #define LITE_HINT_INLINE static __inline #define LITE_FORCE_INLINE static __inline #endif /* _MSC_VER */ #define LITE_API_ENTRY /* LITE_API_ENTRY */ #define LITE_PACK(...) \ __VA_ARGS__ #define LITE_UNUSED(_elem) \ ((void)(_elem)); #define LITE_KERNEL_SECTION(_code_block) \ { LITE_PACK(_code_block) } /*****************************************************************************/ /* Arrays Section */ #define LITE_ARRAY_VALUES(...) \ { LITE_PACK(__VA_ARGS__) } #define LITE_ARRAY_DATA(_array, _type) \ ((_type*)(_array)->data) #define LITE_ARRAY_DATA_START(_array, _type) \ ((_type*)(_array)->data_start) /*****************************************************************************/ /* Tensors Section */ #define LITE_TENSOR_ARRAY(_tensor, _pos) \ (((_tensor)->data) + (_pos)) /*****************************************************************************/ /* Tensors List Section */ #define LITE_TENSOR_LIST(_chain, _pos) \ (&(_chain)->chain[_pos]) #define LITE_TENSOR_IN(_chain, _pos) \ (LITE_TENSOR_LIST(_chain, 0)->tensor[_pos]) #define LITE_TENSOR_OUT(_chain, _pos) \ (LITE_TENSOR_LIST(_chain, 1)->tensor[_pos]) #define LITE_TENSOR_WEIGHTS(_chain, _pos) \ (LITE_TENSOR_LIST(_chain, 2)->tensor[_pos]) #define LITE_TENSOR_SCRATCHS(_chain, _pos) \ (LITE_TENSOR_LIST(_chain, 3)->tensor[_pos]) /*****************************************************************************/ #define LITE_LAYER_ACQUIRE(name_, cast_type_, ptr_) \ LITE_ASSERT(ptr_) \ AI_CONCAT(ai_layer_, cast_type_)* name_ = \ (AI_CONCAT(ai_layer_, cast_type_)*)(ptr_); #define LITE_LAYER_RELEASE(name_, cast_type_) \ /* LITE_LAYER_RELEASE() */ /*****************************************************************************/ AI_API_DECLARE_BEGIN AI_API_DECLARE_END #endif /* AI_LITE_INTERFACE_H */
4,226
C
28.767605
80
0.503076
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_sm.h
/** ****************************************************************************** * @file layers_sm.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform non softmax layer datatype ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_SM_H #define LAYERS_SM_H #pragma once #include "layers_common.h" /*! * @defgroup layers SoftMax Layer Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @brief Softmax normalization computed on an array of fixed point channels * @ingroup layers_sm * @param out opaque handler to output channel array * @param in opaque handler to input channel array * @param in_size total size (number of elements) to process on the input * @param channel_size number of elements of the input channel * @param in_channel_step number of elements to move to next input element * @param out_channel_step number of elements to move to next output element */ AI_INTERNAL_API void sm_func_sm_array_fixed(ai_handle out, const ai_handle in, const ai_size in_size, const ai_size channel_size, const ai_size in_channel_step, const ai_size out_channel_step); /*! * @brief Computes the activations of a fixed point softmax nonlinear layer. * @ingroup layers_sm * @param layer the softmax (sm) layer */ AI_INTERNAL_API void forward_sm_fixed(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_SM_H*/
2,051
C
30.56923
80
0.570453
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/datatypes_network.h
/** ****************************************************************************** * @file datatypes_network.h * @author AST Embedded Analytics Research Platform * @brief Definitions of code generated network types ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef DATATYPES_NETWORK_H #define DATATYPES_NETWORK_H #pragma once /* * Header to be overriden by the generated version * by including with <> the include directories are searched in the order * specified in the compiler * To enable the override, put the generated path before the API path */ #include "ai_platform.h" AI_API_DECLARE_BEGIN #ifdef AI_OVERRIDE_CUSTOM_TYPES #warning "Warning: Custom Types have been already defined!\n" #endif #define AI_CUSTOM_TYPES_COUNT (3) #define AI_CUSTOM_TYPES_SIGNATURE_DECLARE(name) \ const ai_custom_type_signature name[AI_CUSTOM_TYPES_COUNT+1] = { \ AI_CUSTOM_TYPES_COUNT, \ AI_CUSTOM_SIZE(ai_shape_dimension), \ AI_CUSTOM_SIZE(ai_stride_dimension), \ AI_CUSTOM_SIZE(ai_array_size), \ }; typedef ai_i32 ai_stride_dimension; typedef ai_u32 ai_array_size; AI_API_DECLARE_END #endif /*DATATYPES_NETWORK_H*/
1,694
C
27.728813
80
0.579103
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_layer_custom_interface.h
/** ****************************************************************************** * @file ai_layer_custom_interface.h * @author AST Embedded Analytics Research Platform * @brief Definitions of AI platform custom layers interface APIs ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_LAYER_CUSTOM_INTERFACE_H #define AI_LAYER_CUSTOM_INTERFACE_H #pragma once #include "ai_platform.h" #include "ai_platform_interface.h" #include "layers_custom.h" #define INTQ_SCALE_FLOAT (AI_BUFFER_META_FLAG_SCALE_FLOAT) #define INTQ_ZEROPOINT_U8 (AI_BUFFER_META_FLAG_ZEROPOINT_U8) #define INTQ_ZEROPOINT_S8 (AI_BUFFER_META_FLAG_ZEROPOINT_S8) #define INTQ_ZEROPOINT_U16 (AI_BUFFER_META_FLAG_ZEROPOINT_U16) #define INTQ_ZEROPOINT_S16 (AI_BUFFER_META_FLAG_ZEROPOINT_S16) #define AI_TENSOR_HEIGHT (3) #define AI_TENSOR_WIDTH (2) #define AI_TENSOR_CHANNEL (1) #define AI_TENSOR_IN_CHANNEL (0) AI_API_DECLARE_BEGIN typedef enum { TYPE_NONE = 0x0, TYPE_FLOAT, TYPE_BOOL, TYPE_INTEGER, TYPE_SIGNED, TYPE_UNSIGNED, } ai_tensor_type; typedef struct { ai_tensor_type type; ai_i8 bits; ai_i8 fbits; } ai_tensor_format; typedef struct { ai_u16 flags; /*!< optional flags to store intq info attributes */ ai_u16 size; /*!< number of elements in the the intq_info list */ ai_float* scale; /*!< array of scales factors */ union { ai_u8* zeropoint_u8; /*!< array of zeropoints as unsigned */ ai_i8* zeropoint_s8; /*!< array of zeropoints as signed */ }; } ai_tensor_intq_info; /**************************************************************************** ** Layer Custom Interface APIs ****************************************************************************/ /*! * @brief acquire the custom layer from its handle * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the custom layer * @return a pointer to ai_layer_custom if found and valid, else NULL */ AI_INTERFACE_TYPE ai_layer_custom* ai_layer_custom_get( ai_layer* layer); /*! * @brief release the custom layer provided its handle * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the custom layer to release */ AI_INTERFACE_TYPE void ai_layer_custom_release( ai_layer* layer); /*! * @brief get the number of inputs tensors of a custom layer * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the custom layer * @return the number of input tensors of the layer. 0 if no input tensors or error */ AI_INTERFACE_TYPE ai_size ai_layer_get_tensor_in_size( const ai_layer* layer); /*! * @brief get the number of outputs tensors of a custom layer * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the custom layer * @return the number of outputs tensors of the layer. 0 if no outputs tensors or error */ AI_INTERFACE_TYPE ai_size ai_layer_get_tensor_out_size( const ai_layer* layer); /*! * @brief get the number of weights tensors of a custom layer * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the custom layer * @return the number of weights tensors of the layer. 0 if no weights tensors or error */ AI_INTERFACE_TYPE ai_size ai_layer_get_tensor_weights_size( const ai_layer* layer); /*! * @brief get the n-th (at index pos) input tensor pointer from a layer * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the layer * @param pos the index position in the tensor list * @return a pointer to a tensor if found, else, if invalid or out-of-range NULL */ AI_INTERFACE_TYPE ai_tensor* ai_layer_get_tensor_in( const ai_layer* layer, const ai_u16 pos); /*! * @brief get the n-th (at index pos) output tensor pointer from a layer * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the layer * @param pos the index position in the tensor list * @return a pointer to a tensor if found, else, if invalid or out-of-range NULL */ AI_INTERFACE_TYPE ai_tensor* ai_layer_get_tensor_out( const ai_layer* layer, const ai_u16 pos); /*! * @brief get the n-th (at index pos) weight tensor pointer from a layer * @ingroup ai_layer_custom_interface * @param layer an opaque handler to the layer * @param pos the index position in the tensor list * @return a pointer to a tensor if found, else, if invalid or out-of-range NULL */ AI_INTERFACE_TYPE ai_tensor* ai_layer_get_tensor_weights( const ai_layer* layer, const ai_u16 pos); /**** Layer Tensors APIs ***************************************************/ /*! * @brief check if the tensor has integer quantization informations @ref ai_tensor_intq_info * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return true if tensot has integer quantization informations, false otherwise */ AI_INTERFACE_TYPE ai_bool ai_tensor_has_intq( const ai_tensor* t); /*! * @brief get the tensor integer quantization informations @ref ai_tensor_intq_info * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the integer quantization informations as a struct @ref ai_tensor_intq_info */ AI_INTERFACE_TYPE ai_tensor_intq_info ai_tensor_get_intq( const ai_tensor* t); /*! * @brief get the format of the tensor see @ref ai_tensor_format * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the tensor format */ AI_INTERFACE_TYPE ai_tensor_format ai_tensor_get_format( const ai_tensor* t); /**** Shapes Getters ****/ /*! * @brief get the dimensionality of the tensor shapes * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the dimensionality of the tensor shape */ AI_INTERFACE_TYPE ai_size ai_tensor_get_shape_size( const ai_tensor* t); /*! * @brief get the value of the shape dimensionality pos * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the value of the shape dimensionality at pos of the tensor */ AI_INTERFACE_TYPE ai_shape_dimension ai_tensor_get_shape( const ai_tensor* t, const ai_u16 pos); /**** Strides Getters ****/ /*! * @brief get the dimensionality of the tensor strides * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the dimensionality of the tensor strides @ref ai_stride */ AI_INTERFACE_TYPE ai_size ai_tensor_get_stride_size( const ai_tensor* t); /*! * @brief get the value of the stride dimensionality pos * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the value of the stride dimensionality at pos of the tensor */ AI_INTERFACE_TYPE ai_stride_dimension ai_tensor_get_stride( const ai_tensor* t, const ai_u16 pos); /**** Data Storage Getters ****/ /*! * @brief get tensor storage data buffer pointer * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return a pointer to the tensor data buffer, set to NULL if error */ AI_INTERFACE_TYPE ai_any_ptr ai_tensor_get_data( const ai_tensor* t); /*! * @brief get number of tensor elements * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the number of tensor elements or 0 if error */ AI_INTERFACE_TYPE ai_size ai_tensor_get_data_size( const ai_tensor* t); /*! * @brief get the size in bytes of the tensor data buffer * @ingroup ai_layer_custom_interface * @param tensor a pointer to the tensor * @return the size in bytes of the tensor data buffer. 0 if error */ AI_INTERFACE_TYPE ai_size ai_tensor_get_data_byte_size( const ai_tensor* t); AI_API_DECLARE_END #endif /*AI_LAYER_CUSTOM_INTERFACE_H*/
8,272
C
29.985019
92
0.66308
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_pool_dqnn.h
/** ****************************************************************************** * @file layers_conv2d_dqnn.h * @author AIS * @brief header file of AI platform DQNN pool datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_POOL_DQNN_H #define LAYERS_POOL_DQNN_H #pragma once #include "layers_common.h" #include "layers_pool.h" /*! * @defgroup layers_pool_dqnn Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_pool_dqnn * @ingroup layers_pool_dqnn * @brief pool_dqnn layer * * @ref forward_maxpool_is1os1 */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_pool_dqnn_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_shape_2d pool_size; /*!< pooling size */ ai_shape_2d pool_stride; /*!< pooling stride */ ai_shape pool_pad; /*!< pooling pad, y,x border sizes */ // ai_u32 pad_value; /*!< pooling pad value */ } ai_layer_pool_dqnn; /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles max pooling with binary input and binary output * @ingroup layers_pool_dqnn * @param layer conv2d_pool layer */ AI_INTERNAL_API void forward_maxpool_is1os1(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_POOL_DQNN_H*/
1,996
C
26.356164
80
0.482966
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_dw.h
/** ****************************************************************************** * @file lite_dw.h * @author AIS * @brief header file of AI platform lite dw kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_DW_H #define LITE_DW_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles dw convolutions generic case (supports depth multiplier >= 1) * @ingroup lite_dw */ LITE_API_ENTRY void forward_lite_dw_dm_sssa8_ch(const ai_i8 *Im_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_i8 *wt, const ai_u16 ch_im_out, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_i32 *bias, const ai_i8 In_ZeroPoint, const ai_i8 Out_ZeroPoint, ai_i8 *Im_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, const ai_i32 nl_pool_fused, ai_i16 *bufferA); /*! * @brief Handles dw convolutions with depth multiplier = 1 only * @ingroup lite_dw */ LITE_API_ENTRY void forward_lite_dw_sssa8_ch(const ai_i8 *Im_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_i8 *wt, const ai_u16 dim_kernel_x, const ai_u16 dim_kernel_y, const ai_u16 padding_x, const ai_u16 padding_y, const ai_u16 stride_x, const ai_u16 stride_y, const ai_i32 *bias, const ai_i8 In_ZeroPoint, const ai_i8 Out_ZeroPoint, ai_i8 *Im_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, const ai_i32 nl_pool_fused, ai_i16 *bufferA); /*! * @brief Handles dw convolutions with depth multiplier = 1, valid padding * and 3*3 kernel size * @ingroup lite_dw */ LITE_API_ENTRY void forward_lite_dw_3x3_sssa8_ch(const ai_i8 *Im_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_i8 *wt, const ai_u16 stride_x, const ai_u16 stride_y, const ai_i32 *bias, const ai_i8 In_ZeroPoint, const ai_i8 Out_ZeroPoint, ai_i8 *Im_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, const ai_i32 nl_pool_fused, ai_i16 *bufferA); /*! * @brief Handles dw convolutions with depth multiplier = 1, valid padding, * 3*3 kernel size, stride_x = 1 and weights/input are channel first * @ingroup lite_dw */ LITE_API_ENTRY void forward_lite_dw_3x3_ch1st_sssa8_ch(const ai_i8 *Im_in, const ai_u16 dim_im_in_x, const ai_u16 dim_im_in_y, const ai_u16 ch_im_in, const ai_i8 *wt, const ai_u16 stride_x, const ai_u16 stride_y, const ai_i32 *bias, const ai_i8 In_ZeroPoint, const ai_i8 Out_ZeroPoint, ai_i8 *Im_out, const ai_u16 dim_im_out_x, const ai_u16 dim_im_out_y, const ai_i32 nl_pool_fused, ai_i16 *bufferA); #endif /*LITE_DW_H*/
5,348
C
39.218045
80
0.382199
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_ml.h
/** ****************************************************************************** * @file layers_ml.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform ml layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_ML_H #define LAYERS_ML_H #pragma once #include "layers_common.h" /*! * @defgroup layers_generic ML Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_ArrayFeatureExtractor * @ingroup layers_ml * @brief ai_layer_ArrayFeatureExtractor layer definition * * This layer select elements of the input tensor based on the indices passed. It is intended to be used * by his associated forward function @ref forward_arrayfeatureextractor */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_arrayfeatureextractor_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_tensor* indices; /*!< Indices of corrisponding axis in axes*/ } ai_layer_arrayfeatureextractor; /*! * @struct ai_layer_ZipMap * @ingroup layers_ml * @brief ai_layer_ZipMap layer definition * * This layer creates a map from the input and the attributes. * The values are provided by the input tensor, while the keys are specified by the attributes. * The user must provide keys in either classlabels_strings or classlabels_int64s (but not both). * The columns of the tensor correspond one-by-one to the keys specified by the attributes. * There must be as many columns as keys. * It is intended to be used by his associated forward function @ref forward_zipmap. */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_zipmap_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_bool has_classlabels_int; } ai_layer_zipmap; /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief select elements of the input tensor based on the indices passed. * @ingroup layers_ml * @param layer array feture extractor */ AI_INTERNAL_API void forward_arrayfeatureextractor(ai_layer* layer); /*! * @brief creates a map from the inputs and the attributes * @ingroup layers_ml * @param layer zipmap */ AI_INTERNAL_API void forward_zipmap(ai_layer* layer); AI_API_DECLARE_END #endif /*LAYERS_ML_H*/
2,899
C
28.896907
104
0.595378
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_dense_is8os1ws1.h
/** ****************************************************************************** * @file lite_dense_is8os1ws1.h * @author Marco Forleo * @brief header file of AI platform lite dense kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2023 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_DENSE_IS8OS1WS1_H #define LITE_DENSE_IS8OS1WS1_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Forward function for a dense layer with signed 8 bits input, * binary weights and binary output. * @ingroup lite_dense_is8os1ws1 * @param out_ptr The pointer to output buffer. *@param data_in_init_ptr The pointer to input buffer. * @param weights_ptr The pointer to weights. * @param scratch_ptr The pointer to scratch buffer. * @param scratch_size The value of scratch tensor size. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. * @param n_channel_in The number of channels of the input. * @param scale_ptr The pointer to scale buffer of BN. * @param offset_ptr The pointer to offset buffer of BN. */ LITE_API_ENTRY void forward_lite_dense_is8os1ws1_bn_fxp(ai_pbits *out_ptr, const ai_i8 *data_in_init_ptr, const ai_pbits *weights_ptr, ai_i32 *scratch_ptr, const ai_u32 scratch_size, const ai_u32 n_channel_out, const ai_u32 n_channel_in, const ai_i32 *threshold_ptr); #endif /*LITE_DENSE_IS8OS1WS1_H*/
2,452
C
41.293103
80
0.472268
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_list.h
/** ****************************************************************************** * @file layers_list.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ /* No sentry. This is deliberate!! */ /* Template: LAYER_ENTRY(type_, id_, struct_, forward_func_, init_func_, destroy_func_) * Where: * - type_ is the (enum) type name of the layer. to have the complete enum * value you should use the macro @ref AI_LAYER_TYPE_ENTRY(type_) that adds * the specific prefix and postfix tokens to the type_ * - id_ is the numeric id of the layer * - struct_ is the name of the datastruct of the layer without the ai_layer_ * prefix * - forward_func_ is the forward function name of the routine implementing * actual layer processing * - init_func_ is the init function name of the routine implementing * actual layer initialization * - destroy_func_ is the destroy function name of the routine implementing * actual layer de-initialization */ /* Layer IDs for stateless layers (bit 8 set) */ #define LAYER_ID(id_) \ (0x100 + (id_)) /* Layer IDs for stateful layers (bits 7 and 8 set) */ #define LAYER_STATEFUL_ID(id_) \ (0x180 + (id_)) /*!< Base layer */ LAYER_ENTRY(BASE, LAYER_ID(0), base, NULL, NULL, NULL) /*!< Elementwise addition layer */ LAYER_ENTRY(ADD, LAYER_ID(1), add, forward_add, NULL, NULL) /*!< Batch normalization layer */ LAYER_ENTRY(BN, LAYER_ID(2), bn, forward_bn, NULL, NULL) /*!< 2D Convolutional layer */ LAYER_ENTRY(CONV2D, LAYER_ID(3), conv2d, forward_conv2d, NULL, NULL) /*!< Dense layer */ LAYER_ENTRY(DENSE, LAYER_ID(4), dense, forward_dense, NULL, NULL) /*!< Local Response Normalization layer */ LAYER_ENTRY(LRN, LAYER_ID(6), lrn, forward_lrn, NULL, NULL) /*!< Nonlinearity layer */ LAYER_ENTRY(NL, LAYER_ID(7), nl, NULL, NULL, NULL) /*!< Normalization layer */ LAYER_ENTRY(NORM, LAYER_ID(8), norm, forward_norm, NULL, NULL) /*!< Merged Conv2d / Pool layer */ LAYER_ENTRY(OPTIMIZED_CONV2D, LAYER_ID(9), conv2d_nl_pool, forward_conv2d_nl_pool, NULL, NULL) /*!< Transpose Tensor layer */ LAYER_ENTRY(TRANSPOSE, LAYER_ID(10), transpose, forward_transpose, NULL, NULL) /*!< Pooling layer */ LAYER_ENTRY(POOL, LAYER_ID(11), pool, forward_pool, NULL, NULL) /*!< Softmax layer */ LAYER_ENTRY(SM, LAYER_ID(12), sm, forward_sm, NULL, NULL) /*!< Split layer */ LAYER_ENTRY(SPLIT, LAYER_ID(13), split, forward_split, NULL, NULL) /*!< TimeDelay layer */ LAYER_ENTRY(TIME_DELAY, LAYER_ID(14), time_delay, forward_time_delay, NULL, NULL) /*!< TimeDistributed layer */ LAYER_ENTRY(TIME_DISTRIBUTED, LAYER_ID(15), time_distributed, forward_time_distributed, NULL, NULL) /*!< Concat Tensor layer */ LAYER_ENTRY(CONCAT, LAYER_ID(16), concat, forward_concat, NULL, NULL) /*!< GEMM layer */ LAYER_ENTRY(GEMM, LAYER_ID(17), gemm, forward_gemm, NULL, NULL) /*!< Upsample layer */ LAYER_ENTRY(UPSAMPLE, LAYER_ID(18), upsample, forward_upsample, NULL, NULL) /*!< Container layer for eltwise operations */ LAYER_ENTRY(ELTWISE, LAYER_ID(19), eltwise, forward_eltwise, NULL, NULL) /*!< Container layer for eltwise integer operations */ LAYER_ENTRY(ELTWISE_INTEGER, LAYER_ID(20), eltwise_integer, NULL, NULL, NULL) /*!< InstanceNormalization layer */ LAYER_ENTRY(INSTANCENORMALIZATION, LAYER_ID(21), instanceNormalization, forward_instanceNormalization, NULL, NULL) /*!< Pad layer */ LAYER_ENTRY(PAD, LAYER_ID(22), pad, forward_pad, NULL, NULL) /*!< Slice layer */ LAYER_ENTRY(SLICE, LAYER_ID(23), slice, forward_slice, NULL, NULL) /*!< Tile layer */ LAYER_ENTRY(TILE, LAYER_ID(24), tile, forward_tile, NULL, NULL) /*!< Container layer for reduce operations */ LAYER_ENTRY(REDUCE, LAYER_ID(25), reduce, forward_reduce, NULL, NULL) /*!< Recurrent Neural Network layer */ LAYER_ENTRY(RNN, LAYER_ID(26), rnn, forward_rnn, NULL, NULL) /*!< Resize layer */ LAYER_ENTRY(RESIZE, LAYER_ID(27), resize, forward_resize, NULL, NULL) /*!< Gather layer */ LAYER_ENTRY(GATHER, LAYER_ID(28), gather, forward_gather, NULL, NULL) /*!< Pack layer */ LAYER_ENTRY(PACK, LAYER_ID(29), pack, forward_pack, NULL, NULL) /*!< Unpack layer */ LAYER_ENTRY(UNPACK, LAYER_ID(30), unpack, forward_unpack, NULL, NULL) /*!< ArgMax layer */ LAYER_ENTRY(ARGMAX, LAYER_ID(31), argmax, forward_argmax, NULL, NULL) /*!< ArgMin layer */ LAYER_ENTRY(ARGMIN, LAYER_ID(32), argmin, forward_argmin, NULL, NULL) /*!< Cast Neural Network Layer */ LAYER_ENTRY(CAST, LAYER_ID(33), cast, forward_cast, NULL, NULL) /*!< iForest layer */ LAYER_ENTRY(IFOREST, LAYER_ID(34), iforest, forward_iforest, NULL, NULL) /*!< SVM Regressor layer */ LAYER_ENTRY(SVMREG, LAYER_ID(35), svmreg, forward_svm_regressor, NULL, NULL) /*!< ArrayFeatureExtractor layer */ LAYER_ENTRY(ARRAYFEATUREEXTRACTOR, LAYER_ID(36), arrayfeatureextractor, forward_arrayfeatureextractor, NULL, NULL) /*!< SVM Classifier (SVC) layer */ LAYER_ENTRY(SVC, LAYER_ID(37), svc, forward_svc, NULL, NULL) /*!< ZipMap layer */ LAYER_ENTRY(ZIPMAP, LAYER_ID(38), zipmap, forward_zipmap, NULL, NULL) /*!< Where layer */ LAYER_ENTRY(WHERE, LAYER_ID(39), where, forward_where, NULL, NULL) /*!< LinearClassifier layer */ LAYER_ENTRY(LINEARCLASSIFIER, LAYER_ID(42), linearclassifier, forward_linearclassifier, NULL, NULL) /*!< TreeEnsembleClassifier layer */ LAYER_ENTRY(TREE_ENSEMBLE_CLASSIFIER, LAYER_ID(43), tree_ensemble_classifier, forward_tree_ensemble_classifier, NULL, NULL) /*!< TopK layer */ LAYER_ENTRY(TOPK, LAYER_ID(45), topK, forward_topK, NULL, NULL) /*!< ReduceLogSumExp layer */ LAYER_ENTRY(REDUCE_LOG_SUM_EXP, LAYER_ID(51), reduce_log_sum_exp, forward_reduce_log_sum_exp, NULL, NULL) /*!< ReduceL1 layer */ LAYER_ENTRY(REDUCE_L1, LAYER_ID(52), reduce_l1, forward_reduce_l1, NULL, NULL) /*!< Runtime Lite Graph Wrapper layer */ LAYER_ENTRY(LITE_GRAPH, LAYER_ID(63), lite_graph, NULL, NULL, NULL) /*!< TreeEnsembleRegressor layer */ LAYER_ENTRY(TREE_ENSEMBLE_REGRESSOR, LAYER_ID(66), tree_ensemble_regressor, forward_tree_ensemble_regressor, NULL, NULL) /*!< Deeply Quantized Dense Layers */ LAYER_ENTRY(CONV2D_DQNN, LAYER_ID(40), conv2d_dqnn, forward_pw_is1os1ws1_bn, NULL, NULL) LAYER_ENTRY(POOL_DQNN, LAYER_ID(41), pool_dqnn, forward_maxpool_is1os1, NULL, NULL) LAYER_ENTRY(DENSE_DQNN, LAYER_ID(44), dense_dqnn, forward_dense_is1os1ws1, NULL, NULL) /*!< Reverse layer */ LAYER_ENTRY(REVERSE, LAYER_ID(50), reverse, forward_reverse, NULL, NULL) /*****************************************************************************/ /*!< Base Stateful Layer type */ LAYER_ENTRY(STATEFUL, LAYER_STATEFUL_ID(0), stateful, NULL, NULL, NULL) /*!< Long Short Time Memory layer */ LAYER_ENTRY(LSTM, LAYER_STATEFUL_ID(1), lstm, forward_lstm, init_lstm, destroy_lstm) /*!< Custom layer */ LAYER_ENTRY(CUSTOM, LAYER_STATEFUL_ID(2), custom, NULL, NULL, NULL) /*!< Gated Recurrent Unit layer */ LAYER_ENTRY(GRU, LAYER_STATEFUL_ID(3), gru, forward_gru, init_gru, destroy_gru) /*!< Stateless Template layer declaration */ /* LAYER_ENTRY(TEMPLATE, LAYER_ID(XX), template, forward_template, NULL, NULL) */ /*!< Stateful Template layer declaration */ /* LAYER_ENTRY(TEMPLATE, LAYER_STATEFUL_ID(XX), template, forward_template, init_template, destroy_template) */ #undef LAYER_ENTRY #undef LAYER_ID #undef LAYER_STATEFUL_ID
7,821
C
45.838323
123
0.671781
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_pad_generic.h
/** ****************************************************************************** * @file lite_pad_generic.h * @author AIS * @brief header file of AI platform lite padding kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2022 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_PADDING_DQNN_H #define LITE_PADDING_DQNN_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles padding with 8 bits input/output in constant mode - Lite I/F * Channel 1st Format Input and Output * @ingroup lite_padding_dqnn */ LITE_API_ENTRY void forward_lite_pad_8bit_ch1st_3x3_constant(ai_ptr_const in_data_tensor, ai_ptr out_data_tensor, const ai_handle fill_value, const ai_i32 height_in, const ai_i32 channel_in, const ai_ptr_offset ch_stride_in, const ai_ptr_offset h_stride_in, const ai_ptr_offset h_stride_pad); /*! * @brief Handles padding with 8 bits input/output in constant mode - Lite I/F * @ingroup lite_padding_dqnn */ LITE_API_ENTRY void forward_lite_pad_constant(ai_ptr_const in_data, ai_ptr out_data, const ai_handle fill_value, const ai_i16 in_bits, const ai_i32 height_in, const ai_ptr_offset ch_stride_in, const ai_ptr_offset h_stride_in, const ai_ptr_offset h_stride_pad, const ai_ptr_offset h_stride_pad_b, const ai_ptr_offset w_stride_pad, const ai_ptr_offset w_stride_pad_r); /*! * @brief Handles padding with 8 bits input/output in edge mode - Lite I/F * @ingroup lite_padding_dqnn */ void forward_lite_pad_edge(ai_ptr_const in_data_tensor, ai_ptr out_data, const ai_i32 height_in, const ai_i16 pads_y, const ai_i16 pads_x_r, const ai_ptr_offset h_stride_in, const ai_ptr_offset w_stride_in, const ai_ptr_offset h_stride_out, const ai_ptr_offset h_stride_pad, const ai_ptr_offset w_stride_pad, const ai_ptr_offset h_stride_pad_b); /*! * @brief Handles padding with 8 bits input/output in reflect mode - Lite I/F * @ingroup lite_padding_dqnn */ void forward_lite_pad_reflect(ai_ptr_const in_data, ai_ptr out_data, const ai_i32 depth, const ai_i32 height_in, const ai_i32 width_in, const ai_i32 height_out, const ai_i32 width_out, const ai_ptr_offset h_stride_in, const ai_ptr_offset w_stride_in, const ai_ptr_offset h_stride_out, const ai_ptr_offset w_stride_out, const ai_i16 pads_x, const ai_i16 pads_y, const ai_i16 pads_y_b, const ai_ptr_offset h_stride_pad, const ai_ptr_offset w_stride_pad, const ai_ptr_offset w_stride_pad_r); #endif /*LITE_PADDING_GENERIC_H*/
4,546
C
43.145631
80
0.421909
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_datatypes_format.h
/** ****************************************************************************** * @file ai_datatypes_format.h * @author AST Embedded Analytics Research Platform * @brief Definitions of AI platform private format handling routines ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_DATATYPES_FORMAT_H #define AI_DATATYPES_FORMAT_H #pragma once #include "ai_platform.h" #include "ai_datatypes_defines.h" // #include "core_datatypes.h" /*! * @defgroup ai_datatypes_format Definiton and Macro of array and buffer formats * @brief Type definition and implementation of internal @ref ai_array and * @ref ai_buffer formats. * @details The library handles 2 different kind of formats: an internal format * that is part of the @ref ai_array struct that is a packed 32bit representation * of the format attributes, and a public format (used in public APIs) associated * with @ref ai_buffer struct , defined as enum in @ref ai_platform.h, * that is just an enum type. Converters are provided in this header file to * convert from one format representation to another. * Some MSB bits are reserved in both formats to code some bit flag useful to * declare some special attribute. Three flags are actually implemented in both * formats: the @ref AI_BUFFER_FMT_FLAG_CONST and @ref AI_FMT_FLAG_CONST used * to tag read-only memory buffers, @ref AI_BUFFER_FMT_FLAG_STATIC and * @ref AI_FMT_FLAG_STATIC to mark statically allocated memory buffers and * @ref AI_FMT_FLAG_SCRATCH_BUFFER to tag temporary scratch buffers. * All the formats are declared in a proper tuple organize table header named * @ref format_lists.h that enumerates all the formats available for the library. * A new format could be added easily by adding a new FMY_ENTRY() as required. * The preprocessor automatically generates the code for the handling of the * format according to this tuples entry. A rational for the methodology could * be found here: * - https://codecraft.co/2012/10/29/how-enums-spread-disease-and-how-to-cure-it/ * * The 32bits internal format fields are organized as follows: * * MSB LSB * 31 25 24 23 21 17 14 7 0 * /---------------------------------------------------------------------------/ * / ATTR. FLAGS | FLOAT | SIGN | LDIV | TYPE | PMASK | BITS | FBITS / * /---------------------------------------------------------------------------/ * Where: * - FLAGS: is the reserved bits to store additional format attributes (e.g. * I/O / STATIC flags. etc.) * - FLOAT: 1 bit mark the format as floating point type * - SIGN : 1 bit mark the format as signed type * - LDIV : 2 bits is a log2 value that is used to compute elements size * with some special format such as the compressed ones. It is a shift * factor usually set to zero * - TYPE : 4 bits mark the format "family" type. Actually 5 families are coded, * @ref AI_FMT_FLOAT (float types) * @ref AI_FMT_Q (fixed-point types in Qm.n format) * @ref AI_FMT_BOOL (boolean type) * @ref AI_FMT_LUT4 (compressed lookup 16 formats) * @ref AI_FMT_LUT8 (compressed lookup 256 formats) * - PMASK 3 bits padding mask used to set the optional dimension for padding * to handle special aligned formats/ E.g. a 1 bit format * Usually this is set to 0x0 * - BITS 7 bits set the total number of bits of the element, padding bits * excluded. The bits are thus = sign bit + fractional bits + integer bits * The number of integer bits could thus be known using the @ref * AI_FMT_GET_IBITS() macro. * - FBITS 7 bits set the number of fractional bits in the format * * * A reference code snippet for usage is the test unit that uses this header: * * \include test/test_lcut_formats.cpp * */ /*! * Format bitfields definition. NOTE: 7 MSB are masked off * for (optional) atributes setting using flags. see @ref AI_FMT_FLAG_CONST that * is used for marking a data as constant readonly */ /* 1 bit field to identify floating point values*/ #define _FMT_FLOAT_MASK (0x1) #define _FMT_FLOAT_BITS (24) /*! 1 bit sign info */ #define _FMT_SIGN_MASK (0x1) #define _FMT_SIGN_BITS (23) /*! fractional bits field (i.e. for Q formats see @ref AI_FMT_Q) */ #define _FMT_FBITS_MASK (0x7F) #define _FMT_FBITS_BITS (0) #define _FMT_FBITS_BIAS ((_FMT_FBITS_MASK+1) >> 1) /*! TOTAL number of bits (fractional+integer+sign) (excluded padding ones) */ #define _FMT_BITS_MASK (0x7F) #define _FMT_BITS_BITS (7) #define _FMT_BITS_BIAS (0) /*! Padding bits for handling formats not aligned to multiples of 8 bits */ #define _FMT_PMASK_MASK (0x7) #define _FMT_PMASK_BITS (14) /*! bits reserved for identifying the family format, e.g. float, fixed-point..*/ #define _FMT_TYPE_MASK (0xF) #define _FMT_TYPE_BITS (17) #define _FMT_LDIV_MASK (0x3) #define _FMT_LDIV_BITS (21) /******************************************************************************/ #define AI_FMT_OBJ(fmt_) ((ai_array_format)(fmt_)) /*! * Only 25 LSB bits are used for storing actual format bits. 7 bits are reserved * for format attributes, see @ref AI_FMT_FLAG_CONST flag */ #define AI_FMT_FLAG_BITS (25) #define AI_FMT_MASK ((0x1<<AI_FMT_FLAG_BITS)-1) #define AI_FMT_FLAG_CONST (0x1<<30) #define AI_FMT_FLAG_STATIC (0x1<<29) #define AI_FMT_FLAG_SCRATCH_BUFFER (0x1<<28) #define AI_FMT_FLAG_IS_IO (0x1<<27) #define AI_FMT_FLAG_VISITED (0x1<<26) /******************************************************************************/ /*! * Format "Class" type : this identify the family of the format: * float, integer, fixed point (i.e. Q format), compressed via lookup table */ #define AI_FMT_NONE (0x0) #define AI_FMT_FLOAT (0x1) #define AI_FMT_Q (0x2) #define AI_FMT_BOOL (0x3) #define AI_FMT_LUT4 (0x4) #define AI_FMT_LUT8 (0x8) #define AI_FMT_QMASK \ ( (_FMT_FBITS_MASK<<_FMT_FBITS_BITS) | \ (_FMT_BITS_MASK<<_FMT_BITS_BITS) | \ (_FMT_PMASK_MASK<<_FMT_PMASK_BITS) ) #define AI_FMT_BINARY_MASK \ (AI_FMT_MASK & (~(_FMT_SIGN_MASK<<_FMT_SIGN_BITS))) #define AI_FMT_IS_BINARY(val_) \ (((val_) & AI_FMT_BINARY_MASK) == AI_ARRAY_FORMAT_U1) #define AI_FMT_GET(val_) \ ( (AI_FMT_OBJ(val_)) & AI_FMT_MASK ) #define AI_FMT_MASK_Q(val_) \ ( AI_FMT_OBJ(val_) & (~(AI_FMT_QMASK)) ) #define AI_FMT_GET_Q(val_) \ ( AI_FMT_MASK_Q(val_) | AI_FMT_SET_BITS(0) | AI_FMT_SET_FBITS(0) ) #define AI_FMT_GET_FLAGS(val_) \ ( ((AI_FMT_OBJ(val_)) & (~AI_FMT_MASK)) >> AI_FMT_FLAG_BITS ) #define AI_FMT_SAME(fmt1_, fmt2_) \ ( AI_FMT_GET(fmt1_) == AI_FMT_GET(fmt2_) ) #define _FMT_SET(val, mask, bits) AI_FMT_OBJ(((val)&(mask))<<(bits)) #define _FMT_GET(fmt, mask, bits) ((AI_FMT_OBJ(fmt)>>(bits))&(mask)) #define AI_FMT_SET_FLOAT(val) _FMT_SET(val, _FMT_FLOAT_MASK, _FMT_FLOAT_BITS) #define AI_FMT_GET_FLOAT(fmt) _FMT_GET(fmt, _FMT_FLOAT_MASK, _FMT_FLOAT_BITS) #define AI_FMT_SET_SIGN(val) _FMT_SET(val, _FMT_SIGN_MASK, _FMT_SIGN_BITS) #define AI_FMT_GET_SIGN(fmt) _FMT_GET(fmt, _FMT_SIGN_MASK, _FMT_SIGN_BITS) #define AI_FMT_SET_PMASK(val) _FMT_SET(val, _FMT_PMASK_MASK, _FMT_PMASK_BITS) #define AI_FMT_GET_PMASK(fmt) _FMT_GET(fmt, _FMT_PMASK_MASK, _FMT_PMASK_BITS) #define AI_FMT_SET_TYPE(val) _FMT_SET(val, _FMT_TYPE_MASK, _FMT_TYPE_BITS) #define AI_FMT_GET_TYPE(fmt) _FMT_GET(fmt, _FMT_TYPE_MASK, _FMT_TYPE_BITS) #define AI_FMT_SET_LDIV(val) _FMT_SET(val, _FMT_LDIV_MASK, _FMT_LDIV_BITS) #define AI_FMT_GET_LDIV(fmt) _FMT_GET(fmt, _FMT_LDIV_MASK, _FMT_LDIV_BITS) #define AI_FMT_SET_BITS(val) \ _FMT_SET((val) + _FMT_BITS_BIAS, _FMT_BITS_MASK, _FMT_BITS_BITS) #define AI_FMT_GET_BITS(fmt) \ ((ai_i8)_FMT_GET(fmt, _FMT_BITS_MASK, _FMT_BITS_BITS) - _FMT_BITS_BIAS) #define AI_FMT_SET_FBITS(val) \ _FMT_SET((val) + _FMT_FBITS_BIAS, _FMT_FBITS_MASK, _FMT_FBITS_BITS) #define AI_FMT_GET_FBITS(fmt) \ ((ai_i8)_FMT_GET(fmt, _FMT_FBITS_MASK, _FMT_FBITS_BITS) - _FMT_FBITS_BIAS) /*! * The total number of bits for a given format is supposed to be the sum of the * bits + padding bits. This means that the number of integer bits is derived * as follow: int_bits = bits - fbits (fractional bits) - 1 (for the sign) */ #define AI_FMT_GET_BITS_SIZE(fmt_) \ AI_FMT_GET_BITS(fmt_) /*! Macro used to compute the integer bits for a format */ #define AI_FMT_GET_IBITS(fmt_) \ ((ai_i16)AI_FMT_GET_BITS(fmt_)-AI_FMT_GET_FBITS(fmt_)-AI_FMT_GET_SIGN(fmt_)) /*! ai_buffer format handlers section *****************************************/ #define AI_BUFFER_FMT_MASK_Q(fmt_) \ ( AI_BUFFER_FMT_OBJ(fmt_) & 0xFFFFC000 ) #define AI_BUFFER_FMT_GET_Q(fmt_) \ ( AI_BUFFER_FMT_MASK_Q(fmt_) | AI_BUFFER_FMT_SET_FBITS(0) | \ AI_BUFFER_FMT_SET_FBITS(0) ) #define AI_BUFFER_FMT_SET_Q(bits_, fbits_) \ AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, bits_, fbits_) #define AI_BUFFER_FMT_IS_Q(fmt_) \ ( (AI_BUFFER_FMT_TYPE_Q==AI_BUFFER_FMT_GET_TYPE(fmt_)) && \ (1==AI_BUFFER_FMT_GET_SIGN(fmt_)) ) #define AI_BUFFER_FMT_SET_UQ(bits_, fbits_) \ AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, bits_, fbits_) #define AI_BUFFER_FMT_IS_UQ(fmt_) \ ( (AI_BUFFER_FMT_TYPE_Q==AI_BUFFER_FMT_GET_TYPE(fmt_)) && \ (0==AI_BUFFER_FMT_GET_SIGN(fmt_)) ) /*! Q ai_array format handlers ************************************************/ #define AI_ARRAY_FMT_Q(bits_, fbits_) \ ( AI_FMT_MASK_Q(AI_ARRAY_FORMAT_Q) | AI_FMT_SET_BITS(bits_) | AI_FMT_SET_FBITS(fbits_) ) #define AI_ARRAY_FMT_SET_Q(bits_, fbits_) \ AI_ARRAY_FMT_Q(bits_, fbits_) #define AI_ARRAY_FMT_IS_Q(fmt_) \ ( AI_FMT_GET(AI_FMT_MASK_Q(AI_ARRAY_FORMAT_Q))==AI_FMT_GET(AI_FMT_MASK_Q(fmt_)) ) #define AI_ARRAY_FMT_UQ(bits_, fbits_) \ ( AI_FMT_MASK_Q(AI_ARRAY_FORMAT_UQ) | AI_FMT_SET_BITS(bits_) | AI_FMT_SET_FBITS(fbits_) ) #define AI_ARRAY_FMT_SET_UQ(bits_, fbits_) \ AI_ARRAY_FMT_UQ(bits_, fbits_) #define AI_ARRAY_FMT_IS_UQ(fmt_) \ ( AI_FMT_GET(AI_FMT_MASK_Q(AI_ARRAY_FORMAT_UQ))==AI_FMT_GET(AI_FMT_MASK_Q(fmt_)) ) AI_DEPRECATED /* Alias for AI_ARRAY_FMT_SET_Q */ #define AI_ARRAY_FMT_SET_SQ(bits_, fbits_) \ AI_ARRAY_FMT_SET_Q(bits_, fbits_) AI_DEPRECATED /* Alias for AI_ARRAY_FMT_IS_Q */ #define AI_ARRAY_FMT_IS_SQ(fmt_) \ AI_ARRAY_FMT_IS_Q(fmt_) /*! ai_array section **********************************************************/ #define AI_ARRAY_FMT_ENTRY(name_) \ AI_CONCAT(AI_ARRAY_FORMAT_, name_) #define AI_ARRAY_FMT_NAME(fmt_) \ ai_array_fmt_name(fmt_) #define AI_ARRAY_FMT_VALID(fmt_) \ ai_array_fmt_valid(fmt_) #define AI_ARRAY_FMT_EXPORTED(fmt_) \ ai_array_fmt_exported(fmt_) #define AI_ARRAY_FMT_GET_FORMATS(formats_) \ ai_array_fmt_get_formats(formats_) #define AI_ARRAY_TO_BUFFER_FMT(fmt_) \ ai_array_to_buffer_fmt(fmt_) #define AI_ARRAY_GET_BYTE_SIZE(fmt_, count_) \ ai_array_get_byte_size(fmt_, count_) #define AI_ARRAY_GET_DATA_BYTE_SIZE(fmt_, count_) \ ai_array_get_data_byte_size(fmt_, count_) #define AI_ARRAY_GET_ELEMS_FROM_SIZE(fmt_, size_) \ ai_array_get_elems_from_size(fmt_, size_) AI_API_DECLARE_BEGIN /*! * @typedef ai_array_format * @ingroup ai_datatypes_format * @brief Generic Data Format Specifier for @ref ai_array (32bits packed info) */ typedef int32_t ai_array_format; /*! * @enum internal data format enums * @ingroup ai_datatypes_format * @brief Generic Data Format Specifier (32bits packed info) */ typedef enum { #define FMT_ENTRY(exp_, name_, type_id_, sign_bit_, float_bit_, \ pmask_, bits_, fbits_, ldiv_bits_) \ AI_ARRAY_FMT_ENTRY(name_) = (AI_FMT_SET_FLOAT(float_bit_) | \ AI_FMT_SET_SIGN(sign_bit_) | \ AI_FMT_SET_BITS(bits_) | \ AI_FMT_SET_FBITS(fbits_) | \ AI_FMT_SET_PMASK(pmask_) | \ AI_FMT_SET_TYPE(type_id_) | \ AI_FMT_SET_LDIV(ldiv_bits_)), #include "formats_list.h" } ai_array_format_entry; /*! * @brief Get a human readable string from the format ID value * @ingroup ai_datatypes_format * @param[in] type the @ref ai_array_format to print out * @return a string with a human readable name of the format */ AI_INTERNAL_API const char* ai_array_fmt_name(const ai_array_format type); /*! * @brief Check if @ref ai_array_format is a exportable to an @ref ai_buffer_format * @ingroup ai_datatypes_format * @param[in] type the ai_array_format to check * @return true if the format is exported, false otherwise */ AI_INTERNAL_API ai_bool ai_array_fmt_exported(const ai_array_format type); /*! * @brief Check if @ref ai_array_format is a valid format present in the list of * supported formats * @ingroup ai_datatypes_format * @param[in] type the ai_array_format to check * @return true if the format is valid, false otherwise */ AI_INTERNAL_API ai_bool ai_array_fmt_valid(const ai_array_format type); /*! * @brief Get the complete list of supported @ref ai_array_format formats * @ingroup ai_datatypes_format * @param[out] formats a pointer to an array withj all supported formats listed * @return the number of supported formats */ AI_INTERNAL_API ai_size ai_array_fmt_get_formats(const ai_array_format** formats); /*! ai_buffer section ********************************************************* * Only 25 LSB bits are used for storing actual format bits. 7 bits are reserved * for format atrtributes, see @ref AI_FMT_FLAG_CONST flag */ #define AI_BUFFER_FMT_ENTRY(name_) \ AI_CONCAT(AI_BUFFER_FORMAT_, name_) #define AI_BUFFER_FMT_NAME(type_) \ ai_buffer_fmt_name(type_) #define AI_BUFFER_FMT_VALID(type_) \ ai_buffer_fmt_valid(type_) #define AI_BUFFER_FMT_GET_FORMATS(formats_) \ ai_buffer_fmt_get_formats(formats_) #define AI_BUFFER_TO_ARRAY_FMT(fmt_) \ ai_buffer_to_array_fmt(fmt_) #define AI_BUFFER_GET_BITS_SIZE(fmt) \ AI_ARRAY_GET_BITS_SIZE(AI_BUFFER_TO_ARRAY_FMT(fmt)) /*! * @brief Get a human readable string from the format ID value * @ingroup ai_datatypes_format * @param[in] type the @ref ai_buffer_format to print out * @return a string with a human readable name of the format */ AI_INTERNAL_API const char* ai_buffer_fmt_name( const ai_buffer_format type); /*! * @brief Check if @ref ai_buffer_format is a valid format present in the list * of supported formats * @ingroup ai_datatypes_format * @param[in] type the @ref ai_buffer_format to check * @return true if the format is valid, false otherwise */ AI_INTERNAL_API ai_bool ai_buffer_fmt_valid( const ai_buffer_format type); /*! * @brief Get the complete list of supported @ref ai_buffer_format formats * @ingroup ai_datatypes_format * @param[out] formats a pointer to an array with all supported formats listed * @return the number of supported formats */ AI_INTERNAL_API ai_size ai_buffer_fmt_get_formats( const ai_buffer_format** formats); /*! Conversions section *******************************************************/ /*! * @brief Convert from ai_array_format to ai_buffer_format. * @ingroup ai_datatypes_format * @param fmt the input ai_array_format to convert * @return the converted format as a ai_buffer_format */ AI_INTERNAL_API ai_buffer_format ai_array_to_buffer_fmt( const ai_array_format fmt); /*! * @brief Convert from ai_buffer_format to ai_array_format. * @ingroup ai_datatypes_format * @param fmt the input ai_buffer_format to convert * @return the converted format as a ai_array_format */ AI_INTERNAL_API ai_array_format ai_buffer_to_array_fmt( const ai_buffer_format fmt); /** helpers section ***********************************************************/ /*! * @brief Computes the size in bytes given an ai_array_format and number of * array elements. * @details This routine computes from the number of elements of the array its * size in bytes. If the array is referred by a tensor structure, it is the task * of the latter to handle per-dimension padding (e.g. to align odd rows in a * 4-bit matrix. At array level the padding elements MUST be included in the * number of elements. * @ingroup ai_datatypes_format * @param[in] fmt the input array format as an ai_array_format * @param[in] count the number of elements stored in the data array * @return the size in bytes of the array given the specific format and number * of elements (including padding elements) */ AI_INTERNAL_API ai_size ai_array_get_byte_size( const ai_array_format fmt, const ai_size count); /*! * @brief Computes the size in bytes given an ai_array_format and number of * array elements of the data fields (e.g. LUT table size excluded). * @details This routine computes from the number of elements of the array its * size in bytes. If the array is referred by a tensor structure, it is the task * of the latter to handle per-dimension padding (e.g. to align odd rows in a * 4-bit matrix. At array level the padding elements MUST be included in the * number of elements. * @ingroup ai_datatypes_format * @param[in] fmt the input array format as an ai_array_format * @param[in] count the number of elements stored in the data array * @return the size in bytes of the array given the specific format and number * of elements (including padding elements) */ AI_INTERNAL_API ai_size ai_array_get_data_byte_size( const ai_array_format fmt, const ai_size count); /*! * @brief Computes the number of elements from ai_array_format and * the size in byte of the array. * @ingroup ai_datatypes_format * @param fmt the input array format as an ai_array_format * @param size the size in bytes of the array * @return the number of elements that could be stored given the format */ AI_INTERNAL_API ai_size ai_array_get_elems_from_size( const ai_array_format fmt, const ai_size byte_size); AI_API_DECLARE_END #endif /*AI_DATATYPES_FORMAT_H*/
18,640
C
36.965377
91
0.635569
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/core_net_inspect.h
/** ****************************************************************************** * @file core_net_inspect.h * @author AST Embedded Analytics Research Platform * @brief header file of core network inspection APIs ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef __CORE_NET_INSPECT_H_ #define __CORE_NET_INSPECT_H_ #pragma once #include "core_net_inspect_interface.h" #include "core_common.h" #include "layers_common.h" /*! * @defgroup core_net_inspect Core Network Inspection routines * @brief Implementation of core network inspection routines that allows to * inspect on a node basis a generated network model * @details A network context @ref ai_network basically contains a chained list * of nodes @ref ai_node that have an associated forward function. * Each ai)network context and ai_node datastructs have as a required member * field an opaque handler (i.e. a void pointer) to a klass object. * This handler is intended to be used as a platform specific node context * that implements specific target platform routines. * The inspector module basically acts as a plugin that exploiting these features * by temporary creating an hidden inspection context (see * @ref ai_core_inspect_net_klass) associated to the network and * linking it by re-routing the klass field to this inspection context. The * inspection context saves as part of its state (by a stack push operation), the * internal state of the network (all node / network klass pointers and actual * forward functions). * Thus, for each node it re-routes all node's forward functions to a dedicated * inspection forward function (see @ref _forward_inspect_validate() routine) * This routine is the core of the mechanism and it allows to inspect a network * node by node. Some additional inspection could thus be done inside the * _forward_inspect_validate() routine before and after the actual node * forward function is called; * */ AI_API_DECLARE_BEGIN /*! * @defgroup core_net_inspect Network Inspection Core * @brief Implementation of the validation network routines */ /*! * @brief Initialize the network inspection context on a given network * @ingroup core net inspect * @param network opaque handler to the network instance * @param cfg a pointer to the inspector configuration we want to use * @return true if execution of the API is fine, false otherwise */ AI_API_ENTRY ai_bool ai_network_inspect_init( ai_handle network, const ai_inspect_config* cfg); /*! * @brief Get a summary report from the inspected network * @ingroup core net inspect * @param network opaque handler to the network instance * @param report a pointer to the report provided back by the inspection * @return true if execution of the API is fine, false otherwise */ AI_API_ENTRY ai_bool ai_network_inspect_get_report( ai_handle network, ai_inspect_net_report* report); /*! * @brief Destroy the network inspection context on a given network * @ingroup core net inspect * @param network opaque handler to the network instance * @return true if execution of the API is fine, false otherwise */ AI_API_ENTRY ai_bool ai_network_inspect_destroy(ai_handle network); AI_API_DECLARE_END #endif /*__CORE_NET_INSPECT_H_*/
3,780
C
37.581632
81
0.682804
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_nl_generic_integer.h
#ifndef LITE_NL_GENERIC_INTEGER_H #define LITE_NL_GENERIC_INTEGER_H #pragma once #include "ai_lite_interface.h" /** * @brief forward lite function for a s8 softmax non-linearity where the softmax is applied per channel. * @ingroup lite_nl_generic_integer * @param output The pointer to output buffer (s8). * @param input The pointer to input buffer (s8). * @param in_size. The size of the input (including channels). * @param ch_size The nsize of each channel. * @param in_ch_step The step between consecutive elements (inputs) * @param out_ch_step The step between consecutive elements (outputs) * @param mult * @param shift * @param min_diff */ LITE_API_ENTRY void forward_lite_nl_softmax_is8os8( ai_i8* out_ptr, const ai_i8* in_ptr, const ai_size in_size, const ai_size ch_size, const ai_i32 in_ch_step, const ai_i32 out_ch_step, const ai_i32 mult, const ai_i32 shift, const ai_i32 min_diff, ai_i32* scratch); /** * @brief forward lite function for a u8 softmax non-linearity where the softmax is applied per channel. * @ingroup lite_nl_generic_integer * @param output The pointer to output buffer (s8). * @param input The pointer to input buffer (s8). * @param in_size. The size of the input (including channels). * @param ch_size The nsize of each channel. * @param in_ch_step The step between consecutive elements (inputs) * @param out_ch_step The step between consecutive elements (outputs) * @param mult * @param shift * @param min_diff */ LITE_API_ENTRY void forward_lite_nl_softmax_iu8ou8( ai_u8* out_ptr, const ai_u8* in_ptr, const ai_size in_size, const ai_size ch_size, const ai_i32 in_ch_step, const ai_i32 out_ch_step, const ai_i32 mult, const ai_i32 shift, const ai_i32 min_diff, ai_i32* scratch); #endif /* LITE_NL_GENERIC_INTEGER_H */
1,815
C
34.607842
104
0.713499
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_datatypes.h
/** ****************************************************************************** * @file ai_datatypes.h * @author AST Embedded Analytics Research Platform * @brief Definitions of AI platform private APIs types ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_DATATYPES_H #define AI_DATATYPES_H #pragma once #include <string.h> #include "ai_platform.h" #include "ai_platform_interface.h" /*! * @defgroup datatypes Platform Interface Datatypes * @brief Data structures used by AI platform to implement neural networks * */ /** Count Variable Number of Arguments (up to 64 elements) *******************/ #define AI_NUMARGS(...) \ PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) #define PP_NARG_(...) \ PP_ARG_N(__VA_ARGS__) #define PP_ARG_N( \ _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \ _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ _61,_62,_63,N,...) N #define PP_RSEQ_N() \ 63,62,61,60, \ 59,58,57,56,55,54,53,52,51,50, \ 49,48,47,46,45,44,43,42,41,40, \ 39,38,37,36,35,34,33,32,31,30, \ 29,28,27,26,25,24,23,22,21,20, \ 19,18,17,16,15,14,13,12,11,10, \ 9,8,7,6,5,4,3,2,1,0 /*****************************************************************************/ #define AI_PTR_ALIGN(ptr, alignment) \ ((((ai_uptr)(ptr))+((ai_uptr)(alignment)-1))&(~((ai_uptr)(alignment)-1))) /*! * @typedef ai_offset * @ingroup ai_datatypes_internal * @brief Generic index offset type */ typedef int32_t ai_offset; AI_API_DECLARE_BEGIN AI_API_DECLARE_END #endif /* AI_DATATYPES_H */
2,349
C
29.51948
80
0.473819
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_common_config.h
/** ****************************************************************************** * @file ai_common_config.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform common compile configuration defines ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_COMMON_CONFIG_H #define AI_COMMON_CONFIG_H #pragma once /*! * @defgroup layers Layers Compilation Config Definitions * @brief definition * */ #define HAS_PROFILE_FLOAT #define HAS_PROFILE_FIXED #endif /*AI_COMMON_CONFIG_H*/
1,070
C
28.749999
80
0.495327
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_pw_dqnn.h
/** ****************************************************************************** * @file lite_pw_dqnn.h * @author AIS * @brief header file of AI platform lite pw kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_PW_DQNN_H #define LITE_PW_DQNN_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles point wise convolution with binary input, binary output and * binary weights - Lite API version * @ingroup lite_pw_dqnn */ LITE_API_ENTRY void forward_lite_pw_is1os1ws1_bn(const ai_u32 *pDataIn_init, ai_u32 *pDataOut_init, const ai_u32 *pWeights_init, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 *pThreshold); /*! * @brief Handles point wise convolution with binary input, binary output and * binary weights - Lite API version - Optimized thanks to Optim2 * assumptions * @ingroup lite_pw_dqnn */ LITE_API_ENTRY void forward_lite_pw_is1os1ws1_bn_optim2(const ai_u32 *pDataIn_init, ai_u32 *pDataOut_init, const ai_u32 *pWeights_init, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_out, const ai_i32 height_out, const ai_i32 *pThreshold); /*! * @brief Handles point wise convolution with binary input, 8-bits output and * binary weights - Lite API version * @ingroup lite_pw_dqnn */ LITE_API_ENTRY void forward_lite_pw_is1os8ws1_bn(const ai_u32 *pDataIn_init, ai_i8 *pDataOut_init, const ai_u32 *pWeights_init, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_out, const ai_i32 height_out, const ai_float *pScale, const ai_float *pOffset); /*! * @brief Handles point wise convolution with binary input, 8-bits output and * binary weights - Lite API version - Optimized thanks to Optim1 * assumptions * @ingroup lite_pw_dqnn */ LITE_API_ENTRY void forward_lite_pw_is1os8ws1_bn_optim1(const ai_u32 *pDataIn_init, ai_i8 *pDataOut_init, const ai_u32 *pWeights_init, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_out, const ai_i32 height_out, const ai_float *pScale, const ai_float *pOffset); /*! * @brief Handles point-wise convolution with binary input, float32 output * and binary weights - Lite API version * @ingroup lite_pw_dqnn */ LITE_API_ENTRY void forward_lite_pw_is1of32ws1_bn(const ai_u32 *pDataIn_init, ai_float *pDataOut_init, const ai_u32 *pWeights_init, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_out, const ai_i32 height_out, const ai_float *pScale, const ai_float *pOffset); /*! * @brief Handles point-wise convolution with binary input, float32 output * and binary weights - Lite API version - Optimized thanks to Optim1 * assumptions * @ingroup lite_pw_dqnn */ LITE_API_ENTRY void forward_lite_pw_is1of32ws1_bn_optim1(const ai_u32 *pDataIn_init, ai_float *pDataOut_init, const ai_u32 *pWeights_init, const ai_u32 n_channel_in, const ai_u32 n_channel_out, const ai_i32 width_out, const ai_i32 height_out, const ai_float *pScale, const ai_float *pOffset); #endif /*LITE_PW_DQNN_H*/
5,632
C
42
80
0.430753
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/ai_platform.h
/** ****************************************************************************** * @file ai_platform.h * @author AST Embedded Analytics Research Platform * @brief Definitions of AI platform public APIs types ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef AI_PLATFORM_H #define AI_PLATFORM_H #pragma once #include <stdint.h> #include <stddef.h> #include <inttypes.h> #ifndef AI_PLATFORM_API_MAJOR #define AI_PLATFORM_API_MAJOR (1) #endif #ifndef AI_PLATFORM_API_MINOR #define AI_PLATFORM_API_MINOR (2) #endif #ifndef AI_PLATFORM_API_MICRO #define AI_PLATFORM_API_MICRO (0) #endif #define AI_PLATFORM_API_VERSION \ AI_VERSION(AI_PLATFORM_API_MAJOR, \ AI_PLATFORM_API_MINOR, \ AI_PLATFORM_API_MICRO) #ifndef AI_TOOLS_API_VERSION_MAJOR #define AI_TOOLS_API_VERSION_MAJOR (1) #endif #ifndef AI_TOOLS_API_VERSION_MINOR #define AI_TOOLS_API_VERSION_MINOR (5) #endif #ifndef AI_TOOLS_API_VERSION_MICRO #define AI_TOOLS_API_VERSION_MICRO (0) #endif /*****************************************************************************/ #define AI_TOOLS_API_VERSION \ AI_VERSION(AI_TOOLS_API_VERSION_MAJOR, \ AI_TOOLS_API_VERSION_MINOR, \ AI_TOOLS_API_VERSION_MICRO) #define AI_TOOLS_API_VERSION_1_3 \ AI_VERSION(1, 3, 0) #define AI_TOOLS_API_VERSION_1_4 \ AI_VERSION(1, 4, 0) #define AI_TOOLS_API_VERSION_1_5 \ AI_VERSION(1, 5, 0) /*****************************************************************************/ #ifdef __cplusplus #define AI_API_DECLARE_BEGIN extern "C" { #define AI_API_DECLARE_END } #else #include <stdbool.h> #define AI_API_DECLARE_BEGIN /* AI_API_DECLARE_BEGIN */ #define AI_API_DECLARE_END /* AI_API_DECLARE_END */ #endif /*****************************************************************************/ #define AI_FLAG_NONE (0x0) /*****************************************************************************/ AI_API_DECLARE_BEGIN /*! * @typedef ai_flags * @ingroup ai_platform * @brief bitmask for flags management */ typedef uint32_t ai_flags; /*****************************************************************************/ #define AI_CONCAT_ARG(a, b) a ## b #define AI_CONCAT(a, b) AI_CONCAT_ARG(a, b) /*! AI_CAST SECTION ***********************************/ #define AI_CAST(type_, expr_) ((type_)(expr_)) /*****************************************************************************/ #define AI_MAGIC_SIGNATURE \ (0xa1facade) #define AI_PACK(...) \ __VA_ARGS__ /*****************************************************************************/ #define AI_SHAPE_BCWH (0x01u) /*! * @typedef ai_shape_dimension * @ingroup ai_platform * @brief shape dimension type to be used in shape related structs @ref ai_buffer_shape */ typedef uint32_t ai_shape_dimension; /*****************************************************************************/ #if defined(_MSC_VER) #define AI_API_ENTRY __declspec(dllexport) #define AI_ALIGNED(x) /* AI_ALIGNED(x) */ #elif defined(__ICCARM__) || defined (__IAR_SYSTEMS_ICC__) #define AI_API_ENTRY /* AI_API_ENTRY */ #define AI_ALIGNED(x) AI_CONCAT(AI_ALIGNED_,x) #define AI_ALIGNED_1 _Pragma("data_alignment = 1") #define AI_ALIGNED_2 _Pragma("data_alignment = 2") #define AI_ALIGNED_4 _Pragma("data_alignment = 4") #define AI_ALIGNED_8 _Pragma("data_alignment = 8") #define AI_ALIGNED_16 _Pragma("data_alignment = 16") #define AI_ALIGNED_32 _Pragma("data_alignment = 32") #elif defined(__CC_ARM) #define AI_API_ENTRY __attribute__((visibility("default"))) #define AI_ALIGNED(x) __attribute__((aligned (x))) /* Keil disallows anonymous union initialization by default */ #pragma anon_unions #elif defined(__GNUC__) //#define AI_API_ENTRY __attribute__((visibility("default"))) #define AI_API_ENTRY /* AI_API_ENTRY */ #define AI_ALIGNED(x) __attribute__((aligned(x))) #else /* Dynamic libraries are not supported by the compiler */ #define AI_API_ENTRY /* AI_API_ENTRY */ #define AI_ALIGNED(x) /* AI_ALIGNED(x) */ #endif #define AI_HANDLE_PTR(ptr_) ((ai_handle)(ptr_)) #define AI_HANDLE_NULL AI_HANDLE_PTR(NULL) #define AI_HANDLE_FUNC_PTR(func) ((ai_handle_func)(func)) #define AI_UNUSED(x) (void)(x); #define AI_DEPRECATED /* AI_DEPRECATED */ #define AI_LEGACY /* AI_LEGACY */ #define AI_MAGIC_MARKER (0xA1FACADE) #if defined(__cplusplus) #define AI_STRUCT_INIT {} #define AI_C_ARRAY_INIT {} #else #define AI_STRUCT_INIT {0} #define AI_C_ARRAY_INIT {0} #endif #define AI_ERROR_FMT AIU32_FMT #define AI_IS_UNSIGNED(type) \ ((((type)0) - 1) > 0) #define AI_CUSTOM_SIZE(type) \ (ai_custom_type_signature)((AI_IS_UNSIGNED(type)) \ ? (0x80|(sizeof(type)&0x7f)) : (sizeof(type)&0x7f)) /*! network buffers struct handlers *******************************************/ #ifdef __cplusplus #define AI_NETWORK_PARAMS_INIT(params_, activations_) \ { \ {{ params_, activations_ }} \ } #define AI_NETWORK_BUFFERS_INIT(weights_buffers_, activations_buffers_) \ { \ AI_MAGIC_SIGNATURE, AI_PACK(weights_buffers_), AI_PACK(activations_buffers_) \ } #else #define AI_NETWORK_PARAMS_INIT(params_, activations_) \ { \ .params = params_, \ .activations = activations_ \ } #define AI_NETWORK_BUFFERS_INIT(weights_buffers_, activations_buffers_) \ { \ .map_signature = AI_MAGIC_SIGNATURE, \ .map_weights = AI_PACK(weights_buffers_), \ .map_activations = AI_PACK(activations_buffers_) \ } #endif // __cplusplus /*! binary padded bits macro helpers *****************************************/ #define AI_PBITS_MASK \ (0x1F) #define AI_PBITS_SHIFTS \ (5) #define AI_PBITS_PADDED_BYTES_COUNT(bits_) \ (((ai_u32)(bits_) + 7) >> 3) #define AI_PBITS_PADDED_WORDS_COUNT(bits_) \ (((ai_size)(bits_) + AI_PBITS_MASK) >> AI_PBITS_SHIFTS) #define AI_PBITS_GET_WORD(word_ptr_, bits_) \ (((ai_pbits*)(word_ptr_)) + ((bits_) >> AI_PBITS_SHIFTS)) #define AI_PAD_CHANNELS(format_, channels_) \ ((AI_BUFFER_FMT_GET_BITS(format_)==1) ? (AI_PBITS_PADDED_WORDS_COUNT(channels_) << AI_PBITS_SHIFTS) : (channels_)) /*! ai_intq_info struct handlers *********************************************/ #define INTQ_CONST const // #define INTQ_CONST #define AI_INTQ_INFO_LIST(list_) \ ((list_)->info) #define AI_INTQ_INFO_LIST_FLAGS(list_) \ ((list_) ? (list_)->flags : 0) #define AI_INTQ_INFO_LIST_SIZE(list_) \ ((list_) ? (list_)->size : 0) #define AI_HAS_INTQ_INFO_LIST(list_) \ ((list_) ? (((list_)->info) && ((list_)->size>0)) : false) #define AI_INTQ_INFO_LIST_SCALE(list_, type_, pos_) \ (((list_) && (list_)->info && ((pos_)<(list_)->size)) \ ? ((type_*)((list_)->info->scale))[(pos_)] : 0) #define AI_INTQ_INFO_LIST_ZEROPOINT(list_, type_, pos_) \ (((list_) && (list_)->info && ((pos_)<(list_)->size)) \ ? ((type_*)((list_)->info->zeropoint))[(pos_)] : 0) /*! ai_buffer format handlers ************************************************/ /*! * @enum buffer format definition * @ingroup ai_platform * * 32 bit signed format list. */ typedef int32_t ai_buffer_format; /*! ai_buffer_meta flags & macros ********************************************/ #define AI_BUFFER_META_HAS_INTQ_INFO (0x1U << 0) #define AI_BUFFER_META_FLAG_SCALE_FLOAT (0x1U << 0) #define AI_BUFFER_META_FLAG_ZEROPOINT_U8 (0x1U << 1) #define AI_BUFFER_META_FLAG_ZEROPOINT_S8 (0x1U << 2) #define AI_BUFFER_META_FLAG_ZEROPOINT_U16 (0x1U << 3) #define AI_BUFFER_META_FLAG_ZEROPOINT_S16 (0x1U << 4) /*! ai_buffer format variable flags & macros *********************************/ #define AI_BUFFER_FMT_TYPE_NONE (0x0) #define AI_BUFFER_FMT_TYPE_FLOAT (0x1) #define AI_BUFFER_FMT_TYPE_Q (0x2) #define AI_BUFFER_FMT_TYPE_BOOL (0x3) #define AI_BUFFER_FMT_FLAG_CONST (0x1U<<30) #define AI_BUFFER_FMT_FLAG_STATIC (0x1U<<29) #define AI_BUFFER_FMT_FLAG_IS_IO (0x1U<<27) #define AI_BUFFER_FMT_FLAG_PERSISTENT (0x1U<<29) #define AI_BUFFER_FMT_PACK(value_, mask_, bits_) \ ( ((value_) & (mask_)) << (bits_) ) #define AI_BUFFER_FMT_UNPACK(fmt_, mask_, bits_) \ ( (AI_BUFFER_FMT_OBJ(fmt_) >> (bits_)) & (mask_) ) #define AI_BUFFER_FMT_OBJ(fmt_) \ ((ai_buffer_format)(fmt_)) #define AI_BUFFER_FMT_GET_FLOAT(fmt_) \ AI_BUFFER_FMT_UNPACK(fmt_, 0x1, 24) #define AI_BUFFER_FMT_GET_SIGN(fmt_) \ AI_BUFFER_FMT_UNPACK(fmt_, 0x1, 23) #define AI_BUFFER_FMT_GET_TYPE(fmt_) \ AI_BUFFER_FMT_UNPACK(fmt_, 0xF, 17) #define AI_BUFFER_FMT_GET_BITS(fmt_) \ AI_BUFFER_FMT_UNPACK(fmt_, 0x7F, 7) #define AI_BUFFER_FMT_SET_BITS(bits_) \ AI_BUFFER_FMT_PACK((bits_), 0x7F, 7) #define AI_BUFFER_FMT_GET_FBITS(fmt_) \ ( (ai_i8)AI_BUFFER_FMT_UNPACK(fmt_, 0x7F, 0) - 64 ) #define AI_BUFFER_FMT_SET_FBITS(fbits_) \ AI_BUFFER_FMT_PACK((fbits_)+64, 0x7F, 0) #define AI_BUFFER_FMT_SET(type_id_, sign_bit_, float_bit_, bits_, fbits_) \ AI_BUFFER_FMT_OBJ( \ AI_BUFFER_FMT_PACK(float_bit_, 0x1, 24) | \ AI_BUFFER_FMT_PACK(sign_bit_, 0x1, 23) | \ AI_BUFFER_FMT_PACK(0, 0x3, 21) | \ AI_BUFFER_FMT_PACK(type_id_, 0xF, 17) | \ AI_BUFFER_FMT_PACK(0, 0x7, 14) | \ AI_BUFFER_FMT_SET_BITS(bits_) | \ AI_BUFFER_FMT_SET_FBITS(fbits_) \ ) #define AI_BUFFER_FMT_SAME(fmt1_, fmt2_) \ ( AI_BUFFER_FMT_GET(fmt1_) == AI_BUFFER_FMT_GET(fmt2_) ) #define AI_BUFFER_FMT_GET(fmt_) \ (AI_BUFFER_FMT_OBJ(fmt_) & 0x01FFFFFF) #define AI_BUFFER_FORMAT(buf_) \ AI_BUFFER_FMT_GET((buf_)->format) /*! * @define shape type index * @ingroup ai_platform * @brief positional ID for generic shapes C structs */ #define AI_SHAPE_EXTENSION (0x5) #define AI_SHAPE_DEPTH (0x4) #define AI_SHAPE_HEIGHT (0x3) #define AI_SHAPE_WIDTH (0x2) #define AI_SHAPE_CHANNEL (0x1) #define AI_SHAPE_IN_CHANNEL (0x0) #define AI_SHAPE_BATCH (0x0) #define AI_SHAPE_TIME (0x0) AI_DEPRECATED #define AI_BUFFER_WIDTH(buf_) \ ((buf_)->shape.data[AI_SHAPE_WIDTH]) AI_DEPRECATED #define AI_BUFFER_HEIGHT(buf_) \ ((buf_)->shape.data[AI_SHAPE_HEIGHT]) AI_DEPRECATED #define AI_BUFFER_CHANNELS(buf_) \ ((buf_)->shape.data[AI_SHAPE_CHANNEL]) AI_DEPRECATED #define AI_BUFFER_N_BATCHES(buf_) \ ((buf_)->shape.data[AI_SHAPE_BATCH]) #define AI_BUFFER_DATA(buf_, type_) \ ((type_*)((buf_)->data)) #define AI_BUFFER_META_INFO(buf_) \ ((buf_)->meta_info) #define AI_BUFFER_META_INFO_INTQ(meta_) \ ((meta_) && ((meta_)->flags & AI_BUFFER_META_HAS_INTQ_INFO)) \ ? ((meta_)->intq_info) : NULL #define AI_BUFFER_META_INFO_INTQ_GET_SIZE(meta_) \ ( (AI_BUFFER_META_INFO_INTQ(meta_)) \ ? AI_INTQ_INFO_LIST_SIZE(AI_BUFFER_META_INFO_INTQ(meta_)) \ : 0 ) #define AI_BUFFER_META_INFO_INTQ_GET_SCALE(meta_, pos_) \ ( (AI_BUFFER_META_INFO_INTQ(meta_)) \ ? AI_INTQ_INFO_LIST_SCALE(AI_BUFFER_META_INFO_INTQ(meta_), ai_float, pos_) \ : 0 ) #define AI_BUFFER_META_INFO_INTQ_GET_ZEROPOINT(meta_, pos_) \ ( (AI_BUFFER_META_INFO_INTQ(meta_)) \ ? ((AI_INTQ_INFO_LIST_FLAGS(AI_BUFFER_META_INFO_INTQ(meta_))&AI_BUFFER_META_FLAG_ZEROPOINT_U8) \ ? AI_INTQ_INFO_LIST_ZEROPOINT(AI_BUFFER_META_INFO_INTQ(meta_), ai_u8, pos_) \ : AI_INTQ_INFO_LIST_ZEROPOINT(AI_BUFFER_META_INFO_INTQ(meta_), ai_i8, pos_) ) \ : 0 ) #define AI_BUFFER_META_INFO_INIT(flags_, intq_info_) { \ .flags = (flags_), \ .intq_info = AI_PACK(intq_info_) \ } #define AI_BUFFER_SIZE(buf_) \ ai_buffer_get_size(buf_, true) #define AI_BUFFER_SIZE_UNPAD(buf_) \ ai_buffer_get_size(buf_, false) #define AI_BUFFER_BYTE_SIZE(count_, fmt_) \ ai_buffer_get_byte_size(count_, fmt_) #define AI_BUFFER_FLAGS(buf_) \ ((buf_) ? (buf_)->flags : 0x0) #define AI_BUFFER_SHAPE_INIT(type_, size_, ...) \ { \ .type = (type_), \ .size = (size_), \ .data = (ai_shape_dimension[]){ __VA_ARGS__ } \ } #define AI_BUFFER_SHAPE_INIT_FROM_ARRAY(type_, size_, array_ptr_) \ { \ .type = (type_), \ .size = (size_), \ .data = (ai_shape_dimension*)(array_ptr_) \ } #define AI_BUFFER_SHAPE_SIZE(buf_) \ ((buf_) ? (buf_)->shape.size : 0) #define AI_BUFFER_SHAPE_TYPE(buf_) \ ((buf_) ? (buf_)->shape.type : 0) #if defined(HAS_AI_ASSERT) && defined(AI_ASSERT) #define AI_BUFFER_SET_SHAPE_ELEM(buf_, pos_, value_) { \ AI_ASSERT(buf_) \ (buf_)->shape.data[pos_] = (value_); \ } #define AI_BUFFER_SHAPE_ELEM(buf_, pos_) \ (((pos_)<AI_BUFFER_SHAPE_SIZE(buf_)) ? (buf_)->shape.data[pos_] : 0) #else #define AI_BUFFER_SET_SHAPE_ELEM(buf_, pos_, value_) { \ (buf_)->shape.data[pos_] = (value_); \ } #define AI_BUFFER_SHAPE_ELEM(buf_, pos_) \ (buf_)->shape.data[pos_] #endif AI_DEPRECATED #define AI_BUFFER_OBJ_INIT(format_, h_, w_, ch_, n_batches_, data_) \ { .format = (ai_buffer_format)(format_), \ .data = (ai_handle)(data_), \ .meta_info = NULL, \ .flags = AI_FLAG_NONE, \ .size = (h_) * (w_) * AI_PAD_CHANNELS(format_, ch_), \ .shape = AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, (n_batches_), (ch_), (w_), (h_)), \ } AI_DEPRECATED #define AI_BUFFER_OBJ_INIT_STATIC(type_, format_, h_, w_, ch_, n_batches_, ...) \ { .format = (ai_buffer_format)(format_), \ .data = (ai_handle)((type_[]){__VA_ARGS__}), \ .meta_info = NULL, \ .flags = AI_FLAG_NONE, \ .size = (h_) * (w_) * AI_PAD_CHANNELS(format_, ch_), \ .shape = AI_BUFFER_SHAPE_INIT(AI_SHAPE_BCWH, 4, (n_batches_), (ch_), (w_), (h_)) \ } /* 7.1 new macro API */ #define AI_BUFFER_INIT(flags_, format_, shape_, size_, meta_info_, data_) \ { .format = (ai_buffer_format)(format_), \ .data = (ai_handle)(data_), \ .meta_info = (meta_info_), \ .flags = (flags_), \ .size = (size_), \ .shape = AI_PACK(shape_) \ } /* 7.1 new macro API */ #define AI_BUFFER_INIT_STATIC(type_, flags_, format_, shape_, size_, meta_info_, ...) \ { .format = (ai_buffer_format)(format_), \ .data = (ai_handle)((type_[]){__VA_ARGS__}), \ .meta_info = (meta_info_), \ .flags = (flags_), \ .size = (size_), \ .shape = AI_PACK(shape_) \ } /*****************************************************************************/ #define AI_NETWORK_BUFFERS_FIELD_DECLARE \ ai_signature map_signature; /*! structure signature (required!) */ \ ai_buffer_array map_weights; /*! info about weights array buffers (required!) */ \ ai_buffer_array map_activations; /*! info about activations array buffers (required!) */ #define AI_NETWORK_PARAMS_FIELDS_DECLARE \ union { \ struct { \ ai_buffer params; /*! info about params buffer(required!) */ \ ai_buffer activations; /*! info about activations buffer (required!) */ \ }; \ struct { \ AI_NETWORK_BUFFERS_FIELD_DECLARE \ }; \ }; /*****************************************************************************/ #define AI_BUFFER_ARRAY_OBJ_INIT(flags_, size_, buffer_array_) \ { \ .flags = (ai_u16)(flags_), \ .size = (ai_u16)(size_), \ .buffer = (ai_buffer*)(buffer_array_) \ } #define AI_BUFFER_ARRAY_OBJ_INIT_STATIC(flags_, size_, ...) \ { \ .flags = (ai_u16)(flags_), \ .size = (ai_u16)(size_), \ .buffer = (ai_buffer*)((ai_buffer[]){__VA_ARGS__}) \ } #define AI_BUFFER_ARRAY_SANE(buf_array_) \ ai_buffer_array_sane(buf_array_) #define AI_BUFFER_ARRAY_FLAGS(buf_array_) \ ((AI_BUFFER_ARRAY_SANE(buf_array_)) ? (buf_array_)->flags : AI_FLAG_NONE) #define AI_BUFFER_ARRAY_SIZE(buf_array_) \ ((AI_BUFFER_ARRAY_SANE(buf_array_)) ? (buf_array_)->size : 0) #define AI_BUFFER_ARRAY_ITEM(buf_array_, pos_) \ ((AI_BUFFER_ARRAY_SANE(buf_array_)) ? ((buf_array_)->buffer + (pos_)) : NULL) #define AI_BUFFER_ARRAY_ITEM_SET_ADDRESS(buf_array_, pos_, address_) \ ai_buffer_array_item_set_address(buf_array_, pos_, address_) /*! * @enum buffer formats enum list * @ingroup ai_platform * * List of supported ai_buffer format types. */ enum { AI_BUFFER_FORMAT_NONE = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_NONE, 0, 0, 0, 0), AI_BUFFER_FORMAT_FLOAT = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_FLOAT, 1, 1, 32, 0), AI_BUFFER_FORMAT_U1 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, 1, 0), AI_BUFFER_FORMAT_U8 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, 8, 0), AI_BUFFER_FORMAT_U16 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, 16, 0), AI_BUFFER_FORMAT_U32 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, 32, 0), AI_BUFFER_FORMAT_S1 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, 1, 0), AI_BUFFER_FORMAT_S8 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, 8, 0), AI_BUFFER_FORMAT_S16 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, 16, 0), AI_BUFFER_FORMAT_S32 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, 32, 0), AI_BUFFER_FORMAT_Q = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, 0, 0), AI_BUFFER_FORMAT_Q7 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, 8, 7), AI_BUFFER_FORMAT_Q15 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 1, 0, 16, 15), AI_BUFFER_FORMAT_UQ = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, 0, 0), AI_BUFFER_FORMAT_UQ7 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, 8, 7), AI_BUFFER_FORMAT_UQ15 = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_Q, 0, 0, 16, 15), AI_BUFFER_FORMAT_BOOL = AI_BUFFER_FMT_SET(AI_BUFFER_FMT_TYPE_BOOL, 0, 0, 8, 0), }; /*****************************************************************************/ #define AI_ERROR_INIT(type_, code_) { \ .type = AI_ERROR_##type_, \ .code = AI_ERROR_CODE_##code_ \ } /* printf formats */ #define SSIZET_FMT "%" PRIu32 #define AII32_FMT "%" PRId32 #define AIU32_FMT "%" PRIu32 #define AII64_FMT "%" PRId64 #define AIU64_FMT "%" PRIu64 #define AI_VERSION(major_, minor_, micro_) \ (((major_)<<24) | ((minor_)<<16) | ((micro_)<<8)) typedef uint8_t ai_custom_type_signature; typedef void* ai_handle; typedef const void* ai_handle_const; typedef float ai_float; typedef double ai_double; typedef bool ai_bool; typedef char ai_char; typedef uint32_t ai_size; typedef int16_t ai_short_size; typedef uintptr_t ai_uptr; typedef unsigned int ai_uint; typedef uint8_t ai_u8; typedef uint16_t ai_u16; typedef uint32_t ai_u32; typedef uint64_t ai_u64; typedef int ai_int; typedef int8_t ai_i8; typedef int16_t ai_i16; typedef int32_t ai_i32; typedef int64_t ai_i64; typedef uint64_t ai_macc; typedef int32_t ai_pbits; typedef uint32_t ai_signature; typedef void (*ai_handle_func)(ai_handle); /*****************************************************************************/ /*! * @struct ai_error * @ingroup ai_platform * @brief Structure encoding details about the last error. */ typedef struct ai_error_ { ai_u32 type : 8; /*!< Error type represented by @ref ai_error_type */ ai_u32 code : 24; /*!< Error code represented by @ref ai_error_code */ } ai_error; /*****************************************************************************/ /*! * @struct ai_intq_info * @ingroup ai_platform * @brief an element of the ai_intq_info_list entry. It reports an array for the * scale and zeropoint values for each buffer. Optional flags are also present */ typedef struct ai_intq_info_ { INTQ_CONST ai_float* scale; INTQ_CONST ai_handle zeropoint; } ai_intq_info; /*! * @struct ai_intq_info_list * @ingroup ai_platform * @brief list reporting meta info for quantized networks integer support * when size > 1 it means a per channel out quantization */ typedef struct ai_intq_info_list_ { ai_u16 flags; /*!< optional flags to store intq info attributes */ ai_u16 size; /*!< number of elements in the the intq_info list */ INTQ_CONST ai_intq_info* info; /*!< pointer to an array of metainfo * associated to the intq_info list */ } ai_intq_info_list; /*****************************************************************************/ /*! * @struct ai_buffer_meta_info * @ingroup ai_platform * @brief Optional meta attributes associated with the I/O buffer. * This datastruct is used also for network querying, where the data field may * may be NULL. */ typedef struct ai_buffer_meta_info_ { ai_u32 flags; /*!< meta info flags */ ai_intq_info_list* intq_info; /*!< meta info related to integer format */ } ai_buffer_meta_info; /*! * @struct ai_buffer_shape * @ingroup ai_platform * @brief Memory buffer shape datatype definition. */ typedef struct ai_buffer_shape_ { ai_u32 type : 8; /*!< shape type: reserved for compatibility */ ai_u32 size : 24; /*!< size: shape cardinality */ ai_shape_dimension* data; /*!< pointer to shape tuple array */ } ai_buffer_shape; /*! * @struct ai_buffer * @ingroup ai_platform * @brief Memory buffer storing data (optional) with a shape, size and type. * This datastruct is used also for network querying, where the data field may * may be NULL. */ typedef struct ai_buffer_ { ai_buffer_format format; /*!< buffer format */ ai_handle data; /*!< pointer to buffer data */ ai_buffer_meta_info* meta_info; /*!< pointer to buffer metadata info */ /* New 7.1 fields */ ai_flags flags; /*!< shape optional flags */ ai_size size; /*!< number of elements of the buffer (including optional padding) */ ai_buffer_shape shape; /*!< n-dimensional shape info */ } ai_buffer; /*! * @struct ai_buffer_array * @ingroup ai_platform * @brief Array of @ref ai_buffer. */ typedef struct ai_buffer_array_ { ai_u16 flags; /*!< buffer array flags */ ai_u16 size; /*!< buffer array size */ ai_buffer* buffer; /*!< buffer array buffers pointer */ } ai_buffer_array; /* enums section */ /*! * @enum ai_error_type * @ingroup ai_platform * * Generic enum to list network error types. */ typedef enum { AI_ERROR_NONE = 0x00, /*!< No error */ AI_ERROR_TOOL_PLATFORM_API_MISMATCH = 0x01, AI_ERROR_TYPES_MISMATCH = 0x02, AI_ERROR_INVALID_HANDLE = 0x10, AI_ERROR_INVALID_STATE = 0x11, AI_ERROR_INVALID_INPUT = 0x12, AI_ERROR_INVALID_OUTPUT = 0x13, AI_ERROR_INVALID_PARAM = 0x14, AI_ERROR_INVALID_SIGNATURE = 0x15, AI_ERROR_INVALID_SIZE = 0x16, AI_ERROR_INVALID_VALUE = 0x17, AI_ERROR_INIT_FAILED = 0x30, AI_ERROR_ALLOCATION_FAILED = 0x31, AI_ERROR_DEALLOCATION_FAILED = 0x32, AI_ERROR_CREATE_FAILED = 0x33, } ai_error_type; /*! * @enum ai_error_code * @ingroup ai_platform * * Generic enum to list network error codes. */ typedef enum { AI_ERROR_CODE_NONE = 0x0000, /*!< No error */ AI_ERROR_CODE_NETWORK = 0x0010, AI_ERROR_CODE_NETWORK_PARAMS = 0x0011, AI_ERROR_CODE_NETWORK_WEIGHTS = 0x0012, AI_ERROR_CODE_NETWORK_ACTIVATIONS = 0x0013, AI_ERROR_CODE_LAYER = 0x0014, AI_ERROR_CODE_TENSOR = 0x0015, AI_ERROR_CODE_ARRAY = 0x0016, AI_ERROR_CODE_INVALID_PTR = 0x0017, AI_ERROR_CODE_INVALID_SIZE = 0x0018, AI_ERROR_CODE_INVALID_FORMAT = 0x0019, AI_ERROR_CODE_OUT_OF_RANGE = 0x0020, AI_ERROR_CODE_INVALID_BATCH = 0x0021, AI_ERROR_CODE_MISSED_INIT = 0x0030, AI_ERROR_CODE_IN_USE = 0x0040, AI_ERROR_CODE_LOCK = 0x0041, } ai_error_code; /*! * @struct ai_platform_version * @ingroup ai_platform * @brief Datastruct storing platform version info */ typedef struct ai_platform_version_ { ai_u8 major; ai_u8 minor; ai_u8 micro; ai_u8 reserved; } ai_platform_version; /*! * @struct ai_network_params * @ingroup ai_platform * * Datastructure to pass parameters during network initialization. */ typedef struct ai_network_params_ { AI_NETWORK_PARAMS_FIELDS_DECLARE } ai_network_params; /*! * @struct ai_network_buffers * @ingroup ai_platform * * Datastructure to pass network buffers during network initialization. */ typedef struct ai_network_buffers_ { AI_NETWORK_BUFFERS_FIELD_DECLARE } ai_network_buffers; /*! * @struct ai_network_report * @ingroup ai_platform * * Datastructure to query a network report with some relevant network detail. */ typedef struct ai_network_report_ { const char* model_name; const char* model_signature; const char* model_datetime; const char* compile_datetime; const char* runtime_revision; ai_platform_version runtime_version; const char* tool_revision; ai_platform_version tool_version; ai_platform_version tool_api_version; ai_platform_version api_version; ai_platform_version interface_api_version; ai_macc n_macc; ai_u16 n_inputs; ai_u16 n_outputs; ai_buffer* inputs; ai_buffer* outputs; AI_NETWORK_PARAMS_FIELDS_DECLARE ai_u32 n_nodes; ai_signature signature; } ai_network_report; /*! * @enum ai_upsample_mode * @ingroup ai_platform * @brief allowed mode in upsample layer */ typedef enum { AI_UPSAMPLE_ZEROS = 0x0, AI_UPSAMPLE_NEAREST, AI_UPSAMPLE_BILINEAR, AI_UPSAMPLE_TRILINEAR } ai_upsample_mode; /*! * @enum ai_resize_mode * @ingroup ai_platform * @brief allowed mode in resize layer */ typedef enum { AI_RESIZE_ZEROS = 0x0, AI_RESIZE_NEAREST, AI_RESIZE_LINEAR, AI_RESIZE_CUBIC } ai_resize_mode; /*! * @enum ai_coord_transf_mode * @ingroup ai_platform * @brief coordinate_transformation_mode in resize layer */ typedef enum { AI_HALF_PIXEL = 0x0, AI_PYTORCH_HALF_PIXEL, AI_ALIGN_CORNERS, AI_ASYMMETRIC, AI_TF_HALF_PIXEL_FOR_NN, AI_TF_CROP_AND_RESIZE } ai_coord_transf_mode; typedef enum { AI_ROUND_PREFER_FLOOR = 0x0, AI_ROUND_PREFER_CEIL, AI_ROUND_FLOOR, AI_ROUND_CEIL } ai_nearest_mode; typedef enum { AI_PAD_CONSTANT = 0x0, AI_PAD_REFLECT, AI_PAD_EDGE, AI_PAD_8BIT_CH1ST_CONSTANT, } ai_pad_mode; #define OUTPUT_PADDING_FLAG (1 << 0) #define CHANNEL_FIRST_FLAG (1 << 1) /* Carefull when changing those definitions bit0 shall always select output padding (Valid vs Same) bit1 shall always select Channel first /channel lst format */ typedef enum { AI_LAYER_FORMAT_CHANNEL_LAST_VALID = 0x0, AI_LAYER_FORMAT_CHANNEL_LAST_SAME = 0x1, AI_LAYER_FORMAT_CHANNEL_FIRST_VALID = 0x2, AI_LAYER_FORMAT_CHANNEL_FIRST_SAME = 0x3, } ai_layer_format_type; /*! ai_platform public APIs **************************************************/ /*! * @brief get the total number of elements of an ai_buffer. * @ingroup ai_platform * @param buffer a pointer to an @ref ai_buffer * @param with_padding when true it considers also padded elements * @return the number of elements of the buffer (with/without padded ones) */ AI_API_ENTRY ai_size ai_buffer_get_size(const ai_buffer* buffer, const ai_bool with_padding); /*! * @brief get the size in bytes of an ai_buffer (given the number of elements and format). * @ingroup ai_platform * @param count the number of elements composing the buffer * @param fmt the format of the ai_buffer * @return the size in bytes of the buffer */ AI_API_ENTRY ai_size ai_buffer_get_byte_size(const ai_size count, const ai_buffer_format fmt); /*! * @brief get total size in bytes of a buffer array. * @ingroup ai_platform * @param barray a pointer to the buffer array * @return the total size in bytes of all the buffer arrays */ AI_API_ENTRY ai_bool ai_buffer_array_is_empty(const ai_buffer_array* barray); /*! * @brief get total size in bytes of a buffer array. * @ingroup ai_platform * @param barray a pointer to the buffer array * @return the total size in bytes of all the buffer arrays */ AI_API_ENTRY ai_bool ai_buffer_array_is_valid(const ai_buffer_array* barray); /*! * @brief check if a buffer array is valid - i.e. not empty. * @ingroup ai_platform * @param barray a pointer to the buffer array * @return true if the array is consistent and not empty, false otherwise */ AI_API_ENTRY ai_bool ai_buffer_array_sane(const ai_buffer_array* barray); /*! * @brief get total size in bytes of a buffer array. * @ingroup ai_platform * @param barray a pointer to the buffer array * @return the total size in bytes of all the buffer arrays */ AI_API_ENTRY ai_size ai_buffer_array_get_byte_size(const ai_buffer_array* barray); /*! * @brief set the address of buffer array item @pos * @ingroup ai_platform * @param barray a pointer to the buffer array * @param pos the index of the element in the array * @param address the address to set * @return true if successful, false otherwise */ AI_API_ENTRY ai_bool ai_buffer_array_item_set_address( ai_buffer_array* barray, const ai_u32 pos, ai_handle address); AI_API_DECLARE_END #endif /*AI_PLATFORM_H*/
30,193
C
30.159959
116
0.58189
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_ml_iforest.h
/** ****************************************************************************** * @file layers_iforest.h * @author AIS * @brief header file of AI platform iForest layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_IFOREST_H #define LAYERS_IFOREST_H #pragma once #include "layers_common.h" /*! * @defgroup layers_ml Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /* Allowed tests branch in the iTrees */ typedef enum { AI_IFOREST_BRANCH_LT_IDX = 0, AI_IFOREST_BRANCH_LEQ_IDX, AI_IFOREST_BRANCH_EQ_IDX, AI_IFOREST_BRANCH_END, } ai_iforest_branch_e; /*! * @struct ai_layer_iforest * @ingroup layers_iforest * @brief iForest layer * * The type of iforest function is handled by the specific forward function * @ref forward_iforest */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_iforest_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_float global_average_path_length; /*!< global average path length used to normalized average path length*/ ai_float score_threshold; /*!< score threshold used to center the score around 0 */ } ai_layer_iforest; /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Decodes the iforest ML algorithm. * @ingroup layers_iforest * @param layer iforest layer */ AI_INTERNAL_API void forward_iforest(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_IFOREST_H*/
2,134
C
25.6875
112
0.524367
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_ml_svc.h
/** ****************************************************************************** * @file layers_svc.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform SVM Classifier (SVC) datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_SVC_H #define LAYERS_SVC_H #pragma once #include "layers_common.h" /*! * @defgroup layers_svc Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /* SVM classifier (SVC) kernel types */ typedef enum ai_svc_kernel_e_ { AI_SVC_KERNEL_LINEAR = 0, AI_SVC_KERNEL_POLYNOMIAL, AI_SVC_KERNEL_RBF, AI_SVC_KERNEL_SIGMOID, AI_SVC_KERNEL_UNSUPPORTED } ai_svc_kernel_e; /*! * @struct ai_layer_svc * @ingroup layers_svc * @brief SVM Classifier (SVC) layer * * The type of svc function is handled by the specific forward function * @ref forward_svc */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_svc_ { AI_LAYER_COMMON_FIELDS_DECLARE ai_float gamma; /*!< kernel coefficient for rbf, polynomial and sigmoid functions */ ai_float coef0; /*!< term in polynomial and sigmoid functions */ ai_u32 degree; /*!< polynomial function degree */ ai_svc_kernel_e kernel_type; /*!< kernel type : see ai_svm_kernel_e */ ai_bool proba_support; /*!< whether or not use the parameters learned in Platt scaling */ ai_bool has_classlabels_int; /*!< if True, SVC returns classlabels int, else classlabels string */ } ai_layer_svc; /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Decodes the SVM Classifier ML operator. * @ingroup layers_svc * @param layer svm classifier layer */ AI_INTERNAL_API void forward_svc(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_SVC_H*/
2,548
C
30.085365
110
0.523155
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/core_log.h
/** ****************************************************************************** * @file core_log.h * @author AST Embedded Analytics Research Platform * @brief header file of core log interfaces ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef CORE_LOG_H #define CORE_LOG_H #pragma once #include "ai_platform.h" #include "ai_datatypes_defines.h" /*! * @defgroup core_log Logger core routines wrapper interface * @brief Common macros, datatypes and routines of ai logger module * @details This header defines the wrapping macros interfaces to handle the * global logger module. These macro are defined when the macro HAS_LOG is * defined, otherwise they are all set to NOP routines and no logger code is * compiled at all. When the macro HAS_LOG is defined, only the log messages * having an enum id >= the value of the macro are compiled. Thus to include in * compilation only log messages up to the error level the value of HAS_LOG must * be equal the the enum value of LOG_ERROR macro (i.e. 3). a value of 6 means * to include all log messages up to the lower LOG_TRACE level. */ #if defined HAS_LOG && (HAS_LOG>=0) #include "ai_log.h" #define AI_LOG_SECTION(...) \ { __VA_ARGS__ } #define AI_LOG_ACQUIRE() \ ai_log_acquire() #define AI_LOG_SET_LEVEL(level_) \ AI_WRAP_FUNC(ai_log_set_level(level_);) #define AI_LOG_SET_QUIET(onoff_) \ AI_WRAP_FUNC(ai_log_set_quiet(onoff_);) #define AI_LOG_SET_LOCK_FN(fn_, udata_) \ AI_WRAP_FUNC(ai_log_set_lock(fn_, udata_);) #define AI_LOG_CHANNEL_PUSH(level_, fn_, udata_) \ AI_WRAP_FUNC(ai_log_channel_push(level_, fn_, udata_);) #define AI_LOG_CHANNEL_POP(fn_, udata_) \ AI_WRAP_FUNC(ai_log_channel_pop(fn_, udata_);) #ifdef LOG_USE_FILE #define AI_LOG_SET_FILE_POINTER(fp_) \ AI_WRAP_FUNC(ai_log_set_fp(fp_);) #else #define AI_LOG_SET_FILE_POINTER(fp_) \ AI_WRAP_FUNC(/*AI_LOG_SET_FILE_POINTER()*/) #endif #else #define AI_LOG_SECTION(...) AI_WRAP_FUNC(/*AI_LOG_SECTION()*/) #define AI_LOG_ACQUIRE() (NULL) #define AI_LOG_SET_LEVEL(level_) AI_WRAP_FUNC(/*AI_LOG_SET_LEVEL()*/) #define AI_LOG_SET_QUIET(onoff_) AI_WRAP_FUNC(/*AI_LOG_SET_QUIET()*/) #define AI_LOG_SET_LOCK_FN(fn_, udata_) AI_WRAP_FUNC(/*AI_LOG_SET_LOCK_FN()*/) #define AI_LOG_CHANNEL_PUSH(level_, fn_, udata_) AI_WRAP_FUNC(/*AI_LOG_CHANNEL_PUSH()*/) #define AI_LOG_CHANNEL_POP(fn_, udata_) AI_WRAP_FUNC(/*AI_LOG_CHANNEL_POP()*/) #define AI_LOG_SET_FILE_POINTER(fp_) AI_WRAP_FUNC(/*AI_LOG_SET_FILE_POINTER()*/) #endif #if defined HAS_LOG #define AI_LOG_PRINT(level, fmt, ...) \ AI_WRAP_FUNC(ai_log_print(level, fmt, ##__VA_ARGS__);) #else #define AI_LOG_PRINT(level, fmt, ...) \ AI_WRAP_FUNC(/*AI_LOG_PRINT(...)*/) #endif #if defined HAS_LOG && (HAS_LOG>=LOG_SUDO) #define AI_LOG_SUDO(fmt, ...) \ AI_WRAP_FUNC(ai_log_log(LOG_SUDO, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) #else #define AI_LOG_SUDO(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_SUDO()*/) #endif #if defined HAS_LOG && (HAS_LOG>=LOG_TRACE) #define AI_LOG_TRACE(fmt, ...) \ AI_WRAP_FUNC(ai_log_log(LOG_TRACE, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) #else #define AI_LOG_TRACE(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_TRACE()*/) #endif #if defined HAS_LOG && (HAS_LOG>=LOG_DEBUG) #define AI_LOG_DEBUG(fmt, ...) \ AI_WRAP_FUNC(ai_log_log(LOG_DEBUG, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) #else #define AI_LOG_DEBUG(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_DEBUG()*/) #endif #if defined HAS_LOG && (HAS_LOG>=LOG_INFO) #define AI_LOG_INFO(fmt, ...) \ AI_WRAP_FUNC(ai_log_log(LOG_INFO, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) #else #define AI_LOG_INFO(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_INFO()*/) #endif #if defined HAS_LOG && (HAS_LOG>=LOG_WARN) #define AI_LOG_WARN(fmt, ...) \ AI_WRAP_FUNC(ai_log_log(LOG_WARN, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) #else #define AI_LOG_WARN(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_WARN()*/) #endif #if defined HAS_LOG && (HAS_LOG>=LOG_ERROR) #define AI_LOG_ERROR(fmt, ...) \ AI_WRAP_FUNC(ai_log_log(LOG_ERROR, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) #else #define AI_LOG_ERROR(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_ERROR()*/) #endif #if defined HAS_LOG && (HAS_LOG>=LOG_FATAL) #define AI_LOG_FATAL(fmt, ...) \ AI_WRAP_FUNC(ai_log_log(LOG_FATAL, __FILE__, __LINE__, fmt LOG_CR, ##__VA_ARGS__);) #else #define AI_LOG_FATAL(fmt, ...) AI_WRAP_FUNC(/*AI_LOG_FATAL()*/) #endif #endif /*CORE_LOG_H*/
5,222
C
37.404411
97
0.572769
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_dense_if32.h
#ifndef _LITE_DENSE_IF32_H #define _LITE_DENSE_IF32_H #pragma once #include "ai_lite_interface.h" /*! * @brief Forward function for a dense layer with signed float input, * signed float output, and float weights. * @ingroup lite_dense_if32 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to bias (NULL if not available). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_if32of32wf32( ai_float* output, const ai_float* input, const ai_float* weights, const ai_float* bias, const ai_u32 n_channel_in, const ai_u32 n_channel_out); #endif /*_LITE_DENSE_IF32_H*/
855
C
30.703703
69
0.71462
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_dense.h
/** ****************************************************************************** * @file layers_dense.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform dense layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_DENSE_H #define LAYERS_DENSE_H #pragma once #include "layers_common.h" /*! * @defgroup layers Normalization Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @brief Computes the activations of a fixed point dense (fully connected) layer. * @ingroup layers_dense * @param layer the dense layer */ AI_INTERNAL_API void forward_dense_fixed(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_DENSE_H*/
1,264
C
24.3
82
0.524525
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_generic_dqnn.h
/** ****************************************************************************** * @file layers_generic_dqnn.h * @author AIS * @brief header file of AI platform DQNN generic datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_GENERIC_DQNN_H #define LAYERS_GENERIC_DQNN_H #pragma once #include "layers_common.h" #include "layers_generic.h" /*! * @defgroup layers_generic_dqnn Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles concat with binary input, binary output and * binary weights * @ingroup layers_generic_dqnn * @param layer concat layer */ AI_INTERNAL_API void forward_concat_is1os1(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_GENERIC_DQNN_H*/
1,537
C
26.464285
80
0.454782
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_generic_float.h
/** ****************************************************************************** * @file lite_conv2d_dqnn.h * @author AIS * @brief header file of AI platform lite conv kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_GENERIC_FLOAT_H #define LITE_GENERIC_FLOAT_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_topK_axis_0_if32of32(const ai_float *pDataIn_init, ai_float *pDataOut_values_init, ai_i32 *pDataOut_index_init, const ai_size height_in, const ai_size width_in, const ai_size n_channel_in, const ai_size k, ai_i16 largest, void (*f)(const ai_float* inputs, ai_float* values, ai_i32* indices, ai_size k, ai_size n_elements, ai_i32 stride, ai_i16 largest) ); /*! * @brief Handles 2D convolution with binary input, binary output and * binary weights - with 0 padding (QKeras like) - Lite I/F * - Optimized thanks to Optim0 assumptions * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_topK_axis_1_if32of32(const ai_float *pDataIn_init, ai_float *pDataOut_values_init, ai_i32 *pDataOut_index_init, const ai_size height_in, const ai_size width_in, const ai_size n_channel_in, const ai_size k, ai_i16 largest, void (*f)(const ai_float* inputs, ai_float* values, ai_i32* indices, ai_size k, ai_size n_elements, ai_i32 stride, ai_i16 largest) ); /*! * @brief Handles 2D convolution with binary input, 8-bits output and * binary weights - with 0 padding (QKeras like) - Lite I/F * @ingroup lite_conv2d_dqnn */ LITE_API_ENTRY void forward_lite_topK_axis_2_if32of32(const ai_float *pDataIn_init, ai_float *pDataOut_values_init, ai_i32 *pDataOut_index_init, const ai_size height_in, const ai_size width_in, const ai_size n_channel_in, const ai_size k, ai_i16 largest, void (*f)(const ai_float* inputs, ai_float* values, ai_i32* indices, ai_size k, ai_size n_elements, ai_i32 stride, ai_i16 largest) ); LITE_API_ENTRY void forward_lite_func_reduce_l1_if32of32( ai_float* out_ptr, const ai_float* in_ptr, const ai_size out_size, const ai_size in_step, const ai_size axis_size, const ai_size axis_step); LITE_API_ENTRY void forward_lite_func_reduce_l2_if32of32( ai_float* out_ptr, const ai_float* in_ptr, const ai_size out_size, const ai_size in_step, const ai_size axis_size, const ai_size axis_step); #endif /*LITE_GENERIC_FLOAT_H*/
4,287
C
42.755102
148
0.463028
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/layers_nl.h
/** ****************************************************************************** * @file layers_nl.h * @author AST Embedded Analytics Research Platform * @brief header file of AI platform nonlinearity layers datatypes ****************************************************************************** * @attention * * Copyright (c) 2018 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LAYERS_NL_H #define LAYERS_NL_H #pragma once #include "layers_common.h" /*! * @defgroup layers_nl Normalization Layers Definitions * @brief definition * */ AI_API_DECLARE_BEGIN /*! * @struct ai_layer_nl * @ingroup layers_nl * @brief Generic Nonlinearity layer * * The type of nonlinearity is handled by the specific forward function. * It is a sequential layer. see @ref ai_layer */ typedef AI_ALIGNED_TYPE(struct, 4) ai_layer_nl_ { AI_LAYER_COMMON_FIELDS_DECLARE AI_CONST ai_array* nl_params; /*!< associated parameters array */ } ai_layer_nl; /*! * @struct ai_layer_sm * @ingroup layers_nl * @brief Softmax Nonlinearity layer * * It is a sequential layer. see @ref ai_layer */ typedef ai_layer_nl ai_layer_sm; /*! * @typedef (*func_nl) * @ingroup layers_nl * @brief Fuction pointer for generic non linear transform * this function pointer abstracts a generic non linear layer. * see @ref nl_func_tanh_array_f32 and similar as examples. */ //typedef void (*func_nl)(ai_array *out, const ai_array *in, // const ai_size size, const ai_handle params); typedef void (*func_nl)(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Softmax pooling computed on a single float channel * @ingroup layers_nl * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param channel_size number of elements of the input channel * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_sm_channel_f32(ai_tensor *out, const ai_tensor *in, const ai_size channel_size, const ai_handle params); /*! * @brief Softmax normalization computed on an array of float channels * @ingroup layers_nl * @param out opaque handler to float output channel array * @param in opaque handler to float input channel array * @param in_size total size (number of elements) to process on the input * @param channel_size number of elements of the input channel * @param in_channel_step number of elements to move to next input element * @param out_channel_step number of elements to move to next output element */ AI_INTERNAL_API void nl_func_sm_array_f32(ai_tensor *out, ai_tensor *in, const ai_size in_size, const ai_size channel_size, const ai_size in_channel_step, const ai_size out_channel_step); /*! * @brief Softmax zero pooling computed on a single float channel * @ingroup layers_nl * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param channel_size number of elements of the input channel * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_sm_zero_channel_f32(ai_tensor *out, const ai_tensor *in, const ai_size channel_size, const ai_handle params); /*! * @brief Probit non linearity * @ingroup layers_nl * @param out opaque handler to float output channel * @param in opaque handler to float input channel * @param channel_size number of elements of the input channel * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_probit_f32(ai_tensor *out, const ai_tensor *in, const ai_size channel_size, const ai_handle params); /*! * @brief Computes the tanh function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_tanh_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the tanh function on a fixed point data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_tanh_array_fixed(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the sigmoid function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_sigmoid_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the sigmoid function on a fixed point data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_sigmoid_array_fixed(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the hard sigmoid function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_hard_sigmoid_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the logistic function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_logistic_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the swish function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_swish_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the hard swish function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_hard_swish_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the absolute value function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_abs_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the cosine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_cos_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the inverse cosine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_acos_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the hyperbolic cosine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_cosh_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the inverse hyperbolic cosine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_acosh_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the sine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_sin_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the inverse sine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_asin_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the hyperbolic sine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_sinh_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the inverse hyperbolic sine function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_asinh_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the tangent function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_tan_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the inverse tangent function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_atan_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the inverse hyperbolic tangent function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_atanh_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the error function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_erf_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the natural logarithm function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_log_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the reciprocal square root function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_rsqrt_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the squarefunction on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_square_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the floor function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_floor_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the ceil function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_ceil_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the rounding function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_round_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the exponential function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_exp_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the sign negation function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_neg_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the sign negation function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_not_array_bool(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the reciprocal function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_reciprocal_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the square root function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_sqrt_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the soft plus function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer */ AI_INTERNAL_API void nl_func_soft_plus_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the soft sign function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_soft_sign_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the sign function on a single float element. * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer */ AI_INTERNAL_API void nl_func_sign_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the clip function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_clip_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the hardmax function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param axis direction of the max index to be searched */ AI_INTERNAL_API void nl_func_hardmax_array_f32(ai_tensor *out, const ai_tensor *in, const ai_shape *shape, const ai_handle params); /*! * @brief Computes the generic relu function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_relu_generic_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the thresholded relu function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_relu_thresholded_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the relu function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_relu_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the relu function on a fixed point data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_relu_array_fixed(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the relu function on an integer-quantized data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to optional nl parameters */ void nl_func_relu_array_integer(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the clip function on an integer-quantized data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to optional nl parameters */ void nl_func_clip_array_integer(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the activation function on an integer-quantized data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to generated and used LUT */ void nl_func_array_integer(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the elu function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_elu_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the max relu function on a fixed point data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_relu_max_array_fixed(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the selu function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size number of elements in the input buffer * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_selu_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the prelu function on a float data array * @ingroup layers_nl * @param in opaque handler to float, size should be 1 * @param slope opaque handler to float, size should be 1 * @param out opaque handler to float output elem * @param size size of the input data in bytes * @param params opaque handler to optional nl parameters */ AI_INTERNAL_API void nl_func_prelu_array_f32(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /*! * @brief Computes the prelu function on an integer-quantized data array * @ingroup layers_nl * @param in opaque handler to input elements to process * @param out opaque handler to output elements * @param size total size (number of elements) to process on the input * @param params opaque handler to optional nl parameters */ void nl_func_prelu_array_integer(ai_tensor *out, const ai_tensor *in, const ai_size size, const ai_handle params); /******************************************************************************/ /** Forward Functions Section **/ /******************************************************************************/ /*! * @brief Computes the activations of a ReLU nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_relu(ai_layer* layer); /*! * @brief Computes the activations of a fixed point ReLU nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_relu_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of a integer-quantized ReLU nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_relu_integer(ai_layer *pLayer); /*! * @brief Computes the activations of a clip integer-quantized nonlinear layer. * @ingroup layers_nl * @param pLayer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_clip_integer(ai_layer *pLayer); /*! * @brief Computes the activations of a ReLU6 nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_relu_thresholded(ai_layer* layer); /*! * @brief Computes the activations of a fixed point max ReLU layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_relu_max_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of a ELU nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_elu(ai_layer* layer); /*! * @brief Computes the activations of a SELU nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_selu(ai_layer* layer); /*! * @brief Computes the activations of a PRELU nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_prelu(ai_layer* layer); /*! * @brief Computes the activations of a binary tanh (sign) nonlinear layer. * @ingroup layers * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_sign(ai_layer* layer); /*! * @brief Computes the activations of a clip nonlinear layer. * @ingroup layers * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_clip(ai_layer* layer); /*! * @brief Computes the activations of a sigmoid nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_sigmoid(ai_layer* layer); /*! * @brief Computes the activations of a fixed point sigmoid nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_sigmoid_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of a hard sigmoid nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_hard_sigmoid(ai_layer* layer); /*! * @brief Computes the activations of a swish nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_swish(ai_layer* layer); /*! * @brief Computes the activations of a hard swish nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_hard_swish(ai_layer* layer); /*! * @brief Computes the activations of an exponential nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_exp(ai_layer* layer); /*! * @brief Computes the activations of an square root nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_sqrt(ai_layer* layer); /*! * @brief Computes the activations of a soft plus nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_soft_plus(ai_layer* layer); /*! * @brief Computes the activations of a soft sign nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_soft_sign(ai_layer* layer); /*! * @brief Computes the activations of a cosine (cos) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_cos(ai_layer* layer); /*! * @brief Computes the activations of a inverse cosine (acos) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_acos(ai_layer* layer); /*! * @brief Computes the activations of a hyperbolic cosine (cosh) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_cosh(ai_layer* layer); /*! * @brief Computes the activations of a inverse hyperbolic cosine (acosh) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_acosh(ai_layer* layer); /*! * @brief Computes the activations of a sine (sin) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_sin(ai_layer* layer); /*! * @brief Computes the activations of a inverse sine (asin) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_asin(ai_layer* layer); /*! * @brief Computes the activations of a hyperbolic sine (sinh) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_sinh(ai_layer* layer); /*! * @brief Computes the activations of a inverse hyperbolic sine (asinh) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_asinh(ai_layer* layer); /*! * @brief Computes the activations of a tangent (tan) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_tan(ai_layer* layer); /*! * @brief Computes the activations of a inverse tangent (atan) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_atan(ai_layer* layer); /*! * @brief Computes the activations of a hyperbolic tangent (tanh) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_tanh(ai_layer* layer); /*! * @brief Computes the activations of a inverse hyperbolic tangent (atanh) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_atanh(ai_layer* layer); /*! * @brief Computes the activations of a fixed point tanh nonlinear layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_tanh_fixed(ai_layer *pLayer); /*! * @brief Computes the activations of a error function (erf) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_erf(ai_layer* layer); /*! * @brief Computes the activations of a natural logarithm (log) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_log(ai_layer* layer); /*! * @brief Computes the activations of a reciprocal square root (rsqrt) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_rsqrt(ai_layer* layer); /*! * @brief Computes the activations of a square layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_square(ai_layer* layer); /*! * @brief Computes the activations of an absolute value (abs) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_abs(ai_layer* layer); /*! * @brief Computes the activations of a ceil layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_ceil(ai_layer* layer); /*! * @brief Computes the activations of a floor layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_floor(ai_layer* layer); /*! * @brief Computes the activations of a rounding layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_round(ai_layer* layer); /*! * @brief Computes the activations of a sign negation (neg) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_neg(ai_layer* layer); /*! * @brief Computes the activations of a sign negation (not) layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_not(ai_layer* layer); /*! * @brief Computes the activations of a reciprocal layer. * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_reciprocal(ai_layer* layer); /*! * @brief Hardmax on an input tensors * @ingroup layers_generic * @param layer the hardmax layer */ AI_INTERNAL_API void forward_hardmax(ai_layer* layer); /*! * @brief Computes the activations of a softmax nonlinear layer. * @ingroup layers_nl * @param layer the softmax (sm) layer */ AI_INTERNAL_API void forward_sm(ai_layer* layer); /*! * @brief Computes the activations of a softmax nonlinear layer (integer version). * @ingroup layers_nl * @param layer the softmax (sm) layer */ AI_INTERNAL_API void forward_sm_integer(ai_layer* layer); /*! * @brief Computes the activations of an integer quantized nonlinear layer. * Non linear operation is function of used LUT defined through * (pLayer->nl_params->data) * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_nl_integer(ai_layer *pLayer); /*! * @brief Computes the activations of an integer quantized PReLu. * Slope params are located like weights, not params because they are * quantized * @ingroup layers_nl * @param layer the nonlinear (nl) layer */ AI_INTERNAL_API void forward_prelu_integer(ai_layer *pLayer); AI_API_DECLARE_END #endif /*LAYERS_NL_H*/
37,339
C
32.63964
84
0.688663
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_convert_dqnn.h
/** ****************************************************************************** * @file lite_convert_dqnn.h * @author AIS * @brief header file of AI platform lite convert kernel datatypes ****************************************************************************** * @attention * * Copyright (c) 2021 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** @verbatim @endverbatim ****************************************************************************** */ #ifndef LITE_CONVERT_DQNN_H #define LITE_CONVERT_DQNN_H #pragma once #include "ai_lite_interface.h" /******************************************************************************/ /* Forward Functions Section */ /******************************************************************************/ LITE_API_ENTRY void forward_lite_node_convert_is1os8( const ai_pbits *p_in, ai_i8 *p_out, const ai_i32 n_channels, const ai_i32 n_pixels, const ai_i8 *n_values); LITE_API_ENTRY void forward_lite_node_convert_is1os16( const ai_pbits *p_in, ai_i16 *p_out, const ai_i32 n_channels, const ai_i32 n_pixels, const ai_i16 *n_values); LITE_API_ENTRY void forward_lite_node_convert_is1of32( const ai_pbits *p_in, ai_float *p_out, const ai_i32 n_channels, const ai_i32 n_pixels, const ai_float *n_values); /*! * @brief Handles data conversion from 8-bits signed input to signed binary * outputs - Lite API version * @ingroup lite_pw_dqnn */ LITE_API_ENTRY void forward_lite_node_convert_is8os1( const ai_i8 *p_in, ai_pbits *p_out, const ai_i32 n_channels, const ai_i32 n_pixels, const ai_i8 zp, const ai_i8 pad); LITE_API_ENTRY void forward_lite_node_convert_is16os1( const ai_i16 *p_in, ai_pbits *p_out, const ai_i32 n_channels, const ai_i32 n_pixels, const ai_i8 zp, const ai_i8 pad); LITE_API_ENTRY void forward_lite_node_convert_if32os1( const ai_float *p_in, ai_pbits *p_out, const ai_i32 n_channels, const ai_i32 n_pixels, const ai_i8 zp, const ai_i8 pad); LITE_API_ENTRY void forward_lite_node_convert_integer_if32os8( const ai_float *p_in, ai_i8 *p_out, const ai_u32 size, const ai_float out_scale, const ai_i8 out_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_integer_if32ou8( const ai_float *p_in, ai_u8 *p_out, const ai_u32 size, const ai_float out_scale, const ai_u8 out_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_integer_is8of32( const ai_i8 *p_in, ai_float *p_out, const ai_u32 size, const ai_float in_scale, const ai_i8 in_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_integer_iu8of32( const ai_u8 *p_in, ai_float *p_out, const ai_u32 size, const ai_float in_scale, const ai_u8 in_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_if32os16( const ai_float *p_in, ai_i16 *p_out, const ai_u32 size, const ai_float out_scale, const ai_i16 out_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_if32ou16( const ai_float *p_in, ai_u16 *p_out, const ai_u32 size, const ai_float out_scale, const ai_u16 out_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_is16of32( const ai_i16 *p_in, ai_float *p_out, const ai_u32 size, const ai_float in_scale, const ai_i16 in_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_iu16of32( const ai_u16 *p_in, ai_float *p_out, const ai_u32 size, const ai_float in_scale, const ai_u16 in_zeropoint); LITE_API_ENTRY void forward_lite_node_convert_integer_iu8ou8( const ai_u8 *p_in, ai_u8 *p_out, const ai_i32 n_elems, const ai_float scale_ratio, const ai_u8 in_zp, const ai_u8 out_zp); LITE_API_ENTRY void forward_lite_node_convert_integer_iu8os8( const ai_u8 *p_in, ai_i8 *p_out, const ai_i32 n_elems, const ai_float scale_ratio, const ai_u8 in_zp, const ai_i8 out_zp); LITE_API_ENTRY void forward_lite_node_convert_integer_iu8os8_fast( const ai_u8 *p_in, ai_i8 *p_out, const ai_i32 n_elems, const ai_float scale_ratio, const ai_u8 in_zp, const ai_i8 out_zp); LITE_API_ENTRY void forward_lite_node_convert_integer_is8ou8( const ai_i8 *p_in, ai_u8 *p_out, const ai_i32 n_elems, const ai_float scale_ratio, const ai_i8 in_zp, const ai_u8 out_zp); LITE_API_ENTRY void forward_lite_node_convert_integer_is8ou8_fast( const ai_i8 *p_in, ai_u8 *p_out, const ai_i32 n_elems, const ai_float scale_ratio, const ai_i8 in_zp, const ai_u8 out_zp); LITE_API_ENTRY void forward_lite_node_convert_is16ou16( const ai_i16 *p_in, ai_u16 *p_out, const ai_i32 n_elems, const ai_float scale_ratio, const ai_i16 in_zp, const ai_u16 out_zp); #endif /*LITE_CONVERT_DQNN_H*/
5,069
C
21.533333
80
0.616098
Tbarkin121/GuardDog/stm32/AnymalNet/Middlewares_backup/ST/AI/Inc/lite_dense_ws1.h
#ifndef LITE_DENSE_WS1_H #define LITE_DENSE_WS1_H #pragma once #include "ai_lite_interface.h" /*! * @brief Forward function for a dense layer with signed 16bit input, * signed 16bit output, binary weights and binary bias. * @ingroup lite_dense_ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to bias. * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is16os16ws1( ai_i16* output, const ai_i16* input, const ai_pbits* weights, const ai_pbits* bias, ai_i32* scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); /*! * @brief Forward function for a dense layer with signed 16bit input, * signed 16bit output, binary weights and binary bias. * The BN is fused, i.e., the layer requires weights, scale, and offset, where * weights are those of the dense layer, scale is that of the BN, and the offset * corresponds to dense bias * bn scale + bn offset. If the parameters do not * agree with such convention, the behavior is undefined. * @ingroup lite_dense_ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param scale The pointer to scale. * @param offset The pointer to offset. * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_is16os16ws1_bn( ai_i16* output, const ai_i16* input, const ai_pbits* weights, const ai_float *scale, const ai_float *offset, ai_i32* scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); /*! * @brief Forward function for a dense layer with signed f32 input, * f32 output, binary weights and binary bias. * @ingroup lite_dense_ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to bias. * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_if32os1ws1( ai_pbits *output, const ai_float *input, const ai_pbits *weights, const ai_float *bias, ai_float *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); /*! * @brief Forward function for a dense layer with signed f32 input, * f32 output, binary weights. * The BN is fused, i.e., the layer requires weights, scale, and offset, where * weights are those of the dense layer, scale is that of the BN, and the offset * corresponds to dense bias * bn scale + bn offset. If the parameters do not * agree with such convention, the behavior is undefined. * @ingroup lite_dense_ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param scale The pointer to scale. * @param offset The pointer to offset. * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_if32os1ws1_bn( ai_pbits *output, const ai_float *input, const ai_pbits *weights, const ai_float *scale, const ai_float *offset, ai_float *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); /*! * @brief Forward function for a dense layer with signed f32 input, * f32 output, and binary weights. * @ingroup lite_dense_ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param bias The pointer to binary bias. * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_if32of32ws1( ai_float* output, const ai_float* input, const ai_pbits* weights, const ai_pbits* bias, ai_float* scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); /*! * @brief Forward function for a dense layer with signed f32 input, * f32 output, and binary weights. * The BN is fused, i.e., the layer requires weights, scale, and offset, where * weights are those of the dense layer, scale is that of the BN, and the offset * corresponds to dense bias * bn scale + bn offset. If the parameters do not * agree with such convention, the behavior is undefined. * @ingroup lite_dense_ws1 * @param output The pointer to output buffer. * @param input The pointer to input buffer. * @param weights The pointer to weights. * @param scale The pointer to scale. * @param offset The pointer to offset. * @param scratch The pointer to the scratch buffer (unused). * @param n_channel_in The number of channels of the input. * @param n_channel_out The number of channels of the output, i.e., * the number of dense hidden neurons. */ LITE_API_ENTRY void forward_lite_dense_if32of32ws1_bn( ai_float *output, const ai_float *input, const ai_pbits *weights, const ai_float *scale, const ai_float *offset, ai_float *scratch, const ai_u32 n_channel_in, const ai_u32 n_channel_out); #endif /* LITE_DENSE_IS1WS1_H */
5,884
C
39.586207
80
0.720768