]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze/ParTest/ParTest.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / MicroBlaze / ParTest / ParTest.c
1 /*\r
2     FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     This file is part of the FreeRTOS distribution.\r
5 \r
6     FreeRTOS is free software; you can redistribute it and/or modify it    under\r
7     the terms of the GNU General Public License (version 2) as published by the\r
8     Free Software Foundation and modified by the FreeRTOS exception.\r
9     **NOTE** The exception to the GPL is included to allow you to distribute a\r
10     combined work that includes FreeRTOS without being obliged to provide the\r
11     source code for proprietary components outside of the FreeRTOS kernel.\r
12     Alternative commercial license and support terms are also available upon\r
13     request.  See the licensing section of http://www.FreeRTOS.org for full\r
14     license details.\r
15 \r
16     FreeRTOS is distributed in the hope that it will be useful,    but WITHOUT\r
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
19     more details.\r
20 \r
21     You should have received a copy of the GNU General Public License along\r
22     with FreeRTOS; if not, write to the Free Software Foundation, Inc., 59\r
23     Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
24 \r
25 \r
26     ***************************************************************************\r
27     *                                                                         *\r
28     * The FreeRTOS eBook and reference manual are available to purchase for a *\r
29     * small fee. Help yourself get started quickly while also helping the     *\r
30     * FreeRTOS project! See http://www.FreeRTOS.org/Documentation for details *\r
31     *                                                                         *\r
32     ***************************************************************************\r
33 \r
34     1 tab == 4 spaces!\r
35 \r
36     Please ensure to read the configuration and relevant port sections of the\r
37     online documentation.\r
38 \r
39     http://www.FreeRTOS.org - Documentation, latest information, license and\r
40     contact details.\r
41 \r
42     http://www.SafeRTOS.com - A version that is certified for use in safety\r
43     critical systems.\r
44 \r
45     http://www.OpenRTOS.com - Commercial support, development, porting,\r
46     licensing and training services.\r
47 */\r
48 \r
49 /*-----------------------------------------------------------\r
50  * Simple parallel port IO routines.\r
51  *-----------------------------------------------------------*/\r
52 \r
53 /* Kernel includes. */\r
54 #include "FreeRTOS.h"\r
55 \r
56 /* Demo application includes. */\r
57 #include "partest.h"\r
58 \r
59 /* Library includes. */\r
60 #include "xgpio_l.h"\r
61 \r
62 /* Misc hardware specific definitions. */\r
63 #define partstALL_AS_OUTPUT     0x00\r
64 #define partstCHANNEL_1         0x01\r
65 #define partstMAX_4BIT_LED      0x03\r
66 \r
67 /* The outputs are split into two IO sections, these variables maintain the \r
68 current value of either section. */\r
69 static unsigned portBASE_TYPE uxCurrentOutput4Bit, uxCurrentOutput5Bit;\r
70 \r
71 /*-----------------------------------------------------------*/\r
72 /*\r
73  * Setup the IO for the LED outputs.\r
74  */\r
75 void vParTestInitialise( void )\r
76 {\r
77         /* Set both sets of LED's on the demo board to outputs. */\r
78         XGpio_mSetDataDirection( XPAR_LEDS_4BIT_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );\r
79         XGpio_mSetDataDirection( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );\r
80 \r
81         /* Start with all outputs off. */\r
82         uxCurrentOutput4Bit = 0;\r
83         XGpio_mSetDataReg( XPAR_LEDS_4BIT_BASEADDR, partstCHANNEL_1, 0x00 );\r
84         uxCurrentOutput5Bit = 0;\r
85         XGpio_mSetDataReg( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, 0x00 );\r
86 }\r
87 /*-----------------------------------------------------------*/\r
88 \r
89 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
90 {\r
91 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
92 \r
93         portENTER_CRITICAL();\r
94         {\r
95                 /* Which IO section does the LED being set/cleared belong to?  The\r
96                 4 bit or 5 bit outputs? */\r
97                 if( uxLED <= partstMAX_4BIT_LED )\r
98                 {\r
99                         uxBaseAddress = XPAR_LEDS_4BIT_BASEADDR;\r
100                         puxCurrentValue = &uxCurrentOutput4Bit;\r
101                 }       \r
102                 else\r
103                 {\r
104                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
105                         puxCurrentValue = &uxCurrentOutput5Bit;\r
106                         uxLED -= partstMAX_4BIT_LED;\r
107                 }\r
108 \r
109                 /* Setup the bit mask accordingly. */\r
110                 uxLED = 0x01 << uxLED;\r
111 \r
112                 /* Maintain the current output value. */\r
113                 if( xValue )\r
114                 {\r
115                         *puxCurrentValue |= uxLED;\r
116                 }\r
117                 else\r
118                 {\r
119                         *puxCurrentValue &= ~uxLED;\r
120                 }\r
121 \r
122                 /* Write the value to the port. */\r
123                 XGpio_mSetDataReg( uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
124         }\r
125         portEXIT_CRITICAL();\r
126 }\r
127 /*-----------------------------------------------------------*/\r
128 \r
129 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
130 {\r
131 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
132 \r
133         portENTER_CRITICAL();\r
134         {\r
135                 /* Which IO section does the LED being toggled belong to?  The\r
136                 4 bit or 5 bit outputs? */\r
137                 if( uxLED <= partstMAX_4BIT_LED )\r
138                 {\r
139                         uxBaseAddress = XPAR_LEDS_4BIT_BASEADDR;\r
140                         puxCurrentValue = &uxCurrentOutput4Bit;\r
141                 }       \r
142                 else\r
143                 {\r
144                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
145                         puxCurrentValue = &uxCurrentOutput5Bit;\r
146                         uxLED -= partstMAX_4BIT_LED;\r
147                 }\r
148 \r
149                 /* Setup the bit mask accordingly. */\r
150                 uxLED = 0x01 << uxLED;\r
151 \r
152                 /* Maintain the current output value. */\r
153                 if( *puxCurrentValue & uxLED )\r
154                 {\r
155                         *puxCurrentValue &= ~uxLED;\r
156                 }\r
157                 else\r
158                 {\r
159                         *puxCurrentValue |= uxLED;\r
160                 }\r
161 \r
162                 /* Write the value to the port. */\r
163                 XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
164         }\r
165         portEXIT_CRITICAL();\r
166 }\r
167 \r
168 \r