📄 lpnonstreaming.asm
字号:
;--------------------------------------------------------------------------
;
; Filename: lpNonStreaming.asm NON-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
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 | TXC_IRQ | TXE_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.
; --------------------------------------------------------------------
PUSH_F_VIA_RAM ; PUSH F and disable GIE
IF (SYSTEM_LARGE_MEMORY_MODEL)
MOV [RadioWipPtr+1], >RadioTemp1 ; LMM: MSByte of local buf adr
ENDIF
MOV [RadioWipPtr+0], <RadioTemp1 ; Burst write the 2-byte tmp buf
MOV A, TX_LENGTH_ADR ; to start the TX.
MOV X, 2
MOV [RadioWipLen], X
CALL RadioBurstWriteWip ; Write length and TX control as burst.
MOV X, [RadioPacketLength]
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.
;
; IRQ indicates TX_GO is finished
;
RadioGetTransmitStateIsr:
MOV A, TX_IRQ_STATUS_ADR
CALL RadioReadStatusDebounced
AND A, (TXE_IRQ | TXC_IRQ)
OR [RadioState], A
CMP A, TXC_IRQ
JZ RGTSDone ; Tx Complete without Error
; Tx Complete with Error
; During Transaction Ack Rx window, if SOP is received
; then get RXC/RXE (not TXC/TXE). RadioInit() ties RXC/RXE to IRQ.
; Reading RX_IRQ_STATUS_ADR here ensures IRQ deasserts.
;
MOV A, RX_IRQ_STATUS_ADR ; Clear the RX IRQ.
CALL RadioRead
OR [RadioState], (TXE_IRQ | TXC_IRQ) ; Defined as Tx Error
;
; Maybe retry the failed transmit.
;
DEC [RadioRetryCount] ; Dec and test Tx Retry count
JNC RadioRestartTransmit ; Try again.
RGTSDone:
MOV A, [RadioState]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -