2 FreeRTOS V8.2.1 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
70 /* Scheduler includes. */
\r
71 #include "FreeRTOS.h"
\r
75 /*-----------------------------------------------------------
\r
76 * Implementation of functions defined in portable.h for the HCS12 port.
\r
77 *----------------------------------------------------------*/
\r
81 * Configure a timer to generate the RTOS tick at the frequency specified
\r
82 * within FreeRTOSConfig.h.
\r
84 static void prvSetupTimerInterrupt( void );
\r
86 /* Interrupt service routines have to be in non-banked memory - as does the
\r
87 scheduler startup function. */
\r
88 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
90 /* Manual context switch function. This is the SWI ISR. */
\r
91 void interrupt vPortYield( void );
\r
93 /* Tick context switch function. This is the timer ISR. */
\r
94 void interrupt vPortTickInterrupt( void );
\r
96 /* Simply called by xPortStartScheduler(). xPortStartScheduler() does not
\r
97 start the scheduler directly because the header file containing the
\r
98 xPortStartScheduler() prototype is part of the common kernel code, and
\r
99 therefore cannot use the CODE_SEG pragma. */
\r
100 static BaseType_t xBankedStartScheduler( void );
\r
102 #pragma CODE_SEG DEFAULT
\r
104 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
105 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
106 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
107 depth. Each task maintains it's own critical nesting depth variable so
\r
108 uxCriticalNesting is saved and restored from the task stack during a context
\r
110 volatile UBaseType_t uxCriticalNesting = 0xff;
\r
112 /*-----------------------------------------------------------*/
\r
115 * See header file for description.
\r
117 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
120 Place a few bytes of known values on the bottom of the stack.
\r
121 This can be uncommented to provide useful stack markers when debugging.
\r
123 *pxTopOfStack = ( StackType_t ) 0x11;
\r
125 *pxTopOfStack = ( StackType_t ) 0x22;
\r
127 *pxTopOfStack = ( StackType_t ) 0x33;
\r
133 /* Setup the initial stack of the task. The stack is set exactly as
\r
134 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
135 expected by the HCS12 RTI instruction. */
\r
138 /* The address of the task function is placed in the stack byte at a time. */
\r
139 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 1 );
\r
141 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 0 );
\r
144 /* Next are all the registers that form part of the task context. */
\r
147 *pxTopOfStack = ( StackType_t ) 0xff;
\r
149 *pxTopOfStack = ( StackType_t ) 0xee;
\r
153 *pxTopOfStack = ( StackType_t ) 0xdd;
\r
155 *pxTopOfStack = ( StackType_t ) 0xcc;
\r
158 /* A register contains parameter high byte. */
\r
159 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 0 );
\r
162 /* B register contains parameter low byte. */
\r
163 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 1 );
\r
166 /* CCR: Note that when the task starts interrupts will be enabled since
\r
167 "I" bit of CCR is cleared */
\r
168 *pxTopOfStack = ( StackType_t ) 0x00;
\r
171 #ifdef BANKED_MODEL
\r
172 /* The page of the task. */
\r
173 *pxTopOfStack = ( StackType_t ) ( ( int ) pxCode );
\r
177 /* Finally the critical nesting depth is initialised with 0 (not within
\r
178 a critical section). */
\r
179 *pxTopOfStack = ( StackType_t ) 0x00;
\r
181 return pxTopOfStack;
\r
183 /*-----------------------------------------------------------*/
\r
185 void vPortEndScheduler( void )
\r
187 /* It is unlikely that the HCS12 port will get stopped. */
\r
189 /*-----------------------------------------------------------*/
\r
191 static void prvSetupTimerInterrupt( void )
\r
193 TickTimer_SetFreqHz( configTICK_RATE_HZ );
\r
194 TickTimer_Enable();
\r
196 /*-----------------------------------------------------------*/
\r
198 BaseType_t xPortStartScheduler( void )
\r
200 /* xPortStartScheduler() does not start the scheduler directly because
\r
201 the header file containing the xPortStartScheduler() prototype is part
\r
202 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
203 Instead it simply calls the locally defined xBankedStartScheduler() -
\r
204 which does use the CODE_SEG pragma. */
\r
206 return xBankedStartScheduler();
\r
208 /*-----------------------------------------------------------*/
\r
210 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
212 static BaseType_t xBankedStartScheduler( void )
\r
214 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
215 disabled when this function is called. */
\r
216 prvSetupTimerInterrupt();
\r
218 /* Restore the context of the first task. */
\r
219 portRESTORE_CONTEXT();
\r
221 /* Simulate the end of an interrupt to start the scheduler off. */
\r
224 /* Should not get here! */
\r
227 /*-----------------------------------------------------------*/
\r
230 * Context switch functions. These are both interrupt service routines.
\r
234 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
237 void interrupt vPortYield( void )
\r
239 portSAVE_CONTEXT();
\r
240 vTaskSwitchContext();
\r
241 portRESTORE_CONTEXT();
\r
243 /*-----------------------------------------------------------*/
\r
246 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
247 * being used then this simply increments the tick count. If the
\r
248 * preemptive scheduler is being used a context switch can occur.
\r
250 void interrupt vPortTickInterrupt( void )
\r
252 #if configUSE_PREEMPTION == 1
\r
254 /* A context switch might happen so save the context. */
\r
255 portSAVE_CONTEXT();
\r
257 /* Increment the tick ... */
\r
258 if( xTaskIncrementTick() != pdFALSE )
\r
260 vTaskSwitchContext();
\r
265 /* Restore the context of a task - which may be a different task
\r
266 to that interrupted. */
\r
267 portRESTORE_CONTEXT();
\r
271 xTaskIncrementTick();
\r
277 #pragma CODE_SEG DEFAULT
\r