]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Cygnal/ParTest/ParTest.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / Cygnal / ParTest / ParTest.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 #include <c8051f120.h>\r
29 \r
30 #include "FreeRTOS.h"\r
31 #include "task.h"\r
32 #include "partest.h"\r
33 \r
34 #define partstPUSH_PULL                 ( ( unsigned char ) 0xff )\r
35 #define partstALL_OUTPUTS_OFF   ( ( unsigned char ) 0xff )\r
36 \r
37 /* LED to output is dependent on how the LED's are wired. */\r
38 #define partstOUTPUT_0                  ( ( unsigned char ) 0x02 )\r
39 #define partstOUTPUT_1                  ( ( unsigned char ) 0x08 )\r
40 #define partstOUTPUT_2                  ( ( unsigned char ) 0x20 )\r
41 #define partstOUTPUT_3                  ( ( unsigned char ) 0x01 )\r
42 #define partstOUTPUT_4                  ( ( unsigned char ) 0x04 )\r
43 #define partstOUTPUT_5                  ( ( unsigned char ) 0x10 )\r
44 #define partstOUTPUT_6                  ( ( unsigned char ) 0x40 )\r
45 #define partstOUTPUT_7                  ( ( unsigned char ) 0x80 )\r
46 \r
47 /*-----------------------------------------------------------\r
48  * Simple parallel port IO routines.\r
49  *-----------------------------------------------------------*/\r
50 \r
51 void vParTestInitialise( void )\r
52 {\r
53 unsigned char ucOriginalSFRPage;\r
54 \r
55         /* Remember the SFR page before it is changed so it can get set back\r
56         before the function exits. */\r
57         ucOriginalSFRPage = SFRPAGE;\r
58 \r
59         /* Setup the SFR page to access the config SFR's. */\r
60         SFRPAGE = CONFIG_PAGE;\r
61 \r
62         /* Set the on board LED to push pull. */\r
63         P3MDOUT |= partstPUSH_PULL;\r
64 \r
65         /* Return the SFR page. */\r
66         SFRPAGE = ucOriginalSFRPage;\r
67 \r
68         P3 = partstALL_OUTPUTS_OFF;\r
69 }\r
70 /*-----------------------------------------------------------*/\r
71 \r
72 void vParTestSetLED( unsigned portBASE_TYPE uxLED, portBASE_TYPE xValue )\r
73 {\r
74 portBASE_TYPE xError = pdFALSE;\r
75 \r
76         vTaskSuspendAll();\r
77         {\r
78                 if( xValue == pdFALSE )\r
79                 {\r
80                         switch( uxLED )\r
81                         {\r
82                                 case 0  :       P3 |= partstOUTPUT_0;\r
83                                                         break;\r
84                                 case 1  :       P3 |= partstOUTPUT_1;\r
85                                                         break;\r
86                                 case 2  :       P3 |= partstOUTPUT_2;\r
87                                                         break;\r
88                                 case 3  :       P3 |= partstOUTPUT_3;\r
89                                                         break;\r
90                                 case 4  :       P3 |= partstOUTPUT_4;\r
91                                                         break;\r
92                                 case 5  :       P3 |= partstOUTPUT_5;\r
93                                                         break;\r
94                                 case 6  :       P3 |= partstOUTPUT_6;\r
95                                                         break;\r
96                                 case 7  :       P3 |= partstOUTPUT_7;\r
97                                                         break;\r
98                                 default :       /* There are no other LED's wired in. */\r
99                                                         xError = pdTRUE;\r
100                                                         break;\r
101                         }\r
102                 }\r
103                 else\r
104                 {\r
105                         switch( uxLED )\r
106                         {\r
107                                 case 0  :       P3 &= ~partstOUTPUT_0;\r
108                                                         break;\r
109                                 case 1  :       P3 &= ~partstOUTPUT_1;\r
110                                                         break;\r
111                                 case 2  :       P3 &= ~partstOUTPUT_2;\r
112                                                         break;\r
113                                 case 3  :       P3 &= ~partstOUTPUT_3;\r
114                                                         break;\r
115                                 case 4  :       P3 &= ~partstOUTPUT_4;\r
116                                                         break;\r
117                                 case 5  :       P3 &= ~partstOUTPUT_5;\r
118                                                         break;\r
119                                 case 6  :       P3 &= ~partstOUTPUT_6;\r
120                                                         break;\r
121                                 case 7  :       P3 &= ~partstOUTPUT_7;\r
122                                                         break;\r
123                                 default :       /* There are no other LED's wired in. */\r
124                                                         break;\r
125                         }\r
126                 }\r
127         }\r
128         xTaskResumeAll();\r
129 }\r
130 /*-----------------------------------------------------------*/\r
131 \r
132 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
133 {\r
134 unsigned char ucBit;\r
135 portBASE_TYPE xError = pdFALSE;\r
136 \r
137         vTaskSuspendAll();\r
138         {\r
139                 switch( uxLED )\r
140                 {\r
141                         case 0  :       ucBit = partstOUTPUT_0;\r
142                                                 break;\r
143                         case 1  :       ucBit = partstOUTPUT_1;\r
144                                                 break;\r
145                         case 2  :       ucBit = partstOUTPUT_2;\r
146                                                 break;\r
147                         case 3  :       ucBit = partstOUTPUT_3;\r
148                                                 break;\r
149                         case 4  :       ucBit = partstOUTPUT_4;\r
150                                                 break;\r
151                         case 5  :       ucBit = partstOUTPUT_5;\r
152                                                 break;\r
153                         case 6  :       ucBit = partstOUTPUT_6;\r
154                                                 break;\r
155                         case 7  :       ucBit = partstOUTPUT_7;\r
156                                                 break;\r
157                         default :       /* There are no other LED's wired in. */\r
158                                                 xError = pdTRUE;\r
159                                                 break;\r
160                 }\r
161 \r
162                 if( xError != pdTRUE )\r
163                 {\r
164                         if( P3 & ucBit )\r
165                         {\r
166                                 P3 &= ~ucBit;\r
167                         }\r
168                         else\r
169                         {\r
170                                 P3 |= ucBit;\r
171                         }\r
172                 }\r
173         }\r
174         xTaskResumeAll();\r
175 }\r
176 \r
177 \r