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