iverilog/vvp/delay.cc

135 lines
3.3 KiB
C++
Raw Normal View History

/*
2005-04-03 07:45:51 +02:00
* Copyright (c) 2005 Stephen Williams <steve@icarus.com>
*
* 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
*/
#ifdef HAVE_CVS_IDENT
#ident "$Id: delay.cc,v 1.5 2005/05/14 19:43:23 steve Exp $"
#endif
#include "delay.h"
#include "schedule.h"
#include <string.h>
2005-04-03 07:45:51 +02:00
#include <stream.h>
#include <assert.h>
2005-04-03 07:45:51 +02:00
vvp_delay_t::vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall)
{
2005-04-03 07:45:51 +02:00
rise_ = rise;
fall_ = fall;
decay_= fall < rise? fall : rise;
min_delay_ = decay_;
}
2005-04-03 07:45:51 +02:00
vvp_delay_t::vvp_delay_t(vvp_time64_t rise, vvp_time64_t fall, vvp_time64_t decay)
{
2005-04-03 07:45:51 +02:00
rise_ = rise;
fall_ = fall;
decay_= decay;
min_delay_ = rise_;
if (fall_ < min_delay_)
min_delay_ = fall_;
if (decay_ < min_delay_)
min_delay_ = decay_;
}
2005-04-03 07:45:51 +02:00
vvp_delay_t::~vvp_delay_t()
{
}
2005-04-03 07:45:51 +02:00
vvp_time64_t vvp_delay_t::get_delay(vvp_bit4_t from, vvp_bit4_t to)
{
2005-04-03 07:45:51 +02:00
switch (from) {
case BIT4_0:
switch (to) {
case BIT4_0: return 0;
case BIT4_1: return rise_;
case BIT4_X: return min_delay_;
case BIT4_Z: return decay_;
}
break;
2005-04-03 07:45:51 +02:00
case BIT4_1:
switch (to) {
case BIT4_0: return fall_;
case BIT4_1: return 0;
case BIT4_X: return min_delay_;
case BIT4_Z: return decay_;
}
break;
2005-04-03 07:45:51 +02:00
case BIT4_X:
switch (to) {
case BIT4_0: return fall_;
case BIT4_1: return rise_;
case BIT4_X: return 0;
case BIT4_Z: return decay_;
}
break;
case BIT4_Z:
switch (to) {
case BIT4_0: return fall_;
case BIT4_1: return rise_;
case BIT4_X: return min_delay_;
case BIT4_Z: return 0;
}
2005-04-03 07:45:51 +02:00
break;
}
2005-04-03 07:45:51 +02:00
assert(0);
return 0;
}
vvp_fun_delay::vvp_fun_delay(vvp_bit4_t init, const vvp_delay_t&d)
: delay_(d), cur_(1)
{
cur_.set_bit(0, init);
}
vvp_fun_delay::~vvp_fun_delay()
{
}
/*
* FIXME: This implementation currently only uses the LSB to determine
* the delay type for the entire vector. It needs to be upgraded to
* account for different delays for different bits by generating a
* stream of vectors that lead up to the actual value.
*/
void vvp_fun_delay::recv_vec4(vvp_net_ptr_t port, vvp_vector4_t bit)
{
if (cur_.eeq(bit))
return;
vvp_time64_t use_delay;
use_delay = delay_.get_delay(cur_.value(0), bit.value(0));
cur_ = bit;
if (use_delay == 0)
vvp_send_vec4(port.ptr()->out, cur_);
else
schedule_assign_vector(port.ptr()->out, cur_, use_delay);
}
/*
2005-04-03 07:45:51 +02:00
* $Log: delay.cc,v $
* Revision 1.5 2005/05/14 19:43:23 steve
* Move functor delays to vvp_delay_fun object.
*
2005-04-03 07:45:51 +02:00
* Revision 1.4 2005/04/03 05:45:51 steve
* Rework the vvp_delay_t class.
*
*/