]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/CodeWarrior/HCS12/port.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Source / portable / CodeWarrior / HCS12 / port.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /* Scheduler includes. */\r
67 #include "FreeRTOS.h"\r
68 #include "task.h"\r
69 \r
70 \r
71 /*-----------------------------------------------------------\r
72  * Implementation of functions defined in portable.h for the HCS12 port.\r
73  *----------------------------------------------------------*/\r
74 \r
75 \r
76 /*\r
77  * Configure a timer to generate the RTOS tick at the frequency specified \r
78  * within FreeRTOSConfig.h.\r
79  */\r
80 static void prvSetupTimerInterrupt( void );\r
81 \r
82 /* Interrupt service routines have to be in non-banked memory - as does the\r
83 scheduler startup function. */\r
84 #pragma CODE_SEG __NEAR_SEG NON_BANKED\r
85 \r
86         /* Manual context switch function.  This is the SWI ISR. */\r
87         void interrupt vPortYield( void );\r
88 \r
89         /* Tick context switch function.  This is the timer ISR. */\r
90         void interrupt vPortTickInterrupt( void );\r
91         \r
92         /* Simply called by xPortStartScheduler().  xPortStartScheduler() does not\r
93         start the scheduler directly because the header file containing the \r
94         xPortStartScheduler() prototype is part of the common kernel code, and \r
95         therefore cannot use the CODE_SEG pragma. */\r
96         static BaseType_t xBankedStartScheduler( void );\r
97 \r
98 #pragma CODE_SEG DEFAULT\r
99 \r
100 /* Calls to portENTER_CRITICAL() can be nested.  When they are nested the \r
101 critical section should not be left (i.e. interrupts should not be re-enabled)\r
102 until the nesting depth reaches 0.  This variable simply tracks the nesting \r
103 depth.  Each task maintains it's own critical nesting depth variable so \r
104 uxCriticalNesting is saved and restored from the task stack during a context\r
105 switch. */\r
106 volatile UBaseType_t uxCriticalNesting = 0xff;\r
107 \r
108 /*-----------------------------------------------------------*/\r
109 \r
110 /* \r
111  * See header file for description. \r
112  */\r
113 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
114 {\r
115         /* \r
116                 Place a few bytes of known values on the bottom of the stack.\r
117                 This can be uncommented to provide useful stack markers when debugging.\r
118 \r
119                 *pxTopOfStack = ( StackType_t ) 0x11;\r
120                 pxTopOfStack--;\r
121                 *pxTopOfStack = ( StackType_t ) 0x22;\r
122                 pxTopOfStack--;\r
123                 *pxTopOfStack = ( StackType_t ) 0x33;\r
124                 pxTopOfStack--;\r
125         */\r
126 \r
127 \r
128 \r
129         /* Setup the initial stack of the task.  The stack is set exactly as \r
130         expected by the portRESTORE_CONTEXT() macro.  In this case the stack as\r
131         expected by the HCS12 RTI instruction. */\r
132 \r
133 \r
134         /* The address of the task function is placed in the stack byte at a time. */\r
135         *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 1 );\r
136         pxTopOfStack--;\r
137         *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 0 );\r
138         pxTopOfStack--;\r
139 \r
140         /* Next are all the registers that form part of the task context. */\r
141 \r
142         /* Y register */\r
143         *pxTopOfStack = ( StackType_t ) 0xff;\r
144         pxTopOfStack--;\r
145         *pxTopOfStack = ( StackType_t ) 0xee;\r
146         pxTopOfStack--;\r
147 \r
148         /* X register */\r
149         *pxTopOfStack = ( StackType_t ) 0xdd;\r
150         pxTopOfStack--;\r
151         *pxTopOfStack = ( StackType_t ) 0xcc;\r
152         pxTopOfStack--;\r
153  \r
154         /* A register contains parameter high byte. */\r
155         *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 0 );\r
156         pxTopOfStack--;\r
157 \r
158         /* B register contains parameter low byte. */\r
159         *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 1 );\r
160         pxTopOfStack--;\r
161 \r
162         /* CCR: Note that when the task starts interrupts will be enabled since\r
163         "I" bit of CCR is cleared */\r
164         *pxTopOfStack = ( StackType_t ) 0x00;\r
165         pxTopOfStack--;\r
166         \r
167         #ifdef BANKED_MODEL\r
168                 /* The page of the task. */\r
169                 *pxTopOfStack = ( StackType_t ) ( ( int ) pxCode );\r
170                 pxTopOfStack--;\r
171         #endif\r
172         \r
173         /* Finally the critical nesting depth is initialised with 0 (not within\r
174         a critical section). */\r
175         *pxTopOfStack = ( StackType_t ) 0x00;\r
176 \r
177         return pxTopOfStack;\r
178 }\r
179 /*-----------------------------------------------------------*/\r
180 \r
181 void vPortEndScheduler( void )\r
182 {\r
183         /* It is unlikely that the HCS12 port will get stopped. */\r
184 }\r
185 /*-----------------------------------------------------------*/\r
186 \r
187 static void prvSetupTimerInterrupt( void )\r
188 {\r
189         TickTimer_SetFreqHz( configTICK_RATE_HZ );\r
190         TickTimer_Enable();\r
191 }\r
192 /*-----------------------------------------------------------*/\r
193 \r
194 BaseType_t xPortStartScheduler( void )\r
195 {\r
196         /* xPortStartScheduler() does not start the scheduler directly because \r
197         the header file containing the xPortStartScheduler() prototype is part \r
198         of the common kernel code, and therefore cannot use the CODE_SEG pragma. \r
199         Instead it simply calls the locally defined xBankedStartScheduler() - \r
200         which does use the CODE_SEG pragma. */\r
201 \r
202         return xBankedStartScheduler();\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 #pragma CODE_SEG __NEAR_SEG NON_BANKED\r
207 \r
208 static BaseType_t xBankedStartScheduler( void )\r
209 {\r
210         /* Configure the timer that will generate the RTOS tick.  Interrupts are\r
211         disabled when this function is called. */\r
212         prvSetupTimerInterrupt();\r
213 \r
214         /* Restore the context of the first task. */\r
215         portRESTORE_CONTEXT();\r
216 \r
217         /* Simulate the end of an interrupt to start the scheduler off. */\r
218         __asm( "rti" );\r
219 \r
220         /* Should not get here! */\r
221         return pdFALSE;\r
222 }\r
223 /*-----------------------------------------------------------*/\r
224 \r
225 /*\r
226  * Context switch functions.  These are both interrupt service routines.\r
227  */\r
228 \r
229 /*\r
230  * Manual context switch forced by calling portYIELD().  This is the SWI\r
231  * handler.\r
232  */\r
233 void interrupt vPortYield( void )\r
234 {\r
235         portSAVE_CONTEXT();\r
236         vTaskSwitchContext();\r
237         portRESTORE_CONTEXT();\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 /*\r
242  * RTOS tick interrupt service routine.  If the cooperative scheduler is \r
243  * being used then this simply increments the tick count.  If the \r
244  * preemptive scheduler is being used a context switch can occur.\r
245  */\r
246 void interrupt vPortTickInterrupt( void )\r
247 {\r
248         #if configUSE_PREEMPTION == 1\r
249         {\r
250                 /* A context switch might happen so save the context. */\r
251                 portSAVE_CONTEXT();\r
252 \r
253                 /* Increment the tick ... */\r
254                 if( xTaskIncrementTick() != pdFALSE )\r
255                 {\r
256                         vTaskSwitchContext();\r
257                 }\r
258 \r
259                 TFLG1 = 1;                                                                 \r
260 \r
261                 /* Restore the context of a task - which may be a different task\r
262                 to that interrupted. */\r
263                 portRESTORE_CONTEXT();  \r
264         }\r
265         #else\r
266         {\r
267                 xTaskIncrementTick();\r
268                 TFLG1 = 1;\r
269         }\r
270         #endif\r
271 }\r
272 \r
273 #pragma CODE_SEG DEFAULT\r
274 \r
275 \r