2 FreeRTOS V8.2.0 - 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 /* GCC/HCS12 port by Jefferson L Smith, 2005 */
\r
72 /* Scheduler includes. */
\r
73 #include "FreeRTOS.h"
\r
77 #include <sys/ports_def.h>
\r
79 /*-----------------------------------------------------------
\r
80 * Implementation of functions defined in portable.h for the HCS12 port.
\r
81 *----------------------------------------------------------*/
\r
85 * Configure a timer to generate the RTOS tick at the frequency specified
\r
86 * within FreeRTOSConfig.h.
\r
88 static void prvSetupTimerInterrupt( void );
\r
90 /* NOTE: Interrupt service routines must be in non-banked memory - as does the
\r
91 scheduler startup function. */
\r
92 #define ATTR_NEAR __attribute__((near))
\r
94 /* Manual context switch function. This is the SWI ISR. */
\r
95 // __attribute__((interrupt))
\r
96 void ATTR_NEAR vPortYield( void );
\r
98 /* Tick context switch function. This is the timer ISR. */
\r
99 // __attribute__((interrupt))
\r
100 void ATTR_NEAR vPortTickInterrupt( void );
\r
102 /* Function in non-banked memory which actually switches to first task. */
\r
103 BaseType_t ATTR_NEAR xStartSchedulerNear( void );
\r
105 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
106 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
107 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
108 depth. Each task maintains it's own critical nesting depth variable so
\r
109 uxCriticalNesting is saved and restored from the task stack during a context
\r
111 volatile UBaseType_t uxCriticalNesting = 0x80; // un-initialized
\r
113 /*-----------------------------------------------------------*/
\r
116 * See header file for description.
\r
118 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
122 /* Setup the initial stack of the task. The stack is set exactly as
\r
123 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
124 expected by the HCS12 RTI instruction. */
\r
127 /* The address of the task function is placed in the stack byte at a time. */
\r
128 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 1 );
\r
129 *--pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 0 );
\r
131 /* Next are all the registers that form part of the task context. */
\r
134 *--pxTopOfStack = ( StackType_t ) 0xff;
\r
135 *--pxTopOfStack = ( StackType_t ) 0xee;
\r
138 *--pxTopOfStack = ( StackType_t ) 0xdd;
\r
139 *--pxTopOfStack = ( StackType_t ) 0xcc;
\r
141 /* A register contains parameter high byte. */
\r
142 *--pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 0 );
\r
144 /* B register contains parameter low byte. */
\r
145 *--pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 1 );
\r
147 /* CCR: Note that when the task starts interrupts will be enabled since
\r
148 "I" bit of CCR is cleared */
\r
149 *--pxTopOfStack = ( StackType_t ) 0x80; // keeps Stop disabled (MCU default)
\r
151 /* tmp softregs used by GCC. Values right now don't matter. */
\r
153 movw _.frame, 2,-%0 \n\
\r
154 movw _.tmp, 2,-%0 \n\
\r
155 movw _.z, 2,-%0 \n\
\r
156 movw _.xy, 2,-%0 \n\
\r
157 ;movw _.d2, 2,-%0 \n\
\r
158 ;movw _.d1, 2,-%0 \n\
\r
159 ": "=A"(pxTopOfStack) : "0"(pxTopOfStack) );
\r
161 #ifdef BANKED_MODEL
\r
162 /* The page of the task. */
\r
163 *--pxTopOfStack = 0x30; // can only directly start in PPAGE 0x30
\r
166 /* The critical nesting depth is initialised with 0 (meaning not in
\r
167 a critical section). */
\r
168 *--pxTopOfStack = ( StackType_t ) 0x00;
\r
171 return pxTopOfStack;
\r
173 /*-----------------------------------------------------------*/
\r
175 void vPortEndScheduler( void )
\r
177 /* It is unlikely that the HCS12 port will get stopped. */
\r
179 /*-----------------------------------------------------------*/
\r
181 static void prvSetupTimerInterrupt( void )
\r
183 /* Enable hardware RTI timer */
\r
184 /* Ignores configTICK_RATE_HZ */
\r
185 RTICTL = 0x50; // 16 MHz xtal: 976.56 Hz, 1024mS
\r
186 CRGINT |= 0x80; // RTIE
\r
188 /*-----------------------------------------------------------*/
\r
190 BaseType_t xPortStartScheduler( void )
\r
192 /* xPortStartScheduler() does not start the scheduler directly because
\r
193 the header file containing the xPortStartScheduler() prototype is part
\r
194 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
195 Instead it simply calls the locally defined xNearStartScheduler() -
\r
196 which does use the CODE_SEG pragma. */
\r
198 int16_t register d;
\r
199 __asm ("jmp xStartSchedulerNear ; will never return": "=d"(d));
\r
202 /*-----------------------------------------------------------*/
\r
204 BaseType_t xStartSchedulerNear( void )
\r
206 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
207 disabled when this function is called. */
\r
208 prvSetupTimerInterrupt();
\r
210 /* Restore the context of the first task. */
\r
211 portRESTORE_CONTEXT();
\r
215 /* Should not get here! */
\r
218 /*-----------------------------------------------------------*/
\r
221 * Context switch functions. These are interrupt service routines.
\r
225 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
228 void vPortYield( void )
\r
231 /* NOTE: This is the trap routine (swi) although not defined as a trap.
\r
232 It will fill the stack the same way as an ISR in order to mix preemtion
\r
233 and cooperative yield. */
\r
235 portSAVE_CONTEXT();
\r
236 vTaskSwitchContext();
\r
237 portRESTORE_CONTEXT();
\r
241 /*-----------------------------------------------------------*/
\r
244 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
245 * being used then this simply increments the tick count. If the
\r
246 * preemptive scheduler is being used a context switch can occur.
\r
248 void vPortTickInterrupt( void )
\r
252 /* Clear tick timer flag */
\r
255 #if configUSE_PREEMPTION == 1
\r
257 /* A context switch might happen so save the context. */
\r
258 portSAVE_CONTEXT();
\r
260 /* Increment the tick ... */
\r
261 if( xTaskIncrementTick() != pdFALSE )
\r
263 /* A context switch is necessary. */
\r
264 vTaskSwitchContext();
\r
267 /* Restore the context of a task - which may be a different task
\r
268 to that interrupted. */
\r
269 portRESTORE_CONTEXT();
\r
273 xTaskIncrementTick();
\r