]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Cygnal/ParTest/ParTest.c
beade909f9a617f420a062b6ffc55348aca77d5d
[freertos] / FreeRTOS / Demo / Cygnal / ParTest / ParTest.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 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.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 #include <c8051f120.h>\r
28 \r
29 #include "FreeRTOS.h"\r
30 #include "task.h"\r
31 #include "partest.h"\r
32 \r
33 #define partstPUSH_PULL                 ( ( unsigned char ) 0xff )\r
34 #define partstALL_OUTPUTS_OFF   ( ( unsigned char ) 0xff )\r
35 \r
36 /* LED to output is dependent on how the LED's are wired. */\r
37 #define partstOUTPUT_0                  ( ( unsigned char ) 0x02 )\r
38 #define partstOUTPUT_1                  ( ( unsigned char ) 0x08 )\r
39 #define partstOUTPUT_2                  ( ( unsigned char ) 0x20 )\r
40 #define partstOUTPUT_3                  ( ( unsigned char ) 0x01 )\r
41 #define partstOUTPUT_4                  ( ( unsigned char ) 0x04 )\r
42 #define partstOUTPUT_5                  ( ( unsigned char ) 0x10 )\r
43 #define partstOUTPUT_6                  ( ( unsigned char ) 0x40 )\r
44 #define partstOUTPUT_7                  ( ( unsigned char ) 0x80 )\r
45 \r
46 /*-----------------------------------------------------------\r
47  * Simple parallel port IO routines.\r
48  *-----------------------------------------------------------*/\r
49 \r
50 void vParTestInitialise( void )\r
51 {\r
52 unsigned char ucOriginalSFRPage;\r
53 \r
54         /* Remember the SFR page before it is changed so it can get set back\r
55         before the function exits. */\r
56         ucOriginalSFRPage = SFRPAGE;\r
57 \r
58         /* Setup the SFR page to access the config SFR's. */\r
59         SFRPAGE = CONFIG_PAGE;\r
60 \r
61         /* Set the on board LED to push pull. */\r
62         P3MDOUT |= partstPUSH_PULL;\r
63 \r
64         /* Return the SFR page. */\r
65         SFRPAGE = ucOriginalSFRPage;\r
66 \r
67         P3 = partstALL_OUTPUTS_OFF;\r
68 }\r
69 /*-----------------------------------------------------------*/\r
70 \r
71 void vParTestSetLED( unsigned portBASE_TYPE uxLED, portBASE_TYPE xValue )\r
72 {\r
73 portBASE_TYPE xError = pdFALSE;\r
74 \r
75         vTaskSuspendAll();\r
76         {\r
77                 if( xValue == pdFALSE )\r
78                 {\r
79                         switch( uxLED )\r
80                         {\r
81                                 case 0  :       P3 |= partstOUTPUT_0;\r
82                                                         break;\r
83                                 case 1  :       P3 |= partstOUTPUT_1;\r
84                                                         break;\r
85                                 case 2  :       P3 |= partstOUTPUT_2;\r
86                                                         break;\r
87                                 case 3  :       P3 |= partstOUTPUT_3;\r
88                                                         break;\r
89                                 case 4  :       P3 |= partstOUTPUT_4;\r
90                                                         break;\r
91                                 case 5  :       P3 |= partstOUTPUT_5;\r
92                                                         break;\r
93                                 case 6  :       P3 |= partstOUTPUT_6;\r
94                                                         break;\r
95                                 case 7  :       P3 |= partstOUTPUT_7;\r
96                                                         break;\r
97                                 default :       /* There are no other LED's wired in. */\r
98                                                         xError = pdTRUE;\r
99                                                         break;\r
100                         }\r
101                 }\r
102                 else\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                                                         break;\r
124                         }\r
125                 }\r
126         }\r
127         xTaskResumeAll();\r
128 }\r
129 /*-----------------------------------------------------------*/\r
130 \r
131 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
132 {\r
133 unsigned char ucBit;\r
134 portBASE_TYPE xError = pdFALSE;\r
135 \r
136         vTaskSuspendAll();\r
137         {\r
138                 switch( uxLED )\r
139                 {\r
140                         case 0  :       ucBit = partstOUTPUT_0;\r
141                                                 break;\r
142                         case 1  :       ucBit = partstOUTPUT_1;\r
143                                                 break;\r
144                         case 2  :       ucBit = partstOUTPUT_2;\r
145                                                 break;\r
146                         case 3  :       ucBit = partstOUTPUT_3;\r
147                                                 break;\r
148                         case 4  :       ucBit = partstOUTPUT_4;\r
149                                                 break;\r
150                         case 5  :       ucBit = partstOUTPUT_5;\r
151                                                 break;\r
152                         case 6  :       ucBit = partstOUTPUT_6;\r
153                                                 break;\r
154                         case 7  :       ucBit = partstOUTPUT_7;\r
155                                                 break;\r
156                         default :       /* There are no other LED's wired in. */\r
157                                                 xError = pdTRUE;\r
158                                                 break;\r
159                 }\r
160 \r
161                 if( xError != pdTRUE )\r
162                 {\r
163                         if( P3 & ucBit )\r
164                         {\r
165                                 P3 &= ~ucBit;\r
166                         }\r
167                         else\r
168                         {\r
169                                 P3 |= ucBit;\r
170                         }\r
171                 }\r
172         }\r
173         xTaskResumeAll();\r
174 }\r
175 \r
176 \r