Moved proxy code into separate file. (nw)

This commit is contained in:
couriersud 2016-12-27 21:40:03 +01:00
parent 9ade6db46e
commit 63f4e52dae
10 changed files with 265 additions and 203 deletions

View File

@ -187,6 +187,8 @@ project "netlist"
MAME_DIR .. "src/lib/netlist/devices/nld_truthtable.h",
MAME_DIR .. "src/lib/netlist/devices/nlid_cmos.h",
MAME_DIR .. "src/lib/netlist/devices/nlid_system.h",
MAME_DIR .. "src/lib/netlist/devices/nlid_proxy.cpp",
MAME_DIR .. "src/lib/netlist/devices/nlid_proxy.h",
MAME_DIR .. "src/lib/netlist/macro/nlm_ttl74xx.cpp",
MAME_DIR .. "src/lib/netlist/macro/nlm_ttl74xx.h",
MAME_DIR .. "src/lib/netlist/macro/nlm_cd4xxx.cpp",

View File

@ -111,6 +111,7 @@ NLOBJS := \
$(NLOBJ)/devices/nld_legacy.o \
$(NLOBJ)/devices/net_lib.o \
$(NLOBJ)/devices/nld_log.o \
$(NLOBJ)/devices/nlid_proxy.o \
$(NLOBJ)/devices/nld_system.o \
$(NLOBJ)/devices/nld_truthtable.o \
$(NLOBJ)/macro/nlm_cd4xxx.o \

View File

@ -86,38 +86,6 @@ namespace netlist
{
}
// ----------------------------------------------------------------------------------------
// nld_d_to_a_proxy
// ----------------------------------------------------------------------------------------
void nld_d_to_a_proxy::reset()
{
//m_Q.initial(0.0);
m_last_state = -1;
m_RV.do_reset();
m_is_timestep = m_RV.m_P.net().solver()->has_timestep_devices();
m_RV.set(NL_FCONST(1.0) / logic_family().m_R_low, logic_family().m_low_V, 0.0);
}
NETLIB_UPDATE(d_to_a_proxy)
{
const int state = static_cast<int>(m_I());
if (state != m_last_state)
{
m_last_state = state;
const nl_double R = state ? logic_family().m_R_high : logic_family().m_R_low;
const nl_double V = state ? logic_family().m_high_V : logic_family().m_low_V;
// We only need to update the net first if this is a time stepping net
if (m_is_timestep)
{
m_RV.update_dev();
}
m_RV.set(NL_FCONST(1.0) / R, V, 0.0);
m_RV.m_P.schedule_after(NLTIME_FROM_NS(1));
}
}
// -----------------------------------------------------------------------------
// nld_res_sw

View File

@ -0,0 +1,74 @@
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* nlid_proxy.cpp
*
*/
//#include <memory>
#include "nlid_proxy.h"
#include "solver/nld_solver.h"
//#include "plib/pstream.h"
//#include "plib/pfmtlog.h"
//#include "nld_log.h"
namespace netlist
{
namespace devices
{
// ----------------------------------------------------------------------------------------
// nld_d_to_a_proxy
// ----------------------------------------------------------------------------------------
nld_d_to_a_proxy::nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied)
: nld_base_d_to_a_proxy(anetlist, name, out_proxied, m_RV.m_P)
, m_GNDHack(*this, "_Q")
, m_RV(*this, "RV")
, m_last_state(*this, "m_last_var", -1)
, m_is_timestep(false)
{
//register_sub(m_RV);
//register_term("1", m_RV.m_P);
//register_term("2", m_RV.m_N);
register_subalias("Q", m_RV.m_P);
connect_late(m_RV.m_N, m_GNDHack);
printf("%s %s\n", out_proxied->name().cstr(), out_proxied->device().name().cstr());
auto x = netlist().setup().find_terminal(out_proxied->name(), detail::device_object_t::type_t::OUTPUT, false);
if (x) printf("==> %s\n", x->name().cstr());
}
void nld_d_to_a_proxy::reset()
{
//m_Q.initial(0.0);
m_last_state = -1;
m_RV.do_reset();
m_is_timestep = m_RV.m_P.net().solver()->has_timestep_devices();
m_RV.set(NL_FCONST(1.0) / logic_family().m_R_low, logic_family().m_low_V, 0.0);
}
NETLIB_UPDATE(d_to_a_proxy)
{
const int state = static_cast<int>(m_I());
if (state != m_last_state)
{
m_last_state = state;
const nl_double R = state ? logic_family().m_R_high : logic_family().m_R_low;
const nl_double V = state ? logic_family().m_high_V : logic_family().m_low_V;
// We only need to update the net first if this is a time stepping net
if (m_is_timestep)
{
m_RV.update_dev();
}
m_RV.set(NL_FCONST(1.0) / R, V, 0.0);
m_RV.m_P.schedule_after(NLTIME_FROM_NS(1));
}
}
} //namespace devices
} // namespace netlist

View File

@ -0,0 +1,180 @@
// license:GPL-2.0+
// copyright-holders:Couriersud
/*
* nlid_proxy.h
*
* netlist proxy devices
*
* This file contains internal headers
*/
#ifndef NLID_PROXY_H_
#define NLID_PROXY_H_
#include <vector>
#include "nl_setup.h"
#include "nl_base.h"
#include "nl_factory.h"
#include "analog/nld_twoterm.h"
namespace netlist
{
namespace devices
{
// -----------------------------------------------------------------------------
// nld_base_proxy
// -----------------------------------------------------------------------------
NETLIB_OBJECT(base_proxy)
{
public:
nld_base_proxy(netlist_t &anetlist, const pstring &name,
logic_t *inout_proxied, detail::core_terminal_t *proxy_inout)
: device_t(anetlist, name)
{
m_logic_family = inout_proxied->logic_family();
m_term_proxied = inout_proxied;
m_proxy_term = proxy_inout;
}
virtual ~nld_base_proxy() {}
logic_t &term_proxied() const { return *m_term_proxied; }
detail::core_terminal_t &proxy_term() const { return *m_proxy_term; }
protected:
const logic_family_desc_t *m_logic_family;
virtual const logic_family_desc_t &logic_family() const
{
return *m_logic_family;
}
private:
logic_t *m_term_proxied;
detail::core_terminal_t *m_proxy_term;
};
// -----------------------------------------------------------------------------
// nld_a_to_d_proxy
// -----------------------------------------------------------------------------
NETLIB_OBJECT_DERIVED(a_to_d_proxy, base_proxy)
{
public:
nld_a_to_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *in_proxied)
: nld_base_proxy(anetlist, name, in_proxied, &m_I)
, m_I(*this, "I")
, m_Q(*this, "Q")
{
}
virtual ~nld_a_to_d_proxy() {}
analog_input_t m_I;
logic_output_t m_Q;
protected:
NETLIB_RESETI() { }
NETLIB_UPDATEI()
{
nl_assert(m_logic_family != nullptr);
if (m_I.Q_Analog() > logic_family().m_high_thresh_V)
m_Q.push(1, NLTIME_FROM_NS(1));
else if (m_I.Q_Analog() < logic_family().m_low_thresh_V)
m_Q.push(0, NLTIME_FROM_NS(1));
else
{
// do nothing
}
}
private:
};
// -----------------------------------------------------------------------------
// nld_base_d_to_a_proxy
// -----------------------------------------------------------------------------
NETLIB_OBJECT_DERIVED(base_d_to_a_proxy, base_proxy)
{
public:
virtual ~nld_base_d_to_a_proxy() {}
virtual logic_input_t &in() { return m_I; }
protected:
nld_base_d_to_a_proxy(netlist_t &anetlist, const pstring &name,
logic_output_t *out_proxied, detail::core_terminal_t &proxy_out)
: nld_base_proxy(anetlist, name, out_proxied, &proxy_out)
, m_I(*this, "I")
{
}
logic_input_t m_I;
private:
};
NETLIB_OBJECT_DERIVED(d_to_a_proxy, base_d_to_a_proxy)
{
public:
nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied);
virtual ~nld_d_to_a_proxy() {}
protected:
NETLIB_RESETI();
NETLIB_UPDATEI();
private:
analog_output_t m_GNDHack; // FIXME: Long term, we need to connect proxy gnd to device gnd
NETLIB_SUB(twoterm) m_RV;
state_var<int> m_last_state;
bool m_is_timestep;
};
class factory_lib_entry_t : public base_factory_t
{
P_PREVENT_COPYING(factory_lib_entry_t)
public:
factory_lib_entry_t(setup_t &setup, const pstring &name, const pstring &classname,
const pstring &def_param)
: base_factory_t(name, classname, def_param), m_setup(setup) { }
class wrapper : public device_t
{
public:
wrapper(const pstring &devname, netlist_t &anetlist, const pstring &name)
: device_t(anetlist, name), m_devname(devname)
{
anetlist.setup().namespace_push(name);
anetlist.setup().include(m_devname);
anetlist.setup().namespace_pop();
}
protected:
NETLIB_RESETI() { }
NETLIB_UPDATEI() { }
pstring m_devname;
};
plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) override
{
return plib::owned_ptr<device_t>::Create<wrapper>(this->name(), anetlist, name);
}
private:
setup_t &m_setup;
};
} //namespace devices
} // namespace netlist
#endif /* NLD_PROXY_H_ */

View File

@ -413,173 +413,6 @@ namespace netlist
state_var<netlist_sig_t> m_last_state;
};
// -----------------------------------------------------------------------------
// nld_base_proxy
// -----------------------------------------------------------------------------
NETLIB_OBJECT(base_proxy)
{
public:
nld_base_proxy(netlist_t &anetlist, const pstring &name,
logic_t *inout_proxied, detail::core_terminal_t *proxy_inout)
: device_t(anetlist, name)
{
m_logic_family = inout_proxied->logic_family();
m_term_proxied = inout_proxied;
m_proxy_term = proxy_inout;
}
virtual ~nld_base_proxy() {}
logic_t &term_proxied() const { return *m_term_proxied; }
detail::core_terminal_t &proxy_term() const { return *m_proxy_term; }
protected:
const logic_family_desc_t *m_logic_family;
virtual const logic_family_desc_t &logic_family() const
{
return *m_logic_family;
}
private:
logic_t *m_term_proxied;
detail::core_terminal_t *m_proxy_term;
};
// -----------------------------------------------------------------------------
// nld_a_to_d_proxy
// -----------------------------------------------------------------------------
NETLIB_OBJECT_DERIVED(a_to_d_proxy, base_proxy)
{
public:
nld_a_to_d_proxy(netlist_t &anetlist, const pstring &name, logic_input_t *in_proxied)
: nld_base_proxy(anetlist, name, in_proxied, &m_I)
, m_I(*this, "I")
, m_Q(*this, "Q")
{
}
virtual ~nld_a_to_d_proxy() {}
analog_input_t m_I;
logic_output_t m_Q;
protected:
NETLIB_RESETI() { }
NETLIB_UPDATEI()
{
nl_assert(m_logic_family != nullptr);
if (m_I.Q_Analog() > logic_family().m_high_thresh_V)
m_Q.push(1, NLTIME_FROM_NS(1));
else if (m_I.Q_Analog() < logic_family().m_low_thresh_V)
m_Q.push(0, NLTIME_FROM_NS(1));
else
{
// do nothing
}
}
private:
};
// -----------------------------------------------------------------------------
// nld_base_d_to_a_proxy
// -----------------------------------------------------------------------------
NETLIB_OBJECT_DERIVED(base_d_to_a_proxy, base_proxy)
{
public:
virtual ~nld_base_d_to_a_proxy() {}
virtual logic_input_t &in() { return m_I; }
protected:
nld_base_d_to_a_proxy(netlist_t &anetlist, const pstring &name,
logic_output_t *out_proxied, detail::core_terminal_t &proxy_out)
: nld_base_proxy(anetlist, name, out_proxied, &proxy_out)
, m_I(*this, "I")
{
}
logic_input_t m_I;
private:
};
NETLIB_OBJECT_DERIVED(d_to_a_proxy, base_d_to_a_proxy)
{
public:
nld_d_to_a_proxy(netlist_t &anetlist, const pstring &name, logic_output_t *out_proxied)
: nld_base_d_to_a_proxy(anetlist, name, out_proxied, m_RV.m_P)
, m_GNDHack(*this, "_Q")
, m_RV(*this, "RV")
, m_last_state(*this, "m_last_var", -1)
, m_is_timestep(false)
{
//register_sub(m_RV);
//register_term("1", m_RV.m_P);
//register_term("2", m_RV.m_N);
register_subalias("Q", m_RV.m_P);
connect_late(m_RV.m_N, m_GNDHack);
//printf("%s %s\n", out_proxied->name().cstr(), out_proxied->device().name().cstr());
}
virtual ~nld_d_to_a_proxy() {}
protected:
NETLIB_RESETI();
NETLIB_UPDATEI();
private:
analog_output_t m_GNDHack; // FIXME: Long term, we need to connect proxy gnd to device gnd
NETLIB_SUB(twoterm) m_RV;
state_var<int> m_last_state;
bool m_is_timestep;
};
class factory_lib_entry_t : public base_factory_t
{
P_PREVENT_COPYING(factory_lib_entry_t)
public:
factory_lib_entry_t(setup_t &setup, const pstring &name, const pstring &classname,
const pstring &def_param)
: base_factory_t(name, classname, def_param), m_setup(setup) { }
class wrapper : public device_t
{
public:
wrapper(const pstring &devname, netlist_t &anetlist, const pstring &name)
: device_t(anetlist, name), m_devname(devname)
{
anetlist.setup().namespace_push(name);
anetlist.setup().include(m_devname);
anetlist.setup().namespace_pop();
}
protected:
NETLIB_RESETI() { }
NETLIB_UPDATEI() { }
pstring m_devname;
};
plib::owned_ptr<device_t> Create(netlist_t &anetlist, const pstring &name) override
{
return plib::owned_ptr<device_t>::Create<wrapper>(this->name(), anetlist, name);
}
private:
setup_t &m_setup;
};
} //namespace devices
} // namespace netlist

View File

@ -15,6 +15,7 @@
#include "nl_base.h"
#include "devices/nlid_system.h"
#include "devices/nlid_proxy.h"
namespace netlist
{

View File

@ -873,7 +873,7 @@ namespace netlist
{
public:
param_logic_t(device_t &device, const pstring name, const bool val);
const bool operator()() const { return m_param; }
bool operator()() const { return m_param; }
void setTo(const bool &param) { set(m_param, param); }
private:
bool m_param;
@ -883,7 +883,7 @@ namespace netlist
{
public:
param_int_t(device_t &device, const pstring name, const int val);
const int operator()() const { return m_param; }
int operator()() const { return m_param; }
void setTo(const int &param) { set(m_param, param); }
private:
int m_param;
@ -893,7 +893,7 @@ namespace netlist
{
public:
param_double_t(device_t &device, const pstring name, const double val);
const double operator()() const { return m_param; }
double operator()() const { return m_param; }
void setTo(const double &param) { set(m_param, param); }
private:
double m_param;

View File

@ -18,6 +18,7 @@
#include "devices/net_lib.h"
#include "devices/nld_truthtable.h"
#include "devices/nlid_system.h"
#include "devices/nlid_proxy.h"
#include "analog/nld_twoterm.h"
#include "solver/nld_solver.h"

View File

@ -281,10 +281,12 @@ namespace netlist
std::unordered_map<pstring, pstring> m_param_values;
std::unordered_map<pstring, detail::core_terminal_t *> m_terminals;
/* needed by proxy */
detail::core_terminal_t *find_terminal(const pstring &outname_in, detail::device_object_t::type_t atype, bool required = true);
private:
detail::core_terminal_t *find_terminal(const pstring &outname_in, bool required = true);
detail::core_terminal_t *find_terminal(const pstring &outname_in, detail::device_object_t::type_t atype, bool required = true);
void merge_nets(detail::net_t &thisnet, detail::net_t &othernet);