Commit 3fc2879d authored by Simen Natvig's avatar Simen Natvig
Browse files

First GitHub release of ble driver

parent 6a47099b
_build
**/.idea
**/CMakeFiles
**/CMakeCache.txt
*.pyc
# Object files
*.o
*.ko
*.obj
*.elf
# Precompiled Headers
*.gch
*.pch
# Libraries
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
# Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
#
# The information contained herein is property of Nordic Semiconductor ASA.
# Terms and conditions of usage are described in detail in NORDIC
# SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
# Licensees are granted free, non-transferable use of the information. NO
# WARRANTY of ANY KIND is provided. This heading must NOT be removed from
# the file.
cmake_minimum_required (VERSION 2.6)
# Do not allow in-source builds
if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
message(FATAL_ERROR "Prevented in-source build. Build out-of-source instead.")
endif(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
# Environment settings (nrf51_sdk location)
if("${NRF51_SDK_PATH}" STREQUAL "")
message(FATAL_ERROR "NRF51_SDK_PATH must be set to a valid SDK path.")
endif()
set (nrf51_sdk ${NRF51_SDK_PATH})
# Project root path
set (repo_root_path ${CMAKE_SOURCE_DIR})
# Check if necessary parameters is passed to cmake
if("${SERIALIZATION_VERSION}" STREQUAL "")
message(FATAL_ERROR "SERIALIZATION_VERSION not set. Not able to continue build. Please set with -DSERIALIZATION_VERSION=X.Y.Z invoking cmake.")
endif()
if("${SERIALIZATION_REVISION}" STREQUAL "")
message(FATAL_ERROR "SERIALIZATION_REVISION not set. Not able to continue build. Please set with -DSERIALIZATION_REVISION=X when invoking cmake.")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_compile_options(
-g -O0
)
add_definitions(
-DDEBUG
)
endif()
# Remove nRF51 hardware specific files from the SDK that prevents compilation.
# Since the C++ preprocessor will try to search the local directory first before searching
# other directories the we have to remove the files below. That way the preprocessor will use
# nrf_svc.h from override folder instead.
file(REMOVE ${nrf51_sdk}/components/softdevice/s130/headers/nrf_svc.h) # included by ${nrf51_sdk_components}/softdevice/s130/headers/ble_gap.h
# S130 specific include paths
set (nrf51_sdk_components ${nrf51_sdk}/components)
set (nrf51_sdk_codecs ${nrf51_sdk_components}/serialization/application/codecs)
set (nrf51_sdk_codecs_s130 ${nrf51_sdk_codecs}/s130)
set (s130_includes
${repo_root_path}/driver/inc
${repo_root_path}/driver/inc_override
${nrf51_sdk}/framework/cunit/include_override
${nrf51_sdk_components}/drivers_nrf/hal
${nrf51_sdk_components}/drivers_nrf/uart
${nrf51_sdk_components}/libraries/crc16
${nrf51_sdk_components}/libraries/scheduler
${nrf51_sdk_components}/libraries/timer
${nrf51_sdk_components}/libraries/util
${nrf51_sdk_components}/serialization/application/hal
${nrf51_sdk_components}/serialization/application/transport
${nrf51_sdk_components}/serialization/common
${nrf51_sdk_components}/serialization/common/transport
${nrf51_sdk_components}/serialization/common/transport/ser_phy
${nrf51_sdk_components}/softdevice/common/softdevice_handler
${nrf51_sdk_components}/toolchain/gcc
${nrf51_sdk_components}/toolchain
${nrf51_sdk_components}/device
${nrf51_sdk_components}/drivers_nrf/hal
${nrf51_sdk_codecs_s130}/serializers
${nrf51_sdk_components}/serialization/common/struct_ser/s130
${nrf51_sdk_components}/softdevice/s130 #needed for '#include "headers/nrf_soc.h"'
${nrf51_sdk_components}/softdevice/s130/headers
)
# Add subdirectories
if("${ARTIFACT}" STREQUAL "driver")
add_subdirectory(driver)
elseif("${ARTIFACT}" STREQUAL "binding")
add_subdirectory(python)
else()
message(FATAL_ERROR "ARTIFACT variable has to be specified, it can be driver or binding")
endif()
# nRF51 Bluetooth Smart GATT/GAP Driver
## Introduction
The nRF51 Bluetooth Smart GATT/GAP Driver (from now on called the Driver) consists of a standard C dynamic library that lets a PC application set up and interact with an nRF51 SoftDevice through API function calls. The library mirrors the nRF51 S130 SoftDevice API and makes it available to the PC application.
Commands sent from the library are encoded and sent over UART to the nRF51 chip. The connectivity application running on the nRF51 chip decodes the commands and feeds them to the SoftDevice. Command responses and events are encoded and sent from the nRF51 chip to the PC library where they are decoded.
The library makes it possible to create applications on a PC that, in code, can be similar to applications that are running on the nRF51 chip.
Having this kind of API gives the following benefits:
* Setting up a peer device for a Device Under Test (DUT) using a test script.
* Coherent BLE APIs on a PC and an nRF51 chip.
* Creating prototype and test applications for an nRF51 chip on a PC.
* Migrating code between an nRF51 chip and a PC.
## Disclaimer
No guarantees are given regarding stability or backward compatibility. Interfaces are subject to change.
# Building from source
## Dependencies
The following dependencies are required for building the Driver:
* [Boost](http://www.boost.org/users/download) (=1.56.0)
* [cmake](http://www.cmake.org/cmake/resources/software.html) (>=2.8.X)
* [Python](http://www.python.org/download/) (>=2.7.6, <3.0.0)
* [Swig](http://www.swig.org/download.html) (=2.0.12)
* git client
## Get the source code
The source code is available from GitHub at the following URL:
<https://github.com/NordicSemiconductor/pc-ble-driver.git>
## Setup of the build environment
### Windows
- Download the [MinGW] (http://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/4.8.2/threads-posix/dwarf/) Compiler Suite.
- Install MinGW Compiler Suite according to the [instructions](http://www.mingw.org/wiki/InstallationHOWTOforMinGW).
- Verify that gnu patch utility is available in PATH. (e.g. c:\program files(x86)\git\bin)
- Install cmake according to the [installation instructions for Windows](http://www.cmake.org/install/).
- Install [Microsoft Visual C++ Compiler for Python](http://www.microsoft.com/en-us/download/confirmation.aspx?id=44266).
- Extract, compile and install Boost. We assume Boost is extracted into c:\Boost\boost_1_56_0. Issue the following commands in the directory:
bootstrap
b2 toolset=gcc link=static runtime-link=shared threading=multi
### Ubuntu Linux
Run the following command to install compiler, dependencies and tools:
curl -L https://raw.githubusercontent.com/NordicSemiconductor/pc-ble-driver/master/scripts/setup-ubuntu-linux.sh | sh
You will be asked for root password during this process.
### OS X
Run the following command to install compiler, dependencies and tools:
curl -L https://raw.githubusercontent.com/NordicSemiconductor/pc-ble-driver/master/scripts/setup-osx.sh | sh
You will be asked for root password during this process.
## Compilation and packaging of the Driver
- Create a build directory outside the source directory.
- Create a directory to store Nordic Semiconductor software that the Driver depends on.
- Download the necessary Nordic Semiconductor dependencies and compile the Driver and Python binding with the command below.
mkdir build
mkdir deps
cd build
python ..\pc-ble-driver\scripts\build.py -srp <ROOT>\my_deps_directory -d -b (for Unix systems, replace \ with /)
- To package the release into a zip file, run the following command:
python ..\pc-ble-driver\scripts\build.py -srp <ROOT>\my_deps_directory -p (for Unix systems, replace \ with /)
- If you later want to run the Behave tests you will need to compile all the examples, to do this run this command:
python ..\pc-ble-driver\scripts\build.py -srp <ROOT>\my_deps_directory -e (for Unix systems, replace \ with /)
## Running of tests
We have different types of tests:
- BDD tests
- Packaging tests
- Integration/unit tests (without hardware)
- Integration tests (with hardware)
### Packaging and BDD tests
Setup:
- Set the environment variable PYTHONUNBUFFERED to something or else Python will buffer stdout, which will make the BDD tests fail.
- Set the environment variable NORDICSEMI_NRF51_BLE_DRIVER_BUILD_PATH to the build directory of the Driver
- Set the environment variable NORDICSEMI_TARGET_SETUP to the file name of the test targets configuration.
The test targets configuration contains information about nRF5X DK UART port and the drive letter it has been assigned to. Below is an example of a test_targets.json file:
{
"targets":
[
{
"id": 1,
"drive": "E:\\",
"serial_port": "COM8",
"pca": "PCA10028",
"segger_sn": "680595231"
},
{
"id": 2,
"drive": "D:\\",
"serial_port": "COM7",
"pca": "PCA10028",
"segger_sn": "681768567"
}
]
}
First, build and package the driver.
Then, issue the following command to run the packaging tests:
cd <ROOT>\driver\tests
python setup.py test
There is a bug in Behave that prevents us from running the Behave tests from setup.py. A workaround is to run BDD tests from the bdd directory:
cd <ROOT>\driver\tests\bdd
behave
The BDD tests require nRF51 hardware connected to the computer. A combination of two devices of the following is required, two of one kind or one of each:
- nRF51 Development Kit (pca10028), or
- nRF51 Development Dongle (pca10031)
### Integration/unit tests
First, build the driver.
Then, issue the following command to run the integration/unit tests:
python ..\pc-ble-driver\scripts\build.py -srp <ROOT>\my_deps_directory -t (for Unix systems, replace \ with /)
#### uart_cpp_test
For the unit test uart_cpp_test, a set of loopback serial ports is required. You can achieve this by using:
- a pair of usb-to-serial adapters interconnected with a null-modem cable
- a pair of virtual serial ports (emulated serial ports) configured to be interconnected
uart_cpp_test also requires the environment variables TESTSERIALPORT1 and TESTSERIALPORT2 to be set to the serial port names:
Example values:
TESTSERIALPORT1=COM20
TESTSERIALPORT2=COM21
If you want to **disable uart_cpp_test**, comment out the test in the file *driver/tests/CMakeLists.txt*:
#add_test(NAME uart_cpp_test COMMAND "uart_cpp_test" ${test_params})
## Platform specific notes
- Linux:
- udev rules for tty symlink and usb mount points are found in folder tests/config/linux/. These rules must be put in /etc/udev/rules.d/
- Remember to set the environment variable LD_LIBRARY_PATH to directories containing the libs*_nrf51_ble_driver.so so that the tests find the libs*_nrf51_ble_driver.so
- OSX:
- We have not discovered yet how to force the mount point for JLink devices on MacOSX, because of which the tty/mount point location will come out of sync
- Remember to set the environment variable DYLD_LIBRARY_PATH to directories containing the libs*_nrf51_ble_driver.dylib so that the tests find the libs*_nrf51_ble_driver.dylib
# Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
#
# The information contained herein is property of Nordic Semiconductor ASA.
# Terms and conditions of usage are described in detail in NORDIC
# SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
# Licensees are granted free, non-transferable use of the information. NO
# WARRANTY of ANY KIND is provided. This heading must NOT be removed from
# the file.
project(ble_driver CXX)
# Boost specific settings (link statically (on MinGW) with the multithreaded libraries)
if(MINGW OR APPLE)
set(Boost_USE_STATIC_LIBS ON)
endif()
if(APPLE)
message(STATUS "Remember to build boost with the following command line when using brew:")
message(STATUS "CFLAGS=-fPIC brew install --verbose --env=std --build-from-source boost")
endif(APPLE)
set(Boost_USE_MULTITHREADED ON)
# Find the necessary boost components on system
find_package ( Boost 1.54.0 REQUIRED COMPONENTS thread system regex date_time chrono )
# Filename for .def for S130
set(s130_target_def_file s130_nrf51_ble_driver.def)
# Add WIN32 specific settings
if(WIN32)
# Values used when generating version.rc
string(REPLACE "." "," SERIALIZATION_VERSION_WIN32 ${SERIALIZATION_VERSION})
enable_language(RC) # Enable compilation of WIN32 resource files
add_definitions(
-D_WIN32_WINNT=0x0502
)
# Generate dll information for win32 build.
# Values specified above are used in the version.rc.in file
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/version.rc.in
${CMAKE_CURRENT_BINARY_DIR}/version.rc
@ONLY
)
# Generate batch file for creating .lib file
get_filename_component(VS_DIR [HKEY_CURRENT_USER\\Software\\Microsoft\\DevDiv\\VCForPython\\9.0;InstallDir] REALPATH CACHE)
string(REPLACE "/" "\\" VS_DIR ${VS_DIR})
set(VS_DIR "${VS_DIR}\\VC\\bin")
set(VS_LIB_PATH "${VS_DIR}\\lib")
string(REPLACE ".def" ".lib" s130_target_lib_file ${s130_target_def_file})
configure_file(
${CMAKE_SOURCE_DIR}/scripts/msvc_def_to_lib.bat.in
${CMAKE_CURRENT_BINARY_DIR}/msvc_def_to_lib.bat
@ONLY)
endif()
# Include boost as a system include so that the compiler do not nag about issues in boost header files
include_directories (
${s130_includes}
SYSTEM ${Boost_INCLUDE_DIRS}
)
set (s130_src
${nrf51_sdk_codecs_s130}/middleware/app_mw_ble.c
${nrf51_sdk_codecs_s130}/middleware/app_mw_ble_gap.c
${nrf51_sdk_codecs_s130}/middleware/app_mw_ble_gap.c
${nrf51_sdk_codecs_s130}/middleware/app_mw_ble_gattc.c
${nrf51_sdk_codecs_s130}/middleware/app_mw_ble_l2cap.c
${nrf51_sdk_codecs_s130}/middleware/app_mw_ble_gatts.c
${nrf51_sdk_codecs_s130}/serializers/app_ble_gap_sec_keys.c
${nrf51_sdk_codecs_s130}/serializers/app_ble_user_mem.c
${nrf51_sdk_codecs_s130}/serializers/ble_enable.c
${nrf51_sdk_codecs_s130}/serializers/ble_event.c
${nrf51_sdk_codecs_s130}/serializers/ble_evt_tx_complete.c
${nrf51_sdk_codecs_s130}/serializers/ble_evt_user_mem_release.c
${nrf51_sdk_codecs_s130}/serializers/ble_evt_user_mem_request.c
${nrf51_sdk_codecs_s130}/serializers/ble_opt_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_opt_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_tx_buffer_count_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_user_mem_reply.c
${nrf51_sdk_codecs_s130}/serializers/ble_uuid_decode.c
${nrf51_sdk_codecs_s130}/serializers/ble_uuid_encode.c
${nrf51_sdk_codecs_s130}/serializers/ble_uuid_vs_add.c
${nrf51_sdk_codecs_s130}/serializers/ble_version_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_address_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_address_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_adv_data_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_adv_start.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_adv_stop.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_appearance_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_appearance_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_auth_key_reply.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_authenticate.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_conn_param_update.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_conn_sec_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_connect.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_connect_cancel.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_device_name_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_device_name_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_disconnect.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_encrypt.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_adv_report.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_auth_key_request.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_auth_status.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_conn_param_update.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_conn_param_update_request.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_conn_sec_update.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_connected.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_disconnected.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_passkey_display.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_rssi_changed.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_scan_req_report.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_sec_info_request.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_sec_params_request.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_sec_request.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_evt_timeout.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_ppcp_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_ppcp_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_rssi_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_rssi_start.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_rssi_stop.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_scan_start.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_scan_stop.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_sec_info_reply.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_sec_params_reply.c
${nrf51_sdk_codecs_s130}/serializers/ble_gap_tx_power_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_char_value_by_uuid_read.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_char_values_read.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_characteristics_discover.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_descriptors_discover.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_char_disc_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_char_val_by_uuid_read_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_char_vals_read_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_desc_disc_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_hvx.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_prim_srvc_disc_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_read_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_rel_disc_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_timeout.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_evt_write_rsp.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_hv_confirm.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_primary_services_discover.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_read.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_relationships_discover.c
${nrf51_sdk_codecs_s130}/serializers/ble_gattc_write.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_characteristic_add.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_descriptor_add.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_evt_hvc.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_evt_rw_authorize_request.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_evt_sc_confirm.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_evt_sys_attr_missing.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_evt_timeout.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_evt_write.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_hvx.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_include_add.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_rw_authorize_reply.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_service_add.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_service_changed.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_sys_attr_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_sys_attr_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_value_get.c
${nrf51_sdk_codecs_s130}/serializers/ble_gatts_value_set.c
${nrf51_sdk_codecs_s130}/serializers/ble_l2cap_cid_register.c
${nrf51_sdk_codecs_s130}/serializers/ble_l2cap_cid_unregister.c
${nrf51_sdk_codecs_s130}/serializers/ble_l2cap_evt_rx.c
${nrf51_sdk_codecs_s130}/serializers/ble_l2cap_tx.c
${nrf51_sdk_codecs_s130}/serializers/power_system_off.c
${nrf51_sdk_components}/serialization/common/struct_ser/s130/ble_struct_serialization.c
${nrf51_sdk_components}/serialization/common/struct_ser/s130/ble_gattc_struct_serialization.c
${nrf51_sdk_components}/serialization/common/struct_ser/s130/ble_gatts_struct_serialization.c
${nrf51_sdk_components}/serialization/common/struct_ser/s130/ble_gap_struct_serialization.c
)
set (common_src
src/sd_rpc.c
src/app_log.c
src/app_log_utility.c
src/uart.cpp
src/uart_boost.cpp
src/uart_settings.cpp
src/uart_settings_boost.cpp
src/timer.cpp
src/timer_boost.cpp
src/app_timer_pc.c
src/app_uart_pc.c
src/nrf_soc_pc.c
src/ser_app_hal_pc.c
src/ser_app_power_system_off_pc.c
${nrf51_sdk_components}/libraries/crc16/crc16.c
${nrf51_sdk_components}/serialization/application/transport/app_mailbox.c
${nrf51_sdk_components}/serialization/application/transport/ser_sd_transport.c
${nrf51_sdk_components}/serialization/application/transport/ser_softdevice_handler.c
${nrf51_sdk_components}/serialization/common/ble_serialization.c
${nrf51_sdk_components}/serialization/common/cond_field_serialization.c
${nrf51_sdk_components}/serialization/common/transport/ser_hal_transport.c
${nrf51_sdk_components}/serialization/common/transport/ser_phy/ser_phy_hci.c
${nrf51_sdk_components}/serialization/common/transport/ser_phy/ser_phy_hci_slip.c
${nrf51_sdk_components}/softdevice/common/softdevice_handler/softdevice_handler.c
)
# Add definitions used by compiler when compiling source files
add_definitions(
-DSD_RPC_EXPORTS
-DNRF51
-DBOARD_NRF6310
-DSVCALL_AS_NORMAL_FUNCTION
-DBLE_STACK_SUPPORT_REQD
-DHCI_LINK_CONTROL # Adds support for Link Control packets according to the HCI standard
-DS130
)
# Compiler options use when compiling
add_compile_options(
-Wall
-Wno-effc++
-Wno-unknown-pragmas
-Wno-undef
-Wstrict-overflow=4
-Wno-long-long
-Wfloat-equal
-Wundef
-Wshadow
-Wpointer-arith
#-H # Used for debugging header dependencies. See https://docs.freebsd.org/info/gcc/gcc.info.Preprocessor_Options.html
)
if (APPLE)
add_compile_options(-pthread)
endif(APPLE)
# Add warning that is only used on GCC (ant not LLVM)
if (NOT APPLE)
add_compile_options(
-Wlogical-op
)
endif(NOT APPLE)
# Force .c files to be compiled with the C++ compiler
set_source_files_properties(
${common_src}
${s130_src}
PROPERTIES
LANGUAGE CXX
)
# S130 target --start--
set(s130_src_list ${common_src} ${s130_src})
if(MINGW)
set(s130_src_list ${s130_src_list} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
endif(MINGW)
add_library(s130_nrf51_ble_driver SHARED ${s130_src_list})
# Specify libraries to link serialization library with
target_link_libraries (s130_nrf51_ble_driver PRIVATE ${Boost_LIBRARIES})
if(MINGW)
set_property(TARGET s130_nrf51_ble_driver APPEND PROPERTY LINK_LIBRARIES ws2_32)
set_property(TARGET s130_nrf51_ble_driver APPEND PROPERTY LINK_FLAGS "-static-libgcc -static-libstdc++ -static -Wl,--output-def,${s130_target_def_file}")
set_property(TARGET s130_nrf51_ble_driver PROPERTY PREFIX "")
endif(MINGW)
if(APPLE)
set_property(TARGET s130_nrf51_ble_driver APPEND PROPERTY LINK_FLAGS "-static -lc -lc++")
endif(APPLE)
if(WIN32)
add_custom_command(
TARGET s130_nrf51_ble_driver
POST_BUILD
COMMAND "${CMAKE_CURRENT_BINARY_DIR}\\msvc_def_to_lib.bat")
endif(WIN32)
# S130 target --end--
add_subdirectory(tests)
CC = gcc
INCLUDEPATHS += -I../../../include
LIB_PATHS += -L../../../lib
LIBS += -ls130_nrf51_ble_driver
CFLAGS += $(INCLUDEPATHS)
CFLAGS += -Wall
LDFLAGS += $(LIB_PATHS) $(LIBS)
ifeq ($(OS),Windows_NT)
CFLAGS += -m32
LDFLAGS += -m32
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
LDFLAGS += -Wl,-rpath=../../../lib
endif
endif
C_OBJECT_FILES = $(addprefix $(C_OBJECT_PATH)/,$(C_SOURCE_FILES:.c=.o))
vpath %.c $(C_SOURCE_PATHS)
### Targets
.PHONY: build
ifeq ($(OS),Windows_NT)
all: build copy_dll
copy_dll:
xcopy /DY ..\..\..\lib\s130_nrf51_ble_driver.dll
else
all: build
endif
build: $(TARGET)
$(C_OBJECT_PATH)/%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
$(TARGET): $(C_OBJECT_FILES)