]> git.sur5r.net Git - freertos/blob - Demo/MSP430X_MSP430F5438_IAR/main.c
Minor updates to the MSP430X IAR demo application.
[freertos] / Demo / MSP430X_MSP430F5438_IAR / main.c
1 /*\r
2     FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\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 exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     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 and\r
66  * tests 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 and run time stats display - The select button on the\r
89  * joystick input device is configured to generate an external interrupt.  The\r
90  * handler for this interrupt sends a message to LCD task, which interprets the\r
91  * message to mean, firstly write a message to the LCD, and secondly, generate\r
92  * a table of run time statistics.  The run time statistics are displayed as a\r
93  * table that contains information on how much processing time each task has\r
94  * been allocated since the application started to execute.  This information\r
95  * is provided both as an absolute time, and as a percentage of the total run\r
96  * time.  The information is displayed in the terminal IO window of the IAR\r
97  * embedded workbench.  The online documentation for this demo shows a screen\r
98  * shot demonstrating where the run time stats can be viewed.\r
99  *\r
100  * Idle Hook - The idle hook is a function that is called on each iteration of\r
101  * the idle task.  In this case it is used to place the processor into a low\r
102  * power mode.  Note however that this application is implemented using standard\r
103  * components, and is therefore not optimised for low power operation.  Lower\r
104  * power consumption would be achieved by converting polling tasks into event\r
105  * driven tasks, and slowing the tick interrupt frequency.\r
106  *\r
107  * "Check" function called from the tick hook - The tick hook is called during\r
108  * each tick interrupt.  It is called from an interrupt context so must execute\r
109  * quickly, not attempt to block, and not call any FreeRTOS API functions that\r
110  * do not end in "FromISR".  In this case the tick hook executes a 'check'\r
111  * function.  This only executes every five seconds.  Its main function is to\r
112  * check that all the standard demo tasks are still operational.  Each time it\r
113  * executes it sends a status code to the LCD task.  The LCD task interprets the\r
114  * code and displays an appropriate message - which will be PASS if no tasks\r
115  * have reported any errors, or a message stating which task has reported an\r
116  * error.\r
117  *\r
118  * "Reg test" tasks - These fill the registers with known values, then check\r
119  * that each register still contains its expected value.  Each task uses\r
120  * different values.  The tasks run with very low priority so get preempted\r
121  * very frequently.  A check variable is incremented on each iteration of the\r
122  * test loop.  A register containing an unexpected value is indicative of an\r
123  * error in the context switching mechanism and will result in a branch to a\r
124  * null loop - which in turn will prevent the check variable from incrementing\r
125  * any further and allow the check task (described a above) to determine that an\r
126  * error has occurred.  The nature of the reg test tasks necessitates that they\r
127  * are written in assembly code.\r
128  *\r
129  * *NOTE 2* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
130  * the application set up a timer to generate the tick interrupt.  In this\r
131  * example a timer A0 is used for this purpose.\r
132  *\r
133 */\r
134 \r
135 /* Standard includes. */\r
136 #include <stdio.h>\r
137 \r
138 /* FreeRTOS includes. */\r
139 #include "FreeRTOS.h"\r
140 #include "task.h"\r
141 #include "queue.h"\r
142 \r
143 /* Hardware includes. */\r
144 #include "msp430.h"\r
145 #include "hal_MSP-EXP430F5438.h"\r
146 \r
147 /* Standard demo includes. */\r
148 #include "ParTest.h"\r
149 #include "dynamic.h"\r
150 #include "comtest2.h"\r
151 #include "GenQTest.h"\r
152 \r
153 /* Codes sent within messages to the LCD task so the LCD task can interpret\r
154 exactly what the message it just received was.  These are sent in the\r
155 cMessageID member of the message structure (defined below). */\r
156 #define mainMESSAGE_BUTTON_UP                   ( 1 )\r
157 #define mainMESSAGE_BUTTON_SEL                  ( 2 )\r
158 #define mainMESSAGE_STATUS                              ( 3 )\r
159 \r
160 /* When the cMessageID member of the message sent to the LCD task is\r
161 mainMESSAGE_STATUS then these definitions are sent in the ulMessageValue member\r
162 of the same message and indicate what the status actually is. */\r
163 #define mainERROR_DYNAMIC_TASKS                 ( pdPASS + 1 )\r
164 #define mainERROR_COM_TEST                              ( pdPASS + 2 )\r
165 #define mainERROR_GEN_QUEUE_TEST                ( pdPASS + 3 )\r
166 #define mainERROR_REG_TEST                              ( pdPASS + 4 )\r
167 \r
168 /* The length of the queue (the number of items the queue can hold) that is used\r
169 to send messages from tasks and interrupts the the LCD task. */\r
170 #define mainQUEUE_LENGTH                                ( 5 )\r
171 \r
172 /* Priorities used by the test and demo tasks. */\r
173 #define mainLCD_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )\r
174 #define mainCOM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 2 )\r
175 #define mainGENERIC_QUEUE_TEST_PRIORITY ( tskIDLE_PRIORITY )\r
176 \r
177 /* The LED used by the comtest tasks. See the comtest.c file for more\r
178 information.  */\r
179 #define mainCOM_TEST_LED                                ( 1 )\r
180 \r
181 /* The baud rate used by the comtest tasks described at the top of this file. */\r
182 #define mainCOM_TEST_BAUD_RATE                  ( 38400 )\r
183 \r
184 /* The maximum number of lines of text that can be displayed on the LCD. */\r
185 #define mainMAX_LCD_LINES                               ( 8 )\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 /*\r
189  * The reg test tasks as described at the top of this file.\r
190  */\r
191 extern void vRegTest1Task( void *pvParameters );\r
192 extern void vRegTest2Task( void *pvParameters );\r
193 \r
194 /*\r
195  * Configures clocks, LCD, port pints, etc. necessary to execute this demo.\r
196  */\r
197 static void prvSetupHardware( void );\r
198 \r
199 /*\r
200  * Definition of the LCD/controller task described in the comments at the top\r
201  * of this file.\r
202  */\r
203 static void prvLCDTask( void *pvParameters );\r
204 \r
205 /*\r
206  * Definition of the button poll task described in the comments at the top of\r
207  * this file.\r
208  */\r
209 static void prvButtonPollTask( void *pvParameters );\r
210 \r
211 /*\r
212  * Converts a status message value into an appropriate string for display on\r
213  * the LCD.  The string is written to pcBuffer.\r
214  */\r
215 static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue );\r
216 \r
217 /*-----------------------------------------------------------*/\r
218 \r
219 /* Variables that are incremented on each iteration of the reg test tasks -\r
220 provided the tasks have not reported any errors.  The check task inspects these\r
221 variables to ensure they are still incrementing as expected.  If a variable\r
222 stops incrementing then it is likely that its associate task has stalled. */\r
223 volatile unsigned short usRegTest1Counter = 0, usRegTest2Counter = 0;\r
224 \r
225 /* The handle of the queue used to send messages from tasks and interrupts to\r
226 the LCD task. */\r
227 static xQueueHandle xLCDQueue = NULL;\r
228 \r
229 /* The definition of each message sent from tasks and interrupts to the LCD\r
230 task. */\r
231 typedef struct\r
232 {\r
233         char cMessageID;                                /* << States what the message is. */\r
234         unsigned long ulMessageValue;   /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID). */\r
235 } xQueueMessage;\r
236 \r
237 /*-----------------------------------------------------------*/\r
238 \r
239 /* The linker script tests the FreeRTOS ports use of 20bit addresses by\r
240 locating all code in high memory.  The following pragma ensures that main\r
241 remains in low memory.  The ISR_CODE segment is used for convenience as ISR\r
242 functions are always placed in low memory. */\r
243 #pragma location="ISR_CODE"\r
244 void main( void )\r
245 {\r
246         /* Configure the peripherals used by this demo application.  This includes\r
247         configuring the joystick input select button to generate interrupts. */\r
248         prvSetupHardware();\r
249 \r
250         /* Create the queue used by tasks and interrupts to send strings to the LCD\r
251         task. */\r
252         xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );\r
253 \r
254         /* If the queue could not be created then don't create any tasks that might\r
255         attempt to use the queue. */\r
256         if( xLCDQueue != NULL )\r
257         {\r
258                 /* Add the created queue to the queue registry so it can be viewed in\r
259                 the IAR FreeRTOS state viewer plug-in. */\r
260                 vQueueAddToRegistry( xLCDQueue, "LCDQueue" );\r
261 \r
262                 /* Create the standard demo tasks. */\r
263                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
264                 vStartDynamicPriorityTasks();\r
265                 vStartGenericQueueTasks( mainGENERIC_QUEUE_TEST_PRIORITY );\r
266                 \r
267                 /* Create the LCD, button poll and register test tasks, as described at\r
268                 the top of this file. */\r
269                 xTaskCreate( prvLCDTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE * 2, NULL, mainLCD_TASK_PRIORITY, NULL );\r
270                 xTaskCreate( prvButtonPollTask, ( signed char * ) "BPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
271                 xTaskCreate( vRegTest1Task, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
272                 xTaskCreate( vRegTest2Task, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
273 \r
274                 /* Start the scheduler. */\r
275                 vTaskStartScheduler();\r
276         }\r
277         \r
278         /* If all is well then this line will never be reached.  If it is reached\r
279         then it is likely that there was insufficient (FreeRTOS) heap memory space\r
280         to create the idle task.  This may have been trapped by the malloc() failed\r
281         hook function, if one is configured. */ \r
282         for( ;; );\r
283 }\r
284 /*-----------------------------------------------------------*/\r
285 \r
286 static void prvLCDTask( void *pvParameters )\r
287 {\r
288 xQueueMessage xReceivedMessage;\r
289 \r
290 /* Buffer into which strings are formatted and placed ready for display on the\r
291 LCD.  Note this is a static variable to prevent it being allocated on the task\r
292 stack, which is too small to hold such a variable.  The stack size is configured\r
293 when the task is created. */\r
294 static char cBuffer[ 512 ];\r
295 unsigned char ucLine = 1;\r
296 \r
297 \r
298         /* This function is the only function that uses printf().  If printf() is\r
299         used from any other function then some sort of mutual exclusion on stdout\r
300         will be necessary.\r
301         \r
302         This is also the only function that is permitted to access the LCD.\r
303         \r
304         First print out the number of bytes that remain in the FreeRTOS heap.  This\r
305         can be viewed in the terminal IO window within the IAR Embedded Workbench. */\r
306         printf( "%d bytes of heap space remain unallocated\n", ( int ) xPortGetFreeHeapSize() );\r
307 \r
308         for( ;; )\r
309         {\r
310                 /* Wait for a message to be received.  Using portMAX_DELAY as the block\r
311                 time will result in an indefinite wait provided INCLUDE_vTaskSuspend is\r
312                 set to 1 in FreeRTOSConfig.h, therefore there is no need to check the\r
313                 function return value and the function will only return when a value\r
314                 has been received. */\r
315                 xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );\r
316 \r
317                 /* Clear the LCD if no room remains for any more text output. */\r
318                 if( ucLine > mainMAX_LCD_LINES )\r
319                 {\r
320                         halLcdClearScreen();\r
321                         ucLine = 0;\r
322                 }\r
323                 \r
324                 /* What is this message?  What does it contain? */\r
325                 switch( xReceivedMessage.cMessageID )\r
326                 {\r
327                         case mainMESSAGE_BUTTON_UP              :       /* The button poll task has just\r
328                                                                                                 informed this task that the up\r
329                                                                                                 button on the joystick input has\r
330                                                                                                 been pressed or released. */\r
331                                                                                                 sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );\r
332                                                                                                 break;\r
333 \r
334                         case mainMESSAGE_BUTTON_SEL             :       /* The select button interrupt\r
335                                                                                                 just informed this task that the\r
336                                                                                                 select button was pressed.\r
337                                                                                                 Generate a table of task run time\r
338                                                                                                 statistics and output this to\r
339                                                                                                 the terminal IO window in the IAR\r
340                                                                                                 embedded workbench. */\r
341                                                                                                 printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );\r
342                                                                                                 fflush( stdout );\r
343                                                                                                 vTaskGetRunTimeStats( ( signed char * ) cBuffer );\r
344                                                                                                 printf( cBuffer );\r
345                                                                                                 fflush( stdout );\r
346                                                                                                 \r
347                                                                                                 /* Also print out a message to\r
348                                                                                                 the LCD - in this case the\r
349                                                                                                 pointer to the string to print\r
350                                                                                                 is sent directly in the\r
351                                                                                                 ulMessageValue member of the\r
352                                                                                                 message.  This just demonstrates\r
353                                                                                                 a different communication\r
354                                                                                                 technique. */\r
355                                                                                                 sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );\r
356                                                                                                 break;\r
357                                                                                                 \r
358                         case mainMESSAGE_STATUS                 :       /* The tick interrupt hook\r
359                                                                                                 function has just informed this\r
360                                                                                                 task of the system status.\r
361                                                                                                 Generate a string in accordance\r
362                                                                                                 with the status value. */\r
363                                                                                                 prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );\r
364                                                                                                 break;\r
365                                                                                                 \r
366                         default                                                 :       sprintf( cBuffer, "Unknown message" );\r
367                                                                                                 break;\r
368                 }\r
369                 \r
370                 /* Output the message that was placed into the cBuffer array within the\r
371                 switch statement above, then move onto the next line ready for the next\r
372                 message to arrive on the queue. */\r
373                 halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );\r
374                 ucLine++;\r
375         }\r
376 }\r
377 /*-----------------------------------------------------------*/\r
378 \r
379 static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue )\r
380 {\r
381         /* Just a utility function to convert a status value into a meaningful\r
382         string for output onto the LCD. */\r
383         switch( lStatusValue )\r
384         {\r
385                 case pdPASS                                             :       sprintf( pcBuffer, "Status = PASS" );\r
386                                                                                         break;\r
387                 case mainERROR_DYNAMIC_TASKS    :       sprintf( pcBuffer, "Err: Dynamic tsks" );\r
388                                                                                         break;\r
389                 case mainERROR_COM_TEST                 :       sprintf( pcBuffer, "Err: COM test" );\r
390                                                                                         break;\r
391                 case mainERROR_GEN_QUEUE_TEST   :       sprintf( pcBuffer, "Error: Gen Q test" );\r
392                                                                                         break;\r
393                 case mainERROR_REG_TEST                 :       sprintf( pcBuffer, "Error: Reg test" );\r
394                                                                                         break;\r
395                 default                                                 :       sprintf( pcBuffer, "Unknown status" );\r
396                                                                                         break;\r
397         }\r
398 }\r
399 /*-----------------------------------------------------------*/\r
400 \r
401 static void prvButtonPollTask( void *pvParameters )\r
402 {\r
403 unsigned char ucLastState = pdFALSE, ucState;\r
404 xQueueMessage xMessage;\r
405 \r
406         /* This tasks performs the button polling functionality as described at the\r
407         top of this file. */\r
408         for( ;; )\r
409         {\r
410                 /* Check the button state. */\r
411                 ucState = ( halButtonsPressed() & BUTTON_UP );\r
412                 \r
413                 if( ucState != 0 )\r
414                 {\r
415                         /* The button was pressed. */\r
416                         ucState = pdTRUE;\r
417                 }\r
418                 \r
419                 if( ucState != ucLastState )\r
420                 {\r
421                         /* The state has changed, send a message to the LCD task. */\r
422                         xMessage.cMessageID = mainMESSAGE_BUTTON_UP;\r
423                         xMessage.ulMessageValue = ( unsigned long ) ucState;\r
424                         ucLastState = ucState;\r
425                         xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );\r
426                 }\r
427                 \r
428                 /* Block for 10 milliseconds so this task does not utilise all the CPU\r
429                 time and debouncing of the button is not necessary. */\r
430                 vTaskDelay( 10 / portTICK_RATE_MS );\r
431         }\r
432 }\r
433 /*-----------------------------------------------------------*/\r
434 \r
435 static void prvSetupHardware( void )\r
436 {\r
437 /* Convert a Hz value to a KHz value, as required by the Init_FLL_Settle()\r
438 function. */\r
439 unsigned long ulCPU_Clock_KHz = ( configCPU_CLOCK_HZ / 1000UL );\r
440 \r
441         halBoardInit();\r
442 \r
443         LFXT_Start( XT1DRIVE_0 );\r
444         Init_FLL_Settle( ( unsigned short ) ulCPU_Clock_KHz, 488 );\r
445 \r
446         halButtonsInit( BUTTON_ALL );\r
447         halButtonsInterruptEnable( BUTTON_SELECT );\r
448 \r
449         /* Initialise the LCD, but note that the backlight is not used as the\r
450         library function uses timer A0 to modulate the backlight, and this file\r
451         defines vApplicationSetupTimerInterrupt() to also use timer A0 to generate\r
452         the tick interrupt.  If the backlight is required, then change either the\r
453         halLCD library or vApplicationSetupTimerInterrupt() to use a different\r
454         timer.  Timer A1 is used for the run time stats time base6. */\r
455         halLcdInit();\r
456         halLcdSetContrast( 100 );\r
457         halLcdClearScreen();\r
458         \r
459         halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );\r
460 }\r
461 /*-----------------------------------------------------------*/\r
462 \r
463 void vApplicationTickHook( void )\r
464 {\r
465 static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;\r
466 static unsigned long ulCounter = 0;\r
467 static const unsigned long ulCheckFrequency = 5000UL / portTICK_RATE_MS;\r
468 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
469 \r
470 /* Define the status message that is sent to the LCD task.  By default the\r
471 status is PASS. */\r
472 static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };\r
473 \r
474         /* This is called from within the tick interrupt and performs the 'check'\r
475         functionality as described in the comments at the top of this file.\r
476 \r
477         Is it time to perform the 'check' functionality again? */\r
478         ulCounter++;\r
479         if( ulCounter >= ulCheckFrequency )\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                 /* Check the reg test tasks are still cycling.  They will stop\r
500                 incrementing their loop counters if they encounter an error. */\r
501                 if( usRegTest1Counter == usLastRegTest1Counter )\r
502                 {\r
503                         xStatusMessage.ulMessageValue = mainERROR_REG_TEST;\r
504                 }\r
505 \r
506                 if( usRegTest2Counter == usLastRegTest2Counter )\r
507                 {\r
508                         xStatusMessage.ulMessageValue = mainERROR_REG_TEST;\r
509                 }\r
510 \r
511                 usLastRegTest1Counter = usRegTest1Counter;\r
512                 usLastRegTest2Counter = usRegTest2Counter;\r
513                 \r
514                 /* As this is the tick hook the lHigherPriorityTaskWoken parameter is not\r
515                 needed (a context switch is going to be performed anyway), but it must\r
516                 still be provided. */\r
517                 xQueueSendFromISR( xLCDQueue, &xStatusMessage, &xHigherPriorityTaskWoken );\r
518                 ulCounter = 0;\r
519         }\r
520 \r
521         /* Just periodically toggle an LED to show that the tick interrupt is\r
522         running.  Note that this access LED_PORT_OUT in a non-atomic way, so tasks\r
523         that access the same port must do so from a critical section. */\r
524         if( ( ulCounter & 0xff ) == 0 )\r
525         {\r
526                 if( ( LED_PORT_OUT & LED_1 ) == 0 )\r
527                 {\r
528                         LED_PORT_OUT |= LED_1;\r
529                 }\r
530                 else\r
531                 {\r
532                         LED_PORT_OUT &= ~LED_1;\r
533                 }\r
534         }\r
535 }\r
536 /*-----------------------------------------------------------*/\r
537 \r
538 #pragma vector=PORT2_VECTOR\r
539 __interrupt static void prvSelectButtonInterrupt(void)\r
540 {\r
541 /* Define the message sent to the LCD task from this interrupt. */\r
542 static const xQueueMessage xMessage = { mainMESSAGE_BUTTON_SEL, ( unsigned long ) "Select Interrupt" };\r
543 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
544 \r
545         /* This is the interrupt handler for the joystick select button input.\r
546         The button has been pushed, write a message to the LCD via the LCD task. */\r
547         xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );\r
548 \r
549         P2IFG = 0;\r
550         \r
551         /* If writing to xLCDQueue caused a task to unblock, and the unblocked task\r
552         has a priority equal to or above the task that this interrupt interrupted,\r
553         then lHigherPriorityTaskWoken will have been set to pdTRUE internally within\r
554         xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this\r
555         interrupt returns directly to the higher priority unblocked task. */\r
556         portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
557 }\r
558 /*-----------------------------------------------------------*/\r
559 \r
560 /* The MSP430X port uses this callback function to configure its tick interrupt.\r
561 This allows the application to choose the tick interrupt source.\r
562 configTICK_VECTOR must also be set in FreeRTOSConfig.h to the correct\r
563 interrupt vector for the chosen tick interrupt source.  This implementation of\r
564 vApplicationSetupTimerInterrupt() generates the tick from timer A0, so in this\r
565 case configTICK_VECTOR is set to TIMER0_A0_VECTOR. */\r
566 void vApplicationSetupTimerInterrupt( void )\r
567 {\r
568 const unsigned short usACLK_Frequency_Hz = 32768;\r
569 \r
570         /* Ensure the timer is stopped. */\r
571         TA0CTL = 0;\r
572 \r
573         /* Run the timer from the ACLK. */\r
574         TA0CTL = TASSEL_1;\r
575 \r
576         /* Clear everything to start with. */\r
577         TA0CTL |= TACLR;\r
578 \r
579         /* Set the compare match value according to the tick rate we want. */\r
580         TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;\r
581 \r
582         /* Enable the interrupts. */\r
583         TA0CCTL0 = CCIE;\r
584 \r
585         /* Start up clean. */\r
586         TA0CTL |= TACLR;\r
587 \r
588         /* Up mode. */\r
589         TA0CTL |= MC_1;\r
590 }\r
591 /*-----------------------------------------------------------*/\r
592 \r
593 void vApplicationIdleHook( void )\r
594 {\r
595         /* Called on each iteration of the idle task.  In this case the idle task\r
596         just enters a low(ish) power mode. */\r
597         __bis_SR_register( LPM1_bits + GIE );\r
598 }\r
599 /*-----------------------------------------------------------*/\r
600 \r
601 void vApplicationMallocFailedHook( void )\r
602 {\r
603         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
604         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
605         internally by FreeRTOS API functions that create tasks, queues or\r
606         semaphores. */\r
607         taskDISABLE_INTERRUPTS();\r
608         for( ;; );\r
609 }\r
610 /*-----------------------------------------------------------*/\r
611 \r
612 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
613 {\r
614         ( void ) pxTask;\r
615         ( void ) pcTaskName;\r
616         \r
617         /* Run time stack overflow checking is performed if\r
618         configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
619         function is called if a stack overflow is detected. */\r
620         taskDISABLE_INTERRUPTS();\r
621         for( ;; );\r
622 }\r
623 /*-----------------------------------------------------------*/\r
624 \r