]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/PIC18_WizC/Demo1/main.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / PIC18_WizC / Demo1 / main.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \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
12 \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
19 \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
24 \r
25     ***************************************************************************\r
26      *                                                                       *\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
31      *                                                                       *\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
36      *                                                                       *\r
37     ***************************************************************************\r
38 \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
42 \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
46 \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
51 \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
55 \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
58 \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
62 \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
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71 Changes from V3.0.0\r
72 \r
73 Changes from V3.0.1\r
74 */\r
75 \r
76 /*\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
80  *\r
81  * The Demo1 project is configured for a PIC18F4620 device.  Main.c starts 9 \r
82  * tasks (including the idle task).\r
83 \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
87  *\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
97  */\r
98  \r
99 /* Scheduler include files. */\r
100 #include <FreeRTOS.h>\r
101 #include <task.h>\r
102 \r
103 #define mainBLINK_LED_INTERVAL  ( ( TickType_t ) 100 / ( portTICK_PERIOD_MS ) )\r
104 \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
110 \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
116 \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
122 \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
128 \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
134 \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
140 \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
146 \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
152 \r
153 typedef struct {\r
154         unsigned char *port;\r
155         unsigned char *tris;\r
156         unsigned char pin;\r
157         TickType_t  interval;\r
158 } SBLINK;\r
159 \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
168 \r
169 /*\r
170  * The task code for the "vBlink" task.\r
171  */\r
172 static portTASK_FUNCTION_PROTO(vBlink, pvParameters);\r
173 \r
174 /*-----------------------------------------------------------*/\r
175 \r
176 /*\r
177  * Creates the tasks, then starts the scheduler.\r
178  */\r
179 void main( void )\r
180 {\r
181         /*\r
182          * Start the blink tasks defined in this file.\r
183          */\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
192 \r
193         /*\r
194          * Start the scheduler.\r
195          */\r
196         vTaskStartScheduler( );\r
197         \r
198         while(1)        /* This point should never be reached. */\r
199         {\r
200         }\r
201 }\r
202 /*-----------------------------------------------------------*/\r
203 \r
204 static portTASK_FUNCTION(vBlink, pvParameters)\r
205 {\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
210         \r
211         TickType_t      xLastWakeTime;\r
212 \r
213         /*\r
214          * Initialize the hardware\r
215          */\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
218         \r
219         /*\r
220          * Initialise the xLastWakeTime variable with the current time.\r
221          */\r
222         xLastWakeTime = xTaskGetTickCount();\r
223 \r
224         /*\r
225          * Cycle for ever, delaying then toggle the LED.\r
226          */\r
227         for( ;; )\r
228         {\r
229                 /*\r
230                  * Wait until it is time to toggle\r
231                  */\r
232                 vTaskDelayUntil( &xLastWakeTime, Interval );\r
233 \r
234                 /*\r
235                  * Toggle the LED for visual feedback.\r
236                  */\r
237                 *Port ^= 1<<Pin;\r
238         }\r
239 }\r