1 /*
2  * Copyright 2023 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef __TEST_SHARED_IRQ_H__
8 #define __TEST_SHARED_IRQ_H__
9 
10 #include <zephyr/ztest.h>
11 #include <zephyr/interrupt_util.h>
12 
13 #define IRQ_PRIORITY 1
14 #define TEST_VECTOR_SIZE 10
15 #define TEST_INVALID_IDX 0xcafebabe
16 #define TEST_DUMMY_ISR_VAL 0xdeadbeef
17 #define TEST_INVALID_IRQ 0xcafebabe
18 
19 #define ISR_DEFINE(name)				\
20 static inline void name(const void *data)		\
21 {							\
22 	int idx = POINTER_TO_INT(data);			\
23 	test_vector[idx] = result_vector[idx];		\
24 }							\
25 
26 static uint32_t test_vector[TEST_VECTOR_SIZE] = {
27 };
28 
29 static uint32_t result_vector[TEST_VECTOR_SIZE] = {
30 	0xdeadbeef,
31 	0xcafebabe,
32 	0x1234cafe,
33 };
34 
35 ISR_DEFINE(test_isr_0);
36 ISR_DEFINE(test_isr_1);
37 ISR_DEFINE(test_isr_2);
38 
client_exists_at_index(void (* routine)(const void * arg),void * arg,int irq,size_t idx)39 static inline bool client_exists_at_index(void (*routine)(const void *arg),
40 					  void *arg, int irq, size_t idx)
41 {
42 	size_t i;
43 	struct z_shared_isr_table_entry *shared_entry;
44 	struct _isr_table_entry *client;
45 
46 	shared_entry = &z_shared_sw_isr_table[irq];
47 
48 	if (idx == TEST_INVALID_IDX) {
49 		for (i = 0; i < shared_entry->client_num; i++) {
50 			client = &shared_entry->clients[i];
51 
52 			if (client->isr == routine && client->arg == arg) {
53 				return true;
54 			}
55 		}
56 	} else {
57 		if (shared_entry->client_num <= idx) {
58 			return false;
59 		}
60 
61 		client = &shared_entry->clients[idx];
62 
63 		return client->isr == routine && client->arg == arg;
64 	}
65 
66 	return false;
67 }
68 
69 #endif /* __TEST_SHARED_IRQ_H__ */
70