]> begriffs open source - cmsis-freertos/blob - Demo/PIC32MEC14xx_MPLAB/src/include/platform.h
there was an extra ')'... caused build to fail
[cmsis-freertos] / Demo / PIC32MEC14xx_MPLAB / src / include / platform.h
1 /*****************************************************************************
2 * © 2014 Microchip Technology Inc. and its subsidiaries.
3 * You may use this software and any derivatives exclusively with
4 * Microchip products.
5 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS".
6 * NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
7 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
8 * AND FITNESS FOR A PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP
9 * PRODUCTS, COMBINATION WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.
10 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
11 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
12 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
13 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE.
14 * TO THE FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL
15 * CLAIMS IN ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF
16 * FEES, IF ANY, THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
17 * MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE
18 * OF THESE TERMS.
19 *****************************************************************************/
20
21 /** @file platform.h
22  *MEC14xx platform/cpu abstractions
23  */
24 /** @defgroup MEC14xx
25  */
26
27 #ifndef _PLATFORM_H
28 #define _PLATFORM_H
29
30 #if defined(__GNUC__) && defined(__mips__)
31
32 #if defined(__XC32__)  // Microchip XC32 GCC
33
34 /* Pull in MIPS32 specific special instructions instrinsics for
35  * interrupt control, NOP, Wait-for-Interrupt and accessing
36  * MSR's.
37  * Issue: MPLAB-X IDE editor and the CPU macros in xc.h & cp0defs.h.
38  * The IDE editor will show red ! on every line of code using the above
39  * macros due to a bug in the IDE's C language preprocessor.
40  */
41 #include <xc.h>
42
43 #define CPU_DISABLE_INTERRUPTS() __builtin_disable_interrupts()
44 #define CPU_GET_DISABLE_INTERRUPTS(x) { x=_CP0_GET_STATUS()&0x1ul; __builtin_disable_interrupts() }
45 #define CPU_ENABLE_INTERRUPTS() __builtin_enable_interrupts()
46 #define CPU_RESTORE_INTERRUPTS(x) { if (x) { __builtin_enable_interrupts(); } }
47
48 #define Disable_Irq()   CPU_DISABLE_INTERRUPTS()
49 #define Enable_Irq()    CPU_ENABLE_INTERRUPTS()
50
51 #define __CLZ(x) __builtin_clz(x)
52 #define __CTZ(x) __builtin_ctz (x)
53 #define __CLO(x) _clo(x)
54
55 #define __INS(tgt,val,pos,sz) _ins(tgt,val,pos,sz)
56 #define __EXT(x,pos,sz) _ext(x,pos,sz)
57
58 #define CPU_NOP() __asm__ __volatile ("%(ssnop%)" : :)
59
60 #define CPU_WAIT_FOR_INTR() __asm__ __volatile ("wait")
61
62 #define __REV(x) _bswapw(x)
63
64 #define __EHB() _ehb()
65
66 #else
67
68 /* Include MIPS specific inline assembly functions for accessing
69  * MIPS CP0 registers, NOP, WAIT, ASET, ACLR, byte-reverse, etc.
70  */
71 #include "mipscpu.h"
72
73
74 #define CPU_DISABLE_INTERRUPTS()        mips32r2_dis_intr()
75 #define CPU_GET_DISABLE_INTERRUPTS(x) x=mips32r2_dis_intr()
76 #define CPU_ENABLE_INTERRUPTS() mips32r2_en_intr()
77 #define CPU_RESTORE_INTERRUPTS(x) mips32r2_restore_intr(x)
78
79 #define Disable_Irq()   CPU_DISABLE_INTERRUPTS()
80 #define Enable_Irq()    CPU_ENABLE_INTERRUPTS()
81
82 #define __CLZ(x) __builtin_clz(x)
83 #define __CTZ(x) __builtin_ctz (x)
84
85 #define __CLO(x) __extension__({ \
86     unsigned int __x = (x); \
87     unsigned int __v; \
88     __asm__ ("clo %0,%1" : "=d" (__v) : "d" (__x)); \
89     __v; \
90 })
91
92 /* MIPS32r2 insert bits */
93 #define __INS(tgt,val,pos,sz) __extension__({ \
94     unsigned int __t = (tgt), __v = (val); \
95     __asm__ ("ins %0,%z1,%2,%3" \
96              : "+d" (__t) \
97              : "dJ" (__v), "I" (pos), "I" (sz)); \
98     __t; \
99 })
100
101 /* MIPS32r2 extract bits */
102 #define __EXT(x,pos,sz) __extension__({ \
103     unsigned int __x = (x), __v; \
104     __asm__ ("ext %0,%z1,%2,%3" \
105              : "=d" (__v) \
106              : "dJ" (__x), "I" (pos), "I" (sz)); \
107     __v; \
108 })
109
110 #define CPU_NOP() __asm__ __volatile ("%(ssnop%)" : :)
111
112 #define CPU_WAIT_FOR_INTR() __asm__ __volatile ("wait")
113
114 #define __REV(x) mips32r2_rev_word(x)
115
116 #define __EHB() __asm__ __volatile__ ("%(ehb%)" : :)
117
118 #define _CP0_GET_BADVADDR() mips32r2_cp0_badvaddr_get()
119
120 #define _CP0_GET_COUNT() mips32r2_cp0_count_get()
121 #define _CP0_SET_COUNT(val) mips32r2_cp0_count_set((unsigned long)val)
122
123 #define _CP0_GET_COMPARE() mips32r2_cp0_compare_get()
124 #define _CP0_SET_COMPARE(val) mips32r2_cp0_compare_set((unsigned long)val)
125
126 #define _CP0_GET_STATUS() mips32r2_cp0_status_get()
127 #define _CP0_SET_STATUS(val) mips32r2_cp0_status_set((unsigned long)val)
128 #define _CP0_BIC_STATUS(val) mips32r2_cp0_status_bic(val)
129 #define _CP0_BIS_STATUS(val) mips32r2_cp0_status_bis(val)
130
131 #define _CP0_GET_INTCTL() mips32r2_cp0_intctl_get()
132 #define _CP0_SET_INTCTL(val)  mips32r2_cp0_intctl_set((unsigned long)val)
133
134 #define _CP0_GET_VIEW_IPL() mips32r2_cp0_view_ipl_get()
135 #define _CP0_SET_VIEW_IPL(val)  mips32r2_cp0_view_ipl_set((unsigned long)val)
136
137 #define _CP0_GET_CAUSE() mips32r2_cp0_cause_get()
138 #define _CP0_SET_CAUSE(val) mips32r2_cp0_cause_set((unsigned long)val)
139 #define _CP0_BIC_CAUSE(val) mips32r2_cp0_cause_bic((unsigned long)val)
140 #define _CP0_BIS_CAUSE(val) mips32r2_cp0_cause_bis((unsigned long)val)
141
142 #define _CP0_GET_VIEW_RIPL() mips32r2_cp0_view_ripl_get()
143 #define _CP0_SET_VIEW_RIPL(val) mips32r2_cp0_view_ripl_set((unsigned long)val)
144
145 #define _CP0_GET_EPC() mips32r2_cp0_epc_get()
146 #define _CP0_SET_EPC(val) mips32r2_cp0_epc_set((unsigned long)val)
147
148 #define _CP0_GET_EBASE() mips32r2_cp0_ebase_get()
149 #define _CP0_SET_EBASE(val)  mips32r2_cp0_ebase_set((unsigned long)val)
150
151 #define _CP0_GET_CONFIG() mips32r2_cp0_config_get()
152 #define _CP0_GET_CONFIG3() mips32r2_cp0_config3_get()
153
154 #define _CP0_GET_DEPC() mips32r2_cp0_depc_get()
155
156 #endif
157
158 #else  // Any other compiler
159
160 #error "FORCED BUILD ERROR: Unknown compiler"
161
162 #endif
163
164 /*
165 Need to define NULL
166 */
167 #ifndef NULL
168     #ifdef __CPLUSPLUS__
169     #define NULL            0
170     #else
171     #define NULL            ((void *)0)
172     #endif
173 #endif
174
175 #endif // #ifndef _PLATFORM_H
176 /**   @}
177  */