summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/core/devices.h
blob: 15a3f40dabc06c89551bf95983c2cc66ae0c553d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// license:GPL-2.0+
// copyright-holders:Couriersud

#ifndef NL_CORE_DEVICES_H_
#define NL_CORE_DEVICES_H_

///
/// \file devices.h
///
/// The core is accessing members or type definitions of devices defined
/// here directly (e.g. nld_nc_pin).
///

#include "analog.h"
#include "device.h"
#include "device_macros.h"
#include "logic.h"
#include "param.h"

//============================================================
// Namespace starts
//============================================================

namespace netlist
{
	namespace devices
	{
		// -----------------------------------------------------------------------------
		// mainclock
		// -----------------------------------------------------------------------------

		NETLIB_OBJECT(mainclock)
		{
			NETLIB_CONSTRUCTOR(mainclock)
			, m_Q(*this, "Q")
			, m_freq(*this, "FREQ", nlconst::magic(7159000.0 * 5))
			{
				m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two()));
			}

			NETLIB_RESETI()
			{
				m_Q.net().set_next_scheduled_time(exec().time());
			}

			NETLIB_UPDATE_PARAMI()
			{
				m_inc = netlist_time::from_fp(plib::reciprocal(m_freq()*nlconst::two()));
			}

		public:
			logic_output_t m_Q; // NOLINT: needed in core
			netlist_time m_inc; // NOLINT: needed in core
		private:
			param_fp_t m_freq;
		};

		// -----------------------------------------------------------------------------
		// power pins - not a device, but a helper
		// -----------------------------------------------------------------------------

		/// \brief Power pins class.
		///
		/// Power Pins are passive inputs. Delegate noop will silently ignore any
		/// updates.

		class nld_power_pins
		{
		public:
			using this_type = nld_power_pins;

			explicit nld_power_pins(device_t &owner)
			: m_VCC(owner, owner.logic_family()->vcc_pin(), NETLIB_DELEGATE(noop))
			, m_GND(owner, owner.logic_family()->gnd_pin(), NETLIB_DELEGATE(noop))
			{
			}

			explicit nld_power_pins(device_t &owner, nldelegate delegate)
			: m_VCC(owner, owner.logic_family()->vcc_pin(), delegate)
			, m_GND(owner, owner.logic_family()->gnd_pin(), delegate)
			{
			}

			// Some devices like the 74LS629 have two pairs of supply pins.
			explicit nld_power_pins(device_t &owner,
				const pstring &vcc, const pstring &gnd)
			: m_VCC(owner, vcc, NETLIB_DELEGATE(noop))
			, m_GND(owner, gnd, NETLIB_DELEGATE(noop))
			{
			}

			// Some devices like the 74LS629 have two pairs of supply pins.
			explicit nld_power_pins(device_t &owner,
				const pstring &vcc, const pstring &gnd,
				nldelegate delegate)
			: m_VCC(owner, vcc, delegate)
			, m_GND(owner, gnd, delegate)
			{
			}

			const analog_input_t &VCC() const noexcept
			{
				return m_VCC;
			}
			const analog_input_t &GND() const noexcept
			{
				return m_GND;
			}

		private:
			void noop() { }
			analog_input_t m_VCC;
			analog_input_t m_GND;
		};

		// -----------------------------------------------------------------------------
		// netlistparams
		// -----------------------------------------------------------------------------

		NETLIB_OBJECT(netlistparams)
		{
			NETLIB_CONSTRUCTOR(netlistparams)
			, m_use_deactivate(*this, "USE_DEACTIVATE", false)
			, m_startup_strategy(*this, "STARTUP_STRATEGY", 0)
			, m_mos_capmodel(*this, "DEFAULT_MOS_CAPMODEL", 2)
			, m_max_link_loops(*this, "MAX_LINK_RESOLVE_LOOPS", 100)
			{
			}
			//NETLIB_RESETI() {}
			//NETLIB_UPDATE_PARAMI() { }
		public:
			param_logic_t m_use_deactivate;
			param_num_t<unsigned>   m_startup_strategy;
			param_num_t<unsigned>   m_mos_capmodel;
			//! How many times do we try to resolve links (connections)
			param_num_t<unsigned>   m_max_link_loops;
		};

		// -----------------------------------------------------------------------------
		// nld_nc_pin
		// -----------------------------------------------------------------------------

		NETLIB_OBJECT(nc_pin)
		{
		public:
			NETLIB_CONSTRUCTOR(nc_pin)
			, m_I(*this, "I", NETLIB_DELEGATE_NOOP())
			{
			}

		protected:
			//NETLIB_RESETI() {}

		private:
			analog_input_t m_I;

		};

		// -----------------------------------------------------------------------------
		// nld_gnd
		// -----------------------------------------------------------------------------

		NETLIB_OBJECT(gnd)
		{
			NETLIB_CONSTRUCTOR(gnd)
			, m_Q(*this, "Q")
			{
			}

			NETLIB_UPDATE_PARAMI()
			{
				m_Q.push(nlconst::zero());
			}

			//NETLIB_RESETI() {}
		protected:
			analog_output_t m_Q;
		};

	} // namespace devices
} // namespace netlist

#endif // NL_CORE_DEVICES_H_