Ejemplo n.º 1
0
            public override void Establish(IAutoBinder binder)
            {
                if (_realized)
                    return;

                object constValue;
                var literal = (Literal)_literal;
                if (literal.IsConst(out constValue))
                {
                    var slv = Marshal.SerializeForHW(constValue);
                    _dataOutI = (SLVSignal)binder.GetSignal(EPortUsage.Default, "constSignal_" + constValue.ToString(), null, slv);
                    _dataOut = _dataOutI.Descriptor;
                }
                else
                {
                    bool needRead = true, needWrite = true;
                    var fref = _literal as FieldRef;
                    if (fref != null)
                    {
                        needRead = fref.FieldDesc.IsReadInCurrentContext(Host.Context);
                        needWrite = fref.FieldDesc.IsWrittenInCurrentContext(Host.Context);
                    }

                    var stlit = (IStorableLiteral)_literal;
                    string name = stlit.Name;
                    var valueSample = _literal.Type.GetSampleInstance();
                    _dataBits = Marshal.SerializeForHW(valueSample).Size;

                    _clkI = (SLSignal)binder.GetSignal(EPortUsage.Clock, null, null, null);
                    _clk = _clkI.Descriptor;
                    if (needWrite)
                    {
                        _wrEnI = (SLSignal)binder.GetSignal(EPortUsage.Default, name + "_wrEn", null, StdLogic._0);
                        _wrEn = _wrEnI.Descriptor;
                        _dataInI = (SLVSignal)binder.GetSignal(EPortUsage.Default, name + "_dataIn", null, StdLogicVector._0s(_dataBits));
                        _dataIn = _dataInI.Descriptor;
                    }
                    if (needRead)
                    {
                        _dataOutI = (SLVSignal)binder.GetSignal(EPortUsage.Default, name + "_dataOut", null, StdLogicVector._0s(_dataBits));
                        _dataOut = _dataOutI.Descriptor;
                    }

                    //var apb = new AccessProcessBuilder(this, needRead, needWrite);
                    //var alg = apb.GetAlgorithm();
                    //alg.Name = name + "_process";
                    //binder.CreateProcess(Process.EProcessKind.Triggered, alg, _clk);
                    CommonClockProcess ccp = null;
                    string algName = name + "_process";
                    if (Host.Descriptor.HasAttribute<CommonClockProcess>())
                    {
                        ccp = Host.Descriptor.QueryAttribute<CommonClockProcess>();
                        Host.Descriptor.RemoveChild(ccp.CCProc);
                    }
                    else
                    {
                        ccp = new CommonClockProcess(_clk);
                        Host.Descriptor.AddAttribute(ccp);
                    }
                    ccp.AddAccessor(this, needRead, needWrite);
                    var alg = ccp.FrameBuilder.Complete();
                    alg.Name = algName;
                    ccp.CCProc = binder.CreateProcess(Process.EProcessKind.Triggered, alg, _clk);
                }

                _realized = true;
            }
Ejemplo n.º 2
0
            public override void Establish(IAutoBinder binder)
            {
                if (_realized)
                {
                    return;
                }

                object constValue;
                var    literal = (Literal)_literal;

                if (literal.IsConst(out constValue))
                {
                    var slv = Marshal.SerializeForHW(constValue);
                    _dataOutI = (SLVSignal)binder.GetSignal(EPortUsage.Default, "constSignal_" + constValue.ToString(), null, slv);
                    _dataOut  = _dataOutI.Descriptor;
                }
                else
                {
                    bool needRead = true, needWrite = true;
                    var  fref = _literal as FieldRef;
                    if (fref != null)
                    {
                        needRead  = fref.FieldDesc.IsReadInCurrentContext(Host.Context);
                        needWrite = fref.FieldDesc.IsWrittenInCurrentContext(Host.Context);
                    }

                    var    stlit       = (IStorableLiteral)_literal;
                    string name        = stlit.Name;
                    var    valueSample = _literal.Type.GetSampleInstance();
                    _dataBits = Marshal.SerializeForHW(valueSample).Size;

                    _clkI = (SLSignal)binder.GetSignal(EPortUsage.Clock, null, null, null);
                    _clk  = _clkI.Descriptor;
                    if (needWrite)
                    {
                        _wrEnI   = (SLSignal)binder.GetSignal(EPortUsage.Default, name + "_wrEn", null, StdLogic._0);
                        _wrEn    = _wrEnI.Descriptor;
                        _dataInI = (SLVSignal)binder.GetSignal(EPortUsage.Default, name + "_dataIn", null, StdLogicVector._0s(_dataBits));
                        _dataIn  = _dataInI.Descriptor;
                    }
                    if (needRead)
                    {
                        _dataOutI = (SLVSignal)binder.GetSignal(EPortUsage.Default, name + "_dataOut", null, StdLogicVector._0s(_dataBits));
                        _dataOut  = _dataOutI.Descriptor;
                    }

                    //var apb = new AccessProcessBuilder(this, needRead, needWrite);
                    //var alg = apb.GetAlgorithm();
                    //alg.Name = name + "_process";
                    //binder.CreateProcess(Process.EProcessKind.Triggered, alg, _clk);
                    CommonClockProcess ccp     = null;
                    string             algName = name + "_process";
                    if (Host.Descriptor.HasAttribute <CommonClockProcess>())
                    {
                        ccp = Host.Descriptor.QueryAttribute <CommonClockProcess>();
                        Host.Descriptor.RemoveChild(ccp.CCProc);
                    }
                    else
                    {
                        ccp = new CommonClockProcess(_clk);
                        Host.Descriptor.AddAttribute(ccp);
                    }
                    ccp.AddAccessor(this, needRead, needWrite);
                    var alg = ccp.FrameBuilder.Complete();
                    alg.Name   = algName;
                    ccp.CCProc = binder.CreateProcess(Process.EProcessKind.Triggered, alg, _clk);
                }

                _realized = true;
            }