]> begriffs open source - freertos/blob - Source/portable/GCC/TriCore_1782/portmacro.h
Update TriCore GCC port layer.
[freertos] / Source / portable / GCC / TriCore_1782 / portmacro.h
1 /*\r
2     FreeRTOS V7.0.2 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3 \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 #ifndef PORTMACRO_H\r
55 #define PORTMACRO_H\r
56 \r
57 #ifdef __cplusplus\r
58 extern "C" {\r
59 #endif\r
60 \r
61 /* System Includes. */\r
62 #include <tc1782.h>\r
63 #include <machine/intrinsics.h>\r
64 \r
65 /*-----------------------------------------------------------\r
66  * Port specific definitions.\r
67  *\r
68  * The settings in this file configure FreeRTOS correctly for the\r
69  * given hardware and compiler.\r
70  *\r
71  * These settings should not be altered.\r
72  *-----------------------------------------------------------\r
73  */\r
74 \r
75 /* Type definitions. */\r
76 #define portCHAR                char\r
77 #define portFLOAT               float\r
78 #define portDOUBLE              double\r
79 #define portLONG                long\r
80 #define portSHORT               short\r
81 #define portSTACK_TYPE  unsigned long\r
82 #define portBASE_TYPE   long\r
83 \r
84 #if( configUSE_16_BIT_TICKS == 1 )\r
85         typedef unsigned portSHORT portTickType;\r
86         #define portMAX_DELAY ( portTickType ) 0xffff\r
87 #else\r
88         typedef unsigned portLONG portTickType;\r
89         #define portMAX_DELAY ( portTickType ) 0xffffffff\r
90 #endif\r
91 /*---------------------------------------------------------------------------*/\r
92 \r
93 /* Architecture specifics. */\r
94 #define portSTACK_GROWTH                                                        ( -1 )\r
95 #define portTICK_RATE_MS                                                        ( ( portTickType ) 1000 / configTICK_RATE_HZ )\r
96 #define portBYTE_ALIGNMENT                                                      4\r
97 #define portNOP()                                                                       __asm volatile( " nop " )\r
98 #define portCRITICAL_NESTING_IN_TCB                                     1\r
99 #define portRESTORE_FIRST_TASK_PRIORITY_LEVEL           1\r
100 \r
101 \r
102 /*---------------------------------------------------------------------------*/\r
103 \r
104 typedef struct MPU_SETTINGS { unsigned long ulNotUsed; } xMPU_SETTINGS;\r
105 \r
106 /* Define away the instruction from the Restore Context Macro. */\r
107 #define portPRIVILEGE_BIT                                                       0x0UL\r
108 \r
109 #define portCCPN_MASK                                           ( 0x000000FFUL )\r
110 \r
111 extern void vTaskEnterCritical( void );\r
112 extern void vTaskExitCritical( void );\r
113 #define portENTER_CRITICAL()                    vTaskEnterCritical()\r
114 #define portEXIT_CRITICAL()                             vTaskExitCritical()\r
115 /*---------------------------------------------------------------------------*/\r
116 \r
117 /* Task utilities. */\r
118 \r
119 extern void vPortReclaimCSA( unsigned portBASE_TYPE *pxTCB );\r
120 \r
121 /* CSA Manipulation. */\r
122 #define portCSA_TO_ADDRESS( pCSA )                      ( ( unsigned portBASE_TYPE * )( ( ( ( pCSA ) & 0x000F0000 ) << 12 ) | ( ( ( pCSA ) & 0x0000FFFF ) << 6 ) ) )\r
123 #define portADDRESS_TO_CSA( pAddress )          ( ( unsigned portBASE_TYPE )( ( ( ( (unsigned portBASE_TYPE)( pAddress ) ) & 0xF0000000 ) >> 12 ) | ( ( (unsigned portBASE_TYPE)( pAddress ) & 0x003FFFC0 ) >> 6 ) ) )\r
124 /*---------------------------------------------------------------------------*/\r
125 \r
126 #define portYIELD()                                                             _syscall(0)\r
127 /* Port Restore is implicit in the platform when the function is returned from the original PSW is automatically replaced. */\r
128 #define portSYSCALL_TASK_YIELD                                  0\r
129 #define portSYSCALL_RAISE_PRIORITY                              1\r
130 /*---------------------------------------------------------------------------*/\r
131 \r
132 /* Critical section management. */\r
133 \r
134 /* Clear the ICR.IE bit. */\r
135 #define portDISABLE_INTERRUPTS()                        _mtcr( $ICR, ( ( _mfcr( $ICR ) & ~portCCPN_MASK ) | configMAX_SYSCALL_INTERRUPT_PRIORITY ) )\r
136 \r
137 /* Set the ICR.IE bit. */\r
138 #define portENABLE_INTERRUPTS()                         { unsigned long ulCurrentICR = _mfcr( $ICR ); _mtcr( $ICR, ( ulCurrentICR & ~portCCPN_MASK ) ) }\r
139 \r
140 extern unsigned portBASE_TYPE uxPortSetInterruptMaskFromISR( void );\r
141 extern void vPortClearInterruptMaskFromISR( unsigned portBASE_TYPE uxSavedStatusValue );\r
142 \r
143 /* Set ICR.CCPN to configMAX_SYSCALL_INTERRUPT_PRIORITY */\r
144 #define portSET_INTERRUPT_MASK_FROM_ISR()       uxPortSetInterruptMaskFromISR()\r
145 \r
146 /* Set ICR.CCPN to uxSavedInterruptStatus */\r
147 #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusValue ) vPortClearInterruptMaskFromISR( uxSavedStatusValue )\r
148 \r
149 /*---------------------------------------------------------------------------*/\r
150 \r
151 /*\r
152  * Save the context of a task.\r
153  * The upper context is automatically saved when entering a trap or interrupt.\r
154  * Need to save the lower context as well and copy the PCXI CSA ID into\r
155  * pxCurrentTCB->pxTopOfStack. Only Lower Context CSA IDs may be saved to the\r
156  * TCB of a task.\r
157  *\r
158  * Call vTaskSwitchContext to select the next task, note that this changes the\r
159  * value of pxCurrentTCB so that it needs to be reloaded.\r
160  *\r
161  * Call vPortSetMPURegisterSetOne to change the MPU mapping for the task\r
162  * that has just been switched in.\r
163  *\r
164  * Load the context of the task.\r
165  * Need to restore the lower context by loading the CSA from\r
166  * pxCurrentTCB->pxTopOfStack into PCXI (effectively changing the call stack).\r
167  * In the Interrupt handler post-amble, RSLCX will restore the lower context\r
168  * of the task. RFE will restore the upper context of the task, jump to the\r
169  * return address and restore the previous state of interrupts being\r
170  * enabled/disabled.\r
171  */\r
172 #define portYIELD_FROM_ISR( xHigherPriorityTaskWoken )                  \\r
173 {                                                                                                                               \\r
174 unsigned portBASE_TYPE *pxUpperCSA = NULL;                                              \\r
175 unsigned portBASE_TYPE xUpperCSA = 0UL;                                                 \\r
176         if ( pdTRUE == xHigherPriorityTaskWoken )                                       \\r
177         {                                                                                                                       \\r
178                 _disable();                                                                                             \\r
179                 _isync();                                                                                               \\r
180                 xUpperCSA = _mfcr( $PCXI );                                                             \\r
181                 pxUpperCSA = portCSA_TO_ADDRESS( xUpperCSA );                   \\r
182                 *pxCurrentTCB = pxUpperCSA[0];                                                  \\r
183                 vTaskSwitchContext();                                                                   \\r
184                 pxUpperCSA[0] = *pxCurrentTCB;                                                  \\r
185                 _dsync();                                                                                               \\r
186                 _isync();                                                                                               \\r
187                 _nop();                                                                                                 \\r
188                 _nop();                                                                                                 \\r
189         }                                                                                                                       \\r
190 }\r
191 /*---------------------------------------------------------------------------*/\r
192 \r
193 /* Task function macros as described on the FreeRTOS.org WEB site. */\r
194 #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
195 #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )\r
196 /*---------------------------------------------------------------------------*/\r
197 \r
198 /*\r
199  * Port specific clean up macro required to free the CSAs that were consumed by\r
200  * a task that has since been deleted.\r
201  */\r
202 void vPortReclaimCSA( unsigned portBASE_TYPE *pxTCB );\r
203 #define portCLEAN_UP_TCB( pxTCB )               vPortReclaimCSA( ( unsigned portBASE_TYPE *) ( pxTCB ) )\r
204 \r
205 #ifdef __cplusplus\r
206 }\r
207 #endif\r
208 \r
209 #endif /* PORTMACRO_H */\r