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 #include "spi_specifics.h"
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_OK 0
68 #define UWB_ERROR -1
69 
75 #define UWB_SUB_NO 0x00
76 
82 #define UWB_REG_DEV_ID 0x00
83 #define UWB_REG_EU_ID 0x01
84 #define UWB_REG_PAN_ID 0x03
85 #define UWB_REG_SYS_CFG 0x04
86 #define UWB_REG_SYS_CNT 0x06
87 #define UWB_REG_SYS_TX_CTRL 0x08
88 #define UWB_REG_TX_DATA_BUF 0x09
89 #define UWB_REG_DX_TIME 0x0A
90 #define UWB_REG_RX_TIMEOUT 0x0C
91 #define UWB_REG_SYS_CTRL 0x0D
92 #define UWB_REG_SYS_EVENT_MASK 0x0E
93 #define UWB_REG_EVENT_STATUS 0x0F
94 #define UWB_REG_RX_INFO 0x10
95 #define UWB_REG_RX_BUF 0x11
96 #define UWB_REG_RX_QUALITY_INFO 0x12
97 #define UWB_REG_RX_TIME_INTERVAL 0x13
98 #define UWB_REG_RX_TIME_OFFSET 0x14
99 #define UWB_REG_RX_MESSAGE_TOA 0x15
100 #define UWB_REG_TX_MESSAGE_TOS 0x17
101 #define UWB_REG_TX_ANTD 0x18
102 #define UWB_REG_SYS_STATE 0x19
103 #define UWB_REG_ACK_RESPONSE_TIME 0x1A
104 #define UWB_REG_RX_SNIFF_CFG 0x1D
105 #define UWB_REG_TX_POWER 0x1E
106 #define UWB_REG_CHN_CTRL 0x1F
107 #define UWB_REG_SFD 0x21
108 #define UWB_REG_AUTO_GAIN_CFG 0x23
109 #define UWB_REG_EXTERNAL_SYNC 0x24
110 #define UWB_REG_READ_AA_DATA 0x25
111 #define UWB_REG_GPIO_CTRL 0x26
112 #define UWB_REG_DRX_CFG 0x27
113 #define UWB_REG_RF_CFG 0x28
114 #define UWB_REG_TX_CALIBRATION 0x2A
115 #define UWB_REG_FREQ_SYNTH_CTRL 0x2B
116 #define UWB_REG_ALWAYS_ON_REG 0x2C
117 #define UWB_REG_OTP_INTERFACE 0x2D
118 #define UWB_REG_LEAD_EDGE_DET_CTRL 0x2E
119 #define UWB_REG_DIGITAL_DIAG_IF 0x2F
120 #define UWB_REG_POWER_MANAGE_SYS_CTRL 0x36
121 
127 #define UWB_OTP_WRITE 0x00
128 #define UWB_OTP_ADR 0x04
129 #define UWB_OTP_CTRL 0x06
130 #define UWB_OTP_STATUS 0x08
131 #define UWB_OTP_RDAT 0x0A
132 #define UWB_OTP_SRDAT 0x0E
133 #define UWB_OTP_SF 0x12
134 
140 #define UWB_DATA_RATE_110KBSPS 0x00
141 #define UWB_DATA_RATE_850KBSPS 0x01
142 #define UWB_DATA_RATE_6800KBSPS 0x02
143 
149 #define UWB_PULSTE_FREQ_4MHZ 0x00
150 #define UWB_PULSTE_FREQ_16MHZ 0x01
151 #define UWB_PULSTE_FREQ_64MHZ 0x02
152 
158 #define UWB_PREAMBLE_LEN_64 0x01
159 #define UWB_PREAMBLE_LEN_128 0x05
160 #define UWB_PREAMBLE_LEN_256 0x09
161 #define UWB_PREAMBLE_LEN_512 0x0D
162 #define UWB_PREAMBLE_LEN_1024 0x02
163 #define UWB_PREAMBLE_LEN_1536 0x06
164 #define UWB_PREAMBLE_LEN_2048 0x0A
165 #define UWB_PREAMBLE_LEN_4096 0x03
166 
172 #define UWB_PAC_SIZE_8 8
173 #define UWB_PAC_SIZE_16 16
174 #define UWB_PAC_SIZE_32 32
175 #define UWB_PAC_SIZE_64 64
176 
182 #define UWB_CHANNEL_1 1
183 #define UWB_CHANNEL_2 2
184 #define UWB_CHANNEL_3 3
185 #define UWB_CHANNEL_4 4
186 #define UWB_CHANNEL_5 5
187 #define UWB_CHANNEL_7 7
188 
194 #define UWB_PREAMBLE_CODE_1 1
195 #define UWB_PREAMBLE_CODE_2 2
196 #define UWB_PREAMBLE_CODE_3 3
197 #define UWB_PREAMBLE_CODE_4 4
198 #define UWB_PREAMBLE_CODE_5 5
199 #define UWB_PREAMBLE_CODE_6 6
200 #define UWB_PREAMBLE_CODE_7 7
201 #define UWB_PREAMBLE_CODE_8 8
202 #define UWB_PREAMBLE_CODE_9 9
203 #define UWB_PREAMBLE_CODE_10 10
204 #define UWB_PREAMBLE_CODE_11 11
205 #define UWB_PREAMBLE_CODE_12 12
206 #define UWB_PREAMBLE_CODE_13 13
207 #define UWB_PREAMBLE_CODE_14 14
208 #define UWB_PREAMBLE_CODE_15 15
209 #define UWB_PREAMBLE_CODE_16 16
210 #define UWB_PREAMBLE_CODE_17 17
211 #define UWB_PREAMBLE_CODE_18 18
212 #define UWB_PREAMBLE_CODE_19 19
213 #define UWB_PREAMBLE_CODE_20 20
214 #define UWB_PREAMBLE_CODE_21 21
215 #define UWB_PREAMBLE_CODE_22 22
216 #define UWB_PREAMBLE_CODE_23 23
217 #define UWB_PREAMBLE_CODE_24 24
218 
224 #define UWB_FRAME_LEN_NORMAL 0x00
225 #define UWB_FRAME_LEN_EXTENDED 0x03
226 
232 #define UWB_HIGH 1
233 #define UWB_LOW 0
234 
240 #define UWB_DEV_ERROR 0xFF
241 #define UWB_DEV_OK 0x00
242 
248 #define UWB_MODE_IDLE 1
249 #define UWB_MODE_RX 2
250 #define UWB_MODE_TX 3
251 
257 #define UWB_TAG 0xDECA
258 
264 #define WRITE_MASK 0x80
265 #define SUB_MASK 0x40
266 #define READ_MASK 0x00
267 #define SUB_EXT_MASK 0x80
268 
274 #define AGC_TUNE1_SUB 0x04
275 #define AGC_TUNE2_SUB 0x0C
276 #define AGC_TUNE3_SUB 0x12
277 #define LEN_AGC_TUNE1 2
278 #define LEN_AGC_TUNE2 4
279 #define LEN_AGC_TUNE3 2
280 #define DRX_TUNE0b_SUB 0x02
281 #define DRX_TUNE1a_SUB 0x04
282 #define DRX_TUNE1b_SUB 0x06
283 #define DRX_TUNE2_SUB 0x08
284 #define DRX_TUNE4H_SUB 0x26
285 #define LEN_DRX_TUNE0b 2
286 #define LEN_DRX_TUNE1a 2
287 #define LEN_DRX_TUNE1b 2
288 #define LEN_DRX_TUNE2 4
289 #define LEN_DRX_TUNE4H 2
290 #define LDE_CFG1_SUB 0x0806
291 #define LDE_RXANTD_SUB 0x1804
292 #define LDE_CFG2_SUB 0x1806
293 #define LDE_REPC_SUB 0x2804
294 #define LEN_LDE_CFG1 1
295 #define LEN_LDE_CFG2 2
296 #define LEN_LDE_REPC 2
297 #define LEN_LDE_RXANTD 2
298 #define LEN_TX_POWER 4
299 #define RF_RXCTRLH_SUB 0x0B
300 #define RF_TXCTRL_SUB 0x0C
301 #define LEN_RF_RXCTRLH 1
302 #define LEN_RF_TXCTRL 4
303 #define TC_PGDELAY_SUB 0x0B
304 #define LEN_TC_PGDELAY 1
305 #define TC_SARC 0x00
306 #define TC_SARL 0x03
307 #define FS_PLLCFG_SUB 0x07
308 #define FS_PLLTUNE_SUB 0x0B
309 #define FS_XTALT_SUB 0x0E
310 #define LEN_FS_PLLCFG 4
311 #define LEN_FS_PLLTUNE 1
312 #define LEN_FS_XTALT 1
313 
319 #define DUMMY_BUFFER 1024
320 
330 #define UWB_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
331 #define UWB_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
332  // End group macro
333 // --------------------------------------------------------------- PUBLIC TYPES
342 typedef struct
343 {
344  // Output pins
345 
346  digital_out_t rst;
347  digital_out_t cs;
348 
349  // Input pins
350 
351  digital_in_t irq;
352 
353  // Modules
354 
355  spi_master_t spi;
356  pin_name_t chip_select;
357 
358  // Sub address offset
359 
360  uint16_t offset;
361 
362 } uwb_t;
363 
367 typedef struct
368 {
369  // Communication gpio pins
370 
371  pin_name_t miso;
372  pin_name_t mosi;
373  pin_name_t sck;
374  pin_name_t cs;
375 
376  // Additional gpio pins
377 
378  pin_name_t rst;
379  pin_name_t irq;
380 
381  // static variable
382 
383  uint32_t spi_speed;
384  spi_master_mode_t spi_mode;
385  spi_master_chip_select_polarity_t cs_polarity;
386 
387 } uwb_cfg_t;
388 
392 typedef struct
393 {
394  uint8_t dev_mode;
395  uint8_t extended_frame;
396  uint8_t pac_size;
397  uint8_t pulse_freq;
398  uint8_t data_rate;
399  uint8_t preamble_len;
400  uint8_t preamble_code;
401  uint8_t channel;
402  uint16_t antenna_delay;
403  uint8_t antenna_calib;
404  uint8_t smart_power;
405  uint8_t frame_check;
406  uint8_t permanent_rx;
408 
409 }uwb_dev_t;
410  // End types group
412 // ------------------------------------------------------------------ CONSTANTS
418 extern const uint8_t UWB_TMODE_LONGDATA_RANGE_LOWPOWER[ 3 ];
419 extern const uint8_t UWB_TMODE_LONGDATA_RANGE_ACCURACY[ 3 ];
420 extern const uint8_t UWB_TMODE_LONGDATA_FAST_LOWPOWER[ 3 ];
421 extern const uint8_t UWB_TMODE_LONGDATA_FAST_ACCURACY[ 3 ];
422 extern const uint8_t UWB_TMODE_SHORTDATA_FAST_LOWPOWER[ 3 ];
423 extern const uint8_t UWB_TMODE_SHORTDATA_FAST_ACCURACY[ 3 ];
424  // End constants group
426 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
427 
432 #ifdef __cplusplus
433 extern "C"{
434 #endif
435 
444 void uwb_cfg_setup ( uwb_cfg_t *cfg );
445 
454 err_t uwb_init ( uwb_t *ctx, uwb_cfg_t *cfg );
455 
466 void uwb_generic_write ( uwb_t *ctx, uint8_t reg_adr, uint8_t *tx_buf, uint16_t buf_len );
467 
478 void uwb_generic_read ( uwb_t *ctx, uint8_t reg_adr, uint8_t *rx_buf, uint16_t buf_len );
479 
488 void uwb_set_rst_pin_status ( uwb_t *ctx, uint8_t status );
489 
500 
510 void uwb_read_otp ( uwb_t *ctx, uint16_t otp_adr, uint8_t *rx_buf );
511 
522 void uwb_set_bit ( uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num, uint8_t bit_state );
523 
535 uint8_t uwb_get_bit ( uwb_t *ctx, uint8_t reg_adr, uint16_t bit_num );
536 
547 uint16_t uwb_reg_data_len ( uint8_t reg_adr );
548 
558 void uwb_set_dev_adr_n_network_id ( uwb_t *ctx, uint16_t dev_adr, uint16_t net_id );
559 
570 uint8_t uwb_set_data_rate ( uwb_t *ctx, uint8_t rate );
571 
580 void uwb_set_pulse_freq ( uwb_t *ctx, uint8_t freq );
581 
590 void uwb_set_preamble_len ( uwb_t *ctx, uint8_t prealen );
591 
600 void uwb_set_preable_code ( uwb_t *ctx, uint8_t preamble );
601 
610 void uwb_set_channel ( uwb_t *ctx, uint8_t channel );
611 
620 void uwb_set_transmit_type ( uwb_t *ctx, const uint8_t *t_t );
621 
631 void uwb_get_transmit ( uwb_t *ctx, uint8_t *rx_buf, uint16_t len_buf );
632 
642 uint8_t uwb_get_transmit_len ( uwb_t *ctx );
643 
653 void uwb_set_transmit ( uwb_t *ctx, uint8_t *tx_buf, uint16_t len_buf );
654 
663 void uwb_use_smart_power ( uwb_t *ctx, uint8_t smart_power );
664 
673 void uwb_frame_check ( uint8_t fc_val );
674 
683 void uwb_frame_filter ( uwb_t *ctx, uint8_t ff_val );
684 
694 void uwb_set_mode ( uwb_t *ctx, uint8_t mode );
695 
705 
717 
726 void uwb_clear_status ( uwb_t *ctx );
727 
736 void uwb_int_mask_set ( uwb_t *ctx );
737 
747 void uwb_tune_config ( uwb_t *ctx );
748 
756 void uwb_dev_reset ( uwb_t *ctx );
757 
765 void uwb_enable ( uwb_t *ctx );
766 
767 #ifdef __cplusplus
768 }
769 #endif
770 #endif // _UWB_H_
771  // End public_function group
774 
775 // ------------------------------------------------------------------------- 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:355
uwb_dev_t::dev_mode
uint8_t dev_mode
Definition: uwb.h:394
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:403
uwb_dev_t::permanent_rx
uint8_t permanent_rx
Definition: uwb.h:406
uwb_dev_t::channel
uint8_t channel
Definition: uwb.h:401
uwb_cfg_t::sck
pin_name_t sck
Definition: uwb.h:373
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.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
uwb_dev_t::debounce_clk_en
uint8_t debounce_clk_en
Definition: uwb.h:407
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:400
uwb_t
Click ctx object definition.
Definition: uwb.h:343
uwb_t::cs
digital_out_t cs
Definition: uwb.h:347
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:384
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_dev_t::antenna_delay
uint16_t antenna_delay
Definition: uwb.h:402
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:372
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:404
uwb_t::irq
digital_in_t irq
Definition: uwb.h:351
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:396
uwb_cfg_t::rst
pin_name_t rst
Definition: uwb.h:378
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:368
uwb_set_preable_code
void uwb_set_preable_code(uwb_t *ctx, uint8_t preamble)
Function for setting preamble code.
uwb_dev_t::data_rate
uint8_t data_rate
Definition: uwb.h:398
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:346
uwb_init
err_t uwb_init(uwb_t *ctx, uwb_cfg_t *cfg)
Initialization function.
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:405
uwb_t::offset
uint16_t offset
Definition: uwb.h:360
uwb_frame_check
void uwb_frame_check(uint8_t fc_val)
Function for setting frame check option.
uwb_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: uwb.h:385
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:395
uwb_cfg_t::spi_speed
uint32_t spi_speed
Definition: uwb.h:383
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:397
uwb_dev_t::preamble_len
uint8_t preamble_len
Definition: uwb.h:399
uwb_cfg_t::cs
pin_name_t cs
Definition: uwb.h:374
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:356
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_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:379
uwb_dev_t
Structure for device configuration.
Definition: uwb.h:393
uwb_cfg_t::miso
pin_name_t miso
Definition: uwb.h:371
uwb_frame_filter
void uwb_frame_filter(uwb_t *ctx, uint8_t ff_val)
Function for setting frame filter option.
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]