1 /*
2 * FreeRTOS Kernel V11.1.0
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *
5 * SPDX-License-Identifier: MIT
6 *
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:
13 *
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
16 *
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.
23 *
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
26 *
27 */
28
29 /* Kernel includes. */
30 #include "FreeRTOS.h"
31 #include "task.h"
32
33 #define portINITIAL_FORMAT_VECTOR ( ( StackType_t ) 0x4000 )
34
35 /* Supervisor mode set. */
36 #define portINITIAL_STATUS_REGISTER ( ( StackType_t ) 0x2000 )
37
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;
41
42 /*-----------------------------------------------------------*/
43
pxPortInitialiseStack(StackType_t * pxTopOfStack,TaskFunction_t pxCode,void * pvParameters)44 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
45 TaskFunction_t pxCode,
46 void * pvParameters )
47 {
48 *pxTopOfStack = ( StackType_t ) pvParameters;
49 pxTopOfStack--;
50
51 *pxTopOfStack = ( StackType_t ) 0xDEADBEEF;
52 pxTopOfStack--;
53
54 /* Exception stack frame starts with the return address. */
55 *pxTopOfStack = ( StackType_t ) pxCode;
56 pxTopOfStack--;
57
58 *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
59 pxTopOfStack--;
60
61 *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/
62 pxTopOfStack -= 14; /* A5 to D0. */
63
64 return pxTopOfStack;
65 }
66 /*-----------------------------------------------------------*/
67
xPortStartScheduler(void)68 BaseType_t xPortStartScheduler( void )
69 {
70 extern void vPortStartFirstTask( void );
71
72 ulCriticalNesting = 0UL;
73
74 /* Configure the interrupts used by this port. */
75 vApplicationSetupInterrupts();
76
77 /* Start the first task executing. */
78 vPortStartFirstTask();
79
80 return pdFALSE;
81 }
82 /*-----------------------------------------------------------*/
83
vPortEndScheduler(void)84 void vPortEndScheduler( void )
85 {
86 /* Not implemented as there is nothing to return to. */
87 }
88 /*-----------------------------------------------------------*/
89
vPortEnterCritical(void)90 void vPortEnterCritical( void )
91 {
92 if( ulCriticalNesting == 0UL )
93 {
94 /* Guard against context switches being pended simultaneously with a
95 * critical section being entered. */
96 do
97 {
98 portDISABLE_INTERRUPTS();
99
100 if( MCF_INTC0_INTFRCL == 0UL )
101 {
102 break;
103 }
104
105 portENABLE_INTERRUPTS();
106 } while( 1 );
107 }
108
109 ulCriticalNesting++;
110 }
111 /*-----------------------------------------------------------*/
112
vPortExitCritical(void)113 void vPortExitCritical( void )
114 {
115 ulCriticalNesting--;
116
117 if( ulCriticalNesting == 0 )
118 {
119 portENABLE_INTERRUPTS();
120 }
121 }
122 /*-----------------------------------------------------------*/
123
vPortYieldHandler(void)124 void vPortYieldHandler( void )
125 {
126 uint32_t ulSavedInterruptMask;
127
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 );
133 }
134