]> git.sur5r.net Git - freertos/blob - Demo/MSP430X_MSP430F5438_CCS4/Demo_Source/main.c
Added BSP generation files to MicroBlaze directory.
[freertos] / Demo / MSP430X_MSP430F5438_CCS4 / Demo_Source / main.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\r
11      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
12      *    ensuring you get running as quickly as possible and with an        *\r
13      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
14      *    the FreeRTOS project to continue with its mission of providing     *\r
15      *    professional grade, cross platform, de facto standard solutions    *\r
16      *    for microcontrollers - completely free of charge!                  *\r
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     >>>NOTE<<< The modification to the GPL is included to allow you to\r
31     distribute a combined work that includes FreeRTOS without being obliged to\r
32     provide the source code for proprietary components outside of the FreeRTOS\r
33     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
34     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
35     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /*\r
55  * The documentation page for this demo available on http://www.FreeRTOS.org\r
56  * documents the hardware configuration required to run this demo.  It also\r
57  * provides more information on the expected demo application behaviour.\r
58  *\r
59  * main() creates all the demo application tasks, then starts the scheduler.\r
60  * A lot of the created tasks are from the pool of "standard demo" tasks.  The\r
61  * web documentation provides more details of the standard demo tasks, which\r
62  * provide no particular functionality but do provide good examples of how to\r
63  * use the FreeRTOS API.\r
64  *\r
65  * In addition to the standard demo tasks, the following tasks, interrupts tests\r
66  * and timers are defined and/or created within this file:\r
67  *\r
68  * "LCD" task - The LCD task is a 'gatekeeper' task.  It is the only task that\r
69  * is permitted to access the LCD and therefore ensures access to the LCD is\r
70  * always serialised and there are no mutual exclusion issues.  When a task or\r
71  * an interrupt wants to write to the LCD, it does not access the LCD directly\r
72  * but instead sends the message to the LCD task.  The LCD task then performs\r
73  * the actual LCD output.  This mechanism also allows interrupts to, in effect,\r
74  * write to the LCD by sending messages to the LCD task.\r
75  *\r
76  * The LCD task is also a demonstration of a 'controller' task design pattern.\r
77  * Some tasks do not actually send a string to the LCD task directly, but\r
78  * instead send a command that is interpreted by the LCD task.  In a normal\r
79  * application these commands can be control values or set points, in this\r
80  * simple example the commands just result in messages being displayed on the\r
81  * LCD.\r
82  *\r
83  * "Button Poll" task - This task polls the state of the 'up' key on the\r
84  * joystick input device.  It uses the vTaskDelay() API function to control\r
85  * the poll rate to ensure debouncing is not necessary and that the task does\r
86  * not use all the available CPU processing time.\r
87  *\r
88  * Button Interrupt - The select button on the joystick input device is \r
89  * configured to generate an external interrupt.  The handler for this interrupt \r
90  * sends a message to LCD task, which then prints out a string to say the \r
91  * joystick select button was pressed.\r
92  *\r
93  * Idle Hook - The idle hook is a function that is called on each iteration of\r
94  * the idle task.  In this case it is used to place the processor into a low\r
95  * power mode.  Note however that this application is implemented using standard\r
96  * components, and is therefore not optimised for low power operation.  Lower\r
97  * power consumption would be achieved by converting polling tasks into event\r
98  * driven tasks, and slowing the tick interrupt frequency, etc.\r
99  *\r
100  * "Check" callback function - Called each time the 'check' timer expires.  The\r
101  * check timer executes every five seconds.  Its main function is to check that \r
102  * all the standard demo tasks are still operational.  Each time it executes it \r
103  * sends a status code to the LCD task.  The LCD task interprets the code and \r
104  * displays an appropriate message - which will be PASS if no tasks have \r
105  * reported any errors, or a message stating which task has reported an error.\r
106  *\r
107  * "Reg test" tasks - These fill the registers with known values, then check\r
108  * that each register still contains its expected value.  Each task uses\r
109  * different values.  The tasks run with very low priority so get preempted\r
110  * very frequently.  A check variable is incremented on each iteration of the\r
111  * test loop.  A register containing an unexpected value is indicative of an\r
112  * error in the context switching mechanism and will result in a branch to a\r
113  * null loop - which in turn will prevent the check variable from incrementing\r
114  * any further and allow the check timer callback (described a above) to \r
115  * determine that an error has occurred.  The nature of the reg test tasks \r
116  * necessitates that they are written in assembly code.\r
117  *\r
118  * Tick hook function - called inside the RTOS tick function, this simple \r
119  * example does nothing but toggle an LED.\r
120  *\r
121  * *NOTE 1* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
122  * the application set up a timer to generate the tick interrupt.  In this\r
123  * example a timer A0 is used for this purpose.\r
124  *\r
125 */\r
126 \r
127 /* Standard includes. */\r
128 #include <stdio.h>\r
129 \r
130 /* FreeRTOS includes. */\r
131 #include "FreeRTOS.h"\r
132 #include "task.h"\r
133 #include "timers.h"\r
134 #include "queue.h"\r
135 \r
136 /* Hardware includes. */\r
137 #include "msp430.h"\r
138 #include "hal_MSP-EXP430F5438.h"\r
139 \r
140 /* Standard demo includes. */\r
141 #include "ParTest.h"\r
142 #include "dynamic.h"\r
143 #include "comtest2.h"\r
144 #include "GenQTest.h"\r
145 #include "TimerDemo.h"\r
146 #include "countsem.h"\r
147 \r
148 /* Codes sent within messages to the LCD task so the LCD task can interpret\r
149 exactly what the message it just received was.  These are sent in the\r
150 cMessageID member of the message structure (defined below). */\r
151 #define mainMESSAGE_BUTTON_UP                   ( 1 )\r
152 #define mainMESSAGE_BUTTON_SEL                  ( 2 )\r
153 #define mainMESSAGE_STATUS                              ( 3 )\r
154 \r
155 /* When the cMessageID member of the message sent to the LCD task is\r
156 mainMESSAGE_STATUS then these definitions are sent in the ulMessageValue member\r
157 of the same message and indicate what the status actually is. */\r
158 #define mainERROR_DYNAMIC_TASKS                 ( pdPASS + 1 )\r
159 #define mainERROR_COM_TEST                              ( pdPASS + 2 )\r
160 #define mainERROR_GEN_QUEUE_TEST                ( pdPASS + 3 )\r
161 #define mainERROR_REG_TEST                              ( pdPASS + 4 )\r
162 #define mainERROR_TIMER_TEST                    ( pdPASS + 5 )\r
163 #define mainERROR_COUNT_SEM_TEST                ( pdPASS + 6 )\r
164 \r
165 /* The length of the queue (the number of items the queue can hold) that is used\r
166 to send messages from tasks and interrupts the the LCD task. */\r
167 #define mainQUEUE_LENGTH                                ( 5 )\r
168 \r
169 /* Priorities used by the test and demo tasks. */\r
170 #define mainLCD_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )\r
171 #define mainCOM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 2 )\r
172 #define mainGENERIC_QUEUE_TEST_PRIORITY ( tskIDLE_PRIORITY )\r
173 \r
174 /* The LED used by the comtest tasks. See the comtest.c file for more\r
175 information.  */\r
176 #define mainCOM_TEST_LED                                ( 1 )\r
177 \r
178 /* The baud rate used by the comtest tasks. */\r
179 #define mainCOM_TEST_BAUD_RATE                  ( 38400 )\r
180 \r
181 /* The maximum number of lines of text that can be displayed on the LCD. */\r
182 #define mainMAX_LCD_LINES                               ( 8 )\r
183 \r
184 /* Just used to ensure parameters are passed into tasks correctly. */\r
185 #define mainTASK_PARAMETER_CHECK_VALUE  ( ( void * ) 0xDEAD )\r
186 \r
187 /* The base period used by the timer test tasks. */\r
188 #define mainTIMER_TEST_PERIOD                   ( 50 )\r
189 \r
190 /* The frequency at which the check timer (described in the comments at the top\r
191 of this file) will call its callback function. */\r
192 #define mainCHECK_TIMER_PERIOD                  ( 5000UL / ( unsigned long ) portTICK_RATE_MS )\r
193 \r
194 /* Misc. */\r
195 #define mainDONT_BLOCK                                  ( 0 )\r
196 /*-----------------------------------------------------------*/\r
197 \r
198 /*\r
199  * The reg test tasks as described at the top of this file.\r
200  */\r
201 extern void vRegTest1Task( void *pvParameters );\r
202 extern void vRegTest2Task( void *pvParameters );\r
203 \r
204 /*\r
205  * Configures clocks, LCD, port pints, etc. necessary to execute this demo.\r
206  */\r
207 static void prvSetupHardware( void );\r
208 \r
209 /*\r
210  * Definition of the LCD/controller task described in the comments at the top\r
211  * of this file.\r
212  */\r
213 static void prvLCDTask( void *pvParameters );\r
214 \r
215 /*\r
216  * Definition of the button poll task described in the comments at the top of\r
217  * this file.\r
218  */\r
219 static void prvButtonPollTask( void *pvParameters );\r
220 \r
221 /*\r
222  * Converts a status message value into an appropriate string for display on\r
223  * the LCD.  The string is written to pcBuffer.\r
224  */\r
225 static void prvGenerateStatusMessage( char *pcBuffer, unsigned long ulStatusValue );\r
226 \r
227 /*\r
228  * Defines the 'check' functionality as described at the top of this file.  This\r
229  * function is the callback function for the 'check' timer. */\r
230 static void vCheckTimerCallback( xTimerHandle xTimer );\r
231 \r
232 /*-----------------------------------------------------------*/\r
233 \r
234 /* Variables that are incremented on each iteration of the reg test tasks -\r
235 provided the tasks have not reported any errors.  The check task inspects these\r
236 variables to ensure they are still incrementing as expected.  If a variable\r
237 stops incrementing then it is likely that its associate task has stalled. */\r
238 volatile unsigned short usRegTest1Counter = 0, usRegTest2Counter = 0;\r
239 \r
240 /* The handle of the queue used to send messages from tasks and interrupts to\r
241 the LCD task. */\r
242 static xQueueHandle xLCDQueue = NULL;\r
243 \r
244 /* The 'check' timer, as described at the top of this file. */\r
245 static xTimerHandle xCheckTimer = NULL;\r
246 \r
247 /* The definition of each message sent from tasks and interrupts to the LCD\r
248 task. */\r
249 typedef struct\r
250 {\r
251         char cMessageID;                                /* << States what the message is. */\r
252         unsigned long ulMessageValue;   /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID). */\r
253 } xQueueMessage;\r
254 \r
255 /*-----------------------------------------------------------*/\r
256 \r
257 void main( void )\r
258 {\r
259         /* Configure the peripherals used by this demo application.  This includes\r
260         configuring the joystick input select button to generate interrupts. */\r
261         prvSetupHardware();\r
262 \r
263         /* Create the queue used by tasks and interrupts to send strings to the LCD\r
264         task. */\r
265         xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );\r
266 \r
267         /* If the queue could not be created then don't create any tasks that might\r
268         attempt to use the queue. */\r
269         if( xLCDQueue != NULL )\r
270         {\r
271                 /* Create the standard demo tasks. */\r
272                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
273                 vStartDynamicPriorityTasks();\r
274                 vStartGenericQueueTasks( mainGENERIC_QUEUE_TEST_PRIORITY );\r
275                 vStartCountingSemaphoreTasks();\r
276                 \r
277                 /* Note that creating the timer test/demo tasks will fill the timer\r
278                 command queue.  This is intentional, and forms part of the test the tasks\r
279                 perform.  It does mean however that, after this function is called, no\r
280                 more timer commands can be sent until after the scheduler has been\r
281                 started (at which point the timer daemon will drained the timer command\r
282                 queue, freeing up space for more commands to be received). */\r
283                 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
284                 \r
285                 /* Create the LCD, button poll and register test tasks, as described at\r
286                 the top of this file. */\r
287                 xTaskCreate( prvLCDTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE * 2, mainTASK_PARAMETER_CHECK_VALUE, mainLCD_TASK_PRIORITY, NULL );\r
288                 xTaskCreate( prvButtonPollTask, ( signed char * ) "BPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
289                 xTaskCreate( vRegTest1Task, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
290                 xTaskCreate( vRegTest2Task, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
291 \r
292                 /* Create the 'check' timer - the timer that periodically calls the\r
293                 check function as described at the top of this file.  Note that, for\r
294                 the reasons stated in the comments above the call to \r
295                 vStartTimerDemoTask(), that the check timer is not actually started \r
296                 until after the scheduler has been started. */\r
297                 xCheckTimer = xTimerCreate( ( const signed char * ) "Check timer", mainCHECK_TIMER_PERIOD, pdTRUE, ( void * ) 0, vCheckTimerCallback ); \r
298 \r
299                 /* Start the scheduler. */\r
300                 vTaskStartScheduler();\r
301         }\r
302 \r
303         /* If all is well then this line will never be reached.  If it is reached\r
304         then it is likely that there was insufficient (FreeRTOS) heap memory space\r
305         to create the idle task.  This may have been trapped by the malloc() failed\r
306         hook function, if one is configured. */ \r
307         for( ;; );\r
308 }\r
309 /*-----------------------------------------------------------*/\r
310 \r
311 static void prvLCDTask( void *pvParameters )\r
312 {\r
313 xQueueMessage xReceivedMessage;\r
314 \r
315 /* Buffer into which strings are formatted and placed ready for display on the\r
316 LCD.  Note this is a static variable to prevent it being allocated on the task\r
317 stack, which is too small to hold such a variable.  The stack size is configured\r
318 when the task is created. */\r
319 static char cBuffer[ 50 ];\r
320 unsigned char ucLine = 1;\r
321 \r
322         /* Now the scheduler has been started (it must have been for this task to\r
323         be running), start the check timer too.  The call to xTimerStart() will\r
324         block until the command has been accepted. */\r
325         if( xCheckTimer != NULL )\r
326         {\r
327                 xTimerStart( xCheckTimer, portMAX_DELAY );\r
328         }\r
329 \r
330         /* This is the only function that is permitted to access the LCD.\r
331         \r
332         First print out the number of bytes that remain in the FreeRTOS heap.  This\r
333         is done after a short delay to ensure all the demo tasks have created all\r
334         the objects they are going to use.  */\r
335         vTaskDelay( mainTIMER_TEST_PERIOD * 10 );\r
336         sprintf( cBuffer, "%d heap free", ( int ) xPortGetFreeHeapSize() );\r
337         halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );\r
338         ucLine++;\r
339         \r
340         /* Just as a test of the port, and for no functional reason, check the task\r
341         parameter contains its expected value. */\r
342         if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )\r
343         {\r
344                 halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT );\r
345                 ucLine++;               \r
346         }\r
347 \r
348         for( ;; )\r
349         {\r
350                 /* Wait for a message to be received.  Using portMAX_DELAY as the block\r
351                 time will result in an indefinite wait provided INCLUDE_vTaskSuspend is\r
352                 set to 1 in FreeRTOSConfig.h, therefore there is no need to check the\r
353                 function return value and the function will only return when a value\r
354                 has been received. */\r
355                 xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );\r
356 \r
357                 /* Clear the LCD if no room remains for any more text output. */\r
358                 if( ucLine > mainMAX_LCD_LINES )\r
359                 {\r
360                         halLcdClearScreen();\r
361                         ucLine = 0;\r
362                 }\r
363                 \r
364                 /* What is this message?  What does it contain? */\r
365                 switch( xReceivedMessage.cMessageID )\r
366                 {\r
367                         case mainMESSAGE_BUTTON_UP              :       /* The button poll task has just\r
368                                                                                                 informed this task that the up\r
369                                                                                                 button on the joystick input has\r
370                                                                                                 been pressed or released. */\r
371                                                                                                 sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );\r
372                                                                                                 break;\r
373 \r
374                         case mainMESSAGE_BUTTON_SEL             :       /* The select button interrupt\r
375                                                                                                 just informed this task that the\r
376                                                                                                 select button has been pressed.\r
377                                                                                                 In this case the pointer to the \r
378                                                                                                 string to print is sent directly \r
379                                                                                                 in the ulMessageValue member of \r
380                                                                                                 the     message.  This just \r
381                                                                                                 demonstrates a different \r
382                                                                                                 communication technique. */\r
383                                                                                                 sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );\r
384                                                                                                 break;\r
385                                                                                                 \r
386                         case mainMESSAGE_STATUS                 :       /* The tick interrupt hook\r
387                                                                                                 function has just informed this\r
388                                                                                                 task of the system status.\r
389                                                                                                 Generate a string in accordance\r
390                                                                                                 with the status value. */\r
391                                                                                                 prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );\r
392                                                                                                 break;\r
393                                                                                                 \r
394                         default                                                 :       sprintf( cBuffer, "Unknown message" );\r
395                                                                                                 break;\r
396                 }\r
397                 \r
398                 /* Output the message that was placed into the cBuffer array within the\r
399                 switch statement above, then move onto the next line ready for the next\r
400                 message to arrive on the queue. */\r
401                 halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );\r
402                 ucLine++;\r
403         }\r
404 }\r
405 /*-----------------------------------------------------------*/\r
406 \r
407 static void prvGenerateStatusMessage( char *pcBuffer, unsigned long ulStatusValue )\r
408 {\r
409         /* Just a utility function to convert a status value into a meaningful\r
410         string for output onto the LCD. */\r
411         switch( ulStatusValue )\r
412         {\r
413                 case pdPASS                                             :       sprintf( pcBuffer, "Status = PASS" );\r
414                                                                                         break;\r
415                 case mainERROR_DYNAMIC_TASKS    :       sprintf( pcBuffer, "Err: Dynamic tsks" );\r
416                                                                                         break;\r
417                 case mainERROR_COM_TEST                 :       sprintf( pcBuffer, "Err: COM test" );\r
418                                                                                         break;\r
419                 case mainERROR_GEN_QUEUE_TEST   :       sprintf( pcBuffer, "Error: Gen Q test" );\r
420                                                                                         break;\r
421                 case mainERROR_REG_TEST                 :       sprintf( pcBuffer, "Error: Reg test" );\r
422                                                                                         break;\r
423                 case mainERROR_TIMER_TEST               :       sprintf( pcBuffer, "Error: Tmr test" );\r
424                                                                                         break;\r
425                 case mainERROR_COUNT_SEM_TEST   :       sprintf( pcBuffer, "Error: Count sem" );\r
426                                                                                         break;\r
427                 default                                                 :       sprintf( pcBuffer, "Unknown status" );\r
428                                                                                         break;\r
429         }\r
430 }\r
431 /*-----------------------------------------------------------*/\r
432 \r
433 static void prvButtonPollTask( void *pvParameters )\r
434 {\r
435 unsigned char ucLastState = pdFALSE, ucState;\r
436 xQueueMessage xMessage;\r
437 \r
438         /* This tasks performs the button polling functionality as described at the\r
439         top of this file. */\r
440         for( ;; )\r
441         {\r
442                 /* Check the button state. */\r
443                 ucState = ( halButtonsPressed() & BUTTON_UP );\r
444                 \r
445                 if( ucState != 0 )\r
446                 {\r
447                         /* The button was pressed. */\r
448                         ucState = pdTRUE;\r
449                 }\r
450                 \r
451                 if( ucState != ucLastState )\r
452                 {\r
453                         /* The state has changed, send a message to the LCD task. */\r
454                         xMessage.cMessageID = mainMESSAGE_BUTTON_UP;\r
455                         xMessage.ulMessageValue = ( unsigned long ) ucState;\r
456                         ucLastState = ucState;\r
457                         xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );\r
458                 }\r
459                 \r
460                 /* Block for 10 milliseconds so this task does not utilise all the CPU\r
461                 time and debouncing of the button is not necessary. */\r
462                 vTaskDelay( 10 / portTICK_RATE_MS );\r
463         }\r
464 }\r
465 /*-----------------------------------------------------------*/\r
466 \r
467 static void vCheckTimerCallback( xTimerHandle xTimer )\r
468 {\r
469 static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;\r
470 \r
471 /* Define the status message that is sent to the LCD task.  By default the\r
472 status is PASS. */\r
473 static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };\r
474 \r
475         /* This is the callback function used by the 'check' timer, as described\r
476         at the top of this file. */\r
477 \r
478         /* The parameter is not used. */\r
479         ( void ) xTimer;\r
480         \r
481         /* See if the standard demo tasks are executing as expected, changing\r
482         the message that is sent to the LCD task from PASS to an error code if\r
483         any tasks set reports an error. */\r
484         if( xAreComTestTasksStillRunning() != pdPASS )\r
485         {\r
486                 xStatusMessage.ulMessageValue = mainERROR_COM_TEST;\r
487         }\r
488 \r
489         if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
490         {\r
491                 xStatusMessage.ulMessageValue = mainERROR_DYNAMIC_TASKS;\r
492         }\r
493         \r
494         if( xAreGenericQueueTasksStillRunning() != pdPASS )\r
495         {\r
496                 xStatusMessage.ulMessageValue = mainERROR_GEN_QUEUE_TEST;\r
497         }                       \r
498         \r
499         if( xAreCountingSemaphoreTasksStillRunning() != pdPASS )\r
500         {\r
501                 xStatusMessage.ulMessageValue = mainERROR_COUNT_SEM_TEST;\r
502         }\r
503         \r
504         if( xAreTimerDemoTasksStillRunning( ( portTickType ) mainCHECK_TIMER_PERIOD ) != pdPASS )\r
505         {\r
506                 xStatusMessage.ulMessageValue = mainERROR_TIMER_TEST;\r
507         }\r
508 \r
509         /* Check the reg test tasks are still cycling.  They will stop\r
510         incrementing their loop counters if they encounter an error. */\r
511         if( usRegTest1Counter == usLastRegTest1Counter )\r
512         {\r
513                 xStatusMessage.ulMessageValue = mainERROR_REG_TEST;\r
514         }\r
515 \r
516         if( usRegTest2Counter == usLastRegTest2Counter )\r
517         {\r
518                 xStatusMessage.ulMessageValue = mainERROR_REG_TEST;\r
519         }\r
520 \r
521         usLastRegTest1Counter = usRegTest1Counter;\r
522         usLastRegTest2Counter = usRegTest2Counter;\r
523         \r
524         /* This is called from a timer callback so must not block! */\r
525         xQueueSendToBack( xLCDQueue, &xStatusMessage, mainDONT_BLOCK );\r
526 }\r
527 /*-----------------------------------------------------------*/\r
528 \r
529 static void prvSetupHardware( void )\r
530 {\r
531 /* Convert a Hz value to a KHz value, as required by the Init_FLL_Settle()\r
532 function. */\r
533 unsigned long ulCPU_Clock_KHz = ( configCPU_CLOCK_HZ / 1000UL );\r
534 \r
535         taskDISABLE_INTERRUPTS();\r
536         \r
537         /* Disable the watchdog. */\r
538         WDTCTL = WDTPW + WDTHOLD;\r
539   \r
540         halBoardInit();\r
541 \r
542         LFXT_Start( XT1DRIVE_0 );\r
543         Init_FLL_Settle( ( unsigned short ) ulCPU_Clock_KHz, 488 );\r
544 \r
545         halButtonsInit( BUTTON_ALL );\r
546         halButtonsInterruptEnable( BUTTON_SELECT );\r
547 \r
548         /* Initialise the LCD, but note that the backlight is not used as the\r
549         library function uses timer A0 to modulate the backlight, and this file\r
550         defines vApplicationSetupTimerInterrupt() to also use timer A0 to generate\r
551         the tick interrupt.  If the backlight is required, then change either the\r
552         halLCD library or vApplicationSetupTimerInterrupt() to use a different\r
553         timer.  Timer A1 is used for the run time stats time base6. */\r
554         halLcdInit();\r
555         halLcdSetContrast( 100 );\r
556         halLcdClearScreen();\r
557         \r
558         halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );\r
559 }\r
560 /*-----------------------------------------------------------*/\r
561 \r
562 \r
563 void vApplicationTickHook( void )\r
564 {\r
565 static unsigned long ulCounter = 0;\r
566 \r
567         /* Is it time to toggle the LED again? */\r
568         ulCounter++;\r
569 \r
570         /* Just periodically toggle an LED to show that the tick interrupt is\r
571         running.  Note that this access LED_PORT_OUT in a non-atomic way, so tasks\r
572         that access the same port must do so from a critical section. */\r
573         if( ( ulCounter & 0xff ) == 0 )\r
574         {\r
575                 if( ( LED_PORT_OUT & LED_1 ) == 0 )\r
576                 {\r
577                         LED_PORT_OUT |= LED_1;\r
578                 }\r
579                 else\r
580                 {\r
581                         LED_PORT_OUT &= ~LED_1;\r
582                 }\r
583         }\r
584 }\r
585 /*-----------------------------------------------------------*/\r
586 \r
587 #pragma vector=PORT2_VECTOR\r
588 interrupt void prvSelectButtonInterrupt( void )\r
589 {\r
590 /* Define the message sent to the LCD task from this interrupt. */\r
591 static const xQueueMessage xMessage = { mainMESSAGE_BUTTON_SEL, ( unsigned long ) "Select Interrupt" };\r
592 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
593 \r
594         /* This is the interrupt handler for the joystick select button input.\r
595         The button has been pushed, write a message to the LCD via the LCD task. */\r
596         xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );\r
597 \r
598         P2IFG = 0;\r
599         \r
600         /* If writing to xLCDQueue caused a task to unblock, and the unblocked task\r
601         has a priority equal to or above the task that this interrupt interrupted,\r
602         then lHigherPriorityTaskWoken will have been set to pdTRUE internally within\r
603         xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this\r
604         interrupt returns directly to the higher priority unblocked task. */\r
605         portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
606 }\r
607 /*-----------------------------------------------------------*/\r
608 \r
609 /* The MSP430X port uses this callback function to configure its tick interrupt.\r
610 This allows the application to choose the tick interrupt source.\r
611 configTICK_VECTOR must also be set in FreeRTOSConfig.h to the correct\r
612 interrupt vector for the chosen tick interrupt source.  This implementation of\r
613 vApplicationSetupTimerInterrupt() generates the tick from timer A0, so in this\r
614 case configTICK_VECTOR is set to TIMER0_A0_VECTOR. */\r
615 void vApplicationSetupTimerInterrupt( void )\r
616 {\r
617 const unsigned short usACLK_Frequency_Hz = 32768;\r
618 \r
619         /* Ensure the timer is stopped. */\r
620         TA0CTL = 0;\r
621 \r
622         /* Run the timer from the ACLK. */\r
623         TA0CTL = TASSEL_1;\r
624 \r
625         /* Clear everything to start with. */\r
626         TA0CTL |= TACLR;\r
627 \r
628         /* Set the compare match value according to the tick rate we want. */\r
629         TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;\r
630 \r
631         /* Enable the interrupts. */\r
632         TA0CCTL0 = CCIE;\r
633 \r
634         /* Start up clean. */\r
635         TA0CTL |= TACLR;\r
636 \r
637         /* Up mode. */\r
638         TA0CTL |= MC_1;\r
639 }\r
640 /*-----------------------------------------------------------*/\r
641 \r
642 void vApplicationIdleHook( void )\r
643 {\r
644         /* Called on each iteration of the idle task.  In this case the idle task\r
645         just enters a low(ish) power mode. */\r
646         __bis_SR_register( LPM1_bits + GIE );\r
647 }\r
648 /*-----------------------------------------------------------*/\r
649 \r
650 void vApplicationMallocFailedHook( void )\r
651 {\r
652         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
653         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
654         internally by FreeRTOS API functions that create tasks, queues or\r
655         semaphores. */\r
656         taskDISABLE_INTERRUPTS();\r
657         for( ;; );\r
658 }\r
659 /*-----------------------------------------------------------*/\r
660 \r
661 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
662 {\r
663         ( void ) pxTask;\r
664         ( void ) pcTaskName;\r
665         \r
666         /* Run time stack overflow checking is performed if\r
667         configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
668         function is called if a stack overflow is detected. */\r
669         taskDISABLE_INTERRUPTS();\r
670         for( ;; );\r
671 }\r
672 /*-----------------------------------------------------------*/\r
673 \r
674 \r