Qucs-GUI  0.0.19
/home/travis/build/Qucs/qucs/qucs/qucs/components/pad2bit.cpp
Go to the documentation of this file.
00001 /*
00002  * pad2bit.cpp - device implementations for pad2bit 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 "pad2bit.h"
00012 #include "node.h"
00013 
00014 pad2bit::pad2bit()
00015 {
00016   Type = isComponent; // Analogue and digital component.
00017   Description = QObject::tr ("2bit 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 = "pad2bit";
00026   Name  = "Y";
00027 }
00028 
00029 Component * pad2bit::newOne()
00030 {
00031   pad2bit * p = new pad2bit();
00032   p->Props.getFirst()->Value = Props.getFirst()->Value; 
00033   p->recreate(0); 
00034   return p;
00035 }
00036 
00037 Element * pad2bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
00038 {
00039   Name = QObject::tr("2Bit Pattern");
00040   BitmapFile = (char *) "pad2bit";
00041 
00042   if(getNewOne) return new pad2bit();
00043   return 0;
00044 }
00045 
00046 void pad2bit::createSymbol()
00047 {
00048   Lines.append(new Line(-60, -50, 30,-50,QPen(Qt::darkGreen,2)));
00049   Lines.append(new Line( 30, -50, 30, 10,QPen(Qt::darkGreen,2)));
00050   Lines.append(new Line( 30,  10,-60, 10,QPen(Qt::darkGreen,2)));
00051   Lines.append(new Line(-60,  10,-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  
00056   Texts.append(new Text(-58,-33, " 0   1   2    3", Qt::darkGreen, 12.0));
00057 
00058   Ports.append(new Port(40,-10));  // B
00059   Ports.append(new Port(40,-30));  // A
00060 
00061   x1 = -64; y1 = -54;
00062   x2 =  40; y2 =  14;
00063 }
00064 
00065 QString pad2bit::vhdlCode( int )
00066 {
00067   QString v = Props.at(0)->Value; ;
00068   QString s1, s2, s3, s ="";
00069 
00070   QString A    = Ports.at(0)->Connection->Name;
00071   QString B    = Ports.at(1)->Connection->Name;
00072 
00073   s1 = "\n  "+Name+":process\n"+
00074        "  variable n_" + Name + " : integer := " + v + ";\n" +
00075        "  begin\n";
00076   s2 = "    case n_" + Name + " is\n" +
00077        "      when 0 => "+A+" <= '0'; "+B+" <= '0';\n" +
00078        "      when 1 => "+A+" <= '0'; "+B+" <= '1';\n" +
00079        "      when 2 => "+A+" <= '1'; "+B+" <= '0';\n" +
00080        "      when 3 => "+A+" <= '1'; "+B+" <= '1';\n" +
00081        "      when others => null;\n" +
00082        "    end case;\n";
00083   s3 = "  end process;\n";
00084   s = s1+s2+s3;
00085   return s;
00086 }
00087 
00088 QString pad2bit::verilogCode( int )
00089 {
00090   QString v = Props.at(0)->Value;
00091 
00092   QString l = "";
00093   QString l1, l2, l3;
00094 
00095   QString A   = Ports.at(0)->Connection->Name;
00096   QString B   = Ports.at(1)->Connection->Name;
00097 
00098   QString AR  = "A_reg"  + Name + A;
00099   QString BR  = "Y_reg"  + Name + B;
00100   
00101 
00102   l1 = "\n  // "+Name+" 2bit pattern generator\n"+
00103        "  assign  "+A+" = "+AR+";\n"+
00104        "  reg     "+AR+" = 0;\n"+
00105        "  assign  "+B+" = "+BR+";\n"+
00106        "  reg     "+BR+" = 0;\n"+
00107        "  initial\n";
00108   l2 = "  begin\n"
00109        "    case ("+v+")\n"+
00110        "      0 : begin "+AR+" = 0; "+BR+" = 0; end\n"+
00111        "      1 : begin "+AR+" = 0; "+BR+" = 1; end\n"+
00112        "      2 : begin "+AR+" = 1; "+BR+" = 0; end\n"+
00113        "      3 : begin "+AR+" = 1; "+BR+" = 1; end\n"+
00114        "    endcase\n";
00115   l3 = "  end\n";
00116   l = l1+l2+l3;
00117   return l;
00118 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines