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