2 FreeRTOS V7.5.2 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* Scheduler includes. */
\r
66 #include "FreeRTOS.h"
\r
70 /*-----------------------------------------------------------
\r
71 * Implementation of functions defined in portable.h for the HCS12 port.
\r
72 *----------------------------------------------------------*/
\r
76 * Configure a timer to generate the RTOS tick at the frequency specified
\r
77 * within FreeRTOSConfig.h.
\r
79 static void prvSetupTimerInterrupt( void );
\r
81 /* Interrupt service routines have to be in non-banked memory - as does the
\r
82 scheduler startup function. */
\r
83 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
85 /* Manual context switch function. This is the SWI ISR. */
\r
86 void interrupt vPortYield( void );
\r
88 /* Tick context switch function. This is the timer ISR. */
\r
89 void interrupt vPortTickInterrupt( void );
\r
91 /* Simply called by xPortStartScheduler(). xPortStartScheduler() does not
\r
92 start the scheduler directly because the header file containing the
\r
93 xPortStartScheduler() prototype is part of the common kernel code, and
\r
94 therefore cannot use the CODE_SEG pragma. */
\r
95 static portBASE_TYPE xBankedStartScheduler( void );
\r
97 #pragma CODE_SEG DEFAULT
\r
99 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
100 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
101 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
102 depth. Each task maintains it's own critical nesting depth variable so
\r
103 uxCriticalNesting is saved and restored from the task stack during a context
\r
105 volatile unsigned portBASE_TYPE uxCriticalNesting = 0xff;
\r
107 /*-----------------------------------------------------------*/
\r
110 * See header file for description.
\r
112 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
115 Place a few bytes of known values on the bottom of the stack.
\r
116 This can be uncommented to provide useful stack markers when debugging.
\r
118 *pxTopOfStack = ( portSTACK_TYPE ) 0x11;
\r
120 *pxTopOfStack = ( portSTACK_TYPE ) 0x22;
\r
122 *pxTopOfStack = ( portSTACK_TYPE ) 0x33;
\r
128 /* Setup the initial stack of the task. The stack is set exactly as
\r
129 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
130 expected by the HCS12 RTI instruction. */
\r
133 /* The address of the task function is placed in the stack byte at a time. */
\r
134 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );
\r
136 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );
\r
139 /* Next are all the registers that form part of the task context. */
\r
142 *pxTopOfStack = ( portSTACK_TYPE ) 0xff;
\r
144 *pxTopOfStack = ( portSTACK_TYPE ) 0xee;
\r
148 *pxTopOfStack = ( portSTACK_TYPE ) 0xdd;
\r
150 *pxTopOfStack = ( portSTACK_TYPE ) 0xcc;
\r
153 /* A register contains parameter high byte. */
\r
154 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );
\r
157 /* B register contains parameter low byte. */
\r
158 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );
\r
161 /* CCR: Note that when the task starts interrupts will be enabled since
\r
162 "I" bit of CCR is cleared */
\r
163 *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
\r
166 #ifdef BANKED_MODEL
\r
167 /* The page of the task. */
\r
168 *pxTopOfStack = ( portSTACK_TYPE ) ( ( int ) pxCode );
\r
172 /* Finally the critical nesting depth is initialised with 0 (not within
\r
173 a critical section). */
\r
174 *pxTopOfStack = ( portSTACK_TYPE ) 0x00;
\r
176 return pxTopOfStack;
\r
178 /*-----------------------------------------------------------*/
\r
180 void vPortEndScheduler( void )
\r
182 /* It is unlikely that the HCS12 port will get stopped. */
\r
184 /*-----------------------------------------------------------*/
\r
186 static void prvSetupTimerInterrupt( void )
\r
188 TickTimer_SetFreqHz( configTICK_RATE_HZ );
\r
189 TickTimer_Enable();
\r
191 /*-----------------------------------------------------------*/
\r
193 portBASE_TYPE xPortStartScheduler( void )
\r
195 /* xPortStartScheduler() does not start the scheduler directly because
\r
196 the header file containing the xPortStartScheduler() prototype is part
\r
197 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
198 Instead it simply calls the locally defined xBankedStartScheduler() -
\r
199 which does use the CODE_SEG pragma. */
\r
201 return xBankedStartScheduler();
\r
203 /*-----------------------------------------------------------*/
\r
205 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
207 static portBASE_TYPE xBankedStartScheduler( void )
\r
209 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
210 disabled when this function is called. */
\r
211 prvSetupTimerInterrupt();
\r
213 /* Restore the context of the first task. */
\r
214 portRESTORE_CONTEXT();
\r
216 /* Simulate the end of an interrupt to start the scheduler off. */
\r
219 /* Should not get here! */
\r
222 /*-----------------------------------------------------------*/
\r
225 * Context switch functions. These are both interrupt service routines.
\r
229 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
232 void interrupt vPortYield( void )
\r
234 portSAVE_CONTEXT();
\r
235 vTaskSwitchContext();
\r
236 portRESTORE_CONTEXT();
\r
238 /*-----------------------------------------------------------*/
\r
241 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
242 * being used then this simply increments the tick count. If the
\r
243 * preemptive scheduler is being used a context switch can occur.
\r
245 void interrupt vPortTickInterrupt( void )
\r
247 #if configUSE_PREEMPTION == 1
\r
249 /* A context switch might happen so save the context. */
\r
250 portSAVE_CONTEXT();
\r
252 /* Increment the tick ... */
\r
253 if( xTaskIncrementTick() != pdFALSE )
\r
255 vTaskSwitchContext();
\r
260 /* Restore the context of a task - which may be a different task
\r
261 to that interrupted. */
\r
262 portRESTORE_CONTEXT();
\r
266 xTaskIncrementTick();
\r
272 #pragma CODE_SEG DEFAULT
\r