/* TimerExtras.c
    LCS March 31, 1983  5:10 PM, 32 bit counters, and more of them
    LCS August 15, 1983  6:48 PM, added Histogram
  */

/*
  Client code for watchdog timer and for accumulating
  statistics for context time.
 */

struct Long {
  int low, high;
  };

int ctxListTime[84];
int ctxStartTime;

int wdtFlagA, wdtFlagB, wdtFlagC;

InitCtxStats()
  {
  Zero(ctxListTime, 84);
  };

CtxListStart()
  {
  ctxStartTime = ReadTmr();
  };

CtxListEnd()
  {
  Histogram(ReadTmr() - ctxStartTime, ctxListTime);
  };

PokeWDTA()
  {
  wdtFlagA = 1234;
  };

PokeWDTB()
  {
  if (wdtFlagA == 1234) {
    wdtFlagA = 0;
    wdtFlagB = 5678;
    };
  };

PokeWDTC()
  {
  if (wdtFlagB == 5678) {
    wdtFlagB = 0;
    wdtFlagC = 91011;
    };
  };

PokeWDTD()
  {
  if (wdtFlagC == 91011) {
    wdtFlagC = 0;
    CheckWDT();
    };
  };

Histogram(diff, histo)
  int diff;
  int *histo;
  {
  if (diff < 0) {
    DoubleIncrement(&histo[82], 1);
    return;
    };
  if (diff >= 40) DoubleIncrement(&histo[80], 1);
  else DoubleIncrement(&histo[diff << 1], 1);
  };