2 * FreeRTOS Kernel V10.1.0
\r
3 * Copyright (C) 2018 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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 /* Scheduler includes. */
\r
30 #include "FreeRTOS.h"
\r
32 /* Demo application includes. */
\r
33 #include "partest.h"
\r
35 /* Library includes. */
\r
36 #include "xparameters.h"
\r
37 #include "xgpio_l.h"
\r
39 /* Misc hardware specific definitions. */
\r
40 #define partstALL_AS_OUTPUT 0x00
\r
41 #define partstCHANNEL_1 0x01
\r
42 #define partstMAX_8BIT_LED 0x07
\r
44 /* The outputs are split into two IO sections, these variables maintain the
\r
45 current value of either section. */
\r
46 static unsigned portBASE_TYPE uxCurrentOutput8Bit, uxCurrentOutput5Bit;
\r
48 /*-----------------------------------------------------------*/
\r
50 * Setup the IO for the LED outputs.
\r
52 void vParTestInitialise( void )
\r
54 /* Set both sets of LED's on the demo board to outputs. */
\r
55 XGpio_mSetDataDirection( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );
\r
56 XGpio_mSetDataDirection( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );
\r
58 /* Start with all outputs off. */
\r
59 uxCurrentOutput8Bit = 0;
\r
60 XGpio_mSetDataReg( XPAR_LEDS_8BIT_BASEADDR, partstCHANNEL_1, 0x00 );
\r
61 uxCurrentOutput5Bit = 0;
\r
62 XGpio_mSetDataReg( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, 0x00 );
\r
64 /*-----------------------------------------------------------*/
\r
66 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )
\r
68 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;
\r
70 portENTER_CRITICAL();
\r
72 /* Which IO section does the LED being set/cleared belong to? The
\r
73 8 bit or 5 bit outputs? */
\r
74 if( uxLED <= partstMAX_8BIT_LED )
\r
76 uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;
\r
77 puxCurrentValue = &uxCurrentOutput5Bit;
\r
81 uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;
\r
82 puxCurrentValue = &uxCurrentOutput8Bit;
\r
83 uxLED -= partstMAX_8BIT_LED;
\r
86 /* Setup the bit mask accordingly. */
\r
87 uxLED = 0x01 << uxLED;
\r
89 /* Maintain the current output value. */
\r
92 *puxCurrentValue |= uxLED;
\r
96 *puxCurrentValue &= ~uxLED;
\r
99 /* Write the value to the port. */
\r
100 XGpio_mSetDataReg( uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );
\r
102 portEXIT_CRITICAL();
\r
104 /*-----------------------------------------------------------*/
\r
106 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )
\r
108 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;
\r
110 portENTER_CRITICAL();
\r
112 /* Which IO section does the LED being toggled belong to? The
\r
113 8 bit or 5 bit outputs? */
\r
114 if( uxLED <= partstMAX_8BIT_LED )
\r
117 uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;
\r
118 puxCurrentValue = &uxCurrentOutput5Bit;
\r
122 uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;
\r
123 puxCurrentValue = &uxCurrentOutput8Bit;
\r
124 uxLED -= partstMAX_8BIT_LED;
\r
127 /* Setup the bit mask accordingly. */
\r
128 uxLED = 0x01 << uxLED;
\r
130 /* Maintain the current output value. */
\r
131 if( *puxCurrentValue & uxLED )
\r
133 *puxCurrentValue &= ~uxLED;
\r
137 *puxCurrentValue |= uxLED;
\r
140 /* Write the value to the port. */
\r
141 XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );
\r
143 portEXIT_CRITICAL();
\r