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
34 #define portINITIAL_FORMAT_VECTOR ( ( StackType_t ) 0x4000 )
35
36 /* Supervisor mode set. */
37 #define portINITIAL_STATUS_REGISTER ( ( StackType_t ) 0x2000)
38
39 /* Used to keep track of the number of nested calls to taskENTER_CRITICAL(). This
40 will be set to 0 prior to the first task being started. */
41 static uint32_t ulCriticalNesting = 0x9999UL;
42
43
44 #define portSAVE_CONTEXT() \
45 lea.l (-60, %sp), %sp; \
46 movem.l %d0-%fp, (%sp); \
47 move.l pxCurrentTCB, %a0; \
48 move.l %sp, (%a0);
49
50 #define portRESTORE_CONTEXT() \
51 move.l pxCurrentTCB, %a0; \
52 move.l (%a0), %sp; \
53 movem.l (%sp), %d0-%fp; \
54 lea.l %sp@(60), %sp; \
55 rte
56
57
58
59 /*-----------------------------------------------------------*/
60
pxPortInitialiseStack(StackType_t * pxTopOfStack,TaskFunction_t pxCode,void * pvParameters)61 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
62 {
63 *pxTopOfStack = ( StackType_t ) pvParameters;
64 pxTopOfStack--;
65
66 *pxTopOfStack = (StackType_t) 0xDEADBEEF;
67 pxTopOfStack--;
68
69 /* Exception stack frame starts with the return address. */
70 *pxTopOfStack = ( StackType_t ) pxCode;
71 pxTopOfStack--;
72
73 *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
74 pxTopOfStack--;
75
76 *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/
77 pxTopOfStack -= 14; /* A5 to D0. */
78
79 return pxTopOfStack;
80 }
81 /*-----------------------------------------------------------*/
82
xPortStartScheduler(void)83 BaseType_t xPortStartScheduler( void )
84 {
85 extern void vPortStartFirstTask( void );
86
87 ulCriticalNesting = 0UL;
88
89 /* Configure the interrupts used by this port. */
90 vApplicationSetupInterrupts();
91
92 /* Start the first task executing. */
93 vPortStartFirstTask();
94
95 return pdFALSE;
96 }
97 /*-----------------------------------------------------------*/
98
vPortEndScheduler(void)99 void vPortEndScheduler( void )
100 {
101 /* Not implemented as there is nothing to return to. */
102 }
103 /*-----------------------------------------------------------*/
104
vPortEnterCritical(void)105 void vPortEnterCritical( void )
106 {
107 if( ulCriticalNesting == 0UL )
108 {
109 /* Guard against context switches being pended simultaneously with a
110 critical section being entered. */
111 do
112 {
113 portDISABLE_INTERRUPTS();
114 if( MCF_INTC0_INTFRCH == 0UL )
115 {
116 break;
117 }
118
119 portENABLE_INTERRUPTS();
120
121 } while( 1 );
122 }
123 ulCriticalNesting++;
124 }
125 /*-----------------------------------------------------------*/
126
vPortExitCritical(void)127 void vPortExitCritical( void )
128 {
129 ulCriticalNesting--;
130 if( ulCriticalNesting == 0 )
131 {
132 portENABLE_INTERRUPTS();
133 }
134 }
135 /*-----------------------------------------------------------*/
136
vPortYieldHandler(void)137 void vPortYieldHandler( void )
138 {
139 uint32_t ulSavedInterruptMask;
140
141 ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
142 /* Note this will clear all forced interrupts - this is done for speed. */
143 MCF_INTC0_INTFRCL = 0;
144 vTaskSwitchContext();
145 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );
146 }
147 /*-----------------------------------------------------------*/
148