xref: /Kernel-v10.6.2/portable/GCC/ColdFire_V2/port.c (revision ef7b253b56c9788077f5ecd6c9deb4021923d646)
1 /*
2  * FreeRTOS Kernel V10.6.2
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, TaskFunction_t pxCode, void *pvParameters )
45 {
46     *pxTopOfStack = ( StackType_t ) pvParameters;
47     pxTopOfStack--;
48 
49     *pxTopOfStack = (StackType_t) 0xDEADBEEF;
50     pxTopOfStack--;
51 
52     /* Exception stack frame starts with the return address. */
53     *pxTopOfStack = ( StackType_t ) pxCode;
54     pxTopOfStack--;
55 
56     *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
57     pxTopOfStack--;
58 
59     *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/
60     pxTopOfStack -= 14; /* A5 to D0. */
61 
62     return pxTopOfStack;
63 }
64 /*-----------------------------------------------------------*/
65 
xPortStartScheduler(void)66 BaseType_t xPortStartScheduler( void )
67 {
68 extern void vPortStartFirstTask( void );
69 
70     ulCriticalNesting = 0UL;
71 
72     /* Configure the interrupts used by this port. */
73     vApplicationSetupInterrupts();
74 
75     /* Start the first task executing. */
76     vPortStartFirstTask();
77 
78     return pdFALSE;
79 }
80 /*-----------------------------------------------------------*/
81 
vPortEndScheduler(void)82 void vPortEndScheduler( void )
83 {
84     /* Not implemented as there is nothing to return to. */
85 }
86 /*-----------------------------------------------------------*/
87 
vPortEnterCritical(void)88 void vPortEnterCritical( void )
89 {
90     if( ulCriticalNesting == 0UL )
91     {
92         /* Guard against context switches being pended simultaneously with a
93         critical section being entered. */
94         do
95         {
96             portDISABLE_INTERRUPTS();
97             if( MCF_INTC0_INTFRCL == 0UL )
98             {
99                 break;
100             }
101 
102             portENABLE_INTERRUPTS();
103 
104         } while( 1 );
105     }
106     ulCriticalNesting++;
107 }
108 /*-----------------------------------------------------------*/
109 
vPortExitCritical(void)110 void vPortExitCritical( void )
111 {
112     ulCriticalNesting--;
113     if( ulCriticalNesting == 0 )
114     {
115         portENABLE_INTERRUPTS();
116     }
117 }
118 /*-----------------------------------------------------------*/
119 
vPortYieldHandler(void)120 void vPortYieldHandler( void )
121 {
122 uint32_t ulSavedInterruptMask;
123 
124     ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
125         /* Note this will clear all forced interrupts - this is done for speed. */
126         MCF_INTC0_INTFRCL = 0;
127         vTaskSwitchContext();
128     portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );
129 }
130