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