]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/T-HEAD_CB2201_CDK/csi/csi_core/include/csi-gcc/csi_reg.h
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Demo / T-HEAD_CB2201_CDK / csi / csi_core / include / csi-gcc / csi_reg.h
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /******************************************************************************
18  * @file     csi_reg.h
19  * @brief    CSI Header File for reg.
20  * @version  V1.0
21  * @date     02. June 2017
22  ******************************************************************************/
23
24 #ifndef _CSI_REG_H_
25 #define _CSI_REG_H_
26
27 #include<csi_gcc.h>
28
29 /**
30   \brief   Enable IRQ Interrupts
31   \details Enables IRQ interrupts by setting the IE-bit in the PSR.
32            Can only be executed in Privileged modes.
33  */
34 __ALWAYS_INLINE void __enable_irq(void)
35 {
36     __ASM volatile("psrset ie");
37 }
38
39
40
41 /**
42   \brief   Disable IRQ Interrupts
43   \details Disables IRQ interrupts by clearing the IE-bit in the PSR.
44   Can only be executed in Privileged modes.
45  */
46 __ALWAYS_INLINE void __disable_irq(void)
47 {
48     __ASM volatile("psrclr ie");
49 }
50
51 /**
52   \brief   Get PSR
53   \details Returns the content of the PSR Register.
54   \return               PSR Register value
55  */
56 __ALWAYS_INLINE uint32_t __get_PSR(void)
57 {
58     uint32_t result;
59
60     __ASM volatile("mfcr %0, psr" : "=r"(result));
61     return (result);
62 }
63
64 /**
65   \brief   Set PSR
66   \details Writes the given value to the PSR Register.
67   \param [in]    psr  PSR Register value to set
68  */
69 __ALWAYS_INLINE void __set_PSR(uint32_t psr)
70 {
71     __ASM volatile("mtcr %0, psr" : : "r"(psr));
72 }
73
74 /**
75   \brief   Get SP
76   \details Returns the content of the SP Register.
77   \return               SP Register value
78  */
79 __ALWAYS_INLINE uint32_t __get_SP(void)
80 {
81     uint32_t result;
82
83     __ASM volatile("mov %0, sp" : "=r"(result));
84     return (result);
85 }
86
87 /**
88   \brief   Set SP
89   \details Writes the given value to the SP Register.
90   \param [in]    sp  SP Register value to set
91  */
92 __ALWAYS_INLINE void __set_SP(uint32_t sp)
93 {
94     __ASM volatile("mov sp, %0" : : "r"(sp): "sp");
95 }
96
97
98 /**
99   \brief   Get VBR Register
100   \details Returns the content of the VBR Register.
101   \return               VBR Register value
102  */
103 __ALWAYS_INLINE uint32_t __get_VBR(void)
104 {
105     uint32_t result;
106
107     __ASM volatile("mfcr %0, vbr" : "=r"(result));
108     return (result);
109 }
110
111 /**
112   \brief   Set VBR
113   \details Writes the given value to the VBR Register.
114   \param [in]    vbr  VBR Register value to set
115  */
116 __ALWAYS_INLINE void __set_VBR(uint32_t vbr)
117 {
118     __ASM volatile("mtcr %0, vbr" : : "r"(vbr));
119 }
120
121 /**
122   \brief   Get EPC Register
123   \details Returns the content of the EPC Register.
124   \return               EPC Register value
125  */
126 __ALWAYS_INLINE uint32_t __get_EPC(void)
127 {
128     uint32_t result;
129
130     __ASM volatile("mfcr %0, epc" : "=r"(result));
131     return (result);
132 }
133
134 /**
135   \brief   Set EPC
136   \details Writes the given value to the EPC Register.
137   \param [in]    epc  EPC Register value to set
138  */
139 __ALWAYS_INLINE void __set_EPC(uint32_t epc)
140 {
141     __ASM volatile("mtcr %0, epc" : : "r"(epc));
142 }
143
144 /**
145   \brief   Get EPSR
146   \details Returns the content of the EPSR Register.
147   \return               EPSR Register value
148  */
149 __ALWAYS_INLINE uint32_t __get_EPSR(void)
150 {
151     uint32_t result;
152
153     __ASM volatile("mfcr %0, epsr" : "=r"(result));
154     return (result);
155 }
156
157 /**
158   \brief   Set EPSR
159   \details Writes the given value to the EPSR Register.
160   \param [in]    epsr  EPSR Register value to set
161  */
162 __ALWAYS_INLINE void __set_EPSR(uint32_t epsr)
163 {
164     __ASM volatile("mtcr %0, epsr" : : "r"(epsr));
165 }
166
167 /**
168   \brief   Get CPUID Register
169   \details Returns the content of the CPUID Register.
170   \return               CPUID Register value
171  */
172 __ALWAYS_INLINE uint32_t __get_CPUID(void)
173 {
174     uint32_t result;
175
176 #ifdef __CK610
177     __ASM volatile("mfcr %0, cr13" : "=r"(result));
178 #else
179     __ASM volatile("mfcr %0, cr<13, 0>" : "=r"(result));
180 #endif
181     return (result);
182 }
183
184 #if (__SOFTRESET_PRESENT == 1U)
185 /**
186   \brief   Set SRCR
187   \details Assigns the given value to the SRCR.
188   \param [in]    srcr  SRCR value to set
189  */
190 __ALWAYS_INLINE void __set_SRCR(uint32_t srcr)
191 {
192     __ASM volatile("mtcr %0, cr<31, 0>\n" : : "r"(srcr));
193 }
194 #endif /* __SOFTRESET_PRESENT == 1U */
195
196 #if (__MGU_PRESENT == 1U)
197 /**
198   \brief   Get CCR
199   \details Returns the current value of the CCR.
200   \return               CCR Register value
201  */
202 __ALWAYS_INLINE uint32_t __get_CCR(void)
203 {
204     register uint32_t result;
205
206 #ifdef __CK610
207     __ASM volatile("mfcr %0, cr18\n"  : "=r"(result));
208 #else
209     __ASM volatile("mfcr %0, cr<18, 0>\n"  : "=r"(result));
210 #endif
211     return (result);
212 }
213
214
215 /**
216   \brief   Set CCR
217   \details Assigns the given value to the CCR.
218   \param [in]    ccr  CCR value to set
219  */
220 __ALWAYS_INLINE void __set_CCR(uint32_t ccr)
221 {
222 #ifdef __CK610
223     __ASM volatile("mtcr %0, cr18\n" : : "r"(ccr));
224 #else
225     __ASM volatile("mtcr %0, cr<18, 0>\n" : : "r"(ccr));
226 #endif
227 }
228
229
230 /**
231   \brief   Get CAPR
232   \details Returns the current value of the CAPR.
233   \return               CAPR Register value
234  */
235 __ALWAYS_INLINE uint32_t __get_CAPR(void)
236 {
237     register uint32_t result;
238
239 #ifdef __CK610
240     __ASM volatile("mfcr %0, cr19\n" : "=r"(result));
241 #else
242     __ASM volatile("mfcr %0, cr<19, 0>\n" : "=r"(result));
243 #endif
244     return (result);
245 }
246
247 /**
248   \brief   Set CAPR
249   \details Assigns the given value to the CAPR.
250   \param [in]    capr  CAPR value to set
251  */
252 __ALWAYS_INLINE void __set_CAPR(uint32_t capr)
253 {
254 #ifdef __CK610
255     __ASM volatile("mtcr %0, cr19\n" : : "r"(capr));
256 #else
257     __ASM volatile("mtcr %0, cr<19, 0>\n" : : "r"(capr));
258 #endif
259 }
260
261
262 /**
263   \brief   Set PACR
264   \details Assigns the given value to the PACR.
265
266     \param [in]    pacr  PACR value to set
267  */
268 __ALWAYS_INLINE void __set_PACR(uint32_t pacr)
269 {
270 #ifdef __CK610
271     __ASM volatile("mtcr %0, cr20\n" : : "r"(pacr));
272 #else
273     __ASM volatile("mtcr %0, cr<20, 0>\n" : : "r"(pacr));
274 #endif
275 }
276
277
278 /**
279   \brief   Get PACR
280   \details Returns the current value of PACR.
281   \return               PACR value
282  */
283 __ALWAYS_INLINE uint32_t __get_PACR(void)
284 {
285     uint32_t result;
286
287 #ifdef __CK610
288     __ASM volatile("mfcr %0, cr20" : "=r"(result));
289 #else
290     __ASM volatile("mfcr %0, cr<20, 0>" : "=r"(result));
291 #endif
292     return (result);
293 }
294
295 /**
296   \brief   Set PRSR
297   \details Assigns the given value to the PRSR.
298
299     \param [in]    prsr  PRSR value to set
300  */
301 __ALWAYS_INLINE void __set_PRSR(uint32_t prsr)
302 {
303 #ifdef __CK610
304     __ASM volatile("mtcr %0, cr21\n" : : "r"(prsr));
305 #else
306     __ASM volatile("mtcr %0, cr<21, 0>\n" : : "r"(prsr));
307 #endif
308 }
309
310 /**
311   \brief   Get PRSR
312   \details Returns the current value of PRSR.
313   \return               PRSR value
314  */
315 __ALWAYS_INLINE uint32_t __get_PRSR(void)
316 {
317     uint32_t result;
318
319 #ifdef __CK610
320     __ASM volatile("mfcr %0, cr21" : "=r"(result));
321 #else
322     __ASM volatile("mfcr %0, cr<21, 0>" : "=r"(result));
323 #endif
324     return (result);
325 }
326 #endif /* __MGU_PRESENT == 1U */
327
328 /**
329   \brief   Get user sp
330   \details Returns the current value of user r14.
331   \return               UR14 value
332  */
333 __ALWAYS_INLINE uint32_t __get_UR14(void)
334 {
335     uint32_t result;
336
337 #ifdef __CK610
338     __ASM volatile("mov %0, sp" : "=r"(result));
339 #else
340     __ASM volatile("mfcr %0, cr<14, 1>" : "=r"(result));
341 #endif
342     return (result);
343 }
344
345 /**
346   \brief   Enable interrupts and exceptions
347   \details Enables interrupts and exceptions by setting the IE-bit and EE-bit in the PSR.
348            Can only be executed in Privileged modes.
349  */
350 __ALWAYS_INLINE void __enable_excp_irq(void)
351 {
352     __ASM volatile("psrset ee, ie");
353 }
354
355
356 /**
357   \brief   Disable interrupts and exceptions
358   \details Disables interrupts and exceptions by clearing the IE-bit and EE-bit in the PSR.
359            Can only be executed in Privileged modes.
360  */
361 __ALWAYS_INLINE void __disable_excp_irq(void)
362 {
363     __ASM volatile("psrclr ee, ie");
364 }
365
366 #if (__GSR_GCR_PRESENT == 1U)
367 /**
368   \brief   Get GSR
369   \details Returns the content of the GSR Register.
370   \return               GSR Register value
371  */
372 __ALWAYS_INLINE uint32_t __get_GSR(void)
373 {
374     uint32_t result;
375
376 #ifdef __CK610
377     __ASM volatile("mfcr %0, cr12" : "=r"(result));
378 #else
379     __ASM volatile("mfcr %0, cr<12, 0>" : "=r"(result));
380 #endif
381     return (result);
382 }
383
384 /**
385   \brief   Get GCR
386   \details Returns the content of the GCR Register.
387   \return               GCR Register value
388  */
389 __ALWAYS_INLINE uint32_t __get_GCR(void)
390 {
391     uint32_t result;
392
393 #ifdef __CK610
394     __ASM volatile("mfcr %0, cr11" : "=r"(result));
395 #else
396     __ASM volatile("mfcr %0, cr<11, 0>" : "=r"(result));
397 #endif
398     return (result);
399 }
400
401 /**
402   \brief   Set GCR
403   \details Writes the given value to the GCR Register.
404   \param [in]    gcr  GCR Register value to set
405  */
406 __ALWAYS_INLINE void __set_GCR(uint32_t gcr)
407 {
408 #ifdef __CK610
409     __ASM volatile("mtcr %0, cr11" : : "r"(gcr));
410 #else
411     __ASM volatile("mtcr %0, cr<11, 0>" : : "r"(gcr));
412 #endif
413 }
414
415 #endif /* (__GSR_GCR_PRESENT == 1U) */
416
417
418 #endif /* _CSI_REG_H_ */