1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef NSI_COMMON_SRC_INCL_HWS_MODELS_IF_H
8 #define NSI_COMMON_SRC_INCL_HWS_MODELS_IF_H
9 
10 #include <stdint.h>
11 #include "nsi_utils.h"
12 #include "nsi_hw_scheduler.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /* Internal structure used to link HW events */
19 struct nsi_hw_event_st {
20 	void (*const callback)(void);
21 	uint64_t *timer;
22 };
23 
24 /**
25  * Register an event timer and event callback
26  *
27  * The HW scheduler will keep track of this event, and call its callback whenever its
28  * timer is reached.
29  * The ordering of events in the same microsecond is given by prio (lowest first).
30  * (Normally HW models will not care about the event ordering, and will simply set a prio like 100)
31  *
32  * Only very particular models will need to execute before or after others.
33  *
34  * Priority can be a number between 0 and 999.
35  */
36 #define NSI_HW_EVENT(t, fn, prio)					\
37 	static const struct nsi_hw_event_st NSI_CONCAT(NSI_CONCAT(__nsi_hw_event_, fn), t) \
38 		__attribute__((__used__))						\
39 		__attribute__((__section__(".nsi_hw_event_" NSI_STRINGIFY(prio))))	\
40 		= {			\
41 			.callback = fn,	\
42 			.timer = &t,	\
43 		}
44 
45 #ifdef __cplusplus
46 }
47 #endif
48 
49 #endif /* NSI_COMMON_SRC_INCL_HWS_MODELS_IF_H */
50