]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M7_SAMV71_Xplained/libchip_samv7/include/cmsis/CMSIS/Include/core_cmInstr.h
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / CORTEX_M7_SAMV71_Xplained / libchip_samv7 / include / cmsis / CMSIS / Include / core_cmInstr.h
1 /**************************************************************************//**\r
2  * @file     core_cmInstr.h\r
3  * @brief    CMSIS Cortex-M Core Instruction Access Header File\r
4  * @version  V3.01\r
5  * @date     06. March 2013\r
6  *\r
7  * @note\r
8  * Copyright (C) 2009-2014 ARM Limited. All rights reserved.\r
9  *\r
10  * @par\r
11  * ARM Limited (ARM) is supplying this software for use with Cortex-M\r
12  * processor based microcontrollers.  This file can be freely distributed\r
13  * within development tools that are supporting such ARM based processors.\r
14  *\r
15  * @par\r
16  * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED\r
17  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF\r
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.\r
19  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR\r
20  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.\r
21  *\r
22  ******************************************************************************/\r
23 \r
24 #ifndef __CORE_CMINSTR_H\r
25 #define __CORE_CMINSTR_H\r
26 \r
27 \r
28 /* ##########################  Core Instruction Access  ######################### */\r
29 /** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface\r
30   Access to dedicated instructions\r
31   @{\r
32 */\r
33 \r
34 #if   defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/\r
35 /* ARM armcc specific functions */\r
36 \r
37 #if (__ARMCC_VERSION < 400677)\r
38   #error "Please use ARM Compiler Toolchain V4.0.677 or later!"\r
39 #endif\r
40 \r
41 \r
42 /** \brief  No Operation\r
43 \r
44     No Operation does nothing. This instruction can be used for code alignment purposes.\r
45  */\r
46 #define __NOP                             __nop\r
47 \r
48 \r
49 /** \brief  Wait For Interrupt\r
50 \r
51     Wait For Interrupt is a hint instruction that suspends execution\r
52     until one of a number of events occurs.\r
53  */\r
54 #define __WFI                             __wfi\r
55 \r
56 \r
57 /** \brief  Wait For Event\r
58 \r
59     Wait For Event is a hint instruction that permits the processor to enter\r
60     a low-power state until one of a number of events occurs.\r
61  */\r
62 #define __WFE                             __wfe\r
63 \r
64 \r
65 /** \brief  Send Event\r
66 \r
67     Send Event is a hint instruction. It causes an event to be signaled to the CPU.\r
68  */\r
69 #define __SEV                             __sev\r
70 \r
71 \r
72 /** \brief  Instruction Synchronization Barrier\r
73 \r
74     Instruction Synchronization Barrier flushes the pipeline in the processor,\r
75     so that all instructions following the ISB are fetched from cache or\r
76     memory, after the instruction has been completed.\r
77  */\r
78 #define __ISB()                           __isb(0xF)\r
79 \r
80 \r
81 /** \brief  Data Synchronization Barrier\r
82 \r
83     This function acts as a special kind of Data Memory Barrier.\r
84     It completes when all explicit memory accesses before this instruction complete.\r
85  */\r
86 #define __DSB()                           __dsb(0xF)\r
87 \r
88 \r
89 /** \brief  Data Memory Barrier\r
90 \r
91     This function ensures the apparent order of the explicit memory operations before\r
92     and after the instruction, without ensuring their completion.\r
93  */\r
94 #define __DMB()                           __dmb(0xF)\r
95 \r
96 \r
97 /** \brief  Reverse byte order (32 bit)\r
98 \r
99     This function reverses the byte order in integer value.\r
100 \r
101     \param [in]    value  Value to reverse\r
102     \return               Reversed value\r
103  */\r
104 #define __REV                             __rev\r
105 \r
106 \r
107 /** \brief  Reverse byte order (16 bit)\r
108 \r
109     This function reverses the byte order in two unsigned short values.\r
110 \r
111     \param [in]    value  Value to reverse\r
112     \return               Reversed value\r
113  */\r
114 __attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value)\r
115 {\r
116   rev16 r0, r0\r
117   bx lr\r
118 }\r
119 \r
120 \r
121 /** \brief  Reverse byte order in signed short value\r
122 \r
123     This function reverses the byte order in a signed short value with sign extension to integer.\r
124 \r
125     \param [in]    value  Value to reverse\r
126     \return               Reversed value\r
127  */\r
128 __attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value)\r
129 {\r
130   revsh r0, r0\r
131   bx lr\r
132 }\r
133 \r
134 \r
135 /** \brief  Rotate Right in unsigned value (32 bit)\r
136 \r
137     This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.\r
138 \r
139     \param [in]    value  Value to rotate\r
140     \param [in]    value  Number of Bits to rotate\r
141     \return               Rotated value\r
142  */\r
143 #define __ROR                             __ror\r
144 \r
145 \r
146 #if       (__CORTEX_M >= 0x03)\r
147 \r
148 /** \brief  Reverse bit order of value\r
149 \r
150     This function reverses the bit order of the given value.\r
151 \r
152     \param [in]    value  Value to reverse\r
153     \return               Reversed value\r
154  */\r
155 #define __RBIT                            __rbit\r
156 \r
157 \r
158 /** \brief  LDR Exclusive (8 bit)\r
159 \r
160     This function performs a exclusive LDR command for 8 bit value.\r
161 \r
162     \param [in]    ptr  Pointer to data\r
163     \return             value of type uint8_t at (*ptr)\r
164  */\r
165 #define __LDREXB(ptr)                     ((uint8_t ) __ldrex(ptr))\r
166 \r
167 \r
168 /** \brief  LDR Exclusive (16 bit)\r
169 \r
170     This function performs a exclusive LDR command for 16 bit values.\r
171 \r
172     \param [in]    ptr  Pointer to data\r
173     \return        value of type uint16_t at (*ptr)\r
174  */\r
175 #define __LDREXH(ptr)                     ((uint16_t) __ldrex(ptr))\r
176 \r
177 \r
178 /** \brief  LDR Exclusive (32 bit)\r
179 \r
180     This function performs a exclusive LDR command for 32 bit values.\r
181 \r
182     \param [in]    ptr  Pointer to data\r
183     \return        value of type uint32_t at (*ptr)\r
184  */\r
185 #define __LDREXW(ptr)                     ((uint32_t ) __ldrex(ptr))\r
186 \r
187 \r
188 /** \brief  STR Exclusive (8 bit)\r
189 \r
190     This function performs a exclusive STR command for 8 bit values.\r
191 \r
192     \param [in]  value  Value to store\r
193     \param [in]    ptr  Pointer to location\r
194     \return          0  Function succeeded\r
195     \return          1  Function failed\r
196  */\r
197 #define __STREXB(value, ptr)              __strex(value, ptr)\r
198 \r
199 \r
200 /** \brief  STR Exclusive (16 bit)\r
201 \r
202     This function performs a exclusive STR command for 16 bit values.\r
203 \r
204     \param [in]  value  Value to store\r
205     \param [in]    ptr  Pointer to location\r
206     \return          0  Function succeeded\r
207     \return          1  Function failed\r
208  */\r
209 #define __STREXH(value, ptr)              __strex(value, ptr)\r
210 \r
211 \r
212 /** \brief  STR Exclusive (32 bit)\r
213 \r
214     This function performs a exclusive STR command for 32 bit values.\r
215 \r
216     \param [in]  value  Value to store\r
217     \param [in]    ptr  Pointer to location\r
218     \return          0  Function succeeded\r
219     \return          1  Function failed\r
220  */\r
221 #define __STREXW(value, ptr)              __strex(value, ptr)\r
222 \r
223 \r
224 /** \brief  Remove the exclusive lock\r
225 \r
226     This function removes the exclusive lock which is created by LDREX.\r
227 \r
228  */\r
229 #define __CLREX                           __clrex\r
230 \r
231 \r
232 /** \brief  Signed Saturate\r
233 \r
234     This function saturates a signed value.\r
235 \r
236     \param [in]  value  Value to be saturated\r
237     \param [in]    sat  Bit position to saturate to (1..32)\r
238     \return             Saturated value\r
239  */\r
240 #define __SSAT                            __ssat\r
241 \r
242 \r
243 /** \brief  Unsigned Saturate\r
244 \r
245     This function saturates an unsigned value.\r
246 \r
247     \param [in]  value  Value to be saturated\r
248     \param [in]    sat  Bit position to saturate to (0..31)\r
249     \return             Saturated value\r
250  */\r
251 #define __USAT                            __usat\r
252 \r
253 \r
254 /** \brief  Count leading zeros\r
255 \r
256     This function counts the number of leading zeros of a data value.\r
257 \r
258     \param [in]  value  Value to count the leading zeros\r
259     \return             number of leading zeros in value\r
260  */\r
261 #define __CLZ                             __clz\r
262 \r
263 #endif /* (__CORTEX_M >= 0x03) */\r
264 \r
265 \r
266 \r
267 #elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/\r
268 /* IAR iccarm specific functions */\r
269 \r
270 #include <cmsis_iar.h>\r
271 \r
272 \r
273 #elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/\r
274 /* TI CCS specific functions */\r
275 \r
276 #include <cmsis_ccs.h>\r
277 \r
278 \r
279 #elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/\r
280 /* GNU gcc specific functions */\r
281 \r
282 /** \brief  No Operation\r
283 \r
284     No Operation does nothing. This instruction can be used for code alignment purposes.\r
285  */\r
286 __attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void)\r
287 {\r
288   __ASM volatile ("nop");\r
289 }\r
290 \r
291 \r
292 /** \brief  Wait For Interrupt\r
293 \r
294     Wait For Interrupt is a hint instruction that suspends execution\r
295     until one of a number of events occurs.\r
296  */\r
297 __attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void)\r
298 {\r
299   __ASM volatile ("wfi");\r
300 }\r
301 \r
302 \r
303 /** \brief  Wait For Event\r
304 \r
305     Wait For Event is a hint instruction that permits the processor to enter\r
306     a low-power state until one of a number of events occurs.\r
307  */\r
308 __attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void)\r
309 {\r
310   __ASM volatile ("wfe");\r
311 }\r
312 \r
313 \r
314 /** \brief  Send Event\r
315 \r
316     Send Event is a hint instruction. It causes an event to be signaled to the CPU.\r
317  */\r
318 __attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void)\r
319 {\r
320   __ASM volatile ("sev");\r
321 }\r
322 \r
323 \r
324 /** \brief  Instruction Synchronization Barrier\r
325 \r
326     Instruction Synchronization Barrier flushes the pipeline in the processor,\r
327     so that all instructions following the ISB are fetched from cache or\r
328     memory, after the instruction has been completed.\r
329  */\r
330 __attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void)\r
331 {\r
332   __ASM volatile ("isb");\r
333 }\r
334 \r
335 \r
336 /** \brief  Data Synchronization Barrier\r
337 \r
338     This function acts as a special kind of Data Memory Barrier.\r
339     It completes when all explicit memory accesses before this instruction complete.\r
340  */\r
341 __attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void)\r
342 {\r
343   __ASM volatile ("dsb");\r
344 }\r
345 \r
346 \r
347 /** \brief  Data Memory Barrier\r
348 \r
349     This function ensures the apparent order of the explicit memory operations before\r
350     and after the instruction, without ensuring their completion.\r
351  */\r
352 __attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void)\r
353 {\r
354   __ASM volatile ("dmb");\r
355 }\r
356 \r
357 \r
358 /** \brief  Reverse byte order (32 bit)\r
359 \r
360     This function reverses the byte order in integer value.\r
361 \r
362     \param [in]    value  Value to reverse\r
363     \return               Reversed value\r
364  */\r
365 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value)\r
366 {\r
367   uint32_t result;\r
368 \r
369   __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );\r
370   return(result);\r
371 }\r
372 \r
373 \r
374 /** \brief  Reverse byte order (16 bit)\r
375 \r
376     This function reverses the byte order in two unsigned short values.\r
377 \r
378     \param [in]    value  Value to reverse\r
379     \return               Reversed value\r
380  */\r
381 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value)\r
382 {\r
383   uint32_t result;\r
384 \r
385   __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );\r
386   return(result);\r
387 }\r
388 \r
389 \r
390 /** \brief  Reverse byte order in signed short value\r
391 \r
392     This function reverses the byte order in a signed short value with sign extension to integer.\r
393 \r
394     \param [in]    value  Value to reverse\r
395     \return               Reversed value\r
396  */\r
397 __attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value)\r
398 {\r
399   uint32_t result;\r
400 \r
401   __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );\r
402   return(result);\r
403 }\r
404 \r
405 \r
406 /** \brief  Rotate Right in unsigned value (32 bit)\r
407 \r
408     This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits.\r
409 \r
410     \param [in]    value  Value to rotate\r
411     \param [in]    value  Number of Bits to rotate\r
412     \return               Rotated value\r
413  */\r
414 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2)\r
415 {\r
416 \r
417   __ASM volatile ("ror %0, %0, %1" : "+r" (op1) : "r" (op2) );\r
418   return(op1);\r
419 }\r
420 \r
421 \r
422 #if       (__CORTEX_M >= 0x03)\r
423 \r
424 /** \brief  Reverse bit order of value\r
425 \r
426     This function reverses the bit order of the given value.\r
427 \r
428     \param [in]    value  Value to reverse\r
429     \return               Reversed value\r
430  */\r
431 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value)\r
432 {\r
433   uint32_t result;\r
434 \r
435    __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );\r
436    return(result);\r
437 }\r
438 \r
439 \r
440 /** \brief  LDR Exclusive (8 bit)\r
441 \r
442     This function performs a exclusive LDR command for 8 bit value.\r
443 \r
444     \param [in]    ptr  Pointer to data\r
445     \return             value of type uint8_t at (*ptr)\r
446  */\r
447 __attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr)\r
448 {\r
449     uint8_t result;\r
450 \r
451    __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );\r
452    return(result);\r
453 }\r
454 \r
455 \r
456 /** \brief  LDR Exclusive (16 bit)\r
457 \r
458     This function performs a exclusive LDR command for 16 bit values.\r
459 \r
460     \param [in]    ptr  Pointer to data\r
461     \return        value of type uint16_t at (*ptr)\r
462  */\r
463 __attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr)\r
464 {\r
465     uint16_t result;\r
466 \r
467    __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );\r
468    return(result);\r
469 }\r
470 \r
471 \r
472 /** \brief  LDR Exclusive (32 bit)\r
473 \r
474     This function performs a exclusive LDR command for 32 bit values.\r
475 \r
476     \param [in]    ptr  Pointer to data\r
477     \return        value of type uint32_t at (*ptr)\r
478  */\r
479 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr)\r
480 {\r
481     uint32_t result;\r
482 \r
483    __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );\r
484    return(result);\r
485 }\r
486 \r
487 \r
488 /** \brief  STR Exclusive (8 bit)\r
489 \r
490     This function performs a exclusive STR command for 8 bit values.\r
491 \r
492     \param [in]  value  Value to store\r
493     \param [in]    ptr  Pointer to location\r
494     \return          0  Function succeeded\r
495     \return          1  Function failed\r
496  */\r
497 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)\r
498 {\r
499    uint32_t result;\r
500 \r
501    __ASM volatile ("strexb %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );\r
502    return(result);\r
503 }\r
504 \r
505 \r
506 /** \brief  STR Exclusive (16 bit)\r
507 \r
508     This function performs a exclusive STR command for 16 bit values.\r
509 \r
510     \param [in]  value  Value to store\r
511     \param [in]    ptr  Pointer to location\r
512     \return          0  Function succeeded\r
513     \return          1  Function failed\r
514  */\r
515 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)\r
516 {\r
517    uint32_t result;\r
518 \r
519    __ASM volatile ("strexh %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );\r
520    return(result);\r
521 }\r
522 \r
523 \r
524 /** \brief  STR Exclusive (32 bit)\r
525 \r
526     This function performs a exclusive STR command for 32 bit values.\r
527 \r
528     \param [in]  value  Value to store\r
529     \param [in]    ptr  Pointer to location\r
530     \return          0  Function succeeded\r
531     \return          1  Function failed\r
532  */\r
533 __attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)\r
534 {\r
535    uint32_t result;\r
536 \r
537    __ASM volatile ("strex %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) );\r
538    return(result);\r
539 }\r
540 \r
541 \r
542 /** \brief  Remove the exclusive lock\r
543 \r
544     This function removes the exclusive lock which is created by LDREX.\r
545 \r
546  */\r
547 __attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void)\r
548 {\r
549   __ASM volatile ("clrex");\r
550 }\r
551 \r
552 \r
553 /** \brief  Signed Saturate\r
554 \r
555     This function saturates a signed value.\r
556 \r
557     \param [in]  value  Value to be saturated\r
558     \param [in]    sat  Bit position to saturate to (1..32)\r
559     \return             Saturated value\r
560  */\r
561 #define __SSAT(ARG1,ARG2) \\r
562 ({                          \\r
563   uint32_t __RES, __ARG1 = (ARG1); \\r
564   __ASM ("ssat %0, %1, %2" : "=r" (__RES) :  "I" (ARG2), "r" (__ARG1) ); \\r
565   __RES; \\r
566  })\r
567 \r
568 \r
569 /** \brief  Unsigned Saturate\r
570 \r
571     This function saturates an unsigned value.\r
572 \r
573     \param [in]  value  Value to be saturated\r
574     \param [in]    sat  Bit position to saturate to (0..31)\r
575     \return             Saturated value\r
576  */\r
577 #define __USAT(ARG1,ARG2) \\r
578 ({                          \\r
579   uint32_t __RES, __ARG1 = (ARG1); \\r
580   __ASM ("usat %0, %1, %2" : "=r" (__RES) :  "I" (ARG2), "r" (__ARG1) ); \\r
581   __RES; \\r
582  })\r
583 \r
584 \r
585 /** \brief  Count leading zeros\r
586 \r
587     This function counts the number of leading zeros of a data value.\r
588 \r
589     \param [in]  value  Value to count the leading zeros\r
590     \return             number of leading zeros in value\r
591  */\r
592 __attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value)\r
593 {\r
594   uint8_t result;\r
595 \r
596   __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );\r
597   return(result);\r
598 }\r
599 \r
600 #endif /* (__CORTEX_M >= 0x03) */\r
601 \r
602 \r
603 \r
604 \r
605 #elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/\r
606 /* TASKING carm specific functions */\r
607 \r
608 /*\r
609  * The CMSIS functions have been implemented as intrinsics in the compiler.\r
610  * Please use "carm -?i" to get an up to date list of all intrinsics,\r
611  * Including the CMSIS ones.\r
612  */\r
613 \r
614 #endif\r
615 \r
616 /*@}*/ /* end of group CMSIS_Core_InstructionInterface */\r
617 \r
618 #endif /* __CORE_CMINSTR_H */\r