1 /*
2  * Copyright (C) 2015-2017 Alibaba Group Holding Limited
3  */
4 
5 #ifndef K_CRITICAL_H
6 #define K_CRITICAL_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /** @addtogroup aos_rhino critical
13  *  Critical zone protection, os use internally.
14  *
15  *  @{
16  */
17 
18 #if (RHINO_CONFIG_SYS_STATS > 0)
19 /* For measure max int disable count */
20 #define RHINO_INTDIS_MEAS_START() intrpt_disable_measure_start()
21 #define RHINO_INTDIS_MEAS_STOP()  intrpt_disable_measure_stop()
22 #else
23 #define RHINO_INTDIS_MEAS_START()
24 #define RHINO_INTDIS_MEAS_STOP()
25 #endif
26 
27 /**
28  * Critical zone begin.
29  *
30  * @return none
31  */
32 #define RHINO_CRITICAL_ENTER()      \
33     do {                            \
34         RHINO_CPU_INTRPT_DISABLE(); \
35         RHINO_INTDIS_MEAS_START();  \
36     } while (0)
37 
38 /**
39  * Critical zone end.
40  *
41  * @return none
42  */
43 #define RHINO_CRITICAL_EXIT()       \
44     do {                            \
45         RHINO_INTDIS_MEAS_STOP();   \
46         RHINO_CPU_INTRPT_ENABLE();  \
47     } while (0)
48 
49 /**
50  * Critical zone end and trigger scheduling.
51  *
52  * @return none
53  */
54 #if (RHINO_CONFIG_CPU_NUM > 1)
55 #define RHINO_CRITICAL_EXIT_SCHED() \
56     do {                            \
57         RHINO_INTDIS_MEAS_STOP();   \
58         core_sched();               \
59         cpu_intrpt_restore(cpsr);   \
60     } while (0)
61 #else
62 #define RHINO_CRITICAL_EXIT_SCHED() \
63     do {                            \
64         RHINO_INTDIS_MEAS_STOP();   \
65         core_sched();               \
66         RHINO_CPU_INTRPT_ENABLE();  \
67     } while (0)
68 #endif
69 
70 /** @} */
71 
72 #ifdef __cplusplus
73 }
74 #endif
75 
76 #endif /* K_CRITICAL_H */
77 
78