Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/andor4x2.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               andor4x2
00003                              ----------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * andor4x2.cpp - device implementations for andor4x2 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 "andor4x2.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 andor4x2::andor4x2()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("4x2 andor 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 = "andor4x2";
00037   Name  = "Y";
00038 }
00039 
00040 Component * andor4x2::newOne()
00041 {
00042   andor4x2 * p = new andor4x2();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * andor4x2::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("4x2 AndOr");
00051   BitmapFile = (char *) "andor4x2";
00052 
00053   if(getNewOne) return new andor4x2();
00054   return 0;
00055 }
00056 
00057 void andor4x2::createSymbol()
00058 {
00059   Lines.append(new Line(-30, -60, 30,-60,QPen(Qt::darkBlue,2)));
00060   Lines.append(new Line( 30, -60, 30, 60,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30,  60,-30, 60,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line(-30,  60,-30,-60,QPen(Qt::darkBlue,2)));
00063 
00064   Lines.append(new Line(-30, -30,  0,-30,QPen(Qt::darkBlue,2)));
00065   Lines.append(new Line(-30,   0,  0,  0,QPen(Qt::darkBlue,2)));
00066   Lines.append(new Line(-30,  30,  0, 30,QPen(Qt::darkBlue,2)));
00067   Lines.append(new Line(  0, -60,  0, 60,QPen(Qt::darkBlue,2)));
00068 
00069   Lines.append(new Line(-50,-50,-30,-50,QPen(Qt::darkBlue,2)));   //A11
00070   Lines.append(new Line(-50,-40,-30,-40,QPen(Qt::darkBlue,2)));   //A12
00071   Lines.append(new Line(-50,-20,-30,-20,QPen(Qt::darkBlue,2)));   //A21
00072   Lines.append(new Line(-50,-10,-30,-10,QPen(Qt::darkBlue,2)));   //A22
00073 
00074   Lines.append(new Line(-50, 10, -30, 10,QPen(Qt::darkBlue,2)));  //A31
00075   Lines.append(new Line(-50, 20, -30, 20,QPen(Qt::darkBlue,2)));  //A32
00076   Lines.append(new Line(-50, 40, -30, 40,QPen(Qt::darkBlue,2)));  //A41
00077   Lines.append(new Line(-50, 50, -30, 50,QPen(Qt::darkBlue,2)));  //A42
00078   Lines.append(new Line( 30,  0,  50,  0,QPen(Qt::darkBlue,2)));  //Y
00079 
00080   Texts.append(new Text( -20, -60, "&", Qt::darkBlue, 12.0));
00081   Texts.append(new Text( -20, -30, "&", Qt::darkBlue, 12.0));
00082   Texts.append(new Text( -20,   0, "&", Qt::darkBlue, 12.0));
00083   Texts.append(new Text( -20,  30, "&", Qt::darkBlue, 12.0));
00084  
00085   Lines.append(new Line(  7, -45, 17, -40,QPen(Qt::darkBlue,2))); 
00086   Lines.append(new Line(  7, -35, 17, -40,QPen(Qt::darkBlue,2)));
00087   Lines.append(new Line(  7, -30, 17, -35,QPen(Qt::darkBlue,2))); 
00088   Lines.append(new Line( 22, -30, 22, -45,QPen(Qt::darkBlue,2)));  
00089 
00090 
00091   Ports.append(new Port(-50,-50));  // A11
00092   Ports.append(new Port(-50,-40));  // A12
00093   Ports.append(new Port(-50,-20));  // A21
00094   Ports.append(new Port(-50,-10));  // A22
00095   Ports.append(new Port(-50, 10));  // A31
00096   Ports.append(new Port(-50, 20));  // A32
00097   Ports.append(new Port(-50, 40));  // A41
00098   Ports.append(new Port(-50, 50));  // A42
00099 
00100   Ports.append(new Port( 50, 0 )); // Y
00101 
00102   x1 = -50; y1 = -64;
00103   x2 =  50; y2 =  64;
00104 }
00105 
00106 QString andor4x2::vhdlCode( int )
00107 {
00108   QString s="";
00109 
00110   QString td = Props.at(1)->Value;     // delay time
00111   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00112   td += ";\n";
00113 
00114   QString a11 = Ports.at(0)->Connection->Name;
00115   QString a12 = Ports.at(1)->Connection->Name;
00116   QString a21 = Ports.at(2)->Connection->Name;
00117   QString a22 = Ports.at(3)->Connection->Name;
00118   QString a31 = Ports.at(4)->Connection->Name;
00119   QString a32 = Ports.at(5)->Connection->Name;
00120   QString a41 = Ports.at(6)->Connection->Name;
00121   QString a42 = Ports.at(7)->Connection->Name;
00122   QString y   = Ports.at(8)->Connection->Name;
00123 
00124   s = "\n  " + Name +":process ("+a11+", "+a12+", "+a21+", "+ a22+", "+
00125                            a31+", "+a32+", "+a41+", "+a42 + ")\n"+
00126      "  begin\n    " +
00127      y+" <= "+"("+a11+" and "+a12+") or "+"("+a21+" and "+a22+") or "+ 
00128        "\n                 ("+a31+" and " +a32+") or "+ "("+a41+" and "+a42+")"+td+
00129     "  end process;\n";
00130   return s;
00131 }
00132 
00133 QString andor4x2::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 a11 = Ports.at(0)->Connection->Name;
00141   QString a12 = Ports.at(1)->Connection->Name;
00142   QString a21 = Ports.at(2)->Connection->Name;
00143   QString a22 = Ports.at(3)->Connection->Name;
00144   QString a31 = Ports.at(4)->Connection->Name;
00145   QString a32 = Ports.at(5)->Connection->Name;
00146   QString a41 = Ports.at(6)->Connection->Name;
00147   QString a42 = Ports.at(7)->Connection->Name;
00148   QString y   = Ports.at(8)->Connection->Name;
00149 
00150   QString v = "net_reg" + Name + y;
00151 
00152   l = "\n  // " + Name + " 4x2 andor\n" +
00153       "  assign  " + y + " = " + v + ";\n" +
00154       "  reg     " + v + " = 0;\n" +
00155       "  always @ (" + a11 + " or " + a12 + " or "
00156                      + a21 + " or " + a22 + " or "
00157          + a31 + " or " + a32 + " or " 
00158                      + a41 + " or " + a42 + ")\n  " +
00159       "  " + v + " <=" + td + " (" + a11 + " && " + a12 + ")" + " || " +
00160                "(" + a21 + " && " + a22 + ")" + " || " +
00161                "(" + a31 + " && " + a32 + ")" + " || " +
00162                "(" + a41 + " && " + a42 + ")" + ";\n" ;
00163   return l;
00164 }
00165 
00166 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines