1
/***************************************************************************
2
* Copyright (C) 2016 by santiago González *
3
* santigoro@gmail.com *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; if not, see <http://www.gnu.org/licenses/>. *
18
***************************************************************************/
22
#include "e-flipflopjk.h"
23
#include "simulator.h"
26
eFlipFlopJK::eFlipFlopJK( QString id )
30
eFlipFlopJK::~eFlipFlopJK() {}
32
void eFlipFlopJK::stamp()
34
eNode* enode = m_input[2]->getEpin()->getEnode(); // Set pin
35
if( enode ) enode->voltChangedCallback( this );
37
enode = m_input[3]->getEpin()->getEnode(); // Reset pin
38
if( enode ) enode->voltChangedCallback( this );
40
if( m_etrigger != Trig_Clk )
42
for( uint i=0; i<2; i++ )
44
eNode* enode = m_input[i]->getEpin()->getEnode();
45
if( enode ) enode->voltChangedCallback( this );
49
eLogicDevice::stamp();
52
void eFlipFlopJK::voltChanged()
54
// Get Clk to don't miss any clock changes
55
bool clkAllow = (eLogicDevice::getClockState() == Clock_Allow);
57
//qDebug() << "eFlipFlopJK::voltChanged()"<<clkRising;
59
if( eLogicDevice::getInputState( 2 )==true ) // Master Set
63
//qDebug() << "eFlipFlopJK::voltChanged() set";
65
else if( eLogicDevice::getInputState( 3 )==true ) // Master Reset
69
//qDebug() << "eFlipFlopJK::voltChanged() Reset";
71
else if( clkAllow ) // Allow operation
73
bool J = eLogicDevice::getInputState( 0 );
74
bool K = eLogicDevice::getInputState( 1 );
75
bool Q = m_output[0]->out();
77
bool state = (J && !Q) || (!K && Q) ;
78
//qDebug() << "eFlipFlopJK::voltChanged() clk"<<J<<K<<state;
83
Simulator::self()->addEvent( m_propDelay, this );
86
void eFlipFlopJK::runEvent()
88
setOut( 0, m_Q0 ); // Q
89
setOut( 1, m_Q1 ); // Q'
92
void eFlipFlopJK::setSrInv( bool inv )
95
m_input[2]->setInverted( inv ); // Set
96
m_input[3]->setInverted( inv ); // Reset
98
Circuit::self()->update();