1818#include " Constants.h"
1919#include " I2c.h"
2020#include " Ttc.h"
21- #include " register_maps/Regmap_default_PLL2_40mhz_input_240mhz_output.h"
22- #include " register_maps/Regmap_PLL2_240mhz_input_240mhz_output.h"
21+ #include " register_maps/Si5345-RevD_local_pll1_zdb-Registers.h"
22+ #include " register_maps/Si5345-RevD_local_pll2_zdb-Registers.h"
23+ #include " register_maps/Si5345-RevD_ttc_pll1_zdb-Registers.h"
24+ #include " register_maps/Si5345-RevD_ttc_pll2_zdb-Registers.h"
2325#include " register_maps/Si5344-RevD-TFC_40-Registers.h"
2426
2527namespace AliceO2 {
@@ -45,21 +47,29 @@ void Ttc::configurePlls(uint32_t clock)
4547
4648 uint32_t chipAddress = 0x68 ; // fixed address
4749
50+ std::vector<std::pair<uint32_t , uint32_t >> registerMap1;
4851 std::vector<std::pair<uint32_t , uint32_t >> registerMap2;
4952 std::vector<std::pair<uint32_t , uint32_t >> registerMap3 = getSi5344RegisterMap ();
5053
5154 if (clock == Cru::CLOCK_LOCAL) {
52- registerMap2 = getLocalClockRegisterMap ();
55+ registerMap1 = getLocalClockPll1RegisterMap ();
56+ registerMap2 = getLocalClockPll2RegisterMap ();
5357 } else {
58+ setRefGen (0 );
5459 setRefGen (1 );
55- registerMap2 = getTtcClockRegisterMap ();
60+ registerMap1 = getTtcClockPll1RegisterMap ();
61+ registerMap2 = getTtcClockPll1RegisterMap ();
5662 }
5763
64+ I2c p1 = I2c (Cru::Registers::SI5345_1.address , chipAddress, mPdaBar , registerMap1);
5865 I2c p2 = I2c (Cru::Registers::SI5345_2.address , chipAddress, mPdaBar , registerMap2);
5966 I2c p3 = I2c (Cru::Registers::SI5344.address , chipAddress, mPdaBar , registerMap3);
6067
68+ p1.configurePll ();
6169 p2.configurePll ();
6270 p3.configurePll ();
71+
72+ std::this_thread::sleep_for (std::chrono::seconds (2 ));
6373}
6474
6575void Ttc::setRefGen (uint32_t refGenId, int frequency)
@@ -95,15 +105,45 @@ void Ttc::resetFpll()
95105 mPdaBar ->modifyRegister (Cru::Registers::CLOCK_CONTROL.index , 24 , 1 , 0x0 );
96106}
97107
98- void Ttc::configurePonTx (uint32_t onuAddress)
108+ bool Ttc::configurePonTx (uint32_t onuAddress)
99109{
110+ // Disable automatic phase scan
111+ mPdaBar ->writeRegister (Cru::Registers::CLOCK_PLL_CONTROL_ONU.index , 0x1 );
100112
101- Cru::fpllref0 (mPdaBar , Cru::Registers::CLOCK_ONU_FPLL.address , 0x1 );
102- Cru::fpllcal0 (mPdaBar , Cru::Registers::CLOCK_ONU_FPLL.address , false );
113+ // Perform phase scan manually
114+ int count = 0 ;
115+ bool lowSeen = false ;
116+ int minimumSteps = 22 ;
117+ uint32_t onuStatus;
118+ int i;
119+ for (i=0 ; i<256 ; i++) {
120+ mPdaBar ->writeRegister (Cru::Registers::CLOCK_PLL_CONTROL_ONU.index , 0x00300000 );
121+ std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
122+ mPdaBar ->writeRegister (Cru::Registers::CLOCK_PLL_CONTROL_ONU.index , 0x00200000 );
123+ std::this_thread::sleep_for (std::chrono::milliseconds (10 ));
124+ onuStatus = mPdaBar ->readRegister ((Cru::Registers::ONU_USER_LOGIC.address + 0xC )/4 );
125+ if (onuStatus == 0xff || onuStatus == 0x7f ) {
126+ count++;
127+ } else if (onuStatus == 0xf5 || onuStatus == 0xfd ) {
128+ count = 0 ;
129+ lowSeen = true ;
130+ } else {
131+ count = 0 ;
132+ }
103133
104- mPdaBar ->writeRegister (Cru::Registers::CLOCK_PLL_CONTROL_ONU.index , 0x1 );
134+ if (i > minimumSteps && lowSeen && count==1 ) {
135+ break ;
136+ }
137+ }
138+
139+ if (i==256 ) {
140+ return false ;
141+ }
142+
143+ // Assign ONU address
105144 mPdaBar ->modifyRegister (Cru::Registers::ONU_USER_LOGIC.index , 1 , 8 , onuAddress);
106145
146+ return true ;
107147 // TODO: Show calibration status..
108148}
109149
@@ -113,12 +153,18 @@ void Ttc::calibrateTtc()
113153 uint32_t sel0 = mPdaBar ->readRegister ((Cru::Registers::PON_WRAPPER_PLL.address + 0x044c )/4 );
114154 mPdaBar ->writeRegister ((Cru::Registers::PON_WRAPPER_PLL.address + 0x0448 )/4 , sel0);
115155
156+ // Calibrate PON RX
157+ Cru::rxcal0 (mPdaBar , Cru::Registers::PON_WRAPPER_TX.address );
158+
159+ // Calibrate fPLL
160+ Cru::fpllref0 (mPdaBar , Cru::Registers::CLOCK_ONU_FPLL.address , 1 ); // selecte refclk 1
161+ Cru::fpllcal0 (mPdaBar , Cru::Registers::CLOCK_ONU_FPLL.address , false );
162+
116163 // Calibrate ATX PLL
117164 Cru::atxcal0 (mPdaBar , Cru::Registers::PON_WRAPPER_PLL.address );
118165
119- // Calibrate PON TX/RX
166+ // Calibrate PON TX
120167 Cru::txcal0 (mPdaBar , Cru::Registers::PON_WRAPPER_TX.address );
121- Cru::rxcal0 (mPdaBar , Cru::Registers::PON_WRAPPER_TX.address );
122168
123169 std::this_thread::sleep_for (std::chrono::seconds (2 ));
124170}
@@ -143,46 +189,7 @@ uint32_t Ttc::getPllClock()
143189}
144190
145191// Currently unused by RoC
146- /* void Ttc::fpllref(uint32_t refClock, uint32_t baseAddress) //baseAddress = 0
147- {
148- if (baseAddress == 0){
149- int prevWrapper = -1;
150- int prevBank = -1;
151- for (auto const& link: mLinkList) {
152- if ((prevWrapper != link.wrapper) || (prevBank != link.bank)) {
153- Cru::fpllref0(mPdaBar, getBankPllRegisterAddress(link.wrapper, link.bank), refClock);
154- prevWrapper = link.wrapper;
155- prevBank = link.bank;
156- }
157- }
158- } else
159- Cru::fpllref0(mPdaBar, baseAddress, refClock);
160- }
161-
162- void Ttc::fpllcal(uint32_t baseAddress, bool configCompensation) //baseAddress = 0, configCompensation = true
163- {
164- if (baseAddress == 0){
165- int prevWrapper = -1;
166- int prevBank = -1;
167- for (auto const& link: mLinkList) {
168- if ((prevWrapper != link.wrapper) || (prevBank!= link.bank)) {
169- Cru::fpllcal0(mPdaBar, getBankPllRegisterAddress(link.wrapper, link.bank), configCompensation);
170- prevWrapper = link.wrapper;
171- prevBank = link.bank;
172- }
173- }
174- } else
175- Cru::fpllcal0(mPdaBar, baseAddress, configCompensation);
176- }
177-
178- uint32_t Ttc::getBankPllRegisterAddress(int wrapper, int bank)
179- {
180- return Cru::getWrapperBaseAddress(wrapper) +
181- Cru::Registers::GBT_WRAPPER_BANK_OFFSET.address * (bank + 1) +
182- Cru::Registers::GBT_BANK_FPLL.address;
183- }
184-
185- void Ttc::atxref(uint32_t refClock)
192+ /* void Ttc::atxref(uint32_t refClock)
186193{
187194 //Was not used... (just for info purposes)
188195 //uint32_t reg112 = readRegister(getAtxPllRegisterAddress(0, 0x112)/4); //get in gbt for now
0 commit comments