bool CC2500_PacketCheck() { u8 i; u32 *pu32 = NULL; RSSI = CC2500_ReadStatus(CCxxx0_RSSI); LQI = CC2500_ReadStatus(CCxxx0_LQI); CC2500_ReceivePacket(gPacketbuf); ReceiveTime = Timer2Counter; CC2500_SetRxd(); pu32 = (u32*) &gPacketbuf[1]; CRC_ResetDR(); if (CRC_CalcBlockCRC(pu32, CRC_LENGTH - 1) == pu32[CRC_LENGTH - 1]) { if (NodeTimestamp[gPacketbuf[SRC_NUM]] != pu32[CRC_LENGTH - 2]) { NodeTimestamp[gPacketbuf[SRC_NUM]] = pu32[CRC_LENGTH - 2]; return TRUE; } else { return FALSE; } } else { return FALSE; } }
// receive a paket data form cc2500 u8 CC2500_ReceivePacket(u8 *rxBuffer) { u8 status; u8 LEN=0,i=0; status =CC2500_ReadStatus(CCxxx0_RXBYTES); //RX FIFO 等于0 CRC校验失败 如果大于0CRC校验OK数据能读出 if((status & 0x7F)==0x00) { status = CC2500_ReadStatus(CCxxx0_MARCSTATE); if((status!=0x0D)&&(status!=0x08)) //0x0D为RX状态 { CC2500_SetRxd(); //激活(接收或传送) } return 0; } //LEN = CC2500_ReadReg(CCxxx0_RXFIFO_one); LEN = PACKET_LEN; //采用定长模式 if(LEN > 0) { if(LEN<=RFTXDBUFFSIZE) { CC2500_Select(); CC2500_WriteByte(CCxxx0_RXFIFO_Muti); for(i=0;i<LEN;i++) { rxBuffer[i] = CC2500_ReadByte(); } CC2500_NoSelect(); CC2500_SetRxd(); return LEN;//(status & CRC_OK); } else { CC2500_Select(); CC2500_WriteByte(CCxxx0_RXFIFO_Muti); for(i=0;i<LEN;i++) { rxBuffer[i] = CC2500_ReadByte(); } CC2500_NoSelect(); CC2500_SetRxd(); return 0; } } else { CC2500_SetRxd(); return 0; } }
// rf communication void CC2500_Process(void) { u8 i,j; #define GDO0_ #ifdef GDO0_ if(!GDO0_IN()) { return; } while(GDO0_IN()); #else if(!(CC2500_ReadStatus(0x38)&0x01)) { return; } while((CC2500_ReadStatus(0x38)&0x01)); #endif Debug("Have a packet!\n\r"); i = CC2500_ReadRSSIValue(); for(i=0;i<sizeof(bTempBuf);i++) bTempBuf[i]=0; CC2500_ReceivePacket(bTempBuf); Debug("Receive over!\n\r"); CC2500_SetRxd(); // CC2500_REnter_WOR(); #if 1//def RF_DEBUG_ Debug("\n\rRX Data:"); for(j=0;j<sizeof(bTempBuf);j++) { Debug("0x%x ",bTempBuf[j]); } Debug("\n\r"); #endif }
//read RSSI value u8 CC2500_ReadRSSIValue(void) { return(CC2500_ReadStatus(0x34)); }