xref: /Kernel-v10.6.2/portable/CCS/ARM_Cortex-R4/portmacro.h (revision ef7b253b56c9788077f5ecd6c9deb4021923d646)
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 /*-----------------------------------------------------------
33  * Port specific definitions.
34  *
35  * The settings in this file configure FreeRTOS correctly for the
36  * given hardware and compiler.
37  *
38  * These settings should not be altered.
39  *-----------------------------------------------------------
40  */
41 
42 /* Type definitions. */
43 #define portCHAR        char
44 #define portFLOAT       float
45 #define portDOUBLE      double
46 #define portLONG        long
47 #define portSHORT       short
48 #define portSTACK_TYPE  uint32_t
49 #define portBASE_TYPE   long
50 
51 typedef portSTACK_TYPE StackType_t;
52 typedef long BaseType_t;
53 typedef unsigned long UBaseType_t;
54 
55 #if (configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_16_BITS)
56     typedef uint16_t TickType_t;
57     #define portMAX_DELAY (TickType_t) 0xFFFF
58 #elif ( configTICK_TYPE_WIDTH_IN_BITS == TICK_TYPE_WIDTH_32_BITS )
59     typedef uint32_t TickType_t;
60     #define portMAX_DELAY (TickType_t) 0xFFFFFFFFF
61 
62     /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
63     not need to be guarded with a critical section. */
64     #define portTICK_TYPE_IS_ATOMIC 1
65 #else
66     #error configTICK_TYPE_WIDTH_IN_BITS set to unsupported tick type width.
67 #endif
68 
69 
70 /* Architecture specifics. */
71 #define portSTACK_GROWTH    (-1)
72 #define portTICK_PERIOD_MS    ((TickType_t) 1000 / configTICK_RATE_HZ)
73 #define portBYTE_ALIGNMENT  8
74 
75 /* Critical section handling. */
76 extern void vPortEnterCritical(void);
77 extern void vPortExitCritical(void);
78 #define portENTER_CRITICAL()        vPortEnterCritical()
79 #define portEXIT_CRITICAL()         vPortExitCritical()
80 #define portDISABLE_INTERRUPTS()    asm( " CPSID I" )
81 #define portENABLE_INTERRUPTS()     asm( " CPSIE I" )
82 
83 /* Scheduler utilities. */
84 #pragma SWI_ALIAS( vPortYield, 0 )
85 extern void vPortYield( void );
86 #define portYIELD()                 vPortYield()
87 #define portSYS_SSIR1_REG           ( * ( ( volatile uint32_t * ) 0xFFFFFFB0 ) )
88 #define portSYS_SSIR1_SSKEY         ( 0x7500UL )
89 #define portYIELD_WITHIN_API()      { portSYS_SSIR1_REG = portSYS_SSIR1_SSKEY;  asm( " DSB " ); asm( " ISB " ); }
90 #define portYIELD_FROM_ISR( x )     do { if( x != pdFALSE ) { portSYS_SSIR1_REG = portSYS_SSIR1_SSKEY;  ( void ) portSYS_SSIR1_REG; } } while( 0 )
91 
92 #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
93     #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
94 #endif
95 
96 /* Architecture specific optimisations. */
97 #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
98 
99     /* Check the configuration. */
100     #if( configMAX_PRIORITIES > 32 )
101         #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.
102     #endif
103 
104     /* Store/clear the ready priorities in a bit map. */
105     #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
106     #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
107 
108     /*-----------------------------------------------------------*/
109 
110     #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __clz( ( uxReadyPriorities ) ) )
111 
112 #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
113 
114 
115 /* Task function macros as described on the FreeRTOS.org WEB site. */
116 #define portTASK_FUNCTION(vFunction, pvParameters)       void vFunction(void *pvParameters)
117 #define portTASK_FUNCTION_PROTO(vFunction, pvParameters) void vFunction(void *pvParameters)
118 
119 #endif /* __PORTMACRO_H__ */
120