Skip to content

Commit

Permalink
refactor peakrdl_regblock and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Risto97 committed Oct 5, 2024
1 parent f77c479 commit 648dd7d
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 28 deletions.
27 changes: 12 additions & 15 deletions cmake/peakrdl/peakrdl_regblock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#]]
function(peakrdl_regblock IP_LIB)
# Parse keyword arguments
cmake_parse_arguments(ARG "" "OUTDIR;RENAME;INTF;RESET" "" ${ARGN})
cmake_parse_arguments(ARG "" "OUTDIR;RENAME;INTF;RESET" "ARGS" ${ARGN})
# Check for any unknown argument
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "${CMAKE_CURRENT_FUNCTION} passed unrecognized argument "
Expand All @@ -48,28 +48,23 @@ function(peakrdl_regblock IP_LIB)
alias_dereference(IP_LIB ${IP_LIB})
get_target_property(BINARY_DIR ${IP_LIB} BINARY_DIR)

# Default output directory is regblock/
if(NOT ARG_OUTDIR)
set(OUTDIR ${BINARY_DIR}/regblock)
set(OUTDIR ${BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION})
else()
set(OUTDIR ${ARG_OUTDIR})
endif()

if(NOT ARG_RENAME)
# The default name is the IP name
get_target_property(REGBLOCK_NAME ${IP_LIB} IP_NAME)
if(NOT REGBLOCK_NAME)
message(FATAL_ERROR "IP_NAME not set for ${IP_LIB}, check if the IP was added with
add_ip function from SoCMake")
endif()
set(REGBLOCK_NAME ${REGBLOCK_NAME}_regblock)
else()
set(REGBLOCK_NAME ${ARG_RENAME})
endif()

# The default interface used is apb3, set another on if the argument exists
if(ARG_INTF)
set(INTF_ARG --cpuif ${ARG_INTF})
if(NOT ARG_INTF)
set(ARG_INTF apb3-flat)
endif()

# The default reset is active-high and synchronous
Expand Down Expand Up @@ -101,12 +96,13 @@ function(peakrdl_regblock IP_LIB)
find_python3()
set(__CMD ${Python3_EXECUTABLE} -m peakrdl regblock
--rename ${REGBLOCK_NAME}
${INTF_ARG}
--cpuif ${ARG_INTF}
${RESET_ARG}
${INCDIRS_ARG}
${COMPDEFS_ARG}
-o ${OUTDIR}
${RDL_SOURCES}
${ARG_ARGS}
)

set(SV_GEN
Expand All @@ -117,22 +113,23 @@ function(peakrdl_regblock IP_LIB)
ip_sources(${IP_LIB} SYSTEMVERILOG PREPEND ${SV_GEN})

set(STAMP_FILE "${BINARY_DIR}/${IP_LIB}_${CMAKE_CURRENT_FUNCTION}.stamp")
set(DESCRIPTION "Generate register file for \"${IP_LIB}\" with ${ARG_INTF} bus, with ${CMAKE_CURRENT_FUNCTION}")
add_custom_command(
# The output files are automtically marked as GENERATED (deleted by make clean among other things)
OUTPUT ${SV_GEN} ${STAMP_FILE}
COMMAND ${__CMD}

COMMAND touch ${STAMP_FILE}
DEPENDS ${RDL_SOURCES}
COMMENT "Running ${CMAKE_CURRENT_FUNCTION} on ${IP_LIB}"
COMMENT ${DESCRIPTION}
)
# This target triggers the systemverilog register block generation using peakRDL regblock tool (_CMD)
add_custom_target(
${IP_LIB}_regblock
${IP_LIB}_${CMAKE_CURRENT_FUNCTION}
DEPENDS ${SV_GEN} ${STAMP_FILE}
)
set_property(TARGET ${IP_LIB}_${CMAKE_CURRENT_FUNCTION} PROPERTY DESCRIPTION ${DESCRIPTION})

add_dependencies(${IP_LIB} ${IP_LIB}_regblock)
set_property(TARGET ${IP_LIB} APPEND PROPERTY DEPENDS ${IP_LIB}_regblock)
add_dependencies(${IP_LIB} ${IP_LIB}_${CMAKE_CURRENT_FUNCTION})
set_property(TARGET ${IP_LIB} APPEND PROPERTY DEPENDS ${IP_LIB}_${CMAKE_CURRENT_FUNCTION})

endfunction()
1 change: 0 additions & 1 deletion tests/peakrdl/CMakeLists.txt

This file was deleted.

12 changes: 0 additions & 12 deletions tests/peakrdl/ip2.rdl

This file was deleted.

1 change: 1 addition & 0 deletions tests/tests/peakrdl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
add_subdirectory(print)
add_subdirectory(regblock)
59 changes: 59 additions & 0 deletions tests/tests/peakrdl/regblock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
include("../../../../SoCMakeConfig.cmake")
include("../../../utils/test_utils.cmake")

cmake_minimum_required(VERSION 3.25)
project(test NONE)

add_ip(ip)

ip_sources(${IP} SYSTEMRDL
${CMAKE_CURRENT_LIST_DIR}/ip.rdl
)

peakrdl_regblock(${IP})

include(CTest)
enable_testing()

find_python3()
add_test_makefile_rule_match_patterns(${IP}_peakrdl_regblock
"${Python3_EXECUTABLE} -m"
"peakrdl regblock"
"--rename ${IP_NAME}_regblock"
"--cpuif apb3-flat"
"-o ${PROJECT_BINARY_DIR}/${IP}_peakrdl_regblock"
"${CMAKE_CURRENT_LIST_DIR}/ip.rdl"
)

add_ip(ip2)

ip_sources(${IP} SYSTEMRDL
${CMAKE_CURRENT_LIST_DIR}/ip2.rdl
)

ip_link(ip2 ip)

peakrdl_regblock(${IP}
OUTDIR ${PROJECT_BINARY_DIR}/ip2_regblock
INTF axi4-lite
RENAME random_ip
RESET arst_n
ARGS --addr-width 8
--rt-read-response
)

include(CTest)
enable_testing()

find_python3()
add_test_makefile_rule_match_patterns(${IP}_peakrdl_regblock
"${Python3_EXECUTABLE} -m"
"peakrdl regblock"
"--rename random_ip"
"--cpuif axi4-lite"
"--default-reset arst_n"
"--addr-width 8"
"--rt-read-response"
"-o ${PROJECT_BINARY_DIR}/ip2_regblock"
"${CMAKE_CURRENT_LIST_DIR}/ip.rdl ${CMAKE_CURRENT_LIST_DIR}/ip2.rdl" # Keep them in single string to enforce order
)
18 changes: 18 additions & 0 deletions tests/tests/peakrdl/regblock/ip.rdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
addrmap ip {
reg {
regwidth = 32;
field {
hw = rw; sw = rw;
fieldwidth = 32;
} f1;
} r1;

reg {
regwidth = 32;
field {
hw = r; sw = rw;
fieldwidth = 32;
} f1;
} r2;

};
19 changes: 19 additions & 0 deletions tests/tests/peakrdl/regblock/ip2.rdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
addrmap ip2 {
reg {
regwidth = 32;
field {
hw = rw; sw = rw;
fieldwidth = 32;
} f1;
} r1;

reg {
regwidth = 32;
field {
hw = r; sw = rw;
fieldwidth = 32;
} f1;
} r2;

};

0 comments on commit 648dd7d

Please sign in to comment.