;*********************Lab3: A Digital Signal Oscillator**********
; This program use recursion equation to generate sinewave:
; y[n]=a*y[n-1]+b*y[n-2]
; a=?
; b=?
; Initially, let n=2,
; y[n-2]=y[0]=?
; y[n-1]=?
; above equations can be found in 
; Digital Signal Processing: Laboratory experiments Using
; C and the TMS320C31 DSK by Rulph Chassaing pp.150-154.
; This program generate sine wave with frequency of 600Hz
; and sampling frequency of 10KHz.
;
;     written by : Jin Churn Chong
;                  Kevin Donohue (donohue@engr.uky.edu)
;
;     University of Kentucky
;     Electrical Engineering Department
;     Date of last revision (8-11-99)
;     Reference: Digital Signal Processing: Laboratory Experiments
;                Using C and the TMS320C31 DSK by Rulph Chassaing
;****************************************************************

          .start   ".text",0x809900   ;starting addr for code
          .start   ".data",0x809c00   ;starting addr for data
          .data                       ;data section
PBASE     .word    808000h            ;peripheral base address
SETSP     .word    0E970300h          ;serial port set-up data
ATABLE    .word    AICSEC             ;SP0 AIC init table addr
AICSEC    .word    162Ch,1h,4892h,67h ;Fs = 10 kHz
a         .float                      ;
b         .float                      ;
onet      .float   1000               ;multiply output by 1000
ynm1      .float                      ;ynm1=y[n-1]
ynm2      .float                      ;ynm2=y[n-2]
;
          .entry  BEGIN          ;start of code
          .text                  ;assemble into text section
BEGIN     LDP     AICSEC         ;init to data page 128
          LDI     @PBASE,AR0     ;AR0=peripheral base address
          LDI     1h,R0          ;Timer CLK=H1/2*(AIC master CLK)
          STI     R0,*+AR0(28h)  ;timer period reg(TCLK0=6.25MHZ)
          LDI     03C1h,R0       ;to init timer global register
          STI     R0,*+AR0(20h)  ;reset timer
          LDI     02h,IOF        ;AIC reset = 0
          LDI     @ATABLE,AR1    ;AR1=AIC init data
          RPTS    99             ;repeat next instr 100 times
          NOP                    ;keep IOF low for a while
          LDI     131h,R0        ;X port control register data
          STI     R0,*+AR0(42h)  ;FSX/DX/CLKX=SP operational pins
          LDI     111h,R0        ;R port control register data
          STI     R0,*+AR0(43h)  ;FSR/DR/CLKR=SP operational pins
          LDI     @SETSP,R0      ;RESET->SP:16 bits,ext clks,std mode
          STI     R0,*+AR0(40h)  ;FSX=output & INT enable SP global reg
          LDI     0,R0           ;R0=0
          STI     R0,*+AR0(48h)  ;clear serial port XMIT register
          OR      06h,IOF        ;bring AIC out of reset
          LDI     03h,RC         ;RC=3 to transmit 4 values
          RPTB    SECEND         ;repeat 4 data transmit of sec com
          CALL    TWAIT          ;wait for data transmit
          LDI     03h,R0         ;value for secondary XMIT request 
          STI     R0,*+AR0(48h)  ;secondary XMIT request to AIC
          CALL    TWAIT          ;wait for data transmit
          LDI     *AR1++,R0      ;R0=next AIC data
SECEND    STI     R0,*+AR0(48h)  ;DTR=curent AIC data
LOOP      CALL    SINECAL        ;your should write your SINECAL routine
          LDI     R6,R7          ;R7=table value
          CALL    TWAIT          ;wait for data transmit
          LSH     2,R7           ;Two LSB MUST = 0 for primary AIC com
          STI     R7,*+AR0(48h)  ;DTR=next data for AIC D/A
          BR      LOOP           ;branch back to LOOP
TWAIT     LDI     *+AR0(40h),R0  ;R0=content of SP global control reg
          AND     02h,R0         ;see if transmit buffer is ready
          BZ      TWAIT          ;if not ready, try again
          RETS                   ;branch from subroutine


;---------------PROCESSING ROUTINE---------------------------------
;Your code begins here to generate sine wave
SINECAL




;end of your code







