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

Revision 22, 8.5 kB (checked in by phil, 15 years ago)

deleted some test files,
gas meter values (unsigned long long) now updated.
added epoch time handling

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
59 #include "portlcd.h"
60 #include "flash.h"
61
62
63 /* Demo application definitions. */
64 #define mainQUEUE_SIZE                                          ( 3 )
65 #define mainCHECK_DELAY                                         ( ( portTickType ) 5000 / portTICK_RATE_MS )
66 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 2 )
67
68 /* Task priorities. */
69 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )
70 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )
71 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )
72
73
74
75 void setRTC(void);
76 void startRTC(void);
77
78 /*
79  * Checks the status of all the demo tasks then prints a message to the
80  * CrossStudio terminal IO windows.  The message will be either PASS or FAIL
81  * depending on the status of the demo applications tasks.  A FAIL status will
82  * be latched.
83  *
84  * Messages are not written directly to the terminal, but passed to vPrintTask
85  * via a queue.
86  */
87 static void vCheckTask( void *pvParameters );
88
89 /*
90  * The task that handles the uIP stack.  All TCP/IP processing is performed in
91  * this task.
92  */
93 extern void vuIP_Task( void *pvParameters );
94
95 /*
96  * The task that handles the electricity meter handling/calculations.
97  */
98 extern void vMeters_Task( void *pvParameters );
99
100 /*
101  * The LCD is written two by more than one task so is controlled by a
102  * 'gatekeeper' task.  This is the only task that is actually permitted to
103  * access the LCD directly.  Other tasks wanting to display a message send
104  * the message to the gatekeeper.
105  */
106 static void vLCDTask( void *pvParameters );
107
108 /* The queue used to send messages to the LCD task. */
109 xQueueHandle xLCDQueue;
110
111 /*-----------------------------------------------------------*/
112
113 int main (void)
114 {
115   startRTC(); /* start the RTC */
116
117   /* Setup the led's on the MCB2300 board */
118   vParTestInitialise();
119
120   /* Create the queue used by the LCD task.  Messages for display on the LCD
121   are received via this queue. */
122   xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
123
124   /* Create the lwIP task.  This uses the lwIP RTOS abstraction layer.*/
125   xTaskCreate( vuIP_Task, ( signed portCHAR * ) "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
126
127 //  vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
128   vStartMetersTask( mainFLASH_PRIORITY );
129         /* Start the standard demo tasks. */
130 //  vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
131 //  vCreateBlockTimeTasks();
132   vStartLEDFlashTasks( mainFLASH_PRIORITY );
133 //  vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
134 //  vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
135 //  vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );
136
137         /* Start the tasks defined within this file/specific to this demo. */
138  //   xTaskCreate( vCheckTask, ( signed portCHAR * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
139     xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
140
141         /* The suicide tasks must be created last as they need to know how many
142         tasks were running prior to their creation in order to ascertain whether
143         or not the correct/expected number of tasks are running at any given time. */
144  //   vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
145
146
147         /* Start the scheduler. */
148         vTaskStartScheduler();
149
150     /* Will only get here if there was insufficient memory to create the idle
151     task. */
152         return 0;
153 }
154 /*-----------------------------------------------------------*/
155
156 static void vCheckTask( void *pvParameters )
157 {
158 portBASE_TYPE xErrorOccurred = pdFALSE;
159 portTickType xLastExecutionTime;
160 unsigned portBASE_TYPE uxColumn = 0;
161 xLCDMessage xMessage;
162
163         xLastExecutionTime = xTaskGetTickCount();
164
165         xMessage.xColumn = 0;
166         xMessage.pcMessage = "PASS";
167
168     for( ;; )
169         {
170                 /* Perform this check every mainCHECK_DELAY milliseconds. */
171                 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
172
173                 /* Has an error been found in any task? */
174
175
176
177         LCD_cls();
178         xMessage.xColumn++;
179         LCD_gotoxy( ( uxColumn & 0x07 ) + 1, ( uxColumn & 0x01 ) + 1 );
180
181         if( xErrorOccurred == pdTRUE )
182         {
183             xMessage.pcMessage = "FAIL";
184         }
185
186                 /* Send the message to the LCD gatekeeper for display. */
187                 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
188         }
189 }
190 /*-----------------------------------------------------------*/
191
192 void vLCDTask( void *pvParameters )
193 {
194 xLCDMessage xMessage;
195
196         /* Initialise the LCD and display a startup message. */
197         LCD_init();
198         LCD_cur_off();
199     LCD_cls();   
200     LCD_gotoxy( 1, 1 );
201     LCD_puts( ( signed portCHAR * ) "www.FreeRTOS.org" );
202
203         for( ;; )
204         {
205                 /* Wait for a message to arrive that requires displaying. */
206                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
207                
208                 /* Display the message.  Print each message to a different position. */
209                 LCD_cls();
210                 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
211                 LCD_puts( xMessage.pcMessage );
212         }
213
214 }
215 /*-----------------------------------------------------------*/
216
217 /* Keep the compiler quiet. */
218 #include <stdio.h>
219 int __putchar( int c )
220 {
221     return EOF;
222 }
223
224 void setRTC(void)
225 {
226 /*
227   This function needs to be called when the RTC battery was replaces
228
229   SEC 6 Seconds value in the range of 0 to 59 R/W 0xE002 4020
230   MIN 6 Minutes value in the range of 0 to 59 R/W 0xE002 4024
231   HOUR 5 Hours value in the range of 0 to 23 R/W 0xE002 4028
232   DOM 5 Day of month value in the range of 1 to 28, 29, 30,
233   or 31 (depending on the month and whether it is a
234   leap year).[1]
235   R/W 0xE002 402C
236   DOW 3 Day of week value in the range of 0 to 6[1] R/W 0xE002 4030
237   DOY 9 Day of year value in the range of 1 to 365 (366 for
238   leap years)[1]
239   R/W 0xE002 4034
240   MONTH 4 Month value in the range of 1 to 12 R/W 0xE002 4038
241   YEAR 12 Year value in the range of 0 to 4095 R/W 0xE002 403C
242 */
243   RTC_SEC = 00;
244   RTC_MIN = 22;
245   RTC_HOUR = 17;
246   RTC_DOM = 11;
247   RTC_DOW = 2-1;
248   RTC_DOY = 223;
249   RTC_MONTH = 8;
250   RTC_YEAR = 2009;
251 }
252
253 void startRTC(void)
254 {
255   // Initial RTC Function
256   RTC_CCR  = 0; // Reset All Bit Control
257   RTC_CCR |= 0x00000010; // CLKSRC = 1 = Used EXT 32.768 KHz
258   RTC_CCR |= 0x00000002; // Reset   Clock
259   RTC_CCR &= 0xFFFFFFFD; // Release Reset
260   RTC_CCR |= 0x00000001; // Start RTC Clock     
261 }
Note: See TracBrowser for help on using the browser.