2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* Standard includes. */
\r
32 /* Kernel includes. */
\r
33 #include "FreeRTOS.h"
\r
36 /* Machine includes */
\r
37 #include <machine/counter.h>
\r
38 #include <machine/ic.h>
\r
39 /*-----------------------------------------------------------*/
\r
41 /* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */
\r
42 #define portINITIAL_PSR ( 0x00020000 )
\r
44 /*-----------------------------------------------------------*/
\r
47 * Perform any hardware configuration necessary to generate the tick interrupt.
\r
49 static void prvSetupTimerInterrupt( void );
\r
50 /*-----------------------------------------------------------*/
\r
52 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
54 /* Make space on the stack for the context - this leaves a couple of spaces
\r
58 /* Fill the registers with known values to assist debugging. */
\r
59 pxTopOfStack[ 16 ] = 0;
\r
60 pxTopOfStack[ 15 ] = portINITIAL_PSR;
\r
61 pxTopOfStack[ 14 ] = ( uint32_t ) pxCode;
\r
62 pxTopOfStack[ 13 ] = 0x00000000UL; /* R15. */
\r
63 pxTopOfStack[ 12 ] = 0x00000000UL; /* R14. */
\r
64 pxTopOfStack[ 11 ] = 0x0d0d0d0dUL;
\r
65 pxTopOfStack[ 10 ] = 0x0c0c0c0cUL;
\r
66 pxTopOfStack[ 9 ] = 0x0b0b0b0bUL;
\r
67 pxTopOfStack[ 8 ] = 0x0a0a0a0aUL;
\r
68 pxTopOfStack[ 7 ] = 0x09090909UL;
\r
69 pxTopOfStack[ 6 ] = 0x08080808UL;
\r
70 pxTopOfStack[ 5 ] = 0x07070707UL;
\r
71 pxTopOfStack[ 4 ] = 0x06060606UL;
\r
72 pxTopOfStack[ 3 ] = 0x05050505UL;
\r
73 pxTopOfStack[ 2 ] = 0x04040404UL;
\r
74 pxTopOfStack[ 1 ] = 0x03030303UL;
\r
75 pxTopOfStack[ 0 ] = ( uint32_t ) pvParameters;
\r
77 return pxTopOfStack;
\r
79 /*-----------------------------------------------------------*/
\r
81 BaseType_t xPortStartScheduler( void )
\r
83 /* Set-up the timer interrupt. */
\r
84 prvSetupTimerInterrupt();
\r
86 /* Integrated Interrupt Controller: Enable all interrupts. */
\r
89 /* Restore callee saved registers. */
\r
90 portRESTORE_CONTEXT();
\r
92 /* Should not get here. */
\r
95 /*-----------------------------------------------------------*/
\r
97 static void prvSetupTimerInterrupt( void )
\r
99 /* Enable timer interrupts */
\r
100 counter1->reload = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1;
\r
101 counter1->value = counter1->reload;
\r
102 counter1->mask = 1;
\r
104 /* Set the IRQ Handler priority and enable it. */
\r
105 irq[ IRQ_COUNTER1 ].ien = 1;
\r
107 /*-----------------------------------------------------------*/
\r
109 /* Trap 31 handler. */
\r
110 void interrupt31_handler( void ) __attribute__((naked));
\r
111 void interrupt31_handler( void )
\r
113 portSAVE_CONTEXT();
\r
114 __asm volatile ( "call vTaskSwitchContext" );
\r
115 portRESTORE_CONTEXT();
\r
117 /*-----------------------------------------------------------*/
\r
119 static void prvProcessTick( void ) __attribute__((noinline));
\r
120 static void prvProcessTick( void )
\r
122 if( xTaskIncrementTick() != pdFALSE )
\r
124 vTaskSwitchContext();
\r
127 /* Clear the Tick Interrupt. */
\r
128 counter1->expired = 0;
\r
130 /*-----------------------------------------------------------*/
\r
132 /* Timer 1 interrupt handler, used for tick interrupt. */
\r
133 void interrupt7_handler( void ) __attribute__((naked));
\r
134 void interrupt7_handler( void )
\r
136 portSAVE_CONTEXT();
\r
138 portRESTORE_CONTEXT();
\r
140 /*-----------------------------------------------------------*/
\r
142 void vPortEndScheduler( void )
\r
144 /* Nothing to do. Unlikely to want to end. */
\r
146 /*-----------------------------------------------------------*/
\r