Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 comp_2bit 00003 ----------- 00004 begin : December 2008 00005 copyright : (C) 2008 by Mike Brinson 00006 email : mbrin72043@yahoo.co.uk 00007 ***************************************************************************/ 00008 00009 /* 00010 * comp_2bit.cpp - device implementations for comp_2bit module 00011 * 00012 * This is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License as published by 00014 * the Free Software Foundation; either version 2, or (at your option) 00015 * any later version. 00016 * 00017 */ 00018 #include "comp_2bit.h" 00019 #include "node.h" 00020 #include "misc.h" 00021 00022 comp_2bit::comp_2bit() 00023 { 00024 Type = isComponent; // Analogue and digital component. 00025 Description = QObject::tr ("2bit comparator verilog device"); 00026 00027 Props.append (new Property ("TR", "6", false, 00028 QObject::tr ("transfer function high scaling factor"))); 00029 Props.append (new Property ("Delay", "1 ns", false, 00030 QObject::tr ("output delay") 00031 +" ("+QObject::tr ("s")+")")); 00032 00033 createSymbol (); 00034 tx = x1 + 19; 00035 ty = y2 + 4; 00036 Model = "comp_2bit"; 00037 Name = "Y"; 00038 } 00039 00040 Component * comp_2bit::newOne() 00041 { 00042 comp_2bit * p = new comp_2bit(); 00043 p->Props.getFirst()->Value = Props.getFirst()->Value; 00044 p->recreate(0); 00045 return p; 00046 } 00047 00048 Element * comp_2bit::info(QString& Name, char * &BitmapFile, bool getNewOne) 00049 { 00050 Name = QObject::tr("2Bit Comparator"); 00051 BitmapFile = (char *) "comp_2bit"; 00052 00053 if(getNewOne) return new comp_2bit(); 00054 return 0; 00055 } 00056 00057 void comp_2bit::createSymbol() 00058 { 00059 Lines.append(new Line(-40, -50, 40,-50,QPen(Qt::darkBlue,2))); 00060 Lines.append(new Line( 40, -50, 40, 60,QPen(Qt::darkBlue,2))); 00061 Lines.append(new Line( 40, 60,-40, 60,QPen(Qt::darkBlue,2))); 00062 Lines.append(new Line(-40, 60,-40, -50,QPen(Qt::darkBlue,2))); 00063 00064 Lines.append(new Line(-60,-10,-40,-10,QPen(Qt::darkBlue,2))); // X0 00065 Lines.append(new Line(-60, 10,-40, 10,QPen(Qt::darkBlue,2))); // X1 00066 Lines.append(new Line(-60, 30,-40, 30,QPen(Qt::darkBlue,2))); // Y0 00067 Lines.append(new Line(-60, 50,-40, 50,QPen(Qt::darkBlue,2))); // Y1 00068 Lines.append(new Line( 40, 30, 60, 30,QPen(Qt::darkBlue,2))); // L 00069 Lines.append(new Line( 40, 10, 60, 10,QPen(Qt::darkBlue,2))); // G 00070 Lines.append(new Line( 40,-10, 60,-10,QPen(Qt::darkBlue,2))); // E 00071 00072 Texts.append(new Text(-25,-45, "COMP", Qt::darkBlue, 12.0)); 00073 00074 Texts.append(new Text(-25,-20, "{", Qt::darkBlue, 16.0)); 00075 Texts.append(new Text(-15,-15, "X", Qt::darkBlue, 12.0)); 00076 Texts.append(new Text(-35,-23, "0", Qt::darkBlue, 12.0)); 00077 Texts.append(new Text(-35, -3, "1", Qt::darkBlue, 12.0)); 00078 Texts.append(new Text(-25, 22, "{", Qt::darkBlue, 16.0)); 00079 Texts.append(new Text(-15, 27, "Y", Qt::darkBlue, 12.0)); 00080 Texts.append(new Text(-35, 17, "0", Qt::darkBlue, 12.0)); 00081 Texts.append(new Text(-35, 37, "1", Qt::darkBlue, 12.0)); 00082 Texts.append(new Text( 5, 17, "X<Y", Qt::darkBlue, 12.0)); 00083 Texts.append(new Text( 5, -3, "X>Y", Qt::darkBlue, 12.0)); 00084 Texts.append(new Text( 5,-23, "X=Y", Qt::darkBlue, 12.0)); 00085 00086 Ports.append(new Port(-60,-10)); // X0 00087 Ports.append(new Port(-60, 10)); // X1 00088 Ports.append(new Port(-60, 30)); // Y0 00089 Ports.append(new Port(-60, 50)); // Y1 00090 Ports.append(new Port( 60, 30)); // L 00091 Ports.append(new Port( 60, 10)); // G 00092 Ports.append(new Port( 60,-10)); // E 00093 00094 x1 = -60; y1 = -54; 00095 x2 = 60; y2 = 64; 00096 } 00097 00098 QString comp_2bit::vhdlCode( int ) 00099 { 00100 QString s=""; 00101 00102 QString td = Props.at(1)->Value; // delay time 00103 if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format 00104 td += ";\n"; 00105 00106 QString X0 = Ports.at(0)->Connection->Name; 00107 QString X1 = Ports.at(1)->Connection->Name; 00108 QString Y0 = Ports.at(2)->Connection->Name; 00109 QString Y1 = Ports.at(3)->Connection->Name; 00110 QString L = Ports.at(4)->Connection->Name; 00111 QString G = Ports.at(5)->Connection->Name; 00112 QString E = Ports.at(6)->Connection->Name; 00113 00114 s = "\n "+Name+":process ("+X0+", "+X1+", "+Y0+", "+Y1+")\n"+ 00115 " begin\n"+ 00116 " "+L+" <= ((not "+X1+") and "+Y1+") or (not ("+X1+" xor "+Y1+") and (not ("+X0+") and "+Y0+"))"+td+ 00117 " "+G+" <= ("+X1+" and (not "+Y1+"))"+" or (not ("+X1+" xor "+Y1+") and ("+X0+" and (not "+Y0+")))"+td+ 00118 " "+E+" <= (not ("+X1+" xor "+Y1+")) and (not ("+X0+" xor "+Y0+"))"+td+ 00119 " end process;\n"; 00120 return s; 00121 } 00122 00123 QString comp_2bit::verilogCode( int ) 00124 { 00125 QString l=""; 00126 00127 QString td = Props.at(1)->Value; // delay time 00128 if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format 00129 00130 QString X0 = Ports.at(0)->Connection->Name; 00131 QString X1 = Ports.at(1)->Connection->Name; 00132 QString Y0 = Ports.at(2)->Connection->Name; 00133 QString Y1 = Ports.at(3)->Connection->Name; 00134 QString L = Ports.at(4)->Connection->Name; 00135 QString G = Ports.at(5)->Connection->Name; 00136 QString E = Ports.at(6)->Connection->Name; 00137 00138 QString LR = "L_reg" + Name + L; 00139 QString GR = "G_reg" + Name + G; 00140 QString ER = "E_reg" + Name + E; 00141 00142 l = "\n // "+Name+" 2bit comparator\n"+ 00143 " assign "+L+" = "+LR+";\n"+ 00144 " reg "+LR+" = 0;\n"+ 00145 " assign "+G+" = "+GR+";\n"+ 00146 " reg "+GR+" = 0;\n"+ 00147 " assign "+E+" = "+ER+";\n"+ 00148 " reg "+ER+" = 0;\n"+ 00149 " always @ ("+X0+" or "+X1+" or "+Y0+" or "+Y1+")\n"+ 00150 " begin\n"+ 00151 " "+LR+" <="+td+" ((~"+X1+") && "+Y1+") || (~("+X1+" ^ "+Y1+") && (~("+X0+") && "+Y0+"));\n"+ 00152 " "+GR+" <="+td+" ("+X1+" && (~"+Y1+"))"+" || (~("+X1+" ^ "+Y1+") && ("+X0+" && (~"+Y0+")));\n"+ 00153 " "+ER+" <="+td+" (~("+X1+" ^ "+Y1+")) && (~("+X0+" ^ "+Y0+"));\n"+ 00154 " end\n"; 00155 00156 return l; 00157 }