1 /* 2 * Copyright (c) 2023 Nordic Semiconductor ASA 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef NSI_COMMON_SRC_NSI_TASKS_H 8 #define NSI_COMMON_SRC_NSI_TASKS_H 9 10 #include "nsi_utils.h" 11 12 #ifdef __cplusplus 13 extern "C" { 14 #endif 15 16 #define NSITASK_PRE_BOOT_1_LEVEL 0 17 #define NSITASK_PRE_BOOT_2_LEVEL 1 18 #define NSITASK_HW_INIT_LEVEL 2 19 #define NSITASK_PRE_BOOT_3_LEVEL 3 20 #define NSITASK_FIRST_SLEEP_LEVEL 4 21 #define NSITASK_ON_EXIT_PRE_LEVEL 5 22 #define NSITASK_ON_EXIT_POST_LEVEL 6 23 24 /** 25 * NSI_TASK 26 * 27 * Register a function to be called at particular moments 28 * during the Native Simulator execution. 29 * 30 * There is 5 choices for when the function will be called (level): 31 * * PRE_BOOT_1: Will be called before the command line parameters are parsed, 32 * or the HW models are initialized 33 * 34 * * PRE_BOOT_2: Will be called after the command line parameters are parsed, 35 * but before the HW models are initialized 36 * 37 * * HW_INIT: Will be called during HW models initialization 38 * 39 * * PRE_BOOT_3: Will be called after the HW models initialization, right before 40 * the "CPUs are booted" and embedded SW in them is started. 41 * 42 * * FIRST_SLEEP: Will be called after the 1st time all CPUs are sent to sleep 43 * 44 * * ON_EXIT_PRE: Will be called during termination of the runner 45 * execution, as a first set. 46 * 47 * * ON_EXIT_POST: Will be called during termination of the runner 48 * execution, as the very last set before the program returns. 49 * 50 * The function must take no parameters and return nothing. 51 */ 52 #define NSI_TASK(fn, level, prio) \ 53 static void (* const NSI_CONCAT(__nsi_task_, fn))(void) \ 54 __attribute__((__used__)) \ 55 __attribute__((__section__(".nsi_" #level NSI_STRINGIFY(prio) "_task")))\ 56 = fn; \ 57 /* Let's cross-check the macro level is a valid one, so we don't silently drop it */ \ 58 _Static_assert(NSITASK_##level##_LEVEL >= 0, \ 59 "Using a non pre-defined level, it will be dropped") 60 61 /** 62 * @brief Run the set of special native tasks corresponding to the given level 63 * 64 * @param level One of NSITASK_*_LEVEL as defined in soc.h 65 */ 66 void nsi_run_tasks(int level); 67 68 #ifdef __cplusplus 69 } 70 #endif 71 72 #endif /* NSI_COMMON_SRC_NSI_TASKS_H */ 73