]> git.sur5r.net Git - freertos/blob - Source/portable/CodeWarrior/HCS12/port.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Source / portable / CodeWarrior / HCS12 / port.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     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 without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /* Scheduler includes. */\r
50 #include "FreeRTOS.h"\r
51 #include "task.h"\r
52 \r
53 \r
54 /*-----------------------------------------------------------\r
55  * Implementation of functions defined in portable.h for the HCS12 port.\r
56  *----------------------------------------------------------*/\r
57 \r
58 \r
59 /*\r
60  * Configure a timer to generate the RTOS tick at the frequency specified \r
61  * within FreeRTOSConfig.h.\r
62  */\r
63 static void prvSetupTimerInterrupt( void );\r
64 \r
65 /* Interrupt service routines have to be in non-banked memory - as does the\r
66 scheduler startup function. */\r
67 #pragma CODE_SEG __NEAR_SEG NON_BANKED\r
68 \r
69         /* Manual context switch function.  This is the SWI ISR. */\r
70         void interrupt vPortYield( void );\r
71 \r
72         /* Tick context switch function.  This is the timer ISR. */\r
73         void interrupt vPortTickInterrupt( void );\r
74         \r
75         /* Simply called by xPortStartScheduler().  xPortStartScheduler() does not\r
76         start the scheduler directly because the header file containing the \r
77         xPortStartScheduler() prototype is part of the common kernel code, and \r
78         therefore cannot use the CODE_SEG pragma. */\r
79         static portBASE_TYPE xBankedStartScheduler( void );\r
80 \r
81 #pragma CODE_SEG DEFAULT\r
82 \r
83 /* Calls to portENTER_CRITICAL() can be nested.  When they are nested the \r
84 critical section should not be left (i.e. interrupts should not be re-enabled)\r
85 until the nesting depth reaches 0.  This variable simply tracks the nesting \r
86 depth.  Each task maintains it's own critical nesting depth variable so \r
87 uxCriticalNesting is saved and restored from the task stack during a context\r
88 switch. */\r
89 volatile unsigned portBASE_TYPE uxCriticalNesting = 0xff;\r
90 \r
91 /*-----------------------------------------------------------*/\r
92 \r
93 /* \r
94  * See header file for description. \r
95  */\r
96 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
97 {\r
98         /* \r
99                 Place a few bytes of known values on the bottom of the stack.\r
100                 This can be uncommented to provide useful stack markers when debugging.\r
101 \r
102                 *pxTopOfStack = ( portSTACK_TYPE ) 0x11;\r
103                 pxTopOfStack--;\r
104                 *pxTopOfStack = ( portSTACK_TYPE ) 0x22;\r
105                 pxTopOfStack--;\r
106                 *pxTopOfStack = ( portSTACK_TYPE ) 0x33;\r
107                 pxTopOfStack--;\r
108         */\r
109 \r
110 \r
111 \r
112         /* Setup the initial stack of the task.  The stack is set exactly as \r
113         expected by the portRESTORE_CONTEXT() macro.  In this case the stack as\r
114         expected by the HCS12 RTI instruction. */\r
115 \r
116 \r
117         /* The address of the task function is placed in the stack byte at a time. */\r
118         *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );\r
119         pxTopOfStack--;\r
120         *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );\r
121         pxTopOfStack--;\r
122 \r
123         /* Next are all the registers that form part of the task context. */\r
124 \r
125         /* Y register */\r
126         *pxTopOfStack = ( portSTACK_TYPE ) 0xff;\r
127         pxTopOfStack--;\r
128         *pxTopOfStack = ( portSTACK_TYPE ) 0xee;\r
129         pxTopOfStack--;\r
130 \r
131         /* X register */\r
132         *pxTopOfStack = ( portSTACK_TYPE ) 0xdd;\r
133         pxTopOfStack--;\r
134         *pxTopOfStack = ( portSTACK_TYPE ) 0xcc;\r
135         pxTopOfStack--;\r
136  \r
137         /* A register contains parameter high byte. */\r
138         *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );\r
139         pxTopOfStack--;\r
140 \r
141         /* B register contains parameter low byte. */\r
142         *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );\r
143         pxTopOfStack--;\r
144 \r
145         /* CCR: Note that when the task starts interrupts will be enabled since\r
146         "I" bit of CCR is cleared */\r
147         *pxTopOfStack = ( portSTACK_TYPE ) 0x00;\r
148         pxTopOfStack--;\r
149         \r
150         #ifdef BANKED_MODEL\r
151                 /* The page of the task. */\r
152                 *pxTopOfStack = ( portSTACK_TYPE ) ( ( int ) pxCode );\r
153                 pxTopOfStack--;\r
154         #endif\r
155         \r
156         /* Finally the critical nesting depth is initialised with 0 (not within\r
157         a critical section). */\r
158         *pxTopOfStack = ( portSTACK_TYPE ) 0x00;\r
159 \r
160         return pxTopOfStack;\r
161 }\r
162 /*-----------------------------------------------------------*/\r
163 \r
164 void vPortEndScheduler( void )\r
165 {\r
166         /* It is unlikely that the HCS12 port will get stopped. */\r
167 }\r
168 /*-----------------------------------------------------------*/\r
169 \r
170 static void prvSetupTimerInterrupt( void )\r
171 {\r
172         TickTimer_SetFreqHz( configTICK_RATE_HZ );\r
173         TickTimer_Enable();\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 portBASE_TYPE xPortStartScheduler( void )\r
178 {\r
179         /* xPortStartScheduler() does not start the scheduler directly because \r
180         the header file containing the xPortStartScheduler() prototype is part \r
181         of the common kernel code, and therefore cannot use the CODE_SEG pragma. \r
182         Instead it simply calls the locally defined xBankedStartScheduler() - \r
183         which does use the CODE_SEG pragma. */\r
184 \r
185         return xBankedStartScheduler();\r
186 }\r
187 /*-----------------------------------------------------------*/\r
188 \r
189 #pragma CODE_SEG __NEAR_SEG NON_BANKED\r
190 \r
191 static portBASE_TYPE xBankedStartScheduler( void )\r
192 {\r
193         /* Configure the timer that will generate the RTOS tick.  Interrupts are\r
194         disabled when this function is called. */\r
195         prvSetupTimerInterrupt();\r
196 \r
197         /* Restore the context of the first task. */\r
198         portRESTORE_CONTEXT();\r
199 \r
200         /* Simulate the end of an interrupt to start the scheduler off. */\r
201         __asm( "rti" );\r
202 \r
203         /* Should not get here! */\r
204         return pdFALSE;\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 /*\r
209  * Context switch functions.  These are both interrupt service routines.\r
210  */\r
211 \r
212 /*\r
213  * Manual context switch forced by calling portYIELD().  This is the SWI\r
214  * handler.\r
215  */\r
216 void interrupt vPortYield( void )\r
217 {\r
218         portSAVE_CONTEXT();\r
219         vTaskSwitchContext();\r
220         portRESTORE_CONTEXT();\r
221 }\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 /*\r
225  * RTOS tick interrupt service routine.  If the cooperative scheduler is \r
226  * being used then this simply increments the tick count.  If the \r
227  * preemptive scheduler is being used a context switch can occur.\r
228  */\r
229 void interrupt vPortTickInterrupt( void )\r
230 {\r
231         #if configUSE_PREEMPTION == 1\r
232         {\r
233                 /* A context switch might happen so save the context. */\r
234                 portSAVE_CONTEXT();\r
235 \r
236                 /* Increment the tick ... */\r
237                 vTaskIncrementTick();\r
238 \r
239                 /* ... then see if the new tick value has necessitated a\r
240                 context switch. */\r
241                 vTaskSwitchContext();\r
242 \r
243                 TFLG1 = 1;                                                                 \r
244 \r
245                 /* Restore the context of a task - which may be a different task\r
246                 to that interrupted. */\r
247                 portRESTORE_CONTEXT();  \r
248         }\r
249         #else\r
250         {\r
251                 vTaskIncrementTick();\r
252                 TFLG1 = 1;\r
253         }\r
254         #endif\r
255 }\r
256 \r
257 #pragma CODE_SEG DEFAULT\r
258 \r
259 \r