Skip to content

Commit 7bcd022

Browse files
markxoeParaZera
authored andcommitted
feat: initial uds support for ARDEP
- renamed the current UDS library to `uds_legacy` (including Kconfig options) - added support for an external UDS-lib as a zephyr module (https://github.com/driftregion/iso14229) - Currently, there is a PR open to support the *Read DTC Information (`0x19`)* subFunction (driftregion/iso14229#86). - added low-level zephyr support via the `iso14229` library - added new uds library building ontop of the `iso14229` with currently support of the following functions: - Diagnostic Session Control (`0x10`) - ECU Reset (`0x11`) - Read/Write Data by Identifier (`0x22`, `0x2E`) - Read/Write Memeory be Address (`0x23`, `0x3D`) - Read DTC Information (`0x19`) - added tests for the *iso14229* and *uds* lib - added a new uds sample that demonstrates the aforementioned functions - documentation for the uds sample (rst) and lib (doxygen) - CI jobs build samples/tests on all supported os types (linux, mac, windows) Signed-off-by: Tim Schrader <tim.schrader@frickly.systems>
1 parent bbb3153 commit 7bcd022

File tree

104 files changed

+6145
-454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+6145
-454
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,48 @@ on:
88

99
jobs:
1010
build:
11-
runs-on: ubuntu-22.04
12-
container: ghcr.io/zephyrproject-rtos/ci:v0.26.2
13-
env:
14-
CMAKE_PREFIX_PATH: /opt/toolchains
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-24.04, macos-15, windows-2022]
15+
runs-on: ${{ matrix.os }}
1516
steps:
1617
- name: Checkout
17-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1819
with:
19-
path: zephyr-workspace/ardep
20+
path: ardep
2021

21-
- name: Initialize
22-
working-directory: zephyr-workspace/ardep
23-
run: |
24-
west init -l --mf ./west.yml .
25-
west update -o=--depth=1 -n
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: 3.12
26+
27+
- name: Setup Zephyr project
28+
uses: zephyrproject-rtos/action-zephyr-setup@v1
29+
with:
30+
app-path: ardep
31+
toolchains: arm-zephyr-eabi
2632

27-
- name: Build firmware examples
28-
working-directory: zephyr-workspace/ardep
33+
- name: Build firmware
34+
working-directory: ardep
35+
shell: bash
2936
run: |
30-
west twister -T samples -v --inline-logs --integration
37+
if [ "${{ runner.os }}" = "Windows" ]; then
38+
EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out"
39+
fi
40+
west twister -T samples -v --inline-logs --integration $EXTRA_TWISTER_FLAGS
3141
3242
- name: build bootloader
33-
working-directory: zephyr-workspace/ardep
43+
working-directory: ardep
3444
run: |
3545
pip install -r scripts/requirements.txt
3646
west ardep build-bootloader
47+
48+
- name: Twister Tests
49+
working-directory: ardep
50+
shell: bash
51+
run: |
52+
if [ "${{ runner.os }}" = "Windows" ]; then
53+
EXTRA_TWISTER_FLAGS="--short-build-path -O/tmp/twister-out"
54+
fi
55+
west twister -T tests -p native_sim -v --inline-logs --integration $EXTRA_TWISTER_FLAGS

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/twister-out*
1212

1313
__pycache__/
14+
.mypy_cache/
1415

1516
# documentation build output
1617
doc/_build/
@@ -19,4 +20,4 @@ doc/samples/
1920
doc/scripts/
2021

2122
# clangd cache
22-
.cache
23+
.cache

boards/mercedes/ardep/Kconfig.uds

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@
66
# enable UDS module per default
77

88
config UDS
9-
default y
10-
config CAN
119
default y
12-
config ISOTP
10+
11+
config ISO14229
12+
default n # Disables minimal UDS support when UDS gets disabled
13+
14+
choice STD_C
15+
default STD_C11 # requirement for external iso14229 module
16+
endchoice
17+
18+
config CAN
1319
default y
1420

1521
config FLASH
@@ -26,3 +32,4 @@ config IMG_ERASE_PROGRESSIVELY
2632

2733
config REBOOT
2834
default y
35+

doc/Doxyfile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,15 +2214,15 @@ ENABLE_PREPROCESSING = YES
22142214
# The default value is: NO.
22152215
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
22162216

2217-
MACRO_EXPANSION = NO
2217+
MACRO_EXPANSION = YES
22182218

22192219
# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES then
22202220
# the macro expansion is limited to the macros specified with the PREDEFINED and
22212221
# EXPAND_AS_DEFINED tags.
22222222
# The default value is: NO.
22232223
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
22242224

2225-
EXPAND_ONLY_PREDEF = NO
2225+
EXPAND_ONLY_PREDEF = YES
22262226

22272227
# If the SEARCH_INCLUDES tag is set to YES, the include files in the
22282228
# INCLUDE_PATH will be searched if a #include is found.
@@ -2254,7 +2254,7 @@ INCLUDE_FILE_PATTERNS =
22542254
# recursively expanded use the := operator instead of the = operator.
22552255
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
22562256

2257-
PREDEFINED =
2257+
PREDEFINED = CONFIG_UDS_ENABLE_RESET CONFIG_UDS_USE_DYNAMIC_REGISTRATION
22582258

22592259
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
22602260
# tag can be used to specify a list of macro names that should be expanded. The
@@ -2315,8 +2315,8 @@ ALLEXTERNALS = NO
23152315
EXTERNAL_GROUPS = YES
23162316

23172317
# If the EXTERNAL_PAGES tag is set to YES, all external pages will be listed in
2318-
# the related pages index. If set to NO, only the current project's pages will
2319-
# be listed.
2318+
# the related pages index. If set to NO, only the current project's pages will be
2319+
# listed.
23202320
# The default value is: YES.
23212321

23222322
EXTERNAL_PAGES = YES

include/ardep/iso14229.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (C) Frickly Systems GmbH
3+
* Copyright (C) MBition GmbH
4+
*
5+
* SPDX-License-Identifier: Apache-2.0
6+
*/
7+
8+
#ifndef ARDEP_ISO14229_H
9+
#define ARDEP_ISO14229_H
10+
11+
#include <zephyr/drivers/can.h>
12+
#include <zephyr/kernel.h>
13+
#include <zephyr/sys/atomic.h>
14+
15+
#include <iso14229.h>
16+
17+
struct iso14229_zephyr_instance;
18+
19+
/**
20+
* @brief Callback type for UDS events
21+
*
22+
* @param inst Pointer to the iso-14229 instance the event occurred on
23+
* @param event The event that occurred
24+
* @param arg Argument provided by the event source (might be NULL depending on
25+
* the event)
26+
* @param user_context User-defined context pointer as passed to \ref uds_init()
27+
*/
28+
typedef UDSErr_t (*uds_callback)(struct iso14229_zephyr_instance* inst,
29+
UDSEvent_t event,
30+
void* arg,
31+
void* user_context);
32+
33+
/**
34+
* @brief A Zephyr-specific ISO-14229 instance
35+
*/
36+
struct iso14229_zephyr_instance {
37+
/**
38+
* @brief Underlying uds server instance
39+
*/
40+
UDSServer_t server;
41+
/**
42+
* @brief Underlying isotp instance
43+
*/
44+
UDSISOTpC_t tp;
45+
46+
struct k_msgq can_phys_msgq;
47+
struct k_msgq can_func_msgq;
48+
49+
char can_phys_buffer[sizeof(struct can_frame) * 25];
50+
char can_func_buffer[sizeof(struct can_frame) * 25];
51+
52+
struct k_mutex event_callback_mutex;
53+
uds_callback event_callback;
54+
55+
void* user_context;
56+
57+
k_tid_t thread_id;
58+
struct k_thread thread_data;
59+
K_KERNEL_STACK_MEMBER(thread_stack, 1024);
60+
bool thread_running;
61+
atomic_t thread_stop_requested;
62+
struct k_mutex thread_mutex;
63+
64+
/**
65+
* @brief Set the UDS event callback that gets called when a
66+
* new event is emitted by the server
67+
*/
68+
int (*set_callback)(struct iso14229_zephyr_instance* inst,
69+
uds_callback callback);
70+
/**
71+
* @brief Handle a single iteration of the UDS server thread
72+
*
73+
* @note This function must be called periodically when the UDS
74+
* thread is not started by @ref thread_start.
75+
*/
76+
void (*thread_tick)(struct iso14229_zephyr_instance* inst);
77+
/**
78+
* @brief Start the UDS server thread
79+
*/
80+
int (*thread_start)(struct iso14229_zephyr_instance* inst);
81+
/**
82+
* @brief Stop the UDS server thread
83+
*/
84+
int (*thread_stop)(struct iso14229_zephyr_instance* inst);
85+
};
86+
87+
/**
88+
* @brief Initialize a Zephyr-specific ISO-14229 instance
89+
*
90+
* @param inst Pointer to the instance to initialize
91+
* @param iso_tp_config ISO-TP configuration
92+
* @param can_dev CAN device the UDS Server should use
93+
* @param user_context User-defined context pointer that is passed to event
94+
* callbacks
95+
*
96+
* @returns 0 on success
97+
* @returns <0 on failure
98+
*/
99+
int iso14229_zephyr_init(struct iso14229_zephyr_instance* inst,
100+
const UDSISOTpCConfig_t* iso_tp_config,
101+
const struct device* can_dev,
102+
void* user_context);
103+
104+
#endif // ARDEP_ISO14229_H

0 commit comments

Comments
 (0)