Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/mux2to1.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                              mux2to1
00003                             ---------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * mux2to1.cpp - device implementations for mux2to1 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 "mux2to1.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 mux2to1::mux2to1()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("2to1 multiplexer 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 = "mux2to1";
00037   Name  = "Y";
00038 }
00039 
00040 Component * mux2to1::newOne()
00041 {
00042   mux2to1 * p = new mux2to1();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * mux2to1::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("2to1 Mux");
00051   BitmapFile = (char *) "mux2to1";
00052 
00053   if(getNewOne) return new mux2to1();
00054   return 0;
00055 }
00056 
00057 void mux2to1::createSymbol()
00058 {
00059   // put in here symbol drawing code and terminal definitions
00060   Lines.append(new Line(-30, -60, 30,-60,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30, -60, 30, 50,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line( 30,  50,-30, 50,QPen(Qt::darkBlue,2)));
00063   Lines.append(new Line(-30,  50,-30,-60,QPen(Qt::darkBlue,2)));
00064 
00065   Lines.append(new Line(-50,-20,-40,-20,QPen(Qt::darkBlue,2)));
00066   Lines.append(new Line(-50,  0,-30,  0,QPen(Qt::darkBlue,2)));
00067   Lines.append(new Line(-50, 20,-30, 20,QPen(Qt::darkBlue,2)));
00068   Lines.append(new Line(-50, 40,-30, 40,QPen(Qt::darkBlue,2)));
00069 
00070   Lines.append(new Line( 30, 0, 50, 0,QPen(Qt::darkBlue,2)));
00071 
00072   Arcs.append(new Arc(-40, -25, 10, 10, 0, 16*360, QPen(Qt::darkBlue,2)));
00073  
00074   Texts.append(new Text(-17,-55, "MUX", Qt::darkBlue, 12.0));
00075 
00076   Texts.append(new Text(-25,-33, "En", Qt::darkBlue, 12.0));
00077   Texts.append(new Text(-25,-13, "0", Qt::darkBlue, 12.0));
00078 
00079   Texts.append(new Text(-15,-15, "G", Qt::darkBlue, 12.0));
00080   Texts.append(new Text( -1,-21, "}", Qt::darkBlue, 16.0));
00081   Texts.append(new Text( 12,-22, "0", Qt::darkBlue, 12.0));
00082   Texts.append(new Text( 12, -2, "1", Qt::darkBlue, 12.0));
00083 
00084   Lines.append(new Line(11, 0, 23, 0, QPen(Qt::darkBlue,2)));
00085 
00086   Texts.append(new Text(-25,  7, "0", Qt::darkBlue, 12.0));
00087   Texts.append(new Text(-25, 27, "1", Qt::darkBlue, 12.0));
00088 
00089   Ports.append(new Port(-50,-20));  // En
00090   Ports.append(new Port(-50,  0));  // A
00091   Ports.append(new Port(-50, 20));  // D0
00092   Ports.append(new Port(-50, 40));  // D1
00093   Ports.append(new Port( 50, 0 ));  // Y
00094 
00095   x1 = -50; y1 = -64;
00096   x2 =  50; y2 =  54;
00097 }
00098 
00099 QString mux2to1::vhdlCode( int )
00100 {
00101   QString s="";
00102 
00103   QString td = Props.at(1)->Value;
00104   if(!misc::VHDL_Delay(td, Name))
00105     return td;      // Time does not have VHDL format.
00106   td += ";\n";
00107 
00108   QString En = Ports.at(0)->Connection->Name;
00109   QString A  = Ports.at(1)->Connection->Name;
00110   QString D0 = Ports.at(2)->Connection->Name;
00111   QString D1 = Ports.at(3)->Connection->Name;
00112   QString y  = Ports.at(4)->Connection->Name;
00113 
00114   s = "\n  " + Name + ":process (" + En + ", " +  A + ", " + D0 + ", " +  D1 + ")\n" +
00115      "  begin\n" +
00116      "    " + y + " <= " +  "(not " + En + ") and ((" + D1 + " and " + A + ") or " + 
00117                   "(" + D0 + " and " + "(not " + A + ")))" + td +
00118      "  end process;\n";
00119   return s;
00120 }
00121 
00122 QString mux2to1::verilogCode( int )
00123 {
00124   QString td = Props.at(1)->Value;
00125   if(!misc::Verilog_Delay(td, Name))
00126     return td;      // Time does not have VHDL format.
00127   td += " ";
00128   
00129   QString l = "";
00130 
00131   QString En = Ports.at(0)->Connection->Name;
00132   QString A  = Ports.at(1)->Connection->Name;
00133   QString D0 = Ports.at(2)->Connection->Name;
00134   QString D1 = Ports.at(3)->Connection->Name;
00135   QString y  = Ports.at(4)->Connection->Name;
00136 
00137   QString v = "net_reg" + Name + y;
00138   
00139   l = "\n  // " + Name + " 2to1 mux\n" +
00140       "  assign  " + y + " = " + v + ";\n" +
00141       "  reg     " + v + " = 0;\n" +
00142       "  always @ (" + En + " or " + A + " or "
00143                      + D0 + " or " + D1 +  ")\n" +
00144       "    " + v + " <=" + td + "(" + D1 + " && " + A + ")" + " || " +
00145                "(" + D0 + " && (~" + A + "));\n" ;
00146 
00147   return l;
00148 }
00149 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines