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