]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil/driverlib/cpu.c
Final V8.2.1 release ready for tagging:
[freertos] / FreeRTOS / Demo / CORTEX_M4F_MSP432_LaunchPad_IAR_CCS_Keil / driverlib / cpu.c
1 /*
2  * -------------------------------------------
3  *    MSP432 DriverLib - v01_04_00_18 
4  * -------------------------------------------
5  *
6  * --COPYRIGHT--,BSD,BSD
7  * Copyright (c) 2015, Texas Instruments Incorporated
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * *  Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  *
17  * *  Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * *  Neither the name of Texas Instruments Incorporated nor the names of
22  *    its contributors may be used to endorse or promote products derived
23  *    from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
27  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
29  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
32  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
34  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
35  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  * --/COPYRIGHT--*/
37 #include <cpu.h>
38 #include <msp.h>
39 #include <stdint.h>
40
41 //*****************************************************************************
42 //
43 // Wrapper function for the CPSID instruction.  Returns the state of PRIMASK
44 // on entry.
45 //
46 //*****************************************************************************
47 #if defined(gcc)
48 uint32_t __attribute__((naked)) CPU_cpsid(void)
49 {
50     uint32_t ret;
51
52     //
53     // Read PRIMASK and disable interrupts.
54     //
55     __asm("    mrs     r0, PRIMASK\n"
56             "    cpsid   i\n"
57             "    bx      lr\n"
58             : "=r" (ret));
59
60     //
61     // The return is handled in the inline assembly, but the compiler will
62     // still complain if there is not an explicit return here (despite the fact
63     // that this does not result in any code being produced because of the
64     // naked attribute).
65     //
66     return(ret);
67 }
68 #endif
69 #if defined(ewarm)
70 uint32_t CPU_cpsid(void)
71 {
72     //
73     // Read PRIMASK and disable interrupts.
74     //
75     __asm("    mrs     r0, PRIMASK\n"
76             "    cpsid   i\n");
77
78     //
79     // "Warning[Pe940]: missing return statement at end of non-void function"
80     // is suppressed here to avoid putting a "bx lr" in the inline assembly
81     // above and a superfluous return statement here.
82     //
83 #pragma diag_suppress=Pe940
84 }
85 #pragma diag_default=Pe940
86 #endif
87 #if defined(keil)
88 __asm uint32_t CPU_cpsid(void)
89 {
90     //
91     // Read PRIMASK and disable interrupts.
92     //
93     mrs r0, PRIMASK;
94     cpsid i;
95     bx lr
96 }
97 #endif
98 #if defined(ccs)
99 uint32_t CPU_cpsid(void)
100 {
101     //
102     // Read PRIMASK and disable interrupts.
103     //
104     __asm("    mrs     r0, PRIMASK\n"
105             "    cpsid   i\n"
106             "    bx      lr\n");
107
108     //
109     // The following keeps the compiler happy, because it wants to see a
110     // return value from this function.  It will generate code to return
111     // a zero.  However, the real return is the "bx lr" above, so the
112     // return(0) is never executed and the function returns with the value
113     // you expect in R0.
114     //
115     return(0);
116 }
117 #endif
118
119 //*****************************************************************************
120 //
121 // Wrapper function returning the state of PRIMASK (indicating whether
122 // interrupts are enabled or disabled).
123 //
124 //*****************************************************************************
125 #if defined(gcc)
126 uint32_t __attribute__((naked)) CPU_primask(void)
127 {
128     uint32_t ret;
129
130     //
131     // Read PRIMASK and disable interrupts.
132     //
133     __asm("    mrs     r0, PRIMASK\n"
134             "    bx      lr\n"
135             : "=r" (ret));
136
137     //
138     // The return is handled in the inline assembly, but the compiler will
139     // still complain if there is not an explicit return here (despite the fact
140     // that this does not result in any code being produced because of the
141     // naked attribute).
142     //
143     return(ret);
144 }
145 #endif
146 #if defined(ewarm)
147 uint32_t CPU_primask(void)
148 {
149     //
150     // Read PRIMASK and disable interrupts.
151     //
152     __asm("    mrs     r0, PRIMASK\n");
153
154     //
155     // "Warning[Pe940]: missing return statement at end of non-void function"
156     // is suppressed here to avoid putting a "bx lr" in the inline assembly
157     // above and a superfluous return statement here.
158     //
159 #pragma diag_suppress=Pe940
160 }
161 #pragma diag_default=Pe940
162 #endif
163 #if defined(keil)
164 __asm uint32_t CPU_primask(void)
165 {
166     //
167     // Read PRIMASK and disable interrupts.
168     //
169     mrs r0, PRIMASK;
170     bx lr
171 }
172 #endif
173 #if defined(ccs)
174 uint32_t CPU_primask(void)
175 {
176     //
177     // Read PRIMASK and disable interrupts.
178     //
179     __asm("    mrs     r0, PRIMASK\n"
180             "    bx      lr\n");
181
182     //
183     // The following keeps the compiler happy, because it wants to see a
184     // return value from this function.  It will generate code to return
185     // a zero.  However, the real return is the "bx lr" above, so the
186     // return(0) is never executed and the function returns with the value
187     // you expect in R0.
188     //
189     return(0);
190 }
191 #endif
192
193 //*****************************************************************************
194 //
195 // Wrapper function for the CPSIE instruction.  Returns the state of PRIMASK
196 // on entry.
197 //
198 //*****************************************************************************
199 #if defined(gcc)
200 uint32_t __attribute__((naked)) CPU_cpsie(void)
201 {
202     uint32_t ret;
203
204     //
205     // Read PRIMASK and enable interrupts.
206     //
207     __asm("    mrs     r0, PRIMASK\n"
208             "    cpsie   i\n"
209             "    bx      lr\n"
210             : "=r" (ret));
211
212     //
213     // The return is handled in the inline assembly, but the compiler will
214     // still complain if there is not an explicit return here (despite the fact
215     // that this does not result in any code being produced because of the
216     // naked attribute).
217     //
218     return(ret);
219 }
220 #endif
221 #if defined(ewarm)
222 uint32_t CPU_cpsie(void)
223 {
224     //
225     // Read PRIMASK and enable interrupts.
226     //
227     __asm("    mrs     r0, PRIMASK\n"
228             "    cpsie   i\n");
229
230     //
231     // "Warning[Pe940]: missing return statement at end of non-void function"
232     // is suppressed here to avoid putting a "bx lr" in the inline assembly
233     // above and a superfluous return statement here.
234     //
235 #pragma diag_suppress=Pe940
236 }
237 #pragma diag_default=Pe940
238 #endif
239 #if defined(keil)
240 __asm uint32_t CPU_cpsie(void)
241 {
242     //
243     // Read PRIMASK and enable interrupts.
244     //
245     mrs r0, PRIMASK;
246     cpsie i;
247     bx lr
248 }
249 #endif
250 #if defined(ccs)
251 uint32_t CPU_cpsie(void)
252 {
253     //
254     // Read PRIMASK and enable interrupts.
255     //
256     __asm("    mrs     r0, PRIMASK\n"
257             "    cpsie   i\n"
258             "    bx      lr\n");
259
260     //
261     // The following keeps the compiler happy, because it wants to see a
262     // return value from this function.  It will generate code to return
263     // a zero.  However, the real return is the "bx lr" above, so the
264     // return(0) is never executed and the function returns with the value
265     // you expect in R0.
266     //
267     return(0);
268 }
269 #endif
270
271 //*****************************************************************************
272 //
273 // Wrapper function for the CPUWFI instruction.
274 //
275 //*****************************************************************************
276 #if defined(gcc)
277 void __attribute__((naked)) CPU_wfi(void)
278 {
279     //
280     // Wait for the next interrupt.
281     //
282     __asm("    wfi\n"
283             "    bx      lr\n");
284 }
285 #endif
286 #if defined(ewarm)
287 void CPU_wfi(void)
288 {
289     //
290     // Wait for the next interrupt.
291     //
292     __asm("    wfi\n");
293 }
294 #endif
295 #if defined(keil)
296 __asm void CPU_wfi(void)
297 {
298     //
299     // Wait for the next interrupt.
300     //
301     wfi;
302     bx lr
303 }
304 #endif
305 #if defined(ccs)
306 void CPU_wfi(void)
307 {
308     //
309     // Wait for the next interrupt.
310     //
311     __asm("    wfi\n");
312 }
313 #endif
314
315 //*****************************************************************************
316 //
317 // Wrapper function for writing the BASEPRI register.
318 //
319 //*****************************************************************************
320 #if defined(gcc)
321 void __attribute__((naked)) CPU_basepriSet(uint32_t newBasepri)
322 {
323     //
324     // Set the BASEPRI register
325     //
326     __asm("    msr     BASEPRI, r0\n"
327             "    bx      lr\n");
328 }
329 #endif
330 #if defined(ewarm)
331 void CPU_basepriSet(uint32_t newBasepri)
332 {
333     //
334     // Set the BASEPRI register
335     //
336     __asm("    msr     BASEPRI, r0\n");
337 }
338 #endif
339 #if defined(keil)
340 __asm void CPU_basepriSet(uint32_t newBasepri)
341 {
342     //
343     // Set the BASEPRI register
344     //
345     msr BASEPRI, r0;
346     bx lr
347 }
348 #endif
349 #if defined(ccs)
350 void CPU_basepriSet(uint32_t newBasepri)
351 {
352     //
353     // Set the BASEPRI register
354     //
355     __asm("    msr     BASEPRI, r0\n");
356 }
357 #endif
358
359 //*****************************************************************************
360 //
361 // Wrapper function for reading the BASEPRI register.
362 //
363 //*****************************************************************************
364 #if defined(gcc)
365 uint32_t __attribute__((naked)) CPU_basepriGet(void)
366 {
367     uint32_t ret;
368
369     //
370     // Read BASEPRI
371     //
372     __asm("    mrs     r0, BASEPRI\n"
373             "    bx      lr\n"
374             : "=r" (ret));
375
376     //
377     // The return is handled in the inline assembly, but the compiler will
378     // still complain if there is not an explicit return here (despite the fact
379     // that this does not result in any code being produced because of the
380     // naked attribute).
381     //
382     return(ret);
383 }
384 #endif
385 #if defined(ewarm)
386 uint32_t CPU_basepriGet(void)
387 {
388     //
389     // Read BASEPRI
390     //
391     __asm("    mrs     r0, BASEPRI\n");
392
393     //
394     // "Warning[Pe940]: missing return statement at end of non-void function"
395     // is suppressed here to avoid putting a "bx lr" in the inline assembly
396     // above and a superfluous return statement here.
397     //
398 #pragma diag_suppress=Pe940
399 }
400 #pragma diag_default=Pe940
401 #endif
402 #if defined(keil)
403 __asm uint32_t CPU_basepriGet(void)
404 {
405     //
406     // Read BASEPRI
407     //
408     mrs r0, BASEPRI;
409     bx lr
410 }
411 #endif
412 #if defined(ccs)
413 uint32_t CPU_basepriGet(void)
414 {
415     //
416     // Read BASEPRI
417     //
418     __asm("    mrs     r0, BASEPRI\n"
419             "    bx      lr\n");
420
421     //
422     // The following keeps the compiler happy, because it wants to see a
423     // return value from this function.  It will generate code to return
424     // a zero.  However, the real return is the "bx lr" above, so the
425     // return(0) is never executed and the function returns with the value
426     // you expect in R0.
427     //
428     return(0);
429 }
430 #endif