49void rim::Master::setup_python() {
51 bp::class_<rim::Master, rim::MasterPtr, boost::noncopyable>(
"Master", bp::init<>())
52 .def(
"_setSlave", &rim::Master::setSlave)
53 .def(
"_getSlave", &rim::Master::getSlave)
54 .def(
"_reqSlaveId", &rim::Master::reqSlaveId)
55 .def(
"_reqSlaveName", &rim::Master::reqSlaveName)
56 .def(
"_reqMinAccess", &rim::Master::reqMinAccess)
57 .def(
"_reqMaxAccess", &rim::Master::reqMaxAccess)
58 .def(
"_reqAddress", &rim::Master::reqAddress)
59 .def(
"_getError", &rim::Master::getError)
60 .def(
"_clearError", &rim::Master::clearError)
61 .def(
"_setTimeout", &rim::Master::setTimeout)
62 .def(
"_reqTransaction", &rim::Master::reqTransactionPy)
63 .def(
"_waitTransaction", &rim::Master::waitTransaction)
64 .def(
"_copyBits", &rim::Master::copyBits)
65 .staticmethod(
"_copyBits")
66 .def(
"_setBits", &rim::Master::setBits)
67 .staticmethod(
"_setBits")
68 .def(
"_anyBits", &rim::Master::anyBits)
69 .staticmethod(
"_anyBits")
70 .def(
"__rshift__", &rim::Master::rshiftPy)
71 .def(
"_stop", &rim::Master::stop);
141void rim::Master::setTimeout(uint64_t timeout) {
143 std::lock_guard<std::mutex> lock(mastMtx_);
146 div_t divResult = div(timeout, 1000000);
147 sumTime_.tv_sec = divResult.quot;
148 sumTime_.tv_usec = divResult.rem;
167uint32_t rim::Master::reqTransactionPy(uint64_t address,
168 boost::python::object p,
175 if (PyObject_GetBuffer(p.ptr(), &(tran->pyBuf_), PyBUF_CONTIG) < 0)
178 if (PyObject_GetBuffer(p.ptr(), &(tran->pyBuf_), PyBUF_SIMPLE) < 0)
183 tran->size_ = tran->pyBuf_.len;
187 if ((tran->size_ + offset) > tran->pyBuf_.len) {
188 PyBuffer_Release(&(tran->pyBuf_));
190 "Attempt to access %" PRIu32
" bytes in python buffer with size %" PRIu32
191 " at offset %" PRIu32,
197 tran->pyValid_ =
true;
198 tran->iter_ =
reinterpret_cast<uint8_t*
>(tran->pyBuf_.buf) + offset;
200 tran->address_ = address;
202 return (intTransaction(tran));
208 TransactionMap::iterator it;
209 struct timeval currTime;
214 std::lock_guard<std::mutex> lock(mastMtx_);
216 tranMap_[tran->id_] = tran;
219 log_->debug(
"Request transaction type=%" PRIu32
" id=%" PRIu32, tran->type_, tran->id_);
220 tran->log_->debug(
"Created transaction type=%" PRIu32
" id=%" PRIu32
", address=0x%016" PRIx64
", size=%" PRIu32,
225 slave->doTransaction(tran);
226 tran->refreshTimer(tran);
259void rim::Master::copyBits(uint8_t* dstData, uint32_t dstLsb, uint8_t* srcData, uint32_t srcLsb, uint32_t size) {
267 srcByte = srcLsb / 8;
269 dstByte = dstLsb / 8;
277 if ((srcBit == 0) && (dstBit == 0) && (bytes > 0)) {
278 std::memcpy(&(dstData[dstByte]), &(srcData[srcByte]), bytes);
285 dstData[dstByte] &= ((0x1 << dstBit) ^ 0xFF);
286 dstData[dstByte] |= ((srcData[srcByte] >> srcBit) & 0x1) << dstBit;
287 srcByte += (++srcBit / 8);
288 dstByte += (++dstBit / 8);
299void rim::Master::copyBitsPy(boost::python::object dst,
301 boost::python::object src,
307 if (PyObject_GetBuffer(dst.ptr(), &dstBuf, PyBUF_CONTIG) < 0)
310 if ((dstLsb + size) > (dstBuf.len * 8)) {
311 PyBuffer_Release(&dstBuf);
313 "Attempt to copy %" PRIu32
" bits starting from bit %" PRIu32
314 " from dest array with bitSize %" PRIu32,
320 if (PyObject_GetBuffer(src.ptr(), &srcBuf, PyBUF_SIMPLE) < 0) {
321 PyBuffer_Release(&dstBuf);
325 if ((srcLsb + size) > (srcBuf.len * 8)) {
326 PyBuffer_Release(&srcBuf);
327 PyBuffer_Release(&dstBuf);
329 "Attempt to copy %" PRIu32
" bits starting from bit %" PRIu32
330 " from source array with bitSize %" PRIu32,
336 copyBits(
reinterpret_cast<uint8_t*
>(dstBuf.buf), dstLsb,
reinterpret_cast<uint8_t*
>(srcBuf.buf), srcLsb, size);
338 PyBuffer_Release(&srcBuf);
339 PyBuffer_Release(&dstBuf);
345void rim::Master::setBits(uint8_t* dstData, uint32_t lsb, uint32_t size) {
359 if ((dstBit == 0) && (bytes > 0)) {
360 memset(&(dstData[dstByte]), 0xFF, bytes);
366 dstData[dstByte] |= (0x1 << dstBit);
367 dstByte += (++dstBit / 8);
377void rim::Master::setBitsPy(boost::python::object dst, uint32_t lsb, uint32_t size) {
380 if (PyObject_GetBuffer(dst.ptr(), &dstBuf, PyBUF_CONTIG) < 0)
383 if ((lsb + size) > (dstBuf.len * 8)) {
384 PyBuffer_Release(&dstBuf);
386 "Attempt to set %" PRIu32
" bits starting from bit %" PRIu32
387 " in array with bitSize %" PRIu32,
393 setBits(
reinterpret_cast<uint8_t*
>(dstBuf.buf), lsb, size);
395 PyBuffer_Release(&dstBuf);
401bool rim::Master::anyBits(uint8_t* dstData, uint32_t lsb, uint32_t size) {
417 if ((dstBit == 0) && (bytes > 0)) {
418 if (dstData[dstByte] != 0) ret =
true;
424 if ((dstData[dstByte] & (0x1 << dstBit)) != 0) ret =
true;
425 dstByte += (++dstBit / 8);
429 }
while (ret ==
false && rem != 0);
437bool rim::Master::anyBitsPy(boost::python::object dst, uint32_t lsb, uint32_t size) {
441 if (PyObject_GetBuffer(dst.ptr(), &dstBuf, PyBUF_SIMPLE) < 0)
444 if ((lsb + size) > (dstBuf.len * 8)) {
445 PyBuffer_Release(&dstBuf);
447 "Attempt to access %" PRIu32
" bits starting from bit %" PRIu32
448 " from array with bitSize %" PRIu32,
454 ret = anyBits(
reinterpret_cast<uint8_t*
>(dstBuf.buf), lsb, size);
456 PyBuffer_Release(&dstBuf);
460void rim::Master::rshiftPy(bp::object p) {
464 boost::python::extract<rim::SlavePtr> get_slave(p);
467 if (get_slave.check()) {
471 }
else if (PyObject_HasAttrString(p.ptr(),
"_getMemorySlave")) {
473 boost::python::extract<rim::SlavePtr> get_slave(p.attr(
"_getMemorySlave")());
476 if (get_slave.check()) slv = get_slave();
484 "Attempt to use >> operator with incompatible memory slave"));