Index: trunk/FACT++/src/ftmctrl.cc
===================================================================
--- trunk/FACT++/src/ftmctrl.cc	(revision 11337)
+++ trunk/FACT++/src/ftmctrl.cc	(revision 11338)
@@ -1457,6 +1457,4 @@
     }
 
-    //map<uint32_t, uint32_t> fClockConditionerMap;
-
     int SetClockFrequency(const EventImp &evt)
     {
@@ -1464,38 +1462,14 @@
             return T::kSM_FatalError;
 
-        const uint32_t freq = evt.GetUInt();
-
-        //map<uint32_t,uint32_t>::const_iterator = fClockConditionerMap.find(freq);
-
-        static const uint64_t R0hi  = 0x00030000;
-        static const uint64_t R8    = 0x10000908;
-        static const uint64_t R9    = 0xa0032a09;
-        static const uint64_t R11   = 0x0082000b;
-        static const uint64_t R13   = 0x020a000d;
-        static const uint64_t R14hi = 0x08300000;
-
-        static const uint64_t freq0800[8] = { R0hi|0xfe00, 0x00010101, R8, R9, R11, R13, R14hi|0x800e, 0x18017b0f };
-        static const uint64_t freq1000[8] = { R0hi|0xd000, 0x00010101, R8, R9, R11, R13, R14hi|0x400e, 0x1801450f };
-        static const uint64_t freq2000[8] = { R0hi|0x8000, 0x00010101, R8, R9, R11, R13, R14hi|0x280e, 0x1400fa0f };
-        static const uint64_t freq3000[8] = { R0hi|0x9000, 0x00030100, R8, R9, R11, R13, R14hi|0x400e, 0x0602a30f };
-        static const uint64_t freq4000[8] = { R0hi|0x4000, 0x00010101, R8, R9, R11, R13, R14hi|0x280e, 0x1400fa0f };
-        static const uint64_t freq5000[8] = { R0hi|0x8000, 0x00030200, R8, R9, R11, R13, R14hi|0x280e, 0x0802710f };
-
-        const uint64_t *reg = 0;
-
-        switch (freq)
-        {
-        case  800: reg = freq0800; break;
-        case 1000: reg = freq1000; break;
-        case 2000: reg = freq2000; break;
-        case 3000: reg = freq3000; break;
-        case 4000: reg = freq4000; break;
-        case 5000: reg = freq5000; break;
-        default:
+        const map<uint16_t,boost::array<uint64_t, 8>>::const_iterator it =
+            fClockCondSetup.find(evt.GetUInt());
+
+        if (it==fClockCondSetup.end())
+        {
             T::Warn("SetClockFrequency - Frequency not supported.");
             return T::GetCurrentState();
         }
 
-        if (!fFTM.SetClockRegister(reg))
+        if (!fFTM.SetClockRegister(it->second.data()))
             T::Warn("SetClockFrequency - Register values out of range.");
 
@@ -1915,5 +1889,5 @@
             ("");
 
-        T::AddEvent("SET_CLOCK_FREQUENCY", "I:1", FTM::kIdle)
+        T::AddEvent("SET_CLOCK_FREQUENCY", "S:1", FTM::kIdle)
             (boost::bind(&StateMachineFTM::SetClockFrequency, this, _1))
             ("");
@@ -1991,16 +1965,66 @@
     }
 
+    map<uint16_t, boost::array<uint64_t, 8>> fClockCondSetup;
+
     int EvalConfiguration(const Configuration &conf)
     {
-        SetEndpoint(conf.Get<string>("addr"));
-
+        // ---------- General setup ----------
         fFTM.SetVerbose(!conf.Get<bool>("quiet"));
         fFTM.SetHexOutput(conf.Get<bool>("hex-out"));
         fFTM.SetDynamicOut(conf.Get<bool>("dynamic-out"));
 
-//        fFTM.SetDefaultSetup(conf.Get<string>("default-setup"));
-
+        // ---------- Setup clock conditioner frequencies ----------
+        const vector<uint16_t> freq = conf.Get<vector<uint16_t>>("clock-conditioner.frequency");
+        if (freq.size()==0)
+            T::Warn("No frequencies for the clock-conditioner defined.");
+
+        T::Message("Defining clock conditioner frequencies");
+        for (vector<uint16_t>::const_iterator it=freq.begin();
+             it!=freq.end(); it++)
+        {
+            if (fClockCondSetup.count(*it)>0)
+            {
+                T::Error("clock-conditioner frequency defined twice.");
+                return 1;
+            }
+
+            if (!conf.HasDef("clock-conditioner.R0.",  *it) ||
+                !conf.HasDef("clock-conditioner.R1.",  *it) ||
+                !conf.HasDef("clock-conditioner.R8.",  *it) ||
+                !conf.HasDef("clock-conditioner.R9.",  *it) ||
+                !conf.HasDef("clock-conditioner.R11.", *it) ||
+                !conf.HasDef("clock-conditioner.R13.", *it) ||
+                !conf.HasDef("clock-conditioner.R14.", *it) ||
+                !conf.HasDef("clock-conditioner.R15.", *it))
+            {
+                T::Error("clock-conditioner values incomplete.");
+                return 1;
+            }
+
+            boost::array<uint64_t, 8> &arr = fClockCondSetup[*it];
+
+            arr[0] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R0.",  *it);
+            arr[1] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R1.",  *it);
+            arr[2] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R8.",  *it);
+            arr[3] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R9.",  *it);
+            arr[4] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R11.", *it);
+            arr[5] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R13.", *it);
+            arr[6] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R14.", *it);
+            arr[7] = conf.GetDef<Hex<uint64_t>>("clock-conditioner.R15.", *it);
+
+            ostringstream out;
+            out << " -> " << setw(4) << *it << "MHz:" << hex << setfill('0');
+            for (int i=0; i<8; i++)
+                out << " " << setw(8) << arr[i];
+            T::Message(out.str());
+        }
+
+        // ---------- FOR TESTING PURPOSE ---------
+
+        //        fFTM.SetDefaultSetup(conf.Get<string>("default-setup"));
         fConfigs["test"] = FTM::StaticData();
 
+        // ---------- Setup connection endpoint ---------
+        SetEndpoint(conf.Get<string>("addr"));
 
         return -1;
@@ -2113,5 +2137,5 @@
         ;
 
-    po::options_description control("FTM control options");
+    po::options_description control("Control options");
     control.add_options()
         ("addr,a",        var<string>("localhost:5000"),  "Network address of FTM")
@@ -2122,8 +2146,22 @@
         ;
 
+    po::options_description runtype("Run type configuration");
+    runtype.add_options()
+        ("clock-conditioner.frequency", vars<uint16_t>(),      "Frequencies for which to setup the clock-conditioner")
+        ("clock-conditioner.R0.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R0 (replace * by the defined frequency)")
+        ("clock-conditioner.R1.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R1 (replace * by the defined frequency)")
+        ("clock-conditioner.R8.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R8 (replace * by the defined frequency)")
+        ("clock-conditioner.R9.*",      var<Hex<uint64_t>>(),  "Clock-conditioner R9 (replace * by the defined frequency)")
+        ("clock-conditioner.R11.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R11 (replace * by the defined frequency)")
+        ("clock-conditioner.R13.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R13 (replace * by the defined frequency)")
+        ("clock-conditioner.R14.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R14 (replace * by the defined frequency)")
+        ("clock-conditioner.R15.*",     var<Hex<uint64_t>>(),  "Clock-conditioner R15 (replace * by the defined frequency)")
+        ;
+
     conf.AddEnv("dns", "DIM_DNS_NODE");
 
     conf.AddOptions(config);
     conf.AddOptions(control);
+    conf.AddOptions(runtype);
 }
 
