testing
[gnucap-felix.git] / src / delay.h
blobf8a1e87d70d99db5c0219a63851b18f9defba1a8
1 #ifndef __delay_H
2 #define __delay_H
3 /*
4 * Copyright 2005-2008 Stephen Williams
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 # include "vvp/vvp_net.h"
23 # include "schedule.h"
25 enum delay_edge_t {
26 DELAY_EDGE_01 = 0, DELAY_EDGE_10, DELAY_EDGE_0z,
27 DELAY_EDGE_z1, DELAY_EDGE_1z, DELAY_EDGE_z0,
28 DELAY_EDGE_0x, DELAY_EDGE_x1, DELAY_EDGE_1x,
29 DELAY_EDGE_x0, DELAY_EDGE_xz, DELAY_EDGE_zx,
30 DELAY_EDGE_COUNT
34 * Instances of this object are functions that calculate the delay for
35 * the transition from the source vvp_bit4_t value to the destination
36 * value.
38 class vvp_delay_t {
40 public:
41 vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall);
42 vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall, vvp_time64_t decay);
43 ~vvp_delay_t();
45 vvp_time64_t get_delay(vvp_bit4_t from, vvp_bit4_t to);
46 vvp_time64_t get_min_delay() const;
48 void set_rise(vvp_time64_t val);
49 void set_fall(vvp_time64_t val);
50 void set_decay(vvp_time64_t val);
52 private:
53 vvp_time64_t rise_, fall_, decay_;
54 vvp_time64_t min_delay_;
56 void calculate_min_delay_();
59 /* vvp_fun_delay
60 * This is a lighter weight version of vvp_fun_drive, that only
61 * carries delays. The output that it propagates is vvp_vector4_t so
62 * drive strengths are lost, but then again it doesn't go through the
63 * effort of calculating strength values either.
65 * The node needs a pointer to the vvp_net_t input so that it knows
66 * how to find its output when propagating delayed output.
68 * NOTE: This node supports vec4 and real by repeating whatever was
69 * input. This is a bit of a hack, as it may be more efficient to
70 * create the right type of vvp_fun_delay_real.
72 class vvp_fun_delay : public vvp_net_fun_t, private vvp_gen_event_s {
74 struct event_ {
75 event_(vvp_time64_t s) : sim_time(s) { }
76 void (vvp_fun_delay::*run_run_ptr)(struct vvp_fun_delay::event_*cur);
77 const vvp_time64_t sim_time;
78 vvp_vector4_t ptr_vec4;
79 vvp_vector8_t ptr_vec8;
80 double ptr_real;
81 struct event_*next;
84 public:
85 vvp_fun_delay(vvp_net_t*net, vvp_bit4_t init, const vvp_delay_t&d);
86 ~vvp_fun_delay();
88 void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
89 vvp_context_t);
90 void recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit);
91 void recv_real(vvp_net_ptr_t port, double bit,
92 vvp_context_t);
93 //void recv_long(vvp_net_ptr_t port, long bit);
95 private:
96 virtual void run_run();
99 void run_run_vec4_(struct vvp_fun_delay::event_*cur);
100 void run_run_vec8_(struct vvp_fun_delay::event_*cur);
101 void run_run_real_(struct vvp_fun_delay::event_*cur);
103 private:
104 vvp_net_t*net_;
105 vvp_delay_t delay_;
106 bool initial_; // Indicates if the value is still the initial value.
108 vvp_vector4_t cur_vec4_;
109 vvp_vector8_t cur_vec8_;
110 double cur_real_;
111 vvp_time64_t round_, scale_; // Needed to scale variable time values.
113 struct event_ *list_;
114 void enqueue_(struct event_*cur)
116 if (list_) {
117 cur->next = list_->next;
118 list_->next = cur;
119 list_ = cur;
120 } else {
121 cur->next = cur;
122 list_ = cur;
125 struct event_* dequeue_(void)
127 if (list_ == 0)
128 return 0;
129 struct event_*cur = list_->next;
130 if (list_ == cur)
131 list_ = 0;
132 else
133 list_->next = cur->next;
134 return cur;
136 void clean_pulse_events_(vvp_time64_t use_delay);
140 * These objects implement module delay paths. The fun_modpath functor
141 * is the output of the modpath, and the vvp_fun_modpath_src is the
142 * source of the modpath. The modpath source tracks events on the
143 * inputs to enable delays, and the vvp_fun_modpath, when it's time to
144 * schedule, looks at the associated modpath_src objects for which
145 * paths are active.
147 class vvp_fun_modpath;
148 class vvp_fun_modpath_src;
150 class vvp_fun_modpath : public vvp_net_fun_t, private vvp_gen_event_s {
152 public:
153 vvp_fun_modpath(vvp_net_t*net);
154 ~vvp_fun_modpath();
156 void add_modpath_src(vvp_fun_modpath_src*that, bool ifnone);
158 void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
159 vvp_context_t);
161 private:
162 virtual void run_run();
164 private:
165 vvp_net_t*net_;
167 vvp_vector4_t cur_vec4_;
169 vvp_fun_modpath_src*src_list_;
170 vvp_fun_modpath_src*ifnone_list_;
172 private: // not implemented
173 vvp_fun_modpath(const vvp_fun_modpath&);
174 vvp_fun_modpath& operator= (const vvp_fun_modpath&);
177 class vvp_fun_modpath_src : public vvp_net_fun_t {
179 friend class vvp_fun_modpath;
181 public:
182 vvp_fun_modpath_src(vvp_time64_t d[12]);
183 protected:
184 ~vvp_fun_modpath_src();
186 public:
187 void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
188 vvp_context_t);
189 virtual bool test_vec4(const vvp_vector4_t&bit);
191 void get_delay12(vvp_time64_t out[12]) const;
192 void put_delay12(const vvp_time64_t in[12]);
194 private:
195 // FIXME: Needs to be a 12-value array
196 vvp_time64_t delay_[12];
197 // Used by vvp_fun_modpath to keep a list of modpath_src objects.
198 vvp_fun_modpath_src*next_;
200 vvp_time64_t wake_time_;
201 bool condition_flag_;
203 private:
204 vvp_fun_modpath_src(const vvp_fun_modpath_src&);
205 vvp_fun_modpath_src& operator = (const vvp_fun_modpath_src&);
208 class vvp_fun_modpath_edge : public vvp_fun_modpath_src {
210 public:
211 vvp_fun_modpath_edge(vvp_time64_t del[12], bool pos, bool neg);
213 bool test_vec4(const vvp_vector4_t&bit);
215 private:
216 vvp_bit4_t old_value_;
217 bool posedge_;
218 bool negedge_;
221 #endif // __delay_H