2 * FreeRTOS Kernel V11.2.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
8 * this software and associated documentation files (the "Software"), to deal in
9 * the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
11 * the Software, and to permit persons to whom the Software is furnished to do so,
12 * subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 /* Kernel includes. */
33 #define portINITIAL_FORMAT_VECTOR ( ( StackType_t ) 0x4000 )
35 /* Supervisor mode set. */
36 #define portINITIAL_STATUS_REGISTER ( ( StackType_t ) 0x2000 )
38 /* Used to keep track of the number of nested calls to taskENTER_CRITICAL(). This
39 * will be set to 0 prior to the first task being started. */
40 static uint32_t ulCriticalNesting = 0x9999UL;
42 /*-----------------------------------------------------------*/
44 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
45 TaskFunction_t pxCode,
48 *pxTopOfStack = ( StackType_t ) pvParameters;
51 *pxTopOfStack = ( StackType_t ) 0xDEADBEEF;
54 /* Exception stack frame starts with the return address. */
55 *pxTopOfStack = ( StackType_t ) pxCode;
58 *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
61 *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/
62 pxTopOfStack -= 14; /* A5 to D0. */
66 /*-----------------------------------------------------------*/
68 BaseType_t xPortStartScheduler( void )
70 extern void vPortStartFirstTask( void );
72 ulCriticalNesting = 0UL;
74 /* Configure the interrupts used by this port. */
75 vApplicationSetupInterrupts();
77 /* Start the first task executing. */
78 vPortStartFirstTask();
82 /*-----------------------------------------------------------*/
84 void vPortEndScheduler( void )
86 /* Not implemented as there is nothing to return to. */
88 /*-----------------------------------------------------------*/
90 void vPortEnterCritical( void )
92 if( ulCriticalNesting == 0UL )
94 /* Guard against context switches being pended simultaneously with a
95 * critical section being entered. */
98 portDISABLE_INTERRUPTS();
100 if( MCF_INTC0_INTFRCL == 0UL )
105 portENABLE_INTERRUPTS();
111 /*-----------------------------------------------------------*/
113 void vPortExitCritical( void )
117 if( ulCriticalNesting == 0 )
119 portENABLE_INTERRUPTS();
122 /*-----------------------------------------------------------*/
124 void vPortYieldHandler( void )
126 uint32_t ulSavedInterruptMask;
128 ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
129 /* Note this will clear all forced interrupts - this is done for speed. */
130 MCF_INTC0_INTFRCL = 0;
131 vTaskSwitchContext();
132 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );