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

Release v2.1.0 #16

Merged
merged 9 commits into from
Aug 14, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v2.1.0]

### Changed

* Refactor bit manipulation and remove `myhdl` dependency by @fsagbuya in https://github.com/linien-org/pyrp3/pull/12

## [v2.0.2]

### Fixed

* Don't use setuptools_scm & specify version manually by @doronbehar in https://github.com/linien-org/pyrp3/pull/14

[v2.1.0]: https://github.com/linien-org/pyrp3/compare/v2.0.2...v2.1.0
[v2.0.2]: https://github.com/linien-org/pyrp3/compare/v2.0.1...v2.0.2
4 changes: 3 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ BSD 3-Clause License

Copyright (c) 2016, Pierre Cladé All rights reserved.
Copyright (c) 2018-2019, Benjamin Wiegand All rights reserved.
Copyright (c) 2022, Bastian Leykauf All rights reserved.
Copyright (c) 2022-2024, Bastian Leykauf All rights reserved.
Copyright (c) 2024, Doron Behar All rights reserved.
Copyright (c) 2024, Florian Agbuya All rights reserved.


Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ build-backend = "setuptools.build_meta"

[project]
name = "pyrp3"
version = "2.0.2"
version = "2.1.0"
description = "Python utilities for RedPitaya"
authors = [
{ name = "Pierre Cladé", email = "[email protected]" },
{ name = "Benjamin Wiegand", email = "[email protected]" },
{ name = "Bastian Leykauf", email = "[email protected]" },
{ name = "Doron Behar", email = "[email protected]" },
{ name = "Florian Agbuya", email = "[email protected]" },
]
maintainers = [
{ name = "Bastian Leykauf", email = "[email protected]" },
Expand All @@ -20,7 +21,6 @@ readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"cached_property>=1.5.2,<2.0",
"myhdl>=0.11",
"numpy>=1.21.5,<2.0",
"rpyc>=6.0.0,<7.0",
]
Expand Down
46 changes: 30 additions & 16 deletions pyrp3/instrument.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from math import ceil, log

import numpy as np
from myhdl import intbv

from .enum import Enum
from .memory import MemoryInterface
Expand All @@ -12,23 +11,38 @@ def __init__(self, size):
self.size = size

def to_python(self, val):
return int(val & (2**self.size - 1))
if not 0 <= val < (1 << self.size):
raise ValueError("Input value %s exceeds %s-bit limit" % (val, self.size))
return int(val & ((1 << self.size) - 1))

def to_binary(self, val):
return intbv(val, max=2**self.size, min=0)._val
if not 0 <= val < (1 << self.size):
raise ValueError("Input value %s exceeds %s-bit limit" % (val, self.size))
return val & ((1 << self.size) - 1)


class SignedInteger:
def __init__(self, size):
self.size = size

def to_python(self, val):
return int(intbv(val & (2**self.size - 1), min=0, max=2**self.size).signed())
val &= (1 << self.size) - 1
if val >= (1 << (self.size - 1)):
val -= 1 << self.size
if not -(1 << (self.size - 1)) <= val < (1 << (self.size - 1)):
raise ValueError(
"Input value %s exceeds %s-bit signed limit" % (val, self.size)
)
return int(val)

def to_binary(self, val):
return intbv(val, min=-(2 ** (self.size - 1)), max=2 ** (self.size - 1))[
self.size :
]._val
if not -(1 << (self.size - 1)) <= val < (1 << self.size):
raise ValueError(
"Input value %s exceeds %s-bit signed limit" % (val, self.size)
)
if val < 0:
val += 1 << self.size
return val & ((1 << self.size) - 1)


class EnumTypeWrapper(UnsignedInteger):
Expand Down Expand Up @@ -80,11 +94,10 @@ def to_binary(self, val):
val = val / 1.8
assert val >= 0
assert val <= 1
out = intbv(0, min=0, max=2**32)
tmp = np.long(np.round(val * (17 * 157 - 1)))
out[32:16] = tmp // 17
out[16:0] = 2**tmp % 17 - 1
return out[32:]._val
tmp = np.longlong(np.round(val * (17 * 157 - 1)))
high = tmp // 17
low = (1 << (tmp % 17)) - 1
return (high << 16) | low


class RegisterProperty:
Expand Down Expand Up @@ -128,13 +141,14 @@ def __get__(self, instance, owner):
if instance is None:
return self
out = instance.read(self.addr)
val = intbv(out)[self.pos]
return val if self._bit_type is None else self._bit_type.to_python(val)
val = (out >> self.pos) & 1
return (
bool(val) if self._bit_type is None else self._bit_type.to_python(bool(val))
)

def __set__(self, instance, value):
current = instance.read(self.addr)
new_value = intbv(current)
new_value[self.pos] = value
new_value = current & ~(1 << self.pos) | ((value & 1) << self.pos)
return instance.write(self.addr, int(new_value))


Expand Down