]> git.sur5r.net Git - freertos/blob - Demo/Cygnal/ParTest/ParTest.c
Update to V5.4.2. See http://www.freertos.org/History.txt .
[freertos] / Demo / Cygnal / ParTest / ParTest.c
1 /*\r
2         FreeRTOS V5.4.2 - 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         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *\r
29         * See http://www.FreeRTOS.org/Documentation for details                   *\r
30         *                                                                         *\r
31         ***************************************************************************\r
32 \r
33         1 tab == 4 spaces!\r
34 \r
35         Please ensure to read the configuration and relevant port sections of the\r
36         online documentation.\r
37 \r
38         http://www.FreeRTOS.org - Documentation, latest information, license and\r
39         contact details.\r
40 \r
41         http://www.SafeRTOS.com - A version that is certified for use in safety\r
42         critical systems.\r
43 \r
44         http://www.OpenRTOS.com - Commercial support, development, porting,\r
45         licensing and training services.\r
46 */\r
47 #include <c8051f120.h>\r
48 \r
49 #include "FreeRTOS.h"\r
50 #include "task.h"\r
51 #include "partest.h"\r
52 \r
53 #define partstPUSH_PULL                 ( ( unsigned portCHAR ) 0xff )\r
54 #define partstALL_OUTPUTS_OFF   ( ( unsigned portCHAR ) 0xff )\r
55 \r
56 /* LED to output is dependent on how the LED's are wired. */\r
57 #define partstOUTPUT_0                  ( ( unsigned portCHAR ) 0x02 )\r
58 #define partstOUTPUT_1                  ( ( unsigned portCHAR ) 0x08 )\r
59 #define partstOUTPUT_2                  ( ( unsigned portCHAR ) 0x20 )\r
60 #define partstOUTPUT_3                  ( ( unsigned portCHAR ) 0x01 )\r
61 #define partstOUTPUT_4                  ( ( unsigned portCHAR ) 0x04 )\r
62 #define partstOUTPUT_5                  ( ( unsigned portCHAR ) 0x10 )\r
63 #define partstOUTPUT_6                  ( ( unsigned portCHAR ) 0x40 )\r
64 #define partstOUTPUT_7                  ( ( unsigned portCHAR ) 0x80 )\r
65 \r
66 /*-----------------------------------------------------------\r
67  * Simple parallel port IO routines.\r
68  *-----------------------------------------------------------*/\r
69 \r
70 void vParTestInitialise( void )\r
71 {\r
72 unsigned portCHAR ucOriginalSFRPage;\r
73 \r
74         /* Remember the SFR page before it is changed so it can get set back\r
75         before the function exits. */\r
76         ucOriginalSFRPage = SFRPAGE;\r
77 \r
78         /* Setup the SFR page to access the config SFR's. */\r
79         SFRPAGE = CONFIG_PAGE;\r
80 \r
81         /* Set the on board LED to push pull. */\r
82         P3MDOUT |= partstPUSH_PULL;\r
83 \r
84         /* Return the SFR page. */\r
85         SFRPAGE = ucOriginalSFRPage;\r
86 \r
87         P3 = partstALL_OUTPUTS_OFF;\r
88 }\r
89 /*-----------------------------------------------------------*/\r
90 \r
91 void vParTestSetLED( unsigned portBASE_TYPE uxLED, portBASE_TYPE xValue )\r
92 {\r
93 portBASE_TYPE xError = pdFALSE;\r
94 \r
95         vTaskSuspendAll();\r
96         {\r
97                 if( xValue == pdFALSE )\r
98                 {\r
99                         switch( uxLED )\r
100                         {\r
101                                 case 0  :       P3 |= partstOUTPUT_0;\r
102                                                         break;\r
103                                 case 1  :       P3 |= partstOUTPUT_1;\r
104                                                         break;\r
105                                 case 2  :       P3 |= partstOUTPUT_2;\r
106                                                         break;\r
107                                 case 3  :       P3 |= partstOUTPUT_3;\r
108                                                         break;\r
109                                 case 4  :       P3 |= partstOUTPUT_4;\r
110                                                         break;\r
111                                 case 5  :       P3 |= partstOUTPUT_5;\r
112                                                         break;\r
113                                 case 6  :       P3 |= partstOUTPUT_6;\r
114                                                         break;\r
115                                 case 7  :       P3 |= partstOUTPUT_7;\r
116                                                         break;\r
117                                 default :       /* There are no other LED's wired in. */\r
118                                                         xError = pdTRUE;\r
119                                                         break;\r
120                         }\r
121                 }\r
122                 else\r
123                 {\r
124                         switch( uxLED )\r
125                         {\r
126                                 case 0  :       P3 &= ~partstOUTPUT_0;\r
127                                                         break;\r
128                                 case 1  :       P3 &= ~partstOUTPUT_1;\r
129                                                         break;\r
130                                 case 2  :       P3 &= ~partstOUTPUT_2;\r
131                                                         break;\r
132                                 case 3  :       P3 &= ~partstOUTPUT_3;\r
133                                                         break;\r
134                                 case 4  :       P3 &= ~partstOUTPUT_4;\r
135                                                         break;\r
136                                 case 5  :       P3 &= ~partstOUTPUT_5;\r
137                                                         break;\r
138                                 case 6  :       P3 &= ~partstOUTPUT_6;\r
139                                                         break;\r
140                                 case 7  :       P3 &= ~partstOUTPUT_7;\r
141                                                         break;\r
142                                 default :       /* There are no other LED's wired in. */\r
143                                                         break;\r
144                         }\r
145                 }\r
146         }\r
147         xTaskResumeAll();\r
148 }\r
149 /*-----------------------------------------------------------*/\r
150 \r
151 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
152 {\r
153 unsigned portCHAR ucBit;\r
154 portBASE_TYPE xError = pdFALSE;\r
155 \r
156         vTaskSuspendAll();\r
157         {\r
158                 switch( uxLED )\r
159                 {\r
160                         case 0  :       ucBit = partstOUTPUT_0;\r
161                                                 break;\r
162                         case 1  :       ucBit = partstOUTPUT_1;\r
163                                                 break;\r
164                         case 2  :       ucBit = partstOUTPUT_2;\r
165                                                 break;\r
166                         case 3  :       ucBit = partstOUTPUT_3;\r
167                                                 break;\r
168                         case 4  :       ucBit = partstOUTPUT_4;\r
169                                                 break;\r
170                         case 5  :       ucBit = partstOUTPUT_5;\r
171                                                 break;\r
172                         case 6  :       ucBit = partstOUTPUT_6;\r
173                                                 break;\r
174                         case 7  :       ucBit = partstOUTPUT_7;\r
175                                                 break;\r
176                         default :       /* There are no other LED's wired in. */\r
177                                                 xError = pdTRUE;\r
178                                                 break;\r
179                 }\r
180 \r
181                 if( xError != pdTRUE )\r
182                 {\r
183                         if( P3 & ucBit )\r
184                         {\r
185                                 P3 &= ~ucBit;\r
186                         }\r
187                         else\r
188                         {\r
189                                 P3 |= ucBit;\r
190                         }\r
191                 }\r
192         }\r
193         xTaskResumeAll();\r
194 }\r
195 \r
196 \r