diff --git a/port/nrf5-cinnamon/CMakeLists.txt b/port/nrf5-cinnamon/CMakeLists.txt new file mode 100644 index 000000000..8eb17b4a8 --- /dev/null +++ b/port/nrf5-cinnamon/CMakeLists.txt @@ -0,0 +1,48 @@ +cmake_minimum_required(VERSION 3.14) +project(n5rf-ll) + +# nrf5 sdk root with nrfx +set(NRF5_SDK_ROOT /Users/mringwal/Projects/Nordic/nRF5_SDK_17.0.2_d674dde) + +# list all sources +file(GLOB_RECURSE btstack_src_src ../../src/*.c) +file(GLOB_RECURSE btstack_src_hdr ../../src/*.h) +file(GLOB_RECURSE btstack_embedded_src ../../platform/embedded/src/*.c) +file(GLOB_RECURSE btstack_embedded_hdr ../../platform/embedded/src/*.h) +file(GLOB_RECURSE btstack_port_src *.c) +file(GLOB_RECURSE btstack_port_hdr *.h) +file(GLOB_RECURSE nrfx_src ${NRF5_SDK_ROOT}/modules/*.c) +file(GLOB_RECURSE nrfx_hdr ${NRF5_SDK_ROOT}/modules/*.h) + +# Compile pca10040 port using Make +find_program(MAKE make) +add_custom_target(pca10040 + ALL + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/pca10040/armgcc + COMMAND ${MAKE} + SOURCES ${btstack_src_src} ${btstack_embedded_src} ${btstack_port_src} ${nrfx_src}) + +# fake executable for navigation in IDE +add_executable(port EXCLUDE_FROM_ALL + ${btstack_src_src} + ${btstack_src_hdr} + ${btstack_embedded_src} + ${btstack_embedded_hdr} + ${btstack_port_src} + ${btstack_port_hdr} + ${nrfx_src} + ${nrfx_hdr} +) +target_include_directories(port SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/port + ../../3rd-party/segger-rtt + ../../platform/embedded + ../../chipset/controller + ../../src + ${NRF5_SDK_ROOT}/components/boards + ${NRF5_SDK_ROOT}/components/libraries/delay + ${NRF5_SDK_ROOT}/modules/nrfx/drivers/include + ${NRF5_SDK_ROOT}/modules/nrfx/mdk + ${NRF5_SDK_ROOT}/modules/nrfx/hal + ${NRF5_SDK_ROOT}/modules/nrfx +) diff --git a/port/nrf5-cinnamon/README.md b/port/nrf5-cinnamon/README.md new file mode 100644 index 000000000..3976f98a2 --- /dev/null +++ b/port/nrf5-cinnamon/README.md @@ -0,0 +1,25 @@ +# BTstack port with Cinnamon for Nordic nRF5 Series + +*Cinnamon* is BlueKitchen's minimal, yet robust Controller/Link Layer implementation for use with BTstack. + +In contrast to common Link Layer implementations, our focus is on a robust and compact implementation for production use, +where code size matters (e.g. current code size about 8 kB). + +## Status +The current implementation supports a single Peripheral role, or, passive scanning in Observer role. In the Peripheral role, +channel map updates, as well as connection param updates are supported. + +Support for LE Central Role as well as Encryption is planned but not supported yet. + +## Requirements +- arm-none-eabi toolchain +- Nordic's nRF5-SDK + +## Supported Hardware +All nNRF5x SOCs. Built files are provided for PCA10040 (52832 DK), but others can be supported with minimal changes. + +## Use +- Provide path to nRF5-SDK either in `NRF5_SDK_ROOT` environment variable or directly in `pca10040/armgcc/Makefile`. +- run make +- All supported examples are built in the `build` folder. +- You can use Segger's OZONE with the provided `EXAMPLE.jdebug` project file to flash and run the examples. diff --git a/port/nrf5-cinnamon/main.c b/port/nrf5-cinnamon/main.c new file mode 100644 index 000000000..2d6c33fca --- /dev/null +++ b/port/nrf5-cinnamon/main.c @@ -0,0 +1,174 @@ +/** + * Copyright (c) 2014 - 2020, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +/** @file + * + * @defgroup blinky_example_main main.c + * @{ + * @ingroup blinky_example + * @brief Blinky Example Application main file. + * + * This file contains the source code for a sample application to blink LEDs. + * + */ + +#include +#include +#include "boards.h" +#include "SEGGER_RTT.h" + +#include "nrf.h" +#include "nrf52.h" +#include "nrf_delay.h" +#include "nrfx_clock.h" +#include "hal_timer.h" +#include "radio.h" +#include + +#include "btstack_memory.h" +#include "btstack_run_loop_embedded.h" +#include "controller.h" +#include "btstack_tlv.h" +#include "btstack_tlv_none.h" +#include "ble/le_device_db_tlv.h" +#include "hci_dump.h" +#include "hci_dump_segger_rtt_stdout.h" +#include "hci_dump_segger_rtt_binary.h" +#include "hci_dump_embedded_stdout.h" + +void btstack_assert_failed(const char * file, uint16_t line_nr){ + printf("Assert: file %s, line %u\n", file, line_nr); + while (1); +} + +/** hal_time_ms.h */ +#include "hal_time_ms.h" +extern uint32_t hal_timer_get_ticks(void); +uint32_t hal_time_ms(void){ + uint32_t ticks = hal_timer_get_ticks(); + uint32_t seconds = ticks >> 15; // / 32768 + uint32_t remaining_ms = (ticks & 0x7fff) * 1000 / 32768; + return seconds * 1000 + remaining_ms; +} + +/** hal_cpu.h */ + +// TODO: implement +void hal_cpu_disable_irqs(void){ + __disable_irq(); +} + +void hal_cpu_enable_irqs(void){ + __enable_irq(); +} + +void hal_cpu_enable_irqs_and_sleep(void){ + __enable_irq(); + // __asm__("wfe"); // go to sleep if event flag isn't set. if set, just clear it. IRQs set event flag +} + +static void lf_clock_init(void) { + // select 32.768 kHz XTAL as LF Clock source and start + NRF_CLOCK->LFCLKSRC = NRF_CLOCK_LFCLK_Xtal; + NRF_CLOCK->EVENTS_LFCLKSTARTED = 0; + NRF_CLOCK->TASKS_LFCLKSTART = 1; + while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0); +} + +void btstack_main(void); +int main(void){ + + // system init + lf_clock_init(); + hal_timer_init(); + +#if 0 + // get startup time, around 9 ticks and verify that we don't need to wait until it's disabled + uint32_t t0 = hal_timer_get_ticks(); + radio_hf_clock_enable(true); + uint32_t t1 = hal_timer_get_ticks(); + radio_hf_clock_disable(); + radio_hf_clock_enable(true); + radio_hf_clock_disable(); + printf("HF Startup time: %lu ticks\n", t1-t0); +#endif + + + btstack_memory_init(); + btstack_run_loop_init(btstack_run_loop_embedded_get_instance()); + + // initialize controller + controller_init(); + + // get virtual HCI transpoft + const hci_transport_t * hci_transport = controller_get_hci_transport(); + + // TODO: use flash storage + + const btstack_tlv_t * btstack_tlv_impl = btstack_tlv_none_init_instance(); + // setup global tlv + btstack_tlv_set_instance(btstack_tlv_impl, NULL); + + // setup LE Device DB using TLV + le_device_db_tlv_configure(btstack_tlv_impl, NULL); + + // init HCI + hci_init(hci_transport, NULL); + + // uncomment to enable packet logger +#ifdef ENABLE_SEGGER_RTT + // hci_dump_init(hci_dump_segger_rtt_stdout_get_instance()); + + // hci_dump_segger_rtt_binary_open(HCI_DUMP_PACKETLOGGER); + // hci_dump_init(hci_dump_segger_rtt_binary_get_instance()); +#else + // hci_dump_init(hci_dump_embedded_stdout_get_instance()); +#endif + + // hand over to btstack embedded code + btstack_main(); + + // go + btstack_run_loop_execute(); + + while (1){};} + +/** + *@} + **/ diff --git a/port/nrf5-cinnamon/pca10040/armgcc/Makefile b/port/nrf5-cinnamon/pca10040/armgcc/Makefile new file mode 100644 index 000000000..150ec7303 --- /dev/null +++ b/port/nrf5-cinnamon/pca10040/armgcc/Makefile @@ -0,0 +1,213 @@ + +NRF5_SDK_ROOT ?= /Users/mringwal/Projects/Nordic/nRF5_SDK_17.0.2_d674dde + +# unset GNU_INSTALL_ROOT will select arm-none-eabi-gcc from your PATH +export GNU_INSTALL_ROOT ?= + +OUTPUT_DIRECTORY := build + +SDK_ROOT := $(NRF5_SDK_ROOT) +PROJ_DIR := ../.. + +BTSTACK_ROOT = ../../../.. + +LINKER_SCRIPT := nrf52832_xxaa.ld + +# Source files common to all targets +C_SOURCES = \ + $(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \ + $(SDK_ROOT)/components/boards/boards.c \ + $(PROJ_DIR)/main.c \ + $(PROJ_DIR)/port/hal_timer_nrf5.c \ + $(PROJ_DIR)/port/ll_nrf5.c \ + $(PROJ_DIR)/port/radio_nrf5.c \ + ${BTSTACK_ROOT}/3rd-party/micro-ecc/uECC.c \ + ${BTSTACK_ROOT}/3rd-party/rijndael/rijndael.c \ + ${BTSTACK_ROOT}/3rd-party/segger-rtt/SEGGER_RTT.c \ + ${BTSTACK_ROOT}/3rd-party/segger-rtt/SEGGER_RTT_printf.c \ + ${BTSTACK_ROOT}/3rd-party/segger-rtt/SEGGER_RTT_Syscalls_GCC.c \ + ${BTSTACK_ROOT}/chipset/controller/controller.c \ + ${BTSTACK_ROOT}/chipset/controller/hci_event.c \ + ${BTSTACK_ROOT}/chipset/controller/hopping.c \ + ${BTSTACK_ROOT}/platform/embedded/btstack_run_loop_embedded.c \ + ${BTSTACK_ROOT}/platform/embedded/hci_dump_embedded_stdout.c \ + ${BTSTACK_ROOT}/platform/embedded/hci_dump_segger_rtt_stdout.c \ + ${BTSTACK_ROOT}/platform/embedded/hci_dump_segger_rtt_binary.c \ + ${BTSTACK_ROOT}/src/ad_parser.c \ + ${BTSTACK_ROOT}/src/ble/att_db.c \ + ${BTSTACK_ROOT}/src/ble/att_dispatch.c \ + ${BTSTACK_ROOT}/src/ble/att_server.c \ + ${BTSTACK_ROOT}/src/ble/gatt-service/ancs_client.c \ + ${BTSTACK_ROOT}/src/ble/gatt-service/battery_service_client.c \ + ${BTSTACK_ROOT}/src/ble/gatt-service/battery_service_server.c \ + ${BTSTACK_ROOT}/src/ble/gatt-service/device_information_service_client.c \ + ${BTSTACK_ROOT}/src/ble/gatt-service/device_information_service_server.c \ + ${BTSTACK_ROOT}/src/ble/gatt-service/hids_device.c \ + ${BTSTACK_ROOT}/src/ble/gatt_client.c \ + ${BTSTACK_ROOT}/src/ble/le_device_db_memory.c \ + ${BTSTACK_ROOT}/src/ble/le_device_db_tlv.c \ + ${BTSTACK_ROOT}/src/ble/sm.c \ + ${BTSTACK_ROOT}/src/btstack_audio.c \ + ${BTSTACK_ROOT}/src/btstack_crypto.c \ + ${BTSTACK_ROOT}/src/btstack_hid_parser.c \ + ${BTSTACK_ROOT}/src/btstack_linked_list.c \ + ${BTSTACK_ROOT}/src/btstack_linked_queue.c \ + ${BTSTACK_ROOT}/src/btstack_memory.c \ + ${BTSTACK_ROOT}/src/btstack_memory_pool.c \ + ${BTSTACK_ROOT}/src/btstack_resample.c \ + ${BTSTACK_ROOT}/src/btstack_ring_buffer.c \ + ${BTSTACK_ROOT}/src/btstack_run_loop.c \ + ${BTSTACK_ROOT}/src/btstack_tlv.c \ + ${BTSTACK_ROOT}/src/btstack_tlv_none.c \ + ${BTSTACK_ROOT}/src/btstack_util.c \ + ${BTSTACK_ROOT}/src/hci.c \ + ${BTSTACK_ROOT}/src/hci_cmd.c \ + ${BTSTACK_ROOT}/src/hci_dump.c \ + ${BTSTACK_ROOT}/src/hci_transport_h4.c \ + ${BTSTACK_ROOT}/src/l2cap.c \ + ${BTSTACK_ROOT}/src/l2cap_signaling.c \ + +ASM_SOURCES= \ + $(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \ + +# Include folders common to all targets +INC_FOLDERS += \ + $(PROJ_DIR) \ + $(SDK_ROOT)/integration/nrfx \ + $(SDK_ROOT)/integration/nrfx/legacy \ + $(SDK_ROOT)/modules/nrfx \ + $(SDK_ROOT)/modules/nrfx/hal \ + $(SDK_ROOT)/modules/nrfx/mdk \ + $(SDK_ROOT)/modules/nrfx/drivers/include/ \ + $(SDK_ROOT)/components/boards \ + $(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \ + $(SDK_ROOT)/components/libraries/bsp \ + $(SDK_ROOT)/components/toolchain/cmsis/include \ + $(SDK_ROOT)/components/libraries/util \ + $(SDK_ROOT)/components/libraries/delay \ + $(SDK_ROOT)/components/libraries/log/ \ + $(SDK_ROOT)//components/libraries/log/src \ + $(SDK_ROOT)/components/libraries/experimental_section_vars/ \ + $(BTSTACK_ROOT)/3rd-party/segger-rtt \ + $(BTSTACK_ROOT)/chipset/controller \ + $(BTSTACK_ROOT)/src/ \ + $(BTSTACK_ROOT)/platform/embedded \ + ../config \ + ../../port \ + $(OUTPUT_DIRECTORY)\ + +# Libraries common to all targets +LIB_FILES += \ + +# Optimization flags +# OPT = -O3 -g3 +# Uncomment the line below to enable link time optimization +#OPT += -flto +OPT = -Os -g + +# C flags common to all targets +CFLAGS += $(OPT) +CFLAGS += -DBOARD_PCA10040 +CFLAGS += -DBSP_DEFINES_ONLY +CFLAGS += -DCONFIG_GPIO_AS_PINRESET +CFLAGS += -DFLOAT_ABI_HARD +CFLAGS += -DNRF52 +CFLAGS += -DNRF52832_XXAA +CFLAGS += -DNRF52_PAN_74 +CFLAGS += -mcpu=cortex-m4 +CFLAGS += -mthumb -mabi=aapcs +CFLAGS += -Wall -Werror +CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +# keep every function in a separate section, this allows linker to discard unused ones +CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing +CFLAGS += -fno-builtin -fshort-enums + +# C++ flags common to all targets +CXXFLAGS += $(OPT) +# Assembler flags common to all targets +ASMFLAGS += -g3 +ASMFLAGS += -mcpu=cortex-m4 +ASMFLAGS += -mthumb -mabi=aapcs +ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +ASMFLAGS += -DBOARD_PCA10040 +ASMFLAGS += -DBSP_DEFINES_ONLY +ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET +ASMFLAGS += -DFLOAT_ABI_HARD +ASMFLAGS += -DNRF52 +ASMFLAGS += -DNRF52832_XXAA +ASMFLAGS += -DNRF52_PAN_74 + +# Linker flags +LDFLAGS += $(OPT) +LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT) +LDFLAGS += -mcpu=cortex-m4 +LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16 +# let linker dump unused sections +LDFLAGS += -Wl,--gc-sections +# use newlib in nano version +LDFLAGS += --specs=nano.specs + +# Add standard libraries at the very end of the linker input, after all objects +# that may need symbols provided by these libraries. +LIB_FILES += -lc -lnosys -lm + +# default action: build all +EXAMPLES = \ + gap_le_advertisements \ + gatt_counter \ + gatt_streamer_server \ +# require encryption: +# hog_keyboard_demo \ +# hog_mouse_demo \ +# sm_pairing_peripheral \ + +GATT_FILES = \ + gatt_counter.gatt \ + gatt_streamer_server.gatt \ +# require encryption: +# hog_keyboard_demo.gatt \ +# hog_mouse_demo.gatt \ +# sm_pairing_peripheral.gatt \ + +# list of objects +OBJECTS = $(addprefix $(OUTPUT_DIRECTORY)/,$(notdir $(C_SOURCES:.c=.o))) +vpath %.c $(sort $(dir $(C_SOURCES))) +# list of ASM program objects +OBJECTS += $(addprefix $(OUTPUT_DIRECTORY)/,$(notdir $(ASM_SOURCES:.S=.o))) +vpath %.S $(sort $(dir $(ASM_SOURCES))) + +.PHONY: default help + +# VPATH to find .gatt files +VPATH += ${BTSTACK_ROOT}/example + +# Default target - first one defined +default: \ + $(OBJECTS) \ + $(addprefix $(OUTPUT_DIRECTORY)/,$(GATT_FILES:.gatt=.h)) \ + $(addprefix $(OUTPUT_DIRECTORY)/,$(EXAMPLES:=.elf)) \ + $(addprefix $(OUTPUT_DIRECTORY)/,$(EXAMPLES:=.jdebug)) \ + +$(OUTPUT_DIRECTORY)/%.h: %.gatt | $(OUTPUT_DIRECTORY) + python3 ${BTSTACK_ROOT}/tool/compile_gatt.py $< $@ + +$(OUTPUT_DIRECTORY)/%.o: %.S Makefile | $(OUTPUT_DIRECTORY) + $(CC) -c $(ASMFLAGS) $< -o $@ + +$(OUTPUT_DIRECTORY)/%.o: %.c Makefile | $(OUTPUT_DIRECTORY) + $(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(OUTPUT_DIRECTORY)/$(notdir $(<:.c=.lst)) $< -o $@ + +$(OUTPUT_DIRECTORY)/%.elf: Makefile $(OBJECTS) $(OUTPUT_DIRECTORY)/%.o + $(CC) $(filter-out Makefile,$^) $(LDFLAGS) -o $@ + $(SIZE) $@ + +$(OUTPUT_DIRECTORY)/%.jdebug: ozone.jdebug | $(OUTPUT_DIRECTORY) + sed -e "s|EXAMPLE|$(basename $(notdir $@))|" $< > $@ + +TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc + +include $(TEMPLATE_PATH)/Makefile.common + +# Convert INC_FOLDERS into CFLAGS +$(eval INC_PATHS := $(call get_inc_paths, $(INC_FOLDERS) $(call target_specific, INC_FOLDERS, $(1)))) +CFLAGS += ${INC_PATHS} diff --git a/port/nrf5-cinnamon/pca10040/armgcc/nrf52832_xxaa.ld b/port/nrf5-cinnamon/pca10040/armgcc/nrf52832_xxaa.ld new file mode 100644 index 000000000..94339ee66 --- /dev/null +++ b/port/nrf5-cinnamon/pca10040/armgcc/nrf52832_xxaa.ld @@ -0,0 +1,64 @@ +/* Linker script to configure memory regions. */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000 +} + +SECTIONS +{ +} + +SECTIONS +{ + . = ALIGN(4); + .mem_section_dummy_ram : + { + } + .log_dynamic_data : + { + PROVIDE(__start_log_dynamic_data = .); + KEEP(*(SORT(.log_dynamic_data*))) + PROVIDE(__stop_log_dynamic_data = .); + } > RAM + .log_filter_data : + { + PROVIDE(__start_log_filter_data = .); + KEEP(*(SORT(.log_filter_data*))) + PROVIDE(__stop_log_filter_data = .); + } > RAM + +} INSERT AFTER .data; + +SECTIONS +{ + .mem_section_dummy_rom : + { + } + .log_const_data : + { + PROVIDE(__start_log_const_data = .); + KEEP(*(SORT(.log_const_data*))) + PROVIDE(__stop_log_const_data = .); + } > FLASH + .log_backends : + { + PROVIDE(__start_log_backends = .); + KEEP(*(SORT(.log_backends*))) + PROVIDE(__stop_log_backends = .); + } > FLASH + .nrf_balloc : + { + PROVIDE(__start_nrf_balloc = .); + KEEP(*(.nrf_balloc)) + PROVIDE(__stop_nrf_balloc = .); + } > FLASH + +} INSERT AFTER .text + + +INCLUDE "nrf_common.ld" diff --git a/port/nrf5-cinnamon/pca10040/config/sdk_config.h b/port/nrf5-cinnamon/pca10040/config/sdk_config.h new file mode 100644 index 000000000..dfde816bf --- /dev/null +++ b/port/nrf5-cinnamon/pca10040/config/sdk_config.h @@ -0,0 +1,3320 @@ +/** + * Copyright (c) 2017 - 2020, Nordic Semiconductor ASA + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + + + +#ifndef SDK_CONFIG_H +#define SDK_CONFIG_H +// <<< Use Configuration Wizard in Context Menu >>>\n +#ifdef USE_APP_CONFIG +#include "app_config.h" +#endif +// nRF_Libraries + +//========================================================== +// NRF_BALLOC_ENABLED - nrf_balloc - Block allocator module +//========================================================== +#ifndef NRF_BALLOC_ENABLED +#define NRF_BALLOC_ENABLED 1 +#endif +// NRF_BALLOC_CONFIG_DEBUG_ENABLED - Enables debug mode in the module. +//========================================================== +#ifndef NRF_BALLOC_CONFIG_DEBUG_ENABLED +#define NRF_BALLOC_CONFIG_DEBUG_ENABLED 0 +#endif +// NRF_BALLOC_CONFIG_HEAD_GUARD_WORDS - Number of words used as head guard. <0-255> + + +#ifndef NRF_BALLOC_CONFIG_HEAD_GUARD_WORDS +#define NRF_BALLOC_CONFIG_HEAD_GUARD_WORDS 1 +#endif + +// NRF_BALLOC_CONFIG_TAIL_GUARD_WORDS - Number of words used as tail guard. <0-255> + + +#ifndef NRF_BALLOC_CONFIG_TAIL_GUARD_WORDS +#define NRF_BALLOC_CONFIG_TAIL_GUARD_WORDS 1 +#endif + +// NRF_BALLOC_CONFIG_BASIC_CHECKS_ENABLED - Enables basic checks in this module. + + +#ifndef NRF_BALLOC_CONFIG_BASIC_CHECKS_ENABLED +#define NRF_BALLOC_CONFIG_BASIC_CHECKS_ENABLED 0 +#endif + +// NRF_BALLOC_CONFIG_DOUBLE_FREE_CHECK_ENABLED - Enables double memory free check in this module. + + +#ifndef NRF_BALLOC_CONFIG_DOUBLE_FREE_CHECK_ENABLED +#define NRF_BALLOC_CONFIG_DOUBLE_FREE_CHECK_ENABLED 0 +#endif + +// NRF_BALLOC_CONFIG_DATA_TRASHING_CHECK_ENABLED - Enables free memory corruption check in this module. + + +#ifndef NRF_BALLOC_CONFIG_DATA_TRASHING_CHECK_ENABLED +#define NRF_BALLOC_CONFIG_DATA_TRASHING_CHECK_ENABLED 0 +#endif + +// NRF_BALLOC_CLI_CMDS - Enable CLI commands specific to the module + + +#ifndef NRF_BALLOC_CLI_CMDS +#define NRF_BALLOC_CLI_CMDS 0 +#endif + +// + +// + +// NRF_MEMOBJ_ENABLED - nrf_memobj - Linked memory allocator module + + +#ifndef NRF_MEMOBJ_ENABLED +#define NRF_MEMOBJ_ENABLED 1 +#endif + +// NRF_STRERROR_ENABLED - nrf_strerror - Library for converting error code to string. + + +#ifndef NRF_STRERROR_ENABLED +#define NRF_STRERROR_ENABLED 1 +#endif + +// nrf_fprintf - fprintf function. + +//========================================================== +// NRF_FPRINTF_ENABLED - Enable/disable fprintf module. + + +#ifndef NRF_FPRINTF_ENABLED +#define NRF_FPRINTF_ENABLED 1 +#endif + +// NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED - For each printed LF, function will add CR. + + +#ifndef NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED +#define NRF_FPRINTF_FLAG_AUTOMATIC_CR_ON_LF_ENABLED 1 +#endif + +// NRF_FPRINTF_DOUBLE_ENABLED - Enable IEEE-754 double precision formatting. + + +#ifndef NRF_FPRINTF_DOUBLE_ENABLED +#define NRF_FPRINTF_DOUBLE_ENABLED 0 +#endif + +// +//========================================================== + +// +//========================================================== + +// nRF_Log + +//========================================================== +// NRF_LOG_ENABLED - nrf_log - Logger +//========================================================== +#ifndef NRF_LOG_ENABLED +#define NRF_LOG_ENABLED 0 +#endif +// Log message pool - Configuration of log message pool + +//========================================================== +// NRF_LOG_MSGPOOL_ELEMENT_SIZE - Size of a single element in the pool of memory objects. +// If a small value is set, then performance of logs processing +// is degraded because data is fragmented. Bigger value impacts +// RAM memory utilization. The size is set to fit a message with +// a timestamp and up to 2 arguments in a single memory object. + +#ifndef NRF_LOG_MSGPOOL_ELEMENT_SIZE +#define NRF_LOG_MSGPOOL_ELEMENT_SIZE 20 +#endif + +// NRF_LOG_MSGPOOL_ELEMENT_COUNT - Number of elements in the pool of memory objects +// If a small value is set, then it may lead to a deadlock +// in certain cases if backend has high latency and holds +// multiple messages for long time. Bigger value impacts +// RAM memory usage. + +#ifndef NRF_LOG_MSGPOOL_ELEMENT_COUNT +#define NRF_LOG_MSGPOOL_ELEMENT_COUNT 8 +#endif + +// +//========================================================== + +// NRF_LOG_ALLOW_OVERFLOW - Configures behavior when circular buffer is full. + + +// If set then oldest logs are overwritten. Otherwise a +// marker is injected informing about overflow. + +#ifndef NRF_LOG_ALLOW_OVERFLOW +#define NRF_LOG_ALLOW_OVERFLOW 1 +#endif + +// NRF_LOG_BUFSIZE - Size of the buffer for storing logs (in bytes). + + +// Must be power of 2 and multiple of 4. +// If NRF_LOG_DEFERRED = 0 then buffer size can be reduced to minimum. +// <128=> 128 +// <256=> 256 +// <512=> 512 +// <1024=> 1024 +// <2048=> 2048 +// <4096=> 4096 +// <8192=> 8192 +// <16384=> 16384 + +#ifndef NRF_LOG_BUFSIZE +#define NRF_LOG_BUFSIZE 1024 +#endif + +// NRF_LOG_CLI_CMDS - Enable CLI commands for the module. + + +#ifndef NRF_LOG_CLI_CMDS +#define NRF_LOG_CLI_CMDS 0 +#endif + +// NRF_LOG_DEFAULT_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_LOG_DEFAULT_LEVEL +#define NRF_LOG_DEFAULT_LEVEL 3 +#endif + +// NRF_LOG_DEFERRED - Enable deffered logger. + + +// Log data is buffered and can be processed in idle. + +#ifndef NRF_LOG_DEFERRED +#define NRF_LOG_DEFERRED 1 +#endif + +// NRF_LOG_FILTERS_ENABLED - Enable dynamic filtering of logs. + + +#ifndef NRF_LOG_FILTERS_ENABLED +#define NRF_LOG_FILTERS_ENABLED 0 +#endif + +// NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED - Enable use of critical region for non deffered mode when flushing logs. + + +// When enabled NRF_LOG_FLUSH is called from critical section when non deffered mode is used. +// Log output will never be corrupted as access to the log backend is exclusive +// but system will spend significant amount of time in critical section + +#ifndef NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED +#define NRF_LOG_NON_DEFFERED_CRITICAL_REGION_ENABLED 0 +#endif + +// NRF_LOG_STR_PUSH_BUFFER_SIZE - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH. + +// <16=> 16 +// <32=> 32 +// <64=> 64 +// <128=> 128 +// <256=> 256 +// <512=> 512 +// <1024=> 1024 + +#ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE +#define NRF_LOG_STR_PUSH_BUFFER_SIZE 128 +#endif + +// NRF_LOG_STR_PUSH_BUFFER_SIZE - Size of the buffer dedicated for strings stored using @ref NRF_LOG_PUSH. + +// <16=> 16 +// <32=> 32 +// <64=> 64 +// <128=> 128 +// <256=> 256 +// <512=> 512 +// <1024=> 1024 + +#ifndef NRF_LOG_STR_PUSH_BUFFER_SIZE +#define NRF_LOG_STR_PUSH_BUFFER_SIZE 128 +#endif + +// NRF_LOG_USES_COLORS - If enabled then ANSI escape code for colors is prefixed to every string +//========================================================== +#ifndef NRF_LOG_USES_COLORS +#define NRF_LOG_USES_COLORS 0 +#endif +// NRF_LOG_COLOR_DEFAULT - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_LOG_COLOR_DEFAULT +#define NRF_LOG_COLOR_DEFAULT 0 +#endif + +// NRF_LOG_ERROR_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_LOG_ERROR_COLOR +#define NRF_LOG_ERROR_COLOR 2 +#endif + +// NRF_LOG_WARNING_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_LOG_WARNING_COLOR +#define NRF_LOG_WARNING_COLOR 4 +#endif + +// + +// NRF_LOG_USES_TIMESTAMP - Enable timestamping + +// Function for getting the timestamp is provided by the user +//========================================================== +#ifndef NRF_LOG_USES_TIMESTAMP +#define NRF_LOG_USES_TIMESTAMP 0 +#endif +// NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY - Default frequency of the timestamp (in Hz) or 0 to use app_timer frequency. +#ifndef NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY +#define NRF_LOG_TIMESTAMP_DEFAULT_FREQUENCY 0 +#endif + +// + +// nrf_log module configuration + +//========================================================== +// nrf_log in nRF_Core + +//========================================================== +// NRF_MPU_LIB_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_MPU_LIB_CONFIG_LOG_ENABLED +#define NRF_MPU_LIB_CONFIG_LOG_ENABLED 0 +#endif +// NRF_MPU_LIB_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_MPU_LIB_CONFIG_LOG_LEVEL +#define NRF_MPU_LIB_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_MPU_LIB_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_MPU_LIB_CONFIG_INFO_COLOR +#define NRF_MPU_LIB_CONFIG_INFO_COLOR 0 +#endif + +// NRF_MPU_LIB_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_MPU_LIB_CONFIG_DEBUG_COLOR +#define NRF_MPU_LIB_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_STACK_GUARD_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_STACK_GUARD_CONFIG_LOG_ENABLED +#define NRF_STACK_GUARD_CONFIG_LOG_ENABLED 0 +#endif +// NRF_STACK_GUARD_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_STACK_GUARD_CONFIG_LOG_LEVEL +#define NRF_STACK_GUARD_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_STACK_GUARD_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_STACK_GUARD_CONFIG_INFO_COLOR +#define NRF_STACK_GUARD_CONFIG_INFO_COLOR 0 +#endif + +// NRF_STACK_GUARD_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_STACK_GUARD_CONFIG_DEBUG_COLOR +#define NRF_STACK_GUARD_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// TASK_MANAGER_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef TASK_MANAGER_CONFIG_LOG_ENABLED +#define TASK_MANAGER_CONFIG_LOG_ENABLED 0 +#endif +// TASK_MANAGER_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef TASK_MANAGER_CONFIG_LOG_LEVEL +#define TASK_MANAGER_CONFIG_LOG_LEVEL 3 +#endif + +// TASK_MANAGER_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TASK_MANAGER_CONFIG_INFO_COLOR +#define TASK_MANAGER_CONFIG_INFO_COLOR 0 +#endif + +// TASK_MANAGER_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TASK_MANAGER_CONFIG_DEBUG_COLOR +#define TASK_MANAGER_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// +//========================================================== + +// nrf_log in nRF_Drivers + +//========================================================== +// CLOCK_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef CLOCK_CONFIG_LOG_ENABLED +#define CLOCK_CONFIG_LOG_ENABLED 0 +#endif +// CLOCK_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef CLOCK_CONFIG_LOG_LEVEL +#define CLOCK_CONFIG_LOG_LEVEL 3 +#endif + +// CLOCK_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef CLOCK_CONFIG_INFO_COLOR +#define CLOCK_CONFIG_INFO_COLOR 0 +#endif + +// CLOCK_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef CLOCK_CONFIG_DEBUG_COLOR +#define CLOCK_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// COMP_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef COMP_CONFIG_LOG_ENABLED +#define COMP_CONFIG_LOG_ENABLED 0 +#endif +// COMP_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef COMP_CONFIG_LOG_LEVEL +#define COMP_CONFIG_LOG_LEVEL 3 +#endif + +// COMP_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef COMP_CONFIG_INFO_COLOR +#define COMP_CONFIG_INFO_COLOR 0 +#endif + +// COMP_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef COMP_CONFIG_DEBUG_COLOR +#define COMP_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// GPIOTE_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef GPIOTE_CONFIG_LOG_ENABLED +#define GPIOTE_CONFIG_LOG_ENABLED 0 +#endif +// GPIOTE_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef GPIOTE_CONFIG_LOG_LEVEL +#define GPIOTE_CONFIG_LOG_LEVEL 3 +#endif + +// GPIOTE_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef GPIOTE_CONFIG_INFO_COLOR +#define GPIOTE_CONFIG_INFO_COLOR 0 +#endif + +// GPIOTE_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef GPIOTE_CONFIG_DEBUG_COLOR +#define GPIOTE_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// LPCOMP_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef LPCOMP_CONFIG_LOG_ENABLED +#define LPCOMP_CONFIG_LOG_ENABLED 0 +#endif +// LPCOMP_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef LPCOMP_CONFIG_LOG_LEVEL +#define LPCOMP_CONFIG_LOG_LEVEL 3 +#endif + +// LPCOMP_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef LPCOMP_CONFIG_INFO_COLOR +#define LPCOMP_CONFIG_INFO_COLOR 0 +#endif + +// LPCOMP_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef LPCOMP_CONFIG_DEBUG_COLOR +#define LPCOMP_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// MAX3421E_HOST_CONFIG_LOG_ENABLED - Enable logging in the module +//========================================================== +#ifndef MAX3421E_HOST_CONFIG_LOG_ENABLED +#define MAX3421E_HOST_CONFIG_LOG_ENABLED 0 +#endif +// MAX3421E_HOST_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef MAX3421E_HOST_CONFIG_LOG_LEVEL +#define MAX3421E_HOST_CONFIG_LOG_LEVEL 3 +#endif + +// MAX3421E_HOST_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef MAX3421E_HOST_CONFIG_INFO_COLOR +#define MAX3421E_HOST_CONFIG_INFO_COLOR 0 +#endif + +// MAX3421E_HOST_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef MAX3421E_HOST_CONFIG_DEBUG_COLOR +#define MAX3421E_HOST_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRFX_USBD_CONFIG_LOG_ENABLED - Enable logging in the module +//========================================================== +#ifndef NRFX_USBD_CONFIG_LOG_ENABLED +#define NRFX_USBD_CONFIG_LOG_ENABLED 0 +#endif +// NRFX_USBD_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRFX_USBD_CONFIG_LOG_LEVEL +#define NRFX_USBD_CONFIG_LOG_LEVEL 3 +#endif + +// NRFX_USBD_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRFX_USBD_CONFIG_INFO_COLOR +#define NRFX_USBD_CONFIG_INFO_COLOR 0 +#endif + +// NRFX_USBD_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRFX_USBD_CONFIG_DEBUG_COLOR +#define NRFX_USBD_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// PDM_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef PDM_CONFIG_LOG_ENABLED +#define PDM_CONFIG_LOG_ENABLED 0 +#endif +// PDM_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef PDM_CONFIG_LOG_LEVEL +#define PDM_CONFIG_LOG_LEVEL 3 +#endif + +// PDM_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PDM_CONFIG_INFO_COLOR +#define PDM_CONFIG_INFO_COLOR 0 +#endif + +// PDM_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PDM_CONFIG_DEBUG_COLOR +#define PDM_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// PPI_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef PPI_CONFIG_LOG_ENABLED +#define PPI_CONFIG_LOG_ENABLED 0 +#endif +// PPI_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef PPI_CONFIG_LOG_LEVEL +#define PPI_CONFIG_LOG_LEVEL 3 +#endif + +// PPI_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PPI_CONFIG_INFO_COLOR +#define PPI_CONFIG_INFO_COLOR 0 +#endif + +// PPI_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PPI_CONFIG_DEBUG_COLOR +#define PPI_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// PWM_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef PWM_CONFIG_LOG_ENABLED +#define PWM_CONFIG_LOG_ENABLED 0 +#endif +// PWM_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef PWM_CONFIG_LOG_LEVEL +#define PWM_CONFIG_LOG_LEVEL 3 +#endif + +// PWM_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PWM_CONFIG_INFO_COLOR +#define PWM_CONFIG_INFO_COLOR 0 +#endif + +// PWM_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PWM_CONFIG_DEBUG_COLOR +#define PWM_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// QDEC_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef QDEC_CONFIG_LOG_ENABLED +#define QDEC_CONFIG_LOG_ENABLED 0 +#endif +// QDEC_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef QDEC_CONFIG_LOG_LEVEL +#define QDEC_CONFIG_LOG_LEVEL 3 +#endif + +// QDEC_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef QDEC_CONFIG_INFO_COLOR +#define QDEC_CONFIG_INFO_COLOR 0 +#endif + +// QDEC_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef QDEC_CONFIG_DEBUG_COLOR +#define QDEC_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// RNG_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef RNG_CONFIG_LOG_ENABLED +#define RNG_CONFIG_LOG_ENABLED 0 +#endif +// RNG_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef RNG_CONFIG_LOG_LEVEL +#define RNG_CONFIG_LOG_LEVEL 3 +#endif + +// RNG_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef RNG_CONFIG_INFO_COLOR +#define RNG_CONFIG_INFO_COLOR 0 +#endif + +// RNG_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef RNG_CONFIG_DEBUG_COLOR +#define RNG_CONFIG_DEBUG_COLOR 0 +#endif + +// RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED - Enables logging of random numbers. + + +#ifndef RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED +#define RNG_CONFIG_RANDOM_NUMBER_LOG_ENABLED 0 +#endif + +// + +// RTC_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef RTC_CONFIG_LOG_ENABLED +#define RTC_CONFIG_LOG_ENABLED 0 +#endif +// RTC_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef RTC_CONFIG_LOG_LEVEL +#define RTC_CONFIG_LOG_LEVEL 3 +#endif + +// RTC_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef RTC_CONFIG_INFO_COLOR +#define RTC_CONFIG_INFO_COLOR 0 +#endif + +// RTC_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef RTC_CONFIG_DEBUG_COLOR +#define RTC_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// SAADC_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef SAADC_CONFIG_LOG_ENABLED +#define SAADC_CONFIG_LOG_ENABLED 0 +#endif +// SAADC_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef SAADC_CONFIG_LOG_LEVEL +#define SAADC_CONFIG_LOG_LEVEL 3 +#endif + +// SAADC_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SAADC_CONFIG_INFO_COLOR +#define SAADC_CONFIG_INFO_COLOR 0 +#endif + +// SAADC_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SAADC_CONFIG_DEBUG_COLOR +#define SAADC_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// SPIS_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef SPIS_CONFIG_LOG_ENABLED +#define SPIS_CONFIG_LOG_ENABLED 0 +#endif +// SPIS_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef SPIS_CONFIG_LOG_LEVEL +#define SPIS_CONFIG_LOG_LEVEL 3 +#endif + +// SPIS_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SPIS_CONFIG_INFO_COLOR +#define SPIS_CONFIG_INFO_COLOR 0 +#endif + +// SPIS_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SPIS_CONFIG_DEBUG_COLOR +#define SPIS_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// SPI_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef SPI_CONFIG_LOG_ENABLED +#define SPI_CONFIG_LOG_ENABLED 0 +#endif +// SPI_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef SPI_CONFIG_LOG_LEVEL +#define SPI_CONFIG_LOG_LEVEL 3 +#endif + +// SPI_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SPI_CONFIG_INFO_COLOR +#define SPI_CONFIG_INFO_COLOR 0 +#endif + +// SPI_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SPI_CONFIG_DEBUG_COLOR +#define SPI_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// TIMER_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef TIMER_CONFIG_LOG_ENABLED +#define TIMER_CONFIG_LOG_ENABLED 0 +#endif +// TIMER_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef TIMER_CONFIG_LOG_LEVEL +#define TIMER_CONFIG_LOG_LEVEL 3 +#endif + +// TIMER_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TIMER_CONFIG_INFO_COLOR +#define TIMER_CONFIG_INFO_COLOR 0 +#endif + +// TIMER_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TIMER_CONFIG_DEBUG_COLOR +#define TIMER_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// TWIS_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef TWIS_CONFIG_LOG_ENABLED +#define TWIS_CONFIG_LOG_ENABLED 0 +#endif +// TWIS_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef TWIS_CONFIG_LOG_LEVEL +#define TWIS_CONFIG_LOG_LEVEL 3 +#endif + +// TWIS_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TWIS_CONFIG_INFO_COLOR +#define TWIS_CONFIG_INFO_COLOR 0 +#endif + +// TWIS_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TWIS_CONFIG_DEBUG_COLOR +#define TWIS_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// TWI_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef TWI_CONFIG_LOG_ENABLED +#define TWI_CONFIG_LOG_ENABLED 0 +#endif +// TWI_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef TWI_CONFIG_LOG_LEVEL +#define TWI_CONFIG_LOG_LEVEL 3 +#endif + +// TWI_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TWI_CONFIG_INFO_COLOR +#define TWI_CONFIG_INFO_COLOR 0 +#endif + +// TWI_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef TWI_CONFIG_DEBUG_COLOR +#define TWI_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// UART_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef UART_CONFIG_LOG_ENABLED +#define UART_CONFIG_LOG_ENABLED 0 +#endif +// UART_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef UART_CONFIG_LOG_LEVEL +#define UART_CONFIG_LOG_LEVEL 3 +#endif + +// UART_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef UART_CONFIG_INFO_COLOR +#define UART_CONFIG_INFO_COLOR 0 +#endif + +// UART_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef UART_CONFIG_DEBUG_COLOR +#define UART_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// USBD_CONFIG_LOG_ENABLED - Enable logging in the module +//========================================================== +#ifndef USBD_CONFIG_LOG_ENABLED +#define USBD_CONFIG_LOG_ENABLED 0 +#endif +// USBD_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef USBD_CONFIG_LOG_LEVEL +#define USBD_CONFIG_LOG_LEVEL 3 +#endif + +// USBD_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef USBD_CONFIG_INFO_COLOR +#define USBD_CONFIG_INFO_COLOR 0 +#endif + +// USBD_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef USBD_CONFIG_DEBUG_COLOR +#define USBD_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// WDT_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef WDT_CONFIG_LOG_ENABLED +#define WDT_CONFIG_LOG_ENABLED 0 +#endif +// WDT_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef WDT_CONFIG_LOG_LEVEL +#define WDT_CONFIG_LOG_LEVEL 3 +#endif + +// WDT_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef WDT_CONFIG_INFO_COLOR +#define WDT_CONFIG_INFO_COLOR 0 +#endif + +// WDT_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef WDT_CONFIG_DEBUG_COLOR +#define WDT_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// +//========================================================== + +// nrf_log in nRF_Libraries + +//========================================================== +// APP_BUTTON_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef APP_BUTTON_CONFIG_LOG_ENABLED +#define APP_BUTTON_CONFIG_LOG_ENABLED 0 +#endif +// APP_BUTTON_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_BUTTON_CONFIG_LOG_LEVEL +#define APP_BUTTON_CONFIG_LOG_LEVEL 3 +#endif + +// APP_BUTTON_CONFIG_INITIAL_LOG_LEVEL - Initial severity level if dynamic filtering is enabled. + + +// If module generates a lot of logs, initial log level can +// be decreased to prevent flooding. Severity level can be +// increased on instance basis. +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_BUTTON_CONFIG_INITIAL_LOG_LEVEL +#define APP_BUTTON_CONFIG_INITIAL_LOG_LEVEL 3 +#endif + +// APP_BUTTON_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_BUTTON_CONFIG_INFO_COLOR +#define APP_BUTTON_CONFIG_INFO_COLOR 0 +#endif + +// APP_BUTTON_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_BUTTON_CONFIG_DEBUG_COLOR +#define APP_BUTTON_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// APP_TIMER_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef APP_TIMER_CONFIG_LOG_ENABLED +#define APP_TIMER_CONFIG_LOG_ENABLED 0 +#endif +// APP_TIMER_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_TIMER_CONFIG_LOG_LEVEL +#define APP_TIMER_CONFIG_LOG_LEVEL 3 +#endif + +// APP_TIMER_CONFIG_INITIAL_LOG_LEVEL - Initial severity level if dynamic filtering is enabled. + + +// If module generates a lot of logs, initial log level can +// be decreased to prevent flooding. Severity level can be +// increased on instance basis. +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_TIMER_CONFIG_INITIAL_LOG_LEVEL +#define APP_TIMER_CONFIG_INITIAL_LOG_LEVEL 3 +#endif + +// APP_TIMER_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_TIMER_CONFIG_INFO_COLOR +#define APP_TIMER_CONFIG_INFO_COLOR 0 +#endif + +// APP_TIMER_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_TIMER_CONFIG_DEBUG_COLOR +#define APP_TIMER_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// APP_USBD_CDC_ACM_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef APP_USBD_CDC_ACM_CONFIG_LOG_ENABLED +#define APP_USBD_CDC_ACM_CONFIG_LOG_ENABLED 0 +#endif +// APP_USBD_CDC_ACM_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_USBD_CDC_ACM_CONFIG_LOG_LEVEL +#define APP_USBD_CDC_ACM_CONFIG_LOG_LEVEL 3 +#endif + +// APP_USBD_CDC_ACM_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_CDC_ACM_CONFIG_INFO_COLOR +#define APP_USBD_CDC_ACM_CONFIG_INFO_COLOR 0 +#endif + +// APP_USBD_CDC_ACM_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_CDC_ACM_CONFIG_DEBUG_COLOR +#define APP_USBD_CDC_ACM_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// APP_USBD_CONFIG_LOG_ENABLED - Enable logging in the module. +//========================================================== +#ifndef APP_USBD_CONFIG_LOG_ENABLED +#define APP_USBD_CONFIG_LOG_ENABLED 0 +#endif +// APP_USBD_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_USBD_CONFIG_LOG_LEVEL +#define APP_USBD_CONFIG_LOG_LEVEL 3 +#endif + +// APP_USBD_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_CONFIG_INFO_COLOR +#define APP_USBD_CONFIG_INFO_COLOR 0 +#endif + +// APP_USBD_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_CONFIG_DEBUG_COLOR +#define APP_USBD_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// APP_USBD_DUMMY_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef APP_USBD_DUMMY_CONFIG_LOG_ENABLED +#define APP_USBD_DUMMY_CONFIG_LOG_ENABLED 0 +#endif +// APP_USBD_DUMMY_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_USBD_DUMMY_CONFIG_LOG_LEVEL +#define APP_USBD_DUMMY_CONFIG_LOG_LEVEL 3 +#endif + +// APP_USBD_DUMMY_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_DUMMY_CONFIG_INFO_COLOR +#define APP_USBD_DUMMY_CONFIG_INFO_COLOR 0 +#endif + +// APP_USBD_DUMMY_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_DUMMY_CONFIG_DEBUG_COLOR +#define APP_USBD_DUMMY_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// APP_USBD_MSC_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef APP_USBD_MSC_CONFIG_LOG_ENABLED +#define APP_USBD_MSC_CONFIG_LOG_ENABLED 0 +#endif +// APP_USBD_MSC_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_USBD_MSC_CONFIG_LOG_LEVEL +#define APP_USBD_MSC_CONFIG_LOG_LEVEL 3 +#endif + +// APP_USBD_MSC_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_MSC_CONFIG_INFO_COLOR +#define APP_USBD_MSC_CONFIG_INFO_COLOR 0 +#endif + +// APP_USBD_MSC_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_MSC_CONFIG_DEBUG_COLOR +#define APP_USBD_MSC_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// APP_USBD_NRF_DFU_TRIGGER_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef APP_USBD_NRF_DFU_TRIGGER_CONFIG_LOG_ENABLED +#define APP_USBD_NRF_DFU_TRIGGER_CONFIG_LOG_ENABLED 0 +#endif +// APP_USBD_NRF_DFU_TRIGGER_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef APP_USBD_NRF_DFU_TRIGGER_CONFIG_LOG_LEVEL +#define APP_USBD_NRF_DFU_TRIGGER_CONFIG_LOG_LEVEL 3 +#endif + +// APP_USBD_NRF_DFU_TRIGGER_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_NRF_DFU_TRIGGER_CONFIG_INFO_COLOR +#define APP_USBD_NRF_DFU_TRIGGER_CONFIG_INFO_COLOR 0 +#endif + +// APP_USBD_NRF_DFU_TRIGGER_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef APP_USBD_NRF_DFU_TRIGGER_CONFIG_DEBUG_COLOR +#define APP_USBD_NRF_DFU_TRIGGER_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_ATFIFO_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_ATFIFO_CONFIG_LOG_ENABLED +#define NRF_ATFIFO_CONFIG_LOG_ENABLED 0 +#endif +// NRF_ATFIFO_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_ATFIFO_CONFIG_LOG_LEVEL +#define NRF_ATFIFO_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL - Initial severity level if dynamic filtering is enabled + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL +#define NRF_ATFIFO_CONFIG_LOG_INIT_FILTER_LEVEL 3 +#endif + +// NRF_ATFIFO_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_ATFIFO_CONFIG_INFO_COLOR +#define NRF_ATFIFO_CONFIG_INFO_COLOR 0 +#endif + +// NRF_ATFIFO_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_ATFIFO_CONFIG_DEBUG_COLOR +#define NRF_ATFIFO_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_BALLOC_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_BALLOC_CONFIG_LOG_ENABLED +#define NRF_BALLOC_CONFIG_LOG_ENABLED 0 +#endif +// NRF_BALLOC_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BALLOC_CONFIG_LOG_LEVEL +#define NRF_BALLOC_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_BALLOC_CONFIG_INITIAL_LOG_LEVEL - Initial severity level if dynamic filtering is enabled. + + +// If module generates a lot of logs, initial log level can +// be decreased to prevent flooding. Severity level can be +// increased on instance basis. +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BALLOC_CONFIG_INITIAL_LOG_LEVEL +#define NRF_BALLOC_CONFIG_INITIAL_LOG_LEVEL 3 +#endif + +// NRF_BALLOC_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BALLOC_CONFIG_INFO_COLOR +#define NRF_BALLOC_CONFIG_INFO_COLOR 0 +#endif + +// NRF_BALLOC_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BALLOC_CONFIG_DEBUG_COLOR +#define NRF_BALLOC_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_ENABLED +#define NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_ENABLED 0 +#endif +// NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_LEVEL +#define NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_INIT_FILTER_LEVEL - Initial severity level if dynamic filtering is enabled + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_INIT_FILTER_LEVEL +#define NRF_BLOCK_DEV_EMPTY_CONFIG_LOG_INIT_FILTER_LEVEL 3 +#endif + +// NRF_BLOCK_DEV_EMPTY_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BLOCK_DEV_EMPTY_CONFIG_INFO_COLOR +#define NRF_BLOCK_DEV_EMPTY_CONFIG_INFO_COLOR 0 +#endif + +// NRF_BLOCK_DEV_EMPTY_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BLOCK_DEV_EMPTY_CONFIG_DEBUG_COLOR +#define NRF_BLOCK_DEV_EMPTY_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_BLOCK_DEV_QSPI_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_BLOCK_DEV_QSPI_CONFIG_LOG_ENABLED +#define NRF_BLOCK_DEV_QSPI_CONFIG_LOG_ENABLED 0 +#endif +// NRF_BLOCK_DEV_QSPI_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BLOCK_DEV_QSPI_CONFIG_LOG_LEVEL +#define NRF_BLOCK_DEV_QSPI_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_BLOCK_DEV_QSPI_CONFIG_LOG_INIT_FILTER_LEVEL - Initial severity level if dynamic filtering is enabled + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BLOCK_DEV_QSPI_CONFIG_LOG_INIT_FILTER_LEVEL +#define NRF_BLOCK_DEV_QSPI_CONFIG_LOG_INIT_FILTER_LEVEL 3 +#endif + +// NRF_BLOCK_DEV_QSPI_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BLOCK_DEV_QSPI_CONFIG_INFO_COLOR +#define NRF_BLOCK_DEV_QSPI_CONFIG_INFO_COLOR 0 +#endif + +// NRF_BLOCK_DEV_QSPI_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BLOCK_DEV_QSPI_CONFIG_DEBUG_COLOR +#define NRF_BLOCK_DEV_QSPI_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_BLOCK_DEV_RAM_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_BLOCK_DEV_RAM_CONFIG_LOG_ENABLED +#define NRF_BLOCK_DEV_RAM_CONFIG_LOG_ENABLED 0 +#endif +// NRF_BLOCK_DEV_RAM_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BLOCK_DEV_RAM_CONFIG_LOG_LEVEL +#define NRF_BLOCK_DEV_RAM_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_BLOCK_DEV_RAM_CONFIG_LOG_INIT_FILTER_LEVEL - Initial severity level if dynamic filtering is enabled + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_BLOCK_DEV_RAM_CONFIG_LOG_INIT_FILTER_LEVEL +#define NRF_BLOCK_DEV_RAM_CONFIG_LOG_INIT_FILTER_LEVEL 3 +#endif + +// NRF_BLOCK_DEV_RAM_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BLOCK_DEV_RAM_CONFIG_INFO_COLOR +#define NRF_BLOCK_DEV_RAM_CONFIG_INFO_COLOR 0 +#endif + +// NRF_BLOCK_DEV_RAM_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_BLOCK_DEV_RAM_CONFIG_DEBUG_COLOR +#define NRF_BLOCK_DEV_RAM_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_CLI_BLE_UART_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_CLI_BLE_UART_CONFIG_LOG_ENABLED +#define NRF_CLI_BLE_UART_CONFIG_LOG_ENABLED 0 +#endif +// NRF_CLI_BLE_UART_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_CLI_BLE_UART_CONFIG_LOG_LEVEL +#define NRF_CLI_BLE_UART_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_CLI_BLE_UART_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_CLI_BLE_UART_CONFIG_INFO_COLOR +#define NRF_CLI_BLE_UART_CONFIG_INFO_COLOR 0 +#endif + +// NRF_CLI_BLE_UART_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_CLI_BLE_UART_CONFIG_DEBUG_COLOR +#define NRF_CLI_BLE_UART_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED +#define NRF_CLI_LIBUARTE_CONFIG_LOG_ENABLED 0 +#endif +// NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL +#define NRF_CLI_LIBUARTE_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_CLI_LIBUARTE_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_CLI_LIBUARTE_CONFIG_INFO_COLOR +#define NRF_CLI_LIBUARTE_CONFIG_INFO_COLOR 0 +#endif + +// NRF_CLI_LIBUARTE_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_CLI_LIBUARTE_CONFIG_DEBUG_COLOR +#define NRF_CLI_LIBUARTE_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_CLI_UART_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_CLI_UART_CONFIG_LOG_ENABLED +#define NRF_CLI_UART_CONFIG_LOG_ENABLED 0 +#endif +// NRF_CLI_UART_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_CLI_UART_CONFIG_LOG_LEVEL +#define NRF_CLI_UART_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_CLI_UART_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_CLI_UART_CONFIG_INFO_COLOR +#define NRF_CLI_UART_CONFIG_INFO_COLOR 0 +#endif + +// NRF_CLI_UART_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_CLI_UART_CONFIG_DEBUG_COLOR +#define NRF_CLI_UART_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_LIBUARTE_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_LIBUARTE_CONFIG_LOG_ENABLED +#define NRF_LIBUARTE_CONFIG_LOG_ENABLED 0 +#endif +// NRF_LIBUARTE_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_LIBUARTE_CONFIG_LOG_LEVEL +#define NRF_LIBUARTE_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_LIBUARTE_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_LIBUARTE_CONFIG_INFO_COLOR +#define NRF_LIBUARTE_CONFIG_INFO_COLOR 0 +#endif + +// NRF_LIBUARTE_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_LIBUARTE_CONFIG_DEBUG_COLOR +#define NRF_LIBUARTE_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_MEMOBJ_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_MEMOBJ_CONFIG_LOG_ENABLED +#define NRF_MEMOBJ_CONFIG_LOG_ENABLED 0 +#endif +// NRF_MEMOBJ_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_MEMOBJ_CONFIG_LOG_LEVEL +#define NRF_MEMOBJ_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_MEMOBJ_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_MEMOBJ_CONFIG_INFO_COLOR +#define NRF_MEMOBJ_CONFIG_INFO_COLOR 0 +#endif + +// NRF_MEMOBJ_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_MEMOBJ_CONFIG_DEBUG_COLOR +#define NRF_MEMOBJ_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_PWR_MGMT_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_PWR_MGMT_CONFIG_LOG_ENABLED +#define NRF_PWR_MGMT_CONFIG_LOG_ENABLED 0 +#endif +// NRF_PWR_MGMT_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_PWR_MGMT_CONFIG_LOG_LEVEL +#define NRF_PWR_MGMT_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_PWR_MGMT_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_PWR_MGMT_CONFIG_INFO_COLOR +#define NRF_PWR_MGMT_CONFIG_INFO_COLOR 0 +#endif + +// NRF_PWR_MGMT_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_PWR_MGMT_CONFIG_DEBUG_COLOR +#define NRF_PWR_MGMT_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_QUEUE_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_QUEUE_CONFIG_LOG_ENABLED +#define NRF_QUEUE_CONFIG_LOG_ENABLED 0 +#endif +// NRF_QUEUE_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_QUEUE_CONFIG_LOG_LEVEL +#define NRF_QUEUE_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL - Initial severity level if dynamic filtering is enabled + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL +#define NRF_QUEUE_CONFIG_LOG_INIT_FILTER_LEVEL 3 +#endif + +// NRF_QUEUE_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_QUEUE_CONFIG_INFO_COLOR +#define NRF_QUEUE_CONFIG_INFO_COLOR 0 +#endif + +// NRF_QUEUE_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_QUEUE_CONFIG_DEBUG_COLOR +#define NRF_QUEUE_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_SDH_ANT_LOG_ENABLED - Enable logging in SoftDevice handler (ANT) module. +//========================================================== +#ifndef NRF_SDH_ANT_LOG_ENABLED +#define NRF_SDH_ANT_LOG_ENABLED 0 +#endif +// NRF_SDH_ANT_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_SDH_ANT_LOG_LEVEL +#define NRF_SDH_ANT_LOG_LEVEL 3 +#endif + +// NRF_SDH_ANT_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_ANT_INFO_COLOR +#define NRF_SDH_ANT_INFO_COLOR 0 +#endif + +// NRF_SDH_ANT_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_ANT_DEBUG_COLOR +#define NRF_SDH_ANT_DEBUG_COLOR 0 +#endif + +// + +// NRF_SDH_BLE_LOG_ENABLED - Enable logging in SoftDevice handler (BLE) module. +//========================================================== +#ifndef NRF_SDH_BLE_LOG_ENABLED +#define NRF_SDH_BLE_LOG_ENABLED 0 +#endif +// NRF_SDH_BLE_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_SDH_BLE_LOG_LEVEL +#define NRF_SDH_BLE_LOG_LEVEL 3 +#endif + +// NRF_SDH_BLE_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_BLE_INFO_COLOR +#define NRF_SDH_BLE_INFO_COLOR 0 +#endif + +// NRF_SDH_BLE_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_BLE_DEBUG_COLOR +#define NRF_SDH_BLE_DEBUG_COLOR 0 +#endif + +// + +// NRF_SDH_LOG_ENABLED - Enable logging in SoftDevice handler module. +//========================================================== +#ifndef NRF_SDH_LOG_ENABLED +#define NRF_SDH_LOG_ENABLED 0 +#endif +// NRF_SDH_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_SDH_LOG_LEVEL +#define NRF_SDH_LOG_LEVEL 3 +#endif + +// NRF_SDH_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_INFO_COLOR +#define NRF_SDH_INFO_COLOR 0 +#endif + +// NRF_SDH_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_DEBUG_COLOR +#define NRF_SDH_DEBUG_COLOR 0 +#endif + +// + +// NRF_SDH_SOC_LOG_ENABLED - Enable logging in SoftDevice handler (SoC) module. +//========================================================== +#ifndef NRF_SDH_SOC_LOG_ENABLED +#define NRF_SDH_SOC_LOG_ENABLED 0 +#endif +// NRF_SDH_SOC_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_SDH_SOC_LOG_LEVEL +#define NRF_SDH_SOC_LOG_LEVEL 3 +#endif + +// NRF_SDH_SOC_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_SOC_INFO_COLOR +#define NRF_SDH_SOC_INFO_COLOR 0 +#endif + +// NRF_SDH_SOC_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SDH_SOC_DEBUG_COLOR +#define NRF_SDH_SOC_DEBUG_COLOR 0 +#endif + +// + +// NRF_SORTLIST_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_SORTLIST_CONFIG_LOG_ENABLED +#define NRF_SORTLIST_CONFIG_LOG_ENABLED 0 +#endif +// NRF_SORTLIST_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_SORTLIST_CONFIG_LOG_LEVEL +#define NRF_SORTLIST_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_SORTLIST_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SORTLIST_CONFIG_INFO_COLOR +#define NRF_SORTLIST_CONFIG_INFO_COLOR 0 +#endif + +// NRF_SORTLIST_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_SORTLIST_CONFIG_DEBUG_COLOR +#define NRF_SORTLIST_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// NRF_TWI_SENSOR_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRF_TWI_SENSOR_CONFIG_LOG_ENABLED +#define NRF_TWI_SENSOR_CONFIG_LOG_ENABLED 0 +#endif +// NRF_TWI_SENSOR_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRF_TWI_SENSOR_CONFIG_LOG_LEVEL +#define NRF_TWI_SENSOR_CONFIG_LOG_LEVEL 3 +#endif + +// NRF_TWI_SENSOR_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_TWI_SENSOR_CONFIG_INFO_COLOR +#define NRF_TWI_SENSOR_CONFIG_INFO_COLOR 0 +#endif + +// NRF_TWI_SENSOR_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRF_TWI_SENSOR_CONFIG_DEBUG_COLOR +#define NRF_TWI_SENSOR_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// PM_LOG_ENABLED - Enable logging in Peer Manager and its submodules. +//========================================================== +#ifndef PM_LOG_ENABLED +#define PM_LOG_ENABLED 1 +#endif +// PM_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef PM_LOG_LEVEL +#define PM_LOG_LEVEL 3 +#endif + +// PM_LOG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PM_LOG_INFO_COLOR +#define PM_LOG_INFO_COLOR 0 +#endif + +// PM_LOG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef PM_LOG_DEBUG_COLOR +#define PM_LOG_DEBUG_COLOR 0 +#endif + +// + +// +//========================================================== + +// nrf_log in nRF_Serialization + +//========================================================== +// SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED +#define SER_HAL_TRANSPORT_CONFIG_LOG_ENABLED 0 +#endif +// SER_HAL_TRANSPORT_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef SER_HAL_TRANSPORT_CONFIG_LOG_LEVEL +#define SER_HAL_TRANSPORT_CONFIG_LOG_LEVEL 3 +#endif + +// SER_HAL_TRANSPORT_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SER_HAL_TRANSPORT_CONFIG_INFO_COLOR +#define SER_HAL_TRANSPORT_CONFIG_INFO_COLOR 0 +#endif + +// SER_HAL_TRANSPORT_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef SER_HAL_TRANSPORT_CONFIG_DEBUG_COLOR +#define SER_HAL_TRANSPORT_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// +//========================================================== + +// +//========================================================== + +// + +// NRF_LOG_STR_FORMATTER_TIMESTAMP_FORMAT_ENABLED - nrf_log_str_formatter - Log string formatter + + +#ifndef NRF_LOG_STR_FORMATTER_TIMESTAMP_FORMAT_ENABLED +#define NRF_LOG_STR_FORMATTER_TIMESTAMP_FORMAT_ENABLED 1 +#endif + +// +//========================================================== + +// nRF_Drivers + +//========================================================== +// NRFX_CLOCK_ENABLED - nrfx_clock - CLOCK peripheral driver +//========================================================== +#ifndef NRFX_CLOCK_ENABLED +#define NRFX_CLOCK_ENABLED 1 +#endif +// NRFX_CLOCK_CONFIG_LF_SRC - LF Clock Source + +// <0=> RC +// <1=> XTAL +// <2=> Synth +// <131073=> External Low Swing +// <196609=> External Full Swing + +#ifndef NRFX_CLOCK_CONFIG_LF_SRC +#define NRFX_CLOCK_CONFIG_LF_SRC 1 +#endif + +// NRFX_CLOCK_CONFIG_IRQ_PRIORITY - Interrupt priority + +// <0=> 0 (highest) +// <1=> 1 +// <2=> 2 +// <3=> 3 +// <4=> 4 +// <5=> 5 +// <6=> 6 +// <7=> 7 + +#ifndef NRFX_CLOCK_CONFIG_IRQ_PRIORITY +#define NRFX_CLOCK_CONFIG_IRQ_PRIORITY 6 +#endif + +// NRFX_CLOCK_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRFX_CLOCK_CONFIG_LOG_ENABLED +#define NRFX_CLOCK_CONFIG_LOG_ENABLED 0 +#endif +// NRFX_CLOCK_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRFX_CLOCK_CONFIG_LOG_LEVEL +#define NRFX_CLOCK_CONFIG_LOG_LEVEL 3 +#endif + +// NRFX_CLOCK_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRFX_CLOCK_CONFIG_INFO_COLOR +#define NRFX_CLOCK_CONFIG_INFO_COLOR 0 +#endif + +// NRFX_CLOCK_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRFX_CLOCK_CONFIG_DEBUG_COLOR +#define NRFX_CLOCK_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// + + +// NRFX_RTC_ENABLED - nrfx_rtc - RTC peripheral driver +//========================================================== +#ifndef NRFX_RTC_ENABLED +#define NRFX_RTC_ENABLED 1 +#endif +// NRFX_RTC0_ENABLED - Enable RTC0 instance + + +#ifndef NRFX_RTC0_ENABLED +#define NRFX_RTC0_ENABLED 1 +#endif + +// NRFX_RTC1_ENABLED - Enable RTC1 instance + + +#ifndef NRFX_RTC1_ENABLED +#define NRFX_RTC1_ENABLED 0 +#endif + +// NRFX_RTC2_ENABLED - Enable RTC2 instance + + +#ifndef NRFX_RTC2_ENABLED +#define NRFX_RTC2_ENABLED 0 +#endif + +// NRFX_RTC_MAXIMUM_LATENCY_US - Maximum possible time[us] in highest priority interrupt +#ifndef NRFX_RTC_MAXIMUM_LATENCY_US +#define NRFX_RTC_MAXIMUM_LATENCY_US 2000 +#endif + +// NRFX_RTC_DEFAULT_CONFIG_FREQUENCY - Frequency <16-32768> + + +#ifndef NRFX_RTC_DEFAULT_CONFIG_FREQUENCY +#define NRFX_RTC_DEFAULT_CONFIG_FREQUENCY 32768 +#endif + +// NRFX_RTC_DEFAULT_CONFIG_RELIABLE - Ensures safe compare event triggering + + +#ifndef NRFX_RTC_DEFAULT_CONFIG_RELIABLE +#define NRFX_RTC_DEFAULT_CONFIG_RELIABLE 0 +#endif + +// NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY - Interrupt priority + +// <0=> 0 (highest) +// <1=> 1 +// <2=> 2 +// <3=> 3 +// <4=> 4 +// <5=> 5 +// <6=> 6 +// <7=> 7 + +#ifndef NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY +#define NRFX_RTC_DEFAULT_CONFIG_IRQ_PRIORITY 6 +#endif + +// NRFX_RTC_CONFIG_LOG_ENABLED - Enables logging in the module. +//========================================================== +#ifndef NRFX_RTC_CONFIG_LOG_ENABLED +#define NRFX_RTC_CONFIG_LOG_ENABLED 0 +#endif +// NRFX_RTC_CONFIG_LOG_LEVEL - Default Severity level + +// <0=> Off +// <1=> Error +// <2=> Warning +// <3=> Info +// <4=> Debug + +#ifndef NRFX_RTC_CONFIG_LOG_LEVEL +#define NRFX_RTC_CONFIG_LOG_LEVEL 3 +#endif + +// NRFX_RTC_CONFIG_INFO_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRFX_RTC_CONFIG_INFO_COLOR +#define NRFX_RTC_CONFIG_INFO_COLOR 0 +#endif + +// NRFX_RTC_CONFIG_DEBUG_COLOR - ANSI escape code prefix. + +// <0=> Default +// <1=> Black +// <2=> Red +// <3=> Green +// <4=> Yellow +// <5=> Blue +// <6=> Magenta +// <7=> Cyan +// <8=> White + +#ifndef NRFX_RTC_CONFIG_DEBUG_COLOR +#define NRFX_RTC_CONFIG_DEBUG_COLOR 0 +#endif + +// + +// + + +// <<< end of configuration section >>> +#endif //SDK_CONFIG_H + diff --git a/port/nrf5-cinnamon/port/btstack_config.h b/port/nrf5-cinnamon/port/btstack_config.h new file mode 100644 index 000000000..6f9c8e5b7 --- /dev/null +++ b/port/nrf5-cinnamon/port/btstack_config.h @@ -0,0 +1,42 @@ +// +// btstack_config.h for nRF5x LL +// + +#ifndef BTSTACK_CONFIG_H +#define BTSTACK_CONFIG_H + +// Port related features +#define HAVE_EM9304_PATCH_CONTAINER +#define HAVE_EMBEDDED_TIME_MS + +// BTstack features that can be enabled +#define ENABLE_BLE +#define ENABLE_LE_CENTRAL +#define ENABLE_LE_DATA_LENGTH_EXTENSION +#define ENABLE_LE_PERIPHERAL +#define ENABLE_LOG_ERROR +#define ENABLE_LOG_INFO +#define ENABLE_PRINTF_HEXDUMP +#define ENABLE_SEGGER_RTT +#define ENABLE_BTSTACK_ASSERT + +// BTstack configuration. buffers, sizes, ... +#define HCI_ACL_PAYLOAD_SIZE 100 +#define MAX_NR_GATT_CLIENTS 1 +#define MAX_NR_HCI_CONNECTIONS 1 +#define MAX_NR_L2CAP_CHANNELS 1 +#define MAX_NR_L2CAP_SERVICES 1 +#define MAX_NR_SM_LOOKUP_ENTRIES 3 +#define MAX_NR_WHITELIST_ENTRIES 1 + +// LE Device DB using TLV on top of Flash Sector interface +#define NVM_NUM_DEVICE_DB_ENTRIES 16 + +// GPIO debugging +#define DEBUG_PIN_HF_CLOCK 19 +#define DEBUG_PIN_ADDRESS 20 +#define DEBUG_PIN_RX 22 +#define DEBUG_PIN_TX 23 +#define DEBUG_PIN_RADIO_IRQ 24 + +#endif diff --git a/port/nrf5-cinnamon/port/debug.h b/port/nrf5-cinnamon/port/debug.h new file mode 100644 index 000000000..80dac8509 --- /dev/null +++ b/port/nrf5-cinnamon/port/debug.h @@ -0,0 +1,51 @@ +/******************************************************************************* + * + *      Copyright (c) 2018, Raccon BLE Sniffer + *      All rights reserved. + * + *      Redistribution and use in source and binary forms, with or without + *      modification, are permitted provided that the following conditions are + *      met: + *       + *      * Redistributions of source code must retain the above copyright + *        notice, this list of conditions and the following disclaimer. + *      * Redistributions in binary form must reproduce the above + *        copyright notice, this list of conditions and the following disclaimer + *        in the documentation and/or other materials provided with the + *        distribution. + *      * Neither the name of "btlejack2" nor the names of its + *        contributors may be used to endorse or promote products derived from + *        this software without specific prior written permission. + *       + *      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + *      "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + *      LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + *      A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + *      OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + *      SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + *      LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + *      DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + *      THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + *      (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + *      OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + *******************************************************************************/ + +#ifndef _DEBUG_H_ +#define _DEBUG_H_ + +#ifdef DEBUG + +#include "SEGGER_RTT.h" +#define printf(...) SEGGER_RTT_printf( 0, __VA_ARGS__ ) +#define LOG_DBG(...) SEGGER_RTT_printf( 0, __VA_ARGS__ ) +#define log(format, ...) SEGGER_RTT_printf(0, "[%010u] " format, __HAL_TIM_GET_COUNTER(&htim2), ## __VA_ARGS__) + +#else + +#define printf(...) +#define LOG_DBG(...) + +#endif + +#endif // _DEBUG_H_ diff --git a/port/nrf5-cinnamon/port/hal_timer.h b/port/nrf5-cinnamon/port/hal_timer.h new file mode 100644 index 000000000..b385ee15a --- /dev/null +++ b/port/nrf5-cinnamon/port/hal_timer.h @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2020 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +/* + * hci_event.h + */ + +#ifndef HAL_TIMER_H +#define HCI_TIMER_H + +#include "bluetooth.h" + +#include +#include + +#if defined __cplusplus +extern "C" { +#endif + +/* + * @brief Initialize 32.768 kHz timer, usually low power and used by RTC and in deep sleep + */ +void hal_timer_init(void); + +/* + * @brief Set Timer Callback + * @param callback + */ +void hal_timer_set_callback(void (*callback)(void)); + +/** + * @brief Get current ticks + * @return num_ticks + */ +uint32_t hal_timer_get_ticks(void); + +/** + * @brief Stop Timer + */ +void hal_timer_stop(void); + +/** + * @brief Start Timer and fire at given timeout + * @param timeout_ticks timeout in ticks + */ +void hal_timer_start(uint32_t timeout_ticks); + +#if defined __cplusplus +} +#endif +#endif // HAL_TIMER_H diff --git a/port/nrf5-cinnamon/port/hal_timer_nrf5.c b/port/nrf5-cinnamon/port/hal_timer_nrf5.c new file mode 100644 index 000000000..2c06f5066 --- /dev/null +++ b/port/nrf5-cinnamon/port/hal_timer_nrf5.c @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2020 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +#define BTSTACK_FILE__ "hal_timer_nrf5.c" + +/* + * hal_timer.c + * HAL for 32.768 kHz low power timer with 16 bit resolution + * @note Only uses one of multiple RTCs and only a single Capture-Compare unit + */ + +#include "hal_timer.h" +#include "btstack_debug.h" + +#include "nrf.h" + +static void (*hal_timer_callback)(void); + +void RTC0_IRQHandler(void){ + if (NRF_RTC0->EVENTS_COMPARE[0]){ + NRF_RTC0->EVENTS_COMPARE[0] = 0; + btstack_assert(hal_timer_callback != NULL); + (*hal_timer_callback)(); + } +} + +void hal_timer_init(void) { + /* Stop the timer first */ + NRF_RTC0->TASKS_STOP = 1; + NRF_RTC0->TASKS_CLEAR = 1; + + /* Always no prescaler */ + NRF_RTC0->PRESCALER = 0; + + /* Clear overflow events and set overflow interrupt */ + NRF_RTC0->EVENTS_OVRFLW = 0; + NRF_RTC0->INTENSET = RTC_INTENSET_OVRFLW_Msk; + + /* Start the timer */ + NRF_RTC0->TASKS_START = 1; + + /* Set isr in vector table and enable interrupt */ + NVIC_EnableIRQ( RTC0_IRQn ); +} + +void hal_timer_set_callback(void (*callback)(void)){ + hal_timer_callback = callback; +} + +uint32_t hal_timer_get_ticks(void){ + return NRF_RTC0->COUNTER; +} + +void hal_timer_stop(void){ + NRF_RTC0->INTENCLR =RTC_INTENCLR_COMPARE0_Msk; +} + +void hal_timer_start(uint32_t timeout_ticks){ + NRF_RTC0->CC[0] = timeout_ticks & 0x00ffffff; + NRF_RTC0->EVENTS_COMPARE[0] = 0; + NRF_RTC0->INTENSET =RTC_INTENSET_COMPARE0_Msk; +} diff --git a/port/nrf5-cinnamon/port/ll_nrf5.c b/port/nrf5-cinnamon/port/ll_nrf5.c new file mode 100644 index 000000000..24f49bdfb --- /dev/null +++ b/port/nrf5-cinnamon/port/ll_nrf5.c @@ -0,0 +1,1408 @@ +/* + * Copyright (C) 2020 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +#define BTSTACK_FILE__ "ll_nrf5.c" + +#define DEBUG + +#include +#include + +#include "ll.h" + +#include "btstack_config.h" +#include "btstack_debug.h" +#include "btstack_memory.h" +#include "btstack_memory_pool.h" +#include "btstack_linked_queue.h" +#include "bluetooth_company_id.h" +#include "hal_cpu.h" +#include "hci_event.h" +#include "hopping.h" +#include "hal_timer.h" +#include "radio.h" +#include "nrf.h" + +// +// configuration +// + +// bluetooth +// bluetooth.h +#define ADVERTISING_RADIO_ACCESS_ADDRESS 0x8E89BED6 +#define ADVERTISING_CRC_INIT 0x555555 + +#define ACL_LE_MAX_PAYLOAD 31 +#define ADV_MAX_PAYLOAD (6+6+22) +#define LL_MAX_PAYLOAD 37 + +// sync hop delay - time we prepare for next connection event +#define SYNC_HOP_DELAY_US 700 + +// timeout between RX complete and next RX packet +#define TX_TO_RX_TIMEOUT_US 250 + +// num tx buffers for use by link layer +#define HCI_NUM_TX_BUFFERS_LL 4 + +// num rx buffers +#define HCI_NUM_RX_BUFFERS 16 + +// total number PDU buffers +#define MAX_NUM_LL_PDUS (HCI_NUM_TX_BUFFERS_STACK + HCI_NUM_TX_BUFFERS_LL + HCI_NUM_RX_BUFFERS) + +// HCI Connection Handle used for all HCI events/connections +#define HCI_CON_HANDLE 0x0001 + +// convert us to ticks, rounding to the closest tick count +// @note us must be <= 1000000 us = 1 s +#define US_TO_TICKS(US) (((((uint32_t)(US)) * 4096) + 6125) / 125000L) + +// ADV PDU Types +enum pdu_adv_type { + PDU_ADV_TYPE_ADV_IND = 0x00, + PDU_ADV_TYPE_DIRECT_IND = 0x01, + PDU_ADV_TYPE_NONCONN_IND = 0x02, + PDU_ADV_TYPE_SCAN_REQ = 0x03, + PDU_ADV_TYPE_AUX_SCAN_REQ = PDU_ADV_TYPE_SCAN_REQ, + PDU_ADV_TYPE_SCAN_RSP = 0x04, + PDU_ADV_TYPE_CONNECT_IND = 0x05, + PDU_ADV_TYPE_AUX_CONNECT_REQ = PDU_ADV_TYPE_CONNECT_IND, + PDU_ADV_TYPE_SCAN_IND = 0x06, + PDU_ADV_TYPE_EXT_IND = 0x07, + PDU_ADV_TYPE_AUX_ADV_IND = PDU_ADV_TYPE_EXT_IND, + PDU_ADV_TYPE_AUX_SCAN_RSP = PDU_ADV_TYPE_EXT_IND, + PDU_ADV_TYPE_AUX_SYNC_IND = PDU_ADV_TYPE_EXT_IND, + PDU_ADV_TYPE_AUX_CHAIN_IND = PDU_ADV_TYPE_EXT_IND, + PDU_ADV_TYPE_AUX_CONNECT_RSP = 0x08, +}; + +// DATA PDU Types +enum pdu_data_llid { + PDU_DATA_LLID_RESV = 0x00, + PDU_DATA_LLID_DATA_CONTINUE = 0x01, + PDU_DATA_LLID_DATA_START = 0x02, + PDU_DATA_LLID_CTRL = 0x03, +}; + +// DATA Link Layer Control Types +enum pdu_data_llctrl_type { + PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND = 0x00, + PDU_DATA_LLCTRL_TYPE_CHAN_MAP_IND = 0x01, + PDU_DATA_LLCTRL_TYPE_TERMINATE_IND = 0x02, + PDU_DATA_LLCTRL_TYPE_ENC_REQ = 0x03, + PDU_DATA_LLCTRL_TYPE_ENC_RSP = 0x04, + PDU_DATA_LLCTRL_TYPE_START_ENC_REQ = 0x05, + PDU_DATA_LLCTRL_TYPE_START_ENC_RSP = 0x06, + PDU_DATA_LLCTRL_TYPE_UNKNOWN_RSP = 0x07, + PDU_DATA_LLCTRL_TYPE_FEATURE_REQ = 0x08, + PDU_DATA_LLCTRL_TYPE_FEATURE_RSP = 0x09, + PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_REQ = 0x0A, + PDU_DATA_LLCTRL_TYPE_PAUSE_ENC_RSP = 0x0B, + PDU_DATA_LLCTRL_TYPE_VERSION_IND = 0x0C, + PDU_DATA_LLCTRL_TYPE_REJECT_IND = 0x0D, + PDU_DATA_LLCTRL_TYPE_SLAVE_FEATURE_REQ = 0x0E, + PDU_DATA_LLCTRL_TYPE_CONN_PARAM_REQ = 0x0F, + PDU_DATA_LLCTRL_TYPE_CONN_PARAM_RSP = 0x10, + PDU_DATA_LLCTRL_TYPE_REJECT_EXT_IND = 0x11, + PDU_DATA_LLCTRL_TYPE_PING_REQ = 0x12, + PDU_DATA_LLCTRL_TYPE_PING_RSP = 0x13, + PDU_DATA_LLCTRL_TYPE_LENGTH_REQ = 0x14, + PDU_DATA_LLCTRL_TYPE_LENGTH_RSP = 0x15, + PDU_DATA_LLCTRL_TYPE_PHY_REQ = 0x16, + PDU_DATA_LLCTRL_TYPE_PHY_RSP = 0x17, + PDU_DATA_LLCTRL_TYPE_PHY_UPD_IND = 0x18, + PDU_DATA_LLCTRL_TYPE_MIN_USED_CHAN_IND = 0x19, +}; + +// Link Layer State +typedef enum { + LL_STATE_STANDBY, + LL_STATE_SCANNING, + LL_STATE_ADVERTISING, + LL_STATE_INITIATING, + LL_STATE_CONNECTED +} ll_state_t; + +// Link Layer PDU Flags +typedef enum { + LL_PDU_FLAG_DATA_PDU = 1, +} ll_pdu_flags; + +// Link Layer PDU, used in linked list +typedef struct { + // header + void * item; + hci_con_handle_t con_handle; + uint8_t flags; + int8_t rssi; + uint16_t connection_event; + uint16_t packet_nr; + // over the air data + uint8_t header; + uint8_t len; + uint8_t payload[LL_MAX_PAYLOAD]; +} ll_pdu_t; + + +// hopping context +static hopping_t h; + +static struct { + + volatile bool synced; + + volatile uint16_t packet_nr_in_connection_event; + + volatile uint16_t conn_interval_1250us; + volatile uint32_t conn_interval_us; + volatile uint16_t conn_interval_ticks; + + volatile uint16_t conn_latency; + + volatile uint16_t supervision_timeout_10ms; + volatile uint32_t supervision_timeout_us; + + // + volatile uint32_t time_without_any_packets_us; + + // access address + volatile uint32_t aa; + + // start of current connection event + volatile uint32_t anchor_ticks; + + // custom anchor delta to apply on next sync hop (if != 0) + volatile uint16_t anchor_delta_ticks; + + // latest time to send tx packet before sync hop + volatile uint16_t conn_latest_tx_ticks; + + // timeout for sync relative to anchor + volatile uint16_t conn_sync_hop_ticks; + + // current channel + volatile uint8_t channel; + + // CSA #2 supported + uint8_t csa2_support; + + // channels selection algorithm index (1 for csa #2) + volatile uint8_t channel_selection_algorithm; + + // current connection event, first one starts with 0 + // - needed for connection param and channel map updates as well as encryption + volatile uint16_t connection_event; + + // pending channel map update + volatile bool channel_map_update_pending; + volatile uint16_t channel_map_update_instant; + volatile uint8_t channel_map_update_map[5]; + + // pending connection param update + volatile bool conn_param_update_pending; + volatile uint16_t conn_param_update_instant; + volatile uint8_t conn_param_update_win_size; + volatile uint16_t conn_param_update_win_offset; + volatile uint16_t conn_param_update_interval_1250us; + volatile uint16_t conn_param_update_latency; + volatile uint32_t conn_param_update_timeout_us; + + // our bd_addr as little endian + uint8_t bd_addr_le[6]; + + // peer addr + uint8_t peer_addr_type; + uint8_t peer_addr[6]; + + // adv data + uint8_t adv_len; + uint8_t adv_data[31]; + + // adv param + uint8_t adv_map; + uint32_t adv_interval_us; + uint8_t adv_type; + + // adv data + uint8_t scan_resp_len; + uint8_t scan_resp_data[31]; + + // transmit window size in us + volatile uint32_t transmit_window_size_us; + + // transmit window offset in us + volatile uint32_t transmit_window_offset_us; + + // next expected sequence number + volatile uint8_t next_expected_sequence_number; + + // transmit sequence number + volatile uint8_t transmit_sequence_number; + + // remote active: more data or non-empty packet + volatile bool remote_active; + + + // rx queue + btstack_linked_queue_t rx_queue; + + // current incoming packet + ll_pdu_t * rx_pdu; + + // tx queue of outgoing pdus + btstack_linked_queue_t tx_queue; + + // current outgoing packet + ll_pdu_t * tx_pdu; + + // num completed packets + volatile uint8_t num_completed; + + // used for controller events + volatile uint8_t error_code; + + volatile bool ll_send_disconnected; + + volatile bool ll_send_connection_complete; + +} ctx; + +// Buffer pool +static ll_pdu_t ll_pdu_pool_storage[MAX_NUM_LL_PDUS]; +static btstack_memory_pool_t ll_pdu_pool; + +// prepared adv + scan packets +static uint8_t adv_packet_data[39]; +static uint8_t adv_packet_len; +static uint8_t scan_packet_data[39]; +static uint8_t scan_packet_len; + +// single ll empty pdu +static uint8_t ll_empty_pdu[2]; + +// single ll control response +static ll_pdu_t ll_tx_packet; + +// Link Layer State +static ll_state_t ll_state; +static uint32_t ll_scan_interval_us; +static uint32_t ll_scan_window_us; + +static ll_pdu_t * ll_reserved_acl_buffer; + +// Controller interface +static uint8_t ll_outgoing_hci_event[258]; +static void (*controller_packet_handler)(uint8_t packet_type, uint8_t * packet, uint16_t size); + +// Memory Pool for acl-le pdus + +static ll_pdu_t * btstack_memory_ll_pdu_get(void){ + void * buffer = btstack_memory_pool_get(&ll_pdu_pool); + if (buffer){ + memset(buffer, 0, sizeof(ll_pdu_t)); + } + return (ll_pdu_t *) buffer; +} + +static void btstack_memory_ll_pdu_free(ll_pdu_t *acl_le_pdu){ + btstack_memory_pool_free(&ll_pdu_pool, acl_le_pdu); +} + +// Link Layer + +// prototypes + +static bool ll_prepare_rx_buffer(void){ + if (ctx.rx_pdu == NULL){ + ctx.rx_pdu = btstack_memory_ll_pdu_get(); + } + if (ctx.rx_pdu == NULL){ + printf("No free RX buffer\n"); + return false; + } else { + return true; + } +} + +static void ll_stop_timer(void){ + hal_timer_stop(); +} + +static void ll_set_timer_ticks(uint32_t anchor_offset_ticks){ + ll_stop_timer(); + // set timer for next radio event relative to anchor + uint32_t timeout_ticks = ctx.anchor_ticks + anchor_offset_ticks; + hal_timer_start(timeout_ticks); +} + +// preamble (1) + aa (4) + header (1) + len (1) + payload (len) + crc (3) -- ISR handler ca. 5 us (educated guess) +static uint32_t ll_start_ticks_for_end_time_and_len(uint32_t packet_end_ticks, uint16_t len){ + uint32_t timestamp_delay = (10 + len) * 8 - 5; + uint32_t packet_start_ticks = packet_end_ticks - US_TO_TICKS(timestamp_delay); + return packet_start_ticks; +} + +static void ll_emit_hci_event(const hci_event_t * event, ...){ + va_list argptr; + va_start(argptr, event); + uint16_t length = hci_event_create_from_template_and_arglist(ll_outgoing_hci_event, event, argptr); + va_end(argptr); + controller_packet_handler(HCI_EVENT_PACKET, ll_outgoing_hci_event, length); +} + +// ll adv prototypes + +static void ll_advertising_timer_handler(void); +static void ll_advertising_tx_done(radio_result_t result); +static void ll_advertising_tx_to_rx(radio_result_t result); + +static void ll_advertising_statemachine(void){ + // find next channel + while (ctx.channel < 40){ + ctx.channel++; + if ((ctx.adv_map & (1 << (ctx.channel - 37))) != 0) { + // Set Channel + radio_set_channel(ctx.channel); + // Expect response? + radio_transition_t transition; + radio_callback_t callback; + if (ctx.adv_type == 3){ + // Non connectable undirected advertising (ADV_NONCONN_IND) + transition = RADIO_TRANSITION_TX_ONLY; + callback = &ll_advertising_tx_done; + } else { + // All other are either connectable and/or scannable + transition = RADIO_TRANSITION_TX_TO_RX; + callback = &ll_advertising_tx_to_rx; + } + // log_info("Send adv on #%u", ctx.channel); + radio_transmit(callback, transition, adv_packet_data, adv_packet_len); + break; + } + // adv sent on all active channels + if (ctx.channel >= 40){ + // Disable HF Clock + radio_hf_clock_disable(); + + // Set timer + uint32_t adv_interval_ticks = US_TO_TICKS(ctx.adv_interval_us); + hal_timer_set_callback(&ll_advertising_timer_handler); + ll_set_timer_ticks(adv_interval_ticks); + } + } +} + +static void ll_advertising_tx_done(radio_result_t result){ + UNUSED(result); + ll_advertising_statemachine(); +} + +static void ll_advertising_disabled(radio_result_t result){ + UNUSED(result); + ll_advertising_statemachine(); +} + +static void ll_advertising_conn_ind_received(radio_result_t result){ + UNUSED(result); + ll_pdu_t * rx_packet = ctx.rx_pdu; + // packet used + ctx.rx_pdu = NULL; + // mark as adv packet + rx_packet->flags = 0; + // queue received packet -> ll_execute_once + btstack_linked_queue_enqueue(&ctx.rx_queue, (btstack_linked_item_t *) rx_packet); +} + +static void ll_advertising_rx_done(radio_result_t result){ + uint8_t pdu_type; + switch (result){ + case RADIO_RESULT_OK: + // check for Scan and Connect requests + pdu_type = ctx.rx_pdu->header & 0x0f; + switch (pdu_type){ + case PDU_ADV_TYPE_SCAN_REQ: + switch (ctx.adv_type) { + case 3: + // ignore for ADV_NONCONN_IND + radio_stop(&ll_advertising_disabled); + break; + default: + radio_transmit(&ll_advertising_tx_done, RADIO_TRANSITION_TX_ONLY, scan_packet_data, scan_packet_len); + break; + } + break; + case PDU_ADV_TYPE_CONNECT_IND: + switch (ctx.adv_type){ + case 2: // ADV_SCAN_IND + case 3: // ADV_NONCONN_IND + radio_stop(&ll_advertising_disabled); + break; + default: + // store ticks as anchor + ctx.anchor_ticks = hal_timer_get_ticks(); + // stop radio and + radio_stop(&ll_advertising_conn_ind_received); + break; + } + break; + default: + radio_stop(&ll_advertising_disabled); + break; + } + break; + case RADIO_RESULT_TIMEOUT: + ll_advertising_statemachine(); + break; + case RADIO_RESULT_CRC_ERROR: + radio_stop(&ll_advertising_disabled); + break; + default: + btstack_assert(false); + break; + } +} + +static void ll_advertising_tx_to_rx(radio_result_t result){ + UNUSED(result); + if (ll_prepare_rx_buffer()){ + radio_receive(&ll_advertising_rx_done, TX_TO_RX_TIMEOUT_US, &ctx.rx_pdu->header, 2 + LL_MAX_PAYLOAD, NULL); + } else { + // TODO: stop radio + btstack_assert(false); + } +} + +static void ll_advertising_timer_handler(void){ + + uint32_t t0 = hal_timer_get_ticks(); + + // enable HF Clock + radio_hf_clock_enable(true); + + // send adv on all configured channels + ctx.channel = 36; + ctx.anchor_ticks = t0; + ll_advertising_statemachine(); +} + +static uint16_t ll_advertising_setup_pdu(uint8_t * buffer, uint8_t header, uint8_t len, const uint8_t * data){ + buffer[0] = header; + buffer[1] = 6 + len; + memcpy(&buffer[2], ctx.bd_addr_le, 6); + memcpy(&buffer[8], data, len); + uint16_t packet_size = 2 + buffer[1]; + return packet_size; +} + +static uint8_t ll_advertising_start(void){ + // COMMAND DISALLOWED if wrong state. + if (ll_state != LL_STATE_STANDBY) return ERROR_CODE_COMMAND_DISALLOWED; + log_info("Start Advertising on channels 0x%0x, interval %lu us", ctx.adv_map, ctx.adv_interval_us); + + radio_set_access_address(ADVERTISING_RADIO_ACCESS_ADDRESS); + radio_set_crc_init(ADVERTISING_CRC_INIT); + + ll_state = LL_STATE_ADVERTISING; + + // prepare adv and scan data in tx0 and tx1 + enum pdu_adv_type adv_type; + switch (ctx.adv_type){ + case 0: + // Connectable and scannable undirected advertising + adv_type = PDU_ADV_TYPE_ADV_IND; + break; + case 1: + // Connectable high duty cycle directed advertising + adv_type = PDU_ADV_TYPE_DIRECT_IND; + break; + case 2: + // Scannable undirected advertising (ADV_SCAN_IND); + adv_type = PDU_ADV_TYPE_SCAN_IND; + break; + case 3: + // Non connectable undirected advertising (ADV_NONCONN_IND) + adv_type = PDU_ADV_TYPE_NONCONN_IND; + break; + case 4: + // Connectable low duty cycle directed advertising + adv_type = PDU_ADV_TYPE_DIRECT_IND; + break; + default: + adv_type = PDU_ADV_TYPE_ADV_IND; + break; + } + adv_packet_len = ll_advertising_setup_pdu(adv_packet_data, adv_type, ctx.adv_len, ctx.adv_data); + scan_packet_len = ll_advertising_setup_pdu(scan_packet_data, PDU_ADV_TYPE_SCAN_RSP, ctx.scan_resp_len, ctx.scan_resp_data); + + ctx.channel = 36; + ctx.anchor_ticks = hal_timer_get_ticks(); + + // and get started + radio_hf_clock_enable(true); + ll_advertising_statemachine(); + + return ERROR_CODE_SUCCESS; +} + +static uint8_t ll_advertising_stop(void){ + // COMMAND DISALLOWED if wrong state. + if (ll_state != LL_STATE_ADVERTISING) return ERROR_CODE_COMMAND_DISALLOWED; + + // TODO: + return ERROR_CODE_SUCCESS; +} + +// ll scanning + +static void ll_scanning_statemachine(void); + +static void ll_scanning_for_window(void){ + radio_hf_clock_enable(true); + // next channel + ctx.channel++; + if (ctx.channel >= 40){ + ctx.channel = 37; + } + radio_set_channel(ctx.channel); + ctx.anchor_ticks = hal_timer_get_ticks(); + log_info("Scan channel %u", ctx.channel); + ll_scanning_statemachine(); +} + +static void ll_scanning_tx_interrupted(radio_result_t result){ + UNUSED(result); + ll_scanning_statemachine(); +} + +static void ll_scanning_rx_done(radio_result_t result){ + ll_pdu_t * rx_packet; + switch (result){ + case RADIO_RESULT_OK: + rx_packet = ctx.rx_pdu; + btstack_assert(rx_packet != NULL); + // packet used + ctx.rx_pdu = NULL; + // mark as adv packet + rx_packet->flags = 0; + // queue received packet + btstack_linked_queue_enqueue(&ctx.rx_queue, (btstack_linked_item_t *) rx_packet); + // stop rx->tx transition + radio_stop(&ll_scanning_tx_interrupted); + break; + case RADIO_RESULT_CRC_ERROR: + // stop rx->tx transition + radio_stop(&ll_scanning_tx_interrupted); + break; + case RADIO_RESULT_TIMEOUT: + ll_scanning_statemachine(); + break; + default: + break; + } +} + +static void ll_scanning_statemachine(void){ + uint32_t now = hal_timer_get_ticks(); + uint32_t scanning_active_ticks = now - ctx.anchor_ticks; + uint32_t scanning_active_us = (scanning_active_ticks * 70) / 2; + + ll_prepare_rx_buffer(); + + if ((scanning_active_us < ll_scan_window_us) && (ctx.rx_pdu != NULL)){ + uint32_t scan_interval_remaining_us = ll_scan_window_us - scanning_active_us; + // start receiving + radio_receive(&ll_scanning_rx_done, scan_interval_remaining_us, &ctx.rx_pdu->header, 2 + LL_MAX_PAYLOAD, &ctx.rx_pdu->rssi); + } else { + // scan window over or no buffer + + // disable radio if there is enough time + uint32_t pause_us = ll_scan_interval_us - scanning_active_us; + if (pause_us < 500){ + // almost 100% scanning, keep hf clock on + ll_scanning_for_window(); + } else { + radio_hf_clock_disable(); + hal_timer_set_callback(&ll_scanning_for_window); + hal_timer_start(now + US_TO_TICKS(pause_us)); + } + } +} + +static uint8_t ll_scanning_start(uint8_t filter_duplicates){ + + // COMMAND DISALLOWED if wrong state. + if (ll_state != LL_STATE_STANDBY) return ERROR_CODE_COMMAND_DISALLOWED; + + ll_state = LL_STATE_SCANNING; + ctx.channel = 36; + + radio_set_access_address(ADVERTISING_RADIO_ACCESS_ADDRESS); + radio_set_crc_init(ADVERTISING_CRC_INIT); + + log_info("LE Scan Start: window %lu, interval %lu ms", ll_scan_interval_us, ll_scan_window_us); + + ll_scanning_for_window(); + + return ERROR_CODE_SUCCESS; +} + +static void ll_scanning_stop_done(radio_result_t result){ + UNUSED(result); + ll_state = LL_STATE_STANDBY; + radio_hf_clock_disable(); +} + +static uint8_t ll_scanning_stop(void){ + // COMMAND DISALLOWED if wrong state. + if (ll_state != LL_STATE_SCANNING) return 0x0c; + + // TODO: post-pone result until scanning actually stopped + log_info("LE Scan Stop"); + + // stop radio + radio_stop(&ll_scanning_stop_done); + return ERROR_CODE_SUCCESS; +} + +// ll connected + +static bool ll_connected_one_more_packet(void){ + uint32_t now = hal_timer_get_ticks(); + int32_t connection_ticks = now - ctx.anchor_ticks; + return connection_ticks < ctx.conn_latest_tx_ticks; +} + +static void ll_connected_next_channel(void){ + switch (ctx.channel_selection_algorithm){ + case 0: + ctx.channel = hopping_csa1_get_next_channel( &h ); + break; + case 1: + ctx.channel = hopping_csa2_get_channel_for_counter( &h, ctx.connection_event); + break; + default: + break; + } + radio_set_channel(ctx.channel); +} + +static void ll_connected_ctx_set_conn_interval(uint16_t conn_interval_1250us){ + ctx.conn_interval_1250us = conn_interval_1250us; + ctx.conn_interval_us = ctx.conn_interval_1250us * 1250; + ctx.conn_interval_ticks = US_TO_TICKS(ctx.conn_interval_us); + ctx.conn_sync_hop_ticks = US_TO_TICKS(ctx.conn_interval_us - SYNC_HOP_DELAY_US); + + // latest time to send a packet before getting ready for next cnonection event + uint16_t max_packet_time_incl_ifs_us = 500; + ctx.conn_latest_tx_ticks = US_TO_TICKS(ctx.conn_interval_us - SYNC_HOP_DELAY_US - max_packet_time_incl_ifs_us); +} + +static void ll_connected_terminate(uint8_t error_code){ + ll_state = LL_STATE_STANDBY; + ctx.conn_param_update_pending = false; + ctx.channel_map_update_pending = false; + // turn off clock + radio_hf_clock_disable(); + // stop sync hop timer + ll_stop_timer(); + // free outgoing tx packets + if ((ctx.tx_pdu != NULL) && (ctx.tx_pdu != &ll_tx_packet)){ + btstack_memory_ll_pdu_free(ctx.tx_pdu); + ctx.tx_pdu = NULL; + } + // free queued tx packets + while (true){ + ll_pdu_t * tx_packet = (ll_pdu_t *) btstack_linked_queue_dequeue(&ctx.tx_queue); + if (tx_packet != NULL) { + btstack_memory_ll_pdu_free(tx_packet); + } else { + break; + } + } + // notify host stack + ctx.error_code = error_code; + ctx.ll_send_disconnected = true; +} + +static void ll_connected_timer_handler(void); +static void lL_connected_rx_done(radio_result_t result); + +static void ll_connected_connection_event_complete(void){ + radio_hf_clock_disable(); +} + +static void ll_connected_radio_stopped(radio_result_t result){ + UNUSED(result); + ll_connected_connection_event_complete(); +} + +static void ll_connected_tx_only_done(radio_result_t result){ + UNUSED(result); + ll_connected_connection_event_complete(); +} + +static void ll_connected_tx_to_rx_done(radio_result_t result) { + UNUSED(result); + if (!ll_connected_one_more_packet()){ + // stop tx + radio_stop(&ll_connected_radio_stopped); + return; + } + + // receive next packet + (void) ll_prepare_rx_buffer(); + if (ctx.rx_pdu == NULL){ + radio_stop(&ll_connected_radio_stopped); + return; + } + + // receive master packet + radio_receive(&lL_connected_rx_done, TX_TO_RX_TIMEOUT_US, &ctx.rx_pdu->header, 2 + LL_MAX_PAYLOAD, NULL); +} + +static void ll_connected_terminate_received(radio_result_t result){ + UNUSED(result); + ll_connected_terminate(ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION); +} + +static void lL_connected_rx_done(radio_result_t result){ + + uint32_t packet_end_ticks = hal_timer_get_ticks(); + + if (result == RADIO_RESULT_TIMEOUT){ + ll_connected_connection_event_complete(); + return; + } + + // Handle RX + + // set anchor on first packet in connection event + if (ctx.packet_nr_in_connection_event == 0){ + ctx.anchor_ticks = ll_start_ticks_for_end_time_and_len(packet_end_ticks, ctx.rx_pdu->len); + ctx.synced = true; + + // set timer for sync-hop + hal_timer_set_callback(&ll_connected_timer_handler); + ll_set_timer_ticks( ctx.conn_sync_hop_ticks); + } + + // packet received + if (result == RADIO_RESULT_OK) { + + // parse rx pdu header + uint8_t rx_header = ctx.rx_pdu->header; + uint8_t next_expected_sequence_number = (rx_header >> 2) & 1; + uint8_t sequence_number = (rx_header >> 3) & 1; + uint8_t more_data = (rx_header >> 4) & 1; + + // remote active if md or len > 0 + ctx.remote_active = (more_data != 0) || ctx.rx_pdu->len > 0; + + // only accept packets with new sequence number and len <= payload size + if ((sequence_number == ctx.next_expected_sequence_number) && (ctx.rx_pdu->len <= LL_MAX_PAYLOAD)) { + + // update state + ctx.next_expected_sequence_number = 1 - sequence_number; + + // queue if not empty + ll_pdu_t *rx_packet = ctx.rx_pdu; + if (rx_packet->len != 0) { + + // handle terminate immediately + uint8_t ll_id = rx_packet->header & 3; + if (ll_id == PDU_DATA_LLID_CTRL) { + if (rx_packet->payload[0] == PDU_DATA_LLCTRL_TYPE_TERMINATE_IND){ + ll_stop_timer(); + radio_stop(&ll_connected_terminate_received); + return; + } + } + + // packet used + ctx.rx_pdu = NULL; + + // mark as data packet and add meta data + rx_packet->flags |= LL_PDU_FLAG_DATA_PDU; + rx_packet->connection_event = ctx.connection_event; + rx_packet->packet_nr = ctx.packet_nr_in_connection_event; + + // queue received packet + btstack_linked_queue_enqueue(&ctx.rx_queue, (btstack_linked_item_t *) rx_packet); + } + } + + ctx.packet_nr_in_connection_event++; + + // report outgoing packet as ack'ed and free if confirmed by peer + bool tx_acked = ctx.transmit_sequence_number != next_expected_sequence_number; + if (tx_acked) { + // if non link-layer packet, free buffer and report as completed + if ((ctx.tx_pdu != NULL) && (ctx.tx_pdu != &ll_tx_packet)) { + btstack_memory_ll_pdu_free(ctx.tx_pdu); + ctx.num_completed++; + } + ctx.tx_pdu = NULL; + ctx.transmit_sequence_number = next_expected_sequence_number; + } + } + + // restart supervision timeout + ctx.time_without_any_packets_us = 0; + + // Prepare TX + + // check if we can sent a full packet before sync hop + if (!ll_connected_one_more_packet()){ + // stop tx + radio_stop(&ll_connected_radio_stopped); + return; + } + + // fetch next packet + if (ctx.tx_pdu == NULL){ + ctx.tx_pdu = (ll_pdu_t *) btstack_linked_queue_dequeue(&ctx.tx_queue); + } + + // setup empty packet if no tx packet ready + uint8_t * tx_buffer; + if (ctx.tx_pdu == NULL){ + ll_empty_pdu[0] = PDU_DATA_LLID_DATA_CONTINUE; + ll_empty_pdu[1] = 0; + tx_buffer = ll_empty_pdu; + } else { + tx_buffer = &ctx.tx_pdu->header; + } + + // setup pdu header + uint8_t md = btstack_linked_queue_empty(&ctx.tx_queue) ? 0 : 1; + tx_buffer[0] |= (md << 4) | (ctx.transmit_sequence_number << 3) | (ctx.next_expected_sequence_number << 2); + + // send packet + bool tx_to_rx = ctx.remote_active || (tx_buffer[1] > 0); + if (tx_to_rx){ + radio_transmit(&ll_connected_tx_to_rx_done, RADIO_TRANSITION_TX_TO_RX, tx_buffer, 2 + tx_buffer[1]); + } else { + radio_transmit(&ll_connected_tx_only_done, RADIO_TRANSITION_TX_ONLY, tx_buffer, 2 + tx_buffer[1]); + } +} + +static void ll_connected_handle_conn_ind(ll_pdu_t * rx_packet){ + // parse packet + uint8_t * init_addr = &rx_packet->payload[0]; + uint8_t * adv_addr = &rx_packet->payload[6]; + uint8_t chan_sel = (rx_packet->header >> 5) & 1; + + // verify AdvA + if (memcmp(ctx.bd_addr_le, adv_addr, 6) != 0){ + // differs, go back to adv sending + ll_advertising_statemachine(); + return; + } + + // next event is > 1.25 ms away + radio_hf_clock_disable(); + + // TODO: get remote addr type + ctx.peer_addr_type = 0; + memcpy(ctx.peer_addr, init_addr, 6); + + // get params for HCI event + const uint8_t * ll_data = &rx_packet->payload[12]; + + ctx.aa = little_endian_read_32(ll_data, 0); + uint32_t crc_init = little_endian_read_24(ll_data, 4); + uint8_t transmit_window_size = ll_data[7]; + uint16_t transmit_window_offset = little_endian_read_16(ll_data, 8); + uint16_t conn_interval_1250us = little_endian_read_16(ll_data, 10); + ctx.conn_latency = little_endian_read_16(ll_data, 12); + ctx.supervision_timeout_10ms = little_endian_read_16(ll_data, 14); + const uint8_t * channel_map = &ll_data[16]; + uint8_t hop = ll_data[21] & 0x1f; + uint8_t sca = ll_data[21] >> 5; + + // TODO: handle sleep clock accuracy of initiator + UNUSED(sca); + + ll_connected_ctx_set_conn_interval(conn_interval_1250us); + + // convert to us + ctx.supervision_timeout_us = ctx.supervision_timeout_10ms * 10000; + ctx.transmit_window_size_us = transmit_window_size * 1250; + ctx.transmit_window_offset_us = transmit_window_offset * 1250; + + // init connection state + ctx.connection_event = 0; + ctx.packet_nr_in_connection_event = 0; + ctx.next_expected_sequence_number = 0; + ctx.transmit_sequence_number = 0; + + // set AA + radio_set_access_address(ctx.aa); + + // set CRC init value + radio_set_crc_init(crc_init); + + printf("Transmit window offset %u us\n", (int) ctx.transmit_window_offset_us); + printf("Transmit window size %u us\n", (int) ctx.transmit_window_size_us); + printf("Connection interval %u us\n", (int) ctx.conn_interval_us); + printf("Connection timeout %u us\n", (int) ctx.supervision_timeout_us); + printf("AA %08x\n", (int) ctx.aa); + printf("CRC Init 0x%06" PRIx32 "x\n", crc_init); + + // init hopping + hopping_init( &h ); + hopping_set_channel_map( &h, channel_map); + ctx.channel_selection_algorithm = ctx.csa2_support & chan_sel; + switch (ctx.channel_selection_algorithm){ + case 0: + hopping_csa1_set_hop_increment( &h, hop ); + break; + case 1: + hopping_csa2_set_access_address( &h, ctx.aa); + break; + default: + break; + } + + // connected -> notify controller + ll_state = LL_STATE_CONNECTED; + ctx.synced = false; + ctx.ll_send_connection_complete = true; + + // sleep until transmit window + hal_timer_set_callback(&ll_connected_timer_handler); + ctx.anchor_delta_ticks = US_TO_TICKS(ctx.transmit_window_offset_us + 1250); + ll_set_timer_ticks(US_TO_TICKS(ctx.transmit_window_offset_us + 1250 - SYNC_HOP_DELAY_US)); +} + +static void ll_connected_timer_handler(void){ + + // Check supervision timeout + if (ctx.synced){ + // check supervision timeout if connection was established + ctx.time_without_any_packets_us += ctx.conn_interval_us; + if (ctx.time_without_any_packets_us > ctx.supervision_timeout_us) { + printf("Supervision timeout (regular)\n\n"); + ll_connected_terminate(ERROR_CODE_CONNECTION_TIMEOUT); + return; + } + } else { + // give up on receiving first packet after 6 tries + if (ctx.connection_event > 6){ + printf("Supervision timeout(establishment)\n\n"); + ll_connected_terminate(ERROR_CODE_CONNECTION_FAILED_TO_BE_ESTABLISHED); + return; + } + } + + // update anchor using custom value when transmit windows was used + // connection event counter is only incremented for regular connection interval + if (ctx.anchor_delta_ticks == 0){ + ctx.anchor_ticks += ctx.conn_interval_ticks; + ctx.connection_event++; + } else { + ctx.anchor_ticks += ctx.anchor_delta_ticks; + ctx.anchor_delta_ticks = 0; + } + + if (ctx.channel_map_update_pending && (ctx.channel_map_update_instant == ctx.connection_event)) { + ctx.channel_map_update_pending = false; + + log_info("Chan map update now"); + + hopping_set_channel_map( &h, (const uint8_t *) &ctx.channel_map_update_map ); + } + + if (ctx.conn_param_update_pending && ((ctx.conn_param_update_instant) == ctx.connection_event) ) { + ctx.conn_param_update_pending = false; + + log_info("Conn param update now"); + + ll_connected_ctx_set_conn_interval(ctx.conn_param_update_interval_1250us); + ctx.conn_latency = ctx.conn_param_update_latency; + ctx.supervision_timeout_us = ctx.conn_param_update_timeout_us; + ctx.transmit_window_offset_us = ctx.conn_param_update_win_offset * 1250; + ctx.transmit_window_size_us = ctx.conn_param_update_win_size * 1250; + ctx.synced = false; + + // See Core V5.2, Vol 6B, 5.1.1, Figure 5.1 + // if transmit window == 0, continue. If not sleep again + if (ctx.conn_param_update_win_offset > 0){ + ctx.anchor_delta_ticks = US_TO_TICKS(ctx.transmit_window_offset_us); + ll_set_timer_ticks(US_TO_TICKS(ctx.transmit_window_offset_us - SYNC_HOP_DELAY_US)); + return; + } + } + + // prepare connection event + ctx.packet_nr_in_connection_event = 0; + + radio_hf_clock_enable(true); + + ll_connected_next_channel(); + + // set radio timer (should get updated by first packet) + ll_set_timer_ticks( ctx.conn_sync_hop_ticks); + + (void) ll_prepare_rx_buffer(); + if (ctx.rx_pdu == NULL) { + log_info("No RX PDU for first packet, skip connection event"); + } else { + if (ctx.synced){ + radio_receive(&lL_connected_rx_done, SYNC_HOP_DELAY_US + 100, &ctx.rx_pdu->header, 2 + LL_MAX_PAYLOAD, NULL); + } else { + radio_receive(&lL_connected_rx_done, SYNC_HOP_DELAY_US + ctx.transmit_window_size_us, &ctx.rx_pdu->header, 2 + LL_MAX_PAYLOAD, NULL); + } + } + + // printf("--SYNC-Ch %02u-Event %04u - t %08" PRIu32 "--\n", ctx.channel, ctx.connection_event, t0); +} + +static void ll_connected_handle_control(ll_pdu_t * rx_packet){ + ll_pdu_t * tx_packet = &ll_tx_packet; + uint8_t opcode = rx_packet->payload[0]; + switch (opcode){ + case PDU_DATA_LLCTRL_TYPE_VERSION_IND: + tx_packet->len = 6; + tx_packet->header = PDU_DATA_LLID_CTRL; + tx_packet->payload[0] = PDU_DATA_LLCTRL_TYPE_VERSION_IND; + tx_packet->payload[1] = 0x06; // VersNr = Bluetooth Core V4.0 + little_endian_store_16(tx_packet->payload, 2, BLUETOOTH_COMPANY_ID_BLUEKITCHEN_GMBH); + little_endian_store_16(tx_packet->payload, 4, 0); + btstack_linked_queue_enqueue(&ctx.tx_queue, (btstack_linked_item_t *) tx_packet); + printf("Queue Version Ind\n"); + break; + case PDU_DATA_LLCTRL_TYPE_FEATURE_REQ: + tx_packet->len = 9; + tx_packet->header = PDU_DATA_LLID_CTRL; + tx_packet->payload[0] = PDU_DATA_LLCTRL_TYPE_FEATURE_RSP; + // TODO: set features of our controller + memset(&tx_packet->payload[1], 0, 8); + btstack_linked_queue_enqueue(&ctx.tx_queue, (btstack_linked_item_t *) tx_packet); + printf("Queue Feature Rsp\n"); + break; + case PDU_DATA_LLCTRL_TYPE_CHAN_MAP_IND: + memcpy((uint8_t *) ctx.channel_map_update_map, &rx_packet->payload[1], 5); + ctx.channel_map_update_instant = little_endian_read_16(rx_packet->payload, 6); + ctx.channel_map_update_pending = true; + break; + case PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND: + ctx.conn_param_update_win_size = rx_packet->payload[1]; + ctx.conn_param_update_win_offset = little_endian_read_16(rx_packet->payload, 2); + ctx.conn_param_update_interval_1250us = little_endian_read_16(rx_packet->payload, 4); + ctx.conn_param_update_latency = little_endian_read_16(rx_packet->payload, 6); + ctx.conn_param_update_timeout_us = little_endian_read_16(rx_packet->payload, 8) * 10000; + ctx.conn_param_update_instant = little_endian_read_16(rx_packet->payload, 10); + ctx.conn_param_update_pending = true; + log_info("PDU_DATA_LLCTRL_TYPE_CONN_UPDATE_IND, conn interval %u 1250us at instant %u", + (unsigned int) ctx.conn_param_update_interval_1250us, ctx.conn_param_update_instant); + break; + default: + break; + } +} + +static void ll_connected_handle_data(ll_pdu_t * rx_packet){ + btstack_assert(rx_packet->len <= LL_MAX_PAYLOAD); + log_debug("CE: %u, nr %u, header 0x%02x, len %u", rx_packet->connection_event, rx_packet->packet_nr, rx_packet->header, rx_packet->len); + uint8_t acl_packet[4 + LL_MAX_PAYLOAD]; + // ACL Header + uint8_t ll_id = rx_packet->header & 3; + acl_packet[0] = 0x01; + acl_packet[1] = ll_id << 4; + little_endian_store_16(acl_packet, 2, rx_packet->len); + memcpy(&acl_packet[4], rx_packet->payload, rx_packet->len); + (*controller_packet_handler)(HCI_ACL_DATA_PACKET, acl_packet, rx_packet->len + 4); +} + +static void ll_handle_adv(ll_pdu_t * rx_packet) { + // Map PDU_ADV_TYPE to HCI Event_Type + uint8_t event_type = 0; + switch (rx_packet->header & 0x0f){ + case PDU_ADV_TYPE_ADV_IND: + event_type = 0; + break; + case PDU_ADV_TYPE_DIRECT_IND: + event_type = 1; + break; + case PDU_ADV_TYPE_NONCONN_IND: + event_type = 3; + break; + case PDU_ADV_TYPE_SCAN_RSP: + event_type = 3; + break; + default: + return; + } + uint8_t advertiser_addr_type = ((rx_packet->header & 0x40) != 0) ? 1 : 0; + uint8_t adv_data_len = rx_packet->len - 6; + + uint16_t pos = 0; + ll_outgoing_hci_event[pos++] = HCI_EVENT_LE_META; + pos++; + ll_outgoing_hci_event[pos++] = HCI_SUBEVENT_LE_ADVERTISING_REPORT; + ll_outgoing_hci_event[pos++] = 1; + ll_outgoing_hci_event[pos++] = event_type; + ll_outgoing_hci_event[pos++] = advertiser_addr_type; + memcpy(&ll_outgoing_hci_event[pos], &rx_packet->payload[0], 6); + pos += 6; + ll_outgoing_hci_event[pos++] = adv_data_len; + memcpy(&ll_outgoing_hci_event[pos], &rx_packet->payload[6], adv_data_len); + pos += adv_data_len; + ll_outgoing_hci_event[pos++] = (uint8_t) rx_packet->rssi; + ll_outgoing_hci_event[1] = pos - 2; + (*controller_packet_handler)(HCI_EVENT_PACKET, ll_outgoing_hci_event, pos); +} + +// public API + +void ll_init(void){ + // setup memory pools + btstack_memory_pool_create(&ll_pdu_pool, ll_pdu_pool_storage, MAX_NUM_LL_PDUS, sizeof(ll_pdu_t)); + + // set test bd addr 33:33:33:33:33:33 + memset(ctx.bd_addr_le, 0x33, 6); + + // default channels, advertising interval + ctx.adv_map = 0x7; + ctx.adv_interval_us = 1280000; + + // init radio + radio_init(); +} + +void ll_radio_on(void){ + ll_state = LL_STATE_STANDBY; +} + +void ll_set_scan_parameters(uint8_t le_scan_type, uint16_t le_scan_interval, uint16_t le_scan_window, uint8_t own_address_type, uint8_t scanning_filter_policy){ + // TODO .. store other params + ll_scan_interval_us = ((uint32_t) le_scan_interval) * 625; + ll_scan_window_us = ((uint32_t) le_scan_window) * 625; + log_info("LE Scan Params: window %lu, interval %lu ms", ll_scan_interval_us, ll_scan_window_us); +} + +uint8_t ll_set_scan_enable(uint8_t le_scan_enable, uint8_t filter_duplicates){ + if (le_scan_enable){ + return ll_scanning_start(filter_duplicates); + } else { + return ll_scanning_stop(); + } +} + +uint8_t ll_set_advertise_enable(uint8_t le_adv_enable){ + if (le_adv_enable){ + return ll_advertising_start(); + } else { + return ll_advertising_stop(); + } +} + +uint8_t ll_set_advertising_parameters(uint16_t advertising_interval_min, uint16_t advertising_interval_max, + uint8_t advertising_type, uint8_t own_address_type, uint8_t peer_address_types, uint8_t * peer_address, + uint8_t advertising_channel_map, uint8_t advertising_filter_policy){ + + // validate channel map + if (advertising_channel_map == 0) return ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS; + if ((advertising_channel_map & 0xf8) != 0) return ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS; + + // validate advertising interval + if (advertising_interval_min < 0x20) return ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS; + if (advertising_interval_min > 0x4000) return ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS; + if (advertising_interval_max < 0x20) return ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS; + if (advertising_interval_max > 0x4000) return ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS; + if (advertising_interval_min > advertising_interval_max) return ERROR_CODE_INVALID_HCI_COMMAND_PARAMETERS; + + ctx.adv_map = advertising_channel_map; + ctx.adv_interval_us = advertising_interval_max * 625; + ctx.adv_type= advertising_type; + + // TODO: validate other params + // TODO: process other params + + return ERROR_CODE_SUCCESS; +} + +uint8_t ll_set_advertising_data(uint8_t adv_len, const uint8_t * adv_data){ + // COMMAND DISALLOWED if wrong state. + if (ll_state == LL_STATE_ADVERTISING) return ERROR_CODE_COMMAND_DISALLOWED; + if (adv_len > 31) return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; + ctx.adv_len = adv_len; + memcpy(ctx.adv_data, adv_data, adv_len); + + return ERROR_CODE_SUCCESS; +} + +uint8_t ll_set_scan_response_data(uint8_t adv_len, const uint8_t * adv_data){ + // COMMAND DISALLOWED if wrong state. + if (ll_state == LL_STATE_ADVERTISING) return ERROR_CODE_COMMAND_DISALLOWED; + if (adv_len > 31) return ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; + ctx.scan_resp_len = adv_len; + memcpy(ctx.scan_resp_data, adv_data, adv_len); + + return ERROR_CODE_SUCCESS; +} + +void ll_execute_once(void){ + // process received packets + while (1){ + ll_pdu_t * rx_packet; + /** critical section start */ + hal_cpu_disable_irqs(); + rx_packet = (ll_pdu_t *) btstack_linked_queue_dequeue(&ctx.rx_queue); + hal_cpu_enable_irqs(); + /** critical section end */ + if (rx_packet == NULL) break; + uint8_t ll_id; + if (rx_packet->len > 0){ + switch (ll_state){ + case LL_STATE_ADVERTISING: + if ((rx_packet->flags & LL_PDU_FLAG_DATA_PDU) != 0){ + break; + } + if ((rx_packet->header & 0x0f) != PDU_ADV_TYPE_CONNECT_IND) { + break; + } + ll_connected_handle_conn_ind(rx_packet); + break; + case LL_STATE_SCANNING: + if ((rx_packet->flags & LL_PDU_FLAG_DATA_PDU) != 0){ + break; + } + ll_handle_adv(rx_packet); + break; + case LL_STATE_CONNECTED: + // DATA PDU + if ((rx_packet->flags & LL_PDU_FLAG_DATA_PDU) == 0){ + break; + } + ll_id = rx_packet->header & 3; + if (ll_id == PDU_DATA_LLID_CTRL) { + ll_connected_handle_control(rx_packet); + } else { + ll_connected_handle_data(rx_packet); + } + break; + default: + break; + } + } + // free packet + /** critical section start */ + hal_cpu_disable_irqs(); + btstack_memory_ll_pdu_free(rx_packet); + hal_cpu_enable_irqs(); + /** critical section end */ + } + + // generate HCI events + + // report num complete packets + /** critical section start */ + hal_cpu_disable_irqs(); + uint8_t num_completed = ctx.num_completed; + ctx.num_completed = 0; + hal_cpu_enable_irqs(); + /** critical section end */ + if (num_completed > 0){ + ll_emit_hci_event(&hci_event_number_of_completed_packets_1, 1, HCI_CON_HANDLE, num_completed); + } + + // report connection event + if (ctx.ll_send_connection_complete){ + ctx.ll_send_connection_complete = false; + ll_emit_hci_event(&hci_subevent_le_connection_complete, + ERROR_CODE_SUCCESS, HCI_CON_HANDLE, 0x01 /* slave */, ctx.peer_addr_type, ctx.peer_addr, + ctx.conn_interval_1250us, ctx.conn_latency, ctx.supervision_timeout_10ms, 0 /* master clock accuracy */); + } + + // report disconnection event + if (ctx.ll_send_disconnected){ + ctx.ll_send_disconnected = false; + uint8_t error_code = ctx.error_code; + ctx.error_code = ERROR_CODE_SUCCESS; + ll_emit_hci_event(&hci_event_disconnection_complete, ERROR_CODE_SUCCESS, HCI_CON_HANDLE, error_code); + } +} + +bool ll_reserve_acl_packet(void){ + if (ll_reserved_acl_buffer == NULL){ + + /** critical section start */ + hal_cpu_disable_irqs(); + ll_reserved_acl_buffer = btstack_memory_ll_pdu_get(); + hal_cpu_enable_irqs(); + /** critical section end */ + + } + return ll_reserved_acl_buffer != NULL; +} + +void ll_queue_acl_packet(const uint8_t * packet, uint16_t size){ + btstack_assert(ll_reserved_acl_buffer != NULL); + + ll_pdu_t * tx_packet = ll_reserved_acl_buffer; + ll_reserved_acl_buffer = NULL; + + switch ((packet[1] >> 4) & 0x03){ + case 0: + case 2: + tx_packet->header = PDU_DATA_LLID_DATA_START; + break; + case 1: + tx_packet->header = PDU_DATA_LLID_DATA_CONTINUE; + break; + case 3: + while(1); + break; + default: + break; + } + tx_packet->len = size - 4; + memcpy(tx_packet->payload, &packet[4], size - 4); + + /** critical section start */ + hal_cpu_disable_irqs(); + btstack_linked_queue_enqueue(&ctx.tx_queue, (btstack_linked_item_t *) tx_packet); + hal_cpu_enable_irqs(); + /** critical section end */ +} + +void ll_register_packet_handler(void (*packet_handler)(uint8_t packet_type, uint8_t * packet, uint16_t size)){ + controller_packet_handler = packet_handler; +} diff --git a/port/nrf5-cinnamon/port/radio.h b/port/nrf5-cinnamon/port/radio.h new file mode 100644 index 000000000..ffcd9a400 --- /dev/null +++ b/port/nrf5-cinnamon/port/radio.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2020 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +/* + * radio.h + */ + +#ifndef RADIO_H +#define RADIO_H + +#include "btstack_bool.h" +#include + +#if defined __cplusplus +extern "C" { +#endif + +/* API_START */ + +typedef struct { + void (*tx_done)(void); + void (*rx_done)(void); +} radio_callbacks_t; + +typedef enum { + RADIO_TRANSITION_TX_ONLY, + RADIO_TRANSITION_TX_TO_RX, +} radio_transition_t; + +typedef enum { + RADIO_RESULT_OK, + RADIO_RESULT_CRC_ERROR, + RADIO_RESULT_TIMEOUT, +} radio_result_t; + +typedef void (*radio_callback_t)(radio_result_t result); + +/** + * Init radio + */ +void radio_init(void); + +/** + * Set Access Address + * @param access_address + */ +void radio_set_access_address(uint32_t access_address); + +/** + * Enable RF CLock + * @param wait_until_ready if true, waits until HF clock is ready + */ +void radio_hf_clock_enable(bool wait_until_ready); + +/** + * Disable RF CLock + */ +void radio_hf_clock_disable(void); + +/** + * Set CRC Init value + * @param crc 24-bit init value + */ +void radio_set_crc_init(uint32_t crc); + +/** + * Set Channel: frequency and whitening + * @param channel 0..39 + */ +void radio_set_channel(uint8_t channel); + +/** + * Transmit packet. + * @param callback + * @param transition - on RADIO_TRANSITION_TX_TO_RX, radio transitions to RX + * @param packet + * @param len + */ +void radio_transmit(radio_callback_t callback, radio_transition_t transition, const uint8_t * packet, uint16_t len); + +/** + * Receive packet + * @note automatic transition to TX + * @param callback + * @param timeout_us if radio was disabled before (i.e. not in tx -> rx transition) + * @param buffer + * @param len + * @param rssi (out) + */ +void radio_receive(radio_callback_t callback, uint32_t timeout_us, uint8_t * buffer, uint16_t len, int8_t * rssi); + +/** + * Stop active transmission, e.g. tx after rx + * @param callback + */ +void radio_stop(radio_callback_t callback); + +/* API_END */ + +#if defined __cplusplus +} +#endif + +#endif // LL_H diff --git a/port/nrf5-cinnamon/port/radio_nrf5.c b/port/nrf5-cinnamon/port/radio_nrf5.c new file mode 100644 index 000000000..4a2877e51 --- /dev/null +++ b/port/nrf5-cinnamon/port/radio_nrf5.c @@ -0,0 +1,546 @@ +/* + * Copyright (C) 2021 BlueKitchen GmbH + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holders nor the names of + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * 4. Any redistribution, use, or modification is done solely for + * personal benefit and not for any commercial purpose or for + * monetary gain. + * + * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS + * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Please inquire about commercial licensing options at + * contact@bluekitchen-gmbh.com + * + */ + +#define BTSTACK_FILE__ "radio_nrf5.c" + +#include "radio.h" +#include "btstack_debug.h" +#include +#include "nrf.h" +#include "nrf52.h" +#include "nrf_gpio.h" +#include "nrf_gpiote.h" + +#define MAXLEN 37 + +static enum { + RADIO_OFF, + RADIO_DISABLED, + RADIO_W2_TX, + RADIO_W4_TX_DONE, + RADIO_W4_TX_TO_RX, + RADIO_W2_RX, + RADIO_W4_RX_DONE, + RADIO_W4_RX_TIMEOUT, + RADIO_W4_DISABLED, +} volatile radio_state; + +static radio_callback_t radio_callback; +static int8_t * rssi_buffer; + +// channel table: freq in hertz and whitening seed +static const struct { + uint8_t freq_index; + uint8_t whitening; +} channel_table[] = { + { 4, 0x01 /* 00000001 */ }, + { 6, 0x41 /* 01000001 */ }, + { 8, 0x21 /* 00100001 */ }, + { 10, 0x61 /* 01100001 */ }, + { 12, 0x11 /* 00010001 */ }, + { 14, 0x51 /* 01010001 */ }, + { 16, 0x31 /* 00110001 */ }, + { 18, 0x71 /* 01110001 */ }, + { 20, 0x09 /* 00001001 */ }, + { 22, 0x49 /* 01001001 */ }, + { 24, 0x29 /* 00101001 */ }, + { 28, 0x69 /* 01101001 */ }, + { 30, 0x19 /* 00011001 */ }, + { 32, 0x59 /* 01011001 */ }, + { 34, 0x39 /* 00111001 */ }, + { 36, 0x79 /* 01111001 */ }, + { 38, 0x05 /* 00000101 */ }, + { 40, 0x45 /* 01000101 */ }, + { 42, 0x25 /* 00100101 */ }, + { 44, 0x65 /* 01100101 */ }, + { 46, 0x15 /* 00010101 */ }, + { 48, 0x55 /* 01010101 */ }, + { 50, 0x35 /* 00110101 */ }, + { 52, 0x75 /* 01110101 */ }, + { 54, 0x0d /* 00001101 */ }, + { 56, 0x4d /* 01001101 */ }, + { 58, 0x2d /* 00101101 */ }, + { 60, 0x6d /* 01101101 */ }, + { 62, 0x1d /* 00011101 */ }, + { 64, 0x5d /* 01011101 */ }, + { 66, 0x3d /* 00111101 */ }, + { 68, 0x7d /* 01111101 */ }, + { 70, 0x03 /* 00000011 */ }, + { 72, 0x43 /* 01000011 */ }, + { 74, 0x23 /* 00100011 */ }, + { 76, 0x63 /* 01100011 */ }, + { 78, 0x13 /* 00010011 */ }, + { 2, 0x53 /* 01010011 */ }, + { 26, 0x33 /* 00110011 */ }, + { 80, 0x73 /* 01110011 */ }, +}; + +void radio_init(void){ + + radio_state = RADIO_OFF; + + /* TIMER0 setup */ + NRF_TIMER0->TASKS_STOP = 1; + NRF_TIMER0->TASKS_SHUTDOWN = 1; + NRF_TIMER0->BITMODE = 3; /* 32-bit timer */ + NRF_TIMER0->MODE = 0; /* Timer mode */ + NRF_TIMER0->PRESCALER = 4; /* gives us 1 MHz */ + + // PPI setup + // Channel 0: RADIO END -> TIMER0 Start + NRF_PPI->CH[0].EEP = (uint32_t)&(NRF_RADIO->EVENTS_END); + NRF_PPI->CH[0].TEP = (uint32_t)&(NRF_TIMER0->TASKS_START); + // Channel 1: RADIO ADDRESS -> TIMER0 Stop + NRF_PPI->CH[1].EEP = (uint32_t)&(NRF_RADIO->EVENTS_ADDRESS); + NRF_PPI->CH[1].TEP = (uint32_t)&(NRF_TIMER0->TASKS_STOP); + +#ifdef NRF51 + // Handle BLE Radio tuning parameters from production if required. + // Does not exist on NRF52 + // See PCN-083. + if (NRF_FICR->OVERRIDEEN & FICR_OVERRIDEEN_BLE_1MBIT_Msk){ + NRF_RADIO->OVERRIDE0 = NRF_FICR->BLE_1MBIT[0]; + NRF_RADIO->OVERRIDE1 = NRF_FICR->BLE_1MBIT[1]; + NRF_RADIO->OVERRIDE2 = NRF_FICR->BLE_1MBIT[2]; + NRF_RADIO->OVERRIDE3 = NRF_FICR->BLE_1MBIT[3]; + NRF_RADIO->OVERRIDE4 = NRF_FICR->BLE_1MBIT[4] | 0x80000000; + } +#endif // NRF51 + + // Mode: BLE 1 Mbps + NRF_RADIO->MODE = RADIO_MODE_MODE_Ble_1Mbit << RADIO_MODE_MODE_Pos; + + // PacketConfig 0: + // --- + // LENGTH field in bits = 8 + // S0 field in bytes = 1 + // S1 field not used + // 8 bit preamble + NRF_RADIO->PCNF0 = + ( 8 << RADIO_PCNF0_LFLEN_Pos ) | + ( 1 << RADIO_PCNF0_S0LEN_Pos ) | + ( 0 << RADIO_PCNF0_S1LEN_Pos ); + + // PacketConfig 1: + // --- + // Payload MAXLEN = MAXLEN + // No additional bytes + // 4 address bytes (1 + 3) + // S0, LENGTH, S1, PAYLOAD in little endian + // Packet whitening enabled + NRF_RADIO->PCNF1 = + ( MAXLEN << RADIO_PCNF1_MAXLEN_Pos) | + ( 0 << RADIO_PCNF1_STATLEN_Pos ) | + ( 3 << RADIO_PCNF1_BALEN_Pos ) | + ( RADIO_PCNF1_ENDIAN_Little << RADIO_PCNF1_ENDIAN_Pos ) | + ( RADIO_PCNF1_WHITEEN_Enabled << RADIO_PCNF1_WHITEEN_Pos ); + + // Use logical address 0 for sending and receiving + NRF_RADIO->TXADDRESS = 0; + NRF_RADIO->RXADDRESSES = 1 << 0; + + // 24 bit CRC, skip address field + NRF_RADIO->CRCCNF = + ( RADIO_CRCCNF_SKIPADDR_Skip << RADIO_CRCCNF_SKIPADDR_Pos ) | + ( RADIO_CRCCNF_LEN_Three << RADIO_CRCCNF_LEN_Pos ); + + // The polynomial has the form of x^24 +x^10 +x^9 +x^6 +x^4 +x^3 +x+1 + NRF_RADIO->CRCPOLY = 0x100065B; + + // Inter frame spacing 150 us + NRF_RADIO->TIFS = 150; + + // Transmit with max power + NRF_RADIO->TXPOWER = (RADIO_TXPOWER_TXPOWER_Pos4dBm << RADIO_TXPOWER_TXPOWER_Pos); + + // Disable all interrupts + NRF_RADIO->INTENCLR = 0xffffffff; + + // enable Radio IRQs + NVIC_SetPriority( RADIO_IRQn, 0 ); + NVIC_ClearPendingIRQ( RADIO_IRQn ); + NVIC_EnableIRQ( RADIO_IRQn ); + +#ifdef DEBUG_PIN_HF_CLOCK + // debug pins + nrf_gpio_cfg_output(DEBUG_PIN_HF_CLOCK); + nrf_gpio_cfg_output(DEBUG_PIN_ADDRESS); + nrf_gpio_cfg_output(DEBUG_PIN_RX); + nrf_gpio_cfg_output(DEBUG_PIN_TX); + nrf_gpio_cfg_output(DEBUG_PIN_RADIO_IRQ); + // toggle DEBUG_PIN_ADDRESS on RADIO ADDRESS event. Use PPI Channel 19 and GPIOT[0] + // NOTE: unclear how pin could be cleared after set on address. + nrf_gpiote_task_configure(0, DEBUG_PIN_ADDRESS, GPIOTE_CONFIG_POLARITY_Toggle, NRF_GPIOTE_INITIAL_VALUE_LOW); + nrf_gpiote_task_enable(0); + NRF_PPI->CH[19].EEP = (uint32_t)&(NRF_RADIO->EVENTS_ADDRESS); + NRF_PPI->CH[19].TEP = nrf_gpiote_task_addr_get(0); + NRF_PPI->CHENSET = PPI_CHEN_CH19_Msk; +#endif +} + +// Enable the High Frequency clock on the processor. +static void radio_hf_clock_enable_reset(radio_result_t result){ + UNUSED(result); +} +void radio_hf_clock_enable(bool wait_until_ready){ + + // Work around for incomplete RX + if (radio_state == RADIO_W4_RX_DONE){ +#ifdef DEBUG_PIN_HF_CLOCK + nrf_gpio_pin_clear(DEBUG_PIN_HF_CLOCK); + nrf_gpio_pin_set(DEBUG_PIN_HF_CLOCK); +#endif +#if 0 + // state = RX, PAYLOAD = 1, END = 0, DISABLED = 0 + printf("Enable: STATE %u\n", (int) NRF_RADIO->STATE); + printf("Enable: PAYLOAD %u\n", (int) NRF_RADIO->EVENTS_PAYLOAD); + printf("Enable: END %u\n", (int) NRF_RADIO->EVENTS_END); + printf("Enable: DISABLED %u\n", (int) NRF_RADIO->EVENTS_DISABLED); + btstack_assert(false); +#else + printf("\n\nRADIO_W4_RX_DONE hang\n\n\n"); + radio_stop(&radio_hf_clock_enable_reset); + radio_state = RADIO_DISABLED; + return; +#endif + } + +#ifdef DEBUG_PIN_HF_CLOCK + nrf_gpio_pin_set(DEBUG_PIN_HF_CLOCK); +#endif + + + // the RADIO module. Without this clock, no communication is possible. + NRF_CLOCK->EVENTS_HFCLKSTARTED = 0; + NRF_CLOCK->TASKS_HFCLKSTART = 1; + if (wait_until_ready){ + while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0); + } + + radio_state = RADIO_DISABLED; +} + +void radio_hf_clock_disable(void) { +#ifdef DEBUG_PIN_HF_CLOCK + nrf_gpio_pin_clear(DEBUG_PIN_HF_CLOCK); +#endif + + NRF_CLOCK->TASKS_HFCLKSTOP = 1; + radio_state = RADIO_OFF; +} + +void radio_set_access_address(uint32_t access_address) { + NRF_RADIO->BASE0 = ( access_address << 8 ) & 0xFFFFFF00; + NRF_RADIO->PREFIX0 = ( access_address >> 24 ) & RADIO_PREFIX0_AP0_Msk; +} + +void radio_set_crc_init(uint32_t crc_init){ + NRF_RADIO->CRCINIT = crc_init; +} + +void radio_set_channel(uint8_t channel){ + // set frequency based on channel + NRF_RADIO->FREQUENCY = channel_table[channel].freq_index; + + // initializes data whitening with channel index + NRF_RADIO->DATAWHITEIV = channel & 0x3F; +} + +void radio_transmit(radio_callback_t callback, radio_transition_t transition, const uint8_t * packet, uint16_t len){ + +#ifdef DEBUG_PIN_TX + nrf_gpio_pin_set(DEBUG_PIN_TX); +#endif + + uint16_t state = (uint16_t) NRF_RADIO->STATE; + + switch (radio_state){ + case RADIO_W2_TX: + // already in transition to tx + if (state != RADIO_STATE_STATE_TxRu){ + log_info("TX Start after RX, transition %u, state 0x%04x", (int) transition, state); + btstack_assert(false); + } + break; + case RADIO_DISABLED: + if (state != RADIO_STATE_STATE_Disabled){ + log_info("TX Start after Disabled, transition %u, state 0x%04x", (int) transition, state); + btstack_assert(false); + } + // start tx + NRF_RADIO->TASKS_TXEN = 1; + break; + default: + log_info("TX Start unexpected state: our state %u, transition %u, state 0x%04x", radio_state, (int) transition, state); + btstack_assert(false); + break; + } + + radio_callback = callback; + + // set data to send (assume it's valid until tx done) + NRF_RADIO->PACKETPTR = (uint32_t) packet; + + switch (transition){ + case RADIO_TRANSITION_TX_ONLY: + radio_state = RADIO_W4_TX_DONE; + NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk; + break; + case RADIO_TRANSITION_TX_TO_RX: + radio_state = RADIO_W4_TX_TO_RX; + NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_END_DISABLE_Msk | RADIO_SHORTS_DISABLED_RXEN_Msk; + // - Clear Timer0 + NRF_TIMER0->TASKS_CLEAR = 1; + // - Set CC for receive (ca. 300 us) + NRF_TIMER0->CC[1] = 300; // 300 us + NRF_TIMER0->EVENTS_COMPARE[1] = 0; + // - END -> Start Timer0 + NRF_PPI->CHENSET = PPI_CHEN_CH0_Msk; + // - Timer0 CC[1] -> Radio END + NRF_PPI->CHENSET = PPI_CHEN_CH22_Msk; + // - Disable address->stop + NRF_PPI->CHENCLR = PPI_CHEN_CH1_Msk; + break; + default: + btstack_assert(false); + break; + } + + NRF_RADIO->INTENCLR = 0xffffffff; + NRF_RADIO->EVENTS_END = 0; + NRF_RADIO->EVENTS_DISABLED = 0; + + NVIC_ClearPendingIRQ(RADIO_IRQn); + NVIC_EnableIRQ(RADIO_IRQn); + + // Interrupt on DISABLED + NRF_RADIO->INTENSET = 0x00000010; +} + +static void radio_setup_rx(void){ + NRF_RADIO->EVENTS_ADDRESS = 0; + NRF_RADIO->EVENTS_END = 0; + NRF_RADIO->EVENTS_DISABLED = 0; + // PPI0: END -> Start Timer0 + NRF_PPI->CHENCLR = PPI_CHEN_CH0_Msk; + // PPI1: Radio Address -> Stop Timer + NRF_PPI->CHENSET = PPI_CHEN_CH1_Msk; + // Update Shortcuts + NRF_RADIO->SHORTS = RADIO_SHORTS_READY_START_Msk | RADIO_SHORTS_ADDRESS_RSSISTART_Msk | RADIO_SHORTS_END_DISABLE_Msk | RADIO_SHORTS_DISABLED_TXEN_Msk; +} + +void radio_receive(radio_callback_t callback, uint32_t timeout_us, uint8_t * buffer, uint16_t len, int8_t * rssi){ + +#ifdef DEBUG_PIN_RX + nrf_gpio_pin_set(DEBUG_PIN_RX); +#endif + + uint16_t state = (uint16_t) NRF_RADIO->STATE; + + // log_info("RX Start: our state = 0x%0x, radio_state 0x%04x", radio_state, state); + + radio_callback = callback; + rssi_buffer = rssi; + + NRF_RADIO->PACKETPTR = (uint32_t) buffer; + buffer[0] = 0; + buffer[1] = 0; + + switch (radio_state){ + case RADIO_W2_RX: + // radio setup as part of TX->RX transition + switch (state){ + case RADIO_STATE_STATE_RxRu: + case RADIO_STATE_STATE_RxIdle: + case RADIO_STATE_STATE_Rx: + break; + default: + btstack_assert(false); + break; + } + break; + case RADIO_DISABLED: + btstack_assert(state == RADIO_STATE_STATE_Disabled); + // - Stop Timer0 + NRF_TIMER0->TASKS_STOP = 1; + // - Clear Timer0 + NRF_TIMER0->TASKS_CLEAR = 1; + // - Set CC for receive + NRF_TIMER0->CC[1] = timeout_us; + NRF_TIMER0->EVENTS_COMPARE[1] = 0; + // - Timer0 CC[1] -> Radio Disable + NRF_PPI->CHENSET = PPI_CHEN_CH22_Msk; + // - Start Timer0 + NRF_TIMER0->TASKS_START = 1; + // Start Receive + radio_setup_rx(); + NRF_RADIO->TASKS_RXEN = 1; + break; + default: + log_info("RX unexpected radio_state: state 0x%04x / phy state state 0x%04x", radio_state, state); + log_info("cc[1] %" PRIu32 "events_compare[1] %u", NRF_TIMER0->CC[1], (int) NRF_TIMER0->EVENTS_COMPARE[1]); + btstack_assert(false); + break; + } + + // Disable all interrupts + NRF_RADIO->INTENCLR = 0xffffffff; + + NVIC_ClearPendingIRQ(RADIO_IRQn); + NVIC_EnableIRQ(RADIO_IRQn); + + // Interrupt on DISABLED + NRF_RADIO->INTENSET = 0x00000010; + + radio_state = RADIO_W4_RX_DONE; +} + +void radio_stop(radio_callback_t callback){ + + // log_info("Disable, state 0x%04x", (uint16_t) NRF_RADIO->STATE); + + radio_callback = callback; + + NRF_RADIO->SHORTS = 0; + + uint16_t state = (uint16_t) NRF_RADIO->STATE; + switch (state){ + case RADIO_STATE_STATE_Disabled: + (*callback)(RADIO_RESULT_OK); + break; + default: + radio_state = RADIO_W4_DISABLED; + NRF_RADIO->TASKS_DISABLE = 1; + break; + } +} + +void RADIO_IRQHandler(void){ + uint16_t state = (uint16_t) NRF_RADIO->STATE; + +#ifdef DEBUG_PIN_RADIO_IRQ + nrf_gpio_pin_toggle(DEBUG_PIN_RADIO_IRQ); +#endif +#ifdef DEBUG_PIN_RX + nrf_gpio_pin_clear(DEBUG_PIN_RX); +#endif +#ifdef DEBUG_PIN_TX + nrf_gpio_pin_clear(DEBUG_PIN_TX); +#endif + + switch (radio_state){ + case RADIO_W4_TX_DONE: + // TX Done, no transition to rx requested + btstack_assert(state == RADIO_STATE_STATE_Disabled); + NRF_RADIO->EVENTS_DISABLED = 0; + radio_state = RADIO_DISABLED; + (*radio_callback)(RADIO_RESULT_OK); + break; + case RADIO_W4_TX_TO_RX: + // TX Done, transition to rx + btstack_assert(state == RADIO_STATE_STATE_RxRu); + NRF_RADIO->EVENTS_DISABLED = 0; + radio_state = RADIO_W2_RX; + radio_setup_rx(); + (*radio_callback)(RADIO_RESULT_OK); + break; + case RADIO_W4_RX_DONE: + // RX Done + btstack_assert(state == RADIO_STATE_STATE_TxRu); + NRF_RADIO->EVENTS_DISABLED = 0; + NRF_TIMER0->TASKS_STOP = 1; + // check EVENTS_COMPARE[1] + if (NRF_TIMER0->EVENTS_COMPARE[1]){ + // compare event -> timeout + radio_state = RADIO_W4_RX_TIMEOUT; + NRF_RADIO->SHORTS = 0; + NRF_RADIO->TASKS_DISABLE = 1; +#ifdef DEBUG_PIN_RX + // toggle twice for timeout + nrf_gpio_pin_toggle(DEBUG_PIN_RX); + nrf_gpio_pin_toggle(DEBUG_PIN_RX); + nrf_gpio_pin_toggle(DEBUG_PIN_RX); + nrf_gpio_pin_toggle(DEBUG_PIN_RX); +#endif + } else { + // no compare event -> packet with address received + radio_state = RADIO_W2_TX; + // RSSI is stored without sign but is negative (range: 0..127) + if (rssi_buffer != NULL){ + uint32_t rssi_sample = NRF_RADIO->RSSISAMPLE; + int8_t rssi; + if (rssi_sample < 128){ + rssi = -rssi_sample; + } else { + rssi = -128; + } + *rssi_buffer = rssi; + } + // check CRC + radio_result_t result = ((NRF_RADIO->CRCSTATUS & RADIO_CRCSTATUS_CRCSTATUS_Msk) != 0) ? RADIO_RESULT_OK : RADIO_RESULT_CRC_ERROR; +#ifdef DEBUG_PIN_RX + // toggle once for crc error + if (result == RADIO_RESULT_CRC_ERROR){ + nrf_gpio_pin_toggle(DEBUG_PIN_RX); + nrf_gpio_pin_toggle(DEBUG_PIN_RX); + } +#endif + (*radio_callback)(result); + } + break; + case RADIO_W4_RX_TIMEOUT: + // after RX Timeout, RX was started and stopped again + btstack_assert(state == RADIO_STATE_STATE_Disabled); + NRF_RADIO->EVENTS_DISABLED = 0; + radio_state = RADIO_DISABLED; + (*radio_callback)(RADIO_RESULT_TIMEOUT); + break; + case RADIO_W4_DISABLED: + NRF_RADIO->EVENTS_DISABLED = 0; + NRF_RADIO->INTENCLR = 0xffffffff; + radio_state = RADIO_DISABLED; + (*radio_callback)(RADIO_RESULT_OK); + break; + default: + log_info("IRQ: our state = 0x%0x, radio_state 0x%04x", radio_state, state); + btstack_assert(false); + break; + } +#ifdef DEBUG_PIN_RADIO_IRQ + nrf_gpio_pin_toggle(DEBUG_PIN_RADIO_IRQ); +#endif +}