Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/pad3bit.cpp
Go to the documentation of this file.
00001 /*
00002  * pad3bit.cpp - device implementations for pad3bit module
00003  *
00004  * This is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2, or (at your option)
00007  * any later version.
00008  * 
00009  */
00010 #include <stdlib.h>
00011 #include "pad3bit.h"
00012 #include "node.h"
00013 
00014 pad3bit::pad3bit()
00015 {
00016   Type = isComponent; // Analogue and digital component.
00017   Description = QObject::tr ("3bit pattern generator verilog device");
00018 
00019   Props.append (new Property ("Number", "0", false,
00020     QObject::tr ("pad output value")));
00021  
00022   createSymbol ();
00023   tx = x1 + 4;
00024   ty = y2 + 4;
00025   Model = "pad3bit";
00026   Name  = "Y";
00027 }
00028 
00029 Component * pad3bit::newOne()
00030 {
00031   pad3bit * p = new pad3bit();
00032   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00033   p->recreate(0); 
00034   return p;
00035 }
00036 
00037 Element * pad3bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
00038 {
00039   Name = QObject::tr("3Bit Pattern");
00040   BitmapFile = (char *) "pad3bit";
00041 
00042   if(getNewOne) return new pad3bit();
00043   return 0;
00044 }
00045 
00046 void pad3bit::createSymbol()
00047 {
00048   Lines.append(new Line(-60, -50, 30,-50,QPen(Qt::darkGreen,2)));
00049   Lines.append(new Line( 30, -50, 30, 30,QPen(Qt::darkGreen,2)));
00050   Lines.append(new Line( 30,  30,-60, 30,QPen(Qt::darkGreen,2)));
00051   Lines.append(new Line(-60,  30,-60,-50,QPen(Qt::darkGreen,2)));
00052 
00053   Lines.append(new Line( 40,-30, 30,-30,QPen(Qt::darkGreen,2)));  // A
00054   Lines.append(new Line( 40,-10, 30,-10,QPen(Qt::darkGreen,2)));  // B
00055   Lines.append(new Line( 40, 10, 30, 10,QPen(Qt::darkGreen,2))); // C
00056 
00057   Texts.append(new Text(-58,-33, " 0   1   2    3", Qt::darkGreen, 12.0));
00058   Texts.append(new Text(-58, -8, " 4   5   6    7", Qt::darkGreen, 12.0));
00059 
00060   Ports.append(new Port(40, 10));  // C
00061   Ports.append(new Port(40,-10));  // B
00062   Ports.append(new Port(40,-30));  // A
00063 
00064   x1 = -64; y1 = -54;
00065   x2 =  40; y2 =  34;
00066 }
00067 
00068 QString pad3bit::vhdlCode( int )
00069 {
00070   QString v = Props.at(0)->Value;
00071   QString s1, s2, s3, s ="";
00072 
00073   QString A    = Ports.at(0)->Connection->Name;
00074   QString B    = Ports.at(1)->Connection->Name;
00075   QString C    = Ports.at(2)->Connection->Name;
00076 
00077   s1 = "\n  "+Name+":process\n"+
00078        "  variable n_" + Name + " : integer := " + v + ";\n" +
00079        "  begin\n";
00080   s2 = "    case n_" + Name + " is\n" +
00081        "      when 0 => "+A+" <= '0'; "+B+" <= '0'; "+C+" <= '0';\n"+
00082        "      when 1 => "+A+" <= '0'; "+B+" <= '0'; "+C+" <= '1';\n"+
00083        "      when 2 => "+A+" <= '0'; "+B+" <= '1'; "+C+" <= '0';\n"+
00084        "      when 3 => "+A+" <= '0'; "+B+" <= '1'; "+C+" <= '1';\n"+
00085        "      when 4 => "+A+" <= '1'; "+B+" <= '0'; "+C+" <= '0';\n"+
00086        "      when 5 => "+A+" <= '1'; "+B+" <= '0'; "+C+" <= '1';\n"+
00087        "      when 6 => "+A+" <= '1'; "+B+" <= '1'; "+C+" <= '0';\n"+
00088        "      when 7 => "+A+" <= '1'; "+B+" <= '1'; "+C+" <= '1';\n"+
00089        "      when others => null;\n" +
00090        "    end case;\n";
00091   s3 = "  end process;\n";
00092   s = s1+s2+s3;
00093   return s;
00094 }
00095 
00096 QString pad3bit::verilogCode( int )
00097 {
00098   QString v = Props.at(0)->Value;
00099 
00100   QString l = "";
00101   QString l1, l2, l3;
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 
00107   QString AR  = "A_reg"  + Name + A;
00108   QString BR  = "Y_reg"  + Name + B;
00109   QString CR  = "Y_reg"  + Name + C;
00110   
00111   l1 = "\n  // "+Name+" 3bit pattern generator\n"+
00112        "  assign  "+A+" = "+AR+";\n"+
00113        "  reg     "+AR+" = 0;\n"+
00114        "  assign  "+B+" = "+BR+";\n"+
00115        "  reg     "+BR+" = 0;\n"+
00116        "  assign  "+C+" = "+CR+";\n"+
00117        "  reg     "+CR+" = 0;\n"+
00118        "  initial\n" ;
00119   l2 = "  begin\n"
00120        "    case ("+v+")\n"+
00121        "      0 : begin "+AR+" = 0; "+BR+" = 0; "+CR+" = 0; end\n"+
00122        "      1 : begin "+AR+" = 0; "+BR+" = 0; "+CR+" = 1; end\n"+
00123        "      2 : begin "+AR+" = 0; "+BR+" = 1; "+CR+" = 0; end\n"+
00124        "      3 : begin "+AR+" = 0; "+BR+" = 1; "+CR+" = 1; end\n"+
00125        "      4 : begin "+AR+" = 1; "+BR+" = 0; "+CR+" = 0; end\n"+
00126        "      5 : begin "+AR+" = 1; "+BR+" = 0; "+CR+" = 1; end\n"+
00127        "      6 : begin "+AR+" = 1; "+BR+" = 1; "+CR+" = 0; end\n"+
00128        "      7 : begin "+AR+" = 1; "+BR+" = 1; "+CR+" = 1; end\n"+
00129        "    endcase\n";
00130   l3 = "  end\n";
00131   l = l1+l2+l3;
00132   return l;
00133 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines