21 #ifndef _DW1000_H_INCLUDED
22 #define _DW1000_H_INCLUDED
26 #define TIME_RES 0.000015650040064103
27 #define TIME_RES_INV 63897.6
33 #define IDLE_MODE 0x00
59 #define DIS_DRXB_BIT 12
60 #define DIS_STXP_BIT 18
61 #define HIRQ_POL_BIT 9
63 #define PHR_MODE_SUB 16
64 #define LEN_PHR_MODE_SUB 2
65 #define RXM110K_BIT 22
69 #define LEN_SYS_CTRL 4
74 #define WAIT4RESP_BIT 7
79 #define SYS_STATUS 0x0F
80 #define LEN_SYS_STATUS 5
87 #define LDEDONE_BIT 10
95 #define RFPLL_LL_BIT 24
96 #define CLKPLL_LL_BIT 25
100 #define SYS_MASK 0x0E
101 #define LEN_SYS_MASK 4
104 #define SYS_TIME 0x06
105 #define LEN_SYS_TIME LEN_STAMP
109 #define LEN_RX_TIME 14
110 #define RX_STAMP_SUB 0x00
111 #define FP_AMPL1_SUB 0x07
112 #define LEN_RX_STAMP LEN_STAMP
113 #define LEN_FP_AMPL1 2
116 #define RX_FQUAL 0x12
117 #define LEN_RX_FQUAL 8
118 #define FP_AMPL2_SUB 0x02
119 #define FP_AMPL3_SUB 0x04
120 #define LEN_FP_AMPL2 2
121 #define LEN_FP_AMPL3 2
125 #define LEN_TX_TIME 10
126 #define TX_STAMP_SUB 0
127 #define LEN_TX_STAMP LEN_STAMP
131 #define LEN_DX_TIME LEN_STAMP
134 #define TX_BUFFER 0x09
135 #define LEN_TX_BUFFER 1024
136 #define LEN_UWB_FRAMES 127
137 #define LEN_EXT_UWB_FRAMES 1023
140 #define RX_FINFO 0x10
141 #define LEN_RX_FINFO 4
144 #define RX_BUFFER 0x11
145 #define LEN_RX_BUFFER 1024
148 #define TX_FCTRL 0x08
149 #define LEN_TX_FCTRL 5
152 #define CHAN_CTRL 0x1F
153 #define LEN_CHAN_CTRL 4
158 #define OTP_ADDR_SUB 0x04
159 #define OTP_CTRL_SUB 0x06
160 #define OTP_RDAT_SUB 0x0A
161 #define LEN_OTP_ADDR 2
162 #define LEN_OTP_CTRL 2
163 #define LEN_OTP_RDAT 4
166 #define AGC_TUNE 0x23
167 #define AGC_TUNE1_SUB 0x04
168 #define AGC_TUNE2_SUB 0x0C
169 #define AGC_TUNE3_SUB 0x12
170 #define LEN_AGC_TUNE1 2
171 #define LEN_AGC_TUNE2 4
172 #define LEN_AGC_TUNE3 2
175 #define DRX_TUNE 0x27
176 #define DRX_TUNE0b_SUB 0x02
177 #define DRX_TUNE1a_SUB 0x04
178 #define DRX_TUNE1b_SUB 0x06
179 #define DRX_TUNE2_SUB 0x08
180 #define DRX_TUNE4H_SUB 0x26
181 #define LEN_DRX_TUNE0b 2
182 #define LEN_DRX_TUNE1a 2
183 #define LEN_DRX_TUNE1b 2
184 #define LEN_DRX_TUNE2 4
185 #define LEN_DRX_TUNE4H 2
189 #define LDE_CFG1_SUB 0x0806
190 #define LDE_RXANTD_SUB 0x1804
191 #define LDE_CFG2_SUB 0x1806
192 #define LDE_REPC_SUB 0x2804
193 #define LEN_LDE_CFG1 1
194 #define LEN_LDE_CFG2 2
195 #define LEN_LDE_REPC 2
196 #define LEN_LDE_RXANTD 2
199 #define TX_POWER 0x1E
200 #define LEN_TX_POWER 4
204 #define RF_RXCTRLH_SUB 0x0B
205 #define RF_TXCTRL_SUB 0x0C
206 #define LEN_RF_RXCTRLH 1
207 #define LEN_RF_TXCTRL 4
211 #define TC_PGDELAY_SUB 0x0B
212 #define LEN_TC_PGDELAY 1
216 #define FS_PLLCFG_SUB 0x07
217 #define FS_PLLTUNE_SUB 0x0B
218 #define LEN_FS_PLLCFG 4
219 #define LEN_FS_PLLTUNE 1
223 #define PMSC_CTRL0_SUB 0x00
224 #define LEN_PMSC_CTRL0 4
228 #define LEN_TX_ANTD 2
235 #include "../SPI/SPI.h"
253 static void begin(
int irq,
int rst);
261 static void begin(
int irq);
271 static void select(
int ss);
426 static void setData(byte data[],
unsigned int n);
427 static void setData(
const String& data);
428 static void getData(byte data[],
unsigned int n);
429 static void getData(String& data);
453 _handleError = handleError;
456 _handleSent = handleSent;
459 _handleReceived = handleReceived;
462 _handleReceiveFailed = handleReceiveFailed;
465 _handleReceiveTimeout = handleReceiveTimeout;
468 void (*handleReceiveTimestampAvailable)(
void)) {
469 _handleReceiveTimestampAvailable = handleReceiveTimestampAvailable;
516 static void getPrettyBytes(byte cmd, word offset,
char msgBuffer[],
unsigned int n);
517 static void getPrettyBytes(byte data[],
char msgBuffer[],
unsigned int n);
586 static unsigned int _ss;
587 static unsigned int _rst;
588 static unsigned int _irq;
591 static void (*_handleError)(void);
592 static void (*_handleSent)(void);
593 static void (*_handleReceived)(void);
594 static void (*_handleReceiveFailed)(void);
595 static void (*_handleReceiveTimeout)(void);
596 static void (*_handleReceiveTimestampAvailable)(void);
610 static byte _extendedFrameLength;
611 static byte _preambleCode;
612 static byte _channel;
613 static byte _preambleLength;
614 static byte _pulseFrequency;
615 static byte _dataRate;
616 static byte _pacSize;
620 static boolean _permanentReceive;
621 static boolean _frameCheck;
624 static int _deviceMode;
627 static void handleInterrupt();
631 static void setFrameFilter(
boolean val);
633 static void setDoubleBuffering(
boolean val);
635 static void useExtendedFrameLength(
boolean val);
637 static void waitForResponse(
boolean val);
643 static boolean isReceiveTimestampAvailable();
644 static boolean isTransmitDone();
645 static boolean isReceiveDone();
646 static boolean isReceiveFailed();
647 static boolean isReceiveTimeout();
648 static boolean isClockProblem();
651 static void clearInterrupts();
652 static void clearAllStatus();
653 static void clearReceiveStatus();
654 static void clearReceiveTimestampAvailableStatus();
655 static void clearTransmitStatus();
658 static void readSystemEventStatusRegister();
659 static void readSystemConfigurationRegister();
660 static void writeSystemConfigurationRegister();
661 static void readNetworkIdAndDeviceAddress();
662 static void writeNetworkIdAndDeviceAddress();
663 static void readSystemEventMaskRegister();
664 static void writeSystemEventMaskRegister();
665 static void readChannelControlRegister();
666 static void writeChannelControlRegister();
667 static void readTransmitFrameControlRegister();
668 static void writeTransmitFrameControlRegister();
671 static void enableClock(byte clock);
674 static void loadLDE();
677 static void readBytes(byte cmd, word offset, byte data[],
unsigned int n);
678 static void readBytesOTP(word address, byte data[]);
679 static void writeBytes(byte cmd, word offset, byte data[],
unsigned int n);
682 static void writeValueToBytes(byte data[],
long val,
unsigned int n);
685 static boolean getBit(byte data[],
unsigned int n,
unsigned int bit);
686 static void setBit(byte data[],
unsigned int n,
unsigned int bit,
boolean val);
690 static const byte WRITE = 0x80;
691 static const byte WRITE_SUB = 0xC0;
692 static const byte READ = 0x00;
693 static const byte READ_SUB = 0x40;
696 static const byte AUTO_CLOCK = 0x00;
697 static const byte XTI_CLOCK = 0x01;
698 static const byte PLL_CLOCK = 0x02;
701 static const SPISettings _fastSPI;
702 static const SPISettings _slowSPI;
703 static const SPISettings* _currentSPI;
static const byte CHANNEL_3
Definition: DW1000.h:548
#define LEN_TX_FCTRL
Definition: DW1000.h:149
static void setDataRate(byte rate)
Definition: DW1000.cpp:862
static void getPrintableNetworkIdAndShortAddress(char msgBuffer[])
Definition: DW1000.cpp:607
static void suppressFrameCheck(boolean val)
Definition: DW1000.cpp:836
static float getNoiseValue()
Definition: DW1000.cpp:1137
static const byte FRAME_LENGTH_EXTENDED
Definition: DW1000.h:573
static void interruptOnReceiveFailed(boolean val)
Definition: DW1000.cpp:741
static void getSystemTimestamp(DW1000Time &time)
Definition: DW1000.cpp:1042
static const byte MODE_SHORTDATA_FAST_ACCURACY[]
Definition: DW1000.h:580
static const byte PREAMBLE_CODE_16MHZ_1
Definition: DW1000.h:554
static void newReceive()
Definition: DW1000.cpp:771
static const byte PREAMBLE_CODE_16MHZ_7
Definition: DW1000.h:560
static void attachErrorHandler(void(*handleError)(void))
Definition: DW1000.h:452
static const byte PREAMBLE_CODE_16MHZ_2
Definition: DW1000.h:555
static void begin(int irq, int rst)
Definition: DW1000.cpp:123
static const byte PREAMBLE_CODE_16MHZ_5
Definition: DW1000.h:558
static void startReceive()
Definition: DW1000.cpp:778
static void getReceiveTimestamp(DW1000Time &time)
Definition: DW1000.cpp:1036
static void setPulseFrequency(byte freq)
Definition: DW1000.cpp:887
static void getPrintableDeviceIdentifier(char msgBuffer[])
Definition: DW1000.cpp:593
static const byte CHANNEL_7
Definition: DW1000.h:551
static const byte PREAMBLE_CODE_64MHZ_19
Definition: DW1000.h:568
static const byte CHANNEL_2
Definition: DW1000.h:547
static void newConfiguration()
Definition: DW1000.cpp:805
static void getPrettyBytes(byte cmd, word offset, char msgBuffer[], unsigned int n)
Definition: DW1000.cpp:1354
static const byte PREAMBLE_CODE_64MHZ_11
Definition: DW1000.h:564
static const byte PAC_SIZE_32
Definition: DW1000.h:542
static void getPrintableDeviceMode(char msgBuffer[])
Definition: DW1000.cpp:614
static void interruptOnSent(boolean val)
Definition: DW1000.cpp:732
static const byte TX_PULSE_FREQ_16MHZ
Definition: DW1000.h:526
static void receivePermanently(boolean val)
Definition: DW1000.cpp:918
static DW1000Time setDelay(const DW1000Time &delay)
Definition: DW1000.cpp:840
static void softReset()
Definition: DW1000.cpp:200
static void setData(byte data[], unsigned int n)
Definition: DW1000.cpp:963
static void interruptOnReceiveTimestampAvailable(boolean val)
Definition: DW1000.cpp:752
static void reset()
Definition: DW1000.cpp:187
static const byte PREAMBLE_CODE_64MHZ_12
Definition: DW1000.h:565
static const byte TX_PREAMBLE_LEN_2048
Definition: DW1000.h:536
static const byte TX_PREAMBLE_LEN_256
Definition: DW1000.h:532
#define LEN_SYS_STATUS
Definition: DW1000.h:80
static const byte PREAMBLE_CODE_64MHZ_9
Definition: DW1000.h:562
static const byte TX_PREAMBLE_LEN_512
Definition: DW1000.h:533
static void attachReceivedHandler(void(*handleReceived)(void))
Definition: DW1000.h:458
static const byte PAC_SIZE_16
Definition: DW1000.h:541
static void attachReceiveFailedHandler(void(*handleReceiveFailed)(void))
Definition: DW1000.h:461
static void attachReceiveTimestampAvailableHandler(void(*handleReceiveTimestampAvailable)(void))
Definition: DW1000.h:467
static void interruptOnReceived(boolean val)
Definition: DW1000.cpp:736
static void attachSentHandler(void(*handleSent)(void))
Definition: DW1000.h:455
static void select(int ss)
Definition: DW1000.cpp:81
static const byte CHANNEL_1
Definition: DW1000.h:546
static float getFirstPathPower()
Definition: DW1000.cpp:1142
static void setDeviceAddress(unsigned int val)
Definition: DW1000.cpp:711
DW1000Class DW1000
Definition: DW1000.cpp:24
static const byte TX_PULSE_FREQ_64MHZ
Definition: DW1000.h:527
#define LEN_SYS_CFG
Definition: DW1000.h:57
static const byte PREAMBLE_CODE_16MHZ_4
Definition: DW1000.h:557
static void commitConfiguration()
Definition: DW1000.cpp:814
static const byte TX_PREAMBLE_LEN_4096
Definition: DW1000.h:537
static void getPrintableExtendedUniqueIdentifier(char msgBuffer[])
Definition: DW1000.cpp:600
static void setChannel(byte channel)
Definition: DW1000.cpp:927
static const byte MODE_LONGDATA_FAST_LOWPOWER[]
Definition: DW1000.h:579
Definition: DW1000Time.h:38
static void newTransmit()
Definition: DW1000.cpp:784
static float getReceivePower()
Definition: DW1000.cpp:1132
static const byte FRAME_LENGTH_NORMAL
Definition: DW1000.h:572
static const byte PREAMBLE_CODE_16MHZ_8
Definition: DW1000.h:561
static const byte PREAMBLE_CODE_64MHZ_10
Definition: DW1000.h:563
static const byte TRX_RATE_110KBPS
Definition: DW1000.h:520
static void attachReceiveTimeoutHandler(void(*handleReceiveTimeout)(void))
Definition: DW1000.h:464
static void interruptOnAutomaticAcknowledgeTrigger(boolean val)
Definition: DW1000.cpp:756
static const byte TRX_RATE_850KBPS
Definition: DW1000.h:521
static const byte TRX_RATE_6800KBPS
Definition: DW1000.h:522
#define LEN_PANADR
Definition: DW1000.h:53
static void interruptOnReceiveTimeout(boolean val)
Definition: DW1000.cpp:748
static const byte PREAMBLE_CODE_64MHZ_18
Definition: DW1000.h:567
static const byte TX_PREAMBLE_LEN_1024
Definition: DW1000.h:534
static unsigned int getDataLength()
Definition: DW1000.cpp:988
static void idle()
Definition: DW1000.cpp:764
static void getTransmitTimestamp(DW1000Time &time)
Definition: DW1000.cpp:1030
static void setInterruptPolarity(boolean val)
Definition: DW1000.cpp:724
static const byte CHANNEL_4
Definition: DW1000.h:549
static void setDefaults()
Definition: DW1000.cpp:942
static const byte PREAMBLE_CODE_16MHZ_6
Definition: DW1000.h:559
static const byte MODE_LONGDATA_FAST_ACCURACY[]
Definition: DW1000.h:581
static void getData(byte data[], unsigned int n)
Definition: DW1000.cpp:1005
static const byte PREAMBLE_CODE_64MHZ_17
Definition: DW1000.h:566
static const byte TX_PREAMBLE_LEN_1536
Definition: DW1000.h:535
static const byte PREAMBLE_CODE_16MHZ_3
Definition: DW1000.h:556
static void setPreambleLength(byte prealen)
Definition: DW1000.cpp:896
static void setReceiverAutoReenable(boolean val)
Definition: DW1000.cpp:728
static const byte PAC_SIZE_8
Definition: DW1000.h:540
static const byte CHANNEL_5
Definition: DW1000.h:550
#define LEN_SYS_MASK
Definition: DW1000.h:101
static void end()
Definition: DW1000.cpp:77
static const byte TX_PREAMBLE_LEN_64
Definition: DW1000.h:530
static void enableMode(const byte mode[])
Definition: DW1000.cpp:215
#define LEN_CHAN_CTRL
Definition: DW1000.h:153
static void reselect(int ss)
Definition: DW1000.cpp:113
static const byte TX_PREAMBLE_LEN_128
Definition: DW1000.h:531
static const byte MODE_LONGDATA_RANGE_LOWPOWER[]
Definition: DW1000.h:577
static void startTransmit()
Definition: DW1000.cpp:791
static const byte MODE_LONGDATA_RANGE_ACCURACY[]
Definition: DW1000.h:582
static const byte MODE_SHORTDATA_FAST_LOWPOWER[]
Definition: DW1000.h:578
#define LEN_SYS_CTRL
Definition: DW1000.h:69
static const byte PREAMBLE_CODE_64MHZ_20
Definition: DW1000.h:569
static void setPreambleCode(byte preacode)
Definition: DW1000.cpp:933
static const byte PAC_SIZE_64
Definition: DW1000.h:543
static void setNetworkId(unsigned int val)
Definition: DW1000.cpp:706