2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
32 #ifdef WIN32_LEAN_AND_MEAN
43 /******************************************************************************
45 ******************************************************************************/
46 /* Type definitions. */
48 #define portFLOAT float
49 #define portDOUBLE double
51 #define portSHORT short
52 #define portSTACK_TYPE size_t
53 #define portPOINTER_SIZE_TYPE size_t
55 typedef portSTACK_TYPE StackType_t;
57 #if defined( __x86_64__ ) || defined( _M_X64 )
58 #define portBASE_TYPE long long
59 typedef long long BaseType_t;
60 typedef unsigned long long UBaseType_t;
62 #define portBASE_TYPE long
63 typedef long BaseType_t;
64 typedef unsigned long UBaseType_t;
68 #if ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
69 typedef uint16_t TickType_t;
70 #define portMAX_DELAY ( TickType_t ) 0xffff
71 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
72 typedef uint32_t TickType_t;
73 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
75 /* 32-bit tick type on a 32/64-bit architecture, so reads of the tick
76 * count do not need to be guarded with a critical section. */
77 #define portTICK_TYPE_IS_ATOMIC 1
78 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_64_BITS )
79 typedef uint64_t TickType_t;
80 #define portMAX_DELAY ( TickType_t ) 0xffffffffffffffffULL
82 #if defined( __x86_64__ ) || defined( _M_X64 )
83 /* 64-bit tick type on a 64-bit architecture, so reads of the tick
84 * count do not need to be guarded with a critical section. */
85 #define portTICK_TYPE_IS_ATOMIC 1
88 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
91 /* Hardware specifics. */
92 #define portSTACK_GROWTH ( -1 )
93 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
94 #define portINLINE __inline
96 #if defined( __x86_64__ ) || defined( _M_X64 )
97 #define portBYTE_ALIGNMENT 8
99 #define portBYTE_ALIGNMENT 4
102 #define portYIELD() vPortGenerateSimulatedInterrupt( portINTERRUPT_YIELD )
105 extern volatile BaseType_t xInsideInterrupt;
106 #define portSOFTWARE_BARRIER() while( xInsideInterrupt != pdFALSE )
109 /* Simulated interrupts return pdFALSE if no context switch should be performed,
110 * or a non-zero number if a context switch should be performed. */
111 #define portYIELD_FROM_ISR( x ) ( void ) x
112 #define portEND_SWITCHING_ISR( x ) portYIELD_FROM_ISR( ( x ) )
114 void vPortCloseRunningThread( void * pvTaskToDelete,
115 volatile BaseType_t * pxPendYield );
116 void vPortDeleteThread( void * pvThreadToDelete );
117 #define portCLEAN_UP_TCB( pxTCB ) vPortDeleteThread( pxTCB )
118 #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) )
119 #define portDISABLE_INTERRUPTS() vPortEnterCritical()
120 #define portENABLE_INTERRUPTS() vPortExitCritical()
122 /* Critical section handling. */
123 void vPortEnterCritical( void );
124 void vPortExitCritical( void );
126 #define portENTER_CRITICAL() vPortEnterCritical()
127 #define portEXIT_CRITICAL() vPortExitCritical()
129 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
130 #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
133 /*-----------------------------------------------------------*/
135 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
137 /* Check the configuration. */
138 #if ( configMAX_PRIORITIES > 32 )
139 #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.
142 /* Store/clear the ready priorities in a bit map. */
143 #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( ( ( UBaseType_t ) 1 ) << ( uxPriority ) )
144 #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( ( ( UBaseType_t ) 1 ) << ( uxPriority ) )
148 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \
149 __asm volatile ( "bsr %1, %0\n\t" \
150 : "=r" ( uxTopPriority ) \
151 : "rm" ( uxReadyPriorities ) \
156 /* BitScanReverse returns the bit position of the most significant '1'
158 #if defined( __x86_64__ ) || defined( _M_X64 )
160 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) \
163 DWORD ulTopPriority; \
164 _BitScanReverse64( &ulTopPriority, ( uxReadyPriorities ) ); \
165 uxTopPriority = ulTopPriority; \
168 #else /* #if defined( __x86_64__ ) || defined( _M_X64 ) */
170 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) )
172 #endif /* #if defined( __x86_64__ ) || defined( _M_X64 ) */
174 #endif /* __GNUC__ */
176 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
179 __pragma( warning( disable:4211 ) ) /* Nonstandard extension used, as extern is only nonstandard to MSVC. */
183 /* Task function macros as described on the FreeRTOS.org WEB site. */
184 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
185 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
187 #define portINTERRUPT_YIELD ( 0UL )
188 #define portINTERRUPT_TICK ( 1UL )
191 * Raise a simulated interrupt represented by the bit mask in ulInterruptMask.
192 * Each bit can be used to represent an individual interrupt - with the first
193 * two bits being used for the Yield and Tick interrupts respectively.
195 void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber );
198 * Install an interrupt handler to be called by the simulated interrupt handler
199 * thread. The interrupt number must be above any used by the kernel itself
200 * (at the time of writing the kernel was using interrupt numbers 0, 1, and 2
201 * as defined above). The number must also be lower than 32.
203 * Interrupt handler functions must return a non-zero value if executing the
204 * handler resulted in a task switch being required.
206 void vPortSetInterruptHandler( uint32_t ulInterruptNumber,
207 uint32_t ( * pvHandler )( void ) );
209 #endif /* ifndef PORTMACRO_H */