1 /*
2  * FreeRTOS Kernel V11.1.0
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
92 {
93     uint32_t ulNotUsed;
94 } xMPU_SETTINGS;
95 
96 /* Define away the instruction from the Restore Context Macro. */
97 #define portPRIVILEGE_BIT    0x0UL
98 
99 #define portCCPN_MASK        ( 0x000000FFUL )
100 
101 extern void vTaskEnterCritical( void );
102 extern void vTaskExitCritical( void );
103 #define portENTER_CRITICAL()    vTaskEnterCritical()
104 #define portEXIT_CRITICAL()     vTaskExitCritical()
105 /*---------------------------------------------------------------------------*/
106 
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 /*---------------------------------------------------------------------------*/
111 
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 /*---------------------------------------------------------------------------*/
117 
118 /* Critical section management. */
119 
120 /* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY. */
121 #define portDISABLE_INTERRUPTS()                                                                      \
122     {                                                                                                 \
123         uint32_t ulICR;                                                                               \
124         _disable();                                                                                   \
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. */                  \
129         _isync();                                                                                     \
130         _enable();                                                                                    \
131     }
132 
133 /* Clear ICR.CCPN to allow all interrupt priorities. */
134 #define portENABLE_INTERRUPTS()                                \
135     {                                                          \
136         uint32_t ulICR;                                        \
137         _disable();                                            \
138         ulICR = __MFCR( $ICR );  /* Get current ICR value. */  \
139         ulICR &= ~portCCPN_MASK; /* Clear down mask bits. */   \
140         _mtcr( $ICR, ulICR );    /* Write back updated ICR. */ \
141         _isync();                                              \
142         _enable();                                             \
143     }
144 
145 /* Set ICR.CCPN to uxSavedMaskValue. */
146 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedMaskValue )                          \
147     {                                                                                  \
148         uint32_t ulICR;                                                                \
149         _disable();                                                                    \
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. */                       \
154         _isync();                                                                      \
155         _enable();                                                                     \
156     }
157 
158 
159 /* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY */
160 extern uint32_t uxPortSetInterruptMaskFromISR( void );
161 #define portSET_INTERRUPT_MASK_FROM_ISR()                 uxPortSetInterruptMaskFromISR()
162 
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 )
165 
166 /*---------------------------------------------------------------------------*/
167 
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 /*---------------------------------------------------------------------------*/
172 
173 /*
174  * Port specific clean up macro required to free the CSAs that were consumed by
175  * a task that has since been deleted.
176  */
177 void vPortReclaimCSA( uint32_t * pxTCB );
178 #define portCLEAN_UP_TCB( pxTCB )    vPortReclaimCSA( ( uint32_t * ) ( pxTCB ) )
179 
180 /* *INDENT-OFF* */
181 #ifdef __cplusplus
182     }
183 #endif
184 /* *INDENT-ON* */
185 
186 #endif /* PORTMACRO_H */
187