fix for storagecell bitwise start

This commit is contained in:
maliakal_d 2021-07-30 15:51:23 +02:00
parent c989be1e17
commit 6f81741931
2 changed files with 81 additions and 44 deletions

View File

@ -783,6 +783,7 @@ int selectStoragecellStart(int pos) {
uint32_t mask = DAQ_STRG_CELL_SLCT_MSK; uint32_t mask = DAQ_STRG_CELL_SLCT_MSK;
int offset = DAQ_STRG_CELL_SLCT_OFST; int offset = DAQ_STRG_CELL_SLCT_OFST;
if (getChipVersion() == 11) { if (getChipVersion() == 11) {
// set the bit
value = 1 << pos; value = 1 << pos;
addr = CONFIG_V11_REG; addr = CONFIG_V11_REG;
mask = CONFIG_V11_STRG_CLL_MSK; mask = CONFIG_V11_STRG_CLL_MSK;
@ -793,7 +794,18 @@ int selectStoragecellStart(int pos) {
bus_w(addr, bus_r(addr) & ~mask); bus_w(addr, bus_r(addr) & ~mask);
bus_w(addr, bus_r(addr) | ((value << offset) & mask)); bus_w(addr, bus_r(addr) | ((value << offset) & mask));
} }
return ((bus_r(addr) & mask) >> offset); int retval = ((bus_r(addr) & mask) >> offset);
if (getChipVersion() == 11) {
// get which bit
int max = getMaxStoragecellStart();
for (int i = 0; i != max + 1; ++i) {
if (retval & (1 << i)) {
return i;
}
}
}
// chip v1.0
return retval;
} }
int getMaxStoragecellStart() { int getMaxStoragecellStart() {

View File

@ -288,6 +288,8 @@ TEST_CASE("storagecells", "[.cmd]") {
CmdProxy proxy(&det); CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash(); auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) { if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash()*10 == 10) {
auto prev_val = det.getNumberOfAdditionalStorageCells().tsquash( auto prev_val = det.getNumberOfAdditionalStorageCells().tsquash(
"inconsistent #additional storage cells to test"); "inconsistent #additional storage cells to test");
{ {
@ -312,6 +314,12 @@ TEST_CASE("storagecells", "[.cmd]") {
} }
REQUIRE_THROWS(proxy.Call("storagecells", {"16"}, -1, PUT)); REQUIRE_THROWS(proxy.Call("storagecells", {"16"}, -1, PUT));
det.setNumberOfAdditionalStorageCells(prev_val); det.setNumberOfAdditionalStorageCells(prev_val);
}
// chip version 1.1
else {
// cannot set number of addl. storage cells
REQUIRE_THROWS(proxy.Call("storagecells", {"1"}, -1, PUT));
}
} else { } else {
REQUIRE_THROWS(proxy.Call("storagecells", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("storagecells", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("storagecells", {"0"}, -1, PUT)); REQUIRE_THROWS(proxy.Call("storagecells", {"0"}, -1, PUT));
@ -329,11 +337,20 @@ TEST_CASE("storagecell_start", "[.cmd]") {
proxy.Call("storagecell_start", {"1"}, -1, PUT, oss); proxy.Call("storagecell_start", {"1"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 1\n"); REQUIRE(oss.str() == "storagecell_start 1\n");
} }
{ // chip version 1.0
if (det.getChipVersion().squash()*10 == 10) {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("storagecell_start", {"15"}, -1, PUT, oss); proxy.Call("storagecell_start", {"15"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 15\n"); REQUIRE(oss.str() == "storagecell_start 15\n");
} }
// chip version 1.1
else {
// max is 3
REQUIRE_THROWS(proxy.Call("storagecell_start", {"15"}, -1, PUT));
std::ostringstream oss;
proxy.Call("storagecell_start", {"3"}, -1, PUT, oss);
REQUIRE(oss.str() == "storagecell_start 3\n");
}
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("storagecell_start", {"0"}, -1, PUT, oss); proxy.Call("storagecell_start", {"0"}, -1, PUT, oss);
@ -359,6 +376,8 @@ TEST_CASE("storagecell_delay", "[.cmd]") {
CmdProxy proxy(&det); CmdProxy proxy(&det);
auto det_type = det.getDetectorType().squash(); auto det_type = det.getDetectorType().squash();
if (det_type == defs::JUNGFRAU) { if (det_type == defs::JUNGFRAU) {
// chip version 1.0
if (det.getChipVersion().squash()*10 == 10) {
auto prev_val = det.getStorageCellDelay(); auto prev_val = det.getStorageCellDelay();
{ {
std::ostringstream oss; std::ostringstream oss;
@ -379,6 +398,12 @@ TEST_CASE("storagecell_delay", "[.cmd]") {
for (int i = 0; i != det.size(); ++i) { for (int i = 0; i != det.size(); ++i) {
det.setStorageCellDelay(prev_val[i], {i}); det.setStorageCellDelay(prev_val[i], {i});
} }
}
// chip version 1.1
else {
// cannot set storage cell delay
REQUIRE_THROWS(proxy.Call("storagecell_delay", {"1.62ms"}, -1, PUT));
}
} else { } else {
REQUIRE_THROWS(proxy.Call("storagecell_delay", {}, -1, GET)); REQUIRE_THROWS(proxy.Call("storagecell_delay", {}, -1, GET));
REQUIRE_THROWS(proxy.Call("storagecell_delay", {"0"}, -1, PUT)); REQUIRE_THROWS(proxy.Call("storagecell_delay", {"0"}, -1, PUT));