Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 fa2b 00003 ------ 00004 begin : December 2008 00005 copyright : (C) 2008 by Mike Brinson 00006 email : mbrin72043@yahoo.co.uk 00007 ***************************************************************************/ 00008 00009 /* 00010 * fa2b.cpp - device implementations for fa2b 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 "fa2b.h" 00019 #include "node.h" 00020 #include "misc.h" 00021 00022 fa2b::fa2b() 00023 { 00024 Type = isComponent; // Analogue and digital component. 00025 Description = QObject::tr ("2bit full adder 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 = "fa2b"; 00037 Name = "Y"; 00038 } 00039 00040 Component * fa2b::newOne() 00041 { 00042 fa2b * p = new fa2b(); 00043 p->Props.getFirst()->Value = Props.getFirst()->Value; 00044 p->recreate(0); 00045 return p; 00046 } 00047 00048 Element * fa2b::info(QString& Name, char * &BitmapFile, bool getNewOne) 00049 { 00050 Name = QObject::tr("2Bit FullAdder"); 00051 BitmapFile = (char *) "fa2b"; 00052 00053 if(getNewOne) return new fa2b(); 00054 return 0; 00055 } 00056 00057 void fa2b::createSymbol() 00058 { 00059 Lines.append(new Line(-40, -60, 40,-60,QPen(Qt::darkBlue,2))); 00060 Lines.append(new Line( 40, -60, 40, 90,QPen(Qt::darkBlue,2))); 00061 Lines.append(new Line( 40, 90,-40, 90,QPen(Qt::darkBlue,2))); 00062 Lines.append(new Line(-40, 90,-40, -60,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(-60, 70,-40, 70,QPen(Qt::darkBlue,2))); // CI 00069 00070 Lines.append(new Line( 40, 30, 60, 30,QPen(Qt::darkBlue,2))); // C0 00071 Lines.append(new Line( 40, 10, 60, 10,QPen(Qt::darkBlue,2))); // S1 00072 Lines.append(new Line( 40,-10, 60,-10,QPen(Qt::darkBlue,2))); // S0 00073 00074 Lines.append(new Line( -10, -55, 10, -55, QPen(Qt::darkBlue,2))); 00075 Lines.append(new Line( -10, -55, 0, -45, QPen(Qt::darkBlue,2))); 00076 Lines.append(new Line( 0, -45,-10, -35, QPen(Qt::darkBlue,2))); 00077 Lines.append(new Line( -10, -35, 10, -35, QPen(Qt::darkBlue,2))); 00078 00079 Texts.append(new Text(-25,-20, "{", Qt::darkBlue, 16.0)); 00080 Texts.append(new Text(-15,-13, "X", Qt::darkBlue, 12.0)); 00081 Texts.append(new Text(-35,-23, "0", Qt::darkBlue, 12.0)); 00082 Texts.append(new Text(-35, -3, "1", Qt::darkBlue, 12.0)); 00083 Texts.append(new Text(-25, 22, "{", Qt::darkBlue, 16.0)); 00084 Texts.append(new Text(-15, 29, "Y", Qt::darkBlue, 12.0)); 00085 Texts.append(new Text(-35, 17, "0", Qt::darkBlue, 12.0)); 00086 Texts.append(new Text(-35, 37, "1", Qt::darkBlue, 12.0)); 00087 Texts.append(new Text(-35, 57, "CI", Qt::darkBlue, 12.0)); 00088 Texts.append(new Text( 17,-20, "}", Qt::darkBlue, 16.0)); 00089 Texts.append(new Text( 3, -13, "S", Qt::darkBlue, 12.0)); 00090 Texts.append(new Text( 28,-23, "0", Qt::darkBlue, 12.0)); 00091 Texts.append(new Text( 28, -3, "1", Qt::darkBlue, 12.0)); 00092 Texts.append(new Text( 10, 17, "CO", Qt::darkBlue, 12.0)); 00093 00094 Ports.append(new Port(-60,-10)); // X0 -> D 00095 Ports.append(new Port(-60, 10)); // X1 -> C 00096 Ports.append(new Port(-60, 30)); // Y0 -> B 00097 Ports.append(new Port(-60, 50)); // Y1 -> A 00098 Ports.append(new Port(-60, 70)); // CI -> E 00099 Ports.append(new Port( 60, 30)); // CO 00100 Ports.append(new Port( 60, 10)); // S1 00101 Ports.append(new Port( 60,-10)); // S0 00102 00103 x1 = -60; y1 = -64; 00104 x2 = 60; y2 = 94; 00105 } 00106 00107 QString fa2b::vhdlCode( int ) 00108 { 00109 QString s=""; 00110 00111 QString td = Props.at(1)->Value; // delay time 00112 if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format 00113 td += ";\n"; 00114 00115 QString D = Ports.at(0)->Connection->Name; 00116 QString C = Ports.at(1)->Connection->Name; 00117 QString B = Ports.at(2)->Connection->Name; 00118 QString A = Ports.at(3)->Connection->Name; 00119 QString E = Ports.at(4)->Connection->Name; 00120 QString CO = Ports.at(5)->Connection->Name; 00121 QString S1 = Ports.at(6)->Connection->Name; 00122 QString S0 = Ports.at(7)->Connection->Name; 00123 00124 s = "\n "+Name+":process ("+A+", "+B+", "+C+", "+D+", "+E+ ")\n"+ 00125 " begin\n" + 00126 " "+CO+" <= ("+A+" and "+C+") or (("+A+" or "+C+") and (("+B+" and "+D+") or ("+E+" and "+B+") or ("+E+" and "+ D +")))"+td+ 00127 " "+S1+" <= (("+B+" and "+D+") or ("+E+" and "+B+") or ("+E+" and "+D+"))"+" xor ("+A+" xor "+C+")"+td+ 00128 " "+S0+" <= "+E+" xor ("+B+" xor "+D+")"+td+ 00129 " end process;\n"; 00130 return s; 00131 } 00132 00133 QString fa2b::verilogCode( int ) 00134 { 00135 QString td = Props.at(1)->Value; // delay time 00136 if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format 00137 00138 QString l = ""; 00139 00140 QString D = Ports.at(0)->Connection->Name; 00141 QString C = Ports.at(1)->Connection->Name; 00142 QString B = Ports.at(2)->Connection->Name; 00143 QString A = Ports.at(3)->Connection->Name; 00144 QString E = Ports.at(4)->Connection->Name; 00145 QString CO = Ports.at(5)->Connection->Name; 00146 QString S1 = Ports.at(6)->Connection->Name; 00147 QString S0 = Ports.at(7)->Connection->Name; 00148 00149 QString COR = "CO_reg" + Name + CO; 00150 QString S1R = "S1_reg" + Name + S1; 00151 QString S0R = "S0_reg" + Name + S0; 00152 00153 l = "\n // "+Name+" 2bit fulladder\n"+ 00154 " assign "+CO+" = "+COR+";\n"+ 00155 " reg "+COR+" = 0;\n"+ 00156 " assign "+S1+" = "+S1R+";\n"+ 00157 " reg "+S1R+" = 0;\n"+ 00158 " assign "+S0+" = "+S0R+";\n"+ 00159 " reg "+S0R+" = 0;\n"+ 00160 " always @ ("+A+" or "+B+" or "+C+" or "+D+" or "+E+")\n"+ 00161 " begin\n" + 00162 " " +COR+" <="+td+" ("+A+" && "+C+") || ("+A+" || "+C+") && ("+B+" && "+D+" || "+E+" && "+B+" || "+E+" && "+D+");\n"+ 00163 " " +S1R+" <="+td+" ("+B+" && "+D+" || "+E+" && "+B+" || "+E+" && "+D+") ^ ("+A+" ^ "+C+");\n" + 00164 " " +S0R+" <="+td+" "+E+" ^ ("+B+" ^ "+D+");\n"+ 00165 " end\n"; 00166 00167 return l; 00168 } 00169