Added Dispatcher and fix sim (#54)

- Add dispatcher mechanism (a queue for function calls) and tests
- Added tests for MessageQueue
- Fix FreeRTOS config for simulator
- Explicit dependencies for touch-related libs, because minor version changes caused broken builds on CI.
This commit is contained in:
Ken Van Hoeylandt
2024-08-24 19:21:22 +02:00
committed by GitHub
parent 69a0c01686
commit b659d5b940
8 changed files with 215 additions and 31 deletions
+38
View File
@@ -0,0 +1,38 @@
#include "doctest.h"
#include "tactility_core.h"
#include "dispatcher.h"
void increment_callback(void* context) {
auto* counter = (uint32_t*)context;
(*counter)++;
}
TEST_CASE("dispatcher should not call callback if consume isn't called") {
Dispatcher* dispatcher = tt_dispatcher_alloc(10);
uint32_t counter = 0;
tt_dispatcher_dispatch(dispatcher, &increment_callback, &counter);
tt_delay_tick(10);
CHECK_EQ(counter, 0);
tt_dispatcher_free(dispatcher);
}
TEST_CASE("dispatcher should be able to dealloc when message is not consumed") {
Dispatcher* dispatcher = tt_dispatcher_alloc(10);
uint32_t counter = 0;
tt_dispatcher_dispatch(dispatcher, increment_callback, &counter);
tt_dispatcher_free(dispatcher);
}
TEST_CASE("dispatcher should call callback when consume is called") {
Dispatcher* dispatcher = tt_dispatcher_alloc(10);
uint32_t counter = 0;
tt_dispatcher_dispatch(dispatcher, increment_callback, &counter);
tt_dispatcher_consume(dispatcher, 100);
CHECK_EQ(counter, 1);
tt_dispatcher_free(dispatcher);
}