diff options
Diffstat (limited to 'src/libs/mynewt-nimble/porting')
102 files changed, 18627 insertions, 0 deletions
diff --git a/src/libs/mynewt-nimble/porting/examples/dummy/Makefile b/src/libs/mynewt-nimble/porting/examples/dummy/Makefile new file mode 100644 index 00000000..0cf47672 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/dummy/Makefile @@ -0,0 +1,79 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Toolchain commands +CROSS_COMPILE ?= +CC := ccache $(CROSS_COMPLIE)gcc +CXX := ccache $(CROSS_COMPILE)g++ +LD := $(CROSS_COMPILE)gcc +AR := $(CROSS_COMPILE)ar +AS := $(CROSS_COMPILE)as +NM := $(CROSS_COMPILE)nm +OBJDUMP := $(CROSS_COMPILE)objdump +OBJCOPY := $(CROSS_COMPILE)objcopy +SIZE := $(CROSS_COMPILE)size + +# Configure NimBLE variables +NIMBLE_ROOT := ../../.. +NIMBLE_CFG_TINYCRYPT := 1 + +# Skip files that don't build for this port +NIMBLE_IGNORE := $(NIMBLE_ROOT)/nimble/host/src/ble_gatts_lcl.c \ + $(NIMBLE_ROOT)/porting/nimble/src/hal_timer.c \ + $(NIMBLE_ROOT)/porting/nimble/src/os_cputime.c \ + $(NIMBLE_ROOT)/porting/nimble/src/os_cputime_pwr2.c \ + $(NULL) + +include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs + +# Add dummy NPL, dummy HCI transport and all NimBLE sources to build +SRC = \ + $(wildcard $(NIMBLE_ROOT)/porting/npl/dummy/src/*.c) \ + $(NIMBLE_SRC) \ + $(TINYCRYPT_SRC) \ + main.c \ + +# Add dummy NPL and all NimBLE directories to include paths +INC = \ + $(NIMBLE_ROOT)/porting/npl/dummy/include \ + $(NIMBLE_INCLUDE) \ + $(TINYCRYPT_INCLUDE) \ + $(INCLUDE) \ + +OBJ := $(SRC:.c=.o) +TINYCRYPT_OBJ := $(TINYCRYPT_SRC:.c=.o) + +CFLAGS := $(NIMBLE_CFLAGS) + +.PHONY: all clean +.DEFAULT: all + +all: dummy + +clean: + rm $(OBJ) -f + rm dummy -f + +$(TINYCRYPT_OBJ): CFLAGS+=$(TINYCRYPT_CFLAGS) + +%.o: %.c + $(CC) -c $(addprefix -I, $(INC)) $(CFLAGS) -o $@ $< + +dummy: $(OBJ) $(TINYCRYPT_OBJ) + $(CC) -o $@ $^ diff --git a/src/libs/mynewt-nimble/porting/examples/dummy/main.c b/src/libs/mynewt-nimble/porting/examples/dummy/main.c new file mode 100644 index 00000000..4c17d950 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/dummy/main.c @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "nimble/nimble_port.h" + +int main(int argc, char **argv) +{ + nimble_port_init(); + + return 0; +} diff --git a/src/libs/mynewt-nimble/porting/examples/linux/Makefile b/src/libs/mynewt-nimble/porting/examples/linux/Makefile new file mode 100644 index 00000000..4217ea3a --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux/Makefile @@ -0,0 +1,105 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Toolchain commands +CROSS_COMPILE ?= +CC := ccache $(CROSS_COMPLIE)gcc +CXX := ccache $(CROSS_COMPILE)g++ +LD := $(CROSS_COMPILE)gcc +AR := $(CROSS_COMPILE)ar +AS := $(CROSS_COMPILE)as +NM := $(CROSS_COMPILE)nm +OBJDUMP := $(CROSS_COMPILE)objdump +OBJCOPY := $(CROSS_COMPILE)objcopy +SIZE := $(CROSS_COMPILE)size + +# Configure NimBLE variables +NIMBLE_ROOT := ../../.. +NIMBLE_CFG_TINYCRYPT := 1 + +# Skip files that don't build for this port +NIMBLE_IGNORE := $(NIMBLE_ROOT)/porting/nimble/src/hal_timer.c \ + $(NIMBLE_ROOT)/porting/nimble/src/os_cputime.c \ + $(NIMBLE_ROOT)/porting/nimble/src/os_cputime_pwr2.c \ + $(NULL) + +include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs + +SRC := $(NIMBLE_SRC) + +# Source files for NPL OSAL +SRC += \ + $(wildcard $(NIMBLE_ROOT)/porting/npl/linux/src/*.c) \ + $(wildcard $(NIMBLE_ROOT)/porting/npl/linux/src/*.cc) \ + $(wildcard $(NIMBLE_ROOT)/nimble/transport/socket/src/*.c) \ + $(TINYCRYPT_SRC) \ + $(NULL) + +# Source files for demo app +SRC += \ + ./ble.c \ + ./main.c \ + $(NULL) + +# Add NPL and all NimBLE directories to include paths +INC = \ + ./include \ + $(NIMBLE_ROOT)/porting/npl/linux/include \ + $(NIMBLE_ROOT)/nimble/transport/socket/include \ + $(NIMBLE_INCLUDE) \ + $(TINYCRYPT_INCLUDE) \ + $(NULL) + +INCLUDES := $(addprefix -I, $(INC)) + +SRC_C = $(filter %.c, $(SRC)) +SRC_CC = $(filter %.cc, $(SRC)) + +OBJ := $(SRC_C:.c=.o) +OBJ += $(SRC_CC:.cc=.o) + +TINYCRYPT_OBJ := $(TINYCRYPT_SRC:.c=.o) + +CFLAGS = \ + $(NIMBLE_CFLAGS) \ + $(INCLUDES) \ + -g \ + -D_GNU_SOURCE \ + $(NULL) + +LIBS := -lrt -lpthread -lstdc++ + +.PHONY: all clean +.DEFAULT: all + +all: nimble-linux + +clean: + rm $(OBJ) -f + rm nimble-linux -f + +$(TINYCRYPT_OBJ): CFLAGS+=$(TINYCRYPT_CFLAGS) + +%.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $< + +%.o: %.cc + $(CXX) -c $(INCLUDES) $(CFLAGS) -o $@ $< + +nimble-linux: $(OBJ) $(TINYCRYPT_OBJ) + $(LD) -o $@ $^ $(LIBS) + $(SIZE) $@ diff --git a/src/libs/mynewt-nimble/porting/examples/linux/README.md b/src/libs/mynewt-nimble/porting/examples/linux/README.md new file mode 100644 index 00000000..bbf68bb5 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux/README.md @@ -0,0 +1,73 @@ +<!-- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +--> + +# Apache Mynewt NimBLE + +## Overview + +See (https://mynewt.apache.org/network/ble/ble_intro/). + +## Building + +NimBLE is usually built as a part of Apache Mynewt OS, but ports for +other RTOS-es are also available. + +### Linux + +1. Build the sample application + +```no-highlight + cd porting/examples/linux + make +``` + +2. Run the sample application + +First insert a USB Bluetooth dongle. These are typically BLE 4.0 capable. + +Verify the dongle is connected with hciconfig: + +```no-highlight + $ hciconfig +hci0: Type: BR/EDR Bus: USB + BD Address: 00:1B:DC:06:62:5E ACL MTU: 310:10 SCO MTU: 64:8 + DOWN + RX bytes:5470 acl:0 sco:0 events:40 errors:0 + TX bytes:5537 acl:176 sco:0 commands:139 errors:1 +``` + +Then run the application built in step one. The application is configured +in sysconfig.h to use hci0. + +```no-highlight + cd porting/examples/linux + sudo ./_build/nimble_linux.out +``` + +3. Build and run the unit tests + +The Operating System Abstraction Layer (OSAL) used to port Nimble to Linux +has a suite of unit tests. + +```no-highlight + cd tests/unit/porting/npl + make test +``` diff --git a/src/libs/mynewt-nimble/porting/examples/linux/ble.c b/src/libs/mynewt-nimble/porting/examples/linux/ble.c new file mode 100644 index 00000000..ea6655f2 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux/ble.c @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include <stdbool.h> +#include <stdint.h> + +#include "nimble/nimble_port.h" +#include "host/ble_hs.h" +#include "host/util/util.h" +#include "services/gap/ble_svc_gap.h" + +static const char gap_name[] = "nimble"; + +static uint8_t own_addr_type; + +static void start_advertise(void); + +static void +put_ad(uint8_t ad_type, uint8_t ad_len, const void *ad, uint8_t *buf, + uint8_t *len) +{ + buf[(*len)++] = ad_len + 1; + buf[(*len)++] = ad_type; + + memcpy(&buf[*len], ad, ad_len); + + *len += ad_len; +} + +static void +update_ad(void) +{ + uint8_t ad[BLE_HS_ADV_MAX_SZ]; + uint8_t ad_len = 0; + uint8_t ad_flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP; + + put_ad(BLE_HS_ADV_TYPE_FLAGS, 1, &ad_flags, ad, &ad_len); + put_ad(BLE_HS_ADV_TYPE_COMP_NAME, sizeof(gap_name), gap_name, ad, &ad_len); + + ble_gap_adv_set_data(ad, ad_len); +} + +static int +gap_event_cb(struct ble_gap_event *event, void *arg) +{ + switch (event->type) { + case BLE_GAP_EVENT_CONNECT: + if (event->connect.status) { + start_advertise(); + } + break; + + case BLE_GAP_EVENT_DISCONNECT: + start_advertise(); + break; + } + + return 0; +} + +static void +start_advertise(void) +{ + struct ble_gap_adv_params advp; + int rc; + + update_ad(); + + memset(&advp, 0, sizeof advp); + advp.conn_mode = BLE_GAP_CONN_MODE_UND; + advp.disc_mode = BLE_GAP_DISC_MODE_GEN; + rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER, + &advp, gap_event_cb, NULL); + assert(rc == 0); +} + +static void +app_ble_sync_cb(void) +{ + int rc; + + rc = ble_hs_util_ensure_addr(0); + assert(rc == 0); + + rc = ble_hs_id_infer_auto(0, &own_addr_type); + assert(rc == 0); + + start_advertise(); +} + +void +nimble_host_task(void *param) +{ + ble_hs_cfg.sync_cb = app_ble_sync_cb; + + ble_svc_gap_device_name_set(gap_name); + + nimble_port_run(); +} diff --git a/src/libs/mynewt-nimble/porting/examples/linux/include/logcfg/logcfg.h b/src/libs/mynewt-nimble/porting/examples/linux/include/logcfg/logcfg.h new file mode 100644 index 00000000..e21a3ae5 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux/include/logcfg/logcfg.h @@ -0,0 +1,32 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_LOGCFG_ +#define H_MYNEWT_LOGCFG_ + +#include "modlog/modlog.h" +#include "log_common/log_common.h" + +#define BLE_HS_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_HS_LOG_INFO(...) MODLOG_INFO(4, __VA_ARGS__) +#define BLE_HS_LOG_WARN(...) MODLOG_WARN(4, __VA_ARGS__) +#define BLE_HS_LOG_ERROR(...) MODLOG_ERROR(4, __VA_ARGS__) +#define BLE_HS_LOG_CRITICAL(...) MODLOG_CRITICAL(4, __VA_ARGS__) +#define BLE_HS_LOG_DISABLED(...) MODLOG_DISABLED(4, __VA_ARGS__) + +#define DFLT_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define DFLT_LOG_INFO(...) MODLOG_INFO(0, __VA_ARGS__) +#define DFLT_LOG_WARN(...) MODLOG_WARN(0, __VA_ARGS__) +#define DFLT_LOG_ERROR(...) MODLOG_ERROR(0, __VA_ARGS__) +#define DFLT_LOG_CRITICAL(...) MODLOG_CRITICAL(0, __VA_ARGS__) +#define DFLT_LOG_DISABLED(...) MODLOG_DISABLED(0, __VA_ARGS__) + +#define MFG_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_INFO(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_WARN(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_ERROR(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_CRITICAL(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_DISABLED(...) MODLOG_DISABLED(128, __VA_ARGS__) + +#endif diff --git a/src/libs/mynewt-nimble/porting/examples/linux/include/syscfg/syscfg.h b/src/libs/mynewt-nimble/porting/examples/linux/include/syscfg/syscfg.h new file mode 100644 index 00000000..7e9bfcac --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux/include/syscfg/syscfg.h @@ -0,0 +1,1013 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSCFG_ +#define H_MYNEWT_SYSCFG_ + +/** + * This macro exists to ensure code includes this header when needed. If code + * checks the existence of a setting directly via ifdef without including this + * header, the setting macro will silently evaluate to 0. In contrast, an + * attempt to use these macros without including this header will result in a + * compiler error. + */ +#define MYNEWT_VAL(_name) MYNEWT_VAL_ ## _name +#define MYNEWT_VAL_CHOICE(_name, _val) MYNEWT_VAL_ ## _name ## __ ## _val + + + +/*** @apache-mynewt-core/crypto/tinycrypt */ +#ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE +#define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME ("trng") +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG (0) +#endif + +/*** @apache-mynewt-core/hw/hal */ +#ifndef MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS +#define MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS (1) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ +#define MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ (16) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_SYSTEM_RESET_CB +#define MYNEWT_VAL_HAL_SYSTEM_RESET_CB (0) +#endif + +/*** @apache-mynewt-core/kernel/os */ +#ifndef MYNEWT_VAL_FLOAT_USER +#define MYNEWT_VAL_FLOAT_USER (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_1_BLOCK_COUNT (12) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_1_BLOCK_SIZE (292) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_2_BLOCK_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_2_BLOCK_SIZE (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_SANITY_TIMEOUT +#define MYNEWT_VAL_MSYS_SANITY_TIMEOUT (60000) +#endif + +#ifndef MYNEWT_VAL_OS_ASSERT_CB +#define MYNEWT_VAL_OS_ASSERT_CB (0) +#endif + +#ifndef MYNEWT_VAL_OS_CLI +#define MYNEWT_VAL_OS_CLI (0) +#endif + +#ifndef MYNEWT_VAL_OS_COREDUMP +#define MYNEWT_VAL_OS_COREDUMP (0) +#endif + +#ifndef MYNEWT_VAL_OS_CPUTIME_FREQ +#define MYNEWT_VAL_OS_CPUTIME_FREQ (1000000) +#endif + +#ifndef MYNEWT_VAL_OS_CPUTIME_TIMER_NUM +#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_FILE_LINE +#define MYNEWT_VAL_OS_CRASH_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_LOG +#define MYNEWT_VAL_OS_CRASH_LOG (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_RESTORE_REGS +#define MYNEWT_VAL_OS_CRASH_RESTORE_REGS (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_STACKTRACE +#define MYNEWT_VAL_OS_CRASH_STACKTRACE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_CHECK +#define MYNEWT_VAL_OS_CTX_SW_STACK_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_GUARD +#define MYNEWT_VAL_OS_CTX_SW_STACK_GUARD (4) +#endif + +#ifndef MYNEWT_VAL_OS_DEBUG_MODE +#define MYNEWT_VAL_OS_DEBUG_MODE (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_DEBUG +#define MYNEWT_VAL_OS_EVENTQ_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_MONITOR +#define MYNEWT_VAL_OS_EVENTQ_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX (600000) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN (100) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_STACK_SIZE +#define MYNEWT_VAL_OS_MAIN_STACK_SIZE (1024) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_PRIO +#define MYNEWT_VAL_OS_MAIN_TASK_PRIO (127) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS +#define MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_CHECK +#define MYNEWT_VAL_OS_MEMPOOL_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_GUARD +#define MYNEWT_VAL_OS_MEMPOOL_GUARD (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_POISON +#define MYNEWT_VAL_OS_MEMPOOL_POISON (0) +#endif + +#ifndef MYNEWT_VAL_OS_SCHEDULING +#define MYNEWT_VAL_OS_SCHEDULING (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSINIT_STAGE +#define MYNEWT_VAL_OS_SYSINIT_STAGE (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW +#define MYNEWT_VAL_OS_SYSVIEW (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM (1) +#endif + +#ifndef MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME +#define MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME (0) +#endif + +#ifndef MYNEWT_VAL_OS_TIME_DEBUG +#define MYNEWT_VAL_OS_TIME_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_WATCHDOG_MONITOR +#define MYNEWT_VAL_OS_WATCHDOG_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_SANITY_INTERVAL +#define MYNEWT_VAL_SANITY_INTERVAL (15000) +#endif + +#ifndef MYNEWT_VAL_WATCHDOG_INTERVAL +#define MYNEWT_VAL_WATCHDOG_INTERVAL (30000) +#endif + +/*** @apache-mynewt-core/sys/console/stub */ +#ifndef MYNEWT_VAL_CONSOLE_UART_BAUD +#define MYNEWT_VAL_CONSOLE_UART_BAUD (115200) +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_DEV +#define MYNEWT_VAL_CONSOLE_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL +#define MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL (UART_FLOW_CTL_NONE) +#endif + +/*** @apache-mynewt-core/sys/flash_map */ +#ifndef MYNEWT_VAL_FLASH_MAP_MAX_AREAS +#define MYNEWT_VAL_FLASH_MAP_MAX_AREAS (10) +#endif + +#ifndef MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE +#define MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE (2) +#endif + +/*** @apache-mynewt-core/sys/log/common */ +#ifndef MYNEWT_VAL_DFLT_LOG_LVL +#define MYNEWT_VAL_DFLT_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_DFLT_LOG_MOD +#define MYNEWT_VAL_DFLT_LOG_MOD (0) +#endif + +#ifndef MYNEWT_VAL_LOG_GLOBAL_IDX +#define MYNEWT_VAL_LOG_GLOBAL_IDX (1) +#endif + +/*** @apache-mynewt-core/sys/log/modlog */ +#ifndef MYNEWT_VAL_MODLOG_CONSOLE_DFLT +#define MYNEWT_VAL_MODLOG_CONSOLE_DFLT (1) +#endif + +#ifndef MYNEWT_VAL_MODLOG_LOG_MACROS +#define MYNEWT_VAL_MODLOG_LOG_MACROS (0) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_MAPPINGS +#define MYNEWT_VAL_MODLOG_MAX_MAPPINGS (16) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN +#define MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN (128) +#endif + +#ifndef MYNEWT_VAL_MODLOG_SYSINIT_STAGE +#define MYNEWT_VAL_MODLOG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/log/stub */ +#ifndef MYNEWT_VAL_LOG_CONSOLE +#define MYNEWT_VAL_LOG_CONSOLE (1) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB +#define MYNEWT_VAL_LOG_FCB (0) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB_SLOT1 +#define MYNEWT_VAL_LOG_FCB_SLOT1 (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux (defined by @apache-mynewt-core/sys/log/stub) */ +#ifndef MYNEWT_VAL_LOG_LEVEL +#define MYNEWT_VAL_LOG_LEVEL (0) +#endif + +/*** @apache-mynewt-core/sys/mfg */ +#ifndef MYNEWT_VAL_MFG_LOG_LVL +#define MYNEWT_VAL_MFG_LOG_LVL (15) +#endif + +#ifndef MYNEWT_VAL_MFG_LOG_MODULE +#define MYNEWT_VAL_MFG_LOG_MODULE (128) +#endif + +#ifndef MYNEWT_VAL_MFG_MAX_MMRS +#define MYNEWT_VAL_MFG_MAX_MMRS (2) +#endif + +#ifndef MYNEWT_VAL_MFG_SYSINIT_STAGE +#define MYNEWT_VAL_MFG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/sys */ +#ifndef MYNEWT_VAL_DEBUG_PANIC_ENABLED +#define MYNEWT_VAL_DEBUG_PANIC_ENABLED (1) +#endif + +/*** @apache-mynewt-core/sys/sysdown */ +#ifndef MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN +#define MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN (1) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE +#define MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_TIMEOUT_MS +#define MYNEWT_VAL_SYSDOWN_TIMEOUT_MS (10000) +#endif + +/*** @apache-mynewt-core/sys/sysinit */ +#ifndef MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT +#define MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT (1) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_MESSAGE +#define MYNEWT_VAL_SYSINIT_PANIC_MESSAGE (0) +#endif + +/*** @apache-mynewt-core/util/rwlock */ +#ifndef MYNEWT_VAL_RWLOCK_DEBUG +#define MYNEWT_VAL_RWLOCK_DEBUG (0) +#endif + +/*** @apache-mynewt-nimble/nimble */ +#ifndef MYNEWT_VAL_BLE_EXT_ADV +#define MYNEWT_VAL_BLE_EXT_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE +#define MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE (31) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_CONNECTIONS +#define MYNEWT_VAL_BLE_MAX_CONNECTIONS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS +#define MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES +#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV +#define MYNEWT_VAL_BLE_PERIODIC_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER +#define MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER (0) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER +#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_CENTRAL +#define MYNEWT_VAL_BLE_ROLE_CENTRAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_OBSERVER +#define MYNEWT_VAL_BLE_ROLE_OBSERVER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_PERIPHERAL +#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_VERSION +#define MYNEWT_VAL_BLE_VERSION (50) +#endif + +#ifndef MYNEWT_VAL_BLE_WHITELIST +#define MYNEWT_VAL_BLE_WHITELIST (1) +#endif + +/*** @apache-mynewt-nimble/nimble/host */ +#ifndef MYNEWT_VAL_BLE_ATT_PREFERRED_MTU +#define MYNEWT_VAL_BLE_ATT_PREFERRED_MTU (256) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_INDICATE +#define MYNEWT_VAL_BLE_ATT_SVR_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES +#define MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES (64) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_NOTIFY +#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ +#define MYNEWT_VAL_BLE_ATT_SVR_READ (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB +#define MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_MULT +#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE +#define MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS +#define MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_INDICATE +#define MYNEWT_VAL_BLE_GATT_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_MAX_PROCS +#define MYNEWT_VAL_BLE_GATT_MAX_PROCS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_NOTIFY +#define MYNEWT_VAL_BLE_GATT_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ +#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_LONG +#define MYNEWT_VAL_BLE_GATT_READ_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MULT +#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_UUID +#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_RESUME_RATE +#define MYNEWT_VAL_BLE_GATT_RESUME_RATE (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_SIGNED_WRITE +#define MYNEWT_VAL_BLE_GATT_SIGNED_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE +#define MYNEWT_VAL_BLE_GATT_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_LONG +#define MYNEWT_VAL_BLE_GATT_WRITE_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE +#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_HOST +#define MYNEWT_VAL_BLE_HOST (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_AUTO_START +#define MYNEWT_VAL_BLE_HS_AUTO_START (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_DEBUG +#define MYNEWT_VAL_BLE_HS_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH (2) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_LVL +#define MYNEWT_VAL_BLE_HS_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_MOD +#define MYNEWT_VAL_BLE_HS_LOG_MOD (4) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS +#define MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_REQUIRE_OS +#define MYNEWT_VAL_BLE_HS_REQUIRE_OS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_HS_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM +#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MPS +#define MYNEWT_VAL_BLE_L2CAP_COC_MPS (MYNEWT_VAL_MSYS_1_BLOCK_SIZE-8) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC +#define MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS +#define MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_MAX_CHANS +#define MYNEWT_VAL_BLE_L2CAP_MAX_CHANS (3*MYNEWT_VAL_BLE_MAX_CONNECTIONS) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT +#define MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS +#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH +#define MYNEWT_VAL_BLE_MESH (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE (128) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT +#define MYNEWT_VAL_BLE_MONITOR_RTT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME ("btmonitor") +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE (256) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART +#define MYNEWT_VAL_BLE_MONITOR_UART (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE +#define MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE (1000000) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE (64) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_DEV +#define MYNEWT_VAL_BLE_MONITOR_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_BLE_RPA_TIMEOUT +#define MYNEWT_VAL_BLE_RPA_TIMEOUT (300) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_BONDING +#define MYNEWT_VAL_BLE_SM_BONDING (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_IO_CAP +#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_NO_INPUT_OUTPUT) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_KEYPRESS +#define MYNEWT_VAL_BLE_SM_KEYPRESS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_LEGACY +#define MYNEWT_VAL_BLE_SM_LEGACY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MAX_PROCS +#define MYNEWT_VAL_BLE_SM_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MITM +#define MYNEWT_VAL_BLE_SM_MITM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG +#define MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OUR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_OUR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC +#define MYNEWT_VAL_BLE_SM_SC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS +#define MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_BONDS +#define MYNEWT_VAL_BLE_STORE_MAX_BONDS (3) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_CCCDS +#define MYNEWT_VAL_BLE_STORE_MAX_CCCDS (8) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ans */ +#ifndef MYNEWT_VAL_BLE_SVC_ANS_NEW_ALERT_CAT +#define MYNEWT_VAL_BLE_SVC_ANS_NEW_ALERT_CAT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_ANS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_ANS_SYSINIT_STAGE (303) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_ANS_UNR_ALERT_CAT +#define MYNEWT_VAL_BLE_SVC_ANS_UNR_ALERT_CAT (0) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/bas */ +#ifndef MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_NOTIFY_ENABLE +#define MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_NOTIFY_ENABLE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_READ_PERM +#define MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_READ_PERM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_BAS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_BAS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/dis */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_DEFAULT_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_DEFAULT_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_DEFAULT ("Apache Mynewt NimBLE") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_READ_PERM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_DIS_SYSINIT_STAGE (303) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_READ_PERM (-1) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gap */ +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION +#define MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME ("nimble") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH (31) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE (301) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gatt */ +#ifndef MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE (302) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ias */ +#ifndef MYNEWT_VAL_BLE_SVC_IAS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_IAS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ipss */ +#ifndef MYNEWT_VAL_BLE_SVC_IPSS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_IPSS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/lls */ +#ifndef MYNEWT_VAL_BLE_SVC_LLS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_LLS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/tps */ +#ifndef MYNEWT_VAL_BLE_SVC_TPS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_TPS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/transport/socket */ +#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT +#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24) +#endif + +#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE +#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT +#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE +#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE (500) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_LINUX_DEV +#define MYNEWT_VAL_BLE_SOCK_LINUX_DEV (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_STACK_SIZE +#define MYNEWT_VAL_BLE_SOCK_STACK_SIZE (1028) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_TASK_PRIO +#define MYNEWT_VAL_BLE_SOCK_TASK_PRIO (3) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_TCP_PORT +#define MYNEWT_VAL_BLE_SOCK_TCP_PORT (14433) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_USE_LINUX_BLUE +#define MYNEWT_VAL_BLE_SOCK_USE_LINUX_BLUE (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_USE_TCP +#define MYNEWT_VAL_BLE_SOCK_USE_TCP (0) +#endif + +/*** newt */ +#ifndef MYNEWT_VAL_APP_NAME +#define MYNEWT_VAL_APP_NAME ("dummy_app") +#endif + +#ifndef MYNEWT_VAL_APP_dummy_app +#define MYNEWT_VAL_APP_dummy_app (1) +#endif + +#ifndef MYNEWT_VAL_ARCH_NAME +#define MYNEWT_VAL_ARCH_NAME ("dummy") +#endif + +#ifndef MYNEWT_VAL_ARCH_dummy +#define MYNEWT_VAL_ARCH_dummy (1) +#endif + +#ifndef MYNEWT_VAL_BSP_NAME +#define MYNEWT_VAL_BSP_NAME ("dummy_bsp") +#endif + +#ifndef MYNEWT_VAL_BSP_dummy_bsp +#define MYNEWT_VAL_BSP_dummy_bsp (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_LOGCFG +#define MYNEWT_VAL_NEWT_FEATURE_LOGCFG (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_SYSDOWN +#define MYNEWT_VAL_NEWT_FEATURE_SYSDOWN (1) +#endif + +#ifndef MYNEWT_VAL_TARGET_NAME +#define MYNEWT_VAL_TARGET_NAME ("linux") +#endif + +#ifndef MYNEWT_VAL_TARGET_linux +#define MYNEWT_VAL_TARGET_linux (1) +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/examples/linux/include/sysflash/sysflash.h b/src/libs/mynewt-nimble/porting/examples/linux/include/sysflash/sysflash.h new file mode 100644 index 00000000..413cb267 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux/include/sysflash/sysflash.h @@ -0,0 +1,24 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSFLASH_ +#define H_MYNEWT_SYSFLASH_ + +#include "flash_map/flash_map.h" + +/** + * This flash map definition is used for two purposes: + * 1. To locate the meta area, which contains the true flash map definition. + * 2. As a fallback in case the meta area cannot be read from flash. + */ +extern const struct flash_area sysflash_map_dflt[6]; + +#define FLASH_AREA_BOOTLOADER 0 +#define FLASH_AREA_IMAGE_0 1 +#define FLASH_AREA_IMAGE_1 2 +#define FLASH_AREA_IMAGE_SCRATCH 3 +#define FLASH_AREA_REBOOT_LOG 16 +#define FLASH_AREA_NFFS 17 + +#endif diff --git a/src/libs/mynewt-nimble/porting/examples/linux/main.c b/src/libs/mynewt-nimble/porting/examples/linux/main.c new file mode 100644 index 00000000..86b6fb95 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux/main.c @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#include <pthread.h> +#include "nimble/nimble_npl.h" +#include "nimble/nimble_port.h" + +#include "services/gap/ble_svc_gap.h" +#include "services/gatt/ble_svc_gatt.h" +#include "services/ans/ble_svc_ans.h" +#include "services/ias/ble_svc_ias.h" +#include "services/lls/ble_svc_lls.h" +#include "services/tps/ble_svc_tps.h" + +static struct ble_npl_task s_task_host; +static struct ble_npl_task s_task_hci; + +void nimble_host_task(void *param); +void ble_hci_sock_ack_handler(void *param); +void ble_hci_sock_init(void); +void ble_hci_sock_set_device(int dev); + +#define TASK_DEFAULT_PRIORITY 1 +#define TASK_DEFAULT_STACK NULL +#define TASK_DEFAULT_STACK_SIZE 400 + +void *ble_hci_sock_task(void *param) +{ + ble_hci_sock_ack_handler(param); + return NULL; +} + +void *ble_host_task(void *param) +{ + nimble_host_task(param); + return NULL; +} + +int main(int argc, char *argv[]) +{ + int ret = 0; + + /* allow to specify custom hci */ + if (argc > 1) { + ble_hci_sock_set_device(atoi(argv[1])); + } + + ble_hci_sock_init(); + nimble_port_init(); + + /* This example provides GATT Alert service */ + ble_svc_gap_init(); + ble_svc_gatt_init(); + ble_svc_ans_init(); + ble_svc_ias_init(); + ble_svc_lls_init(); + ble_svc_tps_init(); + + /* XXX Need to have template for store */ + ble_store_ram_init(); + + ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, + TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); + + /* Create task which handles default event queue for host stack. */ + ble_npl_task_init(&s_task_host, "ble_host", ble_host_task, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, + TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); + + pthread_exit(&ret); +} diff --git a/src/libs/mynewt-nimble/porting/examples/linux_blemesh/Makefile b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/Makefile new file mode 100644 index 00000000..0e934249 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/Makefile @@ -0,0 +1,107 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Toolchain commands +CROSS_COMPILE ?= +CC := ccache $(CROSS_COMPLIE)gcc +CXX := ccache $(CROSS_COMPILE)g++ +LD := $(CROSS_COMPILE)gcc +AR := $(CROSS_COMPILE)ar +AS := $(CROSS_COMPILE)as +NM := $(CROSS_COMPILE)nm +OBJDUMP := $(CROSS_COMPILE)objdump +OBJCOPY := $(CROSS_COMPILE)objcopy +SIZE := $(CROSS_COMPILE)size + +# Configure NimBLE variables +NIMBLE_ROOT := ../../.. +NIMBLE_CFG_TINYCRYPT := 1 + +# Skip files that don't build for this port +NIMBLE_IGNORE := $(NIMBLE_ROOT)/porting/nimble/src/hal_timer.c \ + $(NIMBLE_ROOT)/porting/nimble/src/os_cputime.c \ + $(NIMBLE_ROOT)/porting/nimble/src/os_cputime_pwr2.c \ + $(NULL) + +include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs +include $(NIMBLE_ROOT)/porting/nimble/Makefile.mesh + +SRC := $(NIMBLE_SRC) + +# Source files for NPL OSAL +SRC += \ + $(wildcard $(NIMBLE_ROOT)/porting/npl/linux/src/*.c) \ + $(wildcard $(NIMBLE_ROOT)/porting/npl/linux/src/*.cc) \ + $(wildcard $(NIMBLE_ROOT)/nimble/transport/socket/src/*.c) \ + $(TINYCRYPT_SRC) \ + $(NULL) + +# Source files for demo app +SRC += \ + ./ble.c \ + ./main.c \ + $(NULL) + +# Add NPL and all NimBLE directories to include paths +INC = \ + ./include \ + $(NIMBLE_ROOT)/porting/npl/linux/include \ + $(NIMBLE_ROOT)/porting/npl/linux/src \ + $(NIMBLE_ROOT)/nimble/transport/socket/include \ + $(NIMBLE_INCLUDE) \ + $(TINYCRYPT_INCLUDE) \ + $(NULL) + +INCLUDES := $(addprefix -I, $(INC)) + +SRC_C = $(filter %.c, $(SRC)) +SRC_CC = $(filter %.cc, $(SRC)) + +OBJ := $(SRC_C:.c=.o) +OBJ += $(SRC_CC:.cc=.o) + +TINYCRYPT_OBJ := $(TINYCRYPT_SRC:.c=.o) + +CFLAGS = \ + $(NIMBLE_CFLAGS) \ + $(INCLUDES) \ + -g \ + -D_GNU_SOURCE \ + $(NULL) + +LIBS := -lrt -lpthread -lstdc++ + +.PHONY: all clean +.DEFAULT: all + +all: nimble-linux-blemesh + +clean: + rm $(OBJ) -f + rm nimble-linux-blemesh -f + +$(TINYCRYPT_OBJ): CFLAGS+=$(TINYCRYPT_CFLAGS) + +%.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) -o $@ $< + +%.o: %.cc + $(CXX) -c $(INCLUDES) $(CFLAGS) -o $@ $< + +nimble-linux-blemesh: $(OBJ) $(TINYCRYPT_OBJ) + $(LD) -o $@ $^ $(LIBS) + $(SIZE) $@ diff --git a/src/libs/mynewt-nimble/porting/examples/linux_blemesh/ble.c b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/ble.c new file mode 100644 index 00000000..22a9e71d --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/ble.c @@ -0,0 +1,448 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include "mesh/mesh.h" +#include "console/console.h" + +/* BLE */ +#include "nimble/nimble_port.h" +#include "nimble/ble.h" +#include "host/ble_hs.h" +#include "services/gap/ble_svc_gap.h" +#include "mesh/glue.h" + +#define BT_DBG_ENABLED (MYNEWT_VAL(BLE_MESH_DEBUG)) + +/* Company ID */ +#define CID_VENDOR 0x05C3 +#define STANDARD_TEST_ID 0x00 +#define TEST_ID 0x01 +static int recent_test_id = STANDARD_TEST_ID; + +#define FAULT_ARR_SIZE 2 + +static bool has_reg_fault = true; + +static struct bt_mesh_cfg_srv cfg_srv = { + .relay = BT_MESH_RELAY_ENABLED, + .beacon = BT_MESH_BEACON_ENABLED, +#if MYNEWT_VAL(BLE_MESH_FRIEND) + .frnd = BT_MESH_FRIEND_ENABLED, +#else + .frnd = BT_MESH_FRIEND_NOT_SUPPORTED , +#endif +#if MYNEWT_VAL(BLE_MESH_GATT_PROXY) + .gatt_proxy = BT_MESH_GATT_PROXY_ENABLED, +#else + .gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED, +#endif + .default_ttl = 7, + + /* 3 transmissions with 20ms interval */ + .net_transmit = BT_MESH_TRANSMIT(2, 20), + .relay_retransmit = BT_MESH_TRANSMIT(2, 20), +}; + +static int +fault_get_cur(struct bt_mesh_model *model, + uint8_t *test_id, + uint16_t *company_id, + uint8_t *faults, + uint8_t *fault_count) +{ + uint8_t reg_faults[FAULT_ARR_SIZE] = { [0 ... FAULT_ARR_SIZE-1] = 0xff }; + + console_printf("fault_get_cur() has_reg_fault %u\n", has_reg_fault); + + *test_id = recent_test_id; + *company_id = CID_VENDOR; + + *fault_count = min(*fault_count, sizeof(reg_faults)); + memcpy(faults, reg_faults, *fault_count); + + return 0; +} + +static int +fault_get_reg(struct bt_mesh_model *model, + uint16_t company_id, + uint8_t *test_id, + uint8_t *faults, + uint8_t *fault_count) +{ + if (company_id != CID_VENDOR) { + return -BLE_HS_EINVAL; + } + + console_printf("fault_get_reg() has_reg_fault %u\n", has_reg_fault); + + *test_id = recent_test_id; + + if (has_reg_fault) { + uint8_t reg_faults[FAULT_ARR_SIZE] = { [0 ... FAULT_ARR_SIZE-1] = 0xff }; + + *fault_count = min(*fault_count, sizeof(reg_faults)); + memcpy(faults, reg_faults, *fault_count); + } else { + *fault_count = 0; + } + + return 0; +} + +static int +fault_clear(struct bt_mesh_model *model, uint16_t company_id) +{ + if (company_id != CID_VENDOR) { + return -BLE_HS_EINVAL; + } + + has_reg_fault = false; + + return 0; +} + +static int +fault_test(struct bt_mesh_model *model, uint8_t test_id, uint16_t company_id) +{ + if (company_id != CID_VENDOR) { + return -BLE_HS_EINVAL; + } + + if (test_id != STANDARD_TEST_ID && test_id != TEST_ID) { + return -BLE_HS_EINVAL; + } + + recent_test_id = test_id; + has_reg_fault = true; + bt_mesh_fault_update(bt_mesh_model_elem(model)); + + return 0; +} + +static const struct bt_mesh_health_srv_cb health_srv_cb = { + .fault_get_cur = &fault_get_cur, + .fault_get_reg = &fault_get_reg, + .fault_clear = &fault_clear, + .fault_test = &fault_test, +}; + +static struct bt_mesh_health_srv health_srv = { + .cb = &health_srv_cb, +}; + +static struct bt_mesh_model_pub health_pub; + +static void +health_pub_init(void) +{ + health_pub.msg = BT_MESH_HEALTH_FAULT_MSG(0); +} + +static struct bt_mesh_model_pub gen_level_pub; +static struct bt_mesh_model_pub gen_onoff_pub; + +static uint8_t gen_on_off_state; +static int16_t gen_level_state; + +static void gen_onoff_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx) +{ + struct os_mbuf *msg = NET_BUF_SIMPLE(3); + uint8_t *status; + + console_printf("#mesh-onoff STATUS\n"); + + bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x04)); + status = net_buf_simple_add(msg, 1); + *status = gen_on_off_state; + + if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + console_printf("#mesh-onoff STATUS: send status failed\n"); + } + + os_mbuf_free_chain(msg); +} + +static void gen_onoff_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + console_printf("#mesh-onoff GET\n"); + + gen_onoff_status(model, ctx); +} + +static void gen_onoff_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + console_printf("#mesh-onoff SET\n"); + + gen_on_off_state = buf->om_data[0]; + + gen_onoff_status(model, ctx); +} + +static void gen_onoff_set_unack(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + console_printf("#mesh-onoff SET-UNACK\n"); + + gen_on_off_state = buf->om_data[0]; +} + +static const struct bt_mesh_model_op gen_onoff_op[] = { + { BT_MESH_MODEL_OP_2(0x82, 0x01), 0, gen_onoff_get }, + { BT_MESH_MODEL_OP_2(0x82, 0x02), 2, gen_onoff_set }, + { BT_MESH_MODEL_OP_2(0x82, 0x03), 2, gen_onoff_set_unack }, + BT_MESH_MODEL_OP_END, +}; + +static void gen_level_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx) +{ + struct os_mbuf *msg = NET_BUF_SIMPLE(4); + + console_printf("#mesh-level STATUS\n"); + + bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_2(0x82, 0x08)); + net_buf_simple_add_le16(msg, gen_level_state); + + if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + console_printf("#mesh-level STATUS: send status failed\n"); + } + + os_mbuf_free_chain(msg); +} + +static void gen_level_get(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + console_printf("#mesh-level GET\n"); + + gen_level_status(model, ctx); +} + +static void gen_level_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + int16_t level; + + level = (int16_t) net_buf_simple_pull_le16(buf); + console_printf("#mesh-level SET: level=%d\n", level); + + gen_level_status(model, ctx); + + gen_level_state = level; + console_printf("#mesh-level: level=%d\n", gen_level_state); +} + +static void gen_level_set_unack(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + int16_t level; + + level = (int16_t) net_buf_simple_pull_le16(buf); + console_printf("#mesh-level SET-UNACK: level=%d\n", level); + + gen_level_state = level; + console_printf("#mesh-level: level=%d\n", gen_level_state); +} + +static void gen_delta_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + int16_t delta_level; + + delta_level = (int16_t) net_buf_simple_pull_le16(buf); + console_printf("#mesh-level DELTA-SET: delta_level=%d\n", delta_level); + + gen_level_status(model, ctx); + + gen_level_state += delta_level; + console_printf("#mesh-level: level=%d\n", gen_level_state); +} + +static void gen_delta_set_unack(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + int16_t delta_level; + + delta_level = (int16_t) net_buf_simple_pull_le16(buf); + console_printf("#mesh-level DELTA-SET: delta_level=%d\n", delta_level); + + gen_level_state += delta_level; + console_printf("#mesh-level: level=%d\n", gen_level_state); +} + +static void gen_move_set(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ +} + +static void gen_move_set_unack(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ +} + +static const struct bt_mesh_model_op gen_level_op[] = { + { BT_MESH_MODEL_OP_2(0x82, 0x05), 0, gen_level_get }, + { BT_MESH_MODEL_OP_2(0x82, 0x06), 3, gen_level_set }, + { BT_MESH_MODEL_OP_2(0x82, 0x07), 3, gen_level_set_unack }, + { BT_MESH_MODEL_OP_2(0x82, 0x09), 5, gen_delta_set }, + { BT_MESH_MODEL_OP_2(0x82, 0x0a), 5, gen_delta_set_unack }, + { BT_MESH_MODEL_OP_2(0x82, 0x0b), 3, gen_move_set }, + { BT_MESH_MODEL_OP_2(0x82, 0x0c), 3, gen_move_set_unack }, + BT_MESH_MODEL_OP_END, +}; + +static struct bt_mesh_model root_models[] = { + BT_MESH_MODEL_CFG_SRV(&cfg_srv), + BT_MESH_MODEL_HEALTH_SRV(&health_srv, &health_pub), + BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_ONOFF_SRV, gen_onoff_op, + &gen_onoff_pub, NULL), + BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_LEVEL_SRV, gen_level_op, + &gen_level_pub, NULL), +}; + +static struct bt_mesh_model_pub vnd_model_pub; + +static void vnd_model_recv(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + struct os_mbuf *buf) +{ + struct os_mbuf *msg = NET_BUF_SIMPLE(3); + + console_printf("#vendor-model-recv\n"); + + console_printf("data:%s len:%d\n", bt_hex(buf->om_data, buf->om_len), + buf->om_len); + + bt_mesh_model_msg_init(msg, BT_MESH_MODEL_OP_3(0x01, CID_VENDOR)); + os_mbuf_append(msg, buf->om_data, buf->om_len); + + if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { + console_printf("#vendor-model-recv: send rsp failed\n"); + } + + os_mbuf_free_chain(msg); +} + +static const struct bt_mesh_model_op vnd_model_op[] = { + { BT_MESH_MODEL_OP_3(0x01, CID_VENDOR), 0, vnd_model_recv }, + BT_MESH_MODEL_OP_END, +}; + +static struct bt_mesh_model vnd_models[] = { + BT_MESH_MODEL_VND(CID_VENDOR, BT_MESH_MODEL_ID_GEN_ONOFF_SRV, vnd_model_op, + &vnd_model_pub, NULL), +}; + +static struct bt_mesh_elem elements[] = { + BT_MESH_ELEM(0, root_models, vnd_models), +}; + +static const struct bt_mesh_comp comp = { + .cid = CID_VENDOR, + .elem = elements, + .elem_count = ARRAY_SIZE(elements), +}; + +static int output_number(bt_mesh_output_action_t action, uint32_t number) +{ + console_printf("OOB Number: %u\n", number); + + return 0; +} + +static void prov_complete(u16_t net_idx, u16_t addr) +{ + console_printf("Local node provisioned, primary address 0x%04x\n", addr); +} + +static const uint8_t dev_uuid[16] = MYNEWT_VAL(BLE_MESH_DEV_UUID); + +static const struct bt_mesh_prov prov = { + .uuid = dev_uuid, + .output_size = 0, + .output_actions = 0, + .output_number = output_number, + .complete = prov_complete, +}; + +static void +blemesh_on_reset(int reason) +{ + BLE_HS_LOG(ERROR, "Resetting state; reason=%d\n", reason); +} + +void mesh_initialized(void); + +static void +blemesh_on_sync(void) +{ + int err; + + console_printf("Bluetooth initialized\n"); + + err = bt_mesh_init(0, &prov, &comp); + if (err) { + console_printf("Initializing mesh failed (err %d)\n", err); + return; + } + +#if (MYNEWT_VAL(BLE_MESH_SHELL)) + shell_register_default_module("mesh"); +#endif + + console_printf("Mesh initialized\n"); + + mesh_initialized(); + + if (IS_ENABLED(CONFIG_SETTINGS)) { + settings_load(); + } + + if (bt_mesh_is_provisioned()) { + printk("Mesh network restored from flash\n"); + } +} + +void +nimble_host_task(void *param) +{ + health_pub_init(); + + /* Initialize the NimBLE host configuration. */ + ble_hs_cfg.reset_cb = blemesh_on_reset; + ble_hs_cfg.sync_cb = blemesh_on_sync; + ble_hs_cfg.store_status_cb = ble_store_util_status_rr; + + nimble_port_run(); +} diff --git a/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/logcfg/logcfg.h b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/logcfg/logcfg.h new file mode 100644 index 00000000..7404dbb4 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/logcfg/logcfg.h @@ -0,0 +1,123 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_LOGCFG_ +#define H_MYNEWT_LOGCFG_ + +#include "modlog/modlog.h" +#include "log_common/log_common.h" + +#define BLE_HS_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_HS_LOG_INFO(...) MODLOG_INFO(4, __VA_ARGS__) +#define BLE_HS_LOG_WARN(...) MODLOG_WARN(4, __VA_ARGS__) +#define BLE_HS_LOG_ERROR(...) MODLOG_ERROR(4, __VA_ARGS__) +#define BLE_HS_LOG_CRITICAL(...) MODLOG_CRITICAL(4, __VA_ARGS__) +#define BLE_HS_LOG_DISABLED(...) MODLOG_DISABLED(4, __VA_ARGS__) + +#define BLE_MESH_ACCESS_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_ACCESS_LOG_INFO(...) MODLOG_INFO(10, __VA_ARGS__) +#define BLE_MESH_ACCESS_LOG_WARN(...) MODLOG_WARN(10, __VA_ARGS__) +#define BLE_MESH_ACCESS_LOG_ERROR(...) MODLOG_ERROR(10, __VA_ARGS__) +#define BLE_MESH_ACCESS_LOG_CRITICAL(...) MODLOG_CRITICAL(10, __VA_ARGS__) +#define BLE_MESH_ACCESS_LOG_DISABLED(...) MODLOG_DISABLED(10, __VA_ARGS__) + +#define BLE_MESH_ADV_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_ADV_LOG_INFO(...) MODLOG_INFO(11, __VA_ARGS__) +#define BLE_MESH_ADV_LOG_WARN(...) MODLOG_WARN(11, __VA_ARGS__) +#define BLE_MESH_ADV_LOG_ERROR(...) MODLOG_ERROR(11, __VA_ARGS__) +#define BLE_MESH_ADV_LOG_CRITICAL(...) MODLOG_CRITICAL(11, __VA_ARGS__) +#define BLE_MESH_ADV_LOG_DISABLED(...) MODLOG_DISABLED(11, __VA_ARGS__) + +#define BLE_MESH_BEACON_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_BEACON_LOG_INFO(...) MODLOG_INFO(12, __VA_ARGS__) +#define BLE_MESH_BEACON_LOG_WARN(...) MODLOG_WARN(12, __VA_ARGS__) +#define BLE_MESH_BEACON_LOG_ERROR(...) MODLOG_ERROR(12, __VA_ARGS__) +#define BLE_MESH_BEACON_LOG_CRITICAL(...) MODLOG_CRITICAL(12, __VA_ARGS__) +#define BLE_MESH_BEACON_LOG_DISABLED(...) MODLOG_DISABLED(12, __VA_ARGS__) + +#define BLE_MESH_CRYPTO_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_CRYPTO_LOG_INFO(...) MODLOG_INFO(13, __VA_ARGS__) +#define BLE_MESH_CRYPTO_LOG_WARN(...) MODLOG_WARN(13, __VA_ARGS__) +#define BLE_MESH_CRYPTO_LOG_ERROR(...) MODLOG_ERROR(13, __VA_ARGS__) +#define BLE_MESH_CRYPTO_LOG_CRITICAL(...) MODLOG_CRITICAL(13, __VA_ARGS__) +#define BLE_MESH_CRYPTO_LOG_DISABLED(...) MODLOG_DISABLED(13, __VA_ARGS__) + +#define BLE_MESH_FRIEND_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_FRIEND_LOG_INFO(...) MODLOG_INFO(14, __VA_ARGS__) +#define BLE_MESH_FRIEND_LOG_WARN(...) MODLOG_WARN(14, __VA_ARGS__) +#define BLE_MESH_FRIEND_LOG_ERROR(...) MODLOG_ERROR(14, __VA_ARGS__) +#define BLE_MESH_FRIEND_LOG_CRITICAL(...) MODLOG_CRITICAL(14, __VA_ARGS__) +#define BLE_MESH_FRIEND_LOG_DISABLED(...) MODLOG_DISABLED(14, __VA_ARGS__) + +#define BLE_MESH_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_LOG_INFO(...) MODLOG_INFO(9, __VA_ARGS__) +#define BLE_MESH_LOG_WARN(...) MODLOG_WARN(9, __VA_ARGS__) +#define BLE_MESH_LOG_ERROR(...) MODLOG_ERROR(9, __VA_ARGS__) +#define BLE_MESH_LOG_CRITICAL(...) MODLOG_CRITICAL(9, __VA_ARGS__) +#define BLE_MESH_LOG_DISABLED(...) MODLOG_DISABLED(9, __VA_ARGS__) + +#define BLE_MESH_LOW_POWER_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_LOW_POWER_LOG_INFO(...) MODLOG_INFO(15, __VA_ARGS__) +#define BLE_MESH_LOW_POWER_LOG_WARN(...) MODLOG_WARN(15, __VA_ARGS__) +#define BLE_MESH_LOW_POWER_LOG_ERROR(...) MODLOG_ERROR(15, __VA_ARGS__) +#define BLE_MESH_LOW_POWER_LOG_CRITICAL(...) MODLOG_CRITICAL(15, __VA_ARGS__) +#define BLE_MESH_LOW_POWER_LOG_DISABLED(...) MODLOG_DISABLED(15, __VA_ARGS__) + +#define BLE_MESH_MODEL_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_MODEL_LOG_INFO(...) MODLOG_INFO(16, __VA_ARGS__) +#define BLE_MESH_MODEL_LOG_WARN(...) MODLOG_WARN(16, __VA_ARGS__) +#define BLE_MESH_MODEL_LOG_ERROR(...) MODLOG_ERROR(16, __VA_ARGS__) +#define BLE_MESH_MODEL_LOG_CRITICAL(...) MODLOG_CRITICAL(16, __VA_ARGS__) +#define BLE_MESH_MODEL_LOG_DISABLED(...) MODLOG_DISABLED(16, __VA_ARGS__) + +#define BLE_MESH_NET_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_NET_LOG_INFO(...) MODLOG_INFO(17, __VA_ARGS__) +#define BLE_MESH_NET_LOG_WARN(...) MODLOG_WARN(17, __VA_ARGS__) +#define BLE_MESH_NET_LOG_ERROR(...) MODLOG_ERROR(17, __VA_ARGS__) +#define BLE_MESH_NET_LOG_CRITICAL(...) MODLOG_CRITICAL(17, __VA_ARGS__) +#define BLE_MESH_NET_LOG_DISABLED(...) MODLOG_DISABLED(17, __VA_ARGS__) + +#define BLE_MESH_PROV_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_PROV_LOG_INFO(...) MODLOG_INFO(18, __VA_ARGS__) +#define BLE_MESH_PROV_LOG_WARN(...) MODLOG_WARN(18, __VA_ARGS__) +#define BLE_MESH_PROV_LOG_ERROR(...) MODLOG_ERROR(18, __VA_ARGS__) +#define BLE_MESH_PROV_LOG_CRITICAL(...) MODLOG_CRITICAL(18, __VA_ARGS__) +#define BLE_MESH_PROV_LOG_DISABLED(...) MODLOG_DISABLED(18, __VA_ARGS__) + +#define BLE_MESH_PROXY_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_PROXY_LOG_INFO(...) MODLOG_INFO(19, __VA_ARGS__) +#define BLE_MESH_PROXY_LOG_WARN(...) MODLOG_WARN(19, __VA_ARGS__) +#define BLE_MESH_PROXY_LOG_ERROR(...) MODLOG_ERROR(19, __VA_ARGS__) +#define BLE_MESH_PROXY_LOG_CRITICAL(...) MODLOG_CRITICAL(19, __VA_ARGS__) +#define BLE_MESH_PROXY_LOG_DISABLED(...) MODLOG_DISABLED(19, __VA_ARGS__) + +#define BLE_MESH_SETTINGS_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_SETTINGS_LOG_INFO(...) MODLOG_INFO(20, __VA_ARGS__) +#define BLE_MESH_SETTINGS_LOG_WARN(...) MODLOG_WARN(20, __VA_ARGS__) +#define BLE_MESH_SETTINGS_LOG_ERROR(...) MODLOG_ERROR(20, __VA_ARGS__) +#define BLE_MESH_SETTINGS_LOG_CRITICAL(...) MODLOG_CRITICAL(20, __VA_ARGS__) +#define BLE_MESH_SETTINGS_LOG_DISABLED(...) MODLOG_DISABLED(20, __VA_ARGS__) + +#define BLE_MESH_TRANS_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_MESH_TRANS_LOG_INFO(...) MODLOG_INFO(21, __VA_ARGS__) +#define BLE_MESH_TRANS_LOG_WARN(...) MODLOG_WARN(21, __VA_ARGS__) +#define BLE_MESH_TRANS_LOG_ERROR(...) MODLOG_ERROR(21, __VA_ARGS__) +#define BLE_MESH_TRANS_LOG_CRITICAL(...) MODLOG_CRITICAL(21, __VA_ARGS__) +#define BLE_MESH_TRANS_LOG_DISABLED(...) MODLOG_DISABLED(21, __VA_ARGS__) + +#define DFLT_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define DFLT_LOG_INFO(...) MODLOG_INFO(0, __VA_ARGS__) +#define DFLT_LOG_WARN(...) MODLOG_WARN(0, __VA_ARGS__) +#define DFLT_LOG_ERROR(...) MODLOG_ERROR(0, __VA_ARGS__) +#define DFLT_LOG_CRITICAL(...) MODLOG_CRITICAL(0, __VA_ARGS__) +#define DFLT_LOG_DISABLED(...) MODLOG_DISABLED(0, __VA_ARGS__) + +#define MFG_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_INFO(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_WARN(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_ERROR(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_CRITICAL(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_DISABLED(...) MODLOG_DISABLED(128, __VA_ARGS__) + +#endif diff --git a/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/syscfg/syscfg.h b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/syscfg/syscfg.h new file mode 100644 index 00000000..24ad0c58 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/syscfg/syscfg.h @@ -0,0 +1,1393 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSCFG_ +#define H_MYNEWT_SYSCFG_ + +/** + * This macro exists to ensure code includes this header when needed. If code + * checks the existence of a setting directly via ifdef without including this + * header, the setting macro will silently evaluate to 0. In contrast, an + * attempt to use these macros without including this header will result in a + * compiler error. + */ +#define MYNEWT_VAL(_name) MYNEWT_VAL_ ## _name +#define MYNEWT_VAL_CHOICE(_name, _val) MYNEWT_VAL_ ## _name ## __ ## _val + + + +/*** @apache-mynewt-core/crypto/tinycrypt */ +#ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE +#define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME ("trng") +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG (0) +#endif + +/*** @apache-mynewt-core/hw/hal */ +#ifndef MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS +#define MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS (1) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ +#define MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ (16) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_SYSTEM_RESET_CB +#define MYNEWT_VAL_HAL_SYSTEM_RESET_CB (0) +#endif + +/*** @apache-mynewt-core/kernel/os */ +#ifndef MYNEWT_VAL_FLOAT_USER +#define MYNEWT_VAL_FLOAT_USER (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_1_BLOCK_COUNT (80) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_1_BLOCK_SIZE (292) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_2_BLOCK_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_2_BLOCK_SIZE (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_SANITY_TIMEOUT +#define MYNEWT_VAL_MSYS_SANITY_TIMEOUT (60000) +#endif + +#ifndef MYNEWT_VAL_OS_ASSERT_CB +#define MYNEWT_VAL_OS_ASSERT_CB (0) +#endif + +#ifndef MYNEWT_VAL_OS_CLI +#define MYNEWT_VAL_OS_CLI (0) +#endif + +#ifndef MYNEWT_VAL_OS_COREDUMP +#define MYNEWT_VAL_OS_COREDUMP (0) +#endif + +#ifndef MYNEWT_VAL_OS_CPUTIME_FREQ +#define MYNEWT_VAL_OS_CPUTIME_FREQ (1000000) +#endif + +#ifndef MYNEWT_VAL_OS_CPUTIME_TIMER_NUM +#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_FILE_LINE +#define MYNEWT_VAL_OS_CRASH_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_LOG +#define MYNEWT_VAL_OS_CRASH_LOG (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_RESTORE_REGS +#define MYNEWT_VAL_OS_CRASH_RESTORE_REGS (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_STACKTRACE +#define MYNEWT_VAL_OS_CRASH_STACKTRACE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_CHECK +#define MYNEWT_VAL_OS_CTX_SW_STACK_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_GUARD +#define MYNEWT_VAL_OS_CTX_SW_STACK_GUARD (4) +#endif + +#ifndef MYNEWT_VAL_OS_DEBUG_MODE +#define MYNEWT_VAL_OS_DEBUG_MODE (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_DEBUG +#define MYNEWT_VAL_OS_EVENTQ_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_MONITOR +#define MYNEWT_VAL_OS_EVENTQ_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX (600000) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN (100) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_STACK_SIZE +#define MYNEWT_VAL_OS_MAIN_STACK_SIZE (1024) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_PRIO +#define MYNEWT_VAL_OS_MAIN_TASK_PRIO (127) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS +#define MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_CHECK +#define MYNEWT_VAL_OS_MEMPOOL_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_GUARD +#define MYNEWT_VAL_OS_MEMPOOL_GUARD (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_POISON +#define MYNEWT_VAL_OS_MEMPOOL_POISON (0) +#endif + +#ifndef MYNEWT_VAL_OS_SCHEDULING +#define MYNEWT_VAL_OS_SCHEDULING (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSINIT_STAGE +#define MYNEWT_VAL_OS_SYSINIT_STAGE (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW +#define MYNEWT_VAL_OS_SYSVIEW (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM (1) +#endif + +#ifndef MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME +#define MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME (0) +#endif + +#ifndef MYNEWT_VAL_OS_TIME_DEBUG +#define MYNEWT_VAL_OS_TIME_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_WATCHDOG_MONITOR +#define MYNEWT_VAL_OS_WATCHDOG_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_SANITY_INTERVAL +#define MYNEWT_VAL_SANITY_INTERVAL (15000) +#endif + +#ifndef MYNEWT_VAL_WATCHDOG_INTERVAL +#define MYNEWT_VAL_WATCHDOG_INTERVAL (30000) +#endif + +/*** @apache-mynewt-core/sys/console/stub */ +#ifndef MYNEWT_VAL_CONSOLE_UART_BAUD +#define MYNEWT_VAL_CONSOLE_UART_BAUD (115200) +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_DEV +#define MYNEWT_VAL_CONSOLE_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL +#define MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL (UART_FLOW_CTL_NONE) +#endif + +/*** @apache-mynewt-core/sys/flash_map */ +#ifndef MYNEWT_VAL_FLASH_MAP_MAX_AREAS +#define MYNEWT_VAL_FLASH_MAP_MAX_AREAS (10) +#endif + +#ifndef MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE +#define MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE (2) +#endif + +/*** @apache-mynewt-core/sys/log/common */ +#ifndef MYNEWT_VAL_DFLT_LOG_LVL +#define MYNEWT_VAL_DFLT_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_DFLT_LOG_MOD +#define MYNEWT_VAL_DFLT_LOG_MOD (0) +#endif + +#ifndef MYNEWT_VAL_LOG_GLOBAL_IDX +#define MYNEWT_VAL_LOG_GLOBAL_IDX (1) +#endif + +/*** @apache-mynewt-core/sys/log/modlog */ +#ifndef MYNEWT_VAL_MODLOG_CONSOLE_DFLT +#define MYNEWT_VAL_MODLOG_CONSOLE_DFLT (1) +#endif + +#ifndef MYNEWT_VAL_MODLOG_LOG_MACROS +#define MYNEWT_VAL_MODLOG_LOG_MACROS (0) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_MAPPINGS +#define MYNEWT_VAL_MODLOG_MAX_MAPPINGS (16) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN +#define MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN (128) +#endif + +#ifndef MYNEWT_VAL_MODLOG_SYSINIT_STAGE +#define MYNEWT_VAL_MODLOG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/log/stub */ +#ifndef MYNEWT_VAL_LOG_CONSOLE +#define MYNEWT_VAL_LOG_CONSOLE (1) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB +#define MYNEWT_VAL_LOG_FCB (0) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB_SLOT1 +#define MYNEWT_VAL_LOG_FCB_SLOT1 (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-core/sys/log/stub) */ +#ifndef MYNEWT_VAL_LOG_LEVEL +#define MYNEWT_VAL_LOG_LEVEL (0) +#endif + +/*** @apache-mynewt-core/sys/mfg */ +#ifndef MYNEWT_VAL_MFG_LOG_LVL +#define MYNEWT_VAL_MFG_LOG_LVL (15) +#endif + +#ifndef MYNEWT_VAL_MFG_LOG_MODULE +#define MYNEWT_VAL_MFG_LOG_MODULE (128) +#endif + +#ifndef MYNEWT_VAL_MFG_MAX_MMRS +#define MYNEWT_VAL_MFG_MAX_MMRS (2) +#endif + +#ifndef MYNEWT_VAL_MFG_SYSINIT_STAGE +#define MYNEWT_VAL_MFG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/sys */ +#ifndef MYNEWT_VAL_DEBUG_PANIC_ENABLED +#define MYNEWT_VAL_DEBUG_PANIC_ENABLED (1) +#endif + +/*** @apache-mynewt-core/sys/sysdown */ +#ifndef MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN +#define MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN (1) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE +#define MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_TIMEOUT_MS +#define MYNEWT_VAL_SYSDOWN_TIMEOUT_MS (10000) +#endif + +/*** @apache-mynewt-core/sys/sysinit */ +#ifndef MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT +#define MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT (1) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_MESSAGE +#define MYNEWT_VAL_SYSINIT_PANIC_MESSAGE (0) +#endif + +/*** @apache-mynewt-core/util/rwlock */ +#ifndef MYNEWT_VAL_RWLOCK_DEBUG +#define MYNEWT_VAL_RWLOCK_DEBUG (0) +#endif + +/*** @apache-mynewt-nimble/nimble */ +#ifndef MYNEWT_VAL_BLE_EXT_ADV +#define MYNEWT_VAL_BLE_EXT_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE +#define MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE (31) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_CONNECTIONS +#define MYNEWT_VAL_BLE_MAX_CONNECTIONS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS +#define MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES +#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV +#define MYNEWT_VAL_BLE_PERIODIC_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER +#define MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER (0) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER +#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_CENTRAL +#define MYNEWT_VAL_BLE_ROLE_CENTRAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_OBSERVER +#define MYNEWT_VAL_BLE_ROLE_OBSERVER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_PERIPHERAL +#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_VERSION +#define MYNEWT_VAL_BLE_VERSION (50) +#endif + +#ifndef MYNEWT_VAL_BLE_WHITELIST +#define MYNEWT_VAL_BLE_WHITELIST (1) +#endif + +/*** @apache-mynewt-nimble/nimble/host */ +#ifndef MYNEWT_VAL_BLE_ATT_PREFERRED_MTU +#define MYNEWT_VAL_BLE_ATT_PREFERRED_MTU (256) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_INDICATE +#define MYNEWT_VAL_BLE_ATT_SVR_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES +#define MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES (64) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_NOTIFY +#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ +#define MYNEWT_VAL_BLE_ATT_SVR_READ (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB +#define MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_MULT +#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE +#define MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS +#define MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_INDICATE +#define MYNEWT_VAL_BLE_GATT_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_MAX_PROCS +#define MYNEWT_VAL_BLE_GATT_MAX_PROCS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_NOTIFY +#define MYNEWT_VAL_BLE_GATT_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ +#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_LONG +#define MYNEWT_VAL_BLE_GATT_READ_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MULT +#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_UUID +#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_RESUME_RATE +#define MYNEWT_VAL_BLE_GATT_RESUME_RATE (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_SIGNED_WRITE +#define MYNEWT_VAL_BLE_GATT_SIGNED_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE +#define MYNEWT_VAL_BLE_GATT_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_LONG +#define MYNEWT_VAL_BLE_GATT_WRITE_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE +#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_HOST +#define MYNEWT_VAL_BLE_HOST (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_AUTO_START +#define MYNEWT_VAL_BLE_HS_AUTO_START (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_DEBUG +#define MYNEWT_VAL_BLE_HS_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH (2) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_LVL +#define MYNEWT_VAL_BLE_HS_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_MOD +#define MYNEWT_VAL_BLE_HS_LOG_MOD (4) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS +#define MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_REQUIRE_OS +#define MYNEWT_VAL_BLE_HS_REQUIRE_OS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_HS_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM +#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MPS +#define MYNEWT_VAL_BLE_L2CAP_COC_MPS (MYNEWT_VAL_MSYS_1_BLOCK_SIZE-8) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC +#define MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS +#define MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_MAX_CHANS +#define MYNEWT_VAL_BLE_L2CAP_MAX_CHANS (3*MYNEWT_VAL_BLE_MAX_CONNECTIONS) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT +#define MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS +#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host) */ +#ifndef MYNEWT_VAL_BLE_MESH +#define MYNEWT_VAL_BLE_MESH (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE (128) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT +#define MYNEWT_VAL_BLE_MONITOR_RTT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME ("btmonitor") +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE (256) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART +#define MYNEWT_VAL_BLE_MONITOR_UART (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE +#define MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE (1000000) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE (64) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_DEV +#define MYNEWT_VAL_BLE_MONITOR_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_BLE_RPA_TIMEOUT +#define MYNEWT_VAL_BLE_RPA_TIMEOUT (300) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_BONDING +#define MYNEWT_VAL_BLE_SM_BONDING (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_IO_CAP +#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_NO_INPUT_OUTPUT) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_KEYPRESS +#define MYNEWT_VAL_BLE_SM_KEYPRESS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_LEGACY +#define MYNEWT_VAL_BLE_SM_LEGACY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MAX_PROCS +#define MYNEWT_VAL_BLE_SM_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MITM +#define MYNEWT_VAL_BLE_SM_MITM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG +#define MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OUR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_OUR_KEY_DIST (0) +#endif + +/* Overridden by @apache-mynewt-nimble/nimble/host (defined by @apache-mynewt-nimble/nimble/host) */ +#ifndef MYNEWT_VAL_BLE_SM_SC +#define MYNEWT_VAL_BLE_SM_SC (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS +#define MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_BONDS +#define MYNEWT_VAL_BLE_STORE_MAX_BONDS (3) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_CCCDS +#define MYNEWT_VAL_BLE_STORE_MAX_CCCDS (8) +#endif + +/*** @apache-mynewt-nimble/nimble/host/mesh */ +#ifndef MYNEWT_VAL_BLE_MESH_ACCESS_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_ACCESS_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_ACCESS_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_ACCESS_LOG_MOD (10) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_ADV_BUF_COUNT +#define MYNEWT_VAL_BLE_MESH_ADV_BUF_COUNT (20) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_ADV_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_ADV_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_ADV_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_ADV_LOG_MOD (11) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_ADV_TASK_PRIO +#define MYNEWT_VAL_BLE_MESH_ADV_TASK_PRIO (9) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_APP_KEY_COUNT +#define MYNEWT_VAL_BLE_MESH_APP_KEY_COUNT (4) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_BEACON_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_BEACON_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_BEACON_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_BEACON_LOG_MOD (12) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_CFG_CLI +#define MYNEWT_VAL_BLE_MESH_CFG_CLI (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_CRPL +#define MYNEWT_VAL_BLE_MESH_CRPL (10) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_CRYPTO_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_CRYPTO_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_CRYPTO_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_CRYPTO_LOG_MOD (13) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_DEVICE_NAME +#define MYNEWT_VAL_BLE_MESH_DEVICE_NAME ("nimble-mesh-node") +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_DEV_UUID +#define MYNEWT_VAL_BLE_MESH_DEV_UUID (((uint8_t[16]){0x11, 0x22, 0})) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND +#define MYNEWT_VAL_BLE_MESH_FRIEND (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_FRIEND_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_FRIEND_LOG_MOD (14) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND_LPN_COUNT +#define MYNEWT_VAL_BLE_MESH_FRIEND_LPN_COUNT (2) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND_QUEUE_SIZE +#define MYNEWT_VAL_BLE_MESH_FRIEND_QUEUE_SIZE (16) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND_RECV_WIN +#define MYNEWT_VAL_BLE_MESH_FRIEND_RECV_WIN (255) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND_SEG_RX +#define MYNEWT_VAL_BLE_MESH_FRIEND_SEG_RX (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_FRIEND_SUB_LIST_SIZE +#define MYNEWT_VAL_BLE_MESH_FRIEND_SUB_LIST_SIZE (3) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_GATT_PROXY +#define MYNEWT_VAL_BLE_MESH_GATT_PROXY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_HEALTH_CLI +#define MYNEWT_VAL_BLE_MESH_HEALTH_CLI (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_IVU_DIVIDER +#define MYNEWT_VAL_BLE_MESH_IVU_DIVIDER (4) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_IV_UPDATE_TEST +#define MYNEWT_VAL_BLE_MESH_IV_UPDATE_TEST (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_LABEL_COUNT +#define MYNEWT_VAL_BLE_MESH_LABEL_COUNT (2) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_LOG_MOD (9) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_LOW_POWER +#define MYNEWT_VAL_BLE_MESH_LOW_POWER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LOW_POWER_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_LOW_POWER_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LOW_POWER_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_LOW_POWER_LOG_MOD (15) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_LPN_AUTO +#define MYNEWT_VAL_BLE_MESH_LPN_AUTO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_AUTO_TIMEOUT +#define MYNEWT_VAL_BLE_MESH_LPN_AUTO_TIMEOUT (15) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_ESTABLISHMENT +#define MYNEWT_VAL_BLE_MESH_LPN_ESTABLISHMENT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_GROUPS +#define MYNEWT_VAL_BLE_MESH_LPN_GROUPS (10) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_INIT_POLL_TIMEOUT +#define MYNEWT_VAL_BLE_MESH_LPN_INIT_POLL_TIMEOUT (MYNEWT_VAL_BLE_MESH_LPN_POLL_TIMEOUT) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_MIN_QUEUE_SIZE +#define MYNEWT_VAL_BLE_MESH_LPN_MIN_QUEUE_SIZE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_POLL_TIMEOUT +#define MYNEWT_VAL_BLE_MESH_LPN_POLL_TIMEOUT (300) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_RECV_DELAY +#define MYNEWT_VAL_BLE_MESH_LPN_RECV_DELAY (100) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_RECV_WIN_FACTOR +#define MYNEWT_VAL_BLE_MESH_LPN_RECV_WIN_FACTOR (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_RETRY_TIMEOUT +#define MYNEWT_VAL_BLE_MESH_LPN_RETRY_TIMEOUT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_RSSI_FACTOR +#define MYNEWT_VAL_BLE_MESH_LPN_RSSI_FACTOR (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_LPN_SCAN_LATENCY +#define MYNEWT_VAL_BLE_MESH_LPN_SCAN_LATENCY (10) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_MODEL_EXTENSIONS +#define MYNEWT_VAL_BLE_MESH_MODEL_EXTENSIONS (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_MODEL_GROUP_COUNT +#define MYNEWT_VAL_BLE_MESH_MODEL_GROUP_COUNT (2) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_MODEL_KEY_COUNT +#define MYNEWT_VAL_BLE_MESH_MODEL_KEY_COUNT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_MODEL_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_MODEL_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_MODEL_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_MODEL_LOG_MOD (16) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_MSG_CACHE_SIZE +#define MYNEWT_VAL_BLE_MESH_MSG_CACHE_SIZE (10) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_NET_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_NET_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_NET_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_NET_LOG_MOD (17) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_NODE_COUNT +#define MYNEWT_VAL_BLE_MESH_NODE_COUNT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_NODE_ID_TIMEOUT +#define MYNEWT_VAL_BLE_MESH_NODE_ID_TIMEOUT (60) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_OOB_INPUT_ACTIONS +#define MYNEWT_VAL_BLE_MESH_OOB_INPUT_ACTIONS (((BT_MESH_NO_INPUT))) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_OOB_INPUT_SIZE +#define MYNEWT_VAL_BLE_MESH_OOB_INPUT_SIZE (4) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_OOB_OUTPUT_ACTIONS +#define MYNEWT_VAL_BLE_MESH_OOB_OUTPUT_ACTIONS (((BT_MESH_DISPLAY_NUMBER))) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_OOB_OUTPUT_SIZE +#define MYNEWT_VAL_BLE_MESH_OOB_OUTPUT_SIZE (4) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_PB_ADV +#define MYNEWT_VAL_BLE_MESH_PB_ADV (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_PB_GATT +#define MYNEWT_VAL_BLE_MESH_PB_GATT (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_PROV +#define MYNEWT_VAL_BLE_MESH_PROV (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_PROVISIONER +#define MYNEWT_VAL_BLE_MESH_PROVISIONER (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_PROV_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_PROV_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_PROV_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_PROV_LOG_MOD (18) +#endif + +/* Overridden by @apache-mynewt-nimble/nimble/host/mesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_PROXY +#define MYNEWT_VAL_BLE_MESH_PROXY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_PROXY_FILTER_SIZE +#define MYNEWT_VAL_BLE_MESH_PROXY_FILTER_SIZE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_PROXY_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_PROXY_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_PROXY_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_PROXY_LOG_MOD (19) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_RELAY +#define MYNEWT_VAL_BLE_MESH_RELAY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_RPL_STORE_TIMEOUT +#define MYNEWT_VAL_BLE_MESH_RPL_STORE_TIMEOUT (5) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_RX_SDU_MAX +#define MYNEWT_VAL_BLE_MESH_RX_SDU_MAX (72) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_RX_SEG_MSG_COUNT +#define MYNEWT_VAL_BLE_MESH_RX_SEG_MSG_COUNT (2) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_SEG_RETRANSMIT_ATTEMPTS +#define MYNEWT_VAL_BLE_MESH_SEG_RETRANSMIT_ATTEMPTS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_SEQ_STORE_RATE +#define MYNEWT_VAL_BLE_MESH_SEQ_STORE_RATE (128) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_SETTINGS +#define MYNEWT_VAL_BLE_MESH_SETTINGS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_SETTINGS_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_SETTINGS_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_SETTINGS_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_SETTINGS_LOG_MOD (20) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_SHELL +#define MYNEWT_VAL_BLE_MESH_SHELL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_SHELL_MODELS +#define MYNEWT_VAL_BLE_MESH_SHELL_MODELS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_STORE_TIMEOUT +#define MYNEWT_VAL_BLE_MESH_STORE_TIMEOUT (2) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_SUBNET_COUNT +#define MYNEWT_VAL_BLE_MESH_SUBNET_COUNT (2) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_MESH_SYSINIT_STAGE (500) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_SYSINIT_STAGE_SHELL +#define MYNEWT_VAL_BLE_MESH_SYSINIT_STAGE_SHELL (1000) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_TESTING +#define MYNEWT_VAL_BLE_MESH_TESTING (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_TRANS_LOG_LVL +#define MYNEWT_VAL_BLE_MESH_TRANS_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_TRANS_LOG_MOD +#define MYNEWT_VAL_BLE_MESH_TRANS_LOG_MOD (21) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/host/mesh) */ +#ifndef MYNEWT_VAL_BLE_MESH_TX_SEG_MAX +#define MYNEWT_VAL_BLE_MESH_TX_SEG_MAX (6) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH_TX_SEG_MSG_COUNT +#define MYNEWT_VAL_BLE_MESH_TX_SEG_MSG_COUNT (4) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ans */ +#ifndef MYNEWT_VAL_BLE_SVC_ANS_NEW_ALERT_CAT +#define MYNEWT_VAL_BLE_SVC_ANS_NEW_ALERT_CAT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_ANS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_ANS_SYSINIT_STAGE (303) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_ANS_UNR_ALERT_CAT +#define MYNEWT_VAL_BLE_SVC_ANS_UNR_ALERT_CAT (0) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/bas */ +#ifndef MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_NOTIFY_ENABLE +#define MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_NOTIFY_ENABLE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_READ_PERM +#define MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_READ_PERM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_BAS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_BAS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/dis */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_DEFAULT_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_DEFAULT_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_DEFAULT ("Apache Mynewt NimBLE") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_READ_PERM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_DIS_SYSINIT_STAGE (303) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_READ_PERM (-1) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gap */ +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION +#define MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME ("nimble") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH (31) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE (301) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gatt */ +#ifndef MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE (302) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ias */ +#ifndef MYNEWT_VAL_BLE_SVC_IAS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_IAS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ipss */ +#ifndef MYNEWT_VAL_BLE_SVC_IPSS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_IPSS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/lls */ +#ifndef MYNEWT_VAL_BLE_SVC_LLS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_LLS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/tps */ +#ifndef MYNEWT_VAL_BLE_SVC_TPS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_TPS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/transport/socket */ +#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT +#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24) +#endif + +#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE +#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT +#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE +#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE (500) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_LINUX_DEV +#define MYNEWT_VAL_BLE_SOCK_LINUX_DEV (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_STACK_SIZE +#define MYNEWT_VAL_BLE_SOCK_STACK_SIZE (1028) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_TASK_PRIO +#define MYNEWT_VAL_BLE_SOCK_TASK_PRIO (3) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_TCP_PORT +#define MYNEWT_VAL_BLE_SOCK_TCP_PORT (14433) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_USE_LINUX_BLUE +#define MYNEWT_VAL_BLE_SOCK_USE_LINUX_BLUE (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/linux_blemesh (defined by @apache-mynewt-nimble/nimble/transport/socket) */ +#ifndef MYNEWT_VAL_BLE_SOCK_USE_TCP +#define MYNEWT_VAL_BLE_SOCK_USE_TCP (0) +#endif + +/*** newt */ +#ifndef MYNEWT_VAL_APP_NAME +#define MYNEWT_VAL_APP_NAME ("dummy_app") +#endif + +#ifndef MYNEWT_VAL_APP_dummy_app +#define MYNEWT_VAL_APP_dummy_app (1) +#endif + +#ifndef MYNEWT_VAL_ARCH_NAME +#define MYNEWT_VAL_ARCH_NAME ("dummy") +#endif + +#ifndef MYNEWT_VAL_ARCH_dummy +#define MYNEWT_VAL_ARCH_dummy (1) +#endif + +#ifndef MYNEWT_VAL_BSP_NAME +#define MYNEWT_VAL_BSP_NAME ("dummy_bsp") +#endif + +#ifndef MYNEWT_VAL_BSP_dummy_bsp +#define MYNEWT_VAL_BSP_dummy_bsp (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_LOGCFG +#define MYNEWT_VAL_NEWT_FEATURE_LOGCFG (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_SYSDOWN +#define MYNEWT_VAL_NEWT_FEATURE_SYSDOWN (1) +#endif + +#ifndef MYNEWT_VAL_TARGET_NAME +#define MYNEWT_VAL_TARGET_NAME ("linux_blemesh") +#endif + +#ifndef MYNEWT_VAL_TARGET_linux_blemesh +#define MYNEWT_VAL_TARGET_linux_blemesh (1) +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/sysflash/sysflash.h b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/sysflash/sysflash.h new file mode 100644 index 00000000..413cb267 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/include/sysflash/sysflash.h @@ -0,0 +1,24 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSFLASH_ +#define H_MYNEWT_SYSFLASH_ + +#include "flash_map/flash_map.h" + +/** + * This flash map definition is used for two purposes: + * 1. To locate the meta area, which contains the true flash map definition. + * 2. As a fallback in case the meta area cannot be read from flash. + */ +extern const struct flash_area sysflash_map_dflt[6]; + +#define FLASH_AREA_BOOTLOADER 0 +#define FLASH_AREA_IMAGE_0 1 +#define FLASH_AREA_IMAGE_1 2 +#define FLASH_AREA_IMAGE_SCRATCH 3 +#define FLASH_AREA_REBOOT_LOG 16 +#define FLASH_AREA_NFFS 17 + +#endif diff --git a/src/libs/mynewt-nimble/porting/examples/linux_blemesh/main.c b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/main.c new file mode 100644 index 00000000..0913551e --- /dev/null +++ b/src/libs/mynewt-nimble/porting/examples/linux_blemesh/main.c @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdbool.h> +#include <stdint.h> +#include <stdlib.h> + +#include <pthread.h> +#include "nimble/nimble_npl.h" +#include "nimble/nimble_port.h" + +#include "mesh/glue.h" +#include "mesh/porting.h" + +#include "services/gap/ble_svc_gap.h" +#include "services/gatt/ble_svc_gatt.h" + +static struct ble_npl_task s_task_host; +static struct ble_npl_task s_task_hci; +static struct ble_npl_task s_task_mesh_adv; + +void nimble_host_task(void *param); +void ble_hci_sock_ack_handler(void *param); +void ble_hci_sock_init(void); + +#define TASK_DEFAULT_PRIORITY 1 +#define TASK_DEFAULT_STACK NULL +#define TASK_DEFAULT_STACK_SIZE 400 + +void *ble_hci_sock_task(void *param) +{ + ble_hci_sock_ack_handler(param); + return NULL; +} + +void *ble_host_task(void *param) +{ + nimble_host_task(param); + return NULL; +} + +void *ble_mesh_adv_task(void *param) +{ + mesh_adv_thread(param); + return NULL; +} + +void mesh_initialized(void) +{ + ble_npl_task_init(&s_task_mesh_adv, "ble_mesh_adv", ble_mesh_adv_task, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, + TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); +} + +int main(int argc, char *argv[]) +{ + int ret = 0; + + /* allow to specify custom hci */ + if (argc > 1) { + ble_hci_sock_set_device(atoi(argv[1])); + } + + ble_hci_sock_init(); + nimble_port_init(); + + ble_svc_gap_init(); + ble_svc_gatt_init(); + bt_mesh_register_gatt(); + + /* XXX Need to have template for store */ + ble_store_ram_init(); + + ble_npl_task_init(&s_task_hci, "hci_sock", ble_hci_sock_task, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, + TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); + + /* Create task which handles default event queue for host stack. */ + ble_npl_task_init(&s_task_host, "ble_host", ble_host_task, + NULL, TASK_DEFAULT_PRIORITY, BLE_NPL_TIME_FOREVER, + TASK_DEFAULT_STACK, TASK_DEFAULT_STACK_SIZE); + + pthread_exit(&ret); +} diff --git a/src/libs/mynewt-nimble/porting/nimble/Makefile.controller b/src/libs/mynewt-nimble/porting/nimble/Makefile.controller new file mode 100644 index 00000000..8479ac1c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/Makefile.controller @@ -0,0 +1,32 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +NIMBLE_CFLAGS += \ + -DNIMBLE_CFG_CONTROLLER=1 \ + +NIMBLE_INCLUDE += \ + $(NIMBLE_ROOT)/nimble/transport/ram/include \ + $(NIMBLE_ROOT)/nimble/controller/include \ + $(NIMBLE_ROOT)/nimble/drivers/nrf52/include \ + $(NULL) + +NIMBLE_SRC += \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/transport/ram/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/controller/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/drivers/nrf52/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/porting/nimble/controller/src/*.c)) \ + $(NULL) diff --git a/src/libs/mynewt-nimble/porting/nimble/Makefile.defs b/src/libs/mynewt-nimble/porting/nimble/Makefile.defs new file mode 100644 index 00000000..ffb531fb --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/Makefile.defs @@ -0,0 +1,68 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +ifeq (,$(NIMBLE_ROOT)) +$(error NIMBLE_ROOT shall be defined) +endif + +NIMBLE_CFLAGS := + +NIMBLE_INCLUDE := \ + $(NIMBLE_ROOT)/nimble/include \ + $(NIMBLE_ROOT)/nimble/host/include \ + $(NIMBLE_ROOT)/nimble/host/services/ans/include \ + $(NIMBLE_ROOT)/nimble/host/services/bas/include \ + $(NIMBLE_ROOT)/nimble/host/services/bleuart/include \ + $(NIMBLE_ROOT)/nimble/host/services/gap/include \ + $(NIMBLE_ROOT)/nimble/host/services/gatt/include \ + $(NIMBLE_ROOT)/nimble/host/services/ias/include \ + $(NIMBLE_ROOT)/nimble/host/services/lls/include \ + $(NIMBLE_ROOT)/nimble/host/services/tps/include \ + $(NIMBLE_ROOT)/nimble/host/store/ram/include \ + $(NIMBLE_ROOT)/nimble/host/util/include \ + $(NIMBLE_ROOT)/porting/nimble/include \ + $(NULL) + +NIMBLE_SRC := \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/porting/nimble/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/util/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/ans/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/bas/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/gap/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/gatt/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/ias/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/lls/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/services/tps/src/*.c)) \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/store/ram/src/*.c)) \ + $(NULL) + +ifneq (,$(NIMBLE_CFG_CONTROLLER)) +include $(NIMBLE_ROOT)/porting/nimble/Makefile.controller +endif + +# TinyCrypt (for SM) +ifneq (,$(NIMBLE_CFG_TINYCRYPT)) +include $(NIMBLE_ROOT)/porting/nimble/Makefile.tinycrypt +endif + +ifneq (,$(NIMBLE_CFG_MESH)) +include $(NIMBLE_ROOT)/porting/nimble/Makefile.mesh +endif + +NIMBLE_OBJ := $(NIMBLE_SRC:.c=.o) diff --git a/src/libs/mynewt-nimble/porting/nimble/Makefile.mesh b/src/libs/mynewt-nimble/porting/nimble/Makefile.mesh new file mode 100644 index 00000000..e7f6ccec --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/Makefile.mesh @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +NIMBLE_INCLUDE += \ + $(NIMBLE_ROOT)/nimble/host/mesh/include \ + $(NULL) + +NIMBLE_SRC += \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/nimble/host/mesh/src/*.c)) \ + $(NULL) diff --git a/src/libs/mynewt-nimble/porting/nimble/Makefile.tinycrypt b/src/libs/mynewt-nimble/porting/nimble/Makefile.tinycrypt new file mode 100644 index 00000000..2333e618 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/Makefile.tinycrypt @@ -0,0 +1,26 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +TINYCRYPT_CFLAGS := -std=c99 + +TINYCRYPT_INCLUDE := \ + $(NIMBLE_ROOT)/ext/tinycrypt/include \ + $(NULL) + +TINYCRYPT_SRC := \ + $(filter-out $(NIMBLE_IGNORE), $(wildcard $(NIMBLE_ROOT)/ext/tinycrypt/src/*.c)) \ + $(NULL) diff --git a/src/libs/mynewt-nimble/porting/nimble/include/hal/hal_timer.h b/src/libs/mynewt-nimble/porting/nimble/include/hal/hal_timer.h new file mode 100644 index 00000000..be41c609 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/hal/hal_timer.h @@ -0,0 +1,173 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +/** + * @addtogroup HAL + * @{ + * @defgroup HALTimer HAL Timer + * @{ + */ + +#ifndef H_HAL_TIMER_ +#define H_HAL_TIMER_ + +#include <inttypes.h> +#include "os/queue.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* HAL timer callback */ +typedef void (*hal_timer_cb)(void *arg); + +/** + * The HAL timer structure. The user can declare as many of these structures + * as desired. They are enqueued on a particular HW timer queue when the user + * calls the :c:func:`hal_timer_start()` or :c:func:`hal_timer_start_at()` API. + * The user must have called :c:func:`hal_timer_set_cb()` before starting a + * timer. + * + * NOTE: the user should not have to modify/examine the contents of this + * structure; the hal timer API should be used. + */ +struct hal_timer { + /** Internal platform specific pointer */ + void *bsp_timer; + /** Callback function */ + hal_timer_cb cb_func; + /** Callback argument */ + void *cb_arg; + /** Tick at which timer should expire */ + uint32_t expiry; + TAILQ_ENTRY(hal_timer) link; /* Queue linked list structure */ +}; + +/** + * Initialize a HW timer. + * + * @param timer_num The number of the HW timer to initialize + * @param cfg Hardware specific timer configuration. This is + * passed from BSP directly to the MCU specific driver. + */ +int hal_timer_init(int timer_num, void *cfg); + +/** + * Un-initialize a HW timer. + * + * @param timer_num The number of the HW timer to un-initialize + */ +int hal_timer_deinit(int timer_num); + +/** + * Config a HW timer at the given frequency and start it. If the exact + * frequency is not obtainable the closest obtainable frequency is set. + * + * @param timer_num The number of the HW timer to configure + * @param freq_hz The frequency in Hz to configure the timer at + * + * @return 0 on success, non-zero error code on failure + */ +int hal_timer_config(int timer_num, uint32_t freq_hz); + +/** + * Returns the resolution of the HW timer. NOTE: the frequency may not be + * obtainable so the caller can use this to determine the resolution. + * Returns resolution in nanoseconds. A return value of 0 indicates an invalid + * timer was used. + * + * @param timer_num The number of the HW timer to get resolution for + * + * @return The resolution of the timer + */ +uint32_t hal_timer_get_resolution(int timer_num); + +/** + * Returns the HW timer current tick value + * + * @param timer_num The HW timer to read the tick value from + * + * @return The current tick value + */ +uint32_t hal_timer_read(int timer_num); + +/** + * Perform a blocking delay for a number of ticks. + * + * @param timer_num The timer number to use for the blocking delay + * @param ticks The number of ticks to delay for + * + * @return 0 on success, non-zero error code on failure + */ +int hal_timer_delay(int timer_num, uint32_t ticks); + +/** + * Set the timer structure prior to use. Should not be called if the timer + * is running. Must be called at least once prior to using timer. + * + * @param timer_num The number of the HW timer to configure the callback on + * @param tmr The timer structure to use for this timer + * @param cb_func The timer callback to call when the timer fires + * @param arg An opaque argument to provide the timer callback + * + * @return 0 on success, non-zero error code on failure. + */ +int hal_timer_set_cb(int timer_num, struct hal_timer *tmr, hal_timer_cb cb_func, + void *arg); + +/** + * Start a timer that will expire in 'ticks' ticks. Ticks cannot be 0 + * + * @param tmr The timer to start + * @param ticks The number of ticks to expire the timer in + * + * @return 0 on success, non-zero error code on failure. + */ +int hal_timer_start(struct hal_timer *tmr, uint32_t ticks); + +/** + * Start a timer that will expire when the timer reaches 'tick'. If tick + * has already passed the timer callback will be called "immediately" (at + * interrupt context). + * + * @param tmr The timer to start + * @param tick The absolute tick value to fire the timer at + * + * @return 0 on success, non-zero error code on failure. + */ +int hal_timer_start_at(struct hal_timer *tmr, uint32_t tick); + +/** + * Stop a currently running timer; associated callback will NOT be called + * + * @param tmr The timer to stop + */ +int hal_timer_stop(struct hal_timer *tmr); + +#ifdef __cplusplus +} +#endif + +#endif /* H_HAL_TIMER_ */ + +/** + * @} HALTimer + * @} HAL + */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/log/log.h b/src/libs/mynewt-nimble/porting/nimble/include/log/log.h new file mode 100644 index 00000000..004667cc --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/log/log.h @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef __LOG_H__ +#define __LOG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +static inline void +log_dummy(void *log, ...) +{ + (void)log; +} + +#define LOG_DEBUG(_log, _mod, ...) NRF_LOG_DEBUG(## __VA_ARGS__) +#define LOG_INFO(_log, _mod, ...) log_dummy(_log, ## __VA_ARGS__) +#define LOG_WARN(_log, _mod, ...) log_dummy(_log, ## __VA_ARGS__) +#define LOG_ERROR(_log, _mod, ...) log_dummy(_log, ## __VA_ARGS__) +#define LOG_CRITICAL(_log, _mod, ...) log_dummy(_log, ## __VA_ARGS__) + +struct log { +}; + +#ifdef __cplusplus +} +#endif + +#endif /* __LOG_H__ */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/log_common/ignore.h b/src/libs/mynewt-nimble/porting/nimble/include/log_common/ignore.h new file mode 100644 index 00000000..46282a02 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/log_common/ignore.h @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_IGNORE_ +#define H_IGNORE_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * These macros prevent the "set but not used" warnings for log writes below + * the log level. + */ + +#define IGN_1(X) ((void)(X)) +#define IGN_2(X, ...) ((void)(X));IGN_1(__VA_ARGS__) +#define IGN_3(X, ...) ((void)(X));IGN_2(__VA_ARGS__) +#define IGN_4(X, ...) ((void)(X));IGN_3(__VA_ARGS__) +#define IGN_5(X, ...) ((void)(X));IGN_4(__VA_ARGS__) +#define IGN_6(X, ...) ((void)(X));IGN_5(__VA_ARGS__) +#define IGN_7(X, ...) ((void)(X));IGN_6(__VA_ARGS__) +#define IGN_8(X, ...) ((void)(X));IGN_7(__VA_ARGS__) +#define IGN_9(X, ...) ((void)(X));IGN_8(__VA_ARGS__) +#define IGN_10(X, ...) ((void)(X));IGN_9(__VA_ARGS__) +#define IGN_11(X, ...) ((void)(X));IGN_10(__VA_ARGS__) +#define IGN_12(X, ...) ((void)(X));IGN_11(__VA_ARGS__) +#define IGN_13(X, ...) ((void)(X));IGN_12(__VA_ARGS__) +#define IGN_14(X, ...) ((void)(X));IGN_13(__VA_ARGS__) +#define IGN_15(X, ...) ((void)(X));IGN_14(__VA_ARGS__) +#define IGN_16(X, ...) ((void)(X));IGN_15(__VA_ARGS__) +#define IGN_17(X, ...) ((void)(X));IGN_16(__VA_ARGS__) +#define IGN_18(X, ...) ((void)(X));IGN_17(__VA_ARGS__) +#define IGN_19(X, ...) ((void)(X));IGN_18(__VA_ARGS__) +#define IGN_20(X, ...) ((void)(X));IGN_19(__VA_ARGS__) + +#define GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \ + _13, _14, _15, _16, _17, _18, _19, _20, NAME, ...) NAME +#define IGNORE(...) \ + GET_MACRO(__VA_ARGS__, IGN_20, IGN_19, IGN_18, IGN_17, IGN_16, IGN_15, \ + IGN_14, IGN_13, IGN_12, IGN_11, IGN_10, IGN_9, IGN_8, IGN_7, \ + IGN_6, IGN_5, IGN_4, IGN_3, IGN_2, IGN_1)(__VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/log_common/log_common.h b/src/libs/mynewt-nimble/porting/nimble/include/log_common/log_common.h new file mode 100644 index 00000000..106d02d7 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/log_common/log_common.h @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_LOG_COMMON_ +#define H_LOG_COMMON_ + +#include "log_common/ignore.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define LOG_LEVEL_DEBUG (0) +#define LOG_LEVEL_INFO (1) +#define LOG_LEVEL_WARN (2) +#define LOG_LEVEL_ERROR (3) +#define LOG_LEVEL_CRITICAL (4) +/* Up to 7 custom log levels. */ +#define LOG_LEVEL_MAX (15) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/logcfg/logcfg.h b/src/libs/mynewt-nimble/porting/nimble/include/logcfg/logcfg.h new file mode 100644 index 00000000..6119ecfa --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/logcfg/logcfg.h @@ -0,0 +1,42 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_LOGCFG_ +#define H_MYNEWT_LOGCFG_ + +#include "modlog/modlog.h" +#include "log_common/log_common.h" +#include <libraries/log/nrf_log.h> + +#if 1 +#define BLE_HS_LOG_DEBUG(...) NRF_LOG_DEBUG(__VA_ARGS__) +#define BLE_HS_LOG_INFO(...) NRF_LOG_INFO(__VA_ARGS__) +#define BLE_HS_LOG_WARN(...) NRF_LOG_WARNING( __VA_ARGS__) +#define BLE_HS_LOG_ERROR(...) NRF_LOG_ERROR(__VA_ARGS__) +#define BLE_HS_LOG_CRITICAL(...) MODLOG_CRITICAL(4, __VA_ARGS__) +#define BLE_HS_LOG_DISABLED(...) MODLOG_DISABLED(4, __VA_ARGS__) +#endif +#if 0 +#define BLE_HS_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_HS_LOG_INFO(...) MODLOG_INFO(4, __VA_ARGS__) +#define BLE_HS_LOG_WARN(...) MODLOG_WARN(4, __VA_ARGS__) +#define BLE_HS_LOG_ERROR(...) MODLOG_ERROR(4, __VA_ARGS__) +#define BLE_HS_LOG_CRITICAL(...) MODLOG_CRITICAL(4, __VA_ARGS__) +#define BLE_HS_LOG_DISABLED(...) MODLOG_DISABLED(4, __VA_ARGS__) +#endif +#define DFLT_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define DFLT_LOG_INFO(...) MODLOG_INFO(0, __VA_ARGS__) +#define DFLT_LOG_WARN(...) MODLOG_WARN(0, __VA_ARGS__) +#define DFLT_LOG_ERROR(...) MODLOG_ERROR(0, __VA_ARGS__) +#define DFLT_LOG_CRITICAL(...) MODLOG_CRITICAL(0, __VA_ARGS__) +#define DFLT_LOG_DISABLED(...) MODLOG_DISABLED(0, __VA_ARGS__) + +#define MFG_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_INFO(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_WARN(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_ERROR(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_CRITICAL(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_DISABLED(...) MODLOG_DISABLED(128, __VA_ARGS__) + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/mem/mem.h b/src/libs/mynewt-nimble/porting/nimble/include/mem/mem.h new file mode 100644 index 00000000..a97e148f --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/mem/mem.h @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_UTIL_MEM_ +#define H_UTIL_MEM_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct os_mempool; +struct os_mbuf_pool; + +int mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks, + uint32_t block_size, char *name, void **out_buf); +int mem_malloc_mempool_ext(struct os_mempool_ext *mempool, uint16_t num_blocks, + uint32_t block_size, char *name, void **out_buf); + +int mem_malloc_mbuf_pool(struct os_mempool *mempool, + struct os_mbuf_pool *mbuf_pool, uint16_t num_blocks, + uint32_t block_size, char *name, + void **out_buf); +int mem_malloc_mbufpkt_pool(struct os_mempool *mempool, + struct os_mbuf_pool *mbuf_pool, int num_blocks, + int block_size, char *name, + void **out_buf); +int mem_init_mbuf_pool(void *mem, struct os_mempool *mempool, + struct os_mbuf_pool *mbuf_pool, int num_blocks, + int block_size, char *name); + +/** + * Specifies a function used as a callback. Functions of this type allocate an + * mbuf chain meant to hold a packet fragment. The resulting mbuf must contain + * a pkthdr. + * + * @param frag_size The number of data bytes that the mbuf will + * eventually contain. + * @param arg A generic parameter. + * + * @return An allocated mbuf chain on success; + * NULL on failure. + */ +typedef struct os_mbuf *mem_frag_alloc_fn(uint16_t frag_size, void *arg); + +struct os_mbuf *mem_split_frag(struct os_mbuf **om, uint16_t max_frag_sz, + mem_frag_alloc_fn *alloc_cb, void *cb_arg); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/modlog/modlog.h b/src/libs/mynewt-nimble/porting/nimble/include/modlog/modlog.h new file mode 100644 index 00000000..29b1e8f0 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/modlog/modlog.h @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_MODLOG_ +#define H_MODLOG_ + +#include <stdio.h> + +#include "log/log.h" + +#define MODLOG_MODULE_DFLT 255 + +#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_DEBUG || defined __DOXYGEN__ +#define MODLOG_DEBUG(ml_mod_, ml_msg_, ...) \ + printf((ml_msg_), ##__VA_ARGS__) +#else +#define MODLOG_DEBUG(ml_mod_, ...) IGNORE(__VA_ARGS__) +#endif + +#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_INFO || defined __DOXYGEN__ +#define MODLOG_INFO(ml_mod_, ml_msg_, ...) \ + printf((ml_msg_), ##__VA_ARGS__) +#else +#define MODLOG_INFO(ml_mod_, ...) IGNORE(__VA_ARGS__) +#endif + +#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_WARN || defined __DOXYGEN__ +#define MODLOG_WARN(ml_mod_, ml_msg_, ...) \ + printf((ml_msg_), ##__VA_ARGS__) +#else +#define MODLOG_WARN(ml_mod_, ...) IGNORE(__VA_ARGS__) +#endif + +#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_ERROR || defined __DOXYGEN__ +#define MODLOG_ERROR(ml_mod_, ml_msg_, ...) \ + printf((ml_msg_), ##__VA_ARGS__) +#else +#define MODLOG_ERROR(ml_mod_, ...) IGNORE(__VA_ARGS__) +#endif + +#if MYNEWT_VAL(LOG_LEVEL) <= LOG_LEVEL_CRITICAL || defined __DOXYGEN__ +#define MODLOG_CRITICAL(ml_mod_, ml_msg_, ...) \ + printf((ml_msg_), ##__VA_ARGS__) +#else +#define MODLOG_CRITICAL(ml_mod_, ...) IGNORE(__VA_ARGS__) +#endif + +#define MODLOG(ml_lvl_, ml_mod_, ...) \ + MODLOG_ ## ml_lvl_((ml_mod_), __VA_ARGS__) + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/nimble/nimble_port.h b/src/libs/mynewt-nimble/porting/nimble/include/nimble/nimble_port.h new file mode 100644 index 00000000..28065cf8 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/nimble/nimble_port.h @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_PORT_H +#define _NIMBLE_PORT_H + +#include "nimble/nimble_npl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void nimble_port_init(void); + +void nimble_port_run(void); + +struct ble_npl_eventq *nimble_port_get_dflt_eventq(void); + +#if NIMBLE_CFG_CONTROLLER +void nimble_port_ll_task_func(void *arg); +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _NIMBLE_PORT_H */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/endian.h b/src/libs/mynewt-nimble/porting/nimble/include/os/endian.h new file mode 100644 index 00000000..e0230756 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/endian.h @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_ENDIAN_ +#define H_ENDIAN_ + +#include <inttypes.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/* Internal helpers */ +#ifndef os_bswap_64 +#define os_bswap_64(x) ((uint64_t) \ + ((((x) & 0xff00000000000000ull) >> 56) | \ + (((x) & 0x00ff000000000000ull) >> 40) | \ + (((x) & 0x0000ff0000000000ull) >> 24) | \ + (((x) & 0x000000ff00000000ull) >> 8) | \ + (((x) & 0x00000000ff000000ull) << 8) | \ + (((x) & 0x0000000000ff0000ull) << 24) | \ + (((x) & 0x000000000000ff00ull) << 40) | \ + (((x) & 0x00000000000000ffull) << 56))) +#endif + +#ifndef os_bswap_32 +#define os_bswap_32(x) ((uint32_t) \ + ((((x) & 0xff000000) >> 24) | \ + (((x) & 0x00ff0000) >> 8) | \ + (((x) & 0x0000ff00) << 8) | \ + (((x) & 0x000000ff) << 24))) +#endif + +#ifndef os_bswap_16 +#define os_bswap_16(x) ((uint16_t) \ + ((((x) & 0xff00) >> 8) | \ + (((x) & 0x00ff) << 8))) +#endif + +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ + +#ifndef ntohll +#define ntohll(x) ((uint64_t)(x)) +#endif + +#ifndef htonll +#define htonll(x) ((uint64_t)(x)) +#endif + +#ifndef ntohl +#define ntohl(x) ((uint32_t)(x)) +#endif + +#ifndef htonl +#define htonl(x) ((uint32_t)(x)) +#endif + +#ifndef ntohs +#define ntohs(x) ((uint16_t)(x)) +#endif + +#ifndef htons +#define htons(x) ((uint16_t)(x)) +#endif + +#ifndef htobe16 +#define htobe16(x) ((uint16_t)(x)) +#endif + +#ifndef htole16 +#define htole16(x) os_bswap_16 (x) +#endif + +#ifndef be16toh +#define be16toh(x) ((uint16_t)(x)) +#endif + +#ifndef le16toh +#define le16toh(x) os_bswap_16 (x) +#endif + +#ifndef htobe32 +#define htobe32(x) ((uint32_t)(x)) +#endif + +#ifndef htole32 +#define htole32(x) os_bswap_32 (x) +#endif + +#ifndef be32toh +#define be32toh(x) ((uint32_t)(x)) +#endif + +#ifndef le32toh +#define le32toh(x) os_bswap_32 (x) +#endif + +#ifndef htobe64 +#define htobe64(x) ((uint64_t)(x)) +#endif + +#ifndef htole64 +#define htole64(x) os_bswap_64 (x) +#endif + +#ifndef be64toh +#define be64toh(x) ((uint64_t)(x)) +#endif + +#ifndef le64toh +#define le64toh(x) os_bswap_64 (x) +#endif + +#else + +#ifndef ntohll +#define ntohll(x) os_bswap_64(x) +#endif + +#ifndef htonll +#define htonll ntohll +#endif + +#ifndef ntohl +#define ntohl(x) os_bswap_32(x) +#endif + +#ifndef htonl +#define htonl ntohl +#endif + +#ifndef htons +#define htons(x) os_bswap_16(x) +#endif + +#ifndef ntohs +#define ntohs htons +#endif + +#ifndef htobe16 +#define htobe16(x) os_bswap_16(x) +#endif + +#ifndef htole16 +#define htole16(x) ((uint16_t)(x)) +#endif + +#ifndef be16toh +#define be16toh(x) os_bswap_16(x) +#endif + +#ifndef le16toh +#define le16toh(x) ((uint16_t)(x)) +#endif + +#ifndef htobe32 +#define htobe32(x) os_bswap_32(x) +#endif + +#ifndef htole32 +#define htole32(x) ((uint32_t)(x)) +#endif + +#ifndef be32toh +#define be32toh(x) os_bswap_32(x) +#endif + +#ifndef le32toh +#define le32toh(x) ((uint32_t)(x)) +#endif + +#ifndef htobe64 +#define htobe64(x) os_bswap64(x) +#endif + +#ifndef htole64 +#define htole64(x) ((uint64_t)(x)) +#endif + +#ifndef be64toh +#define be64toh(x) os_bswap64(x) +#endif + +#ifndef le64toh +#define le64toh(x) ((uint64_t)(x)) +#endif + +#endif + +void put_le16(void *buf, uint16_t x); +void put_le24(void *buf, uint32_t x); +void put_le32(void *buf, uint32_t x); +void put_le64(void *buf, uint64_t x); +uint16_t get_le16(const void *buf); +uint32_t get_le24(const void *buf); +uint32_t get_le32(const void *buf); +uint64_t get_le64(const void *buf); +void put_be16(void *buf, uint16_t x); +void put_be24(void *buf, uint32_t x); +void put_be32(void *buf, uint32_t x); +void put_be64(void *buf, uint64_t x); +uint16_t get_be16(const void *buf); +uint32_t get_be24(const void *buf); +uint32_t get_be32(const void *buf); +uint64_t get_be64(const void *buf); +void swap_in_place(void *buf, int len); +void swap_buf(uint8_t *dst, const uint8_t *src, int len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/os.h b/src/libs/mynewt-nimble/porting/nimble/include/os/os.h new file mode 100644 index 00000000..f7a7ef9c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/os.h @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _OS_H +#define _OS_H + +#include <assert.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef min +#define min(a, b) ((a)<(b)?(a):(b)) +#endif + +#ifndef max +#define max(a, b) ((a)>(b)?(a):(b)) +#endif + +#include "syscfg/syscfg.h" +#include "nimble/nimble_npl.h" + +#define OS_ALIGN(__n, __a) ( \ + (((__n) & ((__a) - 1)) == 0) ? \ + (__n) : \ + ((__n) + ((__a) - ((__n) & ((__a) - 1)))) \ + ) +#define OS_ALIGNMENT (BLE_NPL_OS_ALIGNMENT) + +typedef uint32_t os_sr_t; +#define OS_ENTER_CRITICAL(_sr) (_sr = ble_npl_hw_enter_critical()) +#define OS_EXIT_CRITICAL(_sr) (ble_npl_hw_exit_critical(_sr)) +#define OS_ASSERT_CRITICAL() assert(ble_npl_hw_is_in_critical()) + +/* Mynewt components (not abstracted in NPL) */ +#include "os/endian.h" +#include "os/queue.h" +#include "os/os_error.h" +#include "os/os_mbuf.h" +#include "os/os_mempool.h" + +#ifdef __cplusplus +} +#endif + +#endif /* _OS_H */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/os_cputime.h b/src/libs/mynewt-nimble/porting/nimble/include/os/os_cputime.h new file mode 100644 index 00000000..20124b57 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/os_cputime.h @@ -0,0 +1,240 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + /** + * @addtogroup OSKernel + * @{ + * @defgroup OSCPUTime High Resolution Timers + * @{ + */ + +#ifndef H_OS_CPUTIME_ +#define H_OS_CPUTIME_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "syscfg/syscfg.h" +#include "hal/hal_timer.h" +#include "os/os.h" + +/* + * NOTE: these definitions allow one to override the cputime frequency used. + * The reason these definitions exist is to make the code more + * efficient/smaller when CPUTIME counts at 1 MHz. + * + * For those who want a different cputime frequency, you can set the config + * definition for OS_CPUTIME_FREQ to the desired frequency in your project, + * target or bsp. + */ +#if (MYNEWT_VAL(OS_CPUTIME_FREQ) == 1000000) + +#define OS_CPUTIME_FREQ_1MHZ + +#elif MYNEWT_VAL(OS_CPUTIME_FREQ) == 256 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 512 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 1024 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 2048 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 4096 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 8192 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 16384 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 32768 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 65536 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 131072 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 262144 || \ + MYNEWT_VAL(OS_CPUTIME_FREQ) == 524288 + +#define OS_CPUTIME_FREQ_PWR2 + +#elif MYNEWT_VAL(OS_CPUTIME_FREQ) > 1000000 + +#define OS_CPUTIME_FREQ_HIGH + +#else + +#error "Invalid OS_CPUTIME_FREQ value. Value must be one of a) a power of 2" \ + ">= 256Hz, or b) any value >= 1MHz" + +#endif + +#if defined(OS_CPUTIME_FREQ_HIGH) +/* CPUTIME data. */ +struct os_cputime_data +{ + uint32_t ticks_per_usec; /* number of ticks per usec */ +}; +extern struct os_cputime_data g_os_cputime; +#endif + +/* Helpful macros to compare cputimes */ +/** evaluates to true if t1 is before t2 in time */ +#define CPUTIME_LT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) < 0) +/** evaluates to true if t1 is after t2 in time */ +#define CPUTIME_GT(__t1, __t2) ((int32_t) ((__t1) - (__t2)) > 0) +/** evaluates to true if t1 is after t2 in time */ +#define CPUTIME_GEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) >= 0) +/** evaluates to true if t1 is on or after t2 in time */ +#define CPUTIME_LEQ(__t1, __t2) ((int32_t) ((__t1) - (__t2)) <= 0) + +/** + * Initialize the cputime module. This must be called after os_init is called + * and before any other timer API are used. This should be called only once + * and should be called before the hardware timer is used. + * + * @param clock_freq The desired cputime frequency, in hertz (Hz). + * + * @return int 0 on success; -1 on error. + */ +int os_cputime_init(uint32_t clock_freq); + +/** + * Returns the low 32 bits of cputime. + * + * @return uint32_t The lower 32 bits of cputime + */ +uint32_t os_cputime_get32(void); + +#if !defined(OS_CPUTIME_FREQ_PWR2) +/** + * Converts the given number of nanoseconds into cputime ticks. + * Not defined if OS_CPUTIME_FREQ_PWR2 is defined. + * + * @param usecs The number of nanoseconds to convert to ticks + * + * @return uint32_t The number of ticks corresponding to 'nsecs' + */ +uint32_t os_cputime_nsecs_to_ticks(uint32_t nsecs); + +/** + * Convert the given number of ticks into nanoseconds. + * Not defined if OS_CPUTIME_FREQ_PWR2 is defined. + * + * @param ticks The number of ticks to convert to nanoseconds. + * + * @return uint32_t The number of nanoseconds corresponding to 'ticks' + */ +uint32_t os_cputime_ticks_to_nsecs(uint32_t ticks); + +/** + * Wait until 'nsecs' nanoseconds has elapsed. This is a blocking delay. + * Not defined if OS_CPUTIME_FREQ_PWR2 is defined. + * + * + * @param nsecs The number of nanoseconds to wait. + */ +void os_cputime_delay_nsecs(uint32_t nsecs); +#endif + +#if defined(OS_CPUTIME_FREQ_1MHZ) +#define os_cputime_usecs_to_ticks(x) (x) +#define os_cputime_ticks_to_usecs(x) (x) +#else + +/** + * Converts the given number of microseconds into cputime ticks. + * + * @param usecs The number of microseconds to convert to ticks + * + * @return uint32_t The number of ticks corresponding to 'usecs' + */ +uint32_t os_cputime_usecs_to_ticks(uint32_t usecs); + +/** + * Convert the given number of ticks into microseconds. + * + * @param ticks The number of ticks to convert to microseconds. + * + * @return uint32_t The number of microseconds corresponding to 'ticks' + */ +uint32_t os_cputime_ticks_to_usecs(uint32_t ticks); +#endif + +/** + * Wait until the number of ticks has elapsed. This is a blocking delay. + * + * @param ticks The number of ticks to wait. + */ +void os_cputime_delay_ticks(uint32_t ticks); + +/** + * Wait until 'usecs' microseconds has elapsed. This is a blocking delay. + * + * @param usecs The number of usecs to wait. + */ +void os_cputime_delay_usecs(uint32_t usecs); + +/** + * Initialize a CPU timer, using the given HAL timer. + * + * @param timer The timer to initialize. Cannot be NULL. + * @param fp The timer callback function. Cannot be NULL. + * @param arg Pointer to data object to pass to timer. + */ +void os_cputime_timer_init(struct hal_timer *timer, hal_timer_cb fp, + void *arg); + +/** + * Start a cputimer that will expire at 'cputime'. If cputime has already + * passed, the timer callback will still be called (at interrupt context). + * + * NOTE: This must be called when the timer is stopped. + * + * @param timer Pointer to timer to start. Cannot be NULL. + * @param cputime The cputime at which the timer should expire. + * + * @return int 0 on success; EINVAL if timer already started or timer struct + * invalid + * + */ +int os_cputime_timer_start(struct hal_timer *timer, uint32_t cputime); + +/** + * Sets a cpu timer that will expire 'usecs' microseconds from the current + * cputime. + * + * NOTE: This must be called when the timer is stopped. + * + * @param timer Pointer to timer. Cannot be NULL. + * @param usecs The number of usecs from now at which the timer will expire. + * + * @return int 0 on success; EINVAL if timer already started or timer struct + * invalid + */ +int os_cputime_timer_relative(struct hal_timer *timer, uint32_t usecs); + +/** + * Stops a cputimer from running. The timer is removed from the timer queue + * and interrupts are disabled if no timers are left on the queue. Can be + * called even if timer is not running. + * + * @param timer Pointer to cputimer to stop. Cannot be NULL. + */ +void os_cputime_timer_stop(struct hal_timer *timer); + +#ifdef __cplusplus +} +#endif + +#endif /* H_OS_CPUTIME_ */ + +/** + * @} OSCPUTime + * @} OSKernel + */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/os_error.h b/src/libs/mynewt-nimble/porting/nimble/include/os/os_error.h new file mode 100644 index 00000000..15cc6228 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/os_error.h @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_OS_ERROR_ +#define H_OS_ERROR_ + +#include "os/os.h" + +enum os_error { + OS_OK = 0, + OS_ENOMEM = 1, + OS_EINVAL = 2, + OS_INVALID_PARM = 3, + OS_MEM_NOT_ALIGNED = 4, + OS_BAD_MUTEX = 5, + OS_TIMEOUT = 6, + OS_ERR_IN_ISR = 7, /* Function cannot be called from ISR */ + OS_ERR_PRIV = 8, /* Privileged access error */ + OS_NOT_STARTED = 9, /* OS must be started to call this function, but isn't */ + OS_ENOENT = 10, /* No such thing */ + OS_EBUSY = 11, /* Resource busy */ + OS_ERROR = 12, /* Generic Error */ +}; + +typedef enum os_error os_error_t; + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/os_mbuf.h b/src/libs/mynewt-nimble/porting/nimble/include/os/os_mbuf.h new file mode 100644 index 00000000..f3857fe4 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/os_mbuf.h @@ -0,0 +1,646 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + + +/** + * @addtogroup OSKernel + * @{ + * @defgroup OSMbuf Chained Memory Buffers + * @{ + */ + + +#ifndef _OS_MBUF_H +#define _OS_MBUF_H + +#include "os/os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A mbuf pool from which to allocate mbufs. This contains a pointer to the os + * mempool to allocate mbufs out of, the total number of elements in the pool, + * and the amount of "user" data in a non-packet header mbuf. The total pool + * size, in bytes, should be: + * os_mbuf_count * (omp_databuf_len + sizeof(struct os_mbuf)) + */ +struct os_mbuf_pool { + /** + * Total length of the databuf in each mbuf. This is the size of the + * mempool block, minus the mbuf header + */ + uint16_t omp_databuf_len; + /** + * The memory pool which to allocate mbufs out of + */ + struct os_mempool *omp_pool; + + STAILQ_ENTRY(os_mbuf_pool) omp_next; +}; + + +/** + * A packet header structure that preceeds the mbuf packet headers. + */ +struct os_mbuf_pkthdr { + /** + * Overall length of the packet. + */ + uint16_t omp_len; + /** + * Flags + */ + uint16_t omp_flags; + + STAILQ_ENTRY(os_mbuf_pkthdr) omp_next; +}; + +/** + * Chained memory buffer. + */ +struct os_mbuf { + /** + * Current pointer to data in the structure + */ + uint8_t *om_data; + /** + * Flags associated with this buffer, see OS_MBUF_F_* defintions + */ + uint8_t om_flags; + /** + * Length of packet header + */ + uint8_t om_pkthdr_len; + /** + * Length of data in this buffer + */ + uint16_t om_len; + + /** + * The mbuf pool this mbuf was allocated out of + */ + struct os_mbuf_pool *om_omp; + + SLIST_ENTRY(os_mbuf) om_next; + + /** + * Pointer to the beginning of the data, after this buffer + */ + uint8_t om_databuf[0]; +}; + +/** + * Structure representing a queue of mbufs. + */ +struct os_mqueue { + STAILQ_HEAD(, os_mbuf_pkthdr) mq_head; + /** Event to post when new buffers are available on the queue. */ + struct ble_npl_event mq_ev; +}; + +/* + * Given a flag number, provide the mask for it + * + * @param __n The number of the flag in the mask + */ +#define OS_MBUF_F_MASK(__n) (1 << (__n)) + +/* + * Checks whether a given mbuf is a packet header mbuf + * + * @param __om The mbuf to check + */ +#define OS_MBUF_IS_PKTHDR(__om) \ + ((__om)->om_pkthdr_len >= sizeof (struct os_mbuf_pkthdr)) + +/** Get a packet header pointer given an mbuf pointer */ +#define OS_MBUF_PKTHDR(__om) ((struct os_mbuf_pkthdr *) \ + ((uint8_t *)&(__om)->om_data + sizeof(struct os_mbuf))) + +/** Given a mbuf packet header pointer, return a pointer to the mbuf */ +#define OS_MBUF_PKTHDR_TO_MBUF(__hdr) \ + (struct os_mbuf *)((uint8_t *)(__hdr) - sizeof(struct os_mbuf)) + +/** + * Gets the length of an entire mbuf chain. The specified mbuf must have a + * packet header. + */ +#define OS_MBUF_PKTLEN(__om) (OS_MBUF_PKTHDR(__om)->omp_len) + +/** + * Access the data of a mbuf, and cast it to type + * + * @param __om The mbuf to access, and cast + * @param __type The type to cast it to + */ +#define OS_MBUF_DATA(__om, __type) \ + (__type) ((__om)->om_data) + +/** + * Access the "user header" in the head of an mbuf chain. + * + * @param om Pointer to the head of an mbuf chain. + */ +#define OS_MBUF_USRHDR(om) \ + (void *)((uint8_t *)om + sizeof (struct os_mbuf) + \ + sizeof (struct os_mbuf_pkthdr)) + +/** + * Retrieves the length of the user header in an mbuf. + * + * @param om Pointer to the mbuf to query. + */ +#define OS_MBUF_USRHDR_LEN(om) \ + ((om)->om_pkthdr_len - sizeof (struct os_mbuf_pkthdr)) + + +/** @cond INTERNAL_HIDDEN */ + +/* + * Called by OS_MBUF_LEADINGSPACE() macro + */ +static inline uint16_t +_os_mbuf_leadingspace(struct os_mbuf *om) +{ + uint16_t startoff; + uint16_t leadingspace; + + startoff = 0; + if (OS_MBUF_IS_PKTHDR(om)) { + startoff = om->om_pkthdr_len; + } + + leadingspace = (uint16_t) (OS_MBUF_DATA(om, uint8_t *) - + ((uint8_t *) &om->om_databuf[0] + startoff)); + + return (leadingspace); +} + +/** @endcond */ + +/** + * Returns the leading space (space at the beginning) of the mbuf. + * Works on both packet header, and regular mbufs, as it accounts + * for the additional space allocated to the packet header. + * + * @param __omp Is the mbuf pool (which contains packet header length.) + * @param __om Is the mbuf in that pool to get the leadingspace for + * + * @return Amount of leading space available in the mbuf + */ +#define OS_MBUF_LEADINGSPACE(__om) _os_mbuf_leadingspace(__om) + + +/** @cond INTERNAL_HIDDEN */ + +/* Called by OS_MBUF_TRAILINGSPACE() macro. */ +static inline uint16_t +_os_mbuf_trailingspace(struct os_mbuf *om) +{ + struct os_mbuf_pool *omp; + + omp = om->om_omp; + + return (&om->om_databuf[0] + omp->omp_databuf_len) - + (om->om_data + om->om_len); +} + +/** @endcond */ + +/** + * Returns the trailing space (space at the end) of the mbuf. + * Works on both packet header and regular mbufs. + * + * @param __omp The mbuf pool for this mbuf + * @param __om Is the mbuf in that pool to get trailing space for + * + * @return The amount of trailing space available in the mbuf + */ +#define OS_MBUF_TRAILINGSPACE(__om) _os_mbuf_trailingspace(__om) + + +/** + * Initializes an mqueue. An mqueue is a queue of mbufs that ties to a + * particular task's event queue. Mqueues form a helper API around a common + * paradigm: wait on an event queue until at least one packet is available, + * then process a queue of packets. + * + * When mbufs are available on the queue, an event OS_EVENT_T_MQUEUE_DATA + * will be posted to the task's mbuf queue. + * + * @param mq The mqueue to initialize + * @param ev_cb The callback to associate with the mqeueue + * event. Typically, this callback pulls each + * packet off the mqueue and processes them. + * @param arg The argument to associate with the mqueue event. + * + * @return 0 on success, non-zero on failure. + */ +int os_mqueue_init(struct os_mqueue *mq, ble_npl_event_fn *ev_cb, void *arg); + +/** + * Remove and return a single mbuf from the mbuf queue. Does not block. + * + * @param mq The mbuf queue to pull an element off of. + * + * @return The next mbuf in the queue, or NULL if queue has no mbufs. + */ +struct os_mbuf *os_mqueue_get(struct os_mqueue *); + +/** + * Adds a packet (i.e. packet header mbuf) to an mqueue. The event associated + * with the mqueue gets posted to the specified eventq. + * + * @param mq The mbuf queue to append the mbuf to. + * @param evq The event queue to post an event to. + * @param m The mbuf to append to the mbuf queue. + * + * @return 0 on success, non-zero on failure. + */ +int os_mqueue_put(struct os_mqueue *, struct ble_npl_eventq *, struct os_mbuf *); + +/** + * MSYS is a system level mbuf registry. Allows the system to share + * packet buffers amongst the various networking stacks that can be running + * simultaeneously. + * + * Mbuf pools are created in the system initialization code, and then when + * a mbuf is allocated out of msys, it will try and find the best fit based + * upon estimated mbuf size. + * + * os_msys_register() registers a mbuf pool with MSYS, and allows MSYS to + * allocate mbufs out of it. + * + * @param new_pool The pool to register with MSYS + * + * @return 0 on success, non-zero on failure + */ +int os_msys_register(struct os_mbuf_pool *); + +/** + * Allocate a mbuf from msys. Based upon the data size requested, + * os_msys_get() will choose the mbuf pool that has the best fit. + * + * @param dsize The estimated size of the data being stored in the mbuf + * @param leadingspace The amount of leadingspace to allocate in the mbuf + * + * @return A freshly allocated mbuf on success, NULL on failure. + */ +struct os_mbuf *os_msys_get(uint16_t dsize, uint16_t leadingspace); + +/** + * De-registers all mbuf pools from msys. + */ +void os_msys_reset(void); + +/** + * Allocate a packet header structure from the MSYS pool. See + * os_msys_register() for a description of MSYS. + * + * @param dsize The estimated size of the data being stored in the mbuf + * @param user_hdr_len The length to allocate for the packet header structure + * + * @return A freshly allocated mbuf on success, NULL on failure. + */ +struct os_mbuf *os_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len); + +/** + * Count the number of blocks in all the mbuf pools that are allocated. + * + * @return total number of blocks allocated in Msys + */ +int os_msys_count(void); + +/** + * Return the number of free blocks in Msys + * + * @return Number of free blocks available in Msys + */ +int os_msys_num_free(void); + +/** + * Initialize a pool of mbufs. + * + * @param omp The mbuf pool to initialize + * @param mp The memory pool that will hold this mbuf pool + * @param buf_len The length of the buffer itself. + * @param nbufs The number of buffers in the pool + * + * @return 0 on success, error code on failure. + */ +int os_mbuf_pool_init(struct os_mbuf_pool *, struct os_mempool *mp, + uint16_t, uint16_t); + +/** + * Get an mbuf from the mbuf pool. The mbuf is allocated, and initialized + * prior to being returned. + * + * @param omp The mbuf pool to return the packet from + * @param leadingspace The amount of leadingspace to put before the data + * section by default. + * + * @return An initialized mbuf on success, and NULL on failure. + */ +struct os_mbuf *os_mbuf_get(struct os_mbuf_pool *omp, uint16_t); + +/** + * Allocate a new packet header mbuf out of the os_mbuf_pool. + * + * @param omp The mbuf pool to allocate out of + * @param user_pkthdr_len The packet header length to reserve for the caller. + * + * @return A freshly allocated mbuf on success, NULL on failure. + */ +struct os_mbuf *os_mbuf_get_pkthdr(struct os_mbuf_pool *omp, + uint8_t pkthdr_len); + +/** + * Duplicate a chain of mbufs. Return the start of the duplicated chain. + * + * @param omp The mbuf pool to duplicate out of + * @param om The mbuf chain to duplicate + * + * @return A pointer to the new chain of mbufs + */ +struct os_mbuf *os_mbuf_dup(struct os_mbuf *m); + +/** + * Locates the specified absolute offset within an mbuf chain. The offset + * can be one past than the total length of the chain, but no greater. + * + * @param om The start of the mbuf chain to seek within. + * @param off The absolute address to find. + * @param out_off On success, this points to the relative offset + * within the returned mbuf. + * + * @return The mbuf containing the specified offset on + * success. + * NULL if the specified offset is out of bounds. + */ +struct os_mbuf *os_mbuf_off(const struct os_mbuf *om, int off, + uint16_t *out_off); + + +/* + * Copy data from an mbuf chain starting "off" bytes from the beginning, + * continuing for "len" bytes, into the indicated buffer. + * + * @param m The mbuf chain to copy from + * @param off The offset into the mbuf chain to begin copying from + * @param len The length of the data to copy + * @param dst The destination buffer to copy into + * + * @return 0 on success; + * -1 if the mbuf does not contain enough data. + */ +int os_mbuf_copydata(const struct os_mbuf *m, int off, int len, void *dst); + +/** + * Append data onto a mbuf + * + * @param om The mbuf to append the data onto + * @param data The data to append onto the mbuf + * @param len The length of the data to append + * + * @return 0 on success, and an error code on failure + */ +int os_mbuf_append(struct os_mbuf *m, const void *, uint16_t); + +/** + * Reads data from one mbuf and appends it to another. On error, the specified + * data range may be partially appended. Neither mbuf is required to contain + * an mbuf packet header. + * + * @param dst The mbuf to append to. + * @param src The mbuf to copy data from. + * @param src_off The absolute offset within the source mbuf + * chain to read from. + * @param len The number of bytes to append. + * + * @return 0 on success; + * OS_EINVAL if the specified range extends beyond + * the end of the source mbuf chain. + */ +int os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src, + uint16_t src_off, uint16_t len); + +/** + * Release a mbuf back to the pool + * + * @param omp The Mbuf pool to release back to + * @param om The Mbuf to release back to the pool + * + * @return 0 on success, -1 on failure + */ +int os_mbuf_free(struct os_mbuf *mb); + +/** + * Free a chain of mbufs + * + * @param omp The mbuf pool to free the chain of mbufs into + * @param om The starting mbuf of the chain to free back into the pool + * + * @return 0 on success, -1 on failure + */ +int os_mbuf_free_chain(struct os_mbuf *om); + +/** + * Adjust the length of a mbuf, trimming either from the head or the tail + * of the mbuf. + * + * @param mp The mbuf chain to adjust + * @param req_len The length to trim from the mbuf. If positive, trims + * from the head of the mbuf, if negative, trims from the + * tail of the mbuf. + */ +void os_mbuf_adj(struct os_mbuf *mp, int req_len); + + +/** + * Performs a memory compare of the specified region of an mbuf chain against a + * flat buffer. + * + * @param om The start of the mbuf chain to compare. + * @param off The offset within the mbuf chain to start the + * comparison. + * @param data The flat buffer to compare. + * @param len The length of the flat buffer. + * + * @return 0 if both memory regions are identical; + * A memcmp return code if there is a mismatch; + * INT_MAX if the mbuf is too short. + */ +int os_mbuf_cmpf(const struct os_mbuf *om, int off, const void *data, int len); + +/** + * Compares the contents of two mbuf chains. The ranges of the two chains to + * be compared are specified via the two offset parameters and the len + * parameter. Neither mbuf chain is required to contain a packet header. + * + * @param om1 The first mbuf chain to compare. + * @param offset1 The absolute offset within om1 at which to + * start the comparison. + * @param om2 The second mbuf chain to compare. + * @param offset2 The absolute offset within om2 at which to + * start the comparison. + * @param len The number of bytes to compare. + * + * @return 0 if both mbuf segments are identical; + * A memcmp() return code if the segment contents + * differ; + * INT_MAX if a specified range extends beyond the + * end of its corresponding mbuf chain. + */ +int os_mbuf_cmpm(const struct os_mbuf *om1, uint16_t offset1, + const struct os_mbuf *om2, uint16_t offset2, + uint16_t len); + +/** + * Increases the length of an mbuf chain by adding data to the front. If there + * is insufficient room in the leading mbuf, additional mbufs are allocated and + * prepended as necessary. If this function fails to allocate an mbuf, the + * entire chain is freed. + * + * The specified mbuf chain does not need to contain a packet header. + * + * @param omp The mbuf pool to allocate from. + * @param om The head of the mbuf chain. + * @param len The number of bytes to prepend. + * + * @return The new head of the chain on success; + * NULL on failure. + */ +struct os_mbuf *os_mbuf_prepend(struct os_mbuf *om, int len); + +/** + * Prepends a chunk of empty data to the specified mbuf chain and ensures the + * chunk is contiguous. If either operation fails, the specified mbuf chain is + * freed and NULL is returned. + * + * @param om The mbuf chain to prepend to. + * @param len The number of bytes to prepend and pullup. + * + * @return The modified mbuf on success; + * NULL on failure (and the mbuf chain is freed). + */ +struct os_mbuf *os_mbuf_prepend_pullup(struct os_mbuf *om, uint16_t len); + +/** + * Copies the contents of a flat buffer into an mbuf chain, starting at the + * specified destination offset. If the mbuf is too small for the source data, + * it is extended as necessary. If the destination mbuf contains a packet + * header, the header length is updated. + * + * @param omp The mbuf pool to allocate from. + * @param om The mbuf chain to copy into. + * @param off The offset within the chain to copy to. + * @param src The source buffer to copy from. + * @param len The number of bytes to copy. + * + * @return 0 on success; nonzero on failure. + */ +int os_mbuf_copyinto(struct os_mbuf *om, int off, const void *src, int len); + +/** + * Attaches a second mbuf chain onto the end of the first. If the first chain + * contains a packet header, the header's length is updated. If the second + * chain has a packet header, its header is cleared. + * + * @param first The mbuf chain being attached to. + * @param second The mbuf chain that gets attached. + */ +void os_mbuf_concat(struct os_mbuf *first, struct os_mbuf *second); + + +/** + * Increases the length of an mbuf chain by the specified amount. If there is + * not sufficient room in the last buffer, a new buffer is allocated and + * appended to the chain. It is an error to request more data than can fit in + * a single buffer. + * + * @param omp + * @param om The head of the chain to extend. + * @param len The number of bytes to extend by. + * + * @return A pointer to the new data on success; + * NULL on failure. + */ +void *os_mbuf_extend(struct os_mbuf *om, uint16_t len); + +/** + * Rearrange a mbuf chain so that len bytes are contiguous, + * and in the data area of an mbuf (so that OS_MBUF_DATA() will + * work on a structure of size len.) Returns the resulting + * mbuf chain on success, free's it and returns NULL on failure. + * + * If there is room, it will add up to "max_protohdr - len" + * extra bytes to the contiguous region, in an attempt to avoid being + * called next time. + * + * @param omp The mbuf pool to take the mbufs out of + * @param om The mbuf chain to make contiguous + * @param len The number of bytes in the chain to make contiguous + * + * @return The contiguous mbuf chain on success, NULL on failure. + */ +struct os_mbuf *os_mbuf_pullup(struct os_mbuf *om, uint16_t len); + + +/** + * Removes and frees empty mbufs from the front of a chain. If the chain + * contains a packet header, it is preserved. + * + * @param om The mbuf chain to trim. + * + * @return The head of the trimmed mbuf chain. + */ +struct os_mbuf *os_mbuf_trim_front(struct os_mbuf *om); + +/** + * Creates a single chained mbuf from m1 and m2 utilizing all + * the available buffer space in all mbufs in the resulting + * chain. In other words, ensures there is no leading space in + * any mbuf in the resulting chain and trailing space only in + * the last mbuf in the chain. Mbufs from either chain may be + * freed if not needed. No mbufs are allocated. Note that mbufs + * from m2 are added to the end of m1. If m1 has a packet + * header, it is retained and length updated. If m2 has a packet + * header it is discarded. If m1 is NULL, NULL is returned and + * m2 is left untouched. + * + * @param m1 Pointer to first mbuf chain to pack + * @param m2 Pointer to second mbuf chain to pack + * + * @return struct os_mbuf* Pointer to resulting mbuf chain + */ +struct os_mbuf *os_mbuf_pack_chains(struct os_mbuf *m1, struct os_mbuf *m2); + +#ifdef __cplusplus +} +#endif + +#endif /* _OS_MBUF_H */ + + +/** + * @} OSMbuf + * @} OSKernel + */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/os_mempool.h b/src/libs/mynewt-nimble/porting/nimble/include/os/os_mempool.h new file mode 100644 index 00000000..c69fb3da --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/os_mempool.h @@ -0,0 +1,265 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * @addtogroup OSKernel + * @{ + * @defgroup OSMempool Memory Pools + * @{ + */ + + +#ifndef _OS_MEMPOOL_H_ +#define _OS_MEMPOOL_H_ + +#include <stdbool.h> +#include "os/os.h" +#include "os/queue.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * A memory block structure. This simply contains a pointer to the free list + * chain and is only used when the block is on the free list. When the block + * has been removed from the free list the entire memory block is usable by the + * caller. + */ +struct os_memblock { + SLIST_ENTRY(os_memblock) mb_next; +}; + +/* XXX: Change this structure so that we keep the first address in the pool? */ +/* XXX: add memory debug structure and associated code */ +/* XXX: Change how I coded the SLIST_HEAD here. It should be named: + SLIST_HEAD(,os_memblock) mp_head; */ + +/** + * Memory pool + */ +struct os_mempool { + /** Size of the memory blocks, in bytes. */ + uint32_t mp_block_size; + /** The number of memory blocks. */ + uint16_t mp_num_blocks; + /** The number of free blocks left */ + uint16_t mp_num_free; + /** The lowest number of free blocks seen */ + uint16_t mp_min_free; + /** Bitmap of OS_MEMPOOL_F_[...] values. */ + uint8_t mp_flags; + /** Address of memory buffer used by pool */ + uintptr_t mp_membuf_addr; + STAILQ_ENTRY(os_mempool) mp_list; + SLIST_HEAD(,os_memblock); + /** Name for memory block */ + char *name; +}; + +/** + * Indicates an extended mempool. Address can be safely cast to + * (struct os_mempool_ext *). + */ +#define OS_MEMPOOL_F_EXT 0x01 + +struct os_mempool_ext; + +/** + * Block put callback function. If configured, this callback gets executed + * whenever a block is freed to the corresponding extended mempool. Note: The + * os_memblock_put() function calls this callback instead of freeing the block + * itself. Therefore, it is the callback's responsibility to free the block + * via a call to os_memblock_put_from_cb(). + * + * @param ome The extended mempool that a block is being + * freed back to. + * @param data The block being freed. + * @param arg Optional argument configured along with the + * callback. + * + * @return Indicates whether the block was successfully + * freed. A non-zero value should only be + * returned if the block was not successfully + * released back to its pool. + */ +typedef os_error_t os_mempool_put_fn(struct os_mempool_ext *ome, void *data, + void *arg); + +struct os_mempool_ext { + struct os_mempool mpe_mp; + + /* Callback that is executed immediately when a block is freed. */ + os_mempool_put_fn *mpe_put_cb; + void *mpe_put_arg; +}; + +#define OS_MEMPOOL_INFO_NAME_LEN (32) + +/** + * Information describing a memory pool, used to return OS information + * to the management layer. + */ +struct os_mempool_info { + /** Size of the memory blocks in the pool */ + int omi_block_size; + /** Number of memory blocks in the pool */ + int omi_num_blocks; + /** Number of free memory blocks */ + int omi_num_free; + /** Minimum number of free memory blocks ever */ + int omi_min_free; + /** Name of the memory pool */ + char omi_name[OS_MEMPOOL_INFO_NAME_LEN]; +}; + +/** + * Get information about the next system memory pool. + * + * @param mempool The current memory pool, or NULL if starting iteration. + * @param info A pointer to the structure to return memory pool information + * into. + * + * @return The next memory pool in the list to get information about, or NULL + * when at the last memory pool. + */ +struct os_mempool *os_mempool_info_get_next(struct os_mempool *, + struct os_mempool_info *); + +/* + * To calculate size of the memory buffer needed for the pool. NOTE: This size + * is NOT in bytes! The size is the number of os_membuf_t elements required for + * the memory pool. + */ +#if (OS_CFG_ALIGNMENT == OS_CFG_ALIGN_4) +#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + 3) / 4) * (n)) +typedef uint32_t os_membuf_t; +#else +#define OS_MEMPOOL_SIZE(n,blksize) ((((blksize) + 7) / 8) * (n)) +typedef uint64_t os_membuf_t; +#endif + +/** Calculates the number of bytes required to initialize a memory pool. */ +#define OS_MEMPOOL_BYTES(n,blksize) \ + (sizeof (os_membuf_t) * OS_MEMPOOL_SIZE((n), (blksize))) + +/** + * Initialize a memory pool. + * + * @param mp Pointer to a pointer to a mempool + * @param blocks The number of blocks in the pool + * @param blocks_size The size of the block, in bytes. + * @param membuf Pointer to memory to contain blocks. + * @param name Name of the pool. + * + * @return os_error_t + */ +os_error_t os_mempool_init(struct os_mempool *mp, uint16_t blocks, + uint32_t block_size, void *membuf, char *name); + +/** + * Initializes an extended memory pool. Extended attributes (e.g., callbacks) + * are not specified when this function is called; they are assigned manually + * after initialization. + * + * @param mpe The extended memory pool to initialize. + * @param blocks The number of blocks in the pool. + * @param block_size The size of each block, in bytes. + * @param membuf Pointer to memory to contain blocks. + * @param name Name of the pool. + * + * @return os_error_t + */ +os_error_t os_mempool_ext_init(struct os_mempool_ext *mpe, uint16_t blocks, + uint32_t block_size, void *membuf, char *name); + +/** + * Clears a memory pool. + * + * @param mp The mempool to clear. + * + * @return os_error_t + */ +os_error_t os_mempool_clear(struct os_mempool *mp); + +/** + * Performs an integrity check of the specified mempool. This function + * attempts to detect memory corruption in the specified memory pool. + * + * @param mp The mempool to check. + * + * @return true if the memory pool passes the integrity + * check; + * false if the memory pool is corrupt. + */ +bool os_mempool_is_sane(const struct os_mempool *mp); + +/** + * Checks if a memory block was allocated from the specified mempool. + * + * @param mp The mempool to check as parent. + * @param block_addr The memory block to check as child. + * + * @return 0 if the block does not belong to the mempool; + * 1 if the block does belong to the mempool. + */ +int os_memblock_from(const struct os_mempool *mp, const void *block_addr); + +/** + * Get a memory block from a memory pool + * + * @param mp Pointer to the memory pool + * + * @return void* Pointer to block if available; NULL otherwise + */ +void *os_memblock_get(struct os_mempool *mp); + +/** + * Puts the memory block back into the pool, ignoring the put callback, if any. + * This function should only be called from a put callback to free a block + * without causing infinite recursion. + * + * @param mp Pointer to memory pool + * @param block_addr Pointer to memory block + * + * @return os_error_t + */ +os_error_t os_memblock_put_from_cb(struct os_mempool *mp, void *block_addr); + +/** + * Puts the memory block back into the pool + * + * @param mp Pointer to memory pool + * @param block_addr Pointer to memory block + * + * @return os_error_t + */ +os_error_t os_memblock_put(struct os_mempool *mp, void *block_addr); + +#ifdef __cplusplus +} +#endif + +#endif /* _OS_MEMPOOL_H_ */ + + +/** + * @} OSMempool + * @} OSKernel + */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/os_trace_api.h b/src/libs/mynewt-nimble/porting/nimble/include/os/os_trace_api.h new file mode 100644 index 00000000..4f1aa03c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/os_trace_api.h @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef OS_TRACE_API_H +#define OS_TRACE_API_H + +#include <stdint.h> + +#define OS_TRACE_ID_EVENTQ_PUT (40) +#define OS_TRACE_ID_EVENTQ_GET_NO_WAIT (41) +#define OS_TRACE_ID_EVENTQ_GET (42) +#define OS_TRACE_ID_EVENTQ_REMOVE (43) +#define OS_TRACE_ID_EVENTQ_POLL_0TIMO (44) +#define OS_TRACE_ID_EVENTQ_POLL (45) +#define OS_TRACE_ID_MUTEX_INIT (50) +#define OS_TRACE_ID_MUTEX_RELEASE (51) +#define OS_TRACE_ID_MUTEX_PEND (52) +#define OS_TRACE_ID_SEM_INIT (60) +#define OS_TRACE_ID_SEM_RELEASE (61) +#define OS_TRACE_ID_SEM_PEND (62) + +static inline void +os_trace_isr_enter(void) +{ +} + +static inline void +os_trace_isr_exit(void) +{ +} + +static inline void +os_trace_idle(void) +{ +} + +static inline void +os_trace_api_void(unsigned id) +{ +} + +static inline void +os_trace_api_u32(unsigned id, uint32_t p0) +{ +} + +static inline void +os_trace_api_u32x2(unsigned id, uint32_t p0, uint32_t p1) +{ +} + +static inline void +os_trace_api_u32x3(unsigned id, uint32_t p0, uint32_t p1, uint32_t p2) +{ +} + +static inline void +os_trace_api_ret(unsigned id) +{ +} + +static inline void +os_trace_api_ret_u32(unsigned id, uint32_t return_value) +{ +} + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/queue.h b/src/libs/mynewt-nimble/porting/nimble/include/os/queue.h new file mode 100644 index 00000000..faffd851 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/queue.h @@ -0,0 +1,522 @@ +/* + * Copyright (c) 1991, 1993 + * The Regents of the University of California. 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 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. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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. + * + * @(#)queue.h 8.5 (Berkeley) 8/20/94 + * $FreeBSD: src/sys/sys/queue.h,v 1.32.2.7 2002/04/17 14:21:02 des Exp $ + */ + +#ifndef _QUEUE_H_ +#define _QUEUE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * This file defines five types of data structures: singly-linked lists, + * singly-linked tail queues, lists, tail queues, and circular queues. + * + * A singly-linked list is headed by a single forward pointer. The elements + * are singly linked for minimum space and pointer manipulation overhead at + * the expense of O(n) removal for arbitrary elements. New elements can be + * added to the list after an existing element or at the head of the list. + * Elements being removed from the head of the list should use the explicit + * macro for this purpose for optimum efficiency. A singly-linked list may + * only be traversed in the forward direction. Singly-linked lists are ideal + * for applications with large datasets and few or no removals or for + * implementing a LIFO queue. + * + * A singly-linked tail queue is headed by a pair of pointers, one to the + * head of the list and the other to the tail of the list. The elements are + * singly linked for minimum space and pointer manipulation overhead at the + * expense of O(n) removal for arbitrary elements. New elements can be added + * to the list after an existing element, at the head of the list, or at the + * end of the list. Elements being removed from the head of the tail queue + * should use the explicit macro for this purpose for optimum efficiency. + * A singly-linked tail queue may only be traversed in the forward direction. + * Singly-linked tail queues are ideal for applications with large datasets + * and few or no removals or for implementing a FIFO queue. + * + * A list is headed by a single forward pointer (or an array of forward + * pointers for a hash table header). The elements are doubly linked + * so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before + * or after an existing element or at the head of the list. A list + * may only be traversed in the forward direction. + * + * A tail queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or + * after an existing element, at the head of the list, or at the end of + * the list. A tail queue may be traversed in either direction. + * + * A circle queue is headed by a pair of pointers, one to the head of the + * list and the other to the tail of the list. The elements are doubly + * linked so that an arbitrary element can be removed without a need to + * traverse the list. New elements can be added to the list before or after + * an existing element, at the head of the list, or at the end of the list. + * A circle queue may be traversed in either direction, but has a more + * complex end of list detection. + * + * For details on the use of these macros, see the queue(3) manual page. + * + * + * SLIST LIST STAILQ TAILQ CIRCLEQ + * _HEAD + + + + + + * _HEAD_INITIALIZER + + + + + + * _ENTRY + + + + + + * _INIT + + + + + + * _EMPTY + + + + + + * _FIRST + + + + + + * _NEXT + + + + + + * _PREV - - - + + + * _LAST - - + + + + * _FOREACH + + + + + + * _FOREACH_REVERSE - - - + + + * _INSERT_HEAD + + + + + + * _INSERT_BEFORE - + - + + + * _INSERT_AFTER + + + + + + * _INSERT_TAIL - - + + + + * _REMOVE_HEAD + - + - - + * _REMOVE + + + + + + * + */ + +/* + * Singly-linked List declarations. + */ +#define SLIST_HEAD(name, type) \ +struct name { \ + struct type *slh_first; /* first element */ \ +} + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ +struct { \ + struct type *sle_next; /* next element */ \ +} + +/* + * Singly-linked List functions. + */ +#define SLIST_EMPTY(head) ((head)->slh_first == NULL) + +#define SLIST_FIRST(head) ((head)->slh_first) + +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST((head)); \ + (var); \ + (var) = SLIST_NEXT((var), field)) + +#define SLIST_INIT(head) do { \ + SLIST_FIRST((head)) = NULL; \ +} while (0) + +#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_NEXT((slistelm), field); \ + SLIST_NEXT((slistelm), field) = (elm); \ +} while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) do { \ + SLIST_NEXT((elm), field) = SLIST_FIRST((head)); \ + SLIST_FIRST((head)) = (elm); \ +} while (0) + +#define SLIST_NEXT(elm, field) ((elm)->field.sle_next) + +#define SLIST_REMOVE(head, elm, type, field) do { \ + if (SLIST_FIRST((head)) == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = SLIST_FIRST((head)); \ + while (SLIST_NEXT(curelm, field) != (elm)) \ + curelm = SLIST_NEXT(curelm, field); \ + SLIST_NEXT(curelm, field) = \ + SLIST_NEXT(SLIST_NEXT(curelm, field), field); \ + } \ +} while (0) + +#define SLIST_REMOVE_HEAD(head, field) do { \ + SLIST_FIRST((head)) = SLIST_NEXT(SLIST_FIRST((head)), field); \ +} while (0) + +/* + * Singly-linked Tail queue declarations. + */ +#define STAILQ_HEAD(name, type) \ +struct name { \ + struct type *stqh_first;/* first element */ \ + struct type **stqh_last;/* addr of last next element */ \ +} + +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).stqh_first } + +#define STAILQ_ENTRY(type) \ +struct { \ + struct type *stqe_next; /* next element */ \ +} + +/* + * Singly-linked Tail queue functions. + */ +#define STAILQ_EMPTY(head) ((head)->stqh_first == NULL) + +#define STAILQ_FIRST(head) ((head)->stqh_first) + +#define STAILQ_FOREACH(var, head, field) \ + for((var) = STAILQ_FIRST((head)); \ + (var); \ + (var) = STAILQ_NEXT((var), field)) + +#define STAILQ_INIT(head) do { \ + STAILQ_FIRST((head)) = NULL; \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_INSERT_AFTER(head, tqelm, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_NEXT((tqelm), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_NEXT((tqelm), field) = (elm); \ +} while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((STAILQ_NEXT((elm), field) = STAILQ_FIRST((head))) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ + STAILQ_FIRST((head)) = (elm); \ +} while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) do { \ + STAILQ_NEXT((elm), field) = NULL; \ + *(head)->stqh_last = (elm); \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +#define STAILQ_LAST(head, type, field) \ + (STAILQ_EMPTY(head) ? \ + NULL : \ + ((struct type *) \ + ((char *)((head)->stqh_last) - offsetof(struct type, field)))) + +#define STAILQ_NEXT(elm, field) ((elm)->field.stqe_next) + +#define STAILQ_REMOVE(head, elm, type, field) do { \ + if (STAILQ_FIRST((head)) == (elm)) { \ + STAILQ_REMOVE_HEAD(head, field); \ + } \ + else { \ + struct type *curelm = STAILQ_FIRST((head)); \ + while (STAILQ_NEXT(curelm, field) != (elm)) \ + curelm = STAILQ_NEXT(curelm, field); \ + if ((STAILQ_NEXT(curelm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(curelm, field), field)) == NULL)\ + (head)->stqh_last = &STAILQ_NEXT((curelm), field);\ + } \ +} while (0) + +#define STAILQ_REMOVE_HEAD(head, field) do { \ + if ((STAILQ_FIRST((head)) = \ + STAILQ_NEXT(STAILQ_FIRST((head)), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_REMOVE_HEAD_UNTIL(head, elm, field) do { \ + if ((STAILQ_FIRST((head)) = STAILQ_NEXT((elm), field)) == NULL) \ + (head)->stqh_last = &STAILQ_FIRST((head)); \ +} while (0) + +#define STAILQ_REMOVE_AFTER(head, elm, field) do { \ + if ((STAILQ_NEXT(elm, field) = \ + STAILQ_NEXT(STAILQ_NEXT(elm, field), field)) == NULL) \ + (head)->stqh_last = &STAILQ_NEXT((elm), field); \ +} while (0) + +/* + * List declarations. + */ +#define LIST_HEAD(name, type) \ +struct name { \ + struct type *lh_first; /* first element */ \ +} + +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define LIST_ENTRY(type) \ +struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ +} + +/* + * List functions. + */ + +#define LIST_EMPTY(head) ((head)->lh_first == NULL) + +#define LIST_FIRST(head) ((head)->lh_first) + +#define LIST_FOREACH(var, head, field) \ + for ((var) = LIST_FIRST((head)); \ + (var); \ + (var) = LIST_NEXT((var), field)) + +#define LIST_INIT(head) do { \ + LIST_FIRST((head)) = NULL; \ +} while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) do { \ + if ((LIST_NEXT((elm), field) = LIST_NEXT((listelm), field)) != NULL)\ + LIST_NEXT((listelm), field)->field.le_prev = \ + &LIST_NEXT((elm), field); \ + LIST_NEXT((listelm), field) = (elm); \ + (elm)->field.le_prev = &LIST_NEXT((listelm), field); \ +} while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + LIST_NEXT((elm), field) = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &LIST_NEXT((elm), field); \ +} while (0) + +#define LIST_INSERT_HEAD(head, elm, field) do { \ + if ((LIST_NEXT((elm), field) = LIST_FIRST((head))) != NULL) \ + LIST_FIRST((head))->field.le_prev = &LIST_NEXT((elm), field);\ + LIST_FIRST((head)) = (elm); \ + (elm)->field.le_prev = &LIST_FIRST((head)); \ +} while (0) + +#define LIST_NEXT(elm, field) ((elm)->field.le_next) + +#define LIST_REMOVE(elm, field) do { \ + if (LIST_NEXT((elm), field) != NULL) \ + LIST_NEXT((elm), field)->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = LIST_NEXT((elm), field); \ +} while (0) + +/* + * Tail queue declarations. + */ +#define TAILQ_HEAD(name, type) \ +struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ +} + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ +struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ +} + +/* + * Tail queue functions. + */ +#define TAILQ_EMPTY(head) ((head)->tqh_first == NULL) + +#define TAILQ_FIRST(head) ((head)->tqh_first) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST((head)); \ + (var); \ + (var) = TAILQ_NEXT((var), field)) + +#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var); \ + (var) = TAILQ_PREV((var), headname, field)) + +#define TAILQ_INIT(head) do { \ + TAILQ_FIRST((head)) = NULL; \ + (head)->tqh_last = &TAILQ_FIRST((head)); \ +} while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ + if ((TAILQ_NEXT((elm), field) = TAILQ_NEXT((listelm), field)) != NULL)\ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + TAILQ_NEXT((listelm), field) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_NEXT((listelm), field); \ +} while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + TAILQ_NEXT((elm), field) = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &TAILQ_NEXT((elm), field); \ +} while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) do { \ + if ((TAILQ_NEXT((elm), field) = TAILQ_FIRST((head))) != NULL) \ + TAILQ_FIRST((head))->field.tqe_prev = \ + &TAILQ_NEXT((elm), field); \ + else \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ + TAILQ_FIRST((head)) = (elm); \ + (elm)->field.tqe_prev = &TAILQ_FIRST((head)); \ +} while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) do { \ + TAILQ_NEXT((elm), field) = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &TAILQ_NEXT((elm), field); \ +} while (0) + +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) + +#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) + +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) + +#define TAILQ_REMOVE(head, elm, field) do { \ + if ((TAILQ_NEXT((elm), field)) != NULL) \ + TAILQ_NEXT((elm), field)->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = TAILQ_NEXT((elm), field); \ +} while (0) + +/* + * Circular queue declarations. + */ +#define CIRCLEQ_HEAD(name, type) \ +struct name { \ + struct type *cqh_first; /* first element */ \ + struct type *cqh_last; /* last element */ \ +} + +#define CIRCLEQ_HEAD_INITIALIZER(head) \ + { (void *)&(head), (void *)&(head) } + +#define CIRCLEQ_ENTRY(type) \ +struct { \ + struct type *cqe_next; /* next element */ \ + struct type *cqe_prev; /* previous element */ \ +} + +/* + * Circular queue functions. + */ +#define CIRCLEQ_EMPTY(head) ((head)->cqh_first == (void *)(head)) + +#define CIRCLEQ_FIRST(head) ((head)->cqh_first) + +#define CIRCLEQ_FOREACH(var, head, field) \ + for ((var) = CIRCLEQ_FIRST((head)); \ + (var) != (void *)(head) || ((var) = NULL); \ + (var) = CIRCLEQ_NEXT((var), field)) + +#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ + for ((var) = CIRCLEQ_LAST((head)); \ + (var) != (void *)(head) || ((var) = NULL); \ + (var) = CIRCLEQ_PREV((var), field)) + +#define CIRCLEQ_INIT(head) do { \ + CIRCLEQ_FIRST((head)) = (void *)(head); \ + CIRCLEQ_LAST((head)) = (void *)(head); \ +} while (0) + +#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ + CIRCLEQ_NEXT((elm), field) = CIRCLEQ_NEXT((listelm), field); \ + CIRCLEQ_PREV((elm), field) = (listelm); \ + if (CIRCLEQ_NEXT((listelm), field) == (void *)(head)) \ + CIRCLEQ_LAST((head)) = (elm); \ + else \ + CIRCLEQ_PREV(CIRCLEQ_NEXT((listelm), field), field) = (elm);\ + CIRCLEQ_NEXT((listelm), field) = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ + CIRCLEQ_NEXT((elm), field) = (listelm); \ + CIRCLEQ_PREV((elm), field) = CIRCLEQ_PREV((listelm), field); \ + if (CIRCLEQ_PREV((listelm), field) == (void *)(head)) \ + CIRCLEQ_FIRST((head)) = (elm); \ + else \ + CIRCLEQ_NEXT(CIRCLEQ_PREV((listelm), field), field) = (elm);\ + CIRCLEQ_PREV((listelm), field) = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ + CIRCLEQ_NEXT((elm), field) = CIRCLEQ_FIRST((head)); \ + CIRCLEQ_PREV((elm), field) = (void *)(head); \ + if (CIRCLEQ_LAST((head)) == (void *)(head)) \ + CIRCLEQ_LAST((head)) = (elm); \ + else \ + CIRCLEQ_PREV(CIRCLEQ_FIRST((head)), field) = (elm); \ + CIRCLEQ_FIRST((head)) = (elm); \ +} while (0) + +#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ + CIRCLEQ_NEXT((elm), field) = (void *)(head); \ + CIRCLEQ_PREV((elm), field) = CIRCLEQ_LAST((head)); \ + if (CIRCLEQ_FIRST((head)) == (void *)(head)) \ + CIRCLEQ_FIRST((head)) = (elm); \ + else \ + CIRCLEQ_NEXT(CIRCLEQ_LAST((head)), field) = (elm); \ + CIRCLEQ_LAST((head)) = (elm); \ +} while (0) + +#define CIRCLEQ_LAST(head) ((head)->cqh_last) + +#define CIRCLEQ_NEXT(elm,field) ((elm)->field.cqe_next) + +#define CIRCLEQ_PREV(elm,field) ((elm)->field.cqe_prev) + +#define CIRCLEQ_REMOVE(head, elm, field) do { \ + if (CIRCLEQ_NEXT((elm), field) == (void *)(head)) \ + CIRCLEQ_LAST((head)) = CIRCLEQ_PREV((elm), field); \ + else \ + CIRCLEQ_PREV(CIRCLEQ_NEXT((elm), field), field) = \ + CIRCLEQ_PREV((elm), field); \ + if (CIRCLEQ_PREV((elm), field) == (void *)(head)) \ + CIRCLEQ_FIRST((head)) = CIRCLEQ_NEXT((elm), field); \ + else \ + CIRCLEQ_NEXT(CIRCLEQ_PREV((elm), field), field) = \ + CIRCLEQ_NEXT((elm), field); \ +} while (0) + +#ifdef __cplusplus +} +#endif + +#endif /* !_QUEUE_H_ */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/os/util.h b/src/libs/mynewt-nimble/porting/nimble/include/os/util.h new file mode 100644 index 00000000..3e59670c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/os/util.h @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_OS_UTIL_ +#define H_OS_UTIL_ + +/* Helpers to pass integers as pointers and vice-versa */ +#define POINTER_TO_UINT(p) ((unsigned int) ((uintptr_t) (p))) +#define UINT_TO_POINTER(u) ((void *) ((uintptr_t) (u))) +#define POINTER_TO_INT(p) ((int) ((intptr_t) (p))) +#define INT_TO_POINTER(u) ((void *) ((intptr_t) (u))) + +/* Helper to retrieve pointer to "parent" object in structure */ +#define CONTAINER_OF(ptr, type, field) \ + ((type *)(((char *)(ptr)) - offsetof(type, field))) + +/* Helper to calculate number of elements in array */ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(array) \ + (sizeof(array) / sizeof((array)[0])) +#endif +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/stats/stats.h b/src/libs/mynewt-nimble/porting/nimble/include/stats/stats.h new file mode 100644 index 00000000..996bcbc7 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/stats/stats.h @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef __STATS_H__ +#define __STATS_H__ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define STATS_SECT_DECL(__name) struct stats_ ## __name +#define STATS_SECT_END }; + +#define STATS_SECT_START(__name) STATS_SECT_DECL(__name) { +#define STATS_SECT_VAR(__var) + +#define STATS_HDR(__sectname) NULL + +#define STATS_SECT_ENTRY(__var) +#define STATS_SECT_ENTRY16(__var) +#define STATS_SECT_ENTRY32(__var) +#define STATS_SECT_ENTRY64(__var) +#define STATS_RESET(__var) + +#define STATS_SIZE_INIT_PARMS(__sectvarname, __size) \ + 0, 0 + +#define STATS_INC(__sectvarname, __var) +#define STATS_INCN(__sectvarname, __var, __n) +#define STATS_CLEAR(__sectvarname, __var) + +#define STATS_NAME_START(__name) +#define STATS_NAME(__name, __entry) +#define STATS_NAME_END(__name) +#define STATS_NAME_INIT_PARMS(__name) NULL, 0 + +static inline int +stats_init(void *a, uint8_t b, uint8_t c, void *d, uint8_t e) +{ + /* dummy */ + return 0; +} + +static inline int +stats_register(void *a, void *b) +{ + /* dummy */ + return 0; +} + +static inline int +stats_init_and_reg(void *a, uint8_t b, uint8_t c, void *d, uint8_t e, void *f) +{ + /* dummy */ + return 0; +} + +#ifdef __cplusplus +} +#endif + +#endif /* __STATS_H__ */ diff --git a/src/libs/mynewt-nimble/porting/nimble/include/syscfg/syscfg.h b/src/libs/mynewt-nimble/porting/nimble/include/syscfg/syscfg.h new file mode 100644 index 00000000..d4913caf --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/syscfg/syscfg.h @@ -0,0 +1,1518 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSCFG_ +#define H_MYNEWT_SYSCFG_ + +/** + * This macro exists to ensure code includes this header when needed. If code + * checks the existence of a setting directly via ifdef without including this + * header, the setting macro will silently evaluate to 0. In contrast, an + * attempt to use these macros without including this header will result in a + * compiler error. + */ +#define MYNEWT_VAL(_name) MYNEWT_VAL_ ## _name +#define MYNEWT_VAL_CHOICE(_name, _val) MYNEWT_VAL_ ## _name ## __ ## _val + + + +/*** @apache-mynewt-core/compiler/arm-none-eabi-m4 */ +#ifndef MYNEWT_VAL_HARDFLOAT +#define MYNEWT_VAL_HARDFLOAT (0) +#endif + +/*** @apache-mynewt-core/crypto/tinycrypt */ +#ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE +#define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME ("trng") +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG (0) +#endif + +/*** @apache-mynewt-core/hw/bsp/nordic_pca10056 */ +#ifndef MYNEWT_VAL_BSP_NRF52840 +#define MYNEWT_VAL_BSP_NRF52840 (1) +#endif + +#ifndef MYNEWT_VAL_SOFT_PWM +#define MYNEWT_VAL_SOFT_PWM (0) +#endif + +/*** @apache-mynewt-core/hw/hal */ +#ifndef MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS +#define MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS (1) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ +#define MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ (16) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_SYSTEM_RESET_CB +#define MYNEWT_VAL_HAL_SYSTEM_RESET_CB (0) +#endif + +/*** @apache-mynewt-core/hw/mcu/nordic/nrf52xxx */ +#ifndef MYNEWT_VAL_ADC_0 +#define MYNEWT_VAL_ADC_0 (0) +#endif + +#ifndef MYNEWT_VAL_ADC_0_REFMV_0 +#define MYNEWT_VAL_ADC_0_REFMV_0 (0) +#endif + +#ifndef MYNEWT_VAL_CRYPTO +#define MYNEWT_VAL_CRYPTO (0) +#endif + +#ifndef MYNEWT_VAL_GPIO_AS_PIN_RESET +#define MYNEWT_VAL_GPIO_AS_PIN_RESET (0) +#endif + +#ifndef MYNEWT_VAL_I2C_0 +#define MYNEWT_VAL_I2C_0 (0) +#endif + +#ifndef MYNEWT_VAL_I2C_0_FREQ_KHZ +#define MYNEWT_VAL_I2C_0_FREQ_KHZ (100) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_I2C_0_PIN_SCL +#define MYNEWT_VAL_I2C_0_PIN_SCL (27) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_I2C_0_PIN_SDA +#define MYNEWT_VAL_I2C_0_PIN_SDA (26) +#endif + +#ifndef MYNEWT_VAL_I2C_1 +#define MYNEWT_VAL_I2C_1 (0) +#endif + +#ifndef MYNEWT_VAL_I2C_1_FREQ_KHZ +#define MYNEWT_VAL_I2C_1_FREQ_KHZ (100) +#endif + +#undef MYNEWT_VAL_I2C_1_PIN_SCL + +#undef MYNEWT_VAL_I2C_1_PIN_SDA + +#ifndef MYNEWT_VAL_MCU_BUS_DRIVER_I2C_USE_TWIM +#define MYNEWT_VAL_MCU_BUS_DRIVER_I2C_USE_TWIM (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_MCU_DCDC_ENABLED +#define MYNEWT_VAL_MCU_DCDC_ENABLED (1) +#endif + +#ifndef MYNEWT_VAL_MCU_DEBUG_IGNORE_BKPT +#define MYNEWT_VAL_MCU_DEBUG_IGNORE_BKPT (0) +#endif + +#ifndef MYNEWT_VAL_MCU_FLASH_MIN_WRITE_SIZE +#define MYNEWT_VAL_MCU_FLASH_MIN_WRITE_SIZE (1) +#endif + +#ifndef MYNEWT_VAL_MCU_GPIO_USE_PORT_EVENT +#define MYNEWT_VAL_MCU_GPIO_USE_PORT_EVENT (0) +#endif + +#ifndef MYNEWT_VAL_MCU_I2C_RECOVERY_DELAY_USEC +#define MYNEWT_VAL_MCU_I2C_RECOVERY_DELAY_USEC (100) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__LFRC +#define MYNEWT_VAL_MCU_LFCLK_SOURCE__LFRC (0) +#endif +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__LFSYNTH +#define MYNEWT_VAL_MCU_LFCLK_SOURCE__LFSYNTH (0) +#endif +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__LFXO +#define MYNEWT_VAL_MCU_LFCLK_SOURCE__LFXO (1) +#endif +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE +#define MYNEWT_VAL_MCU_LFCLK_SOURCE (1) +#endif + +#ifndef MYNEWT_VAL_MCU_NRF52832 +#define MYNEWT_VAL_MCU_NRF52832 (0) +#endif + +#ifndef MYNEWT_VAL_MCU_NRF52840 +#define MYNEWT_VAL_MCU_NRF52840 (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52810 +#define MYNEWT_VAL_MCU_TARGET__nRF52810 (0) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52811 +#define MYNEWT_VAL_MCU_TARGET__nRF52811 (0) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52832 +#define MYNEWT_VAL_MCU_TARGET__nRF52832 (0) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52840 +#define MYNEWT_VAL_MCU_TARGET__nRF52840 (1) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET +#define MYNEWT_VAL_MCU_TARGET (1) +#endif + +#ifndef MYNEWT_VAL_NFC_PINS_AS_GPIO +#define MYNEWT_VAL_NFC_PINS_AS_GPIO (1) +#endif + +#ifndef MYNEWT_VAL_PWM_0 +#define MYNEWT_VAL_PWM_0 (0) +#endif + +#ifndef MYNEWT_VAL_PWM_1 +#define MYNEWT_VAL_PWM_1 (0) +#endif + +#ifndef MYNEWT_VAL_PWM_2 +#define MYNEWT_VAL_PWM_2 (0) +#endif + +#ifndef MYNEWT_VAL_PWM_3 +#define MYNEWT_VAL_PWM_3 (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_ADDRMODE +#define MYNEWT_VAL_QSPI_ADDRMODE (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_DPMCONFIG +#define MYNEWT_VAL_QSPI_DPMCONFIG (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_ENABLE +#define MYNEWT_VAL_QSPI_ENABLE (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_FLASH_PAGE_SIZE +#define MYNEWT_VAL_QSPI_FLASH_PAGE_SIZE (256) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_FLASH_SECTOR_COUNT +#define MYNEWT_VAL_QSPI_FLASH_SECTOR_COUNT (4096) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_FLASH_SECTOR_SIZE +#define MYNEWT_VAL_QSPI_FLASH_SECTOR_SIZE (4096) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_CS +#define MYNEWT_VAL_QSPI_PIN_CS (17) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO0 +#define MYNEWT_VAL_QSPI_PIN_DIO0 (20) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO1 +#define MYNEWT_VAL_QSPI_PIN_DIO1 (21) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO2 +#define MYNEWT_VAL_QSPI_PIN_DIO2 (22) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO3 +#define MYNEWT_VAL_QSPI_PIN_DIO3 (23) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_SCK +#define MYNEWT_VAL_QSPI_PIN_SCK (19) +#endif + +#ifndef MYNEWT_VAL_QSPI_READOC +#define MYNEWT_VAL_QSPI_READOC (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_SCK_DELAY +#define MYNEWT_VAL_QSPI_SCK_DELAY (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_SCK_FREQ +#define MYNEWT_VAL_QSPI_SCK_FREQ (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_SPI_MODE +#define MYNEWT_VAL_QSPI_SPI_MODE (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_WRITEOC +#define MYNEWT_VAL_QSPI_WRITEOC (0) +#endif + +#ifndef MYNEWT_VAL_SPI_0_MASTER +#define MYNEWT_VAL_SPI_0_MASTER (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_MASTER_PIN_MISO +#define MYNEWT_VAL_SPI_0_MASTER_PIN_MISO (47) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_MASTER_PIN_MOSI +#define MYNEWT_VAL_SPI_0_MASTER_PIN_MOSI (46) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_MASTER_PIN_SCK +#define MYNEWT_VAL_SPI_0_MASTER_PIN_SCK (45) +#endif + +#ifndef MYNEWT_VAL_SPI_0_SLAVE +#define MYNEWT_VAL_SPI_0_SLAVE (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_MISO +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_MISO (47) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_MOSI +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_MOSI (46) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_SCK +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_SCK (45) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_SS +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_SS (44) +#endif + +#ifndef MYNEWT_VAL_SPI_1_MASTER +#define MYNEWT_VAL_SPI_1_MASTER (0) +#endif + +#undef MYNEWT_VAL_SPI_1_MASTER_PIN_MISO + +#undef MYNEWT_VAL_SPI_1_MASTER_PIN_MOSI + +#undef MYNEWT_VAL_SPI_1_MASTER_PIN_SCK + +#ifndef MYNEWT_VAL_SPI_1_SLAVE +#define MYNEWT_VAL_SPI_1_SLAVE (0) +#endif + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_MISO + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_MOSI + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_SCK + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_SS + +#ifndef MYNEWT_VAL_SPI_2_MASTER +#define MYNEWT_VAL_SPI_2_MASTER (0) +#endif + +#undef MYNEWT_VAL_SPI_2_MASTER_PIN_MISO + +#undef MYNEWT_VAL_SPI_2_MASTER_PIN_MOSI + +#undef MYNEWT_VAL_SPI_2_MASTER_PIN_SCK + +#ifndef MYNEWT_VAL_SPI_2_SLAVE +#define MYNEWT_VAL_SPI_2_SLAVE (0) +#endif + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_MISO + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_MOSI + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_SCK + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_SS + +#ifndef MYNEWT_VAL_SPI_3_MASTER +#define MYNEWT_VAL_SPI_3_MASTER (0) +#endif + +#undef MYNEWT_VAL_SPI_3_MASTER_PIN_MISO + +#undef MYNEWT_VAL_SPI_3_MASTER_PIN_MOSI + +#undef MYNEWT_VAL_SPI_3_MASTER_PIN_SCK + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_TIMER_0 +#define MYNEWT_VAL_TIMER_0 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_1 +#define MYNEWT_VAL_TIMER_1 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_2 +#define MYNEWT_VAL_TIMER_2 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_3 +#define MYNEWT_VAL_TIMER_3 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_4 +#define MYNEWT_VAL_TIMER_4 (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_TIMER_5 +#define MYNEWT_VAL_TIMER_5 (1) +#endif + +#ifndef MYNEWT_VAL_TRNG +#define MYNEWT_VAL_TRNG (0) +#endif + +#ifndef MYNEWT_VAL_UART_0 +#define MYNEWT_VAL_UART_0 (1) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_CTS +#define MYNEWT_VAL_UART_0_PIN_CTS (7) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_RTS +#define MYNEWT_VAL_UART_0_PIN_RTS (5) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_RX +#define MYNEWT_VAL_UART_0_PIN_RX (8) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_TX +#define MYNEWT_VAL_UART_0_PIN_TX (6) +#endif + +#ifndef MYNEWT_VAL_UART_1 +#define MYNEWT_VAL_UART_1 (0) +#endif + +#ifndef MYNEWT_VAL_UART_1_PIN_CTS +#define MYNEWT_VAL_UART_1_PIN_CTS (-1) +#endif + +#ifndef MYNEWT_VAL_UART_1_PIN_RTS +#define MYNEWT_VAL_UART_1_PIN_RTS (-1) +#endif + +#undef MYNEWT_VAL_UART_1_PIN_RX + +#undef MYNEWT_VAL_UART_1_PIN_TX + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_XTAL_32768 +#define MYNEWT_VAL_XTAL_32768 (1) +#endif + +#ifndef MYNEWT_VAL_XTAL_32768_SYNTH +#define MYNEWT_VAL_XTAL_32768_SYNTH (0) +#endif + +#ifndef MYNEWT_VAL_XTAL_RC +#define MYNEWT_VAL_XTAL_RC (0) +#endif + +/*** @apache-mynewt-core/kernel/os */ +#ifndef MYNEWT_VAL_FLOAT_USER +#define MYNEWT_VAL_FLOAT_USER (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_1_BLOCK_COUNT (5) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_1_BLOCK_SIZE (88) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_2_BLOCK_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_2_BLOCK_SIZE (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_SANITY_TIMEOUT +#define MYNEWT_VAL_MSYS_SANITY_TIMEOUT (60000) +#endif + +#ifndef MYNEWT_VAL_OS_ASSERT_CB +#define MYNEWT_VAL_OS_ASSERT_CB (0) +#endif + +#ifndef MYNEWT_VAL_OS_CLI +#define MYNEWT_VAL_OS_CLI (0) +#endif + +#ifndef MYNEWT_VAL_OS_COREDUMP +#define MYNEWT_VAL_OS_COREDUMP (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_OS_CPUTIME_FREQ +#define MYNEWT_VAL_OS_CPUTIME_FREQ (32768) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_OS_CPUTIME_TIMER_NUM +#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (5) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_FILE_LINE +#define MYNEWT_VAL_OS_CRASH_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_LOG +#define MYNEWT_VAL_OS_CRASH_LOG (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_RESTORE_REGS +#define MYNEWT_VAL_OS_CRASH_RESTORE_REGS (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_STACKTRACE +#define MYNEWT_VAL_OS_CRASH_STACKTRACE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_CHECK +#define MYNEWT_VAL_OS_CTX_SW_STACK_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_GUARD +#define MYNEWT_VAL_OS_CTX_SW_STACK_GUARD (4) +#endif + +#ifndef MYNEWT_VAL_OS_DEBUG_MODE +#define MYNEWT_VAL_OS_DEBUG_MODE (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_DEBUG +#define MYNEWT_VAL_OS_EVENTQ_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_MONITOR +#define MYNEWT_VAL_OS_EVENTQ_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX (600000) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN (100) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_STACK_SIZE +#define MYNEWT_VAL_OS_MAIN_STACK_SIZE (1024) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_PRIO +#define MYNEWT_VAL_OS_MAIN_TASK_PRIO (127) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS +#define MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_CHECK +#define MYNEWT_VAL_OS_MEMPOOL_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_GUARD +#define MYNEWT_VAL_OS_MEMPOOL_GUARD (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_POISON +#define MYNEWT_VAL_OS_MEMPOOL_POISON (0) +#endif + +#ifndef MYNEWT_VAL_OS_SCHEDULING +#define MYNEWT_VAL_OS_SCHEDULING (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSINIT_STAGE +#define MYNEWT_VAL_OS_SYSINIT_STAGE (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW +#define MYNEWT_VAL_OS_SYSVIEW (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM (1) +#endif + +#ifndef MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME +#define MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME (0) +#endif + +#ifndef MYNEWT_VAL_OS_TIME_DEBUG +#define MYNEWT_VAL_OS_TIME_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_WATCHDOG_MONITOR +#define MYNEWT_VAL_OS_WATCHDOG_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_SANITY_INTERVAL +#define MYNEWT_VAL_SANITY_INTERVAL (15000) +#endif + +#ifndef MYNEWT_VAL_WATCHDOG_INTERVAL +#define MYNEWT_VAL_WATCHDOG_INTERVAL (30000) +#endif + +/*** @apache-mynewt-core/libc/baselibc */ +#ifndef MYNEWT_VAL_BASELIBC_ASSERT_FILE_LINE +#define MYNEWT_VAL_BASELIBC_ASSERT_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_BASELIBC_PRESENT +#define MYNEWT_VAL_BASELIBC_PRESENT (1) +#endif + +/*** @apache-mynewt-core/sys/console/stub */ +#ifndef MYNEWT_VAL_CONSOLE_UART_BAUD +#define MYNEWT_VAL_CONSOLE_UART_BAUD (115200) +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_DEV +#define MYNEWT_VAL_CONSOLE_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL +#define MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL (UART_FLOW_CTL_NONE) +#endif + +/*** @apache-mynewt-core/sys/flash_map */ +#ifndef MYNEWT_VAL_FLASH_MAP_MAX_AREAS +#define MYNEWT_VAL_FLASH_MAP_MAX_AREAS (10) +#endif + +#ifndef MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE +#define MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE (2) +#endif + +/*** @apache-mynewt-core/sys/log/common */ +#ifndef MYNEWT_VAL_DFLT_LOG_LVL +#define MYNEWT_VAL_DFLT_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_DFLT_LOG_MOD +#define MYNEWT_VAL_DFLT_LOG_MOD (0) +#endif + +#ifndef MYNEWT_VAL_LOG_GLOBAL_IDX +#define MYNEWT_VAL_LOG_GLOBAL_IDX (1) +#endif + +/*** @apache-mynewt-core/sys/log/modlog */ +#ifndef MYNEWT_VAL_MODLOG_CONSOLE_DFLT +#define MYNEWT_VAL_MODLOG_CONSOLE_DFLT (1) +#endif + +#ifndef MYNEWT_VAL_MODLOG_LOG_MACROS +#define MYNEWT_VAL_MODLOG_LOG_MACROS (0) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_MAPPINGS +#define MYNEWT_VAL_MODLOG_MAX_MAPPINGS (16) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN +#define MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN (128) +#endif + +#ifndef MYNEWT_VAL_MODLOG_SYSINIT_STAGE +#define MYNEWT_VAL_MODLOG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/log/stub */ +#ifndef MYNEWT_VAL_LOG_CONSOLE +#define MYNEWT_VAL_LOG_CONSOLE (1) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB +#define MYNEWT_VAL_LOG_FCB (0) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB_SLOT1 +#define MYNEWT_VAL_LOG_FCB_SLOT1 (0) +#endif + +#ifndef MYNEWT_VAL_LOG_LEVEL +#define MYNEWT_VAL_LOG_LEVEL (0) +#endif + +/*** @apache-mynewt-core/sys/mfg */ +#ifndef MYNEWT_VAL_MFG_LOG_LVL +#define MYNEWT_VAL_MFG_LOG_LVL (15) +#endif + +#ifndef MYNEWT_VAL_MFG_LOG_MODULE +#define MYNEWT_VAL_MFG_LOG_MODULE (128) +#endif + +#ifndef MYNEWT_VAL_MFG_MAX_MMRS +#define MYNEWT_VAL_MFG_MAX_MMRS (2) +#endif + +#ifndef MYNEWT_VAL_MFG_SYSINIT_STAGE +#define MYNEWT_VAL_MFG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/sys */ +#ifndef MYNEWT_VAL_DEBUG_PANIC_ENABLED +#define MYNEWT_VAL_DEBUG_PANIC_ENABLED (1) +#endif + +/*** @apache-mynewt-core/sys/sysdown */ +#ifndef MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN +#define MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN (1) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE +#define MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_TIMEOUT_MS +#define MYNEWT_VAL_SYSDOWN_TIMEOUT_MS (10000) +#endif + +/*** @apache-mynewt-core/sys/sysinit */ +#ifndef MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT +#define MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT (1) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_MESSAGE +#define MYNEWT_VAL_SYSINIT_PANIC_MESSAGE (0) +#endif + +/*** @apache-mynewt-core/util/rwlock */ +#ifndef MYNEWT_VAL_RWLOCK_DEBUG +#define MYNEWT_VAL_RWLOCK_DEBUG (0) +#endif + +/*** @apache-mynewt-nimble/nimble */ +#ifndef MYNEWT_VAL_BLE_EXT_ADV +#define MYNEWT_VAL_BLE_EXT_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE +#define MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE (31) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_CONNECTIONS +#define MYNEWT_VAL_BLE_MAX_CONNECTIONS (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble) */ +#ifndef MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS +#define MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES +#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV +#define MYNEWT_VAL_BLE_PERIODIC_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER +#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_CENTRAL +#define MYNEWT_VAL_BLE_ROLE_CENTRAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_OBSERVER +#define MYNEWT_VAL_BLE_ROLE_OBSERVER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_PERIPHERAL +#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_VERSION +#define MYNEWT_VAL_BLE_VERSION (50) +#endif + +#ifndef MYNEWT_VAL_BLE_WHITELIST +#define MYNEWT_VAL_BLE_WHITELIST (1) +#endif + +/*** @apache-mynewt-nimble/nimble/controller */ +#ifndef MYNEWT_VAL_BLE_CONTROLLER +#define MYNEWT_VAL_BLE_CONTROLLER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_DEVICE +#define MYNEWT_VAL_BLE_DEVICE (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_HW_WHITELIST_ENABLE +#define MYNEWT_VAL_BLE_HW_WHITELIST_ENABLE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_ADD_STRICT_SCHED_PERIODS +#define MYNEWT_VAL_BLE_LL_ADD_STRICT_SCHED_PERIODS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_CONN_PARAM_REQ +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_CONN_PARAM_REQ (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_DATA_LEN_EXT +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_DATA_LEN_EXT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_EXT_SCAN_FILT +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_EXT_SCAN_FILT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_2M_PHY +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_2M_PHY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CODED_PHY +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CODED_PHY (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CSA2 +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CSA2 (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION (1) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_PING +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_PING (MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION) +#endif + +/* Value copied from BLE_EXT_ADV */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_EXT_ADV +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_EXT_ADV (0) +#endif + +/* Value copied from BLE_PERIODIC_ADV */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV (0) +#endif + +/* Value copied from BLE_MAX_PERIODIC_SYNCS */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_CNT +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_CNT (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PRIVACY +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PRIVACY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_MAX_TX_BYTES +#define MYNEWT_VAL_BLE_LL_CONN_INIT_MAX_TX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_MIN_WIN_OFFSET +#define MYNEWT_VAL_BLE_LL_CONN_INIT_MIN_WIN_OFFSET (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS +#define MYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DBG_HCI_CMD_PIN +#define MYNEWT_VAL_BLE_LL_DBG_HCI_CMD_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DBG_HCI_EV_PIN +#define MYNEWT_VAL_BLE_LL_DBG_HCI_EV_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DIRECT_TEST_MODE +#define MYNEWT_VAL_BLE_LL_DIRECT_TEST_MODE (0) +#endif + +/* Value copied from BLE_LL_DIRECT_TEST_MODE */ +#ifndef MYNEWT_VAL_BLE_LL_DTM +#define MYNEWT_VAL_BLE_LL_DTM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DTM_EXTENSIONS +#define MYNEWT_VAL_BLE_LL_DTM_EXTENSIONS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_EXT_ADV_AUX_PTR_CNT +#define MYNEWT_VAL_BLE_LL_EXT_ADV_AUX_PTR_CNT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MASTER_SCA +#define MYNEWT_VAL_BLE_LL_MASTER_SCA (4) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE +#define MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE (251) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MFRG_ID +#define MYNEWT_VAL_BLE_LL_MFRG_ID (0xFFFF) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_COMP_PKT_ITVL_MS +#define MYNEWT_VAL_BLE_LL_NUM_COMP_PKT_ITVL_MS (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_SCAN_DUP_ADVS +#define MYNEWT_VAL_BLE_LL_NUM_SCAN_DUP_ADVS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_SCAN_RSP_ADVS +#define MYNEWT_VAL_BLE_LL_NUM_SCAN_RSP_ADVS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_OUR_SCA +#define MYNEWT_VAL_BLE_LL_OUR_SCA (60) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_PRIO +#define MYNEWT_VAL_BLE_LL_PRIO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_RESOLV_LIST_SIZE +#define MYNEWT_VAL_BLE_LL_RESOLV_LIST_SIZE (4) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_RNG_BUFSIZE +#define MYNEWT_VAL_BLE_LL_RNG_BUFSIZE (32) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY +#define MYNEWT_VAL_BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SCHED_AUX_MAFS_DELAY +#define MYNEWT_VAL_BLE_LL_SCHED_AUX_MAFS_DELAY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_STRICT_CONN_SCHEDULING +#define MYNEWT_VAL_BLE_LL_STRICT_CONN_SCHEDULING (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SUPP_MAX_RX_BYTES +#define MYNEWT_VAL_BLE_LL_SUPP_MAX_RX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SUPP_MAX_TX_BYTES +#define MYNEWT_VAL_BLE_LL_SUPP_MAX_TX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_LL_SYSINIT_STAGE (250) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SYSVIEW +#define MYNEWT_VAL_BLE_LL_SYSVIEW (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_TX_PWR_DBM +#define MYNEWT_VAL_BLE_LL_TX_PWR_DBM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_USECS_PER_PERIOD +#define MYNEWT_VAL_BLE_LL_USECS_PER_PERIOD (3250) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_VND_EVENT_ON_ASSERT +#define MYNEWT_VAL_BLE_LL_VND_EVENT_ON_ASSERT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_WHITELIST_SIZE +#define MYNEWT_VAL_BLE_LL_WHITELIST_SIZE (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LP_CLOCK +#define MYNEWT_VAL_BLE_LP_CLOCK (1) +#endif + +#ifndef MYNEWT_VAL_BLE_NUM_COMP_PKT_RATE +#define MYNEWT_VAL_BLE_NUM_COMP_PKT_RATE ((2 * OS_TICKS_PER_SEC)) +#endif + +#ifndef MYNEWT_VAL_BLE_PUBLIC_DEV_ADDR +#define MYNEWT_VAL_BLE_PUBLIC_DEV_ADDR ((uint8_t[6]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_XTAL_SETTLE_TIME +#define MYNEWT_VAL_BLE_XTAL_SETTLE_TIME (1500) +#endif + +/*** @apache-mynewt-nimble/nimble/drivers/nrf52 */ +#ifndef MYNEWT_VAL_BLE_PHY_CODED_RX_IFS_EXTRA_MARGIN +#define MYNEWT_VAL_BLE_PHY_CODED_RX_IFS_EXTRA_MARGIN (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_ADDRESS_END_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_ADDRESS_END_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_TXRXEN_READY_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_TXRXEN_READY_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_WFR_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_WFR_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_164 +#define MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_164 (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_191 +#define MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_191 (1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_SYSVIEW +#define MYNEWT_VAL_BLE_PHY_SYSVIEW (0) +#endif + +/*** @apache-mynewt-nimble/nimble/host */ +#ifndef MYNEWT_VAL_BLE_ATT_PREFERRED_MTU +#define MYNEWT_VAL_BLE_ATT_PREFERRED_MTU (256) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_INDICATE +#define MYNEWT_VAL_BLE_ATT_SVR_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES +#define MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES (64) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_NOTIFY +#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ +#define MYNEWT_VAL_BLE_ATT_SVR_READ (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB +#define MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_MULT +#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE +#define MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS +#define MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_INDICATE +#define MYNEWT_VAL_BLE_GATT_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_MAX_PROCS +#define MYNEWT_VAL_BLE_GATT_MAX_PROCS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_NOTIFY +#define MYNEWT_VAL_BLE_GATT_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ +#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_LONG +#define MYNEWT_VAL_BLE_GATT_READ_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MULT +#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_UUID +#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_RESUME_RATE +#define MYNEWT_VAL_BLE_GATT_RESUME_RATE (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_SIGNED_WRITE +#define MYNEWT_VAL_BLE_GATT_SIGNED_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE +#define MYNEWT_VAL_BLE_GATT_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_LONG +#define MYNEWT_VAL_BLE_GATT_WRITE_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE +#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_HOST +#define MYNEWT_VAL_BLE_HOST (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_AUTO_START +#define MYNEWT_VAL_BLE_HS_AUTO_START (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_DEBUG +#define MYNEWT_VAL_BLE_HS_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH (2) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_LVL +#define MYNEWT_VAL_BLE_HS_LOG_LVL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_MOD +#define MYNEWT_VAL_BLE_HS_LOG_MOD (4) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS +#define MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_REQUIRE_OS +#define MYNEWT_VAL_BLE_HS_REQUIRE_OS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_HS_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM +#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MPS +#define MYNEWT_VAL_BLE_L2CAP_COC_MPS (MYNEWT_VAL_MSYS_1_BLOCK_SIZE-8) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS +#define MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_MAX_CHANS +#define MYNEWT_VAL_BLE_L2CAP_MAX_CHANS (3*MYNEWT_VAL_BLE_MAX_CONNECTIONS) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT +#define MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS +#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH +#define MYNEWT_VAL_BLE_MESH (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE (128) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT +#define MYNEWT_VAL_BLE_MONITOR_RTT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME ("btmonitor") +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE (256) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART +#define MYNEWT_VAL_BLE_MONITOR_UART (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE +#define MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE (1000000) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE (64) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_DEV +#define MYNEWT_VAL_BLE_MONITOR_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_BLE_RPA_TIMEOUT +#define MYNEWT_VAL_BLE_RPA_TIMEOUT (300) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_BONDING +#define MYNEWT_VAL_BLE_SM_BONDING (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_IO_CAP +#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_NO_INPUT_OUTPUT) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_KEYPRESS +#define MYNEWT_VAL_BLE_SM_KEYPRESS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_LEGACY +#define MYNEWT_VAL_BLE_SM_LEGACY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MAX_PROCS +#define MYNEWT_VAL_BLE_SM_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MITM +#define MYNEWT_VAL_BLE_SM_MITM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG +#define MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OUR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_OUR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC +#define MYNEWT_VAL_BLE_SM_SC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS +#define MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_BONDS +#define MYNEWT_VAL_BLE_STORE_MAX_BONDS (3) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_CCCDS +#define MYNEWT_VAL_BLE_STORE_MAX_CCCDS (8) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gap */ +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION +#define MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME ("nimble") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH (31) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE (301) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gatt */ +#ifndef MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE (302) +#endif + +/*** @apache-mynewt-nimble/nimble/transport/ram */ +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/transport/ram) */ +#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT +#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (4) +#endif + +#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE +#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE +#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/transport/ram) */ +#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (2) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_TRANS_RAM_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_TRANS_RAM_SYSINIT_STAGE (100) +#endif + +/*** newt */ +#ifndef MYNEWT_VAL_APP_NAME +#define MYNEWT_VAL_APP_NAME ("dummy_app") +#endif + +#ifndef MYNEWT_VAL_APP_dummy_app +#define MYNEWT_VAL_APP_dummy_app (1) +#endif + +#ifndef MYNEWT_VAL_ARCH_NAME +#define MYNEWT_VAL_ARCH_NAME ("cortex_m4") +#endif + +#ifndef MYNEWT_VAL_ARCH_cortex_m4 +#define MYNEWT_VAL_ARCH_cortex_m4 (1) +#endif + +#ifndef MYNEWT_VAL_BSP_NAME +#define MYNEWT_VAL_BSP_NAME ("nordic_pca10056") +#endif + +#ifndef MYNEWT_VAL_BSP_nordic_pca10056 +#define MYNEWT_VAL_BSP_nordic_pca10056 (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_LOGCFG +#define MYNEWT_VAL_NEWT_FEATURE_LOGCFG (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_SYSDOWN +#define MYNEWT_VAL_NEWT_FEATURE_SYSDOWN (1) +#endif + +#ifndef MYNEWT_VAL_TARGET_NAME +#define MYNEWT_VAL_TARGET_NAME ("riot") +#endif + +#ifndef MYNEWT_VAL_TARGET_riot +#define MYNEWT_VAL_TARGET_riot (1) +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/syscfg/syscfg.old.txt b/src/libs/mynewt-nimble/porting/nimble/include/syscfg/syscfg.old.txt new file mode 100644 index 00000000..aa1d22a5 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/syscfg/syscfg.old.txt @@ -0,0 +1,1089 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSCFG_ +#define H_MYNEWT_SYSCFG_ + +/** + * This macro exists to ensure code includes this header when needed. If code + * checks the existence of a setting directly via ifdef without including this + * header, the setting macro will silently evaluate to 0. In contrast, an + * attempt to use these macros without including this header will result in a + * compiler error. + */ +#define MYNEWT_VAL(_name) MYNEWT_VAL_ ## _name +#define MYNEWT_VAL_CHOICE(_name, _val) MYNEWT_VAL_ ## _name ## __ ## _val + + + +/*** @apache-mynewt-core/crypto/tinycrypt */ +#ifndef MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE +#define MYNEWT_VAL_TINYCRYPT_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_TRNG_DEV_NAME ("trng") +#endif + +#ifndef MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG +#define MYNEWT_VAL_TINYCRYPT_UECC_RNG_USE_TRNG (0) +#endif + +/*** @apache-mynewt-core/hw/hal */ +#ifndef MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS +#define MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS (1) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ +#define MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ (16) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_SYSTEM_RESET_CB +#define MYNEWT_VAL_HAL_SYSTEM_RESET_CB (0) +#endif + +/*** @apache-mynewt-core/kernel/os */ +#ifndef MYNEWT_VAL_FLOAT_USER +#define MYNEWT_VAL_FLOAT_USER (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_1_BLOCK_COUNT (12) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_1_BLOCK_SIZE (292) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_2_BLOCK_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_2_BLOCK_SIZE (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_SANITY_TIMEOUT +#define MYNEWT_VAL_MSYS_SANITY_TIMEOUT (60000) +#endif + +#ifndef MYNEWT_VAL_OS_ASSERT_CB +#define MYNEWT_VAL_OS_ASSERT_CB (0) +#endif + +#ifndef MYNEWT_VAL_OS_CLI +#define MYNEWT_VAL_OS_CLI (0) +#endif + +#ifndef MYNEWT_VAL_OS_COREDUMP +#define MYNEWT_VAL_OS_COREDUMP (0) +#endif + +#ifndef MYNEWT_VAL_OS_CPUTIME_FREQ +#define MYNEWT_VAL_OS_CPUTIME_FREQ (32768) +#endif + +#ifndef MYNEWT_VAL_OS_CPUTIME_TIMER_NUM +#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_FILE_LINE +#define MYNEWT_VAL_OS_CRASH_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_LOG +#define MYNEWT_VAL_OS_CRASH_LOG (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_RESTORE_REGS +#define MYNEWT_VAL_OS_CRASH_RESTORE_REGS (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_STACKTRACE +#define MYNEWT_VAL_OS_CRASH_STACKTRACE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_CHECK +#define MYNEWT_VAL_OS_CTX_SW_STACK_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_GUARD +#define MYNEWT_VAL_OS_CTX_SW_STACK_GUARD (4) +#endif + +#ifndef MYNEWT_VAL_OS_DEBUG_MODE +#define MYNEWT_VAL_OS_DEBUG_MODE (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_DEBUG +#define MYNEWT_VAL_OS_EVENTQ_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_MONITOR +#define MYNEWT_VAL_OS_EVENTQ_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX (600000) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN (100) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_STACK_SIZE +#define MYNEWT_VAL_OS_MAIN_STACK_SIZE (1024) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_PRIO +#define MYNEWT_VAL_OS_MAIN_TASK_PRIO (127) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS +#define MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_CHECK +#define MYNEWT_VAL_OS_MEMPOOL_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_GUARD +#define MYNEWT_VAL_OS_MEMPOOL_GUARD (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_POISON +#define MYNEWT_VAL_OS_MEMPOOL_POISON (0) +#endif + +#ifndef MYNEWT_VAL_OS_SCHEDULING +#define MYNEWT_VAL_OS_SCHEDULING (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSINIT_STAGE +#define MYNEWT_VAL_OS_SYSINIT_STAGE (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW +#define MYNEWT_VAL_OS_SYSVIEW (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM (1) +#endif + +#ifndef MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME +#define MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME (0) +#endif + +#ifndef MYNEWT_VAL_OS_TIME_DEBUG +#define MYNEWT_VAL_OS_TIME_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_WATCHDOG_MONITOR +#define MYNEWT_VAL_OS_WATCHDOG_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_SANITY_INTERVAL +#define MYNEWT_VAL_SANITY_INTERVAL (15000) +#endif + +#ifndef MYNEWT_VAL_WATCHDOG_INTERVAL +#define MYNEWT_VAL_WATCHDOG_INTERVAL (30000) +#endif + +/*** @apache-mynewt-core/sys/console/stub */ +#ifndef MYNEWT_VAL_CONSOLE_UART_BAUD +#define MYNEWT_VAL_CONSOLE_UART_BAUD (115200) +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_DEV +#define MYNEWT_VAL_CONSOLE_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL +#define MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL (UART_FLOW_CTL_NONE) +#endif + +/*** @apache-mynewt-core/sys/flash_map */ +#ifndef MYNEWT_VAL_FLASH_MAP_MAX_AREAS +#define MYNEWT_VAL_FLASH_MAP_MAX_AREAS (10) +#endif + +#ifndef MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE +#define MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE (2) +#endif + +/*** @apache-mynewt-core/sys/log/common */ +#ifndef MYNEWT_VAL_DFLT_LOG_LVL +#define MYNEWT_VAL_DFLT_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_DFLT_LOG_MOD +#define MYNEWT_VAL_DFLT_LOG_MOD (0) +#endif + +#ifndef MYNEWT_VAL_LOG_GLOBAL_IDX +#define MYNEWT_VAL_LOG_GLOBAL_IDX (1) +#endif + +/*** @apache-mynewt-core/sys/log/modlog */ +#ifndef MYNEWT_VAL_MODLOG_CONSOLE_DFLT +#define MYNEWT_VAL_MODLOG_CONSOLE_DFLT (1) +#endif + +#ifndef MYNEWT_VAL_MODLOG_LOG_MACROS +#define MYNEWT_VAL_MODLOG_LOG_MACROS (0) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_MAPPINGS +#define MYNEWT_VAL_MODLOG_MAX_MAPPINGS (16) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN +#define MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN (128) +#endif + +#ifndef MYNEWT_VAL_MODLOG_SYSINIT_STAGE +#define MYNEWT_VAL_MODLOG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/log/stub */ +#ifndef MYNEWT_VAL_LOG_CONSOLE +#define MYNEWT_VAL_LOG_CONSOLE (1) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB +#define MYNEWT_VAL_LOG_FCB (0) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB_SLOT1 +#define MYNEWT_VAL_LOG_FCB_SLOT1 (0) +#endif + +#ifndef MYNEWT_VAL_LOG_LEVEL +#define MYNEWT_VAL_LOG_LEVEL (255) +#endif + +/*** @apache-mynewt-core/sys/mfg */ +#ifndef MYNEWT_VAL_MFG_LOG_LVL +#define MYNEWT_VAL_MFG_LOG_LVL (15) +#endif + +#ifndef MYNEWT_VAL_MFG_LOG_MODULE +#define MYNEWT_VAL_MFG_LOG_MODULE (128) +#endif + +#ifndef MYNEWT_VAL_MFG_MAX_MMRS +#define MYNEWT_VAL_MFG_MAX_MMRS (2) +#endif + +#ifndef MYNEWT_VAL_MFG_SYSINIT_STAGE +#define MYNEWT_VAL_MFG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/sys */ +#ifndef MYNEWT_VAL_DEBUG_PANIC_ENABLED +#define MYNEWT_VAL_DEBUG_PANIC_ENABLED (1) +#endif + +/*** @apache-mynewt-core/sys/sysdown */ +#ifndef MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN +#define MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN (1) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE +#define MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_TIMEOUT_MS +#define MYNEWT_VAL_SYSDOWN_TIMEOUT_MS (10000) +#endif + +/*** @apache-mynewt-core/sys/sysinit */ +#ifndef MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT +#define MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT (1) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_MESSAGE +#define MYNEWT_VAL_SYSINIT_PANIC_MESSAGE (0) +#endif + +/*** @apache-mynewt-core/util/rwlock */ +#ifndef MYNEWT_VAL_RWLOCK_DEBUG +#define MYNEWT_VAL_RWLOCK_DEBUG (0) +#endif + +/*** @apache-mynewt-nimble/nimble */ +#ifndef MYNEWT_VAL_BLE_EXT_ADV +#define MYNEWT_VAL_BLE_EXT_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE +#define MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE (31) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_CONNECTIONS +#define MYNEWT_VAL_BLE_MAX_CONNECTIONS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS +#define MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES +#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV +#define MYNEWT_VAL_BLE_PERIODIC_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER +#define MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER (0) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER +#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_CENTRAL +#define MYNEWT_VAL_BLE_ROLE_CENTRAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_OBSERVER +#define MYNEWT_VAL_BLE_ROLE_OBSERVER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_PERIPHERAL +#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_VERSION +#define MYNEWT_VAL_BLE_VERSION (50) +#endif + +#ifndef MYNEWT_VAL_BLE_WHITELIST +#define MYNEWT_VAL_BLE_WHITELIST (1) +#endif + +/*** @apache-mynewt-nimble/nimble/host */ +#ifndef MYNEWT_VAL_BLE_ATT_PREFERRED_MTU +#define MYNEWT_VAL_BLE_ATT_PREFERRED_MTU (256) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_INDICATE +#define MYNEWT_VAL_BLE_ATT_SVR_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES +#define MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES (64) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_NOTIFY +#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ +#define MYNEWT_VAL_BLE_ATT_SVR_READ (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB +#define MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_MULT +#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE +#define MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS +#define MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_INDICATE +#define MYNEWT_VAL_BLE_GATT_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_MAX_PROCS +#define MYNEWT_VAL_BLE_GATT_MAX_PROCS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_NOTIFY +#define MYNEWT_VAL_BLE_GATT_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ +#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_LONG +#define MYNEWT_VAL_BLE_GATT_READ_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MULT +#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_UUID +#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_RESUME_RATE +#define MYNEWT_VAL_BLE_GATT_RESUME_RATE (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_SIGNED_WRITE +#define MYNEWT_VAL_BLE_GATT_SIGNED_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE +#define MYNEWT_VAL_BLE_GATT_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_LONG +#define MYNEWT_VAL_BLE_GATT_WRITE_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE +#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_HOST +#define MYNEWT_VAL_BLE_HOST (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_AUTO_START +#define MYNEWT_VAL_BLE_HS_AUTO_START (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_DEBUG +#define MYNEWT_VAL_BLE_HS_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH (2) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_LVL +#define MYNEWT_VAL_BLE_HS_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_MOD +#define MYNEWT_VAL_BLE_HS_LOG_MOD (4) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS +#define MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_REQUIRE_OS +#define MYNEWT_VAL_BLE_HS_REQUIRE_OS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_HS_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM +#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MPS +#define MYNEWT_VAL_BLE_L2CAP_COC_MPS (MYNEWT_VAL_MSYS_1_BLOCK_SIZE-8) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC +#define MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS +#define MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_MAX_CHANS +#define MYNEWT_VAL_BLE_L2CAP_MAX_CHANS (3*MYNEWT_VAL_BLE_MAX_CONNECTIONS) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT +#define MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS +#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH +#define MYNEWT_VAL_BLE_MESH (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE (128) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT +#define MYNEWT_VAL_BLE_MONITOR_RTT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME ("btmonitor") +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE (256) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART +#define MYNEWT_VAL_BLE_MONITOR_UART (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE +#define MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE (1000000) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE (64) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_DEV +#define MYNEWT_VAL_BLE_MONITOR_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_BLE_RPA_TIMEOUT +#define MYNEWT_VAL_BLE_RPA_TIMEOUT (300) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_BONDING +#define MYNEWT_VAL_BLE_SM_BONDING (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_IO_CAP +#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_NO_INPUT_OUTPUT) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_KEYPRESS +#define MYNEWT_VAL_BLE_SM_KEYPRESS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_LEGACY +#define MYNEWT_VAL_BLE_SM_LEGACY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MAX_PROCS +#define MYNEWT_VAL_BLE_SM_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MITM +#define MYNEWT_VAL_BLE_SM_MITM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG +#define MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OUR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_OUR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC +#define MYNEWT_VAL_BLE_SM_SC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS +#define MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_BONDS +#define MYNEWT_VAL_BLE_STORE_MAX_BONDS (3) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_CCCDS +#define MYNEWT_VAL_BLE_STORE_MAX_CCCDS (8) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ans */ +#ifndef MYNEWT_VAL_BLE_SVC_ANS_NEW_ALERT_CAT +#define MYNEWT_VAL_BLE_SVC_ANS_NEW_ALERT_CAT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_ANS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_ANS_SYSINIT_STAGE (303) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_ANS_UNR_ALERT_CAT +#define MYNEWT_VAL_BLE_SVC_ANS_UNR_ALERT_CAT (0) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/bas */ +#ifndef MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_NOTIFY_ENABLE +#define MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_NOTIFY_ENABLE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_READ_PERM +#define MYNEWT_VAL_BLE_SVC_BAS_BATTERY_LEVEL_READ_PERM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_BAS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_BAS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/dis */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_DEFAULT_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_DEFAULT_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_FIRMWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_HARDWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_MANUFACTURER_NAME_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_DEFAULT ("Apache Mynewt NimBLE") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_MODEL_NUMBER_READ_PERM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SERIAL_NUMBER_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SOFTWARE_REVISION_READ_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_DIS_SYSINIT_STAGE (303) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_DEFAULT +#define MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_DEFAULT (NULL) +#endif + +/* Value copied from BLE_SVC_DIS_DEFAULT_READ_PERM */ +#ifndef MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_READ_PERM +#define MYNEWT_VAL_BLE_SVC_DIS_SYSTEM_ID_READ_PERM (-1) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gap */ +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION +#define MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME ("nimble") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH (31) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE (301) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gatt */ +#ifndef MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE (302) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ias */ +#ifndef MYNEWT_VAL_BLE_SVC_IAS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_IAS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/ipss */ +#ifndef MYNEWT_VAL_BLE_SVC_IPSS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_IPSS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/lls */ +#ifndef MYNEWT_VAL_BLE_SVC_LLS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_LLS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/tps */ +#ifndef MYNEWT_VAL_BLE_SVC_TPS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_TPS_SYSINIT_STAGE (303) +#endif + +/*** @apache-mynewt-nimble/nimble/transport/socket */ +#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT +#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (24) +#endif + +#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE +#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT +#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE +#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SOCK_CLI_SYSINIT_STAGE (500) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_LINUX_DEV +#define MYNEWT_VAL_BLE_SOCK_LINUX_DEV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_STACK_SIZE +#define MYNEWT_VAL_BLE_SOCK_STACK_SIZE (80) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_TASK_PRIO +#define MYNEWT_VAL_BLE_SOCK_TASK_PRIO (9) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_TCP_PORT +#define MYNEWT_VAL_BLE_SOCK_TCP_PORT (14433) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_USE_LINUX_BLUE +#define MYNEWT_VAL_BLE_SOCK_USE_LINUX_BLUE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SOCK_USE_TCP +#define MYNEWT_VAL_BLE_SOCK_USE_TCP (1) +#endif + +/*** newt */ +#ifndef MYNEWT_VAL_APP_NAME +#define MYNEWT_VAL_APP_NAME ("dummy_app") +#endif + +#ifndef MYNEWT_VAL_APP_dummy_app +#define MYNEWT_VAL_APP_dummy_app (1) +#endif + +#ifndef MYNEWT_VAL_ARCH_NAME +#define MYNEWT_VAL_ARCH_NAME ("dummy") +#endif + +#ifndef MYNEWT_VAL_ARCH_dummy +#define MYNEWT_VAL_ARCH_dummy (1) +#endif + +#ifndef MYNEWT_VAL_BSP_NAME +#define MYNEWT_VAL_BSP_NAME ("dummy_bsp") +#endif + +#ifndef MYNEWT_VAL_BSP_dummy_bsp +#define MYNEWT_VAL_BSP_dummy_bsp (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_LOGCFG +#define MYNEWT_VAL_NEWT_FEATURE_LOGCFG (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_SYSDOWN +#define MYNEWT_VAL_NEWT_FEATURE_SYSDOWN (1) +#endif + +#ifndef MYNEWT_VAL_TARGET_NAME +#define MYNEWT_VAL_TARGET_NAME ("porting_default") +#endif + +#ifndef MYNEWT_VAL_TARGET_porting_default +#define MYNEWT_VAL_TARGET_porting_default (1) +#endif + +// added by JF +#ifndef MYNEWT_VAL_BLE_LL_TX_PWR_DBM +#define MYNEWT_VAL_BLE_LL_TX_PWR_DBM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PUBLIC_DEV_ADDR +#define MYNEWT_VAL_BLE_PUBLIC_DEV_ADDR ((uint8_t[6]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_RNG_BUFSIZE +#define MYNEWT_VAL_BLE_LL_RNG_BUFSIZE (32) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MASTER_SCA +#define MYNEWT_VAL_BLE_LL_MASTER_SCA (4) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS +#define MYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE +#define MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE (251) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SUPP_MAX_RX_BYTES +#define MYNEWT_VAL_BLE_LL_SUPP_MAX_RX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SUPP_MAX_TX_BYTES +#define MYNEWT_VAL_BLE_LL_SUPP_MAX_TX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_MAX_TX_BYTES +#define MYNEWT_VAL_BLE_LL_CONN_INIT_MAX_TX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_TXRXEN_READY_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_TXRXEN_READY_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_ADDRESS_END_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_ADDRESS_END_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_WFR_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_WFR_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MFRG_ID +#define MYNEWT_VAL_BLE_LL_MFRG_ID (0xFFFF) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_COMP_PKT_ITVL_MS +#define MYNEWT_VAL_BLE_LL_NUM_COMP_PKT_ITVL_MS (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_OUR_SCA +#define MYNEWT_VAL_BLE_LL_OUR_SCA (60) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_SCAN_RSP_ADVS +#define MYNEWT_VAL_BLE_LL_NUM_SCAN_RSP_ADVS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_SCAN_DUP_ADVS +#define MYNEWT_VAL_BLE_LL_NUM_SCAN_DUP_ADVS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_WHITELIST_SIZE +#define MYNEWT_VAL_BLE_LL_WHITELIST_SIZE (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_MIN_WIN_OFFSET +#define MYNEWT_VAL_BLE_LL_CONN_INIT_MIN_WIN_OFFSET (0) +#endif + +#ifndef MYNEWT_VAL_BLE_CONTROLLER +#define MYNEWT_VAL_BLE_CONTROLLER (1) +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/sysflash/sysflash.h b/src/libs/mynewt-nimble/porting/nimble/include/sysflash/sysflash.h new file mode 100644 index 00000000..413cb267 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/sysflash/sysflash.h @@ -0,0 +1,24 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSFLASH_ +#define H_MYNEWT_SYSFLASH_ + +#include "flash_map/flash_map.h" + +/** + * This flash map definition is used for two purposes: + * 1. To locate the meta area, which contains the true flash map definition. + * 2. As a fallback in case the meta area cannot be read from flash. + */ +extern const struct flash_area sysflash_map_dflt[6]; + +#define FLASH_AREA_BOOTLOADER 0 +#define FLASH_AREA_IMAGE_0 1 +#define FLASH_AREA_IMAGE_1 2 +#define FLASH_AREA_IMAGE_SCRATCH 3 +#define FLASH_AREA_REBOOT_LOG 16 +#define FLASH_AREA_NFFS 17 + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/include/sysinit/sysinit.h b/src/libs/mynewt-nimble/porting/nimble/include/sysinit/sysinit.h new file mode 100644 index 00000000..d2a806ab --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/include/sysinit/sysinit.h @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef __SYSINIT_H__ +#define __SYSINIT_H__ + +#include <assert.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define SYSINIT_ASSERT_ACTIVE() + +#define SYSINIT_PANIC_ASSERT(rc) assert(rc); + +#ifdef __cplusplus +} +#endif + +#endif /* __SYSINIT_H__ */ diff --git a/src/libs/mynewt-nimble/porting/nimble/pkg.yml b/src/libs/mynewt-nimble/porting/nimble/pkg.yml new file mode 100644 index 00000000..d56c90db --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/pkg.yml @@ -0,0 +1,43 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: porting/nimble +pkg.type: app +pkg.description: Stub for NimBLE porting +pkg.author: "Apache Mynewt <dev@mynewt.incubator.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - nimble/host + - nimble/host/services/ans + - nimble/host/services/bas + - nimble/host/services/gap + - nimble/host/services/gatt + - nimble/host/services/ias + - nimble/host/services/lls + - nimble/host/services/tps + - nimble/transport + - "@apache-mynewt-core/sys/console/stub" + - "@apache-mynewt-core/sys/log/stub" + - "@apache-mynewt-core/sys/stats/stub" + +# No need to build files from this package +pkg.ign_files: + - ".*\\.c"
\ No newline at end of file diff --git a/src/libs/mynewt-nimble/porting/nimble/src/endian.c b/src/libs/mynewt-nimble/porting/nimble/src/endian.c new file mode 100644 index 00000000..2afd6a22 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/endian.c @@ -0,0 +1,268 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "os/endian.h" + +void +put_le16(void *buf, uint16_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)x; + u8ptr[1] = (uint8_t)(x >> 8); +} + +void +put_le24(void *buf, uint32_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)x; + u8ptr[1] = (uint8_t)(x >> 8); + u8ptr[2] = (uint8_t)(x >> 16); +} + +void +put_le32(void *buf, uint32_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)x; + u8ptr[1] = (uint8_t)(x >> 8); + u8ptr[2] = (uint8_t)(x >> 16); + u8ptr[3] = (uint8_t)(x >> 24); +} + +void +put_le64(void *buf, uint64_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)x; + u8ptr[1] = (uint8_t)(x >> 8); + u8ptr[2] = (uint8_t)(x >> 16); + u8ptr[3] = (uint8_t)(x >> 24); + u8ptr[4] = (uint8_t)(x >> 32); + u8ptr[5] = (uint8_t)(x >> 40); + u8ptr[6] = (uint8_t)(x >> 48); + u8ptr[7] = (uint8_t)(x >> 56); +} + +uint16_t +get_le16(const void *buf) +{ + const uint8_t *u8ptr; + uint16_t x; + + u8ptr = buf; + x = u8ptr[0]; + x |= (uint16_t)u8ptr[1] << 8; + + return x; +} + +uint32_t +get_le24(const void *buf) +{ + const uint8_t *u8ptr; + uint32_t x; + + u8ptr = buf; + x = u8ptr[0]; + x |= (uint32_t)u8ptr[1] << 8; + x |= (uint32_t)u8ptr[2] << 16; + + return x; +} + +uint32_t +get_le32(const void *buf) +{ + const uint8_t *u8ptr; + uint32_t x; + + u8ptr = buf; + x = u8ptr[0]; + x |= (uint32_t)u8ptr[1] << 8; + x |= (uint32_t)u8ptr[2] << 16; + x |= (uint32_t)u8ptr[3] << 24; + + return x; +} + +uint64_t +get_le64(const void *buf) +{ + const uint8_t *u8ptr; + uint64_t x; + + u8ptr = buf; + x = u8ptr[0]; + x |= (uint64_t)u8ptr[1] << 8; + x |= (uint64_t)u8ptr[2] << 16; + x |= (uint64_t)u8ptr[3] << 24; + x |= (uint64_t)u8ptr[4] << 32; + x |= (uint64_t)u8ptr[5] << 40; + x |= (uint64_t)u8ptr[6] << 48; + x |= (uint64_t)u8ptr[7] << 56; + + return x; +} + +void +put_be16(void *buf, uint16_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)(x >> 8); + u8ptr[1] = (uint8_t)x; +} + +void +put_be24(void *buf, uint32_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)(x >> 24); + u8ptr[1] = (uint8_t)(x >> 16); + u8ptr[2] = (uint8_t)(x >> 8); +} + +void +put_be32(void *buf, uint32_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)(x >> 24); + u8ptr[1] = (uint8_t)(x >> 16); + u8ptr[2] = (uint8_t)(x >> 8); + u8ptr[3] = (uint8_t)x; +} + +void +put_be64(void *buf, uint64_t x) +{ + uint8_t *u8ptr; + + u8ptr = buf; + u8ptr[0] = (uint8_t)(x >> 56); + u8ptr[1] = (uint8_t)(x >> 48); + u8ptr[2] = (uint8_t)(x >> 40); + u8ptr[3] = (uint8_t)(x >> 32); + u8ptr[4] = (uint8_t)(x >> 24); + u8ptr[5] = (uint8_t)(x >> 16); + u8ptr[6] = (uint8_t)(x >> 8); + u8ptr[7] = (uint8_t)x; +} + +uint16_t +get_be16(const void *buf) +{ + const uint8_t *u8ptr; + uint16_t x; + + u8ptr = buf; + x = (uint16_t)u8ptr[0] << 8; + x |= u8ptr[1]; + + return x; +} + +uint32_t +get_be24(const void *buf) +{ + const uint8_t *u8ptr; + uint32_t x; + + u8ptr = buf; + x = (uint32_t)u8ptr[0] << 24; + x |= (uint32_t)u8ptr[1] << 16; + x |= (uint32_t)u8ptr[2] << 8; + + return x; +} + +uint32_t +get_be32(const void *buf) +{ + const uint8_t *u8ptr; + uint32_t x; + + u8ptr = buf; + x = (uint32_t)u8ptr[0] << 24; + x |= (uint32_t)u8ptr[1] << 16; + x |= (uint32_t)u8ptr[2] << 8; + x |= u8ptr[3]; + + return x; +} + +uint64_t +get_be64(const void *buf) +{ + const uint8_t *u8ptr; + uint64_t x; + + u8ptr = buf; + x = (uint64_t)u8ptr[0] << 56; + x |= (uint64_t)u8ptr[1] << 48; + x |= (uint64_t)u8ptr[2] << 40; + x |= (uint64_t)u8ptr[3] << 32; + x |= (uint64_t)u8ptr[4] << 24; + x |= (uint64_t)u8ptr[5] << 16; + x |= (uint64_t)u8ptr[6] << 8; + x |= u8ptr[7]; + + return x; +} +void +swap_in_place(void *buf, int len) +{ + uint8_t *u8ptr; + uint8_t tmp; + int i; + int j; + + u8ptr = buf; + + for (i = 0, j = len - 1; i < j; i++, j--) { + tmp = u8ptr[i]; + + u8ptr[i] = u8ptr[j]; + u8ptr[j] = tmp; + } +} + +/* swap octets */ +void +swap_buf(uint8_t *dst, const uint8_t *src, int len) +{ + int i; + + for (i = 0; i < len; i++) { + dst[len - 1 - i] = src[i]; + } +} diff --git a/src/libs/mynewt-nimble/porting/nimble/src/hal_timer.c b/src/libs/mynewt-nimble/porting/nimble/src/hal_timer.c new file mode 100644 index 00000000..c67986a8 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/hal_timer.c @@ -0,0 +1,829 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <string.h> +#include <stdint.h> +#include <assert.h> +#include <errno.h> +#include "os/os.h" +#include "nrfx.h" +#include "hal/hal_timer.h" + +/* IRQ prototype */ +typedef void (*hal_timer_irq_handler_t)(void); + +/* User CC 2 for reading counter, CC 3 for timer isr */ +#define NRF_TIMER_CC_READ (2) +#define NRF_TIMER_CC_INT (3) + +/* Output compare 2 used for RTC timers */ +#define NRF_RTC_TIMER_CC_INT (2) + +/* Maximum number of hal timers used */ +#define NRF52_HAL_TIMER_MAX (6) + +/* Maximum timer frequency */ +#define NRF52_MAX_TIMER_FREQ (16000000) + +struct nrf52_hal_timer { + uint8_t tmr_enabled; + uint8_t tmr_irq_num; + uint8_t tmr_rtc; + uint8_t tmr_pad; + uint32_t tmr_cntr; + uint32_t timer_isrs; + uint32_t tmr_freq; + void *tmr_reg; + TAILQ_HEAD(hal_timer_qhead, hal_timer) hal_timer_q; +}; + +#if MYNEWT_VAL(TIMER_0) +struct nrf52_hal_timer nrf52_hal_timer0; +#endif +#if MYNEWT_VAL(TIMER_1) +struct nrf52_hal_timer nrf52_hal_timer1; +#endif +#if MYNEWT_VAL(TIMER_2) +struct nrf52_hal_timer nrf52_hal_timer2; +#endif +#if MYNEWT_VAL(TIMER_3) +struct nrf52_hal_timer nrf52_hal_timer3; +#endif +#if MYNEWT_VAL(TIMER_4) +struct nrf52_hal_timer nrf52_hal_timer4; +#endif +#if MYNEWT_VAL(TIMER_5) +struct nrf52_hal_timer nrf52_hal_timer5; +#endif + +static const struct nrf52_hal_timer *nrf52_hal_timers[NRF52_HAL_TIMER_MAX] = { +#if MYNEWT_VAL(TIMER_0) + &nrf52_hal_timer0, +#else + NULL, +#endif +#if MYNEWT_VAL(TIMER_1) + &nrf52_hal_timer1, +#else + NULL, +#endif +#if MYNEWT_VAL(TIMER_2) + &nrf52_hal_timer2, +#else + NULL, +#endif +#if MYNEWT_VAL(TIMER_3) + &nrf52_hal_timer3, +#else + NULL, +#endif +#if MYNEWT_VAL(TIMER_4) + &nrf52_hal_timer4, +#else + NULL, +#endif +#if MYNEWT_VAL(TIMER_5) + &nrf52_hal_timer5 +#else + NULL +#endif +}; + +/* Resolve timer number into timer structure */ +#define NRF52_HAL_TIMER_RESOLVE(__n, __v) \ + if ((__n) >= NRF52_HAL_TIMER_MAX) { \ + rc = EINVAL; \ + goto err; \ + } \ + (__v) = (struct nrf52_hal_timer *) nrf52_hal_timers[(__n)]; \ + if ((__v) == NULL) { \ + rc = EINVAL; \ + goto err; \ + } + +/* Interrupt mask for interrupt enable/clear */ +#define NRF_TIMER_INT_MASK(x) ((1 << (uint32_t)(x)) << 16) + +static uint32_t +nrf_read_timer_cntr(NRF_TIMER_Type *hwtimer) +{ + uint32_t tcntr; + + /* Force a capture of the timer into 'cntr' capture channel; read it */ + hwtimer->TASKS_CAPTURE[NRF_TIMER_CC_READ] = 1; + tcntr = hwtimer->CC[NRF_TIMER_CC_READ]; + + return tcntr; +} + +/** + * nrf timer set ocmp + * + * Set the OCMP used by the timer to the desired expiration tick + * + * NOTE: Must be called with interrupts disabled. + * + * @param timer Pointer to timer. + */ +static void +nrf_timer_set_ocmp(struct nrf52_hal_timer *bsptimer, uint32_t expiry) +{ + int32_t delta_t; + uint32_t temp; + uint32_t cntr; + NRF_TIMER_Type *hwtimer; + NRF_RTC_Type *rtctimer; + + if (bsptimer->tmr_rtc) { + rtctimer = (NRF_RTC_Type *)bsptimer->tmr_reg; + rtctimer->INTENCLR = NRF_TIMER_INT_MASK(NRF_RTC_TIMER_CC_INT); + temp = bsptimer->tmr_cntr; + cntr = rtctimer->COUNTER; + if (rtctimer->EVENTS_OVRFLW) { + temp += (1UL << 24); + cntr = rtctimer->COUNTER; + } + temp |= cntr; + delta_t = (int32_t)(expiry - temp); + + /* + * The nrf documentation states that you must set the output + * compare to 2 greater than the counter to guarantee an interrupt. + * Since the counter can tick once while we check, we make sure + * it is greater than 2. + */ + if (delta_t < 3) { + NVIC_SetPendingIRQ(bsptimer->tmr_irq_num); + } else { + if (delta_t < (1UL << 24)) { + rtctimer->CC[NRF_RTC_TIMER_CC_INT] = expiry & 0x00ffffff; + } else { + /* CC too far ahead. Just make sure we set compare far ahead */ + rtctimer->CC[NRF_RTC_TIMER_CC_INT] = cntr + (1UL << 23); + } + rtctimer->INTENSET = NRF_TIMER_INT_MASK(NRF_RTC_TIMER_CC_INT); + } + } else { + hwtimer = bsptimer->tmr_reg; + + /* Disable ocmp interrupt and set new value */ + hwtimer->INTENCLR = NRF_TIMER_INT_MASK(NRF_TIMER_CC_INT); + + /* Set output compare register to timer expiration */ + hwtimer->CC[NRF_TIMER_CC_INT] = expiry; + + /* Clear interrupt flag */ + hwtimer->EVENTS_COMPARE[NRF_TIMER_CC_INT] = 0; + + /* Enable the output compare interrupt */ + hwtimer->INTENSET = NRF_TIMER_INT_MASK(NRF_TIMER_CC_INT); + + /* Force interrupt to occur as we may have missed it */ + if ((int32_t)(nrf_read_timer_cntr(hwtimer) - expiry) >= 0) { + NVIC_SetPendingIRQ(bsptimer->tmr_irq_num); + } + } +} + +/* Disable output compare used for timer */ +static void +nrf_timer_disable_ocmp(NRF_TIMER_Type *hwtimer) +{ + hwtimer->INTENCLR = NRF_TIMER_INT_MASK(NRF_TIMER_CC_INT); +} + +static void +nrf_rtc_disable_ocmp(NRF_RTC_Type *rtctimer) +{ + rtctimer->INTENCLR = NRF_TIMER_INT_MASK(NRF_RTC_TIMER_CC_INT); +} + +static uint32_t +hal_timer_read_bsptimer(struct nrf52_hal_timer *bsptimer) +{ + uint32_t low32; + os_sr_t sr; + uint32_t tcntr; + NRF_RTC_Type *rtctimer; + + rtctimer = (NRF_RTC_Type *)bsptimer->tmr_reg; + OS_ENTER_CRITICAL(sr); + tcntr = bsptimer->tmr_cntr; + low32 = rtctimer->COUNTER; + if (rtctimer->EVENTS_OVRFLW) { + tcntr += (1UL << 24); + bsptimer->tmr_cntr = tcntr; + low32 = rtctimer->COUNTER; + rtctimer->EVENTS_OVRFLW = 0; + NVIC_SetPendingIRQ(bsptimer->tmr_irq_num); + } + tcntr |= low32; + OS_EXIT_CRITICAL(sr); + + return tcntr; +} + +#if (MYNEWT_VAL(TIMER_0) || MYNEWT_VAL(TIMER_1) || MYNEWT_VAL(TIMER_2) || \ + MYNEWT_VAL(TIMER_3) || MYNEWT_VAL(TIMER_4) || MYNEWT_VAL(TIMER_5)) +/** + * hal timer chk queue + * + * + * @param bsptimer + */ +static void +hal_timer_chk_queue(struct nrf52_hal_timer *bsptimer) +{ + int32_t delta; + uint32_t tcntr; + os_sr_t sr; + struct hal_timer *timer; + + /* disable interrupts */ + OS_ENTER_CRITICAL(sr); + while ((timer = TAILQ_FIRST(&bsptimer->hal_timer_q)) != NULL) { + if (bsptimer->tmr_rtc) { + tcntr = hal_timer_read_bsptimer(bsptimer); + /* + * If we are within 3 ticks of RTC, we wont be able to set compare. + * Thus, we have to service this timer early. + */ + delta = -3; + } else { + tcntr = nrf_read_timer_cntr(bsptimer->tmr_reg); + delta = 0; + } + if ((int32_t)(tcntr - timer->expiry) >= delta) { + TAILQ_REMOVE(&bsptimer->hal_timer_q, timer, link); + timer->link.tqe_prev = NULL; + timer->cb_func(timer->cb_arg); + } else { + break; + } + } + + /* Any timers left on queue? If so, we need to set OCMP */ + timer = TAILQ_FIRST(&bsptimer->hal_timer_q); + if (timer) { + nrf_timer_set_ocmp(bsptimer, timer->expiry); + } else { + if (bsptimer->tmr_rtc) { + nrf_rtc_disable_ocmp((NRF_RTC_Type *)bsptimer->tmr_reg); + } else { + nrf_timer_disable_ocmp(bsptimer->tmr_reg); + } + } + OS_EXIT_CRITICAL(sr); +} +#endif + +/** + * hal timer irq handler + * + * Generic HAL timer irq handler. + * + * @param tmr + */ +/** + * hal timer irq handler + * + * This is the global timer interrupt routine. + * + */ +#if (MYNEWT_VAL(TIMER_0) || MYNEWT_VAL(TIMER_1) || MYNEWT_VAL(TIMER_2) || \ + MYNEWT_VAL(TIMER_3) || MYNEWT_VAL(TIMER_4)) + +static void +hal_timer_irq_handler(struct nrf52_hal_timer *bsptimer) +{ + uint32_t compare; + NRF_TIMER_Type *hwtimer; + + os_trace_enter_isr(); + + /* Check interrupt source. If set, clear them */ + hwtimer = bsptimer->tmr_reg; + compare = hwtimer->EVENTS_COMPARE[NRF_TIMER_CC_INT]; + if (compare) { + hwtimer->EVENTS_COMPARE[NRF_TIMER_CC_INT] = 0; + } + + /* XXX: make these stats? */ + /* Count # of timer isrs */ + ++bsptimer->timer_isrs; + + /* + * NOTE: we dont check the 'compare' variable here due to how the timer + * is implemented on this chip. There is no way to force an output + * compare, so if we are late setting the output compare (i.e. the timer + * counter is already passed the output compare value), we use the NVIC + * to set a pending interrupt. This means that there will be no compare + * flag set, so all we do is check to see if the compare interrupt is + * enabled. + */ + if (hwtimer->INTENCLR & NRF_TIMER_INT_MASK(NRF_TIMER_CC_INT)) { + hal_timer_chk_queue(bsptimer); + /* XXX: Recommended by nordic to make sure interrupts are cleared */ + compare = hwtimer->EVENTS_COMPARE[NRF_TIMER_CC_INT]; + } + + os_trace_exit_isr(); +} +#endif + +#if MYNEWT_VAL(TIMER_5) +static void +hal_rtc_timer_irq_handler(struct nrf52_hal_timer *bsptimer) +{ + uint32_t overflow; + uint32_t compare; + NRF_RTC_Type *rtctimer; + + /* Check interrupt source. If set, clear them */ + rtctimer = (NRF_RTC_Type *)bsptimer->tmr_reg; + compare = rtctimer->EVENTS_COMPARE[NRF_RTC_TIMER_CC_INT]; + if (compare) { + rtctimer->EVENTS_COMPARE[NRF_RTC_TIMER_CC_INT] = 0; + } + + overflow = rtctimer->EVENTS_OVRFLW; + if (overflow) { + rtctimer->EVENTS_OVRFLW = 0; + bsptimer->tmr_cntr += (1UL << 24); + } + + /* Count # of timer isrs */ + ++bsptimer->timer_isrs; + + /* + * NOTE: we dont check the 'compare' variable here due to how the timer + * is implemented on this chip. There is no way to force an output + * compare, so if we are late setting the output compare (i.e. the timer + * counter is already passed the output compare value), we use the NVIC + * to set a pending interrupt. This means that there will be no compare + * flag set, so all we do is check to see if the compare interrupt is + * enabled. + */ + hal_timer_chk_queue(bsptimer); + + /* Recommended by nordic to make sure interrupts are cleared */ + compare = rtctimer->EVENTS_COMPARE[NRF_RTC_TIMER_CC_INT]; +} +#endif + +#if MYNEWT_VAL(TIMER_0) +void +nrf52_timer0_irq_handler(void) +{ + hal_timer_irq_handler(&nrf52_hal_timer0); +} +#endif + +#if MYNEWT_VAL(TIMER_1) +void +nrf52_timer1_irq_handler(void) +{ + hal_timer_irq_handler(&nrf52_hal_timer1); +} +#endif + +#if MYNEWT_VAL(TIMER_2) +void +nrf52_timer2_irq_handler(void) +{ + hal_timer_irq_handler(&nrf52_hal_timer2); +} +#endif + +#if MYNEWT_VAL(TIMER_3) +void +nrf52_timer3_irq_handler(void) +{ + hal_timer_irq_handler(&nrf52_hal_timer3); +} +#endif + +#if MYNEWT_VAL(TIMER_4) +void +nrf52_timer4_irq_handler(void) +{ + hal_timer_irq_handler(&nrf52_hal_timer4); +} +#endif + +#if MYNEWT_VAL(TIMER_5) +void +nrf52_timer5_irq_handler(void) +{ + hal_rtc_timer_irq_handler(&nrf52_hal_timer5); +} +#endif + +/** + * hal timer init + * + * Initialize platform specific timer items + * + * @param timer_num Timer number to initialize + * @param cfg Pointer to platform specific configuration + * + * @return int 0: success; error code otherwise + */ +int +hal_timer_init(int timer_num, void *cfg) +{ + int rc; + uint8_t irq_num; + struct nrf52_hal_timer *bsptimer; + void *hwtimer; + hal_timer_irq_handler_t irq_isr; + + NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); + + /* If timer is enabled do not allow init */ + if (bsptimer->tmr_enabled) { + rc = EINVAL; + goto err; + } + + switch (timer_num) { +#if MYNEWT_VAL(TIMER_5) + case 5: + irq_num = RTC0_IRQn; + hwtimer = NRF_RTC0; + irq_isr = nrf52_timer5_irq_handler; + bsptimer->tmr_rtc = 1; + break; +#endif + default: + hwtimer = NULL; + break; + } + + if (hwtimer == NULL) { + rc = EINVAL; + goto err; + } + + bsptimer->tmr_reg = hwtimer; + bsptimer->tmr_irq_num = irq_num; + + /* Disable IRQ, set priority and set vector in table */ + NVIC_DisableIRQ(irq_num); +#ifndef RIOT_VERSION + NVIC_SetPriority(irq_num, (1 << __NVIC_PRIO_BITS) - 1); +#endif +#if MYNEWT + NVIC_SetVector(irq_num, (uint32_t)irq_isr); +#else + ble_npl_hw_set_isr(irq_num, irq_isr); +#endif + + return 0; + +err: + return rc; +} + +/** + * hal timer config + * + * Configure a timer to run at the desired frequency. This starts the timer. + * + * @param timer_num + * @param freq_hz + * + * @return int + */ +int +hal_timer_config(int timer_num, uint32_t freq_hz) +{ + int rc; + os_sr_t sr; + struct nrf52_hal_timer *bsptimer; +#if MYNEWT_VAL(TIMER_5) + NRF_RTC_Type *rtctimer; +#endif + + NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); + +#if MYNEWT_VAL(TIMER_5) + if (timer_num == 5) { + /* NOTE: we only allow the RTC frequency to be set at 32768 */ + if (bsptimer->tmr_enabled || (freq_hz != 32768) || + (bsptimer->tmr_reg == NULL)) { + rc = EINVAL; + goto err; + } + + bsptimer->tmr_freq = freq_hz; + bsptimer->tmr_enabled = 1; + + OS_ENTER_CRITICAL(sr); + + rtctimer = (NRF_RTC_Type *)bsptimer->tmr_reg; + + /* Stop the timer first */ + rtctimer->TASKS_STOP = 1; + + /* Always no prescaler */ + rtctimer->PRESCALER = 0; + + /* Clear overflow events and set overflow interrupt */ + rtctimer->EVENTS_OVRFLW = 0; + rtctimer->INTENSET = RTC_INTENSET_OVRFLW_Msk; + + /* Start the timer */ + rtctimer->TASKS_START = 1; + + /* Set isr in vector table and enable interrupt */ + NVIC_EnableIRQ(bsptimer->tmr_irq_num); + + OS_EXIT_CRITICAL(sr); + return 0; + } +#endif + + assert(0); + + return 0; + +err: + return rc; +} + +/** + * hal timer deinit + * + * De-initialize a HW timer. + * + * @param timer_num + * + * @return int + */ +int +hal_timer_deinit(int timer_num) +{ + int rc; + os_sr_t sr; + struct nrf52_hal_timer *bsptimer; + NRF_TIMER_Type *hwtimer; + NRF_RTC_Type *rtctimer; + + rc = 0; + NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); + + OS_ENTER_CRITICAL(sr); + if (bsptimer->tmr_rtc) { + rtctimer = (NRF_RTC_Type *)bsptimer->tmr_reg; + rtctimer->INTENCLR = NRF_TIMER_INT_MASK(NRF_RTC_TIMER_CC_INT); + rtctimer->TASKS_STOP = 1; + } else { + hwtimer = (NRF_TIMER_Type *)bsptimer->tmr_reg; + hwtimer->INTENCLR = NRF_TIMER_INT_MASK(NRF_TIMER_CC_INT); + hwtimer->TASKS_STOP = 1; + } + bsptimer->tmr_enabled = 0; + bsptimer->tmr_reg = NULL; + OS_EXIT_CRITICAL(sr); + +err: + return rc; +} + +/** + * hal timer get resolution + * + * Get the resolution of the timer. This is the timer period, in nanoseconds + * + * @param timer_num + * + * @return uint32_t The + */ +uint32_t +hal_timer_get_resolution(int timer_num) +{ + int rc; + uint32_t resolution; + struct nrf52_hal_timer *bsptimer; + + NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); + + resolution = 1000000000 / bsptimer->tmr_freq; + return resolution; + +err: + rc = 0; + return rc; +} + +/** + * hal timer read + * + * Returns the timer counter. NOTE: if the timer is a 16-bit timer, only + * the lower 16 bits are valid. If the timer is a 64-bit timer, only the + * low 32-bits are returned. + * + * @return uint32_t The timer counter register. + */ +uint32_t +hal_timer_read(int timer_num) +{ + int rc; + uint32_t tcntr; + struct nrf52_hal_timer *bsptimer; + + NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); + if (bsptimer->tmr_rtc) { + tcntr = hal_timer_read_bsptimer(bsptimer); + } else { + tcntr = nrf_read_timer_cntr(bsptimer->tmr_reg); + } + + return tcntr; + + /* Assert here since there is no invalid return code */ +err: + assert(0); + rc = 0; + return rc; +} + +/** + * hal timer delay + * + * Blocking delay for n ticks + * + * @param timer_num + * @param ticks + * + * @return int 0 on success; error code otherwise. + */ +int +hal_timer_delay(int timer_num, uint32_t ticks) +{ + uint32_t until; + + until = hal_timer_read(timer_num) + ticks; + while ((int32_t)(hal_timer_read(timer_num) - until) <= 0) { + /* Loop here till finished */ + } + + return 0; +} + +/** + * + * Initialize the HAL timer structure with the callback and the callback + * argument. Also initializes the HW specific timer pointer. + * + * @param cb_func + * + * @return int + */ +int +hal_timer_set_cb(int timer_num, struct hal_timer *timer, hal_timer_cb cb_func, + void *arg) +{ + int rc; + struct nrf52_hal_timer *bsptimer; + + NRF52_HAL_TIMER_RESOLVE(timer_num, bsptimer); + + timer->cb_func = cb_func; + timer->cb_arg = arg; + timer->link.tqe_prev = NULL; + timer->bsp_timer = bsptimer; + + rc = 0; + +err: + return rc; +} + +int +hal_timer_start(struct hal_timer *timer, uint32_t ticks) +{ + int rc; + uint32_t tick; + struct nrf52_hal_timer *bsptimer; + + /* Set the tick value at which the timer should expire */ + bsptimer = (struct nrf52_hal_timer *)timer->bsp_timer; + if (bsptimer->tmr_rtc) { + tick = hal_timer_read_bsptimer(bsptimer) + ticks; + } else { + tick = nrf_read_timer_cntr(bsptimer->tmr_reg) + ticks; + } + rc = hal_timer_start_at(timer, tick); + return rc; +} + +int +hal_timer_start_at(struct hal_timer *timer, uint32_t tick) +{ + os_sr_t sr; + struct hal_timer *entry; + struct nrf52_hal_timer *bsptimer; + + if ((timer == NULL) || (timer->link.tqe_prev != NULL) || + (timer->cb_func == NULL)) { + return EINVAL; + } + bsptimer = (struct nrf52_hal_timer *)timer->bsp_timer; + timer->expiry = tick; + + OS_ENTER_CRITICAL(sr); + + if (TAILQ_EMPTY(&bsptimer->hal_timer_q)) { + TAILQ_INSERT_HEAD(&bsptimer->hal_timer_q, timer, link); + } else { + TAILQ_FOREACH(entry, &bsptimer->hal_timer_q, link) { + if ((int32_t)(timer->expiry - entry->expiry) < 0) { + TAILQ_INSERT_BEFORE(entry, timer, link); + break; + } + } + if (!entry) { + TAILQ_INSERT_TAIL(&bsptimer->hal_timer_q, timer, link); + } + } + + /* If this is the head, we need to set new OCMP */ + if (timer == TAILQ_FIRST(&bsptimer->hal_timer_q)) { + nrf_timer_set_ocmp(bsptimer, timer->expiry); + } + + OS_EXIT_CRITICAL(sr); + + return 0; +} + +/** + * hal timer stop + * + * Stop a timer. + * + * @param timer + * + * @return int + */ +int +hal_timer_stop(struct hal_timer *timer) +{ + os_sr_t sr; + int reset_ocmp; + struct hal_timer *entry; + struct nrf52_hal_timer *bsptimer; + + if (timer == NULL) { + return EINVAL; + } + + bsptimer = (struct nrf52_hal_timer *)timer->bsp_timer; + + OS_ENTER_CRITICAL(sr); + + if (timer->link.tqe_prev != NULL) { + reset_ocmp = 0; + if (timer == TAILQ_FIRST(&bsptimer->hal_timer_q)) { + /* If first on queue, we will need to reset OCMP */ + entry = TAILQ_NEXT(timer, link); + reset_ocmp = 1; + } + TAILQ_REMOVE(&bsptimer->hal_timer_q, timer, link); + timer->link.tqe_prev = NULL; + if (reset_ocmp) { + if (entry) { + nrf_timer_set_ocmp((struct nrf52_hal_timer *)entry->bsp_timer, + entry->expiry); + } else { + if (bsptimer->tmr_rtc) { + nrf_rtc_disable_ocmp((NRF_RTC_Type *)bsptimer->tmr_reg); + } else { + nrf_timer_disable_ocmp(bsptimer->tmr_reg); + } + } + } + } + + OS_EXIT_CRITICAL(sr); + + return 0; +} diff --git a/src/libs/mynewt-nimble/porting/nimble/src/mem.c b/src/libs/mynewt-nimble/porting/nimble/src/mem.c new file mode 100644 index 00000000..1fea7df4 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/mem.c @@ -0,0 +1,302 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdlib.h> +#include "os/os.h" +#include "mem/mem.h" + +/** + * Generic mempool allocation function. Used with basic and extended mempools. + */ +static int +mem_malloc_mempool_gen(uint16_t num_blocks, uint32_t block_size, + void **out_buf) +{ + block_size = OS_ALIGN(block_size, OS_ALIGNMENT); + + if (num_blocks > 0) { + *out_buf = malloc(OS_MEMPOOL_BYTES(num_blocks, block_size)); + if (*out_buf == NULL) { + return OS_ENOMEM; + } + } else { + *out_buf = NULL; + } + + return 0; +} + +/** + * Mallocs a block of memory and initializes a mempool to use it. + * + * @param mempool The mempool to initialize. + * @param num_blocks The total number of memory blocks in the + * mempool. + * @param block_size The size of each mempool entry. + * @param name The name to give the mempool. + * @param out_buf On success, this points to the malloced memory. + * Pass NULL if you don't need this + * information. + * + * @return 0 on success; + * OS_ENOMEM on malloc failure; + * Other OS code on unexpected error. + */ +int +mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks, + uint32_t block_size, char *name, void **out_buf) +{ + void *buf; + int rc; + + rc = mem_malloc_mempool_gen(num_blocks, block_size, &buf); + if (rc != 0) { + return rc; + } + + rc = os_mempool_init(mempool, num_blocks, block_size, buf, name); + if (rc != 0) { + free(buf); + return rc; + } + + if (out_buf != NULL) { + *out_buf = buf; + } + + return 0; +} + +/** + * Mallocs a block of memory and initializes an extended mempool to use it. + * + * @param mpe The extended mempool to initialize. + * @param num_blocks The total number of memory blocks in the + * mempool. + * @param block_size The size of each mempool entry. + * @param name The name to give the mempool. + * @param out_buf On success, this points to the malloced memory. + * Pass NULL if you don't need this + * information. + * + * @return 0 on success; + * OS_ENOMEM on malloc failure; + * Other OS code on unexpected error. + */ +int +mem_malloc_mempool_ext(struct os_mempool_ext *mpe, uint16_t num_blocks, + uint32_t block_size, char *name, void **out_buf) +{ + void *buf; + int rc; + + rc = mem_malloc_mempool_gen(num_blocks, block_size, &buf); + if (rc != 0) { + return rc; + } + + rc = os_mempool_ext_init(mpe, num_blocks, block_size, buf, name); + if (rc != 0) { + free(buf); + return rc; + } + + if (out_buf != NULL) { + *out_buf = buf; + } + + return 0; +} + +/** + * Mallocs a block of memory and initializes an mbuf pool to use it. The + * specified block_size indicates the size of an mbuf acquired from the pool if + * it does not contain a pkthdr. + * + * @param mempool The mempool to initialize. + * @param mbuf_pool The mbuf pool to initialize. + * @param num_blocks The total number of mbufs in the pool. + * @param block_size The size of each mbuf. + * @param name The name to give the mempool. + * @param out_buf On success, this points to the malloced memory. + * Pass NULL if you don't need this + * information. + * + * @return 0 on success; + * OS_ENOMEM on malloc failure; + * Other OS code on unexpected error. + */ +int +mem_malloc_mbuf_pool(struct os_mempool *mempool, + struct os_mbuf_pool *mbuf_pool, uint16_t num_blocks, + uint32_t block_size, char *name, + void **out_buf) +{ + void *buf; + int rc; + + block_size = OS_ALIGN(block_size + sizeof (struct os_mbuf), OS_ALIGNMENT); + + rc = mem_malloc_mempool(mempool, num_blocks, block_size, name, &buf); + if (rc != 0) { + return rc; + } + + rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks); + if (rc != 0) { + free(buf); + return rc; + } + + if (out_buf != NULL) { + *out_buf = buf; + } + + return 0; +} + +/** + * Mallocs a block of memory and initializes an mbuf pool to use it. The + * specified block_size indicates the size of an mbuf acquired from the pool if + * it contains a pkthdr. + * + * @param mempool The mempool to initialize. + * @param mbuf_pool The mbuf pool to initialize. + * @param num_blocks The total number of mbufs in the pool. + * @param block_size The size of each mbuf. + * @param name The name to give the mempool. + * @param out_buf On success, this points to the malloced memory. + * Pass NULL if you don't need this + * information. + * + * @return 0 on success; + * OS_ENOMEM on malloc failure; + * Other OS code on unexpected error. + */ +int +mem_malloc_mbufpkt_pool(struct os_mempool *mempool, + struct os_mbuf_pool *mbuf_pool, int num_blocks, + int block_size, char *name, + void **out_buf) +{ + int rc; + + rc = mem_malloc_mbuf_pool(mempool, mbuf_pool, num_blocks, + block_size + sizeof (struct os_mbuf_pkthdr), + name, out_buf); + return rc; +} + +int +mem_init_mbuf_pool(void *mem, struct os_mempool *mempool, + struct os_mbuf_pool *mbuf_pool, int num_blocks, + int block_size, char *name) +{ + int rc; + + rc = os_mempool_init(mempool, num_blocks, block_size, mem, name); + if (rc != 0) { + return rc; + } + + rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks); + if (rc != 0) { + return rc; + } + + return 0; +} + +/* + * Splits an appropriately-sized fragment from the front of an mbuf chain, as + * neeeded. If the length of the mbuf chain greater than specified maximum + * fragment size, a new mbuf is allocated, and data is moved from the source + * mbuf to the new mbuf. If the mbuf chain is small enough to fit in a single + * fragment, the source mbuf itself is returned unmodified, and the suplied + * pointer is set to NULL. + * + * This function is expected to be called in a loop until the entire mbuf chain + * has been consumed. For example: + * + * struct os_mbuf *frag; + * struct os_mbuf *rsp; + * // [...] + * while (rsp != NULL) { + * frag = mem_split_frag(&rsp, get_mtu(), frag_alloc, NULL); + * if (frag == NULL) { + * os_mbuf_free_chain(rsp); + * return SYS_ENOMEM; + * } + * send_packet(frag) + * } + * + * @param om The packet to fragment. Upon fragmentation, + * this mbuf is adjusted such that the + * fragment data is removed. If the packet + * constitutes a single fragment, this gets + * set to NULL on success. + * @param max_frag_sz The maximum payload size of a fragment. + * Typically this is the MTU of the + * connection. + * @param alloc_cb Points to a function that allocates an mbuf to + * hold a fragment. This function gets called + * before the source mbuf chain is modified, + * so it can safely inspect it. + * @param cb_arg Generic parameter that gets passed to the + * callback function. + * + * @return The next fragment to send on success; + * NULL on failure. + */ +struct os_mbuf * +mem_split_frag(struct os_mbuf **om, uint16_t max_frag_sz, + mem_frag_alloc_fn *alloc_cb, void *cb_arg) +{ + struct os_mbuf *frag; + int rc; + + if (OS_MBUF_PKTLEN(*om) <= max_frag_sz) { + /* Final fragment. */ + frag = *om; + *om = NULL; + return frag; + } + + /* Packet needs to be split. Allocate a new buffer for the fragment. */ + frag = alloc_cb(max_frag_sz, cb_arg); + if (frag == NULL) { + goto err; + } + + /* Move data from the front of the packet into the fragment mbuf. */ + rc = os_mbuf_appendfrom(frag, *om, 0, max_frag_sz); + if (rc != 0) { + goto err; + } + os_mbuf_adj(*om, max_frag_sz); + + /* Free unused portion of of source mbuf chain, if possible. */ + *om = os_mbuf_trim_front(*om); + + return frag; + +err: + os_mbuf_free_chain(frag); + return NULL; +} diff --git a/src/libs/mynewt-nimble/porting/nimble/src/nimble_port.c b/src/libs/mynewt-nimble/porting/nimble/src/nimble_port.c new file mode 100644 index 00000000..ff350a89 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/nimble_port.c @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stddef.h> +#include "os/os.h" +#include "sysinit/sysinit.h" +#include "host/ble_hs.h" +#include "nimble/nimble_port.h" +#if NIMBLE_CFG_CONTROLLER +#include "controller/ble_ll.h" +#endif + +static struct ble_npl_eventq g_eventq_dflt; + +void +nimble_port_init(void) +{ + void os_msys_init(void); + void ble_store_ram_init(void); +#if NIMBLE_CFG_CONTROLLER + void ble_hci_ram_init(void); +#endif + + /* Initialize default event queue */ + ble_npl_eventq_init(&g_eventq_dflt); + + os_msys_init(); + + ble_hs_init(); + + /* XXX Need to have template for store */ + ble_store_ram_init(); + +#if NIMBLE_CFG_CONTROLLER + hal_timer_init(5, NULL); + os_cputime_init(32768); + ble_ll_init(); + ble_hci_ram_init(); +#endif +} + +void +nimble_port_run(void) +{ + struct ble_npl_event *ev; + + while (1) { + ev = ble_npl_eventq_get(&g_eventq_dflt, BLE_NPL_TIME_FOREVER); + ble_npl_event_run(ev); + } +} + +struct ble_npl_eventq * +nimble_port_get_dflt_eventq(void) +{ + return &g_eventq_dflt; +} + +#if NIMBLE_CFG_CONTROLLER +void +nimble_port_ll_task_func(void *arg) +{ + extern void ble_ll_task(void *); + + ble_ll_task(arg); +} +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/src/os_cputime.c b/src/libs/mynewt-nimble/porting/nimble/src/os_cputime.c new file mode 100644 index 00000000..6c95c4f1 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/os_cputime.c @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <string.h> +#include <stdint.h> +#include <assert.h> +#include "syscfg/syscfg.h" +#include "os/os_cputime.h" +#include "hal/hal_timer.h" + +#if defined(OS_CPUTIME_FREQ_HIGH) +struct os_cputime_data g_os_cputime; +#endif + +int +os_cputime_init(uint32_t clock_freq) +{ + int rc; + + /* Set the ticks per microsecond. */ +#if defined(OS_CPUTIME_FREQ_HIGH) + g_os_cputime.ticks_per_usec = clock_freq / 1000000U; +#endif + rc = hal_timer_config(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM), clock_freq); + return rc; +} + +/** + * Wait until the number of ticks has elapsed. This is a blocking delay. + * + * @param ticks The number of ticks to wait. + */ +void +os_cputime_delay_ticks(uint32_t ticks) +{ + uint32_t until; + + until = os_cputime_get32() + ticks; + while ((int32_t)(os_cputime_get32() - until) < 0) { + /* Loop here till finished */ + } +} + +#if !defined(OS_CPUTIME_FREQ_PWR2) +void +os_cputime_delay_nsecs(uint32_t nsecs) +{ + uint32_t ticks; + + ticks = os_cputime_nsecs_to_ticks(nsecs); + os_cputime_delay_ticks(ticks); +} +#endif + +void +os_cputime_delay_usecs(uint32_t usecs) +{ + uint32_t ticks; + + ticks = os_cputime_usecs_to_ticks(usecs); + os_cputime_delay_ticks(ticks); +} + +void +os_cputime_timer_init(struct hal_timer *timer, hal_timer_cb fp, void *arg) +{ + assert(timer != NULL); + assert(fp != NULL); + + hal_timer_set_cb(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM), timer, fp, arg); +} + +int +os_cputime_timer_start(struct hal_timer *timer, uint32_t cputime) +{ + int rc; + + rc = hal_timer_start_at(timer, cputime); + return rc; +} + +int +os_cputime_timer_relative(struct hal_timer *timer, uint32_t usecs) +{ + int rc; + uint32_t cputime; + + assert(timer != NULL); + + cputime = os_cputime_get32() + os_cputime_usecs_to_ticks(usecs); + rc = hal_timer_start_at(timer, cputime); + + return rc; +} + +void +os_cputime_timer_stop(struct hal_timer *timer) +{ + hal_timer_stop(timer); +} + +uint32_t +os_cputime_get32(void) +{ + uint32_t cpu_time; + + cpu_time = hal_timer_read(MYNEWT_VAL(OS_CPUTIME_TIMER_NUM)); + return cpu_time; +} + diff --git a/src/libs/mynewt-nimble/porting/nimble/src/os_cputime_pwr2.c b/src/libs/mynewt-nimble/porting/nimble/src/os_cputime_pwr2.c new file mode 100644 index 00000000..1567070a --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/os_cputime_pwr2.c @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "os/os_cputime.h" + +/** + * This module implements cputime functionality for timers for which: + * a. freq is a power of 2 Hz, and + * b. 256 Hz <= freq < 1 MHz + */ + +#if defined(OS_CPUTIME_FREQ_PWR2) + +/** + * @addtogroup OSKernel Operating System Kernel + * @{ + * @defgroup OSCPUTime High Resolution Timers + * @{ + */ + +/** + * os cputime usecs to ticks + * + * Converts the given number of microseconds into cputime ticks. + * + * @param usecs The number of microseconds to convert to ticks + * + * @return uint32_t The number of ticks corresponding to 'usecs' + */ +uint32_t +os_cputime_usecs_to_ticks(uint32_t usecs) +{ + uint64_t ticks; + + /* + * Faster calculation but could be off 1 full tick since we do not + * add residual back. Adding back the residual is commented out below, but + * shown. + */ + ticks = (1ULL << 32) * MYNEWT_VAL(OS_CPUTIME_FREQ) / 1000000 * usecs; + + /* Residual for 32768 Hz. */ + //ticks += ((uint64_t)usecs * (1526122139+1)) >> 32; + + return ticks >> 32; +} + +/** + * cputime ticks to usecs + * + * Convert the given number of ticks into microseconds. + * + * @param ticks The number of ticks to convert to microseconds. + * + * @return uint32_t The number of microseconds corresponding to 'ticks' + * + * NOTE: This calculation will overflow if the value for ticks is greater + * than 140737488. I am not going to check that here because that many ticks + * is about 4222 seconds, way more than what this routine should be used for. + */ +uint32_t +os_cputime_ticks_to_usecs(uint32_t ticks) +{ + uint32_t usecs; + uint32_t shift; + uint32_t freq; + + /* Given: `freq = 2^n`, calculate `n`. */ + /* Note: this looks like a lot of work, but gcc can optimize it away since + * `freq` is known at compile time. + */ + freq = MYNEWT_VAL(OS_CPUTIME_FREQ); + shift = 0; + while (freq != 0) { + freq >>= 1; + shift++; + } + + if (shift <= 7) { + return 0; + } + shift -= 7; + + usecs = ((ticks >> shift) * 15625) + (((ticks & 0x1ff) * 15625) >> shift); + return usecs; +} + +/** + * @} OSCPUTime + * @} OSKernel + */ + +#endif diff --git a/src/libs/mynewt-nimble/porting/nimble/src/os_mbuf.c b/src/libs/mynewt-nimble/porting/nimble/src/os_mbuf.c new file mode 100644 index 00000000..92ea935f --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/os_mbuf.c @@ -0,0 +1,1125 @@ +/* + * Software in this file is based heavily on code written in the FreeBSD source + * code repostiory. While the code is written from scratch, it contains + * many of the ideas and logic flow in the original source, this is a + * derivative work, and the following license applies as well: + * + * Copyright (c) 1982, 1986, 1988, 1991, 1993 + * The Regents of the University of California. 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 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. + * 4. Neither the name of the University 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 REGENTS 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 REGENTS 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. + * + */ + +#include "os/os.h" + +#include <assert.h> +#include <stddef.h> +#include <string.h> +#include <limits.h> + +/** + * @addtogroup OSKernel + * @{ + * @defgroup OSMqueue Queue of Mbufs + * @{ + */ + +STAILQ_HEAD(, os_mbuf_pool) g_msys_pool_list = + STAILQ_HEAD_INITIALIZER(g_msys_pool_list); + + +int +os_mqueue_init(struct os_mqueue *mq, ble_npl_event_fn *ev_cb, void *arg) +{ + struct ble_npl_event *ev; + + STAILQ_INIT(&mq->mq_head); + + ev = &mq->mq_ev; + ble_npl_event_init(ev, ev_cb, arg); + + return (0); +} + +struct os_mbuf * +os_mqueue_get(struct os_mqueue *mq) +{ + struct os_mbuf_pkthdr *mp; + struct os_mbuf *m; + os_sr_t sr; + + OS_ENTER_CRITICAL(sr); + mp = STAILQ_FIRST(&mq->mq_head); + if (mp) { + STAILQ_REMOVE_HEAD(&mq->mq_head, omp_next); + } + OS_EXIT_CRITICAL(sr); + + if (mp) { + m = OS_MBUF_PKTHDR_TO_MBUF(mp); + } else { + m = NULL; + } + + return (m); +} + +int +os_mqueue_put(struct os_mqueue *mq, struct ble_npl_eventq *evq, struct os_mbuf *m) +{ + struct os_mbuf_pkthdr *mp; + os_sr_t sr; + int rc; + + /* Can only place the head of a chained mbuf on the queue. */ + if (!OS_MBUF_IS_PKTHDR(m)) { + rc = OS_EINVAL; + goto err; + } + + mp = OS_MBUF_PKTHDR(m); + + OS_ENTER_CRITICAL(sr); + STAILQ_INSERT_TAIL(&mq->mq_head, mp, omp_next); + OS_EXIT_CRITICAL(sr); + + /* Only post an event to the queue if its specified */ + if (evq) { + ble_npl_eventq_put(evq, &mq->mq_ev); + } + + return (0); +err: + return (rc); +} + +int +os_msys_register(struct os_mbuf_pool *new_pool) +{ + struct os_mbuf_pool *pool; + + pool = NULL; + STAILQ_FOREACH(pool, &g_msys_pool_list, omp_next) { + if (new_pool->omp_databuf_len > pool->omp_databuf_len) { + break; + } + } + + if (pool) { + STAILQ_INSERT_AFTER(&g_msys_pool_list, pool, new_pool, omp_next); + } else { + STAILQ_INSERT_TAIL(&g_msys_pool_list, new_pool, omp_next); + } + + return (0); +} + +void +os_msys_reset(void) +{ + STAILQ_INIT(&g_msys_pool_list); +} + +static struct os_mbuf_pool * +_os_msys_find_pool(uint16_t dsize) +{ + struct os_mbuf_pool *pool; + + pool = NULL; + STAILQ_FOREACH(pool, &g_msys_pool_list, omp_next) { + if (dsize <= pool->omp_databuf_len) { + break; + } + } + + if (!pool) { + pool = STAILQ_LAST(&g_msys_pool_list, os_mbuf_pool, omp_next); + } + + return (pool); +} + + +struct os_mbuf * +os_msys_get(uint16_t dsize, uint16_t leadingspace) +{ + struct os_mbuf *m; + struct os_mbuf_pool *pool; + + pool = _os_msys_find_pool(dsize); + if (!pool) { + goto err; + } + + m = os_mbuf_get(pool, leadingspace); + return (m); +err: + return (NULL); +} + +struct os_mbuf * +os_msys_get_pkthdr(uint16_t dsize, uint16_t user_hdr_len) +{ + uint16_t total_pkthdr_len; + struct os_mbuf *m; + struct os_mbuf_pool *pool; + + total_pkthdr_len = user_hdr_len + sizeof(struct os_mbuf_pkthdr); + pool = _os_msys_find_pool(dsize + total_pkthdr_len); + if (!pool) { + goto err; + } + + m = os_mbuf_get_pkthdr(pool, user_hdr_len); + return (m); +err: + return (NULL); +} + +int +os_msys_count(void) +{ + struct os_mbuf_pool *omp; + int total; + + total = 0; + STAILQ_FOREACH(omp, &g_msys_pool_list, omp_next) { + total += omp->omp_pool->mp_num_blocks; + } + + return total; +} + +int +os_msys_num_free(void) +{ + struct os_mbuf_pool *omp; + int total; + + total = 0; + STAILQ_FOREACH(omp, &g_msys_pool_list, omp_next) { + total += omp->omp_pool->mp_num_free; + } + + return total; +} + + +int +os_mbuf_pool_init(struct os_mbuf_pool *omp, struct os_mempool *mp, + uint16_t buf_len, uint16_t nbufs) +{ + omp->omp_databuf_len = buf_len - sizeof(struct os_mbuf); + omp->omp_pool = mp; + + return (0); +} + +struct os_mbuf * +os_mbuf_get(struct os_mbuf_pool *omp, uint16_t leadingspace) +{ + struct os_mbuf *om; + + if (leadingspace > omp->omp_databuf_len) { + goto err; + } + + om = os_memblock_get(omp->omp_pool); + if (!om) { + goto err; + } + + SLIST_NEXT(om, om_next) = NULL; + om->om_flags = 0; + om->om_pkthdr_len = 0; + om->om_len = 0; + om->om_data = (&om->om_databuf[0] + leadingspace); + om->om_omp = omp; + + return (om); +err: + return (NULL); +} + +struct os_mbuf * +os_mbuf_get_pkthdr(struct os_mbuf_pool *omp, uint8_t user_pkthdr_len) +{ + uint16_t pkthdr_len; + struct os_mbuf_pkthdr *pkthdr; + struct os_mbuf *om; + + /* User packet header must fit inside mbuf */ + pkthdr_len = user_pkthdr_len + sizeof(struct os_mbuf_pkthdr); + if ((pkthdr_len > omp->omp_databuf_len) || (pkthdr_len > 255)) { + return NULL; + } + + om = os_mbuf_get(omp, 0); + if (om) { + om->om_pkthdr_len = pkthdr_len; + om->om_data += pkthdr_len; + + pkthdr = OS_MBUF_PKTHDR(om); + pkthdr->omp_len = 0; + pkthdr->omp_flags = 0; + STAILQ_NEXT(pkthdr, omp_next) = NULL; + } + + return om; +} + +int +os_mbuf_free(struct os_mbuf *om) +{ + int rc; + + if (om->om_omp != NULL) { + rc = os_memblock_put(om->om_omp->omp_pool, om); + if (rc != 0) { + goto err; + } + } + + return (0); +err: + return (rc); +} + +int +os_mbuf_free_chain(struct os_mbuf *om) +{ + struct os_mbuf *next; + int rc; + + while (om != NULL) { + next = SLIST_NEXT(om, om_next); + + rc = os_mbuf_free(om); + if (rc != 0) { + goto err; + } + + om = next; + } + + return (0); +err: + return (rc); +} + +/** + * Copy a packet header from one mbuf to another. + * + * @param omp The mbuf pool associated with these buffers + * @param new_buf The new buffer to copy the packet header into + * @param old_buf The old buffer to copy the packet header from + */ +static inline void +_os_mbuf_copypkthdr(struct os_mbuf *new_buf, struct os_mbuf *old_buf) +{ + assert(new_buf->om_len == 0); + + memcpy(&new_buf->om_databuf[0], &old_buf->om_databuf[0], + old_buf->om_pkthdr_len); + new_buf->om_pkthdr_len = old_buf->om_pkthdr_len; + new_buf->om_data = new_buf->om_databuf + old_buf->om_pkthdr_len; +} + +int +os_mbuf_append(struct os_mbuf *om, const void *data, uint16_t len) +{ + struct os_mbuf_pool *omp; + struct os_mbuf *last; + struct os_mbuf *new; + int remainder; + int space; + int rc; + + if (om == NULL) { + rc = OS_EINVAL; + goto err; + } + + omp = om->om_omp; + + /* Scroll to last mbuf in the chain */ + last = om; + while (SLIST_NEXT(last, om_next) != NULL) { + last = SLIST_NEXT(last, om_next); + } + + remainder = len; + space = OS_MBUF_TRAILINGSPACE(last); + + /* If room in current mbuf, copy the first part of the data into the + * remaining space in that mbuf. + */ + if (space > 0) { + if (space > remainder) { + space = remainder; + } + + memcpy(OS_MBUF_DATA(last, uint8_t *) + last->om_len , data, space); + + last->om_len += space; + data += space; + remainder -= space; + } + + /* Take the remaining data, and keep allocating new mbufs and copying + * data into it, until data is exhausted. + */ + while (remainder > 0) { + new = os_mbuf_get(omp, 0); + if (!new) { + break; + } + + new->om_len = min(omp->omp_databuf_len, remainder); + memcpy(OS_MBUF_DATA(new, void *), data, new->om_len); + data += new->om_len; + remainder -= new->om_len; + SLIST_NEXT(last, om_next) = new; + last = new; + } + + /* Adjust the packet header length in the buffer */ + if (OS_MBUF_IS_PKTHDR(om)) { + OS_MBUF_PKTHDR(om)->omp_len += len - remainder; + } + + if (remainder != 0) { + rc = OS_ENOMEM; + goto err; + } + + + return (0); +err: + return (rc); +} + +int +os_mbuf_appendfrom(struct os_mbuf *dst, const struct os_mbuf *src, + uint16_t src_off, uint16_t len) +{ + const struct os_mbuf *src_cur_om; + uint16_t src_cur_off; + uint16_t chunk_sz; + int rc; + + src_cur_om = os_mbuf_off(src, src_off, &src_cur_off); + while (len > 0) { + if (src_cur_om == NULL) { + return OS_EINVAL; + } + + chunk_sz = min(len, src_cur_om->om_len - src_cur_off); + rc = os_mbuf_append(dst, src_cur_om->om_data + src_cur_off, chunk_sz); + if (rc != 0) { + return rc; + } + + len -= chunk_sz; + src_cur_om = SLIST_NEXT(src_cur_om, om_next); + src_cur_off = 0; + } + + return 0; +} + +struct os_mbuf * +os_mbuf_dup(struct os_mbuf *om) +{ + struct os_mbuf_pool *omp; + struct os_mbuf *head; + struct os_mbuf *copy; + + omp = om->om_omp; + + head = NULL; + copy = NULL; + + for (; om != NULL; om = SLIST_NEXT(om, om_next)) { + if (head) { + SLIST_NEXT(copy, om_next) = os_mbuf_get(omp, + OS_MBUF_LEADINGSPACE(om)); + if (!SLIST_NEXT(copy, om_next)) { + os_mbuf_free_chain(head); + goto err; + } + + copy = SLIST_NEXT(copy, om_next); + } else { + head = os_mbuf_get(omp, OS_MBUF_LEADINGSPACE(om)); + if (!head) { + goto err; + } + + if (OS_MBUF_IS_PKTHDR(om)) { + _os_mbuf_copypkthdr(head, om); + } + copy = head; + } + copy->om_flags = om->om_flags; + copy->om_len = om->om_len; + memcpy(OS_MBUF_DATA(copy, uint8_t *), OS_MBUF_DATA(om, uint8_t *), + om->om_len); + } + + return (head); +err: + return (NULL); +} + +struct os_mbuf * +os_mbuf_off(const struct os_mbuf *om, int off, uint16_t *out_off) +{ + struct os_mbuf *next; + struct os_mbuf *cur; + + /* Cast away const. */ + cur = (struct os_mbuf *)om; + + while (1) { + if (cur == NULL) { + return NULL; + } + + next = SLIST_NEXT(cur, om_next); + + if (cur->om_len > off || + (cur->om_len == off && next == NULL)) { + + *out_off = off; + return cur; + } + + off -= cur->om_len; + cur = next; + } +} + +int +os_mbuf_copydata(const struct os_mbuf *m, int off, int len, void *dst) +{ + unsigned int count; + uint8_t *udst; + + if (!len) { + return 0; + } + + udst = dst; + + while (off > 0) { + if (!m) { + return (-1); + } + + if (off < m->om_len) + break; + off -= m->om_len; + m = SLIST_NEXT(m, om_next); + } + while (len > 0 && m != NULL) { + count = min(m->om_len - off, len); + memcpy(udst, m->om_data + off, count); + len -= count; + udst += count; + off = 0; + m = SLIST_NEXT(m, om_next); + } + + return (len > 0 ? -1 : 0); +} + +void +os_mbuf_adj(struct os_mbuf *mp, int req_len) +{ + int len = req_len; + struct os_mbuf *m; + int count; + + if ((m = mp) == NULL) + return; + if (len >= 0) { + /* + * Trim from head. + */ + while (m != NULL && len > 0) { + if (m->om_len <= len) { + len -= m->om_len; + m->om_len = 0; + m = SLIST_NEXT(m, om_next); + } else { + m->om_len -= len; + m->om_data += len; + len = 0; + } + } + if (OS_MBUF_IS_PKTHDR(mp)) + OS_MBUF_PKTHDR(mp)->omp_len -= (req_len - len); + } else { + /* + * Trim from tail. Scan the mbuf chain, + * calculating its length and finding the last mbuf. + * If the adjustment only affects this mbuf, then just + * adjust and return. Otherwise, rescan and truncate + * after the remaining size. + */ + len = -len; + count = 0; + for (;;) { + count += m->om_len; + if (SLIST_NEXT(m, om_next) == (struct os_mbuf *)0) + break; + m = SLIST_NEXT(m, om_next); + } + if (m->om_len >= len) { + m->om_len -= len; + if (OS_MBUF_IS_PKTHDR(mp)) + OS_MBUF_PKTHDR(mp)->omp_len -= len; + return; + } + count -= len; + if (count < 0) + count = 0; + /* + * Correct length for chain is "count". + * Find the mbuf with last data, adjust its length, + * and toss data from remaining mbufs on chain. + */ + m = mp; + if (OS_MBUF_IS_PKTHDR(m)) + OS_MBUF_PKTHDR(m)->omp_len = count; + for (; m; m = SLIST_NEXT(m, om_next)) { + if (m->om_len >= count) { + m->om_len = count; + if (SLIST_NEXT(m, om_next) != NULL) { + os_mbuf_free_chain(SLIST_NEXT(m, om_next)); + SLIST_NEXT(m, om_next) = NULL; + } + break; + } + count -= m->om_len; + } + } +} + +int +os_mbuf_cmpf(const struct os_mbuf *om, int off, const void *data, int len) +{ + uint16_t chunk_sz; + uint16_t data_off; + uint16_t om_off; + int rc; + + if (len <= 0) { + return 0; + } + + data_off = 0; + om = os_mbuf_off(om, off, &om_off); + while (1) { + if (om == NULL) { + return INT_MAX; + } + + chunk_sz = min(om->om_len - om_off, len - data_off); + if (chunk_sz > 0) { + rc = memcmp(om->om_data + om_off, data + data_off, chunk_sz); + if (rc != 0) { + return rc; + } + } + + data_off += chunk_sz; + if (data_off == len) { + return 0; + } + + om = SLIST_NEXT(om, om_next); + om_off = 0; + + if (om == NULL) { + return INT_MAX; + } + } +} + +int +os_mbuf_cmpm(const struct os_mbuf *om1, uint16_t offset1, + const struct os_mbuf *om2, uint16_t offset2, + uint16_t len) +{ + const struct os_mbuf *cur1; + const struct os_mbuf *cur2; + uint16_t bytes_remaining; + uint16_t chunk_sz; + uint16_t om1_left; + uint16_t om2_left; + uint16_t om1_off; + uint16_t om2_off; + int rc; + + om1_off = 0; + om2_off = 0; + + cur1 = os_mbuf_off(om1, offset1, &om1_off); + cur2 = os_mbuf_off(om2, offset2, &om2_off); + + bytes_remaining = len; + while (1) { + if (bytes_remaining == 0) { + return 0; + } + + while (cur1 != NULL && om1_off >= cur1->om_len) { + cur1 = SLIST_NEXT(cur1, om_next); + om1_off = 0; + } + while (cur2 != NULL && om2_off >= cur2->om_len) { + cur2 = SLIST_NEXT(cur2, om_next); + om2_off = 0; + } + + if (cur1 == NULL || cur2 == NULL) { + return INT_MAX; + } + + om1_left = cur1->om_len - om1_off; + om2_left = cur2->om_len - om2_off; + chunk_sz = min(min(om1_left, om2_left), bytes_remaining); + + rc = memcmp(cur1->om_data + om1_off, cur2->om_data + om2_off, + chunk_sz); + if (rc != 0) { + return rc; + } + + om1_off += chunk_sz; + om2_off += chunk_sz; + bytes_remaining -= chunk_sz; + } +} + +struct os_mbuf * +os_mbuf_prepend(struct os_mbuf *om, int len) +{ + struct os_mbuf *p; + int leading; + + while (1) { + /* Fill the available space at the front of the head of the chain, as + * needed. + */ + leading = min(len, OS_MBUF_LEADINGSPACE(om)); + + om->om_data -= leading; + om->om_len += leading; + if (OS_MBUF_IS_PKTHDR(om)) { + OS_MBUF_PKTHDR(om)->omp_len += leading; + } + + len -= leading; + if (len == 0) { + break; + } + + /* The current head didn't have enough space; allocate a new head. */ + if (OS_MBUF_IS_PKTHDR(om)) { + p = os_mbuf_get_pkthdr(om->om_omp, + om->om_pkthdr_len - sizeof (struct os_mbuf_pkthdr)); + } else { + p = os_mbuf_get(om->om_omp, 0); + } + if (p == NULL) { + os_mbuf_free_chain(om); + om = NULL; + break; + } + + if (OS_MBUF_IS_PKTHDR(om)) { + _os_mbuf_copypkthdr(p, om); + om->om_pkthdr_len = 0; + } + + /* Move the new head's data pointer to the end so that data can be + * prepended. + */ + p->om_data += OS_MBUF_TRAILINGSPACE(p); + + SLIST_NEXT(p, om_next) = om; + om = p; + } + + return om; +} + +struct os_mbuf * +os_mbuf_prepend_pullup(struct os_mbuf *om, uint16_t len) +{ + om = os_mbuf_prepend(om, len); + if (om == NULL) { + return NULL; + } + + om = os_mbuf_pullup(om, len); + if (om == NULL) { + return NULL; + } + + return om; +} + +int +os_mbuf_copyinto(struct os_mbuf *om, int off, const void *src, int len) +{ + struct os_mbuf *next; + struct os_mbuf *cur; + const uint8_t *sptr; + uint16_t cur_off; + int copylen; + int rc; + + /* Find the mbuf,offset pair for the start of the destination. */ + cur = os_mbuf_off(om, off, &cur_off); + if (cur == NULL) { + return -1; + } + + /* Overwrite existing data until we reach the end of the chain. */ + sptr = src; + while (1) { + copylen = min(cur->om_len - cur_off, len); + if (copylen > 0) { + memcpy(cur->om_data + cur_off, sptr, copylen); + sptr += copylen; + len -= copylen; + + copylen = 0; + } + + if (len == 0) { + /* All the source data fit in the existing mbuf chain. */ + return 0; + } + + next = SLIST_NEXT(cur, om_next); + if (next == NULL) { + break; + } + + cur = next; + cur_off = 0; + } + + /* Append the remaining data to the end of the chain. */ + rc = os_mbuf_append(cur, sptr, len); + if (rc != 0) { + return rc; + } + + /* Fix up the packet header, if one is present. */ + if (OS_MBUF_IS_PKTHDR(om)) { + OS_MBUF_PKTHDR(om)->omp_len = + max(OS_MBUF_PKTHDR(om)->omp_len, off + len); + } + + return 0; +} + +void +os_mbuf_concat(struct os_mbuf *first, struct os_mbuf *second) +{ + struct os_mbuf *next; + struct os_mbuf *cur; + + /* Point 'cur' to the last buffer in the first chain. */ + cur = first; + while (1) { + next = SLIST_NEXT(cur, om_next); + if (next == NULL) { + break; + } + + cur = next; + } + + /* Attach the second chain to the end of the first. */ + SLIST_NEXT(cur, om_next) = second; + + /* If the first chain has a packet header, calculate the length of the + * second chain and add it to the header length. + */ + if (OS_MBUF_IS_PKTHDR(first)) { + if (OS_MBUF_IS_PKTHDR(second)) { + OS_MBUF_PKTHDR(first)->omp_len += OS_MBUF_PKTHDR(second)->omp_len; + } else { + for (cur = second; cur != NULL; cur = SLIST_NEXT(cur, om_next)) { + OS_MBUF_PKTHDR(first)->omp_len += cur->om_len; + } + } + } + + second->om_pkthdr_len = 0; +} + +void * +os_mbuf_extend(struct os_mbuf *om, uint16_t len) +{ + struct os_mbuf *newm; + struct os_mbuf *last; + void *data; + + if (len > om->om_omp->omp_databuf_len) { + return NULL; + } + + /* Scroll to last mbuf in the chain */ + last = om; + while (SLIST_NEXT(last, om_next) != NULL) { + last = SLIST_NEXT(last, om_next); + } + + if (OS_MBUF_TRAILINGSPACE(last) < len) { + newm = os_mbuf_get(om->om_omp, 0); + if (newm == NULL) { + return NULL; + } + + SLIST_NEXT(last, om_next) = newm; + last = newm; + } + + data = last->om_data + last->om_len; + last->om_len += len; + + if (OS_MBUF_IS_PKTHDR(om)) { + OS_MBUF_PKTHDR(om)->omp_len += len; + } + + return data; +} + + +struct os_mbuf * +os_mbuf_pullup(struct os_mbuf *om, uint16_t len) +{ + struct os_mbuf_pool *omp; + struct os_mbuf *next; + struct os_mbuf *om2; + int count; + int space; + + omp = om->om_omp; + + /* + * If first mbuf has no cluster, and has room for len bytes + * without shifting current data, pullup into it, + * otherwise allocate a new mbuf to prepend to the chain. + */ + if (om->om_len >= len) { + return (om); + } + if (om->om_len + OS_MBUF_TRAILINGSPACE(om) >= len && + SLIST_NEXT(om, om_next)) { + om2 = om; + om = SLIST_NEXT(om, om_next); + len -= om2->om_len; + } else { + if (len > omp->omp_databuf_len - om->om_pkthdr_len) { + goto bad; + } + + om2 = os_mbuf_get(omp, 0); + if (om2 == NULL) { + goto bad; + } + + if (OS_MBUF_IS_PKTHDR(om)) { + _os_mbuf_copypkthdr(om2, om); + } + } + space = OS_MBUF_TRAILINGSPACE(om2); + do { + count = min(min(len, space), om->om_len); + memcpy(om2->om_data + om2->om_len, om->om_data, count); + len -= count; + om2->om_len += count; + om->om_len -= count; + space -= count; + if (om->om_len) { + om->om_data += count; + } else { + next = SLIST_NEXT(om, om_next); + os_mbuf_free(om); + om = next; + } + } while (len > 0 && om); + if (len > 0) { + os_mbuf_free(om2); + goto bad; + } + SLIST_NEXT(om2, om_next) = om; + return (om2); +bad: + os_mbuf_free_chain(om); + return (NULL); +} + +struct os_mbuf * +os_mbuf_trim_front(struct os_mbuf *om) +{ + struct os_mbuf *next; + struct os_mbuf *cur; + + /* Abort early if there is nothing to trim. */ + if (om->om_len != 0) { + return om; + } + + /* Starting with the second mbuf in the chain, continue removing and + * freeing mbufs until an non-empty one is encountered. + */ + cur = SLIST_NEXT(om, om_next); + while (cur != NULL && cur->om_len == 0) { + next = SLIST_NEXT(cur, om_next); + + SLIST_NEXT(om, om_next) = next; + os_mbuf_free(cur); + + cur = next; + } + + if (cur == NULL) { + /* All buffers after the first have been freed. */ + return om; + } + + /* Try to remove the first mbuf in the chain. If this buffer contains a + * packet header, make sure the second buffer can accommodate it. + */ + if (OS_MBUF_LEADINGSPACE(cur) >= om->om_pkthdr_len) { + /* Second buffer has room; copy packet header. */ + cur->om_pkthdr_len = om->om_pkthdr_len; + memcpy(OS_MBUF_PKTHDR(cur), OS_MBUF_PKTHDR(om), om->om_pkthdr_len); + + /* Free first buffer. */ + os_mbuf_free(om); + om = cur; + } + + return om; +} + +struct os_mbuf * +os_mbuf_pack_chains(struct os_mbuf *m1, struct os_mbuf *m2) +{ + uint16_t rem_len; + uint16_t copylen; + uint8_t *dptr; + struct os_mbuf *cur; + struct os_mbuf *next; + + /* If m1 is NULL, return NULL */ + if (m1 == NULL) { + return NULL; + } + + /* + * Concatenate the two chains to start. This will discard packet header in + * m2 and adjust packet length in m1 if m1 has a packet header. + */ + if (m2 != NULL) { + os_mbuf_concat(m1, m2); + } + + cur = m1; + while (1) { + /* If there is leading space in the mbuf, move data up */ + if (OS_MBUF_LEADINGSPACE(cur)) { + dptr = &cur->om_databuf[0]; + if (OS_MBUF_IS_PKTHDR(cur)) { + dptr += cur->om_pkthdr_len; + } + memmove(dptr, cur->om_data, cur->om_len); + cur->om_data = dptr; + } + + /* Set pointer to where we will begin copying data in current mbuf */ + dptr = cur->om_data + cur->om_len; + + /* Get a pointer to the next buf we want to absorb */ + next = SLIST_NEXT(cur, om_next); + + /* + * Is there trailing space in the mbuf? If so, copy data from + * following mbufs into the current mbuf + */ + rem_len = OS_MBUF_TRAILINGSPACE(cur); + while (rem_len && next) { + copylen = min(rem_len, next->om_len); + memcpy(dptr, next->om_data, copylen); + cur->om_len += copylen; + dptr += copylen; + rem_len -= copylen; + + /* + * We copied bytes from the next mbuf. Move the data pointer + * and subtract from its length + */ + next->om_data += copylen; + next->om_len -= copylen; + + /* + * Keep removing and freeing consecutive zero length mbufs, + * stopping when we find one with data in it or we have + * reached the end. This will prevent any zero length mbufs + * from remaining in the chain. + */ + while (next->om_len == 0) { + SLIST_NEXT(cur, om_next) = SLIST_NEXT(next, om_next); + os_mbuf_free(next); + next = SLIST_NEXT(cur, om_next); + if (next == NULL) { + break; + } + } + } + + /* If no mbufs are left, we are done */ + if (next == NULL) { + break; + } + + /* Move cur to next as we filled up current */ + cur = next; + } + + return m1; +} diff --git a/src/libs/mynewt-nimble/porting/nimble/src/os_mempool.c b/src/libs/mynewt-nimble/porting/nimble/src/os_mempool.c new file mode 100644 index 00000000..6a9d2185 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/os_mempool.c @@ -0,0 +1,344 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "os/os.h" + +#include <string.h> +#include <assert.h> +#include <stdbool.h> + +#define OS_MEM_TRUE_BLOCK_SIZE(bsize) OS_ALIGN(bsize, OS_ALIGNMENT) +#define OS_MEMPOOL_TRUE_BLOCK_SIZE(mp) OS_MEM_TRUE_BLOCK_SIZE(mp->mp_block_size) + +STAILQ_HEAD(, os_mempool) g_os_mempool_list = + STAILQ_HEAD_INITIALIZER(g_os_mempool_list); + +#if MYNEWT_VAL(OS_MEMPOOL_POISON) +static uint32_t os_mem_poison = 0xde7ec7ed; + +static void +os_mempool_poison(void *start, int sz) +{ + int i; + char *p = start; + + for (i = sizeof(struct os_memblock); i < sz; + i = i + sizeof(os_mem_poison)) { + memcpy(p + i, &os_mem_poison, min(sizeof(os_mem_poison), sz - i)); + } +} + +static void +os_mempool_poison_check(void *start, int sz) +{ + int i; + char *p = start; + + for (i = sizeof(struct os_memblock); i < sz; + i = i + sizeof(os_mem_poison)) { + assert(!memcmp(p + i, &os_mem_poison, + min(sizeof(os_mem_poison), sz - i))); + } +} +#else +#define os_mempool_poison(start, sz) +#define os_mempool_poison_check(start, sz) +#endif + +os_error_t +os_mempool_init(struct os_mempool *mp, uint16_t blocks, uint32_t block_size, + void *membuf, char *name) +{ + int true_block_size; + uint8_t *block_addr; + struct os_memblock *block_ptr; + + /* Check for valid parameters */ + if (!mp || (block_size == 0)) { + return OS_INVALID_PARM; + } + + if ((!membuf) && (blocks != 0)) { + return OS_INVALID_PARM; + } + + if (membuf != NULL) { + /* Blocks need to be sized properly and memory buffer should be + * aligned + */ + if (((uintptr_t)membuf & (OS_ALIGNMENT - 1)) != 0) { + return OS_MEM_NOT_ALIGNED; + } + } + true_block_size = OS_MEM_TRUE_BLOCK_SIZE(block_size); + + /* Initialize the memory pool structure */ + mp->mp_block_size = block_size; + mp->mp_num_free = blocks; + mp->mp_min_free = blocks; + mp->mp_flags = 0; + mp->mp_num_blocks = blocks; + mp->mp_membuf_addr = (uintptr_t)membuf; + mp->name = name; + os_mempool_poison(membuf, true_block_size); + SLIST_FIRST(mp) = membuf; + + /* Chain the memory blocks to the free list */ + block_addr = (uint8_t *)membuf; + block_ptr = (struct os_memblock *)block_addr; + while (blocks > 1) { + block_addr += true_block_size; + os_mempool_poison(block_addr, true_block_size); + SLIST_NEXT(block_ptr, mb_next) = (struct os_memblock *)block_addr; + block_ptr = (struct os_memblock *)block_addr; + --blocks; + } + + /* Last one in the list should be NULL */ + SLIST_NEXT(block_ptr, mb_next) = NULL; + + STAILQ_INSERT_TAIL(&g_os_mempool_list, mp, mp_list); + + return OS_OK; +} + +os_error_t +os_mempool_ext_init(struct os_mempool_ext *mpe, uint16_t blocks, + uint32_t block_size, void *membuf, char *name) +{ + int rc; + + rc = os_mempool_init(&mpe->mpe_mp, blocks, block_size, membuf, name); + if (rc != 0) { + return rc; + } + + mpe->mpe_mp.mp_flags = OS_MEMPOOL_F_EXT; + mpe->mpe_put_cb = NULL; + mpe->mpe_put_arg = NULL; + + return 0; +} + +os_error_t +os_mempool_clear(struct os_mempool *mp) +{ + struct os_memblock *block_ptr; + int true_block_size; + uint8_t *block_addr; + uint16_t blocks; + + if (!mp) { + return OS_INVALID_PARM; + } + + true_block_size = OS_MEM_TRUE_BLOCK_SIZE(mp->mp_block_size); + + /* cleanup the memory pool structure */ + mp->mp_num_free = mp->mp_num_blocks; + mp->mp_min_free = mp->mp_num_blocks; + os_mempool_poison((void *)mp->mp_membuf_addr, true_block_size); + SLIST_FIRST(mp) = (void *)mp->mp_membuf_addr; + + /* Chain the memory blocks to the free list */ + block_addr = (uint8_t *)mp->mp_membuf_addr; + block_ptr = (struct os_memblock *)block_addr; + blocks = mp->mp_num_blocks; + + while (blocks > 1) { + block_addr += true_block_size; + os_mempool_poison(block_addr, true_block_size); + SLIST_NEXT(block_ptr, mb_next) = (struct os_memblock *)block_addr; + block_ptr = (struct os_memblock *)block_addr; + --blocks; + } + + /* Last one in the list should be NULL */ + SLIST_NEXT(block_ptr, mb_next) = NULL; + + return OS_OK; +} + +bool +os_mempool_is_sane(const struct os_mempool *mp) +{ + struct os_memblock *block; + + /* Verify that each block in the free list belongs to the mempool. */ + SLIST_FOREACH(block, mp, mb_next) { + if (!os_memblock_from(mp, block)) { + return false; + } + os_mempool_poison_check(block, OS_MEMPOOL_TRUE_BLOCK_SIZE(mp)); + } + + return true; +} + +int +os_memblock_from(const struct os_mempool *mp, const void *block_addr) +{ + uintptr_t true_block_size; + uintptr_t baddr_ptr; + uintptr_t end; + + _Static_assert(sizeof block_addr == sizeof baddr_ptr, + "Pointer to void must be native word size."); + + baddr_ptr = (uintptr_t)block_addr; + true_block_size = OS_MEMPOOL_TRUE_BLOCK_SIZE(mp); + end = mp->mp_membuf_addr + (mp->mp_num_blocks * true_block_size); + + /* Check that the block is in the memory buffer range. */ + if ((baddr_ptr < mp->mp_membuf_addr) || (baddr_ptr >= end)) { + return 0; + } + + /* All freed blocks should be on true block size boundaries! */ + if (((baddr_ptr - mp->mp_membuf_addr) % true_block_size) != 0) { + return 0; + } + + return 1; +} + +void * +os_memblock_get(struct os_mempool *mp) +{ + os_sr_t sr; + struct os_memblock *block; + + /* Check to make sure they passed in a memory pool (or something) */ + block = NULL; + if (mp) { + OS_ENTER_CRITICAL(sr); + /* Check for any free */ + if (mp->mp_num_free) { + /* Get a free block */ + block = SLIST_FIRST(mp); + + /* Set new free list head */ + SLIST_FIRST(mp) = SLIST_NEXT(block, mb_next); + + /* Decrement number free by 1 */ + mp->mp_num_free--; + if (mp->mp_min_free > mp->mp_num_free) { + mp->mp_min_free = mp->mp_num_free; + } + } + OS_EXIT_CRITICAL(sr); + + if (block) { + os_mempool_poison_check(block, OS_MEMPOOL_TRUE_BLOCK_SIZE(mp)); + } + } + + return (void *)block; +} + +os_error_t +os_memblock_put_from_cb(struct os_mempool *mp, void *block_addr) +{ + os_sr_t sr; + struct os_memblock *block; + + os_mempool_poison(block_addr, OS_MEMPOOL_TRUE_BLOCK_SIZE(mp)); + + block = (struct os_memblock *)block_addr; + OS_ENTER_CRITICAL(sr); + + /* Chain current free list pointer to this block; make this block head */ + SLIST_NEXT(block, mb_next) = SLIST_FIRST(mp); + SLIST_FIRST(mp) = block; + + /* XXX: Should we check that the number free <= number blocks? */ + /* Increment number free */ + mp->mp_num_free++; + + OS_EXIT_CRITICAL(sr); + + return OS_OK; +} + +os_error_t +os_memblock_put(struct os_mempool *mp, void *block_addr) +{ + struct os_mempool_ext *mpe; + int rc; +#if MYNEWT_VAL(OS_MEMPOOL_CHECK) + struct os_memblock *block; +#endif + + /* Make sure parameters are valid */ + if ((mp == NULL) || (block_addr == NULL)) { + return OS_INVALID_PARM; + } + +#if MYNEWT_VAL(OS_MEMPOOL_CHECK) + /* Check that the block we are freeing is a valid block! */ + assert(os_memblock_from(mp, block_addr)); + + /* + * Check for duplicate free. + */ + SLIST_FOREACH(block, mp, mb_next) { + assert(block != (struct os_memblock *)block_addr); + } +#endif + + /* If this is an extended mempool with a put callback, call the callback + * instead of freeing the block directly. + */ + if (mp->mp_flags & OS_MEMPOOL_F_EXT) { + mpe = (struct os_mempool_ext *)mp; + if (mpe->mpe_put_cb != NULL) { + rc = mpe->mpe_put_cb(mpe, block_addr, mpe->mpe_put_arg); + return rc; + } + } + + /* No callback; free the block. */ + return os_memblock_put_from_cb(mp, block_addr); +} + +struct os_mempool * +os_mempool_info_get_next(struct os_mempool *mp, struct os_mempool_info *omi) +{ + struct os_mempool *cur; + + if (mp == NULL) { + cur = STAILQ_FIRST(&g_os_mempool_list); + } else { + cur = STAILQ_NEXT(mp, mp_list); + } + + if (cur == NULL) { + return (NULL); + } + + omi->omi_block_size = cur->mp_block_size; + omi->omi_num_blocks = cur->mp_num_blocks; + omi->omi_num_free = cur->mp_num_free; + omi->omi_min_free = cur->mp_min_free; + strncpy(omi->omi_name, cur->name, sizeof(omi->omi_name)); + + return (cur); +} + + diff --git a/src/libs/mynewt-nimble/porting/nimble/src/os_msys_init.c b/src/libs/mynewt-nimble/porting/nimble/src/os_msys_init.c new file mode 100644 index 00000000..4d42d184 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/nimble/src/os_msys_init.c @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include "os/os.h" +#include "mem/mem.h" + +#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0 +#define SYSINIT_MSYS_1_MEMBLOCK_SIZE \ + OS_ALIGN(MYNEWT_VAL(MSYS_1_BLOCK_SIZE), OS_ALIGNMENT) +#define SYSINIT_MSYS_1_MEMPOOL_SIZE \ + OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_1_BLOCK_COUNT), \ + SYSINIT_MSYS_1_MEMBLOCK_SIZE) +static os_membuf_t os_msys_init_1_data[SYSINIT_MSYS_1_MEMPOOL_SIZE]; +static struct os_mbuf_pool os_msys_init_1_mbuf_pool; +static struct os_mempool os_msys_init_1_mempool; +#endif + +#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0 +#define SYSINIT_MSYS_2_MEMBLOCK_SIZE \ + OS_ALIGN(MYNEWT_VAL(MSYS_2_BLOCK_SIZE), OS_ALIGNMENT) +#define SYSINIT_MSYS_2_MEMPOOL_SIZE \ + OS_MEMPOOL_SIZE(MYNEWT_VAL(MSYS_2_BLOCK_COUNT), \ + SYSINIT_MSYS_2_MEMBLOCK_SIZE) +static os_membuf_t os_msys_init_2_data[SYSINIT_MSYS_2_MEMPOOL_SIZE]; +static struct os_mbuf_pool os_msys_init_2_mbuf_pool; +static struct os_mempool os_msys_init_2_mempool; +#endif + +static void +os_msys_init_once(void *data, struct os_mempool *mempool, + struct os_mbuf_pool *mbuf_pool, + int block_count, int block_size, char *name) +{ + int rc; + + rc = mem_init_mbuf_pool(data, mempool, mbuf_pool, block_count, block_size, + name); + assert(rc == 0); + + rc = os_msys_register(mbuf_pool); + assert(rc == 0); +} + +void +os_msys_init(void) +{ + os_msys_reset(); + + (void)os_msys_init_once; +#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0 + os_msys_init_once(os_msys_init_1_data, + &os_msys_init_1_mempool, + &os_msys_init_1_mbuf_pool, + MYNEWT_VAL(MSYS_1_BLOCK_COUNT), + SYSINIT_MSYS_1_MEMBLOCK_SIZE, + "msys_1"); +#endif + +#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0 + os_msys_init_once(os_msys_init_2_data, + &os_msys_init_2_mempool, + &os_msys_init_2_mbuf_pool, + MYNEWT_VAL(MSYS_2_BLOCK_COUNT), + SYSINIT_MSYS_2_MEMBLOCK_SIZE, + "msys_2"); +#endif +} diff --git a/src/libs/mynewt-nimble/porting/npl/dummy/include/nimble/nimble_npl_os.h b/src/libs/mynewt-nimble/porting/npl/dummy/include/nimble/nimble_npl_os.h new file mode 100644 index 00000000..996aed23 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/dummy/include/nimble/nimble_npl_os.h @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_NPL_OS_H_ +#define _NIMBLE_NPL_OS_H_ + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define BLE_NPL_OS_ALIGNMENT 4 + +#define BLE_NPL_TIME_FOREVER UINT32_MAX + +typedef uint32_t ble_npl_time_t; +typedef int32_t ble_npl_stime_t; + +struct ble_npl_event { + int dummy; +}; + +struct ble_npl_eventq { + int dummy; +}; + +struct ble_npl_callout { + int dummy; +}; + +struct ble_npl_mutex { + int dummy; +}; + +struct ble_npl_sem { + int dummy; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _NPL_H_ */ diff --git a/src/libs/mynewt-nimble/porting/npl/dummy/src/hci_dummy.c b/src/libs/mynewt-nimble/porting/npl/dummy/src/hci_dummy.c new file mode 100644 index 00000000..78fffe95 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/dummy/src/hci_dummy.c @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include <stdio.h> +#include <stdint.h> +#include "syscfg/syscfg.h" +#include "sysinit/sysinit.h" +#include "os/os_mempool.h" +#include "nimble/ble.h" +#include "nimble/ble_hci_trans.h" +#include "nimble/hci_common.h" + +/* HCI packet types */ +#define HCI_PKT_CMD 0x01 +#define HCI_PKT_ACL 0x02 +#define HCI_PKT_EVT 0x04 +#define HCI_PKT_GTL 0x05 + +/* Buffers for HCI commands data */ +static uint8_t trans_buf_cmd[BLE_HCI_TRANS_CMD_SZ]; +static uint8_t trans_buf_cmd_allocd; + +/* Buffers for HCI events data */ +static uint8_t trans_buf_evt_hi_pool_buf[ OS_MEMPOOL_BYTES( + MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT), + MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE)) ]; +static struct os_mempool trans_buf_evt_hi_pool; +static uint8_t trans_buf_evt_lo_pool_buf[ OS_MEMPOOL_BYTES( + MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT), + MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE)) ]; +static struct os_mempool trans_buf_evt_lo_pool; + +/* Buffers for HCI ACL data */ +#define ACL_POOL_BLOCK_SIZE OS_ALIGN(MYNEWT_VAL(BLE_ACL_BUF_SIZE) + \ + BLE_MBUF_MEMBLOCK_OVERHEAD + \ + BLE_HCI_DATA_HDR_SZ, OS_ALIGNMENT) +static uint8_t trans_buf_acl_pool_buf[ OS_MEMPOOL_BYTES( + MYNEWT_VAL(BLE_ACL_BUF_COUNT), + ACL_POOL_BLOCK_SIZE) ]; +static struct os_mempool trans_buf_acl_pool; +static struct os_mbuf_pool trans_buf_acl_mbuf_pool; + +/* Host interface */ +static ble_hci_trans_rx_cmd_fn *trans_rx_cmd_cb; +static void *trans_rx_cmd_arg; +static ble_hci_trans_rx_acl_fn *trans_rx_acl_cb; +static void *trans_rx_acl_arg; + +/* Called by NimBLE host to reset HCI transport state (i.e. on host reset) */ +int +ble_hci_trans_reset(void) +{ + return 0; +} + +/* Called by NimBLE host to setup callbacks from HCI transport */ +void +ble_hci_trans_cfg_hs(ble_hci_trans_rx_cmd_fn *cmd_cb, void *cmd_arg, + ble_hci_trans_rx_acl_fn *acl_cb, void *acl_arg) +{ + trans_rx_cmd_cb = cmd_cb; + trans_rx_cmd_arg = cmd_arg; + trans_rx_acl_cb = acl_cb; + trans_rx_acl_arg = acl_arg; +} + +/* + * Called by NimBLE host to allocate buffer for HCI Command packet. + * Called by HCI transport to allocate buffer for HCI Event packet. + */ +uint8_t * +ble_hci_trans_buf_alloc(int type) +{ + uint8_t *buf; + + switch (type) { + case BLE_HCI_TRANS_BUF_CMD: + assert(!trans_buf_cmd_allocd); + trans_buf_cmd_allocd = 1; + buf = trans_buf_cmd; + break; + case BLE_HCI_TRANS_BUF_EVT_HI: + buf = os_memblock_get(&trans_buf_evt_hi_pool); + if (buf) { + break; + } + /* no break */ + case BLE_HCI_TRANS_BUF_EVT_LO: + buf = os_memblock_get(&trans_buf_evt_lo_pool); + break; + default: + assert(0); + buf = NULL; + } + + return buf; +} + +/* + * Called by NimBLE host to free buffer allocated for HCI Event packet. + * Called by HCI transport to free buffer allocated for HCI Command packet. + */ +void +ble_hci_trans_buf_free(uint8_t *buf) +{ + int rc; + + if (buf == trans_buf_cmd) { + assert(trans_buf_cmd_allocd); + trans_buf_cmd_allocd = 0; + } else if (os_memblock_from(&trans_buf_evt_hi_pool, buf)) { + rc = os_memblock_put(&trans_buf_evt_hi_pool, buf); + assert(rc == 0); + } else { + assert(os_memblock_from(&trans_buf_evt_lo_pool, buf)); + rc = os_memblock_put(&trans_buf_evt_lo_pool, buf); + assert(rc == 0); + } +} + +/* Called by NimBLE host to send HCI Command packet over HCI transport */ +int +ble_hci_trans_hs_cmd_tx(uint8_t *cmd) +{ + uint8_t *buf = cmd; + + /* + * TODO Send HCI Command packet somewhere. + * Buffer pointed by 'cmd' contains complete HCI Command packet as defined + * by Core spec. + */ + + ble_hci_trans_buf_free(buf); + + return 0; +} + +/* Called by NimBLE host to send HCI ACL Data packet over HCI transport */ +int +ble_hci_trans_hs_acl_tx(struct os_mbuf *om) +{ + uint8_t *buf = om->om_data; + + /* + * TODO Send HCI ACL Data packet somewhere. + * mbuf pointed by 'om' contains complete HCI ACL Data packet as defined + * by Core spec. + */ + (void)buf; + + os_mbuf_free_chain(om); + + return 0; +} + +/* Called by application to send HCI ACL Data packet to host */ +int +hci_transport_send_acl_to_host(uint8_t *buf, uint16_t size) +{ + struct os_mbuf *trans_mbuf; + int rc; + + trans_mbuf = os_mbuf_get_pkthdr(&trans_buf_acl_mbuf_pool, + sizeof(struct ble_mbuf_hdr)); + os_mbuf_append(trans_mbuf, buf, size); + rc = trans_rx_acl_cb(trans_mbuf, trans_rx_acl_arg); + + return rc; +} + +/* Called by application to send HCI Event packet to host */ +int +hci_transport_send_evt_to_host(uint8_t *buf, uint8_t size) +{ + uint8_t *trans_buf; + int rc; + + /* Allocate LE Advertising Report Event from lo pool only */ + if ((buf[0] == BLE_HCI_EVCODE_LE_META) && + (buf[2] == BLE_HCI_LE_SUBEV_ADV_RPT)) { + trans_buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_LO); + if (!trans_buf) { + /* Skip advertising report if we're out of memory */ + return 0; + } + } else { + trans_buf = ble_hci_trans_buf_alloc(BLE_HCI_TRANS_BUF_EVT_HI); + } + + memcpy(trans_buf, buf, size); + + rc = trans_rx_cmd_cb(trans_buf, trans_rx_cmd_arg); + if (rc != 0) { + ble_hci_trans_buf_free(trans_buf); + } + + return rc; +} + +/* Called by application to initialize transport structures */ +int +hci_transport_init(void) +{ + int rc; + + trans_buf_cmd_allocd = 0; + + rc = os_mempool_init(&trans_buf_acl_pool, MYNEWT_VAL(BLE_ACL_BUF_COUNT), + ACL_POOL_BLOCK_SIZE, trans_buf_acl_pool_buf, + "dummy_hci_acl_pool"); + SYSINIT_PANIC_ASSERT(rc == 0); + + rc = os_mbuf_pool_init(&trans_buf_acl_mbuf_pool, &trans_buf_acl_pool, + ACL_POOL_BLOCK_SIZE, + MYNEWT_VAL(BLE_ACL_BUF_COUNT)); + SYSINIT_PANIC_ASSERT(rc == 0); + + rc = os_mempool_init(&trans_buf_evt_hi_pool, + MYNEWT_VAL(BLE_HCI_EVT_HI_BUF_COUNT), + MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE), + trans_buf_evt_hi_pool_buf, + "dummy_hci_hci_evt_hi_pool"); + SYSINIT_PANIC_ASSERT(rc == 0); + + rc = os_mempool_init(&trans_buf_evt_lo_pool, + MYNEWT_VAL(BLE_HCI_EVT_LO_BUF_COUNT), + MYNEWT_VAL(BLE_HCI_EVT_BUF_SIZE), + trans_buf_evt_lo_pool_buf, + "dummy_hci_hci_evt_lo_pool"); + SYSINIT_PANIC_ASSERT(rc == 0); + + return 0; +} diff --git a/src/libs/mynewt-nimble/porting/npl/dummy/src/npl_os_dummy.c b/src/libs/mynewt-nimble/porting/npl/dummy/src/npl_os_dummy.c new file mode 100644 index 00000000..a522531f --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/dummy/src/npl_os_dummy.c @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stddef.h> +#include "nimble/nimble_npl.h" + +bool +ble_npl_os_started(void) +{ + return 0; +} + +void * +ble_npl_get_current_task_id(void) +{ + return NULL; +} + +void +ble_npl_eventq_init(struct ble_npl_eventq *evq) +{ + +} + +struct ble_npl_event * +ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo) +{ +} + +void +ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ +} + +void +ble_npl_eventq_remove(struct ble_npl_eventq *evq, + struct ble_npl_event *ev) +{ + +} + +void +ble_npl_event_run(struct ble_npl_event *ev) +{ + +} + +void +ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, + void *arg) +{ + +} + +bool ble_npl_event_is_queued(struct ble_npl_event *ev) +{ + return false; +} + +void * +ble_npl_event_get_arg(struct ble_npl_event *ev) +{ + return NULL; +} + +void +ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) +{ + +} + +ble_npl_error_t +ble_npl_mutex_init(struct ble_npl_mutex *mu) +{ + return BLE_NPL_ENOENT; +} + +ble_npl_error_t +ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) +{ + return BLE_NPL_ENOENT; +} + +ble_npl_error_t +ble_npl_mutex_release(struct ble_npl_mutex *mu) +{ + return BLE_NPL_ENOENT; +} + +ble_npl_error_t +ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens) +{ + return BLE_NPL_ENOENT; +} + +ble_npl_error_t +ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout) +{ + return BLE_NPL_ENOENT; +} + +ble_npl_error_t +ble_npl_sem_release(struct ble_npl_sem *sem) +{ + return BLE_NPL_ENOENT; +} + +uint16_t +ble_npl_sem_get_count(struct ble_npl_sem *sem) +{ + return 0; +} + +void +ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg) +{ +} + +ble_npl_error_t +ble_npl_callout_reset(struct ble_npl_callout *c, ble_npl_time_t ticks) +{ + return BLE_NPL_ENOENT; +} + +void +ble_npl_callout_stop(struct ble_npl_callout *co) +{ + +} + +bool +ble_npl_callout_is_active(struct ble_npl_callout *c) +{ + return false; +} + +ble_npl_time_t +ble_npl_callout_get_ticks(struct ble_npl_callout *co) +{ + return 0; +} + +uint32_t +ble_npl_time_get(void) +{ + return 0; +} + +ble_npl_error_t +ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) +{ + return BLE_NPL_ENOENT; +} + +ble_npl_error_t +ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms) +{ + return BLE_NPL_ENOENT; +} + +ble_npl_time_t +ble_npl_time_ms_to_ticks32(uint32_t ms) +{ + return 0; +} + +uint32_t +ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks) +{ + return 0; +} + +uint32_t +ble_npl_hw_enter_critical(void) +{ + return 0; +} + +void +ble_npl_hw_exit_critical(uint32_t ctx) +{ + +} diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h new file mode 100644 index 00000000..f04145d3 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h @@ -0,0 +1,301 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_NPL_OS_H_ +#define _NIMBLE_NPL_OS_H_ + +#include <assert.h> +#include <stdint.h> +#include <string.h> +#include "FreeRTOS.h" +#include "queue.h" +#include "semphr.h" +#include "task.h" +#include "timers.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BLE_NPL_OS_ALIGNMENT 4 + +#define BLE_NPL_TIME_FOREVER portMAX_DELAY + +/* This should be compatible with TickType_t */ +typedef uint32_t ble_npl_time_t; +typedef int32_t ble_npl_stime_t; + +struct ble_npl_event { + bool queued; + ble_npl_event_fn *fn; + void *arg; +}; + +struct ble_npl_eventq { + QueueHandle_t q; +}; + +struct ble_npl_callout { + TimerHandle_t handle; + struct ble_npl_eventq *evq; + struct ble_npl_event ev; +}; + +struct ble_npl_mutex { + SemaphoreHandle_t handle; +}; + +struct ble_npl_sem { + SemaphoreHandle_t handle; +}; + +/* + * Simple APIs are just defined as static inline below, but some are a bit more + * complex or require some global state variables and thus are defined in .c + * file instead and static inline wrapper just calls proper implementation. + * We need declarations of these functions and they are defined in header below. + */ +#include "npl_freertos.h" + +static inline bool +ble_npl_os_started(void) +{ + return xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED; +} + +static inline void * +ble_npl_get_current_task_id(void) +{ + return xTaskGetCurrentTaskHandle(); +} + +static inline void +ble_npl_eventq_init(struct ble_npl_eventq *evq) +{ + evq->q = xQueueCreate(32, sizeof(struct ble_npl_eventq *)); +} + +static inline struct ble_npl_event * +ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo) +{ + return npl_freertos_eventq_get(evq, tmo); +} + +static inline void +ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + npl_freertos_eventq_put(evq, ev); +} + +static inline void +ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + npl_freertos_eventq_remove(evq, ev); +} + +static inline void +ble_npl_event_run(struct ble_npl_event *ev) +{ + ev->fn(ev); +} + +static inline bool +ble_npl_eventq_is_empty(struct ble_npl_eventq *evq) +{ + return xQueueIsQueueEmptyFromISR(evq->q); +} + +static inline void +ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, + void *arg) +{ + memset(ev, 0, sizeof(*ev)); + ev->fn = fn; + ev->arg = arg; +} + +static inline bool +ble_npl_event_is_queued(struct ble_npl_event *ev) +{ + return ev->queued; +} + +static inline void * +ble_npl_event_get_arg(struct ble_npl_event *ev) +{ + return ev->arg; +} + +static inline void +ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) +{ + ev->arg = arg; +} + +static inline ble_npl_error_t +ble_npl_mutex_init(struct ble_npl_mutex *mu) +{ + return npl_freertos_mutex_init(mu); +} + +static inline ble_npl_error_t +ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) +{ + return npl_freertos_mutex_pend(mu, timeout); +} + +static inline ble_npl_error_t +ble_npl_mutex_release(struct ble_npl_mutex *mu) +{ + return npl_freertos_mutex_release(mu); +} + +static inline ble_npl_error_t +ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens) +{ + return npl_freertos_sem_init(sem, tokens); +} + +static inline ble_npl_error_t +ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout) +{ + return npl_freertos_sem_pend(sem, timeout); +} + +static inline ble_npl_error_t +ble_npl_sem_release(struct ble_npl_sem *sem) +{ + return npl_freertos_sem_release(sem); +} + +static inline uint16_t +ble_npl_sem_get_count(struct ble_npl_sem *sem) +{ + return uxSemaphoreGetCount(sem->handle); +} + +static inline void +ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg) +{ + npl_freertos_callout_init(co, evq, ev_cb, ev_arg); +} + +static inline ble_npl_error_t +ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks) +{ + return npl_freertos_callout_reset(co, ticks); +} + +static inline void +ble_npl_callout_stop(struct ble_npl_callout *co) +{ + xTimerStop(co->handle, portMAX_DELAY); +} + +static inline bool +ble_npl_callout_is_active(struct ble_npl_callout *co) +{ + return xTimerIsTimerActive(co->handle) == pdTRUE; +} + +static inline ble_npl_time_t +ble_npl_callout_get_ticks(struct ble_npl_callout *co) +{ + return xTimerGetExpiryTime(co->handle); +} + +static inline uint32_t +ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t time) +{ + return npl_freertos_callout_remaining_ticks(co, time); +} + +static inline void +ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg) +{ + co->ev.arg = arg; +} + +static inline uint32_t +ble_npl_time_get(void) +{ + return xTaskGetTickCountFromISR(); +} + +static inline ble_npl_error_t +ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) +{ + return npl_freertos_time_ms_to_ticks(ms, out_ticks); +} + +static inline ble_npl_error_t +ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms) +{ + return ble_npl_time_ticks_to_ms(ticks, out_ms); +} + +static inline ble_npl_time_t +ble_npl_time_ms_to_ticks32(uint32_t ms) +{ + return ms * configTICK_RATE_HZ / 1000; +} + +static inline uint32_t +ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks) +{ + return ticks * 1000 / configTICK_RATE_HZ; +} + +static inline void +ble_npl_time_delay(ble_npl_time_t ticks) +{ + vTaskDelay(ticks); +} + +#if NIMBLE_CFG_CONTROLLER +static inline void +ble_npl_hw_set_isr(int irqn, void (*addr)(void)) +{ + npl_freertos_hw_set_isr(irqn, addr); +} +#endif + +static inline uint32_t +ble_npl_hw_enter_critical(void) +{ + //vPortEnterCritical(); + npl_freertos_hw_enter_critical(); + return 0; +} + +static inline void +ble_npl_hw_exit_critical(uint32_t ctx) +{ + // vPortExitCritical(); + npl_freertos_hw_exit_critical(ctx); + +} + +#ifdef __cplusplus +} +#endif + +#endif /* _NPL_H_ */ diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h new file mode 100644 index 00000000..43cbf291 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/nimble_port_freertos.h @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_PORT_FREERTOS_H +#define _NIMBLE_PORT_FREERTOS_H + +#include "nimble/nimble_npl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void nimble_port_freertos_init(TaskFunction_t host_task_fn); + +#ifdef __cplusplus +} +#endif + +#endif /* _NIMBLE_PORT_FREERTOS_H */ diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/npl_freertos.h b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/npl_freertos.h new file mode 100644 index 00000000..a7b1c4aa --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/freertos/include/nimble/npl_freertos.h @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NPL_FREERTOS_H_ +#define _NPL_FREERTOS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct ble_npl_eventq *npl_freertos_eventq_dflt_get(void); + +struct ble_npl_event *npl_freertos_eventq_get(struct ble_npl_eventq *evq, + ble_npl_time_t tmo); + +void npl_freertos_eventq_put(struct ble_npl_eventq *evq, + struct ble_npl_event *ev); + +void npl_freertos_eventq_remove(struct ble_npl_eventq *evq, + struct ble_npl_event *ev); + +ble_npl_error_t npl_freertos_mutex_init(struct ble_npl_mutex *mu); + +ble_npl_error_t npl_freertos_mutex_pend(struct ble_npl_mutex *mu, + ble_npl_time_t timeout); + +ble_npl_error_t npl_freertos_mutex_release(struct ble_npl_mutex *mu); + +ble_npl_error_t npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens); + +ble_npl_error_t npl_freertos_sem_pend(struct ble_npl_sem *sem, + ble_npl_time_t timeout); + +ble_npl_error_t npl_freertos_sem_release(struct ble_npl_sem *sem); + +void npl_freertos_callout_init(struct ble_npl_callout *co, + struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg); + +ble_npl_error_t npl_freertos_callout_reset(struct ble_npl_callout *co, + ble_npl_time_t ticks); + +ble_npl_time_t npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t now); + +ble_npl_error_t npl_freertos_time_ms_to_ticks(uint32_t ms, + ble_npl_time_t *out_ticks); + +ble_npl_error_t npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, + uint32_t *out_ms); + +void npl_freertos_hw_set_isr(int irqn, void (*addr)(void)); + +uint32_t npl_freertos_hw_enter_critical(void); + +void npl_freertos_hw_exit_critical(uint32_t ctx); + +#ifdef __cplusplus +} +#endif + +#endif /* _NPL_FREERTOS_H_ */ diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c b/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c new file mode 100644 index 00000000..8ee3475a --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/freertos/src/nimble_port_freertos.c @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stddef.h> +#include "FreeRTOS.h" +#include "task.h" +#include "nimble/nimble_port.h" + +#if NIMBLE_CFG_CONTROLLER +static TaskHandle_t ll_task_h; +#endif +static TaskHandle_t host_task_h; + +void +nimble_port_freertos_init(TaskFunction_t host_task_fn) +{ +#if NIMBLE_CFG_CONTROLLER + /* + * Create task where NimBLE LL will run. This one is required as LL has its + * own event queue and should have highest priority. The task function is + * provided by NimBLE and in case of FreeRTOS it does not need to be wrapped + * since it has compatible prototype. + */ + xTaskCreate(nimble_port_ll_task_func, "ll", configMINIMAL_STACK_SIZE + 400, + NULL, configMAX_PRIORITIES - 1, &ll_task_h); +#endif + + /* + * Create task where NimBLE host will run. It is not strictly necessary to + * have separate task for NimBLE host, but since something needs to handle + * default queue it is just easier to make separate task which does this. + */ + xTaskCreate(host_task_fn, "ble", configMINIMAL_STACK_SIZE + 400, + NULL, tskIDLE_PRIORITY + 1, &host_task_h); +} diff --git a/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c new file mode 100644 index 00000000..87936bd8 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/freertos/src/npl_os_freertos.c @@ -0,0 +1,351 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include <stddef.h> +#include <string.h> +#include "nimble/nimble_npl.h" + +static inline bool +in_isr(void) +{ + /* XXX hw specific! */ + return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) != 0; +} + +struct ble_npl_event * +npl_freertos_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo) +{ + struct ble_npl_event *ev = NULL; + BaseType_t woken; + BaseType_t ret; + + if (in_isr()) { + assert(tmo == 0); + ret = xQueueReceiveFromISR(evq->q, &ev, &woken); + portYIELD_FROM_ISR(woken); + } else { + ret = xQueueReceive(evq->q, &ev, tmo); + } + assert(ret == pdPASS || ret == errQUEUE_EMPTY); + + if (ev) { + ev->queued = false; + } + + return ev; +} + +void +npl_freertos_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + BaseType_t woken; + BaseType_t ret; + + if (ev->queued) { + return; + } + + ev->queued = true; + + if (in_isr()) { + ret = xQueueSendToBackFromISR(evq->q, &ev, &woken); + portYIELD_FROM_ISR(woken); + } else { + ret = xQueueSendToBack(evq->q, &ev, portMAX_DELAY); + } + + assert(ret == pdPASS); +} + +void +npl_freertos_eventq_remove(struct ble_npl_eventq *evq, + struct ble_npl_event *ev) +{ + struct ble_npl_event *tmp_ev; + BaseType_t ret; + int i; + int count; + BaseType_t woken, woken2; + + if (!ev->queued) { + return; + } + + /* + * XXX We cannot extract element from inside FreeRTOS queue so as a quick + * workaround we'll just remove all elements and add them back except the + * one we need to remove. This is silly, but works for now - we probably + * better use counting semaphore with os_queue to handle this in future. + */ + + if (in_isr()) { + woken = pdFALSE; + + count = uxQueueMessagesWaitingFromISR(evq->q); + for (i = 0; i < count; i++) { + ret = xQueueReceiveFromISR(evq->q, &tmp_ev, &woken2); + assert(ret == pdPASS); + woken |= woken2; + + if (tmp_ev == ev) { + continue; + } + + ret = xQueueSendToBackFromISR(evq->q, &tmp_ev, &woken2); + assert(ret == pdPASS); + woken |= woken2; + } + + portYIELD_FROM_ISR(woken); + } else { + vPortEnterCritical(); + + count = uxQueueMessagesWaiting(evq->q); + for (i = 0; i < count; i++) { + ret = xQueueReceive(evq->q, &tmp_ev, 0); + assert(ret == pdPASS); + + if (tmp_ev == ev) { + continue; + } + + ret = xQueueSendToBack(evq->q, &tmp_ev, 0); + assert(ret == pdPASS); + } + + vPortExitCritical(); + } + + ev->queued = 0; +} + +ble_npl_error_t +npl_freertos_mutex_init(struct ble_npl_mutex *mu) +{ + if (!mu) { + return BLE_NPL_INVALID_PARAM; + } + + mu->handle = xSemaphoreCreateRecursiveMutex(); + assert(mu->handle); + + return BLE_NPL_OK; +} + +ble_npl_error_t +npl_freertos_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) +{ + BaseType_t ret; + + if (!mu) { + return BLE_NPL_INVALID_PARAM; + } + + assert(mu->handle); + + if (in_isr()) { + ret = pdFAIL; + assert(0); + } else { + ret = xSemaphoreTakeRecursive(mu->handle, timeout); + } + + return ret == pdPASS ? BLE_NPL_OK : BLE_NPL_TIMEOUT; +} + +ble_npl_error_t +npl_freertos_mutex_release(struct ble_npl_mutex *mu) +{ + if (!mu) { + return BLE_NPL_INVALID_PARAM; + } + + assert(mu->handle); + + if (in_isr()) { + assert(0); + } else { + if (xSemaphoreGiveRecursive(mu->handle) != pdPASS) { + return BLE_NPL_BAD_MUTEX; + } + } + + return BLE_NPL_OK; +} + +ble_npl_error_t +npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens) +{ + if (!sem) { + return BLE_NPL_INVALID_PARAM; + } + + sem->handle = xSemaphoreCreateCounting(128, tokens); + assert(sem->handle); + + return BLE_NPL_OK; +} + +ble_npl_error_t +npl_freertos_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout) +{ + BaseType_t woken; + BaseType_t ret; + + if (!sem) { + return BLE_NPL_INVALID_PARAM; + } + + assert(sem->handle); + + if (in_isr()) { + assert(timeout == 0); + ret = xSemaphoreTakeFromISR(sem->handle, &woken); + portYIELD_FROM_ISR(woken); + } else { + ret = xSemaphoreTake(sem->handle, timeout); + } + + return ret == pdPASS ? BLE_NPL_OK : BLE_NPL_TIMEOUT; +} + +ble_npl_error_t +npl_freertos_sem_release(struct ble_npl_sem *sem) +{ + BaseType_t ret; + BaseType_t woken; + + if (!sem) { + return BLE_NPL_INVALID_PARAM; + } + + assert(sem->handle); + + if (in_isr()) { + ret = xSemaphoreGiveFromISR(sem->handle, &woken); + portYIELD_FROM_ISR(woken); + } else { + ret = xSemaphoreGive(sem->handle); + } + + assert(ret == pdPASS); + return BLE_NPL_OK; +} + +static void +os_callout_timer_cb(TimerHandle_t timer) +{ + struct ble_npl_callout *co; + + co = pvTimerGetTimerID(timer); + assert(co); + + if (co->evq) { + ble_npl_eventq_put(co->evq, &co->ev); + } else { + co->ev.fn(&co->ev); + } +} + +void +npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg) +{ + memset(co, 0, sizeof(*co)); + co->handle = xTimerCreate("co", 1, pdFALSE, co, os_callout_timer_cb); + co->evq = evq; + ble_npl_event_init(&co->ev, ev_cb, ev_arg); +} + +ble_npl_error_t +npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks) +{ + BaseType_t woken1, woken2, woken3; + + if (ticks < 0) { + return BLE_NPL_INVALID_PARAM; + } + + if (ticks == 0) { + ticks = 1; + } + + if (in_isr()) { + xTimerStopFromISR(co->handle, &woken1); + xTimerChangePeriodFromISR(co->handle, ticks, &woken2); + xTimerResetFromISR(co->handle, &woken3); + + portYIELD_FROM_ISR(woken1 || woken2 || woken3); + } else { + xTimerStop(co->handle, portMAX_DELAY); + xTimerChangePeriod(co->handle, ticks, portMAX_DELAY); + xTimerReset(co->handle, portMAX_DELAY); + } + + return BLE_NPL_OK; +} + +ble_npl_time_t +npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t now) +{ + ble_npl_time_t rt; + uint32_t exp; + + exp = xTimerGetExpiryTime(co->handle); + + if (exp > now) { + rt = exp - now; + } else { + rt = 0; + } + + return rt; +} + +ble_npl_error_t +npl_freertos_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) +{ + uint64_t ticks; + + ticks = ((uint64_t)ms * configTICK_RATE_HZ) / 1000; + if (ticks > UINT32_MAX) { + return BLE_NPL_EINVAL; + } + + *out_ticks = ticks; + + return 0; +} + +ble_npl_error_t +npl_freertos_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms) +{ + uint64_t ms; + + ms = ((uint64_t)ticks * 1000) / configTICK_RATE_HZ; + if (ms > UINT32_MAX) { + return BLE_NPL_EINVAL; + } + + *out_ms = ms; + + return 0; +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/include/console/console.h b/src/libs/mynewt-nimble/porting/npl/linux/include/console/console.h new file mode 100644 index 00000000..ccbfc015 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/include/console/console.h @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef __CONSOLE_H__ +#define __CONSOLE_H__ + +#include <stdio.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define console_printf(_fmt, ...) printf(_fmt, ##__VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif /* __CONSOLE_H__ */ diff --git a/src/libs/mynewt-nimble/porting/npl/linux/include/nimble/nimble_npl_os.h b/src/libs/mynewt-nimble/porting/npl/linux/include/nimble/nimble_npl_os.h new file mode 100644 index 00000000..bdd39886 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/include/nimble/nimble_npl_os.h @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_NPL_OS_H_ +#define _NIMBLE_NPL_OS_H_ + +#include <assert.h> +#include <stdint.h> +#include <string.h> + +#include "os_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BLE_NPL_OS_ALIGNMENT 4 + +#define BLE_NPL_TIME_FOREVER INT32_MAX + +#define SYSINIT_PANIC_MSG(msg) __assert_fail(msg, __FILE__, __LINE__, __func__) + +#define SYSINIT_PANIC_ASSERT_MSG(rc, msg) do \ +{ \ + if (!(rc)) { \ + SYSINIT_PANIC_MSG(msg); \ + } \ +} while (0) + +#ifdef __cplusplus +} +#endif + +#endif /* _NPL_H_ */ diff --git a/src/libs/mynewt-nimble/porting/npl/linux/include/nimble/os_types.h b/src/libs/mynewt-nimble/porting/npl/linux/include/nimble/os_types.h new file mode 100644 index 00000000..a5d8bf54 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/include/nimble/os_types.h @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NPL_OS_TYPES_H +#define _NPL_OS_TYPES_H + +#include <time.h> +#include <signal.h> +#include <stdbool.h> +#include <pthread.h> +#include <semaphore.h> + +/* The highest and lowest task priorities */ +#define OS_TASK_PRI_HIGHEST (sched_get_priority_max(SCHED_RR)) +#define OS_TASK_PRI_LOWEST (sched_get_priority_min(SCHED_RR)) + +typedef uint32_t ble_npl_time_t; +typedef int32_t ble_npl_stime_t; + +//typedef int os_sr_t; +typedef int ble_npl_stack_t; + + +struct ble_npl_event { + uint8_t ev_queued; + ble_npl_event_fn *ev_cb; + void *ev_arg; +}; + +struct ble_npl_eventq { + void *q; +}; + +struct ble_npl_callout { + struct ble_npl_event c_ev; + struct ble_npl_eventq *c_evq; + uint32_t c_ticks; + timer_t c_timer; + bool c_active; +}; + +struct ble_npl_mutex { + pthread_mutex_t lock; + pthread_mutexattr_t attr; + struct timespec wait; +}; + +struct ble_npl_sem { + sem_t lock; +}; + +struct ble_npl_task { + pthread_t handle; + pthread_attr_t attr; + struct sched_param param; + const char* name; +}; + +typedef void *(*ble_npl_task_func_t)(void *); + +int ble_npl_task_init(struct ble_npl_task *t, const char *name, ble_npl_task_func_t func, + void *arg, uint8_t prio, ble_npl_time_t sanity_itvl, + ble_npl_stack_t *stack_bottom, uint16_t stack_size); + +int ble_npl_task_remove(struct ble_npl_task *t); + +uint8_t ble_npl_task_count(void); + +void ble_npl_task_yield(void); + +#endif // _NPL_OS_TYPES_H diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/os_atomic.c b/src/libs/mynewt-nimble/porting/npl/linux/src/os_atomic.c new file mode 100644 index 00000000..3aaec08a --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/os_atomic.c @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stdint.h> +#include <pthread.h> + +#include "nimble/nimble_npl.h" + +static pthread_mutex_t s_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + +uint32_t ble_npl_hw_enter_critical(void) +{ + pthread_mutex_lock(&s_mutex); + return 0; +} + +void ble_npl_hw_exit_critical(uint32_t ctx) +{ + pthread_mutex_unlock(&s_mutex); +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/os_callout.c b/src/libs/mynewt-nimble/porting/npl/linux/src/os_callout.c new file mode 100644 index 00000000..d3091fa9 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/os_callout.c @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include <stdio.h> +#include <stdint.h> +#include <string.h> + +#include <time.h> +#include <signal.h> + +#include "nimble/nimble_npl.h" + +static void +ble_npl_callout_timer_cb(union sigval sv) +{ + struct ble_npl_callout *c = (struct ble_npl_callout *)sv.sival_ptr; + assert(c); + + if (c->c_evq) { + ble_npl_eventq_put(c->c_evq, &c->c_ev); + } else { + c->c_ev.ev_cb(&c->c_ev); + } +} + +void ble_npl_callout_init(struct ble_npl_callout *c, + struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, + void *ev_arg) +{ + struct sigevent event; + + /* Initialize the callout. */ + memset(c, 0, sizeof(*c)); + c->c_ev.ev_cb = ev_cb; + c->c_ev.ev_arg = ev_arg; + c->c_evq = evq; + c->c_active = false; + + event.sigev_notify = SIGEV_THREAD; + event.sigev_value.sival_ptr = c; // put callout obj in signal args + event.sigev_notify_function = ble_npl_callout_timer_cb; + event.sigev_notify_attributes = NULL; + + timer_create(CLOCK_REALTIME, &event, &c->c_timer); +} + +bool ble_npl_callout_is_active(struct ble_npl_callout *c) +{ + // TODO: seek native posix method to determine whether timer_t is active. + // TODO: fix bug where one-shot timer is still active after fired. + return c->c_active; +} + +int ble_npl_callout_inited(struct ble_npl_callout *c) +{ + return (c->c_timer != NULL); +} + +ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c, + ble_npl_time_t ticks) +{ + struct itimerspec its; + + if (ticks < 0) { + return BLE_NPL_EINVAL; + } + + if (ticks == 0) { + ticks = 1; + } + + c->c_ticks = ble_npl_time_get() + ticks; + + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; // one shot + its.it_value.tv_sec = (ticks / 1000); + its.it_value.tv_nsec = (ticks % 1000) * 1000000; // expiration + its.it_value.tv_nsec %= 1000000000; + c->c_active = true; + timer_settime(c->c_timer, 0, &its, NULL); + + return BLE_NPL_OK; +} + +int ble_npl_callout_queued(struct ble_npl_callout *c) +{ + struct itimerspec its; + timer_gettime(c->c_timer, &its); + + return ((its.it_value.tv_sec > 0) || + (its.it_value.tv_nsec > 0)); +} + +void ble_npl_callout_stop(struct ble_npl_callout *c) +{ + if (!ble_npl_callout_inited(c)) { + return; + } + + struct itimerspec its; + its.it_interval.tv_sec = 0; + its.it_interval.tv_nsec = 0; + its.it_value.tv_sec = 0; + its.it_value.tv_nsec = 0; + timer_settime(c->c_timer, 0, &its, NULL); + c->c_active = false; +} + +ble_npl_time_t +ble_npl_callout_get_ticks(struct ble_npl_callout *co) +{ + return co->c_ticks; +} + +void +ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg) +{ + co->c_ev.ev_arg = arg; +} + +uint32_t +ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t now) +{ + ble_npl_time_t rt; + uint32_t exp; + + struct itimerspec its; + timer_gettime(co->c_timer, &its); + + exp = its.it_value.tv_sec * 1000; + + if (exp > now) { + rt = exp - now; + } else { + rt = 0; + } + + return rt; +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/os_eventq.cc b/src/libs/mynewt-nimble/porting/npl/linux/src/os_eventq.cc new file mode 100644 index 00000000..817d8397 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/os_eventq.cc @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include <stdint.h> +#include <string.h> + +#include "nimble/nimble_npl.h" +#include "wqueue.h" + +extern "C" { + +typedef wqueue<ble_npl_event *> wqueue_t; + +static struct ble_npl_eventq dflt_evq; + +struct ble_npl_eventq * +ble_npl_eventq_dflt_get(void) +{ + if (!dflt_evq.q) { + dflt_evq.q = new wqueue_t(); + } + + return &dflt_evq; +} + +void +ble_npl_eventq_init(struct ble_npl_eventq *evq) +{ + evq->q = new wqueue_t(); +} + +bool +ble_npl_eventq_is_empty(struct ble_npl_eventq *evq) +{ + wqueue_t *q = static_cast<wqueue_t *>(evq->q); + + if (q->size()) { + return 1; + } else { + return 0; + } +} + +int +ble_npl_eventq_inited(const struct ble_npl_eventq *evq) +{ + return (evq->q != NULL); +} + +void +ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + wqueue_t *q = static_cast<wqueue_t *>(evq->q); + + if (ev->ev_queued) { + return; + } + + ev->ev_queued = 1; + q->put(ev); +} + +struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *evq, + ble_npl_time_t tmo) +{ + struct ble_npl_event *ev; + wqueue_t *q = static_cast<wqueue_t *>(evq->q); + + ev = q->get(tmo); + + if (ev) { + ev->ev_queued = 0; + } + + return ev; +} + +void +ble_npl_eventq_run(struct ble_npl_eventq *evq) +{ + struct ble_npl_event *ev; + + ev = ble_npl_eventq_get(evq, BLE_NPL_TIME_FOREVER); + ble_npl_event_run(ev); +} + + +// ======================================================================== +// Event Implementation +// ======================================================================== + +void +ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, + void *arg) +{ + memset(ev, 0, sizeof(*ev)); + ev->ev_cb = fn; + ev->ev_arg = arg; +} + +bool +ble_npl_event_is_queued(struct ble_npl_event *ev) +{ + return ev->ev_queued; +} + +void * +ble_npl_event_get_arg(struct ble_npl_event *ev) +{ + return ev->ev_arg; +} + +void +ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) +{ + ev->ev_arg = arg; +} + +void +ble_npl_event_run(struct ble_npl_event *ev) +{ + assert(ev->ev_cb != NULL); + + ev->ev_cb(ev); +} + +void +ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + wqueue_t *q = static_cast<wqueue_t *>(evq->q); + + if (!ev->ev_queued) { + return; + } + + ev->ev_queued = 0; + q->remove(ev); +} + +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/os_mutex.c b/src/libs/mynewt-nimble/porting/npl/linux/src/os_mutex.c new file mode 100644 index 00000000..c7d6190e --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/os_mutex.c @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <errno.h> +#include <pthread.h> + +#include "os/os.h" +#include "nimble/nimble_npl.h" + +ble_npl_error_t +ble_npl_mutex_init(struct ble_npl_mutex *mu) +{ + if (!mu) { + return BLE_NPL_INVALID_PARAM; + } + + pthread_mutexattr_init(&mu->attr); + pthread_mutexattr_settype(&mu->attr, PTHREAD_MUTEX_RECURSIVE_NP); + pthread_mutex_init(&mu->lock, &mu->attr); + + return BLE_NPL_OK; +} + +ble_npl_error_t +ble_npl_mutex_release(struct ble_npl_mutex *mu) +{ + if (!mu) { + return BLE_NPL_INVALID_PARAM; + } + + if (pthread_mutex_unlock(&mu->lock)) { + return BLE_NPL_BAD_MUTEX; + } + + return BLE_NPL_OK; +} + +ble_npl_error_t +ble_npl_mutex_pend(struct ble_npl_mutex *mu, uint32_t timeout) +{ + int err; + + if (!mu) { + return BLE_NPL_INVALID_PARAM; + } + + if (timeout == BLE_NPL_TIME_FOREVER) { + err = pthread_mutex_lock(&mu->lock); + } else { + err = clock_gettime(CLOCK_REALTIME, &mu->wait); + if (err) { + return BLE_NPL_ERROR; + } + + mu->wait.tv_sec += timeout / 1000; + mu->wait.tv_nsec += (timeout % 1000) * 1000000; + + err = pthread_mutex_timedlock(&mu->lock, &mu->wait); + if (err == ETIMEDOUT) { + return BLE_NPL_TIMEOUT; + } + } + + return (err) ? BLE_NPL_ERROR : BLE_NPL_OK; +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/os_sem.c b/src/libs/mynewt-nimble/porting/npl/linux/src/os_sem.c new file mode 100644 index 00000000..e3434af5 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/os_sem.c @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include <errno.h> +#include <semaphore.h> + +#include "os/os.h" +#include "nimble/nimble_npl.h" + +ble_npl_error_t +ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens) +{ + if (!sem) { + return BLE_NPL_INVALID_PARAM; + } + + sem_init(&sem->lock, 0, tokens); + + return BLE_NPL_OK; +} + +ble_npl_error_t +ble_npl_sem_release(struct ble_npl_sem *sem) +{ + int err; + + if (!sem) { + return BLE_NPL_INVALID_PARAM; + } + + err = sem_post(&sem->lock); + + return (err) ? BLE_NPL_ERROR : BLE_NPL_OK; +} + +ble_npl_error_t +ble_npl_sem_pend(struct ble_npl_sem *sem, uint32_t timeout) +{ + int err = 0; + struct timespec wait; + + if (!sem) { + return BLE_NPL_INVALID_PARAM; + } + + if (timeout == BLE_NPL_TIME_FOREVER) { + err = sem_wait(&sem->lock); + } else { + err = clock_gettime(CLOCK_REALTIME, &wait); + if (err) { + return BLE_NPL_ERROR; + } + + wait.tv_sec += timeout / 1000; + wait.tv_nsec += (timeout % 1000) * 1000000; + + err = sem_timedwait(&sem->lock, &wait); + if (err && errno == ETIMEDOUT) { + return BLE_NPL_TIMEOUT; + } + } + + return (err) ? BLE_NPL_ERROR : BLE_NPL_OK; +} + +uint16_t +ble_npl_sem_get_count(struct ble_npl_sem *sem) +{ + int count; + + assert(sem); + assert(&sem->lock); + sem_getvalue(&sem->lock, &count); + + return count; +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/os_task.c b/src/libs/mynewt-nimble/porting/npl/linux/src/os_task.c new file mode 100644 index 00000000..fe6c2df1 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/os_task.c @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "os/os.h" +#include "nimble/nimble_npl.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Initialize a task. + * + * This function initializes the task structure pointed to by t, + * clearing and setting it's stack pointer, provides sane defaults + * and sets the task as ready to run, and inserts it into the operating + * system scheduler. + * + * @param t The task to initialize + * @param name The name of the task to initialize + * @param func The task function to call + * @param arg The argument to pass to this task function + * @param prio The priority at which to run this task + * @param sanity_itvl The time at which this task should check in with the + * sanity task. OS_WAIT_FOREVER means never check in + * here. + * @param stack_bottom A pointer to the bottom of a task's stack + * @param stack_size The overall size of the task's stack. + * + * @return 0 on success, non-zero on failure. + */ +int +ble_npl_task_init(struct ble_npl_task *t, const char *name, ble_npl_task_func_t func, + void *arg, uint8_t prio, ble_npl_time_t sanity_itvl, + ble_npl_stack_t *stack_bottom, uint16_t stack_size) +{ + int err; + if ((t == NULL) || (func == NULL)) { + return OS_INVALID_PARM; + } + + err = pthread_attr_init(&t->attr); + if (err) return err; + err = pthread_attr_getschedparam (&t->attr, &t->param); + if (err) return err; + err = pthread_attr_setschedpolicy(&t->attr, SCHED_RR); + if (err) return err; + t->param.sched_priority = prio; + err = pthread_attr_setschedparam (&t->attr, &t->param); + if (err) return err; + + t->name = name; + err = pthread_create(&t->handle, &t->attr, func, arg); + + return err; +} + +/* + * Removes specified task + * XXX + * NOTE: This interface is currently experimental and not ready for common use + */ +int +ble_npl_task_remove(struct ble_npl_task *t) +{ + return pthread_cancel(t->handle); +} + +/** + * Return the number of tasks initialized. + * + * @return number of tasks initialized + */ +uint8_t +ble_npl_task_count(void) +{ + return 0; +} + +void * +ble_npl_get_current_task_id(void) +{ + return (void *)pthread_self(); +} + +bool ble_npl_os_started(void) +{ + return true; +} + +void ble_npl_task_yield(void) +{ + pthread_yield(); +} + +#ifdef __cplusplus +} +#endif diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/os_time.c b/src/libs/mynewt-nimble/porting/npl/linux/src/os_time.c new file mode 100644 index 00000000..4625159f --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/os_time.c @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <assert.h> +#include <stdint.h> +#include <string.h> +#include "os/os.h" +#include "nimble/nimble_npl.h" + +#include <unistd.h> +#include <time.h> + +/** + * Return ticks [ms] since system start as uint32_t. + */ +ble_npl_time_t +ble_npl_time_get(void) +{ + struct timespec now; + if (clock_gettime(CLOCK_MONOTONIC, &now)) { + return 0; + } + return now.tv_sec * 1000.0 + now.tv_nsec / 1000000.0; +} + + +ble_npl_error_t ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) +{ + *out_ticks = ms; + + return BLE_NPL_OK; +} + + +ble_npl_error_t ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms) +{ + *out_ms = ticks; + + return BLE_NPL_OK; +} + +ble_npl_time_t ble_npl_time_ms_to_ticks32(uint32_t ms) +{ + return ms; +} + +uint32_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks) +{ + return ticks; +} + +void +ble_npl_time_delay(ble_npl_time_t ticks) +{ + struct timespec sleep_time; + long ms = ble_npl_time_ticks_to_ms32(ticks); + uint32_t s = ms / 1000; + + ms -= s * 1000; + sleep_time.tv_sec = s; + sleep_time.tv_nsec = ms * 1000000; + + nanosleep(&sleep_time, NULL); +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/src/wqueue.h b/src/libs/mynewt-nimble/porting/npl/linux/src/wqueue.h new file mode 100644 index 00000000..1de779e7 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/src/wqueue.h @@ -0,0 +1,91 @@ +/* + wqueue.h + Worker thread queue based on the Standard C++ library list + template class. + ------------------------------------------ + Copyright (c) 2013 Vic Hargrave + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +// https://vichargrave.github.io/articles/2013-01/multithreaded-work-queue-in-cpp +// https://github.com/vichargrave/wqueue/blob/master/wqueue.h + + +#ifndef __wqueue_h__ +#define __wqueue_h__ + +#include <pthread.h> +#include <list> + +using namespace std; + +template <typename T> class wqueue +{ + list<T> m_queue; + pthread_mutex_t m_mutex; + pthread_mutexattr_t m_mutex_attr; + pthread_cond_t m_condv; + +public: + wqueue() + { + pthread_mutexattr_init(&m_mutex_attr); + pthread_mutexattr_settype(&m_mutex_attr, PTHREAD_MUTEX_RECURSIVE); + pthread_mutex_init(&m_mutex, &m_mutex_attr); + pthread_cond_init(&m_condv, NULL); + } + + ~wqueue() { + pthread_mutex_destroy(&m_mutex); + pthread_cond_destroy(&m_condv); + } + + void put(T item) { + pthread_mutex_lock(&m_mutex); + m_queue.push_back(item); + pthread_cond_signal(&m_condv); + pthread_mutex_unlock(&m_mutex); + } + + T get(uint32_t tmo) { + pthread_mutex_lock(&m_mutex); + if (tmo) { + while (m_queue.size() == 0) { + pthread_cond_wait(&m_condv, &m_mutex); + } + } + + T item = NULL; + + if (m_queue.size() != 0) { + item = m_queue.front(); + m_queue.pop_front(); + } + + pthread_mutex_unlock(&m_mutex); + return item; + } + + void remove(T item) { + pthread_mutex_lock(&m_mutex); + m_queue.remove(item); + pthread_mutex_unlock(&m_mutex); + } + + int size() { + pthread_mutex_lock(&m_mutex); + int size = m_queue.size(); + pthread_mutex_unlock(&m_mutex); + return size; + } +}; + +#endif diff --git a/src/libs/mynewt-nimble/porting/npl/linux/test/Makefile b/src/libs/mynewt-nimble/porting/npl/linux/test/Makefile new file mode 100644 index 00000000..c0be3d5f --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/test/Makefile @@ -0,0 +1,120 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# * http://www.apache.org/licenses/LICENSE-2.0 +# * Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Makefile + +PROJ_ROOT = ../../../.. + +### ===== Toolchain ===== + +CROSS_COMPILE ?= +CC = ccache $(CROSS_COMPILE)gcc +CPP = ccache $(CROSS_COMPILE)g++ +LD = $(CROSS_COMPILE)gcc +AR = $(CROSS_COMPILE)ar + +### ===== Compiler Flags ===== + +INCLUDES = \ + -I. \ + -I$(PROJ_ROOT)/nimble/include \ + -I$(PROJ_ROOT)/porting/npl/linux/include \ + -I$(PROJ_ROOT)/porting/npl/linux/src \ + -I$(PROJ_ROOT)/porting/nimble/include \ + $(NULL) + +DEFINES = + +CFLAGS = \ + $(INCLUDES) $(DEFINES) \ + -g \ + -D_GNU_SOURCE \ + $(NULL) + +LIBS = -lrt -lpthread -lstdc++ + +LDFLAGS = + +### ===== Sources ===== + +OSAL_PATH = $(PROJ_ROOT)/porting/npl/linux/src + +SRCS = $(shell find $(OSAL_PATH) -maxdepth 1 -name '*.c') +SRCS += $(shell find $(OSAL_PATH) -maxdepth 1 -name '*.cc') +SRCS += $(PROJ_ROOT)/porting/nimble/src/os_mempool.c + +OBJS = $(patsubst %.c, %.o,$(filter %.c, $(SRCS))) +OBJS += $(patsubst %.cc,%.o,$(filter %.cc, $(SRCS))) + +TEST_SRCS = $(shell find . -maxdepth 1 -name '*.c') +TEST_SRCS += $(shell find . -maxdepth 1 -name '*.cc') + +TEST_OBJS = $(patsubst %.c, %.o,$(filter %.c, $(SRCS))) +TEST_OBJS += $(patsubst %.cc,%.o,$(filter %.cc, $(SRCS))) + +### ===== Rules ===== + +all: depend \ + test_npl_task.exe \ + test_npl_callout.exe \ + test_npl_eventq.exe \ + test_npl_sem.exe \ + $(NULL) + +test_npl_task.exe: test_npl_task.o $(OBJS) + $(LD) -o $@ $^ $(LDFLAGS) $(LIBS) + +test_npl_eventq.exe: test_npl_eventq.o $(OBJS) + $(LD) -o $@ $^ $(LDFLAGS) $(LIBS) + +test_npl_callout.exe: test_npl_callout.o $(OBJS) + $(LD) -o $@ $^ $(LDFLAGS) $(LIBS) + +test_npl_sem.exe: test_npl_sem.o $(OBJS) + $(LD) -o $@ $^ $(LDFLAGS) $(LIBS) + +test: all + ./test_npl_task.exe + ./test_npl_callout.exe + ./test_npl_eventq.exe + ./test_npl_sem.exe + +show_objs: + @echo $(OBJS) + +### ===== Clean ===== +clean: + @echo "Cleaning artifacts." + rm *~ .depend $(OBJS) *.o *.exe + +### ===== Dependencies ===== +### Rebuild if headers change +depend: .depend + +.depend: $(SRCS) $(TEST_SRCS) + @echo "Building dependencies." + rm -f ./.depend + $(CC) $(CFLAGS) -MM $^ > ./.depend; + +include .depend + +### Generic rules based on extension +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + +%.o: %.cc + $(CPP) -c $(CFLAGS) $< -o $@ diff --git a/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_callout.c b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_callout.c new file mode 100644 index 00000000..d04303f8 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_callout.c @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + Unit tests for the ble_npl_callout api: + + void ble_npl_callout_init(struct ble_npl_callout *cf, struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg); + int ble_npl_callout_reset(struct ble_npl_callout *, int32_t); + int ble_npl_callout_queued(struct ble_npl_callout *c); + void ble_npl_callout_stop(struct ble_npl_callout *c); +*/ + +#include "test_util.h" +#include "nimble/nimble_npl.h" + +#define TEST_ARGS_VALUE (55) +#define TEST_INTERVAL (100) + +static bool s_tests_running = true; +static struct ble_npl_task s_task; +static struct ble_npl_callout s_callout; +static int s_callout_args = TEST_ARGS_VALUE; + +static struct ble_npl_eventq s_eventq; + + +void on_callout(struct ble_npl_event *ev) +{ + VerifyOrQuit(ev->ev_arg == &s_callout_args, + "callout: wrong args passed"); + + VerifyOrQuit(*(int*)ev->ev_arg == TEST_ARGS_VALUE, + "callout: args corrupted"); + + s_tests_running = false; +} + +/** + * ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq, + * ble_npl_event_fn *ev_cb, void *ev_arg) + */ +int test_init(void) +{ + ble_npl_callout_init(&s_callout, + &s_eventq, + on_callout, + &s_callout_args); + return PASS; +} + +int test_queued(void) +{ + //VerifyOrQuit(ble_npl_callout_queued(&s_callout), + // "callout: not queued when expected"); + return PASS; +} + +int test_reset(void) +{ + return ble_npl_callout_reset(&s_callout, TEST_INTERVAL); +} + +int test_stop(void) +{ + return PASS; +} + + +/** + * ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq, + * ble_npl_event_fn *ev_cb, void *ev_arg) + */ +void *test_task_run(void *args) +{ + SuccessOrQuit(test_init(), "callout_init failed"); + SuccessOrQuit(test_queued(), "callout_queued failed"); + SuccessOrQuit(test_reset(), "callout_reset failed"); + + while (s_tests_running) + { + ble_npl_eventq_run(&s_eventq); + } + + printf("All tests passed\n"); + exit(PASS); + + return NULL; +} + +int main(void) +{ + ble_npl_eventq_init(&s_eventq); + + SuccessOrQuit(ble_npl_task_init(&s_task, "s_task", test_task_run, + NULL, 1, 0, NULL, 0), + "task: error initializing"); + + while (1) {} +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_eventq.c b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_eventq.c new file mode 100644 index 00000000..f0c362b9 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_eventq.c @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + Unit tests for the ble_npl_eventq api: + + void ble_npl_eventq_init(struct ble_npl_eventq *); + void ble_npl_eventq_put(struct ble_npl_eventq *, struct ble_npl_event *); + struct ble_npl_event *ble_npl_eventq_get_no_wait(struct ble_npl_eventq *evq); + struct ble_npl_event *ble_npl_eventq_get(struct ble_npl_eventq *); + void ble_npl_eventq_run(struct ble_npl_eventq *evq); + struct ble_npl_event *ble_npl_eventq_poll(struct ble_npl_eventq **, int, ble_npl_time_t); + void ble_npl_eventq_remove(struct ble_npl_eventq *, struct ble_npl_event *); + struct ble_npl_eventq *ble_npl_eventq_dflt_get(void); +*/ + +#include <assert.h> +#include <pthread.h> +#include "test_util.h" +#include "nimble/nimble_npl.h" + +#define TEST_ARGS_VALUE (55) +#define TEST_STACK_SIZE (1024) + +static bool s_tests_running = true; +static struct ble_npl_task s_task_runner; +static struct ble_npl_task s_task_dispatcher; + +static struct ble_npl_eventq s_eventq; +static struct ble_npl_event s_event; +static int s_event_args = TEST_ARGS_VALUE; + + +void on_event(struct ble_npl_event *ev) +{ + VerifyOrQuit(ev->ev_arg == &s_event_args, + "callout: wrong args passed"); + + VerifyOrQuit(*(int*)ev->ev_arg == TEST_ARGS_VALUE, + "callout: args corrupted"); + + s_tests_running = false; +} + +int test_init(void) +{ + //VerifyOrQuit(!ble_npl_eventq_inited(&s_eventq), "eventq: empty q initialized"); + ble_npl_eventq_init(&s_eventq); + //VerifyOrQuit(ble_npl_eventq_inited(&s_eventq), "eventq: not initialized"); + + return PASS; +} + +int test_run(void) +{ + while (s_tests_running) + { + ble_npl_eventq_run(&s_eventq); + } + + return PASS; +} + +int test_put(void) +{ + s_event.ev_cb = on_event; + s_event.ev_arg = &s_event_args; + ble_npl_eventq_put(&s_eventq, &s_event); + return PASS; +} + +int test_get_no_wait(void) +{ + //struct ble_npl_event *ev = ble_npl_eventq_get_no_wait(&s_eventq); + return FAIL; +} + +int test_get(void) +{ + struct ble_npl_event *ev = ble_npl_eventq_get(&s_eventq, + BLE_NPL_TIME_FOREVER); + + VerifyOrQuit(ev == &s_event, + "callout: wrong event passed"); + + return PASS; +} + + +void *task_test_runner(void *args) +{ + int count = 1000000000; + + SuccessOrQuit(test_init(), "eventq_init failed"); + SuccessOrQuit(test_put(), "eventq_put failed"); + SuccessOrQuit(test_get(), "eventq_get failed"); + SuccessOrQuit(test_put(), "eventq_put failed"); + SuccessOrQuit(test_run(), "eventq_run failed"); + + printf("All tests passed\n"); + exit(PASS); + + return NULL; +} + +int main(void) +{ + SuccessOrQuit(ble_npl_task_init(&s_task_runner, + "task_test_runner", + task_test_runner, + NULL, 1, 0, NULL, 0), + "task: error initializing"); + + while (1) {} +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_mempool.c b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_mempool.c new file mode 100644 index 00000000..2dac0bb1 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_mempool.c @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "test_util.h" +#include "nimble/nimble_npl.h" + +#define TEST_MEMPOOL_BLOCKS 4 +#define TEST_MEMPOOL_BLOCK_SIZE 128 + +static struct ble_npl_mempool s_mempool; + +static os_membuf_t s_mempool_mem[OS_MEMPOOL_SIZE(TEST_MEMPOOL_BLOCKS, + TEST_MEMPOOL_BLOCK_SIZE)]; + +static void *s_memblock[TEST_MEMPOOL_BLOCKS]; + +/** + * Unit test for initializing a mempool. + * + * ble_npl_error_t ble_npl_mempool_init(struct ble_npl_mempool *mp, int blocks, + * int block_size, void *membuf, char *name); + * + */ +int test_init(void) +{ + int err; + err = ble_npl_mempool_init(NULL, + TEST_MEMPOOL_BLOCKS, + TEST_MEMPOOL_BLOCK_SIZE, + NULL, + "Null mempool"); + VerifyOrQuit(err, "ble_npl_mempool_init accepted NULL parameters."); + + err = ble_npl_mempool_init(&s_mempool, + TEST_MEMPOOL_BLOCKS, + TEST_MEMPOOL_BLOCK_SIZE, + s_mempool_mem, + "s_mempool"); + return err; +} + +/** + * Test integrity check of a mempool. + * + * bool ble_npl_mempool_is_sane(const struct ble_npl_mempool *mp); + */ +int test_is_sane(void) +{ + return (ble_npl_mempool_is_sane(&s_mempool)) ? PASS : FAIL; +} + +/** + * Test getting a memory block from the pool, putting it back, + * and checking if it is still valid. + * + * void *ble_npl_memblock_get(struct ble_npl_mempool *mp); + * + * ble_npl_error_t ble_npl_memblock_put(struct ble_npl_mempool *mp, void *block_addr); + * + * int ble_npl_memblock_from(const struct ble_npl_mempool *mp, const void *block_addr); + */ +int test_stress(void) +{ + int loops = 3; + while(loops--) + { + for (int i = 0; i < 4; i++) + { + s_memblock[i] = ble_npl_memblock_get(&s_mempool); + VerifyOrQuit(ble_npl_memblock_from(&s_mempool, s_memblock[i]), + "ble_npl_memblock_get return invalid block."); + } + + + for (int i = 0; i < 4; i++) + { + SuccessOrQuit(ble_npl_memblock_put(&s_mempool, s_memblock[i]), + "ble_npl_memblock_put refused to take valid block."); + //VerifyOrQuit(!ble_npl_memblock_from(&s_mempool, s_memblock[i]), + // "Block still valid after ble_npl_memblock_put."); + } + + } + return PASS; +} + +int main(void) +{ + SuccessOrQuit(test_init(), "Failed: ble_npl_mempool_init"); + SuccessOrQuit(test_is_sane(), "Failed: ble_npl_mempool_is_sane"); + SuccessOrQuit(test_stress(), "Failed: ble_npl_mempool stree test"); + SuccessOrQuit(test_is_sane(), "Failed: ble_npl_mempool_is_sane"); + printf("All tests passed\n"); + return PASS; +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_sem.c b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_sem.c new file mode 100644 index 00000000..b62f8e2a --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_sem.c @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + Unit tests for the Semaphore api (ble_npl_sem): + + ble_npl_error_t ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens); + ble_npl_error_t ble_npl_sem_release(struct ble_npl_sem *sem); + ble_npl_error_t ble_npl_sem_pend(struct ble_npl_sem *sem, uint32_t timeout); + uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem); +*/ + +#include "test_util.h" +#include "nimble/nimble_npl.h" +//#include "os/os.h" + +#define TEST_ITERATIONS 10 + +#define TASK1_PRIO 1 +#define TASK2_PRIO 1 + +#define TASK1_STACK_SIZE 1028 +#define TASK2_STACK_SIZE 1028 + +static struct ble_npl_task task1; +static struct ble_npl_task task2; + +static ble_npl_stack_t task1_stack[TASK1_STACK_SIZE]; +static ble_npl_stack_t task2_stack[TASK2_STACK_SIZE]; + +struct ble_npl_sem task1_sem; +struct ble_npl_sem task2_sem; + +/* Task 1 handler function */ +void * +task1_handler(void *arg) +{ + for (int i = 0; i < TEST_ITERATIONS; i++) + { + /* Release semaphore to task 2 */ + SuccessOrQuit(ble_npl_sem_release(&task1_sem), + "ble_npl_sem_release: error releasing task2_sem."); + + /* Wait for semaphore from task 2 */ + SuccessOrQuit(ble_npl_sem_pend(&task2_sem, BLE_NPL_TIME_FOREVER), + "ble_npl_sem_pend: error waiting for task2_sem."); + } + + printf("All tests passed\n"); + exit(PASS); + + return NULL; +} + +/* Task 2 handler function */ +void * +task2_handler(void *arg) +{ + while(1) + { + /* Wait for semaphore from task1 */ + SuccessOrQuit(ble_npl_sem_pend(&task1_sem, BLE_NPL_TIME_FOREVER), + "ble_npl_sem_pend: error waiting for task1_sem."); + + /* Release task2 semaphore */ + SuccessOrQuit(ble_npl_sem_release(&task2_sem), + "ble_npl_sem_release: error releasing task1_sem."); + } + + return NULL; +} + + +/* Initialize task 1 exposed data objects */ +void +task1_init(void) +{ + /* Initialize task1 semaphore */ + SuccessOrQuit(ble_npl_sem_init(&task1_sem, 0), + "ble_npl_sem_init: task1 returned error."); +} + +/* Initialize task 2 exposed data objects */ +void +task2_init(void) +{ + /* Initialize task1 semaphore */ + SuccessOrQuit(ble_npl_sem_init(&task2_sem, 0), + "ble_npl_sem_init: task2 returned error."); +} + +/** + * init_app_tasks + * + * This function performs initializations that are required before tasks run. + * + * @return int 0 success; error otherwise. + */ +static int +init_app_tasks(void) +{ + /* + * Call task specific initialization functions to initialize any shared objects + * before initializing the tasks with the OS. + */ + task1_init(); + task2_init(); + + /* + * Initialize tasks 1 and 2 with the OS. + */ + ble_npl_task_init(&task1, "task1", task1_handler, NULL, TASK1_PRIO, + BLE_NPL_TIME_FOREVER, task1_stack, TASK1_STACK_SIZE); + + ble_npl_task_init(&task2, "task2", task2_handler, NULL, TASK2_PRIO, + BLE_NPL_TIME_FOREVER, task2_stack, TASK2_STACK_SIZE); + + return 0; +} + +/** + * main + * + * The main function for the application. This function initializes the system and packages, + * calls the application specific task initialization function, then waits and dispatches + * events from the OS default event queue in an infinite loop. + */ +int +main(int argc, char **arg) +{ + /* Initialize application specific tasks */ + init_app_tasks(); + + while (1) + { + ble_npl_eventq_run(ble_npl_eventq_dflt_get()); + } + /* main never returns */ +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_task.c b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_task.c new file mode 100644 index 00000000..66310cd7 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/test/test_npl_task.c @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "test_util.h" +#include "nimble/nimble_npl.h" + +#include <pthread.h> + +#define TASK0_ARG 55 +#define TASK1_ARG 66 + +static struct ble_npl_task s_task[2]; +static int s_task_arg[2] = +{ + TASK0_ARG, TASK1_ARG +}; + + +void *task0_run(void *args) +{ + int i = 10000; + VerifyOrQuit(args == &s_task_arg[0], "Wrong args passed to task0"); + + while (i--) + { + } + + return NULL; +} + +void *task1_run(void *args) +{ + int i = 10000; + VerifyOrQuit(args == &s_task_arg[1], "Wrong args passed to task0"); + + while (i--) + { + } + + printf("All tests passed\n"); + exit(PASS); + + return NULL; +} + +/** + * Unit test for initializing a task. + * + * int ble_npl_task_init(struct ble_npl_task *t, const char *name, ble_npl_task_func_t func, + * void *arg, uint8_t prio, ble_npl_time_t sanity_itvl, + * ble_npl_stack_t *stack_bottom, uint16_t stack_size) + * + */ +int test_init(void) +{ + int err; + err = ble_npl_task_init(NULL, + "Null task", + NULL, NULL, 1, 0, NULL, 0); + VerifyOrQuit(err, "ble_npl_task_init accepted NULL parameters."); + + err = ble_npl_task_init(&s_task[0], + "s_task[0]", + task0_run, &s_task_arg[0], 1, 0, NULL, 0); + SuccessOrQuit(err, "ble_npl_task_init failed."); + + err = ble_npl_task_init(&s_task[1], + "s_task[1]", + task1_run, &s_task_arg[1], 1, 0, NULL, 0); + + return err; +} + +int main(void) +{ + int ret = PASS; + SuccessOrQuit(test_init(), "Failed: ble_npl_task_init"); + + pthread_exit(&ret); + + return ret; +} diff --git a/src/libs/mynewt-nimble/porting/npl/linux/test/test_util.h b/src/libs/mynewt-nimble/porting/npl/linux/test/test_util.h new file mode 100644 index 00000000..90985c3f --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/linux/test/test_util.h @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _TEST_UTIL_H_ +#define _TEST_UTIL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdio.h> +#include <stdlib.h> + +#define PASS (0) +#define FAIL (-1) + +#define SuccessOrQuit(ERR, MSG) \ + do { \ + if ((ERR)) \ + { \ + fprintf(stderr, "\nFAILED %s:%d - %s\n", __FUNCTION__, __LINE__, MSG); \ + exit(-1); \ + } \ + } while (false) + +#define VerifyOrQuit(TST, MSG) \ + do { \ + if (!(TST)) \ + { \ + fprintf(stderr, "\nFAILED %s:%d - %s\n", __FUNCTION__, __LINE__, MSG); \ + exit(-1); \ + } \ + } while (false) + + +#ifdef __cplusplus +} +#endif + +#endif /* _TEST_UTIL_H_ */ diff --git a/src/libs/mynewt-nimble/porting/npl/mynewt/include/nimble/nimble_npl_os.h b/src/libs/mynewt-nimble/porting/npl/mynewt/include/nimble/nimble_npl_os.h new file mode 100644 index 00000000..8d8ccda3 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/mynewt/include/nimble/nimble_npl_os.h @@ -0,0 +1,293 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_NPL_OS_H_ +#define _NIMBLE_NPL_OS_H_ + +#include <stdint.h> +#include <string.h> +#include <assert.h> +#include "os/os.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BLE_NPL_TIME_FOREVER (OS_TIMEOUT_NEVER) + +typedef os_time_t ble_npl_time_t; +typedef os_stime_t ble_npl_stime_t; + +/* + * This allows to cast between ble_npl_* and os_* structs to make NPL for Mynewt + * just a shim layer on top of kernel/os. + */ + +struct ble_npl_event { + struct os_event ev; +}; + +struct ble_npl_eventq { + struct os_eventq evq; +}; + +struct ble_npl_callout { + struct os_callout co; +}; + +struct ble_npl_mutex { + struct os_mutex mu; +}; + +struct ble_npl_sem { + struct os_sem sem; +}; + +static inline bool +ble_npl_os_started(void) +{ + return os_started(); +} + +static inline void * +ble_npl_get_current_task_id(void) +{ + return os_sched_get_current_task(); +} + +static inline struct ble_npl_eventq * +ble_npl_eventq_dflt_get(void) +{ + return (struct ble_npl_eventq *) os_eventq_dflt_get(); +} + +static inline void +ble_npl_eventq_init(struct ble_npl_eventq *evq) +{ + os_eventq_init(&evq->evq); +} + +static inline struct ble_npl_event * +ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo) +{ + struct os_event *ev; + + if (tmo == BLE_NPL_TIME_FOREVER) { + ev = os_eventq_get(&evq->evq); + } else { + ev = os_eventq_poll((struct os_eventq **)&evq, 1, tmo); + } + + return (struct ble_npl_event *)ev; +} + +static inline void +ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + os_eventq_put(&evq->evq, &ev->ev); +} + +static inline void +ble_npl_eventq_remove(struct ble_npl_eventq *evq, + struct ble_npl_event *ev) +{ + os_eventq_remove(&evq->evq, &ev->ev); +} + +static inline void +ble_npl_event_run(struct ble_npl_event *ev) +{ + ev->ev.ev_cb(&ev->ev); +} + +static inline bool +ble_npl_eventq_is_empty(struct ble_npl_eventq *evq) +{ + return STAILQ_EMPTY(&evq->evq.evq_list); +} + +static inline void +ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, + void *arg) +{ + memset(ev, 0, sizeof(*ev)); + ev->ev.ev_queued = 0; + ev->ev.ev_cb = (os_event_fn *)fn; + ev->ev.ev_arg = arg; +} + +static inline bool +ble_npl_event_is_queued(struct ble_npl_event *ev) +{ + return ev->ev.ev_queued; +} + +static inline void * +ble_npl_event_get_arg(struct ble_npl_event *ev) +{ + return ev->ev.ev_arg; +} + +static inline void +ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) +{ + assert(ev->ev.ev_queued == 0); + ev->ev.ev_arg = arg; +} + +static inline ble_npl_error_t +ble_npl_mutex_init(struct ble_npl_mutex *mu) +{ + return (ble_npl_error_t)os_mutex_init(&mu->mu); +} + +static inline ble_npl_error_t +ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) +{ + return (ble_npl_error_t)os_mutex_pend(&mu->mu, timeout); +} + +static inline ble_npl_error_t +ble_npl_mutex_release(struct ble_npl_mutex *mu) +{ + return (ble_npl_error_t)os_mutex_release(&mu->mu); +} + +static inline ble_npl_error_t +ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens) +{ + return (ble_npl_error_t)os_sem_init(&sem->sem, tokens); +} + +static inline ble_npl_error_t +ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout) +{ + return (ble_npl_error_t)os_sem_pend(&sem->sem, timeout); +} + +static inline ble_npl_error_t +ble_npl_sem_release(struct ble_npl_sem *sem) +{ + return (ble_npl_error_t)os_sem_release(&sem->sem); +} + +static inline uint16_t +ble_npl_sem_get_count(struct ble_npl_sem *sem) +{ + return os_sem_get_count(&sem->sem); +} + +static inline void +ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg) +{ + os_callout_init(&co->co, &evq->evq, (os_event_fn *)ev_cb, ev_arg); +} + +static inline ble_npl_error_t +ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks) +{ + return (ble_npl_error_t)os_callout_reset(&co->co, ticks); +} + +static inline void +ble_npl_callout_stop(struct ble_npl_callout *co) +{ + os_callout_stop(&co->co); +} + +static inline bool +ble_npl_callout_is_active(struct ble_npl_callout *co) +{ + return os_callout_queued(&co->co); +} + +static inline ble_npl_time_t +ble_npl_callout_get_ticks(struct ble_npl_callout *co) +{ + return co->co.c_ticks; +} + +static inline ble_npl_time_t +ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t time) +{ + return os_callout_remaining_ticks(&co->co, time); +} + +static inline void +ble_npl_callout_set_arg(struct ble_npl_callout *co, + void *arg) +{ + co->co.c_ev.ev_arg = arg; +} + +static inline uint32_t +ble_npl_time_get(void) +{ + return os_time_get(); +} + +static inline ble_npl_error_t +ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) +{ + return (ble_npl_error_t)os_time_ms_to_ticks(ms, out_ticks); +} + +static inline ble_npl_error_t +ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms) +{ + return os_time_ticks_to_ms(ticks, out_ms); +} + +static inline ble_npl_time_t +ble_npl_time_ms_to_ticks32(uint32_t ms) +{ + return os_time_ms_to_ticks32(ms); +} + +static inline uint32_t +ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks) +{ + return os_time_ticks_to_ms32(ticks); +} + +static inline void +ble_npl_time_delay(ble_npl_time_t ticks) +{ + return os_time_delay(ticks); +} + +static inline uint32_t +ble_npl_hw_enter_critical(void) +{ + return os_arch_save_sr(); +} + +static inline void +ble_npl_hw_exit_critical(uint32_t ctx) +{ + os_arch_restore_sr(ctx); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _NPL_H_ */ diff --git a/src/libs/mynewt-nimble/porting/npl/mynewt/pkg.yml b/src/libs/mynewt-nimble/porting/npl/mynewt/pkg.yml new file mode 100644 index 00000000..b6a790f0 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/mynewt/pkg.yml @@ -0,0 +1,27 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: porting/npl/mynewt +pkg.description: NimBLE porting layer for Apache Mynewt +pkg.author: "Apache Mynewt <dev@mynewt.incubator.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +pkg.deps: + - "@apache-mynewt-core/kernel/os" diff --git a/src/libs/mynewt-nimble/porting/npl/riot/include/logcfg/logcfg.h b/src/libs/mynewt-nimble/porting/npl/riot/include/logcfg/logcfg.h new file mode 100644 index 00000000..e21a3ae5 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/riot/include/logcfg/logcfg.h @@ -0,0 +1,32 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_LOGCFG_ +#define H_MYNEWT_LOGCFG_ + +#include "modlog/modlog.h" +#include "log_common/log_common.h" + +#define BLE_HS_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define BLE_HS_LOG_INFO(...) MODLOG_INFO(4, __VA_ARGS__) +#define BLE_HS_LOG_WARN(...) MODLOG_WARN(4, __VA_ARGS__) +#define BLE_HS_LOG_ERROR(...) MODLOG_ERROR(4, __VA_ARGS__) +#define BLE_HS_LOG_CRITICAL(...) MODLOG_CRITICAL(4, __VA_ARGS__) +#define BLE_HS_LOG_DISABLED(...) MODLOG_DISABLED(4, __VA_ARGS__) + +#define DFLT_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define DFLT_LOG_INFO(...) MODLOG_INFO(0, __VA_ARGS__) +#define DFLT_LOG_WARN(...) MODLOG_WARN(0, __VA_ARGS__) +#define DFLT_LOG_ERROR(...) MODLOG_ERROR(0, __VA_ARGS__) +#define DFLT_LOG_CRITICAL(...) MODLOG_CRITICAL(0, __VA_ARGS__) +#define DFLT_LOG_DISABLED(...) MODLOG_DISABLED(0, __VA_ARGS__) + +#define MFG_LOG_DEBUG(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_INFO(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_WARN(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_ERROR(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_CRITICAL(...) IGNORE(__VA_ARGS__) +#define MFG_LOG_DISABLED(...) MODLOG_DISABLED(128, __VA_ARGS__) + +#endif diff --git a/src/libs/mynewt-nimble/porting/npl/riot/include/nimble/nimble_npl_os.h b/src/libs/mynewt-nimble/porting/npl/riot/include/nimble/nimble_npl_os.h new file mode 100644 index 00000000..854fd06c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/riot/include/nimble/nimble_npl_os.h @@ -0,0 +1,296 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef _NIMBLE_NPL_OS_H_ +#define _NIMBLE_NPL_OS_H_ + +#include <stdint.h> +#include <stdbool.h> +#include "event/callback.h" +#include "mutex.h" +#include "semaphore.h" +#include "xtimer.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BLE_NPL_OS_ALIGNMENT 4 + +#define BLE_NPL_TIME_FOREVER UINT32_MAX + +typedef uint32_t ble_npl_time_t; +typedef int32_t ble_npl_stime_t; + +extern volatile int ble_npl_in_critical; + +struct ble_npl_event { + event_callback_t e; + void *arg; +}; + +struct ble_npl_eventq { + event_queue_t q; +}; + +struct ble_npl_callout { + xtimer_t timer; + uint64_t target_us; + struct ble_npl_event e; + event_queue_t *q; +}; + +struct ble_npl_mutex { + mutex_t mu; +}; + +struct ble_npl_sem { + sem_t sem; +}; + +static inline bool +ble_npl_os_started(void) +{ + return true; +} + +static inline void * +ble_npl_get_current_task_id(void) +{ + return (void *)(uint32_t)thread_getpid(); +} + +static inline void +ble_npl_eventq_init(struct ble_npl_eventq *evq) +{ + event_queue_init_detached(&evq->q); +} + +static inline void +ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + event_post(&evq->q, &ev->e.super); +} + +static inline struct ble_npl_event * +ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo) +{ + if (evq->q.waiter == NULL) { + event_queue_claim(&evq->q); + } + + if (tmo == 0) { + return (struct ble_npl_event *)event_get(&evq->q); + } else if (tmo == BLE_NPL_TIME_FOREVER) { + return (struct ble_npl_event *)event_wait(&evq->q); + } else { + return (struct ble_npl_event *)event_wait_timeout64(&evq->q, + tmo * US_PER_MS); + } +} + +static inline void +ble_npl_eventq_remove(struct ble_npl_eventq *evq, struct ble_npl_event *ev) +{ + event_cancel(&evq->q, &ev->e.super); +} + +static inline void +ble_npl_event_run(struct ble_npl_event *ev) +{ + ev->e.super.handler(&ev->e.super); +} + +static inline void +ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, void *arg) +{ + /* + * Need to clear list_node manually since init function below does not do + * this. + */ + ev->e.super.list_node.next = NULL; + event_callback_init(&ev->e, (void(*)(void *))fn, ev); + ev->arg = arg; +} + +static inline bool +ble_npl_event_is_queued(struct ble_npl_event *ev) +{ + return (ev->e.super.list_node.next != NULL); +} + +static inline void * +ble_npl_event_get_arg(struct ble_npl_event *ev) +{ + return ev->arg; +} + +static inline void +ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) +{ + ev->arg = arg; +} + +static inline ble_npl_error_t +ble_npl_mutex_init(struct ble_npl_mutex *mu) +{ + mutex_init(&mu->mu); + return BLE_NPL_OK; +} + +static inline ble_npl_error_t +ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) +{ + assert(timeout == BLE_NPL_TIME_FOREVER); + (void)timeout; + + mutex_lock(&mu->mu); + return BLE_NPL_OK; +} + +static inline ble_npl_error_t +ble_npl_mutex_release(struct ble_npl_mutex *mu) +{ + mutex_unlock(&mu->mu); + return BLE_NPL_OK; +} + +static inline ble_npl_error_t +ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens) +{ + int rc; + + rc = sem_init(&sem->sem, 0, tokens); + + return rc == 0 ? BLE_NPL_OK : BLE_NPL_ERROR; +} + +static inline ble_npl_error_t +ble_npl_sem_release(struct ble_npl_sem *sem) +{ + int rc; + + rc = sem_post(&sem->sem); + + return rc == 0 ? BLE_NPL_OK : BLE_NPL_ERROR; +} + +static inline uint16_t +ble_npl_sem_get_count(struct ble_npl_sem *sem) +{ + int val = 0; + + sem_getvalue(&sem->sem, &val); + + return (uint16_t)val; +} + +static inline void +ble_npl_callout_stop(struct ble_npl_callout *co) +{ + xtimer_remove(&co->timer); +} + +static inline bool +ble_npl_callout_is_active(struct ble_npl_callout *c) +{ + return (c->timer.offset || c->timer.long_offset); +} + +static inline ble_npl_time_t +ble_npl_callout_get_ticks(struct ble_npl_callout *co) +{ + return (ble_npl_time_t)(co->target_us / US_PER_MS); +} + +static inline void +ble_npl_callout_set_arg(struct ble_npl_callout *co, void *arg) +{ + co->e.arg = arg; +} + +static inline ble_npl_time_t +ble_npl_time_get(void) +{ + return (ble_npl_time_t)(xtimer_now_usec64() / US_PER_MS); +} + +static inline ble_npl_error_t +ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) +{ + *out_ticks = ms; + return BLE_NPL_OK; +} + +static inline ble_npl_error_t +ble_npl_time_ticks_to_ms(ble_npl_time_t ticks, uint32_t *out_ms) +{ + *out_ms = ticks; + return BLE_NPL_OK; +} + +static inline ble_npl_time_t +ble_npl_time_ms_to_ticks32(uint32_t ms) +{ + return ms; +} + +static inline uint32_t +ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks) +{ + return ticks; +} + +static inline void +ble_npl_time_delay(ble_npl_time_t ticks) +{ + xtimer_usleep64(ticks * US_PER_MS); +} + +static inline uint32_t +ble_npl_hw_enter_critical(void) +{ + uint32_t ctx = irq_disable(); + ++ble_npl_in_critical; + return ctx; +} + +static inline void +ble_npl_hw_exit_critical(uint32_t ctx) +{ + --ble_npl_in_critical; + irq_restore((unsigned)ctx); +} + +static inline bool +ble_npl_hw_is_in_critical(void) +{ + /* + * XXX Currently RIOT does not support an API for finding out if interrupts + * are currently disabled, hence in a critical section in this context. + * So for now, we use this global variable to keep this state for us. + -*/ + return (ble_npl_in_critical > 0); +} + +#ifdef __cplusplus +} +#endif + +#endif /* _NPL_H_ */ diff --git a/src/libs/mynewt-nimble/porting/npl/riot/include/syscfg/syscfg.h b/src/libs/mynewt-nimble/porting/npl/riot/include/syscfg/syscfg.h new file mode 100644 index 00000000..e78ebe0a --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/riot/include/syscfg/syscfg.h @@ -0,0 +1,1535 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSCFG_ +#define H_MYNEWT_SYSCFG_ + +/** + * This macro exists to ensure code includes this header when needed. If code + * checks the existence of a setting directly via ifdef without including this + * header, the setting macro will silently evaluate to 0. In contrast, an + * attempt to use these macros without including this header will result in a + * compiler error. + */ +#define MYNEWT_VAL(_name) MYNEWT_VAL_ ## _name +#define MYNEWT_VAL_CHOICE(_name, _val) MYNEWT_VAL_ ## _name ## __ ## _val + + + +/*** @apache-mynewt-core/compiler/arm-none-eabi-m4 */ +#ifndef MYNEWT_VAL_HARDFLOAT +#define MYNEWT_VAL_HARDFLOAT (0) +#endif + +/*** @apache-mynewt-core/hw/bsp/nordic_pca10056 */ +#ifndef MYNEWT_VAL_BSP_NRF52840 +#define MYNEWT_VAL_BSP_NRF52840 (1) +#endif + +#ifndef MYNEWT_VAL_SOFT_PWM +#define MYNEWT_VAL_SOFT_PWM (0) +#endif + +/*** @apache-mynewt-core/hw/hal */ +#ifndef MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS +#define MYNEWT_VAL_HAL_ENABLE_SOFTWARE_BREAKPOINTS (1) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ +#define MYNEWT_VAL_HAL_FLASH_VERIFY_BUF_SZ (16) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_ERASES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES +#define MYNEWT_VAL_HAL_FLASH_VERIFY_WRITES (0) +#endif + +#ifndef MYNEWT_VAL_HAL_SYSTEM_RESET_CB +#define MYNEWT_VAL_HAL_SYSTEM_RESET_CB (0) +#endif + +/*** @apache-mynewt-core/hw/mcu/nordic/nrf52xxx */ +#ifndef MYNEWT_VAL_ADC_0 +#define MYNEWT_VAL_ADC_0 (0) +#endif + +#ifndef MYNEWT_VAL_ADC_0_REFMV_0 +#define MYNEWT_VAL_ADC_0_REFMV_0 (0) +#endif + +#ifndef MYNEWT_VAL_CRYPTO +#define MYNEWT_VAL_CRYPTO (0) +#endif + +#ifndef MYNEWT_VAL_GPIO_AS_PIN_RESET +#define MYNEWT_VAL_GPIO_AS_PIN_RESET (0) +#endif + +#ifndef MYNEWT_VAL_I2C_0 +#define MYNEWT_VAL_I2C_0 (0) +#endif + +#ifndef MYNEWT_VAL_I2C_0_FREQ_KHZ +#define MYNEWT_VAL_I2C_0_FREQ_KHZ (100) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_I2C_0_PIN_SCL +#define MYNEWT_VAL_I2C_0_PIN_SCL (27) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_I2C_0_PIN_SDA +#define MYNEWT_VAL_I2C_0_PIN_SDA (26) +#endif + +#ifndef MYNEWT_VAL_I2C_1 +#define MYNEWT_VAL_I2C_1 (0) +#endif + +#ifndef MYNEWT_VAL_I2C_1_FREQ_KHZ +#define MYNEWT_VAL_I2C_1_FREQ_KHZ (100) +#endif + +#undef MYNEWT_VAL_I2C_1_PIN_SCL + +#undef MYNEWT_VAL_I2C_1_PIN_SDA + +#ifndef MYNEWT_VAL_MCU_BUS_DRIVER_I2C_USE_TWIM +#define MYNEWT_VAL_MCU_BUS_DRIVER_I2C_USE_TWIM (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_MCU_DCDC_ENABLED +#define MYNEWT_VAL_MCU_DCDC_ENABLED (1) +#endif + +#ifndef MYNEWT_VAL_MCU_DEBUG_IGNORE_BKPT +#define MYNEWT_VAL_MCU_DEBUG_IGNORE_BKPT (0) +#endif + +#ifndef MYNEWT_VAL_MCU_FLASH_MIN_WRITE_SIZE +#define MYNEWT_VAL_MCU_FLASH_MIN_WRITE_SIZE (1) +#endif + +#ifndef MYNEWT_VAL_MCU_GPIO_USE_PORT_EVENT +#define MYNEWT_VAL_MCU_GPIO_USE_PORT_EVENT (0) +#endif + +#ifndef MYNEWT_VAL_MCU_I2C_RECOVERY_DELAY_USEC +#define MYNEWT_VAL_MCU_I2C_RECOVERY_DELAY_USEC (100) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__LFRC +#define MYNEWT_VAL_MCU_LFCLK_SOURCE__LFRC (0) +#endif +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__LFSYNTH +#define MYNEWT_VAL_MCU_LFCLK_SOURCE__LFSYNTH (0) +#endif +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE__LFXO +#define MYNEWT_VAL_MCU_LFCLK_SOURCE__LFXO (1) +#endif +#ifndef MYNEWT_VAL_MCU_LFCLK_SOURCE +#define MYNEWT_VAL_MCU_LFCLK_SOURCE (1) +#endif + +#ifndef MYNEWT_VAL_MCU_NRF52832 +#define MYNEWT_VAL_MCU_NRF52832 (0) +#endif + +#ifndef MYNEWT_VAL_MCU_NRF52840 +#define MYNEWT_VAL_MCU_NRF52840 (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52810 +#define MYNEWT_VAL_MCU_TARGET__nRF52810 (0) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52811 +#define MYNEWT_VAL_MCU_TARGET__nRF52811 (0) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52832 +#define MYNEWT_VAL_MCU_TARGET__nRF52832 (0) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET__nRF52840 +#define MYNEWT_VAL_MCU_TARGET__nRF52840 (1) +#endif +#ifndef MYNEWT_VAL_MCU_TARGET +#define MYNEWT_VAL_MCU_TARGET (1) +#endif + +#ifndef MYNEWT_VAL_NFC_PINS_AS_GPIO +#define MYNEWT_VAL_NFC_PINS_AS_GPIO (1) +#endif + +#ifndef MYNEWT_VAL_PWM_0 +#define MYNEWT_VAL_PWM_0 (0) +#endif + +#ifndef MYNEWT_VAL_PWM_1 +#define MYNEWT_VAL_PWM_1 (0) +#endif + +#ifndef MYNEWT_VAL_PWM_2 +#define MYNEWT_VAL_PWM_2 (0) +#endif + +#ifndef MYNEWT_VAL_PWM_3 +#define MYNEWT_VAL_PWM_3 (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_ADDRMODE +#define MYNEWT_VAL_QSPI_ADDRMODE (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_DPMCONFIG +#define MYNEWT_VAL_QSPI_DPMCONFIG (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_ENABLE +#define MYNEWT_VAL_QSPI_ENABLE (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_FLASH_PAGE_SIZE +#define MYNEWT_VAL_QSPI_FLASH_PAGE_SIZE (256) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_FLASH_SECTOR_COUNT +#define MYNEWT_VAL_QSPI_FLASH_SECTOR_COUNT (4096) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_FLASH_SECTOR_SIZE +#define MYNEWT_VAL_QSPI_FLASH_SECTOR_SIZE (4096) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_CS +#define MYNEWT_VAL_QSPI_PIN_CS (17) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO0 +#define MYNEWT_VAL_QSPI_PIN_DIO0 (20) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO1 +#define MYNEWT_VAL_QSPI_PIN_DIO1 (21) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO2 +#define MYNEWT_VAL_QSPI_PIN_DIO2 (22) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_DIO3 +#define MYNEWT_VAL_QSPI_PIN_DIO3 (23) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_QSPI_PIN_SCK +#define MYNEWT_VAL_QSPI_PIN_SCK (19) +#endif + +#ifndef MYNEWT_VAL_QSPI_READOC +#define MYNEWT_VAL_QSPI_READOC (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_SCK_DELAY +#define MYNEWT_VAL_QSPI_SCK_DELAY (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_SCK_FREQ +#define MYNEWT_VAL_QSPI_SCK_FREQ (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_SPI_MODE +#define MYNEWT_VAL_QSPI_SPI_MODE (0) +#endif + +#ifndef MYNEWT_VAL_QSPI_WRITEOC +#define MYNEWT_VAL_QSPI_WRITEOC (0) +#endif + +#ifndef MYNEWT_VAL_SPI_0_MASTER +#define MYNEWT_VAL_SPI_0_MASTER (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_MASTER_PIN_MISO +#define MYNEWT_VAL_SPI_0_MASTER_PIN_MISO (47) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_MASTER_PIN_MOSI +#define MYNEWT_VAL_SPI_0_MASTER_PIN_MOSI (46) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_MASTER_PIN_SCK +#define MYNEWT_VAL_SPI_0_MASTER_PIN_SCK (45) +#endif + +#ifndef MYNEWT_VAL_SPI_0_SLAVE +#define MYNEWT_VAL_SPI_0_SLAVE (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_MISO +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_MISO (47) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_MOSI +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_MOSI (46) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_SCK +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_SCK (45) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_SPI_0_SLAVE_PIN_SS +#define MYNEWT_VAL_SPI_0_SLAVE_PIN_SS (44) +#endif + +#ifndef MYNEWT_VAL_SPI_1_MASTER +#define MYNEWT_VAL_SPI_1_MASTER (0) +#endif + +#undef MYNEWT_VAL_SPI_1_MASTER_PIN_MISO + +#undef MYNEWT_VAL_SPI_1_MASTER_PIN_MOSI + +#undef MYNEWT_VAL_SPI_1_MASTER_PIN_SCK + +#ifndef MYNEWT_VAL_SPI_1_SLAVE +#define MYNEWT_VAL_SPI_1_SLAVE (0) +#endif + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_MISO + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_MOSI + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_SCK + +#undef MYNEWT_VAL_SPI_1_SLAVE_PIN_SS + +#ifndef MYNEWT_VAL_SPI_2_MASTER +#define MYNEWT_VAL_SPI_2_MASTER (0) +#endif + +#undef MYNEWT_VAL_SPI_2_MASTER_PIN_MISO + +#undef MYNEWT_VAL_SPI_2_MASTER_PIN_MOSI + +#undef MYNEWT_VAL_SPI_2_MASTER_PIN_SCK + +#ifndef MYNEWT_VAL_SPI_2_SLAVE +#define MYNEWT_VAL_SPI_2_SLAVE (0) +#endif + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_MISO + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_MOSI + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_SCK + +#undef MYNEWT_VAL_SPI_2_SLAVE_PIN_SS + +#ifndef MYNEWT_VAL_SPI_3_MASTER +#define MYNEWT_VAL_SPI_3_MASTER (0) +#endif + +#undef MYNEWT_VAL_SPI_3_MASTER_PIN_MISO + +#undef MYNEWT_VAL_SPI_3_MASTER_PIN_MOSI + +#undef MYNEWT_VAL_SPI_3_MASTER_PIN_SCK + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_TIMER_0 +#define MYNEWT_VAL_TIMER_0 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_1 +#define MYNEWT_VAL_TIMER_1 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_2 +#define MYNEWT_VAL_TIMER_2 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_3 +#define MYNEWT_VAL_TIMER_3 (0) +#endif + +#ifndef MYNEWT_VAL_TIMER_4 +#define MYNEWT_VAL_TIMER_4 (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_TIMER_5 +#define MYNEWT_VAL_TIMER_5 (1) +#endif + +#ifndef MYNEWT_VAL_TRNG +#define MYNEWT_VAL_TRNG (0) +#endif + +#ifndef MYNEWT_VAL_UART_0 +#define MYNEWT_VAL_UART_0 (1) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_CTS +#define MYNEWT_VAL_UART_0_PIN_CTS (7) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_RTS +#define MYNEWT_VAL_UART_0_PIN_RTS (5) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_RX +#define MYNEWT_VAL_UART_0_PIN_RX (8) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_UART_0_PIN_TX +#define MYNEWT_VAL_UART_0_PIN_TX (6) +#endif + +#ifndef MYNEWT_VAL_UART_1 +#define MYNEWT_VAL_UART_1 (0) +#endif + +#ifndef MYNEWT_VAL_UART_1_PIN_CTS +#define MYNEWT_VAL_UART_1_PIN_CTS (-1) +#endif + +#ifndef MYNEWT_VAL_UART_1_PIN_RTS +#define MYNEWT_VAL_UART_1_PIN_RTS (-1) +#endif + +#undef MYNEWT_VAL_UART_1_PIN_RX + +#undef MYNEWT_VAL_UART_1_PIN_TX + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-core/hw/mcu/nordic/nrf52xxx) */ +#ifndef MYNEWT_VAL_XTAL_32768 +#define MYNEWT_VAL_XTAL_32768 (1) +#endif + +#ifndef MYNEWT_VAL_XTAL_32768_SYNTH +#define MYNEWT_VAL_XTAL_32768_SYNTH (0) +#endif + +#ifndef MYNEWT_VAL_XTAL_RC +#define MYNEWT_VAL_XTAL_RC (0) +#endif + +/*** @apache-mynewt-core/kernel/os */ +#ifndef MYNEWT_VAL_FLOAT_USER +#define MYNEWT_VAL_FLOAT_USER (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_1_BLOCK_COUNT (5) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_MSYS_1_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_1_BLOCK_SIZE (88) +#endif + +#ifndef MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_1_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_COUNT +#define MYNEWT_VAL_MSYS_2_BLOCK_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_BLOCK_SIZE +#define MYNEWT_VAL_MSYS_2_BLOCK_SIZE (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT +#define MYNEWT_VAL_MSYS_2_SANITY_MIN_COUNT (0) +#endif + +#ifndef MYNEWT_VAL_MSYS_SANITY_TIMEOUT +#define MYNEWT_VAL_MSYS_SANITY_TIMEOUT (60000) +#endif + +#ifndef MYNEWT_VAL_OS_ASSERT_CB +#define MYNEWT_VAL_OS_ASSERT_CB (0) +#endif + +#ifndef MYNEWT_VAL_OS_CLI +#define MYNEWT_VAL_OS_CLI (0) +#endif + +#ifndef MYNEWT_VAL_OS_COREDUMP +#define MYNEWT_VAL_OS_COREDUMP (0) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_OS_CPUTIME_FREQ +#define MYNEWT_VAL_OS_CPUTIME_FREQ (32768) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-core/kernel/os) */ +#ifndef MYNEWT_VAL_OS_CPUTIME_TIMER_NUM +#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (5) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_FILE_LINE +#define MYNEWT_VAL_OS_CRASH_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_LOG +#define MYNEWT_VAL_OS_CRASH_LOG (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_RESTORE_REGS +#define MYNEWT_VAL_OS_CRASH_RESTORE_REGS (0) +#endif + +#ifndef MYNEWT_VAL_OS_CRASH_STACKTRACE +#define MYNEWT_VAL_OS_CRASH_STACKTRACE (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_CHECK +#define MYNEWT_VAL_OS_CTX_SW_STACK_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_CTX_SW_STACK_GUARD +#define MYNEWT_VAL_OS_CTX_SW_STACK_GUARD (4) +#endif + +#ifndef MYNEWT_VAL_OS_DEBUG_MODE +#define MYNEWT_VAL_OS_DEBUG_MODE (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_DEBUG +#define MYNEWT_VAL_OS_EVENTQ_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_EVENTQ_MONITOR +#define MYNEWT_VAL_OS_EVENTQ_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MAX (600000) +#endif + +#ifndef MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN +#define MYNEWT_VAL_OS_IDLE_TICKLESS_MS_MIN (100) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_STACK_SIZE +#define MYNEWT_VAL_OS_MAIN_STACK_SIZE (1024) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_PRIO +#define MYNEWT_VAL_OS_MAIN_TASK_PRIO (127) +#endif + +#ifndef MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS +#define MYNEWT_VAL_OS_MAIN_TASK_SANITY_ITVL_MS (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_CHECK +#define MYNEWT_VAL_OS_MEMPOOL_CHECK (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_GUARD +#define MYNEWT_VAL_OS_MEMPOOL_GUARD (0) +#endif + +#ifndef MYNEWT_VAL_OS_MEMPOOL_POISON +#define MYNEWT_VAL_OS_MEMPOOL_POISON (0) +#endif + +#ifndef MYNEWT_VAL_OS_SCHEDULING +#define MYNEWT_VAL_OS_SCHEDULING (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSINIT_STAGE +#define MYNEWT_VAL_OS_SYSINIT_STAGE (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW +#define MYNEWT_VAL_OS_SYSVIEW (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_CALLOUT (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_EVENTQ (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MBUF (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MEMPOOL (0) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_MUTEX (1) +#endif + +#ifndef MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM +#define MYNEWT_VAL_OS_SYSVIEW_TRACE_SEM (1) +#endif + +#ifndef MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME +#define MYNEWT_VAL_OS_TASK_RUN_TIME_CPUTIME (0) +#endif + +#ifndef MYNEWT_VAL_OS_TIME_DEBUG +#define MYNEWT_VAL_OS_TIME_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_OS_WATCHDOG_MONITOR +#define MYNEWT_VAL_OS_WATCHDOG_MONITOR (0) +#endif + +#ifndef MYNEWT_VAL_SANITY_INTERVAL +#define MYNEWT_VAL_SANITY_INTERVAL (15000) +#endif + +#ifndef MYNEWT_VAL_WATCHDOG_INTERVAL +#define MYNEWT_VAL_WATCHDOG_INTERVAL (30000) +#endif + +/*** @apache-mynewt-core/libc/baselibc */ +#ifndef MYNEWT_VAL_BASELIBC_ASSERT_FILE_LINE +#define MYNEWT_VAL_BASELIBC_ASSERT_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_BASELIBC_PRESENT +#define MYNEWT_VAL_BASELIBC_PRESENT (1) +#endif + +/*** @apache-mynewt-core/sys/console/stub */ +#ifndef MYNEWT_VAL_CONSOLE_UART_BAUD +#define MYNEWT_VAL_CONSOLE_UART_BAUD (115200) +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_DEV +#define MYNEWT_VAL_CONSOLE_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL +#define MYNEWT_VAL_CONSOLE_UART_FLOW_CONTROL (UART_FLOW_CTL_NONE) +#endif + +/*** @apache-mynewt-core/sys/flash_map */ +#ifndef MYNEWT_VAL_FLASH_MAP_MAX_AREAS +#define MYNEWT_VAL_FLASH_MAP_MAX_AREAS (10) +#endif + +#ifndef MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE +#define MYNEWT_VAL_FLASH_MAP_SYSINIT_STAGE (2) +#endif + +/*** @apache-mynewt-core/sys/log/common */ +#ifndef MYNEWT_VAL_DFLT_LOG_LVL +#define MYNEWT_VAL_DFLT_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_DFLT_LOG_MOD +#define MYNEWT_VAL_DFLT_LOG_MOD (0) +#endif + +#ifndef MYNEWT_VAL_LOG_GLOBAL_IDX +#define MYNEWT_VAL_LOG_GLOBAL_IDX (1) +#endif + +/*** @apache-mynewt-core/sys/log/modlog */ +#ifndef MYNEWT_VAL_MODLOG_CONSOLE_DFLT +#define MYNEWT_VAL_MODLOG_CONSOLE_DFLT (1) +#endif + +#ifndef MYNEWT_VAL_MODLOG_LOG_MACROS +#define MYNEWT_VAL_MODLOG_LOG_MACROS (0) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_MAPPINGS +#define MYNEWT_VAL_MODLOG_MAX_MAPPINGS (16) +#endif + +#ifndef MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN +#define MYNEWT_VAL_MODLOG_MAX_PRINTF_LEN (128) +#endif + +#ifndef MYNEWT_VAL_MODLOG_SYSINIT_STAGE +#define MYNEWT_VAL_MODLOG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/log/stub */ +#ifndef MYNEWT_VAL_LOG_CONSOLE +#define MYNEWT_VAL_LOG_CONSOLE (1) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB +#define MYNEWT_VAL_LOG_FCB (0) +#endif + +#ifndef MYNEWT_VAL_LOG_FCB_SLOT1 +#define MYNEWT_VAL_LOG_FCB_SLOT1 (0) +#endif + +#ifndef MYNEWT_VAL_LOG_LEVEL +#define MYNEWT_VAL_LOG_LEVEL (255) +#endif + +/*** @apache-mynewt-core/sys/mfg */ +#ifndef MYNEWT_VAL_MFG_LOG_LVL +#define MYNEWT_VAL_MFG_LOG_LVL (15) +#endif + +#ifndef MYNEWT_VAL_MFG_LOG_MODULE +#define MYNEWT_VAL_MFG_LOG_MODULE (128) +#endif + +#ifndef MYNEWT_VAL_MFG_MAX_MMRS +#define MYNEWT_VAL_MFG_MAX_MMRS (2) +#endif + +#ifndef MYNEWT_VAL_MFG_SYSINIT_STAGE +#define MYNEWT_VAL_MFG_SYSINIT_STAGE (100) +#endif + +/*** @apache-mynewt-core/sys/sys */ +#ifndef MYNEWT_VAL_DEBUG_PANIC_ENABLED +#define MYNEWT_VAL_DEBUG_PANIC_ENABLED (1) +#endif + +/*** @apache-mynewt-core/sys/sysdown */ +#ifndef MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN +#define MYNEWT_VAL_SYSDOWN_CONSTRAIN_DOWN (1) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSDOWN_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE +#define MYNEWT_VAL_SYSDOWN_PANIC_MESSAGE (0) +#endif + +#ifndef MYNEWT_VAL_SYSDOWN_TIMEOUT_MS +#define MYNEWT_VAL_SYSDOWN_TIMEOUT_MS (10000) +#endif + +/*** @apache-mynewt-core/sys/sysinit */ +#ifndef MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT +#define MYNEWT_VAL_SYSINIT_CONSTRAIN_INIT (1) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE +#define MYNEWT_VAL_SYSINIT_PANIC_FILE_LINE (0) +#endif + +#ifndef MYNEWT_VAL_SYSINIT_PANIC_MESSAGE +#define MYNEWT_VAL_SYSINIT_PANIC_MESSAGE (0) +#endif + +/*** @apache-mynewt-core/util/rwlock */ +#ifndef MYNEWT_VAL_RWLOCK_DEBUG +#define MYNEWT_VAL_RWLOCK_DEBUG (0) +#endif + +/*** @apache-mynewt-nimble/nimble */ +#ifndef MYNEWT_VAL_BLE_EXT_ADV +#define MYNEWT_VAL_BLE_EXT_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE +#define MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE (31) +#endif + +#ifndef MYNEWT_VAL_BLE_MAX_CONNECTIONS +#define MYNEWT_VAL_BLE_MAX_CONNECTIONS (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble) */ +#ifndef MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS +#define MYNEWT_VAL_BLE_MAX_PERIODIC_SYNCS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES +#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV +#define MYNEWT_VAL_BLE_PERIODIC_ADV (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER +#define MYNEWT_VAL_BLE_PERIODIC_ADV_SYNC_TRANSFER (0) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_BROADCASTER +#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_CENTRAL +#define MYNEWT_VAL_BLE_ROLE_CENTRAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_OBSERVER +#define MYNEWT_VAL_BLE_ROLE_OBSERVER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ROLE_PERIPHERAL +#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_VERSION +#define MYNEWT_VAL_BLE_VERSION (50) +#endif + +#ifndef MYNEWT_VAL_BLE_WHITELIST +#define MYNEWT_VAL_BLE_WHITELIST (1) +#endif + +/*** @apache-mynewt-nimble/nimble/controller */ +#ifndef MYNEWT_VAL_BLE_CONTROLLER +#define MYNEWT_VAL_BLE_CONTROLLER (1) +#endif + +#ifndef MYNEWT_VAL_BLE_DEVICE +#define MYNEWT_VAL_BLE_DEVICE (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_HW_WHITELIST_ENABLE +#define MYNEWT_VAL_BLE_HW_WHITELIST_ENABLE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_ADD_STRICT_SCHED_PERIODS +#define MYNEWT_VAL_BLE_LL_ADD_STRICT_SCHED_PERIODS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_CONN_PARAM_REQ +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_CONN_PARAM_REQ (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_DATA_LEN_EXT +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_DATA_LEN_EXT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_2M_PHY +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_2M_PHY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CODED_PHY +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CODED_PHY (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CSA2 +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_CSA2 (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_PING +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_PING (MYNEWT_VAL_BLE_LL_CFG_FEAT_LE_ENCRYPTION) +#endif + +/* Value copied from BLE_EXT_ADV */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_EXT_ADV +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_EXT_ADV (0) +#endif + +/* Value copied from BLE_PERIODIC_ADV */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV (0) +#endif + +/* Value copied from BLE_MAX_PERIODIC_SYNCS */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_CNT +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_CNT (0) +#endif + +/* Value copied from BLE_MAX_PERIODIC_SYNCS */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_LIST_CNT +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_LIST_CNT (0) +#endif + +/* Value copied from BLE_PERIODIC_ADV_SYNC_TRANSFER */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PERIODIC_ADV_SYNC_TRANSFER (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PRIVACY +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_LL_PRIVACY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG +#define MYNEWT_VAL_BLE_LL_CFG_FEAT_SLAVE_INIT_FEAT_XCHG (1) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_MAX_TX_BYTES +#define MYNEWT_VAL_BLE_LL_CONN_INIT_MAX_TX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_MIN_WIN_OFFSET +#define MYNEWT_VAL_BLE_LL_CONN_INIT_MIN_WIN_OFFSET (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS +#define MYNEWT_VAL_BLE_LL_CONN_INIT_SLOTS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DBG_HCI_CMD_PIN +#define MYNEWT_VAL_BLE_LL_DBG_HCI_CMD_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DBG_HCI_EV_PIN +#define MYNEWT_VAL_BLE_LL_DBG_HCI_EV_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DIRECT_TEST_MODE +#define MYNEWT_VAL_BLE_LL_DIRECT_TEST_MODE (0) +#endif + +/* Value copied from BLE_LL_DIRECT_TEST_MODE */ +#ifndef MYNEWT_VAL_BLE_LL_DTM +#define MYNEWT_VAL_BLE_LL_DTM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_DTM_EXTENSIONS +#define MYNEWT_VAL_BLE_LL_DTM_EXTENSIONS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_EXT_ADV_AUX_PTR_CNT +#define MYNEWT_VAL_BLE_LL_EXT_ADV_AUX_PTR_CNT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MASTER_SCA +#define MYNEWT_VAL_BLE_LL_MASTER_SCA (4) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE +#define MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE (251) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_MFRG_ID +#define MYNEWT_VAL_BLE_LL_MFRG_ID (0xFFFF) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_COMP_PKT_ITVL_MS +#define MYNEWT_VAL_BLE_LL_NUM_COMP_PKT_ITVL_MS (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_SCAN_DUP_ADVS +#define MYNEWT_VAL_BLE_LL_NUM_SCAN_DUP_ADVS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_NUM_SCAN_RSP_ADVS +#define MYNEWT_VAL_BLE_LL_NUM_SCAN_RSP_ADVS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_OUR_SCA +#define MYNEWT_VAL_BLE_LL_OUR_SCA (60) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_PRIO +#define MYNEWT_VAL_BLE_LL_PRIO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_RESOLV_LIST_SIZE +#define MYNEWT_VAL_BLE_LL_RESOLV_LIST_SIZE (4) +#endif + +/* Overridden by @apache-mynewt-core/hw/bsp/nordic_pca10056 (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_RFMGMT_ENABLE_TIME +#define MYNEWT_VAL_BLE_LL_RFMGMT_ENABLE_TIME (1500) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_RNG_BUFSIZE +#define MYNEWT_VAL_BLE_LL_RNG_BUFSIZE (32) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY +#define MYNEWT_VAL_BLE_LL_SCHED_AUX_CHAIN_MAFS_DELAY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SCHED_AUX_MAFS_DELAY +#define MYNEWT_VAL_BLE_LL_SCHED_AUX_MAFS_DELAY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SCHED_SCAN_AUX_PDU_LEN +#define MYNEWT_VAL_BLE_LL_SCHED_SCAN_AUX_PDU_LEN (41) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SCHED_SCAN_SYNC_PDU_LEN +#define MYNEWT_VAL_BLE_LL_SCHED_SCAN_SYNC_PDU_LEN (32) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_STRICT_CONN_SCHEDULING +#define MYNEWT_VAL_BLE_LL_STRICT_CONN_SCHEDULING (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_SUPP_MAX_RX_BYTES +#define MYNEWT_VAL_BLE_LL_SUPP_MAX_RX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/controller) */ +#ifndef MYNEWT_VAL_BLE_LL_SUPP_MAX_TX_BYTES +#define MYNEWT_VAL_BLE_LL_SUPP_MAX_TX_BYTES (MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_LL_SYSINIT_STAGE (250) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_SYSVIEW +#define MYNEWT_VAL_BLE_LL_SYSVIEW (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_TX_PWR_DBM +#define MYNEWT_VAL_BLE_LL_TX_PWR_DBM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_USECS_PER_PERIOD +#define MYNEWT_VAL_BLE_LL_USECS_PER_PERIOD (3250) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_VND_EVENT_ON_ASSERT +#define MYNEWT_VAL_BLE_LL_VND_EVENT_ON_ASSERT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_LL_WHITELIST_SIZE +#define MYNEWT_VAL_BLE_LL_WHITELIST_SIZE (8) +#endif + +#ifndef MYNEWT_VAL_BLE_LP_CLOCK +#define MYNEWT_VAL_BLE_LP_CLOCK (1) +#endif + +#ifndef MYNEWT_VAL_BLE_NUM_COMP_PKT_RATE +#define MYNEWT_VAL_BLE_NUM_COMP_PKT_RATE ((2 * OS_TICKS_PER_SEC)) +#endif + +#ifndef MYNEWT_VAL_BLE_PUBLIC_DEV_ADDR +#define MYNEWT_VAL_BLE_PUBLIC_DEV_ADDR ((uint8_t[6]){0x00, 0x00, 0x00, 0x00, 0x00, 0x00}) +#endif + +#ifndef MYNEWT_VAL_BLE_XTAL_SETTLE_TIME +#define MYNEWT_VAL_BLE_XTAL_SETTLE_TIME (0) +#endif + +/*** @apache-mynewt-nimble/nimble/drivers/nrf52 */ +#ifndef MYNEWT_VAL_BLE_PHY_CODED_RX_IFS_EXTRA_MARGIN +#define MYNEWT_VAL_BLE_PHY_CODED_RX_IFS_EXTRA_MARGIN (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_ADDRESS_END_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_ADDRESS_END_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_TXRXEN_READY_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_TXRXEN_READY_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_DBG_TIME_WFR_PIN +#define MYNEWT_VAL_BLE_PHY_DBG_TIME_WFR_PIN (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_164 +#define MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_164 (0) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_191 +#define MYNEWT_VAL_BLE_PHY_NRF52840_ERRATA_191 (1) +#endif + +#ifndef MYNEWT_VAL_BLE_PHY_SYSVIEW +#define MYNEWT_VAL_BLE_PHY_SYSVIEW (0) +#endif + +/*** @apache-mynewt-nimble/nimble/host */ +#ifndef MYNEWT_VAL_BLE_ATT_PREFERRED_MTU +#define MYNEWT_VAL_BLE_ATT_PREFERRED_MTU (256) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_INDICATE +#define MYNEWT_VAL_BLE_ATT_SVR_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES +#define MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES (64) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_NOTIFY +#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO +#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ +#define MYNEWT_VAL_BLE_ATT_SVR_READ (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB +#define MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_MULT +#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE +#define MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE +#define MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS +#define MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID +#define MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS +#define MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_INDICATE +#define MYNEWT_VAL_BLE_GATT_INDICATE (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_MAX_PROCS +#define MYNEWT_VAL_BLE_GATT_MAX_PROCS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_NOTIFY +#define MYNEWT_VAL_BLE_GATT_NOTIFY (1) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ +#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_LONG +#define MYNEWT_VAL_BLE_GATT_READ_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS (8) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_MULT +#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_READ_UUID +#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_RESUME_RATE +#define MYNEWT_VAL_BLE_GATT_RESUME_RATE (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_SIGNED_WRITE +#define MYNEWT_VAL_BLE_GATT_SIGNED_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE +#define MYNEWT_VAL_BLE_GATT_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_LONG +#define MYNEWT_VAL_BLE_GATT_WRITE_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS +#define MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS (4) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP +#define MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE +#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL) +#endif + +#ifndef MYNEWT_VAL_BLE_HOST +#define MYNEWT_VAL_BLE_HOST (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_AUTO_START +#define MYNEWT_VAL_BLE_HS_AUTO_START (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_DEBUG +#define MYNEWT_VAL_BLE_HS_DEBUG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL (1000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH (2) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT +#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_LVL +#define MYNEWT_VAL_BLE_HS_LOG_LVL (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_LOG_MOD +#define MYNEWT_VAL_BLE_HS_LOG_MOD (4) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS +#define MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_REQUIRE_OS +#define MYNEWT_VAL_BLE_HS_REQUIRE_OS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN (1) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT +#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT (2000) +#endif + +#ifndef MYNEWT_VAL_BLE_HS_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_HS_SYSINIT_STAGE (200) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM +#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_COC_MPS +#define MYNEWT_VAL_BLE_L2CAP_COC_MPS (MYNEWT_VAL_MSYS_1_BLOCK_SIZE-8) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC +#define MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS +#define MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_MAX_CHANS +#define MYNEWT_VAL_BLE_L2CAP_MAX_CHANS (3*MYNEWT_VAL_BLE_MAX_CONNECTIONS) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT +#define MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT (30000) +#endif + +#ifndef MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS +#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MESH +#define MYNEWT_VAL_BLE_MESH (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE (128) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT +#define MYNEWT_VAL_BLE_MONITOR_RTT (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED (1) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME ("btmonitor") +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE (256) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART +#define MYNEWT_VAL_BLE_MONITOR_UART (0) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE +#define MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE (1000000) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE +#define MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE (64) +#endif + +#ifndef MYNEWT_VAL_BLE_MONITOR_UART_DEV +#define MYNEWT_VAL_BLE_MONITOR_UART_DEV ("uart0") +#endif + +#ifndef MYNEWT_VAL_BLE_RPA_TIMEOUT +#define MYNEWT_VAL_BLE_RPA_TIMEOUT (300) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_BONDING +#define MYNEWT_VAL_BLE_SM_BONDING (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_IO_CAP +#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_NO_INPUT_OUTPUT) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_KEYPRESS +#define MYNEWT_VAL_BLE_SM_KEYPRESS (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/host) */ +#ifndef MYNEWT_VAL_BLE_SM_LEGACY +#define MYNEWT_VAL_BLE_SM_LEGACY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MAX_PROCS +#define MYNEWT_VAL_BLE_SM_MAX_PROCS (1) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_MITM +#define MYNEWT_VAL_BLE_SM_MITM (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG +#define MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_OUR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_OUR_KEY_DIST (0) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/host) */ +#ifndef MYNEWT_VAL_BLE_SM_SC +#define MYNEWT_VAL_BLE_SM_SC (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS +#define MYNEWT_VAL_BLE_SM_SC_DEBUG_KEYS (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST +#define MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST (0) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_BONDS +#define MYNEWT_VAL_BLE_STORE_MAX_BONDS (3) +#endif + +#ifndef MYNEWT_VAL_BLE_STORE_MAX_CCCDS +#define MYNEWT_VAL_BLE_STORE_MAX_CCCDS (8) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gap */ +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION +#define MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME ("nimble") +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH (31) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM +#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM (-1) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO +#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO (0) +#endif + +#ifndef MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GAP_SYSINIT_STAGE (301) +#endif + +/*** @apache-mynewt-nimble/nimble/host/services/gatt */ +#ifndef MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_SVC_GATT_SYSINIT_STAGE (302) +#endif + +/*** @apache-mynewt-nimble/nimble/transport/ram */ +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/transport/ram) */ +#ifndef MYNEWT_VAL_BLE_ACL_BUF_COUNT +#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (4) +#endif + +#ifndef MYNEWT_VAL_BLE_ACL_BUF_SIZE +#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE +#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70) +#endif + +/* Overridden by @apache-mynewt-nimble/targets/riot (defined by @apache-mynewt-nimble/nimble/transport/ram) */ +#ifndef MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (2) +#endif + +#ifndef MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT +#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8) +#endif + +#ifndef MYNEWT_VAL_BLE_TRANS_RAM_SYSINIT_STAGE +#define MYNEWT_VAL_BLE_TRANS_RAM_SYSINIT_STAGE (100) +#endif + +/*** newt */ +#ifndef MYNEWT_VAL_APP_NAME +#define MYNEWT_VAL_APP_NAME ("dummy_app") +#endif + +#ifndef MYNEWT_VAL_APP_dummy_app +#define MYNEWT_VAL_APP_dummy_app (1) +#endif + +#ifndef MYNEWT_VAL_ARCH_NAME +#define MYNEWT_VAL_ARCH_NAME ("cortex_m4") +#endif + +#ifndef MYNEWT_VAL_ARCH_cortex_m4 +#define MYNEWT_VAL_ARCH_cortex_m4 (1) +#endif + +#ifndef MYNEWT_VAL_BSP_NAME +#define MYNEWT_VAL_BSP_NAME ("nordic_pca10056") +#endif + +#ifndef MYNEWT_VAL_BSP_nordic_pca10056 +#define MYNEWT_VAL_BSP_nordic_pca10056 (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_LOGCFG +#define MYNEWT_VAL_NEWT_FEATURE_LOGCFG (1) +#endif + +#ifndef MYNEWT_VAL_NEWT_FEATURE_SYSDOWN +#define MYNEWT_VAL_NEWT_FEATURE_SYSDOWN (1) +#endif + +#ifndef MYNEWT_VAL_TARGET_NAME +#define MYNEWT_VAL_TARGET_NAME ("riot") +#endif + +#ifndef MYNEWT_VAL_TARGET_riot +#define MYNEWT_VAL_TARGET_riot (1) +#endif + +#endif diff --git a/src/libs/mynewt-nimble/porting/npl/riot/include/sysflash/sysflash.h b/src/libs/mynewt-nimble/porting/npl/riot/include/sysflash/sysflash.h new file mode 100644 index 00000000..413cb267 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/riot/include/sysflash/sysflash.h @@ -0,0 +1,24 @@ +/** + * This file was generated by Apache newt version: 1.8.0-dev + */ + +#ifndef H_MYNEWT_SYSFLASH_ +#define H_MYNEWT_SYSFLASH_ + +#include "flash_map/flash_map.h" + +/** + * This flash map definition is used for two purposes: + * 1. To locate the meta area, which contains the true flash map definition. + * 2. As a fallback in case the meta area cannot be read from flash. + */ +extern const struct flash_area sysflash_map_dflt[6]; + +#define FLASH_AREA_BOOTLOADER 0 +#define FLASH_AREA_IMAGE_0 1 +#define FLASH_AREA_IMAGE_1 2 +#define FLASH_AREA_IMAGE_SCRATCH 3 +#define FLASH_AREA_REBOOT_LOG 16 +#define FLASH_AREA_NFFS 17 + +#endif diff --git a/src/libs/mynewt-nimble/porting/npl/riot/src/npl_os_riot.c b/src/libs/mynewt-nimble/porting/npl/riot/src/npl_os_riot.c new file mode 100644 index 00000000..2f4efd8b --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/riot/src/npl_os_riot.c @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include <stddef.h> +#include "nimble/nimble_npl.h" + +#define ENABLE_DEBUG (0) +#include "debug.h" + +volatile int ble_npl_in_critical = 0; + +static void +_callout_fire(void *arg) +{ + struct ble_npl_callout *co = (struct ble_npl_callout *)arg; + event_post(co->q, &co->e.e.super); +} + +ble_npl_error_t +ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout) +{ + int rc; + struct timespec abs; + uint64_t time; + + time = xtimer_now_usec64() + + (ble_npl_time_ticks_to_ms32(timeout) * US_PER_MS); + abs.tv_sec = (time_t)(time / US_PER_SEC); + abs.tv_nsec = (long)((time % US_PER_SEC) * NS_PER_US); + + rc = sem_timedwait(&sem->sem, &abs); + + return rc == 0 ? BLE_NPL_OK : BLE_NPL_ENOENT; +} + +void +ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq, + ble_npl_event_fn *ev_cb, void *ev_arg) +{ + c->timer.arg = (void *)c; + c->timer.callback = _callout_fire; + c->q = &evq->q; + ble_npl_event_init(&c->e, ev_cb, ev_arg); +} + +ble_npl_error_t +ble_npl_callout_reset(struct ble_npl_callout *c, ble_npl_time_t ticks) +{ + /* Use critical section to ensure matching target_us and xtimer value. */ + uint32_t crit_state = ble_npl_hw_enter_critical(); + uint64_t now = xtimer_now_usec64(); + c->target_us = now + ticks * US_PER_MS; + xtimer_set64(&c->timer, ticks * US_PER_MS); + ble_npl_hw_exit_critical(crit_state); + return BLE_NPL_OK; +} + +uint32_t +ble_npl_callout_remaining_ticks(struct ble_npl_callout *co, + ble_npl_time_t time) +{ + uint64_t now = xtimer_now_usec64(); + return (uint32_t)((co->target_us - now) / US_PER_MS); +} diff --git a/src/libs/mynewt-nimble/porting/npl/riot/src/nrf5x_isr.c b/src/libs/mynewt-nimble/porting/npl/riot/src/nrf5x_isr.c new file mode 100644 index 00000000..01ba2348 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/npl/riot/src/nrf5x_isr.c @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#include "cpu.h" + +static void (*radio_isr_addr)(void); +static void (*rng_isr_addr)(void); +static void (*rtc0_isr_addr)(void); + +void +isr_radio(void) +{ + radio_isr_addr(); +} + +void +isr_rng(void) +{ + rng_isr_addr(); +} + +void +isr_rtc0(void) +{ + rtc0_isr_addr(); +} + +void +ble_npl_hw_set_isr(int irqn, void (*addr)(void)) +{ + switch (irqn) { + case RADIO_IRQn: + radio_isr_addr = addr; + break; + case RNG_IRQn: + rng_isr_addr = addr; + break; + case RTC0_IRQn: + rtc0_isr_addr = addr; + break; + } +} diff --git a/src/libs/mynewt-nimble/porting/targets/dummy_app/pkg.yml b/src/libs/mynewt-nimble/porting/targets/dummy_app/pkg.yml new file mode 100644 index 00000000..f39c848e --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/dummy_app/pkg.yml @@ -0,0 +1,24 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: porting/targets/dummy_app +pkg.type: app +pkg.description: Dummy application +pkg.author: "Apache Mynewt <dev@mynewt.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: diff --git a/src/libs/mynewt-nimble/porting/targets/dummy_app/src/dummy.c b/src/libs/mynewt-nimble/porting/targets/dummy_app/src/dummy.c new file mode 100644 index 00000000..0bd431fd --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/dummy_app/src/dummy.c @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#pragma message ( "This will probably not compile. Used to generate syscfg.h file and other artifacts." ) + +int +main(void) +{ + return 0; +} diff --git a/src/libs/mynewt-nimble/porting/targets/dummy_bsp/bsp.yml b/src/libs/mynewt-nimble/porting/targets/dummy_bsp/bsp.yml new file mode 100644 index 00000000..ecd1d420 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/dummy_bsp/bsp.yml @@ -0,0 +1,56 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +bsp.name: "dummy" +bsp.url: +bsp.maker: +bsp.arch: dummy +bsp.compiler: "@apache-mynewt-core/compiler/sim" + +bsp.flash_map: + areas: + # System areas. + FLASH_AREA_BOOTLOADER: + device: 0 + offset: 0x00000000 + size: 32kB + FLASH_AREA_IMAGE_0: + device: 0 + offset: 0x0000c000 + size: 472kB + FLASH_AREA_IMAGE_1: + device: 0 + offset: 0x00082000 + size: 472kB + FLASH_AREA_IMAGE_SCRATCH: + device: 0 + offset: 0x000f8000 + size: 16kB + + # User areas. + FLASH_AREA_REBOOT_LOG: + user_id: 0 + device: 0 + offset: 0x00008000 + size: 16kB + FLASH_AREA_NFFS: + user_id: 1 + device: 0 + offset: 0x000fc000 + size: 16kB diff --git a/src/libs/mynewt-nimble/porting/targets/dummy_bsp/include/bsp/bsp.h b/src/libs/mynewt-nimble/porting/targets/dummy_bsp/include/bsp/bsp.h new file mode 100644 index 00000000..69e8b1cf --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/dummy_bsp/include/bsp/bsp.h @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +#ifndef H_BSP_H +#define H_BSP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* H_BSP_H */ diff --git a/src/libs/mynewt-nimble/porting/targets/dummy_bsp/pkg.yml b/src/libs/mynewt-nimble/porting/targets/dummy_bsp/pkg.yml new file mode 100644 index 00000000..8b848496 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/dummy_bsp/pkg.yml @@ -0,0 +1,27 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: porting/targets/dummy_bsp +pkg.type: bsp +pkg.description: A dummy BSP definition +pkg.author: "Apache Mynewt <dev@mynewt.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: +pkg.cflags: +pkg.deps: diff --git a/src/libs/mynewt-nimble/porting/targets/linux/pkg.yml b/src/libs/mynewt-nimble/porting/targets/linux/pkg.yml new file mode 100644 index 00000000..f1159d4a --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/linux/pkg.yml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: "targets/linux" +pkg.type: "target" +pkg.description: This target is used to generate syscfg.h file and other artifacts for linux example app. +pkg.author: +pkg.homepage: + +pkg.deps: + - "@apache-mynewt-core/kernel/os" + - "@apache-mynewt-core/sys/console/stub" + - "@apache-mynewt-core/sys/log/stub" + - "@apache-mynewt-core/sys/stats/stub" + - "@apache-mynewt-nimble/nimble/host" + - "@apache-mynewt-nimble/nimble/transport/socket" + - "@apache-mynewt-nimble/nimble/host/services/ans" + - "@apache-mynewt-nimble/nimble/host/services/bas" + - "@apache-mynewt-nimble/nimble/host/services/dis" + - "@apache-mynewt-nimble/nimble/host/services/gap" + - "@apache-mynewt-nimble/nimble/host/services/gatt" + - "@apache-mynewt-nimble/nimble/host/services/ias" + - "@apache-mynewt-nimble/nimble/host/services/ipss" + - "@apache-mynewt-nimble/nimble/host/services/lls" + - "@apache-mynewt-nimble/nimble/host/services/tps" diff --git a/src/libs/mynewt-nimble/porting/targets/linux/syscfg.yml b/src/libs/mynewt-nimble/porting/targets/linux/syscfg.yml new file mode 100644 index 00000000..603e586c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/linux/syscfg.yml @@ -0,0 +1,25 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +syscfg.vals: + BLE_SOCK_USE_TCP: 0 + BLE_SOCK_USE_LINUX_BLUE: 1 + BLE_SOCK_TASK_PRIO: 3 + BLE_SOCK_STACK_SIZE: 1028 + + LOG_LEVEL: 0 diff --git a/src/libs/mynewt-nimble/porting/targets/linux/target.yml b/src/libs/mynewt-nimble/porting/targets/linux/target.yml new file mode 100644 index 00000000..9ab4152c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/linux/target.yml @@ -0,0 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +target.app: "porting/targets/dummy_app" +target.bsp: "porting/targets/dummy_bsp" +target.build_profile: "debug" diff --git a/src/libs/mynewt-nimble/porting/targets/linux_blemesh/pkg.yml b/src/libs/mynewt-nimble/porting/targets/linux_blemesh/pkg.yml new file mode 100644 index 00000000..c3149333 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/linux_blemesh/pkg.yml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: "targets/linux_blemesh" +pkg.type: "target" +pkg.description: This target is used to generate syscfg.h file and other artifacts for linux_blemesh example app. +pkg.author: +pkg.homepage: + +pkg.deps: + - "@apache-mynewt-core/kernel/os" + - "@apache-mynewt-core/sys/console/stub" + - "@apache-mynewt-core/sys/log/stub" + - "@apache-mynewt-core/sys/stats/stub" + - "@apache-mynewt-nimble/nimble/host" + - "@apache-mynewt-nimble/nimble/transport/socket" + - "@apache-mynewt-nimble/nimble/host/services/ans" + - "@apache-mynewt-nimble/nimble/host/services/bas" + - "@apache-mynewt-nimble/nimble/host/services/dis" + - "@apache-mynewt-nimble/nimble/host/services/gap" + - "@apache-mynewt-nimble/nimble/host/services/gatt" + - "@apache-mynewt-nimble/nimble/host/services/ias" + - "@apache-mynewt-nimble/nimble/host/services/ipss" + - "@apache-mynewt-nimble/nimble/host/services/lls" + - "@apache-mynewt-nimble/nimble/host/services/tps" diff --git a/src/libs/mynewt-nimble/porting/targets/linux_blemesh/syscfg.yml b/src/libs/mynewt-nimble/porting/targets/linux_blemesh/syscfg.yml new file mode 100644 index 00000000..efc4150b --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/linux_blemesh/syscfg.yml @@ -0,0 +1,50 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +syscfg.vals: + MSYS_1_BLOCK_COUNT: 80 + + BLE_MESH_ADV_BUF_COUNT: 20 + BLE_MESH_TX_SEG_MAX: 6 + + BLE_MESH: 1 + BLE_MESH_SHELL: 0 + BLE_MESH_PROV: 1 + BLE_MESH_RELAY: 1 + BLE_MESH_PB_ADV: 1 + BLE_MESH_PB_GATT: 1 + BLE_MESH_LOW_POWER: 1 + BLE_MESH_LPN_AUTO: 0 + BLE_MESH_GATT_PROXY: 1 + BLE_MESH_LABEL_COUNT: 2 + BLE_MESH_SUBNET_COUNT: 2 + BLE_MESH_MODEL_GROUP_COUNT: 2 + BLE_MESH_APP_KEY_COUNT: 4 + BLE_MESH_IV_UPDATE_TEST: 1 + BLE_MESH_TESTING: 1 + BLE_MESH_FRIEND: 1 + BLE_MESH_CFG_CLI: 1 + BLE_MESH_SETTINGS: 0 + CONFIG_NFFS: 0 + + BLE_SOCK_USE_TCP: 0 + BLE_SOCK_USE_LINUX_BLUE: 1 + BLE_SOCK_TASK_PRIO: 3 + BLE_SOCK_STACK_SIZE: 1028 + + LOG_LEVEL: 0 diff --git a/src/libs/mynewt-nimble/porting/targets/linux_blemesh/target.yml b/src/libs/mynewt-nimble/porting/targets/linux_blemesh/target.yml new file mode 100644 index 00000000..83eb4158 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/linux_blemesh/target.yml @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +target.app: "porting/targets/dummy_app" +target.bsp: "porting/targets/dummy_bsp" +target.build_profile: "debug" diff --git a/src/libs/mynewt-nimble/porting/targets/porting_default/pkg.yml b/src/libs/mynewt-nimble/porting/targets/porting_default/pkg.yml new file mode 100644 index 00000000..f7319c25 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/porting_default/pkg.yml @@ -0,0 +1,40 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: "targets/porting_default" +pkg.type: "target" +pkg.description: This target is used to generate syscfg.h file and other artifacts for default Nimble port includes. +pkg.author: +pkg.homepage: + +pkg.deps: + - "@apache-mynewt-core/kernel/os" + - "@apache-mynewt-core/sys/console/stub" + - "@apache-mynewt-core/sys/log/stub" + - "@apache-mynewt-core/sys/stats/stub" + - "@apache-mynewt-nimble/nimble/host" + - "@apache-mynewt-nimble/nimble/transport/socket" + - "@apache-mynewt-nimble/nimble/host/services/ans" + - "@apache-mynewt-nimble/nimble/host/services/bas" + - "@apache-mynewt-nimble/nimble/host/services/dis" + - "@apache-mynewt-nimble/nimble/host/services/gap" + - "@apache-mynewt-nimble/nimble/host/services/gatt" + - "@apache-mynewt-nimble/nimble/host/services/ias" + - "@apache-mynewt-nimble/nimble/host/services/ipss" + - "@apache-mynewt-nimble/nimble/host/services/lls" + - "@apache-mynewt-nimble/nimble/host/services/tps" diff --git a/src/libs/mynewt-nimble/porting/targets/porting_default/target.yml b/src/libs/mynewt-nimble/porting/targets/porting_default/target.yml new file mode 100644 index 00000000..83eb4158 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/porting_default/target.yml @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +target.app: "porting/targets/dummy_app" +target.bsp: "porting/targets/dummy_bsp" +target.build_profile: "debug" diff --git a/src/libs/mynewt-nimble/porting/targets/riot/pkg.yml b/src/libs/mynewt-nimble/porting/targets/riot/pkg.yml new file mode 100644 index 00000000..b6610c30 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/riot/pkg.yml @@ -0,0 +1,34 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +pkg.name: "targets/riot" +pkg.type: "target" +pkg.description: This target is used to generate syscfg.h file and other artifacts for RIOT Nimble port. +pkg.author: +pkg.homepage: + +pkg.deps: + - "@apache-mynewt-core/kernel/os" + - "@apache-mynewt-core/sys/console/stub" + - "@apache-mynewt-core/sys/log/stub" + - "@apache-mynewt-core/sys/stats/stub" + - "@apache-mynewt-nimble/nimble/host" + - "@apache-mynewt-nimble/nimble/controller" + - "@apache-mynewt-nimble/nimble/transport/ram" + - "@apache-mynewt-nimble/nimble/host/services/gap" + - "@apache-mynewt-nimble/nimble/host/services/gatt" diff --git a/src/libs/mynewt-nimble/porting/targets/riot/syscfg.yml b/src/libs/mynewt-nimble/porting/targets/riot/syscfg.yml new file mode 100644 index 00000000..7bbb57fe --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/riot/syscfg.yml @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +syscfg.vals: + BLE_ACL_BUF_COUNT: 4 + BLE_HCI_EVT_HI_BUF_COUNT: 2 + BLE_HW_WHITELIST_ENABLE: 0 + BLE_LL_CFG_FEAT_DATA_LEN_EXT: 0 + BLE_LL_CFG_FEAT_LE_CSA2: 1 + BLE_LL_CFG_FEAT_LE_ENCRYPTION: 0 + BLE_LL_CFG_FEAT_LL_PRIVACY: 0 + BLE_LL_CONN_INIT_MAX_TX_BYTES: 'MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE' + BLE_LL_SUPP_MAX_RX_BYTES: 'MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE' + BLE_LL_SUPP_MAX_TX_BYTES: 'MYNEWT_VAL_BLE_LL_MAX_PKT_SIZE' + BLE_SM_LEGACY: 0 + BLE_SM_SC: 0 + BLE_MAX_PERIODIC_SYNCS: 0 + MSYS_1_BLOCK_COUNT: 5 + MSYS_1_BLOCK_SIZE: 88 + XTAL_32768: 1 diff --git a/src/libs/mynewt-nimble/porting/targets/riot/target.yml b/src/libs/mynewt-nimble/porting/targets/riot/target.yml new file mode 100644 index 00000000..850d8f1c --- /dev/null +++ b/src/libs/mynewt-nimble/porting/targets/riot/target.yml @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +target.app: "porting/targets/dummy_app" +target.bsp: "@apache-mynewt-core/hw/bsp/nordic_pca10056" +target.build_profile: "debug" diff --git a/src/libs/mynewt-nimble/porting/update_generated_files.sh b/src/libs/mynewt-nimble/porting/update_generated_files.sh new file mode 100755 index 00000000..c01dddd2 --- /dev/null +++ b/src/libs/mynewt-nimble/porting/update_generated_files.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +if [ ! -f "project.yml" ]; then + echo "This script should be executed from project root directory" + exit 1 +fi + +declare -A targets=( + ["linux"]="repos/apache-mynewt-nimble/porting/examples/linux/" + ["linux_blemesh"]="repos/apache-mynewt-nimble/porting/examples/linux_blemesh/" + ["porting_default"]="repos/apache-mynewt-nimble/porting/nimble" + ["riot"]="repos/apache-mynewt-nimble/porting/npl/riot/" +) + +for target in "${!targets[@]}"; do + echo "Updating target $target" + newt build "$target" > /dev/null 2>&1 + cp "bin/@apache-mynewt-nimble/targets/${target}/generated/include" "${targets[$target]}" -r +done |