]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_STR71x_IAR/main.c
3f2997f1b744a4628c47c1d4a78b1a8b5803b9b3
[freertos] / FreeRTOS / Demo / ARM7_STR71x_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.2.1\r
3  * Copyright (C) 2019 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 /*\r
29         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
30         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
31         called.  The demo applications included in the FreeRTOS.org download switch\r
32         to supervisor mode prior to main being called.  If you are not using one of\r
33         these demo application projects then ensure Supervisor mode is used.\r
34 */\r
35 \r
36 /*\r
37  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
38  * documentation provides more details of the demo application tasks.\r
39  *\r
40  * Main.c also creates a task called "Check".  This only executes every three\r
41  * seconds but has the highest priority so is guaranteed to get processor time.\r
42  * Its main function is to check that all the other tasks are still operational.\r
43  * Each task (other than the "flash" tasks) maintains a unique count that is\r
44  * incremented each time the task successfully completes its function.  Should\r
45  * any error occur within such a task the count is permanently halted.  The\r
46  * check task inspects the count of each task to ensure it has changed since\r
47  * the last time the check task executed.  If all the count variables have\r
48  * changed all the tasks are still executing error free, and the check task\r
49  * toggles the onboard LED.  Should any task contain an error at any time\r
50  * the LED toggle rate will change from 3 seconds to 500ms.\r
51  *\r
52  */\r
53 \r
54 /* Library includes. */\r
55 #include "RCCU.h"\r
56 #include "wdg.h"\r
57 \r
58 /* Scheduler includes. */\r
59 #include "FreeRTOS.h"\r
60 #include "task.h"\r
61 \r
62 /* Demo application includes. */\r
63 #include "flash.h"\r
64 #include "integer.h"\r
65 #include "PollQ.h"\r
66 #include "BlockQ.h"\r
67 #include "semtest.h"\r
68 #include "dynamic.h"\r
69 #include "partest.h"\r
70 #include "comtest2.h"\r
71 \r
72 /* Priorities for the demo application tasks. */\r
73 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
74 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
75 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
76 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
77 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
78 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
79 \r
80 /* Constants required by the 'Check' task. */\r
81 #define mainNO_ERROR_FLASH_PERIOD       ( ( TickType_t ) 3000 / portTICK_PERIOD_MS  )\r
82 #define mainERROR_FLASH_PERIOD          ( ( TickType_t ) 500 / portTICK_PERIOD_MS  )\r
83 #define mainCHECK_TASK_LED                      ( 4 )\r
84 \r
85 /* Constants for the ComTest tasks. */\r
86 #define mainCOM_TEST_BAUD_RATE          ( ( unsigned long ) 115200 )\r
87 #define mainCOM_TEST_LED                        ( 6 ) /* The LED built onto the kickstart board. */\r
88 \r
89 /*\r
90  * The task that executes at the highest priority and calls\r
91  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
92  * of the file.\r
93  */\r
94 static void vErrorChecks( void *pvParameters );\r
95 \r
96 /*\r
97  * Configure the processor for use with the IAR STR71x demo board.  This\r
98  * just sets the PLL for the required frequency.\r
99  */\r
100 static void prvSetupHardware( void );\r
101 \r
102 /*\r
103  * Checks that all the demo application tasks are still executing without error\r
104  * - as described at the top of the file.  Called by vErrorChecks().\r
105  */\r
106 static long prvCheckOtherTasksAreStillRunning( void );\r
107 \r
108 \r
109 /*-----------------------------------------------------------*/\r
110 \r
111 /*\r
112  * Starts all the other tasks, then starts the scheduler.\r
113  */\r
114 void main( void )\r
115 {\r
116         /* Setup any hardware that has not already been configured by the low\r
117         level init routines. */\r
118         prvSetupHardware();\r
119 \r
120         /* Initialise the LED outputs for use by the demo application tasks. */\r
121         vParTestInitialise();\r
122 \r
123         /* Start all the standard demo application tasks. */\r
124         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
125         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
126         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
127         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
128         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
129         vStartDynamicPriorityTasks();\r
130         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
131 \r
132         /* Start the check task - which is defined in this file. */\r
133         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
134 \r
135         /* Start the scheduler.\r
136 \r
137         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
138         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
139         called.  The demo applications included in the FreeRTOS.org download switch\r
140         to supervisor mode prior to main being called.  If you are not using one of\r
141         these demo application projects then ensure Supervisor mode is used here. */\r
142 \r
143         vTaskStartScheduler();\r
144 \r
145         /* We should never get here as control is now taken by the scheduler. */\r
146         return;\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 static void prvSetupHardware( void )\r
151 {\r
152     /* Setup the PLL to generate a 48MHz clock from the 4MHz CLK. */\r
153 \r
154     /* Turn of the div by two. */\r
155         RCCU_Div2Config( DISABLE );\r
156 \r
157     /* 48MHz = ( 4MHz * 12 ) / 1 */\r
158         RCCU_PLL1Config( RCCU_PLL1_Mul_12, RCCU_Div_1 );\r
159     RCCU_RCLKSourceConfig( RCCU_PLL1_Output );\r
160 }\r
161 /*-----------------------------------------------------------*/\r
162 \r
163 static void vErrorChecks( void *pvParameters )\r
164 {\r
165 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
166 TickType_t xLastWakeTime;\r
167 \r
168         /* The parameters are not used in this task. */\r
169         ( void ) pvParameters;\r
170 \r
171         /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()\r
172         functions correctly. */\r
173         xLastWakeTime = xTaskGetTickCount();\r
174 \r
175         /* Cycle for ever, delaying then checking all the other tasks are still\r
176         operating without error.  If an error is detected then the delay period\r
177         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
178         the on board LED flash rate will increase. */\r
179 \r
180         for( ;; )\r
181         {\r
182                 /* Delay until it is time to execute again.  The delay period is\r
183                 shorter following an error so the LED flashes faster. */\r
184                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
185         \r
186                 /* Check all the standard demo application tasks are executing without\r
187                 error. */\r
188                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
189                 {\r
190                         /* An error has been detected in one of the tasks - flash faster. */\r
191                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
192                 }\r
193                 \r
194                 vParTestToggleLED( mainCHECK_TASK_LED );\r
195         }\r
196 }\r
197 /*-----------------------------------------------------------*/\r
198 \r
199 static long prvCheckOtherTasksAreStillRunning( void )\r
200 {\r
201 long lReturn = ( long ) pdPASS;\r
202 \r
203         /* Check all the demo tasks (other than the flash tasks) to ensure\r
204         that they are all still running, and that none of them have detected\r
205         an error. */\r
206 \r
207         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
208         {\r
209                 lReturn = ( long ) pdFAIL;\r
210         }\r
211 \r
212         if( xArePollingQueuesStillRunning() != pdTRUE )\r
213         {\r
214                 lReturn = ( long ) pdFAIL;\r
215         }\r
216 \r
217         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
218         {\r
219                 lReturn = ( long ) pdFAIL;\r
220         }\r
221 \r
222         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
223         {\r
224                 lReturn = ( long ) pdFAIL;\r
225         }\r
226 \r
227         if( xAreComTestTasksStillRunning() != pdTRUE )\r
228         {\r
229                 lReturn = ( long ) pdFAIL;\r
230         }\r
231 \r
232         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
233         {\r
234                 lReturn = ( long ) pdFAIL;\r
235         }\r
236 \r
237         return lReturn;\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 \r