]> begriffs open source - freertos/blob - portable/CodeWarrior/ColdFire_V1/port.c
[AUTO][RELEASE]: Bump file header version to "10.4.6"
[freertos] / portable / CodeWarrior / ColdFire_V1 / port.c
1 /*\r
2  * FreeRTOS Kernel V10.4.6\r
3  * Copyright (C) 2021 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * SPDX-License-Identifier: MIT\r
6  *\r
7  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
8  * this software and associated documentation files (the "Software"), to deal in\r
9  * the Software without restriction, including without limitation the rights to\r
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
11  * the Software, and to permit persons to whom the Software is furnished to do so,\r
12  * subject to the following conditions:\r
13  *\r
14  * The above copyright notice and this permission notice shall be included in all\r
15  * copies or substantial portions of the Software.\r
16  *\r
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
19  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
20  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
21  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
22  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
23  *\r
24  * https://www.FreeRTOS.org\r
25  * https://github.com/FreeRTOS\r
26  *\r
27  */\r
28 \r
29 /* Kernel includes. */\r
30 #include "FreeRTOS.h"\r
31 #include "task.h"\r
32 \r
33 \r
34 #define portINITIAL_FORMAT_VECTOR               ( ( StackType_t ) 0x4000 )\r
35 \r
36 /* Supervisor mode set. */\r
37 #define portINITIAL_STATUS_REGISTER             ( ( StackType_t ) 0x2000)\r
38 \r
39 /* The clock prescale into the timer peripheral. */\r
40 #define portPRESCALE_VALUE                              ( ( uint8_t ) 10 )\r
41 \r
42 /* The clock frequency into the RTC. */\r
43 #define portRTC_CLOCK_HZ                                ( ( uint32_t ) 1000 )\r
44 \r
45 asm void interrupt VectorNumber_VL1swi vPortYieldISR( void );\r
46 static void prvSetupTimerInterrupt( void );\r
47 \r
48 /* Used to keep track of the number of nested calls to taskENTER_CRITICAL().  This\r
49 will be set to 0 prior to the first task being started. */\r
50 static uint32_t ulCriticalNesting = 0x9999UL;\r
51 \r
52 /*-----------------------------------------------------------*/\r
53 \r
54 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
55 {\r
56 \r
57 uint32_t ulOriginalA5;\r
58 \r
59         __asm{ MOVE.L A5, ulOriginalA5 };\r
60 \r
61 \r
62         *pxTopOfStack = (StackType_t) 0xDEADBEEF;\r
63         pxTopOfStack--;\r
64 \r
65         /* Exception stack frame starts with the return address. */\r
66         *pxTopOfStack = ( StackType_t ) pxCode;\r
67         pxTopOfStack--;\r
68 \r
69         *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );\r
70         pxTopOfStack--;\r
71 \r
72         *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/\r
73         pxTopOfStack -= 14; /* A5 to D0. */\r
74 \r
75         /* Parameter in A0. */\r
76         *( pxTopOfStack + 8 ) = ( StackType_t ) pvParameters;\r
77 \r
78         /* A5 must be maintained as it is resurved by the compiler. */\r
79         *( pxTopOfStack + 13 ) = ulOriginalA5;\r
80 \r
81         return pxTopOfStack;  \r
82 }\r
83 /*-----------------------------------------------------------*/\r
84 \r
85 BaseType_t xPortStartScheduler( void )\r
86 {\r
87 extern void vPortStartFirstTask( void );\r
88 \r
89         ulCriticalNesting = 0UL;\r
90 \r
91         /* Configure a timer to generate the tick interrupt. */\r
92         prvSetupTimerInterrupt();\r
93 \r
94         /* Start the first task executing. */\r
95         vPortStartFirstTask();\r
96 \r
97         return pdFALSE;\r
98 }\r
99 /*-----------------------------------------------------------*/\r
100 \r
101 static void prvSetupTimerInterrupt( void )\r
102 {                               \r
103         /* Prescale by 1 - ie no prescale. */\r
104         RTCSC |= 8;\r
105         \r
106         /* Compare match value. */\r
107         RTCMOD = portRTC_CLOCK_HZ / configTICK_RATE_HZ;\r
108         \r
109         /* Enable the RTC to generate interrupts - interrupts are already disabled\r
110         when this code executes. */\r
111         RTCSC_RTIE = 1;\r
112 }\r
113 /*-----------------------------------------------------------*/\r
114 \r
115 void vPortEndScheduler( void )\r
116 {\r
117         /* Not implemented as there is nothing to return to. */\r
118 }\r
119 /*-----------------------------------------------------------*/\r
120 \r
121 void vPortEnterCritical( void )\r
122 {\r
123         if( ulCriticalNesting == 0UL )\r
124         {\r
125                 /* Guard against context switches being pended simultaneously with a\r
126                 critical section being entered. */\r
127                 do\r
128                 {\r
129                         portDISABLE_INTERRUPTS();\r
130                         if( INTC_FRC == 0UL )\r
131                         {\r
132                                 break;\r
133                         }\r
134 \r
135                         portENABLE_INTERRUPTS();\r
136 \r
137                 } while( 1 );\r
138         }\r
139         ulCriticalNesting++;\r
140 }\r
141 /*-----------------------------------------------------------*/\r
142 \r
143 void vPortExitCritical( void )\r
144 {\r
145         ulCriticalNesting--;\r
146         if( ulCriticalNesting == 0 )\r
147         {\r
148                 portENABLE_INTERRUPTS();\r
149         }\r
150 }\r
151 /*-----------------------------------------------------------*/\r
152 \r
153 void vPortYieldHandler( void )\r
154 {\r
155 uint32_t ulSavedInterruptMask;\r
156 \r
157         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
158         {\r
159                 /* Note this will clear all forced interrupts - this is done for speed. */\r
160                 INTC_CFRC = 0x3E;\r
161                 vTaskSwitchContext();\r
162         }\r
163         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
164 }\r
165 /*-----------------------------------------------------------*/\r
166 \r
167 void interrupt VectorNumber_Vrtc vPortTickISR( void )\r
168 {\r
169 uint32_t ulSavedInterruptMask;\r
170 \r
171         /* Clear the interrupt. */\r
172         RTCSC |= RTCSC_RTIF_MASK;\r
173 \r
174         /* Increment the RTOS tick. */\r
175         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
176         {\r
177                 if( xTaskIncrementTick() != pdFALSE )\r
178                 {\r
179                         taskYIELD();\r
180                 }\r
181         }\r
182         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
183 }\r
184 \r