summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart <lekaiser@uos.de>2020-07-17 12:39:15 +0200
committerLennart <lekaiser@uos.de>2020-07-17 12:39:15 +0200
commit5c4045862bf55be0b8dc755ac3d5c5bd24b5fedf (patch)
treec104a31c95b5a6498f9c195da4cdc406286d9768
parentdd188370afa340d3b717b8747890bc304c0e3346 (diff)
parent52f23fad43b47c6cebb38fa387c39d0e27a12797 (diff)
Merge branch 'master' into state-duration-timers
-rw-r--r--Makefile13
-rw-r--r--include/driver/resistive_load.h35
-rw-r--r--model/driver/resistive_load.dfa44
-rw-r--r--src/driver/resistive_load.cc120
4 files changed, 212 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index d008049..45501e2 100644
--- a/Makefile
+++ b/Makefile
@@ -130,6 +130,19 @@ ifneq ($(findstring sharp96,${drivers}), )
COMMON_FLAGS += -DSHARP96_CS_PIN=GPIO::${sharp96_cs_pin}
endif
+ifneq ($(findstring resistive_load,${drivers}), )
+ CXX_TARGETS += src/driver/resistive_load.cc
+ resistor1_pin ?= p3_0
+ resistor2_pin ?= p3_1
+ resistor3_pin ?= p3_2
+ resistor4_pin ?= p3_3
+ COMMON_FLAGS += -DDRIVER_RESISTIVE_LOAD
+ COMMON_FLAGS += -DRESISTIVE_LOAD_PIN1=GPIO::${resistor1_pin}
+ COMMON_FLAGS += -DRESISTIVE_LOAD_PIN2=GPIO::${resistor2_pin}
+ COMMON_FLAGS += -DRESISTIVE_LOAD_PIN3=GPIO::${resistor3_pin}
+ COMMON_FLAGS += -DRESISTIVE_LOAD_PIN4=GPIO::${resistor4_pin}
+endif
+
ifneq ($(findstring softi2c,${drivers}), )
CXX_TARGETS += src/driver/soft_i2c.cc
COMMON_FLAGS += -DDRIVER_SOFTI2C
diff --git a/include/driver/resistive_load.h b/include/driver/resistive_load.h
new file mode 100644
index 0000000..74725ac
--- /dev/null
+++ b/include/driver/resistive_load.h
@@ -0,0 +1,35 @@
+#ifndef RESISTIVE_LOAD_H
+#define RESISTIVE_LOAD_H
+
+/*
+ * Resistance at 25°c
+ * R1: 986R
+ * R2: 3K25
+ * R3: 46K3
+ * R4: 9K86
+ */
+
+class ResistiveLoad {
+ private:
+ ResistiveLoad(const ResistiveLoad &copy);
+
+ public:
+ ResistiveLoad() {}
+ void setup();
+ void switchToNone();
+ void switchTo750(); // 576R (R1 || R2)
+ void switchTo1K0(); // 986R (R1)
+ void switchTo2K4(); // 2K44 (R2 || 4)
+ void switchTo3K3(); // 3K25 (R2)
+ void switchTo10K(); // 9K86 (R4)
+ void switchTo47K(); // 46K3 (R3)
+ void nop1K0(unsigned int duration_ms);
+ void nop2K4(unsigned int duration_ms);
+ void nop3K3(unsigned int duration_ms);
+ void nop10K(unsigned int duration_ms);
+ void nop47K(unsigned int duration_ms);
+};
+
+extern ResistiveLoad resistiveLoad;
+
+#endif
diff --git a/model/driver/resistive_load.dfa b/model/driver/resistive_load.dfa
new file mode 100644
index 0000000..a2bf3dd
--- /dev/null
+++ b/model/driver/resistive_load.dfa
@@ -0,0 +1,44 @@
+codegen:
+ instance: resistiveLoad
+ includes:
+ - driver/resistive_load.h
+ flags:
+ - drivers=resistive_load
+ setup:
+ - resistiveLoad.setup();
+
+states:
+ - UNINITIALIZED
+ - SLEEP
+ - P14MW
+ - P11MW
+ - P4_4MW
+ - P3_4MW
+ - P1_1MW
+ - P235UW
+
+transition:
+ setup:
+ src: [UNINITIALIZED]
+ dst: SLEEP
+ switchToNone:
+ src: [UNINITIALIZED, SLEEP, P14MW, P11MW, P4_4MW, P3_4MW, P1_1MW, P235UW]
+ dst: SLEEP
+ switchTo750:
+ src: [UNINITIALIZED, SLEEP, P14MW, P11MW, P4_4MW, P3_4MW, P1_1MW, P235UW]
+ dst: P14MW
+ switchTo1K0:
+ src: [UNINITIALIZED, SLEEP, P14MW, P11MW, P4_4MW, P3_4MW, P1_1MW, P235UW]
+ dst: P11MW
+ switchTo2K4:
+ src: [UNINITIALIZED, SLEEP, P14MW, P11MW, P4_4MW, P3_4MW, P1_1MW, P235UW]
+ dst: P4_4MW
+ switchTo3K3:
+ src: [UNINITIALIZED, SLEEP, P14MW, P11MW, P4_4MW, P3_4MW, P1_1MW, P235UW]
+ dst: P3_4MW
+ switchTo10K:
+ src: [UNINITIALIZED, SLEEP, P14MW, P11MW, P4_4MW, P3_4MW, P1_1MW, P235UW]
+ dst: P1_1MW
+ switchTo47K:
+ src: [UNINITIALIZED, SLEEP, P14MW, P11MW, P4_4MW, P3_4MW, P1_1MW, P235UW]
+ dst: P235UW
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;