From a05fc5f2193afeddeac404c7b9aa8852eb3b246e Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 20 Jun 2023 14:53:53 +0200 Subject: [PATCH] nrf5-zephyr: replaced by new port/zephyr --- CHANGELOG.md | 5 +- port/nrf5-zephyr/Kconfig | 5 - port/nrf5-zephyr/Makefile | 5 - port/nrf5-zephyr/Makefile.ble | 14 - port/nrf5-zephyr/Makefile.bluedroid | 2 - port/nrf5-zephyr/Makefile.bluedroid-decoder | 17 -- port/nrf5-zephyr/Makefile.bluedroid-encoder | 11 - port/nrf5-zephyr/Makefile.gatt-service | 4 - port/nrf5-zephyr/Makefile.src | 25 -- port/nrf5-zephyr/README.md | 36 --- port/nrf5-zephyr/btstack_config.h | 44 --- port/nrf5-zephyr/create_examples.py | 105 ------- port/nrf5-zephyr/flash_nrf51_pca10028.sh | 4 - port/nrf5-zephyr/flash_nrf52_pca10040.sh | 4 - port/nrf5-zephyr/integrate_btstack.sh | 51 ---- port/nrf5-zephyr/main.c | 301 -------------------- port/nrf5-zephyr/net-Kconfig.patch | 11 - port/nrf5-zephyr/nrf5.conf | 23 -- 18 files changed, 3 insertions(+), 664 deletions(-) delete mode 100644 port/nrf5-zephyr/Kconfig delete mode 100644 port/nrf5-zephyr/Makefile delete mode 100644 port/nrf5-zephyr/Makefile.ble delete mode 100644 port/nrf5-zephyr/Makefile.bluedroid delete mode 100644 port/nrf5-zephyr/Makefile.bluedroid-decoder delete mode 100644 port/nrf5-zephyr/Makefile.bluedroid-encoder delete mode 100644 port/nrf5-zephyr/Makefile.gatt-service delete mode 100644 port/nrf5-zephyr/Makefile.src delete mode 100644 port/nrf5-zephyr/README.md delete mode 100644 port/nrf5-zephyr/btstack_config.h delete mode 100755 port/nrf5-zephyr/create_examples.py delete mode 100755 port/nrf5-zephyr/flash_nrf51_pca10028.sh delete mode 100755 port/nrf5-zephyr/flash_nrf52_pca10040.sh delete mode 100755 port/nrf5-zephyr/integrate_btstack.sh delete mode 100644 port/nrf5-zephyr/main.c delete mode 100644 port/nrf5-zephyr/net-Kconfig.patch delete mode 100644 port/nrf5-zephyr/nrf5.conf diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a6d89562..8153c68b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - GATT Client: support GATT over Enhanced LE Bearer - GATT Server: support GATT over Enhanced LE Bearer - +- Port for Zephyr 3.x + ### Fixed - HCI: fix remove le device from whitelist - HFP: use 'don't care' to accept SCO connections, fixes issue on ESP32 @@ -19,7 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - btstack_crypto: allow MBEDTLS config via MBEDTLS_CONFIG_FILE - +- remove old Zephyr 1.9 port ## Release v1.5.6 diff --git a/port/nrf5-zephyr/Kconfig b/port/nrf5-zephyr/Kconfig deleted file mode 100644 index b9fe16707..000000000 --- a/port/nrf5-zephyr/Kconfig +++ /dev/null @@ -1,5 +0,0 @@ -menuconfig BTSTACK - bool "BTstack support" - default n - help - This option enables the BTstack Bluetooth stack. diff --git a/port/nrf5-zephyr/Makefile b/port/nrf5-zephyr/Makefile deleted file mode 100644 index 422972908..000000000 --- a/port/nrf5-zephyr/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -KERNEL_TYPE = nano -CONF_FILE ?= nrf5.conf -BOARD ?= nrf52_pca10040 - -include ${ZEPHYR_BASE}/Makefile.inc diff --git a/port/nrf5-zephyr/Makefile.ble b/port/nrf5-zephyr/Makefile.ble deleted file mode 100644 index 6539eb25f..000000000 --- a/port/nrf5-zephyr/Makefile.ble +++ /dev/null @@ -1,14 +0,0 @@ -obj-y += \ - ancs_client.o \ - att_db.o \ - att_dispatch.o \ - att_server.o \ - gatt_client.o \ - le_device_db_memory.o \ - sm.o \ - sm_mbedtls_allocator.o \ - -# att_db_util.o \ - -obj-y += gatt-service/ -ccflags-y += -I${ZEPHYR_BASE}/subsys/btstack diff --git a/port/nrf5-zephyr/Makefile.bluedroid b/port/nrf5-zephyr/Makefile.bluedroid deleted file mode 100644 index 5b691b451..000000000 --- a/port/nrf5-zephyr/Makefile.bluedroid +++ /dev/null @@ -1,2 +0,0 @@ -obj-y += encoder/srce/ -obj-y += decoder/srce/ diff --git a/port/nrf5-zephyr/Makefile.bluedroid-decoder b/port/nrf5-zephyr/Makefile.bluedroid-decoder deleted file mode 100644 index 3246ebf60..000000000 --- a/port/nrf5-zephyr/Makefile.bluedroid-decoder +++ /dev/null @@ -1,17 +0,0 @@ -obj-y += \ - alloc.o \ - bitalloc.o \ - bitalloc-sbc.o \ - bitstream-decode.o \ - decoder-oina.o \ - decoder-private.o \ - decoder-sbc.o \ - dequant.o \ - framing.o \ - framing-sbc.o \ - oi_codec_version.o \ - synthesis-sbc.o \ - synthesis-dct8.o \ - synthesis-8-generated.o \ - -ccflags-y += -I${ZEPHYR_BASE}/subsys/btstack/bluedroid/decoder/include diff --git a/port/nrf5-zephyr/Makefile.bluedroid-encoder b/port/nrf5-zephyr/Makefile.bluedroid-encoder deleted file mode 100644 index ef222dda1..000000000 --- a/port/nrf5-zephyr/Makefile.bluedroid-encoder +++ /dev/null @@ -1,11 +0,0 @@ -obj-y += \ - sbc_analysis.o \ - sbc_dct.o \ - sbc_dct_coeffs.o \ - sbc_enc_bit_alloc_mono.o \ - sbc_enc_bit_alloc_ste.o \ - sbc_enc_coeffs.o \ - sbc_encoder.o \ - sbc_packing.o \ - -ccflags-y += -I${ZEPHYR_BASE}/subsys/btstack/bluedroid/encoder/include diff --git a/port/nrf5-zephyr/Makefile.gatt-service b/port/nrf5-zephyr/Makefile.gatt-service deleted file mode 100644 index 6f7c43a39..000000000 --- a/port/nrf5-zephyr/Makefile.gatt-service +++ /dev/null @@ -1,4 +0,0 @@ -obj-y += \ - battery_service_server.o \ - -ccflags-y += -I${ZEPHYR_BASE}/subsys/btstack diff --git a/port/nrf5-zephyr/Makefile.src b/port/nrf5-zephyr/Makefile.src deleted file mode 100644 index 783d1f184..000000000 --- a/port/nrf5-zephyr/Makefile.src +++ /dev/null @@ -1,25 +0,0 @@ -obj-y += \ - ad_parser.o \ - btstack_crypto.o \ - btstack_linked_list.o \ - btstack_memory.o \ - btstack_memory_pool.o \ - btstack_ring_buffer.o \ - btstack_run_loop.o \ - btstack_tlv.o \ - btstack_util.o \ - hci.o \ - hci_cmd.o \ - hci_dump.o \ - hci_transport_h4.o \ - l2cap.o \ - l2cap_signaling.o \ - btstack_run_loop_embedded.o \ - hci_dump_embedded_stdout.o \ - -obj-y += ble/ -# obj-y += classic/ -# obj-y += bluedroid/ - -ccflags-y += -I${ZEPHYR_BASE}/subsys/btstack -ccflags-y += -I${ZEPHYR_BASE}/ext/hal/nordic/mdk diff --git a/port/nrf5-zephyr/README.md b/port/nrf5-zephyr/README.md deleted file mode 100644 index bfd8232bb..000000000 --- a/port/nrf5-zephyr/README.md +++ /dev/null @@ -1,36 +0,0 @@ -# BTstack Port for Zephyr RTOS running on Nordic nRF5 Series - -## Overview - -This port targets the bare Nordic nRF5-Series chipsets with the BLE Link Layer provided by the Zephyr project. - -## Status - -Working with nRF52 pca10040 dev board. Public BD ADDR is set to 11:22:33:44:55:66 since the default 00:00:00:00:00:00 is filtered by iOS. - -## Getting Started - -To integrate BTstack into Zephyr, please move the BTstack project into the Zephyr root folder 'zephyr'. Please use the Zephry '1.9-branch' for now. In the master branch, Zephyr switched the build system to CMake and this port hasn't been update for that yet. - -Then integrate BTstack: - - cd /path/to/zephy/btstack/port/nrf5-zephyr - ./integrate_btstack.sh - -Now, the BTstack examples can be build from the Zephyr examples folder in the same way as other examples, e.g.: - - cd /path/to/zephyr/samples/btstack/le_counter - make - -to build the le_counter example for the pca10040 dev kit using the ARM GCC compiler. - -You can use `make flash` or `./flash_nrf52_pca10040.sh` to download it onto the board. - -All examples that provide a GATT Server use the GATT DB in the .gatt file. Therefore you need to run ./update_gatt_db.sh in the example folder after modifying the .gatt file. - -This port does not support Data Sources aside from the HCI Controller. - -## TODO -- printf is configured by patching `drivers/serial/uart_nrf5.c' to use 115200 (default: 100000). There should be a better way to set baud rate. -- enable/configure DLE for max packet size for LE Streamer - diff --git a/port/nrf5-zephyr/btstack_config.h b/port/nrf5-zephyr/btstack_config.h deleted file mode 100644 index 4af98cc97..000000000 --- a/port/nrf5-zephyr/btstack_config.h +++ /dev/null @@ -1,44 +0,0 @@ -// -// btstack_config.h for mRF5-Zephyr port -// -// Documentation: https://bluekitchen-gmbh.com/btstack/#how_to/ -// - -#ifndef BTSTACK_CONFIG_H -#define BTSTACK_CONFIG_H - -// Port related features - -// BTstack features that can be enabled -#define ENABLE_BLE -#define ENABLE_LE_CENTRAL -#define ENABLE_L2CAP_LE_CREDIT_BASED_FLOW_CONTROL_MODE -#define ENABLE_LE_DATA_LENGTH_EXTENSION -#define ENABLE_LE_PERIPHERAL -#define ENABLE_LOG_ERROR -#define ENABLE_LOG_INFO -#define ENABLE_PRINTF_HEXDUMP - -// BTstack configuration. buffers, sizes, ... -#define HCI_ACL_PAYLOAD_SIZE 260 -#define MAX_NR_GATT_CLIENTS 1 -#define MAX_NR_HCI_CONNECTIONS 1 -#define MAX_NR_L2CAP_CHANNELS 1 -#define MAX_NR_L2CAP_SERVICES 1 -#define MAX_NR_SM_LOOKUP_ENTRIES 3 -#define MAX_NR_WHITELIST_ENTRIES 1 - -#define MAX_NR_BNEP_CHANNELS 0 -#define MAX_NR_BNEP_SERVICES 0 -#define MAX_NR_BTSTACK_LINK_KEY_DB_MEMORY_ENTRIES 0 -#define MAX_NR_HFP_CONNECTIONS 0 -#define MAX_NR_LE_DEVICE_DB_ENTRIES 1 -#define MAX_NR_RFCOMM_CHANNELS 0 -#define MAX_NR_RFCOMM_MULTIPLEXERS 0 -#define MAX_NR_RFCOMM_SERVICES 0 -#define MAX_NR_SERVICE_RECORD_ITEMS 0 - -// hack to fix usage of hci_init in zephry -#define hci_init btstack_hci_init - -#endif diff --git a/port/nrf5-zephyr/create_examples.py b/port/nrf5-zephyr/create_examples.py deleted file mode 100755 index 3f4987892..000000000 --- a/port/nrf5-zephyr/create_examples.py +++ /dev/null @@ -1,105 +0,0 @@ -#!/usr/bin/env python3 -# -# Create project files for all BTstack embedded examples in zephyr/samples/btstack - -import os -import shutil -import sys -import time -import subprocess - -mk_template = '''# -# BTstack example 'EXAMPLE' for nRF5-zephyr port -# -# Generated by TOOL -# On DATE - -obj-y += EXAMPLE.o -obj-y += main.o -ccflags-y += -I${ZEPHYR_BASE}/subsys/bluetooth -ccflags-y += -I${ZEPHYR_BASE}/subsys/bluetooth/controller/include -ccflags-y += -I${ZEPHYR_BASE}/subsys/btstack -''' - -gatt_update_template = '''#!/bin/sh -DIR=`dirname $0` -BTSTACK_ROOT=$DIR/../../../btstack -echo "Creating src/EXAMPLE.h from EXAMPLE.gatt" -$BTSTACK_ROOT/tool/compile_gatt.py $BTSTACK_ROOT/example/EXAMPLE.gatt $DIR/src/EXAMPLE.h -''' - -# get script path -script_path = os.path.abspath(os.path.dirname(sys.argv[0])) - -# validate nRF5x SDK root by reading include/zephyr.h -zpehyr_base = script_path + "/../../../" - -zephyr_h = "" -try: - with open(zpehyr_base + '/include/zephyr.h', 'r') as fin: - zephyr_h = fin.read() # Read the contents of the file into memory. -except: - pass -if not "_ZEPHYR__H" in zephyr_h: - print("Cannot find Zpehyr root. Make sure BTstack is checked out as zephyr/btstack") - sys.exit(1) - -# path to examples -examples_embedded = script_path + "/../../example/" - -# path to zephyr/samples/btstack -apps_btstack = zpehyr_base + "/samples/btstack/" - -print("Creating examples in samples/btstack:") - -# iterate over btstack examples -for file in os.listdir(examples_embedded): - if not file.endswith(".c"): - continue - - example = file[:-2] - gatt_path = examples_embedded + example + ".gatt" - - # filter LE-only applications - if not os.path.exists(gatt_path) and not example in [ - "ancs_client_demo","gap_le_advertisements", "gatt_battery_query", "gatt_browser", "sm_pairing_central", 'le_streamer_client']: - continue - if example == "spp_and_gatt_counter": - continue - - # create folder - apps_folder = apps_btstack + example + "/" - if not os.path.exists(apps_folder): - os.makedirs(apps_folder) - - # copy files - for item in ['nrf5.conf', 'flash_nrf51_pca10028.sh', 'flash_nrf52_pca10040.sh', 'Makefile']: - shutil.copyfile(script_path + '/' + item, apps_folder + '/' + item) - - # create src folder - src_folder = apps_folder + "src/" - if not os.path.exists(src_folder): - os.makedirs(src_folder) - - # create Makefile file - with open(src_folder + "Makefile", "wt") as fout: - fout.write(mk_template.replace("EXAMPLE", example).replace("TOOL", script_path).replace("DATE",time.strftime("%c"))) - - # copy port main.c - shutil.copyfile(script_path + '/main.c', src_folder + "/main.c") - - # copy example file - shutil.copyfile(examples_embedded + file, src_folder + "/" + example + ".c") - - # create update_gatt.sh if .gatt file is present - gatt_path = examples_embedded + example + ".gatt" - if os.path.exists(gatt_path): - update_gatt_script = apps_folder + "update_gatt_db.sh" - with open(update_gatt_script, "wt") as fout: - fout.write(gatt_update_template.replace("EXAMPLE", example)) - os.chmod(update_gatt_script, 0o755) - subprocess.call(update_gatt_script + "> /dev/null", shell=True) - print("- %s including compiled GATT DB" % example) - else: - print("- %s" % example) - diff --git a/port/nrf5-zephyr/flash_nrf51_pca10028.sh b/port/nrf5-zephyr/flash_nrf51_pca10028.sh deleted file mode 100755 index d51907f9a..000000000 --- a/port/nrf5-zephyr/flash_nrf51_pca10028.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -nrfjprog --eraseall -f nrf51 -nrfjprog --program outdir/nrf51_pca10028/zephyr.hex -f nrf51 -nrfjprog --reset -f nrf51 diff --git a/port/nrf5-zephyr/flash_nrf52_pca10040.sh b/port/nrf5-zephyr/flash_nrf52_pca10040.sh deleted file mode 100755 index cc2014536..000000000 --- a/port/nrf5-zephyr/flash_nrf52_pca10040.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -nrfjprog --eraseall -f nrf52 -nrfjprog --program outdir/nrf52_pca10040/zephyr.hex -f nrf52 -nrfjprog --reset -f nrf52 diff --git a/port/nrf5-zephyr/integrate_btstack.sh b/port/nrf5-zephyr/integrate_btstack.sh deleted file mode 100755 index 37482ab72..000000000 --- a/port/nrf5-zephyr/integrate_btstack.sh +++ /dev/null @@ -1,51 +0,0 @@ -#/bin/sh - -ZEPHYR_BASE=../../.. - -echo "Integrating BTstack into Zephyr" - -echo "Adding subsys/btstack" - -# add btstack folder to subsys/Makefile -MAKEFILE_ADD_ON='obj-$(CONFIG_BTSTACK) += btstack/' -NET_MAKEFILE=${ZEPHYR_BASE}/subsys/Makefile -grep -q -F btstack ${NET_MAKEFILE} || echo ${MAKEFILE_ADD_ON} >> ${NET_MAKEFILE} - -# add BTstack KConfig to subsys/Kconfig -SUBSYS_KCONFIG=${ZEPHYR_BASE}/subsys/Kconfig -grep -q -F btstack ${SUBSYS_KCONFIG} || echo 'source "subsys/btstack/Kconfig"' >> ${SUBSYS_KCONFIG} - -# create subsys/btstack -mkdir -p ${ZEPHYR_BASE}/subsys/btstack - -# copy sources -rsync -a ../../src/ ${ZEPHYR_BASE}/subsys/btstack - -# copy embedded run loop -rsync -a ../../platform/embedded/hal_cpu.h ${ZEPHYR_BASE}/subsys/btstack -rsync -a ../../platform/embedded/hal_time_ms.h ${ZEPHYR_BASE}/subsys/btstack -rsync -a ../../platform/embedded/hal_tick.h ${ZEPHYR_BASE}/subsys/btstack -rsync -a ../../platform/embedded/btstack_run_loop_embedded.h ${ZEPHYR_BASE}/subsys/btstack -rsync -a ../../platform/embedded/btstack_run_loop_embedded.c ${ZEPHYR_BASE}/subsys/btstack -rsync -a ../../platform/embedded/hci_dump_embedded_stdout.h ${ZEPHYR_BASE}/subsys/btstack -rsync -a ../../platform/embedded/hci_dump_embedded_stdout.c ${ZEPHYR_BASE}/subsys/btstack - -# copy bludroid -rsync -a ../../3rd-party/bluedroid ${ZEPHYR_BASE}/subsys/btstack - -# copy btstack_config.h -rsync -a btstack_config.h ${ZEPHYR_BASE}/subsys/btstack - -# copy Kconfig -rsync -a Kconfig ${ZEPHYR_BASE}/subsys/btstack - -# copy Makefiles -rsync -a Makefile.src ${ZEPHYR_BASE}/subsys/btstack/Makefile -rsync -a Makefile.ble ${ZEPHYR_BASE}/subsys/btstack/ble/Makefile -rsync -a Makefile.gatt-service ${ZEPHYR_BASE}/subsys/btstack/ble/gatt-service/Makefile -rsync -a Makefile.bluedroid ${ZEPHYR_BASE}/subsys/btstack/bluedroid/Makefile -rsync -a Makefile.bluedroid-encoder ${ZEPHYR_BASE}/subsys/btstack/bluedroid/encoder/srce/Makefile -rsync -a Makefile.bluedroid-decoder ${ZEPHYR_BASE}/subsys/btstack/bluedroid/decoder/srce/Makefile - -# create samples/btstack -./create_examples.py diff --git a/port/nrf5-zephyr/main.c b/port/nrf5-zephyr/main.c deleted file mode 100644 index b3428d21c..000000000 --- a/port/nrf5-zephyr/main.c +++ /dev/null @@ -1,301 +0,0 @@ -/* - * Copyright (c) 2016 Nordic Semiconductor ASA - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "ll.h" - -// Nordic NDK -#include "nrf.h" - -#include "common/log.h" - -// BTstack -#include "btstack_debug.h" -#include "btstack_event.h" -#include "btstack_memory.h" -#include "btstack_run_loop.h" -#include "hci.h" -#include "hci_dump.h" -#include "hci_dump_embedded_stdout.h" -#include "hci_transport.h" - -// static struct device *hci_uart_dev; -// static BT_STACK_NOINIT(tx_thread_stack, CONFIG_BT_HCI_TX_STACK_SIZE); -// static struct k_thread tx_thread_data; - -/* HCI command buffers */ -#define CMD_BUF_SIZE BT_BUF_RX_SIZE -NET_BUF_POOL_DEFINE(cmd_tx_pool, CONFIG_BT_HCI_CMD_COUNT, CMD_BUF_SIZE, BT_BUF_USER_DATA_MIN, NULL); - -#if defined(CONFIG_BT_CTLR) -#define BT_L2CAP_MTU (CONFIG_BT_CTLR_TX_BUFFER_SIZE - BT_L2CAP_HDR_SIZE) -#else -#define BT_L2CAP_MTU 65 /* 64-byte public key + opcode */ -#endif /* CONFIG_BT_CTLR */ - -/** Data size needed for ACL buffers */ -#define BT_BUF_ACL_SIZE BT_L2CAP_BUF_SIZE(BT_L2CAP_MTU) - -#if defined(CONFIG_BT_CTLR_TX_BUFFERS) -#define TX_BUF_COUNT CONFIG_BT_CTLR_TX_BUFFERS -#else -#define TX_BUF_COUNT 6 -#endif - -NET_BUF_POOL_DEFINE(acl_tx_pool, TX_BUF_COUNT, BT_BUF_ACL_SIZE, BT_BUF_USER_DATA_MIN, NULL); - -static K_FIFO_DEFINE(tx_queue); -static K_FIFO_DEFINE(rx_queue); - -// -// hci_transport_zephyr.c -// - -static void (*transport_packet_handler)(uint8_t packet_type, uint8_t *packet, uint16_t size); - -/** - * init transport - * @param transport_config - */ -static void transport_init(const void *transport_config){ - /* startup Controller */ - bt_enable_raw(&rx_queue); -} - -/** - * open transport connection - */ -static int transport_open(void){ - return 0; -} - -/** - * close transport connection - */ -static int transport_close(void){ - return 0; -} - -/** - * register packet handler for HCI packets: ACL, SCO, and Events - */ -static void transport_register_packet_handler(void (*handler)(uint8_t packet_type, uint8_t *packet, uint16_t size)){ - transport_packet_handler = handler; -} - -static void send_hardware_error(uint8_t error_code){ - // hci_outgoing_event[0] = HCI_EVENT_HARDWARE_ERROR; - // hci_outgoing_event[1] = 1; - // hci_outgoing_event[2] = error_code; - // hci_outgoing_event_ready = 1; -} - -static int transport_send_packet(uint8_t packet_type, uint8_t *packet, int size){ - struct net_buf *buf; - switch (packet_type){ - case HCI_COMMAND_DATA_PACKET: - buf = net_buf_alloc(&cmd_tx_pool, K_NO_WAIT); - if (buf) { - bt_buf_set_type(buf, BT_BUF_CMD); - memcpy(net_buf_add(buf, size), packet, size); - bt_send(buf); - } else { - log_error("No available command buffers!\n"); - } - break; - case HCI_ACL_DATA_PACKET: - buf = net_buf_alloc(&acl_tx_pool, K_NO_WAIT); - if (buf) { - bt_buf_set_type(buf, BT_BUF_ACL_OUT); - memcpy(net_buf_add(buf, size), packet, size); - bt_send(buf); - } else { - log_error("No available ACL buffers!\n"); - } - break; - default: - send_hardware_error(0x01); // invalid HCI packet - break; - } - - return 0; -} - -static const hci_transport_t transport = { - /* const char * name; */ "nRF5-Zephyr", - /* void (*init) (const void *transport_config); */ &transport_init, - /* int (*open)(void); */ &transport_open, - /* int (*close)(void); */ &transport_close, - /* void (*register_packet_handler)(void (*handler)(...); */ &transport_register_packet_handler, - /* int (*can_send_packet_now)(uint8_t packet_type); */ NULL, - /* int (*send_packet)(...); */ &transport_send_packet, - /* int (*set_baudrate)(uint32_t baudrate); */ NULL, - /* void (*reset_link)(void); */ NULL, -}; - -static const hci_transport_t * transport_get_instance(void){ - return &transport; -} - -static void transport_deliver_controller_packet(struct net_buf * buf){ - uint16_t size = buf->len; - uint8_t * packet = buf->data; - switch (bt_buf_get_type(buf)) { - case BT_BUF_ACL_IN: - transport_packet_handler(HCI_ACL_DATA_PACKET, packet, size); - break; - case BT_BUF_EVT: - transport_packet_handler(HCI_EVENT_PACKET, packet, size); - break; - default: - log_error("Unknown type %u\n", bt_buf_get_type(buf)); - net_buf_unref(buf); - break; - } - net_buf_unref(buf); -} - - -// btstack_run_loop_zephry.c - -// the run loop -static btstack_linked_list_t timers; - -// TODO: handle 32 bit ms time overrun -static uint32_t btstack_run_loop_zephyr_get_time_ms(void){ - return k_uptime_get_32(); -} - -static void btstack_run_loop_zephyr_set_timer(btstack_timer_source_t *ts, uint32_t timeout_in_ms){ - ts->timeout = k_uptime_get_32() + 1 + timeout_in_ms; -} - -/** - * Execute run_loop - */ -static void btstack_run_loop_zephyr_execute(void) { - while (1) { - // process timers - uint32_t now = k_uptime_get_32(); - btstack_run_loop_base_process_timers(now); - - // get time until next timer expires - int32_t timeout_ticks = btstack_run_loop_base_get_time_until_timeout(now); - if (timeout_ticks < 0){ - timeout_ticks = K_FOREVER; - } - - // process RX fifo only - struct net_buf *buf = net_buf_get(&rx_queue, timeout_ticks); - if (buf){ - transport_deliver_controller_packet(buf); - } - } -} - -static void btstack_run_loop_zephyr_btstack_run_loop_init(void){ - btstack_run_loop_base_init(); -} - -static const btstack_run_loop_t btstack_run_loop_wiced = { - &btstack_run_loop_zephyr_btstack_run_loop_init, - NULL, - NULL, - NULL, - NULL, - &btstack_run_loop_zephyr_set_timer, - &btstack_run_loop_base_add_timer, - &btstack_run_loop_base_remove_timer, - &btstack_run_loop_zephyr_execute, - &btstack_run_loop_base_dump_timer, - &btstack_run_loop_zephyr_get_time_ms, -}; -/** - * @brief Provide btstack_run_loop_posix instance for use with btstack_run_loop_init - */ -const btstack_run_loop_t * btstack_run_loop_zephyr_get_instance(void){ - return &btstack_run_loop_wiced; -} - -static btstack_packet_callback_registration_t hci_event_callback_registration; - -static bd_addr_t static_address; - -static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ - if (packet_type != HCI_EVENT_PACKET) return; - if (hci_event_packet_get_type(packet) != BTSTACK_EVENT_STATE) return; - if (btstack_event_state_get_state(packet) != HCI_STATE_WORKING) return; - printf("BTstack up and running as %s.\n", bd_addr_to_str(static_address)); -} - -int btstack_main(void); - -#if defined(CONFIG_BT_CTLR_ASSERT_HANDLER) -void bt_ctlr_assert_handle(char *file, u32_t line) -{ - printf("CONFIG_BT_CTLR_ASSERT_HANDLER: file %s, line %u\n", file, line); - while (1) { - } -} -#endif /* CONFIG_BT_CTLR_ASSERT_HANDLER */ - -void main(void) -{ - // configure console UART by replacing CONFIG_UART_NRF5_BAUD_RATE with 115200 in uart_console.c - - printf("BTstack booting up..\n"); - - // start with BTstack init - especially configure HCI Transport - btstack_memory_init(); - btstack_run_loop_init(btstack_run_loop_zephyr_get_instance()); - - // enable full log output while porting - // hci_dump_init(hci_dump_embedded_stdout_get_instance()); - - // init HCI - hci_init(transport_get_instance(), NULL); - - // nRF5 chipsets don't have an official public address - // Instead, a Static Random Address is assigned during manufacturing - // let's use it as well - big_endian_store_16(static_address, 0, NRF_FICR->DEVICEADDR[1] | 0xc000); - big_endian_store_32(static_address, 2, NRF_FICR->DEVICEADDR[0]); - gap_random_address_set(static_address); - - // inform about BTstack state - hci_event_callback_registration.callback = &packet_handler; - hci_add_event_handler(&hci_event_callback_registration); - - // hand over to btstack embedded code - btstack_main(); - - // go - btstack_run_loop_execute(); - - while (1){}; -} diff --git a/port/nrf5-zephyr/net-Kconfig.patch b/port/nrf5-zephyr/net-Kconfig.patch deleted file mode 100644 index 1353b2f94..000000000 --- a/port/nrf5-zephyr/net-Kconfig.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- Kconfig 2016-11-03 15:27:17.000000000 +0100 -+++ Kconfig-new 2016-11-04 10:59:50.000000000 +0100 -@@ -20,6 +20,8 @@ - - source "net/bluetooth/Kconfig" - -+source "net/btstack/Kconfig" -+ - source "net/ip/Kconfig" - - config NET_BUF diff --git a/port/nrf5-zephyr/nrf5.conf b/port/nrf5-zephyr/nrf5.conf deleted file mode 100644 index e2321582e..000000000 --- a/port/nrf5-zephyr/nrf5.conf +++ /dev/null @@ -1,23 +0,0 @@ -# Debug output -CONFIG_CONSOLE=y -CONFIG_STDOUT_CONSOLE=y -CONFIG_UART_CONSOLE=y -CONFIG_SERIAL=y -CONFIG_UART_NRF5=y -CONFIG_UART_INTERRUPT_DRIVEN=y -CONFIG_UART_NRF5_BAUD_RATE=115200 -CONFIG_UART_DRV_CMD=y - -# Threads stacks -CONFIG_MAIN_STACK_SIZE=2048 -# CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=512 - -# Bluetooth Config -CONFIG_BT=y -CONFIG_BT_HCI_RAW=y -CONFIG_BT_MAX_CONN=16 -CONFIG_BT_CTLR_ASSERT_HANDLER=y -CONFIG_BT_TINYCRYPT_ECC=n -CONFIG_BTSTACK=y - -CONFIG_GPIO=y