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