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