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