micropython: add micropython component
This commit is contained in:
1
components/language/micropython/extmod/nimble/bsp/bsp.h
Normal file
1
components/language/micropython/extmod/nimble/bsp/bsp.h
Normal file
@@ -0,0 +1 @@
|
||||
// empty
|
@@ -0,0 +1 @@
|
||||
// empty
|
128
components/language/micropython/extmod/nimble/hal/hal_uart.c
Normal file
128
components/language/micropython/extmod/nimble/hal/hal_uart.c
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018-2019 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "py/runtime.h"
|
||||
#include "py/mphal.h"
|
||||
#include "nimble/ble.h"
|
||||
#include "extmod/nimble/modbluetooth_nimble.h"
|
||||
#include "extmod/nimble/hal/hal_uart.h"
|
||||
#include "extmod/nimble/nimble/nimble_npl_os.h"
|
||||
#include "extmod/mpbthci.h"
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE
|
||||
|
||||
#ifndef MICROPY_PY_BLUETOOTH_HCI_READ_MODE
|
||||
#define MICROPY_PY_BLUETOOTH_HCI_READ_MODE MICROPY_PY_BLUETOOTH_HCI_READ_MODE_BYTE
|
||||
#endif
|
||||
|
||||
#define HCI_TRACE (0)
|
||||
|
||||
static hal_uart_tx_cb_t hal_uart_tx_cb;
|
||||
static void *hal_uart_tx_arg;
|
||||
static hal_uart_rx_cb_t hal_uart_rx_cb;
|
||||
static void *hal_uart_rx_arg;
|
||||
|
||||
// Provided by the port, and also possibly shared with the driver.
|
||||
extern uint8_t mp_bluetooth_hci_cmd_buf[4 + 256];
|
||||
|
||||
int hal_uart_init_cbs(uint32_t port, hal_uart_tx_cb_t tx_cb, void *tx_arg, hal_uart_rx_cb_t rx_cb, void *rx_arg) {
|
||||
hal_uart_tx_cb = tx_cb;
|
||||
hal_uart_tx_arg = tx_arg;
|
||||
hal_uart_rx_cb = rx_cb;
|
||||
hal_uart_rx_arg = rx_arg;
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
int hal_uart_config(uint32_t port, uint32_t baudrate, uint32_t bits, uint32_t stop, uint32_t parity, uint32_t flow) {
|
||||
return mp_bluetooth_hci_uart_init(port, baudrate);
|
||||
}
|
||||
|
||||
void hal_uart_start_tx(uint32_t port) {
|
||||
size_t len = 0;
|
||||
for (;;) {
|
||||
int data = hal_uart_tx_cb(hal_uart_tx_arg);
|
||||
if (data == -1) {
|
||||
break;
|
||||
}
|
||||
mp_bluetooth_hci_cmd_buf[len++] = data;
|
||||
}
|
||||
|
||||
#if HCI_TRACE
|
||||
printf("< [% 8d] %02x", (int)mp_hal_ticks_ms(), mp_bluetooth_hci_cmd_buf[0]);
|
||||
for (size_t i = 1; i < len; ++i) {
|
||||
printf(":%02x", mp_bluetooth_hci_cmd_buf[i]);
|
||||
}
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
mp_bluetooth_hci_uart_write(mp_bluetooth_hci_cmd_buf, len);
|
||||
|
||||
if (len > 0) {
|
||||
// Allow modbluetooth bindings to hook "sent packet" (e.g. to unstall l2cap channels).
|
||||
mp_bluetooth_nimble_sent_hci_packet();
|
||||
}
|
||||
}
|
||||
|
||||
int hal_uart_close(uint32_t port) {
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
STATIC void mp_bluetooth_hci_uart_char_cb(uint8_t chr) {
|
||||
#if HCI_TRACE
|
||||
printf("> %02x\n", chr);
|
||||
#endif
|
||||
hal_uart_rx_cb(hal_uart_rx_arg, chr);
|
||||
}
|
||||
|
||||
void mp_bluetooth_nimble_hci_uart_process(bool run_events) {
|
||||
bool host_wake = mp_bluetooth_hci_controller_woken();
|
||||
|
||||
for (;;) {
|
||||
#if MICROPY_PY_BLUETOOTH_HCI_READ_MODE == MICROPY_PY_BLUETOOTH_HCI_READ_MODE_BYTE
|
||||
int chr = mp_bluetooth_hci_uart_readchar();
|
||||
if (chr < 0) {
|
||||
break;
|
||||
}
|
||||
mp_bluetooth_hci_uart_char_cb(chr);
|
||||
#elif MICROPY_PY_BLUETOOTH_HCI_READ_MODE == MICROPY_PY_BLUETOOTH_HCI_READ_MODE_PACKET
|
||||
if (mp_bluetooth_hci_uart_readpacket(mp_bluetooth_hci_uart_char_cb) < 0) {
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Incoming data may result in events being enqueued. If we're in
|
||||
// scheduler context then we can run those events immediately.
|
||||
if (run_events) {
|
||||
mp_bluetooth_nimble_os_eventq_run_all();
|
||||
}
|
||||
}
|
||||
|
||||
if (host_wake) {
|
||||
mp_bluetooth_hci_controller_sleep_maybe();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE
|
48
components/language/micropython/extmod/nimble/hal/hal_uart.h
Normal file
48
components/language/micropython/extmod/nimble/hal/hal_uart.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2020 Jim Mussared
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_EXTMOD_NIMBLE_HAL_HAL_UART_H
|
||||
#define MICROPY_INCLUDED_EXTMOD_NIMBLE_HAL_HAL_UART_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define SYSINIT_PANIC_ASSERT_MSG(cond, msg)
|
||||
|
||||
#define HAL_UART_PARITY_NONE (0)
|
||||
|
||||
typedef int (*hal_uart_tx_cb_t)(void *arg);
|
||||
typedef int (*hal_uart_rx_cb_t)(void *arg, uint8_t data);
|
||||
|
||||
// --- Called by NimBLE, implemented in hal_uart.c. ---------------------------
|
||||
int hal_uart_init_cbs(uint32_t port, hal_uart_tx_cb_t tx_cb, void *tx_arg, hal_uart_rx_cb_t rx_cb, void *rx_arg);
|
||||
int hal_uart_config(uint32_t port, uint32_t baud, uint32_t bits, uint32_t stop, uint32_t parity, uint32_t flow);
|
||||
void hal_uart_start_tx(uint32_t port);
|
||||
int hal_uart_close(uint32_t port);
|
||||
|
||||
// --- Called by the MicroPython port when UART data is available -------------
|
||||
void mp_bluetooth_nimble_hci_uart_process(bool run_events);
|
||||
|
||||
#endif // MICROPY_INCLUDED_EXTMOD_NIMBLE_HAL_HAL_UART_H
|
@@ -0,0 +1,45 @@
|
||||
/**
|
||||
* This file was generated by Apache newt version: 1.8.0-dev
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_EXTMOD_NIMBLE_LOGCFG_LOGCFG_H
|
||||
#define MICROPY_INCLUDED_EXTMOD_NIMBLE_LOGCFG_LOGCFG_H
|
||||
|
||||
#include "py/mphal.h"
|
||||
#include "modlog/modlog.h"
|
||||
#include "log_common/log_common.h"
|
||||
|
||||
#define MICROPY_PY_BLUETOOTH_DIAGNOSTIC_LOGGING (1)
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH_DIAGNOSTIC_LOGGING
|
||||
#define DFLT_LOG_DEBUG(...) MODLOG_DEBUG(4, __VA_ARGS__)
|
||||
#else
|
||||
#define DFLT_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH_DIAGNOSTIC_LOGGING > 1
|
||||
#define BLE_HS_LOG_DEBUG(...) MODLOG_DEBUG(4, __VA_ARGS__)
|
||||
#else
|
||||
#define BLE_HS_LOG_DEBUG(...) IGNORE(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#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_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 // MICROPY_INCLUDED_EXTMOD_NIMBLE_LOGCFG_LOGCFG_H
|
1969
components/language/micropython/extmod/nimble/modbluetooth_nimble.c
Normal file
1969
components/language/micropython/extmod/nimble/modbluetooth_nimble.c
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2019 Jim Mussared
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H
|
||||
#define MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H
|
||||
|
||||
#include "extmod/modbluetooth.h"
|
||||
|
||||
#define MP_BLUETOOTH_NIMBLE_MAX_SERVICES (8)
|
||||
|
||||
typedef struct _mp_bluetooth_nimble_root_pointers_t {
|
||||
// Characteristic (and descriptor) value storage.
|
||||
mp_gatts_db_t gatts_db;
|
||||
|
||||
// Pending service definitions.
|
||||
size_t n_services;
|
||||
struct ble_gatt_svc_def *services[MP_BLUETOOTH_NIMBLE_MAX_SERVICES];
|
||||
|
||||
#if MICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS
|
||||
// L2CAP channels.
|
||||
struct _mp_bluetooth_nimble_l2cap_channel_t *l2cap_chan;
|
||||
bool l2cap_listening;
|
||||
#endif
|
||||
} mp_bluetooth_nimble_root_pointers_t;
|
||||
|
||||
enum {
|
||||
MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF,
|
||||
MP_BLUETOOTH_NIMBLE_BLE_STATE_STARTING,
|
||||
MP_BLUETOOTH_NIMBLE_BLE_STATE_WAITING_FOR_SYNC,
|
||||
MP_BLUETOOTH_NIMBLE_BLE_STATE_ACTIVE,
|
||||
MP_BLUETOOTH_NIMBLE_BLE_STATE_STOPPING,
|
||||
};
|
||||
|
||||
extern volatile int mp_bluetooth_nimble_ble_state;
|
||||
|
||||
// --- Optionally provided by the MicroPython port. ---------------------------
|
||||
// (default implementations provided by modbluetooth_nimble.c)
|
||||
|
||||
// Tell the port to init the UART and start the HCI controller.
|
||||
void mp_bluetooth_nimble_port_hci_init(void);
|
||||
|
||||
// Tell the port to deinit the UART and shutdown the HCI controller.
|
||||
void mp_bluetooth_nimble_port_hci_deinit(void);
|
||||
|
||||
// Tell the port to run its background task (i.e. poll the UART and pump events).
|
||||
void mp_bluetooth_nimble_port_start(void);
|
||||
|
||||
// Tell the port to stop its background task.
|
||||
void mp_bluetooth_nimble_port_shutdown(void);
|
||||
|
||||
// --- Called by the HCI UART layer to let us know when packets have been sent.
|
||||
void mp_bluetooth_nimble_sent_hci_packet(void);
|
||||
|
||||
|
||||
#endif // MICROPY_INCLUDED_EXTMOD_NIMBLE_MODBLUETOOTH_NIMBLE_H
|
80
components/language/micropython/extmod/nimble/nimble.cmake
Normal file
80
components/language/micropython/extmod/nimble/nimble.cmake
Normal file
@@ -0,0 +1,80 @@
|
||||
set(NIMBLE_LIB_DIR "${MICROPY_DIR}/lib/mynewt-nimble")
|
||||
set(NIMBLE_EXTMOD_DIR "${MICROPY_DIR}/extmod/nimble")
|
||||
|
||||
add_library(micropy_extmod_nimble INTERFACE)
|
||||
|
||||
target_include_directories(micropy_extmod_nimble INTERFACE
|
||||
${MICROPY_DIR}/
|
||||
${MICROPY_PORT_DIR}/
|
||||
${NIMBLE_EXTMOD_DIR}/
|
||||
${NIMBLE_LIB_DIR}/
|
||||
${NIMBLE_LIB_DIR}/ext/tinycrypt/include
|
||||
${NIMBLE_LIB_DIR}/nimble/host/include
|
||||
${NIMBLE_LIB_DIR}/nimble/host/services/gap/include
|
||||
${NIMBLE_LIB_DIR}/nimble/host/services/gatt/include
|
||||
${NIMBLE_LIB_DIR}/nimble/host/store/ram/include
|
||||
${NIMBLE_LIB_DIR}/nimble/host/util/include
|
||||
${NIMBLE_LIB_DIR}/nimble/include
|
||||
${NIMBLE_LIB_DIR}/nimble/transport/uart/include
|
||||
${NIMBLE_LIB_DIR}/porting/nimble/include
|
||||
)
|
||||
|
||||
target_sources(micropy_extmod_nimble INTERFACE
|
||||
${NIMBLE_EXTMOD_DIR}/hal/hal_uart.c
|
||||
${NIMBLE_EXTMOD_DIR}/nimble/nimble_npl_os.c
|
||||
${NIMBLE_LIB_DIR}/ext/tinycrypt/src/aes_encrypt.c
|
||||
${NIMBLE_LIB_DIR}/ext/tinycrypt/src/cmac_mode.c
|
||||
${NIMBLE_LIB_DIR}/ext/tinycrypt/src/ecc.c
|
||||
${NIMBLE_LIB_DIR}/ext/tinycrypt/src/ecc_dh.c
|
||||
${NIMBLE_LIB_DIR}/ext/tinycrypt/src/utils.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/services/gap/src/ble_svc_gap.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/services/gatt/src/ble_svc_gatt.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_att.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_att_clt.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_att_cmd.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_att_svr.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_eddystone.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_gap.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_gattc.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_gatts.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_adv.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_atomic.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_cfg.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_conn.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_flow.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_hci.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_hci_cmd.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_hci_evt.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_hci_util.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_id.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_log.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_mbuf.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_misc.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_mqueue.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_pvcy.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_startup.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_hs_stop.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_ibeacon.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_l2cap.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_l2cap_coc.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_l2cap_sig.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_l2cap_sig_cmd.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_monitor.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_sm.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_sm_alg.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_sm_cmd.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_sm_lgcy.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_sm_sc.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_store.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_store_util.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/src/ble_uuid.c
|
||||
${NIMBLE_LIB_DIR}/nimble/host/util/src/addr.c
|
||||
${NIMBLE_LIB_DIR}/nimble/transport/uart/src/ble_hci_uart.c
|
||||
${NIMBLE_LIB_DIR}/porting/nimble/src/endian.c
|
||||
${NIMBLE_LIB_DIR}/porting/nimble/src/mem.c
|
||||
${NIMBLE_LIB_DIR}/porting/nimble/src/nimble_port.c
|
||||
${NIMBLE_LIB_DIR}/porting/nimble/src/os_mbuf.c
|
||||
${NIMBLE_LIB_DIR}/porting/nimble/src/os_mempool.c
|
||||
${NIMBLE_LIB_DIR}/porting/nimble/src/os_msys_init.c
|
||||
)
|
120
components/language/micropython/extmod/nimble/nimble.mk
Normal file
120
components/language/micropython/extmod/nimble/nimble.mk
Normal file
@@ -0,0 +1,120 @@
|
||||
# Makefile directives for Apache Mynewt NimBLE component
|
||||
|
||||
ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1)
|
||||
|
||||
EXTMOD_DIR = extmod
|
||||
NIMBLE_EXTMOD_DIR = $(EXTMOD_DIR)/nimble
|
||||
|
||||
EXTMOD_SRC_C += $(NIMBLE_EXTMOD_DIR)/modbluetooth_nimble.c
|
||||
|
||||
CFLAGS_MOD += -DMICROPY_BLUETOOTH_NIMBLE=1
|
||||
|
||||
# Use NimBLE from the submodule in lib/mynewt-nimble by default,
|
||||
# allowing a port to use their own system version (e.g. ESP32).
|
||||
MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY ?= 0
|
||||
|
||||
CFLAGS_MOD += -DMICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY=$(MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY)
|
||||
|
||||
ifeq ($(MICROPY_BLUETOOTH_NIMBLE_BINDINGS_ONLY),0)
|
||||
|
||||
# On all ports where we provide the full implementation (i.e. not just
|
||||
# bindings like on ESP32), then we don't need to use the ringbuffer. In this
|
||||
# case, all NimBLE events are run by the MicroPython scheduler. On Unix, the
|
||||
# scheduler is also responsible for polling the UART, whereas on STM32 the
|
||||
# UART is also polled by the RX IRQ.
|
||||
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS=1
|
||||
|
||||
# Without the ringbuffer, and with the full implementation, we can also
|
||||
# enable pairing and bonding. This requires both synchronous events and
|
||||
# some customisation of the key store.
|
||||
CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_PAIRING_BONDING=1
|
||||
|
||||
NIMBLE_LIB_DIR = lib/mynewt-nimble
|
||||
|
||||
LIB_SRC_C += $(addprefix $(NIMBLE_LIB_DIR)/, \
|
||||
$(addprefix ext/tinycrypt/src/, \
|
||||
aes_encrypt.c \
|
||||
cmac_mode.c \
|
||||
ecc.c \
|
||||
ecc_dh.c \
|
||||
utils.c \
|
||||
) \
|
||||
nimble/host/services/gap/src/ble_svc_gap.c \
|
||||
nimble/host/services/gatt/src/ble_svc_gatt.c \
|
||||
$(addprefix nimble/host/src/, \
|
||||
ble_att.c \
|
||||
ble_att_clt.c \
|
||||
ble_att_cmd.c \
|
||||
ble_att_svr.c \
|
||||
ble_eddystone.c \
|
||||
ble_gap.c \
|
||||
ble_gattc.c \
|
||||
ble_gatts.c \
|
||||
ble_hs_adv.c \
|
||||
ble_hs_atomic.c \
|
||||
ble_hs.c \
|
||||
ble_hs_cfg.c \
|
||||
ble_hs_conn.c \
|
||||
ble_hs_flow.c \
|
||||
ble_hs_hci.c \
|
||||
ble_hs_hci_cmd.c \
|
||||
ble_hs_hci_evt.c \
|
||||
ble_hs_hci_util.c \
|
||||
ble_hs_id.c \
|
||||
ble_hs_log.c \
|
||||
ble_hs_mbuf.c \
|
||||
ble_hs_misc.c \
|
||||
ble_hs_mqueue.c \
|
||||
ble_hs_pvcy.c \
|
||||
ble_hs_startup.c \
|
||||
ble_hs_stop.c \
|
||||
ble_ibeacon.c \
|
||||
ble_l2cap.c \
|
||||
ble_l2cap_coc.c \
|
||||
ble_l2cap_sig.c \
|
||||
ble_l2cap_sig_cmd.c \
|
||||
ble_monitor.c \
|
||||
ble_sm_alg.c \
|
||||
ble_sm.c \
|
||||
ble_sm_cmd.c \
|
||||
ble_sm_lgcy.c \
|
||||
ble_sm_sc.c \
|
||||
ble_store.c \
|
||||
ble_store_util.c \
|
||||
ble_uuid.c \
|
||||
) \
|
||||
nimble/host/util/src/addr.c \
|
||||
nimble/transport/uart/src/ble_hci_uart.c \
|
||||
$(addprefix porting/nimble/src/, \
|
||||
endian.c \
|
||||
mem.c \
|
||||
nimble_port.c \
|
||||
os_mbuf.c \
|
||||
os_mempool.c \
|
||||
os_msys_init.c \
|
||||
) \
|
||||
)
|
||||
# nimble/host/store/ram/src/ble_store_ram.c \
|
||||
|
||||
EXTMOD_SRC_C += $(addprefix $(NIMBLE_EXTMOD_DIR)/, \
|
||||
nimble/nimble_npl_os.c \
|
||||
hal/hal_uart.c \
|
||||
)
|
||||
|
||||
INC += -I$(TOP)/$(NIMBLE_EXTMOD_DIR)
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/ext/tinycrypt/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/nimble/host/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/nimble/host/services/gap/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/nimble/host/services/gatt/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/nimble/host/store/ram/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/nimble/host/util/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/nimble/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/nimble/transport/uart/include
|
||||
INC += -I$(TOP)/$(NIMBLE_LIB_DIR)/porting/nimble/include
|
||||
|
||||
$(BUILD)/$(NIMBLE_LIB_DIR)/%.o: CFLAGS += -Wno-maybe-uninitialized -Wno-pointer-arith -Wno-unused-but-set-variable -Wno-format -Wno-sign-compare -Wno-old-style-declaration
|
||||
|
||||
endif
|
||||
|
||||
endif
|
@@ -0,0 +1,520 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018-2019 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "py/mphal.h"
|
||||
#include "py/runtime.h"
|
||||
#include "nimble/ble.h"
|
||||
#include "nimble/nimble_npl.h"
|
||||
#include "extmod/nimble/hal/hal_uart.h"
|
||||
|
||||
#include "extmod/modbluetooth.h"
|
||||
#include "extmod/nimble/modbluetooth_nimble.h"
|
||||
|
||||
#define DEBUG_OS_printf(...) // printf(__VA_ARGS__)
|
||||
#define DEBUG_MALLOC_printf(...) // printf(__VA_ARGS__)
|
||||
#define DEBUG_EVENT_printf(...) // printf(__VA_ARGS__)
|
||||
#define DEBUG_MUTEX_printf(...) // printf(__VA_ARGS__)
|
||||
#define DEBUG_SEM_printf(...) // printf(__VA_ARGS__)
|
||||
#define DEBUG_CALLOUT_printf(...) // printf(__VA_ARGS__)
|
||||
#define DEBUG_TIME_printf(...) // printf(__VA_ARGS__)
|
||||
#define DEBUG_CRIT_printf(...) // printf(__VA_ARGS__)
|
||||
|
||||
bool ble_npl_os_started(void) {
|
||||
DEBUG_OS_printf("ble_npl_os_started\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
void *ble_npl_get_current_task_id(void) {
|
||||
DEBUG_OS_printf("ble_npl_get_current_task_id\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// malloc
|
||||
|
||||
// Maintain a linked list of heap memory that we've passed to Nimble,
|
||||
// discoverable via the bluetooth_nimble_memory root pointer.
|
||||
|
||||
typedef struct _mp_bluetooth_nimble_malloc_t {
|
||||
struct _mp_bluetooth_nimble_malloc_t *prev;
|
||||
struct _mp_bluetooth_nimble_malloc_t *next;
|
||||
size_t size;
|
||||
uint8_t data[];
|
||||
} mp_bluetooth_nimble_malloc_t;
|
||||
|
||||
// TODO: This is duplicated from mbedtls. Perhaps make this a generic feature?
|
||||
STATIC void *m_malloc_bluetooth(size_t size) {
|
||||
size += sizeof(mp_bluetooth_nimble_malloc_t);
|
||||
mp_bluetooth_nimble_malloc_t *alloc = m_malloc0(size);
|
||||
alloc->size = size;
|
||||
alloc->next = MP_STATE_PORT(bluetooth_nimble_memory);
|
||||
if (alloc->next) {
|
||||
alloc->next->prev = alloc;
|
||||
}
|
||||
MP_STATE_PORT(bluetooth_nimble_memory) = alloc;
|
||||
return alloc->data;
|
||||
}
|
||||
|
||||
STATIC mp_bluetooth_nimble_malloc_t* get_nimble_malloc(void *ptr) {
|
||||
return (mp_bluetooth_nimble_malloc_t*)((uintptr_t)ptr - sizeof(mp_bluetooth_nimble_malloc_t));
|
||||
}
|
||||
|
||||
STATIC void m_free_bluetooth(void *ptr) {
|
||||
mp_bluetooth_nimble_malloc_t *alloc = get_nimble_malloc(ptr);
|
||||
if (alloc->next) {
|
||||
alloc->next->prev = alloc->prev;
|
||||
}
|
||||
if (alloc->prev) {
|
||||
alloc->prev->next = alloc->next;
|
||||
} else {
|
||||
MP_STATE_PORT(bluetooth_nimble_memory) = NULL;
|
||||
}
|
||||
m_free(alloc
|
||||
#if MICROPY_MALLOC_USES_ALLOCATED_SIZE
|
||||
, alloc->size
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
// Check if a nimble ptr is tracked.
|
||||
// If it isn't, that means that it's from a previous soft-reset cycle.
|
||||
STATIC bool is_valid_nimble_malloc(void *ptr) {
|
||||
DEBUG_MALLOC_printf("NIMBLE is_valid_nimble_malloc(%p)\n", ptr);
|
||||
mp_bluetooth_nimble_malloc_t *alloc = MP_STATE_PORT(bluetooth_nimble_memory);
|
||||
while (alloc) {
|
||||
DEBUG_MALLOC_printf("NIMBLE checking: %p\n", alloc->data);
|
||||
if (alloc->data == ptr) {
|
||||
return true;
|
||||
}
|
||||
alloc = alloc->next;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void *nimble_malloc(size_t size) {
|
||||
DEBUG_MALLOC_printf("NIMBLE malloc(%u)\n", (uint)size);
|
||||
void* ptr = m_malloc_bluetooth(size);
|
||||
DEBUG_MALLOC_printf(" --> %p\n", ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Only free if it's still a valid pointer.
|
||||
void nimble_free(void *ptr) {
|
||||
DEBUG_MALLOC_printf("NIMBLE free(%p)\n", ptr);
|
||||
|
||||
if (ptr) {
|
||||
// After a stack re-init, NimBLE has variables in BSS that might be
|
||||
// still pointing to old allocations from a previous init. We can't do
|
||||
// anything about this (e.g. ble_gatts_free_mem is private). But we
|
||||
// can identify that this is a non-null, invalid alloc because it
|
||||
// won't be in our list, so ignore it because it is effectively free'd
|
||||
// anyway (it's not referenced by anything the GC can find).
|
||||
if (is_valid_nimble_malloc(ptr)) {
|
||||
m_free_bluetooth(ptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Only realloc if it's still a valid pointer. Otherwise just malloc.
|
||||
void *nimble_realloc(void *ptr, size_t new_size) {
|
||||
DEBUG_MALLOC_printf("NIMBLE realloc(%p, %u)\n", ptr, (uint)new_size);
|
||||
|
||||
if (!ptr) {
|
||||
return nimble_malloc(new_size);
|
||||
}
|
||||
|
||||
assert(is_valid_nimble_malloc(ptr));
|
||||
|
||||
// Existing alloc is big enough.
|
||||
mp_bluetooth_nimble_malloc_t *alloc = get_nimble_malloc(ptr);
|
||||
size_t old_size = alloc->size - sizeof(mp_bluetooth_nimble_malloc_t);
|
||||
if (old_size >= new_size) {
|
||||
return ptr;
|
||||
}
|
||||
|
||||
// Allocate a new, larger region.
|
||||
void *ptr2 = m_malloc_bluetooth(new_size);
|
||||
|
||||
// Copy old, smaller region into new region.
|
||||
memcpy(ptr2, ptr, old_size);
|
||||
m_free_bluetooth(ptr);
|
||||
|
||||
DEBUG_MALLOC_printf(" --> %p\n", ptr2);
|
||||
|
||||
return ptr2;
|
||||
}
|
||||
|
||||
// No-op implementation (only used by NimBLE logging).
|
||||
int nimble_sprintf(char *str, const char *fmt, ...) {
|
||||
str[0] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// EVENTQ
|
||||
|
||||
struct ble_npl_eventq *global_eventq = NULL;
|
||||
|
||||
// This must not be called recursively or concurrently with the UART handler.
|
||||
void mp_bluetooth_nimble_os_eventq_run_all(void) {
|
||||
if (mp_bluetooth_nimble_ble_state == MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Keep running while there are pending events.
|
||||
while (true) {
|
||||
struct ble_npl_event *ev = NULL;
|
||||
|
||||
os_sr_t sr;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
// Search all queues for an event.
|
||||
for (struct ble_npl_eventq *evq = global_eventq; evq != NULL; evq = evq->nextq) {
|
||||
ev = evq->head;
|
||||
if (ev) {
|
||||
// Remove this event from the queue.
|
||||
evq->head = ev->next;
|
||||
if (ev->next) {
|
||||
ev->next->prev = NULL;
|
||||
ev->next = NULL;
|
||||
}
|
||||
ev->prev = NULL;
|
||||
|
||||
ev->pending = false;
|
||||
|
||||
// Stop searching and execute this event.
|
||||
break;
|
||||
}
|
||||
}
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
|
||||
if (!ev) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Run the event handler.
|
||||
DEBUG_EVENT_printf("event_run(%p)\n", ev);
|
||||
ev->fn(ev);
|
||||
DEBUG_EVENT_printf("event_run(%p) done\n", ev);
|
||||
|
||||
if (ev->pending) {
|
||||
// If this event has been re-enqueued while it was running, then
|
||||
// stop running further events. This prevents an infinite loop
|
||||
// where the reset event re-enqueues itself on HCI timeout.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ble_npl_eventq_init(struct ble_npl_eventq *evq) {
|
||||
DEBUG_EVENT_printf("ble_npl_eventq_init(%p)\n", evq);
|
||||
os_sr_t sr;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
evq->head = NULL;
|
||||
struct ble_npl_eventq **evq2;
|
||||
for (evq2 = &global_eventq; *evq2 != NULL; evq2 = &(*evq2)->nextq) {
|
||||
}
|
||||
*evq2 = evq;
|
||||
evq->nextq = NULL;
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
}
|
||||
|
||||
void ble_npl_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev) {
|
||||
DEBUG_EVENT_printf("ble_npl_eventq_put(%p, %p (%p, %p))\n", evq, ev, ev->fn, ev->arg);
|
||||
os_sr_t sr;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
ev->next = NULL;
|
||||
ev->pending = true;
|
||||
if (evq->head == NULL) {
|
||||
// Empty list, make this the first item.
|
||||
evq->head = ev;
|
||||
ev->prev = NULL;
|
||||
} else {
|
||||
// Find the tail of this list.
|
||||
struct ble_npl_event *tail = evq->head;
|
||||
while (true) {
|
||||
if (tail == ev) {
|
||||
DEBUG_EVENT_printf(" --> already in queue\n");
|
||||
// Already in the list (e.g. a fragmented ACL will enqueue an
|
||||
// event to process it for each fragment).
|
||||
break;
|
||||
}
|
||||
if (tail->next == NULL) {
|
||||
// Found the end of the list, add this event as the tail.
|
||||
tail->next = ev;
|
||||
ev->prev = tail;
|
||||
break;
|
||||
}
|
||||
DEBUG_EVENT_printf(" --> %p\n", tail->next);
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
}
|
||||
|
||||
void ble_npl_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn, void *arg) {
|
||||
DEBUG_EVENT_printf("ble_npl_event_init(%p, %p, %p)\n", ev, fn, arg);
|
||||
ev->fn = fn;
|
||||
ev->arg = arg;
|
||||
ev->next = NULL;
|
||||
ev->pending = false;
|
||||
}
|
||||
|
||||
void *ble_npl_event_get_arg(struct ble_npl_event *ev) {
|
||||
DEBUG_EVENT_printf("ble_npl_event_get_arg(%p) -> %p\n", ev, ev->arg);
|
||||
return ev->arg;
|
||||
}
|
||||
|
||||
void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg) {
|
||||
DEBUG_EVENT_printf("ble_npl_event_set_arg(%p, %p)\n", ev, arg);
|
||||
ev->arg = arg;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// MUTEX
|
||||
|
||||
ble_npl_error_t ble_npl_mutex_init(struct ble_npl_mutex *mu) {
|
||||
DEBUG_MUTEX_printf("ble_npl_mutex_init(%p)\n", mu);
|
||||
mu->locked = 0;
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
ble_npl_error_t ble_npl_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout) {
|
||||
DEBUG_MUTEX_printf("ble_npl_mutex_pend(%p, %u) locked=%u\n", mu, (uint)timeout, (uint)mu->locked);
|
||||
|
||||
// All NimBLE code is executed by the scheduler (and is therefore
|
||||
// implicitly mutexed) so this mutex implementation is a no-op.
|
||||
|
||||
++mu->locked;
|
||||
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
ble_npl_error_t ble_npl_mutex_release(struct ble_npl_mutex *mu) {
|
||||
DEBUG_MUTEX_printf("ble_npl_mutex_release(%p) locked=%u\n", mu, (uint)mu->locked);
|
||||
assert(mu->locked > 0);
|
||||
|
||||
--mu->locked;
|
||||
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// SEM
|
||||
|
||||
ble_npl_error_t ble_npl_sem_init(struct ble_npl_sem *sem, uint16_t tokens) {
|
||||
DEBUG_SEM_printf("ble_npl_sem_init(%p, %u)\n", sem, (uint)tokens);
|
||||
sem->count = tokens;
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
ble_npl_error_t ble_npl_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout) {
|
||||
DEBUG_SEM_printf("ble_npl_sem_pend(%p, %u) count=%u\n", sem, (uint)timeout, (uint)sem->count);
|
||||
|
||||
// This is only called by NimBLE in ble_hs_hci_cmd_tx to synchronously
|
||||
// wait for an HCI ACK. The corresponding ble_npl_sem_release is called
|
||||
// directly by the UART rx handler (i.e. hal_uart_rx_cb in
|
||||
// extmod/nimble/hal/hal_uart.c). So this loop needs to run only the HCI
|
||||
// UART processing but not run any events.
|
||||
|
||||
if (sem->count == 0) {
|
||||
uint32_t t0 = mp_hal_ticks_ms();
|
||||
while (sem->count == 0 && mp_hal_ticks_ms() - t0 < timeout) {
|
||||
if (sem->count != 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
mp_bluetooth_nimble_hci_uart_wfi();
|
||||
}
|
||||
|
||||
if (sem->count == 0) {
|
||||
DEBUG_SEM_printf("ble_npl_sem_pend: semaphore timeout\n");
|
||||
return BLE_NPL_TIMEOUT;
|
||||
}
|
||||
|
||||
DEBUG_SEM_printf("ble_npl_sem_pend: acquired in %u ms\n", (int)(mp_hal_ticks_ms() - t0));
|
||||
}
|
||||
sem->count -= 1;
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
ble_npl_error_t ble_npl_sem_release(struct ble_npl_sem *sem) {
|
||||
DEBUG_SEM_printf("ble_npl_sem_release(%p)\n", sem);
|
||||
sem->count += 1;
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem) {
|
||||
DEBUG_SEM_printf("ble_npl_sem_get_count(%p)\n", sem);
|
||||
return sem->count;
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// CALLOUT
|
||||
|
||||
static struct ble_npl_callout *global_callout = NULL;
|
||||
|
||||
void mp_bluetooth_nimble_os_callout_process(void) {
|
||||
os_sr_t sr;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
uint32_t tnow = mp_hal_ticks_ms();
|
||||
for (struct ble_npl_callout *c = global_callout; c != NULL; c = c->nextc) {
|
||||
if (!c->active) {
|
||||
continue;
|
||||
}
|
||||
if ((int32_t)(tnow - c->ticks) >= 0) {
|
||||
DEBUG_CALLOUT_printf("callout_run(%p) tnow=%u ticks=%u evq=%p\n", c, (uint)tnow, (uint)c->ticks, c->evq);
|
||||
c->active = false;
|
||||
if (c->evq) {
|
||||
// Enqueue this callout for execution in the event queue.
|
||||
ble_npl_eventq_put(c->evq, &c->ev);
|
||||
} else {
|
||||
// Execute this callout directly.
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
c->ev.fn(&c->ev);
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
}
|
||||
DEBUG_CALLOUT_printf("callout_run(%p) done\n", c);
|
||||
}
|
||||
}
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
}
|
||||
|
||||
void ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq, ble_npl_event_fn *ev_cb, void *ev_arg) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_init(%p, %p, %p, %p)\n", c, evq, ev_cb, ev_arg);
|
||||
os_sr_t sr;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
c->active = false;
|
||||
c->ticks = 0;
|
||||
c->evq = evq;
|
||||
ble_npl_event_init(&c->ev, ev_cb, ev_arg);
|
||||
|
||||
struct ble_npl_callout **c2;
|
||||
for (c2 = &global_callout; *c2 != NULL; c2 = &(*c2)->nextc) {
|
||||
if (c == *c2) {
|
||||
// callout already in linked list so don't link it in again
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
*c2 = c;
|
||||
c->nextc = NULL;
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
}
|
||||
|
||||
ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *c, ble_npl_time_t ticks) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_reset(%p, %u) tnow=%u\n", c, (uint)ticks, (uint)mp_hal_ticks_ms());
|
||||
os_sr_t sr;
|
||||
OS_ENTER_CRITICAL(sr);
|
||||
c->active = true;
|
||||
c->ticks = ble_npl_time_get() + ticks;
|
||||
OS_EXIT_CRITICAL(sr);
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
void ble_npl_callout_stop(struct ble_npl_callout *c) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_stop(%p)\n", c);
|
||||
c->active = false;
|
||||
}
|
||||
|
||||
bool ble_npl_callout_is_active(struct ble_npl_callout *c) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_is_active(%p)\n", c);
|
||||
return c->active;
|
||||
}
|
||||
|
||||
ble_npl_time_t ble_npl_callout_get_ticks(struct ble_npl_callout *c) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_get_ticks(%p)\n", c);
|
||||
return c->ticks;
|
||||
}
|
||||
|
||||
ble_npl_time_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *c, ble_npl_time_t now) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_remaining_ticks(%p, %u)\n", c, (uint)now);
|
||||
if (c->ticks > now) {
|
||||
return c->ticks - now;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void *ble_npl_callout_get_arg(struct ble_npl_callout *c) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_get_arg(%p)\n", c);
|
||||
return ble_npl_event_get_arg(&c->ev);
|
||||
}
|
||||
|
||||
void ble_npl_callout_set_arg(struct ble_npl_callout *c, void *arg) {
|
||||
DEBUG_CALLOUT_printf("ble_npl_callout_set_arg(%p, %p)\n", c, arg);
|
||||
ble_npl_event_set_arg(&c->ev, arg);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// TIME
|
||||
|
||||
uint32_t ble_npl_time_get(void) {
|
||||
DEBUG_TIME_printf("ble_npl_time_get -> %u\n", (uint)mp_hal_ticks_ms());
|
||||
return mp_hal_ticks_ms();
|
||||
}
|
||||
|
||||
ble_npl_error_t ble_npl_time_ms_to_ticks(uint32_t ms, ble_npl_time_t *out_ticks) {
|
||||
DEBUG_TIME_printf("ble_npl_time_ms_to_ticks(%u)\n", (uint)ms);
|
||||
*out_ticks = ms;
|
||||
return BLE_NPL_OK;
|
||||
}
|
||||
|
||||
ble_npl_time_t ble_npl_time_ms_to_ticks32(uint32_t ms) {
|
||||
DEBUG_TIME_printf("ble_npl_time_ms_to_ticks32(%u)\n", (uint)ms);
|
||||
return ms;
|
||||
}
|
||||
|
||||
uint32_t ble_npl_time_ticks_to_ms32(ble_npl_time_t ticks) {
|
||||
DEBUG_TIME_printf("ble_npl_time_ticks_to_ms32(%u)\n", (uint)ticks);
|
||||
return ticks;
|
||||
}
|
||||
|
||||
void ble_npl_time_delay(ble_npl_time_t ticks) {
|
||||
mp_hal_delay_ms(ticks + 1);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
// CRITICAL
|
||||
|
||||
// This is used anywhere NimBLE modifies global data structures.
|
||||
|
||||
// Currently all NimBLE code is invoked by the scheduler so there should be no
|
||||
// races, so on STM32 MICROPY_PY_BLUETOOTH_ENTER/MICROPY_PY_BLUETOOTH_EXIT are
|
||||
// no-ops. However, in the future we may wish to make HCI UART processing
|
||||
// happen asynchronously (e.g. on RX IRQ), so the port can implement these
|
||||
// macros accordingly.
|
||||
|
||||
uint32_t ble_npl_hw_enter_critical(void) {
|
||||
DEBUG_CRIT_printf("ble_npl_hw_enter_critical()\n");
|
||||
MICROPY_PY_BLUETOOTH_ENTER
|
||||
return atomic_state;
|
||||
}
|
||||
|
||||
void ble_npl_hw_exit_critical(uint32_t atomic_state) {
|
||||
MICROPY_PY_BLUETOOTH_EXIT
|
||||
DEBUG_CRIT_printf("ble_npl_hw_exit_critical(%u)\n", (uint)atomic_state);
|
||||
}
|
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* This file is part of the MicroPython project, http://micropython.org/
|
||||
*
|
||||
* The MIT License (MIT)
|
||||
*
|
||||
* Copyright (c) 2018-2019 Damien P. George
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef MICROPY_INCLUDED_STM32_NIMBLE_NIMBLE_NIMBLE_NPL_OS_H
|
||||
#define MICROPY_INCLUDED_STM32_NIMBLE_NIMBLE_NIMBLE_NPL_OS_H
|
||||
|
||||
// This is included by nimble/nimble_npl.h -- include that rather than this file directly.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
// --- Configuration of NimBLE data structures --------------------------------
|
||||
|
||||
// This is used at runtime to align allocations correctly.
|
||||
#if __WORDSIZE == 64
|
||||
#define BLE_NPL_OS_ALIGNMENT 8
|
||||
#else
|
||||
#define BLE_NPL_OS_ALIGNMENT 4
|
||||
#endif
|
||||
#define BLE_NPL_TIME_FOREVER (0xffffffff)
|
||||
|
||||
// This is used at compile time to force struct member alignment. See
|
||||
// os_mempool.h for where this is used (none of these three macros are defined
|
||||
// by default).
|
||||
#define OS_CFG_ALIGN_4 (4)
|
||||
#define OS_CFG_ALIGN_8 (8)
|
||||
#if (ULONG_MAX == 0xffffffffffffffff)
|
||||
#define OS_CFG_ALIGNMENT (OS_CFG_ALIGN_8)
|
||||
#else
|
||||
#define OS_CFG_ALIGNMENT (OS_CFG_ALIGN_4)
|
||||
#endif
|
||||
|
||||
typedef uint32_t ble_npl_time_t;
|
||||
typedef int32_t ble_npl_stime_t;
|
||||
|
||||
struct ble_npl_event {
|
||||
ble_npl_event_fn *fn;
|
||||
void *arg;
|
||||
bool pending;
|
||||
struct ble_npl_event *prev;
|
||||
struct ble_npl_event *next;
|
||||
};
|
||||
|
||||
struct ble_npl_eventq {
|
||||
struct ble_npl_event *head;
|
||||
struct ble_npl_eventq *nextq;
|
||||
};
|
||||
|
||||
struct ble_npl_callout {
|
||||
bool active;
|
||||
uint32_t ticks;
|
||||
struct ble_npl_eventq *evq;
|
||||
struct ble_npl_event ev;
|
||||
struct ble_npl_callout *nextc;
|
||||
};
|
||||
|
||||
struct ble_npl_mutex {
|
||||
volatile uint8_t locked;
|
||||
};
|
||||
|
||||
struct ble_npl_sem {
|
||||
volatile uint16_t count;
|
||||
};
|
||||
|
||||
// --- Called by the MicroPython port -----------------------------------------
|
||||
|
||||
void mp_bluetooth_nimble_os_eventq_run_all(void);
|
||||
void mp_bluetooth_nimble_os_callout_process(void);
|
||||
|
||||
// --- Must be provided by the MicroPython port -------------------------------
|
||||
|
||||
void mp_bluetooth_nimble_hci_uart_wfi(void);
|
||||
|
||||
#endif // MICROPY_INCLUDED_STM32_NIMBLE_NIMBLE_NPL_OS_H
|
170
components/language/micropython/extmod/nimble/syscfg/syscfg.h
Normal file
170
components/language/micropython/extmod/nimble/syscfg/syscfg.h
Normal file
@@ -0,0 +1,170 @@
|
||||
#ifndef MICROPY_INCLUDED_EXTMOD_NIMBLE_SYSCFG_H
|
||||
#define MICROPY_INCLUDED_EXTMOD_NIMBLE_SYSCFG_H
|
||||
|
||||
#include "py/mphal.h"
|
||||
|
||||
#include "mpnimbleport.h"
|
||||
|
||||
void *nimble_malloc(size_t size);
|
||||
void nimble_free(void *ptr);
|
||||
void *nimble_realloc(void *ptr, size_t size);
|
||||
|
||||
// Redirect NimBLE malloc to the GC heap.
|
||||
#define malloc(size) nimble_malloc(size)
|
||||
#define free(ptr) nimble_free(ptr)
|
||||
#define realloc(ptr, size) nimble_realloc(ptr, size)
|
||||
|
||||
int nimble_sprintf(char *str, const char *fmt, ...);
|
||||
#define sprintf(str, fmt, ...) nimble_sprintf(str, fmt, __VA_ARGS__)
|
||||
|
||||
#define MYNEWT_VAL(x) MYNEWT_VAL_ ## x
|
||||
|
||||
#define MYNEWT_VAL_LOG_LEVEL (255)
|
||||
|
||||
/*** compiler/arm-none-eabi-m4 */
|
||||
#define MYNEWT_VAL_HARDFLOAT (1)
|
||||
|
||||
/*** kernel/os */
|
||||
#define MYNEWT_VAL_FLOAT_USER (0)
|
||||
#define MYNEWT_VAL_MSYS_1_BLOCK_COUNT (12)
|
||||
#define MYNEWT_VAL_MSYS_1_BLOCK_SIZE (292)
|
||||
#define MYNEWT_VAL_MSYS_2_BLOCK_COUNT (0)
|
||||
#define MYNEWT_VAL_MSYS_2_BLOCK_SIZE (0)
|
||||
#define MYNEWT_VAL_OS_CPUTIME_FREQ (1000000)
|
||||
#define MYNEWT_VAL_OS_CPUTIME_TIMER_NUM (0)
|
||||
#define MYNEWT_VAL_OS_CTX_SW_STACK_CHECK (0)
|
||||
#define MYNEWT_VAL_OS_CTX_SW_STACK_GUARD (4)
|
||||
#define MYNEWT_VAL_OS_MAIN_STACK_SIZE (1024)
|
||||
#define MYNEWT_VAL_OS_MAIN_TASK_PRIO (127)
|
||||
#define MYNEWT_VAL_OS_MEMPOOL_CHECK (0)
|
||||
#define MYNEWT_VAL_OS_MEMPOOL_POISON (0)
|
||||
|
||||
/*** nimble */
|
||||
#define MYNEWT_VAL_BLE_EXT_ADV (0)
|
||||
#define MYNEWT_VAL_BLE_EXT_ADV_MAX_SIZE (31)
|
||||
#define MYNEWT_VAL_BLE_MAX_CONNECTIONS (4)
|
||||
#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (0)
|
||||
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER (1)
|
||||
#define MYNEWT_VAL_BLE_ROLE_CENTRAL (1)
|
||||
#define MYNEWT_VAL_BLE_ROLE_OBSERVER (1)
|
||||
#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL (1)
|
||||
#define MYNEWT_VAL_BLE_WHITELIST (1)
|
||||
|
||||
/*** nimble/host */
|
||||
#define MYNEWT_VAL_BLE_ATT_PREFERRED_MTU (256)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_FIND_INFO (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_FIND_TYPE (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_INDICATE (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_MAX_PREP_ENTRIES (64)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_NOTIFY (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_QUEUED_WRITE_TMO (30000)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_READ (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_READ_BLOB (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_READ_GROUP_TYPE (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_READ_MULT (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_READ_TYPE (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_SIGNED_WRITE (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_WRITE (1)
|
||||
#define MYNEWT_VAL_BLE_ATT_SVR_WRITE_NO_RSP (1)
|
||||
#define MYNEWT_VAL_BLE_GAP_MAX_PENDING_CONN_PARAM_UPDATE (1)
|
||||
#define MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_INDICATE (1)
|
||||
#define MYNEWT_VAL_BLE_GATT_MAX_PROCS (4)
|
||||
#define MYNEWT_VAL_BLE_GATT_NOTIFY (1)
|
||||
#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_READ_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_READ_MAX_ATTRS (8)
|
||||
#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_RESUME_RATE (1000)
|
||||
#define MYNEWT_VAL_BLE_GATT_SIGNED_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_WRITE_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_WRITE_MAX_ATTRS (4)
|
||||
#define MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL)
|
||||
#define MYNEWT_VAL_BLE_HOST (1)
|
||||
#define MYNEWT_VAL_BLE_HS_AUTO_START (1)
|
||||
#define MYNEWT_VAL_BLE_HS_DEBUG (0)
|
||||
#define MYNEWT_VAL_BLE_HS_FLOW_CTRL (0)
|
||||
#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_ITVL (1000)
|
||||
#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_THRESH (2)
|
||||
#define MYNEWT_VAL_BLE_HS_FLOW_CTRL_TX_ON_DISCONNECT (0)
|
||||
#define MYNEWT_VAL_BLE_HS_PHONY_HCI_ACKS (0)
|
||||
#define MYNEWT_VAL_BLE_HS_REQUIRE_OS (1)
|
||||
#define MYNEWT_VAL_BLE_HS_STOP_ON_SHUTDOWN_TIMEOUT (2000)
|
||||
#define MYNEWT_VAL_BLE_L2CAP_COC_MAX_NUM (1)
|
||||
#define MYNEWT_VAL_BLE_L2CAP_COC_MPS (MYNEWT_VAL_MSYS_1_BLOCK_SIZE - 8)
|
||||
#define MYNEWT_VAL_BLE_L2CAP_ENHANCED_COC (0)
|
||||
#define MYNEWT_VAL_BLE_L2CAP_JOIN_RX_FRAGS (1)
|
||||
#define MYNEWT_VAL_BLE_L2CAP_MAX_CHANS (3 * MYNEWT_VAL_BLE_MAX_CONNECTIONS)
|
||||
#define MYNEWT_VAL_BLE_L2CAP_RX_FRAG_TIMEOUT (30000)
|
||||
#define MYNEWT_VAL_BLE_L2CAP_SIG_MAX_PROCS (1)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_CONSOLE_BUFFER_SIZE (128)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_RTT (0)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFERED (1)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_NAME ("monitor")
|
||||
#define MYNEWT_VAL_BLE_MONITOR_RTT_BUFFER_SIZE (256)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_UART (0)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_UART_BAUDRATE (1000000)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_UART_BUFFER_SIZE (64)
|
||||
#define MYNEWT_VAL_BLE_MONITOR_UART_DEV ("uart0")
|
||||
#define MYNEWT_VAL_BLE_RPA_TIMEOUT (300)
|
||||
#define MYNEWT_VAL_BLE_SM_KEYPRESS (0)
|
||||
#define MYNEWT_VAL_BLE_SM_LEGACY (1)
|
||||
#define MYNEWT_VAL_BLE_SM_MAX_PROCS (1)
|
||||
#define MYNEWT_VAL_BLE_SM_OOB_DATA_FLAG (0)
|
||||
#define MYNEWT_VAL_BLE_SM_OUR_KEY_DIST (7)
|
||||
#define MYNEWT_VAL_BLE_SM_THEIR_KEY_DIST (7)
|
||||
#define MYNEWT_VAL_BLE_STORE_MAX_BONDS (3)
|
||||
#define MYNEWT_VAL_BLE_STORE_MAX_CCCDS (8)
|
||||
// These can be overridden at runtime with ble.config(le_secure, mitm, bond, io).
|
||||
#define MYNEWT_VAL_BLE_SM_SC (1)
|
||||
#define MYNEWT_VAL_BLE_SM_MITM (0)
|
||||
#define MYNEWT_VAL_BLE_SM_BONDING (0)
|
||||
#define MYNEWT_VAL_BLE_SM_IO_CAP (BLE_HS_IO_NO_INPUT_OUTPUT)
|
||||
|
||||
/*** nimble/host/services/gap */
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE (0)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_APPEARANCE_WRITE_PERM (-1)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_CENTRAL_ADDRESS_RESOLUTION (-1)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME ("pybd")
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH (31)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_WRITE_PERM (-1)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MAX_CONN_INTERVAL (0)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_MIN_CONN_INTERVAL (0)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SLAVE_LATENCY (0)
|
||||
#define MYNEWT_VAL_BLE_SVC_GAP_PPCP_SUPERVISION_TMO (0)
|
||||
|
||||
/* Overridden by targets/porting-nimble (defined by nimble/transport) */
|
||||
#define MYNEWT_VAL_BLE_HCI_TRANSPORT_NIMBLE_BUILTIN (0)
|
||||
#define MYNEWT_VAL_BLE_HCI_TRANSPORT_RAM (0)
|
||||
#define MYNEWT_VAL_BLE_HCI_TRANSPORT_SOCKET (0)
|
||||
#define MYNEWT_VAL_BLE_HCI_TRANSPORT_UART (1)
|
||||
|
||||
/*** nimble/transport/uart */
|
||||
#define MYNEWT_VAL_BLE_ACL_BUF_COUNT (12)
|
||||
#define MYNEWT_VAL_BLE_ACL_BUF_SIZE (255)
|
||||
#define MYNEWT_VAL_BLE_HCI_ACL_OUT_COUNT (12)
|
||||
#define MYNEWT_VAL_BLE_HCI_EVT_BUF_SIZE (70)
|
||||
#define MYNEWT_VAL_BLE_HCI_EVT_HI_BUF_COUNT (8)
|
||||
#define MYNEWT_VAL_BLE_HCI_EVT_LO_BUF_COUNT (8)
|
||||
|
||||
/* Overridden by targets/porting-nimble (defined by nimble/transport/uart) */
|
||||
#define MYNEWT_VAL_BLE_HCI_UART_BAUD (MICROPY_HW_BLE_UART_BAUDRATE)
|
||||
#define MYNEWT_VAL_BLE_HCI_UART_DATA_BITS (8)
|
||||
#define MYNEWT_VAL_BLE_HCI_UART_FLOW_CTRL (1)
|
||||
#define MYNEWT_VAL_BLE_HCI_UART_PARITY (HAL_UART_PARITY_NONE)
|
||||
#define MYNEWT_VAL_BLE_HCI_UART_PORT (MICROPY_HW_BLE_UART_ID)
|
||||
#define MYNEWT_VAL_BLE_HCI_UART_STOP_BITS (1)
|
||||
|
||||
/* Required for code that uses BLE_HS_LOG */
|
||||
#define MYNEWT_VAL_NEWT_FEATURE_LOGCFG (1)
|
||||
|
||||
#endif // MICROPY_INCLUDED_EXTMOD_NIMBLE_SYSCFG_H
|
Reference in New Issue
Block a user