1 /* Copyright (C) 2012 Eduard Timotei Budulea 2 Copyright (C) 2013 Roy R. Rankin 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #ifndef BIT1W_H 18 #define BIT1W_H 19 #ifndef IN_MODULE 20 #define IN_MODULE 21 #endif 22 23 #include <src/gpsim_time.h> 24 #include <src/ioports.h> 25 #include <src/stimuli.h> 26 #include <src/interface.h> 27 #include <src/trigger.h> 28 #include <iostream> 29 30 using namespace std; 31 32 class LowLevel1W : public Module, public TriggerObject { 33 protected: 34 enum NextAction {WRITE1, WRITE0, READ, RESET, IDLE}; 35 private: 36 guint64 cicluReper; 37 bool lastValue; 38 bool lastTimeout; 39 class Pin1W : public IO_bi_directional { 40 LowLevel1W &to; 41 public: Pin1W(char const * name,LowLevel1W & to)42 Pin1W(char const *name, LowLevel1W &to): IO_bi_directional(name), to(to) {} setDrivenState(bool new_dstate)43 virtual void setDrivenState(bool new_dstate) { 44 IO_bi_directional::setDrivenState(new_dstate); 45 to.change(true); 46 } setDrivenState(char new_state)47 virtual void setDrivenState(char new_state) { 48 IO_bi_directional::setDrivenState(new_state); 49 to.change(true); 50 } 51 }; 52 53 Pin1W *pin; 54 virtual void gotReset() = 0; 55 virtual NextAction gotBitStart() = 0; 56 virtual void readBit(bool value) = 0; 57 virtual int bit_remaining() = 0; 58 virtual bool is_reading() = 0; 59 void change(bool pinChange); 60 61 void (LowLevel1W::*state)(bool input, bool isTimeout); 62 bool ignoreCallback; 63 64 void idle(bool input, bool isTimeout); 65 void inResetPulse(bool input, bool isTimeout); 66 void endResetPulse(bool input, bool isTimeout); 67 void inPresencePulse(bool input, bool isTimeout); 68 void endPresencePulse(bool input, bool isTimeout); 69 void waitIdle(bool input, bool isTimeout); 70 void inWritting0(bool input, bool isTimeout); 71 void inWritting1(bool input, bool isTimeout); 72 void inReading(bool input, bool isTimeout); 73 void finalizeBit(bool input, bool isTimeout); 74 75 public: 76 guint64 bit_break; 77 LowLevel1W(const char *name, const char *desc); 78 ~LowLevel1W(); 79 virtual void callback(); 80 }; 81 82 #endif 83