]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Source / portable / MPLAB / PIC32MX / portmacro.h
1 /*\r
2     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
14     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
15     >>!   obliged to provide the source code for proprietary components     !<<\r
16     >>!   outside of the FreeRTOS kernel.                                   !<<\r
17 \r
18     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
19     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
20     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
21     link: http://www.freertos.org/a00114.html\r
22 \r
23     1 tab == 4 spaces!\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    Having a problem?  Start by reading the FAQ "My application does   *\r
28      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
29      *                                                                       *\r
30      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
31      *                                                                       *\r
32     ***************************************************************************\r
33 \r
34     ***************************************************************************\r
35      *                                                                       *\r
36      *    FreeRTOS provides completely free yet professionally developed,    *\r
37      *    robust, strictly quality controlled, supported, and cross          *\r
38      *    platform software that is more than just the market leader, it     *\r
39      *    is the industry's de facto standard.                               *\r
40      *                                                                       *\r
41      *    Help yourself get started quickly while simultaneously helping     *\r
42      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
43      *    tutorial book, reference manual, or both:                          *\r
44      *    http://www.FreeRTOS.org/Documentation                              *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     ***************************************************************************\r
49      *                                                                       *\r
50      *   Investing in training allows your team to be as productive as       *\r
51      *   possible as early as possible, lowering your overall development    *\r
52      *   cost, and enabling you to bring a more robust product to market     *\r
53      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
54      *   the architect and key author of FreeRTOS, and so also the world's   *\r
55      *   leading authority on what is the world's most popular real time     *\r
56      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
57      *   from Richard ensures your team will gain directly from his in-depth *\r
58      *   product knowledge and years of usage experience.  Contact Real Time *\r
59      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
60      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
61      *                                                                       *\r
62     ***************************************************************************\r
63 \r
64     ***************************************************************************\r
65      *                                                                       *\r
66      *    You are receiving this top quality software for free.  Please play *\r
67      *    fair and reciprocate by reporting any suspected issues and         *\r
68      *    participating in the community forum:                              *\r
69      *    http://www.FreeRTOS.org/support                                    *\r
70      *                                                                       *\r
71      *    Thank you!                                                         *\r
72      *                                                                       *\r
73     ***************************************************************************\r
74 \r
75     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
76     license and Real Time Engineers Ltd. contact details.\r
77 \r
78     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
79     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
80     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
81 \r
82     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
83     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
84 \r
85     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
86     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
87     licenses offer ticketed support, indemnification and commercial middleware.\r
88 \r
89     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
90     engineered and independently SIL3 certified version for use in safety and\r
91     mission critical applications that require provable dependability.\r
92 \r
93     1 tab == 4 spaces!\r
94 */\r
95 \r
96 #ifndef PORTMACRO_H\r
97 #define PORTMACRO_H\r
98 \r
99 /* System include files */\r
100 #include <xc.h>\r
101 \r
102 #ifdef __cplusplus\r
103 extern "C" {\r
104 #endif\r
105 \r
106 /*-----------------------------------------------------------\r
107  * Port specific definitions.\r
108  *\r
109  * The settings in this file configure FreeRTOS correctly for the\r
110  * given hardware and compiler.\r
111  *\r
112  * These settings should not be altered.\r
113  *-----------------------------------------------------------\r
114  */\r
115 \r
116 /* Type definitions. */\r
117 #define portCHAR                char\r
118 #define portFLOAT               float\r
119 #define portDOUBLE              double\r
120 #define portLONG                long\r
121 #define portSHORT               short\r
122 #define portSTACK_TYPE  uint32_t\r
123 #define portBASE_TYPE   long\r
124 \r
125 typedef portSTACK_TYPE StackType_t;\r
126 typedef long BaseType_t;\r
127 typedef unsigned long UBaseType_t;\r
128 \r
129 #if( configUSE_16_BIT_TICKS == 1 )\r
130         typedef uint16_t TickType_t;\r
131         #define portMAX_DELAY ( TickType_t ) 0xffff\r
132 #else\r
133         typedef uint32_t TickType_t;\r
134         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
135 \r
136         /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do\r
137         not need to be guarded with a critical section. */\r
138         #define portTICK_TYPE_IS_ATOMIC 1\r
139 #endif\r
140 /*-----------------------------------------------------------*/\r
141 \r
142 /* Hardware specifics. */\r
143 #define portBYTE_ALIGNMENT                      8\r
144 #define portSTACK_GROWTH                        -1\r
145 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
146 /*-----------------------------------------------------------*/\r
147 \r
148 /* Critical section management. */\r
149 #define portIPL_SHIFT                           ( 10UL )\r
150 #define portALL_IPL_BITS                        ( 0x3fUL << portIPL_SHIFT )\r
151 #define portSW0_BIT                                     ( 0x01 << 8 )\r
152 \r
153 /* This clears the IPL bits, then sets them to\r
154 configMAX_SYSCALL_INTERRUPT_PRIORITY.  An extra check is performed if\r
155 configASSERT() is defined to ensure an assertion handler does not inadvertently\r
156 attempt to lower the IPL when the call to assert was triggered because the IPL\r
157 value was found to be above configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR\r
158 safe FreeRTOS API function was executed.  ISR safe FreeRTOS API functions are\r
159 those that end in FromISR.  FreeRTOS maintains a separate interrupt API to\r
160 ensure API function and interrupt entry is as fast and as simple as possible. */\r
161 #ifdef configASSERT\r
162         #define portDISABLE_INTERRUPTS()                                                                                        \\r
163         {                                                                                                                                                       \\r
164         uint32_t ulStatus;                                                                                                              \\r
165                                                                                                                                                                 \\r
166                 /* Mask interrupts at and below the kernel interrupt priority. */               \\r
167                 ulStatus = _CP0_GET_STATUS();                                                                                   \\r
168                                                                                                                                                                 \\r
169                 /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */    \\r
170                 if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY ) \\r
171                 {                                                                                                                                               \\r
172                         ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
173                         _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \\r
174                 }                                                                                                                                               \\r
175         }\r
176 #else /* configASSERT */\r
177         #define portDISABLE_INTERRUPTS()                                                                                \\r
178         {                                                                                                                                               \\r
179         uint32_t ulStatus;                                                                                                      \\r
180                                                                                                                                                         \\r
181                 /* Mask interrupts at and below the kernel interrupt priority. */       \\r
182                 ulStatus = _CP0_GET_STATUS();                                                                           \\r
183                 ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
184                 _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \\r
185         }\r
186 #endif /* configASSERT */\r
187 \r
188 #define portENABLE_INTERRUPTS()                                                                                 \\r
189 {                                                                                                                                               \\r
190 uint32_t ulStatus;                                                                                                      \\r
191                                                                                                                                                 \\r
192         /* Unmask all interrupts. */                                                                            \\r
193         ulStatus = _CP0_GET_STATUS();                                                                           \\r
194         ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
195         _CP0_SET_STATUS( ulStatus );                                                                            \\r
196 }\r
197 \r
198 \r
199 extern void vTaskEnterCritical( void );\r
200 extern void vTaskExitCritical( void );\r
201 #define portCRITICAL_NESTING_IN_TCB     1\r
202 #define portENTER_CRITICAL()            vTaskEnterCritical()\r
203 #define portEXIT_CRITICAL()                     vTaskExitCritical()\r
204 \r
205 extern UBaseType_t uxPortSetInterruptMaskFromISR();\r
206 extern void vPortClearInterruptMaskFromISR( UBaseType_t );\r
207 #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()\r
208 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) vPortClearInterruptMaskFromISR( uxSavedStatusRegister )\r
209 \r
210 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
211         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\r
212 #endif\r
213 \r
214 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
215 \r
216         /* Check the configuration. */\r
217         #if( configMAX_PRIORITIES > 32 )\r
218                 #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
219         #endif\r
220 \r
221         /* Store/clear the ready priorities in a bit map. */\r
222         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
223         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
224 \r
225         /*-----------------------------------------------------------*/\r
226 \r
227         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - _clz( ( uxReadyPriorities ) ) )\r
228 \r
229 #endif /* taskRECORD_READY_PRIORITY */\r
230 \r
231 /*-----------------------------------------------------------*/\r
232 \r
233 /* Task utilities. */\r
234 \r
235 #define portYIELD()                                                             \\r
236 {                                                                                               \\r
237 uint32_t ulCause;                                                       \\r
238                                                                                                 \\r
239         /* Trigger software interrupt. */                       \\r
240         ulCause = _CP0_GET_CAUSE();                                     \\r
241         ulCause |= portSW0_BIT;                                         \\r
242         _CP0_SET_CAUSE( ulCause );                                      \\r
243 }\r
244 \r
245 extern volatile UBaseType_t uxInterruptNesting;\r
246 #define portASSERT_IF_IN_ISR() configASSERT( uxInterruptNesting == 0 )\r
247 \r
248 #define portNOP()       __asm volatile ( "nop" )\r
249 \r
250 /*-----------------------------------------------------------*/\r
251 \r
252 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
253 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))\r
254 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
255 /*-----------------------------------------------------------*/\r
256 \r
257 #define portEND_SWITCHING_ISR( xSwitchRequired )        if( xSwitchRequired )   \\r
258                                                                                                         {                                               \\r
259                                                                                                                 portYIELD();            \\r
260                                                                                                         }\r
261 \r
262 /* Required by the kernel aware debugger. */\r
263 #ifdef __DEBUG\r
264         #define portREMOVE_STATIC_QUALIFIER\r
265 #endif\r
266 \r
267 #ifdef __cplusplus\r
268 }\r
269 #endif\r
270 \r
271 #endif /* PORTMACRO_H */\r
272 \r