2 * FreeRTOS Kernel V10.4.3
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 /* 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;
43 #define portSAVE_CONTEXT() \
44 lea.l (-60, %sp), %sp; \
45 movem.l %d0-%fp, (%sp); \
46 move.l pxCurrentTCB, %a0; \
49 #define portRESTORE_CONTEXT() \
50 move.l pxCurrentTCB, %a0; \
52 movem.l (%sp), %d0-%fp; \
53 lea.l %sp@(60), %sp; \
58 /*-----------------------------------------------------------*/
60 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
62 *pxTopOfStack = ( StackType_t ) pvParameters;
65 *pxTopOfStack = (StackType_t) 0xDEADBEEF;
68 /* Exception stack frame starts with the return address. */
69 *pxTopOfStack = ( StackType_t ) pxCode;
72 *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
75 *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/
76 pxTopOfStack -= 14; /* A5 to D0. */
80 /*-----------------------------------------------------------*/
82 BaseType_t xPortStartScheduler( void )
84 extern void vPortStartFirstTask( void );
86 ulCriticalNesting = 0UL;
88 /* Configure the interrupts used by this port. */
89 vApplicationSetupInterrupts();
91 /* Start the first task executing. */
92 vPortStartFirstTask();
96 /*-----------------------------------------------------------*/
98 void vPortEndScheduler( void )
100 /* Not implemented as there is nothing to return to. */
102 /*-----------------------------------------------------------*/
104 void vPortEnterCritical( void )
106 if( ulCriticalNesting == 0UL )
108 /* Guard against context switches being pended simultaneously with a
109 critical section being entered. */
112 portDISABLE_INTERRUPTS();
113 if( MCF_INTC0_INTFRCH == 0UL )
118 portENABLE_INTERRUPTS();
124 /*-----------------------------------------------------------*/
126 void vPortExitCritical( void )
129 if( ulCriticalNesting == 0 )
131 portENABLE_INTERRUPTS();
134 /*-----------------------------------------------------------*/
136 void vPortYieldHandler( void )
138 uint32_t ulSavedInterruptMask;
140 ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
141 /* Note this will clear all forced interrupts - this is done for speed. */
142 MCF_INTC0_INTFRCL = 0;
143 vTaskSwitchContext();
144 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );
146 /*-----------------------------------------------------------*/