diff options
author | JF <jf@codingfield.com> | 2020-04-26 10:25:59 +0200 |
---|---|---|
committer | JF <jf@codingfield.com> | 2020-04-26 10:25:59 +0200 |
commit | bdc10744fb338ae197692713a0b48a7ccc36f566 (patch) | |
tree | af7a8f2f16ddd2e5483758effec15c7683f6c453 /src/libs/mynewt-nimble/porting/npl | |
parent | 032fad094c6411ad3ff4321ad61ceed95d7dc4ff (diff) |
Add Nimble in libs directory
Diffstat (limited to 'src/libs/mynewt-nimble/porting/npl')
34 files changed, 5440 insertions, 0 deletions
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; + } +} |