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