summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/analog/nld_switches.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/analog/nld_switches.cpp')
-rw-r--r--src/lib/netlist/analog/nld_switches.cpp118
1 files changed, 50 insertions, 68 deletions
diff --git a/src/lib/netlist/analog/nld_switches.cpp b/src/lib/netlist/analog/nld_switches.cpp
index 0e62fe13952..6b87279e398 100644
--- a/src/lib/netlist/analog/nld_switches.cpp
+++ b/src/lib/netlist/analog/nld_switches.cpp
@@ -1,19 +1,15 @@
-// license:GPL-2.0+
+// license:BSD-3-Clause
// copyright-holders:Couriersud
-/*
- * nld_legacy.c
- *
- */
#include "nlid_twoterm.h"
-#include "netlist/nl_base.h"
-#include "netlist/nl_factory.h"
-#include "netlist/solver/nld_solver.h"
+#include "nl_base.h"
+#include "nl_factory.h"
+#include "solver/nld_solver.h"
-/* FIXME : convert to parameters */
+// FIXME : convert to parameters
-#define R_OFF (1.0 / exec().gmin())
-#define R_ON 0.01
+#define R_OFF (plib::reciprocal(exec().gmin()))
+#define R_ON nlconst::magic(0.01)
namespace netlist
{
@@ -23,83 +19,72 @@ namespace netlist
// SWITCH
// ----------------------------------------------------------------------------------------
- NETLIB_OBJECT(switch1)
+ class nld_switch1 : public base_device_t
{
- NETLIB_CONSTRUCTOR(switch1)
+ public:
+ nld_switch1(constructor_param_t data)
+ : base_device_t(data)
, m_R(*this, "R")
, m_POS(*this, "POS", false)
{
- register_subalias("1", m_R.m_P);
- register_subalias("2", m_R.m_N);
+ register_sub_alias("1", m_R().P());
+ register_sub_alias("2", m_R().N());
}
- NETLIB_RESETI();
- NETLIB_UPDATEI();
- NETLIB_UPDATE_PARAMI();
-
- analog::NETLIB_SUB(R_base) m_R;
- param_logic_t m_POS;
- };
-
-
- NETLIB_RESET(switch1)
- {
- m_R.set_R(R_OFF);
- }
-
- NETLIB_UPDATE(switch1)
- {
- }
-
- NETLIB_UPDATE_PARAM(switch1)
- {
- m_R.solve_now();
- if (!m_POS())
+ NETLIB_RESETI()
{
- m_R.set_R(R_OFF);
+ m_R().set_R(R_OFF);
}
- else
+ NETLIB_UPDATE_PARAMI()
{
- m_R.set_R(R_ON);
+ m_R().change_state([this]()
+ {
+ m_R().set_R(m_POS() ? R_ON : R_OFF);
+ });
}
- m_R.solve_later();
- }
+ private:
+ NETLIB_SUB_NS(analog, R_base) m_R;
+ param_logic_t m_POS;
+ };
// ----------------------------------------------------------------------------------------
// SWITCH2
// ----------------------------------------------------------------------------------------
- NETLIB_OBJECT(switch2)
+ class nld_switch2 : public base_device_t
{
- NETLIB_CONSTRUCTOR(switch2)
+ public:
+ nld_switch2(constructor_param_t data)
+ : base_device_t(data)
, m_R1(*this, "R1")
, m_R2(*this, "R2")
, m_POS(*this, "POS", false)
{
- connect(m_R1.m_N, m_R2.m_N);
+ connect(m_R1().N(), m_R2().N());
- register_subalias("1", m_R1.m_P);
- register_subalias("2", m_R2.m_P);
+ register_sub_alias("1", m_R1().P());
+ register_sub_alias("2", m_R2().P());
- register_subalias("Q", m_R1.m_N);
+ register_sub_alias("Q", m_R1().N());
}
NETLIB_RESETI();
- NETLIB_UPDATEI();
NETLIB_UPDATE_PARAMI();
- analog::NETLIB_SUB(R_base) m_R1;
- analog::NETLIB_SUB(R_base) m_R2;
- param_logic_t m_POS;
+ private:
+ NETLIB_SUB_NS(analog, R_base) m_R1;
+ NETLIB_SUB_NS(analog, R_base) m_R2;
+ param_logic_t m_POS;
};
NETLIB_RESET(switch2)
{
- m_R1.set_R(R_ON);
- m_R2.set_R(R_OFF);
+ m_R1().set_R(R_ON);
+ m_R2().set_R(R_OFF);
}
+#ifdef FIXMELATER
NETLIB_UPDATE(switch2)
{
if (!m_POS())
@@ -112,26 +97,23 @@ namespace netlist
m_R1.set_R(R_OFF);
m_R2.set_R(R_ON);
}
-
- //m_R1.update_dev(time);
- //m_R2.update_dev(time);
}
-
+#endif
NETLIB_UPDATE_PARAM(switch2)
{
- if (!m_POS())
- {
- m_R1.set_R(R_ON);
- m_R2.set_R(R_OFF);
- }
+ // R1 and R2 are connected. However this net may be a rail net.
+ // The code here thus is a bit more complex.
+
+ nl_fptype r1 = m_POS() ? R_OFF : R_ON;
+ nl_fptype r2 = m_POS() ? R_ON : R_OFF;
+
+ if (m_R1().solver() == m_R2().solver())
+ m_R1().change_state([this, &r1, &r2]() { m_R1().set_R(r1); m_R2().set_R(r2); });
else
{
- m_R1.set_R(R_OFF);
- m_R2.set_R(R_ON);
+ m_R1().change_state([this, &r1]() { m_R1().set_R(r1); });
+ m_R2().change_state([this, &r2]() { m_R2().set_R(r2); });
}
-
- m_R1.solve_now();
- m_R2.solve_now();
}
} //namespace analog