]> begriffs open source - cmsis-freertos/blob - Demo/ARM7_LPC2129_Keil_RVDS/main.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / ARM7_LPC2129_Keil_RVDS / main.c
1 /*
2     FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
3     All rights reserved
4
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
6
7     This file is part of the FreeRTOS distribution.
8
9     FreeRTOS is free software; you can redistribute it and/or modify it under
10     the terms of the GNU General Public License (version 2) as published by the
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
12
13     ***************************************************************************
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<
16     >>!   obliged to provide the source code for proprietary components     !<<
17     >>!   outside of the FreeRTOS kernel.                                   !<<
18     ***************************************************************************
19
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following
23     link: http://www.freertos.org/a00114.html
24
25     ***************************************************************************
26      *                                                                       *
27      *    FreeRTOS provides completely free yet professionally developed,    *
28      *    robust, strictly quality controlled, supported, and cross          *
29      *    platform software that is more than just the market leader, it     *
30      *    is the industry's de facto standard.                               *
31      *                                                                       *
32      *    Help yourself get started quickly while simultaneously helping     *
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *
34      *    tutorial book, reference manual, or both:                          *
35      *    http://www.FreeRTOS.org/Documentation                              *
36      *                                                                       *
37     ***************************************************************************
38
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading
40     the FAQ page "My application does not run, what could be wrong?".  Have you
41     defined configASSERT()?
42
43     http://www.FreeRTOS.org/support - In return for receiving this top quality
44     embedded software for free we request you assist our global community by
45     participating in the support forum.
46
47     http://www.FreeRTOS.org/training - Investing in training allows your team to
48     be as productive as possible as early as possible.  Now you can receive
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50     Ltd, and the world's leading authority on the world's leading RTOS.
51
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.
55
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
58
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
61     licenses offer ticketed support, indemnification and commercial middleware.
62
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64     engineered and independently SIL3 certified version for use in safety and
65     mission critical applications that require provable dependability.
66
67     1 tab == 4 spaces!
68 */
69
70 /* 
71         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
72         The processor MUST be in supervisor mode when vTaskStartScheduler is 
73         called.  The demo applications included in the FreeRTOS.org download switch
74         to supervisor mode prior to main being called.  If you are not using one of
75         these demo application projects then ensure Supervisor mode is used.
76 */
77
78
79 /*
80  * Creates all the demo application tasks, then starts the scheduler.  The WEB
81  * documentation provides more details of the demo application tasks.
82  * 
83  * Main.c also creates a task called "Check".  This only executes every three 
84  * seconds but has the highest priority so is guaranteed to get processor time.  
85  * Its main function is to check that all the other tasks are still operational.
86  * Each task (other than the "flash" tasks) maintains a unique count that is 
87  * incremented each time the task successfully completes its function.  Should 
88  * any error occur within such a task the count is permanently halted.  The 
89  * check task inspects the count of each task to ensure it has changed since
90  * the last time the check task executed.  If all the count variables have 
91  * changed all the tasks are still executing error free, and the check task
92  * toggles the onboard LED.  Should any task contain an error at any time 
93  * the LED toggle rate will change from 3 seconds to 500ms.
94  *
95  */
96
97 /* Standard includes. */
98 #include <stdlib.h>
99
100 /* Scheduler includes. */
101 #include "FreeRTOS.h"
102 #include "task.h"
103
104 /* Demo application includes. */
105 #include "partest.h"
106 #include "flash.h"
107 #include "comtest2.h"
108 #include "serial.h"
109 #include "PollQ.h"
110 #include "BlockQ.h"
111 #include "semtest.h"
112 #include "dynamic.h"
113
114 /*-----------------------------------------------------------*/
115
116 /* Constants to setup I/O and processor. */
117 #define mainTX_ENABLE           ( ( unsigned long ) 0x00010000 )        /* UART1. */
118 #define mainRX_ENABLE           ( ( unsigned long ) 0x00040000 )        /* UART1. */
119 #define mainBUS_CLK_FULL        ( ( unsigned char ) 0x01 )
120 #define mainLED_TO_OUTPUT       ( ( unsigned long ) 0xff0000 )
121
122 /* Constants for the ComTest demo application tasks. */
123 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned long ) 115200 )
124 #define mainCOM_TEST_LED                ( 3 )
125
126 /* Priorities for the demo application tasks. */
127 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )
128 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )
129 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )
130 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
131 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
132 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )
133
134 /* Constants used by the "check" task.  As described at the head of this file
135 the check task toggles an LED.  The rate at which the LED flashes is used to
136 indicate whether an error has been detected or not.  If the LED toggles every
137 3 seconds then no errors have been detected.  If the rate increases to 500ms
138 then an error has been detected in at least one of the demo application tasks. */
139 #define mainCHECK_LED                           ( 7 )
140 #define mainNO_ERROR_FLASH_PERIOD       ( ( TickType_t ) 3000 / portTICK_PERIOD_MS  )
141 #define mainERROR_FLASH_PERIOD          ( ( TickType_t ) 500 / portTICK_PERIOD_MS  )
142
143 /*-----------------------------------------------------------*/
144
145 /*
146  * Checks that all the demo application tasks are still executing without error
147  * - as described at the top of the file.
148  */
149 static long prvCheckOtherTasksAreStillRunning( void );
150
151 /*
152  * The task that executes at the highest priority and calls 
153  * prvCheckOtherTasksAreStillRunning().  See the description at the top
154  * of the file.
155  */
156 static void vErrorChecks( void *pvParameters );
157
158 /*
159  * Configure the processor for use with the Keil demo board.  This is very
160  * minimal as most of the setup is managed by the settings in the project
161  * file.
162  */
163 static void prvSetupHardware( void );
164
165 /*-----------------------------------------------------------*/
166
167
168
169 /*
170  * Application entry point:
171  * Starts all the other tasks, then starts the scheduler. 
172  */
173 int main( void )
174 {
175         /* Setup the hardware for use with the Keil demo board. */
176         prvSetupHardware();
177
178         /* Start the demo/test application tasks. */
179         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
180         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
181         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
182         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
183         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
184         vStartDynamicPriorityTasks();
185
186         /* Start the check task - which is defined in this file.  This is the task
187         that periodically checks to see that all the other tasks are executing 
188         without error. */
189         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
190
191         /* Now all the tasks have been started - start the scheduler.
192
193         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
194         The processor MUST be in supervisor mode when vTaskStartScheduler is 
195         called.  The demo applications included in the FreeRTOS.org download switch
196         to supervisor mode prior to main being called.  If you are not using one of
197         these demo application projects then ensure Supervisor mode is used here. */
198         vTaskStartScheduler();
199
200         /* Should never reach here!  If you do then there was not enough heap
201         available for the idle task to be created. */
202         for( ;; );
203 }
204 /*-----------------------------------------------------------*/
205
206 static void vErrorChecks( void *pvParameters )
207 {
208 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
209
210         /* Parameters are not used. */
211         ( void ) pvParameters;
212
213         /* Cycle for ever, delaying then checking all the other tasks are still
214         operating without error.  If an error is detected then the delay period
215         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
216         the on board LED flash rate will increase.
217
218         This task runs at the highest priority. */
219
220         for( ;; )
221         {
222                 /* The period of the delay depends on whether an error has been 
223                 detected or not.  If an error has been detected then the period
224                 is reduced to increase the LED flash rate. */
225                 vTaskDelay( xDelayPeriod );
226
227                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
228                 {
229                         /* An error has been detected in one of the tasks - flash faster. */
230                         xDelayPeriod = mainERROR_FLASH_PERIOD;
231                 }
232
233                 /* Toggle the LED before going back to wait for the next cycle. */
234                 vParTestToggleLED( mainCHECK_LED );
235         }
236 }
237 /*-----------------------------------------------------------*/
238
239 static void prvSetupHardware( void )
240 {
241         /* Perform the hardware setup required.  This is minimal as most of the
242         setup is managed by the settings in the project file. */
243
244         /* Configure the UART1 pins.  All other pins remain at their default of 0. */
245         PINSEL0 |= mainTX_ENABLE;
246         PINSEL0 |= mainRX_ENABLE;
247
248         /* LED pins need to be output. */
249         IODIR1 = mainLED_TO_OUTPUT;
250
251         /* Setup the peripheral bus to be the same as the PLL output. */
252         VPBDIV = mainBUS_CLK_FULL;
253 }
254 /*-----------------------------------------------------------*/
255
256 static long prvCheckOtherTasksAreStillRunning( void )
257 {
258 long lReturn = pdPASS;
259
260         /* Check all the demo tasks (other than the flash tasks) to ensure
261         that they are all still running, and that none of them have detected
262         an error. */
263         if( xAreComTestTasksStillRunning() != pdPASS )
264         {
265                 lReturn = pdFAIL;
266         }
267
268         if( xArePollingQueuesStillRunning() != pdTRUE )
269         {
270                 lReturn = pdFAIL;
271         }
272
273         if( xAreBlockingQueuesStillRunning() != pdTRUE )
274         {
275                 lReturn = pdFAIL;
276         }
277
278         if( xAreSemaphoreTasksStillRunning() != pdTRUE )
279         {
280                 lReturn = pdFAIL;
281         }
282
283         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
284         {
285                 lReturn = pdFAIL;
286         }
287
288         return lReturn;
289 }
290 /*-----------------------------------------------------------*/
291
292