]> begriffs open source - cmsis-freertos/blob - Demo/ARM7_STR75x_IAR/main.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / ARM7_STR75x_IAR / 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  * Creates all the demo application tasks, then starts the scheduler.  The WEB
72  * documentation provides more details of the demo application tasks.
73  *
74  * In addition to the standard demo tasks there are two tasks defined within
75  * this file:
76  *
77  * 1 - The check task
78  * The 'check' task is responsible for ensuring that all the standard demo
79  * tasks are executing as expected.  It only executes every three seconds, but
80  * has the highest priority within the system so is guaranteed to get execution
81  * time.  Any errors discovered by the check task are latched until the
82  * processor is reset.  At the end of each cycle the check task sends either
83  * a pass or fail message to the 'print' task for display on the LCD.
84  *
85  * 2 - The print task
86  * The print task is the LCD 'gatekeeper'.  That is, it is the only task that
87  * should access the LCD directly so is always guaranteed exclusive (and
88  * therefore consistent) access.  The print task simply blocks on a queue
89  * to wait for messages from other tasks wishing to display text on the LCD.
90  * When a message arrives it displays its contents on the LCD then blocks to
91  * wait again.
92  */
93
94 /* ST includes. */
95 #include "lcd.h"
96
97 /* Kernel includes. */
98 #include "FreeRTOS.h"
99 #include "task.h"
100 #include "queue.h"
101
102 /* Demo application includes. */
103 #include "partest.h"
104 #include "flash.h"
105 #include "integer.h"
106 #include "blocktim.h"
107 #include "BlockQ.h"
108 #include "comtest2.h"
109 #include "dynamic.h"
110
111 /* Demo application task priorities. */
112 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )
113 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )
114 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
115 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )
116 #define mainLCD_TASK_PRIORITY           ( tskIDLE_PRIORITY + 1 )
117
118 /* How often should we check the other tasks? */
119 #define mainCHECK_TASK_CYCLE_TIME       ( 3000 )
120
121 /* The maximum offset into the pass and fail strings sent to the LCD.  An
122 offset is used a simple method of using a different column each time a message
123 is written to the LCD. */
124 #define mainMAX_WRITE_COLUMN            ( 14 )
125
126 /* Baud rate used by the comtest tasks. */
127 #define mainCOM_TEST_BAUD_RATE          ( 19200 )
128
129 /* The LED used by the comtest tasks. See the comtest.c file for more
130 information. */
131 #define mainCOM_TEST_LED                        ( 3 )
132
133 /* The number of messages that can be queued for display on the LCD at any one
134 time. */
135 #define mainLCD_QUEUE_LENGTH            ( 2 )
136
137 /* The time to wait when sending to mainLCD_QUEUE_LENGTH. */
138 #define mainNO_DELAY                            ( 0 )
139
140 /*-----------------------------------------------------------*/
141
142 /* The type that is posted to the LCD queue. */
143 typedef struct LCD_MESSAGE
144 {
145         unsigned char *pucString; /* Points to the string to be displayed. */
146         unsigned char ucLine;     /* The line of the LCD that should be used. */
147 } LCDMessage;
148
149 /*-----------------------------------------------------------*/
150
151 /*
152  * The task that executes at the highest priority and checks the operation of
153  * all the other tasks in the system.  See the description at the top of the
154  * file.
155  */
156 static void vCheckTask( void *pvParameters );
157
158 /*
159  * ST provided routine to configure the processor.
160  */
161 static void prvSetupHardware(void);
162
163 /*
164  * The only task that should access the LCD.  Other tasks wanting to write
165  * to the LCD should send a message of type LCDMessage containing the
166  * information to display to the print task.  The print task simply blocks
167  * waiting for the arrival of such messages, displays the message, then blocks
168  * again.
169  */
170 static void vPrintTask( void *pvParameters );
171
172 /*-----------------------------------------------------------*/
173
174 /* The queue used to communicate with the LCD print task. */
175 static QueueHandle_t xLCDQueue;
176
177 /*-----------------------------------------------------------*/
178
179 /* Create all the demo application tasks, then start the scheduler. */
180 void main( void )
181 {
182         /* Perform any hardware setup necessary. */
183         prvSetupHardware();
184         vParTestInitialise();
185
186         /* Create the queue used to communicate with the LCD print task. */
187         xLCDQueue = xQueueCreate( mainLCD_QUEUE_LENGTH, sizeof( LCDMessage ) );
188
189         /* Create the standard demo application tasks.  See the WEB documentation
190         for more information on these tasks. */
191         vCreateBlockTimeTasks();
192         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
193         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
194         vStartDynamicPriorityTasks();
195         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
196         vStartIntegerMathTasks( tskIDLE_PRIORITY );
197
198         /* Create the tasks defined within this file. */
199         xTaskCreate( vPrintTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
200         xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
201
202         vTaskStartScheduler();
203
204         /* Execution will only reach here if there was insufficient heap to
205         start the scheduler. */
206 }
207 /*-----------------------------------------------------------*/
208
209 static void vCheckTask( void *pvParameters )
210 {
211 static unsigned long ulErrorDetected = pdFALSE;
212 TickType_t xLastExecutionTime;
213 unsigned char *cErrorMessage = "              FAIL";
214 unsigned char *cSuccessMessage = "              PASS";
215 unsigned portBASE_TYPE uxColumn = mainMAX_WRITE_COLUMN;
216 LCDMessage xMessage;
217
218         /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
219         works correctly. */
220         xLastExecutionTime = xTaskGetTickCount();
221
222         for( ;; )
223         {
224                 /* Wait until it is time for the next cycle. */
225                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_CYCLE_TIME );
226
227                 /* Has an error been found in any of the standard demo tasks? */
228
229                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
230                 {
231                         ulErrorDetected = pdTRUE;
232                 }
233
234                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
235                 {
236                         ulErrorDetected = pdTRUE;
237                 }
238
239                 if( xAreBlockingQueuesStillRunning() != pdTRUE )
240                 {
241                         ulErrorDetected = pdTRUE;
242                 }
243
244                 if( xAreComTestTasksStillRunning() != pdTRUE )
245                 {
246                         ulErrorDetected = pdTRUE;
247                 }
248
249                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
250                 {
251                         ulErrorDetected = pdTRUE;
252                 }
253
254                 /* Calculate the LCD line on which we would like the message to
255                 be displayed.  The column variable is used for convenience as
256                 it is incremented each cycle anyway. */
257                 xMessage.ucLine = ( unsigned char ) ( uxColumn & 0x01 );
258
259                 /* The message displayed depends on whether an error was found or
260                 not.  Any discovered error is latched.  Here the column variable
261                 is used as an index into the text string as a simple way of moving
262                 the text from column to column. */
263                 if( ulErrorDetected == pdFALSE )
264                 {
265                         xMessage.pucString = cSuccessMessage + uxColumn;
266                 }
267                 else
268                 {
269                         xMessage.pucString = cErrorMessage + uxColumn;
270                 }
271
272                 /* Send the message to the print task for display. */
273                 xQueueSend( xLCDQueue, ( void * ) &xMessage, mainNO_DELAY );
274
275                 /* Make sure the message is printed in a different column the next
276                 time around. */
277                 uxColumn--;
278                 if( uxColumn == 0 )
279                 {
280                         uxColumn = mainMAX_WRITE_COLUMN;
281                 }
282         }
283 }
284 /*-----------------------------------------------------------*/
285
286 static void vPrintTask( void *pvParameters )
287 {
288 LCDMessage xMessage;
289
290         for( ;; )
291         {
292                 /* Wait until a message arrives. */
293                 while( xQueueReceive( xLCDQueue, ( void * ) &xMessage, portMAX_DELAY ) != pdPASS );
294
295                 /* The message contains the text to display, and the line on which the
296                 text should be displayed. */
297                 LCD_Clear();
298                 LCD_DisplayString( xMessage.ucLine, xMessage.pucString, BlackText );
299         }
300 }
301 /*-----------------------------------------------------------*/
302
303 static void prvSetupHardware(void)
304 {
305 ErrorStatus OSC4MStartUpStatus01;
306
307         /* ST provided routine. */
308
309         /* MRCC system reset */
310         MRCC_DeInit();
311
312         /* Wait for OSC4M start-up */
313         OSC4MStartUpStatus01 = MRCC_WaitForOSC4MStartUp();
314
315         if(OSC4MStartUpStatus01 == SUCCESS)
316         {
317                 /* Set HCLK to 60MHz */
318                 MRCC_HCLKConfig(MRCC_CKSYS_Div1);
319
320                 /* Set CKTIM to 60MHz */
321                 MRCC_CKTIMConfig(MRCC_HCLK_Div1);
322
323                 /* Set PCLK to 30MHz */
324                 MRCC_PCLKConfig(MRCC_CKTIM_Div2);
325
326                 /* Enable Flash Burst mode */
327                 CFG_FLASHBurstConfig(CFG_FLASHBurst_Enable);
328
329                 /* Set CK_SYS to 60 MHz */
330                 MRCC_CKSYSConfig(MRCC_CKSYS_OSC4MPLL, MRCC_PLL_Mul_15);
331         }
332
333         /* GPIO pins optimized for 3V3 operation */
334         MRCC_IOVoltageRangeConfig(MRCC_IOVoltageRange_3V3);
335
336         /* GPIO clock source enable */
337         MRCC_PeripheralClockConfig(MRCC_Peripheral_GPIO, ENABLE);
338
339         /* EXTIT clock source enable */
340         MRCC_PeripheralClockConfig(MRCC_Peripheral_EXTIT, ENABLE);
341         /* TB clock source enable */
342         MRCC_PeripheralClockConfig(MRCC_Peripheral_TB, ENABLE);
343
344         /* Initialize the demonstration menu */
345         LCD_Init();
346
347         LCD_DisplayString(Line1, "www.FreeRTOS.org", BlackText);
348         LCD_DisplayString(Line2, "  STR750 Demo  ", BlackText);
349
350         EIC_IRQCmd(ENABLE);
351 }
352 /*-----------------------------------------------------------*/