]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/MPLAB/PIC32MX/portmacro.h
Update version number.
[freertos] / FreeRTOS / Source / portable / MPLAB / PIC32MX / portmacro.h
1 /*\r
2     FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 #ifndef PORTMACRO_H\r
66 #define PORTMACRO_H\r
67 \r
68 /* System include files */\r
69 #include <xc.h>\r
70 \r
71 #ifdef __cplusplus\r
72 extern "C" {\r
73 #endif\r
74 \r
75 /*-----------------------------------------------------------\r
76  * Port specific definitions.  \r
77  *\r
78  * The settings in this file configure FreeRTOS correctly for the\r
79  * given hardware and compiler.\r
80  *\r
81  * These settings should not be altered.\r
82  *-----------------------------------------------------------\r
83  */\r
84 \r
85 /* Type definitions. */\r
86 #define portCHAR                char\r
87 #define portFLOAT               float\r
88 #define portDOUBLE              double\r
89 #define portLONG                long\r
90 #define portSHORT               short\r
91 #define portSTACK_TYPE  unsigned long\r
92 #define portBASE_TYPE   long\r
93 \r
94 #if( configUSE_16_BIT_TICKS == 1 )\r
95         typedef unsigned portSHORT portTickType;\r
96         #define portMAX_DELAY ( portTickType ) 0xffff\r
97 #else\r
98         typedef unsigned long portTickType;\r
99         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
100 #endif\r
101 /*-----------------------------------------------------------*/\r
102 \r
103 /* Hardware specifics. */\r
104 #define portBYTE_ALIGNMENT                      8\r
105 #define portSTACK_GROWTH                        -1\r
106 #define portTICK_RATE_MS                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )          \r
107 /*-----------------------------------------------------------*/\r
108 \r
109 /* Critical section management. */\r
110 #define portIPL_SHIFT                           ( 10UL )\r
111 #define portALL_IPL_BITS                        ( 0x3fUL << portIPL_SHIFT )\r
112 #define portSW0_BIT                                     ( 0x01 << 8 )\r
113 \r
114 /* This clears the IPL bits, then sets them to \r
115 configMAX_SYSCALL_INTERRUPT_PRIORITY.   An extra check is performed if \r
116 configASSERT() is defined to ensure an assertion handler does not inadvertently \r
117 attempt to lower the IPL when the call to assert was triggered because the IPL \r
118 value was found to be above     configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR\r
119 safe FreeRTOS API function was executed.  ISR safe FreeRTOS API functions are\r
120 those that end in FromISR.  FreeRTOS maintains a separate interrupt API to\r
121 ensure API function and interrupt entry is as fast and as simple as possible. */\r
122 #ifdef configASSERT\r
123         #define portDISABLE_INTERRUPTS()                                                                                        \\r
124         {                                                                                                                                                       \\r
125         unsigned long ulStatus;                                                                                                         \\r
126                                                                                                                                                                 \\r
127                 /* Mask interrupts at and below the kernel interrupt priority. */               \\r
128                 ulStatus = _CP0_GET_STATUS();                                                                                   \\r
129                                                                                                                                                                 \\r
130                 /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */    \\r
131                 if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY )       \\r
132                 {                                                                                                                                               \\r
133                         ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
134                         _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \\r
135                 }                                                                                                                                               \\r
136         }\r
137 #else /* configASSERT */\r
138         #define portDISABLE_INTERRUPTS()                                                                                \\r
139         {                                                                                                                                               \\r
140         unsigned long ulStatus;                                                                                                 \\r
141                                                                                                                                                         \\r
142                 /* Mask interrupts at and below the kernel interrupt priority. */       \\r
143                 ulStatus = _CP0_GET_STATUS();                                                                           \\r
144                 ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
145                 _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \\r
146         }\r
147 #endif /* configASSERT */\r
148 \r
149 #define portENABLE_INTERRUPTS()                                                                                 \\r
150 {                                                                                                                                               \\r
151 unsigned long ulStatus;                                                                                                 \\r
152                                                                                                                                                 \\r
153         /* Unmask all interrupts. */                                                                            \\r
154         ulStatus = _CP0_GET_STATUS();                                                                           \\r
155         ulStatus &= ~portALL_IPL_BITS;                                                                          \\r
156         _CP0_SET_STATUS( ulStatus );                                                                            \\r
157 }\r
158 \r
159 \r
160 extern void vTaskEnterCritical( void );\r
161 extern void vTaskExitCritical( void );\r
162 #define portCRITICAL_NESTING_IN_TCB     1\r
163 #define portENTER_CRITICAL()            vTaskEnterCritical()\r
164 #define portEXIT_CRITICAL()                     vTaskExitCritical()\r
165 \r
166 extern unsigned portBASE_TYPE uxPortSetInterruptMaskFromISR();\r
167 extern void vPortClearInterruptMaskFromISR( unsigned portBASE_TYPE );\r
168 #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()\r
169 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) vPortClearInterruptMaskFromISR( uxSavedStatusRegister )\r
170 \r
171 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
172 \r
173         /* Check the configuration. */\r
174         #if( configMAX_PRIORITIES > 32 )\r
175                 #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
176         #endif\r
177 \r
178         /* Store/clear the ready priorities in a bit map. */\r
179         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
180         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
181 \r
182         /*-----------------------------------------------------------*/\r
183 \r
184         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - _clz( ( uxReadyPriorities ) ) )\r
185 \r
186 #endif /* taskRECORD_READY_PRIORITY */\r
187 \r
188 /*-----------------------------------------------------------*/\r
189 \r
190 /* Task utilities. */\r
191 \r
192 #define portYIELD()                                                             \\r
193 {                                                                                               \\r
194 unsigned long ulCause;                                                  \\r
195                                                                                                 \\r
196         /* Trigger software interrupt. */                       \\r
197         ulCause = _CP0_GET_CAUSE();                                     \\r
198         ulCause |= portSW0_BIT;                                         \\r
199         _CP0_SET_CAUSE( ulCause );                                      \\r
200 }\r
201 \r
202 #ifdef configASSERT\r
203         #define portCURRENT_INTERRUPT_PRIORITY ( ( _CP0_GET_STATUS() & portALL_IPL_BITS ) >> portIPL_SHIFT )\r
204         #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() configASSERT( portCURRENT_INTERRUPT_PRIORITY <= configMAX_SYSCALL_INTERRUPT_PRIORITY )\r
205 #endif /* configASSERT */\r
206 \r
207 \r
208 #define portNOP()       asm volatile (  "nop" )\r
209 \r
210 /*-----------------------------------------------------------*/\r
211 \r
212 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
213 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))\r
214 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
215 /*-----------------------------------------------------------*/\r
216 \r
217 #define portEND_SWITCHING_ISR( xSwitchRequired )        if( xSwitchRequired )   \\r
218                                                                                                         {                                               \\r
219                                                                                                                 portYIELD();            \\r
220                                                                                                         }\r
221 \r
222 /* Required by the kernel aware debugger. */\r
223 #ifdef __DEBUG\r
224         #define portREMOVE_STATIC_QUALIFIER\r
225 #endif\r
226 \r
227 #ifdef __cplusplus\r
228 }\r
229 #endif\r
230 \r
231 #endif /* PORTMACRO_H */\r
232 \r