# Time of Flight

The time of flight module is designed to enable measurement of the time it takes for certain operations to complete, especially RF operations. The time of flight module accomplishes this measurement by implementing a 20-bit counter that counts SYSCLK cycles; therefore, the resolution and accuracy is determined by the SYSCLK and the TOF_CFG_CLK_PRESCALE field of the TOF_CFG register. The TOF_CLK settings higher than 8 MHz have no practical value, as the radio interrupts are generated synchronously at 8 MHz. Care must be taken if the SYSCLK is not an even multiple of 8 MHz; for instance, if the internal RC oscillator is used as the SYSCLK. The TOF_CLK is determined by:

The timer can be started or stopped using software control via the TOF_CTRL_START and TOF_CTRL_STOP bits of the TOF_CTRL register. The starting and stopping of the timer can also be controlled in hardware by the radio frequency front end's interrupts. The available hardware interrupt triggers are as configured as the start or stop trigger in the TOF_CFG_START_SRC and TOF_CFG_STOP_SRC fields, respectively, of the TOF_CFG register. The hardware interrupts available are the interrupts generated by the radio

Once the timer has been started and is counting, the counter continues to increment internally and the the TOF_STATUS_BUSY bit of the TOF_STATUS register is set. Once a stop trigger occurs, the TOF_STATUS_BUSY bit is cleared and the TOF_DATA_REQ bit in the TOF_DATA register is set, indicating a new data sample is available in that register.

The time of flight module also has an averaging feature to increase accuracy. The averaging feature can be configured by the TOF_CFG_AVG_CFG field from the TOF_CFG register, for 1 to 128 samples. The default setting is to use 1 sample for the average data; therefore, no averaging is performed, and the data in the TOF_AVG_DATA register is the same as that in the TOF_DATA register. For cases where the TOF_CFG_AVG_CFG field from the TOF_CFG register is higher than 0 (more than 1 data point), the average is calculated from the number of samples specified, and the result is placed in the TOF_AVG_DATA register. The TOF_AVG_DATA register itself is split into two sections, the integer portion located in the TOF_AVG_DATA_AVG_DATA_INT field, and a decimal portion in the TOF_AVG_DATA_AVG_DATA_DEC field.

The module also selects the minimum and maximum data points from the dataset and places these in the TOF_MIN_DATA and TOF_MAX_DATA registers respectively.

The application can check the number of samples left before the sample is computed and available in the TOF_STATUS_AVG_DATA_STATUS bit of the TOF_STATUS register.

The TOF_STATUS_AVG_DATA_REQ bit from the TOF_STATUS register functions similarly to the TOF_STATU_DATA_REQ bit in the same register, in that the bit is set high when a new average data sample is ready.

The TOF_STATUS_AVG_DATA_CLEAR, TOF_STATUS_MAX_DATA_CLEAR and the TOF_STATUS_MIN_DATA_CLEAR bits from the TOF_STATUS register all clear their respective data registers. The TOF_STATUS_AVG_DATA_CLEAR bit has the extra function of restarting the average computation.

There are three bits in the TOF_STATUS register that indicate errors and are sticky bits:

TOF_STATUS_ERROR

Indicates that two start conditions have occurred in a row; can be cleared via the TOF_STATUS_ERROR_CLEAR bit from the TOF_STATUS register.

TOF_STATUS_AVG_DATA_OVERRUN

TOF_STATUS_DATA_OVERRUN

Indicates that two TOF_DATA samples have been calculated without being read; can be cleared via the TOF_STATUS_DATA_OVERRUN_CLEAR bit from the TOF_STATUS register.

The time of flight module has one interrupt that can be generated by 4 sources:

| • | Error state, enabled by the TOF_CFG_ERROR_INT_ENABLE bit from the TOF_CFG register

| • | Overrun state, enabled by the TOF_CFG_OVERRUN_INT_ENABLE bit from the TOF_CFG register

| • | Average data available in TOF_AVG_DATA, enabled by the TOF_CFG_AVG_DATA_INT_ENABLE bit from the TOF_CFG register

| • | Data available in TOF_DATA, enabled by the TOF_CFG_DATA_INT_ENABLE bit from the TOF_CFG register

The time of flight module can automatically transfer its data via the DMA (see Direct Memory Access (DMA) Controller) for configuring the DMA. One extra piece of configuration is required in the time of flight module for DMA transfers to work correctly. The TOF_CFG_AVG_DATA_DMA_ENABLE or TOF_CFG_DATA_DMA_ENABLE bits from the TOF_CFG register must be enabled to request DMA transfers whenever either TOF_AVG_DATA or TOF_DATA, respectively, is available.

The timer can be disabled by setting the TOF_CTRL_DISABLE bit or synchronously reset by setting the TOF_CTRL_RESET bit, both from the TOF_CTRL register.

| • | Disabling the timer resets all registers except the two configuration registers.

| • | Disabling has priority over any start condition.

| • | Resetting the timer synchronously resets all the registers to default value.

## BLE Link Filtering

The time of flight module also offers the ability to filter unwanted radio interrupts from the baseband, based on the link format and link label information read from the baseband. All control of this feature is available through the TOF_LINK_CFG register. The TOF_LINK_CFG_LINK_FILTER_EN bit from this register enables the filter. The TOF_LINK_CFG_LINK_LABEL and TOF_LINK_CFG_LINK_FORMAT fields must be filled with the label and format information that matches the data reported from the baseband. Notably, the bit positioning of the TOF_LINK_CFG_LINK_LABEL and TOF_LINK_CFG_LINK_FORMAT fields relative to the register is identical to that of the BBIF_STATUS_LINK_LABEL and BBIF_STATUS_LINK_FORMAT fields in the BBIF_STATUS register.

For registers, see Time of Flight Registers.