2020-10-13 11:22:43 +03:00
|
|
|
#pragma once
|
|
|
|
|
2020-10-26 12:26:15 +03:00
|
|
|
#include "cmsis_os.h"
|
2020-10-15 21:23:18 +03:00
|
|
|
#include "m-list.h"
|
2020-10-13 11:22:43 +03:00
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
/**
|
2020-10-13 11:22:43 +03:00
|
|
|
== PubSub ==
|
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
* PubSub allows users to subscribe on notifies and notify subscribers.
|
|
|
|
* Notifier side can pass `void*` arg to subscriber callback,
|
|
|
|
* and also subscriber can set `void*` context pointer that pass into
|
|
|
|
* callback (you can see callback signature below).
|
|
|
|
*/
|
2020-10-13 11:22:43 +03:00
|
|
|
|
2020-10-29 10:58:19 +03:00
|
|
|
typedef void (*PubSubCallback)(const void*, void*);
|
2020-10-15 21:23:18 +03:00
|
|
|
typedef struct PubSubType PubSub;
|
2020-10-13 11:22:43 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PubSubCallback cb;
|
|
|
|
void* ctx;
|
2020-10-15 21:23:18 +03:00
|
|
|
PubSub* self;
|
2020-10-13 11:22:43 +03:00
|
|
|
} PubSubItem;
|
|
|
|
|
2020-10-15 21:23:18 +03:00
|
|
|
LIST_DEF(list_pubsub_cb, PubSubItem, M_POD_OPLIST);
|
2020-10-13 11:22:43 +03:00
|
|
|
|
2020-10-15 21:23:18 +03:00
|
|
|
struct PubSubType {
|
|
|
|
list_pubsub_cb_t items;
|
|
|
|
osMutexId_t mutex;
|
|
|
|
};
|
2020-10-13 11:22:43 +03:00
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
/**
|
|
|
|
* To create PubSub you should create PubSub instance and call `init_pubsub`.
|
|
|
|
*/
|
2020-10-15 21:23:18 +03:00
|
|
|
bool init_pubsub(PubSub* pubsub);
|
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
/**
|
|
|
|
* Since we use dynamic memory - we must explicity delete pubsub
|
|
|
|
*/
|
2020-10-15 21:23:18 +03:00
|
|
|
bool delete_pubsub(PubSub* pubsub);
|
2020-10-13 11:22:43 +03:00
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
/**
|
|
|
|
* Use `subscribe_pubsub` to register your callback.
|
|
|
|
*/
|
2020-10-15 21:23:18 +03:00
|
|
|
PubSubItem* subscribe_pubsub(PubSub* pubsub, PubSubCallback cb, void* ctx);
|
2020-10-13 11:22:43 +03:00
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
/**
|
|
|
|
* Use `unsubscribe_pubsub` to unregister callback.
|
|
|
|
*/
|
2020-10-15 21:23:18 +03:00
|
|
|
bool unsubscribe_pubsub(PubSubItem* pubsub_id);
|
2020-10-13 11:22:43 +03:00
|
|
|
|
2021-03-24 12:35:33 +03:00
|
|
|
/**
|
|
|
|
* Use `notify_pubsub` to notify subscribers.
|
|
|
|
*/
|
2020-10-15 21:23:18 +03:00
|
|
|
bool notify_pubsub(PubSub* pubsub, void* arg);
|
2020-10-13 11:22:43 +03:00
|
|
|
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-10-13 11:22:43 +03:00
|
|
|
/*
|
|
|
|
|
|
|
|
```C
|
|
|
|
// MANIFEST
|
|
|
|
// name="test"
|
|
|
|
// stack=128
|
|
|
|
|
|
|
|
void example_pubsub_handler(void* arg, void* ctx) {
|
|
|
|
printf("get %d from %s\n", *(uint32_t*)arg, (const char*)ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pubsub_test() {
|
|
|
|
const char* app_name = "test app";
|
|
|
|
|
|
|
|
PubSub example_pubsub;
|
|
|
|
init_pubsub(&example_pubsub);
|
|
|
|
|
|
|
|
if(!subscribe_pubsub(&example_pubsub, example_pubsub_handler, (void*)app_name)) {
|
|
|
|
printf("critical error\n");
|
|
|
|
flapp_exit(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t counter = 0;
|
|
|
|
while(1) {
|
|
|
|
notify_pubsub(&example_pubsub, (void*)&counter);
|
|
|
|
counter++;
|
|
|
|
|
|
|
|
osDelay(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
[FL-140] Core api dynamic records (#296)
* SYSTEM: tickless mode with deep sleep.
* Move FreeRTOS ticks to lptim2
* API: move all sumbodules init routines to one place. Timebase: working lptim2 at tick source.
* API Timebase: lp-timer routines, timer access safe zones prediction and synchronization. FreeRTOS: adjust configuration for tickless mode.
* NFC: support for tickless mode.
* API Timebase: improve tick error handling in IRQ. Apploader: use insomnia mode to run applications.
* BLE: prevent sleep while core2 starting
* HAL: nap while in insomnia mode
* init records work
* try to implement record delete
* tests and flapp
* flapp subsystem
* new core functions to get app stat, simplify core code
* fix thread termination
* add strdup to core
* fix tests
* Refactoring: remove all unusued parts, update API usage, aggreagate API sources and headers, new record storage
* Refactoring: update furi record api usage, cleanup code
* Fix broken merge for freertos apps
* Core, Target: fix compilation warnings
* Drop firmware target local
* HAL Timebase, Power, Clock: semaphore guarded access to clock and power modes, better sleep mode.
* SD-Filesystem: wait for all deps to arrive before adding widget. Core, BLE: disable debug dump to serial.
* delete old app example-ipc
* delete old app fatfs list
* fix strobe app, add input header
* delete old display driver
* comment old app qr-code
* fix sd-card test, add forced widget update
* remove unused new core test
* increase heap to 128k
* comment and assert old core tests
* fix syntax
Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2021-01-20 19:09:26 +03:00
|
|
|
*/
|