00001 /*This file has been prepared for Doxygen automatic documentation generation.*/ 00016 /* Copyright (c) 2009 Atmel Corporation. All rights reserved. 00017 * 00018 * Redistribution and use in source and binary forms, with or without 00019 * modification, are permitted provided that the following conditions are met: 00020 * 00021 * 1. Redistributions of source code must retain the above copyright notice, this 00022 * list of conditions and the following disclaimer. 00023 * 00024 * 2. Redistributions in binary form must reproduce the above copyright notice, 00025 * this list of conditions and the following disclaimer in the documentation 00026 * and/or other materials provided with the distribution. 00027 * 00028 * 3. The name of Atmel may not be used to endorse or promote products derived 00029 * from this software without specific prior written permission. 00030 * 00031 * 4. This software may only be redistributed and used in connection with an Atmel 00032 * AVR product. 00033 * 00034 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED 00035 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00036 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE 00037 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR 00038 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00039 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00040 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00041 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00042 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00043 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE 00044 * 00045 */ 00046 #include "dsp.h" 00047 00048 00049 #if !defined(FORCE_ALL_GENERICS) && \ 00050 !defined(FORCE_GENERIC_FILT32_LMS) && \ 00051 defined(TARGET_SPECIFIC_FILT32_LMS) 00052 00053 #include "filt_lms.h" 00054 00055 void dsp32_filt_lms(dsp32_t *x, dsp32_t *w, int size, dsp32_t new_x, dsp32_t d, dsp32_t *y, dsp32_t *e) 00056 { 00057 int i = 0; 00058 00059 x[0] = new_x; 00060 00061 /* // Performed a FIR 00062 __asm__ __volatile__ ( 00063 "mov %3, 0\n\t" 00064 "mov r4, %3\n\t" 00065 "mov r5, %3\n\t" 00066 "cp.w %4, 0\n\t" 00067 "brle _filt_nlms_end_fir\n" 00068 00069 "_filt_nlms_loop_fir:\n\t" 00070 00071 "ld.d r0, %1[%3 << 2]\n\t" 00072 "ld.d r2, %2[%3 << 2]\n\t" 00073 "macs.d r4, r0, r2\n\t" 00074 "macs.d r4, r1, r3\n\t" 00075 00076 "sub %3, -2\n\t" 00077 00078 "ld.d r0, %1[%3 << 2]\n\t" 00079 "ld.d r2, %2[%3 << 2]\n\t" 00080 "macs.d r4, r0, r2\n\t" 00081 "macs.d r4, r1, r3\n\t" 00082 00083 "sub %3, -2\n\t" 00084 "cp.w %4, %3\n\t" 00085 "brgt _filt_nlms_loop_fir\n" 00086 00087 "_filt_nlms_end_fir:\n\t" 00088 00089 "lsr %0, r4, "ASTRINGZ(DSP32_QB)"\n\t" 00090 "or %0, %0, r5 << "ASTRINGZ(DSP32_QA)"\n\t" 00091 00092 : "=r" (*y) 00093 : "r" (w), "r" (x), "r" (i), "r" (size), "0" (*y) 00094 : "r0", "r1", "r2", "r3", "r4", "r5", "r8" 00095 );*/ 00096 00097 dsp32_filt_lms_fir(x, w, size, y, i); 00098 00099 // Error calculation 00100 *e = d - *y; 00101 00102 // Refresh the w coefficients 00103 for(i=0; i<size; i+=4) 00104 { 00105 w[i] += ((((S64) *e)*((S64) x[i]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00106 w[i+1] += ((((S64) *e)*((S64) x[i+1]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00107 w[i+2] += ((((S64) *e)*((S64) x[i+2]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00108 w[i+3] += ((((S64) *e)*((S64) x[i+3]))) >> (DSP_LMS_MU - 1 + DSP32_QB); 00109 } 00110 00111 // Shift the circular buffer 00112 for(i=size-1; i>0; i-=4) 00113 { 00114 x[i] = x[i-1]; 00115 x[i-1] = x[i-2]; 00116 x[i-2] = x[i-3]; 00117 x[i-3] = x[i-4]; 00118 } 00119 } 00120 00121 #endif