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