Просмотр исходного кода

Subghz worker stuff removed. 50k of free memory won.

That's the output of free in the cli, after the change:

>: free
Free heap size: 95688
Total heap size: 182584
Minimum heap size: 85104
Maximum heap block: 94136
Pool free: 3628
Maximum pool block: 3584

Before the free heap size was ~58k.
antirez 3 лет назад
Родитель
Сommit
63ea908359
5 измененных файлов с 18 добавлено и 187 удалено
  1. 1 49
      app.c
  2. 3 8
      app.h
  3. 12 8
      app_subghz.c
  4. 0 120
      data_feed.c
  5. 2 2
      view_direct_sampling.c

+ 1 - 49
app.c

@@ -3,32 +3,6 @@
 
 #include "app.h"
 
-/* If this define is enabled, ProtoView is going to mess with the
- * otherwise opaque SubGhzWorker structure in order to disable
- * its filter for samples shorter than a given amount (30us at the
- * time I'm writing this comment).
- *
- * This structure must be taken in sync with the one of the firmware. */
-#define PROTOVIEW_DISABLE_SUBGHZ_FILTER 0
-
-#ifdef PROTOVIEW_DISABLE_SUBGHZ_FILTER
-struct SubGhzWorker {
-    FuriThread* thread;
-    FuriStreamBuffer* stream;
-
-    volatile bool running;
-    volatile bool overrun;
-
-    LevelDuration filter_level_duration;
-    bool filter_running;
-    uint16_t filter_duration;
-
-    SubGhzWorkerOverrunCallback overrun_callback;
-    SubGhzWorkerPairCallback pair_callback;
-    void* context;
-};
-#endif
-
 RawSamplesBuffer *RawSamples, *DetectedSamples;
 extern const SubGhzProtocolRegistry protoview_protocol_registry;
 
@@ -164,28 +138,11 @@ ProtoViewApp* protoview_app_alloc() {
     // Init Worker & Protocol
     app->txrx = malloc(sizeof(ProtoViewTxRx));
 
-    /* Setup rx worker and environment. */
+    /* Setup rx state. */
     app->txrx->freq_mod_changed = false;
     app->txrx->debug_timer_sampling = false;
     app->txrx->last_g0_change_time = DWT->CYCCNT;
     app->txrx->last_g0_value = false;
-    app->txrx->worker = subghz_worker_alloc();
-#ifdef PROTOVIEW_DISABLE_SUBGHZ_FILTER
-    app->txrx->worker->filter_running = 0;
-#endif
-    app->txrx->environment = subghz_environment_alloc();
-    subghz_environment_set_protocol_registry(
-        app->txrx->environment, (void*)&protoview_protocol_registry);
-    app->txrx->receiver =
-        subghz_receiver_alloc_init(app->txrx->environment);
-    subghz_receiver_set_filter(app->txrx->receiver,
-                               SubGhzProtocolFlag_Decodable);
-    subghz_worker_set_overrun_callback(
-        app->txrx->worker,
-        (SubGhzWorkerOverrunCallback)subghz_receiver_reset);
-    subghz_worker_set_pair_callback(
-        app->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode);
-    subghz_worker_set_context(app->txrx->worker, app->txrx->receiver);
     
     app->frequency = subghz_setting_get_default_frequency(app->setting);
     app->modulation = 0; /* Defaults to ProtoViewModulations[0]. */
@@ -218,11 +175,6 @@ void protoview_app_free(ProtoViewApp *app) {
     subghz_setting_free(app->setting);
 
     // Worker stuff.
-    if (!app->txrx->debug_timer_sampling) {
-        subghz_receiver_free(app->txrx->receiver);
-        subghz_environment_free(app->txrx->environment);
-        subghz_worker_free(app->txrx->worker);
-    }
     free(app->txrx);
 
     // Raw samples buffers.

+ 3 - 8
app.h

@@ -17,9 +17,6 @@
 #include <gui/modules/text_input.h>
 #include <notification/notification_messages.h>
 #include <lib/subghz/subghz_setting.h>
-#include <lib/subghz/subghz_worker.h>
-#include <lib/subghz/receiver.h>
-#include <lib/subghz/transmitter.h>
 #include <lib/subghz/registry.h>
 #include "raw_samples.h"
 
@@ -82,10 +79,7 @@ struct ProtoViewTxRx {
     bool freq_mod_changed;      /* The user changed frequency and/or modulation
                                    from the interface. There is to restart the
                                    radio with the right parameters. */
-    SubGhzWorker* worker;       /* Our background worker. */
-    SubGhzEnvironment* environment;
-    SubGhzReceiver* receiver;
-    TxRxState txrx_state; /* Receiving, idle or sleeping? */
+    TxRxState txrx_state;       /* Receiving, idle or sleeping? */
 
     /* Timer sampling mode state. */
     bool debug_timer_sampling;  /* Read data from GDO0 in a busy loop. Only
@@ -238,7 +232,7 @@ typedef struct ProtoViewDecoder {
 
 extern RawSamplesBuffer *RawSamples, *DetectedSamples;
 
-/* app_radio.c */
+/* app_subghz.c */
 void radio_begin(ProtoViewApp* app);
 uint32_t radio_rx(ProtoViewApp* app);
 void radio_idle(ProtoViewApp* app);
@@ -247,6 +241,7 @@ void radio_sleep(ProtoViewApp* app);
 void raw_sampling_worker_start(ProtoViewApp *app);
 void raw_sampling_worker_stop(ProtoViewApp *app);
 void radio_tx_signal(ProtoViewApp *app, FuriHalSubGhzAsyncTxCallback data_feeder, void *ctx);
+void protoview_rx_callback(bool level, uint32_t duration, void* context);
 
 /* signal.c */
 uint32_t duration_delta(uint32_t a, uint32_t b);

+ 12 - 8
app_subghz.c

@@ -57,6 +57,16 @@ void radio_begin(ProtoViewApp* app) {
 
 /* ================================= Reception ============================== */
 
+/* We avoid the subghz provided abstractions and put the data in our
+ * simple abstraction: the RawSamples circular buffer. */
+void protoview_rx_callback(bool level, uint32_t duration, void* context) {
+    UNUSED(context);
+    /* Add data to the circular buffer. */
+    raw_samples_add(RawSamples, level, duration);
+    // FURI_LOG_E(TAG, "FEED: %d %d", (int)level, (int)duration);
+    return;
+}
+
 /* Setup subghz to start receiving using a background worker. */
 uint32_t radio_rx(ProtoViewApp* app) {
     furi_assert(app);
@@ -73,10 +83,7 @@ uint32_t radio_rx(ProtoViewApp* app) {
     furi_hal_subghz_flush_rx();
     furi_hal_subghz_rx();
     if (!app->txrx->debug_timer_sampling) {
-
-        furi_hal_subghz_start_async_rx(subghz_worker_rx_callback,
-                                       app->txrx->worker);
-        subghz_worker_start(app->txrx->worker);
+        furi_hal_subghz_start_async_rx(protoview_rx_callback, NULL);
     } else {
         raw_sampling_worker_start(app);
     }
@@ -90,10 +97,7 @@ void radio_rx_end(ProtoViewApp* app) {
 
     if (app->txrx->txrx_state == TxRxStateRx) {
         if (!app->txrx->debug_timer_sampling) {
-            if(subghz_worker_is_running(app->txrx->worker)) {
-                subghz_worker_stop(app->txrx->worker);
-                furi_hal_subghz_stop_async_rx();
-            }
+            furi_hal_subghz_stop_async_rx();
         } else {
             raw_sampling_worker_stop(app);
         }

+ 0 - 120
data_feed.c

@@ -1,120 +0,0 @@
-/* Copyright (C) 2022-2023 Salvatore Sanfilippo -- All Rights Reserved
- * See the LICENSE file for information about the license. */
-
-#include <inttypes.h>
-#include <lib/flipper_format/flipper_format_i.h>
-#include <furi/core/string.h>
-#include <lib/subghz/registry.h>
-#include <lib/subghz/protocols/base.h>
-#include "raw_samples.h"
-
-#define TAG "PROTOVIEW-protocol"
-
-const SubGhzProtocol subghz_protocol_protoview;
-
-/* The feed() method puts data in the RawSamples global (protected by
- * a mutex). */
-extern RawSamplesBuffer *RawSamples;
-
-/* This is totally dummy: we just define the decoder base for the async
- * system to work but we don't really use it if not to collect raw
- * data via the feed() method. */
-typedef struct SubGhzProtocolDecoderprotoview {
-    SubGhzProtocolDecoderBase base;
-} SubGhzProtocolDecoderprotoview;
-
-void* subghz_protocol_decoder_protoview_alloc(SubGhzEnvironment* environment) {
-    UNUSED(environment);
-
-    SubGhzProtocolDecoderprotoview* instance =
-        malloc(sizeof(SubGhzProtocolDecoderprotoview));
-    instance->base.protocol = &subghz_protocol_protoview;
-    return instance;
-}
-
-void subghz_protocol_decoder_protoview_free(void* context) {
-    furi_assert(context);
-    SubGhzProtocolDecoderprotoview* instance = context;
-    free(instance);
-}
-
-void subghz_protocol_decoder_protoview_reset(void* context) {
-    furi_assert(context);
-}
-
-/* That's the only thig we really use of the protocol decoder
- * implementation. We avoid the subghz provided abstractions and put
- * the data in our simple abstraction: the RawSamples circular buffer. */
-void subghz_protocol_decoder_protoview_feed(void* context, bool level, uint32_t duration) {
-    furi_assert(context);
-    UNUSED(context);
-
-    /* Add data to the circular buffer. */
-    raw_samples_add(RawSamples, level, duration);
-    // FURI_LOG_E(TAG, "FEED: %d %d", (int)level, (int)duration);
-    return;
-}
-
-/* The only scope of this method is to avoid duplicated messages in the
- * Subghz history, which we don't use. */
-uint8_t subghz_protocol_decoder_protoview_get_hash_data(void* context) {
-    furi_assert(context);
-    return 123;
-}
-
-/* Not used. */
-bool subghz_protocol_decoder_protoview_serialize(
-    void* context,
-    FlipperFormat* flipper_format,
-    SubGhzRadioPreset* preset)
-{
-    UNUSED(context);
-    UNUSED(flipper_format);
-    UNUSED(preset);
-    return false;
-}
-
-/* Not used. */
-bool subghz_protocol_decoder_protoview_deserialize(void* context, FlipperFormat* flipper_format)
-{
-    UNUSED(context);
-    UNUSED(flipper_format);
-    return false;
-}
-
-void subhz_protocol_decoder_protoview_get_string(void* context, FuriString* output)
-{
-    furi_assert(context);
-    furi_string_cat_printf(output, "Protoview");
-}
-
-const SubGhzProtocolDecoder subghz_protocol_protoview_decoder = {
-    .alloc = subghz_protocol_decoder_protoview_alloc,
-    .free = subghz_protocol_decoder_protoview_free,
-    .reset = subghz_protocol_decoder_protoview_reset,
-    .feed = subghz_protocol_decoder_protoview_feed,
-    .get_hash_data = subghz_protocol_decoder_protoview_get_hash_data,
-    .serialize = subghz_protocol_decoder_protoview_serialize,
-    .deserialize = subghz_protocol_decoder_protoview_deserialize,
-    .get_string = subhz_protocol_decoder_protoview_get_string,
-};
-
-/* Well, we don't really target a specific protocol. So let's put flags
- * that make sense. */
-const SubGhzProtocol subghz_protocol_protoview = {
-    .name = "Protoview",
-    .type = SubGhzProtocolTypeStatic,
-    .flag = SubGhzProtocolFlag_AM | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable,
-    .decoder = &subghz_protocol_protoview_decoder,
-};
-
-/* Our table has just the single dummy protocol we defined for the
- * sake of data collection. */
-const SubGhzProtocol* protoview_protocol_registry_items[] = {
-    &subghz_protocol_protoview,
-};
-
-const SubGhzProtocolRegistry protoview_protocol_registry = {
-    .items = protoview_protocol_registry_items,
-    .size = COUNT_OF(protoview_protocol_registry_items)
-};

+ 2 - 2
view_direct_sampling.c

@@ -48,7 +48,7 @@ void view_enter_direct_sampling(ProtoViewApp *app) {
     if (app->txrx->txrx_state == TxRxStateRx &&
         !app->txrx->debug_timer_sampling)
     {
-        subghz_worker_stop(app->txrx->worker);
+        furi_hal_subghz_stop_async_rx();
     } else {
         raw_sampling_worker_stop(app);
     }
@@ -59,7 +59,7 @@ void view_exit_direct_sampling(ProtoViewApp *app) {
     if (app->txrx->txrx_state == TxRxStateRx &&
         !app->txrx->debug_timer_sampling)
     {
-        subghz_worker_start(app->txrx->worker);
+        furi_hal_subghz_start_async_rx(protoview_rx_callback, NULL);
     } else {
         raw_sampling_worker_start(app);
     }