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