tdse-tf_3-02

Controlador PID para derretidor de miel con control local via botones y remoto via WiFi
Index Commits Files Refs Submodules README
commit 4158e2ed163bc77bc457a517e90d728e77479b19
parent f87c96e2937bbc17637ee6749afb85126c080782
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Mon, 11 May 2026 14:26:59 -0300

Agregar variable para medir tiempo de ejecución promedio de un tick de `app`

Diffstat:
Mfirmware-nucleo/App/Src/app.c | 29++++++++++++++++++++++++-----
1 file changed, 24 insertions(+), 5 deletions(-)
diff --git a/firmware-nucleo/App/Src/app.c b/firmware-nucleo/App/Src/app.c
@@ -22,9 +22,10 @@
 #include "task_temp_sensor.h"
 #include "task_remote.h"
 
-#define G_APP_CNT_INI       0ul
-#define G_APP_TICK_CNT_INI  0ul
-#define G_APP_WCET_INI      0ul
+#define G_APP_CNT_INI           0ul
+#define G_APP_TICK_CNT_INI      0ul
+#define G_APP_WCET_INI          0ul
+#define G_APP_WCET_MEAN_SAMPLES 1000 // 1 second update rate
 
 #define TASK_X_WCET_INI            0ul
 #define TASK_X_WCET_SAMPLE_TIME_MS 10000ul
@@ -44,8 +45,12 @@ typedef struct {
 
 shared_data_type shared_data;
 uint32_t g_app_runtime_us;
-uint32_t g_app_WCET_us;        // Worst case execution time historically
-uint32_t g_app_WCET_sample_us; // Worst case execution time in sample time
+uint32_t g_app_runtime_us_mean;     // Mean of g_app_runtime_us in
+                                    // G_APP_WCET_MEAN_SAMPLES
+uint32_t g_app_runtime_us_mean_aux;
+uint32_t g_app_runtime_us_mean_cnt;
+uint32_t g_app_WCET_us;             // Worst case execution time historically
+uint32_t g_app_WCET_sample_us;      // Worst case execution time in sample time
 volatile uint32_t g_app_tick_cnt;
 
 const task_cfg_t task_cfg_list[] = {
@@ -96,6 +101,8 @@ void app_init(void)
 
     LOGGER_INFO("Done initializing `app`");
     g_app_WCET_us = G_APP_WCET_INI;
+    g_app_runtime_us_mean = g_app_runtime_us_mean_aux = G_APP_WCET_INI;
+    g_app_runtime_us_mean_cnt = 0;
 }
 
 void app_update(void)
@@ -151,6 +158,18 @@ void app_update(void)
             }
         }
 
+        if (G_APP_WCET_MEAN_SAMPLES == g_app_runtime_us_mean_cnt)
+        {
+            g_app_runtime_us_mean_cnt = 0;
+            g_app_runtime_us_mean = g_app_runtime_us_mean_aux / G_APP_WCET_MEAN_SAMPLES;
+            g_app_runtime_us_mean_aux = G_APP_WCET_INI;
+        }
+        else
+        {
+            g_app_runtime_us_mean_cnt++;
+            g_app_runtime_us_mean_aux += g_app_runtime_us;
+        }
+
         __asm("CPSID i");
         if (G_APP_TICK_CNT_INI < g_app_tick_cnt)
         {