diff --git a/tools/pioasm/.gitignore b/tools/pioasm/.gitignore new file mode 100644 index 000000000..3a777790f --- /dev/null +++ b/tools/pioasm/.gitignore @@ -0,0 +1 @@ +test/coverage/ diff --git a/tools/pioasm/BUILD.bazel b/tools/pioasm/BUILD.bazel index f706960bf..a56280a29 100644 --- a/tools/pioasm/BUILD.bazel +++ b/tools/pioasm/BUILD.bazel @@ -13,7 +13,6 @@ cc_library( "gen/location.h", "gen/parser.cpp", "gen/parser.hpp", - "go_output.cpp", "main.cpp", "output_format.h", "pio_assembler.cpp", @@ -39,6 +38,8 @@ cc_library( target_compatible_with = ["//bazel/constraint:host"], ) +# Register and link outputs as dynamic libraries to ensure they are properly recognized. + cc_library( name = "json_output", srcs = ["json_output.cpp"], @@ -67,6 +68,13 @@ cc_library( alwayslink = True, ) +cc_library( + name = "go_output", + srcs = ["go_output.cpp"], + deps = [":pioasm_core"], + alwayslink = True, +) + cc_library( name = "ada_output", srcs = ["ada_output.cpp"], @@ -88,9 +96,64 @@ cc_binary( deps = [ ":ada_output", ":c_sdk_output", + ":go_output", + ":hex_output", + ":json_output", + ":pioasm_core", + ":python_output", + ], +) + +py_test( + name = "pioasm_tests", + srcs = ["test/run_tests.py"], + data = glob(["test/**/*.pio"]) + [":pioasm"], + env = { + "PIOASM_BIN": "$(location :pioasm)", + }, + main = "test/run_tests.py", + size = "small", + timeout = "short", +) + +py_test( + name = "pioasm_coverage_tests", + srcs = ["test/run_tests_wrapper.py"], + data = glob(["test/**/*.pio"]) + [ + ":pioasm", + "test/run_tests.py", + ], + env = { + "PIOASM_BIN": "$(location :pioasm)", + }, + main = "test/run_tests_wrapper.py", + size = "small", + timeout = "short", +) + +cc_test( + name = "pioasm_core_coverage_test", + srcs = ["test/pioasm_core_coverage_test.cc"], + data = glob(["test/**/*.pio"]), + copts = select({ + "@rules_cc//cc/compiler:msvc-cl": ["/std:c++20"], + "//conditions:default": ["-std=c++17"], + }), + deps = [ + ":ada_output", + ":c_sdk_output", + ":go_output", ":hex_output", ":json_output", ":pioasm_core", ":python_output", ], + size = "small", + timeout = "short", +) + +py_binary( + name = "pioasm_coverage", + srcs = ["test/coverage.py"], + main = "test/coverage.py", ) diff --git a/tools/pioasm/test/README.md b/tools/pioasm/test/README.md new file mode 100644 index 000000000..03804af9c --- /dev/null +++ b/tools/pioasm/test/README.md @@ -0,0 +1,35 @@ +# PIOASM Tests and Coverage + +This folder contains the `.pio` fixtures, the Python test runner, and the +coverage helper for Bazel. + +## Run tests + +- Direct: `./run_tests.py` +- Overwrite expected output: `./run_tests.py --overwrite` +- Bazel: `bazel test //tools/pioasm:pioasm_coverage_tests` + +## Coverage + +Coverage is generated by `coverage.py` and stored under `test/coverage/`. + +- Direct: `python3 coverage.py` +- Bazel: `bazel run //tools/pioasm:pioasm_coverage` + +### Dependencies + +Coverage relies on: +- Bazel (matching the repo `.bazelversion`) +- LLVM tools: `llvm-cov` and `llvm-profdata` +- `genhtml` (optional, to build HTML reports) + +macOS: +- Install LLVM tools (Xcode): `xcode-select --install` +- Install `genhtml` (lcov): `brew install lcov` + +Linux (Debian/Ubuntu): +- LLVM tools: `sudo apt-get install llvm` +- `genhtml`: `sudo apt-get install lcov` + +If `genhtml` is not installed, `coverage.py` still writes `coverage.lcov` +but skips HTML generation. diff --git a/tools/pioasm/test/coverage.py b/tools/pioasm/test/coverage.py new file mode 100644 index 000000000..0b8c9083c --- /dev/null +++ b/tools/pioasm/test/coverage.py @@ -0,0 +1,213 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2024 Raspberry Pi (Trading) Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Generate coverage report for pioasm and optional HTML output. + +from __future__ import annotations + +import os +from pathlib import Path +import re +import shutil +import subprocess +import sys +import tempfile + + +def _run(cmd, check=True, capture_output=False): + return subprocess.run( + cmd, + check=check, + text=True, + capture_output=capture_output, + ) + + +def _bazel_info(key: str) -> str: + result = _run(["bazel", "info", key], capture_output=True) + return result.stdout.strip() + + +def _has_da(path: Path) -> bool: + try: + with path.open("r", encoding="utf-8") as handle: + for line in handle: + if line.startswith("DA:"): + return True + except FileNotFoundError: + return False + return False + + +def _find_tool(name: str) -> str | None: + try: + result = _run(["xcrun", "-f", name], check=False, capture_output=True) + candidate = result.stdout.strip() + if result.returncode == 0 and candidate: + return candidate + except FileNotFoundError: + pass + return shutil.which(name) + + +def _collect_profraw(paths) -> list[Path]: + profraw_files = [] + for base in paths: + if not base or not base.exists(): + continue + for root, _, files in os.walk(base): + for filename in files: + if filename.endswith(".profraw"): + profraw_files.append(Path(root) / filename) + return profraw_files + + +def _rewrite_paths(coverage_path: Path, root_dir: Path) -> None: + root_prefix = f"SF:{root_dir.as_posix()}/" + fd, tmp_name = tempfile.mkstemp(prefix="pioasm-cov-rewrite.") + os.close(fd) + tmp_rewrite = Path(tmp_name) + try: + with coverage_path.open("r", encoding="utf-8") as src, tmp_rewrite.open( + "w", encoding="utf-8" + ) as dst: + for line in src: + if line.startswith("SF:"): + line = re.sub(r"^SF:.*/execroot/_main/", "SF:", line) + if line.startswith(root_prefix): + line = "SF:" + line[len(root_prefix):] + dst.write(line) + tmp_rewrite.replace(coverage_path) + finally: + if tmp_rewrite.exists(): + try: + tmp_rewrite.unlink() + except FileNotFoundError: + pass + + +def main() -> int: + if os.environ.get("BUILD_WORKSPACE_DIRECTORY"): + root_dir = Path(os.environ["BUILD_WORKSPACE_DIRECTORY"]).resolve() + else: + root_dir = Path(__file__).resolve().parents[3] + + os.chdir(root_dir) + _run( + [ + "bazel", + "coverage", + "//tools/pioasm:pioasm_core_coverage_test", + "--combined_report=lcov", + "--cache_test_results=no", + ] + ) + + coverage_src = root_dir / "bazel-out/_coverage/_coverage_report.dat" + if not coverage_src.exists(): + output_base = Path(_bazel_info("output_base")) + alt_src = output_base / "execroot/_main/bazel-out/_coverage/_coverage_report.dat" + if alt_src.exists(): + coverage_src = alt_src + else: + print( + f"Coverage report not found at {coverage_src} or {alt_src}", + file=sys.stderr, + ) + return 1 + + work_dest = coverage_src + temp_dir = None + if not os.access(work_dest, os.W_OK): + temp_dir = Path(tempfile.mkdtemp(prefix="pioasm-cov.")) + work_dest = temp_dir / "coverage.lcov" + + check_src = coverage_src if coverage_src.exists() else work_dest + if not _has_da(check_src): + llvm_cov = _find_tool("llvm-cov") + llvm_profdata = _find_tool("llvm-profdata") + if llvm_cov and llvm_profdata: + bazel_bin = Path(_bazel_info("bazel-bin")) + bazel_testlogs = Path(_bazel_info("bazel-testlogs")) + test_bin = bazel_bin / "tools/pioasm/pioasm_core_coverage_test" + output_base = Path(_bazel_info("output_base")) + profraw_files = _collect_profraw( + [ + bazel_testlogs / "_coverage", + output_base / "sandbox/sandbox_stash/TestRunner", + ] + ) + + if test_bin.exists() and profraw_files: + tmp_dir = Path(tempfile.mkdtemp(prefix="pioasm-cov-merge.")) + profdata_path = tmp_dir / "coverage.profdata" + _run( + [ + llvm_profdata, + "merge", + "-sparse", + *[str(p) for p in profraw_files], + "-o", + str(profdata_path), + ] + ) + with work_dest.open("w", encoding="utf-8") as handle: + subprocess.run( + [ + llvm_cov, + "export", + "-format=lcov", + f"-instr-profile={profdata_path}", + str(test_bin), + ], + check=True, + text=True, + stdout=handle, + ) + shutil.rmtree(tmp_dir, ignore_errors=True) + + coverage_dir = root_dir / "tools/pioasm/test/coverage" + coverage_dir.mkdir(parents=True, exist_ok=True) + coverage_dest = coverage_dir / "coverage.lcov" + if coverage_dest.exists(): + try: + coverage_dest.chmod(coverage_dest.stat().st_mode | 0o200) + except OSError: + pass + + source_path = work_dest if work_dest.exists() else coverage_src + shutil.copyfile(source_path, coverage_dest) + print(f"Coverage report written to {coverage_dest}") + + _rewrite_paths(coverage_dest, root_dir) + + genhtml_bin = shutil.which("genhtml") + if genhtml_bin: + html_dir = coverage_dir / "html" + result = subprocess.run( + [ + genhtml_bin, + str(coverage_dest), + "-o", + str(html_dir), + "--ignore-errors", + "inconsistent,unsupported", + ], + text=True, + ) + if result.returncode == 0: + print(f"HTML coverage written to {html_dir}") + else: + print("genhtml failed; HTML coverage not generated", file=sys.stderr) + + if temp_dir: + shutil.rmtree(temp_dir, ignore_errors=True) + + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/pioasm/test/errors/clock/test_clock_div_errors.pio b/tools/pioasm/test/errors/clock/test_clock_div_errors.pio new file mode 100644 index 000000000..f58885eec --- /dev/null +++ b/tools/pioasm/test/errors/clock/test_clock_div_errors.pio @@ -0,0 +1,23 @@ +// run: pioasm -v 1 input.pio +.program clock_div_too_small +.pio_version 1 +.clock_div 0.5 + nop + +.program clock_div_too_large +.pio_version 1 +.clock_div 65536.0 + nop + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.1-14: clock divider must be between 1 and 65535 +// 4 | .clock_div 0.5 +// | ^~~~~~~~~~~~~~ +// input.pio:9.1-18: clock divider must be between 1 and 65535 +// 9 | .clock_div 65536.0 +// | ^~~~~~~~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/fifo/test_fifo_autopush_incompatible_errors.pio b/tools/pioasm/test/errors/fifo/test_fifo_autopush_incompatible_errors.pio new file mode 100644 index 000000000..06e5c07c3 --- /dev/null +++ b/tools/pioasm/test/errors/fifo/test_fifo_autopush_incompatible_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program fifo_autopush_incompatible +.fifo txput +.in 1 auto + in pins, 1 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.7-11: PIO version 1 is required for 'txput' +// 3 | .fifo txput +// | ^~~~~ +// diff --git a/tools/pioasm/test/errors/fifo/test_fifo_config_errors.pio b/tools/pioasm/test/errors/fifo/test_fifo_config_errors.pio new file mode 100644 index 000000000..12058c270 --- /dev/null +++ b/tools/pioasm/test/errors/fifo/test_fifo_config_errors.pio @@ -0,0 +1,31 @@ +// run: pioasm -v 1 input.pio +.program fifo_push_error +.pio_version 1 +.fifo tx + push + +.program fifo_get_error +.pio_version 1 +.fifo txput + mov osr, rxfifo[0] + +.program fifo_put_error +.pio_version 1 +.fifo txget + mov rxfifo[0], isr + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.5-8: FIFO must be configured for 'txrx' or 'rx' to use this instruction +// 5 | push +// | ^~~~ +// input.pio:10.5-22: FIFO must be configured for 'txget' or 'putget' to use this instruction +// 10 | mov osr, rxfifo[0] +// | ^~~~~~~~~~~~~~~~~~ +// input.pio:15.5-22: FIFO must be configured for 'txput' or 'putget' to use this instruction +// 15 | mov rxfifo[0], isr +// | ^~~~~~~~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/fifo/test_fifo_index_errors.pio b/tools/pioasm/test/errors/fifo/test_fifo_index_errors.pio new file mode 100644 index 000000000..3f55cc69d --- /dev/null +++ b/tools/pioasm/test/errors/fifo/test_fifo_index_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm -v 1 input.pio +.program fifo_index_invalid +.pio_version 1 +.fifo putget + mov rxfifo[8], isr +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.16: FIFO index myst be between 0 and 7 +// 5 | mov rxfifo[8], isr +// | ^ +// diff --git a/tools/pioasm/test/errors/fifo/test_fifo_invalid_mode_errors.pio b/tools/pioasm/test/errors/fifo/test_fifo_invalid_mode_errors.pio new file mode 100644 index 000000000..270a2da2c --- /dev/null +++ b/tools/pioasm/test/errors/fifo/test_fifo_invalid_mode_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program fifo_invalid_mode +.fifo bogus + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.7-11: syntax error, unexpected identifier +// 3 | .fifo bogus +// | ^~~~~ +// diff --git a/tools/pioasm/test/errors/fifo/test_fifo_missing_mode_errors.pio b/tools/pioasm/test/errors/fifo/test_fifo_missing_mode_errors.pio new file mode 100644 index 000000000..fbb86be3f --- /dev/null +++ b/tools/pioasm/test/errors/fifo/test_fifo_missing_mode_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program fifo_missing_mode +.fifo + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.1-5: expected txrx, tx or rx +// 3 | .fifo +// | ^~~~~ +// diff --git a/tools/pioasm/test/errors/fifo/test_fifo_source_errors.pio b/tools/pioasm/test/errors/fifo/test_fifo_source_errors.pio new file mode 100644 index 000000000..d7dda542d --- /dev/null +++ b/tools/pioasm/test/errors/fifo/test_fifo_source_errors.pio @@ -0,0 +1,23 @@ +// run: pioasm -v 1 input.pio +.program fifo_invalid_source +.pio_version 1 +.fifo txput + mov rxfifo[0], x + +.program fifo_invalid_dest +.pio_version 1 +.fifo txget + mov x, rxfifo[0] + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.5-20: mov rxfifo[] source must be isr +// 5 | mov rxfifo[0], x +// | ^~~~~~~~~~~~~~~~ +// input.pio:10.5-20: mov ,txfifo[] target must be osr +// 10 | mov x, rxfifo[0] +// | ^~~~~~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_circular_dependency_errors.pio b/tools/pioasm/test/errors/general/test_circular_dependency_errors.pio new file mode 100644 index 000000000..cbea74ffe --- /dev/null +++ b/tools/pioasm/test/errors/general/test_circular_dependency_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program circular_dependency +.define a b + 1 +.define b a + 1 + .word a +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.11: circular dependency in definition of 'a'; detected at input.pio:4.11) +// 5 | .word a +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_define_float_errors.pio b/tools/pioasm/test/errors/general/test_define_float_errors.pio new file mode 100644 index 000000000..62b04e7fd --- /dev/null +++ b/tools/pioasm/test/errors/general/test_define_float_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program define_float_error +.define PUBLIC bad_val 1.5 + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.24-26: syntax error, unexpected float +// 3 | .define PUBLIC bad_val 1.5 +// | ^~~ +// diff --git a/tools/pioasm/test/errors/general/test_delay_negative_errors.pio b/tools/pioasm/test/errors/general/test_delay_negative_errors.pio new file mode 100644 index 000000000..5dc22da4b --- /dev/null +++ b/tools/pioasm/test/errors/general/test_delay_negative_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program delay_negative + nop [-1] +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.10-11: instruction delay must be positive +// 3 | nop [-1] +// | ^~ +// diff --git a/tools/pioasm/test/errors/general/test_delay_sideset_limit_errors.pio b/tools/pioasm/test/errors/general/test_delay_sideset_limit_errors.pio new file mode 100644 index 000000000..8d057c125 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_delay_sideset_limit_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program delay_sideset_limit +.side_set 5 + nop side 0 [1] +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.17: the instruction delay limit is 0 because of the side set specified at input.pio:3.1-11 +// 4 | nop side 0 [1] +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_delay_too_large_errors.pio b/tools/pioasm/test/errors/general/test_delay_too_large_errors.pio new file mode 100644 index 000000000..fc4cd9591 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_delay_too_large_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program delay_too_large + nop [32] +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.10-11: instruction delay must be <= 31 +// 3 | nop [32] +// | ^~ +// diff --git a/tools/pioasm/test/errors/general/test_duplicate_symbol_errors.pio b/tools/pioasm/test/errors/general/test_duplicate_symbol_errors.pio new file mode 100644 index 000000000..68dd22968 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_duplicate_symbol_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program dup_symbol +start: +start: + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.1-5: label 'start' was already defined at input.pio:3.1-5 +// 4 | start: +// | ^~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_error_cases.pio b/tools/pioasm/test/errors/general/test_error_cases.pio new file mode 100644 index 000000000..2c209e336 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_error_cases.pio @@ -0,0 +1,17 @@ +// run: pioasm input.pio +// expects an error +.program error_test + in pins, 0 ; invalid: bit count must be 1-32 + in pins, 33 ; invalid: bit count too large + jmp 99 ; invalid: address out of range + irq 8 ; invalid: IRQ number too large + +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.14: 'in' bit count must be >= 1 and <= 32 +// 4 | in pins, 0 ; invalid: bit count must be 1-32 +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_instruction_limit_errors.pio b/tools/pioasm/test/errors/general/test_instruction_limit_errors.pio new file mode 100644 index 000000000..03e824697 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_instruction_limit_errors.pio @@ -0,0 +1,44 @@ +// run: pioasm input.pio +.program over_limit + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:35.5-7: program instruction limit of 32 instruction(s) exceeded +// 35 | nop +// | ^~~ +// diff --git a/tools/pioasm/test/errors/general/test_invalid_character_errors.pio b/tools/pioasm/test/errors/general/test_invalid_character_errors.pio new file mode 100644 index 000000000..7898f04de --- /dev/null +++ b/tools/pioasm/test/errors/general/test_invalid_character_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program invalid_character +@ + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.1: invalid character: @ +// 3 | @ +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_irq_next_rel_errors.pio b/tools/pioasm/test/errors/general/test_irq_next_rel_errors.pio new file mode 100644 index 000000000..aa6ff7a60 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_irq_next_rel_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm -v 1 input.pio +.program irq_next_rel +.pio_version 1 + irq next set 0 rel +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.20-22: 'rel' is not supported for 'irq next' +// 4 | irq next set 0 rel +// | ^~~ +// diff --git a/tools/pioasm/test/errors/general/test_irq_prev_rel_errors.pio b/tools/pioasm/test/errors/general/test_irq_prev_rel_errors.pio new file mode 100644 index 000000000..3871fcb42 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_irq_prev_rel_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm -v 1 input.pio +.program irq_prev_rel +.pio_version 1 + irq prev set 0 rel +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.20-22: 'rel' is not supported for 'irq prev' +// 4 | irq prev set 0 rel +// | ^~~ +// diff --git a/tools/pioasm/test/errors/general/test_jmp_target_negative_errors.pio b/tools/pioasm/test/errors/general/test_jmp_target_negative_errors.pio new file mode 100644 index 000000000..3ef4bb8ac --- /dev/null +++ b/tools/pioasm/test/errors/general/test_jmp_target_negative_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program jmp_negative + jmp -1 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.9-10: jmp target address must be positive +// 3 | jmp -1 +// | ^~ +// diff --git a/tools/pioasm/test/errors/general/test_jmp_target_out_of_range_errors.pio b/tools/pioasm/test/errors/general/test_jmp_target_out_of_range_errors.pio new file mode 100644 index 000000000..e7f5f608a --- /dev/null +++ b/tools/pioasm/test/errors/general/test_jmp_target_out_of_range_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program jmp_out_of_range + jmp 5 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.9: jmp target address 5 is beyond the end of the program +// 3 | jmp 5 +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_lang_opt_invalid_errors.pio b/tools/pioasm/test/errors/general/test_lang_opt_invalid_errors.pio new file mode 100644 index 000000000..5b9e2b04a --- /dev/null +++ b/tools/pioasm/test/errors/general/test_lang_opt_invalid_errors.pio @@ -0,0 +1,16 @@ +// run: pioasm input.pio +.program lang_opt_invalid +.lang_opt python foo = "unterminated + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.24: invalid character: " +// 3 | .lang_opt python foo = "unterminated +// | ^ +// input.pio:3.1-22: expected format is .lang_opt language option_name = option_value +// 3 | .lang_opt python foo = "unterminated +// | ^~~~~~~~~~~~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_out_set_wait_errors.pio b/tools/pioasm/test/errors/general/test_out_set_wait_errors.pio new file mode 100644 index 000000000..5e7e330a8 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_out_set_wait_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program out_set_wait_invalid + out pins, 0 + set pins, 32 + wait 2 irq 0 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.15: 'out' bit count must be >= 1 and <= 32 +// 3 | out pins, 0 +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_sideset_bits_negative_errors.pio b/tools/pioasm/test/errors/general/test_sideset_bits_negative_errors.pio new file mode 100644 index 000000000..31b4d5958 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_sideset_bits_negative_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program sideset_bits_negative +.side_set -1 + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.11: syntax error, unexpected -, expecting ( or identifier or integer +// 3 | .side_set -1 +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_sideset_bits_optional_too_large_errors.pio b/tools/pioasm/test/errors/general/test_sideset_bits_optional_too_large_errors.pio new file mode 100644 index 000000000..f2cf1ee98 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_sideset_bits_optional_too_large_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program sideset_bits_optional_too_large +.side_set 5 opt + nop side 0 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.11: maximum number of side set bits with optional is 4 +// 3 | .side_set 5 opt +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_sideset_bits_too_large_errors.pio b/tools/pioasm/test/errors/general/test_sideset_bits_too_large_errors.pio new file mode 100644 index 000000000..e721622ae --- /dev/null +++ b/tools/pioasm/test/errors/general/test_sideset_bits_too_large_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program sideset_bits_too_large +.side_set 6 + nop side 0 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.11: maximum number of side set bits is 5 +// 3 | .side_set 6 +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_sideset_missing_errors.pio b/tools/pioasm/test/errors/general/test_sideset_missing_errors.pio new file mode 100644 index 000000000..aef90da59 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_sideset_missing_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program sideset_missing +.side_set 1 + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.5-7: instruction requires 'side' to specify side set value for the instruction because non optional sideset was specified for the program at input.pio:3.1-11 +// 4 | nop +// | ^~~ +// diff --git a/tools/pioasm/test/errors/general/test_sideset_value_negative_errors.pio b/tools/pioasm/test/errors/general/test_sideset_value_negative_errors.pio new file mode 100644 index 000000000..6d605ec46 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_sideset_value_negative_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program sideset_value_negative +.side_set 2 + nop side -1 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.14: syntax error, unexpected -, expecting ( or identifier or integer +// 4 | nop side -1 +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_sideset_value_too_large_errors.pio b/tools/pioasm/test/errors/general/test_sideset_value_too_large_errors.pio new file mode 100644 index 000000000..b175a6e64 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_sideset_value_too_large_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program sideset_value_too_large +.side_set 2 + nop side 4 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.14: the maximum side set value is 3 based on the configuration specified at input.pio:3.1-11 +// 4 | nop side 4 +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_syntax_error_missing_operand_errors.pio b/tools/pioasm/test/errors/general/test_syntax_error_missing_operand_errors.pio new file mode 100644 index 000000000..5424c362c --- /dev/null +++ b/tools/pioasm/test/errors/general/test_syntax_error_missing_operand_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program syntax_missing_operand + mov , x +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.9: syntax error, unexpected "," +// 3 | mov , x +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_syntax_error_unexpected_token_errors.pio b/tools/pioasm/test/errors/general/test_syntax_error_unexpected_token_errors.pio new file mode 100644 index 000000000..ce2af309e --- /dev/null +++ b/tools/pioasm/test/errors/general/test_syntax_error_unexpected_token_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program syntax_unexpected + jmp , +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.10: syntax error, unexpected end of line +// 3 | jmp , +// | ^ +// diff --git a/tools/pioasm/test/errors/general/test_undefined_symbol_errors.pio b/tools/pioasm/test/errors/general/test_undefined_symbol_errors.pio new file mode 100644 index 000000000..f7e44d464 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_undefined_symbol_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program undefined_symbol + .word missing_symbol +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.11-24: undefined symbol 'missing_symbol' +// 3 | .word missing_symbol +// | ^~~~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_unknown_directive_errors.pio b/tools/pioasm/test/errors/general/test_unknown_directive_errors.pio new file mode 100644 index 000000000..54e2d6989 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_unknown_directive_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program unknown_directive +.bogus 1 + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.1-6: unknown directive .bogus +// 3 | .bogus 1 +// | ^~~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_wait_irq_next_rel_errors.pio b/tools/pioasm/test/errors/general/test_wait_irq_next_rel_errors.pio new file mode 100644 index 000000000..8b1653ef9 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_wait_irq_next_rel_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm -v 1 input.pio +.program wait_irq_next_rel +.pio_version 1 + wait 0 irq next, 0 rel +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.24-26: 'rel' is not supported for 'irq next' +// 4 | wait 0 irq next, 0 rel +// | ^~~ +// diff --git a/tools/pioasm/test/errors/general/test_wait_irq_prev_rel_errors.pio b/tools/pioasm/test/errors/general/test_wait_irq_prev_rel_errors.pio new file mode 100644 index 000000000..d187e4f3a --- /dev/null +++ b/tools/pioasm/test/errors/general/test_wait_irq_prev_rel_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm -v 1 input.pio +.program wait_irq_prev_rel +.pio_version 1 + wait 0 irq prev, 0 rel +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.24-26: 'rel' is not supported for 'irq prev' +// 4 | wait 0 irq prev, 0 rel +// | ^~~ +// diff --git a/tools/pioasm/test/errors/general/test_word_too_large_errors.pio b/tools/pioasm/test/errors/general/test_word_too_large_errors.pio new file mode 100644 index 000000000..0c1b2f14e --- /dev/null +++ b/tools/pioasm/test/errors/general/test_word_too_large_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program word_too_large + .word 0x1ffff +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.5-17: .word value must be a positive 16 bit value +// 3 | .word 0x1ffff +// | ^~~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_wrap_before_instruction_errors.pio b/tools/pioasm/test/errors/general/test_wrap_before_instruction_errors.pio new file mode 100644 index 000000000..5144db3e9 --- /dev/null +++ b/tools/pioasm/test/errors/general/test_wrap_before_instruction_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program wrap_error +.wrap + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.1-5: .wrap cannot be placed before the first program instruction +// 3 | .wrap +// | ^~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_wrap_duplicate_errors.pio b/tools/pioasm/test/errors/general/test_wrap_duplicate_errors.pio new file mode 100644 index 000000000..9550e4c3b --- /dev/null +++ b/tools/pioasm/test/errors/general/test_wrap_duplicate_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program wrap_duplicate + nop +.wrap +.wrap +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.1-5: .wrap was already specified at input.pio:4.1-5 +// 5 | .wrap +// | ^~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_wrap_target_after_end_errors.pio b/tools/pioasm/test/errors/general/test_wrap_target_after_end_errors.pio new file mode 100644 index 000000000..4124b88af --- /dev/null +++ b/tools/pioasm/test/errors/general/test_wrap_target_after_end_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program wrap_target_after_end + nop +.wrap_target +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.1-12: .wrap_target cannot be placed after the last program instruction +// 4 | .wrap_target +// | ^~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_wrap_target_duplicate_errors.pio b/tools/pioasm/test/errors/general/test_wrap_target_duplicate_errors.pio new file mode 100644 index 000000000..63e749eda --- /dev/null +++ b/tools/pioasm/test/errors/general/test_wrap_target_duplicate_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program wrap_target_duplicate +.wrap_target + nop +.wrap_target +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.1-12: .wrap_target was already specified at input.pio:3.1-12 +// 5 | .wrap_target +// | ^~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/general/test_wrap_with_no_instruction_errors.pio b/tools/pioasm/test/errors/general/test_wrap_with_no_instruction_errors.pio new file mode 100644 index 000000000..0beb8c00a --- /dev/null +++ b/tools/pioasm/test/errors/general/test_wrap_with_no_instruction_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program wrap_same_instruction +.wrap_target +.wrap + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.1-5: .wrap cannot be placed before the first program instruction +// 4 | .wrap +// | ^~~~~ +// diff --git a/tools/pioasm/test/errors/mov_status/test_mov_status_errors.pio b/tools/pioasm/test/errors/mov_status/test_mov_status_errors.pio new file mode 100644 index 000000000..7077be4ce --- /dev/null +++ b/tools/pioasm/test/errors/mov_status/test_mov_status_errors.pio @@ -0,0 +1,15 @@ +// run: pioasm -v 1 input.pio +.program mov_status_invalid_n +.pio_version 1 +.mov_status txfifo < 33 + mov x, status + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.22-23: fido depth should be >= 0 and <= 31 +// 4 | .mov_status txfifo < 33 +// | ^~ +// diff --git a/tools/pioasm/test/errors/mov_status/test_mov_status_irq_errors.pio b/tools/pioasm/test/errors/mov_status/test_mov_status_irq_errors.pio new file mode 100644 index 000000000..a2788c029 --- /dev/null +++ b/tools/pioasm/test/errors/mov_status/test_mov_status_irq_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm -v 1 input.pio +.program mov_status_irq +.pio_version 1 +.mov_status irq set 8 + mov x, status +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.21: irq number should be >= 0 and <= 7 +// 4 | .mov_status irq set 8 +// | ^ +// diff --git a/tools/pioasm/test/errors/mov_status/test_mov_status_missing_errors.pio b/tools/pioasm/test/errors/mov_status/test_mov_status_missing_errors.pio new file mode 100644 index 000000000..1e91fb756 --- /dev/null +++ b/tools/pioasm/test/errors/mov_status/test_mov_status_missing_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program mov_status_missing +.mov_status + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:2.28: expected 'txfifo < N', 'rxfifo < N' or 'irq set N' +// 2 | .program mov_status_missing +// | ^ +// diff --git a/tools/pioasm/test/errors/output/test_output_ada_missing_package_errors.pio b/tools/pioasm/test/errors/output/test_output_ada_missing_package_errors.pio new file mode 100644 index 000000000..c400d7f38 --- /dev/null +++ b/tools/pioasm/test/errors/output/test_output_ada_missing_package_errors.pio @@ -0,0 +1,10 @@ +// run: pioasm -o ada input.pio +.program missing_package + nop +// -- Output +// Command: pioasm -o ada input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// error: missing package name options for Ada format +// diff --git a/tools/pioasm/test/errors/output/test_output_ada_too_many_options_errors.pio b/tools/pioasm/test/errors/output/test_output_ada_too_many_options_errors.pio new file mode 100644 index 000000000..d8a248032 --- /dev/null +++ b/tools/pioasm/test/errors/output/test_output_ada_too_many_options_errors.pio @@ -0,0 +1,10 @@ +// run: pioasm -o ada -p First -p Second input.pio +.program too_many_options + nop +// -- Output +// Command: pioasm -o ada -p First -p Second input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// error: too many options for Ada format +// diff --git a/tools/pioasm/test/errors/output/test_output_hex_multiple_programs_errors.pio b/tools/pioasm/test/errors/output/test_output_hex_multiple_programs_errors.pio new file mode 100644 index 000000000..8a7936f7b --- /dev/null +++ b/tools/pioasm/test/errors/output/test_output_hex_multiple_programs_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm -o hex input.pio +.program hex_one + nop + +.program hex_two + nop +// -- Output +// Command: pioasm -o hex input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// error: hex output only supports a single program input +// diff --git a/tools/pioasm/test/errors/pin_config/test_autopush_threshold_invalid_errors.pio b/tools/pioasm/test/errors/pin_config/test_autopush_threshold_invalid_errors.pio new file mode 100644 index 000000000..312b5ef00 --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_autopush_threshold_invalid_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program autopush_threshold_invalid +.in 8 auto 33 + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.5: in pin count must be 32 for PIO version 0 +// 3 | .in 8 auto 33 +// | ^ +// diff --git a/tools/pioasm/test/errors/pin_config/test_in_count_too_large_v0_errors.pio b/tools/pioasm/test/errors/pin_config/test_in_count_too_large_v0_errors.pio new file mode 100644 index 000000000..37e1dc846 --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_in_count_too_large_v0_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program in_count_too_large_v0 +.in 33 + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.5-6: in pin count must be 32 for PIO version 0 +// 3 | .in 33 +// | ^~ +// diff --git a/tools/pioasm/test/errors/pin_config/test_in_count_too_large_v1_errors.pio b/tools/pioasm/test/errors/pin_config/test_in_count_too_large_v1_errors.pio new file mode 100644 index 000000000..0d3f09748 --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_in_count_too_large_v1_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm -v 1 input.pio +.program in_count_too_large_v1 +.pio_version 1 +.in 33 + nop +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.5-6: in pin count should be >= 1 and <= 32 +// 4 | .in 33 +// | ^~ +// diff --git a/tools/pioasm/test/errors/pin_config/test_out_count_too_large_errors.pio b/tools/pioasm/test/errors/pin_config/test_out_count_too_large_errors.pio new file mode 100644 index 000000000..6789cae66 --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_out_count_too_large_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program out_count_too_large +.out 33 + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.6-7: out pin count should be >= 0 and <= 32 +// 3 | .out 33 +// | ^~ +// diff --git a/tools/pioasm/test/errors/pin_config/test_set_count_too_large_errors.pio b/tools/pioasm/test/errors/pin_config/test_set_count_too_large_errors.pio new file mode 100644 index 000000000..d22bae7ee --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_set_count_too_large_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm input.pio +.program set_count_too_large +.set 6 + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.1-6: set pin count should be >= 0 and <= 5 +// 3 | .set 6 +// | ^~~~~~ +// diff --git a/tools/pioasm/test/errors/pin_config/test_wait_gpio_conflict_high_then_low_errors.pio b/tools/pioasm/test/errors/pin_config/test_wait_gpio_conflict_high_then_low_errors.pio new file mode 100644 index 000000000..ae47bc354 --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_wait_gpio_conflict_high_then_low_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm -v 1 input.pio +.program wait_gpio_conflict_high_then_low +.pio_version 1 + wait 0 gpio 40 + wait 0 gpio 0 +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.17: absolute GPIO number must be must be >= 16 and <= 47 as a GPIO number >32 has already been used +// 5 | wait 0 gpio 0 +// | ^ +// diff --git a/tools/pioasm/test/errors/pin_config/test_wait_gpio_conflict_low_then_high_errors.pio b/tools/pioasm/test/errors/pin_config/test_wait_gpio_conflict_low_then_high_errors.pio new file mode 100644 index 000000000..99cfacbc2 --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_wait_gpio_conflict_low_then_high_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm -v 1 input.pio +.program wait_gpio_conflict_low_then_high +.pio_version 1 + wait 0 gpio 0 + wait 0 gpio 40 +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:5.17-18: absolute GPIO number must be must be >= 0 and <= 31 as a GPIO number <16 has already been used +// 5 | wait 0 gpio 40 +// | ^~ +// diff --git a/tools/pioasm/test/errors/pin_config/test_wait_gpio_range_errors.pio b/tools/pioasm/test/errors/pin_config/test_wait_gpio_range_errors.pio new file mode 100644 index 000000000..74ef1669e --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_wait_gpio_range_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm -v 1 input.pio +.program wait_gpio_range +.pio_version 1 + wait 0 gpio 48 +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.17-18: absolute GPIO number must be must be >= 0 and <= 47 +// 4 | wait 0 gpio 48 +// | ^~ +// diff --git a/tools/pioasm/test/errors/pin_config/test_wait_missing_source_errors.pio b/tools/pioasm/test/errors/pin_config/test_wait_missing_source_errors.pio new file mode 100644 index 000000000..b599b620b --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_wait_missing_source_errors.pio @@ -0,0 +1,12 @@ +// run: pioasm input.pio +.program wait_missing_source + wait 0 +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.10: expected irq, gpio or pin +// 3 | wait 0 +// | ^ +// diff --git a/tools/pioasm/test/errors/pin_config/test_wait_missing_source_v1_errors.pio b/tools/pioasm/test/errors/pin_config/test_wait_missing_source_v1_errors.pio new file mode 100644 index 000000000..45a88433e --- /dev/null +++ b/tools/pioasm/test/errors/pin_config/test_wait_missing_source_v1_errors.pio @@ -0,0 +1,13 @@ +// run: pioasm -v 1 input.pio +.program wait_missing_source_v1 +.pio_version 1 + wait 0 +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.10: expected irq, gpio, pin or jmp_pin +// 4 | wait 0 +// | ^ +// diff --git a/tools/pioasm/test/errors/pio_version/test_gpio_range_errors.pio b/tools/pioasm/test/errors/pio_version/test_gpio_range_errors.pio new file mode 100644 index 000000000..c9c697a0b --- /dev/null +++ b/tools/pioasm/test/errors/pio_version/test_gpio_range_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm -v 0 input.pio +.program gpio_v0_overflow +.pio_version 0 + wait 0 gpio 32 + +// -- Output +// Command: pioasm -v 0 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.17-18: absolute GPIO number must be must be >= 0 and <= 31 +// 4 | wait 0 gpio 32 +// | ^~ +// diff --git a/tools/pioasm/test/errors/pio_version/test_pio_version_feature_errors.pio b/tools/pioasm/test/errors/pio_version/test_pio_version_feature_errors.pio new file mode 100644 index 000000000..a91aa2b95 --- /dev/null +++ b/tools/pioasm/test/errors/pio_version/test_pio_version_feature_errors.pio @@ -0,0 +1,26 @@ +// run: pioasm -v 0 input.pio +.program pio_v0_jmppin_error +.pio_version 0 + wait 0 jmppin + +.program pio_v0_irq_next_error +.pio_version 0 + irq next 0 + +.program pio_v0_fifo_error +.pio_version 0 +.fifo tx + pull + +// -- Output +// Command: pioasm -v 0 input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:4.12-17: PIO version 1 is required for 'wait jmppin' +// 4 | wait 0 jmppin +// | ^~~~~~ +// input.pio:8.5-14: PIO version 1 is required for 'irq next' +// 8 | irq next 0 +// | ^~~~~~~~~~ +// diff --git a/tools/pioasm/test/errors/pio_version/test_pio_version_invalid_errors.pio b/tools/pioasm/test/errors/pio_version/test_pio_version_invalid_errors.pio new file mode 100644 index 000000000..7b6dff447 --- /dev/null +++ b/tools/pioasm/test/errors/pio_version/test_pio_version_invalid_errors.pio @@ -0,0 +1,14 @@ +// run: pioasm input.pio +.program pio_version_invalid +.pio_version 2 + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 1 +// Stdout: +// Stderr: +// input.pio:3.1-14: only PIO versions 0 (rp2040) and 1 (rp2350) are supported +// 3 | .pio_version 2 +// | ^~~~~~~~~~~~~~ +// diff --git a/tools/pioasm/test/pioasm_core_coverage_test.cc b/tools/pioasm/test/pioasm_core_coverage_test.cc new file mode 100644 index 000000000..5a6b12605 --- /dev/null +++ b/tools/pioasm/test/pioasm_core_coverage_test.cc @@ -0,0 +1,209 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "pio_assembler.h" +#include "output_format.h" + +namespace { + +struct ScopedRedirect { + int stdout_fd = -1; + int stderr_fd = -1; + FILE *null_out = nullptr; + FILE *null_err = nullptr; + + ScopedRedirect() { + stdout_fd = dup(STDOUT_FILENO); + stderr_fd = dup(STDERR_FILENO); + null_out = freopen("/dev/null", "w", stdout); + null_err = freopen("/dev/null", "w", stderr); + } + + ~ScopedRedirect() { + fflush(stdout); + fflush(stderr); + if (stdout_fd >= 0) { + dup2(stdout_fd, STDOUT_FILENO); + close(stdout_fd); + } + if (stderr_fd >= 0) { + dup2(stderr_fd, STDERR_FILENO); + close(stderr_fd); + } + if (null_out) { + fclose(null_out); + } + if (null_err) { + fclose(null_err); + } + } +}; + +std::string test_root() { + const char *srcdir = std::getenv("TEST_SRCDIR"); + const char *workspace = std::getenv("TEST_WORKSPACE"); + if (srcdir && workspace) { + std::filesystem::path root = std::filesystem::path(srcdir) / workspace / "tools" / "pioasm" / "test"; + return root.string(); + } + return (std::filesystem::current_path() / "test").string(); +} + +std::vector read_commands(const std::filesystem::path &path) { + std::ifstream file(path); + std::vector commands; + std::string line; + + while (std::getline(file, line)) { + const std::string prefix = "// run: "; + if (line.rfind(prefix, 0) == 0) { + commands.push_back(line.substr(prefix.size())); + } else { + break; + } + } + + return commands; +} + +struct CommandOptions { + int default_pio_version = 0; + std::string format = output_format::default_name; + std::vector output_options; +}; + +CommandOptions parse_command(const std::string &command) { + CommandOptions options; + std::istringstream input(command); + std::string token; + std::vector tokens; + + while (input >> token) { + tokens.push_back(token); + } + + for (size_t i = 0; i < tokens.size(); ++i) { + if (tokens[i] == "pioasm") { + continue; + } + if (tokens[i] == "-v" && i + 1 < tokens.size()) { + options.default_pio_version = std::stoi(tokens[++i]); + continue; + } + if (tokens[i] == "-o" && i + 1 < tokens.size()) { + options.format = tokens[++i]; + continue; + } + if (tokens[i] == "-p" && i + 1 < tokens.size()) { + options.output_options.push_back(tokens[++i]); + continue; + } + } + + return options; +} + +std::shared_ptr find_format(const std::string &name) { + const auto &formats = output_format::all(); + auto it = std::find_if(formats.begin(), formats.end(), [&](const auto &format) { + return format->name == name; + }); + if (it == formats.end()) { + return nullptr; + } + return *it; +} + +bool run_command(const std::filesystem::path &source, const CommandOptions &options, bool expect_failure) { + auto format = find_format(options.format); + if (!format) { + return expect_failure; + } + + pio_assembler assembler; + assembler.default_pio_version = options.default_pio_version; + + ScopedRedirect redirect; + + int result = 1; + try { + result = assembler.generate(format, source.string(), "-", options.output_options); + } catch (const std::exception &) { + result = 1; + } + + bool success = (result == 0 && assembler.error_count == 0); + return expect_failure ? !success : success; +} + +bool should_expect_failure(const std::filesystem::path &path) { + std::string path_str = path.generic_string(); + return path_str.find("/errors/") != std::string::npos; +} + +} // namespace + +int main() { + const char *outputs_dir = std::getenv("TEST_UNDECLARED_OUTPUTS_DIR"); + if (outputs_dir) { + if (!std::getenv("LLVM_PROFILE_FILE")) { + std::string profile_path = std::string(outputs_dir) + "/pioasm-%p.profraw"; + setenv("LLVM_PROFILE_FILE", profile_path.c_str(), 1); + } + if (!std::getenv("GCOV_PREFIX")) { + setenv("GCOV_PREFIX", outputs_dir, 1); + } + if (!std::getenv("GCOV_PREFIX_STRIP")) { + setenv("GCOV_PREFIX_STRIP", "0", 1); + } + } + + std::filesystem::path root = test_root(); + if (!std::filesystem::exists(root)) { + std::cerr << "Test root not found: " << root << "\n"; + return 1; + } + + std::vector tests; + for (const auto &entry : std::filesystem::recursive_directory_iterator(root)) { + if (!entry.is_regular_file()) { + continue; + } + const auto &path = entry.path(); + if (path.extension() == ".pio" && path.filename().string().rfind("test_", 0) == 0) { + tests.push_back(path); + } + } + + std::sort(tests.begin(), tests.end()); + + int failures = 0; + for (const auto &test : tests) { + auto commands = read_commands(test); + bool expect_failure = should_expect_failure(test); + for (const auto &command : commands) { + auto options = parse_command(command); + bool ok = run_command(test, options, expect_failure); + if (!ok) { + std::cerr << "Coverage test failed: " << test << " with command: " << command << "\n"; + failures++; + } + } + } + + if (failures > 0) { + std::cerr << failures << " coverage test command(s) failed\n"; + return 1; + } + + return 0; +} diff --git a/tools/pioasm/test/run_tests.py b/tools/pioasm/test/run_tests.py new file mode 100755 index 000000000..5162615b0 --- /dev/null +++ b/tools/pioasm/test/run_tests.py @@ -0,0 +1,235 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2026 Raspberry Pi (Trading) Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Test harness for pioasm validation and coverage tests. +# +# Usage: +# test/run_tests.py + +import os, sys, subprocess, tempfile, shutil, re, unittest +from typing import Optional +from pathlib import Path + +TEST_DIR = Path(__file__).resolve().parent +OVERWRITE = False +PIOASM_BIN = None + +def discover_tests() -> list[Path]: + tests = [] + for root, _dirs, files in os.walk(TEST_DIR): + for file in files: + if file.startswith("test_") and file.endswith(".pio"): + tests.append(Path(root) / file) + return tests + +def run_test(test: Path, overwrite: bool = False) -> bool: + with open(test, "r") as test_file: + line = test_file.readline() + lines = [line] + output_lines = [] + commands = [] + + while line.startswith("// run: "): + commands.append(line.strip()[8:]) + line = test_file.readline() + lines.append(line) + + marker_found = False + while not line == "" and not line.strip() == "// -- Output": + if "// -- Output" in line: + prefix, _ = line.split("// -- Output", 1) + if prefix == "": + lines[-1] = "// -- Output\n" + else: + lines[-1] = prefix if prefix.endswith("\n") else prefix + "\n" + lines.append("// -- Output\n") + marker_found = True + break + + line = test_file.readline() + lines.append(line) + + if line == "" and not marker_found: + if overwrite: + if lines and lines[-1] == "": + lines.pop() + if lines and not lines[-1].endswith("\n"): + lines[-1] += "\n" + lines.append("// -- Output\n") + else: + return False + else: + if not marker_found and (not lines or lines[-1].strip() != "// -- Output"): + lines.append(line) + line = test_file.readline() + + while line != "": + output_lines.append(line) + line = test_file.readline() + + commands_output = [] + + for command in commands: + (code, out, err) = execute_command(test, command) + + commands_output.append(f"// Command: {command}") + commands_output.append(f"// Exit code: {code}") + commands_output.extend(format_stream_output("Stdout:", out)) + commands_output.extend(format_stream_output("Stderr:", err)) + + expected_output = [] + for output_line in output_lines: + expected_output.append(strip_trailing_newline(output_line)) + + if overwrite: + # Rewrite the test file with new output, preserving wildcard lines. + merged_output = list(commands_output) + for index, expected_line in enumerate(expected_output): + if index >= len(merged_output): + break + if expected_line.startswith("//?"): + merged_output[index] = expected_line + with open(test, "w") as test_file: + for line in lines: + test_file.write(line) + for output_line in merged_output: + test_file.write(output_line + "\n") + else: + # Compare output + if not outputs_match(expected_output, commands_output): + print("Test failed!") + #print a diff instead + #an actual diff that is not broken if there is a new / removed line. maybe use a lib + import difflib + diff = difflib.unified_diff(expected_output, commands_output, fromfile='expected', tofile='actual', lineterm='') + print('\n'.join(diff)) + + return False + + return True + +def outputs_match(expected: list[str], actual: list[str]) -> bool: + if len(expected) != len(actual): + return False + for expected_line, actual_line in zip(expected, actual): + if expected_line.startswith("//?"): + continue + if expected_line != actual_line: + return False + return True + +def strip_trailing_newline(line: str) -> str: + if line.endswith("\n"): + return line[:-1] + return line + +def format_stream_output(label: str, output: str) -> list[str]: + lines = [f"// {label}"] + if output == "": + return lines + + for line in output.splitlines(): + lines.append(f"// {line}") + + if output.endswith("\n"): + lines.append("// ") + + return lines + +def execute_command(test_file, command) -> tuple[int, str, str]: + tempdir = tempfile.mkdtemp() + + shutil.copy(test_file, Path(tempdir) / "input.pio") + + env = os.environ.copy() + coverage_dir = env.get("COVERAGE_DIR") or env.get("TEST_UNDECLARED_OUTPUTS_DIR") + if coverage_dir: + env.setdefault("GCOV_PREFIX", coverage_dir) + env.setdefault("GCOV_PREFIX_STRIP", "0") + env.setdefault("LLVM_PROFILE_FILE", str(Path(coverage_dir) / "pioasm-%p.profraw")) + if PIOASM_BIN: + pioasm_dir = str(Path(PIOASM_BIN).parent) + env["PATH"] = f"{pioasm_dir}{os.pathsep}{env.get('PATH', '')}" + result = subprocess.run(command, cwd=tempdir, env=env, capture_output=True, shell=True) + + return (result.returncode, result.stdout.decode(), result.stderr.decode()) + +class PioasmTests(unittest.TestCase): + pass + +def _make_test(test_path: Path): + def _test(self): + ok = run_test(test_path, OVERWRITE) + self.assertTrue(ok, f"Test failed: {test_path}") + return _test + +def _register_tests(): + tests = discover_tests() + for index, test_path in enumerate(tests): + rel_path = test_path.relative_to(TEST_DIR) + safe_name = re.sub(r"[^0-9A-Za-z_]+", "_", str(rel_path)) + test_name = f"test_{safe_name}_{index}" + setattr(PioasmTests, test_name, _make_test(test_path)) + +_register_tests() + +def resolve_pioasm_bin() -> Optional[str]: + env_bin = os.environ.get("PIOASM_BIN") + if env_bin: + env_path = Path(env_bin) + if env_path.is_absolute(): + return str(env_path) + runfiles_dir = os.environ.get("RUNFILES_DIR") + if runfiles_dir: + candidate = Path(runfiles_dir) / env_path + if candidate.exists(): + return str(candidate) + candidate = Path(runfiles_dir) / "_main" / env_path + if candidate.exists(): + return str(candidate) + manifest = os.environ.get("RUNFILES_MANIFEST_FILE") + if manifest: + with open(manifest, "r") as manifest_file: + for line in manifest_file: + if line.startswith(f"{env_path} "): + return line.split(" ", 1)[1].strip() + if line.startswith(f"_main/{env_path} "): + return line.split(" ", 1)[1].strip() + for parent in Path(__file__).resolve().parents: + if parent.name == "_main": + candidate = parent.parent / env_path + if candidate.exists(): + return str(candidate) + candidate = parent / env_path + if candidate.exists(): + return str(candidate) + break + for parent in Path(__file__).resolve().parents: + if parent.name == "execroot": + candidate = parent / env_path + if candidate.exists(): + return str(candidate) + break + repo_root = Path(__file__).resolve().parents[3] + candidate = repo_root / env_path + if candidate.exists(): + return str(candidate) + return env_bin + + repo_root = Path(__file__).resolve().parents[3] + candidate = repo_root / "bazel-bin" / "tools" / "pioasm" / "pioasm" + if candidate.exists(): + return str(candidate) + + return None + +PIOASM_BIN = resolve_pioasm_bin() + +if __name__ == "__main__": + if "--overwrite" in sys.argv: + OVERWRITE = True + sys.argv.remove("--overwrite") + unittest.main(verbosity=2) diff --git a/tools/pioasm/test/run_tests_wrapper.py b/tools/pioasm/test/run_tests_wrapper.py new file mode 100644 index 000000000..d27876fe2 --- /dev/null +++ b/tools/pioasm/test/run_tests_wrapper.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python3 +# +# Copyright (c) 2024 Raspberry Pi (Trading) Ltd. +# +# SPDX-License-Identifier: BSD-3-Clause +# +# Wrapper to locate runfiles and invoke run_tests.py under Bazel. + +from __future__ import annotations + +import os +from pathlib import Path +import subprocess +import sys + + +RUN_TESTS_RUNFILE = "_main/tools/pioasm/test/run_tests.py" +PIOASM_RUNFILE = "_main/tools/pioasm/pioasm" + + +def _resolve_runfile(path: str) -> Path | None: + runfiles_dir = os.environ.get("RUNFILES_DIR") + if runfiles_dir: + candidate = Path(runfiles_dir) / path + if candidate.exists(): + return candidate + + manifest = os.environ.get("RUNFILES_MANIFEST_FILE") + if manifest: + prefix = f"{path} " + with open(manifest, "r", encoding="utf-8") as handle: + for line in handle: + if line.startswith(prefix): + return Path(line[len(prefix):].strip()) + + return None + + +def main() -> int: + script_dir = Path(__file__).resolve().parent + test_script = _resolve_runfile(RUN_TESTS_RUNFILE) or (script_dir / "run_tests.py") + pioasm_path = _resolve_runfile(PIOASM_RUNFILE) + + if not test_script.exists(): + print(f"run_tests.py not found at {test_script}", file=sys.stderr) + return 1 + + env = os.environ.copy() + if pioasm_path: + env["PIOASM_BIN"] = str(pioasm_path) + + python_bin = env.get("PYTHON_BIN", sys.executable) + cmd = [python_bin, str(test_script), *sys.argv[1:]] + return subprocess.run(cmd, env=env).returncode + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/tools/pioasm/test/valid/basic/test_all_directives_valid.pio b/tools/pioasm/test/valid/basic/test_all_directives_valid.pio new file mode 100644 index 000000000..2fe48c1c3 --- /dev/null +++ b/tools/pioasm/test/valid/basic/test_all_directives_valid.pio @@ -0,0 +1,90 @@ +// run: pioasm -v 1 input.pio +.program directives_test +.pio_version 1 +.clock_div 2.5 +.side_set 2 opt +.origin 3 +.define PUBLIC myconst 42 +.mov_status txfifo < 4 +.fifo txrx +.out 4 +.in 3 +.set 5 +.wrap_target + nop side 1 + pull + out pins, 4 + in pins, 3 + set pins, 5 + .word 0xa042 +.wrap + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // --------------- // +// // directives_test // +// // --------------- // +// +// #define directives_test_wrap_target 0 +// #define directives_test_wrap 5 +// #define directives_test_pio_version 1 +// +// #define directives_test_myconst 42 +// +// static __pio_const uint16_t directives_test_program_instructions[] = { +// // .wrap_target +// 0xb442, // 0: nop side 1 +// 0x80a0, // 1: pull block +// 0x6004, // 2: out pins, 4 +// 0x4003, // 3: in pins, 3 +// 0xe005, // 4: set pins, 5 +// 0xa042, // 5: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program directives_test_program = { +// .instructions = directives_test_program_instructions, +// .length = 6, +// .origin = 3, +// .pio_version = directives_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config directives_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + directives_test_wrap_target, offset + directives_test_wrap); +// sm_config_set_in_pin_count(&c, 3); +// sm_config_set_in_shift(&c, 1, 0, 32); +// sm_config_set_out_pin_count(&c, 4); +// sm_config_set_out_shift(&c, 1, 0, 32); +// sm_config_set_set_pin_count(&c, 5); +// sm_config_set_sideset(&c, 3, true, false); +// sm_config_set_mov_status(&c, STATUS_TX_LESSTHAN, 4); +// sm_config_set_clkdiv_int_frac(&c, 2, 128); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/basic/test_all_instructions_valid.pio b/tools/pioasm/test/valid/basic/test_all_instructions_valid.pio new file mode 100644 index 000000000..7e168a07b --- /dev/null +++ b/tools/pioasm/test/valid/basic/test_all_instructions_valid.pio @@ -0,0 +1,27 @@ +// run: pioasm -o hex input.pio +.program all_basic + wait 0 gpio 0 ; WAIT instruction + in pins, 8 ; IN instruction + out pins, 8 ; OUT instruction + push ; PUSH instruction + pull ; PULL instruction + mov x, y ; MOV instruction + irq 0 ; IRQ instruction + set pins, 0 ; SET instruction + jmp 0 ; JMP instruction (back to start) + +// -- Output +// Command: pioasm -o hex input.pio +// Exit code: 0 +// Stdout: +// 2000 +// 4008 +// 6008 +// 8020 +// 80a0 +// a022 +// c000 +// e000 +// 0000 +// +// Stderr: diff --git a/tools/pioasm/test/valid/basic/test_minimal_program_valid.pio b/tools/pioasm/test/valid/basic/test_minimal_program_valid.pio new file mode 100644 index 000000000..16a5404e2 --- /dev/null +++ b/tools/pioasm/test/valid/basic/test_minimal_program_valid.pio @@ -0,0 +1,58 @@ +// run: pioasm input.pio +.program minimal + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------- // +// // minimal // +// // ------- // +// +// #define minimal_wrap_target 0 +// #define minimal_wrap 0 +// #define minimal_pio_version 0 +// +// static __pio_const uint16_t minimal_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program minimal_program = { +// .instructions = minimal_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = minimal_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config minimal_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + minimal_wrap_target, offset + minimal_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_all_config_directives_valid.pio b/tools/pioasm/test/valid/comprehensive/test_all_config_directives_valid.pio new file mode 100644 index 000000000..502d523ae --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_all_config_directives_valid.pio @@ -0,0 +1,91 @@ +// run: pioasm -v 1 input.pio +// Test program combining ALL configuration directives at once +.program everything_kitchen_sink +.pio_version 1 +.clock_div 4.25 +.side_set 2 opt pindirs +.origin 10 +.define PUBLIC test_constant 42 +.mov_status txfifo < 16 +.fifo txrx +.out 8 right auto 28 +.in 12 right auto 20 +.set 3 +.wrap_target + set pins, 3 side 2 [3] + out pins, 8 side 1 [2] + in pins, 12 [3] + mov x, status side 3 + push block + pull block side 0 [1] +.wrap + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------------------- // +// // everything_kitchen_sink // +// // ----------------------- // +// +// #define everything_kitchen_sink_wrap_target 0 +// #define everything_kitchen_sink_wrap 5 +// #define everything_kitchen_sink_pio_version 1 +// +// #define everything_kitchen_sink_test_constant 42 +// +// static __pio_const uint16_t everything_kitchen_sink_program_instructions[] = { +// // .wrap_target +// 0xfb03, // 0: set pins, 3 side 2 [3] +// 0x7608, // 1: out pins, 8 side 1 [2] +// 0x430c, // 2: in pins, 12 [3] +// 0xbc25, // 3: mov x, status side 3 +// 0x8020, // 4: push block +// 0x91a0, // 5: pull block side 0 [1] +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program everything_kitchen_sink_program = { +// .instructions = everything_kitchen_sink_program_instructions, +// .length = 6, +// .origin = 10, +// .pio_version = everything_kitchen_sink_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config everything_kitchen_sink_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + everything_kitchen_sink_wrap_target, offset + everything_kitchen_sink_wrap); +// sm_config_set_in_pin_count(&c, 12); +// sm_config_set_in_shift(&c, 1, 1, 20); +// sm_config_set_out_pin_count(&c, 8); +// sm_config_set_out_shift(&c, 1, 1, 28); +// sm_config_set_set_pin_count(&c, 3); +// sm_config_set_sideset(&c, 3, true, true); +// sm_config_set_mov_status(&c, STATUS_TX_LESSTHAN, 16); +// sm_config_set_clkdiv_int_frac(&c, 4, 64); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_in_all_sources_valid.pio b/tools/pioasm/test/valid/comprehensive/test_in_all_sources_valid.pio new file mode 100644 index 000000000..7f9271d8b --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_in_all_sources_valid.pio @@ -0,0 +1,70 @@ +// run: pioasm input.pio +.program in_sources + in pins, 4 + in x, 8 + in y, 16 + in null, 32 + in isr, 1 + in osr, 24 + in status, 5 + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------- // +// // in_sources // +// // ---------- // +// +// #define in_sources_wrap_target 0 +// #define in_sources_wrap 6 +// #define in_sources_pio_version 0 +// +// static __pio_const uint16_t in_sources_program_instructions[] = { +// // .wrap_target +// 0x4004, // 0: in pins, 4 +// 0x4028, // 1: in x, 8 +// 0x4050, // 2: in y, 16 +// 0x4060, // 3: in null, 32 +// 0x40c1, // 4: in isr, 1 +// 0x40f8, // 5: in osr, 24 +// 0x40a5, // 6: in status, 5 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program in_sources_program = { +// .instructions = in_sources_program_instructions, +// .length = 7, +// .origin = -1, +// .pio_version = in_sources_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config in_sources_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + in_sources_wrap_target, offset + in_sources_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_irq_all_variants_valid.pio b/tools/pioasm/test/valid/comprehensive/test_irq_all_variants_valid.pio new file mode 100644 index 000000000..9cb0f6a56 --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_irq_all_variants_valid.pio @@ -0,0 +1,72 @@ +// run: pioasm -v 1 input.pio +.program irq_test + irq 0 ; set IRQ 0 + irq 7 ; set IRQ 7 + irq clear 3 ; clear IRQ 3 + irq wait 2 ; set and wait IRQ 2 + irq 1 rel ; relative IRQ + irq next 0 ; next state machine (PIO v1) + irq prev 0 ; previous state machine (PIO v1) + irq next clear 1 ; combined (PIO v1) + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // -------- // +// // irq_test // +// // -------- // +// +// #define irq_test_wrap_target 0 +// #define irq_test_wrap 7 +// #define irq_test_pio_version 1 +// +// static __pio_const uint16_t irq_test_program_instructions[] = { +// // .wrap_target +// 0xc000, // 0: irq nowait 0 +// 0xc007, // 1: irq nowait 7 +// 0xc043, // 2: irq clear 3 +// 0xc022, // 3: irq wait 2 +// 0xc011, // 4: irq nowait 1 rel +// 0xc018, // 5: irq next nowait 0 +// 0xc008, // 6: irq prev nowait 0 +// 0xc059, // 7: irq next clear 1 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program irq_test_program = { +// .instructions = irq_test_program_instructions, +// .length = 8, +// .origin = -1, +// .pio_version = irq_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config irq_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + irq_test_wrap_target, offset + irq_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_jmp_all_conditions_valid.pio b/tools/pioasm/test/valid/comprehensive/test_jmp_all_conditions_valid.pio new file mode 100644 index 000000000..27d8d3d10 --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_jmp_all_conditions_valid.pio @@ -0,0 +1,73 @@ +// run: pioasm input.pio +.program jmp_test +start: + jmp start ; unconditional + jmp !x, start ; if X zero + jmp x--, start ; if X non-zero, post-decrement + jmp !y, start ; if Y zero + jmp y--, start ; if Y non-zero, post-decrement + jmp x!=y, start ; if X != Y + jmp pin, start ; if pin + jmp ! osre, start ; if OSR not empty + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // -------- // +// // jmp_test // +// // -------- // +// +// #define jmp_test_wrap_target 0 +// #define jmp_test_wrap 7 +// #define jmp_test_pio_version 0 +// +// static __pio_const uint16_t jmp_test_program_instructions[] = { +// // .wrap_target +// 0x0000, // 0: jmp 0 +// 0x0020, // 1: jmp !x, 0 +// 0x0040, // 2: jmp x--, 0 +// 0x0060, // 3: jmp !y, 0 +// 0x0080, // 4: jmp y--, 0 +// 0x00a0, // 5: jmp x != y, 0 +// 0x00c0, // 6: jmp pin, 0 +// 0x00e0, // 7: jmp !osre, 0 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program jmp_test_program = { +// .instructions = jmp_test_program_instructions, +// .length = 8, +// .origin = -1, +// .pio_version = jmp_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config jmp_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + jmp_test_wrap_target, offset + jmp_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_mov_all_combinations_valid.pio b/tools/pioasm/test/valid/comprehensive/test_mov_all_combinations_valid.pio new file mode 100644 index 000000000..4c98af6d7 --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_mov_all_combinations_valid.pio @@ -0,0 +1,79 @@ +// run: pioasm -v 1 input.pio +.program mov_combo +.pio_version 1 + mov x, y + mov y, x + mov isr, osr + mov osr, isr + mov pins, x + mov x, pins + mov pindirs, x + mov pc, x + mov exec, y + mov x, null + mov y, status + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // --------- // +// // mov_combo // +// // --------- // +// +// #define mov_combo_wrap_target 0 +// #define mov_combo_wrap 10 +// #define mov_combo_pio_version 1 +// +// static __pio_const uint16_t mov_combo_program_instructions[] = { +// // .wrap_target +// 0xa022, // 0: mov x, y +// 0xa041, // 1: mov y, x +// 0xa0c7, // 2: mov isr, osr +// 0xa0e6, // 3: mov osr, isr +// 0xa001, // 4: mov pins, x +// 0xa020, // 5: mov x, pins +// 0xa061, // 6: mov pindirs, x +// 0xa0a1, // 7: mov pc, x +// 0xa082, // 8: mov exec, y +// 0xa023, // 9: mov x, null +// 0xa045, // 10: mov y, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_combo_program = { +// .instructions = mov_combo_program_instructions, +// .length = 11, +// .origin = -1, +// .pio_version = mov_combo_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_combo_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_combo_wrap_target, offset + mov_combo_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_mov_all_operations_valid.pio b/tools/pioasm/test/valid/comprehensive/test_mov_all_operations_valid.pio new file mode 100644 index 000000000..79b2f7c8c --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_mov_all_operations_valid.pio @@ -0,0 +1,74 @@ +// run: pioasm -v 1 input.pio +.program mov_test + mov x, y + mov x, !y ; bitwise NOT + mov x, :: y ; bit reverse + mov pins, x + mov x, pins + mov y, status ; read status + mov osr, isr + mov isr, osr + mov pc, x ; computed jump + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // -------- // +// // mov_test // +// // -------- // +// +// #define mov_test_wrap_target 0 +// #define mov_test_wrap 8 +// #define mov_test_pio_version 1 +// +// static __pio_const uint16_t mov_test_program_instructions[] = { +// // .wrap_target +// 0xa022, // 0: mov x, y +// 0xa02a, // 1: mov x, ~y +// 0xa032, // 2: mov x, ::y +// 0xa001, // 3: mov pins, x +// 0xa020, // 4: mov x, pins +// 0xa045, // 5: mov y, status +// 0xa0e6, // 6: mov osr, isr +// 0xa0c7, // 7: mov isr, osr +// 0xa0a1, // 8: mov pc, x +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_test_program = { +// .instructions = mov_test_program_instructions, +// .length = 9, +// .origin = -1, +// .pio_version = mov_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_test_wrap_target, offset + mov_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_out_all_destinations_valid.pio b/tools/pioasm/test/valid/comprehensive/test_out_all_destinations_valid.pio new file mode 100644 index 000000000..393a3f55a --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_out_all_destinations_valid.pio @@ -0,0 +1,72 @@ +// run: pioasm input.pio +.program out_targets + out pins, 4 + out x, 8 + out y, 16 + out null, 32 + out pindirs, 5 + out isr, 7 + out pc, 5 + out exec, 16 + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------- // +// // out_targets // +// // ----------- // +// +// #define out_targets_wrap_target 0 +// #define out_targets_wrap 7 +// #define out_targets_pio_version 0 +// +// static __pio_const uint16_t out_targets_program_instructions[] = { +// // .wrap_target +// 0x6004, // 0: out pins, 4 +// 0x6028, // 1: out x, 8 +// 0x6050, // 2: out y, 16 +// 0x6060, // 3: out null, 32 +// 0x6085, // 4: out pindirs, 5 +// 0x60c7, // 5: out isr, 7 +// 0x60a5, // 6: out pc, 5 +// 0x60f0, // 7: out exec, 16 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program out_targets_program = { +// .instructions = out_targets_program_instructions, +// .length = 8, +// .origin = -1, +// .pio_version = out_targets_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config out_targets_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + out_targets_wrap_target, offset + out_targets_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_push_pull_all_modes_valid.pio b/tools/pioasm/test/valid/comprehensive/test_push_pull_all_modes_valid.pio new file mode 100644 index 000000000..18495e9a1 --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_push_pull_all_modes_valid.pio @@ -0,0 +1,76 @@ +// run: pioasm input.pio +.program push_pull_test + push + push block + push noblock + push iffull + push iffull block + pull + pull block + pull noblock + pull ifempty + pull ifempty noblock + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // -------------- // +// // push_pull_test // +// // -------------- // +// +// #define push_pull_test_wrap_target 0 +// #define push_pull_test_wrap 9 +// #define push_pull_test_pio_version 0 +// +// static __pio_const uint16_t push_pull_test_program_instructions[] = { +// // .wrap_target +// 0x8020, // 0: push block +// 0x8020, // 1: push block +// 0x8000, // 2: push noblock +// 0x8060, // 3: push iffull block +// 0x8060, // 4: push iffull block +// 0x80a0, // 5: pull block +// 0x80a0, // 6: pull block +// 0x8080, // 7: pull noblock +// 0x80e0, // 8: pull ifempty block +// 0x80c0, // 9: pull ifempty noblock +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program push_pull_test_program = { +// .instructions = push_pull_test_program_instructions, +// .length = 10, +// .origin = -1, +// .pio_version = push_pull_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config push_pull_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + push_pull_test_wrap_target, offset + push_pull_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_set_all_destinations_valid.pio b/tools/pioasm/test/valid/comprehensive/test_set_all_destinations_valid.pio new file mode 100644 index 000000000..f39d04255 --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_set_all_destinations_valid.pio @@ -0,0 +1,64 @@ +// run: pioasm input.pio +.program set_targets + set pins, 0 + set x, 1 + set y, 2 + set pindirs, 3 + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------- // +// // set_targets // +// // ----------- // +// +// #define set_targets_wrap_target 0 +// #define set_targets_wrap 3 +// #define set_targets_pio_version 0 +// +// static __pio_const uint16_t set_targets_program_instructions[] = { +// // .wrap_target +// 0xe000, // 0: set pins, 0 +// 0xe021, // 1: set x, 1 +// 0xe042, // 2: set y, 2 +// 0xe083, // 3: set pindirs, 3 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program set_targets_program = { +// .instructions = set_targets_program_instructions, +// .length = 4, +// .origin = -1, +// .pio_version = set_targets_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config set_targets_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + set_targets_wrap_target, offset + set_targets_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/comprehensive/test_wait_all_sources_valid.pio b/tools/pioasm/test/valid/comprehensive/test_wait_all_sources_valid.pio new file mode 100644 index 000000000..8c3865547 --- /dev/null +++ b/tools/pioasm/test/valid/comprehensive/test_wait_all_sources_valid.pio @@ -0,0 +1,72 @@ +// run: pioasm -v 1 input.pio +.program wait_test + wait 0 gpio 5 ; wait GPIO low + wait 1 gpio 10 ; wait GPIO high + wait 0 pin 2 ; wait pin low + wait 1 pin 3 ; wait pin high + wait 0 irq 4 ; wait IRQ clear + wait 1 irq 7 rel ; wait IRQ set, relative + wait 0 jmppin ; wait jmppin low (PIO v1) + wait 1 jmppin + 2 ; wait jmppin offset (PIO v1) + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // --------- // +// // wait_test // +// // --------- // +// +// #define wait_test_wrap_target 0 +// #define wait_test_wrap 7 +// #define wait_test_pio_version 1 +// +// static __pio_const uint16_t wait_test_program_instructions[] = { +// // .wrap_target +// 0x2005, // 0: wait 0 gpio, 5 +// 0x208a, // 1: wait 1 gpio, 10 +// 0x2022, // 2: wait 0 pin, 2 +// 0x20a3, // 3: wait 1 pin, 3 +// 0x2044, // 4: wait 0 irq, 4 +// 0x20d7, // 5: wait 1 irq, 7 rel +// 0x2060, // 6: wait 0 jmppin +// 0x20e2, // 7: wait 1 jmppin + 2 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wait_test_program = { +// .instructions = wait_test_program_instructions, +// .length = 8, +// .origin = -1, +// .pio_version = wait_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x1 +// #endif +// }; +// +// static inline pio_sm_config wait_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wait_test_wrap_target, offset + wait_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_clock_div_configurations_valid.pio b/tools/pioasm/test/valid/config/test_clock_div_configurations_valid.pio new file mode 100644 index 000000000..c2befd884 --- /dev/null +++ b/tools/pioasm/test/valid/config/test_clock_div_configurations_valid.pio @@ -0,0 +1,244 @@ +// run: pioasm input.pio +.program clock_div_integer +.clock_div 1 + nop + +.program clock_div_fractional +.clock_div 2.5 + nop + +.program clock_div_small_fraction +.clock_div 1.125 + nop + +.program clock_div_large_fraction +.clock_div 123.75 + nop + +.program clock_div_max_integer +.clock_div 65535 + nop + +.program clock_div_complex +.clock_div 3.14159 + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------------- // +// // clock_div_integer // +// // ----------------- // +// +// #define clock_div_integer_wrap_target 0 +// #define clock_div_integer_wrap 0 +// #define clock_div_integer_pio_version 0 +// +// static __pio_const uint16_t clock_div_integer_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program clock_div_integer_program = { +// .instructions = clock_div_integer_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = clock_div_integer_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config clock_div_integer_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + clock_div_integer_wrap_target, offset + clock_div_integer_wrap); +// return c; +// } +// #endif +// +// // -------------------- // +// // clock_div_fractional // +// // -------------------- // +// +// #define clock_div_fractional_wrap_target 0 +// #define clock_div_fractional_wrap 0 +// #define clock_div_fractional_pio_version 0 +// +// static __pio_const uint16_t clock_div_fractional_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program clock_div_fractional_program = { +// .instructions = clock_div_fractional_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = clock_div_fractional_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config clock_div_fractional_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + clock_div_fractional_wrap_target, offset + clock_div_fractional_wrap); +// sm_config_set_clkdiv_int_frac(&c, 2, 128); +// return c; +// } +// #endif +// +// // ------------------------ // +// // clock_div_small_fraction // +// // ------------------------ // +// +// #define clock_div_small_fraction_wrap_target 0 +// #define clock_div_small_fraction_wrap 0 +// #define clock_div_small_fraction_pio_version 0 +// +// static __pio_const uint16_t clock_div_small_fraction_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program clock_div_small_fraction_program = { +// .instructions = clock_div_small_fraction_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = clock_div_small_fraction_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config clock_div_small_fraction_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + clock_div_small_fraction_wrap_target, offset + clock_div_small_fraction_wrap); +// sm_config_set_clkdiv_int_frac(&c, 1, 32); +// return c; +// } +// #endif +// +// // ------------------------ // +// // clock_div_large_fraction // +// // ------------------------ // +// +// #define clock_div_large_fraction_wrap_target 0 +// #define clock_div_large_fraction_wrap 0 +// #define clock_div_large_fraction_pio_version 0 +// +// static __pio_const uint16_t clock_div_large_fraction_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program clock_div_large_fraction_program = { +// .instructions = clock_div_large_fraction_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = clock_div_large_fraction_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config clock_div_large_fraction_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + clock_div_large_fraction_wrap_target, offset + clock_div_large_fraction_wrap); +// sm_config_set_clkdiv_int_frac(&c, 123, 192); +// return c; +// } +// #endif +// +// // --------------------- // +// // clock_div_max_integer // +// // --------------------- // +// +// #define clock_div_max_integer_wrap_target 0 +// #define clock_div_max_integer_wrap 0 +// #define clock_div_max_integer_pio_version 0 +// +// static __pio_const uint16_t clock_div_max_integer_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program clock_div_max_integer_program = { +// .instructions = clock_div_max_integer_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = clock_div_max_integer_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config clock_div_max_integer_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + clock_div_max_integer_wrap_target, offset + clock_div_max_integer_wrap); +// sm_config_set_clkdiv_int_frac(&c, 65535, 0); +// return c; +// } +// #endif +// +// // ----------------- // +// // clock_div_complex // +// // ----------------- // +// +// #define clock_div_complex_wrap_target 0 +// #define clock_div_complex_wrap 0 +// #define clock_div_complex_pio_version 0 +// +// static __pio_const uint16_t clock_div_complex_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program clock_div_complex_program = { +// .instructions = clock_div_complex_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = clock_div_complex_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config clock_div_complex_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + clock_div_complex_wrap_target, offset + clock_div_complex_wrap); +// sm_config_set_clkdiv_int_frac(&c, 3, 36); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_delay_all_values_valid.pio b/tools/pioasm/test/valid/config/test_delay_all_values_valid.pio new file mode 100644 index 000000000..bcb23edfd --- /dev/null +++ b/tools/pioasm/test/valid/config/test_delay_all_values_valid.pio @@ -0,0 +1,120 @@ +// run: pioasm input.pio +.program delay_all + nop [0] + nop [1] + nop [2] + nop [3] + nop [4] + nop [5] + nop [6] + nop [7] + nop [8] + nop [9] + nop [10] + nop [11] + nop [12] + nop [13] + nop [14] + nop [15] + nop [16] + nop [17] + nop [18] + nop [19] + nop [20] + nop [21] + nop [22] + nop [23] + nop [24] + nop [25] + nop [26] + nop [27] + nop [28] + nop [29] + nop [30] + nop [31] + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // --------- // +// // delay_all // +// // --------- // +// +// #define delay_all_wrap_target 0 +// #define delay_all_wrap 31 +// #define delay_all_pio_version 0 +// +// static __pio_const uint16_t delay_all_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa142, // 1: nop [1] +// 0xa242, // 2: nop [2] +// 0xa342, // 3: nop [3] +// 0xa442, // 4: nop [4] +// 0xa542, // 5: nop [5] +// 0xa642, // 6: nop [6] +// 0xa742, // 7: nop [7] +// 0xa842, // 8: nop [8] +// 0xa942, // 9: nop [9] +// 0xaa42, // 10: nop [10] +// 0xab42, // 11: nop [11] +// 0xac42, // 12: nop [12] +// 0xad42, // 13: nop [13] +// 0xae42, // 14: nop [14] +// 0xaf42, // 15: nop [15] +// 0xb042, // 16: nop [16] +// 0xb142, // 17: nop [17] +// 0xb242, // 18: nop [18] +// 0xb342, // 19: nop [19] +// 0xb442, // 20: nop [20] +// 0xb542, // 21: nop [21] +// 0xb642, // 22: nop [22] +// 0xb742, // 23: nop [23] +// 0xb842, // 24: nop [24] +// 0xb942, // 25: nop [25] +// 0xba42, // 26: nop [26] +// 0xbb42, // 27: nop [27] +// 0xbc42, // 28: nop [28] +// 0xbd42, // 29: nop [29] +// 0xbe42, // 30: nop [30] +// 0xbf42, // 31: nop [31] +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program delay_all_program = { +// .instructions = delay_all_program_instructions, +// .length = 32, +// .origin = -1, +// .pio_version = delay_all_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config delay_all_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + delay_all_wrap_target, offset + delay_all_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_fifo_configurations_valid.pio b/tools/pioasm/test/valid/config/test_fifo_configurations_valid.pio new file mode 100644 index 000000000..a2ba3d59f --- /dev/null +++ b/tools/pioasm/test/valid/config/test_fifo_configurations_valid.pio @@ -0,0 +1,329 @@ +// run: pioasm -v 1 input.pio +.program fifo_comprehensive +.pio_version 1 +.fifo tx + nop + +.program fifo_comprehensive_rx +.pio_version 1 +.fifo rx + nop + +.program fifo_comprehensive_txrx +.pio_version 1 +.fifo txrx + nop + +.program fifo_comprehensive_txput +.pio_version 1 +.fifo txput + nop + +.program fifo_comprehensive_txget +.pio_version 1 +.fifo txget + nop + +.program fifo_comprehensive_putget +.pio_version 1 +.fifo putget + nop + +.program fifo_with_push_pull_txrx +.pio_version 1 +.fifo txrx + push + pull + +.program fifo_with_push_pull_rx +.pio_version 1 +.fifo rx + push + pull + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------------ // +// // fifo_comprehensive // +// // ------------------ // +// +// #define fifo_comprehensive_wrap_target 0 +// #define fifo_comprehensive_wrap 0 +// #define fifo_comprehensive_pio_version 1 +// +// static __pio_const uint16_t fifo_comprehensive_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_comprehensive_program = { +// .instructions = fifo_comprehensive_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_comprehensive_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_comprehensive_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_comprehensive_wrap_target, offset + fifo_comprehensive_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); +// return c; +// } +// #endif +// +// // --------------------- // +// // fifo_comprehensive_rx // +// // --------------------- // +// +// #define fifo_comprehensive_rx_wrap_target 0 +// #define fifo_comprehensive_rx_wrap 0 +// #define fifo_comprehensive_rx_pio_version 1 +// +// static __pio_const uint16_t fifo_comprehensive_rx_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_comprehensive_rx_program = { +// .instructions = fifo_comprehensive_rx_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_comprehensive_rx_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_comprehensive_rx_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_comprehensive_rx_wrap_target, offset + fifo_comprehensive_rx_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); +// return c; +// } +// #endif +// +// // ----------------------- // +// // fifo_comprehensive_txrx // +// // ----------------------- // +// +// #define fifo_comprehensive_txrx_wrap_target 0 +// #define fifo_comprehensive_txrx_wrap 0 +// #define fifo_comprehensive_txrx_pio_version 1 +// +// static __pio_const uint16_t fifo_comprehensive_txrx_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_comprehensive_txrx_program = { +// .instructions = fifo_comprehensive_txrx_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_comprehensive_txrx_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_comprehensive_txrx_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_comprehensive_txrx_wrap_target, offset + fifo_comprehensive_txrx_wrap); +// return c; +// } +// #endif +// +// // ------------------------ // +// // fifo_comprehensive_txput // +// // ------------------------ // +// +// #define fifo_comprehensive_txput_wrap_target 0 +// #define fifo_comprehensive_txput_wrap 0 +// #define fifo_comprehensive_txput_pio_version 1 +// +// static __pio_const uint16_t fifo_comprehensive_txput_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_comprehensive_txput_program = { +// .instructions = fifo_comprehensive_txput_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_comprehensive_txput_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_comprehensive_txput_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_comprehensive_txput_wrap_target, offset + fifo_comprehensive_txput_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TXPUT); +// return c; +// } +// #endif +// +// // ------------------------ // +// // fifo_comprehensive_txget // +// // ------------------------ // +// +// #define fifo_comprehensive_txget_wrap_target 0 +// #define fifo_comprehensive_txget_wrap 0 +// #define fifo_comprehensive_txget_pio_version 1 +// +// static __pio_const uint16_t fifo_comprehensive_txget_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_comprehensive_txget_program = { +// .instructions = fifo_comprehensive_txget_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_comprehensive_txget_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_comprehensive_txget_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_comprehensive_txget_wrap_target, offset + fifo_comprehensive_txget_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TXGET); +// return c; +// } +// #endif +// +// // ------------------------- // +// // fifo_comprehensive_putget // +// // ------------------------- // +// +// #define fifo_comprehensive_putget_wrap_target 0 +// #define fifo_comprehensive_putget_wrap 0 +// #define fifo_comprehensive_putget_pio_version 1 +// +// static __pio_const uint16_t fifo_comprehensive_putget_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_comprehensive_putget_program = { +// .instructions = fifo_comprehensive_putget_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_comprehensive_putget_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_comprehensive_putget_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_comprehensive_putget_wrap_target, offset + fifo_comprehensive_putget_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_PUTGET); +// return c; +// } +// #endif +// +// // ------------------------ // +// // fifo_with_push_pull_txrx // +// // ------------------------ // +// +// #define fifo_with_push_pull_txrx_wrap_target 0 +// #define fifo_with_push_pull_txrx_wrap 1 +// #define fifo_with_push_pull_txrx_pio_version 1 +// +// static __pio_const uint16_t fifo_with_push_pull_txrx_program_instructions[] = { +// // .wrap_target +// 0x8020, // 0: push block +// 0x80a0, // 1: pull block +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_with_push_pull_txrx_program = { +// .instructions = fifo_with_push_pull_txrx_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = fifo_with_push_pull_txrx_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_with_push_pull_txrx_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_with_push_pull_txrx_wrap_target, offset + fifo_with_push_pull_txrx_wrap); +// return c; +// } +// #endif +// +// // ---------------------- // +// // fifo_with_push_pull_rx // +// // ---------------------- // +// +// #define fifo_with_push_pull_rx_wrap_target 0 +// #define fifo_with_push_pull_rx_wrap 1 +// #define fifo_with_push_pull_rx_pio_version 1 +// +// static __pio_const uint16_t fifo_with_push_pull_rx_program_instructions[] = { +// // .wrap_target +// 0x8020, // 0: push block +// 0x80a0, // 1: pull block +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_with_push_pull_rx_program = { +// .instructions = fifo_with_push_pull_rx_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = fifo_with_push_pull_rx_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_with_push_pull_rx_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_with_push_pull_rx_wrap_target, offset + fifo_with_push_pull_rx_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_mov_status_configurations_valid.pio b/tools/pioasm/test/valid/config/test_mov_status_configurations_valid.pio new file mode 100644 index 000000000..e68608e5f --- /dev/null +++ b/tools/pioasm/test/valid/config/test_mov_status_configurations_valid.pio @@ -0,0 +1,367 @@ +// run: pioasm -v 1 input.pio +.program mov_status_tx_lessthan +.pio_version 1 +.mov_status txfifo < 4 + mov x, status + nop + +.program mov_status_tx_zero +.pio_version 1 +.mov_status txfifo < 0 + mov x, status + +.program mov_status_tx_max +.pio_version 1 +.mov_status txfifo < 31 + mov x, status + +.program mov_status_rx_lessthan +.pio_version 1 +.mov_status rxfifo < 8 + mov y, status + +.program mov_status_rx_max +.pio_version 1 +.mov_status rxfifo < 31 + mov y, status + +.program mov_status_irq_set +.pio_version 1 +.mov_status irq set 5 + mov isr, status + +.program mov_status_irq_zero +.pio_version 1 +.mov_status irq set 0 + mov isr, status + +.program mov_status_irq_max +.pio_version 1 +.mov_status irq set 7 + mov isr, status + +.program mov_status_irq_rel +.pio_version 1 +.mov_status irq prev set 3 + mov osr, status + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------------------- // +// // mov_status_tx_lessthan // +// // ---------------------- // +// +// #define mov_status_tx_lessthan_wrap_target 0 +// #define mov_status_tx_lessthan_wrap 1 +// #define mov_status_tx_lessthan_pio_version 1 +// +// static __pio_const uint16_t mov_status_tx_lessthan_program_instructions[] = { +// // .wrap_target +// 0xa025, // 0: mov x, status +// 0xa042, // 1: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_tx_lessthan_program = { +// .instructions = mov_status_tx_lessthan_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = mov_status_tx_lessthan_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_tx_lessthan_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_tx_lessthan_wrap_target, offset + mov_status_tx_lessthan_wrap); +// sm_config_set_mov_status(&c, STATUS_TX_LESSTHAN, 4); +// return c; +// } +// #endif +// +// // ------------------ // +// // mov_status_tx_zero // +// // ------------------ // +// +// #define mov_status_tx_zero_wrap_target 0 +// #define mov_status_tx_zero_wrap 0 +// #define mov_status_tx_zero_pio_version 1 +// +// static __pio_const uint16_t mov_status_tx_zero_program_instructions[] = { +// // .wrap_target +// 0xa025, // 0: mov x, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_tx_zero_program = { +// .instructions = mov_status_tx_zero_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_tx_zero_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_tx_zero_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_tx_zero_wrap_target, offset + mov_status_tx_zero_wrap); +// sm_config_set_mov_status(&c, STATUS_TX_LESSTHAN, 0); +// return c; +// } +// #endif +// +// // ----------------- // +// // mov_status_tx_max // +// // ----------------- // +// +// #define mov_status_tx_max_wrap_target 0 +// #define mov_status_tx_max_wrap 0 +// #define mov_status_tx_max_pio_version 1 +// +// static __pio_const uint16_t mov_status_tx_max_program_instructions[] = { +// // .wrap_target +// 0xa025, // 0: mov x, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_tx_max_program = { +// .instructions = mov_status_tx_max_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_tx_max_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_tx_max_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_tx_max_wrap_target, offset + mov_status_tx_max_wrap); +// sm_config_set_mov_status(&c, STATUS_TX_LESSTHAN, 31); +// return c; +// } +// #endif +// +// // ---------------------- // +// // mov_status_rx_lessthan // +// // ---------------------- // +// +// #define mov_status_rx_lessthan_wrap_target 0 +// #define mov_status_rx_lessthan_wrap 0 +// #define mov_status_rx_lessthan_pio_version 1 +// +// static __pio_const uint16_t mov_status_rx_lessthan_program_instructions[] = { +// // .wrap_target +// 0xa045, // 0: mov y, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_rx_lessthan_program = { +// .instructions = mov_status_rx_lessthan_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_rx_lessthan_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_rx_lessthan_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_rx_lessthan_wrap_target, offset + mov_status_rx_lessthan_wrap); +// sm_config_set_mov_status(&c, STATUS_RX_LESSTHAN, 8); +// return c; +// } +// #endif +// +// // ----------------- // +// // mov_status_rx_max // +// // ----------------- // +// +// #define mov_status_rx_max_wrap_target 0 +// #define mov_status_rx_max_wrap 0 +// #define mov_status_rx_max_pio_version 1 +// +// static __pio_const uint16_t mov_status_rx_max_program_instructions[] = { +// // .wrap_target +// 0xa045, // 0: mov y, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_rx_max_program = { +// .instructions = mov_status_rx_max_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_rx_max_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_rx_max_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_rx_max_wrap_target, offset + mov_status_rx_max_wrap); +// sm_config_set_mov_status(&c, STATUS_RX_LESSTHAN, 31); +// return c; +// } +// #endif +// +// // ------------------ // +// // mov_status_irq_set // +// // ------------------ // +// +// #define mov_status_irq_set_wrap_target 0 +// #define mov_status_irq_set_wrap 0 +// #define mov_status_irq_set_pio_version 1 +// +// static __pio_const uint16_t mov_status_irq_set_program_instructions[] = { +// // .wrap_target +// 0xa0c5, // 0: mov isr, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_irq_set_program = { +// .instructions = mov_status_irq_set_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_irq_set_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_irq_set_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_irq_set_wrap_target, offset + mov_status_irq_set_wrap); +// sm_config_set_mov_status(&c, STATUS_IRQ_SET, 5); +// return c; +// } +// #endif +// +// // ------------------- // +// // mov_status_irq_zero // +// // ------------------- // +// +// #define mov_status_irq_zero_wrap_target 0 +// #define mov_status_irq_zero_wrap 0 +// #define mov_status_irq_zero_pio_version 1 +// +// static __pio_const uint16_t mov_status_irq_zero_program_instructions[] = { +// // .wrap_target +// 0xa0c5, // 0: mov isr, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_irq_zero_program = { +// .instructions = mov_status_irq_zero_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_irq_zero_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_irq_zero_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_irq_zero_wrap_target, offset + mov_status_irq_zero_wrap); +// sm_config_set_mov_status(&c, STATUS_IRQ_SET, 0); +// return c; +// } +// #endif +// +// // ------------------ // +// // mov_status_irq_max // +// // ------------------ // +// +// #define mov_status_irq_max_wrap_target 0 +// #define mov_status_irq_max_wrap 0 +// #define mov_status_irq_max_pio_version 1 +// +// static __pio_const uint16_t mov_status_irq_max_program_instructions[] = { +// // .wrap_target +// 0xa0c5, // 0: mov isr, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_irq_max_program = { +// .instructions = mov_status_irq_max_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_irq_max_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_irq_max_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_irq_max_wrap_target, offset + mov_status_irq_max_wrap); +// sm_config_set_mov_status(&c, STATUS_IRQ_SET, 7); +// return c; +// } +// #endif +// +// // ------------------ // +// // mov_status_irq_rel // +// // ------------------ // +// +// #define mov_status_irq_rel_wrap_target 0 +// #define mov_status_irq_rel_wrap 0 +// #define mov_status_irq_rel_pio_version 1 +// +// static __pio_const uint16_t mov_status_irq_rel_program_instructions[] = { +// // .wrap_target +// 0xa0e5, // 0: mov osr, status +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program mov_status_irq_rel_program = { +// .instructions = mov_status_irq_rel_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = mov_status_irq_rel_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config mov_status_irq_rel_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + mov_status_irq_rel_wrap_target, offset + mov_status_irq_rel_wrap); +// sm_config_set_mov_status(&c, STATUS_IRQ_SET, 11); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_origin_configurations_valid.pio b/tools/pioasm/test/valid/config/test_origin_configurations_valid.pio new file mode 100644 index 000000000..6bc8728b0 --- /dev/null +++ b/tools/pioasm/test/valid/config/test_origin_configurations_valid.pio @@ -0,0 +1,97 @@ +// run: pioasm input.pio +.program origin_zero +.origin 0 + nop + nop + +.program origin_five +.origin 5 + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------- // +// // origin_zero // +// // ----------- // +// +// #define origin_zero_wrap_target 0 +// #define origin_zero_wrap 1 +// #define origin_zero_pio_version 0 +// +// static __pio_const uint16_t origin_zero_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_zero_program = { +// .instructions = origin_zero_program_instructions, +// .length = 2, +// .origin = 0, +// .pio_version = origin_zero_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_zero_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_zero_wrap_target, offset + origin_zero_wrap); +// return c; +// } +// #endif +// +// // ----------- // +// // origin_five // +// // ----------- // +// +// #define origin_five_wrap_target 0 +// #define origin_five_wrap 0 +// #define origin_five_pio_version 0 +// +// static __pio_const uint16_t origin_five_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_five_program = { +// .instructions = origin_five_program_instructions, +// .length = 1, +// .origin = 5, +// .pio_version = origin_five_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_five_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_five_wrap_target, offset + origin_five_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_pin_count_configurations_valid.pio b/tools/pioasm/test/valid/config/test_pin_count_configurations_valid.pio new file mode 100644 index 000000000..b05052121 --- /dev/null +++ b/tools/pioasm/test/valid/config/test_pin_count_configurations_valid.pio @@ -0,0 +1,298 @@ +// run: pioasm -v 1 input.pio +.program pin_config_comprehensive +.pio_version 1 +.set 5 +.in 8 right auto 24 +.out 4 right auto 20 + set pins, 5 + in pins, 8 + out pins, 4 + +.program pin_config_set_zero +.set 0 + nop + +.program pin_config_set_max +.set 5 + set pins, 31 + +.program pin_config_in_min +.in 1 + in pins, 1 + +.program pin_config_in_max +.pio_version 1 +.in 32 + in pins, 32 + +.program pin_config_out_zero +.out 0 + nop + +.program pin_config_out_max +.out 32 + out pins, 32 + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------------------ // +// // pin_config_comprehensive // +// // ------------------------ // +// +// #define pin_config_comprehensive_wrap_target 0 +// #define pin_config_comprehensive_wrap 2 +// #define pin_config_comprehensive_pio_version 1 +// +// static __pio_const uint16_t pin_config_comprehensive_program_instructions[] = { +// // .wrap_target +// 0xe005, // 0: set pins, 5 +// 0x4008, // 1: in pins, 8 +// 0x6004, // 2: out pins, 4 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pin_config_comprehensive_program = { +// .instructions = pin_config_comprehensive_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = pin_config_comprehensive_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pin_config_comprehensive_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pin_config_comprehensive_wrap_target, offset + pin_config_comprehensive_wrap); +// sm_config_set_in_pin_count(&c, 8); +// sm_config_set_in_shift(&c, 1, 1, 24); +// sm_config_set_out_pin_count(&c, 4); +// sm_config_set_out_shift(&c, 1, 1, 20); +// sm_config_set_set_pin_count(&c, 5); +// return c; +// } +// #endif +// +// // ------------------- // +// // pin_config_set_zero // +// // ------------------- // +// +// #define pin_config_set_zero_wrap_target 0 +// #define pin_config_set_zero_wrap 0 +// #define pin_config_set_zero_pio_version 1 +// +// static __pio_const uint16_t pin_config_set_zero_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pin_config_set_zero_program = { +// .instructions = pin_config_set_zero_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = pin_config_set_zero_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pin_config_set_zero_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pin_config_set_zero_wrap_target, offset + pin_config_set_zero_wrap); +// sm_config_set_set_pin_count(&c, 0); +// return c; +// } +// #endif +// +// // ------------------ // +// // pin_config_set_max // +// // ------------------ // +// +// #define pin_config_set_max_wrap_target 0 +// #define pin_config_set_max_wrap 0 +// #define pin_config_set_max_pio_version 1 +// +// static __pio_const uint16_t pin_config_set_max_program_instructions[] = { +// // .wrap_target +// 0xe01f, // 0: set pins, 31 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pin_config_set_max_program = { +// .instructions = pin_config_set_max_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = pin_config_set_max_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pin_config_set_max_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pin_config_set_max_wrap_target, offset + pin_config_set_max_wrap); +// sm_config_set_set_pin_count(&c, 5); +// return c; +// } +// #endif +// +// // ----------------- // +// // pin_config_in_min // +// // ----------------- // +// +// #define pin_config_in_min_wrap_target 0 +// #define pin_config_in_min_wrap 0 +// #define pin_config_in_min_pio_version 1 +// +// static __pio_const uint16_t pin_config_in_min_program_instructions[] = { +// // .wrap_target +// 0x4001, // 0: in pins, 1 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pin_config_in_min_program = { +// .instructions = pin_config_in_min_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = pin_config_in_min_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pin_config_in_min_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pin_config_in_min_wrap_target, offset + pin_config_in_min_wrap); +// sm_config_set_in_pin_count(&c, 1); +// sm_config_set_in_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// // ----------------- // +// // pin_config_in_max // +// // ----------------- // +// +// #define pin_config_in_max_wrap_target 0 +// #define pin_config_in_max_wrap 0 +// #define pin_config_in_max_pio_version 1 +// +// static __pio_const uint16_t pin_config_in_max_program_instructions[] = { +// // .wrap_target +// 0x4000, // 0: in pins, 32 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pin_config_in_max_program = { +// .instructions = pin_config_in_max_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = pin_config_in_max_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pin_config_in_max_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pin_config_in_max_wrap_target, offset + pin_config_in_max_wrap); +// sm_config_set_in_pin_count(&c, 32); +// sm_config_set_in_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// // ------------------- // +// // pin_config_out_zero // +// // ------------------- // +// +// #define pin_config_out_zero_wrap_target 0 +// #define pin_config_out_zero_wrap 0 +// #define pin_config_out_zero_pio_version 1 +// +// static __pio_const uint16_t pin_config_out_zero_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pin_config_out_zero_program = { +// .instructions = pin_config_out_zero_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = pin_config_out_zero_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pin_config_out_zero_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pin_config_out_zero_wrap_target, offset + pin_config_out_zero_wrap); +// sm_config_set_out_pin_count(&c, 0); +// sm_config_set_out_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// // ------------------ // +// // pin_config_out_max // +// // ------------------ // +// +// #define pin_config_out_max_wrap_target 0 +// #define pin_config_out_max_wrap 0 +// #define pin_config_out_max_pio_version 1 +// +// static __pio_const uint16_t pin_config_out_max_program_instructions[] = { +// // .wrap_target +// 0x6000, // 0: out pins, 32 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pin_config_out_max_program = { +// .instructions = pin_config_out_max_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = pin_config_out_max_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pin_config_out_max_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pin_config_out_max_wrap_target, offset + pin_config_out_max_wrap); +// sm_config_set_out_pin_count(&c, 32); +// sm_config_set_out_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_shift_configurations_valid.pio b/tools/pioasm/test/valid/config/test_shift_configurations_valid.pio new file mode 100644 index 000000000..fa94f4307 --- /dev/null +++ b/tools/pioasm/test/valid/config/test_shift_configurations_valid.pio @@ -0,0 +1,387 @@ +// run: pioasm -v 1 input.pio +.program shift_left +.pio_version 1 +.in 8 + in pins, 8 + +.program shift_right +.pio_version 1 +.in 8 right + in pins, 8 + +.program shift_autopush +.pio_version 1 +.in 16 auto + in pins, 8 + in pins, 8 + +.program shift_autopush_threshold +.pio_version 1 +.in 8 auto 24 + in pins, 8 + in pins, 8 + +.program shift_out_left +.pio_version 1 +.out 4 + out pins, 4 + +.program shift_out_right +.pio_version 1 +.out 4 right + out pins, 4 + +.program shift_out_autopull +.pio_version 1 +.out 16 auto + out pins, 8 + out pins, 8 + +.program shift_out_autopull_threshold +.pio_version 1 +.out 8 auto 20 + out pins, 8 + out pins, 8 + +.program shift_combined +.pio_version 1 +.in 8 right auto 16 +.out 4 right auto 24 + in pins, 8 + out pins, 4 + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------- // +// // shift_left // +// // ---------- // +// +// #define shift_left_wrap_target 0 +// #define shift_left_wrap 0 +// #define shift_left_pio_version 1 +// +// static __pio_const uint16_t shift_left_program_instructions[] = { +// // .wrap_target +// 0x4008, // 0: in pins, 8 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_left_program = { +// .instructions = shift_left_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = shift_left_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_left_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_left_wrap_target, offset + shift_left_wrap); +// sm_config_set_in_pin_count(&c, 8); +// sm_config_set_in_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// // ----------- // +// // shift_right // +// // ----------- // +// +// #define shift_right_wrap_target 0 +// #define shift_right_wrap 0 +// #define shift_right_pio_version 1 +// +// static __pio_const uint16_t shift_right_program_instructions[] = { +// // .wrap_target +// 0x4008, // 0: in pins, 8 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_right_program = { +// .instructions = shift_right_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = shift_right_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_right_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_right_wrap_target, offset + shift_right_wrap); +// sm_config_set_in_pin_count(&c, 8); +// sm_config_set_in_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// // -------------- // +// // shift_autopush // +// // -------------- // +// +// #define shift_autopush_wrap_target 0 +// #define shift_autopush_wrap 1 +// #define shift_autopush_pio_version 1 +// +// static __pio_const uint16_t shift_autopush_program_instructions[] = { +// // .wrap_target +// 0x4008, // 0: in pins, 8 +// 0x4008, // 1: in pins, 8 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_autopush_program = { +// .instructions = shift_autopush_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = shift_autopush_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_autopush_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_autopush_wrap_target, offset + shift_autopush_wrap); +// sm_config_set_in_pin_count(&c, 16); +// sm_config_set_in_shift(&c, 1, 1, 32); +// return c; +// } +// #endif +// +// // ------------------------ // +// // shift_autopush_threshold // +// // ------------------------ // +// +// #define shift_autopush_threshold_wrap_target 0 +// #define shift_autopush_threshold_wrap 1 +// #define shift_autopush_threshold_pio_version 1 +// +// static __pio_const uint16_t shift_autopush_threshold_program_instructions[] = { +// // .wrap_target +// 0x4008, // 0: in pins, 8 +// 0x4008, // 1: in pins, 8 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_autopush_threshold_program = { +// .instructions = shift_autopush_threshold_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = shift_autopush_threshold_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_autopush_threshold_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_autopush_threshold_wrap_target, offset + shift_autopush_threshold_wrap); +// sm_config_set_in_pin_count(&c, 8); +// sm_config_set_in_shift(&c, 1, 1, 24); +// return c; +// } +// #endif +// +// // -------------- // +// // shift_out_left // +// // -------------- // +// +// #define shift_out_left_wrap_target 0 +// #define shift_out_left_wrap 0 +// #define shift_out_left_pio_version 1 +// +// static __pio_const uint16_t shift_out_left_program_instructions[] = { +// // .wrap_target +// 0x6004, // 0: out pins, 4 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_out_left_program = { +// .instructions = shift_out_left_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = shift_out_left_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_out_left_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_out_left_wrap_target, offset + shift_out_left_wrap); +// sm_config_set_out_pin_count(&c, 4); +// sm_config_set_out_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// // --------------- // +// // shift_out_right // +// // --------------- // +// +// #define shift_out_right_wrap_target 0 +// #define shift_out_right_wrap 0 +// #define shift_out_right_pio_version 1 +// +// static __pio_const uint16_t shift_out_right_program_instructions[] = { +// // .wrap_target +// 0x6004, // 0: out pins, 4 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_out_right_program = { +// .instructions = shift_out_right_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = shift_out_right_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_out_right_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_out_right_wrap_target, offset + shift_out_right_wrap); +// sm_config_set_out_pin_count(&c, 4); +// sm_config_set_out_shift(&c, 1, 0, 32); +// return c; +// } +// #endif +// +// // ------------------ // +// // shift_out_autopull // +// // ------------------ // +// +// #define shift_out_autopull_wrap_target 0 +// #define shift_out_autopull_wrap 1 +// #define shift_out_autopull_pio_version 1 +// +// static __pio_const uint16_t shift_out_autopull_program_instructions[] = { +// // .wrap_target +// 0x6008, // 0: out pins, 8 +// 0x6008, // 1: out pins, 8 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_out_autopull_program = { +// .instructions = shift_out_autopull_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = shift_out_autopull_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_out_autopull_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_out_autopull_wrap_target, offset + shift_out_autopull_wrap); +// sm_config_set_out_pin_count(&c, 16); +// sm_config_set_out_shift(&c, 1, 1, 32); +// return c; +// } +// #endif +// +// // ---------------------------- // +// // shift_out_autopull_threshold // +// // ---------------------------- // +// +// #define shift_out_autopull_threshold_wrap_target 0 +// #define shift_out_autopull_threshold_wrap 1 +// #define shift_out_autopull_threshold_pio_version 1 +// +// static __pio_const uint16_t shift_out_autopull_threshold_program_instructions[] = { +// // .wrap_target +// 0x6008, // 0: out pins, 8 +// 0x6008, // 1: out pins, 8 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_out_autopull_threshold_program = { +// .instructions = shift_out_autopull_threshold_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = shift_out_autopull_threshold_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_out_autopull_threshold_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_out_autopull_threshold_wrap_target, offset + shift_out_autopull_threshold_wrap); +// sm_config_set_out_pin_count(&c, 8); +// sm_config_set_out_shift(&c, 1, 1, 20); +// return c; +// } +// #endif +// +// // -------------- // +// // shift_combined // +// // -------------- // +// +// #define shift_combined_wrap_target 0 +// #define shift_combined_wrap 1 +// #define shift_combined_pio_version 1 +// +// static __pio_const uint16_t shift_combined_program_instructions[] = { +// // .wrap_target +// 0x4008, // 0: in pins, 8 +// 0x6004, // 1: out pins, 4 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program shift_combined_program = { +// .instructions = shift_combined_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = shift_combined_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config shift_combined_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + shift_combined_wrap_target, offset + shift_combined_wrap); +// sm_config_set_in_pin_count(&c, 8); +// sm_config_set_in_shift(&c, 1, 1, 16); +// sm_config_set_out_pin_count(&c, 4); +// sm_config_set_out_shift(&c, 1, 1, 24); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_sideset_all_configs_valid.pio b/tools/pioasm/test/valid/config/test_sideset_all_configs_valid.pio new file mode 100644 index 000000000..2fb84169d --- /dev/null +++ b/tools/pioasm/test/valid/config/test_sideset_all_configs_valid.pio @@ -0,0 +1,138 @@ +// run: pioasm input.pio +.program sideset_1 +.side_set 1 + nop side 0 + nop side 1 + +.program sideset_opt +.side_set 2 opt + nop + nop side 3 + +.program sideset_pindirs +.side_set 3 opt pindirs + nop side 7 + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // --------- // +// // sideset_1 // +// // --------- // +// +// #define sideset_1_wrap_target 0 +// #define sideset_1_wrap 1 +// #define sideset_1_pio_version 0 +// +// static __pio_const uint16_t sideset_1_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop side 0 +// 0xb042, // 1: nop side 1 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program sideset_1_program = { +// .instructions = sideset_1_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = sideset_1_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config sideset_1_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + sideset_1_wrap_target, offset + sideset_1_wrap); +// sm_config_set_sideset(&c, 1, false, false); +// return c; +// } +// #endif +// +// // ----------- // +// // sideset_opt // +// // ----------- // +// +// #define sideset_opt_wrap_target 0 +// #define sideset_opt_wrap 1 +// #define sideset_opt_pio_version 0 +// +// static __pio_const uint16_t sideset_opt_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xbc42, // 1: nop side 3 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program sideset_opt_program = { +// .instructions = sideset_opt_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = sideset_opt_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config sideset_opt_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + sideset_opt_wrap_target, offset + sideset_opt_wrap); +// sm_config_set_sideset(&c, 3, true, false); +// return c; +// } +// #endif +// +// // --------------- // +// // sideset_pindirs // +// // --------------- // +// +// #define sideset_pindirs_wrap_target 0 +// #define sideset_pindirs_wrap 0 +// #define sideset_pindirs_pio_version 0 +// +// static __pio_const uint16_t sideset_pindirs_program_instructions[] = { +// // .wrap_target +// 0xbe42, // 0: nop side 7 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program sideset_pindirs_program = { +// .instructions = sideset_pindirs_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = sideset_pindirs_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config sideset_pindirs_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + sideset_pindirs_wrap_target, offset + sideset_pindirs_wrap); +// sm_config_set_sideset(&c, 4, true, true); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/config/test_wrap_configurations_valid.pio b/tools/pioasm/test/valid/config/test_wrap_configurations_valid.pio new file mode 100644 index 000000000..b6bb58c12 --- /dev/null +++ b/tools/pioasm/test/valid/config/test_wrap_configurations_valid.pio @@ -0,0 +1,105 @@ +// run: pioasm input.pio +.program wrap_begin +.wrap_target +wrap_begin: + nop + jmp wrap_begin +.wrap + +.program wrap_mid +wrap_mid: + nop +.wrap_target + nop + jmp wrap_mid +.wrap + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------- // +// // wrap_begin // +// // ---------- // +// +// #define wrap_begin_wrap_target 0 +// #define wrap_begin_wrap 1 +// #define wrap_begin_pio_version 0 +// +// static __pio_const uint16_t wrap_begin_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0x0000, // 1: jmp 0 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_begin_program = { +// .instructions = wrap_begin_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = wrap_begin_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_begin_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_begin_wrap_target, offset + wrap_begin_wrap); +// return c; +// } +// #endif +// +// // -------- // +// // wrap_mid // +// // -------- // +// +// #define wrap_mid_wrap_target 1 +// #define wrap_mid_wrap 2 +// #define wrap_mid_pio_version 0 +// +// static __pio_const uint16_t wrap_mid_program_instructions[] = { +// 0xa042, // 0: nop +// // .wrap_target +// 0xa042, // 1: nop +// 0x0000, // 2: jmp 0 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_mid_program = { +// .instructions = wrap_mid_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = wrap_mid_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_mid_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_mid_wrap_target, offset + wrap_mid_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_boundary_values_valid.pio b/tools/pioasm/test/valid/edge/test_boundary_values_valid.pio new file mode 100644 index 000000000..eb1356e7c --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_boundary_values_valid.pio @@ -0,0 +1,68 @@ +// run: pioasm input.pio +.program boundary_test + in pins, 1 ; min bit count + in pins, 32 ; max bit count + set pins, 0 ; min value + set pins, 31 ; max value + irq 0 ; min IRQ + irq 7 ; max IRQ + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------- // +// // boundary_test // +// // ------------- // +// +// #define boundary_test_wrap_target 0 +// #define boundary_test_wrap 5 +// #define boundary_test_pio_version 0 +// +// static __pio_const uint16_t boundary_test_program_instructions[] = { +// // .wrap_target +// 0x4001, // 0: in pins, 1 +// 0x4000, // 1: in pins, 32 +// 0xe000, // 2: set pins, 0 +// 0xe01f, // 3: set pins, 31 +// 0xc000, // 4: irq nowait 0 +// 0xc007, // 5: irq nowait 7 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program boundary_test_program = { +// .instructions = boundary_test_program_instructions, +// .length = 6, +// .origin = -1, +// .pio_version = boundary_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config boundary_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + boundary_test_wrap_target, offset + boundary_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_complex_program_valid.pio b/tools/pioasm/test/valid/edge/test_complex_program_valid.pio new file mode 100644 index 000000000..814330f25 --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_complex_program_valid.pio @@ -0,0 +1,71 @@ +// run: pioasm input.pio +.program complex_prog +.side_set 1 opt +.wrap_target +start: + pull + out pins, 8 side 1 + in pins, 8 + mov x, osr + jmp x--, start +.wrap + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------ // +// // complex_prog // +// // ------------ // +// +// #define complex_prog_wrap_target 0 +// #define complex_prog_wrap 4 +// #define complex_prog_pio_version 0 +// +// static __pio_const uint16_t complex_prog_program_instructions[] = { +// // .wrap_target +// 0x80a0, // 0: pull block +// 0x7808, // 1: out pins, 8 side 1 +// 0x4008, // 2: in pins, 8 +// 0xa027, // 3: mov x, osr +// 0x0040, // 4: jmp x--, 0 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program complex_prog_program = { +// .instructions = complex_prog_program_instructions, +// .length = 5, +// .origin = -1, +// .pio_version = complex_prog_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config complex_prog_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + complex_prog_wrap_target, offset + complex_prog_wrap); +// sm_config_set_sideset(&c, 2, true, false); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_entry_points_valid.pio b/tools/pioasm/test/valid/edge/test_entry_points_valid.pio new file mode 100644 index 000000000..daad9e4df --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_entry_points_valid.pio @@ -0,0 +1,281 @@ +// run: pioasm input.pio +// Test public labels as entry points + +.program entry_at_start +public entry_start: + nop + nop + +.program entry_in_middle + nop +public entry_middle: + nop + nop + +.program entry_at_end + nop + nop +public entry_end: + nop + +.program multiple_entries +public init: + nop +public process: + nop +public cleanup: + nop + +.program entry_with_wrap +.wrap_target +public loop_start: + nop + nop +.wrap + +.program entry_outside_wrap +public setup: + nop +.wrap_target + nop + nop +.wrap + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // -------------- // +// // entry_at_start // +// // -------------- // +// +// #define entry_at_start_wrap_target 0 +// #define entry_at_start_wrap 1 +// #define entry_at_start_pio_version 0 +// +// #define entry_at_start_offset_entry_start 0u +// +// static __pio_const uint16_t entry_at_start_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program entry_at_start_program = { +// .instructions = entry_at_start_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = entry_at_start_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config entry_at_start_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + entry_at_start_wrap_target, offset + entry_at_start_wrap); +// return c; +// } +// #endif +// +// // --------------- // +// // entry_in_middle // +// // --------------- // +// +// #define entry_in_middle_wrap_target 0 +// #define entry_in_middle_wrap 2 +// #define entry_in_middle_pio_version 0 +// +// #define entry_in_middle_offset_entry_middle 1u +// +// static __pio_const uint16_t entry_in_middle_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program entry_in_middle_program = { +// .instructions = entry_in_middle_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = entry_in_middle_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config entry_in_middle_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + entry_in_middle_wrap_target, offset + entry_in_middle_wrap); +// return c; +// } +// #endif +// +// // ------------ // +// // entry_at_end // +// // ------------ // +// +// #define entry_at_end_wrap_target 0 +// #define entry_at_end_wrap 2 +// #define entry_at_end_pio_version 0 +// +// #define entry_at_end_offset_entry_end 2u +// +// static __pio_const uint16_t entry_at_end_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program entry_at_end_program = { +// .instructions = entry_at_end_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = entry_at_end_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config entry_at_end_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + entry_at_end_wrap_target, offset + entry_at_end_wrap); +// return c; +// } +// #endif +// +// // ---------------- // +// // multiple_entries // +// // ---------------- // +// +// #define multiple_entries_wrap_target 0 +// #define multiple_entries_wrap 2 +// #define multiple_entries_pio_version 0 +// +// #define multiple_entries_offset_init 0u +// #define multiple_entries_offset_process 1u +// #define multiple_entries_offset_cleanup 2u +// +// static __pio_const uint16_t multiple_entries_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program multiple_entries_program = { +// .instructions = multiple_entries_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = multiple_entries_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config multiple_entries_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + multiple_entries_wrap_target, offset + multiple_entries_wrap); +// return c; +// } +// #endif +// +// // --------------- // +// // entry_with_wrap // +// // --------------- // +// +// #define entry_with_wrap_wrap_target 0 +// #define entry_with_wrap_wrap 1 +// #define entry_with_wrap_pio_version 0 +// +// #define entry_with_wrap_offset_loop_start 0u +// +// static __pio_const uint16_t entry_with_wrap_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program entry_with_wrap_program = { +// .instructions = entry_with_wrap_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = entry_with_wrap_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config entry_with_wrap_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + entry_with_wrap_wrap_target, offset + entry_with_wrap_wrap); +// return c; +// } +// #endif +// +// // ------------------ // +// // entry_outside_wrap // +// // ------------------ // +// +// #define entry_outside_wrap_wrap_target 1 +// #define entry_outside_wrap_wrap 2 +// #define entry_outside_wrap_pio_version 0 +// +// #define entry_outside_wrap_offset_setup 0u +// +// static __pio_const uint16_t entry_outside_wrap_program_instructions[] = { +// 0xa042, // 0: nop +// // .wrap_target +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program entry_outside_wrap_program = { +// .instructions = entry_outside_wrap_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = entry_outside_wrap_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config entry_outside_wrap_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + entry_outside_wrap_wrap_target, offset + entry_outside_wrap_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_max_program_size_valid.pio b/tools/pioasm/test/valid/edge/test_max_program_size_valid.pio new file mode 100644 index 000000000..a64a96dff --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_max_program_size_valid.pio @@ -0,0 +1,122 @@ +// run: pioasm input.pio +.program max_program +.wrap_target + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop + nop +.wrap + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------- // +// // max_program // +// // ----------- // +// +// #define max_program_wrap_target 0 +// #define max_program_wrap 31 +// #define max_program_pio_version 0 +// +// static __pio_const uint16_t max_program_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// 0xa042, // 3: nop +// 0xa042, // 4: nop +// 0xa042, // 5: nop +// 0xa042, // 6: nop +// 0xa042, // 7: nop +// 0xa042, // 8: nop +// 0xa042, // 9: nop +// 0xa042, // 10: nop +// 0xa042, // 11: nop +// 0xa042, // 12: nop +// 0xa042, // 13: nop +// 0xa042, // 14: nop +// 0xa042, // 15: nop +// 0xa042, // 16: nop +// 0xa042, // 17: nop +// 0xa042, // 18: nop +// 0xa042, // 19: nop +// 0xa042, // 20: nop +// 0xa042, // 21: nop +// 0xa042, // 22: nop +// 0xa042, // 23: nop +// 0xa042, // 24: nop +// 0xa042, // 25: nop +// 0xa042, // 26: nop +// 0xa042, // 27: nop +// 0xa042, // 28: nop +// 0xa042, // 29: nop +// 0xa042, // 30: nop +// 0xa042, // 31: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program max_program_program = { +// .instructions = max_program_program_instructions, +// .length = 32, +// .origin = -1, +// .pio_version = max_program_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config max_program_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + max_program_wrap_target, offset + max_program_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_multiple_programs_valid.pio b/tools/pioasm/test/valid/edge/test_multiple_programs_valid.pio new file mode 100644 index 000000000..c5d314b8a --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_multiple_programs_valid.pio @@ -0,0 +1,93 @@ +// run: pioasm input.pio +.program prog_a + nop + +.program prog_b + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------ // +// // prog_a // +// // ------ // +// +// #define prog_a_wrap_target 0 +// #define prog_a_wrap 0 +// #define prog_a_pio_version 0 +// +// static __pio_const uint16_t prog_a_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program prog_a_program = { +// .instructions = prog_a_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = prog_a_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config prog_a_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + prog_a_wrap_target, offset + prog_a_wrap); +// return c; +// } +// #endif +// +// // ------ // +// // prog_b // +// // ------ // +// +// #define prog_b_wrap_target 0 +// #define prog_b_wrap 0 +// #define prog_b_pio_version 0 +// +// static __pio_const uint16_t prog_b_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program prog_b_program = { +// .instructions = prog_b_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = prog_b_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config prog_b_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + prog_b_wrap_target, offset + prog_b_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_origin_edge_cases_valid.pio b/tools/pioasm/test/valid/edge/test_origin_edge_cases_valid.pio new file mode 100644 index 000000000..19bf8caed --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_origin_edge_cases_valid.pio @@ -0,0 +1,186 @@ +// run: pioasm input.pio +// Test origin edge cases - what happens when programs are loaded at specific addresses + +.program origin_zero_with_jumps +.origin 0 +start: + jmp start ; Jump to address 0 + jmp end ; Jump to address 1 +end: + nop + +.program origin_at_end +.origin 29 + nop + nop + nop ; Will be at addresses 29, 30, 31 + +.program origin_with_wrap_target +.origin 15 +.wrap_target + nop + nop +.wrap + +.program origin_affects_jmp +.origin 10 +start: + jmp start ; Will encode as jmp 10 (absolute) + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------------------- // +// // origin_zero_with_jumps // +// // ---------------------- // +// +// #define origin_zero_with_jumps_wrap_target 0 +// #define origin_zero_with_jumps_wrap 2 +// #define origin_zero_with_jumps_pio_version 0 +// +// static __pio_const uint16_t origin_zero_with_jumps_program_instructions[] = { +// // .wrap_target +// 0x0000, // 0: jmp 0 +// 0x0002, // 1: jmp 2 +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_zero_with_jumps_program = { +// .instructions = origin_zero_with_jumps_program_instructions, +// .length = 3, +// .origin = 0, +// .pio_version = origin_zero_with_jumps_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_zero_with_jumps_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_zero_with_jumps_wrap_target, offset + origin_zero_with_jumps_wrap); +// return c; +// } +// #endif +// +// // ------------- // +// // origin_at_end // +// // ------------- // +// +// #define origin_at_end_wrap_target 0 +// #define origin_at_end_wrap 2 +// #define origin_at_end_pio_version 0 +// +// static __pio_const uint16_t origin_at_end_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_at_end_program = { +// .instructions = origin_at_end_program_instructions, +// .length = 3, +// .origin = 29, +// .pio_version = origin_at_end_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_at_end_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_at_end_wrap_target, offset + origin_at_end_wrap); +// return c; +// } +// #endif +// +// // ----------------------- // +// // origin_with_wrap_target // +// // ----------------------- // +// +// #define origin_with_wrap_target_wrap_target 0 +// #define origin_with_wrap_target_wrap 1 +// #define origin_with_wrap_target_pio_version 0 +// +// static __pio_const uint16_t origin_with_wrap_target_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_with_wrap_target_program = { +// .instructions = origin_with_wrap_target_program_instructions, +// .length = 2, +// .origin = 15, +// .pio_version = origin_with_wrap_target_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_with_wrap_target_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_with_wrap_target_wrap_target, offset + origin_with_wrap_target_wrap); +// return c; +// } +// #endif +// +// // ------------------ // +// // origin_affects_jmp // +// // ------------------ // +// +// #define origin_affects_jmp_wrap_target 0 +// #define origin_affects_jmp_wrap 1 +// #define origin_affects_jmp_pio_version 0 +// +// static __pio_const uint16_t origin_affects_jmp_program_instructions[] = { +// // .wrap_target +// 0x0000, // 0: jmp 0 +// 0xa042, // 1: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_affects_jmp_program = { +// .instructions = origin_affects_jmp_program_instructions, +// .length = 2, +// .origin = 10, +// .pio_version = origin_affects_jmp_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_affects_jmp_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_affects_jmp_wrap_target, offset + origin_affects_jmp_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_origin_overwrite_valid.pio b/tools/pioasm/test/valid/edge/test_origin_overwrite_valid.pio new file mode 100644 index 000000000..658d13a89 --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_origin_overwrite_valid.pio @@ -0,0 +1,102 @@ +// run: pioasm input.pio +// Test that multiple .origin directives are allowed - last one wins + +.program origin_overwrite_simple +.origin 5 +.origin 10 + nop + nop + +.program origin_overwrite_multiple +.origin 0 +.origin 15 +.origin 20 + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------------------- // +// // origin_overwrite_simple // +// // ----------------------- // +// +// #define origin_overwrite_simple_wrap_target 0 +// #define origin_overwrite_simple_wrap 1 +// #define origin_overwrite_simple_pio_version 0 +// +// static __pio_const uint16_t origin_overwrite_simple_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_overwrite_simple_program = { +// .instructions = origin_overwrite_simple_program_instructions, +// .length = 2, +// .origin = 10, +// .pio_version = origin_overwrite_simple_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_overwrite_simple_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_overwrite_simple_wrap_target, offset + origin_overwrite_simple_wrap); +// return c; +// } +// #endif +// +// // ------------------------- // +// // origin_overwrite_multiple // +// // ------------------------- // +// +// #define origin_overwrite_multiple_wrap_target 0 +// #define origin_overwrite_multiple_wrap 0 +// #define origin_overwrite_multiple_pio_version 0 +// +// static __pio_const uint16_t origin_overwrite_multiple_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program origin_overwrite_multiple_program = { +// .instructions = origin_overwrite_multiple_program_instructions, +// .length = 1, +// .origin = 20, +// .pio_version = origin_overwrite_multiple_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config origin_overwrite_multiple_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + origin_overwrite_multiple_wrap_target, offset + origin_overwrite_multiple_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/edge/test_wrap_edge_cases_valid.pio b/tools/pioasm/test/valid/edge/test_wrap_edge_cases_valid.pio new file mode 100644 index 000000000..a7e149869 --- /dev/null +++ b/tools/pioasm/test/valid/edge/test_wrap_edge_cases_valid.pio @@ -0,0 +1,313 @@ +// run: pioasm input.pio +// Test edge cases for wrap behavior + +.program wrap_single_instruction +.wrap_target + nop +.wrap + +.program wrap_last_instruction + nop + nop +.wrap_target + nop +.wrap + +.program wrap_entire_program +.wrap_target + nop + nop + nop + nop +.wrap + +.program wrap_skip_first + nop ; This instruction executes once, then never again +.wrap_target + nop + nop +.wrap + +.program wrap_skip_last +.wrap_target + nop + nop +.wrap + nop ; This instruction never executes in normal flow + +.program wrap_with_jmp_outside +.wrap_target + jmp outside + nop +.wrap +outside: + nop ; Can jump here but won't wrap back + +.program wrap_nested_loops +.wrap_target +loop1: + jmp x-- loop1 ; Inner loop + jmp loop2 ; Outer loop +loop2: + nop +.wrap + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------------------- // +// // wrap_single_instruction // +// // ----------------------- // +// +// #define wrap_single_instruction_wrap_target 0 +// #define wrap_single_instruction_wrap 0 +// #define wrap_single_instruction_pio_version 0 +// +// static __pio_const uint16_t wrap_single_instruction_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_single_instruction_program = { +// .instructions = wrap_single_instruction_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = wrap_single_instruction_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_single_instruction_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_single_instruction_wrap_target, offset + wrap_single_instruction_wrap); +// return c; +// } +// #endif +// +// // --------------------- // +// // wrap_last_instruction // +// // --------------------- // +// +// #define wrap_last_instruction_wrap_target 2 +// #define wrap_last_instruction_wrap 2 +// #define wrap_last_instruction_pio_version 0 +// +// static __pio_const uint16_t wrap_last_instruction_program_instructions[] = { +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// // .wrap_target +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_last_instruction_program = { +// .instructions = wrap_last_instruction_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = wrap_last_instruction_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_last_instruction_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_last_instruction_wrap_target, offset + wrap_last_instruction_wrap); +// return c; +// } +// #endif +// +// // ------------------- // +// // wrap_entire_program // +// // ------------------- // +// +// #define wrap_entire_program_wrap_target 0 +// #define wrap_entire_program_wrap 3 +// #define wrap_entire_program_pio_version 0 +// +// static __pio_const uint16_t wrap_entire_program_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// 0xa042, // 3: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_entire_program_program = { +// .instructions = wrap_entire_program_program_instructions, +// .length = 4, +// .origin = -1, +// .pio_version = wrap_entire_program_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_entire_program_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_entire_program_wrap_target, offset + wrap_entire_program_wrap); +// return c; +// } +// #endif +// +// // --------------- // +// // wrap_skip_first // +// // --------------- // +// +// #define wrap_skip_first_wrap_target 1 +// #define wrap_skip_first_wrap 2 +// #define wrap_skip_first_pio_version 0 +// +// static __pio_const uint16_t wrap_skip_first_program_instructions[] = { +// 0xa042, // 0: nop +// // .wrap_target +// 0xa042, // 1: nop +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_skip_first_program = { +// .instructions = wrap_skip_first_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = wrap_skip_first_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_skip_first_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_skip_first_wrap_target, offset + wrap_skip_first_wrap); +// return c; +// } +// #endif +// +// // -------------- // +// // wrap_skip_last // +// // -------------- // +// +// #define wrap_skip_last_wrap_target 0 +// #define wrap_skip_last_wrap 1 +// #define wrap_skip_last_pio_version 0 +// +// static __pio_const uint16_t wrap_skip_last_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// 0xa042, // 1: nop +// // .wrap +// 0xa042, // 2: nop +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_skip_last_program = { +// .instructions = wrap_skip_last_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = wrap_skip_last_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_skip_last_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_skip_last_wrap_target, offset + wrap_skip_last_wrap); +// return c; +// } +// #endif +// +// // --------------------- // +// // wrap_with_jmp_outside // +// // --------------------- // +// +// #define wrap_with_jmp_outside_wrap_target 0 +// #define wrap_with_jmp_outside_wrap 1 +// #define wrap_with_jmp_outside_pio_version 0 +// +// static __pio_const uint16_t wrap_with_jmp_outside_program_instructions[] = { +// // .wrap_target +// 0x0002, // 0: jmp 2 +// 0xa042, // 1: nop +// // .wrap +// 0xa042, // 2: nop +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_with_jmp_outside_program = { +// .instructions = wrap_with_jmp_outside_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = wrap_with_jmp_outside_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_with_jmp_outside_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_with_jmp_outside_wrap_target, offset + wrap_with_jmp_outside_wrap); +// return c; +// } +// #endif +// +// // ----------------- // +// // wrap_nested_loops // +// // ----------------- // +// +// #define wrap_nested_loops_wrap_target 0 +// #define wrap_nested_loops_wrap 2 +// #define wrap_nested_loops_pio_version 0 +// +// static __pio_const uint16_t wrap_nested_loops_program_instructions[] = { +// // .wrap_target +// 0x0040, // 0: jmp x--, 0 +// 0x0002, // 1: jmp 2 +// 0xa042, // 2: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program wrap_nested_loops_program = { +// .instructions = wrap_nested_loops_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = wrap_nested_loops_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config wrap_nested_loops_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + wrap_nested_loops_wrap_target, offset + wrap_nested_loops_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/expressions/test_define_supported_values_valid.pio b/tools/pioasm/test/valid/expressions/test_define_supported_values_valid.pio new file mode 100644 index 000000000..239f4dec4 --- /dev/null +++ b/tools/pioasm/test/valid/expressions/test_define_supported_values_valid.pio @@ -0,0 +1,91 @@ +// run: pioasm input.pio +.program define_values +.define PUBLIC literal_val 7 +.define base_val 6 +.define PUBLIC ref_val base_val +.define PUBLIC add_val 10 + 5 +.define PUBLIC sub_val 20 - 3 +.define PUBLIC mul_val 3 * 5 +.define PUBLIC div_val 20 / 4 +.define PUBLIC or_val 0x3 | 0x4 +.define PUBLIC and_val 0x7 & 0x3 +.define PUBLIC xor_val 0x6 ^ 0x3 +.define PUBLIC shl_val 1 << 4 +.define PUBLIC shr_val 16 >> 2 +.define PUBLIC neg_val -5 +.define PUBLIC rev_val ::1 +.define PUBLIC paren_val (10 + 5) * 2 +.define * star_val 9 +start: + nop + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------- // +// // define_values // +// // ------------- // +// +// #define define_values_wrap_target 0 +// #define define_values_wrap 0 +// #define define_values_pio_version 0 +// +// #define define_values_literal_val 7 +// #define define_values_ref_val 6 +// #define define_values_add_val 15 +// #define define_values_sub_val 17 +// #define define_values_mul_val 15 +// #define define_values_div_val 5 +// #define define_values_or_val 7 +// #define define_values_and_val 3 +// #define define_values_xor_val 5 +// #define define_values_shl_val 16 +// #define define_values_shr_val 4 +// #define define_values_neg_val -5 +// #define define_values_rev_val -2147483648 +// #define define_values_paren_val 30 +// #define define_values_star_val 9 +// +// static __pio_const uint16_t define_values_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program define_values_program = { +// .instructions = define_values_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = define_values_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config define_values_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + define_values_wrap_target, offset + define_values_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/expressions/test_expressions_arithmetic_valid.pio b/tools/pioasm/test/valid/expressions/test_expressions_arithmetic_valid.pio new file mode 100644 index 000000000..6781573ff --- /dev/null +++ b/tools/pioasm/test/valid/expressions/test_expressions_arithmetic_valid.pio @@ -0,0 +1,66 @@ +// run: pioasm input.pio +.program expr_arith +.define a 10 +.define b 2 + set pins, (a + b) + set pins, (a - b) + set pins, (a * b) + set pins, (a / b) + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------- // +// // expr_arith // +// // ---------- // +// +// #define expr_arith_wrap_target 0 +// #define expr_arith_wrap 3 +// #define expr_arith_pio_version 0 +// +// static __pio_const uint16_t expr_arith_program_instructions[] = { +// // .wrap_target +// 0xe00c, // 0: set pins, 12 +// 0xe008, // 1: set pins, 8 +// 0xe014, // 2: set pins, 20 +// 0xe005, // 3: set pins, 5 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program expr_arith_program = { +// .instructions = expr_arith_program_instructions, +// .length = 4, +// .origin = -1, +// .pio_version = expr_arith_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config expr_arith_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + expr_arith_wrap_target, offset + expr_arith_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/expressions/test_expressions_bitwise_valid.pio b/tools/pioasm/test/valid/expressions/test_expressions_bitwise_valid.pio new file mode 100644 index 000000000..cd357de2f --- /dev/null +++ b/tools/pioasm/test/valid/expressions/test_expressions_bitwise_valid.pio @@ -0,0 +1,68 @@ +// run: pioasm input.pio +.program expr_bitwise +.define a 0x3 +.define b 0x5 + set pins, (a | b) + set pins, (a & b) + set pins, (a ^ b) + set pins, (1 << 4) + set pins, (16 >> 2) + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------ // +// // expr_bitwise // +// // ------------ // +// +// #define expr_bitwise_wrap_target 0 +// #define expr_bitwise_wrap 4 +// #define expr_bitwise_pio_version 0 +// +// static __pio_const uint16_t expr_bitwise_program_instructions[] = { +// // .wrap_target +// 0xe007, // 0: set pins, 7 +// 0xe001, // 1: set pins, 1 +// 0xe006, // 2: set pins, 6 +// 0xe010, // 3: set pins, 16 +// 0xe004, // 4: set pins, 4 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program expr_bitwise_program = { +// .instructions = expr_bitwise_program_instructions, +// .length = 5, +// .origin = -1, +// .pio_version = expr_bitwise_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config expr_bitwise_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + expr_bitwise_wrap_target, offset + expr_bitwise_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/expressions/test_expressions_complex_valid.pio b/tools/pioasm/test/valid/expressions/test_expressions_complex_valid.pio new file mode 100644 index 000000000..ca989fbae --- /dev/null +++ b/tools/pioasm/test/valid/expressions/test_expressions_complex_valid.pio @@ -0,0 +1,64 @@ +// run: pioasm input.pio +.program expr_complex +.define a 3 +.define b 5 +.define c 2 +.define d 1 + set pins, ((a + b) * (c - d)) + set pins, ((a + b + c) >> d) + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------ // +// // expr_complex // +// // ------------ // +// +// #define expr_complex_wrap_target 0 +// #define expr_complex_wrap 1 +// #define expr_complex_pio_version 0 +// +// static __pio_const uint16_t expr_complex_program_instructions[] = { +// // .wrap_target +// 0xe008, // 0: set pins, 8 +// 0xe005, // 1: set pins, 5 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program expr_complex_program = { +// .instructions = expr_complex_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = expr_complex_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config expr_complex_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + expr_complex_wrap_target, offset + expr_complex_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/expressions/test_expressions_unary_valid.pio b/tools/pioasm/test/valid/expressions/test_expressions_unary_valid.pio new file mode 100644 index 000000000..3e59a9230 --- /dev/null +++ b/tools/pioasm/test/valid/expressions/test_expressions_unary_valid.pio @@ -0,0 +1,63 @@ +// run: pioasm input.pio +.program unary_test +.define PUBLIC neg_val -5 +.define PUBLIC rev_val ::1 +start: + nop +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------- // +// // unary_test // +// // ---------- // +// +// #define unary_test_wrap_target 0 +// #define unary_test_wrap 0 +// #define unary_test_pio_version 0 +// +// #define unary_test_neg_val -5 +// #define unary_test_rev_val -2147483648 +// +// static __pio_const uint16_t unary_test_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program unary_test_program = { +// .instructions = unary_test_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = unary_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config unary_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + unary_test_wrap_target, offset + unary_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/expressions/test_symbols_and_defines_valid.pio b/tools/pioasm/test/valid/expressions/test_symbols_and_defines_valid.pio new file mode 100644 index 000000000..90ca9dcbf --- /dev/null +++ b/tools/pioasm/test/valid/expressions/test_symbols_and_defines_valid.pio @@ -0,0 +1,69 @@ +// run: pioasm input.pio +.program symbol_test +.define PUBLIC entry_point 0 +.define local_const 2 +start: + jmp middle +middle: + jmp end +end: + jmp start + +// -- Output +// Command: pioasm input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------- // +// // symbol_test // +// // ----------- // +// +// #define symbol_test_wrap_target 0 +// #define symbol_test_wrap 2 +// #define symbol_test_pio_version 0 +// +// #define symbol_test_entry_point 0 +// +// static __pio_const uint16_t symbol_test_program_instructions[] = { +// // .wrap_target +// 0x0001, // 0: jmp 1 +// 0x0002, // 1: jmp 2 +// 0x0000, // 2: jmp 0 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program symbol_test_program = { +// .instructions = symbol_test_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = symbol_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config symbol_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + symbol_test_wrap_target, offset + symbol_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_ada_symbols_lang_opt_valid.pio b/tools/pioasm/test/valid/output/test_output_ada_symbols_lang_opt_valid.pio new file mode 100644 index 000000000..808083202 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_ada_symbols_lang_opt_valid.pio @@ -0,0 +1,44 @@ +// run: pioasm -o ada -p AdaPkg input.pio +.define PUBLIC global_const 5 +.program ada_symbols +.lang_opt ada custom_opt = 3 +.define PUBLIC local_const 6 +public entry: + nop +// -- Output +// Command: pioasm -o ada -p AdaPkg input.pio +// Exit code: 0 +// Stdout: +// ------------------------------------------------------------------------------ +//? +// ------------------------------------------------------------------------------ +// +// pragma Style_Checks (Off); +// +// with RP.PIO; +// +// package AdaPkg is +// +// ----------------- +// -- Ada_Symbols -- +// ----------------- +// +// global_const : constant := 5; +// +// Ada_Symbols_Wrap_Target : constant := 0; +// Ada_Symbols_Wrap : constant := 0; +// +// local_const : constant := 6; +// +// Offset_entry : constant := 0; +// +// Ada_Symbols_Program_Instructions : RP.PIO.Program := ( +// -- .wrap_target +// 16#a042#); -- 0: nop +// -- .wrap +// +// end AdaPkg; +// +// Stderr: +// warning: ada does not support output options; ada lang_opt ignored. +// diff --git a/tools/pioasm/test/valid/output/test_output_ada_valid.pio b/tools/pioasm/test/valid/output/test_output_ada_valid.pio new file mode 100644 index 000000000..36863a8a5 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_ada_valid.pio @@ -0,0 +1,33 @@ +// run: pioasm -o ada -p format_test input.pio +.program format_test + nop + +// -- Output +// Command: pioasm -o ada -p format_test input.pio +// Exit code: 0 +// Stdout: +// ------------------------------------------------------------------------------ +//? +// ------------------------------------------------------------------------------ +// +// pragma Style_Checks (Off); +// +// with RP.PIO; +// +// package format_test is +// +// ----------------- +// -- Format_Test -- +// ----------------- +// +// Format_Test_Wrap_Target : constant := 0; +// Format_Test_Wrap : constant := 0; +// +// Format_Test_Program_Instructions : RP.PIO.Program := ( +// -- .wrap_target +// 16#a042#); -- 0: nop +// -- .wrap +// +// end format_test; +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_c_sdk_code_block_valid.pio b/tools/pioasm/test/valid/output/test_output_c_sdk_code_block_valid.pio new file mode 100644 index 000000000..9432bd3bf --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_c_sdk_code_block_valid.pio @@ -0,0 +1,65 @@ +// run: pioasm -o c-sdk input.pio +.program code_block_program +% c-sdk { +// custom code block line +#define CODE_BLOCK_VALUE 7 +%} + nop +// -- Output +// Command: pioasm -o c-sdk input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------------ // +// // code_block_program // +// // ------------------ // +// +// #define code_block_program_wrap_target 0 +// #define code_block_program_wrap 0 +// #define code_block_program_pio_version 0 +// +// static __pio_const uint16_t code_block_program_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program code_block_program_program = { +// .instructions = code_block_program_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = code_block_program_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config code_block_program_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + code_block_program_wrap_target, offset + code_block_program_wrap); +// return c; +// } +// +// // custom code block line +// #define CODE_BLOCK_VALUE 7 +// +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_c_sdk_fifo_join_v1_valid.pio b/tools/pioasm/test/valid/output/test_output_c_sdk_fifo_join_v1_valid.pio new file mode 100644 index 000000000..c75a3b128 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_c_sdk_fifo_join_v1_valid.pio @@ -0,0 +1,136 @@ +// run: pioasm -o c-sdk input.pio +.program fifo_txput +.pio_version 1 +.fifo txput + nop + +.program fifo_txget +.pio_version 1 +.fifo txget + nop + +.program fifo_putget +.pio_version 1 +.fifo putget + nop +// -- Output +// Command: pioasm -o c-sdk input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ---------- // +// // fifo_txput // +// // ---------- // +// +// #define fifo_txput_wrap_target 0 +// #define fifo_txput_wrap 0 +// #define fifo_txput_pio_version 1 +// +// static __pio_const uint16_t fifo_txput_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_txput_program = { +// .instructions = fifo_txput_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_txput_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_txput_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_txput_wrap_target, offset + fifo_txput_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TXPUT); +// return c; +// } +// #endif +// +// // ---------- // +// // fifo_txget // +// // ---------- // +// +// #define fifo_txget_wrap_target 0 +// #define fifo_txget_wrap 0 +// #define fifo_txget_pio_version 1 +// +// static __pio_const uint16_t fifo_txget_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_txget_program = { +// .instructions = fifo_txget_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_txget_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_txget_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_txget_wrap_target, offset + fifo_txget_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TXGET); +// return c; +// } +// #endif +// +// // ----------- // +// // fifo_putget // +// // ----------- // +// +// #define fifo_putget_wrap_target 0 +// #define fifo_putget_wrap 0 +// #define fifo_putget_pio_version 1 +// +// static __pio_const uint16_t fifo_putget_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_putget_program = { +// .instructions = fifo_putget_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = fifo_putget_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_putget_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_putget_wrap_target, offset + fifo_putget_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_PUTGET); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_c_sdk_valid.pio b/tools/pioasm/test/valid/output/test_output_c_sdk_valid.pio new file mode 100644 index 000000000..0702bf396 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_c_sdk_valid.pio @@ -0,0 +1,58 @@ +// run: pioasm -o c-sdk input.pio +.program format_test + nop + +// -- Output +// Command: pioasm -o c-sdk input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ----------- // +// // format_test // +// // ----------- // +// +// #define format_test_wrap_target 0 +// #define format_test_wrap 0 +// #define format_test_pio_version 0 +// +// static __pio_const uint16_t format_test_program_instructions[] = { +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program format_test_program = { +// .instructions = format_test_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = format_test_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config format_test_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + format_test_wrap_target, offset + format_test_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_go_symbols_valid.pio b/tools/pioasm/test/valid/output/test_output_go_symbols_valid.pio new file mode 100644 index 000000000..49283f033 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_go_symbols_valid.pio @@ -0,0 +1,40 @@ +// run: pioasm -o go input.pio +.define PUBLIC global_const 7 +.program format_test +public entry: + nop +%go { +package pioasmtest +// Custom Go block +%} +// -- Output +// Command: pioasm -o go input.pio +// Exit code: 0 +// Stdout: +//? +// +// package pioasmtest +// // Custom Go block +// // format_test +// +// const format_testWrapTarget = 0 +// const format_testWrap = 0 +// +// const format_testoffset_entry = 0 +// +// var format_testInstructions = []uint16{ +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// } +// const format_testOrigin = -1 +// func format_testProgramDefaultConfig(offset uint8) pio.StateMachineConfig { +// cfg := pio.DefaultStateMachineConfig() +// cfg.SetWrap(offset+format_testWrapTarget, offset+format_testWrap) +// return cfg; +// } +// +// const global_const = 7 +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_go_valid.pio b/tools/pioasm/test/valid/output/test_output_go_valid.pio new file mode 100644 index 000000000..3ef0154bc --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_go_valid.pio @@ -0,0 +1,29 @@ +// run: pioasm -o go input.pio +.program format_test + nop + +// -- Output +// Command: pioasm -o go input.pio +// Exit code: 0 +// Stdout: +//? +// +// // format_test +// +// const format_testWrapTarget = 0 +// const format_testWrap = 0 +// +// var format_testInstructions = []uint16{ +// // .wrap_target +// 0xa042, // 0: nop +// // .wrap +// } +// const format_testOrigin = -1 +// func format_testProgramDefaultConfig(offset uint8) pio.StateMachineConfig { +// cfg := pio.DefaultStateMachineConfig() +// cfg.SetWrap(offset+format_testWrapTarget, offset+format_testWrap) +// return cfg; +// } +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_hex_valid.pio b/tools/pioasm/test/valid/output/test_output_hex_valid.pio new file mode 100644 index 000000000..b7e6d2de8 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_hex_valid.pio @@ -0,0 +1,11 @@ +// run: pioasm -o hex input.pio +.program format_test + nop + +// -- Output +// Command: pioasm -o hex input.pio +// Exit code: 0 +// Stdout: +// a042 +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_json_full_valid.pio b/tools/pioasm/test/valid/output/test_output_json_full_valid.pio new file mode 100644 index 000000000..e29bbb2f3 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_json_full_valid.pio @@ -0,0 +1,142 @@ +// run: pioasm -o json input.pio +.define PUBLIC global_const 7 +.program format_test +.origin 4 +.side_set 2 opt pindirs +.define PUBLIC prog_const 3 +public entry: +.wrap_target + nop side 1 +.wrap + +.lang_opt lang1 opt1 = "this is a test 1" +.lang_opt lang2 opt1 = "this is a test 2" +.lang_opt lang1 opt2 = test_3 +.lang_opt lang1 opt2 = test_4 + +% lang1 { + foo +%} + +% lang2 { + bar +%} + +% lang1 { + foobar +%} + +.lang_opt lang1 opt3 = test_5 + +.program second_prog + nop +// -- Output +// Command: pioasm -o json input.pio +// Exit code: 0 +// Stdout: +// { +// "pioASMVersion": "2.2.1-develop", +// "publicSymbols": { +// "global_const": 7 +// }, +// "programs": [ +// { +// "name": "format_test", +// "pioVersion": 0, +// "wrapTarget": 0, +// "wrap": 0, +// "origin": 4, +// "usedGPIORanges": 0, +// "publicSymbols": { +// "prog_const": 3 +// }, +// "publicLabels": { +// "entry": 0 +// }, +// "in": null, +// "out": null, +// "setCount": null, +// "sideset": {"size": 3, "optional": true, "pindirs": true}, +// "movStatus": null, +// "fifoConfig": null, +// "clockDiv": null, +// "instructions": [ +// {"hex": "B442", "instruction": "nop side 1"} +// ], +// "codeBlocks": [ +// { +// "lang": "lang1", +// "contents": " foo\n" +// }, +// { +// "lang": "lang1", +// "contents": " foobar\n" +// }, +// { +// "lang": "lang2", +// "contents": " bar\n" +// } +// ], +// "langOpts": [ +// { +// "lang": "lang1", +// "name": "opt1", +// "value": "\"this is a test 1\"" +// }, +// { +// "lang": "lang1", +// "name": "opt2", +// "value": "test_3" +// }, +// { +// "lang": "lang1", +// "name": "opt2", +// "value": "test_4" +// }, +// { +// "lang": "lang1", +// "name": "opt3", +// "value": "test_5" +// }, +// { +// "lang": "lang2", +// "name": "opt1", +// "value": "\"this is a test 2\"" +// } +// ] +// }, +// { +// "name": "second_prog", +// "pioVersion": 0, +// "wrapTarget": 0, +// "wrap": 0, +// "origin": -1, +// "usedGPIORanges": 0, +// "publicSymbols": { +// }, +// "publicLabels": { +// }, +// "in": null, +// "out": null, +// "setCount": null, +// "sideset": null, +// "movStatus": null, +// "fifoConfig": null, +// "clockDiv": null, +// "instructions": [ +// {"hex": "A042", "instruction": "nop"} +// ], +// "codeBlocks": [ +// +// ], +// "langOpts": [ +// +// ] +// } +// ] +// } +// +// Stderr: +// input.pio:17.1-19.2: warning, unknown code block output type 'lang1' +// input.pio:21.1-23.2: warning, unknown code block output type 'lang2' +// diff --git a/tools/pioasm/test/valid/output/test_output_json_lang_opt_valid.pio b/tools/pioasm/test/valid/output/test_output_json_lang_opt_valid.pio new file mode 100644 index 000000000..3cf2e5e62 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_json_lang_opt_valid.pio @@ -0,0 +1,93 @@ +// run: pioasm -o json input.pio +.define public GLOBAL_CONST 2 +.program json_cov +.pio_version 1 +.lang_opt json some_option = 1 +.side_set 2 opt pindirs +.define public LOCAL_CONST 3 +public entry: + nop side 0 + jmp entry + +.program json_no_sideset +.origin 5 + nop +// -- Output +// Command: pioasm -o json input.pio +// Exit code: 0 +// Stdout: +// { +// "pioASMVersion": "2.2.1-develop", +// "publicSymbols": { +// "GLOBAL_CONST": 2 +// }, +// "programs": [ +// { +// "name": "json_cov", +// "pioVersion": 1, +// "wrapTarget": 0, +// "wrap": 1, +// "origin": -1, +// "usedGPIORanges": 0, +// "publicSymbols": { +// "LOCAL_CONST": 3 +// }, +// "publicLabels": { +// "entry": 0 +// }, +// "in": null, +// "out": null, +// "setCount": null, +// "sideset": {"size": 3, "optional": true, "pindirs": true}, +// "movStatus": null, +// "fifoConfig": null, +// "clockDiv": null, +// "instructions": [ +// {"hex": "B042", "instruction": "nop side 0"}, +// {"hex": "0000", "instruction": "jmp 0"} +// ], +// "codeBlocks": [ +// +// ], +// "langOpts": [ +// { +// "lang": "json", +// "name": "some_option", +// "value": "1" +// } +// ] +// }, +// { +// "name": "json_no_sideset", +// "pioVersion": 0, +// "wrapTarget": 0, +// "wrap": 0, +// "origin": 5, +// "usedGPIORanges": 0, +// "publicSymbols": { +// }, +// "publicLabels": { +// }, +// "in": null, +// "out": null, +// "setCount": null, +// "sideset": null, +// "movStatus": null, +// "fifoConfig": null, +// "clockDiv": null, +// "instructions": [ +// {"hex": "A042", "instruction": "nop"} +// ], +// "codeBlocks": [ +// +// ], +// "langOpts": [ +// +// ] +// } +// ] +// } +// +// Stderr: +// warning: json does not support output options; json lang_opt ignored. +// diff --git a/tools/pioasm/test/valid/output/test_output_json_symbols_valid.pio b/tools/pioasm/test/valid/output/test_output_json_symbols_valid.pio new file mode 100644 index 000000000..8c60c50eb --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_json_symbols_valid.pio @@ -0,0 +1,55 @@ +// run: pioasm -o json input.pio +.define PUBLIC global_const 7 +.program format_test +public entry: + nop +.lang_opt json foo = 1 +// -- Output +// Command: pioasm -o json input.pio +// Exit code: 0 +// Stdout: +// { +// "pioASMVersion": "2.2.1-develop", +// "publicSymbols": { +// "global_const": 7 +// }, +// "programs": [ +// { +// "name": "format_test", +// "pioVersion": 0, +// "wrapTarget": 0, +// "wrap": 0, +// "origin": -1, +// "usedGPIORanges": 0, +// "publicSymbols": { +// }, +// "publicLabels": { +// "entry": 0 +// }, +// "in": null, +// "out": null, +// "setCount": null, +// "sideset": null, +// "movStatus": null, +// "fifoConfig": null, +// "clockDiv": null, +// "instructions": [ +// {"hex": "A042", "instruction": "nop"} +// ], +// "codeBlocks": [ +// +// ], +// "langOpts": [ +// { +// "lang": "json", +// "name": "foo", +// "value": "1" +// } +// ] +// } +// ] +// } +// +// Stderr: +// warning: json does not support output options; json lang_opt ignored. +// diff --git a/tools/pioasm/test/valid/output/test_output_json_valid.pio b/tools/pioasm/test/valid/output/test_output_json_valid.pio new file mode 100644 index 000000000..77a78e4d3 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_json_valid.pio @@ -0,0 +1,45 @@ +// run: pioasm -o json input.pio +.program format_test + nop + +// -- Output +// Command: pioasm -o json input.pio +// Exit code: 0 +// Stdout: +// { +// "pioASMVersion": "2.2.1-develop", +// "publicSymbols": { +// }, +// "programs": [ +// { +// "name": "format_test", +// "pioVersion": 0, +// "wrapTarget": 0, +// "wrap": 0, +// "origin": -1, +// "usedGPIORanges": 0, +// "publicSymbols": { +// }, +// "publicLabels": { +// }, +// "in": null, +// "out": null, +// "setCount": null, +// "sideset": null, +// "movStatus": null, +// "fifoConfig": null, +// "clockDiv": null, +// "instructions": [ +// {"hex": "A042", "instruction": "nop"} +// ], +// "codeBlocks": [ +// +// ], +// "langOpts": [ +// +// ] +// } +// ] +// } +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_python_full_valid.pio b/tools/pioasm/test/valid/output/test_output_python_full_valid.pio new file mode 100644 index 000000000..1c11a0ee4 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_python_full_valid.pio @@ -0,0 +1,129 @@ +// run: pioasm -o python input.pio +.program python_full +.pio_version 1 +.define PUBLIC global_const 9 +public entry: + jmp entry + jmp x--, entry + wait 0 gpio, 2 + wait 1 pin, 3 + wait 0 irq, 4 + wait 1 irq, 5 rel + in pins, 32 + in x, 1 + in y, 2 + in null, 3 + in status, 4 + in isr, 5 + in osr, 6 + out pins, 32 + out x, 1 + out y, 2 + out null, 3 + out pindirs, 4 + out pc, 5 + out isr, 6 + out exec, 7 + +.program python_full_b +.pio_version 1 +.define PUBLIC local_const 11 +public start: + push + push iffull + push iffull block + pull + pull ifempty + pull ifempty block + mov x, y + mov x, ~y + mov x, ::y + irq 1 + irq set 2 + irq clear 3 + irq wait 4 + irq 5 rel + set pins, 1 + set x, 2 + set y, 3 + set pindirs, 4 +// -- Output +// Command: pioasm -o python input.pio +// Exit code: 0 +// Stdout: +// # ------------------------------------------------------------------------ # +// # This file is autogenerated by pioasm version 2.2.1-develop; do not edit! # +// # ------------------------------------------------------------------------ # +// +// import rp2 +// from machine import Pin +// # ----------- # +// # python_full # +// # ----------- # +// +// python_full_global_const = 9 +// +// python_full_offset_entry = 0 +// +// @rp2.asm_pio() +// def python_full(): +// wrap_target() +// label("0") +// jmp("0") # 0 +// jmp(x_dec, "0") # 1 +// wait(0, gpio, 2) # 2 +// wait(1, pin, 3) # 3 +// wait(0, irq, 4) # 4 +// wait(1, irq, rel(5)) # 5 +// in_(pins, 32) # 6 +// in_(x, 1) # 7 +// in_(y, 2) # 8 +// in_(null, 3) # 9 +// in_(status, 4) # 10 +// in_(isr, 5) # 11 +// in_(osr, 6) # 12 +// out(pins, 32) # 13 +// out(x, 1) # 14 +// out(y, 2) # 15 +// out(null, 3) # 16 +// out(pindirs, 4) # 17 +// out(pc, 5) # 18 +// out(isr, 6) # 19 +// out(exec, 7) # 20 +// wrap() +// +// +// # ------------- # +// # python_full_b # +// # ------------- # +// +// python_full_b_local_const = 11 +// +// python_full_b_offset_start = 0 +// +// @rp2.asm_pio() +// def python_full_b(): +// wrap_target() +// push(block) # 0 +// push(iffull, block) # 1 +// push(iffull, block) # 2 +// pull(block) # 3 +// pull(ifempty, block) # 4 +// pull(ifempty, block) # 5 +// mov(x, y) # 6 +// mov(x, invert(y)) # 7 +// mov(x, reverse(y)) # 8 +// irq(1) # 9 +// irq(2) # 10 +// irq(clear, 3) # 11 +// irq(block, 4) # 12 +// irq(rel(5)) # 13 +// set(pins, 1) # 14 +// set(x, 2) # 15 +// set(y, 3) # 16 +// set(pindirs, 4) # 17 +// wrap() +// +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_python_lang_opts_valid.pio b/tools/pioasm/test/valid/output/test_output_python_lang_opts_valid.pio new file mode 100644 index 000000000..2419c6c29 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_python_lang_opts_valid.pio @@ -0,0 +1,52 @@ +// run: pioasm -o python input.pio +.define PUBLIC global_const 1 +.program python_opts +.pio_version 1 +.side_set 1 opt +.lang_opt python out_shiftdir = 1 +.lang_opt python autopull = 1 +.define PUBLIC local_const 2 +.wrap_target +public entry: + nop side 1 + jmp entry + .word 0xffff +.wrap +%python { +# python block for output +%} +// -- Output +// Command: pioasm -o python input.pio +// Exit code: 0 +// Stdout: +// # ------------------------------------------------------------------------ # +//? +// # ------------------------------------------------------------------------ # +// +// import rp2 +// from machine import Pin +// global_const = 1 +// +// # ----------- # +// # python_opts # +// # ----------- # +// +// python_opts_local_const = 2 +// +// python_opts_offset_entry = 0 +// +// @rp2.asm_pio(out_shiftdir=1, autopull=1) +// def python_opts(): +// wrap_target() +// label("0") +// nop() .side(1) # 0 +// jmp("0") # 1 +// word(0xffff) .side(1) [7] # 2 +// wrap() +// +// +// # python block for output +// +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_python_symbols_valid.pio b/tools/pioasm/test/valid/output/test_output_python_symbols_valid.pio new file mode 100644 index 000000000..088696d4e --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_python_symbols_valid.pio @@ -0,0 +1,39 @@ +// run: pioasm -o python input.pio +.define PUBLIC global_const 7 +.program format_test +public entry: + nop +.lang_opt python in_shiftdir = right +%python { +# Custom python block +%} +// -- Output +// Command: pioasm -o python input.pio +// Exit code: 0 +// Stdout: +// # ------------------------------------------------------------------------ # +//? +// # ------------------------------------------------------------------------ # +// +// import rp2 +// from machine import Pin +// global_const = 7 +// +// # ----------- # +// # format_test # +// # ----------- # +// +// format_test_offset_entry = 0 +// +// @rp2.asm_pio(in_shiftdir=right) +// def format_test(): +// wrap_target() +// nop() # 0 +// wrap() +// +// +// # Custom python block +// +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/output/test_output_python_valid.pio b/tools/pioasm/test/valid/output/test_output_python_valid.pio new file mode 100644 index 000000000..c8fe2fc55 --- /dev/null +++ b/tools/pioasm/test/valid/output/test_output_python_valid.pio @@ -0,0 +1,27 @@ +// run: pioasm -o python input.pio +.program format_test + nop + +// -- Output +// Command: pioasm -o python input.pio +// Exit code: 0 +// Stdout: +// # ------------------------------------------------------------------------ # +//? +// # ------------------------------------------------------------------------ # +// +// import rp2 +// from machine import Pin +// # ----------- # +// # format_test # +// # ----------- # +// +// @rp2.asm_pio() +// def format_test(): +// wrap_target() +// nop() # 0 +// wrap() +// +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/pio_version/test_pio_v0_features_valid.pio b/tools/pioasm/test/valid/pio_version/test_pio_v0_features_valid.pio new file mode 100644 index 000000000..e91224d74 --- /dev/null +++ b/tools/pioasm/test/valid/pio_version/test_pio_v0_features_valid.pio @@ -0,0 +1,59 @@ +// run: pioasm -v 0 input.pio +.program pio_v0_basic +.pio_version 0 + wait 0 gpio 7 + +// -- Output +// Command: pioasm -v 0 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------------ // +// // pio_v0_basic // +// // ------------ // +// +// #define pio_v0_basic_wrap_target 0 +// #define pio_v0_basic_wrap 0 +// #define pio_v0_basic_pio_version 0 +// +// static __pio_const uint16_t pio_v0_basic_program_instructions[] = { +// // .wrap_target +// 0x2007, // 0: wait 0 gpio, 7 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pio_v0_basic_program = { +// .instructions = pio_v0_basic_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = pio_v0_basic_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x1 +// #endif +// }; +// +// static inline pio_sm_config pio_v0_basic_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pio_v0_basic_wrap_target, offset + pio_v0_basic_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/pio_version/test_pio_v1_features_valid.pio b/tools/pioasm/test/valid/pio_version/test_pio_v1_features_valid.pio new file mode 100644 index 000000000..22e35b961 --- /dev/null +++ b/tools/pioasm/test/valid/pio_version/test_pio_v1_features_valid.pio @@ -0,0 +1,67 @@ +// run: pioasm -v 1 input.pio +.program pio_v1_features +.pio_version 1 + wait 0 jmppin + wait 1 jmppin + 2 + irq next 0 + irq prev 0 + mov pindirs, x + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // --------------- // +// // pio_v1_features // +// // --------------- // +// +// #define pio_v1_features_wrap_target 0 +// #define pio_v1_features_wrap 4 +// #define pio_v1_features_pio_version 1 +// +// static __pio_const uint16_t pio_v1_features_program_instructions[] = { +// // .wrap_target +// 0x2060, // 0: wait 0 jmppin +// 0x20e2, // 1: wait 1 jmppin + 2 +// 0xc018, // 2: irq next nowait 0 +// 0xc008, // 3: irq prev nowait 0 +// 0xa061, // 4: mov pindirs, x +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program pio_v1_features_program = { +// .instructions = pio_v1_features_program_instructions, +// .length = 5, +// .origin = -1, +// .pio_version = pio_v1_features_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config pio_v1_features_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + pio_v1_features_wrap_target, offset + pio_v1_features_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/pio_version/test_pio_v1_fifo_valid.pio b/tools/pioasm/test/valid/pio_version/test_pio_v1_fifo_valid.pio new file mode 100644 index 000000000..c98c7c65f --- /dev/null +++ b/tools/pioasm/test/valid/pio_version/test_pio_v1_fifo_valid.pio @@ -0,0 +1,144 @@ +// run: pioasm -v 1 input.pio +.program fifo_tx +.pio_version 1 +.fifo tx + pull + out pins, 8 + +.program fifo_rx +.pio_version 1 +.fifo rx + in pins, 8 + push + +.program fifo_txrx +.pio_version 1 +.fifo txrx + pull + mov isr, osr + push + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // ------- // +// // fifo_tx // +// // ------- // +// +// #define fifo_tx_wrap_target 0 +// #define fifo_tx_wrap 1 +// #define fifo_tx_pio_version 1 +// +// static __pio_const uint16_t fifo_tx_program_instructions[] = { +// // .wrap_target +// 0x80a0, // 0: pull block +// 0x6008, // 1: out pins, 8 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_tx_program = { +// .instructions = fifo_tx_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = fifo_tx_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_tx_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_tx_wrap_target, offset + fifo_tx_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_TX); +// return c; +// } +// #endif +// +// // ------- // +// // fifo_rx // +// // ------- // +// +// #define fifo_rx_wrap_target 0 +// #define fifo_rx_wrap 1 +// #define fifo_rx_pio_version 1 +// +// static __pio_const uint16_t fifo_rx_program_instructions[] = { +// // .wrap_target +// 0x4008, // 0: in pins, 8 +// 0x8020, // 1: push block +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_rx_program = { +// .instructions = fifo_rx_program_instructions, +// .length = 2, +// .origin = -1, +// .pio_version = fifo_rx_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_rx_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_rx_wrap_target, offset + fifo_rx_wrap); +// sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX); +// return c; +// } +// #endif +// +// // --------- // +// // fifo_txrx // +// // --------- // +// +// #define fifo_txrx_wrap_target 0 +// #define fifo_txrx_wrap 2 +// #define fifo_txrx_pio_version 1 +// +// static __pio_const uint16_t fifo_txrx_program_instructions[] = { +// // .wrap_target +// 0x80a0, // 0: pull block +// 0xa0c7, // 1: mov isr, osr +// 0x8020, // 2: push block +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program fifo_txrx_program = { +// .instructions = fifo_txrx_program_instructions, +// .length = 3, +// .origin = -1, +// .pio_version = fifo_txrx_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x0 +// #endif +// }; +// +// static inline pio_sm_config fifo_txrx_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + fifo_txrx_wrap_target, offset + fifo_txrx_wrap); +// return c; +// } +// #endif +// +// +// Stderr: diff --git a/tools/pioasm/test/valid/pio_version/test_pio_v1_gpio_extended_valid.pio b/tools/pioasm/test/valid/pio_version/test_pio_v1_gpio_extended_valid.pio new file mode 100644 index 000000000..8310db113 --- /dev/null +++ b/tools/pioasm/test/valid/pio_version/test_pio_v1_gpio_extended_valid.pio @@ -0,0 +1,59 @@ +// run: pioasm -v 1 input.pio +.program gpio_ext +.pio_version 1 + wait 0 gpio 47 + +// -- Output +// Command: pioasm -v 1 input.pio +// Exit code: 0 +// Stdout: +// // ------------------------------------------------------------------------ // +//? +// // ------------------------------------------------------------------------ // +// +// #pragma once +// +// #if !PICO_NO_HARDWARE +// #include "hardware/pio.h" +// #endif +// +// #ifdef __cpp_constexpr +// #define __pio_const constexpr +// #else +// #define __pio_const const +// #endif +// +// // -------- // +// // gpio_ext // +// // -------- // +// +// #define gpio_ext_wrap_target 0 +// #define gpio_ext_wrap 0 +// #define gpio_ext_pio_version 1 +// +// static __pio_const uint16_t gpio_ext_program_instructions[] = { +// // .wrap_target +// 0x200f, // 0: wait 0 gpio, 47 +// // .wrap +// }; +// +// #if !PICO_NO_HARDWARE +// static __pio_const struct pio_program gpio_ext_program = { +// .instructions = gpio_ext_program_instructions, +// .length = 1, +// .origin = -1, +// .pio_version = gpio_ext_pio_version, +// #if PICO_PIO_VERSION > 0 +// .used_gpio_ranges = 0x4 +// #endif +// }; +// +// static inline pio_sm_config gpio_ext_program_get_default_config(uint offset) { +// pio_sm_config c = pio_get_default_sm_config(); +// sm_config_set_wrap(&c, offset + gpio_ext_wrap_target, offset + gpio_ext_wrap); +// return c; +// } +// #endif +// +// +// Stderr: