From 44d6714b69b9979960a4b2f8e18595f299cde373 Mon Sep 17 00:00:00 2001
From: Theo Arends <11044339+arendst@users.noreply.github.com>
Date: Wed, 7 Nov 2018 11:57:28 +0100
Subject: [PATCH] Moved all func ptr tables to RAM
Moved all function pointer tables to RAM to check performance issues
---
sonoff/sonoff.h | 10 ++++++++++
sonoff/xdrv_interface.ino | 4 +---
sonoff/xdsp_interface.ino | 5 +++++
sonoff/xnrg_interface.ino | 5 +++++
sonoff/xsns_interface.ino | 12 ++++++------
5 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h
index 4c6abee0d..1e27988e0 100644
--- a/sonoff/sonoff.h
+++ b/sonoff/sonoff.h
@@ -20,6 +20,16 @@
#ifndef _SONOFF_H_
#define _SONOFF_H_
+/*********************************************************************************************\
+ * Performance ROM (PROGMEM) vs RAM (RODATA)
+\*********************************************************************************************/
+
+//#define XFUNC_PTR_IN_ROM // Enable for keeping tables in ROM (PROGMEM) which seem to have access issues on some flash types
+
+/*********************************************************************************************\
+ * Default sensor states
+\*********************************************************************************************/
+
#define USE_DHT // Default DHT11 sensor needs no external library
#define USE_ENERGY_SENSOR // Use energy sensors (+14k code)
#define USE_HLW8012 // Use energy sensor for Sonoff Pow and WolfBlitz
diff --git a/sonoff/xdrv_interface.ino b/sonoff/xdrv_interface.ino
index 11699543c..0f0171e20 100644
--- a/sonoff/xdrv_interface.ino
+++ b/sonoff/xdrv_interface.ino
@@ -17,9 +17,7 @@
along with this program. If not, see .
*/
-//#define XDRV_IN_ROM
-
-#ifdef XDRV_IN_ROM
+#ifdef XFUNC_PTR_IN_ROM
boolean (* const xdrv_func_ptr[])(byte) PROGMEM = { // Driver Function Pointers
#else
boolean (* const xdrv_func_ptr[])(byte) = { // Driver Function Pointers
diff --git a/sonoff/xdsp_interface.ino b/sonoff/xdsp_interface.ino
index 8d6d5a814..06fbf01dc 100644
--- a/sonoff/xdsp_interface.ino
+++ b/sonoff/xdsp_interface.ino
@@ -17,7 +17,12 @@
along with this program. If not, see .
*/
+#ifdef XFUNC_PTR_IN_ROM
boolean (* const xdsp_func_ptr[])(byte) PROGMEM = { // Display Function Pointers
+#else
+boolean (* const xdsp_func_ptr[])(byte) = { // Display Function Pointers
+#endif
+
#ifdef XDSP_01
&Xdsp01,
#endif
diff --git a/sonoff/xnrg_interface.ino b/sonoff/xnrg_interface.ino
index 015d5d284..cea14e47c 100644
--- a/sonoff/xnrg_interface.ino
+++ b/sonoff/xnrg_interface.ino
@@ -17,7 +17,12 @@
along with this program. If not, see .
*/
+#ifdef XFUNC_PTR_IN_ROM
int (* const xnrg_func_ptr[])(byte) PROGMEM = { // Energy driver Function Pointers
+#else
+int (* const xnrg_func_ptr[])(byte) = { // Energy driver Function Pointers
+#endif
+
#ifdef XNRG_01
&Xnrg01,
#endif
diff --git a/sonoff/xsns_interface.ino b/sonoff/xsns_interface.ino
index adfebea22..a3cf4d772 100644
--- a/sonoff/xsns_interface.ino
+++ b/sonoff/xsns_interface.ino
@@ -17,13 +17,12 @@
along with this program. If not, see .
*/
-//#define XSNS_IN_ROM
-
-#ifdef XSNS_IN_ROM
+#ifdef XFUNC_PTR_IN_ROM
boolean (* const xsns_func_ptr[])(byte) PROGMEM = { // Sensor Function Pointers for simple implementation of sensors
#else
boolean (* const xsns_func_ptr[])(byte) = { // Sensor Function Pointers for simple implementation of sensors
#endif
+
#ifdef XSNS_01
&Xsns01,
#endif
@@ -266,11 +265,12 @@ boolean (* const xsns_func_ptr[])(byte) = { // Sensor Function Pointers for sim
const uint8_t xsns_present = sizeof(xsns_func_ptr) / sizeof(xsns_func_ptr[0]); // Number of External Sensors found
uint8_t xsns_index = 0;
-#ifdef XSNS_IN_ROM
+#ifdef XFUNC_PTR_IN_ROM
const uint8_t kXsnsList[] PROGMEM = {
#else
const uint8_t kXsnsList[] = {
#endif
+
#ifdef XSNS_01
XSNS_01,
#endif
@@ -518,7 +518,7 @@ const uint8_t kXsnsList[] = {
boolean XsnsEnabled(byte sns_index)
{
if (sns_index < sizeof(kXsnsList)) {
-#ifdef XSNS_IN_ROM
+#ifdef XFUNC_PTR_IN_ROM
uint8_t index = pgm_read_byte(kXsnsList + sns_index);
#else
uint8_t index = kXsnsList[sns_index];
@@ -532,7 +532,7 @@ boolean XsnsPresent(byte sns_index)
{
uint8_t index = 0;
for (byte i = 0; i < sizeof(kXsnsList); i++) {
-#ifdef XSNS_IN_ROM
+#ifdef XFUNC_PTR_IN_ROM
index = pgm_read_byte(kXsnsList + i);
#else
index = kXsnsList[i];