summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2020-07-10 14:53:45 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2020-07-10 14:53:45 +0200
commit4065d4f5d506d7a0e562e98b06d2afd01e529df6 (patch)
tree804a83e8e9e3814aeb2258088cd851a120f61861 /src
parentda828589e00f1d709053431c2249cb53c5cee37f (diff)
add resistive load driver for energy measurement device evaluation
Diffstat (limited to 'src')
-rw-r--r--src/driver/resistive_load.cc120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/driver/resistive_load.cc b/src/driver/resistive_load.cc
new file mode 100644
index 0000000..419c6c0
--- /dev/null
+++ b/src/driver/resistive_load.cc
@@ -0,0 +1,120 @@
+#include "driver/resistive_load.h"
+#include "driver/gpio.h"
+#include "arch.h"
+
+#ifndef RESISTIVE_LOAD_PIN1
+#error RESISTIVE_LOAD_PIN1 must be set
+#endif
+
+#ifndef RESISTIVE_LOAD_PIN2
+#error RESISTIVE_LOAD_PIN2 must be set
+#endif
+
+#ifndef RESISTIVE_LOAD_PIN3
+#error RESISTIVE_LOAD_PIN3 must be set
+#endif
+
+#ifndef RESISTIVE_LOAD_PIN4
+#error RESISTIVE_LOAD_PIN4 must be set
+#endif
+
+void ResistiveLoad::setup()
+{
+ gpio.output(RESISTIVE_LOAD_PIN1, 0);
+ gpio.output(RESISTIVE_LOAD_PIN2, 0);
+ gpio.output(RESISTIVE_LOAD_PIN3, 0);
+ gpio.output(RESISTIVE_LOAD_PIN4, 0);
+}
+
+void ResistiveLoad::switchToNone()
+{
+ gpio.write(RESISTIVE_LOAD_PIN1, 0);
+ gpio.write(RESISTIVE_LOAD_PIN2, 0);
+ gpio.write(RESISTIVE_LOAD_PIN3, 0);
+ gpio.write(RESISTIVE_LOAD_PIN4, 0);
+}
+
+void ResistiveLoad::switchTo750()
+{
+ gpio.write(RESISTIVE_LOAD_PIN1, 1);
+ gpio.write(RESISTIVE_LOAD_PIN2, 1);
+ gpio.write(RESISTIVE_LOAD_PIN3, 0);
+ gpio.write(RESISTIVE_LOAD_PIN4, 0);
+}
+
+void ResistiveLoad::switchTo1K0()
+{
+ gpio.write(RESISTIVE_LOAD_PIN1, 1);
+ gpio.write(RESISTIVE_LOAD_PIN2, 0);
+ gpio.write(RESISTIVE_LOAD_PIN3, 0);
+ gpio.write(RESISTIVE_LOAD_PIN4, 0);
+}
+
+void ResistiveLoad::switchTo2K4()
+{
+ gpio.write(RESISTIVE_LOAD_PIN1, 0);
+ gpio.write(RESISTIVE_LOAD_PIN2, 1);
+ gpio.write(RESISTIVE_LOAD_PIN3, 0);
+ gpio.write(RESISTIVE_LOAD_PIN4, 1);
+}
+
+void ResistiveLoad::switchTo3K3()
+{
+ gpio.write(RESISTIVE_LOAD_PIN1, 0);
+ gpio.write(RESISTIVE_LOAD_PIN2, 1);
+ gpio.write(RESISTIVE_LOAD_PIN3, 0);
+ gpio.write(RESISTIVE_LOAD_PIN4, 0);
+}
+
+void ResistiveLoad::switchTo10K()
+{
+ gpio.write(RESISTIVE_LOAD_PIN1, 0);
+ gpio.write(RESISTIVE_LOAD_PIN2, 0);
+ gpio.write(RESISTIVE_LOAD_PIN3, 0);
+ gpio.write(RESISTIVE_LOAD_PIN4, 1);
+}
+
+void ResistiveLoad::switchTo47K()
+{
+ gpio.write(RESISTIVE_LOAD_PIN1, 0);
+ gpio.write(RESISTIVE_LOAD_PIN2, 0);
+ gpio.write(RESISTIVE_LOAD_PIN3, 1);
+ gpio.write(RESISTIVE_LOAD_PIN4, 0);
+}
+
+void ResistiveLoad::nop1K0(unsigned int duration_ms)
+{
+ switchTo1K0();
+ arch.delay_ms(duration_ms);
+ switchToNone();
+}
+
+void ResistiveLoad::nop2K4(unsigned int duration_ms)
+{
+ switchTo2K4();
+ arch.delay_ms(duration_ms);
+ switchToNone();
+}
+
+void ResistiveLoad::nop3K3(unsigned int duration_ms)
+{
+ switchTo3K3();
+ arch.delay_ms(duration_ms);
+ switchToNone();
+}
+
+void ResistiveLoad::nop10K(unsigned int duration_ms)
+{
+ switchTo10K();
+ arch.delay_ms(duration_ms);
+ switchToNone();
+}
+
+void ResistiveLoad::nop47K(unsigned int duration_ms)
+{
+ switchTo47K();
+ arch.delay_ms(duration_ms);
+ switchToNone();
+}
+
+ResistiveLoad resistiveLoad;