2 FreeRTOS.org V4.3.1 - Copyright (C) 2003-2007 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 See http://www.FreeRTOS.org for documentation, latest information, license
\r
28 and contact details. Please ensure to read the configuration and relevant
\r
29 port sections of the online documentation.
\r
31 Also see http://www.SafeRTOS.com for an IEC 61508 compliant version along
\r
32 with commercial development and support options.
\r
33 ***************************************************************************
\r
37 * This file contains a demo created to execute on the Rowley Associates
\r
38 * LPC2138 CrossFire development board.
\r
40 * main() creates all the demo application tasks, then starts the scheduler.
\r
41 * The WEB documentation provides more details of the standard demo application
\r
44 * Main.c also creates a task called "Check". This only executes every few
\r
45 * seconds but has a high priority so is guaranteed to get processor time.
\r
46 * Its function is to check that all the other tasks are still operational.
\r
47 * Each standard demo task maintains a unique count that is incremented each
\r
48 * time the task successfully completes its function. Should any error occur
\r
49 * within such a task the count is permanently halted. The check task inspects
\r
50 * the count of each task to ensure it has changed since the last time the
\r
51 * check task executed. If all the count variables have changed all the tasks
\r
52 * are still executing error free, and the check task writes "PASS" to the
\r
53 * CrossStudio terminal IO window. Should any task contain an error at any time
\r
54 * the error is latched and "FAIL" written to the terminal IO window.
\r
56 * Finally, main() sets up an interrupt service routine and task to handle
\r
57 * pushes of the button that is built into the CrossFire board. When the button
\r
58 * is pushed the ISR wakes the button task - which generates a table of task
\r
59 * status information which is also displayed on the terminal IO window.
\r
61 * A print task is defined to ensure exclusive and consistent access to the
\r
62 * terminal IO. This is the only task that is allowed to access the terminal.
\r
63 * The check and button task therefore do not access the terminal directly but
\r
64 * instead pass a pointer to the message they wish to display to the print task.
\r
67 /* Standard includes. */
\r
68 #include <__cross_studio_io.h>
\r
70 /* Scheduler includes. */
\r
71 #include "FreeRTOS.h"
\r
76 /* Demo app includes. */
\r
79 #include "dynamic.h"
\r
80 #include "integer.h"
\r
82 #include "blocktim.h"
\r
84 /* Hardware configuration definitions. */
\r
85 #define mainBUS_CLK_FULL ( ( unsigned portCHAR ) 0x01 )
\r
86 #define mainLED_BIT 0x80000000
\r
87 #define mainP0_14__EINT_1 ( 2 << 28 )
\r
88 #define mainEINT_1_EDGE_SENSITIVE 2
\r
89 #define mainEINT_1_FALLING_EDGE_SENSITIVE 0
\r
90 #define mainEINT_1_CHANNEL 15
\r
91 #define mainEINT_1_VIC_CHANNEL_BIT ( 1 << mainEINT_1_CHANNEL )
\r
92 #define mainEINT_1_ENABLE_BIT ( 1 << 5 )
\r
94 /* Demo application definitions. */
\r
95 #define mainQUEUE_SIZE ( 3 )
\r
96 #define mainLED_DELAY ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
97 #define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )
\r
98 #define mainLIST_BUFFER_SIZE 2048
\r
100 /* Task priorities. */
\r
101 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
102 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
103 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
104 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
105 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
106 #define mainPRINT_TASK_PRIORITY ( tskIDLE_PRIORITY + 0 )
\r
108 /*-----------------------------------------------------------*/
\r
110 /* The semaphore used to wake the button task from within the external interrupt
\r
112 xSemaphoreHandle xButtonSemaphore;
\r
114 /* The queue that is used to send message to vPrintTask for display in the
\r
115 terminal output window. */
\r
116 xQueueHandle xPrintQueue;
\r
118 /*-----------------------------------------------------------*/
\r
121 * Simply flashes the on board LED every mainLED_DELAY milliseconds.
\r
123 static void vLEDTask( void *pvParameters );
\r
126 * Checks the status of all the demo tasks then prints a message to the
\r
127 * CrossStudio terminal IO windows. The message will be either PASS or FAIL
\r
128 * depending on the status of the demo applications tasks. A FAIL status will
\r
131 * Messages are not written directly to the terminal, but passed to vPrintTask
\r
134 static void vCheckTask( void *pvParameters );
\r
137 * Controls all terminal output. If a task wants to send a message to the
\r
138 * terminal IO it posts a pointer to the text to vPrintTask via a queue. This
\r
139 * ensures serial access to the terminal IO.
\r
141 static void vPrintTask( void *pvParameter );
\r
144 * Simply waits for an interrupt to be generated from the built in button, then
\r
145 * generates a table of tasks states that is then written by vPrintTask to the
\r
146 * terminal output window within CrossStudio.
\r
148 static void vButtonHandlerTask( void *pvParameters );
\r
150 /*-----------------------------------------------------------*/
\r
154 /* Setup the peripheral bus to be the same as the PLL output. */
\r
155 VPBDIV = mainBUS_CLK_FULL;
\r
157 /* Create the queue used to pass message to vPrintTask. */
\r
158 xPrintQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( portCHAR * ) );
\r
160 /* Create the semaphore used to wake vButtonHandlerTask(). */
\r
161 vSemaphoreCreateBinary( xButtonSemaphore );
\r
162 xSemaphoreTake( xButtonSemaphore, 0 );
\r
164 /* Start the standard demo tasks. */
\r
165 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
166 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
167 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
168 vStartDynamicPriorityTasks();
\r
169 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
170 vCreateBlockTimeTasks();
\r
172 /* Start the tasks defined within this file. */
\r
173 xTaskCreate( vLEDTask, "LED", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
\r
174 xTaskCreate( vCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
175 xTaskCreate( vPrintTask, "Print", configMINIMAL_STACK_SIZE, NULL, mainPRINT_TASK_PRIORITY, NULL );
\r
176 xTaskCreate( vButtonHandlerTask, "Button", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
178 /* Start the scheduler. */
\r
179 vTaskStartScheduler();
\r
181 /* The scheduler should now running, so we will only ever reach here if we
\r
182 ran out of heap space. */
\r
186 /*-----------------------------------------------------------*/
\r
188 static void vLEDTask( void *pvParameters )
\r
190 /* Configure IO. */
\r
191 IO0DIR |= mainLED_BIT;
\r
192 IO0SET = mainLED_BIT;
\r
196 /* Not very exiting - just delay... */
\r
197 vTaskDelay( mainLED_DELAY );
\r
199 /* ...set the IO ... */
\r
200 IO0CLR = mainLED_BIT;
\r
202 /* ...delay again... */
\r
203 vTaskDelay( mainLED_DELAY );
\r
205 /* ...then clear the IO. */
\r
206 IO0SET = mainLED_BIT;
\r
209 /*-----------------------------------------------------------*/
\r
211 static void vCheckTask( void *pvParameters )
\r
213 portBASE_TYPE xErrorOccurred = pdFALSE;
\r
214 portTickType xLastExecutionTime;
\r
215 const portCHAR * const pcPassMessage = "PASS\n";
\r
216 const portCHAR * const pcFailMessage = "FAIL\n";
\r
218 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
219 works correctly. */
\r
220 xLastExecutionTime = xTaskGetTickCount();
\r
224 /* Perform this check every mainCHECK_DELAY milliseconds. */
\r
225 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_DELAY );
\r
227 /* Has an error been found in any task? */
\r
229 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
231 xErrorOccurred = pdTRUE;
\r
234 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
236 xErrorOccurred = pdTRUE;
\r
239 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
241 xErrorOccurred = pdTRUE;
\r
244 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
246 xErrorOccurred = pdTRUE;
\r
249 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
251 xErrorOccurred = pdTRUE;
\r
254 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
256 xErrorOccurred = pdTRUE;
\r
259 /* Send either a pass or fail message. If an error is found it is
\r
260 never cleared again. */
\r
261 if( xErrorOccurred == pdTRUE )
\r
263 xQueueSend( xPrintQueue, &pcFailMessage, portMAX_DELAY );
\r
267 xQueueSend( xPrintQueue, &pcPassMessage, portMAX_DELAY );
\r
271 /*-----------------------------------------------------------*/
\r
273 static void vPrintTask( void *pvParameters )
\r
275 portCHAR *pcMessage;
\r
279 /* Wait for a message to arrive. */
\r
280 while( xQueueReceive( xPrintQueue, &pcMessage, portMAX_DELAY ) != pdPASS );
\r
282 /* Write the message to the terminal IO. */
\r
283 debug_printf( "%s", pcMessage );
\r
286 /*-----------------------------------------------------------*/
\r
288 static void vButtonHandlerTask( void *pvParameters )
\r
290 static portCHAR cListBuffer[ mainLIST_BUFFER_SIZE ];
\r
291 const portCHAR *pcList = &( cListBuffer[ 0 ] );
\r
292 const portCHAR * const pcHeader = "\nTask State Priority Stack #\n************************************************";
\r
293 extern void (vButtonISR) ( void );
\r
295 /* Configure the interrupt. */
\r
296 portENTER_CRITICAL();
\r
298 /* Configure P0.14 to generate interrupts. */
\r
299 PINSEL0 |= mainP0_14__EINT_1;
\r
300 EXTMODE = mainEINT_1_EDGE_SENSITIVE;
\r
301 EXTPOLAR = mainEINT_1_FALLING_EDGE_SENSITIVE;
\r
303 /* Setup the VIC for EINT 1. */
\r
304 VICIntSelect &= ~mainEINT_1_VIC_CHANNEL_BIT;
\r
305 VICIntEnable |= mainEINT_1_VIC_CHANNEL_BIT;
\r
306 VICVectAddr1 = ( portLONG ) vButtonISR;
\r
307 VICVectCntl1 = mainEINT_1_ENABLE_BIT | mainEINT_1_CHANNEL;
\r
309 portEXIT_CRITICAL();
\r
313 /* Wait for an interrupt. */
\r
314 while( xSemaphoreTake( xButtonSemaphore, portMAX_DELAY ) != pdPASS );
\r
316 /* Send the column headers to the print task for display. */
\r
317 xQueueSend( xPrintQueue, &pcHeader, portMAX_DELAY );
\r
319 /* Create the list of task states. */
\r
320 vTaskList( cListBuffer );
\r
322 /* Send the task status information to the print task for display. */
\r
323 xQueueSend( xPrintQueue, &pcList, portMAX_DELAY );
\r
326 /*-----------------------------------------------------------*/
\r