📄 lpstreaming.asm
字号:
;--------------------------------------------------------------------------
;
; Filename: lpStreaming.asm STREAMING version
;
; Description: User functions to access the LP radio.
; Contains functions and support for to actually perform
; transmit and receive operations.
;
; "Non-streaming" means the entire packet fits in the 16-byte
; buffer in the radio without overflowing.
;
; "Streaming" means the buffer must be monitored and serviced
; while the Tx or Rx transaction is in progress because the
; 16-byte hardware buffer can't hold the entire packet.
;
;--------------------------------------------------------------------------
; WirelessUSB LP Radio Driver Version 1.4
;--------------------------------------------------------------------------
;
; Copyright 2005-2007, 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.
;
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------;
; ;
; I N C L U D E F I L E S ;
; ;
;--------------------------------------------------------------------------;
INCLUDE "lpradio.inc"
INCLUDE "spim_radio.inc"
INCLUDE "psocgpioint.inc"
INCLUDE "lpregs.inc"
INCLUDE "m8c.inc"
INCLUDE "lpIrqMacros.inc"
INCLUDE "memory.inc"
;--------------------------------------------------------------------------;
; ;
; M A C R O D E F I N I T I O N S ;
; ;
;--------------------------------------------------------------------------;
macro ISR_REG_PRESERVE (IOReg)
IF (SYSTEM_LARGE_MEMORY_MODEL)
REG_PRESERVE (@IOReg)
ENDIF
endm
macro ISR_REG_RESTORE (IOReg)
IF (SYSTEM_LARGE_MEMORY_MODEL)
REG_RESTORE (@IOReg)
ENDIF
endm
macro TST_IRQ_PIN
TST REG[LP_IRQ_Data_ADDR], LP_IRQ_MASK
endm
LP_FIFO_SIZE: EQU 16 ; Radio Rx/Tx FIFO size
LP_FIFO_HALF: EQU 8 ; Radio Rx/Tx FIFO half-way mark (B8 flag)
;--------------------------------------------------------------------------;
; ;
; V A R I A B L E S ;
; ;
;--------------------------------------------------------------------------;
AREA InterruptRAM(ram)
RadioBytesRead:: BLK 1
RadioTxCtrlShadow::BLK 1 ; The last value written to TX_CTRL_ADR.
RadioScratch0: BLK 1
;--------------------------------------------------------------------------;
; ;
; C O D E ;
; ;
;--------------------------------------------------------------------------;
macro IsRadioSleep: ; Ret ZERO if Radio is in SLEEP mode
TST [RadioXactConfig], END_STATE_MSK
endm
AREA UserModules (ROM, REL)
DISABLE_CODE_COMPRESSION
;--------------------------------------------------------------------------;
; ;
; T R A N S M I T ;
; ;
;--------------------------------------------------------------------------;
.section
;-----------------------------------------------------------------------------
;
; RadioStartTransmit:
; Start the transmission of a packet. The location of the
; packet buffer to transmit must have previously been set
; by calling RadioSetPtr().
;
; After starting the transmission of a packet with this call,
; the transmit operation should be monitored via
; RadioGetTransmitState(). When RadioGetTransmitState()
; indicates that the transmission has completed, then
; RadioEndTransmit() should be called.
;
; After calling RadioStartTransmit() NO CALLS can be made to
; configuration access routines until transmit operation is
; terminated by calling RadioEndTransmit() or RadioAbort().
; Until a call is made to end the transmit operation
; the only other call supported is RadioGetTransmitState().
;
; 'C' Call: void RadioStartTransmit(BYTE retryCount, RADIO_LENGTH len);
; (A call to RadioSetPtr must have been made prior to the
; call to RadioStartTransmit.)
;
; Assembly Call: A: retry count
; X: packet length
;
; Assembly Return: A: State
; X: Undefined
;-----------------------------------------------------------------------------
_RadioStartTransmit::
RadioStartTransmit::
RAM_SETPAGE_CUR >RadioDriverRamPage
MOV [RadioRetryCount], A ; Save retry count
MOV [RadioPacketLength], X ; and length.
;-----------------------------------------------------------------------------
; RadioRestartTransmit - Retry because no AutoAck from prior Tx
;-----------------------------------------------------------------------------
RadioRestartTransmit:
CALL wakeupRadio
MOV [RadioState], RADIO_TX
MOV [RadioTemp2],(TX_GO | TX_CLR | TXBERR_IRQ | TXC_IRQ | TXE_IRQ)
; Check if packet is longer than TxFIFO. Default to short packet
;
MOV X, [RadioPacketLength] ; X = burst-size to radio
MOV [RadioTxCount], 0 ; default to nothing extra
MOV A, X ; Subtract 16 from the packet size.
SUB A, LP_FIFO_SIZE ; Is radio buf big enough
JC .OneFIFO ; Yes, send entire data
MOV [RadioTxCount], A ; No, save "extra" byte count
MOV X, LP_FIFO_SIZE ; Limit burst to radio buf size
OR [RadioTemp2], TXB8_IRQ ; Extra bytes: need to use TXB8 IRQ
; --------------------------------------------------------------------
; TX_GO is issued (starting the radio transmitting).
; IMMEDIATELY after this (during radio "start-up"), the data
; is copied to the radio. Global Interrupts are disabled, because
; the data must be in the radio before the "startup" is finished.
; --------------------------------------------------------------------
.OneFIFO:
MOV [RadioTxCtrlShadow], [RadioTemp2]
PUSH_F_VIA_A ; Save F reg and disable GIE
PUSH X ; Save data Tx Buf write len
MOV [RadioWipPtr], <RadioTemp1 ; Burst write the
MOV A, TX_LENGTH_ADR ; to start the TX.
MOV X, 2
MOV [RadioWipLen], X
CALL RadioBurstWriteWip ; Write length and TX control as burst.
POP X ; # bytes to burst to radio Tx Buf
MOV A, TX_BUFFER_ADR
CALL RadioFileWrite ; Burst the data in
MOV A, [RadioState]
POP_F_RET ; Ret/restore GIE state
;-----------------------------------------------------------------------------
;
; RadioGetTransmitState:
; Returns the state of the current transmit operation.
; This call should be made after starting a transmit
; operation with the RadioStartTransmit function.
;
; Although bits in the status register in the hardware clear
; automatically, we make them sticky until RadioEndReceive.
;
; 'C' Call: RADIO_STATE RadioGetTransmitState(void);
;
; Assembly Call: A: Unused
; X: Unused
;
; Assembly Return: A: State
; X: Undefined
;-----------------------------------------------------------------------------
_RadioGetTransmitState::
RadioGetTransmitState::
RAM_SETPAGE_CUR >RadioDriverRamPage
TST_IRQ_PIN ; Has interrupt asserted?
JZ RGTSDone ; No, just return the state.
;
; Something interesting is happening at IRQ, find out what.
;
RadioGetTransmitStateIsr:
MOV A, TX_IRQ_STATUS_ADR
CALL RadioReadStatusDebounced
AND A, (TXB8_IRQ | TXBERR_IRQ | TXE_IRQ | TXC_IRQ)
AND A, [RadioTxCtrlShadow]
OR [RadioState], A
XOR A, TXB8_IRQ
JNZ TxDontMoveData
; Moving data, set TX IRQ mask to B8 only to simplify checking
; when subsequent data can be moved after the first burst.
;
MOV X, TXB8_IRQ ; End of the data, clear the B8
MOV A, TX_CTRL_ADR ; flag in the TX control register.
CALL RadioWrite
; Is the remaining data is longer than the 8 free bytes in TxFIFO.
; Start by assuming a short packet. In that case...
;
.MoveDataLoop:
MOV X, [RadioTxCount] ; First burst is PacketLength bytes
MOV [RadioTxCount], 0 ; and we will have no data left.
MOV A, X ; Subtract 8 from the packet size.
SUB A, LP_FIFO_HALF
JC .lastChunk ; If packet size >= 8 fall through
MOV [RadioTxCount], A ; save the difference as remaining
MOV X, LP_FIFO_HALF ; count and use 8 for this burst.
.lastChunk:
MOV A, TX_BUFFER_ADR
CALL RadioFileWriteWip ; Burst the data in.
MOV X, (TXC_IRQ | TXE_IRQ) ; TX_CTRL value assuming no more data.
MOV A, [RadioTxCount] ; Was that the end of the data?
JZ .NoMoreData ; Yes, that will be all.
TST_IRQ_PIN ; Is there room for more data?
JNZ .MoveDataLoop ; Yes, go move some more data.
MOV X, (TXB8_IRQ | TXBERR_IRQ | TXC_IRQ | TXE_IRQ)
; No more room, put TX_CTRL back.
.NoMoreData:
MOV [RadioTxCtrlShadow], X
MOV A, TX_CTRL_ADR ; Update the TX control register.
CALL RadioWrite
TxCheckTxErrors:
MOV A, [RadioState]
AND A, (TXE_IRQ | TXBERR_IRQ)
JZ TxNoErrors
TxIsError:
OR [RadioState], TXC_IRQ
TxNoErrors:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -