Exemplo n.º 1
0
def test():

    chip = Chip("square_root")

    test_in = Stimulus(chip, "input", "float", [i*0.1 for i in range(100)])
    test_out = Response(chip, "output", "float")
    
    #create a filter component using the C code
    sqrt = Component("sqrt.c")

    #add an instance to the chip
    sqrt(
        chip, 
        inputs = {
            "x":test_in,
        },
        outputs = {
            "sqrt_x":test_out,
        },
    )

    #run the simulation
    chip.simulation_reset()
    while len(test_out) < 100:
        chip.simulation_step()

    pyplot.plot(list(test_in), list(test_out))
    pyplot.xlim(0, 10.1)
    pyplot.title("Square Root of x")
    pyplot.xlabel("x")
    pyplot.ylabel("$\\sqrt{x}$")
    pyplot.savefig("../docs/source/examples/images/example_1.png")
    pyplot.show()
Exemplo n.º 2
0
def test():

    from math import pi
    from numpy import abs
    from scipy import fft
    from scipy.signal import firwin
    from matplotlib import pyplot
    from chips.api.api import Chip, Stimulus, Response, Wire, Component

    #create a chip
    chip = Chip("filter_example")

    #low pass filter half nyquist 50 tap
    kernel = Stimulus(chip, "kernel", "float", firwin(50, 0.5, window="blackman"))

    #impulse response
    input_ = Stimulus(chip, "input", "float", [1.0] + [0.0 for i in range(1024)])
    output = Response(chip, "output", "float")
    
    #create a filter component using the C code
    fir_comp = Component("fir.c")

    #add an instance to the chip
    fir_inst_1 = fir_comp(
        chip, 
        inputs = {
            "a":input_,
            "k":kernel,
        },
        outputs = {
            "z":output,
        },
        parameters = {
            "N":len(kernel)-1,
        },
    )

    #run the simulation
    chip.simulation_reset()
    while len(output) < 1024:
        chip.simulation_step()
        
    #plot the result
    pyplot.semilogy(abs(fft(list(output)))[0:len(output)/2])
    pyplot.title("Magnitude of Impulse Response")
    pyplot.xlim(0, 512)
    pyplot.xlabel("X Sample")
    pyplot.savefig("../docs/source/examples/images/example_6.png")
    pyplot.show()
Exemplo n.º 3
0
def make_chip():
    chip = Chip("user_design")

    #create stimulus and response
    Input(chip, "input_eth_rx")
    Input(chip, "input_rs232_rx")
    Input(chip, "input_switches")
    Input(chip, "input_buttons")
    Input(chip, "input_timer")
    Input(chip, "input_i2c")
    Input(chip, "input_ps2")

    Output(chip, "output_eth_tx")
    Output(chip, "output_rs232_tx")
    Output(chip, "output_leds")
    Output(chip, "output_led_r")
    Output(chip, "output_led_g")
    Output(chip, "output_led_b")
    Output(chip, "output_seven_segment_cathode")
    Output(chip, "output_seven_segment_annode")
    Output(chip, "output_i2c")
    Output(chip, "output_vga")
    Output(chip, "output_audio")

    return chip
Exemplo n.º 4
0
def test():

    chip = Chip("taylor")

    stimulus = arange(-2*pi, 2.0*pi, pi/25)
    x = Stimulus(chip, "x", "double", stimulus)
    sin_x = Response(chip, "sin_x", "double")
    cos_x = Response(chip, "cos_x", "double")
    
    #create a filter component using the C code
    sqrt = Component("taylor.c")

    #add an instance to the chip
    sqrt(
        chip, 
        inputs = {
            "x":x,
        },
        outputs = {
            "sin_x":sin_x,
            "cos_x":cos_x,
        },
    )

    #run the simulation
    chip.simulation_reset()
    while len(cos_x) < len(x):
        chip.simulation_step()

    x = list(x)
    sin_x = list(sin_x)[:100]
    cos_x = list(cos_x)[:100]

    pyplot.xticks(
        [-2.0*pi, -pi, 0, pi,  2.0*pi],
        [r'$-2\pi$', r"$-\pi$", r'$0$', r'$\pi$', r'$2\pi$'])
    pyplot.plot(x, sin_x, label="sin(x)")
    pyplot.plot(x, cos_x, label="cos(x)")
    pyplot.ylim(-1.1, 1.1)
    pyplot.xlim(-2.2 * pi, 2.2 * pi)
    pyplot.title("Trig Functions")
    pyplot.xlabel("x (radians)")
    pyplot.legend(loc="upper left")
    pyplot.savefig("../docs/source/examples/images/example_2.png")
    pyplot.show()
Exemplo n.º 5
0
def test():

    chip = Chip("square_root")

    test_in = Stimulus(chip, "input", "float", [i * 0.1 for i in range(100)])
    test_out = Response(chip, "output", "float")

    #create a filter component using the C code
    sqrt = Component("sqrt.c")

    #add an instance to the chip
    sqrt(
        chip,
        inputs={
            "x": test_in,
        },
        outputs={
            "sqrt_x": test_out,
        },
    )

    #run the simulation
    chip.simulation_reset()
    while len(test_out) < 100:
        chip.simulation_step()

    pyplot.plot(list(test_in), list(test_out))
    pyplot.xlim(0, 10.1)
    pyplot.title("Square Root of x")
    pyplot.xlabel("x")
    pyplot.ylabel("$\\sqrt{x}$")
    pyplot.savefig("../docs/source/examples/images/example_1.png")
    pyplot.show()
Exemplo n.º 6
0
def make_chip():
    chip = Chip("user_design")

    #create stimulus and response
    Input(chip, "input_rs232_rx")
    Output(chip, "output_rs232_tx")
    Input(chip, "input_gps_count")
    Input(chip, "input_gps_rx")
    Output(chip, "output_gps_tx")
    Output(chip, "output_tx_freq")
    Output(chip, "output_tx_am")
    Output(chip, "output_tx_ctl")
    Output(chip, "output_leds")

    return chip
Exemplo n.º 7
0
def make_chip():
    chip = Chip("user_design")

    #create stimulus and response
    Input(chip, "input_eth_rx")
    Input(chip, "input_rs232_rx")
    Input(chip, "input_switches")
    Input(chip, "input_buttons")
    Input(chip, "input_timer")
    Input(chip, "input_ps2")

    Output(chip, "output_eth_tx")
    Output(chip, "output_rs232_tx")
    Output(chip, "output_leds")

    return chip
Exemplo n.º 8
0
def test():

    from math import pi
    from numpy import abs
    from scipy import fft
    from scipy.signal import firwin
    from matplotlib import pyplot
    from chips.api.api import Chip, Stimulus, Response, Wire, Component

    #create a chip
    chip = Chip("filter_example")

    #low pass filter half nyquist 50 tap
    kernel = Stimulus(chip, "kernel", "float",
                      firwin(50, 0.5, window="blackman"))

    #impulse response
    input_ = Stimulus(chip, "input", "float",
                      [1.0] + [0.0 for i in range(1024)])
    output = Response(chip, "output", "float")

    #create a filter component using the C code
    fir_comp = Component("fir.c")

    #add an instance to the chip
    fir_inst_1 = fir_comp(
        chip,
        inputs={
            "a": input_,
            "k": kernel,
        },
        outputs={
            "z": output,
        },
        parameters={
            "N": len(kernel) - 1,
        },
    )

    #run the simulation
    chip.simulation_reset()
    while len(output) < 1024:
        chip.simulation_step()

    #plot the result
    pyplot.semilogy(abs(fft(list(output)))[0:len(output) / 2])
    pyplot.title("Magnitude of Impulse Response")
    pyplot.xlim(0, 512)
    pyplot.xlabel("X Sample")
    pyplot.savefig("../docs/source/examples/images/example_6.png")
    pyplot.show()
Exemplo n.º 9
0
def test():

    chip = Chip("taylor")

    stimulus = arange(-2 * pi, 2.0 * pi, pi / 25)
    x = Stimulus(chip, "x", "double", stimulus)
    sin_x = Response(chip, "sin_x", "double")
    cos_x = Response(chip, "cos_x", "double")

    #create a filter component using the C code
    sqrt = Component("taylor.c")

    #add an instance to the chip
    sqrt(
        chip,
        inputs={
            "x": x,
        },
        outputs={
            "sin_x": sin_x,
            "cos_x": cos_x,
        },
    )

    #run the simulation
    chip.simulation_reset()
    while len(cos_x) < len(x):
        chip.simulation_step()

    x = list(x)
    sin_x = list(sin_x)[:100]
    cos_x = list(cos_x)[:100]

    pyplot.xticks([-2.0 * pi, -pi, 0, pi, 2.0 * pi],
                  [r'$-2\pi$', r"$-\pi$", r'$0$', r'$\pi$', r'$2\pi$'])
    pyplot.plot(x, sin_x, label="sin(x)")
    pyplot.plot(x, cos_x, label="cos(x)")
    pyplot.ylim(-1.1, 1.1)
    pyplot.xlim(-2.2 * pi, 2.2 * pi)
    pyplot.title("Trig Functions")
    pyplot.xlabel("x (radians)")
    pyplot.legend(loc="upper left")
    pyplot.savefig("../docs/source/examples/images/example_2.png")
    pyplot.show()
Exemplo n.º 10
0
def test():

    chip = Chip("fft")

    x_re = [0.0 for i in range(1024)]
    x_im = [0.0 for i in range(1024)]
    x_re[0:63] = [sin(2.0 * pi * (i/64.0)) for i in range(64)]

    x_re = Stimulus(chip, "x_re", "double", x_re)
    x_im = Stimulus(chip, "x_im", "double", x_im)
    fft_x_re = Response(chip, "fft_x_re", "double")
    fft_x_im = Response(chip, "fft_x_im", "double")
    
    #create a filter component using the C code
    fft = Component("fft.c")

    #add an instance to the chip
    fft(
        chip, 
        inputs = {
            "x_re":x_re,
            "x_im":x_im,
        },
        outputs = {
            "fft_x_re":fft_x_re,
            "fft_x_im":fft_x_im,
        },
    )

    #run the simulation
    chip.simulation_reset()
    while len(fft_x_im) < len(x_im):
        chip.simulation_step()

    x_re = list(x_re)
    x_im = list(x_im)
    fft_x_re = list(fft_x_re)[:len(x_re)]
    fft_x_im = list(fft_x_im)[:len(x_im)]

    time_complex = [i + (j*1.0) for i, j in zip(x_re, x_im)]
    numpy_complex = s.fft(time_complex)
    numpy_magnitude = n.abs(numpy_complex)

    chips_complex = [i + (j*1.0j) for i, j in zip(fft_x_re, fft_x_im)]
    chips_magnitude = n.abs(chips_complex)

    f, subplot = pyplot.subplots(3, sharex=True)

    pyplot.subplots_adjust(hspace=1.0)
    subplot[0].plot(x_re, 'g')
    subplot[1].plot(numpy_magnitude, 'r')
    subplot[2].plot(chips_magnitude, 'b')
    pyplot.xlim(0, 1023)
    subplot[0].set_title("Time Domain Signal (64 point sine)")
    subplot[1].set_title("Frequency Spectrum - Numpy")
    subplot[2].set_title("Frequency Spectrum - Chips")
    subplot[0].set_xlabel("Sample")
    subplot[1].set_xlabel("Sample")
    subplot[2].set_xlabel("Sample")
    pyplot.savefig("../docs/source/examples/images/example_5.png")
    pyplot.show()
Exemplo n.º 11
0
               byte = ord(self.buff[0])
               word |= byte & 0xff
               self.buff = self.buff[1:]
           return word
    def ready(self):
        return True

if len(sys.argv) <= 1:
    print "Usage example board *(simulate | compile | build)"
else:
    example = sys.argv[1]
    board = sys.argv[2]

    #create a chip
    #
    chip = Chip("user_design")

    #create stimulus and response
    eth_stim = NetworkIn(chip, "input_eth_rx")
    rs232_stim = Stimulus(chip, "input_rs232_rx", "int", [0])
    switches_stim = Stimulus(chip, "input_switches", "int", [0, 1, 2, 3, 4])
    buttons_stim = Stimulus(chip, "input_buttons", "int", [0])
    timer_stim = Stimulus(chip, "input_timer", "int", [0, 1])
    eth_response = NetworkOut(chip, "output_eth_tx")
    rs232_response = ConsoleOut(chip, "output_rs232_tx")
    led_response = Leds(chip, "output_leds")

    #Create models of user_design inputs

    application = __import__("demo.examples.%s.application"%example, globals(), locals(), ["application"], -1)
    try:
Exemplo n.º 12
0
                return False
            chip.generate_verilog()
            chip.generate_testbench(1000)
            retval = chip.compile_iverilog(True)
            if retval != 0:
                print "....failed in verilog simulation"
                return False

        except C2CHIPError as e:
            print "....compile error"
            print e
        print "....passed"
        return True

    # Test Arbiter
    chip = Chip("test_chip")
    first = [0, 1, 2, 3, 4, 5, 6]
    second = [10, 11, 12, 13, 14, 15, 16]
    expected = [0, 10, 1, 11, 2, 12, 3, 13, 4, 15, 6, 16]
    stream_1 = cycle(chip, first)
    stream_2 = cycle(chip, second)
    stream_3 = cycle(chip, expected)
    assert_all(chip, eq(chip, arbiter(chip, [stream_1, stream_2]), stream_3))
    test_chip(chip, "arbiter")

    # Test Delay
    test = [1, 2, 3, 0]
    expected = [0, 1, 2, 3]
    chip = Chip("test_chip")
    assert_all(chip,
               eq(chip, delay(chip, cycle(chip, test)), cycle(chip, expected)))
Exemplo n.º 13
0
           outputs={
               "tcp_out": tcp_out,
               "cout": stdout[4]
           },
           parameters={})

    line_arbiter(chip, stdout, console_out)


if __name__ == "__main__":

    import sys

    from demo.io_models.network import VirtualNetworkCard, NetworkIn, NetworkOut
    from demo.io_models.console import ConsoleOut
    from chips.components.components import constant
    from chips.utils.debugger import Debugger
    from chips.compiler.exceptions import C2CHIPError
    from chips.api.gui import GuiChip

    try:
        vnc = VirtualNetworkCard()
        chip = Chip("server")
        wire = Wire(chip)
        server(chip, NetworkIn(chip, "eth_in", vnc),
               NetworkOut(chip, "eth_out", vnc), wire, wire,
               ConsoleOut(chip, "stdout"))
        Debugger(chip)
    except C2CHIPError as e:
        print e.message
Exemplo n.º 14
0
                self.buff = self.buff[1:]
            return word

    def ready(self):
        return True


if len(sys.argv) <= 1:
    print "Usage example board *(simulate | compile | build)"
else:
    example = sys.argv[1]
    board = sys.argv[2]

    #create a chip
    #
    chip = Chip("user_design")

    #create stimulus and response
    eth_stim = NetworkIn(chip, "input_eth_rx")
    rs232_stim = Stimulus(chip, "input_rs232_rx", "int", [0])
    switches_stim = Stimulus(chip, "input_switches", "int", [0, 1, 2, 3, 4])
    buttons_stim = Stimulus(chip, "input_buttons", "int", [0])
    timer_stim = Stimulus(chip, "input_timer", "int", [0, 1])
    eth_response = NetworkOut(chip, "output_eth_tx")
    rs232_response = ConsoleOut(chip, "output_rs232_tx")
    led_response = Leds(chip, "output_leds")

    #Create models of user_design inputs

    application = __import__("demo.examples.%s.application" % example,
                             globals(), locals(), ["application"], -1)