]> begriffs open source - freertos/blob - portable/MPLAB/PIC32MX/portmacro.h
Update SMP branch readme for port migration (#999)
[freertos] / portable / MPLAB / PIC32MX / portmacro.h
1 /*
2  * FreeRTOS SMP Kernel V202110.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 #ifndef PORTMACRO_H
29 #define PORTMACRO_H
30
31 /* System include files */
32 #include <xc.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 /*-----------------------------------------------------------
39  * Port specific definitions.
40  *
41  * The settings in this file configure FreeRTOS correctly for the
42  * given hardware and compiler.
43  *
44  * These settings should not be altered.
45  *-----------------------------------------------------------
46  */
47
48 /* Type definitions. */
49 #define portCHAR                char
50 #define portFLOAT               float
51 #define portDOUBLE              double
52 #define portLONG                long
53 #define portSHORT               short
54 #define portSTACK_TYPE  uint32_t
55 #define portBASE_TYPE   long
56
57 typedef portSTACK_TYPE StackType_t;
58 typedef long BaseType_t;
59 typedef unsigned long UBaseType_t;
60
61 #if( configUSE_16_BIT_TICKS == 1 )
62         typedef uint16_t TickType_t;
63         #define portMAX_DELAY ( TickType_t ) 0xffff
64 #else
65         typedef uint32_t TickType_t;
66         #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
67
68         /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
69         not need to be guarded with a critical section. */
70         #define portTICK_TYPE_IS_ATOMIC 1
71 #endif
72 /*-----------------------------------------------------------*/
73
74 /* Hardware specifics. */
75 #define portBYTE_ALIGNMENT                      8
76 #define portSTACK_GROWTH                        -1
77 #define portTICK_PERIOD_MS                      ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
78 /*-----------------------------------------------------------*/
79
80 /* Critical section management. */
81 #define portIPL_SHIFT                           ( 10UL )
82 #define portALL_IPL_BITS                        ( 0x3fUL << portIPL_SHIFT )
83 #define portSW0_BIT                                     ( 0x01 << 8 )
84
85 /* This clears the IPL bits, then sets them to
86 configMAX_SYSCALL_INTERRUPT_PRIORITY.  An extra check is performed if
87 configASSERT() is defined to ensure an assertion handler does not inadvertently
88 attempt to lower the IPL when the call to assert was triggered because the IPL
89 value was found to be above configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR
90 safe FreeRTOS API function was executed.  ISR safe FreeRTOS API functions are
91 those that end in FromISR.  FreeRTOS maintains a separate interrupt API to
92 ensure API function and interrupt entry is as fast and as simple as possible. */
93 #ifdef configASSERT
94         #define portDISABLE_INTERRUPTS()                                                                                        \
95         {                                                                                                                                                       \
96         uint32_t ulStatus;                                                                                                              \
97                                                                                                                                                                 \
98                 /* Mask interrupts at and below the kernel interrupt priority. */               \
99                 ulStatus = _CP0_GET_STATUS();                                                                                   \
100                                                                                                                                                                 \
101                 /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */    \
102                 if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY ) \
103                 {                                                                                                                                               \
104                         ulStatus &= ~portALL_IPL_BITS;                                                                          \
105                         _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \
106                 }                                                                                                                                               \
107         }
108 #else /* configASSERT */
109         #define portDISABLE_INTERRUPTS()                                                                                \
110         {                                                                                                                                               \
111         uint32_t ulStatus;                                                                                                      \
112                                                                                                                                                         \
113                 /* Mask interrupts at and below the kernel interrupt priority. */       \
114                 ulStatus = _CP0_GET_STATUS();                                                                           \
115                 ulStatus &= ~portALL_IPL_BITS;                                                                          \
116                 _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \
117         }
118 #endif /* configASSERT */
119
120 #define portENABLE_INTERRUPTS()                                                                                 \
121 {                                                                                                                                               \
122 uint32_t ulStatus;                                                                                                      \
123                                                                                                                                                 \
124         /* Unmask all interrupts. */                                                                            \
125         ulStatus = _CP0_GET_STATUS();                                                                           \
126         ulStatus &= ~portALL_IPL_BITS;                                                                          \
127         _CP0_SET_STATUS( ulStatus );                                                                            \
128 }
129
130
131 extern void vTaskEnterCritical( void );
132 extern void vTaskExitCritical( void );
133 #define portCRITICAL_NESTING_IN_TCB     1
134 #define portENTER_CRITICAL()            vTaskEnterCritical()
135 #define portEXIT_CRITICAL()                     vTaskExitCritical()
136
137 extern UBaseType_t uxPortSetInterruptMaskFromISR();
138 extern void vPortClearInterruptMaskFromISR( UBaseType_t );
139 #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()
140 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) vPortClearInterruptMaskFromISR( uxSavedStatusRegister )
141
142 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
143         #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
144 #endif
145
146 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
147
148         /* Check the configuration. */
149         #if( configMAX_PRIORITIES > 32 )
150                 #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.
151         #endif
152
153         /* Store/clear the ready priorities in a bit map. */
154         #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
155         #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
156
157         /*-----------------------------------------------------------*/
158
159         #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - _clz( ( uxReadyPriorities ) ) )
160
161 #endif /* taskRECORD_READY_PRIORITY */
162
163 /*-----------------------------------------------------------*/
164
165 /* Task utilities. */
166
167 #define portYIELD()                                                             \
168 {                                                                                               \
169 uint32_t ulCause;                                                       \
170                                                                                                 \
171         /* Trigger software interrupt. */                       \
172         ulCause = _CP0_GET_CAUSE();                                     \
173         ulCause |= portSW0_BIT;                                         \
174         _CP0_SET_CAUSE( ulCause );                                      \
175 }
176
177 extern volatile UBaseType_t uxInterruptNesting;
178 #define portASSERT_IF_IN_ISR() configASSERT( uxInterruptNesting == 0 )
179
180 #define portNOP()       __asm volatile ( "nop" )
181
182 /*-----------------------------------------------------------*/
183
184 /* Task function macros as described on the FreeRTOS.org WEB site. */
185 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))
186 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
187 /*-----------------------------------------------------------*/
188
189 #define portEND_SWITCHING_ISR( xSwitchRequired )        if( xSwitchRequired )   \
190                                                                                                         {                                               \
191                                                                                                                 portYIELD();            \
192                                                                                                         }
193
194 /* Required by the kernel aware debugger. */
195 #ifdef __DEBUG
196         #define portREMOVE_STATIC_QUALIFIER
197 #endif
198
199 #ifdef __cplusplus
200 }
201 #endif
202
203 #endif /* PORTMACRO_H */
204