aboutsummaryrefslogtreecommitdiffstats
path: root/fpga_interchange/examples/chipdb_nexus.cmake
blob: 4ea180c568411e2406eb593d2110fff542c531a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function(create_prjoxide_device_db)
    # ~~~
    # create_prjoxide_device_db(
    #    device <common device>
    #    output_target <output device target>
    # )
    # ~~~
    #
    # Generates a device database from Project Oxide
    #
    # If output_target is specified, the output_target_name variable
    # is set to the generated output_device_file target.
    #
    # Arguments:
    #   - device: common device name of a set of parts. E.g. LIFCL-17
    #   - output_target: variable name that will hold the output device target for the parent scope
    #
    # Targets generated:
    #   - prjoxide-<device>-device
    set(options)
    set(oneValueArgs device output_target)
    set(multiValueArgs)

    cmake_parse_arguments(
        create_prjoxide_device_db
        "${options}"
        "${oneValueArgs}"
        "${multiValueArgs}"
        ${ARGN}
    )

    set(device ${create_prjoxide_device_db_device})
    set(output_target ${create_prjoxide_device_db_output_target})
    set(prjoxide_device_db ${CMAKE_CURRENT_BINARY_DIR}/${device}.device)
    add_custom_command(
        OUTPUT ${prjoxide_device_db}
        COMMAND
            ${PRJOXIDE_PREFIX}/bin/prjoxide
            interchange-export
            ${device}
            ${prjoxide_device_db}
        DEPENDS
            ${PRJOXIDE_PREFIX}/bin/prjoxide
    )

    add_custom_target(prjoxide-${device}-device DEPENDS ${prjoxide_device_db})
    set_property(TARGET prjoxide-${device}-device PROPERTY LOCATION ${prjoxide_device_db})

    if (DEFINED output_target)
        set(${output_target} prjoxide-${device}-device PARENT_SCOPE)
    endif()

endfunction()

function(generate_nexus_device_db)
    # ~~~
    # generate_nexus_device_db(
    #    device <common device>
    #    device_target <variable name for device target>
    # )
    # ~~~
    #
    # Generates a chipdb BBA file, starting from a Project Oxide device database.
    # Patches applied:
    #   - primitive library from Yosys
    #
    # Arguments:
    #   - device: common device name of a set of parts. E.g. LIFCL-17
    #   - device_target: variable name that will hold the output device target for the parent scope
    set(options)
    set(oneValueArgs device device_target)
    set(multiValueArgs)

    cmake_parse_arguments(
        generate_nexus_device_db
        "${options}"
        "${oneValueArgs}"
        "${multiValueArgs}"
        ${ARGN}
    )

    set(device ${generate_nexus_device_db_device})
    set(device_target ${generate_nexus_device_db_device_target})

    create_prjoxide_device_db(
        device ${device}
        output_target prjoxide_device
    )

    # Add primitive library
    patch_device_with_prim_lib(
        device ${device}
        yosys_script synth_nexus
        input_device ${prjoxide_device}
        output_target prjoxide_prims_device
    )

    if(DEFINED device_target)
        set(${device_target} ${prjoxide_prims_device} PARENT_SCOPE)
    endif()
endfunction()