]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/ThirdParty/CDK/T-HEAD_CK802/portmacro.h
Introduce a port for T-HEAD CK802. A simple demo for T-HEAD CB2201 is also included.
[freertos] / FreeRTOS / Source / portable / ThirdParty / CDK / T-HEAD_CK802 / portmacro.h
1 /*
2  * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a copy of
5  * this software and associated documentation files (the "Software"), to deal in
6  * the Software without restriction, including without limitation the rights to
7  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8  * the Software, and to permit persons to whom the Software is furnished to do so,
9  * subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20  *
21  * 1 tab == 4 spaces!
22  */
23
24 #ifndef PORTMACRO_H
25 #define PORTMACRO_H
26
27 #include <stdlib.h>
28 #include <stdint.h>
29 #include <csi_core.h>
30
31 extern void vPortYield(void);
32 #ifdef __cplusplus
33 class vPortYield;
34 extern "C" {
35 #endif
36
37
38 /*-----------------------------------------------------------
39  * Port specific definitions.
40  *
41  * The settings in this file configure FreeRTOS correctly for the
42  * given hardware and compiler.
43  *
44  * These settings should not be altered.
45  *-----------------------------------------------------------
46  */
47
48 /* Type definitions. */
49 #define portCHAR        char
50 #define portFLOAT       float
51 #define portDOUBLE      double
52 #define portLONG        long
53 #define portSHORT       short
54 #define portSTACK_TYPE  uint32_t
55 #define portBASE_TYPE   long
56
57 typedef portSTACK_TYPE StackType_t;
58 typedef long BaseType_t;
59 typedef unsigned long UBaseType_t;
60 typedef void (*portvectorfunc)(void);
61
62 #if( configUSE_16_BIT_TICKS == 1 )
63     typedef uint16_t  TickType_t;
64     #define portMAX_DELAY ( TickType_t ) 0xffff
65 #else
66     typedef uint32_t  TickType_t;
67     #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
68 #endif
69
70
71 /* Hardware specifics. */
72 #define portBYTE_ALIGNMENT          8
73 #define portSTACK_GROWTH            -1
74 #define portMS_PERIOD_TICK          10
75 #define portTICK_PERIOD_MS              ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
76
77
78 static inline void vPortEnableInterrupt( void )
79 {
80     __enable_irq();
81 }
82
83 static inline void vPortDisableInterrupt( void )
84 {
85     __disable_irq();
86 }
87
88 static inline portLONG GetCurrentPSR (void)
89 {
90     return __get_PSR();
91 }
92
93 static inline portLONG SaveLocalPSR (void)
94 {
95     portLONG flags = __get_PSR();
96     __disable_irq();
97     return flags;
98 }
99
100 static inline void RestoreLocalPSR (portLONG newMask)
101 {
102     __asm__ __volatile__(
103     "mtcr   %0, psr \n"
104     :
105     :"r" (newMask)
106     :"memory"
107     );
108 }
109
110 extern void vPortEnterCritical( void );
111 extern void vPortExitCritical( void );
112 extern __attribute__((naked)) void cpu_yeild(void);
113
114 #define portDISABLE_INTERRUPTS()                vPortDisableInterrupt()
115 #define portENABLE_INTERRUPTS()                 vPortEnableInterrupt()
116 #define portENTER_CRITICAL()                    vPortEnterCritical()
117 #define portEXIT_CRITICAL()                     vPortExitCritical()
118 #define portSET_INTERRUPT_MASK_FROM_ISR()       SaveLocalPSR()
119 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(a)    RestoreLocalPSR(a)
120
121 #define portNOP()                   asm("nop")
122
123 extern portLONG ulCriticalNesting;
124 extern portLONG pendsvflag;
125
126 #define portYIELD()                 if (ulCriticalNesting == 0) \
127                                     {   \
128                                         vPortYield();   \
129                                     }   \
130                                     else \
131                                     {   \
132                                         pendsvflag = 1; \
133                                     }   \
134                                     portNOP();portNOP()
135
136 /*-----------------------------------------------------------*/
137
138 /* Task function macros as described on the FreeRTOS.org WEB site. */
139 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))
140 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
141 /*-----------------------------------------------------------*/
142
143 #define portEND_SWITCHING_ISR( xSwitchRequired )    do {    \
144                                                             if( xSwitchRequired != pdFALSE )    \
145                                                             {   \
146                                                                 portYIELD();    \
147                                                             }   \
148                                                     }while(0)
149
150 #define portYIELD_FROM_ISR( a )     vTaskSwitchContext()
151
152
153
154 #ifdef __cplusplus
155 }
156 #endif
157
158 #endif /* PORTMACRO_H */
159