libraries / Mitov / Mitov_LogicFlipFlops.hon commit Added link to project report (97a3ba0)
   1////////////////////////////////////////////////////////////////////////////////
   2//                                                                            //
   3//     This software is supplied under the terms of a license agreement or    //
   4//     nondisclosure agreement with Mitov Software and may not be copied      //
   5//     or disclosed except in accordance with the terms of that agreement.    //
   6//         Copyright(c) 2002-2016 Mitov Software. All Rights Reserved.        //
   7//                                                                            //
   8////////////////////////////////////////////////////////////////////////////////
   9
  10#ifndef _MITOV_LOGIC_FLIP_FLOPS_h
  11#define _MITOV_LOGIC_FLIP_FLOPS_h
  12
  13#include <Mitov.h>
  14
  15namespace Mitov
  16{
  17        class BasicFlipFlop : public Mitov::CommonSource
  18        {
  19                typedef Mitov::CommonSource inherited;
  20
  21        protected:
  22                bool    FValue = false;
  23
  24        public:
  25                OpenWire::SourcePin     InvertedOutputPin;
  26
  27        protected:
  28                void SetValue( bool AValue )
  29                {
  30                        FValue = AValue;
  31                        SendOutput();
  32                }
  33
  34                void SendOutput()
  35                {
  36                        OutputPin.SendValue( FValue );
  37                        InvertedOutputPin.SendValue( !FValue );
  38                }
  39
  40        protected:
  41                virtual void SystemStart() override
  42                {
  43                        inherited::SystemStart();
  44                        SendOutput();
  45                }
  46
  47        };
  48//---------------------------------------------------------------------------
  49        class SRFlipFlop : public BasicFlipFlop
  50        {
  51                typedef Mitov::BasicFlipFlop inherited;
  52
  53        public:
  54                OpenWire::SinkPin       SetInputPin;
  55                OpenWire::SinkPin       ResetInputPin;
  56
  57        protected:
  58                void DoReceiveSet( void *_Data )
  59                {
  60                        bool AValue = *(bool *)_Data;
  61                        if( AValue )
  62                                SetValue( true );
  63                }
  64
  65                void DoReceiveReset( void *_Data )
  66                {
  67                        bool AValue = *(bool *)_Data;
  68                        if( AValue )
  69                                SetValue( false );
  70                }
  71
  72        public:
  73                SRFlipFlop()
  74                {
  75                        SetInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&SRFlipFlop::DoReceiveSet );
  76                        ResetInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&SRFlipFlop::DoReceiveReset );
  77                }
  78        };
  79//---------------------------------------------------------------------------
  80        class ClockableFlipFlop : public Mitov::SRFlipFlop
  81        {
  82                typedef Mitov::SRFlipFlop inherited;
  83
  84        public:
  85                OpenWire::SinkPin       ClockInputPin;
  86
  87        protected:
  88                virtual void DoClock() = 0;
  89
  90        protected:
  91                void DoClockReceive( void *_Data )
  92                {
  93                        DoClock();
  94                }
  95
  96        public:
  97                ClockableFlipFlop()
  98                {
  99                        ClockInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&ClockableFlipFlop::DoClockReceive );
 100                }
 101
 102        };
 103//---------------------------------------------------------------------------
 104        class TFlipFlop : public Mitov::ClockableFlipFlop
 105        {
 106                typedef Mitov::ClockableFlipFlop inherited;
 107
 108        public:
 109                OpenWire::SinkPin       ToggleInputPin;
 110
 111        protected:
 112                bool FToggleValue = true;
 113
 114        protected:
 115                void DoReceiveToggle( void *_Data )
 116                {
 117                        FToggleValue = *(bool *)_Data;
 118                }
 119
 120        protected:
 121                virtual void DoClock() override
 122                {
 123                        if( FToggleValue )
 124                                SetValue( !FValue );
 125                }
 126
 127        public:
 128                TFlipFlop()
 129                {
 130                        ToggleInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&TFlipFlop::DoReceiveToggle );
 131                }
 132
 133        };
 134//---------------------------------------------------------------------------
 135        class DFlipFlop : public Mitov::ClockableFlipFlop
 136        {
 137                typedef Mitov::ClockableFlipFlop inherited;
 138
 139        public:
 140                OpenWire::SinkPin       DataInputPin;
 141
 142        protected:
 143                bool FData = false;
 144
 145        protected:
 146                virtual void DoClock() override
 147                {
 148                        SetValue( FData );
 149                }
 150
 151        protected:
 152                void DoReceiveData( void *_Data )
 153                {
 154                        FData = *(bool *)_Data;
 155                }
 156
 157        public:
 158                DFlipFlop()
 159                {
 160                        DataInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&DFlipFlop::DoReceiveData );
 161                }
 162
 163        };
 164//---------------------------------------------------------------------------
 165        class JKFlipFlop : public Mitov::BasicFlipFlop
 166        {
 167        public:
 168                OpenWire::SinkPin       JInputPin;
 169                OpenWire::SinkPin       KInputPin;
 170                OpenWire::SinkPin       ClockInputPin;
 171
 172        protected:
 173                bool FJ : 1;
 174                bool FK : 1;
 175
 176        protected:
 177                void DoReceiveJ( void *_Data )
 178                {
 179                        FJ = *(bool *)_Data;
 180                }
 181
 182                void DoReceiveK( void *_Data )
 183                {
 184                        FK = *(bool *)_Data;
 185                }
 186
 187                void DoClockReceive( void *_Data )
 188                {
 189                        if( FJ && FK )
 190                                SetValue( !FValue );
 191
 192                        else if( FJ )
 193                                SetValue( true );
 194
 195                        else if( FK )
 196                                SetValue( false );
 197
 198                }
 199
 200        public:
 201                JKFlipFlop() :
 202                        FJ( false ),
 203                        FK( false )
 204                {
 205                        JInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&JKFlipFlop::DoReceiveJ );
 206                        KInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&JKFlipFlop::DoReceiveK );
 207                        ClockInputPin.SetCallback( this, (OpenWire::TOnPinReceive)&JKFlipFlop::DoClockReceive );
 208                }
 209
 210        };
 211//---------------------------------------------------------------------------
 212}
 213
 214#endif