-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
1 parent
f7258d0
commit 8f89e65
Showing
5 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
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]) |