diff options
author | Iru Cai <mytbk920423@gmail.com> | 2020-02-25 16:23:30 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2020-02-25 16:23:30 +0800 |
commit | de954233b87f5167677f8086686703db1c9f1a7e (patch) | |
tree | 524740d2ae4e6ce9930e6fa4225da3ed5d72f7c3 | |
parent | 1595558f39f6724b3f5bd630c68bcb35fe8bf012 (diff) | |
download | gem5-de954233b87f5167677f8086686703db1c9f1a7e.tar.xz |
learning-gem5: timing readsimple-object-demo
Change-Id: I566aa3e6e14c9d1784eaf93ede88c98a52a1fa71
-rw-r--r-- | src/learning_gem5/part2/simple_object.cc | 26 | ||||
-rw-r--r-- | src/learning_gem5/part2/simple_object.hh | 7 |
2 files changed, 28 insertions, 5 deletions
diff --git a/src/learning_gem5/part2/simple_object.cc b/src/learning_gem5/part2/simple_object.cc index 76dadf9c8..66f1ca206 100644 --- a/src/learning_gem5/part2/simple_object.cc +++ b/src/learning_gem5/part2/simple_object.cc @@ -46,9 +46,18 @@ SimpleObject::SimpleObject(SimpleObjectParams *params) : std::cout << "Hello World! From a SimObject!" << std::endl; } +bool SimpleObject::SimplePort::recvTimingResp(PacketPtr pkt) +{ + std::cout << "Receive packet, val = 0x" << + std::hex << pkt->getLE<uint32_t>() << + ". Tick = " << std::dec << curTick() << std::endl; + return true; +} + void SimpleObject::processEvent() { - readAtomic(); + // readAtomic(); + readTiming(); } void SimpleObject::readAtomic() @@ -66,6 +75,21 @@ void SimpleObject::readAtomic() std::cout << "read value 0x" << std::hex << val << std::endl; } +void SimpleObject::readTiming() +{ + RequestPtr req = std::make_shared<Request>(0x200000, 4, 0, masterId); + PacketPtr pkt = Packet::createRead(req); + + // we cannot use a local stack variable in timing request + pkt->dataDynamic(new uint32_t); + + bool res = memPort.sendTimingReq(pkt); + if (res) { + std::cout << "Successfully send timing request. Tick = " << + curTick() << std::endl; + } +} + void SimpleObject::writeAtomic() { RequestPtr req = std::make_shared<Request>(0x200000, 4, 0, masterId); diff --git a/src/learning_gem5/part2/simple_object.hh b/src/learning_gem5/part2/simple_object.hh index 53fa1fea1..e45dce4ae 100644 --- a/src/learning_gem5/part2/simple_object.hh +++ b/src/learning_gem5/part2/simple_object.hh @@ -41,10 +41,8 @@ class SimpleObject : public SimObject { public: // these virtual functions must be implemented - virtual bool recvTimingResp(PacketPtr pkt) - { - fatal("SimplePort::recvTimingResp not implemented!\n"); - } + virtual bool recvTimingResp(PacketPtr pkt) override; + virtual void recvReqRetry() { fatal("SimplePort::recvReqRetry not implemented!\n"); @@ -74,6 +72,7 @@ class SimpleObject : public SimObject virtual void startup() override; void processEvent(); void readAtomic(); + void readTiming(); void writeAtomic(); }; |