]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/MPLAB/PIC32MEC14xx/portmacro.h
Update license information text files for the CLI, TCP and UDP products to be correct...
[freertos] / FreeRTOS / Source / portable / MPLAB / PIC32MEC14xx / portmacro.h
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 #ifndef PORTMACRO_H\r
30 #define PORTMACRO_H\r
31 \r
32 #ifdef __cplusplus\r
33 extern "C" {\r
34 #endif\r
35 \r
36 /*-----------------------------------------------------------\r
37  * Port specific definitions.\r
38  *\r
39  * The settings in this file configure FreeRTOS correctly for the\r
40  * given hardware and compiler.\r
41  *\r
42  * These settings should not be altered.\r
43  *-----------------------------------------------------------\r
44  */\r
45 \r
46 /* Type definitions. */\r
47 #define portCHAR        char\r
48 #define portFLOAT       float\r
49 #define portDOUBLE      double\r
50 #define portLONG        long\r
51 #define portSHORT       short\r
52 #define portSTACK_TYPE  uint32_t\r
53 #define portBASE_TYPE   long\r
54 \r
55 typedef portSTACK_TYPE StackType_t;\r
56 typedef long BaseType_t;\r
57 typedef unsigned long UBaseType_t;\r
58 \r
59 #if( configUSE_16_BIT_TICKS == 1 )\r
60         typedef uint16_t TickType_t;\r
61         #define portMAX_DELAY ( TickType_t ) 0xffff\r
62 #else\r
63         typedef uint32_t TickType_t;\r
64         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL\r
65 #endif\r
66 /*-----------------------------------------------------------*/\r
67 \r
68 /* Hardware specifics. */\r
69 #define portBYTE_ALIGNMENT  8\r
70 #define portSTACK_GROWTH    -1\r
71 #define portTICK_PERIOD_MS  ( ( TickType_t ) 1000 / configTICK_RATE_HZ )\r
72 /*-----------------------------------------------------------*/\r
73 \r
74 /* Critical section management. */\r
75 #define portIPL_SHIFT       ( 10UL )\r
76 /* Don't straddle the CEE bit.  Interrupts calling FreeRTOS functions should\r
77 never have higher IPL bits set anyway. */\r
78 #define portALL_IPL_BITS    ( 0x7FUL << portIPL_SHIFT )\r
79 #define portSW0_BIT         ( 0x01 << 8 )\r
80 \r
81 /* Interrupt priority conversion */\r
82 #define portIPL_TO_CODE( iplNumber )    ( ( iplNumber >> 1 ) & 0x03ul )\r
83 #define portCODE_TO_IPL( iplCode )      ( ( iplCode << 1 ) | 0x01ul )\r
84 \r
85 /*-----------------------------------------------------------*/\r
86 \r
87 static inline uint32_t ulPortGetCP0Status( void )\r
88 {\r
89 uint32_t rv;\r
90 \r
91         __asm volatile(\r
92                         "\n\t"\r
93                         "mfc0 %0,$12,0      \n\t"\r
94                         : "=r" ( rv ) :: );\r
95 \r
96         return rv;\r
97 }\r
98 /*-----------------------------------------------------------*/\r
99 \r
100 static inline void vPortSetCP0Status( uint32_t new_status)\r
101 {\r
102         ( void ) new_status;\r
103 \r
104         __asm__ __volatile__(\r
105                         "\n\t"\r
106                         "mtc0 %0,$12,0      \n\t"\r
107                         "ehb                \n\t"\r
108                         :\r
109                         :"r" ( new_status ) : );\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 static inline uint32_t ulPortGetCP0Cause( void )\r
114 {\r
115 uint32_t rv;\r
116 \r
117         __asm volatile(\r
118                         "\n\t"\r
119                         "mfc0 %0,$13,0      \n\t"\r
120                         : "=r" ( rv ) :: );\r
121 \r
122     return rv;\r
123 }\r
124 /*-----------------------------------------------------------*/\r
125 \r
126 static inline void vPortSetCP0Cause( uint32_t new_cause )\r
127 {\r
128         ( void ) new_cause;\r
129 \r
130         __asm__ __volatile__(\r
131                         "\n\t"\r
132                         "mtc0 %0,$13,0      \n\t"\r
133                         "ehb                \n\t"\r
134                         :\r
135                         :"r" ( new_cause ) : );\r
136 }\r
137 /*-----------------------------------------------------------*/\r
138 \r
139 /* This clears the IPL bits, then sets them to\r
140 configMAX_SYSCALL_INTERRUPT_PRIORITY.  An extra check is performed if\r
141 configASSERT() is defined to ensure an assertion handler does not inadvertently\r
142 attempt to lower the IPL when the call to assert was triggered because the IPL\r
143 value was found to be above configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR\r
144 safe FreeRTOS API function was executed.  ISR safe FreeRTOS API functions are\r
145 those that end in FromISR.  FreeRTOS maintains a separate interrupt API to\r
146 ensure API function and interrupt entry is as fast and as simple as possible. */\r
147 #ifdef configASSERT\r
148     #define portDISABLE_INTERRUPTS()                                                                                                                                                    \\r
149         {                                                                                                                                                                                                                       \\r
150         uint32_t ulStatus;                                                                                                                                                                                      \\r
151                 /* Mask interrupts at and below the kernel interrupt priority. */                                                                               \\r
152                 ulStatus = ulPortGetCP0Status();                                                                                                                                                \\r
153                 /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */                                                                    \\r
154                 if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY )               \\r
155                 {                                                                                                                                                                                                               \\r
156                         ulStatus &= ~portALL_IPL_BITS;                                                                                                                                          \\r
157                         vPortSetCP0Status( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) );          \\r
158                 }                                                                                                                                                                                                               \\r
159     }\r
160 #else /* configASSERT */\r
161         #define portDISABLE_INTERRUPTS()                                                                                                                                                        \\r
162         {                                                                                                                                                                                                                       \\r
163         uint32_t ulStatus;                                                                                                                                                                              \\r
164                 /* Mask interrupts at and below the kernel interrupt priority. */                                                                               \\r
165                 ulStatus = ulPortGetCP0Status();                                                                                                                                                \\r
166                 ulStatus &= ~portALL_IPL_BITS;                                                                                                                                                  \\r
167                 vPortSetCP0Status( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) );                  \\r
168         }\r
169 #endif /* configASSERT */\r
170 \r
171 #define portENABLE_INTERRUPTS()                         \\r
172 {                                                                                       \\r
173 uint32_t ulStatus;                                                      \\r
174         /* Unmask all interrupts. */                    \\r
175         ulStatus = ulPortGetCP0Status();                \\r
176         ulStatus &= ~portALL_IPL_BITS;                  \\r
177         vPortSetCP0Status( ulStatus );                  \\r
178 }\r
179 \r
180 \r
181 extern void vTaskEnterCritical( void );\r
182 extern void vTaskExitCritical( void );\r
183 #define portCRITICAL_NESTING_IN_TCB     1\r
184 #define portENTER_CRITICAL()            vTaskEnterCritical()\r
185 #define portEXIT_CRITICAL()                     vTaskExitCritical()\r
186 \r
187 extern UBaseType_t uxPortSetInterruptMaskFromISR();\r
188 extern void vPortClearInterruptMaskFromISR( UBaseType_t );\r
189 #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()\r
190 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) vPortClearInterruptMaskFromISR( uxSavedStatusRegister )\r
191 \r
192 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION\r
193         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1\r
194 #endif\r
195 \r
196 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1\r
197 \r
198         /* Check the configuration. */\r
199         #if( configMAX_PRIORITIES > 32 )\r
200                 #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
201         #endif\r
202 \r
203         /* Store/clear the ready priorities in a bit map. */\r
204         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )\r
205         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )\r
206 \r
207         /*-----------------------------------------------------------*/\r
208 \r
209         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - _clz( ( uxReadyPriorities ) ) )\r
210 \r
211 #endif /* taskRECORD_READY_PRIORITY */\r
212 \r
213 /*-----------------------------------------------------------*/\r
214 \r
215 /* Task utilities. */\r
216 \r
217 #define portYIELD()                                             \\r
218 {                                                                                       \\r
219 uint32_t ulCause;                                                       \\r
220         /* Trigger software interrupt. */               \\r
221         ulCause = ulPortGetCP0Cause();                  \\r
222         ulCause |= portSW0_BIT;                                 \\r
223         vPortSetCP0Cause( ulCause );                    \\r
224 }\r
225 \r
226 extern volatile UBaseType_t uxInterruptNesting;\r
227 #define portASSERT_IF_IN_ISR() configASSERT( uxInterruptNesting == 0 )\r
228 \r
229 #define portNOP() __asm volatile ( "nop" )\r
230 \r
231 /*-----------------------------------------------------------*/\r
232 \r
233 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
234 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))\r
235 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
236 /*-----------------------------------------------------------*/\r
237 \r
238 #define portEND_SWITCHING_ISR( xSwitchRequired )        if( xSwitchRequired )   \\r
239                                                                                                         {                                               \\r
240                                                                                                                 portYIELD();            \\r
241                                                                                                         }\r
242 \r
243 /* Required by the kernel aware debugger. */\r
244 #ifdef __DEBUG\r
245     #define portREMOVE_STATIC_QUALIFIER\r
246 #endif\r
247 \r
248 #ifdef __cplusplus\r
249 }\r
250 #endif\r
251 \r
252 #endif /* PORTMACRO_H */\r
253 \r