mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-13 08:30:04 +01:00
changed BitPosition to BitAddress
This commit is contained in:
@@ -28,7 +28,7 @@ from .defines import *
|
||||
IpAddr = _slsdet.IpAddr
|
||||
MacAddr = _slsdet.MacAddr
|
||||
RegisterAddress = _slsdet.RegisterAddress
|
||||
BitPosition = _slsdet.BitPosition
|
||||
BitAddress = _slsdet.BitAddress
|
||||
RegisterValue = _slsdet.RegisterValue
|
||||
scanParameters = _slsdet.scanParameters
|
||||
currentSrcParameters = _slsdet.currentSrcParameters
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
from ._slsdet import CppDetectorApi
|
||||
from ._slsdet import slsDetectorDefs
|
||||
from ._slsdet import IpAddr, MacAddr
|
||||
from ._slsdet import RegisterAddress, RegisterValue, BitPosition
|
||||
from ._slsdet import RegisterAddress, RegisterValue, BitAddress
|
||||
|
||||
runStatus = slsDetectorDefs.runStatus
|
||||
timingMode = slsDetectorDefs.timingMode
|
||||
|
||||
@@ -144,8 +144,8 @@ def make_mac(arg):
|
||||
def make_register_address(arg):
|
||||
return _make(arg, _slsdet.RegisterAddress)
|
||||
|
||||
def make_bit_position(arg):
|
||||
return _make(arg, _slsdet.BitPosition)
|
||||
def make_bit_address(arg):
|
||||
return _make(arg, _slsdet.BitAddress)
|
||||
|
||||
def make_register_value(arg):
|
||||
return _make(arg, _slsdet.RegisterValue)
|
||||
@@ -162,8 +162,8 @@ def _make(arg, transform):
|
||||
elif isinstance(arg, list):
|
||||
return [_make(a, transform) for a in arg]
|
||||
elif isinstance(arg, tuple):
|
||||
# special case for BitPosition
|
||||
if transform is _slsdet.BitPosition:
|
||||
# special case for BitAddress
|
||||
if transform is _slsdet.BitAddress:
|
||||
addr, bit = arg
|
||||
if isinstance(addr, int):
|
||||
addr = _slsdet.RegisterAddress(addr)
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// SPDX-License-Identifier: LGPL-3.0-or-other
|
||||
// Copyright (C) 2021 Contributors to the SLS Detector Package
|
||||
/*
|
||||
This file contains Python bindings for the RegisterAddr, BitPosition and RegisterValue
|
||||
classes.
|
||||
This file contains Python bindings for the RegisterAddr, BitAddress and
|
||||
RegisterValue classes.
|
||||
*/
|
||||
#include "py_headers.h"
|
||||
#include "sls/bit_utils.h"
|
||||
|
||||
namespace py = pybind11;
|
||||
|
||||
using sls::BitAddress;
|
||||
using sls::RegisterAddress;
|
||||
using sls::RegisterValue;
|
||||
using sls::BitPosition;
|
||||
|
||||
void init_bit(py::module &m) {
|
||||
|
||||
@@ -26,15 +26,15 @@ void init_bit(py::module &m) {
|
||||
.def(py::self == py::self)
|
||||
.def(py::self != py::self);
|
||||
|
||||
py::class_<BitPosition>(m, "BitPosition")
|
||||
py::class_<BitAddress>(m, "BitAddress")
|
||||
.def(py::init())
|
||||
.def(py::init<RegisterAddress, int>())
|
||||
.def("__repr__", &BitPosition::str)
|
||||
.def("str", &BitPosition::str)
|
||||
.def("address", &BitPosition::address)
|
||||
.def("bitPosition", &BitPosition::bitPosition)
|
||||
.def("setAddress", &BitPosition::setAddress)
|
||||
.def("setBitPosition", &BitPosition::setBitPosition)
|
||||
.def("__repr__", &BitAddress::str)
|
||||
.def("str", &BitAddress::str)
|
||||
.def("address", &BitAddress::address)
|
||||
.def("bitPosition", &BitAddress::bitPosition)
|
||||
.def("setAddress", &BitAddress::setAddress)
|
||||
.def("setBitPosition", &BitAddress::setBitPosition)
|
||||
.def(py::self == py::self)
|
||||
.def(py::self != py::self);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#include <chrono>
|
||||
namespace py = pybind11;
|
||||
void init_det(py::module &m) {
|
||||
using sls::BitPosition;
|
||||
using sls::BitAddress;
|
||||
using sls::defs;
|
||||
using sls::Detector;
|
||||
using sls::ns;
|
||||
@@ -1842,34 +1842,34 @@ void init_det(py::module &m) {
|
||||
Detector::getBitDefinitionsCount);
|
||||
CppDetectorApi.def(
|
||||
"setBitDefinition",
|
||||
(void (Detector::*)(const std::string &, sls::BitPosition)) &
|
||||
Detector::setBitDefinition,
|
||||
(void (Detector::*)(const std::string &,
|
||||
sls::BitAddress))&Detector::setBitDefinition,
|
||||
py::arg(), py::arg());
|
||||
CppDetectorApi.def("hasBitDefinition",
|
||||
(bool (Detector::*)(const std::string &) const) &
|
||||
Detector::hasBitDefinition,
|
||||
py::arg());
|
||||
CppDetectorApi.def("hasBitDefinition",
|
||||
(bool (Detector::*)(sls::BitPosition) const) &
|
||||
(bool (Detector::*)(sls::BitAddress) const) &
|
||||
Detector::hasBitDefinition,
|
||||
py::arg());
|
||||
CppDetectorApi.def(
|
||||
"getBitDefinition",
|
||||
(sls::BitPosition(Detector::*)(const std::string &) const) &
|
||||
(sls::BitAddress (Detector::*)(const std::string &) const) &
|
||||
Detector::getBitDefinition,
|
||||
py::arg());
|
||||
CppDetectorApi.def("getBitDefinition",
|
||||
(std::string(Detector::*)(sls::BitPosition) const) &
|
||||
(std::string (Detector::*)(sls::BitAddress) const) &
|
||||
Detector::getBitDefinition,
|
||||
py::arg());
|
||||
CppDetectorApi.def("clearBitDefinitions",
|
||||
(void (Detector::*)()) & Detector::clearBitDefinitions);
|
||||
CppDetectorApi.def(
|
||||
"setBitDefinitions",
|
||||
(void (Detector::*)(const std::map<std::string, BitPosition> &)) &
|
||||
Detector::setBitDefinitions,
|
||||
(void (Detector::*)(const std::map<std::string, BitAddress>
|
||||
&))&Detector::setBitDefinitions,
|
||||
py::arg());
|
||||
CppDetectorApi.def("getBitDefinitions", (std::map<std::string, BitPosition>(
|
||||
CppDetectorApi.def("getBitDefinitions", (std::map<std::string, BitAddress> (
|
||||
Detector::*)() const) &
|
||||
Detector::getBitDefinitions);
|
||||
CppDetectorApi.def("configureTransceiver",
|
||||
@@ -2066,21 +2066,19 @@ void init_det(py::module &m) {
|
||||
(void (Detector::*)(uint32_t, uint32_t, bool, sls::Positions)) &
|
||||
Detector::writeRegister,
|
||||
py::arg(), py::arg(), py::arg() = false, py::arg() = Positions{});
|
||||
CppDetectorApi.def(
|
||||
"setBit",
|
||||
(void (Detector::*)(sls::BitPosition, bool, sls::Positions)) &
|
||||
Detector::setBit,
|
||||
py::arg(), py::arg() = false, py::arg() = Positions{});
|
||||
CppDetectorApi.def("setBit",
|
||||
(void (Detector::*)(sls::BitAddress, bool,
|
||||
sls::Positions))&Detector::setBit,
|
||||
py::arg(), py::arg() = false, py::arg() = Positions{});
|
||||
CppDetectorApi.def(
|
||||
"setBit",
|
||||
(void (Detector::*)(uint32_t, int, bool, sls::Positions)) &
|
||||
Detector::setBit,
|
||||
py::arg(), py::arg(), py::arg() = false, py::arg() = Positions{});
|
||||
CppDetectorApi.def(
|
||||
"clearBit",
|
||||
(void (Detector::*)(sls::BitPosition, bool, sls::Positions)) &
|
||||
Detector::clearBit,
|
||||
py::arg(), py::arg() = false, py::arg() = Positions{});
|
||||
CppDetectorApi.def("clearBit",
|
||||
(void (Detector::*)(sls::BitAddress, bool,
|
||||
sls::Positions))&Detector::clearBit,
|
||||
py::arg(), py::arg() = false, py::arg() = Positions{});
|
||||
CppDetectorApi.def(
|
||||
"clearBit",
|
||||
(void (Detector::*)(uint32_t, int, bool, sls::Positions)) &
|
||||
@@ -2088,7 +2086,7 @@ void init_det(py::module &m) {
|
||||
py::arg(), py::arg(), py::arg() = false, py::arg() = Positions{});
|
||||
CppDetectorApi.def(
|
||||
"getBit",
|
||||
(Result<int>(Detector::*)(sls::BitPosition, sls::Positions) const) &
|
||||
(Result<int> (Detector::*)(sls::BitAddress, sls::Positions) const) &
|
||||
Detector::getBit,
|
||||
py::arg(), py::arg() = Positions{});
|
||||
CppDetectorApi.def(
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
#include <chrono>
|
||||
namespace py = pybind11;
|
||||
void init_det(py::module &m) {
|
||||
using sls::BitAddress;
|
||||
using sls::defs;
|
||||
using sls::Detector;
|
||||
using sls::ns;
|
||||
using sls::Positions;
|
||||
using sls::Result;
|
||||
using sls::RegisterAddress;
|
||||
using sls::RegisterValue;
|
||||
using sls::BitPosition;
|
||||
using sls::Result;
|
||||
|
||||
m.def("freeSharedMemory", (void (*)(const int, const int)) &sls::freeSharedMemory, py::arg() = 0, py::arg() = -1);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ Testing functions from utils.py
|
||||
|
||||
import pytest
|
||||
from slsdet.utils import *
|
||||
from slsdet import IpAddr, MacAddr, DurationWrapper, RegisterAddress, RegisterValue, BitPosition
|
||||
from slsdet import IpAddr, MacAddr, DurationWrapper, RegisterAddress, RegisterValue, BitAddress
|
||||
import datetime as dt
|
||||
import pathlib
|
||||
from pathlib import Path
|
||||
@@ -251,8 +251,8 @@ def test_make_bit_pos_from_dict():
|
||||
}
|
||||
res = make_bit_position(arg)
|
||||
assert res == {
|
||||
0: BitPosition(RegisterAddress("0x0"), 2),
|
||||
1: BitPosition(RegisterAddress("0x305"), 23)
|
||||
0: BitAddress(RegisterAddress("0x0"), 2),
|
||||
1: BitAddress(RegisterAddress("0x305"), 23)
|
||||
}
|
||||
assert res[0].str() == "[0x0, 2]"
|
||||
assert res[1].str() == "[0x305, 23]"
|
||||
@@ -263,13 +263,13 @@ def test_make_bit_pos_from_list():
|
||||
(RegisterAddress(0), 2),
|
||||
(RegisterAddress(0x305), 23)
|
||||
]
|
||||
expected = [BitPosition(*a) for a in arg]
|
||||
expected = [BitAddress(*a) for a in arg]
|
||||
assert make_bit_position(arg) == expected
|
||||
|
||||
|
||||
def test_make_bit_pos_from_tuple():
|
||||
arg = (RegisterAddress(0x305), 23)
|
||||
expected = BitPosition(*arg)
|
||||
expected = BitAddress(*arg)
|
||||
assert make_bit_position(arg) == expected
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class Caller {
|
||||
std::string bitoperations(int action);
|
||||
RegisterAddress parseAddress(const std::string &saddr) const;
|
||||
bool parseValidate();
|
||||
BitPosition parseBitPosition() const;
|
||||
BitAddress parseBitAddress() const;
|
||||
|
||||
FunctionMap functions{
|
||||
{"list", &Caller::list},
|
||||
|
||||
@@ -1870,28 +1870,28 @@ class Detector {
|
||||
int getBitDefinitionsCount() const;
|
||||
|
||||
/** [CTB][Xilinx CTB] */
|
||||
void setBitDefinition(const std::string &name, BitPosition bitPos);
|
||||
void setBitDefinition(const std::string &name, BitAddress addr);
|
||||
|
||||
/** [CTB][Xilinx CTB] */
|
||||
bool hasBitDefinition(const std::string &name) const;
|
||||
|
||||
/** [CTB][Xilinx CTB] */
|
||||
bool hasBitDefinition(BitPosition bitPos) const;
|
||||
bool hasBitDefinition(BitAddress addr) const;
|
||||
|
||||
/** [CTB][Xilinx CTB] returns bit position and address */
|
||||
BitPosition getBitDefinition(const std::string &name) const;
|
||||
BitAddress getBitDefinition(const std::string &name) const;
|
||||
|
||||
/** [CTB][Xilinx CTB] */
|
||||
std::string getBitDefinition(BitPosition bitPos) const;
|
||||
std::string getBitDefinition(BitAddress addr) const;
|
||||
|
||||
/** [CTB][Xilinx CTB] */
|
||||
void clearBitDefinitions();
|
||||
|
||||
/** [CTB][Xilinx CTB] */
|
||||
void setBitDefinitions(const std::map<std::string, BitPosition> &list);
|
||||
void setBitDefinitions(const std::map<std::string, BitAddress> &list);
|
||||
|
||||
/** [CTB][Xilinx CTB] */
|
||||
std::map<std::string, BitPosition> getBitDefinitions() const;
|
||||
std::map<std::string, BitAddress> getBitDefinitions() const;
|
||||
|
||||
///@}
|
||||
|
||||
@@ -2130,21 +2130,20 @@ class Detector {
|
||||
/** Advanced user Function! \n
|
||||
* [Ctb][Xilinx_Ctb] Bit position can be picked up from a custom name using
|
||||
* getBitDefinition that was set up prior using setBitDefinition. */
|
||||
void setBit(BitPosition bitPos, bool validate = false, Positions pos = {});
|
||||
void setBit(BitAddress addr, bool validate = false, Positions pos = {});
|
||||
|
||||
/** Advanced user Function! */
|
||||
[[deprecated("Use the overload taking BitPosition instead of uint32_t and "
|
||||
[[deprecated("Use the overload taking BitAddress instead of uint32_t and "
|
||||
"int")]] void
|
||||
setBit(uint32_t addr, int bitnr, bool validate = false, Positions pos = {});
|
||||
|
||||
/** Advanced user Function! \n
|
||||
* [Ctb][Xilinx_Ctb] Bit position can be picked up from a custom name using
|
||||
* getBitDefinition that was set up prior using setBitDefinition. */
|
||||
void clearBit(BitPosition bitPos, bool validate = false,
|
||||
Positions pos = {});
|
||||
void clearBit(BitAddress addr, bool validate = false, Positions pos = {});
|
||||
|
||||
/** Advanced user Function! */
|
||||
[[deprecated("Use the overload taking BitPosition instead of uint32_t and "
|
||||
[[deprecated("Use the overload taking BitAddress instead of uint32_t and "
|
||||
"int")]] void
|
||||
clearBit(uint32_t addr, int bitnr, bool validate = false,
|
||||
Positions pos = {});
|
||||
@@ -2152,10 +2151,10 @@ class Detector {
|
||||
/** Advanced user Function! \n
|
||||
* [Ctb][Xilinx_Ctb] Bit position can be picked up from a custom name using
|
||||
* getBitDefinition that was set up prior using setBitDefinition. */
|
||||
Result<int> getBit(BitPosition bitPos, Positions pos = {}) const;
|
||||
Result<int> getBit(BitAddress addr, Positions pos = {}) const;
|
||||
|
||||
/** Advanced user Function! */
|
||||
[[deprecated("Use the overload taking BitPosition instead of uint32_t and "
|
||||
[[deprecated("Use the overload taking BitAddress instead of uint32_t and "
|
||||
"int")]] Result<int>
|
||||
getBit(uint32_t addr, int bitnr, Positions pos = {}) const;
|
||||
|
||||
|
||||
@@ -403,7 +403,7 @@ class Caller {
|
||||
std::string bitoperations(int action);
|
||||
RegisterAddress parseAddress(const std::string &saddr) const;
|
||||
bool parseValidate();
|
||||
BitPosition parseBitPosition() const;
|
||||
BitAddress parseBitAddress() const;
|
||||
|
||||
FunctionMap functions{
|
||||
{"list", &Caller::list},
|
||||
|
||||
@@ -1538,7 +1538,7 @@ std::string Caller::define(int action) {
|
||||
// get name from position and address
|
||||
else if (args.size() == 3) {
|
||||
auto pos =
|
||||
BitPosition(parseAddress(args[1]), StringTo<int>(args[2]));
|
||||
BitAddress(parseAddress(args[1]), StringTo<int>(args[2]));
|
||||
try {
|
||||
auto t = det->getBitDefinition(pos);
|
||||
os << t << '\n';
|
||||
@@ -1565,7 +1565,7 @@ std::string Caller::define(int action) {
|
||||
throw RuntimeError("Bit position must be an integer value.");
|
||||
}
|
||||
auto pos =
|
||||
BitPosition(parseAddress(args[2]), StringTo<int>(args[3]));
|
||||
BitAddress(parseAddress(args[2]), StringTo<int>(args[3]));
|
||||
det->setBitDefinition(args[1], pos);
|
||||
os << ToString(args) << '\n';
|
||||
}
|
||||
@@ -1709,20 +1709,20 @@ std::string Caller::bitoperations(int action) {
|
||||
}
|
||||
|
||||
auto validate = parseValidate();
|
||||
auto bitPosition = parseBitPosition();
|
||||
auto BitAddress = parseBitAddress();
|
||||
if (action == defs::GET_ACTION) {
|
||||
if (cmd == "setbit" || cmd == "clearbit")
|
||||
throw RuntimeError("Cannot get");
|
||||
|
||||
auto t = det->getBit(bitPosition, std::vector<int>{det_id});
|
||||
auto t = det->getBit(BitAddress, std::vector<int>{det_id});
|
||||
os << OutString(t) << '\n';
|
||||
} else {
|
||||
if (cmd == "getbit")
|
||||
throw RuntimeError("Cannot put");
|
||||
if (cmd == "setbit")
|
||||
det->setBit(bitPosition, validate, std::vector<int>{det_id});
|
||||
det->setBit(BitAddress, validate, std::vector<int>{det_id});
|
||||
else if (cmd == "clearbit")
|
||||
det->clearBit(bitPosition, validate, std::vector<int>{det_id});
|
||||
det->clearBit(BitAddress, validate, std::vector<int>{det_id});
|
||||
else
|
||||
throw RuntimeError("Unknown command");
|
||||
os << ToString(args) << "\n";
|
||||
@@ -1773,7 +1773,7 @@ bool Caller::parseValidate() {
|
||||
return validate;
|
||||
}
|
||||
|
||||
BitPosition Caller::parseBitPosition() const {
|
||||
BitAddress Caller::parseBitAddress() const {
|
||||
int argsSize = args.size();
|
||||
std::string addr_or_bitname = args[0];
|
||||
|
||||
@@ -1793,8 +1793,8 @@ BitPosition Caller::parseBitPosition() const {
|
||||
// address and bit position
|
||||
else if (argsSize == 2) {
|
||||
std::string bit_pos = args[1];
|
||||
return BitPosition(parseAddress(addr_or_bitname),
|
||||
StringTo<int>(bit_pos));
|
||||
return BitAddress(parseAddress(addr_or_bitname),
|
||||
StringTo<int>(bit_pos));
|
||||
} else {
|
||||
throw RuntimeError("Command " + cmd +
|
||||
" expected (1-4) parameter/s but got " +
|
||||
|
||||
@@ -302,34 +302,33 @@ std::map<std::string, RegisterAddress> CtbConfig::getRegisterNames() const {
|
||||
|
||||
int CtbConfig::getBitNamesCount() const { return num_bits; }
|
||||
|
||||
void CtbConfig::setBitName(const std::string &name, BitPosition bitPos) {
|
||||
addEntry<BitDefinition, BitPosition>(name, bitPos, bits, num_bits, max_bits,
|
||||
"bit");
|
||||
void CtbConfig::setBitName(const std::string &name, BitAddress bitPos) {
|
||||
addEntry<BitDefinition, BitAddress>(name, bitPos, bits, num_bits, max_bits,
|
||||
"bit");
|
||||
}
|
||||
|
||||
bool CtbConfig::hasBitName(const std::string &name) const {
|
||||
return lookupEntryByName<BitDefinition, BitPosition>(name, bits, num_bits)
|
||||
return lookupEntryByName<BitDefinition, BitAddress>(name, bits, num_bits)
|
||||
.has_value();
|
||||
}
|
||||
|
||||
bool CtbConfig::hasBitPosition(BitPosition bitPos) const {
|
||||
return lookupEntryByValue<BitDefinition, BitPosition>(bitPos, bits,
|
||||
num_bits)
|
||||
bool CtbConfig::hasBitAddress(BitAddress bitPos) const {
|
||||
return lookupEntryByValue<BitDefinition, BitAddress>(bitPos, bits, num_bits)
|
||||
.has_value();
|
||||
}
|
||||
|
||||
BitPosition CtbConfig::getBitPosition(const std::string &name) const {
|
||||
BitAddress CtbConfig::getBitAddress(const std::string &name) const {
|
||||
auto val =
|
||||
lookupEntryByName<BitDefinition, BitPosition>(name, bits, num_bits);
|
||||
lookupEntryByName<BitDefinition, BitAddress>(name, bits, num_bits);
|
||||
if (!val.has_value()) {
|
||||
throw RuntimeError("No bit definition found for name: " + name);
|
||||
}
|
||||
return val.value();
|
||||
}
|
||||
|
||||
std::string CtbConfig::getBitName(BitPosition bitPos) const {
|
||||
std::string CtbConfig::getBitName(BitAddress bitPos) const {
|
||||
auto val =
|
||||
lookupEntryByValue<BitDefinition, BitPosition>(bitPos, bits, num_bits);
|
||||
lookupEntryByValue<BitDefinition, BitAddress>(bitPos, bits, num_bits);
|
||||
if (!val.has_value()) {
|
||||
throw RuntimeError("No bit definition found for bit position: " +
|
||||
bitPos.str());
|
||||
@@ -342,7 +341,7 @@ void CtbConfig::clearBitNames() {
|
||||
num_bits = 0;
|
||||
}
|
||||
|
||||
void CtbConfig::setBitNames(const std::map<std::string, BitPosition> &list) {
|
||||
void CtbConfig::setBitNames(const std::map<std::string, BitAddress> &list) {
|
||||
if (list.size() >= max_bits) {
|
||||
throw RuntimeError("Bit names need to be of size less than " +
|
||||
std::to_string(max_bits));
|
||||
@@ -353,8 +352,8 @@ void CtbConfig::setBitNames(const std::map<std::string, BitPosition> &list) {
|
||||
}
|
||||
}
|
||||
|
||||
std::map<std::string, BitPosition> CtbConfig::getBitNames() const {
|
||||
std::map<std::string, BitPosition> names;
|
||||
std::map<std::string, BitAddress> CtbConfig::getBitNames() const {
|
||||
std::map<std::string, BitAddress> names;
|
||||
for (size_t i = 0; i != num_bits; ++i)
|
||||
names[bits[i].name()] = bits[i].value();
|
||||
return names;
|
||||
|
||||
@@ -40,11 +40,11 @@ class RegisterDefinition {
|
||||
class BitDefinition {
|
||||
private:
|
||||
char name_[CTB_NAME_LENGTH]{};
|
||||
BitPosition bitPos_;
|
||||
BitAddress bitPos_;
|
||||
|
||||
public:
|
||||
BitDefinition() noexcept = default;
|
||||
BitDefinition(const std::string &name, BitPosition bitPos)
|
||||
BitDefinition(const std::string &name, BitAddress bitPos)
|
||||
: bitPos_(bitPos) {
|
||||
if (name.empty()) {
|
||||
throw sls::RuntimeError("Bit name cannot be empty.");
|
||||
@@ -53,8 +53,8 @@ class BitDefinition {
|
||||
}
|
||||
|
||||
std::string name() const noexcept { return name_; }
|
||||
BitPosition value() const noexcept { return bitPos_; }
|
||||
void setValue(BitPosition bitPos) noexcept { bitPos_ = bitPos; }
|
||||
BitAddress value() const noexcept { return bitPos_; }
|
||||
void setValue(BitAddress bitPos) noexcept { bitPos_ = bitPos; }
|
||||
};
|
||||
|
||||
class CtbConfig {
|
||||
@@ -222,14 +222,14 @@ class CtbConfig {
|
||||
std::map<std::string, RegisterAddress> getRegisterNames() const;
|
||||
|
||||
int getBitNamesCount() const;
|
||||
void setBitName(const std::string &name, BitPosition bitPos);
|
||||
void setBitName(const std::string &name, BitAddress bitPos);
|
||||
bool hasBitName(const std::string &name) const;
|
||||
bool hasBitPosition(BitPosition bitPos) const;
|
||||
BitPosition getBitPosition(const std::string &name) const;
|
||||
std::string getBitName(BitPosition bitPos) const;
|
||||
bool hasBitAddress(BitAddress bitPos) const;
|
||||
BitAddress getBitAddress(const std::string &name) const;
|
||||
std::string getBitName(BitAddress bitPos) const;
|
||||
void clearBitNames();
|
||||
void setBitNames(const std::map<std::string, BitPosition> &list);
|
||||
std::map<std::string, BitPosition> getBitNames() const;
|
||||
void setBitNames(const std::map<std::string, BitAddress> &list);
|
||||
std::map<std::string, BitAddress> getBitNames() const;
|
||||
};
|
||||
|
||||
} // namespace sls
|
||||
|
||||
@@ -2550,34 +2550,34 @@ int Detector::getBitDefinitionsCount() const {
|
||||
return pimpl->getBitDefinitionsCount();
|
||||
}
|
||||
|
||||
void Detector::setBitDefinition(const std::string &name, BitPosition bitPos) {
|
||||
pimpl->setBitDefinition(name, bitPos);
|
||||
void Detector::setBitDefinition(const std::string &name, BitAddress addr) {
|
||||
pimpl->setBitDefinition(name, addr);
|
||||
}
|
||||
|
||||
bool Detector::hasBitDefinition(const std::string &name) const {
|
||||
return pimpl->hasBitDefinition(name);
|
||||
}
|
||||
|
||||
bool Detector::hasBitDefinition(BitPosition bitPos) const {
|
||||
return pimpl->hasBitDefinition(bitPos);
|
||||
bool Detector::hasBitDefinition(BitAddress addr) const {
|
||||
return pimpl->hasBitDefinition(addr);
|
||||
}
|
||||
|
||||
BitPosition Detector::getBitDefinition(const std::string &name) const {
|
||||
BitAddress Detector::getBitDefinition(const std::string &name) const {
|
||||
return pimpl->getBitDefinition(name);
|
||||
}
|
||||
|
||||
std::string Detector::getBitDefinition(BitPosition bitPos) const {
|
||||
return pimpl->getBitDefinition(bitPos);
|
||||
std::string Detector::getBitDefinition(BitAddress addr) const {
|
||||
return pimpl->getBitDefinition(addr);
|
||||
}
|
||||
|
||||
void Detector::clearBitDefinitions() { pimpl->clearBitDefinitions(); }
|
||||
|
||||
void Detector::setBitDefinitions(
|
||||
const std::map<std::string, BitPosition> &list) {
|
||||
const std::map<std::string, BitAddress> &list) {
|
||||
pimpl->setBitDefinitions(list);
|
||||
}
|
||||
|
||||
std::map<std::string, BitPosition> Detector::getBitDefinitions() const {
|
||||
std::map<std::string, BitAddress> Detector::getBitDefinitions() const {
|
||||
return pimpl->getBitDefinitions();
|
||||
}
|
||||
|
||||
@@ -2821,19 +2821,19 @@ void Detector::writeRegister(RegisterAddress addr, RegisterValue val,
|
||||
pimpl->Parallel(&Module::writeRegister, pos, addr, val, validate);
|
||||
}
|
||||
|
||||
void Detector::setBit(BitPosition bitPos, bool validate, Positions pos) {
|
||||
pimpl->Parallel(&Module::setBit, pos, bitPos.address(),
|
||||
bitPos.bitPosition(), validate);
|
||||
void Detector::setBit(BitAddress addr, bool validate, Positions pos) {
|
||||
pimpl->Parallel(&Module::setBit, pos, addr.address(), addr.bitPosition(),
|
||||
validate);
|
||||
}
|
||||
|
||||
void Detector::clearBit(BitPosition bitPos, bool validate, Positions pos) {
|
||||
pimpl->Parallel(&Module::clearBit, pos, bitPos.address(),
|
||||
bitPos.bitPosition(), validate);
|
||||
void Detector::clearBit(BitAddress addr, bool validate, Positions pos) {
|
||||
pimpl->Parallel(&Module::clearBit, pos, addr.address(), addr.bitPosition(),
|
||||
validate);
|
||||
}
|
||||
|
||||
Result<int> Detector::getBit(BitPosition bitPos, Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getBit, pos, bitPos.address(),
|
||||
bitPos.bitPosition());
|
||||
Result<int> Detector::getBit(BitAddress addr, Positions pos) const {
|
||||
return pimpl->Parallel(&Module::getBit, pos, addr.address(),
|
||||
addr.bitPosition());
|
||||
}
|
||||
|
||||
void Detector::executeFirmwareTest(Positions pos) {
|
||||
|
||||
@@ -2122,7 +2122,7 @@ int DetectorImpl::getBitDefinitionsCount() const {
|
||||
}
|
||||
|
||||
void DetectorImpl::setBitDefinition(const std::string &name,
|
||||
BitPosition bitPos) {
|
||||
BitAddress bitPos) {
|
||||
if (!isChipTestBoard())
|
||||
throw RuntimeError("Bit Definitions only for CTB");
|
||||
ctb_shm()->setBitName(name, bitPos);
|
||||
@@ -2134,19 +2134,19 @@ bool DetectorImpl::hasBitDefinition(const std::string &name) const {
|
||||
return ctb_shm()->hasBitName(name);
|
||||
}
|
||||
|
||||
bool DetectorImpl::hasBitDefinition(BitPosition bitPos) const {
|
||||
bool DetectorImpl::hasBitDefinition(BitAddress bitPos) const {
|
||||
if (!isChipTestBoard())
|
||||
throw RuntimeError("Bit Definitions only for CTB");
|
||||
return ctb_shm()->hasBitPosition(bitPos);
|
||||
return ctb_shm()->hasBitAddress(bitPos);
|
||||
}
|
||||
|
||||
BitPosition DetectorImpl::getBitDefinition(const std::string &name) const {
|
||||
BitAddress DetectorImpl::getBitDefinition(const std::string &name) const {
|
||||
if (!isChipTestBoard())
|
||||
throw RuntimeError("Bit Definitions only for CTB");
|
||||
return ctb_shm()->getBitPosition(name);
|
||||
return ctb_shm()->getBitAddress(name);
|
||||
}
|
||||
|
||||
std::string DetectorImpl::getBitDefinition(BitPosition bitPos) const {
|
||||
std::string DetectorImpl::getBitDefinition(BitAddress bitPos) const {
|
||||
if (!isChipTestBoard())
|
||||
throw RuntimeError("Bit Definitions only for CTB");
|
||||
return ctb_shm()->getBitName(bitPos);
|
||||
@@ -2159,13 +2159,13 @@ void DetectorImpl::clearBitDefinitions() {
|
||||
}
|
||||
|
||||
void DetectorImpl::setBitDefinitions(
|
||||
const std::map<std::string, BitPosition> &list) {
|
||||
const std::map<std::string, BitAddress> &list) {
|
||||
if (!isChipTestBoard())
|
||||
throw RuntimeError("Bit Definitions only for CTB");
|
||||
ctb_shm()->setBitNames(list);
|
||||
}
|
||||
|
||||
std::map<std::string, BitPosition> DetectorImpl::getBitDefinitions() const {
|
||||
std::map<std::string, BitAddress> DetectorImpl::getBitDefinitions() const {
|
||||
if (!isChipTestBoard())
|
||||
throw RuntimeError("Bit Definitions only for CTB");
|
||||
return ctb_shm()->getBitNames();
|
||||
|
||||
@@ -344,14 +344,14 @@ class DetectorImpl : public virtual slsDetectorDefs {
|
||||
setRegisterDefinitions(const std::map<std::string, RegisterAddress> &list);
|
||||
std::map<std::string, RegisterAddress> getRegisterDefinitions() const;
|
||||
int getBitDefinitionsCount() const;
|
||||
void setBitDefinition(const std::string &name, BitPosition bitPos);
|
||||
void setBitDefinition(const std::string &name, BitAddress bitPos);
|
||||
bool hasBitDefinition(const std::string &name) const;
|
||||
bool hasBitDefinition(BitPosition bitPos) const;
|
||||
BitPosition getBitDefinition(const std::string &name) const;
|
||||
std::string getBitDefinition(BitPosition bitPos) const;
|
||||
bool hasBitDefinition(BitAddress bitPos) const;
|
||||
BitAddress getBitDefinition(const std::string &name) const;
|
||||
std::string getBitDefinition(BitAddress bitPos) const;
|
||||
void clearBitDefinitions();
|
||||
void setBitDefinitions(const std::map<std::string, BitPosition> &list);
|
||||
std::map<std::string, BitPosition> getBitDefinitions() const;
|
||||
void setBitDefinitions(const std::map<std::string, BitAddress> &list);
|
||||
std::map<std::string, BitAddress> getBitDefinitions() const;
|
||||
|
||||
private:
|
||||
/**
|
||||
|
||||
@@ -1408,7 +1408,7 @@ TEST_CASE("define", "[.cmdcall]") {
|
||||
|
||||
// bits
|
||||
std::string bit_name = "TEST_BIT";
|
||||
BitPosition pos(addr, 1); //=> reg_name => becomes 2 later
|
||||
BitAddress pos(addr, 1); //=> reg_name => becomes 2 later
|
||||
auto bit_pos = pos.bitPosition();
|
||||
auto bit_pos_str = std::to_string(bit_pos);
|
||||
auto bit_addr = pos.address();
|
||||
@@ -1416,7 +1416,7 @@ TEST_CASE("define", "[.cmdcall]") {
|
||||
|
||||
// for second bit same addr
|
||||
std::string bit_name2 = "TEST_BIT2";
|
||||
BitPosition pos2(addr, 4); // => reg_name
|
||||
BitAddress pos2(addr, 4); // => reg_name
|
||||
auto bit_pos2 = pos2.bitPosition();
|
||||
auto bit_pos_str2 = std::to_string(bit_pos2);
|
||||
auto bit_addr2 = pos2.address();
|
||||
@@ -1424,7 +1424,7 @@ TEST_CASE("define", "[.cmdcall]") {
|
||||
|
||||
// for another addr
|
||||
std::string bit_name3 = "TEST_BIT3";
|
||||
BitPosition pos3(addr2, 5); // => reg_name2
|
||||
BitAddress pos3(addr2, 5); // => reg_name2
|
||||
auto bit_pos3 = pos3.bitPosition();
|
||||
auto bit_pos_str3 = std::to_string(bit_pos3);
|
||||
auto bit_addr3 = pos3.address();
|
||||
|
||||
@@ -177,30 +177,30 @@ TEST_CASE("Finding a regiser name or address", "[.reg]") {
|
||||
TEST_CASE("Add or modify a bit name", "[.reg]") {
|
||||
CtbConfig c;
|
||||
RegisterAddress addr(0x100);
|
||||
BitPosition pos(addr, 2);
|
||||
BitPosition pos1(addr, 5);
|
||||
BitAddress pos(addr, 2);
|
||||
BitAddress pos1(addr, 5);
|
||||
|
||||
REQUIRE(c.getBitNamesCount() == 0);
|
||||
|
||||
REQUIRE_THROWS(c.setBitName("bit1_with_a_really_long_name_to_crash",
|
||||
BitPosition(addr, 100)));
|
||||
REQUIRE_THROWS(c.setBitName("bit1", BitPosition(addr, 32)));
|
||||
REQUIRE_THROWS(c.setBitName("bit1", BitPosition(addr, -1)));
|
||||
BitAddress(addr, 100)));
|
||||
REQUIRE_THROWS(c.setBitName("bit1", BitAddress(addr, 32)));
|
||||
REQUIRE_THROWS(c.setBitName("bit1", BitAddress(addr, -1)));
|
||||
|
||||
// add an entry
|
||||
REQUIRE_NOTHROW(c.setBitName("bit1", pos));
|
||||
REQUIRE(c.getBitName(pos) == "bit1");
|
||||
REQUIRE(c.getBitPosition("bit1") == pos);
|
||||
REQUIRE(c.getBitAddress("bit1") == pos);
|
||||
REQUIRE(c.getBitNamesCount() == 1);
|
||||
// modify an entry
|
||||
REQUIRE_NOTHROW(c.setBitName("bit1", pos1));
|
||||
REQUIRE(c.getBitPosition("bit1") == pos1);
|
||||
REQUIRE(c.getBitAddress("bit1") == pos1);
|
||||
REQUIRE(c.getBitName(pos1) == "bit1");
|
||||
// clear all entries
|
||||
REQUIRE_NOTHROW(c.clearBitNames());
|
||||
REQUIRE(c.getBitNamesCount() == 0);
|
||||
REQUIRE_THROWS(c.getBitName(pos));
|
||||
REQUIRE_THROWS(c.getBitPosition("bit1"));
|
||||
REQUIRE_THROWS(c.getBitAddress("bit1"));
|
||||
REQUIRE_THROWS(c.getBitName(pos1));
|
||||
}
|
||||
|
||||
@@ -209,20 +209,20 @@ TEST_CASE("Add a bit list", "[.reg]") {
|
||||
REQUIRE(c.getBitNamesCount() == 0);
|
||||
|
||||
RegisterAddress addr(0x100);
|
||||
BitPosition pos1(addr, 2);
|
||||
BitPosition pos2(addr, 21);
|
||||
BitAddress pos1(addr, 2);
|
||||
BitAddress pos2(addr, 21);
|
||||
|
||||
BitPosition pos3(addr, 31);
|
||||
BitAddress pos3(addr, 31);
|
||||
|
||||
// add a list
|
||||
std::map<std::string, BitPosition> list = {
|
||||
std::map<std::string, BitAddress> list = {
|
||||
{"bit1", pos1}, {"bit2", pos2}, {"bit3", pos3}};
|
||||
REQUIRE_NOTHROW(c.setBitNames(list));
|
||||
REQUIRE(c.getBitNamesCount() == 3);
|
||||
auto names = c.getBitNames();
|
||||
REQUIRE(names.size() == 3);
|
||||
|
||||
// TODO std::set<BitPosition> seen_values;
|
||||
// TODO std::set<BitAddress> seen_values;
|
||||
for (const auto &[key, val] : list) {
|
||||
// check for duplicate keys, and key-value match
|
||||
REQUIRE(names.count(key) == 1);
|
||||
@@ -241,20 +241,20 @@ TEST_CASE("Add a bit list", "[.reg]") {
|
||||
TEST_CASE("Finding a bit value", "[.reg]") {
|
||||
CtbConfig c;
|
||||
RegisterAddress addr(0x100);
|
||||
BitPosition pos(addr, 2);
|
||||
BitPosition pos1(addr, 21);
|
||||
BitPosition pos2(addr, 31);
|
||||
BitAddress pos(addr, 2);
|
||||
BitAddress pos1(addr, 21);
|
||||
BitAddress pos2(addr, 31);
|
||||
|
||||
// find nothing
|
||||
REQUIRE(c.getBitNamesCount() == 0);
|
||||
REQUIRE_THROWS(c.getBitPosition("bit"));
|
||||
REQUIRE_THROWS(c.getBitAddress("bit"));
|
||||
|
||||
std::map<std::string, BitPosition> list = {
|
||||
std::map<std::string, BitAddress> list = {
|
||||
{"bit1", pos}, {"bit1", pos1}, {"bit2", pos2}};
|
||||
REQUIRE_NOTHROW(c.setBitNames(list));
|
||||
|
||||
// find
|
||||
REQUIRE(c.getBitPosition("bit3") == pos2);
|
||||
REQUIRE(c.getBitAddress("bit3") == pos2);
|
||||
REQUIRE(c.getBitName(pos1) == "bit1");
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <bitset>
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
namespace sls {
|
||||
template <typename T> std::vector<int> getSetBits(T val) {
|
||||
@@ -26,7 +26,7 @@ class RegisterAddress {
|
||||
|
||||
public:
|
||||
constexpr RegisterAddress() noexcept = default;
|
||||
explicit RegisterAddress(uint32_t address) : addr_(address) {}
|
||||
constexpr explicit RegisterAddress(uint32_t address) : addr_(address) {}
|
||||
explicit RegisterAddress(const std::string &address);
|
||||
|
||||
std::string str() const;
|
||||
@@ -38,30 +38,30 @@ class RegisterAddress {
|
||||
constexpr bool operator!=(const RegisterAddress &other) const {
|
||||
return (addr_ != other.addr_);
|
||||
}
|
||||
} __attribute__((packed));
|
||||
};
|
||||
|
||||
class BitPosition {
|
||||
class BitAddress {
|
||||
private:
|
||||
RegisterAddress addr_{0};
|
||||
int bitPos_{0};
|
||||
|
||||
public:
|
||||
constexpr BitPosition() noexcept = default;
|
||||
BitPosition(RegisterAddress address, int bitPosition);
|
||||
constexpr BitAddress() noexcept = default;
|
||||
BitAddress(RegisterAddress address, int bitPosition);
|
||||
std::string str() const;
|
||||
|
||||
RegisterAddress address() const noexcept { return addr_; }
|
||||
int bitPosition() const noexcept { return bitPos_; }
|
||||
void setAddress(RegisterAddress address) noexcept { addr_ = address; }
|
||||
void setBitPosition(int bitPosition) noexcept { bitPos_ = bitPosition; }
|
||||
void setBitPosition(int bitPos) noexcept { bitPos_ = bitPos; }
|
||||
|
||||
constexpr bool operator==(const BitPosition &other) const {
|
||||
constexpr bool operator==(const BitAddress &other) const {
|
||||
return (addr_ == other.addr_ && bitPos_ == other.bitPos_);
|
||||
}
|
||||
constexpr bool operator!=(const BitPosition &other) const {
|
||||
constexpr bool operator!=(const BitAddress &other) const {
|
||||
return !(*this == other && bitPos_ == other.bitPos_);
|
||||
}
|
||||
} __attribute__((packed));
|
||||
};
|
||||
|
||||
class RegisterValue {
|
||||
private:
|
||||
@@ -88,7 +88,7 @@ class RegisterValue {
|
||||
} __attribute__((packed));
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const RegisterAddress &r);
|
||||
std::ostream &operator<<(std::ostream &os, const BitPosition &r);
|
||||
std::ostream &operator<<(std::ostream &os, const BitAddress &r);
|
||||
std::ostream &operator<<(std::ostream &os, const RegisterValue &r);
|
||||
|
||||
} // namespace sls
|
||||
|
||||
@@ -16,14 +16,14 @@ RegisterAddress::RegisterAddress(const std::string &address) {
|
||||
|
||||
std::string RegisterAddress::str() const { return ToStringHex(addr_); }
|
||||
|
||||
BitPosition::BitPosition(RegisterAddress address, int bitPosition)
|
||||
BitAddress::BitAddress(RegisterAddress address, int bitPosition)
|
||||
: addr_(address), bitPos_(bitPosition) {
|
||||
if (bitPosition < 0 || bitPosition > 31) {
|
||||
throw RuntimeError("Bit position must be between 0 and 31.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string BitPosition::str() const {
|
||||
std::string BitAddress::str() const {
|
||||
std::ostringstream os;
|
||||
os << '[' << addr_.str() << ", " << ToString(bitPos_) << ']';
|
||||
return os.str();
|
||||
@@ -44,7 +44,7 @@ std::ostream &operator<<(std::ostream &os, const RegisterAddress &r) {
|
||||
return os;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &os, const BitPosition &r) {
|
||||
std::ostream &operator<<(std::ostream &os, const BitAddress &r) {
|
||||
os << r.str();
|
||||
return os;
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ TEST_CASE("Convert RegisterValue using classes ", "[support][bit_utils]") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("Convert BitPosition using classes ", "[support][bit_utils]") {
|
||||
TEST_CASE("Convert BitAddress using classes ", "[support][bit_utils]") {
|
||||
std::vector<RegisterAddress> vec_addr{
|
||||
RegisterAddress(0x305), RegisterAddress(0xffffffffu),
|
||||
RegisterAddress(0x0), RegisterAddress(0x34550987),
|
||||
@@ -103,13 +103,13 @@ TEST_CASE("Convert BitPosition using classes ", "[support][bit_utils]") {
|
||||
};
|
||||
|
||||
for (size_t i = 0; i != vec_addr.size(); ++i) {
|
||||
auto reg0 = BitPosition(vec_addr[i], vec_bitpos[i]);
|
||||
auto reg0 = BitAddress(vec_addr[i], vec_bitpos[i]);
|
||||
|
||||
BitPosition reg1;
|
||||
BitAddress reg1;
|
||||
reg1.setAddress(vec_addr[i]);
|
||||
reg1.setBitPosition(vec_bitpos[i]);
|
||||
|
||||
auto reg2 = BitPosition(vec_addr[0], vec_bitpos[0]);
|
||||
auto reg2 = BitAddress(vec_addr[0], vec_bitpos[0]);
|
||||
|
||||
CHECK(reg0 == reg1);
|
||||
if (i != 0)
|
||||
@@ -159,10 +159,10 @@ TEST_CASE("Strange input throws", "[support][bit_utils]") {
|
||||
REQUIRE(std::string(e.what()) == "Value must be an integer value.");
|
||||
}
|
||||
|
||||
REQUIRE_THROWS(BitPosition(RegisterAddress(0x305), 32));
|
||||
REQUIRE_THROWS(BitAddress(RegisterAddress(0x305), 32));
|
||||
// ensure correct exception message
|
||||
try {
|
||||
BitPosition(RegisterAddress(0x305), 32);
|
||||
BitAddress(RegisterAddress(0x305), 32);
|
||||
} catch (const std::exception &e) {
|
||||
REQUIRE(std::string(e.what()) ==
|
||||
"Bit position must be between 0 and 31.");
|
||||
|
||||
Reference in New Issue
Block a user