Qucs-GUI  0.0.18
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
hpribin4bit.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  hpribin4bit
3  -------------
4  begin : January 2009
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * hpribin4bit.cpp - device implementations for hpribin4bit 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 #include <QtGui>
19 #include "hpribin4bit.h"
20 #include "node.h"
21 #include "main.h"
22 
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("4bit highest priority encoder (binary form) verilog device");
27 
28  Props.append (new Property ("TR", "6", false,
29  QObject::tr ("transfer function 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 = "hpribin4bit";
38  Name = "Y";
39 }
40 
42 {
43  hpribin4bit * p = new hpribin4bit();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * hpribin4bit::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("4Bit HPRI-Bin");
52  BitmapFile = (char *) "hpribin4bit";
53 
54  if(getNewOne) return new hpribin4bit();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-40, -50, 40,-50,QPen(Qt::darkBlue,2)));
61  Lines.append(new Line( 40, -50, 40, 60,QPen(Qt::darkBlue,2)));
62  Lines.append(new Line( 40, 60,-40, 60,QPen(Qt::darkBlue,2)));
63  Lines.append(new Line(-40, 60,-40, -50,QPen(Qt::darkBlue,2)));
64 
65  Lines.append(new Line(-60,-10,-40,-10,QPen(Qt::darkBlue,2))); // A
66  Lines.append(new Line(-60, 10,-40, 10,QPen(Qt::darkBlue,2))); // B
67  Lines.append(new Line(-60, 30,-40, 30,QPen(Qt::darkBlue,2))); // C
68  Lines.append(new Line(-60, 50,-40, 50,QPen(Qt::darkBlue,2))); // D
69  Lines.append(new Line( 40, 30, 60, 30,QPen(Qt::darkBlue,2))); // V
70  Lines.append(new Line( 40, 10, 60, 10,QPen(Qt::darkBlue,2))); // Y
71  Lines.append(new Line( 40,-10, 60,-10,QPen(Qt::darkBlue,2))); // X
72 
73  Texts.append(new Text(-35,-45, "HPRI/BIN", Qt::darkBlue, 12.0));
74 
75  Texts.append(new Text(-35,-23, "0", Qt::darkBlue, 12.0));
76  Texts.append(new Text(-35, -3, "1", Qt::darkBlue, 12.0));
77  Texts.append(new Text(-35, 17, "2", Qt::darkBlue, 12.0));
78  Texts.append(new Text(-35, 37, "3", Qt::darkBlue, 12.0));
79 
80  Texts.append(new Text( 25, 17, "V", Qt::darkBlue, 12.0));
81  Texts.append(new Text( 25, -3, "Y", Qt::darkBlue, 12.0));
82  Texts.append(new Text( 25,-23, "X", Qt::darkBlue, 12.0));
83 
84  Ports.append(new Port(-60,-10)); // A
85  Ports.append(new Port(-60, 10)); // B
86  Ports.append(new Port(-60, 30)); // C
87  Ports.append(new Port(-60, 50)); // D
88  Ports.append(new Port( 60, 30)); // V
89  Ports.append(new Port( 60, 10)); // Y
90  Ports.append(new Port( 60,-10)); // X
91 
92  x1 = -60; y1 = -54;
93  x2 = 60; y2 = 64;
94 }
95 
96 QString hpribin4bit::vhdlCode( int )
97 {
98  QString s;
99 
100  QString td = Props.at(1)->Value; // delay time
101  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
102  td += ";\n";
103 
104  QString A = Ports.at(0)->Connection->Name;
105  QString B = Ports.at(1)->Connection->Name;
106  QString C = Ports.at(2)->Connection->Name;
107  QString D = Ports.at(3)->Connection->Name;
108  QString V = Ports.at(4)->Connection->Name;
109  QString Y = Ports.at(5)->Connection->Name;
110  QString X = Ports.at(6)->Connection->Name;
111 
112  s = "\n "+Name+":process ("+A+", "+B+", "+C+", "+D+")\n"+
113  " begin\n" +
114  " "+X+" <= "+D+" or "+C+td+
115  " "+Y+" <= "+D+" or ((not "+C+") and "+B+")"+td+
116  " "+V+" <= "+D+" or "+C+" or "+B+" or "+A+td+
117  " end process;\n";
118  return s;
119 }
120 
122 {
123  QString td = Props.at(1)->Value; // delay time
124  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
125 
126  QString l = "";
127 
128  QString A = Ports.at(0)->Connection->Name;
129  QString B = Ports.at(1)->Connection->Name;
130  QString C = Ports.at(2)->Connection->Name;
131  QString D = Ports.at(3)->Connection->Name;
132  QString V = Ports.at(4)->Connection->Name;
133  QString Y = Ports.at(5)->Connection->Name;
134  QString X = Ports.at(6)->Connection->Name;
135 
136  QString VR = "V_reg" + Name + V;
137  QString YR = "Y_reg" + Name + Y;
138  QString XR = "X_reg" + Name + X;
139 
140  l = "\n // "+Name+" 4bit hpribin\n"+
141  " assign "+V+" = "+VR+";\n"+
142  " reg "+VR+" = 0;\n"+
143  " assign "+Y+" = "+YR+";\n"+
144  " reg "+YR+" = 0;\n"+
145  " assign "+X+" = "+XR+";\n"+
146  " reg "+XR+" = 0;\n"+
147  " always @ ("+A+" or "+B+" or "+C+" or "+D+")\n"+
148  " begin\n" +
149  " " +XR+" <="+td+" "+D+" || "+C+";\n"+
150  " " +YR+" <="+td+" "+D+" || ((~"+C+") && "+B+");\n" +
151  " " +VR+" <="+td+" "+D+" || "+C+" || "+B+" || "+A+";\n"+
152  " end\n";
153 
154  return l;
155 }
Q3PtrList< Line > Lines
Definition: component.h:67
int Type
Definition: element.h:152
int y1
Definition: element.h:153
bool VHDL_Delay(QString &td, const QString &Name)
Definition: main.cpp:493
int tx
Definition: component.h:78
int y2
Definition: element.h:153
Definition: element.h:72
int x1
Definition: element.h:153
bool Verilog_Delay(QString &td, const QString &Name)
Definition: main.cpp:555
Definitions and declarations for the main application.
int ty
Definition: component.h:78
Q3PtrList< Property > Props
Definition: component.h:72
static Element * info(QString &, char *&, bool getNewOne=false)
Definition: hpribin4bit.cpp:49
Definition: element.h:82
void createSymbol()
Definition: hpribin4bit.cpp:58
Definition: element.h:48
Superclass of all schematic drawing elements.
Definition: element.h:142
QString verilogCode(int)
Q3PtrList< Port > Ports
Definition: component.h:70
QString Name
Definition: component.h:80
Q3PtrList< Text > Texts
Definition: component.h:71
QString Model
Definition: component.h:80
QString Description
Definition: component.h:81
#define isComponent
Definition: element.h:110
int x2
Definition: element.h:153
virtual void recreate(Schematic *)
Definition: component.h:39
QString vhdlCode(int)
Definition: hpribin4bit.cpp:96
Component * newOne()
Definition: hpribin4bit.cpp:41