]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/MSP430X_MSP430F5438_IAR/main.c
422d651acbb2cd6a27d3d568954ea7a3a19c1c8e
[freertos] / FreeRTOS / Demo / MSP430X_MSP430F5438_IAR / main.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /*\r
29  * The documentation page for this demo available on http://www.FreeRTOS.org\r
30  * documents the hardware configuration required to run this demo.  It also\r
31  * provides more information on the expected demo application behaviour.\r
32  *\r
33  * main() creates all the demo application tasks, then starts the scheduler.\r
34  * A lot of the created tasks are from the pool of "standard demo" tasks.  The\r
35  * web documentation provides more details of the standard demo tasks, which\r
36  * provide no particular functionality but do provide good examples of how to\r
37  * use the FreeRTOS API.\r
38  *\r
39  * In addition to the standard demo tasks, the following tasks, interrupts and\r
40  * tests are defined and/or created within this file:\r
41  *\r
42  * "LCD" task - The LCD task is a 'gatekeeper' task.  It is the only task that\r
43  * is permitted to access the LCD and therefore ensures access to the LCD is\r
44  * always serialised and there are no mutual exclusion issues.  When a task or\r
45  * an interrupt wants to write to the LCD, it does not access the LCD directly\r
46  * but instead sends the message to the LCD task.  The LCD task then performs\r
47  * the actual LCD output.  This mechanism also allows interrupts to, in effect,\r
48  * write to the LCD by sending messages to the LCD task.\r
49  *\r
50  * The LCD task is also a demonstration of a 'controller' task design pattern.\r
51  * Some tasks do not actually send a string to the LCD task directly, but\r
52  * instead send a command that is interpreted by the LCD task.  In a normal\r
53  * application these commands can be control values or set points, in this\r
54  * simple example the commands just result in messages being displayed on the\r
55  * LCD.\r
56  *\r
57  * "Button Poll" task - This task polls the state of the 'up' key on the\r
58  * joystick input device.  It uses the vTaskDelay() API function to control\r
59  * the poll rate to ensure debouncing is not necessary and that the task does\r
60  * not use all the available CPU processing time.\r
61  *\r
62  * Button Interrupt and run time stats display - The select button on the\r
63  * joystick input device is configured to generate an external interrupt.  The\r
64  * handler for this interrupt sends a message to LCD task, which interprets the\r
65  * message to mean, firstly write a message to the LCD, and secondly, generate\r
66  * a table of run time statistics.  The run time statistics are displayed as a\r
67  * table that contains information on how much processing time each task has\r
68  * been allocated since the application started to execute.  This information\r
69  * is provided both as an absolute time, and as a percentage of the total run\r
70  * time.  The information is displayed in the terminal IO window of the IAR\r
71  * embedded workbench.  The online documentation for this demo shows a screen\r
72  * shot demonstrating where the run time stats can be viewed.\r
73  *\r
74  * Idle Hook - The idle hook is a function that is called on each iteration of\r
75  * the idle task.  In this case it is used to place the processor into a low\r
76  * power mode.  Note however that this application is implemented using standard\r
77  * components, and is therefore not optimised for low power operation.  Lower\r
78  * power consumption would be achieved by converting polling tasks into event\r
79  * driven tasks, and slowing the tick interrupt frequency.\r
80  *\r
81  * "Check" function called from the tick hook - The tick hook is called during\r
82  * each tick interrupt.  It is called from an interrupt context so must execute\r
83  * quickly, not attempt to block, and not call any FreeRTOS API functions that\r
84  * do not end in "FromISR".  In this case the tick hook executes a 'check'\r
85  * function.  This only executes every five seconds.  Its main function is to\r
86  * check that all the standard demo tasks are still operational.  Each time it\r
87  * executes it sends a status code to the LCD task.  The LCD task interprets the\r
88  * code and displays an appropriate message - which will be PASS if no tasks\r
89  * have reported any errors, or a message stating which task has reported an\r
90  * error.\r
91  *\r
92  * "Reg test" tasks - These fill the registers with known values, then check\r
93  * that each register still contains its expected value.  Each task uses\r
94  * different values.  The tasks run with very low priority so get preempted\r
95  * very frequently.  A check variable is incremented on each iteration of the\r
96  * test loop.  A register containing an unexpected value is indicative of an\r
97  * error in the context switching mechanism and will result in a branch to a\r
98  * null loop - which in turn will prevent the check variable from incrementing\r
99  * any further and allow the check task (described a above) to determine that an\r
100  * error has occurred.  The nature of the reg test tasks necessitates that they\r
101  * are written in assembly code.\r
102  *\r
103  * *NOTE 1* vApplicationSetupTimerInterrupt() is called by the kernel to let\r
104  * the application set up a timer to generate the tick interrupt.  In this\r
105  * example a timer A0 is used for this purpose.\r
106  *\r
107 */\r
108 \r
109 /* Standard includes. */\r
110 #include <stdio.h>\r
111 \r
112 /* FreeRTOS includes. */\r
113 #include "FreeRTOS.h"\r
114 #include "task.h"\r
115 #include "queue.h"\r
116 \r
117 /* Hardware includes. */\r
118 #include "msp430.h"\r
119 #include "hal_MSP-EXP430F5438.h"\r
120 \r
121 /* Standard demo includes. */\r
122 #include "ParTest.h"\r
123 #include "dynamic.h"\r
124 #include "comtest2.h"\r
125 #include "GenQTest.h"\r
126 \r
127 /* Codes sent within messages to the LCD task so the LCD task can interpret\r
128 exactly what the message it just received was.  These are sent in the\r
129 cMessageID member of the message structure (defined below). */\r
130 #define mainMESSAGE_BUTTON_UP                   ( 1 )\r
131 #define mainMESSAGE_BUTTON_SEL                  ( 2 )\r
132 #define mainMESSAGE_STATUS                              ( 3 )\r
133 \r
134 /* When the cMessageID member of the message sent to the LCD task is\r
135 mainMESSAGE_STATUS then these definitions are sent in the ulMessageValue member\r
136 of the same message and indicate what the status actually is. */\r
137 #define mainERROR_DYNAMIC_TASKS                 ( pdPASS + 1 )\r
138 #define mainERROR_COM_TEST                              ( pdPASS + 2 )\r
139 #define mainERROR_GEN_QUEUE_TEST                ( pdPASS + 3 )\r
140 #define mainERROR_REG_TEST                              ( pdPASS + 4 )\r
141 \r
142 /* The length of the queue (the number of items the queue can hold) that is used\r
143 to send messages from tasks and interrupts the the LCD task. */\r
144 #define mainQUEUE_LENGTH                                ( 5 )\r
145 \r
146 /* Priorities used by the test and demo tasks. */\r
147 #define mainLCD_TASK_PRIORITY                   ( tskIDLE_PRIORITY + 1 )\r
148 #define mainCOM_TEST_PRIORITY                   ( tskIDLE_PRIORITY + 2 )\r
149 #define mainGENERIC_QUEUE_TEST_PRIORITY ( tskIDLE_PRIORITY )\r
150 \r
151 /* The LED used by the comtest tasks. See the comtest.c file for more\r
152 information.  */\r
153 #define mainCOM_TEST_LED                                ( 1 )\r
154 \r
155 /* The baud rate used by the comtest tasks described at the top of this file. */\r
156 #define mainCOM_TEST_BAUD_RATE                  ( 38400 )\r
157 \r
158 /* The maximum number of lines of text that can be displayed on the LCD. */\r
159 #define mainMAX_LCD_LINES                               ( 8 )\r
160 \r
161 /* Just used to ensure parameters are passed into tasks correctly. */\r
162 #define mainTASK_PARAMETER_CHECK_VALUE  ( ( void * ) 0xDEAD )\r
163 /*-----------------------------------------------------------*/\r
164 \r
165 /*\r
166  * The reg test tasks as described at the top of this file.\r
167  */\r
168 extern void vRegTest1Task( void *pvParameters );\r
169 extern void vRegTest2Task( void *pvParameters );\r
170 \r
171 /*\r
172  * Configures clocks, LCD, port pints, etc. necessary to execute this demo.\r
173  */\r
174 static void prvSetupHardware( void );\r
175 \r
176 /*\r
177  * Definition of the LCD/controller task described in the comments at the top\r
178  * of this file.\r
179  */\r
180 static void prvLCDTask( void *pvParameters );\r
181 \r
182 /*\r
183  * Definition of the button poll task described in the comments at the top of\r
184  * this file.\r
185  */\r
186 static void prvButtonPollTask( void *pvParameters );\r
187 \r
188 /*\r
189  * Converts a status message value into an appropriate string for display on\r
190  * the LCD.  The string is written to pcBuffer.\r
191  */\r
192 static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue );\r
193 \r
194 /*-----------------------------------------------------------*/\r
195 \r
196 /* Variables that are incremented on each iteration of the reg test tasks -\r
197 provided the tasks have not reported any errors.  The check task inspects these\r
198 variables to ensure they are still incrementing as expected.  If a variable\r
199 stops incrementing then it is likely that its associate task has stalled. */\r
200 volatile unsigned short usRegTest1Counter = 0, usRegTest2Counter = 0;\r
201 \r
202 /* The handle of the queue used to send messages from tasks and interrupts to\r
203 the LCD task. */\r
204 static QueueHandle_t xLCDQueue = NULL;\r
205 \r
206 /* The definition of each message sent from tasks and interrupts to the LCD\r
207 task. */\r
208 typedef struct\r
209 {\r
210         char cMessageID;                                /* << States what the message is. */\r
211         unsigned long ulMessageValue;   /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID). */\r
212 } xQueueMessage;\r
213 \r
214 /*-----------------------------------------------------------*/\r
215 \r
216 /* The linker script can be used to test the FreeRTOS ports use of 20bit\r
217 addresses by locating all code in high memory.  The following pragma ensures\r
218 that main remains in low memory when that is done.  The ISR_CODE segment is used\r
219 for convenience as ISR functions are always placed in low memory. */\r
220 #pragma location="ISR_CODE"\r
221 void main( void )\r
222 {\r
223         /* Configure the peripherals used by this demo application.  This includes\r
224         configuring the joystick input select button to generate interrupts. */\r
225         prvSetupHardware();\r
226 \r
227         /* Create the queue used by tasks and interrupts to send strings to the LCD\r
228         task. */\r
229         xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );\r
230 \r
231         /* If the queue could not be created then don't create any tasks that might\r
232         attempt to use the queue. */\r
233         if( xLCDQueue != NULL )\r
234         {\r
235                 /* Add the created queue to the queue registry so it can be viewed in\r
236                 the IAR FreeRTOS state viewer plug-in. */\r
237                 vQueueAddToRegistry( xLCDQueue, "LCDQueue" );\r
238 \r
239                 /* Create the standard demo tasks. */\r
240                 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
241                 vStartDynamicPriorityTasks();\r
242                 vStartGenericQueueTasks( mainGENERIC_QUEUE_TEST_PRIORITY );\r
243 \r
244                 /* Create the LCD, button poll and register test tasks, as described at\r
245                 the top of this file. */\r
246                 xTaskCreate( prvLCDTask, "LCD", configMINIMAL_STACK_SIZE * 2, mainTASK_PARAMETER_CHECK_VALUE, mainLCD_TASK_PRIORITY, NULL );\r
247                 xTaskCreate( prvButtonPollTask, "BPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );\r
248                 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
249                 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );\r
250 \r
251                 /* Start the scheduler. */\r
252                 vTaskStartScheduler();\r
253         }\r
254 \r
255         /* If all is well then this line will never be reached.  If it is reached\r
256         then it is likely that there was insufficient (FreeRTOS) heap memory space\r
257         to create the idle task.  This may have been trapped by the malloc() failed\r
258         hook function, if one is configured. */\r
259         for( ;; );\r
260 }\r
261 /*-----------------------------------------------------------*/\r
262 \r
263 static void prvLCDTask( void *pvParameters )\r
264 {\r
265 xQueueMessage xReceivedMessage;\r
266 \r
267 /* Buffer into which strings are formatted and placed ready for display on the\r
268 LCD.  Note this is a static variable to prevent it being allocated on the task\r
269 stack, which is too small to hold such a variable.  The stack size is configured\r
270 when the task is created. */\r
271 static char cBuffer[ 512 ];\r
272 unsigned char ucLine = 1;\r
273 \r
274 \r
275         /* This function is the only function that uses printf().  If printf() is\r
276         used from any other function then some sort of mutual exclusion on stdout\r
277         will be necessary.\r
278 \r
279         This is also the only function that is permitted to access the LCD.\r
280 \r
281         First print out the number of bytes that remain in the FreeRTOS heap.  This\r
282         can be viewed in the terminal IO window within the IAR Embedded Workbench. */\r
283         printf( "%d bytes of heap space remain unallocated\n", ( int ) xPortGetFreeHeapSize() );\r
284 \r
285         /* Just as a test of the port, and for no functional reason, check the task\r
286         parameter contains its expected value. */\r
287         if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )\r
288         {\r
289                 halLcdPrintLine( "Invalid parameter", ucLine,  OVERWRITE_TEXT );\r
290                 ucLine++;\r
291         }\r
292 \r
293         for( ;; )\r
294         {\r
295                 /* Wait for a message to be received.  Using portMAX_DELAY as the block\r
296                 time will result in an indefinite wait provided INCLUDE_vTaskSuspend is\r
297                 set to 1 in FreeRTOSConfig.h, therefore there is no need to check the\r
298                 function return value and the function will only return when a value\r
299                 has been received. */\r
300                 xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );\r
301 \r
302                 /* Clear the LCD if no room remains for any more text output. */\r
303                 if( ucLine > mainMAX_LCD_LINES )\r
304                 {\r
305                         halLcdClearScreen();\r
306                         ucLine = 0;\r
307                 }\r
308 \r
309                 /* What is this message?  What does it contain? */\r
310                 switch( xReceivedMessage.cMessageID )\r
311                 {\r
312                         case mainMESSAGE_BUTTON_UP              :       /* The button poll task has just\r
313                                                                                                 informed this task that the up\r
314                                                                                                 button on the joystick input has\r
315                                                                                                 been pressed or released. */\r
316                                                                                                 sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );\r
317                                                                                                 break;\r
318 \r
319                         case mainMESSAGE_BUTTON_SEL             :       /* The select button interrupt\r
320                                                                                                 just informed this task that the\r
321                                                                                                 select button was pressed.\r
322                                                                                                 Generate a table of task run time\r
323                                                                                                 statistics and output this to\r
324                                                                                                 the terminal IO window in the IAR\r
325                                                                                                 embedded workbench. */\r
326                                                                                                 printf( "\nTask\t     Abs Time\t     %%Time\n*****************************************" );\r
327                                                                                                 vTaskGetRunTimeStats( cBuffer );\r
328                                                                                                 printf( cBuffer );\r
329 \r
330                                                                                                 /* Also print out a message to\r
331                                                                                                 the LCD - in this case the\r
332                                                                                                 pointer to the string to print\r
333                                                                                                 is sent directly in the\r
334                                                                                                 ulMessageValue member of the\r
335                                                                                                 message.  This just demonstrates\r
336                                                                                                 a different communication\r
337                                                                                                 technique. */\r
338                                                                                                 sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );\r
339                                                                                                 break;\r
340 \r
341                         case mainMESSAGE_STATUS                 :       /* The tick interrupt hook\r
342                                                                                                 function has just informed this\r
343                                                                                                 task of the system status.\r
344                                                                                                 Generate a string in accordance\r
345                                                                                                 with the status value. */\r
346                                                                                                 prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );\r
347                                                                                                 break;\r
348 \r
349                         default                                                 :       sprintf( cBuffer, "Unknown message" );\r
350                                                                                                 break;\r
351                 }\r
352 \r
353                 /* Output the message that was placed into the cBuffer array within the\r
354                 switch statement above, then move onto the next line ready for the next\r
355                 message to arrive on the queue. */\r
356                 halLcdPrintLine( cBuffer, ucLine,  OVERWRITE_TEXT );\r
357                 ucLine++;\r
358         }\r
359 }\r
360 /*-----------------------------------------------------------*/\r
361 \r
362 static void prvGenerateStatusMessage( char *pcBuffer, long lStatusValue )\r
363 {\r
364         /* Just a utility function to convert a status value into a meaningful\r
365         string for output onto the LCD. */\r
366         switch( lStatusValue )\r
367         {\r
368                 case pdPASS                                             :       sprintf( pcBuffer, "Status = PASS" );\r
369                                                                                         break;\r
370                 case mainERROR_DYNAMIC_TASKS    :       sprintf( pcBuffer, "Err: Dynamic tsks" );\r
371                                                                                         break;\r
372                 case mainERROR_COM_TEST                 :       sprintf( pcBuffer, "Err: COM test" );\r
373                                                                                         break;\r
374                 case mainERROR_GEN_QUEUE_TEST   :       sprintf( pcBuffer, "Error: Gen Q test" );\r
375                                                                                         break;\r
376                 case mainERROR_REG_TEST                 :       sprintf( pcBuffer, "Error: Reg test" );\r
377                                                                                         break;\r
378                 default                                                 :       sprintf( pcBuffer, "Unknown status" );\r
379                                                                                         break;\r
380         }\r
381 }\r
382 /*-----------------------------------------------------------*/\r
383 \r
384 static void prvButtonPollTask( void *pvParameters )\r
385 {\r
386 unsigned char ucLastState = pdFALSE, ucState;\r
387 xQueueMessage xMessage;\r
388 \r
389         /* This tasks performs the button polling functionality as described at the\r
390         top of this file. */\r
391         for( ;; )\r
392         {\r
393                 /* Check the button state. */\r
394                 ucState = ( halButtonsPressed() & BUTTON_UP );\r
395 \r
396                 if( ucState != 0 )\r
397                 {\r
398                         /* The button was pressed. */\r
399                         ucState = pdTRUE;\r
400                 }\r
401 \r
402                 if( ucState != ucLastState )\r
403                 {\r
404                         /* The state has changed, send a message to the LCD task. */\r
405                         xMessage.cMessageID = mainMESSAGE_BUTTON_UP;\r
406                         xMessage.ulMessageValue = ( unsigned long ) ucState;\r
407                         ucLastState = ucState;\r
408                         xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );\r
409                 }\r
410 \r
411                 /* Block for 10 milliseconds so this task does not utilise all the CPU\r
412                 time and debouncing of the button is not necessary. */\r
413                 vTaskDelay( 10 / portTICK_PERIOD_MS );\r
414         }\r
415 }\r
416 /*-----------------------------------------------------------*/\r
417 \r
418 static void prvSetupHardware( void )\r
419 {\r
420         halBoardInit();\r
421 \r
422         LFXT_Start( XT1DRIVE_0 );\r
423         hal430SetSystemClock( configCPU_CLOCK_HZ, configLFXT_CLOCK_HZ );\r
424 \r
425         halButtonsInit( BUTTON_ALL );\r
426         halButtonsInterruptEnable( BUTTON_SELECT );\r
427 \r
428         /* Initialise the LCD, but note that the backlight is not used as the\r
429         library function uses timer A0 to modulate the backlight, and this file\r
430         defines vApplicationSetupTimerInterrupt() to also use timer A0 to generate\r
431         the tick interrupt.  If the backlight is required, then change either the\r
432         halLCD library or vApplicationSetupTimerInterrupt() to use a different\r
433         timer.  Timer A1 is used for the run time stats time base6. */\r
434         halLcdInit();\r
435         halLcdSetContrast( 100 );\r
436         halLcdClearScreen();\r
437 \r
438         halLcdPrintLine( " www.FreeRTOS.org", 0,  OVERWRITE_TEXT );\r
439 }\r
440 /*-----------------------------------------------------------*/\r
441 \r
442 void vApplicationTickHook( void )\r
443 {\r
444 static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;\r
445 static unsigned long ulCounter = 0;\r
446 static const unsigned long ulCheckFrequency = 5000UL / portTICK_PERIOD_MS;\r
447 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
448 \r
449 /* Define the status message that is sent to the LCD task.  By default the\r
450 status is PASS. */\r
451 static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };\r
452 \r
453         /* This is called from within the tick interrupt and performs the 'check'\r
454         functionality as described in the comments at the top of this file.\r
455 \r
456         Is it time to perform the 'check' functionality again? */\r
457         ulCounter++;\r
458         if( ulCounter >= ulCheckFrequency )\r
459         {\r
460                 /* See if the standard demo tasks are executing as expected, changing\r
461                 the message that is sent to the LCD task from PASS to an error code if\r
462                 any tasks set reports an error. */\r
463                 if( xAreComTestTasksStillRunning() != pdPASS )\r
464                 {\r
465                         xStatusMessage.ulMessageValue = mainERROR_COM_TEST;\r
466                 }\r
467 \r
468                 if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
469                 {\r
470                         xStatusMessage.ulMessageValue = mainERROR_DYNAMIC_TASKS;\r
471                 }\r
472 \r
473                 if( xAreGenericQueueTasksStillRunning() != pdPASS )\r
474                 {\r
475                         xStatusMessage.ulMessageValue = mainERROR_GEN_QUEUE_TEST;\r
476                 }\r
477 \r
478                 /* Check the reg test tasks are still cycling.  They will stop\r
479                 incrementing their loop counters if they encounter an error. */\r
480                 if( usRegTest1Counter == usLastRegTest1Counter )\r
481                 {\r
482                         xStatusMessage.ulMessageValue = mainERROR_REG_TEST;\r
483                 }\r
484 \r
485                 if( usRegTest2Counter == usLastRegTest2Counter )\r
486                 {\r
487                         xStatusMessage.ulMessageValue = mainERROR_REG_TEST;\r
488                 }\r
489 \r
490                 usLastRegTest1Counter = usRegTest1Counter;\r
491                 usLastRegTest2Counter = usRegTest2Counter;\r
492 \r
493                 /* As this is the tick hook the lHigherPriorityTaskWoken parameter is not\r
494                 needed (a context switch is going to be performed anyway), but it must\r
495                 still be provided. */\r
496                 xQueueSendFromISR( xLCDQueue, &xStatusMessage, &xHigherPriorityTaskWoken );\r
497                 ulCounter = 0;\r
498         }\r
499 \r
500         /* Just periodically toggle an LED to show that the tick interrupt is\r
501         running.  Note that this access LED_PORT_OUT in a non-atomic way, so tasks\r
502         that access the same port must do so from a critical section. */\r
503         if( ( ulCounter & 0xff ) == 0 )\r
504         {\r
505                 if( ( LED_PORT_OUT & LED_1 ) == 0 )\r
506                 {\r
507                         LED_PORT_OUT |= LED_1;\r
508                 }\r
509                 else\r
510                 {\r
511                         LED_PORT_OUT &= ~LED_1;\r
512                 }\r
513         }\r
514 }\r
515 /*-----------------------------------------------------------*/\r
516 \r
517 #pragma vector=PORT2_VECTOR\r
518 __interrupt static void prvSelectButtonInterrupt(void)\r
519 {\r
520 /* Define the message sent to the LCD task from this interrupt. */\r
521 static const xQueueMessage xMessage = { mainMESSAGE_BUTTON_SEL, ( unsigned long ) "Select Interrupt" };\r
522 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
523 \r
524         /* This is the interrupt handler for the joystick select button input.\r
525         The button has been pushed, write a message to the LCD via the LCD task. */\r
526         xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );\r
527 \r
528         P2IFG = 0;\r
529 \r
530         /* If writing to xLCDQueue caused a task to unblock, and the unblocked task\r
531         has a priority equal to or above the task that this interrupt interrupted,\r
532         then lHigherPriorityTaskWoken will have been set to pdTRUE internally within\r
533         xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this\r
534         interrupt returns directly to the higher priority unblocked task. */\r
535         portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
536 }\r
537 /*-----------------------------------------------------------*/\r
538 \r
539 /* The MSP430X port uses this callback function to configure its tick interrupt.\r
540 This allows the application to choose the tick interrupt source.\r
541 configTICK_VECTOR must also be set in FreeRTOSConfig.h to the correct\r
542 interrupt vector for the chosen tick interrupt source.  This implementation of\r
543 vApplicationSetupTimerInterrupt() generates the tick from timer A0, so in this\r
544 case configTICK_VECTOR is set to TIMER0_A0_VECTOR. */\r
545 void vApplicationSetupTimerInterrupt( void )\r
546 {\r
547 const unsigned short usACLK_Frequency_Hz = 32768;\r
548 \r
549         /* Ensure the timer is stopped. */\r
550         TA0CTL = 0;\r
551 \r
552         /* Run the timer from the ACLK. */\r
553         TA0CTL = TASSEL_1;\r
554 \r
555         /* Clear everything to start with. */\r
556         TA0CTL |= TACLR;\r
557 \r
558         /* Set the compare match value according to the tick rate we want. */\r
559         TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;\r
560 \r
561         /* Enable the interrupts. */\r
562         TA0CCTL0 = CCIE;\r
563 \r
564         /* Start up clean. */\r
565         TA0CTL |= TACLR;\r
566 \r
567         /* Up mode. */\r
568         TA0CTL |= MC_1;\r
569 }\r
570 /*-----------------------------------------------------------*/\r
571 \r
572 void vApplicationIdleHook( void )\r
573 {\r
574         /* Called on each iteration of the idle task.  In this case the idle task\r
575         just enters a low power mode. */\r
576         __bis_SR_register( LPM3_bits + GIE );\r
577 }\r
578 /*-----------------------------------------------------------*/\r
579 \r
580 void vApplicationMallocFailedHook( void )\r
581 {\r
582         /* Called if a call to pvPortMalloc() fails because there is insufficient\r
583         free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
584         internally by FreeRTOS API functions that create tasks, queues or\r
585         semaphores. */\r
586         taskDISABLE_INTERRUPTS();\r
587         for( ;; );\r
588 }\r
589 /*-----------------------------------------------------------*/\r
590 \r
591 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
592 {\r
593         ( void ) pxTask;\r
594         ( void ) pcTaskName;\r
595 \r
596         /* Run time stack overflow checking is performed if\r
597         configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
598         function is called if a stack overflow is detected. */\r
599         taskDISABLE_INTERRUPTS();\r
600         for( ;; );\r
601 }\r
602 /*-----------------------------------------------------------*/\r
603 \r