My Project  0.0.16
QUCS Mapping
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ha1b.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  ha1b
3  ------
4  begin : December 2008
5  copyright : (C) 2008 by Mike Brinson
6  email : mbrin72043@yahoo.co.uk
7  ***************************************************************************/
8 
9 /*
10  * ha1b.cpp - device implementations for ha1b 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 "ha1b.h"
20 #include "node.h"
21 #include "main.h"
22 
23 ha1b::ha1b()
24 {
25  Type = isComponent; // Analogue and digital component.
26  Description = QObject::tr ("1bit half adder 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 = "ha1b";
38  Name = "Y";
39 }
40 
42 {
43  ha1b * p = new ha1b();
44  p->Props.getFirst()->Value = Props.getFirst()->Value;
45  p->recreate(0);
46  return p;
47 }
48 
49 Element * ha1b::info(QString& Name, char * &BitmapFile, bool getNewOne)
50 {
51  Name = QObject::tr("1Bit HalfAdder");
52  BitmapFile = (char *) "ha1b";
53 
54  if(getNewOne) return new ha1b();
55  return 0;
56 }
57 
59 {
60  Lines.append(new Line(-30, -40, 30,-40,QPen(QPen::darkBlue,2)));
61  Lines.append(new Line( 30, -40, 30, 30,QPen(QPen::darkBlue,2)));
62  Lines.append(new Line( 30, 30,-30, 30,QPen(QPen::darkBlue,2)));
63  Lines.append(new Line(-30, 30,-30,-40,QPen(QPen::darkBlue,2)));
64 
65  Lines.append(new Line(-50,-10,-30,-10,QPen(QPen::darkBlue,2))); // A
66  Lines.append(new Line(-50, 10,-30, 10,QPen(QPen::darkBlue,2))); // B
67  Lines.append(new Line( 30, 10, 50, 10,QPen(QPen::darkBlue,2))); // CO
68  Lines.append(new Line( 30,-10, 50,-10,QPen(QPen::darkBlue,2))); // S
69 
70  Texts.append(new Text(0, -3, "CO", QPen::darkBlue, 12.0));
71 
72  Lines.append(new Line(-10,-35, 10, -35, QPen(QPen::darkBlue,2)));
73  Lines.append(new Line(-10,-35, 5, -25, QPen(QPen::darkBlue,2)));
74  Lines.append(new Line( 5,-25,-10, -15, QPen(QPen::darkBlue,2)));
75  Lines.append(new Line(-10,-15, 10, -15, QPen(QPen::darkBlue,2)));
76 
77  Ports.append(new Port(-50,-10)); // A
78  Ports.append(new Port(-50, 10)); // B
79  Ports.append(new Port( 50, 10)); // CO
80  Ports.append(new Port( 50,-10)); // S
81 
82  x1 = -50; y1 = -44;
83  x2 = 50; y2 = 34;
84 }
85 
86 QString ha1b::vhdlCode( int )
87 {
88  QString s="";
89 
90  QString td = Props.at(1)->Value; // delay time
91  if(!VHDL_Delay(td, Name)) return td; // time has not VHDL format
92  td += ";\n";
93 
94  QString A = Ports.at(0)->Connection->Name;
95  QString B = Ports.at(1)->Connection->Name;
96  QString CO = Ports.at(2)->Connection->Name;
97  QString S = Ports.at(3)->Connection->Name;
98 
99  s = "\n " + Name + ":process (" + A + ", " + B + ")\n" +
100  " begin\n" +
101  " " + CO + " <= " + A + " and " + B + td +
102  " " + S + " <= " + A + " xor " + B + td +
103  " end process;\n";
104  return s;
105 }
106 
107 QString ha1b::verilogCode( int )
108 {
109  QString td = Props.at(1)->Value; // delay time
110  if(!Verilog_Delay(td, Name)) return td; // time does not have VHDL format
111 
112  QString l = "";
113 
114  QString A = Ports.at(0)->Connection->Name;
115  QString B = Ports.at(1)->Connection->Name;
116  QString CO = Ports.at(2)->Connection->Name;
117  QString S = Ports.at(3)->Connection->Name;
118 
119  QString COR = "CO_reg" + Name + CO;
120  QString SR = "S_reg" + Name + S;
121 
122  l = "\n // " + Name + " 1bit halfadder\n" +
123  " assign " + CO + " = " + COR + ";\n" +
124  " reg " + COR + " = 0;\n" +
125  " assign " + S + " = " + SR + ";\n" +
126  " reg " + SR + " = 0;\n" +
127  " always @ ("+ A + " or " + B + ")\n" +
128  " begin\n" +
129  " " + COR + " <=" + td + " (" + A + " && " + B + ");\n" +
130  " " + SR + " <=" + td + " (" + A + " ^ " + B + ");\n" +
131  " end\n";
132 
133  return l;
134 }
135