Skip to content

Commit 5ede0d6

Browse files
jaz1-nordicrlubos
authored andcommitted
applications: sdp: Add asm_gen target
Added asm_gen target, which is needed to generate assembler files for the hard real time part. Signed-off-by: Jakub Zymelka <[email protected]>
1 parent 83a6113 commit 5ede0d6

File tree

6 files changed

+124
-0
lines changed

6 files changed

+124
-0
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ include(cmake/extensions.cmake)
2525
include(cmake/version.cmake)
2626
include(cmake/version_app.cmake)
2727
include(cmake/multi_image.cmake)
28+
include(cmake/sdp.cmake)
2829

2930
zephyr_include_directories(include)
3031

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@
597597
/scripts/ncs-docker-version.txt @nrfconnect/ncs-ci
598598
/scripts/print_docker_image.sh @nrfconnect/ncs-ci
599599
/scripts/print_toolchain_checksum.sh @nrfconnect/ncs-ci
600+
/scripts/sdp/ @nrfconnect/ncs-ll-ursus
600601

601602
/scripts/hid_configurator/*.rst @nrfconnect/ncs-si-bluebagel-doc
602603
/scripts/memfault/*.rst @nrfconnect/ncs-cia-doc

applications/sdp/gpio/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ cmake_minimum_required(VERSION 3.20.0)
99
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
1010
project(emulated_gpio)
1111

12+
sdp_assembly_generate("${CMAKE_SOURCE_DIR}/src/hrt/hrt.c")
13+
1214
target_sources(app PRIVATE src/main.c)
1315
target_sources_ifdef(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICMSG app PRIVATE src/backend/backend_icmsg.c)
1416
target_sources_ifdef(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICBMSG app PRIVATE src/backend/backend_icmsg.c)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright (c) 2024 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <hal/nrf_vpr_csr_vio.h>
8+
9+
void set_direction(void)
10+
{
11+
nrf_vpr_csr_vio_dir_set(0xA);
12+
nrf_vpr_csr_vio_dir_set(0xB);
13+
nrf_vpr_csr_vio_dir_set(0xC);
14+
}
15+
16+
void set_output(void)
17+
{
18+
nrf_vpr_csr_vio_out_set(0xA);
19+
nrf_vpr_csr_vio_dir_set(0xB);
20+
nrf_vpr_csr_vio_dir_set(0xC);
21+
}

cmake/sdp.cmake

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#
2+
# Copyright (c) 2024 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
function(sdp_assembly_generate hrt_srcs)
8+
set(hrt_msg "Generating ASM files for Hard Real Time files.")
9+
set(hrt_opts -g0 -fno-ident -fno-verbose-asm)
10+
11+
# Compiler does not know how to build for this platform so we export
12+
# all the flags used in this zephyr build to the external build system.
13+
zephyr_get_compile_options_for_lang(C options)
14+
zephyr_get_compile_definitions_for_lang(C defines)
15+
zephyr_get_include_directories_for_lang(C includes)
16+
zephyr_get_system_include_directories_for_lang(C sys_includes)
17+
# Replace "-I" with "-isystem" to treat all Zephyr headers as system headers
18+
# that do not trigger -Werror.
19+
string(REPLACE "-I" "-isystem" includes "${includes}")
20+
21+
set(compiler_options ${defines} ${options} ${includes} ${sys_includes})
22+
23+
if(TARGET asm_gen)
24+
message(FATAL_ERROR "sdp_assembly_generate() already called, please note that
25+
sdp_assembly_generate() must be called only once with a list of all source files."
26+
)
27+
endif()
28+
29+
# Define the asm_gen target that depends on all generated assembly files
30+
add_custom_target(asm_gen
31+
COMMENT ${hrt_msg}
32+
)
33+
34+
foreach(hrt_src ${hrt_srcs})
35+
if(IS_DIRECTORY ${hrt_src})
36+
message(FATAL_ERROR "sdp_assembly_generate() was called on a directory")
37+
endif()
38+
get_filename_component(src_filename ${hrt_src} NAME_WE) # filename without extension
39+
add_custom_command(TARGET asm_gen
40+
BYPRODUCTS ${src_filename}-temp.s
41+
COMMAND ${CMAKE_C_COMPILER} ${compiler_options} ${hrt_opts} -S ${hrt_src} -o ${src_filename}-temp.s
42+
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_NRF_MODULE_DIR}/scripts/sdp/remove_comments.py ${src_filename}-temp.s
43+
DEPENDS ${hrt_src}
44+
COMMAND_EXPAND_LISTS
45+
COMMENT "Generating ASM file for ${hrt_src}"
46+
)
47+
endforeach()
48+
49+
add_dependencies(asm_gen syscall_list_h_target)
50+
51+
endfunction()

scripts/sdp/remove_comments.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright (c) 2024 Nordic Semiconductor ASA
4+
#
5+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
6+
#
7+
8+
import os
9+
import sys
10+
11+
def remove_comments_from_assembly_file(input_file):
12+
"""Cleans an assembly file by removing lines starting with # and saves the changes in the same file."""
13+
with open(input_file, 'r') as infile:
14+
lines = infile.readlines()
15+
16+
# Filter out lines starting with #
17+
cleaned_lines = [line for line in lines if not line.startswith('#')]
18+
19+
# Save the cleaned file in the same file
20+
with open(input_file, 'w') as outfile:
21+
outfile.writelines(cleaned_lines)
22+
23+
print(f"File {input_file} has been cleaned of comments.")
24+
25+
def process_directory(directory):
26+
"""Processes all .s files in the directory."""
27+
for root, _, files in os.walk(directory): # '_' instead of 'dirs' to ignore unused variable
28+
for file in files:
29+
if file.endswith('.s'):
30+
input_file = os.path.join(root, file)
31+
remove_comments_from_assembly_file(input_file)
32+
33+
def main(path):
34+
"""Checks if given path is a file or a directory and processes it accordingly."""
35+
if os.path.isfile(path) and path.endswith('.s'):
36+
# If a single .s file is provided
37+
remove_comments_from_assembly_file(path)
38+
elif os.path.isdir(path):
39+
# If a directory is provided
40+
process_directory(path)
41+
else:
42+
print("The provided path is neither a .s file nor a directory.")
43+
44+
if __name__ == "__main__":
45+
if len(sys.argv) != 2:
46+
print("Usage: python clean_asm.py <file.or.directory>")
47+
else:
48+
main(sys.argv[1])

0 commit comments

Comments
 (0)