2 * FreeRTOS Kernel V10.4.5
\r
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * SPDX-License-Identifier: MIT
\r
7 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
8 * this software and associated documentation files (the "Software"), to deal in
\r
9 * the Software without restriction, including without limitation the rights to
\r
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
11 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
12 * subject to the following conditions:
\r
14 * The above copyright notice and this permission notice shall be included in all
\r
15 * copies or substantial portions of the Software.
\r
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
19 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
20 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
21 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
24 * https://www.FreeRTOS.org
\r
25 * https://github.com/FreeRTOS
\r
29 /*-----------------------------------------------------------
\r
30 * Implementation of functions defined in portable.h for the ST STR75x ARM7
\r
32 *----------------------------------------------------------*/
\r
34 /* Library includes. */
\r
36 #include "75x_eic.h"
\r
38 /* Scheduler includes. */
\r
39 #include "FreeRTOS.h"
\r
42 /* Constants required to setup the initial stack. */
\r
43 #define portINITIAL_SPSR ( ( StackType_t ) 0x3f ) /* System mode, THUMB mode, interrupts enabled. */
\r
44 #define portINSTRUCTION_SIZE ( ( StackType_t ) 4 )
\r
46 /* Constants required to handle critical sections. */
\r
47 #define portNO_CRITICAL_NESTING ( ( uint32_t ) 0 )
\r
49 /* Prescale used on the timer clock when calculating the tick period. */
\r
50 #define portPRESCALE 20
\r
53 /*-----------------------------------------------------------*/
\r
55 /* Setup the TB to generate the tick interrupts. */
\r
56 static void prvSetupTimerInterrupt( void );
\r
58 /* ulCriticalNesting will get set to zero when the first task starts. It
\r
59 cannot be initialised to 0 as this will cause interrupts to be enabled
\r
60 during the kernel initialisation process. */
\r
61 uint32_t ulCriticalNesting = ( uint32_t ) 9999;
\r
63 /* Tick interrupt routines for preemptive operation. */
\r
64 __arm void vPortPreemptiveTick( void );
\r
66 /*-----------------------------------------------------------*/
\r
69 * Initialise the stack of a task to look exactly as if a call to
\r
70 * portSAVE_CONTEXT had been called.
\r
72 * See header file for description.
\r
74 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
76 StackType_t *pxOriginalTOS;
\r
78 pxOriginalTOS = pxTopOfStack;
\r
80 /* To ensure asserts in tasks.c don't fail, although in this case the assert
\r
81 is not really required. */
\r
84 /* Setup the initial stack of the task. The stack is set exactly as
\r
85 expected by the portRESTORE_CONTEXT() macro. */
\r
87 /* First on the stack is the return address - which in this case is the
\r
88 start of the task. The offset is added to make the return address appear
\r
89 as it would within an IRQ ISR. */
\r
90 *pxTopOfStack = ( StackType_t ) pxCode + portINSTRUCTION_SIZE;
\r
93 *pxTopOfStack = ( StackType_t ) 0xaaaaaaaa; /* R14 */
\r
95 *pxTopOfStack = ( StackType_t ) pxOriginalTOS; /* Stack used when task starts goes in R13. */
\r
97 *pxTopOfStack = ( StackType_t ) 0x12121212; /* R12 */
\r
99 *pxTopOfStack = ( StackType_t ) 0x11111111; /* R11 */
\r
101 *pxTopOfStack = ( StackType_t ) 0x10101010; /* R10 */
\r
103 *pxTopOfStack = ( StackType_t ) 0x09090909; /* R9 */
\r
105 *pxTopOfStack = ( StackType_t ) 0x08080808; /* R8 */
\r
107 *pxTopOfStack = ( StackType_t ) 0x07070707; /* R7 */
\r
109 *pxTopOfStack = ( StackType_t ) 0x06060606; /* R6 */
\r
111 *pxTopOfStack = ( StackType_t ) 0x05050505; /* R5 */
\r
113 *pxTopOfStack = ( StackType_t ) 0x04040404; /* R4 */
\r
115 *pxTopOfStack = ( StackType_t ) 0x03030303; /* R3 */
\r
117 *pxTopOfStack = ( StackType_t ) 0x02020202; /* R2 */
\r
119 *pxTopOfStack = ( StackType_t ) 0x01010101; /* R1 */
\r
122 /* When the task starts is will expect to find the function parameter in
\r
124 *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */
\r
127 /* The status register is set for system mode, with interrupts enabled. */
\r
128 *pxTopOfStack = ( StackType_t ) portINITIAL_SPSR;
\r
131 /* Interrupt flags cannot always be stored on the stack and will
\r
132 instead be stored in a variable, which is then saved as part of the
\r
134 *pxTopOfStack = portNO_CRITICAL_NESTING;
\r
136 return pxTopOfStack;
\r
138 /*-----------------------------------------------------------*/
\r
140 BaseType_t xPortStartScheduler( void )
\r
142 extern void vPortStartFirstTask( void );
\r
144 /* Start the timer that generates the tick ISR. Interrupts are disabled
\r
146 prvSetupTimerInterrupt();
\r
148 /* Start the first task. */
\r
149 vPortStartFirstTask();
\r
151 /* Should not get here! */
\r
154 /*-----------------------------------------------------------*/
\r
156 void vPortEndScheduler( void )
\r
158 /* It is unlikely that the ARM port will require this function as there
\r
159 is nothing to return to. */
\r
161 /*-----------------------------------------------------------*/
\r
163 __arm void vPortPreemptiveTick( void )
\r
165 /* Increment the tick counter. */
\r
166 if( xTaskIncrementTick() != pdFALSE )
\r
168 /* Select a new task to execute. */
\r
169 vTaskSwitchContext();
\r
172 TB_ClearITPendingBit( TB_IT_Update );
\r
174 /*-----------------------------------------------------------*/
\r
176 static void prvSetupTimerInterrupt( void )
\r
178 EIC_IRQInitTypeDef EIC_IRQInitStructure;
\r
179 TB_InitTypeDef TB_InitStructure;
\r
181 /* Setup the EIC for the TB. */
\r
182 EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;
\r
183 EIC_IRQInitStructure.EIC_IRQChannel = TB_IRQChannel;
\r
184 EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;
\r
185 EIC_IRQInit(&EIC_IRQInitStructure);
\r
187 /* Setup the TB for the generation of the tick interrupt. */
\r
188 TB_InitStructure.TB_Mode = TB_Mode_Timing;
\r
189 TB_InitStructure.TB_CounterMode = TB_CounterMode_Down;
\r
190 TB_InitStructure.TB_Prescaler = portPRESCALE - 1;
\r
191 TB_InitStructure.TB_AutoReload = ( ( configCPU_CLOCK_HZ / portPRESCALE ) / configTICK_RATE_HZ );
\r
192 TB_Init(&TB_InitStructure);
\r
194 /* Enable TB Update interrupt */
\r
195 TB_ITConfig(TB_IT_Update, ENABLE);
\r
197 /* Clear TB Update interrupt pending bit */
\r
198 TB_ClearITPendingBit(TB_IT_Update);
\r
203 /*-----------------------------------------------------------*/
\r
205 __arm __interwork void vPortEnterCritical( void )
\r
207 /* Disable interrupts first! */
\r
208 __disable_interrupt();
\r
210 /* Now interrupts are disabled ulCriticalNesting can be accessed
\r
211 directly. Increment ulCriticalNesting to keep a count of how many times
\r
212 portENTER_CRITICAL() has been called. */
\r
213 ulCriticalNesting++;
\r
215 /*-----------------------------------------------------------*/
\r
217 __arm __interwork void vPortExitCritical( void )
\r
219 if( ulCriticalNesting > portNO_CRITICAL_NESTING )
\r
221 /* Decrement the nesting count as we are leaving a critical section. */
\r
222 ulCriticalNesting--;
\r
224 /* If the nesting level has reached zero then interrupts should be
\r
226 if( ulCriticalNesting == portNO_CRITICAL_NESTING )
\r
228 __enable_interrupt();
\r
232 /*-----------------------------------------------------------*/
\r