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

📄 voip8kisr.asm

📁 Cypress 的VOIP DEMO 研究VOIP终端的朋友可以研究研究
💻 ASM
📖 第 1 页 / 共 5 页
字号:
; ----------------------------------------------------------------------------
;
;  Filename:    voip8kIsr.asm
;
;  DESCRIPTION: VoIP Dongle Counter16 Interrupt Service Routine
;
; Remote: Tx1a  Rx1a  Tx1b  Rx1b    Tx2a  Rx2a  Tx2b  Rx2b
; Bridge: Rx1a  Tx1a  Rx1b  Tx1b    Rx2a  Tx2a  Rx2b  Tx2b
; 
; 20Oct06 rwf	Bug w/USB_IN out pointer, "scratchy" mic audio
; 13Oct06 rwf	Maintain IIR average valid voice frames.
; 04Oct06       Reduce 2 bytes RAM by combining 3 booleans into "flags".
; 09Aug06 rwf	isrRadioFileReadWip() reads final byte based on RX_BUFFER_FULL
;		bit because SPI_DONE bit is self-clearing 
; 09Jun06 rwf	Dongle synchronizes to Headset now.
;        	Do ADPCM <-> PCM conversion each 8 KHz ISR: no buffering
;
; -------------------------------------------------------------------------
; $Archive:
; $Modtime:
; $Revision:
; -------------------------------------------------------------------------
;
; Copyright 2005-2006, Cypress Semiconductor Corporation.
;
; This software is owned by Cypress Semiconductor Corporation (Cypress)
; and is protected by and subject to worldwide patent protection (United
; States and foreign), United States copyright laws and international
; treaty provisions. Cypress hereby grants to licensee a personal,
; non-exclusive, non-transferable license to copy, use, modify, create
; derivative works of, and compile the Cypress Source Code and derivative
; works for the sole purpose of creating custom software in support of
; licensee product to be used only in conjunction with a Cypress integrated
; circuit as specified in the applicable agreement. Any reproduction,
; modification, translation, compilation, or representation of this
; software except as specified above is prohibited without the express
; written permission of Cypress.
;
; Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
; WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
; Cypress reserves the right to make changes without further notice to the
; materials described herein. Cypress does not assume any liability arising
; out of the application or use of any product or circuit described herein.
; Cypress does not authorize its products for use as critical components in
; life-support systems where a malfunction or failure may reasonably be
; expected to result in significant injury to the user. The inclusion of
; Cypress' product in a life-support systems application implies that the
; manufacturer assumes all risk of such use and in doing so indemnifies
; Cypress against all charges.
;
; Use may be limited by and subject to the applicable Cypress software
; license agreement.
;
; -------------------------------------------------------------------------

; -------------------------------------------------------------------------
; INDENTATION NOTES:
;  ASM files indent with HARD-TABs and assume standard 8-char/tab
;  'C' files indent with 4 SPACE characters
; -------------------------------------------------------------------------

; -------------------------------------------------------------------------;
;                                                                          ;
;                      I N C L U D E   F I L E S                           ;
;                                                                          ;
; -------------------------------------------------------------------------;
	include "m8c.inc"
	include "memory.inc"
	include "PWM16_1.inc"
	include "usb.inc"
	include "voip.inc"

	include "PSoCGPIOINT.inc"
	include "LpRegs.inc"
	include "LpRadio.inc"
	include "LpIrqMacros.inc"
	INCLUDE "spim_radio.inc"
	include "voipAdpcm.inc"


; ----------------------------------------------------------------------------
; LOOPBACK_ADPCM - USB_OUT to USB_IN, PCM-->ADPCM_Encode-> ADPCM_Decode-->PCM
; ----------------------------------------------------------------------------
LOOPBACK_ADPCM:	EQU	0	; Loopback ADPCM from USB interface

; ----------------------------------------------------------------------------
; SLOTSKIP_TEST - Tests farside's recovery from a temporary bad antenna path.
;            by skipping 64 consecutive SlotA TxGO (192 mS)
;   followed by skipping 64 consecutive SlotB TxGO (192 mS)
;   followed by 128 normal SlotA/SlotB TxGO        (384 mS)
; ----------------------------------------------------------------------------
SLOTSKIP_TEST:	EQU	0	; Skip some TX_GO to test farside recovery

; -----------------------
;  Constant Definitions
; -----------------------
VOIP_PKT_LEN:	equ	15

SPI_CTRL_REG:	EQU	SPIM_Radio_CONTROL_REG
SPI_TX_REG:	EQU	SPIM_Radio_TX_BUFFER_REG
SPI_RX_REG:	EQU	SPIM_Radio_RX_BUFFER_REG
SPI_TX_EMPTY:	EQU	SPIM_Radio_SPIM_TX_BUFFER_EMPTY
SPI_DONE:	EQU	SPIM_Radio_SPIM_SPI_COMPLETE
SPI_RX_FULL:	EQU	SPIM_Radio_SPIM_RX_BUFFER_FULL
; ----------------------------------------------------------------------------
macro	IS_IRQ_ON
	TST	REG[LP_IRQ_Data_ADDR], LP_IRQ_MASK
endm
; ----------------------------------------------
macro	radioSelect
	AND	REG[LP_nSS_Data_ADDR],  ~LP_nSS_MASK
endm
; ----------------------------------------------
macro	radioDeselect
	OR	REG[LP_nSS_Data_ADDR],  LP_nSS_MASK
endm

; ----------------------------------------------------------------------------
; Debug Test signals
; ----------------------------------------------------------------------------
macro	TEST_TIK_ERR1_HI
	OR	REG[TEST_ERR1_Data_ADDR],  TEST_ERR1_MASK
endm
macro	TEST_TIK_ERR1_LO
	AND	REG[TEST_ERR1_Data_ADDR], ~TEST_ERR1_MASK
endm

macro	TEST_TIK_ERR2_HI
	OR	REG[TEST_ERR2_Data_ADDR],  TEST_ERR2_MASK
endm
macro	TEST_TIK_ERR2_LO
	AND	REG[TEST_ERR2_Data_ADDR], ~TEST_ERR2_MASK
endm
; ----------------------------------------------

; ----------------------------------------------
;  Main ISR RAM
; ----------------------------------------------
	AREA	InterruptRAM (RAM,REL,CON)	; <<<<<<<<<<<<<<<<<<<<<<<<<<<<
	; --------------------------------------------------------------------
	;  Radio Tx VOIP buffer is serviced exactly every 3 mS
	; --------------------------------------------------------------------
bufTxVoip:	BLK	VOIP_PKT_LEN 	; 15 Bytes for Radio Tx buffer

	; --------------------------------------------------------------------
	; TWO Rx VoIP buffers ping-pong because although packets arrive an 
	; an AVERAGE of every 3 mS, jitter is +- 1.5 mS depending on whether 
	; the 1st or 2nd copy is used.
	; One buffer feeds the USB, the other loads from the A or B slot
	; --------------------------------------------------------------------
bufRxVoipTog:	BLK	1		; boolean, selects Voip0 or Voip1
bufRxVoip0::	BLK VOIP_PKT_LEN	; 15 Byte data
bufRxVoip1::	BLK VOIP_PKT_LEN	; 15 Byte data

bufTxVoipPtr:	BLK	1	; Ptr to txVoip radio frame composition
bufRxVoipPtr:	BLK	1	; Ptr to rxVoip radio frame decomposition

	; --------------------------------------------------------------------
	;  Rx Control Buffer holds occasional non-VOIP control message.
	;  Tx Control Buffer holds occasional non-VOIP control message.
	; --------------------------------------------------------------------
MAX_CTL_SZ:	EQU	7		; Max buf size for control frame
bufTxCtl:	BLK	(1+MAX_CTL_SZ)	; 1 Byte Len, followed by data
_bufRxCtl::	BLK	(1+MAX_CTL_SZ)	; 1 Byte Len, followed by data
bufTxCtlPtr:	BLK	1		; Load pointer

_slotCt::	BLK	1	; {1-24} wraps every 3 mS
_voipCt::	BLK	2	; Free-running 3 mS counter for f/w timers

	; --------------------------------------------------------------------
	; DIVERSITY TEST: Compare RSSI from each antenna
	; --------------------------------------------------------------------
_tstRssiMax0::	BLK	1	; Ant A Best
_tstRssiMin0::	BLK	1	; Ant A Worst
_tstRssiMax1::	BLK	1	; Ant B Best
_tstRssiMin1::	BLK	1	; Ant B Worst

_rssiAveA_Q3::	BLK	1	; Average RSSI for Antenna A
_rssiAveB_Q3::	BLK	1	; Average RSSI for Antenna B

_rxPktAve_Q3::	BLK	1	; Ant A/B packet average
_rxPktAve_Q8::	BLK	2	; slow average, 0x7F__ is BEST POSSIBLE
_rxPktAveA_Q3::	BLK	1	; Ant A   packet average
_rxPktAveB_Q3::	BLK	1	; Ant B   packet average


	; --------------------------------------------------------------------
	; Scanning all channels for RSSI when redundant slot not needed
	; --------------------------------------------------------------------
rssiCh::	BLK	1	; Channel to check RSSI 
rssiMin::	BLK	1	; Current lowest average RSSI
rssiMinCh::	BLK	1	; Chan # with lowest current average RSSI
p3RssiFilt::	BLK	1	; Ptr to RSSI channel average table on Page 3
	
_bestRssiCh::	BLK	1	; Publish Best alternate channel

	; --------------------------------------------------------------------
	; Advance among possible channel set
	; --------------------------------------------------------------------
_voiceCh::	BLK	1	; Current communication channel
_reqChWrite::	BLK	1	; bool: _voiceCh write to radio request

	; --------------------------------------------------------------------
	; Scratchpad used only with ISR
	; --------------------------------------------------------------------
timeTmpA:	BLK	1
timeTmpB:	BLK	1
timeTmpC:	BLK	1
timeTmpD:	BLK	1
timeTmpE:	BLK	1
timeTmpF:	BLK	1


	; --------------------------------------------------------------------
	; Radio receive variables
	; --------------------------------------------------------------------
RXPKT_NOSOP:	EQU	0	; state: Missing Rx SOP
RXPKT_VOIP:	EQU	1	; state: Load Rx frame as VoIP data
RXPKT_TRASH:	EQU	2	; state: Discard Rx frame as duplicate VoIP data
RXPKT_CTL:	EQU	3	; state: Load Rx frame as Control data
rxPktStat:	BLK	1	; enum for receive state

radRxCount:	BLK	1

rxVoipSet:	BLK	1	; Ptr to new Rx Voip data, 0=no radio data yet

rxGoOn:		BLK	1	; bool: RxGo active, so TxGo must block
txGoSkipped:	BLK	1	; TxGo blocked because RxGo was still active
rxIrqStatus:	BLK	1	; Gather rxIrqStatus bits over various reads

txPktLen:	BLK	1

ISR_VAL_NOM:	 EQU	((3000/8)-1)
ISR_VAL_NOM_MSB: EQU	(>ISR_VAL_NOM)
ISR_VAL_NOM_LSB: EQU	(<ISR_VAL_NOM)
ISR_VAL_POS1:	 EQU	(ISR_VAL_NOM_LSB +1)
ISR_VAL_NEG1:	 EQU	(ISR_VAL_NOM_LSB -1)
isrPeriod:	 BLK	1


; ----------------------------------------------------------------------------
; Statistics, all are 16-bit and wraparound
; ----------------------------------------------------------------------------
_mibMissRx_1::	BLK	2	; Total lost radio frames
_mibMissRx_2::	BLK	2	; Total lost VoIP samples (3 mS gap)
_mibMissTx::	BLK	2	; Total missed Tx because prior Rx too long
macro	INC_16			; ex: INC_16  _mibMissRx_1
	inc	[@0+LSB]
	adc	[@0+MSB], 0
endm

; ----------------------------------------------------------------------------
;
; UART - Bit-bang rough 4800,n,8,1 UART for use as debug channel.
;
; PDC-9267*C dongles have a pad on U2-5.  Although violating RS232 voltage
;  specs, this pad can directly connect to DB9-2 on a PC serial port.
; ----------------------------------------------------------------------------
_uartSr:	BLK	1	// UART Tx Shift Register
_uartTxD::	BLK	1	// UART Tx Holding Register
; --------------------------------------
macro	UART_BIT
	RRC	[_uartSr]
	JC	.bit1
	OR	REG[TEST_SCOPE_Data_ADDR],  TEST_SCOPE_MASK
	JMP	.exit
.bit1:	AND	REG[TEST_SCOPE_Data_ADDR], ~TEST_SCOPE_MASK
.exit:
endm
; --------------------------------------
macro	UART_START
	OR	REG[TEST_SCOPE_Data_ADDR],  TEST_SCOPE_MASK
endm
; --------------------------------------
macro	UART_STOP
	AND	REG[TEST_SCOPE_Data_ADDR], ~TEST_SCOPE_MASK
	MOV	[_uartSr], [_uartTxD]
	MOV	[_uartTxD], 0x00
endm
; ----------------------------------------------------------------------------

	AREA	UserModules (ROM, REL)

	DISABLE_CODE_COMPRESSION ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

; ----------------------------------------------------------------------------
; radTxCtrlPutByte() - Put another byte in Control radio Tx buffer
;
; 		DON'T WRITE MORE THAN 7 BYTES without calling ...PutLen
; 'C' Call:        void radTxCtrlPutByte(BYTE data);
; ----------------------------------------------------------------------------
	export	_radTxCtrlPutByte
_radTxCtrlPutByte::
	MOV	X, [bufTxCtlPtr]
	AND	F, ~FLAG_PGMODE_MASK	; Page Mode 0
	MOV	[X], A
	RAM_RESTORE_NATIVE_PAGING	; Standard compiler Page Mode
	INC	[bufTxCtlPtr]
 	RET

; ----------------------------------------------------------------------------
; radTxCtrlGo() - Put Length in Control Tx buffer
;
; 'C' Call:        void radTxCtrlPutLen(BYTE length);
; ----------------------------------------------------------------------------
	export	_radTxCtrlPutLen
_radTxCtrlPutLen::
	MOV	A, [bufTxCtlPtr]	; Load ptr (inc by Bytes)
	SUB	A, (bufTxCtl + 1)	; A = # bytes loaded
	MOV	[bufTxCtl], A		; Put Length to bufTxCtl on STK_PP
	; Reset load pointer
	MOV	[bufTxCtlPtr], (bufTxCtl+1)
 	RET

; ----------------------------------------------------------------------------
; radTxCtrlPutFull() - Return with Zero Flag SET if OK to write to buffer
; 'C' Call:        BYTE radTxCtrlPutFull(void);
; ----------------------------------------------------------------------------
	export	_radTxCtrlPutFull
_radTxCtrlPutFull::
	MOV	A, [bufTxCtl]		; Ret ZF if OK to write
	RET
; ----------------------------------------------------------------------------

; ----------------------------------------------------------------------------
; isr_8k:
;
; 8 KHz interrupt = 3 MHz/375 (uses 16-bit counter)
;
;   The F register is stored on stack and set to zero before ISR entry.
;   All other registers must be saved/restored if used
; ----------------------------------------------------------------------------
isr_8k::
	TEST_LED_HI	; =======================
	PUSH	A
	PUSH	X
; ----------------------------------------------------------------------------
; USB OUT WORKAROUND
; Either use non-standard USB workaround: manually increment in USB.ASM
; Or use "official return-to-12 MHz" API workaround, running ISR at 24 MHz
; ----------------------------------------------------------------------------
NOT_NDX_WORKAROUND:	EQU	0
 IF NOT_NDX_WORKAROUND
	M8C_SetBank1			; START USB OUT ENDPOINT WORKAROUND
	MOV	A, reg[OSC_CR0]		;
	PUSH	A			;
	AND	A, 0xF8			; ZERO CPU speed bits
	OR	A, OSC_CR0_CPU_24MHz	; Specify
	MOV	reg[OSC_CR0],A		; clk is now 24MHz for sure
	M8C_SetBank0			; STOP USB OUT ENDPOINT WORKAROUND
  ENDIF
; ----------------------------------------------------------------------------
	MOV	A, REG[MVR_PP]
	PUSH	A
	MOV	REG[MVR_PP], 0
	; -----------------------------
	MOV	A, REG[MVW_PP]
	PUSH	A
	MOV	REG[MVW_PP], 0
	; -----------------------------

⌨️ 快捷键说明

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