2 FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS distribution.
\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
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
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
26 ***************************************************************************
\r
28 * Looking for a quick start? Then check out the FreeRTOS eBook! *
\r
29 * See http://www.FreeRTOS.org/Documentation for details *
\r
31 ***************************************************************************
\r
35 Please ensure to read the configuration and relevant port sections of the
\r
36 online documentation.
\r
38 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
41 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
44 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
45 licensing and training services.
\r
48 /* Scheduler includes. */
\r
49 #include "FreeRTOS.h"
\r
53 /*-----------------------------------------------------------
\r
54 * Implementation of functions defined in portable.h for the HCS12 port.
\r
55 *----------------------------------------------------------*/
\r
59 * Configure a timer to generate the RTOS tick at the frequency specified
\r
60 * within FreeRTOSConfig.h.
\r
62 static void prvSetupTimerInterrupt( void );
\r
64 /* Interrupt service routines have to be in non-banked memory - as does the
\r
65 scheduler startup function. */
\r
66 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
68 /* Manual context switch function. This is the SWI ISR. */
\r
69 void interrupt vPortYield( void );
\r
71 /* Tick context switch function. This is the timer ISR. */
\r
72 void interrupt vPortTickInterrupt( void );
\r
74 /* Simply called by xPortStartScheduler(). xPortStartScheduler() does not
\r
75 start the scheduler directly because the header file containing the
\r
76 xPortStartScheduler() prototype is part of the common kernel code, and
\r
77 therefore cannot use the CODE_SEG pragma. */
\r
78 static portBASE_TYPE xBankedStartScheduler( void );
\r
80 #pragma CODE_SEG DEFAULT
\r
82 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
83 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
84 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
85 depth. Each task maintains it's own critical nesting depth variable so
\r
86 uxCriticalNesting is saved and restored from the task stack during a context
\r
88 volatile unsigned portBASE_TYPE uxCriticalNesting = 0xff;
\r
90 /*-----------------------------------------------------------*/
\r
93 * See header file for description.
\r
95 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
98 Place a few bytes of known values on the bottom of the stack.
\r
99 This can be uncommented to provide useful stack markers when debugging.
\r
101 *pxTopOfStack = ( portSTACK_TYPE ) 0x11;
\r
103 *pxTopOfStack = ( portSTACK_TYPE ) 0x22;
\r
105 *pxTopOfStack = ( portSTACK_TYPE ) 0x33;
\r
111 /* Setup the initial stack of the task. The stack is set exactly as
\r
112 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
113 expected by the HCS12 RTI instruction. */
\r
116 /* The address of the task function is placed in the stack byte at a time. */
\r
117 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );
\r
119 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );
\r
122 /* Next are all the registers that form part of the task context. */
\r
125 *pxTopOfStack = ( portSTACK_TYPE ) 0xff;
\r
127 *pxTopOfStack = ( portSTACK_TYPE ) 0xee;
\r
131 *pxTopOfStack = ( portSTACK_TYPE ) 0xdd;
\r
133 *pxTopOfStack = ( portSTACK_TYPE ) 0xcc;
\r
136 /* A register contains parameter high byte. */
\r
137 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );
\r
140 /* B register contains parameter low byte. */
\r
141 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );
\r
144 /* CCR: Note that when the task starts interrupts will be enabled since
\r
145 "I" bit of CCR is cleared */
\r
146 *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
\r
149 #ifdef BANKED_MODEL
\r
150 /* The page of the task. */
\r
151 *pxTopOfStack = ( portSTACK_TYPE ) ( ( int ) pxCode );
\r
155 /* Finally the critical nesting depth is initialised with 0 (not within
\r
156 a critical section). */
\r
157 *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
\r
159 return pxTopOfStack;
\r
161 /*-----------------------------------------------------------*/
\r
163 void vPortEndScheduler( void )
\r
165 /* It is unlikely that the HCS12 port will get stopped. */
\r
167 /*-----------------------------------------------------------*/
\r
169 static void prvSetupTimerInterrupt( void )
\r
171 TickTimer_SetFreqHz( configTICK_RATE_HZ );
\r
172 TickTimer_Enable();
\r
174 /*-----------------------------------------------------------*/
\r
176 portBASE_TYPE xPortStartScheduler( void )
\r
178 /* xPortStartScheduler() does not start the scheduler directly because
\r
179 the header file containing the xPortStartScheduler() prototype is part
\r
180 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
181 Instead it simply calls the locally defined xBankedStartScheduler() -
\r
182 which does use the CODE_SEG pragma. */
\r
184 return xBankedStartScheduler();
\r
186 /*-----------------------------------------------------------*/
\r
188 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
190 static portBASE_TYPE xBankedStartScheduler( void )
\r
192 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
193 disabled when this function is called. */
\r
194 prvSetupTimerInterrupt();
\r
196 /* Restore the context of the first task. */
\r
197 portRESTORE_CONTEXT();
\r
199 /* Simulate the end of an interrupt to start the scheduler off. */
\r
202 /* Should not get here! */
\r
205 /*-----------------------------------------------------------*/
\r
208 * Context switch functions. These are both interrupt service routines.
\r
212 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
215 void interrupt vPortYield( void )
\r
217 portSAVE_CONTEXT();
\r
218 vTaskSwitchContext();
\r
219 portRESTORE_CONTEXT();
\r
221 /*-----------------------------------------------------------*/
\r
224 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
225 * being used then this simply increments the tick count. If the
\r
226 * preemptive scheduler is being used a context switch can occur.
\r
228 void interrupt vPortTickInterrupt( void )
\r
230 #if configUSE_PREEMPTION == 1
\r
232 /* A context switch might happen so save the context. */
\r
233 portSAVE_CONTEXT();
\r
235 /* Increment the tick ... */
\r
236 vTaskIncrementTick();
\r
238 /* ... then see if the new tick value has necessitated a
\r
240 vTaskSwitchContext();
\r
244 /* Restore the context of a task - which may be a different task
\r
245 to that interrupted. */
\r
246 portRESTORE_CONTEXT();
\r
250 vTaskIncrementTick();
\r
256 #pragma CODE_SEG DEFAULT
\r