]> begriffs open source - freertos/blob - portable/MSVC-MingW/portmacro.h
RP2040: Fix compiler warning and comment (#509)
[freertos] / portable / MSVC-MingW / portmacro.h
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 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.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 #ifndef PORTMACRO_H
29 #define PORTMACRO_H
30
31 #include <windows.h>
32 #include <winbase.h>
33
34 /******************************************************************************
35         Defines
36 ******************************************************************************/
37 /* Type definitions. */
38 #define portCHAR                char
39 #define portFLOAT               float
40 #define portDOUBLE              double
41 #define portLONG                long
42 #define portSHORT               short
43 #define portSTACK_TYPE  size_t
44 #define portBASE_TYPE   long
45 #define portPOINTER_SIZE_TYPE size_t
46
47 typedef portSTACK_TYPE StackType_t;
48 typedef long BaseType_t;
49 typedef unsigned long UBaseType_t;
50
51
52 #if( configUSE_16_BIT_TICKS == 1 )
53     typedef uint16_t TickType_t;
54     #define portMAX_DELAY ( TickType_t ) 0xffff
55 #else
56     typedef uint32_t TickType_t;
57     #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
58
59         /* 32/64-bit tick type on a 32/64-bit architecture, so reads of the tick
60         count do not need to be guarded with a critical section. */
61         #define portTICK_TYPE_IS_ATOMIC 1
62 #endif
63
64 /* Hardware specifics. */
65 #define portSTACK_GROWTH                        ( -1 )
66 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
67 #define portINLINE __inline
68
69 #if defined( __x86_64__) || defined( _M_X64 )
70         #define portBYTE_ALIGNMENT              8
71 #else
72         #define portBYTE_ALIGNMENT              4
73 #endif
74
75 #define portYIELD()                                     vPortGenerateSimulatedInterrupt( portINTERRUPT_YIELD )
76
77
78 extern volatile BaseType_t xInsideInterrupt;
79 #define portSOFTWARE_BARRIER() while( xInsideInterrupt != pdFALSE )
80
81
82 /* Simulated interrupts return pdFALSE if no context switch should be performed,
83 or a non-zero number if a context switch should be performed. */
84 #define portYIELD_FROM_ISR( x ) ( void ) x
85 #define portEND_SWITCHING_ISR( x ) portYIELD_FROM_ISR( ( x ) )
86
87 void vPortCloseRunningThread( void *pvTaskToDelete, volatile BaseType_t *pxPendYield );
88 void vPortDeleteThread( void *pvThreadToDelete );
89 #define portCLEAN_UP_TCB( pxTCB )       vPortDeleteThread( pxTCB )
90 #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) )
91 #define portDISABLE_INTERRUPTS() vPortEnterCritical()
92 #define portENABLE_INTERRUPTS() vPortExitCritical()
93
94 /* Critical section handling. */
95 void vPortEnterCritical( void );
96 void vPortExitCritical( void );
97
98 #define portENTER_CRITICAL()            vPortEnterCritical()
99 #define portEXIT_CRITICAL()                     vPortExitCritical()
100
101 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
102         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
103 #endif
104
105 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
106
107         /* Check the configuration. */
108         #if( configMAX_PRIORITIES > 32 )
109                 #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.
110         #endif
111
112         /* Store/clear the ready priorities in a bit map. */
113         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
114         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
115
116
117         /*-----------------------------------------------------------*/
118
119         #ifdef __GNUC__
120                 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    \
121                         __asm volatile( "bsr %1, %0\n\t"                                                                        \
122                                                         :"=r"(uxTopPriority) : "rm"(uxReadyPriorities) : "cc" )
123         #else
124                 /* BitScanReverse returns the bit position of the most significant '1'
125                 in the word. */
126                 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) )
127         #endif /* __GNUC__ */
128
129 #endif /* taskRECORD_READY_PRIORITY */
130
131 #ifndef __GNUC__
132         __pragma( warning( disable:4211 ) ) /* Nonstandard extension used, as extern is only nonstandard to MSVC. */
133 #endif
134
135
136 /* Task function macros as described on the FreeRTOS.org WEB site. */
137 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
138 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
139
140 #define portINTERRUPT_YIELD                             ( 0UL )
141 #define portINTERRUPT_TICK                              ( 1UL )
142
143 /*
144  * Raise a simulated interrupt represented by the bit mask in ulInterruptMask.
145  * Each bit can be used to represent an individual interrupt - with the first
146  * two bits being used for the Yield and Tick interrupts respectively.
147 */
148 void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber );
149
150 /*
151  * Install an interrupt handler to be called by the simulated interrupt handler
152  * thread.  The interrupt number must be above any used by the kernel itself
153  * (at the time of writing the kernel was using interrupt numbers 0, 1, and 2
154  * as defined above).  The number must also be lower than 32.
155  *
156  * Interrupt handler functions must return a non-zero value if executing the
157  * handler resulted in a task switch being required.
158  */
159 void vPortSetInterruptHandler( uint32_t ulInterruptNumber, uint32_t (*pvHandler)( void ) );
160
161 #endif
162