1 /* 2 * This file is part of the MicroPython project, http://micropython.org/ 3 * 4 * The MIT License (MIT) 5 * 6 * Copyright (c) 2018-2019 Damien P. George 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a copy 9 * of this software and associated documentation files (the "Software"), to deal 10 * in the Software without restriction, including without limitation the rights 11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 * copies of the Software, and to permit persons to whom the Software is 13 * furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24 * THE SOFTWARE. 25 */ 26 27 #ifndef MICROPY_INCLUDED_STM32_NIMBLE_NIMBLE_NIMBLE_NPL_OS_H 28 #define MICROPY_INCLUDED_STM32_NIMBLE_NIMBLE_NIMBLE_NPL_OS_H 29 30 // This is included by nimble/nimble_npl.h -- include that rather than this file directly. 31 32 #include <stdint.h> 33 #include <limits.h> 34 35 // --- Configuration of NimBLE data structures -------------------------------- 36 37 // This is used at runtime to align allocations correctly. 38 #define BLE_NPL_OS_ALIGNMENT (sizeof(uintptr_t)) 39 #define BLE_NPL_TIME_FOREVER (0xffffffff) 40 41 // This is used at compile time to force struct member alignment. See 42 // os_mempool.h for where this is used (none of these three macros are defined 43 // by default). 44 #define OS_CFG_ALIGN_4 (4) 45 #define OS_CFG_ALIGN_8 (8) 46 #if (ULONG_MAX == 0xffffffffffffffff) 47 #define OS_CFG_ALIGNMENT (OS_CFG_ALIGN_8) 48 #else 49 #define OS_CFG_ALIGNMENT (OS_CFG_ALIGN_4) 50 #endif 51 52 typedef uint32_t ble_npl_time_t; 53 typedef int32_t ble_npl_stime_t; 54 55 struct ble_npl_event { 56 ble_npl_event_fn *fn; 57 void *arg; 58 bool pending; 59 struct ble_npl_event *prev; 60 struct ble_npl_event *next; 61 }; 62 63 struct ble_npl_eventq { 64 struct ble_npl_event *head; 65 struct ble_npl_eventq *nextq; 66 }; 67 68 struct ble_npl_callout { 69 bool active; 70 uint32_t ticks; 71 struct ble_npl_eventq *evq; 72 struct ble_npl_event ev; 73 struct ble_npl_callout *nextc; 74 }; 75 76 struct ble_npl_mutex { 77 volatile uint8_t locked; 78 }; 79 80 struct ble_npl_sem { 81 volatile uint16_t count; 82 }; 83 84 // --- Called by the MicroPython port ----------------------------------------- 85 86 void mp_bluetooth_nimble_os_eventq_run_all(void); 87 void mp_bluetooth_nimble_os_callout_process(void); 88 89 // --- Must be provided by the MicroPython port ------------------------------- 90 91 void mp_bluetooth_nimble_hci_uart_wfi(void); 92 93 #endif // MICROPY_INCLUDED_STM32_NIMBLE_NIMBLE_NPL_OS_H 94