]> begriffs open source - cmsis-freertos/blob - Demo/ARM7_LPC2368_Rowley/main.c
Update cmsis_os2.c
[cmsis-freertos] / Demo / ARM7_LPC2368_Rowley / 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 /* Environment includes. */
71 #include <targets/LPC2368.h>
72
73 /* Scheduler includes. */
74 #include "FreeRTOS.h"
75 #include "task.h"
76 #include "queue.h"
77 #include "semphr.h"
78
79 /* Demo app includes. */
80 #include "BlockQ.h"
81 #include "death.h"
82 #include "integer.h"
83 #include "blocktim.h"
84 #include "portlcd.h"
85 #include "flash.h"
86 #include "partest.h"
87 #include "semtest.h"
88 #include "PollQ.h"
89
90 /* Demo application definitions. */
91 #define mainQUEUE_SIZE                                          ( 3 )
92 #define mainCHECK_DELAY                                         ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
93 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 2 )
94
95 /* Task priorities. */
96 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
97 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
98 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
99 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
100 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )
101 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
102 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
103
104
105 /*
106  * Checks the status of all the demo tasks then prints a message to the
107  * CrossStudio terminal IO windows.  The message will be either PASS or FAIL
108  * depending on the status of the demo applications tasks.  A FAIL status will
109  * be latched.
110  *
111  * Messages are not written directly to the terminal, but passed to vPrintTask
112  * via a queue.
113  */
114 static void vCheckTask( void *pvParameters );
115
116 /*
117  * The task that handles the uIP stack.  All TCP/IP processing is performed in
118  * this task.
119  */
120 extern void vuIP_Task( void *pvParameters );
121
122 /*
123  * The LCD is written two by more than one task so is controlled by a
124  * 'gatekeeper' task.  This is the only task that is actually permitted to
125  * access the LCD directly.  Other tasks wanting to display a message send
126  * the message to the gatekeeper.
127  */
128 static void vLCDTask( void *pvParameters );
129
130 /* The queue used to send messages to the LCD task. */
131 QueueHandle_t xLCDQueue;
132
133 /*-----------------------------------------------------------*/
134
135 int main (void)
136 {
137         /* Setup the led's on the MCB2300 board */
138         vParTestInitialise();
139
140         /* Create the queue used by the LCD task.  Messages for display on the LCD
141         are received via this queue. */
142         xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
143
144         /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/
145     xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
146
147         /* Start the standard demo tasks - these serve no useful purpose other than
148         to demonstrate the FreeRTOS API being used and to test the port. */
149         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
150     vCreateBlockTimeTasks();
151     vStartLEDFlashTasks( mainFLASH_PRIORITY );
152     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
153     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
154     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
155
156         /* Start the tasks defined within this file/specific to this demo. */
157     xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
158         xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
159
160         /* The suicide tasks must be created last as they need to know how many
161         tasks were running prior to their creation in order to ascertain whether
162         or not the correct/expected number of tasks are running at any given time. */
163     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
164
165         /* Start the scheduler. */
166         vTaskStartScheduler();
167
168     /* Will only get here if there was insufficient memory to create the idle
169     task. */
170         return 0;
171 }
172 /*-----------------------------------------------------------*/
173
174 static void vCheckTask( void *pvParameters )
175 {
176 portBASE_TYPE xErrorOccurred = pdFALSE;
177 TickType_t xLastExecutionTime;
178 unsigned portBASE_TYPE uxColumn = 0;
179 xLCDMessage xMessage;
180
181         xLastExecutionTime = xTaskGetTickCount();
182
183         xMessage.xColumn = 0;
184         xMessage.pcMessage = "PASS";
185
186     for( ;; )
187         {
188                 /* Perform this check every mainCHECK_DELAY milliseconds. */
189                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
190
191                 /* Has an error been found in any task? */
192
193         if( xAreBlockingQueuesStillRunning() != pdTRUE )
194                 {
195                         xErrorOccurred = pdTRUE;
196                 }
197
198                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
199                 {
200                         xErrorOccurred = pdTRUE;
201                 }
202
203         if( xAreSemaphoreTasksStillRunning() != pdTRUE )
204         {
205             xErrorOccurred = pdTRUE;
206         }
207
208         if( xArePollingQueuesStillRunning() != pdTRUE )
209         {
210             xErrorOccurred = pdTRUE;
211         }
212
213         if( xIsCreateTaskStillRunning() != pdTRUE )
214         {
215             xErrorOccurred = pdTRUE;
216         }
217
218         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
219         {
220             xErrorOccurred = pdTRUE;
221         }
222
223         LCD_cls();
224         xMessage.xColumn++;
225         LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );
226
227         if( xErrorOccurred == pdTRUE )
228         {
229             xMessage.pcMessage = "FAIL";
230         }
231
232                 /* Send the message to the LCD gatekeeper for display. */
233                 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
234         }
235 }
236 /*-----------------------------------------------------------*/
237
238 void vLCDTask( void *pvParameters )
239 {
240 xLCDMessage xMessage;
241
242         /* Initialise the LCD and display a startup message. */
243         LCD_init();
244         LCD_cur_off();
245     LCD_cls();
246     LCD_gotoxy( 1, 1 );
247     LCD_puts( ( signed char * ) "www.FreeRTOS.org" );
248
249         for( ;; )
250         {
251                 /* Wait for a message to arrive that requires displaying. */
252                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
253
254                 /* Display the message.  Print each message to a different position. */
255                 LCD_cls();
256                 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
257                 LCD_puts( xMessage.pcMessage );
258         }
259
260 }
261 /*-----------------------------------------------------------*/
262
263 /* Keep the compiler quiet. */
264 #include <stdio.h>
265 int __putchar( int c )
266 {
267     return EOF;
268 }
269
270
271
272
273