public static void ReturnRethrow(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                if (data == 200 || data == 201)
                {
                    throw new Exception1();
                }

                stream.Write(data);
            }
            catch (Exception1)
            {
                stream.Write(50);
                return;
            }
            catch (Exception2)
            {
                if (data == 201)
                {
                    throw new Exception3();
                }
            }
            finally
            {
                if (data == 100)
                {
                    throw new Exception4();
                }

                stream.Write(241);
            }

            stream.Write(240);
        }
        public static void TryCatchExplicit(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                switch (data)
                {
                case 1:
                    throw new Exception1();

                case 2:
                    throw new Exception2();

                default:
                    stream.Write(data);
                    break;
                }
            }
            catch (Exception1)
            {
                stream.Write(10);
            }
            catch (Exception2)
            {
                stream.Write(20);
            }

            stream.Write(255);
        }
        public static void TryCatchSome(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                switch (data)
                {
                case 1:
                    throw new DerivedException1();

                case 2:
                    throw new DerivedException2();

                default:
                    stream.Write(data);
                    break;
                }
            }
            catch (DerivedException1)
            {
                stream.Write(10);
            }
            finally
            {
                stream.Write(154);
            }

            stream.Write(155);
        }
        public static void Bootstrap(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD,
            Action <byte, FPGA.SyncStream <byte> > testAction
            )
        {
            const int baud = 115200;

            var stream = new FPGA.SyncStream <byte>();
            Sequential <byte> streamHandler = (data) =>
            {
                UART.Write(baud, data, TXD);
            };

            FPGA.Config.OnStream <byte>(stream, streamHandler);

            Sequential handler = () =>
            {
                byte data = 0;
                UART.Read(baud, RXD, out data);
                testAction(data, stream);
            };

            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
        public static void TryCatchAll_ReturnRethrow(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                if (data == 10)
                {
                    throw new Exception1();
                }

                ReturnRethrow(data, stream);

                stream.Write(data);
            }
            catch (Exception3)
            {
                stream.Write(199);
            }
            catch (Exception4)
            {
                stream.Write(205);
            }
            catch (Exception)
            {
                stream.Write(254);
            }

            stream.Write(253);
        }
예제 #6
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD)
        {
            var  stream      = new FPGA.SyncStream <byte>();
            bool internalTXD = true;

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

            Sequential <byte> streamHandler = (value) =>
            {
                lock (txdLock)
                {
                    UART.RegisteredWrite(115200, value, out internalTXD);
                }
            };

            FPGA.Config.OnStream(stream, streamHandler, 2);

            Sequential handler = () =>
            {
                byte data = 0;
                UART.Read(115200, RXD, out data);
                for (ushort i = 0; i < data; i++)
                {
                    stream.Write((byte)i);
                }
            };

            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
예제 #7
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD)
        {
            var stream = new FPGA.SyncStream <byte>();

            Sequential <byte> streamHandler = (value) =>
            {
                UART.Write(115200, value, TXD);
            };

            FPGA.Config.OnStream(stream, streamHandler);

            Sequential handler = () =>
            {
                byte data = 0;
                UART.Read(115200, RXD, out data);
                for (ushort i = 0; i < data; i++)
                {
                    stream.Write((byte)i);
                }
            };

            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
예제 #8
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD
            )
        {
            const uint baud = 115200;

            var stream = new FPGA.SyncStream <float>();

            Sequential <float> streamHandler = (data) =>
            {
                UART.WriteFloat(baud, data, TXD);
            };

            FPGA.Config.OnStream(stream, streamHandler);

            Sequential handler = () =>
            {
                float f1 = 0, f2 = 1.234f;

                UART.ReadFloat(baud, RXD, out f1);
                stream.Write(f1);
                stream.Write(f2);
            };

            FPGA.Config.OnStartup(handler);
        }
예제 #9
0
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD)
        {
            bool internalTXD = true;

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

            byte   counter     = 0;
            object counterLock = new object();

            var transmitterStream = new FPGA.SyncStream <byte>();
            Sequential <byte> transmitterStreamHandler = (value) =>
            {
                lock (txdLock)
                {
                    UART.RegisteredWrite(115200, value, out internalTXD);
                }
            };

            FPGA.Config.OnStream(transmitterStream, transmitterStreamHandler, 2);

            var receiverStream = new FPGA.SyncStream <byte>();
            Sequential <byte> receiverStreamHandler = (value) =>
            {
                Func <uint> instanceId = () => FPGA.Config.InstanceId();

                byte increment = 0;
                lock (counterLock)
                {
                    increment = counter;
                    counter++;
                }
                transmitterStream.Write((byte)(value + increment + instanceId()));
            };

            FPGA.Config.OnStream(receiverStream, receiverStreamHandler, 3);

            Sequential handler = () =>
            {
                byte data = 0;
                UART.Read(115200, RXD, out data);
                for (ushort i = 0; i < data; i++)
                {
                    receiverStream.Write((byte)i);
                }
            };

            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, handler);
        }
        public static void TryFinally(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                stream.Write(data);
            }
            finally
            {
                stream.Write(255);
            }

            stream.Write(255);
        }
        public static void TryCatchAll(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                if (data == 10)
                {
                    throw new Exception1();
                }

                stream.Write(data);
            }
            catch (Exception)
            {
                stream.Write(255);
            }

            stream.Write(254);
        }
예제 #12
0
        public static void WriteData(uint baud, FPGA.OutputSignal <bool> TXD, ComplexFloat[] data, uint duration)
        {
            bool internalTXD = true;

            FPGA.Config.Link(internalTXD, TXD);

            FPGA.SyncStream <uint> streamWriter  = new FPGA.SyncStream <uint>();
            Sequential <uint>      streamHandler = (d) =>
            {
                UART.RegisteredWriteUnsigned32(baud, d, out internalTXD);
            };

            FPGA.Config.OnStream(streamWriter, streamHandler);

            ComplexFloat tmp = new ComplexFloat();
            uint         uns = 0;

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

                tmp = data[i];

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

                    switch (idx)
                    {
                    case 0:
                        FPGA.Runtime.Assign(FPGA.Expressions.Unchecked(tmp.Re, out uns));
                        break;

                    case 1:
                        FPGA.Runtime.Assign(FPGA.Expressions.Unchecked(tmp.Im, out uns));
                        break;
                    }

                    streamWriter.Write(uns);
                }
            }

            streamWriter.Write(duration);
        }
        public static async Task Aggregator(
            FPGA.InputSignal <bool> RXD,
            FPGA.OutputSignal <bool> TXD)
        {
            FPGA.SyncStream <byte> tdxStream  = new FPGA.SyncStream <byte>();
            Sequential <byte>      txdHandler = (value) =>
            {
                UART.Write(115200, value, TXD);
            };

            FPGA.Config.OnStream(tdxStream, txdHandler);

            byte       data        = 0;
            Sequential mainHandler = () =>
            {
                data = UART.Read(115200, RXD);
            };

            const bool trigger = true;

            FPGA.Config.OnSignal(trigger, mainHandler);

            Sequential handler1 = () =>
            {
                if (data == 0)
                {
                    return;
                }

                tdxStream.Write(1);
            };

            Sequential handler2 = () =>
            {
                if (data == 0)
                {
                    return;
                }

                tdxStream.Write(2);
            };

            FPGA.Config.OnTimer(TimeSpan.FromMilliseconds(100), handler1, handler2);
        }
        public static void TryCatchBase_TryCatchSome(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                if (data == 10)
                {
                    throw new DerivedException1();
                }

                TryCatchSome(data, stream);

                stream.Write(data);
            }
            catch (BaseException)
            {
                stream.Write(254);
            }

            stream.Write(253);
        }
        public static void SmokeTest(byte data, FPGA.SyncStream <byte> stream)
        {
            try
            {
                if (data > 10)
                {
                    TryCatchAll_ReturnRethrow(data, stream);
                }
                else
                {
                    TryCatchAllFinally(data, stream);
                }
            }
            catch (Exception)
            {
                stream.Write(253);
            }
            finally
            {
                stream.Write(254);
            }

            stream.Write(255);
        }
예제 #16
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);
        }