modm API documentation
modm::Dw3110Phy< SpiMaster, Cs > Class Template Reference

#include <modm/driver/radio/dw3110/dw3110_phy.hpp>

Inheritance diagram for modm::Dw3110Phy< SpiMaster, Cs >:
modm::SpiDevice< SpiMaster >

Public Types

enum  TXMode { Default, DefaultAndReceive, Force, ForceAndReceive }
 
enum  DelayTXMode {
  AtTime, AtTimeAndReceive, DelayWRTRX, DelayWRTRXAndReceive,
  DelayWRTTX, DelayWRTTXAndReceive, DelayWRTRef, DelayWRTRefAndReceive
}
 
enum  Error {
  None, DelayTooShort, ChannelBusy, TimedOut,
  PayloadTooLarge
}
 

Public Member Functions

void setChannel (Dw3110::Channel channel)
 Set the UWB channel used.
 
void setEnableLongFrames (bool value)
 
void setSendHeaderFast (bool value)
 
void setReceiveWaitTimeout (modm::chrono::micro_clock::duration duration)
 
void setReenableOnRxFailure (bool value)
 Set whether to stay in receive mode after receive failure.
 
void setCCATimeout (uint16_t timeout)
 
void setEnableFastTurnaround (bool value)
 
uint32_t readChipTime ()
 Read the value of the internal chip clock.
 
void setPreambleLength (Dw3110::PreambleLength len)
 
uint64_t getReceiveTimestamp ()
 
uint64_t getTransmitTimestamp ()
 Analogous to getReceiveTimestamp.
 
void setAcknowledgeTurnaround (uint8_t time)
 
void setWaitForResponseTime (modm::PreciseClock::duration time)
 
void setSFD (Dw3110::StartFrameDelimiter sfd)
 Set the start frame delimiter used by the chip.
 
void setPreambleCode (Dw3110::PreambleCode rx, Dw3110::PreambleCode tx)
 
uint64_t getDeviceUID ()
 Get devices unique id.
 
void setDeviceUID (uint64_t uid)
 Set devices unique id.
 
uint16_t getPanUID ()
 Get devices pan id.
 
uint16_t getShortUID ()
 Get devices short id.
 
void setPanUID (uint16_t pid)
 Set devices pan id.
 
void setShortUID (uint16_t pid)
 Set devices short id.
 
void setFrameFilterEnabled (bool value)
 Enable or disable the frame filtering.
 
Dw3110::FilterConfig_t getFilterConfig ()
 Get current filtering config.
 
void setFilterConfig (Dw3110::FilterConfig_t fc)
 Set frame filtering config.
 
void setAutoAckEnabled (bool value)
 
Dw3110::SystemState getChipState ()
 Read the reported state of the chip.
 
void setAntennaDelay (uint16_t delay)
 
uint16_t getRXAntennaDelay ()
 
uint16_t getTXAntennaDelay ()
 
float getReceiverClockOffset ()
 
bool calibrate ()
 
bool initialize (Dw3110::Channel channel=Dw3110::Channel::Channel5, Dw3110::PreambleCode pcode=Dw3110::PreambleCode::Code_64Mhz_9, Dw3110::PreambleLength plen=Dw3110::PreambleLength::Preamble_64, Dw3110::StartFrameDelimiter sfd=Dw3110::StartFrameDelimiter::IEEE802_15_4z_8)
 
bool startReceive ()
 Set the chip into receive mode.
 
bool packetReady ()
 Check if a packet has been successfully received.
 
bool isReceiving ()
 Check if the chip is currently in RX mode.
 
bool fetchPacket (std::span< uint8_t > payload, size_t &payload_len)
 
template<TXMode tmode = TXMode::Default>
Error transmit (const std::span< const uint8_t > payload, bool ranging=true, bool fast=true)
 
void setReferenceTime (uint32_t time)
 
template<DelayTXMode dmode = DelayTXMode::AtTime>
Error transmitDelayed (uint32_t time, const std::span< const uint8_t > payload, bool ranging=true, bool fast=true)
 
Dw3110::SystemStatus_t getStatus ()
 Read the current system status register.
 
void clearStatusBits (Dw3110::SystemStatus_t mask)
 Clear the given bits in the status register.
 
void setInterruptsEnabled (Dw3110::SystemStatus_t mask)
 
void setIRQPolarity (bool high)
 
bool setSTSLength (uint8_t len)
 
void setSTSMode (Dw3110::STSMode mode, bool sdc)
 
uint16_t getSTSQuality ()
 Return the 12-bit quality assessment of the last received STS.
 
bool getSTSGood ()
 Return whether or not the STS quality is in an acceptable range.
 
void setSTSKey (std::span< const uint8_t, 16 > key)
 
void setSTSIV (std::span< const uint8_t, 16 > iv)
 
void getSTSKey (std::span< uint8_t, 16 > key)
 Get the Key to use for AES generation of the STS.
 
void getSTSIV (std::span< uint8_t, 16 > iv)
 
uint32_t getCurrentCounter ()
 Get lower 32 bits of the currently used STS IV.
 
void reloadSTSIV ()
 Reload the STS IV from the STSIV registers.
 
void reuseLastSTSIV ()
 Don't increment the STS IV for the next RX/TX.
 
void attachConfigurationHandler (Spi::ConfigurationHandler handler)
 

Protected Member Functions

template<modm::Dw3110::FastCommand Cmd>
Error transmitGeneric (std::span< const uint8_t > payload, bool ranging, bool fast)
 
void loadOTP ()
 
bool checkDevID ()
 Check the device ID over SPI.
 
template<Dw3110::FastCommand Cmd>
void sendCommand ()
 Send a command to the chip.
 
void setRX_SFD_TOC ()
 Recompute the SFD TOC.
 
void fetchSystemStatus ()
 Update the local system_status variable.
 
void fetchChipState ()
 Update the local chip_state variable.
 
Error checkTXFailed ()
 
template<Dw3110::OTPAddr Addr>
void readOTPMemory (std::span< uint8_t, 4 > out)
 Read a variable from the OTP memory.
 
template<Dw3110::Register Reg, size_t Len, size_t Offset = 0>
void readRegister (std::span< uint8_t, Len > out)
 Read a variable from a register.
 
template<Dw3110::RegisterBank Reg>
void readRegisterBank (std::span< uint8_t > out, size_t len)
 
template<Dw3110::Register Reg, size_t Len, size_t Offset = 0>
void writeRegister (std::span< const uint8_t, Len > val)
 Write a variable to a register.
 
template<Dw3110::Register Reg, size_t Len, size_t Offset = 0>
void readModifyWriteRegister (std::span< const uint8_t, Len > or_mask, std::span< const uint8_t, Len > and_mask)
 
template<Dw3110::Register Reg, size_t Len, size_t Offset = 0>
void writeRegisterMasked (std::span< const uint8_t, Len > or_mask, std::span< const uint8_t, Len > and_mask)
 Do not use to clear "write 1 to clear" bits (2.3.1.2 Table 3)
 
template<Dw3110::RegisterBank Reg>
void writeRegisterBank (std::span< const uint8_t > val, size_t len)
 
bool acquireMaster ()
 
bool releaseMaster ()
 

Static Protected Member Functions

template<TXMode mode>
static consteval modm::Dw3110::FastCommand txModeToCmd ()
 
template<DelayTXMode dmode>
static consteval modm::Dw3110::FastCommand txModeToCmdDelay ()
 

Detailed Description

template<typename SpiMaster, typename Cs>
class modm::Dw3110Phy< SpiMaster, Cs >

Hardware abstraction layer for DW3110
Unsupported Features: AES encryption, Double buffering, GPIO, Temperature and Voltage, Pulse Generator calibration, RX antenna delay temp compensation, Soft reset, Sleep, Sniff mode

Author
Elias H.
Raphael Lehmann
Michael Jossen

Member Function Documentation

template<typename SpiMaster , typename Cs >
bool modm::Dw3110Phy< SpiMaster, Cs >::calibrate ( )

Runs the RX calibration.
Needs to be done after startup, wake and after 20C temperature change
Needs to be run when chip is in IDLE_PLL state
Automatically run by initialize()

template<typename SpiMaster , typename Cs >
Error modm::Dw3110Phy< SpiMaster, Cs >::checkTXFailed ( )
protected

Due to an errata the check is a bit more complicated
Relies on system_status and chip_state being up to date

template<typename SpiMaster , typename Cs >
bool modm::Dw3110Phy< SpiMaster, Cs >::fetchPacket ( std::span< uint8_t >  payload,
size_t &  payload_len 
)

Copy received packet into the provided payload buffer, clear packet received flags

Parameters
payloadRegion of memory the payload will be written to
payload_lenContains the length of the received payload
template<typename SpiMaster , typename Cs >
float modm::Dw3110Phy< SpiMaster, Cs >::getReceiverClockOffset ( )

Get the Clock offset multiplier for the received packet
Can be used to recover the clock drift compared to a packets sender
Unit is in parts per million (ppm)

template<typename SpiMaster , typename Cs >
uint64_t modm::Dw3110Phy< SpiMaster, Cs >::getReceiveTimestamp ( )

Get the timestamp of the last arrived packet.
This timestamp already has various correction factors applied to it.
It is given in ~15.65 picoseconds per unit

template<typename SpiMaster , typename Cs >
uint16_t modm::Dw3110Phy< SpiMaster, Cs >::getRXAntennaDelay ( )

Get the currently programmed RX antenna delay
Unit is approx 15.65ps

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::getSTSIV ( std::span< uint8_t, 16 >  iv)

Get the IV to use for AES generation of the STS

Warning
Will only return the programmed IV, to get the incremented value use getCurrentCounter()
template<typename SpiMaster , typename Cs >
uint16_t modm::Dw3110Phy< SpiMaster, Cs >::getTXAntennaDelay ( )

Get the currently programmed TX antenna delay
Unit is approx 15.65ps

template<typename SpiMaster , typename Cs >
bool modm::Dw3110Phy< SpiMaster, Cs >::initialize ( Dw3110::Channel  channel = Dw3110::Channel::Channel5,
Dw3110::PreambleCode  pcode = Dw3110::PreambleCode::Code_64Mhz_9,
Dw3110::PreambleLength  plen = Dw3110::PreambleLength::Preamble_64,
Dw3110::StartFrameDelimiter  sfd = Dw3110::StartFrameDelimiter::IEEE802_15_4z_8 
)

Initialize the DW3000, make ready to receive/transmit
Call ideally after the IRQ Pin has gone high, signalling SPIRDY

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::loadOTP ( )
protected

Only load configuration independent stuff, everything else should be initialized when changing those parts

template<typename SpiMaster , typename Cs >
template<Dw3110::Register Reg, size_t Len, size_t Offset = 0>
void modm::Dw3110Phy< SpiMaster, Cs >::readModifyWriteRegister ( std::span< const uint8_t, Len >  or_mask,
std::span< const uint8_t, Len >  and_mask 
)
protected

Simple implementation of read modify write using and and or masks
Use on registers that do not support native write register masked

template<typename SpiMaster , typename Cs >
template<Dw3110::RegisterBank Reg>
void modm::Dw3110Phy< SpiMaster, Cs >::readRegisterBank ( std::span< uint8_t >  out,
size_t  len 
)
protected

Read a number of bytes from a register bank, useful for RX buffers and other large read transfers

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setAcknowledgeTurnaround ( uint8_t  time)

Set the time between RX of a packet and the TX of the acknowledgement
Specified in number of preamble symbols, so time depends on the PRF

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setAntennaDelay ( uint16_t  delay)

Set both the RX and TX antenna delay
Unit is approx 15.65ps

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setAutoAckEnabled ( bool  value)

Enable auto acknowledgment
Will automatically respond to valid 802.5.14 Frames with the ACK request bit set
Only active when Frame filtering is enabled

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setCCATimeout ( uint16_t  timeout)

Set the time spent listening for competing transmissions on CCA commands
Unit is in counts of PAC symbols

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setEnableFastTurnaround ( bool  value)

Enable a faster TX/RX turnaround.
The Frame will be set ready before computation of ToA data has finished and any ACKs will be sent.
Time of Arrival may not be ready when the frame is made available

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setEnableLongFrames ( bool  value)

Change Header format to non-standard to allow 1021 Byte payloads instead of default 125

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setInterruptsEnabled ( Dw3110::SystemStatus_t  mask)

Set interrupt bits
Set on which status events the IRQ Pin of the chip should be pulled high
Interrupt condition can be cleared by clearing the corresponding status bit using clearStatusBits()
Polarity of the line can be changed with setIRQPolarity()

Warning
Dw3110::SystemStatus::IRQS will be ignored since it does not correspond to an interrupt
template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setIRQPolarity ( bool  high)

Set the polarity of the interrupt line
Default is active high

Parameters
highIf true sets the line to active high
template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setPreambleCode ( Dw3110::PreambleCode  rx,
Dw3110::PreambleCode  tx 
)

Set the preamble code used and looked for.

Warning
This implicitly sets the PRF as codes >8 use the 64MHz PRF instead of 16MHz
template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setPreambleLength ( Dw3110::PreambleLength  len)

Set the number of preamble symbols sent with each transmission
Each symbol takes ~1µs to send

Warning
While further fine tuning of preamble length is possible it is currently unsupported by this driver
template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setReceiveWaitTimeout ( modm::chrono::micro_clock::duration  duration)

Set the timeout to wait on arriving packets after startReceive()
0 = No Timeout
Register resolution is ~1µs

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setReferenceTime ( uint32_t  time)

Set the reference time value
Used as the reference in transmitDelayed() when using DelayTXMode::DelayWRTRef and DelayTXMode::DelayWRTRefAndReceive

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setSendHeaderFast ( bool  value)

Send the PHR at 6.8Mbps.
By default the PHR is always sent at 850kb/s

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setSTSIV ( std::span< const uint8_t, 16 >  iv)

Set the IV to use for AES generation of the STS
Ignored if SDC is set in setSTSMode()

template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setSTSKey ( std::span< const uint8_t, 16 >  key)

Set the Key to use for AES generation of the STS
Ignored if SDC is set in setSTSMode()

template<typename SpiMaster , typename Cs >
bool modm::Dw3110Phy< SpiMaster, Cs >::setSTSLength ( uint8_t  len)

Set the length of the generated Secure timestamp

Parameters
lenLength in units of 8 chips (~1µs), minimum supported is 32 chips(e.g a value of 3)
template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setSTSMode ( Dw3110::STSMode  mode,
bool  sdc 
)

Set the STS mode

Parameters
modeDefines where to place the STS inside the packet
sdcIf true IV and Key are ignored and a deterministic code is used
template<typename SpiMaster , typename Cs >
void modm::Dw3110Phy< SpiMaster, Cs >::setWaitForResponseTime ( modm::PreciseClock::duration  time)

Set the time between a transmission and the start of RX on any of the RX after TX commands
This can be used to delay turning on of the receiver after transmission to save on power.

template<typename SpiMaster , typename Cs >
template<TXMode tmode = TXMode::Default>
Error modm::Dw3110Phy< SpiMaster, Cs >::transmit ( const std::span< const uint8_t >  payload,
bool  ranging = true,
bool  fast = true 
)

Transmit a given package using the current configuration using a given transmission mode

Parameters
payloadSpan to the desired payload
rangingDecides whether or not to set the ranging bit in the header
fastDecides if the data portion is sent at 850kbps or 6.8Mbps
template<typename SpiMaster , typename Cs >
template<DelayTXMode dmode = DelayTXMode::AtTime>
Error modm::Dw3110Phy< SpiMaster, Cs >::transmitDelayed ( uint32_t  time,
const std::span< const uint8_t >  payload,
bool  ranging = true,
bool  fast = true 
)

Transmit a given package using the current configuration using a given delayed transmission mode

Parameters
payloadSpan to the desired payload
rangingDecides whether or not to set the ranging bit in the header
fastDecides if the data portion is sent at 850kbps or 6.8Mbps
timeEither the transmission time or a delay in units of 4ns dependent on the DelayTXMode provided
Warning
This transmission mode does not respect the clear channel assessment
template<typename SpiMaster , typename Cs >
template<modm::Dw3110::FastCommand Cmd>
Error modm::Dw3110Phy< SpiMaster, Cs >::transmitGeneric ( std::span< const uint8_t >  payload,
bool  ranging,
bool  fast 
)
protected

Transmit a given package using the current configuration and a specific command

Parameters
payloadSpan to the desired payload
rangingDecides whether or not to set the ranging bit in the header
fastDecides if the data portion is sent at 850kbps or 6.8Mbps command
template<typename SpiMaster , typename Cs >
template<Dw3110::RegisterBank Reg>
void modm::Dw3110Phy< SpiMaster, Cs >::writeRegisterBank ( std::span< const uint8_t >  val,
size_t  len 
)
protected

Write a number of bytes to a register bank, useful for TX buffers and other large write transfers


The documentation for this class was generated from the following file: