]> begriffs open source - freertos/blob - portable/GCC/STR75x/port.c
Remove "1 tab == 4 spaces!" line from files that still contain it.
[freertos] / portable / GCC / STR75x / port.c
1 /*\r
2  * FreeRTOS Kernel <DEVELOPMENT BRANCH>\r
3  * Copyright (C) 2021 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  * https://www.FreeRTOS.org\r
23  * https://github.com/FreeRTOS\r
24  *\r
25  */\r
26 \r
27 /*-----------------------------------------------------------\r
28  * Implementation of functions defined in portable.h for the ST STR75x ARM7\r
29  * port.\r
30  *----------------------------------------------------------*/\r
31 \r
32 /* Library includes. */\r
33 #include "75x_tb.h"\r
34 #include "75x_eic.h"\r
35 \r
36 /* Scheduler includes. */\r
37 #include "FreeRTOS.h"\r
38 #include "task.h"\r
39 \r
40 /* Constants required to setup the initial stack. */\r
41 #define portINITIAL_SPSR                                ( ( StackType_t ) 0x1f ) /* System mode, ARM mode, interrupts enabled. */\r
42 #define portTHUMB_MODE_BIT                              ( ( StackType_t ) 0x20 )\r
43 #define portINSTRUCTION_SIZE                    ( ( StackType_t ) 4 )\r
44 \r
45 /* Constants required to handle critical sections. */\r
46 #define portNO_CRITICAL_NESTING                 ( ( uint32_t ) 0 )\r
47 \r
48 /* Prescale used on the timer clock when calculating the tick period. */\r
49 #define portPRESCALE 20\r
50 \r
51 \r
52 /*-----------------------------------------------------------*/\r
53 \r
54 /* Setup the TB to generate the tick interrupts. */\r
55 static void prvSetupTimerInterrupt( void );\r
56 \r
57 /*-----------------------------------------------------------*/\r
58 \r
59 /*\r
60  * Initialise the stack of a task to look exactly as if a call to\r
61  * portSAVE_CONTEXT had been called.\r
62  *\r
63  * See header file for description.\r
64  */\r
65 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
66 {\r
67 StackType_t *pxOriginalTOS;\r
68 \r
69         pxOriginalTOS = pxTopOfStack;\r
70 \r
71         /* To ensure asserts in tasks.c don't fail, although in this case the assert\r
72         is not really required. */\r
73         pxTopOfStack--;\r
74 \r
75         /* Setup the initial stack of the task.  The stack is set exactly as\r
76         expected by the portRESTORE_CONTEXT() macro. */\r
77 \r
78         /* First on the stack is the return address - which in this case is the\r
79         start of the task.  The offset is added to make the return address appear\r
80         as it would within an IRQ ISR. */\r
81         *pxTopOfStack = ( StackType_t ) pxCode + portINSTRUCTION_SIZE;          \r
82         pxTopOfStack--;\r
83 \r
84         *pxTopOfStack = ( StackType_t ) 0xaaaaaaaa;     /* R14 */\r
85         pxTopOfStack--; \r
86         *pxTopOfStack = ( StackType_t ) pxOriginalTOS; /* Stack used when task starts goes in R13. */\r
87         pxTopOfStack--;\r
88         *pxTopOfStack = ( StackType_t ) 0x12121212;     /* R12 */\r
89         pxTopOfStack--; \r
90         *pxTopOfStack = ( StackType_t ) 0x11111111;     /* R11 */\r
91         pxTopOfStack--; \r
92         *pxTopOfStack = ( StackType_t ) 0x10101010;     /* R10 */\r
93         pxTopOfStack--; \r
94         *pxTopOfStack = ( StackType_t ) 0x09090909;     /* R9 */\r
95         pxTopOfStack--; \r
96         *pxTopOfStack = ( StackType_t ) 0x08080808;     /* R8 */\r
97         pxTopOfStack--; \r
98         *pxTopOfStack = ( StackType_t ) 0x07070707;     /* R7 */\r
99         pxTopOfStack--; \r
100         *pxTopOfStack = ( StackType_t ) 0x06060606;     /* R6 */\r
101         pxTopOfStack--; \r
102         *pxTopOfStack = ( StackType_t ) 0x05050505;     /* R5 */\r
103         pxTopOfStack--; \r
104         *pxTopOfStack = ( StackType_t ) 0x04040404;     /* R4 */\r
105         pxTopOfStack--; \r
106         *pxTopOfStack = ( StackType_t ) 0x03030303;     /* R3 */\r
107         pxTopOfStack--; \r
108         *pxTopOfStack = ( StackType_t ) 0x02020202;     /* R2 */\r
109         pxTopOfStack--; \r
110         *pxTopOfStack = ( StackType_t ) 0x01010101;     /* R1 */\r
111         pxTopOfStack--; \r
112 \r
113         /* When the task starts is will expect to find the function parameter in\r
114         R0. */\r
115         *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */\r
116         pxTopOfStack--;\r
117 \r
118         /* The status register is set for system mode, with interrupts enabled. */\r
119         *pxTopOfStack = ( StackType_t ) portINITIAL_SPSR;\r
120 \r
121         #ifdef THUMB_INTERWORK\r
122         {\r
123                 /* We want the task to start in thumb mode. */\r
124                 *pxTopOfStack |= portTHUMB_MODE_BIT;\r
125         }\r
126         #endif\r
127 \r
128         pxTopOfStack--;\r
129 \r
130         /* Interrupt flags cannot always be stored on the stack and will\r
131         instead be stored in a variable, which is then saved as part of the\r
132         tasks context. */\r
133         *pxTopOfStack = portNO_CRITICAL_NESTING;\r
134 \r
135         return pxTopOfStack;    \r
136 }\r
137 /*-----------------------------------------------------------*/\r
138 \r
139 BaseType_t xPortStartScheduler( void )\r
140 {\r
141 extern void vPortISRStartFirstTask( void );\r
142 \r
143         /* Start the timer that generates the tick ISR.  Interrupts are disabled\r
144         here already. */\r
145         prvSetupTimerInterrupt();\r
146 \r
147         /* Start the first task. */\r
148         vPortISRStartFirstTask();       \r
149 \r
150         /* Should not get here! */\r
151         return 0;\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 void vPortEndScheduler( void )\r
156 {\r
157         /* It is unlikely that the ARM port will require this function as there\r
158         is nothing to return to.  */\r
159 }\r
160 /*-----------------------------------------------------------*/\r
161 \r
162 static void prvSetupTimerInterrupt( void )\r
163 {\r
164 EIC_IRQInitTypeDef  EIC_IRQInitStructure;       \r
165 TB_InitTypeDef      TB_InitStructure;\r
166 \r
167         /* Setup the EIC for the TB. */\r
168         EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE;\r
169         EIC_IRQInitStructure.EIC_IRQChannel = TB_IRQChannel;\r
170         EIC_IRQInitStructure.EIC_IRQChannelPriority = 1;\r
171         EIC_IRQInit(&EIC_IRQInitStructure);\r
172         \r
173         /* Setup the TB for the generation of the tick interrupt. */\r
174         TB_InitStructure.TB_Mode = TB_Mode_Timing;\r
175         TB_InitStructure.TB_CounterMode = TB_CounterMode_Down;\r
176         TB_InitStructure.TB_Prescaler = portPRESCALE - 1;\r
177         TB_InitStructure.TB_AutoReload = ( ( configCPU_CLOCK_HZ / portPRESCALE ) / configTICK_RATE_HZ );\r
178         TB_Init(&TB_InitStructure);\r
179         \r
180         /* Enable TB Update interrupt */\r
181         TB_ITConfig(TB_IT_Update, ENABLE);\r
182 \r
183         /* Clear TB Update interrupt pending bit */\r
184         TB_ClearITPendingBit(TB_IT_Update);\r
185 \r
186         /* Enable TB */\r
187         TB_Cmd(ENABLE);\r
188 }\r
189 /*-----------------------------------------------------------*/\r
190 \r
191 \r
192 \r
193 \r
194 \r
195 \r
196 \r