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.
Implementation of hal_nrf.
Definition in file hal_nrf.c.
#define SET_BIT | ( | pos ) | ((uint8_t) (1U<<( (uint8_t) (pos) ))) |
#define NRF_READ_MULTIBYTE_REG_COMMON_BODY |
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;
#define NRF_WRITE_MULTIBYTE_REG_COMMON_BODY |
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);
uint8_t hal_nrf_read_reg | ( | uint8_t | reg ) |
Basis function read_reg. Use this function to read the contents of one radios register.
reg | Register to read |
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.
reg | Register to write |
value | New value to write |
< 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
reg | Multibyte register to read from |
*pbuf | Pointer to buffer in which to store read bytes to |
< 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.
reg | Register to write |
*pbuf | pointer 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(); }