Esempio n. 1
0
 private static void enableInterruptsDigital(Interrupt interrupt, ref int status)
 {
     interrupt.DictCallback = (k, v) =>
     {
         //Since the NotifyDict will fire even if the state is the same,
         //We ignore if the state is the same.
         if (v == interrupt.PreviousState)
             return;
         //True => false, Falling
         if (interrupt.PreviousState)
         {
             //Set previous state, so next trigger will work.
             interrupt.PreviousState = v;
             //If we dont fire on down, return
             if (!interrupt.FireOnDown)
                 return;
             //Set out timestamps
             interrupt.FallingTimestamp = SimHooks.GetFPGATimestamp();
             interrupt.RisingTimestamp = 0;
         }
         else
         {
             interrupt.PreviousState = v;
             //If we dont fire on up, return
             if (!interrupt.FireOnUp)
                 return;
             interrupt.RisingTimestamp = SimHooks.GetFPGATimestamp();
             interrupt.FallingTimestamp = 0;
         }
         //Call our callback in a new thread. This is what the FPGA does as well.
         new Thread(() =>
         {
             interrupt.Callback((uint)interrupt.Pin, interrupt.Param);
         }).Start();
     };
     //Set our previous state, and register
     interrupt.PreviousState = DIO[interrupt.Pin].Value;
     var dio = DIO[interrupt.Pin];
     dio.Register(nameof(dio.Value), interrupt.DictCallback);
 }
Esempio n. 2
0
        private static void enableInterruptsAnalog(Interrupt interrupt, ref int status)
        {
            AnalogTriggerData trigData = SimData.AnalogTrigger[interrupt.Pin];

            interrupt.DictCallback = (k, val) =>
            {

                int status2 = 0;
                bool v = trigData.GetTriggerValue(interrupt.AnalogType, ref status2);
                //Since the NotifyDict will fire even if the state is the same,
                //We ignore if the state is the same.
                if (v == interrupt.PreviousState)
                    return;
                //True => false, Falling
                if (interrupt.PreviousState)
                {
                    //Set previous state, so next trigger will work.
                    interrupt.PreviousState = v;
                    //If we dont fire on down, return
                    if (!interrupt.FireOnDown)
                        return;
                    //Set out timestamps
                    interrupt.FallingTimestamp = SimHooks.GetFPGATimestamp();
                    interrupt.RisingTimestamp = 0;
                }
                else
                {
                    interrupt.PreviousState = v;
                    //If we dont fire on up, return
                    if (!interrupt.FireOnUp)
                        return;
                    interrupt.RisingTimestamp = SimHooks.GetFPGATimestamp();
                    interrupt.FallingTimestamp = 0;
                }
                //Call our callback in a new thread. This is what the FPGA does as well.
                new Thread(() =>
                {
                    interrupt.Callback((uint)interrupt.Pin, interrupt.Param);
                }).Start();
            };
            //Set our previous state, and register
            interrupt.PreviousState = trigData.GetTriggerValue(interrupt.AnalogType, ref status);
            var aIn = AnalogIn[trigData.AnalogPin];
            aIn.Register(nameof(aIn.Voltage), interrupt.DictCallback);
        }