mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
FurEventLoop: add support for FuriEventFlag, simplify API (#3958)
* Core: event_flag, removing duplicate code * event_loop: add support furi_event_flags * Examples: add missing free in event loop examples * Furi: fix event flag * Sync api symbols * Unit_test: evet_loop_event_flags * Fix multiple waiting list elements handling * Unit_test: add event_loop_event_flag test * FURI: event_loop add restrictions * Fix multiple waiting lists items for good * Improve FuriEventLoop unit tests * Abolish callback return value * Remove return value from callback signature * Use bool level value instead of int32_t * Add unit tests for FuriStreamBuffer * Add unit tests for FuriSemaphore * Speed up test execution * Improve docs * Add a stub for furi os-level primitives * Add more checks for edge cases * Allow event loop notification from ISR * Bump api version Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com> Co-authored-by: Georgii Surkov <georgii.surkov@outlook.com> Co-authored-by: Georgii Surkov <37121527+gsurkov@users.noreply.github.com>
This commit is contained in:
@@ -82,7 +82,7 @@ static void view_port_input_callback(InputEvent* input_event, void* context) {
|
||||
furi_message_queue_put(app->input_queue, input_event, 0);
|
||||
}
|
||||
|
||||
static bool input_queue_callback(FuriEventLoopObject* object, void* context) {
|
||||
static void input_queue_callback(FuriEventLoopObject* object, void* context) {
|
||||
FuriMessageQueue* queue = object;
|
||||
EventLoopBlinkTestApp* app = context;
|
||||
|
||||
@@ -107,8 +107,6 @@ static bool input_queue_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_event_loop_stop(app->event_loop);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void blink_timer_callback(void* context) {
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
#include "../test.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#define TAG "TestFuriEventLoop"
|
||||
|
||||
#define EVENT_LOOP_EVENT_COUNT (256u)
|
||||
|
||||
typedef struct {
|
||||
FuriMessageQueue* mq;
|
||||
|
||||
FuriEventLoop* producer_event_loop;
|
||||
uint32_t producer_counter;
|
||||
|
||||
FuriEventLoop* consumer_event_loop;
|
||||
uint32_t consumer_counter;
|
||||
} TestFuriData;
|
||||
|
||||
bool test_furi_event_loop_producer_mq_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriData* data = context;
|
||||
furi_check(data->mq == object, "Invalid queue");
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG, "producer_mq_callback: %lu %lu", data->producer_counter, data->consumer_counter);
|
||||
|
||||
if(data->producer_counter == EVENT_LOOP_EVENT_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(data->producer_event_loop, data->mq);
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->producer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_mq_callback,
|
||||
data);
|
||||
}
|
||||
|
||||
if(data->producer_counter == EVENT_LOOP_EVENT_COUNT) {
|
||||
furi_event_loop_stop(data->producer_event_loop);
|
||||
return false;
|
||||
}
|
||||
|
||||
data->producer_counter++;
|
||||
furi_check(
|
||||
furi_message_queue_put(data->mq, &data->producer_counter, 0) == FuriStatusOk,
|
||||
"furi_message_queue_put failed");
|
||||
furi_delay_us(furi_hal_random_get() % 1000);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t test_furi_event_loop_producer(void* p) {
|
||||
furi_check(p);
|
||||
|
||||
TestFuriData* data = p;
|
||||
|
||||
FURI_LOG_I(TAG, "producer start 1st run");
|
||||
|
||||
data->producer_event_loop = furi_event_loop_alloc();
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->producer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_mq_callback,
|
||||
data);
|
||||
|
||||
furi_event_loop_run(data->producer_event_loop);
|
||||
|
||||
// 2 EventLoop index, 0xFFFFFFFF - all possible flags, emulate uncleared flags
|
||||
xTaskNotifyIndexed(xTaskGetCurrentTaskHandle(), 2, 0xFFFFFFFF, eSetBits);
|
||||
|
||||
furi_event_loop_unsubscribe(data->producer_event_loop, data->mq);
|
||||
furi_event_loop_free(data->producer_event_loop);
|
||||
|
||||
FURI_LOG_I(TAG, "producer start 2nd run");
|
||||
|
||||
data->producer_counter = 0;
|
||||
data->producer_event_loop = furi_event_loop_alloc();
|
||||
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->producer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_mq_callback,
|
||||
data);
|
||||
|
||||
furi_event_loop_run(data->producer_event_loop);
|
||||
|
||||
furi_event_loop_unsubscribe(data->producer_event_loop, data->mq);
|
||||
furi_event_loop_free(data->producer_event_loop);
|
||||
|
||||
FURI_LOG_I(TAG, "producer end");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_furi_event_loop_consumer_mq_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriData* data = context;
|
||||
furi_check(data->mq == object);
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 1000);
|
||||
furi_check(furi_message_queue_get(data->mq, &data->consumer_counter, 0) == FuriStatusOk);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG, "consumer_mq_callback: %lu %lu", data->producer_counter, data->consumer_counter);
|
||||
|
||||
if(data->consumer_counter == EVENT_LOOP_EVENT_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(data->consumer_event_loop, data->mq);
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->consumer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_mq_callback,
|
||||
data);
|
||||
}
|
||||
|
||||
if(data->consumer_counter == EVENT_LOOP_EVENT_COUNT) {
|
||||
furi_event_loop_stop(data->consumer_event_loop);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t test_furi_event_loop_consumer(void* p) {
|
||||
furi_check(p);
|
||||
|
||||
TestFuriData* data = p;
|
||||
|
||||
FURI_LOG_I(TAG, "consumer start 1st run");
|
||||
|
||||
data->consumer_event_loop = furi_event_loop_alloc();
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->consumer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_mq_callback,
|
||||
data);
|
||||
|
||||
furi_event_loop_run(data->consumer_event_loop);
|
||||
|
||||
// 2 EventLoop index, 0xFFFFFFFF - all possible flags, emulate uncleared flags
|
||||
xTaskNotifyIndexed(xTaskGetCurrentTaskHandle(), 2, 0xFFFFFFFF, eSetBits);
|
||||
|
||||
furi_event_loop_unsubscribe(data->consumer_event_loop, data->mq);
|
||||
furi_event_loop_free(data->consumer_event_loop);
|
||||
|
||||
FURI_LOG_I(TAG, "consumer start 2nd run");
|
||||
|
||||
data->consumer_counter = 0;
|
||||
data->consumer_event_loop = furi_event_loop_alloc();
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->consumer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_mq_callback,
|
||||
data);
|
||||
|
||||
furi_event_loop_run(data->consumer_event_loop);
|
||||
|
||||
furi_event_loop_unsubscribe(data->consumer_event_loop, data->mq);
|
||||
furi_event_loop_free(data->consumer_event_loop);
|
||||
|
||||
FURI_LOG_I(TAG, "consumer end");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_furi_event_loop(void) {
|
||||
TestFuriData data = {};
|
||||
|
||||
data.mq = furi_message_queue_alloc(16, sizeof(uint32_t));
|
||||
|
||||
FuriThread* producer_thread = furi_thread_alloc();
|
||||
furi_thread_set_name(producer_thread, "producer_thread");
|
||||
furi_thread_set_stack_size(producer_thread, 1 * 1024);
|
||||
furi_thread_set_callback(producer_thread, test_furi_event_loop_producer);
|
||||
furi_thread_set_context(producer_thread, &data);
|
||||
furi_thread_start(producer_thread);
|
||||
|
||||
FuriThread* consumer_thread = furi_thread_alloc();
|
||||
furi_thread_set_name(consumer_thread, "consumer_thread");
|
||||
furi_thread_set_stack_size(consumer_thread, 1 * 1024);
|
||||
furi_thread_set_callback(consumer_thread, test_furi_event_loop_consumer);
|
||||
furi_thread_set_context(consumer_thread, &data);
|
||||
furi_thread_start(consumer_thread);
|
||||
|
||||
// Wait for thread to complete their tasks
|
||||
furi_thread_join(producer_thread);
|
||||
furi_thread_join(consumer_thread);
|
||||
|
||||
// The test itself
|
||||
mu_assert_int_eq(data.producer_counter, data.consumer_counter);
|
||||
mu_assert_int_eq(data.producer_counter, EVENT_LOOP_EVENT_COUNT);
|
||||
|
||||
// Release memory
|
||||
furi_thread_free(consumer_thread);
|
||||
furi_thread_free(producer_thread);
|
||||
furi_message_queue_free(data.mq);
|
||||
}
|
||||
490
applications/debug/unit_tests/tests/furi/furi_event_loop_test.c
Normal file
490
applications/debug/unit_tests/tests/furi/furi_event_loop_test.c
Normal file
@@ -0,0 +1,490 @@
|
||||
#include "../test.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#define TAG "TestFuriEventLoop"
|
||||
|
||||
#define MESSAGE_COUNT (256UL)
|
||||
#define EVENT_FLAG_COUNT (23UL)
|
||||
#define PRIMITIVE_COUNT (4UL)
|
||||
#define RUN_COUNT (2UL)
|
||||
|
||||
typedef struct {
|
||||
FuriEventLoop* event_loop;
|
||||
uint32_t message_queue_count;
|
||||
uint32_t stream_buffer_count;
|
||||
uint32_t event_flag_count;
|
||||
uint32_t semaphore_count;
|
||||
uint32_t primitives_tested;
|
||||
} TestFuriEventLoopThread;
|
||||
|
||||
typedef struct {
|
||||
FuriMessageQueue* message_queue;
|
||||
FuriStreamBuffer* stream_buffer;
|
||||
FuriEventFlag* event_flag;
|
||||
FuriSemaphore* semaphore;
|
||||
|
||||
TestFuriEventLoopThread producer;
|
||||
TestFuriEventLoopThread consumer;
|
||||
} TestFuriEventLoopData;
|
||||
|
||||
static void test_furi_event_loop_pending_callback(void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopThread* test_thread = context;
|
||||
furi_check(test_thread->primitives_tested < PRIMITIVE_COUNT);
|
||||
|
||||
test_thread->primitives_tested++;
|
||||
FURI_LOG_I(TAG, "primitives tested: %lu", test_thread->primitives_tested);
|
||||
|
||||
if(test_thread->primitives_tested == PRIMITIVE_COUNT) {
|
||||
furi_event_loop_stop(test_thread->event_loop);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_furi_event_loop_thread_init(TestFuriEventLoopThread* test_thread) {
|
||||
memset(test_thread, 0, sizeof(TestFuriEventLoopThread));
|
||||
test_thread->event_loop = furi_event_loop_alloc();
|
||||
}
|
||||
|
||||
static void test_furi_event_loop_thread_run_and_cleanup(TestFuriEventLoopThread* test_thread) {
|
||||
furi_event_loop_run(test_thread->event_loop);
|
||||
// 2 EventLoop index, 0xFFFFFFFF - all possible flags, emulate uncleared flags
|
||||
xTaskNotifyIndexed(xTaskGetCurrentTaskHandle(), 2, 0xFFFFFFFF, eSetBits);
|
||||
furi_event_loop_free(test_thread->event_loop);
|
||||
}
|
||||
|
||||
static void test_furi_event_loop_producer_message_queue_callback(
|
||||
FuriEventLoopObject* object,
|
||||
void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->message_queue == object);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"producer MessageQueue: %lu %lu",
|
||||
data->producer.message_queue_count,
|
||||
data->consumer.message_queue_count);
|
||||
|
||||
if(data->producer.message_queue_count == MESSAGE_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(data->producer.event_loop, data->message_queue);
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->producer.event_loop,
|
||||
data->message_queue,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_message_queue_callback,
|
||||
data);
|
||||
|
||||
} else if(data->producer.message_queue_count == MESSAGE_COUNT) {
|
||||
furi_event_loop_unsubscribe(data->producer.event_loop, data->message_queue);
|
||||
furi_event_loop_pend_callback(
|
||||
data->producer.event_loop, test_furi_event_loop_pending_callback, &data->producer);
|
||||
return;
|
||||
}
|
||||
|
||||
data->producer.message_queue_count++;
|
||||
|
||||
furi_check(
|
||||
furi_message_queue_put(data->message_queue, &data->producer.message_queue_count, 0) ==
|
||||
FuriStatusOk);
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
}
|
||||
|
||||
static void test_furi_event_loop_producer_stream_buffer_callback(
|
||||
FuriEventLoopObject* object,
|
||||
void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->stream_buffer == object);
|
||||
|
||||
TestFuriEventLoopThread* producer = &data->producer;
|
||||
TestFuriEventLoopThread* consumer = &data->consumer;
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"producer StreamBuffer: %lu %lu",
|
||||
producer->stream_buffer_count,
|
||||
consumer->stream_buffer_count);
|
||||
|
||||
if(producer->stream_buffer_count == MESSAGE_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(producer->event_loop, data->stream_buffer);
|
||||
furi_event_loop_subscribe_stream_buffer(
|
||||
producer->event_loop,
|
||||
data->stream_buffer,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_stream_buffer_callback,
|
||||
data);
|
||||
|
||||
} else if(producer->stream_buffer_count == MESSAGE_COUNT) {
|
||||
furi_event_loop_unsubscribe(producer->event_loop, data->stream_buffer);
|
||||
furi_event_loop_pend_callback(
|
||||
producer->event_loop, test_furi_event_loop_pending_callback, producer);
|
||||
return;
|
||||
}
|
||||
|
||||
producer->stream_buffer_count++;
|
||||
|
||||
furi_check(
|
||||
furi_stream_buffer_send(
|
||||
data->stream_buffer, &producer->stream_buffer_count, sizeof(uint32_t), 0) ==
|
||||
sizeof(uint32_t));
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
}
|
||||
|
||||
static void
|
||||
test_furi_event_loop_producer_event_flag_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->event_flag == object);
|
||||
|
||||
const uint32_t producer_flags = (1UL << data->producer.event_flag_count);
|
||||
const uint32_t consumer_flags = (1UL << data->consumer.event_flag_count);
|
||||
|
||||
FURI_LOG_I(TAG, "producer EventFlag: 0x%06lX 0x%06lX", producer_flags, consumer_flags);
|
||||
|
||||
furi_check(furi_event_flag_set(data->event_flag, producer_flags) & producer_flags);
|
||||
|
||||
if(data->producer.event_flag_count == EVENT_FLAG_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(data->producer.event_loop, data->event_flag);
|
||||
furi_event_loop_subscribe_event_flag(
|
||||
data->producer.event_loop,
|
||||
data->event_flag,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_event_flag_callback,
|
||||
data);
|
||||
|
||||
} else if(data->producer.event_flag_count == EVENT_FLAG_COUNT) {
|
||||
furi_event_loop_unsubscribe(data->producer.event_loop, data->event_flag);
|
||||
furi_event_loop_pend_callback(
|
||||
data->producer.event_loop, test_furi_event_loop_pending_callback, &data->producer);
|
||||
return;
|
||||
}
|
||||
|
||||
data->producer.event_flag_count++;
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
}
|
||||
|
||||
static void
|
||||
test_furi_event_loop_producer_semaphore_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->semaphore == object);
|
||||
|
||||
TestFuriEventLoopThread* producer = &data->producer;
|
||||
TestFuriEventLoopThread* consumer = &data->consumer;
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG, "producer Semaphore: %lu %lu", producer->semaphore_count, consumer->semaphore_count);
|
||||
furi_check(furi_semaphore_release(data->semaphore) == FuriStatusOk);
|
||||
|
||||
if(producer->semaphore_count == MESSAGE_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(producer->event_loop, data->semaphore);
|
||||
furi_event_loop_subscribe_semaphore(
|
||||
producer->event_loop,
|
||||
data->semaphore,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_semaphore_callback,
|
||||
data);
|
||||
|
||||
} else if(producer->semaphore_count == MESSAGE_COUNT) {
|
||||
furi_event_loop_unsubscribe(producer->event_loop, data->semaphore);
|
||||
furi_event_loop_pend_callback(
|
||||
producer->event_loop, test_furi_event_loop_pending_callback, producer);
|
||||
return;
|
||||
}
|
||||
|
||||
data->producer.semaphore_count++;
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
}
|
||||
|
||||
static int32_t test_furi_event_loop_producer(void* p) {
|
||||
furi_check(p);
|
||||
|
||||
TestFuriEventLoopData* data = p;
|
||||
TestFuriEventLoopThread* producer = &data->producer;
|
||||
|
||||
for(uint32_t i = 0; i < RUN_COUNT; ++i) {
|
||||
FURI_LOG_I(TAG, "producer start run %lu", i);
|
||||
|
||||
test_furi_event_loop_thread_init(producer);
|
||||
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
producer->event_loop,
|
||||
data->message_queue,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_message_queue_callback,
|
||||
data);
|
||||
furi_event_loop_subscribe_stream_buffer(
|
||||
producer->event_loop,
|
||||
data->stream_buffer,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_stream_buffer_callback,
|
||||
data);
|
||||
furi_event_loop_subscribe_event_flag(
|
||||
producer->event_loop,
|
||||
data->event_flag,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_event_flag_callback,
|
||||
data);
|
||||
furi_event_loop_subscribe_semaphore(
|
||||
producer->event_loop,
|
||||
data->semaphore,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_semaphore_callback,
|
||||
data);
|
||||
|
||||
test_furi_event_loop_thread_run_and_cleanup(producer);
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "producer end");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_furi_event_loop_consumer_message_queue_callback(
|
||||
FuriEventLoopObject* object,
|
||||
void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->message_queue == object);
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
|
||||
furi_check(
|
||||
furi_message_queue_get(data->message_queue, &data->consumer.message_queue_count, 0) ==
|
||||
FuriStatusOk);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"consumer MessageQueue: %lu %lu",
|
||||
data->producer.message_queue_count,
|
||||
data->consumer.message_queue_count);
|
||||
|
||||
if(data->consumer.message_queue_count == MESSAGE_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(data->consumer.event_loop, data->message_queue);
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
data->consumer.event_loop,
|
||||
data->message_queue,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_message_queue_callback,
|
||||
data);
|
||||
|
||||
} else if(data->consumer.message_queue_count == MESSAGE_COUNT) {
|
||||
furi_event_loop_unsubscribe(data->consumer.event_loop, data->message_queue);
|
||||
furi_event_loop_pend_callback(
|
||||
data->consumer.event_loop, test_furi_event_loop_pending_callback, &data->consumer);
|
||||
}
|
||||
}
|
||||
|
||||
static void test_furi_event_loop_consumer_stream_buffer_callback(
|
||||
FuriEventLoopObject* object,
|
||||
void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->stream_buffer == object);
|
||||
|
||||
TestFuriEventLoopThread* producer = &data->producer;
|
||||
TestFuriEventLoopThread* consumer = &data->consumer;
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
|
||||
furi_check(
|
||||
furi_stream_buffer_receive(
|
||||
data->stream_buffer, &consumer->stream_buffer_count, sizeof(uint32_t), 0) ==
|
||||
sizeof(uint32_t));
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG,
|
||||
"consumer StreamBuffer: %lu %lu",
|
||||
producer->stream_buffer_count,
|
||||
consumer->stream_buffer_count);
|
||||
|
||||
if(consumer->stream_buffer_count == MESSAGE_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(consumer->event_loop, data->stream_buffer);
|
||||
furi_event_loop_subscribe_stream_buffer(
|
||||
consumer->event_loop,
|
||||
data->stream_buffer,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_stream_buffer_callback,
|
||||
data);
|
||||
|
||||
} else if(consumer->stream_buffer_count == MESSAGE_COUNT) {
|
||||
furi_event_loop_unsubscribe(data->consumer.event_loop, data->stream_buffer);
|
||||
furi_event_loop_pend_callback(
|
||||
consumer->event_loop, test_furi_event_loop_pending_callback, consumer);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_furi_event_loop_consumer_event_flag_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->event_flag == object);
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
|
||||
const uint32_t producer_flags = (1UL << data->producer.event_flag_count);
|
||||
const uint32_t consumer_flags = (1UL << data->consumer.event_flag_count);
|
||||
|
||||
furi_check(
|
||||
furi_event_flag_wait(data->event_flag, consumer_flags, FuriFlagWaitAny, 0) &
|
||||
consumer_flags);
|
||||
|
||||
FURI_LOG_I(TAG, "consumer EventFlag: 0x%06lX 0x%06lX", producer_flags, consumer_flags);
|
||||
|
||||
if(data->consumer.event_flag_count == EVENT_FLAG_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(data->consumer.event_loop, data->event_flag);
|
||||
furi_event_loop_subscribe_event_flag(
|
||||
data->consumer.event_loop,
|
||||
data->event_flag,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_event_flag_callback,
|
||||
data);
|
||||
|
||||
} else if(data->consumer.event_flag_count == EVENT_FLAG_COUNT) {
|
||||
furi_event_loop_unsubscribe(data->consumer.event_loop, data->event_flag);
|
||||
furi_event_loop_pend_callback(
|
||||
data->consumer.event_loop, test_furi_event_loop_pending_callback, &data->consumer);
|
||||
return;
|
||||
}
|
||||
|
||||
data->consumer.event_flag_count++;
|
||||
}
|
||||
|
||||
static void
|
||||
test_furi_event_loop_consumer_semaphore_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriEventLoopData* data = context;
|
||||
furi_check(data->semaphore == object);
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 100);
|
||||
|
||||
TestFuriEventLoopThread* producer = &data->producer;
|
||||
TestFuriEventLoopThread* consumer = &data->consumer;
|
||||
|
||||
furi_check(furi_semaphore_acquire(data->semaphore, 0) == FuriStatusOk);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG, "consumer Semaphore: %lu %lu", producer->semaphore_count, consumer->semaphore_count);
|
||||
|
||||
if(consumer->semaphore_count == MESSAGE_COUNT / 2) {
|
||||
furi_event_loop_unsubscribe(consumer->event_loop, data->semaphore);
|
||||
furi_event_loop_subscribe_semaphore(
|
||||
consumer->event_loop,
|
||||
data->semaphore,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_semaphore_callback,
|
||||
data);
|
||||
|
||||
} else if(consumer->semaphore_count == MESSAGE_COUNT) {
|
||||
furi_event_loop_unsubscribe(consumer->event_loop, data->semaphore);
|
||||
furi_event_loop_pend_callback(
|
||||
consumer->event_loop, test_furi_event_loop_pending_callback, consumer);
|
||||
return;
|
||||
}
|
||||
|
||||
data->consumer.semaphore_count++;
|
||||
}
|
||||
|
||||
static int32_t test_furi_event_loop_consumer(void* p) {
|
||||
furi_check(p);
|
||||
|
||||
TestFuriEventLoopData* data = p;
|
||||
TestFuriEventLoopThread* consumer = &data->consumer;
|
||||
|
||||
for(uint32_t i = 0; i < RUN_COUNT; ++i) {
|
||||
FURI_LOG_I(TAG, "consumer start run %lu", i);
|
||||
|
||||
test_furi_event_loop_thread_init(consumer);
|
||||
|
||||
furi_event_loop_subscribe_message_queue(
|
||||
consumer->event_loop,
|
||||
data->message_queue,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_message_queue_callback,
|
||||
data);
|
||||
furi_event_loop_subscribe_stream_buffer(
|
||||
consumer->event_loop,
|
||||
data->stream_buffer,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_stream_buffer_callback,
|
||||
data);
|
||||
furi_event_loop_subscribe_event_flag(
|
||||
consumer->event_loop,
|
||||
data->event_flag,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_event_flag_callback,
|
||||
data);
|
||||
furi_event_loop_subscribe_semaphore(
|
||||
consumer->event_loop,
|
||||
data->semaphore,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_semaphore_callback,
|
||||
data);
|
||||
|
||||
test_furi_event_loop_thread_run_and_cleanup(consumer);
|
||||
}
|
||||
|
||||
FURI_LOG_I(TAG, "consumer end");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_furi_event_loop(void) {
|
||||
TestFuriEventLoopData data = {};
|
||||
|
||||
data.message_queue = furi_message_queue_alloc(16, sizeof(uint32_t));
|
||||
data.stream_buffer = furi_stream_buffer_alloc(16, sizeof(uint32_t));
|
||||
data.event_flag = furi_event_flag_alloc();
|
||||
data.semaphore = furi_semaphore_alloc(8, 0);
|
||||
|
||||
FuriThread* producer_thread =
|
||||
furi_thread_alloc_ex("producer_thread", 1 * 1024, test_furi_event_loop_producer, &data);
|
||||
furi_thread_start(producer_thread);
|
||||
|
||||
FuriThread* consumer_thread =
|
||||
furi_thread_alloc_ex("consumer_thread", 1 * 1024, test_furi_event_loop_consumer, &data);
|
||||
furi_thread_start(consumer_thread);
|
||||
|
||||
// Wait for thread to complete their tasks
|
||||
furi_thread_join(producer_thread);
|
||||
furi_thread_join(consumer_thread);
|
||||
|
||||
TestFuriEventLoopThread* producer = &data.producer;
|
||||
TestFuriEventLoopThread* consumer = &data.consumer;
|
||||
|
||||
// The test itself
|
||||
mu_assert_int_eq(producer->message_queue_count, consumer->message_queue_count);
|
||||
mu_assert_int_eq(producer->message_queue_count, MESSAGE_COUNT);
|
||||
mu_assert_int_eq(producer->stream_buffer_count, consumer->stream_buffer_count);
|
||||
mu_assert_int_eq(producer->stream_buffer_count, MESSAGE_COUNT);
|
||||
mu_assert_int_eq(producer->event_flag_count, consumer->event_flag_count);
|
||||
mu_assert_int_eq(producer->event_flag_count, EVENT_FLAG_COUNT);
|
||||
mu_assert_int_eq(producer->semaphore_count, consumer->semaphore_count);
|
||||
mu_assert_int_eq(producer->semaphore_count, MESSAGE_COUNT);
|
||||
|
||||
// Release memory
|
||||
furi_thread_free(consumer_thread);
|
||||
furi_thread_free(producer_thread);
|
||||
|
||||
furi_message_queue_free(data.message_queue);
|
||||
furi_stream_buffer_free(data.stream_buffer);
|
||||
furi_event_flag_free(data.event_flag);
|
||||
furi_semaphore_free(data.semaphore);
|
||||
}
|
||||
103
applications/debug/unit_tests/tests/furi/furi_primitives_test.c
Normal file
103
applications/debug/unit_tests/tests/furi/furi_primitives_test.c
Normal file
@@ -0,0 +1,103 @@
|
||||
#include <furi.h>
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#define MESSAGE_QUEUE_CAPACITY (16U)
|
||||
#define MESSAGE_QUEUE_ELEMENT_SIZE (sizeof(uint32_t))
|
||||
|
||||
#define STREAM_BUFFER_SIZE (32U)
|
||||
#define STREAM_BUFFER_TRG_LEVEL (STREAM_BUFFER_SIZE / 2U)
|
||||
|
||||
typedef struct {
|
||||
FuriMessageQueue* message_queue;
|
||||
FuriStreamBuffer* stream_buffer;
|
||||
} TestFuriPrimitivesData;
|
||||
|
||||
static void test_furi_message_queue(TestFuriPrimitivesData* data) {
|
||||
FuriMessageQueue* message_queue = data->message_queue;
|
||||
|
||||
mu_assert_int_eq(0, furi_message_queue_get_count(message_queue));
|
||||
mu_assert_int_eq(MESSAGE_QUEUE_CAPACITY, furi_message_queue_get_space(message_queue));
|
||||
mu_assert_int_eq(MESSAGE_QUEUE_CAPACITY, furi_message_queue_get_capacity(message_queue));
|
||||
mu_assert_int_eq(
|
||||
MESSAGE_QUEUE_ELEMENT_SIZE, furi_message_queue_get_message_size(message_queue));
|
||||
|
||||
for(uint32_t i = 0;; ++i) {
|
||||
mu_assert_int_eq(MESSAGE_QUEUE_CAPACITY - i, furi_message_queue_get_space(message_queue));
|
||||
mu_assert_int_eq(i, furi_message_queue_get_count(message_queue));
|
||||
|
||||
if(furi_message_queue_put(message_queue, &i, 0) != FuriStatusOk) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mu_assert_int_eq(0, furi_message_queue_get_space(message_queue));
|
||||
mu_assert_int_eq(MESSAGE_QUEUE_CAPACITY, furi_message_queue_get_count(message_queue));
|
||||
|
||||
for(uint32_t i = 0;; ++i) {
|
||||
mu_assert_int_eq(i, furi_message_queue_get_space(message_queue));
|
||||
mu_assert_int_eq(MESSAGE_QUEUE_CAPACITY - i, furi_message_queue_get_count(message_queue));
|
||||
|
||||
uint32_t value;
|
||||
if(furi_message_queue_get(message_queue, &value, 0) != FuriStatusOk) {
|
||||
break;
|
||||
}
|
||||
|
||||
mu_assert_int_eq(i, value);
|
||||
}
|
||||
|
||||
mu_assert_int_eq(0, furi_message_queue_get_count(message_queue));
|
||||
mu_assert_int_eq(MESSAGE_QUEUE_CAPACITY, furi_message_queue_get_space(message_queue));
|
||||
}
|
||||
|
||||
static void test_furi_stream_buffer(TestFuriPrimitivesData* data) {
|
||||
FuriStreamBuffer* stream_buffer = data->stream_buffer;
|
||||
|
||||
mu_assert(furi_stream_buffer_is_empty(stream_buffer), "Must be empty");
|
||||
mu_assert(!furi_stream_buffer_is_full(stream_buffer), "Must be not full");
|
||||
mu_assert_int_eq(0, furi_stream_buffer_bytes_available(stream_buffer));
|
||||
mu_assert_int_eq(STREAM_BUFFER_SIZE, furi_stream_buffer_spaces_available(stream_buffer));
|
||||
|
||||
for(uint8_t i = 0;; ++i) {
|
||||
mu_assert_int_eq(i, furi_stream_buffer_bytes_available(stream_buffer));
|
||||
mu_assert_int_eq(
|
||||
STREAM_BUFFER_SIZE - i, furi_stream_buffer_spaces_available(stream_buffer));
|
||||
|
||||
if(furi_stream_buffer_send(stream_buffer, &i, sizeof(uint8_t), 0) != sizeof(uint8_t)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mu_assert(!furi_stream_buffer_is_empty(stream_buffer), "Must be not empty");
|
||||
mu_assert(furi_stream_buffer_is_full(stream_buffer), "Must be full");
|
||||
mu_assert_int_eq(STREAM_BUFFER_SIZE, furi_stream_buffer_bytes_available(stream_buffer));
|
||||
mu_assert_int_eq(0, furi_stream_buffer_spaces_available(stream_buffer));
|
||||
|
||||
for(uint8_t i = 0;; ++i) {
|
||||
mu_assert_int_eq(
|
||||
STREAM_BUFFER_SIZE - i, furi_stream_buffer_bytes_available(stream_buffer));
|
||||
mu_assert_int_eq(i, furi_stream_buffer_spaces_available(stream_buffer));
|
||||
|
||||
uint8_t value;
|
||||
if(furi_stream_buffer_receive(stream_buffer, &value, sizeof(uint8_t), 0) !=
|
||||
sizeof(uint8_t)) {
|
||||
break;
|
||||
}
|
||||
|
||||
mu_assert_int_eq(i, value);
|
||||
}
|
||||
}
|
||||
|
||||
// This is a stub that needs expanding
|
||||
void test_furi_primitives(void) {
|
||||
TestFuriPrimitivesData data = {
|
||||
.message_queue =
|
||||
furi_message_queue_alloc(MESSAGE_QUEUE_CAPACITY, MESSAGE_QUEUE_ELEMENT_SIZE),
|
||||
.stream_buffer = furi_stream_buffer_alloc(STREAM_BUFFER_SIZE, STREAM_BUFFER_TRG_LEVEL),
|
||||
};
|
||||
|
||||
test_furi_message_queue(&data);
|
||||
test_furi_stream_buffer(&data);
|
||||
|
||||
furi_message_queue_free(data.message_queue);
|
||||
furi_stream_buffer_free(data.stream_buffer);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ void test_furi_pubsub(void);
|
||||
void test_furi_memmgr(void);
|
||||
void test_furi_event_loop(void);
|
||||
void test_errno_saving(void);
|
||||
void test_furi_primitives(void);
|
||||
|
||||
static int foo = 0;
|
||||
|
||||
@@ -47,6 +48,10 @@ MU_TEST(mu_test_errno_saving) {
|
||||
test_errno_saving();
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_primitives) {
|
||||
test_furi_primitives();
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_suite) {
|
||||
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
|
||||
MU_RUN_TEST(test_check);
|
||||
@@ -57,6 +62,7 @@ MU_TEST_SUITE(test_suite) {
|
||||
MU_RUN_TEST(mu_test_furi_memmgr);
|
||||
MU_RUN_TEST(mu_test_furi_event_loop);
|
||||
MU_RUN_TEST(mu_test_errno_saving);
|
||||
MU_RUN_TEST(mu_test_furi_primitives);
|
||||
}
|
||||
|
||||
int run_minunit_test_furi(void) {
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
App(
|
||||
appid="example_event_loop_event_flags",
|
||||
name="Example: Event Loop Event Flags",
|
||||
apptype=FlipperAppType.EXTERNAL,
|
||||
sources=["example_event_loop_event_flags.c"],
|
||||
entry_point="example_event_loop_event_flags_app",
|
||||
fap_category="Examples",
|
||||
)
|
||||
|
||||
App(
|
||||
appid="example_event_loop_timer",
|
||||
name="Example: Event Loop Timer",
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* @file example_event_loop_event_flags.c
|
||||
* @brief Example application demonstrating the use of the FuriEventFlag primitive in FuriEventLoop instances.
|
||||
*
|
||||
* This application receives keystrokes from the input service and sets the appropriate flags,
|
||||
* which are subsequently processed in the event loop
|
||||
*/
|
||||
|
||||
#include <furi.h>
|
||||
#include <gui/gui.h>
|
||||
#include <gui/view_port.h>
|
||||
|
||||
#include <furi_hal_random.h>
|
||||
|
||||
#define TAG "ExampleEventLoopEventFlags"
|
||||
|
||||
typedef struct {
|
||||
Gui* gui;
|
||||
ViewPort* view_port;
|
||||
FuriEventLoop* event_loop;
|
||||
FuriEventFlag* event_flag;
|
||||
} EventLoopEventFlagsApp;
|
||||
|
||||
typedef enum {
|
||||
EventLoopEventFlagsOk = (1 << 0),
|
||||
EventLoopEventFlagsUp = (1 << 1),
|
||||
EventLoopEventFlagsDown = (1 << 2),
|
||||
EventLoopEventFlagsLeft = (1 << 3),
|
||||
EventLoopEventFlagsRight = (1 << 4),
|
||||
EventLoopEventFlagsBack = (1 << 5),
|
||||
EventLoopEventFlagsExit = (1 << 6),
|
||||
} EventLoopEventFlags;
|
||||
|
||||
#define EVENT_LOOP_EVENT_FLAGS_MASK \
|
||||
(EventLoopEventFlagsOk | EventLoopEventFlagsUp | EventLoopEventFlagsDown | \
|
||||
EventLoopEventFlagsLeft | EventLoopEventFlagsRight | EventLoopEventFlagsBack | \
|
||||
EventLoopEventFlagsExit)
|
||||
|
||||
// This function is executed in the GUI context each time an input event occurs (e.g. the user pressed a key)
|
||||
static void event_loop_event_flags_app_input_callback(InputEvent* event, void* context) {
|
||||
furi_assert(context);
|
||||
EventLoopEventFlagsApp* app = context;
|
||||
UNUSED(app);
|
||||
|
||||
if(event->type == InputTypePress) {
|
||||
if(event->key == InputKeyOk) {
|
||||
furi_event_flag_set(app->event_flag, EventLoopEventFlagsOk);
|
||||
} else if(event->key == InputKeyUp) {
|
||||
furi_event_flag_set(app->event_flag, EventLoopEventFlagsUp);
|
||||
} else if(event->key == InputKeyDown) {
|
||||
furi_event_flag_set(app->event_flag, EventLoopEventFlagsDown);
|
||||
} else if(event->key == InputKeyLeft) {
|
||||
furi_event_flag_set(app->event_flag, EventLoopEventFlagsLeft);
|
||||
} else if(event->key == InputKeyRight) {
|
||||
furi_event_flag_set(app->event_flag, EventLoopEventFlagsRight);
|
||||
} else if(event->key == InputKeyBack) {
|
||||
furi_event_flag_set(app->event_flag, EventLoopEventFlagsBack);
|
||||
}
|
||||
} else if(event->type == InputTypeLong) {
|
||||
if(event->key == InputKeyBack) {
|
||||
furi_event_flag_set(app->event_flag, EventLoopEventFlagsExit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function is executed each time a new event flag is inserted in the input event flag.
|
||||
static void
|
||||
event_loop_event_flags_app_event_flags_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
EventLoopEventFlagsApp* app = context;
|
||||
|
||||
furi_assert(object == app->event_flag);
|
||||
|
||||
EventLoopEventFlags events =
|
||||
furi_event_flag_wait(app->event_flag, EVENT_LOOP_EVENT_FLAGS_MASK, FuriFlagWaitAny, 0);
|
||||
furi_check((events) != 0);
|
||||
|
||||
if(events & EventLoopEventFlagsOk) {
|
||||
FURI_LOG_I(TAG, "Press \"Ok\"");
|
||||
}
|
||||
if(events & EventLoopEventFlagsUp) {
|
||||
FURI_LOG_I(TAG, "Press \"Up\"");
|
||||
}
|
||||
if(events & EventLoopEventFlagsDown) {
|
||||
FURI_LOG_I(TAG, "Press \"Down\"");
|
||||
}
|
||||
if(events & EventLoopEventFlagsLeft) {
|
||||
FURI_LOG_I(TAG, "Press \"Left\"");
|
||||
}
|
||||
if(events & EventLoopEventFlagsRight) {
|
||||
FURI_LOG_I(TAG, "Press \"Right\"");
|
||||
}
|
||||
if(events & EventLoopEventFlagsBack) {
|
||||
FURI_LOG_I(TAG, "Press \"Back\"");
|
||||
}
|
||||
if(events & EventLoopEventFlagsExit) {
|
||||
FURI_LOG_I(TAG, "Exit App");
|
||||
furi_event_loop_stop(app->event_loop);
|
||||
}
|
||||
}
|
||||
|
||||
static EventLoopEventFlagsApp* event_loop_event_flags_app_alloc(void) {
|
||||
EventLoopEventFlagsApp* app = malloc(sizeof(EventLoopEventFlagsApp));
|
||||
|
||||
// Create event loop instances.
|
||||
app->event_loop = furi_event_loop_alloc();
|
||||
// Create event flag instances.
|
||||
app->event_flag = furi_event_flag_alloc();
|
||||
|
||||
// Create GUI instance.
|
||||
app->gui = furi_record_open(RECORD_GUI);
|
||||
app->view_port = view_port_alloc();
|
||||
// Gain exclusive access to the input events
|
||||
view_port_input_callback_set(app->view_port, event_loop_event_flags_app_input_callback, app);
|
||||
gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
|
||||
|
||||
// Notify the event loop about incoming messages in the event flag
|
||||
furi_event_loop_subscribe_event_flag(
|
||||
app->event_loop,
|
||||
app->event_flag,
|
||||
FuriEventLoopEventIn | FuriEventLoopEventFlagEdge,
|
||||
event_loop_event_flags_app_event_flags_callback,
|
||||
app);
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
static void event_loop_event_flags_app_free(EventLoopEventFlagsApp* app) {
|
||||
gui_remove_view_port(app->gui, app->view_port);
|
||||
|
||||
furi_record_close(RECORD_GUI);
|
||||
app->gui = NULL;
|
||||
|
||||
// Delete all instances
|
||||
view_port_free(app->view_port);
|
||||
app->view_port = NULL;
|
||||
|
||||
// IMPORTANT: The user code MUST unsubscribe from all events before deleting the event loop.
|
||||
// Failure to do so will result in a crash.
|
||||
furi_event_loop_unsubscribe(app->event_loop, app->event_flag);
|
||||
|
||||
furi_event_flag_free(app->event_flag);
|
||||
app->event_flag = NULL;
|
||||
|
||||
furi_event_loop_free(app->event_loop);
|
||||
app->event_loop = NULL;
|
||||
|
||||
free(app);
|
||||
}
|
||||
|
||||
static void event_loop_event_flags_app_run(EventLoopEventFlagsApp* app) {
|
||||
FURI_LOG_I(TAG, "Press keys to see them printed here.");
|
||||
FURI_LOG_I(TAG, "Quickly press different keys to generate events.");
|
||||
FURI_LOG_I(TAG, "Long press \"Back\" to exit app.");
|
||||
|
||||
// Run the application event loop. This call will block until the application is about to exit.
|
||||
furi_event_loop_run(app->event_loop);
|
||||
}
|
||||
|
||||
/*******************************************************************
|
||||
* vvv START HERE vvv
|
||||
*
|
||||
* The application's entry point - referenced in application.fam
|
||||
*******************************************************************/
|
||||
int32_t example_event_loop_event_flags_app(void* arg) {
|
||||
UNUSED(arg);
|
||||
|
||||
EventLoopEventFlagsApp* app = event_loop_event_flags_app_alloc();
|
||||
event_loop_event_flags_app_run(app);
|
||||
event_loop_event_flags_app_free(app);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -52,7 +52,7 @@ typedef struct {
|
||||
*/
|
||||
|
||||
// This function is executed each time the data is taken out of the stream buffer. It is used to restart the worker timer.
|
||||
static bool
|
||||
static void
|
||||
event_loop_multi_app_stream_buffer_worker_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
EventLoopMultiAppWorker* worker = context;
|
||||
@@ -62,8 +62,6 @@ static bool
|
||||
FURI_LOG_I(TAG, "Data was removed from buffer");
|
||||
// Restart the timer to generate another block of random data.
|
||||
furi_event_loop_timer_start(worker->timer, WORKER_DATA_INTERVAL_MS);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is executed when the worker timer expires. The timer will NOT restart automatically
|
||||
@@ -152,7 +150,7 @@ static void event_loop_multi_app_input_callback(InputEvent* event, void* context
|
||||
}
|
||||
|
||||
// This function is executed each time new data is available in the stream buffer.
|
||||
static bool
|
||||
static void
|
||||
event_loop_multi_app_stream_buffer_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
EventLoopMultiApp* app = context;
|
||||
@@ -172,12 +170,10 @@ static bool
|
||||
|
||||
FURI_LOG_I(TAG, "Received data: %s", furi_string_get_cstr(tmp_str));
|
||||
furi_string_free(tmp_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is executed each time a new message is inserted in the input queue.
|
||||
static bool event_loop_multi_app_input_queue_callback(FuriEventLoopObject* object, void* context) {
|
||||
static void event_loop_multi_app_input_queue_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
EventLoopMultiApp* app = context;
|
||||
|
||||
@@ -222,8 +218,6 @@ static bool event_loop_multi_app_input_queue_callback(FuriEventLoopObject* objec
|
||||
// Not a long press, just print the key's name.
|
||||
FURI_LOG_I(TAG, "Short press: %s", input_get_key_name(event.key));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function is executed each time the countdown timer expires.
|
||||
|
||||
@@ -59,7 +59,7 @@ static int32_t event_loop_mutex_app_worker_thread(void* context) {
|
||||
}
|
||||
|
||||
// This function is being run each time when the mutex gets released
|
||||
static bool event_loop_mutex_app_event_callback(FuriEventLoopObject* object, void* context) {
|
||||
static void event_loop_mutex_app_event_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
|
||||
EventLoopMutexApp* app = context;
|
||||
@@ -82,8 +82,6 @@ static bool event_loop_mutex_app_event_callback(FuriEventLoopObject* object, voi
|
||||
MUTEX_EVENT_AND_FLAGS,
|
||||
event_loop_mutex_app_event_callback,
|
||||
app);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static EventLoopMutexApp* event_loop_mutex_app_alloc(void) {
|
||||
|
||||
@@ -54,7 +54,7 @@ static int32_t event_loop_stream_buffer_app_worker_thread(void* context) {
|
||||
}
|
||||
|
||||
// This function is being run each time when the number of bytes in the buffer is above its trigger level.
|
||||
static bool
|
||||
static void
|
||||
event_loop_stream_buffer_app_event_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
EventLoopStreamBufferApp* app = context;
|
||||
@@ -76,8 +76,6 @@ static bool
|
||||
|
||||
FURI_LOG_I(TAG, "Received data: %s", furi_string_get_cstr(tmp_str));
|
||||
furi_string_free(tmp_str);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static EventLoopStreamBufferApp* event_loop_stream_buffer_app_alloc(void) {
|
||||
|
||||
@@ -212,7 +212,7 @@ static void dolphin_update_clear_limits_timer_period(void* context) {
|
||||
FURI_LOG_D(TAG, "Daily limits reset in %lu ms", time_to_clear_limits);
|
||||
}
|
||||
|
||||
static bool dolphin_process_event(FuriEventLoopObject* object, void* context) {
|
||||
static void dolphin_process_event(FuriEventLoopObject* object, void* context) {
|
||||
UNUSED(object);
|
||||
|
||||
Dolphin* dolphin = context;
|
||||
@@ -264,8 +264,6 @@ static bool dolphin_process_event(FuriEventLoopObject* object, void* context) {
|
||||
}
|
||||
|
||||
dolphin_event_release(&event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void dolphin_storage_callback(const void* message, void* context) {
|
||||
|
||||
@@ -376,7 +376,7 @@ void view_dispatcher_update(View* view, void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
bool view_dispatcher_run_event_callback(FuriEventLoopObject* object, void* context) {
|
||||
void view_dispatcher_run_event_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
ViewDispatcher* instance = context;
|
||||
furi_assert(instance->event_queue == object);
|
||||
@@ -384,11 +384,9 @@ bool view_dispatcher_run_event_callback(FuriEventLoopObject* object, void* conte
|
||||
uint32_t event;
|
||||
furi_check(furi_message_queue_get(instance->event_queue, &event, 0) == FuriStatusOk);
|
||||
view_dispatcher_handle_custom_event(instance, event);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool view_dispatcher_run_input_callback(FuriEventLoopObject* object, void* context) {
|
||||
void view_dispatcher_run_input_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
ViewDispatcher* instance = context;
|
||||
furi_assert(instance->input_queue == object);
|
||||
@@ -396,6 +394,4 @@ bool view_dispatcher_run_input_callback(FuriEventLoopObject* object, void* conte
|
||||
InputEvent input;
|
||||
furi_check(furi_message_queue_get(instance->input_queue, &input, 0) == FuriStatusOk);
|
||||
view_dispatcher_handle_input(instance, &input);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void view_dispatcher_set_current_view(ViewDispatcher* view_dispatcher, View* vie
|
||||
void view_dispatcher_update(View* view, void* context);
|
||||
|
||||
/** ViewDispatcher run event loop event callback */
|
||||
bool view_dispatcher_run_event_callback(FuriEventLoopObject* object, void* context);
|
||||
void view_dispatcher_run_event_callback(FuriEventLoopObject* object, void* context);
|
||||
|
||||
/** ViewDispatcher run event loop input callback */
|
||||
bool view_dispatcher_run_input_callback(FuriEventLoopObject* object, void* context);
|
||||
void view_dispatcher_run_input_callback(FuriEventLoopObject* object, void* context);
|
||||
|
||||
@@ -191,7 +191,7 @@ static void power_handle_reboot(PowerBootMode mode) {
|
||||
furi_hal_power_reset();
|
||||
}
|
||||
|
||||
static bool power_message_callback(FuriEventLoopObject* object, void* context) {
|
||||
static void power_message_callback(FuriEventLoopObject* object, void* context) {
|
||||
furi_assert(context);
|
||||
Power* power = context;
|
||||
|
||||
@@ -223,8 +223,6 @@ static bool power_message_callback(FuriEventLoopObject* object, void* context) {
|
||||
if(msg.lock) {
|
||||
api_lock_unlock(msg.lock);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void power_tick_callback(void* context) {
|
||||
|
||||
@@ -80,7 +80,7 @@ static void js_event_loop_callback_generic(void* param) {
|
||||
/**
|
||||
* @brief Handles non-timer events
|
||||
*/
|
||||
static bool js_event_loop_callback(void* object, void* param) {
|
||||
static void js_event_loop_callback(void* object, void* param) {
|
||||
JsEventLoopCallbackContext* context = param;
|
||||
|
||||
if(context->transformer) {
|
||||
@@ -102,8 +102,6 @@ static bool js_event_loop_callback(void* object, void* param) {
|
||||
}
|
||||
|
||||
js_event_loop_callback_generic(param);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user