2 * FreeRTOS Kernel V10.0.1
\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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* Scheduler includes. */
\r
29 #include "FreeRTOS.h"
\r
33 /*-----------------------------------------------------------
\r
34 * Implementation of functions defined in portable.h for the HCS12 port.
\r
35 *----------------------------------------------------------*/
\r
39 * Configure a timer to generate the RTOS tick at the frequency specified
\r
40 * within FreeRTOSConfig.h.
\r
42 static void prvSetupTimerInterrupt( void );
\r
44 /* Interrupt service routines have to be in non-banked memory - as does the
\r
45 scheduler startup function. */
\r
46 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
48 /* Manual context switch function. This is the SWI ISR. */
\r
49 void interrupt vPortYield( void );
\r
51 /* Tick context switch function. This is the timer ISR. */
\r
52 void interrupt vPortTickInterrupt( void );
\r
54 /* Simply called by xPortStartScheduler(). xPortStartScheduler() does not
\r
55 start the scheduler directly because the header file containing the
\r
56 xPortStartScheduler() prototype is part of the common kernel code, and
\r
57 therefore cannot use the CODE_SEG pragma. */
\r
58 static BaseType_t xBankedStartScheduler( void );
\r
60 #pragma CODE_SEG DEFAULT
\r
62 /* Calls to portENTER_CRITICAL() can be nested. When they are nested the
\r
63 critical section should not be left (i.e. interrupts should not be re-enabled)
\r
64 until the nesting depth reaches 0. This variable simply tracks the nesting
\r
65 depth. Each task maintains it's own critical nesting depth variable so
\r
66 uxCriticalNesting is saved and restored from the task stack during a context
\r
68 volatile UBaseType_t uxCriticalNesting = 0xff;
\r
70 /*-----------------------------------------------------------*/
\r
73 * See header file for description.
\r
75 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
78 Place a few bytes of known values on the bottom of the stack.
\r
79 This can be uncommented to provide useful stack markers when debugging.
\r
81 *pxTopOfStack = ( StackType_t ) 0x11;
\r
83 *pxTopOfStack = ( StackType_t ) 0x22;
\r
85 *pxTopOfStack = ( StackType_t ) 0x33;
\r
91 /* Setup the initial stack of the task. The stack is set exactly as
\r
92 expected by the portRESTORE_CONTEXT() macro. In this case the stack as
\r
93 expected by the HCS12 RTI instruction. */
\r
96 /* The address of the task function is placed in the stack byte at a time. */
\r
97 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 1 );
\r
99 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pxCode) ) + 0 );
\r
102 /* Next are all the registers that form part of the task context. */
\r
105 *pxTopOfStack = ( StackType_t ) 0xff;
\r
107 *pxTopOfStack = ( StackType_t ) 0xee;
\r
111 *pxTopOfStack = ( StackType_t ) 0xdd;
\r
113 *pxTopOfStack = ( StackType_t ) 0xcc;
\r
116 /* A register contains parameter high byte. */
\r
117 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 0 );
\r
120 /* B register contains parameter low byte. */
\r
121 *pxTopOfStack = ( StackType_t ) *( ((StackType_t *) (&pvParameters) ) + 1 );
\r
124 /* CCR: Note that when the task starts interrupts will be enabled since
\r
125 "I" bit of CCR is cleared */
\r
126 *pxTopOfStack = ( StackType_t ) 0x00;
\r
129 #ifdef BANKED_MODEL
\r
130 /* The page of the task. */
\r
131 *pxTopOfStack = ( StackType_t ) ( ( int ) pxCode );
\r
135 /* Finally the critical nesting depth is initialised with 0 (not within
\r
136 a critical section). */
\r
137 *pxTopOfStack = ( StackType_t ) 0x00;
\r
139 return pxTopOfStack;
\r
141 /*-----------------------------------------------------------*/
\r
143 void vPortEndScheduler( void )
\r
145 /* It is unlikely that the HCS12 port will get stopped. */
\r
147 /*-----------------------------------------------------------*/
\r
149 static void prvSetupTimerInterrupt( void )
\r
151 TickTimer_SetFreqHz( configTICK_RATE_HZ );
\r
152 TickTimer_Enable();
\r
154 /*-----------------------------------------------------------*/
\r
156 BaseType_t xPortStartScheduler( void )
\r
158 /* xPortStartScheduler() does not start the scheduler directly because
\r
159 the header file containing the xPortStartScheduler() prototype is part
\r
160 of the common kernel code, and therefore cannot use the CODE_SEG pragma.
\r
161 Instead it simply calls the locally defined xBankedStartScheduler() -
\r
162 which does use the CODE_SEG pragma. */
\r
164 return xBankedStartScheduler();
\r
166 /*-----------------------------------------------------------*/
\r
168 #pragma CODE_SEG __NEAR_SEG NON_BANKED
\r
170 static BaseType_t xBankedStartScheduler( void )
\r
172 /* Configure the timer that will generate the RTOS tick. Interrupts are
\r
173 disabled when this function is called. */
\r
174 prvSetupTimerInterrupt();
\r
176 /* Restore the context of the first task. */
\r
177 portRESTORE_CONTEXT();
\r
179 /* Simulate the end of an interrupt to start the scheduler off. */
\r
182 /* Should not get here! */
\r
185 /*-----------------------------------------------------------*/
\r
188 * Context switch functions. These are both interrupt service routines.
\r
192 * Manual context switch forced by calling portYIELD(). This is the SWI
\r
195 void interrupt vPortYield( void )
\r
197 portSAVE_CONTEXT();
\r
198 vTaskSwitchContext();
\r
199 portRESTORE_CONTEXT();
\r
201 /*-----------------------------------------------------------*/
\r
204 * RTOS tick interrupt service routine. If the cooperative scheduler is
\r
205 * being used then this simply increments the tick count. If the
\r
206 * preemptive scheduler is being used a context switch can occur.
\r
208 void interrupt vPortTickInterrupt( void )
\r
210 #if configUSE_PREEMPTION == 1
\r
212 /* A context switch might happen so save the context. */
\r
213 portSAVE_CONTEXT();
\r
215 /* Increment the tick ... */
\r
216 if( xTaskIncrementTick() != pdFALSE )
\r
218 vTaskSwitchContext();
\r
223 /* Restore the context of a task - which may be a different task
\r
224 to that interrupted. */
\r
225 portRESTORE_CONTEXT();
\r
229 xTaskIncrementTick();
\r
235 #pragma CODE_SEG DEFAULT
\r