2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
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
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
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\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
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
40 * In addition to the standard demo tasks, the following tasks, interrupts tests
\r
41 * and timers are defined and/or created within this file:
\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
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
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
63 * Button Interrupt - The select button on the joystick input device is
\r
64 * configured to generate an external interrupt. The handler for this interrupt
\r
65 * sends a message to LCD task, which then prints out a string to say the
\r
66 * joystick select button was pressed.
\r
68 * Idle Hook - The idle hook is a function that is called on each iteration of
\r
69 * the idle task. In this case it is used to place the processor into a low
\r
70 * power mode. Note however that this application is implemented using standard
\r
71 * components, and is therefore not optimised for low power operation. Lower
\r
72 * power consumption would be achieved by converting polling tasks into event
\r
73 * driven tasks, and slowing the tick interrupt frequency, etc.
\r
75 * "Check" callback function - Called each time the 'check' timer expires. The
\r
76 * check timer executes every five seconds. Its main function is to check that
\r
77 * all the standard demo tasks are still operational. Each time it executes it
\r
78 * sends a status code to the LCD task. The LCD task interprets the code and
\r
79 * displays an appropriate message - which will be PASS if no tasks have
\r
80 * reported any errors, or a message stating which task has reported an error.
\r
82 * "Reg test" tasks - These fill the registers with known values, then check
\r
83 * that each register still contains its expected value. Each task uses
\r
84 * different values. The tasks run with very low priority so get preempted
\r
85 * very frequently. A check variable is incremented on each iteration of the
\r
86 * test loop. A register containing an unexpected value is indicative of an
\r
87 * error in the context switching mechanism and will result in a branch to a
\r
88 * null loop - which in turn will prevent the check variable from incrementing
\r
89 * any further and allow the check timer callback (described a above) to
\r
90 * determine that an error has occurred. The nature of the reg test tasks
\r
91 * necessitates that they are written in assembly code.
\r
93 * Tick hook function - called inside the RTOS tick function, this simple
\r
94 * example does nothing but toggle an LED.
\r
96 * *NOTE 1* vApplicationSetupTimerInterrupt() is called by the kernel to let
\r
97 * the application set up a timer to generate the tick interrupt. In this
\r
98 * example a timer A0 is used for this purpose.
\r
102 /* Standard includes. */
\r
105 /* FreeRTOS includes. */
\r
106 #include "FreeRTOS.h"
\r
108 #include "timers.h"
\r
111 /* Hardware includes. */
\r
112 #include "msp430.h"
\r
113 #include "hal_MSP-EXP430F5438.h"
\r
115 /* Standard demo includes. */
\r
116 #include "ParTest.h"
\r
117 #include "dynamic.h"
\r
118 #include "comtest2.h"
\r
119 #include "GenQTest.h"
\r
120 #include "TimerDemo.h"
\r
121 #include "countsem.h"
\r
123 /* Codes sent within messages to the LCD task so the LCD task can interpret
\r
124 exactly what the message it just received was. These are sent in the
\r
125 cMessageID member of the message structure (defined below). */
\r
126 #define mainMESSAGE_BUTTON_UP ( 1 )
\r
127 #define mainMESSAGE_BUTTON_SEL ( 2 )
\r
128 #define mainMESSAGE_STATUS ( 3 )
\r
130 /* When the cMessageID member of the message sent to the LCD task is
\r
131 mainMESSAGE_STATUS then these definitions are sent in the ulMessageValue member
\r
132 of the same message and indicate what the status actually is. */
\r
133 #define mainERROR_DYNAMIC_TASKS ( pdPASS + 1 )
\r
134 #define mainERROR_COM_TEST ( pdPASS + 2 )
\r
135 #define mainERROR_GEN_QUEUE_TEST ( pdPASS + 3 )
\r
136 #define mainERROR_REG_TEST ( pdPASS + 4 )
\r
137 #define mainERROR_TIMER_TEST ( pdPASS + 5 )
\r
138 #define mainERROR_COUNT_SEM_TEST ( pdPASS + 6 )
\r
140 /* The length of the queue (the number of items the queue can hold) that is used
\r
141 to send messages from tasks and interrupts the the LCD task. */
\r
142 #define mainQUEUE_LENGTH ( 5 )
\r
144 /* Priorities used by the test and demo tasks. */
\r
145 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
146 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
147 #define mainGENERIC_QUEUE_TEST_PRIORITY ( tskIDLE_PRIORITY )
\r
149 /* The LED used by the comtest tasks. See the comtest.c file for more
\r
151 #define mainCOM_TEST_LED ( 1 )
\r
153 /* The baud rate used by the comtest tasks. */
\r
154 #define mainCOM_TEST_BAUD_RATE ( 38400 )
\r
156 /* The maximum number of lines of text that can be displayed on the LCD. */
\r
157 #define mainMAX_LCD_LINES ( 8 )
\r
159 /* Just used to ensure parameters are passed into tasks correctly. */
\r
160 #define mainTASK_PARAMETER_CHECK_VALUE ( ( void * ) 0xDEAD )
\r
162 /* The base period used by the timer test tasks. */
\r
163 #define mainTIMER_TEST_PERIOD ( 50 )
\r
165 /* The frequency at which the check timer (described in the comments at the top
\r
166 of this file) will call its callback function. */
\r
167 #define mainCHECK_TIMER_PERIOD ( 5000UL / ( unsigned long ) portTICK_PERIOD_MS )
\r
170 #define mainDONT_BLOCK ( 0 )
\r
171 /*-----------------------------------------------------------*/
\r
174 * The reg test tasks as described at the top of this file.
\r
176 extern void vRegTest1Task( void *pvParameters );
\r
177 extern void vRegTest2Task( void *pvParameters );
\r
180 * Configures clocks, LCD, port pints, etc. necessary to execute this demo.
\r
182 static void prvSetupHardware( void );
\r
185 * Definition of the LCD/controller task described in the comments at the top
\r
188 static void prvLCDTask( void *pvParameters );
\r
191 * Definition of the button poll task described in the comments at the top of
\r
194 static void prvButtonPollTask( void *pvParameters );
\r
197 * Converts a status message value into an appropriate string for display on
\r
198 * the LCD. The string is written to pcBuffer.
\r
200 static void prvGenerateStatusMessage( char *pcBuffer, unsigned long ulStatusValue );
\r
203 * Defines the 'check' functionality as described at the top of this file. This
\r
204 * function is the callback function for the 'check' timer. */
\r
205 static void vCheckTimerCallback( TimerHandle_t xTimer );
\r
207 /*-----------------------------------------------------------*/
\r
209 /* Variables that are incremented on each iteration of the reg test tasks -
\r
210 provided the tasks have not reported any errors. The check task inspects these
\r
211 variables to ensure they are still incrementing as expected. If a variable
\r
212 stops incrementing then it is likely that its associate task has stalled. */
\r
213 volatile unsigned short usRegTest1Counter = 0, usRegTest2Counter = 0;
\r
215 /* The handle of the queue used to send messages from tasks and interrupts to
\r
217 static QueueHandle_t xLCDQueue = NULL;
\r
219 /* The 'check' timer, as described at the top of this file. */
\r
220 static TimerHandle_t xCheckTimer = NULL;
\r
222 /* The definition of each message sent from tasks and interrupts to the LCD
\r
226 char cMessageID; /* << States what the message is. */
\r
227 unsigned long ulMessageValue; /* << States the message value (can be an integer, string pointer, etc. depending on the value of cMessageID). */
\r
230 /*-----------------------------------------------------------*/
\r
234 /* Configure the peripherals used by this demo application. This includes
\r
235 configuring the joystick input select button to generate interrupts. */
\r
236 prvSetupHardware();
\r
238 /* Create the queue used by tasks and interrupts to send strings to the LCD
\r
240 xLCDQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( xQueueMessage ) );
\r
242 /* If the queue could not be created then don't create any tasks that might
\r
243 attempt to use the queue. */
\r
244 if( xLCDQueue != NULL )
\r
246 /* Create the standard demo tasks. */
\r
247 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
248 vStartDynamicPriorityTasks();
\r
249 vStartGenericQueueTasks( mainGENERIC_QUEUE_TEST_PRIORITY );
\r
250 vStartCountingSemaphoreTasks();
\r
252 /* Note that creating the timer test/demo tasks will fill the timer
\r
253 command queue. This is intentional, and forms part of the test the tasks
\r
254 perform. It does mean however that, after this function is called, no
\r
255 more timer commands can be sent until after the scheduler has been
\r
256 started (at which point the timer daemon will drained the timer command
\r
257 queue, freeing up space for more commands to be received). */
\r
258 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
260 /* Create the LCD, button poll and register test tasks, as described at
\r
261 the top of this file. */
\r
262 xTaskCreate( prvLCDTask, "LCD", configMINIMAL_STACK_SIZE * 2, mainTASK_PARAMETER_CHECK_VALUE, mainLCD_TASK_PRIORITY, NULL );
\r
263 xTaskCreate( prvButtonPollTask, "BPoll", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
264 xTaskCreate( vRegTest1Task, "Reg1", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
\r
265 xTaskCreate( vRegTest2Task, "Reg2", configMINIMAL_STACK_SIZE, NULL, 0, NULL );
\r
267 /* Create the 'check' timer - the timer that periodically calls the
\r
268 check function as described at the top of this file. Note that, for
\r
269 the reasons stated in the comments above the call to
\r
270 vStartTimerDemoTask(), that the check timer is not actually started
\r
271 until after the scheduler has been started. */
\r
272 xCheckTimer = xTimerCreate( "Check timer", mainCHECK_TIMER_PERIOD, pdTRUE, ( void * ) 0, vCheckTimerCallback );
\r
274 /* Start the scheduler. */
\r
275 vTaskStartScheduler();
\r
278 /* If all is well then this line will never be reached. If it is reached
\r
279 then it is likely that there was insufficient (FreeRTOS) heap memory space
\r
280 to create the idle task. This may have been trapped by the malloc() failed
\r
281 hook function, if one is configured. */
\r
284 /*-----------------------------------------------------------*/
\r
286 static void prvLCDTask( void *pvParameters )
\r
288 xQueueMessage xReceivedMessage;
\r
290 /* Buffer into which strings are formatted and placed ready for display on the
\r
291 LCD. Note this is a static variable to prevent it being allocated on the task
\r
292 stack, which is too small to hold such a variable. The stack size is configured
\r
293 when the task is created. */
\r
294 static char cBuffer[ 50 ];
\r
295 unsigned char ucLine = 1;
\r
297 /* Now the scheduler has been started (it must have been for this task to
\r
298 be running), start the check timer too. The call to xTimerStart() will
\r
299 block until the command has been accepted. */
\r
300 if( xCheckTimer != NULL )
\r
302 xTimerStart( xCheckTimer, portMAX_DELAY );
\r
305 /* This is the only function that is permitted to access the LCD.
\r
307 First print out the number of bytes that remain in the FreeRTOS heap. This
\r
308 is done after a short delay to ensure all the demo tasks have created all
\r
309 the objects they are going to use. */
\r
310 vTaskDelay( mainTIMER_TEST_PERIOD * 10 );
\r
311 sprintf( cBuffer, "%d heap free", ( int ) xPortGetFreeHeapSize() );
\r
312 halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );
\r
315 /* Just as a test of the port, and for no functional reason, check the task
\r
316 parameter contains its expected value. */
\r
317 if( pvParameters != mainTASK_PARAMETER_CHECK_VALUE )
\r
319 halLcdPrintLine( "Invalid parameter", ucLine, OVERWRITE_TEXT );
\r
325 /* Wait for a message to be received. Using portMAX_DELAY as the block
\r
326 time will result in an indefinite wait provided INCLUDE_vTaskSuspend is
\r
327 set to 1 in FreeRTOSConfig.h, therefore there is no need to check the
\r
328 function return value and the function will only return when a value
\r
329 has been received. */
\r
330 xQueueReceive( xLCDQueue, &xReceivedMessage, portMAX_DELAY );
\r
332 /* Clear the LCD if no room remains for any more text output. */
\r
333 if( ucLine > mainMAX_LCD_LINES )
\r
335 halLcdClearScreen();
\r
339 /* What is this message? What does it contain? */
\r
340 switch( xReceivedMessage.cMessageID )
\r
342 case mainMESSAGE_BUTTON_UP : /* The button poll task has just
\r
343 informed this task that the up
\r
344 button on the joystick input has
\r
345 been pressed or released. */
\r
346 sprintf( cBuffer, "Button up = %d", ( int ) xReceivedMessage.ulMessageValue );
\r
349 case mainMESSAGE_BUTTON_SEL : /* The select button interrupt
\r
350 just informed this task that the
\r
351 select button has been pressed.
\r
352 In this case the pointer to the
\r
353 string to print is sent directly
\r
354 in the ulMessageValue member of
\r
355 the message. This just
\r
356 demonstrates a different
\r
357 communication technique. */
\r
358 sprintf( cBuffer, "%s", ( char * ) xReceivedMessage.ulMessageValue );
\r
361 case mainMESSAGE_STATUS : /* The tick interrupt hook
\r
362 function has just informed this
\r
363 task of the system status.
\r
364 Generate a string in accordance
\r
365 with the status value. */
\r
366 prvGenerateStatusMessage( cBuffer, xReceivedMessage.ulMessageValue );
\r
369 default : sprintf( cBuffer, "Unknown message" );
\r
373 /* Output the message that was placed into the cBuffer array within the
\r
374 switch statement above, then move onto the next line ready for the next
\r
375 message to arrive on the queue. */
\r
376 halLcdPrintLine( cBuffer, ucLine, OVERWRITE_TEXT );
\r
380 /*-----------------------------------------------------------*/
\r
382 static void prvGenerateStatusMessage( char *pcBuffer, unsigned long ulStatusValue )
\r
384 /* Just a utility function to convert a status value into a meaningful
\r
385 string for output onto the LCD. */
\r
386 switch( ulStatusValue )
\r
388 case pdPASS : sprintf( pcBuffer, "Status = PASS" );
\r
390 case mainERROR_DYNAMIC_TASKS : sprintf( pcBuffer, "Err: Dynamic tsks" );
\r
392 case mainERROR_COM_TEST : sprintf( pcBuffer, "Err: COM test" );
\r
394 case mainERROR_GEN_QUEUE_TEST : sprintf( pcBuffer, "Error: Gen Q test" );
\r
396 case mainERROR_REG_TEST : sprintf( pcBuffer, "Error: Reg test" );
\r
398 case mainERROR_TIMER_TEST : sprintf( pcBuffer, "Error: Tmr test" );
\r
400 case mainERROR_COUNT_SEM_TEST : sprintf( pcBuffer, "Error: Count sem" );
\r
402 default : sprintf( pcBuffer, "Unknown status" );
\r
406 /*-----------------------------------------------------------*/
\r
408 static void prvButtonPollTask( void *pvParameters )
\r
410 unsigned char ucLastState = pdFALSE, ucState;
\r
411 xQueueMessage xMessage;
\r
413 /* This tasks performs the button polling functionality as described at the
\r
414 top of this file. */
\r
417 /* Check the button state. */
\r
418 ucState = ( halButtonsPressed() & BUTTON_UP );
\r
422 /* The button was pressed. */
\r
426 if( ucState != ucLastState )
\r
428 /* The state has changed, send a message to the LCD task. */
\r
429 xMessage.cMessageID = mainMESSAGE_BUTTON_UP;
\r
430 xMessage.ulMessageValue = ( unsigned long ) ucState;
\r
431 ucLastState = ucState;
\r
432 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
\r
435 /* Block for 10 milliseconds so this task does not utilise all the CPU
\r
436 time and debouncing of the button is not necessary. */
\r
437 vTaskDelay( 10 / portTICK_PERIOD_MS );
\r
440 /*-----------------------------------------------------------*/
\r
442 static void vCheckTimerCallback( TimerHandle_t xTimer )
\r
444 static unsigned short usLastRegTest1Counter = 0, usLastRegTest2Counter = 0;
\r
446 /* Define the status message that is sent to the LCD task. By default the
\r
448 static xQueueMessage xStatusMessage = { mainMESSAGE_STATUS, pdPASS };
\r
450 /* This is the callback function used by the 'check' timer, as described
\r
451 at the top of this file. */
\r
453 /* The parameter is not used. */
\r
456 /* See if the standard demo tasks are executing as expected, changing
\r
457 the message that is sent to the LCD task from PASS to an error code if
\r
458 any tasks set reports an error. */
\r
459 if( xAreComTestTasksStillRunning() != pdPASS )
\r
461 xStatusMessage.ulMessageValue = mainERROR_COM_TEST;
\r
464 if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
466 xStatusMessage.ulMessageValue = mainERROR_DYNAMIC_TASKS;
\r
469 if( xAreGenericQueueTasksStillRunning() != pdPASS )
\r
471 xStatusMessage.ulMessageValue = mainERROR_GEN_QUEUE_TEST;
\r
474 if( xAreCountingSemaphoreTasksStillRunning() != pdPASS )
\r
476 xStatusMessage.ulMessageValue = mainERROR_COUNT_SEM_TEST;
\r
479 if( xAreTimerDemoTasksStillRunning( ( TickType_t ) mainCHECK_TIMER_PERIOD ) != pdPASS )
\r
481 xStatusMessage.ulMessageValue = mainERROR_TIMER_TEST;
\r
484 /* Check the reg test tasks are still cycling. They will stop
\r
485 incrementing their loop counters if they encounter an error. */
\r
486 if( usRegTest1Counter == usLastRegTest1Counter )
\r
488 xStatusMessage.ulMessageValue = mainERROR_REG_TEST;
\r
491 if( usRegTest2Counter == usLastRegTest2Counter )
\r
493 xStatusMessage.ulMessageValue = mainERROR_REG_TEST;
\r
496 usLastRegTest1Counter = usRegTest1Counter;
\r
497 usLastRegTest2Counter = usRegTest2Counter;
\r
499 /* This is called from a timer callback so must not block! */
\r
500 xQueueSendToBack( xLCDQueue, &xStatusMessage, mainDONT_BLOCK );
\r
502 /*-----------------------------------------------------------*/
\r
504 static void prvSetupHardware( void )
\r
506 taskDISABLE_INTERRUPTS();
\r
508 /* Disable the watchdog. */
\r
509 WDTCTL = WDTPW + WDTHOLD;
\r
513 LFXT_Start( XT1DRIVE_0 );
\r
514 hal430SetSystemClock( configCPU_CLOCK_HZ, configLFXT_CLOCK_HZ );
\r
516 halButtonsInit( BUTTON_ALL );
\r
517 halButtonsInterruptEnable( BUTTON_SELECT );
\r
519 /* Initialise the LCD, but note that the backlight is not used as the
\r
520 library function uses timer A0 to modulate the backlight, and this file
\r
521 defines vApplicationSetupTimerInterrupt() to also use timer A0 to generate
\r
522 the tick interrupt. If the backlight is required, then change either the
\r
523 halLCD library or vApplicationSetupTimerInterrupt() to use a different
\r
524 timer. Timer A1 is used for the run time stats time base6. */
\r
526 halLcdSetContrast( 100 );
\r
527 halLcdClearScreen();
\r
529 halLcdPrintLine( " www.FreeRTOS.org", 0, OVERWRITE_TEXT );
\r
531 /*-----------------------------------------------------------*/
\r
534 void vApplicationTickHook( void )
\r
536 static unsigned long ulCounter = 0;
\r
538 /* Is it time to toggle the LED again? */
\r
541 /* Just periodically toggle an LED to show that the tick interrupt is
\r
542 running. Note that this access LED_PORT_OUT in a non-atomic way, so tasks
\r
543 that access the same port must do so from a critical section. */
\r
544 if( ( ulCounter & 0xff ) == 0 )
\r
546 if( ( LED_PORT_OUT & LED_1 ) == 0 )
\r
548 LED_PORT_OUT |= LED_1;
\r
552 LED_PORT_OUT &= ~LED_1;
\r
556 /*-----------------------------------------------------------*/
\r
558 #pragma vector=PORT2_VECTOR
\r
559 interrupt void prvSelectButtonInterrupt( void )
\r
561 /* Define the message sent to the LCD task from this interrupt. */
\r
562 static const xQueueMessage xMessage = { mainMESSAGE_BUTTON_SEL, ( unsigned long ) "Select Interrupt" };
\r
563 portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
565 /* This is the interrupt handler for the joystick select button input.
\r
566 The button has been pushed, write a message to the LCD via the LCD task. */
\r
567 xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
571 /* If writing to xLCDQueue caused a task to unblock, and the unblocked task
\r
572 has a priority equal to or above the task that this interrupt interrupted,
\r
573 then lHigherPriorityTaskWoken will have been set to pdTRUE internally within
\r
574 xQueuesendFromISR(), and portEND_SWITCHING_ISR() will ensure that this
\r
575 interrupt returns directly to the higher priority unblocked task. */
\r
576 portYIELD_FROM_ISR( xHigherPriorityTaskWoken );
\r
578 /*-----------------------------------------------------------*/
\r
580 /* The MSP430X port uses this callback function to configure its tick interrupt.
\r
581 This allows the application to choose the tick interrupt source.
\r
582 configTICK_VECTOR must also be set in FreeRTOSConfig.h to the correct
\r
583 interrupt vector for the chosen tick interrupt source. This implementation of
\r
584 vApplicationSetupTimerInterrupt() generates the tick from timer A0, so in this
\r
585 case configTICK_VECTOR is set to TIMER0_A0_VECTOR. */
\r
586 void vApplicationSetupTimerInterrupt( void )
\r
588 const unsigned short usACLK_Frequency_Hz = 32768;
\r
590 /* Ensure the timer is stopped. */
\r
593 /* Run the timer from the ACLK. */
\r
596 /* Clear everything to start with. */
\r
599 /* Set the compare match value according to the tick rate we want. */
\r
600 TA0CCR0 = usACLK_Frequency_Hz / configTICK_RATE_HZ;
\r
602 /* Enable the interrupts. */
\r
605 /* Start up clean. */
\r
611 /*-----------------------------------------------------------*/
\r
613 void vApplicationIdleHook( void )
\r
615 /* Called on each iteration of the idle task. In this case the idle task
\r
616 just enters a low(ish) power mode. */
\r
617 __bis_SR_register( LPM1_bits + GIE );
\r
619 /*-----------------------------------------------------------*/
\r
621 void vApplicationMallocFailedHook( void )
\r
623 /* Called if a call to pvPortMalloc() fails because there is insufficient
\r
624 free memory available in the FreeRTOS heap. pvPortMalloc() is called
\r
625 internally by FreeRTOS API functions that create tasks, queues or
\r
627 taskDISABLE_INTERRUPTS();
\r
630 /*-----------------------------------------------------------*/
\r
632 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
635 ( void ) pcTaskName;
\r
637 /* Run time stack overflow checking is performed if
\r
638 configconfigCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
639 function is called if a stack overflow is detected. */
\r
640 taskDISABLE_INTERRUPTS();
\r
643 /*-----------------------------------------------------------*/
\r