root/webserver/example/freeRTOSexample/Demo/ARM7_LPC2368_Rowley/main.c

Revision 19, 9.5 kB (checked in by phil, 15 years ago)

first display of button presses,
stubs for calculations,
removed calls of unused example functions

Line 
1 /*
2         FreeRTOS V5.4.1 - Copyright (C) 2009 Real Time Engineers Ltd.
3
4         This file is part of the FreeRTOS distribution.
5
6         FreeRTOS is free software; you can redistribute it and/or modify it     under
7         the terms of the GNU General Public License (version 2) as published by the
8         Free Software Foundation and modified by the FreeRTOS exception.
9         **NOTE** The exception to the GPL is included to allow you to distribute a
10         combined work that includes FreeRTOS without being obliged to provide the
11         source code for proprietary components outside of the FreeRTOS kernel. 
12         Alternative commercial license and support terms are also available upon
13         request.  See the licensing section of http://www.FreeRTOS.org for full
14         license details.
15
16         FreeRTOS is distributed in the hope that it will be useful,     but WITHOUT
17         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19         more details.
20
21         You should have received a copy of the GNU General Public License along
22         with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59
23         Temple Place, Suite 330, Boston, MA  02111-1307  USA.
24
25
26         ***************************************************************************
27         *                                                                         *
28         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *
29         * See http://www.FreeRTOS.org/Documentation for details                   *
30         *                                                                         *
31         ***************************************************************************
32
33         1 tab == 4 spaces!
34
35         Please ensure to read the configuration and relevant port sections of the
36         online documentation.
37
38         http://www.FreeRTOS.org - Documentation, latest information, license and
39         contact details.
40
41         http://www.SafeRTOS.com - A version that is certified for use in safety
42         critical systems.
43
44         http://www.OpenRTOS.com - Commercial support, development, porting,
45         licensing and training services.
46 */
47
48 /* Environment includes. */
49 #include <targets/LPC23xx.h>
50
51 /* Scheduler includes. */
52 #include "FreeRTOS.h"
53 #include "task.h"
54 #include "queue.h"
55 #include "semphr.h"
56
57 /* Demo app includes. */
58 #include "BlockQ.h"
59 #include "death.h"
60 #include "integer.h"
61 #include "blocktim.h"
62 #include "portlcd.h"
63 #include "flash.h"
64 #include "partest.h"
65 #include "semtest.h"
66 #include "PollQ.h"
67
68 /* Demo application definitions. */
69 #define mainQUEUE_SIZE                                          ( 3 )
70 #define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )
71 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 2 )
72
73 /* Task priorities. */
74 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
75 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
76 #define mainSEM_TEST_PRIORITY                           ( tskIDLE_PRIORITY + 1 )
77 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )
78 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )
79 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )
80 #define mainINTEGER_TASK_PRIORITY           ( tskIDLE_PRIORITY )
81
82
83 void setRTC(void);
84 void startRTC(void);
85
86 /*
87  * Checks the status of all the demo tasks then prints a message to the
88  * CrossStudio terminal IO windows.  The message will be either PASS or FAIL
89  * depending on the status of the demo applications tasks.  A FAIL status will
90  * be latched.
91  *
92  * Messages are not written directly to the terminal, but passed to vPrintTask
93  * via a queue.
94  */
95 static void vCheckTask( void *pvParameters );
96
97 /*
98  * The task that handles the uIP stack.  All TCP/IP processing is performed in
99  * this task.
100  */
101 extern void vuIP_Task( void *pvParameters );
102
103 /*
104  * The task that handles the electricity meter handling/calculations.
105  */
106 extern void vMeters_Task( void *pvParameters );
107
108 /*
109  * The LCD is written two by more than one task so is controlled by a
110  * 'gatekeeper' task.  This is the only task that is actually permitted to
111  * access the LCD directly.  Other tasks wanting to display a message send
112  * the message to the gatekeeper.
113  */
114 static void vLCDTask( void *pvParameters );
115
116 /* The queue used to send messages to the LCD task. */
117 xQueueHandle xLCDQueue;
118
119 /*-----------------------------------------------------------*/
120
121 int main (void)
122 {
123   startRTC(); /* start the RTC */
124
125   /* Setup the led's on the MCB2300 board */
126   vParTestInitialise();
127
128   /* Create the queue used by the LCD task.  Messages for display on the LCD
129   are received via this queue. */
130   xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
131
132   /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/
133   xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
134
135 //  vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
136   vStartMetersTask( mainBLOCK_Q_PRIORITY );
137         /* Start the standard demo tasks. */
138 //  vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
139 //  vCreateBlockTimeTasks();
140   vStartLEDFlashTasks( mainFLASH_PRIORITY );
141 //  vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
142 //  vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
143 //  vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
144
145         /* Start the tasks defined within this file/specific to this demo. */
146  //   xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
147     xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
148
149         /* The suicide tasks must be created last as they need to know how many
150         tasks were running prior to their creation in order to ascertain whether
151         or not the correct/expected number of tasks are running at any given time. */
152  //   vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
153
154
155         /* Start the scheduler. */
156         vTaskStartScheduler();
157
158     /* Will only get here if there was insufficient memory to create the idle
159     task. */
160         return 0;
161 }
162 /*-----------------------------------------------------------*/
163
164 static void vCheckTask( void *pvParameters )
165 {
166 portBASE_TYPE xErrorOccurred = pdFALSE;
167 portTickType xLastExecutionTime;
168 unsigned portBASE_TYPE uxColumn = 0;
169 xLCDMessage xMessage;
170
171         xLastExecutionTime = xTaskGetTickCount();
172
173         xMessage.xColumn = 0;
174         xMessage.pcMessage = "PASS";
175
176     for( ;; )
177         {
178                 /* Perform this check every mainCHECK_DELAY milliseconds. */
179                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
180
181                 /* Has an error been found in any task? */
182
183         if( xAreBlockingQueuesStillRunning() != pdTRUE )
184                 {
185                         xErrorOccurred = pdTRUE;
186                 }
187
188                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
189                 {
190                         xErrorOccurred = pdTRUE;
191                 }
192
193         if( xAreSemaphoreTasksStillRunning() != pdTRUE )
194         {
195             xErrorOccurred = pdTRUE;
196         }
197
198         if( xArePollingQueuesStillRunning() != pdTRUE )
199         {
200             xErrorOccurred = pdTRUE;
201         }
202
203         if( xIsCreateTaskStillRunning() != pdTRUE )
204         {
205             xErrorOccurred = pdTRUE;
206         }
207
208         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
209         {
210             xErrorOccurred = pdTRUE;
211         }
212
213         LCD_cls();
214         xMessage.xColumn++;
215         LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );
216
217         if( xErrorOccurred == pdTRUE )
218         {
219             xMessage.pcMessage = "FAIL";
220         }
221
222                 /* Send the message to the LCD gatekeeper for display. */
223                 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
224         }
225 }
226 /*-----------------------------------------------------------*/
227
228 void vLCDTask( void *pvParameters )
229 {
230 xLCDMessage xMessage;
231
232         /* Initialise the LCD and display a startup message. */
233         LCD_init();
234         LCD_cur_off();
235     LCD_cls();   
236     LCD_gotoxy( 1, 1 );
237     LCD_puts( ( signed portCHAR * ) "www.FreeRTOS.org" );
238
239         for( ;; )
240         {
241                 /* Wait for a message to arrive that requires displaying. */
242                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
243                
244                 /* Display the message.  Print each message to a different position. */
245                 LCD_cls();
246                 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
247                 LCD_puts( xMessage.pcMessage );
248         }
249
250 }
251 /*-----------------------------------------------------------*/
252
253 /* Keep the compiler quiet. */
254 #include <stdio.h>
255 int __putchar( int c )
256 {
257     return EOF;
258 }
259
260 void setRTC(void)
261 {
262 /*
263   This function needs to be called when the RTC battery was replaces
264
265   SEC 6 Seconds value in the range of 0 to 59 R/W 0xE002 4020
266   MIN 6 Minutes value in the range of 0 to 59 R/W 0xE002 4024
267   HOUR 5 Hours value in the range of 0 to 23 R/W 0xE002 4028
268   DOM 5 Day of month value in the range of 1 to 28, 29, 30,
269   or 31 (depending on the month and whether it is a
270   leap year).[1]
271   R/W 0xE002 402C
272   DOW 3 Day of week value in the range of 0 to 6[1] R/W 0xE002 4030
273   DOY 9 Day of year value in the range of 1 to 365 (366 for
274   leap years)[1]
275   R/W 0xE002 4034
276   MONTH 4 Month value in the range of 1 to 12 R/W 0xE002 4038
277   YEAR 12 Year value in the range of 0 to 4095 R/W 0xE002 403C
278 */
279   RTC_SEC = 00;
280   RTC_MIN = 22;
281   RTC_HOUR = 17;
282   RTC_DOM = 11;
283   RTC_DOW = 2-1;
284   RTC_DOY = 223;
285   RTC_MONTH = 8;
286   RTC_YEAR = 2009;
287 }
288
289 void startRTC(void)
290 {
291   // Initial RTC Function
292   RTC_CCR  = 0; // Reset All Bit Control
293   RTC_CCR |= 0x00000010; // CLKSRC = 1 = Used EXT 32.768 KHz
294   RTC_CCR |= 0x00000002; // Reset   Clock
295   RTC_CCR &= 0xFFFFFFFD; // Release Reset
296   RTC_CCR |= 0x00000001; // Start RTC Clock     
297 }
Note: See TracBrowser for help on using the browser.