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