Example #1
0
        static void TestRegOperation()
        {
            UInt32 myInt = 0;
            var    a     = FpgaOp.RegWrite(0, 94);
            var    b     = FpgaOp.RegRead(ref myInt, 0);

            uint[] dataIn  = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            uint[] dataOut = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            var c = FpgaOp.RegArrayWrite(dataIn, 0x100, 10);
            var d = FpgaOp.RegArrayRead(ref dataOut, 0x100, 10);
        }
Example #2
0
        public static int RegArrayRead(ref UInt32[] data, UInt64 address, UInt32 length)
        {
            data = new UInt32[length];
            IntPtr pd  = Marshal.AllocHGlobal((int)(sizeof(int) * length));
            IntPtr pv  = pd;
            var    ret = FpgaOp.RegArrayRead(pd, address, length);

            int[] temp = (int[])(object)data;
            Marshal.Copy(pd, temp, 0, (int)length);
            Marshal.FreeHGlobal(pv);
            return(ret);
        }
Example #3
0
        static void ConfigMM2S(UInt64 dmaBaseAddr, UInt64 ddrSrcAddr, UInt32 bytes)
        {
            // MemoryMapped to Stream DMA Control Register
            const UInt64 MM2S_DMACR = 0x00;
            // MemoryMapped to Stream Source Address, lower 32 bits
            const UInt64 MM2S_SA = 0x18;
            // MemoryMapped to Stream Source Address, upper 32 bits
            const UInt64 MM2S_SA_MSB = 0x1C;
            // MemoryMapped to Stream Length (bytes)
            const UInt64 MM2S_LENGTH = 0x28;

            FpgaOp.RegWrite(dmaBaseAddr + MM2S_DMACR, 0x01);
            FpgaOp.RegWrite(dmaBaseAddr + MM2S_SA_MSB, (UInt32)(ddrSrcAddr >> 32) & 0xFFFFFFFF);
            FpgaOp.RegWrite(dmaBaseAddr + MM2S_SA, (UInt32)(ddrSrcAddr & 0xFFFFFFFF));
            FpgaOp.RegWrite(dmaBaseAddr + MM2S_LENGTH, bytes);
        }
Example #4
0
        static void ConfigS2MM(UInt64 dmaBaseAddr, UInt64 ddrDstAddr, UInt32 bytes)
        {
            // Stream to MemoryMapped DMA Control Register
            const UInt64 S2MM_DMACR = 0x30;
            // Stream to MemoryMapped Destination Address, Lower 32 bits
            const UInt64 S2MM_DA = 0x48;
            // Stream to MemoryMapped Destination Address, Upper 32 bits
            const UInt64 S2MM_DA_MSB = 0x4C;
            // Stream to MemoryMapped Length (bytes)
            const UInt64 S2MM_LENGTH = 0x58;

            FpgaOp.RegWrite(dmaBaseAddr + S2MM_DMACR, 0x01);
            FpgaOp.RegWrite(dmaBaseAddr + S2MM_DA_MSB, (UInt32)(ddrDstAddr >> 32) & 0xFFFFFFFF);
            FpgaOp.RegWrite(dmaBaseAddr + S2MM_DA, (UInt32)(ddrDstAddr & 0xFFFFFFFF));
            FpgaOp.RegWrite(dmaBaseAddr + S2MM_LENGTH, bytes);
        }
Example #5
0
        static void TestDDR()
        {
            const uint   dataLength = 16 * 1024;
            const UInt32 srcAddr    = 0x10000000;
            const UInt32 destAddr   = 0x20000000;
            int          i;

            UInt32[] dataIn = new UInt32[dataLength];
            for (i = 0; i < dataLength; i++)
            {
                dataIn[i] = (UInt32)i;
            }
            FpgaOp.DdrWrite(dataIn, srcAddr, dataLength);

            // DMA copy
            FpgaOp.DdrCopy(srcAddr, destAddr, dataLength);

            UInt32[] dataOut = new UInt32[dataLength];
            for (i = 0; i < dataLength; i++)
            {
                dataOut[i] = 0;
            }
            FpgaOp.DdrRead(dataOut, destAddr, dataLength);

            for (i = 0; i < dataLength; i++)
            {
                if (dataIn[i] != dataOut[i])
                {
                    break;
                }
            }

            if (i == dataLength)
            {
                Console.WriteLine("DDR Test Passed!");
            }
            else
            {
                Console.WriteLine("DDR Test Failed!");
            }
        }
Example #6
0
        static void Main(string[] args)
        {
            SessionOpen();

            ShowAddressMap();

            #region Test
            //TestMemory();
            //TestRegOperation();
            //TestDDR();
            #endregion

            //goto label;

            #region ET Test

            const int    numOfSamples         = 1024;
            const int    osr                  = 8;
            const UInt64 Et_RegBase           = 0x21000;
            const UInt64 Streamer_DMA_RegBase = 0x20000;
            const UInt64 paInAddr             = 0x02000000;
            const UInt64 envOutAddr           = 0x03000000;

            //Step 1. Load Waveform into DDR
            StreamReader sr         = new StreamReader(@"c:\wjh\IQ.csv");
            double[]     iqData     = new double[numOfSamples * 2];
            string       line       = "";
            int          LineNumber = 0;
            while ((line = sr.ReadLine()) != null)
            {
                var iq    = line.Split(',');
                var iData = float.Parse(iq[0]);
                var qData = float.Parse(iq[1]);

                if (LineNumber < numOfSamples)
                {
                    iqData[2 * LineNumber]     = iData;
                    iqData[2 * LineNumber + 1] = qData;
                }
                LineNumber++;
            }
            var fixedPointData = ScaleToFixedPoint(iqData, true, ref scaleFactor);
            Console.WriteLine("scaleFactor = {0}", scaleFactor);
            var dataToDdr = PackToUInt32(fixedPointData);
            FpgaOp.DdrWrite(dataToDdr, paInAddr, numOfSamples);

            //Step 2. Setup ET registers
            FpgaOp.RegWrite(Et_RegBase + 0x4, 0x80000000 / osr);    // Resampler rate = 1
            FpgaOp.RegWrite(Et_RegBase + 0x10, numOfSamples);       // Input Sample=1024
            FpgaOp.RegWrite(Et_RegBase + 0x14, numOfSamples * osr); // Output Sample=1024

            FpgaOp.RegWrite(Et_RegBase + 0x8, 0);
            FpgaOp.RegWrite(Et_RegBase + 0xc, 0);
            FpgaOp.RegWrite(Et_RegBase + 0x18, 0);

            var shapingTable = CreateShapingTable();
            FpgaOp.RegArrayWrite(shapingTable, Et_RegBase + 0x400, 256); //Shaping Table
            FpgaOp.RegWrite(Et_RegBase + 0x0, 1);                        // Clr

            //Step 3. Setup Streamer32
            ConfigS2MM(Streamer_DMA_RegBase, envOutAddr, numOfSamples * osr * 2); // envOut each sample 2 bytes
            ConfigMM2S(Streamer_DMA_RegBase, paInAddr, numOfSamples * 4);         // paIn each sample 4 bytes

            //Step 4. Read back the ET output
            UInt32[] dataFromDdr = new UInt32[numOfSamples * osr / 2];
            FpgaOp.DdrRead(dataFromDdr, envOutAddr, numOfSamples * osr / 2);
            var envData        = UnpackToShort(dataFromDdr);
            var envData_Double = ScaleToFloatingPoint(envData);
            #endregion

            //label:

            //Step 5. Write Env output to file
            StreamWriter sw = new StreamWriter(@"c:\wjh\EnvOut.csv");
            for (int i = 0; i < envData_Double.Length; i++)
            {
                sw.WriteLine("{0}", envData_Double[i]);
            }
            sw.Close();

            SessionClose();

            Console.ReadKey();
        }