2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* Scheduler includes. */
\r
30 #include "FreeRTOS.h"
\r
34 /*-----------------------------------------------------------
\r
35 * Implementation of functions defined in portable.h for the HCS12 port.
\r
36 *----------------------------------------------------------*/
\r
40 * Configure a timer to generate the RTOS tick at the frequency specified
\r
41 * within FreeRTOSConfig.h.
\r
43 static void prvSetupTimerInterrupt( void );
\r
45 /* Interrupt service routines have to be in non-banked memory - as does the
\r
46 scheduler startup function. */
\r
47 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
49 /* Manual context switch function. This is the SWI ISR. */
\r
50 void interrupt vPortYield( void );
\r
52 /* Tick context switch function. This is the timer ISR. */
\r
53 void interrupt vPortTickInterrupt( void );
\r
55 /* Simply called by xPortStartScheduler(). xPortStartScheduler() does not
\r
56 start the scheduler directly because the header file containing the
\r
57 xPortStartScheduler() prototype is part of the common kernel code, and
\r
58 therefore cannot use the CODE_SEG pragma. */
\r
59 static BaseType_t xBankedStartScheduler( void );
\r
61 #pragma CODE_SEG DEFAULT
\r
63 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
64 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
65 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
66 depth. Each task maintains it's own critical nesting depth variable so
\r
67 uxCriticalNesting is saved and restored from the task stack during a context
\r
69 volatile UBaseType_t uxCriticalNesting = 0xff;
\r
71 /*-----------------------------------------------------------*/
\r
74 * See header file for description.
\r
76 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
79 Place a few bytes of known values on the bottom of the stack.
\r
80 This can be uncommented to provide useful stack markers when debugging.
\r
82 *pxTopOfStack = ( StackType_t ) 0x11;
\r
84 *pxTopOfStack = ( StackType_t ) 0x22;
\r
86 *pxTopOfStack = ( StackType_t ) 0x33;
\r
92 /* Setup the initial stack of the task. The stack is set exactly as
\r
93 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
94 expected by the HCS12 RTI instruction. */
\r
97 /* The address of the task function is placed in the stack byte at a time. */
\r
98 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 1 );
\r
100 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 0 );
\r
103 /* Next are all the registers that form part of the task context. */
\r
106 *pxTopOfStack = ( StackType_t ) 0xff;
\r
108 *pxTopOfStack = ( StackType_t ) 0xee;
\r
112 *pxTopOfStack = ( StackType_t ) 0xdd;
\r
114 *pxTopOfStack = ( StackType_t ) 0xcc;
\r
117 /* A register contains parameter high byte. */
\r
118 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 0 );
\r
121 /* B register contains parameter low byte. */
\r
122 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 1 );
\r
125 /* CCR: Note that when the task starts interrupts will be enabled since
\r
126 "I" bit of CCR is cleared */
\r
127 *pxTopOfStack = ( StackType_t ) 0x00;
\r
130 #ifdef BANKED_MODEL
\r
131 /* The page of the task. */
\r
132 *pxTopOfStack = ( StackType_t ) ( ( int ) pxCode );
\r
136 /* Finally the critical nesting depth is initialised with 0 (not within
\r
137 a critical section). */
\r
138 *pxTopOfStack = ( StackType_t ) 0x00;
\r
140 return pxTopOfStack;
\r
142 /*-----------------------------------------------------------*/
\r
144 void vPortEndScheduler( void )
\r
146 /* It is unlikely that the HCS12 port will get stopped. */
\r
148 /*-----------------------------------------------------------*/
\r
150 static void prvSetupTimerInterrupt( void )
\r
152 TickTimer_SetFreqHz( configTICK_RATE_HZ );
\r
153 TickTimer_Enable();
\r
155 /*-----------------------------------------------------------*/
\r
157 BaseType_t xPortStartScheduler( void )
\r
159 /* xPortStartScheduler() does not start the scheduler directly because
\r
160 the header file containing the xPortStartScheduler() prototype is part
\r
161 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
162 Instead it simply calls the locally defined xBankedStartScheduler() -
\r
163 which does use the CODE_SEG pragma. */
\r
165 return xBankedStartScheduler();
\r
167 /*-----------------------------------------------------------*/
\r
169 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
171 static BaseType_t xBankedStartScheduler( void )
\r
173 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
174 disabled when this function is called. */
\r
175 prvSetupTimerInterrupt();
\r
177 /* Restore the context of the first task. */
\r
178 portRESTORE_CONTEXT();
\r
180 /* Simulate the end of an interrupt to start the scheduler off. */
\r
183 /* Should not get here! */
\r
186 /*-----------------------------------------------------------*/
\r
189 * Context switch functions. These are both interrupt service routines.
\r
193 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
196 void interrupt vPortYield( void )
\r
198 portSAVE_CONTEXT();
\r
199 vTaskSwitchContext();
\r
200 portRESTORE_CONTEXT();
\r
202 /*-----------------------------------------------------------*/
\r
205 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
206 * being used then this simply increments the tick count. If the
\r
207 * preemptive scheduler is being used a context switch can occur.
\r
209 void interrupt vPortTickInterrupt( void )
\r
211 #if configUSE_PREEMPTION == 1
\r
213 /* A context switch might happen so save the context. */
\r
214 portSAVE_CONTEXT();
\r
216 /* Increment the tick ... */
\r
217 if( xTaskIncrementTick() != pdFALSE )
\r
219 vTaskSwitchContext();
\r
224 /* Restore the context of a task - which may be a different task
\r
225 to that interrupted. */
\r
226 portRESTORE_CONTEXT();
\r
230 xTaskIncrementTick();
\r
236 #pragma CODE_SEG DEFAULT
\r