CC13xx Driver Library
cpu.h
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: cpu.h
3 * Revised: 2016-01-06 15:55:48 +0100 (Wed, 06 Jan 2016)
4 * Revision: 45385
5 *
6 * Description: Defines and prototypes for the CPU instruction wrapper
7 * functions.
8 *
9 * Copyright (c) 2015, Texas Instruments Incorporated
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions are met:
14 *
15 * 1) Redistributions of source code must retain the above copyright notice,
16 * this list of conditions and the following disclaimer.
17 *
18 * 2) Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 *
22 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
23 * be used to endorse or promote products derived from this software without
24 * specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 *
38 ******************************************************************************/
39 
40 //*****************************************************************************
41 //
46 //
47 //*****************************************************************************
48 
49 #ifndef __CPU_H__
50 #define __CPU_H__
51 
52 //*****************************************************************************
53 //
54 // If building with a C++ compiler, make all of the definitions in this header
55 // have a C binding.
56 //
57 //*****************************************************************************
58 #ifdef __cplusplus
59 extern "C"
60 {
61 #endif
62 
63 #include <stdbool.h>
64 #include <stdint.h>
65 #include <inc/hw_types.h>
66 #include <inc/hw_memmap.h>
67 #include <inc/hw_cpu_scs.h>
68 
69 //*****************************************************************************
70 //
71 // Support for DriverLib in ROM:
72 // This section renames all functions that are not "static inline", so that
73 // calling these functions will default to implementation in flash. At the end
74 // of this file a second renaming will change the defaults to implementation in
75 // ROM for available functions.
76 //
77 // To force use of the implementation in flash, e.g. for debugging:
78 // - Globally: Define DRIVERLIB_NOROM at project level
79 // - Per function: Use prefix "NOROM_" when calling the function
80 //
81 //*****************************************************************************
82 #if !defined(DOXYGEN)
83  #define CPUcpsid NOROM_CPUcpsid
84  #define CPUprimask NOROM_CPUprimask
85  #define CPUcpsie NOROM_CPUcpsie
86  #define CPUbasepriGet NOROM_CPUbasepriGet
87  #define CPUdelay NOROM_CPUdelay
88 #endif
89 
90 //*****************************************************************************
91 //
92 // API Functions and prototypes
93 //
94 //*****************************************************************************
95 
96 //*****************************************************************************
97 //
104 //
105 //*****************************************************************************
106 extern uint32_t CPUcpsid(void);
107 
108 //*****************************************************************************
109 //
118 //
119 //*****************************************************************************
120 extern uint32_t CPUprimask(void);
121 
122 //*****************************************************************************
123 //
130 //
131 //*****************************************************************************
132 extern uint32_t CPUcpsie(void);
133 
134 //*****************************************************************************
135 //
142 //
143 //*****************************************************************************
144 #if defined(__IAR_SYSTEMS_ICC__)
145 __STATIC_INLINE void
146 CPUwfi(void)
147 {
148  //
149  // Wait for the next interrupt.
150  //
151  __asm(" wfi\n");
152 }
153 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
154 __asm __STATIC_INLINE void
155 CPUwfi(void)
156 {
157  //
158  // Wait for the next interrupt.
159  //
160  wfi;
161  bx lr
162 }
163 #elif defined(__TI_COMPILER_VERSION__) || defined(DOXYGEN)
164 __STATIC_INLINE void
165 CPUwfi(void)
166 {
167  //
168  // Wait for the next interrupt.
169  //
170  __asm(" wfi\n");
171 }
172 #else
173 __STATIC_INLINE void __attribute__((always_inline))
174 CPUwfi(void)
175 {
176  //
177  // Wait for the next interrupt.
178  //
179  __asm(" wfi\n");
180 }
181 #endif
182 
183 //*****************************************************************************
184 //
191 //
192 //*****************************************************************************
193 #if defined(__IAR_SYSTEMS_ICC__)
194 __STATIC_INLINE void
195 CPUwfe(void)
196 {
197  //
198  // Wait for the next event.
199  //
200  __asm(" wfe\n");
201 }
202 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
203 __asm __STATIC_INLINE void
204 CPUwfe(void)
205 {
206  //
207  // Wait for the next event.
208  //
209  wfe;
210  bx lr
211 }
212 #elif defined(__TI_COMPILER_VERSION__) || defined(DOXYGEN)
213 __STATIC_INLINE void
214 CPUwfe(void)
215 {
216  //
217  // Wait for the next event.
218  //
219  __asm(" wfe\n");
220 }
221 #else
222 __STATIC_INLINE void __attribute__((always_inline))
223 CPUwfe(void)
224 {
225  //
226  // Wait for the next event.
227  //
228  __asm(" wfe\n");
229 }
230 #endif
231 
232 //*****************************************************************************
233 //
240 //
241 //*****************************************************************************
242 #if defined(__IAR_SYSTEMS_ICC__)
243 __STATIC_INLINE void
244 CPUsev(void)
245 {
246  //
247  // Send event.
248  //
249  __asm(" sev\n");
250 }
251 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
252 __asm __STATIC_INLINE void
253 CPUsev(void)
254 {
255  //
256  // Send event.
257  //
258  sev;
259  bx lr
260 }
261 #elif defined(__TI_COMPILER_VERSION__) || defined(DOXYGEN)
262 __STATIC_INLINE void
263 CPUsev(void)
264 {
265  //
266  // Send event.
267  //
268  __asm(" sev\n");
269 }
270 #else
271 __STATIC_INLINE void __attribute__((always_inline))
272 CPUsev(void)
273 {
274  //
275  // Send event.
276  //
277  __asm(" sev\n");
278 }
279 #endif
280 
281 
282 //*****************************************************************************
283 //
292 //
293 //*****************************************************************************
294 #if defined(__IAR_SYSTEMS_ICC__)
295 __STATIC_INLINE void
296 CPUbasepriSet(uint32_t ui32NewBasepri)
297 {
298  //
299  // Set the BASEPRI register.
300  //
301  __asm(" msr BASEPRI, r0\n");
302 }
303 #elif defined(__CC_ARM) || defined(__ARMCC_VERSION)
304 __asm __STATIC_INLINE void
305 CPUbasepriSet(uint32_t ui32NewBasepri)
306 {
307  //
308  // Set the BASEPRI register.
309  //
310  msr BASEPRI, r0;
311  bx lr
312 }
313 #elif defined(__TI_COMPILER_VERSION__) || defined(DOXYGEN)
314 __STATIC_INLINE void
315 CPUbasepriSet(uint32_t ui32NewBasepri)
316 {
317  //
318  // Set the BASEPRI register.
319  //
320  __asm(" msr BASEPRI, r0\n");
321 }
322 #else
323 #pragma GCC diagnostic push
324 #pragma GCC diagnostic ignored "-Wattributes"
325 __STATIC_INLINE void __attribute__ ((naked))
326 CPUbasepriSet(uint32_t ui32NewBasepri)
327 {
328  //
329  // Set the BASEPRI register.
330  //
331  __asm(" msr BASEPRI, r0\n"
332  " bx lr\n");
333 }
334 #pragma GCC diagnostic pop
335 #endif
336 
337 //*****************************************************************************
338 //
345 //
346 //*****************************************************************************
347 extern uint32_t CPUbasepriGet(void);
348 
349 //*****************************************************************************
350 //
362 //
363 //*****************************************************************************
364 extern void CPUdelay(uint32_t ui32Count);
365 
366 //*****************************************************************************
367 //
380 //
381 //*****************************************************************************
382 __STATIC_INLINE void
384 {
386 }
387 
388 //*****************************************************************************
389 //
398 //
399 //*****************************************************************************
400 __STATIC_INLINE void
402 {
404 }
405 
406 //*****************************************************************************
407 //
408 // Support for DriverLib in ROM:
409 // Redirect to implementation in ROM when available.
410 //
411 //*****************************************************************************
412 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
413  #include <driverlib/rom.h>
414  #ifdef ROM_CPUcpsid
415  #undef CPUcpsid
416  #define CPUcpsid ROM_CPUcpsid
417  #endif
418  #ifdef ROM_CPUprimask
419  #undef CPUprimask
420  #define CPUprimask ROM_CPUprimask
421  #endif
422  #ifdef ROM_CPUcpsie
423  #undef CPUcpsie
424  #define CPUcpsie ROM_CPUcpsie
425  #endif
426  #ifdef ROM_CPUbasepriGet
427  #undef CPUbasepriGet
428  #define CPUbasepriGet ROM_CPUbasepriGet
429  #endif
430  #ifdef ROM_CPUdelay
431  #undef CPUdelay
432  #define CPUdelay ROM_CPUdelay
433  #endif
434 #endif
435 
436 //*****************************************************************************
437 //
438 // Mark the end of the C bindings section for C++ compilers.
439 //
440 //*****************************************************************************
441 #ifdef __cplusplus
442 }
443 #endif
444 
445 #endif // __CPU_H__
446 
447 //*****************************************************************************
448 //
452 //
453 //*****************************************************************************
static void CPU_WriteBufferDisable(void)
Disable CPU write buffering (recommended for debug purpose only).
Definition: cpu.h:383
uint32_t CPUprimask(void)
Get the current interrupt state.
Definition: cpu.c:173
static void CPUbasepriSet(uint32_t ui32NewBasepri)
Update the interrupt priority disable level.
Definition: cpu.h:315
static void CPU_WriteBufferEnable(void)
Enable CPU write buffering (default setting).
Definition: cpu.h:401
static void CPUwfi(void)
Wait for interrupt.
Definition: cpu.h:165
uint32_t CPUcpsid(void)
Disable all external interrupts.
Definition: cpu.c:97
__asm(" .sect \".text:NOROM_CPUdelay\"\n"" .clink\n"" .thumbfunc NOROM_CPUdelay\n"" .thumb\n"" .global NOROM_CPUdelay\n""NOROM_CPUdelay:\n"" subs r0, #1\n"" bne.n NOROM_CPUdelay\n"" bx lr\n")
Provide a small delay.
static void CPUwfe(void)
Wait for event.
Definition: cpu.h:214
uint32_t CPUcpsie(void)
Enable all external interrupts.
Definition: cpu.c:249
static void CPUsev(void)
Send event.
Definition: cpu.h:263
uint32_t CPUbasepriGet(void)
Get the interrupt priority disable level.
Definition: cpu.c:325
void CPUdelay(uint32_t ui32Count)
Provide a small delay.