AN474
12 Rev. 0.1
3.1.4. Radio Register Initialization
The rtPhyInitRadio() initializes all of the radio r egi sters b ased on the curr ent PHY setting s. Normally, all of the PHY
settings should be set first before calling rtPhyInitRadio(). This uses fewer cycles than attempting to set all
parameters on the fly. The rtPhy InitRadio() function must be called before attempting to transmit or receive.
After Shutting down, all of the radio register values will be lost. After calling rtPhyReStart(), the rtPhyInitRadio()
function should be used again to restore the radio register values. Note that the PHY settings are stored in the
MCU and are not lost in radio Shut Down mode.
3.1.5. Packet Transmission
The rtPhyTx() function se nd s a packet. The transmit function p a ra meter s ar e the packet length and a pointer to the
packet. The transmit buffer is an array of bytes large enough to support the largest transmit packet. The maximum
packet size for the radio, without refilling the FIFO, is 64-bytes. A macro, MSPACE_BUFFER, is used to define the
8051 memory space for the PHY transmit and receive buffers. The transmit function copies the transmit buffer to
the radio FIFO before returning; so, the tran smit buf fer is no rmally p art of the application , and a pointer is p assed to
the PHY layer.
The rtPhyTx() function puts the radio into transmit mode. The function works if the radio is in IDLE or Standby
mode. The function will not work properly if the radio is in Shut Down mode. The time it takes to start transmission
will be faster if the radio is already in IDLE mode.
The transmit function is blocking and will wait until the PKSET interrupt occurs. It is simpler to write wireless
software if the transmit process is entirely procedural and the INT0 interrupt is used only for the receiver.
The rtPhyTx() waits on the PKSENT interrupt with a timeout. The timeout is set to accommodate a 64-byte packet
at the lowest supported baud rate. An error should not normally occur if the hardware is working correctly.
3.1.6. Packet Reception
The packet reception process is based on a receiver interrupt. This simple PHY layer implements simple RX ON
and RX OFF functions. The rtPhyRxOn() turns on the radio receiver and enables the INT0 receiver interrupts. The
rtPhyRxOff() disables interrupts and turns off the radio receiver leaving the radio in IDLE mode. Note that the
rtPhyRxOn() may be used from standby or IDLE mode, but the time it ta kes to enable the rece iver will be longer if
the radio is in standby mode. The rtPhyRxOn() is not blocking and may return before the radio has completed the
transition to the receiver on state.
The receiver interrupt service routine Receiver_ISR() process the packets received by the radio. Normally, when a
valid packet has been received, the IPKVALID interrupt flag will be set. The RxPacketLength sets the receiver
packet length. The packet is copied from the radio FIFO to the receiver interrupt buffer, RxIntBuffer. Then, the
RxPacketReceived bit is set to indicate a packet is ready to be read by the application.
The RxPacketReceived bit is used as a mailbo x fl ag. The inter rupt service routing may only write to the RxIntBuf fer
when the RxPacketReceived bit is cleared and may only set the bit after writing. The application may only read
from the buffer when the bit is set and may only clear the bit after copying the data.
If the receiver interrupt service routine, Receiver_ISR(), receives a packet and the application has not read the last
packet from the buffer, the Receiver_ISR() routine has no choice but to drop the packet.
If the ICRCERROR bit is set, Receiver_ISR() will increment an error counter.
The application should periodically poll the RxPacketReceived bit. If the RxPacketReceived, the application should
use the rtPhyGetRxPacket() function to copy the packet to a local buffer.
The para meters of the rtPhyGetRxPacke t() are two pointer s . The *pLength pointer is a pointer to an unsigned 8-bit
variable to store the p acket len gth. This can poin t to a local packet length variable. The value of RxPacke tLength is
only valid when RxPacketReceived is s et; so, the value must be copied. The *rxBuffer pointer points to an array of
bytes to which the buffer is copied. The buffer must be 64-bytes to accommodate the largest possible received
packet.