]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/IAR/V850ES/port.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Source / portable / IAR / V850ES / port.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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 /* Scheduler includes. */\r
32 #include "FreeRTOS.h"\r
33 #include "task.h"\r
34 \r
35 /* Critical nesting should be initialised to a non zero value so interrupts don't\r
36 accidentally get enabled before the scheduler is started. */\r
37 #define portINITIAL_CRITICAL_NESTING  (( StackType_t ) 10)\r
38 \r
39 /* The PSW value assigned to tasks when they start to run for the first time. */\r
40 #define portPSW           (( StackType_t ) 0x00000000)\r
41 \r
42 /* We require the address of the pxCurrentTCB variable, but don't want to know\r
43 any details of its type. */\r
44 typedef void TCB_t;\r
45 extern volatile TCB_t * volatile pxCurrentTCB;\r
46 \r
47 /* Keeps track of the nesting level of critical sections. */\r
48 volatile StackType_t usCriticalNesting = portINITIAL_CRITICAL_NESTING;\r
49 /*-----------------------------------------------------------*/\r
50 \r
51 /* Sets up the timer to generate the tick interrupt. */\r
52 static void prvSetupTimerInterrupt( void );\r
53 \r
54 /*-----------------------------------------------------------*/\r
55 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )\r
56 {\r
57         *pxTopOfStack = ( StackType_t ) pxCode;          /* Task function start address */\r
58         pxTopOfStack--;\r
59         *pxTopOfStack = ( StackType_t ) pxCode;          /* Task function start address */\r
60         pxTopOfStack--;\r
61         *pxTopOfStack = portPSW;                            /* Initial PSW value */\r
62         pxTopOfStack--;\r
63         *pxTopOfStack = ( StackType_t ) 0x20202020;      /* Initial Value of R20 */\r
64         pxTopOfStack--;\r
65         *pxTopOfStack = ( StackType_t ) 0x21212121;      /* Initial Value of R21 */\r
66         pxTopOfStack--;\r
67         *pxTopOfStack = ( StackType_t ) 0x22222222;      /* Initial Value of R22 */\r
68         pxTopOfStack--;\r
69         *pxTopOfStack = ( StackType_t ) 0x23232323;      /* Initial Value of R23 */\r
70         pxTopOfStack--;\r
71         *pxTopOfStack = ( StackType_t ) 0x24242424;      /* Initial Value of R24 */\r
72         pxTopOfStack--;\r
73 #if (__DATA_MODEL__ == 0) || (__DATA_MODEL__ == 1)\r
74         *pxTopOfStack = ( StackType_t ) 0x25252525;      /* Initial Value of R25 */\r
75         pxTopOfStack--;\r
76 #endif /* configDATA_MODE */\r
77         *pxTopOfStack = ( StackType_t ) 0x26262626;      /* Initial Value of R26 */\r
78         pxTopOfStack--;\r
79         *pxTopOfStack = ( StackType_t ) 0x27272727;      /* Initial Value of R27 */\r
80         pxTopOfStack--;\r
81         *pxTopOfStack = ( StackType_t ) 0x28282828;      /* Initial Value of R28 */\r
82         pxTopOfStack--;\r
83         *pxTopOfStack = ( StackType_t ) 0x29292929;      /* Initial Value of R29 */\r
84         pxTopOfStack--;\r
85         *pxTopOfStack = ( StackType_t ) 0x30303030;      /* Initial Value of R30 */\r
86         pxTopOfStack--;         \r
87         *pxTopOfStack = ( StackType_t ) 0x19191919;      /* Initial Value of R19 */\r
88         pxTopOfStack--;\r
89         *pxTopOfStack = ( StackType_t ) 0x18181818;      /* Initial Value of R18 */\r
90         pxTopOfStack--;\r
91         *pxTopOfStack = ( StackType_t ) 0x17171717;      /* Initial Value of R17 */\r
92         pxTopOfStack--;\r
93         *pxTopOfStack = ( StackType_t ) 0x16161616;      /* Initial Value of R16 */\r
94         pxTopOfStack--;\r
95         *pxTopOfStack = ( StackType_t ) 0x15151515;      /* Initial Value of R15 */\r
96         pxTopOfStack--;\r
97         *pxTopOfStack = ( StackType_t ) 0x14141414;      /* Initial Value of R14 */\r
98         pxTopOfStack--;\r
99         *pxTopOfStack = ( StackType_t ) 0x13131313;      /* Initial Value of R13 */\r
100         pxTopOfStack--;\r
101         *pxTopOfStack = ( StackType_t ) 0x12121212;      /* Initial Value of R12 */\r
102         pxTopOfStack--;\r
103         *pxTopOfStack = ( StackType_t ) 0x11111111;      /* Initial Value of R11 */\r
104         pxTopOfStack--;\r
105         *pxTopOfStack = ( StackType_t ) 0x10101010;      /* Initial Value of R10 */\r
106         pxTopOfStack--;\r
107         *pxTopOfStack = ( StackType_t ) 0x99999999;      /* Initial Value of R09 */\r
108         pxTopOfStack--;\r
109         *pxTopOfStack = ( StackType_t ) 0x88888888;      /* Initial Value of R08 */\r
110         pxTopOfStack--;\r
111         *pxTopOfStack = ( StackType_t ) 0x77777777;      /* Initial Value of R07 */\r
112         pxTopOfStack--;\r
113         *pxTopOfStack = ( StackType_t ) 0x66666666;      /* Initial Value of R06 */\r
114         pxTopOfStack--;\r
115         *pxTopOfStack = ( StackType_t ) 0x55555555;      /* Initial Value of R05 */\r
116         pxTopOfStack--;\r
117 #if __DATA_MODEL__ == 0 || __DATA_MODEL__ == 1\r
118         *pxTopOfStack = ( StackType_t ) 0x44444444;      /* Initial Value of R04 */\r
119         pxTopOfStack--;\r
120 #endif /* configDATA_MODE */\r
121         *pxTopOfStack = ( StackType_t ) 0x22222222;      /* Initial Value of R02 */\r
122         pxTopOfStack--;\r
123         *pxTopOfStack = ( StackType_t ) pvParameters;    /* R1 is expected to hold the function parameter*/\r
124         pxTopOfStack--;\r
125         *pxTopOfStack = ( StackType_t ) portNO_CRITICAL_SECTION_NESTING;        \r
126 \r
127         /*\r
128          * Return a pointer to the top of the stack we have generated so this can\r
129          * be stored in the task control block for the task.\r
130          */\r
131         return pxTopOfStack;\r
132 }\r
133 /*-----------------------------------------------------------*/\r
134 \r
135 BaseType_t xPortStartScheduler( void )\r
136 {\r
137         /* Setup the hardware to generate the tick.  Interrupts are disabled when\r
138         this function is called. */\r
139         prvSetupTimerInterrupt();\r
140 \r
141         /* Restore the context of the first task that is going to run. */\r
142         vPortStart();\r
143 \r
144         /* Should not get here as the tasks are now running! */\r
145         return pdTRUE;\r
146 }\r
147 /*-----------------------------------------------------------*/\r
148 \r
149 void vPortEndScheduler( void )\r
150 {\r
151         /* It is unlikely that the V850ES/Fx3 port will get stopped.  If required simply\r
152         disable the tick interrupt here. */\r
153 }\r
154 /*-----------------------------------------------------------*/\r
155 \r
156 /*\r
157  * Hardware initialisation to generate the RTOS tick.  This uses\r
158  */\r
159 static void prvSetupTimerInterrupt( void )\r
160 {\r
161         TM0CE     = 0;  /* TMM0 operation disable */\r
162         TM0EQMK0  = 1;  /* INTTM0EQ0 interrupt disable */\r
163         TM0EQIF0  = 0;  /* clear INTTM0EQ0 interrupt flag */\r
164 \r
165         #ifdef __IAR_V850ES_Fx3__\r
166         {\r
167                 TM0CMP0   = (((configCPU_CLOCK_HZ / configTICK_RATE_HZ) / 2)-1);    /* divided by 2 because peripherals only run at CPU_CLOCK/2 */\r
168         }\r
169         #else\r
170         {\r
171                 TM0CMP0   = (configCPU_CLOCK_HZ / configTICK_RATE_HZ);  \r
172         }\r
173         #endif\r
174 \r
175         TM0EQIC0 &= 0xF8;\r
176         TM0CTL0   = 0x00;\r
177         TM0EQIF0 =  0;  /* clear INTTM0EQ0 interrupt flag */\r
178         TM0EQMK0 =  0;  /* INTTM0EQ0 interrupt enable */\r
179         TM0CE =     1;  /* TMM0 operation enable */\r
180 }\r
181 /*-----------------------------------------------------------*/\r
182 \r
183 \r