Skip to content

Commit

Permalink
Merge pull request #100 from cescalara/zynq_reset_cmds
Browse files Browse the repository at this point in the history
Zynq reset cmds
  • Loading branch information
Francesca Capel authored Mar 9, 2020
2 parents ca30d58 + f6f9449 commit 1ddeb87
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 8 deletions.
26 changes: 21 additions & 5 deletions CPU/CPUsoftware/src/instrument/RunInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ int RunInstrument::DebugMode() {
std::cout << std::endl;
std::cout << "running checks of all subsystems..." <<std::endl;
std::cout << std::endl;


/*
std::cout << "USB" << std::endl;
int num_usb_storage = this->Usb.LookupUsbStorage();
std::cout << "there are " << num_usb_storage << " USB storage devices connected" << std::endl;
Expand Down Expand Up @@ -233,25 +234,32 @@ int RunInstrument::DebugMode() {
std::cout << "Zynq OFF " << std::endl;
this->Lvps.SwitchOff(LvpsManager::ZYNQ);
std::cout << "done!" << std::endl;

*/

/* check the available disk space */
/*
const char * cmd1 = "df -h";
std::string output1 = CpuTools::CommandToStr(cmd1);
std::cout << "Checking disk space: " << std::endl;
std::cout << output1 << std::endl;
clog << "info: " << logstream::info << "Checking disk space:" << std::endl;
clog << "info: " << logstream::info << output1 << std::endl;

*/

/* check CPU usage */
/*
const char * cmd2 = "top -d 5 -b -n1 | grep \"load average\" -A 15";
std::string output2 = CpuTools::CommandToStr(cmd2);
std::cout << "Checking CPU usage: " << std::endl;
std::cout << output2 << std::endl;
clog << "info: " << logstream::info << "Checking CPU usage:" << std::endl;
clog << "info: " << logstream::info << output2 << std::endl;
*/

/* test new DAC10 commands */
std::string path(USB_MOUNTPOINT_0);
this->Zynq.SetMatrixDac10(path, false);

std::cout << "debug tests completed, exiting the program" << std::endl;

return 0;
}

Expand Down Expand Up @@ -973,6 +981,14 @@ int RunInstrument::NightOperations() {
std::cout << "waiting for boot..." << std::endl;
this->CheckStatus();

/* setup the Zynq */
clog << "info: " << logstream::info << "setting up Zynq with DAC 10 tables and trigger mask" << std::endl;
std::string usb_str(USB_MOUNTPOINT_0);
{
std::unique_lock<std::mutex> lock(this->Zynq.m_zynq);
this->Zynq.Setup(usb_str);
}

/* set hidden pixels */
if (this->CmdLine->hide_pixel == true) {
{
Expand Down
79 changes: 79 additions & 0 deletions CPU/CPUsoftware/src/subsystems/ZynqManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,85 @@ int ZynqManager::Reboot() {

}

/**
* Set the ASIC DAC10 values from a text file provided by the USB.
* Adapted from C. Giammanco's script to use socket programming instead of netcat.
*/
int ZynqManager::SetMatrixDac10(std::string usb_mountpoint, bool debug) {

std::string dac10_filename;
std::vector<int> dac10_values;

dac10_filename = usb_mountpoint + ZYNQ_SETUP_SUBDIR + "/" + MATRIX_DAC_10;

/* read values */
if (debug == true) {

/* set all values to 200 for testing */
for (int i=0; i<N_PMT; i++) {
dac10_values.push_back(200);
}

}
else {

/* read values from file */
dac10_values = CpuTools::ReadMatrixDac10(dac10_filename);
if (dac10_values.size() != N_PMT) {
clog << "error: " << logstream::error << "Dac10 matrix has more than " << N_PMT << " values." << std::endl;
}

}

/* connect to telnet */
int sockfd = ConnectTelnet();
std::string cmd;

/* enter command loop */
int line = 0, pixel = 0, val = 0;
unsigned int index;
for (int asic=0; asic<N_ASIC; asic++) {

cmd = "slowctrl asic " + std::to_string(asic) + "\n";
Telnet(cmd, sockfd, true);

for (int board=0; board<N_ASIC; board++) {

line = 5 - board;
cmd = "slowctrl line " + std::to_string(line) + "\n";
Telnet(cmd, sockfd, true);

index = (asic * 6) + board;
cmd = "slowctrl pixel " + std::to_string(pixel) + "\n";
Telnet(cmd, sockfd, true);

val = dac10_values[index];
cmd = "slowctrl dac10 " + std::to_string(val) + "\n";
Telnet (cmd, sockfd, true);

}
}
cmd = "slowctrl apply\n";
Telnet(cmd, sockfd, true);

close(sockfd);

return 0;
}

/**
* Performs the necessary Zynq setup following a reboot.
*/
int ZynqManager::Setup(std::string setup_script_path) {

std::cout << "Trying to set DAC 10 values to 200...." << std::endl;
std::cout << "Using new ZynqManager::SetMatrixDac10()!" << std::endl;

this->SetMatrixDac10(setup_script_path, false);

return 0;
}


/**
* check the HV status
Expand Down
9 changes: 9 additions & 0 deletions CPU/CPUsoftware/src/subsystems/ZynqManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@

/* for use with HV interface functions */
#define N_EC 9
#define N_PMT 36
#define N_ASIC 6

/* time between consecutive telnet commands in mus */
#define SLEEP_TIME 500000

/* location of Zynq setup files */
#define ZYNQ_SETUP_SUBDIR "/automated_boot"
#define MATRIX_DAC_10 "dac10.txt"


/**
* class to handle the Zynq interface.
* commands and information are sent and received over telnet
Expand Down Expand Up @@ -143,6 +150,8 @@ class ZynqManager {
static std::string GetZynqVer();
int InstrumentClean();
int Reboot();
int SetMatrixDac10(std::string usb_mountpoint, bool debug);
int Setup(std::string setup_script_path);

private:

Expand Down
28 changes: 28 additions & 0 deletions CPU/CPUsoftware/src/tools/CpuTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,31 @@ uint32_t CpuTools::BuildCpuTimeStamp() {

return timestamp;
}

/**
* read the DAC10 matrix file into a vector
*/
std::vector<int> CpuTools::ReadMatrixDac10(std::string dac10_filename) {

std::vector<int> output;

std::ifstream matrix(dac10_filename, std::ios::in);
int number;

while(matrix >> number){

output.push_back(number);

}

if(output.size() != 36){

/* debug */
std::cout << "ERROR: file \"" << dac10_filename << "\" is out of format. Check number of elements." << std::endl;
return output;

}
matrix.close();

return output;
}
2 changes: 1 addition & 1 deletion CPU/CPUsoftware/src/tools/CpuTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class CpuTools {
static std::streampos FileSize(std::string file_path);
static uint32_t BuildCpuHeader(uint32_t type, uint32_t ver);
static uint32_t BuildCpuTimeStamp();

static std::vector<int> ReadMatrixDac10(std::string dac10_filename);

};

Expand Down
4 changes: 2 additions & 2 deletions minieuso_data_format/minieuso_data_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
* software definitions
*/

#define VERSION 8.5
#define VERSION_DATE_STRING "18/02/2020"
#define VERSION 8.8
#define VERSION_DATE_STRING "09/03/2020"

/*
* instrument definitions
Expand Down

0 comments on commit 1ddeb87

Please sign in to comment.