]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PPC440_SP_FPU_Xilinx_Virtex5_GCC/RTOSDemo/partest/partest.c
22363718c5b1490fbc2359827309e309c427accf
[freertos] / FreeRTOS / Demo / PPC440_SP_FPU_Xilinx_Virtex5_GCC / RTOSDemo / partest / partest.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\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
11  *\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
14  *\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
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 \r
29 /* Scheduler includes. */\r
30 #include "FreeRTOS.h"\r
31 \r
32 /* Demo application includes. */\r
33 #include "partest.h"\r
34 \r
35 /* Library includes. */\r
36 #include "xparameters.h"\r
37 #include "xgpio_l.h"\r
38 \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
43 \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
47 \r
48 /*-----------------------------------------------------------*/\r
49 /*\r
50  * Setup the IO for the LED outputs.\r
51  */\r
52 void vParTestInitialise( void )\r
53 {\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
57 \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
63 }\r
64 /*-----------------------------------------------------------*/\r
65 \r
66 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
67 {\r
68 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
69 \r
70         portENTER_CRITICAL();\r
71         {\r
72                 /* Which IO section does the LED being set/cleared belong to?  The\r
73                 4 bit or 5 bit outputs? */\r
74                 if( uxLED <= partstMAX_8BIT_LED )\r
75                 {\r
76                         uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;\r
77                         puxCurrentValue = &uxCurrentOutput5Bit;\r
78                 }       \r
79                 else\r
80                 {\r
81                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
82                         puxCurrentValue = &uxCurrentOutput8Bit;\r
83                         uxLED -= partstMAX_8BIT_LED;\r
84                 }\r
85 \r
86                 /* Setup the bit mask accordingly. */\r
87                 uxLED = 0x01 << uxLED;\r
88 \r
89                 /* Maintain the current output value. */\r
90                 if( xValue )\r
91                 {\r
92                         *puxCurrentValue |= uxLED;\r
93                 }\r
94                 else\r
95                 {\r
96                         *puxCurrentValue &= ~uxLED;\r
97                 }\r
98 \r
99                 /* Write the value to the port. */\r
100                 XGpio_mSetDataReg( uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
101         }\r
102         portEXIT_CRITICAL();\r
103 }\r
104 /*-----------------------------------------------------------*/\r
105 \r
106 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
107 {\r
108 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
109 \r
110         portENTER_CRITICAL();\r
111         {\r
112                 /* Which IO section does the LED being toggled belong to?  The\r
113                 4 bit or 5 bit outputs? */\r
114                 if( uxLED <= partstMAX_8BIT_LED )\r
115                 {\r
116 \r
117                         uxBaseAddress = XPAR_LEDS_8BIT_BASEADDR;\r
118                         puxCurrentValue = &uxCurrentOutput5Bit;\r
119                 }       \r
120                 else\r
121                 {\r
122                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
123                         puxCurrentValue = &uxCurrentOutput8Bit;\r
124                         uxLED -= partstMAX_8BIT_LED;\r
125                 }\r
126 \r
127                 /* Setup the bit mask accordingly. */\r
128                 uxLED = 0x01 << uxLED;\r
129 \r
130                 /* Maintain the current output value. */\r
131                 if( *puxCurrentValue & uxLED )\r
132                 {\r
133                         *puxCurrentValue &= ~uxLED;\r
134                 }\r
135                 else\r
136                 {\r
137                         *puxCurrentValue |= uxLED;\r
138                 }\r
139 \r
140                 /* Write the value to the port. */\r
141                 XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
142         }\r
143         portEXIT_CRITICAL();\r
144 }\r
145 \r
146 \r