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