Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

software: migrate away from bitarray dependency. #376

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions software/glasgow/applet/display/pdi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
import logging
import argparse
import asyncio
from bitarray import bitarray
from glasgow.support.bits import bitarray
from amaranth import *

from ...interface.spi_controller import SPIControllerSubtarget, SPIControllerInterface
Expand Down Expand Up @@ -464,8 +464,7 @@ async def interact(self, device, args, pdi_iface):
image_width, image_height = int(image_size[1]), int(image_size[2])
if image_width != pdi_iface.width or image_height != pdi_iface.height:
raise GlasgowAppletError("image size does not match display size")
image = bitarray()
image.frombytes(args.image_file.read())
image = bitarray(args.image_file.read())

stage_ms = 300

Expand Down
9 changes: 2 additions & 7 deletions software/glasgow/applet/program/xc6s/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import logging
import argparse
from bitarray import bitarray

from ... import *
from ....arch.jtag import *
Expand Down Expand Up @@ -57,13 +56,9 @@ async def reconfigure(self):
raise GlasgowAppletError("configuration reset failed: {}".format(status.bits_repr()))

async def load_bitstream(self, bitstream, *, byte_reverse=True):
bitstream = bits(bitstream)
if byte_reverse:
ba = bitarray()
ba.frombytes(bitstream)
ba.bytereverse()
bitstream = bits(ba.tobytes(), len(ba))
else:
bitstream = bits(bitstream)
bitstream = bitstream.byte_reversed()
self._log("load size=%d [bits]", len(bitstream))
await self.lower.lower.write_ir(IR_CFG_IN)
await self.lower.write_dr(bitstream)
Expand Down
6 changes: 3 additions & 3 deletions software/glasgow/applet/program/xc9500xl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ def fuses_to_words(fuses, device):
if len(fuses) != total_bits:
raise GlasgowAppletError(
"JED file does not have the right fuse count (expected %d, got %d)"
% (total_bits, fuses))
% (total_bits, len(fuses)))

words = []
p = 0
for block in range(blocks):
for word in range(9):
words.append(int.from_bytes(fuses[p:p + 8 * wc].tobytes(), "little"))
words.append(int(fuses[p:p + 8 * wc]))
p += 8 * wc
for word in range(6):
val = []
for sextuplet in range(wc):
val.append(fuses[p:p + 6].tobytes()[0])
val.append(int(fuses[p:p + 6]))
p += 6
words.append(int.from_bytes(bytes(val), "little"))
return words
Expand Down
10 changes: 5 additions & 5 deletions software/glasgow/protocol/jesd3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Accession: G00029

import re
from bitarray import bitarray
from glasgow.support.bits import bitarray


__all__ = ["JESD3Parser", "JESD3ParsingError"]
Expand Down Expand Up @@ -167,7 +167,7 @@ def _on_QF(self, count):
"""Fuse count"""
if self.fuse is not None:
self._parse_error("fuse count specified more than once")
self.fuse = bitarray(int(count, 10), endian="little")
self.fuse = bitarray(0, int(count, 10))

def _on_QP(self, count):
"""Pin count (unsupported and ignored)"""
Expand All @@ -193,7 +193,7 @@ def _on_L(self, index, values):
if self.fuse is None:
self._parse_error("fuse list specified before fuse count")
index = int(index, 10)
values = bitarray(re.sub(r"[ \r\n]", "", values.decode("ascii")), endian="little")
values = bitarray(values.decode("ascii"))
if index + len(values) > len(self.fuse):
self._parse_error("fuse list specifies range [%d:%d] beyond last fuse %d"
% (index, index + len(values), len(self.fuse)))
Expand All @@ -203,7 +203,7 @@ def _on_L(self, index, values):
def _on_C(self, checksum):
"""Fuse checksum"""
expected_checksum = int(checksum, 16)
actual_checksum = sum(self.fuse.tobytes()) & 0xffff
actual_checksum = sum(self.fuse.to_bytes()) & 0xffff
if expected_checksum != actual_checksum:
self._parse_error("fuse checksum mismatch: expected %04X, actual %04X"
% (expected_checksum, actual_checksum))
Expand Down Expand Up @@ -298,4 +298,4 @@ def _on_end(self, checksum):
parser = JESD3Parser(f.read(), quirk_no_design_spec=False)
parser.parse()
for i in range(0, len(parser.fuse) + 63, 64):
print("%08x: %s" % (i, parser.fuse[i:i + 64].to01()))
print(f"{i:08x}: {parser.fuse[i:i + 64]}")