Merge pull request #105 from andrzej-kaczmarek/npl-dev

porting: Cleanup and fix NPL
This commit is contained in:
Andrzej Kaczmarek
2018-05-23 18:18:29 +02:00
committed by GitHub
22 changed files with 7899 additions and 93 deletions
+5
View File
@@ -1,3 +1,8 @@
# Dummy NPL build
*.o
/porting/examples/dummy/dummy
# nRF5 SDK build
/porting/examples/freertos_nrf5_sdk/nrf5_sdk
/porting/examples/freertos_nrf5_sdk/pca10040/blank/armgcc/_build/
/porting/examples/freertos_nrf5_sdk/pca10056/blank/armgcc/_build/
+1 -1
View File
@@ -1464,7 +1464,7 @@ ble_ll_conn_hci_wr_auth_pyld_tmo(uint8_t *cmdbuf, uint8_t *rsp, uint8_t *rsplen)
rc = BLE_ERR_INV_HCI_CMD_PARMS;
} else {
connsm->auth_pyld_tmo = tmo;
if (ble_npl_callout_queued(&connsm->auth_pyld_timer)) {
if (ble_npl_callout_is_active(&connsm->auth_pyld_timer)) {
ble_ll_conn_auth_pyld_timer_start(connsm);
}
}
+3 -3
View File
@@ -154,7 +154,7 @@ mesh_adv_thread(void *args)
while (1) {
#if (MYNEWT_VAL(BLE_MESH_PROXY))
ev = ble_npl_eventq_get_tmo(&adv_queue, 0);
ev = ble_npl_eventq_get(&adv_queue, 0);
while (!ev) {
timeout = bt_mesh_proxy_adv_start();
BT_DBG("Proxy Advertising up to %d ms", timeout);
@@ -164,11 +164,11 @@ mesh_adv_thread(void *args)
timeout = ble_npl_time_ms_to_ticks32(timeout);
}
ev = ble_npl_eventq_get_tmo(&adv_queue, timeout);
ev = ble_npl_eventq_get(&adv_queue, timeout);
bt_mesh_proxy_adv_stop();
}
#else
ev = ble_npl_eventq_get(&adv_queue);
ev = ble_npl_eventq_get(&adv_queue, BLE_NPL_TIME_FOREVER);
#endif
if (!ev || !ble_npl_event_get_arg(ev)) {
+1 -1
View File
@@ -309,7 +309,7 @@ k_fifo_is_empty(struct ble_npl_eventq *q)
void * net_buf_get(struct ble_npl_eventq *fifo, s32_t t)
{
struct ble_npl_event *ev = ble_npl_eventq_get_tmo(fifo, 0);
struct ble_npl_event *ev = ble_npl_eventq_get(fifo, 0);
if (ev) {
return ble_npl_event_get_arg(ev);
+1 -1
View File
@@ -430,7 +430,7 @@ ble_hs_timer_sched(int32_t ticks_from_now)
* sooner than the previous expiration time.
*/
abs_time = ble_npl_time_get() + ticks_from_now;
if (!ble_npl_callout_queued(&ble_hs_timer_timer) ||
if (!ble_npl_callout_is_active(&ble_hs_timer_timer) ||
((ble_npl_stime_t)(abs_time -
ble_npl_callout_get_ticks(&ble_hs_timer_timer))) < 0) {
ble_hs_timer_reset(ticks_from_now);
+9 -10
View File
@@ -68,10 +68,8 @@ struct ble_npl_eventq *ble_npl_eventq_dflt_get(void);
void ble_npl_eventq_init(struct ble_npl_eventq *evq);
struct ble_npl_event *ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq,
ble_npl_time_t tmo);
struct ble_npl_event *ble_npl_eventq_get(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);
@@ -89,7 +87,7 @@ void *ble_npl_event_get_arg(struct ble_npl_event *ev);
void ble_npl_event_set_arg(struct ble_npl_event *ev, void *arg);
int ble_npl_eventq_is_empty(struct ble_npl_eventq *evq);
bool ble_npl_eventq_is_empty(struct ble_npl_eventq *evq);
/*
* Mutexes
@@ -122,16 +120,17 @@ uint16_t ble_npl_sem_get_count(struct ble_npl_sem *sem);
void ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
ble_npl_event_fn *ev_cb, void *ev_arg);
int ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks);
ble_npl_error_t ble_npl_callout_reset(struct ble_npl_callout *co,
ble_npl_time_t ticks);
void ble_npl_callout_stop(struct ble_npl_callout *co);
int ble_npl_callout_queued(struct ble_npl_callout *co);
bool ble_npl_callout_is_active(struct ble_npl_callout *co);
uint32_t ble_npl_callout_get_ticks(struct ble_npl_callout *co);
ble_npl_time_t ble_npl_callout_get_ticks(struct ble_npl_callout *co);
uint32_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t time);
ble_npl_time_t ble_npl_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t time);
void ble_npl_callout_set_arg(struct ble_npl_callout *co,
void *arg);
+126
View File
@@ -0,0 +1,126 @@
/*
* 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 <stdbool.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "nimble/nimble_port.h"
#include "host/ble_hs.h"
#include "host/util/util.h"
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
static const char gap_name[] = "FreeRTOS NimBLE";
static uint8_t own_addr_type;
static void start_advertise(void);
static void
put_ad(uint8_t ad_type, uint8_t ad_len, const void *ad, uint8_t *buf,
uint8_t *len)
{
buf[(*len)++] = ad_len + 1;
buf[(*len)++] = ad_type;
memcpy(&buf[*len], ad, ad_len);
*len += ad_len;
}
static void
update_ad(void)
{
uint8_t ad[BLE_HS_ADV_MAX_SZ];
uint8_t ad_len = 0;
uint8_t ad_flags = BLE_HS_ADV_F_DISC_GEN | BLE_HS_ADV_F_BREDR_UNSUP;
put_ad(BLE_HS_ADV_TYPE_FLAGS, 1, &ad_flags, ad, &ad_len);
put_ad(BLE_HS_ADV_TYPE_COMP_NAME, sizeof(gap_name), gap_name, ad, &ad_len);
ble_gap_adv_set_data(ad, ad_len);
}
static int
gap_event_cb(struct ble_gap_event *event, void *arg)
{
switch (event->type) {
case BLE_GAP_EVENT_CONNECT:
if (event->connect.status) {
start_advertise();
}
break;
case BLE_GAP_EVENT_DISCONNECT:
start_advertise();
break;
}
return 0;
}
static void
start_advertise(void)
{
struct ble_gap_adv_params advp;
int rc;
update_ad();
memset(&advp, 0, sizeof advp);
advp.conn_mode = BLE_GAP_CONN_MODE_UND;
advp.disc_mode = BLE_GAP_DISC_MODE_GEN;
rc = ble_gap_adv_start(own_addr_type, NULL, BLE_HS_FOREVER,
&advp, gap_event_cb, NULL);
assert(rc == 0);
}
static void
app_ble_sync_cb(void)
{
int rc;
rc = ble_hs_util_ensure_addr(0);
assert(rc == 0);
rc = ble_hs_id_infer_auto(0, &own_addr_type);
assert(rc == 0);
start_advertise();
}
void
nimble_host_task(void *param)
{
ble_hs_cfg.sync_cb = app_ble_sync_cb;
/* Enable GAP and GATT services */
ble_svc_gap_init();
ble_svc_gatt_init();
ble_svc_gap_device_name_set(gap_name);
while (1) {
ble_npl_eventq_run(ble_npl_eventq_dflt_get());
}
}
@@ -0,0 +1,207 @@
/*
* FreeRTOS Kernel V10.0.0
* Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software. If you wish to use our Amazon
* FreeRTOS name, please do so in a fair use way that does not cause confusion.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
#ifdef SOFTDEVICE_PRESENT
#include "nrf_soc.h"
#endif
#include "app_util_platform.h"
/*-----------------------------------------------------------
* Possible configurations for system timer
*/
#define FREERTOS_USE_RTC 0 /**< Use real time clock for the system */
#define FREERTOS_USE_SYSTICK 1 /**< Use SysTick timer for system */
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#define configTICK_SOURCE FREERTOS_USE_RTC
#define configUSE_PREEMPTION 1
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 1
#define configUSE_TICKLESS_IDLE_SIMPLE_DEBUG 1 /* See into vPortSuppressTicksAndSleep source code for explanation */
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ 1024
#define configMAX_PRIORITIES ( 3 )
#define configMINIMAL_STACK_SIZE ( 60 )
#define configTOTAL_HEAP_SIZE ( 8192 )
#define configMAX_TASK_NAME_LEN ( 4 )
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configUSE_ALTERNATIVE_API 0 /* Deprecated! */
#define configQUEUE_REGISTRY_SIZE 2
#define configUSE_QUEUE_SETS 0
#define configUSE_TIME_SLICING 0
#define configUSE_NEWLIB_REENTRANT 0
#define configENABLE_BACKWARD_COMPATIBILITY 1
/* Hook function related definitions. */
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCHECK_FOR_STACK_OVERFLOW 0
#define configUSE_MALLOC_FAILED_HOOK 0
/* Run time and task stats gathering related definitions. */
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_TRACE_FACILITY 0
#define configUSE_STATS_FORMATTING_FUNCTIONS 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 2 )
#define configTIMER_QUEUE_LENGTH 32
#define configTIMER_TASK_STACK_DEPTH ( 80 )
/* Tickless Idle configuration. */
#define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2
/* Tickless idle/low power functionality. */
/* Define to trap errors during development. */
#if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER)
#define configASSERT( x ) ASSERT(x)
#endif
/* FreeRTOS MPU specific definitions. */
#define configINCLUDE_APPLICATION_DEFINED_PRIVILEGED_FUNCTIONS 1
/* Optional functions - most linkers will remove unused functions anyway. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_xResumeFromISR 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#define INCLUDE_uxTaskGetStackHighWaterMark 1
#define INCLUDE_xTaskGetIdleTaskHandle 1
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
#define INCLUDE_pcTaskGetTaskName 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xEventGroupSetBitFromISR 1
#define INCLUDE_xTimerPendFunctionCall 1
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY _PRIO_APP_HIGH
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY configLIBRARY_LOWEST_INTERRUPT_PRIORITY
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names - or at least those used in the unmodified vector table. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
/*-----------------------------------------------------------
* Settings that are generated automatically
* basing on the settings above
*/
#if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
// do not define configSYSTICK_CLOCK_HZ for SysTick to be configured automatically
// to CPU clock source
#define xPortSysTickHandler SysTick_Handler
#elif (configTICK_SOURCE == FREERTOS_USE_RTC)
#define configSYSTICK_CLOCK_HZ ( 32768UL )
#define xPortSysTickHandler RTC1_IRQHandler
#else
#error Unsupported configTICK_SOURCE value
#endif
/* Code below should be only used by the compiler, and not the assembler. */
#if !(defined(__ASSEMBLY__) || defined(__ASSEMBLER__))
#include "nrf.h"
#include "nrf_assert.h"
/* This part of definitions may be problematic in assembly - it uses definitions from files that are not assembly compatible. */
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#error "This port requires __NVIC_PRIO_BITS to be defined"
#endif
/* Access to current system core clock is required only if we are ticking the system by systimer */
#if (configTICK_SOURCE == FREERTOS_USE_SYSTICK)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif
#endif /* !assembler */
/** Implementation note: Use this with caution and set this to 1 ONLY for debugging
* ----------------------------------------------------------
* Set the value of configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to below for enabling or disabling RTOS tick auto correction:
* 0. This is default. If the RTC tick interrupt is masked for more than 1 tick by higher priority interrupts, then most likely
* one or more RTC ticks are lost. The tick interrupt inside RTOS will detect this and make a correction needed. This is needed
* for the RTOS internal timers to be more accurate.
* 1. The auto correction for RTOS tick is disabled even though few RTC tick interrupts were lost. This feature is desirable when debugging
* the RTOS application and stepping though the code. After stepping when the application is continued in debug mode, the auto-corrections of
* RTOS tick might cause asserts. Setting configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG to 1 will make RTC and RTOS go out of sync but could be
* convenient for debugging.
*/
#define configUSE_DISABLE_TICK_AUTO_CORRECTION_DEBUG 0
#endif /* FREERTOS_CONFIG_H */
File diff suppressed because it is too large Load Diff
+128
View File
@@ -0,0 +1,128 @@
/*
* 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 <stdbool.h>
#include <stdint.h>
#include "FreeRTOS.h"
#include "task.h"
#include "nrf_drv_clock.h"
#include "nimble/nimble_port.h"
static TaskHandle_t nimble_host_task_h;
static TaskHandle_t nimble_ctrl_task_h;
static uint32_t radio_isr_addr;
static uint32_t rng_isr_addr;
static uint32_t rtc0_isr_addr;
/* Some interrupt handlers required for NimBLE radio driver */
void
RADIO_IRQHandler(void)
{
((void (*)(void))radio_isr_addr)();
}
void
RNG_IRQHandler(void)
{
((void (*)(void))rng_isr_addr)();
}
void
RTC0_IRQHandler(void)
{
((void (*)(void))rtc0_isr_addr)();
}
/* This is called by NimBLE radio driver to set interrupt handlers */
void
npl_freertos_hw_set_isr(int irqn, uint32_t addr)
{
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;
}
}
uint32_t
npl_freertos_hw_enter_critical(void)
{
uint32_t ctx = __get_PRIMASK();
__disable_irq();
return (ctx & 0x01);
}
void
npl_freertos_hw_exit_critical(uint32_t ctx)
{
if (!ctx) {
__enable_irq();
}
}
int
main(void)
{
extern void nimble_host_task(void *arg);
ret_code_t err_code;
/* Initialize clock driver for better time accuracy in FREERTOS */
err_code = nrf_drv_clock_init();
APP_ERROR_CHECK(err_code);
/* Initialize NimBLE porting layer */
nimble_port_init();
/*
* 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(nimble_host_task, "nh", configMINIMAL_STACK_SIZE + 400,
NULL, tskIDLE_PRIORITY + 1, &nimble_host_task_h);
/*
* 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, "nc", configMINIMAL_STACK_SIZE + 400,
NULL, configMAX_PRIORITIES - 1, &nimble_ctrl_task_h);
vTaskStartScheduler();
/* We should never reach this code */
assert(0);
while (true) {
}
}
@@ -0,0 +1,187 @@
PROJECT_NAME := nimble_FreeRTOS_pca10040
TARGETS := nrf52832_xxaa
OUTPUT_DIRECTORY := _build
PROJ_DIR := ../../..
SDK_ROOT ?= $(PROJ_DIR)/nrf5_sdk
$(OUTPUT_DIRECTORY)/nrf52832_xxaa.out: \
LINKER_SCRIPT := nimble_FreeRTOS_gcc_nrf52.ld
# Source files common to all targets
SRC_FILES += \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52.S \
$(SDK_ROOT)/components/boards/boards.c \
$(SDK_ROOT)/external/freertos/source/croutine.c \
$(SDK_ROOT)/external/freertos/source/event_groups.c \
$(SDK_ROOT)/external/freertos/source/portable/MemMang/heap_1.c \
$(SDK_ROOT)/external/freertos/source/list.c \
$(SDK_ROOT)/external/freertos/portable/GCC/nrf52/port.c \
$(SDK_ROOT)/external/freertos/portable/CMSIS/nrf52/port_cmsis.c \
$(SDK_ROOT)/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c \
$(SDK_ROOT)/external/freertos/source/queue.c \
$(SDK_ROOT)/external/freertos/source/stream_buffer.c \
$(SDK_ROOT)/external/freertos/source/tasks.c \
$(SDK_ROOT)/external/freertos/source/timers.c \
$(SDK_ROOT)/components/libraries/button/app_button.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/timer/app_timer_freertos.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_nvic.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_soc.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power_clock.c \
$(SDK_ROOT)/components/libraries/bsp/bsp.c \
$(PROJ_DIR)/main.c \
$(PROJ_DIR)/ble.c \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52.c \
# Include folders common to all targets
INC_FOLDERS += \
$(PROJ_DIR)/config \
$(SDK_ROOT)/components \
$(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/components/libraries/experimental_log \
$(PROJ_DIR) \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/external/freertos/source/include \
$(SDK_ROOT)/external/freertos/config \
$(SDK_ROOT)/components/libraries/util \
../config \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/components/libraries/bsp \
$(SDK_ROOT)/components/libraries/button \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/external/freertos/portable/CMSIS/nrf52 \
$(SDK_ROOT)/components/libraries/experimental_log/src \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/components/libraries/experimental_memobj \
$(SDK_ROOT)/external/freertos/portable/GCC/nrf52 \
$(SDK_ROOT)/modules/nrfx/drivers/include \
# Libraries common to all targets
LIB_FILES += \
# Optimization flags
OPT = -Og -g3
# Uncomment the line below to enable link time optimization
#OPT += -flto
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBOARD_PCA10040
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DFREERTOS
CFLAGS += -DNRF52
CFLAGS += -DNRF52832_XXAA
CFLAGS += -DNRF52_PAN_74
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -Wall -Werror
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
# C++ flags common to all targets
CXXFLAGS += $(OPT)
# Assembler flags common to all targets
ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBOARD_PCA10040
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DFREERTOS
ASMFLAGS += -DNRF52
ASMFLAGS += -DNRF52832_XXAA
ASMFLAGS += -DNRF52_PAN_74
# Linker flags
LDFLAGS += $(OPT)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
nrf52832_xxaa: CFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: CFLAGS += -D__STACK_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
nrf52832_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm
# Configure NimBLE variables
NIMBLE_ROOT := $(PROJ_DIR)/../../..
NIMBLE_CFG_CONTROLLER := 1
NIMBLE_CFG_TINYCRYPT := 1
include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs
# Add NimBLE CFLAGS
CFLAGS += $(NIMBLE_CFLAGS)
# Add NPL for FreeRTOS, UART HCI transport for nRF5 SDK and all NimBLE sources
SRC_FILES += \
$(NIMBLE_ROOT)/porting/npl/freertos/src/npl_os_freertos.c \
$(NIMBLE_SRC) \
# Add NPL for FreeRTOS and all NimBLE directories to include paths
INC_FOLDERS += \
$(PROJ_DIR)/include \
$(NIMBLE_ROOT)/porting/npl/freertos/include \
$(NIMBLE_INCLUDE) \
.PHONY: default help
# Default target - first one defined
default: nrf52832_xxaa
# Print all targets that can be built
help:
@echo following targets are available:
@echo nrf52832_xxaa
@echo sdk_config - starting external tool for editing sdk_config.h
@echo flash - flashing binary
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
include $(TEMPLATE_PATH)/Makefile.common
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: flash erase
# Flash the program
flash: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
@echo Flashing: $<
nrfjprog -f nrf52 --program $< --sectorerase
nrfjprog -f nrf52 --reset
erase:
nrfjprog -f nrf52 --eraseall
SDK_CONFIG_FILE := ../config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
sdk_config:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)
@@ -0,0 +1,51 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x80000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x10000
}
SECTIONS
{
}
SECTIONS
{
. = ALIGN(4);
.mem_section_dummy_ram :
{
}
.log_dynamic_data :
{
PROVIDE(__start_log_dynamic_data = .);
KEEP(*(SORT(.log_dynamic_data*)))
PROVIDE(__stop_log_dynamic_data = .);
} > RAM
} INSERT AFTER .data;
SECTIONS
{
.mem_section_dummy_rom :
{
}
.log_const_data :
{
PROVIDE(__start_log_const_data = .);
KEEP(*(SORT(.log_const_data*)))
PROVIDE(__stop_log_const_data = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
} INSERT AFTER .text
INCLUDE "nrf_common.ld"
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,184 @@
PROJECT_NAME := freertos_FreeRTOS_pca10056
TARGETS := nrf52840_xxaa
OUTPUT_DIRECTORY := _build
PROJ_DIR := ../../..
SDK_ROOT ?= $(PROJ_DIR)/nrf5_sdk
$(OUTPUT_DIRECTORY)/nrf52840_xxaa.out: \
LINKER_SCRIPT := nimble_FreeRTOS_gcc_nrf52.ld
# Source files common to all targets
SRC_FILES += \
$(SDK_ROOT)/modules/nrfx/mdk/gcc_startup_nrf52840.S \
$(SDK_ROOT)/components/boards/boards.c \
$(SDK_ROOT)/external/freertos/source/croutine.c \
$(SDK_ROOT)/external/freertos/source/event_groups.c \
$(SDK_ROOT)/external/freertos/source/portable/MemMang/heap_1.c \
$(SDK_ROOT)/external/freertos/source/list.c \
$(SDK_ROOT)/external/freertos/portable/GCC/nrf52/port.c \
$(SDK_ROOT)/external/freertos/portable/CMSIS/nrf52/port_cmsis.c \
$(SDK_ROOT)/external/freertos/portable/CMSIS/nrf52/port_cmsis_systick.c \
$(SDK_ROOT)/external/freertos/source/queue.c \
$(SDK_ROOT)/external/freertos/source/stream_buffer.c \
$(SDK_ROOT)/external/freertos/source/tasks.c \
$(SDK_ROOT)/external/freertos/source/timers.c \
$(SDK_ROOT)/components/libraries/button/app_button.c \
$(SDK_ROOT)/components/libraries/util/app_error.c \
$(SDK_ROOT)/components/libraries/util/app_error_handler_gcc.c \
$(SDK_ROOT)/components/libraries/util/app_error_weak.c \
$(SDK_ROOT)/components/libraries/timer/app_timer_freertos.c \
$(SDK_ROOT)/components/libraries/util/app_util_platform.c \
$(SDK_ROOT)/components/libraries/util/nrf_assert.c \
$(SDK_ROOT)/components/libraries/strerror/nrf_strerror.c \
$(SDK_ROOT)/integration/nrfx/legacy/nrf_drv_clock.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_nvic.c \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd/nrf_soc.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_clock.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_gpiote.c \
$(SDK_ROOT)/modules/nrfx/drivers/src/nrfx_power_clock.c \
$(SDK_ROOT)/components/libraries/bsp/bsp.c \
$(PROJ_DIR)/main.c \
$(PROJ_DIR)/ble.c \
$(SDK_ROOT)/modules/nrfx/mdk/system_nrf52840.c \
# Include folders common to all targets
INC_FOLDERS += \
$(PROJ_DIR)/config \
$(SDK_ROOT)/components \
$(SDK_ROOT)/modules/nrfx/mdk \
$(SDK_ROOT)/components/libraries/experimental_log \
$(PROJ_DIR) \
$(SDK_ROOT)/components/libraries/timer \
$(SDK_ROOT)/components/libraries/strerror \
$(SDK_ROOT)/components/toolchain/cmsis/include \
$(SDK_ROOT)/external/freertos/source/include \
$(SDK_ROOT)/external/freertos/config \
$(SDK_ROOT)/components/libraries/util \
../config \
$(SDK_ROOT)/components/libraries/balloc \
$(SDK_ROOT)/modules/nrfx/hal \
$(SDK_ROOT)/components/libraries/bsp \
$(SDK_ROOT)/components/libraries/button \
$(SDK_ROOT)/modules/nrfx \
$(SDK_ROOT)/components/libraries/experimental_section_vars \
$(SDK_ROOT)/integration/nrfx/legacy \
$(SDK_ROOT)/external/freertos/portable/CMSIS/nrf52 \
$(SDK_ROOT)/components/libraries/experimental_log/src \
$(SDK_ROOT)/integration/nrfx \
$(SDK_ROOT)/components/drivers_nrf/nrf_soc_nosd \
$(SDK_ROOT)/components/boards \
$(SDK_ROOT)/components/libraries/experimental_memobj \
$(SDK_ROOT)/external/freertos/portable/GCC/nrf52 \
$(SDK_ROOT)/modules/nrfx/drivers/include \
# Libraries common to all targets
LIB_FILES += \
# Optimization flags
OPT = -Og -g3
# Uncomment the line below to enable link time optimization
#OPT += -flto
# C flags common to all targets
CFLAGS += $(OPT)
CFLAGS += -DBOARD_PCA10056
CFLAGS += -DCONFIG_GPIO_AS_PINRESET
CFLAGS += -DFLOAT_ABI_HARD
CFLAGS += -DFREERTOS
CFLAGS += -DNRF52840_XXAA
CFLAGS += -mcpu=cortex-m4
CFLAGS += -mthumb -mabi=aapcs
CFLAGS += -Wall -Werror
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# keep every function in a separate section, this allows linker to discard unused ones
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin -fshort-enums
# C++ flags common to all targets
CXXFLAGS += $(OPT)
# Assembler flags common to all targets
ASMFLAGS += -g3
ASMFLAGS += -mcpu=cortex-m4
ASMFLAGS += -mthumb -mabi=aapcs
ASMFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
ASMFLAGS += -DBOARD_PCA10056
ASMFLAGS += -DCONFIG_GPIO_AS_PINRESET
ASMFLAGS += -DFLOAT_ABI_HARD
ASMFLAGS += -DFREERTOS
ASMFLAGS += -DNRF52840_XXAA
# Linker flags
LDFLAGS += $(OPT)
LDFLAGS += -mthumb -mabi=aapcs -L$(SDK_ROOT)/modules/nrfx/mdk -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m4
LDFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
# let linker dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
LDFLAGS += --specs=nano.specs
nrf52840_xxaa: CFLAGS += -D__HEAP_SIZE=8192
nrf52840_xxaa: CFLAGS += -D__STACK_SIZE=8192
nrf52840_xxaa: ASMFLAGS += -D__HEAP_SIZE=8192
nrf52840_xxaa: ASMFLAGS += -D__STACK_SIZE=8192
# Add standard libraries at the very end of the linker input, after all objects
# that may need symbols provided by these libraries.
LIB_FILES += -lc -lnosys -lm
# Configure NimBLE variables
NIMBLE_ROOT := $(PROJ_DIR)/../../..
NIMBLE_CFG_CONTROLLER := 1
NIMBLE_CFG_TINYCRYPT := 1
include $(NIMBLE_ROOT)/porting/nimble/Makefile.defs
# Add NimBLE CFLAGS
CFLAGS += $(NIMBLE_CFLAGS)
# Add NPL for FreeRTOS, UART HCI transport for nRF5 SDK and all NimBLE sources
SRC_FILES += \
$(NIMBLE_ROOT)/porting/npl/freertos/src/npl_os_freertos.c \
$(NIMBLE_SRC) \
# Add NPL for FreeRTOS and all NimBLE directories to include paths
INC_FOLDERS += \
$(PROJ_DIR)/include \
$(NIMBLE_ROOT)/porting/npl/freertos/include \
$(NIMBLE_INCLUDE) \
.PHONY: default help
# Default target - first one defined
default: nrf52840_xxaa
# Print all targets that can be built
help:
@echo following targets are available:
@echo nrf52840_xxaa
@echo sdk_config - starting external tool for editing sdk_config.h
@echo flash - flashing binary
TEMPLATE_PATH := $(SDK_ROOT)/components/toolchain/gcc
include $(TEMPLATE_PATH)/Makefile.common
$(foreach target, $(TARGETS), $(call define_target, $(target)))
.PHONY: flash erase
# Flash the program
flash: $(OUTPUT_DIRECTORY)/nrf52840_xxaa.hex
@echo Flashing: $<
nrfjprog -f nrf52 --program $< --sectorerase
nrfjprog -f nrf52 --reset
erase:
nrfjprog -f nrf52 --eraseall
SDK_CONFIG_FILE := ../config/sdk_config.h
CMSIS_CONFIG_TOOL := $(SDK_ROOT)/external_tools/cmsisconfig/CMSIS_Configuration_Wizard.jar
sdk_config:
java -jar $(CMSIS_CONFIG_TOOL) $(SDK_CONFIG_FILE)
@@ -0,0 +1,51 @@
/* Linker script to configure memory regions. */
SEARCH_DIR(.)
GROUP(-lgcc -lc -lnosys)
MEMORY
{
FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x100000
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x40000
}
SECTIONS
{
}
SECTIONS
{
. = ALIGN(4);
.mem_section_dummy_ram :
{
}
.log_dynamic_data :
{
PROVIDE(__start_log_dynamic_data = .);
KEEP(*(SORT(.log_dynamic_data*)))
PROVIDE(__stop_log_dynamic_data = .);
} > RAM
} INSERT AFTER .data;
SECTIONS
{
.mem_section_dummy_rom :
{
}
.log_const_data :
{
PROVIDE(__start_log_const_data = .);
KEEP(*(SORT(.log_const_data*)))
PROVIDE(__stop_log_const_data = .);
} > FLASH
.nrf_balloc :
{
PROVIDE(__start_nrf_balloc = .);
KEEP(*(.nrf_balloc))
PROVIDE(__stop_nrf_balloc = .);
} > FLASH
} INSERT AFTER .text
INCLUDE "nrf_common.ld"
File diff suppressed because it is too large Load Diff
-14
View File
@@ -24,12 +24,6 @@
#if NIMBLE_CFG_CONTROLLER
#include "controller/ble_ll.h"
#endif
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
#include "services/ans/ble_svc_ans.h"
#include "services/ias/ble_svc_ias.h"
#include "services/lls/ble_svc_lls.h"
#include "services/tps/ble_svc_tps.h"
void
nimble_port_init(void)
@@ -44,14 +38,6 @@ nimble_port_init(void)
ble_hs_init();
/* XXX These should be configurable somehow */
ble_svc_gap_init();
ble_svc_gatt_init();
ble_svc_ans_init();
ble_svc_ias_init();
ble_svc_lls_init();
ble_svc_tps_init();
/* XXX Need to have template for store */
ble_store_ram_init();
+4 -4
View File
@@ -134,7 +134,7 @@ ble_npl_callout_init(struct ble_npl_callout *c, struct ble_npl_eventq *evq,
{
}
int
ble_npl_error_t
ble_npl_callout_reset(struct ble_npl_callout *c, ble_npl_time_t ticks)
{
return BLE_NPL_ENOENT;
@@ -146,10 +146,10 @@ ble_npl_callout_stop(struct ble_npl_callout *co)
}
int
ble_npl_callout_queued(struct ble_npl_callout *c)
bool
ble_npl_callout_is_active(struct ble_npl_callout *c)
{
return 0;
return false;
}
ble_npl_time_t
@@ -100,15 +100,9 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
}
static inline struct ble_npl_event *
ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
{
return npl_freertos_eventq_get_tmo(evq, tmo);
}
static inline struct ble_npl_event *
ble_npl_eventq_get(struct ble_npl_eventq *evq)
{
return npl_freertos_eventq_get(evq);
return npl_freertos_eventq_get(evq, tmo);
}
static inline void
@@ -128,13 +122,13 @@ ble_npl_eventq_run(struct ble_npl_eventq *evq)
{
struct ble_npl_event *ev;
ev = ble_npl_eventq_get(evq);
ev = ble_npl_eventq_get(evq, BLE_NPL_TIME_FOREVER);
assert(ev->fn != NULL);
ev->fn(ev);
}
static inline int
static inline bool
ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
{
return xQueueIsQueueEmptyFromISR(evq->q);
@@ -216,7 +210,7 @@ ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
npl_freertos_callout_init(co, evq, ev_cb, ev_arg);
}
static inline int
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);
@@ -228,8 +222,8 @@ ble_npl_callout_stop(struct ble_npl_callout *co)
xTimerStop(co->handle, portMAX_DELAY);
}
static inline int
ble_npl_callout_queued(struct ble_npl_callout *co)
static inline bool
ble_npl_callout_is_active(struct ble_npl_callout *co)
{
return xTimerIsTimerActive(co->handle) == pdTRUE;
}
@@ -26,9 +26,8 @@ extern "C" {
struct ble_npl_eventq *npl_freertos_eventq_dflt_get(void);
struct ble_npl_event *npl_freertos_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo);
struct ble_npl_event *npl_freertos_eventq_get(struct ble_npl_eventq *evq);
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);
@@ -54,8 +53,8 @@ void npl_freertos_callout_init(struct ble_npl_callout *co,
struct ble_npl_eventq *evq,
ble_npl_event_fn *ev_cb, void *ev_arg);
int npl_freertos_callout_reset(struct ble_npl_callout *co,
ble_npl_time_t ticks);
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);
+31 -30
View File
@@ -42,12 +42,19 @@ npl_freertos_eventq_dflt_get(void)
}
struct ble_npl_event *
npl_freertos_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
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;
ret = xQueueReceive(evq->q, &ev, tmo);
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) {
@@ -57,15 +64,10 @@ npl_freertos_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
return ev;
}
struct ble_npl_event *
npl_freertos_eventq_get(struct ble_npl_eventq *evq)
{
return npl_freertos_eventq_get_tmo(evq, portMAX_DELAY);
}
void
npl_freertos_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
{
BaseType_t woken;
BaseType_t ret;
if (ev->queued) {
@@ -74,7 +76,13 @@ npl_freertos_eventq_put(struct ble_npl_eventq *evq, struct ble_npl_event *ev)
ev->queued = true;
ret = xQueueSendToBack(evq->q, &ev, 0);
if (in_isr()) {
ret = xQueueSendToBackFromISR(evq->q, &ev, &woken);
portYIELD_FROM_ISR(woken);
} else {
ret = xQueueSendToBack(evq->q, &ev, portMAX_DELAY);
}
assert(ret == pdPASS);
}
@@ -134,6 +142,8 @@ 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)
{
BaseType_t ret;
if (!mu) {
return BLE_NPL_INVALID_PARAM;
}
@@ -141,14 +151,13 @@ npl_freertos_mutex_pend(struct ble_npl_mutex *mu, ble_npl_time_t timeout)
assert(mu->handle);
if (in_isr()) {
ret = pdFAIL;
assert(0);
} else {
if (xSemaphoreTakeRecursive(mu->handle, timeout) != pdPASS) {
return BLE_NPL_TIMEOUT;
}
ret = xSemaphoreTakeRecursive(mu->handle, timeout);
}
return BLE_NPL_OK;
return ret == pdPASS ? BLE_NPL_OK : BLE_NPL_TIMEOUT;
}
ble_npl_error_t
@@ -188,6 +197,7 @@ 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;
@@ -197,18 +207,13 @@ npl_freertos_sem_pend(struct ble_npl_sem *sem, ble_npl_time_t timeout)
if (in_isr()) {
assert(timeout == 0);
if (xSemaphoreTakeFromISR(sem->handle, &woken) != pdPASS) {
portYIELD_FROM_ISR(woken);
return BLE_NPL_TIMEOUT;
}
ret = xSemaphoreTakeFromISR(sem->handle, &woken);
portYIELD_FROM_ISR(woken);
} else {
if (xSemaphoreTake(sem->handle, timeout) != pdPASS) {
return BLE_NPL_TIMEOUT;
}
ret = xSemaphoreTake(sem->handle, timeout);
}
return BLE_NPL_OK;
return ret == pdPASS ? BLE_NPL_OK : BLE_NPL_TIMEOUT;
}
ble_npl_error_t
@@ -225,14 +230,12 @@ npl_freertos_sem_release(struct ble_npl_sem *sem)
if (in_isr()) {
ret = xSemaphoreGiveFromISR(sem->handle, &woken);
assert(ret == pdPASS);
portYIELD_FROM_ISR(woken);
} else {
ret = xSemaphoreGive(sem->handle);
assert(ret == pdPASS);
}
assert(ret == pdPASS);
return BLE_NPL_OK;
}
@@ -261,7 +264,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
ble_npl_event_init(&co->ev, ev_cb, ev_arg);
}
int
ble_npl_error_t
npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
{
BaseType_t woken1, woken2, woken3;
@@ -294,18 +297,16 @@ npl_freertos_callout_remaining_ticks(struct ble_npl_callout *co,
ble_npl_time_t now)
{
ble_npl_time_t rt;
uint32_t exp = xTimerGetExpiryTime(co->handle);
uint32_t exp;
taskENTER_CRITICAL();
exp = xTimerGetExpiryTime(co->handle);
if (exp > now) {
rt = exp - now;
} else {
return 0;
rt = 0;
}
taskEXIT_CRITICAL();
return rt;
}
@@ -83,15 +83,17 @@ ble_npl_eventq_init(struct ble_npl_eventq *evq)
}
static inline struct ble_npl_event *
ble_npl_eventq_get_tmo(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
ble_npl_eventq_get(struct ble_npl_eventq *evq, ble_npl_time_t tmo)
{
return (struct ble_npl_event *)os_eventq_poll((struct os_eventq **)&evq, 1, tmo);
}
struct os_event *ev;
static inline struct ble_npl_event *
ble_npl_eventq_get(struct ble_npl_eventq *evq)
{
return (struct ble_npl_event *)os_eventq_get(&evq->evq);
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
@@ -113,7 +115,7 @@ ble_npl_eventq_run(struct ble_npl_eventq *evq)
os_eventq_run(&evq->evq);
}
static inline int
static inline bool
ble_npl_eventq_is_empty(struct ble_npl_eventq *evq)
{
return STAILQ_EMPTY(&evq->evq.evq_list);
@@ -196,7 +198,7 @@ ble_npl_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
os_callout_init(&co->co, &evq->evq, (os_event_fn *)ev_cb, ev_arg);
}
static inline int
static inline ble_npl_error_t
ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
{
return os_callout_reset(&co->co, ticks);
@@ -208,8 +210,8 @@ ble_npl_callout_stop(struct ble_npl_callout *co)
os_callout_stop(&co->co);
}
static inline int
ble_npl_callout_queued(struct ble_npl_callout *co)
static inline bool
ble_npl_callout_is_active(struct ble_npl_callout *co)
{
return os_callout_queued(&co->co);
}