]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_LPC2129_Keil_RVDS/main.c
Update version number in readiness for V10.3.0 release. Sync SVN with reviewed releas...
[freertos] / FreeRTOS / Demo / ARM7_LPC2129_Keil_RVDS / main.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 /* \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 /*\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 /* Standard includes. */\r
56 #include <stdlib.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 "partest.h"\r
64 #include "flash.h"\r
65 #include "comtest2.h"\r
66 #include "serial.h"\r
67 #include "PollQ.h"\r
68 #include "BlockQ.h"\r
69 #include "semtest.h"\r
70 #include "dynamic.h"\r
71 \r
72 /*-----------------------------------------------------------*/\r
73 \r
74 /* Constants to setup I/O and processor. */\r
75 #define mainTX_ENABLE           ( ( unsigned long ) 0x00010000 )        /* UART1. */\r
76 #define mainRX_ENABLE           ( ( unsigned long ) 0x00040000 )        /* UART1. */\r
77 #define mainBUS_CLK_FULL        ( ( unsigned char ) 0x01 )\r
78 #define mainLED_TO_OUTPUT       ( ( unsigned long ) 0xff0000 )\r
79 \r
80 /* Constants for the ComTest demo application tasks. */\r
81 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 115200 )\r
82 #define mainCOM_TEST_LED                ( 3 )\r
83 \r
84 /* Priorities for the demo application tasks. */\r
85 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
86 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
87 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
88 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
89 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
90 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
91 \r
92 /* Constants used by the "check" task.  As described at the head of this file\r
93 the check task toggles an LED.  The rate at which the LED flashes is used to\r
94 indicate whether an error has been detected or not.  If the LED toggles every\r
95 3 seconds then no errors have been detected.  If the rate increases to 500ms\r
96 then an error has been detected in at least one of the demo application tasks. */\r
97 #define mainCHECK_LED                           ( 7 )\r
98 #define mainNO_ERROR_FLASH_PERIOD       ( ( TickType_t ) 3000 / portTICK_PERIOD_MS  )\r
99 #define mainERROR_FLASH_PERIOD          ( ( TickType_t ) 500 / portTICK_PERIOD_MS  )\r
100 \r
101 /*-----------------------------------------------------------*/\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.\r
106  */\r
107 static long prvCheckOtherTasksAreStillRunning( void );\r
108 \r
109 /*\r
110  * The task that executes at the highest priority and calls \r
111  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
112  * of the file.\r
113  */\r
114 static void vErrorChecks( void *pvParameters );\r
115 \r
116 /*\r
117  * Configure the processor for use with the Keil demo board.  This is very\r
118  * minimal as most of the setup is managed by the settings in the project\r
119  * file.\r
120  */\r
121 static void prvSetupHardware( void );\r
122 \r
123 /*-----------------------------------------------------------*/\r
124 \r
125 \r
126 \r
127 /*\r
128  * Application entry point:\r
129  * Starts all the other tasks, then starts the scheduler. \r
130  */\r
131 int main( void )\r
132 {\r
133         /* Setup the hardware for use with the Keil demo board. */\r
134         prvSetupHardware();\r
135 \r
136         /* Start the demo/test application tasks. */\r
137         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
138         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
139         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
140         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
141         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
142         vStartDynamicPriorityTasks();\r
143 \r
144         /* Start the check task - which is defined in this file.  This is the task\r
145         that periodically checks to see that all the other tasks are executing \r
146         without error. */\r
147         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
148 \r
149         /* Now all the tasks have been started - start the scheduler.\r
150 \r
151         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
152         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
153         called.  The demo applications included in the FreeRTOS.org download switch\r
154         to supervisor mode prior to main being called.  If you are not using one of\r
155         these demo application projects then ensure Supervisor mode is used here. */\r
156         vTaskStartScheduler();\r
157 \r
158         /* Should never reach here!  If you do then there was not enough heap\r
159         available for the idle task to be created. */\r
160         for( ;; );\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 \r
168         /* Parameters are not used. */\r
169         ( void ) pvParameters;\r
170 \r
171         /* Cycle for ever, delaying then checking all the other tasks are still\r
172         operating without error.  If an error is detected then the delay period\r
173         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
174         the on board LED flash rate will increase.\r
175 \r
176         This task runs at the highest priority. */\r
177 \r
178         for( ;; )\r
179         {\r
180                 /* The period of the delay depends on whether an error has been \r
181                 detected or not.  If an error has been detected then the period\r
182                 is reduced to increase the LED flash rate. */\r
183                 vTaskDelay( xDelayPeriod );\r
184 \r
185                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
186                 {\r
187                         /* An error has been detected in one of the tasks - flash faster. */\r
188                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
189                 }\r
190 \r
191                 /* Toggle the LED before going back to wait for the next cycle. */\r
192                 vParTestToggleLED( mainCHECK_LED );\r
193         }\r
194 }\r
195 /*-----------------------------------------------------------*/\r
196 \r
197 static void prvSetupHardware( void )\r
198 {\r
199         /* Perform the hardware setup required.  This is minimal as most of the\r
200         setup is managed by the settings in the project file. */\r
201 \r
202         /* Configure the UART1 pins.  All other pins remain at their default of 0. */\r
203         PINSEL0 |= mainTX_ENABLE;\r
204         PINSEL0 |= mainRX_ENABLE;\r
205 \r
206         /* LED pins need to be output. */\r
207         IODIR1 = mainLED_TO_OUTPUT;\r
208 \r
209         /* Setup the peripheral bus to be the same as the PLL output. */\r
210         VPBDIV = mainBUS_CLK_FULL;\r
211 }\r
212 /*-----------------------------------------------------------*/\r
213 \r
214 static long prvCheckOtherTasksAreStillRunning( void )\r
215 {\r
216 long lReturn = pdPASS;\r
217 \r
218         /* Check all the demo tasks (other than the flash tasks) to ensure\r
219         that they are all still running, and that none of them have detected\r
220         an error. */\r
221         if( xAreComTestTasksStillRunning() != pdPASS )\r
222         {\r
223                 lReturn = pdFAIL;\r
224         }\r
225 \r
226         if( xArePollingQueuesStillRunning() != pdTRUE )\r
227         {\r
228                 lReturn = pdFAIL;\r
229         }\r
230 \r
231         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
232         {\r
233                 lReturn = pdFAIL;\r
234         }\r
235 \r
236         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
237         {\r
238                 lReturn = pdFAIL;\r
239         }\r
240 \r
241         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
242         {\r
243                 lReturn = pdFAIL;\r
244         }\r
245 \r
246         return lReturn;\r
247 }\r
248 /*-----------------------------------------------------------*/\r
249 \r
250 \r