2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
36 * Instead of the normal single demo application, the PIC18F demo is split
\r
37 * into several smaller programs of which this is the first. This enables the
\r
38 * demo's to be executed on the RAM limited PIC-devices.
\r
40 * The Demo1 project is configured for a PIC18F4620 device. Main.c starts 9
\r
41 * tasks (including the idle task).
\r
43 * This first demo is included to do a quick check on the FreeRTOS
\r
44 * installation. It is also included to demonstrate a minimal project-setup
\r
45 * to use FreeRTOS in a wizC environment.
\r
47 * Eight independant tasks are created. All tasks share the same taskcode.
\r
48 * Each task blinks a different led on portB. The blinkrate for each task
\r
49 * is different, but chosen in such a way that portB will show a binary
\r
50 * counter pattern. All blinkrates are derived from a single master-rate.
\r
51 * By default, this masterrate is set to 100 milliseconds. Although such
\r
52 * a low value will make it almost impossible to see some of the leds
\r
53 * actually blink, it is a good value when using the wizC-simulator.
\r
54 * When testing on a real chip, changing the value to eg. 500 milliseconds
\r
55 * would be appropiate.
\r
58 /* Scheduler include files. */
\r
59 #include <FreeRTOS.h>
\r
62 #define mainBLINK_LED_INTERVAL ( ( TickType_t ) 100 / ( portTICK_PERIOD_MS ) )
\r
64 /* The LED that is flashed by the B0 task. */
\r
65 #define mainBLINK_LED0_PORT LATD
\r
66 #define mainBLINK_LED0_TRIS TRISD
\r
67 #define mainBLINK_LED0_PIN 0
\r
68 #define mainBLINK_LED0_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED0_PIN))
\r
70 /* The LED that is flashed by the B1 task. */
\r
71 #define mainBLINK_LED1_PORT LATD
\r
72 #define mainBLINK_LED1_TRIS TRISD
\r
73 #define mainBLINK_LED1_PIN 1
\r
74 #define mainBLINK_LED1_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED1_PIN))
\r
76 /* The LED that is flashed by the B2 task. */
\r
77 #define mainBLINK_LED2_PORT LATD
\r
78 #define mainBLINK_LED2_TRIS TRISD
\r
79 #define mainBLINK_LED2_PIN 2
\r
80 #define mainBLINK_LED2_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED2_PIN))
\r
82 /* The LED that is flashed by the B3 task. */
\r
83 #define mainBLINK_LED3_PORT LATD
\r
84 #define mainBLINK_LED3_TRIS TRISD
\r
85 #define mainBLINK_LED3_PIN 3
\r
86 #define mainBLINK_LED3_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED3_PIN))
\r
88 /* The LED that is flashed by the B4 task. */
\r
89 #define mainBLINK_LED4_PORT LATD
\r
90 #define mainBLINK_LED4_TRIS TRISD
\r
91 #define mainBLINK_LED4_PIN 4
\r
92 #define mainBLINK_LED4_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED4_PIN))
\r
94 /* The LED that is flashed by the B5 task. */
\r
95 #define mainBLINK_LED5_PORT LATD
\r
96 #define mainBLINK_LED5_TRIS TRISD
\r
97 #define mainBLINK_LED5_PIN 5
\r
98 #define mainBLINK_LED5_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED5_PIN))
\r
100 /* The LED that is flashed by the B6 task. */
\r
101 #define mainBLINK_LED6_PORT LATD
\r
102 #define mainBLINK_LED6_TRIS TRISD
\r
103 #define mainBLINK_LED6_PIN 6
\r
104 #define mainBLINK_LED6_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED6_PIN))
\r
106 /* The LED that is flashed by the B7 task. */
\r
107 #define mainBLINK_LED7_PORT LATD
\r
108 #define mainBLINK_LED7_TRIS TRISD
\r
109 #define mainBLINK_LED7_PIN 7
\r
110 #define mainBLINK_LED7_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED7_PIN))
\r
113 unsigned char *port;
\r
114 unsigned char *tris;
\r
116 TickType_t interval;
\r
119 const SBLINK sled0 = {&mainBLINK_LED0_PORT, &mainBLINK_LED0_TRIS, mainBLINK_LED0_PIN, mainBLINK_LED0_INTERVAL};
\r
120 const SBLINK sled1 = {&mainBLINK_LED1_PORT, &mainBLINK_LED1_TRIS, mainBLINK_LED1_PIN, mainBLINK_LED1_INTERVAL};
\r
121 const SBLINK sled2 = {&mainBLINK_LED2_PORT, &mainBLINK_LED2_TRIS, mainBLINK_LED2_PIN, mainBLINK_LED2_INTERVAL};
\r
122 const SBLINK sled3 = {&mainBLINK_LED3_PORT, &mainBLINK_LED3_TRIS, mainBLINK_LED3_PIN, mainBLINK_LED3_INTERVAL};
\r
123 const SBLINK sled4 = {&mainBLINK_LED4_PORT, &mainBLINK_LED4_TRIS, mainBLINK_LED4_PIN, mainBLINK_LED4_INTERVAL};
\r
124 const SBLINK sled5 = {&mainBLINK_LED5_PORT, &mainBLINK_LED5_TRIS, mainBLINK_LED5_PIN, mainBLINK_LED5_INTERVAL};
\r
125 const SBLINK sled6 = {&mainBLINK_LED6_PORT, &mainBLINK_LED6_TRIS, mainBLINK_LED6_PIN, mainBLINK_LED6_INTERVAL};
\r
126 const SBLINK sled7 = {&mainBLINK_LED7_PORT, &mainBLINK_LED7_TRIS, mainBLINK_LED7_PIN, mainBLINK_LED7_INTERVAL};
\r
129 * The task code for the "vBlink" task.
\r
131 static portTASK_FUNCTION_PROTO(vBlink, pvParameters);
\r
133 /*-----------------------------------------------------------*/
\r
136 * Creates the tasks, then starts the scheduler.
\r
141 * Start the blink tasks defined in this file.
\r
143 xTaskCreate( vBlink, "B0", configMINIMAL_STACK_SIZE, &sled0, tskIDLE_PRIORITY, NULL );
\r
144 xTaskCreate( vBlink, "B1", configMINIMAL_STACK_SIZE, &sled1, tskIDLE_PRIORITY, NULL );
\r
145 xTaskCreate( vBlink, "B2", configMINIMAL_STACK_SIZE, &sled2, tskIDLE_PRIORITY, NULL );
\r
146 xTaskCreate( vBlink, "B3", configMINIMAL_STACK_SIZE, &sled3, tskIDLE_PRIORITY, NULL );
\r
147 xTaskCreate( vBlink, "B4", configMINIMAL_STACK_SIZE, &sled4, tskIDLE_PRIORITY, NULL );
\r
148 xTaskCreate( vBlink, "B5", configMINIMAL_STACK_SIZE, &sled5, tskIDLE_PRIORITY, NULL );
\r
149 xTaskCreate( vBlink, "B6", configMINIMAL_STACK_SIZE, &sled6, tskIDLE_PRIORITY, NULL );
\r
150 xTaskCreate( vBlink, "B7", configMINIMAL_STACK_SIZE, &sled7, tskIDLE_PRIORITY, NULL );
\r
153 * Start the scheduler.
\r
155 vTaskStartScheduler( );
\r
157 while(1) /* This point should never be reached. */
\r
161 /*-----------------------------------------------------------*/
\r
163 static portTASK_FUNCTION(vBlink, pvParameters)
\r
165 unsigned char *Port = ((SBLINK *)pvParameters)->port;
\r
166 unsigned char *Tris = ((SBLINK *)pvParameters)->tris;
\r
167 unsigned char Pin = ((SBLINK *)pvParameters)->pin;
\r
168 TickType_t Interval = ((SBLINK *)pvParameters)->interval;
\r
170 TickType_t xLastWakeTime;
\r
173 * Initialize the hardware
\r
175 *Tris &= ~(1<<Pin); // Set the pin that is used by this task to ouput
\r
176 *Port &= ~(1<<Pin); // Drive the pin low
\r
179 * Initialise the xLastWakeTime variable with the current time.
\r
181 xLastWakeTime = xTaskGetTickCount();
\r
184 * Cycle for ever, delaying then toggle the LED.
\r
189 * Wait until it is time to toggle
\r
191 vTaskDelayUntil( &xLastWakeTime, Interval );
\r
194 * Toggle the LED for visual feedback.
\r