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