Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ include(cmake/extensions.cmake)
include(cmake/version.cmake)
include(cmake/version_app.cmake)
include(cmake/multi_image.cmake)
include(cmake/sdp.cmake)

zephyr_include_directories(include)

Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@
/scripts/ncs-docker-version.txt @nrfconnect/ncs-ci
/scripts/print_docker_image.sh @nrfconnect/ncs-ci
/scripts/print_toolchain_checksum.sh @nrfconnect/ncs-ci
/scripts/sdp/ @nrfconnect/ncs-ll-ursus

/scripts/hid_configurator/*.rst @nrfconnect/ncs-si-bluebagel-doc
/scripts/memfault/*.rst @nrfconnect/ncs-cia-doc
Expand Down
2 changes: 2 additions & 0 deletions applications/sdp/gpio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(emulated_gpio)

sdp_assembly_generate("${CMAKE_SOURCE_DIR}/src/hrt/hrt.c")

target_sources(app PRIVATE src/main.c)
target_sources_ifdef(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICMSG app PRIVATE src/backend/backend_icmsg.c)
target_sources_ifdef(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICBMSG app PRIVATE src/backend/backend_icmsg.c)
Expand Down
21 changes: 21 additions & 0 deletions applications/sdp/gpio/src/hrt/hrt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/

#include <hal/nrf_vpr_csr_vio.h>

void set_direction(void)
{
nrf_vpr_csr_vio_dir_set(0xA);
nrf_vpr_csr_vio_dir_set(0xB);
nrf_vpr_csr_vio_dir_set(0xC);
}

void set_output(void)
{
nrf_vpr_csr_vio_out_set(0xA);
nrf_vpr_csr_vio_dir_set(0xB);
nrf_vpr_csr_vio_dir_set(0xC);
}
51 changes: 51 additions & 0 deletions cmake/sdp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

function(sdp_assembly_generate hrt_srcs)
set(hrt_msg "Generating ASM files for Hard Real Time files.")
set(hrt_opts -g0 -fno-ident -fno-verbose-asm)

# Compiler does not know how to build for this platform so we export
# all the flags used in this zephyr build to the external build system.
zephyr_get_compile_options_for_lang(C options)
zephyr_get_compile_definitions_for_lang(C defines)
zephyr_get_include_directories_for_lang(C includes)
zephyr_get_system_include_directories_for_lang(C sys_includes)
# Replace "-I" with "-isystem" to treat all Zephyr headers as system headers
# that do not trigger -Werror.
string(REPLACE "-I" "-isystem" includes "${includes}")

set(compiler_options ${defines} ${options} ${includes} ${sys_includes})

if(TARGET asm_gen)
message(FATAL_ERROR "sdp_assembly_generate() already called, please note that
sdp_assembly_generate() must be called only once with a list of all source files."
)
endif()

# Define the asm_gen target that depends on all generated assembly files
add_custom_target(asm_gen
COMMENT ${hrt_msg}
)

foreach(hrt_src ${hrt_srcs})
if(IS_DIRECTORY ${hrt_src})
message(FATAL_ERROR "sdp_assembly_generate() was called on a directory")
endif()
get_filename_component(src_filename ${hrt_src} NAME_WE) # filename without extension
add_custom_command(TARGET asm_gen
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be a problem if the sdp_assembly_generate() function is called multiple times, for example like this:

sdp_assembly_generate(foo.c)
sdp_assembly_generate(bar.c)

because there can only be a single asm_gen target created.

This might be an acceptable limitation for now, but could you please make this check and provide a use-ful error to the user, for example a check like this:

if(TARGET asm_gen)
    message(FATAL_ERROR "sdp_assembly_generate() already called, please note that 
                    sdp_assembly_generate() must be called only once with a list of all source files."
    )
endif()

Note, line length not checked in above example.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message with FATAL_ERROR has been added.

BYPRODUCTS ${src_filename}-temp.s
COMMAND ${CMAKE_C_COMPILER} ${compiler_options} ${hrt_opts} -S ${hrt_src} -o ${src_filename}-temp.s
COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_NRF_MODULE_DIR}/scripts/sdp/remove_comments.py ${src_filename}-temp.s
DEPENDS ${hrt_src}
COMMAND_EXPAND_LISTS
COMMENT "Generating ASM file for ${hrt_src}"
)
endforeach()

add_dependencies(asm_gen syscall_list_h_target)

endfunction()
48 changes: 48 additions & 0 deletions scripts/sdp/remove_comments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

import os
import sys

def remove_comments_from_assembly_file(input_file):
"""Cleans an assembly file by removing lines starting with # and saves the changes in the same file."""
with open(input_file, 'r') as infile:
lines = infile.readlines()

# Filter out lines starting with #
cleaned_lines = [line for line in lines if not line.startswith('#')]
Comment on lines +16 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note, gcc may use @ instead.
See #17638 (comment)


# Save the cleaned file in the same file
with open(input_file, 'w') as outfile:
outfile.writelines(cleaned_lines)

print(f"File {input_file} has been cleaned of comments.")

def process_directory(directory):
"""Processes all .s files in the directory."""
for root, _, files in os.walk(directory): # '_' instead of 'dirs' to ignore unused variable
for file in files:
if file.endswith('.s'):
input_file = os.path.join(root, file)
remove_comments_from_assembly_file(input_file)

def main(path):
"""Checks if given path is a file or a directory and processes it accordingly."""
if os.path.isfile(path) and path.endswith('.s'):
# If a single .s file is provided
remove_comments_from_assembly_file(path)
elif os.path.isdir(path):
# If a directory is provided
process_directory(path)
else:
print("The provided path is neither a .s file nor a directory.")

if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python clean_asm.py <file.or.directory>")
else:
main(sys.argv[1])
Loading