EL4121 Embedded System / mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

UserRevisionLine numberNew contents of line
be_bryan 0:b74591d5ab33 1 /* ----------------------------------------------------------------------
be_bryan 0:b74591d5ab33 2 * Copyright (C) 2010-2014 ARM Limited. All rights reserved.
be_bryan 0:b74591d5ab33 3 *
be_bryan 0:b74591d5ab33 4 * $Date: 19. March 2015
be_bryan 0:b74591d5ab33 5 * $Revision: V.1.4.5
be_bryan 0:b74591d5ab33 6 *
be_bryan 0:b74591d5ab33 7 * Project: CMSIS DSP Library
be_bryan 0:b74591d5ab33 8 * Title: arm_mat_sub_q15.c
be_bryan 0:b74591d5ab33 9 *
be_bryan 0:b74591d5ab33 10 * Description: Q15 Matrix subtraction
be_bryan 0:b74591d5ab33 11 *
be_bryan 0:b74591d5ab33 12 * Target Processor: Cortex-M4/Cortex-M3/Cortex-M0
be_bryan 0:b74591d5ab33 13 *
be_bryan 0:b74591d5ab33 14 * Redistribution and use in source and binary forms, with or without
be_bryan 0:b74591d5ab33 15 * modification, are permitted provided that the following conditions
be_bryan 0:b74591d5ab33 16 * are met:
be_bryan 0:b74591d5ab33 17 * - Redistributions of source code must retain the above copyright
be_bryan 0:b74591d5ab33 18 * notice, this list of conditions and the following disclaimer.
be_bryan 0:b74591d5ab33 19 * - Redistributions in binary form must reproduce the above copyright
be_bryan 0:b74591d5ab33 20 * notice, this list of conditions and the following disclaimer in
be_bryan 0:b74591d5ab33 21 * the documentation and/or other materials provided with the
be_bryan 0:b74591d5ab33 22 * distribution.
be_bryan 0:b74591d5ab33 23 * - Neither the name of ARM LIMITED nor the names of its contributors
be_bryan 0:b74591d5ab33 24 * may be used to endorse or promote products derived from this
be_bryan 0:b74591d5ab33 25 * software without specific prior written permission.
be_bryan 0:b74591d5ab33 26 *
be_bryan 0:b74591d5ab33 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
be_bryan 0:b74591d5ab33 28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
be_bryan 0:b74591d5ab33 29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
be_bryan 0:b74591d5ab33 30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
be_bryan 0:b74591d5ab33 31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
be_bryan 0:b74591d5ab33 32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
be_bryan 0:b74591d5ab33 33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
be_bryan 0:b74591d5ab33 34 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
be_bryan 0:b74591d5ab33 35 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
be_bryan 0:b74591d5ab33 36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
be_bryan 0:b74591d5ab33 37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
be_bryan 0:b74591d5ab33 38 * POSSIBILITY OF SUCH DAMAGE.
be_bryan 0:b74591d5ab33 39 * -------------------------------------------------------------------- */
be_bryan 0:b74591d5ab33 40
be_bryan 0:b74591d5ab33 41 #include "arm_math.h"
be_bryan 0:b74591d5ab33 42
be_bryan 0:b74591d5ab33 43 /**
be_bryan 0:b74591d5ab33 44 * @ingroup groupMatrix
be_bryan 0:b74591d5ab33 45 */
be_bryan 0:b74591d5ab33 46
be_bryan 0:b74591d5ab33 47 /**
be_bryan 0:b74591d5ab33 48 * @addtogroup MatrixSub
be_bryan 0:b74591d5ab33 49 * @{
be_bryan 0:b74591d5ab33 50 */
be_bryan 0:b74591d5ab33 51
be_bryan 0:b74591d5ab33 52 /**
be_bryan 0:b74591d5ab33 53 * @brief Q15 matrix subtraction.
be_bryan 0:b74591d5ab33 54 * @param[in] *pSrcA points to the first input matrix structure
be_bryan 0:b74591d5ab33 55 * @param[in] *pSrcB points to the second input matrix structure
be_bryan 0:b74591d5ab33 56 * @param[out] *pDst points to output matrix structure
be_bryan 0:b74591d5ab33 57 * @return The function returns either
be_bryan 0:b74591d5ab33 58 * <code>ARM_MATH_SIZE_MISMATCH</code> or <code>ARM_MATH_SUCCESS</code> based on the outcome of size checking.
be_bryan 0:b74591d5ab33 59 *
be_bryan 0:b74591d5ab33 60 * <b>Scaling and Overflow Behavior:</b>
be_bryan 0:b74591d5ab33 61 * \par
be_bryan 0:b74591d5ab33 62 * The function uses saturating arithmetic.
be_bryan 0:b74591d5ab33 63 * Results outside of the allowable Q15 range [0x8000 0x7FFF] will be saturated.
be_bryan 0:b74591d5ab33 64 */
be_bryan 0:b74591d5ab33 65
be_bryan 0:b74591d5ab33 66 arm_status arm_mat_sub_q15(
be_bryan 0:b74591d5ab33 67 const arm_matrix_instance_q15 * pSrcA,
be_bryan 0:b74591d5ab33 68 const arm_matrix_instance_q15 * pSrcB,
be_bryan 0:b74591d5ab33 69 arm_matrix_instance_q15 * pDst)
be_bryan 0:b74591d5ab33 70 {
be_bryan 0:b74591d5ab33 71 q15_t *pInA = pSrcA->pData; /* input data matrix pointer A */
be_bryan 0:b74591d5ab33 72 q15_t *pInB = pSrcB->pData; /* input data matrix pointer B */
be_bryan 0:b74591d5ab33 73 q15_t *pOut = pDst->pData; /* output data matrix pointer */
be_bryan 0:b74591d5ab33 74 uint32_t numSamples; /* total number of elements in the matrix */
be_bryan 0:b74591d5ab33 75 uint32_t blkCnt; /* loop counters */
be_bryan 0:b74591d5ab33 76 arm_status status; /* status of matrix subtraction */
be_bryan 0:b74591d5ab33 77
be_bryan 0:b74591d5ab33 78
be_bryan 0:b74591d5ab33 79 #ifdef ARM_MATH_MATRIX_CHECK
be_bryan 0:b74591d5ab33 80
be_bryan 0:b74591d5ab33 81
be_bryan 0:b74591d5ab33 82 /* Check for matrix mismatch condition */
be_bryan 0:b74591d5ab33 83 if((pSrcA->numRows != pSrcB->numRows) ||
be_bryan 0:b74591d5ab33 84 (pSrcA->numCols != pSrcB->numCols) ||
be_bryan 0:b74591d5ab33 85 (pSrcA->numRows != pDst->numRows) || (pSrcA->numCols != pDst->numCols))
be_bryan 0:b74591d5ab33 86 {
be_bryan 0:b74591d5ab33 87 /* Set status as ARM_MATH_SIZE_MISMATCH */
be_bryan 0:b74591d5ab33 88 status = ARM_MATH_SIZE_MISMATCH;
be_bryan 0:b74591d5ab33 89 }
be_bryan 0:b74591d5ab33 90 else
be_bryan 0:b74591d5ab33 91 #endif /* #ifdef ARM_MATH_MATRIX_CHECK */
be_bryan 0:b74591d5ab33 92
be_bryan 0:b74591d5ab33 93 {
be_bryan 0:b74591d5ab33 94 /* Total number of samples in the input matrix */
be_bryan 0:b74591d5ab33 95 numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols;
be_bryan 0:b74591d5ab33 96
be_bryan 0:b74591d5ab33 97 #ifndef ARM_MATH_CM0_FAMILY
be_bryan 0:b74591d5ab33 98
be_bryan 0:b74591d5ab33 99 /* Run the below code for Cortex-M4 and Cortex-M3 */
be_bryan 0:b74591d5ab33 100
be_bryan 0:b74591d5ab33 101 /* Apply loop unrolling */
be_bryan 0:b74591d5ab33 102 blkCnt = numSamples >> 2u;
be_bryan 0:b74591d5ab33 103
be_bryan 0:b74591d5ab33 104 /* First part of the processing with loop unrolling. Compute 4 outputs at a time.
be_bryan 0:b74591d5ab33 105 ** a second loop below computes the remaining 1 to 3 samples. */
be_bryan 0:b74591d5ab33 106 while(blkCnt > 0u)
be_bryan 0:b74591d5ab33 107 {
be_bryan 0:b74591d5ab33 108 /* C(m,n) = A(m,n) - B(m,n) */
be_bryan 0:b74591d5ab33 109 /* Subtract, Saturate and then store the results in the destination buffer. */
be_bryan 0:b74591d5ab33 110 *__SIMD32(pOut)++ = __QSUB16(*__SIMD32(pInA)++, *__SIMD32(pInB)++);
be_bryan 0:b74591d5ab33 111 *__SIMD32(pOut)++ = __QSUB16(*__SIMD32(pInA)++, *__SIMD32(pInB)++);
be_bryan 0:b74591d5ab33 112
be_bryan 0:b74591d5ab33 113 /* Decrement the loop counter */
be_bryan 0:b74591d5ab33 114 blkCnt--;
be_bryan 0:b74591d5ab33 115 }
be_bryan 0:b74591d5ab33 116
be_bryan 0:b74591d5ab33 117 /* If the blockSize is not a multiple of 4, compute any remaining output samples here.
be_bryan 0:b74591d5ab33 118 ** No loop unrolling is used. */
be_bryan 0:b74591d5ab33 119 blkCnt = numSamples % 0x4u;
be_bryan 0:b74591d5ab33 120
be_bryan 0:b74591d5ab33 121 while(blkCnt > 0u)
be_bryan 0:b74591d5ab33 122 {
be_bryan 0:b74591d5ab33 123 /* C(m,n) = A(m,n) - B(m,n) */
be_bryan 0:b74591d5ab33 124 /* Subtract and then store the results in the destination buffer. */
be_bryan 0:b74591d5ab33 125 *pOut++ = (q15_t) __QSUB16(*pInA++, *pInB++);
be_bryan 0:b74591d5ab33 126
be_bryan 0:b74591d5ab33 127 /* Decrement the loop counter */
be_bryan 0:b74591d5ab33 128 blkCnt--;
be_bryan 0:b74591d5ab33 129 }
be_bryan 0:b74591d5ab33 130
be_bryan 0:b74591d5ab33 131 #else
be_bryan 0:b74591d5ab33 132
be_bryan 0:b74591d5ab33 133 /* Run the below code for Cortex-M0 */
be_bryan 0:b74591d5ab33 134
be_bryan 0:b74591d5ab33 135 /* Initialize blkCnt with number of samples */
be_bryan 0:b74591d5ab33 136 blkCnt = numSamples;
be_bryan 0:b74591d5ab33 137
be_bryan 0:b74591d5ab33 138 while(blkCnt > 0u)
be_bryan 0:b74591d5ab33 139 {
be_bryan 0:b74591d5ab33 140 /* C(m,n) = A(m,n) - B(m,n) */
be_bryan 0:b74591d5ab33 141 /* Subtract and then store the results in the destination buffer. */
be_bryan 0:b74591d5ab33 142 *pOut++ = (q15_t) __SSAT(((q31_t) * pInA++ - *pInB++), 16);
be_bryan 0:b74591d5ab33 143
be_bryan 0:b74591d5ab33 144 /* Decrement the loop counter */
be_bryan 0:b74591d5ab33 145 blkCnt--;
be_bryan 0:b74591d5ab33 146 }
be_bryan 0:b74591d5ab33 147
be_bryan 0:b74591d5ab33 148 #endif /* #ifndef ARM_MATH_CM0_FAMILY */
be_bryan 0:b74591d5ab33 149
be_bryan 0:b74591d5ab33 150 /* Set status as ARM_MATH_SUCCESS */
be_bryan 0:b74591d5ab33 151 status = ARM_MATH_SUCCESS;
be_bryan 0:b74591d5ab33 152 }
be_bryan 0:b74591d5ab33 153
be_bryan 0:b74591d5ab33 154 /* Return to application */
be_bryan 0:b74591d5ab33 155 return (status);
be_bryan 0:b74591d5ab33 156 }
be_bryan 0:b74591d5ab33 157
be_bryan 0:b74591d5ab33 158 /**
be_bryan 0:b74591d5ab33 159 * @} end of MatrixSub group
be_bryan 0:b74591d5ab33 160 */