static uint8_t receive_packet_variable(uint8_t *rxBuffer, uint8_t length) { uint8_t status[2]; uint8_t packetLength = 0; /* Any bytes available in RX FIFO? */ if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { // Read length byte (first byte in RX FIFO) cc110x_read_fifo((char*) &packetLength, 1); // Read data from RX FIFO and store in rxBuffer if (packetLength <= length) { // Put length byte at first position in RX Buffer rxBuffer[0] = packetLength; // Read the rest of the packet //cc110x_readburst_reg(CC1100_RXFIFO, (char*)rxBuffer+1, packetLength); cc110x_read_fifo((char*) rxBuffer + 1, packetLength); // Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) cc110x_readburst_reg(CC1100_RXFIFO, (char*)status, 2); // Store RSSI value of packet rflags._RSSI = status[I_RSSI]; // MSB of LQI is the CRC_OK bit rflags.CRC = (status[I_LQI] & CRC_OK) >> 7; if (!rflags.CRC) { cc110x_statistic.packets_in_crc_fail++; } // Bit 0-6 of LQI indicates the link quality (LQI) rflags._LQI = status[I_LQI] & LQI_EST; return rflags.CRC; }
/*---------------------------------------------------------------------------*/ int16_t cc110x_set_channel(uint8_t channr) { uint8_t state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE; if((state != 1) && (channr > MAX_CHANNR)) { return -1; } write_register(CC1100_CHANNR, channr * 10); radio_channel = channr; return radio_channel; }
static uint8_t receive_packet_variable(uint8_t *rxBuffer, radio_packet_length_t length) { uint8_t status[2]; /* Any bytes available in RX FIFO? */ if ((cc110x_read_status(CC1100_RXBYTES) & BYTES_IN_RXFIFO)) { uint8_t packetLength = 0; /* Read length byte (first byte in RX FIFO) */ packetLength = cc110x_read_reg(CC1100_RXFIFO); /* Read data from RX FIFO and store in rxBuffer */ if (packetLength <= length) { uint8_t crc_ok = 0; /* Put length byte at first position in RX Buffer */ rxBuffer[0] = packetLength; /* Read the rest of the packet */ cc110x_readburst_reg(CC1100_RXFIFO, (char *) rxBuffer + 1, packetLength); /* Read the 2 appended status bytes (status[0] = RSSI, status[1] = LQI) */ cc110x_readburst_reg(CC1100_RXFIFO, (char *)status, 2); /* Store RSSI value of packet */ rflags._RSSI = status[I_RSSI]; /* MSB of LQI is the CRC_OK bit */ crc_ok = (status[I_LQI] & CRC_OK) >> 7; if (!crc_ok) { cc110x_statistic.packets_in_crc_fail++; } /* Bit 0-6 of LQI indicates the link quality (LQI) */ rflags._LQI = status[I_LQI] & LQI_EST; return crc_ok; }
char *cc110x_get_marc_state(void) { uint8_t state; /* Save old radio state */ uint8_t old_state = radio_state; /* Read content of status register */ state = cc110x_read_status(CC1100_MARCSTATE) & MARC_STATE; /* Make sure in IDLE state. * Only goes to IDLE if state was RX/WOR */ cc110x_wakeup_from_rx(); /* Have to put radio back to WOR/RX if old radio state * was WOR/RX, otherwise no action is necessary */ if(old_state == RADIO_WOR || old_state == RADIO_RX) { cc110x_switch_to_rx(); } switch(state) { /* Note: it is not possible to read back the SLEEP or XOFF state numbers * because setting CSn low will make the chip enter the IDLE mode from the * SLEEP (0) or XOFF (2) states. */ case 1: return "IDLE"; case 3: case 4: case 5: return "MANCAL"; case 6: case 7: return "FS_WAKEUP"; case 8: case 12: return "CALIBRATE"; case 9: case 10: case 11: return "SETTLING"; case 13: case 14: case 15: return "RX"; case 16: return "TXRX_SETTLING"; case 17: return "RXFIFO_OVERFLOW"; case 18: return "FSTXON"; case 19: case 20: return "TX"; case 21: return "RXTX_SETTLING"; case 22: return "TXFIFO_UNDERFLOW"; default: return "UNKNOWN"; } }