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