diff options
| author | Jim Mussared | 2019-10-01 23:46:53 +1000 |
|---|---|---|
| committer | Jim Mussared | 2019-10-08 14:40:35 +1100 |
| commit | 902bb4ceae6ca3a8379df35f12ccffc0b492d950 (patch) | |
| tree | 9397e917319b1e09f26dd43ee073b914f74eeb96 /ports | |
| parent | 4a6974bea598a9b76c4a49afcc0d6f82760a7006 (diff) | |
stm32: Extract port-specific Nimble implementation.
On other ports (e.g. ESP32) they provide a complete Nimble implementation
(i.e. we don't need to use the code in extmod/nimble). This change
extracts out the bits that we don't need to use in other ports:
- malloc/free/realloc for Nimble memory.
- pendsv poll handler
- depowering the cywbt
Also cleans up the root pointer management.
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/stm32/Makefile | 1 | ||||
| -rw-r--r-- | ports/stm32/mpconfigport.h | 3 | ||||
| -rw-r--r-- | ports/stm32/nimble.c | 82 |
3 files changed, 85 insertions, 1 deletions
diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile index 40db2f756..1a4e3c690 100644 --- a/ports/stm32/Makefile +++ b/ports/stm32/Makefile @@ -436,6 +436,7 @@ endif ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) include $(TOP)/extmod/nimble/nimble.mk +SRC_C += nimble.c SRC_C += nimble_hci_uart.c EXTMOD_SRC_C += extmod/modbluetooth_nimble.c ifeq ($(MICROPY_PY_NETWORK_CYW43),1) diff --git a/ports/stm32/mpconfigport.h b/ports/stm32/mpconfigport.h index 54e1c503c..580675511 100644 --- a/ports/stm32/mpconfigport.h +++ b/ports/stm32/mpconfigport.h @@ -298,7 +298,8 @@ extern const struct _mp_obj_module_t mp_module_onewire; #endif #if MICROPY_BLUETOOTH_NIMBLE -#define MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE void **bluetooth_nimble_memory; +struct _mp_bluetooth_nimble_root_pointers_t; +#define MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE void **bluetooth_nimble_memory; struct _mp_bluetooth_nimble_root_pointers_t *bluetooth_nimble_root_pointers; #else #define MICROPY_PORT_ROOT_POINTER_BLUETOOTH_NIMBLE #endif diff --git a/ports/stm32/nimble.c b/ports/stm32/nimble.c new file mode 100644 index 000000000..b8fdc8f88 --- /dev/null +++ b/ports/stm32/nimble.c @@ -0,0 +1,82 @@ +/* + * 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. + */ + +#include "py/runtime.h" +#include "py/mperrno.h" +#include "py/mphal.h" + +#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE + +#include "systick.h" +#include "pendsv.h" + +#include "transport/uart/ble_hci_uart.h" +#include "host/ble_hs.h" + +#include "extmod/modbluetooth_nimble.h" + +extern void nimble_uart_process(void); +extern void os_eventq_run_all(void); +extern void os_callout_process(void); + +// Hook for pendsv poller to run this periodically every 128ms +#define NIMBLE_TICK(tick) (((tick) & ~(SYSTICK_DISPATCH_NUM_SLOTS - 1) & 0x7f) == 0) + +void nimble_poll(void) { + if (mp_bluetooth_nimble_ble_state == MP_BLUETOOTH_NIMBLE_BLE_STATE_OFF) { + return; + } + + nimble_uart_process(); + os_callout_process(); + os_eventq_run_all(); +} + +void mod_bluetooth_nimble_poll_wrapper(uint32_t ticks_ms) { + if (NIMBLE_TICK(ticks_ms)) { + pendsv_schedule_dispatch(PENDSV_DISPATCH_NIMBLE, nimble_poll); + } +} + +void mp_bluetooth_nimble_port_preinit(void) { + MP_STATE_PORT(bluetooth_nimble_memory) = NULL; + ble_hci_uart_init(); +} + +void mp_bluetooth_nimble_port_postinit(void) { +} + +void mp_bluetooth_nimble_port_deinit(void) { + #ifdef pyb_pin_BT_REG_ON + mp_hal_pin_low(pyb_pin_BT_REG_ON); + #endif +} + +void mp_bluetooth_nimble_port_start(void) { + ble_hs_start(); +} + +#endif // MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_NIMBLE |
