Created
July 9, 2019 20:10
-
-
Save kratsg/c11a67f44f63628ef20b7a0ed4b0c150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ironman.constructs.ipbus import IPBusConstruct | |
from ironman.hardware import HardwareManager, HardwareMap | |
from ironman.communicator import Jarvis | |
from ironman.packet import IPBusPacket | |
from twisted.internet.defer import Deferred | |
import mmap | |
hardware_map = ''' | |
nodes: | |
- | |
id: devmemtest | |
address: 0x00000000 | |
nodes: | |
- {id: read, address: 0x0, permissions: 1} | |
''' | |
j = Jarvis() | |
manager = HardwareManager() | |
manager.add(HardwareMap(hardware_map, 'main')) | |
j.set_hardware_manager(manager) | |
@j.register('main') | |
class DevMemIO(object): | |
__f__ = open('/dev/mem', 'r+') | |
def read(self, offset, size): | |
with mmap.mmap(__f__.fileno(), size, offset=offset) as m: | |
return m.readline() | |
def buildResponsePacket(packet): | |
packet.response.transactions[0].header.info_code = 'SUCCESS' | |
return IPBusConstruct.build(packet.response) | |
def printPacket(raw): | |
print "raw: {0:s}".format(repr(raw.encode('hex'))) | |
print IPBusConstruct.parse(raw) | |
d = Deferred().addCallback(IPBusPacket).addCallback(j).addCallback(buildResponsePacket).addCallback(printPacket) | |
initialPacket = '200000f02000010f00000002'.decode('hex') | |
d.callback(initialPacket) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment