Example #1
0
        public CrystalTimer(Quartz32768HzCrystal master, Scheduler scheduler, int timerNumber)
        {
            switch (timerNumber)
            {
            case 1:
                InterruptId = Calculator.InterruptId.CrystalTimer1;
                break;

            case 2:
                InterruptId = Calculator.InterruptId.CrystalTimer2;
                break;

            case 3:
                InterruptId = Calculator.InterruptId.CrystalTimer3;
                break;

            default:
                throw new ArgumentOutOfRangeException("timerNumber must be between 1 and 3");
            }
            TimerNumber = timerNumber;
            MasterTimer = master;
            //Oscillation = new EventHandler(DoTick);
            Scheduler = scheduler;

            NextWtIncrement         = new Scheduler.WallTimeEvent();
            NextWtIncrement.Tag     = "Crystal timer " + timerNumber.ToString() + " wall-time tick";
            NextWtIncrement.Handler = new EventHandler <Scheduler.WallTimeEvent>(DoTickWt);
            NextScIncrement         = new Scheduler.SystemClockEvent();
            NextScIncrement.Tag     = "Crystal timer " + timerNumber.ToString() + " clock-time tick";
            NextScIncrement.Handler = new EventHandler <Scheduler.SystemClockEvent>(DoTickSc);
            //Scheduler.EnqueueRelativeEvent(NextWtIncrement, 1.0 / 32768);
        }
Example #2
0
 private void DoTickSc(object sender, Scheduler.SystemClockEvent e)
 {
     // TODO: This won't count correctly when the rate is faster than each CPU instruction
     unchecked
     {
         if (--count == 0)
         {
             if (MissedLoop)
             {
                 count = 255;
             }
             else
             {
                 count = InitialCount;
             }
             if (Loop)
             {
                 MissedLoop = true;
                 Scheduler.EnqueueRelativeEvent(e, ScPeriod);
             }
             else
             {
                 IsActive = false;
             }
             if (GenerateInterrupt)
             {
                 HasInterrupt = true;
             }
             HasExpired = true;
         }
         else
         {
             Scheduler.EnqueueRelativeEvent(e, ScPeriod);
         }
     }
 }