001: //
002: // Copyright (C) 2005 United States Government as represented by the
003: // Administrator of the National Aeronautics and Space Administration
004: // (NASA). All Rights Reserved.
005: //
006: // This software is distributed under the NASA Open Source Agreement
007: // (NOSA), version 1.3. The NOSA has been approved by the Open Source
008: // Initiative. See the file NOSA-1.3-JPF at the top of the distribution
009: // directory tree for the complete NOSA document.
010: //
011: // THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
012: // KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
013: // LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
014: // SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
015: // A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
016: // THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
017: // DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
018: //
019: package DEOS;
020:
021: import gov.nasa.jpf.jvm.Verify;
022:
023: /**
024: * DOCUMENT ME!
025: */
026: public class PeriodicClock {
027: int microSecsPeriod = 0;
028: int usedTime = 0;
029: int startingPeriodTime = 0;
030: boolean systemInterrupt = false;
031: int special_case_usedTime = 0; // used to get correct value when systemtick can happen, but doesn't
032:
033: /**
034: * Main constructor
035: * @param periodIn, the period of the clock - clock resets to zero
036: * after period time elapsed
037: */
038: public PeriodicClock(int periodIn) {
039: microSecsPeriod = periodIn;
040: }
041:
042: /**
043: * To get the tick value
044: * @param currentTime the current time on the clock
045: * @return true if tick
046: */
047: public boolean isInterrupted() {
048: //assert (usedTime < microSecsPeriod);
049: return systemInterrupt;
050: }
051:
052: /**
053: * To get the period
054: * @return microSecsPeriod
055: */
056: public int getPeriod() {
057: return microSecsPeriod;
058: }
059:
060: /**
061: * To get remaining time in period
062: */
063: public int getTimeToEOP() {
064: return microSecsPeriod - usedTime;
065: }
066:
067: /**
068: * Clock event - abstraction when thread yields without interruption
069: * @param usedTimeIn the current time on the clock
070: */
071: public void setUsedTime(int usedTimeIn) {
072: usedTime = usedTimeIn;
073: }
074:
075: /**
076: * To get the time used in period
077: * @param currentTime the current time on the clock
078: */
079: public int getUsedTime() {
080: if (systemInterrupt) {
081: return special_case_usedTime;
082: }
083:
084: return usedTime;
085: }
086:
087: /**
088: * To clear interrupt
089: */
090: public void clearInterrupt() {
091: systemInterrupt = false;
092: resetUsedTime();
093: }
094:
095: /**
096: * Clock ticks - inherited from super class
097: * @param currentTime the current time on the clock
098: * @return void
099: */
100: public void clockTicks(int currentTime) {
101: usedTime = currentTime % microSecsPeriod;
102:
103: //System.out.println("Clock - > usedtime = " + usedTime);
104: if (usedTime == 0) {
105: special_case_usedTime = microSecsPeriod;
106: systemInterrupt = true;
107: startingPeriodTime = currentTime;
108: }
109: }
110:
111: public void resetUsedTime() {
112: special_case_usedTime = usedTime;
113: }
114: }
|