2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
67 /* Scheduler includes. */
\r
68 #include "FreeRTOS.h"
\r
72 /*-----------------------------------------------------------
\r
73 * Implementation of functions defined in portable.h for the HCS12 port.
\r
74 *----------------------------------------------------------*/
\r
78 * Configure a timer to generate the RTOS tick at the frequency specified
\r
79 * within FreeRTOSConfig.h.
\r
81 static void prvSetupTimerInterrupt( void );
\r
83 /* Interrupt service routines have to be in non-banked memory - as does the
\r
84 scheduler startup function. */
\r
85 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
87 /* Manual context switch function. This is the SWI ISR. */
\r
88 void interrupt vPortYield( void );
\r
90 /* Tick context switch function. This is the timer ISR. */
\r
91 void interrupt vPortTickInterrupt( void );
\r
93 /* Simply called by xPortStartScheduler(). xPortStartScheduler() does not
\r
94 start the scheduler directly because the header file containing the
\r
95 xPortStartScheduler() prototype is part of the common kernel code, and
\r
96 therefore cannot use the CODE_SEG pragma. */
\r
97 static portBASE_TYPE xBankedStartScheduler( void );
\r
99 #pragma CODE_SEG DEFAULT
\r
101 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
102 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
103 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
104 depth. Each task maintains it's own critical nesting depth variable so
\r
105 uxCriticalNesting is saved and restored from the task stack during a context
\r
107 volatile unsigned portBASE_TYPE uxCriticalNesting = 0xff;
\r
109 /*-----------------------------------------------------------*/
\r
112 * See header file for description.
\r
114 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
117 Place a few bytes of known values on the bottom of the stack.
\r
118 This can be uncommented to provide useful stack markers when debugging.
\r
120 *pxTopOfStack = ( portSTACK_TYPE ) 0x11;
\r
122 *pxTopOfStack = ( portSTACK_TYPE ) 0x22;
\r
124 *pxTopOfStack = ( portSTACK_TYPE ) 0x33;
\r
130 /* Setup the initial stack of the task. The stack is set exactly as
\r
131 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
132 expected by the HCS12 RTI instruction. */
\r
135 /* The address of the task function is placed in the stack byte at a time. */
\r
136 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );
\r
138 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );
\r
141 /* Next are all the registers that form part of the task context. */
\r
144 *pxTopOfStack = ( portSTACK_TYPE ) 0xff;
\r
146 *pxTopOfStack = ( portSTACK_TYPE ) 0xee;
\r
150 *pxTopOfStack = ( portSTACK_TYPE ) 0xdd;
\r
152 *pxTopOfStack = ( portSTACK_TYPE ) 0xcc;
\r
155 /* A register contains parameter high byte. */
\r
156 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );
\r
159 /* B register contains parameter low byte. */
\r
160 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );
\r
163 /* CCR: Note that when the task starts interrupts will be enabled since
\r
164 "I" bit of CCR is cleared */
\r
165 *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
\r
168 #ifdef BANKED_MODEL
\r
169 /* The page of the task. */
\r
170 *pxTopOfStack = ( portSTACK_TYPE ) ( ( int ) pxCode );
\r
174 /* Finally the critical nesting depth is initialised with 0 (not within
\r
175 a critical section). */
\r
176 *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
\r
178 return pxTopOfStack;
\r
180 /*-----------------------------------------------------------*/
\r
182 void vPortEndScheduler( void )
\r
184 /* It is unlikely that the HCS12 port will get stopped. */
\r
186 /*-----------------------------------------------------------*/
\r
188 static void prvSetupTimerInterrupt( void )
\r
190 TickTimer_SetFreqHz( configTICK_RATE_HZ );
\r
191 TickTimer_Enable();
\r
193 /*-----------------------------------------------------------*/
\r
195 portBASE_TYPE xPortStartScheduler( void )
\r
197 /* xPortStartScheduler() does not start the scheduler directly because
\r
198 the header file containing the xPortStartScheduler() prototype is part
\r
199 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
200 Instead it simply calls the locally defined xBankedStartScheduler() -
\r
201 which does use the CODE_SEG pragma. */
\r
203 return xBankedStartScheduler();
\r
205 /*-----------------------------------------------------------*/
\r
207 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
209 static portBASE_TYPE xBankedStartScheduler( void )
\r
211 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
212 disabled when this function is called. */
\r
213 prvSetupTimerInterrupt();
\r
215 /* Restore the context of the first task. */
\r
216 portRESTORE_CONTEXT();
\r
218 /* Simulate the end of an interrupt to start the scheduler off. */
\r
221 /* Should not get here! */
\r
224 /*-----------------------------------------------------------*/
\r
227 * Context switch functions. These are both interrupt service routines.
\r
231 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
234 void interrupt vPortYield( void )
\r
236 portSAVE_CONTEXT();
\r
237 vTaskSwitchContext();
\r
238 portRESTORE_CONTEXT();
\r
240 /*-----------------------------------------------------------*/
\r
243 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
244 * being used then this simply increments the tick count. If the
\r
245 * preemptive scheduler is being used a context switch can occur.
\r
247 void interrupt vPortTickInterrupt( void )
\r
249 #if configUSE_PREEMPTION == 1
\r
251 /* A context switch might happen so save the context. */
\r
252 portSAVE_CONTEXT();
\r
254 /* Increment the tick ... */
\r
255 vTaskIncrementTick();
\r
257 /* ... then see if the new tick value has necessitated a
\r
259 vTaskSwitchContext();
\r
263 /* Restore the context of a task - which may be a different task
\r
264 to that interrupted. */
\r
265 portRESTORE_CONTEXT();
\r
269 vTaskIncrementTick();
\r
275 #pragma CODE_SEG DEFAULT
\r