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 /* *INDENT-OFF* */ 33 #ifdef __cplusplus 34 extern "C" { 35 #endif 36 /* *INDENT-ON* */ 37 38 /* System Includes. */ 39 #include <tc1782.h> 40 #include <machine/intrinsics.h> 41 42 /*----------------------------------------------------------- 43 * Port specific definitions. 44 * 45 * The settings in this file configure FreeRTOS correctly for the 46 * given hardware and compiler. 47 * 48 * These settings should not be altered. 49 *----------------------------------------------------------- 50 */ 51 52 /* Type definitions. */ 53 #define portCHAR char 54 #define portFLOAT float 55 #define portDOUBLE double 56 #define portLONG long 57 #define portSHORT short 58 #define portSTACK_TYPE uint32_t 59 #define portBASE_TYPE long 60 61 typedef portSTACK_TYPE StackType_t; 62 typedef long BaseType_t; 63 typedef unsigned long UBaseType_t; 64 65 #if( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS ) 66 typedef uint16_t TickType_t; 67 #define portMAX_DELAY ( TickType_t ) 0xffff 68 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS ) 69 typedef uint32_t TickType_t; 70 #define portMAX_DELAY ( TickType_t ) 0xffffffffUL 71 72 /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do 73 not need to be guarded with a critical section. */ 74 #define portTICK_TYPE_IS_ATOMIC 1 75 #else 76 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width. 77 #endif 78 /*---------------------------------------------------------------------------*/ 79 80 /* Architecture specifics. */ 81 #define portSTACK_GROWTH ( -1 ) 82 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ ) 83 #define portBYTE_ALIGNMENT 4 84 #define portNOP() __asm volatile( " nop " ) 85 #define portCRITICAL_NESTING_IN_TCB 1 86 #define portRESTORE_FIRST_TASK_PRIORITY_LEVEL 1 87 88 89 /*---------------------------------------------------------------------------*/ 90 91 typedef struct MPU_SETTINGS { uint32_t ulNotUsed; } xMPU_SETTINGS; 92 93 /* Define away the instruction from the Restore Context Macro. */ 94 #define portPRIVILEGE_BIT 0x0UL 95 96 #define portCCPN_MASK ( 0x000000FFUL ) 97 98 extern void vTaskEnterCritical( void ); 99 extern void vTaskExitCritical( void ); 100 #define portENTER_CRITICAL() vTaskEnterCritical() 101 #define portEXIT_CRITICAL() vTaskExitCritical() 102 /*---------------------------------------------------------------------------*/ 103 104 /* CSA Manipulation. */ 105 #define portCSA_TO_ADDRESS( pCSA ) ( ( uint32_t * )( ( ( ( pCSA ) & 0x000F0000 ) << 12 ) | ( ( ( pCSA ) & 0x0000FFFF ) << 6 ) ) ) 106 #define portADDRESS_TO_CSA( pAddress ) ( ( uint32_t )( ( ( ( (uint32_t)( pAddress ) ) & 0xF0000000 ) >> 12 ) | ( ( ( uint32_t )( pAddress ) & 0x003FFFC0 ) >> 6 ) ) ) 107 /*---------------------------------------------------------------------------*/ 108 109 #define portYIELD() _syscall( 0 ) 110 /* Port Restore is implicit in the platform when the function is returned from the original PSW is automatically replaced. */ 111 #define portSYSCALL_TASK_YIELD 0 112 #define portSYSCALL_RAISE_PRIORITY 1 113 /*---------------------------------------------------------------------------*/ 114 115 /* Critical section management. */ 116 117 /* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY. */ 118 #define portDISABLE_INTERRUPTS() { \ 119 uint32_t ulICR; \ 120 _disable(); \ 121 ulICR = __MFCR( $ICR ); /* Get current ICR value. */ \ 122 ulICR &= ~portCCPN_MASK; /* Clear down mask bits. */ \ 123 ulICR |= configMAX_SYSCALL_INTERRUPT_PRIORITY; /* Set mask bits to required priority mask. */ \ 124 _mtcr( $ICR, ulICR ); /* Write back updated ICR. */ \ 125 _isync(); \ 126 _enable(); \ 127 } 128 129 /* Clear ICR.CCPN to allow all interrupt priorities. */ 130 #define portENABLE_INTERRUPTS() { \ 131 uint32_t ulICR; \ 132 _disable(); \ 133 ulICR = __MFCR( $ICR ); /* Get current ICR value. */ \ 134 ulICR &= ~portCCPN_MASK; /* Clear down mask bits. */ \ 135 _mtcr( $ICR, ulICR ); /* Write back updated ICR. */ \ 136 _isync(); \ 137 _enable(); \ 138 } 139 140 /* Set ICR.CCPN to uxSavedMaskValue. */ 141 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedMaskValue ) { \ 142 uint32_t ulICR; \ 143 _disable(); \ 144 ulICR = __MFCR( $ICR ); /* Get current ICR value. */ \ 145 ulICR &= ~portCCPN_MASK; /* Clear down mask bits. */ \ 146 ulICR |= uxSavedMaskValue; /* Set mask bits to previously saved mask value. */ \ 147 _mtcr( $ICR, ulICR ); /* Write back updated ICR. */ \ 148 _isync(); \ 149 _enable(); \ 150 } 151 152 153 /* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY */ 154 extern uint32_t uxPortSetInterruptMaskFromISR( void ); 155 #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR() 156 157 /* Pend a priority 1 interrupt, which will take care of the context switch. */ 158 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) do { if( xHigherPriorityTaskWoken != pdFALSE ) { CPU_SRC0.bits.SETR = 1; _isync(); } } while( 0 ) 159 160 /*---------------------------------------------------------------------------*/ 161 162 /* Task function macros as described on the FreeRTOS.org WEB site. */ 163 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) 164 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) 165 /*---------------------------------------------------------------------------*/ 166 167 /* 168 * Port specific clean up macro required to free the CSAs that were consumed by 169 * a task that has since been deleted. 170 */ 171 void vPortReclaimCSA( uint32_t *pxTCB ); 172 #define portCLEAN_UP_TCB( pxTCB ) vPortReclaimCSA( ( uint32_t * ) ( pxTCB ) ) 173 174 /* *INDENT-OFF* */ 175 #ifdef __cplusplus 176 } 177 #endif 178 /* *INDENT-ON* */ 179 180 #endif /* PORTMACRO_H */ 181