]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Cygnal/ParTest/ParTest.c
cebbd87162927f9553ca910fa704f372835eeed6
[freertos] / FreeRTOS / Demo / Cygnal / ParTest / ParTest.c
1 /*\r
2     FreeRTOS V8.2.3 - Copyright (C) 2015 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 #include <c8051f120.h>\r
70 \r
71 #include "FreeRTOS.h"\r
72 #include "task.h"\r
73 #include "partest.h"\r
74 \r
75 #define partstPUSH_PULL                 ( ( unsigned char ) 0xff )\r
76 #define partstALL_OUTPUTS_OFF   ( ( unsigned char ) 0xff )\r
77 \r
78 /* LED to output is dependent on how the LED's are wired. */\r
79 #define partstOUTPUT_0                  ( ( unsigned char ) 0x02 )\r
80 #define partstOUTPUT_1                  ( ( unsigned char ) 0x08 )\r
81 #define partstOUTPUT_2                  ( ( unsigned char ) 0x20 )\r
82 #define partstOUTPUT_3                  ( ( unsigned char ) 0x01 )\r
83 #define partstOUTPUT_4                  ( ( unsigned char ) 0x04 )\r
84 #define partstOUTPUT_5                  ( ( unsigned char ) 0x10 )\r
85 #define partstOUTPUT_6                  ( ( unsigned char ) 0x40 )\r
86 #define partstOUTPUT_7                  ( ( unsigned char ) 0x80 )\r
87 \r
88 /*-----------------------------------------------------------\r
89  * Simple parallel port IO routines.\r
90  *-----------------------------------------------------------*/\r
91 \r
92 void vParTestInitialise( void )\r
93 {\r
94 unsigned char ucOriginalSFRPage;\r
95 \r
96         /* Remember the SFR page before it is changed so it can get set back\r
97         before the function exits. */\r
98         ucOriginalSFRPage = SFRPAGE;\r
99 \r
100         /* Setup the SFR page to access the config SFR's. */\r
101         SFRPAGE = CONFIG_PAGE;\r
102 \r
103         /* Set the on board LED to push pull. */\r
104         P3MDOUT |= partstPUSH_PULL;\r
105 \r
106         /* Return the SFR page. */\r
107         SFRPAGE = ucOriginalSFRPage;\r
108 \r
109         P3 = partstALL_OUTPUTS_OFF;\r
110 }\r
111 /*-----------------------------------------------------------*/\r
112 \r
113 void vParTestSetLED( unsigned portBASE_TYPE uxLED, portBASE_TYPE xValue )\r
114 {\r
115 portBASE_TYPE xError = pdFALSE;\r
116 \r
117         vTaskSuspendAll();\r
118         {\r
119                 if( xValue == pdFALSE )\r
120                 {\r
121                         switch( uxLED )\r
122                         {\r
123                                 case 0  :       P3 |= partstOUTPUT_0;\r
124                                                         break;\r
125                                 case 1  :       P3 |= partstOUTPUT_1;\r
126                                                         break;\r
127                                 case 2  :       P3 |= partstOUTPUT_2;\r
128                                                         break;\r
129                                 case 3  :       P3 |= partstOUTPUT_3;\r
130                                                         break;\r
131                                 case 4  :       P3 |= partstOUTPUT_4;\r
132                                                         break;\r
133                                 case 5  :       P3 |= partstOUTPUT_5;\r
134                                                         break;\r
135                                 case 6  :       P3 |= partstOUTPUT_6;\r
136                                                         break;\r
137                                 case 7  :       P3 |= partstOUTPUT_7;\r
138                                                         break;\r
139                                 default :       /* There are no other LED's wired in. */\r
140                                                         xError = pdTRUE;\r
141                                                         break;\r
142                         }\r
143                 }\r
144                 else\r
145                 {\r
146                         switch( uxLED )\r
147                         {\r
148                                 case 0  :       P3 &= ~partstOUTPUT_0;\r
149                                                         break;\r
150                                 case 1  :       P3 &= ~partstOUTPUT_1;\r
151                                                         break;\r
152                                 case 2  :       P3 &= ~partstOUTPUT_2;\r
153                                                         break;\r
154                                 case 3  :       P3 &= ~partstOUTPUT_3;\r
155                                                         break;\r
156                                 case 4  :       P3 &= ~partstOUTPUT_4;\r
157                                                         break;\r
158                                 case 5  :       P3 &= ~partstOUTPUT_5;\r
159                                                         break;\r
160                                 case 6  :       P3 &= ~partstOUTPUT_6;\r
161                                                         break;\r
162                                 case 7  :       P3 &= ~partstOUTPUT_7;\r
163                                                         break;\r
164                                 default :       /* There are no other LED's wired in. */\r
165                                                         break;\r
166                         }\r
167                 }\r
168         }\r
169         xTaskResumeAll();\r
170 }\r
171 /*-----------------------------------------------------------*/\r
172 \r
173 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
174 {\r
175 unsigned char ucBit;\r
176 portBASE_TYPE xError = pdFALSE;\r
177 \r
178         vTaskSuspendAll();\r
179         {\r
180                 switch( uxLED )\r
181                 {\r
182                         case 0  :       ucBit = partstOUTPUT_0;\r
183                                                 break;\r
184                         case 1  :       ucBit = partstOUTPUT_1;\r
185                                                 break;\r
186                         case 2  :       ucBit = partstOUTPUT_2;\r
187                                                 break;\r
188                         case 3  :       ucBit = partstOUTPUT_3;\r
189                                                 break;\r
190                         case 4  :       ucBit = partstOUTPUT_4;\r
191                                                 break;\r
192                         case 5  :       ucBit = partstOUTPUT_5;\r
193                                                 break;\r
194                         case 6  :       ucBit = partstOUTPUT_6;\r
195                                                 break;\r
196                         case 7  :       ucBit = partstOUTPUT_7;\r
197                                                 break;\r
198                         default :       /* There are no other LED's wired in. */\r
199                                                 xError = pdTRUE;\r
200                                                 break;\r
201                 }\r
202 \r
203                 if( xError != pdTRUE )\r
204                 {\r
205                         if( P3 & ucBit )\r
206                         {\r
207                                 P3 &= ~ucBit;\r
208                         }\r
209                         else\r
210                         {\r
211                                 P3 |= ucBit;\r
212                         }\r
213                 }\r
214         }\r
215         xTaskResumeAll();\r
216 }\r
217 \r
218 \r