diff --git a/cmake/peakrdl/peakrdl_regblock.cmake b/cmake/peakrdl/peakrdl_regblock.cmake index 77ca910..0db07e8 100644 --- a/cmake/peakrdl/peakrdl_regblock.cmake +++ b/cmake/peakrdl/peakrdl_regblock.cmake @@ -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 " @@ -48,9 +48,8 @@ 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() @@ -58,18 +57,14 @@ function(peakrdl_regblock IP_LIB) 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 @@ -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 @@ -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() diff --git a/tests/peakrdl/CMakeLists.txt b/tests/peakrdl/CMakeLists.txt deleted file mode 100644 index b8bdb1e..0000000 --- a/tests/peakrdl/CMakeLists.txt +++ /dev/null @@ -1 +0,0 @@ -add_subdirectory(print) diff --git a/tests/peakrdl/ip2.rdl b/tests/peakrdl/ip2.rdl deleted file mode 100644 index 5b7e201..0000000 --- a/tests/peakrdl/ip2.rdl +++ /dev/null @@ -1,12 +0,0 @@ -addrmap ip2 { - reg { - regwidth = 32; - field { - fieldwidth = 32; - } f1; - } testreg2; - - `ifdef USE_IP1 - ip1 ip1_i; - `endif -}; diff --git a/tests/tests/peakrdl/CMakeLists.txt b/tests/tests/peakrdl/CMakeLists.txt index b8bdb1e..b664925 100644 --- a/tests/tests/peakrdl/CMakeLists.txt +++ b/tests/tests/peakrdl/CMakeLists.txt @@ -1 +1,2 @@ add_subdirectory(print) +add_subdirectory(regblock) diff --git a/tests/tests/peakrdl/regblock/CMakeLists.txt b/tests/tests/peakrdl/regblock/CMakeLists.txt new file mode 100644 index 0000000..e76b233 --- /dev/null +++ b/tests/tests/peakrdl/regblock/CMakeLists.txt @@ -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 + ) diff --git a/tests/tests/peakrdl/regblock/ip.rdl b/tests/tests/peakrdl/regblock/ip.rdl new file mode 100644 index 0000000..a65bdb5 --- /dev/null +++ b/tests/tests/peakrdl/regblock/ip.rdl @@ -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; + +}; diff --git a/tests/tests/peakrdl/regblock/ip2.rdl b/tests/tests/peakrdl/regblock/ip2.rdl new file mode 100644 index 0000000..a8d1025 --- /dev/null +++ b/tests/tests/peakrdl/regblock/ip2.rdl @@ -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; + +}; +