]> begriffs open source - cmsis-freertos/blob - Demo/ARM7_LPC2368_Rowley/main.c
there was an extra ')'... caused build to fail
[cmsis-freertos] / Demo / ARM7_LPC2368_Rowley / main.c
1 /*
2  * FreeRTOS Kernel V10.1.1
3  * Copyright (C) 2018 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of
6  * this software and associated documentation files (the "Software"), to deal in
7  * the Software without restriction, including without limitation the rights to
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9  * the Software, and to permit persons to whom the Software is furnished to do so,
10  * subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28 /* Environment includes. */
29 #include <targets/LPC2368.h>
30
31 /* Scheduler includes. */
32 #include "FreeRTOS.h"
33 #include "task.h"
34 #include "queue.h"
35 #include "semphr.h"
36
37 /* Demo app includes. */
38 #include "BlockQ.h"
39 #include "death.h"
40 #include "integer.h"
41 #include "blocktim.h"
42 #include "portlcd.h"
43 #include "flash.h"
44 #include "partest.h"
45 #include "semtest.h"
46 #include "PollQ.h"
47
48 /* Demo application definitions. */
49 #define mainQUEUE_SIZE                                          ( 3 )
50 #define mainCHECK_DELAY                                         ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
51 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 2 )
52
53 /* Task priorities. */
54 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
55 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
56 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
57 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
58 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )
59 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
60 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
61
62
63 /*
64  * Checks the status of all the demo tasks then prints a message to the
65  * CrossStudio terminal IO windows.  The message will be either PASS or FAIL
66  * depending on the status of the demo applications tasks.  A FAIL status will
67  * be latched.
68  *
69  * Messages are not written directly to the terminal, but passed to vPrintTask
70  * via a queue.
71  */
72 static void vCheckTask( void *pvParameters );
73
74 /*
75  * The task that handles the uIP stack.  All TCP/IP processing is performed in
76  * this task.
77  */
78 extern void vuIP_Task( void *pvParameters );
79
80 /*
81  * The LCD is written two by more than one task so is controlled by a
82  * 'gatekeeper' task.  This is the only task that is actually permitted to
83  * access the LCD directly.  Other tasks wanting to display a message send
84  * the message to the gatekeeper.
85  */
86 static void vLCDTask( void *pvParameters );
87
88 /* The queue used to send messages to the LCD task. */
89 QueueHandle_t xLCDQueue;
90
91 /*-----------------------------------------------------------*/
92
93 int main (void)
94 {
95         /* Setup the led's on the MCB2300 board */
96         vParTestInitialise();
97
98         /* Create the queue used by the LCD task.  Messages for display on the LCD
99         are received via this queue. */
100         xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
101
102         /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/
103     xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
104
105         /* Start the standard demo tasks - these serve no useful purpose other than
106         to demonstrate the FreeRTOS API being used and to test the port. */
107         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
108     vCreateBlockTimeTasks();
109     vStartLEDFlashTasks( mainFLASH_PRIORITY );
110     vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
111     vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
112     vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
113
114         /* Start the tasks defined within this file/specific to this demo. */
115     xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
116         xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
117
118         /* The suicide tasks must be created last as they need to know how many
119         tasks were running prior to their creation in order to ascertain whether
120         or not the correct/expected number of tasks are running at any given time. */
121     vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
122
123         /* Start the scheduler. */
124         vTaskStartScheduler();
125
126     /* Will only get here if there was insufficient memory to create the idle
127     task. */
128         return 0;
129 }
130 /*-----------------------------------------------------------*/
131
132 static void vCheckTask( void *pvParameters )
133 {
134 portBASE_TYPE xErrorOccurred = pdFALSE;
135 TickType_t xLastExecutionTime;
136 unsigned portBASE_TYPE uxColumn = 0;
137 xLCDMessage xMessage;
138
139         xLastExecutionTime = xTaskGetTickCount();
140
141         xMessage.xColumn = 0;
142         xMessage.pcMessage = "PASS";
143
144     for( ;; )
145         {
146                 /* Perform this check every mainCHECK_DELAY milliseconds. */
147                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
148
149                 /* Has an error been found in any task? */
150
151         if( xAreBlockingQueuesStillRunning() != pdTRUE )
152                 {
153                         xErrorOccurred = pdTRUE;
154                 }
155
156                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
157                 {
158                         xErrorOccurred = pdTRUE;
159                 }
160
161         if( xAreSemaphoreTasksStillRunning() != pdTRUE )
162         {
163             xErrorOccurred = pdTRUE;
164         }
165
166         if( xArePollingQueuesStillRunning() != pdTRUE )
167         {
168             xErrorOccurred = pdTRUE;
169         }
170
171         if( xIsCreateTaskStillRunning() != pdTRUE )
172         {
173             xErrorOccurred = pdTRUE;
174         }
175
176         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
177         {
178             xErrorOccurred = pdTRUE;
179         }
180
181         LCD_cls();
182         xMessage.xColumn++;
183         LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );
184
185         if( xErrorOccurred == pdTRUE )
186         {
187             xMessage.pcMessage = "FAIL";
188         }
189
190                 /* Send the message to the LCD gatekeeper for display. */
191                 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
192         }
193 }
194 /*-----------------------------------------------------------*/
195
196 void vLCDTask( void *pvParameters )
197 {
198 xLCDMessage xMessage;
199
200         /* Initialise the LCD and display a startup message. */
201         LCD_init();
202         LCD_cur_off();
203     LCD_cls();
204     LCD_gotoxy( 1, 1 );
205     LCD_puts( ( signed char * ) "www.FreeRTOS.org" );
206
207         for( ;; )
208         {
209                 /* Wait for a message to arrive that requires displaying. */
210                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
211
212                 /* Display the message.  Print each message to a different position. */
213                 LCD_cls();
214                 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
215                 LCD_puts( xMessage.pcMessage );
216         }
217
218 }
219 /*-----------------------------------------------------------*/
220
221 /* Keep the compiler quiet. */
222 #include <stdio.h>
223 int __putchar( int c )
224 {
225     return EOF;
226 }
227
228
229
230
231