├── VERSION ├── samples ├── CMakeLists.txt ├── 00_hello_leds │ ├── .gitignore │ ├── sample.yaml │ ├── prj.conf │ ├── readme.md │ ├── CMakeLists.txt │ └── src │ │ └── main.c ├── 01_sit_led_ex │ ├── .gitignore │ ├── sample.yaml │ ├── prj.conf │ ├── readme.md │ ├── CMakeLists.txt │ └── src │ │ └── main.c ├── 02_sit_ble_example │ ├── sample.yaml │ ├── readme.md │ ├── CMakeLists.txt │ ├── prj.conf │ └── src │ │ └── main.c ├── 10_sit_ble_mesh │ ├── sample.yaml │ ├── readme.md │ ├── gccdump.s │ ├── CMakeLists.txt │ ├── src │ │ └── main.c │ └── prj.conf ├── 03a_sit_ss_twr_initator │ ├── prj.conf │ ├── CMakeLists.txt │ └── src │ │ └── main.c ├── 05_sit_ds_twr_initator │ ├── prj.conf │ ├── CMakeLists.txt │ └── src │ │ └── main.c ├── 06_sit_ds_twr_responder │ ├── prj.conf │ ├── CMakeLists.txt │ └── src │ │ └── main.c ├── 04_sit_ss_twr_responder │ ├── prj.conf │ ├── CMakeLists.txt │ └── src │ │ └── main.c ├── 20_sit_ble_json │ ├── prj.conf │ ├── CMakeLists.txt │ └── src │ │ ├── main.cpp │ │ └── main.c ├── 03b_sit_ss_twr_initator_ble_output │ ├── CMakeLists.txt │ ├── prj.conf │ └── src │ │ └── main.cpp ├── 03c_sit_ss_twr_initator_ble_in-output │ ├── CMakeLists.txt │ ├── prj.conf │ └── src │ │ └── main.cpp └── Kconfig ├── lib ├── sit_json │ ├── sit_json_config.c │ ├── Kconfig │ ├── CMakeLists.txt │ └── sit_json.c ├── sit_led │ ├── Kconfig │ ├── CMakeLists.txt │ └── sit_led.c ├── cJSON │ ├── CMakeLists.txt │ └── Kconfig ├── sit_mesh │ ├── CMakeLists.txt │ ├── Kconfig │ └── sit_mesh.c ├── sit_ble │ ├── Kconfig │ ├── CMakeLists.txt │ ├── ble_device.c │ └── cts.c ├── sit │ ├── Kconfig │ ├── CMakeLists.txt │ ├── sit_utils.c │ ├── sit_diagnostic.c │ ├── sit_device.c │ ├── sit_config.c │ └── sit_distance.c ├── CMakeLists.txt └── Kconfig ├── subsys ├── sit_json │ ├── sit_json_config.c │ ├── Kconfig │ ├── CMakeLists.txt │ ├── sit_json.c │ ├── sit_json.h │ └── sit_json_config.h └── CMakeLists.txt ├── zephyr └── module.yml ├── sports_indoor_tracking ├── overlay-debug.conf ├── CMakeLists.txt ├── prj.conf └── src │ └── main.c ├── drivers ├── platform │ ├── shared_defines.h │ ├── CMakeLists.txt │ ├── dw3000_hw.h │ ├── deca_spi.h │ ├── deca_probe_interface.h │ ├── dw3000_spi.h │ ├── board.c │ ├── port.c │ ├── deca_port.c │ ├── port.h │ ├── board.h │ ├── example_selection.h │ ├── dw3000_hw.c │ ├── dw3000_spi.c │ └── config_options.h ├── sensor │ ├── CMakeLists.txt │ ├── veml6030 │ │ ├── CMakeLists.txt │ │ └── Kconfig │ ├── ms8607 │ │ ├── CMakeLists.txt │ │ ├── Kconfig │ │ ├── ms8607_i2c.h │ │ └── ms8607_i2c.c │ └── Kconfig ├── battery │ ├── CMakeLists.txt │ ├── Kconfig │ └── battery.c ├── dw3000 │ ├── lib │ │ ├── libdwt_uwb_driver-m33-hfp-6.0.7.a │ │ ├── libdwt_uwb_driver-m33-sfp-6.0.7.a │ │ ├── libdwt_uwb_driver-m4-hfp-6.0.14.a │ │ ├── libdwt_uwb_driver-m4-hfp-6.0.7.a │ │ ├── libdwt_uwb_driver-m4-sfp-6.0.14.a │ │ └── libdwt_uwb_driver-m4-sfp-6.0.7.a │ ├── custom-sections.ld │ ├── CMakeLists.txt │ └── inc │ │ ├── deca_version.h │ │ ├── .backup │ │ ├── deca_version.h │ │ └── deca_types.h │ │ └── deca_types.h ├── CMakeLists.txt └── Kconfig ├── Kconfig.uwb ├── CMakeLists.txt ├── boards └── arm │ └── qorvo_dwm3001cdk │ ├── Kconfig.board │ ├── qorvo_dwm3001cdk.yaml │ ├── board.cmake │ ├── Kconfig.defconfig │ ├── qorvo_dwm3001cdk_defconfig │ ├── qorvo_dwm3001cdk-pinctrl.dtsi │ └── qorvo_dwm3001cdk.dts ├── dts ├── bindings │ ├── sensor │ │ ├── st,lis2ds12-i2c.yaml │ │ └── st,lis2ds12-common.yaml │ └── decawave,dw3000 │ │ └── qorvo,dw3000.yaml └── arm │ └── qorvo_dwm3001cdk-pinctrl.dtsi ├── include ├── sit_ble │ ├── cts.h │ ├── ble_device.h │ ├── ble_init.h │ └── ble_uuids.h ├── sit_mesh │ └── sit_mesh.h ├── sit_led │ └── sit_led.h ├── sit_json │ ├── sit_json.h │ └── sit_json_config.h └── sit │ ├── sit_diagnostic.h │ ├── sit_utils.h │ ├── sit.h │ ├── sit_distance.h │ ├── sit_device.h │ └── sit_config.h ├── .gitignore ├── west.yml └── README.md /VERSION: -------------------------------------------------------------------------------- 1 | 0.1.0 2 | -------------------------------------------------------------------------------- /samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /lib/sit_json/sit_json_config.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /subsys/sit_json/sit_json_config.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /samples/00_hello_leds/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /samples/01_sit_led_ex/.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /zephyr/module.yml: -------------------------------------------------------------------------------- 1 | build: 2 | cmake: . 3 | kconfig: Kconfig.uwb 4 | -------------------------------------------------------------------------------- /samples/01_sit_led_ex/sample.yaml: -------------------------------------------------------------------------------- 1 | sample: 2 | name: SIT LED Test example 3 | -------------------------------------------------------------------------------- /samples/02_sit_ble_example/sample.yaml: -------------------------------------------------------------------------------- 1 | sample: 2 | name: SIT BLE example 3 | -------------------------------------------------------------------------------- /samples/10_sit_ble_mesh/sample.yaml: -------------------------------------------------------------------------------- 1 | sample: 2 | name: SIT BLE example 3 | -------------------------------------------------------------------------------- /samples/00_hello_leds/sample.yaml: -------------------------------------------------------------------------------- 1 | sample: 2 | name: Hello leds etst sample 3 | -------------------------------------------------------------------------------- /sports_indoor_tracking/overlay-debug.conf: -------------------------------------------------------------------------------- 1 | CONFIG_DEBUG=y 2 | CONFIG_DEBUG_THREAD_INFO=y 3 | CONFIG_DEBUG_OPTIMIZATIONS=y -------------------------------------------------------------------------------- /drivers/platform/shared_defines.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svhoy/uwb_zephyr_dwm3001cdk/HEAD/drivers/platform/shared_defines.h -------------------------------------------------------------------------------- /samples/00_hello_leds/prj.conf: -------------------------------------------------------------------------------- 1 | # Logging 2 | CONFIG_LOG=y 3 | CONFIG_LOG_PRINTK=y 4 | 5 | # Activate SIT_LED 6 | CONFIG_SIT_LED=y -------------------------------------------------------------------------------- /drivers/sensor/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | add_subdirectory_ifdef(CONFIG_VEML6030 veml6030) 3 | add_subdirectory_ifdef(CONFIG_MS8607 ms8607) 4 | -------------------------------------------------------------------------------- /samples/01_sit_led_ex/prj.conf: -------------------------------------------------------------------------------- 1 | # Logging 2 | CONFIG_LOG=y 3 | CONFIG_LOG_PRINTK=y 4 | 5 | #Activate SIT_LED 6 | CONFIG_SIT_LED=y 7 | -------------------------------------------------------------------------------- /lib/sit_json/Kconfig: -------------------------------------------------------------------------------- 1 | config SIT_JSON 2 | bool "SIT JSON Interface" 3 | imply GPIO 4 | help 5 | Enable JSON Parser for SIT System 6 | 7 | -------------------------------------------------------------------------------- /subsys/sit_json/Kconfig: -------------------------------------------------------------------------------- 1 | config SIT_JSON 2 | bool "SIT JSON Interface" 3 | imply GPIO 4 | help 5 | Enable JSON Parser for SIT System 6 | 7 | -------------------------------------------------------------------------------- /Kconfig.uwb: -------------------------------------------------------------------------------- 1 | menu "Sport Indoor Tracking" 2 | 3 | rsource "samples/Kconfig" 4 | rsource "drivers/Kconfig" 5 | rsource "lib/Kconfig" 6 | 7 | endmenu 8 | -------------------------------------------------------------------------------- /lib/sit_led/Kconfig: -------------------------------------------------------------------------------- 1 | config SIT_LED 2 | bool "SIT LED Interface" 3 | imply GPIO 4 | help 5 | Enable Simple way to toggle and set LEDs 6 | 7 | -------------------------------------------------------------------------------- /lib/cJSON/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_SIT_JSON cJSON.c) 6 | -------------------------------------------------------------------------------- /drivers/battery/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_BATTERY battery.c) 6 | -------------------------------------------------------------------------------- /lib/sit_mesh/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_SIT_MESH sit_mesh.c) 6 | -------------------------------------------------------------------------------- /drivers/battery/Kconfig: -------------------------------------------------------------------------------- 1 | config BATTERY 2 | bool "BATTERY ADC VDD" 3 | depends on ADC 4 | help 5 | Enable driver for measuring Battery through ADC VDD Channel. 6 | -------------------------------------------------------------------------------- /drivers/dw3000/lib/libdwt_uwb_driver-m33-hfp-6.0.7.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svhoy/uwb_zephyr_dwm3001cdk/HEAD/drivers/dw3000/lib/libdwt_uwb_driver-m33-hfp-6.0.7.a -------------------------------------------------------------------------------- /drivers/dw3000/lib/libdwt_uwb_driver-m33-sfp-6.0.7.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svhoy/uwb_zephyr_dwm3001cdk/HEAD/drivers/dw3000/lib/libdwt_uwb_driver-m33-sfp-6.0.7.a -------------------------------------------------------------------------------- /drivers/dw3000/lib/libdwt_uwb_driver-m4-hfp-6.0.14.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svhoy/uwb_zephyr_dwm3001cdk/HEAD/drivers/dw3000/lib/libdwt_uwb_driver-m4-hfp-6.0.14.a -------------------------------------------------------------------------------- /drivers/dw3000/lib/libdwt_uwb_driver-m4-hfp-6.0.7.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svhoy/uwb_zephyr_dwm3001cdk/HEAD/drivers/dw3000/lib/libdwt_uwb_driver-m4-hfp-6.0.7.a -------------------------------------------------------------------------------- /drivers/dw3000/lib/libdwt_uwb_driver-m4-sfp-6.0.14.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svhoy/uwb_zephyr_dwm3001cdk/HEAD/drivers/dw3000/lib/libdwt_uwb_driver-m4-sfp-6.0.14.a -------------------------------------------------------------------------------- /drivers/dw3000/lib/libdwt_uwb_driver-m4-sfp-6.0.7.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/svhoy/uwb_zephyr_dwm3001cdk/HEAD/drivers/dw3000/lib/libdwt_uwb_driver-m4-sfp-6.0.7.a -------------------------------------------------------------------------------- /drivers/sensor/veml6030/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_VEML6030 veml6030.c) 6 | -------------------------------------------------------------------------------- /lib/sit_led/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_SIT_LED sit_led.c) 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /samples/00_hello_leds/readme.md: -------------------------------------------------------------------------------- 1 | ## usage 2 | ```bash 3 | west build -t guiconfig 4 | west build -b decawave_dwm1001_dev -- -DCONF_FILE=prj.conf 5 | west flash 6 | ``` 7 | -------------------------------------------------------------------------------- /samples/01_sit_led_ex/readme.md: -------------------------------------------------------------------------------- 1 | ## usage 2 | ```bash 3 | west build -t guiconfig 4 | west build -b decawave_dwm1001_dev -- -DCONF_FILE=prj.conf 5 | west flash 6 | ``` 7 | -------------------------------------------------------------------------------- /samples/10_sit_ble_mesh/readme.md: -------------------------------------------------------------------------------- 1 | ## usage 2 | ```bash 3 | west build -t guiconfig 4 | west build -b decawave_dwm1001_dev -- -DCONF_FILE=prj.conf 5 | west flash 6 | ``` 7 | -------------------------------------------------------------------------------- /samples/02_sit_ble_example/readme.md: -------------------------------------------------------------------------------- 1 | ## usage 2 | ```bash 3 | west build -t guiconfig 4 | west build -b decawave_dwm1001_dev -- -DCONF_FILE=prj.conf 5 | west flash 6 | ``` 7 | -------------------------------------------------------------------------------- /drivers/platform/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | zephyr_library_sources(dw3000_hw.c dw3000_spi.c deca_port.c) 5 | zephyr_include_directories(.) 6 | -------------------------------------------------------------------------------- /lib/cJSON/Kconfig: -------------------------------------------------------------------------------- 1 | config cJSON 2 | bool "cJSON Lib" 3 | help 4 | Enable cJSON Funcionality 5 | 6 | config SIT_CTS 7 | bool "SIT CTS Interface" 8 | help 9 | Enable CTS Funcionality 10 | 11 | -------------------------------------------------------------------------------- /drivers/sensor/ms8607/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_MS8607 ms8607.c) 6 | zephyr_library_sources_ifdef(CONFIG_MS8607 ms8607_i2c.c) 7 | -------------------------------------------------------------------------------- /lib/sit_json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_SIT_JSON sit_json.c) 6 | zephyr_library_sources_ifdef(CONFIG_SIT_JSON sit_json_config.c) 7 | -------------------------------------------------------------------------------- /subsys/sit_json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_SIT_JSON sit_json.c) 6 | zephyr_library_sources_ifdef(CONFIG_SIT_JSON sit_json_config.c) 7 | -------------------------------------------------------------------------------- /lib/sit_mesh/Kconfig: -------------------------------------------------------------------------------- 1 | 2 | 3 | config SIT_MESH 4 | bool "SIT Mesh Interface" 5 | imply SIT_LED 6 | imply BT 7 | imply BT_BROADCASTER 8 | imply BT_OBSERVER 9 | imply BT_MESH 10 | help 11 | Enable BLE Mesh Funcionality -------------------------------------------------------------------------------- /drivers/sensor/Kconfig: -------------------------------------------------------------------------------- 1 | menuconfig SENSOR 2 | bool "Sensor Drivers" 3 | help 4 | Include sensor drivers in config 5 | 6 | if SENSOR 7 | 8 | rsource "veml6030/Kconfig" 9 | rsource "ms8607/Kconfig" 10 | 11 | endif # SENSOR 12 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Point to root directory. 2 | set(HSM_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "root directory") 3 | 4 | zephyr_include_directories(include) 5 | 6 | add_subdirectory(samples) 7 | add_subdirectory(drivers) 8 | add_subdirectory(lib) 9 | -------------------------------------------------------------------------------- /lib/sit_ble/Kconfig: -------------------------------------------------------------------------------- 1 | config SIT_BLE 2 | bool "SIT BLE Interface" 3 | imply BT 4 | imply FLASH 5 | help 6 | Enable BLE Funcionality 7 | 8 | config SIT_CTS 9 | bool "SIT CTS Interface" 10 | help 11 | Enable CTS Funcionality 12 | 13 | -------------------------------------------------------------------------------- /boards/arm/qorvo_dwm3001cdk/Kconfig.board: -------------------------------------------------------------------------------- 1 | # Qorvo DWM3001 board configuration 2 | 3 | # Copyright (c) 2022 Sven Hoyer 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | config BOARD_QORVO_DWM3001CDK 7 | bool "Qorvo DWM3001CDK" 8 | depends on SOC_NRF52833_QIAA -------------------------------------------------------------------------------- /drivers/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | zephyr_include_directories(platform) 2 | 3 | add_subdirectory_ifdef(CONFIG_DW3000 dw3000) 4 | add_subdirectory_ifdef(CONFIG_DW3000 platform) 5 | add_subdirectory_ifdef(CONFIG_SENSOR sensor) 6 | add_subdirectory_ifdef(CONFIG_BATTERY battery) 7 | 8 | -------------------------------------------------------------------------------- /boards/arm/qorvo_dwm3001cdk/qorvo_dwm3001cdk.yaml: -------------------------------------------------------------------------------- 1 | identifier: qorvo_dwm3001cdk 2 | name: Qrovo-DWM3001CDK 3 | type: mcu 4 | arch: arm 5 | toolchain: 6 | - zephyr 7 | - gnuarmemb 8 | - xtools 9 | ram: 64 10 | flash: 512 11 | supported: 12 | - spi 13 | - i2c -------------------------------------------------------------------------------- /lib/sit_ble/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_SIT_BLE ble_device.c) 6 | zephyr_library_sources_ifdef(CONFIG_SIT_BLE ble_init.c) 7 | 8 | zephyr_library_sources_ifdef(CONFIG_CTS cts.c) 9 | -------------------------------------------------------------------------------- /drivers/sensor/ms8607/Kconfig: -------------------------------------------------------------------------------- 1 | # MS8607 temperature, humidity and pressure configuration options 2 | 3 | config MS8607 4 | bool "MS8607 temperature, humidity and pressure Sensor" 5 | depends on I2C 6 | help 7 | Enable driver for MS8607 temperature, humidity and pressure sensors. 8 | -------------------------------------------------------------------------------- /dts/bindings/sensor/st,lis2ds12-i2c.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2019 STMicroelectronics 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | description: STMicroelectronics LIS2DS12 3-axis accelerometer 5 | 6 | compatible: "st,lis2ds12" 7 | 8 | include: ["i2c-device.yaml", "st,lis2ds12-common.yaml"] 9 | -------------------------------------------------------------------------------- /samples/03a_sit_ss_twr_initator/prj.conf: -------------------------------------------------------------------------------- 1 | 2 | # Activate SIT Subsys 3 | CONFIG_SIT=y 4 | 5 | # Logging 6 | CONFIG_LOG=y 7 | CONFIG_LOG_PRINTK=y 8 | CONFIG_CBPRINTF_FP_SUPPORT=y 9 | 10 | # newlib is used to include extended math.h funcions (e.g. fabs()) 11 | CONFIG_NEWLIB_LIBC=y 12 | -------------------------------------------------------------------------------- /samples/05_sit_ds_twr_initator/prj.conf: -------------------------------------------------------------------------------- 1 | 2 | # Activate SIT Subsys 3 | CONFIG_SIT=y 4 | 5 | # Logging 6 | CONFIG_LOG=y 7 | CONFIG_LOG_PRINTK=y 8 | CONFIG_CBPRINTF_FP_SUPPORT=y 9 | 10 | # newlib is used to include extended math.h funcions (e.g. fabs()) 11 | CONFIG_NEWLIB_LIBC=y 12 | -------------------------------------------------------------------------------- /samples/06_sit_ds_twr_responder/prj.conf: -------------------------------------------------------------------------------- 1 | 2 | # Activate SIT Subsys 3 | CONFIG_SIT=y 4 | 5 | # Logging 6 | CONFIG_LOG=y 7 | CONFIG_LOG_PRINTK=y 8 | CONFIG_CBPRINTF_FP_SUPPORT=y 9 | 10 | # newlib is used to include extended math.h funcions (e.g. fabs()) 11 | CONFIG_NEWLIB_LIBC=y 12 | -------------------------------------------------------------------------------- /lib/sit/Kconfig: -------------------------------------------------------------------------------- 1 | config SIT 2 | bool "SIT Interface" 3 | imply SIT_LED 4 | help 5 | Enable All Sit Features for an Sports Indoor Tracking System (SIT) 6 | 7 | config SIT_DIAGNOSTIC 8 | bool "SIT Diagnostic Interface" 9 | help 10 | Enable All Sit Diagnostic Features for distance measurements -------------------------------------------------------------------------------- /samples/04_sit_ss_twr_responder/prj.conf: -------------------------------------------------------------------------------- 1 | 2 | # Activate SIT Subsys 3 | CONFIG_SIT=y 4 | CONFIG_SIT_LED=y 5 | 6 | # Logging 7 | CONFIG_LOG=y 8 | CONFIG_LOG_PRINTK=y 9 | CONFIG_CBPRINTF_FP_SUPPORT=y 10 | 11 | # newlib is used to include extended math.h funcions (e.g. fabs()) 12 | CONFIG_NEWLIB_LIBC=y 13 | -------------------------------------------------------------------------------- /drivers/sensor/veml6030/Kconfig: -------------------------------------------------------------------------------- 1 | # VEML6030 light sensor configuration options 2 | 3 | # Copyright (c) 2016 Intel Corporation 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | config VEML6030 7 | bool "VEML6030 Light Sensor" 8 | depends on I2C 9 | help 10 | Enable driver for VEML6030 light sensors. 11 | -------------------------------------------------------------------------------- /lib/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory_ifdef(CONFIG_SIT sit) 2 | add_subdirectory_ifdef(CONFIG_SIT_BLE sit_ble) 3 | add_subdirectory_ifdef(CONFIG_SIT_LED sit_led) 4 | add_subdirectory_ifdef(CONFIG_SIT_MESH sit_mesh) 5 | add_subdirectory_ifdef(CONFIG_SIT_JSON sit_json) 6 | add_subdirectory_ifdef(CONFIG_SIT_JSON cJSON) 7 | -------------------------------------------------------------------------------- /drivers/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Device Drivers" 2 | 3 | rsource "sensor/Kconfig" 4 | 5 | rsource "battery/Kconfig" 6 | 7 | endmenu 8 | 9 | menuconfig DW3000 10 | bool "DW3000" 11 | depends on SPI 12 | help 13 | Qorvo/Decawave DW3000 driver 14 | 15 | module = DW3000 16 | module-str = dw3000 17 | source "subsys/logging/Kconfig.template.log_config" 18 | -------------------------------------------------------------------------------- /lib/Kconfig: -------------------------------------------------------------------------------- 1 | menu "SIT LIBs" 2 | 3 | rsource "sit_ble/Kconfig" 4 | 5 | rsource "sit_led/Kconfig" 6 | 7 | rsource "sit/Kconfig" 8 | 9 | rsource "sit_mesh/Kconfig" 10 | 11 | rsource "sit_json/Kconfig" 12 | 13 | rsource "cJSON/Kconfig" 14 | 15 | endmenu 16 | 17 | menuconfig SIT 18 | bool "Sport Indoor Tracking" 19 | help 20 | Include SIT LIB 21 | -------------------------------------------------------------------------------- /include/sit_ble/cts.h: -------------------------------------------------------------------------------- 1 | /** @file 2 | * @brief CTS Service sample 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2016 Intel Corporation 7 | * 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | void cts_init(void); 16 | void cts_notify(void); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | -------------------------------------------------------------------------------- /boards/arm/qorvo_dwm3001cdk/board.cmake: -------------------------------------------------------------------------------- 1 | board_runner_args(jlink "--device=nRF52833_xxAA" "--speed=4000") 2 | board_runner_args(pyocd "--target=nrf52833") 3 | set(OPENOCD_NRF5_SUBFAMILY "nrf52") 4 | include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) 5 | include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) 6 | include(${ZEPHYR_BASE}/boards/common/pyocd.board.cmake) -------------------------------------------------------------------------------- /samples/00_hello_leds/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1) 2 | 3 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 4 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(BOARD qorvo_dwm3001cdk) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(hello_leds) 9 | 10 | 11 | target_sources(app PRIVATE src/main.c) 12 | -------------------------------------------------------------------------------- /samples/01_sit_led_ex/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1) 2 | 3 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 4 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(BOARD qorvo_dwm3001cdk) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sit_led_example) 9 | 10 | 11 | target_sources(app PRIVATE src/main.c) 12 | -------------------------------------------------------------------------------- /samples/10_sit_ble_mesh/gccdump.s: -------------------------------------------------------------------------------- 1 | .cpu arm7tdmi 2 | .eabi_attribute 20, 1 3 | .eabi_attribute 21, 1 4 | .eabi_attribute 23, 3 5 | .eabi_attribute 24, 1 6 | .eabi_attribute 25, 1 7 | .eabi_attribute 26, 1 8 | .eabi_attribute 30, 6 9 | .eabi_attribute 34, 0 10 | .eabi_attribute 18, 4 11 | .file "" 12 | .text 13 | .ident "GCC: (Zephyr SDK 0.14.1) 10.3.0" 14 | -------------------------------------------------------------------------------- /samples/02_sit_ble_example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1) 2 | 3 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 4 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(BOARD qorvo_dwm3001cdk) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sit_ble_example) 9 | 10 | 11 | target_sources(app PRIVATE src/main.c) 12 | -------------------------------------------------------------------------------- /samples/10_sit_ble_mesh/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.13.1) 2 | 3 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 4 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(BOARD qorvo_dwm3001cdk) 6 | 7 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 8 | project(sit_ble_example) 9 | 10 | 11 | target_sources(app PRIVATE src/main.c) 12 | -------------------------------------------------------------------------------- /subsys/sit_json/sit_json.c: -------------------------------------------------------------------------------- 1 | #include "sit_json.h" 2 | 3 | int json_distance_parser(char *json, size_t len, void *val) { 4 | int ret = json_obj_parse(json, 5 | len, 6 | distance_msg_descr, 7 | ARRAY_SIZE(distance_msg_descr), 8 | val); 9 | return ret; 10 | } -------------------------------------------------------------------------------- /include/sit_mesh/sit_mesh.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sit_mesh.h 3 | */ 4 | #ifndef __SIT_MESH_H__ 5 | #define __SIT_MESH_H__ 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | 13 | void sit_mesh_init(void); 14 | void sit_mesh_prov_init(void); 15 | 16 | bool sit_mesh_is_provisioned(void); 17 | 18 | 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif 23 | 24 | 25 | #endif //__SIT_MESH_H__ -------------------------------------------------------------------------------- /subsys/sit_json/sit_json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sit_json.h 3 | */ 4 | #ifndef __SIT_JSON_H__ 5 | #define __SIT_JSON_H__ 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | #include 12 | 13 | #include "sit_json_config.h" 14 | 15 | int json_distance_parser(char *json, size_t len, void *val); 16 | 17 | #ifdef __cplusplus 18 | } 19 | #endif 20 | 21 | 22 | #endif // __SIT_JSON_H__ -------------------------------------------------------------------------------- /drivers/dw3000/custom-sections.ld: -------------------------------------------------------------------------------- 1 | SECTION_PROLOGUE(.dw_drivers,,) 2 | { 3 | . = ALIGN(4); 4 | dw_drivers_load_start = .; 5 | dw_drivers_start = .; 6 | __dw_drivers_start = dw_drivers_start; 7 | KEEP(*(.dw_drivers .dw_drivers.)) 8 | . = ALIGN(4); 9 | } GROUP_LINK_IN(ROMABLE_REGION) 10 | 11 | dw_drivers_end = dw_drivers_start + SIZEOF(.dw_drivers); 12 | dw_drivers_size = SIZEOF(.dw_drivers); 13 | __dw_drivers_end = dw_drivers_end; 14 | dw_drivers_load_end = dw_drivers_end; 15 | -------------------------------------------------------------------------------- /boards/arm/qorvo_dwm3001cdk/Kconfig.defconfig: -------------------------------------------------------------------------------- 1 | # DecaWave DWM1001 board configuration 2 | 3 | # Copyright (c) 2019 Stéphane D'Alu 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | if BOARD_QORVO_DWM3001CDK 7 | 8 | config BOARD 9 | default "qorvo_dwm3001cdk" 10 | 11 | config BT_CTLR 12 | default BT 13 | 14 | config I2C 15 | default SENSOR 16 | 17 | config GPIO 18 | default y 19 | 20 | config SPI 21 | default y 22 | depends on IEEE802154 23 | 24 | endif # BOARD_QORVO_DWM3001CDK -------------------------------------------------------------------------------- /drivers/platform/dw3000_hw.h: -------------------------------------------------------------------------------- 1 | #ifndef DW3000_HW_H 2 | #define DW3000_HW_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | int dw3000_hw_init(void); 9 | int dw3000_hw_init_interrupt(void); 10 | void dw3000_hw_fini(void); 11 | void dw3000_hw_reset(void); 12 | void dw3000_hw_wakeup(void); 13 | void dw3000_hw_wakeup_pin_low(void); 14 | void dw3000_hw_interrupt_enable(void); 15 | void dw3000_hw_interrupt_disable(void); 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | #endif 20 | -------------------------------------------------------------------------------- /samples/20_sit_ble_json/prj.conf: -------------------------------------------------------------------------------- 1 | CONFIG_HEAP_MEM_POOL_SIZE=4096 2 | CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 3 | 4 | # Activate SIT Subsys 5 | CONFIG_SIT_LED=ys 6 | 7 | # Logging 8 | CONFIG_LOG=y 9 | CONFIG_LOG_PRINTK=y 10 | CONFIG_CBPRINTF_FP_SUPPORT=y 11 | 12 | # newlib is used to include extended math.h funcions (e.g. fabs()) 13 | CONFIG_NEWLIB_LIBC=y 14 | 15 | #JSON 16 | CONFIG_SIT_JSON=y 17 | 18 | # DEBUG 19 | CONFIG_DEBUG_OPTIMIZATIONS=y 20 | CONFIG_DEBUG_THREAD_INFO=y 21 | 22 | -------------------------------------------------------------------------------- /dts/arm/qorvo_dwm3001cdk-pinctrl.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Nordic Semiconductor 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | &pinctrl { 7 | uart0_default: uart0_default { 8 | group1 { 9 | psels = , 10 | ; 11 | }; 12 | }; 13 | 14 | uart0_sleep: uart0_sleep { 15 | group1 { 16 | psels = , 17 | ; 18 | low-power-enable; 19 | }; 20 | }; 21 | }; -------------------------------------------------------------------------------- /subsys/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | zephyr_library() 2 | 3 | zephyr_include_directories(sit) 4 | zephyr_include_directories(sit_ble) 5 | zephyr_include_directories(sit_led) 6 | zephyr_include_directories(sit_mesh) 7 | zephyr_include_directories(sit_json) 8 | 9 | add_subdirectory_ifdef(CONFIG_SIT sit) 10 | add_subdirectory_ifdef(CONFIG_SIT_BLE sit_ble) 11 | add_subdirectory_ifdef(CONFIG_SIT_LED sit_led) 12 | add_subdirectory_ifdef(CONFIG_SIT_MESH sit_mesh) 13 | add_subdirectory_ifdef(CONFIG_SIT_JSON sit_json) -------------------------------------------------------------------------------- /drivers/platform/deca_spi.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file deca_spi.h 3 | * @brief SPI access functions 4 | * 5 | * @attention 6 | * 7 | * Copyright 2015-2020 (c) DecaWave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | * @author DecaWave 12 | */ 13 | 14 | #ifndef _DECA_SPI_H_ 15 | #define _DECA_SPI_H_ 16 | 17 | // this file is only needed because some examples include it 18 | 19 | #endif /* _DECA_SPI_H_ */ 20 | -------------------------------------------------------------------------------- /sports_indoor_tracking/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sports_indoor_tracking) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.c 16 | ) 17 | 18 | -------------------------------------------------------------------------------- /include/sit_led/sit_led.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ble_device.h 3 | */ 4 | #ifndef __SIT_LED_H__ 5 | #define __SIT_LED_H__ 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | #include 13 | 14 | #define LED0_NODE DT_ALIAS(led0) 15 | #define LED1_NODE DT_ALIAS(led1) 16 | #define LED2_NODE DT_ALIAS(led2) 17 | #define LED3_NODE DT_ALIAS(led3) 18 | 19 | void sit_led_init(void); 20 | void sit_toggle_led(int led_id); 21 | void sit_set_led(int led_id, int state); 22 | 23 | #ifdef __cplusplus 24 | } 25 | #endif 26 | 27 | #endif // __SIT_LED_H__ -------------------------------------------------------------------------------- /drivers/dw3000/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | if(CONFIG_FPU) 4 | set(DWTLIBNAME libdwt_uwb_driver-m4-hfp-6.0.14.a) 5 | else() 6 | set(DWTLIBNAME libdwt_uwb_driver-m4-sfp-6.0.14.a) 7 | endif() 8 | 9 | # use zephyr_library_import in order to get it linked with the 10 | # -Wl,--whole-archive flag (keep all symbols) 11 | zephyr_library_import(dwtlib ${CMAKE_CURRENT_SOURCE_DIR}/lib/${DWTLIBNAME}) 12 | 13 | zephyr_include_directories(inc) 14 | 15 | # the library needs a custom linker script 16 | zephyr_linker_sources(SECTIONS custom-sections.ld) 17 | -------------------------------------------------------------------------------- /include/sit_json/sit_json.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sit_json.h 3 | */ 4 | #ifndef __SIT_JSON_H__ 5 | #define __SIT_JSON_H__ 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | #include "sit_json_config.h" 13 | 14 | int json_distance_parser(char *json, size_t len, void *val); 15 | int json_encode_distance(char **json, double *distance); 16 | int json_decode_state_msg(char *json, json_command_msg_t *command_struct); 17 | int json_decode_setup_msg(char *json, json_setup_msg_t *setup_struct); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif // __SIT_JSON_H__ 24 | -------------------------------------------------------------------------------- /drivers/platform/deca_probe_interface.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file deca_probe_interface.h 3 | * @brief Interface structure. Provides external dependencies required by the 4 | * driver 5 | * 6 | * @attention 7 | * 8 | * Copyright 2015 - 2021 (c) DecaWave Ltd, Dublin, Ireland. 9 | * 10 | * All rights reserved. 11 | * 12 | */ 13 | #ifndef DECA_PROBE_INTERFACE_H 14 | #define DECA_PROBE_INTERFACE_H 15 | 16 | #include "deca_device_api.h" 17 | 18 | extern const struct dwt_probe_s dw3000_probe_interf; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | *.d 3 | *.cmd 4 | *.log 5 | *.pyc 6 | *.swp 7 | *.swo 8 | *~ 9 | build 10 | build-* 11 | build_* 12 | cscope.* 13 | .dir 14 | 15 | /*.patch 16 | 17 | tags 18 | .project 19 | .cproject 20 | .xxproject 21 | .envrc 22 | .vscode 23 | sanity-out* 24 | twister-out* 25 | 26 | doc/_build 27 | doc/nrf/_doxygen/ 28 | doc/nrf/_samples/ 29 | doc/*_warnings.txt 30 | doc/*_doc.log 31 | 32 | ext/lib/bin/supl 33 | ext/lib/bin/libsupl.zip 34 | 35 | #samples 36 | samples/zephyr-dw3000-examples/ 37 | 38 | # python 39 | .venv 40 | 41 | # build 42 | /build* 43 | /twister-out* 44 | 45 | __pycache__/ 46 | -------------------------------------------------------------------------------- /lib/sit/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | zephyr_library() 4 | 5 | zephyr_library_sources_ifdef(CONFIG_SIT sit.c) 6 | zephyr_library_sources_ifdef(CONFIG_SIT sit_config.c) 7 | zephyr_library_sources_ifdef(CONFIG_SIT sit_device.c) 8 | zephyr_library_sources_ifdef(CONFIG_SIT_DIAGNOSTIC sit_diagnostic.c) 9 | zephyr_library_sources_ifdef(CONFIG_SIT sit_distance.c) 10 | zephyr_library_sources_ifdef(CONFIG_SIT sit_utils.c) 11 | 12 | target_sources(app PRIVATE ../../drivers/platform/port.c ../../drivers/platform/config_options.c) 13 | 14 | 15 | zephyr_include_directories(../../drivers/platform) -------------------------------------------------------------------------------- /samples/20_sit_ble_json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sit_ble_json) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.c 16 | ) 17 | 18 | target_include_directories(app PRIVATE ../../drivers/platform) 19 | 20 | 21 | -------------------------------------------------------------------------------- /boards/arm/qorvo_dwm3001cdk/qorvo_dwm3001cdk_defconfig: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | CONFIG_SOC_SERIES_NRF52X=y 4 | CONFIG_SOC_NRF52833_QIAA=y 5 | CONFIG_BOARD_QORVO_DWM3001CDK=y 6 | 7 | # Enable MPU 8 | CONFIG_ARM_MPU=y 9 | 10 | # Enable RTT 11 | CONFIG_USE_SEGGER_RTT=y 12 | 13 | # enable GPIO 14 | CONFIG_GPIO=y 15 | CONFIG_SPI=y 16 | 17 | CONFIG_DW3000=y 18 | 19 | # enable uart driver 20 | CONFIG_SERIAL=y 21 | 22 | # enable console 23 | CONFIG_CONSOLE=y 24 | CONFIG_UART_CONSOLE=y 25 | CONFIG_RTT_CONSOLE=y 26 | 27 | # additional board options 28 | CONFIG_GPIO_AS_PINRESET=y 29 | 30 | CONFIG_PINCTRL=y -------------------------------------------------------------------------------- /samples/04_sit_ss_twr_responder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sit_ds-twr_responder_example) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.c 16 | ) 17 | 18 | target_include_directories(app PRIVATE ../../drivers/platform) 19 | -------------------------------------------------------------------------------- /samples/06_sit_ds_twr_responder/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sit_twr_responder_example) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.c 16 | ) 17 | 18 | target_include_directories(app PRIVATE ../../drivers/platform) 19 | -------------------------------------------------------------------------------- /samples/05_sit_ds_twr_initator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sit_ss_twr_initiator_example) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.c 16 | ) 17 | 18 | target_include_directories(app PRIVATE ../../drivers/platform) 19 | 20 | -------------------------------------------------------------------------------- /samples/03a_sit_ss_twr_initator/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sit_ds_twr_initiator_example) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.c 16 | ) 17 | 18 | target_include_directories(app PRIVATE ../../drivers/platform) 19 | 20 | -------------------------------------------------------------------------------- /samples/03b_sit_ss_twr_initator_ble_output/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sit_ss_twr_initiator_example) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.cpp 16 | ) 17 | 18 | target_include_directories(app PRIVATE ../../drivers/platform) 19 | 20 | 21 | -------------------------------------------------------------------------------- /samples/03c_sit_ss_twr_initator_ble_in-output/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | cmake_minimum_required(VERSION 3.13.1) 3 | 4 | set(BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 5 | set(DTS_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../..") 6 | set(BOARD qorvo_dwm3001cdk) 7 | 8 | find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) 9 | project(sit_ss_twr_initiator_ble_example) 10 | 11 | # the binary only library from Qorvo has problems with -Os or -O2 12 | zephyr_library_compile_options(-O1) 13 | 14 | target_sources(app PRIVATE 15 | src/main.cpp 16 | ) 17 | 18 | target_include_directories(app PRIVATE ../../drivers/platform) 19 | 20 | 21 | -------------------------------------------------------------------------------- /samples/Kconfig: -------------------------------------------------------------------------------- 1 | config UWB_SAMPLES_DEFAULTS 2 | bool "Enable HSM sample default settings" 3 | default n 4 | imply LOG 5 | imply LOG_MINIMAL 6 | imply ASSERT 7 | imply ASSERT_NO_COND_INFO 8 | imply ASSERT_NO_MSG_INFO 9 | imply HW_STACK_PROTECTION if ARCH_HAS_STACK_PROTECTION 10 | help 11 | Use the default configuration for HSM samples. 12 | 13 | if LOG 14 | 15 | # LOG_DEFAULT_LEVEL is declared in Zephyr, 16 | # we declare it here for a second time, to set a different default. 17 | # Omit the `prompt` to prevent it from appearing twice in two diffent places. 18 | 19 | config LOG_DEFAULT_LEVEL 20 | default 1 if UWB_SAMPLES_DEFAULTS 21 | 22 | endif # LOG 23 | -------------------------------------------------------------------------------- /samples/02_sit_ble_example/prj.conf: -------------------------------------------------------------------------------- 1 | # Logging 2 | CONFIG_LOG=y 3 | CONFIG_LOG_PRINTK=y 4 | 5 | #Activate SIT_LED 6 | CONFIG_SIT_LED=y 7 | 8 | # Activate SIT_BLE 9 | CONFIG_SIT_BLE=y 10 | 11 | # Activate Bluetooth 12 | CONFIG_BT=y 13 | CONFIG_BT_DEBUG_LOG=y 14 | CONFIG_BT_SMP=y 15 | CONFIG_BT_SIGNING=y 16 | CONFIG_BT_PERIPHERAL=y 17 | CONFIG_BT_DIS=y 18 | CONFIG_BT_ATT_PREPARE_COUNT=5 19 | CONFIG_BT_BAS=y 20 | CONFIG_BT_PRIVACY=y 21 | CONFIG_BT_DEVICE_NAME="DWM3001" 22 | CONFIG_BT_DEVICE_APPEARANCE=833 23 | CONFIG_BT_DEVICE_NAME_DYNAMIC=y 24 | CONFIG_BT_DEVICE_NAME_MAX=65 25 | 26 | CONFIG_BT_KEYS_OVERWRITE_OLDEST=y 27 | CONFIG_BT_SETTINGS=y 28 | CONFIG_FLASH=y 29 | CONFIG_FLASH_PAGE_LAYOUT=y 30 | CONFIG_FLASH_MAP=y 31 | CONFIG_NVS=y 32 | CONFIG_SETTINGS=y 33 | -------------------------------------------------------------------------------- /samples/03b_sit_ss_twr_initator_ble_output/prj.conf: -------------------------------------------------------------------------------- 1 | # Activate SIT Subsys 2 | CONFIG_SIT=y 3 | 4 | # Logging 5 | CONFIG_LOG=y 6 | CONFIG_LOG_PRINTK=y 7 | CONFIG_CBPRINTF_FP_SUPPORT=y 8 | 9 | # newlib is used to include extended math.h funcions (e.g. fabs()) 10 | CONFIG_NEWLIB_LIBC=y 11 | 12 | #C++ 13 | CONFIG_CPP=y 14 | CONFIG_CPP_MAIN=y 15 | CONFIG_STD_CPP11=n 16 | CONFIG_STD_CPP17=y 17 | CONFIG_STD_CPP20=y 18 | 19 | #BLE 20 | CONFIG_SIT_BLE=y 21 | CONFIG_BT=y 22 | CONFIG_BT_PERIPHERAL=y 23 | CONFIG_BT_DEBUG_LOG=y 24 | CONFIG_BT_SMP=y 25 | CONFIG_BT_SIGNING=y 26 | CONFIG_BT_DIS=y 27 | CONFIG_BT_ATT_PREPARE_COUNT=5 28 | CONFIG_BT_BAS=y 29 | CONFIG_BT_PRIVACY=y 30 | CONFIG_BT_DEVICE_APPEARANCE=833 31 | CONFIG_BT_DEVICE_NAME_DYNAMIC=y 32 | CONFIG_BT_DEVICE_NAME_MAX=65 33 | -------------------------------------------------------------------------------- /samples/03c_sit_ss_twr_initator_ble_in-output/prj.conf: -------------------------------------------------------------------------------- 1 | # Activate SIT Subsys 2 | CONFIG_SIT=y 3 | 4 | # Logging 5 | CONFIG_LOG=y 6 | CONFIG_LOG_PRINTK=y 7 | CONFIG_CBPRINTF_FP_SUPPORT=y 8 | 9 | # newlib is used to include extended math.h funcions (e.g. fabs()) 10 | CONFIG_NEWLIB_LIBC=y 11 | 12 | #C++ 13 | CONFIG_CPP=y 14 | CONFIG_CPP_MAIN=y 15 | CONFIG_STD_CPP11=n 16 | CONFIG_STD_CPP17=y 17 | CONFIG_STD_CPP20=y 18 | 19 | #BLE 20 | CONFIG_SIT_BLE=y 21 | CONFIG_BT=y 22 | CONFIG_BT_PERIPHERAL=y 23 | CONFIG_BT_DEBUG_LOG=y 24 | CONFIG_BT_SMP=y 25 | CONFIG_BT_SIGNING=y 26 | CONFIG_BT_DIS=y 27 | CONFIG_BT_ATT_PREPARE_COUNT=5 28 | CONFIG_BT_BAS=y 29 | CONFIG_BT_PRIVACY=y 30 | CONFIG_BT_DEVICE_APPEARANCE=833 31 | CONFIG_BT_DEVICE_NAME_DYNAMIC=y 32 | CONFIG_BT_DEVICE_NAME_MAX=65 33 | -------------------------------------------------------------------------------- /drivers/platform/dw3000_spi.h: -------------------------------------------------------------------------------- 1 | #ifndef DW3000_SPI_H 2 | #define DW3000_SPI_H 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | 10 | int dw3000_spi_init(void); 11 | void dw3000_spi_fini(void); 12 | void dw3000_spi_wakeup(void); 13 | void dw3000_spi_speed_slow(void); 14 | void dw3000_spi_speed_fast(void); 15 | int dw3000_spi_read(uint16_t headerLength, uint8_t* headerBuffer, 16 | uint16_t readLength, uint8_t* readBuffer); 17 | int dw3000_spi_write(uint16_t headerLength, const uint8_t* headerBuffer, 18 | uint16_t bodyLength, const uint8_t* bodyBuffer); 19 | int dw3000_spi_write_crc(uint16_t headerLength, const uint8_t* headerBuffer, 20 | uint16_t bodyLength, const uint8_t* bodyBuffer, 21 | uint8_t crc8); 22 | #ifdef __cplusplus 23 | } 24 | #endif 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /samples/01_sit_led_ex/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 9 | 10 | 11 | void main(void) 12 | { 13 | printk("Welcome to SIT LED Test Example\n"); 14 | 15 | sit_led_init(); 16 | 17 | while (1) { 18 | sit_toggle_led(1); 19 | k_sleep(K_MSEC(1000)); 20 | sit_toggle_led(1); 21 | sit_toggle_led(0); 22 | k_sleep(K_MSEC(1000)); 23 | sit_toggle_led(0); 24 | sit_toggle_led(2); 25 | k_sleep(K_MSEC(1000)); 26 | sit_toggle_led(2); 27 | sit_toggle_led(3); 28 | k_sleep(K_MSEC(1000)); 29 | sit_toggle_led(3); 30 | sit_toggle_led(2); 31 | k_sleep(K_MSEC(1000)); 32 | sit_toggle_led(2); 33 | sit_toggle_led(0); 34 | k_sleep(K_MSEC(1000)); 35 | sit_toggle_led(0); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /west.yml: -------------------------------------------------------------------------------- 1 | manifest: 2 | version: "0.13" 3 | remotes: 4 | - name: sit 5 | url-base: https://github.com/svhoy/uwb_zephyr_project 6 | - name: zephyrproject 7 | url-base: https://github.com/zephyrproject-rtos 8 | 9 | defaults: 10 | remote: sit 11 | 12 | projects: 13 | - name: zephyr 14 | repo-path: zephyr 15 | remote: zephyrproject 16 | revision: v3.5.0 17 | import: 18 | name-whitelist: 19 | - cmsis 20 | - edtt 21 | - fatfs 22 | - hal_nordic 23 | - libmetal 24 | - littlefs 25 | - lvgl 26 | - mbedtls 27 | - mcumgr 28 | - mipi-sys-t 29 | - net-tools 30 | - nrf_hw_models 31 | - openthread 32 | - segger 33 | - tinycrypt 34 | 35 | self: 36 | path: sit 37 | -------------------------------------------------------------------------------- /dts/bindings/decawave,dw3000/qorvo,dw3000.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022, Bruno Randolf 2 | # 3 | # SPDX-License-Identifier: Apache-2.0 4 | 5 | description: Qorvo DW3000 (SPI) 6 | 7 | compatible: "qorvo,dw3000" 8 | 9 | include: spi-device.yaml 10 | 11 | properties: 12 | reset-gpios: 13 | type: phandle-array 14 | required: true 15 | description: RESET pin (active low) 16 | 17 | irq-gpios: 18 | type: phandle-array 19 | required: true 20 | description: IRQ pin (active high) 21 | 22 | wakeup-gpios: 23 | type: phandle-array 24 | required: false 25 | description: WAKEUP pin (active low) 26 | 27 | spi-pol-gpios: 28 | type: phandle-array 29 | required: false 30 | description: SPI Polarity pin 31 | 32 | spi-pha-gpios: 33 | type: phandle-array 34 | required: false 35 | description: SPI Phase pin -------------------------------------------------------------------------------- /include/sit_json/sit_json_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sit_json.h 3 | */ 4 | 5 | #ifndef __SIT_JSON_CONFIG_H__ 6 | #define __SIT_JSON_CONFIG_H__ 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include "sit_json_config.h" 19 | typedef struct { 20 | char type[16]; 21 | char command[6]; 22 | } json_command_msg_t; 23 | 24 | typedef struct { 25 | char type[16]; 26 | char initiator_device[17]; 27 | uint8_t initiator; 28 | char responder_device[4][17]; 29 | uint8_t responder; 30 | uint32_t min_measurement; 31 | uint32_t max_measurement; 32 | char measurement_type[11]; 33 | char device_type[10]; 34 | uint16_t rx_ant_dly; 35 | uint16_t tx_ant_dly; 36 | } json_setup_msg_t; 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif // __SIT_JSON_H__ 43 | 44 | 45 | -------------------------------------------------------------------------------- /samples/10_sit_ble_mesh/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - Decawave Ltd, Dublin, Ireland. 3 | * Copyright (c) 2022 - Sven Hoyer 4 | * 5 | * This is an Simple Bluetooth Low Energy Example for the 6 | * DWM1001-DEV Board Zephyr 7 | */ 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | 21 | #define APP_NAME "SIMPLE MESH EXAMPLE\n" 22 | 23 | /* size of stack area used by each thread */ 24 | #define STACKSIZE 2048 25 | 26 | void main(void) { 27 | printk(APP_NAME); 28 | printk("==================\n"); 29 | k_sleep(K_SECONDS(2)); 30 | sit_mesh_init(); 31 | sit_led_init(); 32 | 33 | while(1) { 34 | if (sit_mesh_is_provisioned()) { 35 | sit_toggle_led(3); 36 | } else { 37 | sit_toggle_led(0); 38 | } 39 | k_sleep(K_SECONDS(1)); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /samples/02_sit_ble_example/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2015 - Decawave Ltd, Dublin, Ireland. 3 | * Copyright (c) 2022 - Sven Hoyer 4 | * 5 | * This is an Simple Bluetooth Low Energy Example for the 6 | * DWM1001-DEV Board Zephyr 7 | */ 8 | #include 9 | #include 10 | 11 | #include "sit_led.h" 12 | #include "ble_device.h" 13 | 14 | #define APP_NAME "SIMPLE BLE EXAMPLE\n" 15 | 16 | void main(void) { 17 | printk(APP_NAME); 18 | printk("==================\n"); 19 | 20 | sit_led_init(); 21 | ble_device_init(); 22 | 23 | 24 | /* Implement notification. At the moment there is no suitable way 25 | * of starting delayed work so we do it here 26 | */ 27 | while (1) { 28 | k_sleep(K_SECONDS(1)); 29 | 30 | if (is_connected()) { 31 | /* Battery level simulation */ 32 | bas_notify(); 33 | 34 | sit_set_led(1, 0); 35 | } else { 36 | /* Toggle LED while disconnect */ 37 | sit_toggle_led(1); 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /drivers/platform/board.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | LOG_MODULE_REGISTER(port, LOG_LEVEL_INF); 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | int reset_semaphore; 17 | 18 | void Sleep(uint32_t Delay) 19 | { 20 | k_msleep(Delay); 21 | } 22 | 23 | void device_init(void) { 24 | dw3000_hw_init(); 25 | dw3000_hw_reset(); 26 | } 27 | 28 | void reset_DWIC(void) 29 | { 30 | #if 1 31 | dw3000_hw_reset(); 32 | #else 33 | dw3000_spi_speed_slow(); 34 | dwt_softreset(reset_semaphore); 35 | dw3000_spi_speed_fast(); 36 | #endif 37 | } 38 | 39 | void port_set_dw_ic_spi_slowrate(void) 40 | { 41 | dw3000_spi_speed_slow(); 42 | } 43 | 44 | void port_set_dw_ic_spi_fastrate(void) 45 | { 46 | dw3000_spi_speed_fast(); 47 | } 48 | 49 | void port_set_dwic_isr(port_deca_isr_t deca_isr) 50 | { 51 | dw3000_hw_init_interrupt(); 52 | } 53 | 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif -------------------------------------------------------------------------------- /drivers/platform/port.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "deca_device_api.h" 5 | #include "dw3000_hw.h" 6 | #include "dw3000_spi.h" 7 | #include "port.h" 8 | 9 | #include 10 | LOG_MODULE_REGISTER(port, LOG_LEVEL_INF); 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | int reset_semaphore; 17 | 18 | void Sleep(uint32_t Delay) 19 | { 20 | k_msleep(Delay); 21 | } 22 | 23 | void device_init(void) { 24 | dw3000_hw_init(); 25 | dw3000_hw_reset(); 26 | } 27 | 28 | void reset_DWIC(void) 29 | { 30 | #if 1 31 | dw3000_hw_reset(); 32 | #else 33 | dw3000_spi_speed_slow(); 34 | dwt_softreset(reset_semaphore); 35 | dw3000_spi_speed_fast(); 36 | #endif 37 | } 38 | 39 | void port_set_dw_ic_spi_slowrate(void) 40 | { 41 | dw3000_spi_speed_slow(); 42 | } 43 | 44 | void port_set_dw_ic_spi_fastrate(void) 45 | { 46 | dw3000_spi_speed_fast(); 47 | } 48 | 49 | void port_set_dwic_isr(port_deca_isr_t deca_isr) 50 | { 51 | dw3000_hw_init_interrupt(); 52 | } 53 | 54 | 55 | #ifdef __cplusplus 56 | } 57 | #endif -------------------------------------------------------------------------------- /drivers/platform/deca_port.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "deca_interface.h" 4 | 5 | #include "dw3000_hw.h" 6 | #include "dw3000_spi.h" 7 | 8 | /* This file implements the functions required by decadriver */ 9 | 10 | decaIrqStatus_t decamutexon(void) 11 | { 12 | dw3000_hw_interrupt_disable(); 13 | return 1; 14 | } 15 | 16 | void decamutexoff(decaIrqStatus_t s) 17 | { 18 | // TODO?: s is not used 19 | dw3000_hw_interrupt_enable(); 20 | } 21 | 22 | void deca_sleep(unsigned int time_ms) 23 | { 24 | k_msleep(time_ms); 25 | } 26 | 27 | void deca_usleep(unsigned long time_us) 28 | { 29 | k_usleep(time_us); 30 | } 31 | 32 | static const struct dwt_spi_s dw3000_spi_fct = { 33 | .readfromspi = dw3000_spi_read, 34 | .writetospi = dw3000_spi_write, 35 | .writetospiwithcrc = dw3000_spi_write_crc, 36 | .setslowrate = dw3000_spi_speed_slow, 37 | .setfastrate = dw3000_spi_speed_fast, 38 | }; 39 | 40 | const struct dwt_probe_s dw3000_probe_interf = { 41 | .dw = NULL, 42 | .spi = (void*)&dw3000_spi_fct, 43 | .wakeup_device_with_io = dw3000_hw_wakeup, 44 | }; 45 | -------------------------------------------------------------------------------- /sports_indoor_tracking/prj.conf: -------------------------------------------------------------------------------- 1 | # Activate SIT Subsys 2 | CONFIG_SIT=y 3 | CONFIG_SIT_LED=y 4 | CONFIG_SIT_DIAGNOSTIC=y 5 | CONFIG_SIT_BLE=y 6 | CONFIG_SIT_JSON=y 7 | 8 | # Logging 9 | CONFIG_LOG=y 10 | CONFIG_LOG_PRINTK=y 11 | CONFIG_CBPRINTF_FP_SUPPORT=y 12 | 13 | # newlib is used to include extended math.h funcions (e.g. fabs()) 14 | CONFIG_NEWLIB_LIBC=y 15 | 16 | # HW INFO 17 | CONFIG_HWINFO=y 18 | CONFIG_I2C=y 19 | 20 | #BLE 21 | CONFIG_BT=y 22 | CONFIG_BT_GATT_NOTIFY_MULTIPLE=y 23 | CONFIG_BT_PERIPHERAL=y 24 | CONFIG_BT_SMP=y 25 | CONFIG_BT_SIGNING=y 26 | CONFIG_BT_DIS=n 27 | CONFIG_BT_ATT_PREPARE_COUNT=64 28 | CONFIG_BT_BAS=n 29 | CONFIG_BT_PRIVACY=y 30 | CONFIG_BT_DEVICE_APPEARANCE=833 31 | CONFIG_BT_DEVICE_NAME_DYNAMIC=y 32 | CONFIG_BT_DEVICE_NAME_MAX=65 33 | # Vergrößert den MTU BUFFER auf 251 weil default ist nur 23bytes 34 | CONFIG_BT_BUF_ACL_TX_SIZE=251 35 | CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 36 | CONFIG_BT_BUF_ACL_RX_SIZE=251 37 | CONFIG_BT_L2CAP_TX_MTU=247 38 | CONFIG_BT_HCI_TX_STACK_SIZE=1024 39 | 40 | CONFIG_HEAP_MEM_POOL_SIZE=4096 41 | CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=4096 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /subsys/sit_json/sit_json_config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * sit_json.h 3 | */ 4 | 5 | #ifndef __SIT_JSON_CONFIG_H__ 6 | #define __SIT_JSON_CONFIG_H__ 7 | 8 | #ifdef __cplusplus 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "sit_json_config.h" 18 | 19 | struct json_data { 20 | char state[10]; 21 | uint8_t distance; 22 | uint8_t test_id; 23 | 24 | }; 25 | 26 | struct json_distance_msg { 27 | char type[12]; 28 | struct json_data data; 29 | }; 30 | 31 | static const struct json_obj_descr data_descr[] = { 32 | JSON_OBJ_DESCR_PRIM(struct json_data, state, JSON_TOK_STRING), 33 | JSON_OBJ_DESCR_PRIM(struct json_data, distance, JSON_TOK_NUMBER), 34 | JSON_OBJ_DESCR_PRIM(struct json_data, test_id, JSON_TOK_NUMBER), 35 | }; 36 | 37 | static const struct json_obj_descr distance_msg_descr[] = { 38 | JSON_OBJ_DESCR_PRIM(struct json_distance_msg, type, JSON_TOK_STRING), 39 | JSON_OBJ_DESCR_OBJECT(struct json_distance_msg, data, data_descr), 40 | }; 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif // __SIT_JSON_H__ 47 | 48 | 49 | -------------------------------------------------------------------------------- /lib/sit_ble/ble_device.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ble_device.c 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | #include "sit_ble/ble_device.h" 16 | #include "sit_ble/ble_init.h" 17 | 18 | #define LOG_LEVEL 3 19 | #include 20 | LOG_MODULE_REGISTER(ble_device); 21 | 22 | uint8_t ble_set_device_name(const char * name) 23 | { 24 | int err = 0; 25 | 26 | bt_set_name(name); 27 | if(err < 0) { 28 | LOG_ERR("Name not set: %d", err); 29 | } 30 | 31 | return 0; 32 | } 33 | 34 | void ble_device_address(void){ 35 | char addr_s[BT_ADDR_LE_STR_LEN]; 36 | bt_addr_le_t addr = {0}; 37 | size_t count = 1; 38 | bt_id_get(&addr, &count); 39 | bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s)); 40 | printk("Device address: %s \n", addr_s); 41 | } 42 | 43 | void ble_device_name(void) { 44 | printk("Device Name: %s\n", bt_get_name()); 45 | } 46 | 47 | void ble_device_init(void) { 48 | sit_ble_init(); 49 | } -------------------------------------------------------------------------------- /drivers/platform/port.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file port.h 3 | * @brief HW specific definitions and functions for portability 4 | * 5 | * @attention 6 | * 7 | * Copyright 2015-2020 (c) DecaWave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | * @author DecaWave 12 | */ 13 | 14 | #ifndef PORT_H_ 15 | #define PORT_H_ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifndef FALSE 26 | #define FALSE 0 27 | #endif 28 | 29 | #ifndef TRUE 30 | #define TRUE 1 31 | #endif 32 | 33 | #if CONFIG_SOC_SERIES_NRF52X 34 | #define NRF52840_XXAA 35 | #endif 36 | 37 | #define UNUSED(X) (void)X 38 | #define UNUSED_PARAMETER(X) (void)X 39 | 40 | typedef void (*port_deca_isr_t)(void); 41 | 42 | void Sleep(uint32_t Delay); 43 | void device_init(void); 44 | void reset_DWIC(void); 45 | void port_set_dw_ic_spi_slowrate(void); 46 | void port_set_dw_ic_spi_fastrate(void); 47 | void port_set_dwic_isr(port_deca_isr_t deca_isr); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* PORT_H_ */ 54 | -------------------------------------------------------------------------------- /drivers/platform/board.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file port.h 3 | * @brief HW specific definitions and functions for portability 4 | * 5 | * @attention 6 | * 7 | * Copyright 2015-2020 (c) DecaWave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | * @author DecaWave 12 | */ 13 | 14 | #ifndef PORT_H_ 15 | #define PORT_H_ 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #ifndef FALSE 26 | #define FALSE 0 27 | #endif 28 | 29 | #ifndef TRUE 30 | #define TRUE 1 31 | #endif 32 | 33 | #if CONFIG_SOC_SERIES_NRF52X 34 | #define NRF52840_XXAA 35 | #endif 36 | 37 | #define UNUSED(X) (void)X 38 | #define UNUSED_PARAMETER(X) (void)X 39 | 40 | typedef void (*port_deca_isr_t)(void); 41 | 42 | void Sleep(uint32_t Delay); 43 | void device_init(void); 44 | void reset_DWIC(void); 45 | void port_set_dw_ic_spi_slowrate(void); 46 | void port_set_dw_ic_spi_fastrate(void); 47 | void port_set_dwic_isr(port_deca_isr_t deca_isr); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* PORT_H_ */ 54 | -------------------------------------------------------------------------------- /boards/arm/qorvo_dwm3001cdk/qorvo_dwm3001cdk-pinctrl.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Nordic Semiconductor 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | &pinctrl { 7 | uart0_default: uart0_default { 8 | group1 { 9 | psels = , 10 | ; 11 | }; 12 | }; 13 | 14 | uart0_sleep: uart0_sleep { 15 | group1 { 16 | psels = , 17 | ; 18 | low-power-enable; 19 | }; 20 | }; 21 | 22 | i2c0_default: i2c0_default { 23 | group1 { 24 | psels = , 25 | ; 26 | }; 27 | }; 28 | 29 | 30 | spi1_default: spi1_default { 31 | group1 { 32 | psels = , 33 | , 34 | ; 35 | }; 36 | }; 37 | 38 | spi3_default: spi3_default { 39 | group1 { 40 | psels = , 41 | , 42 | ; 43 | }; 44 | }; 45 | 46 | pwm0_default: pwm0_default { 47 | group1 { 48 | psels = ; 49 | nordic,invert; 50 | }; 51 | }; 52 | }; -------------------------------------------------------------------------------- /drivers/dw3000/inc/deca_version.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file deca_version.h 3 | * @brief Defines the version info for the DW3XXX device driver including its API 4 | * 5 | * @attention 6 | * 7 | * Copyright 2017 - 2021 (c) Decawave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | */ 12 | 13 | #ifndef _DECA_VERSION_DW3XXX_H_ 14 | #define _DECA_VERSION_DW3XXX_H_ 1 15 | 16 | // 17 | // The DW3XXX device driver is separately version numbered to any version the application using it may have 18 | // 19 | // Two symbols are defined here: one hexadecimal value and one string that includes the hex bytes. 20 | // Both should be updated together in a consistent way when the software is being modified. 21 | // 22 | // The format of the hex version is 0xAABBCC and the string ends with AA.BB.CC, where... 23 | // 24 | // Quantity CC is updated for minor changes/bug fixes that should not need user code changes 25 | // Quantity BB is updated for changes/bug fixes that may need user code changes 26 | // Quantity AA is updated for major changes that will need user code changes 27 | // 28 | 29 | #define DRIVER_NAME "DW3XXX" 30 | 31 | #define DRIVER_VERSION_HEX 0x060014 32 | #define DRIVER_VERSION_STR "DW3XXX Device Driver Version 06.00.14" 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /drivers/dw3000/inc/.backup/deca_version.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file deca_version.h 3 | * @brief Defines the version info for the DW3XXX device driver including its API 4 | * 5 | * @attention 6 | * 7 | * Copyright 2017 - 2021 (c) Decawave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | */ 12 | 13 | #ifndef _DECA_VERSION_DW3XXX_H_ 14 | #define _DECA_VERSION_DW3XXX_H_ 1 15 | 16 | // 17 | // The DW3XXX device driver is separately version numbered to any version the application using it may have 18 | // 19 | // Two symbols are defined here: one hexadecimal value and one string that includes the hex bytes. 20 | // Both should be updated together in a consistent way when the software is being modified. 21 | // 22 | // The format of the hex version is 0xAABBCC and the string ends with AA.BB.CC, where... 23 | // 24 | // Quantity CC is updated for minor changes/bug fixes that should not need user code changes 25 | // Quantity BB is updated for changes/bug fixes that may need user code changes 26 | // Quantity AA is updated for major changes that will need user code changes 27 | // 28 | 29 | #define DRIVER_NAME "DW3XXX" 30 | 31 | #define DRIVER_VERSION_HEX 0x060007 32 | #define DRIVER_VERSION_STR "DW3XXX Device Driver Version 06.00.07" 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /drivers/sensor/ms8607/ms8607_i2c.h: -------------------------------------------------------------------------------- 1 | /** 2 | * \brief MS8607 Temperature sensor driver source file 3 | * 4 | * Copyright (c) 2016 Measurement Specialties. All rights reserved. 5 | * 6 | * For details on programming, refer to ms8607 datasheet : 7 | * http://www.meas-spec.com/downloads/MS8607D.pdf 8 | * 9 | */ 10 | 11 | #ifndef MS8607_I2C_H_INCLUDED 12 | #define MS8607_I2C_H_INCLUDED 13 | 14 | #include 15 | #include 16 | 17 | enum i2c_transfer_direction { 18 | I2C_TRANSFER_WRITE = 0, 19 | I2C_TRANSFER_READ = 1, 20 | }; 21 | 22 | enum status_code { 23 | STATUS_OK = 0x00, 24 | STATUS_ERR_OVERFLOW = 0x01, 25 | STATUS_ERR_TIMEOUT = 0x02, 26 | }; 27 | 28 | struct i2c_master_packet { 29 | // Address to slave device 30 | uint16_t address; 31 | // Length of data array 32 | uint16_t data_length; 33 | // Data array containing all data to be transferred 34 | uint8_t *data; 35 | }; 36 | 37 | struct ms8607_data { 38 | const struct device *i2c; 39 | uint16_t sample; 40 | float humidity; 41 | float pressure; 42 | float temperature; 43 | }; 44 | 45 | 46 | void delay_ms(uint32_t time); 47 | void i2c_master_init(const struct device *dev); 48 | enum status_code i2c_master_read_packet_wait(struct i2c_master_packet *const packet); 49 | enum status_code i2c_master_write_packet_wait(struct i2c_master_packet *const packet); 50 | enum status_code i2c_master_write_packet_wait_no_stop(struct i2c_master_packet *const packet); 51 | 52 | 53 | 54 | #endif /* MS8607_I2C_H_INCLUDED */ 55 | -------------------------------------------------------------------------------- /samples/10_sit_ble_mesh/prj.conf: -------------------------------------------------------------------------------- 1 | # Logging 2 | CONFIG_LOG=y 3 | CONFIG_LOG_PRINTK=y 4 | 5 | CONFIG_INIT_STACKS=y 6 | CONFIG_MAIN_STACK_SIZE=512 7 | CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048 8 | 9 | CONFIG_FLASH=y 10 | CONFIG_FLASH_MAP=y 11 | CONFIG_NVS=y 12 | 13 | 14 | # Activate SIT_BLE 15 | CONFIG_SIT_MESH=y 16 | CONFIG_HWINFO=n 17 | CONFIG_SETTINGS=y 18 | 19 | CONFIG_BT_DEVICE_NAME_DYNAMIC=y 20 | CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 21 | 22 | CONFIG_BT_OBSERVER=y 23 | CONFIG_BT_BROADCASTER=y 24 | CONFIG_BT_CTLR_DUP_FILTER_LEN=0 25 | CONFIG_BT_CTLR_LE_ENC=n 26 | CONFIG_BT_CTLR_LE_PING=n 27 | CONFIG_BT_DATA_LEN_UPDATE=n 28 | CONFIG_BT_PHY_UPDATE=n 29 | CONFIG_BT_CTLR_CHAN_SEL_2=n 30 | CONFIG_BT_CTLR_MIN_USED_CHAN=n 31 | CONFIG_BT_CTLR_ADV_EXT=n 32 | CONFIG_BT_CTLR_PRIVACY=n 33 | 34 | CONFIG_BT_PERIPHERAL=y 35 | 36 | CONFIG_BT=y 37 | CONFIG_BT_TINYCRYPT_ECC=y 38 | 39 | CONFIG_BT_MESH=y 40 | CONFIG_BT_MESH_RELAY=y 41 | CONFIG_BT_MESH_RELAY_ENABLED=n 42 | CONFIG_BT_MESH_BEACON_ENABLED=n 43 | CONFIG_BT_MESH_LOW_POWER=y 44 | CONFIG_BT_MESH_FRIEND=n 45 | 46 | CONFIG_BT_MESH_PB_GATT=y 47 | CONFIG_BT_MESH_PB_ADV=y 48 | CONFIG_BT_MESH_GATT_PROXY=y 49 | 50 | CONFIG_BT_MESH_LPN_SCAN_LATENCY=30 51 | CONFIG_BT_MESH_LPN_RECV_DELAY=40 52 | #CONFIG_BT_MESH_LPN_POLL_TIMEOUT=300 53 | 54 | CONFIG_BT_MESH_SUBNET_COUNT=2 55 | CONFIG_BT_MESH_APP_KEY_COUNT=2 56 | CONFIG_BT_MESH_MODEL_GROUP_COUNT=2 57 | CONFIG_BT_MESH_LABEL_COUNT=3 58 | 59 | CONFIG_BT_DEBUG_LOG=y 60 | CONFIG_BT_MESH_DEBUG=n 61 | CONFIG_BT_MESH_DEBUG_PROVISIONER=n 62 | CONFIG_BT_MESH_DEBUG_PROV=n 63 | CONFIG_BT_MESH_DEBUG_PROV_DEVICE=n -------------------------------------------------------------------------------- /include/sit/sit_diagnostic.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_diagnostic.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Defniton of functions for distance measurement. 25 | * 26 | * This file defines functions for distance measurement for the 27 | * DWM3001cdk in the SIT system. 28 | * 29 | * 30 | * @bug No known bugs. 31 | * @todo everything 32 | */ 33 | 34 | #ifndef __SIT_DIAGNOSTIC_H__ 35 | #define __SIT_DIAGNOSTIC_H__ 36 | 37 | #include "sit_config.h" 38 | #include 39 | 40 | 41 | void get_fp_pp_index(void); 42 | 43 | void get_diagnostic(diagnostic_info *diagnostic); 44 | 45 | #endif // __SIT_DIAGNOSTIC_H__ 46 | -------------------------------------------------------------------------------- /include/sit_ble/ble_device.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_ble_device.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Defniton of device functions for ble. 25 | * 26 | * Defines functions to set and get BLE device informations e.g. name, address. 27 | * 28 | * 29 | * @bug No known bugs. 30 | * @todo everything 31 | */ 32 | #ifndef __BLE_DEVICE_H__ 33 | #define __BLE_DEVICE_H__ 34 | 35 | #ifdef __cplusplus 36 | extern "C" 37 | { 38 | #endif 39 | 40 | #include 41 | 42 | #include "ble_init.h" 43 | 44 | uint8_t ble_set_device_name(const char *name); 45 | void ble_device_name(void); 46 | void ble_device_address(void); 47 | void ble_device_init(void); 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | 54 | #endif //__BLE_DEVICE_H__ -------------------------------------------------------------------------------- /drivers/dw3000/inc/deca_types.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file deca_types.h 3 | * @brief Decawave general type definitions 4 | * 5 | * @attention 6 | * 7 | * Copyright 2013 - 2021 (c) Decawave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | */ 12 | 13 | #ifndef _DECA_TYPES_D0_H_ 14 | #define _DECA_TYPES_D0_H_ 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | #include 22 | #include 23 | 24 | #ifdef STM32F429xx 25 | #ifndef uint8_t 26 | #ifndef _DECA_UINT8_ 27 | #define _DECA_UINT8_ 28 | typedef unsigned char uint8_t; 29 | #endif 30 | #endif 31 | 32 | #ifndef uint16_t 33 | #ifndef _DECA_UINT16_ 34 | #define _DECA_UINT16_ 35 | typedef unsigned short uint16_t; 36 | #endif 37 | #endif 38 | 39 | #ifndef uint32_t 40 | #ifndef _DECA_UINT32_ 41 | #define _DECA_UINT32_ 42 | typedef unsigned long uint32_t; 43 | #endif 44 | #endif 45 | 46 | #ifndef int8_t 47 | #ifndef _DECA_INT8_ 48 | #define _DECA_INT8_ 49 | typedef signed char int8_t; 50 | #endif 51 | #endif 52 | 53 | #ifndef int16_t 54 | #ifndef _DECA_INT16_ 55 | #define _DECA_INT16_ 56 | typedef signed short int16_t; 57 | #endif 58 | #endif 59 | 60 | #ifndef int32_t 61 | #ifndef _DECA_INT32_ 62 | #define _DECA_INT32_ 63 | typedef signed long int32_t; 64 | #endif 65 | #endif 66 | 67 | #ifndef uint64_t 68 | #ifndef _DECA_UINT64_ 69 | #define _DECA_UINT64_ 70 | typedef unsigned long long uint64_t; 71 | #endif 72 | #endif 73 | 74 | #ifndef int64_t 75 | #ifndef _DECA_INT64_ 76 | #define _DECA_INT64_ 77 | typedef signed long long int64_t; 78 | #endif 79 | #endif 80 | #endif // STM32F429xx 81 | 82 | #ifndef NULL 83 | #define NULL ((void *)0UL) 84 | #endif 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif /* DECA_TYPES_H_ */ 91 | -------------------------------------------------------------------------------- /drivers/dw3000/inc/.backup/deca_types.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file deca_types.h 3 | * @brief Decawave general type definitions 4 | * 5 | * @attention 6 | * 7 | * Copyright 2013 - 2021 (c) Decawave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | */ 12 | 13 | #ifndef _DECA_TYPES_D0_H_ 14 | #define _DECA_TYPES_D0_H_ 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | #include 22 | #include 23 | 24 | #ifdef STM32F429xx 25 | #ifndef uint8_t 26 | #ifndef _DECA_UINT8_ 27 | #define _DECA_UINT8_ 28 | typedef unsigned char uint8_t; 29 | #endif 30 | #endif 31 | 32 | #ifndef uint16_t 33 | #ifndef _DECA_UINT16_ 34 | #define _DECA_UINT16_ 35 | typedef unsigned short uint16_t; 36 | #endif 37 | #endif 38 | 39 | #ifndef uint32_t 40 | #ifndef _DECA_UINT32_ 41 | #define _DECA_UINT32_ 42 | typedef unsigned long uint32_t; 43 | #endif 44 | #endif 45 | 46 | #ifndef int8_t 47 | #ifndef _DECA_INT8_ 48 | #define _DECA_INT8_ 49 | typedef signed char int8_t; 50 | #endif 51 | #endif 52 | 53 | #ifndef int16_t 54 | #ifndef _DECA_INT16_ 55 | #define _DECA_INT16_ 56 | typedef signed short int16_t; 57 | #endif 58 | #endif 59 | 60 | #ifndef int32_t 61 | #ifndef _DECA_INT32_ 62 | #define _DECA_INT32_ 63 | typedef signed long int32_t; 64 | #endif 65 | #endif 66 | 67 | #ifndef uint64_t 68 | #ifndef _DECA_UINT64_ 69 | #define _DECA_UINT64_ 70 | typedef unsigned long long uint64_t; 71 | #endif 72 | #endif 73 | 74 | #ifndef int64_t 75 | #ifndef _DECA_INT64_ 76 | #define _DECA_INT64_ 77 | typedef signed long long int64_t; 78 | #endif 79 | #endif 80 | #endif // STM32F429xx 81 | 82 | #ifndef NULL 83 | #define NULL ((void *)0UL) 84 | #endif 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif /* DECA_TYPES_H_ */ 91 | -------------------------------------------------------------------------------- /samples/00_hello_leds/src/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 8 | 9 | #define LED0_NODE DT_ALIAS(led0) 10 | 11 | #define LED1_NODE DT_ALIAS(led1) 12 | 13 | #define LED2_NODE DT_ALIAS(led2) 14 | 15 | #define LED3_NODE DT_ALIAS(led3) 16 | 17 | 18 | static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); 19 | static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); 20 | static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); 21 | static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios); 22 | 23 | void main(void) 24 | { 25 | printk("Welcome to Hello LED Test Example\n"); 26 | LOG_INF("Hello world leds sample"); 27 | 28 | gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE); 29 | gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE); 30 | gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE); 31 | gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE); 32 | gpio_pin_set_dt(&led0, 0); 33 | gpio_pin_set_dt(&led1, 0); 34 | gpio_pin_set_dt(&led2, 0); 35 | gpio_pin_set_dt(&led3, 0); 36 | k_sleep(K_MSEC(1000)); 37 | gpio_pin_set_dt(&led0, 1); 38 | gpio_pin_set_dt(&led1, 1); 39 | gpio_pin_set_dt(&led2, 1); 40 | gpio_pin_set_dt(&led3, 1); 41 | k_sleep(K_MSEC(1000)); 42 | 43 | int count = 0; 44 | while (1) { 45 | count++; 46 | LOG_INF("leds> hello %d",count); 47 | gpio_pin_set_dt(&led1, 0); 48 | k_sleep(K_MSEC(1000)); 49 | gpio_pin_set_dt(&led1, 1); 50 | gpio_pin_set_dt(&led0, 0); 51 | k_sleep(K_MSEC(1000)); 52 | gpio_pin_set_dt(&led0, 1); 53 | gpio_pin_set_dt(&led2, 0); 54 | k_sleep(K_MSEC(1000)); 55 | gpio_pin_set_dt(&led2, 1); 56 | gpio_pin_set_dt(&led3, 0); 57 | k_sleep(K_MSEC(1000)); 58 | gpio_pin_set_dt(&led3, 1); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /lib/sit/sit_utils.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_utils.c 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Utils Functions for SIT System. 25 | * 26 | * This contains function implemantation for handle the DWM 3001 functionality that 27 | * doesn't have to do directly with distance measurement. 28 | * 29 | * @bug No known bugs. 30 | */ 31 | 32 | #include "sit/sit_utils.h" 33 | 34 | #include 35 | 36 | #include 37 | LOG_MODULE_REGISTER(SIT_Utils, LOG_LEVEL_INF); 38 | 39 | 40 | uint64_t get_tx_timestamp_u64(void) 41 | { 42 | uint8_t ts_tab[5]; 43 | uint64_t ts = 0; 44 | int i; 45 | 46 | dwt_readtxtimestamp(ts_tab); 47 | for (i = 4; i >= 0; i--) { 48 | ts <<= 8; 49 | ts |= ts_tab[i]; 50 | } 51 | return ts; 52 | } 53 | 54 | uint64_t get_rx_timestamp_u64(void) 55 | { 56 | uint8_t ts_tab[5]; 57 | uint64_t ts = 0; 58 | int i; 59 | 60 | dwt_readrxtimestamp(ts_tab); 61 | for (i = 4; i >= 0; i--) { 62 | ts <<= 8; 63 | ts |= ts_tab[i]; 64 | } 65 | return ts; 66 | } 67 | 68 | -------------------------------------------------------------------------------- /drivers/battery/battery.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | LOG_MODULE_REGISTER(battery, LOG_LEVEL_INF); 9 | 10 | #define ADC_CHANNEL 0 11 | #define ADC_RESOLUTION 12 12 | #define ADC_GAIN ADC_GAIN_1_6 13 | #define ADC_REFERENCE ADC_REF_INTERNAL 14 | #define ADC_ACQUISITION_TIME ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS,40) 15 | 16 | const struct device *dev_adc; 17 | static int16_t sample; 18 | int32_t adc_vref; 19 | struct adc_channel_cfg channel_cfg = { 20 | .gain = ADC_GAIN, 21 | .reference = ADC_REFERENCE, 22 | .acquisition_time = ADC_ACQUISITION_TIME, 23 | .channel_id = ADC_CHANNEL, 24 | #ifdef CONFIG_ADC_CONFIGURABLE_INPUTS 25 | .differential = 0, 26 | .input_positive = SAADC_CH_PSELN_PSELN_VDD 27 | #else 28 | .differential = 0 29 | #endif 30 | }; 31 | 32 | struct adc_sequence sequence = { 33 | .channels = BIT(ADC_CHANNEL), 34 | .buffer = &sample, 35 | /* buffer size in bytes, not number of samples */ 36 | .buffer_size = sizeof(sample), 37 | .resolution = ADC_RESOLUTION, 38 | }; 39 | 40 | void battery_init() 41 | { 42 | dev_adc = device_get_binding(DT_LABEL(DT_NODELABEL(adc))); 43 | if (!device_is_ready(dev_adc)) { 44 | LOG_ERR("ADC device not found\n"); 45 | return; 46 | } 47 | 48 | adc_channel_setup(dev_adc, &channel_cfg); 49 | adc_vref = adc_ref_internal(dev_adc); 50 | 51 | LOG_INF("battery_init() vref = %d",adc_vref); 52 | } 53 | 54 | void battery_start() 55 | { 56 | int err = adc_read(dev_adc, &sequence); 57 | if (err != 0) { 58 | LOG_ERR("ADC reading failed with error %d.\n", err); 59 | return; 60 | }else{ 61 | LOG_INF("battery_start> adc_read()"); 62 | } 63 | } 64 | 65 | int32_t battery_get_mv() 66 | { 67 | int32_t raw_value = sample; 68 | LOG_INF("battery_get_mv() raw = %d",raw_value); 69 | int32_t mv_value = raw_value; 70 | adc_raw_to_millivolts(adc_vref, ADC_GAIN,ADC_RESOLUTION, &mv_value); 71 | return mv_value; 72 | } 73 | -------------------------------------------------------------------------------- /dts/bindings/sensor/st,lis2ds12-common.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2021 STMicroelectronics 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | properties: 5 | irq-gpios: 6 | type: phandle-array 7 | required: false 8 | description: | 9 | DRDY pin 10 | 11 | This pin defaults to active high when produced by the sensor. 12 | The property value should ensure the flags properly describe 13 | the signal that is presented to the driver. 14 | 15 | range: 16 | type: int 17 | required: false 18 | default: 2 19 | description: | 20 | Range in g. Default is power-up configuration. 21 | 22 | enum: 23 | - 16 # 16g (0.488 mg/LSB) 24 | - 8 # 8g (0.244 mg/LSB) 25 | - 4 # 4g (0.122 mg/LSB) 26 | - 2 # 2g (0.061 mg/LSB) 27 | 28 | power-mode: 29 | type: int 30 | required: false 31 | default: 0 32 | description: | 33 | Specify the sensor power mode. Default is power-down mode 34 | 35 | enum: 36 | - 0 # Power Down (PD) 37 | - 1 # Low Power (LP) 38 | - 2 # High Resolution (HR) 39 | - 3 # High Frequency (HF) 40 | 41 | odr: 42 | type: int 43 | required: false 44 | default: 0 45 | description: | 46 | Specify the default output data rate expressed in samples per second (Hz). 47 | Default is power-down mode 48 | enum: 49 | - 0 # Power-Down 50 | - 1 # 1Hz (available in LP mode only) 51 | - 2 # 12.5Hz (available in LP and HR mode) 52 | - 3 # 25Hz (available in LP and HR mode) 53 | - 4 # 50Hz (available in LP and HR mode) 54 | - 5 # 100Hz (available in LP and HR mode) 55 | - 6 # 200Hz (available in LP and HR mode) 56 | - 7 # 400Hz (available in LP and HR mode) 57 | - 8 # 800Hz (available in LP and HR mode) 58 | - 9 # 1600Hz (available in HF mode only) 59 | - 10 # 3200Hz (available in HF mode only) 60 | - 11 # 6400Hz (available in HF mode only) 61 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UWB Indoor Sport Tracking Project 2 | A Zephyr based Project for uwb module DWM3001cdk based on nRF52832 and DW3110 Transceiver. 3 | 4 | I like to implement an localization system for sport useage (espcially Badminton). 5 | 6 | This Project works with different distance measurment types, SS-TWR and ADS-TWR. Maybe more will be added in future. The main Project folder is Sports Indoor Tracking. Besides this I try to provide simple examples to work with differnt stages of the project. 7 | 8 | The main goal is to implent an system, where the devices connect to a gateway via BLE. The gateway will send setup informations, settings and start/stop the measurement process via GATT with a json msg. The DWM3001cdk than send all information from measurement back to the gateway via BLE notify. At the moment there will be send a struct with all data (WIP: this should be json sometime). 9 | 10 | If you have any question, things to improve or you like to add feel free to open an new issue. 11 | 12 | Main topic of this part is to provide the distance measurement process. Localization and calibration algorithmen can be found in the other modules of the whole project. 13 | 14 | # usage 15 | ```bash 16 | west init -m https://github.com/svhoy/uwb_zephyr_dwm3001cdk --mr main 17 | ``` 18 | 19 | # TODO 20 | - Readme.md 21 | - Update old Samples to New Zephyr Version 22 | - Test PIN Descriptions in Board Description 23 | - Update Project to newer Zepyhr Version 24 | 25 | ## Project Overview 26 | In this Project all parts for my Project can be found: [Sports Indoor Tracking Project](https://github.com/users/svhoy/projects/4) 27 | 28 | You will find the Gateway and the magic for localization and calibration in the Backend. 29 | 30 | # Old Projects Takover from DWM1001-DEV 31 | https://github.com/nRFMesh/sdk-uwb-zephyr 32 | driver zephyr port from https://github.com/foldedtoad/dwm1001.git 33 | 34 | * `uwb\drivers\dw1000\decadriver` 35 | * `uwb\drivers\dw1000\platform` 36 | 37 | Also thank you for your help by porting from DWM1001-DEV to DWM3001CDK 38 | https://github.com/br101/zephyr-dw3000-decadriver 39 | -------------------------------------------------------------------------------- /include/sit/sit_utils.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_utils.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Utils Functions for SIT System. 25 | * 26 | * This contains function definiton for handle the DWM 3001 functionality that 27 | * doesn't have to do directly with distance measurement. 28 | * 29 | * 30 | * @bug No known bugs. 31 | */ 32 | 33 | #include 34 | 35 | 36 | /******************************************************************************** 37 | * @brief Get the TX time-stamp in a 64-bit variable. 38 | * /!\ This function assumes that length of time-stamps is 40 bits, 39 | * for both TX and RX! 40 | * 41 | * @param none 42 | * 43 | * @return 64-bit value of the read time-stamp. 44 | */ 45 | uint64_t get_tx_timestamp_u64(void); 46 | 47 | /******************************************************************************** 48 | * @brief Get the RX time-stamp in a 64-bit variable. 49 | * /!\ This function assumes that length of time-stamps is 40 bits, 50 | * for both TX and RX! 51 | * 52 | * @param none 53 | * 54 | * @return 64-bit value of the read time-stamp. 55 | */ 56 | uint64_t get_rx_timestamp_u64(void); 57 | 58 | -------------------------------------------------------------------------------- /drivers/sensor/ms8607/ms8607_i2c.c: -------------------------------------------------------------------------------- 1 | /** 2 | * \file ms8607.c 3 | * 4 | * \brief MS8607 Temperature sensor driver source file 5 | * 6 | * Copyright (c) 2016 Measurement Specialties. All rights reserved. 7 | * 8 | * For details on programming, refer to ms8607 datasheet : 9 | * http://www.meas-spec.com/downloads/MS8607D.pdf 10 | * 11 | */ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | #include "ms8607_i2c.h" 27 | 28 | LOG_MODULE_REGISTER(MS8607, CONFIG_SENSOR_LOG_LEVEL); 29 | 30 | #define SENSOR_LOG_LEVEL_OFF 0 31 | #define SENSOR_LOG_LEVEL_ERROR 1 32 | #define SENSOR_LOG_LEVEL_WARNING 2 33 | #define SENSOR_LOG_LEVEL_INFO 3 34 | #define SENSOR_LOG_LEVEL_DEBUG 4 35 | 36 | 37 | 38 | struct ms8607_data *drv_data; 39 | 40 | void delay_ms(uint32_t time) 41 | { 42 | k_sleep(K_MSEC(time)); 43 | } 44 | 45 | void i2c_master_init(const struct device *dev) 46 | { 47 | drv_data = dev->data; 48 | LOG_INF("ms8607_init> i2c_master_init()"); 49 | } 50 | 51 | enum status_code i2c_master_read_packet_wait(struct i2c_master_packet *const packet) 52 | { 53 | if (i2c_read(drv_data->i2c , packet->data, packet->data_length, packet->address)) { 54 | return STATUS_ERR_TIMEOUT; 55 | } 56 | 57 | return STATUS_OK; 58 | } 59 | 60 | enum status_code i2c_master_write_packet_wait(struct i2c_master_packet *const packet) 61 | { 62 | if(i2c_write(drv_data->i2c , packet->data, packet->data_length, packet->address)){ 63 | return STATUS_ERR_TIMEOUT; 64 | } 65 | 66 | return STATUS_OK; 67 | } 68 | 69 | enum status_code i2c_master_write_packet_wait_no_stop(struct i2c_master_packet *const packet) 70 | { 71 | struct i2c_msg msg; 72 | 73 | msg.buf = packet->data; 74 | msg.len = packet->data_length; 75 | msg.flags = I2C_MSG_WRITE;// | I2C_MSG_STOP removed 76 | 77 | if(i2c_transfer(drv_data->i2c, &msg, 1, packet->address)){ 78 | return STATUS_ERR_TIMEOUT; 79 | } 80 | 81 | return STATUS_OK; 82 | } 83 | 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | -------------------------------------------------------------------------------- /include/sit/sit.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief SIT System entry header. 25 | * 26 | * This is the main entry in the sit system it contains functions for 27 | * init, start stop measurements, define type of measurements and config 28 | * the system. 29 | * 30 | * 31 | * @bug No known bugs. 32 | * @todo everything 33 | */ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | 42 | #include 43 | #include 44 | 45 | #define SPEED_OF_LIGHT 299702547 46 | extern uint32_t measurements; 47 | /*************************************************************************** 48 | * Initilization for DW3001 -> SPI Connection, DW3000, Antenna Delay 49 | * 50 | * @return error code 51 | * [ 52 | * -1 -> dwt_initialise failed, 53 | * -2 -> dwt_configure failed, 54 | * -3 -> dwt_probe failed 55 | * ] 56 | ****************************************************************************/ 57 | uint8_t sit_init(); 58 | void sit_run_forever(); 59 | 60 | void sit_sstwr_initiator(); 61 | void sit_sstwr_responder(); 62 | 63 | void sit_dstwr_initiator(); 64 | void sit_dstwr_responder(); 65 | 66 | void reset_sequence(); 67 | -------------------------------------------------------------------------------- /include/sit_ble/ble_init.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_ble_init.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Defniton of functions for BLE init. 25 | * 26 | * Init the BLE System for SIT 27 | * 28 | * 29 | * @bug No known bugs. 30 | * @todo everything 31 | */ 32 | #ifndef __BLE_INIT_H__ 33 | #define __BLE_INIT_H__ 34 | 35 | #ifdef __cplusplus 36 | extern "C" 37 | { 38 | #endif 39 | 40 | #include 41 | 42 | #include 43 | #include 44 | 45 | #include "ble_device.h" 46 | #include "ble_uuids.h" 47 | 48 | /*************************************************************************** 49 | * Initilization for BLE 50 | * 51 | * @return error code 52 | * [ 53 | * 0 -> init ok, 54 | * err -> init failed 55 | * ] 56 | ****************************************************************************/ 57 | uint8_t sit_ble_init(void); 58 | 59 | 60 | bool is_connected(void); 61 | void ble_sit_notify(json_distance_msg_all_t* json_data, size_t data_len); 62 | void ble_sit_td_notify(json_simple_td_msg_t* json_data, size_t data_len); 63 | int ble_get_command(void); 64 | void bas_notify(void); 65 | 66 | int ble_start_advertising(void); 67 | int ble_stop_advertising(void); 68 | int ble_disconnect(void); 69 | 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif // __BLE_INIT_H__ -------------------------------------------------------------------------------- /sports_indoor_tracking/src/main.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file main.c 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Main File for start and running the SIT System. 25 | * 26 | * The main of Sports Indoor Tracking System. This File Handles the subsys. 27 | * Here main handle will start. 28 | * 29 | * @bug No known bugs. 30 | * @todo everything 31 | */ 32 | #include "deca_device_api.h" 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | #include 44 | 45 | #define APP_NAME "Sports Indoor Tracking\n" 46 | 47 | #include 48 | #include 49 | LOG_MODULE_REGISTER(sit_main, LOG_LEVEL_INF); 50 | 51 | void initialization() { 52 | uint8_t error = 0; 53 | 54 | sit_led_init(); 55 | 56 | if (sit_ble_init()) { 57 | LOG_ERR("Bluetooth init failed"); 58 | } 59 | // repeat configuration when failed 60 | do { 61 | error = sit_init(); 62 | } while (error > 1); 63 | 64 | LOG_INF("Init Fertig "); 65 | } 66 | 67 | int main(int argc, char *argv[]) { 68 | printk(APP_NAME); 69 | printk("==================\n"); 70 | init_device_id(); 71 | 72 | initialization(); 73 | sit_run_forever(); 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /samples/20_sit_ble_json/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2022 - Sven Hoyer 4 | * 5 | * This file is part of Zephyr-DWM1001. 6 | * 7 | * Zephyr-DWM1001 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Zephyr-DWM1001 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Zephyr-DWM1001. If not, see . 19 | * 20 | */ 21 | #include 22 | #include 23 | #include 24 | 25 | #define APP_NAME "Sports Indoor Tracking\n" 26 | 27 | #include 28 | #include 29 | LOG_MODULE_REGISTER(sit_main, LOG_LEVEL_INF); 30 | 31 | 32 | void main(void) { 33 | printk(APP_NAME); 34 | printk("==================\n"); 35 | 36 | sit_led_init(); 37 | // Problem! in this version of zephyr there is no float in json possible 38 | char json_msg[] = "{\"type\":\"distance_msg\",\"data\":{\"state\":\"start\",\"distance\":1,\"test_id\":44}}"; 39 | 40 | int expected_return_code = (1 << ARRAY_SIZE(distance_msg_descr)) - 1; 41 | struct json_distance_msg distance_msg; 42 | 43 | int ret = json_distance_parser( 44 | json_msg, 45 | sizeof(json_msg), 46 | &distance_msg 47 | ); 48 | 49 | if (ret < 0) { 50 | LOG_ERR("JSON Parse Error: %d", ret); 51 | } 52 | else if (ret != expected_return_code) { 53 | LOG_ERR("Not all values decoded; Expected return code %d but got %d", expected_return_code, ret); 54 | } 55 | else { 56 | LOG_INF("json_obj_parse return code: %d", ret); 57 | LOG_INF("calculated return code: %d", expected_return_code); 58 | if (strcmp(distance_msg.data.state, "start")) 59 | { 60 | LOG_INF("State: start"); 61 | } 62 | else 63 | { 64 | LOG_INF("State: False"); 65 | } 66 | LOG_INF("Distance: %d", distance_msg.data.distance); 67 | LOG_INF("Test ID: %d", distance_msg.data.test_id); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /include/sit_ble/ble_uuids.h: -------------------------------------------------------------------------------- 1 | /** 2 | * app ble_uuids.h 3 | */ 4 | #ifndef __BLE_UUIDS_H__ 5 | #define __BLE_UUIDS_H__ 6 | 7 | /** 8 | * The SIT UUID was generated by the uuidgen utility, which gave 9 | * 6ba1de6b-3ab6-4d77-9ea1-cb642272ba01 10 | * The last two hex digits (0xba, 0x01) were set to 0x00,0x00. 11 | * 6ba1de6b-3ab6-4d77-9ea1-cb6422720000 12 | * This string was reversed to form a byte array to conform to 13 | * Zephyr's BLE API specifications. 14 | * 0000722264cb-a19e-774d-3ab6-6bdea16b 15 | * 16 | * SIT UUID Base (common part) are the last 14 bytes of UUID. 17 | * The first two bytes will be Service or Characteristic unique values. 18 | * This is similar to the UUID16-type UUIDs specified by the BT SIG. 19 | */ 20 | #define SIT_UUID_BASE 0x01,0xba,0x72,0x22,0x64,0xcb,0xa1,0x9e,0x77,0x4d,0x3a,0xb6 21 | 22 | #define SIT_UUID_SERVICE 0x00,0x00,0x00,0x00 23 | #define SIT_UUID_NOTIFY 0x01,0x00,0x00,0x00 24 | #define SIT_UUID_INT_COMMAND 0x02,0x00,0x00,0x00 25 | #define SIT_UUID_JSON_COMMAND 0x03,0x00,0x00,0x00 26 | #define SIT_UUID_JSON_SETUP 0x04,0x00,0x00,0x00 27 | 28 | /** 29 | * SIT Service UUID: 6ba1de6b-3ab6-4d77-9ea1-cb6422720000 30 | */ 31 | #define BT_UUID_SIT_SERVICE_VAL \ 32 | BT_UUID_128_ENCODE(0x6ba1de6b, 0x3ab6, 0x4d77, 0x9ea1, 0xcb6422720000) 33 | 34 | #define BT_UUID_SIT_SERVICE \ 35 | BT_UUID_DECLARE_128(BT_UUID_SIT_SERVICE_VAL) 36 | 37 | 38 | /** 39 | * SIT Characteristics UUIDs: 6ba1de6b-3ab6-4d77-9ea1-cb642272xxxx 40 | */ 41 | #define BT_UUID_SIT_POS_NOTIFY_VAL \ 42 | BT_UUID_128_ENCODE(0x6ba1de6b, 0x3ab6, 0x4d77, 0x9ea1, 0xcb6422720001) 43 | #define BT_UUID_SIT_POS_NOTIFY \ 44 | BT_UUID_DECLARE_128(BT_UUID_SIT_POS_NOTIFY_VAL) 45 | 46 | #define BT_UUID_SIT_INT_COMMAND_VAL \ 47 | BT_UUID_128_ENCODE(0x6ba1de6b, 0x3ab6, 0x4d77, 0x9ea1, 0xcb6422720002) 48 | #define BT_UUID_SIT_INT_COMMAND \ 49 | BT_UUID_DECLARE_128(BT_UUID_SIT_INT_COMMAND_VAL) 50 | 51 | #define BT_UUID_SIT_JSON_COMMAND_VAL \ 52 | BT_UUID_128_ENCODE(0x6ba1de6b, 0x3ab6, 0x4d77, 0x9ea1, 0xcb6422720003) 53 | #define BT_UUID_SIT_JSON_COMMAND \ 54 | BT_UUID_DECLARE_128(BT_UUID_SIT_JSON_COMMAND_VAL) 55 | 56 | #define BT_UUID_SIT_JSON_SETUP_VAL \ 57 | BT_UUID_128_ENCODE(0x6ba1de6b, 0x3ab6, 0x4d77, 0x9ea1, 0xcb6422720004) 58 | #define BT_UUID_SIT_JSON_SETUP \ 59 | BT_UUID_DECLARE_128(BT_UUID_SIT_JSON_SETUP_VAL) 60 | 61 | #endif // __BLE_UUIDS_H__ -------------------------------------------------------------------------------- /drivers/platform/example_selection.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file example_selection.h 3 | * @brief Example selection is configured here 4 | * 5 | * @attention 6 | * 7 | * Copyright 2013 - 2021(c) Decawave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | */ 12 | 13 | #ifndef TEST_SELECTION_ 14 | #define TEST_SELECTION_ 15 | 16 | #ifdef __cplusplus 17 | extern "C" 18 | { 19 | #endif 20 | 21 | // Enable the needed example/test. Please enable only one example/test! 22 | 23 | //#define TEST_READING_DEV_ID 24 | //#define TEST_SIMPLE_TX 25 | //#define TEST_SIMPLE_TX_PDOA 26 | //#define TEST_TX_SLEEP 27 | //#define TEST_TX_SLEEP_IDLE_RC 28 | //#define TEST_TX_SLEEP_AUTO 29 | //#define TEST_TX_SLEEP_TIMED 30 | //#define TEST_TX_WITH_CCA 31 | 32 | //#define TEST_SIMPLE_RX 33 | //#define TEST_SIMPLE_RX_NLOS 34 | //#define TEST_RX_DIAG 35 | //#define TEST_RX_SNIFF 36 | //#define TEST_DOUBLE_BUFFER_RX 37 | //#define TEST_RX_TRIM 38 | //#define TEST_SIMPLE_RX_PDOA 39 | 40 | //#define TEST_SIMPLE_TX_STS_SDC 41 | //#define TEST_SIMPLE_RX_STS_SDC 42 | 43 | //#define TEST_SIMPLE_TX_AES 44 | //#define TEST_SIMPLE_RX_AES 45 | 46 | //#define TEST_TX_WAIT_RESP 47 | //#define TEST_TX_WAIT_RESP_INT 48 | //#define TEST_RX_SEND_RESP 49 | 50 | //#define TEST_CONTINUOUS_WAVE 51 | //#define TEST_CONTINUOUS_FRAME 52 | 53 | //#define TEST_DS_TWR_INITIATOR_STS 54 | //#define TEST_DS_TWR_RESPONDER_STS 55 | 56 | //#define TEST_DS_TWR_INITIATOR 57 | //#define TEST_DS_TWR_RESPONDER 58 | 59 | //#define TEST_DS_TWR_STS_SDC_INITIATOR 60 | //#define TEST_DS_TWR_STS_SDC_RESPONDER 61 | 62 | //#define TEST_SS_TWR_INITIATOR 63 | //#define TEST_SS_TWR_RESPONDER 64 | 65 | //#define TEST_SS_TWR_INITIATOR_STS 66 | //#define TEST_SS_TWR_RESPONDER_STS 67 | 68 | //#define TEST_SS_TWR_INITIATOR_STS_NO_DATA 69 | //#define TEST_SS_TWR_RESPONDER_STS_NO_DATA 70 | 71 | //#define TEST_AES_SS_TWR_INITIATOR 72 | //#define TEST_AES_SS_TWR_RESPONDER 73 | 74 | //#define TEST_ACK_DATA_TX 75 | //#define TEST_ACK_DATA_RX 76 | 77 | //#define TEST_SPI_CRC 78 | //#define TEST_GPIO 79 | //#define TEST_TIMER 80 | 81 | //#define TEST_OTP_WRITE 82 | 83 | //#define TEST_LE_PEND_TX 84 | //#define TEST_LE_PEND_RX 85 | 86 | //#define TEST_PLL_CAL 87 | 88 | //#define TEST_BW_CAL 89 | 90 | //#define TEST_TX_POWER_ADJUSTMENT 91 | 92 | //#define TEST_SIMPLE_AES 93 | #ifdef __cplusplus 94 | } 95 | #endif 96 | 97 | #endif 98 | -------------------------------------------------------------------------------- /lib/sit_led/sit_led.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | #include "sit_led/sit_led.h" 8 | 9 | LOG_MODULE_REGISTER(SIT_LED, LOG_LEVEL_ERR); 10 | 11 | static uint8_t led0_state = 0; 12 | static uint8_t led1_state = 0; 13 | static uint8_t led2_state = 0; 14 | static uint8_t led3_state = 0; 15 | 16 | static const struct gpio_dt_spec led0 = GPIO_DT_SPEC_GET(LED0_NODE, gpios); 17 | static const struct gpio_dt_spec led1 = GPIO_DT_SPEC_GET(LED1_NODE, gpios); 18 | static const struct gpio_dt_spec led2 = GPIO_DT_SPEC_GET(LED2_NODE, gpios); 19 | static const struct gpio_dt_spec led3 = GPIO_DT_SPEC_GET(LED3_NODE, gpios); 20 | 21 | 22 | void sit_led_init(void) { 23 | 24 | gpio_pin_configure_dt(&led0, GPIO_OUTPUT_ACTIVE); 25 | gpio_pin_configure_dt(&led1, GPIO_OUTPUT_ACTIVE); 26 | gpio_pin_configure_dt(&led2, GPIO_OUTPUT_ACTIVE); 27 | gpio_pin_configure_dt(&led3, GPIO_OUTPUT_ACTIVE); 28 | gpio_pin_set_dt(&led0, 0); 29 | gpio_pin_set_dt(&led1, 0); 30 | gpio_pin_set_dt(&led2, 0); 31 | gpio_pin_set_dt(&led3, 0); 32 | k_sleep(K_MSEC(1000)); 33 | gpio_pin_set_dt(&led0, 1); 34 | gpio_pin_set_dt(&led1, 1); 35 | gpio_pin_set_dt(&led2, 1); 36 | gpio_pin_set_dt(&led3, 1); 37 | k_sleep(K_MSEC(1000)); 38 | gpio_pin_set_dt(&led0, 0); 39 | gpio_pin_set_dt(&led1, 0); 40 | gpio_pin_set_dt(&led2, 0); 41 | gpio_pin_set_dt(&led3, 0); 42 | 43 | } 44 | 45 | void toggle_led_state (uint8_t *state) { 46 | if(*state == 0 ) { 47 | *state = 1; 48 | } else { 49 | *state = 0; 50 | } 51 | } 52 | 53 | void sit_toggle_led(int led_id) { 54 | switch (led_id) { 55 | case 0: 56 | toggle_led_state(&led0_state); 57 | gpio_pin_set_dt(&led0, led0_state); 58 | break; 59 | case 1: 60 | toggle_led_state(&led1_state); 61 | gpio_pin_set_dt(&led1, led1_state); 62 | break; 63 | case 2: 64 | toggle_led_state(&led2_state); 65 | gpio_pin_set_dt(&led2, led2_state); 66 | break; 67 | case 3: 68 | toggle_led_state(&led3_state); 69 | gpio_pin_set_dt(&led3, led3_state); 70 | break; 71 | 72 | default: 73 | break; 74 | } 75 | } 76 | 77 | void sit_set_led(int led_id, int state) { 78 | switch (led_id) { 79 | case 0: 80 | led0_state = state; 81 | gpio_pin_set_dt(&led0, led0_state); 82 | break; 83 | case 1: 84 | led1_state = state; 85 | gpio_pin_set_dt(&led1, led1_state); 86 | break; 87 | case 2: 88 | led2_state = state; 89 | gpio_pin_set_dt(&led2, led2_state); 90 | break; 91 | case 3: 92 | led3_state = state; 93 | gpio_pin_set_dt(&led3, led3_state); 94 | break; 95 | default: 96 | break; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /lib/sit_ble/cts.c: -------------------------------------------------------------------------------- 1 | /** @file 2 | * @brief CTS Service sample 3 | */ 4 | 5 | /* 6 | * Copyright (c) 2016 Intel Corporation 7 | * 8 | * SPDX-License-Identifier: Apache-2.0 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static uint8_t ct[10]; 26 | static uint8_t ct_update; 27 | 28 | static void ct_ccc_cfg_changed(const struct bt_gatt_attr *attr, uint16_t value) 29 | { 30 | /* TODO: Handle value */ 31 | } 32 | 33 | static ssize_t read_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr, 34 | void *buf, uint16_t len, uint16_t offset) 35 | { 36 | const char *value = attr->user_data; 37 | 38 | return bt_gatt_attr_read(conn, attr, buf, len, offset, value, 39 | sizeof(ct)); 40 | } 41 | 42 | static ssize_t write_ct(struct bt_conn *conn, const struct bt_gatt_attr *attr, 43 | const void *buf, uint16_t len, uint16_t offset, 44 | uint8_t flags) 45 | { 46 | uint8_t *value = attr->user_data; 47 | 48 | if (offset + len > sizeof(ct)) { 49 | return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); 50 | } 51 | 52 | memcpy(value + offset, buf, len); 53 | ct_update = 1U; 54 | 55 | return len; 56 | } 57 | 58 | /* Current Time Service Declaration */ 59 | BT_GATT_SERVICE_DEFINE(cts_cvs, 60 | BT_GATT_PRIMARY_SERVICE(BT_UUID_CTS), 61 | BT_GATT_CHARACTERISTIC(BT_UUID_CTS_CURRENT_TIME, BT_GATT_CHRC_READ | 62 | BT_GATT_CHRC_NOTIFY | BT_GATT_CHRC_WRITE, 63 | BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, 64 | read_ct, write_ct, ct), 65 | BT_GATT_CCC(ct_ccc_cfg_changed, BT_GATT_PERM_READ | BT_GATT_PERM_WRITE), 66 | ); 67 | 68 | static void generate_current_time(uint8_t *buf) 69 | { 70 | uint16_t year; 71 | 72 | /* 'Exact Time 256' contains 'Day Date Time' which contains 73 | * 'Date Time' - characteristic contains fields for: 74 | * year, month, day, hours, minutes and seconds. 75 | */ 76 | 77 | year = sys_cpu_to_le16(2015); 78 | memcpy(buf, &year, 2); /* year */ 79 | buf[2] = 5U; /* months starting from 1 */ 80 | buf[3] = 30U; /* day */ 81 | buf[4] = 12U; /* hours */ 82 | buf[5] = 45U; /* minutes */ 83 | buf[6] = 30U; /* seconds */ 84 | 85 | /* 'Day of Week' part of 'Day Date Time' */ 86 | buf[7] = 1U; /* day of week starting from 1 */ 87 | 88 | /* 'Fractions 256 part of 'Exact Time 256' */ 89 | buf[8] = 0U; 90 | 91 | /* Adjust reason */ 92 | buf[9] = 0U; /* No update, change, etc */ 93 | } 94 | 95 | void cts_init(void) 96 | { 97 | /* Simulate current time for Current Time Service */ 98 | generate_current_time(ct); 99 | } 100 | 101 | void cts_notify(void) 102 | { /* Current Time Service updates only when time is changed */ 103 | if (!ct_update) { 104 | return; 105 | } 106 | 107 | ct_update = 0U; 108 | bt_gatt_notify(NULL, &cts_cvs.attrs[1], &ct, sizeof(ct)); 109 | } 110 | -------------------------------------------------------------------------------- /lib/sit/sit_diagnostic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "sit/sit_diagnostic.h" 4 | #include "sit/sit_config.h" 5 | #include 6 | 7 | #include 8 | LOG_MODULE_REGISTER(SIT_DIAGNOSTIC, LOG_LEVEL_INF); 9 | 10 | #define A_PRF_16 113.8 // Constant A for PRF of 16 MHz. See User Manual for more information. 11 | #define A_PRF_64 120.7 // Constant A for PRF of 64 MHz. See User Manual for more information. 12 | #define RX_CODE_THRESHOLD 8 // For 64 MHz PRF the RX code is 9. 13 | #define LOG_CONSTANT_C0 63.2 // 10log10(2^21) = 63.2 See User Manual for more information. 14 | 15 | 16 | #define ACCUM_DATA_LEN (4) 17 | static uint8_t accum_data[ACCUM_DATA_LEN]; 18 | 19 | extern dwt_config_t sit_device_config; 20 | 21 | static dwt_rxdiag_t rx_diag; 22 | 23 | dwt_nlos_alldiag_t diag_data; 24 | dwt_nlos_ipdiag_t fp_pp_index; 25 | 26 | void get_fp_pp_index(void) { 27 | dwt_nlos_ipdiag(&fp_pp_index); 28 | dwt_readdiagnostics(&rx_diag); 29 | uint16_t fp_int = rx_diag.ipatovFpIndex >> 6; 30 | uint8_t dgc_decision = dwt_get_dgcdecision(); 31 | uint32_t fp_index = fp_pp_index.index_fp_u32 >> 6; 32 | //uint32_t pp_index = fp_pp_index.index_pp_u32 >> 6; 33 | dwt_readaccdata(accum_data, ACCUM_DATA_LEN, (fp_index - 2)); 34 | //int32_t acc_value = ((int32_t)accum_data[3] << 24) | ((int32_t)accum_data[2] << 16) | ((int32_t)accum_data[1] << 8) | accum_data[0]; 35 | LOG_INF("DGC: %u", dgc_decision); 36 | LOG_INF("FP: %u", fp_index); 37 | LOG_INF("PP: %u", fp_int); 38 | } 39 | 40 | void get_diagnostic(diagnostic_info *diagnostic) { 41 | uint8_t D; 42 | float ip_f1, ip_f2, ip_f3, ip_n, ip_cp, ip_rsl, ip_fsl; 43 | float ip_alpha, log_constant = 0; 44 | 45 | log_constant = LOG_CONSTANT_C0; 46 | 47 | diag_data.diag_type = IPATOV; 48 | dwt_nlos_alldiag(&diag_data); 49 | if (sit_device_config.rxCode > RX_CODE_THRESHOLD){ 50 | ip_alpha = (-(A_PRF_64 + 1)); 51 | } else { 52 | ip_alpha = -(A_PRF_16); 53 | } 54 | ip_n = diag_data.accumCount; // The number of preamble symbols accumulated 55 | ip_f1 = diag_data.F1 / 4; // The First Path Amplitude (point 1) magnitude value (it has 2 fractional bits), 56 | ip_f2 = diag_data.F2 / 4; // The First Path Amplitude (point 2) magnitude value (it has 2 fractional bits), 57 | ip_f3 = diag_data.F3 / 4; // The First Path Amplitude (point 3) magnitude value (it has 2 fractional bits), 58 | ip_cp = diag_data.cir_power; 59 | D = diag_data.D * 6; 60 | 61 | // Quadrate bilden 62 | ip_n *= ip_n; 63 | ip_f1 *= ip_f1; 64 | ip_f2 *= ip_f2; 65 | ip_f3 *= ip_f3; 66 | 67 | // Berechnung der First Path Power und Recived Signal Power (RSSI). 68 | ip_rsl = 10 * log10((float)ip_cp / ip_n) + ip_alpha + log_constant + D; 69 | ip_fsl = 10 * log10(((ip_f1 + ip_f2 + ip_f3) / ip_n)) + ip_alpha + D; 70 | 71 | LOG_INF("Recived Index: %f", ip_rsl); 72 | LOG_INF("First Path Index: %f", ip_fsl); 73 | 74 | // If differenc is bigger than 12 db the singal is Non Line of Sight 75 | if ((ip_rsl - ip_fsl) > 12 ) { 76 | LOG_INF("non line of sight"); 77 | diagnostic->nlos = 100; 78 | } else { 79 | LOG_INF("line of sight"); 80 | diagnostic->nlos = 0; 81 | } 82 | 83 | diagnostic->fpi = ip_fsl; 84 | diagnostic->rssi = ip_rsl; 85 | } -------------------------------------------------------------------------------- /lib/sit/sit_device.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_device.c 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief SIT Device functions. 25 | * 26 | * Device Functions Definiton to handle the device status (e.g.read status register) 27 | * 28 | * @bug No known bugs. 29 | * @todo everything 30 | */ 31 | #include "sit/sit_device.h" 32 | 33 | #include 34 | #include 35 | #include 36 | 37 | 38 | #include 39 | 40 | #include 41 | #include 42 | LOG_MODULE_REGISTER(sit_device, LOG_LEVEL_INF); 43 | 44 | char m_deviceID[17]; 45 | 46 | uint32_t sit_get_device_status(void) { 47 | return dwt_readsysstatuslo(); 48 | } 49 | 50 | void waitforsysstatus(uint32_t *lo_result, uint32_t *hi_result, uint32_t lo_mask, uint32_t hi_mask) 51 | { 52 | uint32_t lo_result_tmp = 0; 53 | uint32_t hi_result_tmp = 0; 54 | 55 | // If a mask has been passed into the function for the system status register (lower 32-bits) 56 | if (lo_mask) 57 | { 58 | while (!((lo_result_tmp = dwt_readsysstatuslo()) & (lo_mask))) 59 | { 60 | // If a mask value is set for the system status register (higher 32-bits) 61 | if (hi_mask) 62 | { 63 | // If mask value for the system status register (higher 32-bits) is found 64 | if ((hi_result_tmp = dwt_readsysstatushi()) & hi_mask) 65 | { 66 | break; 67 | } 68 | } 69 | } 70 | } 71 | // if only a mask value for the system status register (higher 32-bits) is set 72 | else if (hi_mask) 73 | { 74 | while (!((hi_result_tmp = dwt_readsysstatushi()) & (hi_mask))) { }; 75 | } 76 | 77 | if (lo_result != NULL) 78 | { 79 | *lo_result = lo_result_tmp; 80 | } 81 | 82 | if (hi_result != NULL) 83 | { 84 | *hi_result = hi_result_tmp; 85 | } 86 | } 87 | 88 | void set_antenna_delay( 89 | uint16_t rx_delay, 90 | uint16_t tx_delay 91 | ) { 92 | dwt_setrxantennadelay(rx_delay); 93 | dwt_settxantennadelay(tx_delay); 94 | } 95 | 96 | uint16_t get_tx_ant_dly() { 97 | return dwt_gettxantennadelay(); 98 | } 99 | 100 | uint16_t get_rx_ant_dly() { 101 | return dwt_getrxantennadelay(); 102 | } 103 | 104 | // Device ID 105 | void init_device_id(void) { 106 | uint8_t buf_deviceID[8]; 107 | hwinfo_get_device_id(buf_deviceID, sizeof(buf_deviceID)); 108 | 109 | for(int i = 0; i < sizeof(buf_deviceID); i++){ 110 | sprintf(m_deviceID + 2*i, "%02X", buf_deviceID[i]); 111 | } 112 | m_deviceID[16] = '\0'; 113 | } 114 | 115 | void get_device_id(char **deviceID) { 116 | *deviceID = strdup(m_deviceID); 117 | } -------------------------------------------------------------------------------- /samples/20_sit_ble_json/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2022 - Sven Hoyer 4 | * 5 | * This file is part of Zephyr-DWM1001. 6 | * 7 | * Zephyr-DWM1001 is free software: you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation, either version 3 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * Zephyr-DWM1001 is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with Zephyr-DWM1001. If not, see . 19 | * 20 | */ 21 | #include 22 | #include 23 | #include 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | #define APP_NAME "Sports Indoor Tracking - JSON\n" 31 | 32 | #include 33 | #include 34 | #include 35 | LOG_MODULE_REGISTER(sit_main, LOG_LEVEL_INF); 36 | 37 | #define STACK_SIZE 2048 38 | 39 | // void main(void) { 40 | // printk(APP_NAME); 41 | // printk("==================\n"); 42 | 43 | // sit_led_init(); 44 | // // Problem! in this version of zephyr there is no float in json possible 45 | // //char json_msg[] = "{\"type\":\"distance_msg\",\"data\":{\"state\":\"start\",\"distance\":1,\"test_id\":44}}"; 46 | // char json_msg[] = "{\"type\":\"measurement_msg\",\"command\":\"start\"}"; 47 | 48 | // int expected_return_code = (1 << ARRAY_SIZE(command_msg_descr)) - 1; 49 | // json_command_msg_t distance_msg; 50 | 51 | // // int ret = json_distance_parser( 52 | // // json_msg, 53 | // // sizeof(json_msg), 54 | // // &distance_msg 55 | // // ); 56 | // int ret = json_command_parser( 57 | // json_msg, 58 | // sizeof(json_msg), 59 | // &distance_msg 60 | // ); 61 | 62 | // if (ret < 0) { 63 | // LOG_ERR("JSON Parse Error: %d", ret); 64 | // } 65 | // else if (ret != expected_return_code) { 66 | // LOG_ERR("Not all values decoded; Expected return code %d but got %d", expected_return_code, ret); 67 | // } 68 | // else { 69 | // LOG_INF("json_obj_parse return code: %d", ret); 70 | // LOG_INF("calculated return code: %d", expected_return_code); 71 | // // if (strcmp(distance_msg.data.state, "start")) 72 | // // { 73 | // // LOG_INF("State: start"); 74 | // // } 75 | // // else 76 | // // { 77 | // // LOG_INF("State: False"); 78 | // // } 79 | // // LOG_INF("Distance: %d", distance_msg.data.distance); 80 | // // LOG_INF("Test ID: %d", distance_msg.data.test_id); 81 | // if(strcmp(distance_msg.command, "start")) { 82 | // LOG_INF("Test"); 83 | // } 84 | // LOG_INF("Distance: %s", distance_msg.type); 85 | // LOG_INF("Test ID: %s", distance_msg.command); 86 | // } 87 | 88 | // } 89 | 90 | int main(void) { 91 | printk(APP_NAME); 92 | printk("==================\n"); 93 | double distance = 3.1415; 94 | 95 | while(42){ 96 | if (distance >= 0) { 97 | char *json_data; 98 | LOG_INF("Test"); 99 | uint8_t result = json_encode_distance(&json_data, &distance); 100 | if(result == 0){ 101 | LOG_INF("BLE MSG: %s", json_data); 102 | LOG_INF("BLE LEN: %d", strlen(json_data)); 103 | } 104 | LOG_INF("BLE LEN: %d", result); 105 | k_free(json_data); 106 | } 107 | k_msleep(100); 108 | LOG_INF("Test Ende"); 109 | } 110 | return 0; 111 | } 112 | 113 | K_THREAD_DEFINE(josn_example, STACK_SIZE, 114 | main, NULL, NULL, NULL, 115 | K_HIGHEST_APPLICATION_THREAD_PRIO, 0, 0); -------------------------------------------------------------------------------- /include/sit/sit_distance.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_distance.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Defniton of functions for distance measurement. 25 | * 26 | * This file defines functions for distance measurement for the 27 | * DWM3001cdk in the SIT system. 28 | * 29 | * 30 | * @bug No known bugs. 31 | * @todo everything 32 | */ 33 | 34 | #ifndef __SIT_DISTANCE_H__ 35 | #define __SIT_DISTANCE_H__ 36 | 37 | #include "sit_config.h" 38 | 39 | #include 40 | #include 41 | 42 | extern diagnostic_info diagnostic; 43 | 44 | void sit_receive_now(uint16_t preamble_detction_timeout, uint32_t rx_timeout); 45 | 46 | /*************************************************************************** 47 | * Start ranging with a poll msg 48 | * 49 | * @param uint8_t* msg_data -> pointer to the data you like to send with 50 | * the poll msg 51 | * @param uint16_t msg_size -> length of the data you like to send 52 | * 53 | * @return None 54 | * 55 | ****************************************************************************/ 56 | void sit_start_poll(uint8_t* msg_data, uint16_t msg_size); 57 | 58 | /*************************************************************************** 59 | * Send a 60 | * 61 | * @param uint8_t* msg_data -> pointer to the data you like to send with 62 | * the poll msg 63 | * @param uint16_t msg_size -> length of the data you like to send 64 | * @param unit64_t tx_time -> start sending msg at this system time 65 | * 66 | * @return bool true -> if the msg is send at the tx_time 67 | * bool false -> if the msg is send to late 68 | * 69 | ****************************************************************************/ 70 | bool sit_send_at(uint8_t* msg_data, uint16_t size, uint32_t tx_time); 71 | bool sit_send_at_with_response(uint8_t* msg_data, uint16_t size, uint32_t tx_time); 72 | /*************************************************************************** 73 | * Start ranging with a poll msg 74 | * 75 | * @param uint8_t* msg_data -> pointer to the data you like to send with 76 | * the poll msg 77 | * @param uint32_t msg_size -> length of the data you like to send 78 | * 79 | * @return None 80 | * 81 | ****************************************************************************/ 82 | void sit_receive_at(uint32_t timeout); 83 | 84 | bool sit_check_msg_id(msg_id_t id, msg_simple_t * message); 85 | 86 | bool sit_check_final_msg_id(msg_id_t id, msg_ss_twr_final_t* message); 87 | 88 | bool sit_check_ds_final_msg_id(msg_id_t id, msg_ds_twr_final_t* message); 89 | 90 | bool sit_check_sensing_3_msg_id(msg_id_t id, msg_sensing_3_t * message); 91 | 92 | bool sit_check_sensing_info_msg_id(msg_id_t id, msg_sensing_info_t * message); 93 | 94 | void sit_set_rx_tx_delay_and_rx_timeout(uint32_t delay_us,uint16_t timeout); 95 | void sit_set_rx_after_tx_delay(uint32_t delay_us); 96 | void sit_set_rx_timeout(uint16_t timeout); 97 | void sit_set_preamble_detection_timeout(uint16_t timeout); 98 | 99 | void recover_tx_errors(); 100 | 101 | #endif -------------------------------------------------------------------------------- /drivers/platform/dw3000_hw.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "deca_device_api.h" 7 | #include "dw3000_hw.h" 8 | #include "dw3000_spi.h" 9 | 10 | LOG_MODULE_REGISTER(dw3000, CONFIG_DW3000_LOG_LEVEL); 11 | 12 | #define DW_INST DT_INST(0, qorvo_dw3000) 13 | 14 | static struct gpio_callback gpio_cb; 15 | static struct k_work dw3000_isr_work; 16 | 17 | struct dw3000_config { 18 | struct gpio_dt_spec gpio_irq; 19 | struct gpio_dt_spec gpio_reset; 20 | struct gpio_dt_spec gpio_wakeup; 21 | struct gpio_dt_spec gpio_spi_pol; 22 | struct gpio_dt_spec gpio_spi_pha; 23 | }; 24 | 25 | static const struct dw3000_config conf = { 26 | .gpio_irq = GPIO_DT_SPEC_GET_OR(DW_INST, irq_gpios, {0}), 27 | .gpio_reset = GPIO_DT_SPEC_GET_OR(DW_INST, reset_gpios, {0}), 28 | .gpio_wakeup = GPIO_DT_SPEC_GET_OR(DW_INST, wakeup_gpios, {0}), 29 | .gpio_spi_pol = GPIO_DT_SPEC_GET_OR(DW_INST, spi_pol_gpios, {0}), 30 | .gpio_spi_pha = GPIO_DT_SPEC_GET_OR(DW_INST, spi_pha_gpios, {0}), 31 | }; 32 | 33 | int dw3000_hw_init() 34 | { 35 | 36 | /* Reset */ 37 | if (conf.gpio_reset.port) { 38 | gpio_pin_configure_dt(&conf.gpio_reset, GPIO_INPUT); 39 | LOG_INF("RESET on %s pin %d", conf.gpio_reset.port->name, 40 | conf.gpio_reset.pin); 41 | } 42 | 43 | /* Wakeup (optional) */ 44 | if (conf.gpio_wakeup.port) { 45 | gpio_pin_configure_dt(&conf.gpio_wakeup, GPIO_OUTPUT_ACTIVE); 46 | LOG_INF("WAKEUP on %s pin %d", conf.gpio_wakeup.port->name, 47 | conf.gpio_wakeup.pin); 48 | } 49 | 50 | /* SPI Polarity (optional) */ 51 | if (conf.gpio_spi_pol.port) { 52 | gpio_pin_configure_dt(&conf.gpio_spi_pol, GPIO_OUTPUT_INACTIVE); 53 | LOG_INF("SPI_POL on %s pin %d", conf.gpio_spi_pol.port->name, 54 | conf.gpio_spi_pol.pin); 55 | } 56 | 57 | /* SPI Phase (optional) */ 58 | if (conf.gpio_spi_pha.port) { 59 | gpio_pin_configure_dt(&conf.gpio_spi_pha, GPIO_OUTPUT_INACTIVE); 60 | LOG_INF("SPI_PHA on %s pin %d", conf.gpio_spi_pha.port->name, 61 | conf.gpio_spi_pha.pin); 62 | } 63 | 64 | return dw3000_spi_init(); 65 | } 66 | 67 | static void dw3000_hw_isr_work_handler(struct k_work* item) 68 | { 69 | dwt_isr(); 70 | } 71 | 72 | static void dw3000_hw_isr(const struct device* dev, struct gpio_callback* cb, 73 | uint32_t pins) 74 | { 75 | k_work_submit(&dw3000_isr_work); 76 | } 77 | 78 | int dw3000_hw_init_interrupt(void) 79 | { 80 | if (conf.gpio_irq.port) { 81 | k_work_init(&dw3000_isr_work, dw3000_hw_isr_work_handler); 82 | 83 | gpio_pin_configure_dt(&conf.gpio_irq, GPIO_INPUT); 84 | gpio_init_callback(&gpio_cb, dw3000_hw_isr, BIT(conf.gpio_irq.pin)); 85 | gpio_add_callback(conf.gpio_irq.port, &gpio_cb); 86 | gpio_pin_interrupt_configure_dt(&conf.gpio_irq, GPIO_INT_EDGE_RISING); 87 | 88 | LOG_INF("IRQ on %s pin %d", conf.gpio_irq.port->name, 89 | conf.gpio_irq.pin); 90 | return 0; 91 | } else { 92 | LOG_ERR("IRQ pin not configured"); 93 | return -ENOENT; 94 | } 95 | } 96 | 97 | void dw3000_hw_interrupt_enable(void) 98 | { 99 | if (conf.gpio_irq.port) { 100 | gpio_pin_interrupt_configure_dt(&conf.gpio_irq, GPIO_INT_EDGE_RISING); 101 | } 102 | } 103 | 104 | void dw3000_hw_interrupt_disable(void) 105 | { 106 | if (conf.gpio_irq.port) { 107 | gpio_pin_interrupt_configure_dt(&conf.gpio_irq, GPIO_INT_DISABLE); 108 | } 109 | } 110 | 111 | void dw3000_hw_fini(void) 112 | { 113 | // TODO 114 | dw3000_spi_fini(); 115 | } 116 | 117 | void dw3000_hw_reset() 118 | { 119 | if (!conf.gpio_reset.port) { 120 | LOG_ERR("No HW reset configured"); 121 | return; 122 | } 123 | 124 | gpio_pin_configure_dt(&conf.gpio_reset, GPIO_OUTPUT_ACTIVE); 125 | k_msleep(1); // 10 us? 126 | gpio_pin_configure_dt(&conf.gpio_reset, GPIO_INPUT); 127 | k_msleep(2); 128 | } 129 | 130 | /** wakeup either using the WAKEUP pin or SPI CS */ 131 | void dw3000_hw_wakeup(void) 132 | { 133 | if (conf.gpio_wakeup.port) { 134 | /* Use WAKEUP pin if available */ 135 | LOG_INF("WAKEUP PIN"); 136 | gpio_pin_set_dt(&conf.gpio_wakeup, 1); 137 | } else { 138 | /* Use SPI CS pin */ 139 | LOG_INF("WAKEUP CS"); 140 | dw3000_spi_wakeup(); 141 | } 142 | k_sleep(K_MSEC(1)); 143 | } 144 | 145 | /** set WAKEUP pin low if available */ 146 | void dw3000_hw_wakeup_pin_low(void) 147 | { 148 | if (conf.gpio_wakeup.port) { 149 | gpio_pin_set_dt(&conf.gpio_wakeup, 0); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /lib/sit_mesh/sit_mesh.c: -------------------------------------------------------------------------------- 1 | /* 2 | * sit_mesh.c 3 | */ 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include "board.h" 18 | #include "sit_mesh.h" 19 | 20 | LOG_MODULE_REGISTER(sit_mesh, LOG_LEVEL_INF); 21 | 22 | static void attention_on(struct bt_mesh_model *mod) 23 | { 24 | sit_set_led(1, 1); 25 | } 26 | 27 | static void attention_off(struct bt_mesh_model *mod) 28 | { 29 | sit_set_led(1, 0); 30 | } 31 | 32 | 33 | static const struct bt_mesh_health_srv_cb health_cb = { 34 | .attn_on = attention_on, 35 | .attn_off = attention_off, 36 | }; 37 | 38 | static struct bt_mesh_health_srv health_srv = { 39 | .cb = &health_cb, 40 | }; 41 | 42 | BT_MESH_HEALTH_PUB_DEFINE(health_pub, 0); 43 | 44 | static struct bt_mesh_model models[] = { 45 | BT_MESH_MODEL_CFG_SRV, 46 | BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), 47 | }; 48 | 49 | static struct bt_mesh_elem elements[] = { 50 | BT_MESH_ELEM(0, models, BT_MESH_MODEL_NONE), 51 | }; 52 | 53 | static const struct bt_mesh_comp comp = { 54 | .cid = BT_COMP_ID_LF, 55 | .elem = elements, 56 | .elem_count = ARRAY_SIZE(elements), 57 | }; 58 | 59 | static void mesh_blink(uint32_t num) { 60 | printk("Test: %d", num); 61 | 62 | } 63 | 64 | static void output_number(bt_mesh_output_action_t act, uint32_t num) { 65 | if(act == BT_MESH_DISPLAY_NUMBER) { 66 | printk("Test 1"); 67 | printk("Output OOB Number: %u \n", num); 68 | } else if (act == BT_MESH_BLINK){ 69 | LOG_INF("Output OOB Number: %u \n", num); 70 | for(int i = 1; i <= num; i++) { 71 | k_msleep(200); 72 | sit_set_led(1, 1); 73 | k_msleep(200); 74 | sit_set_led(1, 0); 75 | } 76 | } 77 | printk("Test3"); 78 | } 79 | 80 | static void prov_complete(uint16_t net_idx, uint16_t addr) { 81 | printk("Prov Complete \n"); 82 | } 83 | 84 | static void prov_reset(void) 85 | { 86 | bt_mesh_prov_enable( BT_MESH_PROV_GATT | BT_MESH_PROV_ADV ); 87 | } 88 | 89 | static void new_noded_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, uint8_t num_elem) { 90 | printk("New Element: %d, %02x, %d, %d \n", net_idx, uuid, addr, num_elem); 91 | } 92 | 93 | static uint8_t dev_uuid[16]; 94 | 95 | 96 | static const struct bt_mesh_prov prov = { 97 | .uuid = dev_uuid, 98 | .output_size = 1, 99 | .output_actions = BT_MESH_DISPLAY_NUMBER, 100 | .output_number = output_number, 101 | .complete = prov_complete, 102 | .node_added = new_noded_added, 103 | .reset = prov_reset, 104 | }; 105 | 106 | 107 | int sit_set_device_name(const char * name) 108 | { 109 | int err; 110 | 111 | bt_set_name(name); 112 | if(err < 0) { 113 | LOG_ERR("Name not set: %d", err); 114 | return err; 115 | } 116 | 117 | return 0; 118 | } 119 | 120 | 121 | static void bt_ready(int err) { 122 | if (err) { 123 | printk("Bluetooth init failed (err %d)\n", err); 124 | return; 125 | } 126 | 127 | printk("Bluetooth initialized\n"); 128 | sit_set_device_name("DWM3001"); 129 | 130 | err = bt_mesh_init(&prov, &comp); 131 | if (err) { 132 | printk("Initializing mesh failed (err %d)\n", err); 133 | return; 134 | } 135 | 136 | bt_mesh_prov_enable( BT_MESH_PROV_GATT | BT_MESH_PROV_ADV ); 137 | printk("Mesh initialized\n"); 138 | } 139 | 140 | bool sit_mesh_is_provisioned(void) { 141 | return bt_mesh_is_provisioned(); 142 | } 143 | 144 | 145 | void sit_mesh_prov_init(void) { 146 | 147 | } 148 | 149 | void sit_mesh_init(void) { 150 | int err = -1; 151 | 152 | printk("Init Sit MESH \n"); 153 | 154 | if (IS_ENABLED(CONFIG_HWINFO)) { 155 | err = hwinfo_get_device_id(dev_uuid, sizeof(dev_uuid)); 156 | } 157 | 158 | if (err < 0) { 159 | dev_uuid[0] = 0xc7; 160 | dev_uuid[1] = 0x13; 161 | dev_uuid[2] = 0x03; 162 | dev_uuid[3] = 0x0e; 163 | dev_uuid[4] = 0xb8; 164 | dev_uuid[5] = 0x7d; 165 | dev_uuid[6] = 0x4b; 166 | dev_uuid[7] = 0x90; 167 | dev_uuid[8] = 0xb5; 168 | dev_uuid[9] = 0xe7; 169 | dev_uuid[10] = 0x0a; 170 | dev_uuid[11] = 0x51; 171 | dev_uuid[12] = 0xe8; 172 | dev_uuid[13] = 0xaa; 173 | dev_uuid[14] = 0x8e; 174 | dev_uuid[15] = 0x66; 175 | } 176 | printk("UUID: %16x \n", dev_uuid); 177 | /* Initialize the Bluetooth Subsystem */ 178 | err = bt_enable(bt_ready); 179 | if (err) { 180 | printk("Bluetooth init failed (err %d)\n", err); 181 | } 182 | } 183 | -------------------------------------------------------------------------------- /boards/arm/qorvo_dwm3001cdk/qorvo_dwm3001cdk.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2022 Sven Hoyer 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /dts-v1/; 8 | #include 9 | #include "qorvo_dwm3001cdk-pinctrl.dtsi" 10 | 11 | / { 12 | model = "Qorovo DWM3001CDK"; 13 | compatible = "qorvo,dwm3001cdk"; 14 | 15 | chosen { 16 | zephyr,console = &uart0; 17 | zephyr,shell-uart = &uart0; 18 | zephyr,uart-mcumgr = &uart0; 19 | zephyr,bt-mon-uart = &uart0; 20 | zephyr,bt-c2h-uart = &uart0; 21 | zephyr,sram = &sram0; 22 | zephyr,flash = &flash0; 23 | zephyr,code-partition = &slot0_partition; 24 | }; 25 | 26 | leds { 27 | compatible = "gpio-leds"; 28 | led0_red: led_0 { 29 | gpios = <&gpio0 14 GPIO_ACTIVE_LOW>; 30 | label = "Red LED 0"; 31 | }; 32 | led1_green: led_1 { 33 | gpios = <&gpio0 4 GPIO_ACTIVE_LOW>; 34 | label = "Green LED 1"; 35 | }; 36 | led2_red: led_2 { 37 | gpios = <&gpio0 22 GPIO_ACTIVE_LOW>; 38 | label = "Red LED 2"; 39 | }; 40 | led3_blue: led_3 { 41 | gpios = <&gpio0 5 GPIO_ACTIVE_LOW>; 42 | label = "Blue LED 3"; 43 | }; 44 | }; 45 | 46 | pwmleds { 47 | compatible = "pwm-leds"; 48 | pwm_led0_red: pwm_led_0 { 49 | pwms = <&pwm0 0 PWM_MSEC(22) PWM_POLARITY_INVERTED>; 50 | label = "Red PWM LED"; 51 | }; 52 | }; 53 | 54 | buttons { 55 | compatible = "gpio-keys"; 56 | button0: button_0 { 57 | gpios = <&gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; 58 | label = "Push button switch 0"; 59 | }; 60 | }; 61 | 62 | /* These aliases are provided for compatibility with samples */ 63 | aliases { 64 | sw0 = &button0; 65 | led0 = &led0_red; 66 | led1 = &led1_green; 67 | led2 = &led2_red; 68 | led3 = &led3_blue; 69 | led0-red = &led0_red; 70 | led1-green = &led1_green; 71 | led2-red = &led2_red; 72 | led3-blue = &led3_blue; 73 | pwm-led0 = &pwm_led0_red; 74 | watchdog0 = &wdt0; 75 | accel0 = &lis2dh12; 76 | dw3000 = &dwm3000; 77 | }; 78 | 79 | }; 80 | 81 | &adc { 82 | status = "okay"; 83 | }; 84 | 85 | &gpiote { 86 | status = "okay"; 87 | }; 88 | 89 | &gpio0 { 90 | status = "okay"; 91 | }; 92 | 93 | &gpio1 { 94 | status = "okay"; 95 | }; 96 | 97 | &uart0 { 98 | compatible = "nordic,nrf-uart"; 99 | status = "okay"; 100 | current-speed = <115200>; 101 | pinctrl-0=<&uart0_default>; 102 | pinctrl-1=<&uart0_sleep>; 103 | pinctrl-names = "default", "sleep"; 104 | }; 105 | 106 | &i2c0 { 107 | compatible = "nordic,nrf-twim"; 108 | status = "okay"; 109 | clock-frequency = ; 110 | pinctrl-0=<&i2c0_default>; 111 | pinctrl-names = "default"; 112 | /* embedded LIS2DH accelerometer */ 113 | lis2dh12: lis2dh12@19 { 114 | compatible = "st,lis2dh12", "st,lis2dh"; 115 | status = "okay"; 116 | reg = <0x19>; 117 | irq-gpios = <&gpio0 16 GPIO_ACTIVE_HIGH>; 118 | }; 119 | }; 120 | 121 | &spi1 { 122 | compatible = "nordic,nrf-spim"; 123 | status = "okay"; 124 | cs-gpios = <&gpio0 30 GPIO_ACTIVE_LOW>; 125 | pinctrl-0 = <&spi1_default>; 126 | pinctrl-names = "default"; 127 | }; 128 | 129 | &spi3 { 130 | compatible = "nordic,nrf-spim"; 131 | status = "okay"; 132 | pinctrl-0 = <&spi3_default>; 133 | pinctrl-names = "default"; 134 | cs-gpios = <&gpio1 6 GPIO_ACTIVE_LOW>; 135 | dwm3000: dw3000@0 { 136 | compatible = "qorvo,dw3000"; 137 | spi-max-frequency = <32000000>; 138 | status = "okay"; 139 | reg = <0>; 140 | reset-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>; 141 | irq-gpios = <&gpio1 2 GPIO_ACTIVE_HIGH>; 142 | wakeup-gpios= <&gpio1 19 GPIO_ACTIVE_HIGH>; 143 | }; 144 | 145 | }; 146 | 147 | &pwm0 { 148 | pinctrl-0 = <&pwm0_default>; 149 | pinctrl-names = "default"; 150 | }; 151 | 152 | &flash0 { 153 | 154 | partitions { 155 | compatible = "fixed-partitions"; 156 | #address-cells = <1>; 157 | #size-cells = <1>; 158 | 159 | boot_partition: partition@0 { 160 | label = "mcuboot"; 161 | reg = <0x000000000 0xC000>; 162 | }; 163 | slot0_partition: partition@c000 { 164 | label = "image-0"; 165 | reg = <0x0000C000 0x32000>; 166 | }; 167 | slot1_partition: partition@3e000 { 168 | label = "image-1"; 169 | reg = <0x0003E000 0x32000>; 170 | }; 171 | scratch_partition: partition@70000 { 172 | label = "image-scratch"; 173 | reg = <0x00070000 0xA000>; 174 | }; 175 | storage_partition: partition@7a000 { 176 | label = "storage"; 177 | reg = <0x0007A000 0x00006000>; 178 | }; 179 | }; 180 | }; 181 | -------------------------------------------------------------------------------- /samples/05_sit_ds_twr_initator/src/main.c: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file ss_twr_initiator.c 3 | * @brief Single-sided two-way ranging (SS TWR) initiator example code 4 | * 5 | * This is a simple code example which acts as the initiator in a SS TWR distance measurement exchange. This application sends a "poll" 6 | * frame (recording the TX time-stamp of the poll), after which it waits for a "response" message from the "DS TWR responder" example 7 | * code (companion to this application) to complete the exchange. The response message contains the remote responder's time-stamps of poll 8 | * RX, and response TX. With this data and the local time-stamps, (of poll TX and response RX), this example application works out a value 9 | * for the time-of-flight over-the-air and, thus, the estimated distance between the two devices, which it writes to the LCD. 10 | * 11 | * @attention 12 | * 13 | * Copyright 2015 - 2021 (c) Decawave Ltd, Dublin, Ireland. 14 | * 15 | * All rights reserved. 16 | * 17 | * @author Decawave 18 | */ 19 | #include "deca_device_api.h" 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 31 | 32 | /* Example application name */ 33 | #define APP_NAME "SIMPLE DS-TWR Initiator EXAMPLE\n" 34 | 35 | uint8_t this_initiator_node_id = 1; 36 | uint8_t responder_node_id = 2; 37 | 38 | /* Inter-ranging delay period, in milliseconds. */ 39 | #define RNG_DELAY_MS 1000 40 | 41 | /* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */ 42 | #define TX_ANT_DLY 16385 43 | #define RX_ANT_DLY 16385 44 | 45 | /* Indexes to access some of the fields in the frames defined above. */ 46 | #define ALL_MSG_SN_IDX 2 47 | #define RESP_MSG_POLL_RX_TS_IDX 10 48 | #define RESP_MSG_RESP_TX_TS_IDX 14 49 | #define RESP_MSG_TS_LEN 4 50 | /* Frame sequence number, incremented after each transmission. */ 51 | 52 | #define CPU_PROCESSING_TIME 400 53 | #define POLL_TX_TO_RESP_RX_DLY_UUS_T (350 + CPU_PROCESSING_TIME) 54 | #define RESP_RX_TO_FINAL_TX_DLY_UUS_T (350 + CPU_PROCESSING_TIME) 55 | #define RESP_RX_TIMEOUT_UUS_T 1150 56 | #define PRE_TIMEOUT 5 57 | 58 | 59 | int main(void) { 60 | printk(APP_NAME); 61 | printk("==================\n"); 62 | 63 | // INIT LED and let them Blink one Time to see Intitalion Finshed 64 | sit_led_init(); 65 | 66 | int init_ok = sit_init(); 67 | 68 | if(init_ok < 0){ 69 | sit_set_led(2, 0); 70 | } else { 71 | sit_set_led(1, 0); 72 | } 73 | uint8_t frame_sequenz = 0; 74 | while (1) { 75 | 76 | sit_set_rx_tx_delay_and_rx_timeout(POLL_TX_TO_RESP_RX_DLY_UUS_T, RESP_RX_TIMEOUT_UUS_T); 77 | sit_set_preamble_detection_timeout(PRE_TIMEOUT); 78 | 79 | msg_simple_t twr_poll = {twr_1_poll, frame_sequenz, this_initiator_node_id , responder_node_id,0}; 80 | sit_start_poll((uint8_t*) &twr_poll, (uint16_t)sizeof(twr_poll)); 81 | 82 | msg_simple_t rx_resp_msg; 83 | msg_id_t msg_id = ds_twr_2_resp; 84 | 85 | if(sit_check_msg_id(msg_id, &rx_resp_msg)) { 86 | uint64_t poll_tx_ts = get_tx_timestamp_u64(); 87 | uint64_t resp_rx_ts = get_rx_timestamp_u64(); 88 | 89 | uint32_t final_tx_time = (resp_rx_ts + (RESP_RX_TO_FINAL_TX_DLY_UUS_T * UUS_TO_DWT_TIME)) >> 8; 90 | uint64_t final_tx_ts = (((uint64_t)(final_tx_time & 0xFFFFFFFEUL)) << 8) + TX_ANT_DLY; 91 | 92 | msg_ds_twr_final_t final_msg = { 93 | ds_twr_3_final, 94 | rx_resp_msg.header.sequence, 95 | rx_resp_msg.header.dest, 96 | rx_resp_msg.header.source, 97 | (uint32_t)poll_tx_ts, 98 | (uint32_t)resp_rx_ts, 99 | (uint32_t)final_tx_ts, 100 | 0 101 | }; 102 | 103 | bool ret = sit_send_at((uint8_t*)&final_msg, sizeof(msg_ds_twr_final_t),final_tx_time); 104 | 105 | if (ret == false) { 106 | LOG_WRN("Something is wrong with Sending Final Msg"); 107 | continue; 108 | } 109 | frame_sequenz++; 110 | 111 | } else { 112 | LOG_WRN("Something is wrong with Receiving Msg"); 113 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 114 | } 115 | k_msleep(100); 116 | } 117 | return 0; 118 | } -------------------------------------------------------------------------------- /drivers/platform/dw3000_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 (c) DecaWave Ltd, Dublin, Ireland. 3 | * Copyright 2019 (c) Frederic Mes, RTLOC. 4 | * Copyright 2021 (c) Callender-Consulting LLC. 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "dw3000_spi.h" 13 | 14 | /* This file implements the SPI functions required by decadriver */ 15 | 16 | LOG_MODULE_DECLARE(dw3000, CONFIG_DW3000_LOG_LEVEL); 17 | 18 | #define TX_WAIT_RESP_NRF52840_DELAY 30 19 | 20 | #define DW_INST DT_INST(0, qorvo_dw3000) 21 | #define DW_SPI DT_PARENT(DT_INST(0, qorvo_dw3000)) 22 | 23 | static const struct device* spi; 24 | static struct spi_cs_control cs_ctrl = SPI_CS_CONTROL_INIT(DT_NODELABEL(dwm3000), 0); 25 | static struct spi_config spi_cfgs[2] = {0}; // configs for slow and fast 26 | static struct spi_config* spi_cfg; 27 | 28 | int dw3000_spi_init(void) 29 | { 30 | /* set common SPI config */ 31 | for (int i = 0; i < ARRAY_SIZE(spi_cfgs); i++) { 32 | spi_cfgs[i].cs = cs_ctrl; 33 | spi_cfgs[i].operation = SPI_WORD_SET(8); 34 | } 35 | 36 | /* Slow SPI clock speed: 2MHz */ 37 | spi_cfgs[0].frequency = 2000000; 38 | 39 | /* High SPI clock speed: assume 8MHz for all boards */ 40 | spi_cfgs[1].frequency = 8000000; 41 | 42 | /* High SPI clock speed: increase for boards which support higher speeds */ 43 | #if CONFIG_SOC_NRF52833 || CONFIG_SOC_NRF52840 44 | #if CONFIG_SHIELD_QORVO_DWS3000 45 | /* Due to the wiring of the Nordic Development Boards and the DWS3000 46 | * Arduino shield it is not possible to use more than 16MHz */ 47 | spi_cfgs[1].frequency = 16000000; 48 | #else 49 | spi_cfgs[1].frequency = 32000000; 50 | #endif 51 | #endif 52 | 53 | spi_cfg = &spi_cfgs[0]; 54 | 55 | spi = device_get_binding(DEVICE_DT_NAME(DT_NODELABEL(spi3))); 56 | if (!spi) { 57 | LOG_ERR("DW3000 SPI binding failed"); 58 | return -1; 59 | } else { 60 | LOG_INF("DW3000 on %s (max %dMHz)", DEVICE_DT_NAME(DT_NODELABEL(spi3)), 61 | spi_cfgs[1].frequency / 1000000); 62 | } 63 | 64 | return 0; 65 | } 66 | 67 | void dw3000_spi_speed_slow(void) 68 | { 69 | spi_cfg = &spi_cfgs[0]; 70 | } 71 | 72 | void dw3000_spi_speed_fast(void) 73 | { 74 | spi_cfg = &spi_cfgs[1]; 75 | } 76 | 77 | void dw3000_spi_fini(void) 78 | { 79 | // TODO 80 | } 81 | 82 | int dw3000_spi_write_crc(uint16_t headerLength, const uint8_t* headerBuffer, 83 | uint16_t bodyLength, const uint8_t* bodyBuffer, 84 | uint8_t crc8) 85 | { 86 | const struct spi_buf tx_buf[3] = { 87 | { 88 | .buf = (void*)headerBuffer, 89 | .len = headerLength, 90 | }, 91 | { 92 | .buf = (void*)bodyBuffer, 93 | .len = bodyLength, 94 | }, 95 | { 96 | .buf = &crc8, 97 | .len = 1, 98 | }, 99 | }; 100 | const struct spi_buf_set tx = { 101 | .buffers = tx_buf, 102 | .count = ARRAY_SIZE(tx_buf), 103 | }; 104 | 105 | return spi_transceive(spi, spi_cfg, &tx, NULL); 106 | } 107 | 108 | int dw3000_spi_write(uint16_t headerLength, const uint8_t* headerBuffer, 109 | uint16_t bodyLength, const uint8_t* bodyBuffer) 110 | { 111 | const struct spi_buf tx_buf[2] = { 112 | { 113 | .buf = (void*)headerBuffer, 114 | .len = headerLength, 115 | }, 116 | { 117 | .buf = (void*)bodyBuffer, 118 | .len = bodyLength, 119 | }, 120 | }; 121 | const struct spi_buf_set tx = { 122 | .buffers = tx_buf, 123 | .count = ARRAY_SIZE(tx_buf), 124 | }; 125 | 126 | return spi_transceive(spi, spi_cfg, &tx, NULL); 127 | } 128 | 129 | int dw3000_spi_read(uint16_t headerLength, uint8_t* headerBuffer, 130 | uint16_t readLength, uint8_t* readBuffer) 131 | { 132 | const struct spi_buf tx_buf = { 133 | .buf = headerBuffer, 134 | .len = headerLength, 135 | }; 136 | const struct spi_buf_set tx = { 137 | .buffers = &tx_buf, 138 | .count = 1, 139 | }; 140 | const struct spi_buf rx_buf[2] = { 141 | { 142 | .buf = NULL, 143 | .len = headerLength, 144 | }, 145 | { 146 | .buf = readBuffer, 147 | .len = readLength, 148 | }, 149 | }; 150 | const struct spi_buf_set rx = { 151 | .buffers = rx_buf, 152 | .count = ARRAY_SIZE(rx_buf), 153 | }; 154 | 155 | int ret = spi_transceive(spi, spi_cfg, &tx, &rx); 156 | 157 | #if (CONFIG_SOC_NRF52840_QIAA) 158 | /* 159 | * This is a hack to handle the corrupted response frame through the 160 | * nRF52840's SPI3. See this project's issue-log 161 | * (https://github.com/foldedtoad/dwm3000/issues/2) for details. The delay 162 | * value is set in the CMakeList.txt file for this subproject. 163 | */ 164 | if (ret == 0) { 165 | for (volatile int i = 0; i < TX_WAIT_RESP_NRF52840_DELAY; i++) { 166 | /* spin */ 167 | } 168 | } 169 | #endif 170 | 171 | return ret; 172 | } 173 | 174 | void dw3000_spi_wakeup() 175 | { 176 | gpio_pin_set_dt(&cs_ctrl.gpio, 1); 177 | k_sleep(K_USEC(500)); 178 | gpio_pin_set_dt(&cs_ctrl.gpio, 0); 179 | } 180 | -------------------------------------------------------------------------------- /lib/sit/sit_config.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_config.c 22 | * @author Sven Hoyer (svhoy) 23 | * @date 14.05.2023 24 | * @brief Defniton config options for SIT system. 25 | * 26 | * This file defines different configurations for the SIT system. 27 | * 28 | * 29 | * @bug No known bugs. 30 | * @todo everything 31 | */ 32 | 33 | #include "sit/sit_config.h" 34 | 35 | #include 36 | 37 | #define LOG_LEVEL 3 38 | #include 39 | LOG_MODULE_REGISTER(SIT_CONFIG, LOG_LEVEL_INF); 40 | 41 | device_type_t device_type = none; 42 | 43 | device_settings_t device_settings = { 44 | .deviceID = 0, 45 | .initiator = 1, 46 | .responder = 0, 47 | .tx_ant_dly = 16385, 48 | .rx_ant_dly = 16385, 49 | .state = sleep, 50 | .measurement_type = ds_3_twr, 51 | .diagnostic = false, 52 | .min_measurement = 0, 53 | .max_measurement = 0, 54 | }; 55 | 56 | dwt_config_t sit_device_config = { 57 | 9, /* Channel number. */ 58 | DWT_PLEN_128, /* Preamble length. Used in TX only. */ 59 | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ 60 | 9, /* TX preamble code. Used in TX only. */ 61 | 9, /* RX preamble code. Used in RX only. */ 62 | DWT_SFD_DW_8, /* 0 to use standard 8 symbol SFD, 1 to use non-standard 8 symbol, 2 for non-standard 16 symbol SFD and 3 for 4z 8 symbol SDF type */ 63 | DWT_BR_6M8, /* Data rate. */ 64 | DWT_PHRMODE_STD, /* PHY header mode. */ 65 | DWT_PHRRATE_STD, /* PHY header rate. */ 66 | (129 + 8 - 8), /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ 67 | DWT_STS_MODE_OFF, /* STS disabled */ 68 | DWT_STS_LEN_64, /* STS length see allowed values in Enum dwt_sts_lengths_e */ 69 | DWT_PDOA_M0 /* PDOA mode off */ 70 | }; 71 | 72 | void set_device_state(char *command) { 73 | if (strcmp(command, "start") == 0) { 74 | device_settings.state = measurement; 75 | } else if (strcmp(command, "stop") == 0) { 76 | device_settings.state = sleep; 77 | device_type = none; 78 | dwt_forcetrxoff(); 79 | } else { 80 | LOG_ERR("Wrong command"); 81 | } 82 | } 83 | 84 | void set_device_id(uint8_t device_id) { 85 | device_settings.deviceID = device_id; 86 | LOG_INF("Device ID: %d", device_settings.deviceID); 87 | } 88 | 89 | void set_device_type(char *type) { 90 | if (strcmp(type, "initiator") == 0) { 91 | device_type = initiator; 92 | } else if (strcmp(type, "responder") == 0) { 93 | device_type = responder; 94 | } else if (strcmp(type, "A") == 0) { 95 | device_type = dev_a; 96 | } else if (strcmp(type, "B") == 0) { 97 | device_type = dev_b; 98 | } else if (strcmp(type, "C") == 0) { 99 | device_type = dev_c; 100 | } else { 101 | LOG_ERR("Wrong device type"); 102 | } 103 | } 104 | 105 | void set_responder(uint8_t responder) { 106 | device_settings.responder = responder; 107 | } 108 | 109 | void set_min_measurement(uint32_t measurement) { 110 | device_settings.min_measurement = measurement; 111 | } 112 | 113 | void set_max_measurement(uint32_t measurement) { 114 | device_settings.max_measurement = measurement; 115 | } 116 | 117 | void set_measurement_type(char *measurement_type) { 118 | LOG_INF("Measurement type: %s", measurement_type); 119 | if (strcmp(measurement_type, "ss_twr") == 0) { 120 | device_settings.measurement_type = ss_twr; 121 | } else if (strcmp(measurement_type, "ds_3_twr") == 0) { 122 | device_settings.measurement_type = ds_3_twr; 123 | } else if (strcmp(measurement_type, "two_device") == 0) { 124 | device_settings.measurement_type = two_device_calibration; 125 | } 126 | else { 127 | LOG_ERR("Wrong measurement type"); 128 | } 129 | 130 | } 131 | 132 | void set_rx_ant_dly(uint16_t dly) { 133 | device_settings.rx_ant_dly = dly; 134 | dwt_setrxantennadelay(dly); 135 | } 136 | void set_tx_ant_dly(uint16_t dly) { 137 | device_settings.tx_ant_dly = dly; 138 | dwt_settxantennadelay(dly); 139 | } -------------------------------------------------------------------------------- /samples/04_sit_ss_twr_responder/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2019 - Frederic Mes, RTLOC 3 | * Copyright (c) 2015 - Decawave Ltd, Dublin, Ireland. 4 | * Copyright (c) 2021 - Home Smart Mesh 5 | * Copyright (c) 2022 - Sven Hoyer 6 | * 7 | * This file is part of Zephyr-DWM1001. 8 | * 9 | * Zephyr-DWM1001 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Zephyr-DWM1001 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Zephyr-DWM1001. If not, see . 21 | * 22 | */ 23 | #include "deca_probe_interface.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 39 | 40 | #define APP_NAME "SIMPLE TWR Responder EXAMPLE\n" 41 | 42 | /* Inter-ranging delay period, in milliseconds. */ 43 | #define RNG_DELAY_MS 1000 44 | 45 | /* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */ 46 | #define TX_ANT_DLY 16385 47 | #define RX_ANT_DLY 16385 48 | 49 | /* Default communication configuration. We use default non-STS DW mode. */ 50 | static dwt_config_t config = { 51 | 5, /* Channel number. */ 52 | DWT_PLEN_128, /* Preamble length. Used in TX only. */ 53 | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ 54 | 9, /* TX preamble code. Used in TX only. */ 55 | 9, /* RX preamble code. Used in RX only. */ 56 | DWT_SFD_DW_8, /* 0 to use standard 8 symbol SFD, 1 to use non-standard 8 symbol, 2 for non-standard 16 symbol SFD and 3 for 4z 8 symbol SDF type */ 57 | DWT_BR_6M8, /* Data rate. */ 58 | DWT_PHRMODE_STD, /* PHY header mode. */ 59 | DWT_PHRRATE_STD, /* PHY header rate. */ 60 | (129 + 8 - 8), /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ 61 | DWT_STS_MODE_OFF, /* STS disabled */ 62 | DWT_STS_LEN_64, /* STS length see allowed values in Enum dwt_sts_lengths_e */ 63 | DWT_PDOA_M0 /* PDOA mode off */ 64 | }; 65 | 66 | uint8_t this_initiator_node_id = 1; 67 | uint8_t responder_node_id = 2; 68 | 69 | /*rx twr_2_resp after tx twr_1_poll 70 | protected by responder's mp_request_at(twr_2_resp):POLL_RX_TO_RESP_TX_DLY_UUS 71 | */ 72 | #define POLL_TX_TO_RESP_RX_DLY_UUS 500 73 | 74 | /* Delay between frames, in UWB microseconds. See NOTE 1 below. */ 75 | #define POLL_RX_TO_RESP_TX_DLY_UUS 650 76 | 77 | int main(void) { 78 | printk(APP_NAME); 79 | printk("==================\n"); 80 | 81 | int init_ok = sit_init(&config, TX_ANT_DLY, RX_ANT_DLY); 82 | // INIT LED and let them Blink one Time to see Intitalion Finshed 83 | sit_led_init(); 84 | 85 | if(init_ok < 0){ 86 | sit_set_led(2, 0); 87 | } else { 88 | sit_set_led(1, 0); 89 | } 90 | 91 | uint32_t regStatus = sit_get_device_status(); 92 | LOG_INF("statusreg = 0x%08x",regStatus); 93 | k_sleep(K_SECONDS(2)); // Allow Logging to write out put 94 | 95 | int frame_sequenz = 0; 96 | k_yield(); 97 | 98 | while (1) { 99 | regStatus = sit_get_device_status(); 100 | LOG_INF("sequence(%u) starting ; statusreg = 0x%08x",frame_sequenz,regStatus); 101 | sit_receiveNow(0); 102 | msg_header_t rx_poll_msg; 103 | msg_id_t msg_id = twr_1_poll; 104 | if(sit_checkReceivedIdMsg(msg_id, &rx_poll_msg)){ 105 | uint64_t poll_rx_ts = get_rx_timestamp_u64(); 106 | 107 | uint32_t resp_tx_time = (poll_rx_ts + (POLL_RX_TO_RESP_TX_DLY_UUS * UUS_TO_DWT_TIME)) >> 8; 108 | 109 | uint32_t resp_tx_ts = (((uint64_t)(resp_tx_time & 0xFFFFFFFEUL)) << 8) + TX_ANT_DLY; 110 | 111 | msg_ss_twr_final_t msg_ss_twr_final_t = { 112 | ss_twr_2_resp, (uint8_t)(rx_poll_msg.header.sequence + 1), 113 | rx_poll_msg.header.dest , rx_poll_msg.header.source,(uint32_t)poll_rx_ts, resp_tx_ts,0 114 | }; 115 | sit_sendAt((uint8_t*)&msg_ss_twr_final_t, sizeof(msg_ss_twr_final_t), resp_tx_time); 116 | 117 | } else { 118 | LOG_WRN("Something is wrong"); 119 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 120 | } 121 | regStatus = sit_get_device_status(); 122 | LOG_INF("sequence(%u) ending ; statusreg = 0x%08x",frame_sequenz,regStatus); 123 | frame_sequenz++; 124 | k_sleep(K_MSEC(RNG_DELAY_MS)); 125 | } 126 | 127 | return 0; 128 | } 129 | -------------------------------------------------------------------------------- /samples/03a_sit_ss_twr_initator/src/main.c: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file ss_twr_initiator.c 3 | * @brief Single-sided two-way ranging (SS TWR) initiator example code 4 | * 5 | * This is a simple code example which acts as the initiator in a SS TWR distance measurement exchange. This application sends a "poll" 6 | * frame (recording the TX time-stamp of the poll), after which it waits for a "response" message from the "DS TWR responder" example 7 | * code (companion to this application) to complete the exchange. The response message contains the remote responder's time-stamps of poll 8 | * RX, and response TX. With this data and the local time-stamps, (of poll TX and response RX), this example application works out a value 9 | * for the time-of-flight over-the-air and, thus, the estimated distance between the two devices, which it writes to the LCD. 10 | * 11 | * @attention 12 | * 13 | * Copyright 2015 - 2021 (c) Decawave Ltd, Dublin, Ireland. 14 | * 15 | * All rights reserved. 16 | * 17 | * @author Decawave 18 | */ 19 | #include "deca_probe_interface.h" 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 34 | 35 | /* Example application name */ 36 | #define APP_NAME "SS TWR INIT v1.0" 37 | 38 | /* Default communication configuration. We use default non-STS DW mode. */ 39 | static dwt_config_t config = { 40 | 5, /* Channel number. */ 41 | DWT_PLEN_128, /* Preamble length. Used in TX only. */ 42 | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ 43 | 9, /* TX preamble code. Used in TX only. */ 44 | 9, /* RX preamble code. Used in RX only. */ 45 | DWT_SFD_DW_8, /* 0 to use standard 8 symbol SFD, 1 to use non-standard 8 symbol, 2 for non-standard 16 symbol SFD and 3 for 4z 8 symbol SDF type */ 46 | DWT_BR_6M8, /* Data rate. */ 47 | DWT_PHRMODE_STD, /* PHY header mode. */ 48 | DWT_PHRRATE_STD, /* PHY header rate. */ 49 | (129 + 8 - 8), /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ 50 | DWT_STS_MODE_OFF, /* STS disabled */ 51 | DWT_STS_LEN_64, /* STS length see allowed values in Enum dwt_sts_lengths_e */ 52 | DWT_PDOA_M0 /* PDOA mode off */ 53 | }; 54 | 55 | uint8_t this_initiator_node_id = 1; 56 | uint8_t responder_node_id = 2; 57 | 58 | /* Inter-ranging delay period, in milliseconds. */ 59 | #define RNG_DELAY_MS 1000 60 | 61 | /* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */ 62 | #define TX_ANT_DLY 16385 63 | #define RX_ANT_DLY 16385 64 | 65 | /* Indexes to access some of the fields in the frames defined above. */ 66 | #define ALL_MSG_SN_IDX 2 67 | #define RESP_MSG_POLL_RX_TS_IDX 10 68 | #define RESP_MSG_RESP_TX_TS_IDX 14 69 | #define RESP_MSG_TS_LEN 4 70 | /* Frame sequence number, incremented after each transmission. */ 71 | static uint8_t frame_seq_nb = 0; 72 | 73 | /* Delay between frames, in UWB microseconds. See NOTE 1 below. */ 74 | #define POLL_TX_TO_RESP_RX_DLY_UUS 240 75 | /* Receive response timeout. See NOTE 5 below. */ 76 | #define RESP_RX_TIMEOUT_UUS 400 77 | 78 | uint32_t regStatus = 0; 79 | 80 | int main(void) { 81 | printk(APP_NAME); 82 | printk("==================\n"); 83 | 84 | int init_ok = sit_init(&config, TX_ANT_DLY, RX_ANT_DLY); 85 | // INIT LED and let them Blink one Time to see Intitalion Finshed 86 | sit_led_init(); 87 | 88 | if(init_ok < 0){ 89 | sit_set_led(2, 0); 90 | } else { 91 | sit_set_led(1, 0); 92 | } 93 | 94 | uint32_t regStatus = sit_get_device_status(); 95 | LOG_INF("statusreg = 0x%08x",regStatus); 96 | k_sleep(K_SECONDS(2)); // Allow Logging to write out put 97 | 98 | uint8_t frame_sequenz = 0; 99 | k_yield(); 100 | 101 | while (1) { 102 | regStatus = sit_get_device_status(); 103 | LOG_INF("initiator> sequence(%u) starting ; statusreg = 0x%08x",frame_sequenz,regStatus); 104 | sit_setRxAfterTxDelay(POLL_TX_TO_RESP_RX_DLY_UUS, RESP_RX_TIMEOUT_UUS); 105 | msg_header_t twr_poll = {twr_1_poll, frame_sequenz, this_initiator_node_id , responder_node_id,0}; 106 | sit_startPoll((uint8_t*) &twr_poll, (uint16_t)sizeof(twr_poll)); 107 | regStatus = sit_get_device_status(); 108 | LOG_INF("statusreg = 0x%08x",regStatus); 109 | 110 | frame_sequenz++; 111 | 112 | msg_ss_twr_final_t rx_final_msg; 113 | msg_id_t msg_id = ss_twr_2_resp; 114 | regStatus = sit_get_device_status(); 115 | if(sit_checkReceivedIdFinalMsg(msg_id, &rx_final_msg)) { 116 | uint64_t poll_tx_ts = get_tx_timestamp_u64(); 117 | uint64_t resp_rx_ts = get_rx_timestamp_u64(); 118 | 119 | uint64_t poll_rx_ts = rx_final_msg.poll_rx_ts; 120 | uint64_t resp_tx_ts = rx_final_msg.resp_tx_ts; 121 | 122 | float clockOffsetRatio = dwt_readcarrierintegrator() * 123 | (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ; 124 | 125 | uint64_t rtd_init = resp_rx_ts - poll_tx_ts; 126 | uint64_t rtd_resp = resp_tx_ts - poll_rx_ts; 127 | 128 | float tof = ((rtd_init - rtd_resp * 129 | (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS; 130 | 131 | float distance = tof * SPEED_OF_LIGHT; 132 | printk("initiator -> responder Distance: %3.2lf \n", distance); 133 | } else { 134 | LOG_WRN("Something is wrong"); 135 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 136 | } 137 | k_sleep(K_MSEC(RNG_DELAY_MS)); 138 | } 139 | return 0; 140 | } -------------------------------------------------------------------------------- /samples/06_sit_ds_twr_responder/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2019 - Frederic Mes, RTLOC 3 | * Copyright (c) 2015 - Decawave Ltd, Dublin, Ireland. 4 | * Copyright (c) 2021 - Home Smart Mesh 5 | * Copyright (c) 2022 - Sven Hoyer 6 | * 7 | * This file is part of Zephyr-DWM1001. 8 | * 9 | * Zephyr-DWM1001 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Zephyr-DWM1001 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Zephyr-DWM1001. If not, see . 21 | * 22 | */ 23 | #include "deca_device_api.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 36 | 37 | #define APP_NAME "SIMPLE DS-TWR Responder EXAMPLE\n" 38 | 39 | /* Inter-ranging delay period, in milliseconds. */ 40 | #define RNG_DELAY_MS 1000 41 | 42 | /* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */ 43 | #define TX_ANT_DLY 16385 44 | #define RX_ANT_DLY 16385 45 | 46 | /* Default communication configuration. We use default non-STS DW mode. */ 47 | static dwt_config_t config = { 48 | 5, /* Channel number. */ 49 | DWT_PLEN_128, /* Preamble length. Used in TX only. */ 50 | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ 51 | 9, /* TX preamble code. Used in TX only. */ 52 | 9, /* RX preamble code. Used in RX only. */ 53 | DWT_SFD_DW_8, /* 0 to use standard 8 symbol SFD, 1 to use non-standard 8 symbol, 2 for non-standard 16 symbol SFD and 3 for 4z 8 symbol SDF type */ 54 | DWT_BR_6M8, /* Data rate. */ 55 | DWT_PHRMODE_STD, /* PHY header mode. */ 56 | DWT_PHRRATE_STD, /* PHY header rate. */ 57 | (129 + 8 - 8), /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ 58 | DWT_STS_MODE_OFF, /* STS disabled */ 59 | DWT_STS_LEN_64, /* STS length see allowed values in Enum dwt_sts_lengths_e */ 60 | DWT_PDOA_M0 /* PDOA mode off */ 61 | }; 62 | 63 | uint8_t this_initiator_node_id = 1; 64 | uint8_t responder_node_id = 2; 65 | 66 | 67 | #define POLL_RX_TO_RESP_TX_DLY_UUS_T 900 68 | #define RESP_TX_TO_FINAL_RX_DLY_UUS_T 600 69 | #define FINAL_RX_TIMEOUT_T 1200 70 | #define PRE_TIMEOUT 5 71 | 72 | int main(void) { 73 | printk(APP_NAME); 74 | printk("==================\n"); 75 | 76 | // INIT LED and let them Blink one Time to see Intitalion Finshed 77 | sit_led_init(); 78 | 79 | int init_ok = 0; 80 | do { 81 | init_ok = sit_init(); 82 | } while (init_ok > 1); 83 | 84 | if(init_ok < 0){ 85 | sit_set_led(2, 1); 86 | } else { 87 | sit_set_led(1, 1); 88 | } 89 | 90 | uint8_t frame_sequenz = 0; 91 | 92 | while (1) { 93 | sit_receive_now(); 94 | msg_simple_t rx_poll_msg; 95 | msg_id_t msg_id = twr_1_poll; 96 | if(sit_check_msg_id(msg_id, &rx_poll_msg)){ 97 | uint64_t poll_rx_ts = get_rx_timestamp_u64(); 98 | 99 | uint32_t resp_tx_time = (poll_rx_ts + (POLL_RX_TO_RESP_TX_DLY_UUS_T * UUS_TO_DWT_TIME)) >> 8; 100 | 101 | msg_simple_t msg_ds_poll_resp = { 102 | ds_twr_2_resp, 103 | rx_poll_msg.header.sequence, 104 | rx_poll_msg.header.dest, 105 | rx_poll_msg.header.source, 106 | 0 107 | }; 108 | sit_set_rx_after_tx_delay(RESP_TX_TO_FINAL_RX_DLY_UUS_T); 109 | sit_set_rx_timeout(FINAL_RX_TIMEOUT_T); 110 | sit_set_preamble_detection_timeout(PRE_TIMEOUT); 111 | bool ret = sit_send_at_with_response((uint8_t*)&msg_ds_poll_resp, sizeof(msg_simple_t), resp_tx_time); 112 | if (ret == false) { 113 | continue; 114 | LOG_WRN("Something is wrong with Sending Poll Resp Msg"); 115 | } 116 | msg_ds_twr_final_t rx_ds_final_msg; 117 | msg_id = ds_twr_3_final; 118 | if(sit_check_ds_final_msg_id(msg_id, &rx_ds_final_msg)){ 119 | uint64_t resp_tx_ts = get_tx_timestamp_u64(); 120 | uint64_t final_rx_ts = get_rx_timestamp_u64(); 121 | 122 | uint32_t poll_tx_ts = rx_ds_final_msg.poll_tx_ts; 123 | uint32_t resp_rx_ts = rx_ds_final_msg.resp_rx_ts; 124 | uint32_t final_tx_ts = rx_ds_final_msg.final_tx_ts; 125 | 126 | uint32_t poll_rx_ts_32, resp_tx_ts_32, final_rx_ts_32; 127 | poll_rx_ts_32 = (uint32_t) poll_rx_ts; 128 | resp_tx_ts_32 = (uint32_t) resp_tx_ts; 129 | final_rx_ts_32 = (uint32_t) final_rx_ts; 130 | 131 | double Ra, Rb, Da, Db; 132 | int64_t tof_dtu; 133 | Ra = (double)(resp_rx_ts - poll_tx_ts); 134 | Rb = (double)(final_rx_ts_32 - resp_tx_ts_32); 135 | Da = (double)(final_tx_ts - resp_rx_ts); 136 | Db = (double)(resp_tx_ts_32 - poll_rx_ts_32); 137 | tof_dtu = (int64_t)((Ra * Rb - Da * Db) / (Ra + Rb + Da + Db)); 138 | 139 | double tof = tof_dtu * DWT_TIME_UNITS; 140 | double distance = tof * SPEED_OF_LIGHT; 141 | LOG_INF("Distance: %lf", distance); 142 | } else { 143 | LOG_WRN("Something is wrong with Final Msg Receive"); 144 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 145 | } 146 | 147 | } else { 148 | LOG_WRN("Something is wrong with Poll Msg Receive"); 149 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 150 | } 151 | frame_sequenz++; 152 | k_msleep(80); 153 | } 154 | 155 | return 0; 156 | } 157 | -------------------------------------------------------------------------------- /lib/sit_json/sit_json.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "sit_json/sit_json.h" 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | 12 | #define LOG_LEVEL 3 13 | #include 14 | LOG_MODULE_REGISTER(SIT_JSON, LOG_LEVEL_INF); 15 | 16 | 17 | 18 | int json_decode_distance(char *json, size_t len, void *val) { 19 | int ret = 5; 20 | return ret; 21 | } 22 | 23 | int json_encode_distance(char **json, double *distance){ 24 | cJSON *json_object = cJSON_CreateObject(); 25 | if (cJSON_AddStringToObject(json_object, "type", "distance_msg") == NULL) { 26 | return -1; 27 | } 28 | if (cJSON_AddNumberToObject(json_object, "distance", *distance) == NULL) { 29 | return -2; 30 | } 31 | char* jsonString = cJSON_Print(json_object); 32 | size_t jsonStringLength = strlen(jsonString); 33 | *json = (char*)malloc((jsonStringLength + 1) * sizeof(char)); 34 | if (*json == NULL) { 35 | k_free(jsonString); 36 | return -3; 37 | } 38 | 39 | strcpy(*json, jsonString); 40 | 41 | cJSON_Delete(json_object); 42 | k_free(jsonString); 43 | return 0; 44 | } 45 | 46 | int json_decode_state_msg(char *json, json_command_msg_t *command_struct) { 47 | 48 | const cJSON *type = NULL; 49 | const cJSON *command = NULL; 50 | cJSON *json_msg = cJSON_Parse(json); 51 | if (json_msg == NULL) { 52 | const char *error_ptr = cJSON_GetErrorPtr(); 53 | if (error_ptr != NULL) 54 | { 55 | LOG_ERR("Error before: %s\n", error_ptr); 56 | } 57 | return -1; 58 | } 59 | 60 | type = cJSON_GetObjectItemCaseSensitive(json_msg, "type"); 61 | if (cJSON_IsString(type)) { 62 | LOG_INF("Checking msg type \"%s\"\n", type->valuestring); 63 | strcpy(command_struct->type, type->valuestring); 64 | } else { 65 | LOG_ERR("Something wrong"); 66 | } 67 | 68 | command = cJSON_GetObjectItemCaseSensitive(json_msg, "command"); 69 | if (cJSON_IsString(command) && (command->valuestring != NULL)) { 70 | LOG_INF("Checking command \"%s\"\n", command->valuestring); 71 | strcpy(command_struct->command, command->valuestring); 72 | } else { 73 | LOG_ERR("Something wrong"); 74 | } 75 | 76 | LOG_INF("Type: %s", type->valuestring); 77 | cJSON_Delete(json_msg); 78 | 79 | return 0; 80 | } 81 | 82 | int json_decode_setup_msg(char *json, json_setup_msg_t *setup_struct) { 83 | 84 | const cJSON *type = NULL; 85 | const cJSON *device_type = NULL; 86 | const cJSON *initiator_device = NULL; 87 | const cJSON *initiator = NULL; 88 | const cJSON *responder_list = NULL; 89 | const cJSON *responder_device = NULL; 90 | const cJSON *responder = NULL; 91 | const cJSON *min_measurement = NULL; 92 | const cJSON *max_measurement = NULL; 93 | const cJSON *measurement_type = NULL; 94 | const cJSON *rx_ant_dly = NULL; 95 | const cJSON *tx_ant_dly = NULL; 96 | cJSON *json_msg = cJSON_Parse(json); 97 | if (json_msg == NULL) { 98 | const char *error_ptr = cJSON_GetErrorPtr(); 99 | if (error_ptr != NULL) 100 | { 101 | LOG_ERR("Error before: %s\n", error_ptr); 102 | } 103 | return -1; 104 | } 105 | 106 | type = cJSON_GetObjectItemCaseSensitive(json_msg, "type"); 107 | if (cJSON_IsString(type)) { 108 | LOG_INF("Checking msg type \"%s\"\n", type->valuestring); 109 | strcpy(setup_struct->type, type->valuestring); 110 | } else { 111 | LOG_ERR("Something with msg type wrong"); 112 | } 113 | 114 | device_type = cJSON_GetObjectItemCaseSensitive(json_msg, "device_type"); 115 | if (cJSON_IsString(device_type)) { 116 | LOG_INF("Checking msg device_type \"%s\"\n", device_type->valuestring); 117 | strcpy(setup_struct->device_type, device_type->valuestring); 118 | } else { 119 | LOG_ERR("Something with device type wrong"); 120 | } 121 | 122 | initiator_device = cJSON_GetObjectItemCaseSensitive(json_msg, "initiator_device"); 123 | if (cJSON_IsString(initiator_device) && (initiator_device->valuestring != NULL)) { 124 | LOG_INF("Checking initiator_device \"%s\"\n", initiator_device->valuestring); 125 | strcpy(setup_struct->initiator_device, initiator_device->valuestring); 126 | } else { 127 | LOG_ERR("Something init device wrong"); 128 | } 129 | 130 | initiator = cJSON_GetObjectItemCaseSensitive(json_msg, "initiator"); 131 | setup_struct->initiator = initiator->valueint; 132 | 133 | responder_list = cJSON_GetObjectItemCaseSensitive(json_msg, "responder_device"); 134 | uint8_t index = 0; 135 | cJSON_ArrayForEach(responder_device, responder_list) { 136 | if (cJSON_IsString(responder_device) && (responder_device->valuestring != NULL)) { 137 | LOG_INF("Checking responder_device \"%s\"\n", responder_device->valuestring); 138 | strcpy(setup_struct->responder_device[index], responder_device->valuestring); 139 | } else { 140 | LOG_ERR("Something resp devicewrong"); 141 | } 142 | index++; 143 | } 144 | 145 | responder = cJSON_GetObjectItemCaseSensitive(json_msg, "responder"); 146 | setup_struct->responder = responder->valueint; 147 | 148 | min_measurement = cJSON_GetObjectItemCaseSensitive(json_msg, "min_measurement"); 149 | setup_struct->min_measurement = min_measurement->valueint; 150 | 151 | max_measurement = cJSON_GetObjectItemCaseSensitive(json_msg, "max_measurement"); 152 | setup_struct->max_measurement = max_measurement->valueint; 153 | 154 | measurement_type = cJSON_GetObjectItemCaseSensitive(json_msg, "measurement_type"); 155 | if (cJSON_IsString(measurement_type)) { 156 | LOG_INF("Checking Measurement Type \"%s\"\n", measurement_type->valuestring); 157 | strcpy(setup_struct->measurement_type, measurement_type->valuestring); 158 | } else { 159 | LOG_ERR("Something measurement type wrong"); 160 | } 161 | 162 | rx_ant_dly = cJSON_GetObjectItemCaseSensitive(json_msg, "rx_ant_dly"); 163 | setup_struct->rx_ant_dly = rx_ant_dly->valueint; 164 | LOG_INF("Checking RX DLY Type \"%d\"\n", rx_ant_dly->valueint); 165 | tx_ant_dly = cJSON_GetObjectItemCaseSensitive(json_msg, "tx_ant_dly"); 166 | LOG_INF("Checking RX DLY Type \"%d\"\n", tx_ant_dly->valueint); 167 | setup_struct->tx_ant_dly = tx_ant_dly->valueint; 168 | 169 | LOG_INF("Type: %s", type->valuestring); 170 | cJSON_Delete(json_msg); 171 | 172 | return 0; 173 | } -------------------------------------------------------------------------------- /samples/03b_sit_ss_twr_initator_ble_output/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2019 - Frederic Mes, RTLOC 3 | * Copyright (c) 2015 - Decawave Ltd, Dublin, Ireland. 4 | * Copyright (c) 2021 - Home Smart Mesh 5 | * Copyright (c) 2022 - Sven Hoyer 6 | * 7 | * This file is part of Zephyr-DWM1001. 8 | * 9 | * Zephyr-DWM1001 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Zephyr-DWM1001 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Zephyr-DWM1001. If not, see . 21 | * 22 | */ 23 | #include "deca_probe_interface.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #define APP_NAME "SIMPLE TWR Initiator BLE EXAMPLE\n" 44 | 45 | #include 46 | #include 47 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 48 | 49 | /* Default communication configuration. We use default non-STS DW mode. */ 50 | static dwt_config_t config = { 51 | 5, /* Channel number. */ 52 | DWT_PLEN_128, /* Preamble length. Used in TX only. */ 53 | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ 54 | 9, /* TX preamble code. Used in TX only. */ 55 | 9, /* RX preamble code. Used in RX only. */ 56 | DWT_SFD_DW_8, /* 0 to use standard 8 symbol SFD, 1 to use non-standard 8 symbol, 2 for non-standard 16 symbol SFD and 3 for 4z 8 symbol SDF type */ 57 | DWT_BR_6M8, /* Data rate. */ 58 | DWT_PHRMODE_STD, /* PHY header mode. */ 59 | DWT_PHRRATE_STD, /* PHY header rate. */ 60 | (129 + 8 - 8), /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ 61 | DWT_STS_MODE_OFF, /* STS disabled */ 62 | DWT_STS_LEN_64, /* STS length see allowed values in Enum dwt_sts_lengths_e */ 63 | DWT_PDOA_M0 /* PDOA mode off */ 64 | }; 65 | 66 | uint8_t this_initiator_node_id = 1; 67 | uint8_t responder_node_id = 2; 68 | 69 | /* Inter-ranging delay period, in milliseconds. */ 70 | #define RNG_DELAY_MS 1000 71 | 72 | /* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */ 73 | #define TX_ANT_DLY 16385 74 | #define RX_ANT_DLY 16385 75 | 76 | /* Indexes to access some of the fields in the frames defined above. */ 77 | #define ALL_MSG_SN_IDX 2 78 | #define RESP_MSG_POLL_RX_TS_IDX 10 79 | #define RESP_MSG_RESP_TX_TS_IDX 14 80 | #define RESP_MSG_TS_LEN 4 81 | /* Frame sequence number, incremented after each transmission. */ 82 | static uint8_t frame_seq_nb = 0; 83 | 84 | /* Delay between frames, in UWB microseconds. See NOTE 1 below. */ 85 | #define POLL_TX_TO_RESP_RX_DLY_UUS 240 86 | /* Receive response timeout. See NOTE 5 below. */ 87 | #define RESP_RX_TIMEOUT_UUS 400 88 | 89 | uint32_t regStatus = 0; 90 | 91 | int main(void) { 92 | printk(APP_NAME); 93 | printk("==================\n"); 94 | 95 | int init_ok = sit_init(config, TX_ANT_DLY, RX_ANT_DLY); 96 | // INIT LED and let them Blink one Time to see Intitalion Finshed 97 | sit_led_init(); 98 | ble_device_init(); 99 | 100 | if(init_ok < 0){ 101 | sit_set_led(2, 0); 102 | } else { 103 | sit_set_led(1, 0); 104 | } 105 | 106 | regStatus = sit_get_device_status(); 107 | LOG_INF("statusreg = 0x%08x",regStatus); 108 | k_sleep(K_SECONDS(2)); // Allow Logging to write out put 109 | 110 | uint8_t frame_sequenz = 0; 111 | k_yield(); 112 | 113 | while (1) { 114 | k_sleep(K_SECONDS(1)); 115 | if (is_connected()) { 116 | sit_set_led(3, 0); 117 | } else { 118 | sit_toggle_led(3); 119 | } 120 | while (is_connected()) { 121 | regStatus = sit_get_device_status(); 122 | LOG_INF("initiator> sequence(%u) starting ; statusreg = 0x%08x",frame_sequenz,regStatus); 123 | sit_setRxAfterTxDelay(POLL_TX_TO_RESP_RX_DLY_UUS, RESP_RX_TIMEOUT_UUS); 124 | msg_header_t twr_poll = {twr_1_poll, frame_sequenz, this_initiator_node_id , responder_node_id,0}; 125 | sit_startPoll((uint8_t*) &twr_poll, (uint16_t)sizeof(twr_poll)); 126 | regStatus = sit_get_device_status(); 127 | LOG_INF("statusreg = 0x%08x",regStatus); 128 | 129 | frame_sequenz++; 130 | 131 | msg_ss_twr_final_t rx_final_msg; 132 | msg_id_t msg_id = ss_twr_2_resp; 133 | regStatus = sit_get_device_status(); 134 | if(sit_checkReceivedIdFinalMsg(msg_id, rx_final_msg)) { 135 | uint64_t poll_tx_ts = get_tx_timestamp_u64(); 136 | uint64_t resp_rx_ts = get_rx_timestamp_u64(); 137 | 138 | uint64_t poll_rx_ts = rx_final_msg.poll_rx_ts; 139 | uint64_t resp_tx_ts = rx_final_msg.resp_tx_ts; 140 | 141 | float clockOffsetRatio = dwt_readcarrierintegrator() * 142 | (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ; 143 | 144 | uint64_t rtd_init = resp_rx_ts - poll_tx_ts; 145 | uint64_t rtd_resp = resp_tx_ts - poll_rx_ts; 146 | 147 | float tof = ((rtd_init - rtd_resp * 148 | (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS; 149 | 150 | float distance = tof * SPEED_OF_LIGHT; 151 | printk("initiator -> responder Distance: %3.2lf \n", distance); 152 | if((int) distance >= 0) { 153 | ble_sit_notify(distance); 154 | } 155 | } else { 156 | LOG_WRN("Something is wrong"); 157 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 158 | } 159 | k_sleep(K_MSEC(RNG_DELAY_MS)); 160 | } 161 | } 162 | return 0; 163 | } 164 | -------------------------------------------------------------------------------- /samples/03c_sit_ss_twr_initator_ble_in-output/src/main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2019 - Frederic Mes, RTLOC 3 | * Copyright (c) 2015 - Decawave Ltd, Dublin, Ireland. 4 | * Copyright (c) 2021 - Home Smart Mesh 5 | * Copyright (c) 2022 - Sven Hoyer 6 | * 7 | * This file is part of Zephyr-DWM1001. 8 | * 9 | * Zephyr-DWM1001 is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 3 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * Zephyr-DWM1001 is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with Zephyr-DWM1001. If not, see . 21 | * 22 | */ 23 | #include "deca_probe_interface.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #define APP_NAME "SIMPLE TWR Initiator BLE EXAMPLE\n" 44 | 45 | #include 46 | #include 47 | LOG_MODULE_REGISTER(main, LOG_LEVEL_INF); 48 | 49 | /* Default communication configuration. We use default non-STS DW mode. */ 50 | static dwt_config_t config = { 51 | 5, /* Channel number. */ 52 | DWT_PLEN_128, /* Preamble length. Used in TX only. */ 53 | DWT_PAC8, /* Preamble acquisition chunk size. Used in RX only. */ 54 | 9, /* TX preamble code. Used in TX only. */ 55 | 9, /* RX preamble code. Used in RX only. */ 56 | DWT_SFD_DW_8, /* 0 to use standard 8 symbol SFD, 1 to use non-standard 8 symbol, 2 for non-standard 16 symbol SFD and 3 for 4z 8 symbol SDF type */ 57 | DWT_BR_6M8, /* Data rate. */ 58 | DWT_PHRMODE_STD, /* PHY header mode. */ 59 | DWT_PHRRATE_STD, /* PHY header rate. */ 60 | (129 + 8 - 8), /* SFD timeout (preamble length + 1 + SFD length - PAC size). Used in RX only. */ 61 | DWT_STS_MODE_OFF, /* STS disabled */ 62 | DWT_STS_LEN_64, /* STS length see allowed values in Enum dwt_sts_lengths_e */ 63 | DWT_PDOA_M0 /* PDOA mode off */ 64 | }; 65 | 66 | uint8_t this_initiator_node_id = 1; 67 | uint8_t responder_node_id = 2; 68 | 69 | /* Inter-ranging delay period, in milliseconds. */ 70 | #define RNG_DELAY_MS 100 71 | 72 | /* Default antenna delay values for 64 MHz PRF. See NOTE 2 below. */ 73 | #define TX_ANT_DLY 16385 74 | #define RX_ANT_DLY 16385 75 | 76 | /* Indexes to access some of the fields in the frames defined above. */ 77 | #define ALL_MSG_SN_IDX 2 78 | #define RESP_MSG_POLL_RX_TS_IDX 10 79 | #define RESP_MSG_RESP_TX_TS_IDX 14 80 | #define RESP_MSG_TS_LEN 4 81 | /* Frame sequence number, incremented after each transmission. */ 82 | static uint8_t frame_seq_nb = 0; 83 | 84 | /* Delay between frames, in UWB microseconds. See NOTE 1 below. */ 85 | #define POLL_TX_TO_RESP_RX_DLY_UUS 240 86 | /* Receive response timeout. See NOTE 5 below. */ 87 | #define RESP_RX_TIMEOUT_UUS 400 88 | 89 | uint32_t regStatus = 0; 90 | 91 | int main(void) { 92 | printk(APP_NAME); 93 | printk("==================\n"); 94 | 95 | int init_ok = sit_init(&config, TX_ANT_DLY, RX_ANT_DLY); 96 | // INIT LED and let them Blink one Time to see Intitalion Finshed 97 | sit_led_init(); 98 | ble_device_init(); 99 | 100 | if(init_ok < 0){ 101 | sit_set_led(2, 0); 102 | } else { 103 | sit_set_led(1, 0); 104 | } 105 | 106 | regStatus = sit_get_device_status(); 107 | LOG_INF("statusreg = 0x%08x",regStatus); 108 | k_sleep(K_SECONDS(2)); // Allow Logging to write out put 109 | 110 | uint8_t frame_sequenz = 0; 111 | k_yield(); 112 | 113 | while (1) { 114 | k_sleep(K_SECONDS(1)); 115 | if (is_connected()) { 116 | sit_set_led(3, 0); 117 | } else { 118 | sit_toggle_led(3); 119 | } 120 | while (is_connected() && (ble_get_command() == 5)) { 121 | regStatus = sit_get_device_status(); 122 | LOG_INF("initiator> sequence(%u) starting ; statusreg = 0x%08x",frame_sequenz,regStatus); 123 | sit_setRxAfterTxDelay(POLL_TX_TO_RESP_RX_DLY_UUS, RESP_RX_TIMEOUT_UUS); 124 | msg_header_t twr_poll = {twr_1_poll, frame_sequenz, initiator_node_id , responder_node_id, 0}; 125 | sit_startPoll((uint8_t*) &twr_poll, (uint16_t)sizeof(twr_poll)); 126 | regStatus = sit_get_device_status(); 127 | LOG_INF("statusreg = 0x%08x",regStatus); 128 | 129 | frame_sequenz++; 130 | 131 | msg_ss_twr_final_t rx_final_msg; 132 | msg_id_t msg_id = ss_twr_2_resp; 133 | regStatus = sit_get_device_status(); 134 | if(sit_checkReceivedIdFinalMsg(msg_id, rx_final_msg)) { 135 | uint64_t poll_tx_ts = get_tx_timestamp_u64(); 136 | uint64_t resp_rx_ts = get_rx_timestamp_u64(); 137 | 138 | uint64_t poll_rx_ts = rx_final_msg.poll_rx_ts; 139 | uint64_t resp_tx_ts = rx_final_msg.resp_tx_ts; 140 | 141 | float clockOffsetRatio = dwt_readcarrierintegrator() * 142 | (FREQ_OFFSET_MULTIPLIER * HERTZ_TO_PPM_MULTIPLIER_CHAN_5 / 1.0e6) ; 143 | 144 | uint64_t rtd_init = resp_rx_ts - poll_tx_ts; 145 | uint64_t rtd_resp = resp_tx_ts - poll_rx_ts; 146 | 147 | float tof = ((rtd_init - rtd_resp * 148 | (1 - clockOffsetRatio)) / 2.0) * DWT_TIME_UNITS; 149 | 150 | float distance = tof * SPEED_OF_LIGHT; 151 | printk("initiator -> responder Distance: %3.2lf \n", distance); 152 | if((int) distance >= 0) { 153 | ble_sit_notify(distance); 154 | } 155 | } else { 156 | LOG_WRN("Something is wrong"); 157 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 158 | } 159 | k_sleep(K_MSEC(RNG_DELAY_MS)); 160 | } 161 | } 162 | return 0; 163 | } 164 | -------------------------------------------------------------------------------- /include/sit/sit_device.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_device.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief SIT device header. 25 | * 26 | * Device Functions Definiton to read the device status register 27 | * 28 | * @bug No known bugs. 29 | * @todo everything 30 | */ 31 | #include 32 | #include 33 | 34 | /*************************************************************************** 35 | * Read the systemstatus low register and return the device status 36 | * 37 | * @return uint_32 status register 38 | * 39 | ****************************************************************************/ 40 | uint32_t sit_get_device_status(void); 41 | 42 | /*************************************************************************************************************************************************** 43 | * @brief This function will continuously read the system status register until it matches the bits set in the mask 44 | * input parameter. It will then exit the function. 45 | * This is useful to use when waiting on particular events to occurs. For example, the user could wait for a 46 | * good UWB frame to be received and/or no receive errors have occurred. 47 | * The lower 32-bits of the system status register will be read in a while loop. Each iteration of the loop will check if a matching 48 | * mask value for the higher 32-bits of the system status register is set. If the mask value is set in the higher 32-bits of the system 49 | * status register, the function will return that value along with the last recorded value of the lower 32-bits of the system status 50 | * register. Thus, the user should be aware that this function will not wait for high and low mask values to be set in both the low and high 51 | * system status registers. Alternatively, the user can call this function to *only* check the higher or lower system status registers. 52 | * 53 | * input parameters 54 | * @param lo_result - A pointer to a uint32_t that will contain the final value of the system status register (lower 32 bits). 55 | * Pass in a NULL pointer to ignore returning this value. 56 | * @param hi_result - A pointer to a uint32_t that will contain the final value of the system status register (higher 32 bits). 57 | * Pass in a NULL pointer to ignore returning this value. 58 | * @param lo_mask - a uint32 mask value that is used to check for certain bits to be set in the system status register (lower 32 bits). 59 | * Example values to use are as follows: 60 | * DWT_INT_TXFRS_BIT_MASK - Wait for a TX frame to be sent. 61 | * SYS_STATUS_RXFCG_BIT_MASK | SYS_STATUS_ALL_RX_ERR - Wait for frame to be received and no reception errors. 62 | * SYS_STATUS_RXFCG_BIT_MASK | SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR - Wait for frame to be received and no receive timeout errors 63 | * and no reception errors. 64 | * SYS_STATUS_RXFR_BIT_MASK | SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_ND_RX_ERR - Wait for packet to be received and no receive timeout errors 65 | * and no reception errors. 66 | * These flags are useful when polling for STS Mode 4 (no data) 67 | * packets. 68 | * 0 - The function will not wait for any bits in the system status register (lower 32 bits). 69 | * @param hi_mask - a uint32 mask value that is used to check for certain bits to be set in the system status register (higher 32 bits). 70 | * Example values to use are as follows: 71 | * SYS_STATUS_HI_CCA_FAIL_BIT_MASK - Check for CCA fail status. 72 | * 0 - The function will not wait for any bits in the system status register (lower 32 bits). 73 | * 74 | * return None 75 | */ 76 | void waitforsysstatus( 77 | uint32_t *lo_result, 78 | uint32_t *hi_result, 79 | uint32_t lo_mask, 80 | uint32_t hi_mask 81 | ); 82 | 83 | /*************************************************************************** 84 | * Set antenna delay. 85 | * 86 | * @param rx_delay delay when recive the uwb frame 87 | * @param tx_delay delay when transmit the uwb frame 88 | * 89 | * @return None 90 | * 91 | *****************************************************************************/ 92 | void set_antenna_delay( 93 | uint16_t rx_delay, 94 | uint16_t tx_delay 95 | ); 96 | 97 | /*************************************************************************** 98 | * Get tx antenna delay. 99 | * 100 | * @return uint16_t tx antenna delay 101 | * 102 | *****************************************************************************/ 103 | uint16_t get_tx_ant_dly(); 104 | 105 | /*************************************************************************** 106 | * Get rx antenna delay. 107 | * 108 | * @return uint16_t tx antenna delay 109 | * 110 | *****************************************************************************/ 111 | uint16_t get_rx_ant_dly(); 112 | 113 | /******************************************************************************** 114 | * @brief Init the Device ID 115 | * 116 | * This Function saves the Device ID in a char array for further usage 117 | * 118 | * @param none 119 | * 120 | * @return none 121 | */ 122 | void init_device_id(void); 123 | 124 | /******************************************************************************** 125 | * @brief Get Device ID for usage 126 | * 127 | * This Function stores the device id in a char array 128 | * which comes as pointer as parameter 129 | * 130 | * @param deviceID -> Pointer to a char array with the size of minimal 17 131 | * @param deviceIDSize -> size of the pointer 132 | * 133 | * @return none 134 | */ 135 | void get_device_id(char **deviceID); 136 | -------------------------------------------------------------------------------- /include/sit/sit_config.h: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_config.h 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Defniton config options for SIT system. 25 | * 26 | * This header defines different configurations for the SIT system. 27 | * 28 | * 29 | * @bug No known bugs. 30 | * @todo everything 31 | */ 32 | 33 | #ifndef __SIT_CONFIG_H__ 34 | #define __SIT_CONFIG_H__ 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #include 41 | 42 | #include 43 | 44 | /** 45 | * Enum to define if a device is an initator or an responder 46 | */ 47 | typedef enum { 48 | initiator, ///< initiator of SSTWR or DSTWR 49 | responder, ///< responder of SSTWR or DSTWR 50 | dev_a, ///< Device A in Calibration Prozess 51 | dev_b, ///< Device B in Calibration Prozess 52 | dev_c, ///< Device C in Calibration Prozess 53 | none ///< init State for every Device 54 | } device_type_t; 55 | 56 | extern device_type_t device_type; 57 | 58 | 59 | /** 60 | * Enum for different mesaurements states 61 | */ 62 | typedef enum { 63 | measurement, ///< measurement state will run the distance measurement 64 | sleep ///< sleep state, wait for new informations 65 | } device_state_t; 66 | 67 | typedef enum { 68 | ss_twr, 69 | ds_3_twr, 70 | ds_4_twr, ///< not Implemented yet 71 | ds_all_twr, ///< not Implemnted yet 72 | simple_calibration, 73 | extended_calibration, 74 | two_device_calibration, 75 | } measurement_type_t; 76 | 77 | typedef struct { 78 | uint8_t deviceID; 79 | uint8_t devices; 80 | uint8_t initiator; 81 | uint8_t responder; 82 | uint16_t tx_ant_dly; 83 | uint16_t rx_ant_dly; 84 | device_type_t device_type; 85 | device_state_t state; 86 | measurement_type_t measurement_type; 87 | bool diagnostic; 88 | uint32_t min_measurement; 89 | uint32_t max_measurement; 90 | } device_settings_t; 91 | 92 | extern device_settings_t device_settings; 93 | 94 | typedef enum { 95 | twr_1_poll, 96 | ss_twr_2_resp, 97 | ds_twr_2_resp, 98 | ds_twr_3_final, 99 | simple_poll, 100 | simple_resp, 101 | simple_final, 102 | extended_poll, 103 | sensing_1, 104 | sensing_2, 105 | sensing_3, 106 | sensing_resp, 107 | } msg_id_t; 108 | 109 | typedef struct { 110 | msg_id_t id; 111 | uint8_t sequence; 112 | uint8_t source; 113 | uint8_t dest; 114 | } header_t; 115 | 116 | typedef struct { 117 | header_t header; 118 | uint16_t crc; 119 | } msg_simple_t; 120 | 121 | typedef struct { 122 | uint8_t nlos; // NLOS percentage 123 | float rssi; // Recived Signal Strangth Index (Recived Path Index) 124 | float fpi; // First Path Index 125 | } diagnostic_info; 126 | 127 | typedef struct { 128 | header_t header; 129 | uint32_t poll_rx_ts; 130 | uint32_t resp_tx_ts; 131 | uint16_t crc; 132 | } msg_ss_twr_final_t; 133 | 134 | typedef struct { 135 | header_t header; 136 | uint32_t poll_tx_ts; 137 | uint32_t resp_rx_ts; 138 | uint32_t final_tx_ts; 139 | uint16_t crc; 140 | } msg_ds_twr_final_t; 141 | 142 | typedef struct { 143 | header_t header; 144 | uint32_t sensing_1_tx; 145 | uint32_t sensing_2_rx; 146 | uint32_t sensing_3_tx; 147 | uint16_t crc; 148 | } msg_sensing_3_t; 149 | 150 | typedef struct { 151 | header_t header; 152 | uint32_t sensing_1_rx; 153 | uint32_t sensing_2_tx; 154 | uint32_t sensing_3_rx; 155 | uint16_t crc; 156 | } msg_sensing_info_t; 157 | 158 | typedef struct { 159 | char type[15]; 160 | char state[15]; 161 | uint8_t responder; 162 | uint32_t sequence; 163 | uint32_t measurements; 164 | } json_header_t; 165 | 166 | typedef struct { 167 | float distance; 168 | float time_round_1; 169 | float time_round_2; 170 | float time_reply_1; 171 | float time_reply_2; 172 | } json_data_t; 173 | 174 | typedef struct { 175 | float rssi_index_resp; 176 | float fp_index_resp; 177 | uint8_t dummy; 178 | uint8_t nlos_percent_resp; 179 | } json_diagnostic_t; 180 | 181 | typedef struct { 182 | json_header_t header; 183 | json_data_t data; 184 | } json_distance_msg_t; 185 | 186 | typedef struct { 187 | json_header_t header; 188 | json_data_t data; 189 | json_diagnostic_t diagnostic; 190 | } json_distance_msg_all_t; 191 | 192 | typedef struct { 193 | char type[15]; 194 | uint32_t sequence; 195 | uint32_t measurements; 196 | } json_simple_header_t; 197 | 198 | typedef struct { 199 | float time_m21; 200 | float time_m31; 201 | float time_a21; 202 | float time_a31; 203 | float time_b21; 204 | float time_b31; 205 | float time_tc_i; 206 | float time_tc_ii; 207 | float time_tb_i; 208 | float time_tb_ii; 209 | float time_round_1; 210 | float time_round_2; 211 | float time_reply_1; 212 | float time_reply_2; 213 | float distance; 214 | uint8_t dummy; 215 | } json_td_data_t; 216 | 217 | typedef struct { 218 | json_simple_header_t header; 219 | json_td_data_t data; 220 | } json_simple_td_msg_t; 221 | 222 | extern dwt_config_t sit_device_config; 223 | 224 | /* Delay between frames, in UWB microseconds. */ 225 | // #define POLL_TX_TO_RESP_RX_DLY_UUS 250 // 240 * 1,026us -> 226 | #define POLL_TX_TO_RESP_RX_DLY_UUS 1000 // 240 * 1,026us -> 227 | /* Delay between frames, in UWB microseconds. */ 228 | #define POLL_RX_TO_RESP_TX_DLY_UUS 1350 // 650 * 1,026us -> 229 | #define RESP_TX_TO_FINAL_RX_DLY_UUS 500 // 650 * 1,026us -> 230 | /* Receive response timeout. */ 231 | #define RESP_RX_TIMEOUT_UUS 2000 // 400 * 1,026us -> 232 | 233 | 234 | #define CPU_PROCESSING_TIME 400 235 | #define DS_POLL_TX_TO_RESP_RX_DLY_UUS (1100 + CPU_PROCESSING_TIME) 236 | #define DS_RESP_RX_TO_FINAL_TX_DLY_UUS (1000 + CPU_PROCESSING_TIME) 237 | #define DS_RESP_RX_TIMEOUT_UUS 1200 238 | #define DS_PRE_TIMEOUT 5 239 | 240 | #define DS_POLL_RX_TO_RESP_TX_DLY_UUS 1600 241 | #define DS_RESP_TX_TO_FINAL_RX_DLY_UUS 1200 242 | #define DS_FINAL_RX_TIMEOUT 1800 243 | 244 | 245 | /** 246 | * UWB microsecond (uus) to device time unit (dtu, around 15.65 ps) conversion factor. 247 | * 1 uus = 512 / 499.2 µs and 1 µs = 499.2 * 128 dtu. 248 | **/ 249 | #define UUS_TO_DWT_TIME 63898 250 | 251 | void set_device_state(char *comand); 252 | void set_device_id(uint8_t device_id); 253 | void set_device_type(char *type); 254 | void set_responder(uint8_t responder); 255 | void set_min_measurement(uint32_t measurement); 256 | void set_max_measurement(uint32_t measurement); 257 | void set_measurement_type(char *measurement_type); 258 | void set_rx_ant_dly(uint16_t dly); 259 | void set_tx_ant_dly(uint16_t dly); 260 | 261 | #endif // __SIT_CONFIG_H__ 262 | -------------------------------------------------------------------------------- /drivers/platform/config_options.h: -------------------------------------------------------------------------------- 1 | /*! ---------------------------------------------------------------------------- 2 | * @file config_options.h 3 | * @brief Configuration options are selected here. 4 | * 5 | * @attention 6 | * 7 | * Copyright 2019(c) Decawave Ltd, Dublin, Ireland. 8 | * 9 | * All rights reserved. 10 | * 11 | */ 12 | 13 | #include 14 | 15 | #ifndef EXAMPLES_CONFIG_OPTIONS_H_ 16 | #define EXAMPLES_CONFIG_OPTIONS_H_ 17 | 18 | /* Index values for errors in array */ 19 | #define CRC_ERR_IDX 0 20 | #define RSE_ERR_IDX 1 21 | #define PHE_ERR_IDX 2 22 | #define SFDTO_ERR_IDX 3 23 | #define PTO_ERR_IDX 4 24 | #define RTO_ERR_IDX 5 25 | #define SPICRC_ERR_IDX 6 26 | #define TXTO_ERR_IDX 7 27 | #define ARFE_ERR_IDX 8 28 | #define TS_MISMATCH_ERR_IDX 9 29 | #define BAD_FRAME_ERR_IDX 10 30 | #define PREAMBLE_COUNT_ERR_IDX 11 31 | #define CP_QUAL_ERR_IDX 12 32 | #define STS_PREAMBLE_ERR 13 33 | #define STS_PEAK_GROWTH_RATE_ERR 14 34 | #define STS_ADC_COUNT_ERR 15 35 | #define STS_SFD_COUNT_ERR 16 36 | #define STS_LATE_FIRST_PATH_ERR 17 37 | #define STS_LATE_COARSE_EST_ERR 18 38 | #define STS_COARSE_EST_EMPTY_ERR 19 39 | #define STS_HIGH_NOISE_THREASH_ERR 20 40 | #define STS_NON_TRIANGLE_ERR 21 41 | #define STS_LOG_REG_FAILED_ERR 22 42 | 43 | /* 44 | * Number of ranges to attempt in test 45 | */ 46 | #define RANGE_COUNT 200 47 | 48 | /* Compensation value for CPU 49 | * The time taken to receive the poll frame, check for errors, 50 | * calculate length, read content, get poll timestamp, 51 | * calculate response timestamp and send delayed response with timestamp will 52 | * be different for each device. 53 | * Adjusting this value lower and lower until dwt_starttx() starts returning 54 | * DWT_ERROR status allows the user to tweak their system to calculate the 55 | * shortest turn-around time for messages. 56 | */ 57 | #define CPU_PROCESSING_TIME 400 58 | 59 | /* 60 | * SPI Rate Configuration Settings 61 | */ 62 | #define CONFIG_SPI_FAST_RATE 63 | //#define CONFIG_SPI_SLOW_RATE 64 | 65 | /* 66 | * Changing threshold to 5ns for DW3000 B0 red board devices. 67 | * ~10% of ranging attempts have a larger than usual difference between Ipatov and STS. 68 | * A larger threshold allows for better coverage with this coverage. 69 | * This should be fixed for DW3000 C0 devices. 70 | */ 71 | #define TS_MISMATCH_THRESHOLD 5 * 64 /* 64 = 1 ns --> 5 ns */ 72 | 73 | /* 74 | * Please note that a PRF of 16 MHz and a STS PRF of 64 MHz will not be supported for the DW3000. 75 | */ 76 | 77 | /* Configuration option 01. 78 | * Channel 5, PRF 64M, Preamble Length 64, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 79 | */ 80 | //#define CONFIG_OPTION_01 81 | 82 | /* Configuration option 02. 83 | * Channel 9, PRF 64M, Preamble Length 64, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 84 | */ 85 | //#define CONFIG_OPTION_02 86 | 87 | /* Configuration option 03. 88 | * Channel 5, PRF 64M, Preamble Length 128, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 89 | */ 90 | //#define CONFIG_OPTION_03 91 | 92 | /* Configuration option 04. 93 | * Channel 9, PRF 64M, Preamble Length 128, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 94 | */ 95 | //#define CONFIG_OPTION_04 96 | 97 | /* Configuration option 05. 98 | * Channel 5, PRF 64M, Preamble Length 512, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 99 | */ 100 | //#define CONFIG_OPTION_05 101 | 102 | /* Configuration option 06. 103 | * Channel 9, PRF 64M, Preamble Length 512, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 104 | */ 105 | //#define CONFIG_OPTION_06 106 | 107 | /* Configuration option 07. 108 | * Channel 5, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 109 | */ 110 | //#define CONFIG_OPTION_07 111 | 112 | /* Configuration option 08. 113 | * Channel 9, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 114 | */ 115 | //#define CONFIG_OPTION_08 116 | 117 | /* Configuration option 09. 118 | * Channel 5, PRF 64M, Preamble Length 64, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 119 | */ 120 | //#define CONFIG_OPTION_09 121 | 122 | /* Configuration option 10. 123 | * Channel 9, PRF 64M, Preamble Length 64, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 124 | */ 125 | //#define CONFIG_OPTION_10 126 | 127 | /* Configuration option 11. 128 | * Channel 5, PRF 64M, Preamble Length 128, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 129 | */ 130 | //#define CONFIG_OPTION_11 131 | 132 | /* Configuration option 12. 133 | * Channel 9, PRF 64M, Preamble Length 128, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 134 | */ 135 | //#define CONFIG_OPTION_12 136 | 137 | /* Configuration option 13. 138 | * Channel 5, PRF 64M, Preamble Length 512, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 139 | */ 140 | //#define CONFIG_OPTION_13 141 | 142 | /* Configuration option 14. 143 | * Channel 9, PRF 64M, Preamble Length 512, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 144 | */ 145 | //#define CONFIG_OPTION_14 146 | 147 | /* Configuration option 15. 148 | * Channel 5, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 149 | */ 150 | //#define CONFIG_OPTION_15 151 | 152 | /* Configuration option 16. 153 | * Channel 9, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 10, Data Rate 850k, STS Length 64 154 | */ 155 | //#define CONFIG_OPTION_16 156 | 157 | /* Configuration option 17. 158 | * Channel 5, PRF 64M, Preamble Length 64, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 64 159 | */ 160 | //#define CONFIG_OPTION_17 161 | 162 | /* Configuration option 18. 163 | * Channel 9, PRF 64M, Preamble Length 64, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 64 164 | */ 165 | //#define CONFIG_OPTION_18 166 | 167 | /* Configuration option 19. 168 | * Channel 5, PRF 64M, Preamble Length 128, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 64 169 | */ 170 | //#define CONFIG_OPTION_19 171 | 172 | /* Configuration option 20. 173 | * Channel 9, PRF 64M, Preamble Length 128, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 64 174 | */ 175 | //#define CONFIG_OPTION_20 176 | 177 | /* Configuration option 21. 178 | * Channel 5, PRF 64M, Preamble Length 512, PAC 8, Preamble code 9, Data Rate 850k, STS Length 64 179 | */ 180 | //#define CONFIG_OPTION_21 181 | 182 | /* Configuration option 22. 183 | * Channel 9, PRF 64M, Preamble Length 512, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 64 184 | */ 185 | //#define CONFIG_OPTION_22 186 | 187 | /* Configuration option 23. 188 | * Channel 5, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 64 189 | */ 190 | //#define CONFIG_OPTION_23 191 | 192 | /* Configuration option 24. 193 | * Channel 9, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 64 194 | */ 195 | //#define CONFIG_OPTION_24 196 | 197 | /* Configuration option 25. 198 | * Channel 5, PRF 64M, Preamble Length 64, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 199 | */ 200 | //#define CONFIG_OPTION_25 201 | 202 | /* Configuration option 26. 203 | * Channel 9, PRF 64M, Preamble Length 64, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 204 | */ 205 | //#define CONFIG_OPTION_26 206 | 207 | /* Configuration option 27. 208 | * Channel 5, PRF 64M, Preamble Length 128, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 209 | */ 210 | //#define CONFIG_OPTION_27 211 | 212 | /* Configuration option 28. 213 | * Channel 9, PRF 64M, Preamble Length 128, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 214 | */ 215 | //#define CONFIG_OPTION_28 216 | 217 | /* Configuration option 29. 218 | * Channel 5, PRF 64M, Preamble Length 512, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 219 | */ 220 | //#define CONFIG_OPTION_29 221 | 222 | /* Configuration option 30. 223 | * Channel 9, PRF 64M, Preamble Length 512, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 224 | */ 225 | //#define CONFIG_OPTION_30 226 | 227 | /* Configuration option 31. 228 | * Channel 5, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 229 | */ 230 | //#define CONFIG_OPTION_31 231 | 232 | /* Configuration option 32. 233 | * Channel 9, PRF 64M, Preamble Length 1024, PAC 8, Preamble code 10, Data Rate 6.8M, STS Length 64 234 | */ 235 | //#define CONFIG_OPTION_32 236 | 237 | /* Configuration option 33. 238 | * Channel 5, PRF 64M, Preamble Length 128, PAC 8, Preamble code 9, Data Rate 6.8M, STS Length 128 239 | */ 240 | #define CONFIG_OPTION_33 241 | 242 | extern char dist_str[16]; 243 | 244 | #endif /* EXAMPLES_CONFIG_OPTIONS_H_ */ 245 | -------------------------------------------------------------------------------- /lib/sit/sit_distance.c: -------------------------------------------------------------------------------- 1 | /********************************************************************************** 2 | * 3 | * Copyright (C) 2023 Sven Hoyer 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 3 of the License, or 8 | * (at your option) any later version. 9 | 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | * 18 | ***********************************************************************************/ 19 | 20 | /** 21 | * @file sit_distance.c 22 | * @author Sven Hoyer (svhoy) 23 | * @date 17.04.2023 24 | * @brief Implementation of functions for distance measurement. 25 | * 26 | * This file implement functions for distance measurement for the 27 | * DWM3001cdk in the SIT system. 28 | * 29 | * 30 | * @bug No known bugs. 31 | * @todo everything 32 | */ 33 | #include "sit/sit_distance.h" 34 | #include "sit/sit_config.h" 35 | #include "sit/sit_device.h" 36 | #ifdef CONFIG_SIT_DIAGNOSTIC 37 | #include "sit/sit_diagnostic.h" 38 | #endif 39 | 40 | 41 | #include 42 | 43 | #include 44 | LOG_MODULE_REGISTER(SIT_DISTANCE, LOG_LEVEL_INF); 45 | 46 | uint32_t status_reg; 47 | 48 | diagnostic_info diagnostic; 49 | 50 | /*************************************************************************** 51 | * Start ranging with a poll msg 52 | * 53 | * @param uint8_t* msg_data -> pointer to the data you like to send with 54 | * the poll msg 55 | * @param uint16_t msg_size -> length of the data you like to send 56 | * 57 | * @return None 58 | * 59 | ****************************************************************************/ 60 | void sit_start_poll(uint8_t* msg_data, uint16_t msg_size){ 61 | dwt_writesysstatuslo(DWT_INT_TXFRS_BIT_MASK); 62 | dwt_writetxdata(msg_size, msg_data, 0); // 0 offset 63 | dwt_writetxfctrl(msg_size, 0, 1); // frame_length, bufferOffset, ranging bit (0 no ranging, 1 ranging) 64 | dwt_starttx(DWT_START_TX_IMMEDIATE | DWT_RESPONSE_EXPECTED);//switch to rx after `setrxaftertxdelay` 65 | } 66 | 67 | bool sit_send_at(uint8_t* msg_data, uint16_t size, uint32_t tx_time){ 68 | dwt_writetxdata(size, msg_data, 0); 69 | dwt_writetxfctrl(size, 0, 1); 70 | dwt_setdelayedtrxtime(tx_time); 71 | uint8_t ret = dwt_starttx(DWT_START_TX_DELAYED); 72 | if(ret == DWT_SUCCESS) { 73 | waitforsysstatus(&status_reg, NULL, DWT_INT_TXFRS_BIT_MASK, 0); 74 | dwt_writesysstatuslo(DWT_INT_RXFCG_BIT_MASK); // write to clear send status bit 75 | LOG_INF("Send Success"); 76 | return true; 77 | } else { 78 | recover_tx_errors(); 79 | status_reg = dwt_readsysstatuslo(); 80 | LOG_WRN("sit_sendAt() - dwt_starttx() late"); 81 | return false; 82 | } 83 | } 84 | 85 | bool sit_send_at_with_response(uint8_t* msg_data, uint16_t size, uint32_t tx_time){ 86 | dwt_setdelayedtrxtime(tx_time); 87 | dwt_writetxdata(size, msg_data, 0); 88 | dwt_writetxfctrl(size, 0, 1); 89 | uint8_t ret = dwt_starttx(DWT_START_TX_DELAYED | DWT_RESPONSE_EXPECTED); 90 | if(ret == DWT_SUCCESS) { 91 | waitforsysstatus(&status_reg, NULL, DWT_INT_TXFRS_BIT_MASK, 0); 92 | dwt_writesysstatuslo(DWT_INT_RXFCG_BIT_MASK); // write to clear send status bit 93 | LOG_INF("Send Success"); 94 | return true; 95 | } else { 96 | recover_tx_errors(); 97 | status_reg = dwt_readsysstatuslo(); 98 | LOG_WRN("sit_sendAt() - dwt_starttx() late"); 99 | return false; 100 | } 101 | } 102 | 103 | void sit_receive_now(uint16_t preamble_detction_timeout, uint32_t rx_timeout) { 104 | dwt_setpreambledetecttimeout(preamble_detction_timeout); 105 | dwt_setrxtimeout(rx_timeout); 106 | uint8_t ret = dwt_rxenable(DWT_START_RX_IMMEDIATE); 107 | if (ret == DWT_SUCCESS) { 108 | LOG_INF("RX enabled"); 109 | } else { 110 | LOG_ERR("RX enable failed"); 111 | } 112 | } 113 | 114 | void sit_receive_at(uint32_t timeout) { 115 | dwt_setpreambledetecttimeout(0); 116 | dwt_setrxtimeout(timeout); // 0 : disable timeout 117 | dwt_rxenable(DWT_START_RX_DELAYED | DWT_IDLE_ON_DLY_ERR); //DWT_START_RX_DELAYED only used with dwt_setdelayedtrxtime() before 118 | } 119 | 120 | uint32_t sit_msg_receive() { 121 | uint32_t l_status_reg; 122 | waitforsysstatus(&l_status_reg, NULL, (DWT_INT_RXFCG_BIT_MASK | SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR), 0); 123 | return l_status_reg; 124 | } 125 | 126 | bool sit_check_msg(uint8_t* data, uint16_t expected_frame_length) { 127 | bool result = false; 128 | status_reg = sit_msg_receive(); 129 | LOG_INF("Test: %08x & %08x", status_reg, DWT_INT_RXFCG_BIT_MASK); 130 | if(status_reg & DWT_INT_RXFCG_BIT_MASK) { 131 | /* Clear good RX frame event in the DW IC status register. */ 132 | dwt_writesysstatuslo(DWT_INT_RXFCG_BIT_MASK); 133 | uint16_t frame_length = dwt_getframelength(); 134 | if (frame_length == expected_frame_length) { 135 | dwt_readrxdata(data, frame_length, 0); 136 | #ifdef CONFIG_SIT_DIAGNOSTIC 137 | get_diagnostic(&diagnostic); 138 | #endif 139 | result = true; 140 | } else { 141 | LOG_ERR("RX Frame Length: %u != Expected Frame Length: %u",frame_length, expected_frame_length); 142 | } 143 | } else { 144 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 145 | LOG_WRN("sit_checkReceivedMessage() no 'RX Frame Checksum Good'"); 146 | uint32_t reg2 = dwt_readsysstatuslo(); 147 | uint32_t reg_removed = (status_reg ^ reg2); 148 | LOG_WRN("sit_checkReceivedMessage() reg1 = 0x%08x ; reg2 = 0x%08x ; removed = 0x%08x",status_reg,reg2,reg_removed); 149 | status_reg = reg2; 150 | dwt_forcetrxoff(); // set Transceiver to idle if error occurs 151 | } 152 | 153 | return result; 154 | } 155 | 156 | bool sit_check_msg_id(msg_id_t id, msg_simple_t* message) { 157 | bool result = false; 158 | if(sit_check_msg((uint8_t*)message, sizeof(msg_simple_t))){ 159 | if(message->header.id == id) { 160 | result = true; 161 | } else { 162 | LOG_ERR("Simple MSG mismatch expect id / header id (%u/%u)",(uint8_t)id,(uint8_t)message->header.id); 163 | } 164 | } else { 165 | LOG_ERR("SIT Failed Receive Simple MSG (%u, header) fail",(uint8_t)id); 166 | } 167 | return result; 168 | } 169 | 170 | bool sit_check_final_msg_id(msg_id_t id, msg_ss_twr_final_t* message) { 171 | bool result = false; 172 | if(sit_check_msg((uint8_t*)message, sizeof(msg_ss_twr_final_t))){ 173 | LOG_INF("sit_checkReceivedIdFinalMsg() id: %u & %u", (uint8_t)id, (uint8_t)message->header.id); 174 | if(message->header.id == id) { 175 | result = true; 176 | } else { 177 | LOG_ERR("sit_checkReceivedIdFinalMsg() mismatch id(%u/%u)",(uint8_t)id,(uint8_t)message->header.id); 178 | } 179 | } else { 180 | LOG_ERR("sit_checkReceivedIdFinalMsg(%u,header) fail",(uint8_t)id); 181 | } 182 | return result; 183 | } 184 | 185 | bool sit_check_ds_final_msg_id(msg_id_t id, msg_ds_twr_final_t* message) { 186 | bool result = false; 187 | if(sit_check_msg((uint8_t*)message, sizeof(msg_ds_twr_final_t))){ 188 | if(message->header.id == id) { 189 | result = true; 190 | } else { 191 | LOG_ERR("sit_checkReceivedIdFinalMsg() mismatch id(%u/%u)",(uint8_t)id,(uint8_t)message->header.id); 192 | } 193 | } else { 194 | LOG_ERR("sit_checkReceivedIdFinalMsg(%u,header) fail",(uint8_t)id); 195 | } 196 | return result; 197 | } 198 | 199 | bool sit_check_sensing_3_msg_id(msg_id_t id, msg_sensing_3_t * message){ 200 | bool result = false; 201 | if(sit_check_msg((uint8_t*)message, sizeof(msg_sensing_3_t))){ 202 | if(message->header.id == id) { 203 | result = true; 204 | } else { 205 | LOG_ERR("sit_check_sensing_3_msg_id() mismatch id(%u/%u)",(uint8_t)id,(uint8_t)message->header.id); 206 | } 207 | } else { 208 | LOG_ERR("sit_check_sensing_3_final_msg_id(%u,header) fail",(uint8_t)id); 209 | } 210 | return result; 211 | } 212 | 213 | bool sit_check_sensing_info_msg_id(msg_id_t id, msg_sensing_info_t * message){ 214 | bool result = false; 215 | if(sit_check_msg((uint8_t*)message, sizeof(msg_sensing_info_t))){ 216 | if(message->header.id == id) { 217 | result = true; 218 | } else { 219 | LOG_ERR("sit_check_sensing_info_final_msg_id() mismatch id(%u/%u)",(uint8_t)id,(uint8_t)message->header.id); 220 | } 221 | } else { 222 | LOG_ERR("sit_check_sensig_info_msg_id(%u,header) fail",(uint8_t)id); 223 | } 224 | return result; 225 | } 226 | 227 | void sit_set_rx_tx_delay_and_rx_timeout(uint32_t delay_us, uint16_t timeout) { 228 | dwt_setrxaftertxdelay(delay_us); 229 | dwt_setrxtimeout(timeout); 230 | } 231 | 232 | void sit_set_rx_after_tx_delay(uint32_t delay_us) { 233 | dwt_setrxaftertxdelay(delay_us); 234 | } 235 | 236 | void sit_set_rx_timeout(uint16_t timeout) { 237 | dwt_setrxtimeout(timeout); 238 | } 239 | 240 | void sit_set_preamble_detection_timeout(uint16_t timeout) { 241 | dwt_setpreambledetecttimeout(timeout); 242 | } 243 | 244 | void recover_tx_errors() { 245 | uint32_t status = dwt_readsysstatuslo(); 246 | if(status & DWT_INT_RXFCE_BIT_MASK) { 247 | LOG_INF("recovering TX errors 0x%08x", (status & DWT_INT_RXFCE_BIT_MASK)); 248 | dwt_writesysstatuslo(SYS_STATUS_ALL_RX_TO | SYS_STATUS_ALL_RX_ERR); 249 | } 250 | } --------------------------------------------------------------------------------