-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathdeca_device_api.h
executable file
·2039 lines (1872 loc) · 83.1 KB
/
deca_device_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*! ----------------------------------------------------------------------------
* @file deca_device_api.h
* @brief DW1000 API Functions
*
* @attention
*
* Copyright 2013 (c) Decawave Ltd, Dublin, Ireland.
*
* All rights reserved.
*
*/
#ifndef _DECA_DEVICE_API_H_
#define _DECA_DEVICE_API_H_
#ifdef __cplusplus
extern "C" {
#endif
#ifndef uint8
#ifndef _DECA_UINT8_
#define _DECA_UINT8_
typedef unsigned char uint8;
#endif
#endif
#ifndef uint16
#ifndef _DECA_UINT16_
#define _DECA_UINT16_
typedef unsigned short uint16;
#endif
#endif
#ifndef uint32
#ifndef _DECA_UINT32_
#define _DECA_UINT32_
typedef unsigned long uint32;
#endif
#endif
#ifndef int8
#ifndef _DECA_INT8_
#define _DECA_INT8_
typedef signed char int8;
#endif
#endif
#ifndef int16
#ifndef _DECA_INT16_
#define _DECA_INT16_
typedef signed short int16;
#endif
#endif
#ifndef int32
#ifndef _DECA_INT32_
#define _DECA_INT32_
typedef signed long int32;
#endif
#endif
#ifndef DWT_NUM_DW_DEV
#define DWT_NUM_DW_DEV (1)
#endif
#define DWT_SUCCESS (0)
#define DWT_ERROR (-1)
#define DWT_TIME_UNITS (1.0/499.2e6/128.0) //!< = 15.65e-12 s
#define DWT_DEVICE_ID (0xDECA0130) //!< DW1000 MP device ID
//! constants for selecting the bit rate for data TX (and RX)
//! These are defined for write (with just a shift) the TX_FCTRL register
#define DWT_BR_110K 0 //!< UWB bit rate 110 kbits/s
#define DWT_BR_850K 1 //!< UWB bit rate 850 kbits/s
#define DWT_BR_6M8 2 //!< UWB bit rate 6.8 Mbits/s
//! constants for specifying the (Nominal) mean Pulse Repetition Frequency
//! These are defined for direct write (with a shift if necessary) to CHAN_CTRL and TX_FCTRL regs
#define DWT_PRF_16M 1 //!< UWB PRF 16 MHz
#define DWT_PRF_64M 2 //!< UWB PRF 64 MHz
//! constants for specifying Preamble Acquisition Chunk (PAC) Size in symbols
#define DWT_PAC8 0 //!< PAC 8 (recommended for RX of preamble length 128 and below
#define DWT_PAC16 1 //!< PAC 16 (recommended for RX of preamble length 256
#define DWT_PAC32 2 //!< PAC 32 (recommended for RX of preamble length 512
#define DWT_PAC64 3 //!< PAC 64 (recommended for RX of preamble length 1024 and up
//! constants for specifying TX Preamble length in symbols
//! These are defined to allow them be directly written into byte 2 of the TX_FCTRL register
//! (i.e. a four bit value destined for bits 20..18 but shifted left by 2 for byte alignment)
#define DWT_PLEN_4096 0x0C //! Standard preamble length 4096 symbols
#define DWT_PLEN_2048 0x28 //! Non-standard preamble length 2048 symbols
#define DWT_PLEN_1536 0x18 //! Non-standard preamble length 1536 symbols
#define DWT_PLEN_1024 0x08 //! Standard preamble length 1024 symbols
#define DWT_PLEN_512 0x34 //! Non-standard preamble length 512 symbols
#define DWT_PLEN_256 0x24 //! Non-standard preamble length 256 symbols
#define DWT_PLEN_128 0x14 //! Non-standard preamble length 128 symbols
#define DWT_PLEN_64 0x04 //! Standard preamble length 64 symbols
#define DWT_SFDTOC_DEF 0x1041 // default SFD timeout value
#define DWT_PHRMODE_STD 0x0 // standard PHR mode
#define DWT_PHRMODE_EXT 0x3 // DW proprietary extended frames PHR mode
// Defined constants for "mode" bitmask parameter passed into dwt_starttx() function.
#define DWT_START_TX_IMMEDIATE 0
#define DWT_START_TX_DELAYED 1
#define DWT_RESPONSE_EXPECTED 2
#define DWT_START_RX_IMMEDIATE 0
#define DWT_START_RX_DELAYED 1 // Set up delayed RX, if "late" error triggers, then the RX will be enabled immediately
#define DWT_IDLE_ON_DLY_ERR 2 // If delayed RX failed due to "late" error then if this
// flag is set the RX will not be re-enabled immediately, and device will be in IDLE when function exits
#define DWT_NO_SYNC_PTRS 4 // Do not try to sync IC side and Host side buffer pointers when enabling RX. This is used to perform manual RX
// re-enabling when receiving a frame in double buffer mode.
// Defined constants for "mode" bit field parameter passed to dwt_setleds() function.
#define DWT_LEDS_DISABLE 0x00
#define DWT_LEDS_ENABLE 0x01
#define DWT_LEDS_INIT_BLINK 0x02
// Defined constants for "lna_pa" bit field parameter passed to dwt_setlnapamode() function
#define DWT_LNA_PA_DISABLE 0x00
#define DWT_LNA_ENABLE 0x01
#define DWT_PA_ENABLE 0x02
//frame filtering configuration options
#define DWT_FF_NOTYPE_EN 0x000 // no frame types allowed (FF disabled)
#define DWT_FF_COORD_EN 0x002 // behave as coordinator (can receive frames with no dest address (PAN ID has to match))
#define DWT_FF_BEACON_EN 0x004 // beacon frames allowed
#define DWT_FF_DATA_EN 0x008 // data frames allowed
#define DWT_FF_ACK_EN 0x010 // ack frames allowed
#define DWT_FF_MAC_EN 0x020 // mac control frames allowed
#define DWT_FF_RSVD_EN 0x040 // reserved frame types allowed
//DW1000 interrupt events
#define DWT_INT_TFRS 0x00000080 // frame sent
#define DWT_INT_LDED 0x00000400 // micro-code has finished execution
#define DWT_INT_RFCG 0x00004000 // frame received with good CRC
#define DWT_INT_RPHE 0x00001000 // receiver PHY header error
#define DWT_INT_RFCE 0x00008000 // receiver CRC error
#define DWT_INT_RFSL 0x00010000 // receiver sync loss error
#define DWT_INT_RFTO 0x00020000 // frame wait timeout
#define DWT_INT_RXOVRR 0x00100000 // receiver overrun
#define DWT_INT_RXPTO 0x00200000 // preamble detect timeout
#define DWT_INT_GPIO 0x00400000 // GPIO interrupt
#define DWT_INT_SFDT 0x04000000 // SFD timeout
#define DWT_INT_ARFE 0x20000000 // frame rejected (due to frame filtering configuration)
//DW1000 SLEEP and WAKEUP configuration parameters
#define DWT_PRESRV_SLEEP 0x0100 // PRES_SLEEP - on wakeup preserve sleep bit
#define DWT_LOADOPSET 0x0080 // ONW_L64P - on wakeup load operating parameter set for 64 PSR
#define DWT_CONFIG 0x0040 // ONW_LDC - on wakeup restore (load) the saved configurations (from AON array into HIF)
#define DWT_LOADEUI 0x0008 // ONW_LEUI - on wakeup load EUI
#define DWT_RX_EN 0x0002 // ONW_RX - on wakeup activate reception
#define DWT_TANDV 0x0001 // ONW_RADC - on wakeup run ADC to sample temperature and voltage sensor values
#define DWT_XTAL_EN 0x10 // keep XTAL running during sleep
#define DWT_WAKE_SLPCNT 0x8 // wake up after sleep count
#define DWT_WAKE_CS 0x4 // wake up on chip select
#define DWT_WAKE_WK 0x2 // wake up on WAKEUP PIN
#define DWT_SLP_EN 0x1 // enable sleep/deep sleep functionality
//DWT_DW_POWER_ON should be used when dwt_initialise is called on cold power up of DW IC
//When DW IC is being initialised after wake up then some of the init steps can be skipped
//DW1000 INIT configuration parameters
#define DWT_LOADNONE 0x00 // no loading of micro-code or reading of OTP values
#define DWT_LOADUCODE 0x01 // this can be called on power up or after wake up to load ucode
#define DWT_DW_WAKE_UP 0x02 // init after wake up - will not load ucode / ucode will not run
#define DWT_DW_WUP_NO_UCODE 0x04 // init after wake up - ucode has not already been loaded / ucode is not used
#define DWT_DW_WUP_RD_OTPREV 0x08 // init after wakeup - read OTP rev after wake up
#define DWT_READ_OTP_PID 0x10 // read part ID from OTP
#define DWT_READ_OTP_LID 0x20 // read lot ID from OTP
#define DWT_READ_OTP_BAT 0x40 // read ref voltage from OTP
#define DWT_READ_OTP_TMP 0x80 // read ref temperature from OTP
//DW1000 OTP operating parameter set selection
#define DWT_OPSET_64LEN 0x0
#define DWT_OPSET_TIGHT 0x1
#define DWT_OPSET_DEFLT 0x2
//GPIOs
#define DWT_GxP0 0x00000001UL /* GPIO0 Only changed if the GxM0 mask bit has a value of 1 for the write operation*/
#define DWT_GxP1 0x00000002UL /* GPIO1.*/
#define DWT_GxP2 0x00000004UL /* GPIO2.*/
#define DWT_GxP3 0x00000008UL /* GPIO3.*/
#define DWT_GxP4 0x00000100UL /* GPIO4.*/
#define DWT_GxP5 0x00000200UL /* GPIO5.*/
#define DWT_GxP6 0x00000400UL /* GPIO6.*/
#define DWT_GxP7 0x00000800UL /* GPIO7.*/
#define DWT_GxP8 0x00010000UL /* GPIO8 */
#define DWT_GxM0 0x00000010UL /* Mask for GPIO0 */
#define DWT_GxM1 0x00000020UL /* Mask for GPIO1 */
#define DWT_GxM2 0x00000040UL /* Mask for GPIO2 */
#define DWT_GxM3 0x00000080UL /* Mask for GPIO3 */
#define DWT_GxM4 0x00001000UL /* Mask for GPIO4 */
#define DWT_GxM5 0x00002000UL /* Mask for GPIO5 */
#define DWT_GxM6 0x00004000UL /* Mask for GPIO6 */
#define DWT_GxM7 0x00008000UL /* Mask for GPIO7 */
#define DWT_GxM8 0x00100000UL /* Mask for GPIO8 */
// Call-back data RX frames flags
#define DWT_CB_DATA_RX_FLAG_RNG 0x1 // Ranging bit
// TX/RX call-back data
typedef struct
{
uint32 status; //initial value of register as ISR is entered
uint16 datalength; //length of frame
uint8 fctrl[2]; //frame control bytes
uint8 rx_flags; //RX frame flags, see above
} dwt_cb_data_t;
// Call-back type for all events
typedef void (*dwt_cb_t)(const dwt_cb_data_t *);
/*! ------------------------------------------------------------------------------------------------------------------
* Structure typedef: dwt_config_t
*
* Structure for setting device configuration via dwt_configure() function
*
*/
typedef struct
{
uint8 chan ; //!< channel number {1, 2, 3, 4, 5, 7 }
uint8 prf ; //!< Pulse Repetition Frequency {DWT_PRF_16M or DWT_PRF_64M}
uint8 txPreambLength ; //!< DWT_PLEN_64..DWT_PLEN_4096
uint8 rxPAC ; //!< Acquisition Chunk Size (Relates to RX preamble length)
uint8 txCode ; //!< TX preamble code
uint8 rxCode ; //!< RX preamble code
uint8 nsSFD ; //!< Boolean should we use non-standard SFD for better performance
uint8 dataRate ; //!< Data Rate {DWT_BR_110K, DWT_BR_850K or DWT_BR_6M8}
uint8 phrMode ; //!< PHR mode {0x0 - standard DWT_PHRMODE_STD, 0x3 - extended frames DWT_PHRMODE_EXT}
uint16 sfdTO ; //!< SFD timeout value (in symbols)
} dwt_config_t ;
typedef struct
{
uint8 PGdly;
//TX POWER
//31:24 BOOST_0.125ms_PWR
//23:16 BOOST_0.25ms_PWR-TX_SHR_PWR
//15:8 BOOST_0.5ms_PWR-TX_PHR_PWR
//7:0 DEFAULT_PWR-TX_DATA_PWR
uint32 power;
}
dwt_txconfig_t ;
typedef struct
{
uint16 maxNoise ; // LDE max value of noise
uint16 firstPathAmp1 ; // Amplitude at floor(index FP) + 1
uint16 stdNoise ; // Standard deviation of noise
uint16 firstPathAmp2 ; // Amplitude at floor(index FP) + 2
uint16 firstPathAmp3 ; // Amplitude at floor(index FP) + 3
uint16 maxGrowthCIR ; // Channel Impulse Response max growth CIR
uint16 rxPreamCount ; // Count of preamble symbols accumulated
uint16 firstPath ; // First path index (10.6 bits fixed point integer)
}dwt_rxdiag_t ;
typedef struct
{
//all of the below are mapped to a 12-bit register in DW1000
uint16 PHE ; //number of received header errors
uint16 RSL ; //number of received frame sync loss events
uint16 CRCG ; //number of good CRC received frames
uint16 CRCB ; //number of bad CRC (CRC error) received frames
uint16 ARFE ; //number of address filter errors
uint16 OVER ; //number of receiver overflows (used in double buffer mode)
uint16 SFDTO ; //SFD timeouts
uint16 PTO ; //Preamble timeouts
uint16 RTO ; //RX frame wait timeouts
uint16 TXF ; //number of transmitted frames
uint16 HPW ; //half period warn
uint16 TXW ; //power up warn
} dwt_deviceentcnts_t ;
/********************************************************************************************************************/
/* REMOVED API LIST */
/********************************************************************************************************************/
/*
* From version 5.0.0:
* - dwt_getinitxtaltrim: Replaced by the function dwt_getxtaltrim which returns current xtal trim value
*
* From version 4.0.0:
* - dwt_setGPIOforEXTTRX: Replaced by dwt_setlnapamode to get equivalent functionality.
* - dwt_setGPIOdirection: Renamed to dwt_setgpiodirection.
* - dwt_setGPIOvalue: Renamed to dwt_setgpiovalue.
* - dwt_setrxmode: Replaced by dwt_setsniffmode and dwt_setlowpowerlistening depending on the RX mode the user
* wants to set up.
* - dwt_checkoverrun: As automatic RX re-enabling is not supported anymore, this functions has become useless.
* - dwt_setautorxreenable: As automatic RX re-enabling is not supported anymore, this functions has become
* useless.
* - dwt_getrangebias: Range bias correction values are platform dependent and should therefore be managed at user
* application level.
* - dwt_xtaltrim: Renamed to dwt_setxtaltrim.
* - dwt_checkIRQ: Renamed to dwt_checkirq.
*
* From version 3.0.0:
* - dwt_getldotune: As LDO loading is now automatically managed by the driver, this function has become useless.
* - dwt_getotptxpower: TX power values and location in OTP memory are platform dependent and should therefore be
* managed at user application level.
* - dwt_readantennadelay: Antenna delay values and location in OTP memory are platform dependent and should
* therefore be managed at user application level.
* - dwt_readdignostics: Renamed to dwt_readdiagnostics.
*/
/********************************************************************************************************************/
/* API LIST */
/********************************************************************************************************************/
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_apiversion()
*
* @brief This function returns the version of the API as defined by DW1000_DRIVER_VERSION
*
* input parameters
*
* output parameters
*
* returns version (DW1000_DRIVER_VERSION)
*/
int32 dwt_apiversion(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setlocaldataptr()
*
* @brief This function sets the local data structure pointer to point to the element in the local array as given by the index.
*
* input parameters
* @param index - selects the array element to point to. Must be within the array bounds, i.e. < DWT_NUM_DW_DEV
*
* output parameters
*
* returns DWT_SUCCESS for success, or DWT_ERROR for error
*/
int dwt_setlocaldataptr(unsigned int index);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_geticrefvolt()
*
* @brief This is used to return the read V measured @ 3.3 V value recorded in OTP address 0x8 (VBAT_ADDRESS)
*
* NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
*
* input parameters
*
* output parameters
*
* returns the 8 bit V meas value as programmed in the factory
*/
uint8 dwt_geticrefvolt(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_geticreftemp()
*
* @brief This is used to return the read T measured @ 23 C value recorded in OTP address 0x9 (VTEMP_ADDRESS)
*
* NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
*
* input parameters
*
* output parameters
*
* returns the 8 bit T meas value as programmed in the factory
*/
uint8 dwt_geticreftemp(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_getpartid()
*
* @brief This is used to return the read part ID (or chip ID) of the device
*
* NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value (stored in OTP).
*
* input parameters
*
* output parameters
*
* returns the 32 bit part ID (or chip ID) value as programmed in the factory
*/
uint32 dwt_getpartid(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_getlotid()
*
* @brief This is used to return the read lot ID of the device
*
* NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
*
* input parameters
*
* output parameters
*
* returns the 32 bit lot ID value as programmed in the factory
*/
uint32 dwt_getlotid(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readdevid()
*
* @brief This is used to return the read device type and revision information of the DW1000 device (MP part is 0xDECA0130)
*
* input parameters
*
* output parameters
*
* returns the read value which for DW1000 is 0xDECA0130
*/
uint32 dwt_readdevid(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_otprevision()
*
* @brief This is used to return the read OTP revision
*
* NOTE: dwt_initialise() must be called prior to this function so that it can return a relevant value.
*
* input parameters
*
* output parameters
*
* returns the read OTP revision value
*/
uint8 dwt_otprevision(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setfinegraintxseq()
*
* @brief This function enables/disables the fine grain TX sequencing (enabled by default).
*
* input parameters
* @param enable - 1 to enable fine grain TX sequencing, 0 to disable it.
*
* output parameters none
*
* no return value
*/
void dwt_setfinegraintxseq(int enable);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setlnapamode()
*
* @brief This is used to enable GPIO for external LNA or PA functionality - HW dependent, consult the DW1000 User Manual.
* This can also be used for debug as enabling TX and RX GPIOs is quite handy to monitor DW1000's activity.
*
* NOTE: Enabling PA functionality requires that fine grain TX sequencing is deactivated. This can be done using
* dwt_setfinegraintxseq().
*
* input parameters
* @param lna_pa - bit field: bit 0 if set will enable LNA functionality,
* : bit 1 if set will enable PA functionality,
* : to disable LNA/PA set the bits to 0
* output parameters
*
* no return value
*/
void dwt_setlnapamode(int lna_pa);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_enablegpioclocks()
*
* @brief This is used to senable GPIO clocks. The clocks are needed to ensure correct GPIO operation
*
* input parameters
*
* output parameters
*
* no return value
*/
void dwt_enablegpioclocks(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setgpiodirection()
*
* @brief This is used to set GPIO direction as an input (1) or output (0)
*
* input parameters
* @param gpioNum - this is the GPIO to configure - see GxM0... GxM8 in the deca_regs.h file
* @param direction - this sets the GPIO direction - see GxP0... GxP8 in the deca_regs.h file
*
* output parameters
*
* no return value
*/
void dwt_setgpiodirection(uint32 gpioNum, uint32 direction);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setgpiovalue()
*
* @brief This is used to set GPIO value as (1) or (0) only applies if the GPIO is configured as output
*
* input parameters
* @param gpioNum - this is the GPIO to configure - see GxM0... GxM8 in the deca_regs.h file
* @param value - this sets the GPIO value - see GDP0... GDP8 in the deca_regs.h file
*
* output parameters
*
* no return value
*/
void dwt_setgpiovalue(uint32 gpioNum, uint32 value);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_getgpiovalue()
*
* @brief This is used to get GPIO value, returns (1) or (0) depending if the GPIO is high or low
*
* input parameters
* @param gpioNum - this is the GPIO to configure - see DWT_GxP0... DWT_GxP8
*
* output parameters
*
* return int (1 or 0)
*/
int dwt_getgpiovalue(uint32 gpioNum);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_initialise()
*
* @brief This function initiates communications with the DW1000 transceiver
* and reads its DEV_ID register (address 0x00) to verify the IC is one supported
* by this software (e.g. DW1000 32-bit device ID value is 0xDECA0130). Then it
* does any initial once only device configurations needed for its use and initialises
* as necessary any static data items belonging to this low-level driver.
*
* This function does not need to be called after DW1000 device is woken up from DEEPSLEEP,
* the device will preserve register values e.g. LDO, UCODE, XTAL. However if needed this
* function can be called to initialise internal structure dw1000local[] if it has not been preserved
* (e.g. if micro was in sleep and its RAM data (containing dw1000local structure was not preserved during sleep)
*
* NOTES:
* 1. When DW1000 is powered on this function needs to be run before dwt_configuresleep,
* also the SPI frequency has to be < 3MHz
* 2. It reads and applies LDO tune and crystal trim values from OTP memory
* 3. If accurate RX timestamping is needed microcode/LDE must be loaded
*
* input parameters
* @param config - specifies what configuration to load
* DWT_LOADNONE 0x00 - do not load any values from OTP memory
* DWT_LOADUCODE 0x01 - load the LDE microcode from ROM - enable accurate RX timestamp
* DWT_DW_WAKE_UP 0x02 - just initialise dw1000local[] values (e.g. DW1000 has woken up)
* DWT_DW_WUP_NO_UCODE 0x04 - if microcode/LDE algorithm has not already been loaded (on power up) e.g. when LDE is not used
* DWT_READ_OTP_PID 0x10 - read part ID from OTP
* DWT_READ_OTP_LID 0x20 - read lot ID from OTP
* DWT_READ_OTP_BAT 0x40 - read ref voltage from OTP
* DWT_READ_OTP_TMP 0x80 - read ref temperature from OTP
* output parameters
*
* returns DWT_SUCCESS for success, or DWT_ERROR for error
*/
int dwt_initialise(int config) ;
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_configurefor64plen()
* - Use default OPS table should be used with following register modifications:
* These modifications optimise the default OPS configuration further for 64 length preamble use case
*
* NOTE: These register settings are not preserved during SLEEP/DEEPSLEEP, thus they should be programmed again after wake up
*
* input parameters
* @param prf
*
* output parameters
*
* no return value
*/
void dwt_configurefor64plen(int prf);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_configure()
*
* @brief This function provides the main API for the configuration of the
* DW1000 and this low-level driver. The input is a pointer to the data structure
* of type dwt_config_t that holds all the configurable items.
* The dwt_config_t structure shows which ones are supported
*
* input parameters
* @param config - pointer to the configuration structure, which contains the device configuration data.
*
* output parameters
*
* no return value
*/
void dwt_configure(dwt_config_t *config) ;
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_configuretxrf()
*
* @brief This function provides the API for the configuration of the TX spectrum
* including the power and pulse generator delay. The input is a pointer to the data structure
* of type dwt_txconfig_t that holds all the configurable items.
*
* input parameters
* @param config - pointer to the txrf configuration structure, which contains the tx rf config data
*
* output parameters
*
* no return value
*/
void dwt_configuretxrf(dwt_txconfig_t *config) ;
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setrxantennadelay()
*
* @brief This API function writes the antenna delay (in time units) to RX registers
*
* input parameters:
* @param rxDelay - this is the total (RX) antenna delay value, which
* will be programmed into the RX register
*
* output parameters
*
* no return value
*/
void dwt_setrxantennadelay(uint16 antennaDly);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_settxantennadelay()
*
* @brief This API function writes the antenna delay (in time units) to TX registers
*
* input parameters:
* @param txDelay - this is the total (TX) antenna delay value, which
* will be programmed into the TX delay register
*
* output parameters
*
* no return value
*/
void dwt_settxantennadelay(uint16 antennaDly);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setsmarttxpower()
*
* @brief This call enables or disables the smart TX power feature.
*
* input parameters
* @param enable - this enables or disables the TX smart power (1 = enable, 0 = disable)
*
* output parameters
*
* no return value
*/
void dwt_setsmarttxpower(int enable);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_writetxdata()
*
* @brief This API function writes the supplied TX data into the DW1000's
* TX buffer. The input parameters are the data length in bytes and a pointer
* to those data bytes.
*
* input parameters
* @param txFrameLength - This is the total frame length, including the two byte CRC.
* Note: this is the length of TX message (including the 2 byte CRC) - max is 1023
* standard PHR mode allows up to 127 bytes
* if > 127 is programmed, DWT_PHRMODE_EXT needs to be set in the phrMode configuration
* see dwt_configure function
* @param txFrameBytes - Pointer to the users buffer containing the data to send.
* @param txBufferOffset - This specifies an offset in the DW1000s TX Buffer at which to start writing data.
*
* output parameters
*
* returns DWT_SUCCESS for success, or DWT_ERROR for error
*/
int dwt_writetxdata(uint16 txFrameLength, uint8 *txFrameBytes, uint16 txBufferOffset) ;
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_writetxfctrl()
*
* @brief This API function configures the TX frame control register before the transmission of a frame
*
* input parameters:
* @param txFrameLength - this is the length of TX message (including the 2 byte CRC) - max is 1023
* NOTE: standard PHR mode allows up to 127 bytes
* if > 127 is programmed, DWT_PHRMODE_EXT needs to be set in the phrMode configuration
* see dwt_configure function
* @param txBufferOffset - the offset in the tx buffer to start writing the data
* @param ranging - 1 if this is a ranging frame, else 0
*
* output parameters
*
* no return value
*/
void dwt_writetxfctrl(uint16 txFrameLength, uint16 txBufferOffset, int ranging);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_starttx()
*
* @brief This call initiates the transmission, input parameter indicates which TX mode is used see below
*
* input parameters:
* @param mode - if mode = DWT_START_TX_IMMEDIATE - immediate TX (no response expected)
* if mode = DWT_START_TX_DELAYED - delayed TX (no response expected)
* if mode = DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED - immediate TX (response expected - so the receiver will be automatically turned on after TX is done)
* if mode = DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED - delayed TX (response expected - so the receiver will be automatically turned on after TX is done)
*
* output parameters
*
* returns DWT_SUCCESS for success, or DWT_ERROR for error (e.g. a delayed transmission will be cancelled if the delayed time has passed)
*/
int dwt_starttx(uint8 mode) ;
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setdelayedtrxtime()
*
* @brief This API function configures the delayed transmit time or the delayed RX on time
*
* input parameters
* @param starttime - the TX/RX start time (the 32 bits should be the high 32 bits of the system time at which to send the message,
* or at which to turn on the receiver)
*
* output parameters none
*
* no return value
*/
void dwt_setdelayedtrxtime(uint32 starttime) ;
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readtxtimestamp()
*
* @brief This is used to read the TX timestamp (adjusted with the programmed antenna delay)
*
* input parameters
* @param timestamp - a pointer to a 5-byte buffer which will store the read TX timestamp time
*
* output parameters - the timestamp buffer will contain the value after the function call
*
* no return value
*/
void dwt_readtxtimestamp(uint8 * timestamp);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readtxtimestamphi32()
*
* @brief This is used to read the high 32-bits of the TX timestamp (adjusted with the programmed antenna delay)
*
* input parameters
*
* output parameters
*
* returns high 32-bits of TX timestamp
*/
uint32 dwt_readtxtimestamphi32(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readtxtimestamplo32()
*
* @brief This is used to read the low 32-bits of the TX timestamp (adjusted with the programmed antenna delay)
*
* input parameters
*
* output parameters
*
* returns low 32-bits of TX timestamp
*/
uint32 dwt_readtxtimestamplo32(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readrxtimestamp()
*
* @brief This is used to read the RX timestamp (adjusted time of arrival)
*
* input parameters
* @param timestamp - a pointer to a 5-byte buffer which will store the read RX timestamp time
*
* output parameters - the timestamp buffer will contain the value after the function call
*
* no return value
*/
void dwt_readrxtimestamp(uint8 * timestamp);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readrxtimestamphi32()
*
* @brief This is used to read the high 32-bits of the RX timestamp (adjusted with the programmed antenna delay)
*
* input parameters
*
* output parameters
*
* returns high 32-bits of RX timestamp
*/
uint32 dwt_readrxtimestamphi32(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readrxtimestamplo32()
*
* @brief This is used to read the low 32-bits of the RX timestamp (adjusted with the programmed antenna delay)
*
* input parameters
*
* output parameters
*
* returns low 32-bits of RX timestamp
*/
uint32 dwt_readrxtimestamplo32(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readsystimestamphi32()
*
* @brief This is used to read the high 32-bits of the system time
*
* input parameters
*
* output parameters
*
* returns high 32-bits of system time timestamp
*/
uint32 dwt_readsystimestamphi32(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_readsystime()
*
* @brief This is used to read the system time
*
* input parameters
* @param timestamp - a pointer to a 5-byte buffer which will store the read system time
*
* output parameters
* @param timestamp - the timestamp buffer will contain the value after the function call
*
* no return value
*/
void dwt_readsystime(uint8 * timestamp);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_forcetrxoff()
*
* @brief This is used to turn off the transceiver
*
* input parameters
*
* output parameters
*
* no return value
*/
void dwt_forcetrxoff(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_syncrxbufptrs()
*
* @brief this function synchronizes rx buffer pointers
* need to make sure that the host/IC buffer pointers are aligned before starting RX
*
* input parameters:
*
* output parameters
*
* no return value
*/
void dwt_syncrxbufptrs(void);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_rxenable()
*
* @brief This call turns on the receiver, can be immediate or delayed (depending on the mode parameter). In the case of a
* "late" error the receiver will only be turned on if the DWT_IDLE_ON_DLY_ERR is not set.
* The receiver will stay turned on, listening to any messages until
* it either receives a good frame, an error (CRC, PHY header, Reed Solomon) or it times out (SFD, Preamble or Frame).
*
* input parameters
* @param mode - this can be one of the following allowed values:
*
* DWT_START_RX_IMMEDIATE 0 used to enbale receiver immediately
* DWT_START_RX_DELAYED 1 used to set up delayed RX, if "late" error triggers, then the RX will be enabled immediately
* (DWT_START_RX_DELAYED | DWT_IDLE_ON_DLY_ERR) 3 used to disable re-enabling of receiver if delayed RX failed due to "late" error
* (DWT_START_RX_IMMEDIATE | DWT_NO_SYNC_PTRS) 4 used to re-enable RX without trying to sync IC and host side buffer pointers, typically when
* performing manual RX re-enabling in double buffering mode
*
* returns DWT_SUCCESS for success, or DWT_ERROR for error (e.g. a delayed receive enable will be too far in the future if delayed time has passed)
*/
int dwt_rxenable(int mode);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setsniffmode()
*
* @brief enable/disable and configure SNIFF mode.
*
* SNIFF mode is a low-power reception mode where the receiver is sequenced on and off instead of being on all the time.
* The time spent in each state (on/off) is specified through the parameters below.
* See DW1000 User Manual section 4.5 "Low-Power SNIFF mode" for more details.
*
* input parameters:
* @param enable - 1 to enable SNIFF mode, 0 to disable. When 0, all other parameters are not taken into account.
* @param timeOn - duration of receiver ON phase, expressed in multiples of PAC size. The counter automatically adds 1 PAC
* size to the value set. Min value that can be set is 1 (i.e. an ON time of 2 PAC size), max value is 15.
* @param timeOff - duration of receiver OFF phase, expressed in multiples of 128/125 µs (~1 µs). Max value is 255.
*
* output parameters
*
* no return value
*/
void dwt_setsniffmode(int enable, uint8 timeOn, uint8 timeOff);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setlowpowerlistening()
*
* @brief enable/disable low-power listening mode.
*
* Low-power listening is a feature whereby the DW1000 is predominantly in the SLEEP state but wakes periodically, (after
* this "long sleep"), for a very short time to sample the air for a preamble sequence. This preamble sampling "listening"
* phase is actually two reception phases separated by a "short sleep" time. See DW1000 User Manual section "Low-Power
* Listening" for more details.
*
* NOTE: Before enabling low-power listening, the following functions have to be called to fully configure it:
* - dwt_configuresleep() to configure long sleep phase. "mode" parameter should at least have DWT_PRESRV_SLEEP,
* DWT_CONFIG and DWT_RX_EN set and "wake" parameter should at least have both DWT_WAKE_SLPCNT and DWT_SLP_EN set.
* - dwt_calibratesleepcnt() and dwt_configuresleepcnt() to define the "long sleep" phase duration.
* - dwt_setsnoozetime() to define the "short sleep" phase duration.
* - dwt_setpreambledetecttimeout() to define the reception phases duration.
* - dwt_setinterrupt() to activate RX good frame interrupt (DWT_INT_RFCG) only.
* When configured, low-power listening mode can be triggered either by putting the DW1000 to sleep (using
* dwt_entersleep()) or by activating reception (using dwt_rxenable()).
*
* Please refer to the low-power listening examples (examples 8a/8b accompanying the API distribution on Decawave's
* website). They form a working example code that shows how to use low-power listening correctly.
*
* input parameters:
* @param enable - 1 to enable low-power listening, 0 to disable.
*
* output parameters
*
* no return value
*/
void dwt_setlowpowerlistening(int enable);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setsnoozetime()
*
* @brief Set duration of "short sleep" phase when in low-power listening mode.
*
* input parameters:
* @param snooze_time - "short sleep" phase duration, expressed in multiples of 512/19.2 µs (~26.7 µs). The counter
* automatically adds 1 to the value set. The smallest working value that should be set is 1,
* i.e. giving a snooze time of 2 units (or ~53 µs).
*
* output parameters
*
* no return value
*/
void dwt_setsnoozetime(uint8 snooze_time);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setdblrxbuffmode()
*
* @brief This call enables the double receive buffer mode
*
* input parameters
* @param enable - 1 to enable, 0 to disable the double buffer mode
*
* output parameters
*
* no return value
*/
void dwt_setdblrxbuffmode(int enable);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setrxtimeout()
*
* @brief This call enables RX timeout (SY_STAT_RFTO event)
*
* input parameters
* @param time - how long the receiver remains on from the RX enable command
* The time parameter used here is in 1.0256 us (512/499.2MHz) units
* If set to 0 the timeout is disabled.
*
* output parameters
*
* no return value
*/
void dwt_setrxtimeout(uint16 time);
/*! ------------------------------------------------------------------------------------------------------------------
* @fn dwt_setpreambledetecttimeout()
*
* @brief This call enables preamble timeout (SY_STAT_RXPTO event)
*
* input parameters
* @param timeout - Preamble detection timeout, expressed in multiples of PAC size. The counter automatically adds 1 PAC
* size to the value set. Min value that can be set is 1 (i.e. a timeout of 2 PAC size).
*
* Note: value of 0 disables the preamble timeout
* output parameters
*
* no return value
*/