2 * FreeRTOS Kernel V10.1.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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* Standard includes. */
\r
31 /* Kernel includes. */
\r
32 #include "FreeRTOS.h"
\r
35 /* Machine includes */
\r
36 #include <machine/counter.h>
\r
37 #include <machine/ic.h>
\r
38 /*-----------------------------------------------------------*/
\r
40 /* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */
\r
41 #define portINITIAL_PSR ( 0x00020000 )
\r
43 /*-----------------------------------------------------------*/
\r
46 * Perform any hardware configuration necessary to generate the tick interrupt.
\r
48 static void prvSetupTimerInterrupt( void );
\r
49 /*-----------------------------------------------------------*/
\r
51 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
53 /* Make space on the stack for the context - this leaves a couple of spaces
\r
57 /* Fill the registers with known values to assist debugging. */
\r
58 pxTopOfStack[ 16 ] = 0;
\r
59 pxTopOfStack[ 15 ] = portINITIAL_PSR;
\r
60 pxTopOfStack[ 14 ] = ( uint32_t ) pxCode;
\r
61 pxTopOfStack[ 13 ] = 0x00000000UL; /* R15. */
\r
62 pxTopOfStack[ 12 ] = 0x00000000UL; /* R14. */
\r
63 pxTopOfStack[ 11 ] = 0x0d0d0d0dUL;
\r
64 pxTopOfStack[ 10 ] = 0x0c0c0c0cUL;
\r
65 pxTopOfStack[ 9 ] = 0x0b0b0b0bUL;
\r
66 pxTopOfStack[ 8 ] = 0x0a0a0a0aUL;
\r
67 pxTopOfStack[ 7 ] = 0x09090909UL;
\r
68 pxTopOfStack[ 6 ] = 0x08080808UL;
\r
69 pxTopOfStack[ 5 ] = 0x07070707UL;
\r
70 pxTopOfStack[ 4 ] = 0x06060606UL;
\r
71 pxTopOfStack[ 3 ] = 0x05050505UL;
\r
72 pxTopOfStack[ 2 ] = 0x04040404UL;
\r
73 pxTopOfStack[ 1 ] = 0x03030303UL;
\r
74 pxTopOfStack[ 0 ] = ( uint32_t ) pvParameters;
\r
76 return pxTopOfStack;
\r
78 /*-----------------------------------------------------------*/
\r
80 BaseType_t xPortStartScheduler( void )
\r
82 /* Set-up the timer interrupt. */
\r
83 prvSetupTimerInterrupt();
\r
85 /* Integrated Interrupt Controller: Enable all interrupts. */
\r
88 /* Restore callee saved registers. */
\r
89 portRESTORE_CONTEXT();
\r
91 /* Should not get here. */
\r
94 /*-----------------------------------------------------------*/
\r
96 static void prvSetupTimerInterrupt( void )
\r
98 /* Enable timer interrupts */
\r
99 counter1->reload = ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1;
\r
100 counter1->value = counter1->reload;
\r
101 counter1->mask = 1;
\r
103 /* Set the IRQ Handler priority and enable it. */
\r
104 irq[ IRQ_COUNTER1 ].ien = 1;
\r
106 /*-----------------------------------------------------------*/
\r
108 /* Trap 31 handler. */
\r
109 void interrupt31_handler( void ) __attribute__((naked));
\r
110 void interrupt31_handler( void )
\r
112 portSAVE_CONTEXT();
\r
113 __asm volatile ( "call vTaskSwitchContext" );
\r
114 portRESTORE_CONTEXT();
\r
116 /*-----------------------------------------------------------*/
\r
118 static void prvProcessTick( void ) __attribute__((noinline));
\r
119 static void prvProcessTick( void )
\r
121 if( xTaskIncrementTick() != pdFALSE )
\r
123 vTaskSwitchContext();
\r
126 /* Clear the Tick Interrupt. */
\r
127 counter1->expired = 0;
\r
129 /*-----------------------------------------------------------*/
\r
131 /* Timer 1 interrupt handler, used for tick interrupt. */
\r
132 void interrupt7_handler( void ) __attribute__((naked));
\r
133 void interrupt7_handler( void )
\r
135 portSAVE_CONTEXT();
\r
137 portRESTORE_CONTEXT();
\r
139 /*-----------------------------------------------------------*/
\r
141 void vPortEndScheduler( void )
\r
143 /* Nothing to do. Unlikely to want to end. */
\r
145 /*-----------------------------------------------------------*/
\r