]> begriffs open source - freertos/blob - Demo/MicroBlaze/ParTest/ParTest.c
(no commit message)
[freertos] / Demo / MicroBlaze / ParTest / ParTest.c
1 /*\r
2         FreeRTOS.org V4.0.3 - Copyright (C) 2003-2006 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 */\r
32 \r
33 /*-----------------------------------------------------------\r
34  * Simple parallel port IO routines.\r
35  *-----------------------------------------------------------*/\r
36 \r
37 /* Kernel includes. */\r
38 #include "FreeRTOS.h"\r
39 \r
40 /* Demo application includes. */\r
41 #include "partest.h"\r
42 \r
43 /* Library includes. */\r
44 #include "xgpio_l.h"\r
45 \r
46 /* Misc hardware specific definitions. */\r
47 #define partstALL_AS_OUTPUT     0x00\r
48 #define partstCHANNEL_1         0x01\r
49 #define partstMAX_4BIT_LED      0x03\r
50 \r
51 /* The outputs are split into two IO sections, these variables maintain the \r
52 current value of either section. */\r
53 static unsigned portBASE_TYPE uxCurrentOutput4Bit, uxCurrentOutput5Bit;\r
54 \r
55 /*-----------------------------------------------------------*/\r
56 /*\r
57  * Setup the IO for the LED outputs.\r
58  */\r
59 void vParTestInitialise( void )\r
60 {\r
61         /* Set both sets of LED's on the demo board to outputs. */\r
62         XGpio_mSetDataDirection( XPAR_LEDS_4BIT_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );\r
63         XGpio_mSetDataDirection( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, partstALL_AS_OUTPUT );\r
64 \r
65         /* Start with all outputs off. */\r
66         uxCurrentOutput4Bit = 0;\r
67         XGpio_mSetDataReg( XPAR_LEDS_4BIT_BASEADDR, partstCHANNEL_1, 0x00 );\r
68         uxCurrentOutput5Bit = 0;\r
69         XGpio_mSetDataReg( XPAR_LEDS_POSITIONS_BASEADDR, partstCHANNEL_1, 0x00 );\r
70 }\r
71 /*-----------------------------------------------------------*/\r
72 \r
73 void vParTestSetLED( unsigned portBASE_TYPE uxLED, signed portBASE_TYPE xValue )\r
74 {\r
75 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
76 \r
77         portENTER_CRITICAL();\r
78         {\r
79                 /* Which IO section does the LED being set/cleared belong to?  The\r
80                 4 bit or 5 bit outputs? */\r
81                 if( uxLED <= partstMAX_4BIT_LED )\r
82                 {\r
83                         uxBaseAddress = XPAR_LEDS_4BIT_BASEADDR;\r
84                         puxCurrentValue = &uxCurrentOutput4Bit;\r
85                 }       \r
86                 else\r
87                 {\r
88                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
89                         puxCurrentValue = &uxCurrentOutput5Bit;\r
90                         uxLED -= partstMAX_4BIT_LED;\r
91                 }\r
92 \r
93                 /* Setup the bit mask accordingly. */\r
94                 uxLED = 0x01 << uxLED;\r
95 \r
96                 /* Maintain the current output value. */\r
97                 if( xValue )\r
98                 {\r
99                         *puxCurrentValue |= uxLED;\r
100                 }\r
101                 else\r
102                 {\r
103                         *puxCurrentValue &= ~uxLED;\r
104                 }\r
105 \r
106                 /* Write the value to the port. */\r
107                 XGpio_mSetDataReg( uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
108         }\r
109         portEXIT_CRITICAL();\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
114 {\r
115 unsigned portBASE_TYPE uxBaseAddress, *puxCurrentValue;\r
116 \r
117         portENTER_CRITICAL();\r
118         {\r
119                 /* Which IO section does the LED being toggled belong to?  The\r
120                 4 bit or 5 bit outputs? */\r
121                 if( uxLED <= partstMAX_4BIT_LED )\r
122                 {\r
123                         uxBaseAddress = XPAR_LEDS_4BIT_BASEADDR;\r
124                         puxCurrentValue = &uxCurrentOutput4Bit;\r
125                 }       \r
126                 else\r
127                 {\r
128                         uxBaseAddress = XPAR_LEDS_POSITIONS_BASEADDR;\r
129                         puxCurrentValue = &uxCurrentOutput5Bit;\r
130                         uxLED -= partstMAX_4BIT_LED;\r
131                 }\r
132 \r
133                 /* Setup the bit mask accordingly. */\r
134                 uxLED = 0x01 << uxLED;\r
135 \r
136                 /* Maintain the current output value. */\r
137                 if( *puxCurrentValue & uxLED )\r
138                 {\r
139                         *puxCurrentValue &= ~uxLED;\r
140                 }\r
141                 else\r
142                 {\r
143                         *puxCurrentValue |= uxLED;\r
144                 }\r
145 \r
146                 /* Write the value to the port. */\r
147                 XGpio_mSetDataReg(uxBaseAddress, partstCHANNEL_1, *puxCurrentValue );\r
148         }\r
149         portEXIT_CRITICAL();\r
150 }\r
151 \r
152 \r