Example #1
0
def make_write_enable():
    number_inputs = 16
    device = new_tree_decoder([8,8])
    #device = new_decoder(number_inputs, False)
    device['type'] = 'write_enable'
    device['name'] = 'write_enable_0'
    device_file_path = str(DEVICE_DIR) + '/' + device['type'] + '.json'
    write_json(device, device_file_path)
Example #2
0
def make_or(number_inputs):
    device_data = make_prim_part("or", number_inputs)
    switch_list = ['switch'+str(i) for i in range(number_inputs)]
    wires = device_data['wires']
    set_wire(wires, "sourcetoswitch", ['source0'], switch_list)
    set_wire(wires, "switchtoresistor", switch_list, ['resistor0', 'out'])
    device_file_path = str(DEVICE_DIR) + '/' + 'or' + str(number_inputs) + '.json'
    write_json(device_data, device_file_path)
Example #3
0
def make_write_select():
    '''
    Select writeone or writeo?
    '''
    device = new_mux(1, is_dual=False, in_pre='write', select_pre='select', out='w')
    device['type'] = 'write_select'
    device['name'] = 'write_select0'
    device_file_path = str(DEVICE_DIR) + '/' + device['type'] + '.json'
    write_json(device, device_file_path)
Example #4
0
def make_mem_mux():
    '''
    64x32x32

    '''
    sizes = [6,5,5]
    select_sets = get_select_sets(sizes)
    device = new_mem_mux(select_sets)
    device_file_path = str(DEVICE_DIR) + '/' + device['type'] + '.json'
    write_json(device, device_file_path)
Example #5
0
def make_and(number_inputs):
    device_data = make_prim_part("and", number_inputs)
    wires = device_data['wires']
    set_wire(wires, "sourcetoswitch", ['source0'], ['switch0'])
    for index in range(number_inputs-1):
        i = str(index)
        inext = str(index+1)
        set_wire(wires, "wireswitch"+i+"to"+inext, ['switch'+i], ['switch'+inext])

    set_wire(wires, "switchtoresistor", ['switch'+str(number_inputs-1)], ['resistor0', 'out'])
    device_file_path = str(DEVICE_DIR) + '/' + 'and' + str(number_inputs) + '.json'
    write_json(device_data, device_file_path)
Example #6
0
def make_pc_add():
    wires = []
    devices = []
    device = {
        'wires': wires,
        'type': 'pc_add',
        'name': 'pc_add0',
        'devices': devices
    }

    digits = 10
    half = digits/2

    wires_map = {}
    first = new_add(half)
    first['name'] = 'first'
    second = new_add(half)
    second['name'] = 'second'

    for index in range(half):
        i = str(index)
        aname = "a_"+i
        bname = 'b_'+i
        append_bridge(devices, aname)
        set_wire(wires_map, [aname], ['first/a_'+i])
        append_bridge(devices, "b_"+i)
        set_wire(wires_map, [bname], ['first/b_'+i])

        out = 'o_'+i
        append_bridge(devices, out)
        set_wire(wires_map, ['first/'+out], [out])

    for index in range(half):
        i = str(index)
        offset = str(index+half)
        aname = "a_"+offset
        bname = 'b_'+offset
        append_bridge(devices, aname)
        set_wire(wires_map, [aname], ['second/a_'+i])
        append_bridge(devices, bname)
        set_wire(wires_map, [bname], ['second/b_'+i])

        set_wire
        out = 'o_'+i
        append_bridge(devices, out)
        set_wire(wires_map, ['second/'+out], ['o_'+offset])

    set_wire(wires_map, ['first/c_out'], ['second/c_in'])


    device_file_path = str(DEVICE_DIR) + '/' + device['type'] + '.json'
    write_json(device, device_file_path)
Example #7
0
def make_pc_select():
    
    device = new_pc_select()
    device_file_path = str(DEVICE_DIR) + '/' + device['type'] + '.json'
    write_json(device, device_file_path)
Example #8
0
def make_device(new_function, *args):
    device = new_function(*args)
    device_file_path = str(DEVICE_DIR) + '/' + device['type'] + '.json'
    write_json(device, device_file_path)
Example #9
0
def make_prim_dual(prim_type, number_inputs):
    devices = []
    wires = []
    device_type = prim_type+str(number_inputs)+"dual"
    (ds, ws) = make_prim_part_dual(number_inputs)
    devices.extend(ds)
    wires.extend(ws)
    value_sets = itertools.product([False,True], repeat=number_inputs)
    and_values= []
    logic_function = get_or if prim_type =='or' else get_and
    for value_set_index, value_set in enumerate(value_sets):
        set_i = str(value_set_index)
        and_values.append(logic_function(value_set))

        for index, value in enumerate(value_set):
            i = str(index)
            if value:
                wiredown = get_wire(wires, 'wirenot'+i+"down")
                wireup = get_wire(wires, 'wirein'+i+"up")
            else:
                wiredown = get_wire(wires, 'wirein'+i+"down")
                wireup = get_wire(wires, 'wirenot'+i+"up")
            wiredown['to'].append('and'+set_i+"/in"+str(2*index))
            wireup['to'].append('and'+set_i+"/in"+str(2*index+1))

    ones = 0
    zeros = 0
    for value in and_values:
        if value:
            ones += 1
        else:
            zeros += 1

    if ones > 1:
        devices.append(new_device("or1", "or"+str(ones)))
        wire = {
            "name": "wireor1",
            "from": ["or1/out"],
            "to": ["outup"]
        }
        wires.append(wire)
    if zeros > 1:
        devices.append(new_device("or0", "or"+str(zeros)))
        wire = {
            "name": "wireor0",
            "from": ["or0/out"],
            "to": ["outdown"]
        }
        wires.append(wire)

    onei = 0
    zeroi = 0
    for index, value in enumerate(and_values):
        i = str(index)
        devices.append(new_device("and"+i, "and"+str(number_inputs*2)))
        if value:
            output = "outup" if ones <= 1 else "or1/in"+str(onei)
            set_wire(wires, "wireand" + i, ["and"+i+"/out"], [output])
            onei+=1
        else:
            output = "outdown" if zeros <= 1 else "or0/in"+str(zeroi)
            set_wire(wires, "wireand" + i, ["and"+i+"/out"], [output])
            zeroi+=1
        #TODO only have or gate if there is more than one output

    data = {
        "name": device_type+"0",
        "type": device_type,
        "wires": wires,
        "devices": devices
    }

    device_file_path = str(DEVICE_DIR) + '/' + device_type + '.json'
    write_json(data, device_file_path)
Example #10
0
def make_decoder(number_inputs, is_dual=False):
    data = new_decoder(number_inputs, is_dual)
    device_file_path = str(DEVICE_DIR) + '/' + data['type'] + '.json'
    write_json(data, device_file_path)
Example #11
0
def make_mux(number_selects, is_dual):
    mux = new_mux(number_selects, is_dual)
    device_type = get_mux_type(number_selects, is_dual)
    device_file_path = str(DEVICE_DIR) + '/' + device_type + '.json'
    write_json(mux, device_file_path)
Example #12
0
def make_add(number_inputs):
    device = new_add(number_inputs)
    device_file_path = str(DEVICE_DIR) + '/' + device['type'] + '.json'
    write_json(device, device_file_path)