My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
d_flipflop.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  d_flipflop.cpp
3  ----------------
4  begin : Fri Jan 06 2006
5  copyright : (C) 2006 by Michael Margraf
6  email : michael.margraf@alumni.tu-berlin.de
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "d_flipflop.h"
19 #include "node.h"
20 #include "main.h"
21 
23 {
25  Description = QObject::tr("D flip flop with asynchron reset");
26 
27  Props.append(new Property("t", "0", false, QObject::tr("delay time")));
28 
29  Lines.append(new Line(-20,-20, 20,-20,QPen(QPen::darkBlue,2)));
30  Lines.append(new Line(-20, 20, 20, 20,QPen(QPen::darkBlue,2)));
31  Lines.append(new Line(-20,-20,-20, 20,QPen(QPen::darkBlue,2)));
32  Lines.append(new Line( 20,-20, 20, 20,QPen(QPen::darkBlue,2)));
33 
34  Lines.append(new Line(-30,-10,-20,-10,QPen(QPen::darkBlue,2)));
35  Lines.append(new Line(-30, 10,-20, 10,QPen(QPen::darkBlue,2)));
36  Lines.append(new Line( 30,-10, 20,-10,QPen(QPen::darkBlue,2)));
37  Lines.append(new Line( 0, 20, 0, 30,QPen(QPen::darkBlue,2)));
38 
39  Texts.append(new Text(-18,-21, "D", QPen::darkBlue, 12.0));
40  Texts.append(new Text( 6,-21, "Q", QPen::darkBlue, 12.0));
41  Texts.append(new Text( -4, 4, "R", QPen::darkBlue, 9.0));
42  Lines.append(new Line(-20, 6,-12, 10,QPen(QPen::darkBlue,0)));
43  Lines.append(new Line(-20, 14,-12, 10,QPen(QPen::darkBlue,0)));
44 
45  Ports.append(new Port(-30,-10)); // D
46  Ports.append(new Port(-30, 10)); // Clock
47  Ports.append(new Port( 30,-10)); // Q
48  Ports.append(new Port( 0, 30)); // Reset
49 
50  x1 = -30; y1 = -24;
51  x2 = 30; y2 = 30;
52  tx = x1+4;
53  ty = y2+4;
54  Model = "DFF";
55  Name = "Y";
56 }
57 
58 // -------------------------------------------------------
59 QString D_FlipFlop::vhdlCode(int NumPorts)
60 {
61  QString s = "";
62  if(NumPorts <= 0) { // no truth table simulation ?
63  QString td = Props.at(0)->Value; // delay time
64  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
65  s += td;
66  }
67  s += ";\n";
68 
69  s = " " + Name + " : process (" +
70  Ports.at(0)->Connection->Name + ", " +
71  Ports.at(1)->Connection->Name + ")\n begin\n if (" +
72  Ports.at(3)->Connection->Name + "='1') then " +
73  Ports.at(2)->Connection->Name + " <= '0'" + s +" elsif (" +
74  Ports.at(1)->Connection->Name + "='1' and " +
75  Ports.at(1)->Connection->Name + "'event) then\n " +
76  Ports.at(2)->Connection->Name + " <= " +
77  Ports.at(0)->Connection->Name + s + " end if;\n end process;\n\n";
78  return s;
79 }
80 
81 // -------------------------------------------------------
82 QString D_FlipFlop::verilogCode(int NumPorts)
83 {
84  QString t = "";
85  if(NumPorts <= 0) { // no truth table simulation ?
86  QString td = Props.at(0)->Value; // delay time
87  if(!Verilog_Delay(td, Name)) return td; // time has not VHDL format
88  if(!td.isEmpty()) t = " " + td + ";\n";
89  }
90 
91  QString s = "";
92  QString q = Ports.at(2)->Connection->Name;
93  QString d = Ports.at(0)->Connection->Name;
94  QString r = Ports.at(3)->Connection->Name;
95  QString c = Ports.at(1)->Connection->Name;
96  QString v = "net_reg" + Name + q;
97 
98  s = "\n // " + Name + " D-flipflop\n" +
99  " assign " + q + " = " + v + ";\n" +
100  " reg " + v + " = 0;\n" +
101  " always @ (" + c + " or " + r + ") begin\n" + t +
102  " if (" + r + ") " + v + " <= 0;\n" +
103  " else if (~" + r + " && " + c + ") " + v + " <= " + d + ";\n" +
104  " end\n\n";
105  return s;
106 }
107 
108 // -------------------------------------------------------
110 {
111  return new D_FlipFlop();
112 }
113 
114 // -------------------------------------------------------
115 Element* D_FlipFlop::info(QString& Name, char* &BitmapFile, bool getNewOne)
116 {
117  Name = QObject::tr("D-FlipFlop");
118  BitmapFile = (char *) "dflipflop";
119 
120  if(getNewOne) return new D_FlipFlop();
121  return 0;
122 }