Labor04
portmacro.h
Go to the documentation of this file.
1 /*
2  * FreeRTOS Kernel V10.0.0
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software. If you wish to use our Amazon
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.
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  * http://www.FreeRTOS.org
24  * http://aws.amazon.com/freertos
25  *
26  * 1 tab == 4 spaces!
27  */
28 
29 
30 #ifndef PORTMACRO_H
31 #define PORTMACRO_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*-----------------------------------------------------------
38  * Port specific definitions.
39  *
40  * The settings in this file configure FreeRTOS correctly for the
41  * given hardware and compiler.
42  *
43  * These settings should not be altered.
44  *-----------------------------------------------------------
45  */
46 
47 /* Type definitions. */
48 #define portCHAR char
49 #define portFLOAT float
50 #define portDOUBLE double
51 #define portLONG long
52 #define portSHORT short
53 #define portSTACK_TYPE uint32_t
54 #define portBASE_TYPE long
55 
57 typedef long BaseType_t;
58 typedef unsigned long UBaseType_t;
59 
60 #if( configUSE_16_BIT_TICKS == 1 )
61 typedef uint16_t TickType_t;
62 #define portMAX_DELAY ( TickType_t ) 0xffff
63 #else
64 typedef uint32_t TickType_t;
65 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
66 
67 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
68 not need to be guarded with a critical section. */
69 #define portTICK_TYPE_IS_ATOMIC 1
70 #endif
71 /*-----------------------------------------------------------*/
72 
73 /* Architecture specifics. */
74 #define portSTACK_GROWTH ( -1 )
75 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
76 #define portBYTE_ALIGNMENT 8
77 
78 /* Constants used with memory barrier intrinsics. */
79 #define portSY_FULL_READ_WRITE ( 15 )
80 
81 /*-----------------------------------------------------------*/
82 
83 /* Scheduler utilities. */
84 #define portYIELD() \
85 { \
86  /* Set a PendSV to request a context switch. */ \
87  portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT; \
88  \
89  /* Barriers are normally not required but do ensure the code is completely \
90  within the specified behaviour for the architecture. */ \
91  __dsb( portSY_FULL_READ_WRITE ); \
92  __isb( portSY_FULL_READ_WRITE ); \
93 }
94 /*-----------------------------------------------------------*/
95 
96 #define portNVIC_INT_CTRL_REG ( * ( ( volatile uint32_t * ) 0xe000ed04 ) )
97 #define portNVIC_PENDSVSET_BIT ( 1UL << 28UL )
98 #define portEND_SWITCHING_ISR( xSwitchRequired ) if( xSwitchRequired != pdFALSE ) portYIELD()
99 #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
100 /*-----------------------------------------------------------*/
101 
102 /* Critical section management. */
103 extern void vPortEnterCritical( void );
104 extern void vPortExitCritical( void );
105 
106 #define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI()
107 #define portENABLE_INTERRUPTS() vPortSetBASEPRI( 0 )
108 #define portENTER_CRITICAL() vPortEnterCritical()
109 #define portEXIT_CRITICAL() vPortExitCritical()
110 #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
111 #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x)
112 
113 /*-----------------------------------------------------------*/
114 
115 /* Tickless idle/low power functionality. */
116 #ifndef portSUPPRESS_TICKS_AND_SLEEP
117 extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );
118 #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime )
119 #endif
120 /*-----------------------------------------------------------*/
121 
122 /* Port specific optimisations. */
123 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
124 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
125 #endif
126 
127 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
128 
129 /* Check the configuration. */
130 #if( configMAX_PRIORITIES > 32 )
131 #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.
132 #endif
133 
134 /* Store/clear the ready priorities in a bit map. */
135 #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
136 #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
137 
138 /*-----------------------------------------------------------*/
139 
140 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - ( uint32_t ) __clz( ( uxReadyPriorities ) ) )
141 
142 #endif /* taskRECORD_READY_PRIORITY */
143 /*-----------------------------------------------------------*/
144 
145 /* Task function macros as described on the FreeRTOS.org WEB site. These are
146 not necessary for to use this port. They are defined so the common demo files
147 (which build with all the ports) will build. */
148 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
149 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
150 /*-----------------------------------------------------------*/
151 
152 #ifdef configASSERT
153 void vPortValidateInterruptPriority( void );
154 #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
155 #endif
156 
157 /* portNOP() is not required by this port. */
158 #define portNOP()
159 
160 #define portINLINE __inline
161 
162 #ifndef portFORCE_INLINE
163 #define portFORCE_INLINE __forceinline
164 #endif
165 
166 /*-----------------------------------------------------------*/
167 
168 static portFORCE_INLINE void vPortSetBASEPRI( uint32_t ulBASEPRI )
169 {
170  __asm
171  {
172  /* Barrier instructions are not used as this function is only used to
173  lower the BASEPRI value. */
174  msr basepri, ulBASEPRI
175  }
176 }
177 /*-----------------------------------------------------------*/
178 
179 static portFORCE_INLINE void vPortRaiseBASEPRI( void )
180 {
181  uint32_t ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;
182 
183  __asm
184  {
185  /* Set BASEPRI to the max syscall priority to effect a critical
186  section. */
187  msr basepri, ulNewBASEPRI
188  dsb
189  isb
190  }
191 }
192 /*-----------------------------------------------------------*/
193 
194 static portFORCE_INLINE void vPortClearBASEPRIFromISR( void )
195 {
196  __asm
197  {
198  /* Set BASEPRI to 0 so no interrupts are masked. This function is only
199  used to lower the mask in an interrupt, so memory barriers are not
200  used. */
201  msr basepri, #0
202  }
203 }
204 /*-----------------------------------------------------------*/
205 
206 static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI( void )
207 {
208  uint32_t ulReturn, ulNewBASEPRI = configMAX_SYSCALL_INTERRUPT_PRIORITY;
209 
210  __asm
211  {
212  /* Set BASEPRI to the max syscall priority to effect a critical
213  section. */
214  mrs ulReturn, basepri
215  msr basepri, ulNewBASEPRI
216  dsb
217  isb
218  }
219 
220  return ulReturn;
221 }
222 /*-----------------------------------------------------------*/
223 
225 {
226  uint32_t ulCurrentInterrupt;
227  BaseType_t xReturn;
228 
229  /* Obtain the number of the currently executing interrupt. */
230  __asm
231  {
232  mrs ulCurrentInterrupt, ipsr
233  }
234 
235  if( ulCurrentInterrupt == 0 )
236  {
237  xReturn = pdFALSE;
238  }
239  else
240  {
241  xReturn = pdTRUE;
242  }
243 
244  return xReturn;
245 }
246 
247 
248 #ifdef __cplusplus
249 }
250 #endif
251 
252 #endif /* PORTMACRO_H */
253 
portFORCE_INLINE
#define portFORCE_INLINE
Definition: portmacro.h:162
vPortRaiseBASEPRI
static portFORCE_INLINE void vPortRaiseBASEPRI(void)
Definition: portmacro.h:178
vPortClearBASEPRIFromISR
static portFORCE_INLINE void vPortClearBASEPRIFromISR(void)
Definition: portmacro.h:193
vPortExitCritical
void vPortExitCritical(void)
Definition: port.c:364
xPortIsInsideInterrupt
static portFORCE_INLINE BaseType_t xPortIsInsideInterrupt(void)
Definition: portmacro.h:223
vPortSuppressTicksAndSleep
void vPortSuppressTicksAndSleep(TickType_t xExpectedIdleTime)
TickType_t
uint32_t TickType_t
Definition: portmacro.h:64
pdFALSE
#define pdFALSE
Definition: projdefs.h:45
UBaseType_t
unsigned long UBaseType_t
Definition: portmacro.h:58
configMAX_SYSCALL_INTERRUPT_PRIORITY
#define configMAX_SYSCALL_INTERRUPT_PRIORITY
Definition: FreeRTOSConfig.h:24
portSTACK_TYPE
#define portSTACK_TYPE
Definition: portmacro.h:53
StackType_t
portSTACK_TYPE StackType_t
Definition: portmacro.h:56
BaseType_t
long BaseType_t
Definition: portmacro.h:57
pdTRUE
#define pdTRUE
Definition: projdefs.h:46
ulPortRaiseBASEPRI
static portFORCE_INLINE uint32_t ulPortRaiseBASEPRI(void)
Definition: portmacro.h:205
vPortEnterCritical
void vPortEnterCritical(void)
Definition: port.c:347
vPortSetBASEPRI
static portFORCE_INLINE void vPortSetBASEPRI(uint32_t ulBASEPRI)
Definition: portmacro.h:167