📄 infinitelink.c
字号:
//----------------------------------------------------------------------------------------
case RX_START:
//----------------------------------------------------------------------------------------
halSpiStrobe(CCxxx0_SRX);
state = RX_WAIT;
//----------------------------------------------------------------------------------------
case RX_WAIT:
//----------------------------------------------------------------------------------------
if (rxData.packetReceivedFlag) {
rxData.packetReceivedFlag = FALSE;
rxData.pBufferIndex = rxBuffer;
if (rxData.crcOK) {
intToAscii(++rxData.packetsReceived);
ebLcdUpdate("Received:", asciiString);
}
state = RX_START;
// Configure external interrupt 0 to give an interrupt on rising edge (sync received)
ENABLE_GLOBAL_INT(INT_OFF);
SETUP_GDO0_INT(EDGE, HIGH);
_nop_(); // If this instruction is removed, IE0 might not be cleared
INT_SETFLAG(INUM_EXTERNAL0, INT_CLR);
ENABLE_GLOBAL_INT(INT_ON);
}
break;
//----------------------------------------------------------------------------------------
default:
//----------------------------------------------------------------------------------------
break;
}
}
}
//-------------------------------------------------------------------------------------------------------
// void EXTERNAL1_ISR(void)
//
// DESCRIPTION:
// In TX mode there will be an interrupt when the number of bytes in the TX FIFO goes below the
// threshold (less than 5 bytes left in the TX FIFO) and in RX mode there will be an interrupt when
// there are 60 bytes in the RX FIFO.
// For better understanding on how this interrupt work, please see the
// CC1100/CC1150DK & CC2500/CC2550DK Development Kit Examples and Libraries User Manual
//-------------------------------------------------------------------------------------------------------
void EXTERNAL1_ISR(void) interrupt INUM_EXTERNAL1 {
//----------------------- TX MODE -----------------------
if (menuData.radioMode == TX) {
if (txData.writeRemainingDataFlag) { // Less than 60 bytes to write to the TX FIFO
halSpiWriteBurstReg(CCxxx0_TXFIFO, txData.pBufferIndex, txData.bytesLeft);
INT_ENABLE(INUM_EXTERNAL1, INT_OFF);
} else {
halSpiWriteBurstReg(CCxxx0_TXFIFO, txData.pBufferIndex, AVAILABLE_BYTES_IN_TX_FIFO);
// Change to fixed packet length mode when there is less than 256 bytes left to transmit
if ((txData.bytesLeft < (MAX_VARIABLE_LENGTH + 1 - BYTES_IN_TX_FIFO)) && (txData.pktFormat == INFINITE)) {
halSpiWriteReg(CCxxx0_PKTCTRL0, FIXED_PACKET_LENGTH);
txData.pktFormat = FIXED;
}
txData.pBufferIndex += AVAILABLE_BYTES_IN_TX_FIFO;
txData.bytesLeft -= AVAILABLE_BYTES_IN_TX_FIFO;
if (!(--txData.iterations))
txData.writeRemainingDataFlag = TRUE;
}
//-------------------------------------------------------
//----------------------- RX MODE -----------------------
} else {
// Change to fixed packet length mode when there is less than 256 bytes left to receive
if (((rxData.bytesLeft - BYTES_IN_RX_FIFO) < (MAX_VARIABLE_LENGTH + 1)) && (rxData.pktFormat == INFINITE)) {
halSpiWriteReg(CCxxx0_PKTCTRL0, FIXED_PACKET_LENGTH);
rxData.pktFormat = FIXED;
}
// Do not empty the FIFO (See the CC1100 or 2500 Errata Note)
halSpiReadBurstReg(CCxxx0_RXFIFO, rxData.pBufferIndex, (BYTES_IN_RX_FIFO - 1));
rxData.bytesLeft -= (BYTES_IN_RX_FIFO - 1);
rxData.pBufferIndex += (BYTES_IN_RX_FIFO - 1);
}
//-------------------------------------------------------
IE1 = 0; // Clear the interrupt flag in case the interrupt flag were set while in the ISR
}// EXTERNAL_ISR
//-------------------------------------------------------------------------------------------------------
// void EXTERNAL0_ISR(void)
//
// DESCRIPTION:
// In TX mode, this ISR will run when a packet has been sent. In RX mode it will run both when sync
// is received (rising edge) and when the whole packet is received (falling edge).
// For better understanding on how this interrupt work, please see the
// CC1100/CC1150DK & CC2500/CC2550DK Development Kit Examples and Libraries User Manual
//-------------------------------------------------------------------------------------------------------
void EXTERNAL0_ISR(void) interrupt INUM_EXTERNAL0 {
//----------------------- TX MODE -----------------------
if (menuData.radioMode == TX) {
txData.writeRemainingDataFlag = FALSE;
txData.packetSentFlag = TRUE;
halSpiWriteReg(CCxxx0_PKTCTRL0, INFINITE_PACKET_LENGTH);
//-------------------------------------------------------
//----------------------- RX MODE -----------------------
} else {
if (rxData.syncOrEndOfPacket == SYNC) {
// After the sync word is received one needs to wait some time before there will be any data
// in the FIFO.In addition, the FIFO should not be emptied
// (See the CC1100 or 2500 Errata Note) before the whole packet has been received.
halWait(320); // Allow for 3 bytes to be put in the FIFO (3*8*(1/76800)) = 312.5 us
rxData.lengthByte = halSpiReadReg(CCxxx0_RXFIFO) << 8;
rxData.lengthByte |= halSpiReadReg(CCxxx0_RXFIFO);
if ((rxData.lengthByte > MAX_VARIABLE_LENGTH) && (rxData.lengthByte <= menuTable[PACKET_LENGTH].max)) {
rxData.bytesLeft = rxData.lengthByte + 2;
fixedPacketLength = rxData.bytesLeft % (MAX_VARIABLE_LENGTH + 1);
halSpiWriteReg(CCxxx0_PKTLEN, fixedPacketLength);
rxData.pBufferIndex += 2;
rxData.syncOrEndOfPacket = END_OF_PACKET;
SETUP_GDO0_INT(EDGE, LOW); // Enables external interrupt on falling edge (packet received)
_nop_(); // If this instruction is removed, IE0 might not be cleared
INT_SETFLAG(INUM_EXTERNAL0, INT_CLR);
} else {
halSpiStrobe(CCxxx0_SIDLE);
halSpiStrobe(CCxxx0_SFRX);
rxData.syncOrEndOfPacket = SYNC;
rxData.pktFormat = INFINITE;
halSpiWriteReg(CCxxx0_PKTCTRL0, INFINITE_PACKET_LENGTH);
// Configure external interrupt 0 to give an interrupt on rising edge (sync received)
ENABLE_GLOBAL_INT(INT_OFF);
SETUP_GDO0_INT(EDGE, HIGH);
_nop_(); // If this instruction is removed, IE0 might not be cleared
INT_SETFLAG(INUM_EXTERNAL0, INT_CLR);
ENABLE_GLOBAL_INT(INT_ON);
state = RX_START;
}
} else { // End of Packet
halSpiReadBurstReg(CCxxx0_RXFIFO, rxData.pBufferIndex, rxData.bytesLeft);
rxBuffer[0] = rxData.lengthByte >> 8;
rxBuffer[1] = rxData.lengthByte;
rxData.syncOrEndOfPacket = SYNC;
rxData.packetReceivedFlag = TRUE;
rxData.crcOK = ((rxBuffer[rxData.lengthByte + 3]) & CRC_OK);
rxData.pktFormat = INFINITE;
halSpiWriteReg(CCxxx0_PKTCTRL0, INFINITE_PACKET_LENGTH);
}
//-------------------------------------------------------
}
}// EXTERNAL_ISR
//-------------------------------------------------------------------------------------------------------
// void intToAscii(UINT16 value)
//
// DESCRIPTION:
// Takes a 16 bits integer as input and converts it to ascii. The result is put in a global
// variable (UINT8 xdata asciiString[6])
//
// ARGUMENTS:
// UINT16 value
// The value to be converted
//-------------------------------------------------------------------------------------------------------
void intToAscii(UINT16 value) {
UINT8 i;
UINT8 j = 0;
UINT8 digit_start = 0;
UINT16 digit = 0;
UINT16 denom = 10000;
if (value == 0) {
asciiString[0] = '0';
asciiString[1] = NULL;
} else {
for(i = 5; i > 0; i--) {
digit = value / denom;
if((digit_start == 1) || (digit != 0)) {
digit_start = 1;
value %= denom;
asciiString[j++] = (digit + '0');
}
denom /= 10;
}
asciiString[j++] = NULL;
}
}// intToAscii
//-------------------------------------------------------------------------------------------------------
// void createDataPacket(void)
//
// DESCRIPTION:
// This function is called before a packet is going to be transmitted.
// Packet format (length byte >= 255):
//
// |----------------------------------------------------------------------------------------------------
// | | | | | | | |
// | Length field | Length field | Random Data | Random Data |............| Random Data | Random Data |
// | MSB | LSB | | | | | |
// |----------------------------------------------------------------------------------------------------
// ^ ^ ^ ^
// | | | |
// txBuffer[0] txBuffer[1] txBuffer[2] txBuffer[menuData.packetLength]
//-------------------------------------------------------------------------------------------------------
void createDataPacket(void) {
UINT16 xdata i;
txBuffer[0] = menuData.packetLength >> 8;
txBuffer[1] = menuData.packetLength;;
for (i = 2; i <= (menuData.packetLength + 1); i++)
txBuffer[i] = rand();
} //createDataPacket
/******************************************************************************************************
* Revision history: *
*
* $Log: InfiniteLink.c,v $
* Revision 1.3 2007/11/23 09:24:03 a0190596
* Removed halSpiWriteReg(CCxxx0_FIFOTHR, 0x0E);
* since this register is included in the halRfWriteRfSettings(&rfSettings) function.
*
* Revision 1.2 2006/05/03 12:03:25 a0190596
* no message
*
* Revision 1.1 2006/04/25 15:00:38 a0190596
* Initial version in CVS.
*
*
*
*
******************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -