2005-04-03 07:45:51 +02:00
|
|
|
#ifndef __delay_H
|
2001-11-10 19:07:11 +01:00
|
|
|
#define __delay_H
|
|
|
|
|
/*
|
2010-07-13 19:01:32 +02:00
|
|
|
* Copyright 2005-2010 Stephen Williams
|
2001-11-10 19:07:11 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
# include "vvp_net.h"
|
2005-06-02 18:02:11 +02:00
|
|
|
# include "schedule.h"
|
2001-11-10 19:07:11 +01:00
|
|
|
|
2006-09-29 05:57:01 +02:00
|
|
|
enum delay_edge_t {
|
|
|
|
|
DELAY_EDGE_01 = 0, DELAY_EDGE_10, DELAY_EDGE_0z,
|
|
|
|
|
DELAY_EDGE_z1, DELAY_EDGE_1z, DELAY_EDGE_z0,
|
|
|
|
|
DELAY_EDGE_0x, DELAY_EDGE_x1, DELAY_EDGE_1x,
|
|
|
|
|
DELAY_EDGE_x0, DELAY_EDGE_xz, DELAY_EDGE_zx,
|
|
|
|
|
DELAY_EDGE_COUNT
|
|
|
|
|
};
|
|
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
/*
|
|
|
|
|
* Instances of this object are functions that calculate the delay for
|
|
|
|
|
* the transition from the source vvp_bit4_t value to the destination
|
|
|
|
|
* value.
|
|
|
|
|
*/
|
|
|
|
|
class vvp_delay_t {
|
2001-11-10 19:07:11 +01:00
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
public:
|
|
|
|
|
vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall);
|
|
|
|
|
vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall, vvp_time64_t decay);
|
|
|
|
|
~vvp_delay_t();
|
2001-11-10 19:07:11 +01:00
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
vvp_time64_t get_delay(vvp_bit4_t from, vvp_bit4_t to);
|
2005-07-06 06:29:25 +02:00
|
|
|
vvp_time64_t get_min_delay() const;
|
2001-11-10 19:07:11 +01:00
|
|
|
|
2006-01-02 06:32:06 +01:00
|
|
|
void set_rise(vvp_time64_t val);
|
|
|
|
|
void set_fall(vvp_time64_t val);
|
|
|
|
|
void set_decay(vvp_time64_t val);
|
2010-07-13 19:01:32 +02:00
|
|
|
void set_ignore_decay();
|
2006-01-02 06:32:06 +01:00
|
|
|
|
2005-04-03 07:45:51 +02:00
|
|
|
private:
|
|
|
|
|
vvp_time64_t rise_, fall_, decay_;
|
|
|
|
|
vvp_time64_t min_delay_;
|
2010-07-13 19:01:32 +02:00
|
|
|
bool ignore_decay_;
|
2006-01-02 06:32:06 +01:00
|
|
|
|
|
|
|
|
void calculate_min_delay_();
|
2001-11-10 19:07:11 +01:00
|
|
|
};
|
|
|
|
|
|
2005-05-14 21:43:23 +02:00
|
|
|
/* vvp_fun_delay
|
|
|
|
|
* This is a lighter weight version of vvp_fun_drive, that only
|
|
|
|
|
* carries delays. The output that it propagates is vvp_vector4_t so
|
|
|
|
|
* drive strengths are lost, but then again it doesn't go through the
|
|
|
|
|
* effort of calculating strength values either.
|
2005-06-02 18:02:11 +02:00
|
|
|
*
|
|
|
|
|
* The node needs a pointer to the vvp_net_t input so that it knows
|
2008-01-29 21:19:59 +01:00
|
|
|
* how to find its output when propagating delayed output.
|
2005-07-06 06:29:25 +02:00
|
|
|
*
|
|
|
|
|
* NOTE: This node supports vec4 and real by repeating whatever was
|
|
|
|
|
* input. This is a bit of a hack, as it may be more efficient to
|
|
|
|
|
* create the right type of vvp_fun_delay_real.
|
2005-05-14 21:43:23 +02:00
|
|
|
*/
|
2005-06-02 18:02:11 +02:00
|
|
|
class vvp_fun_delay : public vvp_net_fun_t, private vvp_gen_event_s {
|
2005-05-14 21:43:23 +02:00
|
|
|
|
2009-08-07 05:32:10 +02:00
|
|
|
enum delay_type_t {UNKNOWN_DELAY, VEC4_DELAY, VEC8_DELAY, REAL_DELAY};
|
2007-01-26 06:15:41 +01:00
|
|
|
struct event_ {
|
2010-10-11 00:14:29 +02:00
|
|
|
event_(vvp_time64_t s) : sim_time(s) {
|
|
|
|
|
ptr_real = 0.0;
|
|
|
|
|
next = NULL;
|
|
|
|
|
}
|
2007-01-26 06:15:41 +01:00
|
|
|
void (vvp_fun_delay::*run_run_ptr)(struct vvp_fun_delay::event_*cur);
|
|
|
|
|
const vvp_time64_t sim_time;
|
|
|
|
|
vvp_vector4_t ptr_vec4;
|
|
|
|
|
vvp_vector8_t ptr_vec8;
|
|
|
|
|
double ptr_real;
|
|
|
|
|
struct event_*next;
|
|
|
|
|
};
|
|
|
|
|
|
2005-05-14 21:43:23 +02:00
|
|
|
public:
|
2010-04-08 12:48:17 +02:00
|
|
|
vvp_fun_delay(vvp_net_t*net, unsigned width, const vvp_delay_t&d);
|
2005-05-14 21:43:23 +02:00
|
|
|
~vvp_fun_delay();
|
|
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t);
|
2008-06-12 21:08:02 +02:00
|
|
|
void recv_vec8(vvp_net_ptr_t port, const vvp_vector8_t&bit);
|
2008-10-28 18:52:39 +01:00
|
|
|
void recv_real(vvp_net_ptr_t port, double bit,
|
|
|
|
|
vvp_context_t);
|
2005-05-14 21:43:23 +02:00
|
|
|
//void recv_long(vvp_net_ptr_t port, long bit);
|
|
|
|
|
|
|
|
|
|
private:
|
2005-06-02 18:02:11 +02:00
|
|
|
virtual void run_run();
|
|
|
|
|
|
2006-01-02 06:32:06 +01:00
|
|
|
|
2007-01-26 06:15:41 +01:00
|
|
|
void run_run_vec4_(struct vvp_fun_delay::event_*cur);
|
|
|
|
|
void run_run_vec8_(struct vvp_fun_delay::event_*cur);
|
|
|
|
|
void run_run_real_(struct vvp_fun_delay::event_*cur);
|
2006-01-02 06:32:06 +01:00
|
|
|
|
2005-06-02 18:02:11 +02:00
|
|
|
private:
|
|
|
|
|
vvp_net_t*net_;
|
2005-05-14 21:43:23 +02:00
|
|
|
vvp_delay_t delay_;
|
2009-08-07 05:32:10 +02:00
|
|
|
delay_type_t type_;
|
2008-01-30 23:14:52 +01:00
|
|
|
bool initial_; // Indicates if the value is still the initial value.
|
2005-07-06 06:29:25 +02:00
|
|
|
|
|
|
|
|
vvp_vector4_t cur_vec4_;
|
2006-01-02 06:32:06 +01:00
|
|
|
vvp_vector8_t cur_vec8_;
|
2005-07-06 06:29:25 +02:00
|
|
|
double cur_real_;
|
2008-09-12 01:50:45 +02:00
|
|
|
vvp_time64_t round_, scale_; // Needed to scale variable time values.
|
2007-01-26 06:15:41 +01:00
|
|
|
|
|
|
|
|
struct event_ *list_;
|
|
|
|
|
void enqueue_(struct event_*cur)
|
|
|
|
|
{
|
|
|
|
|
if (list_) {
|
|
|
|
|
cur->next = list_->next;
|
|
|
|
|
list_->next = cur;
|
|
|
|
|
list_ = cur;
|
|
|
|
|
} else {
|
|
|
|
|
cur->next = cur;
|
|
|
|
|
list_ = cur;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
struct event_* dequeue_(void)
|
|
|
|
|
{
|
|
|
|
|
if (list_ == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
struct event_*cur = list_->next;
|
|
|
|
|
if (list_ == cur)
|
|
|
|
|
list_ = 0;
|
|
|
|
|
else
|
|
|
|
|
list_->next = cur->next;
|
|
|
|
|
return cur;
|
|
|
|
|
}
|
2009-08-07 05:32:10 +02:00
|
|
|
bool clean_pulse_events_(vvp_time64_t use_delay, const vvp_vector4_t&bit);
|
|
|
|
|
bool clean_pulse_events_(vvp_time64_t use_delay, const vvp_vector8_t&bit);
|
|
|
|
|
bool clean_pulse_events_(vvp_time64_t use_delay, double bit);
|
|
|
|
|
// Delete this when done!
|
2007-01-26 06:15:41 +01:00
|
|
|
void clean_pulse_events_(vvp_time64_t use_delay);
|
2005-05-14 21:43:23 +02:00
|
|
|
};
|
|
|
|
|
|
2007-03-01 07:19:38 +01:00
|
|
|
/*
|
2008-01-29 21:19:59 +01:00
|
|
|
* These objects implement module delay paths. The fun_modpath functor
|
2007-03-01 07:19:38 +01:00
|
|
|
* is the output of the modpath, and the vvp_fun_modpath_src is the
|
|
|
|
|
* source of the modpath. The modpath source tracks events on the
|
|
|
|
|
* inputs to enable delays, and the vvp_fun_modpath, when it's time to
|
|
|
|
|
* schedule, looks at the associated modpath_src objects for which
|
|
|
|
|
* paths are active.
|
|
|
|
|
*/
|
2006-09-23 06:57:19 +02:00
|
|
|
class vvp_fun_modpath;
|
|
|
|
|
class vvp_fun_modpath_src;
|
|
|
|
|
|
|
|
|
|
class vvp_fun_modpath : public vvp_net_fun_t, private vvp_gen_event_s {
|
|
|
|
|
|
|
|
|
|
public:
|
2010-04-08 12:48:17 +02:00
|
|
|
vvp_fun_modpath(vvp_net_t*net, unsigned width);
|
2006-09-23 06:57:19 +02:00
|
|
|
~vvp_fun_modpath();
|
|
|
|
|
|
2008-04-29 04:00:29 +02:00
|
|
|
void add_modpath_src(vvp_fun_modpath_src*that, bool ifnone);
|
2006-09-23 06:57:19 +02:00
|
|
|
|
2008-10-28 18:52:39 +01:00
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t);
|
2006-09-23 06:57:19 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
virtual void run_run();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vvp_net_t*net_;
|
|
|
|
|
|
|
|
|
|
vvp_vector4_t cur_vec4_;
|
|
|
|
|
|
|
|
|
|
vvp_fun_modpath_src*src_list_;
|
2008-04-29 04:00:29 +02:00
|
|
|
vvp_fun_modpath_src*ifnone_list_;
|
2006-09-23 06:57:19 +02:00
|
|
|
|
|
|
|
|
private: // not implemented
|
|
|
|
|
vvp_fun_modpath(const vvp_fun_modpath&);
|
|
|
|
|
vvp_fun_modpath& operator= (const vvp_fun_modpath&);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class vvp_fun_modpath_src : public vvp_net_fun_t {
|
|
|
|
|
|
|
|
|
|
friend class vvp_fun_modpath;
|
|
|
|
|
|
|
|
|
|
public:
|
2006-09-29 05:57:01 +02:00
|
|
|
vvp_fun_modpath_src(vvp_time64_t d[12]);
|
2007-03-02 07:13:22 +01:00
|
|
|
protected:
|
2006-09-23 06:57:19 +02:00
|
|
|
~vvp_fun_modpath_src();
|
|
|
|
|
|
|
|
|
|
public:
|
2008-10-28 18:52:39 +01:00
|
|
|
void recv_vec4(vvp_net_ptr_t port, const vvp_vector4_t&bit,
|
|
|
|
|
vvp_context_t);
|
2007-03-02 07:13:22 +01:00
|
|
|
virtual bool test_vec4(const vvp_vector4_t&bit);
|
2007-11-07 05:26:03 +01:00
|
|
|
|
|
|
|
|
void get_delay12(vvp_time64_t out[12]) const;
|
|
|
|
|
void put_delay12(const vvp_time64_t in[12]);
|
2007-03-02 07:13:22 +01:00
|
|
|
|
2006-09-23 06:57:19 +02:00
|
|
|
private:
|
|
|
|
|
// FIXME: Needs to be a 12-value array
|
2006-09-29 05:57:01 +02:00
|
|
|
vvp_time64_t delay_[12];
|
2006-09-23 06:57:19 +02:00
|
|
|
// Used by vvp_fun_modpath to keep a list of modpath_src objects.
|
|
|
|
|
vvp_fun_modpath_src*next_;
|
|
|
|
|
|
|
|
|
|
vvp_time64_t wake_time_;
|
2007-03-01 07:19:38 +01:00
|
|
|
bool condition_flag_;
|
2006-09-23 06:57:19 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vvp_fun_modpath_src(const vvp_fun_modpath_src&);
|
|
|
|
|
vvp_fun_modpath_src& operator = (const vvp_fun_modpath_src&);
|
|
|
|
|
};
|
|
|
|
|
|
2007-03-02 07:13:22 +01:00
|
|
|
class vvp_fun_modpath_edge : public vvp_fun_modpath_src {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
vvp_fun_modpath_edge(vvp_time64_t del[12], bool pos, bool neg);
|
|
|
|
|
|
|
|
|
|
bool test_vec4(const vvp_vector4_t&bit);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
vvp_bit4_t old_value_;
|
|
|
|
|
bool posedge_;
|
|
|
|
|
bool negedge_;
|
|
|
|
|
};
|
|
|
|
|
|
2001-11-10 19:07:11 +01:00
|
|
|
#endif // __delay_H
|