diff --git a/examples/msp430x/small/msp430fr5994/launchpad/fft_lea/README.md b/examples/msp430x/small/msp430fr5994/launchpad/fft_lea/README.md new file mode 100644 index 000000000..46d2adcfe --- /dev/null +++ b/examples/msp430x/small/msp430fr5994/launchpad/fft_lea/README.md @@ -0,0 +1,12 @@ +# Basic example using LEA to perform fft + +This application is a simple example with a variable defined in LEA_SRAM. +To define the appropriate section that is used, with follow the rules given by the AUTOSAR standard, using a symbol definition, followed by the inclusion of a tpl_memmap.h header file. + +This approach make the application independant of the linker directives. + +The SystemCounter is at 1ms. The serial configuration is 9600, 8N1, with the serial line connected to the debugger (/dev/ttyACM1 on Linux). + +` +goil --target=msp430x/small/msp430fr5994/launchpad --templates=../../../../../../goil/templates/ fft_lea.oil +` diff --git a/examples/msp430x/small/msp430fr5994/launchpad/fft_lea/fft_lea.c b/examples/msp430x/small/msp430fr5994/launchpad/fft_lea/fft_lea.c new file mode 100644 index 000000000..083f4fdce --- /dev/null +++ b/examples/msp430x/small/msp430fr5994/launchpad/fft_lea/fft_lea.c @@ -0,0 +1,101 @@ +#include "tpl_os.h" +#include "msp430.h" +#include +#include +#include +#include "tpl_clocks.h" + +/* Input signal parameters */ +#define FS 8192 +#define SAMPLES 256 +#define SIGNAL_FREQUENCY1 200 +#define SIGNAL_AMPLITUDE1 0.6 + +/* Constants */ +#define PI 3.1415926536 + +#define APP_Task_fft_START_SEC_LEA_VAR_LEA_16BIT +#include "tpl_memmap.h" + +VAR(_q15, AUTOMATIC) input[SAMPLES]; + +#define APP_Task_fft_STOP_SEC_LEA_VAR_LEA_16BIT +#include "tpl_memmap.h" + +/* Function prototypes */ +extern void initSignal(void); + +#define APP_Task_fft_START_SEC_CODE +#include "tpl_memmap.h" + + +/*----------------------------------------------------------------------------*/ +/* main function */ +/*----------------------------------------------------------------------------*/ +FUNC(int, OS_APPL_CODE) main(void) +{ + /* Disable WDT */ + WDTCTL = WDTPW + WDTHOLD; + + P1DIR |= BIT0 + BIT1; + P1OUT &= ~BIT0; + P1OUT &= ~BIT1; + + PM5CTL0 &= ~LOCKLPM5; + + tpl_serial_begin(); + StartOS(OSDEFAULTAPPMODE); + return 0; +} + +void initSignal(void){ + msp_status status; + msp_sinusoid_q15_params sinParams; + /* Generate Q15 input signal */ + sinParams.length = SAMPLES; + sinParams.amplitude = _Q15(SIGNAL_AMPLITUDE1); + sinParams.cosOmega = _Q15(cosf(2*PI*SIGNAL_FREQUENCY1/FS)); + sinParams.sinOmega = _Q15(sinf(2*PI*SIGNAL_FREQUENCY1/FS)); + status = msp_sinusoid_q15(&sinParams, input); + msp_checkStatus(status); +} + +//#define APP_COMMON_STOP_SEC_CODE +//#include "tpl_memmap.h" + +//#define APP_Task_fft_START_SEC_CODE +//#include "tpl_memmap.h" +/*----------------------------------------------------------------------------*/ +/* TASK fft */ +/*----------------------------------------------------------------------------*/ +TASK(fft) +{ + P1OUT |= BIT0; + msp_status status; + msp_fft_q15_params fftParams; + int i; + + initSignal(); + + for(i=0; i 4096 then + let OS::LEA_S::LEA_RAM := 4096 + end if + let lea_origin := 0x3BFF - OS::LEA_S::LEA_RAM + let size_ram := 0x1000 + 0x1000 - OS::LEA_S::LEA_RAM +% + RAM (xrw) : ORIGIN = 0x01C00, LENGTH = %!size_ram% /* size is [4k - 8k] */ + LEA_RAM (xrw) : ORIGIN = %!lea_origin%, LENGTH = %!OS::LEA_S::LEA_RAM% /* size is [0k - 4k] */ +% +else% RAM (xrw) : ORIGIN = 0x01C00, LENGTH = 0x2000 /* size is 8k */ +% +end if +% } diff --git a/goil/templates/linker/gnu_ld/msp430x/small/msp430fr5994/script.goilTemplate b/goil/templates/linker/gnu_ld/msp430x/small/msp430fr5994/script.goilTemplate index d567fb248..5cfc4f0a9 100755 --- a/goil/templates/linker/gnu_ld/msp430x/small/msp430fr5994/script.goilTemplate +++ b/goil/templates/linker/gnu_ld/msp430x/small/msp430fr5994/script.goilTemplate @@ -303,7 +303,40 @@ end foreach . += SIZEOF(.data); } >FRAM } - +% +if OS::LEA then +% +SECTIONS { +.data_lea : { +% +foreach proc in PROCESSES do +% +/* Initialized LEA variables section of % !proc::KIND % % !proc::NAME % */ +% + foreach DATA_SIZE in @( "32BIT","16BIT","8BIT","BOOLEAN","UNSPECIFIED" ) do + foreach SECTION_KIND in @( "_LEA_" ) do +% *(.% !proc::KIND %_% !proc::NAME %_SEC_LEA_VAR% !SECTION_KIND !DATA_SIZE %) +% + end foreach + end foreach +end foreach +foreach app in APPLICATIONS do +%/* Initialized variables sections of OS_APP % !app::NAME % */ +% + foreach DATA_SIZE in @( "32BIT","16BIT","8BIT","BOOLEAN","UNSPECIFIED" ) do + foreach SECTION_KIND in @( "_POWER_ON_INIT_" ) do +% *(.OS_APP_% !app::NAME %_SEC_LEA_VAR% !SECTION_KIND !DATA_SIZE %) +% + end foreach + end foreach +end foreach +% + . = ALIGN(4); + } > LEA_RAM +} +% +end if +% /* * private data of processes */ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib.h new file mode 100755 index 000000000..d8c42a1b1 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib.h @@ -0,0 +1,50 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_H__ +#define __DSPLIB_H__ + +#include "msp430.h" + +#include +#include + +#include "DSPLib_types.h" // Include DSPLib type definitions +#include "DSPLib_lea.h" // Include DSPLib LEA definitions +#include "DSPLib_support.h" // Include DSPLib support functions +#include "DSPLib_vector.h" // Include DSPLib vector functions +#include "DSPLib_matrix.h" // Include DSPLib matrix functions +#include "DSPLib_filter.h" // Include DSPLib filter functions +#include "DSPLib_transform.h" // Include DSPLib transform functions +#include "DSPLib_utility.h" // Include DSPLib utility functions +#include "DSPLib_ROM.h" // Include DSPLib ROM functions + +#endif //__DSPLIB_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_ROM.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_ROM.h new file mode 100755 index 000000000..13469b187 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_ROM.h @@ -0,0 +1,321 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_ROM_H__ +#define __DSPLIB_ROM_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_support Support +//! @{ +//! +//! \defgroup dsplib_support_rom ROM +//! Definitions required to support the use of DSPLib functions in ROM. +//! +//! @} +// +//****************************************************************************** + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +#if (defined(__MSP430FR2355__) || defined(__MSP430FR2353__) || \ + defined(__MSP430FR2155__) || defined(__MSP430FR2153__)) && !defined(MSP_DISABLE_ROM) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Use DSPLib functions located in ROM. The default is to use ROM +//! functions when available, to disable use of ROM functions define +//! MSP_DISABLE_ROM in the compiler settings. +//! +//! It is always recommended to use ROM functions for lowest power and best +//! performance. Disabling ROM functions is only recommended for debugging. +// +//****************************************************************************** +#define MSP_USE_ROM 1 + +// Check for compatible code model +#if (defined(__TI_COMPILER_VERSION__) && !defined(__LARGE_CODE_MODEL__)) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__CODE_MODEL__!=__CODE_MODEL_LARGE__)) +#error "Incompatible code model selected, switch to large code model or \ +disable ROM functions by defining MSP_DISABLE_ROM in compiler settings." +#endif + +// Check for compatible data model +#if (defined(__TI_COMPILER_VERSION__) && !defined(__LARGE_DATA_MODEL__)) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__DATA_MODEL__!=__DATA_MODEL_LARGE__)) +#error "Incompatible data model selected, switch to large code model or \ +disable ROM functions by defining MSP_DISABLE_ROM in compiler settings." +#endif + +// Check CCS compiler version for ROM compatability +#if defined(__TI_COMPILER_VERSION__) +#if __TI_COMPILER_VERSION__ >= 18001001 +#define __cc_rom __attribute__((call_conv("cc_rom"))) +#else +#error "The cc_rom attribute requires MSP TI COMPILER 18.1.1.LTS or newer, \ +please upgrade your compiler to use this version of DSPLib with ROM funcitons." +#endif +#endif + +// Check IAR register model +#if defined(__IAR_SYSTEMS_ICC__) +#if __REGISTER_R4__ != __REGISTER_FREE__ +#error "Incorrect setting for R4, expected it to be free." +#endif +#if __REGISTER_R5__ != __REGISTER_FREE__ +#error "Incorrect setting for R5, expected it to be free." +#endif +#endif + +// Suppress CCS type conversion warning +#if defined (__TI_COMPILER_VERSION__) +#pragma diag_suppress 173 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief DSPLib API table for functions located in ROM. +// +//****************************************************************************** +#define ROM_DSPLIB_TABLE ((uint32_t *)(((uint32_t *)ROMLIB_START)[1])) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for ROM msp_fft_auto_q15() function. +// +//****************************************************************************** +#define ROM_msp_fft_auto_q15 \ + ((msp_status (__cc_rom *) \ + (const msp_fft_q15_params *params, int16_t *src, uint16_t *shift)) \ + ROM_DSPLIB_TABLE[0]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for ROM msp_fft_fixed_q15() function. +// +//****************************************************************************** +#define ROM_msp_fft_fixed_q15 \ + ((msp_status (__cc_rom *) \ + (const msp_fft_q15_params *params, int16_t *src)) \ + ROM_DSPLIB_TABLE[1]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for ROM msp_fft_iq31() function. +// +//****************************************************************************** +#define ROM_msp_fft_iq31 \ + ((msp_status (__cc_rom *) \ + (const msp_fft_iq31_params *params, int32_t *src)) \ + ROM_DSPLIB_TABLE[2]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for ROM msp_cmplx_fft_auto_q15() function. +// +//****************************************************************************** +#define ROM_msp_cmplx_fft_auto_q15 \ + ((msp_status (__cc_rom *) \ + (const msp_cmplx_fft_q15_params *params, int16_t *src, uint16_t *shift)) \ + ROM_DSPLIB_TABLE[3]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for ROM msp_cmplx_fft_fixed_q15() function. +// +//****************************************************************************** +#define ROM_msp_cmplx_fft_fixed_q15 \ + ((msp_status (__cc_rom *) \ + (const msp_cmplx_fft_q15_params *params, int16_t *src)) \ + ROM_DSPLIB_TABLE[4]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for ROM msp_cmplx_fft_iq31() function. +// +//****************************************************************************** +#define ROM_msp_cmplx_fft_iq31 \ + ((msp_status (__cc_rom *) \ + (const msp_cmplx_fft_iq31_params *params, int32_t *src)) \ + ROM_DSPLIB_TABLE[5]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for ROM twiddle table. +// +//****************************************************************************** +#define ROM_msp_cmplx_twiddle_table_2048_q15 \ + ((_q15 *)ROM_DSPLIB_TABLE[6]) + +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for MAP msp_fft_auto_q15() function. +// +//****************************************************************************** +#ifdef ROM_msp_fft_auto_q15 +#define MAP_msp_fft_auto_q15 \ + ROM_msp_fft_auto_q15 +#else +#define MAP_msp_fft_auto_q15 \ + msp_fft_auto_q15 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for MAP msp_fft_fixed_q15() function. +// +//****************************************************************************** +#ifdef ROM_msp_fft_fixed_q15 +#define MAP_msp_fft_fixed_q15 \ + ROM_msp_fft_fixed_q15 +#else +#define MAP_msp_fft_fixed_q15 \ + msp_fft_fixed_q15 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for MAP msp_fft_iq31() function. +// +//****************************************************************************** +#ifdef ROM_msp_fft_iq31 +#define MAP_msp_fft_iq31 \ + ROM_msp_fft_iq31 +#else +#define MAP_msp_fft_iq31 \ + msp_fft_iq31 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for MAP msp_cmplx_fft_auto_q15() function. +// +//****************************************************************************** +#ifdef ROM_msp_cmplx_fft_auto_q15 +#define MAP_msp_cmplx_fft_auto_q15 \ + ROM_msp_cmplx_fft_auto_q15 +#else +#define MAP_msp_cmplx_fft_auto_q15 \ + msp_cmplx_fft_auto_q15 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for MAP msp_cmplx_fft_fixed_q15() function. +// +//****************************************************************************** +#ifdef ROM_msp_cmplx_fft_fixed_q15 +#define MAP_msp_cmplx_fft_fixed_q15 \ + ROM_msp_cmplx_fft_fixed_q15 +#else +#define MAP_msp_cmplx_fft_fixed_q15 \ + msp_cmplx_fft_fixed_q15 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +//! +//! \brief Definition for MAP msp_cmplx_fft_iq31() function. +// +//****************************************************************************** +#ifdef ROM_msp_cmplx_fft_iq31 +#define MAP_msp_cmplx_fft_iq31 \ + ROM_msp_cmplx_fft_iq31 +#else +#define MAP_msp_cmplx_fft_iq31 \ + msp_cmplx_fft_iq31 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_rom +// +//! \brief Definition for MAP twiddle table. +// +//****************************************************************************** +#ifdef ROM_msp_cmplx_twiddle_table_2048_q15 +#define MAP_msp_cmplx_twiddle_table_2048_q15 \ + ROM_msp_cmplx_twiddle_table_2048_q15 +#else +#define MAP_msp_cmplx_twiddle_table_2048_q15 \ + msp_cmplx_twiddle_table_2048_q15 +#endif + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_ROM_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_filter.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_filter.h new file mode 100755 index 000000000..46c319857 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_filter.h @@ -0,0 +1,862 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_FILTER_H__ +#define __DSPLIB_FILTER_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_filter_api Filter +//! @{ +//! +//! Functions for common digital filters such as Finite Impulse Response (FIR) +//! and Infinite Impulse Response (IIR). The filter functions support real and +//! complex inputs as well as 16-bit and 32-bit data types. +//! +//! \defgroup dsplib_filter_real_fir Real FIR +//! Functions for performing real Finite Impulse Response (FIR) filters. +//! +//! \defgroup dsplib_filter_complex_fir Complex FIR +//! Functions for performing complex Finite Impulse Response (FIR) filters. +//! +//! \defgroup dsplib_filter_real_iir Real IIR +//! Functions for performing real Infinite Impulse Response (IIR) filters. +//! +//! @} +// +//****************************************************************************** + +//****************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//****************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_fir +//! +//! \brief Calculate the alignment for a 16-bit real FIR filter from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_FIR_Q15(n) (n*4) + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_fir +//! +//! \brief Calculate the alignment for a 32-bit real FIR filter from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_FIR_IQ31(n) (n*8) + +//****************************************************************************** +// +//! \ingroup dsplib_filter_complex_fir +//! +//! \brief Calculate the alignment for a 16-bit complex FIR filter from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_CMPLX_FIR_Q15(n) (n*8) + +//****************************************************************************** +// +//! \ingroup dsplib_filter_complex_fir +//! +//! \brief Calculate the alignment for a 32-bit complex FIR filter from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_CMPLX_FIR_IQ31(n) (n*16) + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_fir +//! +//! \brief Parameter structure for FIR filter. +// +//****************************************************************************** +typedef struct msp_fir_q15_params { + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Length of FIR coefficients, must be a multiple of two. + uint16_t tapLength; + //! \details + //! Pointer to real FIR filter coefficients. + const _q15 *coeffs; + //! \details + //! Enable circular buffer. + bool enableCircularBuffer; +} msp_fir_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_fir +//! +//! \brief Parameter structure for FIR filter. +// +//****************************************************************************** +typedef struct msp_fir_iq31_params { + //! \details + //! Length of the output, must be a multiple of two. + uint16_t length; + //! \details + //! Length of FIR coefficients, must be a multiple of two. + uint16_t tapLength; + //! \details + //! Pointer to real FIR filter coefficients. + const _iq31 *coeffs; + //! \details + //! Enable circular buffer. + bool enableCircularBuffer; +} msp_fir_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_complex_fir +//! +//! \brief Parameter structure for complex FIR filter. +// +//****************************************************************************** +typedef struct msp_cmplx_fir_q15_params{ + //! \details + //! Length of the output, must be a multiple of two. + uint16_t length; + //! \details + //! Length of FIR coefficients, must be a multiple of two. + uint16_t tapLength; + //! \details + //! Pointer to complex FIR filter coefficients. + const _q15 *coeffs; + //! \details + //! Enable circular buffer. + bool enableCircularBuffer; +} msp_cmplx_fir_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_complex_fir +//! +//! \brief Parameter structure for complex FIR filter. +// +//****************************************************************************** +typedef struct msp_cmplx_fir_iq31_params{ + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Length of FIR coefficients, must be a multiple of two. + uint16_t tapLength; + //! \details + //! Pointer to complex FIR filter coefficients. + const _iq31 *coeffs; + //! \details + //! Enable circular buffer. + bool enableCircularBuffer; +} msp_cmplx_fir_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Coefficients for direct form 1 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_df1_q15_coeffs { + //! \details + //! Coefficient b2 + _q15 b2; + //! \details + //! Coefficient b1 divided by two + _q15 b1By2; + //! \details + //! Coefficient b0 + _q15 b0; + //! \details + //! Reserved, do not remove + uint16_t reserved1; + //! \details + //! Coefficient a2 + _q15 a2; + //! \details + //! Coefficient a1 divided by two + _q15 a1By2; +} msp_biquad_df1_q15_coeffs; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief States for direct form 1 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_df1_q15_states { + //! \details + //! Input x[n-2] + _q15 x2; + //! \details + //! Input x[n-1] + _q15 x1; + //! \details + //! Output y[n-2] + _q15 y2; + //! \details + //! Output y[n-1] + _q15 y1; +} msp_biquad_df1_q15_states; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Parameter structure for direct form 1 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_df1_q15_params { + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Pointer to DF1 filter coefficients. This data block must be allocated in + //! shared RAM when using LEA. + const msp_biquad_df1_q15_coeffs *coeffs; + //! \details + //! Pointer to an array of length four used to store the state of the + //! operation. When continuous operation is desired the previous state + //! needs to be passed to the next biquad operation. This data block must be + //! allocated in shared RAM when using LEA. + msp_biquad_df1_q15_states *states; +} msp_biquad_df1_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Parameter structure for cascaded direct form 1 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_cascade_df1_q15_params { + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Number of cascaded biquad filters, typically the filter order divided by + //! two. + uint16_t stages; + //! \details + //! Pointer to an array of DF1 filter coefficients of length stages. This + //! data block must be allocated in shared RAM when using LEA. + const msp_biquad_df1_q15_coeffs *coeffs; + //! \details + //! Pointer to an array of DF1 filter states of length stages. When + //! continuous operation is desired the previous states must be passed to + //! the next cascaded biquad operation. This data block must be allocated in + //! shared RAM when using LEA. + msp_biquad_df1_q15_states *states; +} msp_biquad_cascade_df1_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Coefficients for direct form 2 biquad filter. When using LEA these +//! coefficients must be placed into shared RAM. +// +//****************************************************************************** +typedef struct msp_biquad_df2_q15_coeffs { + //! \details + //! Reserved, do not remove + uint16_t reserved1; + //! \details + //! Coefficient a2 + _q15 a2; + //! \details + //! Coefficient a1 divided by two + _q15 a1By2; + //! \details + //! Coefficient a0 + _q15 a0; + //! \details + //! Coefficient b0 + _q15 b0; + //! \details + //! Coefficient b1 divided by two + _q15 b1By2; + //! \details + //! Coefficient b2 + _q15 b2; + //! \details + //! Reserved, do not remove + uint16_t reserved2; +} msp_biquad_df2_q15_coeffs; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief States for direct form 2 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_df2_q15_states { + //! \details + //! State Q1 + _q15 q1; + //! \details + //! State Q2 + _q15 q2; +} msp_biquad_df2_q15_states; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Parameter structure for direct form 2 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_df2_q15_params { + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Pointer to DF2 filter coefficients. This data block must be allocated in + //! shared RAM when using LEA. + const msp_biquad_df2_q15_coeffs *coeffs; + //! \details + //! Pointer to an array of length two used to store the state of the + //! operation. When continuous operation is desired the previous state + //! needs to be passed to the next biquad operation. This data block must be + //! allocated in shared RAM when using LEA. + msp_biquad_df2_q15_states *states; +} msp_biquad_df2_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Parameter structure for cascaded direct form 2 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_cascade_df2_q15_params { + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Number of cascaded biquad filters, typically the filter order divided by + //! two. + uint16_t stages; + //! \details + //! Pointer to an array of DF2 filter coefficients of length stages. This + //! data block must be allocated in shared RAM when using LEA. + const msp_biquad_df2_q15_coeffs *coeffs; + //! \details + //! Pointer to an array of DF2 filter states of length stages. When + //! continuous operation is desired the previous states must be passed to + //! the next cascaded biquad operation. This data block must be allocated in + //! shared RAM when using LEA. + msp_biquad_df2_q15_states *states; +} msp_biquad_cascade_df2_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Coefficients for extended direct form 2 biquad filter. When using +//! LEA these coefficients must be placed into shared RAM. +// +//****************************************************************************** +typedef struct msp_biquad_df2_ext_q15_coeffs { + //! \details + //! Constant bias added to input. + _iq31 bias; + //! \details + //! Reserved, do not remove + uint16_t reserved1; + //! \details + //! Coefficient a2 + _q15 a2; + //! \details + //! Coefficient a1 divided by two + _q15 a1By2; + //! \details + //! Coefficient a0 + _q15 a0; + //! \details + //! Coefficient b0 + _q15 b0; + //! \details + //! Coefficient b1 divided by two + _q15 b1By2; + //! \details + //! Coefficient b2 + _q15 b2; + //! \details + //! Reserved, do not remove + uint16_t reserved2; +} msp_biquad_df2_ext_q15_coeffs; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief States for extended direct form 2 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_df2_ext_q15_states { + //! \details + //! State Q1 + _q15 q1; + //! \details + //! State Q2 + _q15 q2; + //! \details + //! Minimum of even states + _q15 minEven; + //! \details + //! Minimum of odd states + _q15 minOdd; + //! \details + //! Maximum of even states + _q15 maxEven; + //! \details + //! Maximum of odd states + _q15 maxOdd; + //! \details + //! Minimum intermediate state + _q15 min; + //! \details + //! Maximum intermediate state + _q15 max; +} msp_biquad_df2_ext_q15_states; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Parameter structure for extended direct form 2 biquad filter. +// +//****************************************************************************** +typedef struct msp_biquad_df2_ext_q15_params { + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Pointer to extended DF2 filter coefficients. This data block must be + //! allocated in shared RAM when using LEA. + const msp_biquad_df2_ext_q15_coeffs *coeffs; + //! \details + //! Pointer to an array of length eight used to store the state of the + //! operation. When continuous operation is desired the previous state + //! needs to be passed to the next biquad operation. This data block must be + //! allocated in shared RAM when using LEA. + msp_biquad_df2_ext_q15_states *states; +} msp_biquad_df2_ext_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Parameter structure for cascaded extended direct form 2 biquad +//! filter. +// +//****************************************************************************** +typedef struct msp_biquad_cascade_df2_ext_q15_params { + //! \details + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! \details + //! Number of cascaded biquad filters, typically the filter order divided by + //! two. + uint16_t stages; + //! \details + //! Pointer to an array of DF2 filter coefficients of length stages. This + //! data block must be allocated in shared RAM when using LEA. + const msp_biquad_df2_ext_q15_coeffs *coeffs; + //! \details + //! Pointer to an array of DF2 filter states of length stages. When + //! continuous operation is desired the previous states must be passed to + //! the next cascaded biquad operation. This data block must be allocated in + //! shared RAM when using LEA. + msp_biquad_df2_ext_q15_states *states; +} msp_biquad_cascade_df2_ext_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_fir +//! +//! \brief Discrete-time convolution of a source vector with real coefficients +//! to apply an FIR filter. +//! +//! \par Details +//! FIR filter implementation utilizing discrete-time convolution. Q15 +//! multiplication is performed with a 32-bit accumulator to avoid intermediate +//! overflow. +//! +//! \par Pseudo code +//! `dst = conv([stateBuffer, src], taps)(0:1:length)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment when circular buffer is disabled or +//! aligned to four times the FIR data length if circular buffer is enabled +//! (e.g. a 64-sample FIR with 128-sample circular buffer must be aligned to a +//! 256-byte address). When allocating data the MSP\_ALIGN\_FIR\_Q15 macro can +//! be used to calculate the correct alignment. +//! +//! \param params Pointer to the FIR parameter structure. +//! \param src Pointer to the source vector to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_fir_q15( + const msp_fir_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_fir +//! +//! \brief Discrete-time convolution of a source vector with real coefficients +//! to apply an FIR filter. +//! +//! \par Details +//! FIR filter implementation utilizing discrete-time convolution. IQ31 +//! multiplication is performed with a 32-bit accumulator to avoid intermediate +//! overflow. +//! +//! \par Pseudo code +//! `dst = conv([stateBuffer, src], taps)(0:1:length)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment when circular buffer is disabled or +//! aligned to eight times the FIR data length if circular buffer is enabled +//! (e.g. a 64-sample FIR with 128-sample circular buffer must be aligned to a +//! 512-byte address). When allocating data the MSP\_ALIGN\_FIR\_IQ31 macro can +//! be used to calculate the correct alignment. +//! +//! \param params Pointer to the FIR parameter structure. +//! \param src Pointer to the source vector to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_fir_iq31( + const msp_fir_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_complex_fir +//! +//! \brief Discrete-time convolution of a complex source vector with complex +//! coefficients to apply an FIR filter. +//! +//! \par Details +//! FIR filter implementation utilizing discrete-time convolution. Complex Q15 +//! multiplication is performed with a 32-bit accumulator to avoid intermediate +//! overflow. +//! +//! \par Pseudo code +//! `dst = conv([stateBuffer, src], taps)(0:1:length)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment when circular buffer is disabled or +//! aligned to eight times the FIR data length if circular buffer is enabled +//! (e.g. a 64-sample FIR with 128-sample circular buffer must be aligned to a +//! 512-byte address). When allocating data the MSP\_ALIGN\_CMPLX\_FIR\_Q15 +//! macro can be used to calculate the correct alignment. +//! +//! \param params Pointer to the complex FIR parameter structure. +//! \param src Pointer to the source vector to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_fir_q15( + const msp_cmplx_fir_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_complex_fir +//! +//! \brief Discrete-time convolution of a complex source vector with complex +//! coefficients to apply an FIR filter. +//! +//! \par Details +//! FIR filter implementation utilizing discrete-time convolution. Complex IQ31 +//! multiplication is performed with a 32-bit accumulator to avoid intermediate +//! overflow. +//! +//! \par Pseudo code +//! `dst = conv([stateBuffer, src], taps)(0:1:length)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment when circular buffer is disabled or +//! aligned to sixteen times the FIR data length if circular buffer is enabled +//! (e.g. a 64-sample FIR with 128-sample circular buffer must be aligned to a +//! 1024-byte address). When allocating data the MSP\_ALIGN\_CMPLX\_FIR\_IQ31 +//! macro can be used to calculate the correct alignment. +//! +//! \param params Pointer to the complex FIR parameter structure. +//! \param src Pointer to the source vector to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_fir_iq31( + const msp_cmplx_fir_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Second-order direct form 1 biquad filter. +//! +//! \par Details +//! Second-order biquad filter with direct form 1 implementation. Q15 +//! multiplication is performed with a 32-bit accumulator to avoid intermediate +//! overflow with saturation to Q15 when storing the result. +//! +//! ![Biquad DF1 structure](images/biquad_df1.svg) +//! +//! \par Pseudo code +//! `y[n] = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2]` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the biquad direct form 1 parameter structure. +//! \param src Pointer to the source data to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_biquad_df1_q15( + const msp_biquad_df1_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Cascaded direct form 1 biquad filter. +//! +//! \par Details +//! Cascaded biquad filter with direct form 1 implementation. The coefficients +//! are passed as an array of second-order sections (SOS matrix) and each +//! section is passed to msp_biquad_df1_q15 to filter the input. +//! +//! ![Example filter with three DF1 stages](images/biquad_cascade_df1.svg) +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the cascaded biquad direct form 1 parameter +//! structure. +//! \param src Pointer to the source data to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_biquad_cascade_df1_q15( + const msp_biquad_cascade_df1_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Second-order direct form 2 biquad filter. +//! +//! \par Details +//! Second-order direct form 2 biquad filter. Q15 multiplication is performed +//! with a 32-bit accumulator to avoid intermediate overflow with saturation to +//! Q15 when storing the result. +//! +//! ![Biquad DF2 structure](images/biquad_df2.svg) +//! +//! \par Pseudo code +//! `y[n] = b0 * w[n] + b1 * w[n-1] + b2 * w[n-2]` \n +//! `w[n] = a0 * x[n] + a1 * x[n-1] + a2 * x[n-2]` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the biquad direct form 2 parameter structure. +//! \param src Pointer to the source data to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_biquad_df2_q15( + const msp_biquad_df2_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Cascaded direct form 2 biquad filter. +//! +//! \par Details +//! Cascaded biquad filter with direct form 2 implementation. The coefficients +//! are passed as an array of second-order sections (SOS matrix) and each +//! section is passed to msp_biquad_df1_q15 to filter the input. +//! +//! ![Example filter with three DF2 stages](images/biquad_cascade_df2.svg) +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the cascaded biquad direct form 2 parameter +//! structure. +//! \param src Pointer to the source data to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_biquad_cascade_df2_q15( + const msp_biquad_cascade_df2_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Second-order direct form 2 biquad filter extended with DC bias and +//! minimum and maximum tracking. +//! +//! \par Details +//! Second-order direct form 2 biquad filter extended to include bias and +//! minimum and maximum state tracking. Q15 multiplication is performed with a +//! 32-bit accumulator to avoid intermediate overflow with saturation to Q15 +//! when storing the result. The maximum and minimum of the intermediate states +//! are stored in the state structure. +//! +//! ![Biquad DF2 structure (extended)](images/biquad_df2_ext.svg) +//! +//! \par Pseudo code +//! `y[n] = b0 * w[n] + b1 * w[n-1] + b2 * w[n-2]` \n +//! `w[n] = a0 * x[n] + a1 * x[n-1] + a2 * x[n-2]` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the biquad direct form 2 parameter structure. +//! \param src Pointer to the source data to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_biquad_df2_ext_q15( + const msp_biquad_df2_ext_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_filter_real_iir +//! +//! \brief Cascaded direct form 2 biquad filter extended with DC bias and +//! minimum and maximum tracking. +//! +//! \par Details +//! Cascaded biquad filter with direct form 2 implementation extended to include +//! bias and minimum and maximum state tracking. The coefficients are passed +//! as an array of second-order sections (SOS matrix) and each section is passed +//! to msp_biquad_df2_ext_q15 to filter the input. +//! +//! ![Example filter with three DF2 stages](images/biquad_cascade_df2_ext.svg) +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the cascaded biquad direct form 2 parameter +//! structure. +//! \param src Pointer to the source data to filter. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_biquad_cascade_df2_ext_q15( + const msp_biquad_cascade_df2_ext_q15_params *params, + const _q15 *src, + _q15 *dst); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_FILTER_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_lea.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_lea.h new file mode 100755 index 000000000..d4e1d6d5e --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_lea.h @@ -0,0 +1,1285 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_LEA_H__ +#define __DSPLIB_LEA_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_support Support +//! @{ +//! +//! \defgroup dsplib_support_lea LEA +//! Definitions required to support the use of LEA. +//! +//! @} +// +//****************************************************************************** + +//***************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//***************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +#if defined(__MSP430_HAS_LEA__) && !defined(MSP_DISABLE_LEA) + +#if __MSP430_HEADER_VERSION__ < 1192 +#error "DSPLib: Device header file is out of date, please upgrade to the \ +latest support package to use this version of DSPLib with LEA." +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Enable the LEA accelerator for DSPLib functions. The default is +//! to use LEA when available, to disable LEA define MSP_DISABLE_LEA in +//! the compiler settings. +//! +//! It is always recommended to use LEA for lowest power and best performance. +//! Disabling LEA is only intended to be used for benchmarking LEA +//! performance against the CPU and hardware multiplier or by users who would +//! like to dedicate the LEA peripheral to a specific function and run the +//! remainder on the CPU. +// +//****************************************************************************** +#define MSP_USE_LEA 1 + +// LEA revision A. +#define MSP_LEA_REVISION_A 0 + +// LEA revision B. +#define MSP_LEA_REVISION_B 1 + +// LEA revision B. +#define MSP_LEA_REVISION_C 2 + +// Unknown revision of LEA. +#define MSP_LEA_REVISION_UNKNOWN 255 + +#if !defined(MSP_LEA_REVISION) + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief If a LEA revision is not specified default to revision B. +// +//****************************************************************************** +#define MSP_LEA_REVISION MSP_LEA_REVISION_B + +#endif //MSP_LEA_REVISION + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Convert MSP430 address to internal LEA address mapping. +// +//****************************************************************************** +#define MSP_LEA_CONVERT_ADDRESS(x) ((uint16_t)(((uintptr_t)(x) >> 2) & 0xffff)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Convert LEA address to MSP430 address mapping. +// +//****************************************************************************** +#define MSP_LEA_REVERT_ADDRESS(x) ((uintptr_t)(((uint32_t)(x) << 2))) + +// Cast read-only registers to const to avoid compiler warnings. +#define MSP_LEA_BOTTOM (*((const uint16_t *)(&LEAMB))) +#define MSP_LEA_TOP (*((const uint16_t *)(&LEAMT))) + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Check that the address is aligned correctly. +// +//****************************************************************************** +#define MSP_LEA_RANGE(x) (((uintptr_t)(x) >= MSP_LEA_BOTTOM) \ + && ((uintptr_t)(x) < MSP_LEA_TOP)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Check that the address is within the LEA RAM. +// +//****************************************************************************** +#define MSP_LEA_ALIGNED(x,n) (!((uint32_t)(x) & ((n)-1))) + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Check that the address aligment is valid and within the LEA RAM. +// +//****************************************************************************** +#define MSP_LEA_VALID_ADDRESS(x,n) (MSP_LEA_RANGE(x) & MSP_LEA_ALIGNED(x,n)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA constant memory address for 0x0000 coefficients. +// +//****************************************************************************** +#define MSP_LEA_CONST_ZERO 0xA000 + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA constant memory address for 0x7fff coefficients. +// +//****************************************************************************** +#define MSP_LEA_CONST_ONE 0xAC00 + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA constant memory address for 0x8000 coefficients. +// +//****************************************************************************** +#define MSP_LEA_Q15_CONST_NEG_ONE 0xB000 + + //****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA constant memory address for 0x80000000 coefficients. +// +//****************************************************************************** +#define MSP_LEA_IQ31_CONST_NEG_ONE 0xE000 + + //****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA command ID for interleave even even command. +// +//****************************************************************************** +#define LEACMD__INTERLEAVEEVENEVEN (0x0000f000) + + //****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA command ID for interleave even odd command. +// +//****************************************************************************** +#define LEACMD__INTERLEAVEEVENODD (0x0000f001) + + //****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA command ID for interleave odd even command. +// +//****************************************************************************** +#define LEACMD__INTERLEAVEODDEVEN (0x0000f002) + + //****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA command ID for interleave odd odd command. +// +//****************************************************************************** +#define LEACMD__INTERLEAVEODDODD (0x0000f003) + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__ADDMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Offset of output vector. + uint16_t outputOffset; +} MSP_LEA_ADDMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEAMD__ADDLONGMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Offset of output vector. + uint16_t outputOffset; +} MSP_LEA_ADDLONGMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__SUBMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Offset of output vector. + uint16_t outputOffset; +} MSP_LEA_SUBMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__SUBLONGMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Offset of output vector. + uint16_t outputOffset; +} MSP_LEA_SUBLONGMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MPYMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Offset of output vector. + uint16_t outputOffset; +} MSP_LEA_MPYMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MPYLONGMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Offset of output vector. + uint16_t outputOffset; +} MSP_LEA_MPYLONGMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MAC command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MAC_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MACLONGMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MACLONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__POLYNOMIAL command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; + //! Polynomial coefficient vector. + uint16_t coeff; + //! Polynomial coefficient order. + uint16_t order; + //! Scale factor. + int32_t scaleFactor; +} MSP_LEA_POLY_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MAX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; +} MSP_LEA_MAX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MAXLONGMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; + //! Offset of input vector. + uint16_t inputOffset; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MAXLONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MAXUNSIGNED command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; +} MSP_LEA_MAXUNSIGNED_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MAXUNSIGNEDMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; + //! Offset of input vector. + uint16_t inputOffset; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MAXLONGUNSIGNED_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MIN command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; +} MSP_LEA_MIN_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MINLONGMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; + //! Offset of input vector. + uint16_t inputOffset; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MINLONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MINUNSIGNEDMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; + //! Offset of input vector. + uint16_t inputOffset; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MINUNSIGNED_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MINLONGUNSIGNED command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Output data vector. + uint16_t output; + //! Offset of input vector. + uint16_t inputOffset; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MINLONGUNSIGNED_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MPYCOMPLEXMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Offset of output vector. + uint16_t outputOffset; +} MSP_LEA_MPYCOMPLEXMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MACCOMPLEXMATRIX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Input data vector 2. + uint16_t input2; + //! Output data vector. + uint16_t output; + //! Offset of input vector 1. + uint16_t input1Offset; + //! Offset of input vector 2. + uint16_t input2Offset; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_MACCOMPLEXMATRIX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__MPYMATRIXROW command. +// +//****************************************************************************** +typedef struct { + //! Input row size. + uint16_t rowSize; + //! Input column size. + uint16_t colSize; + //! Input column vector. + uint16_t colVector; + //! Output data vector. + uint16_t output; +} MSP_LEA_MPYMATRIXROW_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FIR command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! FIR coefficient vector. + uint16_t coeffs; + //! Output data vector. + uint16_t output; + //! Length of FIR coefficient vector. + uint16_t tapLength; + //! Input buffer increment mask. + uint16_t bufferMask; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_FIR_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FIRLONG command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! FIR coefficient vector. + uint16_t coeffs; + //! Output data vector. + uint16_t output; + //! Length of FIR coefficient vector. + uint16_t tapLength; + //! Input buffer increment mask. + uint16_t bufferMask; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_FIRLONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FIRCOMPLEX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! FIR coefficient vector. + uint16_t coeffs; + //! Output data vector. + uint16_t output; + //! Length of FIR coefficient vector. + uint16_t tapLength; + //! Input buffer increment mask. + uint16_t bufferMask; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_FIRCOMPLEX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FIRLONGCOMPLEX command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! FIR coefficient vector. + uint16_t coeffs; + //! Output data vector. + uint16_t output; + //! Length of FIR coefficient vector. + uint16_t tapLength; + //! Input buffer increment mask. + uint16_t bufferMask; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_FIRLONGCOMPLEX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__IIRBQ1 command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector divided by two. + uint16_t vectorSizeBy2; + //! Output data vector. + uint16_t output; + //! Biquad state structure. + uint16_t state; + //! Biquad coefficient structure. + uint16_t coeffs; + //! Input increment direction. + uint16_t direction; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_IIRBQ1_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__IIRBQ2 and LEACMD__IIRBQ2EXTENDED +//! commands. +// +//****************************************************************************** +typedef struct { + //! Length of data vector divided by two. + uint16_t vectorSizeBy2; + //! Output data vector. + uint16_t output; + //! Biquad state structure. + uint16_t state; + //! Biquad coefficient structure. + uint16_t coeffs; +} MSP_LEA_IIRBQ2_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__BITREVERSECOMPLEXEVEN or +//! LEACMD__BITREVERSECOMPLEXODD commands. +// +//****************************************************************************** +typedef struct { + //! Square root of data vector length. + uint16_t sqrtVectorSize; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_BITREVERSECOMPLEX_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__BITREVERSECOMPLEXLONGEVEN or +//! LEACMD__BITREVERSECOMPLEXLONGODD commands. +// +//****************************************************************************** +typedef struct { + //! Square root of data vector length. + uint16_t sqrtVectorSize; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FFTCOMPLEXAUTOSCALING command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector divided by two, must be a power of two. + uint16_t vectorSizeBy2; + //! Log base 2 of 2*vectorSizeBy2 parameter. + uint16_t log2Size; +} MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FFTCOMPLEXFIXEDSCALING command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector divided by two, must be a power of two. + uint16_t vectorSizeBy2; + //! Log base 2 of 2*vectorSizeBy2 parameter. + uint16_t log2Size; +} MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FFTCOMPLEXLONG command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a power of two. + uint16_t vectorSize; + //! Log base 2 of vectorSize parameter. + uint16_t log2Size; +} MSP_LEA_FFTCOMPLEXLONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FFT command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a power of two. + uint16_t vectorSize; + //! Log base 2 of vectorSize parameter. + uint16_t log2Size; +} MSP_LEA_FFT_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__FFTLONG command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector,must be a power of two. + uint16_t vectorSize; + //! Log base 2 of vectorSize parameter. + uint16_t log2Size; +} MSP_LEA_FFTLONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__INTERLEAVEEVENEVEN, +//! LEACMD__INTERLEAVEEVENODD, LEACMD__INTERLEAVEODDEVEN and +//! LEACMD__INTERLEAVEODDODD commands. +// +//****************************************************************************** +typedef struct { + //! Output data vector. + uint16_t output; + //! Channel to insert vector into. + uint16_t channel; + //! Number of destination channels. + uint16_t numChannels; + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; +} MSP_LEA_INTERLEAVE_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__DEINTERLEAVEEVENEVEN, +//! LEACMD__DEINTERLEAVEEVENODD, LEACMD__DEINTERLEAVEODDEVEN and +//! LEACMD__DEINTERLEAVEODDODD commands. +// +//****************************************************************************** +typedef struct { + //! Length of data vector, must be a multiple of two. + uint16_t vectorSize; + //! Depth of interleave operation. + uint16_t interleaveDepth; + //! Output data vector. + uint16_t output; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_DEINTERLEAVE_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Parameter structure for LEACMD__DEINTERLEAVELONG command. +// +//****************************************************************************** +typedef struct { + //! Length of data vector. + uint16_t vectorSize; + //! Depth of interleave operation. + uint16_t interleaveDepth; + //! Output data vector. + uint16_t output; + //! Reserved padding. + uint16_t reserved; +} MSP_LEA_DEINTERLEAVELONG_PARAMS; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MIN command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MIN[23]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MINUNSIGNED command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MINUNSIGNED[23]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MINLONGMATRIX command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MINLONGMATRIX[20]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MINUNSIGNEDLONGMATRIX command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MINUNSIGNEDLONGMATRIX[20]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MAX command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MAX[23]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MAXUNSIGNED command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MAXUNSIGNED[23]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MAXLONGMATRIX command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MAXLONGMATRIX[20]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MAXUNSIGNEDLONGMATRIX command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MAXUNSIGNEDLONGMATRIX[20]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MACLONGMATRIX command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MACLONGMATRIX[18]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEACMD__FFTCOMPLEXAUTOSCALING command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_FFTCOMPLEXAUTOSCALING[58]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__FFTCOMPLEXLONG command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_FFTCOMPLEXLONG[64]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__MPYLONGMATRIX command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_MPYLONGMATRIX[17]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__IIRBQ1 command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_IIRBQ1[31]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__IIRBQ2 command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_IIRBQ2[32]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__IIRBQ2EXTENDED command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_IIRBQ2EXTENDED[47]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__FIRLONG command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_FIRLONG[30]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA patch for the LEA__FIRCOMPLEXLONG command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_FIRCOMPLEXLONG[43]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA function for the LEACMD__INTERLEAVEEVENEVEN command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_INTERLEAVEEVENEVEN[22]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA function for the LEACMD__INTERLEAVEEVENODD command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_INTERLEAVEEVENODD[24]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA function for the LEACMD__INTERLEAVEODDEVEN command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_INTERLEAVEODDEVEN[22]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief LEA function for the LEACMD__INTERLEAVEODDODD command. +// +//****************************************************************************** +extern const uint32_t MSP_LEA_INTERLEAVEODDODD[24]; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief DSPLib interrupt flags. +// +//****************************************************************************** +extern volatile uint16_t msp_lea_ifg; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief DSPLib LEA-SC locked flag. +// +//****************************************************************************** +extern volatile uint16_t msp_lea_locked; + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief DSPLib initialization routine for LEA. +//! +//! \return none +// +//****************************************************************************** +extern void msp_lea_init(void); + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Invoke a command with interrupts enabled and enter low-power mode or +//! poll the interrupt flag. +//! +//! \return none +// +//****************************************************************************** +static inline void msp_lea_invokeCommand(uint16_t cmdId) +{ + /* Save interrupt state and disable interrupts. */ + uint16_t interruptState = __get_interrupt_state(); + __disable_interrupt(); + + /* Clear interrupt flag and invoke the command. */ + msp_lea_ifg = 0; + LEAPMCB = cmdId | LEAITFLG1; + +#if defined(MSP_DISABLE_LPM0) +#warning "DSPLib: LPM0 is disabled, undefine MSP_DISABLE_LPM0 to enable LPM0." + /* Do not enter LPM0, poll interrupt flags for command completion. */ + __bis_SR_register(GIE); + while(!msp_lea_ifg); +#elif ((MSP_LEA_REVISION==MSP_LEA_REVISION_A) && !defined(MSP_ENABLE_LPM0)) + /* Do not enter LPM0, poll interrupt flags for command completion. */ + __bis_SR_register(GIE); + while(!msp_lea_ifg); +#else + /* Enter LPM0 and wait for command complete interrupt to wake the device. */ + __bis_SR_register(GIE+LPM0_bits); +#endif + + /* Restore original interrupt state. */ + __set_interrupt_state(interruptState); +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Allocate LEA-SC memory from stack. +//! +//! \param length Length of memory to allocate in 32-bit words. +//! +//! \return Pointer to allocated memory. +// +//****************************************************************************** +static inline void *msp_lea_allocMemory(uint16_t length) +{ + LEACNF2 -= length; + return (void *)MSP_LEA_REVERT_ADDRESS(LEACNF2); +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Free LEA-SC memory from stack. +//! +//! \param length Length of memory to allocate in 32-bit words. +//! +//! \return none +// +//****************************************************************************** +static inline void msp_lea_freeMemory(uint16_t length) +{ + LEACNF2 += length; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Acquire LEA-SC module if available. +//! +//! \return Status of the operation, true means lock was acquired. +// +//****************************************************************************** +static inline bool msp_lea_acquireLock(void) +{ +#ifndef MSP_DISABLE_DIAGNOSTICS + bool status; + + /* Save interrupt state and disable interrupts. */ + uint16_t interruptState = __get_interrupt_state(); + __disable_interrupt(); + + /* Check LEA-SC busy flag and DSPLib lock flags. */ + if ((LEACNF1 & LEABUSY) || msp_lea_locked) { + status = false; + } + else { + status = true; + msp_lea_locked = true; + } + + /* Restore interrupt state and return status. */ + __set_interrupt_state(interruptState); + return status; +#endif //MSP_DISABLE_DIAGNOSTICS +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Free LEA-SC module. +//! +//! \return none +// +//****************************************************************************** +static inline void msp_lea_freeLock(void) +{ +#ifndef MSP_DISABLE_DIAGNOSTICS + msp_lea_locked = false; +#endif //MSP_DISABLE_DIAGNOSTICS +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Initialize the table used for loading commands. +//! +//! \return none +// +//****************************************************************************** +extern void msp_lea_initCommandTable(void); + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Return the revision of LEA code ROM. +//! +//! \return LEA revision. +// +//****************************************************************************** +extern uint16_t msp_lea_getRevision(void); + +//****************************************************************************** +// +//! \ingroup dsplib_support_lea +//! +//! \brief Load a LEA command into code memory. +//! +//! \return LEA command ID for loaded command. +// +//****************************************************************************** +extern uint16_t msp_lea_loadCommand( + uint16_t commandId, const void *command, uint16_t length); + +#endif + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif // __DSPLIB_LEA_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_matrix.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_matrix.h new file mode 100755 index 000000000..598e696ce --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_matrix.h @@ -0,0 +1,867 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_MATRIX_H__ +#define __DSPLIB_MATRIX_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_matrix_api Matrix +//! @{ +//! +//! Functions for performing matrix operations on real data. +//! +//! \defgroup dsplib_matrix_real Real Matrix +//! Functions for performing matrix operations on real data. +//! +//! @} +// +//****************************************************************************** + +//****************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//****************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the matrix add function. +// +//****************************************************************************** +typedef struct msp_matrix_add_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_add_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the matrix add function. +// +//****************************************************************************** +typedef struct msp_matrix_add_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_add_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the matrix subtract function. +// +//****************************************************************************** +typedef struct msp_matrix_sub_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_sub_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the matrix subtract function. +// +//****************************************************************************** +typedef struct msp_matrix_sub_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_sub_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the matrix transpose function. +// +//****************************************************************************** +typedef struct msp_matrix_trans_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_trans_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the matrix transpose function. +// +//****************************************************************************** +typedef struct msp_matrix_trans_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_trans_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix multiply function. +// +//****************************************************************************** +typedef struct msp_matrix_mpy_q15_params { + //! Number of rows in source A matrix, must be a multiple of two. + uint16_t srcARows; + //! Number of columns in source A matrix, must be a multiple of two. + uint16_t srcACols; + //! Number of rows in source B matrix, must be a multiple of two. + uint16_t srcBRows; + //! Number of columns in source B matrix, must be a multiple of two. + uint16_t srcBCols; +} msp_matrix_mpy_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix multiply function. +// +//****************************************************************************** +typedef struct msp_matrix_mpy_iq31_params { + //! Number of rows in source A matrix, must be a multiple of two. + uint16_t srcARows; + //! Number of columns in source A matrix, must be a multiple of two. + uint16_t srcACols; + //! Number of rows in source B matrix, must be a multiple of two. + uint16_t srcBRows; + //! Number of columns in source B matrix, must be a multiple of two. + uint16_t srcBCols; +} msp_matrix_mpy_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix negate function. +// +//****************************************************************************** +typedef struct msp_matrix_neg_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_neg_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix negate function. +// +//****************************************************************************** +typedef struct msp_matrix_neg_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_neg_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix absolute value function. +// +//****************************************************************************** +typedef struct msp_matrix_abs_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_abs_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix absolute value function. +// +//****************************************************************************** +typedef struct msp_matrix_abs_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; +} msp_matrix_abs_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix offset function. +// +//****************************************************************************** +typedef struct msp_matrix_offset_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; + //! Q15 constant to add to the source matrix. + int16_t offset; +} msp_matrix_offset_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix offset function. +// +//****************************************************************************** +typedef struct msp_matrix_offset_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; + //! IQ31 constant to add to the source matrix. + int32_t offset; +} msp_matrix_offset_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix scale function. +// +//****************************************************************************** +typedef struct msp_matrix_scale_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; + //! Integer amount to shift result matrix by, must be positive. + uint8_t shift; + //! Q15 constant multiplied with the source matrix. + _q15 scale; +} msp_matrix_scale_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix scale function. +// +//****************************************************************************** +typedef struct msp_matrix_scale_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; + //! Integer amount to shift result matrix by, must be positive. + uint8_t shift; + //! IQ31 constant multiplied with the source matrix. + _iq31 scale; +} msp_matrix_scale_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix shift function. +// +//****************************************************************************** +typedef struct msp_matrix_shift_q15_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; + //! Integer value to shift each matrix element by. Positive values will + //! shift to the left and negative values will shift to the right. + int8_t shift; +} msp_matrix_shift_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Parameter structure for the real matrix shift function. +// +//****************************************************************************** +typedef struct msp_matrix_shift_iq31_params { + //! Number of rows in the source matrices, must be a multiple of two. + uint16_t rows; + //! Number of columns in the source matrices, must be a multiple of two. + uint16_t cols; + //! Integer value to shift each matrix element by. Positive values will + //! shift to the left and negative values will shift to the right. + int8_t shift; +} msp_matrix_shift_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Addition of two real source matrices. +//! +//! \par Details +//! Element-wise Q15 addition of two real matrices with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA + srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix add parameter structure. +//! \param srcA Pointer to the first source data matrix. +//! \param srcB Pointer to the second source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_add_q15(const msp_matrix_add_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Addition of two real source matrices. +//! +//! \par Details +//! Element-wise IQ31 addition of two real matrices with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA + srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix add parameter structure. +//! \param srcA Pointer to the first source data matrix. +//! \param srcB Pointer to the second source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_add_iq31(const msp_matrix_add_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Subtraction of two real source matrices. +//! +//! \par Details +//! Element-wise Q15 subtraction of two real matrices with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA - srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix subtraction parameter structure. +//! \param srcA Pointer to the first source data matrix. +//! \param srcB Pointer to the second source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_sub_q15(const msp_matrix_sub_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Subtraction of two real source matrices. +//! +//! \par Details +//! Element-wise IQ31 subtraction of two real matrices with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA - srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix subtraction parameter structure. +//! \param srcA Pointer to the first source data matrix. +//! \param srcB Pointer to the second source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_sub_iq31(const msp_matrix_sub_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Multiplication of two real source matrices. +//! +//! \par Details +//! Element-wise Q15 multiplication of two real source matrices without +//! saturation. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = srcA * srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix multiply parameter structure. +//! \param srcA Pointer to the first source data matrix. +//! \param srcB Pointer to the second source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_mpy_q15(const msp_matrix_mpy_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Multiplication of two real source matrices. +//! +//! \par Details +//! Element-wise IQ31 multiplication of two real source matrices without +//! saturation. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = srcA * srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix multiply parameter structure. +//! \param srcA Pointer to the first source data matrix. +//! \param srcB Pointer to the second source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_mpy_iq31(const msp_matrix_mpy_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Transposition of a source matrix. +//! +//! \par Details +//! Transposition of the source matrix. The resulting matrix +//! will have same number of rows as the source does columns and +//! the same number of columns as the source has rows. This function +//! does not support in-place operations. +//! +//! \par Pseudo code +//! `dst = src'` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the matrix transpose parameter structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_trans_q15(const msp_matrix_trans_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Transposition of a source matrix. +//! +//! \par Details +//! Transposition of the source matrix. The resulting matrix +//! will have same number of rows as the source does columns and +//! the same number of columns as the source has rows. This function +//! does not support in-place operations. +//! +//! \par Pseudo code +//! `dst = src'` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the matrix transpose parameter structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_trans_iq31(const msp_matrix_trans_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Negation of a source matrix. +//! +//! \par Details +//! Element-wise Q15 multiplication by negative one with a real source matrix. +//! This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = -src` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix negate parameter structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_neg_q15(const msp_matrix_neg_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Negation of a source matrix. +//! +//! \par Details +//! Element-wise IQ31 multiplication by negative one with a real source matrix. +//! This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = -src` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix negate parameter structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_neg_iq31(const msp_matrix_neg_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Absolute value of a real source matrix. +//! +//! \par Details +//! Element-wise absolute value of a single source matrix. +//! +//! \par Pseudo code +//! `dst = |src|` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the matrix absolute value structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_abs_q15(const msp_matrix_abs_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Absolute value of a real source matrix. +//! +//! \par Details +//! Element-wise absolute value of a single source matrix. +//! +//! \par Pseudo code +//! `dst = |src|` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the matrix absolute value structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_abs_iq31(const msp_matrix_abs_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Constant offset of a real source matrix. +//! +//! \par Details +//! Element-wise Q15 addition with saturation of a single source matrix with a +//! Q15 constant. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src + offset` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix offset structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_offset_q15( + const msp_matrix_offset_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Constant offset of a real source matrix. +//! +//! \par Details +//! Element-wise IQ31 addition with saturation of a single source matrix with a +//! IQ31 constant. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src + offset` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix offset structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_offset_iq31( + const msp_matrix_offset_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Scale a real source matrix. +//! +//! \par Details +//! Element-wise scaling of a real matrix. Source data is multiplied by a IQ31 +//! constant and then shifted left. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT * SCALE` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the matrix scale structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_scale_q15( + const msp_matrix_scale_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Scale a real source matrix. +//! +//! \par Details +//! Element-wise scaling of a real matrix. Source data is multiplied by a IQ31 +//! constant and then shifted left. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT * SCALE` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the matrix scale structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_scale_iq31( + const msp_matrix_scale_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Bitwise shift of a real source matrix. +//! +//! \par Details +//! Element-wise bitwise shift of a real matrix to the left or right by a signed +//! integer value. This function does not saturate and supports in-place +//! operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix shift structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_shift_q15( + const msp_matrix_shift_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_matrix_real +//! +//! \brief Bitwise shift of a real source matrix. +//! +//! \par Details +//! Element-wise bitwise shift of a real matrix to the left or right by a signed +//! integer value. This function does not saturate and supports in-place +//! operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the matrix shift structure. +//! \param src Pointer to the source data matrix. +//! \param dst Pointer to the destination data matrix. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_matrix_shift_iq31( + const msp_matrix_shift_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_MATRIX_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_support.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_support.h new file mode 100755 index 000000000..a6adb7d76 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_support.h @@ -0,0 +1,632 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_SUPPORT_H__ +#define __DSPLIB_SUPPORT_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_support Support +//! @{ +//! +//! Definitions and abstraction for MSP devices. +//! +//! \defgroup dsplib_support_device Common +//! This file provides common definitions, useful conversion macros and +//! abstracted functions to support the core DSPLib functions. While not all +//! macros and functions in this file are useful outside of DSPLib the main +//! application can use any of them as needed. +//! +//! @} +// +//****************************************************************************** + +//****************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//****************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Offset used to store table size. +// +//****************************************************************************** +#define DSPLIB_TABLE_OFFSET 2 + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Increment size for complex data. +// +//****************************************************************************** +#define CMPLX_INCREMENT (2) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Access the real portion of complex data. +// +//****************************************************************************** +#define CMPLX_REAL(ptr) ((ptr)[0]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Access the imaginary portion of complex data. +// +//****************************************************************************** +#define CMPLX_IMAG(ptr) ((ptr)[1]) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Convert number to Q15 fixed point. +// +//****************************************************************************** +#ifndef __QMATHLIB_H__ // Define _Q15 if not defined by QmathLib header. +#define _Q15(A) ((_q15)((((uint32_t)1 << 15) * \ + __saturate(A,-1.0,32767.0/32768.0)))) +#endif //__QMATHLIB_H__ + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Convert number to IQ31 fixed point. +// +//****************************************************************************** +#define _IQ31(A) ((_iq31)((((uint32_t)1 << 31) * \ + __saturate(A,-1.0,2147483647.0/2147483648.0)))) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Convert number to IQ31 fixed point. +// +//****************************************************************************** +#define _Q31(A) (_IQ31(A)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Saturate input to minimum or maximum value and return value. +// +//****************************************************************************** +#define __saturate(x, min, max) (((x)>(max))?(max):(((x)<(min))?(min):(x))) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Add Q15 arguments with saturation. +// +//****************************************************************************** +#if (defined(__TI_COMPILER_VERSION__) && (__TI_COMPILER_VERSION__ >= 15012001)) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 650)) +#define __saturated_add_q15 __saturated_add_signed_short +#else +static inline _q15 __saturated_add_q15(_q15 x, _q15 y) +{ + return (_q15)__saturate((int32_t)x + (int32_t)y, INT16_MIN, INT16_MAX); +} +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Subtract Q15 arguments with saturation. +// +//****************************************************************************** +#if (defined(__TI_COMPILER_VERSION__) && (__TI_COMPILER_VERSION__ >= 15012001)) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 650)) +#define __saturated_sub_q15 __saturated_sub_signed_short +#else +static inline _q15 __saturated_sub_q15(_q15 x, _q15 y) +{ + return (_q15)__saturate((int32_t)x - (int32_t)y, INT16_MIN, INT16_MAX); +} +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Add IQ31 arguments with saturation. +// +//****************************************************************************** +#if (defined(__TI_COMPILER_VERSION__) && (__TI_COMPILER_VERSION__ >= 15012001)) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 650)) +#define __saturated_add_iq31 __saturated_add_signed_long +#else +static inline _iq31 __saturated_add_iq31(_iq31 x, _iq31 y) +{ + return (_iq31)__saturate((int64_t)x + (int64_t)y, INT32_MIN, INT32_MAX); +} +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Subtract IQ31 arguments with saturation. +// +//****************************************************************************** +#if (defined(__TI_COMPILER_VERSION__) && (__TI_COMPILER_VERSION__ >= 15012001)) || \ + (defined(__IAR_SYSTEMS_ICC__) && (__VER__ >= 650)) +#define __saturated_sub_iq31 __saturated_sub_signed_long +#else +static inline _iq31 __saturated_sub_iq31(_iq31 x, _iq31 y) +{ + return (_iq31)__saturate((int64_t)x - (int64_t)y, INT32_MIN, INT32_MAX); +} +#endif + +//****************************************************************************** +// +//! \brief Circular buffer mask of a pointer. +//! +//! \param ptr Pointer to mask +//! \param mask Circular buffer mask +//! \return Pointer after applying circular buffer mask +// +//****************************************************************************** +static inline const void *__circular_mask(const void *ptr, uintptr_t mask) +{ + return (void *)((uintptr_t)ptr & ~mask); +} + +//****************************************************************************** +// +//! \brief Circular buffer increment of a pointer. +//! +//! \param ptr Pointer to increment +//! \param incr Increment size +//! \param mask Circular buffer mask +//! \return Pointer after incrementing and applying circular buffer +//! mask +// +//****************************************************************************** +static inline const void *__circular_increment( const void *ptr, + int16_t incr, + uintptr_t mask) +{ + uintptr_t base = (uintptr_t)__circular_mask(ptr, mask); + uintptr_t addr = base; + addr += (uintptr_t)__circular_mask( + (const void *)((uintptr_t)ptr + (uintptr_t)incr), + ~mask); + return (const void *)addr; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Place data with alignment, when LEA is used data is placed into the +//! shared RAM section. +// +//****************************************************************************** +#if defined(__TI_COMPILER_VERSION__) +#define _PRAGMA(x) _Pragma (#x) +#if defined(MSP_USE_LEA) +#define DSPLIB_DATA(var,align) _PRAGMA(DATA_SECTION(var,".leaRAM"))\ + _PRAGMA(DATA_ALIGN(var,(align))) +#else +#define DSPLIB_DATA(var,align) _PRAGMA(DATA_ALIGN(var,(align))) +#endif +#elif defined(__IAR_SYSTEMS_ICC__) +#define _PRAGMA(x) _Pragma (#x) +#if defined(MSP_USE_LEA) +#define DSPLIB_DATA(var,align) _PRAGMA(location="LEARAM")\ + _PRAGMA(data_alignment=align)\ + _PRAGMA(object_attribute=__no_init) +#else +#define DSPLIB_DATA(var,align) _PRAGMA(data_alignment=align) +#endif +#elif defined(__GNUC__) +#if defined(MSP_USE_LEA) +#define DSPLIB_DATA(var,align) __attribute__((section(".leaRAM")))\ + __attribute__((aligned(align))) +#else +#define DSPLIB_DATA(var,align) __attribute__((aligned(align))) +#endif +#else +#define DSPLIB_DATA(var,align) +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Check status flag and loop forever if not MSP_SUCCESS. +//! +//! \param status Status of the operation. +//! +//! \return None +// +//****************************************************************************** +static inline void msp_checkStatus(msp_status status) +{ +#ifndef MSP_DISABLE_DIAGNOSTICS + switch (status) { + case MSP_SUCCESS: + break; + case MSP_SIZE_ERROR: + /* Invalid size error, loop forever. */ + while(true) __no_operation(); + case MSP_SHIFT_SIZE_ERROR: + /* Invalid shift size error, loop forever. */ + while(true) __no_operation(); + case MSP_TABLE_SIZE_ERROR: + /* Invalid table size error, loop forever. */ + while(true) __no_operation(); + case MSP_LEA_BUSY: + /* LEA is busy and cannot be invoked, loop forever. */ + while(true) __no_operation(); + case MSP_LEA_INVALID_ADDRESS: + /* Address is not within LEA RAM section, loop forever. */ + while(true) __no_operation(); + case MSP_LEA_OUT_OF_RANGE: + /* Command resulted in out of range memory access, loop forever. */ + while(true) __no_operation(); + case MSP_LEA_SCALAR_INCONSISTENCY: + /* LEA scalar data inconsistency error, loop forever. */ + while(true) __no_operation(); + case MSP_LEA_COMMAND_OVERFLOW: + /* LEA command overflow error, loop forever. */ + while(true) __no_operation(); + case MSP_LEA_INCORRECT_REVISION: + /* LEA incorrect revision, loop forever. */ + while(true) __no_operation(); + default: + /* Unknown error, loop forever. */ + while(true) __no_operation(); + } +#endif //MSP_DISABLE_DIAGNOSTICS +} + +// Benchmark register support +#define HWREG16(x) (*((volatile uint16_t *)((uint16_t)x))) +#define BENCHMARK_TAxR (0x0010) +#define BENCHMARK_TAxEX0 (0x0020) + +// Define default benchmark timer base address for examples +#if defined(TA0_BASE) +#define MSP_BENCHMARK_BASE TA0_BASE +#elif defined(TB0_BASE) +#define MSP_BENCHMARK_BASE TB0_BASE +#else +#define MSP_BENCHMARK_BASE TIMER_A0_BASE +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Start benchmark using Timer_A or Timer_B with SMCLK as the clock +//! source. +//! +//! \param baseAddress Base address of timer peripheral to use. +//! \param res Resolution of the benchmark, valid values are: +//! - 1 (16-bit result) +//! - 2 (17-bit result) +//! - 4 (18-bit result) +//! - 8 (19-bit result) +//! - 16 (20-bit result) +//! - 32 (21-bit result) +//! - 64 (22-bit result) +//! +//! \return None +// +//****************************************************************************** +static inline void msp_benchmarkStart(uint16_t baseAddress, uint8_t res) +{ + static const uint8_t TAx_ID[8] = { + 0x00, 0x40, 0x40, 0x80, 0x80, 0x80, 0x80, 0xC0 + }; + HWREG16(baseAddress) = 0x0004; + HWREG16(baseAddress+BENCHMARK_TAxEX0) = res < 7 ? 0 : ((0x07&(res >> 3))-1); + HWREG16(baseAddress) = 0x0220 + TAx_ID[res > 7 ? 7 : ((res-1)&7)]; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Stop timer benchmark and return cycle counts. +//! +//! \param baseAddress Base address of timer peripheral to use. +//! +//! \return Benchmark cycle counts. +// +//****************************************************************************** +static inline uint32_t msp_benchmarkStop(uint16_t baseAddress) +{ + static const uint8_t TAx_IDEX_SCALE[8] = { + 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 + }; + uint16_t cycles = HWREG16(baseAddress+BENCHMARK_TAxR); + uint16_t shift = (HWREG16(baseAddress) & 0x00C0) >> 6; + uint16_t scale = TAx_IDEX_SCALE[HWREG16(baseAddress+BENCHMARK_TAxEX0) & 7]; + HWREG16(baseAddress) = 0; + return (scale*((uint32_t)cycles << shift)); +} + +#if defined(__MSP430_HAS_MPY32__) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Real Q15 multiply with result returned. +//! +//! \param a First Q15 input +//! \param b Second Q15 input +//! +//! \return Q15 result +// +//****************************************************************************** +static inline int16_t __q15mpy(int16_t a, int16_t b) +{ + MPYS = a; + OP2 = b; + return RESHI; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Real Q15 multiply with 32-bit result returned. +//! +//! \param a First Q15 input +//! \param b Second Q15 input +//! +//! \return IQ31 result +// +//****************************************************************************** +static inline int32_t __q15mpyl(int16_t a, int16_t b) +{ + uint32_t result; + MPYS = a; + OP2 = b; + result = RESLO; + result |= ((uint32_t)RESHI << 16); + return (int32_t)result; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Real Q31 multiply with result returned. +//! +//! \param a First Q31 input +//! \param b Second Q31 input +//! +//! \return Q31 result +// +//****************************************************************************** +static inline int32_t __q31mpy(int32_t a, int32_t b) +{ + uint32_t result; + MPYS32L = a & 0xFFFF; + MPYS32H = a >> 16; + OP2L = b & 0xFFFF; + OP2H = b >> 16; + result = RES2; + result |= ((uint32_t)RES3 << 16); + return (int32_t)result; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Complex Q15 multiply with result stored back to a. +//! +//! \param aR First real Q15 input +//! \param aI First imaginary Q15 input +//! \param bR Second real Q15 input +//! \param bI Second imaginary Q15 input +//! +//! \return Q15 result +// +//****************************************************************************** +static inline void __q15cmpy(int16_t *aR, + int16_t *aI, + const int16_t *bR, + const int16_t *bI) +{ + MPYS = *aI; + OP2 = *bR; + MACS = *aR; + OP2 = *bI; + MPYS = -*aI; + *aI = RESHI; + OP2 = *bI; + MACS = *aR; + OP2 = *bR; + *aR = RESHI; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Complex IQ31 by IQ31 multiply with result stored back to a. +//! +//! \param aR First real IQ31 input +//! \param aI First imaginary IQ31 input +//! \param bR Second real IQ31 input +//! \param bI Second imaginary IQ31 input +//! +//! \return IQ31 result +// +//****************************************************************************** +static inline void __q15iq31cmpy(int32_t *aR, + int32_t *aI, + const int32_t *bR, + const int32_t *bI) +{ + MPYS = *aI; + OP2L = (uint16_t)*bR; + OP2H = (uint16_t)(*bR >> 16); + MACS = *aR; + OP2L = (uint16_t)*bI; + OP2H = (uint16_t)(*bI >> 16); + MPYS = -*aI; + *aI = RES1; + *aI |= ((uint32_t)RES2 << 16); + OP2L = (uint16_t)*bI; + OP2H = (uint16_t)(*bI >> 16); + MACS = *aR; + OP2L = (uint16_t)*bR; + OP2H = (uint16_t)(*bR >> 16); + *aR = RES1; + *aR |= ((uint32_t)RES2 << 16); +} + +#else //__MSP430_HAS_MPY32__ + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Real Q15 multiply with result returned. +// +//****************************************************************************** +#define __q15mpy(A, B) ((int16_t)(((int32_t)(A) * (int32_t)(B)) >> 15)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Real Q15 multiply with 32-bit result returned. +// +//****************************************************************************** +#define __q15mpyl(A, B) ((int32_t)(((int32_t)(A) * (int32_t)(B)) << 1)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Real IQ31 multiply with result returned. +// +//****************************************************************************** +#define __q31mpy(A, B) ((int32_t)(((int64_t)(A) * (int64_t)(B)) >> 31)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Real Q15 by IQ31 multiply with result returned +// +//****************************************************************************** +#define __q15iq31mpy(A, B) ((int32_t)(((int64_t)(A) * (int64_t)(B)) >> 15)) + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Complex Q15 multiply with result stored back to a. +//! +//! \param aR First real Q15 input +//! \param aI First imaginary Q15 input +//! \param bR Second real Q15 input +//! \param bI Second imaginary Q15 input +//! +//! \return Q15 result +// +//****************************************************************************** +static inline void __q15cmpy(int16_t *aR, + int16_t *aI, + const int16_t *bR, + const int16_t *bI) +{ + int16_t resR = __q15mpy(*aR, *bR) - __q15mpy(*aI, *bI); + int16_t resI = __q15mpy(*aR, *bI) + __q15mpy(*aI, *bR); + *aR = resR; + *aI = resI; +} + +//****************************************************************************** +// +//! \ingroup dsplib_support_device +//! +//! \brief Complex IQ31 by IQ31 multiply with result stored back to a. +//! +//! \param aR First real IQ31 input +//! \param aI First imaginary IQ31 input +//! \param bR Second real IQ31 input +//! \param bI Second imaginary IQ31 input +//! +//! \return IQ31 result +// +//****************************************************************************** +static inline void __q15iq31cmpy(int32_t *aR, + int32_t *aI, + const int32_t *bR, + const int32_t *bI) +{ + int32_t resR = __q15iq31mpy(*aR, *bR) - __q15iq31mpy(*aI, *bI); + int32_t resI = __q15iq31mpy(*aR, *bI) + __q15iq31mpy(*aI, *bR); + *aR = resR; + *aI = resI; +} + +#endif //__MSP430_HAS_MPY32__ + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_SUPPORT_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_transform.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_transform.h new file mode 100755 index 000000000..fdeca32a4 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_transform.h @@ -0,0 +1,1092 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_TRANSFORM_H__ +#define __DSPLIB_TRANSFORM_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_transform_api Transform +//! @{ +//! +//! Functions for performing Discreet Fourier Transforms (DFT), commonly +//! referred to as Fast Fourier Transforms (FFT), on MSP embedded devices. +//! Functions for both real and complex inputs, 16-bit and 32-bit data types as +//! well as forward and inverse transforms are included. +//! +//! \defgroup dsplib_transform_real Real FFT +//! Functions for performing forward and inverse FFT of real 16-bit and 32-bit +//! input data. +//! +//! \defgroup dsplib_transform_complex Complex FFT +//! Functions for performing forward and inverse FFT of complex 16-bit and +//! 32-bit input data. +//! +//! \defgroup dsplib_transform_tables Tables +//! Constant lookup tables used for real and complex FFT functions. Pointers to +//! these tables must be set in the FFT parameter blocks with the exception of +//! when LEA is used to accelerate the FFT functions. The size of table used +//! depends on the maximum FFT size required by the application. +//! +//! \defgroup dsplib_transform_support Support +//! Support functions used for real and complex FFT functions. These functions +//! do not need to be called outside of DSPLib. +//! +//! @} +// +//****************************************************************************** + +//****************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//****************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Calculate the alignment for a 16-bit real FFT from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_FFT_Q15(n) (n*2) + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Calculate the alignment for a 32-bit real FFT from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_FFT_IQ31(n) (n*4) + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Calculate the alignment for a 16-bit complex FFT from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_CMPLX_FFT_Q15(n) (n*4) + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Calculate the alignment for a 32-bit complex FFT from length +//! parameter. +// +//****************************************************************************** +#define MSP_ALIGN_CMPLX_FFT_IQ31(n) (n*8) + +#if defined(MSP_USE_LEA) + +// Tables located in LEA ROM, define as null pointers +#define msp_cmplx_bitrev_table_ui8 0 +#define msp_cmplx_twiddle_table_16_q15 0 +#define msp_cmplx_twiddle_table_32_q15 0 +#define msp_cmplx_twiddle_table_64_q15 0 +#define msp_cmplx_twiddle_table_128_q15 0 +#define msp_cmplx_twiddle_table_256_q15 0 +#define msp_cmplx_twiddle_table_512_q15 0 +#define msp_cmplx_twiddle_table_1024_q15 0 +#define msp_cmplx_twiddle_table_2048_q15 0 +#define msp_cmplx_twiddle_table_4096_q15 0 + +#else //MSP_USE_LEA + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Bit reversal lookup table. +// +//****************************************************************************** +extern const uint8_t msp_cmplx_bitrev_table_ui8[256]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 16. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_16_q15[DSPLIB_TABLE_OFFSET+16]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 32. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_32_q15[DSPLIB_TABLE_OFFSET+32]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 64. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_64_q15[DSPLIB_TABLE_OFFSET+64]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 128. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_128_q15[DSPLIB_TABLE_OFFSET+128]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 256. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_256_q15[DSPLIB_TABLE_OFFSET+256]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 512. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_512_q15[DSPLIB_TABLE_OFFSET+512]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 1024. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_1024_q15[DSPLIB_TABLE_OFFSET+1024]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 2048. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_2048_q15[DSPLIB_TABLE_OFFSET+2048]; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_tables +//! +//! \brief Twiddle factor table for FFT of size 4096. +// +//****************************************************************************** +extern const _q15 msp_cmplx_twiddle_table_4096_q15[DSPLIB_TABLE_OFFSET+4096]; + +#endif //MSP_USE_LEA + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Parameter structure for Q15 complex bit-reversal. +// +//****************************************************************************** +typedef struct msp_cmplx_bitrev_q15_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; +} msp_cmplx_bitrev_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Parameter structure for IQ31 complex bit-reversal. +// +//****************************************************************************** +typedef struct msp_cmplx_bitrev_iq31_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; +} msp_cmplx_bitrev_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Parameter structure for Q15 split operation. +// +//****************************************************************************** +typedef struct msp_split_q15_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; + //! \details + //! Pointer to the twiddle coefficient table with size greater than or equal + //! to the source length. When using LEA this can be a NULL pointer. + const _q15 *twiddleTable; +} msp_split_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Parameter structure for IQ31 split operation. +// +//****************************************************************************** +typedef struct msp_split_iq31_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; + //! \details + //! Pointer to the twiddle coefficient table with size greater than or equal + //! to the source length. When using LEA this can be a NULL pointer. + const _q15 *twiddleTable; +} msp_split_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Parameter structure for Q15 real FFT functions. +// +//****************************************************************************** +typedef struct msp_fft_q15_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; + //! \details + //! Perform bit-reversal of the input before transformation. This step is + //! mandatory, this parameter only exists for applications that might handle + //! bit reversal when storing the data samples to memory. If not this needs + //! to be set to true. + bool bitReverse; + //! \details + //! Pointer to the twiddle coefficient table with size greater than or equal + //! to the source length. When using LEA this can be a NULL pointer. + const _q15 *twiddleTable; +} msp_fft_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Parameter structure for IQ31 real FFT functions. +// +//****************************************************************************** +typedef struct msp_fft_iq31_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; + //! \details + //! Perform bit-reversal of the input before transformation. This step is + //! mandatory, this parameter only exists for applications that might handle + //! bit reversal when storing the data samples to memory. If not this needs + //! to be set to true. + bool bitReverse; + //! \details + //! Pointer to the twiddle coefficient table with size greater than or equal + //! to the source length. When using LEA this can be a NULL pointer. + const _q15 *twiddleTable; +} msp_fft_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Parameter structure for Q15 complex FFT functions. +// +//****************************************************************************** +typedef struct msp_cmplx_fft_q15_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; + //! \details + //! Perform bit-reversal of the input before transformation. This step is + //! mandatory, this parameter only exists for applications that might handle + //! bit reversal when storing the data samples to memory. If not this needs + //! to be set to true. + bool bitReverse; + //! \details + //! Pointer to the twiddle coefficient table with size greater than or equal + //! to the source length. When using LEA this can be a NULL pointer. + const _q15 *twiddleTable; +} msp_cmplx_fft_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Parameter structure for IQ31 complex FFT functions. +// +//****************************************************************************** +typedef struct msp_cmplx_fft_iq31_params { + //! \details + //! Length of the source data, must be a power of two. + uint16_t length; + //! \details + //! Perform bit-reversal of the input before transformation. This step is + //! mandatory, this parameter only exists for applications that might handle + //! bit reversal when storing the data samples to memory. If not this needs + //! to be set to true. + bool bitReverse; + //! \details + //! Pointer to the twiddle coefficient table with size greater than or equal + //! to the source length. When using LEA this can be a NULL pointer. + const _q15 *twiddleTable; +} msp_cmplx_fft_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Complex bit-reversal function. +//! +//! \par Details +//! Inputs to the real and complex fft functions need to be in bit reversed +//! order before the result can be computed. The DSPLib fft functions contain +//! a parameter to perform the bit reversal and this API does not need to be +//! invoked directly. Alternatively the application can store input in bit +//! reversed order and skip this step although it may be more efficient to +//! store in linear order using pointer increment or DMA copy and performing +//! the bit reversal all at once. +//! +//! \par Pseudo code +//! `y = bitrevorder(x)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex bit-reversal parameter structure. +//! \param src Pointer to the complex data array to perform the bit-reversal on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_bitrev_q15( + const msp_cmplx_bitrev_q15_params *params, + int16_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Complex bit-reversal function. +//! +//! \par Details +//! Inputs to the real and complex fft functions need to be in bit reversed +//! order before the result can be computed. The DSPLib fft functions contain +//! a parameter to perform the bit reversal and this API does not need to be +//! invoked directly. Alternatively the application can store input in bit +//! reversed order and skip this step although it may be more efficient to +//! store in linear order using pointer increment or DMA copy and performing +//! the bit reversal all at once. +//! +//! \par Pseudo code +//! `y = bitrevorder(x)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex bit-reversal parameter structure. +//! \param src Pointer to the complex data array to perform the bit-reversal on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_bitrev_iq31( + const msp_cmplx_bitrev_iq31_params *params, + int32_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Split operation for performing the final step of a real FFT. +//! +//! \par Details +//! Performs the final stage of a discreet Fourier transform (DFT) of real +//! inputs. First a complex FFT of size length/2 with must be performed before +//! this function can be called. The DSPLib real fft functions invoke this +//! function directly and this API does not need to be called directly from the +//! application. +//! +//! \par Pseudo code +//! `G(k) = 0.5*(X(k) + X*(N-k)) - 0.5*j*(e^-j2*pi*k/2N)*(X(k) - X*(N-k))` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to twice the data length (e.g. +//! a 256-point real FFT requires 512-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_Q15 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the split parameter structure. +//! \param src Pointer to the data array to perform the split operation on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_split_q15(const msp_split_q15_params *params, + int16_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_support +//! +//! \brief Split operation for performing the final step of a real FFT. +//! +//! \par Details +//! Performs the final stage of a discreet Fourier transform (DFT) of real +//! inputs. First a complex FFT of size length/2 with must be performed before +//! this function can be called. The DSPLib real fft functions invoke this +//! function directly and this API does not need to be called directly from the +//! application. +//! +//! \par Pseudo code +//! `G(k) = 0.5*(X(k) + X*(N-k)) - 0.5*j*(e^-j2*pi*k/2N)*(X(k) - X*(N-k))` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to four times the data length (e.g. +//! a 256-point real FFT requires 1024-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_IQ31 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the split parameter structure. +//! \param src Pointer to the data array to perform the split operation on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_split_iq31(const msp_split_iq31_params *params, + int32_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Real forward FFT function with auto-scaling. +//! +//! \par Details +//! Computes the forward discreet Fourier transform (DFT) of 16-bit real inputs. +//! If the inputs are not already in bit reversed order the bit reversal +//! parameter must be set. The output is monitored for overflow and scaled by a +//! factor of two when an overflow risk is detected. The shift parameter +//! contains the number of bit shifts that were applied to the output. +//! +//! \par +//! This functions requires half the data storage and consumes roughly half the +//! cycles and energy as running a complex FFT of the same length. When +//! transforming purely real inputs, such as samples from an ADC or analog +//! sensor, it is recommended to use the real FFT functions. +//! +//! \par Pseudo code +//! `y = fft(real(x)) * 2^-shift` +//! +//! \par Scaling +//! Scaling is applied as needed to prevent saturation of the output. The scale +//! factor that was applied to the output is returned in the shift parameter and +//! can be used to calculate the result by applying the following function. +//! +//! \par +//! `result = result * 2^shift` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to twice the data length (e.g. +//! a 256-point real FFT requires 512-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_Q15 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the real FFT parameter structure. +//! \param src Pointer to the real data array to perform the FFT on. +//! \param shift Auto-scaling shift that was applied to the output. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_fft_auto_q15(const msp_fft_q15_params *params, + int16_t *src, + uint16_t *shift); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Real forward FFT function with fixed scaling by two at each stage. +//! +//! \par Details +//! Computes the forward discreet Fourier transform (DFT) of 16-bit real inputs. +//! If the inputs are not already in bit reversed order the bit reversal +//! parameter must be set. The output is scaled by a factor of two for each +//! stage of the DFT. +//! +//! \par +//! This functions requires half the data storage and consumes roughly half the +//! cycles and energy as running a complex FFT of the same length. When +//! transforming purely real inputs, such as samples from an ADC or analog +//! sensor, it is recommended to use the real FFT functions. +//! +//! \par Pseudo code +//! `y = fft(real(x)) ./ (N/2)` +//! +//! \par Scaling +//! Each stage of the real FFT, with the exception of the final split stage, +//! scales the result by a factor of 0.5. The output format can either be +//! interpreted as the same type with (N/2) scaling or a different fixed point +//! data type. This can be helpful when using the IQmathLib to process the +//! results of the FFT, such as computing the magnitude or phase angle of the +//! complex result. +//! +//! \par +//!
+//! | Length | Input Type | Result Type | +//! | -------- |:----------:| :----------:| +//! | **16** | _q15 | _q12 | +//! | **32** | _q15 | _q11 | +//! | **64** | _q15 | _q10 | +//! | **128** | _q15 | _q9 | +//! | **256** | _q15 | _q8 | +//! | **512** | _q15 | _q7 | +//! | **1024** | _q15 | _q6 | +//! | **2048** | _q15 | _q5 | +//! | **4096** | _q15 | _q4 | +//!
+//! +//! \par +//! The following table lists the applied scaling factor and resulting data type +//! when the input is a 16-bit integer. +//! +//! \par +//!
+//! | Length | Input Type | Result Type | +//! | -------- |:----------:| :-----------------------:| +//! | **16** | int16_t | (int16_t)(result / 8) | +//! | **32** | int16_t | (int16_t)(result / 16) | +//! | **64** | int16_t | (int16_t)(result / 32) | +//! | **128** | int16_t | (int16_t)(result / 64) | +//! | **256** | int16_t | (int16_t)(result / 128) | +//! | **512** | int16_t | (int16_t)(result / 256) | +//! | **1024** | int16_t | (int16_t)(result / 512) | +//! | **2048** | int16_t | (int16_t)(result / 1024) | +//! | **4096** | int16_t | (int16_t)(result / 2048) | +//!
+//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to twice the data length (e.g. +//! a 256-point real FFT requires 512-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_Q15 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the real FFT parameter structure. +//! \param src Pointer to the real data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_fft_fixed_q15(const msp_fft_q15_params *params, + int16_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Real forward FFT function without scaling. +//! +//! \par Details +//! Computes the forward discreet Fourier transform (DFT) of 32-bit real inputs. +//! If the inputs are not already in bit reversed order the bit reversal +//! parameter must be set. The output is not scaled. +//! +//! \par +//! This functions requires half the data storage and consumes roughly half the +//! cycles and energy as running a complex FFT of the same length. When +//! transforming purely real inputs, such as samples from an ADC or analog +//! sensor, it is recommended to use the real FFT functions. +//! +//! \par Pseudo code +//! `y = fft(real(x))` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to four times the data length (e.g. +//! a 256-point real FFT requires 1024-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_IQ31 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the real FFT parameter structure. +//! \param src Pointer to the real data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** + +extern msp_status msp_fft_iq31(const msp_fft_iq31_params *params, + int32_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Real result inverse FFT function with auto-scaling. +//! +//! \par Details +//! Computes the inverse discreet Fourier transform (DFT) of 16-bit complex +//! inputs with real result. If the inputs are not already in bit reversed order +//! the bit reversal parameter must be set. Automatic scaling is performed such +//! that this is the direct inverse of the forward FFT with auto scaling. +//! +//! \par +//! This functions uses half the data storage and consumes roughly half the +//! cycles and energy as running a complex IFFT of the same length. When +//! transforming purely real inputs, such as samples from an ADC or analog +//! sensor, it is recommended to use the real FFT functions. +//! +//! \par Pseudo code +//! `y = (real(ifft(x)) * 2^shift) ./ (N/2)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to twice the data length (e.g. +//! a 256-point real FFT requires 512-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_Q15 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the real FFT parameter structure. +//! \param src Pointer to the real data array to perform the FFT on. +//! \param shift Auto-scaling shift that was applied to the forward FFT. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_ifft_auto_q15(const msp_fft_q15_params *params, + int16_t *src, + uint16_t shift); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Real result inverse FFT function with fixed scaling by two at each +//! stage. +//! +//! \par Details +//! Computes the inverse discreet Fourier transform (DFT) of 16-bit complex +//! inputs with real result. If the inputs are not already in bit reversed order +//! the bit reversal parameter must be set. Fixed scaling is performed such +//! that this is the direct inverse of the forward FFT with fixed scaling. +//! +//! \par +//! This functions uses half the data storage and consumes roughly half the +//! cycles and energy as running a complex IFFT of the same length. When +//! transforming purely real inputs, such as samples from an ADC or analog +//! sensor, it is recommended to use the real FFT functions. +//! +//! \par Pseudo code +//! `y = real(ifft(x))` +//! +//! \par Scaling +//! This function is the direct inverse of the forward real FFT with fixed +//! scaling. The following fixed point input types will all result in Q15 +//! results. +//! +//! \par +//!
+//! | Length | Input Type | Result Type | +//! | -------- |:----------:| :----------:| +//! | **16** | _q12 | _q15 | +//! | **32** | _q11 | _q15 | +//! | **64** | _q10 | _q15 | +//! | **128** | _q9 | _q15 | +//! | **256** | _q8 | _q15 | +//! | **512** | _q7 | _q15 | +//! | **1024** | _q6 | _q15 | +//! | **2048** | _q5 | _q15 | +//! | **4096** | _q4 | _q15 | +//!
+//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to twice the data length (e.g. +//! a 256-point real FFT requires 512-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_Q15 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the real FFT parameter structure. +//! \param src Pointer to the real data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_ifft_fixed_q15(const msp_fft_q15_params *params, + int16_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_real +//! +//! \brief Real result inverse FFT function without scaling. +//! +//! \par Details +//! Computes the inverse discreet Fourier transform (DFT) of 32-bit complex +//! inputs with real result. If the inputs are not already in bit reversed order +//! the bit reversal parameter must be set. Fixed scaling is performed such +//! that this is the direct inverse of the forward FFT without scaling. +//! +//! \par +//! This functions uses half the data storage and consumes roughly half the +//! cycles and energy as running a complex IFFT of the same length. When +//! transforming purely real inputs, such as samples from an ADC or analog +//! sensor, it is recommended to use the real FFT functions. +//! +//! \par Pseudo code +//! `y = real(ifft(x)) ./ N` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to four times the data length (e.g. +//! a 256-point real FFT requires 1024-byte alignment). When allocating data the +//! MSP\_ALIGN\_FFT\_IQ31 macro can be used to calculate correct alignment. The +//! twiddle table pointer parameter is not used with LEA and can be null or +//! uninitialized. +//! +//! \param params Pointer to the real FFT parameter structure. +//! \param src Pointer to the real data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_ifft_iq31(const msp_fft_iq31_params *params, + int32_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Complex forward FFT function with auto-scaling. +//! +//! \par Details +//! Computes the forward discreet Fourier transform (DFT) of 16-bit complex +//! inputs. If the inputs are not already in bit reversed order the bit reversal +//! parameter must be set. The output is monitored for overflow and scaled by a +//! factor of two when an overflow risk is detected. The shift parameter contains +//! the number of bit shifts that were applied to the output. +//! +//! \par Pseudo code +//! `y = fft(x) * 2^-shift` +//! +//! \par Scaling +//! Scaling is applied as needed to prevent saturation of the output. The scale +//! factor that was applied to the output is returned in the shift parameter and +//! can be used to calculate the result by applying the following function. +//! +//! \par +//! `result = result * 2^shift` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to four times the data length (e.g. +//! a 256-point complex FFT requires 1024-byte alignment). When allocating data +//! the MSP\_CMPLX\_ALIGN\_FFT\_Q15 macro can be used to calculate correct +//! alignment. The twiddle table pointer parameter is not used with LEA and +//! can be null or uninitialized. +//! +//! \param params Pointer to the complex FFT parameter structure. +//! \param src Pointer to the complex data array to perform the FFT on. +//! \param shift Auto-scaling shift that was applied to the output. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_fft_auto_q15(const msp_cmplx_fft_q15_params *params, + int16_t *src, + uint16_t *shift); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Complex forward FFT function with fixed scaling by two at each stage. +//! +//! \par Details +//! Computes the forward discreet Fourier transform (DFT) of 16-bit complex +//! inputs. If the inputs are not already in bit reversed order the bit +//! reversal parameter must be set. The output is scaled by a factor of two for +//! each stage of the DFT. +//! +//! \par Pseudo code +//! `y = fft(x) ./ N` +//! +//! \par Scaling +//! Each stage of the complex FFT scales the result by a factor of 0.5. The +//! output format can either be interpreted as the same type with (1/N) scaling +//! or a different fixed point data type. This can be helpful when using the +//! IQmathLib to process the results of the FFT, such as computing the magnitude +//! or phase angle of the complex result. +//! +//! \par +//!
+//! | Length | Input Type | Result Type | +//! | -------- |:----------:| :----------:| +//! | **16** | _q15 | _q11 | +//! | **32** | _q15 | _q10 | +//! | **64** | _q15 | _q9 | +//! | **128** | _q15 | _q8 | +//! | **256** | _q15 | _q7 | +//! | **512** | _q15 | _q6 | +//! | **1024** | _q15 | _q5 | +//! | **2048** | _q15 | _q4 | +//! | **4096** | _q15 | _q3 | +//!
+//! +//! \par +//! The following table lists the applied scaling factor and resulting data type +//! when the input is a 16-bit integer. +//! +//! \par +//!
+//! | Length | Input Type | Result Type | +//! | -------- |:----------:| :-----------------------:| +//! | **16** | int16_t | (int16_t)(result / 16) | +//! | **32** | int16_t | (int16_t)(result / 32) | +//! | **64** | int16_t | (int16_t)(result / 64) | +//! | **128** | int16_t | (int16_t)(result / 128) | +//! | **256** | int16_t | (int16_t)(result / 256) | +//! | **512** | int16_t | (int16_t)(result / 512) | +//! | **1024** | int16_t | (int16_t)(result / 1024) | +//! | **2048** | int16_t | (int16_t)(result / 2048) | +//! | **4096** | int16_t | (int16_t)(result / 4096) | +//!
+//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to four times the data length (e.g. +//! a 256-point complex FFT requires 1024-byte alignment). When allocating data +//! the MSP\_CMPLX\_ALIGN\_FFT\_Q15 macro can be used to calculate correct +//! alignment. The twiddle table pointer parameter is not used with LEA and +//! can be null or uninitialized. +//! +//! \param params Pointer to the complex FFT parameter structure. +//! \param src Pointer to the complex data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_fft_fixed_q15( + const msp_cmplx_fft_q15_params *params, + int16_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Complex forward FFT function without scaling. +//! +//! \par Details +//! Computes the forward discreet Fourier transform (DFT) of 32-bit complex +//! inputs. If the inputs are not already in bit reversed order the bit +//! reversal parameter must be set. The output is not scaled. +//! +//! \par Pseudo code +//! `y = fft(x)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to eight times the data length +//! (e.g. a 256-point complex FFT requires 2048-byte alignment). When allocating +//! data the MSP\_CMPLX\_ALIGN\_FFT\_IQ31 macro can be used to calculate correct +//! alignment. The twiddle table pointer parameter is not used with LEA and +//! can be null or uninitialized. +//! +//! \param params Pointer to the complex FFT parameter structure. +//! \param src Pointer to the complex data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_fft_iq31(const msp_cmplx_fft_iq31_params *params, +int32_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Complex inverse FFT function with auto-scaling. +//! +//! \par Details +//! Computes the inverse discreet Fourier transform (DFT) of 16-bit complex +//! inputs. If the inputs are not already in bit reversed order the bit reversal +//! parameter must be set. The output is monitored for overflow and scaled by a +//! factor of two when an overflow risk is detected. Automatic scaling is +//! performed such that this is the direct inverse of the forward FFT with auto +//! scaling. +//! +//! \par Pseudo code +//! `y = (ifft(x) * 2^shift) ./ N` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to four times the data length (e.g. +//! a 256-point complex FFT requires 1024-byte alignment). When allocating data +//! the MSP\_CMPLX\_ALIGN\_FFT\_Q15 macro can be used to calculate correct +//! alignment. The twiddle table pointer parameter is not used with LEA and +//! can be null or uninitialized. +//! +//! \param params Pointer to the complex FFT parameter structure. +//! \param src Pointer to the complex data array to perform the FFT on. +//! \param shift Auto-scaling shift that was applied to the output. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_ifft_auto_q15( + const msp_cmplx_fft_q15_params *params, + int16_t *src, + uint16_t shift); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Complex inverse FFT function with fixed scaling by two at each stage. +//! +//! \par Details +//! Computes the inverse discreet Fourier transform (DFT) of 16-bit complex +//! inputs. If the inputs are not already in bit reversed order the bit reversal +//! parameter must be set. Fixed scaling is performed such that this is the +//! direct inverse of the forward FFT with fixed scaling. +//! +//! \par Pseudo code +//! `y = ifft(x)` +//! +//! \par Scaling +//! This function is the direct inverse of the forward complex FFT with fixed +//! scaling. The following fixed point input types will all result in Q15 +//! results. +//! +//! \par +//!
+//! | Length | Input Type | Result Type | +//! | -------- |:----------:| :----------:| +//! | **16** | _q11 | _q15 | +//! | **32** | _q10 | _q15 | +//! | **64** | _q9 | _q15 | +//! | **128** | _q8 | _q15 | +//! | **256** | _q7 | _q15 | +//! | **512** | _q6 | _q15 | +//! | **1024** | _q5 | _q15 | +//! | **2048** | _q4 | _q15 | +//! | **4096** | _q3 | _q15 | +//!
+//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to four times the data length (e.g. +//! a 256-point complex FFT requires 1024-byte alignment). When allocating data +//! the MSP\_CMPLX\_ALIGN\_FFT\_Q15 macro can be used to calculate correct +//! alignment. The twiddle table pointer parameter is not used with LEA and +//! can be null or uninitialized. +//! +//! \param params Pointer to the complex FFT parameter structure. +//! \param src Pointer to the complex data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_ifft_fixed_q15( + const msp_cmplx_fft_q15_params *params, + int16_t *src); + +//****************************************************************************** +// +//! \ingroup dsplib_transform_complex +//! +//! \brief Complex inverse FFT function without scaling. +//! +//! \par Details +//! Computes the inverse discreet Fourier transform (DFT) of 32-bit complex +//! inputs. If the inputs are not already in bit reversed order the bit reversal +//! parameter must be set. Fixed scaling is performed such that this is the +//! direct inverse of the forward FFT without scaling. +//! +//! \par Pseudo code +//! `y = ifft(x) ./ N` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with alignment equal to eight times the data length +//! (e.g. a 256-point complex FFT requires 2048-byte alignment). When allocating +//! data the MSP\_CMPLX\_ALIGN\_FFT\_IQ31 macro can be used to calculate correct +//! alignment. The twiddle table pointer parameter is not used with LEA and +//! can be null or uninitialized. +//! +//! \param params Pointer to the complex FFT parameter structure. +//! \param src Pointer to the complex data array to perform the FFT on. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_ifft_iq31(const msp_cmplx_fft_iq31_params *params, + int32_t *src); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_TRANSFORM_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_types.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_types.h new file mode 100755 index 000000000..cb6ff519a --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_types.h @@ -0,0 +1,182 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_TYPES_H__ +#define __DSPLIB_TYPES_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_types Types +//! @{ +//! +//! Definitions of types used in DSPLib. +//! +//! @} +// +//****************************************************************************** + +//****************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//****************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Define C std macros not available in C++ (for Energia). +// +//****************************************************************************** +#ifndef INT16_MIN +#define INT16_MIN 0x8000 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Define C std macros not available in C++ (for Energia). +// +//****************************************************************************** +#ifndef INT16_MAX +#define INT16_MAX 0x7fff +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Define C std macros not available in C++ (for Energia). +// +//****************************************************************************** +#ifndef INT32_MIN +#define INT32_MIN 0x80000000 +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Define C std macros not available in C++ (for Energia). +// +//****************************************************************************** +#ifndef INT32_MAX +#define INT32_MAX 0x7fffffff +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Signed fixed point data type with 1 integer bit and 15 fractional +//! bits. +// +//****************************************************************************** +#ifndef __QMATHLIB_H__ // Define _q15 if not defined by QmathLib header. +typedef int16_t _q15; +#endif //__QMATHLIB_H__ + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Unsigned fixed point data type with 0 integer bit and 16 fractional +//! bits. +// +//****************************************************************************** +typedef uint16_t _uq15; + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Signed fixed point data type with 1 integer bit and 31 fractional +//! bits. +// +//****************************************************************************** +typedef int32_t _iq31; + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Unsigned fixed point data type with 0 integer bits and 32 fractional +//! bits. +// +//****************************************************************************** +typedef uint32_t _uq31; + +//****************************************************************************** +// +//! \ingroup dsplib_types +//! +//! \brief Enumerated type to return the status of an operation. +// +//****************************************************************************** +typedef enum { + //! Successful operation. + MSP_SUCCESS = 0, + //! Invalid size, see API for restrictions. + MSP_SIZE_ERROR = 1, + //! Invalid shift size, see API for restrictions. + MSP_SHIFT_SIZE_ERROR = 2, + //! Invalid table size, see API for restrictions. + MSP_TABLE_SIZE_ERROR = 3, + //! LEA is busy and cannot be invoked. + MSP_LEA_BUSY = 4, + //! Address is not within LEA RAM section. + MSP_LEA_INVALID_ADDRESS = 5, + //! Command resulted in out of range memory access. + MSP_LEA_OUT_OF_RANGE = 6, + //! LEA scalar data inconsistency error. + MSP_LEA_SCALAR_INCONSISTENCY = 7, + //! LEA command overflow error. + MSP_LEA_COMMAND_OVERFLOW = 8, + //! LEA incorrect revision. + MSP_LEA_INCORRECT_REVISION = 9 +} msp_status; + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_TYPES_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_utility.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_utility.h new file mode 100755 index 000000000..79f338b34 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_utility.h @@ -0,0 +1,667 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_UTILITY_H__ +#define __DSPLIB_UTILITY_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_utility_api Utility +//! @{ +//! +//! This file provides utility functions for operations such as data copy, +//! array fill and deinterleaving of channel data. +//! +//! @} +// +//****************************************************************************** + +//****************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//****************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for Q15 to IQ31 conversion. +// +//****************************************************************************** +typedef struct msp_q15_to_iq31_params { + //! Length of the source data, must be a multiple of two. + uint16_t length; +} msp_q15_to_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for IQ31 to Q15 conversion. +// +//****************************************************************************** +typedef struct msp_iq31_to_q15_params { + //! Length of the source data, must be a multiple of two. + uint16_t length; +} msp_iq31_to_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for creating Q15 complex vector from real and imaginary +//! vectors. +// +//****************************************************************************** +typedef struct msp_cmplx_q15_params { + //! Length of the source data. + uint16_t length; +} msp_cmplx_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for creating IQ31 complex vector from real and imaginary +//! vectors. +// +//****************************************************************************** +typedef struct msp_cmplx_iq31_params { + //! Length of the source data. + uint16_t length; +} msp_cmplx_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for Q15 vector copy function. +// +//****************************************************************************** +typedef struct msp_copy_q15_params { + //! Length of the source data, must be a multiple of two. + uint16_t length; +} msp_copy_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for IQ31 vector copy function. +// +//****************************************************************************** +typedef struct msp_copy_iq31_params { + //! Length of the source data. + uint16_t length; +} msp_copy_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for Q15 real vector fill +// +//****************************************************************************** +typedef struct msp_fill_q15_params { + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! Scalar constant to fill the destination vector with. + _q15 value; +} msp_fill_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for IQ31 real vector fill +// +//****************************************************************************** +typedef struct msp_fill_iq31_params { + //! Length of the source data. + uint16_t length; + //! Scalar constant to fill the destination vector with. + _iq31 value; +} msp_fill_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for Q15 complex vector fill +// +//****************************************************************************** +typedef struct msp_cmplx_fill_q15_params { + //! Length of the source data, must be a multiple of two. + uint16_t length; + //! Real constant value to fill real indices with. + _q15 realValue; + //! Imaginary constant value to fill imaginary indices with. + _q15 imagValue; +} msp_cmplx_fill_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for IQ31 complex vector fill +// +//****************************************************************************** +typedef struct msp_cmplx_fill_iq31_params { + //! Length of the source data. + uint16_t length; + //! Real constant value to fill real indices with. + _iq31 realValue; + //! Imaginary constant value to fill imaginary indices with. + _iq31 imagValue; +} msp_cmplx_fill_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for Q15 vector interleave +// +//****************************************************************************** +typedef struct msp_interleave_q15_params { + //! Length of each channel, must be a multiple of two. + uint16_t length; + //! Specific zero-indexed channel to insert source into. + uint16_t channel; + //! Number of channels in destination vector. + uint16_t numChannels; +} msp_interleave_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for IQ31 vector interleave +// +//****************************************************************************** +typedef struct msp_interleave_iq31_params { + //! Length of each channel. + uint16_t length; + //! Specific zero-indexed channel to insert source into. + uint16_t channel; + //! Number of channels in destination vector. + uint16_t numChannels; +} msp_interleave_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for Q15 vector deinterleave +// +//****************************************************************************** +typedef struct msp_deinterleave_q15_params { + //! Length of each channel, must be a multiple of two. + uint16_t length; + //! Specific zero-indexed channel to pull from source. + uint16_t channel; + //! Number of channels being separated. + uint16_t numChannels; +} msp_deinterleave_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for IQ31 vector deinterleave +// +//****************************************************************************** +typedef struct msp_deinterleave_iq31_params { + //! Length of each channel. + uint16_t length; + //! Specific zero-indexed channel to pull from source. + uint16_t channel; + //! Number of channels being separated. + uint16_t numChannels; +} msp_deinterleave_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Parameters for Q15 sinusoid generation +// +//****************************************************************************** +typedef struct msp_sinusoid_q15_params { + //! Length of the generated sinusoid, must be a multiple of two. + uint16_t length; + //! Amplitude of the generated sinusoid. + _q15 amplitude; + //! Q15 constant equal to cos(2*pi*frequency/fs) where fs is the sampling + //! frequency and freq is the desired sinusoid frequency. For example a 200 + //! Hz sinusoid with sampling frequency of 8192 would have a cosOmega + //! constant equal to cos(2*pi*200/8192) = _Q15(0.988258) or 0x7E7F in + //! hexadecimal. + _q15 cosOmega; + //! Q15 constant equal to sin(2*pi*frequency/fs) where fs is the sampling + //! frequency and freq is the desired sinusoid frequency. For example a 200 + //! Hz sinusoid with sampling frequency of 8192 would have a sinOmega + //! constant equal to sin(2*pi*200/8192) = _Q15(0.152797) or 0x138F in + //! hexadecimal. + _q15 sinOmega; +} msp_sinusoid_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Convert Q15 vector to IQ31 format. +//! +//! \par Details +//! Convert a Q15 data vector to a IQ31 format data vector of the same length. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the parameter structure. +//! \param src Pointer to the Q15 source vector. +//! \param dst Pointer to the IQ31 destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_q15_to_iq31(const msp_q15_to_iq31_params *params, + const _q15 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Convert IQ31 vector to Q15 format. +//! +//! \par Details +//! Convert a IQ31 data vector to a Q15 format data vector of the same length. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the parameter structure. +//! \param src Pointer to the IQ31 source vector. +//! \param dst Pointer to the Q15 destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_iq31_to_q15(const msp_iq31_to_q15_params *params, + const _iq31 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Create Q15 complex vector from real and imaginary vectors. +//! +//! \par Details +//! Create Q15 complex vector from real and imaginary vectorsof the same length. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the parameter structure. +//! \param real Pointer to the Q15 real vector. +//! \param imag Pointer to the Q15 imaginary vector. +//! \param dst Pointer to the Q15 complex destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_q15(const msp_cmplx_q15_params *params, + const _q15 *real, + const _q15 *imag, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Create IQ31 complex vector from real and imaginary vectors. +//! +//! \par Details +//! Create IQ31 complex vector from real and imaginary vectorsof the same +//! length. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the parameter structure. +//! \param real Pointer to the IQ31 real vector. +//! \param imag Pointer to the IQ31 imaginary vector. +//! \param dst Pointer to the IQ31 complex destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_iq31(const msp_cmplx_iq31_params *params, + const _iq31 *real, + const _iq31 *imag, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Real Q15 vector copy. +//! +//! \par Details +//! Copy of real Q15 source vector to destination vector. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector copy parameter structure. +//! \param src Pointer to the source data to copy. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_copy_q15(const msp_copy_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Real IQ31 vector copy. +//! +//! \par Details +//! Copy of real IQ31 source vector to destination vector. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector copy parameter structure. +//! \param src Pointer to the source data to copy. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_copy_iq31(const msp_copy_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Real Q15 vector fill with constant. +//! +//! \par Details +//! Fill of real Q15 destination vector with constant. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector copy parameter structure. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_fill_q15(const msp_fill_q15_params *params, _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Real IQ31 vector fill with constant. +//! +//! \par Details +//! Fill of real IQ31 destination vector with constant. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector copy parameter structure. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_fill_iq31(const msp_fill_iq31_params *params, _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Complex Q15 vector fill with constant. +//! +//! \par Details +//! Fill of complex Q15 destination vector with constant real and imaginary +//! components. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex fill parameter structure. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_fill_q15(const msp_cmplx_fill_q15_params *params, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Complex IQ31 vector fill with constant. +//! +//! \par Details +//! Fill of complex IQ31 destination vector with constant real and imaginary +//! components. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex fill parameter structure. +//! \param dst Pointer to the destination vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_fill_iq31(const msp_cmplx_fill_iq31_params *params, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Insert a single channel into a multiple-channel destination. +//! +//! \par Details +//! A single Q15 vector is inserted into multiple interleaved vectors. For +//! example, a interleave operation to insert a source vector x[] into channel +//! one of a four channel destination vector y[] will yield the following data +//! result: +//! +//! y[0], x[0], y[2], y[3], y[4], x[1], y[6], y[7] ... +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the interleave parameter structure. +//! \param src Pointer to the source data to interleave. +//! \param dst Pointer to the destination data to interleave into. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_interleave_q15(const msp_interleave_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Insert a single channel into a multiple-channel destination. +//! +//! \par Details +//! A single IQ31 vector is inserted into multiple interleaved vectors. For +//! example, a interleave operation to insert a source vector x[] into channel +//! one of a four channel destination vector y[] will yield the following data +//! result: +//! +//! y[0], x[0], y[2], y[3], y[4], x[1], y[6], y[7] ... +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the interleave parameter structure. +//! \param src Pointer to the source data to interleave. +//! \param dst Pointer to the destination data to interleave into. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_interleave_iq31(const msp_interleave_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Extract a single channel from multiple-channel source. +//! +//! \par Details +//! A single Q15 vector is extracted from multiple interleaved vectors. For +//! example, a deinterleave operation to extract channel one from a four channel +//! source vector x[] with channel length 4 will extract the following data: +//! +//! x[1], x[5], x[9], x[13] +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the deinterleave parameter structure. +//! \param src Pointer to the source data to deinterleave. +//! \param dst Pointer to the destination data to store results. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_deinterleave_q15( + const msp_deinterleave_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Extract a single channel from multiple-channel source. +//! +//! \par Details +//! A single IQ31 vector is extracted from multiple interleaved vectors. For +//! example, a deinterleave operation to extract channel one from a four channel +//! source vector x[] with channel length 4 will extract the following data: +//! +//! x[1], x[5], x[9], x[13] +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the deinterleave parameter structure. +//! \param src Pointer to the source data to deinterleave. +//! \param dst Pointer to the destination data to store results. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_deinterleave_iq31( + const msp_deinterleave_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_utility_api +//! +//! \brief Generate a sinusoid with specified amplitude and frequency. +//! +//! \par Details +//! Generate a sinusoid waveform with configured amplitude and frequency +//! parameters using DF1 biquad functions. +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the sinusoid parameter structure. +//! \param dst Pointer to the destination to store generated sinusoid. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_sinusoid_q15(const msp_sinusoid_q15_params *params, + _q15 *dst); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_UTILITY_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_vector.h b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_vector.h new file mode 100755 index 000000000..124416309 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/include/DSPLib_vector.h @@ -0,0 +1,1852 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ +#ifndef __DSPLIB_VECTOR_H__ +#define __DSPLIB_VECTOR_H__ + +//****************************************************************************** +// +//! \addtogroup dsplib_vector_api Vector +//! @{ +//! +//! Functions for performing real and complex vector operations. +//! +//! \defgroup dsplib_vector_real Real Vectors +//! Functions for performing vector operations on real data. +//! +//! \defgroup dsplib_vector_complex Complex Vectors +//! Functions for performing vector operations on complex data. +//! +//! @} +// +//****************************************************************************** + +//****************************************************************************** +// +// If building with a C++ compiler, make all of the definitions in this header +// have a C binding. +// +//****************************************************************************** +#ifdef __cplusplus +extern "C" +{ +#endif + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector add functions. +// +//****************************************************************************** +typedef struct msp_add_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_add_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector add functions. +// +//****************************************************************************** +typedef struct msp_add_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_add_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector subtract functions. +// +//****************************************************************************** +typedef struct msp_sub_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_sub_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector subtract functions. +// +//****************************************************************************** +typedef struct msp_sub_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_sub_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector multiply functions. +// +//****************************************************************************** +typedef struct msp_mpy_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_mpy_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector multiply functions. +// +//****************************************************************************** +typedef struct msp_mpy_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_mpy_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector multiply and accumulate function. +// +//****************************************************************************** +typedef struct msp_mac_q15_params { + //! Length of source data, must be a multiple of two. + uint16_t length; +} msp_mac_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector multiply and accumulate function. +// +//****************************************************************************** +typedef struct msp_mac_iq31_params { + //! Length of source data, must be a multiple of two. + uint16_t length; +} msp_mac_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector negate function. +// +//****************************************************************************** +typedef struct msp_neg_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_neg_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector negate function. +// +//****************************************************************************** +typedef struct msp_neg_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_neg_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector absolute value function. +// +//****************************************************************************** +typedef struct msp_abs_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_abs_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector absolute value function. +// +//****************************************************************************** +typedef struct msp_abs_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_abs_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector offset function. +// +//****************************************************************************** +typedef struct msp_offset_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Offset to add to each vector element. + _q15 offset; +} msp_offset_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the vector offset function. +// +//****************************************************************************** +typedef struct msp_offset_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Offset to add to each vector element. + _iq31 offset; +} msp_offset_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector scale function. +// +//****************************************************************************** +typedef struct msp_scale_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Q15 fractional value scale to multiply each vector element by. + _q15 scale; + //! Unsigned integer value to shift each vector result left by. + uint8_t shift; +} msp_scale_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector scale function. +// +//****************************************************************************** +typedef struct msp_scale_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! q31 fractional value scale to multiply each vector element by. + _iq31 scale; + //! Unsigned integer value to shift each vector result left by. + uint8_t shift; +} msp_scale_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 vector shift function. +// +//****************************************************************************** +typedef struct msp_shift_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Integer value to shift each vector element by. Positive values will + //! shift to the left and negative values will shift to the right. + int8_t shift; +} msp_shift_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 vector shift function. +// +//****************************************************************************** +typedef struct msp_shift_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Integer value to shift each vector element by. Positive values will + //! shift to the left and negative values will shift to the right. + int8_t shift; +} msp_shift_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 signed vector maximum function. +// +//****************************************************************************** +typedef struct msp_max_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_max_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 signed vector maximum function. +// +//****************************************************************************** +typedef struct msp_max_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_max_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 unsigned vector maximum function. +// +//****************************************************************************** +typedef struct msp_max_uq15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_max_uq15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 unsigned vector maximum function. +// +//****************************************************************************** +typedef struct msp_max_uq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_max_uq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 signed vector minimum function. +// +//****************************************************************************** +typedef struct msp_min_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_min_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 signed vector minimum function. +// +//****************************************************************************** +typedef struct msp_min_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_min_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the Q15 unsigned vector minimum function. +// +//****************************************************************************** +typedef struct msp_min_uq15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_min_uq15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Parameter structure for the IQ31 unsigned vector minimum function. +// +//****************************************************************************** +typedef struct msp_min_uq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_min_uq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector add functions. +// +//****************************************************************************** +typedef struct msp_cmplx_add_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_add_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector add functions. +// +//****************************************************************************** +typedef struct msp_cmplx_add_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_add_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector subtract functions. +// +//****************************************************************************** +typedef struct msp_cmplx_sub_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_sub_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector subtract functions. +// +//****************************************************************************** +typedef struct msp_cmplx_sub_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_sub_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector multiply functions. +// +//****************************************************************************** +typedef struct msp_cmplx_mpy_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_mpy_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector multiply functions. +// +//****************************************************************************** +typedef struct msp_cmplx_mpy_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_mpy_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector multiply by real +//! functions. +// +//****************************************************************************** +typedef struct msp_cmplx_mpy_real_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_mpy_real_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector multiply by real +//! functions. +// +//****************************************************************************** +typedef struct msp_cmplx_mpy_real_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_mpy_real_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector multiply and +//! accumulate function. +// +//****************************************************************************** +typedef struct msp_cmplx_mac_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_mac_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector multiply and +//! accumulate function. +// +//****************************************************************************** +typedef struct msp_cmplx_mac_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_mac_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector conjugate function. +// +//****************************************************************************** +typedef struct msp_cmplx_conj_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_conj_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector conjugate function. +// +//****************************************************************************** +typedef struct msp_cmplx_conj_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; +} msp_cmplx_conj_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector scale by real +//! function. +// +//****************************************************************************** +typedef struct msp_cmplx_scale_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Q15 real fractional scale to multiply each complex vector element by. + _q15 scale; + //! Unsigned integer value to shift each complex vector result left by. + uint8_t shift; +} msp_cmplx_scale_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector scale by real +//! function. +// +//****************************************************************************** +typedef struct msp_cmplx_scale_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! q31 real fractional scale to multiply each complex vector element by. + _iq31 scale; + //! Unsigned integer value to shift each complex vector result left by. + uint8_t shift; +} msp_cmplx_scale_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the Q15 complex vector shift function. +// +//****************************************************************************** +typedef struct msp_cmplx_shift_q15_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Integer value to shift each vector element by. Positive values will + //! shift to the left and negative values will shift to the right. + int8_t shift; + //! Return complex conjugate result. + bool conjugate; +} msp_cmplx_shift_q15_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Parameter structure for the IQ31 complex vector shift function. +// +//****************************************************************************** +typedef struct msp_cmplx_shift_iq31_params { + //! Length of source and destination data, must be a multiple of two. + uint16_t length; + //! Integer value to shift each vector element by. Positive values will + //! shift to the left and negative values will shift to the right. + int8_t shift; + //! Take complex conjugate of the result. + bool conjugate; +} msp_cmplx_shift_iq31_params; + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Addition of two real source vectors. +//! +//! \par Details +//! Element-wise Q15 addition of two real vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA + srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector add parameter structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_add_q15(const msp_add_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Addition of two real source vectors. +//! +//! \par Details +//! Element-wise IQ31 addition of two real vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA + srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector add parameter structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_add_iq31(const msp_add_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Subtraction of two real source vectors. +//! +//! \par Details +//! Element-wise Q15 subtraction of two real vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA - srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector add parameter structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_sub_q15(const msp_sub_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Subtraction of two real source vectors. +//! +//! \par Details +//! Element-wise IQ31 subtraction of two real vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = srcA - srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector add parameter structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_sub_iq31(const msp_sub_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Multiplication of two real source vectors. +//! +//! \par Details +//! Element-wise Q15 multiplication of two real source vectors without +//! saturation. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = srcA .* srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector multiply parameter structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_mpy_q15(const msp_mpy_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Multiplication of two real source vectors. +//! +//! \par Details +//! Element-wise IQ31 multiplication of two real source vectors without +//! saturation. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = srcA .* srcB` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector multiply parameter structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_mpy_iq31(const msp_mpy_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Multiply and accumulate of real source vectors. +//! +//! \par Details +//! Element-wise Q15 multiplication of two real source vectors with accumulated +//! IQ31 result (dot product). +//! +//! \par Pseudo code +//! `result = sum(srcA .* srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector multiply and accumulate parameter +//! structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param result Pointer to the 32-bit result data. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_mac_q15(const msp_mac_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _iq31 *result); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Multiply and accumulate of real source vectors. +//! +//! \par Details +//! Element-wise IQ31 multiplication of two real source vectors with accumulated +//! IQ31 result (dot product). +//! +//! \par Pseudo code +//! `result = sum(srcA .* srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector multiply and accumulate parameter +//! structure. +//! \param srcA Pointer to the first source data vector. +//! \param srcB Pointer to the second source data vector. +//! \param result Pointer to the 32-bit result data. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_mac_iq31(const msp_mac_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *result); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Negation of a source vector. +//! +//! \par Details +//! Element-wise Q15 multiplication by negative one with a real source vector. +//! This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = -1 * src` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector negate parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_neg_q15(const msp_neg_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Negation of a source vector. +//! +//! \par Details +//! Element-wise IQ31 multiplication by negative one with a real source vector. +//! This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = -1 * src` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector negate parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_neg_iq31(const msp_neg_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Absolute value of a real source vector. +//! +//! \par Details +//! Element-wise absolute value of a single source vector. +//! +//! \par Pseudo code +//! `dst = |src|` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the vector absolute value parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_abs_q15(const msp_abs_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Absolute value of a real source vector. +//! +//! \par Details +//! Element-wise absolute value of a single source vector. +//! +//! \par Pseudo code +//! `dst = |src|` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the vector absolute value parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_abs_iq31(const msp_abs_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Constant offset of a real source vector. +//! +//! \par Details +//! Element-wise Q15 addition with saturation of a single source vector with a +//! Q15 constant. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src + offset` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector offset parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_offset_q15(const msp_offset_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Constant offset of a real source vector. +//! +//! \par Details +//! Element-wise IQ31 addition with saturation of a single source vector with a +//! IQ31 constant. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src + offset` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector offset parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_offset_iq31(const msp_offset_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Scale a real source vector. +//! +//! \par Details +//! Element-wise scaling of a real vector. Source data is multiplied by a IQ31 +//! constant and then shifted left. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT * SCALE` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the vector scale structure. The bitwise shift +//! value must be >=0. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_scale_q15(const msp_scale_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Scale a real source vector. +//! +//! \par Details +//! Element-wise scaling of a real vector. Source data is multiplied by a IQ31 +//! constant and then shifted left. This function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT * SCALE` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the vector scale structure. The bitwise shift value +//! must be >=0. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_scale_iq31(const msp_scale_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Bitwise shift of a real source vector. +//! +//! \par Details +//! Element-wise bitwise shift of a real vector to the left or right by a signed +//! integer value. This function does not saturate and supports in-place +//! operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector shift parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_shift_q15(const msp_shift_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Bitwise shift of a real source vector. +//! +//! \par Details +//! Element-wise bitwise shift of a real vector to the left or right by a signed +//! integer value. This function does not saturate and supports in-place +//! operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the vector shift parameter structure. +//! \param src Pointer to the source data vector. +//! \param dst Pointer to the destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_shift_iq31(const msp_shift_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Signed maximum of a source vector. +//! +//! \par Details +//! This function returns the 16-bit signed maximum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MAX(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the signed vector maximum parameter structure. +//! \param src Pointer to the source data vector. +//! \param max Pointer to the maximum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_max_q15(const msp_max_q15_params *params, + const _q15 *src, + _q15 *max, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Signed maximum of a source vector. +//! +//! \par Details +//! This function returns the 32-bit signed maximum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MAX(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the signed vector maximum parameter structure. +//! \param src Pointer to the source data vector. +//! \param max Pointer to the maximum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_max_iq31(const msp_max_iq31_params *params, + const _iq31 *src, + _iq31 *max, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Unsigned maximum of a source vector. +//! +//! \par Details +//! This function returns the 16-bit unsigned maximum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MAX(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the unsigned vector maximum parameter structure. +//! \param src Pointer to the source data vector. +//! \param max Pointer to the maximum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_max_uq15(const msp_max_uq15_params *params, + const _uq15 *src, + _uq15 *max, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Unsigned maximum of a source vector. +//! +//! \par Details +//! This function returns the 32-bit unsigned maximum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MAX(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the unsigned vector maximum parameter structure. +//! \param src Pointer to the source data vector. +//! \param max Pointer to the maximum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_max_uq31(const msp_max_uq31_params *params, + const _uq31 *src, + _uq31 *max, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Signed minimum of a source vector. +//! +//! \par Details +//! This function returns the 16-bit signed minimum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MIN(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the signed vector minimum parameter structure. +//! \param src Pointer to the source data vector. +//! \param min Pointer to the minimum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_min_q15(const msp_min_q15_params *params, + const _q15 *src, + _q15 *min, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Signed minimum of a source vector. +//! +//! \par Details +//! This function returns the 32-bit signed minimum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MIN(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the signed vector minimum parameter structure. +//! \param src Pointer to the source data vector. +//! \param min Pointer to the minimum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_min_iq31(const msp_min_iq31_params *params, + const _iq31 *src, + _iq31 *min, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Unsigned minimum of a source vector. +//! +//! \par Details +//! This function returns the 16-bit unsigned minimum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MIN(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the unsigned vector minimum parameter structure. +//! \param src Pointer to the source data vector. +//! \param min Pointer to the minimum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_min_uq15(const msp_min_uq15_params *params, + const _uq15 *src, + _uq15 *min, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_real +//! +//! \brief Unsigned minimum of a source vector. +//! +//! \par Details +//! This function returns the 32-bit unsigned minimum value and corresponding +//! index of a single source vector. +//! +//! \par Pseudo code +//! `dst = MIN(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the unsigned vector minimum parameter structure. +//! \param src Pointer to the source data vector. +//! \param min Pointer to the minimum result vector of size one. +//! \param index Pointer to the index result vector of size one. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_min_uq31(const msp_min_uq31_params *params, + const _uq31 *src, + _uq31 *min, + uint16_t *index); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Addition of two complex source vectors. +//! +//! \par Details +//! Element-wise Q15 addition of two complex vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = complex(srcA) + complex(srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector add parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_add_q15(const msp_cmplx_add_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Addition of two complex source vectors. +//! +//! \par Details +//! Element-wise IQ31 addition of two complex vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = complex(srcA) + complex(srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector add parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_add_iq31(const msp_cmplx_add_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Subtraction of two complex source vectors. +//! +//! \par Details +//! Element-wise Q15 subtraction of two complex vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = complex(srcA) - complex(srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector subtraction parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_sub_q15(const msp_cmplx_sub_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Subtraction of two complex source vectors. +//! +//! \par Details +//! Element-wise IQ31 subtraction of two complex vectors with saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = complex(srcA) - complex(srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector subtraction parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_sub_iq31(const msp_cmplx_sub_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Multiplication of two complex source vectors. +//! +//! \par Details +//! Element-wise Q15 multiply of two complex vectors without saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = complex(srcA) .* complex(srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector multiply parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_mpy_q15(const msp_cmplx_mpy_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Multiplication of complex source vectors. +//! +//! \par Details +//! Element-wise IQ31 multiply of two complex vectors without saturation. This +//! function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = complex(srcA) .* complex(srcB)` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the complex vector multiply parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_mpy_iq31(const msp_cmplx_mpy_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Multiplication of complex source vector by real source vector. +//! +//! \par Details +//! Element-wise Q15 multiply of a complex vector by real vector without +//! saturation. The length of complex and real vectors should be equal, that is +//! the complex source vector contains twice the allocated bytes for data +//! storage. This function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = real(srcA) .* real(srcB) + imag(srcB)` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the complex vector multiply parameter structure. +//! \param srcCmplx Pointer to the complex source data vector. +//! \param srcReal Pointer to the real source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_mpy_real_q15( + const msp_cmplx_mpy_real_q15_params *params, + const _q15 *srcCmplx, + const _q15 *srcReal, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Multiplication of complex source vector by real source vector. +//! +//! \par Details +//! Element-wise IQ31 multiply of a complex vector by real vector without +//! saturation. The length of complex and real vectors should be equal, that is +//! the complex source vector contains twice the allocated bytes for data +//! storage. This function supports in-place operations. +//! +//! \par Pseudo code +//! `dst = real(srcA) .* real(srcB) + imag(srcB)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector multiply parameter structure. +//! \param srcCmplx Pointer to the complex source data vector. +//! \param srcReal Pointer to the real source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_mpy_real_iq31( + const msp_cmplx_mpy_real_iq31_params *params, + const _iq31 *srcCmplx, + const _iq31 *srcReal, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Multiply and accumulate of complex source vectors. +//! +//! \par Details +//! Element-wise Q15 multiplication of two complex source vectors with +//! accumulated result (dot product). +//! +//! \par Pseudo code +//! `result = sum(complex(srcA) .* complex(srcB))` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector multiply and accumulate +//! parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param result Pointer to the 32-bit result data. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_mac_q15(const msp_cmplx_mac_q15_params *params, + const _q15 *srcA, + const _q15 *srcB, + _iq31 *result); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Multiply and accumulate of complex source vectors. +//! +//! \par Details +//! Element-wise IQ31 multiplication of two complex source vectors with +//! accumulated result (dot product). +//! +//! \par Pseudo code +//! `result = sum(complex(srcA) .* complex(srcB))` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the complex vector multiply and accumulate +//! parameter structure. +//! \param srcA Pointer to the first complex source data vector. +//! \param srcB Pointer to the second complex source data vector. +//! \param result Pointer to the 32-bit result data. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_mac_iq31(const msp_cmplx_mac_iq31_params *params, + const _iq31 *srcA, + const _iq31 *srcB, + _iq31 *result); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Conjugation of a source vector. +//! +//! \par Details +//! Conjugation of each element in a complex vector. This function supports +//! in-place operations. +//! +//! \par Pseudo code +//! `dst = conj(src)` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the complex vector conjugate parameter structure. +//! \param src Pointer to the complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_conj_q15(const msp_cmplx_conj_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Conjugation of a source vector. +//! +//! \par Details +//! Conjugation of each element in a complex vector. This function supports +//! in-place operations. +//! +//! \par Pseudo code +//! `dst = conj(src)` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector conjugate parameter structure. +//! \param src Pointer to the complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_conj_iq31(const msp_cmplx_conj_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Scale a complex source vector. +//! +//! \par Details +//! Element-wise scaling of both imaginary and real values of a complex vector. +//! Source data is multiplied by a IQ31 constant and then shifted left. This +//! function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT * SCALE` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the complex vector scale structure. +//! \param src Pointer to the complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_scale_q15(const msp_cmplx_scale_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Scale a complex source vector. +//! +//! \par Details +//! Element-wise scaling of both imaginary and real values of a complex vector. +//! Source data is multiplied by a IQ31 constant and then shifted left. This +//! function supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT * SCALE` +//! +//! \par LEA Support +//! This function is not currently supported by LEA. +//! +//! \param params Pointer to the complex vector scale structure. +//! \param src Pointer to the complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_scale_iq31(const msp_cmplx_scale_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Bitwise shift of a complex source vector. +//! +//! \par Details +//! Element-wise bitwise shift of both imaginary and real elements of a complex +//! vector to the left or right by a signed integer value. This function does +//! not saturate and supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector shift parameter structure. +//! \param src Pointer to the complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_shift_q15(const msp_cmplx_shift_q15_params *params, + const _q15 *src, + _q15 *dst); + +//****************************************************************************** +// +//! \ingroup dsplib_vector_complex +//! +//! \brief Bitwise shift of a complex source vector. +//! +//! \par Details +//! Element-wise bitwise shift of both imaginary and real elements of a complex +//! vector to the left or right by a signed int. This function does not saturate +//! and supports in-place operation. +//! +//! \par Pseudo code +//! `dst = src * 2^SHIFT` +//! +//! \par LEA Support +//! This function is supported by LEA and requires data to be placed into +//! shared LEA memory with 4-byte alignment. +//! +//! \param params Pointer to the complex vector shift parameter structure. +//! \param src Pointer to the complex source data vector. +//! \param dst Pointer to the complex destination data vector. +//! +//! \return Status of the operation. +// +//****************************************************************************** +extern msp_status msp_cmplx_shift_iq31(const msp_cmplx_shift_iq31_params *params, + const _iq31 *src, + _iq31 *dst); + +//***************************************************************************** +// +// Mark the end of the C bindings section for C++ compilers. +// +//***************************************************************************** +#ifdef __cplusplus +} +#endif + +#endif //__DSPLIB_VECTOR_H__ diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df1_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df1_q15.c new file mode 100755 index 000000000..1b349f89b --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df1_q15.c @@ -0,0 +1,69 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_biquad_cascade_df1_q15(const msp_biquad_cascade_df1_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t i; + uint16_t stages; + const _q15 *srcPtr; + msp_status status; + msp_biquad_df1_q15_params df1Params; + + /* Load the number of stages from the parameters. */ + stages = params->stages; + + /* Set initial source pointer. */ + srcPtr = src; + + /* Run the input through all stages of the cascaded biquad. */ + for (i = 0; i < stages; i++) { + /* Initialize the DF1 biquad parameter structure. */ + df1Params.length = params->length; + df1Params.coeffs = ¶ms->coeffs[i]; + df1Params.states = ¶ms->states[i]; + + /* Invoke the msp_biquad_df1_q15 function and check status flag. */ + status = msp_biquad_df1_q15(&df1Params, srcPtr, dst); + if (status != MSP_SUCCESS) { + /* Something went wrong, return the status of the operation. */ + return status; + } + + /* Set source pointer to destination for next stage. */ + srcPtr = dst; + } + + /* Return the status of the operation. */ + return status; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df2_ext_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df2_ext_q15.c new file mode 100755 index 000000000..401627563 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df2_ext_q15.c @@ -0,0 +1,69 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_biquad_cascade_df2_ext_q15(const msp_biquad_cascade_df2_ext_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t i; + uint16_t stages; + const _q15 *srcPtr; + msp_status status; + msp_biquad_df2_ext_q15_params df2ExtParams; + + /* Load the number of stages from the parameters. */ + stages = params->stages; + + /* Set initial source pointer. */ + srcPtr = src; + + /* Run the input through all stages of the cascaded biquad. */ + for (i = 0; i < stages; i++) { + /* Initialize the DF2 biquad parameter structure. */ + df2ExtParams.length = params->length; + df2ExtParams.coeffs = ¶ms->coeffs[i]; + df2ExtParams.states = ¶ms->states[i]; + + /* Invoke the msp_biquad_df2_ext_q15 function and check status flag. */ + status = msp_biquad_df2_ext_q15(&df2ExtParams, srcPtr, dst); + if (status != MSP_SUCCESS) { + /* Something went wrong, return the status of the operation. */ + return status; + } + + /* Set source pointer to destination for next stage. */ + srcPtr = dst; + } + + /* Return the status of the operation. */ + return status; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df2_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df2_q15.c new file mode 100755 index 000000000..cf464fa51 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_cascade_df2_q15.c @@ -0,0 +1,69 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_biquad_cascade_df2_q15(const msp_biquad_cascade_df2_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t i; + uint16_t stages; + const _q15 *srcPtr; + msp_status status; + msp_biquad_df2_q15_params df2Params; + + /* Load the number of stages from the parameters. */ + stages = params->stages; + + /* Set initial source pointer. */ + srcPtr = src; + + /* Run the input through all stages of the cascaded biquad. */ + for (i = 0; i < stages; i++) { + /* Initialize the DF2 biquad parameter structure. */ + df2Params.length = params->length; + df2Params.coeffs = ¶ms->coeffs[i]; + df2Params.states = ¶ms->states[i]; + + /* Invoke the msp_biquad_df2_q15 function and check status flag. */ + status = msp_biquad_df2_q15(&df2Params, srcPtr, dst); + if (status != MSP_SUCCESS) { + /* Something went wrong, return the status of the operation. */ + return status; + } + + /* Set source pointer to destination for next stage. */ + srcPtr = dst; + } + + /* Return the status of the operation. */ + return status; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df1_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df1_q15.c new file mode 100755 index 000000000..b7569d37a --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df1_q15.c @@ -0,0 +1,207 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_biquad_df1_q15(const msp_biquad_df1_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_IIRBQ1_PARAMS *leaParams; + + /* Initialize local length variable. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4) & + MSP_LEA_VALID_ADDRESS(params->states, 4) & + MSP_LEA_VALID_ADDRESS(params->coeffs, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_IIRBQ1_PARAMS structure. */ + leaParams = (MSP_LEA_IIRBQ1_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_IIRBQ1_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_IIR_PARAMS structure. */ + leaParams->vectorSizeBy2 = length >> 1; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->state = MSP_LEA_CONVERT_ADDRESS(params->states); + leaParams->coeffs = MSP_LEA_CONVERT_ADDRESS(params->coeffs); + leaParams->direction = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__IIRBQ1, MSP_LEA_IIRBQ1, + sizeof(MSP_LEA_IIRBQ1)/sizeof(MSP_LEA_IIRBQ1[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__IIRBQ1 command. */ + cmdId = LEACMD__IIRBQ1; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_IIRBQ1_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_IIRBQ1_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_biquad_df1_q15(const msp_biquad_df1_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t i; + uint16_t length; + int16_t x2, x1, y2, y1; + const msp_biquad_df1_q15_coeffs *coeffs; + + /* Initialize local variables and pointers. */ + length = params->length; + coeffs = params->coeffs; + x2 = params->states->x2; + x1 = params->states->x1; + y2 = params->states->y2; + y1 = params->states->y1; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; + + /* Calculate filtered output using direct form 1. */ + for (i = 0; i < length; i++) { + /* Process and update input states. */ + MPYS = x2; OP2 = coeffs->b2; + MACS = x1; OP2 = coeffs->b1By2; + OP2 = coeffs->b1By2; + x2 = x1; x1 = *src++; + MACS = x1; OP2 = coeffs->b0; + + /* Process and update output states and result. */ + MACS = y2; OP2 = coeffs->a2; + MACS = y1; OP2 = coeffs->a1By2; + OP2 = coeffs->a1By2; + y2 = y1; y1 = RESHI; + *dst++ = y1; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else + int32_t temp; + int32_t result; + + /* Calculate filtered output using direct form 1. */ + for (i = 0; i < length; i++) { + /* Process and update input states. */ + result = __q15mpy(x2, coeffs->b2); + temp = __q15mpy(x1, coeffs->b1By2); + result += temp; result += temp; + x2 = x1; x1 = *src++; + result += __q15mpy(x1, coeffs->b0); + + /* Process and update output states and result. */ + result += __q15mpy(y2, coeffs->a2); + temp = __q15mpy(y1, coeffs->a1By2); + result += temp; result += temp; + result = (_q15)__saturate(result, INT16_MIN, INT16_MAX); + y2 = y1; y1 = result; + *dst++ = y1; + } +#endif + + /* Store the states and return. */ + params->states->x2 = x2; + params->states->x1 = x1; + params->states->y2 = y2; + params->states->y1 = y1; + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df2_ext_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df2_ext_q15.c new file mode 100755 index 000000000..cea68dedb --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df2_ext_q15.c @@ -0,0 +1,226 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_biquad_df2_ext_q15(const msp_biquad_df2_ext_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_IIRBQ2_PARAMS *leaParams; + + /* Initialize local length variable. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4) & + MSP_LEA_VALID_ADDRESS(params->states, 4) & + MSP_LEA_VALID_ADDRESS(params->coeffs, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Initialize min/max states */ + params->states->minEven = 0; + params->states->minOdd = 0; + params->states->maxEven = 0; + params->states->maxOdd = 0; + + /* Allocate MSP_LEA_IIRBQ2_PARAMS structure on LEA stack. */ + leaParams = (MSP_LEA_IIRBQ2_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_IIRBQ2_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_IIRBQ2_PARAMS structure. */ + leaParams->vectorSizeBy2 = length >> 1; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->state = MSP_LEA_CONVERT_ADDRESS(params->states); + leaParams->coeffs = MSP_LEA_CONVERT_ADDRESS(params->coeffs); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__IIRBQ2EXTENDED, MSP_LEA_IIRBQ2EXTENDED, + sizeof(MSP_LEA_IIRBQ2EXTENDED)/sizeof(MSP_LEA_IIRBQ2EXTENDED[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__IIRBQ2EXTENDED command. */ + cmdId = LEACMD__IIRBQ2EXTENDED; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_IIRBQ2_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_IIRBQ2_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_biquad_df2_ext_q15(const msp_biquad_df2_ext_q15_params *params, const _q15 *src, _q15 *dst) +{ + _q15 w0; + _q15 w1; + _q15 w2; + _q15 min; + _q15 max; + uint16_t i; + uint16_t length; + const msp_biquad_df2_ext_q15_coeffs *coeffs; + + /* Initialize local variables and pointers. */ + length = params->length; + coeffs = params->coeffs; + w1 = params->states->q1; + w2 = params->states->q2; + min = INT16_MAX; + max = INT16_MIN; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + + /* Calculate filtered output using direct form 2. */ + for (i = 0; i < length; i++) { + /* Calculate intermediate state. */ + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; + RESLO = (uint32_t)coeffs->bias & 0xFFFF; + RESHI = (uint32_t)coeffs->bias >> 16; + MACS = *src++; OP2 = coeffs->a0; + MACS = w1; OP2 = coeffs->a1By2; + OP2 = coeffs->a1By2; + MACS = w2; OP2 = coeffs->a2; + w0 = RESHI; + + /* Calculate output. */ + MPYS = w0; OP2 = coeffs->b0; + MACS = w1; OP2 = coeffs->b1By2; + OP2 = coeffs->b1By2; + MACS = w2; OP2 = coeffs->b2; + *dst++ = RESHI; + + /* Update states and minimum and maximum values. */ + w2 = w1; + w1 = w0; + if (w0 < min) min = w0; + else if (w0 > max) max = w0; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else + int32_t temp; + int32_t result; + + /* Calculate filtered output using direct form 2. */ + for (i = 0; i < length; i++) { + /* Calculate intermediate state. */ + result = (_q15)(coeffs->bias >> 16); + result += __q15mpy(*src++, coeffs->a0); + temp = __q15mpy(w1, coeffs->a1By2); + result += temp; result += temp; + result += __q15mpy(w2, coeffs->a2); + w0 = (_q15)__saturate(result, INT16_MIN, INT16_MAX); + + /* Calculate output. */ + result = __q15mpy(w0, coeffs->b0); + temp = __q15mpy(w1, coeffs->b1By2); + result += temp; result += temp; + result += __q15mpy(w2, coeffs->b2); + *dst++ = (_q15)__saturate(result, INT16_MIN, INT16_MAX); + + /* Update states and minimum and maximum values. */ + w2 = w1; + w1 = w0; + if (w0 < min) min = w0; + else if (w0 > max) max = w0; + } +#endif + + /* Store the states and return. */ + params->states->q1 = w1; + params->states->q2 = w2; + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df2_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df2_q15.c new file mode 100755 index 000000000..a2d3edfa1 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_biquad_df2_q15.c @@ -0,0 +1,209 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_biquad_df2_q15(const msp_biquad_df2_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_IIRBQ2_PARAMS *leaParams; + + /* Initialize local length variable. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4) & + MSP_LEA_VALID_ADDRESS(params->states, 4) & + MSP_LEA_VALID_ADDRESS(params->coeffs, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_IIRBQ2_PARAMS structure on LEA stack. */ + leaParams = (MSP_LEA_IIRBQ2_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_IIRBQ2_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_IIR_DF2_PARAMS structure. */ + leaParams->vectorSizeBy2 = length >> 1; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->state = MSP_LEA_CONVERT_ADDRESS(params->states); + leaParams->coeffs = MSP_LEA_CONVERT_ADDRESS(params->coeffs); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__IIRBQ2, MSP_LEA_IIRBQ2, + sizeof(MSP_LEA_IIRBQ2)/sizeof(MSP_LEA_IIRBQ2[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__IIRBQ2 command. */ + cmdId = LEACMD__IIRBQ2; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_IIRBQ2_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_IIRBQ2_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_biquad_df2_q15(const msp_biquad_df2_q15_params *params, const _q15 *src, _q15 *dst) +{ + _q15 w0; + _q15 w1; + _q15 w2; + uint16_t i; + uint16_t length; + const msp_biquad_df2_q15_coeffs *coeffs; + + /* Initialize local variables and pointers. */ + length = params->length; + coeffs = params->coeffs; + w1 = params->states->q1; + w2 = params->states->q2; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; + + /* Calculate filtered output using direct form 2. */ + for (i = 0; i < length; i++) { + /* Calculate intermediate state. */ + MPYS = *src++; OP2 = coeffs->a0; + MACS = w1; OP2 = coeffs->a1By2; + OP2 = coeffs->a1By2; + MACS = w2; OP2 = coeffs->a2; + w0 = RESHI; + + /* Calculate output. */ + MPYS = w0; OP2 = coeffs->b0; + MACS = w1; OP2 = coeffs->b1By2; + OP2 = coeffs->b1By2; + MACS = w2; OP2 = coeffs->b2; + *dst++ = RESHI; + + /* Update states. */ + w2 = w1; + w1 = w0; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else + int32_t temp; + int32_t result; + + /* Calculate filtered output using direct form 2. */ + for (i = 0; i < length; i++) { + /* Calculate intermediate state. */ + result = __q15mpy(*src++, coeffs->a0); + temp = __q15mpy(w1, coeffs->a1By2); + result += temp; result += temp; + result += __q15mpy(w2, coeffs->a2); + w0 = (_q15)__saturate(result, INT16_MIN, INT16_MAX); + + /* Calculate output. */ + result = __q15mpy(w0, coeffs->b0); + temp = __q15mpy(w1, coeffs->b1By2); + result += temp; result += temp; + result += __q15mpy(w2, coeffs->b2); + *dst++ = (_q15)__saturate(result, INT16_MIN, INT16_MAX); + + /* Update states. */ + w2 = w1; + w1 = w0; + } +#endif + + /* Store the states and return. */ + params->states->q1 = w1; + params->states->q2 = w2; + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_cmplx_fir_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_cmplx_fir_iq31.c new file mode 100755 index 000000000..c3ade9d1c --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_cmplx_fir_iq31.c @@ -0,0 +1,278 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_fir_iq31(const msp_cmplx_fir_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t cmdId; + uint16_t tapLength; + uint16_t bufferMask; + uint16_t outputLength; + bool enableCircBuf; + msp_status status; + MSP_LEA_FIRLONGCOMPLEX_PARAMS *leaParams; + + /* Save parameters to local variables. */ + tapLength = params->tapLength; + outputLength = params->length; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4) & + MSP_LEA_VALID_ADDRESS(params->coeffs, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Set buffer mask parameter. */ + if (enableCircBuf) { + bufferMask = 4*outputLength - 1; + } + else { + bufferMask = 0xffff; + } + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FIRLONGCOMPLEX_PARAMS structure. */ + leaParams = (MSP_LEA_FIRLONGCOMPLEX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FIRLONGCOMPLEX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FIRLONGCOMPLEX_PARAMS structure. */ + leaParams->vectorSize = outputLength; + leaParams->coeffs = MSP_LEA_CONVERT_ADDRESS(params->coeffs); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->tapLength = tapLength; + leaParams->bufferMask = bufferMask; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__FIRCOMPLEXLONG, MSP_LEA_FIRCOMPLEXLONG, + sizeof(MSP_LEA_FIRCOMPLEXLONG)/sizeof(MSP_LEA_FIRCOMPLEXLONG[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__FIRCOMPLEXLONG command. */ + cmdId = LEACMD__FIRCOMPLEXLONG; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_FIRLONGCOMPLEX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FIRLONGCOMPLEX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + /* SW workaround for OOR interrupt when src is start of LEA memory. */ + if ((uintptr_t)src + (tapLength+outputLength)*(sizeof(int32_t)*2) > LEAMT) { + status = MSP_LEA_OUT_OF_RANGE; + } + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_fir_iq31(const msp_cmplx_fir_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t i; + uint16_t j; + uint16_t tapLength; + uint16_t outputLength; + bool enableCircBuf; + const _iq31 *srcPtr; + const _iq31 *coeffPtr; + int64_t realRes; + int64_t imagRes; + + /* Save parameters to local variables. */ + tapLength = params->tapLength << 1; + outputLength = params->length << 1; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; +#endif + + /* Calculate filtered output using circular buffer. */ + if (enableCircBuf) { + uintptr_t mask; + const _iq31 *srcStartPtr; + const _iq31 *srcEndPtr; + + /* Initialize circular buffer mask and set start pointer. */ + mask = (uintptr_t)(2*outputLength*sizeof(_iq31) - 1); + srcStartPtr = (const _iq31 *)__circular_mask(src, mask); + srcEndPtr = srcStartPtr + 2*outputLength; + + /* Calculate filtered output. */ + for (i = 0; i < outputLength; i += 2) { + /* Reset data pointers and loop counters. */ + uint16_t j2; + coeffPtr = ¶ms->coeffs[tapLength - 2]; + srcPtr = (const _iq31 *)__circular_increment((const void *)src, i*sizeof(_iq31), mask); + j = srcEndPtr - srcPtr; + j = j > tapLength ? tapLength : j; + j2 = tapLength - j; + + /* Reset accumulators. */ + realRes = 0; + imagRes = 0; + + /* Multiply and accumulate inputs and coefficients. */ + while (j) { + /* Accumulate real and complex. */ + realRes += __q31mpy(CMPLX_REAL(srcPtr), CMPLX_REAL(coeffPtr)); + realRes -= __q31mpy(CMPLX_IMAG(srcPtr), CMPLX_IMAG(coeffPtr)); + imagRes += __q31mpy(CMPLX_REAL(srcPtr), CMPLX_IMAG(coeffPtr)); + imagRes += __q31mpy(CMPLX_IMAG(srcPtr), CMPLX_REAL(coeffPtr)); + + /* Update pointers */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Multiply and accumulate inputs and coefficients after circular buffer loop. */ + srcPtr = srcStartPtr; + while (j2) { + /* Accumulate real and complex. */ + realRes += __q31mpy(CMPLX_REAL(srcPtr), CMPLX_REAL(coeffPtr)); + realRes -= __q31mpy(CMPLX_IMAG(srcPtr), CMPLX_IMAG(coeffPtr)); + imagRes += __q31mpy(CMPLX_REAL(srcPtr), CMPLX_IMAG(coeffPtr)); + imagRes += __q31mpy(CMPLX_IMAG(srcPtr), CMPLX_REAL(coeffPtr)); + + /* Update pointers */ + j2 -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Saturate accumulators and store result. */ + *dst++ = (_iq31)__saturate(realRes, INT32_MIN, INT32_MAX); + *dst++ = (_iq31)__saturate(imagRes, INT32_MIN, INT32_MAX); + } + } + /* Calculate filtered output without circular buffer. */ + else { + for (i = 0; i < outputLength; i += 2) { + /* Reset accumulators. */ + realRes = 0; + imagRes = 0; + + /* Reset data pointers. */ + srcPtr = &src[i]; + coeffPtr = ¶ms->coeffs[tapLength - 2]; + + /* Multiply and accumulate inputs and coefficients. */ + j = tapLength; + while (j) { + /* Accumulate real and complex. */ + realRes += __q31mpy(CMPLX_REAL(srcPtr), CMPLX_REAL(coeffPtr)); + realRes -= __q31mpy(CMPLX_IMAG(srcPtr), CMPLX_IMAG(coeffPtr)); + imagRes += __q31mpy(CMPLX_REAL(srcPtr), CMPLX_IMAG(coeffPtr)); + imagRes += __q31mpy(CMPLX_IMAG(srcPtr), CMPLX_REAL(coeffPtr)); + + /* Update pointers */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Saturate accumulators and store result. */ + *dst++ = (_iq31)__saturate(realRes, INT32_MIN, INT32_MAX); + *dst++ = (_iq31)__saturate(imagRes, INT32_MIN, INT32_MAX); + } + } + +#if defined(__MSP430_HAS_MPY32__) + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#endif + +#if defined(__MSP430_HAS_MPY32__) + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#endif + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_cmplx_fir_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_cmplx_fir_q15.c new file mode 100755 index 000000000..b06b6d373 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_cmplx_fir_q15.c @@ -0,0 +1,384 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_fir_q15(const msp_cmplx_fir_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t tapLength; + uint16_t bufferMask; + uint16_t outputLength; + bool enableCircBuf; + msp_status status; + MSP_LEA_FIRCOMPLEX_PARAMS *leaParams; + + /* Save parameters to local variables. */ + tapLength = params->tapLength; + outputLength = params->length; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4) & + MSP_LEA_VALID_ADDRESS(params->coeffs, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Set buffer mask parameter. */ + if (enableCircBuf) { + bufferMask = 2*outputLength - 1; + } + else { + bufferMask = 0xffff; + } + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FIRCOMPLEX_PARAMS structure. */ + leaParams = (MSP_LEA_FIRCOMPLEX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FIRCOMPLEX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FIRCOMPLEX_PARAMS structure. */ + leaParams->vectorSize = outputLength; + leaParams->coeffs = MSP_LEA_CONVERT_ADDRESS(params->coeffs); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->tapLength = tapLength; + leaParams->bufferMask = bufferMask; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__FIRCOMPLEX command. */ + msp_lea_invokeCommand(LEACMD__FIRCOMPLEX); + + /* Free MSP_LEA_FIRCOMPLEX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FIRCOMPLEX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + /* SW workaround for OOR interrupt when src is start of LEA memory. */ + if ((uintptr_t)src + (tapLength+outputLength)*(sizeof(int16_t)*2) > LEAMT) { + status = MSP_LEA_OUT_OF_RANGE; + } + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_fir_q15(const msp_cmplx_fir_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t i; + uint16_t j; + uint16_t tapLength; + uint16_t outputLength; + bool enableCircBuf; + const _q15 *srcPtr; + const _q15 *coeffPtr; + + /* Save parameters to local variables. */ + tapLength = params->tapLength << 1; + outputLength = params->length << 1; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; +#endif //__MSP430_HAS_MPY32__ + + /* Calculate filtered output using circular buffer. */ + if (enableCircBuf) { + uintptr_t mask; + const _q15 *srcStartPtr; + const _q15 *srcEndPtr; + + /* Initialize circular buffer mask and set start pointer. */ + mask = (uintptr_t)(2*outputLength*sizeof(_q15) - 1); + srcStartPtr = (const _q15 *)__circular_mask(src, mask); + srcEndPtr = srcStartPtr + 2*outputLength; + + /* Calculate filtered output. */ + for (i = 0; i < outputLength; i += 2) { + /* Reset data pointers and loop counters. */ + uint16_t j2; + coeffPtr = ¶ms->coeffs[tapLength - 2]; + srcPtr = (const _q15 *)__circular_increment((const void *)src, i*sizeof(_q15), mask); + j = srcEndPtr - srcPtr; + j = j > tapLength ? tapLength : j; + j2 = tapLength - j; + +#if defined(__MSP430_HAS_MPY32__) + /* Reset result registers */ + MPY32CTL0 &= ~MPYC; + RESHI = 0; RESLO = 0; + + /* Multiply and accumulate real output. */ + while (j) { + MACS = CMPLX_REAL(srcPtr); + OP2 = CMPLX_REAL(coeffPtr); + MACS = -CMPLX_IMAG(srcPtr); + OP2 = CMPLX_IMAG(coeffPtr); + + /* Update pointers. */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Multiply and accumulate inputs and coefficients after circular buffer loop. */ + srcPtr = srcStartPtr; + while (j2) { + MACS = CMPLX_REAL(srcPtr); + OP2 = CMPLX_REAL(coeffPtr); + MACS = -CMPLX_IMAG(srcPtr); + OP2 = CMPLX_IMAG(coeffPtr); + + /* Update pointers. */ + j2 -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Store real result. */ + *dst++ = (_q15)RESHI; + + /* Reset data pointers and loop counters. */ + coeffPtr = ¶ms->coeffs[tapLength - 2]; + srcPtr = (const _q15 *)__circular_increment((const void *)src, i*sizeof(_q15), mask); + j = srcEndPtr - srcPtr; + j = j > tapLength ? tapLength : j; + j2 = tapLength - j; + + /* Reset result registers */ + MPY32CTL0 &= ~MPYC; + RESHI = 0; RESLO = 0; + + /* Multiply and accumulate imaginary output. */ + while (j) { + MACS = CMPLX_REAL(srcPtr); + OP2 = CMPLX_IMAG(coeffPtr); + MACS = CMPLX_IMAG(srcPtr); + OP2 = CMPLX_REAL(coeffPtr); + + /* Update pointers. */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Multiply and accumulate inputs and coefficients after circular buffer loop. */ + srcPtr = srcStartPtr; + while (j2) { + MACS = CMPLX_REAL(srcPtr); + OP2 = CMPLX_IMAG(coeffPtr); + MACS = CMPLX_IMAG(srcPtr); + OP2 = CMPLX_REAL(coeffPtr); + + /* Update pointers. */ + j2 -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Store imaginary result. */ + *dst++ = (_q15)RESHI; +#else + int32_t realRes; + int32_t imagRes; + + /* Reset accumulators. */ + realRes = 0; + imagRes = 0; + + /* Multiply and accumulate inputs and coefficients. */ + while (j) { + realRes += ((int32_t)CMPLX_REAL(srcPtr)*(int32_t)CMPLX_REAL(coeffPtr)); + realRes -= ((int32_t)CMPLX_IMAG(srcPtr)*(int32_t)CMPLX_IMAG(coeffPtr)); + imagRes += ((int32_t)CMPLX_REAL(srcPtr)*(int32_t)CMPLX_IMAG(coeffPtr)); + imagRes += ((int32_t)CMPLX_IMAG(srcPtr)*(int32_t)CMPLX_REAL(coeffPtr)); + + /* Update pointers. */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Multiply and accumulate inputs and coefficients after circular buffer loop. */ + srcPtr = srcStartPtr; + while (j2) { + realRes += ((int32_t)CMPLX_REAL(srcPtr)*(int32_t)CMPLX_REAL(coeffPtr)); + realRes -= ((int32_t)CMPLX_IMAG(srcPtr)*(int32_t)CMPLX_IMAG(coeffPtr)); + imagRes += ((int32_t)CMPLX_REAL(srcPtr)*(int32_t)CMPLX_IMAG(coeffPtr)); + imagRes += ((int32_t)CMPLX_IMAG(srcPtr)*(int32_t)CMPLX_REAL(coeffPtr)); + + /* Update pointers. */ + j2 -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Saturate accumulators and store result. */ + *dst++ = (_q15)__saturate((realRes >> 15), INT16_MIN, INT16_MAX); + *dst++ = (_q15)__saturate((imagRes >> 15), INT16_MIN, INT16_MAX); +#endif + } + } + /* Calculate filtered output without circular buffer. */ + else { + for (i = 0; i < outputLength; i += 2) { + /* Reset data pointers and loop counters. */ + srcPtr = &src[i]; + coeffPtr = ¶ms->coeffs[tapLength - 2]; + +#if defined(__MSP430_HAS_MPY32__) + /* Reset result registers */ + MPY32CTL0 &= ~MPYC; + RESHI = 0; RESLO = 0; + + /* Multiply and accumulate real output. */ + j = tapLength; + while (j) { + MACS = CMPLX_REAL(srcPtr); + OP2 = CMPLX_REAL(coeffPtr); + MACS = -CMPLX_IMAG(srcPtr); + OP2 = CMPLX_IMAG(coeffPtr); + + /* Update pointers. */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Store real result. */ + *dst++ = (_q15)RESHI; + + /* Reset data pointers. */ + srcPtr = &src[i]; + coeffPtr = ¶ms->coeffs[tapLength - 2]; + + /* Reset result registers */ + MPY32CTL0 &= ~MPYC; + RESHI = 0; RESLO = 0; + + /* Multiply and accumulate imaginary output. */ + j = tapLength; + while (j) { + MACS = CMPLX_REAL(srcPtr); + OP2 = CMPLX_IMAG(coeffPtr); + MACS = CMPLX_IMAG(srcPtr); + OP2 = CMPLX_REAL(coeffPtr); + + /* Update pointers. */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Store imaginary result. */ + *dst++ = (_q15)RESHI; +#else + int32_t realRes; + int32_t imagRes; + + /* Reset accumulators. */ + realRes = 0; + imagRes = 0; + + /* Multiply and accumulate inputs and coefficients. */ + j = tapLength; + while (j) { + realRes += ((int32_t)CMPLX_REAL(srcPtr)*(int32_t)CMPLX_REAL(coeffPtr)); + realRes -= ((int32_t)CMPLX_IMAG(srcPtr)*(int32_t)CMPLX_IMAG(coeffPtr)); + imagRes += ((int32_t)CMPLX_REAL(srcPtr)*(int32_t)CMPLX_IMAG(coeffPtr)); + imagRes += ((int32_t)CMPLX_IMAG(srcPtr)*(int32_t)CMPLX_REAL(coeffPtr)); + + /* Update pointers. */ + j -= 2; + srcPtr += 2; + coeffPtr-= 2; + } + + /* Saturate accumulators and store result. */ + *dst++ = (_q15)__saturate((realRes >> 15), INT16_MIN, INT16_MAX); + *dst++ = (_q15)__saturate((imagRes >> 15), INT16_MIN, INT16_MAX); +#endif + } + } + +#if defined(__MSP430_HAS_MPY32__) + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#endif + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_fir_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_fir_iq31.c new file mode 100755 index 000000000..f51c59c02 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_fir_iq31.c @@ -0,0 +1,250 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_fir_iq31(const msp_fir_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t cmdId; + uint16_t tapLength; + uint16_t bufferMask; + uint16_t outputLength; + bool enableCircBuf; + msp_status status; + MSP_LEA_FIRLONG_PARAMS *leaParams; + + /* Save parameters to local variables. */ + tapLength = params->tapLength; + outputLength = params->length; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4) & + MSP_LEA_VALID_ADDRESS(params->coeffs, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Set buffer mask parameter. */ + if (enableCircBuf) { + bufferMask = 2*outputLength - 1; + } + else { + bufferMask = 0xffff; + } + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FIRLONG_PARAMS structure. */ + leaParams = (MSP_LEA_FIRLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FIRLONG_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FIRLONG_PARAMS structure. */ + leaParams->vectorSize = outputLength; + leaParams->coeffs = MSP_LEA_CONVERT_ADDRESS(params->coeffs); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->tapLength = tapLength; + leaParams->bufferMask = bufferMask; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__FIRLONG, MSP_LEA_FIRLONG, + sizeof(MSP_LEA_FIRLONG)/sizeof(MSP_LEA_FIRLONG[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__FIRLONG command. */ + cmdId = LEACMD__FIRLONG; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_FIRLONG_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FIRLONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + /* SW workaround for OOR interrupt when src is start of LEA memory. */ + if ((uintptr_t)src + (tapLength+outputLength)*(sizeof(int32_t)) > LEAMT) { + status = MSP_LEA_OUT_OF_RANGE; + } + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_fir_iq31(const msp_fir_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t i; + uint16_t j; + uint16_t tapLength; + uint16_t outputLength; + bool enableCircBuf; + const _iq31 *srcPtr; + const _iq31 *coeffPtr; + int64_t result; + + /* Save parameters to local variables. */ + tapLength = params->tapLength; + outputLength = params->length; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that tap and output length are a multiple of two. */ + if ((tapLength & 1) || (outputLength & 1)) { + return MSP_SIZE_ERROR; + } + + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; +#endif + + /* Calculate filtered output using circular buffer. */ + if (enableCircBuf) { + uintptr_t mask; + const _iq31 *srcStartPtr; + const _iq31 *srcEndPtr; + + /* Initialize circular buffer mask and set start pointer. */ + mask = (uintptr_t)(2*outputLength*sizeof(_iq31) - 1); + srcStartPtr = (const _iq31 *)__circular_mask(src, mask); + srcEndPtr = srcStartPtr + 2*outputLength; + + /* Calculate filtered output. */ + for (i = 0; i < outputLength; i++) { + /* Reset data pointers and loop counters. */ + uint16_t j2; + coeffPtr = ¶ms->coeffs[tapLength-1]; + srcPtr = (const _iq31 *)__circular_increment((const void *)src, i*sizeof(_iq31), mask); + j = srcEndPtr - srcPtr; + j = j > tapLength ? tapLength : j; + j2 = tapLength - j; + + /* Reset accumulator. */ + result = 0; + + /* Multiply and accumulate inputs and coefficients. */ + while (j--) { + result += __q31mpy(*srcPtr++, *coeffPtr--); + result = __saturate(result, INT32_MIN, INT32_MAX); + } + + /* Multiply and accumulate inputs and coefficients after circular buffer loop. */ + srcPtr = srcStartPtr; + while (j2--) { + result += __q31mpy(*srcPtr++, *coeffPtr--); + result = __saturate(result, INT32_MIN, INT32_MAX); + } + + /* Store accumulated result. */ + *dst++ = (_iq31)result; + } + } + /* Calculate filtered output without circular buffer. */ + else { + for (i = 0; i < outputLength; i++) { + /* Reset accumulator. */ + result = 0; + + /* Reset data pointers and loop counters. */ + srcPtr = &src[i]; + coeffPtr = ¶ms->coeffs[tapLength - 1]; + j = tapLength; + + /* Multiply and accumulate inputs and coefficients. */ + while (j--) { + /* Multiply and saturate accumulator. */ + result += __q31mpy(*srcPtr++, *coeffPtr--); + result = __saturate(result, INT32_MIN, INT32_MAX); + } + + /* Store accumulated result. */ + *dst++ = (_iq31)result; + } + } + +#if defined(__MSP430_HAS_MPY32__) + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#endif + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_fir_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_fir_q15.c new file mode 100755 index 000000000..829b8d8b2 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/filter/msp_fir_q15.c @@ -0,0 +1,272 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_fir_q15(const msp_fir_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t tapLength; + uint16_t bufferMask; + uint16_t outputLength; + bool enableCircBuf; + msp_status status; + MSP_LEA_FIR_PARAMS *leaParams; + + /* Save parameters to local variables. */ + tapLength = params->tapLength; + outputLength = params->length; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that tap and output length are a multiple of two. */ + if ((tapLength & 1) || (outputLength & 1)) { + return MSP_SIZE_ERROR; + } + + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4) & + MSP_LEA_VALID_ADDRESS(params->coeffs, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Set buffer mask parameter. */ + if (enableCircBuf) { + bufferMask = outputLength - 1; + } + else { + bufferMask = 0xffff; + } + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FIR_PARAMS structure. */ + leaParams = (MSP_LEA_FIR_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FIR_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FIR_PARAMS structure. */ + leaParams->vectorSize = outputLength; + leaParams->coeffs = MSP_LEA_CONVERT_ADDRESS(params->coeffs); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->tapLength = tapLength; + leaParams->bufferMask = bufferMask; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__FIR command. */ + msp_lea_invokeCommand(LEACMD__FIR); + + /* Free MSP_LEA_FIR_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FIR_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + /* SW workaround for OOR interrupt when src is start of LEA memory. */ + if ((uintptr_t)src + (tapLength+outputLength)*(sizeof(int16_t)) > LEAMT) { + status = MSP_LEA_OUT_OF_RANGE; + } + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_fir_q15(const msp_fir_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t i; + uint16_t j; + uint16_t tapLength; + uint16_t outputLength; + bool enableCircBuf; + const _q15 *srcPtr; + const _q15 *coeffPtr; + + /* Save parameters to local variables. */ + tapLength = params->tapLength; + outputLength = params->length; + enableCircBuf = params->enableCircularBuffer; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that tap and output length are a multiple of two. */ + if ((tapLength & 1) || (outputLength & 1)) { + return MSP_SIZE_ERROR; + } + + /* Check that the length is a power of two if circular buffer is enabled. */ + if (enableCircBuf && (outputLength & (outputLength-1))) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; +#endif //__MSP430_HAS_MPY32__ + + /* Calculate filtered output using circular buffer. */ + if (enableCircBuf) { + uintptr_t mask; + const _q15 *srcStartPtr; + const _q15 *srcEndPtr; + + /* Initialize circular buffer mask and set start pointer. */ + mask = (uintptr_t)(2*outputLength*sizeof(_q15) - 1); + srcStartPtr = (const _q15 *)__circular_mask(src, mask); + srcEndPtr = srcStartPtr + 2*outputLength; + + /* Calculate filtered output. */ + for (i = 0; i < outputLength; i++) { + /* Reset data pointers and loop counters. */ + uint16_t j2; + coeffPtr = ¶ms->coeffs[tapLength-1]; + srcPtr = (const _q15 *)__circular_increment((const void *)src, i*sizeof(_q15), mask); + j = srcEndPtr - srcPtr; + j = j > tapLength ? tapLength : j; + j2 = tapLength - j; + +#if defined(__MSP430_HAS_MPY32__) + /* Reset multiplier context. */ + MPY32CTL0 &= ~MPYC; + RESLO = 0; RESHI = 0; + + /* Multiply and accumulate inputs and coefficients. */ + while (j--) { + MACS = *srcPtr++; + OP2 = *coeffPtr--; + } + + /* Multiply and accumulate inputs and coefficients after circular buffer loop. */ + srcPtr = srcStartPtr; + while (j2--) { + MACS = *srcPtr++; + OP2 = *coeffPtr--; + } + + /* Store accumulated result. */ + *dst++ = RESHI; +#else //__MSP430_HAS_MPY32__ + /* Reset accumulator. */ + _iq31 result = 0; + + /* Multiply and accumulate inputs and coefficients. */ + while (j--) { + result += (_iq31)*srcPtr++ * (_iq31)*coeffPtr--; + } + + /* Multiply and accumulate inputs and coefficients after circular buffer loop. */ + srcPtr = srcStartPtr; + while (j2--) { + result += (_iq31)*srcPtr++ * (_iq31)*coeffPtr--; + } + + /* Saturate accumulator and store result. */ + *dst++ = __saturate(result >> 15, INT16_MIN, INT16_MAX); +#endif //__MSP430_HAS_MPY32__ + } + } + /* Calculate filtered output without circular buffer. */ + else { + for (i = 0; i < outputLength; i++) { + /* Reset data pointers and loop counters. */ + srcPtr = &src[i]; + coeffPtr = ¶ms->coeffs[tapLength-1]; + j = tapLength; + +#if defined(__MSP430_HAS_MPY32__) + /* Reset multiplier context. */ + MPY32CTL0 &= ~MPYC; + RESLO = 0; RESHI = 0; + + /* Multiply and accumulate inputs and coefficients. */ + while (j--) { + MACS = *srcPtr++; + OP2 = *coeffPtr--; + } + + /* Store accumulated result. */ + *dst++ = RESHI; +#else //__MSP430_HAS_MPY32__ + /* Reset accumulator. */ + _iq31 result = 0; + + /* Multiply and accumulate inputs and coefficients. */ + while (j--) { + result += (_iq31)*srcPtr++ * (_iq31)*coeffPtr--; + } + + /* Saturate accumulator and store result. */ + *dst++ = __saturate(result >> 15, INT16_MIN, INT16_MAX); +#endif //__MSP430_HAS_MPY32__ + } + } + +#if defined(_MSP430_HAS_MPY32_) + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#endif + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_flags.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_flags.c new file mode 100755 index 000000000..25abd472e --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_flags.c @@ -0,0 +1,41 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +volatile uint16_t msp_lea_locked; + +volatile uint16_t msp_lea_ifg; + +#endif diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_init.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_init.c new file mode 100755 index 000000000..d0bbbdb1e --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_init.c @@ -0,0 +1,69 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +#if defined(MSP_DISABLE_LPM0) +#warning "DSPLib: LPM0 is disabled, undefine MSP_DISABLE_LPM0 to enable LPM0. +#elif ((MSP_LEA_REVISION==MSP_LEA_REVISION_A) && !defined(MSP_ENABLE_LPM0)) +#warning "DSPLib: Building for revision A of LEA, LPM0 is disabled to work \ +around LEA1 errata. See the LEA chapter of API User's Guide and device errata \ +sheet for more details." +#endif + +void msp_lea_init(void) +{ + /* Initialize DSPLib flags. */ + msp_lea_ifg = 0; + msp_lea_locked = 0; + + /* Initialize LEA registers. */ + LEACNF0 = LEALPR | LEAILPM; + LEACNF1 = 0; + LEACNF2 = LEAMT >> 2; + LEAPMS1 = 0; + LEAPMS0 = 0; + LEAPMDST = 0; + LEAPMCTL |= LEACMDEN; + LEAIE |= LEAPMCMDIE; + LEACMCTL = 0; + +#if (MSP_LEA_REVISION == MSP_LEA_REVISION_A) + msp_lea_initCommandTable(); +#endif + + return; +} + +#endif diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_isr.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_isr.c new file mode 100755 index 000000000..b30b0ff9c --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_isr.c @@ -0,0 +1,52 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +#if __GXX_ABI_VERSION == 1011 || __GXX_ABI_VERSION == 1013 +__interrupt void tpl_direct_irq_handler_LEA_VECTOR(void) +#elif __GXX_ABI_VERSION == 1002 +void __attribute__ ((interrupt(LEA_VECTOR))) tpl_direct_irq_handler_LEA_VECTOR(void) +#else + #error "Unsupported ABI" +#endif +{ + /* Save the interrupt flags, clear interrupt and exit LPM0. */ + uint16_t flags = LEAIFG; + LEAIFG |= flags; + msp_lea_ifg = flags; + __bic_SR_register_on_exit(LPM0_bits); +} + +#endif diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_patch.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_patch.c new file mode 100755 index 000000000..930d76c61 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/lea/msp_lea_patch.c @@ -0,0 +1,343 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +#define MSP_LEA_REV_A_CHECKSUM 0x7877D27F +#define MSP_LEA_REV_B_CHECKSUM 0xAE790580 + +#define MSP_LEA_COMMAND_TABLE_LENGTH 0x0008 +#define MSP_LEA_COMMAND_TABLE_RESERVED 0x0002 +#define MSP_LEA_COMMAND_TABLE_NULL 0xFFFF +#define MSP_LEA_COMMAND_ID_BASE 0x01e0 +#define MSP_LEA_COMMAND_ID_INCR 0x0004 +#define MSP_LEA_COMMAND_ADDRESS_BASE 0x3C00 +#define MSP_LEA_COMMAND_ADDRESS_INCR 0x0080 + +static uint16_t commandTable[MSP_LEA_COMMAND_TABLE_LENGTH]; + +#if (MSP_LEA_REVISION == MSP_LEA_REVISION_A) +#warning "DSPLib: Building for revision A of LEA, commands will be patched \ +with the latest revision of firmware." +#endif + +void msp_lea_initCommandTable(void) +{ + uint16_t i; + + /* Initialize command table. */ + for (i = 0; i < MSP_LEA_COMMAND_TABLE_LENGTH; i++) { + commandTable[i] = MSP_LEA_COMMAND_TABLE_NULL; + } +} + +uint16_t msp_lea_getRevision(void) +{ + uint32_t checksum; + + /* Read LEA code memory checksum */ + LEACMCTL = 0x2ffc0000 | LEAINC | LEACMAE; + checksum = LEACMA; + LEACMCTL = 0; + + /* Return LEA code ROM revision */ + switch (checksum) { + case MSP_LEA_REV_A_CHECKSUM: + return MSP_LEA_REVISION_A; + case MSP_LEA_REV_B_CHECKSUM: + return MSP_LEA_REVISION_B; + default: + return MSP_LEA_REVISION_UNKNOWN; + } +} + +uint16_t msp_lea_loadCommand(uint16_t commandId, const void *command, uint16_t length) +{ + uint16_t i; + uint16_t j; + uint16_t commandAddress; + uint32_t *commandPtr = (uint32_t *)command; + + /* Return command ID if already loaded or find next open command entry. */ + for (i = 0; i < MSP_LEA_COMMAND_TABLE_LENGTH-MSP_LEA_COMMAND_TABLE_RESERVED; i++) { + /* Check if command is loaded, calculate and return ID. */ + if (commandTable[i] == commandId) { + return (MSP_LEA_COMMAND_ID_BASE + i*MSP_LEA_COMMAND_ID_INCR); + } + /* Check if table entry is NULL, break and load command */ + if (commandTable[i] == MSP_LEA_COMMAND_TABLE_NULL) { + break; + } + } + + /* Calculate command address. */ + commandAddress = MSP_LEA_COMMAND_ADDRESS_BASE + i*MSP_LEA_COMMAND_ADDRESS_INCR; + + /* Load command to address. */ + LEACMCTL = LEACRACTION; + while (LEACMCTL & LEACRACTION); + LEACMCTL = ((uint32_t)commandAddress << 16) | LEAINC | LEACMAE; + for (j = 0; j < length; j++) { + LEACMA = commandPtr[j]; + } + LEACMCTL = 0; + + /* Store command ID of the loaded function and return new ID. */ + commandTable[i] = commandId; + if (length > 32) { + commandTable[i+1] = commandId; + } + return (commandAddress >> 5); +} + +const uint32_t MSP_LEA_MIN[23] = { + 0x7ffff254,0x400ff250,0x7ffff60a,0x7ffff685, + 0xa8000004,0x7ffff4a1,0x7ffff781,0x80000001, + 0x8006ffff,0x80880000,0x80807fff,0xb0000012, + 0x080fffff,0x7ffffb08,0x260ffe10,0x7ffff568, + 0x7ffffb18,0x260ffe90,0x080ff568,0x7ffff204, + 0x7fffffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MINUNSIGNED[23] = { + 0x7ffff254,0x400ff250,0x7ffff60a,0x7ffff685, + 0xa8000004,0x7ffff4a1,0x7ffff781,0x80000001, + 0x8006ffff,0x80880000,0x8080ffff,0xb0000012, + 0x080fffff,0x7ffffb48,0x260ffe10,0x7ffff568, + 0x7ffffb58,0x260ffe90,0x080ff568,0x7ffff204, + 0x7fffffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MINLONGMATRIX[20] = { + 0x7ffff256,0x80000001,0x010ff250,0x490ff003, + 0x8082ffff,0x7ffff611,0x7ffffc32,0x082ff782, + 0x7ffff685,0x80060000,0xb000000e,0x002ff462, + 0x261ffa08,0x002ff281,0x7ffff562,0x7ffff20d, + 0x7ffff114,0x388fffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MINUNSIGNEDLONGMATRIX[20] = { + 0x7ffff256,0x80000001,0x010ff250,0x490ff003, + 0x8082ffff,0x7ffff611,0x7ffffc32,0x082ff782, + 0x7ffff685,0x80060000,0xb000000e,0x002ff462, + 0x261ffa48,0x002ff281,0x7ffff562,0x7ffff20d, + 0x7ffff114,0x388fffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MAX[23] = { + 0x7ffff254,0x400ff250,0x7ffff60a,0x7ffff685, + 0xa8000004,0x7ffff4a1,0x7ffff781,0x80000001, + 0x8006ffff,0x80880000,0x80808000,0xb0000012, + 0x080fffff,0x7ffffb88,0x260ffe10,0x7ffff568, + 0x7ffffb98,0x260ffe90,0x080ff568,0x7ffff204, + 0x7fffffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MAXUNSIGNED[23] = { + 0x7ffff254,0x400ff250,0x7ffff60a,0x7ffff685, + 0xa8000004,0x7ffff4a1,0x7ffff781,0x80000001, + 0x8006ffff,0x80880000,0x80800000,0xb0000012, + 0x080fffff,0x7ffffbc8,0x260ffe10,0x7ffff568, + 0x7ffffbd8,0x260ffe90,0x080ff568,0x7ffff204, + 0x7fffffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MAXLONGMATRIX[20] = { + 0x7ffff256,0x80000001,0x010ff250,0x490ff003, + 0x8082ffff,0x7ffff611,0x7ffffc32,0x082ff782, + 0x7ffff685,0x80060000,0xb000000e,0x002ff462, + 0x261ffa88,0x002ff281,0x7ffff562,0x7ffff20d, + 0x7ffff114,0x388fffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MAXUNSIGNEDLONGMATRIX[20] = { + 0x7ffff256,0x80000001,0x010ff250,0x490ff003, + 0x8082ffff,0x7ffff611,0x7ffffc32,0x082ff782, + 0x7ffff685,0x80060000,0xb000000e,0x002ff462, + 0x261ffac8,0x002ff281,0x7ffff562,0x7ffff20d, + 0x7ffff114,0x388fffff,0x308fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_MACLONGMATRIX[18] = { + 0x7ffff254,0x80000001,0x080ff251,0x000ff781, + 0x7ffff680,0x480ff694,0x188ff611,0x81040000, + 0xb000000e,0x102ff606,0x7ff99fff,0x7ff8ffff, + 0x102a6ed7,0x7fffefdf,0x188fe93c,0x7fffffff, + 0x310fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_FFTCOMPLEXAUTOSCALING[58] = { + 0x7ffff254,0x400ff250,0x7ffff780,0x80000001, + 0x80810000,0x100ff251,0xb000000b,0x180ff61c, + 0x100ff234,0x180ff23d,0x309fffff,0x389ff4c2, + 0x7ffff62d,0x7ffff61c,0x7ffff250,0x7ffff600, + 0x8005fffe,0x250ff459,0x80870001,0x7ffff788, + 0xa8000000,0x7ffff618,0x7ffff617,0x8003ffff, + 0x7ffff675,0x800a0800,0x800907ff,0xb0000035, + 0x230ff670,0x2547f671,0x27dfffff,0x7ffff450, + 0x12bff606,0x04bc1789,0x7ffdb61c,0x7ffcdfff, + 0x12b57fff,0x7ffc049b,0x7ffcc21d,0xb000002c, + 0x04bda01c,0x12b57fff,0x3b3c049b,0x353cc21d, + 0x04bda01c,0xa8000000,0x3b3d7407,0x353fe49b, + 0x7fffe21d,0x7fffe01c,0x3b3ff675,0x353ff4cf, + 0xa8000004,0x7ffff6fd,0x7ffff470,0x80880000, + 0x7ffff262,0xb0c00000 +}; + +const uint32_t MSP_LEA_FFTCOMPLEXLONG[64] = { + 0x7ffff254,0x400ff250,0x7ffff60b,0x8005ffff, + 0x25bff45a,0x8005ffff,0xa8000006,0x25bff452, + 0xa000fffb,0x90820000,0x7ffff788,0x80820002, + 0x80050002,0x80010003,0x80080000,0x800a0800, + 0x80000001,0x800907ff,0xb000003d,0x908a0001, + 0x2547f450,0x108ff622,0x90030000,0x90820002, + 0x7ffa3783,0x7ff896a3,0x7ff8ee9c,0x12aa5606, + 0xb0000029,0x7ff8ced5,0x7ffa7fff,0x7ff88e98, + 0x7ffa2b04,0x008fee99,0x0ccfe94b,0x7fffea25, + 0x1087ea5d,0x39088824,0x3b2a285d,0x3108ce9c, + 0x12aa7fff,0x3d48ce9d,0x7ffa7fff,0x7ff88e98, + 0x7ffa2b04,0x008fee99,0x0ccfe94b,0x7fffea25, + 0x7fffea5d,0x390fe824,0x3b2fe85d,0x310fffff, + 0x3d4fffff,0x90020002,0x7ffff623,0x80010001, + 0xa8000002,0x213ff432,0x7ffff625,0xa8000004, + 0x80080000,0x900a0001,0xa0000005,0xb0800000 +}; + +const uint32_t MSP_LEA_MPYLONGMATRIX[17] = { + 0x7ffff254,0x80000001,0x080ff251,0x000ff781, + 0x480ff694,0x7ffff681,0x7ffff612,0x10aff606, + 0x184fffff,0x7ff8ffff,0xb000000f,0x7ff99690, + 0x10aa6ed7,0x184fefdc,0x7ff99fff,0x3108ffff, + 0xb0800000 +}; + +const uint32_t MSP_LEA_IIRBQ1[31] = { + 0x7ffff256,0x80000001,0x80020000,0x010ff250, + 0x090ff780,0x7ffff617,0x410ff686,0x118ff695, + 0x01cff601,0x188ff204,0x7ff8dfff,0xb000001b, + 0x7ff80890,0x50088810,0x18887211,0x31c80859, + 0x11c88810,0x1a8fe859,0x7ff80851,0x7ff8c810, + 0x7fffe810,0x7ff88816,0x7ff8c851,0x1a8fe851, + 0x188fe854,0x102ff0e4,0x7ff8d235,0x31080890, + 0x338fffff,0x398fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_IIRBQ2[32] = { + 0x7ffff256,0x80000001,0x010ff250,0x090ff780, + 0x7ffff617,0x80020000,0x11cff695,0x8001fffd, + 0x188ff686,0x7ff8dfff,0x18887210,0xb000001e, + 0x7ff81219,0x100fe810,0x7ff84810,0x7ff8e816, + 0x7ff8a859,0x7fffe859,0x7fffe859,0x188ff096, + 0x7ff8f235,0x7ff828d9,0x11c88859,0x18a85210, + 0x39c82810,0x7fffe85c,0x11c88810,0x188fe810, + 0x7ff8d084,0x18887210,0x31081219,0xb0800000 +}; + +const uint32_t MSP_LEA_IIRBQ2EXTENDED[47] = { + 0x7ffff256,0x80000001,0x8001fffc,0x80020000, + 0x010ff250,0x090ff780,0x7ffff617,0x7ffff695, + 0x118ff686,0x088fffff,0x188fffff,0x7ff8dfff, + 0x18886850,0xb0000024,0x7ff80859,0x100fe810, + 0x7ff84810,0x7ff8e816,0x7ff8a859,0x7fffe859, + 0x7fffe859,0x7ffff096,0x018ff234,0x498ff235, + 0x7ffff90d,0x188ff984,0x3b88f235,0x338828d9, + 0x51888859,0x18a85210,0x39c82810,0x088fe85c, + 0x11888810,0x188fe810,0x7ff8d084,0x18886850, + 0x31080859,0x018fffff,0x098ffb10,0x7ffffe80, + 0x7ffff004,0x7ffffb99,0x7ffffe91,0x7ffff01c, + 0x7fffffff,0x31cfffff,0xb0800000 +}; + +const uint32_t MSP_LEA_FIRLONG[30] = { + 0x7ffff255,0x7ffff250,0x7ffff444,0x7ffff450, + 0x80000001,0x008ff604,0x008ff780,0x488ff682, + 0x8001ffff,0x221ff605,0x7ffff420,0x7ffff613, + 0x81050000,0x7ffff601,0xb000001c,0x220ff420, + 0x480ff646,0x7ffff697,0x4d2ff780,0x198ff049, + 0x570ff22c,0xb000001a,0x7ff99fff,0x7ff8ffff, + 0x570a6ed2,0x198fee9a,0x7ff98914,0x210fffff, + 0x308ff094,0xb0800000 +}; + +const uint32_t MSP_LEA_FIRCOMPLEXLONG[43] = { + 0x7ffff255,0x80020001,0x00cff250,0x08cff780, + 0x7ffff690,0x8001ffff,0x201ff084,0x408ff615, + 0x220ff603,0xa8000000,0x81050000,0x7ffff048, + 0x80010001,0xb0000029,0x201ff420,0x7ffff441, + 0x7ffff616,0x7ffff687,0x4d0ff780,0x8002ffff, + 0x19aff22c,0x572fffff,0xb0000025,0x7ff9b229, + 0x7ff8dfff,0x19ca4e9b,0x7ff8eed2,0x7ff98851, + 0x19aa6ed6,0x572fef9a,0x7ff98b14,0x7ff8ffff, + 0x19aa4ed3,0x7ff8eed2,0x7ff98914,0x572a6ed7, + 0x19afefda,0x7ff9a851,0x30aff20c,0x80020002, + 0x30afffff,0x202fffff,0xb0800000 +}; + +const uint32_t MSP_LEA_INTERLEAVEEVENEVEN[22] = { + 0x80000001,0x7ffff255,0x008ff250,0x488ff68a, + 0x7ffff605,0xa8000004,0x25aff61b,0x7ffff69a, + 0xa8000006,0xa8000004,0x7ffff4b2,0x7ffff4aa, + 0x7ffff621,0x000ff78a,0xb0000014,0x7ffff004, + 0x08aff085,0x0aaff09c,0x000ff09d,0x30afffff, + 0x38aff004,0xb0800000 +}; + +const uint32_t MSP_LEA_INTERLEAVEEVENODD[24] = { + 0x80000001,0x7ffff255,0x008ff250,0x488ff68a, + 0x7ffff605,0xa8000004,0x25aff61b,0x7ffff69a, + 0xa8000006,0xa8000004,0x7ffff4b2,0x7ffff4aa, + 0x7ffff622,0x7ffff621,0x220fffff,0x000ff78a, + 0xb0000016,0x7ffff004,0x08aff08d,0x0aaff09c, + 0x000ff015,0x30afffff,0x38cff004,0xb0800000 +}; + +const uint32_t MSP_LEA_INTERLEAVEODDEVEN[22] = { + 0x80000001,0x7ffff255,0x008ff250,0x488ff68a, + 0x7ffff605,0xa8000004,0x25aff61b,0x7ffff69a, + 0xa8000006,0xa8000004,0x7ffff4b2,0x7ffff4aa, + 0x7ffff621,0x000ff78a,0xb0000014,0x7ffff00c, + 0x08aff08d,0x0aaff014,0x000ff015,0x30afffff, + 0x38aff00c,0xb0800000 +}; + +const uint32_t MSP_LEA_INTERLEAVEODDODD[24] = { + 0x80000001,0x7ffff255,0x008ff250,0x488ff68a, + 0x7ffff605,0xa8000004,0x25aff61b,0x7ffff69a, + 0xa8000006,0xa8000004,0x7ffff4b2,0x7ffff4aa, + 0x7ffff621,0x7ffff622,0x210fffff,0x000ff78a, + 0xb0000016,0x7ffff00c,0x08aff085,0x0aaff014, + 0x000ff09d,0x30afffff,0x38cff00c,0xb0800000 +}; + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_abs_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_abs_iq31.c new file mode 100755 index 000000000..778d5e335 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_abs_iq31.c @@ -0,0 +1,48 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix absolute value of a source matrix. + */ +msp_status msp_matrix_abs_iq31(const msp_matrix_abs_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + msp_abs_iq31_params paramsTemp; + + /* Use real vector absolute value function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_abs_iq31(¶msTemp, src, dst); +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_abs_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_abs_q15.c new file mode 100755 index 000000000..107266a98 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_abs_q15.c @@ -0,0 +1,48 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix absolute value of a source matrix. + */ +msp_status msp_matrix_abs_q15(const msp_matrix_abs_q15_params *params, const _q15 *src, _q15 *dst) +{ + msp_abs_q15_params paramsTemp; + + /* Use real vector absolute value function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_abs_q15(¶msTemp, src, dst); +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_add_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_add_iq31.c new file mode 100755 index 000000000..f5a86d0a9 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_add_iq31.c @@ -0,0 +1,48 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix addition of two source matrices. + */ +msp_status msp_matrix_add_iq31(const msp_matrix_add_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + msp_add_iq31_params paramsTemp; + + /* Use real vector addition function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_add_iq31(¶msTemp, srcA, srcB, dst); +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_add_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_add_q15.c new file mode 100755 index 000000000..4720e56f9 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_add_q15.c @@ -0,0 +1,48 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix addition of two source matrices. + */ +msp_status msp_matrix_add_q15(const msp_matrix_add_q15_params *params, const int16_t *srcA, const int16_t *srcB, int16_t *dst) +{ + msp_add_q15_params paramsTemp; + + /* Use real vector addition function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_add_q15(¶msTemp, srcA, srcB, dst); +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_mpy_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_mpy_iq31.c new file mode 100755 index 000000000..be5194a2e --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_mpy_iq31.c @@ -0,0 +1,271 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_matrix_mpy_iq31(const msp_matrix_mpy_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t i; + uint16_t j; + uint16_t cmdId; + uint16_t srcARows; + uint16_t srcACols; + uint16_t srcBRows; + uint16_t srcBCols; + msp_status status; + MSP_LEA_MACLONG_PARAMS *leaParams; + + /* Initialize the row and column sizes. */ + srcARows = params->srcARows; + srcACols = params->srcACols; + srcBRows = params->srcBRows; + srcBCols = params->srcBCols; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that column of A equals rows of B */ + if (srcACols != srcBRows) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MACLONG_PARAMS structure. */ + leaParams = (MSP_LEA_MACLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MACLONG_PARAMS)/sizeof(uint32_t)); + + /* Initialize MSP_LEA_MACLONG_PARAMS structure. */ + leaParams->vectorSize = srcACols; + leaParams->input1Offset = 1; + leaParams->input2Offset = srcBCols; + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MACLONGMATRIX, MSP_LEA_MACLONGMATRIX, + sizeof(MSP_LEA_MACLONGMATRIX)/sizeof(MSP_LEA_MACLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MACLONGMATRIX command. */ + cmdId = LEACMD__MACLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Multiply srcA row by srcB column and accumulate. */ + for (i = 0; i < srcARows*srcACols; i += srcACols) { + for (j = 0; j < srcBCols; j++) { + /* Set MSP_LEA_MACLONG_PARAMS for row by column MAC. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(&srcB[j]); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst++); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&srcA[i]); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + break; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + break; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + break; + } +#endif //MSP_DISABLE_DIAGNOSTICS + } +#ifndef MSP_DISABLE_DIAGNOSTICS + if (status != MSP_SUCCESS) { + break; + } +#endif //MSP_DISABLE_DIAGNOSTICS + } + + /* Free MSP_LEA_MACLONG_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MACLONG_PARAMS)/sizeof(uint32_t)); + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +/* + * Perform matrix multiplication of two source matrices. + */ +msp_status msp_matrix_mpy_iq31(const msp_matrix_mpy_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t cntr; + uint16_t dst_row; + uint16_t dst_col; + uint16_t srcARows; + uint16_t srcACols; + uint16_t srcBRows; + uint16_t srcBCols; + uint16_t row_offset; + uint16_t col_offset; + uint16_t dst_row_offset; + + /* Initialize the row and column sizes. */ + srcARows = params->srcARows; + srcACols = params->srcACols; + srcBRows = params->srcBRows; + srcBCols = params->srcBCols; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that column of A equals rows of B */ + if (srcACols != srcBRows) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* In initialize loop counters. */ + cntr = 0; + dst_row = 0; + dst_col = 0; + row_offset = 0; + col_offset = 0; + dst_row_offset = 0; + +#if defined(__MSP430_HAS_MPY32__) + int32_t result; + + /* If MPY32 is available save control context, set to fractional mode, set saturation mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; + + /* Loop through all srcA rows. */ + while(srcARows--) { + /* Loop through all srcB columns. */ + while (dst_col < srcBCols) { + /* Reset result registers */ + MPY32CTL0 &= ~MPYC; + RES3 = 0; RES2 = 0; RES1 = 0; RES0 = 0; + + /* Multiply and accumulate inputs. */ + while(cntr < srcACols) { + MACS32L = srcA[row_offset + cntr] & 0xffff; + MACS32H = srcA[row_offset + cntr] >> 16; + OP2L = srcB[col_offset + dst_col] & 0xffff; + OP2H = srcB[col_offset + dst_col] >> 16; + col_offset += srcBCols; + cntr++; + } + + /* Store accumulated result. */ + result = RES2; + result |= ((uint32_t)RES3 << 16); + dst[dst_row_offset + dst_col] = result; + + /* Update pointers. */ + dst_col++; + cntr = 0; + col_offset = 0; + } + + /* Update pointers. */ + dst_row++; + dst_col = 0; + row_offset += srcACols; + dst_row_offset += srcBCols; + } + + /* Restore MPY32 control context, previous saturation state. */ + MPY32CTL0 = ui16MPYState; + +#else //__MSP430_HAS_MPY32__ + int64_t result; + + /* Loop through all srcA rows. */ + while(srcARows--) { + /* Loop through all srcB columns. */ + while (dst_col < srcBCols) { + /* Initialize accumulator. */ + result = 0; + + /* Loop through all elements in srcA column and srcB row. */ + while(cntr < srcACols) { + result += (int64_t)srcA[row_offset+cntr] * (int64_t)srcB[col_offset+dst_col]; + col_offset += srcBCols; + cntr++; + } + + /* Scale and saturate accumulator and store to destination. */ + dst[dst_row_offset+dst_col] = (_iq31)__saturate((result >> 31), INT32_MIN, INT32_MAX); + + /* Update pointers. */ + dst_col++; + cntr = 0; + col_offset = 0; + } + + /* Update pointers. */ + dst_row++; + dst_col = 0; + row_offset += srcACols; + dst_row_offset += srcBCols; + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_mpy_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_mpy_q15.c new file mode 100755 index 000000000..b144d61ce --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_mpy_q15.c @@ -0,0 +1,239 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_matrix_mpy_q15(const msp_matrix_mpy_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t srcARows; + uint16_t srcACols; + uint16_t srcBRows; + uint16_t srcBCols; + msp_status status; + MSP_LEA_MPYMATRIXROW_PARAMS *leaParams; + + /* Initialize the row and column sizes. */ + srcARows = params->srcARows; + srcACols = params->srcACols; + srcBRows = params->srcBRows; + srcBCols = params->srcBCols; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that column of A equals rows of B */ + if (srcACols != srcBRows) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYMATRIXROW_PARAMS structure. */ + leaParams = (MSP_LEA_MPYMATRIXROW_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYMATRIXROW_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + + /* Iterate through each row of srcA */ + while (srcARows--) { + /* Set MSP_LEA_MPYMATRIXROW_PARAMS structure. */ + leaParams->rowSize = srcBRows; + leaParams->colSize = srcBCols; + leaParams->colVector = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MPYMATRIXROW command. */ + msp_lea_invokeCommand(LEACMD__MPYMATRIXROW); + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + break; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + break; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + break; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Increment srcA and dst pointers. */ + srcA += srcACols; + dst += srcBCols; + } + + /* Free MSP_LEA_MPYMATRIXROW_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MPYMATRIXROW_PARAMS)/sizeof(uint32_t)); + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_matrix_mpy_q15(const msp_matrix_mpy_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t cntr; + uint16_t srcARows; + uint16_t srcACols; + uint16_t srcBRows; + uint16_t srcBCols; + uint16_t dst_row; + uint16_t dst_col; + uint16_t row_offset; + uint16_t col_offset; + uint16_t dst_row_offset; + + /* Initialize the row and column sizes. */ + srcARows = params->srcARows; + srcACols = params->srcACols; + srcBRows = params->srcBRows; + srcBCols = params->srcBCols; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that column of A equals rows of B */ + if (srcACols != srcBRows) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* In initialize loop counters. */ + cntr = 0; + dst_row = 0; + dst_col = 0; + row_offset = 0; + col_offset = 0; + dst_row_offset = 0; + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context, set to fractional mode, set saturation mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; + + /* Loop through all srcA rows. */ + while(srcARows--) { + /* Loop through all srcB columns. */ + while (dst_col < srcBCols) { + /* Reset result accumulator. */ + MPY32CTL0 &= ~MPYC; + RESLO = 0; RESHI = 0; + + /* Loop through all elements in srcA column and srcB row. */ + while(cntr < srcACols) { + MACS = srcA[row_offset + cntr]; + OP2 = srcB[col_offset + dst_col]; + col_offset += srcBCols; + cntr++; + } + + /* Store the result */ + dst[dst_row_offset + dst_col] = RESHI; + + /* Update pointers. */ + dst_col++; + cntr = 0; + col_offset = 0; + } + + /* Update pointers. */ + dst_row++; + dst_col = 0; + row_offset += srcACols; + dst_row_offset += srcBCols; + } + + /* Restore MPY32 control context, previous saturation state. */ + MPY32CTL0 = ui16MPYState; + +#else //__MSP430_HAS_MPY32__ + _iq31 result; + + /* Loop through all srcA rows. */ + while(srcARows--) { + /* Loop through all srcB columns. */ + while (dst_col < srcBCols) { + /* Initialize accumulator. */ + result = 0; + + /* Loop through all elements in srcA column and srcB row. */ + while(cntr < srcACols) { + result += (_iq31)srcA[row_offset + cntr] * (_iq31)srcB[col_offset + dst_col]; + col_offset += srcBCols; + cntr++; + } + + /* Saturate and store the result */ + dst[dst_row_offset + dst_col] = (_q15)__saturate(result >> 15, INT16_MIN, INT16_MAX); + + /* Update pointers. */ + dst_col++; + cntr = 0; + col_offset = 0; + } + + /* Update pointers. */ + dst_row++; + dst_col = 0; + row_offset += srcACols; + dst_row_offset += srcBCols; + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_neg_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_neg_iq31.c new file mode 100755 index 000000000..489f529ca --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_neg_iq31.c @@ -0,0 +1,46 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise multiplication of a single source vector with negative one. + */ +msp_status msp_matrix_neg_iq31(const msp_matrix_neg_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + msp_neg_iq31_params paramsTemp; + + /* Use real vector negate function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_neg_iq31(¶msTemp, src, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_neg_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_neg_q15.c new file mode 100755 index 000000000..938cd824b --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_neg_q15.c @@ -0,0 +1,46 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise multiplication of a single source vector with negative one. + */ +msp_status msp_matrix_neg_q15(const msp_matrix_neg_q15_params *params, const _q15 *src, _q15 *dst) +{ + msp_neg_q15_params paramsTemp; + + /* Use real vector negate function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_neg_q15(¶msTemp, src, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_offset_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_offset_iq31.c new file mode 100755 index 000000000..ff2a499ba --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_offset_iq31.c @@ -0,0 +1,49 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix offset of a source matrix. + */ +msp_status msp_matrix_offset_iq31(const msp_matrix_offset_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + msp_offset_iq31_params paramsTemp; + + /* Use real vector offset function. */ + paramsTemp.offset = params->offset; + paramsTemp.length = params->rows * params->cols; + + return msp_offset_iq31(¶msTemp, src, dst); +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_offset_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_offset_q15.c new file mode 100755 index 000000000..697e3dd75 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_offset_q15.c @@ -0,0 +1,50 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix offset of a source matrix. + */ +msp_status msp_matrix_offset_q15(const msp_matrix_offset_q15_params *params, const _q15 *src, _q15 *dst) +{ + msp_offset_q15_params paramsTemp; + + /* Use real vector offset function. */ + paramsTemp.offset = params->offset; + paramsTemp.length = params->rows * params->cols; + + return msp_offset_q15(¶msTemp, src, dst); + +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_scale_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_scale_iq31.c new file mode 100755 index 000000000..b45257310 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_scale_iq31.c @@ -0,0 +1,48 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise iq31 multiply and left shift + */ +msp_status msp_matrix_scale_iq31(const msp_matrix_scale_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + msp_scale_iq31_params paramsTemp; + + /* Use real vector scale function. */ + paramsTemp.shift = params->shift; + paramsTemp.length = params->rows * params->cols; + paramsTemp.scale = params->scale; + + return msp_scale_iq31(¶msTemp, src, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_scale_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_scale_q15.c new file mode 100755 index 000000000..9737c40d8 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_scale_q15.c @@ -0,0 +1,51 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix bitwise shift and q15 multiply of a source matrix. + */ +msp_status msp_matrix_scale_q15(const msp_matrix_scale_q15_params *params, const _q15 *src, _q15 *dst) +{ + msp_scale_q15_params paramsTemp; + + /* Use real vector scale function. */ + paramsTemp.scale = params->scale; + paramsTemp.shift = params->shift; + paramsTemp.length = params->rows * params->cols; + + return msp_scale_q15(¶msTemp, src, dst); + +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_shift_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_shift_iq31.c new file mode 100755 index 000000000..d8293ec5e --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_shift_iq31.c @@ -0,0 +1,47 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise left or right shift of a single source matrix. + */ +msp_status msp_matrix_shift_iq31(const msp_matrix_shift_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + msp_shift_iq31_params paramsTemp; + + /* Use real vector shift function. */ + paramsTemp.shift = params->shift; + paramsTemp.length = params->rows * params->cols; + + return msp_shift_iq31(¶msTemp, src, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_shift_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_shift_q15.c new file mode 100755 index 000000000..13467ed52 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_shift_q15.c @@ -0,0 +1,47 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise left or right shift of a single source matrix. + */ +msp_status msp_matrix_shift_q15(const msp_matrix_shift_q15_params *params, const _q15 *src, _q15 *dst) +{ + msp_shift_q15_params paramsTemp; + + /* Use real vector shift function. */ + paramsTemp.shift = params->shift; + paramsTemp.length = params->rows * params->cols; + + return msp_shift_q15(¶msTemp, src, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_sub_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_sub_iq31.c new file mode 100755 index 000000000..69dd5a605 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_sub_iq31.c @@ -0,0 +1,48 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix subtraction of two source matrices. + */ +msp_status msp_matrix_sub_iq31(const msp_matrix_sub_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + msp_sub_iq31_params paramsTemp; + + /* Use real vector subtraction function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_sub_iq31(¶msTemp, srcA, srcB, dst); +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_sub_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_sub_q15.c new file mode 100755 index 000000000..ddc3c6e64 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_sub_q15.c @@ -0,0 +1,48 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix subtraction of two source matrices. + */ +msp_status msp_matrix_sub_q15(const msp_matrix_sub_q15_params *params, const int16_t *srcA, const int16_t *srcB, int16_t *dst) +{ + msp_sub_q15_params paramsTemp; + + /* Use real vector subtraction function. */ + paramsTemp.length = params->rows * params->cols; + + return msp_sub_q15(¶msTemp, srcA, srcB, dst); +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_trans_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_trans_iq31.c new file mode 100755 index 000000000..a4b846e09 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_trans_iq31.c @@ -0,0 +1,65 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix transposition of a source matrix. + */ +msp_status msp_matrix_trans_iq31(const msp_matrix_trans_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t i; + uint16_t rows; + uint16_t cols; + msp_status status; + msp_deinterleave_iq31_params deinterParams; + + /* Extract matrix parameters. */ + rows = params->rows; + cols = params->cols; + + /* Initialize deinterleave parameters. */ + deinterParams.length = rows; + deinterParams.numChannels = cols; + + /* Iterate through source columns and deinterleave to destination. */ + for (i = 0; i < cols; i++) { + /* Transpose source columns to destination rows using deinterleave. */ + deinterParams.channel = i; + status = msp_deinterleave_iq31(&deinterParams, src, &dst[i*rows]); + if (status != MSP_SUCCESS) { + return status; + } + } + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_trans_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_trans_q15.c new file mode 100755 index 000000000..d0ea23e98 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/matrix/msp_matrix_trans_q15.c @@ -0,0 +1,74 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform matrix transposition of a source matrix. + */ +msp_status msp_matrix_trans_q15(const msp_matrix_trans_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t i; + uint16_t rows; + uint16_t cols; + msp_status status; + msp_deinterleave_q15_params deinterParams; + + /* Extract matrix parameters. */ + rows = params->rows; + cols = params->cols; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that row and column sizes are even. */ + if ((rows & 1) || (cols & 1)) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize deinterleave parameters. */ + deinterParams.length = rows; + deinterParams.numChannels = cols; + + /* Iterate through source columns and deinterleave to destination. */ + for (i = 0; i < cols; i++) { + /* Transpose source columns to destination rows using deinterleave. */ + deinterParams.channel = i; + status = msp_deinterleave_q15(&deinterParams, src, &dst[i*rows]); + if (status != MSP_SUCCESS) { + return status; + } + } + + return MSP_SUCCESS; +} + + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_bitrev_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_bitrev_iq31.c new file mode 100755 index 000000000..943c85385 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_bitrev_iq31.c @@ -0,0 +1,175 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_bitrev_iq31(const msp_cmplx_bitrev_iq31_params *params, _iq31 *src) +{ + uint16_t cmdId; + msp_status status; + uint16_t length; + uint16_t sqrtLength; + MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS *leaParams; + + /* Save input length to local. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Check vector size to determine which bit reverse function to use. */ + sqrtLength = 1; + while (length > 2) { + sqrtLength <<= 1; + length >>= 2; + } + + /* Allocate MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS structure. */ + leaParams = (MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS)/sizeof(uint32_t)); + + /* Initialize MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS structure. */ + leaParams->sqrtVectorSize = sqrtLength; + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Check if remainder is even or odd to determine which LEA function to use. */ + if (length == 2) { + /* Invoke the LEACMD__BITREVERSECOMPLEXLONGODD command. */ + cmdId = LEACMD__BITREVERSECOMPLEXLONGODD; + } + else { + /* Invoke the LEACMD__BITREVERSECOMPLEXLONGEVEN command. */ + cmdId = LEACMD__BITREVERSECOMPLEXLONGEVEN; + } + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_BITREVERSECOMPLEXLONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +/* + * Perform an in-place bit reversal of the complex input array using a lookup + * table. + */ +msp_status msp_cmplx_bitrev_iq31(const msp_cmplx_bitrev_iq31_params *params, _iq31 *src) +{ + uint16_t i; // loop counter + uint16_t index; // left justified index + uint16_t indexInc; // index increment + uint16_t length; // src length + uint16_t indexBitRev; // index bit reversal + uint64_t temp; // Temporary storage + uint64_t *srcPtr; // Treat complex data pairs as 32-bit data + + /* Initialize source pointer and length. */ + srcPtr = (uint64_t *)src; + length = params->length; + index = 0; + indexInc = 2; + + /* Calculate index increment for left justified index. */ + while (length < 0x8000) { + indexInc <<= 1; + length <<= 1; + } + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if (length != 0x8000) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* In-place bit-reversal using a larger table length than source data length. */ + length = params->length; + for (i = 0; i < length; i++, index += indexInc) { + /* Calculate bit reversed index. */ + indexBitRev = ((uint16_t)msp_cmplx_bitrev_table_ui8[index & 0xff] << 8) + + ((uint16_t)msp_cmplx_bitrev_table_ui8[(index >> 8) & 0xff]); + + if (i < indexBitRev) { + /* Swap inputs. */ + temp = srcPtr[i]; + srcPtr[i] = srcPtr[indexBitRev]; + srcPtr[indexBitRev] = temp; + } + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_bitrev_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_bitrev_q15.c new file mode 100755 index 000000000..1b192c671 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_bitrev_q15.c @@ -0,0 +1,175 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_bitrev_q15(const msp_cmplx_bitrev_q15_params *params, _q15 *src) +{ + uint16_t cmdId; + msp_status status; + uint16_t length; + uint16_t sqrtLength; + MSP_LEA_BITREVERSECOMPLEX_PARAMS *leaParams; + + /* Save input length to local. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Check vector size to determine which bit reverse function to use. */ + sqrtLength = 1; + while (length > 2) { + sqrtLength <<= 1; + length >>= 2; + } + + /* Allocate MSP_LEA_BITREVERSECOMPLEX_PARAMS structure. */ + leaParams = (MSP_LEA_BITREVERSECOMPLEX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_BITREVERSECOMPLEX_PARAMS)/sizeof(uint32_t)); + + /* Initialize MSP_LEA_BITREVERSECOMPLEX_PARAMS structure. */ + leaParams->sqrtVectorSize = sqrtLength; + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Check if remainder is even or odd to determine which LEA function to use. */ + if (length == 2) { + /* Invoke the LEACMD__BITREVERSECOMPLEXODD command. */ + cmdId = LEACMD__BITREVERSECOMPLEXODD; + } + else { + /* Invoke the LEACMD__BITREVERSECOMPLEXEVEN command. */ + cmdId = LEACMD__BITREVERSECOMPLEXEVEN; + } + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_BITREVERSECOMPLEX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_BITREVERSECOMPLEX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +/* + * Perform an in-place bit reversal of the complex input array using a lookup + * table. + */ +msp_status msp_cmplx_bitrev_q15(const msp_cmplx_bitrev_q15_params *params, _q15 *src) +{ + uint16_t i; // loop counter + uint16_t index; // left justified index + uint16_t indexInc; // index increment + uint16_t length; // src length + uint16_t indexBitRev; // index bit reversal + uint32_t temp; // Temporary storage + uint32_t *srcPtr; // Treat complex data pairs as 32-bit data + + /* Initialize source pointer and length. */ + srcPtr = (uint32_t *)src; + length = params->length; + index = 0; + indexInc = 2; + + /* Calculate index increment for left justified index. */ + while (length < 0x8000) { + indexInc <<= 1; + length <<= 1; + } + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if (length != 0x8000) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* In-place bit-reversal using fixed table length. */ + length = params->length; + for (i = 0; i < length; i++, index += indexInc) { + /* Calculate bit reversed index. */ + indexBitRev = ((uint16_t)msp_cmplx_bitrev_table_ui8[index & 0xff] << 8) + + ((uint16_t)msp_cmplx_bitrev_table_ui8[(index >> 8) & 0xff]); + + if (i < indexBitRev) { + /* Swap inputs. */ + temp = srcPtr[i]; + srcPtr[i] = srcPtr[indexBitRev]; + srcPtr[indexBitRev] = temp; + } + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_auto_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_auto_q15.c new file mode 100755 index 000000000..26ab07b92 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_auto_q15.c @@ -0,0 +1,433 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_fft_auto_q15(const msp_cmplx_fft_q15_params *params, _q15 *src, uint16_t *shift) +{ + uint16_t cmdId; + uint16_t log2Size; + uint16_t length; + msp_status status; + MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS *leaParams; + + /* Save input length to local. */ + length = params->length; + + /* Bit reverse the order of the inputs. */ + if(params->bitReverse) { + /* Create and initialize a bit reversal params structure. */ + msp_cmplx_bitrev_q15_params paramsBitRev; + paramsBitRev.length = params->length; + + /* Perform bit reversal on source data. */ + status = msp_cmplx_bitrev_q15(¶msBitRev, src); + + /* Check if the operation was not successful. */ + if (status != MSP_SUCCESS) { + return status; + } + } + + /* Calculate log2Size parameter. */ + log2Size = 0; + while (length > 1) { + log2Size++; + length >>= 1; + } + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, length*2))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS structure. */ + leaParams = (MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS structure. */ + leaParams->vectorSizeBy2 = length >> 1; + leaParams->log2Size = log2Size; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__FFTCOMPLEXAUTOSCALING, MSP_LEA_FFTCOMPLEXAUTOSCALING, + sizeof(MSP_LEA_FFTCOMPLEXAUTOSCALING)/sizeof(MSP_LEA_FFTCOMPLEXAUTOSCALING[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__FFTCOMPLEXAUTOSCALING command. */ + cmdId = LEACMD__FFTCOMPLEXAUTOSCALING; +#endif //MSP_LEA_REVISION. + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Get auto-scaling result */ + *shift = LEAPMDST; + + /* Free MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FFTCOMPLEXAUTOSCALING_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +#define STAGE1_STEP (2) +#define STAGE2_STEP (STAGE1_STEP*2) +#define STAGE3_STEP (STAGE2_STEP*2) +#define STAGE4_STEP (STAGE3_STEP*2) + +static inline void msp_cmplx_overflow_q15(int16_t *src, bool *overflow); +static inline void msp_cmplx_btfly_auto_q15(int16_t *srcA, int16_t *srcB, const _q15 *coeff, bool *scale, bool *overflow); +static inline void msp_cmplx_btfly_c0_auto_q15(int16_t *srcA, int16_t *srcB, bool *scale, bool *overflow); +static inline void msp_cmplx_btfly_c1_auto_q15(int16_t *srcA, int16_t *srcB, bool *scale, bool *overflow); + +/* + * Perform in-place radix-2 DFT of the input signal using an algorithm optimized + * for MSP430 with fixed scaling by two at each stage. + */ +msp_status msp_cmplx_fft_auto_q15(const msp_cmplx_fft_q15_params *params, int16_t *src, uint16_t *shift) +{ + bool scale; // scale flag + bool overflow; // overflow flag + int16_t i, j; // loop counters + uint16_t step; // step size + uint16_t length; // src length + uint16_t twiddleIndex; // twiddle table index + uint16_t twiddleIncrement; // twiddle table increment + int16_t *srcPtr; // local source pointer + const _q15 *twiddlePtr; // twiddle table pointer + msp_status status; // Status of the operation + + /* Save input length to local. */ + length = params->length; + + /* Bit reverse the order of the inputs. */ + if(params->bitReverse) { + /* Create and initialize a bit reversal params structure. */ + msp_cmplx_bitrev_q15_params paramsBitRev; + paramsBitRev.length = params->length; + + /* Perform bit reversal on source data. */ + status = msp_cmplx_bitrev_q15(¶msBitRev, src); + + /* Check if the operation was not successful. */ + if (status != MSP_SUCCESS) { + return status; + } + } + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the provided table is the correct length. */ + if (*(uint16_t *)params->twiddleTable < length) { + return MSP_TABLE_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize shift result. */ + *shift = 0; + + /* Check for initial overflow. */ + overflow = false; + for (i = 0 ; i < length; i++) { + msp_cmplx_overflow_q15(&src[i*2], &overflow); + } + + /* Stage 1. */ + scale = overflow; + overflow = false; + *shift += scale ? 1 : 0; + if (STAGE1_STEP <= length) { + for (j = 0; j < length; j += STAGE1_STEP) { + srcPtr = src + j*2; + msp_cmplx_btfly_c0_auto_q15(&srcPtr[0], &srcPtr[0+STAGE1_STEP], &scale, &overflow); + } + } + + /* Stage 2. */ + scale = overflow; + overflow = false; + *shift += scale ? 1 : 0; + if (STAGE2_STEP <= length) { + for (j = 0; j < length; j += STAGE2_STEP) { + srcPtr = src + j*2; + msp_cmplx_btfly_c0_auto_q15(&srcPtr[0], &srcPtr[0+STAGE2_STEP], &scale, &overflow); + msp_cmplx_btfly_c1_auto_q15(&srcPtr[2], &srcPtr[2+STAGE2_STEP], &scale, &overflow); + } + } + + /* Initialize step size, twiddle angle increment and twiddle table pointer. */ + step = STAGE3_STEP; + twiddleIncrement = 2*(*(uint16_t*)params->twiddleTable)/STAGE3_STEP; + twiddlePtr = ¶ms->twiddleTable[DSPLIB_TABLE_OFFSET]; + + /* If MPY32 is available save control context and set to fractional mode. */ +#if defined(__MSP430_HAS_MPY32__) + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; +#endif + + /* Stage 3 -> log2(step). */ + while (step <= length) { + /* Reset the twiddle angle index. */ + twiddleIndex = 0; + + /* Set scale and overflow flags. */ + scale = overflow; + overflow = false; + *shift += scale ? 1 : 0; + + for (i = 0; i < (step/2); i++) { + /* Perform butterfly operations on complex pairs. */ + for (j = i; j < length; j += step) { + srcPtr = src + j*2; + msp_cmplx_btfly_auto_q15(srcPtr, srcPtr + step, &twiddlePtr[twiddleIndex], &scale, &overflow); + } + + /* Increment twiddle table index. */ + twiddleIndex += twiddleIncrement; + } + /* Double the step size and halve the increment factor. */ + step *= 2; + twiddleIncrement = twiddleIncrement/2; + } + + /* Restore MPY32 control context. */ +#if defined(__MSP430_HAS_MPY32__) + MPY32CTL0 = ui16MPYState; +#endif + + return MSP_SUCCESS; +} + +#define MSP_OVERFLOW_MAX (INT16_MAX >> 2) +#define MSP_OVERFLOW_MIN (INT16_MIN >> 2) + +/* + * Abstracted helper function to check for overflow. + */ +static inline void msp_cmplx_overflow_q15(int16_t *src, bool *overflow) +{ + if ((CMPLX_REAL(src) > MSP_OVERFLOW_MAX) || (CMPLX_REAL(src) < MSP_OVERFLOW_MIN)) { + *overflow = true; + } + if ((CMPLX_IMAG(src) > MSP_OVERFLOW_MAX) || (CMPLX_IMAG(src) < MSP_OVERFLOW_MIN)) { + *overflow = true; + } +} + +/* + * Abstracted helper functions for a radix-2 butterfly operation. The following + * operation is performed at each stage: + * A = A + coeff*B + * B = A - coeff*B + * + * If overflow is detected the result is scaled by two: + * A = A/2 + * B = A/2 + */ +static inline void msp_cmplx_btfly_auto_q15(int16_t *srcA, int16_t *srcB, const _q15 *coeff, bool *scale, bool *overflow) +{ + /* Load coefficients. */ + _q15 tempR = CMPLX_REAL(coeff); + _q15 tempI = CMPLX_IMAG(coeff); + + /* Calculate real and imaginary parts of coeff*B. */ + __q15cmpy(&tempR, &tempI, &CMPLX_REAL(srcB), &CMPLX_IMAG(srcB)); + + /* Scale result if necessary. */ + if (*scale) { + /* B = (A - coeff*B)/2 */ + CMPLX_REAL(srcB) = (CMPLX_REAL(srcA) - tempR) >> 1; + CMPLX_IMAG(srcB) = (CMPLX_IMAG(srcA) - tempI) >> 1; + + /* A = (A + coeff*B)/2 */ + CMPLX_REAL(srcA) = (CMPLX_REAL(srcA) + tempR) >> 1; + CMPLX_IMAG(srcA) = (CMPLX_IMAG(srcA) + tempI) >> 1; + } + else { + /* B = A - coeff*B */ + CMPLX_REAL(srcB) = CMPLX_REAL(srcA) - tempR; + CMPLX_IMAG(srcB) = CMPLX_IMAG(srcA) - tempI; + + /* A = A + coeff*B */ + CMPLX_REAL(srcA) = CMPLX_REAL(srcA) + tempR; + CMPLX_IMAG(srcA) = CMPLX_IMAG(srcA) + tempI; + } + + /* Check for possibility of overflow. */ + if (!*overflow) { + msp_cmplx_overflow_q15(srcA, overflow); + msp_cmplx_overflow_q15(srcB, overflow); + } +} + +/* + * Simplified radix-2 butterfly operation for e^(-2*pi*(0/4)). This abstracted + * helper function takes advantage of the fact the the twiddle coefficients are + * positive and negative one for a multiplication by e^(-2*pi*(0/4)). The + * following operation is performed at each stage: + * A = A + (1+0j)*B + * B = A - (1+0j)*B + * + * If overflow is detected the result is scaled by two: + * A = A/2 + * B = A/2 + */ +static inline void msp_cmplx_btfly_c0_auto_q15(int16_t *srcA, int16_t *srcB, bool *scale, bool *overflow) +{ + int16_t tempR = CMPLX_REAL(srcB); + int16_t tempI = CMPLX_IMAG(srcB); + + /* Scale result if necessary. */ + if (*scale) { + /* B = (A - (1+0j)*B)/2 */ + CMPLX_REAL(srcB) = (CMPLX_REAL(srcA) - tempR) >> 1; + CMPLX_IMAG(srcB) = (CMPLX_IMAG(srcA) - tempI) >> 1; + + /* A = (A + (1+0j)*B)/2 */ + CMPLX_REAL(srcA) = (CMPLX_REAL(srcA) + tempR) >> 1; + CMPLX_IMAG(srcA) = (CMPLX_IMAG(srcA) + tempI) >> 1; + } + else { + /* B = A - coeff*B */ + CMPLX_REAL(srcB) = CMPLX_REAL(srcA) - tempR; + CMPLX_IMAG(srcB) = CMPLX_IMAG(srcA) - tempI; + + /* A = A + coeff*B */ + CMPLX_REAL(srcA) = CMPLX_REAL(srcA) + tempR; + CMPLX_IMAG(srcA) = CMPLX_IMAG(srcA) + tempI; + } + + /* Check for possibility of overflow. */ + if (!*overflow) { + msp_cmplx_overflow_q15(srcA, overflow); + msp_cmplx_overflow_q15(srcB, overflow); + } +} + +/* + * Simplified radix-2 butterfly operation for e^(-2*pi*(1/4)). This abstracted + * helper function takes advantage of the fact the the twiddle coefficients are + * positive and negative one for a multiplication by e^(-2*pi*(1/4)). The + * following operation is performed at each stage: + * A = A + (0-1j)*B + * B = A - (0-1j)*B + * + * If overflow is detected the result is scaled by two: + * A = A/2 + * B = A/2 + */ +static inline void msp_cmplx_btfly_c1_auto_q15(int16_t *srcA, int16_t *srcB, bool *scale, bool *overflow) +{ + int16_t tempR = CMPLX_REAL(srcB); + int16_t tempI = CMPLX_IMAG(srcB); + + /* Scale result if necessary. */ + if (*scale) { + /* B = (A - (0-1j)*B)/2 */ + CMPLX_REAL(srcB) = (CMPLX_REAL(srcA) - tempI) >> 1; + CMPLX_IMAG(srcB) = (CMPLX_IMAG(srcA) + tempR) >> 1; + + /* A = (A + (0-1j)*B)/2 */ + CMPLX_REAL(srcA) = (CMPLX_REAL(srcA) + tempI) >> 1; + CMPLX_IMAG(srcA) = (CMPLX_IMAG(srcA) - tempR) >> 1; + } + else { + /* B = A - coeff*B */ + CMPLX_REAL(srcB) = CMPLX_REAL(srcA) - tempI; + CMPLX_IMAG(srcB) = CMPLX_IMAG(srcA) + tempR; + + /* A = A + coeff*B */ + CMPLX_REAL(srcA) = CMPLX_REAL(srcA) + tempI; + CMPLX_IMAG(srcA) = CMPLX_IMAG(srcA) - tempR; + } + + /* Check for possibility of overflow. */ + if (!*overflow) { + msp_cmplx_overflow_q15(srcA, overflow); + msp_cmplx_overflow_q15(srcB, overflow); + } +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_fixed_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_fixed_q15.c new file mode 100755 index 000000000..9d29b4137 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_fixed_q15.c @@ -0,0 +1,310 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_fft_fixed_q15(const msp_cmplx_fft_q15_params *params, int16_t *src) +{ + uint16_t log2Size; + uint16_t length; + msp_status status; + MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS *leaParams; + + /* Save input length to local. */ + length = params->length; + + /* Bit reverse the order of the inputs. */ + if(params->bitReverse) { + /* Create and initialize a bit reversal params structure. */ + msp_cmplx_bitrev_q15_params paramsBitRev; + paramsBitRev.length = params->length; + + /* Perform bit reversal on source data. */ + status = msp_cmplx_bitrev_q15(¶msBitRev, src); + + /* Check if the operation was not successful. */ + if (status != MSP_SUCCESS) { + return status; + } + } + + /* Calculate log2Size parameter. */ + log2Size = 0; + while (length > 1) { + log2Size++; + length >>= 1; + } + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, length*2))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS structure. */ + leaParams = (MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS structure. */ + leaParams->vectorSizeBy2 = length >> 1; + leaParams->log2Size = log2Size; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__FFTCOMPLEXFIXEDSCALING command. */ + msp_lea_invokeCommand(LEACMD__FFTCOMPLEXFIXEDSCALING); + + /* Free MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FFTCOMPLEXFIXEDSCALING_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +#define STAGE1_STEP (2) +#define STAGE2_STEP (STAGE1_STEP*2) +#define STAGE3_STEP (STAGE2_STEP*2) +#define STAGE4_STEP (STAGE3_STEP*2) + +static inline void msp_cmplx_btfly_fixed_q15(int16_t *srcA, int16_t *srcB, const _q15 *coeff); +static inline void msp_cmplx_btfly_c0_fixed_q15(int16_t *srcA, int16_t *srcB); +static inline void msp_cmplx_btfly_c1_fixed_q15(int16_t *srcA, int16_t *srcB); + +/* + * Perform in-place radix-2 DFT of the input signal using an algorithm optimized + * for MSP430 with fixed scaling by two at each stage. + */ +msp_status msp_cmplx_fft_fixed_q15(const msp_cmplx_fft_q15_params *params, int16_t *src) +{ + int16_t i, j; // loop counters + uint16_t step; // step size + uint16_t length; // src length + uint16_t twiddleIndex; // twiddle table index + uint16_t twiddleIncrement; // twiddle table increment + int16_t *srcPtr; // local source pointer + const _q15 *twiddlePtr; // twiddle table pointer + msp_status status; // Status of the operation + + /* Save input length to local. */ + length = params->length; + + /* Bit reverse the order of the inputs. */ + if(params->bitReverse) { + /* Create and initialize a bit reversal params structure. */ + msp_cmplx_bitrev_q15_params paramsBitRev; + paramsBitRev.length = params->length; + + /* Perform bit reversal on source data. */ + status = msp_cmplx_bitrev_q15(¶msBitRev, src); + + /* Check if the operation was not successful. */ + if (status != MSP_SUCCESS) { + return status; + } + } + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the provided table is the correct length. */ + if (*(uint16_t *)params->twiddleTable < length) { + return MSP_TABLE_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Stage 1. */ + if (STAGE1_STEP <= length) { + for (j = 0; j < length; j += STAGE1_STEP) { + srcPtr = src + j*2; + msp_cmplx_btfly_c0_fixed_q15(&srcPtr[0], &srcPtr[0+STAGE1_STEP]); + } + } + + /* Stage 2. */ + if (STAGE2_STEP <= length) { + for (j = 0; j < length; j += STAGE2_STEP) { + srcPtr = src + j*2; + msp_cmplx_btfly_c0_fixed_q15(&srcPtr[0], &srcPtr[0+STAGE2_STEP]); + msp_cmplx_btfly_c1_fixed_q15(&srcPtr[2], &srcPtr[2+STAGE2_STEP]); + } + } + + /* Initialize step size, twiddle angle increment and twiddle table pointer. */ + step = STAGE3_STEP; + twiddleIncrement = 2*(*(uint16_t*)params->twiddleTable)/STAGE3_STEP; + twiddlePtr = ¶ms->twiddleTable[DSPLIB_TABLE_OFFSET]; + + /* If MPY32 is available save control context and set to fractional mode. */ +#if defined(__MSP430_HAS_MPY32__) + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; +#endif + + /* Stage 3 -> log2(step). */ + while (step <= length) { + /* Reset the twiddle angle index. */ + twiddleIndex = 0; + + for (i = 0; i < (step/2); i++) { + /* Perform butterfly operations on complex pairs. */ + for (j = i; j < length; j += step) { + srcPtr = src + j*2; + msp_cmplx_btfly_fixed_q15(srcPtr, srcPtr + step, &twiddlePtr[twiddleIndex]); + } + + /* Increment twiddle table index. */ + twiddleIndex += twiddleIncrement; + } + /* Double the step size and halve the increment factor. */ + step *= 2; + twiddleIncrement = twiddleIncrement/2; + } + + /* Restore MPY32 control context. */ +#if defined(__MSP430_HAS_MPY32__) + MPY32CTL0 = ui16MPYState; +#endif + + return MSP_SUCCESS; +} + +/* + * Abstracted helper functions for a radix-2 butterfly operation. The following + * operation is performed with fixed scaling by two at each stage: + * A = (A + coeff*B)/2 + * B = (A - coeff*B)/2 + */ +static inline void msp_cmplx_btfly_fixed_q15(int16_t *srcA, int16_t *srcB, const _q15 *coeff) +{ + /* Load coefficients. */ + _q15 tempR = CMPLX_REAL(coeff); + _q15 tempI = CMPLX_IMAG(coeff); + + /* Calculate real and imaginary parts of coeff*B. */ + __q15cmpy(&tempR, &tempI, &CMPLX_REAL(srcB), &CMPLX_IMAG(srcB)); + + /* B = (A - coeff*B)/2 */ + CMPLX_REAL(srcB) = (CMPLX_REAL(srcA) - tempR) >> 1; + CMPLX_IMAG(srcB) = (CMPLX_IMAG(srcA) - tempI) >> 1; + + /* A = (A + coeff*B)/2 */ + CMPLX_REAL(srcA) = (CMPLX_REAL(srcA) + tempR) >> 1; + CMPLX_IMAG(srcA) = (CMPLX_IMAG(srcA) + tempI) >> 1; +} + +/* + * Simplified radix-2 butterfly operation for e^(-2*pi*(0/4)). This abstracted + * helper function takes advantage of the fact the the twiddle coefficients are + * positive and negative one for a multiplication by e^(-2*pi*(0/4)). The + * following operation is performed with fixed scaling by two at each stage: + * A = (A + (1+0j)*B)/2 + * B = (A - (1+0j)*B)/2 + */ +static inline void msp_cmplx_btfly_c0_fixed_q15(int16_t *srcA, int16_t *srcB) +{ + int16_t tempR = CMPLX_REAL(srcB); + int16_t tempI = CMPLX_IMAG(srcB); + + /* B = (A - (1+0j)*B)/2 */ + CMPLX_REAL(srcB) = (CMPLX_REAL(srcA) - tempR) >> 1; + CMPLX_IMAG(srcB) = (CMPLX_IMAG(srcA) - tempI) >> 1; + + /* A = (A + (1+0j)*B)/2 */ + CMPLX_REAL(srcA) = (CMPLX_REAL(srcA) + tempR) >> 1; + CMPLX_IMAG(srcA) = (CMPLX_IMAG(srcA) + tempI) >> 1; +} + +/* + * Simplified radix-2 butterfly operation for e^(-2*pi*(1/4)). This abstracted + * helper function takes advantage of the fact the the twiddle coefficients are + * positive and negative one for a multiplication by e^(-2*pi*(1/4)). The + * following operation is performed with fixed scaling by two at each stage: + * A = (A + (0-1j)*B)/2 + * B = (A - (0-1j)*B)/2 + */ +static inline void msp_cmplx_btfly_c1_fixed_q15(int16_t *srcA, int16_t *srcB) +{ + int16_t tempR = CMPLX_REAL(srcB); + int16_t tempI = CMPLX_IMAG(srcB); + + /* B = (A - (0-1j)*B)/2 */ + CMPLX_REAL(srcB) = (CMPLX_REAL(srcA) - tempI) >> 1; + CMPLX_IMAG(srcB) = (CMPLX_IMAG(srcA) + tempR) >> 1; + + /* A = (A + (0-1j)*B)/2 */ + CMPLX_REAL(srcA) = (CMPLX_REAL(srcA) + tempI) >> 1; + CMPLX_IMAG(srcA) = (CMPLX_IMAG(srcA) - tempR) >> 1; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_iq31.c new file mode 100755 index 000000000..ff8d54a3c --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_fft_iq31.c @@ -0,0 +1,328 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_fft_iq31(const msp_cmplx_fft_iq31_params *params, int32_t *src) +{ + uint16_t cmdId; + uint16_t log2Size; + uint16_t length; + msp_status status; + MSP_LEA_FFTCOMPLEXLONG_PARAMS *leaParams; + + /* Save input length to local. */ + length = params->length; + + /* Bit reverse the order of the inputs. */ + if(params->bitReverse) { + /* Create and initialize a bit reversal params structure. */ + msp_cmplx_bitrev_iq31_params paramsBitRev; + paramsBitRev.length = params->length; + + /* Perform bit reversal on source data. */ + status = msp_cmplx_bitrev_iq31(¶msBitRev, src); + + /* Check if the operation was not successful. */ + if (status != MSP_SUCCESS) { + return status; + } + } + + /* Calculate log2Size parameter. */ + log2Size = 0; + while (length > 1) { + log2Size++; + length >>= 1; + } + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, length*8))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FFTCOMPLEXLONG_PARAMS structure. */ + leaParams = (MSP_LEA_FFTCOMPLEXLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FFTCOMPLEXLONG_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FFTCOMPLEXLONG_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->log2Size = log2Size; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__FFTCOMPLEXLONG, MSP_LEA_FFTCOMPLEXLONG, + sizeof(MSP_LEA_FFTCOMPLEXLONG)/sizeof(MSP_LEA_FFTCOMPLEXLONG[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__FFTCOMPLEXLONG command. */ + cmdId = LEACMD__FFTCOMPLEXLONG; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_FFTCOMPLEXLONG_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FFTCOMPLEXLONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + /* SW workaround for OOR interrupt during normal operation. */ + if ((uintptr_t)src + length*(sizeof(int32_t)*2) > LEAMT) { + status = MSP_LEA_OUT_OF_RANGE; + } + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +#define STAGE1_STEP (2) +#define STAGE2_STEP (STAGE1_STEP*2) +#define STAGE3_STEP (STAGE2_STEP*2) +#define STAGE4_STEP (STAGE3_STEP*2) + +static inline void msp_cmplx_btfly_iq31(int32_t *srcA, int32_t *srcB, const _q15 *coeff); +static inline void msp_cmplx_btfly_c0_iq31(int32_t *srcA, int32_t *srcB); +static inline void msp_cmplx_btfly_c1_iq31(int32_t *srcA, int32_t *srcB); + +/* + * Perform in-place radix-2 DFT of the input signal using an algorithm optimized + * for MSP430 with fixed scaling by two at each stage. + */ +msp_status msp_cmplx_fft_iq31(const msp_cmplx_fft_iq31_params *params, int32_t *src) +{ + int16_t i, j; // loop counters + uint16_t step; // step size + uint16_t length; // src length + uint16_t twiddleIndex; // twiddle table index + uint16_t twiddleIncrement; // twiddle table increment + int32_t *srcPtr; // local source pointer + const _q15 *twiddlePtr; // twiddle table pointer + msp_status status; // Status of the operation + + /* Save input length to local. */ + length = params->length; + + /* Bit reverse the order of the inputs. */ + if(params->bitReverse) { + /* Create and initialize a bit reversal params structure. */ + msp_cmplx_bitrev_iq31_params paramsBitRev; + paramsBitRev.length = params->length; + + /* Perform bit reversal on source data. */ + status = msp_cmplx_bitrev_iq31(¶msBitRev, src); + + /* Check if the operation was not successful. */ + if (status != MSP_SUCCESS) { + return status; + } + } + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the provided table is the correct length. */ + if (*(uint16_t *)params->twiddleTable < length) { + return MSP_TABLE_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Stage 1. */ + if (STAGE1_STEP <= length) { + for (j = 0; j < length; j += STAGE1_STEP) { + srcPtr = src + j*2; + msp_cmplx_btfly_c0_iq31(&srcPtr[0], &srcPtr[0+STAGE1_STEP]); + } + } + + /* Stage 2. */ + if (STAGE2_STEP <= length) { + for (j = 0; j < length; j += STAGE2_STEP) { + srcPtr = src + j*2; + msp_cmplx_btfly_c0_iq31(&srcPtr[0], &srcPtr[0+STAGE2_STEP]); + msp_cmplx_btfly_c1_iq31(&srcPtr[2], &srcPtr[2+STAGE2_STEP]); + } + } + + /* Initialize step size, twiddle angle increment and twiddle table pointer. */ + step = STAGE3_STEP; + twiddleIncrement = 2*(*(uint16_t*)params->twiddleTable)/STAGE3_STEP; + twiddlePtr = ¶ms->twiddleTable[DSPLIB_TABLE_OFFSET]; + + /* If MPY32 is available save control context and set to fractional mode. */ +#if defined(__MSP430_HAS_MPY32__) + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; +#endif + + /* Stage 3 -> log2(step). */ + while (step <= length) { + /* Reset the twiddle angle index. */ + twiddleIndex = 0; + + for (i = 0; i < (step/2); i++) { + /* Perform butterfly operations on complex pairs. */ + for (j = i; j < length; j += step) { + srcPtr = src + j*2; + msp_cmplx_btfly_iq31(srcPtr, srcPtr + step, &twiddlePtr[twiddleIndex]); + } + + /* Increment twiddle table index. */ + twiddleIndex += twiddleIncrement; + } + /* Double the step size and halve the increment factor. */ + step *= 2; + twiddleIncrement = twiddleIncrement/2; + } + + /* Restore MPY32 control context. */ +#if defined(__MSP430_HAS_MPY32__) + MPY32CTL0 = ui16MPYState; +#endif + + return MSP_SUCCESS; +} + +/* + * Abstracted helper functions for a radix-2 butterfly operation. The following + * operation is performed with fixed scaling by two at each stage: + * A = A + coeff*B + * B = A - coeff*B + */ +static inline void msp_cmplx_btfly_iq31(int32_t *srcA, int32_t *srcB, const _q15 *coeff) +{ + /* Load coefficients. */ + _iq31 tempR = CMPLX_REAL(coeff); + _iq31 tempI = CMPLX_IMAG(coeff); + + /* Calculate real and imaginary parts of coeff*B. */ + __q15iq31cmpy(&tempR, &tempI, &CMPLX_REAL(srcB), &CMPLX_IMAG(srcB)); + + /* B = A - coeff*B */ + CMPLX_REAL(srcB) = CMPLX_REAL(srcA) - tempR; + CMPLX_IMAG(srcB) = CMPLX_IMAG(srcA) - tempI; + + /* A = A + coeff*B */ + CMPLX_REAL(srcA) = CMPLX_REAL(srcA) + tempR; + CMPLX_IMAG(srcA) = CMPLX_IMAG(srcA) + tempI; +} + +/* + * Simplified radix-2 butterfly operation for e^(-2*pi*(0/4)). This abstracted + * helper function takes advantage of the fact the the twiddle coefficients are + * positive and negative one for a multiplication by e^(-2*pi*(0/4)). The + * following operation is performed with fixed scaling by two at each stage: + * A = A + (1+0j)*B + * B = A - (1+0j)*B + */ +static inline void msp_cmplx_btfly_c0_iq31(int32_t *srcA, int32_t *srcB) +{ + int32_t tempR = CMPLX_REAL(srcB); + int32_t tempI = CMPLX_IMAG(srcB); + + /* B = A - (1+0j)*B */ + CMPLX_REAL(srcB) = CMPLX_REAL(srcA) - tempR; + CMPLX_IMAG(srcB) = CMPLX_IMAG(srcA) - tempI; + + /* A = A + (1+0j)*B */ + CMPLX_REAL(srcA) = CMPLX_REAL(srcA) + tempR; + CMPLX_IMAG(srcA) = CMPLX_IMAG(srcA) + tempI; +} + +/* + * Simplified radix-2 butterfly operation for e^(-2*pi*(1/4)). This abstracted + * helper function takes advantage of the fact the the twiddle coefficients are + * positive and negative one for a multiplication by e^(-2*pi*(1/4)). The + * following operation is performed with fixed scaling by two at each stage: + * A = A + (0-1j)*B + * B = A - (0-1j)*B + */ +static inline void msp_cmplx_btfly_c1_iq31(int32_t *srcA, int32_t *srcB) +{ + int32_t tempR = CMPLX_REAL(srcB); + int32_t tempI = CMPLX_IMAG(srcB); + + /* B = A - (0-1j)*B */ + CMPLX_REAL(srcB) = CMPLX_REAL(srcA) - tempI; + CMPLX_IMAG(srcB) = CMPLX_IMAG(srcA) + tempR; + + /* A = A + (0-1j)*B */ + CMPLX_REAL(srcA) = CMPLX_REAL(srcA) + tempI; + CMPLX_IMAG(srcA) = CMPLX_IMAG(srcA) - tempR; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_auto_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_auto_q15.c new file mode 100755 index 000000000..71fe5ea06 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_auto_q15.c @@ -0,0 +1,82 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place complex inverse DFT of the input signal using complex + * conjugate, the complex DFT and complex scaling. Auto scaling is performed + * such that this is the direct inverse of the forward FFT with auto scaling. + */ +msp_status msp_cmplx_ifft_auto_q15(const msp_cmplx_fft_q15_params *params, int16_t *src, uint16_t shift) +{ + uint16_t length; // src length + uint16_t resultShift; // complex fft result shift + msp_status status; // Status of the operations + msp_cmplx_conj_q15_params conjParams; // Complex conjugate params + msp_cmplx_fft_q15_params paramsCmplxFFT; // Complex FFT params + msp_cmplx_shift_q15_params paramsShift; // Complex shift params + + /* Initialize complex conjugate params structure. */ + conjParams.length = params->length; + + /* Take the complex conjugate of the input. */ + status = msp_cmplx_conj_q15(&conjParams, src, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform complex FFT on real source with scaling. */ + status = MAP_msp_cmplx_fft_auto_q15(¶msCmplxFFT, src, &resultShift); + if (status != MSP_SUCCESS) { + return status; + } + + /* Calculate necessary shift to complete the operation. */ + shift += resultShift; + length = params->length; + while (length > 1) { + shift--; + length >>= 1; + } + + /* Initialize complex shift parameters with conjugate enabled. */ + paramsShift.length = params->length; + paramsShift.shift = (int8_t)shift; + paramsShift.conjugate = true; + return msp_cmplx_shift_q15(¶msShift, src, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_fixed_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_fixed_q15.c new file mode 100755 index 000000000..601c4706c --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_fixed_q15.c @@ -0,0 +1,73 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place complex inverse DFT of the input signal using complex + * conjugate, the complex DFT and complex scaling. Fixed scaling is performed + * such that this is the direct inverse of the forward FFT with fixed scaling. + */ +msp_status msp_cmplx_ifft_fixed_q15(const msp_cmplx_fft_q15_params *params, int16_t *src) +{ + uint16_t resultShift; // complex fft result shift + msp_status status; // Status of the operations + msp_cmplx_conj_q15_params conjParams; // Complex conjugate params + msp_cmplx_fft_q15_params paramsCmplxFFT; // Complex FFT params + msp_cmplx_shift_q15_params paramsShift; // Complex shift params + + /* Initialize complex conjugate params structure. */ + conjParams.length = params->length; + + /* Take the complex conjugate of the input. */ + status = msp_cmplx_conj_q15(&conjParams, src, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform complex FFT on real source with scaling. */ + status = MAP_msp_cmplx_fft_auto_q15(¶msCmplxFFT, src, &resultShift); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex shift parameters with conjugate enabled. */ + paramsShift.length = params->length; + paramsShift.shift = (int8_t)resultShift; + paramsShift.conjugate = true; + return msp_cmplx_shift_q15(¶msShift, src, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_iq31.c new file mode 100755 index 000000000..a9e1d8e24 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_cmplx_ifft_iq31.c @@ -0,0 +1,110 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place complex inverse DFT of the input signal using complex + * conjugate, the complex DFT and complex scaling. Fixed scaling is performed + * such that this is the direct inverse of the forward FFT. + */ +msp_status msp_cmplx_ifft_iq31(const msp_cmplx_fft_iq31_params *params, int32_t *src) +{ + uint16_t index; // min/max index + uint16_t length; // vector length + int16_t preShift; // pre-complex fft shift + int16_t postShift; // post-complex fft shift + int32_t maximum; // vector maximum + int32_t minimum; // vector minimum + msp_status status; // Status of the operations + msp_max_iq31_params paramsMax; // Maximum params + msp_min_iq31_params paramsMin; // Minimum params + msp_cmplx_fft_iq31_params paramsCmplxFFT; // Complex FFT params + msp_cmplx_shift_iq31_params paramsShift; // Complex shift params + + /* Calculate the necessary result scale based on length. */ + preShift = -1; + length = params->length; + while (length > 2) { + preShift--; + length >>= 1; + } + + /* Find maximum input to determine scaling order. */ + paramsMax.length = params->length << 1; + status = msp_max_iq31(¶msMax, src, &maximum, &index); + if (status != MSP_SUCCESS) { + return status; + } + + /* Find minimum input to determine scaling order. */ + paramsMin.length = params->length << 1; + status = msp_min_iq31(¶msMin, src, &minimum, &index); + if (status != MSP_SUCCESS) { + return status; + } + + /* Determine scaling order based on min/max. */ + postShift = 0; + minimum = minimum < -maximum ? minimum : -maximum; + while (minimum < (INT32_MIN/2)) { + minimum <<= 1; + preShift++; + postShift--; + } + + /* Prescale the complex fft input with complex conjugate. */ + paramsShift.length = params->length; + paramsShift.shift = preShift; + paramsShift.conjugate = true; + status = msp_cmplx_shift_iq31(¶msShift, src, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform N/2 complex FFT on real source. */ + status = MAP_msp_cmplx_fft_iq31(¶msCmplxFFT, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex shift parameters with conjugate enabled. */ + paramsShift.length = params->length; + paramsShift.shift = postShift; + paramsShift.conjugate = true; + return msp_cmplx_shift_iq31(¶msShift, src, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_auto_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_auto_q15.c new file mode 100755 index 000000000..3d6b5ceb6 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_auto_q15.c @@ -0,0 +1,63 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place real DFT of the real input signal using a complex DFT of + * size N/2 and a split operation to obtain a complex output with length N/2. + * No fixed scaling is performed. + */ +msp_status msp_fft_auto_q15(const msp_fft_q15_params *params, int16_t *src, uint16_t *shift) +{ + msp_status status; // Status of the operations + msp_split_q15_params paramsSplit; // Split operation params + msp_cmplx_fft_q15_params paramsCmplxFFT; // Complex FFT params + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length >> 1; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform N/2 complex FFT on real source without scaling. */ + status = MAP_msp_cmplx_fft_auto_q15(¶msCmplxFFT, src, shift); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize split operation params structure. */ + paramsSplit.length = params->length; + paramsSplit.twiddleTable = params->twiddleTable; + + /* Perform the last stage split operation to obtain N/2 complex FFT results. */ + return msp_split_q15(¶msSplit, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_fixed_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_fixed_q15.c new file mode 100755 index 000000000..4bc65c7e2 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_fixed_q15.c @@ -0,0 +1,63 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place real DFT of the real input signal using a complex DFT of + * size N/2 and a split operation to obtain a complex output with length N/2. + * Fixed scaling by 2 is performed at each stage. + */ +msp_status msp_fft_fixed_q15(const msp_fft_q15_params *params, int16_t *src) +{ + msp_status status; // Status of the operations + msp_split_q15_params paramsSplit; // Split operation params + msp_cmplx_fft_q15_params paramsCmplxFFT; // Complex FFT params + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length >> 1; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform N/2 complex FFT on real source with scaling. */ + status = MAP_msp_cmplx_fft_fixed_q15(¶msCmplxFFT, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize split operation params structure. */ + paramsSplit.length = params->length; + paramsSplit.twiddleTable = params->twiddleTable; + + /* Perform the last stage split operation to obtain N/2 complex FFT results. */ + return msp_split_q15(¶msSplit, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_iq31.c new file mode 100755 index 000000000..5350c0316 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_fft_iq31.c @@ -0,0 +1,63 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place real DFT of the real input signal using a complex DFT of + * size N/2 and a split operation to obtain a complex output with length N/2. + * Fixed scaling by 2 is performed at each stage. + */ +msp_status msp_fft_iq31(const msp_fft_iq31_params *params, int32_t *src) +{ + msp_status status; // Status of the operations + msp_split_iq31_params paramsSplit; // Split operation params + msp_cmplx_fft_iq31_params paramsCmplxFFT; // Complex FFT params + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length >> 1; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform N/2 complex FFT on real source with scaling. */ + status = MAP_msp_cmplx_fft_iq31(¶msCmplxFFT, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize split operation params structure. */ + paramsSplit.length = params->length; + paramsSplit.twiddleTable = params->twiddleTable; + + /* Perform the last stage split operation to obtain N/2 complex FFT results. */ + return msp_split_iq31(¶msSplit, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_auto_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_auto_q15.c new file mode 100755 index 000000000..14a420466 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_auto_q15.c @@ -0,0 +1,94 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place real inverse DFT of the complex input signal using a + * split operation and a complex DFT of size N/2 and to obtain a real output + * with length N. Automatic scaling is performed such that this is the direct + * inverse of the forward FFT with auto scaling. + */ +msp_status msp_ifft_auto_q15(const msp_fft_q15_params *params, int16_t *src, uint16_t shift) +{ + uint16_t length; // src length + uint16_t resultShift; // complex fft result shift + msp_status status; // Status of the operations + msp_split_q15_params paramsSplit; // Split operation params + msp_cmplx_conj_q15_params conjParams; // Complex conjugate params + msp_cmplx_fft_q15_params paramsCmplxFFT; // Complex FFT params + msp_cmplx_shift_q15_params paramsShift; // Complex shift params + + /* Initialize complex conjugate params structure. */ + conjParams.length = params->length/2; + + /* Take the complex conjugate of the input. */ + status = msp_cmplx_conj_q15(&conjParams, src, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize split operation params structure. */ + paramsSplit.length = params->length; + paramsSplit.twiddleTable = params->twiddleTable; + + /* Perform the last stage split operation to obtain N/2 complex FFT results. */ + status = msp_split_q15(¶msSplit, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length >> 1; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform N/2 complex FFT on real source with scaling. */ + status = MAP_msp_cmplx_fft_auto_q15(¶msCmplxFFT, src, &resultShift); + if (status != MSP_SUCCESS) { + return status; + } + + /* Calculate necessary shift to complete the operation. */ + shift += resultShift; + length = params->length; + while (length > 2) { + shift--; + length >>= 1; + } + + /* Initialize complex shift parameters with conjugate enabled. */ + paramsShift.length = params->length >> 1; + paramsShift.shift = (int8_t)shift; + paramsShift.conjugate = true; + return msp_cmplx_shift_q15(¶msShift, src, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_fixed_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_fixed_q15.c new file mode 100755 index 000000000..b13132fe0 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_fixed_q15.c @@ -0,0 +1,85 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place real inverse DFT of the complex input signal using a + * split operation and a complex DFT of size N/2 and to obtain a real output + * with length N. Fixed scaling is performed such that this is the direct + * inverse of the forward FFT with fixed scaling. + */ +msp_status msp_ifft_fixed_q15(const msp_fft_q15_params *params, int16_t *src) +{ + uint16_t resultShift; // complex fft result shift + msp_status status; // Status of the operations + msp_split_q15_params paramsSplit; // Split operation params + msp_cmplx_conj_q15_params conjParams; // Complex conjugate params + msp_cmplx_fft_q15_params paramsCmplxFFT; // Complex FFT params + msp_cmplx_shift_q15_params paramsShift; // Complex shift params + + /* Initialize complex conjugate params structure. */ + conjParams.length = params->length/2; + + /* Take the complex conjugate of the input. */ + status = msp_cmplx_conj_q15(&conjParams, src, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize split operation params structure. */ + paramsSplit.length = params->length; + paramsSplit.twiddleTable = params->twiddleTable; + + /* Perform the last stage split operation to obtain N/2 complex FFT results. */ + status = msp_split_q15(¶msSplit, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length >> 1; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform N/2 complex FFT on real source with scaling. */ + status = MAP_msp_cmplx_fft_auto_q15(¶msCmplxFFT, src, &resultShift); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex shift parameters with conjugate enabled. */ + paramsShift.length = params->length >> 1; + paramsShift.shift = (int8_t)resultShift; + paramsShift.conjugate = true; + return msp_cmplx_shift_q15(¶msShift, src, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_iq31.c new file mode 100755 index 000000000..1116a3213 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_ifft_iq31.c @@ -0,0 +1,121 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform an in-place complex inverse DFT of the input signal using complex + * conjugate, the complex DFT and complex scaling. Fixed scaling is performed + * such that this is the direct inverse of the forward FFT. + */ +msp_status msp_ifft_iq31(const msp_fft_iq31_params *params, int32_t *src) +{ + uint16_t index; // min/max index + uint16_t length; // vector length + int16_t preShift; // pre-complex fft shift + int16_t postShift; // post-complex fft shift + int32_t maximum; // vector maximum + int32_t minimum; // vector minimum + msp_status status; // Status of the operations + msp_max_iq31_params paramsMax; // Maximum params + msp_min_iq31_params paramsMin; // Minimum params + msp_split_iq31_params paramsSplit; // Split operation params + msp_cmplx_fft_iq31_params paramsCmplxFFT; // Complex FFT params + msp_cmplx_shift_iq31_params paramsShift; // Complex shift params + + /* Calculate the necessary result scale based on length. */ + preShift = -2; + length = params->length; + while (length > 2) { + preShift--; + length >>= 1; + } + + /* Find maximum input to determine scaling order. */ + paramsMax.length = params->length; + status = msp_max_iq31(¶msMax, src, &maximum, &index); + if (status != MSP_SUCCESS) { + return status; + } + + /* Find minimum input to determine scaling order. */ + paramsMin.length = params->length; + status = msp_min_iq31(¶msMin, src, &minimum, &index); + if (status != MSP_SUCCESS) { + return status; + } + + /* Determine scaling order based on min/max results. */ + postShift = 0; + minimum = minimum < -maximum ? minimum : -maximum; + while (minimum > (INT32_MIN/2)) { + minimum <<= 1; + preShift++; + postShift--; + } + + /* Prescale the complex fft input with complex conjugate. */ + paramsShift.length = params->length >> 1; + paramsShift.shift = preShift; + paramsShift.conjugate = true; + status = msp_cmplx_shift_iq31(¶msShift, src, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize split operation params structure. */ + paramsSplit.length = params->length; + paramsSplit.twiddleTable = params->twiddleTable; + + /* Perform the last stage split operation to obtain N/2 complex FFT results. */ + status = msp_split_iq31(¶msSplit, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex FFT params structure. */ + paramsCmplxFFT.length = params->length >> 1; + paramsCmplxFFT.bitReverse = params->bitReverse; + paramsCmplxFFT.twiddleTable = params->twiddleTable; + + /* Perform N/2 complex FFT on real source. */ + status = MAP_msp_cmplx_fft_iq31(¶msCmplxFFT, src); + if (status != MSP_SUCCESS) { + return status; + } + + /* Initialize complex shift parameters with conjugate enabled. */ + paramsShift.length = params->length >> 1; + paramsShift.shift = postShift; + paramsShift.conjugate = true; + return msp_cmplx_shift_iq31(¶msShift, src, src); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_split_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_split_iq31.c new file mode 100755 index 000000000..dc63c1e39 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_split_iq31.c @@ -0,0 +1,274 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_split_iq31(const msp_split_iq31_params *params, int32_t *src) +{ + uint16_t i; + uint16_t log2Size; + uint16_t length; + msp_status status; + MSP_LEA_FFTLONG_PARAMS *leaParams; + + /* Get vector length parameter. */ + length = params->length; + + /* Calculate log2Size parameter. */ + i = length; + log2Size = 0; + while (i > 1) { + log2Size++; + i >>= 1; + } + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, length))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FFTLONG_PARAMS structure. */ + leaParams = (MSP_LEA_FFTLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FFTLONG_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FFTLONG_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->log2Size = log2Size; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__FFTLONG command. */ + msp_lea_invokeCommand(LEACMD__FFTLONG); + + /* Free MSP_LEA_FFTLONG_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FFTLONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +/* + * This function performs the last stage of a real FFT of size M in place. + * Before this step is performed, a size M/2 complex FFT must be performed + * on the input data with bit reversal. This algorithm has been optimized + * to use a single coefficient lookup table and a reduced number of multiply + * operations. The complex result G(k) where k = 0,1,2...N-1 and N = M/2 is + * calculated as follows: + * + * G(k) = 0.5*(X(k) + X*(N-k)) - 0.5*j*(e^-j2*pi*k/2N)*(X(k) - X*(N-k)) + * + * This can be optimized by calculating G(N-k) in parallel using the following + * simplification: + * + * G(N-k) = 0.5*(X(N-k) + X*(N-(N-k))) - 0.5*j*(e^-j2*pi*(N-k)/2N)*(X(N-k) - X*(N-(N-k))) + * G(N-k) = 0.5*(X(N-k) + X*(k)) - 0.5*j*(e^-j2*pi*(N-k)/2N)*(X(N-k) - X*(k)) + * G(N-k) = 0.5*(X(N-k) + X*(k)) - 0.5*j*-(e^-j2*pi*(N-k)/2N)*(X*(k) - X(N-k)) + * G(N-k) = 0.5*(X(k) + X*(N-k))* - 0.5*j*((e^-j2*pi*k/2N)*(X(k) - X*(N-k)))* + * + * The common components of G(k) and G(N-k) can be calculated once as local + * variables A and B: + * + * A(k) = 0.5*(X(k) + X*(N-k)) + * B(k) = 0.5*(e^-j2*pi*k/2N)*(X(k) - X*(N-k)) + * + * Finally, performing substitutions to the G(k) and G(N-k) equations yields + * the following optimized equations: + * + * G(k) = A(k) - j*B(k) + * G(N-k) = A*(k) - j*B*(k) + * + * Reference: http://www.ti.com/lit/an/spra291/spra291.pdf + */ +msp_status msp_split_iq31(const msp_split_iq31_params *params, int32_t *src) +{ + uint16_t length; // src length + uint16_t tableLength; // Coefficient table length + uint16_t coeffOffset; // Coefficient table increment + int32_t aR; // Temp variable + int32_t aI; // Temp variable + int32_t bR; // Temp variable + int32_t bI; // Temp variable + int32_t cR; // Temp variable + int32_t cI; // Temp variable + int32_t *srcPtrK; // Source pointer to X(k) + int32_t *srcPtrNK; // Source pointer to X(N-k) + const int16_t *coeffPtr; // Coefficient pointer + + /* Save input length to local. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the provided table is the correct length. */ + if (*(uint16_t *)params->twiddleTable < length) { + return MSP_TABLE_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* + * Calculate the first result bin (DC component). + * + * X(N) = X(0) + * G(0) = 0.5*(X(0) + X*(0)) - j*0.5*(e^-j*0)*(X(0) - X*(0)) + * G(0) = Xr(0) + Xi(0) + */ + CMPLX_REAL(src) = (CMPLX_REAL(src) + CMPLX_IMAG(src)) << 1; + CMPLX_IMAG(src) = 0; + + /* Initialize Src(k) and Src(N/2-k) pointers when k=1. */ + srcPtrK = src + CMPLX_INCREMENT; + srcPtrNK = src + length - CMPLX_INCREMENT; + + /* Calculate coefficient table offset. */ + coeffOffset = 2; + tableLength = *(uint16_t *)params->twiddleTable; + while (length < tableLength) { + coeffOffset *= 2; + length *= 2; + } + + /* Initialize coefficient pointer to index k=1. */ + coeffPtr = ¶ms->twiddleTable[DSPLIB_TABLE_OFFSET] + coeffOffset; + + /* + * Initialize length of split operations to perform. G(k) and G(N/2-k) are + * calculated in the same loop iteration so only half of the N/2 iterations + * are required, N/4. The last iteration where k = N/2-k will be calculated + * separately. + */ + length = (params->length >> 2) - 1; + + /* If MPY32 is available save control context and set to fractional mode. */ +#if defined(__MSP430_HAS_MPY32__) + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; +#endif + + /* Loop through and perform all of the split operations. */ + while(length--) { + /* Calculate X(k) - X*(N-k) to local temporary variables. */ + bR = CMPLX_REAL(srcPtrK) - CMPLX_REAL(srcPtrNK); + bI = CMPLX_IMAG(srcPtrK) + CMPLX_IMAG(srcPtrNK); + + /* B(k) = 0.5*(e^-j2*pi*k/2N)*(X(k) - X(N-k)) */ + cR = CMPLX_REAL(coeffPtr); + cI = CMPLX_IMAG(coeffPtr); + __q15iq31cmpy(&cR, &cI, &bR, &bI); + bR = cR; bI = cI; + + /* + * Ar(k) = 0.5*(Xr(k) + Xr(N-k)) + * Ai(k) = 0.5*(Xi(k) - Xi(N-k)) + */ + aR = (CMPLX_REAL(srcPtrK) + CMPLX_REAL(srcPtrNK)); + aI = (CMPLX_IMAG(srcPtrK) - CMPLX_IMAG(srcPtrNK)); + + /* + * Gr(k) = Ar(k) + Bi(k) + * Gi(k) = Ai(k) - Br(k) + * Gr(N-k) = Ar(k) - Bi(k) + * Gi(N-k) = -(Ai(k) + Br(k)) + */ + CMPLX_REAL(srcPtrK) = aR + bI; + CMPLX_IMAG(srcPtrK) = aI - bR; + CMPLX_REAL(srcPtrNK) = aR - bI; + CMPLX_IMAG(srcPtrNK) = -(aI + bR); + + /* Update pointers. */ + srcPtrK += CMPLX_INCREMENT; + srcPtrNK -= CMPLX_INCREMENT; + coeffPtr += coeffOffset; + } + + /* Restore MPY32 control context. */ +#if defined(__MSP430_HAS_MPY32__) + MPY32CTL0 = ui16MPYState; +#endif + + /* + * Calculate the last result bin where k = N/2-k. + * + * X(k) = X(N-k) + * G(k) = 0.5*(X(k) + X*(k)) - j*0.5*(e^-j*pi/2)*(X(k) - X*(k)) + * G(k) = 0.5(2*Xr(k)) - j*0.5*(-j)*(2*j*Xi(k)) + * G(k) = Xr(k) - j*Xi(k) + */ + CMPLX_REAL(srcPtrK) = CMPLX_REAL(srcPtrK) << 1; + CMPLX_IMAG(srcPtrK) = -(CMPLX_IMAG(srcPtrK) << 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_split_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_split_q15.c new file mode 100755 index 000000000..dc036006c --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_split_q15.c @@ -0,0 +1,273 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_split_q15(const msp_split_q15_params *params, int16_t *src) +{ + uint16_t i; + uint16_t log2Size; + uint16_t length; + msp_status status; + MSP_LEA_FFT_PARAMS *leaParams; + + /* Get vector length parameter. */ + length = params->length; + + /* Calculate log2Size parameter. */ + i = length; + log2Size = 0; + while (i > 1) { + log2Size++; + i >>= 1; + } + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, length))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_FFT_PARAMS structure. */ + leaParams = (MSP_LEA_FFT_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_FFT_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_FFT_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->log2Size = log2Size; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__FFT command. */ + msp_lea_invokeCommand(LEACMD__FFT); + + /* Free MSP_LEA_FFT_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_FFT_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +/* + * This function performs the last stage of a real FFT of size M in place. + * Before this step is performed, a size M/2 complex FFT must be performed + * on the input data with bit reversal. This algorithm has been optimized + * to use a single coefficient lookup table and a reduced number of multiply + * operations. The complex result G(k) where k = 0,1,2...N-1 and N = M/2 is + * calculated as follows: + * + * G(k) = 0.5*(X(k) + X*(N-k)) - 0.5*j*(e^-j2*pi*k/2N)*(X(k) - X*(N-k)) + * + * This can be optimized by calculating G(N-k) in parallel using the following + * simplification: + * + * G(N-k) = 0.5*(X(N-k) + X*(N-(N-k))) - 0.5*j*(e^-j2*pi*(N-k)/2N)*(X(N-k) - X*(N-(N-k))) + * G(N-k) = 0.5*(X(N-k) + X*(k)) - 0.5*j*(e^-j2*pi*(N-k)/2N)*(X(N-k) - X*(k)) + * G(N-k) = 0.5*(X(N-k) + X*(k)) - 0.5*j*-(e^-j2*pi*(N-k)/2N)*(X*(k) - X(N-k)) + * G(N-k) = 0.5*(X(k) + X*(N-k))* - 0.5*j*((e^-j2*pi*k/2N)*(X(k) - X*(N-k)))* + * + * The common components of G(k) and G(N-k) can be calculated once as local + * variables A and B: + * + * A(k) = 0.5*(X(k) + X*(N-k)) + * B(k) = 0.5*(e^-j2*pi*k/2N)*(X(k) - X*(N-k)) + * + * Finally, performing substitutions to the G(k) and G(N-k) equations yields + * the following optimized equations: + * + * G(k) = A(k) - j*B(k) + * G(N-k) = A*(k) - j*B*(k) + * + * Reference: http://www.ti.com/lit/an/spra291/spra291.pdf + */ +msp_status msp_split_q15(const msp_split_q15_params *params, int16_t *src) +{ + uint16_t length; // src length + uint16_t tableLength; // Coefficient table length + uint16_t coeffOffset; // Coefficient table increment + int16_t aR; // Temp variable + int16_t aI; // Temp variable + int16_t bR; // Temp variable + int16_t bI; // Temp variable + int16_t cR; // Temp variable + int16_t cI; // Temp variable + int16_t *srcPtrK; // Source pointer to X(k) + int16_t *srcPtrNK; // Source pointer to X(N-k) + const int16_t *coeffPtr; // Coefficient pointer + + /* Save input length to local. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the length is a power of two. */ + if ((length & (length-1))) { + return MSP_SIZE_ERROR; + } + + /* Check that the provided table is the correct length. */ + if (*(uint16_t *)params->twiddleTable < length) { + return MSP_TABLE_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* + * Calculate the first result bin (DC component). + * + * X(N) = X(0) + * G(0) = 0.5*(X(0) + X*(0)) - j*0.5*(e^-j*0)*(X(0) - X*(0)) + * G(0) = Xr(0) + Xi(0) + */ + CMPLX_REAL(src) = CMPLX_REAL(src) + CMPLX_IMAG(src); + CMPLX_IMAG(src) = 0; + + /* Initialize Src(k) and Src(N/2-k) pointers when k=1. */ + srcPtrK = src + CMPLX_INCREMENT; + srcPtrNK = src + length - CMPLX_INCREMENT; + + /* Calculate coefficient table offset. */ + coeffOffset = 2; + tableLength = *(uint16_t *)params->twiddleTable; + while (length < tableLength) { + coeffOffset *= 2; + length *= 2; + } + + /* Initialize coefficient pointer to index k=1. */ + coeffPtr = ¶ms->twiddleTable[DSPLIB_TABLE_OFFSET] + coeffOffset; + + /* + * Initialize length of split operations to perform. G(k) and G(N/2-k) are + * calculated in the same loop iteration so only half of the N/2 iterations + * are required, N/4. The last iteration where k = N/2-k will be calculated + * separately. + */ + length = (params->length >> 2) - 1; + + /* If MPY32 is available save control context and set to fractional mode. */ +#if defined(__MSP430_HAS_MPY32__) + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; +#endif + + /* Loop through and perform all of the split operations. */ + while(length--) { + /* Calculate X(k) - X*(N-k) to local temporary variables. */ + bR = CMPLX_REAL(srcPtrK) - CMPLX_REAL(srcPtrNK); + bI = CMPLX_IMAG(srcPtrK) + CMPLX_IMAG(srcPtrNK); + + /* B(k) = 0.5*(e^-j2*pi*k/2N)*(X(k) - X(N-k)) */ + cR = CMPLX_REAL(coeffPtr) >> 1; + cI = CMPLX_IMAG(coeffPtr) >> 1; + __q15cmpy(&bR, &bI, &cR, &cI); + + /* + * Ar(k) = 0.5*(Xr(k) + Xr(N-k)) + * Ai(k) = 0.5*(Xi(k) - Xi(N-k)) + */ + aR = (CMPLX_REAL(srcPtrK) + CMPLX_REAL(srcPtrNK)) >> 1; + aI = (CMPLX_IMAG(srcPtrK) - CMPLX_IMAG(srcPtrNK)) >> 1; + + /* + * Gr(k) = Ar(k) + Bi(k) + * Gi(k) = Ai(k) - Br(k) + * Gr(N-k) = Ar(k) - Bi(k) + * Gi(N-k) = -(Ai(k) + Br(k)) + */ + CMPLX_REAL(srcPtrK) = aR + bI; + CMPLX_IMAG(srcPtrK) = aI - bR; + CMPLX_REAL(srcPtrNK) = aR - bI; + CMPLX_IMAG(srcPtrNK) = -(aI + bR); + + /* Update pointers. */ + srcPtrK += CMPLX_INCREMENT; + srcPtrNK -= CMPLX_INCREMENT; + coeffPtr += coeffOffset; + } + + /* Restore MPY32 control context. */ +#if defined(__MSP430_HAS_MPY32__) + MPY32CTL0 = ui16MPYState; +#endif + + /* + * Calculate the last result bin where k = N/2-k. + * + * X(k) = X(N-k) + * G(k) = 0.5*(X(k) + X*(k)) - j*0.5*(e^-j*pi/2)*(X(k) - X*(k)) + * G(k) = 0.5(2*Xr(k)) - j*0.5*(-j)*(2*j*Xi(k)) + * G(k) = Xr(k) - j*Xi(k) + */ + CMPLX_REAL(srcPtrK) = CMPLX_REAL(srcPtrK); + CMPLX_IMAG(srcPtrK) = -CMPLX_IMAG(srcPtrK); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_transform_tables.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_transform_tables.c new file mode 100755 index 000000000..5eb1ad017 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/transform/msp_transform_tables.c @@ -0,0 +1,1161 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if !defined(MSP_USE_LEA) + +/* + * Bit reversal lookup table. + */ +const uint8_t msp_cmplx_bitrev_table_ui8[256] = { + 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, + 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, + 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, + 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, + 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4, + 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, + 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC, + 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, + 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2, + 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, + 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, + 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, + 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, + 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6, + 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, + 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE, + 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, + 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1, + 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, + 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9, + 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, + 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5, + 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, + 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, + 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, + 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, + 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, + 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, + 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7, + 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, + 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF, + 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF +}; + +/* + * FFT twiddle factor table for length of 16. + */ +const _q15 msp_cmplx_twiddle_table_16_q15[DSPLIB_TABLE_OFFSET+16] = { + 0x0010, 0x0000, + 0x7FFF, 0x0000, 0x7642, 0xCF04, 0x5A82, 0xA57E, 0x30FC, 0x89BE, + 0x0000, 0x8001, 0xCF04, 0x89BE, 0xA57E, 0xA57E, 0x89BE, 0xCF04 +}; + +/* + * FFT twiddle factor table for length of 32. + */ +const _q15 msp_cmplx_twiddle_table_32_q15[DSPLIB_TABLE_OFFSET+32] = { + 0x0020, 0x0000, + 0x7FFF, 0x0000, 0x7D8A, 0xE707, 0x7642, 0xCF04, 0x6A6E, 0xB8E3, + 0x5A82, 0xA57E, 0x471D, 0x9592, 0x30FC, 0x89BE, 0x18F9, 0x8276, + 0x0000, 0x8001, 0xE707, 0x8276, 0xCF04, 0x89BE, 0xB8E3, 0x9592, + 0xA57E, 0xA57E, 0x9592, 0xB8E3, 0x89BE, 0xCF04, 0x8276, 0xE707 +}; + +/* + * FFT twiddle factor table for length of 64. + */ +const _q15 msp_cmplx_twiddle_table_64_q15[DSPLIB_TABLE_OFFSET+64] = { + 0x0040, 0x0000, + 0x7FFF, 0x0000, 0x7F62, 0xF374, 0x7D8A, 0xE707, 0x7A7D, 0xDAD8, + 0x7642, 0xCF04, 0x70E3, 0xC3A9, 0x6A6E, 0xB8E3, 0x62F2, 0xAECC, + 0x5A82, 0xA57E, 0x5134, 0x9D0E, 0x471D, 0x9592, 0x3C57, 0x8F1D, + 0x30FC, 0x89BE, 0x2528, 0x8583, 0x18F9, 0x8276, 0x0C8C, 0x809E, + 0x0000, 0x8001, 0xF374, 0x809E, 0xE707, 0x8276, 0xDAD8, 0x8583, + 0xCF04, 0x89BE, 0xC3A9, 0x8F1D, 0xB8E3, 0x9592, 0xAECC, 0x9D0E, + 0xA57E, 0xA57E, 0x9D0E, 0xAECC, 0x9592, 0xB8E3, 0x8F1D, 0xC3A9, + 0x89BE, 0xCF04, 0x8583, 0xDAD8, 0x8276, 0xE707, 0x809E, 0xF374 +}; + +/* + * FFT twiddle factor table for length of 128. + */ +const _q15 msp_cmplx_twiddle_table_128_q15[DSPLIB_TABLE_OFFSET+128] = { + 0x0080, 0x0000, + 0x7FFF, 0x0000, 0x7FD9, 0xF9B8, 0x7F62, 0xF374, 0x7E9D, 0xED38, + 0x7D8A, 0xE707, 0x7C2A, 0xE0E6, 0x7A7D, 0xDAD8, 0x7885, 0xD4E1, + 0x7642, 0xCF04, 0x73B6, 0xC946, 0x70E3, 0xC3A9, 0x6DCA, 0xBE32, + 0x6A6E, 0xB8E3, 0x66D0, 0xB3C0, 0x62F2, 0xAECC, 0x5ED7, 0xAA0A, + 0x5A82, 0xA57E, 0x55F6, 0xA129, 0x5134, 0x9D0E, 0x4C40, 0x9930, + 0x471D, 0x9592, 0x41CE, 0x9236, 0x3C57, 0x8F1D, 0x36BA, 0x8C4A, + 0x30FC, 0x89BE, 0x2B1F, 0x877B, 0x2528, 0x8583, 0x1F1A, 0x83D6, + 0x18F9, 0x8276, 0x12C8, 0x8163, 0x0C8C, 0x809E, 0x0648, 0x8027, + 0x0000, 0x8001, 0xF9B8, 0x8027, 0xF374, 0x809E, 0xED38, 0x8163, + 0xE707, 0x8276, 0xE0E6, 0x83D6, 0xDAD8, 0x8583, 0xD4E1, 0x877B, + 0xCF04, 0x89BE, 0xC946, 0x8C4A, 0xC3A9, 0x8F1D, 0xBE32, 0x9236, + 0xB8E3, 0x9592, 0xB3C0, 0x9930, 0xAECC, 0x9D0E, 0xAA0A, 0xA129, + 0xA57E, 0xA57E, 0xA129, 0xAA0A, 0x9D0E, 0xAECC, 0x9930, 0xB3C0, + 0x9592, 0xB8E3, 0x9236, 0xBE32, 0x8F1D, 0xC3A9, 0x8C4A, 0xC946, + 0x89BE, 0xCF04, 0x877B, 0xD4E1, 0x8583, 0xDAD8, 0x83D6, 0xE0E6, + 0x8276, 0xE707, 0x8163, 0xED38, 0x809E, 0xF374, 0x8027, 0xF9B8 +}; + +/* + * FFT twiddle factor table for length of 256. + */ +const _q15 msp_cmplx_twiddle_table_256_q15[DSPLIB_TABLE_OFFSET+256] = { + 0x0100, 0x0000, + 0x7FFF, 0x0000, 0x7FF6, 0xFCDC, 0x7FD9, 0xF9B8, 0x7FA7, 0xF695, + 0x7F62, 0xF374, 0x7F0A, 0xF055, 0x7E9D, 0xED38, 0x7E1E, 0xEA1E, + 0x7D8A, 0xE707, 0x7CE4, 0xE3F4, 0x7C2A, 0xE0E6, 0x7B5D, 0xDDDC, + 0x7A7D, 0xDAD8, 0x798A, 0xD7D9, 0x7885, 0xD4E1, 0x776C, 0xD1EF, + 0x7642, 0xCF04, 0x7505, 0xCC21, 0x73B6, 0xC946, 0x7255, 0xC673, + 0x70E3, 0xC3A9, 0x6F5F, 0xC0E9, 0x6DCA, 0xBE32, 0x6C24, 0xBB85, + 0x6A6E, 0xB8E3, 0x68A7, 0xB64C, 0x66D0, 0xB3C0, 0x64E9, 0xB140, + 0x62F2, 0xAECC, 0x60EC, 0xAC65, 0x5ED7, 0xAA0A, 0x5CB4, 0xA7BD, + 0x5A82, 0xA57E, 0x5843, 0xA34C, 0x55F6, 0xA129, 0x539B, 0x9F14, + 0x5134, 0x9D0E, 0x4EC0, 0x9B17, 0x4C40, 0x9930, 0x49B4, 0x9759, + 0x471D, 0x9592, 0x447B, 0x93DC, 0x41CE, 0x9236, 0x3F17, 0x90A1, + 0x3C57, 0x8F1D, 0x398D, 0x8DAB, 0x36BA, 0x8C4A, 0x33DF, 0x8AFB, + 0x30FC, 0x89BE, 0x2E11, 0x8894, 0x2B1F, 0x877B, 0x2827, 0x8676, + 0x2528, 0x8583, 0x2224, 0x84A3, 0x1F1A, 0x83D6, 0x1C0C, 0x831C, + 0x18F9, 0x8276, 0x15E2, 0x81E2, 0x12C8, 0x8163, 0x0FAB, 0x80F6, + 0x0C8C, 0x809E, 0x096B, 0x8059, 0x0648, 0x8027, 0x0324, 0x800A, + 0x0000, 0x8001, 0xFCDC, 0x800A, 0xF9B8, 0x8027, 0xF695, 0x8059, + 0xF374, 0x809E, 0xF055, 0x80F6, 0xED38, 0x8163, 0xEA1E, 0x81E2, + 0xE707, 0x8276, 0xE3F4, 0x831C, 0xE0E6, 0x83D6, 0xDDDC, 0x84A3, + 0xDAD8, 0x8583, 0xD7D9, 0x8676, 0xD4E1, 0x877B, 0xD1EF, 0x8894, + 0xCF04, 0x89BE, 0xCC21, 0x8AFB, 0xC946, 0x8C4A, 0xC673, 0x8DAB, + 0xC3A9, 0x8F1D, 0xC0E9, 0x90A1, 0xBE32, 0x9236, 0xBB85, 0x93DC, + 0xB8E3, 0x9592, 0xB64C, 0x9759, 0xB3C0, 0x9930, 0xB140, 0x9B17, + 0xAECC, 0x9D0E, 0xAC65, 0x9F14, 0xAA0A, 0xA129, 0xA7BD, 0xA34C, + 0xA57E, 0xA57E, 0xA34C, 0xA7BD, 0xA129, 0xAA0A, 0x9F14, 0xAC65, + 0x9D0E, 0xAECC, 0x9B17, 0xB140, 0x9930, 0xB3C0, 0x9759, 0xB64C, + 0x9592, 0xB8E3, 0x93DC, 0xBB85, 0x9236, 0xBE32, 0x90A1, 0xC0E9, + 0x8F1D, 0xC3A9, 0x8DAB, 0xC673, 0x8C4A, 0xC946, 0x8AFB, 0xCC21, + 0x89BE, 0xCF04, 0x8894, 0xD1EF, 0x877B, 0xD4E1, 0x8676, 0xD7D9, + 0x8583, 0xDAD8, 0x84A3, 0xDDDC, 0x83D6, 0xE0E6, 0x831C, 0xE3F4, + 0x8276, 0xE707, 0x81E2, 0xEA1E, 0x8163, 0xED38, 0x80F6, 0xF055, + 0x809E, 0xF374, 0x8059, 0xF695, 0x8027, 0xF9B8, 0x800A, 0xFCDC +}; + +/* + * FFT twiddle factor table for length of 512. + */ +const _q15 msp_cmplx_twiddle_table_512_q15[DSPLIB_TABLE_OFFSET+512] = { + 0x0200, 0x0000, + 0x7FFF, 0x0000, 0x7FFE, 0xFE6E, 0x7FF6, 0xFCDC, 0x7FEA, 0xFB4A, + 0x7FD9, 0xF9B8, 0x7FC2, 0xF827, 0x7FA7, 0xF695, 0x7F87, 0xF505, + 0x7F62, 0xF374, 0x7F38, 0xF1E4, 0x7F0A, 0xF055, 0x7ED6, 0xEEC6, + 0x7E9D, 0xED38, 0x7E60, 0xEBAB, 0x7E1E, 0xEA1E, 0x7DD6, 0xE892, + 0x7D8A, 0xE707, 0x7D3A, 0xE57D, 0x7CE4, 0xE3F4, 0x7C89, 0xE26D, + 0x7C2A, 0xE0E6, 0x7BC6, 0xDF61, 0x7B5D, 0xDDDC, 0x7AEF, 0xDC59, + 0x7A7D, 0xDAD8, 0x7A06, 0xD958, 0x798A, 0xD7D9, 0x790A, 0xD65C, + 0x7885, 0xD4E1, 0x77FB, 0xD367, 0x776C, 0xD1EF, 0x76D9, 0xD079, + 0x7642, 0xCF04, 0x75A6, 0xCD92, 0x7505, 0xCC21, 0x7460, 0xCAB2, + 0x73B6, 0xC946, 0x7308, 0xC7DB, 0x7255, 0xC673, 0x719E, 0xC50D, + 0x70E3, 0xC3A9, 0x7023, 0xC248, 0x6F5F, 0xC0E9, 0x6E97, 0xBF8C, + 0x6DCA, 0xBE32, 0x6CF9, 0xBCDA, 0x6C24, 0xBB85, 0x6B4B, 0xBA33, + 0x6A6E, 0xB8E3, 0x698C, 0xB796, 0x68A7, 0xB64C, 0x67BD, 0xB505, + 0x66D0, 0xB3C0, 0x65DE, 0xB27F, 0x64E9, 0xB140, 0x63EF, 0xB005, + 0x62F2, 0xAECC, 0x61F1, 0xAD97, 0x60EC, 0xAC65, 0x5FE4, 0xAB36, + 0x5ED7, 0xAA0A, 0x5DC8, 0xA8E2, 0x5CB4, 0xA7BD, 0x5B9D, 0xA69C, + 0x5A82, 0xA57E, 0x5964, 0xA463, 0x5843, 0xA34C, 0x571E, 0xA238, + 0x55F6, 0xA129, 0x54CA, 0xA01C, 0x539B, 0x9F14, 0x5269, 0x9E0F, + 0x5134, 0x9D0E, 0x4FFB, 0x9C11, 0x4EC0, 0x9B17, 0x4D81, 0x9A22, + 0x4C40, 0x9930, 0x4AFB, 0x9843, 0x49B4, 0x9759, 0x486A, 0x9674, + 0x471D, 0x9592, 0x45CD, 0x94B5, 0x447B, 0x93DC, 0x4326, 0x9307, + 0x41CE, 0x9236, 0x4074, 0x9169, 0x3F17, 0x90A1, 0x3DB8, 0x8FDD, + 0x3C57, 0x8F1D, 0x3AF3, 0x8E62, 0x398D, 0x8DAB, 0x3825, 0x8CF8, + 0x36BA, 0x8C4A, 0x354E, 0x8BA0, 0x33DF, 0x8AFB, 0x326E, 0x8A5A, + 0x30FC, 0x89BE, 0x2F87, 0x8927, 0x2E11, 0x8894, 0x2C99, 0x8805, + 0x2B1F, 0x877B, 0x29A4, 0x86F6, 0x2827, 0x8676, 0x26A8, 0x85FA, + 0x2528, 0x8583, 0x23A7, 0x8511, 0x2224, 0x84A3, 0x209F, 0x843A, + 0x1F1A, 0x83D6, 0x1D93, 0x8377, 0x1C0C, 0x831C, 0x1A83, 0x82C6, + 0x18F9, 0x8276, 0x176E, 0x822A, 0x15E2, 0x81E2, 0x1455, 0x81A0, + 0x12C8, 0x8163, 0x113A, 0x812A, 0x0FAB, 0x80F6, 0x0E1C, 0x80C8, + 0x0C8C, 0x809E, 0x0AFB, 0x8079, 0x096B, 0x8059, 0x07D9, 0x803E, + 0x0648, 0x8027, 0x04B6, 0x8016, 0x0324, 0x800A, 0x0192, 0x8002, + 0x0000, 0x8001, 0xFE6E, 0x8002, 0xFCDC, 0x800A, 0xFB4A, 0x8016, + 0xF9B8, 0x8027, 0xF827, 0x803E, 0xF695, 0x8059, 0xF505, 0x8079, + 0xF374, 0x809E, 0xF1E4, 0x80C8, 0xF055, 0x80F6, 0xEEC6, 0x812A, + 0xED38, 0x8163, 0xEBAB, 0x81A0, 0xEA1E, 0x81E2, 0xE892, 0x822A, + 0xE707, 0x8276, 0xE57D, 0x82C6, 0xE3F4, 0x831C, 0xE26D, 0x8377, + 0xE0E6, 0x83D6, 0xDF61, 0x843A, 0xDDDC, 0x84A3, 0xDC59, 0x8511, + 0xDAD8, 0x8583, 0xD958, 0x85FA, 0xD7D9, 0x8676, 0xD65C, 0x86F6, + 0xD4E1, 0x877B, 0xD367, 0x8805, 0xD1EF, 0x8894, 0xD079, 0x8927, + 0xCF04, 0x89BE, 0xCD92, 0x8A5A, 0xCC21, 0x8AFB, 0xCAB2, 0x8BA0, + 0xC946, 0x8C4A, 0xC7DB, 0x8CF8, 0xC673, 0x8DAB, 0xC50D, 0x8E62, + 0xC3A9, 0x8F1D, 0xC248, 0x8FDD, 0xC0E9, 0x90A1, 0xBF8C, 0x9169, + 0xBE32, 0x9236, 0xBCDA, 0x9307, 0xBB85, 0x93DC, 0xBA33, 0x94B5, + 0xB8E3, 0x9592, 0xB796, 0x9674, 0xB64C, 0x9759, 0xB505, 0x9843, + 0xB3C0, 0x9930, 0xB27F, 0x9A22, 0xB140, 0x9B17, 0xB005, 0x9C11, + 0xAECC, 0x9D0E, 0xAD97, 0x9E0F, 0xAC65, 0x9F14, 0xAB36, 0xA01C, + 0xAA0A, 0xA129, 0xA8E2, 0xA238, 0xA7BD, 0xA34C, 0xA69C, 0xA463, + 0xA57E, 0xA57E, 0xA463, 0xA69C, 0xA34C, 0xA7BD, 0xA238, 0xA8E2, + 0xA129, 0xAA0A, 0xA01C, 0xAB36, 0x9F14, 0xAC65, 0x9E0F, 0xAD97, + 0x9D0E, 0xAECC, 0x9C11, 0xB005, 0x9B17, 0xB140, 0x9A22, 0xB27F, + 0x9930, 0xB3C0, 0x9843, 0xB505, 0x9759, 0xB64C, 0x9674, 0xB796, + 0x9592, 0xB8E3, 0x94B5, 0xBA33, 0x93DC, 0xBB85, 0x9307, 0xBCDA, + 0x9236, 0xBE32, 0x9169, 0xBF8C, 0x90A1, 0xC0E9, 0x8FDD, 0xC248, + 0x8F1D, 0xC3A9, 0x8E62, 0xC50D, 0x8DAB, 0xC673, 0x8CF8, 0xC7DB, + 0x8C4A, 0xC946, 0x8BA0, 0xCAB2, 0x8AFB, 0xCC21, 0x8A5A, 0xCD92, + 0x89BE, 0xCF04, 0x8927, 0xD079, 0x8894, 0xD1EF, 0x8805, 0xD367, + 0x877B, 0xD4E1, 0x86F6, 0xD65C, 0x8676, 0xD7D9, 0x85FA, 0xD958, + 0x8583, 0xDAD8, 0x8511, 0xDC59, 0x84A3, 0xDDDC, 0x843A, 0xDF61, + 0x83D6, 0xE0E6, 0x8377, 0xE26D, 0x831C, 0xE3F4, 0x82C6, 0xE57D, + 0x8276, 0xE707, 0x822A, 0xE892, 0x81E2, 0xEA1E, 0x81A0, 0xEBAB, + 0x8163, 0xED38, 0x812A, 0xEEC6, 0x80F6, 0xF055, 0x80C8, 0xF1E4, + 0x809E, 0xF374, 0x8079, 0xF505, 0x8059, 0xF695, 0x803E, 0xF827, + 0x8027, 0xF9B8, 0x8016, 0xFB4A, 0x800A, 0xFCDC, 0x8002, 0xFE6E +}; + +/* + * FFT twiddle factor table for length of 1024. + */ +const _q15 msp_cmplx_twiddle_table_1024_q15[DSPLIB_TABLE_OFFSET+1024] = { + 0x0400, 0x0000, + 0x7FFF, 0x0000, 0x7FFF, 0xFF37, 0x7FFE, 0xFE6E, 0x7FFA, 0xFDA5, + 0x7FF6, 0xFCDC, 0x7FF1, 0xFC13, 0x7FEA, 0xFB4A, 0x7FE2, 0xFA81, + 0x7FD9, 0xF9B8, 0x7FCE, 0xF8EF, 0x7FC2, 0xF827, 0x7FB5, 0xF75E, + 0x7FA7, 0xF695, 0x7F98, 0xF5CD, 0x7F87, 0xF505, 0x7F75, 0xF43C, + 0x7F62, 0xF374, 0x7F4E, 0xF2AC, 0x7F38, 0xF1E4, 0x7F22, 0xF11C, + 0x7F0A, 0xF055, 0x7EF0, 0xEF8D, 0x7ED6, 0xEEC6, 0x7EBA, 0xEDFF, + 0x7E9D, 0xED38, 0x7E7F, 0xEC71, 0x7E60, 0xEBAB, 0x7E3F, 0xEAE4, + 0x7E1E, 0xEA1E, 0x7DFB, 0xE958, 0x7DD6, 0xE892, 0x7DB1, 0xE7CD, + 0x7D8A, 0xE707, 0x7D63, 0xE642, 0x7D3A, 0xE57D, 0x7D0F, 0xE4B9, + 0x7CE4, 0xE3F4, 0x7CB7, 0xE330, 0x7C89, 0xE26D, 0x7C5A, 0xE1A9, + 0x7C2A, 0xE0E6, 0x7BF9, 0xE023, 0x7BC6, 0xDF61, 0x7B92, 0xDE9E, + 0x7B5D, 0xDDDC, 0x7B27, 0xDD1B, 0x7AEF, 0xDC59, 0x7AB7, 0xDB99, + 0x7A7D, 0xDAD8, 0x7A42, 0xDA18, 0x7A06, 0xD958, 0x79C9, 0xD898, + 0x798A, 0xD7D9, 0x794A, 0xD71B, 0x790A, 0xD65C, 0x78C8, 0xD59E, + 0x7885, 0xD4E1, 0x7840, 0xD424, 0x77FB, 0xD367, 0x77B4, 0xD2AB, + 0x776C, 0xD1EF, 0x7723, 0xD134, 0x76D9, 0xD079, 0x768E, 0xCFBE, + 0x7642, 0xCF04, 0x75F4, 0xCE4B, 0x75A6, 0xCD92, 0x7556, 0xCCD9, + 0x7505, 0xCC21, 0x74B3, 0xCB69, 0x7460, 0xCAB2, 0x740B, 0xC9FC, + 0x73B6, 0xC946, 0x735F, 0xC890, 0x7308, 0xC7DB, 0x72AF, 0xC727, + 0x7255, 0xC673, 0x71FA, 0xC5C0, 0x719E, 0xC50D, 0x7141, 0xC45B, + 0x70E3, 0xC3A9, 0x7083, 0xC2F8, 0x7023, 0xC248, 0x6FC2, 0xC198, + 0x6F5F, 0xC0E9, 0x6EFB, 0xC03A, 0x6E97, 0xBF8C, 0x6E31, 0xBEDF, + 0x6DCA, 0xBE32, 0x6D62, 0xBD86, 0x6CF9, 0xBCDA, 0x6C8F, 0xBC2F, + 0x6C24, 0xBB85, 0x6BB8, 0xBADC, 0x6B4B, 0xBA33, 0x6ADD, 0xB98B, + 0x6A6E, 0xB8E3, 0x69FD, 0xB83C, 0x698C, 0xB796, 0x691A, 0xB6F1, + 0x68A7, 0xB64C, 0x6832, 0xB5A8, 0x67BD, 0xB505, 0x6747, 0xB462, + 0x66D0, 0xB3C0, 0x6657, 0xB31F, 0x65DE, 0xB27F, 0x6564, 0xB1DF, + 0x64E9, 0xB140, 0x646C, 0xB0A2, 0x63EF, 0xB005, 0x6371, 0xAF68, + 0x62F2, 0xAECC, 0x6272, 0xAE31, 0x61F1, 0xAD97, 0x616F, 0xACFD, + 0x60EC, 0xAC65, 0x6068, 0xABCD, 0x5FE4, 0xAB36, 0x5F5E, 0xAAA0, + 0x5ED7, 0xAA0A, 0x5E50, 0xA976, 0x5DC8, 0xA8E2, 0x5D3E, 0xA84F, + 0x5CB4, 0xA7BD, 0x5C29, 0xA72C, 0x5B9D, 0xA69C, 0x5B10, 0xA60C, + 0x5A82, 0xA57E, 0x59F4, 0xA4F0, 0x5964, 0xA463, 0x58D4, 0xA3D7, + 0x5843, 0xA34C, 0x57B1, 0xA2C2, 0x571E, 0xA238, 0x568A, 0xA1B0, + 0x55F6, 0xA129, 0x5560, 0xA0A2, 0x54CA, 0xA01C, 0x5433, 0x9F98, + 0x539B, 0x9F14, 0x5303, 0x9E91, 0x5269, 0x9E0F, 0x51CF, 0x9D8E, + 0x5134, 0x9D0E, 0x5098, 0x9C8F, 0x4FFB, 0x9C11, 0x4F5E, 0x9B94, + 0x4EC0, 0x9B17, 0x4E21, 0x9A9C, 0x4D81, 0x9A22, 0x4CE1, 0x99A9, + 0x4C40, 0x9930, 0x4B9E, 0x98B9, 0x4AFB, 0x9843, 0x4A58, 0x97CE, + 0x49B4, 0x9759, 0x490F, 0x96E6, 0x486A, 0x9674, 0x47C4, 0x9603, + 0x471D, 0x9592, 0x4675, 0x9523, 0x45CD, 0x94B5, 0x4524, 0x9448, + 0x447B, 0x93DC, 0x43D1, 0x9371, 0x4326, 0x9307, 0x427A, 0x929E, + 0x41CE, 0x9236, 0x4121, 0x91CF, 0x4074, 0x9169, 0x3FC6, 0x9105, + 0x3F17, 0x90A1, 0x3E68, 0x903E, 0x3DB8, 0x8FDD, 0x3D08, 0x8F7D, + 0x3C57, 0x8F1D, 0x3BA5, 0x8EBF, 0x3AF3, 0x8E62, 0x3A40, 0x8E06, + 0x398D, 0x8DAB, 0x38D9, 0x8D51, 0x3825, 0x8CF8, 0x3770, 0x8CA1, + 0x36BA, 0x8C4A, 0x3604, 0x8BF5, 0x354E, 0x8BA0, 0x3497, 0x8B4D, + 0x33DF, 0x8AFB, 0x3327, 0x8AAA, 0x326E, 0x8A5A, 0x31B5, 0x8A0C, + 0x30FC, 0x89BE, 0x3042, 0x8972, 0x2F87, 0x8927, 0x2ECC, 0x88DD, + 0x2E11, 0x8894, 0x2D55, 0x884C, 0x2C99, 0x8805, 0x2BDC, 0x87C0, + 0x2B1F, 0x877B, 0x2A62, 0x8738, 0x29A4, 0x86F6, 0x28E5, 0x86B6, + 0x2827, 0x8676, 0x2768, 0x8637, 0x26A8, 0x85FA, 0x25E8, 0x85BE, + 0x2528, 0x8583, 0x2467, 0x8549, 0x23A7, 0x8511, 0x22E5, 0x84D9, + 0x2224, 0x84A3, 0x2162, 0x846E, 0x209F, 0x843A, 0x1FDD, 0x8407, + 0x1F1A, 0x83D6, 0x1E57, 0x83A6, 0x1D93, 0x8377, 0x1CD0, 0x8349, + 0x1C0C, 0x831C, 0x1B47, 0x82F1, 0x1A83, 0x82C6, 0x19BE, 0x829D, + 0x18F9, 0x8276, 0x1833, 0x824F, 0x176E, 0x822A, 0x16A8, 0x8205, + 0x15E2, 0x81E2, 0x151C, 0x81C1, 0x1455, 0x81A0, 0x138F, 0x8181, + 0x12C8, 0x8163, 0x1201, 0x8146, 0x113A, 0x812A, 0x1073, 0x8110, + 0x0FAB, 0x80F6, 0x0EE4, 0x80DE, 0x0E1C, 0x80C8, 0x0D54, 0x80B2, + 0x0C8C, 0x809E, 0x0BC4, 0x808B, 0x0AFB, 0x8079, 0x0A33, 0x8068, + 0x096B, 0x8059, 0x08A2, 0x804B, 0x07D9, 0x803E, 0x0711, 0x8032, + 0x0648, 0x8027, 0x057F, 0x801E, 0x04B6, 0x8016, 0x03ED, 0x800F, + 0x0324, 0x800A, 0x025B, 0x8006, 0x0192, 0x8002, 0x00C9, 0x8001, + 0x0000, 0x8001, 0xFF37, 0x8001, 0xFE6E, 0x8002, 0xFDA5, 0x8006, + 0xFCDC, 0x800A, 0xFC13, 0x800F, 0xFB4A, 0x8016, 0xFA81, 0x801E, + 0xF9B8, 0x8027, 0xF8EF, 0x8032, 0xF827, 0x803E, 0xF75E, 0x804B, + 0xF695, 0x8059, 0xF5CD, 0x8068, 0xF505, 0x8079, 0xF43C, 0x808B, + 0xF374, 0x809E, 0xF2AC, 0x80B2, 0xF1E4, 0x80C8, 0xF11C, 0x80DE, + 0xF055, 0x80F6, 0xEF8D, 0x8110, 0xEEC6, 0x812A, 0xEDFF, 0x8146, + 0xED38, 0x8163, 0xEC71, 0x8181, 0xEBAB, 0x81A0, 0xEAE4, 0x81C1, + 0xEA1E, 0x81E2, 0xE958, 0x8205, 0xE892, 0x822A, 0xE7CD, 0x824F, + 0xE707, 0x8276, 0xE642, 0x829D, 0xE57D, 0x82C6, 0xE4B9, 0x82F1, + 0xE3F4, 0x831C, 0xE330, 0x8349, 0xE26D, 0x8377, 0xE1A9, 0x83A6, + 0xE0E6, 0x83D6, 0xE023, 0x8407, 0xDF61, 0x843A, 0xDE9E, 0x846E, + 0xDDDC, 0x84A3, 0xDD1B, 0x84D9, 0xDC59, 0x8511, 0xDB99, 0x8549, + 0xDAD8, 0x8583, 0xDA18, 0x85BE, 0xD958, 0x85FA, 0xD898, 0x8637, + 0xD7D9, 0x8676, 0xD71B, 0x86B6, 0xD65C, 0x86F6, 0xD59E, 0x8738, + 0xD4E1, 0x877B, 0xD424, 0x87C0, 0xD367, 0x8805, 0xD2AB, 0x884C, + 0xD1EF, 0x8894, 0xD134, 0x88DD, 0xD079, 0x8927, 0xCFBE, 0x8972, + 0xCF04, 0x89BE, 0xCE4B, 0x8A0C, 0xCD92, 0x8A5A, 0xCCD9, 0x8AAA, + 0xCC21, 0x8AFB, 0xCB69, 0x8B4D, 0xCAB2, 0x8BA0, 0xC9FC, 0x8BF5, + 0xC946, 0x8C4A, 0xC890, 0x8CA1, 0xC7DB, 0x8CF8, 0xC727, 0x8D51, + 0xC673, 0x8DAB, 0xC5C0, 0x8E06, 0xC50D, 0x8E62, 0xC45B, 0x8EBF, + 0xC3A9, 0x8F1D, 0xC2F8, 0x8F7D, 0xC248, 0x8FDD, 0xC198, 0x903E, + 0xC0E9, 0x90A1, 0xC03A, 0x9105, 0xBF8C, 0x9169, 0xBEDF, 0x91CF, + 0xBE32, 0x9236, 0xBD86, 0x929E, 0xBCDA, 0x9307, 0xBC2F, 0x9371, + 0xBB85, 0x93DC, 0xBADC, 0x9448, 0xBA33, 0x94B5, 0xB98B, 0x9523, + 0xB8E3, 0x9592, 0xB83C, 0x9603, 0xB796, 0x9674, 0xB6F1, 0x96E6, + 0xB64C, 0x9759, 0xB5A8, 0x97CE, 0xB505, 0x9843, 0xB462, 0x98B9, + 0xB3C0, 0x9930, 0xB31F, 0x99A9, 0xB27F, 0x9A22, 0xB1DF, 0x9A9C, + 0xB140, 0x9B17, 0xB0A2, 0x9B94, 0xB005, 0x9C11, 0xAF68, 0x9C8F, + 0xAECC, 0x9D0E, 0xAE31, 0x9D8E, 0xAD97, 0x9E0F, 0xACFD, 0x9E91, + 0xAC65, 0x9F14, 0xABCD, 0x9F98, 0xAB36, 0xA01C, 0xAAA0, 0xA0A2, + 0xAA0A, 0xA129, 0xA976, 0xA1B0, 0xA8E2, 0xA238, 0xA84F, 0xA2C2, + 0xA7BD, 0xA34C, 0xA72C, 0xA3D7, 0xA69C, 0xA463, 0xA60C, 0xA4F0, + 0xA57E, 0xA57E, 0xA4F0, 0xA60C, 0xA463, 0xA69C, 0xA3D7, 0xA72C, + 0xA34C, 0xA7BD, 0xA2C2, 0xA84F, 0xA238, 0xA8E2, 0xA1B0, 0xA976, + 0xA129, 0xAA0A, 0xA0A2, 0xAAA0, 0xA01C, 0xAB36, 0x9F98, 0xABCD, + 0x9F14, 0xAC65, 0x9E91, 0xACFD, 0x9E0F, 0xAD97, 0x9D8E, 0xAE31, + 0x9D0E, 0xAECC, 0x9C8F, 0xAF68, 0x9C11, 0xB005, 0x9B94, 0xB0A2, + 0x9B17, 0xB140, 0x9A9C, 0xB1DF, 0x9A22, 0xB27F, 0x99A9, 0xB31F, + 0x9930, 0xB3C0, 0x98B9, 0xB462, 0x9843, 0xB505, 0x97CE, 0xB5A8, + 0x9759, 0xB64C, 0x96E6, 0xB6F1, 0x9674, 0xB796, 0x9603, 0xB83C, + 0x9592, 0xB8E3, 0x9523, 0xB98B, 0x94B5, 0xBA33, 0x9448, 0xBADC, + 0x93DC, 0xBB85, 0x9371, 0xBC2F, 0x9307, 0xBCDA, 0x929E, 0xBD86, + 0x9236, 0xBE32, 0x91CF, 0xBEDF, 0x9169, 0xBF8C, 0x9105, 0xC03A, + 0x90A1, 0xC0E9, 0x903E, 0xC198, 0x8FDD, 0xC248, 0x8F7D, 0xC2F8, + 0x8F1D, 0xC3A9, 0x8EBF, 0xC45B, 0x8E62, 0xC50D, 0x8E06, 0xC5C0, + 0x8DAB, 0xC673, 0x8D51, 0xC727, 0x8CF8, 0xC7DB, 0x8CA1, 0xC890, + 0x8C4A, 0xC946, 0x8BF5, 0xC9FC, 0x8BA0, 0xCAB2, 0x8B4D, 0xCB69, + 0x8AFB, 0xCC21, 0x8AAA, 0xCCD9, 0x8A5A, 0xCD92, 0x8A0C, 0xCE4B, + 0x89BE, 0xCF04, 0x8972, 0xCFBE, 0x8927, 0xD079, 0x88DD, 0xD134, + 0x8894, 0xD1EF, 0x884C, 0xD2AB, 0x8805, 0xD367, 0x87C0, 0xD424, + 0x877B, 0xD4E1, 0x8738, 0xD59E, 0x86F6, 0xD65C, 0x86B6, 0xD71B, + 0x8676, 0xD7D9, 0x8637, 0xD898, 0x85FA, 0xD958, 0x85BE, 0xDA18, + 0x8583, 0xDAD8, 0x8549, 0xDB99, 0x8511, 0xDC59, 0x84D9, 0xDD1B, + 0x84A3, 0xDDDC, 0x846E, 0xDE9E, 0x843A, 0xDF61, 0x8407, 0xE023, + 0x83D6, 0xE0E6, 0x83A6, 0xE1A9, 0x8377, 0xE26D, 0x8349, 0xE330, + 0x831C, 0xE3F4, 0x82F1, 0xE4B9, 0x82C6, 0xE57D, 0x829D, 0xE642, + 0x8276, 0xE707, 0x824F, 0xE7CD, 0x822A, 0xE892, 0x8205, 0xE958, + 0x81E2, 0xEA1E, 0x81C1, 0xEAE4, 0x81A0, 0xEBAB, 0x8181, 0xEC71, + 0x8163, 0xED38, 0x8146, 0xEDFF, 0x812A, 0xEEC6, 0x8110, 0xEF8D, + 0x80F6, 0xF055, 0x80DE, 0xF11C, 0x80C8, 0xF1E4, 0x80B2, 0xF2AC, + 0x809E, 0xF374, 0x808B, 0xF43C, 0x8079, 0xF505, 0x8068, 0xF5CD, + 0x8059, 0xF695, 0x804B, 0xF75E, 0x803E, 0xF827, 0x8032, 0xF8EF, + 0x8027, 0xF9B8, 0x801E, 0xFA81, 0x8016, 0xFB4A, 0x800F, 0xFC13, + 0x800A, 0xFCDC, 0x8006, 0xFDA5, 0x8002, 0xFE6E, 0x8001, 0xFF37 +}; + +/* + * FFT twiddle factor table for length of 2048. + */ +const _q15 msp_cmplx_twiddle_table_2048_q15[DSPLIB_TABLE_OFFSET+2048] = { + 0x0800, 0x0000, + 0x7FFF, 0x0000, 0x7FFF, 0xFF9B, 0x7FFF, 0xFF37, 0x7FFF, 0xFED2, + 0x7FFE, 0xFE6E, 0x7FFC, 0xFE09, 0x7FFA, 0xFDA5, 0x7FF8, 0xFD40, + 0x7FF6, 0xFCDC, 0x7FF4, 0xFC77, 0x7FF1, 0xFC13, 0x7FED, 0xFBAE, + 0x7FEA, 0xFB4A, 0x7FE6, 0xFAE5, 0x7FE2, 0xFA81, 0x7FDD, 0xFA1D, + 0x7FD9, 0xF9B8, 0x7FD3, 0xF954, 0x7FCE, 0xF8EF, 0x7FC8, 0xF88B, + 0x7FC2, 0xF827, 0x7FBC, 0xF7C2, 0x7FB5, 0xF75E, 0x7FAE, 0xF6FA, + 0x7FA7, 0xF695, 0x7FA0, 0xF631, 0x7F98, 0xF5CD, 0x7F90, 0xF569, + 0x7F87, 0xF505, 0x7F7E, 0xF4A0, 0x7F75, 0xF43C, 0x7F6C, 0xF3D8, + 0x7F62, 0xF374, 0x7F58, 0xF310, 0x7F4E, 0xF2AC, 0x7F43, 0xF248, + 0x7F38, 0xF1E4, 0x7F2D, 0xF180, 0x7F22, 0xF11C, 0x7F16, 0xF0B9, + 0x7F0A, 0xF055, 0x7EFD, 0xEFF1, 0x7EF0, 0xEF8D, 0x7EE3, 0xEF2A, + 0x7ED6, 0xEEC6, 0x7EC8, 0xEE62, 0x7EBA, 0xEDFF, 0x7EAC, 0xED9B, + 0x7E9D, 0xED38, 0x7E8E, 0xECD5, 0x7E7F, 0xEC71, 0x7E70, 0xEC0E, + 0x7E60, 0xEBAB, 0x7E50, 0xEB47, 0x7E3F, 0xEAE4, 0x7E2F, 0xEA81, + 0x7E1E, 0xEA1E, 0x7E0C, 0xE9BB, 0x7DFB, 0xE958, 0x7DE9, 0xE8F5, + 0x7DD6, 0xE892, 0x7DC4, 0xE82F, 0x7DB1, 0xE7CD, 0x7D9E, 0xE76A, + 0x7D8A, 0xE707, 0x7D77, 0xE6A5, 0x7D63, 0xE642, 0x7D4E, 0xE5E0, + 0x7D3A, 0xE57D, 0x7D25, 0xE51B, 0x7D0F, 0xE4B9, 0x7CFA, 0xE457, + 0x7CE4, 0xE3F4, 0x7CCE, 0xE392, 0x7CB7, 0xE330, 0x7CA0, 0xE2CF, + 0x7C89, 0xE26D, 0x7C72, 0xE20B, 0x7C5A, 0xE1A9, 0x7C42, 0xE148, + 0x7C2A, 0xE0E6, 0x7C11, 0xE085, 0x7BF9, 0xE023, 0x7BDF, 0xDFC2, + 0x7BC6, 0xDF61, 0x7BAC, 0xDEFF, 0x7B92, 0xDE9E, 0x7B78, 0xDE3D, + 0x7B5D, 0xDDDC, 0x7B42, 0xDD7C, 0x7B27, 0xDD1B, 0x7B0B, 0xDCBA, + 0x7AEF, 0xDC59, 0x7AD3, 0xDBF9, 0x7AB7, 0xDB99, 0x7A9A, 0xDB38, + 0x7A7D, 0xDAD8, 0x7A60, 0xDA78, 0x7A42, 0xDA18, 0x7A24, 0xD9B8, + 0x7A06, 0xD958, 0x79E7, 0xD8F8, 0x79C9, 0xD898, 0x79AA, 0xD839, + 0x798A, 0xD7D9, 0x796A, 0xD77A, 0x794A, 0xD71B, 0x792A, 0xD6BB, + 0x790A, 0xD65C, 0x78E9, 0xD5FD, 0x78C8, 0xD59E, 0x78A6, 0xD53F, + 0x7885, 0xD4E1, 0x7863, 0xD482, 0x7840, 0xD424, 0x781E, 0xD3C5, + 0x77FB, 0xD367, 0x77D8, 0xD309, 0x77B4, 0xD2AB, 0x7790, 0xD24D, + 0x776C, 0xD1EF, 0x7748, 0xD191, 0x7723, 0xD134, 0x76FE, 0xD0D6, + 0x76D9, 0xD079, 0x76B4, 0xD01B, 0x768E, 0xCFBE, 0x7668, 0xCF61, + 0x7642, 0xCF04, 0x761B, 0xCEA7, 0x75F4, 0xCE4B, 0x75CD, 0xCDEE, + 0x75A6, 0xCD92, 0x757E, 0xCD35, 0x7556, 0xCCD9, 0x752D, 0xCC7D, + 0x7505, 0xCC21, 0x74DC, 0xCBC5, 0x74B3, 0xCB69, 0x7489, 0xCB0E, + 0x7460, 0xCAB2, 0x7436, 0xCA57, 0x740B, 0xC9FC, 0x73E1, 0xC9A1, + 0x73B6, 0xC946, 0x738B, 0xC8EB, 0x735F, 0xC890, 0x7334, 0xC836, + 0x7308, 0xC7DB, 0x72DC, 0xC781, 0x72AF, 0xC727, 0x7282, 0xC6CD, + 0x7255, 0xC673, 0x7228, 0xC619, 0x71FA, 0xC5C0, 0x71CC, 0xC566, + 0x719E, 0xC50D, 0x7170, 0xC4B4, 0x7141, 0xC45B, 0x7112, 0xC402, + 0x70E3, 0xC3A9, 0x70B3, 0xC351, 0x7083, 0xC2F8, 0x7053, 0xC2A0, + 0x7023, 0xC248, 0x6FF2, 0xC1F0, 0x6FC2, 0xC198, 0x6F90, 0xC140, + 0x6F5F, 0xC0E9, 0x6F2D, 0xC091, 0x6EFB, 0xC03A, 0x6EC9, 0xBFE3, + 0x6E97, 0xBF8C, 0x6E64, 0xBF35, 0x6E31, 0xBEDF, 0x6DFE, 0xBE88, + 0x6DCA, 0xBE32, 0x6D96, 0xBDDC, 0x6D62, 0xBD86, 0x6D2E, 0xBD30, + 0x6CF9, 0xBCDA, 0x6CC4, 0xBC85, 0x6C8F, 0xBC2F, 0x6C5A, 0xBBDA, + 0x6C24, 0xBB85, 0x6BEE, 0xBB30, 0x6BB8, 0xBADC, 0x6B82, 0xBA87, + 0x6B4B, 0xBA33, 0x6B14, 0xB9DF, 0x6ADD, 0xB98B, 0x6AA5, 0xB937, + 0x6A6E, 0xB8E3, 0x6A36, 0xB890, 0x69FD, 0xB83C, 0x69C5, 0xB7E9, + 0x698C, 0xB796, 0x6953, 0xB743, 0x691A, 0xB6F1, 0x68E0, 0xB69E, + 0x68A7, 0xB64C, 0x686D, 0xB5FA, 0x6832, 0xB5A8, 0x67F8, 0xB556, + 0x67BD, 0xB505, 0x6782, 0xB4B3, 0x6747, 0xB462, 0x670B, 0xB411, + 0x66D0, 0xB3C0, 0x6693, 0xB36F, 0x6657, 0xB31F, 0x661B, 0xB2CF, + 0x65DE, 0xB27F, 0x65A1, 0xB22F, 0x6564, 0xB1DF, 0x6526, 0xB18F, + 0x64E9, 0xB140, 0x64AB, 0xB0F1, 0x646C, 0xB0A2, 0x642E, 0xB053, + 0x63EF, 0xB005, 0x63B0, 0xAFB6, 0x6371, 0xAF68, 0x6332, 0xAF1A, + 0x62F2, 0xAECC, 0x62B2, 0xAE7F, 0x6272, 0xAE31, 0x6232, 0xADE4, + 0x61F1, 0xAD97, 0x61B0, 0xAD4A, 0x616F, 0xACFD, 0x612E, 0xACB1, + 0x60EC, 0xAC65, 0x60AA, 0xAC19, 0x6068, 0xABCD, 0x6026, 0xAB81, + 0x5FE4, 0xAB36, 0x5FA1, 0xAAEB, 0x5F5E, 0xAAA0, 0x5F1B, 0xAA55, + 0x5ED7, 0xAA0A, 0x5E94, 0xA9C0, 0x5E50, 0xA976, 0x5E0C, 0xA92C, + 0x5DC8, 0xA8E2, 0x5D83, 0xA899, 0x5D3E, 0xA84F, 0x5CF9, 0xA806, + 0x5CB4, 0xA7BD, 0x5C6F, 0xA774, 0x5C29, 0xA72C, 0x5BE3, 0xA6E4, + 0x5B9D, 0xA69C, 0x5B57, 0xA654, 0x5B10, 0xA60C, 0x5AC9, 0xA5C5, + 0x5A82, 0xA57E, 0x5A3B, 0xA537, 0x59F4, 0xA4F0, 0x59AC, 0xA4A9, + 0x5964, 0xA463, 0x591C, 0xA41D, 0x58D4, 0xA3D7, 0x588C, 0xA391, + 0x5843, 0xA34C, 0x57FA, 0xA307, 0x57B1, 0xA2C2, 0x5767, 0xA27D, + 0x571E, 0xA238, 0x56D4, 0xA1F4, 0x568A, 0xA1B0, 0x5640, 0xA16C, + 0x55F6, 0xA129, 0x55AB, 0xA0E5, 0x5560, 0xA0A2, 0x5515, 0xA05F, + 0x54CA, 0xA01C, 0x547F, 0x9FDA, 0x5433, 0x9F98, 0x53E7, 0x9F56, + 0x539B, 0x9F14, 0x534F, 0x9ED2, 0x5303, 0x9E91, 0x52B6, 0x9E50, + 0x5269, 0x9E0F, 0x521C, 0x9DCE, 0x51CF, 0x9D8E, 0x5181, 0x9D4E, + 0x5134, 0x9D0E, 0x50E6, 0x9CCE, 0x5098, 0x9C8F, 0x504A, 0x9C50, + 0x4FFB, 0x9C11, 0x4FAD, 0x9BD2, 0x4F5E, 0x9B94, 0x4F0F, 0x9B55, + 0x4EC0, 0x9B17, 0x4E71, 0x9ADA, 0x4E21, 0x9A9C, 0x4DD1, 0x9A5F, + 0x4D81, 0x9A22, 0x4D31, 0x99E5, 0x4CE1, 0x99A9, 0x4C91, 0x996D, + 0x4C40, 0x9930, 0x4BEF, 0x98F5, 0x4B9E, 0x98B9, 0x4B4D, 0x987E, + 0x4AFB, 0x9843, 0x4AAA, 0x9808, 0x4A58, 0x97CE, 0x4A06, 0x9793, + 0x49B4, 0x9759, 0x4962, 0x9720, 0x490F, 0x96E6, 0x48BD, 0x96AD, + 0x486A, 0x9674, 0x4817, 0x963B, 0x47C4, 0x9603, 0x4770, 0x95CA, + 0x471D, 0x9592, 0x46C9, 0x955B, 0x4675, 0x9523, 0x4621, 0x94EC, + 0x45CD, 0x94B5, 0x4579, 0x947E, 0x4524, 0x9448, 0x44D0, 0x9412, + 0x447B, 0x93DC, 0x4426, 0x93A6, 0x43D1, 0x9371, 0x437B, 0x933C, + 0x4326, 0x9307, 0x42D0, 0x92D2, 0x427A, 0x929E, 0x4224, 0x926A, + 0x41CE, 0x9236, 0x4178, 0x9202, 0x4121, 0x91CF, 0x40CB, 0x919C, + 0x4074, 0x9169, 0x401D, 0x9137, 0x3FC6, 0x9105, 0x3F6F, 0x90D3, + 0x3F17, 0x90A1, 0x3EC0, 0x9070, 0x3E68, 0x903E, 0x3E10, 0x900E, + 0x3DB8, 0x8FDD, 0x3D60, 0x8FAD, 0x3D08, 0x8F7D, 0x3CAF, 0x8F4D, + 0x3C57, 0x8F1D, 0x3BFE, 0x8EEE, 0x3BA5, 0x8EBF, 0x3B4C, 0x8E90, + 0x3AF3, 0x8E62, 0x3A9A, 0x8E34, 0x3A40, 0x8E06, 0x39E7, 0x8DD8, + 0x398D, 0x8DAB, 0x3933, 0x8D7E, 0x38D9, 0x8D51, 0x387F, 0x8D24, + 0x3825, 0x8CF8, 0x37CA, 0x8CCC, 0x3770, 0x8CA1, 0x3715, 0x8C75, + 0x36BA, 0x8C4A, 0x365F, 0x8C1F, 0x3604, 0x8BF5, 0x35A9, 0x8BCA, + 0x354E, 0x8BA0, 0x34F2, 0x8B77, 0x3497, 0x8B4D, 0x343B, 0x8B24, + 0x33DF, 0x8AFB, 0x3383, 0x8AD3, 0x3327, 0x8AAA, 0x32CB, 0x8A82, + 0x326E, 0x8A5A, 0x3212, 0x8A33, 0x31B5, 0x8A0C, 0x3159, 0x89E5, + 0x30FC, 0x89BE, 0x309F, 0x8998, 0x3042, 0x8972, 0x2FE5, 0x894C, + 0x2F87, 0x8927, 0x2F2A, 0x8902, 0x2ECC, 0x88DD, 0x2E6F, 0x88B8, + 0x2E11, 0x8894, 0x2DB3, 0x8870, 0x2D55, 0x884C, 0x2CF7, 0x8828, + 0x2C99, 0x8805, 0x2C3B, 0x87E2, 0x2BDC, 0x87C0, 0x2B7E, 0x879D, + 0x2B1F, 0x877B, 0x2AC1, 0x875A, 0x2A62, 0x8738, 0x2A03, 0x8717, + 0x29A4, 0x86F6, 0x2945, 0x86D6, 0x28E5, 0x86B6, 0x2886, 0x8696, + 0x2827, 0x8676, 0x27C7, 0x8656, 0x2768, 0x8637, 0x2708, 0x8619, + 0x26A8, 0x85FA, 0x2648, 0x85DC, 0x25E8, 0x85BE, 0x2588, 0x85A0, + 0x2528, 0x8583, 0x24C8, 0x8566, 0x2467, 0x8549, 0x2407, 0x852D, + 0x23A7, 0x8511, 0x2346, 0x84F5, 0x22E5, 0x84D9, 0x2284, 0x84BE, + 0x2224, 0x84A3, 0x21C3, 0x8488, 0x2162, 0x846E, 0x2101, 0x8454, + 0x209F, 0x843A, 0x203E, 0x8421, 0x1FDD, 0x8407, 0x1F7B, 0x83EF, + 0x1F1A, 0x83D6, 0x1EB8, 0x83BE, 0x1E57, 0x83A6, 0x1DF5, 0x838E, + 0x1D93, 0x8377, 0x1D31, 0x8360, 0x1CD0, 0x8349, 0x1C6E, 0x8332, + 0x1C0C, 0x831C, 0x1BA9, 0x8306, 0x1B47, 0x82F1, 0x1AE5, 0x82DB, + 0x1A83, 0x82C6, 0x1A20, 0x82B2, 0x19BE, 0x829D, 0x195B, 0x8289, + 0x18F9, 0x8276, 0x1896, 0x8262, 0x1833, 0x824F, 0x17D1, 0x823C, + 0x176E, 0x822A, 0x170B, 0x8217, 0x16A8, 0x8205, 0x1645, 0x81F4, + 0x15E2, 0x81E2, 0x157F, 0x81D1, 0x151C, 0x81C1, 0x14B9, 0x81B0, + 0x1455, 0x81A0, 0x13F2, 0x8190, 0x138F, 0x8181, 0x132B, 0x8172, + 0x12C8, 0x8163, 0x1265, 0x8154, 0x1201, 0x8146, 0x119E, 0x8138, + 0x113A, 0x812A, 0x10D6, 0x811D, 0x1073, 0x8110, 0x100F, 0x8103, + 0x0FAB, 0x80F6, 0x0F47, 0x80EA, 0x0EE4, 0x80DE, 0x0E80, 0x80D3, + 0x0E1C, 0x80C8, 0x0DB8, 0x80BD, 0x0D54, 0x80B2, 0x0CF0, 0x80A8, + 0x0C8C, 0x809E, 0x0C28, 0x8094, 0x0BC4, 0x808B, 0x0B60, 0x8082, + 0x0AFB, 0x8079, 0x0A97, 0x8070, 0x0A33, 0x8068, 0x09CF, 0x8060, + 0x096B, 0x8059, 0x0906, 0x8052, 0x08A2, 0x804B, 0x083E, 0x8044, + 0x07D9, 0x803E, 0x0775, 0x8038, 0x0711, 0x8032, 0x06AC, 0x802D, + 0x0648, 0x8027, 0x05E3, 0x8023, 0x057F, 0x801E, 0x051B, 0x801A, + 0x04B6, 0x8016, 0x0452, 0x8013, 0x03ED, 0x800F, 0x0389, 0x800C, + 0x0324, 0x800A, 0x02C0, 0x8008, 0x025B, 0x8006, 0x01F7, 0x8004, + 0x0192, 0x8002, 0x012E, 0x8001, 0x00C9, 0x8001, 0x0065, 0x8001, + 0x0000, 0x8001, 0xFF9B, 0x8001, 0xFF37, 0x8001, 0xFED2, 0x8001, + 0xFE6E, 0x8002, 0xFE09, 0x8004, 0xFDA5, 0x8006, 0xFD40, 0x8008, + 0xFCDC, 0x800A, 0xFC77, 0x800C, 0xFC13, 0x800F, 0xFBAE, 0x8013, + 0xFB4A, 0x8016, 0xFAE5, 0x801A, 0xFA81, 0x801E, 0xFA1D, 0x8023, + 0xF9B8, 0x8027, 0xF954, 0x802D, 0xF8EF, 0x8032, 0xF88B, 0x8038, + 0xF827, 0x803E, 0xF7C2, 0x8044, 0xF75E, 0x804B, 0xF6FA, 0x8052, + 0xF695, 0x8059, 0xF631, 0x8060, 0xF5CD, 0x8068, 0xF569, 0x8070, + 0xF505, 0x8079, 0xF4A0, 0x8082, 0xF43C, 0x808B, 0xF3D8, 0x8094, + 0xF374, 0x809E, 0xF310, 0x80A8, 0xF2AC, 0x80B2, 0xF248, 0x80BD, + 0xF1E4, 0x80C8, 0xF180, 0x80D3, 0xF11C, 0x80DE, 0xF0B9, 0x80EA, + 0xF055, 0x80F6, 0xEFF1, 0x8103, 0xEF8D, 0x8110, 0xEF2A, 0x811D, + 0xEEC6, 0x812A, 0xEE62, 0x8138, 0xEDFF, 0x8146, 0xED9B, 0x8154, + 0xED38, 0x8163, 0xECD5, 0x8172, 0xEC71, 0x8181, 0xEC0E, 0x8190, + 0xEBAB, 0x81A0, 0xEB47, 0x81B0, 0xEAE4, 0x81C1, 0xEA81, 0x81D1, + 0xEA1E, 0x81E2, 0xE9BB, 0x81F4, 0xE958, 0x8205, 0xE8F5, 0x8217, + 0xE892, 0x822A, 0xE82F, 0x823C, 0xE7CD, 0x824F, 0xE76A, 0x8262, + 0xE707, 0x8276, 0xE6A5, 0x8289, 0xE642, 0x829D, 0xE5E0, 0x82B2, + 0xE57D, 0x82C6, 0xE51B, 0x82DB, 0xE4B9, 0x82F1, 0xE457, 0x8306, + 0xE3F4, 0x831C, 0xE392, 0x8332, 0xE330, 0x8349, 0xE2CF, 0x8360, + 0xE26D, 0x8377, 0xE20B, 0x838E, 0xE1A9, 0x83A6, 0xE148, 0x83BE, + 0xE0E6, 0x83D6, 0xE085, 0x83EF, 0xE023, 0x8407, 0xDFC2, 0x8421, + 0xDF61, 0x843A, 0xDEFF, 0x8454, 0xDE9E, 0x846E, 0xDE3D, 0x8488, + 0xDDDC, 0x84A3, 0xDD7C, 0x84BE, 0xDD1B, 0x84D9, 0xDCBA, 0x84F5, + 0xDC59, 0x8511, 0xDBF9, 0x852D, 0xDB99, 0x8549, 0xDB38, 0x8566, + 0xDAD8, 0x8583, 0xDA78, 0x85A0, 0xDA18, 0x85BE, 0xD9B8, 0x85DC, + 0xD958, 0x85FA, 0xD8F8, 0x8619, 0xD898, 0x8637, 0xD839, 0x8656, + 0xD7D9, 0x8676, 0xD77A, 0x8696, 0xD71B, 0x86B6, 0xD6BB, 0x86D6, + 0xD65C, 0x86F6, 0xD5FD, 0x8717, 0xD59E, 0x8738, 0xD53F, 0x875A, + 0xD4E1, 0x877B, 0xD482, 0x879D, 0xD424, 0x87C0, 0xD3C5, 0x87E2, + 0xD367, 0x8805, 0xD309, 0x8828, 0xD2AB, 0x884C, 0xD24D, 0x8870, + 0xD1EF, 0x8894, 0xD191, 0x88B8, 0xD134, 0x88DD, 0xD0D6, 0x8902, + 0xD079, 0x8927, 0xD01B, 0x894C, 0xCFBE, 0x8972, 0xCF61, 0x8998, + 0xCF04, 0x89BE, 0xCEA7, 0x89E5, 0xCE4B, 0x8A0C, 0xCDEE, 0x8A33, + 0xCD92, 0x8A5A, 0xCD35, 0x8A82, 0xCCD9, 0x8AAA, 0xCC7D, 0x8AD3, + 0xCC21, 0x8AFB, 0xCBC5, 0x8B24, 0xCB69, 0x8B4D, 0xCB0E, 0x8B77, + 0xCAB2, 0x8BA0, 0xCA57, 0x8BCA, 0xC9FC, 0x8BF5, 0xC9A1, 0x8C1F, + 0xC946, 0x8C4A, 0xC8EB, 0x8C75, 0xC890, 0x8CA1, 0xC836, 0x8CCC, + 0xC7DB, 0x8CF8, 0xC781, 0x8D24, 0xC727, 0x8D51, 0xC6CD, 0x8D7E, + 0xC673, 0x8DAB, 0xC619, 0x8DD8, 0xC5C0, 0x8E06, 0xC566, 0x8E34, + 0xC50D, 0x8E62, 0xC4B4, 0x8E90, 0xC45B, 0x8EBF, 0xC402, 0x8EEE, + 0xC3A9, 0x8F1D, 0xC351, 0x8F4D, 0xC2F8, 0x8F7D, 0xC2A0, 0x8FAD, + 0xC248, 0x8FDD, 0xC1F0, 0x900E, 0xC198, 0x903E, 0xC140, 0x9070, + 0xC0E9, 0x90A1, 0xC091, 0x90D3, 0xC03A, 0x9105, 0xBFE3, 0x9137, + 0xBF8C, 0x9169, 0xBF35, 0x919C, 0xBEDF, 0x91CF, 0xBE88, 0x9202, + 0xBE32, 0x9236, 0xBDDC, 0x926A, 0xBD86, 0x929E, 0xBD30, 0x92D2, + 0xBCDA, 0x9307, 0xBC85, 0x933C, 0xBC2F, 0x9371, 0xBBDA, 0x93A6, + 0xBB85, 0x93DC, 0xBB30, 0x9412, 0xBADC, 0x9448, 0xBA87, 0x947E, + 0xBA33, 0x94B5, 0xB9DF, 0x94EC, 0xB98B, 0x9523, 0xB937, 0x955B, + 0xB8E3, 0x9592, 0xB890, 0x95CA, 0xB83C, 0x9603, 0xB7E9, 0x963B, + 0xB796, 0x9674, 0xB743, 0x96AD, 0xB6F1, 0x96E6, 0xB69E, 0x9720, + 0xB64C, 0x9759, 0xB5FA, 0x9793, 0xB5A8, 0x97CE, 0xB556, 0x9808, + 0xB505, 0x9843, 0xB4B3, 0x987E, 0xB462, 0x98B9, 0xB411, 0x98F5, + 0xB3C0, 0x9930, 0xB36F, 0x996D, 0xB31F, 0x99A9, 0xB2CF, 0x99E5, + 0xB27F, 0x9A22, 0xB22F, 0x9A5F, 0xB1DF, 0x9A9C, 0xB18F, 0x9ADA, + 0xB140, 0x9B17, 0xB0F1, 0x9B55, 0xB0A2, 0x9B94, 0xB053, 0x9BD2, + 0xB005, 0x9C11, 0xAFB6, 0x9C50, 0xAF68, 0x9C8F, 0xAF1A, 0x9CCE, + 0xAECC, 0x9D0E, 0xAE7F, 0x9D4E, 0xAE31, 0x9D8E, 0xADE4, 0x9DCE, + 0xAD97, 0x9E0F, 0xAD4A, 0x9E50, 0xACFD, 0x9E91, 0xACB1, 0x9ED2, + 0xAC65, 0x9F14, 0xAC19, 0x9F56, 0xABCD, 0x9F98, 0xAB81, 0x9FDA, + 0xAB36, 0xA01C, 0xAAEB, 0xA05F, 0xAAA0, 0xA0A2, 0xAA55, 0xA0E5, + 0xAA0A, 0xA129, 0xA9C0, 0xA16C, 0xA976, 0xA1B0, 0xA92C, 0xA1F4, + 0xA8E2, 0xA238, 0xA899, 0xA27D, 0xA84F, 0xA2C2, 0xA806, 0xA307, + 0xA7BD, 0xA34C, 0xA774, 0xA391, 0xA72C, 0xA3D7, 0xA6E4, 0xA41D, + 0xA69C, 0xA463, 0xA654, 0xA4A9, 0xA60C, 0xA4F0, 0xA5C5, 0xA537, + 0xA57E, 0xA57E, 0xA537, 0xA5C5, 0xA4F0, 0xA60C, 0xA4A9, 0xA654, + 0xA463, 0xA69C, 0xA41D, 0xA6E4, 0xA3D7, 0xA72C, 0xA391, 0xA774, + 0xA34C, 0xA7BD, 0xA307, 0xA806, 0xA2C2, 0xA84F, 0xA27D, 0xA899, + 0xA238, 0xA8E2, 0xA1F4, 0xA92C, 0xA1B0, 0xA976, 0xA16C, 0xA9C0, + 0xA129, 0xAA0A, 0xA0E5, 0xAA55, 0xA0A2, 0xAAA0, 0xA05F, 0xAAEB, + 0xA01C, 0xAB36, 0x9FDA, 0xAB81, 0x9F98, 0xABCD, 0x9F56, 0xAC19, + 0x9F14, 0xAC65, 0x9ED2, 0xACB1, 0x9E91, 0xACFD, 0x9E50, 0xAD4A, + 0x9E0F, 0xAD97, 0x9DCE, 0xADE4, 0x9D8E, 0xAE31, 0x9D4E, 0xAE7F, + 0x9D0E, 0xAECC, 0x9CCE, 0xAF1A, 0x9C8F, 0xAF68, 0x9C50, 0xAFB6, + 0x9C11, 0xB005, 0x9BD2, 0xB053, 0x9B94, 0xB0A2, 0x9B55, 0xB0F1, + 0x9B17, 0xB140, 0x9ADA, 0xB18F, 0x9A9C, 0xB1DF, 0x9A5F, 0xB22F, + 0x9A22, 0xB27F, 0x99E5, 0xB2CF, 0x99A9, 0xB31F, 0x996D, 0xB36F, + 0x9930, 0xB3C0, 0x98F5, 0xB411, 0x98B9, 0xB462, 0x987E, 0xB4B3, + 0x9843, 0xB505, 0x9808, 0xB556, 0x97CE, 0xB5A8, 0x9793, 0xB5FA, + 0x9759, 0xB64C, 0x9720, 0xB69E, 0x96E6, 0xB6F1, 0x96AD, 0xB743, + 0x9674, 0xB796, 0x963B, 0xB7E9, 0x9603, 0xB83C, 0x95CA, 0xB890, + 0x9592, 0xB8E3, 0x955B, 0xB937, 0x9523, 0xB98B, 0x94EC, 0xB9DF, + 0x94B5, 0xBA33, 0x947E, 0xBA87, 0x9448, 0xBADC, 0x9412, 0xBB30, + 0x93DC, 0xBB85, 0x93A6, 0xBBDA, 0x9371, 0xBC2F, 0x933C, 0xBC85, + 0x9307, 0xBCDA, 0x92D2, 0xBD30, 0x929E, 0xBD86, 0x926A, 0xBDDC, + 0x9236, 0xBE32, 0x9202, 0xBE88, 0x91CF, 0xBEDF, 0x919C, 0xBF35, + 0x9169, 0xBF8C, 0x9137, 0xBFE3, 0x9105, 0xC03A, 0x90D3, 0xC091, + 0x90A1, 0xC0E9, 0x9070, 0xC140, 0x903E, 0xC198, 0x900E, 0xC1F0, + 0x8FDD, 0xC248, 0x8FAD, 0xC2A0, 0x8F7D, 0xC2F8, 0x8F4D, 0xC351, + 0x8F1D, 0xC3A9, 0x8EEE, 0xC402, 0x8EBF, 0xC45B, 0x8E90, 0xC4B4, + 0x8E62, 0xC50D, 0x8E34, 0xC566, 0x8E06, 0xC5C0, 0x8DD8, 0xC619, + 0x8DAB, 0xC673, 0x8D7E, 0xC6CD, 0x8D51, 0xC727, 0x8D24, 0xC781, + 0x8CF8, 0xC7DB, 0x8CCC, 0xC836, 0x8CA1, 0xC890, 0x8C75, 0xC8EB, + 0x8C4A, 0xC946, 0x8C1F, 0xC9A1, 0x8BF5, 0xC9FC, 0x8BCA, 0xCA57, + 0x8BA0, 0xCAB2, 0x8B77, 0xCB0E, 0x8B4D, 0xCB69, 0x8B24, 0xCBC5, + 0x8AFB, 0xCC21, 0x8AD3, 0xCC7D, 0x8AAA, 0xCCD9, 0x8A82, 0xCD35, + 0x8A5A, 0xCD92, 0x8A33, 0xCDEE, 0x8A0C, 0xCE4B, 0x89E5, 0xCEA7, + 0x89BE, 0xCF04, 0x8998, 0xCF61, 0x8972, 0xCFBE, 0x894C, 0xD01B, + 0x8927, 0xD079, 0x8902, 0xD0D6, 0x88DD, 0xD134, 0x88B8, 0xD191, + 0x8894, 0xD1EF, 0x8870, 0xD24D, 0x884C, 0xD2AB, 0x8828, 0xD309, + 0x8805, 0xD367, 0x87E2, 0xD3C5, 0x87C0, 0xD424, 0x879D, 0xD482, + 0x877B, 0xD4E1, 0x875A, 0xD53F, 0x8738, 0xD59E, 0x8717, 0xD5FD, + 0x86F6, 0xD65C, 0x86D6, 0xD6BB, 0x86B6, 0xD71B, 0x8696, 0xD77A, + 0x8676, 0xD7D9, 0x8656, 0xD839, 0x8637, 0xD898, 0x8619, 0xD8F8, + 0x85FA, 0xD958, 0x85DC, 0xD9B8, 0x85BE, 0xDA18, 0x85A0, 0xDA78, + 0x8583, 0xDAD8, 0x8566, 0xDB38, 0x8549, 0xDB99, 0x852D, 0xDBF9, + 0x8511, 0xDC59, 0x84F5, 0xDCBA, 0x84D9, 0xDD1B, 0x84BE, 0xDD7C, + 0x84A3, 0xDDDC, 0x8488, 0xDE3D, 0x846E, 0xDE9E, 0x8454, 0xDEFF, + 0x843A, 0xDF61, 0x8421, 0xDFC2, 0x8407, 0xE023, 0x83EF, 0xE085, + 0x83D6, 0xE0E6, 0x83BE, 0xE148, 0x83A6, 0xE1A9, 0x838E, 0xE20B, + 0x8377, 0xE26D, 0x8360, 0xE2CF, 0x8349, 0xE330, 0x8332, 0xE392, + 0x831C, 0xE3F4, 0x8306, 0xE457, 0x82F1, 0xE4B9, 0x82DB, 0xE51B, + 0x82C6, 0xE57D, 0x82B2, 0xE5E0, 0x829D, 0xE642, 0x8289, 0xE6A5, + 0x8276, 0xE707, 0x8262, 0xE76A, 0x824F, 0xE7CD, 0x823C, 0xE82F, + 0x822A, 0xE892, 0x8217, 0xE8F5, 0x8205, 0xE958, 0x81F4, 0xE9BB, + 0x81E2, 0xEA1E, 0x81D1, 0xEA81, 0x81C1, 0xEAE4, 0x81B0, 0xEB47, + 0x81A0, 0xEBAB, 0x8190, 0xEC0E, 0x8181, 0xEC71, 0x8172, 0xECD5, + 0x8163, 0xED38, 0x8154, 0xED9B, 0x8146, 0xEDFF, 0x8138, 0xEE62, + 0x812A, 0xEEC6, 0x811D, 0xEF2A, 0x8110, 0xEF8D, 0x8103, 0xEFF1, + 0x80F6, 0xF055, 0x80EA, 0xF0B9, 0x80DE, 0xF11C, 0x80D3, 0xF180, + 0x80C8, 0xF1E4, 0x80BD, 0xF248, 0x80B2, 0xF2AC, 0x80A8, 0xF310, + 0x809E, 0xF374, 0x8094, 0xF3D8, 0x808B, 0xF43C, 0x8082, 0xF4A0, + 0x8079, 0xF505, 0x8070, 0xF569, 0x8068, 0xF5CD, 0x8060, 0xF631, + 0x8059, 0xF695, 0x8052, 0xF6FA, 0x804B, 0xF75E, 0x8044, 0xF7C2, + 0x803E, 0xF827, 0x8038, 0xF88B, 0x8032, 0xF8EF, 0x802D, 0xF954, + 0x8027, 0xF9B8, 0x8023, 0xFA1D, 0x801E, 0xFA81, 0x801A, 0xFAE5, + 0x8016, 0xFB4A, 0x8013, 0xFBAE, 0x800F, 0xFC13, 0x800C, 0xFC77, + 0x800A, 0xFCDC, 0x8008, 0xFD40, 0x8006, 0xFDA5, 0x8004, 0xFE09, + 0x8002, 0xFE6E, 0x8001, 0xFED2, 0x8001, 0xFF37, 0x8001, 0xFF9B +}; + +/* + * FFT twiddle factor table for length of 4096. + */ +const _q15 msp_cmplx_twiddle_table_4096_q15[DSPLIB_TABLE_OFFSET+4096] = { + 0x1000, 0x0000, + 0x7FFF, 0x0000, 0x7FFF, 0xFFCE, 0x7FFF, 0xFF9B, 0x7FFF, 0xFF69, + 0x7FFF, 0xFF37, 0x7FFF, 0xFF05, 0x7FFF, 0xFED2, 0x7FFE, 0xFEA0, + 0x7FFE, 0xFE6E, 0x7FFD, 0xFE3C, 0x7FFC, 0xFE09, 0x7FFB, 0xFDD7, + 0x7FFA, 0xFDA5, 0x7FF9, 0xFD73, 0x7FF8, 0xFD40, 0x7FF7, 0xFD0E, + 0x7FF6, 0xFCDC, 0x7FF5, 0xFCAA, 0x7FF4, 0xFC77, 0x7FF2, 0xFC45, + 0x7FF1, 0xFC13, 0x7FEF, 0xFBE1, 0x7FED, 0xFBAE, 0x7FEC, 0xFB7C, + 0x7FEA, 0xFB4A, 0x7FE8, 0xFB18, 0x7FE6, 0xFAE5, 0x7FE4, 0xFAB3, + 0x7FE2, 0xFA81, 0x7FE0, 0xFA4F, 0x7FDD, 0xFA1D, 0x7FDB, 0xF9EA, + 0x7FD9, 0xF9B8, 0x7FD6, 0xF986, 0x7FD3, 0xF954, 0x7FD1, 0xF922, + 0x7FCE, 0xF8EF, 0x7FCB, 0xF8BD, 0x7FC8, 0xF88B, 0x7FC5, 0xF859, + 0x7FC2, 0xF827, 0x7FBF, 0xF7F4, 0x7FBC, 0xF7C2, 0x7FB9, 0xF790, + 0x7FB5, 0xF75E, 0x7FB2, 0xF72C, 0x7FAE, 0xF6FA, 0x7FAB, 0xF6C8, + 0x7FA7, 0xF695, 0x7FA3, 0xF663, 0x7FA0, 0xF631, 0x7F9C, 0xF5FF, + 0x7F98, 0xF5CD, 0x7F94, 0xF59B, 0x7F90, 0xF569, 0x7F8B, 0xF537, + 0x7F87, 0xF505, 0x7F83, 0xF4D3, 0x7F7E, 0xF4A0, 0x7F7A, 0xF46E, + 0x7F75, 0xF43C, 0x7F71, 0xF40A, 0x7F6C, 0xF3D8, 0x7F67, 0xF3A6, + 0x7F62, 0xF374, 0x7F5D, 0xF342, 0x7F58, 0xF310, 0x7F53, 0xF2DE, + 0x7F4E, 0xF2AC, 0x7F49, 0xF27A, 0x7F43, 0xF248, 0x7F3E, 0xF216, + 0x7F38, 0xF1E4, 0x7F33, 0xF1B2, 0x7F2D, 0xF180, 0x7F27, 0xF14E, + 0x7F22, 0xF11C, 0x7F1C, 0xF0EB, 0x7F16, 0xF0B9, 0x7F10, 0xF087, + 0x7F0A, 0xF055, 0x7F03, 0xF023, 0x7EFD, 0xEFF1, 0x7EF7, 0xEFBF, + 0x7EF0, 0xEF8D, 0x7EEA, 0xEF5C, 0x7EE3, 0xEF2A, 0x7EDD, 0xEEF8, + 0x7ED6, 0xEEC6, 0x7ECF, 0xEE94, 0x7EC8, 0xEE62, 0x7EC1, 0xEE31, + 0x7EBA, 0xEDFF, 0x7EB3, 0xEDCD, 0x7EAC, 0xED9B, 0x7EA5, 0xED6A, + 0x7E9D, 0xED38, 0x7E96, 0xED06, 0x7E8E, 0xECD5, 0x7E87, 0xECA3, + 0x7E7F, 0xEC71, 0x7E78, 0xEC3F, 0x7E70, 0xEC0E, 0x7E68, 0xEBDC, + 0x7E60, 0xEBAB, 0x7E58, 0xEB79, 0x7E50, 0xEB47, 0x7E48, 0xEB16, + 0x7E3F, 0xEAE4, 0x7E37, 0xEAB3, 0x7E2F, 0xEA81, 0x7E26, 0xEA4F, + 0x7E1E, 0xEA1E, 0x7E15, 0xE9EC, 0x7E0C, 0xE9BB, 0x7E03, 0xE989, + 0x7DFB, 0xE958, 0x7DF2, 0xE926, 0x7DE9, 0xE8F5, 0x7DE0, 0xE8C4, + 0x7DD6, 0xE892, 0x7DCD, 0xE861, 0x7DC4, 0xE82F, 0x7DBA, 0xE7FE, + 0x7DB1, 0xE7CD, 0x7DA7, 0xE79B, 0x7D9E, 0xE76A, 0x7D94, 0xE739, + 0x7D8A, 0xE707, 0x7D81, 0xE6D6, 0x7D77, 0xE6A5, 0x7D6D, 0xE673, + 0x7D63, 0xE642, 0x7D58, 0xE611, 0x7D4E, 0xE5E0, 0x7D44, 0xE5AF, + 0x7D3A, 0xE57D, 0x7D2F, 0xE54C, 0x7D25, 0xE51B, 0x7D1A, 0xE4EA, + 0x7D0F, 0xE4B9, 0x7D05, 0xE488, 0x7CFA, 0xE457, 0x7CEF, 0xE426, + 0x7CE4, 0xE3F4, 0x7CD9, 0xE3C3, 0x7CCE, 0xE392, 0x7CC2, 0xE361, + 0x7CB7, 0xE330, 0x7CAC, 0xE2FF, 0x7CA0, 0xE2CF, 0x7C95, 0xE29E, + 0x7C89, 0xE26D, 0x7C7E, 0xE23C, 0x7C72, 0xE20B, 0x7C66, 0xE1DA, + 0x7C5A, 0xE1A9, 0x7C4E, 0xE178, 0x7C42, 0xE148, 0x7C36, 0xE117, + 0x7C2A, 0xE0E6, 0x7C1E, 0xE0B5, 0x7C11, 0xE085, 0x7C05, 0xE054, + 0x7BF9, 0xE023, 0x7BEC, 0xDFF2, 0x7BDF, 0xDFC2, 0x7BD3, 0xDF91, + 0x7BC6, 0xDF61, 0x7BB9, 0xDF30, 0x7BAC, 0xDEFF, 0x7B9F, 0xDECF, + 0x7B92, 0xDE9E, 0x7B85, 0xDE6E, 0x7B78, 0xDE3D, 0x7B6A, 0xDE0D, + 0x7B5D, 0xDDDC, 0x7B50, 0xDDAC, 0x7B42, 0xDD7C, 0x7B34, 0xDD4B, + 0x7B27, 0xDD1B, 0x7B19, 0xDCEA, 0x7B0B, 0xDCBA, 0x7AFD, 0xDC8A, + 0x7AEF, 0xDC59, 0x7AE1, 0xDC29, 0x7AD3, 0xDBF9, 0x7AC5, 0xDBC9, + 0x7AB7, 0xDB99, 0x7AA8, 0xDB68, 0x7A9A, 0xDB38, 0x7A8C, 0xDB08, + 0x7A7D, 0xDAD8, 0x7A6E, 0xDAA8, 0x7A60, 0xDA78, 0x7A51, 0xDA48, + 0x7A42, 0xDA18, 0x7A33, 0xD9E8, 0x7A24, 0xD9B8, 0x7A15, 0xD988, + 0x7A06, 0xD958, 0x79F7, 0xD928, 0x79E7, 0xD8F8, 0x79D8, 0xD8C8, + 0x79C9, 0xD898, 0x79B9, 0xD869, 0x79AA, 0xD839, 0x799A, 0xD809, + 0x798A, 0xD7D9, 0x797A, 0xD7AA, 0x796A, 0xD77A, 0x795B, 0xD74A, + 0x794A, 0xD71B, 0x793A, 0xD6EB, 0x792A, 0xD6BB, 0x791A, 0xD68C, + 0x790A, 0xD65C, 0x78F9, 0xD62D, 0x78E9, 0xD5FD, 0x78D8, 0xD5CE, + 0x78C8, 0xD59E, 0x78B7, 0xD56F, 0x78A6, 0xD53F, 0x7895, 0xD510, + 0x7885, 0xD4E1, 0x7874, 0xD4B1, 0x7863, 0xD482, 0x7851, 0xD453, + 0x7840, 0xD424, 0x782F, 0xD3F4, 0x781E, 0xD3C5, 0x780C, 0xD396, + 0x77FB, 0xD367, 0x77E9, 0xD338, 0x77D8, 0xD309, 0x77C6, 0xD2DA, + 0x77B4, 0xD2AB, 0x77A2, 0xD27C, 0x7790, 0xD24D, 0x777E, 0xD21E, + 0x776C, 0xD1EF, 0x775A, 0xD1C0, 0x7748, 0xD191, 0x7736, 0xD162, + 0x7723, 0xD134, 0x7711, 0xD105, 0x76FE, 0xD0D6, 0x76EC, 0xD0A7, + 0x76D9, 0xD079, 0x76C7, 0xD04A, 0x76B4, 0xD01B, 0x76A1, 0xCFED, + 0x768E, 0xCFBE, 0x767B, 0xCF90, 0x7668, 0xCF61, 0x7655, 0xCF33, + 0x7642, 0xCF04, 0x762E, 0xCED6, 0x761B, 0xCEA7, 0x7608, 0xCE79, + 0x75F4, 0xCE4B, 0x75E1, 0xCE1C, 0x75CD, 0xCDEE, 0x75B9, 0xCDC0, + 0x75A6, 0xCD92, 0x7592, 0xCD63, 0x757E, 0xCD35, 0x756A, 0xCD07, + 0x7556, 0xCCD9, 0x7542, 0xCCAB, 0x752D, 0xCC7D, 0x7519, 0xCC4F, + 0x7505, 0xCC21, 0x74F0, 0xCBF3, 0x74DC, 0xCBC5, 0x74C7, 0xCB97, + 0x74B3, 0xCB69, 0x749E, 0xCB3C, 0x7489, 0xCB0E, 0x7475, 0xCAE0, + 0x7460, 0xCAB2, 0x744B, 0xCA85, 0x7436, 0xCA57, 0x7421, 0xCA29, + 0x740B, 0xC9FC, 0x73F6, 0xC9CE, 0x73E1, 0xC9A1, 0x73CB, 0xC973, + 0x73B6, 0xC946, 0x73A0, 0xC918, 0x738B, 0xC8EB, 0x7375, 0xC8BE, + 0x735F, 0xC890, 0x734A, 0xC863, 0x7334, 0xC836, 0x731E, 0xC809, + 0x7308, 0xC7DB, 0x72F2, 0xC7AE, 0x72DC, 0xC781, 0x72C5, 0xC754, + 0x72AF, 0xC727, 0x7299, 0xC6FA, 0x7282, 0xC6CD, 0x726C, 0xC6A0, + 0x7255, 0xC673, 0x723F, 0xC646, 0x7228, 0xC619, 0x7211, 0xC5ED, + 0x71FA, 0xC5C0, 0x71E3, 0xC593, 0x71CC, 0xC566, 0x71B5, 0xC53A, + 0x719E, 0xC50D, 0x7187, 0xC4E0, 0x7170, 0xC4B4, 0x7158, 0xC487, + 0x7141, 0xC45B, 0x712A, 0xC42E, 0x7112, 0xC402, 0x70FA, 0xC3D6, + 0x70E3, 0xC3A9, 0x70CB, 0xC37D, 0x70B3, 0xC351, 0x709B, 0xC324, + 0x7083, 0xC2F8, 0x706B, 0xC2CC, 0x7053, 0xC2A0, 0x703B, 0xC274, + 0x7023, 0xC248, 0x700B, 0xC21C, 0x6FF2, 0xC1F0, 0x6FDA, 0xC1C4, + 0x6FC2, 0xC198, 0x6FA9, 0xC16C, 0x6F90, 0xC140, 0x6F78, 0xC114, + 0x6F5F, 0xC0E9, 0x6F46, 0xC0BD, 0x6F2D, 0xC091, 0x6F14, 0xC066, + 0x6EFB, 0xC03A, 0x6EE2, 0xC00F, 0x6EC9, 0xBFE3, 0x6EB0, 0xBFB8, + 0x6E97, 0xBF8C, 0x6E7D, 0xBF61, 0x6E64, 0xBF35, 0x6E4A, 0xBF0A, + 0x6E31, 0xBEDF, 0x6E17, 0xBEB3, 0x6DFE, 0xBE88, 0x6DE4, 0xBE5D, + 0x6DCA, 0xBE32, 0x6DB0, 0xBE07, 0x6D96, 0xBDDC, 0x6D7C, 0xBDB1, + 0x6D62, 0xBD86, 0x6D48, 0xBD5B, 0x6D2E, 0xBD30, 0x6D14, 0xBD05, + 0x6CF9, 0xBCDA, 0x6CDF, 0xBCAF, 0x6CC4, 0xBC85, 0x6CAA, 0xBC5A, + 0x6C8F, 0xBC2F, 0x6C75, 0xBC05, 0x6C5A, 0xBBDA, 0x6C3F, 0xBBB0, + 0x6C24, 0xBB85, 0x6C09, 0xBB5B, 0x6BEE, 0xBB30, 0x6BD3, 0xBB06, + 0x6BB8, 0xBADC, 0x6B9D, 0xBAB1, 0x6B82, 0xBA87, 0x6B66, 0xBA5D, + 0x6B4B, 0xBA33, 0x6B30, 0xBA09, 0x6B14, 0xB9DF, 0x6AF8, 0xB9B5, + 0x6ADD, 0xB98B, 0x6AC1, 0xB961, 0x6AA5, 0xB937, 0x6A89, 0xB90D, + 0x6A6E, 0xB8E3, 0x6A52, 0xB8B9, 0x6A36, 0xB890, 0x6A1A, 0xB866, + 0x69FD, 0xB83C, 0x69E1, 0xB813, 0x69C5, 0xB7E9, 0x69A9, 0xB7C0, + 0x698C, 0xB796, 0x6970, 0xB76D, 0x6953, 0xB743, 0x6937, 0xB71A, + 0x691A, 0xB6F1, 0x68FD, 0xB6C7, 0x68E0, 0xB69E, 0x68C4, 0xB675, + 0x68A7, 0xB64C, 0x688A, 0xB623, 0x686D, 0xB5FA, 0x6850, 0xB5D1, + 0x6832, 0xB5A8, 0x6815, 0xB57F, 0x67F8, 0xB556, 0x67DA, 0xB52D, + 0x67BD, 0xB505, 0x67A0, 0xB4DC, 0x6782, 0xB4B3, 0x6764, 0xB48B, + 0x6747, 0xB462, 0x6729, 0xB439, 0x670B, 0xB411, 0x66ED, 0xB3E9, + 0x66D0, 0xB3C0, 0x66B2, 0xB398, 0x6693, 0xB36F, 0x6675, 0xB347, + 0x6657, 0xB31F, 0x6639, 0xB2F7, 0x661B, 0xB2CF, 0x65FC, 0xB2A7, + 0x65DE, 0xB27F, 0x65C0, 0xB257, 0x65A1, 0xB22F, 0x6582, 0xB207, + 0x6564, 0xB1DF, 0x6545, 0xB1B7, 0x6526, 0xB18F, 0x6507, 0xB168, + 0x64E9, 0xB140, 0x64CA, 0xB118, 0x64AB, 0xB0F1, 0x648B, 0xB0C9, + 0x646C, 0xB0A2, 0x644D, 0xB07B, 0x642E, 0xB053, 0x640F, 0xB02C, + 0x63EF, 0xB005, 0x63D0, 0xAFDD, 0x63B0, 0xAFB6, 0x6391, 0xAF8F, + 0x6371, 0xAF68, 0x6351, 0xAF41, 0x6332, 0xAF1A, 0x6312, 0xAEF3, + 0x62F2, 0xAECC, 0x62D2, 0xAEA5, 0x62B2, 0xAE7F, 0x6292, 0xAE58, + 0x6272, 0xAE31, 0x6252, 0xAE0B, 0x6232, 0xADE4, 0x6211, 0xADBD, + 0x61F1, 0xAD97, 0x61D1, 0xAD70, 0x61B0, 0xAD4A, 0x6190, 0xAD24, + 0x616F, 0xACFD, 0x614E, 0xACD7, 0x612E, 0xACB1, 0x610D, 0xAC8B, + 0x60EC, 0xAC65, 0x60CB, 0xAC3F, 0x60AA, 0xAC19, 0x6089, 0xABF3, + 0x6068, 0xABCD, 0x6047, 0xABA7, 0x6026, 0xAB81, 0x6005, 0xAB5C, + 0x5FE4, 0xAB36, 0x5FC2, 0xAB10, 0x5FA1, 0xAAEB, 0x5F80, 0xAAC5, + 0x5F5E, 0xAAA0, 0x5F3C, 0xAA7A, 0x5F1B, 0xAA55, 0x5EF9, 0xAA30, + 0x5ED7, 0xAA0A, 0x5EB6, 0xA9E5, 0x5E94, 0xA9C0, 0x5E72, 0xA99B, + 0x5E50, 0xA976, 0x5E2E, 0xA951, 0x5E0C, 0xA92C, 0x5DEA, 0xA907, + 0x5DC8, 0xA8E2, 0x5DA5, 0xA8BD, 0x5D83, 0xA899, 0x5D61, 0xA874, + 0x5D3E, 0xA84F, 0x5D1C, 0xA82B, 0x5CF9, 0xA806, 0x5CD7, 0xA7E2, + 0x5CB4, 0xA7BD, 0x5C91, 0xA799, 0x5C6F, 0xA774, 0x5C4C, 0xA750, + 0x5C29, 0xA72C, 0x5C06, 0xA708, 0x5BE3, 0xA6E4, 0x5BC0, 0xA6C0, + 0x5B9D, 0xA69C, 0x5B7A, 0xA678, 0x5B57, 0xA654, 0x5B34, 0xA630, + 0x5B10, 0xA60C, 0x5AED, 0xA5E8, 0x5AC9, 0xA5C5, 0x5AA6, 0xA5A1, + 0x5A82, 0xA57E, 0x5A5F, 0xA55A, 0x5A3B, 0xA537, 0x5A18, 0xA513, + 0x59F4, 0xA4F0, 0x59D0, 0xA4CC, 0x59AC, 0xA4A9, 0x5988, 0xA486, + 0x5964, 0xA463, 0x5940, 0xA440, 0x591C, 0xA41D, 0x58F8, 0xA3FA, + 0x58D4, 0xA3D7, 0x58B0, 0xA3B4, 0x588C, 0xA391, 0x5867, 0xA36F, + 0x5843, 0xA34C, 0x581E, 0xA329, 0x57FA, 0xA307, 0x57D5, 0xA2E4, + 0x57B1, 0xA2C2, 0x578C, 0xA29F, 0x5767, 0xA27D, 0x5743, 0xA25B, + 0x571E, 0xA238, 0x56F9, 0xA216, 0x56D4, 0xA1F4, 0x56AF, 0xA1D2, + 0x568A, 0xA1B0, 0x5665, 0xA18E, 0x5640, 0xA16C, 0x561B, 0xA14A, + 0x55F6, 0xA129, 0x55D0, 0xA107, 0x55AB, 0xA0E5, 0x5586, 0xA0C4, + 0x5560, 0xA0A2, 0x553B, 0xA080, 0x5515, 0xA05F, 0x54F0, 0xA03E, + 0x54CA, 0xA01C, 0x54A4, 0x9FFB, 0x547F, 0x9FDA, 0x5459, 0x9FB9, + 0x5433, 0x9F98, 0x540D, 0x9F77, 0x53E7, 0x9F56, 0x53C1, 0x9F35, + 0x539B, 0x9F14, 0x5375, 0x9EF3, 0x534F, 0x9ED2, 0x5329, 0x9EB2, + 0x5303, 0x9E91, 0x52DC, 0x9E70, 0x52B6, 0x9E50, 0x5290, 0x9E2F, + 0x5269, 0x9E0F, 0x5243, 0x9DEF, 0x521C, 0x9DCE, 0x51F5, 0x9DAE, + 0x51CF, 0x9D8E, 0x51A8, 0x9D6E, 0x5181, 0x9D4E, 0x515B, 0x9D2E, + 0x5134, 0x9D0E, 0x510D, 0x9CEE, 0x50E6, 0x9CCE, 0x50BF, 0x9CAF, + 0x5098, 0x9C8F, 0x5071, 0x9C6F, 0x504A, 0x9C50, 0x5023, 0x9C30, + 0x4FFB, 0x9C11, 0x4FD4, 0x9BF1, 0x4FAD, 0x9BD2, 0x4F85, 0x9BB3, + 0x4F5E, 0x9B94, 0x4F37, 0x9B75, 0x4F0F, 0x9B55, 0x4EE8, 0x9B36, + 0x4EC0, 0x9B17, 0x4E98, 0x9AF9, 0x4E71, 0x9ADA, 0x4E49, 0x9ABB, + 0x4E21, 0x9A9C, 0x4DF9, 0x9A7E, 0x4DD1, 0x9A5F, 0x4DA9, 0x9A40, + 0x4D81, 0x9A22, 0x4D59, 0x9A04, 0x4D31, 0x99E5, 0x4D09, 0x99C7, + 0x4CE1, 0x99A9, 0x4CB9, 0x998B, 0x4C91, 0x996D, 0x4C68, 0x994E, + 0x4C40, 0x9930, 0x4C17, 0x9913, 0x4BEF, 0x98F5, 0x4BC7, 0x98D7, + 0x4B9E, 0x98B9, 0x4B75, 0x989C, 0x4B4D, 0x987E, 0x4B24, 0x9860, + 0x4AFB, 0x9843, 0x4AD3, 0x9826, 0x4AAA, 0x9808, 0x4A81, 0x97EB, + 0x4A58, 0x97CE, 0x4A2F, 0x97B0, 0x4A06, 0x9793, 0x49DD, 0x9776, + 0x49B4, 0x9759, 0x498B, 0x973C, 0x4962, 0x9720, 0x4939, 0x9703, + 0x490F, 0x96E6, 0x48E6, 0x96C9, 0x48BD, 0x96AD, 0x4893, 0x9690, + 0x486A, 0x9674, 0x4840, 0x9657, 0x4817, 0x963B, 0x47ED, 0x961F, + 0x47C4, 0x9603, 0x479A, 0x95E6, 0x4770, 0x95CA, 0x4747, 0x95AE, + 0x471D, 0x9592, 0x46F3, 0x9577, 0x46C9, 0x955B, 0x469F, 0x953F, + 0x4675, 0x9523, 0x464B, 0x9508, 0x4621, 0x94EC, 0x45F7, 0x94D0, + 0x45CD, 0x94B5, 0x45A3, 0x949A, 0x4579, 0x947E, 0x454F, 0x9463, + 0x4524, 0x9448, 0x44FA, 0x942D, 0x44D0, 0x9412, 0x44A5, 0x93F7, + 0x447B, 0x93DC, 0x4450, 0x93C1, 0x4426, 0x93A6, 0x43FB, 0x938B, + 0x43D1, 0x9371, 0x43A6, 0x9356, 0x437B, 0x933C, 0x4351, 0x9321, + 0x4326, 0x9307, 0x42FB, 0x92EC, 0x42D0, 0x92D2, 0x42A5, 0x92B8, + 0x427A, 0x929E, 0x424F, 0x9284, 0x4224, 0x926A, 0x41F9, 0x9250, + 0x41CE, 0x9236, 0x41A3, 0x921C, 0x4178, 0x9202, 0x414D, 0x91E9, + 0x4121, 0x91CF, 0x40F6, 0x91B6, 0x40CB, 0x919C, 0x409F, 0x9183, + 0x4074, 0x9169, 0x4048, 0x9150, 0x401D, 0x9137, 0x3FF1, 0x911E, + 0x3FC6, 0x9105, 0x3F9A, 0x90EC, 0x3F6F, 0x90D3, 0x3F43, 0x90BA, + 0x3F17, 0x90A1, 0x3EEC, 0x9088, 0x3EC0, 0x9070, 0x3E94, 0x9057, + 0x3E68, 0x903E, 0x3E3C, 0x9026, 0x3E10, 0x900E, 0x3DE4, 0x8FF5, + 0x3DB8, 0x8FDD, 0x3D8C, 0x8FC5, 0x3D60, 0x8FAD, 0x3D34, 0x8F95, + 0x3D08, 0x8F7D, 0x3CDC, 0x8F65, 0x3CAF, 0x8F4D, 0x3C83, 0x8F35, + 0x3C57, 0x8F1D, 0x3C2A, 0x8F06, 0x3BFE, 0x8EEE, 0x3BD2, 0x8ED6, + 0x3BA5, 0x8EBF, 0x3B79, 0x8EA8, 0x3B4C, 0x8E90, 0x3B20, 0x8E79, + 0x3AF3, 0x8E62, 0x3AC6, 0x8E4B, 0x3A9A, 0x8E34, 0x3A6D, 0x8E1D, + 0x3A40, 0x8E06, 0x3A13, 0x8DEF, 0x39E7, 0x8DD8, 0x39BA, 0x8DC1, + 0x398D, 0x8DAB, 0x3960, 0x8D94, 0x3933, 0x8D7E, 0x3906, 0x8D67, + 0x38D9, 0x8D51, 0x38AC, 0x8D3B, 0x387F, 0x8D24, 0x3852, 0x8D0E, + 0x3825, 0x8CF8, 0x37F7, 0x8CE2, 0x37CA, 0x8CCC, 0x379D, 0x8CB6, + 0x3770, 0x8CA1, 0x3742, 0x8C8B, 0x3715, 0x8C75, 0x36E8, 0x8C60, + 0x36BA, 0x8C4A, 0x368D, 0x8C35, 0x365F, 0x8C1F, 0x3632, 0x8C0A, + 0x3604, 0x8BF5, 0x35D7, 0x8BDF, 0x35A9, 0x8BCA, 0x357B, 0x8BB5, + 0x354E, 0x8BA0, 0x3520, 0x8B8B, 0x34F2, 0x8B77, 0x34C4, 0x8B62, + 0x3497, 0x8B4D, 0x3469, 0x8B39, 0x343B, 0x8B24, 0x340D, 0x8B10, + 0x33DF, 0x8AFB, 0x33B1, 0x8AE7, 0x3383, 0x8AD3, 0x3355, 0x8ABE, + 0x3327, 0x8AAA, 0x32F9, 0x8A96, 0x32CB, 0x8A82, 0x329D, 0x8A6E, + 0x326E, 0x8A5A, 0x3240, 0x8A47, 0x3212, 0x8A33, 0x31E4, 0x8A1F, + 0x31B5, 0x8A0C, 0x3187, 0x89F8, 0x3159, 0x89E5, 0x312A, 0x89D2, + 0x30FC, 0x89BE, 0x30CD, 0x89AB, 0x309F, 0x8998, 0x3070, 0x8985, + 0x3042, 0x8972, 0x3013, 0x895F, 0x2FE5, 0x894C, 0x2FB6, 0x8939, + 0x2F87, 0x8927, 0x2F59, 0x8914, 0x2F2A, 0x8902, 0x2EFB, 0x88EF, + 0x2ECC, 0x88DD, 0x2E9E, 0x88CA, 0x2E6F, 0x88B8, 0x2E40, 0x88A6, + 0x2E11, 0x8894, 0x2DE2, 0x8882, 0x2DB3, 0x8870, 0x2D84, 0x885E, + 0x2D55, 0x884C, 0x2D26, 0x883A, 0x2CF7, 0x8828, 0x2CC8, 0x8817, + 0x2C99, 0x8805, 0x2C6A, 0x87F4, 0x2C3B, 0x87E2, 0x2C0C, 0x87D1, + 0x2BDC, 0x87C0, 0x2BAD, 0x87AF, 0x2B7E, 0x879D, 0x2B4F, 0x878C, + 0x2B1F, 0x877B, 0x2AF0, 0x876B, 0x2AC1, 0x875A, 0x2A91, 0x8749, + 0x2A62, 0x8738, 0x2A32, 0x8728, 0x2A03, 0x8717, 0x29D3, 0x8707, + 0x29A4, 0x86F6, 0x2974, 0x86E6, 0x2945, 0x86D6, 0x2915, 0x86C6, + 0x28E5, 0x86B6, 0x28B6, 0x86A5, 0x2886, 0x8696, 0x2856, 0x8686, + 0x2827, 0x8676, 0x27F7, 0x8666, 0x27C7, 0x8656, 0x2797, 0x8647, + 0x2768, 0x8637, 0x2738, 0x8628, 0x2708, 0x8619, 0x26D8, 0x8609, + 0x26A8, 0x85FA, 0x2678, 0x85EB, 0x2648, 0x85DC, 0x2618, 0x85CD, + 0x25E8, 0x85BE, 0x25B8, 0x85AF, 0x2588, 0x85A0, 0x2558, 0x8592, + 0x2528, 0x8583, 0x24F8, 0x8574, 0x24C8, 0x8566, 0x2498, 0x8558, + 0x2467, 0x8549, 0x2437, 0x853B, 0x2407, 0x852D, 0x23D7, 0x851F, + 0x23A7, 0x8511, 0x2376, 0x8503, 0x2346, 0x84F5, 0x2316, 0x84E7, + 0x22E5, 0x84D9, 0x22B5, 0x84CC, 0x2284, 0x84BE, 0x2254, 0x84B0, + 0x2224, 0x84A3, 0x21F3, 0x8496, 0x21C3, 0x8488, 0x2192, 0x847B, + 0x2162, 0x846E, 0x2131, 0x8461, 0x2101, 0x8454, 0x20D0, 0x8447, + 0x209F, 0x843A, 0x206F, 0x842D, 0x203E, 0x8421, 0x200E, 0x8414, + 0x1FDD, 0x8407, 0x1FAC, 0x83FB, 0x1F7B, 0x83EF, 0x1F4B, 0x83E2, + 0x1F1A, 0x83D6, 0x1EE9, 0x83CA, 0x1EB8, 0x83BE, 0x1E88, 0x83B2, + 0x1E57, 0x83A6, 0x1E26, 0x839A, 0x1DF5, 0x838E, 0x1DC4, 0x8382, + 0x1D93, 0x8377, 0x1D62, 0x836B, 0x1D31, 0x8360, 0x1D01, 0x8354, + 0x1CD0, 0x8349, 0x1C9F, 0x833E, 0x1C6E, 0x8332, 0x1C3D, 0x8327, + 0x1C0C, 0x831C, 0x1BDA, 0x8311, 0x1BA9, 0x8306, 0x1B78, 0x82FB, + 0x1B47, 0x82F1, 0x1B16, 0x82E6, 0x1AE5, 0x82DB, 0x1AB4, 0x82D1, + 0x1A83, 0x82C6, 0x1A51, 0x82BC, 0x1A20, 0x82B2, 0x19EF, 0x82A8, + 0x19BE, 0x829D, 0x198D, 0x8293, 0x195B, 0x8289, 0x192A, 0x827F, + 0x18F9, 0x8276, 0x18C7, 0x826C, 0x1896, 0x8262, 0x1865, 0x8259, + 0x1833, 0x824F, 0x1802, 0x8246, 0x17D1, 0x823C, 0x179F, 0x8233, + 0x176E, 0x822A, 0x173C, 0x8220, 0x170B, 0x8217, 0x16DA, 0x820E, + 0x16A8, 0x8205, 0x1677, 0x81FD, 0x1645, 0x81F4, 0x1614, 0x81EB, + 0x15E2, 0x81E2, 0x15B1, 0x81DA, 0x157F, 0x81D1, 0x154D, 0x81C9, + 0x151C, 0x81C1, 0x14EA, 0x81B8, 0x14B9, 0x81B0, 0x1487, 0x81A8, + 0x1455, 0x81A0, 0x1424, 0x8198, 0x13F2, 0x8190, 0x13C1, 0x8188, + 0x138F, 0x8181, 0x135D, 0x8179, 0x132B, 0x8172, 0x12FA, 0x816A, + 0x12C8, 0x8163, 0x1296, 0x815B, 0x1265, 0x8154, 0x1233, 0x814D, + 0x1201, 0x8146, 0x11CF, 0x813F, 0x119E, 0x8138, 0x116C, 0x8131, + 0x113A, 0x812A, 0x1108, 0x8123, 0x10D6, 0x811D, 0x10A4, 0x8116, + 0x1073, 0x8110, 0x1041, 0x8109, 0x100F, 0x8103, 0x0FDD, 0x80FD, + 0x0FAB, 0x80F6, 0x0F79, 0x80F0, 0x0F47, 0x80EA, 0x0F15, 0x80E4, + 0x0EE4, 0x80DE, 0x0EB2, 0x80D9, 0x0E80, 0x80D3, 0x0E4E, 0x80CD, + 0x0E1C, 0x80C8, 0x0DEA, 0x80C2, 0x0DB8, 0x80BD, 0x0D86, 0x80B7, + 0x0D54, 0x80B2, 0x0D22, 0x80AD, 0x0CF0, 0x80A8, 0x0CBE, 0x80A3, + 0x0C8C, 0x809E, 0x0C5A, 0x8099, 0x0C28, 0x8094, 0x0BF6, 0x808F, + 0x0BC4, 0x808B, 0x0B92, 0x8086, 0x0B60, 0x8082, 0x0B2D, 0x807D, + 0x0AFB, 0x8079, 0x0AC9, 0x8075, 0x0A97, 0x8070, 0x0A65, 0x806C, + 0x0A33, 0x8068, 0x0A01, 0x8064, 0x09CF, 0x8060, 0x099D, 0x805D, + 0x096B, 0x8059, 0x0938, 0x8055, 0x0906, 0x8052, 0x08D4, 0x804E, + 0x08A2, 0x804B, 0x0870, 0x8047, 0x083E, 0x8044, 0x080C, 0x8041, + 0x07D9, 0x803E, 0x07A7, 0x803B, 0x0775, 0x8038, 0x0743, 0x8035, + 0x0711, 0x8032, 0x06DE, 0x802F, 0x06AC, 0x802D, 0x067A, 0x802A, + 0x0648, 0x8027, 0x0616, 0x8025, 0x05E3, 0x8023, 0x05B1, 0x8020, + 0x057F, 0x801E, 0x054D, 0x801C, 0x051B, 0x801A, 0x04E8, 0x8018, + 0x04B6, 0x8016, 0x0484, 0x8014, 0x0452, 0x8013, 0x041F, 0x8011, + 0x03ED, 0x800F, 0x03BB, 0x800E, 0x0389, 0x800C, 0x0356, 0x800B, + 0x0324, 0x800A, 0x02F2, 0x8009, 0x02C0, 0x8008, 0x028D, 0x8007, + 0x025B, 0x8006, 0x0229, 0x8005, 0x01F7, 0x8004, 0x01C4, 0x8003, + 0x0192, 0x8002, 0x0160, 0x8002, 0x012E, 0x8001, 0x00FB, 0x8001, + 0x00C9, 0x8001, 0x0097, 0x8001, 0x0065, 0x8001, 0x0032, 0x8001, + 0x0000, 0x8001, 0xFFCE, 0x8001, 0xFF9B, 0x8001, 0xFF69, 0x8001, + 0xFF37, 0x8001, 0xFF05, 0x8001, 0xFED2, 0x8001, 0xFEA0, 0x8002, + 0xFE6E, 0x8002, 0xFE3C, 0x8003, 0xFE09, 0x8004, 0xFDD7, 0x8005, + 0xFDA5, 0x8006, 0xFD73, 0x8007, 0xFD40, 0x8008, 0xFD0E, 0x8009, + 0xFCDC, 0x800A, 0xFCAA, 0x800B, 0xFC77, 0x800C, 0xFC45, 0x800E, + 0xFC13, 0x800F, 0xFBE1, 0x8011, 0xFBAE, 0x8013, 0xFB7C, 0x8014, + 0xFB4A, 0x8016, 0xFB18, 0x8018, 0xFAE5, 0x801A, 0xFAB3, 0x801C, + 0xFA81, 0x801E, 0xFA4F, 0x8020, 0xFA1D, 0x8023, 0xF9EA, 0x8025, + 0xF9B8, 0x8027, 0xF986, 0x802A, 0xF954, 0x802D, 0xF922, 0x802F, + 0xF8EF, 0x8032, 0xF8BD, 0x8035, 0xF88B, 0x8038, 0xF859, 0x803B, + 0xF827, 0x803E, 0xF7F4, 0x8041, 0xF7C2, 0x8044, 0xF790, 0x8047, + 0xF75E, 0x804B, 0xF72C, 0x804E, 0xF6FA, 0x8052, 0xF6C8, 0x8055, + 0xF695, 0x8059, 0xF663, 0x805D, 0xF631, 0x8060, 0xF5FF, 0x8064, + 0xF5CD, 0x8068, 0xF59B, 0x806C, 0xF569, 0x8070, 0xF537, 0x8075, + 0xF505, 0x8079, 0xF4D3, 0x807D, 0xF4A0, 0x8082, 0xF46E, 0x8086, + 0xF43C, 0x808B, 0xF40A, 0x808F, 0xF3D8, 0x8094, 0xF3A6, 0x8099, + 0xF374, 0x809E, 0xF342, 0x80A3, 0xF310, 0x80A8, 0xF2DE, 0x80AD, + 0xF2AC, 0x80B2, 0xF27A, 0x80B7, 0xF248, 0x80BD, 0xF216, 0x80C2, + 0xF1E4, 0x80C8, 0xF1B2, 0x80CD, 0xF180, 0x80D3, 0xF14E, 0x80D9, + 0xF11C, 0x80DE, 0xF0EB, 0x80E4, 0xF0B9, 0x80EA, 0xF087, 0x80F0, + 0xF055, 0x80F6, 0xF023, 0x80FD, 0xEFF1, 0x8103, 0xEFBF, 0x8109, + 0xEF8D, 0x8110, 0xEF5C, 0x8116, 0xEF2A, 0x811D, 0xEEF8, 0x8123, + 0xEEC6, 0x812A, 0xEE94, 0x8131, 0xEE62, 0x8138, 0xEE31, 0x813F, + 0xEDFF, 0x8146, 0xEDCD, 0x814D, 0xED9B, 0x8154, 0xED6A, 0x815B, + 0xED38, 0x8163, 0xED06, 0x816A, 0xECD5, 0x8172, 0xECA3, 0x8179, + 0xEC71, 0x8181, 0xEC3F, 0x8188, 0xEC0E, 0x8190, 0xEBDC, 0x8198, + 0xEBAB, 0x81A0, 0xEB79, 0x81A8, 0xEB47, 0x81B0, 0xEB16, 0x81B8, + 0xEAE4, 0x81C1, 0xEAB3, 0x81C9, 0xEA81, 0x81D1, 0xEA4F, 0x81DA, + 0xEA1E, 0x81E2, 0xE9EC, 0x81EB, 0xE9BB, 0x81F4, 0xE989, 0x81FD, + 0xE958, 0x8205, 0xE926, 0x820E, 0xE8F5, 0x8217, 0xE8C4, 0x8220, + 0xE892, 0x822A, 0xE861, 0x8233, 0xE82F, 0x823C, 0xE7FE, 0x8246, + 0xE7CD, 0x824F, 0xE79B, 0x8259, 0xE76A, 0x8262, 0xE739, 0x826C, + 0xE707, 0x8276, 0xE6D6, 0x827F, 0xE6A5, 0x8289, 0xE673, 0x8293, + 0xE642, 0x829D, 0xE611, 0x82A8, 0xE5E0, 0x82B2, 0xE5AF, 0x82BC, + 0xE57D, 0x82C6, 0xE54C, 0x82D1, 0xE51B, 0x82DB, 0xE4EA, 0x82E6, + 0xE4B9, 0x82F1, 0xE488, 0x82FB, 0xE457, 0x8306, 0xE426, 0x8311, + 0xE3F4, 0x831C, 0xE3C3, 0x8327, 0xE392, 0x8332, 0xE361, 0x833E, + 0xE330, 0x8349, 0xE2FF, 0x8354, 0xE2CF, 0x8360, 0xE29E, 0x836B, + 0xE26D, 0x8377, 0xE23C, 0x8382, 0xE20B, 0x838E, 0xE1DA, 0x839A, + 0xE1A9, 0x83A6, 0xE178, 0x83B2, 0xE148, 0x83BE, 0xE117, 0x83CA, + 0xE0E6, 0x83D6, 0xE0B5, 0x83E2, 0xE085, 0x83EF, 0xE054, 0x83FB, + 0xE023, 0x8407, 0xDFF2, 0x8414, 0xDFC2, 0x8421, 0xDF91, 0x842D, + 0xDF61, 0x843A, 0xDF30, 0x8447, 0xDEFF, 0x8454, 0xDECF, 0x8461, + 0xDE9E, 0x846E, 0xDE6E, 0x847B, 0xDE3D, 0x8488, 0xDE0D, 0x8496, + 0xDDDC, 0x84A3, 0xDDAC, 0x84B0, 0xDD7C, 0x84BE, 0xDD4B, 0x84CC, + 0xDD1B, 0x84D9, 0xDCEA, 0x84E7, 0xDCBA, 0x84F5, 0xDC8A, 0x8503, + 0xDC59, 0x8511, 0xDC29, 0x851F, 0xDBF9, 0x852D, 0xDBC9, 0x853B, + 0xDB99, 0x8549, 0xDB68, 0x8558, 0xDB38, 0x8566, 0xDB08, 0x8574, + 0xDAD8, 0x8583, 0xDAA8, 0x8592, 0xDA78, 0x85A0, 0xDA48, 0x85AF, + 0xDA18, 0x85BE, 0xD9E8, 0x85CD, 0xD9B8, 0x85DC, 0xD988, 0x85EB, + 0xD958, 0x85FA, 0xD928, 0x8609, 0xD8F8, 0x8619, 0xD8C8, 0x8628, + 0xD898, 0x8637, 0xD869, 0x8647, 0xD839, 0x8656, 0xD809, 0x8666, + 0xD7D9, 0x8676, 0xD7AA, 0x8686, 0xD77A, 0x8696, 0xD74A, 0x86A5, + 0xD71B, 0x86B6, 0xD6EB, 0x86C6, 0xD6BB, 0x86D6, 0xD68C, 0x86E6, + 0xD65C, 0x86F6, 0xD62D, 0x8707, 0xD5FD, 0x8717, 0xD5CE, 0x8728, + 0xD59E, 0x8738, 0xD56F, 0x8749, 0xD53F, 0x875A, 0xD510, 0x876B, + 0xD4E1, 0x877B, 0xD4B1, 0x878C, 0xD482, 0x879D, 0xD453, 0x87AF, + 0xD424, 0x87C0, 0xD3F4, 0x87D1, 0xD3C5, 0x87E2, 0xD396, 0x87F4, + 0xD367, 0x8805, 0xD338, 0x8817, 0xD309, 0x8828, 0xD2DA, 0x883A, + 0xD2AB, 0x884C, 0xD27C, 0x885E, 0xD24D, 0x8870, 0xD21E, 0x8882, + 0xD1EF, 0x8894, 0xD1C0, 0x88A6, 0xD191, 0x88B8, 0xD162, 0x88CA, + 0xD134, 0x88DD, 0xD105, 0x88EF, 0xD0D6, 0x8902, 0xD0A7, 0x8914, + 0xD079, 0x8927, 0xD04A, 0x8939, 0xD01B, 0x894C, 0xCFED, 0x895F, + 0xCFBE, 0x8972, 0xCF90, 0x8985, 0xCF61, 0x8998, 0xCF33, 0x89AB, + 0xCF04, 0x89BE, 0xCED6, 0x89D2, 0xCEA7, 0x89E5, 0xCE79, 0x89F8, + 0xCE4B, 0x8A0C, 0xCE1C, 0x8A1F, 0xCDEE, 0x8A33, 0xCDC0, 0x8A47, + 0xCD92, 0x8A5A, 0xCD63, 0x8A6E, 0xCD35, 0x8A82, 0xCD07, 0x8A96, + 0xCCD9, 0x8AAA, 0xCCAB, 0x8ABE, 0xCC7D, 0x8AD3, 0xCC4F, 0x8AE7, + 0xCC21, 0x8AFB, 0xCBF3, 0x8B10, 0xCBC5, 0x8B24, 0xCB97, 0x8B39, + 0xCB69, 0x8B4D, 0xCB3C, 0x8B62, 0xCB0E, 0x8B77, 0xCAE0, 0x8B8B, + 0xCAB2, 0x8BA0, 0xCA85, 0x8BB5, 0xCA57, 0x8BCA, 0xCA29, 0x8BDF, + 0xC9FC, 0x8BF5, 0xC9CE, 0x8C0A, 0xC9A1, 0x8C1F, 0xC973, 0x8C35, + 0xC946, 0x8C4A, 0xC918, 0x8C60, 0xC8EB, 0x8C75, 0xC8BE, 0x8C8B, + 0xC890, 0x8CA1, 0xC863, 0x8CB6, 0xC836, 0x8CCC, 0xC809, 0x8CE2, + 0xC7DB, 0x8CF8, 0xC7AE, 0x8D0E, 0xC781, 0x8D24, 0xC754, 0x8D3B, + 0xC727, 0x8D51, 0xC6FA, 0x8D67, 0xC6CD, 0x8D7E, 0xC6A0, 0x8D94, + 0xC673, 0x8DAB, 0xC646, 0x8DC1, 0xC619, 0x8DD8, 0xC5ED, 0x8DEF, + 0xC5C0, 0x8E06, 0xC593, 0x8E1D, 0xC566, 0x8E34, 0xC53A, 0x8E4B, + 0xC50D, 0x8E62, 0xC4E0, 0x8E79, 0xC4B4, 0x8E90, 0xC487, 0x8EA8, + 0xC45B, 0x8EBF, 0xC42E, 0x8ED6, 0xC402, 0x8EEE, 0xC3D6, 0x8F06, + 0xC3A9, 0x8F1D, 0xC37D, 0x8F35, 0xC351, 0x8F4D, 0xC324, 0x8F65, + 0xC2F8, 0x8F7D, 0xC2CC, 0x8F95, 0xC2A0, 0x8FAD, 0xC274, 0x8FC5, + 0xC248, 0x8FDD, 0xC21C, 0x8FF5, 0xC1F0, 0x900E, 0xC1C4, 0x9026, + 0xC198, 0x903E, 0xC16C, 0x9057, 0xC140, 0x9070, 0xC114, 0x9088, + 0xC0E9, 0x90A1, 0xC0BD, 0x90BA, 0xC091, 0x90D3, 0xC066, 0x90EC, + 0xC03A, 0x9105, 0xC00F, 0x911E, 0xBFE3, 0x9137, 0xBFB8, 0x9150, + 0xBF8C, 0x9169, 0xBF61, 0x9183, 0xBF35, 0x919C, 0xBF0A, 0x91B6, + 0xBEDF, 0x91CF, 0xBEB3, 0x91E9, 0xBE88, 0x9202, 0xBE5D, 0x921C, + 0xBE32, 0x9236, 0xBE07, 0x9250, 0xBDDC, 0x926A, 0xBDB1, 0x9284, + 0xBD86, 0x929E, 0xBD5B, 0x92B8, 0xBD30, 0x92D2, 0xBD05, 0x92EC, + 0xBCDA, 0x9307, 0xBCAF, 0x9321, 0xBC85, 0x933C, 0xBC5A, 0x9356, + 0xBC2F, 0x9371, 0xBC05, 0x938B, 0xBBDA, 0x93A6, 0xBBB0, 0x93C1, + 0xBB85, 0x93DC, 0xBB5B, 0x93F7, 0xBB30, 0x9412, 0xBB06, 0x942D, + 0xBADC, 0x9448, 0xBAB1, 0x9463, 0xBA87, 0x947E, 0xBA5D, 0x949A, + 0xBA33, 0x94B5, 0xBA09, 0x94D0, 0xB9DF, 0x94EC, 0xB9B5, 0x9508, + 0xB98B, 0x9523, 0xB961, 0x953F, 0xB937, 0x955B, 0xB90D, 0x9577, + 0xB8E3, 0x9592, 0xB8B9, 0x95AE, 0xB890, 0x95CA, 0xB866, 0x95E6, + 0xB83C, 0x9603, 0xB813, 0x961F, 0xB7E9, 0x963B, 0xB7C0, 0x9657, + 0xB796, 0x9674, 0xB76D, 0x9690, 0xB743, 0x96AD, 0xB71A, 0x96C9, + 0xB6F1, 0x96E6, 0xB6C7, 0x9703, 0xB69E, 0x9720, 0xB675, 0x973C, + 0xB64C, 0x9759, 0xB623, 0x9776, 0xB5FA, 0x9793, 0xB5D1, 0x97B0, + 0xB5A8, 0x97CE, 0xB57F, 0x97EB, 0xB556, 0x9808, 0xB52D, 0x9826, + 0xB505, 0x9843, 0xB4DC, 0x9860, 0xB4B3, 0x987E, 0xB48B, 0x989C, + 0xB462, 0x98B9, 0xB439, 0x98D7, 0xB411, 0x98F5, 0xB3E9, 0x9913, + 0xB3C0, 0x9930, 0xB398, 0x994E, 0xB36F, 0x996D, 0xB347, 0x998B, + 0xB31F, 0x99A9, 0xB2F7, 0x99C7, 0xB2CF, 0x99E5, 0xB2A7, 0x9A04, + 0xB27F, 0x9A22, 0xB257, 0x9A40, 0xB22F, 0x9A5F, 0xB207, 0x9A7E, + 0xB1DF, 0x9A9C, 0xB1B7, 0x9ABB, 0xB18F, 0x9ADA, 0xB168, 0x9AF9, + 0xB140, 0x9B17, 0xB118, 0x9B36, 0xB0F1, 0x9B55, 0xB0C9, 0x9B75, + 0xB0A2, 0x9B94, 0xB07B, 0x9BB3, 0xB053, 0x9BD2, 0xB02C, 0x9BF1, + 0xB005, 0x9C11, 0xAFDD, 0x9C30, 0xAFB6, 0x9C50, 0xAF8F, 0x9C6F, + 0xAF68, 0x9C8F, 0xAF41, 0x9CAF, 0xAF1A, 0x9CCE, 0xAEF3, 0x9CEE, + 0xAECC, 0x9D0E, 0xAEA5, 0x9D2E, 0xAE7F, 0x9D4E, 0xAE58, 0x9D6E, + 0xAE31, 0x9D8E, 0xAE0B, 0x9DAE, 0xADE4, 0x9DCE, 0xADBD, 0x9DEF, + 0xAD97, 0x9E0F, 0xAD70, 0x9E2F, 0xAD4A, 0x9E50, 0xAD24, 0x9E70, + 0xACFD, 0x9E91, 0xACD7, 0x9EB2, 0xACB1, 0x9ED2, 0xAC8B, 0x9EF3, + 0xAC65, 0x9F14, 0xAC3F, 0x9F35, 0xAC19, 0x9F56, 0xABF3, 0x9F77, + 0xABCD, 0x9F98, 0xABA7, 0x9FB9, 0xAB81, 0x9FDA, 0xAB5C, 0x9FFB, + 0xAB36, 0xA01C, 0xAB10, 0xA03E, 0xAAEB, 0xA05F, 0xAAC5, 0xA080, + 0xAAA0, 0xA0A2, 0xAA7A, 0xA0C4, 0xAA55, 0xA0E5, 0xAA30, 0xA107, + 0xAA0A, 0xA129, 0xA9E5, 0xA14A, 0xA9C0, 0xA16C, 0xA99B, 0xA18E, + 0xA976, 0xA1B0, 0xA951, 0xA1D2, 0xA92C, 0xA1F4, 0xA907, 0xA216, + 0xA8E2, 0xA238, 0xA8BD, 0xA25B, 0xA899, 0xA27D, 0xA874, 0xA29F, + 0xA84F, 0xA2C2, 0xA82B, 0xA2E4, 0xA806, 0xA307, 0xA7E2, 0xA329, + 0xA7BD, 0xA34C, 0xA799, 0xA36F, 0xA774, 0xA391, 0xA750, 0xA3B4, + 0xA72C, 0xA3D7, 0xA708, 0xA3FA, 0xA6E4, 0xA41D, 0xA6C0, 0xA440, + 0xA69C, 0xA463, 0xA678, 0xA486, 0xA654, 0xA4A9, 0xA630, 0xA4CC, + 0xA60C, 0xA4F0, 0xA5E8, 0xA513, 0xA5C5, 0xA537, 0xA5A1, 0xA55A, + 0xA57E, 0xA57E, 0xA55A, 0xA5A1, 0xA537, 0xA5C5, 0xA513, 0xA5E8, + 0xA4F0, 0xA60C, 0xA4CC, 0xA630, 0xA4A9, 0xA654, 0xA486, 0xA678, + 0xA463, 0xA69C, 0xA440, 0xA6C0, 0xA41D, 0xA6E4, 0xA3FA, 0xA708, + 0xA3D7, 0xA72C, 0xA3B4, 0xA750, 0xA391, 0xA774, 0xA36F, 0xA799, + 0xA34C, 0xA7BD, 0xA329, 0xA7E2, 0xA307, 0xA806, 0xA2E4, 0xA82B, + 0xA2C2, 0xA84F, 0xA29F, 0xA874, 0xA27D, 0xA899, 0xA25B, 0xA8BD, + 0xA238, 0xA8E2, 0xA216, 0xA907, 0xA1F4, 0xA92C, 0xA1D2, 0xA951, + 0xA1B0, 0xA976, 0xA18E, 0xA99B, 0xA16C, 0xA9C0, 0xA14A, 0xA9E5, + 0xA129, 0xAA0A, 0xA107, 0xAA30, 0xA0E5, 0xAA55, 0xA0C4, 0xAA7A, + 0xA0A2, 0xAAA0, 0xA080, 0xAAC5, 0xA05F, 0xAAEB, 0xA03E, 0xAB10, + 0xA01C, 0xAB36, 0x9FFB, 0xAB5C, 0x9FDA, 0xAB81, 0x9FB9, 0xABA7, + 0x9F98, 0xABCD, 0x9F77, 0xABF3, 0x9F56, 0xAC19, 0x9F35, 0xAC3F, + 0x9F14, 0xAC65, 0x9EF3, 0xAC8B, 0x9ED2, 0xACB1, 0x9EB2, 0xACD7, + 0x9E91, 0xACFD, 0x9E70, 0xAD24, 0x9E50, 0xAD4A, 0x9E2F, 0xAD70, + 0x9E0F, 0xAD97, 0x9DEF, 0xADBD, 0x9DCE, 0xADE4, 0x9DAE, 0xAE0B, + 0x9D8E, 0xAE31, 0x9D6E, 0xAE58, 0x9D4E, 0xAE7F, 0x9D2E, 0xAEA5, + 0x9D0E, 0xAECC, 0x9CEE, 0xAEF3, 0x9CCE, 0xAF1A, 0x9CAF, 0xAF41, + 0x9C8F, 0xAF68, 0x9C6F, 0xAF8F, 0x9C50, 0xAFB6, 0x9C30, 0xAFDD, + 0x9C11, 0xB005, 0x9BF1, 0xB02C, 0x9BD2, 0xB053, 0x9BB3, 0xB07B, + 0x9B94, 0xB0A2, 0x9B75, 0xB0C9, 0x9B55, 0xB0F1, 0x9B36, 0xB118, + 0x9B17, 0xB140, 0x9AF9, 0xB168, 0x9ADA, 0xB18F, 0x9ABB, 0xB1B7, + 0x9A9C, 0xB1DF, 0x9A7E, 0xB207, 0x9A5F, 0xB22F, 0x9A40, 0xB257, + 0x9A22, 0xB27F, 0x9A04, 0xB2A7, 0x99E5, 0xB2CF, 0x99C7, 0xB2F7, + 0x99A9, 0xB31F, 0x998B, 0xB347, 0x996D, 0xB36F, 0x994E, 0xB398, + 0x9930, 0xB3C0, 0x9913, 0xB3E9, 0x98F5, 0xB411, 0x98D7, 0xB439, + 0x98B9, 0xB462, 0x989C, 0xB48B, 0x987E, 0xB4B3, 0x9860, 0xB4DC, + 0x9843, 0xB505, 0x9826, 0xB52D, 0x9808, 0xB556, 0x97EB, 0xB57F, + 0x97CE, 0xB5A8, 0x97B0, 0xB5D1, 0x9793, 0xB5FA, 0x9776, 0xB623, + 0x9759, 0xB64C, 0x973C, 0xB675, 0x9720, 0xB69E, 0x9703, 0xB6C7, + 0x96E6, 0xB6F1, 0x96C9, 0xB71A, 0x96AD, 0xB743, 0x9690, 0xB76D, + 0x9674, 0xB796, 0x9657, 0xB7C0, 0x963B, 0xB7E9, 0x961F, 0xB813, + 0x9603, 0xB83C, 0x95E6, 0xB866, 0x95CA, 0xB890, 0x95AE, 0xB8B9, + 0x9592, 0xB8E3, 0x9577, 0xB90D, 0x955B, 0xB937, 0x953F, 0xB961, + 0x9523, 0xB98B, 0x9508, 0xB9B5, 0x94EC, 0xB9DF, 0x94D0, 0xBA09, + 0x94B5, 0xBA33, 0x949A, 0xBA5D, 0x947E, 0xBA87, 0x9463, 0xBAB1, + 0x9448, 0xBADC, 0x942D, 0xBB06, 0x9412, 0xBB30, 0x93F7, 0xBB5B, + 0x93DC, 0xBB85, 0x93C1, 0xBBB0, 0x93A6, 0xBBDA, 0x938B, 0xBC05, + 0x9371, 0xBC2F, 0x9356, 0xBC5A, 0x933C, 0xBC85, 0x9321, 0xBCAF, + 0x9307, 0xBCDA, 0x92EC, 0xBD05, 0x92D2, 0xBD30, 0x92B8, 0xBD5B, + 0x929E, 0xBD86, 0x9284, 0xBDB1, 0x926A, 0xBDDC, 0x9250, 0xBE07, + 0x9236, 0xBE32, 0x921C, 0xBE5D, 0x9202, 0xBE88, 0x91E9, 0xBEB3, + 0x91CF, 0xBEDF, 0x91B6, 0xBF0A, 0x919C, 0xBF35, 0x9183, 0xBF61, + 0x9169, 0xBF8C, 0x9150, 0xBFB8, 0x9137, 0xBFE3, 0x911E, 0xC00F, + 0x9105, 0xC03A, 0x90EC, 0xC066, 0x90D3, 0xC091, 0x90BA, 0xC0BD, + 0x90A1, 0xC0E9, 0x9088, 0xC114, 0x9070, 0xC140, 0x9057, 0xC16C, + 0x903E, 0xC198, 0x9026, 0xC1C4, 0x900E, 0xC1F0, 0x8FF5, 0xC21C, + 0x8FDD, 0xC248, 0x8FC5, 0xC274, 0x8FAD, 0xC2A0, 0x8F95, 0xC2CC, + 0x8F7D, 0xC2F8, 0x8F65, 0xC324, 0x8F4D, 0xC351, 0x8F35, 0xC37D, + 0x8F1D, 0xC3A9, 0x8F06, 0xC3D6, 0x8EEE, 0xC402, 0x8ED6, 0xC42E, + 0x8EBF, 0xC45B, 0x8EA8, 0xC487, 0x8E90, 0xC4B4, 0x8E79, 0xC4E0, + 0x8E62, 0xC50D, 0x8E4B, 0xC53A, 0x8E34, 0xC566, 0x8E1D, 0xC593, + 0x8E06, 0xC5C0, 0x8DEF, 0xC5ED, 0x8DD8, 0xC619, 0x8DC1, 0xC646, + 0x8DAB, 0xC673, 0x8D94, 0xC6A0, 0x8D7E, 0xC6CD, 0x8D67, 0xC6FA, + 0x8D51, 0xC727, 0x8D3B, 0xC754, 0x8D24, 0xC781, 0x8D0E, 0xC7AE, + 0x8CF8, 0xC7DB, 0x8CE2, 0xC809, 0x8CCC, 0xC836, 0x8CB6, 0xC863, + 0x8CA1, 0xC890, 0x8C8B, 0xC8BE, 0x8C75, 0xC8EB, 0x8C60, 0xC918, + 0x8C4A, 0xC946, 0x8C35, 0xC973, 0x8C1F, 0xC9A1, 0x8C0A, 0xC9CE, + 0x8BF5, 0xC9FC, 0x8BDF, 0xCA29, 0x8BCA, 0xCA57, 0x8BB5, 0xCA85, + 0x8BA0, 0xCAB2, 0x8B8B, 0xCAE0, 0x8B77, 0xCB0E, 0x8B62, 0xCB3C, + 0x8B4D, 0xCB69, 0x8B39, 0xCB97, 0x8B24, 0xCBC5, 0x8B10, 0xCBF3, + 0x8AFB, 0xCC21, 0x8AE7, 0xCC4F, 0x8AD3, 0xCC7D, 0x8ABE, 0xCCAB, + 0x8AAA, 0xCCD9, 0x8A96, 0xCD07, 0x8A82, 0xCD35, 0x8A6E, 0xCD63, + 0x8A5A, 0xCD92, 0x8A47, 0xCDC0, 0x8A33, 0xCDEE, 0x8A1F, 0xCE1C, + 0x8A0C, 0xCE4B, 0x89F8, 0xCE79, 0x89E5, 0xCEA7, 0x89D2, 0xCED6, + 0x89BE, 0xCF04, 0x89AB, 0xCF33, 0x8998, 0xCF61, 0x8985, 0xCF90, + 0x8972, 0xCFBE, 0x895F, 0xCFED, 0x894C, 0xD01B, 0x8939, 0xD04A, + 0x8927, 0xD079, 0x8914, 0xD0A7, 0x8902, 0xD0D6, 0x88EF, 0xD105, + 0x88DD, 0xD134, 0x88CA, 0xD162, 0x88B8, 0xD191, 0x88A6, 0xD1C0, + 0x8894, 0xD1EF, 0x8882, 0xD21E, 0x8870, 0xD24D, 0x885E, 0xD27C, + 0x884C, 0xD2AB, 0x883A, 0xD2DA, 0x8828, 0xD309, 0x8817, 0xD338, + 0x8805, 0xD367, 0x87F4, 0xD396, 0x87E2, 0xD3C5, 0x87D1, 0xD3F4, + 0x87C0, 0xD424, 0x87AF, 0xD453, 0x879D, 0xD482, 0x878C, 0xD4B1, + 0x877B, 0xD4E1, 0x876B, 0xD510, 0x875A, 0xD53F, 0x8749, 0xD56F, + 0x8738, 0xD59E, 0x8728, 0xD5CE, 0x8717, 0xD5FD, 0x8707, 0xD62D, + 0x86F6, 0xD65C, 0x86E6, 0xD68C, 0x86D6, 0xD6BB, 0x86C6, 0xD6EB, + 0x86B6, 0xD71B, 0x86A5, 0xD74A, 0x8696, 0xD77A, 0x8686, 0xD7AA, + 0x8676, 0xD7D9, 0x8666, 0xD809, 0x8656, 0xD839, 0x8647, 0xD869, + 0x8637, 0xD898, 0x8628, 0xD8C8, 0x8619, 0xD8F8, 0x8609, 0xD928, + 0x85FA, 0xD958, 0x85EB, 0xD988, 0x85DC, 0xD9B8, 0x85CD, 0xD9E8, + 0x85BE, 0xDA18, 0x85AF, 0xDA48, 0x85A0, 0xDA78, 0x8592, 0xDAA8, + 0x8583, 0xDAD8, 0x8574, 0xDB08, 0x8566, 0xDB38, 0x8558, 0xDB68, + 0x8549, 0xDB99, 0x853B, 0xDBC9, 0x852D, 0xDBF9, 0x851F, 0xDC29, + 0x8511, 0xDC59, 0x8503, 0xDC8A, 0x84F5, 0xDCBA, 0x84E7, 0xDCEA, + 0x84D9, 0xDD1B, 0x84CC, 0xDD4B, 0x84BE, 0xDD7C, 0x84B0, 0xDDAC, + 0x84A3, 0xDDDC, 0x8496, 0xDE0D, 0x8488, 0xDE3D, 0x847B, 0xDE6E, + 0x846E, 0xDE9E, 0x8461, 0xDECF, 0x8454, 0xDEFF, 0x8447, 0xDF30, + 0x843A, 0xDF61, 0x842D, 0xDF91, 0x8421, 0xDFC2, 0x8414, 0xDFF2, + 0x8407, 0xE023, 0x83FB, 0xE054, 0x83EF, 0xE085, 0x83E2, 0xE0B5, + 0x83D6, 0xE0E6, 0x83CA, 0xE117, 0x83BE, 0xE148, 0x83B2, 0xE178, + 0x83A6, 0xE1A9, 0x839A, 0xE1DA, 0x838E, 0xE20B, 0x8382, 0xE23C, + 0x8377, 0xE26D, 0x836B, 0xE29E, 0x8360, 0xE2CF, 0x8354, 0xE2FF, + 0x8349, 0xE330, 0x833E, 0xE361, 0x8332, 0xE392, 0x8327, 0xE3C3, + 0x831C, 0xE3F4, 0x8311, 0xE426, 0x8306, 0xE457, 0x82FB, 0xE488, + 0x82F1, 0xE4B9, 0x82E6, 0xE4EA, 0x82DB, 0xE51B, 0x82D1, 0xE54C, + 0x82C6, 0xE57D, 0x82BC, 0xE5AF, 0x82B2, 0xE5E0, 0x82A8, 0xE611, + 0x829D, 0xE642, 0x8293, 0xE673, 0x8289, 0xE6A5, 0x827F, 0xE6D6, + 0x8276, 0xE707, 0x826C, 0xE739, 0x8262, 0xE76A, 0x8259, 0xE79B, + 0x824F, 0xE7CD, 0x8246, 0xE7FE, 0x823C, 0xE82F, 0x8233, 0xE861, + 0x822A, 0xE892, 0x8220, 0xE8C4, 0x8217, 0xE8F5, 0x820E, 0xE926, + 0x8205, 0xE958, 0x81FD, 0xE989, 0x81F4, 0xE9BB, 0x81EB, 0xE9EC, + 0x81E2, 0xEA1E, 0x81DA, 0xEA4F, 0x81D1, 0xEA81, 0x81C9, 0xEAB3, + 0x81C1, 0xEAE4, 0x81B8, 0xEB16, 0x81B0, 0xEB47, 0x81A8, 0xEB79, + 0x81A0, 0xEBAB, 0x8198, 0xEBDC, 0x8190, 0xEC0E, 0x8188, 0xEC3F, + 0x8181, 0xEC71, 0x8179, 0xECA3, 0x8172, 0xECD5, 0x816A, 0xED06, + 0x8163, 0xED38, 0x815B, 0xED6A, 0x8154, 0xED9B, 0x814D, 0xEDCD, + 0x8146, 0xEDFF, 0x813F, 0xEE31, 0x8138, 0xEE62, 0x8131, 0xEE94, + 0x812A, 0xEEC6, 0x8123, 0xEEF8, 0x811D, 0xEF2A, 0x8116, 0xEF5C, + 0x8110, 0xEF8D, 0x8109, 0xEFBF, 0x8103, 0xEFF1, 0x80FD, 0xF023, + 0x80F6, 0xF055, 0x80F0, 0xF087, 0x80EA, 0xF0B9, 0x80E4, 0xF0EB, + 0x80DE, 0xF11C, 0x80D9, 0xF14E, 0x80D3, 0xF180, 0x80CD, 0xF1B2, + 0x80C8, 0xF1E4, 0x80C2, 0xF216, 0x80BD, 0xF248, 0x80B7, 0xF27A, + 0x80B2, 0xF2AC, 0x80AD, 0xF2DE, 0x80A8, 0xF310, 0x80A3, 0xF342, + 0x809E, 0xF374, 0x8099, 0xF3A6, 0x8094, 0xF3D8, 0x808F, 0xF40A, + 0x808B, 0xF43C, 0x8086, 0xF46E, 0x8082, 0xF4A0, 0x807D, 0xF4D3, + 0x8079, 0xF505, 0x8075, 0xF537, 0x8070, 0xF569, 0x806C, 0xF59B, + 0x8068, 0xF5CD, 0x8064, 0xF5FF, 0x8060, 0xF631, 0x805D, 0xF663, + 0x8059, 0xF695, 0x8055, 0xF6C8, 0x8052, 0xF6FA, 0x804E, 0xF72C, + 0x804B, 0xF75E, 0x8047, 0xF790, 0x8044, 0xF7C2, 0x8041, 0xF7F4, + 0x803E, 0xF827, 0x803B, 0xF859, 0x8038, 0xF88B, 0x8035, 0xF8BD, + 0x8032, 0xF8EF, 0x802F, 0xF922, 0x802D, 0xF954, 0x802A, 0xF986, + 0x8027, 0xF9B8, 0x8025, 0xF9EA, 0x8023, 0xFA1D, 0x8020, 0xFA4F, + 0x801E, 0xFA81, 0x801C, 0xFAB3, 0x801A, 0xFAE5, 0x8018, 0xFB18, + 0x8016, 0xFB4A, 0x8014, 0xFB7C, 0x8013, 0xFBAE, 0x8011, 0xFBE1, + 0x800F, 0xFC13, 0x800E, 0xFC45, 0x800C, 0xFC77, 0x800B, 0xFCAA, + 0x800A, 0xFCDC, 0x8009, 0xFD0E, 0x8008, 0xFD40, 0x8007, 0xFD73, + 0x8006, 0xFDA5, 0x8005, 0xFDD7, 0x8004, 0xFE09, 0x8003, 0xFE3C, + 0x8002, 0xFE6E, 0x8002, 0xFEA0, 0x8001, 0xFED2, 0x8001, 0xFF05, + 0x8001, 0xFF37, 0x8001, 0xFF69, 0x8001, 0xFF9B, 0x8001, 0xFFCE +}; + +#endif //MSP_USE_LEA + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_fill_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_fill_iq31.c new file mode 100755 index 000000000..681a86f92 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_fill_iq31.c @@ -0,0 +1,145 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_fill_iq31(const msp_cmplx_fill_iq31_params *params, _iq31 *dst) +{ + uint16_t length; + int32_t *fillVector; + msp_status status; + MSP_LEA_ADDMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data array is aligned and in a valid memory segment. */ + if (!MSP_LEA_VALID_ADDRESS(dst, 4)) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate offset vector of length one. */ + fillVector = (int32_t *)msp_lea_allocMemory(sizeof(int32_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_ADDMATRIX_PARAMS structure for real. */ + fillVector[0] = params->realValue; + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&CMPLX_REAL(dst)); + leaParams->vectorSize = length; + leaParams->input1Offset = 0; + leaParams->input2Offset = 0; + leaParams->outputOffset = 2; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(fillVector); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDMATRIX); + + /* Set MSP_LEA_ADDMATRIX_PARAMS structure for imaginary. */ + fillVector[0] = params->imagValue; + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&CMPLX_IMAG(dst)); + leaParams->vectorSize = length; + leaParams->input1Offset = 0; + leaParams->input2Offset = 0; + leaParams->outputOffset = 2; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(fillVector); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDMATRIX); + + /* Free MSP_LEA_ADDMATRIX_PARAMS structure and offset vector. */ + msp_lea_freeMemory(sizeof(int32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_fill_iq31(const msp_cmplx_fill_iq31_params *params, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + + /* Fill destination buffer. */ + while(length--) { + *dst++ = params->realValue; + *dst++ = params->imagValue; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_fill_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_fill_q15.c new file mode 100755 index 000000000..c21bade85 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_fill_q15.c @@ -0,0 +1,130 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_fill_q15(const msp_cmplx_fill_q15_params *params, _q15 *dst) +{ + uint16_t length; + int16_t *fillVector; + msp_status status; + MSP_LEA_ADDMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data array is aligned and in a valid memory segment. */ + if (!MSP_LEA_VALID_ADDRESS(dst, 4)) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate fill vector of length two. */ + fillVector = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + fillVector[0] = params->realValue; + fillVector[1] = params->imagValue; + + /* Set MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length << 1; + leaParams->input1Offset = 0; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(fillVector); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDMATRIX); + + /* Free MSP_LEA_ADDMATRIX_PARAMS structure and fill vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_fill_q15(const msp_cmplx_fill_q15_params *params, _q15 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + + /* Fill destination buffer. */ + while(length--) { + *dst++ = params->realValue; + *dst++ = params->imagValue; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_iq31.c new file mode 100755 index 000000000..278ad0c42 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_iq31.c @@ -0,0 +1,57 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_cmplx_iq31(const msp_cmplx_iq31_params *params, const _iq31 *real, const _iq31 *imag, _iq31 *dst) +{ + uint16_t length; + msp_status status; + msp_interleave_iq31_params interleaveParams; + + /* Initialize the vector length. */ + length = params->length; + + /* Interleave IQ31 real to channel zero of the destination vector. */ + interleaveParams.length = length; + interleaveParams.numChannels = 2; + interleaveParams.channel = 0; + status = msp_interleave_iq31(&interleaveParams, real, dst); + + /* Interleave IQ31 imaginary to channel one of the destination vector. */ + interleaveParams.length = length; + interleaveParams.numChannels = 2; + interleaveParams.channel = 1; + status = msp_interleave_iq31(&interleaveParams, imag, dst); + + return status; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_q15.c new file mode 100755 index 000000000..4107ab6eb --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_cmplx_q15.c @@ -0,0 +1,57 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_cmplx_q15(const msp_cmplx_q15_params *params, const _q15 *real, const _q15 *imag, _q15 *dst) +{ + uint16_t length; + msp_status status; + msp_interleave_q15_params interleaveParams; + + /* Initialize the vector length. */ + length = params->length; + + /* Interleave Q15 real to channel zero of the destination vector. */ + interleaveParams.length = length; + interleaveParams.numChannels = 2; + interleaveParams.channel = 0; + status = msp_interleave_q15(&interleaveParams, real, dst); + + /* Interleave Q15 imaginary to channel one of the destination vector. */ + interleaveParams.length = length; + interleaveParams.numChannels = 2; + interleaveParams.channel = 1; + status = msp_interleave_q15(&interleaveParams, imag, dst); + + return status; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_copy_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_copy_iq31.c new file mode 100755 index 000000000..8d271c52b --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_copy_iq31.c @@ -0,0 +1,121 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_copy_iq31(const msp_copy_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_ADDLONGMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data array is aligned and in a valid memory segment. */ + if (!MSP_LEA_VALID_ADDRESS(dst, 4)) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDLONGMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDLONGMATRIX); + + /* Free MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_copy_iq31(const msp_copy_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + + while(length--) { + *dst++ = *src++; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_copy_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_copy_q15.c new file mode 100755 index 000000000..383b666ba --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_copy_q15.c @@ -0,0 +1,120 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_copy_q15(const msp_copy_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_ADDMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data array is aligned and in a valid memory segment. */ + if (!MSP_LEA_VALID_ADDRESS(dst, 4)) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDMATRIX); + + /* Free MSP_LEA_ADDMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_copy_q15(const msp_copy_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + while(length--) { + *dst++ = *src++; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_deinterleave_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_deinterleave_iq31.c new file mode 100755 index 000000000..535c37852 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_deinterleave_iq31.c @@ -0,0 +1,142 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_deinterleave_iq31(const msp_deinterleave_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + uint16_t channel; + uint16_t numChannels; + msp_status status; + MSP_LEA_DEINTERLEAVELONG_PARAMS *leaParams; + + /* Initialize local variables from parameters. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_DEINTERLEAVELONG_PARAMS structure. */ + leaParams = (MSP_LEA_DEINTERLEAVELONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_DEINTERLEAVELONG_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_DEINTERLEAVELONG_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->interleaveDepth = numChannels; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&src[channel]); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__DEINTERLEAVELONG command. */ + msp_lea_invokeCommand(LEACMD__DEINTERLEAVELONG); + + /* Free MSP_LEA_DEINTERLEAVELONG_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_DEINTERLEAVELONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_deinterleave_iq31(const msp_deinterleave_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + uint16_t channel; + uint16_t numChannels; + + /* Initialize local variables from parameters. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Extract requested channel from source data. */ + src += channel; + while (length--) { + *dst++ = *src; + src += numChannels; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_deinterleave_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_deinterleave_q15.c new file mode 100755 index 000000000..0549ab21b --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_deinterleave_q15.c @@ -0,0 +1,165 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_deinterleave_q15(const msp_deinterleave_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t cmdId; + uint16_t length; + uint16_t channel; + uint16_t numChannels; + msp_status status; + MSP_LEA_DEINTERLEAVE_PARAMS *leaParams; + + /* Initialize local variables from parameters. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_DEINTERLEAVE_PARAMS structure. */ + leaParams = (MSP_LEA_DEINTERLEAVE_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_DEINTERLEAVE_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_DEINTERLEAVE_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->interleaveDepth = numChannels; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&src[channel]); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Determine which LEA deinterleave command to invoke. */ + if (channel & 1) { + if (numChannels & 1) { + /* Invoke the LEACMD__DEINTERLEAVEODDODD command. */ + cmdId = LEACMD__DEINTERLEAVEODDODD; + } + else { + /* Invoke the LEACMD__DEINTERLEAVEODDEVEN command. */ + cmdId = LEACMD__DEINTERLEAVEODDEVEN; + } + } + else { + if (numChannels & 1) { + /* Invoke the LEACMD__DEINTERLEAVEEVENODD command. */ + cmdId = LEACMD__DEINTERLEAVEEVENODD; + } + else { + /* Invoke the LEACMD__DEINTERLEAVEEVENEVEN command. */ + cmdId = LEACMD__DEINTERLEAVEEVENEVEN; + } + } + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_DEINTERLEAVE_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_DEINTERLEAVE_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_deinterleave_q15(const msp_deinterleave_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + uint16_t channel; + uint16_t numChannels; + + /* Initialize local variables from parameters. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Extract requested channel from source data. */ + src += channel; + while (length--) { + *dst++ = *src; + src += numChannels; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_fill_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_fill_iq31.c new file mode 100755 index 000000000..797a56332 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_fill_iq31.c @@ -0,0 +1,127 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_fill_iq31(const msp_fill_iq31_params *params, _iq31 *dst) +{ + uint16_t length; + int32_t *fillVector; + msp_status status; + MSP_LEA_ADDLONGMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data array is aligned and in a valid memory segment. */ + if (!MSP_LEA_VALID_ADDRESS(dst, 4)) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate fill vector of length one. */ + fillVector = (int32_t *)msp_lea_allocMemory(sizeof(int32_t)/sizeof(uint32_t)); + fillVector[0] = params->value; + + /* Set MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 0; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(fillVector); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDLONGMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDLONGMATRIX); + + /* Free MSP_LEA_ADDLONGMATRIX_PARAMS structure and fill vector. */ + msp_lea_freeMemory(sizeof(fillVector)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_fill_iq31(const msp_fill_iq31_params *params, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + + while(length--) { + *dst++ = params->value; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_fill_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_fill_q15.c new file mode 100755 index 000000000..d973d5b03 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_fill_q15.c @@ -0,0 +1,127 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_fill_q15(const msp_fill_q15_params *params, _q15 *dst) +{ + uint16_t length; + int16_t *fillVector; + msp_status status; + MSP_LEA_ADDMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data array is aligned and in a valid memory segment. */ + if (!MSP_LEA_VALID_ADDRESS(dst, 4)) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate fill vector of length two. */ + fillVector = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + fillVector[0] = params->value; + fillVector[1] = params->value; + + /* Set MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 0; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(fillVector); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDMATRIX); + + /* Free MSP_LEA_ADDMATRIX_PARAMS structure and fill vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_fill_q15(const msp_fill_q15_params *params, _q15 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + while(length--) { + *dst++ = params->value; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_interleave_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_interleave_iq31.c new file mode 100755 index 000000000..f2f9fc52f --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_interleave_iq31.c @@ -0,0 +1,145 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_interleave_iq31(const msp_interleave_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + uint16_t channel; + uint16_t numChannels; + msp_status status; + MSP_LEA_ADDLONGMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&dst[channel]); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = numChannels; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDLONGMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDLONGMATRIX); + + /* Free MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_interleave_iq31(const msp_interleave_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + uint16_t channel; + uint16_t numChannels; + + /* Initialize local variables from parameters. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Insert the requested channel into the destination data. */ + dst += channel; + while (length--) { + *dst = *src++; + dst += numChannels; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_interleave_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_interleave_q15.c new file mode 100755 index 000000000..ae823abb3 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_interleave_q15.c @@ -0,0 +1,175 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_interleave_q15(const msp_interleave_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t cmdId; + uint16_t length; + uint16_t channel; + uint16_t numChannels; + msp_status status; + MSP_LEA_INTERLEAVE_PARAMS *leaParams; + + /* Initialize local variables from parameters. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_INTERLEAVE_PARAMS structure. */ + leaParams = (MSP_LEA_INTERLEAVE_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_INTERLEAVE_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_INTERLEAVE_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->channel = channel; + leaParams->numChannels = numChannels; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Determine which LEA deinterleave command to invoke. */ + if (channel & 1) { + if (numChannels & 1) { + /* Load the LEACMD__INTERLEAVEODDODD command into code memory. */ + cmdId = msp_lea_loadCommand(LEACMD__INTERLEAVEODDODD,MSP_LEA_INTERLEAVEODDODD, + sizeof(MSP_LEA_INTERLEAVEODDODD)/sizeof(MSP_LEA_INTERLEAVEODDODD[0])); + } + else { + /* Load the LEACMD__INTERLEAVEODDEVEN command into code memory. */ + cmdId = msp_lea_loadCommand(LEACMD__INTERLEAVEODDEVEN,MSP_LEA_INTERLEAVEODDEVEN, + sizeof(MSP_LEA_INTERLEAVEODDEVEN)/sizeof(MSP_LEA_INTERLEAVEODDEVEN[0])); + } + } + else { + if (numChannels & 1) { + /* Load the LEACMD__INTERLEAVEEVENODD command into code memory. */ + cmdId = msp_lea_loadCommand(LEACMD__INTERLEAVEEVENODD,MSP_LEA_INTERLEAVEEVENODD, + sizeof(MSP_LEA_INTERLEAVEEVENODD)/sizeof(MSP_LEA_INTERLEAVEEVENODD[0])); + } + else { + /* Load the LEACMD__INTERLEAVEEVENEVEN command into code memory. */ + cmdId = msp_lea_loadCommand(LEACMD__INTERLEAVEEVENEVEN,MSP_LEA_INTERLEAVEEVENEVEN, + sizeof(MSP_LEA_INTERLEAVEEVENEVEN)/sizeof(MSP_LEA_INTERLEAVEEVENEVEN[0])); + } + } + + /* Invoke the loaded command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_INTERLEAVE_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_INTERLEAVE_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_interleave_q15(const msp_interleave_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + uint16_t channel; + uint16_t numChannels; + + /* Initialize local variables from parameters. */ + length = params->length; + channel = params->channel; + numChannels = params->numChannels; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the channel is less than the total number of channels. */ + if (channel > numChannels) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Insert the requested channel into the destination data. */ + dst += channel; + while (length--) { + *dst = *src++; + dst += numChannels; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_iq31_to_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_iq31_to_q15.c new file mode 100755 index 000000000..46dcabc13 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_iq31_to_q15.c @@ -0,0 +1,51 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_iq31_to_q15(const msp_iq31_to_q15_params *params, const _iq31 *src, _q15 *dst) +{ + uint16_t length; + msp_status status; + msp_deinterleave_q15_params deinterleaveParams; + + /* Initialize the vector length. */ + length = params->length; + + /* Extract upper 16-bits of IQ31 source to Q15 destination. */ + deinterleaveParams.length = length; + deinterleaveParams.numChannels = 2; + deinterleaveParams.channel = 1; + status = msp_deinterleave_q15(&deinterleaveParams, (const _q15 *)src, dst); + + return status; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_q15_to_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_q15_to_iq31.c new file mode 100755 index 000000000..9e9d1a670 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_q15_to_iq31.c @@ -0,0 +1,60 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_q15_to_iq31(const msp_q15_to_iq31_params *params, const _q15 *src, _iq31 *dst) +{ + uint16_t length; + msp_status status; + msp_fill_iq31_params fillParams; + msp_interleave_q15_params interleaveParams; + + /* Initialize the vector length. */ + length = params->length; + + /* Fill destination with zeros. */ + fillParams.length = length; + fillParams.value = 0; + status = msp_fill_iq31(&fillParams, dst); + if (status != MSP_SUCCESS) { + return status; + } + + /* Interleave Q15 source to upper 16-bits of IQ31 destination. */ + interleaveParams.length = length; + interleaveParams.numChannels = 2; + interleaveParams.channel = 1; + status = msp_interleave_q15(&interleaveParams, src, (_q15 *)dst); + + return status; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_sinusoid_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_sinusoid_q15.c new file mode 100755 index 000000000..39e3c73f3 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/utility/msp_sinusoid_q15.c @@ -0,0 +1,96 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_sinusoid_q15(const msp_sinusoid_q15_params *params, _q15 *dst) +{ + msp_status status; + msp_biquad_df1_q15_params df1Params; + +#if defined(MSP_USE_LEA) + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate coefficients in LEA memory and set parameters */ + df1Params.length = params->length; + df1Params.coeffs = (msp_biquad_df1_q15_coeffs *)msp_lea_allocMemory(sizeof(msp_biquad_df1_q15_coeffs)/sizeof(uint32_t)); + df1Params.states = (msp_biquad_df1_q15_states *)msp_lea_allocMemory(sizeof(msp_biquad_df1_q15_coeffs)/sizeof(uint32_t)); +#else //MSP_USE_LEA + /* Allocate coefficients on stack */ + msp_biquad_df1_q15_coeffs coeffs; + msp_biquad_df1_q15_states states; + + /* Set parameters */ + df1Params.coeffs = &coeffs; + df1Params.states = &states; + df1Params.length = params->length; +#endif //MSP_USE_LEA + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; +#endif //__MSP430_HAS_MPY32__ + + /* Initialize coefficients */ + ((msp_biquad_df1_q15_coeffs *)df1Params.coeffs)->a1By2 = params->cosOmega; + ((msp_biquad_df1_q15_coeffs *)df1Params.coeffs)->a2 = _Q15(-1.0); + ((msp_biquad_df1_q15_coeffs *)df1Params.coeffs)->b0 = _Q15(0.0); + ((msp_biquad_df1_q15_coeffs *)df1Params.coeffs)->b1By2 = _Q15(0.0); + ((msp_biquad_df1_q15_coeffs *)df1Params.coeffs)->b2 = _Q15(0.0); + + /* Initialize states */ + df1Params.states->x1 = _Q15(0.0); + df1Params.states->x2 = _Q15(0.0); + df1Params.states->y1 = -__q15mpy(params->amplitude, params->sinOmega); + df1Params.states->y2 = __q15mpy(df1Params.states->y1, params->cosOmega) << 1; + +#if defined(__MSP430_HAS_MPY32__) + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#endif //__MSP430_HAS_MPY32__ + + /* Call DF1 biquad to generate sinusoid */ + status = msp_biquad_df1_q15(&df1Params, dst, dst); + +#if defined(MSP_USE_LEA) + /* Free coefficients and states from LEA memory */ + msp_lea_freeMemory(sizeof(msp_biquad_df1_q15_coeffs)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(msp_biquad_df1_q15_states)/sizeof(uint32_t)); +#endif //MSP_USE_LEA + + return status; +} + diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_abs_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_abs_iq31.c new file mode 100755 index 000000000..ed77aaa20 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_abs_iq31.c @@ -0,0 +1,57 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise absolute value of a single source vector. + */ +msp_status msp_abs_iq31(const msp_abs_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Loop through all vector elements. */ + while (length--) { + /* Compute the absolute value of src and store to dst. */ + if (*src < 0) { + *dst++ = -*src++; + } + else { + *dst++ = *src++; + } + } + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_abs_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_abs_q15.c new file mode 100755 index 000000000..9835c7cf4 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_abs_q15.c @@ -0,0 +1,64 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise absolute value of a single source vector. + */ +msp_status msp_abs_q15(const msp_abs_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Loop through all vector elements. */ + while (length--) { + /* Compute the absolute value of src and store to dst. */ + if (*src < 0) { + *dst++ = -*src++; + } + else { + *dst++ = *src++; + } + } + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_add_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_add_iq31.c new file mode 100755 index 000000000..0e43f9511 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_add_iq31.c @@ -0,0 +1,125 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_add_iq31(const msp_add_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_ADDLONGMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDLONGMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDLONGMATRIX); + + /* Free MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_add_iq31(const msp_add_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + + /* Loop through all vector elements. */ + while (length--) { + /* Add srcA and srcB with saturation and store result. */ + *dst++ = __saturated_add_iq31(*srcA++, *srcB++); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_add_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_add_q15.c new file mode 100755 index 000000000..076fe0a41 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_add_q15.c @@ -0,0 +1,137 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_add_q15(const msp_add_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_ADDMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDMATRIX); + + /* Free MSP_LEA_ADDMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_add_q15(const msp_add_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Loop through all vector elements. */ + while (length--) { + /* Add srcA and srcB with saturation and store result. */ + *dst++ = __saturated_add_q15(*srcA++, *srcB++); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_add_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_add_iq31.c new file mode 100755 index 000000000..3ebb4e076 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_add_iq31.c @@ -0,0 +1,46 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise addition of two complex source vectors without saturation. + */ +msp_status msp_cmplx_add_iq31(const msp_cmplx_add_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + msp_add_iq31_params paramsTemp; + + /* Use real vector addition function. */ + paramsTemp.length = params->length << 1; + + return msp_add_iq31(¶msTemp, srcA, srcB, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_add_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_add_q15.c new file mode 100755 index 000000000..4e2644793 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_add_q15.c @@ -0,0 +1,46 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise addition of two complex source vectors without saturation. + */ +msp_status msp_cmplx_add_q15(const msp_cmplx_add_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + msp_add_q15_params paramsTemp; + + /* Use real vector addition function. */ + paramsTemp.length = params->length << 1; + + return msp_add_q15(¶msTemp, srcA, srcB, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_conj_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_conj_iq31.c new file mode 100755 index 000000000..0710f0c4f --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_conj_iq31.c @@ -0,0 +1,150 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_conj_iq31(const msp_cmplx_conj_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_ADDLONGMATRIX_PARAMS *leaParams; + + /* Initialize the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) && MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONST_ZERO; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&CMPLX_REAL(dst)); + leaParams->vectorSize = length; + leaParams->input1Offset = 2; + leaParams->input2Offset = 0; + leaParams->outputOffset = 2; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&CMPLX_REAL(src)); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDLONGMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDLONGMATRIX); + + /* Reset source 2 and dst pointers. */ + leaParams->input2 = MSP_LEA_IQ31_CONST_NEG_ONE; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&CMPLX_IMAG(dst)); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&CMPLX_IMAG(src)); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MPYLONGMATRIX, MSP_LEA_MPYLONGMATRIX, + sizeof(MSP_LEA_MPYLONGMATRIX)/sizeof(MSP_LEA_MPYLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MPYLONGMATRIX command. */ + cmdId = LEACMD__MPYLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_conj_iq31(const msp_cmplx_conj_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the vector length. */ + length = params->length; + + /* Loop through all vector elements. */ + while (length--) { + /* Take the complex conjugate of src and store to dst. */ + *dst++ = *src++; // real + *dst++ = -*src++; // imaginary + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_conj_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_conj_q15.c new file mode 100755 index 000000000..825976ee4 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_conj_q15.c @@ -0,0 +1,53 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise complex conjugate of a single complex source vector. + */ +msp_status msp_cmplx_conj_q15(const msp_cmplx_conj_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Loop through all vector elements. */ + while (length--) { + /* Take the complex conjugate of src and store to dst. */ + *dst++ = *src++; // real + *dst++ = -*src++; // imaginary + } + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mac_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mac_iq31.c new file mode 100755 index 000000000..e482e1331 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mac_iq31.c @@ -0,0 +1,122 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +msp_status msp_cmplx_mac_iq31(const msp_cmplx_mac_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *result) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#if defined(__MSP430_HAS_MPY32__) + uint16_t *resultPtr = (uint16_t *)result; + + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Initialize result registers. */ + RES0=0; RES1=0; RES2=0; RES3=0; + + /* Multiply and accumulate the real components of srcA and srcB. */ + while (length--) { + MACS32L = (uint16_t)CMPLX_REAL(srcA); + MACS32H = (uint16_t)(CMPLX_REAL(srcA) >> 16); + OP2L = (uint16_t)CMPLX_REAL(srcB); + OP2H = (uint16_t)(CMPLX_REAL(srcB) >> 16); + MACS32L = (uint16_t)(-CMPLX_IMAG(srcA)); + MACS32H = (uint16_t)(-CMPLX_IMAG(srcA) >> 16); + OP2L = (uint16_t)CMPLX_IMAG(srcB); + OP2H = (uint16_t)(CMPLX_IMAG(srcB) >> 16); + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Save real result. */ + *resultPtr++ = RES2; + *resultPtr++ = RES3; + + /* Reset length to calculate imaginary value, reset result registers .*/ + length = params->length; + RES3=0; RES2=0; RES1=0; RES0=0; + srcA -= length*CMPLX_INCREMENT; + srcB -= length*CMPLX_INCREMENT; + + while (length--) { + MACS32L = (uint16_t)CMPLX_REAL(srcA); + MACS32H = (uint16_t)(CMPLX_REAL(srcA) >> 16); + OP2L = (uint16_t)CMPLX_IMAG(srcB); + OP2H = (uint16_t)(CMPLX_IMAG(srcB) >> 16); + MACS32L = (uint16_t)CMPLX_IMAG(srcA); + MACS32H = (uint16_t)(CMPLX_IMAG(srcA) >> 16); + OP2L = (uint16_t)CMPLX_REAL(srcB); + OP2H = (uint16_t)(CMPLX_REAL(srcB) >> 16); + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Save imaginary result. */ + *resultPtr++ = RES2; + *resultPtr++ = RES3; + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + int64_t resultReal = 0; + int64_t resultImag = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Complex multiply srcA and srcB and accumulate to the result. */ + resultReal += ((int64_t)CMPLX_REAL(srcA) * (int64_t)CMPLX_REAL(srcB)); + resultReal -= ((int64_t)CMPLX_IMAG(srcA) * (int64_t)CMPLX_IMAG(srcB)); + resultImag += ((int64_t)CMPLX_REAL(srcA) * (int64_t)CMPLX_IMAG(srcB)); + resultImag += ((int64_t)CMPLX_IMAG(srcA) * (int64_t)CMPLX_REAL(srcB)); + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Scale result, saturate and save to result array. */ + CMPLX_REAL(result) = (_iq31)__saturate((resultReal >> 31), INT32_MIN, INT32_MAX); + CMPLX_IMAG(result) = (_iq31)__saturate((resultImag >> 31), INT32_MIN, INT32_MAX); +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mac_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mac_q15.c new file mode 100755 index 000000000..10ff41411 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mac_q15.c @@ -0,0 +1,190 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_mac_q15(const msp_cmplx_mac_q15_params *params, const _q15 *srcA, const _q15 *srcB, _iq31 *result) +{ + uint16_t length; + msp_status status; + MSP_LEA_MACCOMPLEXMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(result, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MACCOMPLEXMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MACCOMPLEXMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MACCOMPLEXMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MACCOMPLEXMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(result); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MACCOMPLEXMATRIX command. */ + msp_lea_invokeCommand(LEACMD__MACCOMPLEXMATRIX); + + /* Free MSP_LEA_MACCOMPLEXMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MACCOMPLEXMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_mac_q15(const msp_cmplx_mac_q15_params *params, const _q15 *srcA, const _q15 *srcB, _iq31 *result) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Initialize the result. */ + CMPLX_REAL(result) = 0; + CMPLX_IMAG(result) = 0; + +#if defined(__MSP430_HAS_MPY32__) + uint16_t *resultPtr = (uint16_t *)result; + + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Initialize result registers. */ + MPY32CTL0 &= ~MPYC; + RESLO = 0; RESHI = 0; + + /* Multiply and accumulate the real components of srcA and srcB. */ + while (length--) { + MACS = (uint16_t)CMPLX_REAL(srcA); + OP2 = (uint16_t)CMPLX_REAL(srcB); + MACS = (uint16_t)(-CMPLX_IMAG(srcA)); + OP2 = (uint16_t)CMPLX_IMAG(srcB); + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Save real result. */ + *resultPtr++ = RESLO; + *resultPtr++ = RESHI; + + /* Reset length to calculate imaginary value, reset result registers */ + length = params->length; + MPY32CTL0 &= ~MPYC; + RESLO = 0; RESHI = 0; + srcA -= length*CMPLX_INCREMENT; + srcB -= length*CMPLX_INCREMENT; + + while (length--) { + MACS = (uint16_t)CMPLX_REAL(srcA); + OP2 = (uint16_t)CMPLX_IMAG(srcB); + MACS = (uint16_t)CMPLX_IMAG(srcA); + OP2 = (uint16_t)CMPLX_REAL(srcB); + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Save imaginary result. */ + *resultPtr++ = RESLO; + *resultPtr++ = RESHI; + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Loop through all vector elements. */ + while (length--) { + /* Complex multiply srcA and srcB and accumulate to the result. */ + CMPLX_REAL(result) += ((int32_t)CMPLX_REAL(srcA) * (int32_t)CMPLX_REAL(srcB)) - ((int32_t)CMPLX_IMAG(srcA) * (int32_t)CMPLX_IMAG(srcB)); + CMPLX_IMAG(result) += ((int32_t)CMPLX_REAL(srcA) * (int32_t)CMPLX_IMAG(srcB)) + ((int32_t)CMPLX_IMAG(srcA) * (int32_t)CMPLX_REAL(srcB)); + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Scale result by 2. */ + CMPLX_REAL(result) <<= 1; + CMPLX_IMAG(result) <<= 1; +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_iq31.c new file mode 100755 index 000000000..b01fa2b05 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_iq31.c @@ -0,0 +1,97 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise Q31 multiplication of two complex source vectors. + */ +msp_status msp_cmplx_mpy_iq31(const msp_cmplx_mpy_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#if defined(__MSP430_HAS_MPY32__) + uint16_t *dstPtr = (uint16_t *)dst; + + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Loop through all vector elements. */ + while (length--) { + /* Complex multiply srcA and srcB and store to dst. */ + MPYS32L = (uint16_t)CMPLX_REAL(srcA); + MPYS32H = (uint16_t)(CMPLX_REAL(srcA) >> 16); + OP2L = (uint16_t)CMPLX_REAL(srcB); + OP2H = (uint16_t)(CMPLX_REAL(srcB) >> 16); + MACS32L = (uint16_t)(-CMPLX_IMAG(srcA)); + MACS32H = (uint16_t)(-CMPLX_IMAG(srcA) >> 16); + OP2L = (uint16_t)CMPLX_IMAG(srcB); + OP2H = (uint16_t)(CMPLX_IMAG(srcB) >> 16); + *dstPtr++ = RES2; + *dstPtr++ = RES3; + MPYS32L = (uint16_t)CMPLX_REAL(srcA); + MPYS32H = (uint16_t)(CMPLX_REAL(srcA) >> 16); + OP2L = (uint16_t)CMPLX_IMAG(srcB); + OP2H = (uint16_t)(CMPLX_IMAG(srcB) >> 16); + MACS32L = (uint16_t)(CMPLX_IMAG(srcA)); + MACS32H = (uint16_t)(CMPLX_IMAG(srcA) >> 16); + OP2L = (uint16_t)CMPLX_REAL(srcB); + OP2H = (uint16_t)(CMPLX_REAL(srcB) >> 16); + *dstPtr++ = RES2; + *dstPtr++ = RES3; + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Loop through all vector elements. */ + while (length--) { + /* Complex multiply srcA and srcB and store to dst. */ + *dst++ = (((int64_t)CMPLX_REAL(srcA) * (int64_t)CMPLX_REAL(srcB)) - ((int64_t)CMPLX_IMAG(srcA) * (int64_t)CMPLX_IMAG(srcB))) >> 31; + *dst++ = (((int64_t)CMPLX_REAL(srcA) * (int64_t)CMPLX_IMAG(srcB)) + ((int64_t)CMPLX_IMAG(srcA) * (int64_t)CMPLX_REAL(srcB))) >> 31; + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_q15.c new file mode 100755 index 000000000..53e98fba2 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_q15.c @@ -0,0 +1,158 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_mpy_q15(const msp_cmplx_mpy_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_MPYCOMPLEXMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYCOMPLEXMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYCOMPLEXMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYCOMPLEXMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MPYCOMPLEXMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MPYCOMPLEXMATRIX command. */ + msp_lea_invokeCommand(LEACMD__MPYCOMPLEXMATRIX); + + /* Free MSP_LEA_MPYCOMPLEXMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MPYCOMPLEXMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_mpy_q15(const msp_cmplx_mpy_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Loop through all vector elements. */ + while (length--) { + /* Complex multiply srcA and srcB and store to dst. */ + MPYS = CMPLX_REAL(srcA); + OP2 = CMPLX_REAL(srcB); + MACS = -CMPLX_IMAG(srcA); + OP2 = CMPLX_IMAG(srcB); + *dst++ = RESHI; + MPYS = CMPLX_REAL(srcA); + OP2 = CMPLX_IMAG(srcB); + MACS = CMPLX_IMAG(srcA); + OP2 = CMPLX_REAL(srcB); + *dst++ = RESHI; + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Loop through all vector elements. */ + while (length--) { + /* Complex multiply srcA and srcB and store to dst. */ + *dst++ = (((int32_t)CMPLX_REAL(srcA) * (int32_t)CMPLX_REAL(srcB)) - ((int32_t)CMPLX_IMAG(srcA) * (int32_t)CMPLX_IMAG(srcB))) >> 15; + *dst++ = (((int32_t)CMPLX_REAL(srcA) * (int32_t)CMPLX_IMAG(srcB)) + ((int32_t)CMPLX_IMAG(srcA) * (int32_t)CMPLX_REAL(srcB))) >> 15; + + /* Increment pointers. */ + srcA += CMPLX_INCREMENT; + srcB += CMPLX_INCREMENT; + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_real_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_real_iq31.c new file mode 100755 index 000000000..08c4b5a8d --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_real_iq31.c @@ -0,0 +1,183 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_cmplx_mpy_real_iq31(const msp_cmplx_mpy_real_iq31_params *params, const _iq31 *srcCmplx, const _iq31 *srcReal, _iq31 *dst) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_MPYLONGMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcCmplx, 4) & + MSP_LEA_VALID_ADDRESS(srcReal, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcReal); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 2; + leaParams->input2Offset = 1; + leaParams->outputOffset = 2; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcCmplx); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MPYLONGMATRIX, MSP_LEA_MPYLONGMATRIX, + sizeof(MSP_LEA_MPYLONGMATRIX)/sizeof(MSP_LEA_MPYLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MPYLONGMATRIX command. */ + cmdId = LEACMD__MPYLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Reset MSP_LEA_MPYLONGMATRIX_PARAMS source 2 and dst pointers. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcReal); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&dst[1]); + + /* Load first source argument to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&srcCmplx[1]); + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_cmplx_mpy_real_iq31(const msp_cmplx_mpy_real_iq31_params *params, const _iq31 *srcCmplx, const _iq31 *srcReal, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#if defined(__MSP430_HAS_MPY32__) + uint16_t *dstPtr = (uint16_t *)dst; + + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply CMPLX_REAL(srcA) and CMPLX_REAL(srcB) */ + MPYS32L = (uint16_t)CMPLX_REAL(srcReal); + MPYS32H = (uint16_t)(CMPLX_REAL(srcReal) >> 16); + OP2L = (uint16_t)CMPLX_REAL(srcCmplx); + OP2H = (uint16_t)(CMPLX_REAL(srcCmplx) >> 16); + *dstPtr++ = RES2; + *dstPtr++ = RES3; + + /* Multiply CMPLX_IMAG(srcA) and CMPLX_REAL(srcB) */ + OP2L = (uint16_t)CMPLX_IMAG(srcCmplx); + OP2H = (uint16_t)(CMPLX_IMAG(srcCmplx) >> 16); + *dstPtr++ = RES2; + *dstPtr++ = RES3; + + /* Increment pointers. */ + srcReal++; + srcCmplx += CMPLX_INCREMENT; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcCmplx and srcReal and store to dst. */ + *dst++ = __q31mpy(*srcCmplx++, *srcReal); // real + *dst++ = __q31mpy(*srcCmplx++, *srcReal++); // imaginary + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_real_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_real_q15.c new file mode 100755 index 000000000..23cf89154 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_mpy_real_q15.c @@ -0,0 +1,72 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise Q15 multiplication of a complex source vector with a real source vector. + */ +msp_status msp_cmplx_mpy_real_q15(const msp_cmplx_mpy_real_q15_params *params, const _q15 *srcCmplx, const _q15 *srcReal, _q15 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcCmplx and srcReal and store to dst. */ + MPYS = *srcReal++; + OP2 = *srcCmplx++; + *dst++ = RESHI; + OP2 = *srcCmplx++; + *dst++ = RESHI; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcCmplx and srcReal and store to dst. */ + *dst++ = __q15mpy(*srcCmplx++, *srcReal); // real + *dst++ = __q15mpy(*srcCmplx++, *srcReal++); // imaginary + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_scale_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_scale_iq31.c new file mode 100755 index 000000000..c2b9e6626 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_scale_iq31.c @@ -0,0 +1,49 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise Q15 multiplication of a single complex source vector + * with a Q15 real scale value and shift left by scale. + */ +msp_status msp_cmplx_scale_iq31(const msp_cmplx_scale_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + msp_scale_iq31_params paramsTemp; + + /* Use real vector scale function with twice the length. */ + paramsTemp.length = params->length << 1; + paramsTemp.scale = params->scale; + paramsTemp.shift = params->shift; + + return msp_scale_iq31(¶msTemp, src, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_scale_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_scale_q15.c new file mode 100755 index 000000000..087e43b0c --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_scale_q15.c @@ -0,0 +1,49 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise Q15 multiplication of a single complex source vector + * with a Q15 real scale value and shift left by scale. + */ +msp_status msp_cmplx_scale_q15(const msp_cmplx_scale_q15_params *params, const _q15 *src, _q15 *dst) +{ + msp_scale_q15_params paramsTemp; + + /* Use real vector scale function with twice the length. */ + paramsTemp.length = params->length << 1; + paramsTemp.scale = params->scale; + paramsTemp.shift = params->shift; + + return msp_scale_q15(¶msTemp, src, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_shift_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_shift_iq31.c new file mode 100755 index 000000000..b29ba77c2 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_shift_iq31.c @@ -0,0 +1,216 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Optimized helper function for shift right with complex conjugate, used for + * inverse FFT functions. + */ +static inline msp_status msp_cmplx_shift_right_conj_iq31(const _iq31 *src, _iq31 *dst, uint16_t length, uint8_t shift); + +/* + * Perform element wise left or right shift of a single complex source vector. + */ +msp_status msp_cmplx_shift_iq31(const msp_cmplx_shift_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + int8_t shift; + uint16_t length; + msp_shift_iq31_params shiftParams; + msp_cmplx_conj_iq31_params conjParams; + + /* Initialize the loop counter and shift variables. */ + length = params->length; + shift = params->shift; + + /* If conjugate is not enabled use real version. */ + if (!params->conjugate) { + shiftParams.shift = params->shift; + shiftParams.length = params->length << 1; + return msp_shift_iq31(&shiftParams, src, dst); + } + else { +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Verify the shift parameter. */ + if ((shift > 31) || (shift < -31)) { + return MSP_SHIFT_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Shift src array left for a positive shift parameter. */ + if (shift > 0) { + /* Loop through all vector elements. */ + while (length--) { + /* Shift src left by the shift parameter and store to dst. */ + *dst++ = *src++ << shift; + *dst++ = -(*src++ << shift); + } + return MSP_SUCCESS; + } + /* Shift src array right for a negative shift parameter. */ + else if (shift < 0) { + /* Use optimized helper function. */ + return msp_cmplx_shift_right_conj_iq31(src, dst, length, -shift); + } + else { + /* No shift, just return conjugate. */ + conjParams.length = length; + return msp_cmplx_conj_iq31(&conjParams, src, dst); + } + } +} + +#if defined(MSP_USE_LEA) + +/* Shift factor lookup table. */ +extern const uint32_t msp_shift_right_factor_iq31[32]; + +static inline msp_status msp_cmplx_shift_right_conj_iq31(const _iq31 *src, _iq31 *dst, uint16_t length, uint8_t shift) +{ + uint16_t cmdId; + int32_t shiftValue; + int32_t *shiftVector; + uint32_t leaFlags; + msp_status status; + MSP_LEA_MPYLONGMATRIX_PARAMS *leaParams; + + /* Lookup the fractional shift value. */ + shiftValue = msp_shift_right_factor_iq31[shift & 0x1f]; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) && MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate shift vector of length one. */ + shiftVector = (int32_t *)msp_lea_allocMemory(sizeof(int32_t)/sizeof(uint32_t)); + shiftVector[0] = shiftValue; + + /* Set MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(shiftVector); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&CMPLX_REAL(dst)); + leaParams->vectorSize = length; + leaParams->input1Offset = 2; + leaParams->input2Offset = 0; + leaParams->outputOffset = 2; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&CMPLX_REAL(src)); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MPYLONGMATRIX, MSP_LEA_MPYLONGMATRIX, + sizeof(MSP_LEA_MPYLONGMATRIX)/sizeof(MSP_LEA_MPYLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MPYLONGMATRIX command. */ + cmdId = LEACMD__MPYLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Save flags status before invoking the next command. */ + leaFlags = msp_lea_ifg; + + /* Rerun the shift operation for imaginary components. */ + shiftVector[0] = -shiftValue; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(&CMPLX_IMAG(dst)); + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(&CMPLX_IMAG(src)); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_MPYLONGMATRIX_PARAMS structure and shift vector. */ + msp_lea_freeMemory(sizeof(int32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Add flags to result. */ + leaFlags |= msp_lea_ifg; + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (leaFlags & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (leaFlags & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (leaFlags & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +static inline msp_status msp_cmplx_shift_right_conj_iq31(const _iq31 *src, _iq31 *dst, uint16_t length, uint8_t shift) +{ + /* Loop through all vector elements. */ + while (length--) { + /* Shift src right by the negated shift parameter and store to dst. */ + *dst++ = *src++ >> shift; + *dst++ = -(*src++ >> shift); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_shift_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_shift_q15.c new file mode 100755 index 000000000..f16114e79 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_shift_q15.c @@ -0,0 +1,186 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Optimized helper function for shift right with complex conjugate, used for + * inverse FFT functions. + */ +static inline msp_status msp_cmplx_shift_right_conj_q15(const _q15 *src, _q15 *dst, uint16_t length, uint8_t shift); + +/* + * Perform element wise left or right shift of a single complex source vector. + */ +msp_status msp_cmplx_shift_q15(const msp_cmplx_shift_q15_params *params, const _q15 *src, _q15 *dst) +{ + int8_t shift; + uint16_t length; + msp_shift_q15_params shiftParams; + msp_cmplx_conj_q15_params conjParams; + + /* Initialize the loop counter and shift variables. */ + length = params->length; + shift = params->shift; + + /* If conjugate is not enabled use real version. */ + if (!params->conjugate) { + shiftParams.shift = params->shift; + shiftParams.length = params->length << 1; + return msp_shift_q15(&shiftParams, src, dst); + } + else { +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Verify the shift parameter. */ + if ((shift > 15) || (shift < -15)) { + return MSP_SHIFT_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Shift src array left for a positive shift parameter. */ + if (shift > 0) { + /* Loop through all vector elements. */ + while (length--) { + /* Shift src left by the shift parameter and store to dst. */ + *dst++ = *src++ << shift; + *dst++ = -(*src++ << shift); + } + return MSP_SUCCESS; + } + /* Shift src array right for a negative shift parameter. */ + else if (shift < 0) { + /* Use optimized helper function. */ + return msp_cmplx_shift_right_conj_q15(src, dst, length, -shift); + } + else { + /* No shift, just return conjugate. */ + conjParams.length = length; + return msp_cmplx_conj_q15(&conjParams, src, dst); + } + } +} + +#if defined(MSP_USE_LEA) + +/* Shift factor lookup table. */ +extern const uint16_t msp_shift_right_factor_q15[16]; + +static inline msp_status msp_cmplx_shift_right_conj_q15(const _q15 *src, _q15 *dst, uint16_t length, uint8_t shift) +{ + int16_t shiftValue; + int16_t *shiftVector; + msp_status status; + MSP_LEA_MPYMATRIX_PARAMS *leaParams; + + /* Lookup the fractional shift value. */ + shiftValue = msp_shift_right_factor_q15[shift & 0xf]; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) && MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate shift vector of length two. */ + shiftVector = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + shiftVector[0] = shiftValue; + shiftVector[1] = -shiftValue; + + /* Set MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(shiftVector); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length << 1; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MPYMATRIX command. */ + msp_lea_invokeCommand(LEACMD__MPYMATRIX); + + /* Free MSP_LEA_MPYMATRIX_PARAMS structure and shift vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +static inline msp_status msp_cmplx_shift_right_conj_q15(const _q15 *src, _q15 *dst, uint16_t length, uint8_t shift) +{ + /* Loop through all vector elements. */ + while (length--) { + /* Shift src right by the negated shift parameter and store to dst. */ + *dst++ = *src++ >> shift; + *dst++ = -(*src++ >> shift); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_sub_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_sub_iq31.c new file mode 100755 index 000000000..cae376be1 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_sub_iq31.c @@ -0,0 +1,46 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise subtraction of two complex source vectors without saturation. + */ +msp_status msp_cmplx_sub_iq31(const msp_cmplx_sub_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + msp_sub_iq31_params paramsTemp; + + /* Use real vector subtraction function. */ + paramsTemp.length = params->length << 1; + + return msp_sub_iq31(¶msTemp, srcA, srcB, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_sub_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_sub_q15.c new file mode 100755 index 000000000..254251a70 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_cmplx_sub_q15.c @@ -0,0 +1,46 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise subtraction of two complex source vectors without saturation. + */ +msp_status msp_cmplx_sub_q15(const msp_cmplx_sub_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + msp_sub_q15_params paramsTemp; + + /* Use real vector subtraction function. */ + paramsTemp.length = params->length << 1; + + return msp_sub_q15(¶msTemp, srcA, srcB, dst); +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mac_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mac_iq31.c new file mode 100755 index 000000000..0478593ab --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mac_iq31.c @@ -0,0 +1,153 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_mac_iq31(const msp_mac_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *result) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_MACLONG_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(result, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MACLONG_PARAMS structure. */ + leaParams = (MSP_LEA_MACLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MACLONG_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MACLONG_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(result); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MACLONGMATRIX, MSP_LEA_MACLONGMATRIX, + sizeof(MSP_LEA_MACLONGMATRIX)/sizeof(MSP_LEA_MACLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MACLONGMATRIX command. */ + cmdId = LEACMD__MACLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_MACLONG_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MACLONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_mac_iq31(const msp_mac_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *result) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Initialize the result. */ + *result = 0; + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; +#endif //__MSP430_HAS_MPY32__ + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcA and srcB and accumulate to the result. */ + *result += __q31mpy(*srcA++,*srcB++); + } + +#if defined(__MSP430_HAS_MPY32__) + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mac_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mac_q15.c new file mode 100755 index 000000000..310a44746 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mac_q15.c @@ -0,0 +1,168 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_mac_q15(const msp_mac_q15_params *params, const _q15 *srcA, const _q15 *srcB, _iq31 *result) +{ + uint16_t length; + msp_status status; + MSP_LEA_MAC_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(result, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MAC_PARAMS structure. */ + leaParams = (MSP_LEA_MAC_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MAC_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MAC_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(result); + leaParams->vectorSize = length; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MAC command. */ + msp_lea_invokeCommand(LEACMD__MAC); + + /* Free MSP_LEA_MAC_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MAC_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_mac_q15(const msp_mac_q15_params *params, const _q15 *srcA, const _q15 *srcB, _iq31 *result) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + uint16_t *resultPtr = (uint16_t *)result; + + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN | MPYSAT; + + /* Reset multiplier context. */ + MPY32CTL0 &= ~MPYC; + RESHI = 0; RESLO = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply and accumulate srcA and srcB. */ + MACS = *srcA++; + OP2 = *srcB++; + } + + /* Store result. */ + *resultPtr++ = RESLO; + *resultPtr++ = RESHI; + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; + +#else //__MSP430_HAS_MPY32__ + + /* Initialize the result. */ + *result = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcA and srcB and accumulate to the result. */ + *result += (int32_t)*srcA++ * (int32_t)*srcB++; + } + + /* Scale result by 2. */ + *result <<= 1; +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_iq31.c new file mode 100755 index 000000000..83d3f4f46 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_iq31.c @@ -0,0 +1,162 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_max_iq31(const msp_max_iq31_params *params, const _iq31 *src, _iq31 *max, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + int32_t *output; + msp_status status; + MSP_LEA_MAXLONG_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MAXLONG_PARAMS structure. */ + leaParams = (MSP_LEA_MAXLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MAXLONG_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (int32_t *)msp_lea_allocMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MAXLONG_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + leaParams->inputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MAXLONGMATRIX, MSP_LEA_MAXLONGMATRIX, + sizeof(MSP_LEA_MAXLONGMATRIX)/sizeof(MSP_LEA_MAXLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MAXLONGMATRIX command. */ + cmdId = LEACMD__MAXLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *max = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MAXLONG_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MAXLONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_max_iq31(const msp_max_iq31_params *params, const _iq31 *src, _iq31 *max, uint16_t *index) +{ + uint16_t i; + uint16_t length; + _iq31 temp; + _iq31 maximum; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Initialize the maximum value and index. */ + maximum = INT32_MIN; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current maximum value. */ + if (temp >= maximum) { + /* Update maximum value and index. */ + maximum = temp; + i = length; + } + } + + /* Save local maximum and index to output arguments. */ + *max = maximum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_q15.c new file mode 100755 index 000000000..ff5ff316b --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_q15.c @@ -0,0 +1,173 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_max_q15(const msp_max_q15_params *params, const _q15 *src, _q15 *max, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + int16_t *output; + msp_status status; + MSP_LEA_MAX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MAX_PARAMS structure. */ + leaParams = (MSP_LEA_MAX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MAX_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MAX_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MAX, MSP_LEA_MAX, + sizeof(MSP_LEA_MAX)/sizeof(MSP_LEA_MAX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MAX command. */ + cmdId = LEACMD__MAX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *max = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MAX_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MAX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_max_q15(const msp_max_q15_params *params, const _q15 *src, _q15 *max, uint16_t *index) +{ + uint16_t i; + _q15 temp; + _q15 maximum; + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize the maximum value and index. */ + maximum = INT16_MIN; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current maximum value. */ + if (temp >= maximum) { + /* Update maximum value and index. */ + maximum = temp; + i = length; + } + } + + /* Save local maximum and index to output arguments. */ + *max = maximum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_uq15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_uq15.c new file mode 100755 index 000000000..cda398c63 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_uq15.c @@ -0,0 +1,161 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_max_uq15(const msp_max_uq15_params *params, const _uq15 *src, _uq15 *max, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + int16_t *output; + msp_status status; + MSP_LEA_MAXUNSIGNED_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MAXUNSIGNED_PARAMS structure. */ + leaParams = (MSP_LEA_MAXUNSIGNED_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MAXUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MAXUNSIGNED_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MAXUNSIGNED, MSP_LEA_MAXUNSIGNED, + sizeof(MSP_LEA_MAXUNSIGNED)/sizeof(MSP_LEA_MAXUNSIGNED[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MAXUNSIGNED command. */ + cmdId = LEACMD__MAXUNSIGNED; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *max = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MAXUNSIGNED_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MAXUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_max_uq15(const msp_max_uq15_params *params, const _uq15 *src, _uq15 *max, uint16_t *index) +{ + uint16_t i; + _uq15 temp; + _uq15 maximum; + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Initialize the maximum value and index. */ + maximum = 0; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current maximum value. */ + if (temp >= maximum) { + /* Update maximum value and index. */ + maximum = temp; + i = length; + } + } + + /* Save local maximum and index to output arguments. */ + *max = maximum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_uq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_uq31.c new file mode 100755 index 000000000..56971b55e --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_max_uq31.c @@ -0,0 +1,162 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_max_uq31(const msp_max_uq31_params *params, const _uq31 *src, _uq31 *max, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + uint32_t *output; + msp_status status; + MSP_LEA_MAXLONGUNSIGNED_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MAXLONGUNSIGNED_PARAMS structure. */ + leaParams = (MSP_LEA_MAXLONGUNSIGNED_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MAXLONGUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (uint32_t *)msp_lea_allocMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MAXLONGUNSIGNED_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + leaParams->inputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MAXUNSIGNEDLONGMATRIX, MSP_LEA_MAXUNSIGNEDLONGMATRIX, + sizeof(MSP_LEA_MAXUNSIGNEDLONGMATRIX)/sizeof(MSP_LEA_MAXUNSIGNEDLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MAXUNSIGNEDLONGMATRIX command. */ + cmdId = LEACMD__MAXUNSIGNEDLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *max = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MAXLONGUNSIGNED_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MAXLONGUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_max_uq31(const msp_max_uq31_params *params, const _uq31 *src, _uq31 *max, uint16_t *index) +{ + uint16_t i; + _uq31 temp; + _uq31 maximum; + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Initialize the maximum value and index. */ + maximum = 0; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current maximum value. */ + if (temp >= maximum) { + /* Update maximum value and index. */ + maximum = temp; + i = length; + } + } + + /* Save local maximum and index to output arguments. */ + *max = maximum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_iq31.c new file mode 100755 index 000000000..a7edbdc54 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_iq31.c @@ -0,0 +1,162 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_min_iq31(const msp_min_iq31_params *params, const _iq31 *src, _iq31 *min, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + int32_t *output; + msp_status status; + MSP_LEA_MINLONG_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MINLONG_PARAMS structure. */ + leaParams = (MSP_LEA_MINLONG_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MINLONG_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (int32_t *)msp_lea_allocMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MINLONG_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + leaParams->inputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MINLONGMATRIX, MSP_LEA_MINLONGMATRIX, + sizeof(MSP_LEA_MINLONGMATRIX)/sizeof(MSP_LEA_MINLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MINLONGMATRIX command. */ + cmdId = LEACMD__MINLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *min = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MINLONG_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MINLONG_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_min_iq31(const msp_min_iq31_params *params, const _iq31 *src, _iq31 *min, uint16_t *index) +{ + uint16_t i; + _iq31 temp; + _iq31 minimum; + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Initialize the minimum value and index. */ + minimum = INT32_MAX; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current minimum value. */ + if (temp <= minimum) { + /* Update minimum value and index. */ + minimum = temp; + i = length; + } + } + + /* Save local minimum and index to output arguments. */ + *min = minimum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_q15.c new file mode 100755 index 000000000..6cd8d20ce --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_q15.c @@ -0,0 +1,173 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_min_q15(const msp_min_q15_params *params, const _q15 *src, _q15 *min, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + int16_t *output; + msp_status status; + MSP_LEA_MIN_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MIN_PARAMS structure. */ + leaParams = (MSP_LEA_MIN_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MIN_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MIN_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MIN, MSP_LEA_MIN, + sizeof(MSP_LEA_MIN)/sizeof(MSP_LEA_MIN[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MIN command. */ + cmdId = LEACMD__MIN; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *min = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MIN_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MIN_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_min_q15(const msp_min_q15_params *params, const _q15 *src, _q15 *min, uint16_t *index) +{ + uint16_t i; + _q15 temp; + _q15 minimum; + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize the minimum value and index. */ + minimum = INT16_MAX; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current minimum value. */ + if (temp <= minimum) { + /* Update minimum value and index. */ + minimum = temp; + i = length; + } + } + + /* Save local minimum and index to output arguments. */ + *min = minimum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_uq15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_uq15.c new file mode 100755 index 000000000..6cba597f1 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_uq15.c @@ -0,0 +1,173 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_min_uq15(const msp_min_uq15_params *params, const _uq15 *src, _uq15 *min, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + int16_t *output; + msp_status status; + MSP_LEA_MINUNSIGNED_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MINUNSIGNED_PARAMS structure. */ + leaParams = (MSP_LEA_MINUNSIGNED_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MINUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MINUNSIGNED_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MINUNSIGNED, MSP_LEA_MINUNSIGNED, + sizeof(MSP_LEA_MINUNSIGNED)/sizeof(MSP_LEA_MINUNSIGNED[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MINUNSIGNED command. */ + cmdId = LEACMD__MINUNSIGNED; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *min = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MINUNSIGNED_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MINUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_min_uq15(const msp_min_uq15_params *params, const _uq15 *src, _uq15 *min, uint16_t *index) +{ + uint16_t i; + _uq15 temp; + _uq15 minimum; + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize the minimum value and index. */ + minimum = UINT16_MAX; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current minimum value. */ + if (temp <= minimum) { + /* Update minimum value and index. */ + minimum = temp; + i = length; + } + } + + /* Save local minimum and index to output arguments. */ + *min = minimum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_uq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_uq31.c new file mode 100755 index 000000000..f04b3ccf1 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_min_uq31.c @@ -0,0 +1,162 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_min_uq31(const msp_min_uq31_params *params, const _uq31 *src, _uq31 *min, uint16_t *index) +{ + uint16_t cmdId; + uint16_t length; + uint32_t *output; + msp_status status; + MSP_LEA_MINLONGUNSIGNED_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MINLONGUNSIGNED_PARAMS structure. */ + leaParams = (MSP_LEA_MINLONGUNSIGNED_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MINLONGUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Allocate output vector of length two. */ + output = (uint32_t *)msp_lea_allocMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + + /* Set MSP_LEA_MINLONGUNSIGNED_PARAMS structure. */ + leaParams->vectorSize = length; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(output); + leaParams->inputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MINUNSIGNEDLONGMATRIX, MSP_LEA_MINUNSIGNEDLONGMATRIX, + sizeof(MSP_LEA_MINUNSIGNEDLONGMATRIX)/sizeof(MSP_LEA_MINUNSIGNEDLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MINUNSIGNEDLONGMATRIX command. */ + cmdId = LEACMD__MINUNSIGNEDLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Write results. */ + *min = output[0]; + *index = output[1]; + + /* Free MSP_LEA_MINLONGUNSIGNED_PARAMS structure and output vector. */ + msp_lea_freeMemory(2*sizeof(uint32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MINLONGUNSIGNED_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_min_uq31(const msp_min_uq31_params *params, const _uq31 *src, _uq31 *min, uint16_t *index) +{ + uint16_t i; + _uq31 temp; + _uq31 minimum; + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Initialize the minimum value and index. */ + minimum = UINT32_MAX; + i = 0; + + /* Loop through all vector elements. */ + while (length--) { + /* Store vector element to local variable. */ + temp = *src++; + + /* Compare vector element with current minimum value. */ + if (temp <= minimum) { + /* Update minimum value and index. */ + minimum = temp; + i = length; + } + } + + /* Save local minimum and index to output arguments. */ + *min = minimum; + *index = params->length - (i + 1); + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mpy_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mpy_iq31.c new file mode 100755 index 000000000..75f41194b --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mpy_iq31.c @@ -0,0 +1,162 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_mpy_iq31(const msp_mpy_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_MPYLONGMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MPYMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MPYLONGMATRIX, MSP_LEA_MPYLONGMATRIX, + sizeof(MSP_LEA_MPYLONGMATRIX)/sizeof(MSP_LEA_MPYLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MPYLONGMATRIX command. */ + cmdId = LEACMD__MPYLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_mpy_iq31(const msp_mpy_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#if defined(__MSP430_HAS_MPY32__) + uint16_t *dstPtr = (uint16_t *)dst; + + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcA and srcB and store to dst. */ + MPYS32L = (uint16_t)*srcA; + MPYS32H = (uint16_t)(*srcA++ >> 16); + OP2L = (uint16_t)*srcB; + OP2H = (uint16_t)(*srcB++ >> 16); + *dstPtr++ = RES2; + *dstPtr++ = RES3; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcA and srcB and store to dst. */ + *dst++ = __q31mpy(*srcA++, *srcB++); + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mpy_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mpy_q15.c new file mode 100755 index 000000000..794969c90 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_mpy_q15.c @@ -0,0 +1,154 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_mpy_q15(const msp_mpy_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_MPYMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MPYMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MPYMATRIX command. */ + msp_lea_invokeCommand(LEACMD__MPYMATRIX); + + /* Free MSP_LEA_MPYMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_mpy_q15(const msp_mpy_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcA and srcB and store to dst. */ + MPYS = *srcA++; + OP2 = *srcB++; + *dst++ = RESHI; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Loop through all vector elements. */ + while (length--) { + /* Multiply srcA and srcB and store to dst. */ + *dst++ = __q15mpy(*srcA++, *srcB++); + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_neg_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_neg_iq31.c new file mode 100755 index 000000000..5552abcb7 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_neg_iq31.c @@ -0,0 +1,139 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_neg_iq31(const msp_neg_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t cmdId; + uint16_t length; + msp_status status; + MSP_LEA_MPYLONGMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_IQ31_CONST_NEG_ONE; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MPYLONGMATRIX, MSP_LEA_MPYLONGMATRIX, + sizeof(MSP_LEA_MPYLONGMATRIX)/sizeof(MSP_LEA_MPYLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MPYLONGMATRIX command. */ + cmdId = LEACMD__MPYLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_neg_iq31(const msp_neg_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Loop through all vector elements. */ + while (length--) { + /* Negate src and store to dst. */ + *dst++ = -*src++; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_neg_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_neg_q15.c new file mode 100755 index 000000000..57dafee16 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_neg_q15.c @@ -0,0 +1,136 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_neg_q15(const msp_neg_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_MPYMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_MPYMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_Q15_CONST_NEG_ONE; + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MPYMATRIX command. */ + msp_lea_invokeCommand(LEACMD__MPYMATRIX); + + /* Free MSP_LEA_MPYMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_neg_q15(const msp_neg_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Loop through all vector elements. */ + while (length--) { + /* Negate src and store to dst. */ + *dst++ = -*src++; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_offset_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_offset_iq31.c new file mode 100755 index 000000000..59d425baf --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_offset_iq31.c @@ -0,0 +1,134 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_offset_iq31(const msp_offset_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + _iq31 iq31Offset; + int32_t *offsetVector; + msp_status status; + MSP_LEA_ADDLONGMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter and offset. */ + length = params->length; + iq31Offset = params->offset; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate offset vector of length one. */ + offsetVector = (int32_t *)msp_lea_allocMemory(sizeof(int32_t)/sizeof(uint32_t)); + offsetVector[0] = iq31Offset; + + /* Set MSP_LEA_ADDLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(offsetVector); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDLONGMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDLONGMATRIX); + + /* Free MSP_LEA_ADDLONGMATRIX_PARAMS structure and offset vector. */ + msp_lea_freeMemory(sizeof(int32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_ADDLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_offset_iq31(const msp_offset_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint16_t length; + _iq31 iq31Offset; + + /* Initialize the loop counter and offset. */ + length = params->length; + iq31Offset = params->offset; + + /* Loop through all vector elements. */ + while (length--) { + /* Add offset to src with saturation and store result. */ + *dst++ = __saturated_add_iq31(*src++, iq31Offset); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_offset_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_offset_q15.c new file mode 100755 index 000000000..1525bb551 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_offset_q15.c @@ -0,0 +1,147 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_offset_q15(const msp_offset_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + _q15 q15Offset; + int16_t *offsetVector; + msp_status status; + MSP_LEA_ADDMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter and offset. */ + length = params->length; + q15Offset = params->offset; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_ADDMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate offset vector of length two. */ + offsetVector = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + offsetVector[0] = q15Offset; + offsetVector[1] = q15Offset; + + /* Set MSP_LEA_ADDMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(offsetVector); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__ADDMATRIX command. */ + msp_lea_invokeCommand(LEACMD__ADDMATRIX); + + /* Free MSP_LEA_ADDMATRIX_PARAMS structure and offset vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_ADDMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_offset_q15(const msp_offset_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + _q15 q15Offset; + + /* Initialize the loop counter and offset. */ + length = params->length; + q15Offset = params->offset; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Loop through all vector elements. */ + while (length--) { + /* Add offset to src with saturation and store result. */ + *dst++ = __saturated_add_q15(*src++, q15Offset); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_scale_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_scale_iq31.c new file mode 100755 index 000000000..8d7dbd935 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_scale_iq31.c @@ -0,0 +1,117 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise Q31 multiplication of a single source vector with a Q31 + * scale value and shift left by scale. There is no risk of intermediate + * saturation between steps however the result will overflow if the result is + * outside the Q31 range of operation. + */ +msp_status msp_scale_iq31(const msp_scale_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + uint8_t shift; + uint16_t length; + int32_t scale; + + /* Initialize the loop counter, scale and shift variables. */ + length = params->length; + scale = params->scale; + shift = params->shift; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check for invalid shift size (maximum of 31). */ + if (shift > 31) { + return MSP_SHIFT_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + int32_t result; + + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Load scale arguments once. */ + MPYS32L = (uint16_t)scale; + MPYS32H = (uint16_t)(scale >> 16); + + /* Select 48-bit result registers based on shift count. */ + if (shift >= 16) { + /* Decrement shift and use registers offset by 16-bits. */ + shift -= 16; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply src and the combined scale and shift value. */ + OP2L = (uint16_t)*src; + OP2H = (uint16_t)(*src++ >> 16); + + /* Combine the three registers comprising the result, with appropriate shifts */ + result = ((uint32_t)RES0 >> (16 - shift)); + result += ((uint32_t)RES1 << (shift)); + result += (int32_t)((uint32_t)RES2 << (shift + 16)); + *dst++ = result; + } + } + else { + /* Loop through all vector elements. */ + while (length--) { + /* Multiply src and the combined scale and shift value. */ + OP2L = (uint16_t)*src; + OP2H = (uint16_t)(*src++ >> 16); + + /* Combine the three registers comprising the result, with appropriate shifts */ + result = ((uint32_t)RES1 >> (16 - shift)); + result += ((uint32_t)RES2 << (shift)); + result += (int32_t)((uint32_t)RES3 << (shift + 16)); + *dst++ = result; + } + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Recalculate shift value to be a shift right offset by the default Q15 shift by 15. */ + shift = 31 - shift; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply src by scale and shift result right by the offset shift value. */ + *dst++ = (_iq31)(((int64_t)*src++ * (int64_t)scale) >> shift); + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_scale_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_scale_q15.c new file mode 100755 index 000000000..5be1b83fc --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_scale_q15.c @@ -0,0 +1,97 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Perform element wise Q15 multiplication of a single source vector with a Q15 + * scale value and shift left by shift. + */ +msp_status msp_scale_q15(const msp_scale_q15_params *params, const _q15 *src, _q15 *dst) +{ + uint16_t length; + uint8_t shift; + int32_t scale; + + /* Initialize the loop counter, scale and shift variables. */ + length = params->length; + scale = params->scale; + shift = params->shift; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check for invalid shift size (maximum of 15). */ + if (shift > 15) { + return MSP_SHIFT_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + +#if defined(__MSP430_HAS_MPY32__) + /* If MPY32 is available save control context and set to fractional mode. */ + uint16_t ui16MPYState = MPY32CTL0; + MPY32CTL0 = MPYFRAC | MPYDLYWRTEN; + + /* Combine the scale and shift parameters to a single 32-bit variable than can be reused. */ + while (shift--) { + scale = scale << 1; + } + + /* Load MPY32 registers for the first argument with the new scale value. */ + MPYS32L = (uint16_t)scale; + MPYS32H = (uint16_t)(scale >> 16); + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply src and the combined scale and shift value. */ + OP2 = *src++; + *dst++ = RESHI; + } + + /* Restore MPY32 control context. */ + MPY32CTL0 = ui16MPYState; +#else //__MSP430_HAS_MPY32__ + /* Recalculate shift value to be a shift right offset by the default Q15 shift by 15. */ + shift = 15 - shift; + + /* Loop through all vector elements. */ + while (length--) { + /* Multiply src by scale and shift result right by the offset shift value. */ + *dst++ = (_q15)(((int32_t)*src++ * (int32_t)scale) >> shift); + } +#endif //__MSP430_HAS_MPY32__ + + return MSP_SUCCESS; +} diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_shift_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_shift_iq31.c new file mode 100755 index 000000000..0962e03b5 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_shift_iq31.c @@ -0,0 +1,199 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Optimized helper function for right shift operations with LEA. + */ +static inline msp_status msp_shift_right_iq31(const _iq31 *src, _iq31 *dst, uint16_t length, uint8_t shift); + +/* + * Perform element wise left or right shift of a single source vector. + */ +msp_status msp_shift_iq31(const msp_shift_iq31_params *params, const _iq31 *src, _iq31 *dst) +{ + int8_t shift; // Shift count + uint16_t length; // Shift length + + /* Initialize the loop counter and shift variables. */ + length = params->length; + shift = params->shift; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Verify the shift parameter. */ + if ((shift > 31) || (shift < -31)) { + return MSP_SHIFT_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Shift src array left for a positive shift parameter. */ + if (shift > 0) { + /* Loop through all vector elements. */ + while (length--) { + /* Shift src left by the shift parameter and store to dst. */ + *dst++ = *src++ << shift; + } + } + /* Shift src array right for a negative shift parameter. */ + else { + /* Use optimized helper function. */ + return msp_shift_right_iq31(src, dst, length, -shift); + } + + return MSP_SUCCESS; +} + +#if defined(MSP_USE_LEA) + +/* Shift factor lookup table. */ +const uint32_t msp_shift_right_factor_iq31[32] = { + 0x80000000, 0x40000000, 0x20000000, 0x10000000, + 0x08000000, 0x04000000, 0x02000000, 0x01000000, + 0x00800000, 0x00400000, 0x00200000, 0x00100000, + 0x00080000, 0x00040000, 0x00020000, 0x00010000, + 0x00008000, 0x00004000, 0x00002000, 0x00001000, + 0x00000800, 0x00000400, 0x00000200, 0x00000100, + 0x00000080, 0x00000040, 0x00000020, 0x00000010, + 0x00000008, 0x00000004, 0x00000002, 0x00000001 +}; + +static inline msp_status msp_shift_right_iq31(const _iq31 *src, _iq31 *dst, uint16_t length, uint8_t shift) +{ + uint16_t cmdId; + int32_t shiftValue; + int32_t *shiftVector; + msp_status status; + MSP_LEA_MPYLONGMATRIX_PARAMS *leaParams; + + /* If shift is zero and source and data are not the same array copy data. */ + if ((shift == 0) && (src != dst)) { + msp_copy_iq31_params copyParams; + copyParams.length = length; + return msp_copy_iq31(©Params, src, dst); + } + + /* Lookup the fractional shift value. */ + shiftValue = msp_shift_right_factor_iq31[shift & 0x1f]; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) && MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Check that the correct revision is defined. */ + if (MSP_LEA_REVISION != msp_lea_getRevision()) { + return MSP_LEA_INCORRECT_REVISION; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate offset vector of length one. */ + shiftVector = (int32_t *)msp_lea_allocMemory(sizeof(int32_t)/sizeof(uint32_t)); + shiftVector[0] = shiftValue; + + /* Set MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(shiftVector); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + +#if (MSP_LEA_REVISION < MSP_LEA_REVISION_B) + /* Load function into code memory */ + cmdId = msp_lea_loadCommand(LEACMD__MPYLONGMATRIX, MSP_LEA_MPYLONGMATRIX, + sizeof(MSP_LEA_MPYLONGMATRIX)/sizeof(MSP_LEA_MPYLONGMATRIX[0])); +#else //MSP_LEA_REVISION + /* Invoke the LEACMD__MPYLONGMATRIX command. */ + cmdId = LEACMD__MPYLONGMATRIX; +#endif //MSP_LEA_REVISION + + /* Invoke the command. */ + msp_lea_invokeCommand(cmdId); + + /* Free MSP_LEA_MPYLONGMATRIX_PARAMS structure and shift vector. */ + msp_lea_freeMemory(sizeof(int32_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MPYLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +static inline msp_status msp_shift_right_iq31(const _iq31 *src, _iq31 *dst, uint16_t length, uint8_t shift) +{ + /* Loop through all vector elements. */ + while (length--) { + /* Shift src right and store to dst. */ + *dst++ = *src++ >> shift; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_shift_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_shift_q15.c new file mode 100755 index 000000000..3b3f0673b --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_shift_q15.c @@ -0,0 +1,179 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +/* + * Optimized helper function for right shift operations with LEA. + */ +static inline msp_status msp_shift_right_q15(const _q15 *src, _q15 *dst, uint16_t length, uint8_t shift); + +/* + * Perform element wise left or right shift of a single source vector. + */ +msp_status msp_shift_q15(const msp_shift_q15_params *params, const _q15 *src, _q15 *dst) +{ + int8_t shift; // Shift count + uint16_t length; // Shift length + + /* Initialize the loop counter and shift variables. */ + length = params->length; + shift = params->shift; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Verify the shift parameter. */ + if ((shift > 15) || (shift < -15)) { + return MSP_SHIFT_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Shift src array left for a positive shift parameter. */ + if (shift > 0) { + /* Loop through all vector elements. */ + while (length--) { + /* Shift src left by the shift parameter and store to dst. */ + *dst++ = *src++ << shift; + } + } + /* Shift src array right for a negative shift parameter. */ + else { + /* Use optimized helper function. */ + return msp_shift_right_q15(src, dst, length, -shift); + } + + return MSP_SUCCESS; +} + +#if defined(MSP_USE_LEA) + +/* Shift factor lookup table. */ +const uint16_t msp_shift_right_factor_q15[16] = { + 0x8000, 0x4000, 0x2000, 0x1000, 0x0800, 0x0400, 0x0200, 0x0100, + 0x0080, 0x0040, 0x0020, 0x0010, 0x0008, 0x0004, 0x0002, 0x0001 +}; + +static inline msp_status msp_shift_right_q15(const _q15 *src, _q15 *dst, uint16_t length, uint8_t shift) +{ + int16_t shiftValue; + int16_t *shiftVector; + msp_status status; + MSP_LEA_MPYMATRIX_PARAMS *leaParams; + + /* If shift is zero and source and data are not the same array copy data. */ + if ((shift == 0) && (src != dst)) { + msp_copy_q15_params copyParams; + copyParams.length = length; + return msp_copy_q15(©Params, src, dst); + } + + /* Lookup the fractional shift value. */ + shiftValue = msp_shift_right_factor_q15[shift & 0xf]; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(src, 4) && MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_MPYMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_MPYMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Allocate offset vector of length two. */ + shiftVector = (int16_t *)msp_lea_allocMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + shiftVector[0] = shiftValue; + shiftVector[1] = shiftValue; + + /* Set MSP_LEA_MPYLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(shiftVector); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 0; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(src); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__MPYMATRIX command. */ + msp_lea_invokeCommand(LEACMD__MPYMATRIX); + + /* Free MSP_LEA_MPYMATRIX_PARAMS structure and shift vector. */ + msp_lea_freeMemory(2*sizeof(int16_t)/sizeof(uint32_t)); + msp_lea_freeMemory(sizeof(MSP_LEA_MPYMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +static inline msp_status msp_shift_right_q15(const _q15 *src, _q15 *dst, uint16_t length, uint8_t shift) +{ + /* Loop through all vector elements. */ + while (length--) { + /* Shift src right and store to dst. */ + *dst++ = *src++ >> shift; + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_sub_iq31.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_sub_iq31.c new file mode 100755 index 000000000..55457c282 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_sub_iq31.c @@ -0,0 +1,125 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_sub_iq31(const msp_sub_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_SUBLONGMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_SUBLONGMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_SUBLONGMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_SUBLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_SUBLONGMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__SUBLONGMATRIX command. */ + msp_lea_invokeCommand(LEACMD__SUBLONGMATRIX); + + /* Free MSP_LEA_SUBLONGMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_SUBLONGMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA undefined + +msp_status msp_sub_iq31(const msp_sub_iq31_params *params, const _iq31 *srcA, const _iq31 *srcB, _iq31 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + + /* Loop through all vector elements. */ + while (length--) { + /* Subtract srcA and srcB with saturation and store result. */ + *dst++ = __saturated_sub_iq31(*srcA++, *srcB++); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_sub_q15.c b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_sub_q15.c new file mode 100755 index 000000000..11c368188 --- /dev/null +++ b/machines/msp430x/small/msp430fr5994/launchpad/dsplib/source/vector/msp_sub_q15.c @@ -0,0 +1,137 @@ +/* --COPYRIGHT--,BSD + * Copyright (c) 2017, Texas Instruments Incorporated + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --/COPYRIGHT--*/ + +#include "../../include/DSPLib.h" + +#if defined(MSP_USE_LEA) + +msp_status msp_sub_q15(const msp_sub_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + msp_status status; + MSP_LEA_SUBMATRIX_PARAMS *leaParams; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } + + /* Check that the data arrays are aligned and in a valid memory segment. */ + if (!(MSP_LEA_VALID_ADDRESS(srcA, 4) & + MSP_LEA_VALID_ADDRESS(srcB, 4) & + MSP_LEA_VALID_ADDRESS(dst, 4))) { + return MSP_LEA_INVALID_ADDRESS; + } + + /* Acquire lock for LEA module. */ + if (!msp_lea_acquireLock()) { + return MSP_LEA_BUSY; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Initialize LEA if it is not enabled. */ + if (!(LEAPMCTL & LEACMDEN)) { + msp_lea_init(); + } + + /* Allocate MSP_LEA_SUBMATRIX_PARAMS structure. */ + leaParams = (MSP_LEA_SUBMATRIX_PARAMS *)msp_lea_allocMemory(sizeof(MSP_LEA_SUBMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set MSP_LEA_SUBMATRIX_PARAMS structure. */ + leaParams->input2 = MSP_LEA_CONVERT_ADDRESS(srcB); + leaParams->output = MSP_LEA_CONVERT_ADDRESS(dst); + leaParams->vectorSize = length; + leaParams->input1Offset = 1; + leaParams->input2Offset = 1; + leaParams->outputOffset = 1; + + /* Load source arguments to LEA. */ + LEAPMS0 = MSP_LEA_CONVERT_ADDRESS(srcA); + LEAPMS1 = MSP_LEA_CONVERT_ADDRESS(leaParams); + + /* Invoke the LEACMD__SUBMATRIX command. */ + msp_lea_invokeCommand(LEACMD__SUBMATRIX); + + /* Free MSP_LEA_SUBMATRIX_PARAMS structure. */ + msp_lea_freeMemory(sizeof(MSP_LEA_SUBMATRIX_PARAMS)/sizeof(uint32_t)); + + /* Set status flag. */ + status = MSP_SUCCESS; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check LEA interrupt flags for any errors. */ + if (msp_lea_ifg & LEACOVLIFG) { + status = MSP_LEA_COMMAND_OVERFLOW; + } + else if (msp_lea_ifg & LEAOORIFG) { + status = MSP_LEA_OUT_OF_RANGE; + } + else if (msp_lea_ifg & LEASDIIFG) { + status = MSP_LEA_SCALAR_INCONSISTENCY; + } +#endif + + /* Free lock for LEA module and return status. */ + msp_lea_freeLock(); + return status; +} + +#else //MSP_USE_LEA + +msp_status msp_sub_q15(const msp_sub_q15_params *params, const _q15 *srcA, const _q15 *srcB, _q15 *dst) +{ + uint16_t length; + + /* Initialize the loop counter with the vector length. */ + length = params->length; + +#ifndef MSP_DISABLE_DIAGNOSTICS + /* Check that length parameter is a multiple of two. */ + if (length & 1) { + return MSP_SIZE_ERROR; + } +#endif //MSP_DISABLE_DIAGNOSTICS + + /* Loop through all vector elements. */ + while (length--) { + /* Subtract srcA and srcB with saturation and store result. */ + *dst++ = __saturated_sub_q15(*srcA++, *srcB++); + } + + return MSP_SUCCESS; +} + +#endif //MSP_USE_LEA diff --git a/machines/msp430x/small/msp430fr5994/launchpad/serial/serial.c b/machines/msp430x/small/msp430fr5994/launchpad/serial/serial.c index 1f750dbe7..d7c4c2f78 100644 --- a/machines/msp430x/small/msp430fr5994/launchpad/serial/serial.c +++ b/machines/msp430x/small/msp430fr5994/launchpad/serial/serial.c @@ -187,7 +187,13 @@ char tpl_serial_read(void) } /* ISR1 related to USCI_A0_VECTOR */ +#if __GXX_ABI_VERSION == 1011 || __GXX_ABI_VERSION == 1013 +__interrupt void tpl_direct_irq_handler_USCI_A0_VECTOR(void) +#elif __GXX_ABI_VERSION ==1002 void __attribute__((interrupt(USCI_A0_VECTOR))) tpl_direct_irq_handler_USCI_A0_VECTOR() +#else + #error "Unsupported ABI" +#endif { #if (SERIAL_TX_BUFFER_SIZE > 0) && (SERIAL_TX_BUFFER_SIZE > 0) uint8_t c;