1
0
Fork 0

Respect different behaviour of RS and SR flip flops

No more invalid states here.
According to IEC 61131, RS flip flop have dominant reset and SR have
dominant set. This is now implemented.
This commit is contained in:
Torsten Dreyer 2010-05-27 22:22:01 +02:00
parent 321bbeb2e8
commit 54c964aed5

View file

@ -918,9 +918,15 @@ void FGXMLAutoLogic::update(double dt)
} }
class FGXMLAutoRSFlipFlop : public FGXMLAutoFlipFlop { class FGXMLAutoRSFlipFlop : public FGXMLAutoFlipFlop {
private:
bool _rs;
public: public:
FGXMLAutoRSFlipFlop( SGPropertyNode * node ) : FGXMLAutoRSFlipFlop( SGPropertyNode * node ) :
FGXMLAutoFlipFlop( node ) {} FGXMLAutoFlipFlop( node ) {
// type exists here, otherwise we were not constructed
string val = node->getNode( "type" )->getStringValue();
_rs = (val == "RS");
}
void updateState( double dt ) { void updateState( double dt ) {
@ -940,9 +946,13 @@ public:
// s == false && q == false: no change, keep state // s == false && q == false: no change, keep state
if( s || r ) { if( s || r ) {
bool q = false; bool q = false;
if( s ) q = true; // set if( _rs ) { // RS: reset is dominant
if( r ) q = false; // reset if( s ) q = true; // set
// s && q: race condition. we let r win if( r ) q = false; // reset
} else { // SR: set is dominant
if( r ) q = false; // reset
if( s ) q = true; // set
}
if( inverted ) q = !q; if( inverted ) q = !q;
if ( debug ) cout << "Updating " << get_name() << ":" if ( debug ) cout << "Updating " << get_name() << ":"
@ -1374,7 +1384,7 @@ bool FGXMLAutopilot::build( SGPropertyNode_ptr config_props ) {
string val; string val;
if( typeNode != NULL ) val = typeNode->getStringValue(); if( typeNode != NULL ) val = typeNode->getStringValue();
val = simgear::strutils::strip(val); val = simgear::strutils::strip(val);
if( val == "RS" || val =="SR" ) flipFlop = new FGXMLAutoRSFlipFlop( node ); if( val == "RS" || val =="SR" ) flipFlop = new FGXMLAutoRSFlipFlop( node );
else if( val == "JK" ) flipFlop = new FGXMLAutoJKFlipFlop( node ); else if( val == "JK" ) flipFlop = new FGXMLAutoJKFlipFlop( node );
else if( val == "T" ) flipFlop = new FGXMLAutoTFlipFlop( node ); else if( val == "T" ) flipFlop = new FGXMLAutoTFlipFlop( node );
else if( val == "D" ) flipFlop = new FGXMLAutoDFlipFlop( node ); else if( val == "D" ) flipFlop = new FGXMLAutoDFlipFlop( node );