XENSIV BGT60TRxx Radar Sensor
XENSIV(TM) BGT60TRxx Radar Sensor ModusToolBox(TM) Interface

General Description

Provides the ModusToolbox(TM) interface to the XENSIV(TM) BGT60TRxx 60GHz FMCW radar sensors library and the implementation of the platform functions using the PSoC(TM) 6 HAL.

Note
The library uses delays while waiting for the sensor. If the RTOS_AWARE component is set or CY_RTOS_AWARE is defined, the driver will defer to the RTOS for delays. Because of this, it is not safe to call any functions until after the RTOS scheduler has started.

Code snippets

Snippet 1: Initialization.

The following snippet initializes an SPI instance and the BGT60TRxx.

/* Enable LDO */
result = cyhal_gpio_init(PIN_XENSIV_BGT60TRXX_LDO_EN,
CYHAL_GPIO_DIR_OUTPUT,
CYHAL_GPIO_DRIVE_STRONG,
true);
CY_ASSERT(result == CY_RSLT_SUCCESS);
/* Wait LDO stable */
(void)cyhal_system_delay_ms(5);
cyhal_spi_t cyhal_spi;
result = cyhal_spi_init(&cyhal_spi,
PIN_XENSIV_BGT60TRXX_SPI_MOSI,
PIN_XENSIV_BGT60TRXX_SPI_MISO,
PIN_XENSIV_BGT60TRXX_SPI_SCLK,
NC,
NULL,
8,
CYHAL_SPI_MODE_00_MSB,
false);
CY_ASSERT(result == CY_RSLT_SUCCESS);
#if defined(COMPONENT_CAT1)
/* Reduce drive strength to improve EMI */
Cy_GPIO_SetSlewRate(CYHAL_GET_PORTADDR(PIN_XENSIV_BGT60TRXX_SPI_MOSI),
CYHAL_GET_PIN(PIN_XENSIV_BGT60TRXX_SPI_MOSI), CY_GPIO_SLEW_FAST);
Cy_GPIO_SetDriveSel(CYHAL_GET_PORTADDR(PIN_XENSIV_BGT60TRXX_SPI_MOSI),
CYHAL_GET_PIN(PIN_XENSIV_BGT60TRXX_SPI_MOSI), CY_GPIO_DRIVE_1_8);
Cy_GPIO_SetSlewRate(CYHAL_GET_PORTADDR(PIN_XENSIV_BGT60TRXX_SPI_SCLK),
CYHAL_GET_PIN(PIN_XENSIV_BGT60TRXX_SPI_SCLK), CY_GPIO_SLEW_FAST);
Cy_GPIO_SetDriveSel(CYHAL_GET_PORTADDR(PIN_XENSIV_BGT60TRXX_SPI_SCLK),
CYHAL_GET_PIN(PIN_XENSIV_BGT60TRXX_SPI_SCLK), CY_GPIO_DRIVE_1_8);
#endif
/* Set SPI data rate to communicate with sensor */
result = cyhal_spi_set_frequency(&cyhal_spi, XENSIV_BGT60TRXX_SPI_FREQUENCY);
CY_ASSERT(result == CY_RSLT_SUCCESS);
/* Initialize sensor */
result = xensiv_bgt60trxx_mtb_init(&sensor,
&cyhal_spi,
PIN_XENSIV_BGT60TRXX_SPI_CSN,
PIN_XENSIV_BGT60TRXX_RSTN,
register_list,
XENSIV_BGT60TRXX_CONF_NUM_REGS);
CY_ASSERT(result == CY_RSLT_SUCCESS);
/* The sensor will generate an interrupt once the sensor FIFO level is
NUM_SAMPLES_PER_FRAME */
NUM_SAMPLES,
PIN_XENSIV_BGT60TRXX_IRQ,
CYHAL_ISR_PRIORITY_DEFAULT,
xensiv_bgt60trxx_mtb_interrupt_handler,
NULL);
CY_ASSERT(result == CY_RSLT_SUCCESS);

Snippet 2: Reading from the sensor.

The following snippet demonstrates how to read data from the sensor.

{
CY_ASSERT(false);
}
uint32_t frame_idx = 0;
uint16_t test_word = XENSIV_BGT60TRXX_INITIAL_TEST_WORD;
for (;;)
{
/* wait for radar device to indicate the availability of data to fetched */
while (data_available == false)
{
}
data_available = false;
if (xensiv_bgt60trxx_get_fifo_data(&sensor.dev, samples,
NUM_SAMPLES) == XENSIV_BGT60TRXX_STATUS_OK)
{
/* Check received data */
for (int32_t sample_idx = 0; sample_idx < NUM_SAMPLES; ++sample_idx)
{
if ((sample_idx % XENSIV_BGT60TRXX_CONF_NUM_RX_ANTENNAS) == 0)
{
if (test_word != samples[sample_idx])
{
printf("Frame %" PRIu32 " error detected. "
"Expected: %" PRIu16 ". "
"Received: %" PRIu16 "\n",
frame_idx, test_word, samples[sample_idx]);
CY_ASSERT(false);
}
}
// Generate next test_word
test_word = xensiv_bgt60trxx_get_next_test_word(test_word);
}
}
printf("Frame %" PRIu32 " received correctly\n", frame_idx);
frame_idx++;
}
example-terminal.png

Data Structures

struct  xensiv_bgt60trxx_mtb_iface_t
 Structure holding the XENSIV(TM) BGT60TRxx ModusToolbox(TM) interface. More...
 
struct  xensiv_bgt60trxx_mtb_t
 Structure holding the XENSIV(TM) BGT60TRxx ModusToolbox(TM) object. More...
 

Macros

#define CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX   0x01CC
 Module identifier for the XENSIV(TM) BGT60TRxx radar sensor library. More...
 
#define XENSIV_BGT60TRXX_RSLT_ERR_COMM   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX, XENSIV_BGT60TRXX_STATUS_COM_ERROR))
 Result code indicating a communication error. More...
 
#define XENSIV_BGT60TRXX_RSLT_ERR_UNKNOWN_DEVICE   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX, XENSIV_BGT60TRXX_STATUS_DEV_ERROR))
 Result code indicating an unsupported device error. More...
 
#define XENSIV_BGT60TRXX_RSLT_ERR_INTPIN_INUSE   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX, 0x100))
 An attempt was made to reconfigure the interrupt pin.
 

Functions

cy_rslt_t xensiv_bgt60trxx_mtb_init (xensiv_bgt60trxx_mtb_t *obj, cyhal_spi_t *spi, cyhal_gpio_t selpin, cyhal_gpio_t rstpin, const uint32_t *regs, size_t len)
 Initializes the XENSIV(TM) BGT60TRxx sensor. More...
 
cy_rslt_t xensiv_bgt60trxx_mtb_interrupt_init (xensiv_bgt60trxx_mtb_t *obj, uint16_t fifo_limit, cyhal_gpio_t irqpin, uint8_t intr_priority, cyhal_gpio_event_callback_t callback, void *callback_arg)
 Configures a GPIO pin as an interrupt for the XENSIV(TM) BGT60TRxx. More...
 
void xensiv_bgt60trxx_mtb_free (xensiv_bgt60trxx_mtb_t *obj)
 Frees up any resources allocated by the XENSIV(TM) BGT60TRxx as part of xensiv_bgt60trxx_mtb_init() More...
 

Data Structure Documentation

◆ xensiv_bgt60trxx_mtb_iface_t

struct xensiv_bgt60trxx_mtb_iface_t
Data Fields
cyhal_spi_t * spi
cyhal_gpio_t selpin
cyhal_gpio_t rstpin
xensiv_bgt60trxx_mtb_interrupt_pin_t irqpin

◆ xensiv_bgt60trxx_mtb_t

struct xensiv_bgt60trxx_mtb_t
Data Fields
xensiv_bgt60trxx_t dev sensor object
xensiv_bgt60trxx_mtb_iface_t iface interface object for communication

Macro Definition Documentation

◆ CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX

#define CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX   0x01CC

Module identifier for the XENSIV(TM) BGT60TRxx radar sensor library.

Asset(s): (sensor-XENSIV(TM)-bgt60trxx)

◆ XENSIV_BGT60TRXX_RSLT_ERR_COMM

#define XENSIV_BGT60TRXX_RSLT_ERR_COMM   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX, XENSIV_BGT60TRXX_STATUS_COM_ERROR))

Result code indicating a communication error.

◆ XENSIV_BGT60TRXX_RSLT_ERR_UNKNOWN_DEVICE

#define XENSIV_BGT60TRXX_RSLT_ERR_UNKNOWN_DEVICE   (CY_RSLT_CREATE(CY_RSLT_TYPE_ERROR, CY_RSLT_MODULE_BOARD_HARDWARE_XENSIV_BGT60TRXX, XENSIV_BGT60TRXX_STATUS_DEV_ERROR))

Result code indicating an unsupported device error.

Function Documentation

◆ xensiv_bgt60trxx_mtb_init()

cy_rslt_t xensiv_bgt60trxx_mtb_init ( xensiv_bgt60trxx_mtb_t obj,
cyhal_spi_t *  spi,
cyhal_gpio_t  selpin,
cyhal_gpio_t  rstpin,
const uint32_t *  regs,
size_t  len 
)

Initializes the XENSIV(TM) BGT60TRxx sensor.

The provided pins will be initialized by this function. If the reset pin is used (rstpin) the function will generate a hardware reset sequence. The SPI slave select pin (selpin) is expected to be controlled by this driver, not the SPI block itself. This allows the driver to issue multiple read/write requests back to back.

The function initializes a sensor object using the configuration register list.

Refer Code snippets for more information.

Parameters
[in,out]objPointer to the BGT60TRxx ModusToolbox(TM) object. The caller must allocate the memory for this object but the init function will initialize its contents.
[in]spiPointer to an initialized SPI HAL object using Standard Motorola SPI Mode 0 (CPOL=0, CPHA=0) with MSB first
[in]selpinPin connected to the SPI_CSN pin of the sensor.
Note
This pin cannot be NC
Parameters
[in]rstpinPin connected to the SPI_DIO3 pin of the sensor.
Note
This pin can be NC
Parameters
[in]regsPointer to the configuration registers list.
[in]lenLength of the configuration registers list.
Returns
CY_RSLT_SUCCESS if properly initialized; else an error indicating what went wrong.

◆ xensiv_bgt60trxx_mtb_interrupt_init()

cy_rslt_t xensiv_bgt60trxx_mtb_interrupt_init ( xensiv_bgt60trxx_mtb_t obj,
uint16_t  fifo_limit,
cyhal_gpio_t  irqpin,
uint8_t  intr_priority,
cyhal_gpio_event_callback_t  callback,
void *  callback_arg 
)

Configures a GPIO pin as an interrupt for the XENSIV(TM) BGT60TRxx.

Initializes and configures the pin (irqpin) as an interrupt input. Configures the XENSIV(TM) BGT60TRxx to trigger an interrupt after the number of fifo_limit words are stored in the BGT60TRxx FIFO. Each FIFO word corresponds to two ADC samples.

Note
BGT60TRxx pointer must be initialized using xensiv_bgt60trxx_mtb_init() before calling this function.

Refer Code snippets for more information.

Parameters
[in,out]objPointer to the BGT60TRxx ModusToolbox(TM) object.
[in]fifo_limitNumber of words stored in FIFO that will trigger an interrupt.
[in]irqpinPin connected to the IRQ pin of the sensor.
[in]intr_priorityThe priority for NVIC interrupt events.
[in]callbackThe function to call when the specified event happens. Pass NULL to unregister the handler.
[in]callback_argGeneric argument that will be provided to the callback when called, can be NULL
Returns
CY_RSLT_SUCCESS if interrupt was successfully enabled; else an error occurred while initializing the pin.

◆ xensiv_bgt60trxx_mtb_free()

void xensiv_bgt60trxx_mtb_free ( xensiv_bgt60trxx_mtb_t obj)

Frees up any resources allocated by the XENSIV(TM) BGT60TRxx as part of xensiv_bgt60trxx_mtb_init()

Parameters
[in]objPointer to the BGT60TRxx ModusToolbox(TM) object.