📄 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.1
;--------------------------------------------------------------------------
;
; 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.
;
;--------------------------------------------------------------------------
;--------------------------------------------------------------------------;
; ;
; 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 ;
; ;
;--------------------------------------------------------------------------;
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
.endsection
.section
;-----------------------------------------------------------------------------
;
; 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]
RET
.endsection
.section
;-----------------------------------------------------------------------------
;
; RadioEndTransmit: Completes a transmit operation.
;
; 'C' Call: void RadioEndTransmit(void);
;
; Assembly Call: A: Unused
; X: Unused
;
; Assembly Return: A: Preserved
; X: Undefined
;
_RadioEndTransmit::
RadioEndTransmit::
RAM_SETPAGE_CUR >RadioDriverRamPage
MOV [RadioState], RADIO_IDLE ; Clear our status.
RET
.endsection
.section
;-----------------------------------------------------------------------------
;
; RadioBlockingTransmit:
; Transmit a packet. Block execution until it completes.
; This function attempts to transmit a packet. The address
; of the packet buffer should have previously been set with
; a call to RadioSetPtr.
;
; This routine gives the user very little control - probably
; less than most applications will require. This function is
; primarily intended for very simple applications that have
; no use for a time-out.
;
; 'C' Call: RADIO_STATE RadioBlockingTransmit(BYTE retryCt,
; RADIO_LENGTH len);
; (A call to RadioSetPtr must have been made prior to the
; call to RadioBlockingTransmit.)
;
; Assembly Call: A: retryCount
; X: length
; RadioPtr: Address of packet buffer
;
; Assembly Return: A: RADIO_STATE
; X: Undefined
;-----------------------------------------------------------------------------
_RadioBlockingTransmit::
RadioBlockingTransmit::
CALL RadioStartTransmit
.Wait: CALL RadioGetTransmitState
MOV [RadioTemp2], A
TST [RadioTemp2], TXC_IRQ | TXE_IRQ
JZ .Wait
JMP RadioEndTransmit ; A = RADIO_STATE
.endsection
;--------------------------------------------------------------------------;
; ;
; R E C E I V E ;
; ;
;--------------------------------------------------------------------------;
.section
;-----------------------------------------------------------------------------
;
; RadioStartReceive:
; Start the reception of a packet. The location and length of
; the packet buffer to receive the data into must have
; previously been set with a call to RadioSetPtr and
; RadioSetLength.
;
; After starting the reception of a packet with this call,
; the state of the receive operation should be checked by
; calling RadioGetReceiveState. When RadioGetReceiveState
; indicates that the transmission has completed a call
; should be made to RadioEndReceive.
;
; Receive is started by setting RX_GO" bit. All interesting
; interrupt enables are set and RadioGetReceiveState
; can be called in a polling loop in systems that do not use
; interrupts, or can be called directly in an interrupt
; handler.
;
; After calling RadioStartReceive NO CALLS can be made to the
; configuration access routines until receive operation is
; terminated with a call to RadioEndReceive or RadioAbort.
; Until a call is made to end the receive operation
; the only other calls supported are RadioGetReceiveState and
; RadioGetRssi.
;
; 'C' Call: void RadioStartReceive(void);
; (A call to RadioSetPtr must have been made prior to the
; call to RadioStartReceive.)
;
; Assembly Call: A: Unused
; X: Unused
;
; Assembly Return: A: Undefined
; X: Undefined
;-----------------------------------------------------------------------------
_RadioStartReceive::
RadioStartReceive::
RAM_SETPAGE_CUR >RadioDriverRamPage
IF (SYSTEM_LARGE_MEMORY_MODEL)
MOV [RadioWipPtr+1], [RadioPtr+1] ; MSByte of pointer
ENDIF
MOV [RadioWipPtr+0], [RadioPtr+0]
MOV [RadioWipLen], [RadioLen] ; sizeof(RadioPtr)
MOV [RadioState], RADIO_RX
MOV [RadioBytesRead], 0
CALL wakeupRadio
MOV A, RX_CTRL_ADR
MOV X, (RX_GO | RXC_IRQ | RXE_IRQ)
JMP RadioWrite
.endsection
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -