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

📄 dpll.asm

📁 用dsp解压mp3程序的算法
💻 ASM
📖 第 1 页 / 共 2 页
字号:
*********************************************************************
* DPLL.asm: TMS320F2407 implementation of digital phase-locked loops
*           for C2000 CCS simulator
*--------------------------------------------------------------------
*  DSP Algorithms:
*
*  e(n) ----------------- e'(n)  -------  c(n)
*  ---->| Median filter |------->| LPF |----->
*       -----------------        -------
*
*  where
*    Median filter: Order 5, the output e'(n) is the median of 5
*                   samples in the buffer
*    LPF is the moving-average filter of length L
*      implemented by the first-order IIR filter.
*
*  NOTE: data buffers for median filters and LPFs are
*        initialized to the value of 2047
*        e(n) is the data from data file "en.int"
********************************************************************
             .mmregs            ; include symbolic names of MMRs

********************************************************************
* Interrupt vector table for TMS320F2407
*   See TMS320F2407 data sheet, pp. 24-25
********************************************************************
             .sect ".vectors"

RSVECT        B        START    ; PM 0, Reset

********************************************************************
* Following interrupts may be defined later based on target hardware
* and add interrupt service routines. For example,
*
* INT1        B        ISR_1    ; branch to ISR_1 if INT1 occurs
*
* Each vector occupy two words, B ISR_routinename takes two words
*   however, RET only uses 1 word, thus use NOP to fill the gap here
********************************************************************

INT1          RET               ; PM 2, INT1
              NOP               ; dummy for 2-word table
INT2          RET               ; PM 4, INT2
              NOP
INT3          RET               ; PM 6, INT3
              NOP
INT4          RET               ; PM 8, INT4
              NOP
INT5          RET               ; PM Ah, INT5
              NOP
INT6          RET               ; PM Ch, INT6
              NOP
RESERVED      RET               ; PM Eh
              NOP
SW_INT8       RET               ; PM 10h, User S/W int
              NOP
SW_INT9       RET               ; PM 12h, User S/W int
              NOP
SW_INT10      RET               ; PM 14h, User S/W int
              NOP
SW_INT11      RET               ; PM 16h, User S/W int
              NOP
SW_INT12      RET               ; PM 18h, User S/W int
              NOP
SW_INT13      RET               ; PM 1Ah, User S/W int
              NOP
SW_INT14      RET               ; PM 1Ch, User S/W int
              NOP
SW_INT15      RET               ; PM 1Eh, User S/W int
              NOP
SW_INT16      RET               ; PM 20h, User S/W int
              NOP
TRAP          RET               ; PM 22h, Trap vector
              NOP
NMI           RET               ; PM 24h, Non maskable Int
              NOP
EMU_TRAP      RET               ; PM 26h, Emulator Trap
              NOP
SW_INT20      RET               ; PM 28h, User S/W int
              NOP
SW_INT21      RET               ; PM 2Ah, User S/W int
              NOP
SW_INT22      RET               ; PM 2Ch, User S/W int
              NOP
SW_INT23      RET               ; PM 2Eh, User S/W int
              NOP

**********************************************************************
* include e(n) from data files en.int into data
* memory locations for program development
**********************************************************************
             .sect    ".indata"
en_in        .copy    "en.int"    ; copy en.dat to memory label en_in
             .bss     cn_out,1024 ; reserve 1024 words for saving c(n)

             .text                ; program segment

*  LPF (or mean estimator) is the 1st-order IIR filter approximation 
*      of moving-average filter of order L
* 
*    e'(n)   -------   c(n)
*    ------->| LPF |------>
*            -------
*
*    c(n) = (1-a)*c(n-1) + a*e'(n)
*         = c(n-1) - a*c(n-1) + a*e'(n)
*
*    where a = 1/L. Assume L = 2^m, a = 2^-m, which can be implemented
*      by shifting right m bits of data
*
*    Let c(n) be represented by double-precision 32-bit word, 
*      shift right m-bit can be implemented by 
*      loading ACC with shift left (16-m) bits      
*
*  Relationship between L, m, and 16-m:
*
*     L  | 2 4  8  16 32 64 128 256 512 1024 2048 4096 8192 16384 32768
*     m  | 1 2  3  4  5  6   7   8   9   10   11   12   13    14    15
*   16-m |15 14 13 12 11 10  9   8   7    6    5    4    3     2     1
*
*   Assuming L = 256 is used LPF, m = 8, 16-m = 8
*            L = 16 is used for mean estimator, m = 4, 16-m = 12

m8           .set     8         ; order 256
m4           .set    12         ; order 16
file_length  .set    1024       ; length of input data file


**********************************************************************
*  Memory (on-chip DARAM) map:
*
*   B2 (page 0): 060h - 07Fh, used for switching and automatic phase
*                             compensation, data I/O buffer, MISC
*   B0 (pages 4, 5): 0200h - 02FFh, used for REF 1
*   B1 (pages 6, 7): 0300h - 03FFh, used for REF 2
*
**********************************************************************
*    Page 0, B2 DARAM, 060h - 07Fh
*

en           .set    060h       ; address of e(n)
cn           .set    061h       ; address of c(n)
loop_cnt     .set    065h       ; address of loop counter
ONE          .set    066h       ; address of ONE, contain constant 1

**********************************************************************
*    Page 4, B0, 0200h - 027Fh, use for REF 1 processing
*

* buffer for median filter

med1_buf0    .set    0200h      ; address of med_buf[0]
med1_buf1    .set    0201h      ; address of med_buf[1]
med1_buf2    .set    0202h      ; address of med_buf[2]
med1_buf3    .set    0203h      ; address of med_buf[3]
med1_buf4    .set    0204h      ; address of med_buf[4]

* buffer for sorting of median filter

sort1_buf0   .set    0205h      ; address of sort_buf[0]
sort1_buf1   .set    0206h      ; address of sort_buf[1]
sort1_buf2   .set    0207h      ; address of sort_buf[2]
sort1_buf3   .set    0208h      ; address of sort_buf[3]
sort1_buf4   .set    0209h      ; address of sort_buf[4]

temp1        .set    020ah      ; address of temp1
cn_high      .set    020bh      ; address of c(n),  high word
cn_low       .set    020ch      ; address of c(n), low word

*---------------------------------------------------------------------
*    Page 5, B0, 0280h - 02FFh, not been used yet!

**********************************************************************
*    Page 6, B1, 0300h - 037Fh, use for REF 2 processing

*---------------------------------------------------------------------
*    Page 7, B1, 0380h - 03FFh, not been used yet!

*=====================================================================
* Processor initialization - starts here from RESET
*=====================================================================

START:  DINT                  ; disable interrupt
        LDP     #0            ; DP = 0, page 0
        SETC    SXM           ; SXM = 1, sign-extension mode
      
*
*  Initialize memory on page 0
*
        MAR     *,AR7         ; ARP = 7, AR7 used as pointer
        LAR     AR7,#060h     ; AR7 -> lowest address of B2
        ZAC                   ; ACC = 0
        RPT     #31           ; repeat next instruction 32 times
        SACL    *+            ; clear 32 words memory on B2
                              ; REF_ID = 0, REF1 is used
                              ; OFFSET = loop_cnt = 0

        LACL    #1            ; ACC = 1
        SACL    ONE           ; ONE = 1
        
*
*  Clear pages 4, 5, 6, and 7
*
        LAR     AR7,#0200h    ; AR7 -> lowest address of page 4
        ZAC                   ; ACC = 0
        RPT     #255          ; repeat next instruction 256 times
        SACL    *+            ; clear memory on pages 4 & 5

        RPT     #255          ; repeat next instruction 256 times
        SACL    *+            ; clear memory on pages 6 & 7

*
*  Initialize data memory locations
*
        LACC    #2047           ; ACC = 2047
        LAR     AR7,#med1_buf0  ; AR7 -> median buffer of REF1
        RPT     #4              ; repeat next instruction 5 times
        SACL    *+              ; med1_buf[i] = 2047, i=0,1,2,3,4
        LAR     AR7,#cn_high    ; AR7 -> c(n), high word
        SACL    *               ; c(n) = 2047
 

⌨️ 快捷键说明

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