cmake: extensions: add NAME parameter to DT register helpers
Allow register address and size access by name. Example devicetree fragment: / { foo@deadbeef { reg = <0xdeadbeef 0x1000>, <0xfeedface 0x2000>; reg-names = "bar", "baz"; }; }; Example usage: dt_reg_addr(bar_addr PATH "/foo@deadbeef" NAME bar) dt_reg_size(bar_size PATH "/foo@deadbeef" NAME bar) dt_reg_addr(baz_addr PATH "/foo@deadbeef" NAME baz) dt_reg_size(baz_size PATH "/foo@deadbeef" NAME baz) Results: - bar_addr is 0xdeadbeef - bar_size is 0x1000 - baz_addr is 0xfeedface - baz_size is 0x2000 Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
parent
843ea97eac
commit
77a403cf6e
1 changed files with 44 additions and 13 deletions
|
@ -2859,10 +2859,11 @@ function(dt_num_regs var)
|
|||
endfunction()
|
||||
|
||||
# Usage:
|
||||
# dt_reg_addr(<var> PATH <path> [INDEX <idx>])
|
||||
# dt_reg_addr(<var> PATH <path> [INDEX <idx>] [NAME <name>])
|
||||
#
|
||||
# Get the base address of the register block at index <idx>.
|
||||
# If <idx> is omitted, then the value at index 0 will be returned.
|
||||
# Get the base address of the register block at index <idx>, or with
|
||||
# name <name>. If <idx> and <name> are both omitted, the value at
|
||||
# index 0 will be returned. Do not give both <idx> and <name>.
|
||||
#
|
||||
# The value will be returned in the <var> parameter.
|
||||
#
|
||||
|
@ -2875,14 +2876,15 @@ endfunction()
|
|||
# Results can be:
|
||||
# - The base address of the register block
|
||||
# - <var> will be undefined if node does not exists or does not have a register
|
||||
# block at the requested index.
|
||||
# block at the requested index or with the requested name
|
||||
#
|
||||
# <var> : Return variable where the address value will be stored
|
||||
# PATH <path> : Node path
|
||||
# INDEX <idx> : Index number
|
||||
# INDEX <idx> : Register block index number
|
||||
# NAME <name> : Register block name
|
||||
function(dt_reg_addr var)
|
||||
set(req_single_args "PATH")
|
||||
set(single_args "INDEX")
|
||||
set(single_args "INDEX;NAME")
|
||||
cmake_parse_arguments(DT_REG "" "${req_single_args};${single_args}" "" ${ARGN})
|
||||
|
||||
if(${ARGV0} IN_LIST req_single_args)
|
||||
|
@ -2897,8 +2899,16 @@ function(dt_reg_addr var)
|
|||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT DEFINED DT_REG_INDEX)
|
||||
if(DEFINED DT_REG_INDEX AND DEFINED DT_REG_NAME)
|
||||
message(FATAL_ERROR "dt_reg_addr(${ARGV0} ...) given both INDEX and NAME")
|
||||
elseif(NOT DEFINED DT_REG_INDEX AND NOT DEFINED DT_REG_NAME)
|
||||
set(DT_REG_INDEX 0)
|
||||
elseif(DEFINED DT_REG_NAME)
|
||||
dt_reg_index_private(DT_REG_INDEX "${DT_REG_PATH}" "${DT_REG_NAME}")
|
||||
if(DT_REG_INDEX EQUAL "-1")
|
||||
set(${var} PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
dt_path_internal(canonical "${DT_REG_PATH}")
|
||||
|
@ -2914,10 +2924,11 @@ function(dt_reg_addr var)
|
|||
endfunction()
|
||||
|
||||
# Usage:
|
||||
# dt_reg_size(<var> PATH <path> [INDEX <idx>])
|
||||
# dt_reg_size(<var> PATH <path> [INDEX <idx>] [NAME <name>])
|
||||
#
|
||||
# Get the size of the register block at index <idx>.
|
||||
# If INDEX is omitted, then the value at index 0 will be returned.
|
||||
# Get the size of the register block at index <idx>, or with
|
||||
# name <name>. If <idx> and <name> are both omitted, the value at
|
||||
# index 0 will be returned. Do not give both <idx> and <name>.
|
||||
#
|
||||
# The value will be returned in the <value> parameter.
|
||||
#
|
||||
|
@ -2929,10 +2940,11 @@ endfunction()
|
|||
#
|
||||
# <var> : Return variable where the size value will be stored
|
||||
# PATH <path> : Node path
|
||||
# INDEX <idx> : Index number
|
||||
# INDEX <idx> : Register block index number
|
||||
# NAME <name> : Register block name
|
||||
function(dt_reg_size var)
|
||||
set(req_single_args "PATH")
|
||||
set(single_args "INDEX")
|
||||
set(single_args "INDEX;NAME")
|
||||
cmake_parse_arguments(DT_REG "" "${req_single_args};${single_args}" "" ${ARGN})
|
||||
|
||||
if(${ARGV0} IN_LIST req_single_args)
|
||||
|
@ -2947,8 +2959,16 @@ function(dt_reg_size var)
|
|||
endif()
|
||||
endforeach()
|
||||
|
||||
if(NOT DEFINED DT_REG_INDEX)
|
||||
if(DEFINED DT_REG_INDEX AND DEFINED DT_REG_NAME)
|
||||
message(FATAL_ERROR "dt_reg_size(${ARGV0} ...) given both INDEX and NAME")
|
||||
elseif(NOT DEFINED DT_REG_INDEX AND NOT DEFINED DT_REG_NAME)
|
||||
set(DT_REG_INDEX 0)
|
||||
elseif(DEFINED DT_REG_NAME)
|
||||
dt_reg_index_private(DT_REG_INDEX "${DT_REG_PATH}" "${DT_REG_NAME}")
|
||||
if(DT_REG_INDEX EQUAL "-1")
|
||||
set(${var} PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
dt_path_internal(canonical "${DT_REG_PATH}")
|
||||
|
@ -2963,6 +2983,17 @@ function(dt_reg_size var)
|
|||
set(${var} ${${var}} PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Internal helper for dt_reg_addr/dt_reg_size; not meant to be used directly
|
||||
function(dt_reg_index_private var path name)
|
||||
dt_prop(reg_names PATH "${path}" PROPERTY "reg-names")
|
||||
if(NOT DEFINED reg_names)
|
||||
set(index "-1")
|
||||
else()
|
||||
list(FIND reg_names "${name}" index)
|
||||
endif()
|
||||
set(${var} "${index}" PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
# Usage:
|
||||
# dt_has_chosen(<var> PROPERTY <prop>)
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue