Код
####################################################################
## File : asm_codec.s
####################################################################
##
## Version : 1.0
##
## Written by : Chaouki ROUAISSIA
##
## Date : 02-08-2004
##
## Project : -
##
####################################################################
## Changes :
####################################################################
## Description : Reads and writes a sample
##
## Connections between the CODEC and the LC07A :
##
## MCLK --> PB(2)
## FSYNC --> PB(0)
## BCLK --> PB(1)
## SDI --> PB(6)
## SDO --> PA(6)
####################################################################
.altregsyn 0
.global Asm_Send_Receive_Sample ;; Function declared in this file
.text
;******************************************************************;
;* FUNCTION: 'Asm_Send_Receive_Sample' *;
;* INPUT: sample to be sent in r3 and r2 *;
;* OUTPUT: received sample in r3 and r2 *;
;* DESCRIPTION: *;
;* This function sends a 16 bits sample on SDI *;
;* and receives in the mean time a 16 bits sample on SDO *;
;******************************************************************;
Asm_Send_Receive_Sample:
move -(i3), ipl
move -(i3), iph
loop_wait_sampling_event: ;;
move a,RegEvnEvn ;
jzs loop_wait_sampling_event ; Wait for the sampling event
move RegEvn,#0x80 ;;
; the value we want to send is stored in the i1 register
move i1l, r2
move i1h, r3
move r0, RegPBOut ; Read the status of the Port B
or r0, #0x03
move RegPBOut,r0 ; Set BCLK and FSYNC
clrb r0,#1
move RegPBOut,r0 ; Keep FSYNC set and clear BCLK
clrb r0,#0
setb r0,#1
move RegPBOut,r0 ; Clear FSYNC and set BCLK
; in the following loop: first we send and receive the 8 bits of the MSB
; then we send and receive the 8 bits of the LSB
move i0h,#2 ; Initialize byte counter
loop_msb_lsb:
move r2,#0x00 ; By default, the word received on SDO is 00000000
;***************** Read / Write bit 15 then bit 7 *****************;
or r0, #0x42 ;;
tstb i1h,#7 ;
jzc _write_bit_15 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_15: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_15_zero ;; read bit on SDO
setb r2,#7 ;
bit_15_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 14 then bit 6 *****************;
or r0, #0x42 ;;
tstb i1h,#6 ;
jzc _write_bit_14 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_14: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_14_zero ;; read bit on SDO
setb r2,#6 ;
bit_14_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 13 then bit 5 *****************;
or r0, #0x42 ;;
tstb i1h,#5 ;
jzc _write_bit_13 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_13: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_13_zero ;; read bit on SDO
setb r2,#5 ;
bit_13_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 12 then bit 4 *****************;
or r0, #0x42 ;;
tstb i1h,#4 ;
jzc _write_bit_12 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_12: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_12_zero ;; read bit on SDO
setb r2,#4 ;
bit_12_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 11 then bit 3 *****************;
or r0, #0x42 ;;
tstb i1h,#3 ;
jzc _write_bit_11 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_11: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_11_zero ;; read bit on SDO
setb r2,#3 ;
bit_11_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 10 then bit 2 *****************;
or r0, #0x42 ;;
tstb i1h,#2 ;
jzc _write_bit_10 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_10: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_10_zero ;; read bit on SDO
setb r2,#2 ;
bit_10_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 9 then bit 1 *****************;
or r0, #0x42 ;;
tstb i1h,#1 ;
jzc _write_bit_9 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_9: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_9_zero ;; read bit on SDO
setb r2,#1 ;
bit_9_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 8 then bit 0 *****************;
or r0, #0x42 ;;
tstb i1h,#0 ;
jzc _write_bit_8 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_8: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_8_zero ;; read bit on SDO
setb r2,#0 ;
bit_8_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
; Test to check if we have to send the LSB
dec i0h
jzs end
move r3,r2 ; Rotate SDI and SDO registers
move i1h,i1l ;
jump loop_msb_lsb
end:
move iph, (i3)+
move ipl, (i3)+
jump ip
;*********************************************************************;
;* END OF 'Asm_Send_Receive_Sample' FUNCTION *;
;*********************************************************************;
## File : asm_codec.s
####################################################################
##
## Version : 1.0
##
## Written by : Chaouki ROUAISSIA
##
## Date : 02-08-2004
##
## Project : -
##
####################################################################
## Changes :
####################################################################
## Description : Reads and writes a sample
##
## Connections between the CODEC and the LC07A :
##
## MCLK --> PB(2)
## FSYNC --> PB(0)
## BCLK --> PB(1)
## SDI --> PB(6)
## SDO --> PA(6)
####################################################################
.altregsyn 0
.global Asm_Send_Receive_Sample ;; Function declared in this file
.text
;******************************************************************;
;* FUNCTION: 'Asm_Send_Receive_Sample' *;
;* INPUT: sample to be sent in r3 and r2 *;
;* OUTPUT: received sample in r3 and r2 *;
;* DESCRIPTION: *;
;* This function sends a 16 bits sample on SDI *;
;* and receives in the mean time a 16 bits sample on SDO *;
;******************************************************************;
Asm_Send_Receive_Sample:
move -(i3), ipl
move -(i3), iph
loop_wait_sampling_event: ;;
move a,RegEvnEvn ;
jzs loop_wait_sampling_event ; Wait for the sampling event
move RegEvn,#0x80 ;;
; the value we want to send is stored in the i1 register
move i1l, r2
move i1h, r3
move r0, RegPBOut ; Read the status of the Port B
or r0, #0x03
move RegPBOut,r0 ; Set BCLK and FSYNC
clrb r0,#1
move RegPBOut,r0 ; Keep FSYNC set and clear BCLK
clrb r0,#0
setb r0,#1
move RegPBOut,r0 ; Clear FSYNC and set BCLK
; in the following loop: first we send and receive the 8 bits of the MSB
; then we send and receive the 8 bits of the LSB
move i0h,#2 ; Initialize byte counter
loop_msb_lsb:
move r2,#0x00 ; By default, the word received on SDO is 00000000
;***************** Read / Write bit 15 then bit 7 *****************;
or r0, #0x42 ;;
tstb i1h,#7 ;
jzc _write_bit_15 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_15: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_15_zero ;; read bit on SDO
setb r2,#7 ;
bit_15_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 14 then bit 6 *****************;
or r0, #0x42 ;;
tstb i1h,#6 ;
jzc _write_bit_14 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_14: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_14_zero ;; read bit on SDO
setb r2,#6 ;
bit_14_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 13 then bit 5 *****************;
or r0, #0x42 ;;
tstb i1h,#5 ;
jzc _write_bit_13 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_13: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_13_zero ;; read bit on SDO
setb r2,#5 ;
bit_13_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 12 then bit 4 *****************;
or r0, #0x42 ;;
tstb i1h,#4 ;
jzc _write_bit_12 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_12: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_12_zero ;; read bit on SDO
setb r2,#4 ;
bit_12_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 11 then bit 3 *****************;
or r0, #0x42 ;;
tstb i1h,#3 ;
jzc _write_bit_11 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_11: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_11_zero ;; read bit on SDO
setb r2,#3 ;
bit_11_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 10 then bit 2 *****************;
or r0, #0x42 ;;
tstb i1h,#2 ;
jzc _write_bit_10 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_10: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_10_zero ;; read bit on SDO
setb r2,#2 ;
bit_10_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 9 then bit 1 *****************;
or r0, #0x42 ;;
tstb i1h,#1 ;
jzc _write_bit_9 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_9: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_9_zero ;; read bit on SDO
setb r2,#1 ;
bit_9_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
;***************** Read / Write bit 8 then bit 0 *****************;
or r0, #0x42 ;;
tstb i1h,#0 ;
jzc _write_bit_8 ;
clrb r0,#6 ;; write bit on SDI
_write_bit_8: ;
move RegPBOut,r0; update SDI and set BCLK ;
;;
move a,RegPAIn ;;
tstb a,#6 ;
jzs bit_8_zero ;; read bit on SDO
setb r2,#0 ;
bit_8_zero: ;;
clrb r0, #1 ; clear BCLK
move RegPBOut,r0
; Test to check if we have to send the LSB
dec i0h
jzs end
move r3,r2 ; Rotate SDI and SDO registers
move i1h,i1l ;
jump loop_msb_lsb
end:
move iph, (i3)+
move ipl, (i3)+
jump ip
;*********************************************************************;
;* END OF 'Asm_Send_Receive_Sample' FUNCTION *;
;*********************************************************************;