2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
73 * See http://www.freertos.org/Documentation/FreeRTOS-documentation-and-book.html
74 * for an introductory guide to using real time kernels, and FreeRTOS in
79 * The DICE-KIT-16FX has two 7 segment displays and two buttons that can
80 * generate interrupts. This example uses this IO as follows:
83 * - Left 7 segment display -
85 * 7 'flash' tasks are created, each of which toggles a single segment of the
86 * left display. Each task executes at a fixed frequency, with a different
87 * frequency being used by each task.
89 * When button SW2 is pressed an interrupt is generated that wakes up a 'dice'
90 * task. The dice task suspends the 7 tasks that are accessing the left display
91 * before simulating a dice being thrown by generating a random number between
92 * 1 and 6. After the number has been generated the task sleeps for 5 seconds,
93 * if SW2 is pressed again within the 5 seconds another random number is
94 * generated, if SW2 is not pressed within the 5 seconds then the 7 tasks are
95 * un-suspended and will once again toggle the segments of the left hand display.
98 * - Right 7 segment display -
100 * Control of the right side 7 segment display is very similar to that of the
101 * left, except co-routines are used to toggle the segments instead of tasks,
102 * and button SW3 is used instead of SW2.
107 * Only one dice task is actually defined. Two instances of this single
108 * definition are created, the first to simulate a dice being thrown on the left
109 * display, and the other to simulate a dice being thrown on the right display.
110 * The task parameter is used to let the dice tasks know which display to
113 * Both dice tasks and the flash tasks operate completely independently under
114 * the control of FreeRTOS. 11 tasks and 7 co-routines are created in total,
115 * including the idle task.
117 * The co-routines all execute within a single low priority task.
121 * When this demo is executing as expected:
123 * + Every segment of both displays will toggle at a fixed frequency - with each
124 * segment using a different frequency.
125 * + When a button is pushed the segment toggling will temporarily stop and the
126 * dice 'throw' will start whereby the display will show a fast changing random
127 * number for a few seconds before the dice value is chosen and displayed.
128 * + If the button is not pushed again within five seconds of the dice value being
129 * displayed the segment toggling will commence again.
133 /* Kernel includes. */
134 #include "FreeRTOS.h"
138 #include "DiceTask.h"
142 /* The priority at which the dice task execute. */
143 #define mainDICE_PRIORITY ( tskIDLE_PRIORITY + 2 )
146 * Sets up the MCU IO for the 7 segment displays and the button inputs.
148 static void prvSetupHardware( void );
151 * The function that creates the flash tasks and co-routines (the tasks and
152 * co-routines that toggle the 7 segment display segments.
154 extern vCreateFlashTasksAndCoRoutines( void );
156 /*-----------------------------------------------------------*/
160 /* Setup the MCU IO. */
163 /* Create the tasks and co-routines that toggle the display segments. */
164 vCreateFlashTasksAndCoRoutines();
166 /* Create a 'dice' task to control the left hand display. */
167 xTaskCreate( vDiceTask, "Dice1", configMINIMAL_STACK_SIZE, ( void * ) configLEFT_DISPLAY, mainDICE_PRIORITY, NULL );
169 /* Create a 'dice' task to control the right hand display. */
170 xTaskCreate( vDiceTask, "Dice2", configMINIMAL_STACK_SIZE, ( void * ) configRIGHT_DISPLAY, mainDICE_PRIORITY, NULL );
172 /* Start the scheduler running. */
173 vTaskStartScheduler();
175 /* If this loop is executed then there was insufficient heap memory for the
176 idle task to be created - causing vTaskStartScheduler() to return. */
179 /*-----------------------------------------------------------*/
181 static void prvSetupHardware( void )
183 /* Setup interrupt hardware - interrupts are kept disabled for now to
184 prevent any interrupts attempting to cause a context switch before the
185 scheduler has been started. */
187 portDISABLE_INTERRUPTS();
190 /* Set Port3 as output (7Segment Display). */
193 /* Use Port 5 as I/O-Port. */
197 /* Set Port5 as output (7Segment Display). */
200 /* Disable inputs on the following ports. */
212 /* Enable P00_0/INT8 and P00_1/INT9 as input. */
215 /* Enable external interrupt 8. */
218 /* LB0, LA0 = 11 -> falling edge. */
222 /* Reset and enable the interrupt request. */
226 /* Enable external interrupt 9. */
229 /* LB1, LA1 = 11 -> falling edge. */
233 /* Reset and enable the interrupt request. */