2 FreeRTOS V8.2.0 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
77 * Instead of the normal single demo application, the PIC18F demo is split
\r
78 * into several smaller programs of which this is the first. This enables the
\r
79 * demo's to be executed on the RAM limited PIC-devices.
\r
81 * The Demo1 project is configured for a PIC18F4620 device. Main.c starts 9
\r
82 * tasks (including the idle task).
\r
84 * This first demo is included to do a quick check on the FreeRTOS
\r
85 * installation. It is also included to demonstrate a minimal project-setup
\r
86 * to use FreeRTOS in a wizC environment.
\r
88 * Eight independant tasks are created. All tasks share the same taskcode.
\r
89 * Each task blinks a different led on portB. The blinkrate for each task
\r
90 * is different, but chosen in such a way that portB will show a binary
\r
91 * counter pattern. All blinkrates are derived from a single master-rate.
\r
92 * By default, this masterrate is set to 100 milliseconds. Although such
\r
93 * a low value will make it almost impossible to see some of the leds
\r
94 * actually blink, it is a good value when using the wizC-simulator.
\r
95 * When testing on a real chip, changing the value to eg. 500 milliseconds
\r
96 * would be appropiate.
\r
99 /* Scheduler include files. */
\r
100 #include <FreeRTOS.h>
\r
103 #define mainBLINK_LED_INTERVAL ( ( TickType_t ) 100 / ( portTICK_PERIOD_MS ) )
\r
105 /* The LED that is flashed by the B0 task. */
\r
106 #define mainBLINK_LED0_PORT LATD
\r
107 #define mainBLINK_LED0_TRIS TRISD
\r
108 #define mainBLINK_LED0_PIN 0
\r
109 #define mainBLINK_LED0_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED0_PIN))
\r
111 /* The LED that is flashed by the B1 task. */
\r
112 #define mainBLINK_LED1_PORT LATD
\r
113 #define mainBLINK_LED1_TRIS TRISD
\r
114 #define mainBLINK_LED1_PIN 1
\r
115 #define mainBLINK_LED1_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED1_PIN))
\r
117 /* The LED that is flashed by the B2 task. */
\r
118 #define mainBLINK_LED2_PORT LATD
\r
119 #define mainBLINK_LED2_TRIS TRISD
\r
120 #define mainBLINK_LED2_PIN 2
\r
121 #define mainBLINK_LED2_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED2_PIN))
\r
123 /* The LED that is flashed by the B3 task. */
\r
124 #define mainBLINK_LED3_PORT LATD
\r
125 #define mainBLINK_LED3_TRIS TRISD
\r
126 #define mainBLINK_LED3_PIN 3
\r
127 #define mainBLINK_LED3_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED3_PIN))
\r
129 /* The LED that is flashed by the B4 task. */
\r
130 #define mainBLINK_LED4_PORT LATD
\r
131 #define mainBLINK_LED4_TRIS TRISD
\r
132 #define mainBLINK_LED4_PIN 4
\r
133 #define mainBLINK_LED4_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED4_PIN))
\r
135 /* The LED that is flashed by the B5 task. */
\r
136 #define mainBLINK_LED5_PORT LATD
\r
137 #define mainBLINK_LED5_TRIS TRISD
\r
138 #define mainBLINK_LED5_PIN 5
\r
139 #define mainBLINK_LED5_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED5_PIN))
\r
141 /* The LED that is flashed by the B6 task. */
\r
142 #define mainBLINK_LED6_PORT LATD
\r
143 #define mainBLINK_LED6_TRIS TRISD
\r
144 #define mainBLINK_LED6_PIN 6
\r
145 #define mainBLINK_LED6_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED6_PIN))
\r
147 /* The LED that is flashed by the B7 task. */
\r
148 #define mainBLINK_LED7_PORT LATD
\r
149 #define mainBLINK_LED7_TRIS TRISD
\r
150 #define mainBLINK_LED7_PIN 7
\r
151 #define mainBLINK_LED7_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED7_PIN))
\r
154 unsigned char *port;
\r
155 unsigned char *tris;
\r
157 TickType_t interval;
\r
160 const SBLINK sled0 = {&mainBLINK_LED0_PORT, &mainBLINK_LED0_TRIS, mainBLINK_LED0_PIN, mainBLINK_LED0_INTERVAL};
\r
161 const SBLINK sled1 = {&mainBLINK_LED1_PORT, &mainBLINK_LED1_TRIS, mainBLINK_LED1_PIN, mainBLINK_LED1_INTERVAL};
\r
162 const SBLINK sled2 = {&mainBLINK_LED2_PORT, &mainBLINK_LED2_TRIS, mainBLINK_LED2_PIN, mainBLINK_LED2_INTERVAL};
\r
163 const SBLINK sled3 = {&mainBLINK_LED3_PORT, &mainBLINK_LED3_TRIS, mainBLINK_LED3_PIN, mainBLINK_LED3_INTERVAL};
\r
164 const SBLINK sled4 = {&mainBLINK_LED4_PORT, &mainBLINK_LED4_TRIS, mainBLINK_LED4_PIN, mainBLINK_LED4_INTERVAL};
\r
165 const SBLINK sled5 = {&mainBLINK_LED5_PORT, &mainBLINK_LED5_TRIS, mainBLINK_LED5_PIN, mainBLINK_LED5_INTERVAL};
\r
166 const SBLINK sled6 = {&mainBLINK_LED6_PORT, &mainBLINK_LED6_TRIS, mainBLINK_LED6_PIN, mainBLINK_LED6_INTERVAL};
\r
167 const SBLINK sled7 = {&mainBLINK_LED7_PORT, &mainBLINK_LED7_TRIS, mainBLINK_LED7_PIN, mainBLINK_LED7_INTERVAL};
\r
170 * The task code for the "vBlink" task.
\r
172 static portTASK_FUNCTION_PROTO(vBlink, pvParameters);
\r
174 /*-----------------------------------------------------------*/
\r
177 * Creates the tasks, then starts the scheduler.
\r
182 * Start the blink tasks defined in this file.
\r
184 xTaskCreate( vBlink, "B0", configMINIMAL_STACK_SIZE, &sled0, tskIDLE_PRIORITY, NULL );
\r
185 xTaskCreate( vBlink, "B1", configMINIMAL_STACK_SIZE, &sled1, tskIDLE_PRIORITY, NULL );
\r
186 xTaskCreate( vBlink, "B2", configMINIMAL_STACK_SIZE, &sled2, tskIDLE_PRIORITY, NULL );
\r
187 xTaskCreate( vBlink, "B3", configMINIMAL_STACK_SIZE, &sled3, tskIDLE_PRIORITY, NULL );
\r
188 xTaskCreate( vBlink, "B4", configMINIMAL_STACK_SIZE, &sled4, tskIDLE_PRIORITY, NULL );
\r
189 xTaskCreate( vBlink, "B5", configMINIMAL_STACK_SIZE, &sled5, tskIDLE_PRIORITY, NULL );
\r
190 xTaskCreate( vBlink, "B6", configMINIMAL_STACK_SIZE, &sled6, tskIDLE_PRIORITY, NULL );
\r
191 xTaskCreate( vBlink, "B7", configMINIMAL_STACK_SIZE, &sled7, tskIDLE_PRIORITY, NULL );
\r
194 * Start the scheduler.
\r
196 vTaskStartScheduler( );
\r
198 while(1) /* This point should never be reached. */
\r
202 /*-----------------------------------------------------------*/
\r
204 static portTASK_FUNCTION(vBlink, pvParameters)
\r
206 unsigned char *Port = ((SBLINK *)pvParameters)->port;
\r
207 unsigned char *Tris = ((SBLINK *)pvParameters)->tris;
\r
208 unsigned char Pin = ((SBLINK *)pvParameters)->pin;
\r
209 TickType_t Interval = ((SBLINK *)pvParameters)->interval;
\r
211 TickType_t xLastWakeTime;
\r
214 * Initialize the hardware
\r
216 *Tris &= ~(1<<Pin); // Set the pin that is used by this task to ouput
\r
217 *Port &= ~(1<<Pin); // Drive the pin low
\r
220 * Initialise the xLastWakeTime variable with the current time.
\r
222 xLastWakeTime = xTaskGetTickCount();
\r
225 * Cycle for ever, delaying then toggle the LED.
\r
230 * Wait until it is time to toggle
\r
232 vTaskDelayUntil( &xLastWakeTime, Interval );
\r
235 * Toggle the LED for visual feedback.
\r