2 FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify it
\r
7 under the terms of the GNU General Public License (version 2) as published
\r
8 by the Free Software Foundation and modified by the FreeRTOS exception.
\r
10 FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT
\r
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59
\r
17 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
\r
19 A special exception to the GPL is included to allow you to distribute a
\r
20 combined work that includes FreeRTOS.org without being obliged to provide
\r
21 the source code for any proprietary components. See the licensing section
\r
22 of http://www.FreeRTOS.org for full details.
\r
25 ***************************************************************************
\r
27 * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *
\r
29 * This is a concise, step by step, 'hands on' guide that describes both *
\r
30 * general multitasking concepts and FreeRTOS specifics. It presents and *
\r
31 * explains numerous examples that are written using the FreeRTOS API. *
\r
32 * Full source code for all the examples is provided in an accompanying *
\r
35 ***************************************************************************
\r
39 Please ensure to read the configuration and relevant port sections of the
\r
40 online documentation.
\r
42 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
45 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
48 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
49 licensing and training services.
\r
55 * See http://www.freertos.org/Documentation/FreeRTOS-documentation-and-book.html
\r
56 * for an introductory guide to using real time kernels, and FreeRTOS in
\r
61 * The DICE-KIT-16FX has two 7 segment displays and two buttons that can
\r
62 * generate interrupts. This example uses this IO as follows:
\r
65 * - Left 7 segment display -
\r
67 * 7 'flash' tasks are created, each of which toggles a single segment of the
\r
68 * left display. Each task executes at a fixed frequency, with a different
\r
69 * frequency being used by each task.
\r
71 * When button SW2 is pressed an interrupt is generated that wakes up a 'dice'
\r
72 * task. The dice task suspends the 7 tasks that are accessing the left display
\r
73 * before simulating a dice being thrown by generating a random number between
\r
74 * 1 and 6. After the number has been generated the task sleeps for 5 seconds,
\r
75 * if SW2 is pressed again within the 5 seconds another random number is
\r
76 * generated, if SW2 is not pressed within the 5 seconds then the 7 tasks are
\r
77 * un-suspended and will once again toggle the segments of the left hand display.
\r
80 * - Right 7 segment display -
\r
82 * Control of the right side 7 segment display is very similar to that of the
\r
83 * left, except co-routines are used to toggle the segments instead of tasks,
\r
84 * and button SW3 is used instead of SW2.
\r
89 * Only one dice task is actually defined. Two instances of this single
\r
90 * definition are created, the first to simulate a dice being thrown on the left
\r
91 * display, and the other to simulate a dice being thrown on the right display.
\r
92 * The task parameter is used to let the dice tasks know which display to
\r
95 * Both dice tasks and the flash tasks operate completely independently under
\r
96 * the control of FreeRTOS. 11 tasks and 7 co-routines are created in total,
\r
97 * including the idle task.
\r
99 * The co-routines all execute within a single low priority task.
\r
103 * When this demo is executing as expected:
\r
105 * + Every segment of both displays will toggle at a fixed frequency - with each
\r
106 * segment using a different frequency.
\r
107 * + When a button is pushed the segment toggling will temporarily stop and the
\r
108 * dice 'throw' will start whereby the display will show a fast changing random
\r
109 * number for a few seconds before the dice value is chosen and displayed.
\r
110 * + If the button is not pushed again within five seconds of the dice value being
\r
111 * displayed the segment toggling will commence again.
\r
115 /* Kernel includes. */
\r
116 #include "FreeRTOS.h"
\r
119 /* Demo includes. */
\r
120 #include "DiceTask.h"
\r
121 #include "ParTest.h"
\r
124 /* The priority at which the dice task execute. */
\r
125 #define mainDICE_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
128 * Sets up the MCU IO for the 7 segment displays and the button inputs.
\r
130 static void prvSetupHardware( void );
\r
133 * The function that creates the flash tasks and co-routines (the tasks and
\r
134 * co-routines that toggle the 7 segment display segments.
\r
136 extern vCreateFlashTasksAndCoRoutines( void );
\r
138 /*-----------------------------------------------------------*/
\r
142 /* Setup the MCU IO. */
\r
143 prvSetupHardware();
\r
145 /* Create the tasks and co-routines that toggle the display segments. */
\r
146 vCreateFlashTasksAndCoRoutines();
\r
148 /* Create a 'dice' task to control the left hand display. */
\r
149 xTaskCreate( vDiceTask, ( signed char * ) "Dice1", configMINIMAL_STACK_SIZE, ( void * ) configLEFT_DISPLAY, mainDICE_PRIORITY, NULL );
\r
151 /* Create a 'dice' task to control the right hand display. */
\r
152 xTaskCreate( vDiceTask, ( signed char * ) "Dice2", configMINIMAL_STACK_SIZE, ( void * ) configRIGHT_DISPLAY, mainDICE_PRIORITY, NULL );
\r
154 /* Start the scheduler running. */
\r
155 vTaskStartScheduler();
\r
157 /* If this loop is executed then there was insufficient heap memory for the
\r
158 idle task to be created - causing vTaskStartScheduler() to return. */
\r
161 /*-----------------------------------------------------------*/
\r
163 static void prvSetupHardware( void )
\r
165 /* Setup interrupt hardware - interrupts are kept disabled for now to
\r
166 prevent any interrupts attempting to cause a context switch before the
\r
167 scheduler has been started. */
\r
169 portDISABLE_INTERRUPTS();
\r
172 /* Set Port3 as output (7Segment Display). */
\r
175 /* Use Port 5 as I/O-Port. */
\r
179 /* Set Port5 as output (7Segment Display). */
\r
182 /* Disable inputs on the following ports. */
\r
194 /* Enable P00_0/INT8 and P00_1/INT9 as input. */
\r
197 /* Enable external interrupt 8. */
\r
200 /* LB0, LA0 = 11 -> falling edge. */
\r
204 /* Reset and enable the interrupt request. */
\r
208 /* Enable external interrupt 9. */
\r
211 /* LB1, LA1 = 11 -> falling edge. */
\r
215 /* Reset and enable the interrupt request. */
\r