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