1 package DEOS; 20 21 import gov.nasa.jpf.jvm.Verify; 22 23 24 27 class Timer { 28 static final int uSecsPeriod = Registry.uSecsInFastestPeriod; 29 static int Start_time = 0; static int Remaining_time = 0; 31 static int Used_time = 0; 32 33 static boolean tick = false; 35 static boolean timer = false; 36 37 public Timer () { 38 } 39 40 public static void clearInterrupts () { 41 timer = false; 42 tick = false; 43 } 44 45 public int timeRemaining () { 46 int used_in_period = 0; int time_to_eop = uSecsPeriod - Used_time; 50 if (tick) { used_in_period = time_to_eop; 54 55 } else if (timer) { used_in_period = Start_time; 58 59 } else if (time_to_eop <= Start_time) { 61 DEOS.inc(); 62 63 if (!Verify.randomBool()) { used_in_period = time_to_eop; 65 66 } else { 68 used_in_period = 0; 69 70 } 72 } else { DEOS.inc(); 74 75 if (Verify.randomBool()) { 76 used_in_period = Start_time; 77 78 } else { 80 used_in_period = 0; 81 82 } 84 } 85 86 Used_time += used_in_period; 87 88 if (tick) { 89 Used_time = 0; } 91 92 clearInterrupts(); 93 94 Remaining_time = Start_time - used_in_period; 95 96 return Remaining_time; 103 } 104 105 public 106 void write (int delayInMicroseconds) { 107 Start_time = delayInMicroseconds; 108 109 if ((Start_time + Used_time) >= uSecsPeriod) { 111 tick = true; } else if ((Start_time + Used_time) < uSecsPeriod) { 113 timer = true; 114 } else { 115 System.out.println("Timer ERROR - this case should not happen"); 116 117 } 119 } 120 } | Popular Tags |