Expose the existing registers through Modbus and service CAN using one GAS provider only in M95M02 builds. Include the EEPROM layout/driver, LOAD protection and calibration, firmware identity and shared CCS build workflow. Add transport/profile and SCI8 validation tests, documentation and the checked M95M02 firmware image.
52 lines
2.7 KiB
Python
52 lines
2.7 KiB
Python
"""Exercise the production GAS provider and extracted production RTU/CAN routes."""
|
|
import os
|
|
from pathlib import Path
|
|
import re
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
root = Path(__file__).resolve().parents[2]
|
|
templates = Path(os.environ.get("TEMPLATES_ROOT", root.parent / "newProject/SETGUI/third_party/templates"))
|
|
protocol = templates / "c/set-protocol"
|
|
compiler = os.environ.get("CC") or shutil.which("gcc") or "C:/msys64/mingw64/bin/gcc.exe"
|
|
os.environ["PATH"] = str(Path(compiler).resolve().parent) + os.pathsep + os.environ["PATH"]
|
|
|
|
|
|
def function(text, name):
|
|
match = re.search(r"^(?:static )?(?:void|int) " + name + r"\(", text, re.M)
|
|
if not match:
|
|
raise ValueError(f"Production function {name} missing")
|
|
end = re.search(r"^}", text[match.start():], re.M)
|
|
if not end:
|
|
raise ValueError(f"Production function {name} incomplete")
|
|
return text[match.start():match.start() + end.end()] + "\n"
|
|
|
|
|
|
message = (root / "Source/Internal/message.c").read_text(encoding="cp1251")
|
|
ecan = (root / "Source/Internal/ecan.c").read_text(encoding="cp1251")
|
|
can_globals = ecan[ecan.index("static volatile unsigned int ump_can_pending;"):
|
|
ecan.index("static unsigned long ump_can_sent_at;") + len("static unsigned long ump_can_sent_at;")]
|
|
# On C28x unsigned int is uint16_t. Preserve that target word layout on GCC.
|
|
can_globals = can_globals.replace("static unsigned int ump_can_reply[",
|
|
"static uint16_t ump_can_reply[")
|
|
routes = can_globals + "\n" + "".join(function(message, name) for name in
|
|
("modbus_exception", "receive_ump", "ReceiveCommandModbus3", "ReceiveCommandModbus6"))
|
|
routes += function(ecan, "UMP_CAN_service")
|
|
with tempfile.TemporaryDirectory(prefix="gas167-test-") as tmp:
|
|
directory = Path(tmp)
|
|
(directory / "production_routes.inc").write_text(routes, encoding="utf-8")
|
|
for profile in (0, 1):
|
|
exe = directory / f"gas167_{profile}.exe"
|
|
subprocess.run([compiler, "-std=c99", "-Wall", "-Wextra",
|
|
"-Wno-unused-function", "-Wno-unused-parameter",
|
|
f"-DEEPROM_M95M02={profile}", "-I" + str(directory),
|
|
"-ISource/Internal/Include", "-I" + str(protocol),
|
|
"-I" + str(protocol / "include"),
|
|
"-I" + str(protocol / "ports/tms320f28335"),
|
|
"tests/gas167/gas167_test.c", "Source/Internal/gas167.c",
|
|
str(protocol / "src/ump_protocol.c"),
|
|
str(protocol / "ports/tms320f28335/ump_tms28335.c"),
|
|
"-o", str(exe)], cwd=root, check=True)
|
|
subprocess.run([str(exe)], check=True, timeout=10)
|