;********************************************* ; ; INIT.ASM ASSEMBLER PROGRAM ; ; program designed by Mohamed El-Sharkawy,Ph.D ; program written and compiled by Ronald William Bazillion ; ;********************************************* ; init_system macro DEBUG EQU $000200 NO_PREAMP EQU $100000 SAMP_RATE_48 EQU $003000 STEREO EQU $000400 DATA_16 EQU $200000 IMMED_3STATE EQU $800000 XTAL2_SELECT EQU $200000 BITS_64 EQU $000000 CODEC_MASTER EQU $020000 CTRL_WD_12 EQU NO_PREAMP+SAMP_RATE_48+STEREO+DATA_16 ;CLB=0 CTRL_WD_34 EQU IMMED_3STATE+XTAL2_SELECT+BITS_64+CODEC_MASTER CTRL_WD_56 EQU $000000 CTRL_WD_78 EQU $000000 HEADPHONE_EN EQU $800000 LINEOUT_EN EQU $400000 LEFT_ATTN EQU $010000 ;63*LEFT_ATTN = -94.5 dB, 1.5 dB steps RIGHT_ATTN EQU $000100 ;63*RIGHT_ATTN = -94.5 dB, 1.5 dB steps MIC_IN_SELECT EQU $100000 MONITOR_ATTN EQU $001000 ;15*MONITOR_ATTN = mute, 6dB steps OUTPUT_SET EQU HEADPHONE_EN+LINEOUT_EN+(LEFT_ATTN*4) INPUT_SET EQU MIC_IN_SELECT+(15*MONITOR_ATTN)+(RIGHT_ATTN*4) ; DSP56002 ON-CHIP PERIPHERAL ADDRESSES PCD EQU $FFE5 PCDDR EQU $FFE3 PCC EQU $FFE1 CRA EQU $FFEC CRB EQU $FFED SSIDR EQU $FFEF IPR EQU $FFFF BCR EQU $FFFE SSISR EQU $FFEE PLL EQU $FFFD org x:0 RX_BUFF_BASE EQU * RX_data_1_2 ds 1 ;data time slot 1/2 for RX ISR RX_data_3_4 ds 1 ;data time slot 3/4 for RX ISR RX_data_5_6 ds 1 ;data time slot 5/6 for RX ISR RX_data_7_8 ds 1 ;data time slot 7/8 for RX ISR TX_BUFF_BASE EQU * TX_data_1_2 ds 1 ;data time slot 1/2 for TX ISR TX_data_3_4 ds 1 ;data time slot 3/4 for TX ISR TX_data_5_6 ds 1 ;data time slot 5/6 for TX ISR TX_data_7_8 ds 1 ;data time slot 7/8 for TX ISR SSI_FLAG ds 1 ;bit flags used for word index RX_PTR ds 1 ;Pointer for rx buffer TX_PTR ds 1 ;Pointer for tx buffer init_codec equ $40 org p:0 jmp START org p:$C jsr ssi_rx_isr ;SSI RX jsr ssi_rx_isr ;SSI RX jsr ssi_tx_isr ;SSI TX jsr ssi_tx_isr ;SSI TX ;----------------------------------------------------- ; ; Main init macro ; ;----------------------------------------------------- org p:init_codec ;***************************************************** ; initialize the crystal CS4215 codec ;***************************************************** ; headphones and line out, and set up for no gain or attenuation, and no ; monitor feedback. ;***************************************************** ; ; initialize ssi -- fsync and sclk == outputs ; movep #$0000,x:PCC ;turn off ssi port movep #$4303,x:CRA ;40MHz/16 = 2.5MHz SCLK, WL=16 bits, 4W/F movep #$FB30,x:CRB ;RIE,TIE,RE,TE, NTWK, SYN, FSR/RSR-bit movep #$14,x:PCDDR ; setup pc2 and pc4 as outputs movep #$0,x:PCD ; D/C~ and RESET~ = 0 == control mode do #500,delay_loop rep #2000 ;100 us delay nop delay_loop nop bset #4,x:PCD ; RESET~ = 1 movep #$3000,x:IPR ; set interrupt priority level andi #$FC,mr ;enable interrupts ; set up buffer with control mode data move #CTRL_WD_12,x0 move x0,x:TX_BUFF_BASE move #CTRL_WD_34,x0 move x0,x:TX_BUFF_BASE+1 move #CTRL_WD_56,x0 move x0,x:TX_BUFF_BASE+2 move #CTRL_WD_78,x0 move x0,x:TX_BUFF_BASE+3 movep #$01E8,x:PCC ;Turn on ssi port ; ; CLB == 0 ; jclr #3,x:SSISR,* ;wait until rx frame bit==1 jset #3,x:SSISR,* ;wait until rx frame bit==0 jclr #3,x:SSISR,* ;wait until rx frame bit==1 jset #18,x:RX_BUFF_BASE,* ;loop until CLB set ; ; CLB==1 ; bset #18,x:TX_BUFF_BASE ;set CLB do #4,init_loopB jclr #2,x:SSISR,* ;wait until tx frame bit==1 jset #2,x:SSISR,* ;wait until tx frame bit==0 init_loopB movep #0,x:PCC ;disable, reset SSI ;*************************************************************************** ; now CLB should be 1 -- re-program fsync and sclk direction (i/p) -- movep #$4303,x:CRA ;16bits, 4word/frame, /2/4/2=2.5MHz movep #$FB00,x:CRB ;rcv,xmt & int ena,netwk,syn,sclk==i/p,msb lst movep #$14,x:PCD ;D/C~ pin = 1 == data mode movep #$01E8,x:PCC ;turn on ssi port rts ;**************************SSI TRANSMIT ISR ************************************ ssi_tx_isr jclr #2,x:SSISR,next_tx ;If not frame sync, jump to transmit data. move #TX_BUFF_BASE+1,r0 ;If frame sync, reset pointer. nop next_tx movep x:(r0)+,x:SSIDR ;SSI transfer data register rti ;*************************SSI RECEIVE ISR**************************************** ssi_rx_isr jclr #3,x:SSISR,next_rx ;If not frame sync, jump to receive data. move #RX_BUFF_BASE,r7 ;If frame sync, reset base pointer. nop next_rx movep x:SSIDR,x:(r7)+ ;Read out received data to buffers. rti ;**************************init_system_macro**************************************** START movep #$261009,x:PLL ;set PLL for MPY of 10x movep #$0000,x:BCR ;number of wait states ori #3,mr ;disable interrupts movec #0,sp move #0,omr ;single chip mode move #3,m0 ;Modulus 4 buffer. move #3,m7 ;Modulo 4 buffer. move #RX_BUFF_BASE,x0 move x0,x:RX_PTR ;Initialize the rx pointer move x:RX_PTR,r7 ;Load the pointer to the rx buffer. move #TX_BUFF_BASE+1,x0 move x0,x:TX_PTR ;Initialize the tx pointer move x:TX_PTR,r0 ;Load the pointer to the rx buffer. jsr init_codec ;init the output set in the beginning rather than each time move #OUTPUT_SET,y0 ;headphones, line out, mute spkr, no attn move y0,x:TX_BUFF_BASE+2 move #INPUT_SET,y0 ;no input gain, monitor mute move y0,x:TX_BUFF_BASE+3 ;wait for sync to be established and then switch to shorter interrupts do #$100,gothru jclr #2,x:SSISR,* ;wait until tx frame bit==1 jset #2,x:SSISR,* ;wait until tx frame bit==0 nop gothru nop ;set up shorter interrupts to next_rx for receiving and next_tx for trans. move #next_rx,a1 move a1,p:$d move #next_tx,a1 move a1,p:$11 nop endm wait_receive macro ;this macro wait to recieve data jclr #3,x:SSISR,* ;wait until rx frame bit==1 jset #3,x:SSISR,* ;wait until rx frame bit==0 endm wait_send macro jclr #2,x:SSISR,* ;wait until rx frame bit==1 jset #2,x:SSISR,* ;wait until rx frame bit==0 endm get_left macro ;this macro get the left channel to x0 move x:RX_BUFF_BASE,x0 endm put_left macro ;this macro put the left channel from a move a,x:TX_BUFF_BASE endm get_right macro ;this macro get the right channel to x1 move x:RX_BUFF_BASE+1,x1 endm put_right macro ;this macro put the right channel from b move b,x:TX_BUFF_BASE+1 endm wait_word macro jclr #1,r7,* endm