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)
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"
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
,
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
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
);
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
);
53 vvp_time64_t rise_
, fall_
, decay_
;
54 vvp_time64_t min_delay_
;
56 void calculate_min_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
{
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
;
85 vvp_fun_delay(vvp_net_t
*net
, vvp_bit4_t init
, const vvp_delay_t
&d
);
88 void recv_vec4(vvp_net_ptr_t port
, const vvp_vector4_t
&bit
,
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
,
93 //void recv_long(vvp_net_ptr_t port, long bit);
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
);
106 bool initial_
; // Indicates if the value is still the initial value.
108 vvp_vector4_t cur_vec4_
;
109 vvp_vector8_t cur_vec8_
;
111 vvp_time64_t round_
, scale_
; // Needed to scale variable time values.
113 struct event_
*list_
;
114 void enqueue_(struct event_
*cur
)
117 cur
->next
= list_
->next
;
125 struct event_
* dequeue_(void)
129 struct event_
*cur
= list_
->next
;
133 list_
->next
= cur
->next
;
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
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
{
153 vvp_fun_modpath(vvp_net_t
*net
);
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
,
162 virtual void run_run();
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
;
182 vvp_fun_modpath_src(vvp_time64_t d
[12]);
184 ~vvp_fun_modpath_src();
187 void recv_vec4(vvp_net_ptr_t port
, const vvp_vector4_t
&bit
,
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]);
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_
;
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
{
211 vvp_fun_modpath_edge(vvp_time64_t del
[12], bool pos
, bool neg
);
213 bool test_vec4(const vvp_vector4_t
&bit
);
216 vvp_bit4_t old_value_
;