Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
vacabun committed Jan 12, 2024
1 parent f16aa8c commit ab7ba6b
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 74 deletions.
23 changes: 0 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,4 @@ target_compile_definitions(app PRIVATE DS_TWR)
# target_compile_definitions(app PRIVATE LOG_LEVEL=LOG_LEVEL_INF)
target_compile_definitions(app PRIVATE LOG_LEVEL=LOG_LEVEL_DBG)

target_compile_definitions(app PRIVATE PAN_ID=0xAAAA)

if(TAG_DEF)
message("Build application for tag.")
target_compile_definitions(app PRIVATE DEVICE_TAG)
target_compile_definitions(app PRIVATE DEVICE_ADDR=0x0000000000000001)
endif()

if(ANCHOR_DEF)
message("Build application for anthor.")
target_compile_definitions(app PRIVATE DEVICE_ANCHOR)
target_compile_definitions(app PRIVATE DEVICE_ADDR=0x0000000000001001)
endif()

if(NODE_DEF)
message("Build application for tag.")
target_compile_definitions(app PRIVATE DEVICE_NODE)
# target_compile_definitions(app PRIVATE DEVICE_ADDR=0x0000000000000001)
target_compile_definitions(app PRIVATE DEVICE_ADDR=0x0000000000001001)
endif()

target_compile_definitions(app PRIVATE CONFIG_FPU)

target_compile_definitions(app PRIVATE CMAKE_EXPORT_COMPILE_COMMANDS=1)
25 changes: 21 additions & 4 deletions Kconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
config DEBUG_SWD
bool "Enable usage debug via swd in wfi mode"
default y

source "Kconfig.zephyr"
config DEVICE_ADDRESS
int "address of the device"
default 0
config DEVICE_PANID
int "PAN ID of the device"
default 1

choice
prompt "Device Type"
default DEVICE_TYPE_NODE
config DEVICE_TYPE_NODE
bool "Node"
config DEVICE_TYPE_TAG
bool "Tag"
config DEVICE_TYPE_ANCHOR
bool "Anchor"
endchoice

menu "Zephyr options"
source "Kconfig.zephyr"
endmenu
8 changes: 8 additions & 0 deletions include/config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef CONFIG_HPP
#define CONFIG_HPP

if


#endif // CONFIG_HPP

2 changes: 1 addition & 1 deletion include/device/anthor.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _ANTHOR_H_
#define _ANTHOR_H_

#if defined(DEVICE_ANCHOR)
#if CONFIG_DEVICE_TYPE_ANCHOR

#include "device/device.hpp"
#include <zephyr/sys/hash_map.h>
Expand Down
2 changes: 1 addition & 1 deletion include/device/node.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _NODE_HPP_
#define _NODE_HPP_

#if defined(DEVICE_NODE)
#if CONFIG_DEVICE_TYPE_NODE

#include "device/device.hpp"
#include <zephyr/sys/ring_buffer.h>
Expand Down
2 changes: 1 addition & 1 deletion include/device/tag.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _TAG_HPP_
#define _TAG_HPP_

#if defined(DEVICE_TAG)
#if CONFIG_DEVICE_TYPE_TAG

#include "device/device.hpp"
#include <zephyr/sys/hash_map.h>
Expand Down
60 changes: 43 additions & 17 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,55 @@
clean:
rm -rf $(CURDIR)/build
rm prj.conf
rm prj.conf.template
rm boards/stm32f401_mini.overlay
dw1000:
cp $(CURDIR)/boards/stm32f401_mini_dw1000.overlay $(CURDIR)/boards/stm32f401_mini.overlay
if grep -q 'CONFIG_DW3000=y' $(CURDIR)/prj.conf; then \
sed -i 's/CONFIG_DW3000=y/CONFIG_DW3000=n/g' prj.conf; \
fi
if grep -q 'CONFIG_DW1000=n' $(CURDIR)/prj.conf; then \
sed -i 's/CONFIG_DW1000=n/CONFIG_DW1000=y/g' prj.conf; \
fi
cp $(CURDIR)/prj.conf.dw1000 $(CURDIR)/prj.conf.template
dw3000:
cp $(CURDIR)/boards/stm32f401_mini_dw3000.overlay $(CURDIR)/boards/stm32f401_mini.overlay
if grep -q 'CONFIG_DW3000=n' $(CURDIR)/prj.conf; then \
sed -i 's/CONFIG_DW3000=n/CONFIG_DW3000=y/g' prj.conf; \
fi
if grep -q 'CONFIG_DW1000=y' $(CURDIR)/prj.conf; then \
sed -i 's/CONFIG_DW1000=y/CONFIG_DW1000=n/g' prj.conf; \
fi
cp $(CURDIR)/prj.conf.dw3000 $(CURDIR)/prj.conf.template
tag:
west build -- -DTAG_DEF=ON -DANCHOR_DEF=OFF -DNODE_DEF=OFF
cp $(CURDIR)/prj.conf.template $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_TYPE_TAG=y" >> $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_ADDRESS=1" >> $(CURDIR)/prj.conf
west build
anchor:
west build -- -DTAG_DEF=OFF -DANCHOR_DEF=ON -DNODE_DEF=OFF
cp $(CURDIR)/prj.conf.template $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_TYPE_ANCHOR=y" >> $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_ADDRESS=4097" >> $(CURDIR)/prj.conf
west build
node:
west build -- -DTAG_DEF=OFF -DANCHOR_DEF=OFF -DNODE_DEF=ON
cp $(CURDIR)/prj.conf.template $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_TYPE_NODE=y" >> $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_ADDRESS=1" >> $(CURDIR)/prj.conf
west build

test:
west build -- -DTAG_DEF=ON -DANCHOR_DEF=OFF -DNODE_DEF=OFF
cp $(CURDIR)/prj.conf.template $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_TYPE_ANCHOR=y" >> $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_ADDRESS=4097" >> $(CURDIR)/prj.conf

west build
west flash -r openocd --config boards/stlink.cfg
west build -- -DTAG_DEF=OFF -DANCHOR_DEF=ON -DNODE_DEF=OFF

cp $(CURDIR)/prj.conf.template $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_TYPE_TAG=y" >> $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_ADDRESS=1" >> $(CURDIR)/prj.conf

west build
west flash -r openocd --config boards/daplink.cfg

test_node:
cp $(CURDIR)/prj.conf.template $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_TYPE_NODE=y" >> $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_ADDRESS=1" >> $(CURDIR)/prj.conf

west build
west flash -r openocd --config boards/stlink.cfg

cp $(CURDIR)/prj.conf.template $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_TYPE_NODE=y" >> $(CURDIR)/prj.conf
echo "CONFIG_DEVICE_ADDRESS=2" >> $(CURDIR)/prj.conf
west build
west flash -r openocd --config boards/daplink.cfg
7 changes: 4 additions & 3 deletions prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ CONFIG_UART_LINE_CTRL=y

CONFIG_SPI=y
CONFIG_GPIO=y
CONFIG_DEBUG_SWD=y

CONFIG_SHELL=y
CONFIG_LOG=y
CONFIG_CBPRINTF_FP_SUPPORT=y

CONFIG_JSON_LIBRARY=y

CONFIG_DW3000=n
CONFIG_DW1000=y
CONFIG_DW3000=y
CONFIG_DW1000=n
CONFIG_DEVICE_TYPE_NODE=y
CONFIG_DEVICE_ADDRESS=1
29 changes: 29 additions & 0 deletions prj.conf.dw1000
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CONFIG_CPP=y
CONFIG_CPP_MAIN=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_SYS_HASH_MAP_CHOICE_CXX=y
CONFIG_SYS_HASH_MAP=y
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=1024

CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_VID=0x2FE4
CONFIG_USB_DEVICE_PRODUCT="USB console"
CONFIG_USB_DEVICE_MANUFACTURER="vacabun"

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y

CONFIG_SPI=y
CONFIG_GPIO=y

CONFIG_SHELL=y
CONFIG_LOG=y
CONFIG_CBPRINTF_FP_SUPPORT=y

CONFIG_JSON_LIBRARY=y


CONFIG_DW1000=y
CONFIG_DW1000=n
28 changes: 28 additions & 0 deletions prj.conf.dw3000
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CONFIG_CPP=y
CONFIG_CPP_MAIN=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_SYS_HASH_MAP_CHOICE_CXX=y
CONFIG_SYS_HASH_MAP=y
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=1024

CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_VID=0x2FE4
CONFIG_USB_DEVICE_PRODUCT="USB console"
CONFIG_USB_DEVICE_MANUFACTURER="vacabun"

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y

CONFIG_SPI=y
CONFIG_GPIO=y

CONFIG_SHELL=y
CONFIG_LOG=y
CONFIG_CBPRINTF_FP_SUPPORT=y

CONFIG_JSON_LIBRARY=y

CONFIG_DW3000=y
CONFIG_DW1000=n
28 changes: 28 additions & 0 deletions prj.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CONFIG_CPP=y
CONFIG_CPP_MAIN=y
CONFIG_LIB_CPLUSPLUS=y
CONFIG_SYS_HASH_MAP_CHOICE_CXX=y
CONFIG_SYS_HASH_MAP=y
CONFIG_MINIMAL_LIBC_MALLOC_ARENA_SIZE=1024

CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_VID=0x2FE4
CONFIG_USB_DEVICE_PRODUCT="USB console"
CONFIG_USB_DEVICE_MANUFACTURER="vacabun"

CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y

CONFIG_SPI=y
CONFIG_GPIO=y

CONFIG_SHELL=y
CONFIG_LOG=y
CONFIG_CBPRINTF_FP_SUPPORT=y

CONFIG_JSON_LIBRARY=y

CONFIG_DW3000=y
CONFIG_DW1000=n
5 changes: 4 additions & 1 deletion src/device/anthor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <msg/twr_response.hpp>
#include <msg/twr_report.hpp>

#if defined(DEVICE_ANCHOR)
#if CONFIG_DEVICE_TYPE_ANCHOR

LOG_MODULE_REGISTER(anthor, LOG_LEVEL);
#if defined(DS_TWR)
Expand All @@ -30,6 +30,9 @@ void Anthor::app(void *p1, void *p2, void *p3)
// dwt_rxenable(DWT_START_RX_IMMEDIATE);
// }
// k_mutex_unlock(&transceiver_mutex);
#endif
#if CONFIG_DW3000
dwt_rxenable(DWT_START_RX_IMMEDIATE);
#endif
k_sleep(K_SECONDS(1));
}
Expand Down
6 changes: 3 additions & 3 deletions src/device/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Device::Device()
LOG_DBG("DEV INIT FAILED");
}

LOG_INF("Device ID: 0x%lx", dwt_readdevid());
LOG_INF("Device ID: 0x%x", dwt_readdevid());
#if CONFIG_DW1000
dw1000_spi_speed_fast();
#endif
Expand Down Expand Up @@ -167,8 +167,8 @@ Device::Device()

k_sleep(K_MSEC(100));

device_address = DEVICE_ADDR;
pan_id = PAN_ID;
device_address = CONFIG_DEVICE_ADDRESS;
pan_id = CONFIG_DEVICE_PANID;

LOG_INF("pan_id: %04X", pan_id);
LOG_INF("device_address: %016llX", device_address);
Expand Down
2 changes: 1 addition & 1 deletion src/device/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#define SPEED_OF_LIGHT (299702547)

#if defined(DEVICE_NODE)
#if CONFIG_DEVICE_TYPE_NODE

LOG_MODULE_REGISTER(node, LOG_LEVEL);

Expand Down
4 changes: 2 additions & 2 deletions src/device/tag.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define SPEED_OF_LIGHT (299702547)

#if defined(DEVICE_TAG)
#if CONFIG_DEVICE_TYPE_TAG

LOG_MODULE_REGISTER(tag, LOG_LEVEL);

Expand Down Expand Up @@ -191,7 +191,7 @@ void Tag::msg_process_cb(uint8_t *msg_recv, uint16_t msg_recv_len, uint64_t src_

sys_hashmap_insert(&measure_res, src_addr, (uint64_t)(distance * 1000), NULL);

LOG_INF("distance from %016llx to %016llx is %lfcm", src_addr, device_address, distance);
LOG_INF("distance from %016llx to %016llx is %lfm", src_addr, device_address, distance);

k_sem_give(&measure_finish_sem);
}
Expand Down
Loading

0 comments on commit ab7ba6b

Please sign in to comment.