]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC18_WizC/Demo1/main.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / PIC18_WizC / Demo1 / main.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /*\r
67 Changes from V3.0.0\r
68 \r
69 Changes from V3.0.1\r
70 */\r
71 \r
72 /*\r
73  * Instead of the normal single demo application, the PIC18F demo is split \r
74  * into several smaller programs of which this is the first.  This enables the \r
75  * demo's to be executed on the RAM limited PIC-devices.\r
76  *\r
77  * The Demo1 project is configured for a PIC18F4620 device.  Main.c starts 9 \r
78  * tasks (including the idle task).\r
79 \r
80  * This first demo is included to do a quick check on the FreeRTOS\r
81  * installation. It is also included to demonstrate a minimal project-setup\r
82  * to use FreeRTOS in a wizC environment.\r
83  *\r
84  * Eight independant tasks are created. All tasks share the same taskcode.\r
85  * Each task blinks a different led on portB. The blinkrate for each task\r
86  * is different, but chosen in such a way that portB will show a binary\r
87  * counter pattern. All blinkrates are derived from a single master-rate.\r
88  * By default, this  masterrate is set to 100 milliseconds. Although such\r
89  * a low value will make it almost impossible to see some of the leds\r
90  * actually blink, it is a good value when using the wizC-simulator.\r
91  * When testing on a real chip, changing the value to eg. 500 milliseconds\r
92  * would be appropiate.\r
93  */\r
94  \r
95 /* Scheduler include files. */\r
96 #include <FreeRTOS.h>\r
97 #include <task.h>\r
98 \r
99 #define mainBLINK_LED_INTERVAL  ( ( TickType_t ) 100 / ( portTICK_PERIOD_MS ) )\r
100 \r
101 /* The LED that is flashed by the B0 task. */\r
102 #define mainBLINK_LED0_PORT             LATD\r
103 #define mainBLINK_LED0_TRIS             TRISD\r
104 #define mainBLINK_LED0_PIN              0\r
105 #define mainBLINK_LED0_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED0_PIN))\r
106 \r
107 /* The LED that is flashed by the B1 task. */\r
108 #define mainBLINK_LED1_PORT             LATD\r
109 #define mainBLINK_LED1_TRIS             TRISD\r
110 #define mainBLINK_LED1_PIN              1\r
111 #define mainBLINK_LED1_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED1_PIN))\r
112 \r
113 /* The LED that is flashed by the B2 task. */\r
114 #define mainBLINK_LED2_PORT             LATD\r
115 #define mainBLINK_LED2_TRIS             TRISD\r
116 #define mainBLINK_LED2_PIN              2\r
117 #define mainBLINK_LED2_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED2_PIN))\r
118 \r
119 /* The LED that is flashed by the B3 task. */\r
120 #define mainBLINK_LED3_PORT             LATD\r
121 #define mainBLINK_LED3_TRIS             TRISD\r
122 #define mainBLINK_LED3_PIN              3\r
123 #define mainBLINK_LED3_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED3_PIN))\r
124 \r
125 /* The LED that is flashed by the B4 task. */\r
126 #define mainBLINK_LED4_PORT             LATD\r
127 #define mainBLINK_LED4_TRIS             TRISD\r
128 #define mainBLINK_LED4_PIN              4\r
129 #define mainBLINK_LED4_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED4_PIN))\r
130 \r
131 /* The LED that is flashed by the B5 task. */\r
132 #define mainBLINK_LED5_PORT             LATD\r
133 #define mainBLINK_LED5_TRIS             TRISD\r
134 #define mainBLINK_LED5_PIN              5\r
135 #define mainBLINK_LED5_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED5_PIN))\r
136 \r
137 /* The LED that is flashed by the B6 task. */\r
138 #define mainBLINK_LED6_PORT             LATD\r
139 #define mainBLINK_LED6_TRIS             TRISD\r
140 #define mainBLINK_LED6_PIN              6\r
141 #define mainBLINK_LED6_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED6_PIN))\r
142 \r
143 /* The LED that is flashed by the B7 task. */\r
144 #define mainBLINK_LED7_PORT             LATD\r
145 #define mainBLINK_LED7_TRIS             TRISD\r
146 #define mainBLINK_LED7_PIN              7\r
147 #define mainBLINK_LED7_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED7_PIN))\r
148 \r
149 typedef struct {\r
150         unsigned char *port;\r
151         unsigned char *tris;\r
152         unsigned char pin;\r
153         TickType_t  interval;\r
154 } SBLINK;\r
155 \r
156 const SBLINK sled0 = {&mainBLINK_LED0_PORT, &mainBLINK_LED0_TRIS, mainBLINK_LED0_PIN, mainBLINK_LED0_INTERVAL};\r
157 const SBLINK sled1 = {&mainBLINK_LED1_PORT, &mainBLINK_LED1_TRIS, mainBLINK_LED1_PIN, mainBLINK_LED1_INTERVAL};\r
158 const SBLINK sled2 = {&mainBLINK_LED2_PORT, &mainBLINK_LED2_TRIS, mainBLINK_LED2_PIN, mainBLINK_LED2_INTERVAL};\r
159 const SBLINK sled3 = {&mainBLINK_LED3_PORT, &mainBLINK_LED3_TRIS, mainBLINK_LED3_PIN, mainBLINK_LED3_INTERVAL};\r
160 const SBLINK sled4 = {&mainBLINK_LED4_PORT, &mainBLINK_LED4_TRIS, mainBLINK_LED4_PIN, mainBLINK_LED4_INTERVAL};\r
161 const SBLINK sled5 = {&mainBLINK_LED5_PORT, &mainBLINK_LED5_TRIS, mainBLINK_LED5_PIN, mainBLINK_LED5_INTERVAL};\r
162 const SBLINK sled6 = {&mainBLINK_LED6_PORT, &mainBLINK_LED6_TRIS, mainBLINK_LED6_PIN, mainBLINK_LED6_INTERVAL};\r
163 const SBLINK sled7 = {&mainBLINK_LED7_PORT, &mainBLINK_LED7_TRIS, mainBLINK_LED7_PIN, mainBLINK_LED7_INTERVAL};\r
164 \r
165 /*\r
166  * The task code for the "vBlink" task.\r
167  */\r
168 static portTASK_FUNCTION_PROTO(vBlink, pvParameters);\r
169 \r
170 /*-----------------------------------------------------------*/\r
171 \r
172 /*\r
173  * Creates the tasks, then starts the scheduler.\r
174  */\r
175 void main( void )\r
176 {\r
177         /*\r
178          * Start the blink tasks defined in this file.\r
179          */\r
180         xTaskCreate( vBlink,  "B0", configMINIMAL_STACK_SIZE, &sled0, tskIDLE_PRIORITY, NULL );\r
181         xTaskCreate( vBlink,  "B1", configMINIMAL_STACK_SIZE, &sled1, tskIDLE_PRIORITY, NULL );\r
182         xTaskCreate( vBlink,  "B2", configMINIMAL_STACK_SIZE, &sled2, tskIDLE_PRIORITY, NULL );\r
183         xTaskCreate( vBlink,  "B3", configMINIMAL_STACK_SIZE, &sled3, tskIDLE_PRIORITY, NULL );\r
184         xTaskCreate( vBlink,  "B4", configMINIMAL_STACK_SIZE, &sled4, tskIDLE_PRIORITY, NULL );\r
185         xTaskCreate( vBlink,  "B5", configMINIMAL_STACK_SIZE, &sled5, tskIDLE_PRIORITY, NULL );\r
186         xTaskCreate( vBlink,  "B6", configMINIMAL_STACK_SIZE, &sled6, tskIDLE_PRIORITY, NULL );\r
187         xTaskCreate( vBlink,  "B7", configMINIMAL_STACK_SIZE, &sled7, tskIDLE_PRIORITY, NULL );\r
188 \r
189         /*\r
190          * Start the scheduler.\r
191          */\r
192         vTaskStartScheduler( );\r
193         \r
194         while(1)        /* This point should never be reached. */\r
195         {\r
196         }\r
197 }\r
198 /*-----------------------------------------------------------*/\r
199 \r
200 static portTASK_FUNCTION(vBlink, pvParameters)\r
201 {\r
202         unsigned char   *Port           = ((SBLINK *)pvParameters)->port;\r
203         unsigned char   *Tris           = ((SBLINK *)pvParameters)->tris;\r
204         unsigned char   Pin                     = ((SBLINK *)pvParameters)->pin;\r
205         TickType_t      Interval        = ((SBLINK *)pvParameters)->interval;\r
206         \r
207         TickType_t      xLastWakeTime;\r
208 \r
209         /*\r
210          * Initialize the hardware\r
211          */\r
212         *Tris &= ~(1<<Pin);     // Set the pin that is used by this task to ouput\r
213         *Port &= ~(1<<Pin);     // Drive the pin low\r
214         \r
215         /*\r
216          * Initialise the xLastWakeTime variable with the current time.\r
217          */\r
218         xLastWakeTime = xTaskGetTickCount();\r
219 \r
220         /*\r
221          * Cycle for ever, delaying then toggle the LED.\r
222          */\r
223         for( ;; )\r
224         {\r
225                 /*\r
226                  * Wait until it is time to toggle\r
227                  */\r
228                 vTaskDelayUntil( &xLastWakeTime, Interval );\r
229 \r
230                 /*\r
231                  * Toggle the LED for visual feedback.\r
232                  */\r
233                 *Port ^= 1<<Pin;\r
234         }\r
235 }\r