]> begriffs open source - cmsis-freertos/blob - Demo/CORTEX_A2F200_SoftConsole/ParTest.c
osEventFlagsWait: Fix flag comparison
[cmsis-freertos] / Demo / CORTEX_A2F200_SoftConsole / ParTest.c
1 /*
2  * FreeRTOS Kernel V10.2.1
3  * Copyright (C) 2019 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  * Simple parallel port IO routines.
30  *-----------------------------------------------------------*/
31
32 /* Kernel includes. */
33 #include "FreeRTOS.h"
34 #include "task.h"
35
36 /* Library includes. */
37 #include "mss_gpio.h"
38
39 #define partstMAX_LEDS          8
40
41 static volatile unsigned long ulGPIOState = 0UL;
42
43 /*-----------------------------------------------------------*/
44
45 void vParTestInitialise( void )
46 {
47 long x;
48
49         /* Initialise the GPIO */
50         MSS_GPIO_init();
51
52         /* Set up GPIO for the LEDs. */
53         for( x = 0; x < partstMAX_LEDS; x++ )
54         {
55                 MSS_GPIO_config( ( mss_gpio_id_t ) x , MSS_GPIO_OUTPUT_MODE );
56         }
57
58         /* All LEDs start off. */
59         ulGPIOState = 0xffffffffUL;
60         MSS_GPIO_set_outputs( ulGPIOState );
61 }
62 /*-----------------------------------------------------------*/
63
64 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
65 {
66         if( uxLED < partstMAX_LEDS )
67         {
68                 /* A critical section is used as the LEDs are also accessed from an
69                 interrupt. */
70                 taskENTER_CRITICAL();
71                 {
72                         if( xValue == pdTRUE )
73                         {
74                                 ulGPIOState &= ~( 1UL << uxLED );
75                         }
76                         else
77                         {
78                                 ulGPIOState |= ( 1UL << uxLED );
79                         }
80                         
81                         MSS_GPIO_set_outputs( ulGPIOState );
82                 }
83                 taskEXIT_CRITICAL();
84         }
85 }
86 /*-----------------------------------------------------------*/
87
88 void vParTestSetLEDFromISR( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
89 {
90 unsigned portBASE_TYPE uxInterruptFlags;
91
92         uxInterruptFlags = portSET_INTERRUPT_MASK_FROM_ISR();
93         {
94                 if( uxLED < partstMAX_LEDS )
95                 {
96                         if( xValue == pdTRUE )
97                         {
98                                 ulGPIOState &= ~( 1UL << uxLED );
99                         }
100                         else
101                         {
102                                 ulGPIOState |= ( 1UL << uxLED );
103                         }
104
105                         MSS_GPIO_set_outputs( ulGPIOState );
106                 }
107         }
108         portCLEAR_INTERRUPT_MASK_FROM_ISR( uxInterruptFlags );
109 }
110 /*-----------------------------------------------------------*/
111
112 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
113 {
114         if( uxLED < partstMAX_LEDS )
115         {
116                 /* A critical section is used as the LEDs are also accessed from an
117                 interrupt. */
118                 taskENTER_CRITICAL();
119                 {
120                         if( ( ulGPIOState & ( 1UL << uxLED ) ) != 0UL )
121                         {
122                                 ulGPIOState &= ~( 1UL << uxLED );
123                         }
124                         else
125                         {
126                                 ulGPIOState |= ( 1UL << uxLED );
127                         }
128                         
129                         MSS_GPIO_set_outputs( ulGPIOState );
130                 }
131                 taskEXIT_CRITICAL();
132         }
133 }
134 /*-----------------------------------------------------------*/
135
136 long lParTestGetLEDState( unsigned long ulLED )
137 {
138 long lReturn = pdFALSE;
139
140         if( ulLED < partstMAX_LEDS )
141         {
142                 taskENTER_CRITICAL();
143                 {
144                         if( ( ulGPIOState & ( 1UL << ulLED ) ) == 0UL )
145                         {
146                                 lReturn = pdTRUE;
147                         }
148                 }
149                 taskEXIT_CRITICAL();
150         }
151
152         return lReturn;
153 }
154 /*-----------------------------------------------------------*/