From 73d7f57f095b9d0f985b5e3bed1b9b7dc7514ced Mon Sep 17 00:00:00 2001
From: "Carlo A. Nicolau" <cnicolau@km3net.de>
Date: Mon, 21 Jun 2021 20:05:03 +0200
Subject: [PATCH] Debug Version (something still missing but basically working)

---
 host/python/codegen/digitalvariables.py       |   5 +
 host/python/codegen/entities/descriptors.py   |   4 +-
 .../codegen/generate_digitalvariables.py      |  12 +-
 .../output/templates/alarm_callbacks.tpl.c    |   2 +-
 .../commands/command_ALARM_ENABLE.tpl.c       |   2 +-
 .../command_ALARM_FIRECOUNT_GET.tpl.c         |   2 +-
 .../commands/command_ALARM_FIRED_GET.tpl.c    |   2 +-
 .../commands/command_ALARM_FIRED_RESET.tpl.c  |   2 +-
 .../commands/command_ALARM_MAXCOUNT_GET.tpl.c |   2 +-
 .../command_ALARM_MAXCOUNT_RESET.tpl.c        |   2 +-
 .../command_ALARM_THRESHOLD_GET.tpl.c         |   2 +-
 .../command_ALARM_THRESHOLD_SET.tpl.c         |   2 +-
 .../commands/command_ALARM_TIMEOUT_GET.tpl.c  |   2 +-
 .../commands/command_ALARM_TIMEOUT_SET.tpl.c  |   2 +-
 .../commands/command_BOARDTIME.tpl.c          |   2 +-
 .../templates/commands/command_ECHO1.tpl.c    |   2 +-
 .../templates/commands/command_ECHO32.tpl.c   |   2 +-
 .../templates/commands/command_ECHO4.tpl.c    |   2 +-
 .../commands/command_LASTCOMMANDTIME.tpl.c    |   2 +-
 .../commands/command_LASTERROR.tpl.c          |   2 +-
 .../commands/command_RESCUE_ENABLE.tpl.c      |   2 +-
 .../commands/command_RESCUE_STATUS_GET.tpl.c  |   2 +-
 .../command_RESCUE_STATUS_RESET.tpl.c         |   2 +-
 .../commands/command_RESCUE_TIMEOUT_GET.tpl.c |   2 +-
 .../commands/command_RESCUE_TIMEOUT_SET.tpl.c |   2 +-
 .../command_SENSOR_AVERAGE_GETALL.tpl.c       |   2 +-
 ...mmand_SENSOR_AVERAGING_PRESCALER_GET.tpl.c |   2 +-
 ...mmand_SENSOR_AVERAGING_PRESCALER_SET.tpl.c |   2 +-
 .../commands/command_SENSOR_GET_SINGLE.tpl.c  |   2 +-
 .../command_SENSOR_MAXVALUES_GETALL.tpl.c     |   2 +-
 .../command_SENSOR_MAXVALUE_RESET.tpl.c       |   2 +-
 .../command_SENSOR_OFFSETS_GETALL.tpl.c       |   2 +-
 .../command_SENSOR_VALUES_GETALL.tpl.c        |   2 +-
 .../commands/command_SWITCH_CONTROL.tpl.c     |   2 +-
 .../commands/command_USER_PIN_CONTROL.tpl.c   |   2 +-
 .../templates/commands/command_VALCHECK.tpl.c |   2 +-
 .../templates/commands/command_VERSION.tpl.c  |   2 +-
 micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3   |  80 ++---
 micro/BPD-V01-FIRMWARE.X/alarm_callbacks.c    |  36 +-
 micro/BPD-V01-FIRMWARE.X/errors.c             |  59 +++-
 micro/BPD-V01-FIRMWARE.X/errors.h             |   4 +
 .../generated/sources/commandstable.c         |   2 +-
 .../generated/sources/commandstable.h         |  10 +-
 .../generated/sources/datatypes.h             |   2 +-
 .../generated/sources/variables.c             |  22 +-
 .../generated/sources/variables.h             |   2 +-
 .../nbproject/configurations.xml              |   4 +-
 micro/BPD-V01-FIRMWARE.X/spurious.c           | 313 ++----------------
 micro/BPD-V01-FIRMWARE.X/spurious.h           |  22 +-
 micro/BPD-V01-FIRMWARE.X/timing.c             |   6 +
 50 files changed, 230 insertions(+), 421 deletions(-)

diff --git a/host/python/codegen/digitalvariables.py b/host/python/codegen/digitalvariables.py
index d109d31..645cf6d 100644
--- a/host/python/codegen/digitalvariables.py
+++ b/host/python/codegen/digitalvariables.py
@@ -116,6 +116,7 @@ class DigitalVariableList:
                 firmware_config=fwcfg,
                 name='FLAG_HYDRO_PWR_FAULT',
                 ioname='DIN_HYDRO_PWR_FLT',
+                active_low=True,
                 description='Fault status acquisition of 12V ISO HYDRO power line',
                 enum_index=var_enum_index,
                 alarm=DigitalAlarmDescriptor(
@@ -135,6 +136,7 @@ class DigitalVariableList:
                 firmware_config=fwcfg,
                 name='FLAG_LBL_PWR_FAULT',
                 ioname='DIN_LBL_PWR_FLT',
+                active_low=True,
                 description='Fault status acquisition of 12V ISO LBL power line',
                 enum_index=var_enum_index,
                 alarm=DigitalAlarmDescriptor(
@@ -154,6 +156,7 @@ class DigitalVariableList:
                 firmware_config=fwcfg,
                 name='FLAG_GLRA_FAULT',
                 ioname='DIN_GLR_A_FLT',
+                active_low=True,
                 description='Fault status acquisition of 12V GLENAIR-A power line',
                 enum_index=var_enum_index,
                 alarm=None
@@ -174,6 +177,7 @@ class DigitalVariableList:
                 firmware_config=fwcfg,
                 name='FLAG_GLRB_FAULT',
                 ioname='DIN_GLR_B_FLT',
+                active_low=True,
                 description='Fault status acquisition of 12V GLENAIR-B power line',
                 enum_index=var_enum_index,
                 alarm=None
@@ -194,6 +198,7 @@ class DigitalVariableList:
                 firmware_config=fwcfg,
                 name='FLAG_POWERBOARD_FAULT',
                 ioname='DIN_PWB_FLT',
+                active_low=True,
                 description='Fault status acquisition of 12V POWER BOARD power line',
                 enum_index=var_enum_index,
                 alarm=None
diff --git a/host/python/codegen/entities/descriptors.py b/host/python/codegen/entities/descriptors.py
index 6a070d8..59d4bd4 100644
--- a/host/python/codegen/entities/descriptors.py
+++ b/host/python/codegen/entities/descriptors.py
@@ -111,19 +111,21 @@ class DigitalVariableDescriptor(EntityDescriptor):
 
     _enum_indexes = list()
 
-    def __init__(self, firmware_config, name, ioname, description, enum_index=None, alarm=None):
+    def __init__(self, firmware_config, name, ioname, description, active_low=False, enum_index=None, alarm=None):
         """
         Coonbstructor
         :param firmware_config: the class FirmwareConfig
         :param name: name of the digital variable (used for code generation)
         :param ioname: name of the pin control macro (i.e. _SetHigh and _SetLow will be appended)
         :param description: human readeable description (used for comments)
+        :param active_low: True if the flag is active low (defaults to False)
         :param enum_index: index used if used if enumerating
         :param alarm: default values for the alarm
         """
         EntityDescriptor.__init__(self, firmware_config, name)
         self.ioname = ioname
         self.description = description
+        self.active_low = active_low
         self.enum_index = enum_index
         self.alarm = alarm
         # check enum uniqueness
diff --git a/host/python/codegen/generate_digitalvariables.py b/host/python/codegen/generate_digitalvariables.py
index b2f1e96..3887d40 100644
--- a/host/python/codegen/generate_digitalvariables.py
+++ b/host/python/codegen/generate_digitalvariables.py
@@ -92,6 +92,13 @@ def generate_digitalvariables_source(_digialvariables):
 digital_value_t [readfunc](void) {
     return (digital_value_t)(0 != [ioname]_GetValue());
 }
+"""
+
+    ioread_tpl_active_low = """
+// IO read function for variable [name] (active low)
+digital_value_t [readfunc](void) {
+    return (digital_value_t)(0 == [ioname]_GetValue());
+}
 """
 
     source_list = list()
@@ -132,7 +139,10 @@ digital_value_t [readfunc](void) {
 
         source_list.append(entry_source)
 
-        ioread_source = ioread_tpl
+        if digitalvariable.active_low:
+            ioread_source = ioread_tpl_active_low
+        else:
+            ioread_source = ioread_tpl
         ioread_source = ioread_source.replace('[name]', digitalvariable.name)
         ioread_source = ioread_source.replace('[readfunc]', digitalvariable.get_read_function_name())
         ioread_source = ioread_source.replace('[ioname]', digitalvariable.ioname)
diff --git a/host/python/codegen/output/templates/alarm_callbacks.tpl.c b/host/python/codegen/output/templates/alarm_callbacks.tpl.c
index fc31d45..cf84839 100644
--- a/host/python/codegen/output/templates/alarm_callbacks.tpl.c
+++ b/host/python/codegen/output/templates/alarm_callbacks.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: alarm_callbacks.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 #include "generated/sources/variables.h"
 
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c
index 360938e..537de8d 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_ENABLE.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_ENABLE.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c
index 751396e..a4a3664 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_FIRECOUNT_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_FIRECOUNT_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c
index b92cca9..2cb802a 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_FIRED_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c
index ad41dc3..863ac01 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_FIRED_RESET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_FIRED_RESET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c
index 3c45e73..22f373b 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_MAXCOUNT_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c
index f9dbe4e..55ce9f0 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_MAXCOUNT_RESET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_MAXCOUNT_RESET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c
index e4fae8d..e1c7eb2 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_THRESHOLD_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c
index 53ee066..910866f 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_THRESHOLD_SET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_THRESHOLD_SET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c
index 5598690..32f2cef 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_TIMEOUT_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c
index 79838fd..c72b52b 100644
--- a/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ALARM_TIMEOUT_SET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ALARM_TIMEOUT_SET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c b/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c
index 9751cc6..3ed0e0f 100644
--- a/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_BOARDTIME.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_BOARDTIME.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c b/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c
index c1677ba..04d2c30 100644
--- a/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ECHO1.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ECHO1.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c b/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c
index bd90820..bfaddcb 100644
--- a/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ECHO32.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ECHO32.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c b/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c
index 76d5139..02d9ed3 100644
--- a/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_ECHO4.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_ECHO4.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c b/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c
index 84db3ed..86822e1 100644
--- a/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_LASTCOMMANDTIME.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_LASTCOMMANDTIME.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c b/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c
index 05efcf1..4ef72aa 100644
--- a/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_LASTERROR.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_LASTERROR.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c
index 70444aa..d54bd95 100644
--- a/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_RESCUE_ENABLE.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_RESCUE_ENABLE.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c
index 9aa923f..8fc1e9f 100644
--- a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_RESCUE_STATUS_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c
index b8efe25..a734f84 100644
--- a/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_RESCUE_STATUS_RESET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_RESCUE_STATUS_RESET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c
index 4c67348..dcab360 100644
--- a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_RESCUE_TIMEOUT_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c
index 68e3c0a..4f2f368 100644
--- a/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_RESCUE_TIMEOUT_SET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_RESCUE_TIMEOUT_SET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c
index df362e0..e4069c7 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGE_GETALL.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_AVERAGE_GETALL.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c
index 4fdb9db..8f20d86 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_AVERAGING_PRESCALER_GET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c
index ad7a765..1dc3e74 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_AVERAGING_PRESCALER_SET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c
index 5942890..b82fda4 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_GET_SINGLE.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_GET_SINGLE.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c
index 1a88e0c..d2887ec 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUES_GETALL.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_MAXVALUES_GETALL.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c
index b7a1c7b..9baecc5 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_MAXVALUE_RESET.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_MAXVALUE_RESET.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c
index 011cb75..77bb070 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_OFFSETS_GETALL.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_OFFSETS_GETALL.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c b/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c
index 668dde7..6c1c32a 100644
--- a/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SENSOR_VALUES_GETALL.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SENSOR_VALUES_GETALL.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c b/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c
index 65f0b1a..cfd47c4 100644
--- a/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_SWITCH_CONTROL.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_SWITCH_CONTROL.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c b/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c
index f960e68..49be46e 100644
--- a/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_USER_PIN_CONTROL.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_USER_PIN_CONTROL.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c b/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c
index 5c9446e..fdf2544 100644
--- a/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_VALCHECK.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_VALCHECK.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/host/python/codegen/output/templates/commands/command_VERSION.tpl.c b/host/python/codegen/output/templates/commands/command_VERSION.tpl.c
index 59ef1a9..ee65478 100644
--- a/host/python/codegen/output/templates/commands/command_VERSION.tpl.c
+++ b/host/python/codegen/output/templates/commands/command_VERSION.tpl.c
@@ -1,5 +1,5 @@
 // Auto-generated template file: command_VERSION.tpl.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 
 #include "../typedefs.h"  
diff --git a/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3 b/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3
index 28c8c9b..2b08456 100644
--- a/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3
+++ b/micro/BPD-V01-FIRMWARE.X/BPD_MCC_config.mc3
@@ -1,9 +1,5 @@
 <config configVersion="1.1" device="PIC18F46K22" coreVersion="5.0.2">
    <usedClasses class="java.util.HashMap">
-      <entry>
-         <string>ADC</string>
-         <string>class com.microchip.mcc.mcu8.modules.adc.ADC</string>
-      </entry>
       <entry>
          <string>TMR0</string>
          <string>class com.microchip.mcc.mcu8.modules.tmr0_v1.TMR0</string>
@@ -12,6 +8,10 @@
          <string>System Module</string>
          <string>class com.microchip.mcc.mcu8.systemManager.SystemManager</string>
       </entry>
+      <entry>
+         <string>ADC</string>
+         <string>class com.microchip.mcc.mcu8.modules.adc.ADC</string>
+      </entry>
       <entry>
          <string>FVR</string>
          <string>class com.microchip.mcc.mcu8.modules.fvr.FVR</string>
@@ -32,14 +32,14 @@
          <string>CCP5</string>
          <string>class com.microchip.mcc.mcu8.modules.ccp_v3.CCP</string>
       </entry>
-      <entry>
-         <string>RESET</string>
-         <string>class com.microchip.mcc.mcu8.systemManager.reset.RESET</string>
-      </entry>
       <entry>
          <string>EUSART1</string>
          <string>class com.microchip.mcc.mcu8.modules.eusart.EUSART</string>
       </entry>
+      <entry>
+         <string>RESET</string>
+         <string>class com.microchip.mcc.mcu8.systemManager.reset.RESET</string>
+      </entry>
       <entry>
          <string>Interrupt Module</string>
          <string>class com.microchip.mcc.mcu8.interruptManager.InterruptManager</string>
@@ -1253,14 +1253,14 @@
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS" alias="1:7"/>
          <value>6</value>
       </entry>
-      <entry>
-         <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="EUSART1" name="DT1"/>
-         <value>disabled</value>
-      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS" alias="1:6"/>
          <value>5</value>
       </entry>
+      <entry>
+         <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="EUSART1" name="DT1"/>
+         <value>disabled</value>
+      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="INTCON2" settingAlias="nWPUEN" alias="enabled"/>
          <value>0</value>
@@ -1329,14 +1329,14 @@
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG1H" settingAlias="PRICLKEN" alias="OFF"/>
          <value>0</value>
       </entry>
-      <entry>
-         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR0" registerAlias="TMRI" settingAlias="order"/>
-         <value>1</value>
-      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="CCP5" name="pwmCCPRDisplayValue"/>
          <value>0</value>
       </entry>
+      <entry>
+         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR0" registerAlias="TMRI" settingAlias="order"/>
+         <value>1</value>
+      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR0" name="minPeriod"/>
          <value>0.000004</value>
@@ -1577,14 +1577,14 @@
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="RESET" registerAlias="RCON" settingAlias="POR" alias="occurred"/>
          <value>0</value>
       </entry>
-      <entry>
-         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ADC" registerAlias="ADCON0" settingAlias="CHS"/>
-         <value>AN0</value>
-      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS"/>
          <value>1:4</value>
       </entry>
+      <entry>
+         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ADC" registerAlias="ADCON0" settingAlias="CHS"/>
+         <value>AN0</value>
+      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="BRG16"/>
          <value>16bit_generator</value>
@@ -1706,11 +1706,11 @@
          <value>2</value>
       </entry>
       <entry>
-         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR0" registerAlias="T0CON" settingAlias="PS" alias="1:64"/>
+         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="CCP5" registerAlias="CCPCON" settingAlias="CCPM" alias="Rising edge"/>
          <value>5</value>
       </entry>
       <entry>
-         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="CCP5" registerAlias="CCPCON" settingAlias="CCPM" alias="Rising edge"/>
+         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR0" registerAlias="T0CON" settingAlias="PS" alias="1:64"/>
          <value>5</value>
       </entry>
       <entry>
@@ -2601,14 +2601,14 @@
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="Custom Name RB2"/>
          <value>AIN_GLR_A_I_MON</value>
       </entry>
-      <entry>
-         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="DTRXP" alias="inverted"/>
-         <value>1</value>
-      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="TMR2" registerAlias="TCON" settingAlias="TOUTPS" alias="1:16"/>
          <value>15</value>
       </entry>
+      <entry>
+         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="DTRXP" alias="inverted"/>
+         <value>1</value>
+      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="Pin Module" name="Custom Name RB3"/>
          <value>AIN_GLR_B_I_MON</value>
@@ -2821,14 +2821,14 @@
          <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="ADC" registerAlias="ADRESL" settingAlias="ADRESL"/>
          <value>0</value>
       </entry>
-      <entry>
-         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="FVR" registerAlias="FVRCON" settingAlias="FVREN"/>
-         <value>enabled</value>
-      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="TXSTA" settingAlias="SYNC" alias="asynchronous"/>
          <value>0</value>
       </entry>
+      <entry>
+         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="FVR" registerAlias="FVRCON" settingAlias="FVREN"/>
+         <value>enabled</value>
+      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="System Module" registerAlias="CONFIG2L" settingAlias="BORV" alias="190"/>
          <value>24</value>
@@ -3477,14 +3477,14 @@
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATD" settingAlias="LATD0" alias="clear"/>
          <value>0</value>
       </entry>
-      <entry>
-         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ADC" registerAlias="ADCON0" settingAlias="CHS" alias="AN14"/>
-         <value>14</value>
-      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="timerstart"/>
          <value>enabled</value>
       </entry>
+      <entry>
+         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="ADC" registerAlias="ADCON0" settingAlias="CHS" alias="AN14"/>
+         <value>14</value>
+      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="Pin Module" registerAlias="LATA" settingAlias="LATA4" alias="set"/>
          <value>1</value>
@@ -3842,11 +3842,11 @@
          <value>disabled</value>
       </entry>
       <entry>
-         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="FVR" registerAlias="FVRCON" settingAlias="FVRRDY"/>
+         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="ABDEN"/>
          <value>disabled</value>
       </entry>
       <entry>
-         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="ABDEN"/>
+         <key class="com.microchip.mcc.core.tokenManager.SettingKey" moduleName="FVR" registerAlias="FVRCON" settingAlias="FVRRDY"/>
          <value>disabled</value>
       </entry>
       <entry>
@@ -4357,14 +4357,14 @@
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ADC" name="AN17"/>
          <value>disabled</value>
       </entry>
-      <entry>
-         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="BRG16" alias="16bit_generator"/>
-         <value>1</value>
-      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="TMR2" name="TMR2_TMRIISRFunction"/>
          <value>ISR</value>
       </entry>
+      <entry>
+         <key class="com.microchip.mcc.core.tokenManager.OptionKey" moduleName="EUSART1" registerAlias="BAUDCON" settingAlias="BRG16" alias="16bit_generator"/>
+         <value>1</value>
+      </entry>
       <entry>
          <key class="com.microchip.mcc.core.tokenManager.CustomKey" moduleName="ADC" name="AN19"/>
          <value>disabled</value>
diff --git a/micro/BPD-V01-FIRMWARE.X/alarm_callbacks.c b/micro/BPD-V01-FIRMWARE.X/alarm_callbacks.c
index e28cd3e..4b03882 100644
--- a/micro/BPD-V01-FIRMWARE.X/alarm_callbacks.c
+++ b/micro/BPD-V01-FIRMWARE.X/alarm_callbacks.c
@@ -6,52 +6,68 @@
 
 // Callback function for alarm on analog variable MON_VEOC_RTN_I (DU backbone return current sensor signal acquisition )
 void alarm_MON_VEOC_RTN_I() {
-    // TODO implement auto-generated callback function alarm_MON_VEOC_RTN_I
+    // OPEN VEOC
+    switch_SWITCH_VEOC_RETURN_set_open_fromIRQ();
+    switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable MON_VEOC_FWR_I (DU backbone forward current sensor signal acquisition )
 void alarm_MON_VEOC_FWR_I() {
-    // TODO implement auto-generated callback function alarm_MON_VEOC_FWR_I
+    // OPEN VEOC
+    switch_SWITCH_VEOC_RETURN_set_open_fromIRQ();
+    switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable MON_HYDRO_I (HYDRO current sensor signal acquisition )
 void alarm_MON_HYDRO_I() {
-    // TODO implement auto-generated callback function alarm_MON_HYDRO_I
+    // OPEN HYDRO
+    switch_SWITCH_HYDRO_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable MON_LBL_I (LBL current sensor signal acquisition )
 void alarm_MON_LBL_I() {
-    // TODO implement auto-generated callback function alarm_MON_LBL_I
+    // OPEN LBL
+    switch_SWITCH_LBL_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable FLAG_DUL_ALARMPOS1 (DUL current limiting on VEOC direct alarm 1)
 void alarm_FLAG_DUL_ALARMPOS1() {
-    // TODO implement auto-generated callback function alarm_FLAG_DUL_ALARMPOS1
+    // OPEN VEOC
+    switch_SWITCH_VEOC_RETURN_set_open_fromIRQ();
+    switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable FLAG_DUL_ALARMPOS2 (DUL current limiting on VEOC direct alarm 2)
 void alarm_FLAG_DUL_ALARMPOS2() {
-    // TODO implement auto-generated callback function alarm_FLAG_DUL_ALARMPOS2
+    // OPEN VEOC
+    switch_SWITCH_VEOC_RETURN_set_open_fromIRQ();
+    switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable FLAG_DUL_ALARMNEG1 (DUL current limiting on VEOC return alarm 1)
 void alarm_FLAG_DUL_ALARMNEG1() {
-    // TODO implement auto-generated callback function alarm_FLAG_DUL_ALARMNEG1
+    // OPEN VEOC
+    switch_SWITCH_VEOC_RETURN_set_open_fromIRQ();
+    switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable FLAG_DUL_ALARMNEG2 (DUL current limiting on VEOC return alarm 2)
 void alarm_FLAG_DUL_ALARMNEG2() {
-    // TODO implement auto-generated callback function alarm_FLAG_DUL_ALARMNEG2
+    // OPEN VEOC
+    switch_SWITCH_VEOC_RETURN_set_open_fromIRQ();
+    switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable FLAG_HYDRO_PWR_FAULT (Fault status acquisition of 12V ISO HYDRO power line)
 void alarm_FLAG_HYDRO_PWR_FAULT() {
-    // TODO implement auto-generated callback function alarm_FLAG_HYDRO_PWR_FAULT
+    // OPEN HYDRO
+    switch_SWITCH_HYDRO_set_open_fromIRQ();
 }
 
 // Callback function for alarm on analog variable FLAG_LBL_PWR_FAULT (Fault status acquisition of 12V ISO LBL power line)
 void alarm_FLAG_LBL_PWR_FAULT() {
-    // TODO implement auto-generated callback function alarm_FLAG_LBL_PWR_FAULT
+    // OPEN LBL
+    switch_SWITCH_LBL_set_open_fromIRQ();
 }
 
 
diff --git a/micro/BPD-V01-FIRMWARE.X/errors.c b/micro/BPD-V01-FIRMWARE.X/errors.c
index c77c398..9c77ea7 100644
--- a/micro/BPD-V01-FIRMWARE.X/errors.c
+++ b/micro/BPD-V01-FIRMWARE.X/errors.c
@@ -9,6 +9,7 @@
 #include "errors.h"
 #include "hardware.h"
 #include "errorcodes.h"
+#include "generated/sources/variables.h"
 
 err_t errors_last_error = NOERR;
 
@@ -17,18 +18,56 @@ void error_notify(err_t _err) {
     // notify one error (probably to remove on final version)
     errors_last_error = _err;
     
-    // T O D O DEBUG remove USER PIN activity
-    //    DIGITAL_OUT_USER_J1_1_SetHigh();
-    //    DIGITAL_OUT_USER_J1_1_SetLow();
+    // Signal with some LED flashes
+    // TODO COMMENT OUT error_notify
+    INTERRUPT_GlobalInterruptDisable();
+    for(int k=0; k<8; k++) {
+        userpin_SWITCH_LED_D9_set_high();
+        userpin_SWITCH_LED_D10_set_high();
+        __delay_ms(50);
+        userpin_SWITCH_LED_D9_set_low();
+        userpin_SWITCH_LED_D10_set_low();
+        __delay_ms(50);        
+    }
+    for(int k=0; k<8; k++) {
+        userpin_SWITCH_LED_D9_set_high();
+        userpin_SWITCH_LED_D10_set_low();
+        __delay_ms(50);
+        userpin_SWITCH_LED_D9_set_low();
+        userpin_SWITCH_LED_D10_set_high();
+        __delay_ms(50);        
+    }
+    userpin_SWITCH_LED_D9_set_low();    
+    userpin_SWITCH_LED_D10_set_low();
+    INTERRUPT_GlobalInterruptEnable();
+    
 }
 
 void error_die_forever(void) {    
     // THIS SHOULD NEVE HAPPEN, PLEASE UNCOMMENT DURING DEVELOPMENT
-    //    INTERRUPT_GlobalInterruptDisable();
-    //    while(1) {
-    //        DIGITAL_OUT_USER_J1_1_SetHigh();
-    //        __delay_ms(250);
-    //        DIGITAL_OUT_USER_J1_1_SetLow();
-    //        __delay_ms(250);
-    //    }    
+    // TODO COMMENT OUT error_die_forever
+    INTERRUPT_GlobalInterruptDisable();
+    while(1) {
+        userpin_SWITCH_LED_D9_set_high();
+        userpin_SWITCH_LED_D10_set_high();
+        __delay_ms(250);
+        userpin_SWITCH_LED_D9_set_low();
+        userpin_SWITCH_LED_D10_set_low();
+        __delay_ms(250);
+    }    
+}
+
+// ... see .h
+void error_die_forever_fromIRQ(void) {    
+    // THIS SHOULD NEVE HAPPEN, PLEASE UNCOMMENT DURING DEVELOPMENT
+    // TODO COMMENT OUT error_die_forever_fromIRQ
+    INTERRUPT_GlobalInterruptDisable();
+    while(1) {
+        userpin_SWITCH_LED_D9_set_high();
+        userpin_SWITCH_LED_D10_set_low();
+        __delay_ms(250);
+        userpin_SWITCH_LED_D9_set_low();
+        userpin_SWITCH_LED_D10_set_high();
+        __delay_ms(250);
+    }    
 }
diff --git a/micro/BPD-V01-FIRMWARE.X/errors.h b/micro/BPD-V01-FIRMWARE.X/errors.h
index f2af29b..3859f83 100644
--- a/micro/BPD-V01-FIRMWARE.X/errors.h
+++ b/micro/BPD-V01-FIRMWARE.X/errors.h
@@ -17,5 +17,9 @@ extern err_t errors_last_error;
 void error_notify(err_t _err);
 void error_die_forever(void);
 
+// Just replicated versions of non-IRQ, to avoid compiler complaining:
+// "appears in multiple call graphs and has been duplicated by the compiler"
+void error_die_forever_fromIRQ(void); 
+
 #endif	// __ERRORS_H
 
diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c
index 8b6eb71..1422a91 100644
--- a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c
+++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.c
@@ -1,5 +1,5 @@
 // Auto-generated file: commandstable.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 #include "commandstable.h"
 
diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h
index a27cb26..fca07ab 100644
--- a/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h
+++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/commandstable.h
@@ -1,5 +1,5 @@
 // Auto-generated file: commandstable.h
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 #ifndef _AUTOGENERATED_COMMANDSTABLE_H
 #define _AUTOGENERATED_COMMANDSTABLE_H
@@ -190,10 +190,10 @@ err_t command_INVALID(void);
 #define COMMAND_TABLE_VERSION_NUM 34
 #define TEMPLATE_GENERATION_YEAR 2021
 #define TEMPLATE_GENERATION_MONTH 6
-#define TEMPLATE_GENERATION_DAY 20
-#define TEMPLATE_GENERATION_HOUR 5
-#define TEMPLATE_GENERATION_MINUTE 48
-#define TEMPLATE_GENERATION_SECOND 56
+#define TEMPLATE_GENERATION_DAY 21
+#define TEMPLATE_GENERATION_HOUR 19
+#define TEMPLATE_GENERATION_MINUTE 42
+#define TEMPLATE_GENERATION_SECOND 34
 
 
 #endif // _AUTOGENERATED_COMMANDSTABLE_H
diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h b/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h
index 246cea6..18f894a 100644
--- a/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h
+++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/datatypes.h
@@ -1,5 +1,5 @@
 // Auto-generated file: datatypes.h
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 #ifndef _AUTOGENERATED_DATATYPES_H
 #define _AUTOGENERATED_DATATYPES_H
diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c
index e24d7bf..95a3dd6 100644
--- a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c
+++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.c
@@ -1,5 +1,5 @@
 // Auto-generated file: variables.c
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 #include "variables.h"
 #include "../../configuration.h"
@@ -681,33 +681,33 @@ digital_value_t ioread_DIN_ALRMNEG2(void) {
 }
 
 
-// IO read function for variable FLAG_HYDRO_PWR_FAULT
+// IO read function for variable FLAG_HYDRO_PWR_FAULT (active low)
 digital_value_t ioread_DIN_HYDRO_PWR_FLT(void) {
-    return (digital_value_t)(0 != DIN_HYDRO_PWR_FLT_GetValue());
+    return (digital_value_t)(0 == DIN_HYDRO_PWR_FLT_GetValue());
 }
 
 
-// IO read function for variable FLAG_LBL_PWR_FAULT
+// IO read function for variable FLAG_LBL_PWR_FAULT (active low)
 digital_value_t ioread_DIN_LBL_PWR_FLT(void) {
-    return (digital_value_t)(0 != DIN_LBL_PWR_FLT_GetValue());
+    return (digital_value_t)(0 == DIN_LBL_PWR_FLT_GetValue());
 }
 
 
-// IO read function for variable FLAG_GLRA_FAULT
+// IO read function for variable FLAG_GLRA_FAULT (active low)
 digital_value_t ioread_DIN_GLR_A_FLT(void) {
-    return (digital_value_t)(0 != DIN_GLR_A_FLT_GetValue());
+    return (digital_value_t)(0 == DIN_GLR_A_FLT_GetValue());
 }
 
 
-// IO read function for variable FLAG_GLRB_FAULT
+// IO read function for variable FLAG_GLRB_FAULT (active low)
 digital_value_t ioread_DIN_GLR_B_FLT(void) {
-    return (digital_value_t)(0 != DIN_GLR_B_FLT_GetValue());
+    return (digital_value_t)(0 == DIN_GLR_B_FLT_GetValue());
 }
 
 
-// IO read function for variable FLAG_POWERBOARD_FAULT
+// IO read function for variable FLAG_POWERBOARD_FAULT (active low)
 digital_value_t ioread_DIN_PWB_FLT(void) {
-    return (digital_value_t)(0 != DIN_PWB_FLT_GetValue());
+    return (digital_value_t)(0 == DIN_PWB_FLT_GetValue());
 }
 
 
diff --git a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h
index e556c20..8122807 100644
--- a/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h
+++ b/micro/BPD-V01-FIRMWARE.X/generated/sources/variables.h
@@ -1,5 +1,5 @@
 // Auto-generated file: variables.h
-// Generation timestamp: 2021-06-20 05:48:56.170376
+// Generation timestamp: 2021-06-21 19:42:34.864200
 
 #ifndef _AUTOGENERATED_VARIABLES_H
 #define _AUTOGENERATED_VARIABLES_H
diff --git a/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml b/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml
index 5cb90fb..30174c0 100644
--- a/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml
+++ b/micro/BPD-V01-FIRMWARE.X/nbproject/configurations.xml
@@ -132,7 +132,7 @@
         <targetPluginBoard></targetPluginBoard>
         <platformTool>noID</platformTool>
         <languageToolchain>XC8</languageToolchain>
-        <languageToolchainVersion>2.20</languageToolchainVersion>
+        <languageToolchainVersion>2.00</languageToolchainVersion>
         <platform>2</platform>
       </toolsSet>
       <packs>
@@ -273,7 +273,7 @@
         <targetPluginBoard></targetPluginBoard>
         <platformTool>ICD3PlatformTool</platformTool>
         <languageToolchain>XC8</languageToolchain>
-        <languageToolchainVersion>2.20</languageToolchainVersion>
+        <languageToolchainVersion>2.00</languageToolchainVersion>
         <platform>2</platform>
       </toolsSet>
       <packs>
diff --git a/micro/BPD-V01-FIRMWARE.X/spurious.c b/micro/BPD-V01-FIRMWARE.X/spurious.c
index 44d3ab4..ef40d7f 100644
--- a/micro/BPD-V01-FIRMWARE.X/spurious.c
+++ b/micro/BPD-V01-FIRMWARE.X/spurious.c
@@ -12,256 +12,6 @@
 #include "generated/sources/variables.h"
 #include "mcc_generated_files/mcc.h"
 
-// analog and digital alarm structures are defined and initialized in file variables.c under generated folder
-
-//bool variable_is_analog_by_enum(enum_variable_number_t _variable_index) {
-//    switch(_variable_index) {        
-//        
-//        case VARIABLE_NUMBER_MON_DUL_BOARDTEMP:
-//        case VARIABLE_NUMBER_MON_TEMP2:
-//        case VARIABLE_NUMBER_MON_TEMP1:
-//        case VARIABLE_NUMBER_MON_VEOC_RTN_I:
-//        case VARIABLE_NUMBER_MON_VEOC_FWR_I:
-//        case VARIABLE_NUMBER_MON_HYDRO_I:
-//        case VARIABLE_NUMBER_MON_INPUT_V:
-//        case VARIABLE_NUMBER_MON_LBL_I:
-//        case VARIABLE_NUMBER_MON_GLRA_I:
-//        case VARIABLE_NUMBER_MON_GLRB_I:
-//        case VARIABLE_NUMBER_MON_PWB_I:
-//            return true;
-//            
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMPOS1:
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMPOS2:
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMNEG1:
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMNEG2:
-//        case VARIABLE_NUMBER_FLAG_HYDRO_PWR_FAULT:
-//        case VARIABLE_NUMBER_FLAG_LBL_PWR_FAULT:
-//        case VARIABLE_NUMBER_FLAG_GLRA_FAULT:
-//        case VARIABLE_NUMBER_FLAG_GLRB_FAULT:
-//        case VARIABLE_NUMBER_FLAG_POWERBOARD_FAULT:
-//        case VARIABLE_NUMBER_FLAG_GLRA_GOOD:
-//        case VARIABLE_NUMBER_FLAG_GLRB_GOOD:
-//        case VARIABLE_NUMBER_FLAG_POWERBOARD_GOOD:
-//            return false;
-//            
-//    }   
-//    error_die_forever();
-//    // never reached, just to avoid one warning
-//    return false;
-//}
-//
-//analog_variable_t* analog_variable_get_pointer_by_enum(enum_variable_number_t _variable_index) {
-//    switch(_variable_index) {
-//        
-//        case VARIABLE_NUMBER_MON_DUL_BOARDTEMP: return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_DUL_BOARDTEMP]);
-//        case VARIABLE_NUMBER_MON_TEMP2:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_TEMP2]);
-//        case VARIABLE_NUMBER_MON_TEMP1:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_TEMP1]);
-//        case VARIABLE_NUMBER_MON_VEOC_RTN_I:    return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_VEOC_RTN_I]);
-//        case VARIABLE_NUMBER_MON_VEOC_FWR_I:    return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_VEOC_FWR_I]);
-//        case VARIABLE_NUMBER_MON_HYDRO_I:       return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_HYDRO_I]);
-//        case VARIABLE_NUMBER_MON_INPUT_V:       return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_INPUT_V]);
-//        case VARIABLE_NUMBER_MON_LBL_I:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_LBL_I]);
-//        case VARIABLE_NUMBER_MON_GLRA_I:        return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_GLRA_I]);
-//        case VARIABLE_NUMBER_MON_GLRB_I:        return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_GLRB_I]);
-//        case VARIABLE_NUMBER_MON_PWB_I:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_PWB_I]);
-//        
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMPOS1:
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMPOS2:
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMNEG1:
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMNEG2:
-//        case VARIABLE_NUMBER_FLAG_HYDRO_PWR_FAULT:
-//        case VARIABLE_NUMBER_FLAG_LBL_PWR_FAULT:
-//        case VARIABLE_NUMBER_FLAG_GLRA_FAULT:
-//        case VARIABLE_NUMBER_FLAG_GLRB_FAULT:
-//        case VARIABLE_NUMBER_FLAG_POWERBOARD_FAULT:
-//        case VARIABLE_NUMBER_FLAG_GLRA_GOOD:
-//        case VARIABLE_NUMBER_FLAG_GLRB_GOOD:
-//        case VARIABLE_NUMBER_FLAG_POWERBOARD_GOOD:
-//            error_die_forever();
-//            break;   
-//            
-//    }
-//    error_die_forever();
-//    // never reached, just to avoid one warning
-//    return &(analog_variables[0]); 
-//}
-//
-//digital_variable_t* digital_variable_get_pointer_by_enum(enum_variable_number_t _variable_index) {
-//    switch(_variable_index) {       
-//        
-//        case VARIABLE_NUMBER_MON_DUL_BOARDTEMP:
-//        case VARIABLE_NUMBER_MON_TEMP2:
-//        case VARIABLE_NUMBER_MON_TEMP1:
-//        case VARIABLE_NUMBER_MON_VEOC_RTN_I:
-//        case VARIABLE_NUMBER_MON_VEOC_FWR_I:
-//        case VARIABLE_NUMBER_MON_HYDRO_I:
-//        case VARIABLE_NUMBER_MON_INPUT_V:
-//        case VARIABLE_NUMBER_MON_LBL_I:
-//        case VARIABLE_NUMBER_MON_GLRA_I:
-//        case VARIABLE_NUMBER_MON_GLRB_I:
-//        case VARIABLE_NUMBER_MON_PWB_I:   
-//            error_die_forever();
-//            break;       
-//            
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMPOS1:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMPOS1]);
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMPOS2:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMPOS2]);
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMNEG1:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMNEG1]);
-//        case VARIABLE_NUMBER_FLAG_DUL_ALARMNEG2:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMNEG2]);
-//        case VARIABLE_NUMBER_FLAG_HYDRO_PWR_FAULT:  return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_HYDRO_PWR_FAULT]);
-//        case VARIABLE_NUMBER_FLAG_LBL_PWR_FAULT:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_LBL_PWR_FAULT]);
-//        case VARIABLE_NUMBER_FLAG_GLRA_FAULT:       return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRA_FAULT]);
-//        case VARIABLE_NUMBER_FLAG_GLRB_FAULT:       return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRB_FAULT]);
-//        case VARIABLE_NUMBER_FLAG_POWERBOARD_FAULT: return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_POWERBOARD_FAULT]);
-//        case VARIABLE_NUMBER_FLAG_GLRA_GOOD:        return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRA_GOOD]);
-//        case VARIABLE_NUMBER_FLAG_GLRB_GOOD:        return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRB_GOOD]);
-//        case VARIABLE_NUMBER_FLAG_POWERBOARD_GOOD:  return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_POWERBOARD_GOOD]);
-//            
-//    }
-//    error_die_forever();
-//    // never reached, just to avoid one warning
-//    return &(digital_variables[0]);    
-//}
-//
-//bool alarm_is_analog_by_enum(enum_alarm_number_t _alarm_index) {    
-//    switch(_alarm_index) {          
-//        
-//        case ALARM_NUMBER_ALARM_SLOW_MON_DUL_BOARDTEMP:
-//        case ALARM_NUMBER_ALARM_FAST_MON_DUL_BOARDTEMP:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_TEMP2:
-//        case ALARM_NUMBER_ALARM_FAST_MON_TEMP2:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_TEMP1:
-//        case ALARM_NUMBER_ALARM_FAST_MON_TEMP1:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_VEOC_RTN_I:
-//        case ALARM_NUMBER_ALARM_FAST_MON_VEOC_RTN_I:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_VEOC_FWR_I:
-//        case ALARM_NUMBER_ALARM_FAST_MON_VEOC_FWR_I:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_HYDRO_I:
-//        case ALARM_NUMBER_ALARM_FAST_MON_HYDRO_I:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_INPUT_V:
-//        case ALARM_NUMBER_ALARM_FAST_MON_INPUT_V:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_LBL_I:
-//        case ALARM_NUMBER_ALARM_FAST_MON_LBL_I:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_GLRA_I:
-//        case ALARM_NUMBER_ALARM_FAST_MON_GLRA_I:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_GLRB_I:
-//        case ALARM_NUMBER_ALARM_FAST_MON_GLRB_I:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_PWB_I:
-//        case ALARM_NUMBER_ALARM_FAST_MON_PWB_I:
-//            return true;
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMPOS1:
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMPOS2:
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMNEG1:
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMNEG2:
-//        case ALARM_NUMBER_ALARM_FLAG_HYDRO_PWR_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_LBL_PWR_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRA_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRB_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_POWERBOARD_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRA_GOOD:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRB_GOOD:
-//        case ALARM_NUMBER_ALARM_FLAG_POWERBOARD_GOOD:
-//            return false;
-//            
-//    }        
-//    error_die_forever();
-//    // never reached, just to avoid one warning
-//    return false;
-//}
-//
-//analogalarm_info_t* alarm_get_analog_alarm_ptr_by_enum(enum_alarm_number_t _alarm_index) {   
-//    switch(_alarm_index) {          
-//        
-//        case ALARM_NUMBER_ALARM_SLOW_MON_DUL_BOARDTEMP: return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_DUL_BOARDTEMP].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_DUL_BOARDTEMP: return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_DUL_BOARDTEMP].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_TEMP2:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_TEMP2].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_TEMP2:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_TEMP2].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_TEMP1:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_TEMP1].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_TEMP1:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_TEMP1].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_VEOC_RTN_I:    return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_VEOC_RTN_I].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_VEOC_RTN_I:    return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_VEOC_RTN_I].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_VEOC_FWR_I:    return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_VEOC_FWR_I].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_VEOC_FWR_I:    return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_VEOC_FWR_I].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_HYDRO_I:       return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_HYDRO_I].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_HYDRO_I:       return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_HYDRO_I].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_INPUT_V:       return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_INPUT_V].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_INPUT_V:       return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_INPUT_V].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_LBL_I:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_LBL_I].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_LBL_I:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_LBL_I].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_GLRA_I:        return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_GLRA_I].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_GLRA_I:        return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_GLRA_I].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_GLRB_I:        return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_GLRB_I].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_GLRB_I:        return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_GLRB_I].alarms.fast);
-//        case ALARM_NUMBER_ALARM_SLOW_MON_PWB_I:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_PWB_I].alarms.slow);
-//        case ALARM_NUMBER_ALARM_FAST_MON_PWB_I:         return &(analog_variables[ANALOG_VARIABLE_INDEX_MON_PWB_I].alarms.fast);
-//        
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMPOS1:
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMPOS2:
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMNEG1:
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMNEG2:
-//        case ALARM_NUMBER_ALARM_FLAG_HYDRO_PWR_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_LBL_PWR_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRA_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRB_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_POWERBOARD_FAULT:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRA_GOOD:
-//        case ALARM_NUMBER_ALARM_FLAG_GLRB_GOOD:
-//        case ALARM_NUMBER_ALARM_FLAG_POWERBOARD_GOOD:
-//            error_die_forever();
-//            break; 
-//            
-//    }
-//    error_die_forever();
-//    // never reached, just to avoid one warning
-//    return &(analog_variables[0].alarms.slow);
-//}
-//
-//digitalalarm_info_t* alarm_get_digital_alarm_ptr_by_enum(enum_alarm_number_t _alarm_index) {
-//    switch(_alarm_index) {  
-//        
-//        case ALARM_NUMBER_ALARM_SLOW_MON_DUL_BOARDTEMP:
-//        case ALARM_NUMBER_ALARM_FAST_MON_DUL_BOARDTEMP:
-//        case ALARM_NUMBER_ALARM_SLOW_MON_TEMP2:        
-//        case ALARM_NUMBER_ALARM_FAST_MON_TEMP2:        
-//        case ALARM_NUMBER_ALARM_SLOW_MON_TEMP1:        
-//        case ALARM_NUMBER_ALARM_FAST_MON_TEMP1:        
-//        case ALARM_NUMBER_ALARM_SLOW_MON_VEOC_RTN_I:   
-//        case ALARM_NUMBER_ALARM_FAST_MON_VEOC_RTN_I:   
-//        case ALARM_NUMBER_ALARM_SLOW_MON_VEOC_FWR_I:   
-//        case ALARM_NUMBER_ALARM_FAST_MON_VEOC_FWR_I:   
-//        case ALARM_NUMBER_ALARM_SLOW_MON_HYDRO_I:      
-//        case ALARM_NUMBER_ALARM_FAST_MON_HYDRO_I:      
-//        case ALARM_NUMBER_ALARM_SLOW_MON_INPUT_V:      
-//        case ALARM_NUMBER_ALARM_FAST_MON_INPUT_V:      
-//        case ALARM_NUMBER_ALARM_SLOW_MON_LBL_I:        
-//        case ALARM_NUMBER_ALARM_FAST_MON_LBL_I:        
-//        case ALARM_NUMBER_ALARM_SLOW_MON_GLRA_I:       
-//        case ALARM_NUMBER_ALARM_FAST_MON_GLRA_I:       
-//        case ALARM_NUMBER_ALARM_SLOW_MON_GLRB_I:       
-//        case ALARM_NUMBER_ALARM_FAST_MON_GLRB_I:       
-//        case ALARM_NUMBER_ALARM_SLOW_MON_PWB_I:        
-//        case ALARM_NUMBER_ALARM_FAST_MON_PWB_I:            
-//            error_die_forever();
-//            break;     
-//        
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMPOS1:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMPOS1].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMPOS2:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMPOS2].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMNEG1:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMNEG1].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_DUL_ALARMNEG2:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_DUL_ALARMNEG2].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_HYDRO_PWR_FAULT:  return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_HYDRO_PWR_FAULT].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_LBL_PWR_FAULT:    return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_LBL_PWR_FAULT].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_GLRA_FAULT:       return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRA_FAULT].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_GLRB_FAULT:       return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRB_FAULT].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_POWERBOARD_FAULT: return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_POWERBOARD_FAULT].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_GLRA_GOOD:        return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRA_GOOD].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_GLRB_GOOD:        return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_GLRB_GOOD].alarm);
-//        case ALARM_NUMBER_ALARM_FLAG_POWERBOARD_GOOD:  return &(digital_variables[DIGITAL_VARIABLE_INDEX_FLAG_POWERBOARD_GOOD].alarm);
-//        
-//    }
-//    error_die_forever();
-//    // never reached, just to avoid one warning
-//    return &(digital_variables[0].alarm);
-//}
-
 bool* alarm_get_enable_ptr_by_enum(enum_alarm_number_t _alarm_index) {
     if(alarm_is_analog_by_enum(_alarm_index)) {
         return &(alarm_get_analog_alarm_ptr_by_enum(_alarm_index)->enabled);
@@ -278,14 +28,6 @@ alarm_timeout_t* alarm_get_timeout_ptr_by_enum(enum_alarm_number_t _alarm_index)
     }        
 }
 
-//alarm_timeout_t* alarm_get_timeout_counter_ptr_by_enum(enum_alarm_number_t _alarm_index) {
-//    if(alarm_is_analog_by_enum(_alarm_index)) {
-//        return &(alarm_get_analog_alarm_ptr_by_enum(_alarm_index)->timeout_counter);
-//    }else{
-//        return &(alarm_get_digital_alarm_ptr_by_enum(_alarm_index)->timeout_counter);        
-//    }        
-//}
-
 alarm_timeout_t* alarm_get_timeout_counter_max_ptr_by_enum(enum_alarm_number_t _alarm_index) {
     if(alarm_is_analog_by_enum(_alarm_index)) {
         return &(alarm_get_analog_alarm_ptr_by_enum(_alarm_index)->timeout_counter_max);
@@ -302,38 +44,31 @@ alarm_firecount_t* alarm_get_firecount_ptr_by_enum(enum_alarm_number_t _alarm_in
     }        
 }
 
-//DA RIVEDERE...
-//// open switch SWITCH_VEOC_RETURN and update switch structure (call from irq only)
-//void switch_SWITCH_VEOC_RETURN_set_open_irq(void) {
-//    DIGITAL_OUT_SWITCH_VEOC_RETURN_SetLow();
-//    switches.state_SWITCH_VEOC_RETURN = SWITCHSTATE_OPEN;
-//}
-//
-//// open switch SWITCH_VEOC_DIRECT and update switch structure (call from irq only)
-//void switch_SWITCH_VEOC_DIRECT_set_open_irq(void) {
-//    DIGITAL_OUT_SWITCH_VEOC_DIRECT_SetLow();
-//    switches.state_SWITCH_VEOC_DIRECT = SWITCHSTATE_OPEN;
-//}
-//
-//// open switch SWITCH_12V_ENABLE and update switch structure (call from irq only)
-//void switch_SWITCH_12V_ENABLE_set_open_irq(void) {
-//    DIGITAL_OUT_SWITCH_12V_ENABLE_SetLow();
-//    switches.state_SWITCH_12V_ENABLE = SWITCHSTATE_OPEN;
-//}
-//
-//// open switch SWITCH_HYDRO and update switch structure (call from irq only)
-//void switch_SWITCH_HYDRO_set_open_irq(void) {
-//    DIGITAL_OUT_SWITCH_HYDRO_SetLow();
-//    switches.state_SWITCH_HYDRO = SWITCHSTATE_OPEN;
-//}
-//
-//// open switch SWITCH_LBL and update switch structure (call from irq only)
-//void switch_SWITCH_LBL_set_open_irq(void) {
-//    DIGITAL_OUT_SWITCH_LBL_SetLow();
-//    switches.state_SWITCH_LBL = SWITCHSTATE_OPEN;
-//}
+// ...see .h
+void switch_SWITCH_VEOC_RETURN_set_open_fromIRQ(void) {
+    DOUT_375V_RTN_SWITCH_ON_OFF_SetLow();
+    switches.state_SWITCH_VEOC_RETURN = SWITCHSTATE_OPEN;
+}
+
+// ...see .h
+void switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ(void) {    
+    DOUT_375V_FWR_SWTCH_ON_OFF_SetLow();
+    switches.state_SWITCH_VEOC_DIRECT = SWITCHSTATE_OPEN;
+}
+
+// ...see .h
+void switch_SWITCH_HYDRO_set_open_fromIRQ(void) {
+    DOUT_HYDRO_SWITCH_ON_OFF_SetLow();
+    switches.state_SWITCH_HYDRO = SWITCHSTATE_OPEN;
+}
+
+// ...see .h
+void switch_SWITCH_LBL_set_open_fromIRQ(void) {
+    DOUT_LBL_SWITCH_ON_OFF_SetLow();
+    switches.state_SWITCH_LBL = SWITCHSTATE_OPEN;
+}
 
 void dummy_alarm_callback(void) {
     // should never be called
-    error_die_forever();
+    error_die_forever_fromIRQ();
 }
diff --git a/micro/BPD-V01-FIRMWARE.X/spurious.h b/micro/BPD-V01-FIRMWARE.X/spurious.h
index 5b9b17d..fa9881c 100644
--- a/micro/BPD-V01-FIRMWARE.X/spurious.h
+++ b/micro/BPD-V01-FIRMWARE.X/spurious.h
@@ -13,27 +13,19 @@
 #include "typedefs.h"
 #include "generated/sources/variables.h"
 
-// moved to pythonized stuff
-//bool variable_is_analog_by_enum(enum_variable_number_t _variable_index);
-//analog_variable_t* analog_variable_get_pointer_by_enum(enum_variable_number_t _variable_index);
-//bool alarm_is_analog_by_enum(enum_alarm_number_t _alarm_index);
-//analogalarm_info_t* alarm_get_analog_alarm_ptr_by_enum(enum_alarm_number_t _alarm_index);
-//digital_variable_t* digital_variable_get_pointer_by_enum(enum_variable_number_t _variable_index);
-//digitalalarm_info_t* alarm_get_digital_alarm_ptr_by_enum(enum_alarm_number_t _alarm_index);
-
 bool* alarm_get_enable_ptr_by_enum(enum_alarm_number_t _alarm_index);
 alarm_timeout_t* alarm_get_timeout_ptr_by_enum(enum_alarm_number_t _alarm_index);
 //alarm_timeout_t* alarm_get_timeout_counter_ptr_by_enum(enum_alarm_number_t _alarm_index);
 alarm_timeout_t* alarm_get_timeout_counter_max_ptr_by_enum(enum_alarm_number_t _alarm_index);
 alarm_firecount_t* alarm_get_firecount_ptr_by_enum(enum_alarm_number_t _alarm_index);
 
-//DA RINOMINARE
-//void switch_SWITCH_VEOC_RETURN_set_open_irq(void);
-//void switch_SWITCH_VEOC_DIRECT_set_open_irq(void);
-//void switch_SWITCH_12V_ENABLE_set_open_irq(void);
-//void switch_SWITCH_HYDRO_set_open_irq(void);
-//void switch_SWITCH_LBL_set_open_irq(void);
-
+// Switch control functions (to be called from IRQ)
+// they are just replicated versions of non-IRQ, to avoid compiler complaining:
+// "appears in multiple call graphs and has been duplicated by the compiler"
+void switch_SWITCH_VEOC_RETURN_set_open_fromIRQ(void);
+void switch_SWITCH_VEOC_DIRECT_set_open_fromIRQ(void);
+void switch_SWITCH_HYDRO_set_open_fromIRQ(void);
+void switch_SWITCH_LBL_set_open_fromIRQ(void);
 
 void dummy_alarm_callback(void);
 
diff --git a/micro/BPD-V01-FIRMWARE.X/timing.c b/micro/BPD-V01-FIRMWARE.X/timing.c
index 17e02ea..c0b0779 100644
--- a/micro/BPD-V01-FIRMWARE.X/timing.c
+++ b/micro/BPD-V01-FIRMWARE.X/timing.c
@@ -70,6 +70,12 @@ void timing_tick_irq(void) {
     // check if a second has elapsed
     if(_tick_counter_us >= 1000000) {        
         // ONE second elapsed!
+        
+        // TODO LED remove activity
+        if(userpin_SWITCH_LED_D9_get()) userpin_SWITCH_LED_D9_set_low();
+        else userpin_SWITCH_LED_D9_set_high();
+        
+        
         // increment number of seconds since last received command
         _timing_seconds_lc += 1;
         // increment number of seconds since reset
-- 
GitLab