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 /* Scheduler includes. */
\r
31 #include "FreeRTOS.h"
\r
33 /* Demo application includes. */
\r
34 #include "partest.h"
\r
36 /* Library includes. */
\r
37 #include "xparameters.h"
\r
38 #include "xgpio_l.h"
\r
40 /* Misc hardware specific definitions. */
\r
41 #define partstALL_AS_OUTPUT 0x00
\r
42 #define partstCHANNEL_1 0x01
\r
43 #define partstMAX_8BIT_LED 0x07
\r
45 /* The outputs are split into two IO sections, these variables maintain the
\r
46 current value of either section. */
\r
47 static unsigned portBASE_TYPE uxCurrentOutput8Bit, uxCurrentOutput5Bit;
\r
49 /*-----------------------------------------------------------*/
\r
51 * Setup the IO for the LED outputs.
\r
53 void vParTestInitialise( void )
\r
55 /* Set both sets of LED's on the demo board to outputs. */
\r
56 XGpio_mSetDataDirection( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );
\r
57 XGpio_mSetDataDirection( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );
\r
59 /* Start with all outputs off. */
\r
60 uxCurrentOutput8Bit = 0;
\r
61 XGpio_mSetDataReg( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, 0x00 );
\r
62 uxCurrentOutput5Bit = 0;
\r
63 XGpio_mSetDataReg( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, 0x00 );
\r
65 /*-----------------------------------------------------------*/
\r
67 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
\r
69 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;
\r
71 portENTER_CRITICAL();
\r
73 /* Which IO section does the LED being set/cleared belong to? The
\r
74 4 bit or 5 bit outputs? */
\r
75 if( uxLED <= partstMAX_8BIT_LED )
\r
77 uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;
\r
78 puxCurrentValue = &uxCurrentOutput5Bit;
\r
82 uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;
\r
83 puxCurrentValue = &uxCurrentOutput8Bit;
\r
84 uxLED -= partstMAX_8BIT_LED;
\r
87 /* Setup the bit mask accordingly. */
\r
88 uxLED = 0x01 << uxLED;
\r
90 /* Maintain the current output value. */
\r
93 *puxCurrentValue |= uxLED;
\r
97 *puxCurrentValue &= ~uxLED;
\r
100 /* Write the value to the port. */
\r
101 XGpio_mSetDataReg( uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );
\r
103 portEXIT_CRITICAL();
\r
105 /*-----------------------------------------------------------*/
\r
107 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
\r
109 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;
\r
111 portENTER_CRITICAL();
\r
113 /* Which IO section does the LED being toggled belong to? The
\r
114 4 bit or 5 bit outputs? */
\r
115 if( uxLED <= partstMAX_8BIT_LED )
\r
118 uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;
\r
119 puxCurrentValue = &uxCurrentOutput5Bit;
\r
123 uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;
\r
124 puxCurrentValue = &uxCurrentOutput8Bit;
\r
125 uxLED -= partstMAX_8BIT_LED;
\r
128 /* Setup the bit mask accordingly. */
\r
129 uxLED = 0x01 << uxLED;
\r
131 /* Maintain the current output value. */
\r
132 if( *puxCurrentValue & uxLED )
\r
134 *puxCurrentValue &= ~uxLED;
\r
138 *puxCurrentValue |= uxLED;
\r
141 /* Write the value to the port. */
\r
142 XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );
\r
144 portEXIT_CRITICAL();
\r