Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/fa1b.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                                fa1b
00003                               ------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * fa1b.cpp - device implementations for fa1b 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 "fa1b.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 fa1b::fa1b()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("1bit 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 = "fa1b";
00037   Name  = "Y";
00038 }
00039 
00040 Component * fa1b::newOne()
00041 {
00042   fa1b * p = new fa1b();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * fa1b::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("1Bit FullAdder");
00051   BitmapFile = (char *) "fa1b";
00052 
00053   if(getNewOne) return new fa1b();
00054   return 0;
00055 }
00056 
00057 void fa1b::createSymbol()
00058 {
00059   Lines.append(new Line(-30, -40, 30,-40,QPen(Qt::darkBlue,2)));
00060   Lines.append(new Line( 30, -40, 30, 50,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30,  50,-30, 50,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line(-30,  50,-30,-40,QPen(Qt::darkBlue,2)));
00063 
00064   Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2)));  // A
00065   Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2)));  // B
00066   Lines.append(new Line(-50, 30,-30, 30,QPen(Qt::darkBlue,2)));  // CI
00067   Lines.append(new Line( 30, 10, 50, 10,QPen(Qt::darkBlue,2)));  // CO
00068   Lines.append(new Line( 30,-10, 50,-10,QPen(Qt::darkBlue,2)));  // S
00069   
00070   Texts.append(new Text(-25, 17, "CI", Qt::darkBlue, 12.0));
00071   Texts.append(new Text( 0,  -3, "CO", Qt::darkBlue, 12.0));
00072 
00073   Lines.append(new Line(-10,-35, 10, -35, QPen(Qt::darkBlue,2)));
00074   Lines.append(new Line(-10,-35,  5, -25, QPen(Qt::darkBlue,2)));
00075   Lines.append(new Line(  5,-25,-10, -15, QPen(Qt::darkBlue,2)));
00076   Lines.append(new Line(-10,-15, 10, -15, QPen(Qt::darkBlue,2)));
00077  
00078   Ports.append(new Port(-50,-10));  // A
00079   Ports.append(new Port(-50, 10));  // B
00080   Ports.append(new Port(-50, 30));  // CI
00081   Ports.append(new Port( 50, 10));  // CO
00082   Ports.append(new Port( 50,-10));  // S
00083 
00084   x1 = -50; y1 = -44;
00085   x2 =  50; y2 =  54;
00086 }
00087 
00088 QString fa1b::vhdlCode( int )
00089 {
00090   QString s="";
00091 
00092   QString td = Props.at(1)->Value;     // delay time
00093   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00094   td += ";\n";
00095 
00096   QString A   = Ports.at(0)->Connection->Name;
00097   QString B   = Ports.at(1)->Connection->Name;
00098   QString CI  = Ports.at(2)->Connection->Name;
00099   QString CO  = Ports.at(3)->Connection->Name;
00100   QString S   = Ports.at(4)->Connection->Name;
00101  
00102   s = "\n  " + Name + ":process (" + A + ", " +  B + ", " + CI + ")\n" +
00103       "  begin\n" +
00104       "    " + CO + " <= (" + A + " and " + B +  ") or (" + CI + " and (" + A + " xor " + B + "))" + td +
00105       "    " + S  + " <= " + CI + " xor " + A + " xor " + B + td +
00106       "  end process;\n";
00107   return s;
00108 }
00109 
00110 QString fa1b::verilogCode( int )
00111 {
00112   QString td = Props.at(1)->Value;        // delay time
00113   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00114   
00115   QString l = "";
00116 
00117   QString A   = Ports.at(0)->Connection->Name;
00118   QString B   = Ports.at(1)->Connection->Name;
00119   QString CI  = Ports.at(2)->Connection->Name;
00120   QString CO  = Ports.at(3)->Connection->Name;
00121   QString S   = Ports.at(4)->Connection->Name;
00122 
00123   QString COR = "CO_reg" + Name + CO;
00124   QString SR  = "S_reg"  + Name + S;
00125 
00126   l = "\n  // " + Name + " 1bit fulladder\n" +
00127       "  assign  " + CO + " = " + COR + ";\n" +
00128       "  reg     " + COR + " = 0;\n" +
00129       "  assign  " + S + " = " + SR + ";\n" +
00130       "  reg     " + SR + " = 0;\n" +
00131       "  always @ ("+ A + " or " + B + " or " + CI + ")\n" +
00132       "  begin\n" +
00133       "    " + COR + " <=" + td + " (" + A + " && " + B + ") || " + CI + " && " + "(" + A + " ^ " + B + ");\n" +
00134       "    " + SR + " <=" + td + " (" + CI + " ^ " + A + " ^ "  + B + ");\n" +
00135       "  end\n";
00136 
00137   return l;
00138 }
00139 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines