Changeset 11338


Ignore:
Timestamp:
07/11/11 11:12:23 (13 years ago)
Author:
tbretz
Message:
Moved setup of the clock-conditioner to the config-file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/ftmctrl.cc

    r11301 r11338  
    14571457    }
    14581458
    1459     //map<uint32_t, uint32_t> fClockConditionerMap;
    1460 
    14611459    int SetClockFrequency(const EventImp &evt)
    14621460    {
     
    14641462            return T::kSM_FatalError;
    14651463
    1466         const uint32_t freq = evt.GetUInt();
    1467 
    1468         //map<uint32_t,uint32_t>::const_iterator = fClockConditionerMap.find(freq);
    1469 
    1470         static const uint64_t R0hi  = 0x00030000;
    1471         static const uint64_t R8    = 0x10000908;
    1472         static const uint64_t R9    = 0xa0032a09;
    1473         static const uint64_t R11   = 0x0082000b;
    1474         static const uint64_t R13   = 0x020a000d;
    1475         static const uint64_t R14hi = 0x08300000;
    1476 
    1477         static const uint64_t freq0800[8] = { R0hi|0xfe00, 0x00010101, R8, R9, R11, R13, R14hi|0x800e, 0x18017b0f };
    1478         static const uint64_t freq1000[8] = { R0hi|0xd000, 0x00010101, R8, R9, R11, R13, R14hi|0x400e, 0x1801450f };
    1479         static const uint64_t freq2000[8] = { R0hi|0x8000, 0x00010101, R8, R9, R11, R13, R14hi|0x280e, 0x1400fa0f };
    1480         static const uint64_t freq3000[8] = { R0hi|0x9000, 0x00030100, R8, R9, R11, R13, R14hi|0x400e, 0x0602a30f };
    1481         static const uint64_t freq4000[8] = { R0hi|0x4000, 0x00010101, R8, R9, R11, R13, R14hi|0x280e, 0x1400fa0f };
    1482         static const uint64_t freq5000[8] = { R0hi|0x8000, 0x00030200, R8, R9, R11, R13, R14hi|0x280e, 0x0802710f };
    1483 
    1484         const uint64_t *reg = 0;
    1485 
    1486         switch (freq)
    1487         {
    1488         case  800: reg = freq0800; break;
    1489         case 1000: reg = freq1000; break;
    1490         case 2000: reg = freq2000; break;
    1491         case 3000: reg = freq3000; break;
    1492         case 4000: reg = freq4000; break;
    1493         case 5000: reg = freq5000; break;
    1494         default:
     1464        const map<uint16_t,boost::array<uint64_t, 8>>::const_iterator it =
     1465            fClockCondSetup.find(evt.GetUInt());
     1466
     1467        if (it==fClockCondSetup.end())
     1468        {
    14951469            T::Warn("SetClockFrequency - Frequency not supported.");
    14961470            return T::GetCurrentState();
    14971471        }
    14981472
    1499         if (!fFTM.SetClockRegister(reg))
     1473        if (!fFTM.SetClockRegister(it->second.data()))
    15001474            T::Warn("SetClockFrequency - Register values out of range.");
    15011475
     
    19151889            ("");
    19161890
    1917         T::AddEvent("SET_CLOCK_FREQUENCY", "I:1", FTM::kIdle)
     1891        T::AddEvent("SET_CLOCK_FREQUENCY", "S:1", FTM::kIdle)
    19181892            (boost::bind(&StateMachineFTM::SetClockFrequency, this, _1))
    19191893            ("");
     
    19911965    }
    19921966
     1967    map<uint16_t, boost::array<uint64_t, 8>> fClockCondSetup;
     1968
    19931969    int EvalConfiguration(const Configuration &conf)
    19941970    {
    1995         SetEndpoint(conf.Get<string>("addr"));
    1996 
     1971        // ---------- General setup ----------
    19971972        fFTM.SetVerbose(!conf.Get<bool>("quiet"));
    19981973        fFTM.SetHexOutput(conf.Get<bool>("hex-out"));
    19991974        fFTM.SetDynamicOut(conf.Get<bool>("dynamic-out"));
    20001975
    2001 //        fFTM.SetDefaultSetup(conf.Get<string>("default-setup"));
    2002 
     1976        // ---------- Setup clock conditioner frequencies ----------
     1977        const vector<uint16_t> freq = conf.Get<vector<uint16_t>>("clock-conditioner.frequency");
     1978        if (freq.size()==0)
     1979            T::Warn("No frequencies for the clock-conditioner defined.");
     1980
     1981        T::Message("Defining clock conditioner frequencies");
     1982        for (vector<uint16_t>::const_iterator it=freq.begin();
     1983             it!=freq.end(); it++)
     1984        {
     1985            if (fClockCondSetup.count(*it)>0)
     1986            {
     1987                T::Error("clock-conditioner frequency defined twice.");
     1988                return 1;
     1989            }
     1990
     1991            if (!conf.HasDef("clock-conditioner.R0.",  *it) ||
     1992                !conf.HasDef("clock-conditioner.R1.",  *it) ||
     1993                !conf.HasDef("clock-conditioner.R8.",  *it) ||
     1994                !conf.HasDef("clock-conditioner.R9.",  *it) ||
     1995                !conf.HasDef("clock-conditioner.R11.", *it) ||
     1996                !conf.HasDef("clock-conditioner.R13.", *it) ||
     1997                !conf.HasDef("clock-conditioner.R14.", *it) ||
     1998                !conf.HasDef("clock-conditioner.R15.", *it))
     1999            {
     2000                T::Error("clock-conditioner values incomplete.");
     2001                return 1;
     2002            }
     2003
     2004            boost::array<uint64_t, 8> &arr = fClockCondSetup[*it];
     2005
     2006            arr[0] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R0.",  *it);
     2007            arr[1] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R1.",  *it);
     2008            arr[2] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R8.",  *it);
     2009            arr[3] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R9.",  *it);
     2010            arr[4] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R11.", *it);
     2011            arr[5] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R13.", *it);
     2012            arr[6] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R14.", *it);
     2013            arr[7] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R15.", *it);
     2014
     2015            ostringstream out;
     2016            out << " -> " << setw(4) << *it << "MHz:" << hex << setfill('0');
     2017            for (int i=0; i<8; i++)
     2018                out << " " << setw(8) << arr[i];
     2019            T::Message(out.str());
     2020        }
     2021
     2022        // ---------- FOR TESTING PURPOSE ---------
     2023
     2024        //        fFTM.SetDefaultSetup(conf.Get<string>("default-setup"));
    20032025        fConfigs["test"] = FTM::StaticData();
    20042026
     2027        // ---------- Setup connection endpoint ---------
     2028        SetEndpoint(conf.Get<string>("addr"));
    20052029
    20062030        return -1;
     
    21132137        ;
    21142138
    2115     po::options_description control("FTM control options");
     2139    po::options_description control("Control options");
    21162140    control.add_options()
    21172141        ("addr,a",        var<string>("localhost:5000"),  "Network address of FTM")
     
    21222146        ;
    21232147
     2148    po::options_description runtype("Run type configuration");
     2149    runtype.add_options()
     2150        ("clock-conditioner.frequency", vars<uint16_t>(),      "Frequencies for which to setup the clock-conditioner")
     2151        ("clock-conditioner.R0.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R0 (replace * by the defined frequency)")
     2152        ("clock-conditioner.R1.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R1 (replace * by the defined frequency)")
     2153        ("clock-conditioner.R8.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R8 (replace * by the defined frequency)")
     2154        ("clock-conditioner.R9.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R9 (replace * by the defined frequency)")
     2155        ("clock-conditioner.R11.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R11 (replace * by the defined frequency)")
     2156        ("clock-conditioner.R13.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R13 (replace * by the defined frequency)")
     2157        ("clock-conditioner.R14.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R14 (replace * by the defined frequency)")
     2158        ("clock-conditioner.R15.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R15 (replace * by the defined frequency)")
     2159        ;
     2160
    21242161    conf.AddEnv("dns", "DIM_DNS_NODE");
    21252162
    21262163    conf.AddOptions(config);
    21272164    conf.AddOptions(control);
     2165    conf.AddOptions(runtype);
    21282166}
    21292167
Note: See TracChangeset for help on using the changeset viewer.