1 /*
2  * Copyright (c) 2021 KT-Elektronik, Klaucke und Partner GmbH
3  * Copyright (c) 2024 Renesas Electronics Corporation
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Software interrupts utility code - Renesas rx architecture implementation.
10  *
11  * The code is using the first software interrupt (SWINT) of the RX processor
12  * should this interrupt ever be used for something else, this has to be
13  * changed - maybe to the second software interrupt (SWINT2).
14  */
15 
16 #include <zephyr/kernel.h>
17 #include <zephyr/irq_offload.h>
18 #include <zephyr/sys/util.h>
19 
20 #define SWINT1_IRQ_LINE 27
21 #define SWINT1_PRIO 14
22 /* Address of the software interrupt trigger register for SWINT1 */
23 #define SWINT_REGISTER_ADDRESS 0x872E0
24 #define SWINTR_SWINT *(uint8_t *)(SWINT_REGISTER_ADDRESS)
25 
26 static irq_offload_routine_t _offload_routine;
27 static const void *offload_param;
28 
z_irq_do_offload(void)29 void z_irq_do_offload(void)
30 {
31 	irq_offload_routine_t tmp;
32 
33 	if (!_offload_routine) {
34 		return;
35 	}
36 
37 	tmp = _offload_routine;
38 	_offload_routine = NULL;
39 
40 	tmp((const void *)offload_param);
41 }
42 
swi0_handler(void)43 static void swi0_handler(void)
44 {
45 	z_irq_do_offload();
46 }
47 
arch_irq_offload(irq_offload_routine_t routine,const void * parameter)48 void arch_irq_offload(irq_offload_routine_t routine, const void *parameter)
49 {
50 	_offload_routine = routine;
51 	offload_param = parameter;
52 
53 	SWINTR_SWINT = 1;
54 }
55 
arch_irq_offload_init(void)56 void arch_irq_offload_init(void)
57 {
58 	IRQ_CONNECT(SWINT1_IRQ_LINE, SWINT1_PRIO, swi0_handler, NULL, 0);
59 	irq_enable(SWINT1_IRQ_LINE);
60 }
61