Files
MuditaOS/module-bluetooth/Bluetooth/glucode/BluetoothRunLoop.hpp
T
SP2FET 6befeb5073 [EGD-5316] Add Bluetooth run loop integration into worker
To be able to handle properly the Bluetooth stack we need to
get rid of doubled FreeRTOS task and do refactor of
the whole BT section. This is first part of refactor and it
includes integrating run loop into our worker and unifying
namespaces
2021-01-28 12:36:43 +01:00

55 lines
1.9 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
#include <log/log.hpp>
#include "queue.hpp"
#include <btstack_run_loop.h>
#include <timer.hpp>
namespace bluetooth
{
using function_call_t = struct function_call
{
void (*fn)(void *arg);
void *arg;
};
constexpr inline auto RUN_LOOP_QUEUE_LENGTH = 20;
constexpr inline auto RUN_LOOP_QUEUE_ITEM_SIZE = sizeof(function_call_t);
class RunLoop
{
private:
static auto removeTimer(btstack_timer_source_t *ts) -> bool;
static void init();
static void enableDataSourceCallbacks(btstack_data_source_t *ds, uint16_t callback_types);
static void disableDataSourceCallbacks(btstack_data_source_t *ds, uint16_t callback_types);
static void addDataSource(btstack_data_source_t *ds);
static auto removeDataSource(btstack_data_source_t *ds) -> bool;
static void triggerExit();
static auto getTimeMs() -> TickType_t;
static void trigger();
static void executeCodeOnMainThread(void (*fn)(void *arg), void *arg);
static void addTimer(btstack_timer_source_t *ts);
static void setTimer(btstack_timer_source_t *ts, uint32_t timeout_in_ms);
static void start();
static void triggerCallback(TimerHandle_t xTimer);
static QueueHandle_t btstack_run_loop_queue;
static TaskHandle_t btstack_run_loop_task;
static QueueHandle_t triggerQueue;
static TimerHandle_t testTimer;
static btstack_linked_list_t timers;
static btstack_linked_list_t data_sources;
static bool run_loop_exit_requested;
btstack_run_loop runLoop;
public:
auto process() -> bool;
void setTriggerQueue(QueueHandle_t queue);
auto getRunLoopInstance() -> btstack_run_loop *;
};
} // namespace bluetooth