Skip to content

Commit

Permalink
Update NimBLE core to esp-nimble @94afe27
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Sep 9, 2021
1 parent 679610f commit 26e0130
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 8 deletions.
16 changes: 16 additions & 0 deletions src/nimble/nimble/host/include/host/ble_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,22 @@ int ble_gap_wl_tx_rmv(const ble_addr_t *addrs);
int ble_gap_update_params(uint16_t conn_handle,
const struct ble_gap_upd_params *params);

/**
* Configure LE Data Length in controller (OGF = 0x08, OCF = 0x0022).
*
* @param conn_handle Connection handle.
* @param tx_octets The preferred value of payload octets that the Controller
* should use for a new connection (Range
* 0x001B-0x00FB).
* @param tx_time The preferred maximum number of microseconds that the local Controller
* should use to transmit a single link layer packet
* (Range 0x0148-0x4290).
*
* @return 0 on success,
* other error code on failure.
*/
int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time);

/**
* Initiates the GAP security procedure.
*
Expand Down
10 changes: 5 additions & 5 deletions src/nimble/nimble/host/src/ble_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -2246,11 +2246,6 @@ ble_gap_wl_set(const ble_addr_t *addrs, uint8_t white_list_count)

ble_hs_lock();

if (white_list_count == 0) {
rc = BLE_HS_EINVAL;
goto done;
}

for (i = 0; i < white_list_count; i++) {
if (addrs[i].type != BLE_ADDR_PUBLIC &&
addrs[i].type != BLE_ADDR_RANDOM) {
Expand Down Expand Up @@ -5617,6 +5612,11 @@ ble_gap_update_params(uint16_t conn_handle,
#endif
}

int ble_gap_set_data_len(uint16_t conn_handle, uint16_t tx_octets, uint16_t tx_time)
{
return ble_hs_hci_util_set_data_len(conn_handle, tx_octets, tx_time);
}

/*****************************************************************************
* $security *
*****************************************************************************/
Expand Down
11 changes: 8 additions & 3 deletions src/nimble/porting/npl/freertos/include/nimble/nimble_npl_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ struct ble_npl_eventq {
};

struct ble_npl_callout {
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
esp_timer_handle_t handle;
#else
TimerHandle_t handle;
#endif
struct ble_npl_eventq *evq;
struct ble_npl_event ev;
};
Expand Down Expand Up @@ -221,6 +225,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 void
ble_npl_callout_deinit(struct ble_npl_callout *co)
{
Expand All @@ -236,19 +241,19 @@ ble_npl_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
static inline void
ble_npl_callout_stop(struct ble_npl_callout *co)
{
xTimerStop(co->handle, portMAX_DELAY);
npl_freertos_callout_stop(co);
}

static inline bool
ble_npl_callout_is_active(struct ble_npl_callout *co)
{
return xTimerIsTimerActive(co->handle) == pdTRUE;
return npl_freertos_callout_is_active(co);
}

static inline ble_npl_time_t
ble_npl_callout_get_ticks(struct ble_npl_callout *co)
{
return xTimerGetExpiryTime(co->handle);
return npl_freertos_callout_get_ticks(co);
}

static inline uint32_t
Expand Down
6 changes: 6 additions & 0 deletions src/nimble/porting/npl/freertos/include/nimble/npl_freertos.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ void npl_freertos_callout_init(struct ble_npl_callout *co,

void npl_freertos_callout_deinit(struct ble_npl_callout *co);

void npl_freertos_callout_stop(struct ble_npl_callout *co);

bool npl_freertos_callout_is_active(struct ble_npl_callout *co);

ble_npl_time_t npl_freertos_callout_get_ticks(struct ble_npl_callout *co);

ble_npl_error_t npl_freertos_callout_reset(struct ble_npl_callout *co,
ble_npl_time_t ticks);

Expand Down
97 changes: 97 additions & 0 deletions src/nimble/porting/npl/freertos/src/npl_os_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,38 @@ npl_freertos_sem_release(struct ble_npl_sem *sem)
return BLE_NPL_OK;
}


#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
static void
ble_npl_event_fn_wrapper(void *arg)
{
struct ble_npl_callout *co = (struct ble_npl_callout *)arg;

if (co->evq) {
ble_npl_eventq_put(co->evq, &co->ev);
} else {
co->ev.fn(&co->ev);
}
}

static
ble_npl_error_t esp_err_to_npl_error(esp_err_t err)
{
switch(err) {
case ESP_ERR_INVALID_ARG:
return BLE_NPL_INVALID_PARAM;

case ESP_ERR_INVALID_STATE:
return BLE_NPL_EINVAL;

case ESP_OK:
return BLE_NPL_OK;

default:
return BLE_NPL_ERROR;
}
}
#else
static void
os_callout_timer_cb(TimerHandle_t timer)
{
Expand All @@ -386,30 +418,56 @@ os_callout_timer_cb(TimerHandle_t timer)
co->ev.fn(&co->ev);
}
}
#endif

void
npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq,
ble_npl_event_fn *ev_cb, void *ev_arg)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
co->ev.fn = ev_cb;
co->ev.arg = ev_arg;
co->evq = evq;

esp_timer_create_args_t create_args = {
.callback = ble_npl_event_fn_wrapper,
.arg = co,
.name = "nimble_timer"
};

ESP_ERROR_CHECK(esp_timer_create(&create_args, &co->handle));
#else
if (co->handle == NULL) {
co->handle = xTimerCreate("co", 1, pdFALSE, co, os_callout_timer_cb);
}

co->evq = evq;
ble_npl_event_init(&co->ev, ev_cb, ev_arg);
#endif
}

void
npl_freertos_callout_deinit(struct ble_npl_callout *co)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_timer_stop(co->handle));
ESP_ERROR_CHECK_WITHOUT_ABORT(esp_timer_delete(co->handle));
#else
if (co->handle) {
xTimerDelete(co->handle, portMAX_DELAY);
}
#endif
}

ble_npl_error_t
npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
esp_timer_stop(co->handle);

return esp_err_to_npl_error(esp_timer_start_once(co->handle, ticks*1000));
#else

BaseType_t woken1, woken2, woken3;

if (co->handle == NULL) {
Expand Down Expand Up @@ -439,6 +497,45 @@ npl_freertos_callout_reset(struct ble_npl_callout *co, ble_npl_time_t ticks)
}

return BLE_NPL_OK;
#endif
}

void
npl_freertos_callout_stop(struct ble_npl_callout *co)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
esp_timer_stop(co->handle);
#else
xTimerStop(co->handle, portMAX_DELAY);
#endif
}

bool
npl_freertos_callout_is_active(struct ble_npl_callout *co)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
return esp_timer_is_active(co->handle);
#else
return xTimerIsTimerActive(co->handle) == pdTRUE;
#endif
}

ble_npl_time_t
npl_freertos_callout_get_ticks(struct ble_npl_callout *co)
{
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
/* Currently, esp_timer does not support an API which gets the expiry time for
* current timer.
* Returning 0 from here should not cause any effect.
* Drawback of this approach is that existing code to reset timer would be called
* more often (since the if condition to invoke reset timer would always succeed if
* timer is active).
*/

return 0;
#else
return xTimerGetExpiryTime(co->handle);
#endif
}

ble_npl_time_t
Expand Down

0 comments on commit 26e0130

Please sign in to comment.