├── lib ├── rtdoa_backhaul │ ├── README.md │ ├── syscfg.yml │ ├── .gitignore │ ├── pkg.yml │ └── include │ │ └── rtdoa_backhaul │ │ └── rtdoa_backhaul.h └── bleprph │ ├── syscfg.yml │ ├── include │ └── bleprph │ │ └── bleprph.h │ ├── pkg.yml │ └── src │ ├── gatt_svr.c │ ├── ble_priv.h │ └── bleprph.c ├── .rat-excludes ├── toolchain ├── cortex-m0.cmake ├── cortex-m4.cmake ├── cortex-m0+.cmake ├── xtensa-lx106.cmake ├── cortex-m3.cmake ├── cortex-m7.cmake ├── cortex-m4f.cmake ├── common │ ├── avr-gcc.cmake │ ├── msp430-gcc.cmake │ ├── bfin-elf.cmake │ ├── arm-none-eabi.cmake │ └── xtensa-lx106-gcc.cmake └── generic.cmake ├── apps ├── rtdoa_tag │ ├── node-red │ │ └── flows.json │ ├── syscfg.yml │ ├── pkg.yml │ └── README.md ├── twr_node_tdma │ ├── node-red │ │ ├── pdoa_viewer.json │ │ └── pdoa_viewer_serial.json │ ├── syscfg.yml │ └── pkg.yml ├── twr_aloha │ ├── syscfg.yml │ ├── pkg.yml │ ├── README.md │ └── src │ │ └── main.c ├── ota_uwb_slave │ ├── syscfg.yml │ ├── pkg.yml │ ├── src │ │ └── main.c │ └── README.md ├── twr_tag_tdma │ ├── README.md │ ├── syscfg.yml │ ├── pkg.yml │ └── src │ │ └── main.c ├── ota_uwb_master │ ├── syscfg.yml │ ├── pkg.yml │ ├── src │ │ └── main.c │ └── README.md ├── rtdoa_node │ ├── README.md │ ├── pkg.yml │ ├── syscfg.yml │ └── src │ │ └── main.c ├── tdoa_tag │ ├── syscfg.yml │ ├── README.md │ ├── pkg.yml │ └── src │ │ └── main.c ├── streaming │ ├── syscfg.yml │ ├── pkg.yml │ └── README.md ├── listener │ ├── pkg.yml │ ├── syscfg.yml │ └── README.md ├── twr_nranges_tdma │ ├── CMakeLists.txt │ ├── pkg.yml │ └── syscfg.yml └── README.md ├── NOTICE ├── .gitignore ├── config.h.in ├── project.yml ├── repository.yml ├── CMakeLists.txt ├── Jenkinsfile ├── .travis.yml ├── Makefile ├── README.md ├── CODING_STANDARDS.md └── LICENSE /lib/rtdoa_backhaul/README.md: -------------------------------------------------------------------------------- 1 | # RTDoA Backhaul 2 | 3 | This package outputs rtdoa and sensor data as json to uart. -------------------------------------------------------------------------------- /.rat-excludes: -------------------------------------------------------------------------------- 1 | # Can't easily add license to rat-excludes file. 2 | .rat-excludes 3 | 4 | # Temporary user files. 5 | .gdb_history 6 | .gdb_out 7 | tags 8 | -------------------------------------------------------------------------------- /toolchain/cortex-m0.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m0) 4 | 5 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m0") 6 | set(VFP_FLAGS "") 7 | set(LD_FLAGS "-nostartfiles") 8 | 9 | include(${CMAKE_CURRENT_LIST_DIR}/common/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /toolchain/cortex-m4.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m4) 4 | 5 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m4") 6 | set(VFP_FLAGS "") 7 | set(LD_FLAGS "-nostartfiles") 8 | 9 | include(${CMAKE_CURRENT_LIST_DIR}/common/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /toolchain/cortex-m0+.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m0) 4 | 5 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m0plus") 6 | set(VFP_FLAGS "") 7 | set(LD_FLAGS "-nostartfiles") 8 | 9 | include(${CMAKE_CURRENT_LIST_DIR}/common/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /toolchain/xtensa-lx106.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR xtensa) 4 | 5 | set(LD_FLAGS "-nostartfiles -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static") 6 | 7 | include(${CMAKE_CURRENT_LIST_DIR}/common/xtensa-lx106-gcc.cmake) 8 | -------------------------------------------------------------------------------- /toolchain/cortex-m3.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m3) 4 | 5 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m3") 6 | set(VFP_FLAGS "") 7 | set(LD_FLAGS "-nostartfiles") 8 | 9 | include(${CMAKE_CURRENT_LIST_DIR}/common/arm-none-eabi.cmake) 10 | -------------------------------------------------------------------------------- /toolchain/cortex-m7.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m4) 4 | 5 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m7") 6 | set(VFP_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16") 7 | set(LD_FLAGS "-nostartfiles") 8 | 9 | include(${CMAKE_CURRENT_LIST_DIR}/common/arm-none-eabi.cmake) -------------------------------------------------------------------------------- /apps/rtdoa_tag/node-red/flows.json: -------------------------------------------------------------------------------- 1 | [{"id":"4fdde091.f7f34","type":"delay","z":"4eb9e89c.bbff58","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"5","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":200.5,"y":311,"wires":[["a3638597.630c98","1ec4813e.5a851f"]]}] -------------------------------------------------------------------------------- /toolchain/cortex-m4f.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_NAME Generic) 3 | set(CMAKE_SYSTEM_PROCESSOR cortex-m4) 4 | 5 | set(MCPU_FLAGS "-mthumb -mcpu=cortex-m4") 6 | set(VFP_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16") 7 | set(LD_FLAGS "-nostartfiles") 8 | 9 | include(${CMAKE_CURRENT_LIST_DIR}/common/arm-none-eabi.cmake) 10 | -------------------------------------------------------------------------------- /lib/rtdoa_backhaul/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.defs: 2 | RTDOABH_NUM_MBUFS: 3 | description: 'Number of message buffers' 4 | value: 64 5 | RTDOABH_MBUF_SIZE: 6 | description: 'Size of each message buffer' 7 | value: 136 8 | RTDOABH_STATS: 9 | description: 'Collect statistics' 10 | value: 1 11 | RTDOABH_MAXNUM_RANGES: 12 | value: 16 13 | RTDOABH_COMPACT_MEAS: 14 | value: 1 15 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache Mynewt 2 | Copyright 2015-2017 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | 7 | Portions of this software were developed at 8 | Runtime Inc, copyright 2015. 9 | 10 | Portions of this software were developed at 11 | Decawave Ltd, copyright 2017-2020. 12 | 13 | Portions of this software were developed at 14 | Lohmega, copyright 2018-2020. 15 | 16 | 17 | -------------------------------------------------------------------------------- /lib/bleprph/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.defs: 2 | BLEPRPH_ENABLED: 3 | description: 'Have BLEPRPH' 4 | value: 1 5 | restrictions: 6 | - BLE_ROLE_BROADCASTER 7 | # - !BLE_ROLE_CENTRAL 8 | # - !BLE_ROLE_OBSERVER 9 | - BLE_ROLE_PERIPHERAL 10 | - MSYS_1_BLOCK_SIZE > 127 11 | BLE_PREFIX: 12 | description: 'Bluetooth name prefix' 13 | value: '"bleprph"' 14 | 15 | #syscfg.vals: 16 | # BLE_ROLE_BROADCASTER: 1 17 | # BLE_ROLE_CENTRAL: 0 18 | # BLE_ROLE_OBSERVER: 0 19 | # BLE_ROLE_PERIPHERAL: 1 20 | -------------------------------------------------------------------------------- /apps/twr_node_tdma/node-red/pdoa_viewer.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "13e33316.35536d", 4 | "type": "delay", 5 | "z": "699d61f9.f62f5", 6 | "name": "", 7 | "pauseType": "rate", 8 | "timeout": "5", 9 | "timeoutUnits": "seconds", 10 | "rate": "10", 11 | "nbRateUnits": "1", 12 | "rateUnits": "second", 13 | "randomFirst": "1", 14 | "randomLast": "5", 15 | "randomUnits": "seconds", 16 | "drop": true, 17 | "x": 401, 18 | "y": 385, 19 | "wires": [ 20 | [ 21 | "e66d7bd2.e2ab48" 22 | ] 23 | ] 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /apps/twr_aloha/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | # Route console to RTT 3 | CONSOLE_UART: 1 4 | CONSOLE_UART_BAUD: '115200' 5 | CONSOLE_UART_TX_BUF_SIZE: '1024' 6 | CONSOLE_RTT: 0 7 | CONSOLE_HISTORY_SIZE: 8 8 | 9 | CONFIG_FCB: 1 10 | 11 | UWB_DEVICE_0: 1 12 | FS_XTALT_AUTOTUNE_ENABLED: 0 13 | HARDFLOAT: 1 14 | FLOAT_USER: 1 15 | RNG_VERBOSE: 2 16 | UWB_CCP_VERBOSE: 0 17 | STATS_NAMES: 1 18 | STATS_CLI: 1 19 | CONFIG_CLI: 1 20 | UWB_CLI: 1 21 | UWB_CLI_BACKTRACE: 1 22 | SHELL_TASK: 1 23 | 24 | # Enable newtmgr commands. 25 | STATS_NEWTMGR: 1 26 | LOG_NEWTMGR: 1 27 | CONFIG_NEWTMGR: 1 28 | 29 | syscfg.defs: 30 | ANCHOR_ADDRESS: 31 | description: 'Address of anchor' 32 | value: 0x1234 33 | -------------------------------------------------------------------------------- /apps/ota_uwb_slave/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | # Route console to RTT 3 | CONSOLE_UART: 1 4 | CONSOLE_UART_BAUD: '115200' 5 | CONSOLE_UART_TX_BUF_SIZE: '1024' 6 | CONSOLE_RTT: 0 7 | CONSOLE_HISTORY_SIZE: 8 8 | 9 | UWB_DEVICE_0: 1 10 | FS_XTALT_AUTOTUNE_ENABLED: 0 11 | DW1000_BIAS_CORRECTION_ENABLED: 0 12 | HARDFLOAT: 1 13 | TDMA_NSLOTS: 128 14 | WCS_VERBOSE: 1 15 | RNG_VERBOSE: 0 16 | STATS_NAMES: 1 17 | STATS_CLI: 1 18 | CONFIG_CLI: 1 19 | IMGMGR_CLI: 1 20 | DW1000_CLI: 1 21 | DW3000_CLI: 1 22 | 23 | # Log reboot messages to a flash circular buffer. 24 | REBOOT_LOG_FCB: 1 25 | LOG_FCB: 1 26 | CONFIG_FCB: 1 27 | 28 | # Enable newtmgr commands. 29 | STATS_NEWTMGR: 1 30 | LOG_NEWTMGR: 1 31 | CONFIG_NEWTMGR: 1 32 | 33 | DW_DEVICE_ID_0: 0x1234 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | .app.db 21 | .app 22 | bin 23 | obj 24 | tags 25 | .gdb_history 26 | .gdb_out 27 | .gdb_cmds 28 | *~ 29 | .DS_Store 30 | *.swp 31 | *.swo 32 | -------------------------------------------------------------------------------- /apps/twr_tag_tdma/README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # Decawave TDMA Example 23 | 24 | ## Overview 25 | 26 | See companion example twr_node_tdma 27 | 28 | -------------------------------------------------------------------------------- /lib/rtdoa_backhaul/.gitignore: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | .app.db 21 | .app 22 | bin 23 | obj 24 | tags 25 | .gdb_history 26 | .gdb_out 27 | .gdb_cmds 28 | .gdbinit 29 | *~ 30 | .DS_Store 31 | *.swp 32 | *.swo 33 | 34 | -------------------------------------------------------------------------------- /apps/ota_uwb_master/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | # Route console to RTT 3 | CONSOLE_UART: 1 4 | CONSOLE_UART_BAUD: '115200' 5 | CONSOLE_UART_TX_BUF_SIZE: '1024' 6 | CONSOLE_RTT: 0 7 | CONSOLE_HISTORY_SIZE: 8 8 | 9 | UWB_DEVICE_0: 1 10 | FS_XTALT_AUTOTUNE_ENABLED: 0 11 | TDMA_NSLOTS: 128 12 | DW_DEVICE_ID_0: 0x4321 13 | UWB_CCP_VERBOSE: 0 14 | STATS_NAMES: 1 15 | STATS_CLI: 1 16 | CONFIG_CLI: 1 17 | DW1000_CLI: 1 18 | DW3000_CLI: 1 19 | SHELL_TASK: 1 20 | IMGMGR_CLI: 1 21 | 22 | # Enable newtmgr commands. 23 | STATS_NEWTMGR: 1 24 | LOG_NEWTMGR: 1 25 | CONFIG_NEWTMGR: 1 26 | 27 | REBOOT_LOG_FCB: 1 28 | LOG_FCB: 1 29 | CONFIG_FCB: 1 30 | LOG_LEVEL: 2 31 | # Disable central and observer roles. 32 | BLE_ROLE_BROADCASTER: 1 33 | BLE_ROLE_CENTRAL: 0 34 | BLE_ROLE_OBSERVER: 0 35 | BLE_ROLE_PERIPHERAL: 1 36 | # OS main/default task 37 | OS_MAIN_STACK_SIZE: 640 38 | SHELL_NEWTMGR: 1 39 | 40 | syscfg.defs: 41 | BLE_ENABLED: 42 | description: 'Activate BLE' 43 | value: 1 44 | -------------------------------------------------------------------------------- /apps/rtdoa_node/README.md: -------------------------------------------------------------------------------- 1 | # Ranging with n nodes using 2n+2 messages along with TDMA slotting. 2 | 3 | ## Overview 4 | 5 | 6 | 7 | ### Building targets 8 | 9 | Master node (only one allowed per network): 10 | 11 | ```no-highlight 12 | newt target create rtdoa_master 13 | newt target set rtdoa_master app=apps/rtdoa_node 14 | newt target set rtdoa_master bsp=@decawave-uwb-core/hw/bsp/dwm1001 15 | newt target amend rtdoa_master syscfg="MASTER_NODE=1" 16 | newt run rtdoa_master 0.1.0 17 | ``` 18 | 19 | Slave node, up to 16 per network (for now): 20 | 21 | ```no-highlight 22 | newt target create rtdoa_slave 23 | newt target set rtdoa_slave app=apps/rtdoa_node 24 | newt target set rtdoa_slave bsp=@decawave-uwb-core/hw/bsp/dwm1001 25 | newt target amend rtdoa_slave syscfg="MASTER_NODE=0" 26 | newt run rtdoa_slave 0.1.0 27 | ``` 28 | 29 | Tags: 30 | 31 | ```no-highlight 32 | newt target create rtdoa_tag 33 | newt target set rtdoa_tag app=apps/rtdoa_tag 34 | #newt target set rtdoa_tag bsp=@decawave-uwb-core/hw/bsp/dwm1001 35 | newt target set rtdoa_tag bsp=@decawave-uwb-core/hw/bsp/dwm1003 36 | #newt target amend rtdoa_tag syscfg="MASTER_NODE=0" 37 | newt run rtdoa_tag 0.1.0 38 | ``` 39 | 40 | 41 | -------------------------------------------------------------------------------- /lib/bleprph/include/bleprph/bleprph.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLEPRPH_ 21 | #define H_BLEPRPH_ 22 | 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | int ble_init(uint64_t ble_id); 32 | int ble_stop(); 33 | int ble_is_connected(); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /config.h.in: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019, Decawave Limited, All Rights Reserved 3 | * 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, 15 | * software distributed under the License is distributed on an 16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 | * KIND, either express or implied. See the License for the 18 | * specific language governing permissions and limitations 19 | * under the License. 20 | */ 21 | 22 | #ifndef CONFIG_INCLUDE 23 | #define CONFIG_INCLUDE 24 | // the configured options 25 | #define VERSION_MAJOR ${${PROJECT_NAME}_VERSION_MAJOR} 26 | #define VERSION_MINOR ${${PROJECT_NAME}_VERSION_MINOR} 27 | #define VERSION_PATCH ${${PROJECT_NAME}_VERSION_PATCH} 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /lib/rtdoa_backhaul/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: "lib/rtdoa_backhaul" 21 | pkg.description: "Backhaul for rtdoa" 22 | pkg.author: "UWB Core " 23 | pkg.homepage: "http://decawave.com/" 24 | pkg.keywords: 25 | 26 | pkg.deps: 27 | - "@decawave-uwb-core/lib/rtdoa" 28 | - "@decawave-uwb-core/lib/rtdoa_tag" 29 | - "@apache-mynewt-core/hw/sensor" 30 | 31 | pkg.init: 32 | rtdoa_backhaul_pkg_init: 600 33 | -------------------------------------------------------------------------------- /apps/twr_tag_tdma/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | # Route console to RTT 3 | CONSOLE_UART: 0 4 | CONSOLE_UART_BAUD: '460800' 5 | CONSOLE_UART_TX_BUF_SIZE: '1024' 6 | CONSOLE_RTT: 1 7 | CONSOLE_HISTORY_SIZE: 8 8 | 9 | UWB_DEVICE_0: 1 10 | FS_XTALT_AUTOTUNE_ENABLED: 0 11 | HARDFLOAT: 1 12 | FLOAT_USER: 1 13 | TDMA_NSLOTS: 160 14 | RNG_VERBOSE: 2 15 | WCS_VERBOSE: 1 16 | UWB_CCP_VERBOSE: 0 17 | 18 | STATS_NAMES: 1 19 | STATS_CLI: 1 20 | CONFIG_CLI: 1 21 | DW1000_CLI: 1 22 | DW3000_CLI: 1 23 | SHELL_TASK: 1 24 | 25 | # Enable newtmgr commands. 26 | STATS_NEWTMGR: 1 27 | LOG_NEWTMGR: 1 28 | CONFIG_NEWTMGR: 1 29 | CONFIG_FCB: 1 30 | 31 | # By default we're a tag 32 | UWBCFG_DEF_ROLE: '"0x0"' 33 | 34 | syscfg.vals.BLE_ENABLED: 35 | BLE_PREFIX: '"twr-tag"' 36 | # BLE Disable central and observer roles. 37 | BLE_ROLE_BROADCASTER: 1 38 | BLE_ROLE_CENTRAL: 0 39 | BLE_ROLE_OBSERVER: 0 40 | BLE_ROLE_PERIPHERAL: 1 41 | 42 | # No point in having the CIR enabled unless we can use it for pdoa 43 | syscfg.vals.'!UWB_DEVICE_1 && !DW3000_DEVICE_0': 44 | CIR_ENABLED: 0 45 | 46 | syscfg.defs: 47 | BLE_ENABLED: 48 | description: 'Activate BLE' 49 | value: 0 50 | -------------------------------------------------------------------------------- /apps/tdoa_tag/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.defs: 2 | TDOA_TAG_BLINK_RATE: 3 | description: 'blinks per second' 4 | value: '"1"' 5 | BLE_ENABLED: 6 | description: 'Activate BLE' 7 | value: 1 8 | 9 | syscfg.vals: 10 | # console 11 | UART_0: 0 12 | CONSOLE_UART: 0 13 | CONSOLE_RTT: 1 14 | CONSOLE_UART_BAUD: 115200 15 | CONSOLE_UART_TX_BUF_SIZE: 1024 16 | CONSOLE_UART_RX_BUF_SIZE: 256 17 | CONSOLE_HISTORY_SIZE: 8 18 | LOG_LEVEL: 2 19 | 20 | # Shell 21 | SHELL_TASK: 1 22 | SHELL_PROMPT_MODULE: 1 23 | CONFIG_CLI: 1 24 | STATS_CLI: 1 25 | STATS_NAMES: 1 26 | STATS_NEWTMGR: 1 27 | UWB_CLI: 1 28 | UWB_CLI_BACKTRACE: 0 29 | 30 | # Enable DWx000 31 | UWB_DEVICE_0: 1 32 | UWBCFG_APPLY_AT_INIT: 1 33 | 34 | # ST Mems 35 | I2C_1: 0 36 | LSM6DSL_ONB: 0 37 | LIS2MDL_ONB: 0 38 | LPS22HB_ONB: 0 39 | SENSOR_OIC: 0 40 | 41 | ## Where to store config 42 | CONFIG_FCB: 1 43 | CONFIG_NEWTMGR: 1 44 | CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS 45 | 46 | # BLE Disable central and observer roles. 47 | BLE_ROLE_BROADCASTER: 1 48 | BLE_ROLE_CENTRAL: 0 49 | BLE_ROLE_OBSERVER: 0 50 | BLE_ROLE_PERIPHERAL: 1 51 | 52 | syscfg.vals.CONSOLE_UART: 53 | UART_0: 1 54 | -------------------------------------------------------------------------------- /toolchain/common/avr-gcc.cmake: -------------------------------------------------------------------------------- 1 | # Toolchain settings 2 | set(CMAKE_C_COMPILER avr-gcc) 3 | set(CMAKE_CXX_COMPILER avr-g++) 4 | set(AS avr--gcc) 5 | set(AR avr-ar) 6 | set(OBJCOPY avr-objcopy) 7 | set(OBJDUMP avr-objdump) 8 | set(SIZE avr-size) 9 | 10 | set(CMAKE_C_FLAGS "${MCPU_FLAGS} -Wall -std=gnu11 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags") 11 | set(CMAKE_CXX_FLAGS "${MCPU_FLAGS} -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags") 12 | set(CMAKE_ASM_FLAGS "${MCPU_FLAGS} -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") 13 | set(CMAKE_EXE_LINKER_FLAGS "${MCPU_FLAGS} -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 14 | 15 | 16 | SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags") 17 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags") 18 | SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags") 19 | 20 | SET(CMAKE_C_FLAGS_RELEASE "-Os -g -ggdb3" CACHE INTERNAL "c release compiler flags") 21 | SET(CMAKE_CXX_FLAGS_RELEASE "-Os -g -ggdb3" CACHE INTERNAL "cxx release compiler flags") 22 | SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") -------------------------------------------------------------------------------- /toolchain/common/msp430-gcc.cmake: -------------------------------------------------------------------------------- 1 | # Toolchain settings 2 | set(CMAKE_C_COMPILER msp430-gcc) 3 | set(CMAKE_CXX_COMPILER msp430-g++) 4 | set(AS msp430--gcc) 5 | set(AR msp430-ar) 6 | set(OBJCOPY msp430-objcopy) 7 | set(OBJDUMP msp430-objdump) 8 | set(SIZE msp430-size) 9 | 10 | set(CMAKE_C_FLAGS "${MCPU_FLAGS} -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags") 11 | set(CMAKE_CXX_FLAGS "${MCPU_FLAGS} -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags") 12 | set(CMAKE_ASM_FLAGS "${MCPU_FLAGS} -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") 13 | set(CMAKE_EXE_LINKER_FLAGS "${MCPU_FLAGS} -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 14 | 15 | 16 | SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags") 17 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags") 18 | SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags") 19 | 20 | SET(CMAKE_C_FLAGS_RELEASE "-Os -g -ggdb3" CACHE INTERNAL "c release compiler flags") 21 | SET(CMAKE_CXX_FLAGS_RELEASE "-Os -g -ggdb3" CACHE INTERNAL "cxx release compiler flags") 22 | SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") 23 | -------------------------------------------------------------------------------- /toolchain/common/bfin-elf.cmake: -------------------------------------------------------------------------------- 1 | # Toolchain settings 2 | set(CMAKE_C_COMPILER bfin-elf-gcc) 3 | set(CMAKE_CXX_COMPILER bfin-elf-g++) 4 | set(AS bfin-elf--gcc) 5 | set(AR bfin-elf-ar) 6 | set(OBJCOPY bfin-elf-objcopy) 7 | set(OBJDUMP bfin-elf-objdump) 8 | set(SIZE bfin-elf-size) 9 | 10 | set(CMAKE_C_FLAGS "${MCPU_FLAGS} -Wall -std=gnu99 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags") 11 | set(CMAKE_CXX_FLAGS "${MCPU_FLAGS} -Wall -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags") 12 | set(CMAKE_ASM_FLAGS "${MCPU_FLAGS} -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") 13 | set(CMAKE_EXE_LINKER_FLAGS "${MCPU_FLAGS} -nostartfiles -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 14 | 15 | 16 | SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags") 17 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags") 18 | SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags") 19 | 20 | SET(CMAKE_C_FLAGS_RELEASE "-Os -g -ggdb3" CACHE INTERNAL "c release compiler flags") 21 | SET(CMAKE_CXX_FLAGS_RELEASE "-Os -g -ggdb3" CACHE INTERNAL "cxx release compiler flags") 22 | SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") -------------------------------------------------------------------------------- /toolchain/common/arm-none-eabi.cmake: -------------------------------------------------------------------------------- 1 | # Toolchain settings 2 | set(CMAKE_C_COMPILER arm-none-eabi-gcc) 3 | set(CMAKE_CXX_COMPILER arm-none-eabi-g++) 4 | set(AS arm-none-eabi-as) 5 | set(AR arm-none-eabi-ar) 6 | set(OBJCOPY arm-none-eabi-objcopy) 7 | set(OBJDUMP arm-none-eabi-objdump) 8 | set(SIZE arm-none-eabi-size) 9 | 10 | set(CMAKE_C_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -Wall -fno-builtin -std=gnu11 -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags") 11 | set(CMAKE_CXX_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -Wall -fno-builtin -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags") 12 | set(CMAKE_ASM_FLAGS "${MCPU_FLAGS} -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") 13 | set(CMAKE_EXE_LINKER_FLAGS "${MCPU_FLAGS} ${LD_FLAGS} -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 14 | 15 | 16 | 17 | SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags") 18 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags") 19 | SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags") 20 | 21 | SET(CMAKE_C_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "c release compiler flags") 22 | SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "cxx release compiler flags") 23 | SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") -------------------------------------------------------------------------------- /project.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | project.name: "decawave-uwb-apps" 21 | 22 | project.repositories: 23 | - apache-mynewt-core 24 | - decawave-uwb-core 25 | 26 | # Use github's distribution mechanism for core ASF libraries. 27 | # This provides mirroring automatically for us. 28 | # 29 | repository.apache-mynewt-core: 30 | type: github 31 | vers: 1.7.0 32 | user: apache 33 | repo: mynewt-core 34 | 35 | repository.decawave-uwb-core: 36 | type: git 37 | vers: 0-dev 38 | user: decawave 39 | repo: uwb-core 40 | url: 'git@github.com:Decawave/uwb-core.git' 41 | 42 | -------------------------------------------------------------------------------- /toolchain/generic.cmake: -------------------------------------------------------------------------------- 1 | # Name of the target 2 | set(CMAKE_SYSTEM_PROCESSOR generic) 3 | 4 | # Toolchain settings 5 | set(CMAKE_C_COMPILER gcc) 6 | set(CMAKE_CXX_COMPILER g++) 7 | set(AS as) 8 | set(AR ar) 9 | set(OBJCOPY objcopy) 10 | set(OBJDUMP objdump) 11 | set(SIZE size) 12 | 13 | set(CMAKE_C_FLAGS "-D_GNU_SOURCE -D_POSIX_C_SOURCE=200809 -std=gnu11 -fms-extensions -fdata-sections -ffunction-sections" CACHE INTERNAL "c compiler flags") 14 | set(CMAKE_CXX_FLAGS "-D_GNU_SOURCE -D_POSIX_C_SOURCE=200809 -std=gnu++11 -fms-extensions -fdata-sections -ffunction-sections" CACHE INTERNAL "cxx compiler flags") 15 | set(CMAKE_ASM_FLAGS "" CACHE INTERNAL "asm compiler flags") 16 | if (APPLE) 17 | set(CMAKE_EXE_LINKER_FLAGS "-lrt -dead_strip" CACHE INTERNAL "exe link flags") 18 | else (APPLE) 19 | set(CMAKE_EXE_LINKER_FLAGS "-lrt -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 20 | endif (APPLE) 21 | 22 | SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags") 23 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags") 24 | SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags") 25 | 26 | SET(CMAKE_C_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "c release compiler flags") 27 | SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "cxx release compiler flags") 28 | SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") 29 | -------------------------------------------------------------------------------- /toolchain/common/xtensa-lx106-gcc.cmake: -------------------------------------------------------------------------------- 1 | # Toolchain settings 2 | set(CMAKE_C_COMPILER xtensa-lx106-elf-gcc) 3 | set(CMAKE_CXX_COMPILER xtensa-lx106-elf-g++) 4 | set(AS xtensa-lx106-elf-as) 5 | set(AR xtensa-lx106-elf-ar) 6 | set(OBJCOPY xtensa-lx106-elf-objcopy) 7 | set(OBJDUMP xtensa-lx106-elf-objdump) 8 | set(SIZE xtensa-lx106-elf-size) 9 | 10 | set(CMAKE_C_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -Wall -fno-builtin -std=gnu11 -fdata-sections -ffunction-sections -mtext-section-literals -mlongcalls" CACHE INTERNAL "c compiler flags") 11 | set(CMAKE_CXX_FLAGS "${MCPU_FLAGS} ${VFP_FLAGS} -Wall -fno-builtin -fdata-sections -ffunction-sections -mtext-section-literals -mlongcalls" CACHE INTERNAL "cxx compiler flags") 12 | set(CMAKE_ASM_FLAGS "${MCPU_FLAGS} -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags") 13 | set(CMAKE_EXE_LINKER_FLAGS "${MCPU_FLAGS} ${LD_FLAGS} -Wl,--gc-sections" CACHE INTERNAL "exe link flags") 14 | 15 | 16 | SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "c debug compiler flags") 17 | SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb3" CACHE INTERNAL "cxx debug compiler flags") 18 | SET(CMAKE_ASM_FLAGS_DEBUG "-g -ggdb3" CACHE INTERNAL "asm debug compiler flags") 19 | 20 | SET(CMAKE_C_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "c release compiler flags") 21 | SET(CMAKE_CXX_FLAGS_RELEASE "-O2 -g -ggdb3" CACHE INTERNAL "cxx release compiler flags") 22 | SET(CMAKE_ASM_FLAGS_RELEASE "" CACHE INTERNAL "asm release compiler flags") 23 | -------------------------------------------------------------------------------- /apps/twr_node_tdma/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | # Route console to RTT 3 | CONSOLE_UART: 0 4 | CONSOLE_RTT: 1 5 | CONSOLE_UART_BAUD: '460800' 6 | CONSOLE_UART_TX_BUF_SIZE: '1024' 7 | CONSOLE_HISTORY_SIZE: 8 8 | 9 | UWB_DEVICE_0: 1 10 | FS_XTALT_AUTOTUNE_ENABLED: 0 11 | HARDFLOAT: 1 12 | FLOAT_USER: 1 13 | TDMA_NSLOTS: 160 14 | RNG_VERBOSE: 2 15 | CIR_VERBOSE: 0 16 | UWB_CCP_VERBOSE: 0 17 | 18 | STATS_NAMES: 1 19 | STATS_CLI: 1 20 | CONFIG_CLI: 1 21 | DW1000_CLI: 1 22 | DW3000_CLI: 1 23 | SHELL_TASK: 1 24 | 25 | # Enable newtmgr commands. 26 | STATS_NEWTMGR: 1 27 | LOG_NEWTMGR: 1 28 | CONFIG_NEWTMGR: 1 29 | CONFIG_FCB: 1 30 | 31 | # Enable frame_filter by default to allow auto-ack to work 32 | UWBCFG_DEF_FRAME_FILTER: '"0xF"' 33 | # By default we're ccp(0x1)|anchor(0x4) 34 | UWBCFG_DEF_ROLE: '"0x5"' 35 | 36 | syscfg.vals.BLE_ENABLED: 37 | BLE_PREFIX: '"twr-node"' 38 | # BLE Disable central and observer roles. 39 | BLE_ROLE_BROADCASTER: 1 40 | BLE_ROLE_CENTRAL: 0 41 | BLE_ROLE_OBSERVER: 0 42 | BLE_ROLE_PERIPHERAL: 1 43 | 44 | # No point in having the CIR enabled unless we can use it for pdoa 45 | syscfg.vals.'!UWB_DEVICE_1 && !DW3000_DEVICE_0': 46 | CIR_ENABLED: 0 47 | 48 | 49 | syscfg.defs: 50 | BLE_ENABLED: 51 | description: 'Activate BLE' 52 | value: 0 53 | AOA_ANGLE_INVERT: 54 | description: 'Set this to one if the aoa direction is inverted relative your board' 55 | value: 0 56 | -------------------------------------------------------------------------------- /apps/streaming/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | # Route console to RTT 3 | CONSOLE_UART: 0 4 | CONSOLE_UART_BAUD: '460800' 5 | CONSOLE_UART_TX_BUF_SIZE: '1024' 6 | CONSOLE_RTT: 1 7 | CONSOLE_HISTORY_SIZE: 8 8 | 9 | UWB_DEVICE_0: 1 10 | FS_XTALT_AUTOTUNE_ENABLED: 0 11 | HARDFLOAT: 1 12 | FLOAT_USER: 1 13 | TDMA_NSLOTS: 16 14 | RNG_VERBOSE: 2 15 | CIR_VERBOSE: 0 16 | UWB_CCP_VERBOSE: 0 17 | STATS_NAMES: 1 18 | STATS_CLI: 1 19 | CONFIG_CLI: 1 20 | DW1000_CLI: 1 21 | DW3000_CLI: 1 22 | SHELL_TASK: 1 23 | 24 | # Enable newtmgr commands. 25 | STATS_NEWTMGR: 1 26 | LOG_NEWTMGR: 1 27 | CONFIG_NEWTMGR: 1 28 | CONFIG_FCB: 1 29 | DW1000_RXTX_GPIO: 1 30 | 31 | 32 | syscfg.defs: 33 | UWB_TRANSPORT_ROLE: 34 | description: 'sender' 35 | value: 1 36 | BLE_ENABLED: 37 | description: 'Activate BLE' 38 | value: 0 39 | USE_DBLBUFFER: 40 | description: 'Enable doublebuffer or not' 41 | value: 0 42 | restrictions: 43 | - '!CIR_ENABLED' 44 | CONCURRENT_NRNG: 45 | description: 'NRNG while streaming' 46 | value: 0 47 | NRANGES_ANCHOR: 48 | description: 'Act as slave-anchor in the network' 49 | value: 0 50 | NODE_START_SLOT_ID: 51 | description: > 52 | Slot ID from which the nodes should respond 53 | value: 0 54 | NODE_END_SLOT_ID: 55 | description: > 56 | Slot ID till which the nodes should respond 57 | value: 7 58 | -------------------------------------------------------------------------------- /apps/tdoa_tag/README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # Decawave TDoA blink tag Example 23 | 24 | ## Overview 25 | 26 | To demonstrate a simple blinking tag for tdoa example. Sleeping between blinks. 27 | 28 | 29 | 1. To erase the default flash image that shipped with the board 30 | 31 | ```no-highlight 32 | $ JLinkExe -device nRF52 -speed 4000 -if SWD 33 | J-Link>erase 34 | J-Link>exit 35 | $ 36 | ``` 37 | 38 | or 39 | 40 | ``` 41 | $ nrfjprog -f NRF52 -e 42 | 43 | ``` 44 | 45 | Program and build the bootloader, see other README files. 46 | 47 | 2. Build and program the application: 48 | 49 | ```no-highlight 50 | 51 | newt target create tdoa_tag 52 | newt target set tdoa_tag app=apps/tdoa_tag 53 | newt target set tdoa_tag bsp=@decawave-uwb-core/hw/bsp/dwm1001 54 | newt target set tdoa_tag build_profile=debug 55 | newt run tdoa_tag 0 56 | 57 | ``` 58 | 59 | -------------------------------------------------------------------------------- /apps/tdoa_tag/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/tdoa_tag 21 | pkg.type: app 22 | pkg.description: "Basic TDOA tag" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://loligoelectronics.com" 25 | pkg.keywords: 26 | - dw1000 27 | - tdoa 28 | 29 | pkg.deps: 30 | - "@apache-mynewt-core/kernel/os" 31 | - "@apache-mynewt-core/hw/hal" 32 | - "@apache-mynewt-core/sys/console/full" 33 | - "@apache-mynewt-core/sys/shell" 34 | - "@apache-mynewt-core/sys/log/full" 35 | - "@apache-mynewt-core/sys/stats/full" 36 | - "@apache-mynewt-core/hw/sensor" 37 | - "@decawave-uwb-core/sys/uwbcfg" 38 | - "@apache-mynewt-core/sys/config" 39 | - "@decawave-uwb-core/hw/drivers/uwb" 40 | 41 | pkg.deps.BLE_ENABLED: 42 | - "@decawave-uwb-apps/lib/bleprph" 43 | 44 | pkg.cflags: 45 | - "-std=gnu11" 46 | - "-fms-extensions" 47 | -------------------------------------------------------------------------------- /lib/bleprph/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: lib/bleprph 21 | pkg.description: "Base BLE Peripheral lib" 22 | pkg.author: "UWB Core " 23 | pkg.homepage: "http://decawave.com/" 24 | pkg.keywords: 25 | - ble 26 | 27 | pkg.deps: 28 | - "@apache-mynewt-core/mgmt/newtmgr/transport/ble" 29 | - "@apache-mynewt-nimble/nimble/host/services/ans" 30 | - "@apache-mynewt-nimble/nimble/host/services/gap" 31 | - "@apache-mynewt-nimble/nimble/host/services/gatt" 32 | - "@apache-mynewt-nimble/nimble/host/store/config" 33 | - "@apache-mynewt-nimble/nimble/host/util" 34 | - "@apache-mynewt-nimble/nimble/transport" 35 | - "@apache-mynewt-core/mgmt/imgmgr" 36 | - "@apache-mynewt-core/mgmt/newtmgr" 37 | - "@apache-mynewt-core/mgmt/newtmgr/transport/nmgr_shell" 38 | - "@mcuboot/boot/bootutil" 39 | 40 | pkg.init: 41 | bleprph_pkg_init: 320 42 | -------------------------------------------------------------------------------- /apps/listener/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/listener 21 | pkg.type: app 22 | pkg.description: "UWB listener" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://loligoelectronics.com" 25 | pkg.keywords: 26 | - dw1000 27 | 28 | pkg.deps: 29 | - "@apache-mynewt-core/kernel/os" 30 | - "@apache-mynewt-core/hw/hal" 31 | - "@apache-mynewt-core/sys/console/full" 32 | - "@apache-mynewt-core/sys/shell" 33 | - "@apache-mynewt-core/sys/log/full" 34 | - "@apache-mynewt-core/sys/stats/full" 35 | - "@apache-mynewt-core/sys/config" 36 | - "@decawave-uwb-core/sys/uwbcfg" 37 | - "@decawave-uwb-core/hw/drivers/uwb" 38 | - "@decawave-uwb-core/lib/cir" 39 | 40 | pkg.deps.BLE_ENABLED: 41 | - "@decawave-uwb-apps/lib/bleprph" 42 | 43 | pkg.deps.ETH_0: 44 | - "@apache-mynewt-core/net/ip/inet_def_service" 45 | 46 | pkg.cflags: 47 | - "-std=gnu11" 48 | - "-fms-extensions" 49 | -------------------------------------------------------------------------------- /apps/twr_nranges_tdma/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(slave_node) 2 | 3 | set(CMAKE_VERBOSE_MAKEFILE ON) 4 | 5 | #Copy syscfg.h from mynewt build system 6 | #configure_file ( 7 | # "${PROJECT_BINARY_DIR}/../../../bin/targets/${PROJECT_NAME}/generated/include/syscfg/syscfg.h" 8 | # "${PROJECT_SOURCE_DIR}/../include/syscfg/syscfg.h" 9 | #) 10 | 11 | if(NOT EXISTS "${PROJECT_BINARY_DIR}/../../../bin/targets/${PROJECT_NAME}/generated/include/syscfg/syscfg.h") 12 | message(WARNING "Building newt dependencies") 13 | execute_process(COMMAND newt target create ${PROJECT_NAME}) 14 | execute_process(COMMAND newt target set ${PROJECT_NAME} app=apps/twr_nranges_tdma) 15 | execute_process(COMMAND newt target set ${PROJECT_NAME} bsp=@mynewt-dw1000-core/hw/bsp/dwm1001) 16 | execute_process(COMMAND newt target amend ${PROJECT_NAME} syscfg=NRANGES_ANCHOR=1) 17 | execute_process(COMMAND newt build ${PROJECT_NAME}) 18 | if(NOT EXISTS "${PROJECT_BINARY_DIR}/../../../bin/targets/${PROJECT_NAME}/generated/include/syscfg/syscfg.h") 19 | message( FATAL_ERROR "Building newt dependencies failed." ) 20 | endif() 21 | endif() 22 | 23 | file(GLOB ${PROJECT_NAME}_SOURCES 24 | Src/*.c 25 | "${PROJECT_BINARY_DIR}/../../../bin/targets/${PROJECT_NAME}/generated/include/syscfg/*.h" 26 | "${PROJECT_BINARY_DIR}/../../../bin/targets/${PROJECT_NAME}/generated/include/sysflash/*.h" 27 | ) 28 | file(GLOB ${PROJECT_NAME}_HEADERS 29 | include/*.h 30 | "${PROJECT_BINARY_DIR}/../../../bin/targets/${PROJECT_NAME}/generated/src/*.c" 31 | ) 32 | 33 | add_executable( 34 | ${PROJECT_NAME} 35 | ${${PROJECT_NAME}_SOURCES} 36 | ) 37 | #target_link_libraries( 38 | # ${DW1000_DRIVER_ROOT}/dw1000 39 | # dpl 40 | # dpl_linux 41 | # dpl_os 42 | # Threads::Threads 43 | #) 44 | 45 | -------------------------------------------------------------------------------- /apps/listener/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.defs: 2 | BLE_ENABLED: 3 | description: 'Activate BLE' 4 | value: 1 5 | UWB_NUM_MBUFS: 6 | description: 'Number of message buffers' 7 | value: 64 8 | UWB_MBUF_SIZE: 9 | description: 'Size of each message buffer' 10 | value: 136 11 | CIR_NUM_SAMPLES: 12 | description: 'Default number of of CIR accumulator samples to show, 0=none. Change in console with config command.' 13 | value: '"0"' 14 | USE_DBLBUFFER: 15 | description: 'Enable doublebuffer or not' 16 | value: 1 17 | restrictions: 18 | - '!CIR_ENABLED' 19 | 20 | syscfg.vals: 21 | LOG_LEVEL: 2 22 | 23 | # Route console to UART 24 | CONSOLE_RTT: 0 25 | CONSOLE_UART: 1 26 | #CONSOLE_UART_BAUD: 460800 # Max baudrate if using ACM through jlink (/dev/ttyACMx) 27 | CONSOLE_UART_BAUD: 1000000 28 | CONSOLE_UART_TX_BUF_SIZE: 1024 29 | CONSOLE_UART_RX_BUF_SIZE: 256 30 | CONSOLE_HISTORY_SIZE: 8 31 | 32 | # Shell 33 | SHELL_TASK: 1 34 | SHELL_PROMPT_MODULE: 1 35 | SHELL_NEWTMGR: 1 36 | CONFIG_CLI: 1 37 | CONFIG_CLI_DEBUG: 1 38 | DW1000_CLI: 1 39 | STATS_NAMES: 1 40 | STATS_CLI: 1 41 | 42 | # Enable DW1000 43 | UWB_DEVICE_0: 1 44 | UWBCFG_APPLY_AT_INIT: 1 45 | CIR_ENABLED: 0 46 | CIR_VERBOSE: 0 47 | CIR_OFFSET: 4 48 | CIR_SIZE: 8 49 | UWB_CLI: 1 50 | UWB_CLI_BACKTRACE: 0 51 | 52 | ## Where to store config 53 | CONFIG_FCB: 1 54 | CONFIG_NEWTMGR: 1 55 | CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS 56 | 57 | # BLE Disable central and observer roles. 58 | BLE_ROLE_BROADCASTER: 1 59 | BLE_ROLE_CENTRAL: 0 60 | BLE_ROLE_OBSERVER: 0 61 | BLE_ROLE_PERIPHERAL: 1 62 | 63 | MSYS_1_BLOCK_COUNT: 24 64 | MSYS_1_BLOCK_SIZE: 512 65 | -------------------------------------------------------------------------------- /lib/bleprph/src/gatt_svr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include "bsp/bsp.h" 25 | 26 | #include "host/ble_hs.h" 27 | #include "host/ble_uuid.h" 28 | #include "ble_priv.h" 29 | 30 | 31 | static const struct ble_gatt_svc_def gatt_svr_svcs[] = { 32 | { 33 | 0, /* No more services. */ 34 | }, 35 | }; 36 | 37 | void 38 | gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg) 39 | { 40 | switch (ctxt->op) { 41 | case BLE_GATT_REGISTER_OP_SVC: 42 | break; 43 | 44 | case BLE_GATT_REGISTER_OP_CHR: 45 | break; 46 | 47 | case BLE_GATT_REGISTER_OP_DSC: 48 | break; 49 | 50 | default: 51 | assert(0); 52 | break; 53 | } 54 | } 55 | 56 | int 57 | gatt_svr_init(void) 58 | { 59 | int rc; 60 | 61 | rc = ble_gatts_count_cfg(gatt_svr_svcs); 62 | if (rc != 0) { 63 | return rc; 64 | } 65 | 66 | rc = ble_gatts_add_svcs(gatt_svr_svcs); 67 | if (rc != 0) { 68 | return rc; 69 | } 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /apps/rtdoa_tag/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | OS_MAIN_STACK_SIZE: 512 3 | MSYS_1_BLOCK_COUNT: 32 4 | MSYS_1_BLOCK_SIZE: 128 5 | HARDFLOAT: 1 6 | FLOAT_USER: 0 7 | OS_SYSVIEW: 0 8 | LOG_LEVEL: 2 9 | 10 | # Route console to RTT 11 | CONSOLE_UART: 1 12 | CONSOLE_RTT: 0 13 | CONSOLE_UART_BAUD: 1000000 14 | CONSOLE_UART_TX_BUF_SIZE: 1024 15 | CONSOLE_UART_RX_BUF_SIZE: 256 16 | CONSOLE_ECHO: 1 17 | CONSOLE_HISTORY_SIZE: 4 18 | 19 | # Shell 20 | SHELL_TASK: 1 21 | SHELL_PROMPT_MODULE: 1 22 | SHELL_NEWTMGR: 1 23 | CONFIG_CLI: 1 24 | IMGMGR_CLI: 1 25 | STATS_CLI: 1 26 | STATS_NAMES: 1 27 | STATS_NEWTMGR: 1 28 | DW1000_CLI: 1 29 | BCAST_OTA_CLI: 0 30 | 31 | 32 | # UWB 33 | UWB_DEVICE_0: 1 34 | DW1000_DEV_TASK_STACK_SZ: 256 35 | UWB_PKG_INIT_LOG: 1 36 | DW1000_RXTX_LEDS: 0 37 | UWBCFG_APPLY_AT_INIT: 1 38 | UWB_CCP_STATS: 1 39 | TDMA_STATS: 1 40 | RNG_STATS: 0 41 | DW1000_MAC_STATS: 0 42 | 43 | TDMA_NSLOTS: 64 44 | TDMA_ENABLED: 1 45 | TDMA_SANITY_INTERVAL: 10 46 | TDMA_STATS: 1 47 | 48 | UWB_WCS_ENABLED: 1 49 | TIMESCALE_PROCESSING_ENABLED: 1 50 | ADAPTIVE_TIMESCALE_ENABLED: 1 51 | FS_XTALT_AUTOTUNE_ENABLED: 0 52 | DW1000_BIAS_CORRECTION_ENABLED: 0 53 | OS_LATENCY: 2000 54 | XTALT_GUARD: 0x60 55 | 56 | # Config interface 57 | CONFIG_NFFS: 0 58 | CONFIG_FCB: 1 59 | CONFIG_NEWTMGR: 1 60 | CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS 61 | 62 | # IMU 63 | I2C_1: 1 64 | ADC_0: 1 65 | LSM6DSL_ONB: 1 66 | LIS2MDL_ONB: 1 67 | LPS22HB_ONB: 1 68 | 69 | NCBWIFI_ESP_PASSTHROUGH: 0 70 | ESP12F_ENABLED: 0 71 | 72 | BLEPRPH_LOG_ENABLE: 0 73 | BLE_ROLE_BROADCASTER: 1 74 | BLE_ROLE_CENTRAL: 0 75 | BLE_ROLE_OBSERVER: 0 76 | BLE_ROLE_PERIPHERAL: 1 77 | 78 | syscfg.defs: 79 | IMU_RATE: 80 | description: 'Rate at which to print IMU data to UART. Set to 0 to disable' 81 | value: 80 82 | -------------------------------------------------------------------------------- /apps/rtdoa_tag/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/rtdoa_tag 21 | pkg.type: app 22 | pkg.description: "Rtdoa tag application" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "https://decawave.com/" 25 | pkg.keywords: 26 | - dw1000 27 | - rtdoa 28 | 29 | pkg.deps: 30 | - "@apache-mynewt-core/kernel/os" 31 | - "@apache-mynewt-core/hw/hal" 32 | - "@mcuboot/boot/bootutil" 33 | - "@apache-mynewt-core/sys/id" 34 | - "@apache-mynewt-core/sys/shell" 35 | - "@apache-mynewt-core/sys/log/full" 36 | - "@apache-mynewt-core/sys/stats/full" 37 | - "@apache-mynewt-core/sys/console/full" 38 | - "@apache-mynewt-core/mgmt/imgmgr" 39 | - "@apache-mynewt-core/mgmt/newtmgr" 40 | - "@decawave-uwb-core/lib/dsp" 41 | - "@decawave-uwb-core/lib/tdma" 42 | - "@decawave-uwb-core/lib/uwb_ccp" 43 | - "@decawave-uwb-core/lib/uwb_wcs" 44 | - "@decawave-uwb-core/lib/uwb_rng" 45 | - "@decawave-uwb-core/lib/rtdoa_tag" 46 | - "@mynewt-timescale-lib/lib/timescale" 47 | - "@decawave-uwb-core/sys/uwbcfg" 48 | - "@decawave-uwb-core/lib/nmgr_uwb" 49 | - "@decawave-uwb-apps/lib/bleprph" 50 | - "@decawave-uwb-apps/lib/rtdoa_backhaul" 51 | 52 | pkg.cflags: 53 | - "-std=gnu11" 54 | - "-fms-extensions" 55 | 56 | pkg.lflags: 57 | - "-lm" 58 | -------------------------------------------------------------------------------- /apps/twr_aloha/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/twr_aloha 21 | pkg.type: app 22 | pkg.description: "Basic aloha-style ss-twr" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://www.decawave.com/" 25 | pkg.keywords: 26 | - uwb 27 | 28 | pkg.deps: 29 | - "@apache-mynewt-core/kernel/os" 30 | - "@apache-mynewt-core/hw/hal" 31 | - "@apache-mynewt-core/sys/console/full" 32 | - "@apache-mynewt-core/sys/shell" 33 | - "@apache-mynewt-core/sys/stats/full" 34 | - "@decawave-uwb-core/hw/drivers/uwb" 35 | - "@decawave-uwb-core/lib/twr_ss" 36 | - "@decawave-uwb-core/lib/twr_ss_ack" 37 | - "@decawave-uwb-core/lib/twr_ss_ext" 38 | - "@decawave-uwb-core/lib/twr_ds" 39 | - "@decawave-uwb-core/lib/twr_ds_ext" 40 | - "@decawave-uwb-core/sys/uwbcfg" 41 | - "@decawave-uwb-core/lib/cir" 42 | - "@apache-mynewt-core/boot/split" 43 | - "@mcuboot/boot/bootutil" 44 | - "@apache-mynewt-core/kernel/os" 45 | - "@apache-mynewt-core/mgmt/imgmgr" 46 | - "@apache-mynewt-core/mgmt/newtmgr" 47 | - "@apache-mynewt-core/mgmt/newtmgr/transport/nmgr_shell" 48 | - "@apache-mynewt-core/sys/log/full" 49 | 50 | pkg.cflags: 51 | - "-std=gnu11" 52 | - "-fms-extensions" 53 | - "-Wno-strict-aliasing" 54 | 55 | pkg.lflags: 56 | - "-lm" 57 | -------------------------------------------------------------------------------- /apps/README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # UWB APPs 23 | 24 | ## Overview 25 | 26 | This repo contains a series of examples for studying UWB networks and discover the uwb-core APIs. Collectivly uwb-app and uwb-core contain the essential building blocksfor a UWB enabled system. The examples use a device independent APIs and run out-of-the-box an all of Decawave products. The example are also platform independent and run out-of-the-box on a host of hardware platform. See respective example directories for usage. 27 | 28 | ``` 29 | ├── desense // Desense testing app 30 | ├── listener // Sniffer app 31 | ├── ota_uwb_master // OTA over UWB demonstration 32 | ├── ota_uwb_slave // ~ 33 | ├── rtdoa_node // Reverse Time Differene of Arrival node example 34 | ├── rtdoa_tag // ~ 35 | ├── streaming // Streaming example 36 | ├── tdoa_tag // Blink service app intended for TDOA ranging scheme 37 | ├── twr_aloha // Two-Way-Ranging without TDMA, Aloha-style 38 | ├── twr_nrng_tdma // n ranges with n+2 messages, using with TDMA scheme 39 | ├── twr_node_tdma // Two-Way-Ranging example with TDMA scheme 40 | ├── twr_tag_tdma // ~ 41 | └── README.md // This file 42 | 43 | ``` 44 | -------------------------------------------------------------------------------- /apps/twr_nranges_tdma/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/twr_nranges_tdma 21 | pkg.type: app 22 | pkg.description: "Basic nranges anchor/tag app" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://www.decawave.com/" 25 | pkg.keywords: 26 | - uwb 27 | 28 | pkg.deps: 29 | - "@apache-mynewt-core/kernel/os" 30 | - "@apache-mynewt-core/hw/hal" 31 | - "@apache-mynewt-core/sys/console/full" 32 | - "@apache-mynewt-core/sys/shell" 33 | - "@apache-mynewt-core/sys/log/full" 34 | - "@apache-mynewt-core/mgmt/imgmgr" 35 | - "@apache-mynewt-core/mgmt/newtmgr" 36 | - "@decawave-uwb-core/hw/drivers/uwb" 37 | - "@decawave-uwb-core/lib/twr_ss_nrng" 38 | - "@decawave-uwb-core/sys/uwbcfg" 39 | - "@decawave-uwb-core/lib/uwb_pan" 40 | - "@decawave-uwb-core/lib/dsp" 41 | - "@decawave-uwb-core/lib/tdma" 42 | - "@decawave-uwb-core/lib/uwb_ccp" 43 | - "@decawave-uwb-core/lib/survey" 44 | - "@decawave-uwb-core/lib/nmgr_uwb" 45 | - "@decawave-uwb-core/mgmt/bcast_ota" 46 | - "@decawave-uwb-core/lib/panmaster" 47 | - "@mcuboot/boot/bootutil" 48 | # - "@decawave-uwb-apps/lib/bleprph" 49 | 50 | pkg.deps.APP_USE_WCS: 51 | - "@decawave-uwb-core/lib/uwb_wcs" 52 | - "@mynewt-timescale-lib/lib/timescale" 53 | 54 | pkg.cflags: 55 | - "-std=gnu11" 56 | - "-fms-extensions" 57 | 58 | pkg.lflags: 59 | - "-lm" 60 | -------------------------------------------------------------------------------- /apps/ota_uwb_slave/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/ota_uwb_slave 21 | pkg.type: app 22 | pkg.description: "Sample app to test ota over uwb" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://www.decawave.com/" 25 | pkg.keywords: 26 | - dw1000 27 | 28 | pkg.deps: 29 | - "@apache-mynewt-core/kernel/os" 30 | - "@apache-mynewt-core/hw/hal" 31 | - "@apache-mynewt-core/sys/console/full" 32 | - "@apache-mynewt-core/sys/shell" 33 | - "@apache-mynewt-core/sys/stats/full" 34 | - "@decawave-uwb-core/hw/drivers/uwb" 35 | - "@mynewt-timescale-lib/lib/timescale" 36 | - "@decawave-uwb-core/lib/twr_ss" 37 | - "@decawave-uwb-core/lib/twr_ds" 38 | - "@decawave-uwb-core/lib/twr_ds_ext" 39 | - "@decawave-uwb-core/lib/nmgr_uwb" 40 | - "@decawave-uwb-core/lib/nmgr_cmds" 41 | - "@decawave-uwb-core/sys/uwbcfg" 42 | - "@apache-mynewt-core/boot/split" 43 | - "@mcuboot/boot/bootutil" 44 | - "@apache-mynewt-core/kernel/os" 45 | - "@apache-mynewt-core/mgmt/imgmgr" 46 | - "@apache-mynewt-core/mgmt/newtmgr" 47 | - "@apache-mynewt-core/mgmt/newtmgr/transport/nmgr_shell" 48 | - "@apache-mynewt-core/sys/log/full" 49 | - "@apache-mynewt-core/sys/log/modlog" 50 | 51 | pkg.cflags: 52 | - "-std=gnu11" 53 | - "-fms-extensions" 54 | - "-DNRF52" 55 | - "-Wno-strict-aliasing" 56 | 57 | pkg.lflags: 58 | - "-lm" 59 | -------------------------------------------------------------------------------- /repository.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | repo.name: decawave-uwb-apps 21 | repo.versions: 22 | "0.0.0": "master" 23 | "0.0.2": "uwb_apps_0_0_2_tag" 24 | "0.0.3": "uwb_apps_0_0_3_tag" 25 | "0.1.0": "uwb_apps_0_1_0_tag" 26 | "0.1.1": "uwb_apps_0_1_1_tag" 27 | 28 | "0-latest": "0.1.1" 29 | "0-dev": "0.0.0" # master 30 | 31 | repo.newt_compatibility: 32 | # Allow all versions for 0.0.0. This is a workaround to prevent a warning 33 | # from being displayed when newt doesn't know which version of the repo is 34 | # present. 35 | 0.0.0: 36 | 0.0.0: good 37 | 0.1.1: 38 | 1.7.0: good 39 | 0.1.0: 40 | 1.7.0: good 41 | 0.0.3: 42 | 1.7.0: good 43 | 0.0.2: 44 | 1.7.0: good 45 | 46 | repo.deps: 47 | apache-mynewt-core: 48 | type: github 49 | user: apache 50 | repo: mynewt-core 51 | vers: 52 | #master: 0-dev 53 | uwb_apps_0_0_2_tag: 1.7.0 54 | uwb_apps_0_0_3_tag: 1.7.0 55 | uwb_apps_0_1_0_tag: 1.7.0 56 | uwb_apps_0_1_1_tag: 1.7.0 57 | decawave-uwb-core: 58 | type: github 59 | user: decawave 60 | repo: uwb-core 61 | vers: 62 | master: 0-dev 63 | uwb_apps_0_0_2_tag: 0.0.2 64 | uwb_apps_0_0_3_tag: 0.0.3 65 | uwb_apps_0_1_0_tag: 0.1.0 66 | uwb_apps_0_1_1_tag: 0.1.1 67 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.2) 2 | project(uwb-apps) 3 | set (${PROJECT_NAME}_VERSION_MAJOR ${VERSION_MAJOR}) 4 | set (${PROJECT_NAME}_VERSION_MINOR ${VERSION_MINOR}) 5 | set (${PROJECT_NAME}_VERSION_PATCH ${VERSION_PATCH}) 6 | configure_file ( 7 | "${PROJECT_SOURCE_DIR}/config.h.in" 8 | "${PROJECT_BINARY_DIR}/../include/config.h" 9 | ) 10 | set(CMAKE_BUILD_TYPE ${BUILD_TYPE}) 11 | 12 | add_subdirectory(apps/twr_nranges_tdma) 13 | 14 | option(BUILD_DOC "Build documentation" ON) 15 | 16 | if (CMAKE_BUILD_TYPE MATCHES "^[Rr]elease") 17 | find_package(Doxygen) 18 | if(DOXYGEN_FOUND) 19 | option(BUILD_DOC "Build documentation" ON) 20 | set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/doxy/Doxyfile-dw1000.conf) 21 | set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) 22 | configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY) 23 | message("Doxygen build started") 24 | 25 | add_custom_target( doc_doxygen ALL 26 | COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT} 27 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 28 | COMMENT "Generating API documentation with Doxygen" 29 | VERBATIM ) 30 | endif() 31 | endif() 32 | 33 | # build a CPack driven installer package 34 | include (InstallRequiredSystemLibraries) 35 | set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") 36 | set (CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}") 37 | set (CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}") 38 | set (CPACK_PACKAGE_VERSION_PATCH "${${PROJECT_NAME}_VERSION_PATCH}") 39 | 40 | set (CPACK_COMPONENTS_ALL applications libraries headers) 41 | set (CPACK_COMPONENT_APPLICATIONS_DESCRIPTION "Decawave Porting Layer") 42 | set (CPACK_COMPONENT_LIBRARIES_DESCRIPTION "Static libraries used to build programs with example") 43 | set (CPACK_COMPONENT_HEADERS_DESCRIPTION "C/C++ header files for use with template") 44 | set (CPACK_COMPONENT_DOCS_DISPLAY_NAME "C++ API Documentation") 45 | set (CPACK_COMPONENT_DOCS_DESCRIPTION "C++ API HTML files describing the API for Interface") 46 | 47 | find_package(Doxygen) 48 | if(DOXYGEN_FOUND) 49 | install (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/docs/html DESTINATION ./) 50 | endif() 51 | 52 | include (CPack) 53 | 54 | include(CTest) 55 | 56 | # does the application run 57 | add_test (TutorialRuns Tutorial 25) 58 | 59 | -------------------------------------------------------------------------------- /apps/rtdoa_node/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/rtdoa_node 21 | pkg.type: app 22 | pkg.description: "Rtdoa node application" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "https://decawave.com/" 25 | pkg.keywords: 26 | - dw1000 27 | - rtdoa 28 | 29 | pkg.deps: 30 | - "@apache-mynewt-core/kernel/os" 31 | - "@apache-mynewt-core/hw/hal" 32 | - "@mcuboot/boot/bootutil" 33 | - "@apache-mynewt-core/sys/id" 34 | - "@apache-mynewt-core/sys/shell" 35 | - "@apache-mynewt-core/sys/log/full" 36 | - "@apache-mynewt-core/sys/stats/full" 37 | - "@apache-mynewt-core/sys/console/full" 38 | - "@apache-mynewt-core/mgmt/imgmgr" 39 | - "@apache-mynewt-core/mgmt/newtmgr" 40 | - "@decawave-uwb-core/lib/dsp" 41 | - "@decawave-uwb-core/lib/tdma" 42 | - "@decawave-uwb-core/lib/uwb_ccp" 43 | - "@decawave-uwb-core/lib/uwb_rng" 44 | - "@decawave-uwb-core/lib/nrng" 45 | - "@decawave-uwb-core/lib/rtdoa_node" 46 | - "@decawave-uwb-core/lib/twr_ss_nrng" 47 | - "@decawave-uwb-core/lib/uwb_pan" 48 | - "@decawave-uwb-core/lib/uwb_wcs" 49 | - "@mynewt-timescale-lib/lib/timescale" 50 | - "@decawave-uwb-core/sys/uwbcfg" 51 | - "@decawave-uwb-core/lib/nmgr_uwb" 52 | - "@decawave-uwb-core/lib/tofdb" 53 | - "@decawave-uwb-core/mgmt/bcast_ota" 54 | - "@decawave-uwb-core/lib/panmaster" 55 | - "@decawave-uwb-apps/lib/bleprph" 56 | 57 | pkg.cflags: 58 | - "-std=gnu11" 59 | - "-fms-extensions" 60 | 61 | pkg.lflags: 62 | - "-lm" 63 | -------------------------------------------------------------------------------- /apps/ota_uwb_master/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/ota_uwb_master 21 | pkg.type: app 22 | pkg.description: "Sample app to test ota over uwb" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://www.decawave.com/" 25 | pkg.keywords: 26 | - dw1000 27 | - superres 28 | 29 | pkg.deps: 30 | - "@apache-mynewt-core/hw/hal" 31 | - "@apache-mynewt-core/kernel/os" 32 | - "@apache-mynewt-core/sys/console/full" 33 | - "@apache-mynewt-core/sys/log/modlog" 34 | - "@apache-mynewt-core/sys/stats/full" 35 | - "@apache-mynewt-core/sys/log/full" 36 | - "@apache-mynewt-core/sys/sysinit" 37 | - "@apache-mynewt-core/sys/shell" 38 | - "@apache-mynewt-core/sys/id" 39 | - "@apache-mynewt-core/mgmt/newtmgr/transport/ble" 40 | - "@mcuboot/boot/bootutil" 41 | - "@apache-mynewt-core/mgmt/newtmgr" 42 | - "@apache-mynewt-core/mgmt/imgmgr" 43 | - "@apache-mynewt-core/boot/split" 44 | #uwb related 45 | - "@decawave-uwb-core/hw/drivers/uwb" 46 | - "@decawave-uwb-core/lib/twr_ds_ext" 47 | - "@decawave-uwb-core/lib/nmgr_cmds" 48 | - "@decawave-uwb-core/lib/nmgr_uwb" 49 | - "@decawave-uwb-core/lib/twr_ss" 50 | - "@decawave-uwb-core/lib/twr_ds" 51 | - "@decawave-uwb-core/sys/uwbcfg" 52 | - "@decawave-uwb-core/lib/dsp" 53 | 54 | pkg.deps.BLE_ENABLED: 55 | - "@decawave-uwb-apps/lib/bleprph" 56 | 57 | pkg.cflags: 58 | - "-std=gnu11" 59 | - "-fms-extensions" 60 | - "-DNRF52" 61 | - "-Wno-strict-aliasing" 62 | 63 | pkg.lflags: 64 | - "-lm" 65 | -------------------------------------------------------------------------------- /apps/twr_node_tdma/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/twr_node_tdma 21 | pkg.type: app 22 | pkg.description: "Basic reverse superres anchor node" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://www.decawave.com/" 25 | pkg.keywords: 26 | - dw1000 27 | 28 | pkg.deps: 29 | - "@apache-mynewt-core/kernel/os" 30 | - "@apache-mynewt-core/hw/hal" 31 | - "@apache-mynewt-core/sys/console/full" 32 | - "@apache-mynewt-core/sys/shell" 33 | - "@apache-mynewt-core/sys/stats/full" 34 | - "@decawave-uwb-core/hw/drivers/uwb" 35 | - "@decawave-uwb-core/lib/dsp" 36 | - "@decawave-uwb-core/lib/tdma" 37 | - "@decawave-uwb-core/lib/uwb_ccp" 38 | - "@decawave-uwb-core/lib/uwb_wcs" 39 | - "@mynewt-timescale-lib/lib/timescale" 40 | - "@decawave-uwb-core/lib/cir" 41 | - "@decawave-uwb-core/lib/twr_ss" 42 | - "@decawave-uwb-core/lib/twr_ss_ack" 43 | - "@decawave-uwb-core/lib/twr_ss_ext" 44 | - "@decawave-uwb-core/lib/twr_ds" 45 | - "@decawave-uwb-core/lib/twr_ds_ext" 46 | - "@decawave-uwb-core/sys/uwbcfg" 47 | - "@apache-mynewt-core/boot/split" 48 | - "@mcuboot/boot/bootutil" 49 | - "@apache-mynewt-core/kernel/os" 50 | - "@apache-mynewt-core/mgmt/imgmgr" 51 | - "@apache-mynewt-core/mgmt/newtmgr" 52 | - "@apache-mynewt-core/mgmt/newtmgr/transport/nmgr_shell" 53 | - "@apache-mynewt-core/sys/log/full" 54 | 55 | pkg.deps.BLE_ENABLED: 56 | - "@decawave-uwb-apps/lib/bleprph" 57 | 58 | pkg.cflags: 59 | - "-std=gnu11" 60 | - "-fms-extensions" 61 | - "-Wno-strict-aliasing" 62 | -------------------------------------------------------------------------------- /apps/twr_tag_tdma/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/twr_tag_tdma 21 | pkg.type: app 22 | pkg.description: "Basic reverse superres anchor node" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://www.decawave.com/" 25 | pkg.keywords: 26 | - dw1000 27 | 28 | pkg.deps: 29 | - "@apache-mynewt-core/kernel/os" 30 | - "@apache-mynewt-core/hw/hal" 31 | - "@apache-mynewt-core/sys/console/full" 32 | - "@apache-mynewt-core/sys/shell" 33 | - "@apache-mynewt-core/sys/stats/full" 34 | - "@decawave-uwb-core/hw/drivers/uwb" 35 | - "@decawave-uwb-core/lib/tdma" 36 | - "@decawave-uwb-core/lib/uwb_ccp" 37 | - "@decawave-uwb-core/lib/uwb_wcs" 38 | - "@mynewt-timescale-lib/lib/timescale" 39 | - "@decawave-uwb-core/lib/twr_ss" 40 | - "@decawave-uwb-core/lib/twr_ss_ack" 41 | - "@decawave-uwb-core/lib/twr_ss_ext" 42 | - "@decawave-uwb-core/lib/twr_ds" 43 | - "@decawave-uwb-core/lib/twr_ds_ext" 44 | - "@decawave-uwb-core/lib/cir" 45 | - "@decawave-uwb-core/sys/uwbcfg" 46 | - "@apache-mynewt-core/boot/split" 47 | - "@mcuboot/boot/bootutil" 48 | - "@apache-mynewt-core/kernel/os" 49 | - "@apache-mynewt-core/mgmt/imgmgr" 50 | - "@apache-mynewt-core/mgmt/newtmgr" 51 | - "@apache-mynewt-core/mgmt/newtmgr/transport/nmgr_shell" 52 | - "@apache-mynewt-core/sys/log/full" 53 | 54 | pkg.deps.BLE_ENABLED: 55 | - "@decawave-uwb-apps/lib/bleprph" 56 | 57 | pkg.cflags: 58 | - "-std=gnu11" 59 | - "-fms-extensions" 60 | - "-Wno-strict-aliasing" 61 | 62 | pkg.lflags: 63 | - "-lm" 64 | -------------------------------------------------------------------------------- /apps/streaming/pkg.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | 20 | pkg.name: apps/streaming 21 | pkg.type: app 22 | pkg.description: "Basic reverse superres anchor node" 23 | pkg.author: "UWB Core " 24 | pkg.homepage: "http://www.decawave.com/" 25 | pkg.keywords: 26 | 27 | pkg.deps: 28 | - "@decawave-uwb-core/lib/uwb_transport" 29 | - "@apache-mynewt-core/hw/hal" 30 | - "@apache-mynewt-core/sys/console/full" 31 | - "@apache-mynewt-core/sys/shell" 32 | - "@apache-mynewt-core/sys/stats/full" 33 | - "@decawave-uwb-core/hw/drivers/uwb" 34 | - "@decawave-uwb-core/lib/dsp" 35 | - "@decawave-uwb-core/lib/tdma" 36 | - "@decawave-uwb-core/lib/uwb_ccp" 37 | - "@decawave-uwb-core/lib/uwb_wcs" 38 | - "@mynewt-timescale-lib/lib/timescale" 39 | # - "@decawave-uwb-core/lib/twr_ss" 40 | # - "@decawave-uwb-core/lib/twr_ss_ext" 41 | # - "@decawave-uwb-core/lib/twr_ds" 42 | # - "@decawave-uwb-core/lib/twr_ds_ext" 43 | - "@decawave-uwb-core/porting/dpl_lib" 44 | - "@decawave-uwb-core/lib/twr_ss_nrng" 45 | - "@decawave-uwb-core/sys/uwbcfg" 46 | - "@apache-mynewt-core/boot/split" 47 | - "@mcuboot/boot/bootutil" 48 | - "@apache-mynewt-core/kernel/os" 49 | - "@apache-mynewt-core/mgmt/imgmgr" 50 | - "@apache-mynewt-core/mgmt/newtmgr" 51 | - "@apache-mynewt-core/mgmt/newtmgr/transport/nmgr_shell" 52 | - "@apache-mynewt-core/sys/log/full" 53 | - "@apache-mynewt-core/util/crc" 54 | 55 | pkg.deps.BLE_ENABLED: 56 | - "@decawave-uwb-apps/lib/bleprph" 57 | 58 | pkg.cflags: 59 | - "-std=gnu11" 60 | - "-fms-extensions" 61 | - "-Wno-strict-aliasing" 62 | -------------------------------------------------------------------------------- /lib/bleprph/src/ble_priv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #ifndef H_BLEPRPH_PRIV_ 21 | #define H_BLEPRPH_PRIV_ 22 | 23 | #include 24 | #include "log/log.h" 25 | #include "nimble/ble.h" 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | struct ble_hs_cfg; 31 | struct ble_gatt_register_ctxt; 32 | 33 | extern struct log bleprph_log; 34 | 35 | /* bleprph uses the first "peruser" log module. */ 36 | #define BLEPRPH_LOG_MODULE (LOG_MODULE_PERUSER + 0) 37 | 38 | /* Convenience macro for logging to the bleprph module. */ 39 | #if MYNEWT_VAL(BLEPRPH_LOG_ENABLE) 40 | #define BLEPRPH_LOG(lvl, ...) \ 41 | LOG_ ## lvl(&bleprph_log, BLEPRPH_LOG_MODULE, __VA_ARGS__) 42 | #else 43 | #define BLEPRPH_LOG(lvl, ...) {} 44 | #endif 45 | 46 | /** GATT server. */ 47 | #define GATT_SVR_SVC_ALERT_UUID 0x1811 48 | #define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47 49 | #define GATT_SVR_CHR_NEW_ALERT 0x2A46 50 | #define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48 51 | #define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45 52 | #define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44 53 | 54 | void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg); 55 | int gatt_svr_init(void); 56 | 57 | /* PHY support */ 58 | #if MYNEWT_VAL(BLEPRPH_LE_PHY_SUPPORT) 59 | #define CONN_HANDLE_INVALID 0xffff 60 | 61 | void phy_init(void); 62 | void phy_conn_changed(uint16_t handle); 63 | void phy_update(uint8_t phy); 64 | #endif 65 | 66 | /** Misc. */ 67 | void print_bytes(const uint8_t *bytes, int len); 68 | void print_addr(const void *addr); 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /apps/streaming/README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # Decawave UWB Transport Streaming Example 23 | 24 | 25 | ## Overview 26 | 27 | The streaming example makes use of the UWB transport layer for stream data. 28 | 29 | ## Setup 30 | 31 | 1. Flash tx/rx_stream apps 32 | 33 | In this example the tx_stream streams transmits a buffer at 3.9Mbps to the rx_stream. The rx_stream is the designated clock master. The example also enables bleprph package so stats information can be view through AdaFruit Mynewt Manager App or in the CLI. 34 | 35 | 36 | ```no-highlight 37 | 38 | newt target create tx_stream 39 | newt target set tx_stream app=apps/streaming 40 | newt target set tx_stream bsp=@decawave-uwb-core/hw/bsp/dwm1001 41 | newt target set tx_stream build_profile=debug 42 | # Uncomment next line to use uart instead of rtt console 43 | #newt target amend tx_stream syscfg=CONSOLE_UART_BAUD=460800:CONSOLE_UART=1:CONSOLE_RTT=0 44 | newt target amend tx_stream syscfg=UWB_TRANSPORT_ROLE=1:OS_LATENCY=1000:CONSOLE_UART_BAUD=115200:CONSOLE_UART=1:CONSOLE_RTT=0:DW1000_SYS_STATUS_BACKTRACE_LEN=128 45 | newt run tx_stream 0 46 | 47 | #newt target set tx_stream bsp=@decawave-uwb-core/hw/bsp/dwm1002 48 | #newt run tx_stream 0 49 | 50 | newt target create rx_stream 51 | newt target set rx_stream app=apps/streaming 52 | newt target set rx_stream bsp=@decawave-uwb-core/hw/bsp/dwm1001 53 | newt target set rx_stream build_profile=debug 54 | # Uncomment next line to use uart instead of rtt console 55 | #newt target amend rx_stream syscfg=CONSOLE_UART_BAUD=460800:CONSOLE_UART=1:CONSOLE_RTT=0 56 | newt target amend rx_stream syscfg=UWB_TRANSPORT_ROLE=0:OS_LATENCY=1000:USE_DBLBUFFER=1:CONSOLE_UART_BAUD=115200:CONSOLE_UART=1:CONSOLE_RTT=0:DW1000_SYS_STATUS_BACKTRACE_LEN=128 57 | newt run rx_stream 0 58 | 59 | ``` 60 | 61 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent { 3 | label 'ubuntu' 4 | } 5 | environment { 6 | TEST = 'BUILD_TARGETS' 7 | TOTAL_SETS = 1 8 | TARGET_SET = 1 9 | } 10 | stages { 11 | stage('Install') { 12 | environment { 13 | JENKINS_CI = "${env.WORKSPACE}/.ci" 14 | JENKINS_BIN = "${env.WORKSPACE}/../bin" 15 | TOOLCHAIN_PATH = "${env.WORKSPACE}/../gcc_toolchain" 16 | } 17 | steps { 18 | echo 'Installing...' 19 | sh 'rm -rf ${JENKINS_CI};git clone https://github.com/decawave/mynewt-travis-ci ${JENKINS_CI}' 20 | sh 'chmod +x ${JENKINS_CI}/jenkins/*.sh' 21 | sh '${JENKINS_CI}/jenkins/linux_jenkins_install.sh' 22 | sh '#cp -r ${JENKINS_CI}/jenkins/uwb-apps-project.yml project.yml' 23 | sh 'mkdir -p targets;cp -r ${JENKINS_CI}/uwb-apps-targets/* targets/' 24 | echo 'Remove any patches to mynewt-core if there..' 25 | sh '[ -d repos/apache-mynewt-core ] && (cd repos/apache-mynewt-core;git checkout -- ./;cd ${WORKSPACE}) || echo "nothing to do"' 26 | sh ''' 27 | if ! newt upgrade;then 28 | echo "Need to remove mcuboot/ext/mbedtls due to bug in git" 29 | rm -rf repos/mcuboot/ext/mbedtls; 30 | newt upgrade; 31 | fi 32 | ''' 33 | echo 'Test for dw3000 access' 34 | sh 'bash repos/decawave-uwb-core/setup.sh' 35 | sh '${JENKINS_CI}/jenkins/uwb-apps-setup.sh' 36 | } 37 | } 38 | stage('Build') { 39 | environment { 40 | JENKINS_CI = "${env.WORKSPACE}/.ci" 41 | JENKINS_BIN = "${env.WORKSPACE}/../bin" 42 | TOOLCHAIN_PATH = "${env.WORKSPACE}/../gcc_toolchain" 43 | } 44 | steps { 45 | echo 'Building..' 46 | sh '${JENKINS_CI}/jenkins/prepare_test.sh ${TOTAL_SETS}' 47 | sh '${JENKINS_CI}/jenkins/run_test.sh' 48 | } 49 | } 50 | stage('Test') { 51 | environment { 52 | JENKINS_CI = "${env.WORKSPACE}/.ci" 53 | JENKINS_BIN = "${env.WORKSPACE}/../bin" 54 | TOOLCHAIN_PATH = "${env.WORKSPACE}/../gcc_toolchain" 55 | } 56 | steps { 57 | echo 'Testing....' 58 | sh '${JENKINS_CI}/jenkins/post_build.sh' 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /apps/rtdoa_node/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | OS_MAIN_STACK_SIZE: 512 3 | MSYS_1_BLOCK_COUNT: 32 4 | MSYS_1_BLOCK_SIZE: 128 5 | HARDFLOAT: 1 6 | LOG_LEVEL: 2 7 | 8 | # Route console 9 | CONSOLE_UART: 1 10 | CONSOLE_RTT: 0 11 | CONSOLE_UART_BAUD: 115200 12 | CONSOLE_UART_TX_BUF_SIZE: 1024 13 | CONSOLE_UART_RX_BUF_SIZE: 256 14 | CONSOLE_ECHO: 1 15 | CONSOLE_HISTORY_SIZE: 4 16 | 17 | # Shell 18 | SHELL_TASK: 1 19 | SHELL_PROMPT_MODULE: 1 20 | SHELL_NEWTMGR: 1 21 | CONFIG_CLI: 1 22 | IMGMGR_CLI: 1 23 | STATS_CLI: 1 24 | STATS_NAMES: 1 25 | STATS_NEWTMGR: 1 26 | DW1000_CLI: 1 27 | BCAST_OTA_CLI: 1 28 | 29 | # UWB 30 | UWB_DEVICE_0: 1 31 | DW1000_DEV_TASK_STACK_SZ: 256 32 | UWB_PKG_INIT_LOG: 1 33 | DW1000_RXTX_LEDS: 0 34 | UWBCFG_APPLY_AT_INIT: 1 35 | UWB_CCP_STATS: 1 36 | TDMA_STATS: 1 37 | RNG_STATS: 0 38 | DW1000_MAC_STATS: 1 39 | 40 | UWB_CCP_ENABLED: 1 41 | UWB_CCP_PERIOD: ((uint32_t)0x100000) # ~1Hz 42 | UWB_CCP_MAX_CASCADE_RPTS: 8 43 | TDMA_NSLOTS: 64 44 | TDMA_ENABLED: 1 45 | TDMA_SANITY_INTERVAL: 10 46 | TDMA_STATS: 1 47 | 48 | WCS_ENABLED: 1 49 | TIMESCALE_PROCESSING_ENABLED: 1 50 | ADAPTIVE_TIMESCALE_ENABLED: 1 51 | FS_XTALT_AUTOTUNE_ENABLED: 0 52 | DW1000_BIAS_CORRECTION_ENABLED: 0 53 | OS_LATENCY: 2000 54 | XTALT_GUARD: 0x60 55 | 56 | UWBCFG_DEF_ROLE: '"0x4"' 57 | 58 | # Pan 59 | UWB_PAN_ENABLED: 1 60 | UWB_PAN_RX_TIMEOUT: ((uint16_t){4000}) 61 | UWB_PAN_LEASE_TIME: 1800 62 | UWB_PAN_LEASE_EXP_MARGIN: 60500 63 | 64 | ## Panmaster 65 | PANMASTER_FCB: 1 66 | PANMASTER_FCB_FLASH_AREA: FLASH_AREA_REBOOT_LOG 67 | REBOOT_LOG_FLASH_AREA: "" 68 | PANMASTER_NFFS: 0 69 | PANMASTER_MAXNUM_NODES: 64 70 | PANMASTER_DEFAULT_PANID: '"0xDECA"' 71 | PANMASTER_CLI: 1 72 | 73 | NRNG_ENABLED: 1 74 | LOLIGO_NRANGES_N_NODES: 8 75 | LOLIGO_NRANGES_USE_SSR: 1 76 | LOLIGO_NRANGES_N_TAGS: 4 77 | LOLIGO_NRANGES_GUARD_DLY: ((uint16_t){0x140}) 78 | 79 | # Config interface 80 | CONFIG_NFFS: 0 81 | CONFIG_FCB: 1 82 | CONFIG_NEWTMGR: 1 83 | CONFIG_FCB_FLASH_AREA: FLASH_AREA_NFFS 84 | 85 | I2C_1: 1 86 | ADC_0: 1 87 | LSM6DSL_ONB: 1 88 | LIS2MDL_ONB: 1 89 | LPS22HB_ONB: 1 90 | 91 | NCBWIFI_ESP_PASSTHROUGH: 0 92 | ESP12F_ENABLED: 0 93 | 94 | # BLE 95 | BLEPRPH_LOG_ENABLE: 0 96 | BLE_ROLE_BROADCASTER: 1 97 | BLE_ROLE_CENTRAL: 0 98 | BLE_ROLE_OBSERVER: 0 99 | BLE_ROLE_PERIPHERAL: 1 100 | 101 | 102 | syscfg.defs: 103 | MASTER_NODE: 104 | description: 'Act as pan/clock master in the network' 105 | value: 0 106 | 107 | syscfg.vals.MASTER_NODE: 108 | UWBCFG_DEF_ROLE: '"0x7"' 109 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, 12 | # software distributed under the License is distributed on an 13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 | # KIND, either express or implied. See the License for the 15 | # specific language governing permissions and limitations 16 | # under the License. 17 | 18 | language: go 19 | 20 | _addons: &addon_conf 21 | apt: 22 | sources: 23 | - ubuntu-toolchain-r-test 24 | packages: 25 | - gcc-7-multilib 26 | - linux-libc-dev:i386 27 | 28 | go: 29 | - "1.12" 30 | 31 | git: 32 | depth: false 33 | 34 | matrix: 35 | include: 36 | # newt build 37 | - os: linux 38 | env: 39 | - TEST=BUILD_TARGETS 40 | - VM_AMOUNT=2 41 | - TARGET_SET=1 42 | - os: linux 43 | env: 44 | - TEST=BUILD_TARGETS 45 | - VM_AMOUNT=2 46 | - TARGET_SET=2 47 | # - os: linux 48 | # env: 49 | # - TEST=BUILD_TARGETS 50 | # - VM_AMOUNT=4 51 | # - TARGET_SET=3 52 | # - os: linux 53 | # env: 54 | # - TEST=BUILD_TARGETS 55 | # - VM_AMOUNT=4 56 | # - TARGET_SET=4 57 | 58 | # newt test all (Linux) 59 | # - os: linux 60 | # addons: *addon_conf 61 | # env: 62 | # - TEST=TEST_ALL 63 | # - VM_AMOUNT=3 64 | # - TARGET_SET=1 65 | # - os: linux 66 | # addons: *addon_conf 67 | # env: 68 | # - TEST=TEST_ALL 69 | # - VM_AMOUNT=3 70 | # - TARGET_SET=2 71 | # - os: linux 72 | # addons: *addon_conf 73 | # env: 74 | # - TEST=TEST_ALL 75 | # - VM_AMOUNT=3 76 | # - TARGET_SET=3 77 | 78 | before_install: 79 | - printenv 80 | - export GOPATH=$HOME/gopath 81 | - go version 82 | 83 | install: 84 | - git clone https://github.com/decawave/mynewt-travis-ci $HOME/ci 85 | - chmod +x $HOME/ci/*.sh 86 | - $HOME/ci/${TRAVIS_OS_NAME}_travis_install.sh 87 | 88 | before_script: 89 | - newt version 90 | - gcc --version 91 | - if [ "${TEST}" != "TEST_ALL" ]; then arm-none-eabi-gcc --version; fi 92 | - cp -R $HOME/ci/uwb-apps-project.yml project.yml 93 | - cp -R $HOME/ci/uwb-apps-targets targets 94 | - newt upgrade 95 | # Try to sync branches between core and apps 96 | - $HOME/ci/uwb-apps-setup.sh 97 | # pass in the number of target sets 98 | - $HOME/ci/prepare_test.sh $VM_AMOUNT 99 | 100 | script: 101 | - $HOME/ci/run_test.sh 102 | 103 | cache: 104 | directories: 105 | - $HOME/TOOLCHAIN 106 | - $HOME/Library/Caches/Homebrew 107 | -------------------------------------------------------------------------------- /apps/twr_nranges_tdma/syscfg.yml: -------------------------------------------------------------------------------- 1 | syscfg.vals: 2 | # Route console to RTT 3 | CONSOLE_UART: 0 4 | CONSOLE_RTT: 1 5 | CONSOLE_BLE_MONITOR: 0 6 | CONSOLE_UART_BAUD: 460800 7 | CONSOLE_UART_TX_BUF_SIZE: 1024 8 | CONSOLE_HISTORY_SIZE: 8 9 | 10 | LOG_LEVEL: 0 11 | 12 | CONFIG_FCB: 1 13 | 14 | UWB_DEVICE_0: 1 15 | FS_XTALT_AUTOTUNE_ENABLED: 0 16 | TDMA_NSLOTS: 160 17 | NRNG_DEVICE_TYPE: 1 18 | HARDFLOAT: 1 19 | FLOAT_USER: 1 20 | STATS_NAMES: 1 21 | STATS_CLI: 1 22 | CONFIG_CLI: 1 23 | DW1000_CLI: 1 24 | DW3000_CLI: 1 25 | BCAST_OTA_CLI: 1 26 | IMGMGR_CLI: 1 27 | SHELL_TASK: 1 28 | WCS_VERBOSE: 1 29 | SURVEY_VERBOSE: 1 30 | NRNG_VERBOSE: 0 31 | TDMA_SANITY_INTERVAL: 10 32 | OS_LATENCY: 1000 33 | 34 | NRNG_VERBOSE: 1 35 | NRNG_DEVICE_TYPE: 1 36 | 37 | # Pan related parameters, lease in s, lease exp margin in ms 38 | UWB_PAN_ENABLED: 1 39 | UWB_PAN_RX_TIMEOUT: ((uint16_t){4000}) 40 | UWB_PAN_LEASE_TIME: 3600 41 | UWB_PAN_LEASE_EXP_MARGIN: 60000 42 | 43 | ## Panmaster 44 | PANMASTER_FCB: 1 45 | PANMASTER_FCB_FLASH_AREA: FLASH_AREA_REBOOT_LOG 46 | REBOOT_LOG_FLASH_AREA: "" 47 | PANMASTER_NFFS: 0 48 | PANMASTER_MAXNUM_NODES: 64 49 | PANMASTER_DEFAULT_PANID: '"0xDECA"' 50 | PANMASTER_CLI: 1 51 | 52 | SURVEY_RANGE_SLOT: 3 53 | SURVEY_BROADCAST_SLOT: 4 54 | 55 | # By default we're a tag 56 | UWBCFG_DEF_ROLE: '"0x0"' 57 | UWBCFG_APPLY_AT_INIT: 1 58 | 59 | # Disable central and observer roles. 60 | # STAT_NEWTMGR: 1 61 | # BLEPRPH_LOG_ENABLE: 0 62 | BLE_LL_PRIO: 30 63 | BLE_ROLE_BROADCASTER: 1 64 | BLE_ROLE_CENTRAL: 0 65 | BLE_ROLE_OBSERVER: 0 66 | BLE_ROLE_PERIPHERAL: 1 67 | 68 | syscfg.defs: 69 | PANMASTER_ISSUER: 70 | description: 'Act as panmaster in the network' 71 | value: 0 72 | NRANGES_ANCHOR: 73 | description: 'Act as slave-anchor in the network' 74 | value: 0 75 | NODE_START_SLOT_ID: 76 | description: > 77 | Slot ID from which the nodes should respond 78 | value: 0 79 | NODE_END_SLOT_ID: 80 | description: > 81 | Slot ID till which the nodes should respond 82 | value: 7 83 | 84 | UWB_CCP_TOF_COMP_LOCATION_X: 85 | description: 'x-location of this node in relation to the ccp master' 86 | value: ((float){2.0}) 87 | UWB_CCP_TOF_COMP_LOCATION_Y: 88 | description: 'y-location of this node in relation to the ccp master' 89 | value: ((float){0.0}) 90 | UWB_CCP_TOF_COMP_LOCATION_Z: 91 | description: 'z-location of this node in relation to the ccp master' 92 | value: ((float){0.0}) 93 | 94 | APP_USE_WCS: 95 | description: 'Whether to use WCS or not, setting this to 0 removes the WCS pkg' 96 | value: 1 97 | 98 | syscfg.vals.PANMASTER_ISSUER: 99 | UWBCFG_DEF_ROLE: '"0x7"' 100 | 101 | syscfg.vals.NRANGES_ANCHOR: 102 | UWBCFG_DEF_ROLE: '"0x4"' 103 | NRNG_DEVICE_TYPE: 1 104 | -------------------------------------------------------------------------------- /lib/rtdoa_backhaul/include/rtdoa_backhaul/rtdoa_backhaul.h: -------------------------------------------------------------------------------- 1 | /* 2 | */ 3 | 4 | #ifndef _RTDOA_BACKHAUL_H_ 5 | #define _RTDOA_BACKHAUL_H_ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "rtdoa/rtdoa.h" 13 | #include "rtdoa_tag/rtdoa_tag.h" 14 | 15 | #define GPS_LAT_LONG_ENABLED 0x0001UL 16 | #define UWB_RANGES_ENABLED 0x0002UL 17 | #define SX1280_RANGES_ENABLED 0x0004UL 18 | #define COMPASS_ENABLED 0x0008UL 19 | 20 | #define ACCELEROMETER_ENABLED 0x0010UL 21 | #define GYRO_ENABLED 0x0020UL 22 | #define PRESSURE_ENABLED 0x0040UL 23 | #define BATTERY_LEVELS_ENABLED 0x0080UL 24 | 25 | #define FCNTL_IEEE_RTDOABH 0x88C1 26 | #define DWT_RTDOABH_CODE 0x6003 27 | 28 | struct rtdoabh_sensor_data { 29 | uint64_t ts; /**< timestamp as in master's clock frame (dwt_usecs)*/ 30 | uint16_t sensors_valid:14; /**< Filled in as values arrive */ 31 | uint16_t has_usb_power:1; /**< If power on UWB input > 3V */ 32 | uint16_t is_anchor_data:1; /**< Anchor to anchor ranging */ 33 | float gps_lat; /**< Decimal deg */ 34 | float gps_long; /**< Decimal deg */ 35 | int8_t battery_voltage; /**< steps: 5/128 */ 36 | int16_t pressure; /**< Pa diff from 1013hPa */ 37 | int16_t compass[3]; /**< mG, 6 byte */ 38 | int16_t acceleration[3]; /**< mm/s^2, 6 byte */ 39 | int16_t gyro[3]; /**< 10*deg/s, 6 byte */ 40 | } __attribute__((packed, aligned(1))); // 38 byte 41 | 42 | struct rtdoabh_range_data { 43 | uint16_t anchor_addr; 44 | int32_t diff_dist_mm; 45 | int16_t rssi:14; /**< rssi = -(rssi_float+60)*3 */ 46 | int16_t quality:2; 47 | } __attribute__((packed, aligned(1))); // 8 byte 48 | 49 | struct rtdoabh_tag_results_pkg { 50 | struct _ieee_rng_request_frame_t head; 51 | struct rtdoabh_sensor_data sensors; 52 | uint16_t ref_anchor_addr; 53 | uint8_t num_ranges; 54 | struct rtdoabh_range_data ranges[MYNEWT_VAL(RTDOABH_MAXNUM_RANGES)]; 55 | } __attribute__((packed, aligned(1))); 56 | 57 | typedef enum _rtdoa_backhaul_role_t{ 58 | RTDOABH_ROLE_INVALID, 59 | RTDOABH_ROLE_BRIDGE, // Bridge UWB -> USB / UDP 60 | RTDOABH_ROLE_PRODUCER, 61 | }rtdoa_backhaul_role_t; 62 | 63 | #ifdef __cplusplus 64 | extern "C" { 65 | #endif 66 | 67 | void rtdoa_backhaul_set_a2a(struct uwb_dev * inst); 68 | void rtdoa_backhaul_set_role(struct uwb_dev * inst, rtdoa_backhaul_role_t role); 69 | void rtdoa_backhaul_print(struct rtdoabh_tag_results_pkg *p, bool tight); 70 | int rtdoa_backhaul_sensor_data_cb(struct sensor* sensor, void *arg, void *data, sensor_type_t type); 71 | void rtdoa_backhaul_battery_cb(float battery_volt); 72 | void rtdoa_backhaul_usb_cb(float usb_volt); 73 | void rtdoa_backhaul_set_ts(uint64_t sensor_time); 74 | 75 | struct uwb_dev_status rtdoa_backhaul_send(struct uwb_dev * inst, struct rtdoa_instance *rtdoa, uint64_t dxtime); 76 | int rtdoa_backhaul_queue_size(); 77 | void rtdoa_backhaul_send_imu_only(uint64_t ts); 78 | struct uwb_dev_status rtdoa_backhaul_local(struct uwb_dev * inst, struct rtdoa_instance *rtdoa); 79 | struct uwb_dev_status rtdoa_backhaul_listen(struct uwb_dev * inst, uint64_t dx_time, uint16_t timeout_uus); 80 | #ifdef __cplusplus 81 | } 82 | #endif 83 | 84 | #endif /* _RTDOA_BACKHAUL_H */ 85 | -------------------------------------------------------------------------------- /apps/ota_uwb_master/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "sysinit/sysinit.h" 25 | #include "os/os.h" 26 | #include "bsp/bsp.h" 27 | #include "hal/hal_gpio.h" 28 | #include "hal/hal_bsp.h" 29 | #ifdef ARCH_sim 30 | #include "mcu/mcu_sim.h" 31 | #endif 32 | 33 | #if MYNEWT_VAL(BLE_ENABLED) 34 | #include "bleprph/bleprph.h" 35 | #endif 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | //#define DIAGMSG(s,u) printf(s,u) 43 | #ifndef DIAGMSG 44 | #define DIAGMSG(s,u) 45 | #endif 46 | 47 | static struct os_callout uwb_callout; 48 | 49 | static void 50 | uwb_ev_cb(struct os_event *ev) 51 | { 52 | struct _nmgr_uwb_instance_t *nmgr = (struct _nmgr_uwb_instance_t *)ev->ev_arg; 53 | os_callout_reset(&uwb_callout, OS_TICKS_PER_SEC/25); 54 | 55 | if (uwb_nmgr_process_tx_queue(nmgr, 0) == false) { 56 | return; 57 | } 58 | 59 | uwb_set_rx_timeout(nmgr->dev_inst, 0); 60 | uwb_start_rx(nmgr->dev_inst); 61 | } 62 | 63 | int main(int argc, char **argv){ 64 | int rc; 65 | 66 | sysinit(); 67 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 68 | 69 | #if MYNEWT_VAL(BLE_ENABLED) 70 | ble_init(udev->my_short_address); 71 | #endif 72 | 73 | uint32_t utime = os_cputime_ticks_to_usecs(os_cputime_get32()); 74 | printf("{\"utime\": %lu,\"exec\": \"%s\"}\n",utime,__FILE__); 75 | printf("{\"utime\": %lu,\"msg\": \"device_id = 0x%lX\"}\n",utime,udev->device_id); 76 | printf("{\"utime\": %lu,\"msg\": \"PANID = 0x%X\"}\n",utime,udev->pan_id); 77 | printf("{\"utime\": %lu,\"msg\": \"DeviceID = 0x%X\"}\n",utime,udev->uid); 78 | printf("{\"utime\": %lu,\"msg\": \"partID = 0x%lX\"}\n", 79 | utime,(uint32_t)(udev->euid&0xffffffff)); 80 | printf("{\"utime\": %lu,\"msg\": \"lotID = 0x%lX\"}\n", 81 | utime,(uint32_t)(udev->euid>>32)); 82 | printf("{\"utime\": %lu,\"msg\": \"SHR_duration = %d usec\"}\n",utime, uwb_phy_SHR_duration(udev)); 83 | 84 | struct _nmgr_uwb_instance_t *nmgr = (struct _nmgr_uwb_instance_t *) uwb_mac_find_cb_inst_ptr(udev, UWBEXT_NMGR_UWB); 85 | os_callout_init(&uwb_callout, nmgr_cmds_get_eventq(), uwb_ev_cb, nmgr); 86 | os_callout_reset(&uwb_callout, OS_TICKS_PER_SEC/25); 87 | 88 | uwb_set_rx_timeout(udev, 0); 89 | uwb_start_rx(udev); 90 | 91 | while (1) { 92 | os_eventq_run(os_eventq_dflt_get()); 93 | } 94 | assert(0); 95 | return rc; 96 | } 97 | -------------------------------------------------------------------------------- /apps/ota_uwb_slave/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "sysinit/sysinit.h" 25 | #include "os/os.h" 26 | #include "bsp/bsp.h" 27 | #include "hal/hal_gpio.h" 28 | #include "hal/hal_bsp.h" 29 | #ifdef ARCH_sim 30 | #include "mcu/mcu_sim.h" 31 | #endif 32 | 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | //#define DIAGMSG(s,u) printf(s,u) 41 | #ifndef DIAGMSG 42 | #define DIAGMSG(s,u) 43 | #endif 44 | 45 | #ifndef TICTOC 46 | #undef TICTOC 47 | #endif 48 | 49 | static struct os_callout uwb_callout; 50 | 51 | static void 52 | uwb_ev_cb(struct os_event *ev) { 53 | struct _nmgr_uwb_instance_t *nmgr = (struct _nmgr_uwb_instance_t *)ev->ev_arg; 54 | 55 | if (uwb_nmgr_process_tx_queue(nmgr, 0) != false) { 56 | printf("tx\n"); 57 | os_callout_reset(&uwb_callout, OS_TICKS_PER_SEC/50); 58 | return; 59 | } 60 | nmgr_uwb_listen(nmgr, UWB_BLOCKING, 0, 0xffff); 61 | os_callout_reset(&uwb_callout, OS_TICKS_PER_SEC/50); 62 | } 63 | 64 | int main(int argc, char **argv){ 65 | int rc; 66 | 67 | sysinit(); 68 | hal_gpio_init_out(LED_BLINK_PIN, 1); 69 | hal_gpio_init_out(LED_1, 1); 70 | hal_gpio_init_out(LED_3, 1); 71 | 72 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 73 | 74 | uint32_t utime = os_cputime_ticks_to_usecs(os_cputime_get32()); 75 | printf("{\"utime\": %lu,\"exec\": \"%s\"}\n",utime,__FILE__); 76 | printf("{\"utime\": %lu,\"msg\": \"device_id = 0x%lX\"}\n",utime,udev->device_id); 77 | printf("{\"utime\": %lu,\"msg\": \"PANID = 0x%X\"}\n",utime,udev->pan_id); 78 | printf("{\"utime\": %lu,\"msg\": \"DeviceID = 0x%X\"}\n",utime,udev->uid); 79 | printf("{\"utime\": %lu,\"msg\": \"partID = 0x%lX\"}\n", 80 | utime,(uint32_t)(udev->euid&0xffffffff)); 81 | printf("{\"utime\": %lu,\"msg\": \"lotID = 0x%lX\"}\n", 82 | utime,(uint32_t)(udev->euid>>32)); 83 | printf("{\"utime\": %lu,\"msg\": \"SHR_duration = %d usec\"}\n",utime, uwb_phy_SHR_duration(udev)); 84 | 85 | struct _nmgr_uwb_instance_t *nmgr = (struct _nmgr_uwb_instance_t *) uwb_mac_find_cb_inst_ptr(udev, UWBEXT_NMGR_UWB); 86 | os_callout_init(&uwb_callout, os_eventq_dflt_get(), uwb_ev_cb, nmgr); 87 | os_callout_reset(&uwb_callout, OS_TICKS_PER_SEC/25); 88 | 89 | uwb_set_rx_timeout(udev, 0xffff); 90 | uwb_start_rx(udev); 91 | 92 | while (1) { 93 | os_eventq_run(os_eventq_dflt_get()); 94 | } 95 | assert(0); 96 | return rc; 97 | } 98 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | BUILD_TYPE = Debug 2 | 3 | ifneq ($(shell test -d .git), 0) 4 | GIT_SHORT_HASH:= $(shell git rev-parse --short HEAD) 5 | endif 6 | 7 | VERSION_MAJOR = 1 8 | VERSION_MINOR = 0 9 | VERSION_PATCH = 0 10 | 11 | VERSION = $(VERSION_MAJOR).$(VERSION_MINOR).$(VERSION_PATCH)-$(GIT_SHORT_HASH) 12 | 13 | COMMON_DEFINITIONS = \ 14 | -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \ 15 | -DVERSION_MAJOR=$(VERSION_MAJOR) \ 16 | -DVERSION_MINOR=$(VERSION_MINOR) \ 17 | -DVERSION_PATCH=$(VERSION_PATCH) \ 18 | -DVERSION=$(VERSION) \ 19 | 20 | generic: 21 | rm -R -f build_generic 22 | mkdir build_generic 23 | cd build_generic && cmake -G"Unix Makefiles" \ 24 | $(COMMON_DEFINITIONS) \ 25 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/generic.cmake .. 26 | 27 | cortex-m0: 28 | rm -R -f build_cortex-m0 29 | mkdir build_cortex-m0 30 | cd build_cortex-m0 && cmake -G"Unix Makefiles" \ 31 | $(COMMON_DEFINITIONS) \ 32 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m0.cmake .. 33 | 34 | cortex-m3: 35 | rm -R -f build_cortex-m3 36 | mkdir build_cortex-m3 37 | cd build_cortex-m3 && cmake -G"Unix Makefiles" \ 38 | $(COMMON_DEFINITIONS) \ 39 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m3.cmake .. 40 | 41 | cortex-m4: 42 | rm -R -f build_cortex-m4 43 | mkdir build_cortex-m4 44 | cd build_cortex-m4 && cmake -G"Unix Makefiles" \ 45 | $(COMMON_DEFINITIONS) \ 46 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m4.cmake .. 47 | 48 | cortex-m4f: 49 | rm -R -f build_cortex-m4f 50 | mkdir build_cortex-m4f 51 | cd build_cortex-m4f && cmake -G"Unix Makefiles" \ 52 | $(COMMON_DEFINITIONS) \ 53 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m4f.cmake .. 54 | 55 | cortex-m7: 56 | rm -R -f build_cortex-m7 57 | make build_cortex-m7 58 | cd build_cortex-m7 && cmake -G"Unix Makefiles" \ 59 | $(COMMON_DEFINITIONS) \ 60 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/cortex-m7.cmake .. 61 | 62 | xtensa-lx106: 63 | rm -R -f build_xtensa-lx106 64 | mkdir build_xtensa-lx106 65 | cd build_xtensa-lx106 && cmake -G"Unix Makefiles" \ 66 | $(COMMON_DEFINITIONS) \ 67 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/xtensa-lx106.cmake .. 68 | 69 | arm64: 70 | rm -R -f build_arm64 71 | mkdir build_arm64 72 | cd build_arm64 && cmake -G"Unix Makefiles" \ 73 | $(COMMON_DEFINITIONS) \ 74 | -DCMAKE_TOOLCHAIN_FILE=../toolchain/arm64.cmake .. 75 | 76 | xcode: 77 | rm -R -f xcode 78 | mkdir xcode 79 | cd xcode && cmake -G"Xcode" \ 80 | $(COMMON_DEFINITIONS) .. 81 | 82 | eclipse: 83 | rm -R -f build 84 | mkdir build 85 | cd build && cmake -G"Eclipse CDT4 - Unix Makefiles" \ 86 | $(COMMON_DEFINITIONS) .. 87 | 88 | visual: 89 | rm -R -f visualstudio:wq 90 | mkdir visualstudio 91 | cd visualstudio && cmake -G”Visual Studio 10 Win64" \ 92 | $(COMMON_DEFINITIONS) .. 93 | 94 | lib_only: 95 | rm -R -f build_lib_only 96 | mkdir build_lib_only 97 | cd build_lib_only && cmake $(COMMON_DEFINITIONS) -DLIB_ONLY=TRUE .. 98 | 99 | all: generic cortex-m0 cortex-m3 cortex-m4 lib_only 100 | 101 | clean: 102 | rm -R -f build_* 103 | rm -R -f ext_images 104 | rm -R -f xcode 105 | 106 | unpack_images: 107 | rm -R -f ext_images 108 | 7z x ext_images.7z 109 | 110 | -------------------------------------------------------------------------------- /apps/rtdoa_tag/README.md: -------------------------------------------------------------------------------- 1 | # RTDoA 2 | 3 | ## To upload a new firmware through BLE: 4 | 5 | 1. Download the new firmware (file ending in .img) onto your iphone/ipad and save it in “Files”. 6 | Making sure to change the file-suffix to either txt or png (otherwise ios will not show it) 7 | You can do this by either emailing it to yourself and on the phone saving it to Files or using airdrop. 8 | 2. open the Mynewt Manager app and connect to the board of choice. 9 | 3. enter the Images tab and select “Upload a custom image” 10 | 4. select browse and navigate to the file you saved in step 1. For example rtdoa_node_0_1_0_1.txt. 11 | Uploading will take a minute or two. 12 | 5. once uploaded, the Image slots will update with the new image you uploaded. 13 | 6. select the new image in the list and click “Test”. The app will ask you for confirmation and reset the board. 14 | The board will disconnect. 15 | 7. the board will now swap the two images. Note, this will take 20-50s. 16 | 8. reconnect to the board and enter the images tab again. 17 | 9. if successful, select the image with the new firmware, shown as “Main slot – Testing” and select confirm. 18 | This will ensure that the board will not swap back to the old firmware next time it reboots. 19 | The board will reset again and swap the two images if there's a problem. 20 | 21 | Note that if the update fails for some reason the board will revert to the old firmware. 22 | 23 | ## Serial Connection 24 | 25 | The board comes up as a USB serial port. The settings you need to use are 1000000bps 8-n-1. 26 | 27 | ## Creating a master node 28 | 29 | A rtdoa network needs a master node and 1 or more slave nodes. All nodes are by default setup as slaves. 30 | To configure a node as a master you connect over the serial port and issue the following commands: 31 | 32 | ``` 33 | 34 | config ntwr/role 0x1 35 | config save 36 | config commit 37 | 38 | ``` 39 | 40 | You can then check that it worked by using the following command: 41 | 42 | ``` 43 | config dump 44 | ``` 45 | 46 | which will give you a whole list of parameters. Look and verify that the ntwr/role is set to 1 or 0x1. 47 | 48 | NOTE: Only one node can be master, the others have to be slaves (0x0 or 0) 49 | 50 | ## Listing nodes in the current network 51 | 52 | On the master node, issue the command ```panm list``` over the usb. A list of the nodes connected to this master will show. 53 | If using the command ```tdb list``` instead, a list of nodes and their distance to the master should show. 54 | 55 | ## Tag data 56 | 57 | The tag outputs data on it's local usb in json format like below: 58 | 59 | {"id":"0x499b","ts":"2473.4125","msgid":50196,"vbat":"4.29","usb":1, 60 | "acc":"[0.254,-8.345,-5.99]","gyro":"[0.5,0.3,0.4]","mag":[-548,140,-373],"pres":102072, 61 | "ref_anchor":"492","meas":[{"addr":"492","ddist":"0.005","tqf":1,"rssi":"-82.8"},{"addr":"533","ddist":"0.698","tqf":1,"rssi":"-79.9"}]} 62 | 63 | The fields are: 64 | id The local tag's own 16-bit id 65 | ts Timestamp relative the master node. 66 | msgid A number increasing with every message sent until the board resets 67 | vbat If a lipo is connected this field will show it's voltage level otherwise it'll show a value of about 4.30V. 68 | usb 1 indicates that the board has usb power 69 | acc Accelerometer (m/s^2) 70 | gyro dps (Degrees per second) 71 | mag Magnetometer / Compass (uT) 72 | pres Air-pressure in Pa 73 | ref_anchor The reference anchor used for the rtdoa sequence. This is the base for the difference of distances. 74 | meas Vector of rtdoa measurements 75 | addr Address of node 76 | ddist difference in distance between this node and the reference anchor 77 | tfq quality of the measurement (only 1 or 0 at the moment, estimation of Line of Sight) 78 | rssi Receiver strength of signal from this anchor 79 | 80 | -------------------------------------------------------------------------------- /apps/listener/README.md: -------------------------------------------------------------------------------- 1 | # UWB sniffer / listener 2 | 3 | ## Overview 4 | This example is really a very useful tool for assisting you develop UWB applications. It allows you to monitor the traffic and get accurate 5 | timestamps for each package. 6 | 7 | ### Building target for dwm1001 8 | 9 | ```no-highlight 10 | newt target create dwm1001_listener 11 | newt target set dwm1001_listener app=apps/listener 12 | newt target set dwm1001_listener bsp=@decawave-uwb-core/hw/bsp/dwm1001 13 | newt target amend dwm1001_listener syscfg=CONSOLE_UART_BAUD=115200 14 | newt run dwm1001_listener 0 15 | ``` 16 | 17 | ### Building listener for dwm3120 on ST nucleo 18 | 19 | ```no-highlight 20 | newt target create dwm3120_listener 21 | newt target set dwm3120_listener app=apps/listener 22 | newt target set dwm3120_listener bsp=@decawave-uwb-core/hw/bsp/nucleo-f429zi 23 | newt target amend dwm3120_listener syscfg=CONSOLE_UART_BAUD=115200:BLE_ENABLED=0 24 | newt run dwm3120_listener 0 25 | ``` 26 | 27 | 28 | If you connect to the virtual serial port, on linux /dev/ttyACMx where x is a number assigned by your computer, you should 29 | see json packaged coming similar to the ones below if you have UWB traffic within range of the dwm1001: 30 | ``` 31 | $ socat /dev/ttyACM0,b115200,raw,echo=0,nonblock $(tty),raw,echo=0,escape=0x03 32 | 33 | {"utime":32240936,"ts":959949481290,"rssi":-84.0,"dlen":30,"d":"c5939204b2cf86c102049204000000000400000050c03791490713000004"} 34 | {"utime":32509826,"ts":977129894189,"rssi":-84.1,"dlen":30,"d":"c5949204b2cf86c1020492040000000004000000500038914d0713000004"} 35 | ``` 36 | 37 | The fields are: 38 | 39 | - utime: Microcontroller time, usec 40 | - ts0: uwb timestamp 41 | - rssi: estimated received signal strength in dBm 42 | - dlen: length of data packet 43 | - d: data in hexadecimal 44 | 45 | 46 | ### Building target for dwm1002 47 | 48 | The dwm1002 has the advantage of having two receivers and can thus extract information about the phase difference to estimate 49 | a direction to the incoming packet. In the example below all this data (and more) is included in the json stream. 50 | 51 | ```no-highlight 52 | newt target create dwm1002_listener 53 | newt target set dwm1002_listener app=apps/listener 54 | newt target set dwm1002_listener bsp=@decawave-uwb-core/hw/bsp/dwm1002 55 | newt target amend dwm1002_listener syscfg=CONSOLE_UART_BAUD=460800:UWB_DEVICE_0=1:UWB_DEVICE_1=1:CIR_ENABLED=1:USE_DBLBUFFER=0 56 | newt run dwm1002_listener 0 57 | ``` 58 | 59 | If you connect to the virtual serial port, on linux /dev/ttyACMx where x is a number assigned by your computer, you should 60 | see json packaged coming similar to the ones below if you have UWB traffic within range of the dwm1001: 61 | ``` 62 | $ socat /dev/ttyACM0,b460800,raw,echo=0,nonblock - 63 | 64 | {"utime":3219787,"ts":[203624381252,203624381278],"rssi":[-80.5,-81.3],"fppl":[-84.5,-85.3],"pd":[1.267],"dlen":30,"d":"c5439204b2cf86c102049204000000000400000050c0639c09ba13000004","cir0":{"o":6,"fp_idx":745.187,"rcphase":1.030,"angle":2.588,"real":[92,2,79,127,-36,-429,-2656,-6108,-6876,-5448,1261,4428,1492,-1380,-1113,275],"imag":[-172,-82,37,61,35,232,1641,3090,2532,-642,-4520,-3425,470,2132,467,-806]},"cir1":{"o":6,"fp_idx":745.593,"rcphase":0.932,"angle":1.222,"real":[-164,1,111,36,16,619,1620,312,-3040,-3991,-948,1312,717,-467,-372,165],"imag":[-89,-140,-6,85,102,1132,4460,6440,5022,-1016,-4559,-1405,2121,1369,-1023,-1252]}} 65 | 66 | ``` 67 | 68 | The fields are: 69 | 70 | - utime: Microcontroller time, usec 71 | - ts: [uwb_0 timestamp 72 | - ts1: uwb_1 timestamp 73 | - rssi0: estimated received signal strength in dBm for receiver 0 74 | - rssi1: estimated received signal strength in dBm for receiver 1 75 | - pd: estimated phase difference in radians 76 | - cir0: accumulator data for receiver 0 77 | - o: offset relative detected leading edge (how many samples before the edge to extract) 78 | - fp_idx: leading edge location in accumulator (floating point) 79 | - cir1: accumulator data for receiver 1 80 | - dlen: length of data packet 81 | - d: data in hexadecimal 82 | 83 | ### Building target for ttk1000 84 | 85 | The ttk1000 can broadcast the UWB results as UDP packets on the local network. 86 | 87 | ```no-highlight 88 | newt target create ttk1000_listener 89 | newt target set ttk1000_listener app=apps/listener 90 | newt target set ttk1000_listener bsp=@decawave-uwb-core/hw/bsp/ttk1000 91 | newt target amend ttk1000_listener syscfg=CONSOLE_UART_BAUD=460800:UWB_DEVICE_0=1:USE_DBLBUFFER=1 92 | newt run ttk1000_listener 0 93 | ``` 94 | -------------------------------------------------------------------------------- /apps/twr_aloha/README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # Decawave TWR_ALOHA Example 23 | 24 | ## Overview 25 | 26 | WIP 27 | 28 | 1. To erase the default flash image that shipped with the DWM1001 boards. 29 | 30 | ```no-highlight 31 | $ JLinkExe -device nRF52 -speed 4000 -if SWD 32 | J-Link>erase 33 | J-Link>exit 34 | $ 35 | ``` 36 | 37 | 2. On 1st dwm1001-dev board build the node application for the DWM1001 module. 38 | 39 | ```no-highlight 40 | 41 | newt target create twr_node 42 | newt target set twr_node app=apps/twr_aloha 43 | newt target set twr_node bsp=@decawave-uwb-core/hw/bsp/dwm1001 44 | newt target set twr_node build_profile=debug 45 | newt target amend twr_node syscfg=LOG_LEVEL=1:UWBCFG_DEF_ROLE='"0x4"' 46 | newt run twr_node 0 47 | 48 | ``` 49 | 50 | 3. On 2nd dwm1001-dev board build the tag application for the DWM1001 module. 51 | 52 | ```no-highlight 53 | 54 | newt target create twr_tag 55 | newt target set twr_tag app=apps/twr_aloha 56 | newt target set twr_tag bsp=@decawave-uwb-core/hw/bsp/dwm1001 57 | newt target set twr_tag build_profile=debug 58 | newt run twr_tag 0 59 | 60 | ``` 61 | 62 | 4. On the console you should see the following expected result. 63 | 64 | Use telnet or nc if you are using CONSOLE_RTT: 1 in syscfg.yml 65 | Or screen or socat if you are using CONSOLE_UART: 1 in syscfg.yml 66 | 67 | For Human readable JSON you can use add FLOAT_USER 68 | ```no-highlight 69 | newt target amend twr_node syscfg=FLOAT_USER=1 70 | ``` 71 | 72 | ```no-highlight 73 | 74 | telnet localhost 19021 75 | .... 76 | {"utime": 23859733,"tof": 1101004815,"range": 1036004551,"azimuth": 0,"res_req":"6003EB0", "rec_tra": "6003E60"} 77 | {"utime": 23873159,"tof": 1099956214,"range": 1034745086,"azimuth": 0,"res_req":"6004092", "rec_tra": "600403A"} 78 | {"utime": 23879880,"tof": 1102053369,"range": 1037263961,"azimuth": 0,"res_req":"6003F78", "rec_tra": "6003F1E"} 79 | .... 80 | {"utime": 23920210,"tof": 1104150538,"range": 1039782852,"azimuth": 0,"res_req":"6003EFB", "rec_tra": "6003E97"} 81 | {"utime": 23926932,"tof": 1098383319,"range": 1033170778,"azimuth": 0,"res_req":"6003FE2", "rec_tra": "6003F92"} 82 | {"utime": 23933653,"tof": 1099825167,"range": 1034587686,"azimuth": 0,"res_req":"6003ECB", "rec_tra": "6003E76"} 83 | 84 | ``` 85 | 86 | 87 | See the ./matlab/stats.m script for an example of parsing json strings. 88 | 89 | 5. Trying different ranging algorithms 90 | 91 | The method for ranging used is selected by modifying the mode variable in the uwb_ev_cb 92 | function in main.c. By default, it will use one of the modes available and setting the 93 | ```mode``` variable accordingly. By editing main you can select another mode if that 94 | is available: 95 | 96 | ``` 97 | ...// around line 166 in src/main.c 98 | /* Uncomment the next line to force the range mode */ 99 | // mode = UWB_DATA_CODE_SS_TWR_ACK; 100 | ... 101 | ``` 102 | 103 | ## Using DW3000 as node and tag on ST nucleo 104 | 105 | ```no-highlight 106 | newt target create nucleo-f429zi_twr_aloha_tag 107 | newt target set nucleo-f429zi_twr_aloha_tag app=apps/twr_aloha 108 | newt target set nucleo-f429zi_twr_aloha_tag bsp=@decawave-uwb-core/hw/bsp/nucleo-f429zi 109 | newt target set nucleo-f429zi_twr_aloha_tag build_profile=debug 110 | newt target amend nucleo-f429zi_twr_aloha_tag syscfg=BLE_ENABLED=0:CONSOLE_UART=1:CONSOLE_RTT=0 111 | newt run nucleo-f429zi_twr_aloha_tag 0 112 | ``` 113 | ```no-highlight 114 | newt target create nucleo-f429zi_twr_aloha_node 115 | newt target set nucleo-f429zi_twr_aloha_node app=apps/twr_aloha 116 | newt target set nucleo-f429zi_twr_aloha_node bsp=@decawave-uwb-core/hw/bsp/nucleo-f429zi 117 | newt target set nucleo-f429zi_twr_aloha_node build_profile=debug 118 | newt target amend nucleo-f429zi_twr_aloha_node syscfg=LBLE_ENABLED=0:LOG_LEVEL=1:UWBCFG_DEF_ROLE='"0x4"':CONSOLE_UART=1:CONSOLE_RTT=0 119 | newt run nucleo-f429zi_twr_aloha_node 0 120 | ``` -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # Decawave UWB Applications 23 | [![Build Status](https://travis-ci.org/Decawave/uwb-apps.svg?branch=master)](https://travis-ci.org/Decawave/uwb-apps) 24 | 25 | ## Overview 26 | 27 | This distribution contains the example applications for the DW1000 UWB transceiver. 28 | 29 | ## Getting hardware 30 | 31 | * DWM1001 from https://www.decawave.com/products/dwm1001-module 32 | * lps2mini from https://lohmega.com 33 | 34 | ## Getting started 35 | 36 | The remainder of this README.md shows how to bring up the elementary twr_node/twr_tag examples. 37 | 38 | 1. Download and install Apache Newt. 39 | 40 | You will need to download the Apache Newt tool, as documented in the [Getting Started Guide](http://mynewt.apache.org/latest/get_started/index.html). 41 | 42 | Prerequisites: You should follow the generic tutorials at http://mynewt.apache.org/latest/tutorials/tutorials.html, particularly the basic Blinky example that will guide you through the basic setup. 43 | 44 | 2. Download the UWB apps repository. 45 | 46 | ```no-highlight 47 | git clone git@github.com:Decawave/uwb-apps.git 48 | cd uwb-apps 49 | ``` 50 | 51 | 3. Running the ```newt upgrade``` command downloads the apache-mynewt-core, decawave-uwb-core, decawave-uwb-dwXXXX driver(s) repo, and mynewt-timescale-lib packages, these are dependent repos of the decawave-uwb-apps project and are automatically checked-out by the newt tools. 52 | 53 | ```no-highlight 54 | $ newt upgrade 55 | # Depending on what version of the newt tool you use you 56 | # may have to manually remove git-but artifacts and then rerun 57 | # upgrade. I.e. only if you see an error like: 58 | # "Error: Error updating "mcuboot"..." do: 59 | rm repos/mcuboot/ext/mbedtls/include/mbedtls/ -rf 60 | newt upgrade 61 | ``` 62 | 63 | To see if you have access to other driver repos, run the setup.sh 64 | script under repos/decawave-uwb-core like so: 65 | 66 | ``` 67 | repos/decawave-uwb-core/setup.sh 68 | # Rerun newt install 69 | newt install 70 | ``` 71 | 72 | Apply any patches to apache-mynewt-core: 73 | 74 | ``` 75 | cd repos/apache-mynewt-core/ 76 | git apply ../decawave-uwb-core/patches/apache-mynewt-core/mynewt_1_7_0_* 77 | cd - 78 | ``` 79 | 80 | 4. To erase the default flash image that shipped with the DWM1001. 81 | 82 | ```no-highlight 83 | $ JLinkExe -device nRF52 -speed 4000 -if SWD 84 | J-Link>erase 85 | J-Link>exit 86 | $ 87 | ``` 88 | 89 | or if you have nrfjprog ([Nordic Cmd Tools](https://www.nordicsemi.com/Software-and-tools/Development-Tools/nRF-Command-Line-Tools/Download)) installed: 90 | 91 | ``` 92 | $ nrfjprog -f NRF52 -e 93 | ``` 94 | 95 | 96 | 5. Build the new bootloader applicaiton for the DWM1001 target. 97 | 98 | (executed from the mynewt-dw1000-app directory). 99 | 100 | ```no-highlight 101 | 102 | newt target create dwm1001_boot 103 | newt target set dwm1001_boot app=@mcuboot/boot/mynewt 104 | newt target set dwm1001_boot bsp=@decawave-uwb-core/hw/bsp/dwm1001 105 | newt target set dwm1001_boot build_profile=optimized 106 | newt build dwm1001_boot 107 | newt load dwm1001_boot 108 | 109 | ``` 110 | 111 | 6. On the first DWM1001-DEV board build the Two-Way-Ranging (twr_tag_tdma) application for the DWM1001 module. The run command compiles the project and loads the image on the target platform. 112 | 113 | (executed from the decawave-uwb-apps directory). 114 | 115 | ```no-highlight 116 | 117 | newt target create twr_tag_tdma 118 | newt target set twr_tag_tdma app=apps/twr_tag_tdma 119 | newt target set twr_tag_tdma bsp=@decawave-uwb-core/hw/bsp/dwm1001 120 | newt target set twr_tag_tdma build_profile=debug 121 | newt run twr_tag_tdma 0 122 | 123 | ``` 124 | 125 | 7. On a second DWM1001-DEV board build the node side of the Two-Way-Ranging (twr_node_tdma) application as follows. 126 | 127 | (executed from the decawave-uwb-apps directory). 128 | 129 | ```no-highlight 130 | 131 | newt target create twr_node_tdma 132 | newt target set twr_node_tdma app=apps/twr_node_tdma 133 | newt target set twr_node_tdma bsp=@decawave-uwb-core/hw/bsp/dwm1001 134 | newt target set twr_node_tdma build_profile=debug 135 | newt target amend twr_node_tdma syscfg=LOG_LEVEL=1:UWBCFG_DEF_ROLE='"0x1"' 136 | newt run twr_node_tdma 0 137 | 138 | ``` 139 | 140 | 141 | 8. Both examples are configured to use the Segger RTT console interface. This is covered within the mynewt tutorials/Tooling/SeggerRTT (http://mynewt.apache.org/latest/tutorials/tooling/segger_rtt.html). To launch the console simply telnet localhost 19021. Note at time of writing the newt tools does not support multiple connect dwm1001-dev devices. So it is recomended that you connect twr_tag_tdma and twr_node_tdma examples to different computers or at least the twr_tag_tdma to an external battery. If all goes well you should see the twr_node_tdma example stream range information on the console. 142 | 143 | (executed from the decawave-uwb-apps directory). 144 | 145 | ```no-highlight 146 | 147 | nc localhost 19021 148 | 149 | ``` 150 | -------------------------------------------------------------------------------- /apps/ota_uwb_master/README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # Decawave OTA over BLE Example 23 | 24 | ## Overview 25 | ```no-highlight 26 | 27 | The ota_uwb_master & ota_uwb_slave are simple examples that facilitates the image upgrade over air using UWB with a CLI. 28 | 29 | To run the below applications which are configured with UART, change the pins in hw/bsp/dwm1001/syscfg.yml 30 | 31 | 1. To erase the default flash image that shipped with the DWM1001 boards. 32 | 33 | $ JLinkExe -device nRF52 -speed 4000 -if SWD 34 | J-Link>erase 35 | J-Link>exit 36 | $ 37 | ``` 38 | ```no-highlight 39 | 2. On 1st dwm1001-dev board build the ota_uwb_master applications for the DWM1001 module. 40 | 41 | newt target create master 42 | newt target set master app=apps/ota_uwb_master 43 | newt target set master bsp=@decawave-uwb-core/hw/bsp/dwm1001 44 | newt target set master build_profile=optimized 45 | newt target amend master syscfg="LOG_LEVEL=1" 46 | newt build master 47 | newt create-image master 1.0.0 48 | newt load master 49 | ``` 50 | ```no-highlight 51 | 3. On 2nd dwm1001-dev board build the ota_uwb_slave applications for the DWM1001 module. 52 | 53 | newt target create slave 54 | newt target set slave app=apps/ota_uwb_slave 55 | newt target set slave bsp=@decawave-uwb-core/hw/bsp/dwm1001 56 | newt target set slave build_profile=optimized 57 | newt target amend slave syscfg="LOG_LEVEL=1" 58 | newt build slave 59 | newt create-image slave 1.0.0 60 | newt load slave 61 | ``` 62 | 63 | #i## How to test 64 | 65 | 1. Upload the image that needs to be sent to slave node using BLE to the master node 66 | 67 | ### Create a newtmgr connection profile 68 | ``` 69 | newtmgr conn add ble type=ble connstring="peer_name=DECA-4321" (ota_uwb_master) 70 | 71 | ``` 72 | ## check whether newtmgr can communicate and check image status of the device 73 | ``` 74 | newtmgr image list -c ble 75 | 76 | ``` 77 | With the above command, you get the image slots of the device 78 | 79 | ## Create a the image of interest 80 | ``` 81 | newt create-image slave 2.0.0 82 | ``` 83 | ### Uploading an image to device 84 | ``` 85 | newtmgr image upload -c ble /path of the image created in bin file/ 86 | 87 | ``` 88 | ## check for image status 89 | ``` 90 | newtmgr image list -c ble 91 | 92 | ``` 93 | Now, you get status of primary and secondary slots with 2 different versioned images. 94 | 95 | 2. Once the required image has been uploaded in the second slot start the upload of this image to slave node 96 | ### check whether master can talk to slave 97 | ``` 98 | img_list 0x1234 (Slave node address) 99 | Should get some logs like this 100 | slot = 0 101 | Version = 0.0.0 102 | bootable : true 103 | Flags : active confirmed 104 | 7b6af13ca48f82fe22e009393779a3100458c2dc99e4e86ea38922c0aec5380a 105 | 106 | With the above commands, you get the image slots of both the devices. 107 | ``` 108 | ### Uploading an image to device 109 | ``` 110 | img_upload slot2 0x1234 (Slave node address) 111 | 112 | ``` 113 | ### check for image status 114 | ``` 115 | img_list 0x1234 (Slave node address) 116 | Should get some logs like this 117 | Slot = 0 118 | Version = 1.0.0 119 | bootable : true 120 | Flags : active confirmed 121 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 122 | 123 | Slot = 1 124 | Version = 1.0.0 125 | bootable : true 126 | Flags : 127 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 128 | ``` 129 | Now, you get status of primary and secondary slots with 2 different versioned images. 130 | ### Test the image 131 | ``` 132 | img_set_state test 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7(32 byte hash of testing image) 0x1234(Slave node address) 133 | Should get some logs like this 134 | Slot = 0 135 | Version = 1.0.0 136 | bootable : true 137 | Flags : active confirmed 138 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 139 | 140 | Slot = 1 141 | Version = 1.0.0 142 | bootable : true 143 | Flags : pending 144 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 145 | ``` 146 | Now the images of secondary slot goes to pending state. 147 | 148 | **NOTE:** Then power OFF and ON the slave node. 149 | 150 | Once the device boots up 151 | ## Check for image status 152 | ``` 153 | img_list 0x1234 (Slave node address) 154 | Slot = 0 155 | Version = 1.0.0 156 | bootable : true 157 | Flags : active 158 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 159 | 160 | Slot = 1 161 | Version = 1.0.0 162 | bootable : true 163 | Flags : confirmed 164 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 165 | ``` 166 | After this, the uploaded image becomes active and will be running in primary slot. 167 | ### Confirming the image 168 | ``` 169 | img_set_state confirm 0x1234 (Slave node address) 170 | ``` 171 | Should get some logs like this 172 | 173 | ``` 174 | Slot = 0 175 | Version = 1.0.0 176 | bootable : true 177 | Flags : active confirmed 178 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 179 | 180 | Slot = 1 181 | Version = 1.0.0 182 | bootable : true 183 | Flags : 184 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 185 | ``` 186 | 187 | -------------------------------------------------------------------------------- /apps/ota_uwb_slave/README.md: -------------------------------------------------------------------------------- 1 | 21 | 22 | # Decawave OTA over BLE Example 23 | 24 | ## Overview 25 | ```no-highlight 26 | 27 | The ota_uwb_master & ota_uwb_slave are simple examples that facilitates the image upgrade over air using UWB with a CLI. 28 | 29 | To run the below applications which are configured with UART, change the pins in hw/bsp/dwm1001/syscfg.yml 30 | 31 | 1. To erase the default flash image that shipped with the DWM1001 boards. 32 | 33 | $ JLinkExe -device nRF52 -speed 4000 -if SWD 34 | J-Link>erase 35 | J-Link>exit 36 | $ 37 | ``` 38 | ```no-highlight 39 | 2. On 1st dwm1001-dev board build the ota_uwb_master applications for the DWM1001 module. 40 | 41 | newt target create master 42 | newt target set master app=apps/ota_uwb_master 43 | newt target set master bsp=@decawave-uwb-core/hw/bsp/dwm1001 44 | newt target set master build_profile=optimized 45 | newt target amend master syscfg="LOG_LEVEL=1" 46 | newt build master 47 | newt create-image master 1.0.0 48 | newt load master 49 | ``` 50 | ```no-highlight 51 | 3. On 2nd dwm1001-dev board build the ota_uwb_slave applications for the DWM1001 module. 52 | 53 | newt target create slave 54 | newt target set slave app=apps/ota_uwb_slave 55 | newt target set slave bsp=@decawave-uwb-core/hw/bsp/dwm1001 56 | newt target set slave build_profile=optimized 57 | newt target amend slave syscfg="LOG_LEVEL=1" 58 | newt build slave 59 | newt create-image slave 1.0.0 60 | newt load slave 61 | ``` 62 | 63 | #i## How to test 64 | 65 | 1. Upload the image that needs to be sent to slave node using BLE to the master node 66 | 67 | ### Create a newtmgr connection profile 68 | ``` 69 | newtmgr conn add ble type=ble connstring="peer_name=DECA-4321" (ota_uwb_master) 70 | 71 | ``` 72 | ## check whether newtmgr can communicate and check image status of the device 73 | ``` 74 | newtmgr image list -c ble 75 | 76 | ``` 77 | With the above command, you get the image slots of the device 78 | 79 | ## Create a the image of interest 80 | ``` 81 | newt create-image slave 2.0.0 82 | ``` 83 | ### Uploading an image to device 84 | ``` 85 | newtmgr image upload -c ble /path of the image created in bin file/ 86 | 87 | ``` 88 | ## check for image status 89 | ``` 90 | newtmgr image list -c ble 91 | 92 | ``` 93 | Now, you get status of primary and secondary slots with 2 different versioned images. 94 | 95 | 2. Once the required image has been uploaded in the second slot start the upload of this image to slave node 96 | ### check whether master can talk to slave 97 | ``` 98 | img_list 0x1234 (Slave node address) 99 | Should get some logs like this 100 | slot = 0 101 | Version = 0.0.0 102 | bootable : true 103 | Flags : active confirmed 104 | 7b6af13ca48f82fe22e009393779a3100458c2dc99e4e86ea38922c0aec5380a 105 | 106 | With the above commands, you get the image slots of both the devices. 107 | ``` 108 | ### Uploading an image to device 109 | ``` 110 | img_upload slot2 0x1234 (Slave node address) 111 | 112 | ``` 113 | ### check for image status 114 | ``` 115 | img_list 0x1234 (Slave node address) 116 | Should get some logs like this 117 | Slot = 0 118 | Version = 1.0.0 119 | bootable : true 120 | Flags : active confirmed 121 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 122 | 123 | Slot = 1 124 | Version = 1.0.0 125 | bootable : true 126 | Flags : 127 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 128 | ``` 129 | Now, you get status of primary and secondary slots with 2 different versioned images. 130 | ### Test the image 131 | ``` 132 | img_set_state test 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7(32 byte hash of testing image) 0x1234(Slave node address) 133 | Should get some logs like this 134 | Slot = 0 135 | Version = 1.0.0 136 | bootable : true 137 | Flags : active confirmed 138 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 139 | 140 | Slot = 1 141 | Version = 1.0.0 142 | bootable : true 143 | Flags : pending 144 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 145 | ``` 146 | Now the images of secondary slot goes to pending state. 147 | 148 | **NOTE:** Then power OFF and ON the slave node. 149 | 150 | Once the device boots up 151 | ## Check for image status 152 | ``` 153 | img_list 0x1234 (Slave node address) 154 | Slot = 0 155 | Version = 1.0.0 156 | bootable : true 157 | Flags : active 158 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 159 | 160 | Slot = 1 161 | Version = 1.0.0 162 | bootable : true 163 | Flags : confirmed 164 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 165 | ``` 166 | After this, the uploaded image becomes active and will be running in primary slot. 167 | ### Confirming the image 168 | ``` 169 | img_set_state confirm 0x1234 (Slave node address) 170 | ``` 171 | Should get some logs like this 172 | 173 | ``` 174 | Slot = 0 175 | Version = 1.0.0 176 | bootable : true 177 | Flags : active confirmed 178 | 76609ae104fd47f74413d1c39501569605a12c2d17f17922cc3e417448244ab7 179 | 180 | Slot = 1 181 | Version = 1.0.0 182 | bootable : true 183 | Flags : 184 | 6479df5a957bf7fa2e9b45e075788fd91e3fb15895affee06ff3b9cb4e546645 185 | ``` 186 | 187 | -------------------------------------------------------------------------------- /CODING_STANDARDS.md: -------------------------------------------------------------------------------- 1 | # Coding Style for Apache Mynewt Core 2 | 3 | This document is meant to define the coding style for Apache Mynewt, and 4 | all subprojects of Apache Mynewt. This covers C and Assembly coding 5 | conventions, *only*. Other languages (such as Go), have their own 6 | coding conventions. 7 | 8 | ## Headers 9 | 10 | * All files that are newly written, should have the Apache License clause 11 | at the top of them. 12 | 13 | * For files that are copied from another source, but contain an Apache 14 | compatible license, the original license header shall be maintained. 15 | 16 | * For more information on applying the Apache license, the definitive 17 | source is here: http://www.apache.org/dev/apply-license.html 18 | 19 | * The Apache License clause for the top of files is as follows: 20 | 21 | ```no-highlight 22 | /* 23 | * Licensed to the Apache Software Foundation (ASF) under one 24 | * or more contributor license agreements. See the NOTICE file 25 | * distributed with this work for additional information 26 | * regarding copyright ownership. The ASF licenses this file 27 | * to you under the Apache License, Version 2.0 (the 28 | * "License"); you may not use this file except in compliance 29 | * with the License. You may obtain a copy of the License at 30 | * 31 | * http://www.apache.org/licenses/LICENSE-2.0 32 | * 33 | * Unless required by applicable law or agreed to in writing, 34 | * software distributed under the License is distributed on an 35 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 36 | * KIND, either express or implied. See the License for the 37 | * specific language governing permissions and limitations 38 | * under the License. 39 | */ 40 | ``` 41 | 42 | ## Whitespace and Braces 43 | 44 | * Code must be indented to 4 spaces, tabs should not be used. 45 | 46 | * Do not add whitespace at the end of a line. 47 | 48 | * Put space after keywords (for, if, return, switch, while). 49 | 50 | * for, else, if, while statements must have braces around their 51 | code blocks, i.e., do: 52 | 53 | ``` 54 | if (x) { 55 | assert(0); 56 | } else { 57 | assert(0); 58 | } 59 | ``` 60 | 61 | Not: 62 | 63 | ``` 64 | if (x) 65 | assert(0); 66 | else 67 | assert(0); 68 | ``` 69 | 70 | * Braces for statements must be on the same line as the statement. Good: 71 | 72 | ``` 73 | for (i = 0; i < 10; i++) { 74 | if (i == 5) { 75 | break; 76 | } else { 77 | continue; 78 | } 79 | } 80 | ``` 81 | 82 | Not: 83 | 84 | ``` 85 | for (i = 0; i < 10; i++) 86 | { <-- brace must be on same line as for 87 | if (i == 5) { 88 | break; 89 | } <-- no new line between else 90 | else { 91 | continue; 92 | } 93 | } 94 | ``` 95 | 96 | * After a function declaration, the braces should be on a newline, i.e. do: 97 | 98 | ``` 99 | static void * 100 | function(int var1, int var2) 101 | { 102 | ``` 103 | 104 | not: 105 | 106 | ``` 107 | static void * 108 | function(int var1, int var2) { 109 | ``` 110 | 111 | ## Line Length and Wrap 112 | 113 | * Line length should never exceed 79 columns. 114 | 115 | * When you have to wrap a long statement, put the operator at the end of the 116 | line. i.e.: 117 | 118 | ``` 119 | if (x && 120 | y == 10 && 121 | b) 122 | ``` 123 | 124 | Not: 125 | 126 | ``` 127 | if (x 128 | && y == 10 129 | && b) 130 | ``` 131 | 132 | ## Comments 133 | 134 | * No C++ style comments allowed. 135 | 136 | * When using a single line comment, put it above the line of code that you 137 | intend to comment, i.e., do: 138 | 139 | ``` 140 | /* check variable */ 141 | if (a) { 142 | ``` 143 | 144 | Not: 145 | 146 | ``` 147 | if (a) { /* check variable */ 148 | ``` 149 | 150 | 151 | * All public APIs should be commented with Doxygen style comments describing 152 | purpose, parameters and return values. Private APIs need not be documented. 153 | 154 | 155 | ## Header files 156 | 157 | * Header files must contain the following structure: 158 | * Apache License (see above) 159 | * ```#ifdef``` aliasing, to prevent multiple includes 160 | * ```#include``` directives for other required header files 161 | * ```#ifdef __cplusplus``` wrappers to maintain C++ friendly APIs 162 | * Contents of the header file 163 | 164 | * ```#ifdef``` aliasing, shall be in the following format, where 165 | the package name is "os" and the file name is "callout.h": 166 | 167 | ```no-highlight 168 | #ifndef _OS_CALLOUT_H 169 | #define _OS_CALLOUT_H 170 | ``` 171 | 172 | * ```#include``` directives must happen prior to the cplusplus 173 | wrapper. 174 | 175 | * The cplusplus wrapper must have the following format, and precedes 176 | any contents of the header file: 177 | 178 | ```no-highlight 179 | #ifdef __cplusplus 180 | #extern "C" { 181 | ##endif 182 | ``` 183 | 184 | ## Naming 185 | 186 | * Names of functions, structures and variables must be in all lowercase. 187 | 188 | * Names should be as short as possible, but no shorter. 189 | 190 | * Globally visible names must be prefixed with the name of the module, 191 | followed by the '_' character, i.e.: 192 | 193 | ``` 194 | os_callout_init(&c) 195 | ``` 196 | 197 | Not: 198 | 199 | ``` 200 | callout_init(c) 201 | ``` 202 | 203 | ## Functions 204 | 205 | * No spaces after function names when calling a function, i.e, do: 206 | 207 | ``` 208 | rc = function(a) 209 | ``` 210 | 211 | Not: 212 | 213 | ``` 214 | rc = function (a) 215 | ``` 216 | 217 | 218 | * Arguments to function calls should have spaces between the comma, i.e. do: 219 | 220 | ``` 221 | rc = function(a, b) 222 | ``` 223 | 224 | Not: 225 | 226 | ``` 227 | rc = function(a,b) 228 | ``` 229 | 230 | * The function type must be on a line by itself preceding the function, i.e. do: 231 | 232 | ``` 233 | static void * 234 | function(int var1, int var2) 235 | { 236 | ``` 237 | 238 | Not: 239 | 240 | ``` 241 | static void *function(int var1, int var2) 242 | { 243 | ``` 244 | 245 | * In general, for functions that return values that denote success or error, 0 246 | shall be success, and non-zero shall be the failure code. 247 | 248 | ## Variables and Macros 249 | 250 | * Do not use typedefs for structures. This makes it impossible for 251 | applications to use pointers to those structures opaquely. 252 | 253 | * typedef may be used for non-structure types, where it is beneficial to 254 | hide or alias the underlying type used (e.g. ```os_time_t```.) Indicate 255 | typedefs by applying the ```_t``` marker to them. 256 | 257 | * Place all function-local variable definitions at the top of the function body, before any statements. 258 | 259 | ## Compiler Directives 260 | 261 | * Code must compile cleanly with -Wall enabled. 262 | 263 | -------------------------------------------------------------------------------- /apps/tdoa_tag/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include "sysinit/sysinit.h" 24 | #include "os/os.h" 25 | #include "bsp/bsp.h" 26 | #include "hal/hal_gpio.h" 27 | #include "hal/hal_bsp.h" 28 | #ifdef ARCH_sim 29 | #include "mcu/mcu_sim.h" 30 | #endif 31 | 32 | #if MYNEWT_VAL(BLE_ENABLED) 33 | #include "bleprph/bleprph.h" 34 | #endif 35 | 36 | #include "sensor/sensor.h" 37 | #include "sensor/accel.h" 38 | #include "sensor/gyro.h" 39 | #include "sensor/mag.h" 40 | #include "sensor/pressure.h" 41 | #include "console/console.h" 42 | #include 43 | #include "uwbcfg/uwbcfg.h" 44 | 45 | #include 46 | #include 47 | 48 | /* The timer callout */ 49 | static struct dpl_callout tdoa_callout; 50 | static int16_t g_blink_rate = 1; 51 | static bool config_changed = false; 52 | 53 | /* 54 | * Config 55 | */ 56 | static char *uwb_conf_get(int argc, char **argv, char *val, int val_len_max); 57 | static int uwb_conf_set(int argc, char **argv, char *val); 58 | static int uwb_conf_commit(void); 59 | static int uwb_conf_export(void (*export_func)(char *name, char *val), 60 | enum conf_export_tgt tgt); 61 | 62 | static struct uwb_config_s { 63 | char blink_rate[8]; 64 | } uwb_config = { .blink_rate = {MYNEWT_VAL(TDOA_TAG_BLINK_RATE)} }; 65 | 66 | static struct conf_handler uwb_conf_cbs = { 67 | .ch_name = "main", 68 | .ch_get = uwb_conf_get, 69 | .ch_set = uwb_conf_set, 70 | .ch_commit = uwb_conf_commit, 71 | .ch_export = uwb_conf_export, 72 | }; 73 | 74 | static char * 75 | uwb_conf_get(int argc, char **argv, char *val, int val_len_max) 76 | { 77 | if (argc == 1) { 78 | if (!strcmp(argv[0], "blink_rate")) { 79 | return uwb_config.blink_rate; 80 | } 81 | } 82 | return NULL; 83 | } 84 | 85 | static int 86 | uwb_conf_set(int argc, char **argv, char *val) 87 | { 88 | if (argc == 1) { 89 | if (!strcmp(argv[0], "blink_rate")) { 90 | return CONF_VALUE_SET(val, CONF_STRING, uwb_config.blink_rate); 91 | } 92 | } 93 | return DPL_ENOENT; 94 | } 95 | 96 | static int 97 | uwb_conf_commit(void) 98 | { 99 | int16_t old_blink_rate = g_blink_rate; 100 | conf_value_from_str(uwb_config.blink_rate, CONF_INT16, 101 | (void*)&g_blink_rate, 0); 102 | 103 | /* Start blinking if we weren't before */ 104 | if (g_blink_rate > 0 && old_blink_rate==0) { 105 | dpl_callout_reset(&tdoa_callout, DPL_TICKS_PER_SEC/g_blink_rate); 106 | } 107 | return 0; 108 | } 109 | 110 | static int 111 | uwb_conf_export(void (*export_func)(char *name, char *val), 112 | enum conf_export_tgt tgt) 113 | { 114 | export_func("main/blink_rate", uwb_config.blink_rate); 115 | return 0; 116 | } 117 | 118 | 119 | int 120 | uwb_sleep(void) 121 | { 122 | #if MYNEWT_VAL(UWB_DEVICE_0) 123 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 124 | 125 | /* Enter sleep */ 126 | uwb_phy_forcetrxoff(udev); 127 | uwb_phy_rx_reset(udev); 128 | uwb_sleep_config(udev); 129 | /* Clear all status flags that could prevent entering sleep */ 130 | //dw1000_write_reg(inst, SYS_STATUS_ID,3,0xFFFF,sizeof(uint16_t)); 131 | //dw1000_write_reg(inst, SYS_STATUS_ID,0,0xFFFFFFFF,sizeof(uint32_t)); 132 | uwb_sleep_config(udev); 133 | /* Enter sleep */ 134 | uwb_enter_sleep(udev); 135 | #endif 136 | return 0; 137 | } 138 | 139 | /* 140 | * Event callback function for timer events. 141 | */ 142 | static ieee_blink_frame_t tdoa_blink_frame = { 143 | .fctrl = 0xC5, /* frame type (0xC5 for a blink) using 64-bit addressing */ 144 | .seq_num = 0, /* sequence number, incremented for each new frame. */ 145 | .long_address = 0, /* device ID */ 146 | }; 147 | 148 | static 149 | void tdoa_timer_ev_cb(struct dpl_event *ev) { 150 | assert(ev != NULL); 151 | 152 | hal_gpio_write(LED_BLINK_PIN, 1); 153 | 154 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 155 | if (udev->status.sleeping) { 156 | uwb_wakeup(udev); 157 | } 158 | 159 | if (config_changed) { 160 | uwb_mac_config(udev, NULL); 161 | uwb_txrf_config(udev, &udev->config.txrf); 162 | config_changed = false; 163 | } 164 | 165 | uwb_sleep_config(udev); 166 | uwb_enter_sleep_after_tx(udev, g_blink_rate < 10); 167 | 168 | uwb_write_tx_fctrl(udev, sizeof(ieee_blink_frame_t), 0); 169 | 170 | if (uwb_start_tx(udev).start_tx_error){ 171 | printf("start tx err\n"); 172 | } else { 173 | uwb_write_tx(udev, tdoa_blink_frame.array, 0, sizeof(ieee_blink_frame_t)); 174 | } 175 | hal_gpio_write(LED_BLINK_PIN, 0); 176 | 177 | tdoa_blink_frame.seq_num++; 178 | if (g_blink_rate) { 179 | dpl_callout_reset(&tdoa_callout, DPL_TICKS_PER_SEC/g_blink_rate); 180 | } 181 | } 182 | 183 | 184 | static void init_timer(void) { 185 | /* 186 | * Initialize the callout for a timer event. 187 | */ 188 | dpl_callout_init(&tdoa_callout, dpl_eventq_dflt_get(), tdoa_timer_ev_cb, NULL); 189 | if (g_blink_rate) { 190 | dpl_callout_reset(&tdoa_callout, DPL_TICKS_PER_SEC/g_blink_rate); 191 | } 192 | } 193 | 194 | int 195 | uwb_config_updated() 196 | { 197 | config_changed = true; 198 | return 0; 199 | } 200 | 201 | struct uwbcfg_cbs uwb_cb = { 202 | .uc_update = uwb_config_updated 203 | }; 204 | 205 | int main(int argc, char **argv){ 206 | int rc; 207 | 208 | sysinit(); 209 | hal_gpio_init_out(LED_BLINK_PIN, 1); 210 | 211 | uwbcfg_register(&uwb_cb); 212 | 213 | /* Register local config */ 214 | rc = conf_register(&uwb_conf_cbs); 215 | assert(rc == 0); 216 | 217 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 218 | udev->config.dblbuffon_enabled = 0; 219 | udev->config.bias_correction_enable = 0; 220 | udev->config.LDE_enable = 1; 221 | udev->config.LDO_enable = 0; 222 | udev->config.sleep_enable = 1; 223 | udev->config.wakeup_rx_enable = 0; 224 | udev->config.rxauto_enable = 0; 225 | 226 | uwb_sleep(); 227 | 228 | printf("{\"device_id\"=\"%lX\"",udev->device_id); 229 | printf(",\"panid=\"%X\"",udev->pan_id); 230 | printf(",\"addr\"=\"%X\"",udev->uid); 231 | printf(",\"part_id\"=\"%lX\"",(uint32_t)(udev->euid&0xffffffff)); 232 | printf(",\"lot_id\"=\"%lX\"}\n",(uint32_t)(udev->euid>>32)); 233 | 234 | tdoa_blink_frame.long_address = udev->my_long_address; 235 | #if MYNEWT_VAL(BLE_ENABLED) 236 | ble_init(udev->my_long_address); 237 | #endif 238 | 239 | init_timer(); 240 | hal_gpio_init_out(LED_BLINK_PIN, 0); 241 | 242 | while (1) { 243 | dpl_eventq_run(dpl_eventq_dflt_get()); 244 | } 245 | 246 | assert(0); 247 | return rc; 248 | } 249 | -------------------------------------------------------------------------------- /apps/twr_aloha/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "sysinit/sysinit.h" 26 | #include "os/os.h" 27 | #include "bsp/bsp.h" 28 | #include "imgmgr/imgmgr.h" 29 | #include "hal/hal_gpio.h" 30 | #include "hal/hal_bsp.h" 31 | #ifdef ARCH_sim 32 | #include "mcu/mcu_sim.h" 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | //#define DIAGMSG(s,u) printf(s,u) 41 | #ifndef DIAGMSG 42 | #define DIAGMSG(s,u) 43 | #endif 44 | #if MYNEWT_VAL(CIR_ENABLED) 45 | #include 46 | #endif 47 | 48 | static void slot_complete_cb(struct dpl_event *ev); 49 | 50 | /*! 51 | * @fn complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) 52 | * 53 | * @brief This callback is part of the struct uwb_mac_interface extension interface and invoked of the completion of a range request. 54 | * The struct uwb_mac_interface is in the interrupt context and is used to schedule events an event queue. Processing should be kept 55 | * to a minimum giving the interrupt context. All algorithms activities should be deferred to a thread on an event queue. 56 | * The callback should return true if and only if it can determine if it is the sole recipient of this event. 57 | * 58 | * NOTE: The MAC extension interface is a link-list of callbacks, subsequent callbacks on the list will be not be called in the 59 | * event of returning true. 60 | * 61 | * @param inst - dw1000_dev_instance_t * 62 | * @param cbs - struct uwb_mac_interface * 63 | * 64 | * output parameters 65 | * 66 | * returns bool 67 | */ 68 | /* The timer callout */ 69 | 70 | static struct dpl_event slot_event = {0}; 71 | static struct os_callout tx_callout; 72 | static uint16_t g_idx_latest; 73 | 74 | static bool 75 | complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) 76 | { 77 | if(inst->fctrl != FCNTL_IEEE_RANGE_16){ 78 | return false; 79 | } 80 | struct uwb_rng_instance * rng = (struct uwb_rng_instance*)cbs->inst_ptr; 81 | g_idx_latest = (rng->idx)%rng->nframes; // Store valid frame pointer 82 | dpl_eventq_put(dpl_eventq_dflt_get(), &slot_event); 83 | return true; 84 | } 85 | 86 | static bool 87 | rx_timeout_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) 88 | { 89 | struct uwb_rng_instance * rng = (struct uwb_rng_instance*)cbs->inst_ptr; 90 | if (inst->role&UWB_ROLE_ANCHOR) { 91 | uwb_phy_forcetrxoff(inst); 92 | uwb_rng_listen(rng, 0xfffff, UWB_NONBLOCKING); 93 | } else { 94 | /* Do nothing */ 95 | } 96 | return true; 97 | } 98 | 99 | /*! 100 | * @fn slot_complete_cb(struct os_event * ev) 101 | * 102 | * @brief In the example this function represents the event context processing of the received range request. 103 | * In this case, a JSON string is constructed and written to stdio. See the ./apps/matlab or ./apps/python folders for examples on 104 | * how to parse and render these results. 105 | * 106 | * input parameters 107 | * @param inst - struct os_event * 108 | * output parameters 109 | * returns none 110 | */ 111 | 112 | static void slot_complete_cb(struct dpl_event *ev) 113 | { 114 | assert(ev != NULL); 115 | 116 | hal_gpio_toggle(LED_BLINK_PIN); 117 | 118 | struct uwb_rng_instance * rng = (struct uwb_rng_instance *)dpl_event_get_arg(ev); 119 | struct uwb_dev * inst = rng->dev_inst; 120 | 121 | if (inst->role&UWB_ROLE_ANCHOR) { 122 | uwb_rng_listen(rng, 0xfffff, UWB_NONBLOCKING); 123 | } 124 | } 125 | 126 | static void 127 | uwb_ev_cb(struct os_event *ev) 128 | { 129 | struct uwb_rng_instance * rng = (struct uwb_rng_instance *)ev->ev_arg; 130 | struct uwb_dev * inst = rng->dev_inst; 131 | 132 | if (inst->role&UWB_ROLE_ANCHOR) { 133 | if(dpl_sem_get_count(&rng->sem) == 1){ 134 | uwb_rng_listen(rng, 0xfffff, UWB_NONBLOCKING); 135 | } 136 | } else { 137 | int mode_v[8] = {0}, mode_i=0, mode=-1; 138 | static int last_used_mode = 0; 139 | #if MYNEWT_VAL(TWR_SS_ENABLED) 140 | mode_v[mode_i++] = UWB_DATA_CODE_SS_TWR; 141 | #endif 142 | #if MYNEWT_VAL(TWR_SS_EXT_ENABLED) 143 | mode_v[mode_i++] = UWB_DATA_CODE_SS_TWR_EXT; 144 | #endif 145 | #if MYNEWT_VAL(TWR_SS_ACK_ENABLED) 146 | mode_v[mode_i++] = UWB_DATA_CODE_SS_TWR_ACK; 147 | #endif 148 | #if MYNEWT_VAL(TWR_DS_ENABLED) 149 | mode_v[mode_i++] = UWB_DATA_CODE_DS_TWR; 150 | #endif 151 | #if MYNEWT_VAL(TWR_DS_EXT_ENABLED) 152 | mode_v[mode_i++] = UWB_DATA_CODE_DS_TWR_EXT; 153 | #endif 154 | if (++last_used_mode >= mode_i) last_used_mode=0; 155 | mode = mode_v[last_used_mode]; 156 | /* Uncomment the next line to force the range mode */ 157 | // mode = UWB_DATA_CODE_SS_TWR; 158 | if (mode>0) { 159 | uwb_rng_request(rng, MYNEWT_VAL(ANCHOR_ADDRESS), mode); 160 | } 161 | } 162 | os_callout_reset(&tx_callout, OS_TICKS_PER_SEC/60); 163 | } 164 | 165 | 166 | /** 167 | * @fn uwb_config_update 168 | * 169 | * Called from the main event queue as a result of the uwbcfg packet 170 | * having received a commit/load of new uwb configuration. 171 | */ 172 | int 173 | uwb_config_updated() 174 | { 175 | struct uwb_dev *inst = uwb_dev_idx_lookup(0); 176 | struct uwb_rng_instance * rng = (struct uwb_rng_instance*)uwb_mac_find_cb_inst_ptr( 177 | inst, UWBEXT_RNG); 178 | assert(rng); 179 | uwb_mac_config(inst, NULL); 180 | uwb_txrf_config(inst, &inst->config.txrf); 181 | 182 | if (inst->role&UWB_ROLE_ANCHOR) { 183 | uwb_phy_forcetrxoff(inst); 184 | uwb_rng_listen(rng, 0xfffff, UWB_NONBLOCKING); 185 | } else { 186 | /* Do nothing */ 187 | } 188 | return 0; 189 | } 190 | 191 | int main(int argc, char **argv){ 192 | int rc; 193 | 194 | sysinit(); 195 | /* Register callback for UWB configuration changes */ 196 | struct uwbcfg_cbs uwb_cb = { 197 | .uc_update = uwb_config_updated 198 | }; 199 | uwbcfg_register(&uwb_cb); 200 | /* Load config from flash */ 201 | conf_load(); 202 | 203 | hal_gpio_init_out(LED_BLINK_PIN, 1); 204 | hal_gpio_init_out(LED_1, 1); 205 | hal_gpio_init_out(LED_3, 1); 206 | 207 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 208 | struct uwb_rng_instance * rng = (struct uwb_rng_instance*)uwb_mac_find_cb_inst_ptr(udev, UWBEXT_RNG); 209 | assert(rng); 210 | struct uwb_mac_interface cbs = (struct uwb_mac_interface){ 211 | .id = UWBEXT_APP0, 212 | .inst_ptr = rng, 213 | .complete_cb = complete_cb, 214 | .rx_timeout_cb = rx_timeout_cb, 215 | }; 216 | uwb_mac_append_interface(udev, &cbs); 217 | 218 | uint32_t utime = os_cputime_ticks_to_usecs(os_cputime_get32()); 219 | printf("{\"utime\": %lu,\"exec\": \"%s\"}\n",utime,__FILE__); 220 | printf("{\"device_id\"=\"%lX\"",udev->device_id); 221 | printf(",\"panid=\"%X\"",udev->pan_id); 222 | printf(",\"addr\"=\"%X\"",udev->uid); 223 | printf(",\"part_id\"=\"%lX\"",(uint32_t)(udev->euid&0xffffffff)); 224 | printf(",\"lot_id\"=\"%lX\"}\n",(uint32_t)(udev->euid>>32)); 225 | printf("{\"utime\": %lu,\"msg\": \"frame_duration = %d usec\"}\n",utime, uwb_phy_frame_duration(udev, sizeof(twr_frame_final_t))); 226 | printf("{\"utime\": %lu,\"msg\": \"SHR_duration = %d usec\"}\n",utime,uwb_phy_SHR_duration(udev)); 227 | printf("{\"utime\": %lu,\"msg\": \"holdoff = %d usec\"}\n",utime,(uint16_t)ceilf(uwb_dwt_usecs_to_usecs(rng->config.tx_holdoff_delay))); 228 | 229 | #if MYNEWT_VAL(TWR_SS_ACK_ENABLED) 230 | uwb_set_autoack(udev, true); 231 | uwb_set_autoack_delay(udev, 12); 232 | #endif 233 | 234 | os_callout_init(&tx_callout, os_eventq_dflt_get(), uwb_ev_cb, rng); 235 | os_callout_reset(&tx_callout, OS_TICKS_PER_SEC/25); 236 | 237 | dpl_event_init(&slot_event, slot_complete_cb, rng); 238 | 239 | if ((udev->role&UWB_ROLE_ANCHOR)) { 240 | udev->my_short_address = MYNEWT_VAL(ANCHOR_ADDRESS); 241 | uwb_set_uid(udev, udev->my_short_address); 242 | } 243 | #if MYNEWT_VAL(RNG_VERBOSE) > 1 244 | udev->config.rxdiag_enable = 1; 245 | #else 246 | udev->config.rxdiag_enable = 0; 247 | #endif 248 | while (1) { 249 | os_eventq_run(os_eventq_dflt_get()); 250 | } 251 | assert(0); 252 | return rc; 253 | } 254 | -------------------------------------------------------------------------------- /lib/bleprph/src/bleprph.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | 21 | #include 22 | #include 23 | #include 24 | #include "os/os.h" 25 | #include "bsp/bsp.h" 26 | #include "hal/hal_gpio.h" 27 | #include "console/console.h" 28 | #include "hal/hal_system.h" 29 | #include "config/config.h" 30 | #include "log/log.h" 31 | 32 | /* BLE */ 33 | #include "bleprph/bleprph.h" 34 | #include "ble_priv.h" 35 | #include "nimble/ble.h" 36 | #include "host/ble_hs.h" 37 | #include "host/util/util.h" 38 | #include "services/gap/ble_svc_gap.h" 39 | 40 | struct log bleprph_log; 41 | 42 | 43 | struct ble_hs_cfg; 44 | struct ble_gatt_register_ctxt; 45 | 46 | /* bleprph uses the first "peruser" log module. */ 47 | #define BLEPRPH_LOG_MODULE (LOG_MODULE_PERUSER + 0) 48 | 49 | /** GATT server. */ 50 | #define GATT_SVR_SVC_ALERT_UUID 0x1811 51 | #define GATT_SVR_CHR_SUP_NEW_ALERT_CAT_UUID 0x2A47 52 | #define GATT_SVR_CHR_NEW_ALERT 0x2A46 53 | #define GATT_SVR_CHR_SUP_UNR_ALERT_CAT_UUID 0x2A48 54 | #define GATT_SVR_CHR_UNR_ALERT_STAT_UUID 0x2A45 55 | #define GATT_SVR_CHR_ALERT_NOT_CTRL_PT 0x2A44 56 | 57 | void gatt_svr_register_cb(struct ble_gatt_register_ctxt *ctxt, void *arg); 58 | int gatt_svr_init(void); 59 | 60 | static int bleprph_gap_event(struct ble_gap_event *event, void *arg); 61 | static uint8_t g_bleprph_connected = 0; 62 | 63 | /** 64 | * Enables advertising with the following parameters: 65 | * o General discoverable mode. 66 | * o Undirected connectable mode. 67 | */ 68 | static void 69 | bleprph_advertise(void) 70 | { 71 | uint8_t own_addr_type; 72 | struct ble_gap_adv_params adv_params; 73 | struct ble_hs_adv_fields fields; 74 | const char *name; 75 | int rc; 76 | 77 | /* Figure out address to use while advertising (no privacy for now) */ 78 | rc = ble_hs_id_infer_auto(0, &own_addr_type); 79 | if (rc != 0) { 80 | BLEPRPH_LOG(ERROR, "error determining address type; rc=%d\n", rc); 81 | return; 82 | } 83 | 84 | /** 85 | * Set the advertisement data included in our advertisements: 86 | * o Flags (indicates advertisement type and other general info). 87 | * o Advertising tx power. 88 | * o Device name. 89 | * o 16-bit service UUIDs (alert notifications). 90 | */ 91 | 92 | memset(&fields, 0, sizeof fields); 93 | 94 | /* Advertise two flags: 95 | * o Discoverability in forthcoming advertisement (general) 96 | * o BLE-only (BR/EDR unsupported). 97 | */ 98 | fields.flags = BLE_HS_ADV_F_DISC_GEN | 99 | BLE_HS_ADV_F_BREDR_UNSUP; 100 | 101 | /* Indicate that the TX power level field should be included; have the 102 | * stack fill this value automatically. This is done by assiging the 103 | * special value BLE_HS_ADV_TX_PWR_LVL_AUTO. 104 | */ 105 | fields.tx_pwr_lvl_is_present = 1; 106 | fields.tx_pwr_lvl = BLE_HS_ADV_TX_PWR_LVL_AUTO; 107 | 108 | name = ble_svc_gap_device_name(); 109 | fields.name = (uint8_t *)name; 110 | fields.name_len = strlen(name); 111 | fields.name_is_complete = 1; 112 | 113 | fields.uuids16 = (ble_uuid16_t[]){ 114 | BLE_UUID16_INIT(GATT_SVR_SVC_ALERT_UUID) 115 | }; 116 | fields.num_uuids16 = 1; 117 | fields.uuids16_is_complete = 1; 118 | 119 | rc = ble_gap_adv_set_fields(&fields); 120 | if (rc != 0) { 121 | BLEPRPH_LOG(ERROR, "error setting advertisement data; rc=%d\n", rc); 122 | return; 123 | } 124 | 125 | /* Begin advertising. */ 126 | memset(&adv_params, 0, sizeof adv_params); 127 | adv_params.conn_mode = BLE_GAP_CONN_MODE_UND; 128 | adv_params.disc_mode = BLE_GAP_DISC_MODE_GEN; 129 | rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, 130 | &adv_params, bleprph_gap_event, NULL); 131 | if (rc != 0) { 132 | BLEPRPH_LOG(ERROR, "error enabling advertisement; rc=%d\n", rc); 133 | return; 134 | } 135 | } 136 | 137 | /** 138 | * The nimble host executes this callback when a GAP event occurs. The 139 | * application associates a GAP event callback with each connection that forms. 140 | * bleprph uses the same callback for all connections. 141 | * 142 | * @param event The type of event being signalled. 143 | * @param ctxt Various information pertaining to the event. 144 | * @param arg Application-specified argument; unuesd by 145 | * bleprph. 146 | * 147 | * @return 0 if the application successfully handled the 148 | * event; nonzero on failure. The semantics 149 | * of the return code is specific to the 150 | * particular GAP event being signalled. 151 | */ 152 | static int 153 | bleprph_gap_event(struct ble_gap_event *event, void *arg) 154 | { 155 | struct ble_gap_conn_desc desc; 156 | int rc; 157 | 158 | switch (event->type) { 159 | case BLE_GAP_EVENT_CONNECT: 160 | /* A new connection was established or a connection attempt failed. */ 161 | BLEPRPH_LOG(INFO, "connection %s; status=%d ", 162 | event->connect.status == 0 ? "established" : "failed", 163 | event->connect.status); 164 | if (event->connect.status == 0) { 165 | rc = ble_gap_conn_find(event->connect.conn_handle, &desc); 166 | assert(rc == 0); 167 | 168 | } 169 | BLEPRPH_LOG(INFO, "\n"); 170 | 171 | if (event->connect.status != 0) { 172 | /* Connection failed; resume advertising. */ 173 | bleprph_advertise(); 174 | } else { 175 | g_bleprph_connected=1; 176 | } 177 | return 0; 178 | 179 | case BLE_GAP_EVENT_DISCONNECT: 180 | BLEPRPH_LOG(INFO, "disconnect; reason=%d ", event->disconnect.reason); 181 | BLEPRPH_LOG(INFO, "\n"); 182 | 183 | /* Connection terminated; resume advertising. */ 184 | bleprph_advertise(); 185 | g_bleprph_connected=0; 186 | return 0; 187 | 188 | case BLE_GAP_EVENT_CONN_UPDATE: 189 | /* The central has updated the connection parameters. */ 190 | BLEPRPH_LOG(INFO, "connection updated; status=%d ", 191 | event->conn_update.status); 192 | rc = ble_gap_conn_find(event->connect.conn_handle, &desc); 193 | assert(rc == 0); 194 | BLEPRPH_LOG(INFO, "\n"); 195 | return 0; 196 | 197 | case BLE_GAP_EVENT_ADV_COMPLETE: 198 | BLEPRPH_LOG(INFO, "advertise complete; reason=%d", 199 | event->adv_complete.reason); 200 | bleprph_advertise(); 201 | return 0; 202 | 203 | case BLE_GAP_EVENT_ENC_CHANGE: 204 | /* Encryption has been enabled or disabled for this connection. */ 205 | BLEPRPH_LOG(INFO, "encryption change event; status=%d ", 206 | event->enc_change.status); 207 | rc = ble_gap_conn_find(event->connect.conn_handle, &desc); 208 | assert(rc == 0); 209 | BLEPRPH_LOG(INFO, "\n"); 210 | return 0; 211 | 212 | case BLE_GAP_EVENT_SUBSCRIBE: 213 | BLEPRPH_LOG(INFO, "subscribe event; conn_handle=%d attr_handle=%d " 214 | "reason=%d prevn=%d curn=%d previ=%d curi=%d\n", 215 | event->subscribe.conn_handle, 216 | event->subscribe.attr_handle, 217 | event->subscribe.reason, 218 | event->subscribe.prev_notify, 219 | event->subscribe.cur_notify, 220 | event->subscribe.prev_indicate, 221 | event->subscribe.cur_indicate); 222 | return 0; 223 | 224 | case BLE_GAP_EVENT_MTU: 225 | BLEPRPH_LOG(INFO, "mtu update event; conn_handle=%d cid=%d mtu=%d\n", 226 | event->mtu.conn_handle, 227 | event->mtu.channel_id, 228 | event->mtu.value); 229 | return 0; 230 | } 231 | 232 | return 0; 233 | } 234 | 235 | static void 236 | bleprph_on_reset(int reason) 237 | { 238 | BLEPRPH_LOG(ERROR, "Resetting state; reason=%d\n", reason); 239 | } 240 | 241 | static void 242 | bleprph_on_sync(void) 243 | { 244 | int rc; 245 | 246 | /* Make sure we have proper identity address set (public preferred) */ 247 | rc = ble_hs_util_ensure_addr(0); 248 | assert(rc == 0); 249 | 250 | /* Begin advertising. */ 251 | bleprph_advertise(); 252 | } 253 | 254 | int 255 | ble_is_connected() 256 | { 257 | #if MYNEWT_VAL(BLEPRPH_ENABLED) 258 | return g_bleprph_connected; 259 | #else 260 | return 0; 261 | #endif 262 | } 263 | 264 | int 265 | ble_init(uint64_t ble_id) 266 | { 267 | int rc = 0; 268 | 269 | ble_hs_cfg.reset_cb = bleprph_on_reset; 270 | ble_hs_cfg.sync_cb = bleprph_on_sync; 271 | ble_hs_cfg.gatts_register_cb = gatt_svr_register_cb; 272 | ble_hs_cfg.store_status_cb = ble_store_util_status_rr; 273 | 274 | rc = gatt_svr_init(); 275 | assert(rc == 0); 276 | 277 | /* Set the default device name. */ 278 | char ble_name[32]; 279 | snprintf(ble_name, sizeof(ble_name), "%s-%04lX", MYNEWT_VAL(BLE_PREFIX), 280 | (uint32_t)ble_id&0xffffffff); 281 | BLEPRPH_LOG(INFO, "Setting name to %s\n", ble_name); 282 | 283 | rc = ble_svc_gap_device_name_set(ble_name); 284 | assert(rc == 0); 285 | return rc; 286 | } 287 | 288 | int 289 | ble_stop() 290 | { 291 | return ble_gap_adv_stop(); 292 | } 293 | 294 | void 295 | bleprph_pkg_init(void) 296 | { 297 | /* Placeholder */ 298 | } 299 | -------------------------------------------------------------------------------- /apps/twr_tag_tdma/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "sysinit/sysinit.h" 25 | #include "os/os.h" 26 | #include "bsp/bsp.h" 27 | #include "hal/hal_gpio.h" 28 | #include "hal/hal_bsp.h" 29 | #ifdef ARCH_sim 30 | #include "mcu/mcu_sim.h" 31 | #endif 32 | 33 | #if MYNEWT_VAL(BLE_ENABLED) 34 | #include "bleprph/bleprph.h" 35 | #endif 36 | 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #if MYNEWT_VAL(DW1000_DEVICE_0) 43 | #include 44 | #endif 45 | 46 | #include 47 | #include 48 | 49 | //#define DIAGMSG(s,u) printf(s,u) 50 | #ifndef DIAGMSG 51 | #define DIAGMSG(s,u) 52 | #endif 53 | 54 | 55 | static bool error_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs); 56 | static void slot_complete_cb(struct dpl_event * ev); 57 | 58 | /*! 59 | * @fn slot_cb(struct os_event * ev) 60 | * 61 | * @brief In this example slot_cb is used to initiate a range request. The slot_cb is scheduled 62 | * MYNEWT_VAL(OS_LATENCY) in advance of the transmit epoch and a delayed start request is issued in advance of 63 | * the required epoch. The transmission timing is controlled precisely by the DW1000 with the transmission time 64 | * defined by the value of the dw_time variable. If the OS_LATENCY value is set too small the range request 65 | * function will report a start_tx_error. In a synchronized network, the node device switches the transceiver 66 | * to receiver mode for the same epoch; and will either receive the inbound frame or timeout after the frame 67 | * duration as elapsed. This ensures that the transceiver is in receive mode for the minimum time required. 68 | * 69 | * input parameters 70 | * @param inst - struct dpl_event * 71 | * 72 | * output parameters 73 | * 74 | * returns none 75 | */ 76 | static void 77 | slot_cb(struct dpl_event *ev){ 78 | assert(ev); 79 | tdma_slot_t * slot = (tdma_slot_t *) dpl_event_get_arg(ev); 80 | tdma_instance_t * tdma = slot->parent; 81 | uint16_t idx = slot->idx; 82 | struct uwb_rng_instance *rng = (struct uwb_rng_instance*)slot->arg; 83 | 84 | hal_gpio_toggle(LED_BLINK_PIN); 85 | uint64_t dx_time = tdma_tx_slot_start(tdma, idx) & 0xFFFFFFFFFE00UL; 86 | 87 | /* Range with the clock master by default */ 88 | struct uwb_ccp_instance *ccp = tdma->ccp; 89 | uint16_t node_address = ccp->frames[ccp->idx%ccp->nframes]->short_address; 90 | 91 | /* Select single-sided or double sided twr every second slot */ 92 | int mode = UWB_DATA_CODE_SS_TWR_ACK; 93 | if ((slot->idx&7)==1) { 94 | mode = UWB_DATA_CODE_SS_TWR; 95 | } 96 | if ((slot->idx&7)==2) { 97 | mode = UWB_DATA_CODE_SS_TWR_EXT; 98 | } 99 | if ((slot->idx&7)==3) { 100 | mode = UWB_DATA_CODE_DS_TWR; 101 | } 102 | if ((slot->idx&7)==4) { 103 | mode = UWB_DATA_CODE_DS_TWR_EXT; 104 | } 105 | 106 | uwb_rng_request_delay_start(rng, node_address, dx_time, mode); 107 | } 108 | 109 | 110 | /*! 111 | * @fn complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) 112 | * 113 | * @brief This callback is part of the struct uwb_mac_interface extension interface and invoked of the completion of a range request 114 | * in the context of this example. The struct uwb_mac_interface is in the interrupt context and is used to schedule events an event queue. 115 | * Processing should be kept to a minimum giving the interrupt context. All algorithms activities should be deferred to a thread on an event queue. 116 | * The callback should return true if and only if it can determine if it is the sole recipient of this event. 117 | * 118 | * NOTE: The MAC extension interface is a link-list of callbacks, subsequent callbacks on the list will be not be called in the 119 | * event of returning true. 120 | * 121 | * @param inst - struct uwb_dev * 122 | * @param cbs - struct uwb_mac_interface * 123 | * 124 | * output parameters 125 | * 126 | * returns bool 127 | */ 128 | /* The timer callout */ 129 | static struct dpl_event slot_event = {0}; 130 | static uint16_t g_idx_latest; 131 | 132 | static bool 133 | complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) 134 | { 135 | if (inst->fctrl != FCNTL_IEEE_RANGE_16 && 136 | inst->fctrl != (FCNTL_IEEE_RANGE_16|UWB_FCTRL_ACK_REQUESTED)) { 137 | return false; 138 | } 139 | struct uwb_rng_instance* rng = (struct uwb_rng_instance*)cbs->inst_ptr; 140 | g_idx_latest = (rng->idx)%rng->nframes; // Store valid frame pointer 141 | if (!dpl_event_is_queued(&slot_event)) { 142 | dpl_eventq_put(dpl_eventq_dflt_get(), &slot_event); 143 | } 144 | return true; 145 | } 146 | 147 | /*! 148 | * @fn slot_complete_cb(struct os_event * ev) 149 | * 150 | * @brief In the example this function represents the event context processing of the received range request. 151 | * In this case, a JSON string is constructed and written to stdio. See the ./apps/matlab or ./apps/python folders for examples on 152 | * how to parse and render these results. 153 | * 154 | * input parameters 155 | * @param inst - struct os_event * 156 | * output parameters 157 | * returns none 158 | */ 159 | static void 160 | slot_complete_cb(struct dpl_event * ev){ 161 | assert(ev != NULL); 162 | 163 | hal_gpio_toggle(LED_BLINK_PIN); 164 | } 165 | 166 | /*! 167 | * @fn error_cb(struct os_event *ev) 168 | * 169 | * @brief This callback is in the interrupt context and is called on error event. 170 | * In this example just log event. 171 | * Note: interrupt context so overlapping IO is possible 172 | * input parameters 173 | * @param inst - struct uwb_dev * inst 174 | * 175 | * output parameters 176 | * 177 | * returns none 178 | */ 179 | static bool 180 | error_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) 181 | { 182 | if (inst->fctrl != FCNTL_IEEE_RANGE_16 && 183 | inst->fctrl != (FCNTL_IEEE_RANGE_16|UWB_FCTRL_ACK_REQUESTED)) { 184 | return false; 185 | } 186 | 187 | uint32_t utime = os_cputime_ticks_to_usecs(os_cputime_get32()); 188 | if (inst->status.start_rx_error) 189 | printf("{\"utime\": %lu,\"msg\": \"start_rx_error,%s:%d\"}\n",utime, __FILE__, __LINE__); 190 | if (inst->status.start_tx_error) 191 | printf("{\"utime\": %lu,\"msg\": \"start_tx_error,%s:%d\"}\n",utime, __FILE__, __LINE__); 192 | if (inst->status.rx_error) 193 | printf("{\"utime\": %lu,\"msg\": \"rx_error,%s:%d\"}\n",utime, __FILE__, __LINE__); 194 | 195 | return true; 196 | } 197 | 198 | /** 199 | * @fn uwb_config_update 200 | * 201 | * Called from the main event queue as a result of the uwbcfg packet 202 | * having received a commit/load of new uwb configuration. 203 | */ 204 | int 205 | uwb_config_updated() 206 | { 207 | uint32_t utime = os_cputime_ticks_to_usecs(os_cputime_get32()); 208 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 209 | uwb_mac_config(udev, NULL); 210 | uwb_txrf_config(udev, &udev->config.txrf); 211 | printf("{\"utime\": %lu,\"msg\": \"new config applied\"}\n",utime); 212 | return 0; 213 | } 214 | 215 | 216 | int main(int argc, char **argv){ 217 | int rc; 218 | 219 | sysinit(); 220 | /* Register callback for UWB configuration changes */ 221 | struct uwbcfg_cbs uwb_cb = { 222 | .uc_update = uwb_config_updated 223 | }; 224 | uwbcfg_register(&uwb_cb); 225 | /* Load config from flash */ 226 | conf_load(); 227 | 228 | hal_gpio_init_out(LED_BLINK_PIN, 1); 229 | hal_gpio_init_out(LED_1, 1); 230 | hal_gpio_init_out(LED_3, 1); 231 | 232 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 233 | struct uwb_rng_instance* rng = (struct uwb_rng_instance*)uwb_mac_find_cb_inst_ptr(udev, UWBEXT_RNG); 234 | assert(rng); 235 | 236 | struct uwb_mac_interface cbs = { 237 | .id = UWBEXT_APP0, 238 | .inst_ptr = rng, 239 | .tx_error_cb = error_cb, 240 | .rx_error_cb = error_cb, 241 | .complete_cb = complete_cb 242 | }; 243 | uwb_mac_append_interface(udev, &cbs); 244 | 245 | tdma_instance_t * tdma = (tdma_instance_t*)uwb_mac_find_cb_inst_ptr(udev, UWBEXT_TDMA); 246 | assert(tdma); 247 | uwb_ccp_start(tdma->ccp, CCP_ROLE_SLAVE); 248 | 249 | uint32_t utime = os_cputime_ticks_to_usecs(os_cputime_get32()); 250 | printf("{\"utime\": %lu,\"exec\": \"%s\"}\n",utime,__FILE__); 251 | printf("{\"device_id\"=\"%lX\"",udev->device_id); 252 | printf(",\"panid=\"%X\"",udev->pan_id); 253 | printf(",\"addr\"=\"%X\"",udev->uid); 254 | printf(",\"part_id\"=\"%lX\"",(uint32_t)(udev->euid&0xffffffff)); 255 | printf(",\"lot_id\"=\"%lX\"}\n",(uint32_t)(udev->euid>>32)); 256 | printf("{\"utime\": %lu,\"msg\": \"frame_duration = %d usec\"}\n",utime, uwb_phy_frame_duration(udev, sizeof(twr_frame_final_t))); 257 | printf("{\"utime\": %lu,\"msg\": \"SHR_duration = %d usec\"}\n",utime, uwb_phy_SHR_duration(udev)); 258 | printf("{\"utime\": %lu,\"msg\": \"holdoff = %d usec\"}\n",utime,(uint16_t)ceilf(uwb_dwt_usecs_to_usecs(rng->config.tx_holdoff_delay))); 259 | 260 | #if MYNEWT_VAL(BLE_ENABLED) 261 | ble_init(udev->euid); 262 | #endif 263 | dpl_event_init(&slot_event, slot_complete_cb, rng); 264 | 265 | /* Slot 0:ccp, 1+ twr */ 266 | for (uint16_t i = 1; i < MYNEWT_VAL(TDMA_NSLOTS); i++) { 267 | tdma_assign_slot(tdma, slot_cb, i, (void*)rng); 268 | } 269 | 270 | #if MYNEWT_VAL(RNG_VERBOSE) > 1 271 | udev->config.rxdiag_enable = 1; 272 | #else 273 | udev->config.rxdiag_enable = 0; 274 | #endif 275 | 276 | while (1) { 277 | os_eventq_run(os_eventq_dflt_get()); 278 | } 279 | assert(0); 280 | return rc; 281 | } 282 | -------------------------------------------------------------------------------- /apps/twr_node_tdma/node-red/pdoa_viewer_serial.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "b7edb48f.cf6568", 4 | "type": "tab", 5 | "label": "Flow 3", 6 | "disabled": false, 7 | "info": "" 8 | }, 9 | { 10 | "id": "e36a7219.5c62f", 11 | "type": "ui_template", 12 | "z": "b7edb48f.cf6568", 13 | "group": "", 14 | "name": "D3 libraries", 15 | "order": 0, 16 | "width": 0, 17 | "height": 0, 18 | "format": "\n\n", 19 | "storeOutMessages": true, 20 | "fwdInMessages": true, 21 | "templateScope": "global", 22 | "x": 135, 23 | "y": 324, 24 | "wires": [ 25 | [] 26 | ] 27 | }, 28 | { 29 | "id": "7010bfa0.fdc47", 30 | "type": "json", 31 | "z": "b7edb48f.cf6568", 32 | "name": "", 33 | "property": "payload", 34 | "action": "", 35 | "pretty": false, 36 | "x": 564, 37 | "y": 385, 38 | "wires": [ 39 | [ 40 | "adf08c2a.dd279" 41 | ] 42 | ] 43 | }, 44 | { 45 | "id": "99e4eca3.7a8af", 46 | "type": "delay", 47 | "z": "b7edb48f.cf6568", 48 | "name": "", 49 | "pauseType": "rate", 50 | "timeout": "5", 51 | "timeoutUnits": "seconds", 52 | "rate": "10", 53 | "nbRateUnits": "1", 54 | "rateUnits": "second", 55 | "randomFirst": "1", 56 | "randomLast": "5", 57 | "randomUnits": "seconds", 58 | "drop": true, 59 | "x": 353.00003814697266, 60 | "y": 388.00000953674316, 61 | "wires": [ 62 | [ 63 | "7010bfa0.fdc47" 64 | ] 65 | ] 66 | }, 67 | { 68 | "id": "adf08c2a.dd279", 69 | "type": "function", 70 | "z": "b7edb48f.cf6568", 71 | "name": "RAZ to XY", 72 | "func": "// Range Azimuth and Zenith to X, Y for display\n// 0 rad is straight down from Node\nif (!msg.payload.twr) return;\nif (!msg.payload.twr.raz) return;\n\ntwr = msg.payload.twr;\nx = twr.raz[0] * Math.cos(twr.raz[1]-Math.PI/2.0);\ny = -twr.raz[0] * Math.sin(twr.raz[1]-Math.PI/2.0);\n\nif (isNaN(x) || isNaN(y)) return;\n\nvar averages = context.get('pdoa_averages') || {\n 'x' : x, 'y' : y\n};\nif (isNaN(averages.x) || isNaN(averages.y)) {\n averages = {\n 'x' : x, 'y' : y\n }; \n}\nvar f = 0.2;\naverages.x = (1.0-f)*averages.x + f*x;\naverages.y = (1.0-f)*averages.y + f*y;\ncontext.set('pdoa_averages', averages)\n\nreturn {\"topic\":msg.payload.uid, \n \"payload\":[\n {\"id\":msg.payload.uid,\"x\":x,\"y\":y,\"radius\":1.5,\"is_average\":false,\"age\":0.0},\n {\"id\":'avg('+msg.payload.uid+')',\"x\":averages.x,\"y\":averages.y,\"radius\":0.3,\"is_average\":true,\"age\":0.0},\n ]};", 73 | "outputs": 1, 74 | "noerr": 0, 75 | "x": 744.9999847412109, 76 | "y": 386.99999618530273, 77 | "wires": [ 78 | [ 79 | "53808daf.732ae4" 80 | ] 81 | ] 82 | }, 83 | { 84 | "id": "53808daf.732ae4", 85 | "type": "ui_template", 86 | "z": "b7edb48f.cf6568", 87 | "group": "352e8057.feb55", 88 | "name": "PdoaView", 89 | "order": 1, 90 | "width": 0, 91 | "height": 0, 92 | "format": "\n\n\n \n\n\n", 93 | "storeOutMessages": false, 94 | "fwdInMessages": false, 95 | "templateScope": "local", 96 | "x": 946.9999771118164, 97 | "y": 388.9999895095825, 98 | "wires": [ 99 | [] 100 | ] 101 | }, 102 | { 103 | "id": "72c1f9fc.85bab8", 104 | "type": "serial in", 105 | "z": "b7edb48f.cf6568", 106 | "name": "", 107 | "serial": "7c4436b2.544378", 108 | "x": 138, 109 | "y": 387, 110 | "wires": [ 111 | [ 112 | "99e4eca3.7a8af" 113 | ] 114 | ] 115 | }, 116 | { 117 | "id": "352e8057.feb55", 118 | "type": "ui_group", 119 | "z": "", 120 | "name": "AoA", 121 | "tab": "31ce7246.25a33e", 122 | "order": 2, 123 | "disp": true, 124 | "width": "12", 125 | "collapse": false 126 | }, 127 | { 128 | "id": "7c4436b2.544378", 129 | "type": "serial-port", 130 | "z": "", 131 | "serialport": "/dev/ttyACM0", 132 | "serialbaud": "460800", 133 | "databits": "8", 134 | "parity": "none", 135 | "stopbits": "1", 136 | "waitfor": "", 137 | "newline": "\\n", 138 | "bin": "false", 139 | "out": "char", 140 | "addchar": "", 141 | "responsetimeout": "10000" 142 | }, 143 | { 144 | "id": "31ce7246.25a33e", 145 | "type": "ui_tab", 146 | "z": "", 147 | "name": "PdoaView", 148 | "icon": "dashboard", 149 | "order": 1, 150 | "disabled": false, 151 | "hidden": false 152 | } 153 | ] 154 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /apps/rtdoa_node/src/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "sysinit/sysinit.h" 25 | #include "os/os.h" 26 | #include "bsp/bsp.h" 27 | #include "imgmgr/imgmgr.h" 28 | #include "hal/hal_gpio.h" 29 | #include "hal/hal_bsp.h" 30 | #include 31 | #ifdef ARCH_sim 32 | #include "mcu/mcu_sim.h" 33 | #endif 34 | 35 | #if MYNEWT_VAL(BLEPRPH_ENABLED) 36 | #include "bleprph/bleprph.h" 37 | #endif 38 | 39 | #include 40 | #include 41 | #include 42 | #include "dw1000/dw1000_dev.h" 43 | #include "dw1000/dw1000_hal.h" 44 | #include "uwbcfg/uwbcfg.h" 45 | #include 46 | 47 | #if MYNEWT_VAL(NMGR_UWB_ENABLED) 48 | #include 49 | #endif 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #if MYNEWT_VAL(UWB_RNG_ENABLED) 56 | #include 57 | #endif 58 | #if MYNEWT_VAL(NRNG_ENABLED) 59 | #include 60 | #endif 61 | #include 62 | #include 63 | #include 64 | 65 | //#define DIAGMSG(s,u) printf(s,u) 66 | #ifndef DIAGMSG 67 | #define DIAGMSG(s,u) 68 | #endif 69 | 70 | 71 | #if MYNEWT_VAL(UWB_PAN_ENABLED) 72 | #include 73 | 74 | #include "panmaster/panmaster.h" 75 | 76 | #endif 77 | 78 | static bool uwb_config_updated = false; 79 | int 80 | uwb_config_upd_cb() 81 | { 82 | /* Workaround in case we're stuck waiting for ccp with the 83 | * wrong radio settings */ 84 | struct uwb_dev * inst = uwb_dev_idx_lookup(0); 85 | struct uwb_ccp_instance *ccp = (struct uwb_ccp_instance*)uwb_mac_find_cb_inst_ptr(inst, UWBEXT_CCP); 86 | if (dpl_sem_get_count(&ccp->sem) == 0 || !ccp->status.valid) { 87 | uwb_mac_config(inst, NULL); 88 | uwb_txrf_config(inst, &inst->config.txrf); 89 | if (dpl_sem_get_count(&ccp->sem) == 0) { 90 | uwb_start_rx(inst); 91 | } 92 | return 0; 93 | } 94 | 95 | uwb_config_updated = true; 96 | return 0; 97 | } 98 | struct uwbcfg_cbs uwb_cb = { 99 | .uc_update = uwb_config_upd_cb 100 | }; 101 | 102 | 103 | /** 104 | * @fn nrng_slot_timer_cb(struct dpl_event * ev) 105 | * 106 | * @brief Node to Node ranging for tof timing compensation 107 | * 108 | */ 109 | static void 110 | nrng_slot_timer_cb(struct dpl_event *ev) 111 | { 112 | assert(ev); 113 | tdma_slot_t * slot = (tdma_slot_t *) dpl_event_get_arg(ev);; 114 | tdma_instance_t * tdma = slot->parent; 115 | struct uwb_dev * inst = tdma->dev_inst; 116 | struct uwb_ccp_instance * ccp = tdma->ccp; 117 | struct nrng_instance * nrng = (struct nrng_instance *) uwb_mac_find_cb_inst_ptr(inst, UWBEXT_NRNG); 118 | 119 | uint16_t idx = slot->idx; 120 | 121 | /* Avoid colliding with the ccp */ 122 | if (dpl_sem_get_count(&ccp->sem) == 0 || idx == 0xffff) { 123 | return; 124 | } 125 | 126 | hal_gpio_write(LED_BLINK_PIN, 1); 127 | 128 | uint16_t anchor_rng_initiator = ccp->seq_num % 8; 129 | if (anchor_rng_initiator == inst->slot_id) { 130 | uint64_t dx_time = tdma_tx_slot_start(tdma, idx) & 0xFFFFFFFFFE00UL; 131 | uint32_t slot_mask = 0xFFFF; 132 | 133 | if(nrng_request_delay_start(nrng, UWB_BROADCAST_ADDRESS, dx_time, 134 | UWB_DATA_CODE_SS_TWR_NRNG, slot_mask, 0).start_tx_error){ 135 | /* Do nothing */ 136 | } 137 | } else { 138 | uwb_set_delay_start(inst, tdma_rx_slot_start(tdma, idx)); 139 | uint16_t timeout = uwb_phy_frame_duration(inst, sizeof(nrng_request_frame_t)) 140 | + nrng->config.rx_timeout_delay; 141 | 142 | uwb_set_rx_timeout(inst, timeout + 0x100); 143 | nrng_listen(nrng, UWB_BLOCKING); 144 | } 145 | hal_gpio_write(LED_BLINK_PIN, 0); 146 | } 147 | 148 | static void 149 | nrng_complete_cb(struct dpl_event *ev) 150 | { 151 | assert(ev != NULL); 152 | assert(dpl_event_get_arg(ev)); 153 | 154 | struct nrng_instance * nrng = (struct nrng_instance *) dpl_event_get_arg(ev); 155 | nrng_frame_t * frame = nrng->frames[(nrng->idx)%nrng->nframes]; 156 | 157 | for (int i=0;inframes;i++) { 158 | frame = nrng->frames[(nrng->idx + i)%nrng->nframes]; 159 | uint16_t dst_addr = frame->dst_address; 160 | if (frame->code != UWB_DATA_CODE_SS_TWR_NRNG_FINAL || frame->seq_num != nrng->seq_num) { 161 | continue; 162 | } 163 | 164 | float tof = nrng_twr_to_tof_frames(nrng->dev_inst, frame, frame); 165 | // float rssi = dw1000_calc_rssi(inst, &frame->diag); 166 | tofdb_set_tof(dst_addr, tof); 167 | } 168 | } 169 | 170 | static struct dpl_event slot_event; 171 | static bool complete_cb(struct uwb_dev * inst, struct uwb_mac_interface * cbs) 172 | { 173 | if(inst->fctrl != FCNTL_IEEE_RANGE_16){ 174 | return false; 175 | } 176 | dpl_eventq_put(dpl_eventq_dflt_get(), &slot_event); 177 | return true; 178 | } 179 | 180 | /** 181 | * @fn rtdoa_slot_timer_cb(struct dpl_event * ev) 182 | * 183 | * @brief RTDoA Emission slot 184 | * 185 | */ 186 | static void 187 | rtdoa_slot_timer_cb(struct dpl_event *ev) 188 | { 189 | assert(ev); 190 | tdma_slot_t * slot = (tdma_slot_t *) dpl_event_get_arg(ev); 191 | uint16_t idx = slot->idx; 192 | // printf("rtdoa %02d\n", idx); 193 | tdma_instance_t * tdma = slot->parent; 194 | assert(tdma); 195 | struct uwb_ccp_instance * ccp = tdma->ccp; 196 | assert(ccp); 197 | struct uwb_dev * inst = tdma->dev_inst; 198 | assert(inst); 199 | struct rtdoa_instance* rtdoa = (struct rtdoa_instance*)slot->arg; 200 | assert(rtdoa); 201 | 202 | /* Avoid colliding with the ccp */ 203 | if (dpl_sem_get_count(&ccp->sem) == 0) { 204 | return; 205 | } 206 | 207 | if (uwb_config_updated) { 208 | uwb_mac_config(inst, NULL); 209 | uwb_txrf_config(inst, &inst->config.txrf); 210 | uwb_config_updated = false; 211 | return; 212 | } 213 | 214 | /* See if there's anything to send, if so finish early */ 215 | nmgr_uwb_instance_t *nmgruwb = (nmgr_uwb_instance_t*)uwb_mac_find_cb_inst_ptr(tdma->dev_inst, UWBEXT_NMGR_UWB); 216 | assert(nmgruwb); 217 | if (uwb_nmgr_process_tx_queue(nmgruwb, tdma_tx_slot_start(tdma, idx)) == true) { 218 | return; 219 | } 220 | 221 | if (inst->role & UWB_ROLE_CCP_MASTER) { 222 | uint64_t dx_time = tdma_tx_slot_start(tdma, idx) & 0xFFFFFFFFFE00UL; 223 | 224 | if(rtdoa_request(rtdoa, dx_time).start_tx_error) { 225 | /* Do nothing */ 226 | printf("rtdoa_start_err\n"); 227 | } 228 | } else { 229 | uint64_t dx_time = tdma_rx_slot_start(tdma, idx); 230 | if(rtdoa_listen(rtdoa, UWB_BLOCKING, dx_time, 3*ccp->period/tdma->nslots/4).start_rx_error) { 231 | printf("#rse\n"); 232 | } 233 | } 234 | } 235 | 236 | static void 237 | nmgr_slot_timer_cb(struct dpl_event * ev) 238 | { 239 | assert(ev); 240 | tdma_slot_t * slot = (tdma_slot_t *) dpl_event_get_arg(ev); 241 | tdma_instance_t * tdma = slot->parent; 242 | struct uwb_ccp_instance * ccp = tdma->ccp; 243 | uint16_t idx = slot->idx; 244 | nmgr_uwb_instance_t * nmgruwb = (nmgr_uwb_instance_t *) slot->arg; 245 | assert(nmgruwb); 246 | // printf("idx %02d nmgr\n", idx); 247 | 248 | /* Avoid colliding with the ccp */ 249 | if (dpl_sem_get_count(&ccp->sem) == 0) { 250 | return; 251 | } 252 | 253 | uint16_t timeout = 3*ccp->period/tdma->nslots/4; 254 | if (uwb_nmgr_process_tx_queue(nmgruwb, tdma_tx_slot_start(tdma, idx)) == false) { 255 | nmgr_uwb_listen(nmgruwb, UWB_BLOCKING, tdma_rx_slot_start(tdma, idx), timeout); 256 | } 257 | } 258 | 259 | 260 | static void 261 | tdma_allocate_slots(tdma_instance_t * tdma) 262 | { 263 | uint16_t i; 264 | struct uwb_dev * inst = tdma->dev_inst; 265 | 266 | /* Pan is slot 1 */ 267 | struct uwb_pan_instance *pan = (struct uwb_pan_instance*)uwb_mac_find_cb_inst_ptr(inst, UWBEXT_PAN); 268 | assert(pan); 269 | tdma_assign_slot(tdma, uwb_pan_slot_timer_cb, 1, (void*)pan); 270 | 271 | /* anchor-to-anchor range slot is 31 */ 272 | struct nrng_instance * nrng = (struct nrng_instance *)uwb_mac_find_cb_inst_ptr(inst, UWBEXT_NRNG); 273 | assert(nrng); 274 | tdma_assign_slot(tdma, nrng_slot_timer_cb, 31, (void*)nrng); 275 | 276 | nmgr_uwb_instance_t *nmgruwb = (nmgr_uwb_instance_t*)uwb_mac_find_cb_inst_ptr(inst, UWBEXT_NMGR_UWB); 277 | assert(nmgruwb); 278 | struct rtdoa_instance* rtdoa = (struct rtdoa_instance*)uwb_mac_find_cb_inst_ptr(inst, UWBEXT_RTDOA); 279 | assert(rtdoa); 280 | 281 | for (i=2;i < MYNEWT_VAL(TDMA_NSLOTS);i++) { 282 | if (i==31) { 283 | continue; 284 | } 285 | if (i%12==0) { 286 | tdma_assign_slot(tdma, nmgr_slot_timer_cb, i, (void*)nmgruwb); 287 | } else { 288 | tdma_assign_slot(tdma, rtdoa_slot_timer_cb, i, (void*)rtdoa); 289 | } 290 | } 291 | } 292 | 293 | int 294 | main(int argc, char **argv) 295 | { 296 | int rc = 0; 297 | 298 | sysinit(); 299 | hal_gpio_init_out(LED_BLINK_PIN, 1); 300 | 301 | uwbcfg_register(&uwb_cb); 302 | conf_load(); 303 | 304 | struct uwb_mac_interface cbs = (struct uwb_mac_interface){ 305 | .id = UWBEXT_APP0, 306 | .complete_cb = complete_cb 307 | }; 308 | 309 | struct uwb_dev *udev = uwb_dev_idx_lookup(0); 310 | uwb_mac_append_interface(udev, &cbs); 311 | struct nrng_instance * nrng = (struct nrng_instance *)uwb_mac_find_cb_inst_ptr(udev, UWBEXT_NRNG); 312 | assert(nrng); 313 | dpl_event_init(&slot_event, nrng_complete_cb, nrng); 314 | 315 | udev->config.rxauto_enable = 0; 316 | udev->config.trxoff_enable = 1; 317 | udev->config.rxdiag_enable = 1; 318 | udev->config.sleep_enable = 1; 319 | udev->config.dblbuffon_enabled = 0; 320 | uwb_set_dblrxbuff(udev, false); 321 | 322 | udev->slot_id = 0xffff; 323 | 324 | ble_init(udev->my_long_address); 325 | 326 | struct uwb_ccp_instance *ccp = (struct uwb_ccp_instance *) uwb_mac_find_cb_inst_ptr(udev, UWBEXT_CCP); 327 | assert(ccp); 328 | struct uwb_pan_instance *pan = (struct uwb_pan_instance *) uwb_mac_find_cb_inst_ptr(udev, UWBEXT_PAN); 329 | assert(pan); 330 | 331 | if (udev->role & UWB_ROLE_CCP_MASTER) { 332 | printf("{\"role\":\"ccp_master\"}\n"); 333 | uwb_ccp_start(ccp, CCP_ROLE_MASTER); 334 | 335 | struct image_version fw_ver; 336 | struct panmaster_node *node; 337 | panmaster_idx_find_node(udev->euid, NETWORK_ROLE_ANCHOR, &node); 338 | assert(node); 339 | imgr_my_version(&fw_ver); 340 | node->fw_ver.iv_major = fw_ver.iv_major; 341 | node->fw_ver.iv_minor = fw_ver.iv_minor; 342 | node->fw_ver.iv_revision = fw_ver.iv_revision; 343 | node->fw_ver.iv_build_num = fw_ver.iv_build_num; 344 | udev->my_short_address = node->addr; 345 | udev->slot_id = node->slot_id; 346 | panmaster_postprocess(); 347 | uwb_pan_start(pan, UWB_PAN_ROLE_MASTER, NETWORK_ROLE_ANCHOR); 348 | } else { 349 | uwb_ccp_start(ccp, CCP_ROLE_RELAY); 350 | uwb_pan_start(pan, UWB_PAN_ROLE_RELAY, NETWORK_ROLE_ANCHOR); 351 | } 352 | printf("{\"device_id\":\"%lX\"",udev->device_id); 353 | printf(",\"panid\":\"%X\"",udev->pan_id); 354 | printf(",\"addr\":\"%X\"",udev->uid); 355 | printf(",\"part_id\":\"%lX\"",(uint32_t)(udev->euid&0xffffffff)); 356 | printf(",\"lot_id\":\"%lX\"}\n",(uint32_t)(udev->euid>>32)); 357 | 358 | tdma_instance_t * tdma = (tdma_instance_t*)uwb_mac_find_cb_inst_ptr(udev, UWBEXT_TDMA); 359 | assert(tdma); 360 | tdma_allocate_slots(tdma); 361 | 362 | #if MYNEWT_VAL(NCBWIFI_ESP_PASSTHROUGH) 363 | hal_bsp_esp_bypass(true); 364 | #endif 365 | 366 | while (1) { 367 | dpl_eventq_run(dpl_eventq_dflt_get()); 368 | } 369 | assert(0); 370 | return rc; 371 | } 372 | --------------------------------------------------------------------------------