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