├── .gitattributes ├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md ├── apps ├── pytas_chl_api_demo │ └── pytas_chl_client_demo.py ├── pytas_rw_api_demo │ └── pytas_rw_client_demo.py ├── tas_chl_api_demo │ ├── CMakeLists.txt │ └── tas_chl_api_demo_main.cpp └── tas_rw_api_demo │ ├── CMakeLists.txt │ └── tas_rw_api_demo_main.cpp ├── cmake ├── TasClientApiMinDepVersions.cmake ├── TasClientApiUtils.cmake └── templates │ ├── TasClientApiConfig.cmake.in │ └── setup.py.in ├── conanfile.py ├── data └── icons │ └── TAS_icon_small.png ├── docs ├── CMakeLists.txt ├── Doxyfile.in ├── client_chl_api.md ├── client_rw_api.md ├── client_trc_api.md ├── footer.html ├── header.html ├── mainpage.md └── stylesheet.css ├── python ├── CMakeLists.txt ├── README.md ├── binding │ ├── tas_python_binding.cpp │ ├── tas_python_binding.hpp │ ├── tas_python_client_chl.cpp │ ├── tas_python_client_chl.hpp │ ├── tas_python_client_rw.hpp │ ├── tas_python_client_rw_base.cpp │ ├── tas_python_client_rw_base.hpp │ ├── tas_python_client_server_con.cpp │ ├── tas_python_client_server_con.hpp │ ├── tas_python_client_trc.cpp │ └── tas_python_client_trc.hpp ├── requirements.txt └── tests │ ├── __init__.py │ ├── tas_python_client_rw_test.py │ └── tas_python_client_server_test.py ├── src ├── CMakeLists.txt ├── tas_client │ ├── CMakeLists.txt │ ├── tas_am15_am14.h │ ├── tas_client.h │ ├── tas_client_chl.cpp │ ├── tas_client_chl.h │ ├── tas_client_impl.h │ ├── tas_client_rw.h │ ├── tas_client_rw_base.cpp │ ├── tas_client_rw_base.h │ ├── tas_client_server_con.cpp │ ├── tas_client_server_con.h │ ├── tas_client_trc.cpp │ ├── tas_client_trc.h │ ├── tas_debug.h │ ├── tas_device_family.h │ ├── tas_pkt.h │ ├── tas_pkt_handler_base.cpp │ ├── tas_pkt_handler_base.h │ ├── tas_pkt_handler_chl.cpp │ ├── tas_pkt_handler_chl.h │ ├── tas_pkt_handler_rw.cpp │ ├── tas_pkt_handler_rw.h │ ├── tas_pkt_handler_server_con.cpp │ ├── tas_pkt_handler_server_con.h │ ├── tas_pkt_handler_trc.cpp │ ├── tas_pkt_handler_trc.h │ ├── tas_pkt_mailbox_if.h │ ├── tas_pkt_mailbox_socket.cpp │ ├── tas_pkt_mailbox_socket.h │ ├── tas_utils.cpp │ ├── tas_utils.h │ ├── tas_utils_client.h │ ├── tas_utils_ifx.cpp │ ├── tas_utils_ifx.h │ ├── tas_utils_jtag.cpp │ ├── tas_utils_jtag.h │ └── tas_utils_os.cpp └── tas_socket │ ├── CMakeLists.txt │ ├── tas_conn_socket.cpp │ ├── tas_conn_socket.h │ ├── tas_socket.cpp │ ├── tas_socket.h │ ├── tas_tcp_server_socket.cpp │ ├── tas_tcp_server_socket.h │ ├── tas_tcp_socket.cpp │ └── tas_tcp_socket.h ├── test_package ├── CMakeLists.txt ├── conanfile.py └── src │ └── main.cpp └── tools ├── build.py ├── deploy.py ├── start_tas_server.bat ├── test.py └── utilities.py /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior 2 | * text eol=lf 3 | 4 | # Declare files that will always have CRLF line endings on checkout. 5 | 6 | # Denote all files that are truly binary and should not be modified. 7 | *.elf binary 8 | *.png binary -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | 3 | build 4 | install 5 | 6 | CMakeUserPresets.json 7 | 8 | __pycache__ -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Disable in-source builds to prevent source tree corruption. 3 | # ----------------------------------------------------------------------------- 4 | if(" ${CMAKE_SOURCE_DIR}" STREQUAL " ${CMAKE_BINARY_DIR}") 5 | message(FATAL_ERROR "FATAL: In-source builds are not allowed. 6 | You should create a seperate directory for build files.") 7 | endif() 8 | # ----------------------------------------------------------------------------- 9 | # Minimum supported versions 10 | # ----------------------------------------------------------------------------- 11 | include(cmake/TasClientApiMinDepVersions.cmake) 12 | cmake_minimum_required(VERSION "${MIN_VER_CMAKE}" FATAL_ERROR) 13 | 14 | # ----------------------------------------------------------------------------- 15 | # Project definition 16 | # ----------------------------------------------------------------------------- 17 | project(tas_client_api 18 | VERSION 1.0.2 19 | DESCRIPTION "Infineon's Tool Access Socket (TAS) Client API" 20 | HOMEPAGE_URL "https://github.com/Infineon/tas_client_api" 21 | LANGUAGES CXX 22 | ) 23 | set(TAS_CLIENT_COPYRIGHT "(c) Infineon Technologies AG 2024") 24 | 25 | # ----------------------------------------------------------------------------- 26 | # Break in case of popular CMake configuration mistakes 27 | # ----------------------------------------------------------------------------- 28 | if(NOT CMAKE_SIZEOF_VOID_P GREATER 0) 29 | message(FATAL_ERROR "CMake fails to determine the bitness of the target 30 | platform. Please check your CMake and compiler installation. If you are 31 | cross-compiling then ensure that your CMake toolchain file correctly sets 32 | the compiler details.") 33 | endif() 34 | 35 | # ----------------------------------------------------------------------------- 36 | # Project options 37 | # ----------------------------------------------------------------------------- 38 | option(TAS_CLIENT_API_BUILD_PYTHON "Build Python interface if enabled" OFF) 39 | option(TAS_CLIENT_API_BUILD_TEST "Build test binaries if enabled" OFF) 40 | option(TAS_CLIENT_API_BUILD_DOCS "Build documentation using doxygen if enabled" OFF) 41 | 42 | # ----------------------------------------------------------------------------- 43 | # Soruce and test files 44 | # ----------------------------------------------------------------------------- 45 | include(cmake/TasClientApiUtils.cmake) 46 | include(GNUInstallDirs) 47 | 48 | set_property(GLOBAL PROPERTY CTEST_TARGETS_ADDED 1) 49 | include(CTest) 50 | 51 | add_subdirectory(apps/tas_rw_api_demo) 52 | add_subdirectory(apps/tas_chl_api_demo) 53 | add_subdirectory(python) 54 | add_subdirectory(src) 55 | add_subdirectory(docs) 56 | 57 | # ----------------------------------------------------------------------------- 58 | # Install 59 | # ----------------------------------------------------------------------------- 60 | # export targets 61 | install(EXPORT TasClientApiTargets 62 | FILE TasClientApiTargets.cmake 63 | NAMESPACE TasClientApi:: 64 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TasClientApi 65 | ) 66 | 67 | # export targets to be used from a build directory 68 | export(EXPORT TasClientApiTargets 69 | FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/TasClientApiTargets.cmake" 70 | NAMESPACE TasClientApi:: 71 | ) 72 | 73 | # Package definition 74 | # provides configure_package_config_file() which enables creation of relocatable packages. 75 | include(CMakePackageConfigHelpers) 76 | 77 | # Package configuration file 78 | configure_package_config_file(${CMAKE_SOURCE_DIR}/cmake/templates/TasClientApiConfig.cmake.in 79 | "${CMAKE_CURRENT_BINARY_DIR}/TasClientApiConfig.cmake" 80 | INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TasClientApi 81 | ) 82 | 83 | # Package version file 84 | # If no specific version set, it takes PROJECT_VERSION 85 | write_basic_package_version_file( 86 | "${CMAKE_CURRENT_BINARY_DIR}/TasClientApiConfigVersion.cmake" 87 | COMPATIBILITY SameMajorVersion 88 | ) 89 | 90 | install(FILES 91 | "${CMAKE_CURRENT_BINARY_DIR}/TasClientApiConfig.cmake" 92 | "${CMAKE_CURRENT_BINARY_DIR}/TasClientApiConfigVersion.cmake" 93 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/TasClientApi 94 | ) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tool Access Socket (TAS) Client API source code 2 | [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/Infineon/tas_client_api/commits/master/) 3 | [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen)](https://github.com/Infineon/tas_client_api/pulls) 4 | 5 | This readme file gives an overview how to build and run the code. 6 | 7 | ## Prerequisite for building locally 8 | This project uses [conan](https://conan.io) as dependency manager and consequently CMake as the build environment. 9 | All required packages and build tools are retrieved from the [ConanCenter](https://conan.io/center). See conanfile.py 10 | for the list of dependencies. Therefore, to build this project you will need: 11 | 12 | - [Python](https://www.python.org/), a version that supports Conan2, 13 | - [CMake](https://cmake.org/), minimum version 3.25 14 | - Target compiler: msvc, gcc, etc. 15 | - [Doxygen](https://www.doxygen.nl/), if you want to build the API reference documentation 16 | 17 | ### Prerequisite for building the python wrapper 18 | Python packages: setuptools, wheel, virtualenv 19 | 20 | ### Conan 21 | If not already installed, install conan: 22 | ``` 23 | python -m pip install conan 24 | ``` 25 | 26 | If it is your first time using conan, you first need to generate a default profile: 27 | ``` 28 | conan profile detect 29 | ``` 30 | The generated profile can be then found under *\/.conan2/profiles*. The default configuration is Release. 31 | More information about conan profiles can be found here https://docs.conan.io/2.0/reference/config_files/profiles.html. 32 | Edit the default conan profile with your favorite text editor so that the **C++17 standard** is used. 33 | ``` 34 | compiler.cppstd=17 35 | ``` 36 | Note: make sure your compiler supports C++17. 37 | 38 | ## Building 39 | First generate the build environment by invoking conan **from the root of this repository**: 40 | ``` 41 | conan install . 42 | conan install . -s build_type=Debug --build=missing 43 | ``` 44 | The above step configures the environment in way that only the C++ API will be build. If you want to build the python 45 | wrapper, the API reference, and/or the tests then you need to specify this by providing an option to the above commands. 46 | See the conanfile.py for available options. 47 | ``` 48 | conan install . -o python=True -o docs=True -o tests=True 49 | ``` 50 | By default all options are disabled, i.e. False 51 | 52 | ### Invoking CMake 53 | Things generally happen in two phases with CMake: 54 | * Configure the build based on the CMakeLists.txt 55 | * Perform the build based on the toolchain of your platform (typically msvc on windows and make on Linux) 56 | 57 | The project uses **CMakePresets.json** to define global configuration, build, and test presets. 58 | 59 | If using Visual Studio refer to [Configure and build with CMake Presets in Visual Studio](https://learn.microsoft.com/en-us/cpp/build/cmake-presets-vs?view=msvc-170). 60 | 61 | If using Visual Studio Code refer to [Configure and build with CMake Presets in Visual Studio Code](https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/cmake-presets.md). 62 | 63 | Conan will generate some default cmake presets. For multi-config generators like msvc and ninja, this will be conan-default. 64 | For single-config generators like Unix Makefiles, this will be conan-release and conan-debug. 65 | 66 | **Windows** 67 | ``` 68 | # Assuming Visual Studio 17 2022 is your VS version and that it matches your default profile 69 | cmake --preset conan-default 70 | # Note: if you have problems during consecutive runs, then specify your platform name and the toolset 71 | cmake --preset conan-default -A x64 -T v143 # In case of VS201: -T v142 72 | ``` 73 | At this point a Visual Studio solution file is generated, and can be used instead of CLI commands. The solution file is 74 | located under the build folder. 75 | 76 | **Linux** 77 | ``` 78 | cmake --preset conan-release 79 | cmake --preset conan-debug # Assuming conan install . -s build_type=Debug was run prior to this 80 | ``` 81 | 82 | Followed by the build step: 83 | ``` 84 | cmake --build --preset conan-release # Builds the release version 85 | cmake --build --preset conan-debug # Builds the debug version, Assuming cmake --preset conan-debug was run prior to this 86 | ``` 87 | Note: The conan-debug preset will be available only if conan install with build_type set to Debug was run beforehand. 88 | 89 | ### Using Conan (not recommended) 90 | ``` 91 | conan build . 92 | ``` 93 | 94 | ## Building using a build script 95 | Alternative you can use the CI build script for building the project. For available options run the script with the help 96 | flag (-h/--help). Build the project by invoking the CI build script with required options. 97 | 98 | **Windows** 99 | ``` 100 | python .\tools\build.py 101 | ``` 102 | **Linux** 103 | ``` 104 | python3 ./tools/build.py 105 | ``` 106 | 107 | ## Installing / exporting binaries 108 | The project is configured in way that the binaries can be installed to a specified location. Use the following command: 109 | ``` 110 | cmake --install build --prefix=install 111 | ``` 112 | where build is the build directory, and prefix options defines the root install / export folder. 113 | 114 | ## Python wrapper 115 | Building the python wrapper using the above steps requires -o python=True conan option when invoking the conan install command. 116 | 117 | If you want to use a specific Python version or you have multiple version installed you can tell CMake which one to use 118 | by modifying the following CMake file: python\CMakeLists.txt before executing the above commands. 119 | ``` 120 | set(Python3_ROOT_DIR "") 121 | ``` 122 | 123 | The generated python wheel will be located under: build\python\dist 124 | -------------------------------------------------------------------------------- /apps/pytas_chl_api_demo/pytas_chl_client_demo.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | from PyTAS.PyTAS import * 20 | 21 | print("TAS API channels demo\n") 22 | 23 | # Create an instance of TAS Client Chl 24 | client = TasClientChl("DemoClientChl") 25 | 26 | # Connect to the server, provide IP address or localhost 27 | ret = client.server_connect("localhost") 28 | if (ret != TAS_ERR_NONE): 29 | print(f"Failed to connect to the server, {client.get_error_info()}") 30 | # other error processing code 31 | exit() # Fatal 32 | 33 | 34 | # Print the server info 35 | print() 36 | server_info = client.get_server_info() 37 | print("Server Info: ") 38 | 39 | start_time = server_info.start_time_us / 1000000; # Convert to seconds 40 | print(f"Started at {start_time}\n") 41 | 42 | print(f"{server_info.server_name} V{server_info.v_major}.{server_info.v_minor} ({server_info.date})") 43 | 44 | # Print the server IP address and its port number 45 | print(f"Server IP:port: {client.get_server_ip_addr()}:{client.get_server_port_num()}") 46 | 47 | 48 | # Print the list of targets connected to the server 49 | print() 50 | targets, ret = client.get_targets() 51 | if (ret != TAS_ERR_NONE): 52 | print(f"Failed to get the list of targets {client.get_error_info()}") 53 | # other error processing code 54 | exit() # Fatal 55 | 56 | print(f"Number of targets: {len(targets)}\n") 57 | 58 | for i in range(len(targets)): 59 | print(f"Target {i}: {targets[i].identifier}") 60 | 61 | 62 | 63 | # Connect to the first target from the list 64 | print() 65 | print("Connecting to the first target from the list...\n") 66 | ret = client.session_start(targets[0].identifier, "DemoSession") 67 | 68 | if (ret != TAS_ERR_NONE): 69 | print(f"Failed to start a session, {client.get_error_info()}\n") 70 | # other error processing code 71 | exit() # Fatal 72 | 73 | 74 | # Print con_info 75 | con_info = client.get_con_info() 76 | 77 | print(f"TARGET:") 78 | print(f"\tidentifier: {con_info.identifier}") 79 | print(f"\thash: {con_info.device_id_hash_str}") 80 | print() 81 | 82 | client2 = TasClientChl("DemoClientChl2") 83 | 84 | ret = client2.server_connect("localhost") 85 | if (ret != TAS_ERR_NONE): 86 | print(f"Failed to connect to the server, {client2.get_error_info()}") 87 | # other error processing code 88 | exit() # Fatal 89 | 90 | ret = client2.session_start(targets[0].identifier, "DemoSession") 91 | if (ret != TAS_ERR_NONE): 92 | print(f"Failed to start a session, {client2.get_error_info()}\n") 93 | # other error processing code 94 | exit() # Fatal 95 | 96 | 97 | # Bidirectional client 98 | chl = 5 99 | channel_type = TAS_CHT_BIDI 100 | con_mode = TAS_CHSO_DEFAULT 101 | 102 | ret = client.subscribe(chl, channel_type, con_mode) 103 | assert ret == TAS_ERR_NONE 104 | 105 | s_msg = "Hello World! PyMCDS demo" 106 | ret = client.send_string(s_msg) 107 | assert ret == TAS_ERR_NONE 108 | print(f"Message sent to chl {chl}: {s_msg}") 109 | 110 | r_msg, init, ret = client.rcv_string(1000) 111 | assert ret == TAS_ERR_NONE, client.get_error_info() 112 | print(f"Message received from chl {chl}: {r_msg}") 113 | 114 | s_bmsg = (0xBEBACAFE).to_bytes(4, 'little') 115 | ret = client.send_msg(s_bmsg) 116 | assert ret == TAS_ERR_NONE 117 | print(f"Message sent to chl {chl}: {s_bmsg}") 118 | 119 | r_msg, init, ret = client.rcv_msg(1000) 120 | assert ret == TAS_ERR_NONE 121 | print(f"Message received from chl {chl}: {r_msg}") 122 | 123 | ret = client.unsubscribe() 124 | assert ret == TAS_ERR_NONE 125 | 126 | 127 | # Single direction clients 128 | chl = 3 129 | 130 | ret = client.subscribe(chl, TAS_CHT_SEND, con_mode) 131 | assert ret == TAS_ERR_NONE 132 | 133 | ret = client2.subscribe(chl, TAS_CHT_RCV, con_mode) 134 | assert ret == TAS_ERR_NONE 135 | 136 | s_msg = "Hello World!" 137 | ret = client.send_string(s_msg) 138 | assert ret == TAS_ERR_NONE 139 | print(f"Message sent: {s_msg}") 140 | 141 | r_msg, init, ret = client2.rcv_string(1000) 142 | assert ret == TAS_ERR_NONE 143 | print(f"Message received: {r_msg[:-1]}") 144 | 145 | 146 | r_msg, init, ret = client.rcv_msg(1000) 147 | assert ret == TAS_ERR_FN_USAGE 148 | 149 | s_msg = "Hello World!" 150 | ret = client2.send_string(s_msg) 151 | assert ret == TAS_ERR_FN_USAGE -------------------------------------------------------------------------------- /apps/pytas_rw_api_demo/pytas_rw_client_demo.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | from PyTAS.PyTAS import * 20 | 21 | print("TAS API rw demo\n") 22 | 23 | # Create an instance of TAS Client RW 24 | client = TasClientRw("DemoClientRw") 25 | 26 | # Connect to the server, provide IP address or localhost 27 | ret = client.server_connect("localhost") 28 | if (ret != TAS_ERR_NONE): 29 | print(f"Failed to connect to the server, {client.get_error_info()}") 30 | # other error processing code 31 | exit() # Fatal 32 | 33 | 34 | # Print the server info 35 | print() 36 | server_info = client.get_server_info() 37 | print("Server Info: ") 38 | 39 | start_time = server_info.start_time_us / 1000000; # Convert to seconds 40 | print(f"Started at {start_time}\n") 41 | 42 | print(f"{server_info.server_name} V{server_info.v_major}.{server_info.v_minor} ({server_info.date})") 43 | 44 | # Print the server IP address and its port number 45 | print(f"Server IP:port: {client.get_server_ip_addr()}:{client.get_server_port_num()}") 46 | 47 | 48 | # Print the list of targets connected to the server 49 | print() 50 | targets, ret = client.get_targets() 51 | if (ret != TAS_ERR_NONE): 52 | print(f"Failed to get the list of targets {client.get_error_info()}") 53 | # other error processing code 54 | exit() # Fatal 55 | 56 | print(f"Number of targets: {len(targets)}\n") 57 | 58 | for i in range(len(targets)): 59 | print(f"Target {i}: {targets[i].identifier}") 60 | 61 | 62 | 63 | # Connect to the first target from the list 64 | print() 65 | print("Connecting to the first target from the list...\n") 66 | ret = client.session_start(targets[0].identifier, "DemoSession") 67 | if (ret != TAS_ERR_NONE): 68 | print(f"Failed to start a session, {client.get_error_info()}\n") 69 | # other error processing code 70 | exit() # Fatal 71 | 72 | 73 | # Print con_info 74 | con_info = client.get_con_info() 75 | 76 | print(f"TARGET:") 77 | print(f"\tidentifier: {con_info.identifier}") 78 | print(f"\thash: {con_info.device_id_hash_str}") 79 | 80 | 81 | # Reset the target 82 | ret = client.device_connect(TAS_CLNT_DCO_RESET_AND_HALT) 83 | if (ret != TAS_ERR_NONE): 84 | print(f"Failed to reset the device, {client.get_error_info()}") 85 | # other error processing code 86 | 87 | # Basic read/write operations 88 | base_addr = 0x70000000 89 | 90 | print() 91 | print("Basic read/write operations") 92 | addr = base_addr 93 | print(f"\tRead - write - read 1 Byte at address {hex(addr)}") 94 | rd_data_8, ret = client.read8(addr) 95 | assert ret == TAS_ERR_NONE 96 | print(f"Read data: {hex(rd_data_8)}") 97 | value8 = 0xAB 98 | print(f"Write {hex(value8)}") 99 | assert client.write8(addr, value8) == TAS_ERR_NONE 100 | rd_data_8, ret = client.read8(addr) 101 | assert ret == TAS_ERR_NONE 102 | print(f"Read back data: {hex(rd_data_8)}") 103 | 104 | print() 105 | addr = base_addr + 1 106 | print(f"\tRead - write - read 1 Byte at address {hex(addr)}") 107 | rd_data_8, ret = client.read8(addr) 108 | assert ret == TAS_ERR_NONE 109 | print(f"Read data: {hex(rd_data_8)}") 110 | value8 = 0xCD 111 | print(f"Write {hex(value8)}") 112 | assert client.write8(addr, value8) == TAS_ERR_NONE 113 | rd_data_8, ret = client.read8(addr) 114 | assert ret == TAS_ERR_NONE 115 | print(f"Read back data: {hex(rd_data_8)}") 116 | 117 | # Reset the target 118 | assert client.device_connect(TAS_CLNT_DCO_RESET_AND_HALT) == TAS_ERR_NONE 119 | 120 | print() 121 | addr = base_addr 122 | print(f"\tRead - write - read 4 Bytes at address {hex(addr)}") 123 | rd_data, ret = client.read32(addr) 124 | print(f"Read data: {hex(rd_data)}") 125 | wr_data = 0xABCDEF09 126 | print(f"Write {hex(wr_data)}") 127 | assert client.write32(addr, wr_data) == TAS_ERR_NONE 128 | rd_data, ret = client.read32(addr) 129 | assert ret == TAS_ERR_NONE 130 | print(f"Read back data: {hex(rd_data)}") 131 | 132 | 133 | print() 134 | addr = base_addr + 1 135 | print(f"\tRead - write - read 4 Bytes at unaligned address {hex(addr)}") 136 | rd_data, ret = client.read32(addr) 137 | print(f"Read data: {hex(rd_data)}") 138 | wr_data = 0x12345678 139 | print(f"Write {hex(wr_data)}") 140 | assert client.write32(addr, wr_data) == TAS_ERR_NONE 141 | rd_data, ret = client.read32(addr & 0xFFFFFFFE) 142 | assert ret == TAS_ERR_NONE 143 | rd_data1, ret = client.read32((addr & 0xFFFFFFFE) + 4) 144 | assert ret == TAS_ERR_NONE 145 | print(f"Read back data @{hex(addr & 0xFFFFFFFE)}: {hex(rd_data)}") 146 | print(f"Read back data @{hex((addr & 0xFFFFFFFE) + 4)}: {hex(rd_data1)}") 147 | 148 | # Reset the target 149 | assert client.device_connect(TAS_CLNT_DCO_RESET_AND_HALT) == TAS_ERR_NONE 150 | 151 | # Example fill 152 | print() 153 | print("Fill data starting from target address") 154 | addr = base_addr 155 | # fill the memory with 0x123ABCD from 0x60000000 to 0x6000007C 156 | assert client.fill32(addr, 0x1234ABCD, 128) == TAS_ERR_NONE 157 | rd_data, ret = client.read(addr, 128) 158 | for i in range(int(128 / 4)): 159 | data = int.from_bytes(rd_data[i*4:(i*4)+4], "little") 160 | print(f"Data @{hex(addr | (i*4))}: {hex(data)}") 161 | 162 | # Reset the target 163 | assert client.device_connect(TAS_CLNT_DCO_RESET_AND_HALT) == TAS_ERR_NONE 164 | 165 | # Example with transaction list 166 | print() 167 | print("Read - write - read with transaction list") 168 | rd_data = 0 169 | addr = 0x60000000 170 | wr_data = 0xFFABCDEF 171 | 172 | trans = list() 173 | t1 = TasRwTransaction() 174 | t1.addr = addr 175 | t1.data = bytes() 176 | t1.num_bytes = 4 177 | t1.type = TasRwTransType.TAS_RW_TT_RD 178 | trans.append(t1) 179 | 180 | t2 = TasRwTransaction() 181 | t2.addr = addr 182 | t2.data = wr_data.to_bytes(4, byteorder="little") 183 | t2.num_bytes = 4 184 | t2.type = TasRwTransType.TAS_RW_TT_WR 185 | trans.append(t2) 186 | 187 | t3 = TasRwTransaction() 188 | t3.addr = addr 189 | t3.data = bytes() 190 | t3.num_bytes = 4 191 | t3.type = TasRwTransType.TAS_RW_TT_RD 192 | trans.append(t3) 193 | 194 | 195 | 196 | # Execute list 197 | trans, ret = client.execute_trans(trans) 198 | assert ret == TAS_ERR_NONE 199 | print(f"Read transaction: {trans[0].data}") 200 | print(f"Write transaction: {trans[1].data}") 201 | print(f"Read transaction: {trans[2].data}") 202 | 203 | # Reset the target 204 | assert client.device_connect(TAS_CLNT_DCO_RESET) == TAS_ERR_NONE 205 | 206 | # Destructor of clientRw will automatically end the session -------------------------------------------------------------------------------- /apps/tas_chl_api_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # tas_chl_api_demo 3 | # ----------------------------------------------------------------------------- 4 | set(EXE_NAME tas_chl_api_demo) 5 | 6 | # ----------------------------------------------------------------------------- 7 | # Relevant source files and their virtual folders for IDE (source groups) 8 | # ----------------------------------------------------------------------------- 9 | set(NO_GROUP_SRCS 10 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_chl_api_demo_main.cpp" 11 | ) 12 | 13 | # generate IDE virtual folders where supported 14 | source_group("" FILES ${NO_GROUP_SRCS}) 15 | 16 | # ----------------------------------------------------------------------------- 17 | # Find relevant dependencies 18 | # ----------------------------------------------------------------------------- 19 | 20 | # ----------------------------------------------------------------------------- 21 | # Add executable, its includes, and libraries 22 | # ----------------------------------------------------------------------------- 23 | add_executable(${EXE_NAME} 24 | ${NO_GROUP_SRCS} 25 | ) 26 | 27 | target_link_libraries(${EXE_NAME} tas_client) 28 | 29 | # ----------------------------------------------------------------------------- 30 | # Dependencies 31 | # ----------------------------------------------------------------------------- 32 | 33 | # ----------------------------------------------------------------------------- 34 | # Compile definitions 35 | # ----------------------------------------------------------------------------- 36 | if (MSVC) 37 | target_compile_definitions(${EXE_NAME} PRIVATE 38 | "$<$:" 39 | "_DEBUG" 40 | ">" 41 | "$<$:" 42 | "NDEBUG" 43 | ">" 44 | "_CRT_SECURE_NO_WARNINGS" 45 | "_WIN32" 46 | ) 47 | elseif (UNIX) 48 | target_compile_definitions(${EXE_NAME} PRIVATE 49 | "UNIX" 50 | ) 51 | endif() 52 | 53 | # ----------------------------------------------------------------------------- 54 | # Compile and link options 55 | # ----------------------------------------------------------------------------- 56 | if (MSVC) 57 | target_compile_options(${EXE_NAME} PRIVATE 58 | /W3 59 | /MP 60 | ) 61 | 62 | target_link_options(${EXE_NAME} PRIVATE 63 | /SUBSYSTEM:CONSOLE 64 | ) 65 | elseif (UNIX) 66 | target_compile_options(${EXE_NAME} PRIVATE 67 | -Wall; 68 | ) 69 | target_link_libraries(${EXE_NAME} pthread dl) 70 | endif() 71 | 72 | # ----------------------------------------------------------------------------- 73 | # Install 74 | # ----------------------------------------------------------------------------- 75 | install(TARGETS ${EXE_NAME} DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT applications) -------------------------------------------------------------------------------- /apps/tas_chl_api_demo/tas_chl_api_demo_main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | //******************************************************************************************************************** 21 | //------------------------------------------------------Includes------------------------------------------------------ 22 | //******************************************************************************************************************** 23 | #include "tas_client_chl.h" 24 | #include "tas_utils.h" 25 | #include "tas_device_family.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | std::unique_ptr createAndConnectChlClient(const char* client_name); 33 | 34 | //******************************************************************************************************************** 35 | //----------------------------------------------------- Main --------------------------------------------------------- 36 | //******************************************************************************************************************** 37 | int main(int argc, char** argv) 38 | { 39 | printf("TAS CHL API demo\n"); 40 | 41 | auto clientChlBi = createAndConnectChlClient("DemoBidirectionalClient"); 42 | 43 | if (!clientChlBi) 44 | return -1; 45 | 46 | // Basic channel operations 47 | // Bidirectional client 48 | uint8_t chl_num = 1; 49 | 50 | 51 | tasutil_assert(clientChlBi->subscribe(chl_num, tas_cht_et::TAS_CHT_BIDI)); 52 | 53 | tasutil_assert(clientChlBi->send_msg("HELLO WORLD!", 13)); 54 | 55 | uint32_t timeout = 100; 56 | const char* msg_rec; 57 | uint16_t msg_len; 58 | uint32_t init; 59 | tasutil_assert(clientChlBi->rcv_msg(timeout, (const void**)&msg_rec, &msg_len, &init)); 60 | 61 | printf("Received message: %s\n", msg_rec); 62 | 63 | tasutil_assert(clientChlBi->unsubscribe()); 64 | 65 | // Single direction clients 66 | auto clientSnd = createAndConnectChlClient("DemoSendClient"); 67 | auto clientRcv = createAndConnectChlClient("DemoReceiveClient"); 68 | 69 | if (!clientRcv || !clientSnd) 70 | return -1; 71 | 72 | uint8_t prioS; 73 | uint8_t prioR; 74 | const uint32_t data_2_send = 0xBEBECAFE; 75 | const uint32_t* data_received; 76 | 77 | prioS = 1; 78 | prioR = 2; 79 | 80 | tasutil_assert(clientSnd->subscribe(2, tas_cht_et::TAS_CHT_SEND, tas_chso_et::TAS_CHSO_DEFAULT, &prioS)); 81 | tasutil_assert(clientRcv->subscribe(2, tas_cht_et::TAS_CHT_RCV, tas_chso_et::TAS_CHSO_DEFAULT, &prioR)); 82 | 83 | tasutil_assert(clientSnd->send_msg(&data_2_send, sizeof(data_2_send))); 84 | tasutil_assert(clientRcv->rcv_msg(timeout, (const void**)&data_received, &msg_len, &init)); 85 | 86 | printf("Received data: %X", *data_received); 87 | 88 | tasutil_assert(clientSnd->unsubscribe()); 89 | tasutil_assert(clientRcv->unsubscribe()); 90 | 91 | return 0; 92 | } 93 | 94 | std::unique_ptr createAndConnectChlClient(const char* client_name){ 95 | // Create an instance of TAS Client RW 96 | auto clientChl = std::make_unique(client_name); 97 | 98 | 99 | // Connect to the server, provide IP address or localhost 100 | tas_return_et ret; // TAS return value 101 | ret = clientChl->server_connect("localhost"); 102 | if (ret != TAS_ERR_NONE) 103 | { 104 | printf("Failed to connect to the server, %s\n", clientChl->get_error_info()); 105 | // other error processing code 106 | return nullptr; // Fatal 107 | } 108 | 109 | 110 | // Print the server info 111 | printf("\n"); 112 | const tas_server_info_st* serverInfo = clientChl->get_server_info(); 113 | printf("Server Info: \n"); 114 | 115 | time_t startTime = serverInfo->start_time_us / 1000000; // Convert to seconds 116 | std::array timeStr; 117 | tasutil_get_time_str(startTime, timeStr.data()); 118 | printf("Started at %s\n", timeStr.data()); 119 | 120 | printf("%s V%d.%d (%s)\n", serverInfo->server_name, serverInfo->v_major, serverInfo->v_minor, serverInfo->date); 121 | 122 | // Print the server IP address and its port number 123 | printf("Server IP:port: %s:%d\n", clientChl->get_server_ip_addr(), clientChl->get_server_port_num()); 124 | 125 | 126 | // Print the list of targets connected to the server 127 | printf("\n"); 128 | const tas_target_info_st* targets; // list of targets 129 | uint32_t numTargets; // number of connected targets, updated by the API call 130 | ret = clientChl->get_targets(&targets, &numTargets); 131 | if (ret != TAS_ERR_NONE) 132 | { 133 | printf("Failed to get the list of targets %s\n", clientChl->get_error_info()); 134 | // other error processing code 135 | return nullptr; // Fatal 136 | } 137 | printf("Number of targets: %d\n", numTargets); 138 | for (uint32_t i = 0; i < numTargets; i++) 139 | { 140 | const char* deviceName = tas_get_device_name_str(targets[i].device_type); 141 | uint32_t deviceIdHash = tasutil_crc32(targets[i].device_id, 16); 142 | std::array deviceIdHashStr; 143 | tasutil_hash32_to_str(deviceIdHash, deviceIdHashStr.data()); 144 | printf("Target %d: %s %s (%s)\n", i, deviceName, deviceIdHashStr.data(), targets[i].identifier); 145 | } 146 | 147 | 148 | // Connect to the first target from the list 149 | printf("\n"); 150 | printf("Connecting to the first target from the list...\n"); 151 | ret = clientChl->session_start(targets[0].identifier, "DemoSession"); 152 | if (ret != TAS_ERR_NONE) 153 | { 154 | printf("Failed to start a session, %s\n", clientChl->get_error_info()); 155 | // other error processing code 156 | return nullptr; // Fatal 157 | } 158 | 159 | 160 | // Print con_info 161 | const tas_con_info_st* conInfo = clientChl->get_con_info(); 162 | constexpr int infoStrBufSize = 4096; 163 | std::array infoStr; 164 | int s = snprintf(infoStr.data(), 16, "TARGET:\n"); 165 | tasutil_get_con_info_str(conInfo, infoStr.data() + s); 166 | printf("%s", infoStr.data()); 167 | 168 | return clientChl; 169 | } -------------------------------------------------------------------------------- /apps/tas_rw_api_demo/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # tas_rw_api_demo 3 | # ----------------------------------------------------------------------------- 4 | set(EXE_NAME tas_rw_api_demo) 5 | 6 | # ----------------------------------------------------------------------------- 7 | # Relevant source files and their virtual folders for IDE (source groups) 8 | # ----------------------------------------------------------------------------- 9 | set(NO_GROUP_SRCS 10 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_rw_api_demo_main.cpp" 11 | ) 12 | 13 | # generate IDE virtual folders where supported 14 | source_group("" FILES ${NO_GROUP_SRCS}) 15 | 16 | # ----------------------------------------------------------------------------- 17 | # Find relevant dependencies 18 | # ----------------------------------------------------------------------------- 19 | 20 | # ----------------------------------------------------------------------------- 21 | # Add executable, its includes, and libraries 22 | # ----------------------------------------------------------------------------- 23 | add_executable(${EXE_NAME} 24 | ${NO_GROUP_SRCS} 25 | ) 26 | 27 | target_link_libraries(${EXE_NAME} tas_client) 28 | 29 | # ----------------------------------------------------------------------------- 30 | # Dependencies 31 | # ----------------------------------------------------------------------------- 32 | 33 | # ----------------------------------------------------------------------------- 34 | # Compile definitions 35 | # ----------------------------------------------------------------------------- 36 | if (MSVC) 37 | target_compile_definitions(${EXE_NAME} PRIVATE 38 | "$<$:" 39 | "_DEBUG" 40 | ">" 41 | "$<$:" 42 | "NDEBUG" 43 | ">" 44 | "_CRT_SECURE_NO_WARNINGS" 45 | "_WIN32" 46 | ) 47 | elseif (UNIX) 48 | target_compile_definitions(${EXE_NAME} PRIVATE 49 | "UNIX" 50 | ) 51 | endif() 52 | 53 | # ----------------------------------------------------------------------------- 54 | # Compile and link options 55 | # ----------------------------------------------------------------------------- 56 | if (MSVC) 57 | target_compile_options(${EXE_NAME} PRIVATE 58 | /W3 59 | /MP 60 | "$<$:" 61 | "/O2" 62 | ">" 63 | ) 64 | 65 | target_link_options(${EXE_NAME} PRIVATE 66 | /SUBSYSTEM:CONSOLE 67 | ) 68 | elseif (UNIX) 69 | target_compile_options(${EXE_NAME} PRIVATE 70 | -Wall; 71 | ) 72 | target_link_libraries(${EXE_NAME} pthread dl) 73 | endif() 74 | 75 | # ----------------------------------------------------------------------------- 76 | # Install 77 | # ----------------------------------------------------------------------------- 78 | install(TARGETS ${EXE_NAME} DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT applications) -------------------------------------------------------------------------------- /cmake/TasClientApiMinDepVersions.cmake: -------------------------------------------------------------------------------- 1 | if(NOT DEFINED MIN_VER_CMAKE) 2 | set(MIN_VER_CMAKE 3.23.0) 3 | endif() 4 | set(MIN_VER_PYTHON3 3.11) -------------------------------------------------------------------------------- /cmake/TasClientApiUtils.cmake: -------------------------------------------------------------------------------- 1 | 2 | function(tac_add_target_sources target srcs) 3 | if(TARGET ${target}) 4 | target_sources(${target} 5 | PRIVATE ${srcs} 6 | ) 7 | 8 | target_include_directories(${target} 9 | PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}" 10 | ) 11 | else() 12 | message(STATUS "Target ${target} not defined, sources not added") 13 | endif() 14 | endfunction() 15 | 16 | -------------------------------------------------------------------------------- /cmake/templates/TasClientApiConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include("${CMAKE_CURRENT_LIST_DIR}/TasClientApiTargets.cmake") 4 | 5 | check_required_components(TasClientApi) -------------------------------------------------------------------------------- /cmake/templates/setup.py.in: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | from setuptools import find_packages, setup 4 | from setuptools.dist import Distribution 5 | 6 | class BinaryDistribution(Distribution): 7 | def is_pure(self): 8 | return False 9 | 10 | def has_ext_modules(self): 11 | return True 12 | 13 | from setuptools.command.install import install 14 | class InstallPlatlib(install): 15 | def finalize_options(self): 16 | install.finalize_options(self) 17 | self.install_lib=self.install_platlib 18 | 19 | setup( 20 | name="@PYTHON_PROJECT@", 21 | version="@PROJECT_VERSION@", 22 | description="A python interface for TAS", 23 | long_description="This library provides an interface for the C++ TAS library", 24 | author="Ibai Irigoien", 25 | author_email="ibai.irigoyenceberio@infineon.com", 26 | maintainer="TBD", 27 | maintainer_email="TBD", 28 | url="https://www.infineon.com/DAS", 29 | distclass=BinaryDistribution, 30 | cmdclass={'install': InstallPlatlib}, 31 | packages=find_packages( 32 | where="src", 33 | include=["Py*"], 34 | ), 35 | package_dir={"": "src"}, 36 | package_data={ 37 | "@PYTHON_PROJECT@":["$<$>:'.libs/*'>", "$"], 38 | }, 39 | classifiers=[ 40 | "Development Status :: 5 - Production/Stable", 41 | "Intended Audience :: Developers", 42 | "License :: OSI Approved :: Apache Software License", 43 | "Operating System :: POSIX :: Linux", 44 | "Operating System :: MacOS :: MacOS X", 45 | "Operating System :: Microsoft :: Windows", 46 | "Programming Language :: Python", 47 | "Programming Language :: C++", 48 | "Topic :: Scientific/Engineering", 49 | "Topic :: Software Development :: Libraries :: Python Modules", 50 | ], 51 | ) -------------------------------------------------------------------------------- /conanfile.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | from conan import ConanFile 20 | from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout 21 | from conan.tools.build import check_min_cppstd 22 | from conan.errors import ConanInvalidConfiguration 23 | 24 | # for installing missing python packages 25 | import os 26 | import re 27 | import sys 28 | import subprocess 29 | from pathlib import Path 30 | 31 | # Conan recipe class 32 | class TasClientApiRecipe(ConanFile): 33 | name = "tas_client_api" 34 | 35 | def set_version(self): 36 | cmakeFile = Path(os.path.join(self.recipe_folder, "CMakeLists.txt")) 37 | pkgVersion = "x.x.x" 38 | with cmakeFile.open("r") as f: 39 | content = f.read() 40 | pkgVersion = re.search(r"project((.|\n)*)VERSION (.*)", content).group(3) 41 | 42 | self.version = pkgVersion.strip() 43 | 44 | package_type = "library" 45 | 46 | # Binary configuration 47 | settings = "os", "compiler", "build_type", "arch" 48 | options = { 49 | "shared": [True, False], 50 | "fPIC": [True, False], 51 | "python": [True, False], 52 | "docs": [True, False], 53 | "tests": [True, False] 54 | } 55 | default_options = { 56 | "shared": False, 57 | "fPIC": True, 58 | "python": False, 59 | "docs": False, 60 | "tests": False 61 | } 62 | 63 | # Source in same place as this recipe 64 | exports_sources = "apps/*", "cmake/*", "data/*", "docs/*", "python/*", "src/*", "CMakeLists.txt" 65 | 66 | def config_options(self): 67 | if self.settings.os == "Windows": 68 | self.options.rm_safe("fPIC") 69 | 70 | def configure(self): 71 | if self.options.shared: 72 | self.options.rm_safe("fPIC") 73 | 74 | def validate(self): 75 | check_min_cppstd(self, "17") 76 | if self.settings.os == "Windows" and self.settings.arch != "x86_64": 77 | raise ConanInvalidConfiguration("Only 64-bit architecture supported on Windows.") 78 | 79 | def system_requirements(self): 80 | # define system dependencies 81 | packages = ["setuptools", "virtualenv", "wheel"] 82 | subprocess.check_call([sys.executable, "-m", "pip", "install"] + packages) 83 | 84 | def requirements(self): 85 | # define dependencies 86 | if self.options.python: 87 | self.requires("pybind11/2.13.5") 88 | 89 | def build_requirements(self): 90 | # define build tools dependencies 91 | self.tool_requires("cmake/3.27.0") 92 | 93 | def layout(self): 94 | cmake_layout(self) 95 | # This "includedirs" starts in the source folder, which is "." by default setting in cmake_layout 96 | self.cpp.source.components["tas_client"].includedirs = ["src/tas_client"] 97 | self.cpp.source.components["tas_socket"].includedirs = ["src/tas_socket"] 98 | # compiled libraries "libdirs" will be inside the "build" folder, depending 99 | # on the platform they will be in "build/Release" or directly in "build" folder 100 | if self.settings.os != "Windows": 101 | self.cpp.build.components["tas_client"].libdirs = ["src/tas_client"] 102 | self.cpp.build.components["tas_socket"].libdirs = ["src/tas_socket"] 103 | else: 104 | self.cpp.build.components["tas_client"].libdirs = ["src/tas_client/"+str(self.settings.build_type)] 105 | self.cpp.build.components["tas_socket"].libdirs = ["src/tas_socket/"+str(self.settings.build_type)] 106 | 107 | def generate(self): 108 | # convert conan variables into build-system files 109 | deps = CMakeDeps(self) # -> creates FindXXX.cmake (sets paths to XXX lib files in conan cache) 110 | deps.generate() 111 | tc = CMakeToolchain(self) # -> conantoolchain.cmake (variables translated from conan settings) 112 | tc.cache_variables["TAS_CLIENT_API_BUILD_PYTHON"] = self.options.python 113 | tc.cache_variables["TAS_CLIENT_API_BUILD_DOCS"] = self.options.docs 114 | tc.cache_variables["TAS_CLIENT_API_BUILD_TEST"] = self.options.tests 115 | tc.generate() 116 | 117 | 118 | def build(self): 119 | # invoke the build system, reading generated files 120 | cmake = CMake(self) # CMake helper auto-formats CLI arguments for CMake 121 | cmake.configure() # cmake -DCMAKE_TOOLCHAIN_FILE=conantoolchain.cmake 122 | cmake.build() # cmake --build . 123 | 124 | def package(self): 125 | # copy artifacts from "build" to "package" directory 126 | cmake = CMake(self) # For CMake projects which define an install target, leverage it 127 | cmake.install() # cmake --build . --target=install 128 | # sets CMAKE_INSTALL_PREFIX to appropriate directory in conan cache 129 | 130 | def package_info(self): 131 | # declare whats in the package for consumers 132 | self.cpp_info.components["tas_client"].libs = ["tas_client"] 133 | self.cpp_info.components["tas_client"].requires = ["tas_socket"] 134 | self.cpp_info.components["tas_client"].includedirs = ["include/tas_client"] 135 | 136 | self.cpp_info.components["tas_socket"].libs = ["tas_socket"] 137 | self.cpp_info.components["tas_socket"].includedirs = ["include/tas_socket"] -------------------------------------------------------------------------------- /data/icons/TAS_icon_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Infineon/tas_client_api/f75d55098a6491844c95eb21df4617d2b109777a/data/icons/TAS_icon_small.png -------------------------------------------------------------------------------- /docs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # Source documentation 3 | # ----------------------------------------------------------------------------- 4 | if (NOT TAS_CLIENT_API_BUILD_DOCS) 5 | return() 6 | endif() 7 | 8 | find_package(Doxygen) 9 | if(Doxygen_FOUND) 10 | # Doxygen settings 11 | set(DOCS_PROJECT_NAME "TAS Client API") 12 | set(DOCS_LOGO "${CMAKE_SOURCE_DIR}/data/icons/TAS_icon_small.png") 13 | set(DOCS_EXTRA_FILES "${CMAKE_SOURCE_DIR}/data/icons/TAS_icon_small.png") 14 | 15 | # Directories and files relevant for documentation 16 | list(APPEND DOCS_SRC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/mainpage.md) 17 | list(APPEND DOCS_SRC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/client_rw_api.md) 18 | list(APPEND DOCS_SRC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/client_chl_api.md) 19 | list(APPEND DOCS_SRC_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/client_trc_api.md) 20 | list(APPEND DOCS_SRC_DIRS ${CMAKE_SOURCE_DIR}/src) 21 | list(APPEND DOCS_SRC_DIRS ${CMAKE_SOURCE_DIR}/apps) 22 | string(REPLACE ";" " \\\n" DOCS_SRC_DIRS "${DOCS_SRC_DIRS}") 23 | # Doxygen settings 24 | 25 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) 26 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) 27 | 28 | # Doxyfile.in contains cmake variables e.g. @CMAKE_PROJECT_NAME@ 29 | configure_file( ${doxyfile_in} ${doxyfile} @ONLY ) 30 | 31 | add_custom_target(docs_doxygen ALL 32 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} 33 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 34 | COMMENT "Generating API documentation with Doxygen" 35 | VERBATIM 36 | ) 37 | else() 38 | message(STATUS "${CMAKE_PROJECT_NAME}: Doxygen not found, building documentation is skipped") 39 | endif() -------------------------------------------------------------------------------- /docs/client_chl_api.md: -------------------------------------------------------------------------------- 1 | TAS Client CHL API {#client_chl_api} 2 | =============================================================================== -------------------------------------------------------------------------------- /docs/client_rw_api.md: -------------------------------------------------------------------------------- 1 | TAS Client RW API {#client_rw_api} 2 | =============================================================================== -------------------------------------------------------------------------------- /docs/client_trc_api.md: -------------------------------------------------------------------------------- 1 | TAS Client TRC API {#client_trc_api} 2 | =============================================================================== 3 | 4 | TBD -------------------------------------------------------------------------------- /docs/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | $projectname: $title 10 | $title 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | $treeview 21 | $search 22 | $mathjax 23 | $darkmode 24 | 25 | $extrastylesheet 26 | 27 | 28 | 29 | 30 |
31 | 32 | 33 | 34 |
35 | 36 | 37 |
38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 50 | 51 | 52 | 53 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
46 |
$projectname $projectnumber 47 |
48 |
$projectbrief
49 |
54 |
$projectbrief
55 |
$searchbox
$searchbox
73 |
74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/mainpage.md: -------------------------------------------------------------------------------- 1 | Tool Access Socket (TAS) Client API {#mainpage} 2 | =============================================================================== 3 | 4 | The Tool Access Socket (TAS) Client API can be used in line with Infineon's Microcontroller Starter Kits, Application 5 | Kits and DAP miniWiggler. All access is done through a TAS server, which can be downloaded and installed with the latest 6 | release of [DAS](https://www.infineon.com/DAS). Applications using the TAS Client API are then able to communicate whit 7 | the installed TAS server. In case of any breaking changes to the TAS protocol, the TAS server will be updated accordingly. 8 | 9 | A Tool access hardware (JTAG, DAP, SPD, SWD) can be found here: [DAP miniWiggler](https://www.infineon.com/cms/en/product/evaluation-boards/kit_miniwiggler_3_usb/?redirId=54610) 10 | 11 | What you are reading is a TAS Client API reference documentation, which does not cover a design of debug tools, but 12 | gives an overview of the API and it's usage. The following subpages go in more detail in respect to different types of 13 | clients supported by the TAS architecture. 14 | 15 | - @ref Read_Write_API 16 | - @ref Channel_API 17 | - @ref Trace_API 18 | 19 | In addition to the above descriptions, the repository includes demo projects, which demonstrate the basic usage of each 20 | API. 21 | -------------------------------------------------------------------------------- /python/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Check if python wrapper should be built 2 | if (NOT TAS_CLIENT_API_BUILD_PYTHON) 3 | return() 4 | endif() 5 | 6 | # ----------------------------------------------------------------------------- 7 | # Python project definition 8 | # ----------------------------------------------------------------------------- 9 | set(PYTHON_PROJECT PyTAS) 10 | message(STATUS "Python project: ${PYTHON_PROJECT}") 11 | set(PYTHON_PROJECT_DIR ${PROJECT_BINARY_DIR}/python/src/${PYTHON_PROJECT}) 12 | message(STATUS "Python project build path: ${PYTHON_PROJECT_DIR}") 13 | 14 | # ----------------------------------------------------------------------------- 15 | # Find relevant dependencies 16 | # ----------------------------------------------------------------------------- 17 | # Uncomment and spcify the root of Python installation if specific version should be used, otherwise the system default 18 | # is selected 19 | if (WIN32) 20 | #set(Python3_ROOT_DIR "C:\\Program Files\\Python311") 21 | elseif (UNIX) 22 | #set(Python3_ROOT_DIR "/usr/bin/python3.11") 23 | endif() 24 | 25 | set(PYBIND11_FINDPYTHON ON) 26 | find_package(pybind11 CONFIG REQUIRED) 27 | 28 | if (NOT pybind11_FOUND) 29 | message(FATAL_ERROR "pybind11 not found ${pybind11_FOUND}. Dependecies managed by conan, run 'conan install . -o python=True' first") 30 | endif() 31 | 32 | # ================================ General configuration ====================================== 33 | # Solution for an open issue due to installed python debug libs: https://github.com/pybind/pybind11/issues/3403 34 | set_target_properties(Python::Module PROPERTIES 35 | MAP_IMPORTED_CONFIG_DEBUG ";RELEASE") 36 | 37 | # Setup virtual pyton environment for testing and stub gen 38 | # Setup variables for targeting a virtual environment 39 | set(VENV_DIR "${CMAKE_CURRENT_BINARY_DIR}/pytas_venv") 40 | if(CMAKE_SYSTEM_NAME STREQUAL "Windows") 41 | set(VENV_BIN "${VENV_DIR}/Scripts") 42 | elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin" OR CMAKE_SYSTEM_NAME STREQUAL "Linux") 43 | set(VENV_BIN "${VENV_DIR}/bin") 44 | else() 45 | message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") 46 | endif() 47 | 48 | # Create virtual environment 49 | if(NOT EXISTS ${VENV_DIR}) 50 | message(STATUS "Creating virtual environment...") 51 | execute_process( 52 | COMMAND ${Python_EXECUTABLE} -m venv ${VENV_DIR} 53 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 54 | ) 55 | endif() 56 | 57 | cmake_path(GET Python_EXECUTABLE FILENAME Python_EXECUTABLE_NAME) 58 | find_program(Python_VENV_EXECUTABLE NAMES ${Python_EXECUTABLE_NAME} PATHS ${VENV_BIN} NO_CACHE NO_DEFAULT_PATH) 59 | message(STATUS "Python executable in venv: ${Python_VENV_EXECUTABLE}") 60 | 61 | if(NOT Python_VENV_EXECUTABLE) 62 | message(FATAL_ERROR "Python executable not found in virtual environment: ${Python_VENV_EXECUTABLE}") 63 | endif() 64 | 65 | # Install required Python packages 66 | message(STATUS "Venv exe: ${Python_VENV_EXECUTABLE}") 67 | execute_process( 68 | COMMAND ${Python_VENV_EXECUTABLE} -m pip install -r ${CMAKE_CURRENT_SOURCE_DIR}/requirements.txt 69 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 70 | ) 71 | 72 | # =============================== CMake target - bindings_library ============================= 73 | pybind11_add_module(PyTAS 74 | binding/tas_python_binding.cpp 75 | binding/tas_python_binding.hpp 76 | binding/tas_python_client_server_con.cpp 77 | binding/tas_python_client_server_con.hpp 78 | binding/tas_python_client_rw_base.cpp 79 | binding/tas_python_client_rw_base.hpp 80 | binding/tas_python_client_rw.hpp 81 | binding/tas_python_client_chl.cpp 82 | binding/tas_python_client_chl.hpp 83 | binding/tas_python_client_trc.cpp 84 | binding/tas_python_client_trc.hpp 85 | ) 86 | 87 | target_include_directories(PyTAS 88 | PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/binding" 89 | ) 90 | 91 | 92 | 93 | # ----------------------------------------------------------------------------- 94 | # Python package 95 | # ----------------------------------------------------------------------------- 96 | file(GENERATE OUTPUT ${PYTHON_PROJECT_DIR}/__init__.py CONTENT "__version__ = \"${PROJECT_VERSION}\"\n\nfrom PyTAS import *") 97 | 98 | # setup.py.in contains cmake variable e.g. @PYTHON_PROJECT@ and 99 | # generator expression e.g. $ 100 | configure_file( 101 | ${PROJECT_SOURCE_DIR}/cmake/templates/setup.py.in 102 | ${PROJECT_BINARY_DIR}/python/setup.py.in 103 | @ONLY 104 | ) 105 | 106 | # This step is required to trigger the generator expressions 107 | file(GENERATE 108 | OUTPUT ${PROJECT_BINARY_DIR}/python/setup.py 109 | INPUT ${PROJECT_BINARY_DIR}/python/setup.py.in 110 | ) 111 | 112 | add_custom_command( 113 | OUTPUT dist/timestamp 114 | COMMAND ${CMAKE_COMMAND} -E remove_directory dist 115 | COMMAND ${CMAKE_COMMAND} -E make_directory ${PYTHON_PROJECT_DIR}/.libs 116 | 117 | COMMAND ${CMAKE_COMMAND} -E copy $ ${PYTHON_PROJECT_DIR} 118 | 119 | COMMAND ${Python_VENV_EXECUTABLE} setup.py sdist bdist_wheel 120 | COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/dist/timestamp 121 | 122 | DEPENDS 123 | setup.py 124 | 125 | BYPRODUCTS 126 | ${PYTHON_PROJECT} 127 | ${PYTHON_PROJECT}.egg-info 128 | build 129 | dist 130 | 131 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 132 | COMMAND_EXPAND_LISTS 133 | ) 134 | 135 | add_custom_target(python_package ALL 136 | DEPENDS 137 | dist/timestamp 138 | WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/python 139 | ) 140 | 141 | # ----------------------------------------------------------------------------- 142 | # Python tests 143 | # ----------------------------------------------------------------------------- 144 | # Check if the Python executable exists 145 | if(NOT Python_VENV_EXECUTABLE) 146 | message(FATAL_ERROR "Python executable not found in virtual environment.") 147 | endif() 148 | 149 | # Install the .whl file using a custom script to ensure platform independence 150 | file(WRITE ${CMAKE_BINARY_DIR}/install_whl.py 151 | "import os 152 | import subprocess 153 | import glob 154 | 155 | whl_dir = os.path.join('${CMAKE_CURRENT_BINARY_DIR}', 'dist') 156 | whl_files = glob.glob(os.path.join(whl_dir, '*.whl')) 157 | 158 | if whl_files: 159 | for whl_file in whl_files: 160 | print(f'Installing {whl_file}') 161 | subprocess.check_call(['${Python_VENV_EXECUTABLE}', '-m', 'pip', 'install', '--force-reinstall', '--no-deps', '--upgrade', whl_file]) 162 | else: 163 | raise FileNotFoundError('No .whl file found in the specified directory') 164 | ") 165 | 166 | add_custom_command(TARGET python_package POST_BUILD 167 | COMMAND ${Python_VENV_EXECUTABLE} ${CMAKE_BINARY_DIR}/install_whl.py 168 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 169 | COMMENT "Installing ${PYTHON_PROJECT}" 170 | VERBATIM 171 | ) 172 | 173 | # add_python_test() 174 | # CMake function to generate and build python test. 175 | # Parameters: 176 | # the python filename 177 | # e.g.: 178 | # add_python_test(foo.py) 179 | function(add_python_test FILE_NAME) 180 | message(STATUS "Configuring test ${FILE_NAME} ...") 181 | get_filename_component(EXAMPLE_NAME ${FILE_NAME} NAME_WE) 182 | 183 | if(BUILD_TESTING) 184 | add_test( 185 | NAME python_test_${EXAMPLE_NAME} 186 | COMMAND ${Python_VENV_EXECUTABLE} ${FILE_NAME} 187 | WORKING_DIRECTORY ${VENV_DIR}) 188 | endif() 189 | message(STATUS "Configuring test ${FILE_NAME} done") 190 | endfunction() 191 | 192 | add_python_test(${CMAKE_CURRENT_SOURCE_DIR}/tests/tas_python_client_rw_test.py) 193 | add_python_test(${CMAKE_CURRENT_SOURCE_DIR}/tests/tas_python_client_server_test.py) -------------------------------------------------------------------------------- /python/README.md: -------------------------------------------------------------------------------- 1 | # Python wrapper for TAS client APIs 2 | 3 | ## Installation 4 | 5 | ## Usage 6 | ### TAS Client RW API 7 | ### TAS Client CHL API 8 | ### TAS Client TRC API -------------------------------------------------------------------------------- /python/binding/tas_python_binding.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "tas_python_client_rw.hpp" 27 | #include "tas_python_client_chl.hpp" 28 | #include "tas_python_client_trc.hpp" -------------------------------------------------------------------------------- /python/binding/tas_python_client_chl.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #include "tas_python_client_chl.hpp" 21 | 22 | tas_return_et TasClientChl::session_start(const char* identifier, const char* session_id, const char* session_pw, tas_chl_target_et chl_target, uint64_t chl_param) 23 | { 24 | return client.session_start(identifier, session_id, session_pw, chl_target, chl_param); 25 | } 26 | 27 | tas_return_et TasClientChl::subscribe(uint8_t chl, tas_cht_et cht, tas_chso_et chso, uint8_t* prio){ 28 | return client.subscribe(chl, cht, chso, prio); 29 | } 30 | 31 | tas_return_et TasClientChl::unsubscribe(){ 32 | return client.unsubscribe(); 33 | } 34 | 35 | tas_return_et TasClientChl::send_msg(pybind11::bytes message, uint32_t init){ 36 | char* msg; 37 | Py_ssize_t msg_length; 38 | 39 | PyBytes_AsStringAndSize(message.ptr(), &msg, &msg_length); 40 | 41 | return client.send_msg((const void*)msg, (uint16_t)msg_length, init); 42 | } 43 | 44 | tas_return_et TasClientChl::send_string(std::string message, uint32_t init){ 45 | pybind11::bytes msg(message.c_str(), message.length()+1); 46 | 47 | return send_msg(msg, init); 48 | } 49 | 50 | pybind11::tuple TasClientChl::rcv_msg(uint32_t timeout_ms){ 51 | char* message = nullptr; 52 | uint16_t message_length; 53 | uint32_t init; 54 | 55 | tas_return_et ret = client.rcv_msg(timeout_ms, (const void**)&message, &message_length, &init); 56 | 57 | pybind11::bytes msg(message, message_length); 58 | 59 | return pybind11::make_tuple(msg, init, ret); 60 | } 61 | 62 | pybind11::tuple TasClientChl::rcv_string(uint32_t timeout_ms){ 63 | char* message = nullptr; 64 | uint16_t message_length; 65 | uint32_t init; 66 | 67 | tas_return_et ret = client.rcv_msg(timeout_ms, (const void**)&message, &message_length, &init); 68 | 69 | py::str pMessage(message, message_length); 70 | 71 | return pybind11::make_tuple(pMessage, init, ret); 72 | } -------------------------------------------------------------------------------- /python/binding/tas_python_client_chl.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include "tas_python_client_server_con.hpp" 26 | 27 | 28 | class TasClientChl : public TasClientServerCon 29 | { 30 | public: 31 | tas_return_et session_start(const char* identifier, const char* session_id = "", const char* session_pw = "", tas_chl_target_et chl_target = TAS_CHL_TGT_DMM, uint64_t chl_param = 0); 32 | 33 | tas_return_et subscribe(uint8_t chl, tas_cht_et cht, tas_chso_et chso = TAS_CHSO_EXCLUSIVE, uint8_t* prio = nullptr); 34 | 35 | tas_return_et unsubscribe(); 36 | 37 | tas_return_et send_msg(pybind11::bytes message, uint32_t init = 0); 38 | 39 | tas_return_et send_string(std::string message, uint32_t init = 0); 40 | 41 | pybind11::tuple rcv_msg(uint32_t timeout_ms); 42 | 43 | pybind11::tuple rcv_string(uint32_t timeout_ms); 44 | 45 | TasClientChl(const char* client_name) : client(client_name), TasClientServerCon(client){}; 46 | 47 | private: 48 | CTasClientChl client; 49 | 50 | }; -------------------------------------------------------------------------------- /python/binding/tas_python_client_rw.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include "tas_python_client_rw_base.hpp" 25 | #include "tas_python_client_server_con.hpp" 26 | 27 | class TasClientRw : public TasClientRwBase, public TasClientServerCon 28 | { 29 | public: 30 | tas_return_et session_start(const char* identifier, const char* session_id = "", const char* session_pw = ""){ 31 | return client.session_start(identifier, session_id, session_pw); 32 | } 33 | 34 | TasClientRw(const char* client_name) : client(client_name), TasClientServerCon(client), TasClientRwBase(client){ 35 | }; 36 | 37 | private: 38 | CTasClientRw client; 39 | 40 | }; -------------------------------------------------------------------------------- /python/binding/tas_python_client_rw_base.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #include "tas_python_client_rw_base.hpp" 21 | 22 | pybind11::tuple TasClientRwBase::read8(uint64_t addr, uint8_t addr_map){ 23 | uint8_t value; 24 | tas_return_et ret = clientRwBase->read8(addr, &value, addr_map); 25 | return pybind11::make_tuple(value, ret); 26 | } 27 | 28 | tas_return_et TasClientRwBase::write8(uint64_t addr, uint8_t value, uint8_t addr_map){ 29 | return clientRwBase->write8(addr, value, addr_map); 30 | } 31 | 32 | pybind11::tuple TasClientRwBase::read16(uint64_t addr, uint8_t addr_map){ 33 | uint16_t value; 34 | tas_return_et ret = clientRwBase->read16(addr, &value, addr_map); 35 | return pybind11::make_tuple(value, ret); 36 | } 37 | 38 | tas_return_et TasClientRwBase::write16(uint64_t addr, uint16_t value, uint8_t addr_map){ 39 | return clientRwBase->write16(addr, value, addr_map); 40 | } 41 | 42 | pybind11::tuple TasClientRwBase::read32(uint64_t addr, uint8_t addr_map){ 43 | uint32_t value; 44 | tas_return_et ret = clientRwBase->read32(addr, &value, addr_map); 45 | return pybind11::make_tuple(value, ret); 46 | } 47 | 48 | tas_return_et TasClientRwBase::write32(uint64_t addr, uint32_t value, uint8_t addr_map){ 49 | return clientRwBase->write32(addr, value, addr_map); 50 | } 51 | 52 | pybind11::tuple TasClientRwBase::read64(uint64_t addr, uint8_t addr_map){ 53 | uint64_t value; 54 | tas_return_et ret = clientRwBase->read64(addr, &value, addr_map); 55 | return pybind11::make_tuple(value, ret); 56 | } 57 | 58 | tas_return_et TasClientRwBase::write64(uint64_t addr, uint64_t value, uint8_t addr_map){ 59 | return clientRwBase->write64(addr, value, addr_map); 60 | } 61 | 62 | pybind11::tuple TasClientRwBase::read(uint64_t addr, uint32_t num_bytes, uint8_t addr_map){ 63 | uint8_t* values = new uint8_t[num_bytes]; 64 | uint32_t num_bytes_ok; 65 | 66 | tas_return_et ret = clientRwBase->read(addr, values, num_bytes, &num_bytes_ok, addr_map); 67 | 68 | pybind11::bytes data((char*)values, num_bytes_ok); 69 | 70 | delete[] values; 71 | 72 | return pybind11::make_tuple(data, ret); 73 | } 74 | 75 | pybind11::tuple TasClientRwBase::write(uint64_t addr, pybind11::bytes data, uint8_t addr_map){ 76 | uint32_t num_bytes_ok; 77 | 78 | char* c_data; 79 | Py_ssize_t data_length; 80 | 81 | PyBytes_AsStringAndSize(data.ptr(), &c_data, &data_length); 82 | 83 | tas_return_et ret = clientRwBase->write(addr, (const void*)c_data, (uint32_t)data_length, &num_bytes_ok, addr_map); 84 | return pybind11::make_tuple(num_bytes_ok, ret); 85 | } 86 | 87 | tas_return_et TasClientRwBase::fill32(uint64_t addr, uint32_t value, uint32_t num_bytes, uint8_t addr_map){ 88 | return clientRwBase->fill32(addr, value, num_bytes, addr_map); 89 | } 90 | 91 | tas_return_et TasClientRwBase::fill64(uint64_t addr, uint64_t value, uint32_t num_bytes, uint8_t addr_map){ 92 | return clientRwBase->fill64(addr, value, num_bytes, addr_map); 93 | } 94 | 95 | pybind11::tuple TasClientRwBase::execute_trans(pybind11::list &trans){ 96 | tas_rw_trans_st* trans_a = new tas_rw_trans_st[trans.size()]; 97 | 98 | for (int i = 0; i < trans.size(); i++) 99 | { 100 | TasRwTransaction tran = trans[i].cast(); 101 | 102 | trans_a[i].addr = tran.addr; 103 | trans_a[i].num_bytes = tran.num_bytes; 104 | trans_a[i].acc_mode = 0; 105 | trans_a[i].addr_map = 0; 106 | trans_a[i].type = tran.type; 107 | 108 | if(tran.type == TAS_RW_TT_RD){ 109 | trans_a[i].rdata = (void*)new char[tran.num_bytes]; 110 | }else{ 111 | trans_a[i].wdata = (const void*)PyBytes_AsString(tran.data.ptr()); 112 | } 113 | } 114 | 115 | tas_return_et ret = clientRwBase->execute_trans(trans_a, (uint32_t)trans.size()); 116 | 117 | pybind11::list new_trans; 118 | 119 | for (int i = 0; i < trans.size(); i++) 120 | { 121 | TasRwTransaction tran = trans[i].cast(); 122 | 123 | if(tran.type == TAS_RW_TT_RD){ 124 | pybind11::bytes data((char*)trans_a[i].rdata, trans_a[i].num_bytes); 125 | tran.data = data; 126 | delete[] trans_a[i].rdata; 127 | } 128 | 129 | new_trans.append(tran); 130 | } 131 | 132 | delete[] trans_a; 133 | 134 | return pybind11::make_tuple(new_trans, ret); 135 | } 136 | 137 | TasClientRwBase::TasClientRwBase(CTasClientRwBase& c){ 138 | clientRwBase = &c; 139 | } 140 | 141 | TasClientRwBase::TasClientRwBase(uint32_t max_rsp_size){ 142 | clientRwBase = new CTasClientRwBase(max_rsp_size); 143 | } -------------------------------------------------------------------------------- /python/binding/tas_python_client_rw_base.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | typedef struct { 27 | uint64_t addr; 28 | uint32_t num_bytes; 29 | tas_rw_trans_type_et type; 30 | pybind11::bytes data; 31 | } TasRwTransaction; 32 | 33 | typedef enum : uint8_t { 34 | TAS_AM_0 = 0, // Default for device access 35 | TAS_AM_1 = 1, // Auxiliary address map for device access. E.g. direct EEC access of AURIX EDs 36 | TAS_AM_12 = 12, // All address maps equal or higher than 12 are for special usage 37 | TAS_AM_14 = 14, // Exclusively used in the TasProxyServer inside of the device 38 | TAS_AM_15 = 15, // Exclusively used inside of the TasServer 39 | TAS_AM_132 = 132, // Converted to TAS_AM15 during TasClient packet request generation 40 | }TasAddrMap; 41 | 42 | class TasClientRwBase{ 43 | public: 44 | pybind11::tuple read8(uint64_t addr, uint8_t addr_map = TAS_AM0); 45 | 46 | tas_return_et write8(uint64_t addr, uint8_t value, uint8_t addr_map = TAS_AM0); 47 | 48 | pybind11::tuple read16(uint64_t addr, uint8_t addr_map = TAS_AM0); 49 | 50 | tas_return_et write16(uint64_t addr, uint16_t value, uint8_t addr_map = TAS_AM0); 51 | 52 | pybind11::tuple read32(uint64_t addr, uint8_t addr_map = TAS_AM0); 53 | 54 | tas_return_et write32(uint64_t addr, uint32_t value, uint8_t addr_map = TAS_AM0); 55 | 56 | pybind11::tuple read64(uint64_t addr, uint8_t addr_map = TAS_AM0); 57 | 58 | tas_return_et write64(uint64_t addr, uint64_t value, uint8_t addr_map = TAS_AM0); 59 | 60 | pybind11::tuple read(uint64_t addr, uint32_t num_bytes, uint8_t addr_map = TAS_AM0); 61 | 62 | pybind11::tuple write(uint64_t addr, pybind11::bytes data, uint8_t addr_map = TAS_AM0); 63 | 64 | pybind11::tuple execute_trans(pybind11::list &trans); 65 | 66 | tas_return_et fill32(uint64_t addr, uint32_t value, uint32_t num_bytes, uint8_t addr_map = TAS_AM0); 67 | 68 | tas_return_et fill64(uint64_t addr, uint64_t value, uint32_t num_bytes, uint8_t addr_map = TAS_AM0); 69 | 70 | TasClientRwBase(CTasClientRwBase& c); 71 | 72 | TasClientRwBase(uint32_t max_rsp_size = CTasPktHandlerRw::RSP_PKT_BUF_SIZE_DEFAULT); 73 | 74 | private: 75 | CTasClientRwBase* clientRwBase; 76 | 77 | }; 78 | -------------------------------------------------------------------------------- /python/binding/tas_python_client_server_con.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #include "tas_python_client_server_con.hpp" 21 | 22 | const char* TasClientServerCon::get_error_info(){ 23 | return clientServerCon->get_error_info(); 24 | } 25 | 26 | tas_return_et TasClientServerCon::server_connect(const char* ip_addr, uint16_t port_num){ 27 | return clientServerCon->server_connect(ip_addr, port_num); 28 | } 29 | 30 | const char* TasClientServerCon::get_server_ip_addr() { 31 | return clientServerCon->get_server_ip_addr(); 32 | } 33 | 34 | uint16_t TasClientServerCon::get_server_port_num() { 35 | return clientServerCon->get_server_port_num(); 36 | } 37 | 38 | const tas_server_info_st TasClientServerCon::get_server_info() { 39 | return *(clientServerCon->get_server_info()); 40 | } 41 | 42 | uint64_t TasClientServerCon::get_server_challenge() { 43 | return clientServerCon->get_server_challenge(); 44 | } 45 | 46 | tas_return_et TasClientServerCon::server_unlock(py::bytes key){ 47 | char *key_c = nullptr; 48 | Py_ssize_t key_length = 0; 49 | 50 | PyBytes_AsStringAndSize(key.ptr(), &key_c, &key_length); 51 | 52 | return clientServerCon->server_unlock((const void*)key_c, (uint16_t)key_length); 53 | } 54 | 55 | py::tuple TasClientServerCon::get_targets(){ 56 | tas_target_info_st* target_info = nullptr; 57 | uint32_t num_target = 0; 58 | 59 | tas_return_et ret = clientServerCon->get_targets((const tas_target_info_st**)&target_info, &num_target); 60 | 61 | py::list targets; 62 | for(uint32_t i = 0; i < num_target; i++){ 63 | targets.append(target_info[i]); 64 | } 65 | 66 | return py::make_tuple(targets, ret); 67 | } 68 | 69 | py::tuple TasClientServerCon::get_target_clients(const char* identifier){ 70 | tas_target_client_info_st* target_client_info = nullptr; 71 | char* session_name = nullptr; 72 | uint64_t session_start_time_us = 0; 73 | uint32_t num_client = 0; 74 | 75 | tas_return_et ret = clientServerCon->get_target_clients(identifier, (const char**)&session_name, &session_start_time_us, (const tas_target_client_info_st**)&target_client_info, &num_client); 76 | 77 | py::list target_clients; 78 | 79 | for(uint32_t i = 0; i < num_client; i++){ 80 | target_clients.append(target_client_info[i]); 81 | } 82 | 83 | py::str s_name(session_name); 84 | 85 | return py::make_tuple(target_clients, s_name, session_start_time_us, ret); 86 | } 87 | 88 | const tas_con_info_st TasClientServerCon::get_con_info() { 89 | const tas_con_info_st *info = clientServerCon->get_con_info(); 90 | 91 | return *info; 92 | } 93 | 94 | tas_device_family_t TasClientServerCon::get_device_family(uint32_t device_type){ 95 | return tas_get_device_family(device_type); 96 | } 97 | 98 | py::tuple TasClientServerCon::device_unlock_get_challenge(tas_dev_unlock_cr_option_et ulcro){ 99 | char* challenge = nullptr; 100 | uint16_t challenge_length = 0; 101 | 102 | tas_return_et ret = clientServerCon->device_unlock_get_challenge(ulcro, (const void**)&challenge, &challenge_length); 103 | 104 | py::bytes py_challenge(challenge, challenge_length); 105 | 106 | return py::make_tuple(py_challenge, ret); 107 | } 108 | 109 | tas_return_et TasClientServerCon::device_unlock_set_key(tas_dev_unlock_option_et ulo, py::bytes key){ 110 | char *key_c = nullptr; 111 | Py_ssize_t key_length = 0; 112 | 113 | PyBytes_AsStringAndSize(key.ptr(), &key_c, &key_length); 114 | 115 | return clientServerCon->device_unlock_set_key(ulo, (const void*)key_c, (uint16_t)key_length); 116 | } 117 | 118 | tas_return_et TasClientServerCon::device_connect(tas_clnt_dco_et dco){ 119 | return clientServerCon->device_connect(dco); 120 | } 121 | 122 | bool TasClientServerCon::device_reset_occurred(){ 123 | return clientServerCon->device_reset_occurred(); 124 | } 125 | 126 | TasClientServerCon::TasClientServerCon(CTasClientServerCon& c) 127 | { 128 | clientServerCon = &c; 129 | }; -------------------------------------------------------------------------------- /python/binding/tas_python_client_server_con.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | namespace py = pybind11; 30 | 31 | class TasClientServerCon{ 32 | public: 33 | 34 | TasClientServerCon(CTasClientServerCon& c); 35 | 36 | const char* get_error_info(); 37 | 38 | tas_return_et server_connect(const char* ip_addr, uint16_t port_num = TAS_PORT_NUM_SERVER_DEFAULT); 39 | 40 | const char* get_server_ip_addr(); 41 | 42 | uint16_t get_server_port_num(); 43 | 44 | const tas_server_info_st get_server_info(); 45 | 46 | uint64_t get_server_challenge(); 47 | 48 | tas_return_et server_unlock(py::bytes key); 49 | 50 | py::tuple get_targets(); 51 | 52 | py::tuple get_target_clients(const char* identifier); 53 | 54 | const tas_con_info_st get_con_info(); 55 | 56 | tas_device_family_t get_device_family(uint32_t device_type); 57 | 58 | py::tuple device_unlock_get_challenge(tas_dev_unlock_cr_option_et ulcro); 59 | 60 | tas_return_et device_unlock_set_key(tas_dev_unlock_option_et ulo, py::bytes key); 61 | 62 | tas_return_et device_connect(tas_clnt_dco_et dco); 63 | 64 | bool device_reset_occurred(); 65 | 66 | private: 67 | CTasClientServerCon* clientServerCon; 68 | }; -------------------------------------------------------------------------------- /python/binding/tas_python_client_trc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #include "tas_python_client_trc.hpp" 21 | 22 | pybind11::tuple TasClientTrc::subscribe(uint8_t stream, tas_chso_et chso){ 23 | tas_trc_type_et trct; 24 | 25 | tas_return_et ret = client.subscribe(&trct, stream, chso); 26 | 27 | return pybind11::make_tuple(trct, ret); 28 | } 29 | 30 | tas_return_et TasClientTrc::unsubscribe(uint8_t stream){ 31 | return client.unsubscribe(stream); 32 | } 33 | 34 | pybind11::tuple TasClientTrc::rcv_trace(uint32_t timeout_ms, uint8_t* stream){ 35 | char* trace_data = nullptr; 36 | uint32_t length; 37 | tas_trcs_et trcs; 38 | 39 | tas_return_et ret = client.rcv_trace(timeout_ms, (const void**)&trace_data, &length, &trcs, stream); 40 | 41 | pybind11::bytes trc((char*)(*trace_data), length); 42 | 43 | return pybind11::make_tuple(trc, trcs, *stream, ret); 44 | } -------------------------------------------------------------------------------- /python/binding/tas_python_client_trc.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | 27 | class TasClientTrc 28 | { 29 | public: 30 | 31 | pybind11::tuple subscribe(uint8_t stream = 0, tas_chso_et chso = TAS_CHSO_DEFAULT); 32 | 33 | tas_return_et unsubscribe(uint8_t stream = 0); 34 | 35 | pybind11::tuple rcv_trace(uint32_t timeout_ms, uint8_t* stream = nullptr); 36 | 37 | TasClientTrc(){}; 38 | 39 | private: 40 | CTasClientTrc client; 41 | 42 | }; -------------------------------------------------------------------------------- /python/requirements.txt: -------------------------------------------------------------------------------- 1 | setuptools 2 | build 3 | wheel 4 | numpy 5 | pybind11-stubgen -------------------------------------------------------------------------------- /python/tests/__init__.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | -------------------------------------------------------------------------------- /python/tests/tas_python_client_server_test.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | from PyTAS.PyTAS import TasClientRw, TasReturn, TasServerInfo, TasTargetInfo 20 | import numpy as np 21 | import unittest 22 | 23 | 24 | class TestTasClientServer(unittest.TestCase): 25 | SERVER_IP = "localhost" 26 | SERVER_PORT = 24817 27 | SERVER_NAME = "TasServer" 28 | SERVER_V_MIN = 0 29 | SERVER_V_MAJ = 1 30 | CLIENT_NAME = "serverTester" 31 | 32 | def test_connect_successful(self): 33 | c = TasClientRw(self.CLIENT_NAME) 34 | ret = c.server_connect(self.SERVER_IP, self.SERVER_PORT) 35 | assert ret == TasReturn.TAS_ERR_NONE, f'Check if the server is running on {self.SERVER_IP}:{self.SERVER_PORT}' 36 | pass 37 | 38 | def test_connect_unseccessful(self): 39 | c = TasClientRw(self.CLIENT_NAME) 40 | 41 | #Wrong port 42 | ret = c.server_connect(port_num=10) 43 | assert ret == TasReturn.TAS_ERR_SERVER_CON, 'Should not have connected to the server, wrong PORT' 44 | 45 | #Wrong ip 46 | ret = c.server_connect(ip_addr="192.168.1.10") 47 | assert ret == TasReturn.TAS_ERR_SERVER_CON, 'Should not have connected to the server, wrong IP' 48 | pass 49 | 50 | def test_get_ip_address(self): 51 | c = TasClientRw(self.CLIENT_NAME) 52 | c.server_connect(self.SERVER_IP, self.SERVER_PORT) 53 | ip = c.get_server_ip_addr() 54 | assert ip == self.SERVER_IP, 'Different IP address to the one connected to' 55 | pass 56 | 57 | def test_get_server_port(self): 58 | c = TasClientRw(self.CLIENT_NAME) 59 | c.server_connect(self.SERVER_IP, self.SERVER_PORT) 60 | port = c.get_server_port_num() 61 | assert port == self.SERVER_PORT, 'Different port to one connected to' 62 | pass 63 | 64 | def test_get_server_info(self): 65 | c = TasClientRw(self.CLIENT_NAME) 66 | c.server_connect(self.SERVER_IP, self.SERVER_PORT) 67 | info = c.get_server_info() 68 | 69 | assert isinstance(info, TasServerInfo) 70 | assert isinstance(info.server_name, str) 71 | assert isinstance(info.v_minor, int) 72 | assert isinstance(info.v_major, int) 73 | assert isinstance(info.date, str) 74 | assert isinstance(info.supp_protoc_ver, int) 75 | assert isinstance(info.supp_chl_target, int) 76 | assert isinstance(info.supp_trc_type, int) 77 | assert isinstance(info.start_time_us, int) 78 | pass 79 | 80 | def test_get_targets(self): 81 | c = TasClientRw(self.CLIENT_NAME) 82 | ret = c.server_connect(self.SERVER_IP, self.SERVER_PORT) 83 | 84 | targets, ret = c.get_targets() 85 | 86 | assert isinstance(ret, TasReturn) 87 | assert ret == TasReturn.TAS_ERR_NONE, 'Error getting the targets' 88 | assert isinstance(targets, list) 89 | assert len(targets)>0, 'No connected target found' 90 | assert isinstance(targets[0], TasTargetInfo) 91 | pass 92 | 93 | def test_connect_to_target(self): 94 | c = TasClientRw(self.CLIENT_NAME) 95 | ret = c.server_connect(self.SERVER_IP, self.SERVER_PORT) 96 | targets, _ = c.get_targets() 97 | 98 | assert len(targets)>0, 'No connected target found' 99 | 100 | ret = c.session_start(targets[0].identifier) 101 | 102 | assert ret == TasReturn.TAS_ERR_NONE, 'Error while connecting to the target' 103 | pass 104 | 105 | def test_get_target_clients(self): 106 | c = TasClientRw(self.CLIENT_NAME) 107 | ret = c.server_connect(self.SERVER_IP, self.SERVER_PORT) 108 | targets, _ = c.get_targets() 109 | 110 | assert len(targets)>0, 'No connected target found' 111 | 112 | ret = c.session_start(targets[0].identifier) 113 | 114 | assert ret == TasReturn.TAS_ERR_NONE 115 | 116 | clients, session_name, start_time, ret = c.get_target_clients(targets[0].identifier) 117 | 118 | assert ret == TasReturn.TAS_ERR_NONE 119 | assert isinstance(start_time, int) 120 | assert isinstance(session_name, str) 121 | assert isinstance(clients, list) 122 | 123 | found_me = False 124 | 125 | for client in clients: 126 | if client.client_name == self.CLIENT_NAME: 127 | found_me = True 128 | assert found_me, 'Username belonged to the using client not found' 129 | pass 130 | 131 | if __name__ == '__main__': 132 | unittest.main() 133 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(tas_socket) 2 | add_subdirectory(tas_client) -------------------------------------------------------------------------------- /src/tas_client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # list of sources: 3 | # ----------------------------------------------------------------------------- 4 | set(TAS_HDRS 5 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_am15_am14.h" 6 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_chl.h" 7 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_impl.h" 8 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_rw_base.h" 9 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_rw.h" 10 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_server_con.h" 11 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_trc.h" 12 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client.h" 13 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_debug.h" 14 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_device_family.h" 15 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_base.h" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_chl.h" 17 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_rw.h" 18 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_server_con.h" 19 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_trc.h" 20 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_mailbox_if.h" 21 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_mailbox_socket.h" 22 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt.h" 23 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils_ifx.h" 24 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils_jtag.h" 25 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils_client.h" 26 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils.h" 27 | ) 28 | 29 | set(TAS_SRCS 30 | "${TAS_HDRS}" 31 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_chl.cpp" 32 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_rw_base.cpp" 33 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_server_con.cpp" 34 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_client_trc.cpp" 35 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_base.cpp" 36 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_chl.cpp" 37 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_rw.cpp" 38 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_server_con.cpp" 39 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_handler_trc.cpp" 40 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_pkt_mailbox_socket.cpp" 41 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils_ifx.cpp" 42 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils_jtag.cpp" 43 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils_os.cpp" 44 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_utils.cpp" 45 | ) 46 | 47 | # ----------------------------------------------------------------------------- 48 | # include soruces in the following targets: 49 | # ----------------------------------------------------------------------------- 50 | # Python wrapper 51 | tac_add_target_sources(PyTAS "${TAS_SRCS}") 52 | 53 | # ----------------------------------------------------------------------------- 54 | # tas socket lib 55 | # ----------------------------------------------------------------------------- 56 | set(LIB_NAME tas_client) 57 | 58 | # generate IDE virtual folders where supported 59 | set(REC ".*([.]cpp|[.]h)") 60 | 61 | set(REG1 ".*/src/tas_client/") 62 | source_group("tas_client" REGULAR_EXPRESSION "${REG1}${REC}") 63 | 64 | # ----------------------------------------------------------------------------- 65 | # Add executable, its includes, and libraries 66 | # ----------------------------------------------------------------------------- 67 | add_library(${LIB_NAME} STATIC ${TAS_SRCS}) 68 | 69 | target_include_directories(${LIB_NAME} 70 | PUBLIC 71 | "$" 72 | "$" 73 | ) 74 | 75 | target_link_libraries(${LIB_NAME} tas_socket) 76 | 77 | # ----------------------------------------------------------------------------- 78 | # Compile definitions 79 | # ----------------------------------------------------------------------------- 80 | if (MSVC) 81 | target_compile_definitions(${LIB_NAME} PRIVATE 82 | "$<$:" 83 | "_DEBUG" 84 | ">" 85 | "$<$:" 86 | "NDEBUG" 87 | ">" 88 | "_CRT_SECURE_NO_WARNINGS" 89 | "_WIN32" 90 | ) 91 | elseif (UNIX) 92 | target_compile_definitions(${LIB_NAME} PRIVATE 93 | "UNIX" 94 | ) 95 | endif() 96 | 97 | # ----------------------------------------------------------------------------- 98 | # Compile and link options 99 | # ----------------------------------------------------------------------------- 100 | if (MSVC) 101 | target_compile_options(${LIB_NAME} PRIVATE 102 | /W3 103 | /MP 104 | "$<$:" 105 | "/O2" 106 | ">" 107 | ) 108 | 109 | target_link_options(${LIB_NAME} PRIVATE 110 | /SUBSYSTEM:CONSOLE 111 | ) 112 | elseif (UNIX) 113 | target_compile_options(${LIB_NAME} PRIVATE 114 | -Wall; 115 | ) 116 | endif() 117 | 118 | # ----------------------------------------------------------------------------- 119 | # Install 120 | # ----------------------------------------------------------------------------- 121 | # library 122 | install(TARGETS ${LIB_NAME} 123 | EXPORT TasClientApiTargets 124 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 125 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 126 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 127 | INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tas_client" 128 | ) 129 | 130 | # header files 131 | install(FILES ${TAS_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tas_client) 132 | -------------------------------------------------------------------------------- /src/tas_client/tas_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \defgroup Client_API TAS Client Application Programming Interface 23 | 24 | //! \defgroup Read_Write_API Read/Write (RW) 25 | //! \ingroup Client_API 26 | //! \defgroup Channel_API Channel (CHL) 27 | //! \ingroup Client_API 28 | //! \defgroup Trace_API Trace (TRC) 29 | //! \ingroup Client_API 30 | 31 | //! \addtogroup Client_API 32 | //! \{ 33 | // TAS includes 34 | #include "tas_pkt.h" 35 | 36 | // Standard includes 37 | #include 38 | #include 39 | 40 | constexpr size_t TAS_INFO_STR_LEN = 256; //!< \brief Maximum allowed string for TAS information 41 | 42 | //! \brief TAS error codes 43 | enum tas_return_et : uint16_t { 44 | TAS_ERR_NONE = 0, //!< \brief No error 45 | 46 | TAS_ERR_GENERAL = 0x0F00, //!< \brief General error. E.g. unexpected behavior of the TasServer 47 | 48 | TAS_ERR_FN_NOT_SUPPORTED = 0x0100, //!< \brief Function is e.g. not implemented 49 | TAS_ERR_FN_USAGE = 0x0110, //!< \brief TAS API not correctly used 50 | TAS_ERR_FN_PARAM = 0x0120, //!< \brief Caller passed an invalid parameter 51 | 52 | TAS_ERR_SERVER_CON = 0x0200, //!< \brief Server connection error 53 | TAS_ERR_SERVER_LOCKED = 0x0210, //!< \brief Server is locked 54 | 55 | TAS_ERR_DEVICE_ACCESS = 0x0400, //!< \brief Cannot access device (power-down, reset active, etc.) 56 | TAS_ERR_DEVICE_LOCKED = 0x0410, //!< \brief Device is locked 57 | 58 | TAS_ERR_RW_READ = 0x0600, //!< \brief Read access failed 59 | TAS_ERR_RW_WRITE = 0x0610, //!< \brief Write access failed 60 | 61 | TAS_ERR_CHL_SETUP = 0x0800, //!< \brief Channel setup failed 62 | TAS_ERR_CHL_SEND = 0x0810, //!< \brief Sending of the message has failed (e.g. buffer full). Can try again. 63 | TAS_ERR_CHL_RCV = 0x0820, //!< \brief No message was received. Can try again. 64 | 65 | TAS_ERR_TRC_RCV = 0x0A00, //!< \brief No trace data was received. Can try again. 66 | }; 67 | 68 | //! \brief Connection options for device_connect() method. 69 | enum tas_clnt_dco_et : uint16_t { 70 | TAS_CLNT_DCO_HOT_ATTACH = 0, //!< \brief Default is hot attach 71 | TAS_CLNT_DCO_RESET = TAS_DEV_CON_FEAT_RESET, //!< \brief Triggers a reset 72 | TAS_CLNT_DCO_RESET_AND_HALT = TAS_DEV_CON_FEAT_RESET_AND_HALT, //!< \brief Triggers a reset and halt 73 | TAS_CLNT_DCO_UNKNOWN = TAS_DEV_CON_FEAT_UNKNOWN, //!< \brief Connect to "unknown" device -> no device interaction 74 | TAS_CLNT_DCO_UNKNOWN_RESET = TAS_DEV_CON_FEAT_UNKNOWN_RESET, //!< \brief Reset "unknown" device -> no device interaction 75 | }; 76 | 77 | //! \brief Transaction types. 78 | enum tas_rw_trans_type_et : uint8_t { 79 | TAS_RW_TT_RD = 1, //!< \brief Indicates a read transaction 80 | TAS_RW_TT_WR = 2, //!< \brief Indicates a write transaction 81 | TAS_RW_TT_FILL = 6, //!< \brief Indicates a fill transaction 82 | }; 83 | 84 | //! \brief Read/write transaction description 85 | struct tas_rw_trans_st { 86 | uint64_t addr; //!< \brief 64-bit address on which the action is performed 87 | uint32_t num_bytes; //!< \brief Number of bytes to be read/written 88 | uint16_t acc_mode; //!< \brief Type of access mode to be used 89 | uint8_t addr_map; //!< \brief Address map 90 | tas_rw_trans_type_et type; //!< \brief Transaction type as defined by \ref tas_rw_trans_type_et 91 | union { 92 | const void* wdata; //!< \brief Data to be written 93 | void* rdata; //!< \brief Data to be read 94 | }; 95 | }; 96 | 97 | //! \brief Read/write transaction response 98 | struct tas_rw_trans_rsp_st { 99 | uint32_t num_bytes_ok; //!< \brief Number of bytes successfully read/written 100 | tas_pl_err_et8 pl_err; //!< \brief PL Error code \ref tas_pl_err_et8 101 | }; 102 | //! \} // end of group Client_API -------------------------------------------------------------------------------- /src/tas_client/tas_client_chl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Channel_API 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_client_impl.h" 27 | #include "tas_client_server_con.h" 28 | #include "tas_pkt_handler_chl.h" 29 | #include "tas_pkt_mailbox_if.h" 30 | 31 | //! \brief Class for sending and receiving massages through the TAS channel interface 32 | class CTasClientChl final : public CTasClientServerCon 33 | { 34 | 35 | public: 36 | 37 | //! \brief Channel object constructor 38 | //! \param client_name Mandatory client name as a c-string 39 | explicit CTasClientChl(const char* client_name); 40 | 41 | //! \brief Start a connection session 42 | //! \details A session can only be started when a channel description is available in the TasServer. 43 | //! The channel description is read from a device by the first ClientChl.session_start() call. 44 | //! If this is not possible (e.g. device in halt after reset state), session_start() fails. 45 | //! The TasServer forgets the channel description, when no ClientChl is connected to a target. 46 | //! \param identifier Unique access HW name or IP address of device as a c-string 47 | //! \param session_name Unique session name as a c-string 48 | //! \param session_pw Session password, specify to block other clients joining this session 49 | //! \param chl_target channel target in case of a CHL client 50 | //! \param chl_param channel parameters in case of a CHL client 51 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 52 | tas_return_et session_start(const char* identifier, const char* session_name = "", const char* session_pw = "", 53 | tas_chl_target_et chl_target = TAS_CHL_TGT_DMM, uint64_t chl_param = 0); 54 | 55 | //! \brief Subscribe to a channel. 56 | //! \details A channel can be claimed as exclusive (no other client can subscribe anymore). 57 | //! Claiming will fail if the channel was already subscribed by another client. 58 | //! For prioritized channels 0 is highest and TAS_CHL_LOWEST_PRIORITY lowest priority. 59 | //! Priorities can only be assigned to one channel except the lowest priority.\n 60 | //! prio [in] : Requested priority (default TAS_CHL_LOWEST_PRIORITY)\n 61 | //! prio [out] : Assigned priority (equal or lower than requested)\n 62 | //! It is not possible to subscribe to more than one channel. 63 | //! \param chl Channel number, can be between 0 and 31 64 | //! \param cht Channel type, can be send, receive or bidirectional 65 | //! \param chso Subscribe exclusively to a channel. 66 | //! \param prio Channel's priority 67 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 68 | tas_return_et subscribe(uint8_t chl, tas_cht_et cht, tas_chso_et chso = TAS_CHSO_EXCLUSIVE, uint8_t* prio = nullptr); 69 | 70 | //! \brief Unsubscribe from a channel. 71 | //! \details Unsubscribing from an unsubscribed channel has no effect. 72 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 73 | tas_return_et unsubscribe(); 74 | 75 | //! \brief Send a message through a subscribed channel 76 | //! \details \ref tas_con_info_st.msg_length_c2d sets the limit for msg_length plus 4 bytes for init if init is not 0 77 | //! \param msg Pointer to message content 78 | //! \param msg_length Length of the message in Bytes 79 | //! \param init Optional init word, default 0 80 | tas_return_et send_msg(const void* msg, uint16_t msg_length, uint32_t init = 0); 81 | 82 | //! \brief Receive a message through a subscribed channel 83 | //! \details \ref tas_con_info_st.msg_length_d2c sets the limit for msg_length plus 4 bytes for init if init is not 0 84 | //! \param timeout_ms Timeout value in milliseconds. Blocking function with timeout. Timeout can be 0 for non-blocking. 85 | //! \param msg Pointer to a message buffer 86 | //! \param msg_length Pointer to a variable for storing the message length 87 | //! \param init Pointer to a variable for storing the init word 88 | tas_return_et rcv_msg(uint32_t timeout_ms, const void** msg, uint16_t* msg_length, uint32_t* init); 89 | 90 | //! \brief Performs a check if device reset has occurred. 91 | //! \returns \c true if reset occurred, otherwise \c false 92 | bool device_reset_occurred() override 93 | { 94 | if (!mSessionStarted) { 95 | return false; 96 | } 97 | 98 | uint32_t resetCount = mTphChl.get_device_reset_count(); 99 | 100 | if (mDeviceResetCount > resetCount) { 101 | assert(mDeviceResetCount == ~0U); // device_connect() was not called 102 | assert(false); // Wrong usage 103 | return false; 104 | } 105 | 106 | bool resetOccurred = (resetCount > mDeviceResetCount); 107 | 108 | mDeviceResetCount = resetCount; 109 | 110 | return resetOccurred; 111 | } 112 | 113 | //! \brief Connect to a target device. Can only be called when no channel is subscribed. 114 | //! \param dco Connection option, _RESET, _RESET_AND_HALT, _UNLOCK, default hot attach 115 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 116 | tas_return_et device_connect(tas_clnt_dco_et dco) override; 117 | 118 | // The following methods are only needed for special use cases and debugging 119 | 120 | //! \brief Send a ping to a target and obtain connection info 121 | //! \details Check the connection which was established with CTasClientServerCon::session_start() before.\n 122 | //! The channel description will be read from the device only once if the channel information is present.\n 123 | //! Only needed for special use cases and debugging. 124 | //! \param con_info Pointer to a variable to which connection info should be stored 125 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 126 | tas_return_et target_ping(tas_con_info_st* con_info); 127 | 128 | //! \brief Channel object constructor. Only used for special test setups. 129 | //! \param mb_if Mailbox interface 130 | explicit CTasClientChl(CTasPktMailboxIf* mb_if); 131 | 132 | private: 133 | 134 | tas_error_info_st mEi; //!< \brief Contains current error information. 135 | 136 | CTasPktMailboxIf* mMbIfChl; //!< \brief Packet mailbox interface. 137 | 138 | CTasPktHandlerChl mTphChl; //!< \brief Packet handler object. Used for constructing and parsing packets. 139 | 140 | tas_cht_et mChlCht = TAS_CHT_NONE; //!< \brief Channel type 141 | uint8_t mChlNum = TAS_CHL_NUM_MAX; //!< \brief Channel number 142 | 143 | }; 144 | 145 | //! \} // end of group Channel_API -------------------------------------------------------------------------------- /src/tas_client/tas_client_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Client_API 23 | //! \{ 24 | // TAS includes 25 | #include "tas_client.h" 26 | 27 | // Standard includes 28 | #include 29 | #include 30 | 31 | #ifdef _DEBUG 32 | enum { TAS_DEFAULT_TIMEOUT_MS = -1 }; //!< \brief No timeout 33 | #else 34 | enum { TAS_DEFAULT_TIMEOUT_MS = 2000 }; //!< \brief 2s 35 | #endif 36 | 37 | //! \brief TAS error information including c-string and an error code. 38 | struct tas_error_info_st { 39 | char info[TAS_INFO_STR_LEN]; //!< \brief c-string describing the error 40 | tas_return_et tas_err; //!< \brief Corresponding error code 41 | }; 42 | 43 | //! \brief Clean up error information. 44 | //! \param ei Pointer to an error information 45 | //! \returns \ref TAS_ERR_NONE 46 | inline tas_return_et tas_clear_error_info(tas_error_info_st* ei) 47 | { 48 | ei->info[0] = 0; 49 | ei->tas_err = TAS_ERR_NONE; 50 | return TAS_ERR_NONE; 51 | } 52 | 53 | //! \brief Forces the caller to handel server connection error 54 | //! \param ei Pointer to an error information 55 | //! \returns \ref TAS_ERR_SERVER_CON 56 | inline tas_return_et tas_client_handle_error_server_con(tas_error_info_st* ei) 57 | { 58 | assert(false); 59 | snprintf(ei->info, TAS_INFO_STR_LEN, "ERROR: Server connection"); 60 | ei->tas_err = TAS_ERR_SERVER_CON; 61 | return ei->tas_err; 62 | } 63 | 64 | //! \} // end of group Client_API -------------------------------------------------------------------------------- /src/tas_client/tas_client_rw.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Read_Write_API 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_client_rw_base.h" 27 | #include "tas_client_server_con.h" 28 | 29 | // Standard includes 30 | #include 31 | 32 | //! \brief This class facilitates read/write access to a target. 33 | class CTasClientRw final : public CTasClientRwBase, public CTasClientServerCon 34 | { 35 | public: 36 | 37 | //! \brief Start a connection session 38 | //! \param identifier Unique access HW name or IP address of device as a c-string 39 | //! \param session_name Unique session name as a c-string 40 | //! \param session_pw Session password, specify to block other clients joining this session 41 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 42 | tas_return_et session_start(const char* identifier, const char* session_name = "", const char* session_pw = "") 43 | { 44 | tas_return_et ret = mSessionStart(TAS_CLIENT_TYPE_RW, identifier, session_name, session_pw); 45 | 46 | assert(mTphRw == nullptr); 47 | if (ret == TAS_ERR_NONE) { 48 | mTphRw = new CTasPktHandlerRw(&mEi, get_con_info()); 49 | } 50 | return ret; 51 | } 52 | 53 | //! \brief Performs a check if device reset has occurred. 54 | //! \returns \c true if reset occurred, otherwise \c false 55 | bool device_reset_occurred() override 56 | { 57 | if (!mSessionStarted) { 58 | return false; 59 | } 60 | 61 | uint32_t resetCount = mTphRw->get_device_reset_count(); 62 | 63 | if (mDeviceResetCount > resetCount) { 64 | assert(mDeviceResetCount == ~0); // device_connect() was not called 65 | assert(false); // Wrong usage 66 | return false; 67 | } 68 | 69 | bool resetOccurred = (resetCount > mDeviceResetCount); 70 | 71 | mDeviceResetCount = resetCount; 72 | 73 | return resetOccurred; 74 | } 75 | 76 | //! \brief Connect to a target device 77 | //! \param dco Connection option, _RESET, _RESET_AND_HALT, _UNLOCK, default hot attach 78 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 79 | tas_return_et device_connect(tas_clnt_dco_et dco) override 80 | { 81 | tas_return_et ret = mDeviceConnect(dco); 82 | if (mTphRw) 83 | mDeviceResetCount = mTphRw->get_device_reset_count(); 84 | return ret; 85 | } 86 | 87 | //! \brief Read/Write client object constructor 88 | //! \param client_name Mandatory client name as a c-string 89 | explicit CTasClientRw(const char* client_name) 90 | : CTasClientRwBase(CTasPktHandlerRw::RSP_PKT_BUF_SIZE_DEFAULT) 91 | , CTasClientServerCon(client_name, &mEi) 92 | { 93 | mMbIfRw = mMbSocket; 94 | mMbIfRw->config(rw_get_timeout(), CTasPktHandlerRw::RSP_PKT_BUF_SIZE_DEFAULT); 95 | }; 96 | 97 | //! \brief Read/Write client object constructor 98 | //! \details !!Only needed for testing purposes. Not for regular TAS clients!! 99 | //! \param mb_if Mailbox interface 100 | //! \param max_rq_size Defines maximum size of request packets 101 | //! \param max_rsp_size Defines maximum size of response packets 102 | //! \param max_num_rw Defines maximum number of read/write transactions 103 | CTasClientRw(CTasPktMailboxIf* mb_if, uint32_t max_rq_size, uint32_t max_rsp_size, uint32_t max_num_rw) 104 | : CTasClientRwBase(mb_if, max_rq_size, max_rsp_size, max_num_rw) 105 | , CTasClientServerCon("TestOnly", &mEi) 106 | { 107 | mMbIf = mb_if; 108 | mSessionStarted = true; 109 | }; 110 | 111 | }; 112 | //! \} // end of group Read_Write_API -------------------------------------------------------------------------------- /src/tas_client/tas_client_trc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | // TAS includes 20 | #include "tas_client_trc.h" 21 | 22 | // Standard includes 23 | #include 24 | 25 | CTasClientTrc::CTasClientTrc() 26 | { 27 | assert(mMbIfTrc); 28 | } 29 | 30 | CTasClientTrc::CTasClientTrc(CTasPktMailboxIf* mb_if) : mMbIfTrc(mb_if) 31 | { 32 | 33 | } 34 | 35 | tas_return_et CTasClientTrc::subscribe(tas_trc_type_et* trct, uint8_t stream, tas_chso_et chso) 36 | { 37 | const uint32_t *pktRq, *pktRsp; 38 | pktRq = mTphTrc->get_pkt_rq_subscribe(stream, chso); 39 | 40 | if (!mMbIfTrc->execute(pktRq, (uint32_t*)&pktRsp)) 41 | return tas_client_handle_error_server_con(&mEi); 42 | 43 | tas_chso_et chsoRsp; 44 | if (mTphTrc->set_pkt_rsp_subscribe(pktRsp, trct, &chsoRsp)) 45 | return mEi.tas_err; 46 | 47 | return tas_clear_error_info(&mEi); 48 | } 49 | 50 | tas_return_et CTasClientTrc::unsubscribe(uint8_t stream) 51 | { 52 | const uint32_t *pktRq, *pktRsp; 53 | pktRq = mTphTrc->get_pkt_rq_unsubscribe(stream); 54 | 55 | if (!mMbIfTrc->execute(pktRq, (uint32_t*)&pktRsp)) 56 | return tas_client_handle_error_server_con(&mEi); 57 | 58 | if (!mTphTrc->set_pkt_rsp_unsubscribe(pktRsp)) 59 | return mEi.tas_err; 60 | 61 | return tas_clear_error_info(&mEi); 62 | } 63 | 64 | tas_return_et CTasClientTrc::rcv_trace(uint32_t timeout_ms, const void** trace_data, uint32_t* length, tas_trcs_et* trcs, uint8_t* stream) 65 | 66 | { 67 | *trace_data = nullptr; 68 | *length = 0; 69 | *trcs = TAS_TRCS_CONT; 70 | if (stream) 71 | *stream = 0xFF; 72 | 73 | mMbIfTrc->config(timeout_ms, TAS_PL2_MAX_PKT_SIZE); 74 | 75 | uint32_t* pktRsp = nullptr; assert(false); // Need to implement this 76 | uint32_t rspNumBytesReceived; 77 | if (!mMbIfTrc->receive(pktRsp, &rspNumBytesReceived)) 78 | return tas_client_handle_error_server_con(&mEi); 79 | 80 | if (rspNumBytesReceived == 0) { 81 | tas_clear_error_info(&mEi); 82 | return TAS_ERR_CHL_RCV; // Not TAS_ERR_NONE 83 | } 84 | 85 | const void* traceData; uint32_t lengthRcv; tas_trcs_et trcsRcv; uint8_t streamRcv; 86 | if (mTphTrc->set_pkt_rcv_trace(pktRsp, &traceData, &lengthRcv, &trcsRcv, &streamRcv)) 87 | return mEi.tas_err; 88 | 89 | *trace_data = traceData; 90 | *length = lengthRcv; 91 | *trcs = trcsRcv; 92 | if (stream) 93 | *stream = streamRcv; 94 | 95 | return tas_clear_error_info(&mEi); 96 | } 97 | 98 | -------------------------------------------------------------------------------- /src/tas_client/tas_client_trc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Trace_API 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_client_impl.h" 27 | #include "tas_client_server_con.h" 28 | #include "tas_pkt_handler_trc.h" 29 | #include "tas_pkt_mailbox_if.h" 30 | 31 | //! \brief Class for receiving continuous trace data. 32 | class CTasClientTrc final 33 | { 34 | 35 | public: 36 | 37 | //! \brief 38 | CTasClientTrc(); 39 | 40 | //! \brief Subscribe to a trace channel. 41 | //! \param trct Trace type 42 | //! \param stream Optional stream identifier, it allows to differentiate between independent trace streams from the same device 43 | //! \param chso Subscribe exclusively to a channel, default \ref TAS_CHSO_DEFAULT 44 | //! \returns \ref TAS_ERR_NONE on sucess, otherwise any other relevant TAS error code 45 | tas_return_et subscribe(tas_trc_type_et* trct, uint8_t stream = 0, tas_chso_et chso = TAS_CHSO_DEFAULT); 46 | 47 | //! \brief Unsubscribe from a trace channel or selected trace stream 48 | //! \param stream Optional stream identifier 49 | //! \returns \ref TAS_ERR_NONE on sucess, otherwise any other relevant TAS error code 50 | tas_return_et unsubscribe(uint8_t stream = 0); 51 | 52 | //! \brief Receive trace data. It is a blocking function with timeout. 53 | //! \param timeout_ms Configure timeout in milliseconds 54 | //! \param trace_data Pointer to a trace data buffer 55 | //! \param length Pointer to length of the received data 56 | //! \param trcs Pointer to trace stream status 57 | //! \param stream Pointer to a stream identifier 58 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 59 | tas_return_et rcv_trace(uint32_t timeout_ms, const void** trace_data, uint32_t *length, tas_trcs_et* trcs, uint8_t* stream = nullptr); 60 | 61 | 62 | // The following methods are only needed for special use cases and debugging 63 | 64 | //! \brief Send a ping to a target and obtain connection info 65 | //! \details Check the connection which was established with CTasClientServerCon::session_start() before.\n 66 | //! Only needed for special use cases and debugging. 67 | //! \param con_info Pointer to a variable to which connection info should be stored 68 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 69 | tas_return_et target_ping(tas_con_info_st* con_info); 70 | 71 | //! \brief Trace client object constructor 72 | //! \details !!Only needed for testing purposes. Not for regular TAS clients!! 73 | //! \param mb_if Mailbox interface 74 | explicit CTasClientTrc(CTasPktMailboxIf* mb_if); 75 | 76 | private: 77 | 78 | tas_error_info_st mEi; //!< \brief Contains current error information. 79 | 80 | CTasPktMailboxIf* mMbIfTrc; //!< \brief Packet mailbox interface. 81 | 82 | CTasPktHandlerTrc* mTphTrc; //!< \brief Packet handler object. Used for constructing and parsing packets. 83 | 84 | }; 85 | 86 | //! \} // end of group Trace_API -------------------------------------------------------------------------------- /src/tas_client/tas_debug.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Client_API 23 | //! \{ 24 | 25 | #undef TAS_DBG 26 | #ifdef TAS_DEBUG // Check if TAS debugging is enabled 27 | #define TAS_DBG 1 //!< \brief debugging prints enabled 28 | #else 29 | #define TAS_DBG 0 //!< \brief debugging prints disabled 30 | #endif 31 | 32 | // Inspired by StackOverflow answer: https://stackoverflow.com/a/1644898 33 | 34 | //! \brief Helper marco to print debug info 35 | #define tas_debug_print(fmt, ...) \ 36 | { if (TAS_DBG) fprintf(stderr, fmt, ##__VA_ARGS__); } 37 | 38 | //! \brief Helper macro to print debug info including location 39 | #define tas_debug_printloc(fmt, ...) \ 40 | { if (TAS_DBG) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, ##__VA_ARGS__); } 41 | 42 | //! \} // end of group Client_API -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_handler_base.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | // TAS includes 21 | #include "tas_pkt_handler_base.h" 22 | #include "tas_pkt.h" 23 | #include "tas_utils.h" 24 | 25 | // Standard includes 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | CTasPktHandlerBase::CTasPktHandlerBase(tas_error_info_st* ei) 33 | : mEip(ei) {} 34 | 35 | tas_return_et CTasPktHandlerBase::set_pkt_rsp_ping(tas_pl_cmd_et cmd, tas_client_type_et client_type, const uint32_t* pkt_rsp) 36 | { 37 | assert((cmd == TAS_PL1_CMD_SESSION_START) || (cmd == TAS_PL1_CMD_PING)); 38 | 39 | mConInfo = {}; 40 | 41 | auto pkt = (const tas_pl1rsp_ping_st*)&pkt_rsp[1]; 42 | 43 | // perhaps there is a better way to reuse this in tests for target side parser 44 | const uint32_t pl1PktSize = client_type == TAS_CLIENT_TYPE_UNKNOWN ? sizeof(tas_pl1rsp_ping_d2s_st) : sizeof(tas_pl1rsp_ping_st); 45 | if (pkt_rsp[0] != 4 + pl1PktSize) { 46 | return mHandlePktError(pkt_rsp, cmd); 47 | } 48 | else if ((pkt->cmd != cmd) || (pkt->wl != (pl1PktSize / 4) - 1)) { 49 | return mSetPktRspErrConnectionProtocol(); 50 | } 51 | else if ((PROTOC_VER < pkt->protoc_ver_min) || (PROTOC_VER > pkt->protoc_ver_max)) { 52 | return mSetPktRspErrConnectionProtocol(); 53 | } 54 | else if (!( (pkt->err == TAS_PL_ERR_NO_ERROR) || (pkt->err == TAS_PL1_ERR_CMD_FAILED) || 55 | (pkt->err == TAS_PL1_ERR_SESSION) || (pkt->err == TAS_PL_ERR_NOT_SUPPORTED))) { 56 | return mSetPktRspErrConnectionProtocol(); 57 | } 58 | else if (pkt->err == TAS_PL1_ERR_SESSION) { 59 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Session name or password"); 60 | mEip->tas_err = TAS_ERR_FN_PARAM; 61 | return mEip->tas_err; 62 | } 63 | else if (pkt->err == TAS_PL_ERR_NOT_SUPPORTED) { 64 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Parameter refused by server"); 65 | mEip->tas_err = TAS_ERR_FN_PARAM; 66 | return mEip->tas_err; 67 | } 68 | else if (pkt->err == TAS_PL1_ERR_CMD_FAILED) { 69 | if (client_type == TAS_CLIENT_TYPE_CHL) { 70 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Could not read channel description from device"); 71 | mEip->tas_err = TAS_ERR_CHL_SETUP; 72 | } 73 | else { 74 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Target not connected"); 75 | mEip->tas_err = TAS_ERR_DEVICE_ACCESS; 76 | } 77 | return mEip->tas_err; 78 | } 79 | else { 80 | assert(pkt->err == TAS_PL_ERR_NO_ERROR); 81 | uint32_t mpsRq = pkt->con_info.max_pl2rq_pkt_size; 82 | uint32_t mpsRsp = pkt->con_info.max_pl2rsp_pkt_size; 83 | uint16_t msgLenC2d = pkt->con_info.msg_length_c2d; 84 | uint16_t msgLenD2c= pkt->con_info.msg_length_d2c; 85 | if ((mpsRq % 4 != 0) || (mpsRq < TAS_PL2_MAX_PKT_SIZE_MIN) || (mpsRq > TAS_PL2_MAX_PKT_SIZE)) { 86 | return mSetPktRspErrConnectionProtocol(); 87 | } 88 | else if ((mpsRsp % 4 != 0) || (mpsRsp < TAS_PL2_MAX_PKT_SIZE_MIN) || (mpsRsp > TAS_PL2_MAX_PKT_SIZE)) { 89 | return mSetPktRspErrConnectionProtocol(); 90 | } 91 | else if ((msgLenC2d % 4 != 0) || (msgLenC2d > TAS_PL1_CHL_MAX_MSG_SIZE)) { 92 | return mSetPktRspErrConnectionProtocol(); 93 | } 94 | else if ((msgLenD2c % 4 != 0) || (msgLenD2c > TAS_PL1_CHL_MAX_MSG_SIZE)) { 95 | return mSetPktRspErrConnectionProtocol(); 96 | } 97 | else { // Success 98 | memcpy(&mConInfo, &pkt->con_info, sizeof(tas_con_info_st)); 99 | assert(!(mConInfo.identifier[0] == 0 && client_type != TAS_CLIENT_TYPE_UNKNOWN)); // perhaps there is a better way to identify target parser 100 | 101 | if (std::array zeros = {}; memcmp(mConInfo.device_id, zeros.data(), 16) == 0) { 102 | mConInfo.device_id_hash = 0; 103 | snprintf(mConInfo.device_id_hash_str, 6, "NoUid"); 104 | } 105 | else { 106 | mConInfo.device_id_hash = tasutil_crc32(mConInfo.device_id, 16); 107 | tasutil_hash32_to_str(mConInfo.device_id_hash, mConInfo.device_id_hash_str); 108 | } 109 | return tas_clear_error_info(mEip); 110 | } 111 | } 112 | } 113 | 114 | const uint32_t* CTasPktHandlerBase::get_pkt_rq_ping(tas_pl_cmd_et cmd) 115 | { 116 | assert(cmd == TAS_PL1_CMD_PING); 117 | const uint32_t pl1PktSize = sizeof(tas_pl1rq_ping_st); 118 | mRqBuf[0] = 4 + pl1PktSize; 119 | auto pkt = (tas_pl1rq_ping_st*)&mRqBuf[1]; 120 | *pkt = {}; 121 | pkt->wl = (pl1PktSize / 4) - 1; 122 | pkt->cmd = cmd; 123 | return mRqBuf; 124 | } 125 | 126 | tas_return_et CTasPktHandlerBase::mHandlePktError(const uint32_t* pkt_rsp, tas_pl_cmd_et cmd) 127 | { 128 | if (auto pkt = (const tas_pl1rsp_header_st*)&pkt_rsp[1]; (pkt_rsp[0] == 4 + sizeof(tas_pl1rsp_header_st)) && 129 | (pkt->cmd == cmd)) { 130 | 131 | switch (pkt->err) { 132 | case TAS_PL_ERR_USAGE: 133 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Wrong TAS API usage"); 134 | mEip->tas_err = TAS_ERR_FN_USAGE; 135 | // No assertion to allow testing this error 136 | break; 137 | case TAS_PL_ERR_NOT_SUPPORTED: 138 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Function is not supported"); 139 | mEip->tas_err = TAS_ERR_FN_NOT_SUPPORTED; 140 | assert(false); 141 | break; 142 | case TAS_PL1_ERR_CMD_FAILED: 143 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Function failed at TasServer"); 144 | mEip->tas_err = TAS_ERR_GENERAL; 145 | assert(false); 146 | break; 147 | default: 148 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Unknown error"); 149 | mEip->tas_err = TAS_ERR_GENERAL; 150 | assert(false); 151 | } 152 | return mEip->tas_err; 153 | } 154 | return mSetPktRspErrConnectionProtocol(); 155 | } 156 | 157 | tas_return_et CTasPktHandlerBase::mSetPktRspErrConnectionProtocol() 158 | { 159 | assert(false); 160 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Server connection protocol"); 161 | mEip->tas_err = TAS_ERR_SERVER_CON; 162 | return mEip->tas_err; 163 | } 164 | 165 | tas_return_et CTasPktHandlerBase::mSetPktRspErrDeviceAccess() 166 | { 167 | // No assertion to allow testing this error 168 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Device access failed"); 169 | mEip->tas_err = TAS_ERR_DEVICE_ACCESS; 170 | return mEip->tas_err; 171 | } 172 | 173 | 174 | -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_handler_base.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \defgroup Packet_Handlers Packet Handlers 23 | //! \brief A set of classes for constructing and parsing TAS packets. 24 | 25 | //! \defgroup Packet_Handler_RW Read/Write (RW) 26 | //! \brief Read/Write packet handler related classes and functions. 27 | //! \ingroup Packet_Handlers 28 | //! \defgroup Packet_Handler_CHL Channel (CHL) 29 | //! \brief Channel packet handler related classes and functions. 30 | //! \ingroup Packet_Handlers 31 | //! \defgroup Packet_Handler_TRC Trace (TRC) 32 | //! \brief Trace packet handler related classes and functions. 33 | //! \ingroup Packet_Handlers 34 | 35 | //! \addtogroup Packet_Handlers 36 | //! \{ 37 | 38 | // TAS includes 39 | #include "tas_client.h" 40 | #include "tas_client_impl.h" 41 | 42 | // Standard includes 43 | #include 44 | #include 45 | 46 | //! \brief A class for handling a set of common packet types to all client types. 47 | class CTasPktHandlerBase 48 | { 49 | 50 | public: 51 | 52 | //! \brief Packet handler object constructor. 53 | //! \param ei pointer to the TAS error info 54 | explicit CTasPktHandlerBase(tas_error_info_st* ei); 55 | 56 | //! \brief Base class destructor 57 | virtual ~CTasPktHandlerBase() = default; 58 | 59 | //! \brief Get a ping request packet 60 | //! \param cmd command identifier, \ref TAS_PL1_CMD_PING 61 | //! \returns pointer to the generated request packet 62 | const uint32_t* get_pkt_rq_ping(tas_pl_cmd_et cmd); 63 | 64 | //! \brief Parses a response from a ping request. 65 | //! \param cmd command identifier, \ref TAS_PL1_CMD_PING or \ref TAS_PL1_CMD_SESSION_START 66 | //! \param client_type client type, RW, CHL, or TRC 67 | //! \param pkt_rsp pointer to the ping response 68 | tas_return_et set_pkt_rsp_ping(tas_pl_cmd_et cmd, tas_client_type_et client_type, const uint32_t* pkt_rsp); 69 | 70 | //! \brief Initial setting of con_info with the data from CTasClientServerCon 71 | //! \param con_info pointer to the connection info 72 | void set_con_info(const tas_con_info_st* con_info) { memcpy(&mConInfo, con_info, sizeof(tas_con_info_st)); } 73 | 74 | //! \brief Get the connection information which was retrieved by a ping or session start command. 75 | //! \details Assuming connection details have not changed this calls saves a ping request. The packet handler object 76 | //! buffers the connection information which is updated by a ping request. 77 | //! \returns pointer to the connection information 78 | const tas_con_info_st* get_con_info() const { return &mConInfo; } 79 | 80 | //! \brief Get the device reset count. Value updated by the derived classes based on the packet error \ref TAS_PL1_ERR_DEV_RESET 81 | //! or reset notification by the server. 82 | //! \returns the respective reset count 83 | uint32_t get_device_reset_count() const { return mDeviceResetCount; }; 84 | 85 | protected: 86 | 87 | //! \brief Maps packet level error codes in a response packet to a TAS errro code. 88 | //! \param pkt_rsp pointer to a response packet 89 | //! \param cmd command identifier 90 | //! \returns \ref TAS_ERR_SERVER_CON, otherwise any other relevant TAS error code based on the PL error code 91 | tas_return_et mHandlePktError(const uint32_t* pkt_rsp, tas_pl_cmd_et cmd); 92 | 93 | //! \brief Set the server conenction error in case of a an issue with a server connection. 94 | //! \returns \ref TAS_ERR_SERVER_CON 95 | tas_return_et mSetPktRspErrConnectionProtocol(); 96 | 97 | //! \brief Set device access error in case of device access failed. 98 | //! \returns \ref TAS_ERR_DEVICE_ACCESS 99 | tas_return_et mSetPktRspErrDeviceAccess(); 100 | 101 | tas_error_info_st* mEip; //!< \brief Pointer to single object in primary client class 102 | 103 | //! \brief protocol version supported by this class 104 | enum { 105 | PROTOC_VER = TAS_PKT_PROTOC_VER_1 //!< \brief tas_pkt.h protocol version implemented in this class 106 | }; 107 | 108 | // This needs to be allocated and set in the derived class: 109 | uint32_t* mRqBuf; //!< \brief pointer to a request buffer. For one or more PL2 packet. Allocated and set in a derived class. 110 | uint32_t mMaxRqSize; //!< \brief maximum request sizes in bytes. Can be more than one PL2 packet. Allocated and set in a derived class. 111 | uint32_t mMaxRspSize; //!< \brief maximum response sizes in bytes. Can be more than one PL2 packet. Allocated and set in a derived class. 112 | uint32_t mRqWiMax; //!< \brief maximum value of the (word) index in the request buffer 113 | 114 | uint32_t mRqBufWi; //!< \brief current value of the (Word) index in the request buffer 115 | 116 | tas_con_info_st mConInfo = {}; //!< \brief local storage for the connection information 117 | 118 | uint16_t mDeviceConnectOption; //!< \brief local storage for the device connection option 119 | 120 | uint16_t mPl1CntOutstandingOldest; //!< \brief cnt of first outstanding request 121 | uint16_t mPl1CntOutstandingLast = 0xFFC0; //!< \brief cnt of last outstanding request 122 | 123 | uint32_t mDeviceResetCount; //!< \brief local storage for the device reset count 124 | 125 | private: 126 | 127 | virtual void mEnforceDerivedClass() = 0; //!< \brief pure virtual method enforce that only used in derived RW or CHL class 128 | 129 | }; 130 | 131 | //! \} // end of group Packet_Handlers -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_handler_chl.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Packet_Handler_CHL 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_pkt_handler_base.h" 27 | 28 | //! \brief Derived packet handler class for handling channel packets 29 | class CTasPktHandlerChl : public CTasPktHandlerBase 30 | { 31 | 32 | public: 33 | CTasPktHandlerChl(const CTasPktHandlerChl&) = delete; //!< \brief delete the copy constructor 34 | CTasPktHandlerChl operator= (const CTasPktHandlerChl&) = delete; //!< \brief delete copy-assignment operator 35 | 36 | //! \brief Channel packet handler object constructor. 37 | //! \param ei pointer to the TAS error info 38 | explicit CTasPktHandlerChl(tas_error_info_st* ei); 39 | 40 | //! \brief Packet handler object destructor for cleanup 41 | ~CTasPktHandlerChl(); 42 | 43 | //! \brief Get a request packet for subscribing to a channel. 44 | //! \details The length of the request in bytes is pkt_rq[0]. 45 | //! \param chl channel number: 0 to \ref TAS_CHL_NUM_MAX - 1 46 | //! \param cht channel type: send, recv, bidi 47 | //! \param chso channel subscribe option: none, exclusive 48 | //! \param prio channel priority 49 | //! \returns pointer to the request packet 50 | const uint32_t* get_pkt_rq_subscribe(uint8_t chl, tas_cht_et cht, tas_chso_et chso, uint8_t prio); 51 | 52 | //! \brief Get a response from a subscribe request. 53 | //! \param pkt_rsp pointer to the response packet 54 | //! \param cht pointer to the channel type value: send, recv, bidi 55 | //! \param chso pointer to the channel subscribe option value: none, exclusive 56 | //! \param prio pointer to the channel priority value 57 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 58 | tas_return_et set_pkt_rsp_subscribe(const uint32_t* pkt_rsp, tas_cht_et* cht, tas_chso_et* chso, uint8_t *prio); 59 | 60 | //! \brief Get a request packet for unsubscribing from a channel. 61 | //! \details The length of the request in bytes is pkt_rq[0]. 62 | //! \param chl channel number of a subscribed channel 63 | //! \returns pointer to the request packet 64 | const uint32_t* get_pkt_rq_unsubscribe(uint8_t chl); 65 | 66 | //! \brief Get a response from a unsubscribe request. 67 | //! \param pkt_rsp pointer to the response packet 68 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 69 | tas_return_et set_pkt_rsp_unsubscribe(const uint32_t* pkt_rsp); 70 | 71 | //! \brief Get a request packet for sending a message. 72 | //! \details The length of the request in bytes is pkt_rq[0]. 73 | //! \param chl channel number of a subscribed channel 74 | //! \param msg pointer to the message data 75 | //! \param msg_length length of the message data 76 | //! \param init init word, should be 0 if not used 77 | //! \returns pointer to the request packet 78 | const uint32_t* get_pkt_send_msg(uint8_t chl, const void* msg, uint16_t msg_length, uint32_t init); 79 | 80 | //! \brief Get a response for a received message. 81 | //! \param pkt_rsp pointer to the response packet 82 | //! \param chl channel number of a subscribed channel 83 | //! \param msg pointer to the received message data 84 | //! \param msg_length pointer to the length of the message data 85 | //! \param init pointer to the init word 86 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 87 | tas_return_et set_pkt_rcv_msg(const uint32_t* pkt_rsp, uint8_t chl, const void** msg, uint16_t* msg_length, uint32_t* init); 88 | 89 | private: 90 | 91 | void mEnforceDerivedClass() final { ; } 92 | 93 | uint8_t mChl = 0xFF; //!< \brief Check response of subscribe/unsubscribe 94 | tas_cht_et mCht = TAS_CHT_NONE; //!< \brief Check response of subscribe 95 | tas_chso_et mChso = TAS_CHSO_DEFAULT; //!< \brief Check response of subscribe 96 | 97 | }; 98 | 99 | //! \} // end of group Packet_Handlers_CHL -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_handler_trc.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | // TAS includes 20 | #include "tas_pkt_handler_trc.h" 21 | 22 | // Standard includes 23 | #include 24 | #include 25 | #include 26 | 27 | CTasPktHandlerTrc::CTasPktHandlerTrc(tas_error_info_st* ei) 28 | : CTasPktHandlerBase(ei) {} 29 | 30 | const uint32_t* CTasPktHandlerTrc::get_pkt_rq_subscribe(uint8_t stream, tas_chso_et chso) 31 | { 32 | mStream = stream; 33 | mChso = chso; 34 | 35 | assert(chso <= TAS_CHSO_EXCLUSIVE); 36 | const uint32_t pl1PktSize = sizeof(tas_pl1rq_trc_subscribe_st); 37 | mRqBuf[0] = 4 + pl1PktSize; 38 | auto pkt = (tas_pl1rq_trc_subscribe_st*)&mRqBuf[1]; 39 | pkt->wl = (pl1PktSize / 4) - 1; 40 | pkt->cmd = TAS_PL1_CMD_TRC_SUBSCRIBE; 41 | pkt->reserved = 0; 42 | pkt->stream = stream; 43 | pkt->chso = chso; 44 | pkt->reserved1 = 0; 45 | return mRqBuf; 46 | } 47 | 48 | tas_return_et CTasPktHandlerTrc::set_pkt_rsp_subscribe(const uint32_t* pkt_rsp, tas_trc_type_et* trct, tas_chso_et* chso) 49 | { 50 | *chso = TAS_CHSO_DEFAULT; 51 | 52 | auto pkt = (const tas_pl1rsp_trc_subscribe_st*)&pkt_rsp[1]; 53 | 54 | const uint32_t pl1PktSize = sizeof(tas_pl1rsp_trc_subscribe_st); 55 | if (pkt_rsp[0] != 4 + pl1PktSize) { 56 | return mSetPktRspErrConnectionProtocol(); 57 | } 58 | assert(pkt->reserved == 0); 59 | assert(pkt->reserved1 == 0); 60 | if ((pkt->cmd != TAS_PL1_CMD_TRC_SUBSCRIBE) || (pkt->wl != (pl1PktSize / 4) - 1)) { 61 | return mSetPktRspErrConnectionProtocol(); 62 | } 63 | if (pkt->stream != mStream) { 64 | return mSetPktRspErrConnectionProtocol(); 65 | } 66 | if (pkt->chso > TAS_CHSO_EXCLUSIVE) { 67 | return mSetPktRspErrConnectionProtocol(); 68 | } 69 | 70 | if (pkt->err != TAS_PL_ERR_NO_ERROR) { 71 | if (pkt->err == TAS_PL1_ERR_CMD_FAILED) { 72 | return mSetPktRspErrTraceClaimed(mStream); 73 | } 74 | else if (pkt->err == TAS_PL_ERR_NOT_SUPPORTED) { 75 | return mSetPktRspErrTraceNotSupported(); 76 | } 77 | else { 78 | return mSetPktRspErrConnectionProtocol(); 79 | } 80 | } 81 | 82 | *trct = (tas_trc_type_et)pkt->trct; 83 | 84 | assert(pkt->chso == mChso); 85 | *chso = (tas_chso_et)pkt->chso; 86 | 87 | return tas_clear_error_info(mEip); 88 | } 89 | 90 | const uint32_t* CTasPktHandlerTrc::get_pkt_rq_unsubscribe(uint8_t stream) 91 | { 92 | mStream = stream; 93 | 94 | const uint32_t pl1PktSize = sizeof(tas_pl1rq_trc_unsubscribe_st); 95 | mRqBuf[0] = 4 + pl1PktSize; 96 | auto pkt = (tas_pl1rq_trc_unsubscribe_st*)&mRqBuf[1]; 97 | pkt->wl = (pl1PktSize / 4) - 1; 98 | pkt->cmd = TAS_PL1_CMD_TRC_UNSUBSCRIBE; 99 | pkt->stream = stream; 100 | pkt->reserved = 0; 101 | return mRqBuf; 102 | } 103 | 104 | tas_return_et CTasPktHandlerTrc::set_pkt_rsp_unsubscribe(const uint32_t* pkt_rsp) 105 | { 106 | auto pkt = (const tas_pl1rsp_trc_unsubscribe_st*)&pkt_rsp[1]; 107 | 108 | const uint32_t pl1PktSize = sizeof(tas_pl1rsp_trc_unsubscribe_st); 109 | if (pkt_rsp[0] != 4 + pl1PktSize) { 110 | return mSetPktRspErrConnectionProtocol(); 111 | } 112 | if ((pkt->cmd != TAS_PL1_CMD_TRC_UNSUBSCRIBE) || (pkt->wl != (pl1PktSize / 4) - 1) || (pkt->err != TAS_PL_ERR_NO_ERROR)) { 113 | return mSetPktRspErrConnectionProtocol(); 114 | } 115 | if (pkt->stream != mStream) { 116 | return mSetPktRspErrConnectionProtocol(); 117 | } 118 | 119 | return tas_clear_error_info(mEip); 120 | } 121 | 122 | tas_return_et CTasPktHandlerTrc::set_pkt_rcv_trace(const uint32_t* pkt_rsp, const void** trace_data, uint32_t* length, tas_trcs_et* trcs, uint8_t* stream) 123 | { 124 | *trace_data = nullptr; 125 | *length = 0; 126 | *trcs = TAS_TRCS_CONT; 127 | *stream = 0xFF; 128 | 129 | auto pkt = (const tas_pl1rsp_trc_data_st*)&pkt_rsp[1]; 130 | 131 | const uint32_t pl1PktSize = sizeof(tas_pl1rsp_trc_data_st); 132 | if ((pkt_rsp[0] < 4 + pl1PktSize + 32) || (pkt_rsp[0] % 4) || (pkt_rsp[0] > TAS_PL2_MAX_PKT_SIZE)) { 133 | return mSetPktRspErrConnectionProtocol(); 134 | } 135 | if ((pkt->cmd != TAS_PL1_CMD_TRC_DATA) || (pkt->wl != (pl1PktSize / 4) - 1) || (pkt->trcs > TAS_TRCS_START_AI)) { 136 | return mSetPktRspErrConnectionProtocol(); 137 | } 138 | 139 | *trcs = (tas_trcs_et)pkt->trcs; 140 | *stream = pkt->stream; 141 | 142 | return tas_clear_error_info(mEip); 143 | } 144 | 145 | tas_return_et CTasPktHandlerTrc::mSetPktRspErrTraceClaimed(uint8_t stream) 146 | { 147 | if (stream == 0) 148 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Continuous trace exclusively claimed by another client"); 149 | else 150 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Continuous trace for stream %d exclusively claimed by another client", stream); 151 | mEip->tas_err = TAS_ERR_FN_USAGE; 152 | return mEip->tas_err; 153 | } 154 | 155 | tas_return_et CTasPktHandlerTrc::mSetPktRspErrTraceNotSupported() 156 | { 157 | snprintf(mEip->info, TAS_INFO_STR_LEN, "ERROR: Continuous trace not supported by this device, access HW or server"); 158 | mEip->tas_err = TAS_ERR_FN_NOT_SUPPORTED; 159 | return mEip->tas_err; 160 | } 161 | -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_handler_trc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Packet_Handler_TRC 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_pkt_handler_base.h" 27 | 28 | //! \brief Derived packet handler class for handling trace packets 29 | //! \details The top level API is not completely fixed. Therefore, the definitions might still change. 30 | class CTasPktHandlerTrc : public CTasPktHandlerBase 31 | { 32 | 33 | public: 34 | 35 | //! \brief Trace packet handler object constructor. 36 | //! \param ei pointer to the TAS error info 37 | explicit CTasPktHandlerTrc(tas_error_info_st* ei); 38 | 39 | //! \brief Get a request to subscribe to a trace channel. 40 | //! \param stream trace stream identifier 41 | //! \param chso channel subscribe option: none, exclusive 42 | //! \returns pointer to the request packet 43 | const uint32_t* get_pkt_rq_subscribe(uint8_t stream, tas_chso_et chso); 44 | 45 | //! \brief Get a response from a subscribe request. 46 | //! \param pkt_rsp pointer to the response packet 47 | //! \param trct pointer to the trace type 48 | //! \param chso pointer to channel subscribe option 49 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 50 | tas_return_et set_pkt_rsp_subscribe(const uint32_t* pkt_rsp, tas_trc_type_et *trct, tas_chso_et* chso); 51 | 52 | //! \brief Get a request to unsubscribe from a trace channel. 53 | //! \param stream trace stream identifier 54 | //! \returns pointer to the request packet 55 | const uint32_t* get_pkt_rq_unsubscribe(uint8_t stream); 56 | 57 | //! \brief Get a response from the unsubscribe request. 58 | //! \param pkt_rsp pointer to the response packet 59 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 60 | tas_return_et set_pkt_rsp_unsubscribe(const uint32_t* pkt_rsp); 61 | 62 | //! \brief Get received trace data from a response packet 63 | //! \param pkt_rsp pointer to the response packet 64 | //! \param trace_data pointer to the received trace data 65 | //! \param length pointer to the length of trace data 66 | //! \param trcs pointer to the trace stream state 67 | //! \param stream pointer to the trace stream identifier 68 | //! \return \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 69 | tas_return_et set_pkt_rcv_trace(const uint32_t* pkt_rsp, const void** trace_data, uint32_t* length, tas_trcs_et* trcs, uint8_t* stream); 70 | 71 | 72 | private: 73 | 74 | void mEnforceDerivedClass() { ; } 75 | 76 | //! \brief Set function usage error in case the trace channel or a stream was exclusively claimed by another client. 77 | //! \returns \ref TAS_ERR_FN_USAGE 78 | tas_return_et mSetPktRspErrTraceClaimed(uint8_t stream); 79 | 80 | //! \brief Set function not supported in case continuous trace not supported by this device, access HW or server. 81 | //! \returns \ref TAS_ERR_FN_NOT_SUPPORTED 82 | tas_return_et mSetPktRspErrTraceNotSupported(); 83 | 84 | uint8_t mStream; //!< \brief Check response of subscribe/unsubscribe 85 | tas_chso_et mChso; //!< \brief Check response of subscribe 86 | 87 | }; 88 | 89 | //! \} // end of group Packet_Handler_TRC -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_mailbox_if.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Client_API 23 | //! \{ 24 | 25 | // Standard includes 26 | #include 27 | 28 | //! \brief A pure virtual class defining the packet mailbox interface 29 | struct CTasPktMailboxIf 30 | { 31 | 32 | public: 33 | 34 | //! \brief Base class destructor 35 | virtual ~CTasPktMailboxIf() = default; 36 | 37 | //! \brief Configure receive timeout and response packet size. 38 | //! \param timeout_ms timeout value in milliseconds 39 | //! \param max_num_bytes_rsp maximum size of a response in bytes 40 | virtual void config(uint32_t timeout_ms, uint32_t max_num_bytes_rsp) = 0; 41 | 42 | //! \brief Check if connected. 43 | //! \returns \c true if yes, otherwise \c false 44 | virtual bool connected() = 0; 45 | 46 | //! \brief Send out a request packet. 47 | //! \details The method call is blocking until all PL2 packets have been sent. 48 | //! \param rq pointer to a request packet buffer, can contain more than one PL2 defined by the num_pl2_pkt value 49 | //! \param num_pl2_pkt number of PL2 packets within the buffer 50 | //! \returns \c true on success, \c false in case of an error 51 | virtual bool send(const uint32_t* rq, uint32_t num_pl2_pkt = 1) = 0; 52 | 53 | //! \brief Receive response packet. 54 | //! \details The method call is blocking until a packet is received or a timeout occurred. 55 | //! \param rsp pointer to a response packet buffer 56 | //! \param num_bytes_rsp pointer to a storage for the number of bytes in the response packet 57 | //! \returns \c true on success, \c false in case of an error, timeout is not an error! 58 | virtual bool receive(uint32_t* rsp, uint32_t* num_bytes_rsp) = 0; 59 | 60 | //! \brief Send out a request and wait for a response 61 | //! \details The method call is blocking until all PL2 packets have been sent and received or a timeout occurred. 62 | //! If num_pl2_pkt = 1, rq is a single PL2 packet. In this case num_bytes_rsp is not needed as well. 63 | //! \param rq pointer to a request packet buffer, can contain more than one PL2 defined by the num_pl2_pkt value 64 | //! \param rsp pointer to a response packet buffer 65 | //! \param num_pl2_pkt number of PL2 packets within the buffer 66 | //! \param num_bytes_rsp pointer to a storage for the number of bytes in the response packet 67 | //! \returns \c true on success, \c false in case of an error, timeout is not an error! 68 | virtual bool execute(const uint32_t* rq, uint32_t* rsp, uint32_t num_pl2_pkt = 1, uint32_t* num_bytes_rsp = nullptr) = 0; 69 | 70 | }; 71 | 72 | //! \} // end of group Client_API -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_mailbox_socket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | // TAS includes 20 | #include "tas_pkt_mailbox_socket.h" 21 | #include "tas_pkt.h" 22 | 23 | // Standard includes 24 | #include 25 | #include 26 | 27 | bool CTasPktMailboxSocket::server_connect(const char* ip_addr, uint16_t port_num) 28 | { 29 | assert(!connected()); 30 | 31 | mSocket = new CTasTcpSocket(); 32 | if (!mSocket->connect(ip_addr, port_num, mTimeoutMs)) 33 | { 34 | return false; 35 | } 36 | 37 | return true; 38 | } 39 | 40 | void CTasPktMailboxSocket::config(uint32_t timeout_ms, uint32_t max_num_bytes_rsp) 41 | { 42 | assert(max_num_bytes_rsp % 4 == 0); 43 | mTimeoutMs = timeout_ms; 44 | mMaxNumBytesRsp = max_num_bytes_rsp; 45 | } 46 | 47 | bool CTasPktMailboxSocket::send(const uint32_t* rq, uint32_t num_pl2_pkt) 48 | { 49 | if (!connected()) { 50 | assert(false); 51 | return false; 52 | } 53 | 54 | uint32_t w = 0; 55 | for (uint32_t p = 0; p < num_pl2_pkt; p++) { 56 | 57 | uint32_t pktSize = rq[w]; 58 | assert(pktSize % 4 == 0); 59 | assert(pktSize <= TAS_PL2_MAX_PKT_SIZE); 60 | 61 | if (!mSocketSend(&rq[w], pktSize)) { 62 | assert(false); 63 | return false; 64 | } 65 | w += pktSize / 4; 66 | } 67 | return true; 68 | } 69 | 70 | bool CTasPktMailboxSocket::receive(uint32_t* rsp, uint32_t* num_bytes_rsp) 71 | { 72 | mRspBuf = rsp; 73 | 74 | *num_bytes_rsp = 0; 75 | 76 | assert(connected()); 77 | if (!connected()) 78 | return false; 79 | 80 | mNumBytesRsp = 0; 81 | if (!mReceivePl2Pkt()) 82 | return false; 83 | 84 | *num_bytes_rsp = mNumBytesRsp; 85 | return true; 86 | } 87 | 88 | bool CTasPktMailboxSocket::execute(const uint32_t* rq, uint32_t* rsp, uint32_t num_pl2_pkt, uint32_t* num_bytes_rsp) 89 | { 90 | mRspBuf = rsp; 91 | 92 | if (num_bytes_rsp) 93 | *num_bytes_rsp = 0; 94 | 95 | if (!send(rq, num_pl2_pkt)) { 96 | return false; 97 | } 98 | 99 | mNumBytesRsp = 0; 100 | for (uint32_t p = 0; p < num_pl2_pkt; p++) { 101 | if (!mReceivePl2Pkt()) 102 | return false; 103 | } 104 | 105 | if (num_bytes_rsp) 106 | *num_bytes_rsp = mNumBytesRsp; 107 | 108 | return true; 109 | } 110 | 111 | bool CTasPktMailboxSocket::mReceivePl2Pkt() 112 | { 113 | uint32_t w; 114 | uint32_t pktSize; 115 | 116 | w = mNumBytesRsp / 4; 117 | 118 | // Get PL2 packet size 119 | if (!mSocketReceive(w, 4)) { 120 | return false; // Timeout case 121 | } 122 | pktSize = mRspBuf[w]; 123 | 124 | if ((pktSize % 4 != 0) || 125 | (pktSize < 8) || 126 | (pktSize + (w * 4) > mMaxNumBytesRsp)) { 127 | assert(false); 128 | mSocketDisconnect(); 129 | return false; 130 | } 131 | if (!mSocketReceive(w + 1, pktSize - 4)) { 132 | assert(false); // Timeout at this point is fatal 133 | mSocketDisconnect(); 134 | return false; 135 | } 136 | mNumBytesRsp += pktSize; 137 | return true; 138 | } 139 | 140 | bool CTasPktMailboxSocket::mSocketSend(const uint32_t* rq, uint32_t num_bytes) 141 | { 142 | assert(num_bytes % 4 == 0); 143 | 144 | if (mSocket->send(rq, num_bytes, mTimeoutMs) <= 0) 145 | { 146 | mSocketDisconnect(); 147 | return false; 148 | } 149 | 150 | return true; 151 | } 152 | 153 | bool CTasPktMailboxSocket::mSocketReceive(uint32_t w, uint32_t num_bytes) 154 | { 155 | mRspBuf[w] = 0; 156 | 157 | if (mSocket->recv(&mRspBuf[w], num_bytes, (int)mTimeoutMs) <= 0) 158 | { 159 | mSocketDisconnect(); 160 | return false; 161 | } 162 | 163 | return (mRspBuf[w] != 0); 164 | } 165 | -------------------------------------------------------------------------------- /src/tas_client/tas_pkt_mailbox_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup Client_API 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_pkt_mailbox_if.h" 27 | 28 | // TAS Socket includes 29 | #include "tas_tcp_socket.h" 30 | 31 | //! \brief Derived mailbox class utilizing socket connection. 32 | class CTasPktMailboxSocket : public CTasPktMailboxIf 33 | { 34 | 35 | public: 36 | CTasPktMailboxSocket(const CTasPktMailboxSocket&) = delete; //!< \brief delete the copy constructor 37 | CTasPktMailboxSocket operator= (const CTasPktMailboxSocket&) = delete; //!< \brief delete copy-assignment operator 38 | 39 | //! \brief Mailbox constructor. 40 | CTasPktMailboxSocket() = default; 41 | 42 | //! \brief Mailbox destructor for clean up. 43 | ~CTasPktMailboxSocket() 44 | { 45 | mSocketDisconnect(); 46 | } 47 | 48 | //! \brief Connect to a TAS server. 49 | //! \param ip_addr server's IP address or a hostname 50 | //! \param port_num server's port number 51 | //! \returns \c true on success, otherwise \c false 52 | bool server_connect(const char* ip_addr, uint16_t port_num); 53 | 54 | // CTasPktMailboxIf 55 | void config(uint32_t timeout_receive_ms, uint32_t max_num_bytes_rsp); 56 | bool connected() { return (mSocket != nullptr); } 57 | bool send(const uint32_t* rq, uint32_t num_pl2_pkt = 1); 58 | bool receive(uint32_t* rsp, uint32_t* num_bytes_rsp); 59 | bool execute(const uint32_t* rq, uint32_t* rsp, uint32_t num_pl2_pkt = 1, uint32_t* num_bytes_rsp = nullptr); 60 | 61 | private: 62 | 63 | //! \brief Receive a PL2 packet 64 | //! \returns \c true on success, otherwise \c false 65 | bool mReceivePl2Pkt(); 66 | 67 | //! \brief Send data through the socket. 68 | //! \param rq pointer to a request buffer 69 | //! \param num_bytes length of the request in bytes 70 | //! \returns \c true on success, otherwise \c false 71 | bool mSocketSend(const uint32_t* rq, uint32_t num_bytes); 72 | 73 | //! \brief Receive data from the socket. 74 | //! \param w index in the mRspBuf 75 | //! \param num_bytes number of expected bytes 76 | //! \returns \c true on success, otherwise \c false 77 | bool mSocketReceive(uint32_t w, uint32_t num_bytes); 78 | 79 | //! \brief Disconnect the socket. Used in case of a fetal error. 80 | void mSocketDisconnect() 81 | { 82 | delete mSocket; 83 | mSocket = nullptr; 84 | } 85 | 86 | CTasTcpSocket* mSocket = nullptr; //!< \brief Pointer to a socket instance which is connected to a TAS server 87 | 88 | uint32_t mTimeoutMs = 0; //!< \brief Timeout value in milliseconds for the receive operation 89 | 90 | uint32_t mMaxNumBytesRsp = 0; //!< \brief Defines the maximum number of bytes in a response packet 91 | 92 | uint32_t* mRspBuf = nullptr; //!< \brief Pointer to a response packet buffer 93 | uint32_t mNumBytesRsp = 0; //!< \brief Number of bytes in the response packet buffer 94 | }; 95 | 96 | //! \} // end of group Client_API -------------------------------------------------------------------------------- /src/tas_client/tas_utils_client.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup TAS_utils 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_client_rw.h" 27 | 28 | // Standard includes 29 | #include 30 | 31 | //! \brief Set a set of user pins to logic high. 32 | //! \param tcrw pointer to a RW client object, which will execute the operation 33 | //! \param pins set of pins to be set to high 34 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 35 | inline tas_return_et tasutil_userpins_set_high(CTasClientRw* tcrw, uint32_t pins) 36 | { 37 | tas_userpins_mask_st up = { pins, pins }; 38 | return tcrw->write64(TAS_AM15_RW_USERPINS, *(uint64_t*)&up, TAS_AM15); 39 | } 40 | 41 | //! \brief Set a set of user pins to logic low. 42 | //! \param tcrw pointer to a RW client object, which will execute the operation 43 | //! \param pins set of pins to be set to low 44 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 45 | inline tas_return_et tasutil_userpins_set_low(CTasClientRw* tcrw, uint32_t pins) 46 | { 47 | tas_userpins_mask_st up = { 0, pins }; 48 | return tcrw->write64(TAS_AM15_RW_USERPINS, *(uint64_t*)&up, TAS_AM15); 49 | } 50 | 51 | //! \brief Turn on the run led of access hardware. 52 | //! \param tcrw pointer to a RW client object, which will execute the operation 53 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 54 | inline tas_return_et tasutil_acc_hw_runled_on(CTasClientRw* tcrw) 55 | { 56 | return tasutil_userpins_set_low(tcrw, TAS_UP_RUNLED); 57 | } 58 | 59 | //! \brief Turn off the run led of access hardware. 60 | //! \param tcrw pointer to a RW client object, which will execute the operation 61 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 62 | inline tas_return_et tasutil_acc_hw_runled_off(CTasClientRw* tcrw) 63 | { 64 | return tasutil_userpins_set_high(tcrw, TAS_UP_RUNLED); 65 | } 66 | 67 | //! \brief Check if client is connected to an emulator. 68 | //! \returns \c true if yes, otherwise \c false 69 | inline bool tasutil_emulator_connected(CTasClientServerCon* client) 70 | { 71 | return (strstr(client->get_con_info()->identifier, "Emulator") != NULL);; 72 | } 73 | 74 | //! \} // end of group TAS_utils -------------------------------------------------------------------------------- /src/tas_client/tas_utils_ifx.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | // TAS includes 20 | #include "tas_device_family.h" 21 | #include "tas_utils_ifx.h" 22 | 23 | // Standard includes 24 | #include 25 | #include 26 | 27 | 28 | bool tasutil_ifx_get_device_name(uint32_t device_type, uint32_t device_id0, char* device_name) 29 | { 30 | tas_device_family_t deviceFamily = tas_get_device_family(device_type); 31 | 32 | if ( (deviceFamily == TAS_DF_TC2X) 33 | || (deviceFamily == TAS_DF_TC3X) 34 | || (deviceFamily == TAS_DF_TC4X)) { 35 | if (device_id0 == 0) { 36 | snprintf(device_name, TAS_NAME_LEN32, "UNKNOWN"); 37 | } 38 | else { 39 | snprintf(device_name, TAS_NAME_LEN32, "%s", tas_get_device_name_str(device_type)); 40 | 41 | } 42 | return true; 43 | } 44 | else { 45 | snprintf(device_name, TAS_NAME_LEN32, "device_type 0x%8.8X", device_type); 46 | return false; 47 | } 48 | } 49 | 50 | -------------------------------------------------------------------------------- /src/tas_client/tas_utils_ifx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup TAS_utils 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_pkt.h" 27 | 28 | // Standard includes 29 | #include 30 | 31 | //! \brief Get a device name. 32 | //! \details It allocates TAS_NAME_LEN32 long buffer for the device name. 33 | //! \param device_type device type identifier 34 | //! \param device_id0 device ID (JTAG ID) 35 | //! \param device_name pointer to a c-string containing device name 36 | //! \returns \c true if device is known, otherwise \c false. 37 | bool tasutil_ifx_get_device_name(uint32_t device_type, uint32_t device_id0, char* device_name); 38 | 39 | //! \} // end of group TAS_utils -------------------------------------------------------------------------------- /src/tas_client/tas_utils_jtag.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | // TAS includes 20 | #include "tas_utils_jtag.h" 21 | #include "tas_device_family.h" 22 | #include "tas_am15_am14.h" 23 | 24 | // Standard includes 25 | #include 26 | 27 | tas_return_et tasutil_jtag_scan(CTasClientRw* tcrw, const tasutil_jtag_scan_st* scan, uint8_t num_scan) 28 | { 29 | tas_return_et ret = TAS_ERR_NONE; 30 | 31 | uint32_t numTransMax = 16 + 6 * num_scan; // Very generous 32 | auto rwTrans = new tas_rw_trans_st[numTransMax]; 33 | uint64_t* zeroDataBlock = nullptr; 34 | 35 | uint32_t resDat; 36 | uint32_t t = 1; 37 | rwTrans[0] = { TAS_AM15_RW_JTAG_SCAN_MODE_ENABLE, 4, 0, TAS_AM15, TAS_RW_TT_WR, &resDat }; 38 | for (uint32_t s = 0; s < num_scan; s++) { 39 | assert((scan[s].tjs == TJS_NONE) || (scan[s].tjs == TJS_TAP_RESET)); 40 | if (scan[s].tjs == TJS_TAP_RESET) { 41 | rwTrans[t] = { TAS_AM15_W_JTAG_RESET, 4, 0, TAS_AM15, TAS_RW_TT_WR, &resDat }; 42 | t++; 43 | } 44 | if (scan[s].ir.width > 0) { 45 | rwTrans[t] = { TAS_AM15_W_JTAG_SET_IR, 8, 0, TAS_AM15, TAS_RW_TT_WR, &scan[s].ir }; 46 | t++; 47 | } 48 | rwTrans[t] = { TAS_AM15_W_JTAG_CAPTURE, 4, 0, TAS_AM15, TAS_RW_TT_WR, &scan[s].num_bits }; 49 | t++; 50 | 51 | const uint32_t maxBitsTrans = TAS_AM15_JTAG_MAX_NUM_SCAN_BITS_PER_TRANSACTION; 52 | uint64_t* dataOut = scan[s].data_out; 53 | const uint64_t* dataIn = scan[s].data_in; 54 | if (scan[s].data_in == nullptr) { 55 | if (!zeroDataBlock) 56 | zeroDataBlock = new uint64_t[maxBitsTrans / 64]; 57 | dataIn = zeroDataBlock; 58 | } 59 | 60 | uint32_t bitsNow; 61 | uint32_t bytesNow; 62 | uint32_t bitsRemaining = scan[s].num_bits; 63 | do { 64 | bitsNow = (bitsRemaining > maxBitsTrans) ? maxBitsTrans : bitsRemaining; 65 | bytesNow = ((bitsNow + 63) / 64) * 8; 66 | rwTrans[t] = { TAS_AM15_RW_JTAG_DATA_SHIFT, bytesNow, 0, TAS_AM15, TAS_RW_TT_WR, dataIn }; 67 | t++; 68 | if (dataOut != nullptr) { 69 | rwTrans[t] = { TAS_AM15_RW_JTAG_DATA_SHIFT, bytesNow, 0, TAS_AM15, TAS_RW_TT_RD, dataOut }; 70 | t++; 71 | } 72 | if (bitsNow == maxBitsTrans) { 73 | if (dataIn != zeroDataBlock) 74 | dataIn += (maxBitsTrans / 64); 75 | if (dataOut != nullptr) 76 | dataOut += (maxBitsTrans / 64); 77 | } 78 | bitsRemaining -= bitsNow; 79 | } while ((bitsRemaining > 0) && (t < numTransMax - 6)); 80 | 81 | if (bitsRemaining > 0) { 82 | assert(false); // May only happen for extremely long scan chains (higher level SW bug) 83 | ret = TAS_ERR_FN_PARAM; 84 | break; // for (s) 85 | } 86 | } 87 | rwTrans[t] = { TAS_AM15_W_JTAG_SCAN_MODE_DISABLE, 4, 0, TAS_AM15, TAS_RW_TT_WR, &resDat }; 88 | t++; 89 | 90 | if (ret == TAS_ERR_NONE) { 91 | ret = tcrw->execute_trans(rwTrans, t); 92 | } 93 | 94 | delete[] rwTrans; 95 | delete[] zeroDataBlock; 96 | 97 | return ret; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/tas_client/tas_utils_jtag.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | #pragma once 21 | 22 | //! \addtogroup TAS_utils 23 | //! \{ 24 | 25 | // TAS includes 26 | #include "tas_client_rw.h" 27 | 28 | //! \brief Options for JTAG scan 29 | enum tasutil_jtag_scan_et : uint32_t { 30 | TJS_NONE = 0, //!< \brief no special option 31 | TJS_TAP_RESET = 0x01, //!< \brief Initial TAP controller reset with state machine sequence 32 | }; 33 | 34 | //! \brief JTAG scan configuration 35 | struct tasutil_jtag_scan_st { 36 | tasutil_jtag_scan_et tjs; //!< \brief scan option 37 | tas_jtag_set_ir_st ir; //!< \brief Instruction register. If ir.width is 0 -> no IR update 38 | uint32_t num_bits; //!< \brief Number of data scan bits 39 | const uint64_t* data_in; //!< \brief input data, nullptr means zeros are shifted in 40 | uint64_t* data_out; //!< \brief output data, nullptr means output is ignored 41 | }; 42 | 43 | //! \brief Execute a JTAG scan operation 44 | //! \param tcrw pointer to RW client object, which will execute the operation 45 | //! \param scan pointer to a list of scan configurations 46 | //! \param num_scan number of scan configurations 47 | //! \returns \ref TAS_ERR_NONE on success, otherwise any other relevant TAS error code 48 | tas_return_et tasutil_jtag_scan(CTasClientRw* tcrw, const tasutil_jtag_scan_st* scan, uint8_t num_scan); 49 | 50 | //! \} // end of group TAS_utils -------------------------------------------------------------------------------- /src/tas_client/tas_utils_os.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | // tas_utils functions which require an OS specific implementation 21 | // TAS includes 22 | #include "tas_pkt.h" 23 | #include "tas_utils.h" 24 | 25 | // Standard includes 26 | #include 27 | #include 28 | 29 | #ifdef _WIN32 30 | #include 31 | #include 32 | 33 | void tasutil_get_user_name(char *user_name) 34 | { 35 | char userNameTmp[256]; 36 | DWORD usernameLen = 256; 37 | GetUserName(userNameTmp, &usernameLen); 38 | snprintf(user_name, TAS_NAME_LEN16, "%s", userNameTmp); 39 | } 40 | 41 | uint32_t tasutil_get_pid() { return (uint32_t)_getpid(); } 42 | 43 | bool tasutil_check_local_tas_server_is_running() 44 | { 45 | // https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-openmutexw 46 | // https://docs.microsoft.com/en-us/windows/win32/termserv/kernel-object-namespaces 47 | 48 | GetLastError(); // Clear old errors 49 | HANDLE hMutex = OpenMutexW(SYNCHRONIZE, FALSE, L"Global\\only_one_TasServer_on_host"); 50 | DWORD lastError = GetLastError(); 51 | if (lastError != ERROR_SUCCESS) { 52 | assert(lastError == ERROR_FILE_NOT_FOUND); 53 | return false; // TasServer is NOT running 54 | } 55 | CloseHandle(hMutex); // Not needed 56 | 57 | return true; // TasServer is running 58 | } 59 | 60 | void tasutil_start_local_tas_server() 61 | { 62 | // https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getwindowsdirectory 63 | 64 | char applicationPath[MAX_PATH+16]; 65 | UINT len = GetSystemDirectoryA(applicationPath, MAX_PATH); 66 | if (len == 0) { 67 | assert(false); 68 | return; 69 | } 70 | snprintf(&applicationPath[len], MAX_PATH + 16, "\\start_tas_server.bat"); 71 | 72 | // Disable redirection immediately prior to the native API function call. 73 | // https://social.msdn.microsoft.com/Forums/vstudio/en-US/f9a54564-1006-42f9-b4d1-b225f370c60c/getsystemdirectory-should-return-the-native-system32-directory-in-a-64bit-machine?forum=vcgeneral 74 | // https://learn.microsoft.com/en-us/windows/win32/api/wow64apiset/nf-wow64apiset-wow64disablewow64fsredirection 75 | PVOID OldValue = NULL; 76 | BOOL isWoW64 = FALSE; 77 | if (Wow64DisableWow64FsRedirection(&OldValue)) { 78 | isWoW64 = TRUE; // Wow64DisableWow64FsRedirection() is success in case of 32 bit applications 79 | } 80 | else { 81 | DWORD winError = GetLastError(); // Just for debugging 82 | assert(winError == ERROR_INVALID_FUNCTION); // For 64 bit applications, Wow64DisableWow64FsRedirection() fails with ERROR_INVALID_FUNCTION error 83 | isWoW64 = FALSE; 84 | } 85 | 86 | PROCESS_INFORMATION processInfo; 87 | STARTUPINFO startupInfo; 88 | ZeroMemory(&startupInfo, sizeof(startupInfo)); 89 | //startupInfo.cb = sizeof startupInfo; 90 | //int success = CreateProcessA(applicationPath, NULL, NULL, NULL, FALSE, 0, NULL, NULL, 91 | // &startupInfo, &processInfo); 92 | 93 | //if (!success) { 94 | // DWORD winError = GetLastError(); // Just for debugging 95 | // return; 96 | //} 97 | 98 | //CloseHandle(processInfo.hThread); // Not needed 99 | //CloseHandle(processInfo.hProcess); // Not needed 100 | 101 | HINSTANCE success = ShellExecuteA(0, "open", applicationPath, NULL, NULL, 0); 102 | if (success < (HINSTANCE)32) { 103 | DWORD winError = GetLastError(); // Just for debugging 104 | return; 105 | } 106 | if (isWoW64 == TRUE) { 107 | // Immediately re-enable redirection. Note that any resources 108 | // associated with OldValue are cleaned up by this call. 109 | if (FALSE == Wow64RevertWow64FsRedirection(OldValue)) 110 | { 111 | // Failure to re-enable redirection should be considered 112 | // a critical failure and execution aborted. 113 | return; 114 | } 115 | } 116 | } 117 | 118 | 119 | 120 | #else // Unix 121 | 122 | #include 123 | 124 | void tasutil_get_user_name(char* user_name) 125 | { 126 | getlogin_r(user_name, TAS_NAME_LEN16); 127 | } 128 | 129 | uint32_t tasutil_get_pid() { return (uint32_t)getpid(); } 130 | 131 | #endif -------------------------------------------------------------------------------- /src/tas_socket/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ----------------------------------------------------------------------------- 2 | # list of sources: 3 | # ----------------------------------------------------------------------------- 4 | set(TAS_SOCKET_HDRS 5 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_conn_socket.h" 6 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_socket.h" 7 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_tcp_server_socket.h" 8 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_tcp_socket.h" 9 | ) 10 | 11 | set(TAS_SOCKET_SRCS 12 | "${TAS_SOCKET_HDRS}" 13 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_conn_socket.cpp" 14 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_socket.cpp" 15 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_tcp_server_socket.cpp" 16 | "${CMAKE_CURRENT_SOURCE_DIR}/tas_tcp_socket.cpp" 17 | ) 18 | 19 | # ----------------------------------------------------------------------------- 20 | # include soruces in the following targets: 21 | # ----------------------------------------------------------------------------- 22 | 23 | # Python wrapper 24 | tac_add_target_sources(PyTAS "${TAS_SOCKET_SRCS}") 25 | 26 | # ----------------------------------------------------------------------------- 27 | # tas socket lib 28 | # ----------------------------------------------------------------------------- 29 | set(LIB_NAME tas_socket) 30 | 31 | # generate IDE virtual folders where supported 32 | set(REC ".*([.]cpp|[.]h)") 33 | 34 | set(REG1 ".*/src/tas_socket/") 35 | source_group("tas_socket" REGULAR_EXPRESSION "${REG1}${REC}") 36 | 37 | # ----------------------------------------------------------------------------- 38 | # Add executable, its includes, and libraries 39 | # ----------------------------------------------------------------------------- 40 | add_library(${LIB_NAME} STATIC ${TAS_SOCKET_SRCS}) 41 | 42 | target_include_directories(${LIB_NAME} 43 | PUBLIC 44 | "$" 45 | "$" 46 | ) 47 | 48 | # ----------------------------------------------------------------------------- 49 | # Compile definitions 50 | # ----------------------------------------------------------------------------- 51 | if (MSVC) 52 | target_compile_definitions(${LIB_NAME} PRIVATE 53 | "$<$:" 54 | "_DEBUG" 55 | ">" 56 | "$<$:" 57 | "NDEBUG" 58 | ">" 59 | "_CRT_SECURE_NO_WARNINGS" 60 | "_WIN32" 61 | ) 62 | elseif (UNIX) 63 | target_compile_definitions(${LIB_NAME} PRIVATE 64 | "UNIX" 65 | ) 66 | endif() 67 | 68 | # ----------------------------------------------------------------------------- 69 | # Compile and link options 70 | # ----------------------------------------------------------------------------- 71 | if (MSVC) 72 | target_compile_options(${LIB_NAME} PRIVATE 73 | /W3 74 | /MP 75 | "$<$:" 76 | "/O2" 77 | ">" 78 | ) 79 | 80 | target_link_options(${LIB_NAME} PRIVATE 81 | /SUBSYSTEM:CONSOLE 82 | ) 83 | elseif (UNIX) 84 | target_compile_options(${LIB_NAME} PRIVATE 85 | -Wall; 86 | ) 87 | endif() 88 | 89 | # ----------------------------------------------------------------------------- 90 | # Install 91 | # ----------------------------------------------------------------------------- 92 | # library 93 | install(TARGETS ${LIB_NAME} 94 | EXPORT TasClientApiTargets 95 | LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" 96 | ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" 97 | RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" 98 | INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tas_socket" 99 | ) 100 | 101 | # header files 102 | install(FILES ${TAS_SOCKET_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tas_socket) 103 | -------------------------------------------------------------------------------- /src/tas_socket/tas_conn_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | //! \ingroup socket_lib 21 | 22 | #pragma once 23 | 24 | // Socket lib includes 25 | #include "tas_socket.h" 26 | 27 | // Standard includes 28 | #include 29 | 30 | //! \brief A class for socket data transmission operations 31 | class CTasConnSocket : public CTasSocket 32 | { 33 | public: 34 | 35 | //! \brief Establish a connection with a remote, blocking mode by default. 36 | //! \details Set timeout_ms to non-zero value for non-blocking mode. 37 | //! \param hostname remote's IP address or it's hostname 38 | //! \param port remote's port number 39 | //! \param timeout_ms timeout in milliseconds befor attempted is canceled, default: -1 40 | //! \returns \c true on successful connection, otherwise \c false 41 | bool connect(const char* hostname, unsigned short port, int timeout_ms = -1); 42 | 43 | //! \brief Send data through an established connection 44 | //! \details It is not guaranteed that all the data is sent, check the return value 45 | //! If the timeout is not provided this is a blocking operation and it may block forever 46 | //! \param buf a pointer to a buffer containing the data to be transmitted 47 | //! \param len the length, in bytes, of the data in buffer pointed to by the buf parameter 48 | //! \param timeout_ms timeout in milliseconds, default: -1 49 | //! \returns the total number of bytes sent, which can be less than the number requested to be sent in the len 50 | //! parameter, \c -1 in case of an error, \c 0 if the connection has been gracefully closed 51 | int send(const void* buf, int len, int timeout_ms = -1); 52 | 53 | //! \brief Tries to send all the data specified by len parameter through an established connection 54 | //! \details If the timeout is not provided this is a blocking operation and it may block forever 55 | //! \param buf a pointer to a buffer containing the data to be transmitted 56 | //! \param len the length, in bytes, of the data in buffer pointed to by the buf parameter 57 | //! \param timeout_ms timeout in milliseconds, default: -1 58 | //! \returns the total number of bytes sent, which can be less than the number requested to be sent in the len 59 | //! parameter, \c -1 in case of an error, \c 0 if the connection has been gracefully closed 60 | int sendAll(const void* buf, int len, int timeout_ms = -1); 61 | 62 | //! \brief Receive data through an established connection 63 | //! \details It is not guaranteed that all the data is received, check the return value 64 | //! If the timeout is not provided this is a blocking operation and it may block forever 65 | //! \param buf pointer to a data buffer for storing the incoming data 66 | //! \param len the length, in bytes, of the buffer pointed to by the buf parameter or expected number of incoming 67 | //! bytes which should be <= buffer size 68 | //! \param timeout_ms timeout in milliseconds, default: -1 69 | //! \returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data 70 | //! received, \c -1 in case of an error, \c 0 if the connection has been gracefully closed 71 | int recv(void* buf, int len, int timeout_ms = -1); 72 | 73 | //! \brief Tries to receive all the data specified by the len parameter through an established connection 74 | //! \details If the timeout is not provided this is a blocking operation and it may block forever 75 | //! \param buf pointer to a data buffer for storing the incoming data 76 | //! \param len the length, in bytes, of the buffer pointed to by the buf parameter or expected number of incoming 77 | //! bytes which should be <= buffer size 78 | //! \param timeout_ms timeout in milliseconds, default: -1 no timeout 79 | //! \returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data 80 | //! received, \c -1 in case of an error, \c 0 if the connection has been gracefully closed 81 | int recvAll(void* buf, int len, int timeout_ms = -1); 82 | 83 | //! \brief Retrieves remote's IP address 84 | //! \returns remote's IP address as c-string in dot notation 85 | const char* get_remote_ip(); 86 | 87 | //! \brief Retrieves remote's port number 88 | //! \returns remote's port number 89 | unsigned short get_remote_port(); 90 | 91 | private: 92 | //! \brief Privet method for non-blocking connect 93 | //! \param saptr pointer to a sockaddr struct 94 | //! \param salen length of the struct in Bytes 95 | //! \param timeout_ms timeout in milliseconds 96 | //! \returns \c true if connected successfully, otherwise \c false 97 | bool mConnectNonblock(const struct sockaddr* saptr, int salen, unsigned int timeout_ms); 98 | 99 | //! \brief Timeout helper function on Unix systems 100 | //! \param timeout_ms timeout in milliseconds 101 | void mSleepMs(int timeout_ms); 102 | 103 | std::array mRemoteIp; //!< \brief buffer for remote's IP address 104 | 105 | //! \brief Last measured tick for mSleepMs function 106 | std::chrono::milliseconds mLastTick = std::chrono::milliseconds(0); 107 | 108 | protected: 109 | //! \brief constructor with socket type and protocol 110 | //! \details Only available in derived classes 111 | CTasConnSocket(int type, int protocol); 112 | 113 | //! \brief constructor with socket descriptor 114 | //! \details Only available in derived classes 115 | explicit CTasConnSocket(int conn_sock_desc); 116 | }; 117 | -------------------------------------------------------------------------------- /src/tas_socket/tas_socket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | // Socket lib includes 21 | #include "tas_socket.h" 22 | // Standard includes 23 | #include 24 | 25 | #ifdef _WIN32 26 | static bool winsock_init_done = false; 27 | #endif 28 | 29 | CTasSocket::CTasSocket(int type, int protocol) 30 | { 31 | #ifdef _WIN32 32 | // WinSock initialization, should be done just once 33 | if (!winsock_init_done) 34 | { 35 | WSADATA wsaData; 36 | if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) 37 | { 38 | // error handling in constructor 39 | } 40 | winsock_init_done = true; 41 | } 42 | #endif 43 | if ((mSocketDesc = (int)socket(AF_INET, type, protocol)) == INVALID_SOCKET) 44 | { 45 | // error handling 46 | } 47 | assert(mSocketDesc != INVALID_SOCKET); 48 | 49 | // Optimize latency by disabling Nagle algorithm 50 | int on = 1; 51 | int error = setsockopt(mSocketDesc, IPPROTO_TCP, TCP_NODELAY, (char *)&on, sizeof(on)); 52 | assert(error == 0); 53 | (void)error; // Unused beyond assert 54 | } 55 | 56 | CTasSocket::CTasSocket(int socket_desc) : mSocketDesc(socket_desc) {} 57 | 58 | CTasSocket::~CTasSocket() 59 | { 60 | close(); 61 | } 62 | 63 | int CTasSocket::select_socket(const unsigned int msec) const 64 | { 65 | if (mSocketDesc < 0) 66 | return -1; 67 | 68 | struct timeval tval; 69 | fd_set rset; 70 | int res; 71 | 72 | if (msec > 0) 73 | { 74 | tval.tv_sec = msec / 1000; 75 | tval.tv_usec = (msec % 1000) * 1000; 76 | } 77 | 78 | FD_ZERO(&rset); 79 | FD_SET(mSocketDesc, &rset); 80 | 81 | // block until socket is readable 82 | res = select(mSocketDesc + 1, &rset, nullptr, nullptr, &tval); 83 | 84 | if (res <= 0) 85 | return res; 86 | 87 | if (!FD_ISSET(mSocketDesc, &rset)) 88 | return -1; 89 | 90 | return 1; 91 | } 92 | 93 | bool CTasSocket::set_option(int optname, void* arg) const 94 | { 95 | switch(optname) 96 | { 97 | case SO_RCVBUF: 98 | { 99 | int option = *(int*)arg; 100 | int option_set; 101 | socklen_t len = sizeof(socklen_t); 102 | 103 | setsockopt(mSocketDesc, SOL_SOCKET, SO_RCVBUF, (char*)&option, sizeof(option)); 104 | getsockopt(mSocketDesc, SOL_SOCKET, SO_RCVBUF, (char*)&option_set, &len); 105 | 106 | if (option_set != option) 107 | return false; 108 | 109 | break; 110 | } 111 | 112 | case SO_SNDBUF: 113 | { 114 | int option = *(int*)arg; 115 | int option_set; 116 | socklen_t len = sizeof(socklen_t); 117 | 118 | setsockopt(mSocketDesc, SOL_SOCKET, SO_SNDBUF, (char*)&option, sizeof(int)); 119 | getsockopt(mSocketDesc, SOL_SOCKET, SO_SNDBUF, (char*)&option_set, &len); 120 | 121 | if (option_set != option) 122 | return false; 123 | 124 | break; 125 | } 126 | 127 | default: 128 | return false; 129 | } 130 | 131 | return true; 132 | } 133 | 134 | bool CTasSocket::set_local_port(unsigned short port) const 135 | { 136 | struct sockaddr_in saddr; 137 | 138 | memset(&saddr, 0, sizeof(saddr)); 139 | saddr.sin_family = AF_INET; 140 | saddr.sin_addr.s_addr = htonl(INADDR_ANY); 141 | saddr.sin_port = htons(port); 142 | 143 | if ((bind(mSocketDesc, (sockaddr*)&saddr, sizeof(saddr))) == SOCKET_ERROR) 144 | { 145 | return false; // Unable to set local port 146 | } 147 | 148 | return true; 149 | } 150 | 151 | unsigned short CTasSocket::get_local_port() const 152 | { 153 | struct sockaddr_in saddr; 154 | 155 | if (socklen_t saddrLen = sizeof(saddr); getsockname(mSocketDesc, (sockaddr*)&saddr, &saddrLen) == SOCKET_ERROR) 156 | { 157 | return 0; // Unable to get local port 158 | } 159 | 160 | return ntohs(saddr.sin_port); 161 | } 162 | 163 | const char* CTasSocket::get_local_addr() 164 | { 165 | struct sockaddr_in saddr; 166 | 167 | if (socklen_t saddrLen = sizeof(saddr); getsockname(mSocketDesc, (sockaddr*)&saddr, &saddrLen) == SOCKET_ERROR) 168 | { 169 | mLocalIpv4[0] = '\0'; // empty string 170 | return mLocalIpv4.data(); // Unable to get local address 171 | } 172 | return inet_ntop(saddr.sin_family, &saddr.sin_addr, mLocalIpv4.data(), INET_ADDRSTRLEN); // Assumes only Ipv4! 173 | } 174 | 175 | bool CTasSocket::set_local_addr_and_port(const char* addr, unsigned short port) const 176 | { 177 | struct sockaddr_in saddr; 178 | 179 | memset(&saddr, 0, sizeof(saddr)); 180 | saddr.sin_family = AF_INET; 181 | saddr.sin_port = htons(port); 182 | inet_pton(AF_INET, addr, &saddr.sin_addr); // what about the return value? 183 | 184 | if ((bind(mSocketDesc, (sockaddr*)&saddr, sizeof(saddr))) == SOCKET_ERROR) 185 | { 186 | return false; // Unable to set local address and port 187 | } 188 | 189 | return true; 190 | } 191 | 192 | void CTasSocket::close() 193 | { 194 | #ifdef _WIN32 195 | closesocket(mSocketDesc); 196 | #else 197 | ::close(mSocketDesc); 198 | #endif 199 | mSocketDesc = (int)INVALID_SOCKET; 200 | } 201 | 202 | int CTasSocket::get_socket_desc() 203 | { 204 | return mSocketDesc; 205 | } 206 | 207 | int CTasSocket::get_new_socket_desc(int type, int protocol) 208 | { 209 | // If the old descriptor is still valid return invalid socket descriptor 210 | if (mSocketDesc != INVALID_SOCKET) { 211 | return (int)INVALID_SOCKET; 212 | } 213 | 214 | mSocketDesc = (int)socket(AF_INET, type, protocol); 215 | return mSocketDesc; 216 | } -------------------------------------------------------------------------------- /src/tas_socket/tas_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | //! \defgroup socket_lib TAS Socket Library 21 | 22 | #pragma once 23 | 24 | // Winsock library on windows 25 | #if defined(_WIN32) || defined(_WIN64) 26 | #include 27 | #include 28 | #pragma comment (lib, "Ws2_32.lib") 29 | // socket and other network libraries on unix 30 | #else 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #define INVALID_SOCKET (int)(~0) 40 | #define SOCKET_ERROR -1 41 | #endif 42 | 43 | // standard includes 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | //! \brief Base socket class 50 | //! \details Call WSACleanUp() at the end of socket usage in win applications 51 | //! \ingroup socket_lib 52 | class CTasSocket 53 | { 54 | public: 55 | CTasSocket(const CTasSocket&) = delete; //!< \brief delete the copy constructor 56 | CTasSocket operator= (const CTasSocket&) = delete; //!< \brief delete copy-assignment operator 57 | 58 | //! \brief socket destructor 59 | //! closes the socket 60 | ~CTasSocket(); 61 | 62 | //! \brief use select function on this socket 63 | //! \param msec timeout in milliseconds 64 | //! \returns \c -1 on failure 65 | int select_socket(const unsigned int msec) const; 66 | 67 | //! \brief set a socket option 68 | //! \param optname option name 69 | //! \param arg parameters of the corresponding option 70 | //! \return \c false if the options was not set, otherwise \c true 71 | bool set_option(int optname, void* arg) const; 72 | 73 | //! \brief set the (socket's) local port number 74 | //! \param port port number 75 | //! \returns \c false if the local port could not be set, otherwise \c true 76 | bool set_local_port(unsigned short port) const; 77 | 78 | //! \brief get the (socket's) local port number 79 | //! \returns port number 80 | unsigned short get_local_port() const; 81 | 82 | //! \brief get the local IP address 83 | //! \returns c-string of an IP address in dot notation 84 | const char* get_local_addr(); 85 | 86 | //! \brief set local IP address and port number 87 | //! \param addr c-string of an IP address in dot notation 88 | //! \param port port number 89 | //! \returns \c false if the operation fails, otherwise \c true 90 | bool set_local_addr_and_port(const char* addr, unsigned short port) const; 91 | 92 | //! \brief explicitly close the socket 93 | void close(); 94 | 95 | private: 96 | //! \brief storage for the socket's local IP address 97 | std::array mLocalIpv4; 98 | 99 | int mSocketDesc; //!< \brief socket descriptor 100 | 101 | protected: 102 | //! \brief get current socket descriptor value 103 | //! \returns socket descriptor 104 | int get_socket_desc(); 105 | 106 | //! \brief get a new socket descriptor value 107 | //! \details It assumes that the previous socket was closed 108 | //! \param type socket type 109 | //! \param protocol socket protocol 110 | //! \returns socket descriptor on success or invalid socket descriptor on failure 111 | int get_new_socket_desc(int type, int protocol); 112 | 113 | CTasSocket(int type, int protocol); //!< \brief socket constructor with its type and protocol 114 | explicit CTasSocket(int socket_desc); //!< \brief socket constructor with its descriptor 115 | }; -------------------------------------------------------------------------------- /src/tas_socket/tas_tcp_server_socket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | // Socket lib includes 21 | #include "tas_tcp_server_socket.h" 22 | 23 | CTasTcpServerSocket::CTasTcpServerSocket() : CTasSocket(SOCK_STREAM, IPPROTO_TCP) 24 | { 25 | 26 | } 27 | 28 | bool CTasTcpServerSocket::listen(unsigned short port) 29 | { 30 | if (!set_local_port(port)) 31 | return false; 32 | 33 | if (::listen(get_socket_desc(), 5) == SOCKET_ERROR) 34 | { 35 | return false; // listen failed 36 | } 37 | 38 | return true; 39 | } 40 | 41 | bool CTasTcpServerSocket::listen(const char* addr, unsigned short port) 42 | { 43 | if (!set_local_addr_and_port(addr, port)) 44 | return false; 45 | 46 | if (::listen(get_socket_desc(), 5) == SOCKET_ERROR) 47 | { 48 | return false; // listen failed 49 | } 50 | return true; 51 | } 52 | 53 | CTasTcpSocket* CTasTcpServerSocket::accept() 54 | { 55 | int sock; 56 | if ((sock = (int)::accept(get_socket_desc(), nullptr, nullptr)) == INVALID_SOCKET) 57 | { 58 | // accept failed 59 | return nullptr; 60 | } 61 | 62 | return new CTasTcpSocket(sock); 63 | } -------------------------------------------------------------------------------- /src/tas_socket/tas_tcp_server_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | //! \ingroup socket_lib 21 | 22 | #pragma once 23 | 24 | // Socket lib includes 25 | #include "tas_tcp_socket.h" 26 | 27 | //! \brief TCP server socket class 28 | class CTasTcpServerSocket : public CTasSocket 29 | { 30 | public: 31 | //! \brief TCP Server socket constructor 32 | //! \details This creates an object that represents a stream socket which uses the TCP protocol 33 | CTasTcpServerSocket(); 34 | 35 | //! \brief Open a listening socket 36 | //! \param port port number on which to listen for new connections 37 | //! \returns \c false if listen fails, otherwise \c true 38 | bool listen(unsigned short port); 39 | 40 | //! \brief Bind to an address and open a listening socket 41 | //! \param addr IP address to which the listening socket is bound to 42 | //! \param port port number on which to listen for new connections 43 | //! \returns \c false if listen fails, otherwise \c true 44 | bool listen(const char* addr, unsigned short port); 45 | 46 | //! \brief Accept a new connection 47 | //! \returns a pointer to a TCP socket object for which the connection was accepted 48 | CTasTcpSocket* accept(); 49 | }; -------------------------------------------------------------------------------- /src/tas_socket/tas_tcp_socket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | // Socket lib includes 21 | #include "tas_tcp_socket.h" 22 | 23 | CTasTcpSocket::CTasTcpSocket() : CTasConnSocket(SOCK_STREAM, IPPROTO_TCP) {}; 24 | 25 | CTasTcpSocket::CTasTcpSocket(int tcp_sock_desc) : CTasConnSocket(tcp_sock_desc) {}; -------------------------------------------------------------------------------- /src/tas_socket/tas_tcp_socket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | //! \ingroup socket_lib 21 | 22 | #pragma once 23 | 24 | // Socket lib includes 25 | #include "tas_conn_socket.h" 26 | 27 | //! \brief TCP socket class 28 | class CTasTcpSocket : public CTasConnSocket 29 | { 30 | public: 31 | //! \brief TCP socket constructor 32 | //! \details This creates an object that represents a stream socket which uses the TCP protocol 33 | CTasTcpSocket(); 34 | 35 | protected: 36 | //! \brief a friend class definition 37 | //! \details make the CTasTcpServerSocket class a friend of CTasTcpSocket class so it can access 38 | //! CTasTcpSocket(int tcp_sock_desc) constructor, which should not be available to the user 39 | friend class CTasTcpServerSocket; 40 | 41 | //! \brief TCP socket constructor with a socket descriptor 42 | explicit CTasTcpSocket(int tcp_sock_desc); 43 | }; -------------------------------------------------------------------------------- /test_package/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(PackageTest CXX) 3 | 4 | find_package(tas_client_api CONFIG REQUIRED) 5 | 6 | add_executable(pkg_test src/main.cpp) 7 | target_link_libraries(pkg_test tas_client_api::tas_client) 8 | -------------------------------------------------------------------------------- /test_package/conanfile.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | import os 20 | 21 | from conan import ConanFile 22 | from conan.tools.cmake import CMake, cmake_layout 23 | from conan.tools.build import can_run 24 | 25 | 26 | class helloTestConan(ConanFile): 27 | settings = "os", "compiler", "build_type", "arch" 28 | generators = "CMakeDeps", "CMakeToolchain" 29 | 30 | def requirements(self): 31 | self.requires(self.tested_reference_str) 32 | 33 | def build(self): 34 | cmake = CMake(self) 35 | cmake.configure() 36 | cmake.build() 37 | 38 | def layout(self): 39 | cmake_layout(self) 40 | 41 | def test(self): 42 | if can_run(self): 43 | cmd = os.path.join(self.cpp.build.bindir, "pkg_test") 44 | self.run(cmd, env="conanrun") 45 | -------------------------------------------------------------------------------- /test_package/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2024 Infineon Technologies AG. 3 | * 4 | * This file is part of TAS Client, an API for device access for Infineon's 5 | * automotive MCUs. 6 | * 7 | * Licensed under the Apache License, Version 2.0 (the "License"); 8 | * you may not use this file except in compliance with the License. 9 | * You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, software 14 | * distributed under the License is distributed on an "AS IS" BASIS, 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | * See the License for the specific language governing permissions and 17 | * limitations under the License. 18 | * **************************************************************************************************************** */ 19 | 20 | //******************************************************************************************************************** 21 | //------------------------------------------------------Includes------------------------------------------------------ 22 | //******************************************************************************************************************** 23 | #include "tas_client_rw.h" 24 | #include "tas_utils.h" 25 | #include "tas_device_family.h" 26 | 27 | #include 28 | #include 29 | 30 | //******************************************************************************************************************** 31 | //----------------------------------------------------- Main --------------------------------------------------------- 32 | //******************************************************************************************************************** 33 | int main(int argc, char** argv) 34 | { 35 | printf("TAS API demo\n"); 36 | 37 | // Create an instance of TAS Client RW 38 | CTasClientRw clientRw("DemoClientRw"); 39 | 40 | 41 | // Connect to the server, provide IP address or localhost 42 | tas_return_et ret; // TAS return value 43 | ret = clientRw.server_connect("localhost"); 44 | // Expected to fail, but this is ok, only for testing if conan package is created properly 45 | if (ret != TAS_ERR_NONE) { 46 | printf("Failed to connect to the server, %s\n", clientRw.get_error_info()); 47 | } 48 | 49 | return 0; 50 | } -------------------------------------------------------------------------------- /tools/build.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | import os 20 | import platform 21 | import argparse 22 | 23 | from utilities import run 24 | 25 | # Input arguments parsing 26 | parser = argparse.ArgumentParser("Build script for building TAS Client API") 27 | parser.add_argument("-c", "--config", choices=["release", "debug", "all"], default="release", help="Specifies configuration type to build") 28 | parser.add_argument("-p", "--python", help="Build the python wrapper of the C++ API", action="store_true") 29 | parser.add_argument("-d", "--docs", help="Build the API reference documentation", action="store_true") 30 | parser.add_argument("-t", "--tests", help="Build the test executables", action="store_true") 31 | parser.add_argument("-sq", "--sonar", help="Build using SonarQube build wrapper. Only in release mode.", action="store_true") 32 | args = parser.parse_args() 33 | 34 | # Generate build environment 35 | if args.config in ["release", "all"]: 36 | run(f"conan install . -o python={str(args.python)} -o docs={str(args.docs)} -o tests={str(args.tests)}") 37 | 38 | if args.config in ["debug", "all"]: 39 | run(f"conan install . -o python={str(args.python)} -o docs={str(args.docs)} -o tests={str(args.tests)} -s build_type=Debug --build=missing") 40 | 41 | # CMake version used 42 | run("cmake --version") 43 | 44 | # CMake configuration 45 | if platform.system() == "Windows": 46 | run("cmake --preset conan-default") 47 | else: 48 | if args.config in ["release", "all"]: 49 | run("cmake --preset conan-release") 50 | if args.config in ["debug", "all"]: 51 | run("cmake --preset conan-debug") 52 | 53 | # Build step 54 | if args.config in ["release", "all"]: 55 | if args.sonar: 56 | if platform.system() == "Windows": 57 | run("build-wrapper-win-x86-64.exe --out-dir bw-output cmake --build --preset conan-release") 58 | else: 59 | run(".sonar/build-wrapper-linux-x86/build-wrapper-linux-x86-64 --out-dir bw-output cmake --build --preset conan-release") 60 | else: 61 | run("cmake --build --preset conan-release") 62 | 63 | if args.config in ["debug", "all"]: 64 | run("cmake --build --preset conan-debug") 65 | -------------------------------------------------------------------------------- /tools/deploy.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | import os 20 | import re 21 | import platform 22 | from pathlib import Path 23 | from utilities import run 24 | 25 | # Helper function to get the current git branch name 26 | def get_active_branch_name(): 27 | head_dir = Path(".") / ".git" / "HEAD" 28 | with head_dir.open("r") as f: content = f.read().splitlines() 29 | 30 | for line in content: 31 | if line[0:4] == "ref:": 32 | return line.partition("refs/heads/")[2] 33 | 34 | # Get the current working dir 35 | current = os.getcwd() 36 | print(f"cwd: {current}") 37 | 38 | # Get the current active branch 39 | gitBranch = get_active_branch_name() 40 | print(f"Current git branch: {gitBranch}") 41 | 42 | # Determine package maturity 43 | pkgMaturity = "dev" 44 | if gitBranch == "master": 45 | pkgMaturity = "stable" 46 | 47 | # Get teh package version from the top level CMakeLists file 48 | # Prerequisite is that project definition includes the version property 49 | cmakeFile = Path(".") / "CMakeLists.txt" 50 | pkgVersion = "x.x.x" 51 | with cmakeFile.open("r") as f: 52 | content = f.read() 53 | pkgVersion = re.search(r"project((.|\n)*)VERSION (.*)", content).group(3) 54 | print(f"Package version: {pkgVersion}") 55 | 56 | # Create the TAS Client API package & upload it 57 | run(f"conan create . --user=ifx --channel={pkgMaturity}") 58 | run(f"conan upload tas_client_api/{pkgVersion}@ifx/{pkgMaturity} -r=conan-atv-debug-tools-local") 59 | 60 | # Uploading TAS Client API python wrapper wheel 61 | if platform.system() == "Windows": 62 | if os.path.exists(".\\build\\python\\"): 63 | os.chdir(".\\build\\python\\") 64 | run("python setup.py bdist_wheel upload -r local") 65 | else: 66 | print("Python wrapper not build, skipped uploading the wheel.") 67 | 68 | else: 69 | if os.path.exists("./build/Release/python/"): 70 | os.chdir("./build/Release/python/") 71 | run("python3 setup.py bdist_wheel upload -r local") 72 | else: 73 | print("Python wrapper not build, skipped uploading the wheel.") 74 | 75 | # Restoring the environment 76 | os.chdir(current) -------------------------------------------------------------------------------- /tools/start_tas_server.bat: -------------------------------------------------------------------------------- 1 | :: 2 | :: Copyright (c) 2024 Infineon Technologies AG. 3 | :: 4 | :: This file is part of TAS Client, an API for device access for Infineon's 5 | :: automotive MCUs. 6 | :: 7 | :: Licensed under the Apache License, Version 2.0 (the "License"); 8 | :: you may not use this file except in compliance with the License. 9 | :: You may obtain a copy of the License at 10 | :: 11 | :: http://www.apache.org/licenses/LICENSE-2.0 12 | :: 13 | :: Unless required by applicable law or agreed to in writing, software 14 | :: distributed under the License is distributed on an "AS IS" BASIS, 15 | :: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | :: See the License for the specific language governing permissions and 17 | :: limitations under the License. 18 | :: ****************************************************************************************************************:: 19 | cd %~dp0 20 | call tas_server.exe -------------------------------------------------------------------------------- /tools/test.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | import os 20 | import platform 21 | import subprocess 22 | from utilities import run 23 | 24 | current = os.getcwd() 25 | process = None 26 | # start a TAS server 27 | if platform.system() == "Windows": 28 | process = subprocess.Popen("C:\\Windows\\System32\\tas_server.exe", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) 29 | print(process.pid) 30 | os.chdir(".\\build") 31 | 32 | else: 33 | process = subprocess.Popen("/usr/local/bin/tas_server", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) 34 | os.chdir("./build/Release/") 35 | 36 | # Execute tests 37 | run("ctest -C Release") 38 | 39 | # kill the running TAS server 40 | process.terminate() 41 | 42 | os.chdir(current) -------------------------------------------------------------------------------- /tools/utilities.py: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2024 Infineon Technologies AG. 3 | # 4 | # This file is part of TAS Client, an API for device access for Infineon's 5 | # automotive MCUs. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # ****************************************************************************************************************# 19 | import os 20 | import subprocess 21 | import re 22 | from pathlib import Path 23 | 24 | def run(cmd, error=False): 25 | process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) 26 | output = "" 27 | 28 | print("Running: {}".format(cmd)) 29 | print("----- OUTPUT -------") 30 | while True: 31 | out = process.stdout.readline() 32 | out = out.decode("utf-8") 33 | 34 | ret = process.poll() 35 | if out == "" and ret is not None: 36 | break 37 | 38 | if out != "": 39 | output += out 40 | print(out.rstrip(os.linesep)) 41 | 42 | print("----END OUTPUT------") 43 | print() 44 | 45 | if ret != 0 and not error: 46 | raise Exception("Failed cmd: {}\n".format(cmd)) 47 | if ret == 0 and error: 48 | raise Exception( 49 | "Cmd succeded (failure expected): {}\n".format(cmd)) 50 | 51 | return output 52 | 53 | def get_project_version(cmake_file): 54 | cmakeFile = Path(cmake_file) 55 | with cmakeFile.open("r") as f: 56 | content = f.read() 57 | pkgVersion = re.search(r"project((.|\n)*)VERSION (.*)", content).group(3) 58 | return pkgVersion --------------------------------------------------------------------------------