2 FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
66 * The documentation page for this demo available on http://www.FreeRTOS.org
\r
67 * documents the hardware configuration required to run this demo. It also
\r
68 * provides more information on the expected demo application behaviour.
\r
70 * main() creates all the demo application tasks, then starts the scheduler.
\r
71 * A lot of the created tasks are from the pool of "standard demo" tasks. The
\r
72 * web documentation provides more details of the standard demo tasks, which
\r
73 * provide no particular functionality but do provide good examples of how to
\r
74 * use the FreeRTOS API.
\r
76 * In addition to the standard demo tasks, the following tasks, interrupts tests
\r
77 * and timers are defined and/or created within this file:
\r
79 * "LCD" task - The LCD task is a 'gatekeeper' task. It is the only task that
\r
80 * is permitted to access the LCD and therefore ensures access to the LCD is
\r
81 * always serialised and there are no mutual exclusion issues. When a task or
\r
82 * an interrupt wants to write to the LCD, it does not access the LCD directly
\r
83 * but instead sends the message to the LCD task. The LCD task then performs
\r
84 * the actual LCD output. This mechanism also allows interrupts to, in effect,
\r
85 * write to the LCD by sending messages to the LCD task.
\r
87 * The LCD task is also a demonstration of a 'controller' task design pattern.
\r
88 * Some tasks do not actually send a string to the LCD task directly, but
\r
89 * instead send a command that is interpreted by the LCD task. In a normal
\r
90 * application these commands can be control values or set points, in this
\r
91 * simple example the commands just result in messages being displayed on the
\r
94 * "Button Poll" task - This task polls the state of the 'up' key on the
\r
95 * joystick input device. It uses the vTaskDelay() API function to control
\r
96 * the poll rate to ensure debouncing is not necessary and that the task does
\r
97 * not use all the available CPU processing time.
\r
99 * Button Interrupt - The select button on the joystick input device is
\r
100 * configured to generate an external interrupt. The handler for this interrupt
\r
101 * sends a message to LCD task, which then prints out a string to say the
\r
102 * joystick select button was pressed.
\r
104 * Idle Hook - The idle hook is a function that is called on each iteration of
\r
105 * the idle task. In this case it is used to place the processor into a low
\r
106 * power mode. Note however that this application is implemented using standard
\r
107 * components, and is therefore not optimised for low power operation. Lower
\r
108 * power consumption would be achieved by converting polling tasks into event
\r
109 * driven tasks, and slowing the tick interrupt frequency, etc.
\r
111 * "Check" callback function - Called each time the 'check' timer expires. The
\r
112 * check timer executes every five seconds. Its main function is to check that
\r
113 * all the standard demo tasks are still operational. Each time it executes it
\r
114 * sends a status code to the LCD task. The LCD task interprets the code and
\r
115 * displays an appropriate message - which will be PASS if no tasks have
\r
116 * reported any errors, or a message stating which task has reported an error.
\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 timer callback (described a above) to
\r
126 * determine that an error has occurred. The nature of the reg test tasks
\r
127 * necessitates that they are written in assembly code.
\r
129 * Tick hook function - called inside the RTOS tick function, this simple
\r
130 * example does nothing but toggle an LED.
\r
132 * *NOTE 1* vApplicationSetupTimerInterrupt() is called by the kernel to let
\r
133 * the application set up a timer to generate the tick interrupt. In this
\r
134 * example a timer A0 is used for this purpose.
\r
138 /* Standard includes. */
\r
141 /* FreeRTOS includes. */
\r
142 #include "FreeRTOS.h"
\r
144 #include "timers.h"
\r
147 /* Hardware includes. */
\r
148 #include "msp430.h"
\r
149 #include "hal_MSP-EXP430F5438.h"
\r
151 /* Standard demo includes. */
\r
152 #include "ParTest.h"
\r
153 #include "dynamic.h"
\r
154 #include "comtest2.h"
\r
155 #include "GenQTest.h"
\r
156 #include "TimerDemo.h"
\r
157 #include "countsem.h"
\r
159 /* Codes sent within messages to the LCD task so the LCD task can interpret
\r
160 exactly what the message it just received was. These are sent in the
\r
161 cMessageID member of the message structure (defined below). */
\r
162 #define mainMESSAGE_BUTTON_UP ( 1 )
\r
163 #define mainMESSAGE_BUTTON_SEL ( 2 )
\r
164 #define mainMESSAGE_STATUS ( 3 )
\r
166 /* When the cMessageID member of the message sent to the LCD task is
\r
167 mainMESSAGE_STATUS then these definitions are sent in the ulMessageValue member
\r
168 of the same message and indicate what the status actually is. */
\r
169 #define mainERROR_DYNAMIC_TASKS ( pdPASS + 1 )
\r
170 #define mainERROR_COM_TEST ( pdPASS + 2 )
\r
171 #define mainERROR_GEN_QUEUE_TEST ( pdPASS + 3 )
\r
172 #define mainERROR_REG_TEST ( pdPASS + 4 )
\r
173 #define mainERROR_TIMER_TEST ( pdPASS + 5 )
\r
174 #define mainERROR_COUNT_SEM_TEST ( pdPASS + 6 )
\r
176 /* The length of the queue (the number of items the queue can hold) that is used
\r
177 to send messages from tasks and interrupts the the LCD task. */
\r
178 #define mainQUEUE_LENGTH ( 5 )
\r
180 /* Priorities used by the test and demo tasks. */
\r
181 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
182 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
183 #define mainGENERIC_QUEUE_TEST_PRIORITY ( tskIDLE_PRIORITY )
\r
185 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
187 #define mainCOM_TEST_LED ( 1 )
\r
189 /* The baud rate used by the comtest tasks. */
\r
190 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
192 /* The maximum number of lines of text that can be displayed on the LCD. */
\r
193 #define mainMAX_LCD_LINES ( 8 )
\r
195 /* Just used to ensure parameters are passed into tasks correctly. */
\r
196 #define mainTASK_PARAMETER_CHECK_VALUE ( ( void * ) 0xDEAD )
\r
198 /* The base period used by the timer test tasks. */
\r
199 #define mainTIMER_TEST_PERIOD ( 50 )
\r
201 /* The frequency at which the check timer (described in the comments at the top
\r
202 of this file) will call its callback function. */
\r
203 #define mainCHECK_TIMER_PERIOD ( 5000UL / ( unsigned long ) portTICK_RATE_MS )
\r
206 #define mainDONT_BLOCK ( 0 )
\r
207 /*-----------------------------------------------------------*/
\r
210 * The reg test tasks as described at the top of this file.
\r
212 extern void vRegTest1Task( void *pvParameters );
\r
213 extern void vRegTest2Task( void *pvParameters );
\r
216 * Configures clocks, LCD, port pints, etc. necessary to execute this demo.
\r
218 static void prvSetupHardware( void );
\r
221 * Definition of the LCD/controller task described in the comments at the top
\r
224 static void prvLCDTask( void *pvParameters );
\r
227 * Definition of the button poll task described in the comments at the top of
\r
230 static void prvButtonPollTask( void *pvParameters );
\r
233 * Converts a status message value into an appropriate string for display on
\r
234 * the LCD. The string is written to pcBuffer.
\r
236 static void prvGenerateStatusMessage( char *pcBuffer, unsigned long ulStatusValue );
\r
239 * Defines the 'check' functionality as described at the top of this file. This
\r
240 * function is the callback function for the 'check' timer. */
\r
241 static void vCheckTimerCallback( xTimerHandle xTimer );
\r
243 /*-----------------------------------------------------------*/
\r
245 /* Variables that are incremented on each iteration of the reg test tasks -
\r
246 provided the tasks have not reported any errors. The check task inspects these
\r
247 variables to ensure they are still incrementing as expected. If a variable
\r
248 stops incrementing then it is likely that its associate task has stalled. */
\r
249 volatile unsigned short usRegTest1Counter = 0, usRegTest2Counter = 0;
\r
251 /* The handle of the queue used to send messages from tasks and interrupts to
\r
253 static xQueueHandle xLCDQueue = NULL;
\r
255 /* The 'check' timer, as described at the top of this file. */
\r
256 static xTimerHandle xCheckTimer = NULL;
\r
258 /* The definition of each message sent from tasks and interrupts to the LCD
\r
262 char cMessageID; /* << States what the message is. */
\r
263 unsigned long ulMessageValue; /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID). */
\r
266 /*-----------------------------------------------------------*/
\r
270 /* Configure the peripherals used by this demo application. This includes
\r
271 configuring the joystick input select button to generate interrupts. */
\r
272 prvSetupHardware();
\r
274 /* Create the queue used by tasks and interrupts to send strings to the LCD
\r
276 xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );
\r
278 /* If the queue could not be created then don't create any tasks that might
\r
279 attempt to use the queue. */
\r
280 if( xLCDQueue != NULL )
\r
282 /* Create the standard demo tasks. */
\r
283 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
284 vStartDynamicPriorityTasks();
\r
285 vStartGenericQueueTasks( mainGENERIC_QUEUE_TEST_PRIORITY );
\r
286 vStartCountingSemaphoreTasks();
\r
288 /* Note that creating the timer test/demo tasks will fill the timer
\r
289 command queue. This is intentional, and forms part of the test the tasks
\r
290 perform. It does mean however that, after this function is called, no
\r
291 more timer commands can be sent until after the scheduler has been
\r
292 started (at which point the timer daemon will drained the timer command
\r
293 queue, freeing up space for more commands to be received). */
\r
294 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
296 /* Create the LCD, button poll and register test tasks, as described at
\r
297 the top of this file. */
\r
298 xTaskCreate( prvLCDTask, ( signed char * ) "LCD", configMINIMAL_STACK_SIZE * 2, mainTASK_PARAMETER_CHECK_VALUE, mainLCD_TASK_PRIORITY, NULL );
\r
299 xTaskCreate( prvButtonPollTask, ( signed char * ) "BPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
300 xTaskCreate( vRegTest1Task, ( signed char * ) "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
\r
301 xTaskCreate( vRegTest2Task, ( signed char * ) "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
\r
303 /* Create the 'check' timer - the timer that periodically calls the
\r
304 check function as described at the top of this file. Note that, for
\r
305 the reasons stated in the comments above the call to
\r
306 vStartTimerDemoTask(), that the check timer is not actually started
\r
307 until after the scheduler has been started. */
\r
308 xCheckTimer = xTimerCreate( ( const signed char * ) "Check timer", mainCHECK_TIMER_PERIOD, pdTRUE, ( void * ) 0, vCheckTimerCallback );
\r
310 /* Start the scheduler. */
\r
311 vTaskStartScheduler();
\r
314 /* If all is well then this line will never be reached. If it is reached
\r
315 then it is likely that there was insufficient (FreeRTOS) heap memory space
\r
316 to create the idle task. This may have been trapped by the malloc() failed
\r
317 hook function, if one is configured. */
\r
320 /*-----------------------------------------------------------*/
\r
322 static void prvLCDTask( void *pvParameters )
\r
324 xQueueMessage xReceivedMessage;
\r
326 /* Buffer into which strings are formatted and placed ready for display on the
\r
327 LCD. Note this is a static variable to prevent it being allocated on the task
\r
328 stack, which is too small to hold such a variable. The stack size is configured
\r
329 when the task is created. */
\r
330 static char cBuffer[ 50 ];
\r
331 unsigned char ucLine = 1;
\r
333 /* Now the scheduler has been started (it must have been for this task to
\r
334 be running), start the check timer too. The call to xTimerStart() will
\r
335 block until the command has been accepted. */
\r
336 if( xCheckTimer != NULL )
\r
338 xTimerStart( xCheckTimer, portMAX_DELAY );
\r
341 /* This is the only function that is permitted to access the LCD.
\r
343 First print out the number of bytes that remain in the FreeRTOS heap. This
\r
344 is done after a short delay to ensure all the demo tasks have created all
\r
345 the objects they are going to use. */
\r
346 vTaskDelay( mainTIMER_TEST_PERIOD * 10 );
\r
347 sprintf( cBuffer, "%d heap free", ( int ) xPortGetFreeHeapSize() );
\r
348 halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );
\r
351 /* Just as a test of the port, and for no functional reason, check the task
\r
352 parameter contains its expected value. */
\r
353 if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
\r
355 halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT );
\r
361 /* Wait for a message to be received. Using portMAX_DELAY as the block
\r
362 time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
\r
363 set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
\r
364 function return value and the function will only return when a value
\r
365 has been received. */
\r
366 xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );
\r
368 /* Clear the LCD if no room remains for any more text output. */
\r
369 if( ucLine > mainMAX_LCD_LINES )
\r
371 halLcdClearScreen();
\r
375 /* What is this message? What does it contain? */
\r
376 switch( xReceivedMessage.cMessageID )
\r
378 case mainMESSAGE_BUTTON_UP : /* The button poll task has just
\r
379 informed this task that the up
\r
380 button on the joystick input has
\r
381 been pressed or released. */
\r
382 sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
\r
385 case mainMESSAGE_BUTTON_SEL : /* The select button interrupt
\r
386 just informed this task that the
\r
387 select button has been pressed.
\r
388 In this case the pointer to the
\r
389 string to print is sent directly
\r
390 in the ulMessageValue member of
\r
391 the message. This just
\r
392 demonstrates a different
\r
393 communication technique. */
\r
394 sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
\r
397 case mainMESSAGE_STATUS : /* The tick interrupt hook
\r
398 function has just informed this
\r
399 task of the system status.
\r
400 Generate a string in accordance
\r
401 with the status value. */
\r
402 prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
\r
405 default : sprintf( cBuffer, "Unknown message" );
\r
409 /* Output the message that was placed into the cBuffer array within the
\r
410 switch statement above, then move onto the next line ready for the next
\r
411 message to arrive on the queue. */
\r
412 halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );
\r
416 /*-----------------------------------------------------------*/
\r
418 static void prvGenerateStatusMessage( char *pcBuffer, unsigned long ulStatusValue )
\r
420 /* Just a utility function to convert a status value into a meaningful
\r
421 string for output onto the LCD. */
\r
422 switch( ulStatusValue )
\r
424 case pdPASS : sprintf( pcBuffer, "Status = PASS" );
\r
426 case mainERROR_DYNAMIC_TASKS : sprintf( pcBuffer, "Err: Dynamic tsks" );
\r
428 case mainERROR_COM_TEST : sprintf( pcBuffer, "Err: COM test" );
\r
430 case mainERROR_GEN_QUEUE_TEST : sprintf( pcBuffer, "Error: Gen Q test" );
\r
432 case mainERROR_REG_TEST : sprintf( pcBuffer, "Error: Reg test" );
\r
434 case mainERROR_TIMER_TEST : sprintf( pcBuffer, "Error: Tmr test" );
\r
436 case mainERROR_COUNT_SEM_TEST : sprintf( pcBuffer, "Error: Count sem" );
\r
438 default : sprintf( pcBuffer, "Unknown status" );
\r
442 /*-----------------------------------------------------------*/
\r
444 static void prvButtonPollTask( void *pvParameters )
\r
446 unsigned char ucLastState = pdFALSE, ucState;
\r
447 xQueueMessage xMessage;
\r
449 /* This tasks performs the button polling functionality as described at the
\r
450 top of this file. */
\r
453 /* Check the button state. */
\r
454 ucState = ( halButtonsPressed() & BUTTON_UP );
\r
458 /* The button was pressed. */
\r
462 if( ucState != ucLastState )
\r
464 /* The state has changed, send a message to the LCD task. */
\r
465 xMessage.cMessageID = mainMESSAGE_BUTTON_UP;
\r
466 xMessage.ulMessageValue = ( unsigned long ) ucState;
\r
467 ucLastState = ucState;
\r
468 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
\r
471 /* Block for 10 milliseconds so this task does not utilise all the CPU
\r
472 time and debouncing of the button is not necessary. */
\r
473 vTaskDelay( 10 / portTICK_RATE_MS );
\r
476 /*-----------------------------------------------------------*/
\r
478 static void vCheckTimerCallback( xTimerHandle xTimer )
\r
480 static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;
\r
482 /* Define the status message that is sent to the LCD task. By default the
\r
484 static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };
\r
486 /* This is the callback function used by the 'check' timer, as described
\r
487 at the top of this file. */
\r
489 /* The parameter is not used. */
\r
492 /* See if the standard demo tasks are executing as expected, changing
\r
493 the message that is sent to the LCD task from PASS to an error code if
\r
494 any tasks set reports an error. */
\r
495 if( xAreComTestTasksStillRunning() != pdPASS )
\r
497 xStatusMessage.ulMessageValue = mainERROR_COM_TEST;
\r
500 if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
502 xStatusMessage.ulMessageValue = mainERROR_DYNAMIC_TASKS;
\r
505 if( xAreGenericQueueTasksStillRunning() != pdPASS )
\r
507 xStatusMessage.ulMessageValue = mainERROR_GEN_QUEUE_TEST;
\r
510 if( xAreCountingSemaphoreTasksStillRunning() != pdPASS )
\r
512 xStatusMessage.ulMessageValue = mainERROR_COUNT_SEM_TEST;
\r
515 if( xAreTimerDemoTasksStillRunning( ( portTickType ) mainCHECK_TIMER_PERIOD ) != pdPASS )
\r
517 xStatusMessage.ulMessageValue = mainERROR_TIMER_TEST;
\r
520 /* Check the reg test tasks are still cycling. They will stop
\r
521 incrementing their loop counters if they encounter an error. */
\r
522 if( usRegTest1Counter == usLastRegTest1Counter )
\r
524 xStatusMessage.ulMessageValue = mainERROR_REG_TEST;
\r
527 if( usRegTest2Counter == usLastRegTest2Counter )
\r
529 xStatusMessage.ulMessageValue = mainERROR_REG_TEST;
\r
532 usLastRegTest1Counter = usRegTest1Counter;
\r
533 usLastRegTest2Counter = usRegTest2Counter;
\r
535 /* This is called from a timer callback so must not block! */
\r
536 xQueueSendToBack( xLCDQueue, &xStatusMessage, mainDONT_BLOCK );
\r
538 /*-----------------------------------------------------------*/
\r
540 static void prvSetupHardware( void )
\r
542 taskDISABLE_INTERRUPTS();
\r
544 /* Disable the watchdog. */
\r
545 WDTCTL = WDTPW + WDTHOLD;
\r
549 LFXT_Start( XT1DRIVE_0 );
\r
550 hal430SetSystemClock( configCPU_CLOCK_HZ, configLFXT_CLOCK_HZ );
\r
552 halButtonsInit( BUTTON_ALL );
\r
553 halButtonsInterruptEnable( BUTTON_SELECT );
\r
555 /* Initialise the LCD, but note that the backlight is not used as the
\r
556 library function uses timer A0 to modulate the backlight, and this file
\r
557 defines vApplicationSetupTimerInterrupt() to also use timer A0 to generate
\r
558 the tick interrupt. If the backlight is required, then change either the
\r
559 halLCD library or vApplicationSetupTimerInterrupt() to use a different
\r
560 timer. Timer A1 is used for the run time stats time base6. */
\r
562 halLcdSetContrast( 100 );
\r
563 halLcdClearScreen();
\r
565 halLcdPrintLine( " www.FreeRTOS.org", 0, OVERWRITE_TEXT );
\r
567 /*-----------------------------------------------------------*/
\r
570 void vApplicationTickHook( void )
\r
572 static unsigned long ulCounter = 0;
\r
574 /* Is it time to toggle the LED again? */
\r
577 /* Just periodically toggle an LED to show that the tick interrupt is
\r
578 running. Note that this access LED_PORT_OUT in a non-atomic way, so tasks
\r
579 that access the same port must do so from a critical section. */
\r
580 if( ( ulCounter & 0xff ) == 0 )
\r
582 if( ( LED_PORT_OUT & LED_1 ) == 0 )
\r
584 LED_PORT_OUT |= LED_1;
\r
588 LED_PORT_OUT &= ~LED_1;
\r
592 /*-----------------------------------------------------------*/
\r
594 #pragma vector=PORT2_VECTOR
\r
595 interrupt void prvSelectButtonInterrupt( void )
\r
597 /* Define the message sent to the LCD task from this interrupt. */
\r
598 static const xQueueMessage xMessage = { mainMESSAGE_BUTTON_SEL, ( unsigned long ) "Select Interrupt" };
\r
599 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
601 /* This is the interrupt handler for the joystick select button input.
\r
602 The button has been pushed, write a message to the LCD via the LCD task. */
\r
603 xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
607 /* If writing to xLCDQueue caused a task to unblock, and the unblocked task
\r
608 has a priority equal to or above the task that this interrupt interrupted,
\r
609 then lHigherPriorityTaskWoken will have been set to pdTRUE internally within
\r
610 xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this
\r
611 interrupt returns directly to the higher priority unblocked task. */
\r
612 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
614 /*-----------------------------------------------------------*/
\r
616 /* The MSP430X port uses this callback function to configure its tick interrupt.
\r
617 This allows the application to choose the tick interrupt source.
\r
618 configTICK_VECTOR must also be set in FreeRTOSConfig.h to the correct
\r
619 interrupt vector for the chosen tick interrupt source. This implementation of
\r
620 vApplicationSetupTimerInterrupt() generates the tick from timer A0, so in this
\r
621 case configTICK_VECTOR is set to TIMER0_A0_VECTOR. */
\r
622 void vApplicationSetupTimerInterrupt( void )
\r
624 const unsigned short usACLK_Frequency_Hz = 32768;
\r
626 /* Ensure the timer is stopped. */
\r
629 /* Run the timer from the ACLK. */
\r
632 /* Clear everything to start with. */
\r
635 /* Set the compare match value according to the tick rate we want. */
\r
636 TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;
\r
638 /* Enable the interrupts. */
\r
641 /* Start up clean. */
\r
647 /*-----------------------------------------------------------*/
\r
649 void vApplicationIdleHook( void )
\r
651 /* Called on each iteration of the idle task. In this case the idle task
\r
652 just enters a low(ish) power mode. */
\r
653 __bis_SR_register( LPM1_bits + GIE );
\r
655 /*-----------------------------------------------------------*/
\r
657 void vApplicationMallocFailedHook( void )
\r
659 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
660 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
661 internally by FreeRTOS API functions that create tasks, queues or
\r
663 taskDISABLE_INTERRUPTS();
\r
666 /*-----------------------------------------------------------*/
\r
668 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
671 ( void ) pcTaskName;
\r
673 /* Run time stack overflow checking is performed if
\r
674 configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
675 function is called if a stack overflow is detected. */
\r
676 taskDISABLE_INTERRUPTS();
\r
679 /*-----------------------------------------------------------*/
\r