]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/CORTUS_APS3/port.c
Update version numbers in preparation for a new release.
[freertos] / FreeRTOS / Source / portable / GCC / CORTUS_APS3 / port.c
1 /*\r
2  * FreeRTOS Kernel V10.1.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* Standard includes. */\r
29 #include <stdlib.h>\r
30 \r
31 /* Kernel includes. */\r
32 #include "FreeRTOS.h"\r
33 #include "task.h"\r
34 \r
35 /* Machine includes */\r
36 #include <machine/counter.h>\r
37 #include <machine/ic.h>\r
38 /*-----------------------------------------------------------*/\r
39 \r
40 /* The initial PSR has the Previous Interrupt Enabled (PIEN) flag set. */\r
41 #define portINITIAL_PSR                 ( 0x00020000 )\r
42 \r
43 /*-----------------------------------------------------------*/\r
44 \r
45 /*\r
46  * Perform any hardware configuration necessary to generate the tick interrupt.\r
47  */\r
48 static void prvSetupTimerInterrupt( void );\r
49 /*-----------------------------------------------------------*/\r
50 \r
51 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
52 {\r
53         /* Make space on the stack for the context - this leaves a couple of spaces\r
54         empty.  */\r
55         pxTopOfStack -= 20;\r
56 \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
75 \r
76         return pxTopOfStack;\r
77 }\r
78 /*-----------------------------------------------------------*/\r
79 \r
80 BaseType_t xPortStartScheduler( void )\r
81 {\r
82         /* Set-up the timer interrupt. */\r
83         prvSetupTimerInterrupt();\r
84 \r
85         /* Integrated Interrupt Controller: Enable all interrupts. */\r
86         ic->ien = 1;\r
87 \r
88         /* Restore callee saved registers. */\r
89         portRESTORE_CONTEXT();\r
90 \r
91         /* Should not get here. */\r
92         return 0;\r
93 }\r
94 /*-----------------------------------------------------------*/\r
95 \r
96 static void prvSetupTimerInterrupt( void )\r
97 {\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
102 \r
103         /* Set the IRQ Handler priority and enable it. */\r
104         irq[ IRQ_COUNTER1 ].ien = 1;\r
105 }\r
106 /*-----------------------------------------------------------*/\r
107 \r
108 /* Trap 31 handler. */\r
109 void interrupt31_handler( void ) __attribute__((naked));\r
110 void interrupt31_handler( void )\r
111 {\r
112         portSAVE_CONTEXT();\r
113         __asm volatile ( "call vTaskSwitchContext" );\r
114         portRESTORE_CONTEXT();\r
115 }\r
116 /*-----------------------------------------------------------*/\r
117 \r
118 static void prvProcessTick( void ) __attribute__((noinline));\r
119 static void prvProcessTick( void )\r
120 {\r
121         if( xTaskIncrementTick() != pdFALSE )\r
122         {\r
123                 vTaskSwitchContext();\r
124         }\r
125                 \r
126         /* Clear the Tick Interrupt. */\r
127         counter1->expired = 0;\r
128 }\r
129 /*-----------------------------------------------------------*/\r
130 \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
134 {\r
135         portSAVE_CONTEXT();\r
136         prvProcessTick();\r
137         portRESTORE_CONTEXT();\r
138 }\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 void vPortEndScheduler( void )\r
142 {\r
143         /* Nothing to do. Unlikely to want to end. */\r
144 }\r
145 /*-----------------------------------------------------------*/\r