2 * FreeRTOS Kernel V10.4.6
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, TaskFunction_t pxCode, void *pvParameters )
75 /* R0 is not included as it is the stack pointer. */
79 *pxTopOfStack = portINITIAL_PSW;
81 *pxTopOfStack = ( StackType_t ) pxCode;
83 /* When debugging it can be useful if every register is set to a known
84 value. Otherwise code space can be saved by just setting the registers
85 that need to be set. */
86 #ifdef USE_FULL_REGISTER_INITIALISATION
89 *pxTopOfStack = 0xffffffff; /* r15. */
91 *pxTopOfStack = 0xeeeeeeee;
93 *pxTopOfStack = 0xdddddddd;
95 *pxTopOfStack = 0xcccccccc;
97 *pxTopOfStack = 0xbbbbbbbb;
99 *pxTopOfStack = 0xaaaaaaaa;
101 *pxTopOfStack = 0x99999999;
103 *pxTopOfStack = 0x88888888;
105 *pxTopOfStack = 0x77777777;
107 *pxTopOfStack = 0x66666666;
109 *pxTopOfStack = 0x55555555;
111 *pxTopOfStack = 0x44444444;
113 *pxTopOfStack = 0x33333333;
115 *pxTopOfStack = 0x22222222;
124 *pxTopOfStack = ( StackType_t ) pvParameters; /* R1 */
126 *pxTopOfStack = portINITIAL_FPSW;
128 *pxTopOfStack = 0x12345678; /* Accumulator. */
130 *pxTopOfStack = 0x87654321; /* Accumulator. */
134 /*-----------------------------------------------------------*/
136 BaseType_t xPortStartScheduler( void )
138 extern void vApplicationSetupTimerInterrupt( void );
140 /* Use pxCurrentTCB just so it does not get optimised away. */
141 if( pxCurrentTCB != NULL )
143 /* Call an application function to set up the timer that will generate the
144 tick interrupt. This way the application can decide which peripheral to
145 use. A demo application is provided to show a suitable example. */
146 vApplicationSetupTimerInterrupt();
148 /* Enable the software interrupt. */
149 _IEN( _ICU_SWINT ) = 1;
151 /* Ensure the software interrupt is clear. */
152 _IR( _ICU_SWINT ) = 0;
154 /* Ensure the software interrupt is set to the kernel priority. */
155 _IPR( _ICU_SWINT ) = configKERNEL_INTERRUPT_PRIORITY;
157 /* Start the first task. */
161 /* Should not get here. */
164 /*-----------------------------------------------------------*/
166 #pragma vector = configTICK_VECTOR
167 __interrupt void vTickISR( void )
169 /* Re-enable interrupts. */
170 __enable_interrupt();
172 /* Increment the tick, and perform any processing the new tick value
174 __set_interrupt_level( configMAX_SYSCALL_INTERRUPT_PRIORITY );
176 if( xTaskIncrementTick() != pdFALSE )
181 __set_interrupt_level( configKERNEL_INTERRUPT_PRIORITY );
183 /*-----------------------------------------------------------*/
185 void vPortEndScheduler( void )
187 /* Not implemented in ports where there is nothing to return to.
188 Artificially force an assert. */
189 configASSERT( pxCurrentTCB == NULL );
191 /*-----------------------------------------------------------*/