-- Copyright (C) 1984  by Xerox Corporation. All rights reserved. 
-- GMTUsingIntervalTimer.mesa, HGM, 17-Sep-84 20:05:14

DIRECTORY
  DeviceCleanup USING [Perform],
  PilotMP USING [cPowerOff],  -- heads should have their own MP codes!
  Process USING [SecondsToTicks, Detach, Pause, Ticks],
  ProcessOperations USING [DisableInterrupts],
  ProcessorFace USING [
    BootButton, GetClockPulses, gmtEpoch, GreenwichMeanTime,
    microsecondsPerHundredPulses, SetMP],
  TemporarySetGMT USING [];

GMTUsingIntervalTimer: PROGRAM
  IMPORTS DeviceCleanup, Process, ProcessOperations, ProcessorFace
  EXPORTS ProcessorFace, TemporarySetGMT =
  BEGIN OPEN ProcessorFace;

  --
  -- Simulate greenwich mean time and power control features of ProcessorFace using
  -- interval timer

  GetGreenwichMeanTime: PUBLIC PROC RETURNS [GreenwichMeanTime] =
    BEGIN
    newPulses, pulsesJumped, new100Seconds, leftoverSeconds: LONG CARDINAL;
    IF gmtSimulated = gmtEpoch THEN RETURN[gmtSimulated]; -- clock not set
    newPulses ← GetClockPulses[] - pulsesGmtSimulated;
    new100Seconds ← newPulses / pulsesPer100Seconds;
    pulsesJumped ← new100Seconds * pulsesPer100Seconds;
    pulsesGmtSimulated ← pulsesGmtSimulated + pulsesJumped;
    gmtSimulated ← gmtSimulated + new100Seconds * 100;
    leftoverSeconds ← ((newPulses - pulsesJumped) * 100) / pulsesPer100Seconds;
    RETURN[gmtSimulated + leftoverSeconds];
    END;

  SetGreenwichMeanTime: PUBLIC PROC [gmt: GreenwichMeanTime] =
    BEGIN
    IF gmtSimulated = gmtEpoch THEN Process.Detach[FORK Ticker[]];
    pulsesGmtSimulated ← GetClockPulses[];
    gmtSimulated ← gmt;
    END;
  
  adjustableClockRate: PUBLIC BOOLEAN ← TRUE;
  
  SetClockRate: PUBLIC PROC [internal, external: LONG CARDINAL] =
    BEGIN
    diff: LONG INTEGER = external-internal;
    temp: LONG INTEGER;
    f: LONG CARDINAL ← 10*(1D9/microsecondsPerHundredPulses);
    temp ← f*diff/external;
    pulsesPer100Seconds ← f - temp;
    END;
  
  gmtSimulated:       GreenwichMeanTime ← gmtEpoch;  -- =gmtEpoch => not set
  pulsesGmtSimulated: LONG CARDINAL;  -- interval timer value corresponding to gmtSimulated
  pulsesPer100Seconds: LONG CARDINAL ← 10*(1D9/microsecondsPerHundredPulses);

  PowerOff: PUBLIC PROC =
    BEGIN
    -- NOTE: This code depends on the greenwich mean time clock running with
    -- interrupts disabled and devices turned off.
    ProcessOperations.DisableInterrupts[];
    DeviceCleanup.Perform[turnOff];
    SetMP[PilotMP.cPowerOff];
    DO  -- forever
      IF GetGreenwichMeanTime[] - gmtEpoch >= gmtAutomaticPowerOn - gmtEpoch
        AND (~externalEventRequired OR ExternalEvent[]) THEN BootButton[]
      ENDLOOP
    END;

  gmtAutomaticPowerOn:   GreenwichMeanTime;
  externalEventRequired: BOOLEAN;
  ExternalEvent:         PROC RETURNS [BOOLEAN] = {RETURN[FALSE]};

  SetAutomaticPowerOn: PUBLIC PROC [gmt: GreenwichMeanTime, externalEvent: BOOLEAN] =
    {gmtAutomaticPowerOn ← gmt; externalEventRequired ← externalEvent};

  ResetAutomaticPowerOn: PUBLIC PROC = {gmtAutomaticPowerOn ← gmtEpoch - 1};

  Ticker: PROC =
    BEGIN
    oneHour: Process.Ticks = Process.SecondsToTicks[60*60];
    DO
      [] ← GetGreenwichMeanTime[];
      Process.Pause[oneHour];
      ENDLOOP;
    END;
    
  --
  -- Initialization

  ResetAutomaticPowerOn[];

  END....




LOG

Time: February 4, 1980  10:36 AM	By: McJones	Action: Create file, borrowing code from SystemImpl
Time: June 26, 1980  10:48 AM	By: McJones	Action: OISProcessorFace=>ProcessorFace
Time:  7-Dec-81 15:32:28	By: Marzullo	Action: added adjustableClockrate and SetClockRate
Time: 20-Sep-82 18:13:12	By: Marzullo	Action: fixed signed/unsigned problem with SetClockRate (fix courtesy HGM).