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