AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
|
A test module to verify implementation of the HAL. More...
Macros | |
#define | error_log(fmt, ...) print("ERROR: " fmt "\n", ##__VA_ARGS__) |
#define | HAL_TEST_VERSION "v1.4" |
Version number of the HAL Self Test. | |
Functions | |
static status_t | VerifyHALImplementation (s2pi_slave_t spi_slave) |
Executes a series of tests in order to verify the HAL implementation. | |
static status_t | TimerPlausibilityTest (void) |
Plausibility Test for Timer HAL Implementation. | |
static status_t | TimerWraparoundTest (void) |
Wraparound Test for the Timer HAL Implementation. | |
static status_t | SpiConnectionTest (s2pi_slave_t slave) |
SPI Connection Test for S2PI HAL Implementation. | |
static status_t | SpiMaxLengthTest (s2pi_slave_t slave) |
Maximum SPI Data Size Test for S2PI HAL Implementation. | |
static status_t | GpioInterruptTest (s2pi_slave_t slave) |
SPI Interrupt Test for S2PI HAL Implementation. | |
static status_t | GpioModeTest (s2pi_slave_t slave) |
GPIO Mode Test for S2PI HAL Implementation. | |
static status_t | TimerTest (s2pi_slave_t slave) |
Test for Timer HAL Implementation by comparing timings to the device. | |
static status_t | PITTest (void) |
Test for PIT HAL Implementation by comparing timings to the device. | |
static status_t | SpiTransferFromInterruptTest (s2pi_slave_t slave) |
SPI Transfer from Interrupt Test for S2PI HAL Implementation. | |
static status_t | CheckTimerCounterValues (uint32_t hct, uint32_t lct) |
Checks the validity of timer counter values. | |
static status_t | SPITransferSync (s2pi_slave_t slave, uint8_t *data, size_t size) |
Helper function for transfer data to SPI in blocking mode. | |
static status_t | ConfigureDevice (s2pi_slave_t slave, int8_t rcoTrim) |
Configures the device with a bare minimum setup to run the tests. | |
static status_t | TriggerMeasurement (s2pi_slave_t slave, uint16_t samples, s2pi_callback_t callback, void *callbackData) |
Triggers a measurement on the device with specified sample count. | |
static status_t | ReadEEPROM (s2pi_slave_t slave, uint8_t *eeprom) |
Reads the EEPROM byte-wise and applies Hamming weight. | |
static status_t | ReadRcoTrim (s2pi_slave_t slave, int8_t *rcotrim) |
Reads the RCO_TRIM value from the devices EEPROM. | |
static status_t | RunMeasurement (s2pi_slave_t slave, uint16_t samples) |
Triggers a measurement on the device and waits for the data ready interrupt. | |
static status_t | RunPITTest (uint32_t exp_dt_us, uint32_t n) |
Executes a PIT measurement and verifies the callback interval. | |
static void | PIT_Callback (void *param) |
Callback function invoked by the PIT. | |
static void | GPIO_Callback (void *param) |
The IRQ callback dedicated to the GpioInterruptTest. | |
status_t | Argus_VerifyHALImplementation (s2pi_slave_t spi_slave) |
Executes a series of tests in order to verify the HAL implementation. | |
static status_t | SpiTransferInterruptCallback (status_t status, void *param) |
SPI interrupt callback function for the SPI transfer interrupt test. | |
static status_t | GPIO_SPI_Callback (status_t status, void *param) |
The SPI transfer callback dedicated to the GpioInterruptTest. | |
static void | MeasurementCallback (void *param) |
Callback function for the data ready interrupt. | |
static status_t | SpiTransferFromSpiInterruptCallback (status_t status, void *param) |
SPI interrupt callback function for the SPI transfer from IRQ test. | |
static status_t | SpiTransferFromSpiInterrupt (s2pi_slave_t slave) |
SPI transfer from SPI interrupt callback test. | |
static void | SpiTransferFromGpioInterruptCallback (void *param) |
GPIO interrupt callback function for the SPI transfer from IRQ test. | |
static status_t | SpiTransferFromGpioInterrupt (s2pi_slave_t slave) |
SPI transfer from GPIO interrupt callback test. | |
static void | SpiTransferFromPitInterruptCallback (void *param) |
PIT interrupt callback function for the SPI transfer from IRQ test. | |
static status_t | SpiTransferFromPitInterrupt (s2pi_slave_t slave) |
SPI transfer from PIT interrupt callback test. | |
A test module to verify implementation of the HAL.
A series of automated tests that can be executed on the target platform in order to verify the implementation of the HAL that are required by the API.
See Argus_VerifyHALImplementation for a detailed documentation.
#define error_log | ( | fmt, | |
... | |||
) | print("ERROR: " fmt "\n", ##__VA_ARGS__) |
An error log message via print function.
#define HAL_TEST_VERSION "v1.4" |
Version number of the HAL Self Test.
Changes:
status_t Argus_VerifyHALImplementation | ( | s2pi_slave_t | spi_slave | ) |
Executes a series of tests in order to verify the HAL implementation.
A series of automated tests are executed on the target platform in order to verify the implementation of the HAL that are required by the API.
Each test will write an error description via the print (i.e. UART) function that shows what went wrong. Also an corresponding status is returned in case no print functionality is available.
The following tests are executed:
1) Timer Plausibility Test:
Rudimentary tests of the lifetime counter (LTC) implementation. This verifies that the LTC is running by checking if the returned values of two consecutive calls to the Timer_GetCounterValue function are ascending. An artificial delay using the NOP operation is induced such that the timer is not read to fast.
2) Timer Wraparound Test:
The LTC values must wrap from 999999 µs to 0 µs and increase the seconds counter accordingly. This test verifies the correct wrapping by consecutively calling the Timer_GetCounterValue function until at least 2 wraparound events have been occurred.
3) SPI Connection Test:
This test verifies the basic functionality of the SPI interface. The test utilizes the devices laser pattern register, which can be freely programmed by any 128-bit pattern. Thus, it writes a byte sequence and reads back the written values on the consecutive SPI access.
4) SPI Maximum Data Length Test:
This test verifies the maximum data transfer length of the SPI interface. The test sends and receives up to 396 data bytes plus a single address byte over the SPI interface and verifies that no data get lost.
5) SPI Interrupt Test:
This test verifies the correct implementation of the device integration finished interrupt callback. Therefore it configures the device with a minimal setup to run a pseudo measurement that does not emit any laser light.
Note that this test does verify the GPIO interrupt that occurs whenever the device has finished the integration/measurement and new data is waiting to be read from the device. This does not test the interrupt that is triggered when the SPI transfer has finished.
The data ready interrupt implies two S2PI layer functions that are tested in this test: The S2PI_SetIrqCallback function installs a callback function that is invoked whenever the IRQ occurs. The IRQ can be delayed due to higher priority task, e.g. from the user code. It is essential for the laser safety timeout algorithm to determine the device ready signal as fast as possible, another method is implemented to read if the IRQ is pending but the callback has not been reset yet. This is what the S2PI_ReadIrqPin function is for.
6) GPIO Mode Test:
This test verifies the GPIO mode of the S2PI HAL module. This is done by leveraging the EEPROM readout sequence that accesses the devices EEPROM via a software protocol that depends on the GPIO mode.
This the requires several steps, most of them are already verified in previous tests:
7) Timer Test for Lifetime Counter:
The test verifies the lifetime counter timer HAL implementation by comparing the timings to the AFBR-S50 device as a reference. Therefore several measurement are executed on the device, each with a different averaging sample count. The elapsed time increases linearly with the number of averaging samples. In order to remove the time for software/setup, a linear regression fit is applied to the measurement results and only the slope is considered for the result. A delta of 102.4 microseconds per sample is expected. If the measured delta per sample is within an specified error range, the timer implementation is considered correct.
8) Timer Test for Periodic Interrupt Timer (optional):
The test verifies the correct implementation of the periodic interrupt timer (PIT). It sets different intervals and waits for a certain number of interrupts to happen. Each interrupt event is counted and the time between the first and the last interrupt is measured. Finally, the measured interval is compared to the expectations.
Note that this test is only executed if the PIT is actually implemented. Otherwise, the test is skipped.
9) SPI Transfer from Interrupt Callback Test:
The test verifies that the S2PI_TransferFrame method of the S2PI layer can be invoked from a interrupt callback function too. Thus, it repeats the S2PI Connection Test but this time from different interrupt callback functions:
spi_slave | The SPI hardware slave, i.e. the specified CS and IRQ lines. This is actually just a number that is passed to the SPI interface to distinct for multiple SPI slave devices. Note that the slave must be not equal to 0, since is reserved for error handling. |
|
static |
Checks the validity of timer counter values.
This verifies that the counter values returned from the Timer_GetCounterValue function are valid. This means, the low counter value lct
is within 0 and 999999 µs.
|
static |
Configures the device with a bare minimum setup to run the tests.
This function applies a number of configuration values to the device, such that a pseudo measurement w/o laser output can be performed.
A rcoTrim
parameter can be passed to adjust the actual clock setup.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
rcoTrim | The RCO Trimming value added to the nominal RCO register value. Pass 0 if no fine tuning is required. |
|
static |
The IRQ callback dedicated to the GpioInterruptTest.
The callback is invoked by the API when the device GPIO IRQ is pending after a measurement has been executed and data is ready to be read from the device.
param | The abstract pointer to the boolean value that determines if the callback is invoked. |
The SPI transfer callback dedicated to the GpioInterruptTest.
The callback is invoked by the S2PI layer when the SPI transfer finished IRQ is invoked. The callback is used to simulate a deferred GPIO interrupt by locking the interrupts until the S2PI_ReadIrqPin detects an GPIO interrupt pending state and returns 0.
status | The status of the SPI transfer. |
param | The abstract pointer to the boolean value that determines if the callback is invoked. |
param
parameter is NULL.status
parameter.
|
static |
SPI Interrupt Test for S2PI HAL Implementation.
This test verifies the correct implementation of the device integration finished interrupt callback, a.k.a. the GPIO interrupt. Therefore it configures the device with a minimal setup to run a pseudo measurement that does not emit any laser light but triggers an GPIO interrupt once finished.
The data ready interrupt implies two S2PI layer functions that are tested in this test: The S2PI_SetIrqCallback function installs a callback function that is invoked whenever the IRQ occurs and the S2PI_ReadIrqPin function to obtain the pending interrupt state.
The IRQ can be delayed due to higher priority task, e.g. from the user code. It is essential for the laser safety timeout algorithm to determine the device ready signal as fast as possible. Thus a method is required to obtain if the IRQ is currently pending but the callback has not been invoked yet. This is what the S2PI_ReadIrqPin function is for. Note that the S2PI_ReadIrqPin must return 0 if not interrupt is pending and 1 else. Just like the IRQ pin is active low.
The test simulate a delayed GPIO interrupt by locking the interrupts until the S2PI_ReadIrqPin detects an GPIO interrupt pending state and returns 0. This is done by the GPIO_SPI_Callback function.
Note that this test does verify the GPIO interrupt that occurs whenever the device has finished the integration/measurement and new data is waiting to be read from the device. This does not test the interrupt that is triggered when the SPI transfer has finished.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
GPIO Mode Test for S2PI HAL Implementation.
This test verifies the GPIO mode of the S2PI HAL module. This is done by leveraging the EEPROM readout sequence that accesses the devices EEPROM via a software protocol that depends on the GPIO mode.
This the requires several steps, most of them are already verified in previous tests:
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
Callback function for the data ready interrupt.
The function is called by the S2PI layer when the data ready interrupt is pending. The function sets the param
to STATUS_IDLE.
param | The parameter passed to the S2PI_SetIrqCallback function as an abstract pointer to an status_t type. |
|
static |
Callback function invoked by the PIT.
The function that is invoked every time a specified interval elapses. An abstract parameter is passed to the function whenever it is called.
This implementation collects callback time stamps and counts the number of callback events using the abstract parameter.
param | An abstract parameter to be passed to the callback. This is also the identifier of the given interval. |
|
static |
Test for PIT HAL Implementation by comparing timings to the device.
The test verifies the timer HAL implementation by comparing the period between the interrupts with the lifetime timer values that has been already verified in a previous test (see TimerTest).
|
static |
Reads the EEPROM byte-wise and applies Hamming weight.
The EEPROM bytes are consecutively read from the device via GPIO mode. The EEPROM_Read function is an internal API function that enables the GPIO mode from the S2PI module and reads the data via a software bit-banging protocol. Finally it disables the GPIO mode and returns to SPI mode.
The calls to S2PI HAL module is as follows:
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
eeprom | The 16 byte array to be filled with EEPROM data. |
|
static |
Reads the RCO_TRIM value from the devices EEPROM.
The function reads the devices EEPROM via GPIO mode and extracts the RCO_TRIM value from the EEPROM map.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
rcotrim | The read RCO_TRIM value will be returned via this pointer. |
|
static |
Triggers a measurement on the device and waits for the data ready interrupt.
The function triggers a measurement cycle on the device and waits until the measurement has been finished. A sample
count can be specified to setup individual number of digital averaging.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
samples | The specified number of averaging samples for the measurement. |
|
static |
Executes a PIT measurement and verifies the callback interval.
The function configures the PIT with a given interval and waits several callback events to happen. In each callback event, the elapsed time is measured and the number of calls are counted. Finally, the average interrupt period is compared with the lifetime timer that has been already verified in a previous test (see TimerTest). The time until the first interrupt event is also verified.
exp_dt_us | The expected timer interval in microseconds. |
n | The number of PIT events to await. |
|
static |
SPI Connection Test for S2PI HAL Implementation.
This test verifies the basic functionality of the SPI interface.
The test utilizes the devices laser pattern register, which can be freely programmed by any 128-bit pattern. Thus, it writes a byte sequence and reads back the written values on the consecutive SPI access. Note: The test verifies the SPI interface transfer functionality in blocking mode and also verifies the interrupt callback. In order to wait for the transfer to finish, it reads the S2PI status in a loop. If the status does not change to #STATUS_IDLE, the test will fail with an #ERROR_TIMEOUT. Finally, the test will verify the SPI transfer callback status.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
Maximum SPI Data Size Test for S2PI HAL Implementation.
This test verifies the maximum data transfer length of the SPI interface. The test sends and receives up to 396 data bytes plus a single address byte over the SPI interface and verifies that no data get lost.
The test utilizes the channel select register which is 3 bytes plus address. This register can be repeatedly written with any pattern using the DMA mode. The register is written 100 times in a row to verify that long data frames with up to 400 bytes can be transmitted.
Note that this test was motivated by an invalid implementation that used uint8_t type for the frame length in the S2PI_TransferFrame function instead of an uint16_t value. This resulted in a maximum data length of 141 bytes (367 & 0xFF = 141) when reading the data value register.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
SPI transfer from GPIO interrupt callback test.
This test verifies the interrupt functionality of the SPI interface. The test verifies that an SPI transfer can be triggered from the GPIO interrupt service routine context.
The test basically repeats the SpiTransferFromSpiInterrupt but this time it invokes the first SPI transfer from the GPIO callback function. In order to trigger a GPIO interrupt, the device is configured and a measurement is started (see GpioInterruptTest).
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
GPIO interrupt callback function for the SPI transfer from IRQ test.
The interrupt callback is invoked from the S2PI module upon receiving an GPIO interrupt from the devices IRQ pin. The callback is used by the SpiTransferFromGpioInterrupt test to trigger the first SPI transfer from the interrupt callback context.
param | The abstract interrupt callback parameter. |
|
static |
SPI Transfer from Interrupt Test for S2PI HAL Implementation.
This test verifies the interrupt functionality of the SPI interface. The test verifies that an SPI transfer can be triggered from the interrupt service routine context. I.e. the S2PI_TransferFrame function is called from the following interrupts:
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
SPI transfer from PIT interrupt callback test.
This test verifies the interrupt functionality of the SPI interface. The test verifies that an SPI transfer can be triggered from the PIT interrupt service routine context.
The test basically repeats the SpiTransferFromSpiInterrupt but this time it invokes the first SPI transfer from the PIT callback function. In order to trigger a PIT interrupt, the timer is configured with a small interval and immediately disabled upon the first event.
Note that this test is only executed if the PIT module is actually implemented.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
PIT interrupt callback function for the SPI transfer from IRQ test.
The interrupt callback is invoked from the PIT module upon periodic timeout event. The callback is used by the SpiTransferFromPitInterrupt test to trigger the first SPI transfer from the interrupt callback context.
param | The abstract interrupt callback parameter. |
|
static |
SPI transfer from SPI interrupt callback test.
This test verifies the interrupt functionality of the SPI interface. The test verifies that an SPI transfer can be triggered from the SPI interrupt service routine context.
The test basically repeats the SpiConnectionTest but this time it invokes the second SPI transfer from the SPI callback function. A very common error is that the callback is invoked while the SPI module is still busy which does not allow to invoke another SPI transfer from the callback.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
SPI interrupt callback function for the SPI transfer from IRQ test.
The interrupt callback is invoked from the S2PI module upon finishing the SPI transfer. The callback is used by the SpiTransferFromSpiInterrupt test to trigger the second SPI transfer from the interrupt callback context.
status | The S2PI module status passed to the callback. |
param | The abstract interrupt callback parameter. |
param
is NULL.SPI interrupt callback function for the SPI transfer interrupt test.
The interrupt callback is invoked from the S2PI module upon finishing the SPI transfer. The callback is used by the SPITransferSync helper function to retrieve the status of the SPI transfer.
status | The S2PI module status passed to the callback. |
param | The abstract interrupt callback parameter. |
|
static |
Helper function for transfer data to SPI in blocking mode.
Calls the S2PI_TransferFrame function and waits until the transfer has been finished by checking the S2PI_GetStatus return code to become STATUS_IDLE (or STATUS_OK).
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
data | The data array to be transferred. |
size | The size of the data array to be transferred. |
|
static |
Plausibility Test for Timer HAL Implementation.
Rudimentary tests the lifetime counter (LTC) implementation. This verifies that the LTC is running by checking if the returned values of two consecutive calls to the Timer_GetCounterValue function are ascending. An artificial delay using the NOP operation is induced such that the timer is not read to fast.
|
static |
Test for Timer HAL Implementation by comparing timings to the device.
The test verifies the timer HAL implementation by comparing the timings to the AFBR-S50 device as a reference. Therefore several measurement are executed on the device, each with a different averaging sample count. The elapsed time increases linearly with the number of averaging samples. In order to remove the time for software/setup, a linear regression fit is applied to the measurement results and only the slope is considered for the result. A delta of 102.4 microseconds per sample is expected. If the measured delta per sample is within an specified error range, the timer implementation is considered correct.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
|
static |
Wraparound Test for the Timer HAL Implementation.
The LTC values must wrap from 999999 µs to 0 µs and increase the seconds counter accordingly. This test verifies the correct wrapping by consecutively calling the Timer_GetCounterValue function until at least 2 wraparound events have been occurred.
|
static |
Triggers a measurement on the device with specified sample count.
The function triggers a measurement cycle on the device. A sample
count can be specified to setup individual number of digital averaging.
The measurement in triggered asynchronously without waiting for any event to finish.
slave | The S2PI slave parameter passed to the S2PI HAL functions. |
samples | The specified number of averaging samples for the measurement. |
callback | An optional SPI callback. |
callbackData | The optional callback data parameter. |
|
static |
Executes a series of tests in order to verify the HAL implementation.
See Argus_VerifyHALImplementation for details.
spi_slave | The SPI hardware slave. |