]> git.sur5r.net Git - freertos/blob - Demo/NEC_78K0R_IAR/ButtonTask.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / NEC_78K0R_IAR / ButtonTask.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     Free Software Foundation and modified by the FreeRTOS exception.\r
9     **NOTE** The exception to the GPL is included to allow you to distribute a\r
10     combined work that includes FreeRTOS without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /*\r
50  * This file defines the button push task and ISR as described at the top of\r
51  * main.c.  The ISR is called from a wrapper function defined in ButtonISR.s26.\r
52  */\r
53 \r
54 /* Kernel includes. */\r
55 #include "FreeRTOS.h"\r
56 #include "task.h"\r
57 #include "semphr.h"\r
58 \r
59 /* The LED output used by the button push task. */\r
60 #define butLED1   P7_bit.no7\r
61 \r
62 /* A short delay used for button debouncing. */\r
63 #define butDEBOUNCE_DELAY       ( 200 / portTICK_RATE_MS )\r
64 \r
65 /* The semaphore used to synchronise the button push task with the interrupt. */\r
66 static xSemaphoreHandle xButtonSemaphore;\r
67 \r
68 /*\r
69  * The definition of the button task itself.  See the comments at the top of\r
70  * main.c.\r
71  */\r
72 void vButtonTask( void *pvParameters )\r
73 {\r
74         /* Ensure the semaphore is created before it gets used. */\r
75         vSemaphoreCreateBinary( xButtonSemaphore );\r
76 \r
77         for( ;; )\r
78         {\r
79                 /* Block on the semaphore to wait for an interrupt event.  The semaphore\r
80                 is 'given' from vButtonISRHandler() below.  Using portMAX_DELAY as the\r
81                 block time will cause the task to block indefinitely provided\r
82                 INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. */\r
83                 xSemaphoreTake( xButtonSemaphore, portMAX_DELAY );\r
84 \r
85                 /* The button must have been pushed for this line to be executed.\r
86                 Simply toggle the LED. */\r
87                 butLED1 = !butLED1;\r
88                 \r
89                 /* Wait a short time then clear any pending button pushes as a crude\r
90                 method of debouncing the switch.  xSemaphoreTake() uses a block time of\r
91                 zero this time so it returns immediately rather than waiting for the\r
92                 interrupt to occur. */\r
93                 vTaskDelay( butDEBOUNCE_DELAY );\r
94                 xSemaphoreTake( xButtonSemaphore, 0 );\r
95         }\r
96 }\r
97 /*-----------------------------------------------------------*/\r
98 \r
99 /*\r
100  * The C portion of the interrupt handler.  Interrupts are triggered by pushing\r
101  * the button on the target board.  This interrupt can cause a context switch\r
102  * so has an assembly file wrapper defined within ButtonISR.s26.\r
103  */\r
104 void vButtonISRHandler( void )\r
105 {\r
106 short sHigherPriorityTaskWoken = pdFALSE;\r
107 \r
108         /* 'Give' the semaphore to unblock the button task. */\r
109         xSemaphoreGiveFromISR( xButtonSemaphore, &sHigherPriorityTaskWoken );\r
110         \r
111         /* If giving the semaphore unblocked a task, and the unblocked task has a\r
112         priority that is higher than the currently running task, then\r
113         sHigherPriorityTaskWoken will have been set to pdTRUE.  Passing a pdTRUE\r
114         value to portYIELD_FROM_ISR() will cause this interrupt to return directly\r
115         to the higher priority unblocked task. */\r
116         portYIELD_FROM_ISR( sHigherPriorityTaskWoken );\r
117 }\r
118 /*-----------------------------------------------------------*/\r