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 #include <machine/cpu.h>
40 /*-----------------------------------------------------------
41 * Port specific definitions.
43 * The settings in this file configure FreeRTOS correctly for the
44 * given hardware and compiler.
46 * These settings should not be altered.
47 *-----------------------------------------------------------
50 /* Type definitions. */
52 #define portFLOAT float
53 #define portDOUBLE double
55 #define portSHORT short
56 #define portSTACK_TYPE uint32_t
57 #define portBASE_TYPE long
59 typedef portSTACK_TYPE StackType_t;
60 typedef long BaseType_t;
61 typedef unsigned long UBaseType_t;
63 #if( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS )
64 typedef uint16_t TickType_t;
65 #define portMAX_DELAY ( TickType_t ) 0xffff
66 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
67 typedef uint32_t TickType_t;
68 #define portMAX_DELAY ( TickType_t ) ( 0xFFFFFFFFUL )
70 #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
72 /*-----------------------------------------------------------*/
74 /* Architecture specifics. */
75 #define portSTACK_GROWTH ( -1 )
76 #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
77 #define portBYTE_ALIGNMENT 4
78 #define portNOP() __asm__ volatile ( "mov r0, r0" )
79 #define portCRITICAL_NESTING_IN_TCB 1
80 #define portIRQ_TRAP_YIELD 31
81 /*-----------------------------------------------------------*/
85 extern void vPortYield( void );
87 /*---------------------------------------------------------------------------*/
89 #define portYIELD() asm __volatile__( " trap #%0 "::"i"(portIRQ_TRAP_YIELD):"memory")
90 /*---------------------------------------------------------------------------*/
92 extern void vTaskEnterCritical( void );
93 extern void vTaskExitCritical( void );
94 #define portENTER_CRITICAL() vTaskEnterCritical()
95 #define portEXIT_CRITICAL() vTaskExitCritical()
96 /*---------------------------------------------------------------------------*/
98 /* Critical section management. */
99 #define portDISABLE_INTERRUPTS() cpu_int_disable()
100 #define portENABLE_INTERRUPTS() cpu_int_enable()
102 /*---------------------------------------------------------------------------*/
104 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken ) do { if( xHigherPriorityTaskWoken != pdFALSE ) vTaskSwitchContext(); } while( 0 )
106 /*---------------------------------------------------------------------------*/
108 #define portSAVE_CONTEXT() \
111 "sub r1, #68 \n" /* Make space on the stack for the context. */ \
112 "std r2, [r1] + 0 \n" \
113 "stq r4, [r1] + 8 \n" \
114 "stq r8, [r1] + 24 \n" \
115 "stq r12, [r1] + 40 \n" \
118 "std r6, [r1] + 56 \n" \
119 "movhi r2, #16384 \n" /* Set the pointer to the IC. */ \
120 "ldub r3, [r2] + 2 \n" /* Load the current interrupt mask. */ \
121 "st r3, [r1]+ 64 \n" /* Store the interrupt mask on the stack. */ \
122 "ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the pointer to the TCB. */ \
123 "st r1, [r2] \n" /* Save the stack pointer into the TCB. */ \
124 "mov r14, r1 \n" /* Compiler expects r14 to be set to the function stack. */ \
126 /*---------------------------------------------------------------------------*/
128 #define portRESTORE_CONTEXT() \
130 "ld r2, [r0]+short(pxCurrentTCB) \n" /* Load the TCB to find the stack pointer and context. */ \
132 "movhi r2, #16384 \n" /* Set the pointer to the IC. */ \
133 "ld r3, [r1] + 64 \n" /* Load the previous interrupt mask. */ \
134 "stb r3, [r2] + 2 \n" /* Set the current interrupt mask to be the previous. */ \
135 "ldd r6, [r1] + 56 \n" /* Restore context. */ \
138 "ldd r2, [r1] + 0 \n" \
139 "ldq r4, [r1] + 8 \n" \
140 "ldq r8, [r1] + 24 \n" \
141 "ldq r12, [r1] + 40 \n" \
146 /*---------------------------------------------------------------------------*/
148 /* Task function macros as described on the FreeRTOS.org WEB site. */
149 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
150 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
151 /*---------------------------------------------------------------------------*/
159 #endif /* PORTMACRO_H */