gen_defines: output the interrupt level of a node

Currently it is tedious to know the level of an interrupt for
a node in C. One would have to go through a very complex and
error prone macros to check if there's a parent interrupt
controller & if the controller has an interrupt number and thus
not a pseudo interrupt controller like the one found in
`rv32m1`. The level of a node is required to encode the
Zephyr's multi-level interrupt number

Since it is easier to do it in the `gen_defines` script, let's
do the heavy lifting there so that we can introduce new DT
macros to get the interrupt level very easily later.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
Yong Cong Sin 2023-12-22 16:20:10 +08:00 committed by Chris Friedt
parent 89fb8f8b98
commit 450a66fa36
2 changed files with 11 additions and 0 deletions

View file

@ -37,6 +37,7 @@ node-macro =/ %s"DT_N" path-id %s"_REG_NAME_" dt-name
%s"_VAL_" ( %s"ADDRESS" / %s"SIZE")
; The interrupts property is also special.
node-macro =/ %s"DT_N" path-id %s"_IRQ_NUM"
node-macro =/ %s"DT_N" path-id %s"_IRQ_LEVEL"
node-macro =/ %s"DT_N" path-id %s"_IRQ_IDX_" DIGIT "_EXISTS"
node-macro =/ %s"DT_N" path-id %s"_IRQ_IDX_" DIGIT
%s"_VAL_" dt-name [ %s"_EXISTS" ]

View file

@ -484,6 +484,16 @@ def write_interrupts(node):
name_controller_macro = f"{path_id}_IRQ_NAME_{str2ident(irq.name)}_CONTROLLER"
name_vals.append((name_controller_macro, f"DT_{idx_controller_macro}"))
# Interrupt controller info
irqs = []
while node.interrupts is not None and len(node.interrupts) > 0:
irq = node.interrupts[0]
irqs.append(irq)
if node == irq.controller:
break
node = irq.controller
idx_vals.append((f"{path_id}_IRQ_LEVEL", len(irqs)))
for macro, val in idx_vals:
out_dt_define(macro, val)
for macro, val in name_vals: