mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-22 20:43:07 +00:00
Furi: wrap message queue in container, prepare it for epoll. Accessor: disable expansion service on start. (#3672)
* Furi: wrap message queue in container, prepare it for epoll. Accessor: disable expansion service on start. * Furi: one allocation, smaller message queue struct, type compatibility with FreeRTOS.
This commit is contained in:
parent
f309844ee0
commit
3f04d6dd46
5 changed files with 38 additions and 15 deletions
|
@ -34,12 +34,16 @@ void AccessorApp::run(void) {
|
||||||
AccessorApp::AccessorApp()
|
AccessorApp::AccessorApp()
|
||||||
: text_store{0} {
|
: text_store{0} {
|
||||||
notification = static_cast<NotificationApp*>(furi_record_open(RECORD_NOTIFICATION));
|
notification = static_cast<NotificationApp*>(furi_record_open(RECORD_NOTIFICATION));
|
||||||
|
expansion = static_cast<Expansion*>(furi_record_open(RECORD_EXPANSION));
|
||||||
onewire_host = onewire_host_alloc(&gpio_ibutton);
|
onewire_host = onewire_host_alloc(&gpio_ibutton);
|
||||||
|
expansion_disable(expansion);
|
||||||
furi_hal_power_enable_otg();
|
furi_hal_power_enable_otg();
|
||||||
}
|
}
|
||||||
|
|
||||||
AccessorApp::~AccessorApp() {
|
AccessorApp::~AccessorApp() {
|
||||||
furi_hal_power_disable_otg();
|
furi_hal_power_disable_otg();
|
||||||
|
expansion_enable(expansion);
|
||||||
|
furi_record_close(RECORD_EXPANSION);
|
||||||
furi_record_close(RECORD_NOTIFICATION);
|
furi_record_close(RECORD_NOTIFICATION);
|
||||||
onewire_host_free(onewire_host);
|
onewire_host_free(onewire_host);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "helpers/wiegand.h"
|
#include "helpers/wiegand.h"
|
||||||
#include <one_wire/one_wire_host.h>
|
#include <one_wire/one_wire_host.h>
|
||||||
#include <notification/notification_messages.h>
|
#include <notification/notification_messages.h>
|
||||||
|
#include <expansion/expansion.h>
|
||||||
|
|
||||||
class AccessorApp {
|
class AccessorApp {
|
||||||
public:
|
public:
|
||||||
|
@ -51,4 +52,5 @@ private:
|
||||||
OneWireHost* onewire_host;
|
OneWireHost* onewire_host;
|
||||||
|
|
||||||
NotificationApp* notification;
|
NotificationApp* notification;
|
||||||
|
Expansion* expansion;
|
||||||
};
|
};
|
||||||
|
|
|
@ -136,15 +136,17 @@ static void snake_game_render_callback(Canvas* const canvas, void* ctx) {
|
||||||
furi_mutex_release(snake_state->mutex);
|
furi_mutex_release(snake_state->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void snake_game_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
|
static void snake_game_input_callback(InputEvent* input_event, void* context) {
|
||||||
furi_assert(event_queue);
|
furi_assert(context);
|
||||||
|
FuriMessageQueue* event_queue = context;
|
||||||
|
|
||||||
SnakeEvent event = {.type = EventTypeKey, .input = *input_event};
|
SnakeEvent event = {.type = EventTypeKey, .input = *input_event};
|
||||||
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
furi_message_queue_put(event_queue, &event, FuriWaitForever);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void snake_game_update_timer_callback(FuriMessageQueue* event_queue) {
|
static void snake_game_update_timer_callback(void* context) {
|
||||||
furi_assert(event_queue);
|
furi_assert(context);
|
||||||
|
FuriMessageQueue* event_queue = context;
|
||||||
|
|
||||||
SnakeEvent event = {.type = EventTypeTick};
|
SnakeEvent event = {.type = EventTypeTick};
|
||||||
furi_message_queue_put(event_queue, &event, 0);
|
furi_message_queue_put(event_queue, &event, 0);
|
||||||
|
|
|
@ -5,13 +5,30 @@
|
||||||
#include <FreeRTOS.h>
|
#include <FreeRTOS.h>
|
||||||
#include <queue.h>
|
#include <queue.h>
|
||||||
|
|
||||||
|
struct FuriMessageQueue {
|
||||||
|
// !!! Semi-Opaque type inheritance, Very Fragile, DO NOT MOVE !!!
|
||||||
|
StaticQueue_t container;
|
||||||
|
|
||||||
|
// !!! Data buffer, must be last in the structure, DO NOT MOVE !!!
|
||||||
|
uint8_t buffer[];
|
||||||
|
};
|
||||||
|
|
||||||
FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size) {
|
FuriMessageQueue* furi_message_queue_alloc(uint32_t msg_count, uint32_t msg_size) {
|
||||||
furi_check((furi_kernel_is_irq_or_masked() == 0U) && (msg_count > 0U) && (msg_size > 0U));
|
furi_check((furi_kernel_is_irq_or_masked() == 0U) && (msg_count > 0U) && (msg_size > 0U));
|
||||||
|
|
||||||
QueueHandle_t handle = xQueueCreate(msg_count, msg_size);
|
FuriMessageQueue* instance = malloc(sizeof(FuriMessageQueue) + msg_count * msg_size);
|
||||||
furi_check(handle);
|
|
||||||
|
|
||||||
return ((FuriMessageQueue*)handle);
|
// 3 things happens here:
|
||||||
|
// - create queue
|
||||||
|
// - check results
|
||||||
|
// - ensure that queue container is first in the FuriMessageQueue structure
|
||||||
|
//
|
||||||
|
// As a bonus it guarantees that FuriMessageQueue* can be casted into StaticQueue_t* or QueueHandle_t.
|
||||||
|
furi_check(
|
||||||
|
xQueueCreateStatic(msg_count, msg_size, instance->buffer, &instance->container) ==
|
||||||
|
(void*)instance);
|
||||||
|
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void furi_message_queue_free(FuriMessageQueue* instance) {
|
void furi_message_queue_free(FuriMessageQueue* instance) {
|
||||||
|
@ -19,6 +36,7 @@ void furi_message_queue_free(FuriMessageQueue* instance) {
|
||||||
furi_check(instance);
|
furi_check(instance);
|
||||||
|
|
||||||
vQueueDelete((QueueHandle_t)instance);
|
vQueueDelete((QueueHandle_t)instance);
|
||||||
|
free(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
FuriStatus
|
FuriStatus
|
||||||
|
@ -102,11 +120,10 @@ FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uin
|
||||||
uint32_t furi_message_queue_get_capacity(FuriMessageQueue* instance) {
|
uint32_t furi_message_queue_get_capacity(FuriMessageQueue* instance) {
|
||||||
furi_check(instance);
|
furi_check(instance);
|
||||||
|
|
||||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
|
||||||
uint32_t capacity;
|
uint32_t capacity;
|
||||||
|
|
||||||
/* capacity = pxQueue->uxLength */
|
/* capacity = pxQueue->uxLength */
|
||||||
capacity = mq->uxDummy4[1];
|
capacity = instance->container.uxDummy4[1];
|
||||||
|
|
||||||
/* Return maximum number of messages */
|
/* Return maximum number of messages */
|
||||||
return (capacity);
|
return (capacity);
|
||||||
|
@ -115,11 +132,10 @@ uint32_t furi_message_queue_get_capacity(FuriMessageQueue* instance) {
|
||||||
uint32_t furi_message_queue_get_message_size(FuriMessageQueue* instance) {
|
uint32_t furi_message_queue_get_message_size(FuriMessageQueue* instance) {
|
||||||
furi_check(instance);
|
furi_check(instance);
|
||||||
|
|
||||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
|
|
||||||
/* size = pxQueue->uxItemSize */
|
/* size = pxQueue->uxItemSize */
|
||||||
size = mq->uxDummy4[2];
|
size = instance->container.uxDummy4[2];
|
||||||
|
|
||||||
/* Return maximum message size */
|
/* Return maximum message size */
|
||||||
return (size);
|
return (size);
|
||||||
|
@ -144,7 +160,6 @@ uint32_t furi_message_queue_get_count(FuriMessageQueue* instance) {
|
||||||
uint32_t furi_message_queue_get_space(FuriMessageQueue* instance) {
|
uint32_t furi_message_queue_get_space(FuriMessageQueue* instance) {
|
||||||
furi_check(instance);
|
furi_check(instance);
|
||||||
|
|
||||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
|
||||||
uint32_t space;
|
uint32_t space;
|
||||||
uint32_t isrm;
|
uint32_t isrm;
|
||||||
|
|
||||||
|
@ -152,11 +167,11 @@ uint32_t furi_message_queue_get_space(FuriMessageQueue* instance) {
|
||||||
isrm = taskENTER_CRITICAL_FROM_ISR();
|
isrm = taskENTER_CRITICAL_FROM_ISR();
|
||||||
|
|
||||||
/* space = pxQueue->uxLength - pxQueue->uxMessagesWaiting; */
|
/* space = pxQueue->uxLength - pxQueue->uxMessagesWaiting; */
|
||||||
space = mq->uxDummy4[1] - mq->uxDummy4[0];
|
space = instance->container.uxDummy4[1] - instance->container.uxDummy4[0];
|
||||||
|
|
||||||
taskEXIT_CRITICAL_FROM_ISR(isrm);
|
taskEXIT_CRITICAL_FROM_ISR(isrm);
|
||||||
} else {
|
} else {
|
||||||
space = (uint32_t)uxQueueSpacesAvailable((QueueHandle_t)mq);
|
space = (uint32_t)uxQueueSpacesAvailable((QueueHandle_t)instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return number of available slots */
|
/* Return number of available slots */
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void FuriMessageQueue;
|
typedef struct FuriMessageQueue FuriMessageQueue;
|
||||||
|
|
||||||
/** Allocate furi message queue
|
/** Allocate furi message queue
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue