//----------------------------------------------------------------------------- // char RFReceivePacket(char *rxBuffer, char *length) // // DESCRIPTION: // Receives a packet of variable length (first byte in the packet must be the // length byte). The packet length should not exceed the RXFIFO size. To use // this function, APPEND_STATUS in the PKTCTRL1 register must be enabled. It // is assumed that the function is called after it is known that a packet has // been received; for example, in response to GDO0 going low when it is // configured to output packet reception status. // // The RXBYTES register is first read to ensure there are bytes in the FIFO. // This is done because the GDO signal will go high even if the FIFO is flushed // due to address filtering, CRC filtering, or packet length filtering. // // ARGUMENTS: // char *rxBuffer // Pointer to the buffer where the incoming data should be stored // char *length // Pointer to a variable containing the size of the buffer where the // incoming data should be stored. After this function returns, that // variable holds the packet length. // // RETURN VALUE: // char // 0x80: CRC OK // 0x00: CRC NOT OK (or no pkt was put in the RXFIFO due to filtering) //----------------------------------------------------------------------------- char RFReceivePacket(char *rxBuffer, char *length, char *retStatus) { char status[2]; char pktLen; if ((TI_CC_SPIReadStatus(TI_CCxxx0_RXBYTES) & TI_CCxxx0_NUM_RXBYTES)) { pktLen = TI_CC_SPIReadReg(TI_CCxxx0_RXFIFO); // Read length byte if (pktLen <= *length) // If pktLen size <= rxBuffer { TI_CC_SPIReadBurstReg(TI_CCxxx0_RXFIFO, rxBuffer, pktLen); // Pull data *length = pktLen; // Return the actual size TI_CC_SPIReadBurstReg(TI_CCxxx0_RXFIFO, status, 2); // Read appended status bytes if (retStatus){ retStatus[0]=status[0]; retStatus[1]=status[1]; } return (char)(status[TI_CCxxx0_LQI_RX]&TI_CCxxx0_CRC_OK); } // Return CRC_OK bit else { *length = pktLen; // Return the large size TI_CC_SPIStrobe(TI_CCxxx0_SFRX); // Flush RXFIFO return 0; // Error } } else return 0; // Error }
//----------------------------------------------------------------------------- // char RFReceivePacket(char *rxBuffer, char *length) // // DESCRIPTION: // Receives a packet of variable length (first byte in the packet must be the // length byte). The packet length should not exceed the RXFIFO size. To use // this function, APPEND_STATUS in the PKTCTRL1 register must be enabled. It // is assumed that the function is called after it is known that a packet has // been received; for example, in response to GDO0 going low when it is // configured to output packet reception status. // // The RXBYTES register is first read to ensure there are bytes in the FIFO. // This is done because the GDO signal will go high even if the FIFO is flushed // due to address filtering, CRC filtering, or packet length filtering. // // ARGUMENTS: // char *rxBuffer // Pointer to the buffer where the incoming data should be stored // char *length // Pointer to location where length will be returned // // RETURN VALUE: // char // 0x80: CRC OK // 0x00: CRC NOT OK (or no pkt was put in the RXFIFO due to filtering) //----------------------------------------------------------------------------- char RFReceivePacket(char *rxBuffer, char *length) { char status[2]; char pktLen; if ((TI_CC_SPIReadStatus(TI_CCxxx0_RXBYTES) & TI_CCxxx0_NUM_RXBYTES)) { // Use the appropriate library function to read the first byte in the // RX FIFO, which is the length of the packet (the total remaining bytes // in this packet after reading this byte). // Hint: how many bytes are being retrieved? One or multiple? pktLen = TI_CC_SPIReadReg(TI_CCxxx0_RXFIFO); // Use the appropriate library function to read the rest of the packet into // rxBuffer (i.e., read pktLen bytes out of the FIFO) // Hint: how many bytes are being retrieved? One or multiple? TI_CC_SPIReadBurstReg(TI_CCxxx0_RXFIFO, rxBuffer, pktLen); // Pull data *length = pktLen; // Return the actual size // Our initialization code configured this CC1100 to append two status // bytes to the end of the received packets. These bytes are still in the // FIFO. Use the appropriate library function to read these two bytes into // the status array TI_CC_SPIReadBurstReg(TI_CCxxx0_RXFIFO, status, 2); return (char)(status[TI_CCxxx0_LQI_RX]&TI_CCxxx0_CRC_OK); } else return 0; // Error }
//----------------------------------------------------------------------------- char RFReceivePacket(char *rxBuffer, char *length) { char pktLen; if ((TI_CC_SPIReadStatus(TI_CCxxx0_RXBYTES) & TI_CCxxx0_NUM_RXBYTES)) { pktLen = TI_CC_SPIReadReg(TI_CCxxx0_RXFIFO); // Quantes dades hi ha? #ifdef LSMAKER_BASE // LS_USB_printf("\r\nLenR %d LenE %d\r\n", pktLen, *length); #endif if ((pktLen <= *length) && (pktLen > 0)) { // Suficients= TI_CC_SPIReadBurstReg(TI_CCxxx0_RXFIFO, rxBuffer, pktLen+2); // Llegeix les dades + 2 d'estat *length = pktLen; // Returna el tamany real RssiAct = rxBuffer[LengthDATA]; // El primer byte indica el RSSI LQIAct = rxBuffer[LengthDATA+TI_CCxxx0_LQI_RX] & 0x7f; // I el segon l'indicador de qualitat de l'enllaç ModeRecepcio(); return (char)(rxBuffer[LengthDATA+TI_CCxxx0_LQI_RX]&TI_CCxxx0_CRC_OK); // Return CRC_OK bit } else { *length = pktLen; // Return the large size TI_CC_SPIStrobe(TI_CCxxx0_SFRX); // Flush RXFIFO IoWait(2); ModeRecepcio(); return 0; // Error } } else { ModeRecepcio(); return 0; // Error } return 0; }
//----------------------------------------------------------------------------- // char RFReceivePacket(char *rxBuffer, char *length) // // DESCRIPTION: // Receives a packet of variable length (first byte in the packet must be the // length byte). The packet length should not exceed the RXFIFO size. To use // this function, APPEND_STATUS in the PKTCTRL1 register must be enabled. It // is assumed that the function is called after it is known that a packet has // been received; for example, in response to GDO0 going low when it is // configured to output packet reception status. // // The RXBYTES register is first read to ensure there are bytes in the FIFO. // This is done because the GDO signal will go high even if the FIFO is flushed // due to address filtering, CRC filtering, or packet length filtering. // // ARGUMENTS: // char *rxBuffer // Pointer to the buffer where the incoming data should be stored // char *length // Pointer to a variable containing the size of the buffer where the // incoming data should be stored. After this function returns, that // variable holds the packet length. // // RETURN VALUE: // char // 0x80: CRC OK // 0x00: CRC NOT OK (or no pkt was put in the RXFIFO due to filtering) //----------------------------------------------------------------------------- char RFReceivePacket(char *rxBuffer, char *length) { char status[2]; char pktLen; char rxBytesVerify; char rxBytes; //mrfi code rxBytesVerify = TI_CC_SPIReadReg( TI_CCxxx0_RXBYTES ); do { rxBytes = rxBytesVerify; rxBytesVerify = TI_CC_SPIReadReg( TI_CCxxx0_RXBYTES ); } while (rxBytes != rxBytesVerify); if (rxBytes ==0) return 0; //end of mrfi code //if ((TI_CC_SPIReadStatus(TI_CCxxx0_RXBYTES) & TI_CCxxx0_NUM_RXBYTES)) { pktLen = TI_CC_SPIReadReg(TI_CCxxx0_RXFIFO); // Read length byte if (pktLen > *length) // If pktLen size <= rxBuffer { *length = pktLen; // Return the large size TI_CC_SPIStrobe(TI_CCxxx0_SIDLE); // set IDLE - MRFI code TI_CC_SPIStrobe(TI_CCxxx0_SFRX); // Flush RXFIFO TI_CC_SPIStrobe(TI_CCxxx0_SRX); // RX state - from MRFI return 0; // Error } else { TI_CC_SPIReadBurstReg(TI_CCxxx0_RXFIFO, rxBuffer, pktLen); // Pull data *length = pktLen; // Return the actual size TI_CC_SPIReadBurstReg(TI_CCxxx0_RXFIFO, status, 2); // Read appended status bytes return (char)(status[TI_CCxxx0_LQI_RX]&TI_CCxxx0_CRC_OK); } // Return CRC_OK bit } //else return 0; // Error }