]> begriffs open source - cmsis-freertos/blob - Demo/RX600_RX64M_RSK_GCC_e2studio/src/ParTest.c
Update README.md - branch main is now the base branch
[cmsis-freertos] / Demo / RX600_RX64M_RSK_GCC_e2studio / src / ParTest.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  * Simple IO routines to control the LEDs.
30  *-----------------------------------------------------------*/
31
32 /* Scheduler includes. */
33 #include "FreeRTOS.h"
34 #include "task.h"
35
36 /* Demo includes. */
37 #include "partest.h"
38
39 /* Hardware specifics. */
40 #include "iodefine.h"
41 #include "rskrx64mdef.h"
42
43 #define partestNUM_LEDS ( 4 )
44
45 long lParTestGetLEDState( unsigned long ulLED );
46
47 /*-----------------------------------------------------------*/
48
49 void vParTestInitialise( void )
50 {
51         /* First set the data levels. */
52         LED0 = LED_OFF;
53         LED1 = LED_OFF;
54         LED2 = LED_OFF;
55         LED3 = LED_OFF;
56
57         /* Set port direction registers. */
58         LED0_PIN_DIR = OUTPUT_PIN;
59         LED1_PIN_DIR = OUTPUT_PIN;
60         LED2_PIN_DIR = OUTPUT_PIN;
61         LED3_PIN_DIR = OUTPUT_PIN;
62 }
63 /*-----------------------------------------------------------*/
64
65 void vParTestSetLED( unsigned long ulLED, signed long xValue )
66 {
67         if( ulLED < partestNUM_LEDS )
68         {
69                 if( xValue != 0 )
70                 {
71                         /* Turn the LED on. */
72                         taskENTER_CRITICAL();
73                         {
74                                 switch( ulLED )
75                                 {
76                                         case 0: LED0 = LED_ON;
77                                                         break;
78                                         case 1: LED1 = LED_ON;
79                                                         break;
80                                         case 2: LED2 = LED_ON;
81                                                         break;
82                                         case 3: LED3 = LED_ON;
83                                                         break;
84                                 }
85                         }
86                         taskEXIT_CRITICAL();
87                 }
88                 else
89                 {
90                         /* Turn the LED off. */
91                         taskENTER_CRITICAL();
92                         {
93                                 switch( ulLED )
94                                 {
95                                         case 0: LED0 = LED_OFF;
96                                                         break;
97                                         case 1: LED1 = LED_OFF;
98                                                         break;
99                                         case 2: LED2 = LED_OFF;
100                                                         break;
101                                         case 3: LED3 = LED_OFF;
102                                                         break;
103                                 }
104
105                         }
106                         taskEXIT_CRITICAL();
107                 }
108         }
109 }
110 /*-----------------------------------------------------------*/
111
112 void vParTestToggleLED( unsigned long ulLED )
113 {
114         if( ulLED < partestNUM_LEDS )
115         {
116                 taskENTER_CRITICAL();
117                 {
118                         if( lParTestGetLEDState( ulLED ) != 0x00 )
119                         {
120                                 vParTestSetLED( ulLED, 0 );
121                         }
122                         else
123                         {
124                                 vParTestSetLED( ulLED, 1 );
125                         }
126                 }
127                 taskEXIT_CRITICAL();
128         }
129 }
130 /*-----------------------------------------------------------*/
131
132 long lParTestGetLEDState( unsigned long ulLED )
133 {
134 long lReturn = pdTRUE;
135
136         if( ulLED < partestNUM_LEDS )
137         {
138                 switch( ulLED )
139                 {
140                         case 0  :       if( LED0 != 0 )
141                                                 {
142                                                         lReturn =  pdFALSE;
143                                                 }
144                                                 break;
145                         case 1  :       if( LED1 != 0 )
146                                                 {
147                                                         lReturn =  pdFALSE;
148                                                 }
149                                                 break;
150                         case 2  :       if( LED2 != 0 )
151                                                 {
152                                                         lReturn =  pdFALSE;
153                                                 }
154                                                 break;
155                         case 3  :       if( LED3 != 0 )
156                                                 {
157                                                         lReturn =  pdFALSE;
158                                                 }
159                                                 break;
160                 }
161         }
162
163         return lReturn;
164 }
165 /*-----------------------------------------------------------*/
166