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