Пример #1
0
        public static void ReadData(uint baud, FPGA.InputSignal <bool> RXD, ComplexFloat[] data)
        {
            uint tmp32 = 0;

            for (uint i = 0; i < data.Length; i++)
            {
                FPGA.Config.SetInclusiveRange(0, data.Length, i);

                ComplexFloat tmp = new ComplexFloat();

                for (byte idx = 0; idx < 2; idx++)
                {
                    FPGA.Config.SetInclusiveRange(0, 2, idx);

                    UART.ReadUnsigned32(baud, RXD, ref tmp32);
                    switch (idx)
                    {
                    case 0:
                        FPGA.Runtime.Assign(FPGA.Expressions.Unchecked(tmp32, out tmp.Re));
                        break;

                    case 1:
                        FPGA.Runtime.Assign(FPGA.Expressions.Unchecked(tmp32, out tmp.Im));
                        break;
                    }
                }
                data[i] = tmp;
            }
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            const int  baud    = 115200;
            Sequential handler = () =>
            {
                while (true)
                {
                    byte op = 0;
                    UART.Read(baud, RXD, out op);

                    uint op1 = 0, op2 = 0;
                    UART.ReadUnsigned32(baud, RXD, ref op1);
                    UART.ReadUnsigned32(baud, RXD, ref op2);

                    var result = TestMethod(op, (int)op1, (int)op2);

                    UART.WriteUnsigned64(baud, (ulong)result, TXD);
                }
            };

            FPGA.Config.OnStartup(handler);
        }
Пример #3
0
        public static void DeviceControl(
            FPGA.OutputSignal <bool> DOUT,
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);
            object commsLock = new object();

            bool internalDOUT = false;

            FPGA.Config.Link(internalDOUT, DOUT);

            const uint baud = 115200;

            FPGA.SyncStream <uint> heartBeat = new FPGA.SyncStream <uint>();

            const int servosCount = 5;

            byte[] servosBuff = new byte[servosCount];

            Sequential servosHandler = () =>
            {
                FPGA.OutputSignal <bool> ServoItem = new FPGA.OutputSignal <bool>();
                bool servoOut = false;
                FPGA.Config.Link(servoOut, ServoItem);

                while (true)
                {
                    uint idx       = FPGA.Config.InstanceId();
                    byte servoData = 0;
                    servoData = servosBuff[idx];

                    MG996R.Write(servoData, out servoOut);
                }
            };

            FPGA.Config.OnStartup(servosHandler, servosCount);


            // SERVOs driver
            Sequential <uint> servosDataHandler = (iteration) =>
            {
                byte data = 0;

                lock (commsLock)
                {
                    UART.RegisteredWrite(baud, 2, out internalTXD);

                    for (int i = 0; i < servosCount; i++)
                    {
                        data          = UART.Read(baud, RXD);
                        servosBuff[i] = data;
                    }
                }
            };

            FPGA.Config.OnStream(heartBeat, servosDataHandler);

            // LED driver
            Sequential <uint> ledHandler = (iteration) =>
            {
                uint   data = 0;
                uint[] buff = new uint[64];

                lock (commsLock)
                {
                    UART.RegisteredWrite(baud, 1, out internalTXD);

                    for (int i = 0; i < buff.Length; i++)
                    {
                        UART.ReadUnsigned32(baud, RXD, ref data);
                        buff[i] = data;
                    }
                }

                WS2812B.SyncWrite(buff, 0, buff.Length, out internalDOUT);
            };

            FPGA.Config.OnStream(heartBeat, ledHandler);


            // main application driver
            uint       beat             = 0;
            Sequential heartBeatHandler = () =>
            {
                heartBeat.Write(beat);
                beat++;
            };

            FPGA.Config.OnTimer(TimeSpan.FromMilliseconds(100), heartBeatHandler);
        }