From 08c816b7c72531ffab514347dd204bc6608332ef Mon Sep 17 00:00:00 2001 From: Torsten Robitzki Date: Wed, 17 Apr 2019 17:16:10 +0200 Subject: [PATCH 1/6] create hardware abstractions to prepare blinky (and later other examples) to run on different hardware --- examples/CMakeLists.txt | 3 +++ examples/blinky.cpp | 13 +++---------- examples/hal/CMakeLists.txt | 5 +++++ examples/hal/io.cpp | 19 +++++++++++++++++++ examples/hal/io.hpp | 10 ++++++++++ 5 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 examples/hal/CMakeLists.txt create mode 100644 examples/hal/io.cpp create mode 100644 examples/hal/io.hpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2f94bc20..75855733 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -25,6 +25,8 @@ add_subdirectory(${BINDING}_toolchain_support) add_compile_options(-ftemplate-backtrace-limit=0 -fvisibility-inlines-hidden -fno-rtti -fno-exceptions) #bluetoe library add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/bluetoe) +# Some hardware abstractions, required by the examples +add_subdirectory(hal) function(add_bluetoe_example target_name) add_executable(${target_name} ${target_name}.cpp runtime.cpp) set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${target_name}.elf) @@ -34,6 +36,7 @@ function(add_bluetoe_example target_name) bluetoe::bindings::nrf51 startup::${BINDING} toolchain::${BINDING} + example_hal -lm -lstdc++ -lsupc++ -T${CMAKE_CURRENT_BINARY_DIR}/${BINDING}_toolchain_support/linker_script.ld -Wl,--gc-sections -Wl,--warn-common diff --git a/examples/blinky.cpp b/examples/blinky.cpp index 69aa3ee4..04c868fe 100644 --- a/examples/blinky.cpp +++ b/examples/blinky.cpp @@ -1,17 +1,13 @@ #include #include -#include +#include "hal/io.hpp" using namespace bluetoe; -static constexpr int io_pin = 21; - static std::uint8_t io_pin_write_handler( bool state ) { // the GPIO pin according to the received value: 0 = off, 1 = on - NRF_GPIO->OUT = state - ? NRF_GPIO->OUT | ( 1 << io_pin ) - : NRF_GPIO->OUT & ~( 1 << io_pin ); + set_led( state ); return error_codes::success; } @@ -31,10 +27,7 @@ device< blinky_server > gatt_srv; int main() { - // Init GPIO pin - NRF_GPIO->PIN_CNF[ io_pin ] = - ( GPIO_PIN_CNF_DRIVE_S0H1 << GPIO_PIN_CNF_DRIVE_Pos ) | - ( GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos ); + init_led(); for ( ;; ) gatt_srv.run( gatt ); diff --git a/examples/hal/CMakeLists.txt b/examples/hal/CMakeLists.txt new file mode 100644 index 00000000..57a39cb3 --- /dev/null +++ b/examples/hal/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_policy(SET CMP0079 NEW) + +add_library(example_hal STATIC io.cpp) +target_link_libraries(example_hal PRIVATE toolchain::${BINDING}) +target_include_directories(example_hal PUBLIC ..) \ No newline at end of file diff --git a/examples/hal/io.cpp b/examples/hal/io.cpp new file mode 100644 index 00000000..6bf3e9b0 --- /dev/null +++ b/examples/hal/io.cpp @@ -0,0 +1,19 @@ +#include +#include + +static constexpr int io_pin = 21; + +void init_led() +{ + // Init GPIO pin + NRF_GPIO->PIN_CNF[ io_pin ] = + ( GPIO_PIN_CNF_DRIVE_S0H1 << GPIO_PIN_CNF_DRIVE_Pos ) | + ( GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos ); +} + +void set_led( bool state ) +{ + NRF_GPIO->OUT = state + ? NRF_GPIO->OUT | ( 1 << io_pin ) + : NRF_GPIO->OUT & ~( 1 << io_pin ); +} diff --git a/examples/hal/io.hpp b/examples/hal/io.hpp new file mode 100644 index 00000000..d0ab21d4 --- /dev/null +++ b/examples/hal/io.hpp @@ -0,0 +1,10 @@ +#ifndef BLUETOE_EXAMPLES_HAL_IO_HPP +#define BLUETOE_EXAMPLES_HAL_IO_HPP + +/** + * @TODO this needs some more work (but not to much!!!) + */ +void init_led(); +void set_led( bool state ); + +#endif From f66a75f7236009b41be6f1e0343bc1a8edc02b2f Mon Sep 17 00:00:00 2001 From: Torsten Robitzki Date: Thu, 18 Apr 2019 16:37:06 +0200 Subject: [PATCH 2/6] Split bluetoe/link_layer into the scheduled_radio based link_layer implementation and a part that will most likely be relevant for every/most link layer implementations. --- CMakeLists.txt | 1 + bluetoe/bindings/nrf51/CMakeLists.txt | 12 +++++++++- bluetoe/scheduled_radio/CMakeLists.txt | 5 +++++ .../include/bluetoe/advertising.hpp | 8 +++---- .../include/bluetoe/link_layer.hpp | 22 +++++++++---------- .../include/bluetoe/ll_data_pdu_buffer.hpp | 0 .../include/bluetoe/ring_buffer.hpp | 2 +- .../scheduled_radio.hpp | 0 tests/CMakeLists.txt | 10 ++++++++- tests/link_layer/CMakeLists.txt | 22 +++++++++---------- tests/test_tools/CMakeLists.txt | 2 +- 11 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 bluetoe/scheduled_radio/CMakeLists.txt rename bluetoe/{link_layer => scheduled_radio}/include/bluetoe/advertising.hpp (99%) rename bluetoe/{link_layer => scheduled_radio}/include/bluetoe/link_layer.hpp (99%) rename bluetoe/{link_layer => scheduled_radio}/include/bluetoe/ll_data_pdu_buffer.hpp (100%) rename bluetoe/{link_layer => scheduled_radio}/include/bluetoe/ring_buffer.hpp (99%) rename bluetoe/{link_layer => scheduled_radio}/scheduled_radio.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c3cbaa4..f226b6cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ add_library(bluetoe::iface ALIAS bluetoe_iface) target_include_directories(bluetoe_iface INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory(bluetoe/link_layer) +add_subdirectory(bluetoe/scheduled_radio) add_subdirectory(bluetoe/utility) add_subdirectory(bluetoe/sm) add_subdirectory(bluetoe/services) diff --git a/bluetoe/bindings/nrf51/CMakeLists.txt b/bluetoe/bindings/nrf51/CMakeLists.txt index 242934f6..7aaf5b02 100644 --- a/bluetoe/bindings/nrf51/CMakeLists.txt +++ b/bluetoe/bindings/nrf51/CMakeLists.txt @@ -4,6 +4,16 @@ add_library(bluetoe::bindings::nrf51 ALIAS bluetoe_bindings_nrf51) target_include_directories(bluetoe_bindings_nrf51 PUBLIC include) -target_link_libraries(bluetoe_bindings_nrf51 PUBLIC bluetoe::utility bluetoe::sm bluetoe::iface bluetoe::linklayer PRIVATE toolchain::${BINDING}) +target_link_libraries(bluetoe_bindings_nrf51 + PUBLIC + bluetoe::utility + bluetoe::sm + bluetoe::iface + bluetoe::linklayer + bluetoe::scheduled_radio + PRIVATE + toolchain::${BINDING} +) + target_compile_features(bluetoe_bindings_nrf51 PRIVATE cxx_std_11) target_compile_options(bluetoe_bindings_nrf51 PRIVATE -Wall -pedantic -Wextra -Wfatal-errors -Wno-parentheses) diff --git a/bluetoe/scheduled_radio/CMakeLists.txt b/bluetoe/scheduled_radio/CMakeLists.txt new file mode 100644 index 00000000..0c3b827e --- /dev/null +++ b/bluetoe/scheduled_radio/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(bluetoe_scheduled_radio INTERFACE) +add_library(bluetoe::scheduled_radio ALIAS bluetoe_scheduled_radio) + +target_include_directories(bluetoe_scheduled_radio INTERFACE include) +target_compile_features(bluetoe_linklayer PRIVATE cxx_std_11) diff --git a/bluetoe/link_layer/include/bluetoe/advertising.hpp b/bluetoe/scheduled_radio/include/bluetoe/advertising.hpp similarity index 99% rename from bluetoe/link_layer/include/bluetoe/advertising.hpp rename to bluetoe/scheduled_radio/include/bluetoe/advertising.hpp index 12641c93..649759cc 100644 --- a/bluetoe/link_layer/include/bluetoe/advertising.hpp +++ b/bluetoe/scheduled_radio/include/bluetoe/advertising.hpp @@ -2,10 +2,10 @@ #define BLUETOE_LINK_LAYER_ADVERTISING_HPP #include -#include "address.hpp" -#include "buffer.hpp" -#include "delta_time.hpp" -#include "ll_meta_types.hpp" +#include +#include +#include +#include /** * @file bluetoe/link_layer/advertising.hpp diff --git a/bluetoe/link_layer/include/bluetoe/link_layer.hpp b/bluetoe/scheduled_radio/include/bluetoe/link_layer.hpp similarity index 99% rename from bluetoe/link_layer/include/bluetoe/link_layer.hpp rename to bluetoe/scheduled_radio/include/bluetoe/link_layer.hpp index 7045454a..46477c73 100644 --- a/bluetoe/link_layer/include/bluetoe/link_layer.hpp +++ b/bluetoe/scheduled_radio/include/bluetoe/link_layer.hpp @@ -1,17 +1,17 @@ #ifndef BLUETOE_LINK_LAYER_LINK_LAYER_HPP #define BLUETOE_LINK_LAYER_LINK_LAYER_HPP -#include "buffer.hpp" -#include "delta_time.hpp" -#include "ll_options.hpp" -#include "address.hpp" -#include "channel_map.hpp" -#include "notification_queue.hpp" -#include "connection_callbacks.hpp" -#include "connection_event_callback.hpp" -#include "l2cap_signaling_channel.hpp" -#include "white_list.hpp" -#include "advertising.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/bluetoe/link_layer/include/bluetoe/ll_data_pdu_buffer.hpp b/bluetoe/scheduled_radio/include/bluetoe/ll_data_pdu_buffer.hpp similarity index 100% rename from bluetoe/link_layer/include/bluetoe/ll_data_pdu_buffer.hpp rename to bluetoe/scheduled_radio/include/bluetoe/ll_data_pdu_buffer.hpp diff --git a/bluetoe/link_layer/include/bluetoe/ring_buffer.hpp b/bluetoe/scheduled_radio/include/bluetoe/ring_buffer.hpp similarity index 99% rename from bluetoe/link_layer/include/bluetoe/ring_buffer.hpp rename to bluetoe/scheduled_radio/include/bluetoe/ring_buffer.hpp index eb525957..9d0a61b0 100644 --- a/bluetoe/link_layer/include/bluetoe/ring_buffer.hpp +++ b/bluetoe/scheduled_radio/include/bluetoe/ring_buffer.hpp @@ -5,7 +5,7 @@ #include #include -#include "buffer.hpp" +#include namespace bluetoe { namespace link_layer { diff --git a/bluetoe/link_layer/scheduled_radio.hpp b/bluetoe/scheduled_radio/scheduled_radio.hpp similarity index 100% rename from bluetoe/link_layer/scheduled_radio.hpp rename to bluetoe/scheduled_radio/scheduled_radio.hpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7d26d8d9..606c4d47 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -13,7 +13,15 @@ function(add_and_register_test test_runner) add_executable(${test_runner} ${test_runner}.cpp) target_include_directories(${test_runner} PRIVATE ${Boost_INCLUDE_DIR}) - target_link_libraries(${test_runner} PRIVATE bluetoe::iface bluetoe::linklayer bluetoe::sm bluetoe::utility test::tools) + target_link_libraries(${test_runner} + PRIVATE + bluetoe::iface + bluetoe::linklayer + bluetoe::sm + bluetoe::utility + test::tools + ${ARGN} + ) target_compile_features(${test_runner} PRIVATE cxx_std_11) if (BLUETOE_EXCLUDE_SLOW_TESTS) diff --git a/tests/link_layer/CMakeLists.txt b/tests/link_layer/CMakeLists.txt index 18e78d17..cb3a9950 100644 --- a/tests/link_layer/CMakeLists.txt +++ b/tests/link_layer/CMakeLists.txt @@ -1,17 +1,17 @@ -add_and_register_test(ll_advertising_tests) +add_and_register_test(ll_advertising_tests bluetoe::scheduled_radio) add_and_register_test(address_tests) add_and_register_test(channel_map_tests) add_and_register_test(delta_time_tests) -add_and_register_test(ll_data_pdu_buffer_tests) -add_and_register_test(ll_connection_tests) -add_and_register_test(ll_connecting_tests) -add_and_register_test(ll_control_tests) -add_and_register_test(ll_data_tests) -add_and_register_test(ring_buffer_tests) +add_and_register_test(ll_data_pdu_buffer_tests bluetoe::scheduled_radio) +add_and_register_test(ll_connection_tests bluetoe::scheduled_radio) +add_and_register_test(ll_connecting_tests bluetoe::scheduled_radio) +add_and_register_test(ll_control_tests bluetoe::scheduled_radio) +add_and_register_test(ll_data_tests bluetoe::scheduled_radio) +add_and_register_test(ring_buffer_tests bluetoe::scheduled_radio) add_and_register_test(notification_queue_tests) -add_and_register_test(connection_callbacks_tests) +add_and_register_test(connection_callbacks_tests bluetoe::scheduled_radio) add_and_register_test(signaling_channel_tests) add_and_register_test(white_list_tests) -add_and_register_test(connection_parameter_update_procedure_tests) -add_and_register_test(test_radio_tests) -add_and_register_test(advertiser_tests) +add_and_register_test(connection_parameter_update_procedure_tests bluetoe::scheduled_radio) +add_and_register_test(test_radio_tests bluetoe::scheduled_radio) +add_and_register_test(advertiser_tests bluetoe::scheduled_radio) diff --git a/tests/test_tools/CMakeLists.txt b/tests/test_tools/CMakeLists.txt index 9f81531b..b486074b 100644 --- a/tests/test_tools/CMakeLists.txt +++ b/tests/test_tools/CMakeLists.txt @@ -11,7 +11,7 @@ add_library(test::tools ALIAS test_tools) target_include_directories(test_tools PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_include_directories(test_tools PRIVATE ${Boost_INCLUDE_DIR}) -target_link_libraries(test_tools PRIVATE bluetoe::linklayer) +target_link_libraries(test_tools PRIVATE bluetoe::linklayer bluetoe::scheduled_radio) target_compile_features(test_tools PRIVATE cxx_std_11) target_compile_definitions(test_tools PRIVATE "") From 6265560f5ea34a4b1bbaac65df4e2ba2543702de Mon Sep 17 00:00:00 2001 From: Torsten Robitzki Date: Thu, 18 Apr 2019 16:54:55 +0200 Subject: [PATCH 3/6] also split tests into link_layer and scheduled_radio --- tests/CMakeLists.txt | 1 + tests/link_layer/CMakeLists.txt | 11 ----------- tests/scheduled_radio/CMakeLists.txt | 15 +++++++++++++++ .../advertiser_tests.cpp | 0 .../{link_layer => scheduled_radio}/connected.hpp | 0 .../connection_callbacks_tests.cpp | 0 ...onnection_parameter_update_procedure_tests.cpp | 0 .../ll_advertising_tests.cpp | 0 .../ll_connecting_tests.cpp | 0 .../ll_connection_tests.cpp | 0 .../ll_control_tests.cpp | 0 .../ll_data_pdu_buffer_tests.cpp | 0 .../ll_data_tests.cpp | 0 .../ring_buffer_tests.cpp | 0 .../test_radio_tests.cpp | 0 15 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 tests/scheduled_radio/CMakeLists.txt rename tests/{link_layer => scheduled_radio}/advertiser_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/connected.hpp (100%) rename tests/{link_layer => scheduled_radio}/connection_callbacks_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/connection_parameter_update_procedure_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/ll_advertising_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/ll_connecting_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/ll_connection_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/ll_control_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/ll_data_pdu_buffer_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/ll_data_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/ring_buffer_tests.cpp (100%) rename tests/{link_layer => scheduled_radio}/test_radio_tests.cpp (100%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 606c4d47..4f038f24 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -52,3 +52,4 @@ add_subdirectory(att) add_subdirectory(link_layer) add_subdirectory(services) add_subdirectory(security_manager) +add_subdirectory(scheduled_radio) diff --git a/tests/link_layer/CMakeLists.txt b/tests/link_layer/CMakeLists.txt index cb3a9950..a9f717d1 100644 --- a/tests/link_layer/CMakeLists.txt +++ b/tests/link_layer/CMakeLists.txt @@ -1,17 +1,6 @@ -add_and_register_test(ll_advertising_tests bluetoe::scheduled_radio) add_and_register_test(address_tests) add_and_register_test(channel_map_tests) add_and_register_test(delta_time_tests) -add_and_register_test(ll_data_pdu_buffer_tests bluetoe::scheduled_radio) -add_and_register_test(ll_connection_tests bluetoe::scheduled_radio) -add_and_register_test(ll_connecting_tests bluetoe::scheduled_radio) -add_and_register_test(ll_control_tests bluetoe::scheduled_radio) -add_and_register_test(ll_data_tests bluetoe::scheduled_radio) -add_and_register_test(ring_buffer_tests bluetoe::scheduled_radio) add_and_register_test(notification_queue_tests) -add_and_register_test(connection_callbacks_tests bluetoe::scheduled_radio) add_and_register_test(signaling_channel_tests) add_and_register_test(white_list_tests) -add_and_register_test(connection_parameter_update_procedure_tests bluetoe::scheduled_radio) -add_and_register_test(test_radio_tests bluetoe::scheduled_radio) -add_and_register_test(advertiser_tests bluetoe::scheduled_radio) diff --git a/tests/scheduled_radio/CMakeLists.txt b/tests/scheduled_radio/CMakeLists.txt new file mode 100644 index 00000000..48adb7f7 --- /dev/null +++ b/tests/scheduled_radio/CMakeLists.txt @@ -0,0 +1,15 @@ +function(add_and_register_ll_test name) + add_and_register_test(${name} bluetoe::scheduled_radio) +endfunction() + +add_and_register_ll_test(ll_advertising_tests) +add_and_register_ll_test(ll_data_pdu_buffer_tests) +add_and_register_ll_test(ll_connection_tests) +add_and_register_ll_test(ll_connecting_tests) +add_and_register_ll_test(ll_control_tests) +add_and_register_ll_test(ll_data_tests) +add_and_register_ll_test(ring_buffer_tests) +add_and_register_ll_test(connection_callbacks_tests) +add_and_register_ll_test(connection_parameter_update_procedure_tests) +add_and_register_ll_test(test_radio_tests) +add_and_register_ll_test(advertiser_tests) diff --git a/tests/link_layer/advertiser_tests.cpp b/tests/scheduled_radio/advertiser_tests.cpp similarity index 100% rename from tests/link_layer/advertiser_tests.cpp rename to tests/scheduled_radio/advertiser_tests.cpp diff --git a/tests/link_layer/connected.hpp b/tests/scheduled_radio/connected.hpp similarity index 100% rename from tests/link_layer/connected.hpp rename to tests/scheduled_radio/connected.hpp diff --git a/tests/link_layer/connection_callbacks_tests.cpp b/tests/scheduled_radio/connection_callbacks_tests.cpp similarity index 100% rename from tests/link_layer/connection_callbacks_tests.cpp rename to tests/scheduled_radio/connection_callbacks_tests.cpp diff --git a/tests/link_layer/connection_parameter_update_procedure_tests.cpp b/tests/scheduled_radio/connection_parameter_update_procedure_tests.cpp similarity index 100% rename from tests/link_layer/connection_parameter_update_procedure_tests.cpp rename to tests/scheduled_radio/connection_parameter_update_procedure_tests.cpp diff --git a/tests/link_layer/ll_advertising_tests.cpp b/tests/scheduled_radio/ll_advertising_tests.cpp similarity index 100% rename from tests/link_layer/ll_advertising_tests.cpp rename to tests/scheduled_radio/ll_advertising_tests.cpp diff --git a/tests/link_layer/ll_connecting_tests.cpp b/tests/scheduled_radio/ll_connecting_tests.cpp similarity index 100% rename from tests/link_layer/ll_connecting_tests.cpp rename to tests/scheduled_radio/ll_connecting_tests.cpp diff --git a/tests/link_layer/ll_connection_tests.cpp b/tests/scheduled_radio/ll_connection_tests.cpp similarity index 100% rename from tests/link_layer/ll_connection_tests.cpp rename to tests/scheduled_radio/ll_connection_tests.cpp diff --git a/tests/link_layer/ll_control_tests.cpp b/tests/scheduled_radio/ll_control_tests.cpp similarity index 100% rename from tests/link_layer/ll_control_tests.cpp rename to tests/scheduled_radio/ll_control_tests.cpp diff --git a/tests/link_layer/ll_data_pdu_buffer_tests.cpp b/tests/scheduled_radio/ll_data_pdu_buffer_tests.cpp similarity index 100% rename from tests/link_layer/ll_data_pdu_buffer_tests.cpp rename to tests/scheduled_radio/ll_data_pdu_buffer_tests.cpp diff --git a/tests/link_layer/ll_data_tests.cpp b/tests/scheduled_radio/ll_data_tests.cpp similarity index 100% rename from tests/link_layer/ll_data_tests.cpp rename to tests/scheduled_radio/ll_data_tests.cpp diff --git a/tests/link_layer/ring_buffer_tests.cpp b/tests/scheduled_radio/ring_buffer_tests.cpp similarity index 100% rename from tests/link_layer/ring_buffer_tests.cpp rename to tests/scheduled_radio/ring_buffer_tests.cpp diff --git a/tests/link_layer/test_radio_tests.cpp b/tests/scheduled_radio/test_radio_tests.cpp similarity index 100% rename from tests/link_layer/test_radio_tests.cpp rename to tests/scheduled_radio/test_radio_tests.cpp From e5578950ad9fd92cf6169b7ff51092de0648f3ca Mon Sep 17 00:00:00 2001 From: Torsten Robitzki Date: Thu, 18 Apr 2019 17:10:31 +0200 Subject: [PATCH 4/6] general files / build structure including HCI / targets that do not run on embedded hardware --- CMakeLists.txt | 7 +- bluetoe/bindings/hci/CMakeLists.txt | 13 +++ .../hci/include_libusb/bluetoe/device.hpp | 17 +++ bluetoe/bindings/hci/libusb.cpp | 0 bluetoe/bindings/nrf51/CMakeLists.txt | 3 + bluetoe/hci/CMakeLists.txt | 7 ++ bluetoe/hci/include/bluetoe/link_layer.hpp | 63 +++++++++++ bluetoe/link_layer/CMakeLists.txt | 1 - examples/CMakeLists.txt | 106 ++++++++++++------ examples/hal/CMakeLists.txt | 7 +- 10 files changed, 187 insertions(+), 37 deletions(-) create mode 100644 bluetoe/bindings/hci/CMakeLists.txt create mode 100644 bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp create mode 100644 bluetoe/bindings/hci/libusb.cpp create mode 100644 bluetoe/hci/CMakeLists.txt create mode 100644 bluetoe/hci/include/bluetoe/link_layer.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index f226b6cc..cc0c5900 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,16 +7,21 @@ project(lib_bluetoe CXX) add_library(bluetoe_iface INTERFACE) add_library(bluetoe::iface ALIAS bluetoe_iface) target_include_directories(bluetoe_iface INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_features(bluetoe_iface INTERFACE cxx_std_11) + add_subdirectory(bluetoe/link_layer) add_subdirectory(bluetoe/scheduled_radio) +add_subdirectory(bluetoe/hci) add_subdirectory(bluetoe/utility) add_subdirectory(bluetoe/sm) add_subdirectory(bluetoe/services) if (CMAKE_CROSSCOMPILING) add_subdirectory(bluetoe/bindings/nrf51) -endif () +endif() + +add_subdirectory(bluetoe/bindings/hci) if (NOT CMAKE_CROSSCOMPILING) enable_testing() diff --git a/bluetoe/bindings/hci/CMakeLists.txt b/bluetoe/bindings/hci/CMakeLists.txt new file mode 100644 index 00000000..b66e4662 --- /dev/null +++ b/bluetoe/bindings/hci/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(bluetoe_bindings_hci_libusb STATIC libusb.cpp) +add_library(bluetoe::bindings::hci_libusb ALIAS bluetoe_bindings_hci_libusb) + +target_include_directories(bluetoe_bindings_hci_libusb + INTERFACE + include_libusb) + +target_link_libraries(bluetoe_bindings_hci_libusb + PUBLIC + bluetoe::hci + bluetoe::utility + bluetoe::linklayer +) diff --git a/bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp b/bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp new file mode 100644 index 00000000..cad35f66 --- /dev/null +++ b/bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp @@ -0,0 +1,17 @@ +#ifndef BLUETOE_BINDINGS_HCI_DEVICE_HPP +#define BLUETOE_BINDINGS_HCI_DEVICE_HPP + +#include + +namespace bluetoe +{ + namespace hci_details { + struct libsub_transport {}; + } + + template < class Server, typename ... Options > + using device = bluetoe::hci::link_layer< Server, hci_details::libsub_transport, Options... >; +} + +#endif + diff --git a/bluetoe/bindings/hci/libusb.cpp b/bluetoe/bindings/hci/libusb.cpp new file mode 100644 index 00000000..e69de29b diff --git a/bluetoe/bindings/nrf51/CMakeLists.txt b/bluetoe/bindings/nrf51/CMakeLists.txt index 7aaf5b02..1c76e66e 100644 --- a/bluetoe/bindings/nrf51/CMakeLists.txt +++ b/bluetoe/bindings/nrf51/CMakeLists.txt @@ -2,6 +2,9 @@ add_library(bluetoe_bindings_nrf51 STATIC nrf51.cpp) add_library(bluetoe::bindings::nrf51 ALIAS bluetoe_bindings_nrf51) +# Currently nrf52 is equal to nrf51, which is wrong if one looks at the details +add_library(bluetoe::bindings::nrf52 ALIAS bluetoe_bindings_nrf51) + target_include_directories(bluetoe_bindings_nrf51 PUBLIC include) target_link_libraries(bluetoe_bindings_nrf51 diff --git a/bluetoe/hci/CMakeLists.txt b/bluetoe/hci/CMakeLists.txt new file mode 100644 index 00000000..1e1ff61c --- /dev/null +++ b/bluetoe/hci/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_policy(SET CMP0079 NEW) + +add_library(bluetoe_hci INTERFACE) +add_library(bluetoe::hci ALIAS bluetoe_hci) + +target_include_directories(bluetoe_hci INTERFACE include) +target_link_libraries(bluetoe_hci INTERFACE bluetoe::sm bluetoe::iface) diff --git a/bluetoe/hci/include/bluetoe/link_layer.hpp b/bluetoe/hci/include/bluetoe/link_layer.hpp new file mode 100644 index 00000000..0338b18e --- /dev/null +++ b/bluetoe/hci/include/bluetoe/link_layer.hpp @@ -0,0 +1,63 @@ +#ifndef BLUETOE_HCI_LINK_LAYER_HPP +#define BLUETOE_HCI_LINK_LAYER_HPP + +#include + +namespace bluetoe { +namespace hci { + + /** + * @brief link layer implementation based on HCI + */ + template < + class Server, + class Transport, + typename ... Options + > + class link_layer + { + public: + /** + * @brief this function passes the CPU to the link layer implementation + * + * This function should return on certain events to alow user code to do + * usefull things. Details depend on the ScheduleRadio implemention. + */ + void run( Server& ); + + /** + * @brief initiating the change of communication parameters of an established connection + * + * If it was not possible to initiate the connection parameter update, the function returns false. + * @todo Add parameter that identifies the connection. + */ + bool connection_parameter_update_request( std::uint16_t interval_min, std::uint16_t interval_max, std::uint16_t latency, std::uint16_t timeout ); + + /** + * @brief terminates the give connection + * + * @todo Add parameter that identifies the connection. + */ + void disconnect(); + + /** + * @brief fills the given buffer with l2cap advertising payload + */ + std::size_t fill_l2cap_advertising_data( std::uint8_t* buffer, std::size_t buffer_size ) const; + + /** + * @brief returns the own local device address + */ + const bluetoe::link_layer::device_address& local_address() const; + private: + }; + + // implementation + template < class Server, class Transport, typename ... Options > + void link_layer< Server, Transport, Options... >::run( Server& ) + { + } +} +} + +#endif diff --git a/bluetoe/link_layer/CMakeLists.txt b/bluetoe/link_layer/CMakeLists.txt index b40e40b2..73652128 100644 --- a/bluetoe/link_layer/CMakeLists.txt +++ b/bluetoe/link_layer/CMakeLists.txt @@ -6,6 +6,5 @@ add_library(bluetoe_linklayer STATIC add_library(bluetoe::linklayer ALIAS bluetoe_linklayer) target_include_directories(bluetoe_linklayer PUBLIC include) -target_link_libraries(bluetoe_linklayer PRIVATE bluetoe::sm bluetoe::iface) target_compile_features(bluetoe_linklayer PRIVATE cxx_std_11) target_compile_options(bluetoe_linklayer PRIVATE -Wall -pedantic -Wextra -Wfatal-errors) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 75855733..57c658ad 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,58 +1,96 @@ cmake_minimum_required(VERSION 3.10) + # Prevent in source build, add this options before project keyword set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) + project(bluetoe_examples CXX C) -if (NOT CMAKE_CROSSCOMPILING) - message(ERROR " examples can only be cross compiled to arm cortex-m, missing -Dtoolchain_file on cmake invocation?") - return() -endif() if (NOT BINDING) message(ERROR " A binding must be defined. Use -DBINDING=nrf51. Current available bindings are nrf51, nrf52") return() endif() -# include hardware specific compile options and definitions that must be apllied to the whole project -include(${BINDING}_toolchain_support/platform.cmake) +set(supported_bindings nrf51 nrf52 hci_libusb) +set(cross_compile_bindings nrf51 nrf52) + +list(FIND supported_bindings "${BINDING}" binding_pos) + +if (${binding_pos} EQUAL -1) + message(FATAL_ERROR " not supported binding: ${BINDING}. Please choose one out of ${supported_bindings}") +endif() + +if (NOT CMAKE_CROSSCOMPILING) + list(FIND cross_compile_bindings "${BINDING}" cross_binding_pos) + + if (NOT ${cross_binding_pos} EQUAL -1) + message(FATAL_ERROR " examples can only be cross compiled to arm cortex-m, missing -Dtoolchain_file on cmake invocation?") + endif() +endif() + #set global compile options that are hardware independent, these will be used to build the applications (examples) #and will also be used to build bluetoe library # add global compile options add_compile_options(-ffunction-sections -fdata-sections) -#toolchain support targets, these are C and asm only, dont add cpp flags yet -add_subdirectory(${BINDING}_toolchain_support) + +if (CMAKE_CROSSCOMPILING) + # include hardware specific compile options and definitions that must be apllied to the whole project + include(${BINDING}_toolchain_support/platform.cmake) + + #toolchain support targets, these are C and asm only, dont add cpp flags yet + add_subdirectory(${BINDING}_toolchain_support) +endif() + #add global options to cpp targets add_compile_options(-ftemplate-backtrace-limit=0 -fvisibility-inlines-hidden -fno-rtti -fno-exceptions) + #bluetoe library add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_BINARY_DIR}/bluetoe) + # Some hardware abstractions, required by the examples add_subdirectory(hal) -function(add_bluetoe_example target_name) - add_executable(${target_name} ${target_name}.cpp runtime.cpp) - set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${target_name}.elf) - add_dependencies(${target_name} linker_script) - target_compile_options(${target_name} PRIVATE ) - target_link_libraries(${target_name} PRIVATE bluetoe::iface - bluetoe::bindings::nrf51 - startup::${BINDING} - toolchain::${BINDING} - example_hal - -lm -lstdc++ -lsupc++ - -T${CMAKE_CURRENT_BINARY_DIR}/${BINDING}_toolchain_support/linker_script.ld - -Wl,--gc-sections -Wl,--warn-common - -Wl,-Map,${CMAKE_CURRENT_BINARY_DIR}/${target_name}.map -nostdlib - ) - add_custom_target(${target_name}.artifacts ALL - COMMAND ${CMAKE_OBJCOPY} -S -O ihex ${target_name}.elf ${target_name}.hex - COMMAND ${CMAKE_OBJCOPY} -S -O binary --only-section=.text ${target_name}.elf ${target_name}.bin - COMMAND ${CMAKE_OBJDUMP} -hS ${target_name}.elf > ${target_name}.lss - COMMAND ${CMAKE_SIZE} ${target_name}.elf - ) - add_dependencies(${target_name}.artifacts ${target_name}) - add_custom_target(${target_name}.flash - COMMAND nrfjprog --chiperase --program ${target_name}.hex) - add_dependencies(${target_name}.flash ${target_name}.artifacts) -endfunction() + +if (CMAKE_CROSSCOMPILING) + function(add_bluetoe_example target_name) + add_executable(${target_name} ${target_name}.cpp runtime.cpp) + set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${target_name}.elf) + add_dependencies(${target_name} linker_script) + target_compile_options(${target_name} PRIVATE ) + target_link_libraries(${target_name} PRIVATE bluetoe::iface + bluetoe::bindings::${BINDING} + startup::${BINDING} + toolchain::${BINDING} + example_hal + -lm -lstdc++ -lsupc++ + -T${CMAKE_CURRENT_BINARY_DIR}/${BINDING}_toolchain_support/linker_script.ld + -Wl,--gc-sections -Wl,--warn-common + -Wl,-Map,${CMAKE_CURRENT_BINARY_DIR}/${target_name}.map -nostdlib + ) + add_custom_target(${target_name}.artifacts ALL + COMMAND ${CMAKE_OBJCOPY} -S -O ihex ${target_name}.elf ${target_name}.hex + COMMAND ${CMAKE_OBJCOPY} -S -O binary --only-section=.text ${target_name}.elf ${target_name}.bin + COMMAND ${CMAKE_OBJDUMP} -hS ${target_name}.elf > ${target_name}.lss + COMMAND ${CMAKE_SIZE} ${target_name}.elf + ) + add_dependencies(${target_name}.artifacts ${target_name}) + add_custom_target(${target_name}.flash + COMMAND nrfjprog --chiperase --program ${target_name}.hex) + add_dependencies(${target_name}.flash ${target_name}.artifacts) + endfunction() +else() + + # When not building for embedded hardware, things become more simple + function(add_bluetoe_example target_name) + add_executable(${target_name} ${target_name}.cpp) + + target_link_libraries(${target_name} + PRIVATE + bluetoe::bindings::${BINDING} + ) + endfunction() + +endif() + add_bluetoe_example(blinky) add_bluetoe_example(thermometer) add_bluetoe_example(cycling_speed_and_cadence) diff --git a/examples/hal/CMakeLists.txt b/examples/hal/CMakeLists.txt index 57a39cb3..2561ad4b 100644 --- a/examples/hal/CMakeLists.txt +++ b/examples/hal/CMakeLists.txt @@ -1,5 +1,10 @@ cmake_policy(SET CMP0079 NEW) add_library(example_hal STATIC io.cpp) -target_link_libraries(example_hal PRIVATE toolchain::${BINDING}) + +if (CMAKE_CROSSCOMPILING) + # to get the required include path + target_link_libraries(example_hal PRIVATE toolchain::${BINDING}) +endif() + target_include_directories(example_hal PUBLIC ..) \ No newline at end of file From 03872c8fc8c49f22f7c9011c2343b302a10cddc6 Mon Sep 17 00:00:00 2001 From: Torsten Robitzki Date: Fri, 19 Apr 2019 16:13:34 +0200 Subject: [PATCH 5/6] require cmake 3.14 --- .travis.yml | 4 ++-- CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index abb43697..0ac07cee 100644 --- a/.travis.yml +++ b/.travis.yml @@ -68,9 +68,9 @@ after_success: before_install: - sudo apt-get update -qq - - wget https://cmake.org/files/v3.11/cmake-3.11.4-Linux-x86_64.sh + - wget https://cmake.org/files/v3.14/cmake-3.14.2-Linux-x86_64.sh - mkdir /opt/cmake - - sh cmake-3.11.4-Linux-x86_64.sh --prefix=/opt/cmake --skip-license + - sh cmake-3.14.2-Linux-x86_64.sh --prefix=/opt/cmake --skip-license - wget https://launchpad.net/%7Eboost-latest/+archive/ubuntu/ppa/+files/libboost1.55-dev_1.55.0-1ppa1%7Esaucy1_amd64.deb - sudo dpkg --install libboost1.55-dev_1.55.0-1ppa1~saucy1_amd64.deb # - openssl aes-256-cbc -K $encrypted_eb6359394db6_key -iv $encrypted_eb6359394db6_iv -in config/travisci_rsa.enc -out config/travisci_rsa -d diff --git a/CMakeLists.txt b/CMakeLists.txt index cc0c5900..db2d6d17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) # Prevent in source build, add this options before project keyword set(CMAKE_DISABLE_SOURCE_CHANGES ON) set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) From d27d32f841456037c70e83c499fe283cc8467187 Mon Sep 17 00:00:00 2001 From: Torsten Robitzki Date: Wed, 24 Apr 2019 10:38:43 +0200 Subject: [PATCH 6/6] an HCI device --- .../hci/include_libusb/bluetoe/device.hpp | 5 +---- .../hci/include_libusb/bluetoe/libsub.hpp | 14 ++++++++++++++ bluetoe/hci/include/bluetoe/link_layer.hpp | 5 +++-- examples/CMakeLists.txt | 6 +++--- examples/hal/CMakeLists.txt | 5 ++++- examples/hal/io.cpp | 16 +++++----------- examples/hal/nrf51_io.cpp | 19 +++++++++++++++++++ examples/hal/nrf52_io.cpp | 1 + 8 files changed, 50 insertions(+), 21 deletions(-) create mode 100644 bluetoe/bindings/hci/include_libusb/bluetoe/libsub.hpp create mode 100644 examples/hal/nrf51_io.cpp create mode 100644 examples/hal/nrf52_io.cpp diff --git a/bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp b/bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp index cad35f66..3cc5eea5 100644 --- a/bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp +++ b/bluetoe/bindings/hci/include_libusb/bluetoe/device.hpp @@ -2,13 +2,10 @@ #define BLUETOE_BINDINGS_HCI_DEVICE_HPP #include +#include namespace bluetoe { - namespace hci_details { - struct libsub_transport {}; - } - template < class Server, typename ... Options > using device = bluetoe::hci::link_layer< Server, hci_details::libsub_transport, Options... >; } diff --git a/bluetoe/bindings/hci/include_libusb/bluetoe/libsub.hpp b/bluetoe/bindings/hci/include_libusb/bluetoe/libsub.hpp new file mode 100644 index 00000000..8721cc31 --- /dev/null +++ b/bluetoe/bindings/hci/include_libusb/bluetoe/libsub.hpp @@ -0,0 +1,14 @@ +#ifndef BLUETOE_BINDINGS_HCI_LIBUSB_HPP +#define BLUETOE_BINDINGS_HCI_LIBUSB_HPP + +namespace bluetoe { + + namespace hci_details { + template < typename LinkLayer > + class libsub_transport { + + }; + } +} + +#endif diff --git a/bluetoe/hci/include/bluetoe/link_layer.hpp b/bluetoe/hci/include/bluetoe/link_layer.hpp index 0338b18e..da3a6677 100644 --- a/bluetoe/hci/include/bluetoe/link_layer.hpp +++ b/bluetoe/hci/include/bluetoe/link_layer.hpp @@ -11,10 +11,11 @@ namespace hci { */ template < class Server, + template < typename > class Transport, typename ... Options > - class link_layer + class link_layer : Transport< link_layer< Server, Transport, Options... > > { public: /** @@ -53,7 +54,7 @@ namespace hci { }; // implementation - template < class Server, class Transport, typename ... Options > + template < class Server, template < typename > class Transport, typename ... Options > void link_layer< Server, Transport, Options... >::run( Server& ) { } diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 57c658ad..94518fea 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) # Prevent in source build, add this options before project keyword set(CMAKE_DISABLE_SOURCE_CHANGES ON) @@ -7,8 +7,7 @@ set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) project(bluetoe_examples CXX C) if (NOT BINDING) - message(ERROR " A binding must be defined. Use -DBINDING=nrf51. Current available bindings are nrf51, nrf52") - return() + message(FATAL_ERROR " A binding must be defined. Use -DBINDING=nrf51. Current available bindings are nrf51, nrf52") endif() set(supported_bindings nrf51 nrf52 hci_libusb) @@ -86,6 +85,7 @@ else() target_link_libraries(${target_name} PRIVATE bluetoe::bindings::${BINDING} + example_hal ) endfunction() diff --git a/examples/hal/CMakeLists.txt b/examples/hal/CMakeLists.txt index 2561ad4b..79ae09cf 100644 --- a/examples/hal/CMakeLists.txt +++ b/examples/hal/CMakeLists.txt @@ -1,10 +1,13 @@ cmake_policy(SET CMP0079 NEW) -add_library(example_hal STATIC io.cpp) if (CMAKE_CROSSCOMPILING) + add_library(example_hal STATIC ${BINDING}_io.cpp) + # to get the required include path target_link_libraries(example_hal PRIVATE toolchain::${BINDING}) +else() + add_library(example_hal STATIC io.cpp) endif() target_include_directories(example_hal PUBLIC ..) \ No newline at end of file diff --git a/examples/hal/io.cpp b/examples/hal/io.cpp index 6bf3e9b0..751a030c 100644 --- a/examples/hal/io.cpp +++ b/examples/hal/io.cpp @@ -1,19 +1,13 @@ -#include -#include - -static constexpr int io_pin = 21; +#include "hal/io.hpp" +#include void init_led() { - // Init GPIO pin - NRF_GPIO->PIN_CNF[ io_pin ] = - ( GPIO_PIN_CNF_DRIVE_S0H1 << GPIO_PIN_CNF_DRIVE_Pos ) | - ( GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos ); + std::cout << "init_led()" << std::endl; } void set_led( bool state ) { - NRF_GPIO->OUT = state - ? NRF_GPIO->OUT | ( 1 << io_pin ) - : NRF_GPIO->OUT & ~( 1 << io_pin ); + std::cout << "LED: " << ( state ? "on" : "off" ) << std::endl; } + diff --git a/examples/hal/nrf51_io.cpp b/examples/hal/nrf51_io.cpp new file mode 100644 index 00000000..6bf3e9b0 --- /dev/null +++ b/examples/hal/nrf51_io.cpp @@ -0,0 +1,19 @@ +#include +#include + +static constexpr int io_pin = 21; + +void init_led() +{ + // Init GPIO pin + NRF_GPIO->PIN_CNF[ io_pin ] = + ( GPIO_PIN_CNF_DRIVE_S0H1 << GPIO_PIN_CNF_DRIVE_Pos ) | + ( GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos ); +} + +void set_led( bool state ) +{ + NRF_GPIO->OUT = state + ? NRF_GPIO->OUT | ( 1 << io_pin ) + : NRF_GPIO->OUT & ~( 1 << io_pin ); +} diff --git a/examples/hal/nrf52_io.cpp b/examples/hal/nrf52_io.cpp new file mode 100644 index 00000000..dd58f0d7 --- /dev/null +++ b/examples/hal/nrf52_io.cpp @@ -0,0 +1 @@ +#include "nrf51.cpp" \ No newline at end of file