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 * This file defines the button push task and ISR as described at the top of
\r
31 * main.c. The ISR is called from a wrapper function defined in ButtonISR.s26.
\r
34 /* Kernel includes. */
\r
35 #include "FreeRTOS.h"
\r
39 /* The LED output used by the button push task. */
\r
40 #define butLED1 P7_bit.no7
\r
42 /* A short delay used for button debouncing. */
\r
43 #define butDEBOUNCE_DELAY ( 200 / portTICK_PERIOD_MS )
\r
45 /* The semaphore used to synchronise the button push task with the interrupt. */
\r
46 static SemaphoreHandle_t xButtonSemaphore;
\r
49 * The definition of the button task itself. See the comments at the top of
\r
52 void vButtonTask( void *pvParameters )
\r
54 /* Ensure the semaphore is created before it gets used. */
\r
55 vSemaphoreCreateBinary( xButtonSemaphore );
\r
59 /* Block on the semaphore to wait for an interrupt event. The semaphore
\r
60 is 'given' from vButtonISRHandler() below. Using portMAX_DELAY as the
\r
61 block time will cause the task to block indefinitely provided
\r
62 INCLUDE_vTaskSuspend is set to 1 in FreeRTOSConfig.h. */
\r
63 xSemaphoreTake( xButtonSemaphore, portMAX_DELAY );
\r
65 /* The button must have been pushed for this line to be executed.
\r
66 Simply toggle the LED. */
\r
69 /* Wait a short time then clear any pending button pushes as a crude
\r
70 method of debouncing the switch. xSemaphoreTake() uses a block time of
\r
71 zero this time so it returns immediately rather than waiting for the
\r
72 interrupt to occur. */
\r
73 vTaskDelay( butDEBOUNCE_DELAY );
\r
74 xSemaphoreTake( xButtonSemaphore, 0 );
\r
77 /*-----------------------------------------------------------*/
\r
80 * The C portion of the interrupt handler. Interrupts are triggered by pushing
\r
81 * the button on the target board. This interrupt can cause a context switch
\r
82 * so has an assembly file wrapper defined within ButtonISR.s26.
\r
84 void vButtonISRHandler( void )
\r
86 short sHigherPriorityTaskWoken = pdFALSE;
\r
88 /* 'Give' the semaphore to unblock the button task. */
\r
89 xSemaphoreGiveFromISR( xButtonSemaphore, &sHigherPriorityTaskWoken );
\r
91 /* If giving the semaphore unblocked a task, and the unblocked task has a
\r
92 priority that is higher than the currently running task, then
\r
93 sHigherPriorityTaskWoken will have been set to pdTRUE. Passing a pdTRUE
\r
94 value to portYIELD_FROM_ISR() will cause this interrupt to return directly
\r
95 to the higher priority unblocked task. */
\r
96 portYIELD_FROM_ISR( sHigherPriorityTaskWoken );
\r
98 /*-----------------------------------------------------------*/
\r