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;
273 if (rem == 0)
return;
279 if ((srcBit == 0) && (dstBit == 0) && (bytes > 0)) {
280 std::memcpy(&(dstData[dstByte]), &(srcData[srcByte]), bytes);
287 dstData[dstByte] &= ((0x1 << dstBit) ^ 0xFF);
288 dstData[dstByte] |= ((srcData[srcByte] >> srcBit) & 0x1) << dstBit;
289 srcByte += (++srcBit / 8);
290 dstByte += (++dstBit / 8);
301void rim::Master::copyBitsPy(boost::python::object dst,
303 boost::python::object src,
309 if (PyObject_GetBuffer(dst.ptr(), &dstBuf, PyBUF_CONTIG) < 0)
312 if ((dstLsb + size) > (dstBuf.len * 8)) {
313 PyBuffer_Release(&dstBuf);
315 "Attempt to copy %" PRIu32
" bits starting from bit %" PRIu32
316 " from dest array with bitSize %" PRIu32,
322 if (PyObject_GetBuffer(src.ptr(), &srcBuf, PyBUF_SIMPLE) < 0) {
323 PyBuffer_Release(&dstBuf);
327 if ((srcLsb + size) > (srcBuf.len * 8)) {
328 PyBuffer_Release(&srcBuf);
329 PyBuffer_Release(&dstBuf);
331 "Attempt to copy %" PRIu32
" bits starting from bit %" PRIu32
332 " from source array with bitSize %" PRIu32,
338 copyBits(
reinterpret_cast<uint8_t*
>(dstBuf.buf), dstLsb,
reinterpret_cast<uint8_t*
>(srcBuf.buf), srcLsb, size);
340 PyBuffer_Release(&srcBuf);
341 PyBuffer_Release(&dstBuf);
347void rim::Master::setBits(uint8_t* dstData, uint32_t lsb, uint32_t size) {
357 if (rem == 0)
return;
363 if ((dstBit == 0) && (bytes > 0)) {
364 memset(&(dstData[dstByte]), 0xFF, bytes);
370 dstData[dstByte] |= (0x1 << dstBit);
371 dstByte += (++dstBit / 8);
381void rim::Master::setBitsPy(boost::python::object dst, uint32_t lsb, uint32_t size) {
384 if (PyObject_GetBuffer(dst.ptr(), &dstBuf, PyBUF_CONTIG) < 0)
387 if ((lsb + size) > (dstBuf.len * 8)) {
388 PyBuffer_Release(&dstBuf);
390 "Attempt to set %" PRIu32
" bits starting from bit %" PRIu32
391 " in array with bitSize %" PRIu32,
397 setBits(
reinterpret_cast<uint8_t*
>(dstBuf.buf), lsb, size);
399 PyBuffer_Release(&dstBuf);
405bool rim::Master::anyBits(uint8_t* dstData, uint32_t lsb, uint32_t size) {
417 if (rem == 0)
return false;
423 if ((dstBit == 0) && (bytes > 0)) {
424 if (dstData[dstByte] != 0) ret =
true;
430 if ((dstData[dstByte] & (0x1 << dstBit)) != 0) ret =
true;
431 dstByte += (++dstBit / 8);
435 }
while (ret ==
false && rem != 0);
443bool rim::Master::anyBitsPy(boost::python::object dst, uint32_t lsb, uint32_t size) {
447 if (PyObject_GetBuffer(dst.ptr(), &dstBuf, PyBUF_SIMPLE) < 0)
450 if ((lsb + size) > (dstBuf.len * 8)) {
451 PyBuffer_Release(&dstBuf);
453 "Attempt to access %" PRIu32
" bits starting from bit %" PRIu32
454 " from array with bitSize %" PRIu32,
460 ret = anyBits(
reinterpret_cast<uint8_t*
>(dstBuf.buf), lsb, size);
462 PyBuffer_Release(&dstBuf);
466void rim::Master::rshiftPy(bp::object p) {
470 boost::python::extract<rim::SlavePtr> get_slave(p);
473 if (get_slave.check()) {
477 }
else if (PyObject_HasAttrString(p.ptr(),
"_getMemorySlave")) {
479 boost::python::extract<rim::SlavePtr> get_slave(p.attr(
"_getMemorySlave")());
482 if (get_slave.check()) slv = get_slave();
490 "Attempt to use >> operator with incompatible memory slave"));