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 
41 #ifndef ti_sysbios_hal_Hwi__include
42 #define ti_sysbios_hal_Hwi__include
43 
44 /* BIOS 6.x compatibility, use -Dxdc_std__include to disable */
45 #include <xdc/std.h>
46 
47 #include <stdbool.h>
48 #include <stddef.h>
49 #include <stdint.h>
50 
51 #ifdef __IAR_SYSTEMS_ICC__
52 #include <intrinsics.h>
53 #endif
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 #if (defined(__ARM_ARCH) && ((__ARM_ARCH == 6) && (__ARM_ARCH_PROFILE == 'M'))) || \
60  (defined(__CORE__) && (__CORE__ == __ARM6M__)) || \
61  defined(__ARM_ARCH_6M__)
62 #include <ti/sysbios/family/arm/v6m/Hwi.h>
63 #elif (defined(__ARM_ARCH) && ((__ARM_ARCH == 7) && (__ARM_ARCH_PROFILE == 'M'))) || \
64  (defined(__CORE__) && (__CORE__ == __ARM7M__)) || \
65  defined(__ARM_ARCH_7M__)
67 #elif (defined(__ARM_ARCH) && ((__ARM_ARCH == 8) && (__ARM_ARCH_PROFILE == 'M'))) || \
68  (defined(__CORE__) && (__CORE__ == __ARM8M__)) || \
69  defined(__ARM_ARCH_8M__)
70 #include <ti/sysbios/family/arm/v8m/Hwi.h>
71 #endif
72 
74 
75 /* Target unique Hwi_switchAndRunFunc */
76 extern void Hwi_switchAndRunFunc(void (*func)(void));
77 
78 extern const unsigned int Hwi_disablePriority;
79 
80 #if (defined(__ARM_ARCH) && ((__ARM_ARCH == 6) && (__ARM_ARCH_PROFILE == 'M'))) || \
81  (defined(__CORE__) && (__CORE__ == __ARM6M__)) || \
82  defined(__ARM_ARCH_6M__)
83 
84 #if defined(__TI_COMPILER_VERSION__) && !defined(__clang__)
85 
86 /* \static Disable Hardware Interrupts
87  */
88 static inline unsigned int Hwi_disable()
89 {
90  return ((unsigned int)__set_PRIMASK(1));
91 }
92 
93 /* \static Enable Hardware Interrupts
94  */
95 static inline unsigned int Hwi_enable()
96 {
97  return ((unsigned int)__set_PRIMASK(0));
98 }
99 
100 /* \static Restore Hardware Interrupts to previous setting
101  */
102 static inline void Hwi_restore(unsigned int key)
103 {
104  __set_PRIMASK(key);
105 }
106 
107 #elif defined(__IAR_SYSTEMS_ICC__)
108 
109 
110 static inline unsigned int Hwi_disable()
111 {
112  unsigned int key;
113 
114  key = __get_PRIMASK();
115  __set_PRIMASK(1);
116 
117  return (key);
118 }
119 
120 static inline unsigned int Hwi_enable()
121 {
122  unsigned int key;
123  key = __get_PRIMASK();
124  __set_PRIMASK(0);
125 
126  return (key);
127 }
128 
129 static inline void Hwi_restore(unsigned int key)
130 {
131  __set_PRIMASK(key);
132 }
133 
134 #else /* V6M and clang or GNU */
135 
136 static inline unsigned int Hwi_disable()
137 {
138  unsigned int key;
139 
140  __asm__ __volatile__ (
141  "mrs %0, primask\n\t"
142  "cpsid i"
143  : "=&r" (key)
144  :
145  : "memory"
146  );
147  return (key);
148 }
149 
150 static inline unsigned int Hwi_enable()
151 {
152  unsigned int key;
153 
154  __asm__ __volatile__ (
155  "mrs %0, primask\n\t"
156  "cpsid i"
157  : "=&r" (key)
158  :
159  : "memory"
160  );
161  return (key);
162 }
163 
164 static inline void Hwi_restore(unsigned int key)
165 {
166  __asm__ __volatile__ (
167  "msr primask, %0"
168  :
169  : "r" (key)
170  : "memory"
171  );
172 }
173 
174 #endif
175 
176 /* TODO -- replace with check for V7M */
177 #elif (1 /* V7M */)
178 
179 #if defined(__TI_COMPILER_VERSION__) && !defined(__clang__)
180 
181 static inline unsigned int Hwi_disable()
182 {
183  return (_set_interrupt_priority(Hwi_disablePriority));
184 }
185 
188 static inline unsigned int Hwi_enable()
189 {
190  return (_set_interrupt_priority(0));
191 }
192 
195 static inline void Hwi_restore(unsigned int key)
196 {
197  (void)_set_interrupt_priority(key);
198 }
199 
200 
201 #elif defined(__IAR_SYSTEMS_ICC__)
202 
203 static inline unsigned int Hwi_disable()
204 {
205  unsigned int key;
206 
207  key = __get_BASEPRI();
208  __set_BASEPRI(Hwi_disablePriority);
209 
210  return (key);
211 }
212 
215 static inline unsigned int Hwi_enable()
216 {
217  unsigned int key;
218  key = __get_BASEPRI();
219  __set_BASEPRI(0);
220 
221  return (key);
222 }
223 
226 static inline void Hwi_restore(unsigned int key)
227 {
228  __set_BASEPRI(key);
229 }
230 
231 #else /* clang or GNU */
232 
233 static inline unsigned int Hwi_disable()
234 {
235  unsigned int key;
236 
237  __asm__ __volatile__ (
238  "mrs %0, basepri\n\t"
239  "msr basepri, %1"
240  : "=&r" (key)
241  : "r" (Hwi_disablePriority)
242  : "memory"
243  );
244  return (key);
245 }
246 
249 static inline unsigned int Hwi_enable()
250 {
251  unsigned int key;
252 
253  __asm__ __volatile__ (
254  "movw r12, #0\n\t"
255  "mrs %0, basepri\n\t"
256  "msr basepri, r12"
257  : "=r" (key)
258  :
259  : "r12", "memory"
260  );
261  return (key);
262 }
263 
266 static inline void Hwi_restore(unsigned int key)
267 {
268  __asm__ __volatile__ (
269  "msr basepri, %0"
270  :
271  : "r" (key)
272  : "memory"
273  );
274 }
275 
276 #endif /* defined(__ti__) && !defined(__clang__) */
277 
278 #endif /* V7M */
279 
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 #endif /* ti_sysbios_hal_Hwi__include */
285 
Basic constants and types.
static unsigned int Hwi_enable()
Definition: Hwi.h:249
void Hwi_switchAndRunFunc(void(*func)(void))
Cortex M3/M4 Hardware Interrupt Manager.
static unsigned int Hwi_disable()
Definition: Hwi.h:233
static void Hwi_restore(unsigned int key)
Definition: Hwi.h:266
const unsigned int Hwi_disablePriority
The priority that BASEPRI is set to by Hwi_disable().
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale