Exemple #1
0
        public void I2CStreamTest()
        {
            Console.WriteLine("Starting I2C data stream test...");

            I2CPreamble pre = new I2CPreamble();

            pre.DeviceAddress = 0xA0;
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0);
            pre.PreambleData.Add(0xA1);
            pre.StartMask = 4;

            TestI2CFunctionality();

            byte[] StreamData, InitialRead;

            for (int trial = 0; trial < 5; trial++)
            {
                Console.WriteLine("Starting stream...");
                FX3.StartI2CStream(pre, 64, 1000);
                FX3.WaitForStreamCompletion(10000);
                Console.WriteLine("Stream complete. Checking data...");
                InitialRead = FX3.GetI2CBuffer();
                for (int i = 1; i < 1000; i++)
                {
                    StreamData = FX3.GetI2CBuffer();
                    for (int j = 0; j < StreamData.Count(); j++)
                    {
                        Assert.AreEqual(InitialRead[j], StreamData[j], "ERROR: Invalid I2C read back data on buffer " + i.ToString());
                    }
                }
                TestI2CFunctionality();
            }
        }
Exemple #2
0
        public void ADcmXLRealTimeStreamTest()
        {
            Console.WriteLine("Starting ADcmXL data stream test...");

            double expectedTime;

            double realTime;

            double baseTime;

            uint numBuffers = 13600;

            Stopwatch timer = new Stopwatch();

            FX3.DrActive   = true;
            FX3.SensorType = DeviceType.ADcmXL;
            FX3.PartType   = DUTType.ADcmXL3021;
            FX3.DrPin      = FX3.DIO3;
            /* Start 6.8KHz, 80% duty cycle DR signal on DIO4 */
            FX3.StartPWM(6800, 0.8, FX3.DIO4);

            Console.WriteLine("Measuring base stream time...");
            baseTime = 0;
            for (int trial = 0; trial < 5; trial++)
            {
                timer.Restart();
                FX3.StartRealTimeStreaming(1000);
                System.Threading.Thread.Sleep(5);
                FX3.WaitForStreamCompletion(1000);
                baseTime += (timer.ElapsedMilliseconds - (1000.0 / 6.8));
            }
            baseTime /= 5;
            Console.WriteLine("Base stream overhead time: " + baseTime.ToString() + "ms");

            for (int trial = 0; trial < 4; trial++)
            {
                Console.WriteLine("Starting trial " + trial.ToString());
                /* Start stream */
                timer.Restart();
                FX3.StartRealTimeStreaming(numBuffers);
                System.Threading.Thread.Sleep(100);
                FX3.WaitForStreamCompletion((int)(numBuffers / 6.0) + 1000);
                timer.Stop();
                Assert.AreEqual(FX3.GetNumBuffersRead, numBuffers, "ERROR: Invalid number of buffers read");
                realTime = timer.ElapsedMilliseconds;
                /* Take off a base time */
                realTime -= baseTime;

                expectedTime = numBuffers / 6.8;
                Console.WriteLine("Expected time: " + expectedTime.ToString() + "ms, Real time: " + realTime.ToString() + "ms");
                Assert.AreEqual(expectedTime, realTime, 0.01 * expectedTime, "ERROR: Invalid stream time");

                /* Check SPI functionality */
                FX3.WordLength = 16;
                TestSpiFunctionality();
            }

            Console.WriteLine("Verifying that when the DR edge is missed the stream waits until the following edge to start...");
            FX3.SclkFrequency = 8000000;
            timer.Restart();
            FX3.StartRealTimeStreaming(numBuffers);
            System.Threading.Thread.Sleep(100);
            FX3.WaitForStreamCompletion((int)(2 * numBuffers / 6.0) + 1000);
            timer.Stop();
            Assert.AreEqual(FX3.GetNumBuffersRead, numBuffers, "ERROR: Invalid number of buffers read");
            realTime = timer.ElapsedMilliseconds;
            /* Take off a base time */
            realTime -= baseTime;

            /* Twice the time because we read every other data ready */
            expectedTime = 2 * numBuffers / 6.8;
            Console.WriteLine("Expected time: " + expectedTime.ToString() + "ms, Real time: " + realTime.ToString() + "ms");
            Assert.AreEqual(expectedTime, realTime, 0.01 * expectedTime, "ERROR: Invalid stream time");
        }
Exemple #3
0
        public void BurstSpiTest()
        {
            Console.WriteLine("Starting SPI burst read test...");

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

            ushort[] BurstData;
            int      index;

            RegMapClasses.RegClass triggerReg = new RegMapClasses.RegClass();
            triggerReg.NumBytes = 2;
            triggerReg.Address  = 0x12;

            FX3.DrActive = false;

            for (int byteCount = 4; byteCount < 400; byteCount += 2)
            {
                Console.WriteLine("Testing burst read of " + byteCount.ToString() + " bytes...");
                FX3.BurstByteCount = byteCount;
                Assert.AreEqual(byteCount, FX3.BurstByteCount, "ERROR; Byte count not applied correctly");
                Assert.AreEqual((byteCount - 2) / 2, FX3.WordCount, "ERROR: FX3 burst word count not set correctly");

                /* Burst trigger reg */
                FX3.TriggerReg = triggerReg;

                /* strip header */
                Console.WriteLine("Testing burst read with trigger reg and header stripped...");
                FX3.StripBurstTriggerWord = true;
                FX3.SetupBurstMode();
                FX3.StartBurstStream(1, FX3.BurstMOSIData);
                FX3.WaitForStreamCompletion(50);
                BurstData = FX3.GetBuffer();
                Assert.AreEqual((byteCount / 2) - 1, BurstData.Count(), "ERROR: Invalid burst data count");
                for (int i = 0; i < BurstData.Count(); i++)
                {
                    Assert.AreEqual(0, BurstData[i], "ERROR: Expected all burst data to be 0");
                }

                /* No strip header */
                Console.WriteLine("Testing burst read with trigger reg and header not stripped...");
                FX3.StripBurstTriggerWord = false;
                FX3.SetupBurstMode();
                FX3.StartBurstStream(1, FX3.BurstMOSIData);
                FX3.WaitForStreamCompletion(50);
                BurstData = FX3.GetBuffer();
                Assert.AreEqual((byteCount / 2), BurstData.Count(), "ERROR: Invalid burst data count");
                Assert.AreEqual(0x1200, BurstData[0], "ERROR: Invalid burst data echoed");
                for (int i = 1; i < BurstData.Count(); i++)
                {
                    Assert.AreEqual(0, BurstData[i], "ERROR: Expected remainder of burst data to be 0");
                }

                /* Burst transmit data */
                BurstTxData.Clear();
                for (int i = 0; i < byteCount; i++)
                {
                    BurstTxData.Add((byte)(i & 0xFFU));
                }
                FX3.BurstMOSIData = BurstTxData.ToArray();
                for (int i = 0; i < BurstTxData.Count; i++)
                {
                    Assert.AreEqual(BurstTxData[i], FX3.BurstMOSIData[i], "ERROR: Burst MOSI data not applied correctly");
                }

                /* strip header */
                Console.WriteLine("Testing burst read with MOSI byte array and header stripped...");
                FX3.StripBurstTriggerWord = true;
                FX3.SetupBurstMode();
                FX3.StartBurstStream(1, FX3.BurstMOSIData);
                FX3.WaitForStreamCompletion(50);
                BurstData = FX3.GetBuffer();
                Assert.AreEqual((byteCount / 2) - 1, BurstData.Count(), "ERROR: Invalid burst data count");
                index = 2;
                for (int i = 0; i < BurstData.Count(); i++)
                {
                    Assert.AreEqual(BurstTxData[index], BurstData[i] >> 8, "ERROR: Invalid burst data echoed");
                    Assert.AreEqual(BurstTxData[index + 1], BurstData[i] & 0xFF, "ERROR: Invalid burst data echoed");
                    index += 2;
                }

                /* No strip header */
                Console.WriteLine("Testing burst read with MOSI byte array and header not stripped...");
                FX3.StripBurstTriggerWord = false;
                FX3.SetupBurstMode();
                FX3.StartBurstStream(1, FX3.BurstMOSIData);
                FX3.WaitForStreamCompletion(50);
                BurstData = FX3.GetBuffer();
                Assert.AreEqual((byteCount / 2), BurstData.Count(), "ERROR: Invalid burst data count");
                index = 0;
                for (int i = 0; i < BurstData.Count(); i++)
                {
                    Assert.AreEqual(BurstTxData[index], BurstData[i] >> 8, "ERROR: Invalid burst data echoed");
                    Assert.AreEqual(BurstTxData[index + 1], BurstData[i] & 0xFF, "ERROR: Invalid burst data echoed");
                    index += 2;
                }
            }

            Console.WriteLine("Testing Dr Active triggering for burst...");
            FX3.DrPin = FX3.DIO3;
            FX3.StartPWM(100, 0.5, FX3.DIO4);

            FX3.BurstByteCount = 64;
            BurstTxData.Clear();
            for (int i = 0; i < 64; i++)
            {
                BurstTxData.Add((byte)(i & 0xFFU));
            }
            FX3.BurstMOSIData         = BurstTxData.ToArray();
            FX3.StripBurstTriggerWord = false;
            FX3.SetupBurstMode();
            FX3.DrActive = true;

            double    expectedTime;
            long      drActiveTime, baseTime;
            Stopwatch timer = new Stopwatch();

            for (uint numBuffers = 100; numBuffers <= 300; numBuffers += 100)
            {
                Console.WriteLine("Capturing " + numBuffers.ToString() + " buffers with DrActive set to false...");
                FX3.DrActive = false;
                FX3.StartBurstStream(numBuffers, FX3.BurstMOSIData);
                timer.Restart();
                while (FX3.GetNumBuffersRead < numBuffers)
                {
                    System.Threading.Thread.Sleep(1);
                }
                baseTime = timer.ElapsedMilliseconds;
                Console.WriteLine("Stream time: " + baseTime.ToString() + "ms");
                CheckBurstBuffers(BurstTxData.ToArray(), numBuffers);

                Console.WriteLine("Capturing " + numBuffers.ToString() + " buffers with DrActive set to true...");
                expectedTime = 10 * numBuffers; //100Hz DR
                FX3.DrActive = true;
                FX3.StartBurstStream(numBuffers, FX3.BurstMOSIData);
                timer.Restart();
                while (FX3.GetNumBuffersRead < numBuffers)
                {
                    System.Threading.Thread.Sleep(1);
                }
                drActiveTime = timer.ElapsedMilliseconds;
                Console.WriteLine("Stream time: " + drActiveTime.ToString() + "ms");
                Assert.AreEqual(expectedTime, drActiveTime, 0.25 * expectedTime, "ERROR: Invalid stream time");
                CheckBurstBuffers(BurstTxData.ToArray(), numBuffers);

                Assert.Less(baseTime, drActiveTime, "ERROR: Base stream time greater than DrActive stream time");
            }
        }