Add byteorder to word wrappers

This commit is contained in:
Alex Forencich
2020-12-01 22:51:11 -08:00
parent 645ebb069c
commit 4546900651
2 changed files with 107 additions and 97 deletions

View File

@@ -186,37 +186,42 @@ class AxiMasterWrite(object):
await self.wait(token)
return self.get_write_resp(token)
async def write_words(self, address, data, ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_words(self, address, data, byteorder='little', ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
words = data
data = bytearray()
for w in words:
data.extend(w.to_bytes(ws, 'little'))
data.extend(w.to_bytes(ws, byteorder))
await self.write(address, data, awid, burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_dwords(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_dwords(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
await self.write_words(address, data, 4, awid, burst, size, lock, cache, prot, qos, region, user, wuser)
await self.write_words(address, data, byteorder, 4, awid, burst, size,
lock, cache, prot, qos, region, user, wuser)
async def write_qwords(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_qwords(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
await self.write_words(address, data, 8, awid, burst, size, lock, cache, prot, qos, region, user, wuser)
await self.write_words(address, data, byteorder, 8, awid, burst, size,
lock, cache, prot, qos, region, user, wuser)
async def write_byte(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
await self.write(address, [data], awid, burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_word(self, address, data, ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_word(self, address, data, byteorder='little', ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
await self.write_words(address, [data], ws, awid, burst, size, lock, cache, prot, qos, region, user, wuser)
await self.write_words(address, [data], byteorder, ws, awid, burst, size,
lock, cache, prot, qos, region, user, wuser)
async def write_dword(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_dword(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
await self.write_dwords(address, [data], awid, burst, size, lock, cache, prot, qos, region, user, wuser)
await self.write_dwords(address, [data], byteorder, awid, burst, size,
lock, cache, prot, qos, region, user, wuser)
async def write_qword(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_qword(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
await self.write_qwords(address, [data], awid, burst, size, lock, cache, prot, qos, region, user, wuser)
await self.write_qwords(address, [data], byteorder, awid, burst, size,
lock, cache, prot, qos, region, user, wuser)
async def _process_write(self):
while True:
@@ -511,37 +516,42 @@ class AxiMasterRead(object):
await self.wait(token)
return self.get_read_data(token)
async def read_words(self, address, count, ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_words(self, address, count, byteorder='little', ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
data = await self.read(address, count*ws, burst, size, lock, cache, prot, qos, region, user)
data = await self.read(address, count*ws, arid, burst, size, lock, cache, prot, qos, region, user)
words = []
for k in range(count):
words.append(int.from_bytes(data.data[ws*k:ws*(k+1)], 'little'))
words.append(int.from_bytes(data.data[ws*k:ws*(k+1)], byteorder))
return words
async def read_dwords(self, address, count, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_dwords(self, address, count, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_words(address, count, 4, arid, burst, size, lock, cache, prot, qos, region, user)
return await self.read_words(address, count, byteorder, 4, arid, burst, size,
lock, cache, prot, qos, region, user)
async def read_qwords(self, address, count, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_qwords(self, address, count, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_words(address, count, 8, arid, burst, size, lock, cache, prot, qos, region, user)
return await self.read_words(address, count, byteorder, 8, arid, burst, size,
lock, cache, prot, qos, region, user)
async def read_byte(self, address, arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return (await self.read(address, 1, arid, burst, size, lock, cache, prot, qos, region, user)).data[0]
async def read_word(self, address, ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_word(self, address, byteorder='little', ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return (await self.read_words(address, 1, ws, arid, burst, size, lock, cache, prot, qos, region, user))[0]
return (await self.read_words(address, 1, byteorder, ws, arid, burst, size,
lock, cache, prot, qos, region, user))[0]
async def read_dword(self, address, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_dword(self, address, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return (await self.read_dwords(address, 1, arid, burst, size, lock, cache, prot, qos, region, user))[0]
return (await self.read_dwords(address, 1, byteorder, arid, burst, size,
lock, cache, prot, qos, region, user))[0]
async def read_qword(self, address, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_qword(self, address, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return (await self.read_qwords(address, 1, arid, burst, size, lock, cache, prot, qos, region, user))[0]
return (await self.read_qwords(address, 1, byteorder, arid, burst, size,
lock, cache, prot, qos, region, user))[0]
async def _process_read(self):
while True:
@@ -749,19 +759,19 @@ class AxiMaster(object):
return await self.read_if.read(address, length, arid,
burst, size, lock, cache, prot, qos, region, user)
async def read_words(self, address, count, ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_words(self, address, count, byteorder='little', ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_if.read_words(address, count, ws, arid,
return await self.read_if.read_words(address, count, byteorder, ws, arid,
burst, size, lock, cache, prot, qos, region, user)
async def read_dwords(self, address, count, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_dwords(self, address, count, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_if.read_dwords(address, count, arid,
return await self.read_if.read_dwords(address, count, byteorder, arid,
burst, size, lock, cache, prot, qos, region, user)
async def read_qwords(self, address, count, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_qwords(self, address, count, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_if.read_qwords(address, count, arid,
return await self.read_if.read_qwords(address, count, byteorder, arid,
burst, size, lock, cache, prot, qos, region, user)
async def read_byte(self, address, arid=None, burst=AxiBurstType.INCR, size=None,
@@ -769,19 +779,19 @@ class AxiMaster(object):
return await self.read_if.read_byte(address, arid,
burst, size, lock, cache, prot, qos, region, user)
async def read_word(self, address, ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_word(self, address, byteorder='little', ws=2, arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_if.read_word(address, ws, arid,
return await self.read_if.read_word(address, byteorder, ws, arid,
burst, size, lock, cache, prot, qos, region, user)
async def read_dword(self, address, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_dword(self, address, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_if.read_dword(address, arid,
return await self.read_if.read_dword(address, byteorder, arid,
burst, size, lock, cache, prot, qos, region, user)
async def read_qword(self, address, arid=None, burst=AxiBurstType.INCR, size=None,
async def read_qword(self, address, byteorder='little', arid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0):
return await self.read_if.read_qword(address, arid,
return await self.read_if.read_qword(address, byteorder, arid,
burst, size, lock, cache, prot, qos, region, user)
async def write(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
@@ -789,19 +799,19 @@ class AxiMaster(object):
return await self.write_if.write(address, data, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_words(self, address, data, ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_words(self, address, data, byteorder='little', ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
return await self.write_if.write_words(address, data, ws, awid,
return await self.write_if.write_words(address, data, byteorder, ws, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_dwords(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_dwords(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
return await self.write_if.write_dwords(address, data, awid,
return await self.write_if.write_dwords(address, data, byteorder, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_qwords(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_qwords(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
return await self.write_if.write_qwords(address, data, awid,
return await self.write_if.write_qwords(address, data, byteorder, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_byte(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
@@ -809,17 +819,17 @@ class AxiMaster(object):
return await self.write_if.write_byte(address, data, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_word(self, address, data, ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_word(self, address, data, byteorder='little', ws=2, awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
return await self.write_if.write_word(address, data, ws, awid,
return await self.write_if.write_word(address, data, byteorder, ws, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_dword(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_dword(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
return await self.write_if.write_dword(address, data, awid,
return await self.write_if.write_dword(address, data, byteorder, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)
async def write_qword(self, address, data, awid=None, burst=AxiBurstType.INCR, size=None,
async def write_qword(self, address, data, byteorder='little', awid=None, burst=AxiBurstType.INCR, size=None,
lock=AxiLockType.NORMAL, cache=0b0011, prot=AxiProt.NONSECURE, qos=0, region=0, user=0, wuser=0):
return await self.write_if.write_qword(address, data, awid,
return await self.write_if.write_qword(address, data, byteorder, awid,
burst, size, lock, cache, prot, qos, region, user, wuser)

View File

@@ -142,30 +142,30 @@ class AxiLiteMasterWrite(object):
await self.wait(token)
return self.get_write_resp(token)
async def write_words(self, address, data, ws=2, prot=AxiProt.NONSECURE):
async def write_words(self, address, data, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
words = data
data = bytearray()
for w in words:
data.extend(w.to_bytes(ws, 'little'))
data.extend(w.to_bytes(ws, byteorder))
await self.write(address, data, prot)
async def write_dwords(self, address, data, prot=AxiProt.NONSECURE):
await self.write_words(address, data, 4, prot)
async def write_dwords(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
await self.write_words(address, data, byteorder, 4, prot)
async def write_qwords(self, address, data, prot=AxiProt.NONSECURE):
await self.write_words(address, data, 8, prot)
async def write_qwords(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
await self.write_words(address, data, byteorder, 8, prot)
async def write_byte(self, address, data, prot=AxiProt.NONSECURE):
await self.write(address, [data], prot)
async def write_word(self, address, data, ws=2, prot=AxiProt.NONSECURE):
await self.write_words(address, [data], ws, prot)
async def write_word(self, address, data, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
await self.write_words(address, [data], byteorder, ws, prot)
async def write_dword(self, address, data, prot=AxiProt.NONSECURE):
await self.write_dwords(address, [data], prot)
async def write_dword(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
await self.write_dwords(address, [data], byteorder, prot)
async def write_qword(self, address, data, prot=AxiProt.NONSECURE):
await self.write_qwords(address, [data], prot)
async def write_qword(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
await self.write_qwords(address, [data], byteorder, prot)
async def _process_write(self):
while True:
@@ -347,30 +347,30 @@ class AxiLiteMasterRead(object):
await self.wait(token)
return self.get_read_data(token)
async def read_words(self, address, count, ws=2, prot=AxiProt.NONSECURE):
async def read_words(self, address, count, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
data = await self.read(address, count*ws, prot)
words = []
for k in range(count):
words.append(int.from_bytes(data.data[ws*k:ws*(k+1)], 'little'))
words.append(int.from_bytes(data.data[ws*k:ws*(k+1)], byteorder))
return words
async def read_dwords(self, address, count, prot=AxiProt.NONSECURE):
return await self.read_words(address, count, 4, prot)
async def read_dwords(self, address, count, byteorder='little', prot=AxiProt.NONSECURE):
return await self.read_words(address, count, byteorder, 4, prot)
async def read_qwords(self, address, count, prot=AxiProt.NONSECURE):
return await self.read_words(address, count, 8, prot)
async def read_qwords(self, address, count, byteorder='little', prot=AxiProt.NONSECURE):
return await self.read_words(address, count, byteorder, 8, prot)
async def read_byte(self, address, prot=AxiProt.NONSECURE):
return (await self.read(address, 1, prot)).data[0]
async def read_word(self, address, ws=2, prot=AxiProt.NONSECURE):
return (await self.read_words(address, 1, ws, prot))[0]
async def read_word(self, address, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
return (await self.read_words(address, 1, byteorder, ws, prot))[0]
async def read_dword(self, address, prot=AxiProt.NONSECURE):
return (await self.read_dwords(address, 1, prot))[0]
async def read_dword(self, address, byteorder='little', prot=AxiProt.NONSECURE):
return (await self.read_dwords(address, 1, byteorder, prot))[0]
async def read_qword(self, address, prot=AxiProt.NONSECURE):
return (await self.read_qwords(address, 1, prot))[0]
async def read_qword(self, address, byteorder='little', prot=AxiProt.NONSECURE):
return (await self.read_qwords(address, 1, byteorder, prot))[0]
async def _process_read(self):
while True:
@@ -493,47 +493,47 @@ class AxiLiteMaster(object):
async def read(self, address, length, prot=AxiProt.NONSECURE):
return await self.read_if.read(address, length, prot)
async def read_words(self, address, count, ws=2, prot=AxiProt.NONSECURE):
return await self.read_if.read_words(address, count, ws, prot)
async def read_words(self, address, count, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
return await self.read_if.read_words(address, count, byteorder, ws, prot)
async def read_dwords(self, address, count, prot=AxiProt.NONSECURE):
return await self.read_if.read_dwords(address, count, prot)
async def read_dwords(self, address, count, byteorder='little', prot=AxiProt.NONSECURE):
return await self.read_if.read_dwords(address, count, byteorder, prot)
async def read_qwords(self, address, count, prot=AxiProt.NONSECURE):
return await self.read_if.read_qwords(address, count, prot)
async def read_qwords(self, address, count, byteorder='little', prot=AxiProt.NONSECURE):
return await self.read_if.read_qwords(address, count, byteorder, prot)
async def read_byte(self, address, prot=AxiProt.NONSECURE):
return await self.read_if.read_byte(address, prot)
async def read_word(self, address, ws=2, prot=AxiProt.NONSECURE):
return await self.read_if.read_word(address, ws, prot)
async def read_word(self, address, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
return await self.read_if.read_word(address, byteorder, ws, prot)
async def read_dword(self, address, prot=AxiProt.NONSECURE):
return await self.read_if.read_dword(address, prot)
async def read_dword(self, address, byteorder='little', prot=AxiProt.NONSECURE):
return await self.read_if.read_dword(address, byteorder, prot)
async def read_qword(self, address, prot=AxiProt.NONSECURE):
return await self.read_if.read_qword(address, prot)
async def read_qword(self, address, byteorder='little', prot=AxiProt.NONSECURE):
return await self.read_if.read_qword(address, byteorder, prot)
async def write(self, address, data, prot=AxiProt.NONSECURE):
return await self.write_if.write(address, data, prot)
async def write_words(self, address, data, ws=2, prot=AxiProt.NONSECURE):
return await self.write_if.write_words(address, data, ws, prot)
async def write_words(self, address, data, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
return await self.write_if.write_words(address, data, byteorder, ws, prot)
async def write_dwords(self, address, data, prot=AxiProt.NONSECURE):
return await self.write_if.write_dwords(address, data, prot)
async def write_dwords(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
return await self.write_if.write_dwords(address, data, byteorder, prot)
async def write_qwords(self, address, data, prot=AxiProt.NONSECURE):
return await self.write_if.write_qwords(address, data, prot)
async def write_qwords(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
return await self.write_if.write_qwords(address, data, byteorder, prot)
async def write_byte(self, address, data, prot=AxiProt.NONSECURE):
return await self.write_if.write_byte(address, data, prot)
async def write_word(self, address, data, ws=2, prot=AxiProt.NONSECURE):
return await self.write_if.write_word(address, data, ws, prot)
async def write_word(self, address, data, byteorder='little', ws=2, prot=AxiProt.NONSECURE):
return await self.write_if.write_word(address, data, byteorder, ws, prot)
async def write_dword(self, address, data, prot=AxiProt.NONSECURE):
return await self.write_if.write_dword(address, data, prot)
async def write_dword(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
return await self.write_if.write_dword(address, data, byteorder, prot)
async def write_qword(self, address, data, prot=AxiProt.NONSECURE):
return await self.write_if.write_qword(address, data, prot)
async def write_qword(self, address, data, byteorder='little', prot=AxiProt.NONSECURE):
return await self.write_if.write_qword(address, data, byteorder, prot)