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