]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC18_MPLAB/ParTest/ParTest.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / PIC18_MPLAB / 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 \r
29 /* \r
30 Changes from V2.0.0\r
31 \r
32         + Use scheduler suspends in place of critical sections.\r
33 */\r
34 \r
35 #include "FreeRTOS.h"\r
36 #include "task.h"\r
37 #include "partest.h"\r
38 \r
39 /*-----------------------------------------------------------\r
40  * Simple parallel port IO routines for the FED 40pin demo board.\r
41  * The four LED's are connected to D4 to D7.\r
42  *-----------------------------------------------------------*/\r
43 \r
44 #define partstBIT_AS_OUTPUT                     ( ( unsigned short ) 0 )\r
45 #define partstSET_OUTPUT                        ( ( unsigned short ) 1 )\r
46 #define partstCLEAR_OUTPUT                      ( ( unsigned short ) 0 )\r
47 \r
48 #define partstENABLE_GENERAL_IO         ( ( unsigned char ) 7 )\r
49 \r
50 /*-----------------------------------------------------------*/\r
51 \r
52 void vParTestInitialise( void )\r
53 {\r
54         /* Set the top four bits of port D to output. */\r
55         TRISDbits.TRISD7 = partstBIT_AS_OUTPUT;\r
56         TRISDbits.TRISD6 = partstBIT_AS_OUTPUT;\r
57         TRISDbits.TRISD5 = partstBIT_AS_OUTPUT;\r
58         TRISDbits.TRISD4 = partstBIT_AS_OUTPUT;\r
59 \r
60         /* Start with all bits off. */\r
61         PORTDbits.RD7 = partstCLEAR_OUTPUT;\r
62         PORTDbits.RD6 = partstCLEAR_OUTPUT;\r
63         PORTDbits.RD5 = partstCLEAR_OUTPUT;\r
64         PORTDbits.RD4 = partstCLEAR_OUTPUT;\r
65 \r
66         /* Enable the driver. */\r
67         ADCON1 = partstENABLE_GENERAL_IO;\r
68         TRISEbits.TRISE2 = partstBIT_AS_OUTPUT;\r
69         PORTEbits.RE2 = partstSET_OUTPUT;       \r
70 }\r
71 /*-----------------------------------------------------------*/\r
72 \r
73 void vParTestSetLED( unsigned portBASE_TYPE uxLED, portBASE_TYPE xValue )\r
74 {\r
75         /* We are only using the top nibble, so LED 0 corresponds to bit 4. */  \r
76         vTaskSuspendAll();\r
77         {\r
78                 switch( uxLED )\r
79                 {\r
80                         case 3  :       PORTDbits.RD7 = ( short ) xValue;\r
81                                                 break;\r
82                         case 2  :       PORTDbits.RD6 = ( short ) xValue;\r
83                                                 break;\r
84                         case 1  :       PORTDbits.RD5 = ( short ) xValue;\r
85                                                 break;\r
86                         case 0  :       PORTDbits.RD4 = ( short ) xValue;\r
87                                                 break;\r
88                         default :       /* There are only 4 LED's. */\r
89                                                 break;\r
90                 }\r
91         }\r
92         xTaskResumeAll();\r
93 }\r
94 /*-----------------------------------------------------------*/\r
95 \r
96 void vParTestToggleLED( unsigned portBASE_TYPE uxLED )\r
97 {\r
98         /* We are only using the top nibble, so LED 0 corresponds to bit 4. */  \r
99         vTaskSuspendAll();\r
100         {\r
101                 switch( uxLED )\r
102                 {\r
103                         case 3  :       PORTDbits.RD7 = !( PORTDbits.RD7 );\r
104                                                 break;\r
105                         case 2  :       PORTDbits.RD6 = !( PORTDbits.RD6 );\r
106                                                 break;\r
107                         case 1  :       PORTDbits.RD5 = !( PORTDbits.RD5 );\r
108                                                 break;\r
109                         case 0  :       PORTDbits.RD4 = !( PORTDbits.RD4 );\r
110                                                 break;\r
111                         default :       /* There are only 4 LED's. */\r
112                                                 break;\r
113                 }\r
114         }\r
115         xTaskResumeAll();\r
116 }\r
117 \r
118 \r
119 \r