2 * FreeRTOS Kernel V10.1.1
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
6 * this software and associated documentation files (the "Software"), to deal in
7 * the Software without restriction, including without limitation the rights to
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 * the Software, and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in all
13 * copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 * http://www.FreeRTOS.org
23 * http://aws.amazon.com/freertos
29 * This file defines the button push task and ISR as described at the top of
30 * main.c. The ISR is called from a wrapper function defined in ButtonISR.s26.
33 /* Kernel includes. */
38 /* The LED output used by the button push task. */
39 #define butLED1 P7_bit.no7
41 /* A short delay used for button debouncing. */
42 #define butDEBOUNCE_DELAY ( 200 / portTICK_PERIOD_MS )
44 /* The semaphore used to synchronise the button push task with the interrupt. */
45 static SemaphoreHandle_t xButtonSemaphore;
48 * The definition of the button task itself. See the comments at the top of
51 void vButtonTask( void *pvParameters )
53 /* Ensure the semaphore is created before it gets used. */
54 vSemaphoreCreateBinary( xButtonSemaphore );
58 /* Block on the semaphore to wait for an interrupt event. The semaphore
59 is 'given' from vButtonISRHandler() below. Using portMAX_DELAY as the
60 block time will cause the task to block indefinitely provided
61 INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. */
62 xSemaphoreTake( xButtonSemaphore, portMAX_DELAY );
64 /* The button must have been pushed for this line to be executed.
65 Simply toggle the LED. */
68 /* Wait a short time then clear any pending button pushes as a crude
69 method of debouncing the switch. xSemaphoreTake() uses a block time of
70 zero this time so it returns immediately rather than waiting for the
71 interrupt to occur. */
72 vTaskDelay( butDEBOUNCE_DELAY );
73 xSemaphoreTake( xButtonSemaphore, 0 );
76 /*-----------------------------------------------------------*/
79 * The C portion of the interrupt handler. Interrupts are triggered by pushing
80 * the button on the target board. This interrupt can cause a context switch
81 * so has an assembly file wrapper defined within ButtonISR.s26.
83 void vButtonISRHandler( void )
85 short sHigherPriorityTaskWoken = pdFALSE;
87 /* 'Give' the semaphore to unblock the button task. */
88 xSemaphoreGiveFromISR( xButtonSemaphore, &sHigherPriorityTaskWoken );
90 /* If giving the semaphore unblocked a task, and the unblocked task has a
91 priority that is higher than the currently running task, then
92 sHigherPriorityTaskWoken will have been set to pdTRUE. Passing a pdTRUE
93 value to portYIELD_FROM_ISR() will cause this interrupt to return directly
94 to the higher priority unblocked task. */
95 portYIELD_FROM_ISR( sHigherPriorityTaskWoken );
97 /*-----------------------------------------------------------*/