]> begriffs open source - cmsis-freertos/blob - Source/portable/MSVC-MingW/portmacro.h
Update cmsis_os2.c
[cmsis-freertos] / Source / portable / MSVC-MingW / portmacro.h
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 #ifndef PORTMACRO_H
71 #define PORTMACRO_H
72
73 #include <Windows.h>
74
75 /******************************************************************************
76         Defines
77 ******************************************************************************/
78 /* Type definitions. */
79 #define portCHAR                char
80 #define portFLOAT               float
81 #define portDOUBLE              double
82 #define portLONG                long
83 #define portSHORT               short
84 #define portSTACK_TYPE  size_t
85 #define portBASE_TYPE   long
86 #define portPOINTER_SIZE_TYPE size_t
87
88 typedef portSTACK_TYPE StackType_t;
89 typedef long BaseType_t;
90 typedef unsigned long UBaseType_t;
91
92
93 #if( configUSE_16_BIT_TICKS == 1 )
94     typedef uint16_t TickType_t;
95     #define portMAX_DELAY ( TickType_t ) 0xffff
96 #else
97     typedef uint32_t TickType_t;
98     #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
99
100         /* 32/64-bit tick type on a 32/64-bit architecture, so reads of the tick
101         count do not need to be guarded with a critical section. */
102         #define portTICK_TYPE_IS_ATOMIC 1
103 #endif
104
105 /* Hardware specifics. */
106 #define portSTACK_GROWTH                        ( -1 )
107 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
108 #define portINLINE __inline
109
110 #if defined( __x86_64__) || defined( _M_X64 )
111         #define portBYTE_ALIGNMENT              8
112 #else
113         #define portBYTE_ALIGNMENT              4
114 #endif
115
116 #define portYIELD()                                     vPortGenerateSimulatedInterrupt( portINTERRUPT_YIELD )
117
118 /* Simulated interrupts return pdFALSE if no context switch should be performed,
119 or a non-zero number if a context switch should be performed. */
120 #define portYIELD_FROM_ISR( x ) return x
121 #define portEND_SWITCHING_ISR( x ) portYIELD_FROM_ISR( ( x ) )
122
123 void vPortCloseRunningThread( void *pvTaskToDelete, volatile BaseType_t *pxPendYield );
124 void vPortDeleteThread( void *pvThreadToDelete );
125 #define portCLEAN_UP_TCB( pxTCB )       vPortDeleteThread( pxTCB )
126 #define portPRE_TASK_DELETE_HOOK( pvTaskToDelete, pxPendYield ) vPortCloseRunningThread( ( pvTaskToDelete ), ( pxPendYield ) )
127 #define portDISABLE_INTERRUPTS() vPortEnterCritical()
128 #define portENABLE_INTERRUPTS() vPortExitCritical()
129
130 /* Critical section handling. */
131 void vPortEnterCritical( void );
132 void vPortExitCritical( void );
133
134 #define portENTER_CRITICAL()            vPortEnterCritical()
135 #define portEXIT_CRITICAL()                     vPortExitCritical()
136
137 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
138         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
139 #endif
140
141 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
142
143         /* Check the configuration. */
144         #if( configMAX_PRIORITIES > 32 )
145                 #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.
146         #endif
147
148         /* Store/clear the ready priorities in a bit map. */
149         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
150         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
151
152
153         /*-----------------------------------------------------------*/
154
155         #ifdef __GNUC__
156                 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities )    \
157                         __asm volatile( "bsr %1, %0\n\t"                                                                        \
158                                                         :"=r"(uxTopPriority) : "rm"(uxReadyPriorities) : "cc" )
159         #else
160                 /* BitScanReverse returns the bit position of the most significant '1'
161                 in the word. */
162                 #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) _BitScanReverse( ( DWORD * ) &( uxTopPriority ), ( uxReadyPriorities ) )
163         #endif /* __GNUC__ */
164
165 #endif /* taskRECORD_READY_PRIORITY */
166
167 #ifndef __GNUC__
168         __pragma( warning( disable:4211 ) ) /* Nonstandard extension used, as extern is only nonstandard to MSVC. */
169 #endif
170
171
172 /* Task function macros as described on the FreeRTOS.org WEB site. */
173 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
174 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
175
176 #define portINTERRUPT_YIELD                             ( 0UL )
177 #define portINTERRUPT_TICK                              ( 1UL )
178
179 /*
180  * Raise a simulated interrupt represented by the bit mask in ulInterruptMask.
181  * Each bit can be used to represent an individual interrupt - with the first
182  * two bits being used for the Yield and Tick interrupts respectively.
183 */
184 void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber );
185
186 /*
187  * Install an interrupt handler to be called by the simulated interrupt handler
188  * thread.  The interrupt number must be above any used by the kernel itself
189  * (at the time of writing the kernel was using interrupt numbers 0, 1, and 2
190  * as defined above).  The number must also be lower than 32.
191  *
192  * Interrupt handler functions must return a non-zero value if executing the
193  * handler resulted in a task switch being required.
194  */
195 void vPortSetInterruptHandler( uint32_t ulInterruptNumber, uint32_t (*pvHandler)( void ) );
196
197 #endif
198