Skip to content
Snippets Groups Projects
Verified Commit 278df494 authored by schneider's avatar schneider Committed by rahix
Browse files

feat(epicardium): Implement BLE scheduling

parent 78e5b900
No related branches found
No related tags found
1 merge request!47BLE FreeRTOS integration + Demo
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "task.h" #include "task.h"
TaskHandle_t dispatcher_task_id; TaskHandle_t dispatcher_task_id;
TaskHandle_t ble_task_id;
void vBleTask(void*pvParameters); void vBleTask(void*pvParameters);
...@@ -106,13 +105,14 @@ int main(void) ...@@ -106,13 +105,14 @@ int main(void)
abort(); abort();
} }
/* BLE */
if (xTaskCreate( if (xTaskCreate(
vBleTask, vBleTask,
(const char*)"BLE", (const char*)"BLE",
configMINIMAL_STACK_SIZE, configMINIMAL_STACK_SIZE,
NULL, NULL,
tskIDLE_PRIORITY + 3, tskIDLE_PRIORITY + 1,
&ble_task_id NULL
) != pdPASS) { ) != pdPASS) {
printf("Failed to create BLE task!\n"); printf("Failed to create BLE task!\n");
abort(); abort();
......
...@@ -12,9 +12,15 @@ ...@@ -12,9 +12,15 @@
#include "mcr_regs.h" #include "mcr_regs.h"
#include "hci_core.h" #include "hci_core.h"
#include "FreeRTOS.h"
#include "timers.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
/* Task ID for the ble handler */
static TaskHandle_t ble_task_id = NULL;
/* Number of WSF buffer pools */ /* Number of WSF buffer pools */
#define WSF_BUF_POOLS 6 #define WSF_BUF_POOLS 6
...@@ -65,28 +71,19 @@ static void myTrace(const char *pStr, va_list args) ...@@ -65,28 +71,19 @@ static void myTrace(const char *pStr, va_list args)
} }
} }
/*************************************************************************************************/
/*!
* \brief Initialize WSF.
*
* \return None.
*/
/*************************************************************************************************/
static void WsfInit(void) static void WsfInit(void)
{ {
WsfTimerInit(); WsfTimerInit();
WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc); WsfBufInit(sizeof(mainBufMem), (uint8_t*)mainBufMem, WSF_BUF_POOLS, mainPoolDesc);
WsfTraceRegister(myTrace); WsfTraceRegister(myTrace);
} }
void MacInit(void)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlAdvSlaveInit();
LlConnSlaveInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
}
/* TODO: WTF? */ /* TODO: WTF? */
/* /*
* In two-chip solutions, setting the address must wait until the HCI interface is initialized. * In two-chip solutions, setting the address must wait until the HCI interface is initialized.
...@@ -109,6 +106,67 @@ void SetAddress(uint8_t event) ...@@ -109,6 +106,67 @@ void SetAddress(uint8_t event)
} }
} }
/*************************************************************************************************/
/*!
* \brief Initialize MAC layer.
*
* \param None.
*
* \return None.
*/
/*************************************************************************************************/
extern int8_t tx_rfpower_on;
void MacInit(void)
{
wsfHandlerId_t handlerId;
/* Initialize link layer. */
BbInit();
handlerId = WsfOsSetNextHandler(SchHandler);
SchInit(handlerId);
LlAdvSlaveInit();
LlConnSlaveInit();
handlerId = WsfOsSetNextHandler(LlHandler);
LlHandlerInit(handlerId);
}
static StaticTimer_t x;
TimerHandle_t timerWakeup;
int lasttick = 0;
static void vTimerCallback(xTimerHandle pxTimer)
{
bool_t timerRunning;
wsfTimerTicks_t time_to_next_expire;
do {
int tick = xTaskGetTickCount();
WsfTimerUpdate(tick - lasttick);
lasttick = tick;
time_to_next_expire = WsfTimerNextExpiration(&timerRunning);
} while (timerRunning && time_to_next_expire == 0);
if(timerRunning) {
printf("time_to_next_expire = %d\n", time_to_next_expire);
timerWakeup = xTimerCreateStatic(
"timerWakeup", /* name */
pdMS_TO_TICKS(time_to_next_expire), /* period/time */
pdFALSE, /* auto reload */
NULL, /* timer ID */
vTimerCallback, &x); /* callback */
if(timerWakeup != NULL) {
xTimerStart(timerWakeup, 0);
} else {
printf("could not create timer\n");
}
} else {
printf("No timer running\n");
}
}
static void ble_init(void) static void ble_init(void)
...@@ -121,14 +179,23 @@ static void ble_init(void) ...@@ -121,14 +179,23 @@ static void ble_init(void)
/* Register a handler for Application events */ /* Register a handler for Application events */
AppUiActionRegister(SetAddress); AppUiActionRegister(SetAddress);
lasttick = xTaskGetTickCount();
vTimerCallback(NULL);
} }
void vBleTask(void*pvParameters) void vBleTask(void*pvParameters)
{ {
ble_task_id = xTaskGetCurrentTaskHandle();
ble_init(); ble_init();
const TickType_t xDelay = 500 / portTICK_PERIOD_MS;
while (1){ while (1){
// TODO: this need some timing and sleeping // TODO: this need some timing and sleeping
wsfOsDispatcher(); wsfOsDispatcher();
vTimerCallback(NULL);
vTaskDelay( xDelay );
} }
} }
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