Skip to content

Commit

Permalink
Peakrdl regblock refactor (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
Risto97 authored Oct 5, 2024
1 parent 59c59e7 commit 1c6ae51
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 173 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
sudo make install
cd ..
pip install peakrdl
pip install peakrdl rich
- name: run tests
run: |
Expand Down
1 change: 0 additions & 1 deletion SoCMakeConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ include("${CMAKE_CURRENT_LIST_DIR}/cmake/sim/cocotb/add_cocotb_iverilog_tests.cm
# ====================================

include("${CMAKE_CURRENT_LIST_DIR}/cmake/peakrdl/peakrdl_regblock.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/peakrdl/peakrdl_regblock_wrap.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/peakrdl/peakrdl_halcpp.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/peakrdl/peakrdl_ipblocksvg.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/cmake/peakrdl/peakrdl_html/peakrdl_html.cmake")
Expand Down
47 changes: 22 additions & 25 deletions cmake/peakrdl/peakrdl_regblock.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,40 @@
# PeakRDL-regblock is transforming SystemRDL input files to SystemVerilog register block files.
# Regblock documentation can be found on this `link <https://peakrdl-regblock.readthedocs.io/en/latest/>`_.
#
# Function expects that **${IP_LIB}** *INTERFACE_LIBRARY* has **SYSTEMRDL_SOURCES** property set with
# Function expects that **${IP_LIB}** has **SYSTEMRDL_SOURCES** property set with
# a list of SystemRDL files to be used as inputs. To set the SYSTEMRDL_SOURCES property use the ip_sources()
# function from SoCMake (internally using `set_property()
# <https://cmake.org/cmake/help/latest/command/set_property.html>`_ CMake function):
#
# .. code-block:: cmake
#
# ip_sources(IP_LIB LANGUAGE [SYSTEMRDL|SYSTEMVERILOG|...] ${PROJECT_SOURCE_DIR}/file.rdl)
# ip_sources(ip SYSTEMRDL ${PROJECT_SOURCE_DIR}/file.rdl)
#
#
# This function will append 2 generated files from PeakRDL-regblock to the **SOURCES** property of the
# This function will append 2 generated files from PeakRDL-regblock to the **SYSTEMVERILOG_SOURCES** property of the
# **${IP_LIB}**.
#
# :param IP_LIB: RTL interface library, it needs to have SYSTEMRDL_SOURCES property set with a list of
# SystemRDL files.
# :type IP_LIB: INTERFACE_LIBRARY
# :param IP_LIB: IP for which to create regblock target.
# :type IP_LIB: IP library
#
# **Keyword Arguments**
#
# :keyword OUTDIR: output directory in which the files will be generated.
# If ommited ${BINARY_DIR}/regblock will be used.
# :type OUTDIR: string path
# :type OUTDIR: string
# :keyword RENAME: Rename the generated module and file name to a custom string, otherwise the
# name will be ${IP_LIB}.sv.
# :type RENAME: string
# :keyword INTF: Interface to use for the regblock. Possible values are:
# [apb3 (default), apb3-flat, apb4, apb4-flat, axi4-lite, axi4-lite-flat, avalon-mm, avalon-mm-flat, passthrough]
# :type INTF: string
# :keyword RESET: reset type for generated regblock. Possible values are:
# [rst (default), rst,rst_n,arst,arst_n]
# :type RESET: string
# :keyword ARGS: any additional arguments to pass to regblock cli executable
# :type ARGS: list
#]]
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 +50,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 +98,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 +115,21 @@ 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}
)

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

endfunction()
132 changes: 0 additions & 132 deletions cmake/peakrdl/peakrdl_regblock_wrap.cmake

This file was deleted.

2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ add_custom_target(check
)

add_custom_target(check_cdash
COMMAND ctest -D Nightly $(JOBS) --output-on-failure
COMMAND ctest -D Nightly $(JOBS) --verbose --output-on-failure
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/../
)

Expand Down
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)
63 changes: 63 additions & 0 deletions tests/tests/peakrdl/regblock/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
include("../../../../SoCMakeConfig.cmake")
include("../../../utils/test_utils.cmake")

cmake_minimum_required(VERSION 3.25)
project(test NONE)

### A simple test with default arguments
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"
)
set_property(TEST ${IP}_peakrdl_regblock_makefile_validate PROPERTY LABELS peakrdl)

##### Test with mutliple arguments
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
)
set_property(TEST ${IP}_peakrdl_regblock_makefile_validate PROPERTY LABELS peakrdl)
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;

};
Loading

0 comments on commit 1c6ae51

Please sign in to comment.