Exemplo n.º 1
0
/**
 * Read data from the RX fifo
 *
 * @param data
 * Pointer to the array in which to store the data.
 *
 * @param len
 * Pointer to variable storing the data length.
 *
 * @param pipe
 * Pointer to the pipe on which the data was received. Can be 0.
 *
 * @return
 * 1: Read OK, more data to read.
 * 0: Read OK
 * -1: No RX data
 * -2: Wrong length read. Something is likely wrong.
 */
int rfhelp_read_rx_data(char *data, int *len, int *pipe) {
	int retval = -1;

	chMtxLock(&rf_mutex);

	int s = rf_status();
	int pipe_n = NRF_STATUS_GET_RX_P_NO(s);

	if (pipe_n != 7) {
		*len = rf_get_payload_width();
		if (pipe) {
			*pipe = pipe_n;
		}
		if (*len <= 32 && *len >= 0) {
			rf_read_rx_payload(data, *len);
			rf_clear_rx_irq();

			s = rf_status();
			if (NRF_STATUS_GET_RX_P_NO(s) == 7) {
				retval = 0;
			} else {
				retval = 1;
			}
		} else {
			*len = 0;
			retval = -2;
		}
	}

	chMtxUnlock();

	return retval;
}
Exemplo n.º 2
0
/* Radio "interrupt" routine.
 * (but it is only manually called) */
static void nrf_irq()
{
  uint8_t status=rf_get_status();

  // Transmission success
  if(rf_is_tx_ds_active(status))  send_success = true; // Data has been sent
  
  // Transmission failed (maximum re-transmits)
  if(rf_is_max_rt_active(status)){
      rf_flush_tx();
      send_success = false;
  }

  // Data received 
  if(rf_is_rx_dr_active(status)){
      rf_read_rx_payload(rcvd_buf,PAYLOAD_SIZE,NULL); //can be only one payload from host ack
      packet_received = true;
  }
}