Beispiel #1
0
int nrf_read_ack_pl(nrf_payload *payload)
{
     unsigned char i = 0;

     nrf_reg_buf status;
     nrf_read_reg(NRF_REG_FIFO_STATUS, &status);

     // if RX buffer is full, indicate no bytes where receifed, flush RX buffer
     if(nrf_get_reg_field(NRF_REG_FIFO_STATUS, NRF_REGF_FIFO_RX_FULL, &status) == 1) {
          nrf_spi_csl();
          nrf_spi_xfer_byte(NRF_CMD_FLUSH_RX);
          nrf_spi_csh();
          return NRF_ERR_RX_FULL;
     }

     nrf_spi_csl();
     nrf_spi_xfer_byte(NRF_CMD_RX);

     for(i = 0; i < payload->size; i++) {
          payload->data[i] = nrf_spi_xfer_byte(NRF_CMD_RREG);
     }

     nrf_spi_csh();

     return i;
}
Beispiel #2
0
int nrf_send(nrf_payload *payload)
{
     int i;

     nrf_reg_buf status;
     nrf_read_reg(NRF_REG_STATUS, &status);

     // if TX buffer is full, indicate no bytes where sent, flush TX buffer
     if(nrf_get_reg_field(NRF_REG_STATUS, NRF_REGF_TX_FULL, &status) == 1) {
          nrf_spi_csl();
          nrf_spi_xfer_byte(NRF_CMD_FLUSH_TX);
          nrf_spi_csh();
          return NRF_ERR_TX_FULL;
     }

     // send command
     nrf_spi_csl();
     nrf_spi_xfer_byte(NRF_CMD_TX);

     // send payload
     for(i = 0; i < payload->size; i++) {
          nrf_spi_xfer_byte(payload->data[i]);
     }

     nrf_spi_csh();

     return i;
}
Beispiel #3
0
int nrf_write_ack_pl(nrf_payload *payload, unsigned char pipe)
{
     int i;

     nrf_reg_buf status;
     nrf_read_reg(NRF_REG_STATUS, &status);

     // if TX buffer is full, indicate no bytes where sent, flush TX buffer
     if(nrf_get_reg_field(NRF_REG_STATUS, NRF_REGF_TX_FULL, &status) == 1) {
          nrf_spi_csl();
          nrf_spi_xfer_byte(NRF_CMD_FLUSH_TX);
          nrf_spi_csh();
          return NRF_ERR_TX_FULL;
     }

     nrf_spi_csl();
     nrf_spi_xfer_byte(NRF_CMD_WACKPL | (0b00000111 & pipe));

     for(i = 0; i < payload->size; i++) {
          nrf_spi_xfer_byte(payload->data[i]);
     }

     nrf_spi_csh();

     return i;
}
void nrf_dump_regs(nrf_regs *r) {
    int i;
    int j;

    chprintf((BaseSequentialStream *) &SD1, "\n\r** START nRF2401 Register DUMP **\n\r");

    nrf_reg_buf buf;

    for(i = 0; i < r->count; i++) {

        nrf_read_reg(i, &buf);

        if(r->data[i].size == 0) continue;

        chprintf((BaseSequentialStream *) &SD1, "%s: ", r->data[i].name);

        for(j = 0; j < buf.size; j++) {
            chprintf((BaseSequentialStream *) &SD1, " (%u) ", buf.data[j]);
        }

        chprintf((BaseSequentialStream *) &SD1,"\n\r - ");

        for(j = 0; j < r->data[i].fields->count; j++) {
            chprintf((BaseSequentialStream *) &SD1, "%u[%u]:%s=%u ", j,
                     r->data[i].fields->data[j].size,
                     r->data[i].fields->data[j].name,
                     nrf_get_reg_field(i, j, &buf));
        }

        chprintf((BaseSequentialStream *) &SD1,"\n\r - ");
    }
    chprintf((BaseSequentialStream *) &SD1,"** END **\n\r");
}
Beispiel #5
0
int nrf_send_blocking(nrf_payload *payload)
{
     int i;

     nrf_reg_buf status;
     nrf_read_reg(NRF_REG_STATUS, &status);

     // if TX buffer is full, indicate no bytes where sent, flush TX buffer
     if(nrf_get_reg_field(NRF_REG_STATUS, NRF_REGF_TX_FULL, &status) == 1) {
          nrf_spi_csl();
          nrf_spi_xfer_byte(NRF_CMD_FLUSH_TX);
          nrf_spi_csh();
          i =  NRF_ERR_TX_FULL;
     }

     // send command
     nrf_spi_csl();
     nrf_spi_xfer_byte(NRF_CMD_TX);

     // send payload
     for(i = 0; i < payload->size; i++) {
          nrf_spi_xfer_byte(payload->data[i]);
     }
     nrf_spi_csh();

     // wait until payload passed TX FIFO
     do {
          nrf_read_reg(NRF_REG_STATUS, &status);

          // If MAX_RT is reached, indicate no bytes where sent ...
          if(nrf_get_reg_field(NRF_REG_STATUS, NRF_REGF_MAX_RT, &status) == 1) {
               nrf_spi_csl();
               nrf_spi_xfer_byte(NRF_CMD_FLUSH_TX);
               nrf_spi_csh();
               i =  NRF_ERR_MAX_RT;
               break;
          }
     } while(nrf_get_reg_field(NRF_REG_STATUS, NRF_REGF_TX_DS , &status) != 1);

     // clear TX_DS/MAX_RT bits (by writing 1 or just writing back the status)
     nrf_write_reg(NRF_REG_STATUS, &status);

     return i;
}
Beispiel #6
0
int nrf_receive_blocking(nrf_payload *payload)
{
     unsigned char i = 0;

     nrf_reg_buf status;

     // wait until data arrives
     do {
          nrf_read_reg(NRF_REG_STATUS, &status);
     } while(nrf_get_reg_field(NRF_REG_STATUS, NRF_REGF_RX_DR, &status) != 1);

     // receive payload
     nrf_spi_csl();
     nrf_spi_xfer_byte(NRF_CMD_RX);

     for(i = 0; i < payload->size; i++) {
          payload->data[i] = nrf_spi_xfer_byte(NRF_CMD_RREG);
     }

     nrf_spi_csh();

     // write back status to clean RX_DR
     nrf_write_reg(NRF_REG_STATUS, &status);

     nrf_read_reg(NRF_REG_FIFO_STATUS, &status);

     // if RX buffer is full, indicate no bytes where receifed, flush RX buffer
     if(nrf_get_reg_field(NRF_REG_FIFO_STATUS, NRF_REGF_FIFO_RX_FULL, &status) == 1) {
          nrf_spi_csl();
          nrf_spi_xfer_byte(NRF_CMD_FLUSH_RX);
          nrf_spi_csh();
          return NRF_ERR_RX_FULL;
     }

     return i;
}
Beispiel #7
0
void nrf_dump_regs(nrf_regs *r) {

	int i;
	int j;

	cio_print("\n\r** START nRF2401 Register DUMP **\n\r");

	nrf_reg_buf buf;

	for(i = 0; i < r->count; i++) {

		nrf_read_reg(i, &buf);

		if(r->data[i].size == 0) continue;

		cio_printf("%s: ", r->data[i].name);

		for(j = 0; j < buf.size; j++) {
			cio_printb(buf.data[j], 8);
			cio_printf(" (%u) ", buf.data[j]);
		}

		cio_print("\n\r - ");

		for(j = 0; j < r->data[i].fields->count; j++) {
			cio_printf("%u[%u]:%s=%u ", j,
				r->data[i].fields->data[j].size,
				r->data[i].fields->data[j].name,
				nrf_get_reg_field(i, j, &buf));
		}

		cio_print("-\n\r");
	}

	cio_print("** END nRF2401 Register DUMP **\n\r");
}