CMSIS2000  0.0.7
 Указатель Структуры данных Файлы Функции Переменные Определения типов Перечисления Элементы перечислений Макросы Группы Страницы
core_cm0.c
См. документацию.
1 /**************************************************************************//**
2  * @file core_cm0.c
3  * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Source File
4  * @version V2.00
5  * @date 10. September 2010
6  *
7  * @note
8  * Copyright (C) 2009-2010 ARM Limited. All rights reserved.
9  *
10  * @par
11  * ARM Limited (ARM) is supplying this software for use with Cortex-M
12  * processor based microcontrollers. This file can be freely distributed
13  * within development tools that are supporting such ARM based processors.
14  *
15  * @par
16  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
17  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
18  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
19  * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
20  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
21  *
22  ******************************************************************************/
23 
24 #include <stdint.h>
25 
26 /* define compiler specific symbols */
27 #if defined ( __CC_ARM )
28  #define __ASM __asm /*!< asm keyword for ARM Compiler */
29  #define __INLINE __inline /*!< inline keyword for ARM Compiler */
30 
31 #elif defined ( __ICCARM__ )
32  #define __ASM __asm /*!< asm keyword for IAR Compiler */
33  #define __INLINE inline /*!< inline keyword for IAR Compiler. Only avaiable in High optimization mode! */
34 
35 #elif defined ( __GNUC__ )
36  #define __ASM __asm /*!< asm keyword for GNU Compiler */
37  #define __INLINE inline /*!< inline keyword for GNU Compiler */
38 
39 #elif defined ( __TASKING__ )
40  #define __ASM __asm /*!< asm keyword for TASKING Compiler */
41  #define __INLINE inline /*!< inline keyword for TASKING Compiler */
42 
43 #endif
44 
45 
46 /* ########################## Core Instruction Access ######################### */
47 
48 #if defined ( __CC_ARM ) /*------------------ RealView Compiler ----------------*/
49 
50 /** \brief Reverse byte order (16 bit)
51 
52  This function reverses the byte order in two unsigned short values.
53 
54  \param [in] value Value to reverse
55  \return Reversed value
56  */
57 #if (__ARMCC_VERSION < 400677)
58 __ASM uint32_t __REV16(uint32_t value)
59 {
60  rev16 r0, r0
61  bx lr
62 }
63 #endif /* __ARMCC_VERSION */
64 
65 
66 /** \brief Reverse byte order in signed short value
67 
68  This function reverses the byte order in a signed short value with sign extension to integer.
69 
70  \param [in] value Value to reverse
71  \return Reversed value
72  */
73 #if (__ARMCC_VERSION < 400677)
74 __ASM int32_t __REVSH(int32_t value)
75 {
76  revsh r0, r0
77  bx lr
78 }
79 #endif /* __ARMCC_VERSION */
80 
81 
82 /** \brief Remove the exclusive lock
83 
84  This function removes the exclusive lock which is created by LDREX.
85 
86  */
87 #if (__ARMCC_VERSION < 400000)
88 __ASM void __CLREX(void)
89 {
90  clrex
91 }
92 #endif /* __ARMCC_VERSION */
93 
94 
95 #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/
96 /* obsolete */
97 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
98 /* obsolete */
99 #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
100 /* obsolete */
101 #endif
102 
103 
104 /* ########################### Core Function Access ########################### */
105 
106 #if defined ( __CC_ARM ) /*------------------ RealView Compiler ----------------*/
107 
108 /** \brief Get Control Register
109 
110  This function returns the content of the Control Register.
111 
112  \return Control Register value
113  */
114 #if (__ARMCC_VERSION < 400000)
115 __ASM uint32_t __get_CONTROL(void)
116 {
117  mrs r0, control
118  bx lr
119 }
120 #endif /* __ARMCC_VERSION */
121 
122 
123 /** \brief Set Control Register
124 
125  This function writes the given value to the Control Register.
126 
127  \param [in] control Control Register value to set
128  */
129 #if (__ARMCC_VERSION < 400000)
130 __ASM void __set_CONTROL(uint32_t control)
131 {
132  msr control, r0
133  bx lr
134 }
135 #endif /* __ARMCC_VERSION */
136 
137 
138 /** \brief Get ISPR Register
139 
140  This function returns the content of the ISPR Register.
141 
142  \return ISPR Register value
143  */
144 #if (__ARMCC_VERSION < 400000)
145 __ASM uint32_t __get_IPSR(void)
146 {
147  mrs r0, ipsr
148  bx lr
149 }
150 #endif /* __ARMCC_VERSION */
151 
152 
153 /** \brief Get APSR Register
154 
155  This function returns the content of the APSR Register.
156 
157  \return APSR Register value
158  */
159 #if (__ARMCC_VERSION < 400000)
160 __ASM uint32_t __get_APSR(void)
161 {
162  mrs r0, apsr
163  bx lr
164 }
165 #endif /* __ARMCC_VERSION */
166 
167 
168 /** \brief Get xPSR Register
169 
170  This function returns the content of the xPSR Register.
171 
172  \return xPSR Register value
173  */
174 #if (__ARMCC_VERSION < 400000)
175 __ASM uint32_t __get_xPSR(void)
176 {
177  mrs r0, xpsr
178  bx lr
179 }
180 #endif /* __ARMCC_VERSION */
181 
182 
183 /** \brief Get Process Stack Pointer
184 
185  This function returns the current value of the Process Stack Pointer (PSP).
186 
187  \return PSP Register value
188  */
189 #if (__ARMCC_VERSION < 400000)
190 __ASM uint32_t __get_PSP(void)
191 {
192  mrs r0, psp
193  bx lr
194 }
195 #endif /* __ARMCC_VERSION */
196 
197 
198 /** \brief Set Process Stack Pointer
199 
200  This function assigns the given value to the Process Stack Pointer (PSP).
201 
202  \param [in] topOfProcStack Process Stack Pointer value to set
203  */
204 #if (__ARMCC_VERSION < 400000)
205 __ASM void __set_PSP(uint32_t topOfProcStack)
206 {
207  msr psp, r0
208  bx lr
209 }
210 #endif /* __ARMCC_VERSION */
211 
212 
213 /** \brief Get Main Stack Pointer
214 
215  This function returns the current value of the Main Stack Pointer (MSP).
216 
217  \return MSP Register value
218  */
219 #if (__ARMCC_VERSION < 400000)
220 __ASM uint32_t __get_MSP(void)
221 {
222  mrs r0, msp
223  bx lr
224 }
225 #endif /* __ARMCC_VERSION */
226 
227 
228 /** \brief Set Main Stack Pointer
229 
230  This function assigns the given value to the Main Stack Pointer (MSP).
231 
232  \param [in] topOfMainStack Main Stack Pointer value to set
233  */
234 #if (__ARMCC_VERSION < 400000)
235 __ASM void __set_MSP(uint32_t mainStackPointer)
236 {
237  msr msp, r0
238  bx lr
239 }
240 #endif /* __ARMCC_VERSION */
241 
242 
243 /** \brief Get Priority Mask
244 
245  This function returns the current state of the priority mask bit from the Priority Mask Register.
246 
247  \return Priority Mask value
248  */
249 #if (__ARMCC_VERSION < 400000)
250 __ASM uint32_t __get_PRIMASK(void)
251 {
252  mrs r0, primask
253  bx lr
254 }
255 #endif /* __ARMCC_VERSION */
256 
257 
258 /** \brief Set Priority Mask
259 
260  This function assigns the given value to the Priority Mask Register.
261 
262  \param [in] priMask Priority Mask
263  */
264 #if (__ARMCC_VERSION < 400000)
265 __ASM void __set_PRIMASK(uint32_t priMask)
266 {
267  msr primask, r0
268  bx lr
269 }
270 #endif /* __ARMCC_VERSION */
271 
272 
273 #elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/
274 /* obsolete */
275 #elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
276 /* obsolete */
277 #elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
278 /* obsolete */
279 #endif