⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firg.asm

📁 DSP的实验测试程序
💻 ASM
字号:
;========================================================================
;
; File Name     :firg.asm
; 
; Originator    :Digital Control Systems Group 
;                Texas Instruments 
; 
; Description   :This file contain source code for Generic FIR Filter
;               
; Date          : 13/1/2001
;======================================================================
; 
; 
; Routine Name  : Generic Function      
; Routine Type  : C Callable
; 
; Description   :
; void FIRFILT_GEN_calc(FIRFILT_GEN_handle) 
; void FIRFILT_GEN_calc(FIRFILT_GEN_handle)
;       
; This routine implements the non-recursive difference equation of an 
; all-zero filter(FIR), of order N. All the coefficients of all-zero 
; filter are assumed to be less than 1 in magnitude.

;======================================================================
;
; Difference Equation :
;
;       y(n)=H(0)*x(n)+H(1)*x(n-1)+H(2)*x(n-2)+....+H(N)*x(n-N)
;
;      where
;              y(n)=output sample of the filter at index n 
;              x(n)=input sample of the filter at index n 
;
; Transfer Function :
;                                  
;              Y(z)                -1        -2               -N+1       -N
;             ----- = h(0) + h(1) z  + h(2) z  + ... +h(N-1) z   + h(N) z    
;              X(z)
;
;     Network Diagram  : 

;     dbuffer[0]          dbuffer[1]    dbuffer[2]    dbuffer[N}
;     Input           -1  x(n-1)  -1    x(n-2)        x(n-N)
;   x(n) >------o----z---->-o----z---->-o---  - ->- - o
;               |           |           |             |
;               |           |           |             |
;               |           |           |             |
;               v H(0)      v H(1)      v H(2)        v H(N)  
;               |           |           |             |  
;               |           |           |             |        output
;               |---->-----(+)---->----(+)-- - -> -  (+)-----> y(n)    
;
;       Symbols Used :
;             H(0),H(1),H(2),...,H(N) : filter coefficients
;            x(n-1),x(n-2),...,x(n-N) : filter states
;                                x(n) : filter input 
;                                y(n) : filter output
;==============================================================================         
;  Function Input: This function accepts the handle of the below structure
;
;  typedef struct 
;     {int *coeff_ptr;          /* Pointer to Filter co-efficient array */
;      int *dbuffer_ptr;        /* Delay buffer pointer                 */ 
;      int order;               /* Order of the filter                  */
;      int input;               /* Input data                           */
;      int output;              /* Output data                          */ 
;      void (*init)(void *)     /* Pointer to init fun                  */  
;      void (*calc)(void *);    /* Pointer to the calculation function  */
;     }FIRFILT_GEN;    
;       
;  Filter input (x) :   
;    x(n) = | s.fff ffff | ffff ffff |
;     
;  Filter coefficients(h[]):
;    h(k) for k=0,1,2,...,N  
;       = | s.fff ffff | ffff ffff |  are stored as shown below.  
;                                                               LOWER MEMORY ADDRESS
;                                                                        |
;                      |----------|                                      |
;                      |   H(0)   |                                      |
;                      |----------|        |----------|                  |
;                      |   H(1)   |        | x(n-1)   | dbuffer[0]       |
;                      |----------|        |----------|                  |
;                      |   H(2)   |        | x(n-2)   | dbuffer[1]       |
;                      |----------|        |----------|                  |
;                      |    .     |        |    .     |                  |
;                      |    .     |        |    .     |                  |
;                      |----------|        |----------|                  V
;                      |   H(N-2) |        |  x(n-N+2)|                  |
;                      |----------|        |----------|                  |
;                      |   H(N-1) |        |  x(n-N+1)| dbuffer[N-2]     V
;                      |----------|        |----------|                  
;           AR3------> |   H(N)   |        |  x(n-N)  | dbuffer[N-1}<--- AR4    
;                      |----------|        |----------|        
;                filter coefficients       filter states 
;                                                              HIGHER MEMORY ADDRESS
; Implicit inputs(dbuffer[]):
;    To compute the present output y(n), inputs x(n-i) for i=1,2,...N
;    are needed. These are stored in the filter states buffer, as shown 
;    above.
;              
; Filter order(n):
;    This member of the structure holds the order of the filter
;
; Filter output(y):
;    y(n)= | s.fff ffff | ffff ffff |  Q15 Format
;====================================================================
; Function Local Frame
;====================================================================
;   |_______|
;   |_______|<- Stack Pointer                           (FP+1) <---AR1
;   |_______|<- Register to Register Tfr & Computation  (FP)  
;   |_______|<- Old FP                                  (FP-1)
;   |_______|<- Return Address of the Caller            (FP-2) 
;   |_______|<- Formal parameter FIRFILT_GEN_handle     (FP-3) 
;======================================================================

; Module definition for external referance
                .def    _FIRFILT_GEN_calc   


__fir_calc_frs  .set    00001h          ; Local frame size for this routine 
          
          
_FIRFILT_GEN_calc:      
            POPD    *+              ; Store the Return Address in stack
            SAR     AR0,*+          ; Store the Caller's Frame Pointer
            SAR     AR1,* 
            LAR     AR2,*+,AR2      ; ARP=AR2, AR2=FP, AR1=FP+1
            
            SETC    SXM         
            SETC    OVM  
            SBRK    #3              ; ARP=AR2, AR2=FP-3 points to the input argument
            LAR     AR2,*           ; ARP=AR2, AR2=FIRFILT_GEN_handle->coeff_ptr 
            
            LAR     AR3,*+          ; ARP=AR2, AR2->dbuffer_ptr, AR3=coeff_ptr->coeff[N] 
            LAR     AR4,*+          ; ARP=AR2, AR2->order, AR4=dbuffer_ptr->dbuffer[N-1]
            LAR     AR5,*+,AR5      ; ARP=AR5, AR5=order, AR2->input
            SBRK    #2              ; ARP=AR5, AR5=order-2
            MAR     *,AR4           ; ARP=AR4, AR4=dbuffer_ptr->dbuffer[N-1]
            
            LACL    #0              ; Clear ACC
            LT      *-,AR3          ; ARP=AR3, TREG=dbuffer[N-1], AR4->dbuffer[N-2]

domac:      MPY     *-,AR4          ; Filter Tap execution from oldest sample                
            LTD     *-,AR5          ; 
            BANZ    domac,*-,AR3    ; 
            
            MPY     *-,AR2          ; ARP=AR2, AR2->input
            LTA     *+,AR3          ; ARP=AR3, AR2->output
            MPY     *,AR2           ;
            APAC                    ;
            
            SACH    *               ; 32 bit of ACC is added with itself to get Q31 result
            ADDH    *               
            SACL    *
            ADDS    *               ; ARP=AR2, AR2->output
            ADD     #1,15           ; Round the result
            SACH    *-              ; ARP=AR2, AR2->input, Store ACCH in Q15 format
            LACL    *,AR4
            MAR     *+
            SACL    *,0,AR1         ; Store the latest sample in the delay buffer
            
            CLRC    OVM
            SBRK    #(__fir_calc_frs+1)     ; Clear the local frame
            LAR     AR0,*-          ; Retrive Caller's frame pointer
            PSHD    *               ; Push the return address to TOS
            RET                     ; Return to the caller
            
            
                           

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -