]> begriffs open source - cmsis-freertos/blob - Demo/MicroBlaze_Kintex7_EthernetLite/RTOSDemo/src/LEDs.c
Merge branch 'develop'
[cmsis-freertos] / Demo / MicroBlaze_Kintex7_EthernetLite / RTOSDemo / src / LEDs.c
1 /*
2  * FreeRTOS V202111.00
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
4  *
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:
11  *
12  * The above copyright notice and this permission notice shall be included in all
13  * copies or substantial portions of the Software.
14  *
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.
21  *
22  * http://www.FreeRTOS.org
23  * http://aws.amazon.com/freertos
24  *
25  * 1 tab == 4 spaces!
26  */
27
28
29 /*-----------------------------------------------------------
30  * Simple IO routines to control the LEDs.
31  *-----------------------------------------------------------*/
32
33 /* Scheduler includes. */
34 #include "FreeRTOS.h"
35 #include "task.h"
36
37 /* Demo includes. */
38 #include "partest.h"
39
40 /* Xilinx includes. */
41 #include "xgpio.h"
42
43
44 #define partstNUM_LEDS  8
45
46 /*-----------------------------------------------------------*/
47
48 /* The GPIO instance to which the LEDs are connected. */
49 static XGpio xOutputGPIOInstance;
50
51 /* Maintains the current LED output state. */
52 static volatile UBaseType_t uxGPIOState = 0U;
53
54 /* Constant required by the Xilinx peripheral driver API functions that are
55 relevant to the particular hardware set up. */
56 static const unsigned long ulGPIOOutputChannel = 1UL;
57
58 /*-----------------------------------------------------------*/
59
60 void vParTestInitialise( void )
61 {
62 portBASE_TYPE xStatus;
63 const unsigned char ucSetToOutput = 0U;
64
65         /* Initialize the GPIO for the LEDs. */
66         xStatus = XGpio_Initialize( &xOutputGPIOInstance, XPAR_AXI_GPIO_0_DEVICE_ID );
67         if( xStatus == XST_SUCCESS )
68         {
69                 /* All bits on this channel are going to be outputs (LEDs). */
70                 XGpio_SetDataDirection( &xOutputGPIOInstance, ulGPIOOutputChannel, ucSetToOutput );
71
72                 /* Start with all LEDs off. */
73                 uxGPIOState = 0U;
74                 XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ( uint8_t ) uxGPIOState );
75         }
76
77         configASSERT( ( xStatus == XST_SUCCESS ) );
78 }
79 /*-----------------------------------------------------------*/
80
81 void vParTestSetLED( UBaseType_t uxLED, BaseType_t xValue )
82 {
83         if( uxLED < partstNUM_LEDS )
84         {
85                 taskENTER_CRITICAL();
86                 {
87                         if( xValue != pdFALSE )
88                         {
89                                 uxGPIOState |= ( 1UL << uxLED );
90                         }
91                         else
92                         {
93                                 uxGPIOState &= ~( 1UL << uxLED );
94                         }
95
96                         XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ( uint8_t ) uxGPIOState );
97                 }
98                 taskEXIT_CRITICAL();
99         }
100 }
101 /*-----------------------------------------------------------*/
102
103 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
104 {
105         if( uxLED < partstNUM_LEDS )
106         {
107                 taskENTER_CRITICAL();
108                 {
109                         uxGPIOState ^= ( 1UL << uxLED );
110                         XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ( uint8_t ) uxGPIOState );
111                 }
112                 taskEXIT_CRITICAL();
113         }
114 }
115