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