2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
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:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
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.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
38 /* System Includes. */
40 #include <machine/intrinsics.h>
42 /*-----------------------------------------------------------
43 * Port specific definitions.
45 * The settings in this file configure FreeRTOS correctly for the
46 * given hardware and compiler.
48 * These settings should not be altered.
49 *-----------------------------------------------------------
52 /* Type definitions. */
54 #define portFLOAT float
55 #define portDOUBLE double
57 #define portSHORT short
58 #define portSTACK_TYPE uint32_t
59 #define portBASE_TYPE long
61 typedef portSTACK_TYPE StackType_t;
62 typedef long BaseType_t;
63 typedef unsigned long UBaseType_t;
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
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
76 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
78 /*---------------------------------------------------------------------------*/
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
89 /*---------------------------------------------------------------------------*/
91 typedef struct MPU_SETTINGS
96 /* Define away the instruction from the Restore Context Macro. */
97 #define portPRIVILEGE_BIT 0x0UL
99 #define portCCPN_MASK ( 0x000000FFUL )
101 extern void vTaskEnterCritical( void );
102 extern void vTaskExitCritical( void );
103 #define portENTER_CRITICAL() vTaskEnterCritical()
104 #define portEXIT_CRITICAL() vTaskExitCritical()
105 /*---------------------------------------------------------------------------*/
107 /* CSA Manipulation. */
108 #define portCSA_TO_ADDRESS( pCSA ) ( ( uint32_t * ) ( ( ( ( pCSA ) & 0x000F0000 ) << 12 ) | ( ( ( pCSA ) & 0x0000FFFF ) << 6 ) ) )
109 #define portADDRESS_TO_CSA( pAddress ) ( ( uint32_t ) ( ( ( ( ( uint32_t ) ( pAddress ) ) & 0xF0000000 ) >> 12 ) | ( ( ( uint32_t ) ( pAddress ) & 0x003FFFC0 ) >> 6 ) ) )
110 /*---------------------------------------------------------------------------*/
112 #define portYIELD() _syscall( 0 )
113 /* Port Restore is implicit in the platform when the function is returned from the original PSW is automatically replaced. */
114 #define portSYSCALL_TASK_YIELD 0
115 #define portSYSCALL_RAISE_PRIORITY 1
116 /*---------------------------------------------------------------------------*/
118 /* Critical section management. */
120 /* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY. */
121 #define portDISABLE_INTERRUPTS() \
125 ulICR = __MFCR( $ICR ); /* Get current ICR value. */ \
126 ulICR &= ~portCCPN_MASK; /* Clear down mask bits. */ \
127 ulICR |= configMAX_SYSCALL_INTERRUPT_PRIORITY; /* Set mask bits to required priority mask. */ \
128 _mtcr( $ICR, ulICR ); /* Write back updated ICR. */ \
133 /* Clear ICR.CCPN to allow all interrupt priorities. */
134 #define portENABLE_INTERRUPTS() \
138 ulICR = __MFCR( $ICR ); /* Get current ICR value. */ \
139 ulICR &= ~portCCPN_MASK; /* Clear down mask bits. */ \
140 _mtcr( $ICR, ulICR ); /* Write back updated ICR. */ \
145 /* Set ICR.CCPN to uxSavedMaskValue. */
146 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedMaskValue ) \
150 ulICR = __MFCR( $ICR ); /* Get current ICR value. */ \
151 ulICR &= ~portCCPN_MASK; /* Clear down mask bits. */ \
152 ulICR |= uxSavedMaskValue; /* Set mask bits to previously saved mask value. */ \
153 _mtcr( $ICR, ulICR ); /* Write back updated ICR. */ \
159 /* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY */
160 extern uint32_t uxPortSetInterruptMaskFromISR( void );
161 #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()
163 /* Pend a priority 1 interrupt, which will take care of the context switch. */
164 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) do { if( xHigherPriorityTaskWoken != pdFALSE ) { CPU_SRC0.bits.SETR = 1; _isync(); } } while( 0 )
166 /*---------------------------------------------------------------------------*/
168 /* Task function macros as described on the FreeRTOS.org WEB site. */
169 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
170 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
171 /*---------------------------------------------------------------------------*/
174 * Port specific clean up macro required to free the CSAs that were consumed by
175 * a task that has since been deleted.
177 void vPortReclaimCSA( uint32_t * pxTCB );
178 #define portCLEAN_UP_TCB( pxTCB ) vPortReclaimCSA( ( uint32_t * ) ( pxTCB ) )
186 #endif /* PORTMACRO_H */