My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mux2to1.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  mux2to1
3  ---------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * mux2to1.cpp - device implementations for mux2to1 module
11  *
12  * This is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2, or (at your option)
15  * any later version.
16  *
17  */
18 
19 #include "mux2to1.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("2to1 multiplexer verilog device");
27 
28  Props.append (new Property ("TR", "6", false,
29  QObject::tr ("transfer function high scaling factor")));
30  Props.append (new Property ("Delay", "1 ns", false,
31  QObject::tr ("output delay")
32  +" ("+QObject::tr ("s")+")"));
33 
34  createSymbol ();
35  tx = x1 + 19;
36  ty = y2 + 4;
37  Model = "mux2to1";
38  Name = "Y";
39 }
40 
42 {
43  mux2to1 * p = new mux2to1();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * mux2to1::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("2to1 Mux");
52  BitmapFile = (char *) "mux2to1";
53 
54  if(getNewOne) return new mux2to1();
55  return 0;
56 }
57 
59 {
60  // put in here symbol drawing code and terminal definitions
61  Lines.append(new Line(-30, -60, 30,-60,QPen(QPen::darkBlue,2)));
62  Lines.append(new Line( 30, -60, 30, 50,QPen(QPen::darkBlue,2)));
63  Lines.append(new Line( 30, 50,-30, 50,QPen(QPen::darkBlue,2)));
64  Lines.append(new Line(-30, 50,-30,-60,QPen(QPen::darkBlue,2)));
65 
66  Lines.append(new Line(-50,-20,-40,-20,QPen(QPen::darkBlue,2)));
67  Lines.append(new Line(-50, 0,-30, 0,QPen(QPen::darkBlue,2)));
68  Lines.append(new Line(-50, 20,-30, 20,QPen(QPen::darkBlue,2)));
69  Lines.append(new Line(-50, 40,-30, 40,QPen(QPen::darkBlue,2)));
70 
71  Lines.append(new Line( 30, 0, 50, 0,QPen(QPen::darkBlue,2)));
72 
73  Arcs.append(new Arc(-40, -25, 10, 10, 0, 16*360, QPen(QPen::darkBlue,2)));
74 
75  Texts.append(new Text(-17,-55, "MUX", QPen::darkBlue, 12.0));
76 
77  Texts.append(new Text(-25,-33, "En", QPen::darkBlue, 12.0));
78  Texts.append(new Text(-25,-13, "0", QPen::darkBlue, 12.0));
79 
80  Texts.append(new Text(-15,-15, "G", QPen::darkBlue, 12.0));
81  Texts.append(new Text( -1,-21, "}", QPen::darkBlue, 16.0));
82  Texts.append(new Text( 12,-22, "0", QPen::darkBlue, 12.0));
83  Texts.append(new Text( 12, -2, "1", QPen::darkBlue, 12.0));
84 
85  Lines.append(new Line(11, 0, 23, 0, QPen(QPen::darkBlue,2)));
86 
87  Texts.append(new Text(-25, 7, "0", QPen::darkBlue, 12.0));
88  Texts.append(new Text(-25, 27, "1", QPen::darkBlue, 12.0));
89 
90  Ports.append(new Port(-50,-20)); // En
91  Ports.append(new Port(-50, 0)); // A
92  Ports.append(new Port(-50, 20)); // D0
93  Ports.append(new Port(-50, 40)); // D1
94  Ports.append(new Port( 50, 0 )); // Y
95 
96  x1 = -50; y1 = -64;
97  x2 = 50; y2 = 54;
98 }
99 
100 QString mux2to1::vhdlCode( int )
101 {
102  QString s="";
103 
104  QString td = Props.at(1)->Value;
105  if(!VHDL_Delay(td, Name))
106  return td; // Time does not have VHDL format.
107  td += ";\n";
108 
109  QString En = Ports.at(0)->Connection->Name;
110  QString A = Ports.at(1)->Connection->Name;
111  QString D0 = Ports.at(2)->Connection->Name;
112  QString D1 = Ports.at(3)->Connection->Name;
113  QString y = Ports.at(4)->Connection->Name;
114 
115  s = "\n " + Name + ":process (" + En + ", " + A + ", " + D0 + ", " + D1 + ")\n" +
116  " begin\n" +
117  " " + y + " <= " + "(not " + En + ") and ((" + D1 + " and " + A + ") or " +
118  "(" + D0 + " and " + "(not " + A + ")))" + td +
119  " end process;\n";
120  return s;
121 }
122 
123 QString mux2to1::verilogCode( int )
124 {
125  QString td = Props.at(1)->Value;
126  if(!Verilog_Delay(td, Name))
127  return td; // Time does not have VHDL format.
128  td += " ";
129 
130  QString l = "";
131 
132  QString En = Ports.at(0)->Connection->Name;
133  QString A = Ports.at(1)->Connection->Name;
134  QString D0 = Ports.at(2)->Connection->Name;
135  QString D1 = Ports.at(3)->Connection->Name;
136  QString y = Ports.at(4)->Connection->Name;
137 
138  QString v = "net_reg" + Name + y;
139 
140  l = "\n // " + Name + " 2to1 mux\n" +
141  " assign " + y + " = " + v + ";\n" +
142  " reg " + v + " = 0;\n" +
143  " always @ (" + En + " or " + A + " or "
144  + D0 + " or " + D1 + ")\n" +
145  " " + v + " <=" + td + "(" + D1 + " && " + A + ")" + " || " +
146  "(" + D0 + " && (~" + A + "));\n" ;
147 
148  return l;
149 }
150