Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/andor4x4.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                               andor4x4
00003                              ----------
00004     begin                : December 2008
00005     copyright            : (C) 2008 by Mike Brinson
00006     email                : mbrin72043@yahoo.co.uk
00007  ***************************************************************************/
00008 
00009 /*
00010  * andor4x4.cpp - device implementations for andor4x4 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 "andor4x4.h"
00019 #include "node.h"
00020 #include "misc.h"
00021 
00022 andor4x4::andor4x4()
00023 {
00024   Type = isComponent; // Analogue and digital component.
00025   Description = QObject::tr ("4x4 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 = "andor4x4";
00037   Name  = "Y";
00038 }
00039 
00040 Component * andor4x4::newOne()
00041 {
00042   andor4x4 * p = new andor4x4();
00043   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00044   p->recreate(0); 
00045   return p;
00046 }
00047 
00048 Element * andor4x4::info(QString& Name, char * &BitmapFile, bool getNewOne)
00049 {
00050   Name = QObject::tr("4x4 AndOr");
00051   BitmapFile = (char *) "andor4x4";
00052 
00053   if(getNewOne) return new andor4x4();
00054   return 0;
00055 }
00056 
00057 void andor4x4::createSymbol()
00058 {
00059   Lines.append(new Line(-30, -60, 30,-60,QPen(Qt::darkBlue,2)));
00060   Lines.append(new Line( 30, -60, 30, 140,QPen(Qt::darkBlue,2)));
00061   Lines.append(new Line( 30,  140,-30,140,QPen(Qt::darkBlue,2)));
00062   Lines.append(new Line(-30,  140,-30,-60,QPen(Qt::darkBlue,2)));
00063 
00064   Lines.append(new Line(-30, -10,  0,-10,QPen(Qt::darkBlue,2)));
00065   Lines.append(new Line(-30,  40,  0, 40,QPen(Qt::darkBlue,2)));
00066   Lines.append(new Line(-30,  90,  0, 90,QPen(Qt::darkBlue,2)));
00067   Lines.append(new Line(  0, -60,  0,140,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,-30,-30,-30,QPen(Qt::darkBlue,2)));   //A13
00072   Lines.append(new Line(-50,-20,-30,-20,QPen(Qt::darkBlue,2)));   //A14
00073 
00074   Lines.append(new Line(-50,  0,-30,  0,QPen(Qt::darkBlue,2)));   //A21
00075   Lines.append(new Line(-50, 10,-30, 10,QPen(Qt::darkBlue,2)));   //A22
00076   Lines.append(new Line(-50, 20,-30, 20,QPen(Qt::darkBlue,2)));   //A23
00077   Lines.append(new Line(-50, 30,-30, 30,QPen(Qt::darkBlue,2)));   //A24
00078 
00079   Lines.append(new Line(-50, 50, -30, 50,QPen(Qt::darkBlue,2)));  //A31
00080   Lines.append(new Line(-50, 60, -30, 60,QPen(Qt::darkBlue,2)));  //A32
00081   Lines.append(new Line(-50, 70,-30,  70,QPen(Qt::darkBlue,2)));  //A33
00082   Lines.append(new Line(-50, 80, -30, 80,QPen(Qt::darkBlue,2)));   //A34
00083 
00084   Lines.append(new Line(-50, 100,-30,100,QPen(Qt::darkBlue,2)));  //A41
00085   Lines.append(new Line(-50, 110,-30,110,QPen(Qt::darkBlue,2)));  //A42
00086   Lines.append(new Line(-50, 120,-30,120,QPen(Qt::darkBlue,2)));  //A43
00087   Lines.append(new Line(-50, 130,-30,130,QPen(Qt::darkBlue,2)));  //A44
00088 
00089   Lines.append(new Line( 30,  40, 50, 40,QPen(Qt::darkBlue,2)));  //Y
00090 
00091   Texts.append(new Text( -20, -60, "&", Qt::darkBlue, 12.0));
00092   Texts.append(new Text( -20, -10, "&", Qt::darkBlue, 12.0));
00093   Texts.append(new Text( -20,  40, "&", Qt::darkBlue, 12.0));
00094   Texts.append(new Text( -20,  90, "&", Qt::darkBlue, 12.0));
00095  
00096   Lines.append(new Line(  7, -45, 17, -40,QPen(Qt::darkBlue,2))); 
00097   Lines.append(new Line(  7, -35, 17, -40,QPen(Qt::darkBlue,2)));
00098   Lines.append(new Line(  7, -30, 17, -35,QPen(Qt::darkBlue,2))); 
00099   Lines.append(new Line( 22, -30, 22, -45,QPen(Qt::darkBlue,2)));  
00100 
00101   Ports.append(new Port(-50,-50));  // A11
00102   Ports.append(new Port(-50,-40));  // A12
00103   Ports.append(new Port(-50,-30));  // A13
00104   Ports.append(new Port(-50,-20));  // A14
00105 
00106   Ports.append(new Port(-50,  0));  // A21
00107   Ports.append(new Port(-50, 10));  // A22
00108   Ports.append(new Port(-50, 20));  // A23
00109   Ports.append(new Port(-50, 30));  // A24
00110 
00111   Ports.append(new Port(-50, 50));  // A31
00112   Ports.append(new Port(-50, 60));  // A32
00113   Ports.append(new Port(-50, 70));  // A33
00114   Ports.append(new Port(-50, 80));  // A34
00115 
00116   Ports.append(new Port(-50,100));  // A41
00117   Ports.append(new Port(-50,110));  // A42
00118   Ports.append(new Port(-50,120));  // A43
00119   Ports.append(new Port(-50,130));  // A44
00120 
00121   Ports.append(new Port( 50, 40));  // Y
00122 
00123   x1 = -50; y1 = -64;
00124   x2 =  50; y2 = 144;
00125 }
00126 
00127 QString andor4x4::vhdlCode( int )
00128 {
00129   QString s="";
00130 
00131   QString td = Props.at(1)->Value;     // delay time
00132   if(!misc::VHDL_Delay(td, Name)) return td; // time has not VHDL format
00133   td += ";\n";
00134 
00135   QString a11 = Ports.at(0)->Connection->Name;
00136   QString a12 = Ports.at(1)->Connection->Name;
00137   QString a13 = Ports.at(2)->Connection->Name;
00138   QString a14 = Ports.at(3)->Connection->Name;
00139   QString a21 = Ports.at(4)->Connection->Name;
00140   QString a22 = Ports.at(5)->Connection->Name;
00141   QString a23 = Ports.at(6)->Connection->Name;
00142   QString a24 = Ports.at(7)->Connection->Name;
00143   QString a31 = Ports.at(8)->Connection->Name;
00144   QString a32 = Ports.at(9)->Connection->Name;
00145   QString a33 = Ports.at(10)->Connection->Name;
00146   QString a34 = Ports.at(11)->Connection->Name;
00147   QString a41 = Ports.at(12)->Connection->Name;
00148   QString a42 = Ports.at(13)->Connection->Name;
00149   QString a43 = Ports.at(14)->Connection->Name;
00150   QString a44 = Ports.at(15)->Connection->Name;
00151 
00152   QString y   = Ports.at(16)->Connection->Name;
00153 
00154   s = "\n  " + Name + ":process (" +
00155       a11 + ", " +  a12 + ", " + a13 + ", " + a14 + ", " +
00156       a21 + ", " +  a22 + ", " + a23 + ", " + a24 + ", " +
00157       a31 + ", " +  a32 + ", " + a33 + ", " + a34 + ", " +
00158       a41 + ", " +  a42 + ", " + a43 + ", " + a44 + ")\n"  +
00159      "  begin\n    " +
00160      y + " <= " + "(" + a11 + " and " + a12 + " and " + a13 + " and " + a14 + ") or " + 
00161                   "(" + a21 + " and " + a22 + " and " + a23 + " and " + a24 + ") or\n" + 
00162          "                 (" + a31 + " and " + a32 + " and " + a33 + " and " + a34 + ") or " + 
00163                  "(" + a41 + " and " + a42 + " and " + a43 + " and " + a43 + ")" + td  +
00164      "  end process;\n";
00165   return s;
00166 }
00167 
00168 QString andor4x4::verilogCode( int )
00169 {
00170   QString td = Props.at(1)->Value;        // delay time
00171   if(!misc::Verilog_Delay(td, Name)) return td; // time does not have VHDL format
00172   
00173   QString a11 = Ports.at(0)->Connection->Name;
00174   QString a12 = Ports.at(1)->Connection->Name;
00175   QString a13 = Ports.at(2)->Connection->Name;
00176   QString a14 = Ports.at(3)->Connection->Name;
00177   QString a21 = Ports.at(4)->Connection->Name;
00178   QString a22 = Ports.at(5)->Connection->Name;
00179   QString a23 = Ports.at(6)->Connection->Name;
00180   QString a24 = Ports.at(7)->Connection->Name;
00181   QString a31 = Ports.at(8)->Connection->Name;
00182   QString a32 = Ports.at(9)->Connection->Name;
00183   QString a33 = Ports.at(10)->Connection->Name;
00184   QString a34 = Ports.at(11)->Connection->Name;
00185   QString a41 = Ports.at(12)->Connection->Name;
00186   QString a42 = Ports.at(13)->Connection->Name;
00187   QString a43 = Ports.at(14)->Connection->Name;
00188   QString a44 = Ports.at(15)->Connection->Name;
00189 
00190   QString y   = Ports.at(16)->Connection->Name;
00191 
00192   QString l = "";
00193  
00194   QString v = "net_reg" + Name + y;
00195   
00196   l = "\n  // " + Name + " 4x4 andor\n" +
00197       "  assign  " + y + " = " + v + ";\n" +
00198       "  reg     " + v + " = 0;\n" +
00199       "  always @ (" + a11 + " or " + a12 + " or " + a13 + " or " + a14 + " or "
00200                      + a21 + " or " + a22 + " or " + a23 + " or " + a24 + " or "
00201          + a31 + " or " + a32 + " or " + a33 + " or " + a34 + " or "
00202                      + a41 + " or " + a42 + " or " + a43 + " or " + a44 + ")\n  " +
00203       "  " + v + " <=" + td + " (" + a11 + " && " + a12 + " && " + a13 + " && " + a14 +")" + " || " +
00204                                "(" + a21 + " && " + a22 + " && " + a23 + " && " + a24 +")" + " ||\n" +
00205                  "                           (" + a31 + " && " + a32 + " && " + a33 + " && " + a34 +")" + " || " +
00206                                "(" + a41 + " && " + a42 + " && " + a43 + " && " + a44 +");\n" ;
00207   return l;
00208 }
00209 
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines