1 package DEOS; 20 21 import gov.nasa.jpf.jvm.Verify; 22 23 24 27 public class Clock { 28 public static int TIME_CONSTRAINT = Registry.numPeriods * 20 * 2; public static int NOINTERRUPTS = 0; 30 public static int TIMEOUT = 1; 31 public static int SYSTEMINTERRUPT = 2; 32 public static int NOTIMECHANGE = 3; 33 int currentTime = -20; 34 PeriodicClock clockToNotify; NewTimer timerToNotify; boolean eventDriven = false; 37 38 40 43 public Clock (PeriodicClock periodicIn, NewTimer timerIn) { 44 if (DEOS.abstraction) { 45 currentTime = -20; 46 } else { 47 currentTime = -1; 48 } 49 50 clockToNotify = periodicIn; 51 timerToNotify = timerIn; 52 } 53 54 58 public int getCurrentTime () { 59 return currentTime; 60 } 61 62 66 public void setTimer (int timeIn) { 67 timerToNotify.setTimer(timeIn, currentTime); 68 } 69 70 73 public void clearInterrupts () { 74 clockToNotify.clearInterrupt(); 75 timerToNotify.clearTimeOut(); 76 } 77 78 82 public int ticks () { 83 clearInterrupts(); 84 85 int delta; 86 87 if (!DEOS.abstraction) { 88 delta = 1; 89 } else { 90 int timeToEOP = (clockToNotify.getTimeToEOP()); 91 int timeOutTime = (timerToNotify.getStoppingTime()); 92 int timeToTimeOut = (timeOutTime - currentTime); 93 94 if (Verify.randomBool()) { 96 delta = 0; 97 } else { 98 if (timeToEOP <= timeToTimeOut) { 99 delta = timeToEOP; 100 } else { 101 delta = timeToTimeOut; 102 } 103 } 104 } 105 106 if (delta == 0) { 107 return NOTIMECHANGE; 108 } else { 109 if ((currentTime + delta) > TIME_CONSTRAINT) { 110 return NOTIMECHANGE; 111 } 112 113 currentTime = (currentTime + delta); 114 clockToNotify.clockTicks(currentTime); 115 timerToNotify.clockTicks(currentTime); 116 117 if (clockToNotify.isInterrupted()) { 118 timerToNotify.interruptTimer(); 119 120 return SYSTEMINTERRUPT; 121 } else if (timerToNotify.isTimeOut()) { 122 return TIMEOUT; 123 } else { 124 return NOINTERRUPTS; 125 } 126 } 127 } 128 129 133 134 153 } | Popular Tags |