]> git.sur5r.net Git - freertos/blob - Source/portable/CodeWarrior/ColdFire_V1/port.c
Update version number.
[freertos] / Source / portable / CodeWarrior / ColdFire_V1 / port.c
1 /*\r
2         FreeRTOS.org V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify it\r
7         under the terms of the GNU General Public License (version 2) as published\r
8         by the Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS.org without being obliged to provide\r
11         the source code for any proprietary components.  Alternative commercial\r
12         license and support terms are also available upon request.  See the \r
13         licensing section of http://www.FreeRTOS.org for full details.\r
14 \r
15         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
16         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
17         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
18         more details.\r
19 \r
20         You should have received a copy of the GNU General Public License along\r
21         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
22         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\r
29         * This is a concise, step by step, 'hands on' guide that describes both   *\r
30         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
31         * explains numerous examples that are written using the FreeRTOS API.     *\r
32         * Full source code for all the examples is provided in an accompanying    *\r
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 /* Kernel includes. */\r
53 #include "FreeRTOS.h"\r
54 #include "task.h"\r
55 \r
56 \r
57 #define portINITIAL_FORMAT_VECTOR               ( ( portSTACK_TYPE ) 0x4000 )\r
58 \r
59 /* Supervisor mode set. */\r
60 #define portINITIAL_STATUS_REGISTER             ( ( portSTACK_TYPE ) 0x2000)\r
61 \r
62 /* The clock prescale into the timer peripheral. */\r
63 #define portPRESCALE_VALUE                              ( ( unsigned portCHAR ) 10 )\r
64 \r
65 /* The clock frequency into the RTC. */\r
66 #define portRTC_CLOCK_HZ                                ( ( unsigned portLONG ) 1000 )\r
67 \r
68 asm void interrupt VectorNumber_VL1swi vPortYieldISR( void );\r
69 static void prvSetupTimerInterrupt( void );\r
70 \r
71 /* Used to keep track of the number of nested calls to taskENTER_CRITICAL().  This\r
72 will be set to 0 prior to the first task being started. */\r
73 static unsigned portLONG ulCriticalNesting = 0x9999UL;\r
74 \r
75 /*-----------------------------------------------------------*/\r
76 \r
77 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE * pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
78 {\r
79 \r
80 unsigned portLONG ulOriginalA5;\r
81 \r
82         __asm{ MOVE.L A5, ulOriginalA5 };\r
83 \r
84 \r
85         *pxTopOfStack = (portSTACK_TYPE) 0xDEADBEEF;\r
86         pxTopOfStack--;\r
87 \r
88         /* Exception stack frame starts with the return address. */\r
89         *pxTopOfStack = ( portSTACK_TYPE ) pxCode;\r
90         pxTopOfStack--;\r
91 \r
92         *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );\r
93         pxTopOfStack--;\r
94 \r
95         *pxTopOfStack = ( portSTACK_TYPE ) 0x0; /*FP*/\r
96         pxTopOfStack -= 14; /* A5 to D0. */\r
97 \r
98         /* Parameter in A0. */\r
99         *( pxTopOfStack + 8 ) = ( portSTACK_TYPE ) pvParameters;\r
100 \r
101         /* A5 must be maintained as it is resurved by the compiler. */\r
102         *( pxTopOfStack + 13 ) = ulOriginalA5;\r
103 \r
104         return pxTopOfStack;  \r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 portBASE_TYPE xPortStartScheduler( void )\r
109 {\r
110 extern void vPortStartFirstTask( void );\r
111 \r
112         ulCriticalNesting = 0UL;\r
113 \r
114         /* Configure a timer to generate the tick interrupt. */\r
115         prvSetupTimerInterrupt();\r
116 \r
117         /* Start the first task executing. */\r
118         vPortStartFirstTask();\r
119 \r
120         return pdFALSE;\r
121 }\r
122 /*-----------------------------------------------------------*/\r
123 \r
124 static void prvSetupTimerInterrupt( void )\r
125 {                               \r
126         /* Prescale by 1 - ie no prescale. */\r
127         RTCSC |= 8;\r
128         \r
129         /* Compare match value. */\r
130         RTCMOD = portRTC_CLOCK_HZ / configTICK_RATE_HZ;\r
131         \r
132         /* Enable the RTC to generate interrupts - interrupts are already disabled\r
133         when this code executes. */\r
134         RTCSC_RTIE = 1;\r
135 }\r
136 /*-----------------------------------------------------------*/\r
137 \r
138 void vPortEndScheduler( void )\r
139 {\r
140         /* Not implemented as there is nothing to return to. */\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 void vPortEnterCritical( void )\r
145 {\r
146         if( ulCriticalNesting == 0UL )\r
147         {\r
148                 /* Guard against context switches being pended simultaneously with a\r
149                 critical section being entered. */\r
150                 do\r
151                 {\r
152                         portDISABLE_INTERRUPTS();\r
153                         if( INTC_FRC == 0UL )\r
154                         {\r
155                                 break;\r
156                         }\r
157 \r
158                         portENABLE_INTERRUPTS();\r
159 \r
160                 } while( 1 );\r
161         }\r
162         ulCriticalNesting++;\r
163 }\r
164 /*-----------------------------------------------------------*/\r
165 \r
166 void vPortExitCritical( void )\r
167 {\r
168         ulCriticalNesting--;\r
169         if( ulCriticalNesting == 0 )\r
170         {\r
171                 portENABLE_INTERRUPTS();\r
172         }\r
173 }\r
174 /*-----------------------------------------------------------*/\r
175 \r
176 void vPortYieldHandler( void )\r
177 {\r
178 unsigned portLONG ulSavedInterruptMask;\r
179 \r
180         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
181         {\r
182                 /* Note this will clear all forced interrupts - this is done for speed. */\r
183                 INTC_CFRC = 0x3E;\r
184                 vTaskSwitchContext();\r
185         }\r
186         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
187 }\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 void interrupt VectorNumber_Vrtc vPortTickISR( void )\r
191 {\r
192 unsigned portLONG ulSavedInterruptMask;\r
193 \r
194         /* Clear the interrupt. */\r
195         RTCSC |= RTCSC_RTIF_MASK;\r
196 \r
197         /* Increment the RTOS tick. */\r
198         ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();\r
199         {\r
200                 vTaskIncrementTick();\r
201         }\r
202         portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );\r
203 \r
204         /* If we are using the pre-emptive scheduler then also request a\r
205         context switch as incrementing the tick could have unblocked a task. */\r
206         #if configUSE_PREEMPTION == 1\r
207         {\r
208                 taskYIELD();\r
209         }\r
210         #endif\r
211 }\r
212 \r