예제 #1
0
uint8_t ccRxPacket(uint8_t *data) {

	uint8_t count= 0;	// length byte
	uint8_t status;		// RX status
	uint8_t nrcvd= 0;	// bytes received
	uint8_t n;

	while(1) {

		status= ccGetRxStatus();

		switch(status & CC1100_STATUS_STATE_BM) {
			case CC1100_STATE_IDLE:
			case CC1100_STATE_RX:
				// If there's anything in the RX FIFO....
				if((n= (status & CC1100_STATUS_FIFO_BYTES_AVAILABLE_BM))) {
					if(!count) {
		                	    // Make sure that the RX FIFO is not emptied
	                		    // (see the CC1100 or 2500 Errata Note)
        	        		    if(n>1) {
                			    	count= ccReadReg(CC1100_RXFIFO);
                			    	n--;
                			    } else {
	                		    	break;
        	        		    }
                			}
	   			        // Make sure that the RX FIFO is not emptied
        	        		// (see the CC1100 or 2500 Errata Note)
	                		if((n>1) && (n!= count-nrcvd)) {
        	        			// Leave one byte in FIFO
						n--;
	                		} else if((n<=1) && (n!= count-nrcvd)) {
		                	    	// Need more data in FIFO before reading additional bytes
                	    			break;
		                	}
			                // Read from RX FIFO and store the data in rxBuffer
                			ccReadFifo(&(data[nrcvd]), n);
                			nrcvd+= n;
					// Done?
					if(!count && (nrcvd==count)) return count;
					break;
                		} else if(!count) return 0; // nothing to receive
			case CC1100_STATE_RX_OVERFLOW:
				ccSpiStrobe(CC1100_SFRX); // clear overflow
				return 0;
		}
	}

}
예제 #2
0
uint16_t CC1200::registerConfig(void)
{
	byte writeByte;
	byte verifyVal;
	uint16_t errors = 0;
	// Reset radio
	reset();
	byte registerCount = (sizeof(settings) / sizeof(registerSettings));

	// Write registers to radio
	for (uint16_t i = 0; i < registerCount; i++)
	{
		writeByte = settings[i].data;
		ccWriteReg(settings[i].addr, &writeByte, 1);
		ccReadReg(settings[i].addr, &verifyVal, 1);

		if (verifyVal != writeByte)
		{
			errors++;

			if (Serial)
			{
				Serial.print("Error writing to address 0x");
				Serial.print(settings[i].addr, HEX);
				Serial.print(". Value set as 0x");
				Serial.print(writeByte, HEX);
				Serial.print(" but read as 0x");
				Serial.println(verifyVal, HEX);
			}
		}
	}

	if (Serial)
	{
		Serial.print("Wrote ");
		Serial.print(registerCount - errors);
		Serial.print(" of ");
		Serial.print(registerCount);
		Serial.println(" register values.");
	}

	return errors;
}
예제 #3
0
boolean CC1200::transmit(byte *txBuffer, byte start, byte length)
{
	if (asleep == true)
	{
		return false;
	}

	//check FIFO and radio state here
	byte txBytesUsed = 0;
	// Read number of bytes in TX FIFO
	ccReadReg(REG_NUM_TXBYTES, &txBytesUsed, 1);

	if (txBytesUsed > 0)
	{
		// Make sure that the radio is in IDLE state before flushing the FIFO
		setState(CC1200_IDLE);
		SendStrobe(SFTX); //flush buffer if needed
	}

	setState(CC1200_FSTX); //spin up frequency synthesizer
	byte data[length];

	for (int i = 0; i < length; i++)
	{
		data[i] = txBuffer[i + start]; //TODO: alter fifo access functions to allow passing txBuffer directly to read or write from a specific chunk of it
	}

	ccWriteTxFifo(data, length); //TODO: do error checking for underflow, CCA, etc.
#ifdef DEBUG1
	Serial.print("Writing ");
	Serial.print(length);
	Serial.println(" bytes: ");
	printBuffer(txBuffer, length);
#endif
	setState(CC1200_TX); //spin up frequency synthesizer
	return true;
}