SYS/BIOS  7.00
Hwi.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
35 #ifndef ti_sysbios_hal_Hwi__include
36 #define ti_sysbios_hal_Hwi__include
37 
38 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
39 #include <xdc/std.h>
40 
41 #include <stdbool.h>
42 #include <stddef.h>
43 #include <stdint.h>
44 
45 #ifdef __IAR_SYSTEMS_ICC__
46 #include <intrinsics.h>
47 #endif
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 #if (defined(__ARM_ARCH) && ((__ARM_ARCH == 6) && (__ARM_ARCH_PROFILE == 'M'))) || \
54  (defined(__CORE__) && (__CORE__ == __ARM6M__)) || \
55  defined(__ARM_ARCH_6M__)
56 #include <ti/sysbios/family/arm/v6m/Hwi.h>
57 #elif (defined(__ARM_ARCH) && ((__ARM_ARCH == 7) && (__ARM_ARCH_PROFILE == 'M'))) || \
58  (defined(__CORE__) && (__CORE__ == __ARM7M__)) || \
59  defined(__ARM_ARCH_7M__)
61 #elif (defined(__ARM_ARCH) && ((__ARM_ARCH == 8) && (__ARM_ARCH_PROFILE == 'M'))) || \
62  (defined(__CORE__) && (__CORE__ == __ARM8M__)) || \
63  defined(__ARM_ARCH_8M__)
64 #include <ti/sysbios/family/arm/v8m/Hwi.h>
65 #endif
66 
68 
69 /* Target unique Hwi_switchAndRunFunc */
70 extern void Hwi_switchAndRunFunc(void (*func)(void));
71 
72 extern const unsigned int Hwi_disablePriority;
73 
74 #if (defined(__ARM_ARCH) && ((__ARM_ARCH == 6) && (__ARM_ARCH_PROFILE == 'M'))) || \
75  (defined(__CORE__) && (__CORE__ == __ARM6M__)) || \
76  defined(__ARM_ARCH_6M__)
77 
78 #if defined(__TI_COMPILER_VERSION__) && !defined(__clang__)
79 
80 static inline unsigned int Hwi_disable()
81 {
82  return ((unsigned int)__set_PRIMASK(1));
83 }
84 
87 static inline unsigned int Hwi_enable()
88 {
89  return ((unsigned int)__set_PRIMASK(0));
90 }
91 
94 static inline void Hwi_restore(unsigned int key)
95 {
96  __set_PRIMASK(key);
97 }
98 
99 #elif defined(__IAR_SYSTEMS_ICC__)
100 
101 
102 static inline unsigned int Hwi_disable()
103 {
104  unsigned int key;
105 
106  key = __get_PRIMASK();
107  __set_PRIMASK(1);
108 
109  return (key);
110 }
111 
112 static inline unsigned int Hwi_enable()
113 {
114  unsigned int key;
115  key = __get_PRIMASK();
116  __set_PRIMASK(0);
117 
118  return (key);
119 }
120 
121 static inline void Hwi_restore(unsigned int key)
122 {
123  __set_PRIMASK(key);
124 }
125 
126 #else /* V6M and clang or GNU */
127 
128 static inline unsigned int Hwi_disable()
129 {
130  unsigned int key;
131 
132  __asm__ __volatile__ (
133  "mrs %0, primask\n\t"
134  "cpsid i"
135  : "=&r" (key)
136  :
137  : "memory"
138  );
139  return (key);
140 }
141 
142 static inline unsigned int Hwi_enable()
143 {
144  unsigned int key;
145 
146  __asm__ __volatile__ (
147  "mrs %0, primask\n\t"
148  "cpsid i"
149  : "=&r" (key)
150  :
151  : "memory"
152  );
153  return (key);
154 }
155 
156 static inline void Hwi_restore(unsigned int key)
157 {
158  __asm__ __volatile__ (
159  "msr primask, %0"
160  :
161  : "r" (key)
162  : "memory"
163  );
164 }
165 
166 #endif
167 
168 /* TODO -- replace with check for V7M */
169 #elif (1 /* V7M */)
170 
171 #if defined(__TI_COMPILER_VERSION__) && !defined(__clang__)
172 
173 static inline unsigned int Hwi_disable()
174 {
175  return (_set_interrupt_priority(Hwi_disablePriority));
176 }
177 
180 static inline unsigned int Hwi_enable()
181 {
182  return (_set_interrupt_priority(0));
183 }
184 
187 static inline void Hwi_restore(unsigned int key)
188 {
189  (void)_set_interrupt_priority(key);
190 }
191 
192 
193 #elif defined(__IAR_SYSTEMS_ICC__)
194 
195 static inline unsigned int Hwi_disable()
196 {
197  unsigned int key;
198 
199  key = __get_BASEPRI();
200  __set_BASEPRI(Hwi_disablePriority);
201 
202  return (key);
203 }
204 
207 static inline unsigned int Hwi_enable()
208 {
209  unsigned int key;
210  key = __get_BASEPRI();
211  __set_BASEPRI(0);
212 
213  return (key);
214 }
215 
218 static inline void Hwi_restore(unsigned int key)
219 {
220  __set_BASEPRI(key);
221 }
222 
223 #else /* clang or GNU */
224 
225 static inline unsigned int Hwi_disable()
226 {
227  unsigned int key;
228 
229  __asm__ __volatile__ (
230  "mrs %0, basepri\n\t"
231  "msr basepri, %1"
232  : "=&r" (key)
233  : "r" (Hwi_disablePriority)
234  : "memory"
235  );
236  return (key);
237 }
238 
241 static inline unsigned int Hwi_enable()
242 {
243  unsigned int key;
244 
245  __asm__ __volatile__ (
246  "movw r12, #0\n\t"
247  "mrs %0, basepri\n\t"
248  "msr basepri, r12"
249  : "=r" (key)
250  :
251  : "r12", "memory"
252  );
253  return (key);
254 }
255 
258 static inline void Hwi_restore(unsigned int key)
259 {
260  __asm__ __volatile__ (
261  "msr basepri, %0"
262  :
263  : "r" (key)
264  : "memory"
265  );
266 }
267 
268 #endif /* defined(__ti__) && !defined(__clang__) */
269 
270 #endif /* V7M */
271 
272 #ifdef __cplusplus
273 }
274 #endif
275 
276 #endif /* ti_sysbios_hal_Hwi__include */
277 
Basic constants and types.
Cortex M3/M4 Hardware Interrupt Manager.
const unsigned int Hwi_disablePriority
The priority that BASEPRI is set to by Hwi_disable().
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale