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
34 /* *INDENT-OFF* */
35 #ifdef __cplusplus
36 class vPortYield;
37 extern "C" {
38 #endif
39 /* *INDENT-ON* */
40
41
42 /*-----------------------------------------------------------
43 * Port specific definitions.
44 *
45 * The settings in this file configure FreeRTOS correctly for the
46 * given hardware and compiler.
47 *
48 * These settings should not be altered.
49 *-----------------------------------------------------------
50 */
51
52 /* Type definitions. */
53 #define portCHAR char
54 #define portFLOAT float
55 #define portDOUBLE double
56 #define portLONG long
57 #define portSHORT short
58 #define portSTACK_TYPE uint32_t
59 #define portBASE_TYPE long
60
61 typedef portSTACK_TYPE StackType_t;
62 typedef long BaseType_t;
63 typedef unsigned long UBaseType_t;
64 typedef void (*portvectorfunc)(void);
65
66 #if( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
67 typedef uint16_t TickType_t;
68 #define portMAX_DELAY ( TickType_t ) 0xffff
69 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
70 typedef uint32_t TickType_t;
71 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
72 #else
73 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
74 #endif
75
76
77 /* Hardware specifics. */
78 #define portBYTE_ALIGNMENT 8
79 #define portSTACK_GROWTH -1
80 #define portMS_PERIOD_TICK 10
81 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
82
83
vPortEnableInterrupt(void)84 static inline void vPortEnableInterrupt( void )
85 {
86 __enable_irq();
87 }
88
vPortDisableInterrupt(void)89 static inline void vPortDisableInterrupt( void )
90 {
91 __disable_irq();
92 }
93
GetCurrentPSR(void)94 static inline portLONG GetCurrentPSR (void)
95 {
96 return __get_PSR();
97 }
98
SaveLocalPSR(void)99 static inline portLONG SaveLocalPSR (void)
100 {
101 portLONG flags = __get_PSR();
102 __disable_irq();
103 return flags;
104 }
105
RestoreLocalPSR(portLONG newMask)106 static inline void RestoreLocalPSR (portLONG newMask)
107 {
108 __asm__ __volatile__(
109 "mtcr %0, psr \n"
110 :
111 :"r" (newMask)
112 :"memory"
113 );
114 }
115
116 extern void vPortEnterCritical( void );
117 extern void vPortExitCritical( void );
118 extern __attribute__((naked)) void cpu_yeild(void);
119
120 #define portDISABLE_INTERRUPTS() vPortDisableInterrupt()
121 #define portENABLE_INTERRUPTS() vPortEnableInterrupt()
122 #define portENTER_CRITICAL() vPortEnterCritical()
123 #define portEXIT_CRITICAL() vPortExitCritical()
124 #define portSET_INTERRUPT_MASK_FROM_ISR() SaveLocalPSR()
125 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(a) RestoreLocalPSR(a)
126
127 #define portNOP() asm("nop")
128
129 extern portLONG ulCriticalNesting;
130 extern portLONG pendsvflag;
131
132 #define portYIELD() if (ulCriticalNesting == 0) \
133 { \
134 vPortYield(); \
135 } \
136 else \
137 { \
138 pendsvflag = 1; \
139 } \
140 portNOP();portNOP()
141
142 /*-----------------------------------------------------------*/
143
144 /* Task function macros as described on the FreeRTOS.org WEB site. */
145 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))
146 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
147 /*-----------------------------------------------------------*/
148
149 #define portEND_SWITCHING_ISR( xSwitchRequired ) do { \
150 if( xSwitchRequired != pdFALSE ) \
151 { \
152 portYIELD(); \
153 } \
154 }while(0)
155
156 #define portYIELD_FROM_ISR( a ) vTaskSwitchContext()
157
158
159
160 /* *INDENT-OFF* */
161 #ifdef __cplusplus
162 }
163 #endif
164 /* *INDENT-ON* */
165
166 #endif /* PORTMACRO_H */
167