iverilog/vvp/npmos.cc

102 lines
2.5 KiB
C++
Raw Normal View History

2001-10-09 04:28:16 +02:00
/*
2005-06-12 02:44:49 +02:00
* Copyright (c) 2005 Stephen Williams (steve@icarus.com)
2001-10-09 04:28:16 +02: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
*/
#ifdef HAVE_CVS_IDENT
2005-06-12 02:44:49 +02:00
#ident "$Id: npmos.cc,v 1.11 2005/06/12 00:44:49 steve Exp $"
2001-10-09 04:28:16 +02:00
#endif
# include "npmos.h"
2005-06-12 02:44:49 +02:00
vvp_fun_pmos::vvp_fun_pmos(bool enable_invert)
2001-10-09 04:28:16 +02:00
{
2005-06-12 02:44:49 +02:00
inv_en_ = enable_invert;
}
2001-10-11 20:20:51 +02:00
2005-06-12 02:44:49 +02:00
void vvp_fun_pmos::recv_vec4(vvp_net_ptr_t ptr, vvp_vector4_t bit)
{
/* Data input is processed throught eh recv_vec8 method,
because the strength most be preserved. */
if (ptr.port() == 0) {
vvp_vector8_t tmp = bit;
recv_vec8(ptr, tmp);
return;
}
2005-06-12 02:44:49 +02:00
if (ptr.port() != 1)
return;
2005-06-12 02:44:49 +02:00
en_ = inv_en_? ~bit : bit;
generate_output_(ptr);
}
2005-06-12 02:44:49 +02:00
void vvp_fun_pmos::recv_vec8(vvp_net_ptr_t ptr, vvp_vector8_t bit)
{
if (ptr.port() == 1) {
recv_vec4(ptr, reduce4(bit));
return;
}
2005-06-12 02:44:49 +02:00
if (ptr.port() != 0)
return;
2005-06-12 02:44:49 +02:00
bit_ = bit;
generate_output_(ptr);
}
2001-10-09 04:28:16 +02:00
2005-06-12 02:44:49 +02:00
void vvp_fun_pmos::generate_output_(vvp_net_ptr_t ptr)
{
vvp_vector8_t out (bit_.size());
2005-06-12 02:44:49 +02:00
for (unsigned idx = 0 ; idx < out.size() ; idx += 1) {
vvp_bit4_t b_en = en_.value(idx);
vvp_scalar_t b_bit = bit_.value(idx);
2005-06-12 02:44:49 +02:00
switch (b_en) {
case BIT4_0:
out.set_bit(idx, b_bit);
2001-10-09 04:28:16 +02:00
break;
2005-06-12 02:44:49 +02:00
case BIT4_1:
out.set_bit(idx, vvp_scalar_t(BIT4_Z,0,0));
2001-10-09 04:28:16 +02:00
break;
default:
2005-06-12 02:44:49 +02:00
switch (b_bit.value()) {
case BIT4_0:
b_bit = vvp_scalar_t(BIT4_X,b_bit.strength0(),0);
break;
case BIT4_1:
b_bit = vvp_scalar_t(BIT4_X,0,b_bit.strength1());
break;
default:
break;
}
out.set_bit(idx, b_bit);
2001-10-09 04:28:16 +02:00
break;
}
}
2005-06-12 02:44:49 +02:00
vvp_send_vec8(ptr.ptr()->out, out);
2001-10-09 04:28:16 +02:00
}
/*
* $Log: npmos.cc,v $
2005-06-12 02:44:49 +02:00
* Revision 1.11 2005/06/12 00:44:49 steve
* Implement nmos and pmos devices.
2001-10-09 04:28:16 +02:00
*
*/