Estimating transmission time of a DecaWave DW1000 UWB transceiver frame

I like to share with you my C implementation for estimating the DecaWave transmission time because it has been created with help from the community and thus should be shared with it.

The DecaWave DW1000 is a versatile ultra-wideband transceiver that enables long range and fast communication. Due to its wide spectral width it is able to occupy a very narrow temporal with. Precise time-stamping then allows for estimating the time-of-flight which in turn can be used for determining the distance between two nodes.

Buy IEEE802.15.4-2011 UWB Compliant Wireless Transceiver Module at Amazon

When implementing this with a lot of nodes, strict timing becomes important. It is favorable to know the transmission time of a frame in advance such that the process of planning and sending a frame takes as little of time as possible.

After discussing some details with fellow DecaWave users I wrote a small C-function that is able to estimate the TX-time from the DecaWave configuration struct as used in their C API software. I would like to share this function here for others to use. If you notice any room for improvements, please let me know.

A typical frame consists of a preamble, a start-frame-delimiter (SFD), a PHY header (PHR) and data. The preamble and SFD together form the synchronization header (SHR). The time the first symbol launches from the antenna is the RMARKER. This is the event used for timestamping and scheduling. The function allows for computing only the time to the RMARKER such that a transmission with planned TX-time can be send as soon as possible. The SHR is followed by the PHR containing details about the remaining frame, it is 19 bits in length and embeds a 6 bit SECDED parity check. The PHR is followed by the data. Every block of 330 (or less) databits is accompanied by a block of 48 Reed-Solomon parity bits. If the frame adheres to the IEEE 802.15.4 MAC layer, the data part is started with a MAC header and ended with two CRC bytes.