📄 infinitelink.c
字号:
/*******************************************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** This program lets the user test a simple rf link with packets longer than *
* *** + 256 bytes. *
* *** + + *** *
* *** +++ *** InfiniteLink.c *
* *** *** *
* ************ *
* ********** *
* *
*******************************************************************************************************
* Compiler: Keil C51 V7.50 *
* Target platform: Chipcon CCxxx0 (Silabs F320) *
* Author: SNA *
*******************************************************************************************************
* Revision history: See end of file *
******************************************************************************************************/
#include <Chipcon\srf04\regssrf04.h>
#include <Chipcon\srf04\halsrf04.h>
#include <Chipcon\srf04\ebsrf04.h>
#include <InfiniteLink.h>
#include <stdlib.h>
#include <intrins.h>
//-------------------------------------------------------------------------------------------------------
// DESCRIPTION:
// This program demonstrates how it is possible to transmit and receive packets that are longer
// than 256 bytes. The radios use a combination of infinite and fixed packet length mode,
// CRC enabled and append status. No form of filtering should be used as one should not read any
// status registers (See the CC1100 or 2500 Errata Note) to determine if the FIFO
// has been flushed or not.
// If other data rates than 76.8 kbps should be used, the halWait(320) in the EXTERNAL0_ISR(void)
// needs to be changed to:
// halWait(n);, where n = 3*8*(1/data rate) + a couple of us margin
// For better understanding on how this program works, please see the
// CC1100/CC1150DK & CC2500/CC2550DK Development Kit Examples and Libraries User Manual
//
// Parameters | Values
// ------------------------------------------------------
// Packet Length | 270, 290,....., 430, 450
// Number of Packets | 100, 200, 300, ......, 900, 1000
// Radio Mode | Rx, Tx
//
// RX UNIT:
// * Set radio mode to RX.
// * Move joystick down until the message
// "Press S1 to start" is showed on the LCD display
// * Press S1
//
// The LCD display will show number of packets received with CRC OK
//
// TX UNIT:
// * Set packet length and number of packets to transmit
// * Set radio mode to TX
// * Press S1 to Start
//
// The LCD will show number of packets transmitted
//
// After all the packets have been transmitted, S1 can be pressed again to transmit
// or the joystick can be used to change packet length and number of packets
// to transmit
//
//
// IMPORTANT NOTICE!
// When compiling this example you will get the following warnings:
//
// *** WARNING L15: MULTIPLE CALL TO FUNCTION
// NAME: _HALSPIREADBURSTREG/SPIREADBURSTREG
// CALLER1: EXTERNAL1_ISR/INFINITELINK
// CALLER2: EXTERNAL0_ISR/INFINITELINK
// *** WARNING L15: MULTIPLE CALL TO FUNCTION
// NAME: _HALSPIWRITEBURSTREG/SPIWRITEBURSTREG
// CALLER1: EXTERNAL1_ISR/INFINITELINK
// CALLER2: ?C_C51STARTUP
//
// These warnings are generated because the halSpiReadBurstReg and halSpiWriteBurstReg functions
// are not reentrant. The code is, however, written so that these interrupts will never occur while
// in the process of accessing the SPI interface, so these warnings can be ignored.
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// Global Variables
BYTE xdata txBuffer[454]; // 2 length bytes + 450 bytes payload + 2 status bytes
BYTE xdata rxBuffer[454]; // 2 length bytes + 450 bytes payload + 2 status bytes
UINT8 xdata joystickPosition = JOYSTICK_CENTER;
UINT8 xdata prevJoystickPosition = JOYSTICK_CENTER;
UINT8 state = SETUP; // Variable used to hold the next state in the state machine in the main loop
TX_DATA xdata txData = {
0, // bytesLeft
0, // iterations
FALSE, // writeRemainingDataFlag
FALSE, // packetSentFlag
txBuffer, // *pBufferIndex
0, // packetsSent
INFINITE // pktFormat
};
RX_DATA xdata rxData = {
0, // bytesLeft
FALSE, // packetReceivedFlag
SYNC, // syncOrEndOfPacket
rxBuffer, // *pBufferIndex
0, // lengthByte
FALSE, // crcOK
0, // packetsReceived
INFINITE // pktFormat
};
UINT8 fixedPacketLength;
//-------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------
// void main(void)
//
// DESCRIPTION:
// This function takes care of all the MCU initialization and radio configuration. The main loop
// is implemented as a state machine and a state diagram can be found in the
// CC1100/CC1150DK & CC2500/CC2550DK Development Kit Examples and Libraries User Manual
//----------------------------------------------------------------------------------------------------
void main (void) {
#ifdef STAND_ALONE
// Select the Internal Oscillator as Multiplier input source and disable the watchdog timer
// SYSCLK = 4X Clock Multiplier / 2
CLOCK_INIT();
#endif
// Set up the crossbar and I/O ports to communicate with the SmartRF04EB peripherals
IO_PORT_INIT();
// Initialize the LCD display. The SMBus uses timer 0 to generate SCL
ebLcdInit();
// Initialize the ADC converter
ebAdcInit(ADC_JOY);
SPI_INIT(SCLK_6_MHZ);
// Reset CC2500 and write rf setting to config registers
POWER_UP_RESET_CCxxx0();
halRfWriteRfSettings(&rfSettings);
halSpiWriteReg(CCxxx0_PATABLE, paTable);
handleAndDisplayMenu();
INT_PRIORITY(INUM_EXTERNAL1, INT_HIGH);
// Infinite loop
while (TRUE) {
switch (state) {
//----------------------------------------------------------------------------------------
case SETUP:
//----------------------------------------------------------------------------------------
// This wait is implemented to give the LCD display enought time to be update
// between each iteration
halWait(250);
joystickPosition = ebGetJoystickPosition();
if (prevJoystickPosition != joystickPosition)
parseMenu(joystickPosition);
prevJoystickPosition = joystickPosition;
if ((index == START) && (ebButtonPushed())) {
ENABLE_GLOBAL_INT(INT_OFF);
if (menuData.radioMode == RX) {
state = RX_START;
ebLcdUpdate("Waiting for", "data");
// Associated to the RX FIFO: Asserts when RX FIFO is filled above RXFIFO_THR.
// De-asserts when RX FIFO is drained below RXFIFO_THR.
halSpiWriteReg(CCxxx0_IOCFG2, 0x00);
SETUP_GDO2_INT(EDGE, HIGH); // Enables external interrupt on rising edge
SETUP_GDO0_INT(EDGE, HIGH);
} else {
state = TX_START;
// Associated to the TX FIFO: Asserts when the TX FIFO is filled above TXFIFO_THR.
// De-asserts when the TX FIFO is below TXFIFO_THR.
halSpiWriteReg(CCxxx0_IOCFG2, 0x02);
SETUP_GDO2_INT(EDGE, LOW); // Enables external interrupt on falling edge
SETUP_GDO0_INT(EDGE, LOW);
}
_nop_(); // If this instruction is removed, IE0 might not be cleared
INT_SETFLAG(INUM_EXTERNAL0, INT_CLR); // Clears the interrupt flag
INT_SETFLAG(INUM_EXTERNAL1, INT_CLR); // Clears the interrupt flag
ENABLE_GLOBAL_INT(INT_ON);
}
break;
//----------------------------------------------------------------------------------------
case TX_START:
//----------------------------------------------------------------------------------------
// Create data packet
createDataPacket();
txData.pktFormat = INFINITE;
halWait(25000); // Delay to allow for the LCD display to be updated for every packet
txData.bytesLeft = menuData.packetLength + 2;
fixedPacketLength = txData.bytesLeft % (MAX_VARIABLE_LENGTH + 1);
halSpiWriteBurstReg(CCxxx0_TXFIFO, txBuffer, FIFO_SIZE); // Fill up the TX FIFO
halSpiStrobe(CCxxx0_STX);
txData.bytesLeft -= FIFO_SIZE;
txData.pBufferIndex = txBuffer + FIFO_SIZE;
txData.iterations = (txData.bytesLeft / AVAILABLE_BYTES_IN_TX_FIFO);
halSpiWriteReg(CCxxx0_PKTLEN, fixedPacketLength);
// Enable external interrupt 1 (the TX FIFO will need to be re-filled in this ISR)
ENABLE_GLOBAL_INT(INT_OFF);
INT_ENABLE(INUM_EXTERNAL1, INT_ON);
INT_SETFLAG(INUM_EXTERNAL1, INT_CLR);
ENABLE_GLOBAL_INT(INT_ON);
state = TX_WAIT;
//----------------------------------------------------------------------------------------
case TX_WAIT:
//----------------------------------------------------------------------------------------
if (txData.packetSentFlag) {
txData.packetSentFlag = FALSE;
intToAscii(++txData.packetsSent);
ebLcdUpdate("Sent:", asciiString);
if (txData.packetsSent < menuData.numberOfPackets)
state = TX_START;
else {
txData.packetsSent = 0;
state = SETUP;
}
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -