]> begriffs open source - freertos/blob - portable/CodeWarrior/ColdFire_V2/port.c
Feature: SMP (#278)
[freertos] / portable / CodeWarrior / ColdFire_V2 / port.c
1 /*
2  * FreeRTOS Kernel V10.4.3
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * https://www.FreeRTOS.org
23  * https://github.com/FreeRTOS
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /* Kernel includes. */
29 #include "FreeRTOS.h"
30 #include "task.h"
31
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 #define portSAVE_CONTEXT()                              \
44         lea.l           (-60, %sp), %sp;                \
45         movem.l         %d0-%fp, (%sp);                 \
46         move.l          pxCurrentTCB, %a0;              \
47         move.l          %sp, (%a0);
48
49 #define portRESTORE_CONTEXT()                   \
50         move.l          pxCurrentTCB, %a0;              \
51         move.l          (%a0), %sp;                             \
52         movem.l         (%sp), %d0-%fp;                 \
53         lea.l           %sp@(60), %sp;                  \
54         rte
55
56
57
58 /*-----------------------------------------------------------*/
59
60 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
61 {
62         *pxTopOfStack = ( StackType_t ) pvParameters;
63         pxTopOfStack--;
64
65         *pxTopOfStack = (StackType_t) 0xDEADBEEF;
66         pxTopOfStack--;
67
68         /* Exception stack frame starts with the return address. */
69         *pxTopOfStack = ( StackType_t ) pxCode;
70         pxTopOfStack--;
71
72         *pxTopOfStack = ( portINITIAL_FORMAT_VECTOR << 16UL ) | ( portINITIAL_STATUS_REGISTER );
73         pxTopOfStack--;
74
75         *pxTopOfStack = ( StackType_t ) 0x0; /*FP*/
76         pxTopOfStack -= 14; /* A5 to D0. */
77
78     return pxTopOfStack;
79 }
80 /*-----------------------------------------------------------*/
81
82 BaseType_t xPortStartScheduler( void )
83 {
84 extern void vPortStartFirstTask( void );
85
86         ulCriticalNesting = 0UL;
87
88         /* Configure the interrupts used by this port. */
89         vApplicationSetupInterrupts();
90
91         /* Start the first task executing. */
92         vPortStartFirstTask();
93
94         return pdFALSE;
95 }
96 /*-----------------------------------------------------------*/
97
98 void vPortEndScheduler( void )
99 {
100         /* Not implemented as there is nothing to return to. */
101 }
102 /*-----------------------------------------------------------*/
103
104 void vPortEnterCritical( void )
105 {
106         if( ulCriticalNesting == 0UL )
107         {
108                 /* Guard against context switches being pended simultaneously with a
109                 critical section being entered. */
110                 do
111                 {
112                         portDISABLE_INTERRUPTS();
113                         if( MCF_INTC0_INTFRCH == 0UL )
114                         {
115                                 break;
116                         }
117
118                         portENABLE_INTERRUPTS();
119
120                 } while( 1 );
121         }
122         ulCriticalNesting++;
123 }
124 /*-----------------------------------------------------------*/
125
126 void vPortExitCritical( void )
127 {
128         ulCriticalNesting--;
129         if( ulCriticalNesting == 0 )
130         {
131                 portENABLE_INTERRUPTS();
132         }
133 }
134 /*-----------------------------------------------------------*/
135
136 void vPortYieldHandler( void )
137 {
138 uint32_t ulSavedInterruptMask;
139
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 );
145 }
146 /*-----------------------------------------------------------*/
147