예제 #1
0
int cc1101_read(struct cc1101_dev_s * dev, uint8_t * buf, size_t size)
{
  ASSERT(dev);

  if (buf==NULL)
    {
      if (size==0)
        {
          return 64;
        }

      /* else received packet size */

      return 0;
    }

  if (cc1101_interrupt == 0)
    {
      return 0;
    }

  int status = cc1101_strobe(dev, CC1101_SNOP | CC1101_READ_SINGLE);

  if (status & CC1101_STATUS_FIFO_BYTES_AVAILABLE_BM &&
      (status & CC1101_STATE_MASK) == CC1101_STATE_IDLE)
    {
      uint8_t nbytes;

      cc1101_access(dev, CC1101_RXFIFO, &nbytes, 1);

      nbytes += 2;    /* RSSI and LQI */

      cc1101_access(dev, CC1101_RXFIFO, buf, (nbytes > size) ? size : nbytes);

      /* Flush remaining bytes, if there is no room to receive
       * or if there is a BAD CRC
       */

      if (nbytes > size || (nbytes <= size && !(buf[nbytes-1]&0x80)))
        {
          printf("Flushing RX FIFO\n");
          cc1101_strobe(dev, CC1101_SFRX);
        }

      return nbytes;
    }

  return 0;
}
예제 #2
0
int cc1101_receive(struct cc1101_dev_s * dev)
{
  ASSERT(dev);

  /* \todo Wait for IDLE before going into another state? */

  cc1101_interrupt = 0;

  cc1101_strobe(dev, CC1101_SRX | CC1101_READ_SINGLE);

  return 0;
}
예제 #3
0
파일: cc1101.c 프로젝트: CNCBASHER/Firmware
int cc1101_send(struct cc1101_dev_s * dev)
{
    ASSERT(dev);
    
    if (dev->flags & FLAGS_RXONLY) return -EPERM;
    
    cc1101_interrupt = 0;
    
    cc1101_strobe(dev, CC1101_STX);
    
    /* wait until send, going to IDLE */
    
    while( cc1101_interrupt == 0 );

    return 0;
}
예제 #4
0
int cc1101_idle(struct cc1101_dev_s * dev)
{
  ASSERT(dev);
  cc1101_strobe(dev, CC1101_SIDLE);
  return 0;
}
예제 #5
0
int cc1101_reset(struct cc1101_dev_s * dev)
{
    cc1101_strobe(dev, CC1101_SRES);
    return OK;
}
예제 #6
0
파일: main.c 프로젝트: elirentz/raspCC1101
int main(int argc, char * argv[])
{
	uint8_t rx[64];
	char buff[256];
	uint8_t length;
	uint8_t address;
	uint8_t status;
	int i;
	
	rpi_gpio_init();
	cc1101_init();
	status = cc1101_read_status();
	if (status != 0x0F)
	{
		cc1101_strobe(CC1101_STROBE_SIDLE, CC1101_WRITE_SINGLE);
	}
	printf("status ok\n\r");
	if(argc > 1)
	{
		printf("argv: %s\n\r", argv[1]);
		if(!strcmp(argv[1], "-w"))
		{
			if(strlen(argv[2]) == 2)
			{
				strcpy(buff, argv[2]);
			} else {
				printf("Adress too short\n\r");
				return 0;
			}
			// translate from ascii hex value to raw value
			for(i=0;i<2;i++)
			{
				if(buff[i] > 0x40 && buff[i] < 0x47)
				{
					address += (buff[i] - 55)<<((1-i)*4);
				}
				else if (buff[i] > 0x2F && buff[i] < 0x3A)
				{
					address += (buff[i]-0x30)<<((1-i)*4); //shift
				}
				else
				{
					printf("Not a hex number. %.02X\n\r", buff[i]);
					return 0;
				}
			}
			printf("Address: 0x%.02X\n\r", address);
			strcpy(buff, argv[3]);
			length = strlen(buff) + 1;
			printf("Length: %d\n\r", length);
			cc1101_send_msg(length, address, buff);
			cc1101_tx_end_wait();
		} else if (!strcmp(argv[1], "-r")) {
			cc1101_start_rx();
			printf("Rx mode started. Waiting...\n\r");
			while(length == 0)
			{
				do
				{
				}while(!READ_GD02);
				cc1101_rd_burst(CC1101_STROBE_SFTX, &length, 1); //read byte count RX_FIFO
			}
			cc1101_rd_burst(CC1101_RX_FIFO, rx,length);
			rx[length] = '\0';
			printf("Received Message:\n\r%s\n\r", rx);
		}

	} else {
		printf("Not enough arguments. Try again.\n\r");
	}
}