2 * FreeRTOS Kernel <DEVELOPMENT BRANCH>
3 * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: MIT
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:
14 * The above copyright notice and this permission notice shall be included in all
15 * copies or substantial portions of the Software.
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.
24 * https://www.FreeRTOS.org
25 * https://github.com/FreeRTOS
29 /*-----------------------------------------------------------
30 * Implementation of functions defined in portable.h for the SH2A port.
31 *----------------------------------------------------------*/
33 /* Scheduler includes. */
37 /* Library includes. */
40 /* Hardware specifics. */
43 /*-----------------------------------------------------------*/
45 /* Tasks should start with interrupts enabled and in Supervisor mode, therefore
46 * PSW is set with U and I set, and PM and IPL clear. */
47 #define portINITIAL_PSW ( ( StackType_t ) 0x00030000 )
48 #define portINITIAL_FPSW ( ( StackType_t ) 0x00000100 )
50 /*-----------------------------------------------------------*/
53 * Function to start the first task executing - written in asm code as direct
54 * access to registers is required.
56 extern void prvStartFirstTask( void );
59 * The tick ISR handler. The peripheral used is configured by the application
60 * via a hook/callback function.
62 __interrupt void vTickISR( void );
64 /*-----------------------------------------------------------*/
66 extern void * pxCurrentTCB;
68 /*-----------------------------------------------------------*/
71 * See header file for description.
73 StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
74 TaskFunction_t pxCode,
77 /* R0 is not included as it is the stack pointer. */
81 *pxTopOfStack = portINITIAL_PSW;
83 *pxTopOfStack = ( StackType_t ) pxCode;
85 /* When debugging it can be useful if every register is set to a known
86 * value. Otherwise code space can be saved by just setting the registers
87 * that need to be set. */
88 #ifdef USE_FULL_REGISTER_INITIALISATION
91 *pxTopOfStack = 0xffffffff; /* r15. */
93 *pxTopOfStack = 0xeeeeeeee;
95 *pxTopOfStack = 0xdddddddd;
97 *pxTopOfStack = 0xcccccccc;
99 *pxTopOfStack = 0xbbbbbbbb;
101 *pxTopOfStack = 0xaaaaaaaa;
103 *pxTopOfStack = 0x99999999;
105 *pxTopOfStack = 0x88888888;
107 *pxTopOfStack = 0x77777777;
109 *pxTopOfStack = 0x66666666;
111 *pxTopOfStack = 0x55555555;
113 *pxTopOfStack = 0x44444444;
115 *pxTopOfStack = 0x33333333;
117 *pxTopOfStack = 0x22222222;
120 #else /* ifdef USE_FULL_REGISTER_INITIALISATION */
124 #endif /* ifdef USE_FULL_REGISTER_INITIALISATION */
126 *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */
128 *pxTopOfStack = portINITIAL_FPSW;
130 *pxTopOfStack = 0x11111111; /* Accumulator 0. */
132 *pxTopOfStack = 0x22222222; /* Accumulator 0. */
134 *pxTopOfStack = 0x33333333; /* Accumulator 0. */
136 *pxTopOfStack = 0x44444444; /* Accumulator 1. */
138 *pxTopOfStack = 0x55555555; /* Accumulator 1. */
140 *pxTopOfStack = 0x66666666; /* Accumulator 1. */
144 /*-----------------------------------------------------------*/
146 BaseType_t xPortStartScheduler( void )
148 extern void vApplicationSetupTimerInterrupt( void );
150 /* Use pxCurrentTCB just so it does not get optimised away. */
151 if( pxCurrentTCB != NULL )
153 /* Call an application function to set up the timer that will generate the
154 * tick interrupt. This way the application can decide which peripheral to
155 * use. A demo application is provided to show a suitable example. */
156 vApplicationSetupTimerInterrupt();
158 /* Enable the software interrupt. */
159 _IEN( _ICU_SWINT ) = 1;
161 /* Ensure the software interrupt is clear. */
162 _IR( _ICU_SWINT ) = 0;
164 /* Ensure the software interrupt is set to the kernel priority. */
165 _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;
167 /* Start the first task. */
171 /* Should not get here. */
174 /*-----------------------------------------------------------*/
176 #pragma vector = configTICK_VECTOR
177 __interrupt void vTickISR( void )
179 /* Re-enable interrupts. */
180 __enable_interrupt();
182 /* Increment the tick, and perform any processing the new tick value
184 __set_interrupt_level( configMAX_SYSCALL_INTERRUPT_PRIORITY );
186 if( xTaskIncrementTick() != pdFALSE )
191 __set_interrupt_level( configKERNEL_INTERRUPT_PRIORITY );
193 /*-----------------------------------------------------------*/
195 void vPortEndScheduler( void )
197 /* Not implemented in ports where there is nothing to return to.
198 * Artificially force an assert. */
199 configASSERT( pxCurrentTCB == NULL );
201 /*-----------------------------------------------------------*/