Skip to content
Snippets Groups Projects
Commit 8f2a825b authored by Hauke Petersen's avatar Hauke Petersen
Browse files

pkg/nimble: ipmrove host initialization

parent fa520a09
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ extern "C" {
#endif
/**
* @brief Define the priority used for NimBLE's controller thread
* @brief Priority used for NimBLE's controller thread
*
* This should be as high as possible.
*/
......@@ -33,9 +33,30 @@ extern "C" {
#endif
/**
* @brief Starts a thread running NimBLE's controller
* @brief Stacksize used for NimBLE's controller thread
*/
void nimble_riot_controller_init(void);
#ifndef NIMBLE_CONTROLLER_STACKSIZE
#define NIMBLE_CONTROLLER_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#endif
/**
* @brief Priority used for NimBLE's host thread
*/
#ifndef NIMBLE_HOST_PRIO
#define NIMBLE_HOST_PRIO (THREAD_PRIORITY_MAIN - 2)
#endif
/**
* @brief Stacksize used for NimBLE's host thread
*/
#ifndef NIMBLE_HOST_STACKSIZE
#define NIMBLE_HOST_STACKSIZE (THREAD_STACKSIZE_DEFAULT)
#endif
/**
* @brief Setup and run NimBLE's controller and host threads
*/
void nimble_riot_init(void);
#ifdef __cplusplus
}
......
......@@ -11,7 +11,7 @@
* @{
*
* @file
* @brief Initialization of the nimble controller
* @brief Glue code for running NimBLE for RIOT
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
......@@ -23,24 +23,49 @@
#include "nimble/nimble_port.h"
#include "services/gap/ble_svc_gap.h"
#include "services/gatt/ble_svc_gatt.h"
#ifdef CPU_FAM_NRF52
#include "nrf_clock.h"
#endif
static char stack[THREAD_STACKSIZE_DEFAULT];
static char _stack_controller[NIMBLE_CONTROLLER_STACKSIZE];
static char _stack_host[NIMBLE_HOST_STACKSIZE];
static void *_host_thread(void *arg)
{
(void)arg;
nimble_port_init();
nimble_port_run();
void nimble_riot_controller_init(void)
/* never reached */
return NULL;
}
void nimble_riot_init(void)
{
/* XXX: NimBLE needs the nRF5x's LF clock to run */
#ifdef CPU_FAM_NRF52
clock_start_lf();
#endif
/*
/* Run the controller
*
* Create task where NimBLE LL will run. This one is required as LL has its
* own event queue and should have highest priority.
*/
thread_create(stack, sizeof(stack), NIMBLE_CONTROLLER_PRIO,
thread_create(_stack_controller, sizeof(_stack_controller),
NIMBLE_CONTROLLER_PRIO,
THREAD_CREATE_STACKTEST,
(thread_task_func_t)nimble_port_ll_task_func, NULL,
"nimble_ctrl");
/* and finally initialize and run the host */
thread_create(_stack_host, sizeof(_stack_host),
NIMBLE_HOST_PRIO,
THREAD_CREATE_STACKTEST,
_host_thread, NULL,
"nimble_host");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment