Skip to content

Commit

Permalink
applications: sdp: Add asm_gen target
Browse files Browse the repository at this point in the history
Added asm_gen target, which is needed to generate
assembler files for the hard real time part.

Signed-off-by: Jakub Zymelka <[email protected]>
  • Loading branch information
jaz1-nordic committed Oct 4, 2024
1 parent f7258d0 commit 8f89e65
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 0 deletions.
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)

include(${ZEPHYR_NRF_MODULE_DIR}/cmake/sdp.cmake)

target_sources_ifdef(CONFIG_GPIO_NRFE_EGPIO_BACKEND_ICMSG app PRIVATE src/nrfe_icmsg.c)
target_sources_ifdef(CONFIG_GPIO_NRFE_EGPIO_BACKEND_MBOX app PRIVATE src/nrfe_mbox.c)
target_sources(app PRIVATE src/main.c)
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);
}
30 changes: 30 additions & 0 deletions applications/sdp/gpio/src/hrt/hrt.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.file "hrt.c"
.option nopic
.attribute arch, "rv32e1p9_m2p0_c2p0_zicsr2p0_zifencei2p0"
.attribute unaligned_access, 0
.attribute stack_align, 4
.text
.section .text.set_direction,"ax",@progbits
.align 1
.globl set_direction
.type set_direction, @function
set_direction:
#APP
csrw 3009, 10
csrw 3009, 11
csrw 3009, 12
#NO_APP
ret
.size set_direction, .-set_direction
.section .text.set_output,"ax",@progbits
.align 1
.globl set_output
.type set_output, @function
set_output:
#APP
csrw 3008, 10
csrw 3009, 11
csrw 3009, 12
#NO_APP
ret
.size set_output, .-set_output
34 changes: 34 additions & 0 deletions cmake/sdp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (c) 2024 Nordic Semiconductor ASA
#
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
#

function(sdp_assembly_generate)
set(hrt_dir ${PROJECT_SOURCE_DIR}/src/hrt)
set(hrt_src ${hrt_dir}/hrt.c)
set(hrt_msg "Generating ASM file for Hard Real Time files.")

# The external static library that we are linking with 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 hrt_opt)
zephyr_get_compile_definitions_for_lang(C hrt_def)
zephyr_get_include_directories_for_lang(C hrt_inc)
zephyr_get_system_include_directories_for_lang(C hrt_sys)
# Replace "-I" with "-isystem" to treat all Zephyr headers as system headers
# that do not trigger -Werror.
string(REPLACE "-I" "-isystem" hrt_inc "${hrt_inc}")

zephyr_include_directories(include)

add_custom_target(asm_gen
COMMAND ${CMAKE_C_COMPILER} ${hrt_def} ${hrt_opt} ${hrt_inc} ${hrt_sys} -g0 -P -fno-ident -fno-verbose-asm -S ${hrt_src}
COMMAND python3 ${ZEPHYR_NRF_MODULE_DIR}/scripts/sdp/clean_asm.py ${hrt_dir}
WORKING_DIRECTORY "${hrt_dir}"
COMMAND_EXPAND_LISTS
COMMENT ${hrt_msg}
)
endfunction()

sdp_assembly_generate()
48 changes: 48 additions & 0 deletions scripts/sdp/clean_asm.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 clean_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('#')]

# 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, dirs, files in os.walk(directory):

Check warning on line 27 in scripts/sdp/clean_asm.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

W0612

scripts/sdp/clean_asm.py:27 Unused variable 'dirs' (unused-variable)
for file in files:
if file.endswith('.s'):
input_file = os.path.join(root, file)
clean_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
clean_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])

0 comments on commit 8f89e65

Please sign in to comment.