├── software
├── otma_bringup
│ ├── mem_init
│ │ └── meminit.qip
│ ├── test
│ │ ├── Makefile
│ │ ├── seatest
│ │ │ ├── license.txt
│ │ │ ├── seatest.h
│ │ │ └── seatest.c
│ │ └── test_IDT8NxQ001.c
│ ├── src
│ │ ├── cli.h
│ │ ├── devices.c
│ │ ├── mem_sw_check.h
│ │ ├── mini_i2cdetect.h
│ │ ├── devices.h
│ │ ├── cli_commands.h
│ │ ├── IDT8NxQ001.h
│ │ ├── main.c
│ │ ├── cli.c
│ │ ├── mini_i2cdetect.c
│ │ ├── mem_sw_check.c
│ │ ├── IDT8NxQ001.c
│ │ └── cli_commands.c
│ ├── .project
│ ├── .settings
│ │ └── language.settings.xml
│ ├── .cproject
│ └── Makefile
└── otma_bringup_bsp
│ ├── .project
│ ├── .settings
│ └── language.settings.xml
│ ├── .cproject
│ └── Makefile
├── qsys
└── system.ipx
├── ip_cores
├── clock_counter
│ ├── clock_counter_sw.tcl
│ ├── inc
│ │ └── clock_counter.h
│ ├── src
│ │ └── clock_counter.c
│ ├── clock_counter.sv
│ └── clock_counter_hw.tcl
├── pcie_status_amm
│ ├── pcie_status_amm_sw.tcl
│ ├── inc
│ │ └── pcie_status_amm.h
│ ├── src
│ │ └── pcie_status_amm.c
│ ├── hdl
│ │ └── pcie_status_amm.sv
│ └── pcie_status_amm_hw.tcl
└── mem_checker
│ ├── mem_checker_sw.tcl
│ ├── inc
│ ├── mem_checker.h
│ └── mem_checker_regs.h
│ ├── mem_checker_hw.tcl
│ └── src
│ └── mem_checker.c
├── README.md
├── .gitignore
├── constraints
└── timing.sdc
├── project
└── otma_bringup.qpf
└── hdl
└── otma_bringup.sv
/software/otma_bringup/mem_init/meminit.qip:
--------------------------------------------------------------------------------
1 | set_global_assignment -name SEARCH_PATH $::quartus(qip_path)
2 |
--------------------------------------------------------------------------------
/qsys/system.ipx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/software/otma_bringup/test/Makefile:
--------------------------------------------------------------------------------
1 |
2 |
3 | all: test_IDT8NxQ001
4 |
5 | test_IDT8NxQ001: obj/IDT8NxQ001.o obj/seatest.o test_IDT8NxQ001.c
6 | gcc -o $@ $^
7 |
8 | obj/seatest.o: seatest/seatest.c obj
9 | gcc -Wall -Wextra -c -o $@ $<
10 |
11 | obj/IDT8NxQ001.o: ../src/IDT8NxQ001.c
12 | gcc -Wall -Wextra -c -o $@ $<
13 |
14 | obj:
15 | mkdir obj
16 |
17 | clean:
18 | rm -f test_IDT8NxQ001 seatest.o
19 |
--------------------------------------------------------------------------------
/ip_cores/clock_counter/clock_counter_sw.tcl:
--------------------------------------------------------------------------------
1 |
2 | create_driver clock_counter_driver
3 |
4 | set_sw_property hw_class_name clock_counter
5 | set_sw_property version 1.0
6 | set_sw_property bsp_subdirectory drivers
7 | set_sw_property min_compatible_hw_version 1.0
8 |
9 | add_sw_property include_source inc/clock_counter.h
10 |
11 | add_sw_property c_source src/clock_counter.c
12 |
13 | add_sw_property supported_bsp_type HAL
14 |
--------------------------------------------------------------------------------
/ip_cores/pcie_status_amm/pcie_status_amm_sw.tcl:
--------------------------------------------------------------------------------
1 |
2 | create_driver pcie_status_amm_driver
3 |
4 | set_sw_property hw_class_name pcie_status_amm
5 | set_sw_property version 1.0
6 | set_sw_property bsp_subdirectory drivers
7 | set_sw_property min_compatible_hw_version 1.0
8 |
9 | add_sw_property include_source inc/pcie_status_amm.h
10 |
11 | add_sw_property c_source src/pcie_status_amm.c
12 |
13 | add_sw_property supported_bsp_type HAL
14 |
--------------------------------------------------------------------------------
/ip_cores/mem_checker/mem_checker_sw.tcl:
--------------------------------------------------------------------------------
1 |
2 | create_driver mem_checker_driver
3 |
4 | set_sw_property hw_class_name mem_checker
5 | set_sw_property version 1.1
6 | set_sw_property bsp_subdirectory drivers
7 | set_sw_property min_compatible_hw_version 0.1
8 |
9 | add_sw_property include_source inc/mem_checker.h
10 | add_sw_property include_source inc/mem_checker_regs.h
11 |
12 | add_sw_property c_source src/mem_checker.c
13 |
14 | add_sw_property supported_bsp_type HAL
15 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Unofficial Pikes Peak/Storey Peak reference design
2 |
3 | ## Software generation
4 |
5 | Here are the commands which were used to generate software project. Maybe this
6 | can be useful when setting up single-script build for CI.
7 |
8 | ### Generate BSP
9 |
10 | ```
11 | nios2-bsp hal . ../../qsys/system.sopcinfo --cpu-name nios2_gen2_0 --type-version 16.1
12 | ```
13 |
14 | ### Generate application
15 |
16 | ```
17 | nios2-app-generate-makefile --app-dir . --bsp-dir ../otma_bringup_bsp --elf-name
18 | ```
19 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | *.bak
3 | *.rpt
4 | *~
5 |
6 | */.qsys_edit/
7 |
8 | /project/db/
9 | /project/incremental_db/
10 | /project/output_files/
11 |
12 | /qsys/system/
13 | /qsys/system.sopcinfo
14 |
15 | /software/*_bsp/alt_sys_init.c
16 | /software/*_bsp/drivers/
17 | /software/*_bsp/HAL/
18 | /software/*_bsp/linker.h
19 | /software/*_bsp/linker.x
20 | /software/*_bsp/mem_init.mk
21 | /software/*_bsp/memory.gdb
22 | /software/*_bsp/public.mk
23 | /software/*_bsp/summary.html
24 | /software/*_bsp/system.h
25 | /software/**/*.a
26 | /software/**/*.elf
27 | /software/**/*.objdump
28 | /software/**/obj/
29 | /software/.metadata/
30 |
--------------------------------------------------------------------------------
/constraints/timing.sdc:
--------------------------------------------------------------------------------
1 |
2 | # Clocks
3 | #create_clock -name clk_125 -period 8 [get_ports CLK_125M]
4 | create_clock -name clk_xcvr_ref -period 1.551 [get_ports CLK_QSFP_OSC]
5 | create_clock -name clk_pcie1 -period 10 [get_ports CLK_PCIE1]
6 | create_clock -name clk_pcie2 -period 10 [get_ports CLK_PCIE2]
7 |
8 | derive_pll_clocks
9 | derive_clock_uncertainty
10 |
11 | # Exceptions
12 | set_false_path -to [get_ports {LEDS[*]}]
13 |
14 | set_false_path -to {system:inst_system|clock_counter:clock_counter_0|reg_clk_meas[*][*]}
15 | set_false_path -to {system:inst_system|clock_counter:clock_counter_0|pulse_1hz_p[*]}
16 | set_false_path -to {system:inst_system|clock_counter:clock_counter_0|avs_ctrl_readdata[*]}
17 |
18 | set_false_path -to {inst_system|pcie1_status_amm|status_reg[*]}
19 | set_false_path -to {inst_system|pcie2_status_amm|status_reg[*]}
20 |
21 | set_false_path -from {system:inst_system|system_pio_pcie_npor:pio_pcie_npor|data_out}
22 |
--------------------------------------------------------------------------------
/software/otma_bringup_bsp/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | otma_bringup_bsp
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
10 | clean,full,incremental,
11 |
12 |
13 |
14 |
15 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
16 | full,incremental,
17 |
18 |
19 |
20 |
21 |
22 | org.eclipse.cdt.core.cnature
23 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
24 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
25 | org.eclipse.cdt.core.ccnature
26 | com.altera.sbtgui.project.SBTGUINature
27 | com.altera.sbtgui.project.SBTGUIBspNature
28 |
29 |
30 |
--------------------------------------------------------------------------------
/software/otma_bringup_bsp/.settings/language.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/software/otma_bringup/test/seatest/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2010 Keith Nicholas
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is
8 | furnished to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in
11 | all copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
--------------------------------------------------------------------------------
/software/otma_bringup/src/cli.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | void cli(void);
26 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/devices.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include "devices.h"
24 |
25 | struct devices devices;
26 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/mem_sw_check.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 |
27 | void mem_sw_check_128b_cntr(uint32_t size_bytes);
28 |
29 | void mem_sw_write_32b_cntr(uint32_t size_bytes);
30 |
31 | void mem_sw_inj_err(void);
32 |
--------------------------------------------------------------------------------
/ip_cores/clock_counter/inc/clock_counter.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 |
27 | void clock_counter_get_info(uint32_t base, uint32_t *ident_reg,
28 | uint32_t *version);
29 |
30 | uint32_t clock_counter_get_freq(uint32_t base, int clk_index);
31 |
--------------------------------------------------------------------------------
/software/otma_bringup/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | otma_bringup
4 |
5 |
6 |
7 |
8 |
9 | com.altera.sbtgui.project.makefileBuilder
10 |
11 |
12 |
13 |
14 | com.altera.sbtgui.project.makefileBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
20 | clean,full,incremental,
21 |
22 |
23 |
24 |
25 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
26 | full,incremental,
27 |
28 |
29 |
30 |
31 |
32 | org.eclipse.cdt.core.cnature
33 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
34 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
35 | org.eclipse.cdt.core.ccnature
36 | com.altera.sbtgui.project.SBTGUINature
37 | com.altera.sbtgui.project.SBTGUIAppNature
38 | com.altera.sbtgui.project.SBTGUIManagedNature
39 |
40 |
41 |
--------------------------------------------------------------------------------
/project/otma_bringup.qpf:
--------------------------------------------------------------------------------
1 | # -------------------------------------------------------------------------- #
2 | #
3 | # Copyright (C) 2016 Intel Corporation. All rights reserved.
4 | # Your use of Intel Corporation's design tools, logic functions
5 | # and other software and tools, and its AMPP partner logic
6 | # functions, and any output files from any of the foregoing
7 | # (including device programming or simulation files), and any
8 | # associated documentation or information are expressly subject
9 | # to the terms and conditions of the Intel Program License
10 | # Subscription Agreement, the Intel Quartus Prime License Agreement,
11 | # the Intel MegaCore Function License Agreement, or other
12 | # applicable license agreement, including, without limitation,
13 | # that your use is for the sole purpose of programming logic
14 | # devices manufactured by Intel and sold by Intel or its
15 | # authorized distributors. Please refer to the applicable
16 | # agreement for further details.
17 | #
18 | # -------------------------------------------------------------------------- #
19 | #
20 | # Quartus Prime
21 | # Version 16.1.0 Build 196 10/24/2016 SJ Standard Edition
22 | # Date created = 14:04:51 August 29, 2020
23 | #
24 | # -------------------------------------------------------------------------- #
25 |
26 | QUARTUS_VERSION = "16.1"
27 | DATE = "14:04:51 August 29, 2020"
28 |
29 | # Revisions
30 |
31 | PROJECT_REVISION = "otma_bringup"
32 |
--------------------------------------------------------------------------------
/software/otma_bringup/.settings/language.settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/mini_i2cdetect.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 |
27 | #include "altera_avalon_i2c.h"
28 |
29 | void mini_i2cdetect(ALT_AVALON_I2C_DEV_t *i2c_dev, uint16_t start_addr,
30 | uint16_t stop_addr);
31 |
32 | void mini_i2cdump(ALT_AVALON_I2C_DEV_t *i2c_dev, uint8_t addr);
33 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/devices.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include "altera_avalon_i2c.h"
26 |
27 | struct devices {
28 | ALT_AVALON_I2C_DEV_t *i2c_dev_idt;
29 | ALT_AVALON_I2C_DEV_t *i2c_dev_qsfp0;
30 | ALT_AVALON_I2C_DEV_t *i2c_dev_qsfp1;
31 | ALT_AVALON_I2C_DEV_t *i2c_dev_mon;
32 | };
33 |
34 | extern struct devices devices;
35 |
--------------------------------------------------------------------------------
/ip_cores/pcie_status_amm/inc/pcie_status_amm.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 |
27 | struct pcie_status {
28 | uint32_t currentspeed : 2;
29 | uint32_t rsvd2 : 6;
30 | uint32_t ltssmstate : 5;
31 | uint32_t rsvd13 : 3;
32 | uint32_t lane_act : 4;
33 | uint32_t rsvd20 : 4;
34 | uint32_t dlup : 1;
35 | uint32_t rsvd25 : 7;
36 | };
37 |
38 | void pcie_status_id_version(uint32_t base, uint32_t *id_reg, uint32_t *version);
39 |
40 | struct pcie_status pcie_status_get(uint32_t base);
--------------------------------------------------------------------------------
/ip_cores/clock_counter/src/clock_counter.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include "io.h"
24 |
25 | #include "clock_counter.h"
26 |
27 | void clock_counter_get_info(uint32_t base, uint32_t *ident_reg,
28 | uint32_t *version) {
29 | if (ident_reg) {
30 | *ident_reg = IORD_32DIRECT(base, 0);
31 | }
32 |
33 | if (version) {
34 | *version = IORD_32DIRECT(base, 4);
35 | }
36 | }
37 |
38 | uint32_t clock_counter_get_freq(uint32_t base, int clk_index) {
39 | return IORD_32DIRECT(base, 0x10 + clk_index * 4);
40 | }
41 |
--------------------------------------------------------------------------------
/ip_cores/pcie_status_amm/src/pcie_status_amm.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include "io.h"
24 |
25 | #include "pcie_status_amm.h"
26 |
27 | void pcie_status_id_version(uint32_t base, uint32_t *id_reg,
28 | uint32_t *version) {
29 | if (id_reg) {
30 | *id_reg = IORD_32DIRECT(base, 0);
31 | }
32 |
33 | if (version) {
34 | *version = IORD_32DIRECT(base, 4);
35 | }
36 | }
37 |
38 | struct pcie_status pcie_status_get(uint32_t base) {
39 | struct pcie_status status;
40 | *(uint32_t *)&status = IORD_32DIRECT(base, 0x10);
41 |
42 | return status;
43 | }
44 |
--------------------------------------------------------------------------------
/ip_cores/mem_checker/inc/mem_checker.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 |
27 | enum mem_check_mode {
28 | MEM_CHECK_MODE_ALL_0,
29 | MEM_CHECK_MODE_ALL_1,
30 | MEM_CHECK_MODE_WALK_0,
31 | MEM_CHECK_MODE_WALK_1,
32 | MEM_CHECK_MODE_ALT,
33 | MEM_CHECK_MODE_CNTR_8,
34 | MEM_CHECK_MODE_CNTR_32,
35 | MEM_CHECK_MODE_CNTR_128
36 | };
37 |
38 | int mem_check_write(uint32_t base, uint64_t mem_address, uint32_t mem_size, enum mem_check_mode mode);
39 |
40 | int mem_check_read_and_check(uint32_t base, uint64_t mem_address, uint32_t mem_size, enum mem_check_mode mode);
41 |
42 | int mem_check_full(uint32_t base, uint64_t mem_address, uint32_t mem_size);
43 |
--------------------------------------------------------------------------------
/ip_cores/mem_checker/inc/mem_checker_regs.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #define ADDR_ID (0x0)
26 | #define ADDR_VERSION (0x4)
27 | #define ADDR_CONF (0x8)
28 | #define ADDR_CTRL (0x10)
29 | #define ADDR_READ_STATUS (0x20)
30 | #define ADDR_READ_CTRL (0x24)
31 | #define ADDR_READ_ADDR_LO (0x28)
32 | #define ADDR_READ_ADDR_HI (0x2c)
33 | #define ADDR_READ_LEN (0x30)
34 | #define ADDR_READ_RESP_CNTR (0x34)
35 | #define ADDR_READ_DURATION (0x38)
36 | #define ADDR_WRITE_STATUS (0x60)
37 | #define ADDR_WRITE_CTRL (0x64)
38 | #define ADDR_WRITE_ADDR_LO (0x68)
39 | #define ADDR_WRITE_ADDR_HI (0x6c)
40 | #define ADDR_WRITE_LEN (0x70)
41 | #define ADDR_WRITE_RESP_CNTR (0x74)
42 | #define ADDR_WRITE_DURATION (0x78)
43 | #define ADDR_CHECK_TOT (0xa0)
44 | #define ADDR_CHECK_OK (0xa4)
45 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/cli_commands.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 |
27 | typedef void (*cli_func_ptr)(char *, char *, char *);
28 |
29 | struct cmd {
30 | const char *cmd;
31 | const char *help;
32 | cli_func_ptr func;
33 | };
34 |
35 | extern struct cmd cmds[];
36 | extern size_t cmds_len;
37 |
38 | void cmd_clks(char *cmd, char *arg1, char *arg2);
39 | void cmd_eeprom(char *cmd, char *arg1, char *arg2);
40 | void cmd_hello(char *cmd, char *arg1, char *arg2);
41 | void cmd_help(char *cmd, char *arg1, char *arg2);
42 | void cmd_i2cdetect(char *cmd, char *arg1, char *arg2);
43 | void cmd_idt(char *cmd, char *arg1, char *arg2);
44 | void cmd_mem_test(char *cmd, char *arg1, char *arg2);
45 | void cmd_pcie(char *cmd, char *arg1, char *arg2);
46 | void cmd_sys_id(char *cmd, char *arg1, char *arg2);
47 |
--------------------------------------------------------------------------------
/software/otma_bringup/test/test_IDT8NxQ001.c:
--------------------------------------------------------------------------------
1 |
2 | #include "seatest/seatest.h"
3 |
4 | #include "../src/IDT8NxQ001.h"
5 |
6 | const int IDT8NXQ001_MINT_MAX = (1 << 6) - 1;
7 | const int IDT8NXQ001_MFRAC_MAX = (1 << 18) - 1;
8 | const int IDT8NXQ001_N_MAX = (1 << 7) - 1;
9 | const int IDT8NXQ001_P_MAX = (1 << 2) - 1;
10 | const int IDT8NXQ001_DSM_MAX = (1 << 2) - 1;
11 | const int IDT8NXQ001_CP_MAX = (1 << 2) - 1;
12 |
13 | void test_dec_enc(void) {
14 | uint8_t in_bytes[IDT8NXQ001_REG_SIZE] = {
15 | 0x06, 0x4e, 0x9e, 0xfe, 10, 20, 30, 40,
16 | 1, 2, 3, 4, 10, 12, 14, 16,
17 | 0, 0, 0x80, 0, 0x1f, 0x1f | 0x40, 0x1f | 0x80, 0x1f | 0xc0};
18 | uint8_t out_bytes[IDT8NXQ001_REG_SIZE] = {0};
19 | struct idt8nxq001_conf conf;
20 |
21 | idt8nxq001_decode_conf(in_bytes, &conf);
22 |
23 | idt8nxq001_conf_print(&conf);
24 |
25 | assert_int_equal(0x3, conf.MINT[0]);
26 | assert_int_equal(0x7, conf.MINT[1]);
27 | assert_int_equal(0xF, conf.MINT[2]);
28 | assert_int_equal(0x1F, conf.MINT[3]);
29 | assert_int_equal(10 * 512 + 1 * 2, conf.MFRAC[0]);
30 | assert_int_equal(20 * 512 + 2 * 2, conf.MFRAC[1]);
31 | assert_int_equal(30 * 512 + 3 * 2, conf.MFRAC[2]);
32 | assert_int_equal(40 * 512 + 4 * 2, conf.MFRAC[3]);
33 | assert_int_equal(10, conf.N[0]);
34 | assert_int_equal(12, conf.N[1]);
35 | assert_int_equal(14, conf.N[2]);
36 | assert_int_equal(16, conf.N[3]);
37 | assert_true(conf.ADC_ENA);
38 | assert_false(conf.nPLL_BYP);
39 |
40 | idt8nxq001_encode_conf(&conf, out_bytes);
41 |
42 | assert_n_array_equal(in_bytes, out_bytes, IDT8NXQ001_REG_SIZE);
43 | }
44 |
45 | void test_enc_dec_0() {
46 | struct idt8nxq001_conf in_conf = {.MINT = {12, 20, 28, 30}};
47 | uint8_t bytes[IDT8NXQ001_REG_SIZE] = {0};
48 | struct idt8nxq001_conf out_conf;
49 |
50 | idt8nxq001_encode_conf(&in_conf, bytes);
51 | idt8nxq001_decode_conf(bytes, &out_conf);
52 |
53 | idt8nxq001_conf_print(&out_conf);
54 |
55 | assert_n_array_equal(((uint8_t *)&out_conf), ((uint8_t *)&in_conf),
56 | IDT8NXQ001_REG_SIZE);
57 | }
58 |
59 | void all_tests(void) {
60 | test_fixture_start();
61 | run_test(test_dec_enc);
62 | run_test(test_enc_dec_0);
63 | test_fixture_end();
64 | }
65 |
66 | int main(int argc, char **argv) {
67 | return seatest_testrunner(argc, argv, all_tests, NULL, NULL);
68 | }
69 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/IDT8NxQ001.h:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #pragma once
24 |
25 | #include
26 | #include
27 |
28 | #define IDT8NXQ001_NR_CH (4)
29 | #define IDT8NXQ001_REG_SIZE (24)
30 |
31 | struct idt8nxq001_conf {
32 | uint8_t MINT[IDT8NXQ001_NR_CH];
33 | uint32_t MFRAC[IDT8NXQ001_NR_CH];
34 | uint8_t N[IDT8NXQ001_NR_CH];
35 | uint8_t P[IDT8NXQ001_NR_CH];
36 | bool DG[IDT8NXQ001_NR_CH];
37 | uint8_t DSM[IDT8NXQ001_NR_CH];
38 | bool DSM_ENA[IDT8NXQ001_NR_CH];
39 | bool LF[IDT8NXQ001_NR_CH];
40 | uint8_t CP[IDT8NXQ001_NR_CH];
41 | uint8_t FSEL;
42 | bool nPLL_BYP;
43 | bool ADC_ENA;
44 | };
45 |
46 | enum IDT8NXQ001_FREQ {
47 | IDT8NXQ001_FREQ_100M = 0,
48 | IDT8NXQ001_FREQ_125M,
49 | IDT8NXQ001_FREQ_156p25M,
50 | IDT8NXQ001_FREQ_200M,
51 | IDT8NXQ001_FREQ_300M,
52 | IDT8NXQ001_FREQ_312p5M,
53 | IDT8NXQ001_FREQ_COUNT
54 | };
55 |
56 | void idt8nxq001_decode_conf(const uint8_t conf_bytes[IDT8NXQ001_REG_SIZE],
57 | struct idt8nxq001_conf *conf);
58 |
59 | void idt8nxq001_encode_conf(const struct idt8nxq001_conf *conf,
60 | uint8_t conf_bytes[IDT8NXQ001_REG_SIZE]);
61 |
62 | void idt8nxq001_conf_print(const struct idt8nxq001_conf *conf);
63 |
64 | void idt8nxq001_set_freq(struct idt8nxq001_conf *conf, unsigned int ch_sel,
65 | enum IDT8NXQ001_FREQ freq);
66 |
67 | void idt8nxq001_set_fsel(struct idt8nxq001_conf *conf, uint8_t fsel);
68 |
--------------------------------------------------------------------------------
/ip_cores/pcie_status_amm/hdl/pcie_status_amm.sv:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | module pcie_status_amm (
24 | input clk,
25 | input rsi_reset_reset,
26 |
27 | input [ 3:0] avs_ctrl_address,
28 | input avs_ctrl_read,
29 | output logic [31:0] avs_ctrl_readdata,
30 |
31 | input [1:0] hip_currentspeed_currentspeed,
32 |
33 | input [4:0] hip_status_ltssmstate,
34 | input [3:0] hip_status_lane_act,
35 | input hip_status_dlup
36 | );
37 |
38 | logic [31:0] status_reg;
39 | logic [31:0] status_reg_s;
40 |
41 | always_ff @(posedge clk) begin : proc_status_reg
42 | status_reg[1:0] <= hip_currentspeed_currentspeed;
43 | status_reg[7:2] <= 'd0;
44 | status_reg[12:8] <= hip_status_ltssmstate;
45 | status_reg[15:13] <= 'd0;
46 | status_reg[19:16] <= hip_status_lane_act;
47 | status_reg[23:20] <= 'd0;
48 | status_reg[24:24] <= hip_status_dlup;
49 | status_reg[31:25] <= 'd0;
50 | end
51 |
52 |
53 | always_ff @(posedge clk) begin : proc_status_reg_s
54 | status_reg_s <= status_reg;
55 | end
56 |
57 | always_ff @(posedge clk) begin : proc_readdata
58 | if (avs_ctrl_read) begin
59 | case (avs_ctrl_address)
60 | 0: avs_ctrl_readdata <= 32'h2c1e57a7; // PCIE STAT
61 | 1: avs_ctrl_readdata <= 32'h00010000;
62 | 4: avs_ctrl_readdata <= status_reg_s;
63 | default: avs_ctrl_readdata <= 32'hdeadbeef;
64 | endcase
65 | end
66 | end
67 |
68 | endmodule
69 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/main.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 |
28 | #include "altera_avalon_i2c.h"
29 | #include "altera_avalon_pio_regs.h"
30 | #include "io.h"
31 | #include "sys/alt_stdio.h"
32 | #include "system.h"
33 |
34 | #include "cli.h"
35 | #include "devices.h"
36 |
37 | void blink_loop_error() {
38 | while (1) {
39 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 1);
40 | usleep(1e5);
41 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_LED_BASE, 0);
42 | usleep(1e5);
43 | }
44 | }
45 |
46 | void init_leds() {
47 | // set LED GPIO as output
48 | IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_LED_BASE, 0x3);
49 | }
50 |
51 | void init_i2c_single(ALT_AVALON_I2C_DEV_t **i2c_dev, const char *name) {
52 | int rc;
53 |
54 | *i2c_dev = alt_avalon_i2c_open(name);
55 | if (*i2c_dev == NULL) {
56 | alt_printf("init_i2c_single: error - could not open device %s\n", name);
57 | blink_loop_error();
58 | }
59 |
60 | ALT_AVALON_I2C_MASTER_CONFIG_t i2c_idt_cfg = {
61 | .addr_mode = ALT_AVALON_I2C_ADDR_MODE_7_BIT,
62 | .speed_mode = ALT_AVALON_I2C_SPEED_STANDARD,
63 | };
64 |
65 | rc = alt_avalon_i2c_master_config_speed_set(*i2c_dev, &i2c_idt_cfg, 400000);
66 | if (rc != ALT_AVALON_I2C_SUCCESS) {
67 | alt_printf("init_i2c_single: error - config speed set failed\n");
68 | blink_loop_error();
69 | }
70 | alt_avalon_i2c_master_config_set(*i2c_dev, &i2c_idt_cfg);
71 | }
72 |
73 | void init_i2cs(void) {
74 |
75 | init_i2c_single(&devices.i2c_dev_idt, I2C_IDT_OSC_NAME);
76 | init_i2c_single(&devices.i2c_dev_qsfp0, I2C_QSFP_0_NAME);
77 | init_i2c_single(&devices.i2c_dev_qsfp1, I2C_QSFP_1_NAME);
78 | init_i2c_single(&devices.i2c_dev_mon, I2C_MON_NAME);
79 | }
80 |
81 | int main() {
82 | init_leds();
83 | init_i2cs();
84 |
85 | alt_printf("init done\n");
86 | while (true) {
87 | cli();
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/ip_cores/clock_counter/clock_counter.sv:
--------------------------------------------------------------------------------
1 |
2 |
3 | module clock_counter # (
4 | parameter int CLK_FREQ = 125000000
5 | ) (
6 | // Clock and reset
7 | input csi_clk_clk,
8 | input rsi_reset_reset,
9 |
10 | // slave interface
11 | input [ 3:0] avs_ctrl_address,
12 | input avs_ctrl_read,
13 | input avs_ctrl_write,
14 | output reg [31:0] avs_ctrl_readdata,
15 | input [31:0] avs_ctrl_writedata,
16 |
17 | // measurements inputs
18 | input [ 7:0] coe_meas,
19 |
20 | // debug led
21 | output coe_led_dbg
22 | );
23 |
24 | //==============================================================================
25 | // Connections
26 |
27 | wire clk = csi_clk_clk;
28 |
29 | //==============================================================================
30 | // Avalon interface
31 |
32 | logic [31:0] reg_scratch;
33 | logic [31:0] reg_clk_meas [0:7];
34 |
35 |
36 | always_ff @(posedge clk) begin: proc_avs_ctrl_readdata
37 | case (avs_ctrl_address)
38 | 0: avs_ctrl_readdata <= 32'hc10cc272;
39 | 1: avs_ctrl_readdata <= 32'h00010000;
40 | 2: avs_ctrl_readdata <= 32'h00000000;
41 | 3: avs_ctrl_readdata <= reg_scratch;
42 | 4: avs_ctrl_readdata <= reg_clk_meas[0];
43 | 5: avs_ctrl_readdata <= reg_clk_meas[1];
44 | 6: avs_ctrl_readdata <= reg_clk_meas[2];
45 | 7: avs_ctrl_readdata <= reg_clk_meas[3];
46 | 8: avs_ctrl_readdata <= reg_clk_meas[4];
47 | 9: avs_ctrl_readdata <= reg_clk_meas[5];
48 | 10: avs_ctrl_readdata <= reg_clk_meas[6];
49 | 11: avs_ctrl_readdata <= reg_clk_meas[7];
50 | default: avs_ctrl_readdata <= 32'hdeadbeef;
51 | endcase
52 | end
53 |
54 | always_ff @(posedge clk) begin: proc_reg_scratch
55 | if (avs_ctrl_write && (avs_ctrl_address == 3)) begin
56 | reg_scratch <= avs_ctrl_writedata;
57 | end
58 | end
59 |
60 | //==============================================================================
61 | // 1 Hz pulse
62 |
63 | logic pulse_1hz = 1'b0;
64 | logic [$clog2(CLK_FREQ)-1:0] cntr_pulse_1hz = 'd0;
65 |
66 | assign coe_led_dbg = pulse_1hz;
67 |
68 | always_ff @(posedge clk) begin: proc_pulse_1hz
69 | if (cntr_pulse_1hz < CLK_FREQ-1) begin
70 | cntr_pulse_1hz <= cntr_pulse_1hz + 1'd1;
71 | end else begin
72 | cntr_pulse_1hz <= 0;
73 | pulse_1hz <= !pulse_1hz;
74 | end
75 | end
76 |
77 | //==============================================================================
78 | // counters
79 |
80 | logic pulse_1hz_p[0:7], pulse_1hz_pp[0:7], pulse_1hz_ppp[0:7];
81 | logic [31:0] clk_cntr[0:7];
82 |
83 | genvar i;
84 |
85 | generate
86 | for (i = 0; i < 8; i++) begin: gen_cntr
87 | always_ff @(posedge coe_meas[i]) begin: proc_pulse_sync
88 | pulse_1hz_p[i] <= pulse_1hz;
89 | pulse_1hz_pp[i] <= pulse_1hz_p[i];
90 | pulse_1hz_ppp[i] <= pulse_1hz_pp[i];
91 | end
92 |
93 | always_ff @(posedge coe_meas[i]) begin: proc_cntr
94 | if (pulse_1hz_ppp[i] != pulse_1hz_pp[i]) begin
95 | clk_cntr[i] <= 0;
96 | reg_clk_meas[i] <= clk_cntr[i]; // store measurement
97 | end else begin
98 | clk_cntr[i] <= clk_cntr[i] + 1;
99 | end
100 | end
101 | end
102 | endgenerate
103 |
104 | endmodule
105 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/cli.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | #include "sys/alt_stdio.h"
28 | #include "system.h"
29 |
30 | #include "cli_commands.h"
31 |
32 | #define CLI_PROMPT ("pp_sp_example > ")
33 | #define CLI_BUFFER_SIZE (32)
34 |
35 | static void simple_sscanf(char *cmd_args, char *cmd, char *arg1, char *arg2) {
36 | char *dests[] = {cmd, arg1, arg2};
37 | int dest_sel = 0;
38 |
39 | while (*cmd_args) {
40 | if (*cmd_args == ' ') {
41 | if (dest_sel < sizeof(dests) / sizeof(dests[0])) {
42 | dest_sel++;
43 | } else {
44 | return;
45 | }
46 | } else {
47 | *(dests[dest_sel]) = *cmd_args;
48 | dests[dest_sel]++;
49 | }
50 | cmd_args++;
51 | }
52 | }
53 |
54 | void cli(void) {
55 |
56 | // read clock counter ID and version
57 | char cmd_buf[CLI_BUFFER_SIZE] = {0};
58 | int pos = 0;
59 |
60 | alt_printf(CLI_PROMPT);
61 | while (1) {
62 | char recv_char = alt_getchar();
63 |
64 | // echo
65 | alt_putchar(recv_char);
66 |
67 | // check if end of the command
68 | if (recv_char == '\n') {
69 |
70 | // split the string into individual parts (command + arguments)
71 | char cmd[CLI_BUFFER_SIZE] = {0};
72 | char arg1[CLI_BUFFER_SIZE] = {0};
73 | char arg2[CLI_BUFFER_SIZE] = {0};
74 | simple_sscanf(cmd_buf, cmd, arg1, arg2);
75 |
76 | // traverse all commands
77 | bool matched = false;
78 | for (int i = 0; i < cmds_len; i++) {
79 | if (strcmp(cmd, cmds[i].cmd) == 0) {
80 | matched = true;
81 |
82 | cmds[i].func(cmd, arg1, arg2);
83 | }
84 | }
85 |
86 | // user command did not match any command in the command list
87 | if (!matched) {
88 | alt_printf("unknown command: %s\n", cmd_buf);
89 | }
90 |
91 | // clean-up and print prompt
92 | memset(cmd_buf, 0, sizeof(cmd_buf));
93 | pos = 0;
94 | alt_printf(CLI_PROMPT);
95 | } else {
96 | cmd_buf[pos] = recv_char;
97 | pos++;
98 | }
99 |
100 | // handle the case when we filled the buffer before seeing a new line
101 | if (pos >= sizeof(cmd_buf) - 1) {
102 | alt_printf("unknown command: %s\n", cmd_buf);
103 | memset(cmd_buf, 0, sizeof(cmd_buf));
104 | pos = 0;
105 | alt_printf(CLI_PROMPT);
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/mini_i2cdetect.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include
24 | #include
25 |
26 | #include "altera_avalon_i2c.h"
27 | #include "sys/alt_stdio.h"
28 |
29 | #include "mini_i2cdetect.h"
30 |
31 | void mini_i2cdetect(ALT_AVALON_I2C_DEV_t *i2c_dev, uint16_t start_addr,
32 | uint16_t stop_addr) {
33 |
34 | const int LINE_LEN = 16;
35 | uint8_t rx_buf[1];
36 |
37 | // print header for the first line (if not aligned to LINE_LEN
38 | if ((start_addr % LINE_LEN) != 0) {
39 | if (start_addr < LINE_LEN) {
40 | alt_printf(" ");
41 | }
42 | alt_printf(" %x | ", 0);
43 | }
44 | // print empty spaces for alignment
45 | for (int i = 0; i < (start_addr % LINE_LEN); i++) {
46 | alt_printf(" ");
47 | }
48 |
49 | // scan the addresses
50 | for (int addr = start_addr; addr < stop_addr; addr++) {
51 | if ((addr % LINE_LEN) == 0) {
52 | alt_printf("\n %x | ", addr);
53 | }
54 |
55 | alt_avalon_i2c_master_target_set(i2c_dev, addr);
56 | ALT_AVALON_I2C_STATUS_CODE rc = alt_avalon_i2c_master_receive(
57 | i2c_dev, rx_buf, 1, ALT_AVALON_I2C_NO_RESTART, ALT_AVALON_I2C_STOP);
58 | if (rc == ALT_AVALON_I2C_SUCCESS) {
59 | alt_printf("%x ", addr);
60 | } else {
61 | alt_printf("-- ");
62 | }
63 | }
64 | alt_printf("\n");
65 | }
66 |
67 | void mini_i2cdump(ALT_AVALON_I2C_DEV_t *i2c_dev, uint8_t addr) {
68 | uint8_t tx_buf[1] = {0};
69 | uint8_t rx_buf[16] = {0};
70 | ALT_AVALON_I2C_STATUS_CODE rc;
71 |
72 | // set address
73 | alt_avalon_i2c_master_target_set(i2c_dev, addr);
74 |
75 | for (int i = 0; i < 16; i++) {
76 |
77 | // read 16 bytes at a time
78 | tx_buf[0] = i * 16;
79 | rc = alt_avalon_i2c_master_tx_rx(i2c_dev, tx_buf, 1, rx_buf, 16, 0);
80 | if (rc != ALT_AVALON_I2C_SUCCESS) {
81 | alt_printf("mini_i2cdump: I2C read error (-0x%x)\n", -rc);
82 | return;
83 | }
84 |
85 | // print address part
86 | if (i == 0) {
87 | alt_printf(" ");
88 | }
89 | alt_printf(" %x | ", i * 16);
90 |
91 | // print line (hex part)
92 | for (int i = 0; i < 16; i++) {
93 | if (rx_buf[i] < 16) {
94 | alt_printf("0");
95 | }
96 | alt_printf("%x ", rx_buf[i]);
97 | }
98 |
99 | // print line (char part)
100 | alt_printf("| ");
101 | for (int i = 0; i < 16; i++) {
102 | if (rx_buf[i] >= 20 && rx_buf[i] < 127) {
103 | alt_printf("%c", rx_buf[i]);
104 | } else {
105 | alt_printf(".");
106 | }
107 | }
108 |
109 | // next line
110 | alt_printf("\n");
111 | }
112 | }
113 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/mem_sw_check.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include "mem_sw_check.h"
24 |
25 | #include
26 | #include
27 |
28 | #include "io.h"
29 | #include "system.h"
30 |
31 | static int mem_sw_check_get_nr_pages(void) {
32 | uint32_t addr_bit_diff = ADDRESS_SPAN_EXTENDER_0_CNTL_MASTER_ADDRESS_WIDTH -
33 | ADDRESS_SPAN_EXTENDER_0_CNTL_SLAVE_ADDRESS_WIDTH -
34 | ADDRESS_SPAN_EXTENDER_0_CNTL_SLAVE_ADDRESS_SHIFT;
35 |
36 | return 1 << addr_bit_diff;
37 | }
38 |
39 | static uint32_t mem_sw_check_get_page_size_bytes(void) {
40 | uint32_t slave_addr_size = ADDRESS_SPAN_EXTENDER_0_CNTL_SLAVE_ADDRESS_WIDTH +
41 | ADDRESS_SPAN_EXTENDER_0_CNTL_SLAVE_ADDRESS_SHIFT;
42 |
43 | return 1 << slave_addr_size;
44 | }
45 |
46 | static void mem_sw_check_set_page(uint32_t page) {
47 | uint32_t addr_offs = page
48 | << (ADDRESS_SPAN_EXTENDER_0_CNTL_SLAVE_ADDRESS_WIDTH +
49 | ADDRESS_SPAN_EXTENDER_0_CNTL_SLAVE_ADDRESS_SHIFT);
50 | IOWR_32DIRECT(ADDRESS_SPAN_EXTENDER_0_CNTL_BASE, 0, addr_offs);
51 | IOWR_32DIRECT(ADDRESS_SPAN_EXTENDER_0_CNTL_BASE, 4, 0);
52 | }
53 |
54 | typedef struct {
55 | uint32_t data[4];
56 | } uint128_t;
57 |
58 | static void uint128_inc(uint128_t *x) {
59 | uint32_t carry[5] = {1, 0, 0, 0, 0};
60 |
61 | for (int i = 0; i < 4; i++) {
62 | if ((x->data[i] == 0xFFFFFFFFUL) && (carry[0] != 0)) {
63 | carry[i + 1] = 1;
64 | }
65 | x->data[i] += carry[i];
66 | }
67 | }
68 |
69 | static void uint128_print(uint128_t *x) {
70 | for (int i = 0; i < 4; i++) {
71 | alt_printf("%x%s", x->data[i], i == 3 ? "" : " ");
72 | }
73 | }
74 |
75 | static bool uint128_eq(uint128_t *a, uint128_t *b) {
76 | for (int i = 0; i < 4; i++) {
77 | if (a->data[i] != b->data[i]) {
78 | return false;
79 | }
80 | }
81 | return true;
82 | }
83 |
84 | static uint32_t min_u32(uint32_t a, uint32_t b) {
85 | if (a < b) {
86 | return a;
87 | }
88 |
89 | return b;
90 | }
91 |
92 | void mem_sw_check_128b_cntr(uint32_t size_bytes) {
93 | uint128_t ref = {.data = {0}};
94 |
95 | alt_printf("check 128b cntr: [");
96 | for (int i = 0; i < mem_sw_check_get_nr_pages(); i++) {
97 | mem_sw_check_set_page(i);
98 | volatile uint128_t *ptr =
99 | (volatile uint128_t *)ADDRESS_SPAN_EXTENDER_0_WINDOWED_SLAVE_BASE;
100 |
101 | alt_printf("==");
102 | uint32_t lim = min_u32(mem_sw_check_get_page_size_bytes(), size_bytes);
103 | size_bytes -= lim;
104 | for (int j = 0; j < lim; j += 16) {
105 | bool eq = uint128_eq(ptr, &ref);
106 | if (!eq) {
107 | alt_printf("ERROR at 0x%x, 0x%x\n", i, j);
108 | alt_printf(" recv = ");
109 | uint128_print(ptr);
110 | alt_printf(", exp = ");
111 | uint128_print(&ref);
112 | alt_printf("\n");
113 | return;
114 | }
115 | ptr++;
116 | uint128_inc(&ref);
117 | }
118 | }
119 | alt_printf("]\n");
120 | }
121 |
122 | void mem_sw_write_32b_cntr(uint32_t size_bytes) {
123 | uint32_t cntr = 0;
124 |
125 | alt_printf("write 32b cntr: [");
126 | for (int i = 0; i < mem_sw_check_get_nr_pages(); i++) {
127 | mem_sw_check_set_page(i);
128 | volatile uint32_t *ptr =
129 | (volatile uint32_t *)ADDRESS_SPAN_EXTENDER_0_WINDOWED_SLAVE_BASE;
130 |
131 | alt_printf("==");
132 | uint32_t lim = min_u32(mem_sw_check_get_page_size_bytes(), size_bytes);
133 | size_bytes -= lim;
134 | for (int j = 0; j < lim; j += 4) {
135 | ptr[j] = cntr;
136 | cntr++;
137 | }
138 | }
139 | alt_printf("]\n");
140 | }
141 |
142 | void mem_sw_inj_err(void) {
143 | alt_printf("inj err: [");
144 | for (int i = 0; i < mem_sw_check_get_nr_pages(); i++) {
145 | mem_sw_check_set_page(i);
146 | volatile uint32_t *ptr =
147 | (volatile uint32_t *)ADDRESS_SPAN_EXTENDER_0_WINDOWED_SLAVE_BASE;
148 |
149 | alt_printf("==");
150 | ptr[i] ^= 0x1;
151 | }
152 | alt_printf("]\n");
153 | }
154 |
--------------------------------------------------------------------------------
/software/otma_bringup_bsp/.cproject:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/ip_cores/clock_counter/clock_counter_hw.tcl:
--------------------------------------------------------------------------------
1 | # TCL File Generated by Component Editor 16.1
2 | # Sat Aug 29 17:24:37 CEST 2020
3 | # DO NOT MODIFY
4 |
5 |
6 | #
7 | # clock_counter "Clock counter" v1.0
8 | # 2020.08.29.17:24:37
9 | #
10 | #
11 |
12 | #
13 | # request TCL package from ACDS 16.1
14 | #
15 | package require -exact qsys 16.1
16 |
17 |
18 | #
19 | # module clock_counter
20 | #
21 | set_module_property DESCRIPTION ""
22 | set_module_property NAME clock_counter
23 | set_module_property VERSION 1.0
24 | set_module_property INTERNAL false
25 | set_module_property OPAQUE_ADDRESS_MAP true
26 | set_module_property AUTHOR ""
27 | set_module_property DISPLAY_NAME "Clock counter"
28 | set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
29 | set_module_property EDITABLE true
30 | set_module_property REPORT_TO_TALKBACK false
31 | set_module_property ALLOW_GREYBOX_GENERATION false
32 | set_module_property REPORT_HIERARCHY false
33 |
34 |
35 | #
36 | # file sets
37 | #
38 | add_fileset QUARTUS_SYNTH QUARTUS_SYNTH "" ""
39 | set_fileset_property QUARTUS_SYNTH TOP_LEVEL clock_counter
40 | set_fileset_property QUARTUS_SYNTH ENABLE_RELATIVE_INCLUDE_PATHS false
41 | set_fileset_property QUARTUS_SYNTH ENABLE_FILE_OVERWRITE_MODE false
42 | add_fileset_file clock_counter.sv SYSTEM_VERILOG PATH clock_counter.sv TOP_LEVEL_FILE
43 |
44 | add_fileset SIM_VERILOG SIM_VERILOG "" ""
45 | set_fileset_property SIM_VERILOG TOP_LEVEL clock_counter
46 | set_fileset_property SIM_VERILOG ENABLE_RELATIVE_INCLUDE_PATHS false
47 | set_fileset_property SIM_VERILOG ENABLE_FILE_OVERWRITE_MODE false
48 | add_fileset_file clock_counter.sv SYSTEM_VERILOG PATH clock_counter.sv
49 |
50 |
51 | #
52 | # parameters
53 | #
54 | add_parameter CLK_FREQ INTEGER 125000000 ""
55 | set_parameter_property CLK_FREQ DEFAULT_VALUE 125000000
56 | set_parameter_property CLK_FREQ DISPLAY_NAME CLK_FREQ
57 | set_parameter_property CLK_FREQ WIDTH ""
58 | set_parameter_property CLK_FREQ TYPE INTEGER
59 | set_parameter_property CLK_FREQ UNITS None
60 | set_parameter_property CLK_FREQ ALLOWED_RANGES -2147483648:2147483647
61 | set_parameter_property CLK_FREQ DESCRIPTION ""
62 | set_parameter_property CLK_FREQ HDL_PARAMETER true
63 |
64 |
65 | #
66 | # display items
67 | #
68 |
69 |
70 | #
71 | # connection point clk
72 | #
73 | add_interface clk clock end
74 | set_interface_property clk clockRate 0
75 | set_interface_property clk ENABLED true
76 | set_interface_property clk EXPORT_OF ""
77 | set_interface_property clk PORT_NAME_MAP ""
78 | set_interface_property clk CMSIS_SVD_VARIABLES ""
79 | set_interface_property clk SVD_ADDRESS_GROUP ""
80 |
81 | add_interface_port clk csi_clk_clk clk Input 1
82 |
83 |
84 | #
85 | # connection point reset
86 | #
87 | add_interface reset reset end
88 | set_interface_property reset associatedClock clk
89 | set_interface_property reset synchronousEdges DEASSERT
90 | set_interface_property reset ENABLED true
91 | set_interface_property reset EXPORT_OF ""
92 | set_interface_property reset PORT_NAME_MAP ""
93 | set_interface_property reset CMSIS_SVD_VARIABLES ""
94 | set_interface_property reset SVD_ADDRESS_GROUP ""
95 |
96 | add_interface_port reset rsi_reset_reset reset Input 1
97 |
98 |
99 | #
100 | # connection point ctrl
101 | #
102 | add_interface ctrl avalon end
103 | set_interface_property ctrl addressUnits WORDS
104 | set_interface_property ctrl associatedClock clk
105 | set_interface_property ctrl associatedReset reset
106 | set_interface_property ctrl bitsPerSymbol 8
107 | set_interface_property ctrl burstOnBurstBoundariesOnly false
108 | set_interface_property ctrl burstcountUnits WORDS
109 | set_interface_property ctrl explicitAddressSpan 0
110 | set_interface_property ctrl holdTime 0
111 | set_interface_property ctrl linewrapBursts false
112 | set_interface_property ctrl maximumPendingReadTransactions 0
113 | set_interface_property ctrl maximumPendingWriteTransactions 0
114 | set_interface_property ctrl readLatency 0
115 | set_interface_property ctrl readWaitTime 1
116 | set_interface_property ctrl setupTime 0
117 | set_interface_property ctrl timingUnits Cycles
118 | set_interface_property ctrl writeWaitTime 0
119 | set_interface_property ctrl ENABLED true
120 | set_interface_property ctrl EXPORT_OF ""
121 | set_interface_property ctrl PORT_NAME_MAP ""
122 | set_interface_property ctrl CMSIS_SVD_VARIABLES ""
123 | set_interface_property ctrl SVD_ADDRESS_GROUP ""
124 |
125 | add_interface_port ctrl avs_ctrl_address address Input 9
126 | add_interface_port ctrl avs_ctrl_read read Input 1
127 | add_interface_port ctrl avs_ctrl_write write Input 1
128 | add_interface_port ctrl avs_ctrl_readdata readdata Output 32
129 | add_interface_port ctrl avs_ctrl_writedata writedata Input 32
130 | set_interface_assignment ctrl embeddedsw.configuration.isFlash 0
131 | set_interface_assignment ctrl embeddedsw.configuration.isMemoryDevice 0
132 | set_interface_assignment ctrl embeddedsw.configuration.isNonVolatileStorage 0
133 | set_interface_assignment ctrl embeddedsw.configuration.isPrintableDevice 0
134 |
135 |
136 | #
137 | # connection point conduit_end_0
138 | #
139 | add_interface conduit_end_0 conduit end
140 | set_interface_property conduit_end_0 associatedClock clk
141 | set_interface_property conduit_end_0 associatedReset ""
142 | set_interface_property conduit_end_0 ENABLED true
143 | set_interface_property conduit_end_0 EXPORT_OF ""
144 | set_interface_property conduit_end_0 PORT_NAME_MAP ""
145 | set_interface_property conduit_end_0 CMSIS_SVD_VARIABLES ""
146 | set_interface_property conduit_end_0 SVD_ADDRESS_GROUP ""
147 |
148 | add_interface_port conduit_end_0 coe_meas meas Input 8
149 | add_interface_port conduit_end_0 coe_led_dbg led_dbg Output 1
150 |
151 |
--------------------------------------------------------------------------------
/ip_cores/pcie_status_amm/pcie_status_amm_hw.tcl:
--------------------------------------------------------------------------------
1 | # TCL File Generated by Component Editor 19.1
2 | # Sat May 08 17:40:15 CEST 2021
3 | # DO NOT MODIFY
4 |
5 |
6 | #
7 | # pcie_status_amm "PCIe Status over Avalon-MM" v1.0
8 | # Jan Marjanovic 2021.05.08.17:40:15
9 | #
10 | #
11 |
12 | #
13 | # request TCL package from ACDS 16.1
14 | #
15 | package require -exact qsys 16.1
16 |
17 |
18 | #
19 | # module pcie_status_amm
20 | #
21 | set_module_property DESCRIPTION ""
22 | set_module_property NAME pcie_status_amm
23 | set_module_property VERSION 1.0
24 | set_module_property INTERNAL false
25 | set_module_property OPAQUE_ADDRESS_MAP true
26 | set_module_property AUTHOR "Jan Marjanovic"
27 | set_module_property DISPLAY_NAME "PCIe Status over Avalon-MM"
28 | set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
29 | set_module_property EDITABLE true
30 | set_module_property REPORT_TO_TALKBACK false
31 | set_module_property ALLOW_GREYBOX_GENERATION false
32 | set_module_property REPORT_HIERARCHY false
33 |
34 |
35 | #
36 | # file sets
37 | #
38 | add_fileset QUARTUS_SYNTH QUARTUS_SYNTH "" ""
39 | set_fileset_property QUARTUS_SYNTH TOP_LEVEL pcie_status_amm
40 | set_fileset_property QUARTUS_SYNTH ENABLE_RELATIVE_INCLUDE_PATHS false
41 | set_fileset_property QUARTUS_SYNTH ENABLE_FILE_OVERWRITE_MODE false
42 | add_fileset_file pcie_status_amm.sv SYSTEM_VERILOG PATH hdl/pcie_status_amm.sv TOP_LEVEL_FILE
43 |
44 | add_fileset SIM_VERILOG SIM_VERILOG "" ""
45 | set_fileset_property SIM_VERILOG TOP_LEVEL pcie_status_amm
46 | set_fileset_property SIM_VERILOG ENABLE_RELATIVE_INCLUDE_PATHS false
47 | set_fileset_property SIM_VERILOG ENABLE_FILE_OVERWRITE_MODE false
48 | add_fileset_file pcie_status_amm.sv SYSTEM_VERILOG PATH hdl/pcie_status_amm.sv
49 |
50 |
51 | #
52 | # parameters
53 | #
54 |
55 |
56 | #
57 | # display items
58 | #
59 |
60 |
61 | #
62 | # connection point clock
63 | #
64 | add_interface clock clock end
65 | set_interface_property clock clockRate 0
66 | set_interface_property clock ENABLED true
67 | set_interface_property clock EXPORT_OF ""
68 | set_interface_property clock PORT_NAME_MAP ""
69 | set_interface_property clock CMSIS_SVD_VARIABLES ""
70 | set_interface_property clock SVD_ADDRESS_GROUP ""
71 |
72 | add_interface_port clock clk clk Input 1
73 |
74 |
75 | #
76 | # connection point reset
77 | #
78 | add_interface reset reset end
79 | set_interface_property reset associatedClock clock
80 | set_interface_property reset synchronousEdges DEASSERT
81 | set_interface_property reset ENABLED true
82 | set_interface_property reset EXPORT_OF ""
83 | set_interface_property reset PORT_NAME_MAP ""
84 | set_interface_property reset CMSIS_SVD_VARIABLES ""
85 | set_interface_property reset SVD_ADDRESS_GROUP ""
86 |
87 | add_interface_port reset rsi_reset_reset reset Input 1
88 |
89 |
90 | #
91 | # connection point ctrl
92 | #
93 | add_interface ctrl avalon end
94 | set_interface_property ctrl addressUnits WORDS
95 | set_interface_property ctrl associatedClock clock
96 | set_interface_property ctrl associatedReset reset
97 | set_interface_property ctrl bitsPerSymbol 8
98 | set_interface_property ctrl burstOnBurstBoundariesOnly false
99 | set_interface_property ctrl burstcountUnits WORDS
100 | set_interface_property ctrl explicitAddressSpan 0
101 | set_interface_property ctrl holdTime 0
102 | set_interface_property ctrl linewrapBursts false
103 | set_interface_property ctrl maximumPendingReadTransactions 0
104 | set_interface_property ctrl maximumPendingWriteTransactions 0
105 | set_interface_property ctrl readLatency 0
106 | set_interface_property ctrl readWaitTime 1
107 | set_interface_property ctrl setupTime 0
108 | set_interface_property ctrl timingUnits Cycles
109 | set_interface_property ctrl writeWaitTime 0
110 | set_interface_property ctrl ENABLED true
111 | set_interface_property ctrl EXPORT_OF ""
112 | set_interface_property ctrl PORT_NAME_MAP ""
113 | set_interface_property ctrl CMSIS_SVD_VARIABLES ""
114 | set_interface_property ctrl SVD_ADDRESS_GROUP ""
115 |
116 | add_interface_port ctrl avs_ctrl_address address Input 4
117 | add_interface_port ctrl avs_ctrl_readdata readdata Output 32
118 | add_interface_port ctrl avs_ctrl_read read Input 1
119 | set_interface_assignment ctrl embeddedsw.configuration.isFlash 0
120 | set_interface_assignment ctrl embeddedsw.configuration.isMemoryDevice 0
121 | set_interface_assignment ctrl embeddedsw.configuration.isNonVolatileStorage 0
122 | set_interface_assignment ctrl embeddedsw.configuration.isPrintableDevice 0
123 |
124 |
125 | #
126 | # connection point hip_currentspeed
127 | #
128 | add_interface hip_currentspeed conduit end
129 | set_interface_property hip_currentspeed associatedClock ""
130 | set_interface_property hip_currentspeed associatedReset ""
131 | set_interface_property hip_currentspeed ENABLED true
132 | set_interface_property hip_currentspeed EXPORT_OF ""
133 | set_interface_property hip_currentspeed PORT_NAME_MAP ""
134 | set_interface_property hip_currentspeed CMSIS_SVD_VARIABLES ""
135 | set_interface_property hip_currentspeed SVD_ADDRESS_GROUP ""
136 |
137 | add_interface_port hip_currentspeed hip_currentspeed_currentspeed currentspeed Input 2
138 |
139 |
140 | #
141 | # connection point hip_status
142 | #
143 | add_interface hip_status conduit end
144 | set_interface_property hip_status associatedClock ""
145 | set_interface_property hip_status associatedReset ""
146 | set_interface_property hip_status ENABLED true
147 | set_interface_property hip_status EXPORT_OF ""
148 | set_interface_property hip_status PORT_NAME_MAP ""
149 | set_interface_property hip_status CMSIS_SVD_VARIABLES ""
150 | set_interface_property hip_status SVD_ADDRESS_GROUP ""
151 |
152 | add_interface_port hip_status hip_status_lane_act lane_act Input 4
153 | add_interface_port hip_status hip_status_ltssmstate ltssmstate Input 5
154 | add_interface_port hip_status hip_status_dlup dlup Input 1
155 |
156 |
--------------------------------------------------------------------------------
/software/otma_bringup/test/seatest/seatest.h:
--------------------------------------------------------------------------------
1 | #ifndef SEATEST_H
2 | #define SEATEST_H
3 | #include
4 |
5 | /*
6 | Defines
7 | */
8 |
9 | #define SEATEST_VERSION "1.0"
10 | #define SEATEST_PROJECT_HOME "http://code.google.com/p/seatest/"
11 | #define SEATEST_PRINT_BUFFER_SIZE 100000
12 |
13 | #ifdef ABORT_TEST_IF_ASSERT_FAIL
14 | #include
15 | jmp_buf env;
16 | int skip_failed_test;
17 | #endif
18 |
19 | /*
20 | Typedefs
21 | */
22 |
23 | typedef void (*seatest_void_void)(void);
24 | typedef void (*seatest_void_string)(char*);
25 |
26 | /*
27 | Declarations
28 | */
29 | void (*seatest_simple_test_result)(int passed, char* reason, const char* function, unsigned int line);
30 | void seatest_test_fixture_start(char* filepath);
31 | void seatest_test_fixture_end( void );
32 | void seatest_simple_test_result_log(int passed, char* reason, const char* function, unsigned int line);
33 | void seatest_assert_true(int test, const char* function, unsigned int line);
34 | void seatest_assert_false(int test, const char* function, unsigned int line);
35 | void seatest_assert_int_equal(int expected, int actual, const char* function, unsigned int line);
36 | void seatest_assert_ulong_equal(unsigned long expected, unsigned long actual, const char* function, unsigned int line);
37 | void seatest_assert_float_equal(float expected, float actual, float delta, const char* function, unsigned int line);
38 | void seatest_assert_double_equal(double expected, double actual, double delta, const char* function, unsigned int line);
39 | void seatest_assert_string_equal(const char* expected, const char* actual, const char* function, unsigned int line);
40 | void seatest_assert_string_ends_with(const char* expected, const char* actual, const char* function, unsigned int line);
41 | void seatest_assert_string_starts_with(const char* expected, const char* actual, const char* function, unsigned int line);
42 | void seatest_assert_string_contains(const char* expected, const char* actual, const char* function, unsigned int line);
43 | void seatest_assert_string_doesnt_contain(const char* expected, const char* actual, const char* function, unsigned int line);
44 | int seatest_should_run( char* fixture, char* test);
45 | void seatest_before_run( char* fixture, char* test);
46 | void seatest_run_test(char* fixture, char* test);
47 | void seatest_setup( void );
48 | void seatest_teardown( void );
49 | void seatest_suite_teardown( void );
50 | void seatest_suite_setup( void );
51 | void seatest_test(char* fixture, char* test, void(*test_function)(void));
52 | /*
53 | Assert Macros
54 | */
55 |
56 | #define assert_true(test) do { seatest_assert_true(test, __FUNCTION__, __LINE__); } while (0)
57 | #define assert_false(test) do { seatest_assert_false(test, __FUNCTION__, __LINE__); } while (0)
58 | #define assert_int_equal(expected, actual) do { seatest_assert_int_equal(expected, actual, __FUNCTION__, __LINE__); } while (0)
59 | #define assert_ulong_equal(expected, actual) do { seatest_assert_ulong_equal(expected, actual, __FUNCTION__, __LINE__); } while (0)
60 | #define assert_string_equal(expected, actual) do { seatest_assert_string_equal(expected, actual, __FUNCTION__, __LINE__); } while (0)
61 | #define assert_n_array_equal(expected, actual, n) do { size_t seatest_count; for(seatest_count=0; seatest_count
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 | make
69 |
70 | mem_init_install
71 | true
72 | false
73 | false
74 |
75 |
76 | make
77 |
78 | mem_init_generate
79 | true
80 | false
81 | false
82 |
83 |
84 | make
85 |
86 | help
87 | true
88 | false
89 | false
90 |
91 |
92 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/ip_cores/mem_checker/src/mem_checker.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include
24 | #include
25 |
26 | #include "io.h"
27 | #include "sys/alt_stdio.h"
28 |
29 | #include "mem_checker.h"
30 | #include "mem_checker_regs.h"
31 |
32 | // clang-format off
33 | const char* mem_check_mode_str[8] = {
34 | "all 0s",
35 | "all 1s",
36 | "walking 1",
37 | "walking 0",
38 | "alternate",
39 | "8-bit counter",
40 | "32-bit counter",
41 | "128-bit counter"
42 | };
43 | // clang-format on
44 |
45 | static void _mem_check_get_id(uint32_t base, uint32_t* id, uint32_t* ver)
46 | {
47 | *id = IORD_32DIRECT(base, ADDR_ID);
48 | *ver = IORD_32DIRECT(base, ADDR_VERSION);
49 | }
50 |
51 | static void _mem_check_ctrl(uint32_t base, bool write_not_read, enum mem_check_mode mode)
52 | {
53 | IOWR_32DIRECT(base, ADDR_CTRL, (mode << 8) | write_not_read);
54 | }
55 |
56 | static void _mem_check_write_start(uint32_t base, uint64_t mem_address,
57 | uint32_t mem_size)
58 | {
59 | IOWR_32DIRECT(base, ADDR_WRITE_ADDR_LO, mem_address);
60 | IOWR_32DIRECT(base, ADDR_WRITE_ADDR_HI, mem_address >> 32);
61 | IOWR_32DIRECT(base, ADDR_WRITE_LEN, mem_size);
62 | IOWR_32DIRECT(base, ADDR_WRITE_CTRL, 1);
63 | }
64 |
65 | static int _mem_check_wait_done(uint32_t base, uint32_t reg_addr)
66 | {
67 | uint32_t status;
68 |
69 | for (int i = 0; i < 10000; i++) {
70 | status = IORD_32DIRECT(base, reg_addr);
71 | if (status & 1) {
72 | return 0;
73 | }
74 | usleep(1000);
75 | }
76 |
77 | return -1;
78 | }
79 |
80 | static int _mem_check_write_wait_done(uint32_t base)
81 | {
82 | return _mem_check_wait_done(base, ADDR_WRITE_STATUS);
83 | }
84 |
85 | static int _mem_check_read_wait_done(uint32_t base)
86 | {
87 | return _mem_check_wait_done(base, ADDR_READ_STATUS);
88 | }
89 |
90 | static void _mem_check_write_clear(uint32_t base)
91 | {
92 | IOWR_32DIRECT(base, ADDR_WRITE_STATUS, 1);
93 | }
94 |
95 | static void _mem_check_read_start(uint32_t base, uint64_t mem_address,
96 | uint32_t mem_size)
97 | {
98 | IOWR_32DIRECT(base, ADDR_READ_ADDR_LO, mem_address);
99 | IOWR_32DIRECT(base, ADDR_READ_ADDR_HI, mem_address >> 32);
100 | IOWR_32DIRECT(base, ADDR_READ_LEN, mem_size);
101 | IOWR_32DIRECT(base, ADDR_READ_CTRL, 1);
102 | }
103 |
104 | static void _mem_check_read_clear(uint32_t base)
105 | {
106 | IOWR_32DIRECT(base, ADDR_READ_STATUS, 1);
107 | }
108 |
109 | static void _mem_check_get_stats(uint32_t base, uint32_t* read_duration,
110 | uint32_t* write_duration, uint32_t* check_tot,
111 | uint32_t* check_ok)
112 | {
113 | *read_duration = IORD_32DIRECT(base, ADDR_READ_DURATION);
114 | *write_duration = IORD_32DIRECT(base, ADDR_WRITE_DURATION);
115 | *check_tot = IORD_32DIRECT(base, ADDR_CHECK_TOT);
116 | *check_ok = IORD_32DIRECT(base, ADDR_CHECK_OK);
117 | }
118 |
119 | static int _mem_check_print_stats(uint32_t base, uint32_t mem_size)
120 | {
121 | uint32_t read_duration, write_duration, check_tot, check_ok;
122 | _mem_check_get_stats(base, &read_duration, &write_duration, &check_tot,
123 | &check_ok);
124 |
125 | int write_througput_mbps = mem_size * 200ULL / write_duration;
126 | int read_througput_mbps = mem_size * 200ULL / read_duration;
127 |
128 | bool mem_check_pass = (check_tot == mem_size / 64) && (check_tot == check_ok);
129 |
130 | alt_printf("[mem check] results = %s (%x / %x)\n",
131 | mem_check_pass ? "PASS" : "FAIL", check_ok, check_tot);
132 |
133 | alt_printf("[mem check] write throughput = 0x%x MB/s\n",
134 | write_througput_mbps);
135 | alt_printf("[mem check] read throughput = 0x%x MB/s\n", read_througput_mbps);
136 | return mem_check_pass ? 0 : -2;
137 | }
138 |
139 | static void _mem_check_get_conf(uint32_t base, unsigned int* avalon_width_bytes,
140 | unsigned int* avalon_burst_len)
141 | {
142 | uint32_t cfg = IORD_32DIRECT(base, ADDR_CONF);
143 | *avalon_width_bytes = cfg & 0xFF;
144 | *avalon_burst_len = (cfg >> 8) & 0xFF;
145 | }
146 |
147 | int mem_check_write(uint32_t base, uint64_t mem_address, uint32_t mem_size, enum mem_check_mode mode)
148 | {
149 | int rc;
150 | _mem_check_ctrl(base, true, mode);
151 | _mem_check_write_start(base, mem_address, mem_size);
152 | rc = _mem_check_write_wait_done(base);
153 | if (rc) {
154 | alt_printf("[mem check] ERROR: timeout on write procedure\n");
155 | return rc;
156 | }
157 | _mem_check_write_clear(base);
158 |
159 | return 0;
160 | }
161 |
162 | int mem_check_read_and_check(uint32_t base, uint64_t mem_address, uint32_t mem_size, enum mem_check_mode mode)
163 | {
164 | int rc;
165 | _mem_check_ctrl(base, false, mode);
166 | _mem_check_read_start(base, mem_address, mem_size);
167 | rc = _mem_check_read_wait_done(base);
168 | if (rc) {
169 | alt_printf("[mem check] ERROR: timeout on read procedure\n");
170 | return rc;
171 | }
172 |
173 | rc = _mem_check_print_stats(base, mem_size);
174 | if (rc) {
175 | return rc;
176 | }
177 |
178 | _mem_check_read_clear(base);
179 |
180 | return 0;
181 | }
182 |
183 | int mem_check_full(uint32_t base, uint64_t mem_address, uint32_t mem_size)
184 | {
185 | int rc;
186 |
187 | uint32_t id, ver;
188 | _mem_check_get_id(base, &id, &ver);
189 |
190 | alt_printf("[mem check] =================================================\n");
191 | alt_printf("[mem check] IP id = 0x%x, version = %x\n", id, ver);
192 |
193 | unsigned int avalon_width_bytes, avalon_burst_len;
194 | _mem_check_get_conf(base, &avalon_width_bytes, &avalon_burst_len);
195 | alt_printf("[mem check] Avalon width = 0x%x bytes, burst len = 0x%x\n",
196 | avalon_width_bytes, avalon_burst_len);
197 |
198 | for (int mode = 0; mode < 8; mode++) {
199 | alt_printf("[mem check] mode = %s\n", mem_check_mode_str[mode]);
200 |
201 | rc = mem_check_write(base, mem_address, mem_size, mode);
202 | if (rc) {
203 | return rc;
204 | }
205 |
206 | rc = mem_check_read_and_check(base, mem_address, mem_size, mode);
207 | if (rc) {
208 | return rc;
209 | }
210 | }
211 |
212 | return 0;
213 | }
214 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/IDT8NxQ001.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include "IDT8NxQ001.h"
30 |
31 | static const int NR_CH = IDT8NXQ001_NR_CH;
32 |
33 | struct idt8nxq001_freq_conf {
34 | uint8_t MINT;
35 | uint32_t MFRAC;
36 | uint8_t N;
37 | uint8_t P;
38 | bool DSM_ENA;
39 | };
40 |
41 | static struct idt8nxq001_freq_conf
42 | idt8nxq001_freq_confs[IDT8NXQ001_FREQ_COUNT] = {
43 | [IDT8NXQ001_FREQ_100M] =
44 | {.MINT = 24, .MFRAC = 0, .N = 24, .P = 0, .DSM_ENA = 0},
45 | [IDT8NXQ001_FREQ_125M] =
46 | {.MINT = 25, .MFRAC = 0, .N = 20, .P = 0, .DSM_ENA = 0},
47 | [IDT8NXQ001_FREQ_156p25M] =
48 | {.MINT = 25, .MFRAC = 0, .N = 16, .P = 0, .DSM_ENA = 0},
49 | [IDT8NXQ001_FREQ_200M] =
50 | {.MINT = 24, .MFRAC = 0, .N = 12, .P = 0, .DSM_ENA = 0},
51 | [IDT8NXQ001_FREQ_300M] =
52 | {.MINT = 24, .MFRAC = 0, .N = 8, .P = 0, .DSM_ENA = 0},
53 | [IDT8NXQ001_FREQ_312p5M] =
54 | {.MINT = 25, .MFRAC = 0, .N = 8, .P = 0, .DSM_ENA = 0},
55 | };
56 |
57 | static const unsigned int MINT_MAX = (1 << 6) - 1;
58 | static const unsigned int MFRAC_MAX = (1 << 18) - 1;
59 | static const unsigned int N_MAX = (1 << 7) - 1;
60 | static const unsigned int P_MAX = (1 << 2) - 1;
61 | static const unsigned int DSM_MAX = (1 << 2) - 1;
62 | static const unsigned int CP_MAX = (1 << 2) - 1;
63 |
64 | void idt8nxq001_decode_conf(const uint8_t conf_bytes[24],
65 | struct idt8nxq001_conf *conf) {
66 | assert(conf);
67 |
68 | memset(conf, 0, sizeof(struct idt8nxq001_conf));
69 |
70 | for (int i = 0; i < NR_CH; i++) {
71 | conf->MINT[i] =
72 | ((conf_bytes[0 + i] >> 1) & 0x1F) | (conf_bytes[20 + i] & (1 << 5));
73 | }
74 |
75 | for (int i = 0; i < NR_CH; i++) {
76 | conf->MFRAC[i] = ((conf_bytes[0 + i] & 0x1) << 17) |
77 | (conf_bytes[4 + i] << 9) | (conf_bytes[8 + i] << 1) |
78 | ((conf_bytes[12 + i] >> 7) & 0x1);
79 | }
80 |
81 | for (int i = 0; i < NR_CH; i++) {
82 | conf->N[i] = conf_bytes[12 + i] & 0x7F;
83 | }
84 |
85 | for (int i = 0; i < NR_CH; i++) {
86 | conf->P[i] = (conf_bytes[20 + i] >> 6) & 0x3;
87 | }
88 |
89 | for (int i = 0; i < NR_CH; i++) {
90 | conf->DG[i] = (conf_bytes[20 + i] >> 2) & 0x1;
91 | }
92 |
93 | for (int i = 0; i < NR_CH; i++) {
94 | conf->DSM[i] = (conf_bytes[20 + i] >> 3) & 0x3;
95 | }
96 |
97 | for (int i = 0; i < NR_CH; i++) {
98 | conf->DSM_ENA[i] = (conf_bytes[20 + i] >> 1) & 0x1;
99 | }
100 |
101 | for (int i = 0; i < NR_CH; i++) {
102 | conf->LF[i] = conf_bytes[20 + i] & 0x1;
103 | }
104 |
105 | for (int i = 0; i < NR_CH; i++) {
106 | conf->CP[i] = (conf_bytes[0 + i] >> 6) & 0x3;
107 | }
108 |
109 | conf->FSEL = (conf_bytes[18] >> 3) & 0x3;
110 | conf->nPLL_BYP = (conf_bytes[18] >> 5) & 0x1;
111 | conf->ADC_ENA = (conf_bytes[18] >> 7) & 0x1;
112 | }
113 |
114 | void idt8nxq001_encode_conf(const struct idt8nxq001_conf *conf,
115 | uint8_t conf_bytes[24]) {
116 |
117 | for (int i = 0; i < NR_CH; i++) {
118 | assert(conf->MINT[i] <= MINT_MAX);
119 | assert(conf->MFRAC[i] <= MFRAC_MAX);
120 | assert(conf->N[i] <= N_MAX);
121 | assert(conf->P[i] <= P_MAX);
122 | assert(conf->DSM[i] <= DSM_MAX);
123 | assert(conf->CP[i] <= CP_MAX);
124 | }
125 |
126 | for (int i = 0; i < NR_CH; i++) {
127 | conf_bytes[0 + i] = (conf->CP[i] << 6) | ((conf->MINT[i] & 0x1F) << 1) |
128 | ((conf->MFRAC[i] >> 17) & 0x1);
129 | }
130 |
131 | for (int i = 0; i < NR_CH; i++) {
132 | conf_bytes[4 + i] = (conf->MFRAC[i] >> 9);
133 | }
134 |
135 | for (int i = 0; i < NR_CH; i++) {
136 | conf_bytes[8 + i] = (conf->MFRAC[i] >> 1);
137 | }
138 |
139 | for (int i = 0; i < NR_CH; i++) {
140 | conf_bytes[12 + i] = ((conf->MFRAC[i] & 0x1) << 7) | conf->N[i];
141 | }
142 |
143 | conf_bytes[16] = 0;
144 | conf_bytes[17] = 0;
145 | conf_bytes[18] =
146 | (conf->ADC_ENA << 7) | (conf->nPLL_BYP << 5) | (conf->FSEL << 3);
147 | conf_bytes[19] = 0;
148 |
149 | for (int i = 0; i < NR_CH; i++) {
150 | conf_bytes[20 + i] = (conf->P[i] << 6) |
151 | (((conf->MINT[i] >> 5) & 0x1) << 5) |
152 | (conf->DSM[i] << 3) | (conf->DG[i] << 2) |
153 | (conf->DSM_ENA[i] << 1) | (conf->LF[i]);
154 | }
155 | }
156 |
157 | void idt8nxq001_conf_print(const struct idt8nxq001_conf *conf) {
158 |
159 | alt_printf("IDT8NXQ001 config:\n");
160 |
161 | alt_printf(" MINT :");
162 | for (int i = 0; i < NR_CH; i++) {
163 | alt_printf(" %x", conf->MINT[i]);
164 | }
165 | alt_printf("\n");
166 |
167 | alt_printf(" MFRAC :");
168 | for (int i = 0; i < NR_CH; i++) {
169 | alt_printf(" %x", conf->MFRAC[i]);
170 | }
171 | alt_printf("\n");
172 |
173 | alt_printf(" N :");
174 | for (int i = 0; i < NR_CH; i++) {
175 | alt_printf(" %x", conf->N[i]);
176 | }
177 | alt_printf("\n");
178 |
179 | alt_printf(" P :");
180 | for (int i = 0; i < NR_CH; i++) {
181 | alt_printf(" %x", conf->P[i]);
182 | }
183 | alt_printf("\n");
184 |
185 | // DG not printed
186 | // DSM not printed
187 |
188 | alt_printf(" DSM_ENA :");
189 | for (int i = 0; i < NR_CH; i++) {
190 | alt_printf(" %x", conf->DSM_ENA[i]);
191 | }
192 | alt_printf("\n");
193 |
194 | alt_printf(" LF :");
195 | for (int i = 0; i < NR_CH; i++) {
196 | alt_printf(" %x", conf->LF[i]);
197 | }
198 | alt_printf("\n");
199 |
200 | alt_printf(" CP :");
201 | for (int i = 0; i < NR_CH; i++) {
202 | alt_printf(" %x", conf->CP[i]);
203 | }
204 | alt_printf("\n");
205 |
206 | alt_printf(" FSEL : %x\n", conf->FSEL);
207 | alt_printf(" nPLL_BYP : %x\n", conf->nPLL_BYP);
208 | alt_printf(" ADC_ENA : %x\n", conf->ADC_ENA);
209 | }
210 |
211 | void idt8nxq001_set_freq(struct idt8nxq001_conf *conf, unsigned int ch_sel,
212 | enum IDT8NXQ001_FREQ freq) {
213 | conf->DSM_ENA[ch_sel] = 0;
214 | conf->DSM[ch_sel] = 0x3;
215 | conf->LF[ch_sel] = 1;
216 | conf->DG[ch_sel] = 1;
217 |
218 | const struct idt8nxq001_freq_conf *freq_conf = &idt8nxq001_freq_confs[freq];
219 | conf->MINT[ch_sel] = freq_conf->MINT;
220 | conf->MFRAC[ch_sel] = freq_conf->MFRAC;
221 | conf->N[ch_sel] = freq_conf->N;
222 | conf->P[ch_sel] = freq_conf->P;
223 | conf->DSM_ENA[ch_sel] = freq_conf->DSM_ENA;
224 |
225 | // CP depends on DSA_ENA
226 | conf->CP[ch_sel] = freq_conf->DSM_ENA ? 0 : 0x3;
227 | }
228 |
229 | void idt8nxq001_set_fsel(struct idt8nxq001_conf *conf, uint8_t fsel) {
230 | conf->FSEL = fsel;
231 | }
232 |
--------------------------------------------------------------------------------
/software/otma_bringup/src/cli_commands.c:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2021 Jan Marjanovic
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining a copy
5 | of this software and associated documentation files (the "Software"), to deal
6 | in the Software without restriction, including without limitation the rights
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 | copies of the Software, and to permit persons to whom the Software is
9 | furnished to do so, subject to the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be included in all
12 | copies or substantial portions of the Software.
13 |
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 | SOFTWARE.
21 | */
22 |
23 | #include
24 | #include
25 |
26 | #include "altera_avalon_pio_regs.h"
27 | #include "sys/alt_stdio.h"
28 | #include "system.h"
29 |
30 | #include "IDT8NxQ001.h"
31 | #include "altera_avalon_sysid_qsys_regs.h"
32 | #include "cli_commands.h"
33 | #include "clock_counter.h"
34 | #include "devices.h"
35 | #include "mem_checker.h"
36 | #include "mem_sw_check.h"
37 | #include "mini_i2cdetect.h"
38 | #include "pcie_status_amm.h"
39 |
40 | struct cmd cmds[] = {
41 | {"clks", "Print clock frequencies", cmd_clks},
42 | {"eeprom", "Dump EEPROM", cmd_eeprom},
43 | {"hello", "Says hello", cmd_hello},
44 | {"help", "Prints help", cmd_help},
45 | {"i2cdetect", "Scans I2C bus", cmd_i2cdetect},
46 | {"idt", "Manage IDT oscillator", cmd_idt},
47 | {"mem_test", "Performs the DDR3 memory test", cmd_mem_test},
48 | {"pcie", "Report PCIe state", cmd_pcie},
49 | {"sys_id", "Shows system ID", cmd_sys_id},
50 | };
51 |
52 | size_t cmds_len = sizeof(cmds) / sizeof(cmds[0]);
53 |
54 | void cmd_clks(char *cmd, char *arg1, char *arg2) {
55 | uint32_t cc_ident_reg, cc_version;
56 | clock_counter_get_info(CLOCK_COUNTER_0_BASE, &cc_ident_reg, &cc_version);
57 | alt_printf("Clock counter: ident = 0x%x, version = 0x%x\n", cc_ident_reg,
58 | cc_version);
59 |
60 | for (int i = 0; i < 8; i++) {
61 | uint32_t clk_freq = clock_counter_get_freq(CLOCK_COUNTER_0_BASE, i);
62 | alt_printf("Clock frequency [%x] = ", i);
63 |
64 | // poor man's %f - alt_printf does not have it
65 | bool first_non_zero = false;
66 | for (int scale = 1000000000; scale >= 1000; scale /= 10) {
67 | uint32_t digit = clk_freq / scale;
68 | clk_freq -= digit * scale;
69 |
70 | if ((digit != 0) || (scale == 1000000)) {
71 | first_non_zero = true;
72 | }
73 |
74 | if (first_non_zero) {
75 | alt_putchar(digit + '0');
76 | } else {
77 | alt_putchar(' ');
78 | }
79 |
80 | if (scale == 1000000) {
81 | alt_putchar('.');
82 | }
83 | }
84 | alt_printf(" MHz\n");
85 | }
86 | }
87 |
88 | void cmd_eeprom(char *cmd, char *arg1, char *arg2) {
89 | if (strcmp(arg1, "qsfp0") == 0) {
90 | mini_i2cdump(devices.i2c_dev_qsfp0, 0x50);
91 | } else if (strcmp(arg1, "qsfp1") == 0) {
92 | mini_i2cdump(devices.i2c_dev_qsfp1, 0x50);
93 | } else if (strcmp(arg1, "fru") == 0) {
94 | mini_i2cdump(devices.i2c_dev_mon, 0x51);
95 | } else {
96 | if (strlen(arg1) == 0) {
97 | alt_printf("eeprom (qsfp0|qsfp1|fru)\n");
98 | } else {
99 | alt_printf("Error: unknown i2c channel (%s)\n", arg1);
100 | }
101 | }
102 | }
103 |
104 | void cmd_hello(char *cmd, char *arg1, char *arg2) {
105 | alt_printf("hello from Pikes Peak/Storey Peak board\n");
106 | }
107 |
108 | void cmd_help(char *cmd, char *arg1, char *arg2) {
109 | alt_printf("Available commands:\n");
110 | for (int i = 0; i < sizeof(cmds) / sizeof(cmds[0]); i++) {
111 | alt_printf(" %s - %s\n", cmds[i].cmd, cmds[i].help);
112 | }
113 | }
114 |
115 | void cmd_i2cdetect(char *cmd, char *arg1, char *arg2) {
116 | if (strcmp(arg1, "idt") == 0) {
117 | mini_i2cdetect(devices.i2c_dev_idt, 0x8, 0x78);
118 | } else if (strcmp(arg1, "qsfp0") == 0) {
119 | mini_i2cdetect(devices.i2c_dev_qsfp0, 0x8, 0x78);
120 | } else if (strcmp(arg1, "qsfp1") == 0) {
121 | mini_i2cdetect(devices.i2c_dev_qsfp1, 0x8, 0x78);
122 | } else if (strcmp(arg1, "mon") == 0) {
123 | mini_i2cdetect(devices.i2c_dev_mon, 0x8, 0x78);
124 | } else {
125 | if (strlen(arg1) == 0) {
126 | alt_printf("i2cdetect (idt|qsfp0|qsfp1|mon)\n");
127 | } else {
128 | alt_printf("Error: unknown i2c channel (%s)\n", arg1);
129 | }
130 | }
131 | }
132 |
133 | #define IDT8NxQ001_I2C_ADDR (0x6e)
134 |
135 | void cmd_idt(char *cmd, char *arg1, char *arg2) {
136 | if (strcmp(arg1, "dump") == 0) {
137 | uint8_t idt_tx_buf[1] = {0};
138 | uint8_t idt_rx_buf[IDT8NXQ001_REG_SIZE] = {0};
139 |
140 | alt_avalon_i2c_master_target_set(devices.i2c_dev_idt, IDT8NxQ001_I2C_ADDR);
141 |
142 | // read from the IDT
143 | ALT_AVALON_I2C_STATUS_CODE rc = alt_avalon_i2c_master_tx_rx(
144 | devices.i2c_dev_idt, idt_tx_buf, 1, idt_rx_buf, IDT8NXQ001_REG_SIZE, 0);
145 | if (rc != 0) {
146 | alt_printf("Error: i2c error (err code = -0x%x)\n", -rc);
147 | return;
148 | }
149 |
150 | // print the IDT oscillator config
151 | struct idt8nxq001_conf conf;
152 | idt8nxq001_decode_conf(idt_rx_buf, &conf);
153 |
154 | // print conf
155 | idt8nxq001_conf_print(&conf);
156 | } else {
157 | if (strlen(arg1) == 0) {
158 | alt_printf("idt (dump)\n");
159 | } else {
160 | alt_printf("Error: unknown idt command (%s)\n", arg1);
161 | }
162 | }
163 | }
164 |
165 | static bool get_user_ok(const char *arg2, const char *msg) {
166 |
167 | bool confirm = strcmp(arg2, "-y") == 0;
168 |
169 | if (!confirm) {
170 | alt_printf("%s. Continue [yN]?\n", msg);
171 |
172 | char c;
173 | do {
174 | c = alt_getchar();
175 | // very simple, it works as long as user does not reply "nay"
176 | if (c == 'y' || c == 'Y') {
177 | confirm = true;
178 | }
179 | } while (c != '\n');
180 | }
181 |
182 | return confirm;
183 | }
184 |
185 | void cmd_mem_test(char *cmd, char *arg1, char *arg2) {
186 | if (strlen(arg1) == 0) {
187 | mem_check_full(MEM_CHECKER_0_BASE, 0, 4294967040);
188 | } else if (strcmp("sw_check", arg1) == 0) {
189 | bool confirm =
190 | get_user_ok(arg2, "SW-based memory test takes a lot of time");
191 | if (!confirm) {
192 | alt_printf("aborted by the user\n");
193 | return;
194 | }
195 | mem_check_write(MEM_CHECKER_0_BASE, 0, 4294967040, MEM_CHECK_MODE_CNTR_128);
196 | mem_sw_check_128b_cntr(4294967040);
197 | } else if (strcmp("sw_write", arg1) == 0) {
198 | bool confirm =
199 | get_user_ok(arg2, "SW-based memory test takes a lot of time");
200 | if (!confirm) {
201 | alt_printf("aborted by the user\n");
202 | return;
203 | }
204 | mem_sw_write_32b_cntr(4294967040);
205 | mem_check_read_and_check(MEM_CHECKER_0_BASE, 0, 4294967040,
206 | MEM_CHECK_MODE_CNTR_32);
207 | } else if (strcmp("inj_err", arg1) == 0) {
208 | mem_check_write(MEM_CHECKER_0_BASE, 0, 4294967040, MEM_CHECK_MODE_CNTR_8);
209 | mem_sw_inj_err();
210 | mem_check_read_and_check(MEM_CHECKER_0_BASE, 0, 4294967040,
211 | MEM_CHECK_MODE_CNTR_8);
212 | } else {
213 | alt_printf("mem_test: unknown command (%s)\n", arg1);
214 | }
215 | }
216 |
217 | void cmd_pcie(char *cmd, char *arg1, char *arg2) {
218 | if (strcmp("status", arg1) == 0) {
219 |
220 | uint32_t pcie_status_bases[] = {
221 | PCIE1_STATUS_AMM_BASE,
222 | PCIE2_STATUS_AMM_BASE,
223 | };
224 |
225 | for (unsigned int i = 0;
226 | i < sizeof(pcie_status_bases) / sizeof(*pcie_status_bases); i++) {
227 |
228 | uint32_t pcie_status_base = pcie_status_bases[i];
229 | uint32_t id_reg, version;
230 | pcie_status_id_version(pcie_status_base, &id_reg, &version);
231 |
232 | struct pcie_status status = pcie_status_get(pcie_status_base);
233 |
234 | alt_printf("pcie %x:\n", i);
235 | alt_printf(" id = %x\n", id_reg);
236 | alt_printf(" version = %x\n", version);
237 | alt_printf(" status.cur speed = %x\n", status.currentspeed);
238 | alt_printf(" status.LTTSM state = %x\n", status.ltssmstate);
239 | alt_printf(" status.lane act = %x\n", status.lane_act);
240 | alt_printf(" status.DL up = %x\n", status.dlup);
241 | }
242 | } else if (strcmp("reset", arg1) == 0) {
243 | alt_printf("pcie: asserting reset...\n");
244 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_PCIE_NPOR_BASE, 0);
245 | usleep(100000);
246 | alt_printf("pcie: deasserted reset...\n");
247 | IOWR_ALTERA_AVALON_PIO_DATA(PIO_PCIE_NPOR_BASE, 1);
248 | alt_printf("pcie: reset deasserted\n");
249 | } else {
250 | alt_printf("pcie: unknown command (%s), try 'status' or 'reset'\n", arg1);
251 | }
252 | }
253 |
254 | void cmd_sys_id(char *cmd, char *arg1, char *arg2) {
255 | uint32_t sys_id = IORD_ALTERA_AVALON_SYSID_QSYS_ID(SYSID_QSYS_0_BASE);
256 | uint32_t timestamp =
257 | IORD_ALTERA_AVALON_SYSID_QSYS_TIMESTAMP(SYSID_QSYS_0_BASE);
258 | alt_printf("system id = 0x%x\n", sys_id);
259 | alt_printf("timestamp = 0x%x\n", timestamp);
260 | }
261 |
--------------------------------------------------------------------------------
/hdl/otma_bringup.sv:
--------------------------------------------------------------------------------
1 |
2 | `default_nettype none
3 |
4 | module otma_bringup (
5 | // Clocks
6 | input CLK_125M,
7 | input CLK_QSFP_OSC,
8 | input CLK_PCIE1,
9 | input CLK_PCIE2,
10 |
11 | // I2C
12 | inout I2C_IDT_SCL,
13 | inout I2C_IDT_SDA,
14 |
15 | inout I2C_QSFP0_SCL,
16 | inout I2C_QSFP0_SDA,
17 |
18 | inout I2C_QSFP1_SCL,
19 | inout I2C_QSFP1_SDA,
20 |
21 | inout I2C_MON_SCL,
22 | inout I2C_MON_SDA,
23 |
24 | // DDR3
25 | output [15:0] memory_mem_a,
26 | output [ 2:0] memory_mem_ba,
27 | output [ 0:0] memory_mem_ck,
28 | output [ 0:0] memory_mem_ck_n,
29 | output [ 0:0] memory_mem_cke,
30 | output [ 0:0] memory_mem_cs_n,
31 | output [ 8:0] memory_mem_dm,
32 | output [ 0:0] memory_mem_ras_n,
33 | output [ 0:0] memory_mem_cas_n,
34 | output [ 0:0] memory_mem_we_n,
35 | output memory_mem_reset_n,
36 | inout [71:0] memory_mem_dq,
37 | inout [ 8:0] memory_mem_dqs,
38 | inout [ 8:0] memory_mem_dqs_n,
39 | output [ 0:0] memory_mem_odt,
40 | input oct_rzqin,
41 |
42 | // QSFP0
43 | // input [3:0] XCVR_QSFP0_RX,
44 | // output [3:0] XCVR_QSFP0_TX,
45 |
46 | // QSFP1
47 | // input [3:0] XCVR_QSFP1_RX,
48 | // output [3:0] XCVR_QSFP1_TX,
49 |
50 | // PCIe 1
51 | input PCIE1_PERSTN,
52 | input [ 7:0] PCIE1_SERIAL_RX,
53 | output [ 7:0] PCIE1_SERIAL_TX,
54 |
55 | // PCIe 2
56 | input PCIE2_PERSTN,
57 | input [ 7:0] PCIE2_SERIAL_RX,
58 | output [ 7:0] PCIE2_SERIAL_TX,
59 |
60 | // LED
61 | output [7:0] LEDS
62 | );
63 |
64 |
65 | //==============================================================================
66 | // clocks
67 |
68 | wire clk_125_int; // generated by Qsys
69 |
70 |
71 | //==============================================================================
72 | // blinky
73 |
74 | logic [27:0] cntr = 0;
75 |
76 | always_ff @(posedge CLK_125M) begin: proc_cntr
77 | cntr <= cntr + 1'd1;
78 | end
79 |
80 | assign LEDS[7] = cntr[26];
81 |
82 |
83 | //==============================================================================
84 | // clock connections
85 |
86 | wire [7:0] clk_cntr_meas = {1'b0, 1'b0, 1'b0, 1'b0, CLK_PCIE2, CLK_PCIE1, CLK_QSFP_OSC, clk_125_int};
87 |
88 | //==============================================================================
89 | // I2C
90 |
91 | wire i2c_idt_osc_sda_oe;
92 | wire i2c_idt_osc_scl_oe;
93 |
94 | assign I2C_IDT_SDA = i2c_idt_osc_sda_oe ? 1'b0 : 1'bz;
95 | assign I2C_IDT_SCL = i2c_idt_osc_scl_oe ? 1'b0 : 1'bz;
96 |
97 | wire i2c_qsfp0_sda_oe;
98 | wire i2c_qsfp0_scl_oe;
99 |
100 | assign I2C_QSFP0_SDA = i2c_qsfp0_sda_oe ? 1'b0 : 1'bz;
101 | assign I2C_QSFP0_SCL = i2c_qsfp0_scl_oe ? 1'b0 : 1'bz;
102 |
103 | wire i2c_qsfp1_sda_oe;
104 | wire i2c_qsfp1_scl_oe;
105 |
106 | assign I2C_QSFP1_SDA = i2c_qsfp1_sda_oe ? 1'b0 : 1'bz;
107 | assign I2C_QSFP1_SCL = i2c_qsfp1_scl_oe ? 1'b0 : 1'bz;
108 |
109 | wire i2c_mon_sda_oe;
110 | wire i2c_mon_scl_oe;
111 |
112 | assign I2C_MON_SDA = i2c_mon_sda_oe ? 1'b0 : 1'bz;
113 | assign I2C_MON_SCL = i2c_mon_scl_oe ? 1'b0 : 1'bz;
114 |
115 |
116 | //==============================================================================
117 | // DDR3
118 |
119 | wire ddr3_mem_status_local_init_done;
120 | wire ddr3_mem_status_local_cal_success;
121 | wire ddr3_mem_status_local_cal_fail;
122 |
123 | assign LEDS[6] = ddr3_mem_status_local_init_done;
124 | assign LEDS[5] = ddr3_mem_status_local_cal_success;
125 | // assign LEDS[4] = ddr3_mem_status_local_cal_fail;
126 |
127 | //==============================================================================
128 | // PCIe
129 |
130 | wire [31:0] pcie_test_in;
131 | assign pcie_test_in[0] = 1'b0;
132 | assign pcie_test_in[4:1] = 4'b1000;
133 | assign pcie_test_in[5] = 1'b0;
134 | assign pcie_test_in[31:6] = 26'h2;
135 |
136 | wire pcie_cpu_npor;
137 |
138 | //==============================================================================
139 | // qsys
140 |
141 | system inst_system (
142 | .clk_clk ( CLK_125M ),
143 | .reset_reset_n ( 1'b1 ),
144 | .clk_cntr_meas ( clk_cntr_meas ),
145 | .clk_cntr_led_dbg ( LEDS[2] ),
146 | .clk_125_clk ( clk_125_int ),
147 | .led_dbg_export ( LEDS[1:0] ),
148 | .cpu_pcie_npor_export ( pcie_cpu_npor ),
149 | .i2c_idt_osc_sda_in ( I2C_IDT_SDA ),
150 | .i2c_idt_osc_scl_in ( I2C_IDT_SCL ),
151 | .i2c_idt_osc_sda_oe ( i2c_idt_osc_sda_oe ),
152 | .i2c_idt_osc_scl_oe ( i2c_idt_osc_scl_oe ),
153 | .i2c_qsfp_0_sda_in ( I2C_QSFP0_SDA ),
154 | .i2c_qsfp_0_scl_in ( I2C_QSFP0_SCL ),
155 | .i2c_qsfp_0_sda_oe ( i2c_qsfp0_sda_oe ),
156 | .i2c_qsfp_0_scl_oe ( i2c_qsfp0_scl_oe ),
157 | .i2c_qsfp_1_sda_in ( I2C_QSFP1_SDA ),
158 | .i2c_qsfp_1_scl_in ( I2C_QSFP1_SCL ),
159 | .i2c_qsfp_1_sda_oe ( i2c_qsfp1_sda_oe ),
160 | .i2c_qsfp_1_scl_oe ( i2c_qsfp1_scl_oe ),
161 | .i2c_mon_sda_in ( I2C_MON_SDA ),
162 | .i2c_mon_scl_in ( I2C_MON_SCL ),
163 | .i2c_mon_sda_oe ( i2c_mon_sda_oe ),
164 | .i2c_mon_scl_oe ( i2c_mon_scl_oe ),
165 | .ddr3_mem_status_local_init_done ( ddr3_mem_status_local_init_done ),
166 | .ddr3_mem_status_local_cal_success ( ddr3_mem_status_local_cal_success ),
167 | .ddr3_mem_status_local_cal_fail ( ddr3_mem_status_local_cal_fail ),
168 | .memory_mem_a ( memory_mem_a ),
169 | .memory_mem_ba ( memory_mem_ba ),
170 | .memory_mem_ck ( memory_mem_ck ),
171 | .memory_mem_ck_n ( memory_mem_ck_n ),
172 | .memory_mem_cke ( memory_mem_cke ),
173 | .memory_mem_cs_n ( memory_mem_cs_n ),
174 | .memory_mem_dm ( memory_mem_dm ),
175 | .memory_mem_ras_n ( memory_mem_ras_n ),
176 | .memory_mem_cas_n ( memory_mem_cas_n ),
177 | .memory_mem_we_n ( memory_mem_we_n ),
178 | .memory_mem_reset_n ( memory_mem_reset_n ),
179 | .memory_mem_dq ( memory_mem_dq ),
180 | .memory_mem_dqs ( memory_mem_dqs ),
181 | .memory_mem_dqs_n ( memory_mem_dqs_n ),
182 | .memory_mem_odt ( memory_mem_odt ),
183 | .oct_rzqin ( oct_rzqin ),
184 | .pcie1_hip_ctrl_test_in ( pcie_test_in ),
185 | .pcie1_hip_ctrl_simu_mode_pipe ( ),
186 | .pcie1_hip_serial_rx_in0 ( PCIE1_SERIAL_RX[0] ),
187 | .pcie1_hip_serial_rx_in1 ( PCIE1_SERIAL_RX[1] ),
188 | .pcie1_hip_serial_rx_in2 ( PCIE1_SERIAL_RX[2] ),
189 | .pcie1_hip_serial_rx_in3 ( PCIE1_SERIAL_RX[3] ),
190 | .pcie1_hip_serial_rx_in4 ( PCIE1_SERIAL_RX[4] ),
191 | .pcie1_hip_serial_rx_in5 ( PCIE1_SERIAL_RX[5] ),
192 | .pcie1_hip_serial_rx_in6 ( PCIE1_SERIAL_RX[6] ),
193 | .pcie1_hip_serial_rx_in7 ( PCIE1_SERIAL_RX[7] ),
194 | .pcie1_hip_serial_tx_out0 ( PCIE1_SERIAL_TX[0] ),
195 | .pcie1_hip_serial_tx_out1 ( PCIE1_SERIAL_TX[1] ),
196 | .pcie1_hip_serial_tx_out2 ( PCIE1_SERIAL_TX[2] ),
197 | .pcie1_hip_serial_tx_out3 ( PCIE1_SERIAL_TX[3] ),
198 | .pcie1_hip_serial_tx_out4 ( PCIE1_SERIAL_TX[4] ),
199 | .pcie1_hip_serial_tx_out5 ( PCIE1_SERIAL_TX[5] ),
200 | .pcie1_hip_serial_tx_out6 ( PCIE1_SERIAL_TX[6] ),
201 | .pcie1_hip_serial_tx_out7 ( PCIE1_SERIAL_TX[7] ),
202 | .pcie1_led_dbg_export ( LEDS[3] ),
203 | .pcie1_npor_npor ( pcie_cpu_npor ),
204 | .pcie1_npor_pin_perst ( PCIE1_PERSTN ),
205 | .pcie1_refclk_clk ( CLK_PCIE1 ),
206 | .pcie2_hip_ctrl_test_in ( pcie_test_in ),
207 | .pcie2_hip_ctrl_simu_mode_pipe ( ),
208 | .pcie2_hip_serial_rx_in0 ( PCIE2_SERIAL_RX[0] ),
209 | .pcie2_hip_serial_rx_in1 ( PCIE2_SERIAL_RX[1] ),
210 | .pcie2_hip_serial_rx_in2 ( PCIE2_SERIAL_RX[2] ),
211 | .pcie2_hip_serial_rx_in3 ( PCIE2_SERIAL_RX[3] ),
212 | .pcie2_hip_serial_rx_in4 ( PCIE2_SERIAL_RX[4] ),
213 | .pcie2_hip_serial_rx_in5 ( PCIE2_SERIAL_RX[5] ),
214 | .pcie2_hip_serial_rx_in6 ( PCIE2_SERIAL_RX[6] ),
215 | .pcie2_hip_serial_rx_in7 ( PCIE2_SERIAL_RX[7] ),
216 | .pcie2_hip_serial_tx_out0 ( PCIE2_SERIAL_TX[0] ),
217 | .pcie2_hip_serial_tx_out1 ( PCIE2_SERIAL_TX[1] ),
218 | .pcie2_hip_serial_tx_out2 ( PCIE2_SERIAL_TX[2] ),
219 | .pcie2_hip_serial_tx_out3 ( PCIE2_SERIAL_TX[3] ),
220 | .pcie2_hip_serial_tx_out4 ( PCIE2_SERIAL_TX[4] ),
221 | .pcie2_hip_serial_tx_out5 ( PCIE2_SERIAL_TX[5] ),
222 | .pcie2_hip_serial_tx_out6 ( PCIE2_SERIAL_TX[6] ),
223 | .pcie2_hip_serial_tx_out7 ( PCIE2_SERIAL_TX[7] ),
224 | .pcie2_led_dbg_export ( LEDS[4] ),
225 | .pcie2_npor_npor ( pcie_cpu_npor ),
226 | .pcie2_npor_pin_perst ( PCIE2_PERSTN ),
227 | .pcie2_refclk_clk ( CLK_PCIE2 ),
228 | );
229 |
230 | endmodule
231 |
232 | `default_nettype wire
233 |
--------------------------------------------------------------------------------
/software/otma_bringup/test/seatest/seatest.c:
--------------------------------------------------------------------------------
1 | #include "seatest.h"
2 | #include
3 | #ifdef WIN32
4 | #include "windows.h"
5 | int seatest_is_string_equal_i(const char* s1, const char* s2)
6 | {
7 | #pragma warning(disable: 4996)
8 | return stricmp(s1, s2) == 0;
9 | }
10 |
11 | #else
12 | #include
13 | unsigned int GetTickCount() { return 0;}
14 | void _getch( void ) { }
15 | int seatest_is_string_equal_i(const char* s1, const char* s2)
16 | {
17 | return strcasecmp(s1, s2) == 0;
18 | }
19 | #endif
20 |
21 | #ifdef SEATEST_INTERNAL_TESTS
22 | static int sea_test_last_passed = 0;
23 | #endif
24 |
25 | #define SEATEST_RET_ERROR (-1)
26 | #define SEATEST_RET_OK 0
27 | #define SEATEST_RET_FAILED_COUNT(tests_failed_count) (tests_failed_count)
28 |
29 | typedef enum
30 | {
31 | SEATEST_DISPLAY_TESTS,
32 | SEATEST_RUN_TESTS,
33 | SEATEST_DO_NOTHING,
34 | SEATEST_DO_ABORT
35 | } seatest_action_t;
36 |
37 | typedef struct
38 | {
39 | int argc;
40 | char** argv;
41 | seatest_action_t action;
42 | } seatest_testrunner_t;
43 | static int seatest_screen_width = 70;
44 | static int sea_tests_run = 0;
45 | static int sea_tests_passed = 0;
46 | static int sea_tests_failed = 0;
47 | static int seatest_display_only = 0;
48 | static int seatest_verbose = 0;
49 | static int vs_mode = 0;
50 | static int seatest_machine_readable = 0;
51 | static char* seatest_current_fixture;
52 | static char* seatest_current_fixture_path;
53 | static char seatest_magic_marker[20] = "";
54 |
55 | static seatest_void_void seatest_suite_setup_func = 0;
56 | static seatest_void_void seatest_suite_teardown_func = 0;
57 | static seatest_void_void seatest_fixture_setup = 0;
58 | static seatest_void_void seatest_fixture_teardown = 0;
59 |
60 | void (*seatest_simple_test_result)(int passed, char* reason, const char* function, unsigned int line) = seatest_simple_test_result_log;
61 |
62 | void suite_setup(seatest_void_void setup)
63 | {
64 | seatest_suite_setup_func = setup;
65 | }
66 | void suite_teardown(seatest_void_void teardown)
67 | {
68 | seatest_suite_teardown_func = teardown;
69 | }
70 |
71 | int seatest_is_display_only()
72 | {
73 | return seatest_display_only;
74 | }
75 |
76 | void seatest_suite_setup( void )
77 | {
78 | if(seatest_suite_setup_func != 0) seatest_suite_setup_func();
79 | }
80 |
81 | void seatest_suite_teardown( void )
82 | {
83 | if(seatest_suite_teardown_func != 0) seatest_suite_teardown_func();
84 | }
85 |
86 | void fixture_setup(void (*setup)( void ))
87 | {
88 | seatest_fixture_setup = setup;
89 | }
90 | void fixture_teardown(void (*teardown)( void ))
91 | {
92 | seatest_fixture_teardown = teardown;
93 | }
94 |
95 | void seatest_setup( void )
96 | {
97 | if(seatest_fixture_setup != 0) seatest_fixture_setup();
98 | }
99 |
100 | void seatest_teardown( void )
101 | {
102 | if(seatest_fixture_teardown != 0) seatest_fixture_teardown();
103 | }
104 |
105 | char* test_file_name(char* path)
106 | {
107 | char* file = path + strlen(path);
108 | while(file != path && *file!= '\\' ) file--;
109 | if(*file == '\\') file++;
110 | return file;
111 | }
112 |
113 | static int seatest_fixture_tests_run;
114 | static int seatest_fixture_tests_failed;
115 |
116 |
117 | void seatest_simple_test_result_log(int passed, char* reason, const char* function, unsigned int line)
118 | {
119 | if (!passed)
120 | {
121 |
122 | if(seatest_machine_readable)
123 | {
124 | if (vs_mode)
125 | {
126 | printf("%s (%u) %s,%s\r\n", seatest_current_fixture_path, line, function, reason );
127 | }
128 | else
129 | {
130 | printf("%s%s,%s,%u,%s\r\n", seatest_magic_marker, seatest_current_fixture_path, function, line, reason );
131 | }
132 |
133 | }
134 | else
135 | {
136 | if ( vs_mode )
137 | {
138 | printf("%s (%u) %s,%s\r\n", seatest_current_fixture_path, line, function, reason );
139 | }
140 | else
141 | {
142 | printf("%-30s Line %-5d %s\r\n", function, line, reason );
143 | }
144 | }
145 | sea_tests_failed++;
146 |
147 | #ifdef ABORT_TEST_IF_ASSERT_FAIL
148 | printf("Test has been finished with failure.\r\n");
149 | longjmp(env,1);
150 | #endif
151 | }
152 | else
153 | {
154 | if(seatest_verbose)
155 | {
156 | if(seatest_machine_readable)
157 | {
158 | printf("%s%s,%s,%u,Passed\r\n", seatest_magic_marker, seatest_current_fixture_path, function, line );
159 | }
160 | else
161 | {
162 | printf("%-30s Line %-5d Passed\r\n", function, line);
163 | }
164 | }
165 | sea_tests_passed++;
166 | }
167 | }
168 |
169 | void seatest_assert_true(int test, const char* function, unsigned int line)
170 | {
171 | seatest_simple_test_result(test, "Should have been true", function, line);
172 |
173 | }
174 |
175 | void seatest_assert_false(int test, const char* function, unsigned int line)
176 | {
177 | seatest_simple_test_result(!test, "Should have been false", function, line);
178 | }
179 |
180 |
181 | void seatest_assert_int_equal(int expected, int actual, const char* function, unsigned int line)
182 | {
183 | char s[SEATEST_PRINT_BUFFER_SIZE];
184 | sprintf(s, "Expected %d but was %d", expected, actual);
185 | seatest_simple_test_result(expected==actual, s, function, line);
186 | }
187 |
188 | void seatest_assert_ulong_equal(unsigned long expected, unsigned long actual, const char* function, unsigned int line)
189 | {
190 | char s[SEATEST_PRINT_BUFFER_SIZE];
191 | sprintf(s, "Expected %lu but was %lu", expected, actual);
192 | seatest_simple_test_result(expected==actual, s, function, line);
193 | }
194 |
195 | void seatest_assert_float_equal( float expected, float actual, float delta, const char* function, unsigned int line )
196 | {
197 | char s[SEATEST_PRINT_BUFFER_SIZE];
198 | float result = expected-actual;
199 | sprintf(s, "Expected %f but was %f", expected, actual);
200 | if(result < 0.0) result = 0.0f - result;
201 | seatest_simple_test_result( result <= delta, s, function, line);
202 | }
203 |
204 | void seatest_assert_double_equal( double expected, double actual, double delta, const char* function, unsigned int line )
205 | {
206 | char s[SEATEST_PRINT_BUFFER_SIZE];
207 | double result = expected-actual;
208 | sprintf(s, "Expected %f but was %f", expected, actual);
209 | if(result < 0.0) result = 0.0 - result;
210 | seatest_simple_test_result( result <= delta, s, function, line);
211 | }
212 |
213 | void seatest_assert_string_equal(const char* expected, const char* actual, const char* function, unsigned int line)
214 | {
215 | int comparison;
216 | char s[SEATEST_PRINT_BUFFER_SIZE];
217 |
218 | if ((expected == (char *)0) && (actual == (char *)0))
219 | {
220 | sprintf(s, "Expected but was ");
221 | comparison = 1;
222 | }
223 | else if (expected == (char *)0)
224 | {
225 | sprintf(s, "Expected but was %s", actual);
226 | comparison = 0;
227 | }
228 | else if (actual == (char *)0)
229 | {
230 | sprintf(s, "Expected %s but was ", expected);
231 | comparison = 0;
232 | }
233 | else
234 | {
235 | comparison = strcmp(expected, actual) == 0;
236 | sprintf(s, "Expected %s but was %s", expected, actual);
237 | }
238 |
239 | seatest_simple_test_result(comparison, s, function, line);
240 | }
241 |
242 | void seatest_assert_string_ends_with(const char* expected, const char* actual, const char* function, unsigned int line)
243 | {
244 | char s[SEATEST_PRINT_BUFFER_SIZE];
245 | sprintf(s, "Expected %s to end with %s", actual, expected);
246 | seatest_simple_test_result(strcmp(expected, actual+(strlen(actual)-strlen(expected)))==0, s, function, line);
247 | }
248 |
249 | void seatest_assert_string_starts_with(const char* expected, const char* actual, const char* function, unsigned int line)
250 | {
251 | char s[SEATEST_PRINT_BUFFER_SIZE];
252 | sprintf(s, "Expected %s to start with %s", actual, expected);
253 | seatest_simple_test_result(strncmp(expected, actual, strlen(expected))==0, s, function, line);
254 | }
255 |
256 | void seatest_assert_string_contains(const char* expected, const char* actual, const char* function, unsigned int line)
257 | {
258 | char s[SEATEST_PRINT_BUFFER_SIZE];
259 | sprintf(s, "Expected %s to be in %s", expected, actual);
260 | seatest_simple_test_result(strstr(actual, expected)!=0, s, function, line);
261 | }
262 |
263 | void seatest_assert_string_doesnt_contain(const char* expected, const char* actual, const char* function, unsigned int line)
264 | {
265 | char s[SEATEST_PRINT_BUFFER_SIZE];
266 | sprintf(s, "Expected %s not to have %s in it", actual, expected);
267 | seatest_simple_test_result(strstr(actual, expected)==0, s, function, line);
268 | }
269 |
270 | void seatest_run_test(char* fixture, char* test)
271 | {
272 | sea_tests_run++;
273 | }
274 |
275 | void seatest_header_printer(char* s, int length, char f)
276 | {
277 | int l = strlen(s);
278 | int d = (length- (l + 2)) / 2;
279 | int i;
280 | if(seatest_is_display_only() || seatest_machine_readable) return;
281 | for(i = 0; i 0) {
388 | seatest_header_printer("Failed", seatest_screen_width, ' ');
389 | }
390 | else {
391 | seatest_header_printer("ALL TESTS PASSED", seatest_screen_width, ' ');
392 | }
393 | sprintf(s,"%d tests run", sea_tests_run);
394 | seatest_header_printer(s, seatest_screen_width, ' ');
395 | sprintf(s,"in %lu ms",end - start);
396 | seatest_header_printer(s, seatest_screen_width, ' ');
397 | printf("\r\n");
398 | seatest_header_printer("", seatest_screen_width, '=');
399 |
400 | return SEATEST_RET_FAILED_COUNT(sea_tests_failed);
401 | }
402 |
403 |
404 | void seatest_show_help( void )
405 | {
406 | printf("Usage: [-t ] [-f ] [-d] [help] [-v] [-m] [-k \r\n");
407 | printf("Flags:\r\n");
408 | printf("\thelp:\twill display this help\r\n");
409 | printf("\t-t:\twill only run tests that match \r\n");
410 | printf("\t-f:\twill only run fixtures that match \r\n");
411 | printf("\t-d:\twill just display test names and fixtures without\r\n");
412 | printf("\t-d:\trunning the test\r\n");
413 | printf("\t-v:\twill print a more verbose version of the test run\r\n");
414 | printf("\t-m:\twill print a machine readable format of the test run, ie :- \r\n");
415 | printf("\t \t,,,\r\n");
416 | printf("\t-k:\twill prepend before machine readable output \r\n");
417 | printf("\t \t cannot start with a '-'\r\n");
418 | }
419 |
420 |
421 | int seatest_commandline_has_value_after(seatest_testrunner_t* runner, int arg)
422 | {
423 | if(!((arg+1) < runner->argc)) return 0;
424 | if(runner->argv[arg+1][0]=='-') return 0;
425 | return 1;
426 | }
427 |
428 | int seatest_parse_commandline_option_with_value(seatest_testrunner_t* runner, int arg, char* option, seatest_void_string setter)
429 | {
430 | if(seatest_is_string_equal_i(runner->argv[arg], option))
431 | {
432 | if(!seatest_commandline_has_value_after(runner, arg))
433 | {
434 | printf("Error: The %s option expects to be followed by a value\r\n", option);
435 | runner->action = SEATEST_DO_ABORT;
436 | return 0;
437 | }
438 | setter(runner->argv[arg+1]);
439 | return 1;
440 | }
441 | return 0;
442 | }
443 |
444 | void seatest_interpret_commandline(seatest_testrunner_t* runner)
445 | {
446 | int arg;
447 | for(arg=0; (arg < runner->argc) && (runner->action != SEATEST_DO_ABORT); arg++)
448 | {
449 | if(seatest_is_string_equal_i(runner->argv[arg], "help"))
450 | {
451 | seatest_show_help();
452 | runner->action = SEATEST_DO_NOTHING;
453 | return;
454 | }
455 | if(seatest_is_string_equal_i(runner->argv[arg], "-d")) runner->action = SEATEST_DISPLAY_TESTS;
456 | if(seatest_is_string_equal_i(runner->argv[arg], "-v")) seatest_verbose = 1;
457 | if(seatest_is_string_equal_i(runner->argv[arg], "-vs")) vs_mode = 1;
458 | if(seatest_is_string_equal_i(runner->argv[arg], "-m")) seatest_machine_readable = 1;
459 | if(seatest_parse_commandline_option_with_value(runner,arg,"-t", test_filter)) arg++;
460 | if(seatest_parse_commandline_option_with_value(runner,arg,"-f", fixture_filter)) arg++;
461 | if(seatest_parse_commandline_option_with_value(runner,arg,"-k", set_magic_marker)) arg++;
462 | }
463 | }
464 |
465 | void seatest_testrunner_create(seatest_testrunner_t* runner, int argc, char** argv )
466 | {
467 | runner->action = SEATEST_RUN_TESTS;
468 | runner->argc = argc;
469 | runner->argv = argv;
470 | seatest_interpret_commandline(runner);
471 | }
472 |
473 | int seatest_testrunner(int argc, char** argv, seatest_void_void tests, seatest_void_void setup, seatest_void_void teardown)
474 | {
475 | seatest_testrunner_t runner;
476 | seatest_testrunner_create(&runner, argc, argv);
477 | switch(runner.action)
478 | {
479 | case SEATEST_DISPLAY_TESTS:
480 | {
481 | seatest_display_only = 1;
482 | run_tests(tests);
483 | return SEATEST_RET_OK;
484 | }
485 | case SEATEST_RUN_TESTS:
486 | {
487 | seatest_display_only = 0;
488 | suite_setup(setup);
489 | suite_teardown(teardown);
490 | return run_tests(tests);
491 | }
492 | case SEATEST_DO_NOTHING:
493 | {
494 | return SEATEST_RET_OK;
495 | }
496 | case SEATEST_DO_ABORT:
497 | default:
498 | {
499 | /* there was an error which should of been already printed out. */
500 | return SEATEST_RET_ERROR;
501 | }
502 | }
503 | return SEATEST_RET_ERROR;
504 | }
505 |
506 | #ifdef SEATEST_INTERNAL_TESTS
507 | void seatest_simple_test_result_nolog(int passed, char* reason, const char* function, unsigned int line)
508 | {
509 | sea_test_last_passed = passed;
510 | }
511 |
512 | void seatest_assert_last_passed()
513 | {
514 | assert_int_equal(1, sea_test_last_passed);
515 | }
516 |
517 | void seatest_assert_last_failed()
518 | {
519 | assert_int_equal(0, sea_test_last_passed);
520 | }
521 |
522 | void seatest_disable_logging()
523 | {
524 | seatest_simple_test_result = seatest_simple_test_result_nolog;
525 | }
526 |
527 | void seatest_enable_logging()
528 | {
529 | seatest_simple_test_result = seatest_simple_test_result_log;
530 | }
531 | #endif
532 |
--------------------------------------------------------------------------------
/software/otma_bringup_bsp/Makefile:
--------------------------------------------------------------------------------
1 | #------------------------------------------------------------------------------
2 | # BSP MAKEFILE
3 | #
4 | # This makefile was automatically generated by the nios2-bsp-generate-files
5 | # command. Its purpose is to build a custom Board Support Package (BSP)
6 | # targeting a specific Nios II processor in an SOPC Builder-based design.
7 | #
8 | # To create an application or library Makefile which uses this BSP, try the
9 | # nios2-app-generate-makefile or nios2-lib-generate-makefile commands.
10 | #------------------------------------------------------------------------------
11 |
12 | #------------------------------------------------------------------------------
13 | # TOOLS
14 | #------------------------------------------------------------------------------
15 |
16 | MKDIR := mkdir -p
17 | ECHO := echo
18 | SPACE := $(empty) $(empty)
19 |
20 | #------------------------------------------------------------------------------
21 | # The adjust-path macro
22 | #
23 | # If Make is launched from Windows through
24 | # Windows Subsystem for Linux (WSL). The adjust-path macro converts absolute windows
25 | # paths into unix style paths (Example: c:/dir -> /c/dir).
26 | # The adjust_path_mixed function converts WSL path to Windows path.
27 | # This will ensure paths are readable by GNU Make.
28 | #------------------------------------------------------------------------------
29 |
30 | UNAME = $(shell uname -r)
31 | ifeq ($(findstring Microsoft,$(UNAME)),Microsoft)
32 | WINDOWS_EXE = .exe
33 | endif
34 |
35 | ifdef WINDOWS_EXE
36 | adjust-path = $(if $1,$(shell wslpath "$1"),)
37 | adjust-path-mixed = $(if $1,$(shell wslpath -m "$1"),)
38 | else # !WINDOWS_EXE
39 | adjust-path = $1
40 | adjust-path-mixed = $1
41 | endif
42 |
43 | #------------------------------------------------------------------------------
44 | # DEFAULT TARGET
45 | #
46 | # The default target, "all", must appear before any other target in the
47 | # Makefile. Note that extra prerequisites are added to the "all" rule later.
48 | #------------------------------------------------------------------------------
49 | .PHONY: all
50 | all:
51 | @$(ECHO) [BSP build complete]
52 |
53 |
54 | #------------------------------------------------------------------------------
55 | # PATHS & DIRECTORY NAMES
56 | #
57 | # Explicitly locate absolute path of the BSP root
58 | #------------------------------------------------------------------------------
59 |
60 | BSP_ROOT_DIR := .
61 |
62 | # Define absolute path to the root of the BSP.
63 | ABS_BSP_ROOT := $(shell pwd)
64 |
65 | # Stash all BSP object files here
66 | OBJ_DIR := ./obj
67 |
68 |
69 | #------------------------------------------------------------------------------
70 | # MANAGED CONTENT
71 | #
72 | # All content between the lines "START MANAGED" and "END MANAGED" below is
73 | # generated based on variables in the BSP settings file when the
74 | # nios2-bsp-generate-files command is invoked. If you wish to persist any
75 | # information pertaining to the build process, it is recomended that you
76 | # utilize the BSP settings mechanism to do so.
77 | #
78 | # Note that most variable assignments in this section have a corresponding BSP
79 | # setting that can be changed by using the nios2-bsp-create-settings or
80 | # nios2-bsp-update-settings command before nios2-bsp-generate-files; if you
81 | # want any variable set to a specific value when this Makefile is re-generated
82 | # (to prevent hand-edits from being over-written), use the BSP settings
83 | # facilities above.
84 | #------------------------------------------------------------------------------
85 |
86 | #START MANAGED
87 |
88 | # The following TYPE comment allows tools to identify the 'type' of target this
89 | # makefile is associated with.
90 | # TYPE: BSP_PRIVATE_MAKEFILE
91 |
92 | # This following VERSION comment indicates the version of the tool used to
93 | # generate this makefile. A makefile variable is provided for VERSION as well.
94 | # ACDS_VERSION: 19.1
95 | ACDS_VERSION := 19.1
96 |
97 | # This following BUILD_NUMBER comment indicates the build number of the tool
98 | # used to generate this makefile.
99 | # BUILD_NUMBER: 670
100 |
101 | SETTINGS_FILE := settings.bsp
102 | SOPC_FILE := ../../qsys/system.sopcinfo
103 |
104 | #-------------------------------------------------------------------------------
105 | # TOOL & COMMAND DEFINITIONS
106 | #
107 | # The base command for each build operation are expressed here. Additional
108 | # switches may be expressed here. They will run for all instances of the
109 | # utility.
110 | #-------------------------------------------------------------------------------
111 |
112 | # Archiver command. Creates library files.
113 | AR = nios2-elf-ar$(WINDOWS_EXE)
114 |
115 | # Assembler command. Note that CC is used for .S files.
116 | AS = nios2-elf-gcc$(WINDOWS_EXE)
117 |
118 | # Custom flags only passed to the archiver. This content of this variable is
119 | # directly passed to the archiver rather than the more standard "ARFLAGS". The
120 | # reason for this is that GNU Make assumes some default content in ARFLAGS.
121 | # This setting defines the value of BSP_ARFLAGS in Makefile.
122 | BSP_ARFLAGS = -src
123 |
124 | # Custom flags only passed to the assembler. This setting defines the value of
125 | # BSP_ASFLAGS in Makefile.
126 | BSP_ASFLAGS = -Wa,-gdwarf2
127 |
128 | # C/C++ compiler debug level. '-g' provides the default set of debug symbols
129 | # typically required to debug a typical application. Omitting '-g' removes
130 | # debug symbols from the ELF. This setting defines the value of
131 | # BSP_CFLAGS_DEBUG in Makefile.
132 | BSP_CFLAGS_DEBUG = -g1
133 |
134 | # C/C++ compiler optimization level. "-O0" = no optimization,"-O2" = "normal"
135 | # optimization, etc. "-O0" is recommended for code that you want to debug since
136 | # compiler optimization can remove variables and produce non-sequential
137 | # execution of code while debugging. This setting defines the value of
138 | # BSP_CFLAGS_OPTIMIZATION in Makefile.
139 | BSP_CFLAGS_OPTIMIZATION = -Os
140 |
141 | # C/C++ compiler warning level. "-Wall" is commonly used.This setting defines
142 | # the value of BSP_CFLAGS_WARNINGS in Makefile.
143 | BSP_CFLAGS_WARNINGS = -Wall
144 |
145 | # C compiler command.
146 | CC = nios2-elf-gcc$(WINDOWS_EXE) -xc
147 |
148 | # C++ compiler command.
149 | CXX = nios2-elf-gcc$(WINDOWS_EXE) -xc++
150 |
151 | # Command used to remove files during 'clean' target.
152 | RM = rm -f
153 |
154 |
155 | #-------------------------------------------------------------------------------
156 | # BUILD PRE & POST PROCESS COMMANDS
157 | #
158 | # The following variables are treated as shell commands in the rule
159 | # definitions for each file-type associated with the BSP build, as well as
160 | # commands run at the beginning and end of the entire BSP build operation.
161 | # Pre-process commands are executed before the relevant command (for example,
162 | # a command defined in the "CC_PRE_PROCESS" variable executes before the C
163 | # compiler for building .c files), while post-process commands are executed
164 | # immediately afterwards.
165 | #
166 | # You can view each pre/post-process command in the "Build Rules: All &
167 | # Clean", "Pattern Rules to Build Objects", and "Library Rules" sections of
168 | # this Makefile.
169 | #-------------------------------------------------------------------------------
170 |
171 |
172 | #-------------------------------------------------------------------------------
173 | # BSP SOURCE BUILD SETTINGS (FLAG GENERATION)
174 | #
175 | # Software build settings such as compiler optimization, debug level, warning
176 | # flags, etc., may be defined in the following variables. The variables below
177 | # are concatenated together in the 'Flags' section of this Makefile to form
178 | # final variables of flags passed to the build tools.
179 | #
180 | # These settings are considered private to the BSP and apply to all library &
181 | # driver files in it; they do NOT automatically propagate to, for example, the
182 | # build settings for an application.
183 | # # For additional detail and syntax requirements, please refer to GCC help
184 | # (example: "nios2-elf-gcc --help --verbose").
185 | #
186 | # Unless indicated otherwise, multiple entries in each variable should be
187 | # space-separated.
188 | #-------------------------------------------------------------------------------
189 |
190 | # Altera HAL alt_sys_init.c generated source file
191 | GENERATED_C_FILES := $(ABS_BSP_ROOT)/alt_sys_init.c
192 | GENERATED_C_LIB_SRCS += alt_sys_init.c
193 |
194 |
195 | #-------------------------------------------------------------------------------
196 | # BSP SOURCE FILE LISTING
197 | #
198 | # All source files that comprise the BSP are listed here, along with path
199 | # information to each file expressed relative to the BSP root. The precise
200 | # list and location of each file is derived from the driver, operating system,
201 | # or software package source file declarations.
202 | #
203 | # Following specification of the source files for each component, driver, etc.,
204 | # each source file type (C, assembly, etc.) is concatenated together and used
205 | # to construct a list of objects. Pattern rules to build each object are then
206 | # used to build each file.
207 | #-------------------------------------------------------------------------------
208 |
209 | # altera_avalon_i2c_driver sources root
210 | altera_avalon_i2c_driver_SRCS_ROOT := drivers
211 |
212 | # altera_avalon_i2c_driver sources
213 | altera_avalon_i2c_driver_C_LIB_SRCS := \
214 | $(altera_avalon_i2c_driver_SRCS_ROOT)/src/altera_avalon_i2c.c
215 |
216 | # altera_avalon_jtag_uart_driver sources root
217 | altera_avalon_jtag_uart_driver_SRCS_ROOT := drivers
218 |
219 | # altera_avalon_jtag_uart_driver sources
220 | altera_avalon_jtag_uart_driver_C_LIB_SRCS := \
221 | $(altera_avalon_jtag_uart_driver_SRCS_ROOT)/src/altera_avalon_jtag_uart_init.c \
222 | $(altera_avalon_jtag_uart_driver_SRCS_ROOT)/src/altera_avalon_jtag_uart_read.c \
223 | $(altera_avalon_jtag_uart_driver_SRCS_ROOT)/src/altera_avalon_jtag_uart_write.c \
224 | $(altera_avalon_jtag_uart_driver_SRCS_ROOT)/src/altera_avalon_jtag_uart_ioctl.c \
225 | $(altera_avalon_jtag_uart_driver_SRCS_ROOT)/src/altera_avalon_jtag_uart_fd.c
226 |
227 | # altera_avalon_pio_driver sources root
228 | altera_avalon_pio_driver_SRCS_ROOT := drivers
229 |
230 | # altera_avalon_pio_driver sources
231 | # altera_avalon_sysid_qsys_driver sources root
232 | altera_avalon_sysid_qsys_driver_SRCS_ROOT := drivers
233 |
234 | # altera_avalon_sysid_qsys_driver sources
235 | altera_avalon_sysid_qsys_driver_C_LIB_SRCS := \
236 | $(altera_avalon_sysid_qsys_driver_SRCS_ROOT)/src/altera_avalon_sysid_qsys.c
237 |
238 | # altera_avalon_timer_driver sources root
239 | altera_avalon_timer_driver_SRCS_ROOT := drivers
240 |
241 | # altera_avalon_timer_driver sources
242 | altera_avalon_timer_driver_C_LIB_SRCS := \
243 | $(altera_avalon_timer_driver_SRCS_ROOT)/src/altera_avalon_timer_sc.c \
244 | $(altera_avalon_timer_driver_SRCS_ROOT)/src/altera_avalon_timer_ts.c \
245 | $(altera_avalon_timer_driver_SRCS_ROOT)/src/altera_avalon_timer_vars.c
246 |
247 | # altera_nios2_gen2_hal_driver sources root
248 | altera_nios2_gen2_hal_driver_SRCS_ROOT := HAL
249 |
250 | # altera_nios2_gen2_hal_driver sources
251 | altera_nios2_gen2_hal_driver_C_LIB_SRCS := \
252 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/altera_nios2_gen2_irq.c \
253 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_usleep.c \
254 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_busy_sleep.c \
255 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_irq_vars.c \
256 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_icache_flush.c \
257 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_icache_flush_all.c \
258 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_dcache_flush.c \
259 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_dcache_flush_all.c \
260 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_dcache_flush_no_writeback.c \
261 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_ecc_fatal_exception.c \
262 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_instruction_exception_entry.c \
263 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_irq_register.c \
264 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_iic.c \
265 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_remap_cached.c \
266 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_remap_uncached.c \
267 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_uncached_free.c \
268 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_uncached_malloc.c \
269 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_do_ctors.c \
270 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_do_dtors.c \
271 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_gmon.c
272 |
273 | altera_nios2_gen2_hal_driver_ASM_LIB_SRCS := \
274 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_ecc_fatal_entry.S \
275 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_exception_entry.S \
276 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_exception_trap.S \
277 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_exception_muldiv.S \
278 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_irq_entry.S \
279 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_software_exception.S \
280 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_mcount.S \
281 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/alt_log_macro.S \
282 | $(altera_nios2_gen2_hal_driver_SRCS_ROOT)/src/crt0.S
283 |
284 | # clock_counter_driver sources root
285 | clock_counter_driver_SRCS_ROOT := drivers
286 |
287 | # clock_counter_driver sources
288 | clock_counter_driver_C_LIB_SRCS := \
289 | $(clock_counter_driver_SRCS_ROOT)/src/clock_counter.c
290 |
291 | # hal sources root
292 | hal_SRCS_ROOT := HAL
293 |
294 | # hal sources
295 | hal_C_LIB_SRCS := \
296 | $(hal_SRCS_ROOT)/src/alt_alarm_start.c \
297 | $(hal_SRCS_ROOT)/src/alt_close.c \
298 | $(hal_SRCS_ROOT)/src/alt_dev.c \
299 | $(hal_SRCS_ROOT)/src/alt_dev_llist_insert.c \
300 | $(hal_SRCS_ROOT)/src/alt_dma_rxchan_open.c \
301 | $(hal_SRCS_ROOT)/src/alt_dma_txchan_open.c \
302 | $(hal_SRCS_ROOT)/src/alt_environ.c \
303 | $(hal_SRCS_ROOT)/src/alt_env_lock.c \
304 | $(hal_SRCS_ROOT)/src/alt_errno.c \
305 | $(hal_SRCS_ROOT)/src/alt_execve.c \
306 | $(hal_SRCS_ROOT)/src/alt_exit.c \
307 | $(hal_SRCS_ROOT)/src/alt_fcntl.c \
308 | $(hal_SRCS_ROOT)/src/alt_fd_lock.c \
309 | $(hal_SRCS_ROOT)/src/alt_fd_unlock.c \
310 | $(hal_SRCS_ROOT)/src/alt_find_dev.c \
311 | $(hal_SRCS_ROOT)/src/alt_find_file.c \
312 | $(hal_SRCS_ROOT)/src/alt_flash_dev.c \
313 | $(hal_SRCS_ROOT)/src/alt_fork.c \
314 | $(hal_SRCS_ROOT)/src/alt_fs_reg.c \
315 | $(hal_SRCS_ROOT)/src/alt_fstat.c \
316 | $(hal_SRCS_ROOT)/src/alt_get_fd.c \
317 | $(hal_SRCS_ROOT)/src/alt_getchar.c \
318 | $(hal_SRCS_ROOT)/src/alt_getpid.c \
319 | $(hal_SRCS_ROOT)/src/alt_gettod.c \
320 | $(hal_SRCS_ROOT)/src/alt_iic_isr_register.c \
321 | $(hal_SRCS_ROOT)/src/alt_instruction_exception_register.c \
322 | $(hal_SRCS_ROOT)/src/alt_ioctl.c \
323 | $(hal_SRCS_ROOT)/src/alt_io_redirect.c \
324 | $(hal_SRCS_ROOT)/src/alt_irq_handler.c \
325 | $(hal_SRCS_ROOT)/src/alt_isatty.c \
326 | $(hal_SRCS_ROOT)/src/alt_kill.c \
327 | $(hal_SRCS_ROOT)/src/alt_link.c \
328 | $(hal_SRCS_ROOT)/src/alt_load.c \
329 | $(hal_SRCS_ROOT)/src/alt_log_printf.c \
330 | $(hal_SRCS_ROOT)/src/alt_lseek.c \
331 | $(hal_SRCS_ROOT)/src/alt_main.c \
332 | $(hal_SRCS_ROOT)/src/alt_malloc_lock.c \
333 | $(hal_SRCS_ROOT)/src/alt_open.c \
334 | $(hal_SRCS_ROOT)/src/alt_printf.c \
335 | $(hal_SRCS_ROOT)/src/alt_putchar.c \
336 | $(hal_SRCS_ROOT)/src/alt_putcharbuf.c \
337 | $(hal_SRCS_ROOT)/src/alt_putstr.c \
338 | $(hal_SRCS_ROOT)/src/alt_read.c \
339 | $(hal_SRCS_ROOT)/src/alt_release_fd.c \
340 | $(hal_SRCS_ROOT)/src/alt_rename.c \
341 | $(hal_SRCS_ROOT)/src/alt_sbrk.c \
342 | $(hal_SRCS_ROOT)/src/alt_settod.c \
343 | $(hal_SRCS_ROOT)/src/alt_stat.c \
344 | $(hal_SRCS_ROOT)/src/alt_tick.c \
345 | $(hal_SRCS_ROOT)/src/alt_times.c \
346 | $(hal_SRCS_ROOT)/src/alt_unlink.c \
347 | $(hal_SRCS_ROOT)/src/alt_wait.c \
348 | $(hal_SRCS_ROOT)/src/alt_write.c
349 |
350 | # mem_checker_driver sources root
351 | mem_checker_driver_SRCS_ROOT := drivers
352 |
353 | # mem_checker_driver sources
354 | mem_checker_driver_C_LIB_SRCS := \
355 | $(mem_checker_driver_SRCS_ROOT)/src/mem_checker.c
356 |
357 | # pcie_status_amm_driver sources root
358 | pcie_status_amm_driver_SRCS_ROOT := drivers
359 |
360 | # pcie_status_amm_driver sources
361 | pcie_status_amm_driver_C_LIB_SRCS := \
362 | $(pcie_status_amm_driver_SRCS_ROOT)/src/pcie_status_amm.c
363 |
364 |
365 | # Assemble all component C source files
366 | COMPONENT_C_LIB_SRCS += \
367 | $(altera_avalon_i2c_driver_C_LIB_SRCS) \
368 | $(altera_avalon_jtag_uart_driver_C_LIB_SRCS) \
369 | $(altera_avalon_sysid_qsys_driver_C_LIB_SRCS) \
370 | $(altera_avalon_timer_driver_C_LIB_SRCS) \
371 | $(altera_nios2_gen2_hal_driver_C_LIB_SRCS) \
372 | $(clock_counter_driver_C_LIB_SRCS) \
373 | $(hal_C_LIB_SRCS) \
374 | $(mem_checker_driver_C_LIB_SRCS) \
375 | $(pcie_status_amm_driver_C_LIB_SRCS)
376 |
377 | # Assemble all component assembly source files
378 | COMPONENT_ASM_LIB_SRCS += \
379 | $(altera_nios2_gen2_hal_driver_ASM_LIB_SRCS)
380 |
381 | # Assemble all component C++ source files
382 | COMPONENT_CPP_LIB_SRCS += \
383 |
384 | #END MANAGED
385 |
386 | #------------------------------------------------------------------------------
387 | # PUBLIC.MK
388 | #
389 | # The generated public.mk file contains BSP information that is shared with
390 | # other external makefiles, such as a Nios II application makefile. System-
391 | # dependent information such as hardware-specific compiler flags and
392 | # simulation file generation are stored here.
393 | #
394 | # In addition, public.mk contains include paths that various software,
395 | # such as a device driver, may need for the C compiler. These paths are
396 | # written to public.mk with respect to the BSP root. In public.mk, each
397 | # path is prefixed with a special variable, $(ALT_LIBRARY_ROOT_DIR). The
398 | # purpose of this variable is to allow an external Makefile to append on
399 | # path information to precisely locate paths expressed in public.mk
400 | # Since this is the BSP Makefile, we set ALT_LIBRARY_ROOT_DIR to point right
401 | # here ("."), at the BSP root.
402 | #
403 | # ALT_LIBRARY_ROOT_DIR must always be set before public.mk is included.
404 | #------------------------------------------------------------------------------
405 | ALT_LIBRARY_ROOT_DIR := .
406 | include public.mk
407 |
408 |
409 | #------------------------------------------------------------------------------
410 | # FLAGS
411 | #
412 | # Include paths for BSP files are written into the public.mk file and must
413 | # be added to the existing list of pre-processor flags. In addition, "hooks"
414 | # for standard flags left intentionally empty (CFLAGS, CPPFLAGS, ASFLAGS,
415 | # and CXXFLAGS) are provided for conveniently adding to the relevant flags
416 | # on the command-line or via script that calls make.
417 | #------------------------------------------------------------------------------
418 | # Assemble final list of compiler flags from generated content
419 | BSP_CFLAGS += \
420 | $(BSP_CFLAGS_DEFINED_SYMBOLS) \
421 | $(BSP_CFLAGS_UNDEFINED_SYMBOLS) \
422 | $(BSP_CFLAGS_OPTIMIZATION) \
423 | $(BSP_CFLAGS_DEBUG) \
424 | $(BSP_CFLAGS_WARNINGS) \
425 | $(BSP_CFLAGS_USER_FLAGS) \
426 | $(ALT_CFLAGS) \
427 | $(CFLAGS)
428 |
429 | # Make ready the final list of include directories and other C pre-processor
430 | # flags. Each include path is made ready by prefixing it with "-I".
431 | BSP_CPPFLAGS += \
432 | $(addprefix -I, $(BSP_INC_DIRS)) \
433 | $(addprefix -I, $(ALT_INCLUDE_DIRS)) \
434 | $(ALT_CPPFLAGS) \
435 | $(CPPFLAGS)
436 |
437 | # Finish off assembler flags with any user-provided flags
438 | BSP_ASFLAGS += $(ASFLAGS)
439 |
440 | # Finish off C++ flags with any user-provided flags
441 | BSP_CXXFLAGS += $(CXXFLAGS)
442 |
443 | # And finally, the ordered list
444 | C_SRCS += $(GENERATED_C_LIB_SRCS) \
445 | $(COMPONENT_C_LIB_SRCS)
446 |
447 | CXX_SRCS += $(GENERATED_CPP_LIB_SRCS) \
448 | $(COMPONENT_CPP_LIB_SRCS)
449 |
450 | ASM_SRCS += $(GENERATED_ASM_LIB_SRCS) \
451 | $(COMPONENT_ASM_LIB_SRCS)
452 |
453 |
454 | #------------------------------------------------------------------------------
455 | # LIST OF GENERATED FILES
456 | #
457 | # A Nios II BSP relies on the generation of several source files used
458 | # by both the BSP and any applications referencing the BSP.
459 | #------------------------------------------------------------------------------
460 |
461 |
462 | GENERATED_H_FILES := $(ABS_BSP_ROOT)/system.h
463 |
464 | GENERATED_LINKER_SCRIPT := $(ABS_BSP_ROOT)/linker.x
465 |
466 | GENERATED_FILES += $(GENERATED_H_FILES) \
467 | $(GENERATED_LINKER_SCRIPT)
468 |
469 |
470 | #------------------------------------------------------------------------------
471 | # SETUP TO BUILD OBJECTS
472 | #
473 | # List of object files which are to be built. This is constructed from the input
474 | # list of C source files (C_SRCS), C++ source files (CXX_SRCS), and assembler
475 | # source file (ASM_SRCS). The permitted file extensions are:
476 | #
477 | # .c .C - for C files
478 | # .cxx .cc .cpp .CXX .CC .CPP - for C++ files
479 | # .S .s - for assembly files
480 | #
481 | # Extended description: The list of objects is a sorted list (duplicates
482 | # removed) of all possible objects, placed beneath the ./obj directory,
483 | # including any path information stored in the "*_SRCS" variable. The
484 | # "patsubst" commands are used to concatenate together multiple file suffix
485 | # types for common files (i.e. c++ as .cxx, .cc, .cpp).
486 | #
487 | # File extensions are case-insensitive in build rules with the exception of
488 | # assembly sources. Nios II assembly sources with the ".S" extension are first
489 | # run through the C preprocessor. Sources with the ".s" extension are not.
490 | #------------------------------------------------------------------------------
491 | OBJS = $(sort $(addprefix $(OBJ_DIR)/, \
492 | $(patsubst %.c, %.o, $(patsubst %.C, %.o, $(C_SRCS))) \
493 | $(patsubst %.cxx, %.o, $(patsubst %.CXX, %.o, \
494 | $(patsubst %.cc, %.o, $(patsubst %.CC, %.o, \
495 | $(patsubst %.cpp, %.o, $(patsubst %.CPP, %.o, \
496 | $(CXX_SRCS) )))))) \
497 | $(patsubst %.S, %.o, $(patsubst %.s, %.o, $(ASM_SRCS))) ))
498 |
499 | # List of dependancy files for each object file.
500 | DEPS = $(OBJS:.o=.d)
501 |
502 |
503 | # Rules to force your project to rebuild or relink
504 | # .force_relink file will cause any application that depends on this project to relink
505 | # .force_rebuild file will cause this project to rebuild object files
506 | # .force_rebuild_all file will cause this project and any project that depends on this project to rebuild object files
507 |
508 | FORCE_RELINK_DEP := .force_relink
509 | FORCE_REBUILD_DEP := .force_rebuild
510 | FORCE_REBUILD_ALL_DEP := .force_rebuild_all
511 | FORCE_REBUILD_DEP_LIST := $(FORCE_RELINK_DEP) $(FORCE_REBUILD_DEP) $(FORCE_REBUILD_ALL_DEP)
512 |
513 | $(FORCE_REBUILD_DEP_LIST):
514 |
515 | $(OBJS): $(wildcard $(FORCE_REBUILD_DEP)) $(wildcard $(FORCE_REBUILD_ALL_DEP))
516 |
517 |
518 | #------------------------------------------------------------------------------
519 | # BUILD RULES: ALL & CLEAN
520 | #------------------------------------------------------------------------------
521 | .DELETE_ON_ERROR:
522 |
523 | .PHONY: all
524 | all: build_pre_process
525 | all: Makefile $(GENERATED_FILES) $(BSP_LIB) $(NEWLIB_DIR)
526 | all: build_post_process
527 |
528 |
529 | # clean: remove .o/.a/.d
530 | .PHONY: clean
531 | clean:
532 | @$(RM) -r $(BSP_LIB) $(OBJ_DIR) $(FORCE_REBUILD_DEP_LIST)
533 | ifneq ($(wildcard $(NEWLIB_DIR)),)
534 | @$(RM) -r $(NEWLIB_DIR)
535 | endif
536 | @$(ECHO) [BSP clean complete]
537 |
538 |
539 | #------------------------------------------------------------------------------
540 | # BUILD PRE/POST PROCESS
541 | #------------------------------------------------------------------------------
542 | build_pre_process :
543 | $(BUILD_PRE_PROCESS)
544 |
545 | build_post_process :
546 | $(BUILD_POST_PROCESS)
547 |
548 | .PHONY: build_pre_process build_post_process
549 |
550 |
551 |
552 | #------------------------------------------------------------------------------
553 | # MAKEFILE UP TO DATE?
554 | #
555 | # Is this very Makefile up to date? Someone may have changed the BSP settings
556 | # file or the associated target hardware.
557 | #------------------------------------------------------------------------------
558 | # Skip this check when clean is the only target
559 | ifneq ($(MAKECMDGOALS),clean)
560 |
561 | ifneq ($(wildcard $(call adjust-path,$(SETTINGS_FILE))),$(call adjust-path,$(SETTINGS_FILE)))
562 | $(warning Warning: BSP Settings File $(SETTINGS_FILE) could not be found.)
563 | endif
564 |
565 | Makefile: $(wildcard $(call adjust-path,$(SETTINGS_FILE)))
566 | @$(ECHO) Makefile not up to date.
567 | @$(ECHO) $(call adjust-path,$(SETTINGS_FILE)) has been modified since the BSP Makefile was generated.
568 | @$(ECHO)
569 | @$(ECHO) Generate the BSP to update the Makefile, and then build again.
570 | @$(ECHO)
571 | @$(ECHO) To generate from Eclipse:
572 | @$(ECHO) " 1. Right-click the BSP project."
573 | @$(ECHO) " 2. In the Nios II Menu, click Generate BSP."
574 | @$(ECHO)
575 | @$(ECHO) To generate from the command line:
576 | @$(ECHO) " nios2-bsp-generate-files --settings= --bsp-dir="
577 | @$(ECHO)
578 | @exit 1
579 |
580 | ifneq ($(wildcard $(call adjust-path,$(SOPC_FILE))),$(call adjust-path,$(SOPC_FILE)))
581 | $(warning Warning: SOPC File $(SOPC_FILE) could not be found.)
582 | endif
583 |
584 | public.mk: $(wildcard $(call adjust-path,$(SOPC_FILE)))
585 | @$(ECHO) Makefile not up to date.
586 | @$(ECHO) $(call adjust-path,$(SOPC_FILE)) has been modified since the BSP was generated.
587 | @$(ECHO)
588 | @$(ECHO) Generate the BSP to update the Makefile, and then build again.
589 | @$(ECHO)
590 | @$(ECHO) To generate from Eclipse:
591 | @$(ECHO) " 1. Right-click the BSP project."
592 | @$(ECHO) " 2. In the Nios II Menu, click Generate BSP."
593 | @$(ECHO)
594 | @$(ECHO) To generate from the command line:
595 | @$(ECHO) " nios2-bsp-generate-files --settings= --bsp-dir="
596 | @$(ECHO)
597 | @exit 1
598 |
599 | endif # $(MAKECMDGOALS) != clean
600 |
601 | #------------------------------------------------------------------------------
602 | # PATTERN RULES TO BUILD OBJECTS
603 | #------------------------------------------------------------------------------
604 | $(OBJ_DIR)/%.o: %.c
605 | @$(ECHO) Compiling $( /c/dir). This will ensture
45 | # paths are readable by GNU Make.
46 | #
47 | # If COMSPEC/ComSpec is not defined, Make is launched from linux, and no
48 | # adjustment is necessary
49 | #
50 | #------------------------------------------------------------------------------
51 |
52 | ifndef COMSPEC
53 | ifdef ComSpec
54 | COMSPEC = $(ComSpec)
55 | endif # ComSpec
56 | endif # COMSPEC
57 |
58 | ifdef COMSPEC # if Windows OS
59 |
60 | ifeq ($(MAKE_VERSION),3.81)
61 | #
62 | # adjust-path/adjust-path-mixed for Mingw Gnu Make on Windows
63 | #
64 | # Example Usage:
65 | # $(call adjust-path,c:/aaa/bbb) => /c/aaa/bbb
66 | # $(call adjust-path-mixed,/c/aaa/bbb) => c:/aaa/bbb
67 | # $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) => c:/aaa/bbb
68 | #
69 |
70 | #
71 | # adjust-path
72 | # - converts back slash characters into forward slashes
73 | # - if input arg ($1) is an empty string then return the empty string
74 | # - if input arg ($1) does not contain the string ":/", then return input arg
75 | # - using sed, convert mixed path [c:/...] into mingw path [/c/...]
76 | define adjust-path
77 | $(strip \
78 | $(if $1,\
79 | $(if $(findstring :/,$(subst \,/,$1)),\
80 | $(shell echo $(subst \,/,$1) | sed -e 's,^\([a-zA-Z]\):/,/\1/,'),\
81 | $(subst \,/,$1))))
82 | endef
83 |
84 | #
85 | # adjust-path-mixed
86 | # - converts back slash characters into forward slashes
87 | # - if input arg ($1) is an empty string then return the empty string
88 | # - if input arg ($1) does not begin with a forward slash '/' char, then
89 | # return input arg
90 | # - using sed, convert mingw path [/c/...] or cygwin path [/c/cygdrive/...]
91 | # into a mixed path [c:/...]
92 | define adjust-path-mixed
93 | $(strip \
94 | $(if $1,\
95 | $(if $(findstring $(subst \,/,$1),$(patsubst /%,%,$(subst \,/,$1))),\
96 | $(subst \,/,$1),\
97 | $(shell echo $(subst \,/,$1) | sed -e 's,^/cygdrive/\([a-zA-Z]\)/,\1:/,' -e 's,^/\([a-zA-Z]\)/,\1:/,'))))
98 | endef
99 |
100 | else # MAKE_VERSION != 3.81 (MAKE_VERSION == 3.80 or MAKE_VERSION == 3.79)
101 | #
102 | # adjust-path for Cygwin Gnu Make
103 | # $(call adjust-path,c:/aaa/bbb) = /cygdrive/c/aaa/bbb
104 | # $(call adjust-path-mixed,/cygdrive/c/aaa/bbb) = c:/aaa/bbb
105 | #
106 | adjust-path = $(if $1,$(shell cygpath -u "$1"),)
107 | adjust-path-mixed = $(if $1,$(shell cygpath -m "$1"),)
108 | endif
109 |
110 | else # !COMSPEC
111 |
112 | adjust-path = $1
113 | adjust-path-mixed = $1
114 |
115 | endif # COMSPEC
116 |
117 |
118 | #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
119 | # GENERATED SETTINGS START v
120 | #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
121 |
122 | #START GENERATED
123 | ACTIVE_BUILD_CONFIG := default
124 | BUILD_CONFIGS := default
125 |
126 | # The following TYPE comment allows tools to identify the 'type' of target this
127 | # makefile is associated with.
128 | # TYPE: APP_MAKEFILE
129 |
130 | # This following VERSION comment indicates the version of the tool used to
131 | # generate this makefile. A makefile variable is provided for VERSION as well.
132 | # ACDS_VERSION: 16.1
133 | ACDS_VERSION := 16.1
134 |
135 | # This following BUILD_NUMBER comment indicates the build number of the tool
136 | # used to generate this makefile.
137 | # BUILD_NUMBER: 196
138 |
139 | # Define path to the application ELF.
140 | # It may be used by the makefile fragments so is defined before including them.
141 | #
142 | ELF := otma_bringup.elf
143 |
144 | # Paths to C, C++, and assembly source files.
145 | C_SRCS += src/main.c
146 | C_SRCS += src/IDT8NxQ001.c
147 | C_SRCS += src/mini_i2cdetect.c
148 | C_SRCS += src/cli.c
149 | C_SRCS += src/devices.c
150 | C_SRCS += src/cli_commands.c
151 | C_SRCS += src/mem_sw_check.c
152 | CXX_SRCS :=
153 | ASM_SRCS :=
154 |
155 |
156 | # Path to root of object file tree.
157 | OBJ_ROOT_DIR := obj
158 |
159 | # Options to control objdump.
160 | CREATE_OBJDUMP := 1
161 | OBJDUMP_INCLUDE_SOURCE := 0
162 | OBJDUMP_FULL_CONTENTS := 0
163 |
164 | # Options to enable/disable optional files.
165 | CREATE_ELF_DERIVED_FILES := 0
166 | CREATE_LINKER_MAP := 1
167 |
168 | # Common arguments for ALT_CFLAGSs
169 | APP_CFLAGS_DEFINED_SYMBOLS :=
170 | APP_CFLAGS_UNDEFINED_SYMBOLS :=
171 | APP_CFLAGS_OPTIMIZATION := -O0
172 | APP_CFLAGS_DEBUG_LEVEL := -g
173 | APP_CFLAGS_WARNINGS := -Wall
174 | APP_CFLAGS_USER_FLAGS :=
175 |
176 | APP_ASFLAGS_USER :=
177 | APP_LDFLAGS_USER :=
178 |
179 | # Linker options that have default values assigned later if not
180 | # assigned here.
181 | LINKER_SCRIPT :=
182 | CRT0 :=
183 | SYS_LIB :=
184 |
185 | # Define path to the root of the BSP.
186 | BSP_ROOT_DIR := ../otma_bringup_bsp/
187 |
188 | # List of application specific include directories, library directories and library names
189 | APP_INCLUDE_DIRS :=
190 | APP_LIBRARY_DIRS :=
191 | APP_LIBRARY_NAMES :=
192 |
193 | # Pre- and post- processor settings.
194 | BUILD_PRE_PROCESS :=
195 | BUILD_POST_PROCESS :=
196 |
197 |
198 |
199 | #END GENERATED
200 |
201 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
202 | # GENERATED SETTINGS END ^
203 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
204 |
205 |
206 | #------------------------------------------------------------------------------
207 | # DEFAULT TARGET
208 | #------------------------------------------------------------------------------
209 |
210 | # Define the variable used to echo output if not already defined.
211 | ifeq ($(ECHO),)
212 | ECHO := echo
213 | endif
214 |
215 | # Put "all" rule before included makefile fragments because they may
216 | # define rules and we don't want one of those to become the default rule.
217 | .PHONY : all
218 |
219 | all:
220 | @$(ECHO) [$(APP_NAME) build complete]
221 |
222 | all : build_pre_process libs app build_post_process
223 |
224 |
225 | #------------------------------------------------------------------------------
226 | # VARIABLES DEPENDENT ON GENERATED CONTENT
227 | #------------------------------------------------------------------------------
228 |
229 | # Define object file directory per build configuration
230 | CONFIG_OBJ_DIR := $(OBJ_ROOT_DIR)/$(ACTIVE_BUILD_CONFIG)
231 |
232 | ifeq ($(BSP_ROOT_DIR),)
233 | $(error Edit Makefile and provide a value for BSP_ROOT_DIR)
234 | endif
235 |
236 | ifeq ($(wildcard $(BSP_ROOT_DIR)),)
237 | $(error BSP directory does not exist: $(BSP_ROOT_DIR))
238 | endif
239 |
240 | # Define absolute path to the root of the BSP.
241 | ABS_BSP_ROOT_DIR := $(call adjust-path-mixed,$(shell cd "$(BSP_ROOT_DIR)"; pwd))
242 |
243 | # Include makefile fragments. Define variable ALT_LIBRARY_ROOT_DIR before
244 | # including each makefile fragment so that it knows the path to itself.
245 | BSP_INCLUDE_FILE := $(BSP_ROOT_DIR)/public.mk
246 | ALT_LIBRARY_ROOT_DIR := $(BSP_ROOT_DIR)
247 | include $(BSP_INCLUDE_FILE)
248 | # C2H will need this to touch the BSP public.mk and avoid the sopc file
249 | # out-of-date error during a BSP make
250 | ABS_BSP_INCLUDE_FILE := $(ABS_BSP_ROOT_DIR)/public.mk
251 |
252 |
253 | ifneq ($(WARNING.SMALL_STACK_SIZE),)
254 | # This WARNING is here to protect you from unknowingly using a very small stack
255 | # If the warning is set, increase your stack size or enable the BSP small stack
256 | # setting to eliminate the warning
257 | $(warning WARNING: $(WARNING.SMALL_STACK_SIZE))
258 | endif
259 |
260 | # If the BSP public.mk indicates that ALT_SIM_OPTIMIZE is set, rename the ELF
261 | # by prefixing it with RUN_ON_HDL_SIMULATOR_ONLY_.
262 | ifneq ($(filter -DALT_SIM_OPTIMIZE,$(ALT_CPPFLAGS)),)
263 | ELF := RUN_ON_HDL_SIMULATOR_ONLY_$(ELF)
264 | endif
265 |
266 | # If the BSP public.mk indicates that ALT_PROVIDE_GMON is set, add option to
267 | # download_elf target
268 | ifneq ($(filter -DALT_PROVIDE_GMON,$(ALT_CPPFLAGS)),)
269 | GMON_OUT_FILENAME := gmon.out
270 | WRITE_GMON_OPTION := --write-gmon $(GMON_OUT_FILENAME)
271 | endif
272 |
273 | # Name of ELF application.
274 | APP_NAME := $(basename $(ELF))
275 |
276 | # Set to defaults if variables not already defined in settings.
277 | ifeq ($(LINKER_SCRIPT),)
278 | LINKER_SCRIPT := $(BSP_LINKER_SCRIPT)
279 | endif
280 | ifeq ($(CRT0),)
281 | CRT0 := $(BSP_CRT0)
282 | endif
283 | ifeq ($(SYS_LIB),)
284 | SYS_LIB := $(BSP_SYS_LIB)
285 | endif
286 |
287 | OBJDUMP_NAME := $(APP_NAME).objdump
288 | OBJDUMP_FLAGS := --disassemble --syms --all-header
289 | ifeq ($(OBJDUMP_INCLUDE_SOURCE),1)
290 | OBJDUMP_FLAGS += --source
291 | endif
292 | ifeq ($(OBJDUMP_FULL_CONTENTS),1)
293 | OBJDUMP_FLAGS += --full-contents
294 | endif
295 |
296 | # Create list of linker dependencies (*.a files).
297 | APP_LDDEPS := $(ALT_LDDEPS) $(LDDEPS)
298 |
299 | # Take lists and add required prefixes.
300 | APP_INC_DIRS := $(addprefix -I, $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS))
301 | ASM_INC_PREFIX := -Wa,-I
302 | APP_ASM_INC_DIRS := $(addprefix $(ASM_INC_PREFIX), $(ALT_INCLUDE_DIRS) $(APP_INCLUDE_DIRS) $(INC_DIRS))
303 | APP_LIB_DIRS := $(addprefix -L, $(ALT_LIBRARY_DIRS) $(APP_LIBRARY_DIRS) $(LIB_DIRS))
304 | APP_LIBS := $(addprefix -l, $(ALT_LIBRARY_NAMES) $(APP_LIBRARY_NAMES) $(LIBS))
305 |
306 | ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),)
307 |
308 | #
309 | # Avoid Nios II GCC 3.X options.
310 | #
311 |
312 | # Detect if small newlib C library is requested.
313 | # If yes, remove the -msmallc option because it is
314 | # now handled by other means.
315 | ifneq ($(filter -msmallc,$(ALT_LDFLAGS)),)
316 | ALT_LDFLAGS := $(filter-out -msmallc,$(ALT_LDFLAGS))
317 | ALT_C_LIBRARY := smallc
318 | else
319 | ALT_C_LIBRARY := c
320 | endif
321 |
322 | # Put each BSP dependent library in a group to avoid circular dependencies.
323 | APP_BSP_DEP_LIBS := $(foreach l,$(ALT_BSP_DEP_LIBRARY_NAMES),-Wl,--start-group -l$(ALT_C_LIBRARY) -lgcc -lm -l$(l) -Wl,--end-group)
324 |
325 | else # !AVOID_NIOS2_GCC3_OPTIONS
326 |
327 | #
328 | # Use Nios II GCC 3.X options.
329 | #
330 | ALT_BSP_DEP_LIBRARY_NAMES += $(ALT_BSP_DEP_LIBRARY_NAMES) m
331 | APP_BSP_DEP_LIBS := $(addprefix -msys-lib=, $(ALT_BSP_DEP_LIBRARY_NAMES))
332 |
333 | endif # !AVOID_NIOS2_GCC3_OPTIONS
334 |
335 | # Arguments for the C preprocessor, C/C++ compiler, assembler, and linker.
336 | APP_CFLAGS := $(APP_CFLAGS_DEFINED_SYMBOLS) \
337 | $(APP_CFLAGS_UNDEFINED_SYMBOLS) \
338 | $(APP_CFLAGS_OPTIMIZATION) \
339 | $(APP_CFLAGS_DEBUG_LEVEL) \
340 | $(APP_CFLAGS_WARNINGS) \
341 | $(APP_CFLAGS_USER_FLAGS) \
342 | $(ALT_CFLAGS) \
343 | $(CFLAGS)
344 |
345 | # Arguments only for the C++ compiler.
346 | APP_CXXFLAGS := $(ALT_CXXFLAGS) $(CXXFLAGS)
347 |
348 | # Arguments only for the C preprocessor.
349 | # Prefix each include directory with -I.
350 | APP_CPPFLAGS := $(APP_INC_DIRS) \
351 | $(ALT_CPPFLAGS) \
352 | $(CPPFLAGS)
353 |
354 | # Arguments only for the assembler.
355 | APP_ASFLAGS := $(APP_ASM_INC_DIRS) \
356 | $(ALT_ASFLAGS) \
357 | $(APP_ASFLAGS_USER) \
358 | $(ASFLAGS)
359 |
360 | # Arguments only for the linker.
361 | APP_LDFLAGS := $(APP_LDFLAGS_USER)
362 |
363 | ifneq ($(LINKER_SCRIPT),)
364 | APP_LDFLAGS += -T'$(LINKER_SCRIPT)'
365 | endif
366 |
367 | ifneq ($(AVOID_NIOS2_GCC3_OPTIONS),)
368 |
369 | # Avoid Nios II GCC 3.x options.
370 | ifneq ($(CRT0),)
371 | APP_LDFLAGS += $(CRT0)
372 | endif
373 |
374 | # The equivalent of the -msys-lib option is provided
375 | # by the GROUP() command in the linker script.
376 | # Note this means the SYS_LIB variable is now ignored.
377 |
378 | else # !AVOID_NIOS2_GCC3_OPTIONS
379 |
380 | # Use Nios II GCC 3.x options.
381 | ifneq ($(CRT0),)
382 | APP_LDFLAGS += -msys-crt0='$(CRT0)'
383 | endif
384 | ifneq ($(SYS_LIB),)
385 | APP_LDFLAGS += -msys-lib=$(SYS_LIB)
386 | endif
387 |
388 | endif # !AVOID_NIOS2_GCC3_OPTIONS
389 |
390 | APP_LDFLAGS += \
391 | $(APP_LIB_DIRS) \
392 | $(ALT_LDFLAGS) \
393 | $(LDFLAGS)
394 |
395 | LINKER_MAP_NAME := $(APP_NAME).map
396 | ifeq ($(CREATE_LINKER_MAP), 1)
397 | APP_LDFLAGS += -Wl,-Map=$(LINKER_MAP_NAME)
398 | endif
399 |
400 | # QUARTUS_PROJECT_DIR and SOPC_NAME need to be defined if you want the
401 | # mem_init_install target of the mem_init.mk (located in the associated BSP)
402 | # to know how to copy memory initialization files (e.g. .dat, .hex) into
403 | # directories required for Quartus compilation or RTL simulation.
404 |
405 | # Defining QUARTUS_PROJECT_DIR causes mem_init_install to copy memory
406 | # initialization files into your Quartus project directory. This is required
407 | # to provide the initial memory contents of FPGA memories that can be
408 | # initialized by the programming file (.sof) or Hardcopy ROMs. It is also used
409 | # for VHDL simulation of on-chip memories.
410 |
411 | # Defining SOPC_NAME causes the mem_init_install target to copy memory
412 | # initialization files into your RTL simulation directory. This is required
413 | # to provide the initial memory contents of all memories that can be
414 | # initialized by RTL simulation. This variable should be set to the same name
415 | # as your SOPC Builder system name. For example, if you have a system called
416 | # "foo.sopc", this variable should be set to "foo".
417 |
418 | # If SOPC_NAME is not set and QUARTUS_PROJECT_DIR is set, then derive SOPC_NAME.
419 | ifeq ($(SOPC_NAME),)
420 | ifneq ($(QUARTUS_PROJECT_DIR),)
421 | SOPC_NAME := $(basename $(notdir $(wildcard $(QUARTUS_PROJECT_DIR)/*.sopcinfo)))
422 | endif
423 | endif
424 |
425 | # Defining JDI_FILE is required to specify the JTAG Debug Information File
426 | # path. This file is generated by Quartus, and is needed along with the
427 | # .sopcinfo file to resolve processor instance ID's from names in a multi-CPU
428 | # systems. For multi-CPU systems, the processor instance ID is used to select
429 | # from multiple CPU's during ELF download.
430 |
431 | # Both JDI_FILE and SOPCINFO_FILE are provided by the BSP if they found during
432 | # BSP creation. If JDI_FILE is not set and QUARTUS_PROJECT_DIR is set, then
433 | # derive JDI_FILE. We do not attempt to derive SOPCINFO_FILE since there may be
434 | # multiple .sopcinfo files in a Quartus project.
435 | ifeq ($(JDI_FILE),)
436 | ifneq ($(QUARTUS_PROJECT_DIR),)
437 | JDI_FILE := $(firstword $(wildcard $(QUARTUS_PROJECT_DIR)/output_files/*.jdi) $(wildcard $(QUARTUS_PROJECT_DIR)/*.jdi))
438 | endif
439 | endif
440 |
441 | # Path to root runtime directory used for hdl simulation
442 | RUNTIME_ROOT_DIR := $(CONFIG_OBJ_DIR)/runtime
443 |
444 |
445 |
446 | #------------------------------------------------------------------------------
447 | # MAKEFILE INCLUDES DEPENDENT ON GENERATED CONTENT
448 | #------------------------------------------------------------------------------
449 | # mem_init.mk is a generated makefile fragment. This file defines all targets
450 | # used to generate HDL initialization simulation files and pre-initialized
451 | # onchip memory files.
452 | MEM_INIT_FILE := $(BSP_ROOT_DIR)/mem_init.mk
453 | include $(MEM_INIT_FILE)
454 |
455 | # Create list of object files to be built using the list of source files.
456 | # The source file hierarchy is preserved in the object tree.
457 | # The supported file extensions are:
458 | #
459 | # .c - for C files
460 | # .cxx .cc .cpp - for C++ files
461 | # .S .s - for assembler files
462 | #
463 | # Handle source files specified by --src-dir & --src-rdir differently, to
464 | # save some processing time in calling the adjust-path macro.
465 |
466 | OBJ_LIST_C := $(patsubst %.c,%.o,$(filter %.c,$(C_SRCS)))
467 | OBJ_LIST_CPP := $(patsubst %.cpp,%.o,$(filter %.cpp,$(CXX_SRCS)))
468 | OBJ_LIST_CXX := $(patsubst %.cxx,%.o,$(filter %.cxx,$(CXX_SRCS)))
469 | OBJ_LIST_CC := $(patsubst %.cc,%.o,$(filter %.cc,$(CXX_SRCS)))
470 | OBJ_LIST_S := $(patsubst %.S,%.o,$(filter %.S,$(ASM_SRCS)))
471 | OBJ_LIST_SS := $(patsubst %.s,%.o,$(filter %.s,$(ASM_SRCS)))
472 |
473 | OBJ_LIST := $(sort $(OBJ_LIST_C) $(OBJ_LIST_CPP) $(OBJ_LIST_CXX) \
474 | $(OBJ_LIST_CC) $(OBJ_LIST_S) $(OBJ_LIST_SS))
475 |
476 | SDIR_OBJ_LIST_C := $(patsubst %.c,%.o,$(filter %.c,$(SDIR_C_SRCS)))
477 | SDIR_OBJ_LIST_CPP := $(patsubst %.cpp,%.o,$(filter %.cpp,$(SDIR_CXX_SRCS)))
478 | SDIR_OBJ_LIST_CXX := $(patsubst %.cxx,%.o,$(filter %.cxx,$(SDIR_CXX_SRCS)))
479 | SDIR_OBJ_LIST_CC := $(patsubst %.cc,%.o,$(filter %.cc,$(SDIR_CXX_SRCS)))
480 | SDIR_OBJ_LIST_S := $(patsubst %.S,%.o,$(filter %.S,$(SDIR_ASM_SRCS)))
481 | SDIR_OBJ_LIST_SS := $(patsubst %.s,%.o,$(filter %.s,$(SDIR_ASM_SRCS)))
482 |
483 | SDIR_OBJ_LIST := $(sort $(SDIR_OBJ_LIST_C) $(SDIR_OBJ_LIST_CPP) \
484 | $(SDIR_OBJ_LIST_CXX) $(SDIR_OBJ_LIST_CC) $(SDIR_OBJ_LIST_S) \
485 | $(SDIR_OBJ_LIST_SS))
486 |
487 | # Relative-pathed objects that being with "../" are handled differently.
488 | #
489 | # Regular objects are created as
490 | # $(CONFIG_OBJ_DIR)//.o
491 | # where the path structure is maintained under the obj directory. This
492 | # applies for both absolute and relative paths; in the absolute path
493 | # case this means the entire source path will be recreated under the obj
494 | # directory. This is done to allow two source files with the same name
495 | # to be included as part of the project.
496 | #
497 | # Note: On Cygwin, the path recreated under the obj directory will be
498 | # the cygpath -u output path.
499 | #
500 | # Relative-path objects that begin with "../" cause problems under this
501 | # scheme, as $(CONFIG_OBJ_DIR)/..// can potentially put the object
502 | # files anywhere in the system, creating clutter and polluting the source tree.
503 | # As such, their paths are flattened - the object file created will be
504 | # $(CONFIG_OBJ_DIR)/.o. Due to this, two files specified with
505 | # "../" in the beginning cannot have the same name in the project. VPATH
506 | # will be set for these sources to allow make to relocate the source file
507 | # via %.o rules.
508 | #
509 | # The following lines separate the object list into the flatten and regular
510 | # lists, and then handles them as appropriate.
511 |
512 | FLATTEN_OBJ_LIST := $(filter ../%,$(OBJ_LIST))
513 | FLATTEN_APP_OBJS := $(addprefix $(CONFIG_OBJ_DIR)/,$(notdir $(FLATTEN_OBJ_LIST)))
514 |
515 | REGULAR_OBJ_LIST := $(filter-out $(FLATTEN_OBJ_LIST),$(OBJ_LIST))
516 | REGULAR_OBJ_LIST_C := $(filter $(OBJ_LIST_C),$(REGULAR_OBJ_LIST))
517 | REGULAR_OBJ_LIST_CPP := $(filter $(OBJ_LIST_CPP),$(REGULAR_OBJ_LIST))
518 | REGULAR_OBJ_LIST_CXX := $(filter $(OBJ_LIST_CXX),$(REGULAR_OBJ_LIST))
519 | REGULAR_OBJ_LIST_CC := $(filter $(OBJ_LIST_CC),$(REGULAR_OBJ_LIST))
520 | REGULAR_OBJ_LIST_S := $(filter $(OBJ_LIST_S),$(REGULAR_OBJ_LIST))
521 | REGULAR_OBJ_LIST_SS := $(filter $(OBJ_LIST_SS),$(REGULAR_OBJ_LIST))
522 |
523 | FLATTEN_SDIR_OBJ_LIST := $(filter ../%,$(SDIR_OBJ_LIST))
524 | FLATTEN_SDIR_APP_OBJS := $(addprefix $(CONFIG_OBJ_DIR)/,$(notdir $(FLATTEN_SDIR_OBJ_LIST)))
525 |
526 | REGULAR_SDIR_OBJ_LIST := $(filter-out $(FLATTEN_SDIR_OBJ_LIST),$(SDIR_OBJ_LIST))
527 | REGULAR_SDIR_OBJ_LIST_C := $(filter $(SDIR_OBJ_LIST_C),$(REGULAR_SDIR_OBJ_LIST))
528 | REGULAR_SDIR_OBJ_LIST_CPP := $(filter $(SDIR_OBJ_LIST_CPP),$(REGULAR_SDIR_OBJ_LIST))
529 | REGULAR_SDIR_OBJ_LIST_CXX := $(filter $(SDIR_OBJ_LIST_CXX),$(REGULAR_SDIR_OBJ_LIST))
530 | REGULAR_SDIR_OBJ_LIST_CC := $(filter $(SDIR_OBJ_LIST_CC),$(REGULAR_SDIR_OBJ_LIST))
531 | REGULAR_SDIR_OBJ_LIST_S := $(filter $(SDIR_OBJ_LIST_S),$(REGULAR_SDIR_OBJ_LIST))
532 | REGULAR_SDIR_OBJ_LIST_SS := $(filter $(SDIR_OBJ_LIST_SS),$(REGULAR_SDIR_OBJ_LIST))
533 |
534 | VPATH := $(sort $(dir $(FLATTEN_OBJ_LIST)) $(dir $(FLATTEN_SDIR_OBJ_LIST)))
535 |
536 | APP_OBJS_C := $(addprefix $(CONFIG_OBJ_DIR)/,\
537 | $(REGULAR_SDIR_OBJ_LIST_C) \
538 | $(foreach s,$(REGULAR_OBJ_LIST_C),$(call adjust-path,$s)))
539 |
540 | APP_OBJS_CPP := $(addprefix $(CONFIG_OBJ_DIR)/,\
541 | $(REGULAR_SDIR_OBJ_LIST_CPP) \
542 | $(foreach s,$(REGULAR_OBJ_LIST_CPP),$(call adjust-path,$s)))
543 |
544 | APP_OBJS_CXX := $(addprefix $(CONFIG_OBJ_DIR)/,\
545 | $(REGULAR_SDIR_OBJ_LIST_CXX) \
546 | $(foreach s,$(REGULAR_OBJ_LIST_CXX),$(call adjust-path,$s)))
547 |
548 | APP_OBJS_CC := $(addprefix $(CONFIG_OBJ_DIR)/,\
549 | $(REGULAR_SDIR_OBJ_LIST_CC) \
550 | $(foreach s,$(REGULAR_OBJ_LIST_CC),$(call adjust-path,$s)))
551 |
552 | APP_OBJS_S := $(addprefix $(CONFIG_OBJ_DIR)/,\
553 | $(REGULAR_SDIR_OBJ_LIST_S) \
554 | $(foreach s,$(REGULAR_OBJ_LIST_S),$(call adjust-path,$s)))
555 |
556 | APP_OBJS_SS := $(addprefix $(CONFIG_OBJ_DIR)/,\
557 | $(REGULAR_SDIR_OBJ_LIST_SS) \
558 | $(foreach s,$(REGULAR_OBJ_LIST_SS),$(call adjust-path,$s)))
559 |
560 | APP_OBJS := $(APP_OBJS_C) $(APP_OBJS_CPP) $(APP_OBJS_CXX) $(APP_OBJS_CC) \
561 | $(APP_OBJS_S) $(APP_OBJS_SS) \
562 | $(FLATTEN_APP_OBJS) $(FLATTEN_SDIR_APP_OBJS)
563 |
564 | # Add any extra user-provided object files.
565 | APP_OBJS += $(OBJS)
566 |
567 | # Create list of dependancy files for each object file.
568 | APP_DEPS := $(APP_OBJS:.o=.d)
569 |
570 | # Patch the Elf file with system specific information
571 |
572 | # Patch the Elf with the name of the sopc system
573 | ifneq ($(SOPC_NAME),)
574 | ELF_PATCH_FLAG += --sopc_system_name $(SOPC_NAME)
575 | endif
576 |
577 | # Patch the Elf with the absolute path to the Quartus Project Directory
578 | ifneq ($(QUARTUS_PROJECT_DIR),)
579 | ABS_QUARTUS_PROJECT_DIR := $(call adjust-path-mixed,$(shell cd "$(QUARTUS_PROJECT_DIR)"; pwd))
580 | ELF_PATCH_FLAG += --quartus_project_dir "$(ABS_QUARTUS_PROJECT_DIR)"
581 | endif
582 |
583 | # Patch the Elf and download args with the JDI_FILE if specified
584 | ifneq ($(wildcard $(JDI_FILE)),)
585 | ELF_PATCH_FLAG += --jdi $(JDI_FILE)
586 | DOWNLOAD_JDI_FLAG := --jdi $(JDI_FILE)
587 | endif
588 |
589 | # Patch the Elf with the SOPCINFO_FILE if specified
590 | ifneq ($(wildcard $(SOPCINFO_FILE)),)
591 | ELF_PATCH_FLAG += --sopcinfo $(SOPCINFO_FILE)
592 | endif
593 |
594 | # Use the DOWNLOAD_CABLE variable to specify which JTAG cable to use.
595 | # This is not needed if you only have one cable.
596 | ifneq ($(DOWNLOAD_CABLE),)
597 | DOWNLOAD_CABLE_FLAG := --cable '$(DOWNLOAD_CABLE)'
598 | endif
599 |
600 |
601 | #------------------------------------------------------------------------------
602 | # BUILD PRE/POST PROCESS
603 | #------------------------------------------------------------------------------
604 | build_pre_process :
605 | $(BUILD_PRE_PROCESS)
606 |
607 | build_post_process :
608 | $(BUILD_POST_PROCESS)
609 |
610 | .PHONY: build_pre_process build_post_process
611 |
612 |
613 | #------------------------------------------------------------------------------
614 | # TOOLS
615 | #------------------------------------------------------------------------------
616 |
617 | #
618 | # Set tool default variables if not already defined.
619 | # If these are defined, they would typically be defined in an
620 | # included makefile fragment.
621 | #
622 | ifeq ($(DEFAULT_CROSS_COMPILE),)
623 | DEFAULT_CROSS_COMPILE := nios2-elf-
624 | endif
625 |
626 | ifeq ($(DEFAULT_STACKREPORT),)
627 | DEFAULT_STACKREPORT := nios2-stackreport
628 | endif
629 |
630 | ifeq ($(DEFAULT_DOWNLOAD),)
631 | DEFAULT_DOWNLOAD := nios2-download
632 | endif
633 |
634 | ifeq ($(DEFAULT_FLASHPROG),)
635 | DEFAULT_FLASHPROG := nios2-flash-programmer
636 | endif
637 |
638 | ifeq ($(DEFAULT_ELFPATCH),)
639 | DEFAULT_ELFPATCH := nios2-elf-insert
640 | endif
641 |
642 | ifeq ($(DEFAULT_RM),)
643 | DEFAULT_RM := rm -f
644 | endif
645 |
646 | ifeq ($(DEFAULT_CP),)
647 | DEFAULT_CP := cp -f
648 | endif
649 |
650 | ifeq ($(DEFAULT_MKDIR),)
651 | DEFAULT_MKDIR := mkdir -p
652 | endif
653 |
654 | #
655 | # Set tool variables to defaults if not already defined.
656 | # If these are defined, they would typically be defined by a
657 | # setting in the generated portion of this makefile.
658 | #
659 | ifeq ($(CROSS_COMPILE),)
660 | CROSS_COMPILE := $(DEFAULT_CROSS_COMPILE)
661 | endif
662 |
663 | ifeq ($(origin CC),default)
664 | CC := $(CROSS_COMPILE)gcc -xc
665 | endif
666 |
667 | ifeq ($(origin CXX),default)
668 | CXX := $(CROSS_COMPILE)gcc -xc++
669 | endif
670 |
671 | ifeq ($(origin AS),default)
672 | AS := $(CROSS_COMPILE)gcc
673 | endif
674 |
675 | ifeq ($(origin AR),default)
676 | AR := $(CROSS_COMPILE)ar
677 | endif
678 |
679 | ifeq ($(origin LD),default)
680 | LD := $(CROSS_COMPILE)g++
681 | endif
682 |
683 | ifeq ($(origin RM),default)
684 | RM := $(DEFAULT_RM)
685 | endif
686 |
687 | ifeq ($(NM),)
688 | NM := $(CROSS_COMPILE)nm
689 | endif
690 |
691 | ifeq ($(CP),)
692 | CP := $(DEFAULT_CP)
693 | endif
694 |
695 | ifeq ($(OBJDUMP),)
696 | OBJDUMP := $(CROSS_COMPILE)objdump
697 | endif
698 |
699 | ifeq ($(OBJCOPY),)
700 | OBJCOPY := $(CROSS_COMPILE)objcopy
701 | endif
702 |
703 | ifeq ($(STACKREPORT),)
704 | STACKREPORT := $(DEFAULT_STACKREPORT) --prefix $(CROSS_COMPILE)
705 | else
706 | DISABLE_STACKREPORT := 1
707 | endif
708 |
709 | ifeq ($(DOWNLOAD),)
710 | DOWNLOAD := $(DEFAULT_DOWNLOAD)
711 | endif
712 |
713 | ifeq ($(FLASHPROG),)
714 | FLASHPROG := $(DEFAULT_FLASHPROG)
715 | endif
716 |
717 | ifeq ($(ELFPATCH),)
718 | ELFPATCH := $(DEFAULT_ELFPATCH)
719 | endif
720 |
721 | ifeq ($(MKDIR),)
722 | MKDIR := $(DEFAULT_MKDIR)
723 | endif
724 |
725 | #------------------------------------------------------------------------------
726 | # PATTERN RULES TO BUILD OBJECTS
727 | #------------------------------------------------------------------------------
728 |
729 | define compile.c
730 | @$(ECHO) Info: Compiling $< to $@
731 | @$(MKDIR) $(@D)
732 | $(CC) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<
733 | $(CC_POST_PROCESS)
734 | endef
735 |
736 | define compile.cpp
737 | @$(ECHO) Info: Compiling $< to $@
738 | @$(MKDIR) $(@D)
739 | $(CXX) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
740 | $(CXX_POST_PROCESS)
741 | endef
742 |
743 | # If assembling with the compiler, ensure "-Wa," is prepended to all APP_ASFLAGS
744 | ifeq ($(AS),$(patsubst %as,%,$(AS)))
745 | COMMA := ,
746 | APP_ASFLAGS := $(filter-out $(APP_CFLAGS),$(addprefix -Wa$(COMMA),$(patsubst -Wa$(COMMA)%,%,$(APP_ASFLAGS))))
747 | endif
748 |
749 | define compile.s
750 | @$(ECHO) Info: Assembling $< to $@
751 | @$(MKDIR) $(@D)
752 | $(AS) -MP -MMD -c $(APP_CPPFLAGS) $(APP_CFLAGS) $(APP_ASFLAGS) -o $@ $<
753 | $(AS_POST_PROCESS)
754 | endef
755 |
756 | ifeq ($(MAKE_VERSION),3.81)
757 | .SECONDEXPANSION:
758 |
759 | $(APP_OBJS_C): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.c)
760 | $(compile.c)
761 |
762 | $(APP_OBJS_CPP): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cpp)
763 | $(compile.cpp)
764 |
765 | $(APP_OBJS_CC): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cc)
766 | $(compile.cpp)
767 |
768 | $(APP_OBJS_CXX): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.cxx)
769 | $(compile.cpp)
770 |
771 | $(APP_OBJS_S): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.S)
772 | $(compile.s)
773 |
774 | $(APP_OBJS_SS): $(CONFIG_OBJ_DIR)/%.o: $$(call adjust-path-mixed,%.s)
775 | $(compile.s)
776 |
777 | endif # MAKE_VERSION != 3.81
778 |
779 | $(CONFIG_OBJ_DIR)/%.o: %.c
780 | $(compile.c)
781 |
782 | $(CONFIG_OBJ_DIR)/%.o: %.cpp
783 | $(compile.cpp)
784 |
785 | $(CONFIG_OBJ_DIR)/%.o: %.cc
786 | $(compile.cpp)
787 |
788 | $(CONFIG_OBJ_DIR)/%.o: %.cxx
789 | $(compile.cpp)
790 |
791 | $(CONFIG_OBJ_DIR)/%.o: %.S
792 | $(compile.s)
793 |
794 | $(CONFIG_OBJ_DIR)/%.o: %.s
795 | $(compile.s)
796 |
797 |
798 | #------------------------------------------------------------------------------
799 | # PATTERN RULES TO INTERMEDIATE FILES
800 | #------------------------------------------------------------------------------
801 |
802 | $(CONFIG_OBJ_DIR)/%.s: %.c
803 | @$(ECHO) Info: Compiling $< to $@
804 | @$(MKDIR) $(@D)
805 | $(CC) -S $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<
806 |
807 | $(CONFIG_OBJ_DIR)/%.s: %.cpp
808 | @$(ECHO) Info: Compiling $< to $@
809 | @$(MKDIR) $(@D)
810 | $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
811 |
812 | $(CONFIG_OBJ_DIR)/%.s: %.cc
813 | @$(ECHO) Info: Compiling $< to $@
814 | @$(MKDIR) $(@D)
815 | $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
816 |
817 | $(CONFIG_OBJ_DIR)/%.s: %.cxx
818 | @$(ECHO) Info: Compiling $< to $@
819 | @$(MKDIR) $(@D)
820 | $(CXX) -S $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
821 |
822 | $(CONFIG_OBJ_DIR)/%.i: %.c
823 | @$(ECHO) Info: Compiling $< to $@
824 | @$(MKDIR) $(@D)
825 | $(CC) -E $(APP_CPPFLAGS) $(APP_CFLAGS) -o $@ $<
826 |
827 | $(CONFIG_OBJ_DIR)/%.i: %.cpp
828 | @$(ECHO) Info: Compiling $< to $@
829 | @$(MKDIR) $(@D)
830 | $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
831 |
832 | $(CONFIG_OBJ_DIR)/%.i: %.cc
833 | @$(ECHO) Info: Compiling $< to $@
834 | @$(MKDIR) $(@D)
835 | $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
836 |
837 | $(CONFIG_OBJ_DIR)/%.i: %.cxx
838 | @$(ECHO) Info: Compiling $< to $@
839 | @$(MKDIR) $(@D)
840 | $(CXX) -E $(APP_CPPFLAGS) $(APP_CXXFLAGS) $(APP_CFLAGS) -o $@ $<
841 |
842 |
843 | #------------------------------------------------------------------------------
844 | # TARGET RULES
845 | #------------------------------------------------------------------------------
846 |
847 | .PHONY : help
848 | help :
849 | @$(ECHO) "Summary of Makefile targets"
850 | @$(ECHO) " Build targets:"
851 | @$(ECHO) " all (default) - Application and all libraries (including BSP)"
852 | @$(ECHO) " bsp - Just the BSP"
853 | @$(ECHO) " libs - All libraries (including BSP)"
854 | @$(ECHO) " flash - All flash files"
855 | @$(ECHO) " mem_init_generate - All memory initialization files"
856 | @$(ECHO)
857 | @$(ECHO) " Clean targets:"
858 | @$(ECHO) " clean_all - Application and all libraries (including BSP)"
859 | @$(ECHO) " clean - Just the application"
860 | @$(ECHO) " clean_bsp - Just the BSP"
861 | @$(ECHO) " clean_libs - All libraries (including BSP)"
862 | @$(ECHO)
863 | @$(ECHO) " Run targets:"
864 | @$(ECHO) " download-elf - Download and run your elf executable"
865 | @$(ECHO) " program-flash - Program flash contents to the board"
866 |
867 | # Handy rule to skip making libraries and just make application.
868 | .PHONY : app
869 | app : $(ELF)
870 |
871 | ifeq ($(CREATE_OBJDUMP), 1)
872 | app : $(OBJDUMP_NAME)
873 | endif
874 |
875 | ifeq ($(CREATE_ELF_DERIVED_FILES),1)
876 | app : elf_derived_files
877 | endif
878 |
879 | .PHONY: elf_derived_files
880 | elf_derived_files: default_mem_init
881 |
882 | # Handy rule for making just the BSP.
883 | .PHONY : bsp
884 | bsp :
885 | @$(ECHO) Info: Building $(BSP_ROOT_DIR)
886 | @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR)
887 |
888 |
889 | # Make sure all makeable libraries (including the BSP) are up-to-date.
890 | LIB_TARGETS := $(patsubst %,%-recurs-make-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS))
891 |
892 | .PHONY : libs
893 | libs : $(LIB_TARGETS)
894 |
895 | ifneq ($(strip $(LIB_TARGETS)),)
896 | $(LIB_TARGETS): %-recurs-make-lib:
897 | @$(ECHO) Info: Building $*
898 | $(MAKE) --no-print-directory -C $*
899 | endif
900 |
901 | ifneq ($(strip $(APP_LDDEPS)),)
902 | $(APP_LDDEPS): libs
903 | @true
904 | endif
905 |
906 | # Rules to force your project to rebuild or relink
907 | # .force_relink file will cause any application that depends on this project to relink
908 | # .force_rebuild file will cause this project to rebuild object files
909 | # .force_rebuild_all file will cause this project and any project that depends on this project to rebuild object files
910 |
911 | FORCE_RELINK_DEP := .force_relink
912 | FORCE_REBUILD_DEP := .force_rebuild
913 | FORCE_REBUILD_ALL_DEP := .force_rebuild_all
914 | FORCE_REBUILD_DEP_LIST := $(CONFIG_OBJ_DIR)/$(FORCE_RELINK_DEP) $(CONFIG_OBJ_DIR)/$(FORCE_REBUILD_DEP) $(FORCE_REBUILD_ALL_DEP)
915 |
916 | $(FORCE_REBUILD_DEP_LIST):
917 |
918 | $(APP_OBJS): $(wildcard $(CONFIG_OBJ_DIR)/$(FORCE_REBUILD_DEP)) $(wildcard $(addsuffix /$(FORCE_REBUILD_ALL_DEP), . $(ALT_LIBRARY_DIRS)))
919 |
920 | $(ELF): $(wildcard $(addsuffix /$(FORCE_RELINK_DEP), $(CONFIG_OBJ_DIR) $(ALT_LIBRARY_DIRS)))
921 |
922 |
923 | # Clean just the application.
924 | .PHONY : clean
925 | ifeq ($(CREATE_ELF_DERIVED_FILES),1)
926 | clean : clean_elf_derived_files
927 | endif
928 |
929 | clean :
930 | @$(RM) -r $(ELF) $(OBJDUMP_NAME) $(LINKER_MAP_NAME) $(OBJ_ROOT_DIR) $(RUNTIME_ROOT_DIR) $(FORCE_REBUILD_DEP_LIST)
931 | @$(ECHO) [$(APP_NAME) clean complete]
932 |
933 | # Clean just the BSP.
934 | .PHONY : clean_bsp
935 | clean_bsp :
936 | @$(ECHO) Info: Cleaning $(BSP_ROOT_DIR)
937 | @$(MAKE) --no-print-directory -C $(BSP_ROOT_DIR) clean
938 |
939 | # Clean all makeable libraries including the BSP.
940 | LIB_CLEAN_TARGETS := $(patsubst %,%-recurs-make-clean-lib,$(MAKEABLE_LIBRARY_ROOT_DIRS))
941 |
942 | .PHONY : clean_libs
943 | clean_libs : $(LIB_CLEAN_TARGETS)
944 |
945 | ifneq ($(strip $(LIB_CLEAN_TARGETS)),)
946 | $(LIB_CLEAN_TARGETS): %-recurs-make-clean-lib:
947 | @$(ECHO) Info: Cleaning $*
948 | $(MAKE) --no-print-directory -C $* clean
949 | endif
950 |
951 | .PHONY: clean_elf_derived_files
952 | clean_elf_derived_files: mem_init_clean
953 |
954 | # Clean application and all makeable libraries including the BSP.
955 | .PHONY : clean_all
956 | clean_all : clean mem_init_clean clean_libs
957 |
958 | # Include the dependency files unless the make goal is performing a clean
959 | # of the application.
960 | ifneq ($(firstword $(MAKECMDGOALS)),clean)
961 | ifneq ($(firstword $(MAKECMDGOALS)),clean_all)
962 | -include $(APP_DEPS)
963 | endif
964 | endif
965 |
966 | .PHONY : download-elf
967 | download-elf : $(ELF)
968 | @if [ "$(DOWNLOAD)" = "none" ]; \
969 | then \
970 | $(ECHO) Downloading $(ELF) not supported; \
971 | else \
972 | $(ECHO) Info: Downloading $(ELF); \
973 | $(DOWNLOAD) --go --cpu_name=$(CPU_NAME) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) $(DOWNLOAD_JDI_FLAG) $(WRITE_GMON_OPTION) $(ELF); \
974 | fi
975 |
976 | # Delete the target of a rule if it has changed and its commands exit
977 | # with a nonzero exit status.
978 | .DELETE_ON_ERROR:
979 |
980 | # Rules for flash programming commands
981 | PROGRAM_FLASH_SUFFIX := -program
982 | PROGRAM_FLASH_TARGET := $(addsuffix $(PROGRAM_FLASH_SUFFIX), $(FLASH_FILES))
983 |
984 | .PHONY : program-flash
985 | program-flash : $(PROGRAM_FLASH_TARGET)
986 |
987 | .PHONY : $(PROGRAM_FLASH_TARGET)
988 | $(PROGRAM_FLASH_TARGET) : flash
989 | @if [ "$(FLASHPROG)" = "none" ]; \
990 | then \
991 | $(ECHO) Programming flash not supported; \
992 | else \
993 | $(ECHO) Info: Programming $(basename $@).flash; \
994 | if [ -z "$($(basename $@)_EPCS_FLAGS)" ]; \
995 | then \
996 | $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \
997 | $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --base=$($(basename $@)_START) $(basename $@).flash; \
998 | else \
999 | $(ECHO) $(FLASHPROG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \
1000 | $(FLASHPROG) $(DOWNLOAD_CABLE_FLAG) $(SOPC_SYSID_FLAG) --epcs --base=$($(basename $@)_START) $(basename $@).flash; \
1001 | fi \
1002 | fi
1003 |
1004 |
1005 | # Rules for simulating with an HDL Simulator [QSYS only]
1006 | ifeq ($(QSYS),1)
1007 | #Create a top level modelsim script load_sim.tcl to source generate msim_setup.tcl and copy mem initialization files
1008 | CREATE_TOP_SIM_SCRIPT := alt-create-top-sim-script
1009 |
1010 | ifeq ($(VSIM),)
1011 | VSIM_EXE := "$(if $(VSIM_DIR),$(VSIM_DIR)/,)vsim"
1012 | ifeq ($(ENABLE_VSIM_GUI),1)
1013 | VSIM := $(VSIM_EXE) -gui
1014 | else
1015 | VSIM := $(VSIM_EXE) -c
1016 | endif # ENABLE_VSIM_GUI == 1
1017 | endif # VSIM not set
1018 |
1019 | ifeq ($(SPD),)
1020 | ifneq ($(ABS_QUARTUS_PROJECT_DIR),)
1021 | ifneq ($(SOPC_NAME),)
1022 | SPD_LOCATION = $(ABS_QUARTUS_PROJECT_DIR)/$(SOPC_NAME)_tb/$(SOPC_NAME)_tb/$(SOPC_NAME)_tb.spd
1023 | LEGACY_SPD_LOCATION = $(ABS_QUARTUS_PROJECT_DIR)/$(SOPC_NAME)_tb.spd
1024 | SPD = $(if $(wildcard $(SPD_LOCATION)),$(SPD_LOCATION),$(LEGACY_SPD_LOCATION))
1025 | endif # SOPC_NAME set
1026 | endif # ABS_QUARTUS_PROJECT_DIR set
1027 | endif # SPD == empty string
1028 |
1029 |
1030 | ifeq ($(LOAD_SIM_SCRIPT),)
1031 | SIM_SCRIPT_DIR := $(RUNTIME_ROOT_DIR)/sim
1032 | LOAD_SIM_SCRIPT := $(SIM_SCRIPT_DIR)/mentor/load_sim.tcl
1033 | endif # LOAD_SIM_SCRIPT == empty string
1034 |
1035 | ifeq ($(MAKE_VERSION),3.81)
1036 | ABS_MEM_INIT_DESCRIPTOR_FILE := $(abspath $(MEM_INIT_DESCRIPTOR_FILE))
1037 | else
1038 | ABS_MEM_INIT_DESCRIPTOR_FILE := $(call adjust-path-mixed,$(shell pwd))/$(MEM_INIT_DESCRIPTOR_FILE)
1039 | endif
1040 |
1041 | $(LOAD_SIM_SCRIPT): $(SPD) $(MEM_INIT_DESCRIPTOR_FILE)
1042 | ifeq ($(SPD),)
1043 | $(error No SPD file specified. Ensure QUARTUS_PROJECT_DIR variable is set)
1044 | endif
1045 | @$(MKDIR) $(SIM_SCRIPT_DIR)
1046 | $(CREATE_TOP_SIM_SCRIPT) --spd=$(SPD) --mem-init-spd=$(abspath $(MEM_INIT_DESCRIPTOR_FILE)) --output-directory=$(SIM_SCRIPT_DIR)
1047 |
1048 | VSIM_COMMAND = \
1049 | cd $(dir $(LOAD_SIM_SCRIPT)) && \
1050 | $(VSIM) -do "do $(notdir $(LOAD_SIM_SCRIPT)); ld; $(if $(VSIM_RUN_TIME),run ${VSIM_RUN_TIME};quit;)"
1051 |
1052 | .PHONY: sim
1053 | sim: $(LOAD_SIM_SCRIPT) mem_init_generate
1054 | ifeq ($(LOAD_SIM_SCRIPT),)
1055 | $(error LOAD_SIM_SCRIPT not set)
1056 | endif
1057 | $(VSIM_COMMAND)
1058 |
1059 | endif # QSYS == 1
1060 |
1061 |
1062 |
1063 |
1064 | #------------------------------------------------------------------------------
1065 | # ELF TARGET RULE
1066 | #------------------------------------------------------------------------------
1067 | # Rule for constructing the executable elf file.
1068 | $(ELF) : $(APP_OBJS) $(LINKER_SCRIPT) $(APP_LDDEPS)
1069 | @$(ECHO) Info: Linking $@
1070 | $(LD) $(APP_LDFLAGS) $(APP_CFLAGS) -o $@ $(filter-out $(CRT0),$(APP_OBJS)) $(APP_LIBS) $(APP_BSP_DEP_LIBS)
1071 | ifneq ($(DISABLE_ELFPATCH),1)
1072 | $(ELFPATCH) $@ $(ELF_PATCH_FLAG)
1073 | endif
1074 | ifneq ($(DISABLE_STACKREPORT),1)
1075 | @bash -c "$(STACKREPORT) $@"
1076 | endif
1077 |
1078 | $(OBJDUMP_NAME) : $(ELF)
1079 | @$(ECHO) Info: Creating $@
1080 | $(OBJDUMP) $(OBJDUMP_FLAGS) $< >$@
1081 |
1082 | # Rule for printing the name of the elf file
1083 | .PHONY: print-elf-name
1084 | print-elf-name:
1085 | @$(ECHO) $(ELF)
1086 |
1087 |
1088 |
--------------------------------------------------------------------------------