Example #1
0
def mkLed():
    m = Module('blinkled')
    width = m.Parameter('WIDTH', 8)
    clk = m.Input('CLK')
    rst = m.Input('RST')

    a = fixed.FixedReg(m, 'a', width=16, point=4, initval=4)
    b = fixed.FixedReg(m,
                       'b',
                       width=16,
                       point=8,
                       initval=fixed.FixedConst(1, point=8, raw=True))
    c = fixed.FixedReg(m, 'c', width=32, point=8, initval=-8)
    d = fixed.FixedReg(m,
                       'd',
                       width=32,
                       point=16,
                       initval=fixed.FixedConst(1, point=16, raw=True))
    e = fixed.FixedReg(m, 'e', width=32, point=16, initval=0)

    seq = Seq(m, 'seq', clk, rst)
    seq(a(b - 1), b(a - 1), c.write_raw(b.raw + 1), d.write_raw(c + 1),
        e.inc())

    #    seq.Delay(1)(
    #        Display("a=%h", a),
    #        Display("b=%h", b),
    #        Display("c=%h", c),
    #        Display("d=%h", d),
    #        Display("e=%h", e)
    #    )

    return m
Example #2
0
def mkLed():
    m = Module('blinkled')
    width = m.Parameter('WIDTH', 8)
    clk = m.Input('CLK')
    rst = m.Input('RST')
    led = m.OutputReg('LED', width)
    count = m.Reg('count', 32)

    m.Always(Posedge(clk))(If(rst)(count(0)).Else(
        If(count == 1023)(count(0)).Else(count(count + 1))))

    m.Always(Posedge(clk))(If(rst)(led(0)).Else(
        If(count == 1024 - 1)(led(led + 1))))

    a = fixed.FixedReg(m, 'a', point=6)
    b = fixed.FixedReg(m, 'b', point=8)
    c = fixed.FixedReg(m, 'c', point=4)
    d = fixed.FixedReg(m, 'd', point=8)

    m.Always(Posedge(clk))(If(rst)(a(fixed.FixedConst(Int(2) * Int(2), 6)),
                                   b(fixed.FixedConst(1, 8, raw=True)), c(1),
                                   d.raw(1)).Else(a(a + 1), b(a + 1),
                                                  c.raw(b.raw + 1),
                                                  d.raw((c + 1).raw)))

    return m
Example #3
0
def mkLed():
    m = Module('blinkled')
    width = m.Parameter('WIDTH', 8)
    clk = m.Input('CLK')
    rst = m.Input('RST')

    a = fixed.FixedReg(m, 'a', point=16, signed=False, initval=2)
    b = fixed.FixedReg(m, 'b', point=8, signed=False, initval=16)
    c = fixed.FixedReg(m, 'c', point=16, signed=False, initval=1)
    d = fixed.FixedReg(m, 'd', point=16, signed=False, initval=1)
    sa = fixed.FixedReg(m, 'sa', point=16, initval=2)
    sb = fixed.FixedReg(m, 'sb', point=8, initval=-16)
    sc = fixed.FixedReg(m, 'sc', point=16, initval=-1)
    sd = fixed.FixedReg(m, 'sd', point=16, initval=-1)

    seq = Seq(m, 'seq', clk, rst)
    seq(a(a), b(b), c(b * a), d(a * b), sa(sa), sb(sb), sc(sb * sa),
        sd(fixed.to_signed(a) * sb))

    #    seq.Delay(1)(
    #        Display("a=%h", a),
    #        Display("b=%h", b),
    #        Display("c=%h", c),
    #        Display("d=%h", d),
    #        Display("sa=%h", sa),
    #        Display("sb=%h", sb),
    #        Display("sc=%h", sc),
    #        Display("sd=%h", sd),
    #    )

    return m
Example #4
0
def mkLed():
    m = Module('blinkled')
    clk = m.Input('CLK')
    rst = m.Input('RST')
    led = m.Reg('LED', 8, initval=0)

    count = fx.FixedReg(m, 'count', 8, point=3, initval=0)

    seq = Seq(m, 'seq', clk, rst)
    seq(
        count.inc()
    )

    def blink(times):
        led.value = 0
        next_val = vthread.fixed.FixedConst(0, 8)
        for i in range(times):
            next_val = next_val + 1
            led.value = next_val
            print("led = ", led)

    th = vthread.Thread(m, 'th_blink', clk, rst, blink)
    fsm = th.start(10)

    return m
Example #5
0
 def makeVariableFixed(self, name, width=None, point=0, signed=True):
     signame = _tmp_name('_'.join(['', self.name, name]))
     if width is None:
         width = self.datawidth
     return fxd.FixedReg(self.m,
                         signame,
                         width=width,
                         point=point,
                         signed=signed)
Example #6
0
def mkLed():
    m = Module('blinkled')
    width = m.Parameter('WIDTH', 8)
    clk = m.Input('CLK')
    rst = m.Input('RST')
    led = m.OutputReg('LED', width)
    count = m.Reg('count', 32)

    m.Always(Posedge(clk))(If(rst)(count(0)).Else(
        If(count == 1023)(count(0)).Else(count(count + 1))))

    m.Always(Posedge(clk))(If(rst)(led(0)).Else(
        If(count == 1024 - 1)(led(led + 1))))

    a = fixed.FixedReg(m, 'a', point=4)
    b = fixed.FixedReg(m, 'b', point=8)
    c = fixed.FixedReg(m, 'c', point=16)
    d = fixed.FixedReg(m, 'd', point=6)
    sa = fixed.FixedReg(m, 'sa', point=4, signed=True)
    sb = fixed.FixedReg(m, 'sb', point=8, signed=True)
    sc = fixed.FixedReg(m, 'sc', point=16, signed=True)
    sd = fixed.FixedReg(m, 'sd', point=6, signed=True)

    m.Always(Posedge(clk))(If(rst)(a(fixed.FixedConst(1, 4)),
                                   b(fixed.FixedConst(32, 4, raw=True)),
                                   c(fixed.FixedConst(32, 4, raw=True)),
                                   d(fixed.FixedConst(32, 4, raw=True)),
                                   sa(fixed.FixedConst(1, 4)),
                                   sb(fixed.FixedConst(32, 4, raw=True)),
                                   sc(fixed.FixedConst(32, 4, raw=True)),
                                   sd(fixed.FixedConst(32, 4, raw=True))).Else(
                                       a(a / b), b(a / b), c(a / b), d(b / a),
                                       sa(sa / sb), sb(sa / sb), sc(sa / sb),
                                       sd(sb / sa)))

    return m