示例#1
0
        private void SetPinResistorSetting(FX3PinResistorSetting setting)
        {
            List <IPinObject> pins = new List <IPinObject>();

            FX3.BitBangSpiConfig = new BitBangSpiConfig(true);
            pins.Add(FX3.DIO1);
            pins.Add(FX3.DIO2);
            pins.Add(FX3.DIO3);
            pins.Add(FX3.DIO4);
            pins.Add(FX3.FX3_GPIO1);
            pins.Add(FX3.FX3_GPIO2);
            pins.Add(FX3.FX3_GPIO3);
            pins.Add(FX3.FX3_GPIO4);
            pins.Add(FX3.BitBangSpiConfig.CS);
            pins.Add(FX3.BitBangSpiConfig.SCLK);
            pins.Add(FX3.BitBangSpiConfig.MISO);
            pins.Add(FX3.BitBangSpiConfig.MOSI);
            pins.Add(FX3.ResetPin);
            //uart
            pins.Add(new FX3PinObject(48));
            foreach (IPinObject pin in  pins)
            {
                /* Read each pin to set as input */
                FX3.ReadPin(pin);
                FX3.SetPinResistorSetting(pin, setting);
            }
        }
示例#2
0
        public void USBTimingTest()
        {
            Console.WriteLine("Starting USB command execution timing test...");

            const int NUM_TRIALS = 5000;

            /* Timer for measuring elapsed time */
            Stopwatch timer = new Stopwatch();

            //Set pin
            timer.Restart();
            for (int trial = 0; trial < NUM_TRIALS; trial++)
            {
                FX3.SetPin(FX3.DIO1, 0);
            }
            timer.Stop();
            Console.WriteLine("Average SetPin execution time: " + ((timer.ElapsedMilliseconds * 1000) / NUM_TRIALS).ToString() + "us");

            timer.Restart();
            for (int trial = 0; trial < NUM_TRIALS; trial++)
            {
                FX3.ReadPin(FX3.DIO1);
            }
            timer.Stop();
            Console.WriteLine("Average ReadPin execution time: " + ((timer.ElapsedMilliseconds * 1000) / NUM_TRIALS).ToString() + "us");

            timer.Restart();
            for (int trial = 0; trial < NUM_TRIALS; trial++)
            {
                FX3.StallTime = 10;
            }
            timer.Stop();
            Console.WriteLine("Average SPI parameter configuration time: " + ((timer.ElapsedMilliseconds * 1000) / NUM_TRIALS).ToString() + "us");
        }
示例#3
0
        public void BitBangSpiModeTest()
        {
            Console.WriteLine("Starting bit bang SPI mode test...");

            byte[] MISO;

            uint mode;

            List <byte> MOSI = new List <byte>();

            for (int i = 0; i < 1024; i++)
            {
                MOSI.Add((byte)(i & 0x7F));
            }

            FX3.BitBangSpiConfig      = new BitBangSpiConfig(true);
            FX3.BitBangSpiConfig.SCLK = (FX3PinObject)FX3.DIO3;
            FX3.ReadPin(FX3.DIO3);
            FX3.ReadPin(FX3.DIO3);
            Random rnd = new Random();

            for (int trial = 0; trial < 64; trial++)
            {
                mode = (uint)(rnd.NextDouble() * 4);
                Console.WriteLine("Testing bit-bang SPI mode " + mode.ToString());
                FX3.BitBangSpiConfig.CPHA = ((mode & 0x1) != 0);
                FX3.BitBangSpiConfig.CPOL = ((mode & 0x2) != 0);

                for (uint len = 8; len < 64; len += 8)
                {
                    MISO = FX3.BitBangSpi(len, 1, MOSI.ToArray(), 1000);
                    Assert.AreEqual(len >> 3, MISO.Count(), "ERROR: Invalid data count");
                    for (int i = 0; i < MISO.Count(); i++)
                    {
                        Assert.AreEqual(MOSI[i], MISO[i], "ERROR: Invalid echo data");
                    }
                }

                /* Check SCLK pin level after transfer */
                if (FX3.BitBangSpiConfig.CPOL)
                {
                    Assert.AreEqual(1, FX3.ReadPin(FX3.DIO4), "ERROR: Expected SCLK to be idle high");
                }
                else
                {
                    Assert.AreEqual(0, FX3.ReadPin(FX3.DIO4), "ERROR: Expected SCLK to be idle low");
                }
            }
        }
示例#4
0
        public void SetReadPinTest()
        {
            Console.WriteLine("Starting pin read/write test...");

            const int NUM_TRIALS = 100;

            Console.WriteLine("Testing " + NUM_TRIALS.ToString() + " pin set/read trials");
            for (int trial = 0; trial < NUM_TRIALS; trial++)
            {
                Console.WriteLine("Starting trial " + trial.ToString());
                FX3.SetPin(FX3.DIO3, 1);
                Assert.AreEqual(1, FX3.ReadPin(FX3.DIO4), "ERROR: Invalid pin value read on DIO4");
                FX3.SetPin(FX3.DIO3, 0);
                Assert.AreEqual(0, FX3.ReadPin(FX3.DIO4), "ERROR: Invalid pin value read on DIO4");

                FX3.SetPin(FX3.DIO4, 1);
                Assert.AreEqual(1, FX3.ReadPin(FX3.DIO3), "ERROR: Invalid pin value read on DIO3");
                FX3.SetPin(FX3.DIO4, 0);
                Assert.AreEqual(0, FX3.ReadPin(FX3.DIO3), "ERROR: Invalid pin value read on DIO3");
            }
        }
示例#5
0
        public void ResistorConfigurationTest()
        {
            Console.WriteLine("Starting GPIO resistor configuration test...");

            for (int trial = 0; trial < 10; trial++)
            {
                Console.WriteLine("Enabling internal pull up on all user accessible GPIO...");
                SetPinResistorSetting(FX3PinResistorSetting.PullUp);
                System.Threading.Thread.Sleep(50);

                Console.WriteLine("Checking input stage values...");
                Assert.AreEqual(1, FX3.ReadPin(FX3.DIO1), "ERROR: Expected pin to be high");
                Assert.AreEqual(1, FX3.ReadPin(FX3.DIO2), "ERROR: Expected pin to be high");
                Assert.AreEqual(1, FX3.ReadPin(FX3.DIO3), "ERROR: Expected pin to be high");
                Assert.AreEqual(1, FX3.ReadPin(FX3.DIO4), "ERROR: Expected pin to be high");
                Assert.AreEqual(1, FX3.ReadPin(FX3.FX3_GPIO1), "ERROR: Expected pin to be high");
                Assert.AreEqual(1, FX3.ReadPin(FX3.FX3_GPIO2), "ERROR: Expected pin to be high");
                Assert.AreEqual(1, FX3.ReadPin(FX3.FX3_GPIO3), "ERROR: Expected pin to be high");
                Assert.AreEqual(1, FX3.ReadPin(FX3.FX3_GPIO4), "ERROR: Expected pin to be high");

                Console.WriteLine("Enabling internal pull down on all user accessible GPIO...");
                SetPinResistorSetting(FX3PinResistorSetting.PullDown);
                System.Threading.Thread.Sleep(50);

                Console.WriteLine("Checking input stage values...");
                Assert.AreEqual(0, FX3.ReadPin(FX3.DIO1), "ERROR: Expected pin to be low");
                Assert.AreEqual(0, FX3.ReadPin(FX3.DIO2), "ERROR: Expected pin to be low");
                Assert.AreEqual(0, FX3.ReadPin(FX3.DIO3), "ERROR: Expected pin to be low");
                Assert.AreEqual(0, FX3.ReadPin(FX3.DIO4), "ERROR: Expected pin to be low");
                Assert.AreEqual(0, FX3.ReadPin(FX3.FX3_GPIO1), "ERROR: Expected pin to be low");
                Assert.AreEqual(0, FX3.ReadPin(FX3.FX3_GPIO2), "ERROR: Expected pin to be low");
                Assert.AreEqual(0, FX3.ReadPin(FX3.FX3_GPIO3), "ERROR: Expected pin to be low");
                Assert.AreEqual(0, FX3.ReadPin(FX3.FX3_GPIO4), "ERROR: Expected pin to be low");

                Console.WriteLine("Disabling resistors...");
                SetPinResistorSetting(FX3PinResistorSetting.None);
                System.Threading.Thread.Sleep(50);
            }
        }