#include "board/board_config.h"
#include "driver/irq.h"
#ifndef DEVICE_COUNT
#define DEVICE_COUNT 4
#endif
#ifndef SPI_SLAVE1
#define SPI_SLAVE1 (SPI_SLAVE)
#endif
#ifndef SPI_SLAVE2
#define SPI_SLAVE2 (SPI_SLAVE1 + 1)
#endif
#ifndef SPI_SLAVE3
#define SPI_SLAVE3 (SPI_SLAVE2 + 1)
#endif
#ifndef SPI_SLAVE4
#define SPI_SLAVE4 (SPI_SLAVE3 + 1)
#endif
#define FIFO_SIZE 8
typedef struct fifo_t
{
size_t volatile Load;
} fifo_t;
static fifo_t DataReadyEventQueue = { 0 };
{
return device;
}
{
(void)device;
assert(DataReadyEventQueue.Load < FIFO_SIZE);
*DataReadyEventQueue.WrPtr = device;
DataReadyEventQueue.WrPtr++;
if (DataReadyEventQueue.WrPtr >= DataReadyEventQueue.Buffer + FIFO_SIZE)
DataReadyEventQueue.WrPtr = DataReadyEventQueue.Buffer;
DataReadyEventQueue.Load++;
}
{
print(
"#%06d: %4d.%06d s; Range: %5d mm; Amplitude: %4d LSB; Quality: %3d; Status: %d\n",
id,
}
static void PrintDeviceInfo(
const uint8_t device_count,
argus_hnd_t * devices[
static device_count])
{
const uint8_t a = (uint8_t)((value >> 24) & 0xFFU);
const uint8_t b = (uint8_t)((value >> 16) & 0xFFU);
const uint8_t c = (uint8_t)(value & 0xFFFFU);
print(
"\n##### AFBR-S50 API - Multi-Device Example #####################\n"
" API Version: v%d.%d.%d\n", a, b, c);
for (uint8_t d = 0; d < device_count; d++)
{
print(
" Chip ID #%d: %d\n"
" Module #%d: %s\n",
d + 1, id, d + 1, m);
}
print(
"###############################################################\n\n");
}
{
HardwareInit();
const s2pi_slave_t slaves[] = { SPI_SLAVE1, SPI_SLAVE2, SPI_SLAVE3, SPI_SLAVE4 };
DataReadyEventQueue.WrPtr = DataReadyEventQueue.Buffer;
DataReadyEventQueue.RdPtr = DataReadyEventQueue.Buffer;
DataReadyEventQueue.Load = 0;
for (uint8_t d = 0; d < DEVICE_COUNT; d++)
{
devices[d] = InitializeDevice(slaves[d]);
}
PrintDeviceInfo(sizeof(devices) / sizeof(devices[0]), devices);
for (uint8_t d = 0; d < DEVICE_COUNT; d++)
{
}
for (;;)
{
if (DataReadyEventQueue.Load > 0)
{
DataReadyEventQueue.Load--;
DataReadyEventQueue.RdPtr++;
if (DataReadyEventQueue.RdPtr >= DataReadyEventQueue.Buffer + FIFO_SIZE)
DataReadyEventQueue.RdPtr = DataReadyEventQueue.Buffer;
PrintResults(&res, id);
}
}
}
int main(void)
Application entry point.
Definition main.c:48
This file is part of the AFBR-S50 API.
status_t MeasurementReadyCallback(status_t status, argus_hnd_t *argus)
char const * Argus_GetModuleName(argus_hnd_t *hnd)
Gets the name string of the module.
status_t Argus_Init(argus_hnd_t *hnd, s2pi_slave_t spi_slave)
Initializes the device with default measurement mode.
uint32_t Argus_GetChipID(argus_hnd_t *hnd)
Gets the unique identification number of the chip.
argus_hnd_t * Argus_CreateHandle(void)
Creates a new device data handle object to store all internal states.
struct argus_hnd_t argus_hnd_t
Definition argus_def.h:284
int32_t s2pi_slave_t
Definition argus_api.h:67
uint32_t Argus_GetAPIVersion(void)
Gets the version number of the current API library.
status_t Argus_SetConfigurationFrameTime(argus_hnd_t *hnd, uint32_t value)
Sets the frame time to a specified device.
#define UQ12_4_ONE
Definition fp_def.h:237
#define Q9_22_ONE
Definition fp_def.h:547
void IRQ_UNLOCK(void)
Enable IRQ Interrupts.
void IRQ_LOCK(void)
Disable IRQ Interrupts.
status_t print(const char *fmt_s,...)
A printf-like function to print formatted data to an debugging interface.
Definition sci_log.c:106
status_t Argus_EvaluateData(argus_hnd_t *hnd, argus_results_t *res)
Evaluates measurement data from the raw sensor readout data.
status_t Argus_StartMeasurementTimer(argus_hnd_t *hnd, argus_measurement_ready_callback_t cb)
Starts the timer based measurement cycle asynchronously.
int32_t status_t
Type used for all status and error return values.
Definition argus_status.h:70
@ STATUS_OK
Definition argus_status.h:80
@ ERROR_FAIL
Definition argus_status.h:95
static status_t status
Definition argus_xtalk_cal_cli.c:140
void HandleError(status_t status, bool stop, char const *msg)
A callback function from the example code whenever an error occurs.
Definition main.c:62
uint8_t SignalQuality
Definition argus_res.h:87
q9_22_t Range
Definition argus_res.h:75
uq12_4_t Amplitude
Definition argus_res.h:81
The measurement results data structure.
Definition argus_res.h:216
ltc_t TimeStamp
Definition argus_res.h:225
status_t Status
Definition argus_res.h:221
argus_results_bin_t Bin
Definition argus_res.h:269
uint32_t usec
Definition time.h:77
uint32_t sec
Definition time.h:73