Source code for hwtLib.xilinx.locallink.axis_conv

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from hwt.code import Concat, Switch, If
from hwt.hdl.types.bits import Bits
from hwt.interfaces.utils import addClkRstn, propagateClkRstn
from hwt.synthesizer.param import Param
from hwt.synthesizer.unit import Unit
from hwtLib.amba.axis import AxiStream
from hwtLib.xilinx.locallink.intf import LocalLink
from pyMathBitPrecise.bit_utils import mask


[docs]def strbToRem(strbBits, remBits): for i in range(strbBits): strb = Bits(strbBits).from_py(mask(i + 1)) rem = Bits(remBits).from_py(i) yield strb, rem
[docs]class LocalLinkToAxiS(Unit): """ Framelink to axi-stream format of user signal: user[0]: start of packet user[1]: end of packet .. hwt-autodoc:: """ def _config(self): AxiSToLocalLink._config(self) def _declr(self): with self._paramsShared(): addClkRstn(self) self.dataIn = LocalLink() self.dataOut = AxiStream()._m() def _impl(self): In = self.dataIn Out = self.dataOut sop = self._sig("sop") eop = self._sig("eop") Out.data(In.data) Out.valid(~In.src_rdy_n) In.dst_rdy_n(~Out.ready) Out.last(~In.eof_n) eop(~In.eop_n) sop(~In.sop_n) Out.user(Concat(eop, sop)) strbMap = [] remBits = In.rem._dtype.bit_length() strbBits = Out.strb._dtype.bit_length() for strb, rem in strbToRem(strbBits, remBits): strbMap.append((rem, Out.strb(strb))) Switch(In.rem)\ .add_cases(strbMap)\ .Default(Out.strb(None))
if __name__ == "__main__": from hwt.synthesizer.utils import to_rtl_str u = AxiSToLocalLink() print(to_rtl_str(u))