2 FreeRTOS.org V5.1.1 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
27 ***************************************************************************
\r
29 * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *
\r
30 * and even write all or part of your application on your behalf. *
\r
31 * See http://www.OpenRTOS.com for details of the services we provide to *
\r
32 * expedite your project. *
\r
34 ***************************************************************************
\r
35 ***************************************************************************
\r
37 Please ensure to read the configuration and relevant port sections of the
\r
38 online documentation.
\r
40 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
43 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
46 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
47 licensing and training services.
\r
51 * This file defines the button push task and ISR as described at the top of
\r
52 * main.c. The ISR is called from a wrapper function defined in ButtonISR.s26.
\r
55 /* Kernel includes. */
\r
56 #include "FreeRTOS.h"
\r
60 /* The LED output used by the button push task. */
\r
61 #define butLED1 P7_bit.no7
\r
63 /* A short delay used for button debouncing. */
\r
64 #define butDEBOUNCE_DELAY ( 200 / portTICK_RATE_MS )
\r
66 /* The semaphore used to synchronise the button push task with the interrupt. */
\r
67 static xSemaphoreHandle xButtonSemaphore;
\r
70 * The definition of the button task itself. See the comments at the top of
\r
73 void vButtonTask( void *pvParameters )
\r
75 /* Ensure the semaphore is created before it gets used. */
\r
76 vSemaphoreCreateBinary( xButtonSemaphore );
\r
80 /* Block on the semaphore to wait for an interrupt event. The semaphore
\r
81 is 'given' from vButtonISRHandler() below. Using portMAX_DELAY as the
\r
82 block time will cause the task to block indefinitely provided
\r
83 INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. */
\r
84 xSemaphoreTake( xButtonSemaphore, portMAX_DELAY );
\r
86 /* The button must have been pushed for this line to be executed.
\r
87 Simply toggle the LED. */
\r
90 /* Wait a short time then clear any pending button pushes as a crude
\r
91 method of debouncing the switch. xSemaphoreTake() uses a block time of
\r
92 zero this time so it returns immediately rather than waiting for the
\r
93 interrupt to occur. */
\r
94 vTaskDelay( butDEBOUNCE_DELAY );
\r
95 xSemaphoreTake( xButtonSemaphore, 0 );
\r
98 /*-----------------------------------------------------------*/
\r
101 * The C portion of the interrupt handler. Interrupts are triggered by pushing
\r
102 * the button on the target board. This interrupt can cause a context switch
\r
103 * so has an assembly file wrapper defined within ButtonISR.s26.
\r
105 void vButtonISRHandler( void )
\r
107 short sHigherPriorityTaskWoken = pdFALSE;
\r
109 /* 'Give' the semaphore to unblock the button task. */
\r
110 xSemaphoreGiveFromISR( xButtonSemaphore, &sHigherPriorityTaskWoken );
\r
112 /* If giving the semaphore unblocked a task, and the unblocked task has a
\r
113 priority that is higher than the currently running task, then
\r
114 sHigherPriorityTaskWoken will have been set to pdTRUE. Passing a pdTRUE
\r
115 value to portYIELD_FROM_ISR() will cause this interrupt to return directly
\r
116 to the higher priority unblocked task. */
\r
117 portYIELD_FROM_ISR( sHigherPriorityTaskWoken );
\r
119 /*-----------------------------------------------------------*/
\r