2 * FreeRTOS Kernel V10.0.1
\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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
35 * Instead of the normal single demo application, the PIC18F demo is split
\r
36 * into several smaller programs of which this is the first. This enables the
\r
37 * demo's to be executed on the RAM limited PIC-devices.
\r
39 * The Demo1 project is configured for a PIC18F4620 device. Main.c starts 9
\r
40 * tasks (including the idle task).
\r
42 * This first demo is included to do a quick check on the FreeRTOS
\r
43 * installation. It is also included to demonstrate a minimal project-setup
\r
44 * to use FreeRTOS in a wizC environment.
\r
46 * Eight independant tasks are created. All tasks share the same taskcode.
\r
47 * Each task blinks a different led on portB. The blinkrate for each task
\r
48 * is different, but chosen in such a way that portB will show a binary
\r
49 * counter pattern. All blinkrates are derived from a single master-rate.
\r
50 * By default, this masterrate is set to 100 milliseconds. Although such
\r
51 * a low value will make it almost impossible to see some of the leds
\r
52 * actually blink, it is a good value when using the wizC-simulator.
\r
53 * When testing on a real chip, changing the value to eg. 500 milliseconds
\r
54 * would be appropiate.
\r
57 /* Scheduler include files. */
\r
58 #include <FreeRTOS.h>
\r
61 #define mainBLINK_LED_INTERVAL ( ( TickType_t ) 100 / ( portTICK_PERIOD_MS ) )
\r
63 /* The LED that is flashed by the B0 task. */
\r
64 #define mainBLINK_LED0_PORT LATD
\r
65 #define mainBLINK_LED0_TRIS TRISD
\r
66 #define mainBLINK_LED0_PIN 0
\r
67 #define mainBLINK_LED0_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED0_PIN))
\r
69 /* The LED that is flashed by the B1 task. */
\r
70 #define mainBLINK_LED1_PORT LATD
\r
71 #define mainBLINK_LED1_TRIS TRISD
\r
72 #define mainBLINK_LED1_PIN 1
\r
73 #define mainBLINK_LED1_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED1_PIN))
\r
75 /* The LED that is flashed by the B2 task. */
\r
76 #define mainBLINK_LED2_PORT LATD
\r
77 #define mainBLINK_LED2_TRIS TRISD
\r
78 #define mainBLINK_LED2_PIN 2
\r
79 #define mainBLINK_LED2_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED2_PIN))
\r
81 /* The LED that is flashed by the B3 task. */
\r
82 #define mainBLINK_LED3_PORT LATD
\r
83 #define mainBLINK_LED3_TRIS TRISD
\r
84 #define mainBLINK_LED3_PIN 3
\r
85 #define mainBLINK_LED3_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED3_PIN))
\r
87 /* The LED that is flashed by the B4 task. */
\r
88 #define mainBLINK_LED4_PORT LATD
\r
89 #define mainBLINK_LED4_TRIS TRISD
\r
90 #define mainBLINK_LED4_PIN 4
\r
91 #define mainBLINK_LED4_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED4_PIN))
\r
93 /* The LED that is flashed by the B5 task. */
\r
94 #define mainBLINK_LED5_PORT LATD
\r
95 #define mainBLINK_LED5_TRIS TRISD
\r
96 #define mainBLINK_LED5_PIN 5
\r
97 #define mainBLINK_LED5_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED5_PIN))
\r
99 /* The LED that is flashed by the B6 task. */
\r
100 #define mainBLINK_LED6_PORT LATD
\r
101 #define mainBLINK_LED6_TRIS TRISD
\r
102 #define mainBLINK_LED6_PIN 6
\r
103 #define mainBLINK_LED6_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED6_PIN))
\r
105 /* The LED that is flashed by the B7 task. */
\r
106 #define mainBLINK_LED7_PORT LATD
\r
107 #define mainBLINK_LED7_TRIS TRISD
\r
108 #define mainBLINK_LED7_PIN 7
\r
109 #define mainBLINK_LED7_INTERVAL ((mainBLINK_LED_INTERVAL) << (mainBLINK_LED7_PIN))
\r
112 unsigned char *port;
\r
113 unsigned char *tris;
\r
115 TickType_t interval;
\r
118 const SBLINK sled0 = {&mainBLINK_LED0_PORT, &mainBLINK_LED0_TRIS, mainBLINK_LED0_PIN, mainBLINK_LED0_INTERVAL};
\r
119 const SBLINK sled1 = {&mainBLINK_LED1_PORT, &mainBLINK_LED1_TRIS, mainBLINK_LED1_PIN, mainBLINK_LED1_INTERVAL};
\r
120 const SBLINK sled2 = {&mainBLINK_LED2_PORT, &mainBLINK_LED2_TRIS, mainBLINK_LED2_PIN, mainBLINK_LED2_INTERVAL};
\r
121 const SBLINK sled3 = {&mainBLINK_LED3_PORT, &mainBLINK_LED3_TRIS, mainBLINK_LED3_PIN, mainBLINK_LED3_INTERVAL};
\r
122 const SBLINK sled4 = {&mainBLINK_LED4_PORT, &mainBLINK_LED4_TRIS, mainBLINK_LED4_PIN, mainBLINK_LED4_INTERVAL};
\r
123 const SBLINK sled5 = {&mainBLINK_LED5_PORT, &mainBLINK_LED5_TRIS, mainBLINK_LED5_PIN, mainBLINK_LED5_INTERVAL};
\r
124 const SBLINK sled6 = {&mainBLINK_LED6_PORT, &mainBLINK_LED6_TRIS, mainBLINK_LED6_PIN, mainBLINK_LED6_INTERVAL};
\r
125 const SBLINK sled7 = {&mainBLINK_LED7_PORT, &mainBLINK_LED7_TRIS, mainBLINK_LED7_PIN, mainBLINK_LED7_INTERVAL};
\r
128 * The task code for the "vBlink" task.
\r
130 static portTASK_FUNCTION_PROTO(vBlink, pvParameters);
\r
132 /*-----------------------------------------------------------*/
\r
135 * Creates the tasks, then starts the scheduler.
\r
140 * Start the blink tasks defined in this file.
\r
142 xTaskCreate( vBlink, "B0", configMINIMAL_STACK_SIZE, &sled0, tskIDLE_PRIORITY, NULL );
\r
143 xTaskCreate( vBlink, "B1", configMINIMAL_STACK_SIZE, &sled1, tskIDLE_PRIORITY, NULL );
\r
144 xTaskCreate( vBlink, "B2", configMINIMAL_STACK_SIZE, &sled2, tskIDLE_PRIORITY, NULL );
\r
145 xTaskCreate( vBlink, "B3", configMINIMAL_STACK_SIZE, &sled3, tskIDLE_PRIORITY, NULL );
\r
146 xTaskCreate( vBlink, "B4", configMINIMAL_STACK_SIZE, &sled4, tskIDLE_PRIORITY, NULL );
\r
147 xTaskCreate( vBlink, "B5", configMINIMAL_STACK_SIZE, &sled5, tskIDLE_PRIORITY, NULL );
\r
148 xTaskCreate( vBlink, "B6", configMINIMAL_STACK_SIZE, &sled6, tskIDLE_PRIORITY, NULL );
\r
149 xTaskCreate( vBlink, "B7", configMINIMAL_STACK_SIZE, &sled7, tskIDLE_PRIORITY, NULL );
\r
152 * Start the scheduler.
\r
154 vTaskStartScheduler( );
\r
156 while(1) /* This point should never be reached. */
\r
160 /*-----------------------------------------------------------*/
\r
162 static portTASK_FUNCTION(vBlink, pvParameters)
\r
164 unsigned char *Port = ((SBLINK *)pvParameters)->port;
\r
165 unsigned char *Tris = ((SBLINK *)pvParameters)->tris;
\r
166 unsigned char Pin = ((SBLINK *)pvParameters)->pin;
\r
167 TickType_t Interval = ((SBLINK *)pvParameters)->interval;
\r
169 TickType_t xLastWakeTime;
\r
172 * Initialize the hardware
\r
174 *Tris &= ~(1<<Pin); // Set the pin that is used by this task to ouput
\r
175 *Port &= ~(1<<Pin); // Drive the pin low
\r
178 * Initialise the xLastWakeTime variable with the current time.
\r
180 xLastWakeTime = xTaskGetTickCount();
\r
183 * Cycle for ever, delaying then toggle the LED.
\r
188 * Wait until it is time to toggle
\r
190 vTaskDelayUntil( &xLastWakeTime, Interval );
\r
193 * Toggle the LED for visual feedback.
\r