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 #if defined(CONFIG_RISCV_HAS_CLIC) 20 #define IRQ_FLAGS 1 /* rising edge */ 21 #else 22 #define IRQ_FLAGS 0 23 #endif 24 25 #define ISR_DEFINE(name) \ 26 static inline void name(const void *data) \ 27 { \ 28 int idx = POINTER_TO_INT(data); \ 29 test_vector[idx] = result_vector[idx]; \ 30 } \ 31 32 static uint32_t test_vector[TEST_VECTOR_SIZE] = { 33 }; 34 35 static uint32_t result_vector[TEST_VECTOR_SIZE] = { 36 0xdeadbeef, 37 0xcafebabe, 38 0x1234cafe, 39 }; 40 41 ISR_DEFINE(test_isr_0); 42 ISR_DEFINE(test_isr_1); 43 ISR_DEFINE(test_isr_2); 44 client_exists_at_index(void (* routine)(const void * arg),void * arg,int irq,size_t idx)45static inline bool client_exists_at_index(void (*routine)(const void *arg), 46 void *arg, int irq, size_t idx) 47 { 48 size_t i; 49 const struct z_shared_isr_table_entry *shared_entry; 50 const struct _isr_table_entry *client; 51 52 shared_entry = &z_shared_sw_isr_table[irq]; 53 54 if (idx == TEST_INVALID_IDX) { 55 for (i = 0; i < shared_entry->client_num; i++) { 56 client = &shared_entry->clients[i]; 57 58 if (client->isr == routine && client->arg == arg) { 59 return true; 60 } 61 } 62 } else { 63 if (shared_entry->client_num <= idx) { 64 return false; 65 } 66 67 client = &shared_entry->clients[idx]; 68 69 return client->isr == routine && client->arg == arg; 70 } 71 72 return false; 73 } 74 75 #endif /* __TEST_SHARED_IRQ_H__ */ 76