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