Skip to content
Snippets Groups Projects
Commit ea2a5af0 authored by Timon Heim's avatar Timon Heim
Browse files

Added reg read functionality to FE (not quite happy with that yet), added com...

Added reg read functionality to FE (not quite happy with that yet), added com check function before scan!
parent ad9feff4
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@
#include "AllChips.h"
#include "Rd53a.h"
#include "RawData.h"
bool rd53a_registred =
StdDict::registerFrontEnd("RD53A", [](){return std::unique_ptr<FrontEnd>(new Rd53a());});
......@@ -239,4 +240,47 @@ void Rd53a::disableCalCol(unsigned col) {
}
}
int Rd53a::checkCom() {
//std::cout << __PRETTY_FUNCTION__ << " : Checking communication for " << this->name << " by reading a register .." << std::endl;
uint32_t regAddr = 21;
uint32_t regValue = m_cfg[regAddr];
rdRegister(m_chipId, regAddr);
std::this_thread::sleep_for(std::chrono::milliseconds(10));
//std::cout << __PRETTY_FUNCTION__ << " : Trying to read data .." << std::endl;
RawData *data = m_rxcore->readData();
if (data != NULL) {
if (!(data->words == 2 || data->words == 4)) {
std::cout << "#ERROR# Received wrong number of words (" << data->words << ") for " << this->name << std::endl;
return 0;
}
std::pair<uint32_t, uint32_t> answer = decodeSingleRegRead(data->buf[0], data->buf[1]);
//std::cout << "Addr (" << answer.first << ") Value(" << answer.second << ")" << std::endl;
if (answer.first != regAddr || answer.second != regValue) {
std::cout << "#ERROR# Received data was not as expected:" << std::endl;
std::cout << " Received Addr: " << answer.first << " (expected " << regAddr <<")" << std::endl;
std::cout << " Received Value: " << answer.second << " (expected "<< regValue << ")" << std::endl;
return 0;
}
//std::cout << " ... success!" << std::endl;
return 1;
} else {
std::cout << "#ERROR# Did not receive any data for " << this->name << std::endl;
return 0;
}
}
std::pair<uint32_t, uint32_t> Rd53a::decodeSingleRegRead(uint32_t higher, uint32_t lower) {
if ((higher & 0x55000000) == 0x55000000) {
return std::make_pair((lower>>16)&0x3FF, lower&0xFFFF);
} else if ((higher & 0x99000000) == 0x99000000) {
return std::make_pair((higher>>10)&0x3FF, ((lower>>26)&0x3F)+((higher&0x3FF)<<6));
} else {
std::cout << "#ERROR# Could not decode reg read!" << std::endl;
return std::make_pair(999, 666);
}
return std::make_pair(999, 666);
}
......@@ -40,6 +40,8 @@ class Rd53a : public FrontEnd, public Rd53aCfg, public Rd53aCmd {
void configurePixels();
void configurePixels(std::vector<std::pair<unsigned, unsigned>> &pixels);
int checkCom() override;
void maskPixel(unsigned col, unsigned row) override {
this->setEn(col, row, 0);
this->setHitbus(col, row, 0);
......@@ -59,6 +61,7 @@ class Rd53a : public FrontEnd, public Rd53aCfg, public Rd53aCmd {
protected:
private:
std::pair<uint32_t, uint32_t> decodeSingleRegRead(uint32_t higher, uint32_t lower);
};
#endif
......@@ -35,6 +35,7 @@ class FrontEnd {
virtual void makeGlobal(){};
virtual void configure()=0;
virtual int checkCom() {return 0;}
/// Write to a register using a string name (most likely from json)
virtual void writeNamedRegister(std::string name, uint16_t value) = 0;
......
......@@ -358,6 +358,19 @@ int main(int argc, char *argv[]) {
// Wait for rx to sync with FE stream
// TODO Check RX sync
std::this_thread::sleep_for(std::chrono::microseconds(1000));
hwCtrl->flushBuffer();
for ( FrontEnd* fe : bookie.feList ) {
std::cout << "-> Checking com " << dynamic_cast<FrontEndCfg*>(fe)->getName() << std::endl;
// Select correct channel
hwCtrl->setCmdEnable(dynamic_cast<FrontEndCfg*>(fe)->getTxChannel());
hwCtrl->setRxEnable(dynamic_cast<FrontEndCfg*>(fe)->getRxChannel());
// Configure
if (fe->checkCom() != 1) {
std::cout << "#ERROR# Can't establish communication, aborting!" << std::endl;
return -1;
}
std::cout << "... success!" << std::endl;
}
// Enable all active channels
std::cout << "-> Enabling Tx channels: " << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment