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