2 FreeRTOS V6.0.0 - Copyright (C) 2009 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS eBook *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 ***NOTE*** The exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
61 * Instead of the normal single demo application, the PIC18F demo is split
\r
62 * into several smaller programs of which this is the first. This enables the
\r
63 * demo's to be executed on the RAM limited PIC-devices.
\r
65 * The Demo1 project is configured for a PIC18F4620 device. Main.c starts 9
\r
66 * tasks (including the idle task).
\r
68 * This first demo is included to do a quick check on the FreeRTOS
\r
69 * installation. It is also included to demonstrate a minimal project-setup
\r
70 * to use FreeRTOS in a wizC environment.
\r
72 * Eight independant tasks are created. All tasks share the same taskcode.
\r
73 * Each task blinks a different led on portB. The blinkrate for each task
\r
74 * is different, but chosen in such a way that portB will show a binary
\r
75 * counter pattern. All blinkrates are derived from a single master-rate.
\r
76 * By default, this masterrate is set to 100 milliseconds. Although such
\r
77 * a low value will make it almost impossible to see some of the leds
\r
78 * actually blink, it is a good value when using the wizC-simulator.
\r
79 * When testing on a real chip, changing the value to eg. 500 milliseconds
\r
80 * would be appropiate.
\r
83 /* Scheduler include files. */
\r
84 #include <FreeRTOS.h>
\r
87 #define mainBLINK_LED_INTERVAL ( ( portTickType ) 100 / ( portTICK_RATE_MS ) )
\r
89 /* The LED that is flashed by the B0 task. */
\r
90 #define mainBLINK_LED0_PORT LATD
\r
91 #define mainBLINK_LED0_TRIS TRISD
\r
92 #define mainBLINK_LED0_PIN 0
\r
93 #define mainBLINK_LED0_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED0_PIN))
\r
95 /* The LED that is flashed by the B1 task. */
\r
96 #define mainBLINK_LED1_PORT LATD
\r
97 #define mainBLINK_LED1_TRIS TRISD
\r
98 #define mainBLINK_LED1_PIN 1
\r
99 #define mainBLINK_LED1_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED1_PIN))
\r
101 /* The LED that is flashed by the B2 task. */
\r
102 #define mainBLINK_LED2_PORT LATD
\r
103 #define mainBLINK_LED2_TRIS TRISD
\r
104 #define mainBLINK_LED2_PIN 2
\r
105 #define mainBLINK_LED2_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED2_PIN))
\r
107 /* The LED that is flashed by the B3 task. */
\r
108 #define mainBLINK_LED3_PORT LATD
\r
109 #define mainBLINK_LED3_TRIS TRISD
\r
110 #define mainBLINK_LED3_PIN 3
\r
111 #define mainBLINK_LED3_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED3_PIN))
\r
113 /* The LED that is flashed by the B4 task. */
\r
114 #define mainBLINK_LED4_PORT LATD
\r
115 #define mainBLINK_LED4_TRIS TRISD
\r
116 #define mainBLINK_LED4_PIN 4
\r
117 #define mainBLINK_LED4_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED4_PIN))
\r
119 /* The LED that is flashed by the B5 task. */
\r
120 #define mainBLINK_LED5_PORT LATD
\r
121 #define mainBLINK_LED5_TRIS TRISD
\r
122 #define mainBLINK_LED5_PIN 5
\r
123 #define mainBLINK_LED5_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED5_PIN))
\r
125 /* The LED that is flashed by the B6 task. */
\r
126 #define mainBLINK_LED6_PORT LATD
\r
127 #define mainBLINK_LED6_TRIS TRISD
\r
128 #define mainBLINK_LED6_PIN 6
\r
129 #define mainBLINK_LED6_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED6_PIN))
\r
131 /* The LED that is flashed by the B7 task. */
\r
132 #define mainBLINK_LED7_PORT LATD
\r
133 #define mainBLINK_LED7_TRIS TRISD
\r
134 #define mainBLINK_LED7_PIN 7
\r
135 #define mainBLINK_LED7_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED7_PIN))
\r
138 unsigned char *port;
\r
139 unsigned char *tris;
\r
141 portTickType interval;
\r
144 const SBLINK sled0 = {&mainBLINK_LED0_PORT, &mainBLINK_LED0_TRIS, mainBLINK_LED0_PIN, mainBLINK_LED0_INTERVAL};
\r
145 const SBLINK sled1 = {&mainBLINK_LED1_PORT, &mainBLINK_LED1_TRIS, mainBLINK_LED1_PIN, mainBLINK_LED1_INTERVAL};
\r
146 const SBLINK sled2 = {&mainBLINK_LED2_PORT, &mainBLINK_LED2_TRIS, mainBLINK_LED2_PIN, mainBLINK_LED2_INTERVAL};
\r
147 const SBLINK sled3 = {&mainBLINK_LED3_PORT, &mainBLINK_LED3_TRIS, mainBLINK_LED3_PIN, mainBLINK_LED3_INTERVAL};
\r
148 const SBLINK sled4 = {&mainBLINK_LED4_PORT, &mainBLINK_LED4_TRIS, mainBLINK_LED4_PIN, mainBLINK_LED4_INTERVAL};
\r
149 const SBLINK sled5 = {&mainBLINK_LED5_PORT, &mainBLINK_LED5_TRIS, mainBLINK_LED5_PIN, mainBLINK_LED5_INTERVAL};
\r
150 const SBLINK sled6 = {&mainBLINK_LED6_PORT, &mainBLINK_LED6_TRIS, mainBLINK_LED6_PIN, mainBLINK_LED6_INTERVAL};
\r
151 const SBLINK sled7 = {&mainBLINK_LED7_PORT, &mainBLINK_LED7_TRIS, mainBLINK_LED7_PIN, mainBLINK_LED7_INTERVAL};
\r
154 * The task code for the "vBlink" task.
\r
156 static portTASK_FUNCTION_PROTO(vBlink, pvParameters);
\r
158 /*-----------------------------------------------------------*/
\r
161 * Creates the tasks, then starts the scheduler.
\r
166 * Start the blink tasks defined in this file.
\r
168 xTaskCreate( vBlink, "B0", configMINIMAL_STACK_SIZE, &sled0, tskIDLE_PRIORITY, NULL );
\r
169 xTaskCreate( vBlink, "B1", configMINIMAL_STACK_SIZE, &sled1, tskIDLE_PRIORITY, NULL );
\r
170 xTaskCreate( vBlink, "B2", configMINIMAL_STACK_SIZE, &sled2, tskIDLE_PRIORITY, NULL );
\r
171 xTaskCreate( vBlink, "B3", configMINIMAL_STACK_SIZE, &sled3, tskIDLE_PRIORITY, NULL );
\r
172 xTaskCreate( vBlink, "B4", configMINIMAL_STACK_SIZE, &sled4, tskIDLE_PRIORITY, NULL );
\r
173 xTaskCreate( vBlink, "B5", configMINIMAL_STACK_SIZE, &sled5, tskIDLE_PRIORITY, NULL );
\r
174 xTaskCreate( vBlink, "B6", configMINIMAL_STACK_SIZE, &sled6, tskIDLE_PRIORITY, NULL );
\r
175 xTaskCreate( vBlink, "B7", configMINIMAL_STACK_SIZE, &sled7, tskIDLE_PRIORITY, NULL );
\r
178 * Start the scheduler.
\r
180 vTaskStartScheduler( );
\r
182 while(1) /* This point should never be reached. */
\r
186 /*-----------------------------------------------------------*/
\r
188 static portTASK_FUNCTION(vBlink, pvParameters)
\r
190 unsigned char *Port = ((SBLINK *)pvParameters)->port;
\r
191 unsigned char *Tris = ((SBLINK *)pvParameters)->tris;
\r
192 unsigned char Pin = ((SBLINK *)pvParameters)->pin;
\r
193 portTickType Interval = ((SBLINK *)pvParameters)->interval;
\r
195 portTickType xLastWakeTime;
\r
198 * Initialize the hardware
\r
200 *Tris &= ~(1<<Pin); // Set the pin that is used by this task to ouput
\r
201 *Port &= ~(1<<Pin); // Drive the pin low
\r
204 * Initialise the xLastWakeTime variable with the current time.
\r
206 xLastWakeTime = xTaskGetTickCount();
\r
209 * Cycle for ever, delaying then toggle the LED.
\r
214 * Wait until it is time to toggle
\r
216 vTaskDelayUntil( &xLastWakeTime, Interval );
\r
219 * Toggle the LED for visual feedback.
\r