2 FreeRTOS V7.5.1 - 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 /* GCC/HCS12 port by Jefferson L Smith, 2005 */
\r
67 /* Scheduler includes. */
\r
68 #include "FreeRTOS.h"
\r
72 #include <sys/ports_def.h>
\r
74 /*-----------------------------------------------------------
\r
75 * Implementation of functions defined in portable.h for the HCS12 port.
\r
76 *----------------------------------------------------------*/
\r
80 * Configure a timer to generate the RTOS tick at the frequency specified
\r
81 * within FreeRTOSConfig.h.
\r
83 static void prvSetupTimerInterrupt( void );
\r
85 /* NOTE: Interrupt service routines must be in non-banked memory - as does the
\r
86 scheduler startup function. */
\r
87 #define ATTR_NEAR __attribute__((near))
\r
89 /* Manual context switch function. This is the SWI ISR. */
\r
90 // __attribute__((interrupt))
\r
91 void ATTR_NEAR vPortYield( void );
\r
93 /* Tick context switch function. This is the timer ISR. */
\r
94 // __attribute__((interrupt))
\r
95 void ATTR_NEAR vPortTickInterrupt( void );
\r
97 /* Function in non-banked memory which actually switches to first task. */
\r
98 portBASE_TYPE ATTR_NEAR xStartSchedulerNear( void );
\r
100 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
101 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
102 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
103 depth. Each task maintains it's own critical nesting depth variable so
\r
104 uxCriticalNesting is saved and restored from the task stack during a context
\r
106 volatile unsigned portBASE_TYPE uxCriticalNesting = 0x80; // un-initialized
\r
108 /*-----------------------------------------------------------*/
\r
111 * See header file for description.
\r
113 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
117 /* Setup the initial stack of the task. The stack is set exactly as
\r
118 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
119 expected by the HCS12 RTI instruction. */
\r
122 /* The address of the task function is placed in the stack byte at a time. */
\r
123 *pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 1 );
\r
124 *--pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pxCode) ) + 0 );
\r
126 /* Next are all the registers that form part of the task context. */
\r
129 *--pxTopOfStack = ( portSTACK_TYPE ) 0xff;
\r
130 *--pxTopOfStack = ( portSTACK_TYPE ) 0xee;
\r
133 *--pxTopOfStack = ( portSTACK_TYPE ) 0xdd;
\r
134 *--pxTopOfStack = ( portSTACK_TYPE ) 0xcc;
\r
136 /* A register contains parameter high byte. */
\r
137 *--pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 0 );
\r
139 /* B register contains parameter low byte. */
\r
140 *--pxTopOfStack = ( portSTACK_TYPE ) *( ((portSTACK_TYPE *) (&pvParameters) ) + 1 );
\r
142 /* CCR: Note that when the task starts interrupts will be enabled since
\r
143 "I" bit of CCR is cleared */
\r
144 *--pxTopOfStack = ( portSTACK_TYPE ) 0x80; // keeps Stop disabled (MCU default)
\r
146 /* tmp softregs used by GCC. Values right now don't matter. */
\r
148 movw _.frame, 2,-%0 \n\
\r
149 movw _.tmp, 2,-%0 \n\
\r
150 movw _.z, 2,-%0 \n\
\r
151 movw _.xy, 2,-%0 \n\
\r
152 ;movw _.d2, 2,-%0 \n\
\r
153 ;movw _.d1, 2,-%0 \n\
\r
154 ": "=A"(pxTopOfStack) : "0"(pxTopOfStack) );
\r
156 #ifdef BANKED_MODEL
\r
157 /* The page of the task. */
\r
158 *--pxTopOfStack = 0x30; // can only directly start in PPAGE 0x30
\r
161 /* The critical nesting depth is initialised with 0 (meaning not in
\r
162 a critical section). */
\r
163 *--pxTopOfStack = ( portSTACK_TYPE ) 0x00;
\r
166 return pxTopOfStack;
\r
168 /*-----------------------------------------------------------*/
\r
170 void vPortEndScheduler( void )
\r
172 /* It is unlikely that the HCS12 port will get stopped. */
\r
174 /*-----------------------------------------------------------*/
\r
176 static void prvSetupTimerInterrupt( void )
\r
178 /* Enable hardware RTI timer */
\r
179 /* Ignores configTICK_RATE_HZ */
\r
180 RTICTL = 0x50; // 16 MHz xtal: 976.56 Hz, 1024mS
\r
181 CRGINT |= 0x80; // RTIE
\r
183 /*-----------------------------------------------------------*/
\r
185 portBASE_TYPE xPortStartScheduler( void )
\r
187 /* xPortStartScheduler() does not start the scheduler directly because
\r
188 the header file containing the xPortStartScheduler() prototype is part
\r
189 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
190 Instead it simply calls the locally defined xNearStartScheduler() -
\r
191 which does use the CODE_SEG pragma. */
\r
194 __asm ("jmp xStartSchedulerNear ; will never return": "=d"(d));
\r
197 /*-----------------------------------------------------------*/
\r
199 portBASE_TYPE xStartSchedulerNear( void )
\r
201 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
202 disabled when this function is called. */
\r
203 prvSetupTimerInterrupt();
\r
205 /* Restore the context of the first task. */
\r
206 portRESTORE_CONTEXT();
\r
210 /* Should not get here! */
\r
213 /*-----------------------------------------------------------*/
\r
216 * Context switch functions. These are interrupt service routines.
\r
220 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
223 void vPortYield( void )
\r
226 /* NOTE: This is the trap routine (swi) although not defined as a trap.
\r
227 It will fill the stack the same way as an ISR in order to mix preemtion
\r
228 and cooperative yield. */
\r
230 portSAVE_CONTEXT();
\r
231 vTaskSwitchContext();
\r
232 portRESTORE_CONTEXT();
\r
236 /*-----------------------------------------------------------*/
\r
239 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
240 * being used then this simply increments the tick count. If the
\r
241 * preemptive scheduler is being used a context switch can occur.
\r
243 void vPortTickInterrupt( void )
\r
247 /* Clear tick timer flag */
\r
250 #if configUSE_PREEMPTION == 1
\r
252 /* A context switch might happen so save the context. */
\r
253 portSAVE_CONTEXT();
\r
255 /* Increment the tick ... */
\r
256 if( xTaskIncrementTick() != pdFALSE )
\r
258 /* A context switch is necessary. */
\r
259 vTaskSwitchContext();
\r
262 /* Restore the context of a task - which may be a different task
\r
263 to that interrupted. */
\r
264 portRESTORE_CONTEXT();
\r
268 xTaskIncrementTick();
\r