Save 64 bytes RAM per thermistor by moving median_buffer to AHB0.
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sat, 20 Dec 2014 08:26:49 +0000 (10:26 +0200)
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>
Sat, 20 Dec 2014 08:26:49 +0000 (10:26 +0200)
Also we only need one median_buffer (total), because each thermistor
uses it only when quick_median() is running. Actual data is stored
in the queue. So this patch reuses the same buffer for all thermistors.

src/modules/tools/temperaturecontrol/Thermistor.cpp
src/modules/tools/temperaturecontrol/Thermistor.h

index ae98755..234ae84 100644 (file)
@@ -14,6 +14,7 @@
 #include "ConfigValue.h"
 #include "libs/Median.h"
 #include "Thermistor.h"
+#include "libs/platform_memory.h"
 
 // a const list of predefined thermistors
 #include "predefined_thermistors.h"
 #define r2_checksum                        CHECKSUM("r2")
 #define thermistor_pin_checksum            CHECKSUM("thermistor_pin")
 
+
+// Temporary buffer used only during median computation.
+// Shared between all thermistors.
+static uint16_t *median_buffer = NULL;
+
 Thermistor::Thermistor()
 {
+    if (median_buffer == NULL)
+    {
+        median_buffer = static_cast<uint16_t*>(AHB0.alloc(QUEUE_LEN * sizeof(uint16_t)));
+    }
 }
 
 Thermistor::~Thermistor()
index 2cb28e3..199fec3 100644 (file)
@@ -40,8 +40,6 @@ class Thermistor : public TempSensor
         Pin  thermistor_pin;
 
         RingBuffer<uint16_t,QUEUE_LEN> queue;  // Queue of readings
-        uint16_t median_buffer[QUEUE_LEN];
-        
 };
 
 #endif