uwb  2.0.0.0
uwb.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef UWB_H
36 #define UWB_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
54 #define UWB_MAP_MIKROBUS( cfg, mikrobus ) \
55  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
56  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
57  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
58  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
59  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
60  cfg.irq = MIKROBUS( mikrobus, MIKROBUS_INT )
61 
67 #define UWB_RETVAL uint8_t
68 
69 #define UWB_OK 0x00
70 #define UWB_INIT_ERROR 0xFF
71 
77 #define UWB_SUB_NO 0x00
78 
84 #define UWB_REG_DEV_ID 0x00
85 #define UWB_REG_EU_ID 0x01
86 #define UWB_REG_PAN_ID 0x03
87 #define UWB_REG_SYS_CFG 0x04
88 #define UWB_REG_SYS_CNT 0x06
89 #define UWB_REG_SYS_TX_CTRL 0x08
90 #define UWB_REG_TX_DATA_BUF 0x09
91 #define UWB_REG_DX_TIME 0x0A
92 #define UWB_REG_RX_TIMEOUT 0x0C
93 #define UWB_REG_SYS_CTRL 0x0D
94 #define UWB_REG_SYS_EVENT_MASK 0x0E
95 #define UWB_REG_EVENT_STATUS 0x0F
96 #define UWB_REG_RX_INFO 0x10
97 #define UWB_REG_RX_BUF 0x11
98 #define UWB_REG_RX_QUALITY_INFO 0x12
99 #define UWB_REG_RX_TIME_INTERVAL 0x13
100 #define UWB_REG_RX_TIME_OFFSET 0x14
101 #define UWB_REG_RX_MESSAGE_TOA 0x15
102 #define UWB_REG_TX_MESSAGE_TOS 0x17
103 #define UWB_REG_TX_ANTD 0x18
104 #define UWB_REG_SYS_STATE 0x19
105 #define UWB_REG_ACK_RESPONSE_TIME 0x1A
106 #define UWB_REG_RX_SNIFF_CFG 0x1D
107 #define UWB_REG_TX_POWER 0x1E
108 #define UWB_REG_CHN_CTRL 0x1F
109 #define UWB_REG_SFD 0x21
110 #define UWB_REG_AUTO_GAIN_CFG 0x23
111 #define UWB_REG_EXTERNAL_SYNC 0x24
112 #define UWB_REG_READ_AA_DATA 0x25
113 #define UWB_REG_GPIO_CTRL 0x26
114 #define UWB_REG_DRX_CFG 0x27
115 #define UWB_REG_RF_CFG 0x28
116 #define UWB_REG_TX_CALIBRATION 0x2A
117 #define UWB_REG_FREQ_SYNTH_CTRL 0x2B
118 #define UWB_REG_ALWAYS_ON_REG 0x2C
119 #define UWB_REG_OTP_INTERFACE 0x2D
120 #define UWB_REG_LEAD_EDGE_DET_CTRL 0x2E
121 #define UWB_REG_DIGITAL_DIAG_IF 0x2F
122 #define UWB_REG_POWER_MANAGE_SYS_CTRL 0x36
123 
129 #define UWB_OTP_WRITE 0x00
130 #define UWB_OTP_ADR 0x04
131 #define UWB_OTP_CTRL 0x06
132 #define UWB_OTP_STATUS 0x08
133 #define UWB_OTP_RDAT 0x0A
134 #define UWB_OTP_SRDAT 0x0E
135 #define UWB_OTP_SF 0x12
136 
142 #define UWB_DATA_RATE_110KBSPS 0x00
143 #define UWB_DATA_RATE_850KBSPS 0x01
144 #define UWB_DATA_RATE_6800KBSPS 0x02
145 
151 #define UWB_PULSTE_FREQ_4MHZ 0x00
152 #define UWB_PULSTE_FREQ_16MHZ 0x01
153 #define UWB_PULSTE_FREQ_64MHZ 0x02
154 
160 #define UWB_PREAMBLE_LEN_64 0x01
161 #define UWB_PREAMBLE_LEN_128 0x05
162 #define UWB_PREAMBLE_LEN_256 0x09
163 #define UWB_PREAMBLE_LEN_512 0x0D
164 #define UWB_PREAMBLE_LEN_1024 0x02
165 #define UWB_PREAMBLE_LEN_1536 0x06
166 #define UWB_PREAMBLE_LEN_2048 0x0A
167 #define UWB_PREAMBLE_LEN_4096 0x03
168 
174 #define UWB_PAC_SIZE_8 8
175 #define UWB_PAC_SIZE_16 16
176 #define UWB_PAC_SIZE_32 32
177 #define UWB_PAC_SIZE_64 64
178 
184 #define UWB_CHANNEL_1 1
185 #define UWB_CHANNEL_2 2
186 #define UWB_CHANNEL_3 3
187 #define UWB_CHANNEL_4 4
188 #define UWB_CHANNEL_5 5
189 #define UWB_CHANNEL_7 7
190 
196 #define UWB_PREAMBLE_CODE_1 1
197 #define UWB_PREAMBLE_CODE_2 2
198 #define UWB_PREAMBLE_CODE_3 3
199 #define UWB_PREAMBLE_CODE_4 4
200 #define UWB_PREAMBLE_CODE_5 5
201 #define UWB_PREAMBLE_CODE_6 6
202 #define UWB_PREAMBLE_CODE_7 7
203 #define UWB_PREAMBLE_CODE_8 8
204 #define UWB_PREAMBLE_CODE_9 9
205 #define UWB_PREAMBLE_CODE_10 10
206 #define UWB_PREAMBLE_CODE_11 11
207 #define UWB_PREAMBLE_CODE_12 12
208 #define UWB_PREAMBLE_CODE_13 13
209 #define UWB_PREAMBLE_CODE_14 14
210 #define UWB_PREAMBLE_CODE_15 15
211 #define UWB_PREAMBLE_CODE_16 16
212 #define UWB_PREAMBLE_CODE_17 17
213 #define UWB_PREAMBLE_CODE_18 18
214 #define UWB_PREAMBLE_CODE_19 19
215 #define UWB_PREAMBLE_CODE_20 20
216 #define UWB_PREAMBLE_CODE_21 21
217 #define UWB_PREAMBLE_CODE_22 22
218 #define UWB_PREAMBLE_CODE_23 23
219 #define UWB_PREAMBLE_CODE_24 24
220 
226 #define UWB_FRAME_LEN_NORMAL 0x00
227 #define UWB_FRAME_LEN_EXTENDED 0x03
228 
234 #define UWB_HIGH 1
235 #define UWB_LOW 0
236 
242 #define UWB_DEV_ERROR 0xFF
243 #define UWB_DEV_OK 0x00
244 
250 #define UWB_MODE_IDLE 1
251 #define UWB_MODE_RX 2
252 #define UWB_MODE_TX 3
253 
259 #define UWB_TAG 0xDECA
260 
266 #define WRITE_MASK 0x80
267 #define SUB_MASK 0x40
268 #define READ_MASK 0x00
269 #define SUB_EXT_MASK 0x80
270 
276 #define AGC_TUNE1_SUB 0x04
277 #define AGC_TUNE2_SUB 0x0C
278 #define AGC_TUNE3_SUB 0x12
279 #define LEN_AGC_TUNE1 2
280 #define LEN_AGC_TUNE2 4
281 #define LEN_AGC_TUNE3 2
282 #define DRX_TUNE0b_SUB 0x02
283 #define DRX_TUNE1a_SUB 0x04
284 #define DRX_TUNE1b_SUB 0x06
285 #define DRX_TUNE2_SUB 0x08
286 #define DRX_TUNE4H_SUB 0x26
287 #define LEN_DRX_TUNE0b 2
288 #define LEN_DRX_TUNE1a 2
289 #define LEN_DRX_TUNE1b 2
290 #define LEN_DRX_TUNE2 4
291 #define LEN_DRX_TUNE4H 2
292 #define LDE_CFG1_SUB 0x0806
293 #define LDE_RXANTD_SUB 0x1804
294 #define LDE_CFG2_SUB 0x1806
295 #define LDE_REPC_SUB 0x2804
296 #define LEN_LDE_CFG1 1
297 #define LEN_LDE_CFG2 2
298 #define LEN_LDE_REPC 2
299 #define LEN_LDE_RXANTD 2
300 #define LEN_TX_POWER 4
301 #define RF_RXCTRLH_SUB 0x0B
302 #define RF_TXCTRL_SUB 0x0C
303 #define LEN_RF_RXCTRLH 1
304 #define LEN_RF_TXCTRL 4
305 #define TC_PGDELAY_SUB 0x0B
306 #define LEN_TC_PGDELAY 1
307 #define TC_SARC 0x00
308 #define TC_SARL 0x03
309 #define FS_PLLCFG_SUB 0x07
310 #define FS_PLLTUNE_SUB 0x0B
311 #define FS_XTALT_SUB 0x0E
312 #define LEN_FS_PLLCFG 4
313 #define LEN_FS_PLLTUNE 1
314 #define LEN_FS_XTALT 1
315 
321 #define DUMMY_BUFFER 1024
322  // End group macro
324 // --------------------------------------------------------------- PUBLIC TYPES
333 typedef struct
334 {
335  // Output pins
336 
337  digital_out_t rst;
338  digital_out_t cs;
339 
340  // Input pins
341 
342  digital_in_t irq;
343 
344  // Modules
345 
346  spi_master_t spi;
347  pin_name_t chip_select;
348 
349  // Sub address offset
350 
351  uint16_t offset;
352 
353 } uwb_t;
354 
358 typedef struct
359 {
360  // Communication gpio pins
361 
362  pin_name_t miso;
363  pin_name_t mosi;
364  pin_name_t sck;
365  pin_name_t cs;
366 
367  // Additional gpio pins
368 
369  pin_name_t rst;
370  pin_name_t irq;
371 
372  // static variable
373 
374  uint32_t spi_speed;
375  spi_master_mode_t spi_mode;
376  spi_master_chip_select_polarity_t cs_polarity;
377 
378 } uwb_cfg_t;
379 
383 typedef struct
384 {
385  uint8_t dev_mode;
386  uint8_t extended_frame;
387  uint8_t pac_size;
388  uint8_t pulse_freq;
389  uint8_t data_rate;
390  uint8_t preamble_len;
391  uint8_t preamble_code;
392  uint8_t channel;
393  uint8_t antenna_delay;
394  uint8_t antenna_calib;
395  uint8_t smart_power;
396  uint8_t frame_check;
397  uint8_t permanent_rx;
399 
400 }uwb_dev_t;
401  // End types group
403 // ------------------------------------------------------------------ CONSTANTS
409 extern const uint8_t UWB_TMODE_LONGDATA_RANGE_LOWPOWER[ 3 ];
410 extern const uint8_t UWB_TMODE_LONGDATA_RANGE_ACCURACY[ 3 ];
411 extern const uint8_t UWB_TMODE_LONGDATA_FAST_LOWPOWER[ 3 ];
412 extern const uint8_t UWB_TMODE_LONGDATA_FAST_ACCURACY[ 3 ];
413 extern const uint8_t UWB_TMODE_SHORTDATA_FAST_LOWPOWER[ 3 ];
414 extern const uint8_t UWB_TMODE_SHORTDATA_FAST_ACCURACY[ 3 ];
415  // End constants group
417 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
418 
423 #ifdef __cplusplus
424 extern "C"{
425 #endif
426 
435 void uwb_cfg_setup ( uwb_cfg_t *cfg );
436 
446 
457 void uwb_generic_write ( uwb_t *ctx, uint8_t reg_adr, uint8_t *tx_buf, uint16_t buf_len );
458 
469 void uwb_generic_read ( uwb_t *ctx, uint8_t reg_adr, uint8_t *rx_buf, uint16_t buf_len );
470 
479 void uwb_set_rst_pin_status ( uwb_t *ctx, uint8_t status );
480 
491 
501 void uwb_read_otp ( uwb_t *ctx, uint16_t otp_adr, uint8_t *rx_buf );
502 
513 void uwb_set_bit ( uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num, uint8_t bit_state );
514 
526 uint8_t uwb_get_bit ( uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num );
527 
538 uint16_t uwb_reg_data_len ( uint8_t reg_adr );
539 
549 void uwb_set_dev_adr_n_network_id ( uwb_t *ctx, uint16_t dev_adr, uint16_t net_id );
550 
561 uint8_t uwb_set_data_rate ( uwb_t *ctx, uint8_t rate );
562 
571 void uwb_set_pulse_freq ( uwb_t *ctx, uint8_t freq );
572 
581 void uwb_set_preamble_len ( uwb_t *ctx, uint8_t prealen );
582 
591 void uwb_set_preable_code ( uwb_t *ctx, uint8_t preamble );
592 
601 void uwb_set_channel ( uwb_t *ctx, uint8_t channel );
602 
611 void uwb_set_transmit_type ( uwb_t *ctx, const uint8_t *t_t );
612 
622 void uwb_get_transmit ( uwb_t *ctx, uint8_t *rx_buf, uint16_t len_buf );
623 
633 uint8_t uwb_get_transmit_len ( uwb_t *ctx );
634 
644 void uwb_set_transmit ( uwb_t *ctx, uint8_t *tx_buf, uint16_t len_buf );
645 
654 void uwb_use_smart_power ( uwb_t *ctx, uint8_t smart_power );
655 
664 void uwb_frame_check ( uint8_t fc );
665 
674 void uwb_frame_filter ( uwb_t *ctx, uint8_t ff );
675 
685 void uwb_set_mode ( uwb_t *ctx, uint8_t mode );
686 
696 
708 
717 void uwb_clear_status ( uwb_t *ctx );
718 
727 void uwb_int_mask_set ( uwb_t *ctx );
728 
738 void uwb_tune_config ( uwb_t *ctx );
739 
747 void uwb_dev_reset ( uwb_t *ctx );
748 
756 void uwb_enable ( uwb_t *ctx );
757 
758 #ifdef __cplusplus
759 }
760 #endif
761 #endif // _UWB_H_
762  // End public_function group
765 
766 // ------------------------------------------------------------------------- END
uwb_set_dev_adr_n_network_id
void uwb_set_dev_adr_n_network_id(uwb_t *ctx, uint16_t dev_adr, uint16_t net_id)
Function for setting device address and network ID.
UWB_TMODE_SHORTDATA_FAST_LOWPOWER
const uint8_t UWB_TMODE_SHORTDATA_FAST_LOWPOWER[3]
uwb_enable
void uwb_enable(uwb_t *ctx)
Function for enabling device.
uwb_t::spi
spi_master_t spi
Definition: uwb.h:346
uwb_dev_t::dev_mode
uint8_t dev_mode
Definition: uwb.h:385
uwb_get_bit
uint8_t uwb_get_bit(uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num)
Function for getting single bit state.
uwb_set_channel
void uwb_set_channel(uwb_t *ctx, uint8_t channel)
Function for setting channel.
uwb_dev_t::antenna_calib
uint8_t antenna_calib
Definition: uwb.h:394
uwb_dev_t::permanent_rx
uint8_t permanent_rx
Definition: uwb.h:397
uwb_dev_t::channel
uint8_t channel
Definition: uwb.h:392
uwb_cfg_t::sck
pin_name_t sck
Definition: uwb.h:364
UWB_TMODE_SHORTDATA_FAST_ACCURACY
const uint8_t UWB_TMODE_SHORTDATA_FAST_ACCURACY[3]
uwb_int_mask_set
void uwb_int_mask_set(uwb_t *ctx)
Function for setting interrupt mask.
UWB_RETVAL
#define UWB_RETVAL
Definition: uwb.h:67
uwb_dev_t::debounce_clk_en
uint8_t debounce_clk_en
Definition: uwb.h:398
uwb_clear_status
void uwb_clear_status(uwb_t *ctx)
Function for clearing status.
uwb_cfg_setup
void uwb_cfg_setup(uwb_cfg_t *cfg)
Config Object Initialization function.
uwb_get_qint_pin_status
uint8_t uwb_get_qint_pin_status(uwb_t *ctx)
Function for getting irq pin status.
uwb_dev_t::preamble_code
uint8_t preamble_code
Definition: uwb.h:391
uwb_t
Click ctx object definition.
Definition: uwb.h:334
uwb_t::cs
digital_out_t cs
Definition: uwb.h:338
uwb_dev_reset
void uwb_dev_reset(uwb_t *ctx)
Function for reseting device.
uwb_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: uwb.h:375
uwb_generic_write
void uwb_generic_write(uwb_t *ctx, uint8_t reg_adr, uint8_t *tx_buf, uint16_t buf_len)
Function for writing data to register.
uwb_get_transmit_status
uint8_t uwb_get_transmit_status(uwb_t *ctx)
Function for getting transmit status.
uwb_use_smart_power
void uwb_use_smart_power(uwb_t *ctx, uint8_t smart_power)
Function for setting smart power option.
uwb_cfg_t::mosi
pin_name_t mosi
Definition: uwb.h:363
UWB_TMODE_LONGDATA_FAST_LOWPOWER
const uint8_t UWB_TMODE_LONGDATA_FAST_LOWPOWER[3]
uwb_dev_t::smart_power
uint8_t smart_power
Definition: uwb.h:395
uwb_t::irq
digital_in_t irq
Definition: uwb.h:342
uwb_set_preamble_len
void uwb_set_preamble_len(uwb_t *ctx, uint8_t prealen)
Function for setting preamble length.
uwb_dev_t::pac_size
uint8_t pac_size
Definition: uwb.h:387
uwb_cfg_t::rst
pin_name_t rst
Definition: uwb.h:369
uwb_read_otp
void uwb_read_otp(uwb_t *ctx, uint16_t otp_adr, uint8_t *rx_buf)
Function for reading OTM memory.
uwb_get_transmit
void uwb_get_transmit(uwb_t *ctx, uint8_t *rx_buf, uint16_t len_buf)
Function for getting transmit data.
uwb_start_transceiver
void uwb_start_transceiver(uwb_t *ctx)
Function for starting communication of device.
uwb_cfg_t
Click configuration structure definition.
Definition: uwb.h:359
uwb_frame_check
void uwb_frame_check(uint8_t fc)
Function for setting frame check option.
uwb_set_preable_code
void uwb_set_preable_code(uwb_t *ctx, uint8_t preamble)
Function for setting preamble code.
uwb_init
UWB_RETVAL uwb_init(uwb_t *ctx, uwb_cfg_t *cfg)
Initialization function.
uwb_dev_t::data_rate
uint8_t data_rate
Definition: uwb.h:389
UWB_TMODE_LONGDATA_RANGE_ACCURACY
const uint8_t UWB_TMODE_LONGDATA_RANGE_ACCURACY[3]
uwb_set_transmit_type
void uwb_set_transmit_type(uwb_t *ctx, const uint8_t *t_t)
Function for setting transmit type mode.
uwb_set_pulse_freq
void uwb_set_pulse_freq(uwb_t *ctx, uint8_t freq)
Function for setting pulse frequency.
uwb_t::rst
digital_out_t rst
Definition: uwb.h:337
uwb_set_rst_pin_status
void uwb_set_rst_pin_status(uwb_t *ctx, uint8_t status)
Function for setting rst pin status.
uwb_dev_t::frame_check
uint8_t frame_check
Definition: uwb.h:396
uwb_t::offset
uint16_t offset
Definition: uwb.h:351
uwb_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: uwb.h:376
uwb_set_data_rate
uint8_t uwb_set_data_rate(uwb_t *ctx, uint8_t rate)
Function for setting data rate.
uwb_dev_t::extended_frame
uint8_t extended_frame
Definition: uwb.h:386
uwb_cfg_t::spi_speed
uint32_t spi_speed
Definition: uwb.h:374
uwb_generic_read
void uwb_generic_read(uwb_t *ctx, uint8_t reg_adr, uint8_t *rx_buf, uint16_t buf_len)
Function for reading data from register.
uwb_dev_t::pulse_freq
uint8_t pulse_freq
Definition: uwb.h:388
uwb_dev_t::preamble_len
uint8_t preamble_len
Definition: uwb.h:390
uwb_cfg_t::cs
pin_name_t cs
Definition: uwb.h:365
uwb_get_transmit_len
uint8_t uwb_get_transmit_len(uwb_t *ctx)
Function for getting transmit length.
uwb_t::chip_select
pin_name_t chip_select
Definition: uwb.h:347
uwb_reg_data_len
uint16_t uwb_reg_data_len(uint8_t reg_adr)
Function for getting length of register data.
uwb_tune_config
void uwb_tune_config(uwb_t *ctx)
Function for tuneing configuration for set values.
UWB_TMODE_LONGDATA_RANGE_LOWPOWER
const uint8_t UWB_TMODE_LONGDATA_RANGE_LOWPOWER[3]
uwb_frame_filter
void uwb_frame_filter(uwb_t *ctx, uint8_t ff)
Function for setting frame filter option.
uwb_dev_t::antenna_delay
uint8_t antenna_delay
Definition: uwb.h:393
uwb_set_transmit
void uwb_set_transmit(uwb_t *ctx, uint8_t *tx_buf, uint16_t len_buf)
Function for setting transmit data.
uwb_set_mode
void uwb_set_mode(uwb_t *ctx, uint8_t mode)
Function for setting device working mode.
uwb_cfg_t::irq
pin_name_t irq
Definition: uwb.h:370
uwb_dev_t
Structure for device configuration.
Definition: uwb.h:384
uwb_cfg_t::miso
pin_name_t miso
Definition: uwb.h:362
uwb_set_bit
void uwb_set_bit(uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num, uint8_t bit_state)
Function for setting single bit state.
UWB_TMODE_LONGDATA_FAST_ACCURACY
const uint8_t UWB_TMODE_LONGDATA_FAST_ACCURACY[3]