Defines | Functions

hal/nrf24l01p/hal_nrf.c File Reference

Implementation of hal_nrf. More...

#include <stdint.h>
#include <stdbool.h>
#include "nordic_common.h"
#include "hal_nrf.h"

Go to the source code of this file.

Defines

#define SET_BIT(pos)   ((uint8_t) (1U<<( (uint8_t) (pos) )))
#define UINT8(t)   ((uint8_t) (t))
#define NRF_READ_MULTIBYTE_REG_COMMON_BODY
#define NRF_WRITE_MULTIBYTE_REG_COMMON_BODY

Functions

uint8_t hal_nrf_read_reg (uint8_t reg)
uint8_t hal_nrf_write_reg (uint8_t reg, uint8_t value)
uint16_t hal_nrf_read_multibyte_reg (uint8_t reg, uint8_t *pbuf)
void hal_nrf_write_multibyte_reg (uint8_t reg, const uint8_t *pbuf, uint8_t length)
void hal_nrf_set_operation_mode (hal_nrf_operation_mode_t op_mode)
void hal_nrf_set_power_mode (hal_nrf_pwr_mode_t pwr_mode)
void hal_nrf_set_crc_mode (hal_nrf_crc_mode_t crc_mode)
void hal_nrf_set_irq_mode (hal_nrf_irq_source_t int_source, _Bool irq_state)
uint8_t hal_nrf_get_clear_irq_flags (void)
uint8_t hal_nrf_clear_irq_flags_get_status (void)
void hal_nrf_clear_irq_flag (hal_nrf_irq_source_t int_source)
uint8_t hal_nrf_get_irq_flags (void)
void hal_nrf_open_pipe (hal_nrf_address_t pipe_num, _Bool auto_ack)
void hal_nrf_close_pipe (hal_nrf_address_t pipe_num)
void hal_nrf_set_address (const hal_nrf_address_t address, const uint8_t *addr)
uint8_t hal_nrf_get_address (uint8_t address, uint8_t *addr)
void hal_nrf_set_auto_retr (uint8_t retr, uint16_t delay)
void hal_nrf_set_address_width (hal_nrf_address_width_t address_width)
uint8_t hal_nrf_get_address_width (void)
void hal_nrf_set_rx_payload_width (uint8_t pipe_num, uint8_t pload_width)
uint8_t hal_nrf_get_pipe_status (uint8_t pipe_num)
uint8_t hal_nrf_get_auto_retr_status (void)
uint8_t hal_nrf_get_packet_lost_ctr (void)
uint8_t hal_nrf_get_rx_payload_width (uint8_t pipe_num)
void hal_nrf_set_rf_channel (uint8_t channel)
void hal_nrf_set_output_power (hal_nrf_output_power_t power)
void hal_nrf_set_datarate (hal_nrf_datarate_t datarate)
_Bool hal_nrf_rx_fifo_empty (void)
_Bool hal_nrf_rx_fifo_full (void)
_Bool hal_nrf_tx_fifo_empty (void)
_Bool hal_nrf_tx_fifo_full (void)
uint8_t hal_nrf_get_tx_fifo_status (void)
uint8_t hal_nrf_get_rx_fifo_status (void)
uint8_t hal_nrf_get_fifo_status (void)
uint8_t hal_nrf_get_transmit_attempts (void)
_Bool hal_nrf_get_carrier_detect (void)
void hal_nrf_activate_features (void)
void hal_nrf_setup_dynamic_payload (uint8_t setup)
void hal_nrf_enable_dynamic_payload (_Bool enable)
void hal_nrf_enable_ack_payload (_Bool enable)
void hal_nrf_enable_dynamic_ack (_Bool enable)
void hal_nrf_write_tx_payload (const uint8_t *tx_pload, uint8_t length)
void hal_nrf_write_tx_payload_noack (const uint8_t *tx_pload, uint8_t length)
void hal_nrf_write_ack_payload (uint8_t pipe, const uint8_t *tx_pload, uint8_t length)
uint8_t hal_nrf_read_rx_payload_width (void)
uint16_t hal_nrf_read_rx_payload (uint8_t *rx_pload)
uint8_t hal_nrf_get_rx_data_source (void)
void hal_nrf_reuse_tx (void)
_Bool hal_nrf_get_reuse_tx_status (void)
void hal_nrf_flush_rx (void)
void hal_nrf_flush_tx (void)
uint8_t hal_nrf_nop (void)
void hal_nrf_set_pll_mode (_Bool pll_lock)
void hal_nrf_enable_continious_wave (_Bool enable)

Detailed Description

Implementation of hal_nrf.

Definition in file hal_nrf.c.


Define Documentation

#define SET_BIT (   pos )    ((uint8_t) (1U<<( (uint8_t) (pos) )))

Definition at line 29 of file hal_nrf.c.

#define UINT8 (   t )    ((uint8_t) (t))

Definition at line 30 of file hal_nrf.c.

#define NRF_READ_MULTIBYTE_REG_COMMON_BODY
Value:
do \
    { \
      HAL_NRF_HW_SPI_WRITE(0U); \
      if (!first_round) \
      { \
        *buf = read_byte; \
        buf++; \
      } \
      else \
      { \
        first_round = false; \
      } \
      /* wait for byte transfer finished */ \
      while(HAL_NRF_HW_SPI_BUSY){} \
      read_byte = HAL_NRF_HW_SPI_READ(); \
    } while (--ctr); \
    *buf = read_byte;

Definition at line 785 of file hal_nrf.c.

#define NRF_WRITE_MULTIBYTE_REG_COMMON_BODY
Value:
do \
  { \
    next = *buf; \
    buf++; \
    while(HAL_NRF_HW_SPI_BUSY) {}  /* wait for byte transfer finished */ \
    dummy = HAL_NRF_HW_SPI_READ(); \
    HAL_NRF_HW_SPI_WRITE(next); \
  } while (--length);

Definition at line 869 of file hal_nrf.c.


Function Documentation

uint8_t hal_nrf_read_reg ( uint8_t  reg )

Basis function read_reg. Use this function to read the contents of one radios register.

Parameters:
regRegister to read
Returns:
Register contents

Definition at line 743 of file hal_nrf.c.

{
  uint8_t temp;

  CSN_LOW();

  HAL_NRF_HW_SPI_WRITE(reg);
  while(HAL_NRF_HW_SPI_BUSY) {}
  temp = HAL_NRF_HW_SPI_READ();

  HAL_NRF_HW_SPI_WRITE(0U);
  while(HAL_NRF_HW_SPI_BUSY) {}
  temp = HAL_NRF_HW_SPI_READ();

  CSN_HIGH();

  return temp;
}
uint8_t hal_nrf_write_reg ( uint8_t  reg,
uint8_t  value 
)

Basis function write_reg. Use this function to write a new value to a radio register.

Parameters:
regRegister to write
valueNew value to write
Returns:
Status register

< Register write command

Definition at line 762 of file hal_nrf.c.

{
  uint8_t retval;
/*lint -esym(550,dummy) symbol not accessed*/
/*lint -esym(438,dummy) last assigned value not used*/
/*lint -esym(838,dummy) previously assigned value not used*/
  uint8_t volatile dummy;

  CSN_LOW();

  HAL_NRF_HW_SPI_WRITE((W_REGISTER + reg));
  while(HAL_NRF_HW_SPI_BUSY) {}
  retval = HAL_NRF_HW_SPI_READ();

  HAL_NRF_HW_SPI_WRITE(value);
  while(HAL_NRF_HW_SPI_BUSY) {}
  dummy = HAL_NRF_HW_SPI_READ();

  CSN_HIGH();

  return retval;
}
uint16_t hal_nrf_read_multibyte_reg ( uint8_t  reg,
uint8_t *  pbuf 
)

Basis function, read_multibyte register . Use this function to read multiple bytes from a multibyte radio-register

Parameters:
regMultibyte register to read from
*pbufPointer to buffer in which to store read bytes to
Returns:
pipe# of received data (MSB), if operation used by a hal_nrf_read_rx_pload
length of read data (LSB), either for hal_nrf_read_rx_pload or for hal_nrf_get_address.

< nRF24L01 receive address data pipe0

< Read RX payload command

Definition at line 804 of file hal_nrf.c.

{
  uint8_t ctr, length;
  uint8_t memtype;
  uint8_t read_byte; /*lint -esym(530,read_byte) symbol not initialized*/
  bool first_round;
  first_round = true;

  memtype = *(uint8_t*)(&pbuf);

  switch(reg)
  {
    case HAL_NRF_PIPE0:
    case HAL_NRF_PIPE1:
    case HAL_NRF_TX:
      length = ctr = hal_nrf_get_address_width();
      CSN_LOW();
      hal_nrf_rw(RX_ADDR_P0 + reg);
      break;

    case HAL_NRF_RX_PLOAD:
      reg = hal_nrf_get_rx_data_source();
      if (reg < 7U)
      {
        length = ctr = hal_nrf_read_rx_payload_width();
        CSN_LOW();
        hal_nrf_rw(R_RX_PAYLOAD);
      }
      else
      {
        ctr = length = 0U;
      }
      break;

    default:
      ctr = length = 0U;
      break;
  }

  if (memtype == 0x00U)
  {
    uint8_t data *buf = (uint8_t data *)pbuf;
    NRF_READ_MULTIBYTE_REG_COMMON_BODY
  }
  else if (memtype == 0x01U)
  {
    uint8_t xdata *buf = (uint8_t xdata *)pbuf;
    NRF_READ_MULTIBYTE_REG_COMMON_BODY
  }
  else if (memtype == 0xFEU)
  {
    uint8_t pdata *buf = (uint8_t pdata *)pbuf;
    NRF_READ_MULTIBYTE_REG_COMMON_BODY
  }
  else
  {
    uint8_t *buf = (uint8_t *)pbuf;
    NRF_READ_MULTIBYTE_REG_COMMON_BODY
  }

  CSN_HIGH();

  return (((uint16_t) reg << 8) | length);
}
void hal_nrf_write_multibyte_reg ( uint8_t  reg,
const uint8_t *  pbuf,
uint8_t  length 
)

Basis function, write_multibyte register. Use this function to write multiple bytes to a multiple radio register.

Parameters:
regRegister to write
*pbufpointer to buffer in which data to write is
length# of bytes to write

Definition at line 881 of file hal_nrf.c.

{
  uint8_t memtype;
  uint8_t next;
  uint8_t volatile dummy;

  memtype = *(uint8_t*)(&pbuf);

  CSN_LOW();
  HAL_NRF_HW_SPI_WRITE(reg);

  if (memtype == 0x00U)
  {
    const uint8_t data *buf = (const uint8_t data *)pbuf;
    NRF_WRITE_MULTIBYTE_REG_COMMON_BODY
  }
  else if (memtype == 0x01U)
  {
    const uint8_t xdata *buf = (const uint8_t xdata *)pbuf;
    NRF_WRITE_MULTIBYTE_REG_COMMON_BODY
  }
  else if (memtype == 0xFEU)
  {
    const uint8_t pdata *buf = (const uint8_t pdata *)pbuf;
    NRF_WRITE_MULTIBYTE_REG_COMMON_BODY
  }
  else
  {
    const uint8_t *buf = (const uint8_t *)pbuf;
    NRF_WRITE_MULTIBYTE_REG_COMMON_BODY
  }

  while(HAL_NRF_HW_SPI_BUSY) {} /* wait for byte transfer finished */
  dummy = HAL_NRF_HW_SPI_READ();
  CSN_HIGH();
}